@strkfarm/sdk 2.0.0-dev.5 → 2.0.0-dev.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +190 -36
- package/dist/cli.mjs +188 -34
- package/dist/index.browser.global.js +118889 -92229
- package/dist/index.browser.mjs +13381 -11153
- package/dist/index.d.ts +2284 -1938
- package/dist/index.js +13794 -11360
- package/dist/index.mjs +14253 -11843
- package/package.json +59 -60
- package/src/data/avnu.abi.json +840 -0
- package/src/data/ekubo-price-fethcer.abi.json +265 -0
- package/src/data/redeem-request-nft.abi.json +752 -0
- package/src/data/universal-vault.abi.json +8 -7
- package/src/dataTypes/_bignumber.ts +13 -4
- package/src/dataTypes/bignumber.browser.ts +10 -1
- package/src/dataTypes/bignumber.node.ts +10 -1
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +280 -233
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +229 -6
- package/src/modules/apollo-client-config.ts +28 -0
- package/src/modules/avnu.ts +21 -12
- package/src/modules/ekubo-pricer.ts +99 -0
- package/src/modules/ekubo-quoter.ts +48 -30
- package/src/modules/erc20.ts +17 -0
- package/src/modules/harvests.ts +43 -29
- package/src/modules/index.ts +2 -1
- package/src/modules/pragma.ts +23 -8
- package/src/modules/pricer-avnu-api.ts +114 -0
- package/src/modules/pricer-from-api.ts +159 -15
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer-quote-utils.ts +54 -0
- package/src/modules/pricer.ts +157 -54
- package/src/modules/pricerBase.ts +2 -1
- package/src/modules/zkLend.ts +3 -2
- package/src/node/deployer.ts +36 -1
- package/src/node/pricer-redis.ts +3 -1
- package/src/strategies/base-strategy.ts +168 -16
- package/src/strategies/constants.ts +8 -3
- package/src/strategies/ekubo-cl-vault.tsx +1048 -355
- package/src/strategies/factory.ts +199 -0
- package/src/strategies/index.ts +5 -3
- package/src/strategies/registry.ts +262 -0
- package/src/strategies/sensei.ts +354 -10
- package/src/strategies/svk-strategy.ts +292 -31
- package/src/strategies/token-boosted-xstrk-carry-strategy.tsx +1261 -0
- package/src/strategies/types.ts +4 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +4 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +196 -272
- package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
- package/src/strategies/universal-adapters/common-adapter.ts +206 -203
- package/src/strategies/universal-adapters/index.ts +10 -8
- package/src/strategies/universal-adapters/svk-troves-adapter.ts +511 -0
- package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +120 -82
- package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +525 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +866 -860
- package/src/strategies/universal-adapters/vesu-position-common.ts +258 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +895 -416
- package/src/strategies/universal-strategy.tsx +1332 -1173
- package/src/strategies/vesu-rebalance.tsx +254 -153
- package/src/strategies/yoloVault.ts +1096 -0
- package/src/utils/cacheClass.ts +11 -2
- package/src/utils/health-factor-math.ts +33 -1
- package/src/utils/index.ts +3 -1
- package/src/utils/logger.browser.ts +22 -4
- package/src/utils/logger.node.ts +259 -24
- package/src/utils/starknet-call-parser.ts +1036 -0
- package/src/utils/strategy-utils.ts +61 -0
- package/src/modules/ExtendedWrapperSDk/index.ts +0 -62
- package/src/modules/ExtendedWrapperSDk/types.ts +0 -311
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +0 -395
- package/src/strategies/universal-adapters/extended-adapter.ts +0 -662
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +0 -34
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +0 -77
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +0 -49
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +0 -372
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +0 -1140
package/src/global.ts
CHANGED
|
@@ -1,322 +1,369 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import { TokenInfo } from
|
|
3
|
-
import { ContractAddr } from
|
|
4
|
-
import { logger } from
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { TokenIndexingType, TokenInfo } from './interfaces';
|
|
3
|
+
import { ContractAddr } from './dataTypes';
|
|
4
|
+
import { logger } from '@/utils/logger';
|
|
5
|
+
|
|
5
6
|
|
|
6
7
|
export class FatalError extends Error {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
constructor(message: string, err?: Error) {
|
|
9
|
+
super(message);
|
|
10
|
+
logger.error(message);
|
|
11
|
+
if (err)
|
|
12
|
+
logger.error(err.message);
|
|
13
|
+
this.name = "FatalError";
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
const defaultTokens: TokenInfo[] = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
address: ContractAddr.from(
|
|
21
|
-
"0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
|
|
22
|
-
),
|
|
17
|
+
const defaultTokens: TokenInfo[] = [{
|
|
18
|
+
name: 'Starknet',
|
|
19
|
+
symbol: 'STRK',
|
|
20
|
+
logo: 'https://assets.troves.fi/integrations/tokens/strk.svg',
|
|
21
|
+
address: ContractAddr.from('0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d'),
|
|
23
22
|
decimals: 18,
|
|
24
|
-
coingeckId:
|
|
23
|
+
coingeckId: 'starknet',
|
|
25
24
|
displayDecimals: 2,
|
|
26
|
-
priceCheckAmount:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
),
|
|
25
|
+
priceCheckAmount: 5000,
|
|
26
|
+
priceMethod: 'Avnu',
|
|
27
|
+
indexingType: TokenIndexingType.INDEXER,
|
|
28
|
+
}, {
|
|
29
|
+
name: 'xSTRK',
|
|
30
|
+
symbol: 'xSTRK',
|
|
31
|
+
logo: 'https://assets.troves.fi/integrations/tokens/xstrk.svg',
|
|
32
|
+
address: ContractAddr.from('0x028d709c875c0ceac3dce7065bec5328186dc89fe254527084d1689910954b0a'),
|
|
35
33
|
decimals: 18,
|
|
36
34
|
coingeckId: undefined,
|
|
37
|
-
priceCheckAmount:
|
|
35
|
+
priceCheckAmount: 5000,
|
|
38
36
|
displayDecimals: 2,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
),
|
|
37
|
+
priceMethod: 'Avnu',
|
|
38
|
+
indexingType: TokenIndexingType.LST_SCRIPT,
|
|
39
|
+
intermediateQuoteTokenSymbol: 'STRK',
|
|
40
|
+
}, {
|
|
41
|
+
name: 'ETH',
|
|
42
|
+
symbol: 'ETH',
|
|
43
|
+
logo: 'https://assets.troves.fi/integrations/tokens/eth.svg',
|
|
44
|
+
address: ContractAddr.from('0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'),
|
|
47
45
|
decimals: 18,
|
|
48
46
|
coingeckId: undefined,
|
|
49
47
|
priceCheckAmount: 0.1,
|
|
50
48
|
displayDecimals: 6,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
name:
|
|
54
|
-
symbol:
|
|
55
|
-
logo:
|
|
56
|
-
address: ContractAddr.from(
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
indexingType: TokenIndexingType.INDEXER,
|
|
50
|
+
}, {
|
|
51
|
+
name: 'USDC.e',
|
|
52
|
+
symbol: 'USDC.e',
|
|
53
|
+
logo: 'https://assets.troves.fi/integrations/tokens/usdc.svg',
|
|
54
|
+
address: ContractAddr.from('0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8'),
|
|
55
|
+
decimals: 6,
|
|
56
|
+
coingeckId: undefined,
|
|
57
|
+
displayDecimals: 2,
|
|
58
|
+
priceCheckAmount: 1000,
|
|
59
|
+
priceProxySymbol: 'USDC',
|
|
60
|
+
indexingType: TokenIndexingType.PEGGED,
|
|
61
|
+
}, {
|
|
62
|
+
name: 'USDC',
|
|
63
|
+
symbol: 'USDC',
|
|
64
|
+
logo: 'https://assets.troves.fi/integrations/tokens/usdc.svg',
|
|
65
|
+
address: ContractAddr.from('0x033068F6539f8e6e6b131e6B2B814e6c34A5224bC66947c47DaB9dFeE93b35fb'),
|
|
59
66
|
decimals: 6,
|
|
60
67
|
coingeckId: undefined,
|
|
61
68
|
displayDecimals: 2,
|
|
62
69
|
priceCheckAmount: 1000,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
name:
|
|
66
|
-
symbol:
|
|
67
|
-
logo:
|
|
68
|
-
address: ContractAddr.from(
|
|
69
|
-
"0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"
|
|
70
|
-
),
|
|
70
|
+
indexingType: TokenIndexingType.INDEXER,
|
|
71
|
+
}, {
|
|
72
|
+
name: 'USDT',
|
|
73
|
+
symbol: 'USDT',
|
|
74
|
+
logo: 'https://assets.troves.fi/integrations/tokens/usdt.svg',
|
|
75
|
+
address: ContractAddr.from('0x68f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8'),
|
|
71
76
|
decimals: 6,
|
|
72
77
|
coingeckId: undefined,
|
|
73
78
|
priceCheckAmount: 1000,
|
|
74
79
|
displayDecimals: 2,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
name:
|
|
78
|
-
symbol:
|
|
79
|
-
logo:
|
|
80
|
-
address: ContractAddr.from(
|
|
81
|
-
"0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac"
|
|
82
|
-
),
|
|
80
|
+
indexingType: TokenIndexingType.INDEXER,
|
|
81
|
+
}, {
|
|
82
|
+
name: 'WBTC',
|
|
83
|
+
symbol: 'WBTC',
|
|
84
|
+
logo: 'https://assets.troves.fi/integrations/tokens/wbtc.svg',
|
|
85
|
+
address: ContractAddr.from('0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac'),
|
|
83
86
|
decimals: 8,
|
|
84
87
|
coingeckId: undefined,
|
|
85
88
|
displayDecimals: 6,
|
|
86
89
|
priceCheckAmount: 0.001, // 112000 * 0.0001 = $110.2
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
name:
|
|
90
|
-
symbol:
|
|
91
|
-
logo:
|
|
92
|
-
address: ContractAddr.from(
|
|
93
|
-
"0x4daa17763b286d1e59b97c283c0b8c949994c361e426a28f743c67bdfe9a32f"
|
|
94
|
-
),
|
|
90
|
+
indexingType: TokenIndexingType.INDEXER,
|
|
91
|
+
}, {
|
|
92
|
+
name: 'tBTC',
|
|
93
|
+
symbol: 'tBTC',
|
|
94
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/tbtc.svg',
|
|
95
|
+
address: ContractAddr.from('0x4daa17763b286d1e59b97c283c0b8c949994c361e426a28f743c67bdfe9a32f'),
|
|
95
96
|
decimals: 18,
|
|
96
97
|
coingeckId: undefined,
|
|
97
98
|
displayDecimals: 6,
|
|
98
99
|
priceCheckAmount: 0.001, // 112000 * 0.0001 = $110.2
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
),
|
|
100
|
+
priceProxySymbol: 'WBTC',
|
|
101
|
+
indexingType: TokenIndexingType.PEGGED,
|
|
102
|
+
}, {
|
|
103
|
+
name: 'solvBTC',
|
|
104
|
+
symbol: 'solvBTC',
|
|
105
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/solvbtc.svg',
|
|
106
|
+
address: ContractAddr.from('0x0593e034dda23eea82d2ba9a30960ed42cf4a01502cc2351dc9b9881f9931a68'),
|
|
107
107
|
decimals: 18,
|
|
108
108
|
coingeckId: undefined,
|
|
109
|
-
priceProxySymbol:
|
|
109
|
+
priceProxySymbol: 'WBTC',
|
|
110
110
|
displayDecimals: 6,
|
|
111
111
|
priceCheckAmount: 0.0001, // 112000 * 0.0001 = $11.2
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
name:
|
|
115
|
-
symbol:
|
|
116
|
-
logo:
|
|
117
|
-
address: ContractAddr.from(
|
|
118
|
-
"0x036834a40984312f7f7de8d31e3f6305b325389eaeea5b1c0664b2fb936461a4"
|
|
119
|
-
),
|
|
112
|
+
indexingType: TokenIndexingType.PEGGED,
|
|
113
|
+
}, {
|
|
114
|
+
name: 'LBTC',
|
|
115
|
+
symbol: 'LBTC',
|
|
116
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/lbtc.svg',
|
|
117
|
+
address: ContractAddr.from('0x036834a40984312f7f7de8d31e3f6305b325389eaeea5b1c0664b2fb936461a4'),
|
|
120
118
|
decimals: 8,
|
|
121
119
|
coingeckId: undefined,
|
|
122
120
|
displayDecimals: 6,
|
|
123
|
-
priceProxySymbol:
|
|
121
|
+
priceProxySymbol: 'WBTC',
|
|
124
122
|
priceCheckAmount: 0.0001, // 112000 * 0.0001 = $11.2
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
name:
|
|
128
|
-
symbol:
|
|
129
|
-
logo:
|
|
130
|
-
address: ContractAddr.from(
|
|
131
|
-
"0x6a567e68c805323525fe1649adb80b03cddf92c23d2629a6779f54192dffc13"
|
|
132
|
-
),
|
|
123
|
+
indexingType: TokenIndexingType.PEGGED,
|
|
124
|
+
}, {
|
|
125
|
+
name: 'xWBTC',
|
|
126
|
+
symbol: 'xWBTC',
|
|
127
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/xwbtc.svg',
|
|
128
|
+
address: ContractAddr.from('0x6a567e68c805323525fe1649adb80b03cddf92c23d2629a6779f54192dffc13'),
|
|
133
129
|
decimals: 8,
|
|
134
130
|
coingeckId: undefined,
|
|
135
131
|
displayDecimals: 6,
|
|
136
132
|
priceCheckAmount: 0.001, // 112000 * 0.0001 = $110.2
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
),
|
|
133
|
+
priceMethod: 'Avnu',
|
|
134
|
+
indexingType: TokenIndexingType.LST_SCRIPT,
|
|
135
|
+
}, {
|
|
136
|
+
name: 'xsBTC',
|
|
137
|
+
symbol: 'xsBTC',
|
|
138
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/xsbtc_solv.svg',
|
|
139
|
+
address: ContractAddr.from('0x580f3dc564a7b82f21d40d404b3842d490ae7205e6ac07b1b7af2b4a5183dc9'),
|
|
145
140
|
decimals: 18,
|
|
146
141
|
coingeckId: undefined,
|
|
147
142
|
displayDecimals: 6,
|
|
148
|
-
priceProxySymbol: "WBTC",
|
|
149
143
|
priceCheckAmount: 0.0001, // 112000 * 0.0001 = $11.2
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
name:
|
|
154
|
-
symbol:
|
|
155
|
-
logo:
|
|
156
|
-
address: ContractAddr.from(
|
|
157
|
-
"0x43a35c1425a0125ef8c171f1a75c6f31ef8648edcc8324b55ce1917db3f9b91"
|
|
158
|
-
),
|
|
144
|
+
priceMethod: 'Avnu',
|
|
145
|
+
indexingType: TokenIndexingType.LST_SCRIPT,
|
|
146
|
+
}, {
|
|
147
|
+
name: 'xtBTC',
|
|
148
|
+
symbol: 'xtBTC',
|
|
149
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/xtbtc.svg',
|
|
150
|
+
address: ContractAddr.from('0x43a35c1425a0125ef8c171f1a75c6f31ef8648edcc8324b55ce1917db3f9b91'),
|
|
159
151
|
decimals: 18,
|
|
160
152
|
coingeckId: undefined,
|
|
161
153
|
displayDecimals: 6,
|
|
162
154
|
priceCheckAmount: 0.001, // 112000 * 0.0001 = $110.2
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
),
|
|
155
|
+
priceMethod: 'Avnu',
|
|
156
|
+
indexingType: TokenIndexingType.LST_SCRIPT,
|
|
157
|
+
}, {
|
|
158
|
+
name: 'xLBTC',
|
|
159
|
+
symbol: 'xLBTC',
|
|
160
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/xlbtc.svg',
|
|
161
|
+
address: ContractAddr.from('0x07dd3c80de9fcc5545f0cb83678826819c79619ed7992cc06ff81fc67cd2efe0'),
|
|
171
162
|
decimals: 8,
|
|
172
163
|
coingeckId: undefined,
|
|
173
164
|
displayDecimals: 6,
|
|
174
|
-
priceProxySymbol: "WBTC",
|
|
175
165
|
priceCheckAmount: 0.0001, // 112000 * 0.0001 = $11.2
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
),
|
|
166
|
+
priceMethod: 'Avnu',
|
|
167
|
+
indexingType: TokenIndexingType.LST_SCRIPT,
|
|
168
|
+
}, {
|
|
169
|
+
name: 'mRe7BTC',
|
|
170
|
+
symbol: 'mRe7BTC',
|
|
171
|
+
logo: 'https://imagedelivery.net/0xPAQaDtnQhBs8IzYRIlNg/3a62ecee-1e58-45d3-9862-3ce90dff1900/logo',
|
|
172
|
+
address: ContractAddr.from('0x4e4fb1a9ca7e84bae609b9dc0078ad7719e49187ae7e425bb47d131710eddac'),
|
|
184
173
|
decimals: 18,
|
|
185
174
|
coingeckId: undefined,
|
|
186
175
|
displayDecimals: 6,
|
|
187
176
|
priceCheckAmount: 0.0001, // 112000 * 0.0001 = $11.2
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
),
|
|
177
|
+
dontPrice: true,
|
|
178
|
+
indexingType: TokenIndexingType.IGNORE,
|
|
179
|
+
}, {
|
|
180
|
+
name: 'mRe7YIELD',
|
|
181
|
+
symbol: 'mRe7YIELD',
|
|
182
|
+
logo: 'https://midas.app/assets/mre7-BcOOHm7i.svg',
|
|
183
|
+
address: ContractAddr.from('0x4be8945e61dc3e19ebadd1579a6bd53b262f51ba89e6f8b0c4bc9a7e3c633fc'),
|
|
196
184
|
decimals: 18,
|
|
197
185
|
coingeckId: undefined,
|
|
198
186
|
displayDecimals: 2,
|
|
199
187
|
priceCheckAmount: 100,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
188
|
+
dontPrice: true,
|
|
189
|
+
indexingType: TokenIndexingType.IGNORE,
|
|
190
|
+
}, {
|
|
191
|
+
name: "fyeWBTC",
|
|
192
|
+
symbol: "fyeWBTC",
|
|
193
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/wbtc.svg',
|
|
194
|
+
address: ContractAddr.from('0x04dd39de0a588f5e1c7a8377e1bef2c49caaee49a11433429d2c48f587b3a492'),
|
|
195
|
+
decimals: 8,
|
|
196
|
+
coingeckId: undefined,
|
|
197
|
+
displayDecimals: 6,
|
|
198
|
+
priceCheckAmount: 0.001, // 112000 * 0.0001 = $110.2
|
|
199
|
+
dontPrice: true,
|
|
200
|
+
indexingType: TokenIndexingType.IGNORE,
|
|
201
|
+
}, {
|
|
202
|
+
name: "fyETH",
|
|
203
|
+
symbol: "fyETH",
|
|
204
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/eth.svg',
|
|
205
|
+
address: ContractAddr.from('0x050707bC3b8730022F10530C2c6f6b9467644129C50C2868Ad0036c5e4E9e616'),
|
|
206
|
+
decimals: 18,
|
|
207
|
+
coingeckId: undefined,
|
|
208
|
+
displayDecimals: 4,
|
|
209
|
+
priceCheckAmount: 0.1,
|
|
210
|
+
dontPrice: true,
|
|
211
|
+
indexingType: TokenIndexingType.IGNORE,
|
|
212
|
+
}, {
|
|
213
|
+
name: "fyeUSDC",
|
|
214
|
+
symbol: "fyeUSDC",
|
|
215
|
+
logo: 'https://assets.strkfarm.com/integrations/tokens/usdc.svg',
|
|
216
|
+
address: ContractAddr.from('0x07fdcec0cef01294c9c3d52415215949805c77bae8003702a7928fd6d2c36bc1'),
|
|
208
217
|
decimals: 6,
|
|
209
218
|
coingeckId: undefined,
|
|
210
219
|
displayDecimals: 2,
|
|
211
220
|
priceCheckAmount: 100,
|
|
212
|
-
|
|
213
|
-
|
|
221
|
+
dontPrice: true,
|
|
222
|
+
indexingType: TokenIndexingType.IGNORE,
|
|
223
|
+
}, {
|
|
224
|
+
name: 'strkBTC',
|
|
225
|
+
symbol: 'strkBTC',
|
|
226
|
+
logo: 'https://assets.troves.fi/integrations/tokens/strkbtc.svg',
|
|
227
|
+
address: ContractAddr.from('0x0787150e306e6eae6e3f79dea881770e8bbff2c1b8eb490f969669ee945b3135'),
|
|
228
|
+
decimals: 8,
|
|
229
|
+
coingeckId: undefined,
|
|
230
|
+
displayDecimals: 6,
|
|
231
|
+
priceCheckAmount: 0.001, // 112000 * 0.0001 = $110.2
|
|
232
|
+
priceMethod: 'Avnu',
|
|
233
|
+
priceProxySymbol: 'WBTC',
|
|
234
|
+
indexingType: TokenIndexingType.PEGGED,
|
|
235
|
+
}, {
|
|
236
|
+
name: 'xstrkBTC',
|
|
237
|
+
symbol: 'xstrkBTC',
|
|
238
|
+
logo: 'https://assets.troves.fi/integrations/tokens/xstrkbtc.svg',
|
|
239
|
+
address: ContractAddr.from('0x047751b3532fabca89b0f2e35ca1cb45e5a7b11d5e3d3663dfa1f4406b45fd88'),
|
|
240
|
+
decimals: 8,
|
|
241
|
+
coingeckId: undefined,
|
|
242
|
+
displayDecimals: 6,
|
|
243
|
+
priceCheckAmount: 0.001,
|
|
244
|
+
priceMethod: 'Avnu',
|
|
245
|
+
indexingType: TokenIndexingType.LST_SCRIPT,
|
|
246
|
+
}];
|
|
214
247
|
const tokens: TokenInfo[] = defaultTokens;
|
|
215
248
|
|
|
216
249
|
/** Contains globally useful functions.
|
|
217
250
|
* - fatalError: Things to do when a fatal error occurs
|
|
218
251
|
*/
|
|
219
252
|
export class Global {
|
|
220
|
-
|
|
221
|
-
{};
|
|
253
|
+
static cache: Record<string, { value: any, ttl: number, timestamp: number }> = {};
|
|
222
254
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
255
|
+
static fatalError(message: string, err?: Error) {
|
|
256
|
+
logger.error(message);
|
|
257
|
+
console.error(message, err);
|
|
258
|
+
if (err)
|
|
259
|
+
console.error(err);
|
|
260
|
+
process.exit(1);
|
|
261
|
+
}
|
|
229
262
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
263
|
+
static httpError(url: string, err: Error, message?: string) {
|
|
264
|
+
logger.error(`${url}: ${message}`);
|
|
265
|
+
console.error(err);
|
|
266
|
+
}
|
|
234
267
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
268
|
+
static getDefaultTokens() {
|
|
269
|
+
return tokens;
|
|
270
|
+
}
|
|
238
271
|
|
|
239
|
-
|
|
240
|
-
|
|
272
|
+
static async getTokens(): Promise<TokenInfo[]> {
|
|
273
|
+
if (tokens.length) return tokens;
|
|
241
274
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
);
|
|
246
|
-
const tokensData = data.data.content;
|
|
275
|
+
// fetch from avnu API
|
|
276
|
+
const data = await axios.get('https://assets.troves.fi/integrations/tokens.json');
|
|
277
|
+
const tokensData = data.data.content;
|
|
247
278
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
279
|
+
// Array of the following is returned
|
|
280
|
+
// {
|
|
281
|
+
// "name": "USD Coin",
|
|
282
|
+
// "address": "0x53c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
|
|
283
|
+
// "symbol": "USDC",
|
|
284
|
+
// "decimals": 6,
|
|
285
|
+
// "logoUri": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png",
|
|
286
|
+
// "lastDailyVolumeUsd": 2964287916.82621,
|
|
287
|
+
// "extensions": {
|
|
288
|
+
// "coingeckoId": "usd-coin"
|
|
289
|
+
// },
|
|
290
|
+
// "tags": [
|
|
291
|
+
// "AVNU",
|
|
292
|
+
// "Verified"
|
|
293
|
+
// ]
|
|
294
|
+
// }
|
|
264
295
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
296
|
+
tokensData.forEach((token: any) => {
|
|
297
|
+
// if tags do not contain Avnu and verified, ignore
|
|
298
|
+
// This would exclude meme coins for now
|
|
299
|
+
if (!token.tags.includes('AVNU') || !token.tags.includes('Verified')) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
271
302
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
303
|
+
tokens.push({
|
|
304
|
+
name: token.name,
|
|
305
|
+
symbol: token.symbol,
|
|
306
|
+
address: ContractAddr.from(token.address),
|
|
307
|
+
decimals: token.decimals,
|
|
308
|
+
logo: token.logoUri,
|
|
309
|
+
coingeckId: token.extensions.coingeckoId,
|
|
310
|
+
displayDecimals: 2,
|
|
311
|
+
indexingType: TokenIndexingType.IGNORE,
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
console.log(tokens);
|
|
315
|
+
return tokens;
|
|
316
|
+
}
|
|
285
317
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
318
|
+
static assert(condition: any, message: string) {
|
|
319
|
+
if (!condition) {
|
|
320
|
+
throw new FatalError(message);
|
|
321
|
+
}
|
|
289
322
|
}
|
|
290
|
-
}
|
|
291
323
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
324
|
+
static async getTokenInfoFromAddr(addr: ContractAddr) {
|
|
325
|
+
// if tokens are not loaded, load them
|
|
326
|
+
if (tokens.length == defaultTokens.length) {
|
|
327
|
+
await Global.getTokens();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const token = tokens.find((token) => addr.eq(token.address));
|
|
331
|
+
if (!token) {
|
|
332
|
+
throw new FatalError(`Token not found: ${addr.address}`);
|
|
333
|
+
}
|
|
334
|
+
return token;
|
|
296
335
|
}
|
|
297
336
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
337
|
+
static async getTokenInfoFromName(tokenName: string) {
|
|
338
|
+
// if tokens are not loaded, load them
|
|
339
|
+
if (tokens.length == defaultTokens.length) {
|
|
340
|
+
await Global.getTokens();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const token = tokens.find(
|
|
344
|
+
(token) => token.name.toLowerCase() === tokenName.toLowerCase()
|
|
345
|
+
);
|
|
346
|
+
if (!token) {
|
|
347
|
+
throw new FatalError(`Token not found: ${tokenName}`);
|
|
348
|
+
}
|
|
349
|
+
return token;
|
|
301
350
|
}
|
|
302
|
-
return token;
|
|
303
|
-
}
|
|
304
351
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
352
|
+
static setGlobalCache(key: string, data: any, ttl: number = 60000) {
|
|
353
|
+
Global.cache[key] = {
|
|
354
|
+
value: data,
|
|
355
|
+
ttl,
|
|
356
|
+
timestamp: Date.now()
|
|
357
|
+
};
|
|
358
|
+
}
|
|
312
359
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
360
|
+
static getGlobalCache<T>(key: string): T | null {
|
|
361
|
+
const cached = Global.cache[key];
|
|
362
|
+
if (!cached) return null;
|
|
363
|
+
if (Date.now() - cached.timestamp > cached.ttl) {
|
|
364
|
+
delete Global.cache[key];
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
return cached.value;
|
|
319
368
|
}
|
|
320
|
-
return cached.value;
|
|
321
|
-
}
|
|
322
369
|
}
|
package/src/index.browser.ts
CHANGED