@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.js
CHANGED
|
@@ -74,12 +74,12 @@ __export(src_exports, {
|
|
|
74
74
|
UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
|
|
75
75
|
USE_TEST_ADDRESS: () => USE_TEST_ADDRESS,
|
|
76
76
|
assetCoins: () => assetCoins,
|
|
77
|
-
borrowIncentiveRewardCoins: () => borrowIncentiveRewardCoins,
|
|
78
77
|
coinDecimals: () => coinDecimals,
|
|
79
78
|
coinIds: () => coinIds,
|
|
80
79
|
marketCoins: () => marketCoins,
|
|
81
80
|
queryKeys: () => queryKeys,
|
|
82
81
|
sCoinIds: () => sCoinIds,
|
|
82
|
+
sCoinRawNameToName: () => sCoinRawNameToName,
|
|
83
83
|
sCoinTypeToName: () => sCoinTypeToName,
|
|
84
84
|
sCoins: () => sCoins,
|
|
85
85
|
spoolRewardCoins: () => spoolRewardCoins,
|
|
@@ -115,9 +115,10 @@ var COIN_GECKGO_IDS = {
|
|
|
115
115
|
afsui: "sui",
|
|
116
116
|
hasui: "sui",
|
|
117
117
|
vsui: "sui",
|
|
118
|
-
sca: "scallop-2"
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
sca: "scallop-2"
|
|
119
|
+
// TODO: enable for production
|
|
120
|
+
// deep: 'deepbook',
|
|
121
|
+
// fud: 'fud-the-pug',
|
|
121
122
|
};
|
|
122
123
|
|
|
123
124
|
// src/constants/common.ts
|
|
@@ -146,9 +147,10 @@ var SUPPORT_POOLS = [
|
|
|
146
147
|
"afsui",
|
|
147
148
|
"hasui",
|
|
148
149
|
"vsui",
|
|
149
|
-
"sca"
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
"sca"
|
|
151
|
+
// TODO: enable for production
|
|
152
|
+
// 'fud',
|
|
153
|
+
// 'deep',
|
|
152
154
|
];
|
|
153
155
|
var SUPPORT_COLLATERALS = [
|
|
154
156
|
"usdc",
|
|
@@ -192,9 +194,10 @@ var SUPPORT_SCOIN = [
|
|
|
192
194
|
"ssca",
|
|
193
195
|
"scetus",
|
|
194
196
|
"swsol",
|
|
195
|
-
"swbtc"
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
"swbtc"
|
|
198
|
+
// TODO: enable for production
|
|
199
|
+
// 'sdeep',
|
|
200
|
+
// 'sfud',
|
|
198
201
|
];
|
|
199
202
|
var SUPPORT_SUI_BRIDGE = ["sbeth"];
|
|
200
203
|
var SUPPORT_WORMHOLE = [
|
|
@@ -218,7 +221,10 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
|
|
|
218
221
|
"sca",
|
|
219
222
|
"usdc"
|
|
220
223
|
];
|
|
221
|
-
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
224
|
+
var SUPPORT_BORROW_INCENTIVE_REWARDS = [
|
|
225
|
+
...SUPPORT_POOLS,
|
|
226
|
+
...SUPPORT_SCOIN
|
|
227
|
+
];
|
|
222
228
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
223
229
|
var SUPPORT_PACKAGES = [
|
|
224
230
|
"coinDecimalsRegistry",
|
|
@@ -251,8 +257,9 @@ var coinDecimals = {
|
|
|
251
257
|
hasui: 9,
|
|
252
258
|
vsui: 9,
|
|
253
259
|
sca: 9,
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
// TODO: enable for production
|
|
261
|
+
// deep: 6,
|
|
262
|
+
// fud: 5,
|
|
256
263
|
susdc: 6,
|
|
257
264
|
sweth: 8,
|
|
258
265
|
ssbeth: 8,
|
|
@@ -266,9 +273,10 @@ var coinDecimals = {
|
|
|
266
273
|
safsui: 9,
|
|
267
274
|
shasui: 9,
|
|
268
275
|
svsui: 9,
|
|
269
|
-
ssca: 9
|
|
270
|
-
|
|
271
|
-
|
|
276
|
+
ssca: 9
|
|
277
|
+
// TODO: enable for production
|
|
278
|
+
// sdeep: 6,
|
|
279
|
+
// sfud: 5,
|
|
272
280
|
};
|
|
273
281
|
var assetCoins = {
|
|
274
282
|
usdc: "usdc",
|
|
@@ -284,9 +292,10 @@ var assetCoins = {
|
|
|
284
292
|
afsui: "afsui",
|
|
285
293
|
hasui: "hasui",
|
|
286
294
|
vsui: "vsui",
|
|
287
|
-
sca: "sca"
|
|
288
|
-
|
|
289
|
-
|
|
295
|
+
sca: "sca"
|
|
296
|
+
// TODO: enable for production
|
|
297
|
+
// deep: 'deep',
|
|
298
|
+
// fud: 'fud',
|
|
290
299
|
};
|
|
291
300
|
var marketCoins = {
|
|
292
301
|
susdc: "susdc",
|
|
@@ -302,9 +311,10 @@ var marketCoins = {
|
|
|
302
311
|
safsui: "safsui",
|
|
303
312
|
shasui: "shasui",
|
|
304
313
|
svsui: "svsui",
|
|
305
|
-
ssca: "ssca"
|
|
306
|
-
|
|
307
|
-
|
|
314
|
+
ssca: "ssca"
|
|
315
|
+
// TODO: enable for production
|
|
316
|
+
// sdeep: 'sdeep',
|
|
317
|
+
// sfud: 'sfud',
|
|
308
318
|
};
|
|
309
319
|
var sCoins = {
|
|
310
320
|
susdc: "susdc",
|
|
@@ -319,9 +329,10 @@ var sCoins = {
|
|
|
319
329
|
svsui: "svsui",
|
|
320
330
|
ssca: "ssca",
|
|
321
331
|
swsol: "swsol",
|
|
322
|
-
swbtc: "swbtc"
|
|
323
|
-
|
|
324
|
-
|
|
332
|
+
swbtc: "swbtc"
|
|
333
|
+
// TODO: enable for production
|
|
334
|
+
// sfud: 'sfud',
|
|
335
|
+
// sdeep: 'sdeep',
|
|
325
336
|
};
|
|
326
337
|
var stakeMarketCoins = {
|
|
327
338
|
susdc: "susdc",
|
|
@@ -348,18 +359,6 @@ var spoolRewardCoins = {
|
|
|
348
359
|
var suiBridgeCoins = {
|
|
349
360
|
sbeth: "sbeth"
|
|
350
361
|
};
|
|
351
|
-
var borrowIncentiveRewardCoins = {
|
|
352
|
-
usdc: ["sui", "sca"],
|
|
353
|
-
sui: ["sui", "sca"],
|
|
354
|
-
wusdc: ["sui", "sca"],
|
|
355
|
-
wusdt: ["sui", "sca"],
|
|
356
|
-
sca: ["sui", "sca"],
|
|
357
|
-
afsui: ["sui"],
|
|
358
|
-
hasui: ["sui"],
|
|
359
|
-
vsui: ["sui"],
|
|
360
|
-
weth: ["sui"],
|
|
361
|
-
sbeth: ["sui"]
|
|
362
|
-
};
|
|
363
362
|
var coinIds = {
|
|
364
363
|
usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
|
|
365
364
|
sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
@@ -374,10 +373,10 @@ var coinIds = {
|
|
|
374
373
|
afsui: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
375
374
|
hasui: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
376
375
|
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
377
|
-
sca: IS_VE_SCA_TEST ? "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524" : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"
|
|
376
|
+
sca: IS_VE_SCA_TEST ? "0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524" : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"
|
|
378
377
|
// isolated assets
|
|
379
|
-
deep:
|
|
380
|
-
fud:
|
|
378
|
+
// deep: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
|
|
379
|
+
// fud: '0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1',
|
|
381
380
|
};
|
|
382
381
|
var wormholeCoinIds = {
|
|
383
382
|
weth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
@@ -393,19 +392,28 @@ var voloCoinIds = {
|
|
|
393
392
|
var sCoinIds = {
|
|
394
393
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
395
394
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
396
|
-
|
|
395
|
+
// prod values
|
|
396
|
+
// ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
397
|
+
// swusdc:
|
|
398
|
+
// '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
399
|
+
// swusdt:
|
|
400
|
+
// '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
401
|
+
// ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
402
|
+
// test values
|
|
403
|
+
ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
|
|
404
|
+
swusdt: "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
405
|
+
swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
406
|
+
ssca: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
|
|
397
407
|
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
398
|
-
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
399
|
-
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
400
|
-
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
401
408
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
402
409
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
403
410
|
shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
404
411
|
svsui: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI",
|
|
405
412
|
swsol: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
|
|
406
|
-
swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
|
|
407
|
-
sdeep:
|
|
408
|
-
|
|
413
|
+
swbtc: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC"
|
|
414
|
+
// sdeep:
|
|
415
|
+
// '0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP',
|
|
416
|
+
// sfud: '0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD',
|
|
409
417
|
};
|
|
410
418
|
var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
411
419
|
(acc, [coinName, coinType]) => {
|
|
@@ -414,6 +422,13 @@ var sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
414
422
|
},
|
|
415
423
|
{}
|
|
416
424
|
);
|
|
425
|
+
var sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
426
|
+
(acc, [coinName, coinType]) => {
|
|
427
|
+
acc[coinType.split("::")[2].toLowerCase()] = coinName;
|
|
428
|
+
return acc;
|
|
429
|
+
},
|
|
430
|
+
{}
|
|
431
|
+
);
|
|
417
432
|
|
|
418
433
|
// src/constants/flashloan.ts
|
|
419
434
|
var FlashLoanFeeObjectMap = {
|
|
@@ -488,13 +503,16 @@ var POOL_ADDRESSES = {
|
|
|
488
503
|
sca: {
|
|
489
504
|
lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
|
|
490
505
|
collateralPoolAddress: "0xff677a5d9e9dc8f08f0a8681ebfc7481d1c7d57bc441f2881974adcdd7b13c31"
|
|
491
|
-
},
|
|
492
|
-
fud: {
|
|
493
|
-
lendingPoolAddress: "0x14367ddca30e2860cb89ed4eaca20c7ece260c5d59dd9990d2c85a8321326acb"
|
|
494
|
-
},
|
|
495
|
-
deep: {
|
|
496
|
-
lendingPoolAddress: "0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03"
|
|
497
506
|
}
|
|
507
|
+
// TODO: enable for production
|
|
508
|
+
// fud: {
|
|
509
|
+
// lendingPoolAddress:
|
|
510
|
+
// '0x14367ddca30e2860cb89ed4eaca20c7ece260c5d59dd9990d2c85a8321326acb',
|
|
511
|
+
// },
|
|
512
|
+
// deep: {
|
|
513
|
+
// lendingPoolAddress:
|
|
514
|
+
// '0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03',
|
|
515
|
+
// },
|
|
498
516
|
};
|
|
499
517
|
|
|
500
518
|
// src/constants/pyth.ts
|
|
@@ -516,9 +534,10 @@ var PYTH_FEED_IDS = {
|
|
|
516
534
|
afsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
517
535
|
hasui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
518
536
|
vsui: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
519
|
-
sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
|
|
520
|
-
|
|
521
|
-
|
|
537
|
+
sca: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc"
|
|
538
|
+
// TODO: enable for production
|
|
539
|
+
// deep: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
|
|
540
|
+
// fud: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
|
|
522
541
|
};
|
|
523
542
|
|
|
524
543
|
// src/constants/queryKeys.ts
|
|
@@ -1044,7 +1063,7 @@ var TEST_ADDRESSES = {
|
|
|
1044
1063
|
|
|
1045
1064
|
// src/constants/tokenBucket.ts
|
|
1046
1065
|
var DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
1047
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
1066
|
+
var DEFAULT_INTERVAL_IN_MS = 100;
|
|
1048
1067
|
|
|
1049
1068
|
// src/constants/vesca.ts
|
|
1050
1069
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1645,7 +1664,7 @@ var TokenBucket = class {
|
|
|
1645
1664
|
return false;
|
|
1646
1665
|
}
|
|
1647
1666
|
};
|
|
1648
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries =
|
|
1667
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 2) => {
|
|
1649
1668
|
let retries = 0;
|
|
1650
1669
|
const tryRequest = async () => {
|
|
1651
1670
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1681,13 +1700,19 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1681
1700
|
|
|
1682
1701
|
// src/utils/indexer.ts
|
|
1683
1702
|
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1684
|
-
const
|
|
1685
|
-
if (indexer) {
|
|
1703
|
+
const lastArgs = args[args.length - 1];
|
|
1704
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1686
1705
|
try {
|
|
1687
1706
|
return await method.apply(context, args);
|
|
1688
1707
|
} catch (e) {
|
|
1689
1708
|
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1690
|
-
return await method.apply(context, [
|
|
1709
|
+
return await method.apply(context, [
|
|
1710
|
+
...args.slice(0, -1),
|
|
1711
|
+
{
|
|
1712
|
+
...lastArgs,
|
|
1713
|
+
indexer: false
|
|
1714
|
+
}
|
|
1715
|
+
]);
|
|
1691
1716
|
}
|
|
1692
1717
|
}
|
|
1693
1718
|
return await method.apply(context, args);
|
|
@@ -2555,15 +2580,21 @@ var queryBorrowIncentivePools = async (address) => {
|
|
|
2555
2580
|
};
|
|
2556
2581
|
var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
2557
2582
|
...SUPPORT_BORROW_INCENTIVE_POOLS
|
|
2558
|
-
], indexer = false, coinPrices) => {
|
|
2583
|
+
], indexer = false, marketPools, coinPrices) => {
|
|
2559
2584
|
const borrowIncentivePools = {};
|
|
2560
|
-
|
|
2585
|
+
marketPools = marketPools ?? await query.getMarketPools(void 0, { indexer, coinPrices });
|
|
2586
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools });
|
|
2561
2587
|
if (indexer) {
|
|
2562
2588
|
const borrowIncentivePoolsIndexer = await query.indexer.getBorrowIncentivePools();
|
|
2563
2589
|
const updateBorrowIncentivePool = (pool) => {
|
|
2564
2590
|
if (!borrowIncentiveCoinNames.includes(pool.coinName))
|
|
2565
2591
|
return;
|
|
2566
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
2592
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
2593
|
+
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
2594
|
+
if (pool.points[sCoinName]) {
|
|
2595
|
+
pool.points[sCoinName].coinPrice = coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2567
2598
|
borrowIncentivePools[pool.coinName] = pool;
|
|
2568
2599
|
};
|
|
2569
2600
|
Object.values(borrowIncentivePoolsIndexer).forEach(
|
|
@@ -2589,12 +2620,15 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2589
2620
|
for (const [coinName, poolPoint] of Object.entries(
|
|
2590
2621
|
parsedBorrowIncentivePoolData.poolPoints
|
|
2591
2622
|
)) {
|
|
2592
|
-
const rewardCoinType =
|
|
2593
|
-
|
|
2623
|
+
const rewardCoinType = poolPoint.pointType;
|
|
2624
|
+
let rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2594
2625
|
rewardCoinType
|
|
2595
2626
|
);
|
|
2596
|
-
|
|
2627
|
+
if (sCoinRawNameToName[rewardCoinName]) {
|
|
2628
|
+
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
2629
|
+
}
|
|
2597
2630
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2631
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2598
2632
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
2599
2633
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2600
2634
|
const calculatedPoolPoint = calculateBorrowIncentivePoolPointData(
|
|
@@ -2740,7 +2774,7 @@ var supplyLimitZod = import_zod.z.object({
|
|
|
2740
2774
|
value: import_zod.z.string()
|
|
2741
2775
|
})
|
|
2742
2776
|
});
|
|
2743
|
-
var supplyLimitKeyType = `
|
|
2777
|
+
var supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
|
|
2744
2778
|
var getSupplyLimit = async (utils, poolName) => {
|
|
2745
2779
|
try {
|
|
2746
2780
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
@@ -2780,7 +2814,7 @@ var isolatedAssetZod = import_zod2.z.object({
|
|
|
2780
2814
|
value: import_zod2.z.boolean()
|
|
2781
2815
|
})
|
|
2782
2816
|
});
|
|
2783
|
-
var isolatedAssetKeyType = `
|
|
2817
|
+
var isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
|
|
2784
2818
|
var getIsolatedAssets = async (address) => {
|
|
2785
2819
|
try {
|
|
2786
2820
|
const marketObject = address.get("core.market");
|
|
@@ -2860,7 +2894,7 @@ var borrowLimitZod = import_zod3.z.object({
|
|
|
2860
2894
|
value: import_zod3.z.string()
|
|
2861
2895
|
})
|
|
2862
2896
|
});
|
|
2863
|
-
var borrowLimitKeyType = `
|
|
2897
|
+
var borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
|
|
2864
2898
|
var getBorrowLimit = async (utils, poolName) => {
|
|
2865
2899
|
try {
|
|
2866
2900
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
@@ -3027,7 +3061,7 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
3027
3061
|
const marketObjectResponse = await query.cache.queryGetObject(marketId, {
|
|
3028
3062
|
showContent: true
|
|
3029
3063
|
});
|
|
3030
|
-
coinPrices = await query.utils.getCoinPrices(
|
|
3064
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
3031
3065
|
const marketPools = {};
|
|
3032
3066
|
if (indexer) {
|
|
3033
3067
|
const marketPoolsIndexer = await query.indexer.getMarketPools();
|
|
@@ -3060,154 +3094,150 @@ var getMarketPools = async (query, poolCoinNames = [...SUPPORT_POOLS], indexer =
|
|
|
3060
3094
|
return marketPools;
|
|
3061
3095
|
};
|
|
3062
3096
|
var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3097
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName];
|
|
3098
|
+
if (indexer) {
|
|
3099
|
+
const marketPoolIndexer = await query.indexer.getMarketPool(poolCoinName);
|
|
3100
|
+
if (!marketPoolIndexer) {
|
|
3101
|
+
return void 0;
|
|
3102
|
+
}
|
|
3103
|
+
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
3104
|
+
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
3105
|
+
marketPoolIndexer.coinName
|
|
3106
|
+
);
|
|
3107
|
+
return marketPoolIndexer;
|
|
3108
|
+
}
|
|
3109
|
+
const marketId = query.address.get("core.market");
|
|
3110
|
+
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
3111
|
+
showContent: true
|
|
3112
|
+
}))?.data;
|
|
3113
|
+
if (!(marketObject && marketObject.content?.dataType === "moveObject"))
|
|
3114
|
+
throw new Error(`Failed to fetch marketObject`);
|
|
3115
|
+
const fields = marketObject.content.fields;
|
|
3116
|
+
const coinType = query.utils.parseCoinType(poolCoinName);
|
|
3117
|
+
const balanceSheetParentId = fields.vault.fields.balance_sheets.fields.table.fields.id.id;
|
|
3118
|
+
const balanceSheetDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3119
|
+
parentId: balanceSheetParentId,
|
|
3120
|
+
name: {
|
|
3121
|
+
type: "0x1::type_name::TypeName",
|
|
3122
|
+
value: {
|
|
3123
|
+
name: coinType.substring(2)
|
|
3069
3124
|
}
|
|
3070
|
-
marketPoolIndexer.coinPrice = coinPrice ?? marketPoolIndexer.coinPrice;
|
|
3071
|
-
marketPoolIndexer.coinWrappedType = query.utils.getCoinWrappedType(
|
|
3072
|
-
marketPoolIndexer.coinName
|
|
3073
|
-
);
|
|
3074
|
-
return marketPoolIndexer;
|
|
3075
3125
|
}
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
name: coinType.substring(2)
|
|
3091
|
-
}
|
|
3126
|
+
});
|
|
3127
|
+
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse?.data;
|
|
3128
|
+
if (!(balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content))
|
|
3129
|
+
throw new Error(
|
|
3130
|
+
`Failed to fetch balanceSheetDynamicFieldObject for ${poolCoinName}: ${balanceSheetDynamicFieldObjectResponse?.error?.code.toString()}`
|
|
3131
|
+
);
|
|
3132
|
+
const balanceSheet = balanceSheetDynamicFieldObject.content.fields.value.fields;
|
|
3133
|
+
const borrowIndexParentId = fields.borrow_dynamics.fields.table.fields.id.id;
|
|
3134
|
+
const borrowIndexDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3135
|
+
parentId: borrowIndexParentId,
|
|
3136
|
+
name: {
|
|
3137
|
+
type: "0x1::type_name::TypeName",
|
|
3138
|
+
value: {
|
|
3139
|
+
name: coinType.substring(2)
|
|
3092
3140
|
}
|
|
3093
|
-
}
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3141
|
+
}
|
|
3142
|
+
});
|
|
3143
|
+
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse?.data;
|
|
3144
|
+
if (!(borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content))
|
|
3145
|
+
throw new Error(
|
|
3146
|
+
`Failed to fetch borrowIndexDynamicFieldObject for ${poolCoinName}`
|
|
3147
|
+
);
|
|
3148
|
+
const borrowIndex = borrowIndexDynamicFieldObject.content.fields.value.fields;
|
|
3149
|
+
const interestModelParentId = fields.interest_models.fields.table.fields.id.id;
|
|
3150
|
+
const interestModelDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3151
|
+
parentId: interestModelParentId,
|
|
3152
|
+
name: {
|
|
3153
|
+
type: "0x1::type_name::TypeName",
|
|
3154
|
+
value: {
|
|
3155
|
+
name: coinType.substring(2)
|
|
3108
3156
|
}
|
|
3109
|
-
}
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3157
|
+
}
|
|
3158
|
+
});
|
|
3159
|
+
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3160
|
+
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3161
|
+
throw new Error(
|
|
3162
|
+
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3163
|
+
);
|
|
3164
|
+
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3165
|
+
const getBorrowFee = async () => {
|
|
3166
|
+
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3167
|
+
parentId: marketId,
|
|
3119
3168
|
name: {
|
|
3120
|
-
type:
|
|
3169
|
+
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3121
3170
|
value: {
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
}
|
|
3125
|
-
});
|
|
3126
|
-
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse?.data;
|
|
3127
|
-
if (!(interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content))
|
|
3128
|
-
throw new Error(
|
|
3129
|
-
`Failed to fetch interestModelDynamicFieldObject for ${poolCoinName}: ${interestModelDynamicFieldObject}`
|
|
3130
|
-
);
|
|
3131
|
-
const interestModel = interestModelDynamicFieldObject.content.fields.value.fields;
|
|
3132
|
-
const getBorrowFee = async () => {
|
|
3133
|
-
const borrowFeeDynamicFieldObjectResponse = await query.cache.queryGetDynamicFieldObject({
|
|
3134
|
-
parentId: marketId,
|
|
3135
|
-
name: {
|
|
3136
|
-
type: `${BORROW_FEE_PROTOCOL_ID}::market_dynamic_keys::BorrowFeeKey`,
|
|
3137
|
-
value: {
|
|
3138
|
-
type: {
|
|
3139
|
-
name: coinType.substring(2)
|
|
3140
|
-
}
|
|
3171
|
+
type: {
|
|
3172
|
+
name: coinType.substring(2)
|
|
3141
3173
|
}
|
|
3142
3174
|
}
|
|
3143
|
-
}
|
|
3144
|
-
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3145
|
-
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3146
|
-
return { value: "0" };
|
|
3147
|
-
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3148
|
-
};
|
|
3149
|
-
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3150
|
-
type: interestModel.type.fields,
|
|
3151
|
-
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3152
|
-
interestRate: borrowIndex.interest_rate.fields,
|
|
3153
|
-
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3154
|
-
borrowIndex: borrowIndex.borrow_index,
|
|
3155
|
-
lastUpdated: borrowIndex.last_updated,
|
|
3156
|
-
cash: balanceSheet.cash,
|
|
3157
|
-
debt: balanceSheet.debt,
|
|
3158
|
-
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3159
|
-
reserve: balanceSheet.revenue,
|
|
3160
|
-
reserveFactor: interestModel.revenue_factor.fields,
|
|
3161
|
-
borrowWeight: interestModel.borrow_weight.fields,
|
|
3162
|
-
borrowFeeRate: await getBorrowFee(),
|
|
3163
|
-
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3164
|
-
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3165
|
-
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3166
|
-
highKink: interestModel.high_kink.fields,
|
|
3167
|
-
midKink: interestModel.mid_kink.fields,
|
|
3168
|
-
minBorrowAmount: interestModel.min_borrow_amount
|
|
3175
|
+
}
|
|
3169
3176
|
});
|
|
3170
|
-
const
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3177
|
+
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse?.data;
|
|
3178
|
+
if (!(borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content))
|
|
3179
|
+
return { value: "0" };
|
|
3180
|
+
return borrowFeeDynamicFieldObject.content.fields.value.fields;
|
|
3181
|
+
};
|
|
3182
|
+
const parsedMarketPoolData = parseOriginMarketPoolData({
|
|
3183
|
+
type: interestModel.type.fields,
|
|
3184
|
+
maxBorrowRate: interestModel.max_borrow_rate.fields,
|
|
3185
|
+
interestRate: borrowIndex.interest_rate.fields,
|
|
3186
|
+
interestRateScale: borrowIndex.interest_rate_scale,
|
|
3187
|
+
borrowIndex: borrowIndex.borrow_index,
|
|
3188
|
+
lastUpdated: borrowIndex.last_updated,
|
|
3189
|
+
cash: balanceSheet.cash,
|
|
3190
|
+
debt: balanceSheet.debt,
|
|
3191
|
+
marketCoinSupply: balanceSheet.market_coin_supply,
|
|
3192
|
+
reserve: balanceSheet.revenue,
|
|
3193
|
+
reserveFactor: interestModel.revenue_factor.fields,
|
|
3194
|
+
borrowWeight: interestModel.borrow_weight.fields,
|
|
3195
|
+
borrowFeeRate: await getBorrowFee(),
|
|
3196
|
+
baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
|
|
3197
|
+
borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
|
|
3198
|
+
borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
|
|
3199
|
+
highKink: interestModel.high_kink.fields,
|
|
3200
|
+
midKink: interestModel.mid_kink.fields,
|
|
3201
|
+
minBorrowAmount: interestModel.min_borrow_amount
|
|
3202
|
+
});
|
|
3203
|
+
const calculatedMarketPoolData = calculateMarketPoolData(
|
|
3204
|
+
query.utils,
|
|
3205
|
+
parsedMarketPoolData
|
|
3206
|
+
);
|
|
3207
|
+
const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
3208
|
+
const maxSupplyCoin = (0, import_bignumber3.default)(
|
|
3209
|
+
await getSupplyLimit(query.utils, poolCoinName) ?? "0"
|
|
3210
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3211
|
+
const maxBorrowCoin = (0, import_bignumber3.default)(
|
|
3212
|
+
await getBorrowLimit(query.utils, poolCoinName) ?? "0"
|
|
3213
|
+
).shiftedBy(-coinDecimal).toNumber();
|
|
3214
|
+
return {
|
|
3215
|
+
coinName: poolCoinName,
|
|
3216
|
+
symbol: query.utils.parseSymbol(poolCoinName),
|
|
3217
|
+
coinType: query.utils.parseCoinType(poolCoinName),
|
|
3218
|
+
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
3219
|
+
sCoinType: query.utils.parseSCoinType(
|
|
3220
|
+
query.utils.parseMarketCoinName(poolCoinName)
|
|
3221
|
+
),
|
|
3222
|
+
coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
|
|
3223
|
+
coinDecimal,
|
|
3224
|
+
coinPrice: coinPrice ?? 0,
|
|
3225
|
+
highKink: parsedMarketPoolData.highKink,
|
|
3226
|
+
midKink: parsedMarketPoolData.midKink,
|
|
3227
|
+
reserveFactor: parsedMarketPoolData.reserveFactor,
|
|
3228
|
+
borrowWeight: parsedMarketPoolData.borrowWeight,
|
|
3229
|
+
borrowFee: parsedMarketPoolData.borrowFee,
|
|
3230
|
+
marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
|
|
3231
|
+
minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
|
|
3232
|
+
maxSupplyCoin,
|
|
3233
|
+
maxBorrowCoin,
|
|
3234
|
+
isIsolated: await isIsolatedAsset(query.utils, poolCoinName),
|
|
3235
|
+
...calculatedMarketPoolData
|
|
3236
|
+
};
|
|
3207
3237
|
};
|
|
3208
3238
|
var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLATERALS], indexer = false) => {
|
|
3209
3239
|
const marketId = query.address.get("core.market");
|
|
3210
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
3240
|
+
const coinPrices = await query.utils.getCoinPrices() ?? {};
|
|
3211
3241
|
const marketCollaterals = {};
|
|
3212
3242
|
if (indexer) {
|
|
3213
3243
|
const marketCollateralsIndexer = await query.indexer.getMarketCollaterals();
|
|
@@ -3243,7 +3273,7 @@ var getMarketCollaterals = async (query, collateralCoinNames = [...SUPPORT_COLLA
|
|
|
3243
3273
|
return marketCollaterals;
|
|
3244
3274
|
};
|
|
3245
3275
|
var getMarketCollateral = async (query, collateralCoinName, indexer = false, marketObject, coinPrice) => {
|
|
3246
|
-
coinPrice = coinPrice
|
|
3276
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[collateralCoinName];
|
|
3247
3277
|
if (indexer) {
|
|
3248
3278
|
const marketCollateralIndexer = await query.indexer.getMarketCollateral(collateralCoinName);
|
|
3249
3279
|
marketCollateralIndexer.coinPrice = coinPrice ?? marketCollateralIndexer.coinPrice;
|
|
@@ -3559,11 +3589,13 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3559
3589
|
const stakeMarketCoinNames = marketCoinNames.filter(
|
|
3560
3590
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
3561
3591
|
);
|
|
3562
|
-
const coinPrices = await query.utils.getCoinPrices(
|
|
3563
|
-
const marketPools = await query.getMarketPools(poolCoinNames,
|
|
3592
|
+
const coinPrices = await query.utils.getCoinPrices();
|
|
3593
|
+
const marketPools = await query.getMarketPools(poolCoinNames, {
|
|
3594
|
+
indexer,
|
|
3564
3595
|
coinPrices
|
|
3565
3596
|
});
|
|
3566
|
-
const spools = await query.getSpools(stakeMarketCoinNames,
|
|
3597
|
+
const spools = await query.getSpools(stakeMarketCoinNames, {
|
|
3598
|
+
indexer,
|
|
3567
3599
|
marketPools,
|
|
3568
3600
|
coinPrices
|
|
3569
3601
|
});
|
|
@@ -3597,22 +3629,20 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
3597
3629
|
};
|
|
3598
3630
|
var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
|
|
3599
3631
|
const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
|
|
3600
|
-
coinPrice = coinPrice ?? (await query.utils.getCoinPrices(
|
|
3601
|
-
marketPool = marketPool ?? await query.getMarketPool(poolCoinName,
|
|
3632
|
+
coinPrice = coinPrice ?? (await query.utils.getCoinPrices())?.[poolCoinName] ?? 0;
|
|
3633
|
+
marketPool = marketPool ?? await query.getMarketPool(poolCoinName, {
|
|
3634
|
+
indexer,
|
|
3602
3635
|
coinPrice
|
|
3603
3636
|
});
|
|
3604
3637
|
if (!marketPool)
|
|
3605
3638
|
throw new Error(`Failed to fetch marketPool for ${poolCoinName}`);
|
|
3606
|
-
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(
|
|
3607
|
-
marketCoinName,
|
|
3639
|
+
spool = spool ?? SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, {
|
|
3608
3640
|
indexer,
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
[poolCoinName]: coinPrice
|
|
3613
|
-
}
|
|
3641
|
+
marketPool,
|
|
3642
|
+
coinPrices: {
|
|
3643
|
+
[poolCoinName]: coinPrice
|
|
3614
3644
|
}
|
|
3615
|
-
) : void 0;
|
|
3645
|
+
}) : void 0;
|
|
3616
3646
|
stakeAccounts = stakeAccounts || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getStakeAccounts(
|
|
3617
3647
|
marketCoinName,
|
|
3618
3648
|
ownerAddress
|
|
@@ -3732,7 +3762,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
3732
3762
|
};
|
|
3733
3763
|
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
3734
3764
|
const coinPrices = await query.utils.getCoinPrices();
|
|
3735
|
-
const market = await query.queryMarket(indexer,
|
|
3765
|
+
const market = await query.queryMarket({ indexer, coinPrices });
|
|
3736
3766
|
const [coinAmounts, obligations] = await Promise.all([
|
|
3737
3767
|
query.getCoinAmounts(void 0, ownerAddress),
|
|
3738
3768
|
query.getObligations(ownerAddress)
|
|
@@ -3757,13 +3787,14 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3757
3787
|
const collateralAssetCoinNames = [
|
|
3758
3788
|
...SUPPORT_COLLATERALS
|
|
3759
3789
|
];
|
|
3760
|
-
|
|
3761
|
-
|
|
3790
|
+
market = market ?? await query.queryMarket({ indexer });
|
|
3791
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
|
|
3762
3792
|
coinAmounts = coinAmounts || await query.getCoinAmounts(collateralAssetCoinNames, ownerAddress);
|
|
3763
3793
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3764
3794
|
query.queryObligation(obligationId),
|
|
3765
|
-
query.getBorrowIncentivePools(void 0,
|
|
3766
|
-
coinPrices
|
|
3795
|
+
query.getBorrowIncentivePools(void 0, {
|
|
3796
|
+
coinPrices,
|
|
3797
|
+
indexer
|
|
3767
3798
|
}),
|
|
3768
3799
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3769
3800
|
]);
|
|
@@ -3899,44 +3930,47 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3899
3930
|
const borrowIncentivePool = borrowIncentivePools[coinName];
|
|
3900
3931
|
if (borrowIncentivePool) {
|
|
3901
3932
|
const rewards = [];
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
(0, import_bignumber5.default)(
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3933
|
+
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
3934
|
+
([key, accountPoint]) => {
|
|
3935
|
+
const poolPoint = borrowIncentivePool.points[key];
|
|
3936
|
+
if (accountPoint && poolPoint) {
|
|
3937
|
+
let availableClaimAmount = (0, import_bignumber5.default)(0);
|
|
3938
|
+
let availableClaimCoin = (0, import_bignumber5.default)(0);
|
|
3939
|
+
const accountBorrowedAmount = (0, import_bignumber5.default)(
|
|
3940
|
+
accountPoint.weightedAmount
|
|
3941
|
+
);
|
|
3942
|
+
const baseIndexRate = 1e9;
|
|
3943
|
+
const increasedPointRate = poolPoint.currentPointIndex ? Math.max(
|
|
3944
|
+
(0, import_bignumber5.default)(poolPoint.currentPointIndex - accountPoint.index).dividedBy(baseIndexRate).toNumber(),
|
|
3945
|
+
0
|
|
3946
|
+
) : 1;
|
|
3947
|
+
availableClaimAmount = availableClaimAmount.plus(
|
|
3948
|
+
accountBorrowedAmount.multipliedBy(increasedPointRate).plus(accountPoint.points)
|
|
3949
|
+
);
|
|
3950
|
+
availableClaimCoin = availableClaimAmount.shiftedBy(
|
|
3951
|
+
-1 * poolPoint.coinDecimal
|
|
3952
|
+
);
|
|
3953
|
+
const weightScale = (0, import_bignumber5.default)(1e12);
|
|
3954
|
+
const boostValue = (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
|
|
3955
|
+
(0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3956
|
+
).isFinite() ? (0, import_bignumber5.default)(accountPoint.weightedAmount).div(
|
|
3957
|
+
(0, import_bignumber5.default)(borrowIncentiveAccount.debtAmount).multipliedBy(poolPoint.baseWeight).dividedBy(weightScale)
|
|
3958
|
+
).toNumber() : 1;
|
|
3959
|
+
if (availableClaimAmount.isGreaterThanOrEqualTo(0)) {
|
|
3960
|
+
rewards.push({
|
|
3961
|
+
coinName: poolPoint.coinName,
|
|
3962
|
+
coinType: poolPoint.coinType,
|
|
3963
|
+
symbol: poolPoint.symbol,
|
|
3964
|
+
coinDecimal: poolPoint.coinDecimal,
|
|
3965
|
+
coinPrice: poolPoint.coinPrice,
|
|
3966
|
+
availableClaimAmount: availableClaimAmount.toNumber(),
|
|
3967
|
+
availableClaimCoin: availableClaimCoin.toNumber(),
|
|
3968
|
+
boostValue
|
|
3969
|
+
});
|
|
3970
|
+
}
|
|
3937
3971
|
}
|
|
3938
3972
|
}
|
|
3939
|
-
|
|
3973
|
+
);
|
|
3940
3974
|
if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
|
|
3941
3975
|
const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
|
|
3942
3976
|
return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
|
|
@@ -4043,7 +4077,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
4043
4077
|
return obligationAccount;
|
|
4044
4078
|
};
|
|
4045
4079
|
var getTotalValueLocked = async (query, indexer = false) => {
|
|
4046
|
-
const market = await query.queryMarket(indexer);
|
|
4080
|
+
const market = await query.queryMarket({ indexer });
|
|
4047
4081
|
let supplyValue = (0, import_bignumber5.default)(0);
|
|
4048
4082
|
let borrowValue = (0, import_bignumber5.default)(0);
|
|
4049
4083
|
if (indexer) {
|
|
@@ -4080,6 +4114,7 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4080
4114
|
};
|
|
4081
4115
|
|
|
4082
4116
|
// src/queries/priceQuery.ts
|
|
4117
|
+
var import_bignumber6 = __toESM(require("bignumber.js"));
|
|
4083
4118
|
var getPythPrice = async ({
|
|
4084
4119
|
address
|
|
4085
4120
|
}, assetCoinName, priceFeedObject) => {
|
|
@@ -4161,6 +4196,22 @@ var getPythPrices = async ({
|
|
|
4161
4196
|
{}
|
|
4162
4197
|
);
|
|
4163
4198
|
};
|
|
4199
|
+
var getAllCoinPrices = async (query, marketPools, coinPrices) => {
|
|
4200
|
+
coinPrices = coinPrices ?? await query.utils.getCoinPrices();
|
|
4201
|
+
marketPools = marketPools ?? await query.getMarketPools(void 0, { coinPrices });
|
|
4202
|
+
if (!marketPools) {
|
|
4203
|
+
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
4204
|
+
}
|
|
4205
|
+
const sCoinPrices = {};
|
|
4206
|
+
SUPPORT_SCOIN.forEach((sCoinName) => {
|
|
4207
|
+
const coinName = query.utils.parseCoinName(sCoinName);
|
|
4208
|
+
sCoinPrices[sCoinName] = (0, import_bignumber6.default)(coinPrices[coinName] ?? 0).multipliedBy(marketPools[coinName]?.conversionRate ?? 1).toNumber();
|
|
4209
|
+
});
|
|
4210
|
+
return {
|
|
4211
|
+
...coinPrices,
|
|
4212
|
+
...sCoinPrices
|
|
4213
|
+
};
|
|
4214
|
+
};
|
|
4164
4215
|
|
|
4165
4216
|
// src/queries/referralQuery.ts
|
|
4166
4217
|
var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
@@ -4181,7 +4232,7 @@ var queryVeScaKeyIdFromReferralBindings = async (address, refereeAddress) => {
|
|
|
4181
4232
|
// src/queries/sCoinQuery.ts
|
|
4182
4233
|
var import_bcs = require("@mysten/sui/bcs");
|
|
4183
4234
|
var import_assert = __toESM(require("assert"));
|
|
4184
|
-
var
|
|
4235
|
+
var import_bignumber7 = __toESM(require("bignumber.js"));
|
|
4185
4236
|
var getSCoinTotalSupply = async ({
|
|
4186
4237
|
utils
|
|
4187
4238
|
}, sCoinName) => {
|
|
@@ -4202,7 +4253,7 @@ var getSCoinTotalSupply = async ({
|
|
|
4202
4253
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4203
4254
|
const type = results[0].returnValues[0][1];
|
|
4204
4255
|
(0, import_assert.default)(type === "u64", "Result type is not u64");
|
|
4205
|
-
return (0,
|
|
4256
|
+
return (0, import_bignumber7.default)(import_bcs.bcs.u64().parse(value)).shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName))).toNumber();
|
|
4206
4257
|
}
|
|
4207
4258
|
return 0;
|
|
4208
4259
|
};
|
|
@@ -4228,7 +4279,7 @@ var getSCoinAmount = async ({
|
|
|
4228
4279
|
owner,
|
|
4229
4280
|
coinType: sCoinType
|
|
4230
4281
|
});
|
|
4231
|
-
return (0,
|
|
4282
|
+
return (0, import_bignumber7.default)(amount).toNumber();
|
|
4232
4283
|
};
|
|
4233
4284
|
var isSupportStakeCoins = (value) => {
|
|
4234
4285
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4247,8 +4298,8 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4247
4298
|
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
4248
4299
|
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
4249
4300
|
const marketPools = await Promise.all([
|
|
4250
|
-
query.getMarketPool(fromCoinName
|
|
4251
|
-
query.getMarketPool(toCoinName
|
|
4301
|
+
query.getMarketPool(fromCoinName),
|
|
4302
|
+
query.getMarketPool(toCoinName)
|
|
4252
4303
|
]);
|
|
4253
4304
|
if (marketPools.some((pool) => !pool))
|
|
4254
4305
|
throw new Error("Failed to fetch the lendings data");
|
|
@@ -4258,7 +4309,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4258
4309
|
const ScoinAToARate = marketPools[0].conversionRate;
|
|
4259
4310
|
const BtoSCoinBRate = 1 / marketPools[1].conversionRate;
|
|
4260
4311
|
const calcAtoBRate = async () => {
|
|
4261
|
-
const prices = await query.utils.getCoinPrices(
|
|
4312
|
+
const prices = await query.utils.getCoinPrices();
|
|
4262
4313
|
if (!prices[fromCoinName] || !prices[toCoinName]) {
|
|
4263
4314
|
throw new Error("Failed to fetch the coin prices");
|
|
4264
4315
|
}
|
|
@@ -4268,7 +4319,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4268
4319
|
return prices[fromCoinName] / prices[toCoinName];
|
|
4269
4320
|
};
|
|
4270
4321
|
const AtoBRate = underlyingCoinPrice ?? await calcAtoBRate();
|
|
4271
|
-
return (0,
|
|
4322
|
+
return (0, import_bignumber7.default)(ScoinAToARate).multipliedBy(AtoBRate).multipliedBy(BtoSCoinBRate).toNumber();
|
|
4272
4323
|
};
|
|
4273
4324
|
|
|
4274
4325
|
// src/queries/spoolQuery.ts
|
|
@@ -4278,7 +4329,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4278
4329
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4279
4330
|
);
|
|
4280
4331
|
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4281
|
-
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, indexer);
|
|
4332
|
+
marketPools = marketPools ?? await query.getMarketPools(stakeCoinNames, { indexer });
|
|
4282
4333
|
if (!marketPools)
|
|
4283
4334
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4284
4335
|
const spools = {};
|
|
@@ -4319,7 +4370,7 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4319
4370
|
};
|
|
4320
4371
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
4321
4372
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4322
|
-
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
4373
|
+
marketPool = marketPool || await query.getMarketPool(coinName, { indexer });
|
|
4323
4374
|
if (!marketPool) {
|
|
4324
4375
|
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
4325
4376
|
}
|
|
@@ -4328,7 +4379,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4328
4379
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4329
4380
|
);
|
|
4330
4381
|
let spool = void 0;
|
|
4331
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
4382
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4332
4383
|
if (indexer) {
|
|
4333
4384
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4334
4385
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
@@ -4348,7 +4399,7 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
4348
4399
|
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4349
4400
|
}
|
|
4350
4401
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4351
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices(
|
|
4402
|
+
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4352
4403
|
const spoolObject = spoolObjectResponse[0];
|
|
4353
4404
|
const rewardPoolObject = spoolObjectResponse[1];
|
|
4354
4405
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
@@ -4592,7 +4643,7 @@ var getStakeRewardPool = async ({
|
|
|
4592
4643
|
};
|
|
4593
4644
|
|
|
4594
4645
|
// src/queries/vescaQuery.ts
|
|
4595
|
-
var
|
|
4646
|
+
var import_bignumber8 = __toESM(require("bignumber.js"));
|
|
4596
4647
|
var import_sui_kit3 = require("@scallop-io/sui-kit");
|
|
4597
4648
|
var import_bcs2 = require("@mysten/sui/bcs");
|
|
4598
4649
|
var import_zod5 = require("zod");
|
|
@@ -4674,7 +4725,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4674
4725
|
0
|
|
4675
4726
|
);
|
|
4676
4727
|
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
4677
|
-
const lockedScaCoin = (0,
|
|
4728
|
+
const lockedScaCoin = (0, import_bignumber8.default)(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
4678
4729
|
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
4679
4730
|
vesca = {
|
|
4680
4731
|
id: veScaDynamicFieldObject.objectId,
|
|
@@ -4684,7 +4735,7 @@ var getVeSca = async (utils, veScaKey) => {
|
|
|
4684
4735
|
lockedScaAmount,
|
|
4685
4736
|
lockedScaCoin,
|
|
4686
4737
|
currentVeScaBalance,
|
|
4687
|
-
unlockAt: (0,
|
|
4738
|
+
unlockAt: (0, import_bignumber8.default)(dynamicFields.unlock_at * 1e3).toNumber()
|
|
4688
4739
|
};
|
|
4689
4740
|
}
|
|
4690
4741
|
return vesca;
|
|
@@ -4746,10 +4797,10 @@ var getVeScaTreasuryInfo = async (utils) => {
|
|
|
4746
4797
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
|
|
4747
4798
|
return null;
|
|
4748
4799
|
const treasuryFields = veScaTreasury.data.content.fields;
|
|
4749
|
-
const totalLockedSca = (0,
|
|
4800
|
+
const totalLockedSca = (0, import_bignumber8.default)(
|
|
4750
4801
|
treasuryFields.unlock_schedule.fields.locked_sca_amount
|
|
4751
4802
|
).shiftedBy(-9).toNumber();
|
|
4752
|
-
const totalVeSca = (0,
|
|
4803
|
+
const totalVeSca = (0, import_bignumber8.default)(
|
|
4753
4804
|
await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data) ?? 0
|
|
4754
4805
|
).shiftedBy(-9).toNumber();
|
|
4755
4806
|
const averageLockingPeriod = totalLockedSca > 0 ? totalVeSca / totalLockedSca * 4 : 0;
|
|
@@ -4785,15 +4836,6 @@ var ScallopUtils = class {
|
|
|
4785
4836
|
this.getSpoolRewardCoinName = (stakeMarketCoinName) => {
|
|
4786
4837
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
4787
4838
|
};
|
|
4788
|
-
/**
|
|
4789
|
-
* Get reward type of borrow incentive pool.
|
|
4790
|
-
*
|
|
4791
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
4792
|
-
* @return Borrow incentive reward coin name.
|
|
4793
|
-
*/
|
|
4794
|
-
this.getBorrowIncentiveRewardCoinName = (borrowIncentiveCoinName) => {
|
|
4795
|
-
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
4796
|
-
};
|
|
4797
4839
|
this.params = {
|
|
4798
4840
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
4799
4841
|
...params
|
|
@@ -4863,7 +4905,10 @@ var ScallopUtils = class {
|
|
|
4863
4905
|
* @param coinName - Specific support coin name.
|
|
4864
4906
|
* @return Coin type.
|
|
4865
4907
|
*/
|
|
4866
|
-
parseCoinType(coinName) {
|
|
4908
|
+
parseCoinType(coinName, useOldMarketCoin = false) {
|
|
4909
|
+
if (sCoinIds[coinName] && !useOldMarketCoin) {
|
|
4910
|
+
return sCoinIds[coinName];
|
|
4911
|
+
}
|
|
4867
4912
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
4868
4913
|
const coinPackageId = this.address.get(`core.coins.${coinName}.id`) || coinIds[coinName] || void 0;
|
|
4869
4914
|
if (!coinPackageId) {
|
|
@@ -4918,6 +4963,15 @@ var ScallopUtils = class {
|
|
|
4918
4963
|
return void 0;
|
|
4919
4964
|
}
|
|
4920
4965
|
}
|
|
4966
|
+
/**
|
|
4967
|
+
* Convert sCoin name to coin name.
|
|
4968
|
+
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
4969
|
+
* e.g: `scallop_sui -> ssui
|
|
4970
|
+
* @return sCoin name
|
|
4971
|
+
*/
|
|
4972
|
+
parseCoinNameFromSCoinName(coinName) {
|
|
4973
|
+
return sCoinRawNameToName[coinName];
|
|
4974
|
+
}
|
|
4921
4975
|
/**
|
|
4922
4976
|
* Convert sCoin name into sCoin type
|
|
4923
4977
|
* @param sCoinName
|
|
@@ -4960,7 +5014,7 @@ var ScallopUtils = class {
|
|
|
4960
5014
|
*/
|
|
4961
5015
|
parseMarketCoinType(coinName) {
|
|
4962
5016
|
const protocolObjectId = this.address.get("core.object") ?? PROTOCOL_OBJECT_ID;
|
|
4963
|
-
const coinType = this.parseCoinType(coinName);
|
|
5017
|
+
const coinType = this.parseCoinType(coinName, true);
|
|
4964
5018
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
4965
5019
|
}
|
|
4966
5020
|
parseCoinNameFromType(coinType) {
|
|
@@ -4969,7 +5023,7 @@ var ScallopUtils = class {
|
|
|
4969
5023
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
4970
5024
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|
|
4971
5025
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
4972
|
-
const
|
|
5026
|
+
const wormholeCoinTypeMap = {
|
|
4973
5027
|
[`${this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc}::coin::COIN`]: "wusdc",
|
|
4974
5028
|
[`${this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt}::coin::COIN`]: "wusdt",
|
|
4975
5029
|
[`${this.address.get("core.coins.weth.id") ?? wormholeCoinIds.weth}::coin::COIN`]: "weth",
|
|
@@ -4989,7 +5043,7 @@ var ScallopUtils = class {
|
|
|
4989
5043
|
},
|
|
4990
5044
|
{}
|
|
4991
5045
|
);
|
|
4992
|
-
const assetCoinName =
|
|
5046
|
+
const assetCoinName = wormholeCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
|
|
4993
5047
|
return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
|
|
4994
5048
|
}
|
|
4995
5049
|
/**
|
|
@@ -6100,11 +6154,7 @@ var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
|
6100
6154
|
]
|
|
6101
6155
|
);
|
|
6102
6156
|
},
|
|
6103
|
-
claimBorrowIncentive: (obligationId, obligationKey,
|
|
6104
|
-
const rewardCoinNames = builder.utils.getBorrowIncentiveRewardCoinName(coinName);
|
|
6105
|
-
if (rewardCoinNames.includes(rewardCoinName) === false) {
|
|
6106
|
-
throw new Error(`Invalid reward coin name ${rewardCoinName}`);
|
|
6107
|
-
}
|
|
6157
|
+
claimBorrowIncentive: (obligationId, obligationKey, rewardCoinName) => {
|
|
6108
6158
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
6109
6159
|
return txBlock.moveCall(
|
|
6110
6160
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
@@ -6197,7 +6247,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6197
6247
|
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
6198
6248
|
}
|
|
6199
6249
|
},
|
|
6200
|
-
claimBorrowIncentiveQuick: async (
|
|
6250
|
+
claimBorrowIncentiveQuick: async (rewardCoinName, obligation, obligationKey) => {
|
|
6201
6251
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo2(
|
|
6202
6252
|
builder,
|
|
6203
6253
|
txBlock,
|
|
@@ -6207,7 +6257,6 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
6207
6257
|
return txBlock.claimBorrowIncentive(
|
|
6208
6258
|
obligationArg,
|
|
6209
6259
|
obligationKeyArg,
|
|
6210
|
-
coinName,
|
|
6211
6260
|
rewardCoinName
|
|
6212
6261
|
);
|
|
6213
6262
|
}
|
|
@@ -7103,8 +7152,8 @@ var ScallopQuery = class {
|
|
|
7103
7152
|
* @param indexer - Whether to use indexer.
|
|
7104
7153
|
* @return Market data.
|
|
7105
7154
|
*/
|
|
7106
|
-
async queryMarket(
|
|
7107
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
7155
|
+
async queryMarket(args) {
|
|
7156
|
+
return await queryMarket(this, args?.indexer, args?.coinPrices);
|
|
7108
7157
|
}
|
|
7109
7158
|
/**
|
|
7110
7159
|
* Get market pools.
|
|
@@ -7117,8 +7166,13 @@ var ScallopQuery = class {
|
|
|
7117
7166
|
* @param indexer - Whether to use indexer.
|
|
7118
7167
|
* @return Market pools data.
|
|
7119
7168
|
*/
|
|
7120
|
-
async getMarketPools(poolCoinNames,
|
|
7121
|
-
return await getMarketPools(
|
|
7169
|
+
async getMarketPools(poolCoinNames, args) {
|
|
7170
|
+
return await getMarketPools(
|
|
7171
|
+
this,
|
|
7172
|
+
poolCoinNames,
|
|
7173
|
+
args?.indexer,
|
|
7174
|
+
args?.coinPrices
|
|
7175
|
+
);
|
|
7122
7176
|
}
|
|
7123
7177
|
/**
|
|
7124
7178
|
* Get market pool
|
|
@@ -7127,11 +7181,11 @@ var ScallopQuery = class {
|
|
|
7127
7181
|
* @param indexer - Whether to use indexer.
|
|
7128
7182
|
* @return Market pool data.
|
|
7129
7183
|
*/
|
|
7130
|
-
async getMarketPool(poolCoinName,
|
|
7184
|
+
async getMarketPool(poolCoinName, args) {
|
|
7131
7185
|
return await getMarketPool(
|
|
7132
7186
|
this,
|
|
7133
7187
|
poolCoinName,
|
|
7134
|
-
indexer,
|
|
7188
|
+
args?.indexer,
|
|
7135
7189
|
args?.marketObject,
|
|
7136
7190
|
args?.coinPrice
|
|
7137
7191
|
);
|
|
@@ -7147,8 +7201,8 @@ var ScallopQuery = class {
|
|
|
7147
7201
|
* @param indexer - Whether to use indexer.
|
|
7148
7202
|
* @return Market collaterals data.
|
|
7149
7203
|
*/
|
|
7150
|
-
async getMarketCollaterals(collateralCoinNames,
|
|
7151
|
-
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
7204
|
+
async getMarketCollaterals(collateralCoinNames, args) {
|
|
7205
|
+
return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
|
|
7152
7206
|
}
|
|
7153
7207
|
/**
|
|
7154
7208
|
* Get market collateral
|
|
@@ -7157,8 +7211,8 @@ var ScallopQuery = class {
|
|
|
7157
7211
|
* @param indexer - Whether to use indexer.
|
|
7158
7212
|
* @return Market collateral data.
|
|
7159
7213
|
*/
|
|
7160
|
-
async getMarketCollateral(collateralCoinName,
|
|
7161
|
-
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
7214
|
+
async getMarketCollateral(collateralCoinName, args) {
|
|
7215
|
+
return await getMarketCollateral(this, collateralCoinName, args?.indexer);
|
|
7162
7216
|
}
|
|
7163
7217
|
/**
|
|
7164
7218
|
* Get obligations data.
|
|
@@ -7244,11 +7298,11 @@ var ScallopQuery = class {
|
|
|
7244
7298
|
* @param indexer - Whether to use indexer.
|
|
7245
7299
|
* @return Spools data.
|
|
7246
7300
|
*/
|
|
7247
|
-
async getSpools(stakeMarketCoinNames,
|
|
7301
|
+
async getSpools(stakeMarketCoinNames, args) {
|
|
7248
7302
|
return await getSpools(
|
|
7249
7303
|
this,
|
|
7250
7304
|
stakeMarketCoinNames,
|
|
7251
|
-
indexer,
|
|
7305
|
+
args?.indexer,
|
|
7252
7306
|
args?.marketPools,
|
|
7253
7307
|
args?.coinPrices
|
|
7254
7308
|
);
|
|
@@ -7260,11 +7314,11 @@ var ScallopQuery = class {
|
|
|
7260
7314
|
* @param indexer - Whether to use indexer.
|
|
7261
7315
|
* @return Spool data.
|
|
7262
7316
|
*/
|
|
7263
|
-
async getSpool(stakeMarketCoinName,
|
|
7317
|
+
async getSpool(stakeMarketCoinName, args) {
|
|
7264
7318
|
return await getSpool(
|
|
7265
7319
|
this,
|
|
7266
7320
|
stakeMarketCoinName,
|
|
7267
|
-
indexer,
|
|
7321
|
+
args?.indexer,
|
|
7268
7322
|
args?.marketPool,
|
|
7269
7323
|
args?.coinPrices
|
|
7270
7324
|
);
|
|
@@ -7367,11 +7421,12 @@ var ScallopQuery = class {
|
|
|
7367
7421
|
* @param indexer - Whether to use indexer.
|
|
7368
7422
|
* @return Borrow incentive pools data.
|
|
7369
7423
|
*/
|
|
7370
|
-
async getBorrowIncentivePools(coinNames,
|
|
7424
|
+
async getBorrowIncentivePools(coinNames, args) {
|
|
7371
7425
|
return await getBorrowIncentivePools(
|
|
7372
7426
|
this,
|
|
7373
7427
|
coinNames,
|
|
7374
|
-
indexer,
|
|
7428
|
+
args?.indexer,
|
|
7429
|
+
args?.marketPools,
|
|
7375
7430
|
args?.coinPrices
|
|
7376
7431
|
);
|
|
7377
7432
|
}
|
|
@@ -7393,8 +7448,8 @@ var ScallopQuery = class {
|
|
|
7393
7448
|
* @param indexer - Whether to use indexer.
|
|
7394
7449
|
* @return All lending and spool infomation.
|
|
7395
7450
|
*/
|
|
7396
|
-
async getLendings(poolCoinNames, ownerAddress = this.walletAddress,
|
|
7397
|
-
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
7451
|
+
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
7452
|
+
return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
|
|
7398
7453
|
}
|
|
7399
7454
|
/**
|
|
7400
7455
|
* Get user lending and spool information for specific pool.
|
|
@@ -7404,8 +7459,8 @@ var ScallopQuery = class {
|
|
|
7404
7459
|
* @param indexer - Whether to use indexer.
|
|
7405
7460
|
* @return Lending pool data.
|
|
7406
7461
|
*/
|
|
7407
|
-
async getLending(poolCoinName, ownerAddress = this.walletAddress,
|
|
7408
|
-
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
7462
|
+
async getLending(poolCoinName, ownerAddress = this.walletAddress, args) {
|
|
7463
|
+
return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
|
|
7409
7464
|
}
|
|
7410
7465
|
/**
|
|
7411
7466
|
* Get user all obligation accounts information.
|
|
@@ -7417,8 +7472,8 @@ var ScallopQuery = class {
|
|
|
7417
7472
|
* @param indexer - Whether to use indexer.
|
|
7418
7473
|
* @return All obligation accounts information.
|
|
7419
7474
|
*/
|
|
7420
|
-
async getObligationAccounts(ownerAddress = this.walletAddress,
|
|
7421
|
-
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
7475
|
+
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
7476
|
+
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
7422
7477
|
}
|
|
7423
7478
|
/**
|
|
7424
7479
|
* Get obligation account information for specific id.
|
|
@@ -7431,12 +7486,12 @@ var ScallopQuery = class {
|
|
|
7431
7486
|
* @param indexer - Whether to use indexer.
|
|
7432
7487
|
* @return Borrowing and collateral information.
|
|
7433
7488
|
*/
|
|
7434
|
-
async getObligationAccount(obligationId, ownerAddress = this.walletAddress,
|
|
7489
|
+
async getObligationAccount(obligationId, ownerAddress = this.walletAddress, args) {
|
|
7435
7490
|
return await getObligationAccount(
|
|
7436
7491
|
this,
|
|
7437
7492
|
obligationId,
|
|
7438
7493
|
ownerAddress,
|
|
7439
|
-
indexer
|
|
7494
|
+
args?.indexer
|
|
7440
7495
|
);
|
|
7441
7496
|
}
|
|
7442
7497
|
/**
|
|
@@ -7448,8 +7503,8 @@ var ScallopQuery = class {
|
|
|
7448
7503
|
*
|
|
7449
7504
|
* @return Total value locked.
|
|
7450
7505
|
*/
|
|
7451
|
-
async getTvl(
|
|
7452
|
-
return await getTotalValueLocked(this, indexer);
|
|
7506
|
+
async getTvl(args) {
|
|
7507
|
+
return await getTotalValueLocked(this, args?.indexer);
|
|
7453
7508
|
}
|
|
7454
7509
|
/**
|
|
7455
7510
|
* Get veSca data.
|
|
@@ -7587,6 +7642,13 @@ var ScallopQuery = class {
|
|
|
7587
7642
|
async getCoinPriceByIndexer(poolName) {
|
|
7588
7643
|
return this.indexer.getCoinPrice(poolName);
|
|
7589
7644
|
}
|
|
7645
|
+
/**
|
|
7646
|
+
* Get all coin prices, including sCoin
|
|
7647
|
+
* @returns prices data
|
|
7648
|
+
*/
|
|
7649
|
+
async getAllCoinPrices(args) {
|
|
7650
|
+
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
7651
|
+
}
|
|
7590
7652
|
};
|
|
7591
7653
|
|
|
7592
7654
|
// src/models/scallopBuilder.ts
|
|
@@ -8236,30 +8298,46 @@ var ScallopClient = class {
|
|
|
8236
8298
|
}
|
|
8237
8299
|
}
|
|
8238
8300
|
/**
|
|
8239
|
-
*
|
|
8301
|
+
* Claim borrow incentive reward.
|
|
8240
8302
|
*
|
|
8241
|
-
* @param
|
|
8303
|
+
* @param poolName
|
|
8242
8304
|
* @param amount - The amount of coins would deposit.
|
|
8243
8305
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
8244
8306
|
* @param accountId - The stake account object.
|
|
8245
8307
|
* @param walletAddress - The wallet address of the owner.
|
|
8246
8308
|
* @return Transaction block response or transaction block
|
|
8247
8309
|
*/
|
|
8248
|
-
async claimBorrowIncentive(
|
|
8310
|
+
async claimBorrowIncentive(obligationId, obligationKeyId, sign = true, walletAddress) {
|
|
8249
8311
|
const txBlock = this.builder.createTxBlock();
|
|
8250
8312
|
const sender = walletAddress ?? this.walletAddress;
|
|
8251
8313
|
txBlock.setSender(sender);
|
|
8252
|
-
const
|
|
8253
|
-
|
|
8314
|
+
const rewardCoinsCollection = {};
|
|
8315
|
+
const obligationAccount = await this.query.getObligationAccount(obligationId);
|
|
8316
|
+
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives).flatMap(
|
|
8317
|
+
({ rewards }) => rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
8318
|
+
).flatMap(({ coinName }) => coinName);
|
|
8319
|
+
for (const rewardCoinName of rewardCoinNames) {
|
|
8254
8320
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
8255
|
-
coinName,
|
|
8256
8321
|
rewardCoinName,
|
|
8257
8322
|
obligationId,
|
|
8258
8323
|
obligationKeyId
|
|
8259
8324
|
);
|
|
8260
|
-
|
|
8325
|
+
if (!rewardCoinsCollection[rewardCoinName]) {
|
|
8326
|
+
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
8327
|
+
} else {
|
|
8328
|
+
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
8329
|
+
}
|
|
8261
8330
|
}
|
|
8262
|
-
txBlock.transferObjects(
|
|
8331
|
+
txBlock.transferObjects(
|
|
8332
|
+
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
8333
|
+
const mergeDest = rewardCoins[0];
|
|
8334
|
+
if (rewardCoins.length > 1) {
|
|
8335
|
+
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
8336
|
+
}
|
|
8337
|
+
return mergeDest;
|
|
8338
|
+
}),
|
|
8339
|
+
sender
|
|
8340
|
+
);
|
|
8263
8341
|
if (sign) {
|
|
8264
8342
|
return await this.suiKit.signAndSendTxn(
|
|
8265
8343
|
txBlock
|
|
@@ -8569,12 +8647,12 @@ var Scallop = class {
|
|
|
8569
8647
|
UNLOCK_ROUND_DURATION,
|
|
8570
8648
|
USE_TEST_ADDRESS,
|
|
8571
8649
|
assetCoins,
|
|
8572
|
-
borrowIncentiveRewardCoins,
|
|
8573
8650
|
coinDecimals,
|
|
8574
8651
|
coinIds,
|
|
8575
8652
|
marketCoins,
|
|
8576
8653
|
queryKeys,
|
|
8577
8654
|
sCoinIds,
|
|
8655
|
+
sCoinRawNameToName,
|
|
8578
8656
|
sCoinTypeToName,
|
|
8579
8657
|
sCoins,
|
|
8580
8658
|
spoolRewardCoins,
|