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

feat: Adapter, defi.money #11330

Merged
merged 7 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
52 changes: 52 additions & 0 deletions projects/defi-money-cdp/index.js
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",
Copy link
Member

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)

tvl: (api) => getTvl(api, controller, viewer),
};
});
61 changes: 61 additions & 0 deletions projects/defi-money-earn/index.js
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 })),
Copy link
Member

Choose a reason for hiding this comment

The 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),
};
});
Loading