From 5afa6905bb81b94ad2d7e81cd8655ffdee8442ee Mon Sep 17 00:00:00 2001 From: Stefaan Ponnet Date: Tue, 26 Nov 2024 15:26:24 +0100 Subject: [PATCH] Aqua Patina APY adapter (#1597) * init * calculate apy+tvl * tvl calculation using BigInt to avoid potential overflows * reads 10-day moving average --------- Co-authored-by: 0xwildhare --- src/adaptors/aqua-patina/abi.json | 28 ++++++++++++++++ src/adaptors/aqua-patina/index.js | 54 +++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/adaptors/aqua-patina/abi.json create mode 100644 src/adaptors/aqua-patina/index.js diff --git a/src/adaptors/aqua-patina/abi.json b/src/adaptors/aqua-patina/abi.json new file mode 100644 index 000000000..e85509e94 --- /dev/null +++ b/src/adaptors/aqua-patina/abi.json @@ -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" + } +} \ No newline at end of file diff --git a/src/adaptors/aqua-patina/index.js b/src/adaptors/aqua-patina/index.js new file mode 100644 index 000000000..8bd7492ea --- /dev/null +++ b/src/adaptors/aqua-patina/index.js @@ -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/', +}; \ No newline at end of file