Skip to content

Commit bab8036

Browse files
authored
Merge pull request #2056 from prevostc/feat/cap-adapter
cap adapter
2 parents 32b7745 + 6c458ab commit bab8036

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

src/adaptors/cap/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const utils = require('../utils');
2+
const sdk = require('@defillama/sdk');
3+
const { capConfig, capABI } = require('./lib/configs');
4+
5+
6+
const poolsFunction = async () => {
7+
const chain = 'ethereum';
8+
const infra = capConfig[chain].infra;
9+
const cUSD = capConfig[chain].tokens.cUSD;
10+
const stcUSD = capConfig[chain].tokens.stcUSD;
11+
12+
const stcUSDInfos = await utils.getERC4626Info(stcUSD.address, chain);
13+
const cUSDPriceRes = await sdk.api.abi.call({
14+
abi: capABI.Oracle.getPrice,
15+
target: infra.oracle.address,
16+
chain,
17+
params: [cUSD.address],
18+
});
19+
20+
const cUSDPrice = BigInt(cUSDPriceRes.output[0]);
21+
const tvlCUSD = BigInt(stcUSDInfos.tvl);
22+
const tvlUsd = cUSDPrice * tvlCUSD / BigInt(10) ** BigInt(cUSD.decimals);
23+
const tvlUsdNum = Number(tvlUsd) / 10 ** infra.oracle.priceDecimals;
24+
25+
const stcUSDPool = {
26+
pool: stcUSDInfos.pool,
27+
chain: utils.formatChain(chain),
28+
project: 'cap',
29+
symbol: utils.formatSymbol(stcUSD.id),
30+
tvlUsd: tvlUsdNum,
31+
apy: stcUSDInfos.apyBase,
32+
};
33+
34+
return [stcUSDPool];
35+
};
36+
37+
module.exports = {
38+
apy: poolsFunction,
39+
url: 'https://cap.app',
40+
};

src/adaptors/cap/lib/configs.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
const capConfig = {
3+
ethereum: {
4+
fromBlock: 22867447,
5+
fromTime: 1751892875,
6+
infra: {
7+
oracle: {
8+
priceDecimals: 8,
9+
address: '0xcD7f45566bc0E7303fB92A93969BB4D3f6e662bb',
10+
fromBlock: 22867447,
11+
},
12+
lender: {
13+
address: '0x15622c3dbbc5614E6DFa9446603c1779647f01FC',
14+
fromBlock: 22867447,
15+
},
16+
delegation: {
17+
address: '0xF3E3Eae671000612CE3Fd15e1019154C1a4d693F',
18+
fromBlock: 22867447,
19+
},
20+
},
21+
tokens: {
22+
cUSD: {
23+
id: 'cUSD',
24+
coingeckoId: 'cap-usd',
25+
decimals: 18,
26+
address: '0xcCcc62962d17b8914c62D74FfB843d73B2a3cccC',
27+
fromBlock: 22874015,
28+
},
29+
stcUSD: {
30+
id: 'stcUSD',
31+
coingeckoId: 'cap-staked-usd',
32+
decimals: 18,
33+
address: '0x88887bE419578051FF9F4eb6C858A951921D8888',
34+
fromBlock: 22874056,
35+
},
36+
},
37+
symbiotic: {
38+
// no good way to fetch it on chain?
39+
networkMiddlewareToNetwork: {
40+
// this one is deprecated
41+
'0x8c9140fe6650e56a0a07e86455d745f8f7843b6d': '0x44f7e678e8412dbef1fd930f60af2bd125095962',
42+
43+
// this one is the new one (and default)
44+
'0x09a3976d8d63728d20dcdfee1e531c206ba91225': '0x98e52ea7578f2088c152e81b17a9a459bf089f2a',
45+
default: '0x98e52ea7578f2088c152e81b17a9a459bf089f2a',
46+
}
47+
}
48+
},
49+
};
50+
51+
const capABI = {
52+
Oracle: {
53+
getPrice: 'function getPrice(address _token) external view returns (uint256,uint256)',
54+
},
55+
Vault: {
56+
AddAssetEvent: 'event AddAsset(address asset)',
57+
totalSupplies: 'function totalSupplies(address _token) external view returns (uint256 totalSupply)',
58+
},
59+
Lender: {
60+
ReserveAssetAddedEvent: 'event ReserveAssetAdded(address indexed asset, address vault, address debtToken, address interestReceiver, uint256 id)',
61+
},
62+
Delegation: {
63+
AddAgentEvent: 'event AddAgent(address agent, address network, uint256 ltv, uint256 liquidationThreshold)',
64+
},
65+
SymbioticNetworkMiddleware: {
66+
coverageByVault: 'function coverageByVault(address _network, address _agent, address _vault, address _oracle, uint48 _timestamp) public view returns (uint256 collateralValue, uint256 collateral)',
67+
vaults: 'function vaults(address _agent) external view returns (address vaultAddress)',
68+
}
69+
}
70+
71+
const symbioticABI = {
72+
Vault: {
73+
collateral: 'function collateral() public view returns (address)',
74+
}
75+
}
76+
77+
module.exports = {
78+
capConfig,
79+
capABI,
80+
symbioticABI,
81+
}

0 commit comments

Comments
 (0)