forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new Sushi strategy and combine MIM + Sushi in arbitrum and add ne…
…w Aura strategy in ethereum (DefiLlama#6604) * new strategy * add new Sushi strategy and combine MIM + Sushi in arbitrum and add new Aura strategy in ethereum
- Loading branch information
Showing
4 changed files
with
260 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"strategyToId": "function strategyToId(address) view returns (uint256)", | ||
"strategies": "function strategies(uint256) view returns (tuple fees, uint256 totalDeposited, uint256 totalStaked, uint256 lastCompoundTimestamp, uint256 cap, uint256 rewardPerBlock, uint256 rewardPerShare, uint256 lastUpdatedBlockNumber, address strategy, uint32 timelock, bool isActive, address rewardToken, uint256 usersCount)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"eth": { | ||
"parallaxAddress": "0xd8935F1369E1dAc77CD37e664BC13ffdd741B962", | ||
"strategyAddress": "0x9E6121e89dD50B5D02362A9fdb7EC1fAd3D15725", | ||
"lpAddress": "0x5aee1e99fe86960377de9f88689616916d5dcabe", | ||
"feedAddress": "0x5f4ec3df9cbd43714fe2740f5e3616155c5b8419", | ||
"usdc": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" | ||
}, | ||
"arbitrum": { | ||
"mim": { | ||
"parallaxCoreAddress": "0x07F78cC2668F9Bb152c4026E801df68Ed3AB9858", | ||
"strategyAddress": "0xbf81Ba9D10F96ce0bb1206DE5F2d5B363f9796A9", | ||
"parallaxCoreAddressOld": "0x74A819d4925dC9f473F398863666Ac787B48e1d0", | ||
"strategyAddressOld": "0x7b8eFCd93ee71A0480Ad4dB06849B75573168AF4", | ||
"lpAddresss": "0x30dF229cefa463e991e29D42DB0bae2e122B2AC7", | ||
"usdc": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8" | ||
}, | ||
"sushi": { | ||
"parallaxAddr": "0xDCBEA8b2142Fe5E97BE9545FCFB30af812685Fb6", | ||
"strategyAddrSushi": "0xb53BbF686b600857B209B863c1Bce2C83acef123", | ||
"strategyAddrGMX": "0xF7caD5Ec40b5980Bd741346eAeE019c6E2b5D373", | ||
"parallaxBackendAddr": "0x1724623a721a094f8Ba9d271c9BE8be83e64f74f", | ||
"usdc": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const get_virtual_price = "function get_virtual_price() view returns (uint256)"; | ||
const getRate = "function getRate() view returns (uint256)"; | ||
const latestRoundData = | ||
"function latestRoundData() view returns (uint80 roundId,int256 answer,uint256 startedAt,uint256 updatedAt,uint80 answeredInRound)"; | ||
const getPrice = "function getPrice() view returns (uint256 sushi,uint256 gmx)"; | ||
const { default: BigNumber } = require("bignumber.js"); | ||
|
||
const getPriceMIM = async (tokenAddress, api) => { | ||
const priceLpWei = await api.call({ | ||
target: tokenAddress, | ||
abi: get_virtual_price, | ||
}) | ||
|
||
const decimals = await api.call({ | ||
target: tokenAddress, | ||
abi: "erc20:decimals", | ||
}) | ||
|
||
const tokenPrice = new BigNumber(priceLpWei).div(`1e${decimals}`); | ||
|
||
return { | ||
price: tokenPrice, | ||
decimals, | ||
}; | ||
}; | ||
|
||
const getPriceAura = async ( | ||
tokenAddress, | ||
feedAddress, | ||
api | ||
) => { | ||
const decimals = | ||
await api.call({ | ||
target: tokenAddress, | ||
abi: "erc20:decimals", | ||
}) | ||
|
||
const rate = | ||
await api.call({ | ||
target: tokenAddress, | ||
abi: getRate, | ||
}) | ||
|
||
const getLatestRoundData = | ||
await api.call({ | ||
target: feedAddress, | ||
abi: latestRoundData, | ||
}) | ||
|
||
const ethPriceInUSD = parseInt(getLatestRoundData.answer) / 10 ** 8; | ||
const priceETH = new BigNumber(rate).div(`1e${decimals}`); | ||
|
||
const tokenPrice = new BigNumber(priceETH * ethPriceInUSD).div( | ||
`1e${decimals}` | ||
); | ||
|
||
return { | ||
price: tokenPrice, | ||
decimals, | ||
}; | ||
}; | ||
|
||
const getPriceSushi = async (backendAddress, api) => { | ||
const sushiDecimals = 14, | ||
gmxDecimals = 8; | ||
|
||
const sushiGmxPrice = await api.call({ | ||
target: backendAddress, | ||
abi: getPrice, | ||
}) | ||
|
||
const sushiPrice = new BigNumber(sushiGmxPrice.sushi).div( | ||
`1e${sushiDecimals}` | ||
); | ||
const gmxPrice = new BigNumber(sushiGmxPrice.gmx).div(`1e${gmxDecimals}`); | ||
|
||
return { | ||
sushiPrice: sushiPrice, | ||
gmxPrice: gmxPrice, | ||
sushiDecimals, | ||
gmxDecimals, | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
getPriceMIM, | ||
getPriceAura, | ||
getPriceSushi, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,150 @@ | ||
async function tvl(time, _ethBlock, _1, { api }) { | ||
await Promise.all([addMIMStrategy(api)]); | ||
const sdk = require("@defillama/sdk"); | ||
const { default: BigNumber } = require("bignumber.js"); | ||
|
||
const { getPriceMIM, getPriceAura, getPriceSushi } = require("./getPrice"); | ||
|
||
const prllxERC20 = require("./abis/prllxERC20.json"); | ||
const contracts = require("./contracts.json"); | ||
|
||
async function ethTvl(time, _ethBlock, { ethereum: block }, { api }) { | ||
const strategyId = await api.call({ | ||
target: contracts.eth.parallaxAddress, | ||
params: contracts.eth.strategyAddress, | ||
abi: prllxERC20["strategyToId"], | ||
}) | ||
|
||
const strategy = await api.call({ | ||
target: contracts.eth.parallaxAddress, | ||
params: strategyId, | ||
abi: prllxERC20["strategies"], | ||
}) | ||
|
||
const balances = {}; | ||
const { price, decimals } = await getPriceAura(contracts.eth.lpAddress, contracts.eth.feedAddress, api,); | ||
|
||
// const totalStaked = new BigNumber(strategy.totalStaked).div(`1e${decimals}`); | ||
const totalStakedTVL = price | ||
.times(strategy.totalStaked) | ||
.times(1e6) | ||
.toFixed(0); | ||
|
||
sdk.util.sumSingleBalance( | ||
balances, | ||
`ethereum:${contracts.eth.usdc}`, | ||
totalStakedTVL | ||
); | ||
|
||
return balances; | ||
} | ||
|
||
async function addMIMStrategy(api) { | ||
const token = "0x30dF229cefa463e991e29D42DB0bae2e122B2AC7"; | ||
const sorbettiere = "0x839de324a1ab773f76a53900d70ac1b913d2b387"; | ||
// const strategy = "0x7b8eFCd93ee71A0480Ad4dB06849B75573168AF4"; | ||
const strategies = [ | ||
"0x7b8eFCd93ee71A0480Ad4dB06849B75573168AF4", | ||
"0xbf81Ba9D10F96ce0bb1206DE5F2d5B363f9796A9", | ||
]; | ||
for (let iterator = 0; iterator < strategies.length; iterator++) { | ||
const strategy = strategies[iterator]; | ||
const [bal] = await api.call({ | ||
abi: "function userInfo(uint256, address) view returns (uint256,uint256,uint256)", | ||
target: sorbettiere, | ||
params: [0, strategy], | ||
}); | ||
|
||
api.add(token, bal); | ||
} | ||
async function arbitrumTvl(time, _ethBlock, { arbitrum: block }, { api }) { | ||
const balances = {}; | ||
|
||
const strategyId = await api.call({ | ||
target: contracts.arbitrum.mim.parallaxCoreAddress, | ||
params: contracts.arbitrum.mim.strategyAddress, | ||
abi: prllxERC20["strategyToId"], | ||
}) | ||
|
||
const strategy = await api.call({ | ||
target: contracts.arbitrum.mim.parallaxCoreAddress, | ||
params: strategyId, | ||
abi: prllxERC20["strategies"], | ||
}) | ||
|
||
const { price, decimals } = await getPriceMIM(contracts.arbitrum.mim.lpAddresss, api); | ||
|
||
const totalStaked = new BigNumber(strategy.totalStaked).div(`1e${decimals}`); | ||
const totalStakedTVLMIM = price.times(totalStaked).times(1e6).toFixed(0); | ||
|
||
const strategyIdOld = await api.call({ | ||
target: contracts.arbitrum.mim.parallaxCoreAddressOld, | ||
params: contracts.arbitrum.mim.strategyAddressOld, | ||
abi: prllxERC20["strategyToId"], | ||
}) | ||
|
||
const strategyOld = | ||
await api.call({ | ||
target: contracts.arbitrum.mim.parallaxCoreAddressOld, | ||
params: strategyIdOld, | ||
abi: prllxERC20["strategies"], | ||
}) | ||
|
||
const totalStakedOld = new BigNumber(strategyOld.totalStaked).div( | ||
`1e${decimals}` | ||
); | ||
const totalStakedTVLMIMOld = price | ||
.times(totalStakedOld) | ||
.times(1e6) | ||
.toFixed(0); | ||
|
||
const totalStakedTVLMIMAll = | ||
Number(totalStakedTVLMIM) + Number(totalStakedTVLMIMOld); | ||
|
||
sdk.util.sumSingleBalance( | ||
balances, | ||
`arbitrum:${contracts.arbitrum.mim.usdc}`, | ||
totalStakedTVLMIMAll | ||
); | ||
|
||
const strategySushiId = | ||
await api.call({ | ||
target: contracts.arbitrum.sushi.parallaxAddr, | ||
params: contracts.arbitrum.sushi.strategyAddrSushi, | ||
abi: prllxERC20["strategyToId"], | ||
}) | ||
|
||
const strategyGmxId = await api.call({ | ||
target: contracts.arbitrum.sushi.parallaxAddr, | ||
params: contracts.arbitrum.sushi.strategyAddrGMX, | ||
abi: prllxERC20["strategyToId"], | ||
}) | ||
|
||
const strategySushi = await api.call({ | ||
target: contracts.arbitrum.sushi.parallaxAddr, | ||
params: strategySushiId, | ||
abi: prllxERC20["strategies"], | ||
}) | ||
|
||
const strategyGmx = await api.call({ | ||
target: contracts.arbitrum.sushi.parallaxAddr, | ||
params: strategyGmxId, | ||
abi: prllxERC20["strategies"], | ||
}) | ||
|
||
const { sushiPrice, gmxPrice, sushiDecimals, gmxDecimals } = await getPriceSushi(contracts.arbitrum.sushi.parallaxBackendAddr, api,); | ||
|
||
const totalStakedSushi = new BigNumber(strategySushi.totalStaked).div(`1e18`); | ||
const totalStakedGmx = new BigNumber(strategyGmx.totalStaked).div(`1e18`); | ||
|
||
const totalStakedTVLSushi = sushiPrice | ||
.times(totalStakedSushi) | ||
.times(1e6) | ||
.toFixed(0); | ||
|
||
const totalStakedTVLGmx = gmxPrice | ||
.times(totalStakedGmx) | ||
.times(1e6) | ||
.toFixed(0); | ||
|
||
const totalStakedTVL = | ||
Number(totalStakedTVLSushi) + Number(totalStakedTVLGmx); | ||
|
||
sdk.util.sumSingleBalance( | ||
balances, | ||
`arbitrum:${contracts.arbitrum.sushi.usdc}`, | ||
totalStakedTVL | ||
); | ||
|
||
return balances; | ||
} | ||
|
||
module.exports = { | ||
methodology: "TVL comes from the Staking Vaults", | ||
arbitrum: { | ||
tvl, | ||
tvl: arbitrumTvl, | ||
}, | ||
ethereum: { | ||
tvl: ethTvl, | ||
}, | ||
}; |