Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apy dexfinance farms #1398

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/adaptors/dexfinance-arbitrum/abi/FARM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const FARM = [
{
'inputs': [
{
'internalType': 'address',
'name': '',
'type': 'address'
}
],
'name': 'sharePerTimeUnit',
'outputs': [
{
'internalType': 'uint256',
'name': '',
'type': 'uint256'
}
],
'stateMutability': 'view',
'type': 'function'
},
]

module.exports = {
FARM
}
46 changes: 46 additions & 0 deletions src/adaptors/dexfinance-arbitrum/abi/LP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const LP_ABI = [
{
'constant': true,
'inputs': [],
'name': 'getReserves',
'outputs': [
{
'internalType': 'uint112',
'name': '_reserve0',
'type': 'uint112'
},
{
'internalType': 'uint112',
'name': '_reserve1',
'type': 'uint112'
},
{
'internalType': 'uint32',
'name': '_blockTimestampLast',
'type': 'uint32'
}
],
'payable': false,
'stateMutability': 'view',
'type': 'function'
},
{
'constant': true,
'inputs': [],
'name': 'totalSupply',
'outputs': [
{
'internalType': 'uint256',
'name': '',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'view',
'type': 'function'
}
]

module.exports = {
LP_ABI,
}
107 changes: 107 additions & 0 deletions src/adaptors/dexfinance-arbitrum/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
const sdk = require('@defillama/sdk');
const BigNumber = require('bignumber.js');
const { LP_ABI } = require('./abi/LP');
const { FARM } = require('./abi/FARM');
const utils = require('../utils');


const TOKENS = {
GDEX: '0x92a212d9f5eef0b262ac7d84aea64a0d0758b94f',
USDEX: '0x4117ec0a779448872d3820f37ba2060ae0b7c34b',
}
const SECONDS_IN_YEAR = 24 * 60 * 60 * 365;
const pairsDexswap = [
{
name: 'USDEX+/USDC',
address: '0x24129a6c5b700435cc0d1bd3500796f3fb9ebd49',
},
{
name: 'USDEX+/gDEX',
address: '0x0e75ca30b075aa0df8c360e30cd0ed26ed62432a',
}
];

const originFarms = [
{
symbol: 'GDEX',
origin: '0xde1e437e0be59b596e69ff58e2bda9209a72ce8b',
stakingToken: '0x92a212d9f5eef0b262ac7d84aea64a0d0758b94f',
connector: '0x0b8905bb2ab1bae7b081d5b8cc9d906f01dd3b82',
rewardToken: '0x4117ec0a779448872d3820f37ba2060ae0b7c34b',
},
{
symbol: 'USDEX+/GDEX',
origin: '0x74337fb8381ce8c323110cef2e041d0f2220a2ce',
stakingToken: '0x0e75ca30b075aa0df8c360e30cd0ed26ed62432a',
connector: '0xa7fbbdf114f1f2218825a500515b6bf7d49c1b2c',
rewardToken: '0x4117ec0a779448872d3820f37ba2060ae0b7c34b',
}
]

PROJECT_SLUG = 'dexfinance-arbitrum';

async function getDexSwapPrices() {
const lpInfo = [];
for (const pair of pairsDexswap) {
const { output: reserves } = await sdk.api.abi.call({
target: pair.address,
abi: LP_ABI[0],
chain: 'arbitrum',
})
const { output: totalSupply } = await sdk.api.abi.call({
target: pair.address,
abi: LP_ABI[1],
chain: 'arbitrum',
})
lpInfo.push({ ...reserves, totalSupply });
}
const [lpInfo0, lpInfo1] = lpInfo;
const usdcWithoutDecimalsBN = new BigNumber(lpInfo0['1']).div(10 ** 6);
const usdexPair0PlusWithoutDecimalsBN = new BigNumber(lpInfo0['0']).div(10 ** 18);
const gdexWithoutDecimalsBN = new BigNumber(lpInfo1['1']).div(10 ** 18);
const usdexPair1PlusWithoutDecimalsBN = new BigNumber(lpInfo1['0']).div(10 ** 18);
const usdexPriceUsd = usdcWithoutDecimalsBN.div(usdexPair0PlusWithoutDecimalsBN).toString();
const totalPriceToGdexPairBN = gdexWithoutDecimalsBN.times(usdexPriceUsd);
const priceGdexBN = usdexPair1PlusWithoutDecimalsBN.div(totalPriceToGdexPairBN);

const totalSupplyBN = new BigNumber(lpInfo1.totalSupply).div(10 ** 18);
const priceLpGdexUsdex = usdexPair1PlusWithoutDecimalsBN.times(usdexPriceUsd).plus(priceGdexBN.times(gdexWithoutDecimalsBN)).div(totalSupplyBN).toString();
return {
[TOKENS.GDEX]: priceGdexBN.toString(),
[TOKENS.USDEX]: usdexPriceUsd,
[pairsDexswap[1].address]: priceLpGdexUsdex,
}

}

async function getGdexFarmsApy() {
const prices = await getDexSwapPrices();
const res = [];
for (const origin of originFarms) {
const { output: balance } = await sdk.api.abi.call({ chain: 'arbitrum', abi: 'erc20:balanceOf', target: origin.stakingToken, params: origin.origin });
const tvlUsd = new BigNumber(balance).div(10 ** 18).times(prices[origin.stakingToken]).toNumber();
const { output: sharePerTimeUnit } = await sdk.api.abi.call({
target: origin.connector,
chain: 'arbitrum',
abi: FARM[0],
params: [origin.rewardToken],
});
const rewardsPerSecondUsdBN = new BigNumber(sharePerTimeUnit).div(10 ** 18).times(prices[origin.rewardToken]).times(100);
const rewardPerYearUsdBN = rewardsPerSecondUsdBN.times(SECONDS_IN_YEAR);
const apy = rewardPerYearUsdBN.div(tvlUsd).toNumber();
res.push({
pool: origin.origin,
chain: utils.formatChain('arbitrum'),
project: PROJECT_SLUG,
symbol: origin.symbol,
tvlUsd,
apy,
url: 'https://www.dexfinance.com/',
})
}
return res;
}

module.exports = {
apy: getGdexFarmsApy,
};
Loading