Skip to content

Commit 27a2c08

Browse files
authored
add Sturdy v2 (DefiLlama#8963)
1 parent 9a68b18 commit 27a2c08

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

projects/sturdy-v2/abi.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"getStrategies": "function getStrategies() view returns (tuple(address deployedAt, address pair, tuple(address asset, string assetSymbol, uint256 assetDecimals, address collateral, string collateralSymbol, uint256 collateralDecimals, address rateContract, address oracle, uint256 depositLimit, uint64 ratePerSec, uint64 fullUtilizationRate, uint32 feeToProtocolRate, uint32 maxOacleDeviation, uint256 lowExchangeRate, uint256 highExchangeRate, uint256 maxLTV, uint256 protocolLiquidationFee, uint256 totalAsset, uint256 totalCollateral, uint256 totalBorrow, uint256 version) pairData)[])",
3+
"getVaults": "function getVaults() view returns (tuple(address deployedAt, bool isShutdown, address asset, string assetSymbol, uint256 assetDecimals, string name, uint256 totalAssets, uint256 totalDebt)[])"
4+
5+
}

projects/sturdy-v2/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const abi = require("./abi.json");
2+
3+
const REGISTRY_ADDR = "0x69764E3e0671747A7768A1C1AfB7C0C39868CC9e"
4+
5+
async function tvl(timestamp, block, chainBlocks, { api }) {
6+
const aggregators = await api.call({target: REGISTRY_ADDR, abi: abi['getVaults'], })
7+
const totalAssets = aggregators.forEach((aggregator) => api.add(aggregator.asset, aggregator.totalAssets))
8+
9+
const strategies = await api.call({ target: REGISTRY_ADDR, abi: abi['getStrategies'], })
10+
const totalCollaterals = strategies.forEach((strategy) => api.add(strategy.pairData.collateral, strategy.pairData.totalCollateral))
11+
12+
return totalAssets + totalCollaterals;
13+
}
14+
async function borrowed(timestamp, block, chainBlocks, { api }) {
15+
const strategies = await api.call({ target: REGISTRY_ADDR, abi: abi['getStrategies'], })
16+
const pairs = strategies.map((strategy) => strategy.pair);
17+
const assets = strategies.map((strategy) => strategy.pairData.asset);
18+
const bals = await api.multiCall({ abi: 'function totalBorrow() view returns (uint128 amount, uint128 shares)', calls: pairs })
19+
bals.forEach((bal, i) => api.add(assets[i], bal.amount))
20+
}
21+
22+
module.exports = {
23+
methodology: 'Gets the aggregators & strategies from the REGISTRY_ADDRESS and adds the asset amounts from each of them',
24+
ethereum: {
25+
tvl, borrowed,
26+
},
27+
}

0 commit comments

Comments
 (0)