-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Ripe Protocol #16586
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
base: main
Are you sure you want to change the base?
Ripe Protocol #16586
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
const SGREEN_CONTRACT = '0xaa0f13488ce069a7b5a099457c753a7cfbe04d36' | ||
const GREEN_CONTRACT = '0xd1Eac76497D06Cf15475A5e3984D5bC03de7C707' | ||
const LEGO_TOOLS_CONTRACT = '0x3F8aE1C72a2Ca223CAe3f3e3312DBee55C4C6d5F'; | ||
const USDC_CONTRACT = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913' | ||
const GREEN_LP_CONTRACT = '0xd6c283655b42fa0eb2685f7ab819784f071459dc' | ||
const RIPE_CONTRACT = '0x2A0a59d6B975828e781EcaC125dBA40d7ee5dDC0' | ||
const RIPE_GREEN_LP_CONTRACT = '0x2aEf3eE3Eb64B7EC0B4ef57BB7E004747FE87eFc' | ||
const RIPE_WETH_LP_CONTRACT = '0x765824aD2eD0ECB70ECc25B0Cf285832b335d6A9' | ||
const ENDAOMENT_CONTRACT = '0x14F4f1CD5F4197DB7cB536B282fe6c59eACfE40d' | ||
const RIPE_GOV_CONTRACT = '0xe42b3dC546527EB70D741B185Dc57226cA01839D' | ||
const LEDGER_CONTRACT = '0x365256e322a47Aa2015F6724783F326e9B24fA47' | ||
|
||
const ONE_HUNDRED = BigInt(10000) | ||
const RIPE_MAX_SUPPLY = BigInt(1000000000) * BigInt(10) ** BigInt(18) | ||
|
||
async function getGreenLpValues(api, address){ | ||
const [usdcBalance, greenBalance, greenLpSupply, addressLp] = await Promise.all([ | ||
api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: USDC_CONTRACT, | ||
params: [GREEN_LP_CONTRACT], | ||
}), | ||
api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: GREEN_CONTRACT, | ||
params: [GREEN_LP_CONTRACT], | ||
}), | ||
api.call({ | ||
abi: 'erc20:totalSupply', | ||
target: GREEN_LP_CONTRACT, | ||
}), | ||
api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: GREEN_LP_CONTRACT, | ||
params: [address] | ||
}), | ||
]) | ||
|
||
const usdc = BigInt(usdcBalance) | ||
const green = BigInt(greenBalance) | ||
const lpAddressShare = (BigInt(addressLp) * ONE_HUNDRED) / BigInt(greenLpSupply) | ||
|
||
const usdcFinal = (lpAddressShare * usdc) / ONE_HUNDRED | ||
const greenFinal = (lpAddressShare * green) / ONE_HUNDRED | ||
|
||
api.add(USDC_CONTRACT, usdcFinal) | ||
api.add(GREEN_CONTRACT, greenFinal) | ||
} | ||
|
||
async function getPairs(){ | ||
const response = await fetch('https://api.ripe.finance/api/ripe/assets'); | ||
const assets = await response.json(); | ||
const assetsArray = assets.result.filter(a => a.tokenAddress.toLowerCase() !== SGREEN_CONTRACT.toLowerCase() && a.tokenAddress.toLowerCase() !== GREEN_LP_CONTRACT.toLowerCase()); | ||
const stabilityPoolAddress = assets.result.find(a => a.vaultId === 1).vaultAddress | ||
const nonSpAssets = assetsArray.filter(a => a.vaultId > 2) | ||
|
||
const assetVaultPairs = [ | ||
...nonSpAssets.map(({ tokenAddress, vaultAddress }) => [tokenAddress, vaultAddress]), | ||
...nonSpAssets.map(({ tokenAddress }) => [tokenAddress, stabilityPoolAddress]), | ||
[GREEN_CONTRACT, SGREEN_CONTRACT], | ||
[USDC_CONTRACT, ENDAOMENT_CONTRACT], | ||
[GREEN_CONTRACT, ENDAOMENT_CONTRACT] | ||
]; | ||
|
||
return {assetVaultPairs, stabilityPoolAddress}; | ||
} | ||
|
||
async function tvl(api) { | ||
const { assetVaultPairs: pairs, stabilityPoolAddress } = await getPairs(); | ||
|
||
const calls = pairs.map(([token, vault]) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use multicall here instead? |
||
return api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: token, | ||
params: [vault], | ||
}); | ||
}); | ||
|
||
const balances = await Promise.all(calls); | ||
|
||
const underlyingCalls = pairs.map(([token], index) => { | ||
return api.call({ | ||
abi: "function getUnderlyingData(address, uint256) view returns (tuple(address asset, uint256 amount, uint256 usdValue, uint256 legId, address legoAddr, string legoDesc))", | ||
target: LEGO_TOOLS_CONTRACT, | ||
params: [token, balances[index]], | ||
|
||
}) | ||
}) | ||
|
||
const underlyingBalances = await Promise.all(underlyingCalls); | ||
underlyingBalances.forEach(({asset, amount}) => { | ||
if(amount !== '0'){ | ||
api.add(asset, amount); | ||
} | ||
}); | ||
|
||
await getGreenLpValues(api, stabilityPoolAddress) | ||
await getGreenLpValues(api, ENDAOMENT_CONTRACT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these shouldnt be included in TVL. Its Curve TVL and any GREEN is double counting the underlying collateral TVLs |
||
} | ||
|
||
async function vesting(api){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vesting export is more for token streaming services etc where they facilitate vesting for third parties - I think we should remove it here (if I understand the project correctly) |
||
const [endaoRipe, totalSupply] = await Promise.all([ | ||
api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: RIPE_CONTRACT, | ||
params: [ENDAOMENT_CONTRACT] | ||
}), | ||
api.call({ | ||
abi: 'erc20:totalSupply', | ||
target: RIPE_CONTRACT | ||
}) | ||
]) | ||
|
||
const total = RIPE_MAX_SUPPLY + BigInt(endaoRipe) - BigInt(totalSupply) | ||
api.add(RIPE_CONTRACT, total) | ||
} | ||
|
||
async function staking(api){ | ||
const ripeStaked = await api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: RIPE_CONTRACT, | ||
params: [RIPE_GOV_CONTRACT] | ||
}) | ||
|
||
api.add(RIPE_CONTRACT, ripeStaked) | ||
} | ||
|
||
async function pool2(api){ | ||
const [ripeWethLp, endaoRipeGreenLp] = await Promise.all([ | ||
api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: RIPE_WETH_LP_CONTRACT, | ||
params: [RIPE_GOV_CONTRACT] | ||
}), | ||
api.call({ | ||
abi: 'erc20:balanceOf', | ||
target: RIPE_GREEN_LP_CONTRACT, | ||
params: [ENDAOMENT_CONTRACT] | ||
}), | ||
]) | ||
|
||
api.add(RIPE_WETH_LP_CONTRACT, ripeWethLp) | ||
api.add(RIPE_GREEN_LP_CONTRACT, endaoRipeGreenLp) | ||
} | ||
|
||
async function borrowed(api){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont use borrowed for CDPs, this can be removed |
||
const borrowed = await api.call({ | ||
abi: "function totalDebt() view returns (uint256)", | ||
target: LEDGER_CONTRACT, | ||
}) | ||
|
||
api.add(GREEN_CONTRACT, borrowed) | ||
} | ||
|
||
module.exports = { | ||
methodology: 'Ripe Protocol', | ||
start: 1754006400, | ||
base: { | ||
tvl, | ||
pool2, | ||
vesting, | ||
staking, | ||
borrowed | ||
}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get a 500 from this endpoint