Skip to content

Commit 221dd24

Browse files
authored
Add Pinto protocol TVL (DefiLlama#13430)
2 parents 80415bf + 1e89ec9 commit 221dd24

File tree

1 file changed

+184
-0
lines changed

1 file changed

+184
-0
lines changed

projects/pinto/index.js

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
const ADDRESSES = require('../helper/coreAssets.json')
2+
3+
const ADDR = {
4+
base: {
5+
DIAMOND: "0xd1a0d188e861ed9d15773a2f3574a2e94134ba8f",
6+
PINTO: "0xb170000aeefa790fa61d6e837d1035906839a3c8",
7+
PINTOWETH: "0x3e11001cfbb6de5737327c59e10afab47b82b5d3",
8+
PINTOCBETH: "0x3e111115a82df6190e36adf0d552880663a4dbf1",
9+
PINTOCBBTC: "0x3e11226fe3d85142b734abce6e58918d5828d1b4",
10+
PINTOWSOL: "0x3e11444c7650234c748d743d8d374fce2ee5e6c9",
11+
PINTOUSDC: "0x3e1133ac082716ddc3114bbefeed8b1731ea9cb1",
12+
// Underlying non-pinto tokens
13+
WETH: ADDRESSES.base.WETH,
14+
CBETH: "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22",
15+
CBBTC: "0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf",
16+
WSOL: "0x1c61629598e4a901136a81bc138e5828dc150d67",
17+
USDC: ADDRESSES.base.USDC
18+
}
19+
};
20+
21+
const DEPLOYMENT = 1732035400;
22+
23+
// List of whitelisted pools and time time periods they are valid
24+
const ALL_POOLS = {
25+
base: {
26+
[ADDR.base.PINTOWETH]: {
27+
startTime: DEPLOYMENT,
28+
endTime: Number.MAX_SAFE_INTEGER,
29+
underlying: [ADDR.base.PINTO, ADDR.base.WETH]
30+
},
31+
[ADDR.base.PINTOCBETH]: {
32+
startTime: DEPLOYMENT,
33+
endTime: Number.MAX_SAFE_INTEGER,
34+
underlying: [ADDR.base.PINTO, ADDR.base.CBETH]
35+
},
36+
[ADDR.base.PINTOCBBTC]: {
37+
startTime: DEPLOYMENT,
38+
endTime: Number.MAX_SAFE_INTEGER,
39+
underlying: [ADDR.base.PINTO, ADDR.base.CBBTC]
40+
},
41+
[ADDR.base.PINTOWSOL]: {
42+
startTime: DEPLOYMENT,
43+
endTime: Number.MAX_SAFE_INTEGER,
44+
underlying: [ADDR.base.PINTO, ADDR.base.WSOL]
45+
},
46+
[ADDR.base.PINTOUSDC]: {
47+
startTime: DEPLOYMENT,
48+
endTime: Number.MAX_SAFE_INTEGER,
49+
underlying: [ADDR.base.PINTO, ADDR.base.USDC]
50+
}
51+
},
52+
};
53+
54+
function invalidTime(api) {
55+
return api.timestamp < DEPLOYMENT;
56+
}
57+
58+
// Returns the whitelilisted pools for the given timestamp
59+
function getPools(api) {
60+
const { chain, timestamp } = api;
61+
const pools = [];
62+
for (const contract in ALL_POOLS[chain]) {
63+
const pool = ALL_POOLS[chain][contract];
64+
if (timestamp >= pool.startTime && timestamp <= pool.endTime) {
65+
pools.push(contract);
66+
}
67+
}
68+
return pools;
69+
}
70+
71+
// Gets the total supply of the given erc20 token
72+
async function getTotalSupply(api, token) {
73+
const tokenSupply = await api.call({
74+
abi: 'erc20:totalSupply',
75+
target: token
76+
});
77+
return Number(tokenSupply);
78+
}
79+
80+
// Gets the reserves of the requested pool
81+
async function getPoolReserves(api, pool) {
82+
83+
pool = pool.toLowerCase();
84+
const poolBalances = await api.multiCall({
85+
calls: ALL_POOLS[api.chain][pool].underlying.map(token => ({
86+
target: token,
87+
params: pool
88+
})),
89+
abi: 'erc20:balanceOf'
90+
});
91+
92+
return poolBalances.map((balance, i) => ({ token: ALL_POOLS[api.chain][pool].underlying[i], balance }));
93+
}
94+
95+
// Returns the total silo'd amount of the requested token
96+
async function getSiloDeposited(api, token) {
97+
const deposited = await api.call({
98+
abi: "function getTotalDeposited(address) external view returns (uint256)",
99+
target: ADDR[api.chain].DIAMOND,
100+
params: token
101+
});
102+
const germinating = await api.call({
103+
abi: "function getGerminatingTotalDeposited(address) external view returns (uint256)",
104+
target: ADDR[api.chain].DIAMOND,
105+
params: token
106+
});
107+
return parseInt(deposited) + parseInt(germinating);
108+
}
109+
110+
/**
111+
* Returns the balances of the underlying tokens in the given pools of the given ratios
112+
* @param {*} api
113+
* @param {string[]} pools - the pools to calculate the balances for
114+
* @param {number[]} ratios - proportions of the pool underlying to credit towards the resulting balance
115+
*/
116+
async function getPooledBalances(api, pools, ratios) {
117+
118+
const pooledTokenBalances = {};
119+
120+
const poolReserves = await Promise.all(pools.map(pool => getPoolReserves(api, pool)));
121+
122+
for (let i = 0; i < pools.length; ++i) {
123+
const reserves = poolReserves[i];
124+
for (const reserve of reserves) {
125+
const ratioAmount = reserve.balance * ratios[i];
126+
pooledTokenBalances[reserve.token] = (pooledTokenBalances[reserve.token] ?? 0) + ratioAmount;
127+
}
128+
}
129+
return pooledTokenBalances;
130+
}
131+
132+
// Pinto deposited in the Silo
133+
async function staking(api) {
134+
if (invalidTime(api)) {
135+
return {};
136+
}
137+
return {
138+
[`${api.chain}:${ADDR.base.PINTO.toLowerCase()}`]: await getSiloDeposited(api, ADDR.base.PINTO)
139+
}
140+
}
141+
142+
// Tokens in liquidity pools corresponding to LP tokens that are deposited in the Silo
143+
async function pool2(api) {
144+
if (invalidTime(api)) {
145+
return {};
146+
}
147+
148+
// Get the amount of LP tokens deposited in the silo
149+
const pools = getPools(api);
150+
const poolPromises = pools.map(pool => [
151+
getSiloDeposited(api, pool),
152+
getTotalSupply(api, pool)
153+
]);
154+
// And determine how much of the pooled tokens correspond to those deposits
155+
const flatResolved = await Promise.all(poolPromises.flat());
156+
const ratios = [];
157+
for (let i = 0; i < flatResolved.length; i += 2) {
158+
if (flatResolved[i + 1] !== 0) {
159+
ratios.push(flatResolved[i] / flatResolved[i + 1]);
160+
} else {
161+
ratios.push(0);
162+
}
163+
}
164+
165+
// Gets the underlying token balances for deposited LP tokens
166+
const pool2Balances = await getPooledBalances(api, pools, ratios);
167+
168+
// Add chain info
169+
const retval = {};
170+
for (const token in pool2Balances) {
171+
retval[`${api.chain}:${token.toLowerCase()}`] = pool2Balances[token];
172+
}
173+
return retval;
174+
}
175+
176+
module.exports = {
177+
methodology: "Counts the value of deposited Pinto and LP tokens in the Silo.",
178+
start: '2024-11-19',
179+
base: {
180+
tvl: () => ({}),
181+
pool2,
182+
staking
183+
},
184+
};

0 commit comments

Comments
 (0)