-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat: Adapter, defi.money #11330
Merged
Merged
feat: Adapter, defi.money #11330
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aebdb7a
feat:Adapter, defi-money
c2c7820
add methodology
bceba01
add yield part
7dd5eee
doublecounted: true
9bf9b3c
split project in two different products
c5fed5c
code refactor
g1nt0ki 46443bb
remove pool2
g1nt0ki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,52 @@ | ||
const abi = { | ||
markets: "function get_all_markets() view returns (address[] memory)", | ||
coll: "function get_all_collaterals() view returns (address[] memory)", | ||
state: `function get_market_states(address[] markets) view returns ( | ||
(uint256 total_debt, uint256 total_coll, uint256 debt_ceiling, uint256 remaining_mintable, uint256 oracle_price, uint256 current_rate, uint256 pending_rate)[] | ||
)`, | ||
}; | ||
|
||
const config = { | ||
optimism: { | ||
controller: "0x1337F001E280420EcCe9E7B934Fa07D67fdb62CD", | ||
viewer: "0x4459FF9D7FE90FD550c0b9d39E00b4f18b13A0Ab", | ||
}, | ||
arbitrum: { | ||
controller: "0x1337F001E280420EcCe9E7B934Fa07D67fdb62CD", | ||
viewer: "0x45D92BF29f1b5B0e7eb0640D6230Fae488311845", | ||
}, | ||
}; | ||
|
||
const getVaults = async (api, controller) => { | ||
const [colls, markets] = await Promise.all([ | ||
api.call({ target: controller, abi: abi.coll }), | ||
api.call({ target: controller, abi: abi.markets }), | ||
]); | ||
|
||
return colls.map((coll, index) => { | ||
const market = markets[index]; | ||
return { coll, market }; | ||
}); | ||
}; | ||
|
||
const getVaultsBalances = async (api, viewer, vaults) => { | ||
const markets = vaults.map(({ market }) => market); | ||
const states = await api.call({ target: viewer, params: [markets], abi: abi.state}); | ||
vaults.forEach(({ coll }, index) => { | ||
const totalSupply = states[index].total_coll; | ||
api.add(coll, totalSupply); | ||
}); | ||
}; | ||
|
||
const getTvl = async (api, controller, viewer) => { | ||
const vaults = await getVaults(api, controller); | ||
await getVaultsBalances(api, viewer, vaults); | ||
}; | ||
|
||
Object.keys(config).forEach((chain) => { | ||
const { controller, viewer } = config[chain]; | ||
module.exports[chain] = { | ||
methodology: "TVL corresponds to the collateral deposited in the markets", | ||
tvl: (api) => getTvl(api, controller, viewer), | ||
}; | ||
}); |
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,61 @@ | ||
const abi = { | ||
stakeToken: "function STAKE_TOKEN() view returns (address)", | ||
}; | ||
|
||
const config = { | ||
optimism: { | ||
MONEY: "0x7e803F4edd6528caFBf5C5d03Cc106b04379C24b", | ||
stakeLPs: [ | ||
"0x7e803F4edd6528caFBf5C5d03Cc106b04379C24b", // MONEY | ||
"0xE8f00491afa68B4A653C77e5f92DBA0F8df3a185", // crvUSD/MONEY | ||
"0xa398a48C2738fd6c79F5654823Fb93456B0fDaF6", // USDT/MONEY | ||
"0x36afCD1083eE9186A2b984E10d75C1E14b99B75e", // USDC/MONEY | ||
"0xcf38a66DeD7825cfEF66046c256Aa0EDbd41BEf5", // DAI/MONEY | ||
"0x73C3eC2b8e00929824a529e60fb6ed8aF193c7cc", // FRAX/MONEY | ||
], | ||
}, | ||
arbitrum: { | ||
MONEY: "0xEbE54BEE7A397919C53850bA68E126b0A6b295ed", | ||
stakeLPs: [ | ||
"0xEbE54BEE7A397919C53850bA68E126b0A6b295ed", // MONEY | ||
"0xF2852d7e810d3EC7094bFE1D7DDCa5044c259c25", // crvUSD/MONEY | ||
"0x6e59b326984fC132F16a977cd20E38641A9043De", // USDT/MONEY | ||
"0xdE718A791226c93B53C77D60E5D4693C05a31422", // USDC/MONEY | ||
"0xE3763d545707F435e21eeBbe75070495c806B744", // DAI/MONEY | ||
"0x07aDF588508b923B8eA0389d27b61b9CB8a197Cb", // FRAX/MONEY | ||
], | ||
}, | ||
}; | ||
|
||
const getLPTokens = async (api, stakingContracts) => { | ||
const stakeTokens = await api.multiCall({ | ||
calls: stakingContracts.map((address) => ({ target: address })), | ||
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. this wrapping is not needed |
||
abi: abi.stakeToken, | ||
}); | ||
return stakingContracts.map((contract, index) => ({ contract, token: stakeTokens[index], | ||
})); | ||
}; | ||
|
||
const getLPBalances = async (api, stakingLPs) => { | ||
const calls = stakingLPs.map(({ contract }) => ({ target: contract })); | ||
const totalSupplies = await api.multiCall({ calls, abi: "erc20:totalSupply" }); | ||
stakingLPs.forEach(({ token }, index) => { | ||
const totalSupply = totalSupplies[index]; | ||
api.add(token, totalSupply); | ||
}); | ||
}; | ||
|
||
const getTvl = async (api, stakingLPs, MONEY) => { | ||
const stakingWithLP = await getLPTokens(api, stakingLPs); | ||
await getLPBalances(api, stakingWithLP); | ||
api.removeTokenBalance(MONEY); | ||
}; | ||
|
||
Object.keys(config).forEach((chain) => { | ||
const { stakeLPs, MONEY } = config[chain]; | ||
module.exports[chain] = { | ||
doublecounted: true, | ||
methodology: "TVL corresponds to the LPs staked in the protocol to earn yield.", | ||
tvl: (api) => getTvl(api, stakeLPs, MONEY), | ||
}; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we set the methodology at the top level, not per chain
I am not a fan of this pattern of splitting into micro functions as I have to read bottom up, feel like it is easier if everything is in a single function so one can read it like a script (just a suggestion)