Skip to content

Commit 2d8b4ea

Browse files
authored
Add files via upload
1 parent badbfe5 commit 2d8b4ea

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

projects/kanvas/abi.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"tokenList": {
3+
"inputs": [],
4+
"name": "tokenList",
5+
"outputs": [
6+
{ "internalType": "address[]", "name": "", "type": "address[]" }
7+
],
8+
"stateMutability": "view",
9+
"type": "function"
10+
},
11+
"tokenParameters": {
12+
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
13+
"name": "tokenParameters",
14+
"outputs": [
15+
{
16+
"internalType": "contract IRewarder",
17+
"name": "rewarder",
18+
"type": "address"
19+
},
20+
{
21+
"internalType": "contract IKanvasStrategy",
22+
"name": "strategy",
23+
"type": "address"
24+
},
25+
{
26+
"internalType": "uint256",
27+
"name": "lastRewardTime",
28+
"type": "uint256"
29+
},
30+
{
31+
"internalType": "uint256",
32+
"name": "lastCumulativeReward",
33+
"type": "uint256"
34+
},
35+
{ "internalType": "uint256", "name": "storedPrice", "type": "uint256" },
36+
{
37+
"internalType": "uint256",
38+
"name": "accSKANVASPerShare",
39+
"type": "uint256"
40+
},
41+
{ "internalType": "uint256", "name": "totalShares", "type": "uint256" },
42+
{ "internalType": "uint256", "name": "totalTokens", "type": "uint256" },
43+
{ "internalType": "uint128", "name": "multiplier", "type": "uint128" },
44+
{ "internalType": "uint16", "name": "withdrawFeeBP", "type": "uint16" }
45+
],
46+
"stateMutability": "view",
47+
"type": "function"
48+
}
49+
}

projects/kanvas/index.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const sdk = require("@defillama/sdk");
2+
const abi = require("./abi.json");
3+
const token0Abi = require("../helper/abis/token0.json");
4+
const token1Abi = require("../helper/abis/token1.json");
5+
const {unwrapUniswapLPs} = require("../helper/unwrapLPs");
6+
const {staking} = require("../helper/staking");
7+
const BigNumber = require("bignumber.js");
8+
9+
const kanvas = "0xe005097ad7eea379ce404011eef68359b052cd0a";
10+
const stakingAddress = "0x34d2Cfb257cCf7EFDC41DB9a824ac314da80Bae8";
11+
const artStudio = "0xf15Bf479A5711f9411595C6289a9e7C36F24ad2F";
12+
13+
const transform = {
14+
"0x150410ebbccc3be87997462ea7a44449b7c0dbf2":"kava:0xfa9343c3897324496a05fc75abed6bac29f8a40f"
15+
}
16+
17+
async function calcTvl(block, chain, pool2) {
18+
let balances = {};
19+
const tokenList = (await sdk.api.abi.call({
20+
target: artStudio,
21+
abi: abi.tokenList,
22+
block,
23+
chain
24+
})).output;
25+
const tokenBalances = (await sdk.api.abi.multiCall({
26+
calls: tokenList.map(p => ({
27+
target: artStudio,
28+
params: p
29+
})),
30+
abi: abi.tokenParameters,
31+
block,
32+
chain
33+
})).output;
34+
const symbols = (await sdk.api.abi.multiCall({
35+
calls: tokenList.map(p => ({
36+
target: p
37+
})),
38+
abi: "erc20:symbol",
39+
block,
40+
chain
41+
})).output;
42+
const token0Address = (await sdk.api.abi.multiCall({
43+
calls: tokenList.map(p => ({
44+
target: p,
45+
})),
46+
abi: token0Abi,
47+
block,
48+
chain
49+
})).output;
50+
const token1Address = (await sdk.api.abi.multiCall({
51+
calls: tokenList.map(p => ({
52+
target: p,
53+
})),
54+
abi: token1Abi,
55+
block,
56+
chain
57+
})).output;
58+
59+
let lpPositions = [];
60+
for (let i = 0; i < tokenList.length; i++) {
61+
let token = tokenList[i].toLowerCase();
62+
let balance = tokenBalances[i].output.totalShares;
63+
let symbol = symbols[i].output;
64+
let token0 = token0Address[i].output;
65+
let token1 = token1Address[i].output;
66+
if (token === kanvas) continue;
67+
if (pool2 && !symbol.endsWith("LP")) continue;
68+
if (!symbol.endsWith("LP")) {
69+
if (transform[token] !== undefined) {
70+
token = transform[token];
71+
sdk.util.sumSingleBalance(balances, token, balance);
72+
continue;
73+
}
74+
sdk.util.sumSingleBalance(balances, `${chain}:${token}`, balance);
75+
continue;
76+
}
77+
token0 = token0.toLowerCase();
78+
token1 = token1.toLowerCase();
79+
if (pool2) {
80+
if (token0 !== kanvas && token1 !== kanvas) continue;
81+
}
82+
else if (!pool2) {
83+
if (token0 === kanvas || token1 === kanvas) continue;
84+
}
85+
lpPositions.push({
86+
token,
87+
balance
88+
});
89+
}
90+
await unwrapUniswapLPs(balances, lpPositions, block, chain, addr=>{
91+
addr = addr.toLowerCase();
92+
if (transform[addr] !== undefined) {
93+
return transform[addr];
94+
}
95+
return `kava:${addr}`;
96+
})
97+
return balances;
98+
}
99+
100+
async function tvl(timestamp, block, chainBlocks) {
101+
return await calcTvl(chainBlocks.kava, "kava", false);
102+
}
103+
104+
async function pool2(timestamp, block, chainBlocks) {
105+
return await calcTvl(chainBlocks.kava, "kava", true);
106+
}
107+
108+
module.exports = {
109+
kava:{
110+
tvl,
111+
pool2,
112+
staking: staking(stakingAddress, kanvas, "kava")
113+
}
114+
}

0 commit comments

Comments
 (0)