Skip to content

Commit f83fa4d

Browse files
committed
fix stacks adapters
1 parent ad863c0 commit f83fa4d

File tree

3 files changed

+131
-15
lines changed

3 files changed

+131
-15
lines changed

projects/helper/chain/stacks-api.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
const stacks = require('@stacks/transactions')
2-
const { StacksMainnet } = require('@stacks/network')
2+
const { STACKS_MAINNET, } = require('@stacks/network')
3+
const { createApiKeyMiddleware, createFetchFn } = require('@stacks/common')
34

4-
const { bufferCVFromString, callReadOnlyFunction, uintCV, principalCV,tupleCV, } = stacks
5-
let network
5+
const k = '260ff2d24e32b02'
6+
+'e69c516779e3ddbf5'
7+
const apiMiddleware = createApiKeyMiddleware({
8+
['api'+
9+
'Key']: k,
10+
});
611

7-
const senderAddress = 'ST2F4BK4GZH6YFBNHYDDGN4T1RKBA7DA1BJZPJEJJ'
812

9-
function getNetwork() {
10-
if (!network)
11-
network = new StacksMainnet()
12-
return network
13-
}
13+
const customFetchFn = createFetchFn(apiMiddleware);
14+
STACKS_MAINNET.client.fetch = customFetchFn
15+
16+
const { bufferCVFromString, fetchCallReadOnlyFunction, uintCV, principalCV,tupleCV, } = stacks
17+
18+
const senderAddress = 'ST2F4BK4GZH6YFBNHYDDGN4T1RKBA7DA1BJZPJEJJ'
1419

1520
async function call({ target, abi, inputArgs = [], }) {
1621
const [contractAddress, contractName] = target.split('.')
17-
const network = getNetwork()
18-
const result = await callReadOnlyFunction({ network, contractAddress, contractName, functionName: abi, functionArgs: inputArgs.map(toClairty), senderAddress});
22+
const result = await fetchCallReadOnlyFunction({ network: STACKS_MAINNET, contractAddress, contractName, functionName: abi, functionArgs: inputArgs.map(toClairty), senderAddress, client: STACKS_MAINNET.client, });
1923
return stacks.cvToValue(result)
2024

2125
function toClairty(arg) {
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
module.exports = {
2+
hourlyRun: [
3+
[
4+
{
5+
'fxdao': '/fxdao/api.js',
6+
'blend-pools': '/blend-pools/api.js',
7+
'blend-backstop': '/blend-backstop/api.js',
8+
'harvest': '/harvest.js',
9+
'astar-dapps-staking': '/astar-dapps-staking/api',
10+
'hydradex-v3': '/hydradex-v3/index.js',
11+
'injective-orderbook': '/injective-orderbook/api',
12+
'lisa': '/lisa/api',
13+
},
14+
{
15+
'bifrost-staking': '/bifrost-staking/api',
16+
'bifrost-dex': '/bifrost-dex/api',
17+
'bifrost-liquid-crowdloan': '/bifrost-liquid-crowdloan/api',
18+
},
19+
{
20+
// 'genshiro': '/genshiro/api',
21+
// 'streamflow': '/streamflow/index',
22+
},
23+
{
24+
'interlay-btc': '/interlay-btc/api',
25+
'interlay-staking': '/interlay-staking/api',
26+
'interlay-collateral': '/interlay-collateral/api',
27+
'interlay-dex': '/interlay-dex/api',
28+
'interlay-lending': '/interlay-lending/api',
29+
},
30+
],
31+
[
32+
{
33+
// 'parallel-staking': '/parallel-staking/api',
34+
// 'parallel-crowdloan': '/parallel-crowdloan/api',
35+
// 'parallelamm': '/parallelamm/api',
36+
// 'parallel-lending': '/parallel-lending/api',
37+
// 'parallel-stream': '/parallel-stream/api',
38+
'manta-atlantic-stake': '/manta-atlantic-stake/api',
39+
'mantadex': '/mantadex/api',
40+
},
41+
{
42+
'acala-staking': '/acala-staking/api',
43+
'acala-lcdot': '/acala-lcdot/api',
44+
'tapio': '/tapio/api',
45+
'acala-lending': '/acala-lending/api',
46+
'acala-dex': '/acala-dex/api',
47+
},
48+
{
49+
'polkadex': '/polkadex/api',
50+
},
51+
{
52+
'karura-lending': '/karura-lending/api',
53+
'karura-staking': '/karura-staking/api',
54+
'taiga': '/taiga/api',
55+
'karura-dex': '/karura-dex/api',
56+
},
57+
{
58+
'kintsugi': '/kintsugi/api',
59+
'jewelswap-lev-farming': '/jewelswap-lev-farming/index',
60+
'jewelswap-nft': '/jewelswap-nft/index',
61+
62+
},
63+
{
64+
'hydradx': '/hydradx/api',
65+
},
66+
{
67+
'newbitcoin': '/newbitcoin/index',
68+
'nemoswap': '/nemoswap/index',
69+
'stackingdao': '/stackingdao/api',
70+
'stacks': '/stacks/api',
71+
},
72+
],
73+
],
74+
bulky: [
75+
[{
76+
// 'quantumx-network': '/quantumx-network/index',
77+
'polkadot': '/treasury/polkadot-api',
78+
'stackswap': '/stackswap/api',
79+
'velar-amm': '/velar-amm/api',
80+
'alexlab': '/alexlab/api',
81+
'satoshi-dex': '/satoshi-dex/api',
82+
'raydium': '/raydium/index',
83+
'vitcswap': '/vitcswap/api',
84+
'defichain-loans': '/defichain-loans',
85+
// 'kamino': '/kamino/api',
86+
// '1inch': '/1inch/apiCache',
87+
'izumi': '/izumi/api',
88+
// 'summer-fi': '/summer-fi/index',
89+
// 'sunswap-v2': '/sunswap-v2/index',
90+
unicrypt: '/unicrypt/apiCache',
91+
deeplock: '/deeplock/apiCache',
92+
pinksale: '/pinksale/apiCache',
93+
'team-finance': '/team-finance/apiCache',
94+
synthetix: '/synthetix/apiCache',
95+
dxsale: '/dxsale/apiCache',
96+
'yodeswap': '/yodeswap/api',
97+
'dogeswap-org': '/dogeswap-org/api',
98+
99+
// breaks often
100+
// 'equilibrium': '/equilibrium/api',
101+
'hydradex': '/hydradex.js',
102+
103+
// chain down?
104+
// 'parallel-staking': '/parallel-staking/api',
105+
// 'parallel-crowdloan': '/parallel-crowdloan/api',
106+
// 'parallelamm': '/parallelamm/api',
107+
// 'parallel-lending': '/parallel-lending/api',
108+
// 'parallel-stream': '/parallel-stream/api',
109+
}],
110+
],
111+
}

projects/stackswap/api.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { call } = require('../helper/chain/stacks-api')
22
const { transformDexBalances } = require('../helper/portedTokens')
33
const { getCache, setCache, } = require('../helper/cache')
4-
const { sleep } = require('../helper/utils')
5-
const sdk = require('@defillama/sdk')
4+
// const { sleep } = require('../helper/utils')
5+
// const sdk = require('@defillama/sdk')
66

77
const factory = 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.stackswap-swap-v5k'
88

@@ -17,6 +17,7 @@ async function tvl(api) {
1717
if (!cache.pairData) cache.pairData = []
1818
for (let i = cache.pairData.length +1; i <= pairCount; i++) {
1919
const pair = await call({ target: factory, abi: 'get-pair-contracts', inputArgs: [{ type: 'number', value: i }] })
20+
api.log(`stackswap: ${i}/${pairCount}`)
2021
cache.pairData.push(pair)
2122
}
2223

@@ -31,8 +32,8 @@ async function tvl(api) {
3132
token0Bal: +pairData.value['balance-x'].value + +pairData.value['fee-balance-x'].value,
3233
token1Bal: +pairData.value['balance-y'].value + +pairData.value['fee-balance-y'].value,
3334
})
34-
sdk.log(`stackswap: ${++i}/${pairCount}`)
35-
await sleep(2100)
35+
api.log(`stackswap: ${++i}/${pairCount}`)
36+
// await sleep(2100)
3637
}
3738
return transformDexBalances({ chain: 'stacks', data})
3839
}

0 commit comments

Comments
 (0)