Skip to content

Commit

Permalink
Aqua Patina APY adapter (#1597)
Browse files Browse the repository at this point in the history
* init

* calculate apy+tvl

* tvl calculation using BigInt to avoid potential overflows

* reads 10-day moving average

---------

Co-authored-by: 0xwildhare <[email protected]>
  • Loading branch information
sponnet and 0xWildhare authored Nov 26, 2024
1 parent 7b7f779 commit 5afa690
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/adaptors/aqua-patina/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"totalSupply": {
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "totalSupply",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
"ethPerAPEth": {
"inputs": [],
"name": "ethPerAPEth",
"outputs": [
{
"internalType": "uint256",
"name": "ethPerAPEth",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
}
54 changes: 54 additions & 0 deletions src/adaptors/aqua-patina/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const utils = require('../utils');
const sdk = require('@defillama/sdk');
const abi = require('./abi.json');
const axios = require('axios');

const APETH = '0xAaAaAAaBC6CBc3A1FD3a0fe0FDec43251C6562F5';
const ETH = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'


const getApy = async () => {
const apy = await utils.getData('https://wallet.aquapatina.com/api/apy_current');

tvl = await tvlUsd();

return [
{
pool: APETH,
chain: utils.formatChain('ethereum'),
project: 'aqua-patina',
symbol: utils.formatSymbol('APETH'),
tvlUsd: tvl,
apy: apy.data.apy,
},
];
};

async function tvlUsd() {

const supply = await sdk.api.abi.call({
target: APETH,
abi: abi['totalSupply'],
chain: 'ethereum'
});

const multiplier = await sdk.api.abi.call({
target: APETH,
abi: abi['ethPerAPEth'],
chain: 'ethereum'
});

const ethPrice = (
await axios.get('https://coins.llama.fi/prices/current/coingecko:ethereum')
).data.coins['coingecko:ethereum'].price;

let tvl = BigInt(supply.output) * BigInt(multiplier.output) / BigInt(1e18) / BigInt(1e18);

return Number(tvl) * ethPrice;
}

module.exports = {
timetravel: false,
apy: getApy,
url: 'https://aquapatina.eth/',
};

0 comments on commit 5afa690

Please sign in to comment.