Skip to content

Commit 5b87c88

Browse files
committed
Pinto Silo yields
1 parent 21d126a commit 5b87c88

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

src/adaptors/pinto/index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const { request, gql } = require('graphql-request');
2+
const utils = require('../utils');
3+
const axios = require('axios');
4+
5+
const START_TIME = 1732071601; // First silo yield distribution at Season 4.
6+
const API = "https://api.pinto.money/silo/yield"
7+
const SUBGRAPH = "https://graph.pinto.money/pinto/"
8+
9+
async function getPools(timestamp = null) {
10+
const pools = await getPoolsForChain("base", timestamp);
11+
return pools.flat();
12+
}
13+
14+
async function getPoolsForChain(chain, timestamp) {
15+
16+
if (timestamp && timestamp < START_TIME) {
17+
return [];
18+
}
19+
20+
const resultPools = [];
21+
22+
// When a timestamp is specified, determine which block to use
23+
let block;
24+
if (timestamp) {
25+
[block] = await utils.getBlocksByTime([timestamp], chain);
26+
}
27+
28+
// Query subgraph to identify each yield-bearing pool and its info
29+
const poolData = await request(SUBGRAPH, gql`
30+
{
31+
beans${block ? `(block: {number: ${block}})` : ''} {
32+
id
33+
lastSeason
34+
pools {
35+
id
36+
liquidityUSD
37+
tokens {
38+
id
39+
name
40+
}
41+
}
42+
}
43+
}`
44+
);
45+
46+
for (const bean of poolData.beans) {
47+
48+
// Get apy info
49+
const apy = await axios.post(API, {
50+
season: bean.lastSeason,
51+
emaWindows: [720],
52+
tokens: bean.pools.map(p => p.id),
53+
options: {
54+
initType: 'NEW'
55+
}
56+
});
57+
// Uses the available window if fewer datapoints were available
58+
const yields = apy.data.yields[Object.keys(apy.data.yields)[0]];
59+
const pools = bean.pools.filter(p => yields[p.id]);
60+
61+
// Add results for each pool
62+
for (const pool of pools) {
63+
// Sort PINTO to be first in the token list
64+
const tokens = pool.tokens[0].name === 'PINTO' ? pool.tokens : [pool.tokens[1], pool.tokens[0]];
65+
resultPools.push({
66+
pool: (`${pool.id}-${chain}`).toLowerCase(),
67+
chain: utils.formatChain(chain),
68+
project: 'pinto',
69+
symbol: `${tokens[0].name}-${tokens[1].name}`,
70+
tvlUsd: parseInt(pool.liquidityUSD),
71+
apyBase: 0,
72+
apyReward: Math.round(yields[pool.id].bean * 10000) / 100,
73+
rewardTokens: [bean.id],
74+
underlyingTokens: tokens.map(p => p.id.toLowerCase()),
75+
poolMeta: 'Pinto Silo'
76+
});
77+
}
78+
}
79+
return resultPools;
80+
}
81+
82+
module.exports = {
83+
timetravel: true,
84+
apy: getPools,
85+
url: 'https://pinto.money/'
86+
};

0 commit comments

Comments
 (0)