@scallop-io/sui-scallop-sdk 1.3.41 → 1.4.1-alpha.1
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/constants/common.d.ts +3 -3
- package/dist/constants/enum.d.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +412 -334
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -333
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +74 -20
- package/dist/models/scallopUtils.d.ts +11 -11
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/coreQuery.d.ts +0 -2
- package/dist/queries/portfolioQuery.d.ts +0 -2
- package/dist/queries/priceQuery.d.ts +32 -2
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/test.d.ts +0 -0
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +2 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/coinGecko.ts +3 -2
- package/src/constants/common.ts +10 -5
- package/src/constants/enum.ts +44 -34
- package/src/constants/poolAddress.ts +9 -8
- package/src/constants/pyth.ts +3 -2
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopQuery.ts +55 -31
- package/src/models/scallopUtils.ts +23 -18
- package/src/queries/borrowIncentiveQuery.ts +29 -12
- package/src/queries/borrowLimitQuery.ts +3 -2
- package/src/queries/coreQuery.ts +185 -196
- package/src/queries/isolatedAssetQuery.ts +3 -2
- package/src/queries/portfolioQuery.ts +81 -77
- package/src/queries/priceQuery.ts +35 -2
- package/src/queries/sCoinQuery.ts +3 -3
- package/src/queries/spoolQuery.ts +4 -6
- package/src/queries/supplyLimitQuery.ts +3 -2
- package/src/test.ts +20 -0
- package/src/types/builder/borrowIncentive.ts +10 -15
- package/src/types/constant/common.ts +1 -2
- package/src/types/utils.ts +2 -10
- package/src/utils/indexer.ts +9 -3
- package/src/utils/query.ts +0 -87
- package/src/utils/tokenBucket.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -23,9 +23,10 @@ var COIN_GECKGO_IDS = {
|
|
|
23
23
|
afsui: "sui",
|
|
24
24
|
hasui: "sui",
|
|
25
25
|
vsui: "sui",
|
|
26
|
-
sca: "scallop-2"
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
sca: "scallop-2"
|
|
27
|
+
// TODO: enable for production
|
|
28
|
+
// deep: 'deepbook',
|
|
29
|
+
// fud: 'fud-the-pug',
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
// src/constants/common.ts
|
|
@@ -54,9 +55,10 @@ var SUPPORT_POOLS = [
|
|
|
54
55
|
"afsui",
|
|
55
56
|
"hasui",
|
|
56
57
|
"vsui",
|
|
57
|
-
"sca"
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
"sca"
|
|
59
|
+
// TODO: enable for production
|
|
60
|
+
// 'fud',
|
|
61
|
+
// 'deep',
|
|
60
62
|
];
|
|
61
63
|
var SUPPORT_COLLATERALS = [
|
|
62
64
|
"usdc",
|
|
@@ -100,9 +102,10 @@ var SUPPORT_SCOIN = [
|
|
|
100
102
|
"ssca",
|
|
101
103
|
"scetus",
|
|
102
104
|
"swsol",
|
|
103
|
-
"swbtc"
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
"swbtc"
|
|
106
|
+
// TODO: enable for production
|
|
107
|
+
// 'sdeep',
|
|
108
|
+
// 'sfud',
|
|
106
109
|
];
|
|
107
110
|
var SUPPORT_SUI_BRIDGE = ["sbeth"];
|
|
108
111
|
var SUPPORT_WORMHOLE = [
|
|
@@ -126,7 +129,10 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
|
126
129
|
"sca",
|
|
127
130
|
"usdc"
|
|
128
131
|
];
|
|
129
|
-
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
132
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
133
|
+
...SUPPORT_POOLS,
|
|
134
|
+
...SUPPORT_SCOIN
|
|
135
|
+
];
|
|
130
136
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
131
137
|
var SUPPORT_PACKAGES = [
|
|
132
138
|
"coinDecimalsRegistry",
|
|
@@ -159,8 +165,9 @@ var coinDecimals = {
|
|
|
159
165
|
hasui: 9,
|
|
160
166
|
vsui: 9,
|
|
161
167
|
sca: 9,
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
// TODO: enable for production
|
|
169
|
+
// deep: 6,
|
|
170
|
+
// fud: 5,
|
|
164
171
|
susdc: 6,
|
|
165
172
|
sweth: 8,
|
|
166
173
|
ssbeth: 8,
|
|
@@ -174,9 +181,10 @@ var coinDecimals = {
|
|
|
174
181
|
safsui: 9,
|
|
175
182
|
shasui: 9,
|
|
176
183
|
svsui: 9,
|
|
177
|
-
ssca: 9
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
ssca: 9
|
|
185
|
+
// TODO: enable for production
|
|
186
|
+
// sdeep: 6,
|
|
187
|
+
// sfud: 5,
|
|
180
188
|
};
|
|
181
189
|
var assetCoins = {
|
|
182
190
|
usdc: "usdc",
|
|
@@ -192,9 +200,10 @@ var assetCoins = {
|
|
|
192
200
|
afsui: "afsui",
|
|
193
201
|
hasui: "hasui",
|
|
194
202
|
vsui: "vsui",
|
|
195
|
-
sca: "sca"
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
sca: "sca"
|
|
204
|
+
// TODO: enable for production
|
|
205
|
+
// deep: 'deep',
|
|
206
|
+
// fud: 'fud',
|
|
198
207
|
};
|
|
199
208
|
var marketCoins = {
|
|
200
209
|
susdc: "susdc",
|
|
@@ -210,9 +219,10 @@ var marketCoins = {
|
|
|
210
219
|
safsui: "safsui",
|
|
211
220
|
shasui: "shasui",
|
|
212
221
|
svsui: "svsui",
|
|
213
|
-
ssca: "ssca"
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
ssca: "ssca"
|
|
223
|
+
// TODO: enable for production
|
|
224
|
+
// sdeep: 'sdeep',
|
|
225
|
+
// sfud: 'sfud',
|
|
216
226
|
};
|
|
217
227
|
var sCoins = {
|
|
218
228
|
susdc: "susdc",
|
|
@@ -227,9 +237,10 @@ var sCoins = {
|
|
|
227
237
|
svsui: "svsui",
|
|
228
238
|
ssca: "ssca",
|
|
229
239
|
swsol: "swsol",
|
|
230
|
-
swbtc: "swbtc"
|
|
231
|
-
|
|
232
|
-
|
|
240
|
+
swbtc: "swbtc"
|
|
241
|
+
// TODO: enable for production
|
|
242
|
+
// sfud: 'sfud',
|
|
243
|
+
// sdeep: 'sdeep',
|
|
233
244
|
};
|
|
234
245
|
var stakeMarketCoins = {
|
|
235
246
|
susdc: "susdc",
|
|
@@ -256,18 +267,6 @@ var spoolRewardCoins = {
|
|
|
256
267
|
var suiBridgeCoins = {
|
|
257
268
|
sbeth: "sbeth"
|
|
258
269
|
};
|
|
259
|
-
var borrowIncentiveRewardCoins = {
|
|
260
|
-
usdc: ["sui", "sca"],
|
|
261
|
-
sui: ["sui", "sca"],
|
|
262
|
-
wusdc: ["sui", "sca"],
|
|
263
|
-
wusdt: ["sui", "sca"],
|
|
264
|
-
sca: ["sui", "sca"],
|
|
265
|
-
afsui: ["sui"],
|
|
266
|
-
hasui: ["sui"],
|
|
267
|
-
vsui: ["sui"],
|
|
268
|
-
weth: ["sui"],
|
|
269
|
-
sbeth: ["sui"]
|
|
270
|
-
};
|
|
271
270
|
var coinIds = {
|
|
272
271
|
usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
273
272
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -282,10 +281,10 @@ var coinIds = {
|
|
|
282
281
|
afsui: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
283
282
|
hasui: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
284
283
|
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
285
|
-
sca: IS_VE_SCA_TEST ? "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524" : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"
|
|
284
|
+
sca: IS_VE_SCA_TEST ? "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524" : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"
|
|
286
285
|
// isolated assets
|
|
287
|
-
deep:
|
|
288
|
-
fud:
|
|
286
|
+
// deep: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
|
|
287
|
+
// fud: '0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1',
|
|
289
288
|
};
|
|
290
289
|
var wormholeCoinIds = {
|
|
291
290
|
weth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -301,19 +300,28 @@ var voloCoinIds = {
|
|
|
301
300
|
var sCoinIds = {
|
|
302
301
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
303
302
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
304
|
-
|
|
303
|
+
// prod values
|
|
304
|
+
// ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
305
|
+
// swusdc:
|
|
306
|
+
// '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
307
|
+
// swusdt:
|
|
308
|
+
// '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
309
|
+
// ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
310
|
+
// test values
|
|
311
|
+
ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
|
|
312
|
+
swusdt: "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
313
|
+
swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
314
|
+
ssca: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
|
|
305
315
|
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
306
|
-
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
307
|
-
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
308
|
-
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
309
316
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
310
317
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
311
318
|
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
312
319
|
svsui: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI",
|
|
313
320
|
swsol: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
|
|
314
|
-
swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
|
|
315
|
-
sdeep:
|
|
316
|
-
|
|
321
|
+
swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
|
|
322
|
+
// sdeep:
|
|
323
|
+
// '0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP',
|
|
324
|
+
// sfud: '0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD',
|
|
317
325
|
};
|
|
318
326
|
var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
319
327
|
(acc, [coinName, coinType]) => {
|
|
@@ -322,6 +330,13 @@ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
322
330
|
},
|
|
323
331
|
{}
|
|
324
332
|
);
|
|
333
|
+
var sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
334
|
+
(acc, [coinName, coinType]) => {
|
|
335
|
+
acc[coinType.split("::")[2].toLowerCase()] = coinName;
|
|
336
|
+
return acc;
|
|
337
|
+
},
|
|
338
|
+
{}
|
|
339
|
+
);
|
|
325
340
|
|
|
326
341
|
// src/constants/flashloan.ts
|
|
327
342
|
var FlashLoanFeeObjectMap = {
|
|
@@ -396,13 +411,16 @@ var POOL_ADDRESSES = {
|
|
|
396
411
|
sca: {
|
|
397
412
|
lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
|
|
398
413
|
collateralPoolAddress: "0xff677a5d9e9dc8f08f0a8681ebfc7481d1c7d57bc441f2881974adcdd7b13c31"
|
|
399
|
-
},
|
|
400
|
-
fud: {
|
|
401
|
-
lendingPoolAddress: "0x14367ddca30e2860cb89ed4eaca20c7ece260c5d59dd9990d2c85a8321326acb"
|
|
402
|
-
},
|
|
403
|
-
deep: {
|
|
404
|
-
lendingPoolAddress: "0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03"
|
|
405
414
|
}
|
|
415
|
+
// TODO: enable for production
|
|
416
|
+
// fud: {
|
|
417
|
+
// lendingPoolAddress:
|
|
418
|
+
// '0x14367ddca30e2860cb89ed4eaca20c7ece260c5d59dd9990d2c85a8321326acb',
|
|
419
|
+
// },
|
|
420
|
+
// deep: {
|
|
421
|
+
// lendingPoolAddress:
|
|
422
|
+
// '0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03',
|
|
423
|
+
// },
|
|
406
424
|
};
|
|
407
425
|
|
|
408
426
|
// src/constants/pyth.ts
|
|
@@ -424,9 +442,10 @@ var PYTH_FEED_IDS = {
|
|
|
424
442
|
afsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
425
443
|
hasui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
426
444
|
vsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
427
|
-
sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
|
|
428
|
-
|
|
429
|
-
|
|
445
|
+
sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
|
|
446
|
+
// TODO: enable for production
|
|
447
|
+
// deep: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
|
|
448
|
+
// fud: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
|
|
430
449
|
};
|
|
431
450
|
|
|
432
451
|
// src/constants/queryKeys.ts
|
|
@@ -952,7 +971,7 @@ var TEST_ADDRESSES = {
|
|
|
952
971
|
|
|
953
972
|
// src/constants/tokenBucket.ts
|
|
954
973
|
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
955
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
974
|
+
var DEFAULT_INTERVAL_IN_MS = 100;
|
|
956
975
|
|
|
957
976
|
// src/constants/vesca.ts
|
|
958
977
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1556,7 +1575,7 @@ var TokenBucket = class {
|
|
|
1556
1575
|
return false;
|
|
1557
1576
|
}
|
|
1558
1577
|
};
|
|
1559
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
1578
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
|
|
1560
1579
|
let retries = 0;
|
|
1561
1580
|
const tryRequest = async () => {
|
|
1562
1581
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1592,13 +1611,19 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1592
1611
|
|
|
1593
1612
|
// src/utils/indexer.ts
|
|
1594
1613
|
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1595
|
-
const
|
|
1596
|
-
if (indexer) {
|
|
1614
|
+
const lastArgs = args[args.length - 1];
|
|
1615
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1597
1616
|
try {
|
|
1598
1617
|
return await method.apply(context, args);
|
|
1599
1618
|
} catch (e) {
|
|
1600
1619
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1601
|
-
return await method.apply(context, [
|
|
1620
|
+
return await method.apply(context, [
|
|
1621
|
+
...args.slice(0, -1),
|
|
1622
|
+
{
|
|
1623
|
+
...lastArgs,
|
|
1624
|
+
indexer: false
|
|
1625
|
+
}
|
|
1626
|
+
]);
|
|
1602
1627
|
}
|
|
1603
1628
|
}
|
|
1604
1629
|
return await method.apply(context, args);
|
|
@@ -2466,15 +2491,21 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
2466
2491
|
};
|
|
2467
2492
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
2468
2493
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2469
|
-
], indexer = false, coinPrices) => {
|
|
2494
|
+
], indexer = false, marketPools, coinPrices) => {
|
|
2470
2495
|
const borrowIncentivePools = {};
|
|
2471
|
-
|
|
2496
|
+
marketPools = marketPools ?? await query.getMarketPools(void 0, { indexer, coinPrices });
|
|
2497
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
|
|
2472
2498
|
if (indexer) {
|
|
2473
2499
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2474
2500
|
const updateBorrowIncentivePool = (pool) => {
|
|
2475
2501
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
2476
2502
|
return;
|
|
2477
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
2503
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
2504
|
+
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2505
|
+
if (pool.points[sCoinName]) {
|
|
2506
|
+
pool.points[sCoinName].coinPrice = coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2478
2509
|
borrowIncentivePools[pool.coinName] = pool;
|
|
2479
2510
|
};
|
|
2480
2511
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -2500,12 +2531,15 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2500
2531
|
for (const [coinName, poolPoint] of Object.entries(
|
|
2501
2532
|
parsedBorrowIncentivePoolData.poolPoints
|
|
2502
2533
|
)) {
|
|
2503
|
-
const rewardCoinType =
|
|
2504
|
-
|
|
2534
|
+
const rewardCoinType = poolPoint.pointType;
|
|
2535
|
+
let rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2505
2536
|
rewardCoinType
|
|
2506
2537
|
);
|
|
2507
|
-
|
|
2538
|
+
if (sCoinRawNameToName[rewardCoinName]) {
|
|
2539
|
+
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
2540
|
+
}
|
|
2508
2541
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2542
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2509
2543
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2510
2544
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2511
2545
|
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
@@ -2651,7 +2685,7 @@ var supplyLimitZod = zod.object({
|
|
|
2651
2685
|
value: zod.string()
|
|
2652
2686
|
})
|
|
2653
2687
|
});
|
|
2654
|
-
var supplyLimitKeyType = `
|
|
2688
|
+
var supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
|
|
2655
2689
|
var getSupplyLimit = async (utils, poolName) => {
|
|
2656
2690
|
try {
|
|
2657
2691
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
@@ -2691,7 +2725,7 @@ var isolatedAssetZod = zod2.object({
|
|
|
2691
2725
|
value: zod2.boolean()
|
|
2692
2726
|
})
|
|
2693
2727
|
});
|
|
2694
|
-
var isolatedAssetKeyType = `
|
|
2728
|
+
var isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
|
|
2695
2729
|
var getIsolatedAssets = async (address) => {
|
|
2696
2730
|
try {
|
|
2697
2731
|
const marketObject = address.get("core.market");
|
|
@@ -2771,7 +2805,7 @@ var borrowLimitZod = zod3.object({
|
|
|
2771
2805
|
value: zod3.string()
|
|
2772
2806
|
})
|
|
2773
2807
|
});
|
|
2774
|
-
var borrowLimitKeyType = `
|
|
2808
|
+
var borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
|
|
2775
2809
|
var getBorrowLimit = async (utils, poolName) => {
|
|
2776
2810
|
try {
|
|
2777
2811
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
@@ -2938,7 +2972,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2938
2972
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
2939
2973
|
showContent: true
|
|
2940
2974
|
});
|
|
2941
|
-
coinPrices = await query.utils.getCoinPrices(
|
|
2975
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
2942
2976
|
const marketPools = {};
|
|
2943
2977
|
if (indexer) {
|
|
2944
2978
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
@@ -2971,154 +3005,150 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
2971
3005
|
return marketPools;
|
|
2972
3006
|
};
|
|
2973
3007
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
3008
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName];
|
|
3009
|
+
if (indexer) {
|
|
3010
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
3011
|
+
if (!marketPoolIndexer) {
|
|
3012
|
+
return void 0;
|
|
3013
|
+
}
|
|
3014
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
3015
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
3016
|
+
marketPoolIndexer.coinName
|
|
3017
|
+
);
|
|
3018
|
+
return marketPoolIndexer;
|
|
3019
|
+
}
|
|
3020
|
+
const marketId = query.address.get("core.market");
|
|
3021
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
3022
|
+
showContent: true
|
|
3023
|
+
}))?.data;
|
|
3024
|
+
if (!(marketObject && marketObject.content?.dataType === "moveObject"))
|
|
3025
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
3026
|
+
const fields = marketObject.content.fields;
|
|
3027
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
3028
|
+
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
3029
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3030
|
+
parentId: balanceSheetParentId,
|
|
3031
|
+
name: {
|
|
3032
|
+
type: "0x1::type_name::TypeName",
|
|
3033
|
+
value: {
|
|
3034
|
+
name: coinType.substring(2)
|
|
2980
3035
|
}
|
|
2981
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
2982
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
2983
|
-
marketPoolIndexer.coinName
|
|
2984
|
-
);
|
|
2985
|
-
return marketPoolIndexer;
|
|
2986
3036
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
name: coinType.substring(2)
|
|
3002
|
-
}
|
|
3037
|
+
});
|
|
3038
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
|
|
3039
|
+
if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
|
|
3040
|
+
throw new Error(
|
|
3041
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
3042
|
+
);
|
|
3043
|
+
const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
|
|
3044
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
3045
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3046
|
+
parentId: borrowIndexParentId,
|
|
3047
|
+
name: {
|
|
3048
|
+
type: "0x1::type_name::TypeName",
|
|
3049
|
+
value: {
|
|
3050
|
+
name: coinType.substring(2)
|
|
3003
3051
|
}
|
|
3004
|
-
}
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3052
|
+
}
|
|
3053
|
+
});
|
|
3054
|
+
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
|
|
3055
|
+
if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
|
|
3056
|
+
throw new Error(
|
|
3057
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
3058
|
+
);
|
|
3059
|
+
const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
|
|
3060
|
+
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
3061
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3062
|
+
parentId: interestModelParentId,
|
|
3063
|
+
name: {
|
|
3064
|
+
type: "0x1::type_name::TypeName",
|
|
3065
|
+
value: {
|
|
3066
|
+
name: coinType.substring(2)
|
|
3019
3067
|
}
|
|
3020
|
-
}
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3068
|
+
}
|
|
3069
|
+
});
|
|
3070
|
+
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3071
|
+
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3072
|
+
throw new Error(
|
|
3073
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3074
|
+
);
|
|
3075
|
+
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3076
|
+
const getBorrowFee = async () => {
|
|
3077
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3078
|
+
parentId: marketId,
|
|
3030
3079
|
name: {
|
|
3031
|
-
type:
|
|
3080
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3032
3081
|
value: {
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
}
|
|
3036
|
-
});
|
|
3037
|
-
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3038
|
-
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3039
|
-
throw new Error(
|
|
3040
|
-
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3041
|
-
);
|
|
3042
|
-
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3043
|
-
const getBorrowFee = async () => {
|
|
3044
|
-
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3045
|
-
parentId: marketId,
|
|
3046
|
-
name: {
|
|
3047
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3048
|
-
value: {
|
|
3049
|
-
type: {
|
|
3050
|
-
name: coinType.substring(2)
|
|
3051
|
-
}
|
|
3082
|
+
type: {
|
|
3083
|
+
name: coinType.substring(2)
|
|
3052
3084
|
}
|
|
3053
3085
|
}
|
|
3054
|
-
}
|
|
3055
|
-
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3056
|
-
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3057
|
-
return { value: "0" };
|
|
3058
|
-
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3059
|
-
};
|
|
3060
|
-
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3061
|
-
type: interestModel.type.fields,
|
|
3062
|
-
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3063
|
-
interestRate: borrowIndex.interest_rate.fields,
|
|
3064
|
-
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3065
|
-
borrowIndex: borrowIndex.borrow_index,
|
|
3066
|
-
lastUpdated: borrowIndex.last_updated,
|
|
3067
|
-
cash: balanceSheet.cash,
|
|
3068
|
-
debt: balanceSheet.debt,
|
|
3069
|
-
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3070
|
-
reserve: balanceSheet.revenue,
|
|
3071
|
-
reserveFactor: interestModel.revenue_factor.fields,
|
|
3072
|
-
borrowWeight: interestModel.borrow_weight.fields,
|
|
3073
|
-
borrowFeeRate: await getBorrowFee(),
|
|
3074
|
-
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3075
|
-
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3076
|
-
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3077
|
-
highKink: interestModel.high_kink.fields,
|
|
3078
|
-
midKink: interestModel.mid_kink.fields,
|
|
3079
|
-
minBorrowAmount: interestModel.min_borrow_amount
|
|
3086
|
+
}
|
|
3080
3087
|
});
|
|
3081
|
-
const
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3088
|
+
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3089
|
+
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3090
|
+
return { value: "0" };
|
|
3091
|
+
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3092
|
+
};
|
|
3093
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3094
|
+
type: interestModel.type.fields,
|
|
3095
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3096
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
3097
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3098
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
3099
|
+
lastUpdated: borrowIndex.last_updated,
|
|
3100
|
+
cash: balanceSheet.cash,
|
|
3101
|
+
debt: balanceSheet.debt,
|
|
3102
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3103
|
+
reserve: balanceSheet.revenue,
|
|
3104
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
3105
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
3106
|
+
borrowFeeRate: await getBorrowFee(),
|
|
3107
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3108
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3109
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3110
|
+
highKink: interestModel.high_kink.fields,
|
|
3111
|
+
midKink: interestModel.mid_kink.fields,
|
|
3112
|
+
minBorrowAmount: interestModel.min_borrow_amount
|
|
3113
|
+
});
|
|
3114
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
3115
|
+
query.utils,
|
|
3116
|
+
parsedMarketPoolData
|
|
3117
|
+
);
|
|
3118
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3119
|
+
const maxSupplyCoin = BigNumber3(
|
|
3120
|
+
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
3121
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3122
|
+
const maxBorrowCoin = BigNumber3(
|
|
3123
|
+
await getBorrowLimit(query.utils, poolCoinName) ?? "0"
|
|
3124
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3125
|
+
return {
|
|
3126
|
+
coinName: poolCoinName,
|
|
3127
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3128
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
3129
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
3130
|
+
sCoinType: query.utils.parseSCoinType(
|
|
3131
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
3132
|
+
),
|
|
3133
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
3134
|
+
coinDecimal,
|
|
3135
|
+
coinPrice: coinPrice ?? 0,
|
|
3136
|
+
highKink: parsedMarketPoolData.highKink,
|
|
3137
|
+
midKink: parsedMarketPoolData.midKink,
|
|
3138
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
3139
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
3140
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
3141
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
3142
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
3143
|
+
maxSupplyCoin,
|
|
3144
|
+
maxBorrowCoin,
|
|
3145
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
3146
|
+
...calculatedMarketPoolData
|
|
3147
|
+
};
|
|
3118
3148
|
};
|
|
3119
3149
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
3120
3150
|
const marketId = query.address.get("core.market");
|
|
3121
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
3151
|
+
const coinPrices = await query.utils.getCoinPrices() ?? {};
|
|
3122
3152
|
const marketCollaterals = {};
|
|
3123
3153
|
if (indexer) {
|
|
3124
3154
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -3154,7 +3184,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
3154
3184
|
return marketCollaterals;
|
|
3155
3185
|
};
|
|
3156
3186
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3157
|
-
coinPrice = coinPrice
|
|
3187
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[collateralCoinName];
|
|
3158
3188
|
if (indexer) {
|
|
3159
3189
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
3160
3190
|
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
@@ -3470,11 +3500,13 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3470
3500
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3471
3501
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3472
3502
|
);
|
|
3473
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
3474
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
3503
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
3504
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
3505
|
+
indexer,
|
|
3475
3506
|
coinPrices
|
|
3476
3507
|
});
|
|
3477
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
3508
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
3509
|
+
indexer,
|
|
3478
3510
|
marketPools,
|
|
3479
3511
|
coinPrices
|
|
3480
3512
|
});
|
|
@@ -3508,22 +3540,20 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3508
3540
|
};
|
|
3509
3541
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3510
3542
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3511
|
-
coinPrice = coinPrice ?? (await query.utils.getCoinPrices(
|
|
3512
|
-
marketPool = marketPool ?? await query.getMarketPool(poolCoinName,
|
|
3543
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
3544
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
|
|
3545
|
+
indexer,
|
|
3513
3546
|
coinPrice
|
|
3514
3547
|
});
|
|
3515
3548
|
if (!marketPool)
|
|
3516
3549
|
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3517
|
-
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3518
|
-
marketCoinName,
|
|
3550
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, {
|
|
3519
3551
|
indexer,
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
[poolCoinName]: coinPrice
|
|
3524
|
-
}
|
|
3552
|
+
marketPool,
|
|
3553
|
+
coinPrices: {
|
|
3554
|
+
[poolCoinName]: coinPrice
|
|
3525
3555
|
}
|
|
3526
|
-
) : void 0;
|
|
3556
|
+
}) : void 0;
|
|
3527
3557
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3528
3558
|
marketCoinName,
|
|
3529
3559
|
ownerAddress
|
|
@@ -3643,7 +3673,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3643
3673
|
};
|
|
3644
3674
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3645
3675
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3646
|
-
const market = await query.queryMarket(indexer,
|
|
3676
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
3647
3677
|
const [coinAmounts, obligations] = await Promise.all([
|
|
3648
3678
|
query.getCoinAmounts(void 0, ownerAddress),
|
|
3649
3679
|
query.getObligations(ownerAddress)
|
|
@@ -3668,13 +3698,14 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3668
3698
|
const collateralAssetCoinNames = [
|
|
3669
3699
|
...SUPPORT_COLLATERALS
|
|
3670
3700
|
];
|
|
3671
|
-
|
|
3672
|
-
|
|
3701
|
+
market = market ?? await query.queryMarket({ indexer });
|
|
3702
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
|
|
3673
3703
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3674
3704
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3675
3705
|
query.queryObligation(obligationId),
|
|
3676
|
-
query.getBorrowIncentivePools(void 0,
|
|
3677
|
-
coinPrices
|
|
3706
|
+
query.getBorrowIncentivePools(void 0, {
|
|
3707
|
+
coinPrices,
|
|
3708
|
+
indexer
|
|
3678
3709
|
}),
|
|
3679
3710
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3680
3711
|
]);
|
|
@@ -3810,44 +3841,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3810
3841
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3811
3842
|
if (borrowIncentivePool) {
|
|
3812
3843
|
const rewards = [];
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
BigNumber5(
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3844
|
+
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
3845
|
+
([key, accountPoint]) => {
|
|
3846
|
+
const poolPoint = borrowIncentivePool.points[key];
|
|
3847
|
+
if (accountPoint && poolPoint) {
|
|
3848
|
+
let availableClaimAmount = BigNumber5(0);
|
|
3849
|
+
let availableClaimCoin = BigNumber5(0);
|
|
3850
|
+
const accountBorrowedAmount = BigNumber5(
|
|
3851
|
+
accountPoint.weightedAmount
|
|
3852
|
+
);
|
|
3853
|
+
const baseIndexRate = 1e9;
|
|
3854
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3855
|
+
BigNumber5(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3856
|
+
0
|
|
3857
|
+
) : 1;
|
|
3858
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3859
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3860
|
+
);
|
|
3861
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3862
|
+
-1 * poolPoint.coinDecimal
|
|
3863
|
+
);
|
|
3864
|
+
const weightScale = BigNumber5(1e12);
|
|
3865
|
+
const boostValue = BigNumber5(accountPoint.weightedAmount).div(
|
|
3866
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3867
|
+
).isFinite() ? BigNumber5(accountPoint.weightedAmount).div(
|
|
3868
|
+
BigNumber5(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3869
|
+
).toNumber() : 1;
|
|
3870
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3871
|
+
rewards.push({
|
|
3872
|
+
coinName: poolPoint.coinName,
|
|
3873
|
+
coinType: poolPoint.coinType,
|
|
3874
|
+
symbol: poolPoint.symbol,
|
|
3875
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3876
|
+
coinPrice: poolPoint.coinPrice,
|
|
3877
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3878
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3879
|
+
boostValue
|
|
3880
|
+
});
|
|
3881
|
+
}
|
|
3848
3882
|
}
|
|
3849
3883
|
}
|
|
3850
|
-
|
|
3884
|
+
);
|
|
3851
3885
|
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3852
3886
|
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3853
3887
|
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
@@ -3954,7 +3988,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3954
3988
|
return obligationAccount;
|
|
3955
3989
|
};
|
|
3956
3990
|
var getTotalValueLocked = async (query, indexer = false) => {
|
|
3957
|
-
const market = await query.queryMarket(indexer);
|
|
3991
|
+
const market = await query.queryMarket({ indexer });
|
|
3958
3992
|
let supplyValue = BigNumber5(0);
|
|
3959
3993
|
let borrowValue = BigNumber5(0);
|
|
3960
3994
|
if (indexer) {
|
|
@@ -3991,6 +4025,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
3991
4025
|
};
|
|
3992
4026
|
|
|
3993
4027
|
// src/queries/priceQuery.ts
|
|
4028
|
+
import BigNumber6 from "bignumber.js";
|
|
3994
4029
|
var getPythPrice = async ({
|
|
3995
4030
|
address
|
|
3996
4031
|
}, assetCoinName, priceFeedObject) => {
|
|
@@ -4072,6 +4107,22 @@ var getPythPrices = async ({
|
|
|
4072
4107
|
{}
|
|
4073
4108
|
);
|
|
4074
4109
|
};
|
|
4110
|
+
var getAllCoinPrices = async (query, marketPools, coinPrices) => {
|
|
4111
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
4112
|
+
marketPools = marketPools ?? await query.getMarketPools(void 0, { coinPrices });
|
|
4113
|
+
if (!marketPools) {
|
|
4114
|
+
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
4115
|
+
}
|
|
4116
|
+
const sCoinPrices = {};
|
|
4117
|
+
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
4118
|
+
const coinName = query.utils.parseCoinName(sCoinName);
|
|
4119
|
+
sCoinPrices[sCoinName] = BigNumber6(coinPrices[coinName] ?? 0).multipliedBy(marketPools[coinName]?.conversionRate ?? 1).toNumber();
|
|
4120
|
+
});
|
|
4121
|
+
return {
|
|
4122
|
+
...coinPrices,
|
|
4123
|
+
...sCoinPrices
|
|
4124
|
+
};
|
|
4125
|
+
};
|
|
4075
4126
|
|
|
4076
4127
|
// src/queries/referralQuery.ts
|
|
4077
4128
|
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
@@ -4092,7 +4143,7 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4092
4143
|
// src/queries/sCoinQuery.ts
|
|
4093
4144
|
import { bcs } from "@mysten/sui/bcs";
|
|
4094
4145
|
import assert from "assert";
|
|
4095
|
-
import
|
|
4146
|
+
import BigNumber7 from "bignumber.js";
|
|
4096
4147
|
var getSCoinTotalSupply = async ({
|
|
4097
4148
|
utils
|
|
4098
4149
|
}, sCoinName) => {
|
|
@@ -4113,7 +4164,7 @@ var getSCoinTotalSupply = async ({
|
|
|
4113
4164
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4114
4165
|
const type = results[0].returnValues[0][1];
|
|
4115
4166
|
assert(type === "u64", "Result type is not u64");
|
|
4116
|
-
return
|
|
4167
|
+
return BigNumber7(bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
4117
4168
|
}
|
|
4118
4169
|
return 0;
|
|
4119
4170
|
};
|
|
@@ -4139,7 +4190,7 @@ var getSCoinAmount = async ({
|
|
|
4139
4190
|
owner,
|
|
4140
4191
|
coinType: sCoinType
|
|
4141
4192
|
});
|
|
4142
|
-
return
|
|
4193
|
+
return BigNumber7(amount).toNumber();
|
|
4143
4194
|
};
|
|
4144
4195
|
var isSupportStakeCoins = (value) => {
|
|
4145
4196
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4158,8 +4209,8 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4158
4209
|
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
4159
4210
|
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
4160
4211
|
const marketPools = await Promise.all([
|
|
4161
|
-
query.getMarketPool(fromCoinName
|
|
4162
|
-
query.getMarketPool(toCoinName
|
|
4212
|
+
query.getMarketPool(fromCoinName),
|
|
4213
|
+
query.getMarketPool(toCoinName)
|
|
4163
4214
|
]);
|
|
4164
4215
|
if (marketPools.some((pool) => !pool))
|
|
4165
4216
|
throw new Error("Failed to fetch the lendings data");
|
|
@@ -4169,7 +4220,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4169
4220
|
const ScoinAToARate = marketPools[0].conversionRate;
|
|
4170
4221
|
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
4171
4222
|
const calcAtoBRate = async () => {
|
|
4172
|
-
const prices = await query.utils.getCoinPrices(
|
|
4223
|
+
const prices = await query.utils.getCoinPrices();
|
|
4173
4224
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
4174
4225
|
throw new Error("Failed to fetch the coin prices");
|
|
4175
4226
|
}
|
|
@@ -4179,7 +4230,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4179
4230
|
return prices[fromCoinName] / prices[toCoinName];
|
|
4180
4231
|
};
|
|
4181
4232
|
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
4182
|
-
return
|
|
4233
|
+
return BigNumber7(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
4183
4234
|
};
|
|
4184
4235
|
|
|
4185
4236
|
// src/queries/spoolQuery.ts
|
|
@@ -4189,7 +4240,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4189
4240
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4190
4241
|
);
|
|
4191
4242
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4192
|
-
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
4243
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, { indexer });
|
|
4193
4244
|
if (!marketPools)
|
|
4194
4245
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4195
4246
|
const spools = {};
|
|
@@ -4230,7 +4281,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4230
4281
|
};
|
|
4231
4282
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
4232
4283
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4233
|
-
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
4284
|
+
marketPool = marketPool || await query.getMarketPool(coinName, { indexer });
|
|
4234
4285
|
if (!marketPool) {
|
|
4235
4286
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
4236
4287
|
}
|
|
@@ -4239,7 +4290,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4239
4290
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4240
4291
|
);
|
|
4241
4292
|
let spool = void 0;
|
|
4242
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
4293
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4243
4294
|
if (indexer) {
|
|
4244
4295
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4245
4296
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
@@ -4259,7 +4310,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4259
4310
|
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4260
4311
|
}
|
|
4261
4312
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4262
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
4313
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4263
4314
|
const spoolObject = spoolObjectResponse[0];
|
|
4264
4315
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
4265
4316
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
@@ -4503,7 +4554,7 @@ var getStakeRewardPool = async ({
|
|
|
4503
4554
|
};
|
|
4504
4555
|
|
|
4505
4556
|
// src/queries/vescaQuery.ts
|
|
4506
|
-
import
|
|
4557
|
+
import BigNumber8 from "bignumber.js";
|
|
4507
4558
|
import { SUI_CLOCK_OBJECT_ID, SuiTxBlock as SuiTxBlock2 } from "@scallop-io/sui-kit";
|
|
4508
4559
|
import { bcs as bcs2 } from "@mysten/sui/bcs";
|
|
4509
4560
|
import { z as zod5 } from "zod";
|
|
@@ -4585,7 +4636,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4585
4636
|
0
|
|
4586
4637
|
);
|
|
4587
4638
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
4588
|
-
const lockedScaCoin =
|
|
4639
|
+
const lockedScaCoin = BigNumber8(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
4589
4640
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
4590
4641
|
vesca = {
|
|
4591
4642
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -4595,7 +4646,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4595
4646
|
lockedScaAmount,
|
|
4596
4647
|
lockedScaCoin,
|
|
4597
4648
|
currentVeScaBalance,
|
|
4598
|
-
unlockAt:
|
|
4649
|
+
unlockAt: BigNumber8(dynamicFields.unlock_at * 1e3).toNumber()
|
|
4599
4650
|
};
|
|
4600
4651
|
}
|
|
4601
4652
|
return vesca;
|
|
@@ -4657,10 +4708,10 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4657
4708
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
4658
4709
|
return null;
|
|
4659
4710
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
4660
|
-
const totalLockedSca =
|
|
4711
|
+
const totalLockedSca = BigNumber8(
|
|
4661
4712
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
4662
4713
|
).shiftedBy(-9).toNumber();
|
|
4663
|
-
const totalVeSca =
|
|
4714
|
+
const totalVeSca = BigNumber8(
|
|
4664
4715
|
await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
|
|
4665
4716
|
).shiftedBy(-9).toNumber();
|
|
4666
4717
|
const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
|
|
@@ -4696,15 +4747,6 @@ var ScallopUtils = class {
|
|
|
4696
4747
|
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
4697
4748
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
4698
4749
|
};
|
|
4699
|
-
/**
|
|
4700
|
-
* Get reward type of borrow incentive pool.
|
|
4701
|
-
*
|
|
4702
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
4703
|
-
* @return Borrow incentive reward coin name.
|
|
4704
|
-
*/
|
|
4705
|
-
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
4706
|
-
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
4707
|
-
};
|
|
4708
4750
|
this.params = {
|
|
4709
4751
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4710
4752
|
...params
|
|
@@ -4774,7 +4816,10 @@ var ScallopUtils = class {
|
|
|
4774
4816
|
* @param coinName - Specific support coin name.
|
|
4775
4817
|
* @return Coin type.
|
|
4776
4818
|
*/
|
|
4777
|
-
parseCoinType(coinName) {
|
|
4819
|
+
parseCoinType(coinName, useOldMarketCoin = false) {
|
|
4820
|
+
if (sCoinIds[coinName] && !useOldMarketCoin) {
|
|
4821
|
+
return sCoinIds[coinName];
|
|
4822
|
+
}
|
|
4778
4823
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
4779
4824
|
const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
4780
4825
|
if (!coinPackageId) {
|
|
@@ -4829,6 +4874,15 @@ var ScallopUtils = class {
|
|
|
4829
4874
|
return void 0;
|
|
4830
4875
|
}
|
|
4831
4876
|
}
|
|
4877
|
+
/**
|
|
4878
|
+
* Convert sCoin name to coin name.
|
|
4879
|
+
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
4880
|
+
* e.g: `scallop_sui -> ssui
|
|
4881
|
+
* @return sCoin name
|
|
4882
|
+
*/
|
|
4883
|
+
parseCoinNameFromSCoinName(coinName) {
|
|
4884
|
+
return sCoinRawNameToName[coinName];
|
|
4885
|
+
}
|
|
4832
4886
|
/**
|
|
4833
4887
|
* Convert sCoin name into sCoin type
|
|
4834
4888
|
* @param sCoinName
|
|
@@ -4871,7 +4925,7 @@ var ScallopUtils = class {
|
|
|
4871
4925
|
*/
|
|
4872
4926
|
parseMarketCoinType(coinName) {
|
|
4873
4927
|
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4874
|
-
const coinType = this.parseCoinType(coinName);
|
|
4928
|
+
const coinType = this.parseCoinType(coinName, true);
|
|
4875
4929
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4876
4930
|
}
|
|
4877
4931
|
parseCoinNameFromType(coinType) {
|
|
@@ -4880,7 +4934,7 @@ var ScallopUtils = class {
|
|
|
4880
4934
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
4881
4935
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
4882
4936
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
4883
|
-
const
|
|
4937
|
+
const wormholeCoinTypeMap = {
|
|
4884
4938
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
4885
4939
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
4886
4940
|
[`${this.address.get("core.coins.weth.id") ?? wormholeCoinIds.weth}::coin::COIN`]: "weth",
|
|
@@ -4900,7 +4954,7 @@ var ScallopUtils = class {
|
|
|
4900
4954
|
},
|
|
4901
4955
|
{}
|
|
4902
4956
|
);
|
|
4903
|
-
const assetCoinName =
|
|
4957
|
+
const assetCoinName = wormholeCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
4904
4958
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
4905
4959
|
}
|
|
4906
4960
|
/**
|
|
@@ -6014,11 +6068,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6014
6068
|
]
|
|
6015
6069
|
);
|
|
6016
6070
|
},
|
|
6017
|
-
claimBorrowIncentive: (obligationId, obligationKey,
|
|
6018
|
-
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
6019
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
6020
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
6021
|
-
}
|
|
6071
|
+
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
6022
6072
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
6023
6073
|
return txBlock.moveCall(
|
|
6024
6074
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -6111,7 +6161,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6111
6161
|
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6112
6162
|
}
|
|
6113
6163
|
},
|
|
6114
|
-
claimBorrowIncentiveQuick: async (
|
|
6164
|
+
claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
|
|
6115
6165
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6116
6166
|
builder,
|
|
6117
6167
|
txBlock,
|
|
@@ -6121,7 +6171,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6121
6171
|
return txBlock.claimBorrowIncentive(
|
|
6122
6172
|
obligationArg,
|
|
6123
6173
|
obligationKeyArg,
|
|
6124
|
-
coinName,
|
|
6125
6174
|
rewardCoinName
|
|
6126
6175
|
);
|
|
6127
6176
|
}
|
|
@@ -7025,8 +7074,8 @@ var ScallopQuery = class {
|
|
|
7025
7074
|
* @param indexer - Whether to use indexer.
|
|
7026
7075
|
* @return Market data.
|
|
7027
7076
|
*/
|
|
7028
|
-
async queryMarket(
|
|
7029
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
7077
|
+
async queryMarket(args) {
|
|
7078
|
+
return await queryMarket(this, args?.indexer, args?.coinPrices);
|
|
7030
7079
|
}
|
|
7031
7080
|
/**
|
|
7032
7081
|
* Get market pools.
|
|
@@ -7039,8 +7088,13 @@ var ScallopQuery = class {
|
|
|
7039
7088
|
* @param indexer - Whether to use indexer.
|
|
7040
7089
|
* @return Market pools data.
|
|
7041
7090
|
*/
|
|
7042
|
-
async getMarketPools(poolCoinNames,
|
|
7043
|
-
return await getMarketPools(
|
|
7091
|
+
async getMarketPools(poolCoinNames, args) {
|
|
7092
|
+
return await getMarketPools(
|
|
7093
|
+
this,
|
|
7094
|
+
poolCoinNames,
|
|
7095
|
+
args?.indexer,
|
|
7096
|
+
args?.coinPrices
|
|
7097
|
+
);
|
|
7044
7098
|
}
|
|
7045
7099
|
/**
|
|
7046
7100
|
* Get market pool
|
|
@@ -7049,11 +7103,11 @@ var ScallopQuery = class {
|
|
|
7049
7103
|
* @param indexer - Whether to use indexer.
|
|
7050
7104
|
* @return Market pool data.
|
|
7051
7105
|
*/
|
|
7052
|
-
async getMarketPool(poolCoinName,
|
|
7106
|
+
async getMarketPool(poolCoinName, args) {
|
|
7053
7107
|
return await getMarketPool(
|
|
7054
7108
|
this,
|
|
7055
7109
|
poolCoinName,
|
|
7056
|
-
indexer,
|
|
7110
|
+
args?.indexer,
|
|
7057
7111
|
args?.marketObject,
|
|
7058
7112
|
args?.coinPrice
|
|
7059
7113
|
);
|
|
@@ -7069,8 +7123,8 @@ var ScallopQuery = class {
|
|
|
7069
7123
|
* @param indexer - Whether to use indexer.
|
|
7070
7124
|
* @return Market collaterals data.
|
|
7071
7125
|
*/
|
|
7072
|
-
async getMarketCollaterals(collateralCoinNames,
|
|
7073
|
-
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
7126
|
+
async getMarketCollaterals(collateralCoinNames, args) {
|
|
7127
|
+
return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
|
|
7074
7128
|
}
|
|
7075
7129
|
/**
|
|
7076
7130
|
* Get market collateral
|
|
@@ -7079,8 +7133,8 @@ var ScallopQuery = class {
|
|
|
7079
7133
|
* @param indexer - Whether to use indexer.
|
|
7080
7134
|
* @return Market collateral data.
|
|
7081
7135
|
*/
|
|
7082
|
-
async getMarketCollateral(collateralCoinName,
|
|
7083
|
-
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
7136
|
+
async getMarketCollateral(collateralCoinName, args) {
|
|
7137
|
+
return await getMarketCollateral(this, collateralCoinName, args?.indexer);
|
|
7084
7138
|
}
|
|
7085
7139
|
/**
|
|
7086
7140
|
* Get obligations data.
|
|
@@ -7166,11 +7220,11 @@ var ScallopQuery = class {
|
|
|
7166
7220
|
* @param indexer - Whether to use indexer.
|
|
7167
7221
|
* @return Spools data.
|
|
7168
7222
|
*/
|
|
7169
|
-
async getSpools(stakeMarketCoinNames,
|
|
7223
|
+
async getSpools(stakeMarketCoinNames, args) {
|
|
7170
7224
|
return await getSpools(
|
|
7171
7225
|
this,
|
|
7172
7226
|
stakeMarketCoinNames,
|
|
7173
|
-
indexer,
|
|
7227
|
+
args?.indexer,
|
|
7174
7228
|
args?.marketPools,
|
|
7175
7229
|
args?.coinPrices
|
|
7176
7230
|
);
|
|
@@ -7182,11 +7236,11 @@ var ScallopQuery = class {
|
|
|
7182
7236
|
* @param indexer - Whether to use indexer.
|
|
7183
7237
|
* @return Spool data.
|
|
7184
7238
|
*/
|
|
7185
|
-
async getSpool(stakeMarketCoinName,
|
|
7239
|
+
async getSpool(stakeMarketCoinName, args) {
|
|
7186
7240
|
return await getSpool(
|
|
7187
7241
|
this,
|
|
7188
7242
|
stakeMarketCoinName,
|
|
7189
|
-
indexer,
|
|
7243
|
+
args?.indexer,
|
|
7190
7244
|
args?.marketPool,
|
|
7191
7245
|
args?.coinPrices
|
|
7192
7246
|
);
|
|
@@ -7289,11 +7343,12 @@ var ScallopQuery = class {
|
|
|
7289
7343
|
* @param indexer - Whether to use indexer.
|
|
7290
7344
|
* @return Borrow incentive pools data.
|
|
7291
7345
|
*/
|
|
7292
|
-
async getBorrowIncentivePools(coinNames,
|
|
7346
|
+
async getBorrowIncentivePools(coinNames, args) {
|
|
7293
7347
|
return await getBorrowIncentivePools(
|
|
7294
7348
|
this,
|
|
7295
7349
|
coinNames,
|
|
7296
|
-
indexer,
|
|
7350
|
+
args?.indexer,
|
|
7351
|
+
args?.marketPools,
|
|
7297
7352
|
args?.coinPrices
|
|
7298
7353
|
);
|
|
7299
7354
|
}
|
|
@@ -7315,8 +7370,8 @@ var ScallopQuery = class {
|
|
|
7315
7370
|
* @param indexer - Whether to use indexer.
|
|
7316
7371
|
* @return All lending and spool infomation.
|
|
7317
7372
|
*/
|
|
7318
|
-
async getLendings(poolCoinNames, ownerAddress = this.walletAddress,
|
|
7319
|
-
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
7373
|
+
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
7374
|
+
return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
|
|
7320
7375
|
}
|
|
7321
7376
|
/**
|
|
7322
7377
|
* Get user lending and spool information for specific pool.
|
|
@@ -7326,8 +7381,8 @@ var ScallopQuery = class {
|
|
|
7326
7381
|
* @param indexer - Whether to use indexer.
|
|
7327
7382
|
* @return Lending pool data.
|
|
7328
7383
|
*/
|
|
7329
|
-
async getLending(poolCoinName, ownerAddress = this.walletAddress,
|
|
7330
|
-
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
7384
|
+
async getLending(poolCoinName, ownerAddress = this.walletAddress, args) {
|
|
7385
|
+
return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
|
|
7331
7386
|
}
|
|
7332
7387
|
/**
|
|
7333
7388
|
* Get user all obligation accounts information.
|
|
@@ -7339,8 +7394,8 @@ var ScallopQuery = class {
|
|
|
7339
7394
|
* @param indexer - Whether to use indexer.
|
|
7340
7395
|
* @return All obligation accounts information.
|
|
7341
7396
|
*/
|
|
7342
|
-
async getObligationAccounts(ownerAddress = this.walletAddress,
|
|
7343
|
-
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
7397
|
+
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
7398
|
+
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
7344
7399
|
}
|
|
7345
7400
|
/**
|
|
7346
7401
|
* Get obligation account information for specific id.
|
|
@@ -7353,12 +7408,12 @@ var ScallopQuery = class {
|
|
|
7353
7408
|
* @param indexer - Whether to use indexer.
|
|
7354
7409
|
* @return Borrowing and collateral information.
|
|
7355
7410
|
*/
|
|
7356
|
-
async getObligationAccount(obligationId, ownerAddress = this.walletAddress,
|
|
7411
|
+
async getObligationAccount(obligationId, ownerAddress = this.walletAddress, args) {
|
|
7357
7412
|
return await getObligationAccount(
|
|
7358
7413
|
this,
|
|
7359
7414
|
obligationId,
|
|
7360
7415
|
ownerAddress,
|
|
7361
|
-
indexer
|
|
7416
|
+
args?.indexer
|
|
7362
7417
|
);
|
|
7363
7418
|
}
|
|
7364
7419
|
/**
|
|
@@ -7370,8 +7425,8 @@ var ScallopQuery = class {
|
|
|
7370
7425
|
*
|
|
7371
7426
|
* @return Total value locked.
|
|
7372
7427
|
*/
|
|
7373
|
-
async getTvl(
|
|
7374
|
-
return await getTotalValueLocked(this, indexer);
|
|
7428
|
+
async getTvl(args) {
|
|
7429
|
+
return await getTotalValueLocked(this, args?.indexer);
|
|
7375
7430
|
}
|
|
7376
7431
|
/**
|
|
7377
7432
|
* Get veSca data.
|
|
@@ -7509,6 +7564,13 @@ var ScallopQuery = class {
|
|
|
7509
7564
|
async getCoinPriceByIndexer(poolName) {
|
|
7510
7565
|
return this.indexer.getCoinPrice(poolName);
|
|
7511
7566
|
}
|
|
7567
|
+
/**
|
|
7568
|
+
* Get all coin prices, including sCoin
|
|
7569
|
+
* @returns prices data
|
|
7570
|
+
*/
|
|
7571
|
+
async getAllCoinPrices(args) {
|
|
7572
|
+
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
7573
|
+
}
|
|
7512
7574
|
};
|
|
7513
7575
|
|
|
7514
7576
|
// src/models/scallopBuilder.ts
|
|
@@ -8158,30 +8220,46 @@ var ScallopClient = class {
|
|
|
8158
8220
|
}
|
|
8159
8221
|
}
|
|
8160
8222
|
/**
|
|
8161
|
-
*
|
|
8223
|
+
* Claim borrow incentive reward.
|
|
8162
8224
|
*
|
|
8163
|
-
* @param
|
|
8225
|
+
* @param poolName
|
|
8164
8226
|
* @param amount - The amount of coins would deposit.
|
|
8165
8227
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
8166
8228
|
* @param accountId - The stake account object.
|
|
8167
8229
|
* @param walletAddress - The wallet address of the owner.
|
|
8168
8230
|
* @return Transaction block response or transaction block
|
|
8169
8231
|
*/
|
|
8170
|
-
async claimBorrowIncentive(
|
|
8232
|
+
async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8171
8233
|
const txBlock = this.builder.createTxBlock();
|
|
8172
8234
|
const sender = walletAddress ?? this.walletAddress;
|
|
8173
8235
|
txBlock.setSender(sender);
|
|
8174
|
-
const
|
|
8175
|
-
|
|
8236
|
+
const rewardCoinsCollection = {};
|
|
8237
|
+
const obligationAccount = await this.query.getObligationAccount(obligationId);
|
|
8238
|
+
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
|
|
8239
|
+
({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
8240
|
+
).flatMap(({ coinName }) => coinName);
|
|
8241
|
+
for (const rewardCoinName of rewardCoinNames) {
|
|
8176
8242
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
8177
|
-
coinName,
|
|
8178
8243
|
rewardCoinName,
|
|
8179
8244
|
obligationId,
|
|
8180
8245
|
obligationKeyId
|
|
8181
8246
|
);
|
|
8182
|
-
|
|
8247
|
+
if (!rewardCoinsCollection[rewardCoinName]) {
|
|
8248
|
+
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
8249
|
+
} else {
|
|
8250
|
+
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
8251
|
+
}
|
|
8183
8252
|
}
|
|
8184
|
-
txBlock.transferObjects(
|
|
8253
|
+
txBlock.transferObjects(
|
|
8254
|
+
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
8255
|
+
const mergeDest = rewardCoins[0];
|
|
8256
|
+
if (rewardCoins.length > 1) {
|
|
8257
|
+
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
8258
|
+
}
|
|
8259
|
+
return mergeDest;
|
|
8260
|
+
}),
|
|
8261
|
+
sender
|
|
8262
|
+
);
|
|
8185
8263
|
if (sign) {
|
|
8186
8264
|
return await this.suiKit.signAndSendTxn(
|
|
8187
8265
|
txBlock
|
|
@@ -8490,12 +8568,12 @@ export {
|
|
|
8490
8568
|
UNLOCK_ROUND_DURATION,
|
|
8491
8569
|
USE_TEST_ADDRESS,
|
|
8492
8570
|
assetCoins,
|
|
8493
|
-
borrowIncentiveRewardCoins,
|
|
8494
8571
|
coinDecimals,
|
|
8495
8572
|
coinIds,
|
|
8496
8573
|
marketCoins,
|
|
8497
8574
|
queryKeys,
|
|
8498
8575
|
sCoinIds,
|
|
8576
|
+
sCoinRawNameToName,
|
|
8499
8577
|
sCoinTypeToName,
|
|
8500
8578
|
sCoins,
|
|
8501
8579
|
spoolRewardCoins,
|