Skip to content

Commit 1704094

Browse files
authored
Refactor oETH (DefiLlama#11497)
1 parent 113c288 commit 1704094

File tree

2 files changed

+43
-58
lines changed

2 files changed

+43
-58
lines changed

projects/origindollar/index.js

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
1-
const sdk = require("@defillama/sdk");
21
const abi = require("./abi.json");
3-
const { staking, stakings } = require("../helper/staking");
2+
const { stakings } = require("../helper/staking");
43

54
const vault = "0xE75D77B1865Ae93c7eaa3040B038D7aA7BC02F70";
65

7-
const ethTvl = async (timestamp, ethBlock) => {
8-
const balances = {};
9-
10-
// Account DAI, USDT and USDC backing up the minted OUSD
11-
const stablecoins = (
12-
await sdk.api.abi.call({
13-
abi: abi.getAllAssets,
14-
target: vault,
15-
block: ethBlock,
16-
})
17-
).output;
18-
19-
for (let i = 0; i < stablecoins.length; i++) {
20-
const balance_stablecoin = (
21-
await sdk.api.abi.call({
22-
abi: abi.checkBalance,
23-
target: vault,
24-
params: stablecoins[i],
25-
block: ethBlock,
26-
})
27-
).output;
28-
29-
sdk.util.sumSingleBalance(balances, stablecoins[i], balance_stablecoin);
30-
}
31-
32-
return balances;
6+
const ethTvl = async (api) => {
7+
const tokens = await api.call({ abi: abi.getAllAssets, target: vault})
8+
const bals = await api.multiCall({ abi: abi.checkBalance, calls: tokens, target: vault})
9+
api.add(tokens, bals)
3310
};
3411

3512
module.exports = {

projects/originether/index.js

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
1-
const sdk = require("@defillama/sdk");
1+
const ADDRESSES = require('../helper/coreAssets.json')
22
const abi = require("../origindollar/abi.json");
33

4-
const vault = "0x39254033945aa2e4809cc2977e7087bee48bd7ab";
5-
6-
const ethTvl = async (timestamp, ethBlock) => {
7-
const balances = {};
8-
9-
// Account WETH, rETH, frxETH and stETH backing up the minted OUSD
10-
const backingAssets = (
11-
await sdk.api.abi.call({
12-
abi: abi.getAllAssets,
13-
target: vault,
14-
block: ethBlock,
15-
})
16-
).output;
17-
18-
for (let i = 0; i < backingAssets.length; i++) {
19-
const backingAssetBalance = (
20-
await sdk.api.abi.call({
21-
abi: abi.checkBalance,
22-
target: vault,
23-
params: backingAssets[i],
24-
block: ethBlock,
25-
})
26-
).output;
27-
28-
sdk.util.sumSingleBalance(balances, backingAssets[i], backingAssetBalance);
29-
}
30-
31-
return balances;
32-
};
4+
5+
const ethTvl = async (api) => {
6+
const vault = "0x39254033945aa2e4809cc2977e7087bee48bd7ab";
7+
const nativeStaking = '0x34eDb2ee25751eE67F68A45813B22811687C0238'
8+
const nativeStaking2 = '0x4685dB8bF2Df743c861d71E6cFb5347222992076'
9+
const stakingBalance1 = await api.call({ abi: abi.checkBalance, target: nativeStaking, params: ADDRESSES.ethereum.WETH })
10+
api.add(ADDRESSES.ethereum.WETH, stakingBalance1)
11+
const stakingBalance2 = await api.call({ abi: abi.checkBalance, target: nativeStaking2, params: ADDRESSES.ethereum.WETH })
12+
api.add(ADDRESSES.ethereum.WETH, stakingBalance2)
13+
14+
// add ETH part of curve LP
15+
const convexStrategy = '0x1827F9eA98E0bf96550b2FC20F7233277FcD7E63'
16+
const lp = await api.call({ abi: 'address:curvePool', target: convexStrategy})
17+
const ethIndex = await api.call({ abi: 'uint128:ethCoinIndex', target: convexStrategy})
18+
const lpBalance = await api.call({ abi: abi.checkBalance, target: convexStrategy, params: ADDRESSES.ethereum.WETH})
19+
const lpSupply = await api.call({ abi: 'erc20:totalSupply', target: lp})
20+
const ethInPool = await api.call({ abi: 'function balances(uint256) view returns (uint256)', target: lp, params: ethIndex})
21+
const ethLPBalance = (lpBalance / lpSupply) * ethInPool
22+
api.add(ADDRESSES.ethereum.WETH, ethLPBalance)
23+
24+
25+
return api.sumTokens({ owner: vault, tokens: [ADDRESSES.ethereum.WETH] })
26+
}
27+
28+
async function baseTvl(api) {
29+
const vault = '0x98a0CbeF61bD2D21435f433bE4CD42B56B38CC93'
30+
const aeroAMO = '0xF611cC500eEE7E4e4763A05FE623E2363c86d2Af'
31+
const dripper = await api.call({ target: vault, abi: 'function dripper() view returns (address)' })
32+
const [amountWeth, _amountOETH] = await api.call({ abi: 'function getPositionPrincipal() view returns (uint256, uint256)', target: aeroAMO })
33+
api.add(ADDRESSES.base.WETH, amountWeth)
34+
return api.sumTokens({ owners: [vault], tokens: [ADDRESSES.base.WETH] })
35+
36+
}
37+
3338

3439
module.exports = {
3540
ethereum: {
3641
tvl: ethTvl,
3742
},
43+
base: {
44+
tvl: baseTvl,
45+
},
3846
};

0 commit comments

Comments
 (0)