Skip to content

Commit 11ae8a3

Browse files
authored
Add Yield Adaptor for Plasma
1 parent b5539ba commit 11ae8a3

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/adaptors/enclabs/index.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
const sdk = require("@defillama/sdk");
22

3-
const CORE_POOL = {
3+
const CORE_SONIC_POOL = {
44
name: "Core Sonic Pool",
55
comptroller: "0xccAdFCFaa71407707fb3dC93D7d83950171aA2c9",
66
oracle: "0xd05b05590609c3610161e60eb41eC317c7562408",
77
};
88

9+
const CORE_PLASMA_POOL = {
10+
name: "Core Plasma Pool",
11+
comptroller: "0xA3F48548562A30A33257A752d396A20B4413E8E3",
12+
oracle: "0xd05b05590609c3610161e60eb41eC317c7562408",
13+
};
14+
915
const abi = {
1016
getAllMarkets: "function getAllMarkets() view returns (address[])",
1117
symbol: "function symbol() view returns (string)",
@@ -20,17 +26,17 @@ const abi = {
2026
markets: "function markets(address) view returns (bool, uint256, bool)",
2127
};
2228

23-
const BLOCKS_PER_YEAR = 31_536_000;
29+
const BLOCKS_PER_YEAR = 31_536_000;
2430

2531
function round(n) {
2632
return Math.round(n * 100) / 100;
2733
}
2834

29-
async function main() {
35+
async function getPoolsData(poolConfig, chain) {
3036
const { output: markets } = await sdk.api.abi.call({
31-
target: CORE_POOL.comptroller,
37+
target: poolConfig.comptroller,
3238
abi: abi.getAllMarkets,
33-
chain: "sonic",
39+
chain,
3440
});
3541

3642
const pools = [];
@@ -39,15 +45,15 @@ async function main() {
3945
const { output: cTokenSymbol } = await sdk.api.abi.call({
4046
target: market,
4147
abi: abi.symbol,
42-
chain: "sonic",
48+
chain,
4349
});
4450

4551
let underlying = market;
4652
try {
4753
const { output } = await sdk.api.abi.call({
4854
target: market,
4955
abi: abi.underlying,
50-
chain: "sonic",
56+
chain,
5157
});
5258
underlying = output;
5359
} catch {}
@@ -57,7 +63,7 @@ async function main() {
5763
const { output: symbol } = await sdk.api.abi.call({
5864
target: underlying,
5965
abi: abi.symbol,
60-
chain: "sonic",
66+
chain,
6167
});
6268
underlyingSymbol = symbol;
6369
} catch {}
@@ -67,7 +73,7 @@ async function main() {
6773
const { output: d } = await sdk.api.abi.call({
6874
target: underlying,
6975
abi: abi.decimals,
70-
chain: "sonic",
76+
chain,
7177
});
7278
decimals = Number(d);
7379
} catch {}
@@ -81,23 +87,13 @@ async function main() {
8187
{ output: priceRaw },
8288
{ output: marketData },
8389
] = await Promise.all([
84-
sdk.api.abi.call({ target: market, abi: abi.totalSupply, chain: "sonic" }),
85-
sdk.api.abi.call({ target: market, abi: abi.exchangeRateStored, chain: "sonic" }),
86-
sdk.api.abi.call({ target: market, abi: abi.totalBorrows, chain: "sonic" }),
87-
sdk.api.abi.call({ target: market, abi: abi.supplyRatePerBlock, chain: "sonic" }),
88-
sdk.api.abi.call({ target: market, abi: abi.borrowRatePerBlock, chain: "sonic" }),
89-
sdk.api.abi.call({
90-
target: CORE_POOL.oracle,
91-
abi: abi.getUnderlyingPrice,
92-
params: [market],
93-
chain: "sonic",
94-
}),
95-
sdk.api.abi.call({
96-
target: CORE_POOL.comptroller,
97-
abi: abi.markets,
98-
params: [market],
99-
chain: "sonic",
100-
}),
90+
sdk.api.abi.call({ target: market, abi: abi.totalSupply, chain }),
91+
sdk.api.abi.call({ target: market, abi: abi.exchangeRateStored, chain }),
92+
sdk.api.abi.call({ target: market, abi: abi.totalBorrows, chain }),
93+
sdk.api.abi.call({ target: market, abi: abi.supplyRatePerBlock, chain }),
94+
sdk.api.abi.call({ target: market, abi: abi.borrowRatePerBlock, chain }),
95+
sdk.api.abi.call({ target: poolConfig.oracle, abi: abi.getUnderlyingPrice, params: [market], chain }),
96+
sdk.api.abi.call({ target: poolConfig.comptroller, abi: abi.markets, params: [market], chain }),
10197
]);
10298

10399
const exchangeRate = Number(exchangeRateRaw) / 1e18;
@@ -121,8 +117,8 @@ async function main() {
121117
} catch {}
122118

123119
pools.push({
124-
pool: `${market}-sonic`.toLowerCase(),
125-
chain: "Sonic",
120+
pool: `${market}-${chain}`.toLowerCase(),
121+
chain: chain.charAt(0).toUpperCase() + chain.slice(1),
126122
project: "enclabs",
127123
symbol: underlyingSymbol,
128124
tvlUsd: round(tvlUsd),
@@ -132,15 +128,21 @@ async function main() {
132128
totalBorrowUsd: round(totalBorrowUsd),
133129
ltv: round(ltv),
134130
underlyingTokens: [underlying],
135-
poolMeta: CORE_POOL.name,
131+
poolMeta: poolConfig.name,
136132
});
137133
}
138134

139135
return pools;
140136
}
141137

138+
async function main() {
139+
const sonicPools = await getPoolsData(CORE_SONIC_POOL, "sonic");
140+
const plasmaPools = await getPoolsData(CORE_PLASMA_POOL, "plasma");
141+
return [...sonicPools, ...plasmaPools];
142+
}
143+
142144
module.exports = {
143145
timetravel: false,
144146
apy: main,
145147
url: "https://www.enclabs.finance",
146-
};
148+
}

0 commit comments

Comments
 (0)