@scallop-io/sui-scallop-sdk 1.4.5 → 1.4.7
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/index.d.ts +0 -1
- package/dist/constants/poolAddress.d.ts +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1644 -1478
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1848 -1678
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +1 -2
- package/dist/models/scallopCache.d.ts +16 -11
- package/dist/models/scallopQuery.d.ts +67 -3
- package/dist/queries/poolAddressesQuery.d.ts +2 -0
- package/dist/queries/portfolioQuery.d.ts +60 -3
- package/dist/types/model.d.ts +8 -2
- package/dist/utils/index.d.ts +0 -2
- package/package.json +1 -1
- package/src/constants/index.ts +0 -1
- package/src/constants/poolAddress.ts +93 -25
- package/src/constants/queryKeys.ts +1 -1
- package/src/index.ts +0 -1
- package/src/models/scallop.ts +8 -13
- package/src/models/scallopAddress.ts +2 -9
- package/src/models/scallopBuilder.ts +3 -6
- package/src/models/scallopCache.ts +96 -55
- package/src/models/scallopClient.ts +3 -6
- package/src/models/scallopIndexer.ts +1 -5
- package/src/models/scallopQuery.ts +42 -16
- package/src/models/scallopUtils.ts +7 -11
- package/src/queries/coreQuery.ts +4 -4
- package/src/queries/poolAddressesQuery.ts +6 -0
- package/src/queries/portfolioQuery.ts +209 -8
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/types/model.ts +13 -2
- package/src/utils/index.ts +0 -2
- package/src/utils/indexer.ts +3 -1
- package/dist/constants/tokenBucket.d.ts +0 -2
- package/dist/utils/tokenBucket.d.ts +0 -11
- package/src/constants/tokenBucket.ts +0 -2
- package/src/utils/tokenBucket.ts +0 -68
package/dist/index.mjs
CHANGED
|
@@ -352,7 +352,9 @@ var POOL_ADDRESSES = {
|
|
|
352
352
|
spool: "0x0b5f5f413bd3799e4052c37311966c77f3a4545eb125d2e93e67a68478021918",
|
|
353
353
|
spoolReward: "0x85ed6ed72ea97c35dbf0cdc7ed6fbc48d8ec15de9b17c74bf4512df8a6d7f166",
|
|
354
354
|
sCoinTreasury: "0xbe6b63021f3d82e0e7e977cdd718ed7c019cf2eba374b7b546220402452f938e",
|
|
355
|
-
|
|
355
|
+
sCoinType: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
356
|
+
coinDecimalId: "0x69b7a7c3c200439c1b5f3b19d7d495d5966d5f08de66c69276152f8db3992ec6",
|
|
357
|
+
coinType: "dba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
356
358
|
},
|
|
357
359
|
sbeth: {
|
|
358
360
|
lendingPoolAddress: "0xaa34c938e0394e5186c7dc626ad69be96af2194b23fdc6ac1c63090e399f5ba4",
|
|
@@ -367,7 +369,9 @@ var POOL_ADDRESSES = {
|
|
|
367
369
|
spool: void 0,
|
|
368
370
|
spoolReward: void 0,
|
|
369
371
|
sCoinTreasury: "0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed",
|
|
370
|
-
|
|
372
|
+
sCoinType: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
373
|
+
coinDecimalId: "0x89b04ba87f8832d4d76e17a1c9dce72eb3e64d372cf02012b8d2de5384faeef0",
|
|
374
|
+
coinType: "d0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH"
|
|
371
375
|
},
|
|
372
376
|
weth: {
|
|
373
377
|
lendingPoolAddress: "0xc8fcdff48efc265740ae0b74aae3faccae9ec00034039a113f3339798035108c",
|
|
@@ -382,7 +386,9 @@ var POOL_ADDRESSES = {
|
|
|
382
386
|
spool: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
383
387
|
spoolReward: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077",
|
|
384
388
|
sCoinTreasury: "0x4b7f5da0e306c9d52490a0c1d4091e653d6b89778b9b4f23c877e534e4d9cd21",
|
|
385
|
-
|
|
389
|
+
sCoinType: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
390
|
+
coinDecimalId: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
|
|
391
|
+
coinType: "af8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
|
|
386
392
|
},
|
|
387
393
|
wbtc: {
|
|
388
394
|
lendingPoolAddress: "0x65cc08a5aca0a0b8d72e1993ded8d145f06dd102fd0d8f285b92934faed564ab",
|
|
@@ -397,7 +403,9 @@ var POOL_ADDRESSES = {
|
|
|
397
403
|
spool: void 0,
|
|
398
404
|
spoolReward: void 0,
|
|
399
405
|
sCoinTreasury: "0xe2883934ea42c99bc998bbe0f01dd6d27aa0e27a56455707b1b34e6a41c20baa",
|
|
400
|
-
|
|
406
|
+
sCoinType: "0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC",
|
|
407
|
+
coinDecimalId: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
|
|
408
|
+
coinType: "027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN"
|
|
401
409
|
},
|
|
402
410
|
wusdc: {
|
|
403
411
|
lendingPoolAddress: "0x2f4df5e1368fbbdaa5c712d28b837b3d41c2d3872979ccededcdfdac55ff8a93",
|
|
@@ -412,7 +420,9 @@ var POOL_ADDRESSES = {
|
|
|
412
420
|
spool: "0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0",
|
|
413
421
|
spoolReward: "0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8",
|
|
414
422
|
sCoinTreasury: "0x50c5cfcbcca3aaacab0984e4d7ad9a6ad034265bebb440f0d1cd688ec20b2548",
|
|
415
|
-
|
|
423
|
+
sCoinType: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
424
|
+
coinDecimalId: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
|
|
425
|
+
coinType: "5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN"
|
|
416
426
|
},
|
|
417
427
|
wusdt: {
|
|
418
428
|
lendingPoolAddress: "0xfbc056f126dd35adc1f8fe985e2cedc8010e687e8e851e1c5b99fdf63cd1c879",
|
|
@@ -427,7 +437,9 @@ var POOL_ADDRESSES = {
|
|
|
427
437
|
spool: "0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f",
|
|
428
438
|
spoolReward: "0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080",
|
|
429
439
|
sCoinTreasury: "0x1f02e2fed702b477732d4ad6044aaed04f2e8e586a169153694861a901379df0",
|
|
430
|
-
|
|
440
|
+
sCoinType: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
441
|
+
coinDecimalId: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
|
|
442
|
+
coinType: "c060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN"
|
|
431
443
|
},
|
|
432
444
|
sui: {
|
|
433
445
|
lendingPoolAddress: "0x9c9077abf7a29eebce41e33addbcd6f5246a5221dd733e56ea0f00ae1b25c9e8",
|
|
@@ -442,7 +454,9 @@ var POOL_ADDRESSES = {
|
|
|
442
454
|
spool: "0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4",
|
|
443
455
|
spoolReward: "0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9",
|
|
444
456
|
sCoinTreasury: "0x5c1678c8261ac9eec024d4d630006a9f55c80dc0b1aa38a003fcb1d425818c6b",
|
|
445
|
-
|
|
457
|
+
sCoinType: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
458
|
+
coinDecimalId: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
|
|
459
|
+
coinType: "0000000000000000000000000000000000000000000000000000000000000002::sui::SUI"
|
|
446
460
|
},
|
|
447
461
|
wapt: {
|
|
448
462
|
lendingPoolAddress: "0xca8c14a24e0c32b198eaf479a3317461e3cc339097ce88eaf296a15df8dcfdf5",
|
|
@@ -457,22 +471,9 @@ var POOL_ADDRESSES = {
|
|
|
457
471
|
spool: void 0,
|
|
458
472
|
spoolReward: void 0,
|
|
459
473
|
sCoinTreasury: void 0,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
|
|
464
|
-
collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f",
|
|
465
|
-
borrowDynamic: "0xe3f301e16d4f1273ea659dd82c5c3f124ca5a5883a5726c7ec0f77bf43b70895",
|
|
466
|
-
interestModel: "0xd95affaee077006b8dbb4b108c1b087e95fc6e5143ef0682da345d5b35bc6356",
|
|
467
|
-
riskModel: "0x8e0da6358073144ec3557400c87f04991ba3a13ca7e0d0a19daed45260b32f16",
|
|
468
|
-
borrowFeeKey: "0x604bffbc817e8e12db15f2373a9e15b2c7adbc510649cdf2cc62a594af90671c",
|
|
469
|
-
supplyLimitKey: "0xbd419b536b3f9c9d4adfc20372ca6feedc53cc31798ac860dbfc847bcf05f54b",
|
|
470
|
-
borrowLimitKey: "0x77d453c51948f32564c810bc73f9ba7abde880657b7f89e1c8a3bc28fa36ee87",
|
|
471
|
-
isolatedAssetKey: void 0,
|
|
472
|
-
spool: void 0,
|
|
473
|
-
spoolReward: void 0,
|
|
474
|
-
sCoinTreasury: "0x760fd66f5be869af4382fa32b812b3c67f0eca1bb1ed7a5578b21d56e1848819",
|
|
475
|
-
coinDecimalId: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e"
|
|
474
|
+
sCoinType: void 0,
|
|
475
|
+
coinDecimalId: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
|
|
476
|
+
coinType: "3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37::coin::COIN"
|
|
476
477
|
},
|
|
477
478
|
cetus: {
|
|
478
479
|
lendingPoolAddress: "0xc09858f60e74a1b671635bec4e8a2c84a0ff313eb87f525fba3258e88c6b6282",
|
|
@@ -487,7 +488,26 @@ var POOL_ADDRESSES = {
|
|
|
487
488
|
spool: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
488
489
|
spoolReward: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f",
|
|
489
490
|
sCoinTreasury: "0xa283c63488773c916cb3d6c64109536160d5eb496caddc721eb39aad2977d735",
|
|
490
|
-
|
|
491
|
+
sCoinType: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
492
|
+
coinDecimalId: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
|
|
493
|
+
coinType: "06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
|
|
494
|
+
},
|
|
495
|
+
wsol: {
|
|
496
|
+
lendingPoolAddress: "0x985682c42984cdfb03f9ff7d8923344c2fe096b1ae4b82ea17721af19d22a21f",
|
|
497
|
+
collateralPoolAddress: "0xdc1cc2c371a043ae8e3c3fe2d013c35f1346960b7dbb4c072982c5b794ed144f",
|
|
498
|
+
borrowDynamic: "0xe3f301e16d4f1273ea659dd82c5c3f124ca5a5883a5726c7ec0f77bf43b70895",
|
|
499
|
+
interestModel: "0xd95affaee077006b8dbb4b108c1b087e95fc6e5143ef0682da345d5b35bc6356",
|
|
500
|
+
riskModel: "0x8e0da6358073144ec3557400c87f04991ba3a13ca7e0d0a19daed45260b32f16",
|
|
501
|
+
borrowFeeKey: "0x604bffbc817e8e12db15f2373a9e15b2c7adbc510649cdf2cc62a594af90671c",
|
|
502
|
+
supplyLimitKey: "0xbd419b536b3f9c9d4adfc20372ca6feedc53cc31798ac860dbfc847bcf05f54b",
|
|
503
|
+
borrowLimitKey: "0x77d453c51948f32564c810bc73f9ba7abde880657b7f89e1c8a3bc28fa36ee87",
|
|
504
|
+
isolatedAssetKey: void 0,
|
|
505
|
+
spool: void 0,
|
|
506
|
+
spoolReward: void 0,
|
|
507
|
+
sCoinTreasury: "0x760fd66f5be869af4382fa32b812b3c67f0eca1bb1ed7a5578b21d56e1848819",
|
|
508
|
+
sCoinType: "0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL",
|
|
509
|
+
coinDecimalId: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
|
|
510
|
+
coinType: "b7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8::coin::COIN"
|
|
491
511
|
},
|
|
492
512
|
afsui: {
|
|
493
513
|
lendingPoolAddress: "0x9b942a24ce390b7f5016d34a0217057bf9487b92aa6d7cc9894271dbbe62471a",
|
|
@@ -502,7 +522,9 @@ var POOL_ADDRESSES = {
|
|
|
502
522
|
spool: "0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800",
|
|
503
523
|
spoolReward: "0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e",
|
|
504
524
|
sCoinTreasury: "0x55f4dfe9e40bc4cc11c70fcb1f3daefa2bdc330567c58d4f0792fbd9f9175a62",
|
|
505
|
-
|
|
525
|
+
sCoinType: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
526
|
+
coinDecimalId: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
|
|
527
|
+
coinType: "f325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"
|
|
506
528
|
},
|
|
507
529
|
hasui: {
|
|
508
530
|
lendingPoolAddress: "0x7ebc607f6bdeb659fb6506cb91c5cc1d47bb365cfd5d2e637ea765346ec84ed4",
|
|
@@ -517,7 +539,9 @@ var POOL_ADDRESSES = {
|
|
|
517
539
|
spool: "0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa",
|
|
518
540
|
spoolReward: "0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66",
|
|
519
541
|
sCoinTreasury: "0x404ccc1404d74a90eb6f9c9d4b6cda6d417fb03189f80d9070a35e5dab1df0f5",
|
|
520
|
-
|
|
542
|
+
sCoinType: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
543
|
+
coinDecimalId: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
|
|
544
|
+
coinType: "bde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
521
545
|
},
|
|
522
546
|
vsui: {
|
|
523
547
|
lendingPoolAddress: "0xda9257c0731d8822e8a438ebced13415850d705b779c79958dcf2aeb21fcb43d",
|
|
@@ -532,7 +556,9 @@ var POOL_ADDRESSES = {
|
|
|
532
556
|
spool: "0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670",
|
|
533
557
|
spoolReward: "0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a",
|
|
534
558
|
sCoinTreasury: "0xc06688ee1af25abc286ffb1d18ce273d1d5907cd1064c25f4e8ca61ea989c1d1",
|
|
535
|
-
|
|
559
|
+
sCoinType: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI",
|
|
560
|
+
coinDecimalId: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
|
|
561
|
+
coinType: "549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
536
562
|
},
|
|
537
563
|
sca: {
|
|
538
564
|
lendingPoolAddress: "0x6fc7d4211fc7018b6c75e7b908b88f2e0536443239804a3d32af547637bd28d7",
|
|
@@ -547,7 +573,9 @@ var POOL_ADDRESSES = {
|
|
|
547
573
|
spool: void 0,
|
|
548
574
|
spoolReward: void 0,
|
|
549
575
|
sCoinTreasury: "0xe04bfc95e00252bd654ee13c08edef9ac5e4b6ae4074e8390db39e9a0109c529",
|
|
550
|
-
|
|
576
|
+
sCoinType: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
577
|
+
coinDecimalId: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
|
|
578
|
+
coinType: "7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA"
|
|
551
579
|
},
|
|
552
580
|
fud: {
|
|
553
581
|
lendingPoolAddress: "0xefed2cbe76b344792ac724523c8b2236740d1cea2100d46a0ed0dc760c7f4231",
|
|
@@ -562,7 +590,9 @@ var POOL_ADDRESSES = {
|
|
|
562
590
|
spool: void 0,
|
|
563
591
|
spoolReward: void 0,
|
|
564
592
|
sCoinTreasury: "0xf25212f11d182decff7a86165699a73e3d5787aced203ca539f43cfbc10db867",
|
|
565
|
-
|
|
593
|
+
sCoinType: "0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD",
|
|
594
|
+
coinDecimalId: "0x01087411ef48aaac1eb6e24803213e3a60a03b147dac930e5e341f17a85e524e",
|
|
595
|
+
coinType: "76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1::fud::FUD"
|
|
566
596
|
},
|
|
567
597
|
deep: {
|
|
568
598
|
lendingPoolAddress: "0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03",
|
|
@@ -577,7 +607,9 @@ var POOL_ADDRESSES = {
|
|
|
577
607
|
spool: void 0,
|
|
578
608
|
spoolReward: void 0,
|
|
579
609
|
sCoinTreasury: "0xc63838fabe37b25ad897392d89876d920f5e0c6a406bf3abcb84753d2829bc88",
|
|
580
|
-
|
|
610
|
+
sCoinType: "0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP",
|
|
611
|
+
coinDecimalId: "0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0",
|
|
612
|
+
coinType: "deeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP"
|
|
581
613
|
},
|
|
582
614
|
fdusd: {
|
|
583
615
|
lendingPoolAddress: "0x4f46051a01f05c3ad9aecf29a771aad5c884e1a1888e08d7709085e3a095bc9c",
|
|
@@ -592,7 +624,9 @@ var POOL_ADDRESSES = {
|
|
|
592
624
|
spool: void 0,
|
|
593
625
|
spoolReward: void 0,
|
|
594
626
|
sCoinTreasury: "0xdad9bc6293e694f67a5274ea51b596e0bdabfafc585ae6d7e82888e65f1a03e0",
|
|
595
|
-
|
|
627
|
+
sCoinType: "0x6711551c1e7652a270d9fbf0eee25d99594c157cde3cb5fbb49035eb59b1b001::scallop_fdusd::SCALLOP_FDUSD",
|
|
628
|
+
coinDecimalId: "0xdebee5265a67c186ed87fe93303d33dfe1de53e3b4fd7d9329c2852860acd3e7",
|
|
629
|
+
coinType: "f16e6b723f242ec745dfd7634ad072c42d5c1d9ac9d62a39c381303eaa57693a::fdusd::FDUSD"
|
|
596
630
|
}
|
|
597
631
|
};
|
|
598
632
|
|
|
@@ -655,7 +689,7 @@ var queryKeys = {
|
|
|
655
689
|
{
|
|
656
690
|
walletAddress,
|
|
657
691
|
options,
|
|
658
|
-
objectIds: JSON.stringify(objectIds ??
|
|
692
|
+
objectIds: JSON.stringify(objectIds ?? void 0)
|
|
659
693
|
}
|
|
660
694
|
],
|
|
661
695
|
getOwnedObjects: (input) => [
|
|
@@ -1200,10 +1234,6 @@ var TEST_ADDRESSES = {
|
|
|
1200
1234
|
}
|
|
1201
1235
|
};
|
|
1202
1236
|
|
|
1203
|
-
// src/constants/tokenBucket.ts
|
|
1204
|
-
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1205
|
-
var DEFAULT_INTERVAL_IN_MS = 250;
|
|
1206
|
-
|
|
1207
1237
|
// src/constants/vesca.ts
|
|
1208
1238
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
1209
1239
|
var MAX_LOCK_ROUNDS = 1460;
|
|
@@ -1211,1651 +1241,1641 @@ var MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION;
|
|
|
1211
1241
|
var MIN_INITIAL_LOCK_AMOUNT = 1e10;
|
|
1212
1242
|
var MIN_TOP_UP_AMOUNT = 1e9;
|
|
1213
1243
|
|
|
1214
|
-
// src/models/scallopAddress.ts
|
|
1215
|
-
import { SuiKit } from "@scallop-io/sui-kit";
|
|
1216
|
-
|
|
1217
1244
|
// src/models/scallopCache.ts
|
|
1218
1245
|
import { QueryClient } from "@tanstack/query-core";
|
|
1219
1246
|
import {
|
|
1220
1247
|
SuiTxBlock,
|
|
1221
|
-
normalizeStructTag
|
|
1222
|
-
parseStructTag
|
|
1248
|
+
normalizeStructTag,
|
|
1249
|
+
parseStructTag
|
|
1223
1250
|
} from "@scallop-io/sui-kit";
|
|
1224
1251
|
|
|
1225
|
-
// src/
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1252
|
+
// src/models/suiKit.ts
|
|
1253
|
+
import { SuiKit } from "@scallop-io/sui-kit";
|
|
1254
|
+
var newSuiKit = (params) => {
|
|
1255
|
+
return new SuiKit({
|
|
1256
|
+
...params,
|
|
1257
|
+
fullnodeUrls: Array.from(
|
|
1258
|
+
/* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
|
|
1259
|
+
)
|
|
1260
|
+
});
|
|
1232
1261
|
};
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1262
|
+
|
|
1263
|
+
// src/models/scallopCache.ts
|
|
1264
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1265
|
+
var DEFAULT_INTERVAL_IN_MS = 250;
|
|
1266
|
+
var ScallopCache = class {
|
|
1267
|
+
constructor(params, instance) {
|
|
1268
|
+
this.tokensPerInterval = DEFAULT_TOKENS_PER_INTERVAL;
|
|
1269
|
+
this.interval = DEFAULT_INTERVAL_IN_MS;
|
|
1270
|
+
this.params = params;
|
|
1271
|
+
this.suiKit = instance?.suiKit ?? newSuiKit(params);
|
|
1272
|
+
this.queryClient = instance?.queryClient ?? new QueryClient(params?.cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
1273
|
+
this.tokens = this.tokensPerInterval;
|
|
1274
|
+
this.lastRefill = Date.now();
|
|
1275
|
+
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
1236
1276
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
1240
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
1277
|
+
get client() {
|
|
1278
|
+
return this.suiKit.client();
|
|
1241
1279
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
throw new Error("Minimum lock period is 1 day");
|
|
1280
|
+
refill() {
|
|
1281
|
+
const now = Date.now();
|
|
1282
|
+
const elapsed = now - this.lastRefill;
|
|
1283
|
+
if (elapsed >= this.interval) {
|
|
1284
|
+
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1285
|
+
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1286
|
+
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
1287
|
+
}
|
|
1251
1288
|
}
|
|
1252
|
-
|
|
1253
|
-
(
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1289
|
+
removeTokens(count) {
|
|
1290
|
+
this.refill();
|
|
1291
|
+
if (this.tokens >= count) {
|
|
1292
|
+
this.tokens -= count;
|
|
1293
|
+
return true;
|
|
1294
|
+
}
|
|
1295
|
+
return false;
|
|
1259
1296
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1297
|
+
async callWithRateLimit(fn, maxRetries = 15, backoffFactor = 1.25) {
|
|
1298
|
+
let retries = 0;
|
|
1299
|
+
const tryRequest = async () => {
|
|
1300
|
+
if (this.removeTokens(1)) {
|
|
1301
|
+
const result = await fn();
|
|
1302
|
+
return result;
|
|
1303
|
+
} else if (retries < maxRetries) {
|
|
1304
|
+
retries++;
|
|
1305
|
+
const delay = this.interval * Math.pow(backoffFactor, retries);
|
|
1306
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1307
|
+
return tryRequest();
|
|
1308
|
+
} else {
|
|
1309
|
+
console.error("Maximum retries reached");
|
|
1310
|
+
return null;
|
|
1269
1311
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1312
|
+
};
|
|
1313
|
+
return tryRequest();
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* @description Invalidate cache based on the refetchType parameter
|
|
1317
|
+
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
1318
|
+
*
|
|
1319
|
+
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1320
|
+
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
1321
|
+
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
1322
|
+
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
1323
|
+
*/
|
|
1324
|
+
// public async invalidateAllCache() {
|
|
1325
|
+
// return Object.values(queryKeys.rpc).map((t) =>
|
|
1326
|
+
// this.queryClient.invalidateQueries({
|
|
1327
|
+
// queryKey: t(),
|
|
1328
|
+
// type: 'all',
|
|
1329
|
+
// })
|
|
1330
|
+
// );
|
|
1331
|
+
// }
|
|
1332
|
+
retryFn(errCount, e) {
|
|
1333
|
+
if (errCount === 5)
|
|
1334
|
+
return false;
|
|
1335
|
+
if (e.status === 429)
|
|
1336
|
+
return true;
|
|
1337
|
+
return false;
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* @description Provides cache for inspectTxn of the SuiKit.
|
|
1341
|
+
* @param QueryInspectTxnParams
|
|
1342
|
+
* @param txBlock
|
|
1343
|
+
* @returns Promise<DevInspectResults>
|
|
1344
|
+
*/
|
|
1345
|
+
async queryInspectTxn({
|
|
1346
|
+
queryTarget,
|
|
1347
|
+
args,
|
|
1348
|
+
typeArgs
|
|
1349
|
+
}) {
|
|
1350
|
+
const txBlock = new SuiTxBlock();
|
|
1351
|
+
const resolvedQueryTarget = await this.queryGetNormalizedMoveFunction(queryTarget);
|
|
1352
|
+
if (!resolvedQueryTarget)
|
|
1353
|
+
throw new Error("Invalid query target");
|
|
1354
|
+
const { parameters } = resolvedQueryTarget;
|
|
1355
|
+
const resolvedArgs = await Promise.all(
|
|
1356
|
+
(args ?? []).map(async (arg, idx) => {
|
|
1357
|
+
if (typeof arg !== "string")
|
|
1358
|
+
return arg;
|
|
1359
|
+
const cachedData = (await this.queryGetObject(arg))?.data;
|
|
1360
|
+
if (!cachedData)
|
|
1361
|
+
return arg;
|
|
1362
|
+
const owner = cachedData.owner;
|
|
1363
|
+
if (!owner || typeof owner !== "object" || !("Shared" in owner))
|
|
1364
|
+
return {
|
|
1365
|
+
objectId: cachedData.objectId,
|
|
1366
|
+
version: cachedData.version,
|
|
1367
|
+
digest: cachedData.digest
|
|
1368
|
+
};
|
|
1369
|
+
const parameter = parameters[idx];
|
|
1370
|
+
if (typeof parameter !== "object" || !("MutableReference" in parameter || "Reference" in parameter))
|
|
1371
|
+
return arg;
|
|
1372
|
+
return {
|
|
1373
|
+
objectId: cachedData.objectId,
|
|
1374
|
+
initialSharedVersion: owner.Shared.initial_shared_version,
|
|
1375
|
+
mutable: "MutableReference" in parameter
|
|
1376
|
+
};
|
|
1377
|
+
})
|
|
1378
|
+
);
|
|
1379
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
1380
|
+
const query = await this.queryClient.fetchQuery({
|
|
1381
|
+
retry: this.retryFn,
|
|
1382
|
+
retryDelay: 1e3,
|
|
1383
|
+
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1384
|
+
queryFn: async () => {
|
|
1385
|
+
return await this.callWithRateLimit(
|
|
1386
|
+
async () => await this.suiKit.inspectTxn(txBlock)
|
|
1273
1387
|
);
|
|
1274
1388
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1389
|
+
});
|
|
1390
|
+
return query;
|
|
1391
|
+
}
|
|
1392
|
+
async queryGetNormalizedMoveFunction(target) {
|
|
1393
|
+
const { address, module, name } = parseStructTag(target);
|
|
1394
|
+
return this.queryClient.fetchQuery({
|
|
1395
|
+
queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
|
|
1396
|
+
queryFn: async () => {
|
|
1397
|
+
return await this.callWithRateLimit(
|
|
1398
|
+
async () => await this.suiKit.client().getNormalizedMoveFunction({
|
|
1399
|
+
package: address,
|
|
1400
|
+
module,
|
|
1401
|
+
function: name
|
|
1402
|
+
})
|
|
1279
1403
|
);
|
|
1280
1404
|
}
|
|
1281
|
-
}
|
|
1282
|
-
throw new Error(
|
|
1283
|
-
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
1284
|
-
);
|
|
1285
|
-
}
|
|
1286
|
-
} else {
|
|
1287
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1288
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1289
|
-
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
1290
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
1291
|
-
}
|
|
1292
|
-
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
1293
|
-
checkExtendLockPeriod(
|
|
1294
|
-
lockPeriodInDays,
|
|
1295
|
-
newUnlockAtInSecondTimestamp,
|
|
1296
|
-
prevUnlockAtInMillisTimestamp
|
|
1297
|
-
);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
};
|
|
1301
|
-
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
1302
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1303
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1304
|
-
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
1305
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
1306
|
-
}
|
|
1307
|
-
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
1308
|
-
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
1309
|
-
if (isLockExpired) {
|
|
1310
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
1314
|
-
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
1315
|
-
throw new Error("Renew method can only be used for expired veSca");
|
|
1405
|
+
});
|
|
1316
1406
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1407
|
+
/**
|
|
1408
|
+
* @description Provides cache for getObject of the SuiKit.
|
|
1409
|
+
* @param objectId
|
|
1410
|
+
* @param QueryObjectParams
|
|
1411
|
+
* @returns Promise<SuiObjectResponse>
|
|
1412
|
+
*/
|
|
1413
|
+
async queryGetObject(objectId, options) {
|
|
1414
|
+
options = {
|
|
1415
|
+
...options,
|
|
1416
|
+
showOwner: true,
|
|
1417
|
+
showContent: true
|
|
1418
|
+
};
|
|
1419
|
+
return this.queryClient.fetchQuery({
|
|
1420
|
+
retry: this.retryFn,
|
|
1421
|
+
retryDelay: 1e3,
|
|
1422
|
+
queryKey: queryKeys.rpc.getObject(objectId, options),
|
|
1423
|
+
queryFn: async () => {
|
|
1424
|
+
return await this.callWithRateLimit(
|
|
1425
|
+
async () => await this.client.getObject({
|
|
1426
|
+
id: objectId,
|
|
1427
|
+
options
|
|
1428
|
+
})
|
|
1429
|
+
);
|
|
1430
|
+
}
|
|
1431
|
+
});
|
|
1319
1432
|
}
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1433
|
+
/**
|
|
1434
|
+
* @description Provides cache for getObjects of the SuiKit.
|
|
1435
|
+
* @param objectIds
|
|
1436
|
+
* @returns Promise<SuiObjectData[]>
|
|
1437
|
+
*/
|
|
1438
|
+
async queryGetObjects(objectIds, options = {
|
|
1439
|
+
showContent: true
|
|
1440
|
+
}) {
|
|
1441
|
+
if (objectIds.length === 0)
|
|
1442
|
+
return [];
|
|
1443
|
+
return this.queryClient.fetchQuery({
|
|
1444
|
+
retry: this.retryFn,
|
|
1445
|
+
retryDelay: 1e3,
|
|
1446
|
+
queryKey: queryKeys.rpc.getObjects(
|
|
1447
|
+
objectIds,
|
|
1448
|
+
this.walletAddress,
|
|
1449
|
+
options
|
|
1450
|
+
),
|
|
1451
|
+
queryFn: async () => {
|
|
1452
|
+
const results = await this.callWithRateLimit(
|
|
1453
|
+
async () => await this.suiKit.getObjects(objectIds, options)
|
|
1454
|
+
);
|
|
1455
|
+
if (results) {
|
|
1456
|
+
results.forEach((result) => {
|
|
1457
|
+
this.queryClient.setQueriesData(
|
|
1458
|
+
{
|
|
1459
|
+
exact: false,
|
|
1460
|
+
queryKey: queryKeys.rpc.getObject(result.objectId, options)
|
|
1461
|
+
},
|
|
1462
|
+
{
|
|
1463
|
+
data: result,
|
|
1464
|
+
error: null
|
|
1465
|
+
},
|
|
1466
|
+
{
|
|
1467
|
+
updatedAt: Date.now()
|
|
1468
|
+
}
|
|
1469
|
+
);
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
return results;
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
1478
|
+
* @param input
|
|
1479
|
+
* @returns Promise<PaginatedObjectsResponse>
|
|
1480
|
+
*/
|
|
1481
|
+
async queryGetOwnedObjects(input) {
|
|
1482
|
+
return this.queryClient.fetchQuery({
|
|
1483
|
+
retry: this.retryFn,
|
|
1484
|
+
retryDelay: 1e3,
|
|
1485
|
+
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1486
|
+
queryFn: async () => {
|
|
1487
|
+
const results = await this.callWithRateLimit(
|
|
1488
|
+
async () => await this.client.getOwnedObjects(input)
|
|
1489
|
+
);
|
|
1490
|
+
if (results && results.data.length > 0) {
|
|
1491
|
+
results.data.filter(
|
|
1492
|
+
(result) => !!result.data
|
|
1493
|
+
).forEach((result) => {
|
|
1494
|
+
this.queryClient.setQueriesData(
|
|
1495
|
+
{
|
|
1496
|
+
exact: false,
|
|
1497
|
+
queryKey: queryKeys.rpc.getObject(
|
|
1498
|
+
result.data.objectId,
|
|
1499
|
+
input.options ?? {}
|
|
1500
|
+
)
|
|
1501
|
+
},
|
|
1502
|
+
{
|
|
1503
|
+
data: result.data,
|
|
1504
|
+
error: null
|
|
1505
|
+
},
|
|
1506
|
+
{
|
|
1507
|
+
updatedAt: Date.now()
|
|
1508
|
+
}
|
|
1509
|
+
);
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
return results;
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1515
|
+
}
|
|
1516
|
+
async queryGetDynamicFields(input) {
|
|
1517
|
+
return this.queryClient.fetchQuery({
|
|
1518
|
+
retry: this.retryFn,
|
|
1519
|
+
retryDelay: 1e3,
|
|
1520
|
+
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1521
|
+
queryFn: async () => {
|
|
1522
|
+
return await this.callWithRateLimit(
|
|
1523
|
+
async () => await this.client.getDynamicFields(input)
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
}
|
|
1528
|
+
async queryGetDynamicFieldObject(input) {
|
|
1529
|
+
return this.queryClient.fetchQuery({
|
|
1530
|
+
retry: this.retryFn,
|
|
1531
|
+
retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
|
|
1532
|
+
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1533
|
+
queryFn: async () => {
|
|
1534
|
+
const result = await this.callWithRateLimit(
|
|
1535
|
+
() => this.client.getDynamicFieldObject(input)
|
|
1536
|
+
);
|
|
1537
|
+
if (result?.data) {
|
|
1538
|
+
this.queryClient.setQueriesData(
|
|
1539
|
+
{
|
|
1540
|
+
exact: false,
|
|
1541
|
+
queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
|
|
1542
|
+
showContent: true,
|
|
1543
|
+
showOwner: true
|
|
1544
|
+
})
|
|
1545
|
+
},
|
|
1546
|
+
{
|
|
1547
|
+
data: result.data,
|
|
1548
|
+
error: null
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
updatedAt: Date.now()
|
|
1552
|
+
}
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
return result;
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
async queryGetAllCoinBalances(owner) {
|
|
1560
|
+
return this.queryClient.fetchQuery({
|
|
1561
|
+
retry: this.retryFn,
|
|
1562
|
+
retryDelay: 1e3,
|
|
1563
|
+
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1564
|
+
queryFn: async () => {
|
|
1565
|
+
const allBalances = await this.callWithRateLimit(
|
|
1566
|
+
async () => await this.client.getAllBalances({ owner })
|
|
1567
|
+
);
|
|
1568
|
+
if (!allBalances)
|
|
1569
|
+
return {};
|
|
1570
|
+
const balances = allBalances.reduce(
|
|
1571
|
+
(acc, coinBalance) => {
|
|
1572
|
+
if (coinBalance.totalBalance !== "0") {
|
|
1573
|
+
acc[normalizeStructTag(coinBalance.coinType)] = coinBalance;
|
|
1574
|
+
}
|
|
1575
|
+
return acc;
|
|
1576
|
+
},
|
|
1577
|
+
{}
|
|
1578
|
+
);
|
|
1579
|
+
return balances;
|
|
1580
|
+
}
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
async queryGetCoinBalance(input) {
|
|
1584
|
+
if (!input.coinType)
|
|
1585
|
+
return null;
|
|
1586
|
+
return (await this.queryGetAllCoinBalances(input.owner) ?? {})[normalizeStructTag(input.coinType)] ?? "0";
|
|
1325
1587
|
}
|
|
1326
1588
|
};
|
|
1327
1589
|
|
|
1328
|
-
// src/
|
|
1329
|
-
import
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
1353
|
-
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount),
|
|
1354
|
-
isIsolated: originMarketPoolData.isIsolated,
|
|
1355
|
-
supplyLimit: Number(originMarketPoolData.supplyLimit),
|
|
1356
|
-
borrowLimit: Number(originMarketPoolData.borrowLimit)
|
|
1357
|
-
};
|
|
1358
|
-
};
|
|
1359
|
-
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
1360
|
-
const poolCoinName = utils.parseCoinNameFromType(
|
|
1361
|
-
parsedMarketPoolData.coinType
|
|
1362
|
-
);
|
|
1363
|
-
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
1364
|
-
const borrowYearFactor = 24 * 365 * 3600;
|
|
1365
|
-
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1366
|
-
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1367
|
-
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1368
|
-
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1369
|
-
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1370
|
-
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
1371
|
-
const borrowIndexDelta = BigNumber(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
1372
|
-
BigNumber(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
1373
|
-
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
1374
|
-
const currentBorrowIndex = BigNumber(parsedMarketPoolData.borrowIndex).plus(
|
|
1375
|
-
borrowIndexDelta
|
|
1376
|
-
);
|
|
1377
|
-
const growthInterest = BigNumber(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
1378
|
-
const increasedDebtAmount = BigNumber(
|
|
1379
|
-
parsedMarketPoolData.debtAmount
|
|
1380
|
-
).multipliedBy(growthInterest);
|
|
1381
|
-
const borrowAmount = increasedDebtAmount.plus(
|
|
1382
|
-
parsedMarketPoolData.debtAmount
|
|
1383
|
-
);
|
|
1384
|
-
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
1385
|
-
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
1386
|
-
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
1387
|
-
);
|
|
1388
|
-
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
1389
|
-
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
1390
|
-
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
1391
|
-
);
|
|
1392
|
-
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
1393
|
-
let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
|
|
1394
|
-
utilizationRate = utilizationRate.isFinite() ? utilizationRate : BigNumber(0);
|
|
1395
|
-
let supplyApr = BigNumber(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
1396
|
-
supplyApr = supplyApr.isFinite() ? supplyApr : BigNumber(0);
|
|
1397
|
-
let conversionRate = supplyAmount.dividedBy(
|
|
1398
|
-
parsedMarketPoolData.marketCoinSupplyAmount
|
|
1399
|
-
);
|
|
1400
|
-
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : BigNumber(1);
|
|
1401
|
-
return {
|
|
1402
|
-
baseBorrowApr,
|
|
1403
|
-
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
1404
|
-
borrowAprOnHighKink,
|
|
1405
|
-
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
1406
|
-
borrowAprOnMidKink,
|
|
1407
|
-
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
1408
|
-
coinDecimal,
|
|
1409
|
-
maxBorrowApr,
|
|
1410
|
-
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
1411
|
-
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
1412
|
-
borrowApy: Math.min(
|
|
1413
|
-
utils.parseAprToApy(borrowApr),
|
|
1414
|
-
utils.parseAprToApy(maxBorrowApr)
|
|
1415
|
-
),
|
|
1416
|
-
borrowIndex: currentBorrowIndex.toNumber(),
|
|
1417
|
-
growthInterest: growthInterest.toNumber(),
|
|
1418
|
-
supplyAmount: supplyAmount.toNumber(),
|
|
1419
|
-
supplyCoin: supplyCoin.toNumber(),
|
|
1420
|
-
borrowAmount: borrowAmount.toNumber(),
|
|
1421
|
-
borrowCoin: borrowCoin.toNumber(),
|
|
1422
|
-
reserveAmount: reserveAmount.toNumber(),
|
|
1423
|
-
reserveCoin: reserveCoin.toNumber(),
|
|
1424
|
-
utilizationRate: utilizationRate.toNumber(),
|
|
1425
|
-
supplyApr: supplyApr.toNumber(),
|
|
1426
|
-
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
1427
|
-
conversionRate: conversionRate.toNumber(),
|
|
1428
|
-
isIsolated: parsedMarketPoolData.isIsolated,
|
|
1429
|
-
maxSupplyCoin: BigNumber(parsedMarketPoolData.supplyLimit).shiftedBy(-coinDecimal).toNumber(),
|
|
1430
|
-
maxBorrowCoin: BigNumber(parsedMarketPoolData.borrowLimit).shiftedBy(-coinDecimal).toNumber()
|
|
1431
|
-
};
|
|
1432
|
-
};
|
|
1433
|
-
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
1434
|
-
const divisor = 2 ** 32;
|
|
1435
|
-
return {
|
|
1436
|
-
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
1437
|
-
isIsolated: originMarketCollateralData.isIsolated,
|
|
1438
|
-
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
1439
|
-
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
1440
|
-
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
1441
|
-
liquidationPenalty: Number(originMarketCollateralData.liquidationPenalty.value) / divisor,
|
|
1442
|
-
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
1443
|
-
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
1444
|
-
totalCollateralAmount: Number(
|
|
1445
|
-
originMarketCollateralData.totalCollateralAmount
|
|
1446
|
-
)
|
|
1447
|
-
};
|
|
1448
|
-
};
|
|
1449
|
-
var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
1450
|
-
const collateralCoinName = utils.parseCoinNameFromType(
|
|
1451
|
-
parsedMarketCollateralData.coinType
|
|
1452
|
-
);
|
|
1453
|
-
const coinDecimal = utils.getCoinDecimal(collateralCoinName);
|
|
1454
|
-
const maxCollateralCoin = BigNumber(
|
|
1455
|
-
parsedMarketCollateralData.maxCollateralAmount
|
|
1456
|
-
).shiftedBy(-1 * coinDecimal);
|
|
1457
|
-
const depositCoin = BigNumber(
|
|
1458
|
-
parsedMarketCollateralData.totalCollateralAmount
|
|
1459
|
-
).shiftedBy(-1 * coinDecimal);
|
|
1460
|
-
return {
|
|
1461
|
-
coinDecimal,
|
|
1462
|
-
isIsolated: parsedMarketCollateralData.isIsolated,
|
|
1463
|
-
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
1464
|
-
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
1465
|
-
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
|
1466
|
-
depositCoin: depositCoin.toNumber()
|
|
1467
|
-
};
|
|
1468
|
-
};
|
|
1469
|
-
var parseOriginSpoolData = (originSpoolData) => {
|
|
1470
|
-
return {
|
|
1471
|
-
stakeType: normalizeStructTag(originSpoolData.stakeType.fields.name),
|
|
1472
|
-
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
1473
|
-
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
1474
|
-
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
1475
|
-
period: Number(originSpoolData.pointDistributionTime),
|
|
1476
|
-
maxStake: Number(originSpoolData.maxStake),
|
|
1477
|
-
staked: Number(originSpoolData.stakes),
|
|
1478
|
-
index: Number(originSpoolData.index),
|
|
1479
|
-
createdAt: Number(originSpoolData.createdAt),
|
|
1480
|
-
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
1481
|
-
};
|
|
1482
|
-
};
|
|
1483
|
-
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
1484
|
-
const baseIndexRate = 1e9;
|
|
1485
|
-
const distributedPointPerSec = BigNumber(
|
|
1486
|
-
parsedSpoolData.pointPerPeriod
|
|
1487
|
-
).dividedBy(parsedSpoolData.period);
|
|
1488
|
-
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
1489
|
-
parsedSpoolData.period
|
|
1490
|
-
);
|
|
1491
|
-
const remainingPeriod = pointPerSec.gt(0) ? BigNumber(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec) : BigNumber(0);
|
|
1492
|
-
const startDate = parsedSpoolData.createdAt;
|
|
1493
|
-
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
1494
|
-
const timeDelta = BigNumber(
|
|
1495
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
1496
|
-
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
1497
|
-
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
1498
|
-
parsedSpoolData.distributedPoint
|
|
1499
|
-
);
|
|
1500
|
-
const accumulatedPoints = BigNumber.minimum(
|
|
1501
|
-
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
1502
|
-
remainingPoints
|
|
1503
|
-
);
|
|
1504
|
-
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
1505
|
-
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
1506
|
-
);
|
|
1507
|
-
const currentTotalDistributedPoint = BigNumber(
|
|
1508
|
-
parsedSpoolData.distributedPoint
|
|
1509
|
-
).plus(accumulatedPoints);
|
|
1510
|
-
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
1511
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
1512
|
-
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
1513
|
-
return {
|
|
1514
|
-
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1515
|
-
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1516
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
1517
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1518
|
-
startDate: new Date(startDate * 1e3),
|
|
1519
|
-
endDate: new Date(endDate * 1e3),
|
|
1520
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
1521
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
1522
|
-
stakedValue: stakedValue.toNumber()
|
|
1523
|
-
};
|
|
1524
|
-
};
|
|
1525
|
-
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
1526
|
-
return {
|
|
1527
|
-
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
1528
|
-
exchangeRateDenominator: Number(
|
|
1529
|
-
originSpoolRewardPoolData.exchange_rate_denominator
|
|
1530
|
-
),
|
|
1531
|
-
exchangeRateNumerator: Number(
|
|
1532
|
-
originSpoolRewardPoolData.exchange_rate_numerator
|
|
1533
|
-
),
|
|
1534
|
-
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
1535
|
-
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
1536
|
-
};
|
|
1537
|
-
};
|
|
1538
|
-
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1539
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1540
|
-
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
1541
|
-
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
1542
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1543
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1544
|
-
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
1545
|
-
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1546
|
-
-1 * rewardCoinDecimal
|
|
1547
|
-
);
|
|
1548
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1549
|
-
const claimedRewardAmount = BigNumber(
|
|
1550
|
-
parsedSpoolRewardPoolData.claimedRewards
|
|
1551
|
-
);
|
|
1552
|
-
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1553
|
-
-1 * rewardCoinDecimal
|
|
1554
|
-
);
|
|
1555
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1556
|
-
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1557
|
-
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
1558
|
-
if (parsedSpoolData.maxPoint <= parsedSpoolData.distributedPoint || parsedSpoolData.pointPerPeriod === 0) {
|
|
1559
|
-
rewardRate = Infinity;
|
|
1560
|
-
}
|
|
1561
|
-
return {
|
|
1562
|
-
rewardApr: rewardRate,
|
|
1563
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1564
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1565
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
1566
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1567
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1568
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1569
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1570
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1571
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1572
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1573
|
-
};
|
|
1574
|
-
};
|
|
1575
|
-
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
1576
|
-
return {
|
|
1577
|
-
pointType: normalizeStructTag(
|
|
1578
|
-
originBorrowIncentivePoolPointData.point_type.name
|
|
1579
|
-
),
|
|
1580
|
-
distributedPointPerPeriod: Number(
|
|
1581
|
-
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
1582
|
-
),
|
|
1583
|
-
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
1584
|
-
distributedPoint: Number(
|
|
1585
|
-
originBorrowIncentivePoolPointData.distributed_point
|
|
1586
|
-
),
|
|
1587
|
-
points: Number(originBorrowIncentivePoolPointData.points),
|
|
1588
|
-
index: Number(originBorrowIncentivePoolPointData.index),
|
|
1589
|
-
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
1590
|
-
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
1591
|
-
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update),
|
|
1592
|
-
createdAt: Number(originBorrowIncentivePoolPointData.created_at)
|
|
1593
|
-
};
|
|
1594
|
-
};
|
|
1595
|
-
var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
|
|
1596
|
-
return {
|
|
1597
|
-
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
1598
|
-
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
1599
|
-
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
1600
|
-
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
1601
|
-
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
1602
|
-
(acc, point) => {
|
|
1603
|
-
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
1604
|
-
const name = utils.parseSCoinTypeNameToMarketCoinName(
|
|
1605
|
-
parseStructTag(parsed.pointType).name.toLowerCase()
|
|
1606
|
-
);
|
|
1607
|
-
acc[name] = parsed;
|
|
1608
|
-
return acc;
|
|
1590
|
+
// src/models/scallopAddress.ts
|
|
1591
|
+
import axios from "axios";
|
|
1592
|
+
var EMPTY_ADDRESSES = {
|
|
1593
|
+
core: {
|
|
1594
|
+
version: "",
|
|
1595
|
+
versionCap: "",
|
|
1596
|
+
object: "",
|
|
1597
|
+
market: "",
|
|
1598
|
+
adminCap: "",
|
|
1599
|
+
coinDecimalsRegistry: "",
|
|
1600
|
+
obligationAccessStore: "",
|
|
1601
|
+
coins: {
|
|
1602
|
+
cetus: {
|
|
1603
|
+
id: "",
|
|
1604
|
+
metaData: "",
|
|
1605
|
+
treasury: "",
|
|
1606
|
+
oracle: {
|
|
1607
|
+
supra: "",
|
|
1608
|
+
switchboard: "",
|
|
1609
|
+
pyth: {
|
|
1610
|
+
feed: "",
|
|
1611
|
+
feedObject: ""
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1609
1614
|
},
|
|
1610
|
-
{
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
const rewardValueForYear = BigNumber(rewardPerSec).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1649
|
-
const weightScale = BigNumber(1e12);
|
|
1650
|
-
const rewardRate = rewardValueForYear.multipliedBy(
|
|
1651
|
-
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1652
|
-
weightScale
|
|
1653
|
-
)
|
|
1654
|
-
).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
|
|
1655
|
-
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1656
|
-
weightScale
|
|
1657
|
-
)
|
|
1658
|
-
).dividedBy(weightedStakedValue).toNumber() : Infinity;
|
|
1659
|
-
return {
|
|
1660
|
-
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1661
|
-
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1662
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
1663
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1664
|
-
baseWeight: baseWeight.toNumber(),
|
|
1665
|
-
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
1666
|
-
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
1667
|
-
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
1668
|
-
rewardApr: rewardRate,
|
|
1669
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1670
|
-
};
|
|
1671
|
-
};
|
|
1672
|
-
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
1673
|
-
return {
|
|
1674
|
-
pointType: normalizeStructTag(
|
|
1675
|
-
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
1676
|
-
),
|
|
1677
|
-
weightedAmount: Number(
|
|
1678
|
-
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
1679
|
-
),
|
|
1680
|
-
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
1681
|
-
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
1682
|
-
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
1683
|
-
};
|
|
1684
|
-
};
|
|
1685
|
-
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
1686
|
-
return {
|
|
1687
|
-
poolType: normalizeStructTag(
|
|
1688
|
-
originBorrowIncentiveAccountData.pool_type.name
|
|
1689
|
-
),
|
|
1690
|
-
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
1691
|
-
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
1692
|
-
(acc, point) => {
|
|
1693
|
-
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
1694
|
-
const name = parseStructTag(
|
|
1695
|
-
parsed.pointType
|
|
1696
|
-
).name.toLowerCase();
|
|
1697
|
-
acc[name] = parsed;
|
|
1698
|
-
return acc;
|
|
1615
|
+
wapt: {
|
|
1616
|
+
id: "",
|
|
1617
|
+
metaData: "",
|
|
1618
|
+
treasury: "",
|
|
1619
|
+
oracle: {
|
|
1620
|
+
supra: "",
|
|
1621
|
+
switchboard: "",
|
|
1622
|
+
pyth: {
|
|
1623
|
+
feed: "",
|
|
1624
|
+
feedObject: ""
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
},
|
|
1628
|
+
wsol: {
|
|
1629
|
+
id: "",
|
|
1630
|
+
metaData: "",
|
|
1631
|
+
treasury: "",
|
|
1632
|
+
oracle: {
|
|
1633
|
+
supra: "",
|
|
1634
|
+
switchboard: "",
|
|
1635
|
+
pyth: {
|
|
1636
|
+
feed: "",
|
|
1637
|
+
feedObject: ""
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
},
|
|
1641
|
+
wbtc: {
|
|
1642
|
+
id: "",
|
|
1643
|
+
metaData: "",
|
|
1644
|
+
treasury: "",
|
|
1645
|
+
oracle: {
|
|
1646
|
+
supra: "",
|
|
1647
|
+
switchboard: "",
|
|
1648
|
+
pyth: {
|
|
1649
|
+
feed: "",
|
|
1650
|
+
feedObject: ""
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1699
1653
|
},
|
|
1700
|
-
{
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
}
|
|
1711
|
-
var estimatedFactor = (amount, scaleStep, type) => {
|
|
1712
|
-
const amountOfDigits = Math.max(
|
|
1713
|
-
1,
|
|
1714
|
-
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
1715
|
-
);
|
|
1716
|
-
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
1717
|
-
let adjustFactor = Math.pow(10, -adjustScale);
|
|
1718
|
-
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
1719
|
-
return adjustFactor;
|
|
1720
|
-
};
|
|
1721
|
-
|
|
1722
|
-
// src/utils/util.ts
|
|
1723
|
-
var COIN_SET = Array.from(
|
|
1724
|
-
/* @__PURE__ */ new Set([
|
|
1725
|
-
...SUPPORT_POOLS,
|
|
1726
|
-
...SUPPORT_COLLATERALS,
|
|
1727
|
-
...SUPPORT_SPOOLS_REWARDS,
|
|
1728
|
-
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
1729
|
-
...SUPPORT_SCOIN
|
|
1730
|
-
])
|
|
1731
|
-
);
|
|
1732
|
-
var isMarketCoin = (coinName) => {
|
|
1733
|
-
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1734
|
-
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
1735
|
-
};
|
|
1736
|
-
var isSuiBridgeAsset = (coinName) => {
|
|
1737
|
-
return SUPPORT_SUI_BRIDGE.includes(coinName);
|
|
1738
|
-
};
|
|
1739
|
-
var isWormholeAsset = (coinName) => {
|
|
1740
|
-
return SUPPORT_WORMHOLE.includes(coinName);
|
|
1741
|
-
};
|
|
1742
|
-
var parseAssetSymbol = (coinName) => {
|
|
1743
|
-
if (isWormholeAsset(coinName)) {
|
|
1744
|
-
return `w${coinName.slice(1).toUpperCase()}`;
|
|
1745
|
-
}
|
|
1746
|
-
if (isSuiBridgeAsset(coinName)) {
|
|
1747
|
-
return `sb${coinName.slice(2).toUpperCase()}`;
|
|
1748
|
-
}
|
|
1749
|
-
if (isMarketCoin(coinName)) {
|
|
1750
|
-
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
1751
|
-
return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
|
|
1752
|
-
}
|
|
1753
|
-
switch (coinName) {
|
|
1754
|
-
case "afsui":
|
|
1755
|
-
return "afSUI";
|
|
1756
|
-
case "hasui":
|
|
1757
|
-
return "haSUI";
|
|
1758
|
-
case "vsui":
|
|
1759
|
-
return "vSUI";
|
|
1760
|
-
default:
|
|
1761
|
-
return coinName.toUpperCase();
|
|
1762
|
-
}
|
|
1763
|
-
};
|
|
1764
|
-
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
1765
|
-
const assetCoinNames = COIN_SET;
|
|
1766
|
-
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
1767
|
-
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
1768
|
-
});
|
|
1769
|
-
if (assetCoinName) {
|
|
1770
|
-
const price = feed.price.price * 10 ** feed.price.expo;
|
|
1771
|
-
return {
|
|
1772
|
-
coinName: assetCoinName,
|
|
1773
|
-
price,
|
|
1774
|
-
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
1775
|
-
};
|
|
1776
|
-
} else {
|
|
1777
|
-
throw new Error("Invalid feed id");
|
|
1778
|
-
}
|
|
1779
|
-
};
|
|
1780
|
-
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
1781
|
-
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1782
|
-
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
1783
|
-
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
1784
|
-
if (unlockDate.getUTCHours() >= 0) {
|
|
1785
|
-
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
1786
|
-
}
|
|
1787
|
-
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1788
|
-
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
1789
|
-
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
1790
|
-
}
|
|
1791
|
-
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
1792
|
-
};
|
|
1793
|
-
var partitionArray = (array, chunkSize) => {
|
|
1794
|
-
const result = [];
|
|
1795
|
-
for (let i = 0; i < array.length; i += chunkSize) {
|
|
1796
|
-
result.push(array.slice(i, i + chunkSize));
|
|
1797
|
-
}
|
|
1798
|
-
return result;
|
|
1799
|
-
};
|
|
1800
|
-
|
|
1801
|
-
// src/utils/tokenBucket.ts
|
|
1802
|
-
var TokenBucket = class {
|
|
1803
|
-
constructor(tokensPerInterval, intervalInMs) {
|
|
1804
|
-
this.tokensPerInterval = tokensPerInterval;
|
|
1805
|
-
this.interval = intervalInMs;
|
|
1806
|
-
this.tokens = tokensPerInterval;
|
|
1807
|
-
this.lastRefill = Date.now();
|
|
1808
|
-
}
|
|
1809
|
-
refill() {
|
|
1810
|
-
const now = Date.now();
|
|
1811
|
-
const elapsed = now - this.lastRefill;
|
|
1812
|
-
if (elapsed >= this.interval) {
|
|
1813
|
-
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1814
|
-
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1815
|
-
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
removeTokens(count) {
|
|
1819
|
-
this.refill();
|
|
1820
|
-
if (this.tokens >= count) {
|
|
1821
|
-
this.tokens -= count;
|
|
1822
|
-
return true;
|
|
1823
|
-
}
|
|
1824
|
-
return false;
|
|
1825
|
-
}
|
|
1826
|
-
};
|
|
1827
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
|
|
1828
|
-
let retries = 0;
|
|
1829
|
-
const tryRequest = async () => {
|
|
1830
|
-
if (tokenBucket.removeTokens(1)) {
|
|
1831
|
-
const result = await fn();
|
|
1832
|
-
return result;
|
|
1833
|
-
} else if (retries < maxRetries) {
|
|
1834
|
-
retries++;
|
|
1835
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1836
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1837
|
-
return tryRequest();
|
|
1838
|
-
} else {
|
|
1839
|
-
console.error("Maximum retries reached");
|
|
1840
|
-
return null;
|
|
1841
|
-
}
|
|
1842
|
-
};
|
|
1843
|
-
return tryRequest();
|
|
1844
|
-
};
|
|
1845
|
-
|
|
1846
|
-
// src/utils/indexer.ts
|
|
1847
|
-
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
1848
|
-
const lastArgs = args[args.length - 1];
|
|
1849
|
-
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
1850
|
-
try {
|
|
1851
|
-
return await method.apply(context, args);
|
|
1852
|
-
} catch (e) {
|
|
1853
|
-
console.warn(`Indexer requests failed: ${e}. Retrying without indexer..`);
|
|
1854
|
-
return await method.apply(context, [
|
|
1855
|
-
...args.slice(0, -1),
|
|
1856
|
-
{
|
|
1857
|
-
...lastArgs,
|
|
1858
|
-
indexer: false
|
|
1654
|
+
weth: {
|
|
1655
|
+
id: "",
|
|
1656
|
+
metaData: "",
|
|
1657
|
+
treasury: "",
|
|
1658
|
+
oracle: {
|
|
1659
|
+
supra: "",
|
|
1660
|
+
switchboard: "",
|
|
1661
|
+
pyth: {
|
|
1662
|
+
feed: "",
|
|
1663
|
+
feedObject: ""
|
|
1664
|
+
}
|
|
1859
1665
|
}
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1666
|
+
},
|
|
1667
|
+
wusdc: {
|
|
1668
|
+
id: "",
|
|
1669
|
+
metaData: "",
|
|
1670
|
+
treasury: "",
|
|
1671
|
+
oracle: {
|
|
1672
|
+
supra: "",
|
|
1673
|
+
switchboard: "",
|
|
1674
|
+
pyth: {
|
|
1675
|
+
feed: "",
|
|
1676
|
+
feedObject: ""
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
},
|
|
1680
|
+
wusdt: {
|
|
1681
|
+
id: "",
|
|
1682
|
+
metaData: "",
|
|
1683
|
+
treasury: "",
|
|
1684
|
+
oracle: {
|
|
1685
|
+
supra: "",
|
|
1686
|
+
switchboard: "",
|
|
1687
|
+
pyth: {
|
|
1688
|
+
feed: "",
|
|
1689
|
+
feedObject: ""
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
},
|
|
1693
|
+
sui: {
|
|
1694
|
+
id: "",
|
|
1695
|
+
metaData: "",
|
|
1696
|
+
treasury: "",
|
|
1697
|
+
oracle: {
|
|
1698
|
+
supra: "",
|
|
1699
|
+
switchboard: "",
|
|
1700
|
+
pyth: {
|
|
1701
|
+
feed: "",
|
|
1702
|
+
feedObject: ""
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
},
|
|
1706
|
+
afsui: {
|
|
1707
|
+
id: "",
|
|
1708
|
+
metaData: "",
|
|
1709
|
+
treasury: "",
|
|
1710
|
+
oracle: {
|
|
1711
|
+
supra: "",
|
|
1712
|
+
switchboard: "",
|
|
1713
|
+
pyth: {
|
|
1714
|
+
feed: "",
|
|
1715
|
+
feedObject: ""
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
},
|
|
1719
|
+
hasui: {
|
|
1720
|
+
id: "",
|
|
1721
|
+
metaData: "",
|
|
1722
|
+
treasury: "",
|
|
1723
|
+
oracle: {
|
|
1724
|
+
supra: "",
|
|
1725
|
+
switchboard: "",
|
|
1726
|
+
pyth: {
|
|
1727
|
+
feed: "",
|
|
1728
|
+
feedObject: ""
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
},
|
|
1732
|
+
vsui: {
|
|
1733
|
+
id: "",
|
|
1734
|
+
metaData: "",
|
|
1735
|
+
treasury: "",
|
|
1736
|
+
oracle: {
|
|
1737
|
+
supra: "",
|
|
1738
|
+
switchboard: "",
|
|
1739
|
+
pyth: {
|
|
1740
|
+
feed: "",
|
|
1741
|
+
feedObject: ""
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
},
|
|
1745
|
+
sca: {
|
|
1746
|
+
id: "",
|
|
1747
|
+
metaData: "",
|
|
1748
|
+
treasury: "",
|
|
1749
|
+
oracle: {
|
|
1750
|
+
supra: "",
|
|
1751
|
+
switchboard: "",
|
|
1752
|
+
pyth: {
|
|
1753
|
+
feed: "",
|
|
1754
|
+
feedObject: ""
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
},
|
|
1759
|
+
oracles: {
|
|
1760
|
+
xOracle: "",
|
|
1761
|
+
xOracleCap: "",
|
|
1762
|
+
supra: { registry: "", registryCap: "", holder: "" },
|
|
1763
|
+
switchboard: { registry: "", registryCap: "" },
|
|
1764
|
+
pyth: {
|
|
1765
|
+
registry: "",
|
|
1766
|
+
registryCap: "",
|
|
1767
|
+
state: "",
|
|
1768
|
+
wormhole: "",
|
|
1769
|
+
wormholeState: ""
|
|
1770
|
+
}
|
|
1771
|
+
},
|
|
1772
|
+
packages: {
|
|
1773
|
+
coinDecimalsRegistry: {
|
|
1774
|
+
id: "",
|
|
1775
|
+
upgradeCap: ""
|
|
1776
|
+
},
|
|
1777
|
+
math: {
|
|
1778
|
+
id: "",
|
|
1779
|
+
upgradeCap: ""
|
|
1780
|
+
},
|
|
1781
|
+
whitelist: {
|
|
1782
|
+
id: "",
|
|
1783
|
+
upgradeCap: ""
|
|
1784
|
+
},
|
|
1785
|
+
x: {
|
|
1786
|
+
id: "",
|
|
1787
|
+
upgradeCap: ""
|
|
1788
|
+
},
|
|
1789
|
+
protocol: {
|
|
1790
|
+
id: "",
|
|
1791
|
+
upgradeCap: ""
|
|
1792
|
+
},
|
|
1793
|
+
protocolWhitelist: {
|
|
1794
|
+
id: "",
|
|
1795
|
+
upgradeCap: ""
|
|
1796
|
+
},
|
|
1797
|
+
query: {
|
|
1798
|
+
id: "",
|
|
1799
|
+
upgradeCap: ""
|
|
1800
|
+
},
|
|
1801
|
+
supra: { id: "", upgradeCap: "" },
|
|
1802
|
+
pyth: {
|
|
1803
|
+
id: "",
|
|
1804
|
+
upgradeCap: ""
|
|
1805
|
+
},
|
|
1806
|
+
switchboard: { id: "", upgradeCap: "" },
|
|
1807
|
+
xOracle: {
|
|
1808
|
+
id: "",
|
|
1809
|
+
upgradeCap: ""
|
|
1810
|
+
},
|
|
1811
|
+
testCoin: { id: "", upgradeCap: "" }
|
|
1898
1812
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1813
|
+
},
|
|
1814
|
+
spool: {
|
|
1815
|
+
id: "",
|
|
1816
|
+
adminCap: "",
|
|
1817
|
+
object: "",
|
|
1818
|
+
pools: {
|
|
1819
|
+
sweth: {
|
|
1820
|
+
id: "",
|
|
1821
|
+
rewardPoolId: ""
|
|
1822
|
+
},
|
|
1823
|
+
ssui: {
|
|
1824
|
+
id: "",
|
|
1825
|
+
rewardPoolId: ""
|
|
1826
|
+
},
|
|
1827
|
+
swusdc: {
|
|
1828
|
+
id: "",
|
|
1829
|
+
rewardPoolId: ""
|
|
1830
|
+
},
|
|
1831
|
+
swusdt: {
|
|
1832
|
+
id: "",
|
|
1833
|
+
rewardPoolId: ""
|
|
1834
|
+
},
|
|
1835
|
+
scetus: {
|
|
1836
|
+
id: "",
|
|
1837
|
+
rewardPoolId: ""
|
|
1838
|
+
},
|
|
1839
|
+
safsui: {
|
|
1840
|
+
id: "",
|
|
1841
|
+
rewardPoolId: ""
|
|
1842
|
+
},
|
|
1843
|
+
shasui: {
|
|
1844
|
+
id: "",
|
|
1845
|
+
rewardPoolId: ""
|
|
1846
|
+
},
|
|
1847
|
+
svsui: {
|
|
1848
|
+
id: "",
|
|
1849
|
+
rewardPoolId: ""
|
|
1850
|
+
}
|
|
1851
|
+
},
|
|
1852
|
+
config: ""
|
|
1853
|
+
},
|
|
1854
|
+
borrowIncentive: {
|
|
1855
|
+
id: "",
|
|
1856
|
+
adminCap: "",
|
|
1857
|
+
object: "",
|
|
1858
|
+
query: "",
|
|
1859
|
+
incentivePools: "",
|
|
1860
|
+
incentiveAccounts: "",
|
|
1861
|
+
config: ""
|
|
1862
|
+
},
|
|
1863
|
+
vesca: {
|
|
1864
|
+
id: "",
|
|
1865
|
+
object: "",
|
|
1866
|
+
adminCap: "",
|
|
1867
|
+
tableId: "",
|
|
1868
|
+
table: "",
|
|
1869
|
+
treasury: "",
|
|
1870
|
+
config: ""
|
|
1871
|
+
},
|
|
1872
|
+
referral: {
|
|
1873
|
+
id: "",
|
|
1874
|
+
version: "",
|
|
1875
|
+
object: "",
|
|
1876
|
+
adminCap: "",
|
|
1877
|
+
referralBindings: "",
|
|
1878
|
+
bindingTableId: "",
|
|
1879
|
+
referralRevenuePool: "",
|
|
1880
|
+
revenueTableId: "",
|
|
1881
|
+
referralTiers: "",
|
|
1882
|
+
tiersTableId: "",
|
|
1883
|
+
authorizedWitnessList: ""
|
|
1884
|
+
},
|
|
1885
|
+
loyaltyProgram: {
|
|
1886
|
+
id: "",
|
|
1887
|
+
object: "",
|
|
1888
|
+
rewardPool: "",
|
|
1889
|
+
userRewardTableId: ""
|
|
1890
|
+
},
|
|
1891
|
+
scoin: {
|
|
1892
|
+
id: "",
|
|
1893
|
+
coins: {
|
|
1894
|
+
ssui: {
|
|
1895
|
+
coinType: "",
|
|
1896
|
+
treasury: ""
|
|
1897
|
+
},
|
|
1898
|
+
scetus: {
|
|
1899
|
+
coinType: "",
|
|
1900
|
+
treasury: ""
|
|
1901
|
+
},
|
|
1902
|
+
ssca: {
|
|
1903
|
+
coinType: "",
|
|
1904
|
+
treasury: ""
|
|
1905
|
+
},
|
|
1906
|
+
swusdc: {
|
|
1907
|
+
coinType: "",
|
|
1908
|
+
treasury: ""
|
|
1909
|
+
},
|
|
1910
|
+
swusdt: {
|
|
1911
|
+
coinType: "",
|
|
1912
|
+
treasury: ""
|
|
1913
|
+
},
|
|
1914
|
+
sweth: {
|
|
1915
|
+
coinType: "",
|
|
1916
|
+
treasury: ""
|
|
1917
|
+
},
|
|
1918
|
+
safsui: {
|
|
1919
|
+
coinType: "",
|
|
1920
|
+
treasury: ""
|
|
1921
|
+
},
|
|
1922
|
+
shasui: {
|
|
1923
|
+
coinType: "",
|
|
1924
|
+
treasury: ""
|
|
1925
|
+
},
|
|
1926
|
+
svsui: {
|
|
1927
|
+
coinType: "",
|
|
1928
|
+
treasury: ""
|
|
1978
1929
|
}
|
|
1979
|
-
}
|
|
1980
|
-
return query;
|
|
1930
|
+
}
|
|
1981
1931
|
}
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
);
|
|
1995
|
-
}
|
|
1932
|
+
};
|
|
1933
|
+
var ScallopAddress = class {
|
|
1934
|
+
constructor(params, instance) {
|
|
1935
|
+
const { id, auth, network, forceInterface } = params;
|
|
1936
|
+
this.cache = instance?.cache ?? new ScallopCache({});
|
|
1937
|
+
this._requestClient = axios.create({
|
|
1938
|
+
baseURL: API_BASE_URL,
|
|
1939
|
+
headers: {
|
|
1940
|
+
"Content-Type": "application/json",
|
|
1941
|
+
Accept: "application/json"
|
|
1942
|
+
},
|
|
1943
|
+
timeout: 8e3
|
|
1996
1944
|
});
|
|
1945
|
+
if (auth)
|
|
1946
|
+
this._auth = auth;
|
|
1947
|
+
this._id = id;
|
|
1948
|
+
this._network = network ?? "mainnet";
|
|
1949
|
+
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
1950
|
+
if (USE_TEST_ADDRESS)
|
|
1951
|
+
this._currentAddresses = TEST_ADDRESSES;
|
|
1952
|
+
if (forceInterface) {
|
|
1953
|
+
for (const [network2, addresses] of Object.entries(
|
|
1954
|
+
forceInterface
|
|
1955
|
+
)) {
|
|
1956
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
1957
|
+
if (network2 === this._network)
|
|
1958
|
+
this._currentAddresses = addresses;
|
|
1959
|
+
this._addressesMap.set(network2, addresses);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1997
1963
|
}
|
|
1998
1964
|
/**
|
|
1999
|
-
*
|
|
2000
|
-
*
|
|
2001
|
-
* @
|
|
2002
|
-
* @returns Promise<SuiObjectResponse>
|
|
1965
|
+
* Get addresses API id.
|
|
1966
|
+
*
|
|
1967
|
+
* @return The addresses API id.
|
|
2003
1968
|
*/
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
...options,
|
|
2007
|
-
showOwner: true,
|
|
2008
|
-
showContent: true
|
|
2009
|
-
};
|
|
2010
|
-
return this.queryClient.fetchQuery({
|
|
2011
|
-
retry: this.retryFn,
|
|
2012
|
-
retryDelay: 1e3,
|
|
2013
|
-
queryKey: queryKeys.rpc.getObject(objectId, options),
|
|
2014
|
-
queryFn: async () => {
|
|
2015
|
-
return await callWithRateLimit(
|
|
2016
|
-
this.tokenBucket,
|
|
2017
|
-
async () => await this.client.getObject({
|
|
2018
|
-
id: objectId,
|
|
2019
|
-
options
|
|
2020
|
-
})
|
|
2021
|
-
);
|
|
2022
|
-
}
|
|
2023
|
-
});
|
|
1969
|
+
getId() {
|
|
1970
|
+
return this._id || void 0;
|
|
2024
1971
|
}
|
|
2025
1972
|
/**
|
|
2026
|
-
*
|
|
2027
|
-
*
|
|
2028
|
-
* @
|
|
1973
|
+
* Get the address at the provided path.
|
|
1974
|
+
*
|
|
1975
|
+
* @param path - The path of the address to get.
|
|
1976
|
+
* @return The address at the provided path.
|
|
2029
1977
|
*/
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
this.walletAddress,
|
|
2041
|
-
options
|
|
2042
|
-
),
|
|
2043
|
-
queryFn: async () => {
|
|
2044
|
-
const results = await callWithRateLimit(
|
|
2045
|
-
this.tokenBucket,
|
|
2046
|
-
async () => await this.suiKit.getObjects(objectIds, options)
|
|
2047
|
-
);
|
|
2048
|
-
if (results) {
|
|
2049
|
-
results.forEach((result) => {
|
|
2050
|
-
this.queryClient.setQueriesData(
|
|
2051
|
-
{
|
|
2052
|
-
exact: false,
|
|
2053
|
-
queryKey: queryKeys.rpc.getObject(result.objectId, options)
|
|
2054
|
-
},
|
|
2055
|
-
{
|
|
2056
|
-
data: result,
|
|
2057
|
-
error: null
|
|
2058
|
-
},
|
|
2059
|
-
{
|
|
2060
|
-
updatedAt: Date.now()
|
|
2061
|
-
}
|
|
2062
|
-
);
|
|
2063
|
-
});
|
|
2064
|
-
}
|
|
2065
|
-
return results;
|
|
2066
|
-
}
|
|
2067
|
-
});
|
|
1978
|
+
get(path) {
|
|
1979
|
+
if (this._currentAddresses) {
|
|
1980
|
+
const value = path.split(".").reduce(
|
|
1981
|
+
(nestedAddressObj, key) => typeof nestedAddressObj === "object" ? nestedAddressObj[key] : nestedAddressObj,
|
|
1982
|
+
this._currentAddresses
|
|
1983
|
+
);
|
|
1984
|
+
return value || void 0;
|
|
1985
|
+
} else {
|
|
1986
|
+
return void 0;
|
|
1987
|
+
}
|
|
2068
1988
|
}
|
|
2069
1989
|
/**
|
|
2070
|
-
*
|
|
2071
|
-
*
|
|
2072
|
-
* @
|
|
1990
|
+
* Sets the address for the specified path, it does not interact with the API.
|
|
1991
|
+
*
|
|
1992
|
+
* @param path - The path of the address to set.
|
|
1993
|
+
* @param address - The address be setted to the tartget path.
|
|
1994
|
+
* @return The addresses.
|
|
2073
1995
|
*/
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
async () => await this.client.getOwnedObjects(input)
|
|
2083
|
-
);
|
|
2084
|
-
if (results && results.data.length > 0) {
|
|
2085
|
-
results.data.filter(
|
|
2086
|
-
(result) => !!result.data
|
|
2087
|
-
).forEach((result) => {
|
|
2088
|
-
this.queryClient.setQueriesData(
|
|
2089
|
-
{
|
|
2090
|
-
exact: false,
|
|
2091
|
-
queryKey: queryKeys.rpc.getObject(
|
|
2092
|
-
result.data.objectId,
|
|
2093
|
-
input.options ?? {}
|
|
2094
|
-
)
|
|
2095
|
-
},
|
|
2096
|
-
{
|
|
2097
|
-
data: result.data,
|
|
2098
|
-
error: null
|
|
2099
|
-
},
|
|
2100
|
-
{
|
|
2101
|
-
updatedAt: Date.now()
|
|
2102
|
-
}
|
|
2103
|
-
);
|
|
2104
|
-
});
|
|
1996
|
+
set(path, address) {
|
|
1997
|
+
if (this._currentAddresses) {
|
|
1998
|
+
const keys = path.split(".");
|
|
1999
|
+
keys.reduce((nestedAddressObj, key, index) => {
|
|
2000
|
+
if (index === keys.length - 1) {
|
|
2001
|
+
nestedAddressObj[key] = address;
|
|
2002
|
+
} else {
|
|
2003
|
+
return nestedAddressObj[key];
|
|
2105
2004
|
}
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
}
|
|
2110
|
-
async queryGetDynamicFields(input) {
|
|
2111
|
-
return this.queryClient.fetchQuery({
|
|
2112
|
-
retry: this.retryFn,
|
|
2113
|
-
retryDelay: 1e3,
|
|
2114
|
-
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
2115
|
-
queryFn: async () => {
|
|
2116
|
-
return await callWithRateLimit(
|
|
2117
|
-
this.tokenBucket,
|
|
2118
|
-
async () => await this.client.getDynamicFields(input)
|
|
2119
|
-
);
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2005
|
+
}, this._currentAddresses);
|
|
2006
|
+
}
|
|
2007
|
+
return this._currentAddresses;
|
|
2122
2008
|
}
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
exact: false,
|
|
2137
|
-
queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
|
|
2138
|
-
showContent: true,
|
|
2139
|
-
showOwner: true
|
|
2140
|
-
})
|
|
2141
|
-
},
|
|
2142
|
-
{
|
|
2143
|
-
data: result.data,
|
|
2144
|
-
error: null
|
|
2145
|
-
},
|
|
2146
|
-
{
|
|
2147
|
-
updatedAt: Date.now()
|
|
2148
|
-
}
|
|
2149
|
-
);
|
|
2150
|
-
}
|
|
2151
|
-
return result;
|
|
2152
|
-
}
|
|
2153
|
-
});
|
|
2009
|
+
/**
|
|
2010
|
+
* Synchronize the specified network addresses from the addresses map to the
|
|
2011
|
+
* current addresses and change the default network to specified network.
|
|
2012
|
+
*
|
|
2013
|
+
* @param network - Specifies which network's addresses you want to get.
|
|
2014
|
+
* @return Current addresses.
|
|
2015
|
+
*/
|
|
2016
|
+
switchCurrentAddresses(network) {
|
|
2017
|
+
if (this._addressesMap.has(network)) {
|
|
2018
|
+
this._currentAddresses = this._addressesMap.get(network);
|
|
2019
|
+
this._network = network;
|
|
2020
|
+
}
|
|
2021
|
+
return this._currentAddresses;
|
|
2154
2022
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
const balances = allBalances.reduce(
|
|
2168
|
-
(acc, coinBalance) => {
|
|
2169
|
-
if (coinBalance.totalBalance !== "0") {
|
|
2170
|
-
acc[normalizeStructTag2(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
2171
|
-
}
|
|
2172
|
-
return acc;
|
|
2173
|
-
},
|
|
2174
|
-
{}
|
|
2175
|
-
);
|
|
2176
|
-
return balances;
|
|
2177
|
-
}
|
|
2178
|
-
});
|
|
2023
|
+
/**
|
|
2024
|
+
* Get the addresses, If `network` is not provided, returns the current
|
|
2025
|
+
* addresses or the default network addresses in the addresses map.
|
|
2026
|
+
*
|
|
2027
|
+
* @param network - Specifies which network's addresses you want to get.
|
|
2028
|
+
*/
|
|
2029
|
+
getAddresses(network) {
|
|
2030
|
+
if (network) {
|
|
2031
|
+
return this._addressesMap.get(network);
|
|
2032
|
+
} else {
|
|
2033
|
+
return this._currentAddresses ?? this._addressesMap.get(this._network);
|
|
2034
|
+
}
|
|
2179
2035
|
}
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2036
|
+
/**
|
|
2037
|
+
* Set the addresses into addresses map. If the specified network is the same
|
|
2038
|
+
* as the current network, the current addresses will be updated at the same time.
|
|
2039
|
+
*
|
|
2040
|
+
* @param addresses - The addresses be setted to the tartget network.
|
|
2041
|
+
* @param network - Specifies which network's addresses you want to set.
|
|
2042
|
+
* @return The addresses.
|
|
2043
|
+
*/
|
|
2044
|
+
setAddresses(addresses, network) {
|
|
2045
|
+
const targetNetwork = network || this._network;
|
|
2046
|
+
if (targetNetwork === this._network)
|
|
2047
|
+
this._currentAddresses = addresses;
|
|
2048
|
+
this._addressesMap.set(targetNetwork, addresses);
|
|
2184
2049
|
}
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
metaData: "",
|
|
2228
|
-
treasury: "",
|
|
2229
|
-
oracle: {
|
|
2230
|
-
supra: "",
|
|
2231
|
-
switchboard: "",
|
|
2232
|
-
pyth: {
|
|
2233
|
-
feed: "",
|
|
2234
|
-
feedObject: ""
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2237
|
-
},
|
|
2238
|
-
wbtc: {
|
|
2239
|
-
id: "",
|
|
2240
|
-
metaData: "",
|
|
2241
|
-
treasury: "",
|
|
2242
|
-
oracle: {
|
|
2243
|
-
supra: "",
|
|
2244
|
-
switchboard: "",
|
|
2245
|
-
pyth: {
|
|
2246
|
-
feed: "",
|
|
2247
|
-
feedObject: ""
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
},
|
|
2251
|
-
weth: {
|
|
2252
|
-
id: "",
|
|
2253
|
-
metaData: "",
|
|
2254
|
-
treasury: "",
|
|
2255
|
-
oracle: {
|
|
2256
|
-
supra: "",
|
|
2257
|
-
switchboard: "",
|
|
2258
|
-
pyth: {
|
|
2259
|
-
feed: "",
|
|
2260
|
-
feedObject: ""
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
},
|
|
2264
|
-
wusdc: {
|
|
2265
|
-
id: "",
|
|
2266
|
-
metaData: "",
|
|
2267
|
-
treasury: "",
|
|
2268
|
-
oracle: {
|
|
2269
|
-
supra: "",
|
|
2270
|
-
switchboard: "",
|
|
2271
|
-
pyth: {
|
|
2272
|
-
feed: "",
|
|
2273
|
-
feedObject: ""
|
|
2050
|
+
/**
|
|
2051
|
+
* Get all addresses.
|
|
2052
|
+
*
|
|
2053
|
+
* @return All addresses.
|
|
2054
|
+
*/
|
|
2055
|
+
getAllAddresses() {
|
|
2056
|
+
return Object.fromEntries(this._addressesMap);
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Create a new addresses through the API and synchronize it back to the
|
|
2060
|
+
* instance.
|
|
2061
|
+
*
|
|
2062
|
+
* @description
|
|
2063
|
+
* If the `network` is not specified, the mainnet is used by default.
|
|
2064
|
+
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
2065
|
+
* all empty strings is created by default.
|
|
2066
|
+
*
|
|
2067
|
+
* This function only allows for one addresses to be input into a specific network
|
|
2068
|
+
* at a time, and does not provide an addresses map for setting addresses
|
|
2069
|
+
* across all networks at once.
|
|
2070
|
+
*
|
|
2071
|
+
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2072
|
+
* @param params.network - Specifies which network's addresses you want to set.
|
|
2073
|
+
* @param params.auth - The authentication API key.
|
|
2074
|
+
* @param params.memo - Add memo to the addresses created in the API.
|
|
2075
|
+
* @return All addresses.
|
|
2076
|
+
*/
|
|
2077
|
+
async create(params) {
|
|
2078
|
+
const { addresses, network, auth, memo } = params ?? {};
|
|
2079
|
+
const apiKey = auth || this._auth || void 0;
|
|
2080
|
+
const targetNetwork = network || this._network;
|
|
2081
|
+
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2082
|
+
if (apiKey !== void 0) {
|
|
2083
|
+
this._addressesMap.clear();
|
|
2084
|
+
this.setAddresses(targetAddresses, targetNetwork);
|
|
2085
|
+
const response = await this._requestClient.post(
|
|
2086
|
+
`/addresses`,
|
|
2087
|
+
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2088
|
+
{
|
|
2089
|
+
headers: {
|
|
2090
|
+
"Content-Type": "application/json",
|
|
2091
|
+
"api-key": auth || this._auth
|
|
2274
2092
|
}
|
|
2275
2093
|
}
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
feed: "",
|
|
2286
|
-
feedObject: ""
|
|
2094
|
+
);
|
|
2095
|
+
if (response.status === 201) {
|
|
2096
|
+
for (const [network2, addresses2] of Object.entries(
|
|
2097
|
+
response.data
|
|
2098
|
+
)) {
|
|
2099
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2100
|
+
if (network2 === this._network)
|
|
2101
|
+
this._currentAddresses = addresses2;
|
|
2102
|
+
this._addressesMap.set(network2, addresses2);
|
|
2287
2103
|
}
|
|
2288
2104
|
}
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2105
|
+
this._id = response.data.id;
|
|
2106
|
+
return this.getAllAddresses();
|
|
2107
|
+
} else {
|
|
2108
|
+
throw Error("Failed to create addresses.");
|
|
2109
|
+
}
|
|
2110
|
+
} else {
|
|
2111
|
+
throw Error("You don't have permission to access this request.");
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Read and synchronizes all addresses from the API into instance.
|
|
2116
|
+
*
|
|
2117
|
+
* @param id - The id of the addresses to get.
|
|
2118
|
+
* @return All addresses.
|
|
2119
|
+
*/
|
|
2120
|
+
async read(id) {
|
|
2121
|
+
const addressesId = id || this._id || void 0;
|
|
2122
|
+
if (addressesId !== void 0) {
|
|
2123
|
+
const response = await this.cache.queryClient.fetchQuery({
|
|
2124
|
+
queryKey: queryKeys.api.getAddresses(addressesId),
|
|
2125
|
+
queryFn: async () => {
|
|
2126
|
+
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
2127
|
+
headers: {
|
|
2128
|
+
"Content-Type": "application/json"
|
|
2129
|
+
}
|
|
2130
|
+
});
|
|
2301
2131
|
}
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
feed: "",
|
|
2312
|
-
feedObject: ""
|
|
2132
|
+
});
|
|
2133
|
+
if (response.status === 200) {
|
|
2134
|
+
for (const [network, addresses] of Object.entries(
|
|
2135
|
+
response.data
|
|
2136
|
+
)) {
|
|
2137
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network)) {
|
|
2138
|
+
if (network === this._network)
|
|
2139
|
+
this._currentAddresses = addresses;
|
|
2140
|
+
this._addressesMap.set(network, addresses);
|
|
2313
2141
|
}
|
|
2314
2142
|
}
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2143
|
+
this._id = response.data.id;
|
|
2144
|
+
return this.getAllAddresses();
|
|
2145
|
+
} else {
|
|
2146
|
+
throw Error("Failed to create addresses.");
|
|
2147
|
+
}
|
|
2148
|
+
} else {
|
|
2149
|
+
throw Error("Please provide API addresses id.");
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* Update the addresses through the API and synchronize it back to the
|
|
2154
|
+
* instance.
|
|
2155
|
+
*
|
|
2156
|
+
* @description
|
|
2157
|
+
* If the `network` is not specified, the mainnet is used by default.
|
|
2158
|
+
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
2159
|
+
* all empty strings is created by default.
|
|
2160
|
+
*
|
|
2161
|
+
* This function only allows for one addresses to be input into a specific network
|
|
2162
|
+
* at a time, and does not provide an addresses map for setting addresses
|
|
2163
|
+
* across all networks at once.
|
|
2164
|
+
*
|
|
2165
|
+
* @param params.id - The id of the addresses to update.
|
|
2166
|
+
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2167
|
+
* @param params.network - Specifies which network's addresses you want to set.
|
|
2168
|
+
* @param params.auth - The authentication api key.
|
|
2169
|
+
* @param params.memo - Add memo to the addresses created in the API.
|
|
2170
|
+
* @return All addresses.
|
|
2171
|
+
*/
|
|
2172
|
+
async update(params) {
|
|
2173
|
+
const { id, addresses, network, auth, memo } = params ?? {};
|
|
2174
|
+
const apiKey = auth || this._auth || void 0;
|
|
2175
|
+
const targetId = id || this._id || void 0;
|
|
2176
|
+
const targetNetwork = network || this._network;
|
|
2177
|
+
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2178
|
+
if (targetId === void 0)
|
|
2179
|
+
throw Error("Require specific addresses id to be updated.");
|
|
2180
|
+
if (apiKey !== void 0) {
|
|
2181
|
+
if (id !== this._id) {
|
|
2182
|
+
this._addressesMap.clear();
|
|
2183
|
+
}
|
|
2184
|
+
this.setAddresses(targetAddresses, targetNetwork);
|
|
2185
|
+
const response = await this._requestClient.put(
|
|
2186
|
+
`/addresses/${targetId}`,
|
|
2187
|
+
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2188
|
+
{
|
|
2189
|
+
headers: {
|
|
2190
|
+
"Content-Type": "application/json",
|
|
2191
|
+
"api-key": auth || this._auth
|
|
2326
2192
|
}
|
|
2327
2193
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
feed: "",
|
|
2338
|
-
feedObject: ""
|
|
2194
|
+
);
|
|
2195
|
+
if (response.status === 200) {
|
|
2196
|
+
for (const [network2, addresses2] of Object.entries(
|
|
2197
|
+
response.data
|
|
2198
|
+
)) {
|
|
2199
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2200
|
+
if (network2 === this._network)
|
|
2201
|
+
this._currentAddresses = addresses2;
|
|
2202
|
+
this._addressesMap.set(network2, addresses2);
|
|
2339
2203
|
}
|
|
2340
2204
|
}
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2205
|
+
this._id = response.data.id;
|
|
2206
|
+
return this.getAllAddresses();
|
|
2207
|
+
} else {
|
|
2208
|
+
throw Error("Failed to update addresses.");
|
|
2209
|
+
}
|
|
2210
|
+
} else {
|
|
2211
|
+
throw Error("You don't have permission to access this request.");
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
/**
|
|
2215
|
+
* Deletes all addresses of a specified id through the API and clear all
|
|
2216
|
+
* addresses in the instance.
|
|
2217
|
+
*
|
|
2218
|
+
* @param id - The id of the addresses to delete.
|
|
2219
|
+
* @param auth - The authentication API key.
|
|
2220
|
+
*/
|
|
2221
|
+
async delete(id, auth) {
|
|
2222
|
+
const apiKey = auth || this._auth || void 0;
|
|
2223
|
+
const targetId = id || this._id || void 0;
|
|
2224
|
+
if (targetId === void 0)
|
|
2225
|
+
throw Error("Require specific addresses id to be deleted.");
|
|
2226
|
+
if (apiKey !== void 0) {
|
|
2227
|
+
const response = await this._requestClient.delete(
|
|
2228
|
+
`/addresses/${targetId}`,
|
|
2229
|
+
{
|
|
2230
|
+
headers: {
|
|
2231
|
+
"Content-Type": "application/json",
|
|
2232
|
+
"api-key": auth || this._auth
|
|
2352
2233
|
}
|
|
2353
2234
|
}
|
|
2235
|
+
);
|
|
2236
|
+
if (response.status === 200) {
|
|
2237
|
+
this._id = void 0;
|
|
2238
|
+
this._currentAddresses = void 0;
|
|
2239
|
+
this._addressesMap.clear();
|
|
2240
|
+
} else {
|
|
2241
|
+
throw Error("Failed to delete addresses.");
|
|
2354
2242
|
}
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
|
-
xOracle: "",
|
|
2358
|
-
xOracleCap: "",
|
|
2359
|
-
supra: { registry: "", registryCap: "", holder: "" },
|
|
2360
|
-
switchboard: { registry: "", registryCap: "" },
|
|
2361
|
-
pyth: {
|
|
2362
|
-
registry: "",
|
|
2363
|
-
registryCap: "",
|
|
2364
|
-
state: "",
|
|
2365
|
-
wormhole: "",
|
|
2366
|
-
wormholeState: ""
|
|
2367
|
-
}
|
|
2368
|
-
},
|
|
2369
|
-
packages: {
|
|
2370
|
-
coinDecimalsRegistry: {
|
|
2371
|
-
id: "",
|
|
2372
|
-
upgradeCap: ""
|
|
2373
|
-
},
|
|
2374
|
-
math: {
|
|
2375
|
-
id: "",
|
|
2376
|
-
upgradeCap: ""
|
|
2377
|
-
},
|
|
2378
|
-
whitelist: {
|
|
2379
|
-
id: "",
|
|
2380
|
-
upgradeCap: ""
|
|
2381
|
-
},
|
|
2382
|
-
x: {
|
|
2383
|
-
id: "",
|
|
2384
|
-
upgradeCap: ""
|
|
2385
|
-
},
|
|
2386
|
-
protocol: {
|
|
2387
|
-
id: "",
|
|
2388
|
-
upgradeCap: ""
|
|
2389
|
-
},
|
|
2390
|
-
protocolWhitelist: {
|
|
2391
|
-
id: "",
|
|
2392
|
-
upgradeCap: ""
|
|
2393
|
-
},
|
|
2394
|
-
query: {
|
|
2395
|
-
id: "",
|
|
2396
|
-
upgradeCap: ""
|
|
2397
|
-
},
|
|
2398
|
-
supra: { id: "", upgradeCap: "" },
|
|
2399
|
-
pyth: {
|
|
2400
|
-
id: "",
|
|
2401
|
-
upgradeCap: ""
|
|
2402
|
-
},
|
|
2403
|
-
switchboard: { id: "", upgradeCap: "" },
|
|
2404
|
-
xOracle: {
|
|
2405
|
-
id: "",
|
|
2406
|
-
upgradeCap: ""
|
|
2407
|
-
},
|
|
2408
|
-
testCoin: { id: "", upgradeCap: "" }
|
|
2243
|
+
} else {
|
|
2244
|
+
throw Error("You don't have permission to access this request.");
|
|
2409
2245
|
}
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2246
|
+
}
|
|
2247
|
+
};
|
|
2248
|
+
|
|
2249
|
+
// src/models/scallopClient.ts
|
|
2250
|
+
import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui/utils";
|
|
2251
|
+
|
|
2252
|
+
// src/models/scallopUtils.ts
|
|
2253
|
+
import { SUI_TYPE_ARG as SUI_TYPE_ARG2, normalizeStructTag as normalizeStructTag7 } from "@mysten/sui/utils";
|
|
2254
|
+
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
2255
|
+
|
|
2256
|
+
// src/queries/borrowIncentiveQuery.ts
|
|
2257
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
|
|
2258
|
+
|
|
2259
|
+
// src/utils/builder.ts
|
|
2260
|
+
var requireSender = (txBlock) => {
|
|
2261
|
+
const sender = txBlock.blockData.sender;
|
|
2262
|
+
if (!sender) {
|
|
2263
|
+
throw new Error("Sender is required");
|
|
2264
|
+
}
|
|
2265
|
+
return sender;
|
|
2266
|
+
};
|
|
2267
|
+
var checkVesca = (prevUnlockAtInMillisTimestamp) => {
|
|
2268
|
+
if (prevUnlockAtInMillisTimestamp === void 0) {
|
|
2269
|
+
throw new Error("veSca not found");
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
|
|
2273
|
+
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
2274
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
2275
|
+
}
|
|
2276
|
+
};
|
|
2277
|
+
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
2278
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
2279
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
2280
|
+
const prevUnlockAtInSecondTimestamp = Math.floor(
|
|
2281
|
+
prevUnlockAtInMillisTimestamp / 1e3
|
|
2282
|
+
);
|
|
2283
|
+
if (lockPeriodInDays < 1) {
|
|
2284
|
+
throw new Error("Minimum lock period is 1 day");
|
|
2285
|
+
}
|
|
2286
|
+
const availableLockPeriodInDays = Math.floor(
|
|
2287
|
+
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
2288
|
+
);
|
|
2289
|
+
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
2290
|
+
throw new Error(
|
|
2291
|
+
`Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
};
|
|
2295
|
+
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
2296
|
+
const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
|
|
2297
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
2298
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
2299
|
+
if (isInitialLock || isLockExpired) {
|
|
2300
|
+
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
2301
|
+
if (lockPeriodInDays <= 0) {
|
|
2302
|
+
throw new Error("Lock period must be greater than 0");
|
|
2303
|
+
}
|
|
2304
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
2305
|
+
throw new Error(
|
|
2306
|
+
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
2307
|
+
);
|
|
2308
|
+
}
|
|
2309
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
2310
|
+
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
2311
|
+
throw new Error(
|
|
2312
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
2313
|
+
);
|
|
2447
2314
|
}
|
|
2448
|
-
}
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2315
|
+
} else {
|
|
2316
|
+
throw new Error(
|
|
2317
|
+
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
2318
|
+
);
|
|
2319
|
+
}
|
|
2320
|
+
} else {
|
|
2321
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
2322
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
2323
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
2324
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
2325
|
+
}
|
|
2326
|
+
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
2327
|
+
checkExtendLockPeriod(
|
|
2328
|
+
lockPeriodInDays,
|
|
2329
|
+
newUnlockAtInSecondTimestamp,
|
|
2330
|
+
prevUnlockAtInMillisTimestamp
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
};
|
|
2335
|
+
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
2336
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
2337
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
2338
|
+
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
2339
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
2340
|
+
}
|
|
2341
|
+
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
2342
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
2343
|
+
if (isLockExpired) {
|
|
2344
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
2348
|
+
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
2349
|
+
throw new Error("Renew method can only be used for expired veSca");
|
|
2350
|
+
}
|
|
2351
|
+
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
2352
|
+
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
2353
|
+
}
|
|
2354
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
2355
|
+
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
2356
|
+
throw new Error(
|
|
2357
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
2358
|
+
);
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2361
|
+
|
|
2362
|
+
// src/utils/query.ts
|
|
2363
|
+
import BigNumber from "bignumber.js";
|
|
2364
|
+
import { normalizeStructTag as normalizeStructTag2, parseStructTag as parseStructTag2 } from "@mysten/sui/utils";
|
|
2365
|
+
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
2366
|
+
return {
|
|
2367
|
+
coinType: normalizeStructTag2(originMarketPoolData.type.name),
|
|
2368
|
+
// Parse origin data required for basic calculations.
|
|
2369
|
+
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
2370
|
+
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
2371
|
+
borrowRateScale: Number(originMarketPoolData.interestRateScale),
|
|
2372
|
+
borrowIndex: Number(originMarketPoolData.borrowIndex),
|
|
2373
|
+
lastUpdated: Number(originMarketPoolData.lastUpdated),
|
|
2374
|
+
cashAmount: Number(originMarketPoolData.cash),
|
|
2375
|
+
debtAmount: Number(originMarketPoolData.debt),
|
|
2376
|
+
marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
|
|
2377
|
+
reserveAmount: Number(originMarketPoolData.reserve),
|
|
2378
|
+
reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
|
|
2379
|
+
borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
|
|
2380
|
+
borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
|
|
2381
|
+
// Parse origin data required for additional display.
|
|
2382
|
+
baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
|
|
2383
|
+
borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
|
|
2384
|
+
borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
|
|
2385
|
+
highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
|
|
2386
|
+
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
2387
|
+
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount),
|
|
2388
|
+
isIsolated: originMarketPoolData.isIsolated,
|
|
2389
|
+
supplyLimit: Number(originMarketPoolData.supplyLimit),
|
|
2390
|
+
borrowLimit: Number(originMarketPoolData.borrowLimit)
|
|
2391
|
+
};
|
|
2392
|
+
};
|
|
2393
|
+
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
2394
|
+
const poolCoinName = utils.parseCoinNameFromType(
|
|
2395
|
+
parsedMarketPoolData.coinType
|
|
2396
|
+
);
|
|
2397
|
+
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
2398
|
+
const borrowYearFactor = 24 * 365 * 3600;
|
|
2399
|
+
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2400
|
+
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2401
|
+
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2402
|
+
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2403
|
+
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
2404
|
+
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
2405
|
+
const borrowIndexDelta = BigNumber(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
2406
|
+
BigNumber(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
2407
|
+
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
2408
|
+
const currentBorrowIndex = BigNumber(parsedMarketPoolData.borrowIndex).plus(
|
|
2409
|
+
borrowIndexDelta
|
|
2410
|
+
);
|
|
2411
|
+
const growthInterest = BigNumber(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
2412
|
+
const increasedDebtAmount = BigNumber(
|
|
2413
|
+
parsedMarketPoolData.debtAmount
|
|
2414
|
+
).multipliedBy(growthInterest);
|
|
2415
|
+
const borrowAmount = increasedDebtAmount.plus(
|
|
2416
|
+
parsedMarketPoolData.debtAmount
|
|
2417
|
+
);
|
|
2418
|
+
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
2419
|
+
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
2420
|
+
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
2421
|
+
);
|
|
2422
|
+
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
2423
|
+
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
2424
|
+
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
2425
|
+
);
|
|
2426
|
+
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
2427
|
+
let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
|
|
2428
|
+
utilizationRate = utilizationRate.isFinite() ? utilizationRate : BigNumber(0);
|
|
2429
|
+
let supplyApr = BigNumber(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
2430
|
+
supplyApr = supplyApr.isFinite() ? supplyApr : BigNumber(0);
|
|
2431
|
+
let conversionRate = supplyAmount.dividedBy(
|
|
2432
|
+
parsedMarketPoolData.marketCoinSupplyAmount
|
|
2433
|
+
);
|
|
2434
|
+
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : BigNumber(1);
|
|
2435
|
+
return {
|
|
2436
|
+
baseBorrowApr,
|
|
2437
|
+
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
2438
|
+
borrowAprOnHighKink,
|
|
2439
|
+
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
2440
|
+
borrowAprOnMidKink,
|
|
2441
|
+
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
2442
|
+
coinDecimal,
|
|
2443
|
+
maxBorrowApr,
|
|
2444
|
+
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
2445
|
+
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
2446
|
+
borrowApy: Math.min(
|
|
2447
|
+
utils.parseAprToApy(borrowApr),
|
|
2448
|
+
utils.parseAprToApy(maxBorrowApr)
|
|
2449
|
+
),
|
|
2450
|
+
borrowIndex: currentBorrowIndex.toNumber(),
|
|
2451
|
+
growthInterest: growthInterest.toNumber(),
|
|
2452
|
+
supplyAmount: supplyAmount.toNumber(),
|
|
2453
|
+
supplyCoin: supplyCoin.toNumber(),
|
|
2454
|
+
borrowAmount: borrowAmount.toNumber(),
|
|
2455
|
+
borrowCoin: borrowCoin.toNumber(),
|
|
2456
|
+
reserveAmount: reserveAmount.toNumber(),
|
|
2457
|
+
reserveCoin: reserveCoin.toNumber(),
|
|
2458
|
+
utilizationRate: utilizationRate.toNumber(),
|
|
2459
|
+
supplyApr: supplyApr.toNumber(),
|
|
2460
|
+
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
2461
|
+
conversionRate: conversionRate.toNumber(),
|
|
2462
|
+
isIsolated: parsedMarketPoolData.isIsolated,
|
|
2463
|
+
maxSupplyCoin: BigNumber(parsedMarketPoolData.supplyLimit).shiftedBy(-coinDecimal).toNumber(),
|
|
2464
|
+
maxBorrowCoin: BigNumber(parsedMarketPoolData.borrowLimit).shiftedBy(-coinDecimal).toNumber()
|
|
2465
|
+
};
|
|
2466
|
+
};
|
|
2467
|
+
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
2468
|
+
const divisor = 2 ** 32;
|
|
2469
|
+
return {
|
|
2470
|
+
coinType: normalizeStructTag2(originMarketCollateralData.type.name),
|
|
2471
|
+
isIsolated: originMarketCollateralData.isIsolated,
|
|
2472
|
+
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
2473
|
+
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
2474
|
+
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
2475
|
+
liquidationPenalty: Number(originMarketCollateralData.liquidationPenalty.value) / divisor,
|
|
2476
|
+
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
2477
|
+
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
2478
|
+
totalCollateralAmount: Number(
|
|
2479
|
+
originMarketCollateralData.totalCollateralAmount
|
|
2480
|
+
)
|
|
2481
|
+
};
|
|
2482
|
+
};
|
|
2483
|
+
var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
2484
|
+
const collateralCoinName = utils.parseCoinNameFromType(
|
|
2485
|
+
parsedMarketCollateralData.coinType
|
|
2486
|
+
);
|
|
2487
|
+
const coinDecimal = utils.getCoinDecimal(collateralCoinName);
|
|
2488
|
+
const maxCollateralCoin = BigNumber(
|
|
2489
|
+
parsedMarketCollateralData.maxCollateralAmount
|
|
2490
|
+
).shiftedBy(-1 * coinDecimal);
|
|
2491
|
+
const depositCoin = BigNumber(
|
|
2492
|
+
parsedMarketCollateralData.totalCollateralAmount
|
|
2493
|
+
).shiftedBy(-1 * coinDecimal);
|
|
2494
|
+
return {
|
|
2495
|
+
coinDecimal,
|
|
2496
|
+
isIsolated: parsedMarketCollateralData.isIsolated,
|
|
2497
|
+
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
2498
|
+
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
2499
|
+
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
|
2500
|
+
depositCoin: depositCoin.toNumber()
|
|
2501
|
+
};
|
|
2502
|
+
};
|
|
2503
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
2504
|
+
return {
|
|
2505
|
+
stakeType: normalizeStructTag2(originSpoolData.stakeType.fields.name),
|
|
2506
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
2507
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
2508
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
2509
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
2510
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
2511
|
+
staked: Number(originSpoolData.stakes),
|
|
2512
|
+
index: Number(originSpoolData.index),
|
|
2513
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
2514
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
2515
|
+
};
|
|
2516
|
+
};
|
|
2517
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
2518
|
+
const baseIndexRate = 1e9;
|
|
2519
|
+
const distributedPointPerSec = BigNumber(
|
|
2520
|
+
parsedSpoolData.pointPerPeriod
|
|
2521
|
+
).dividedBy(parsedSpoolData.period);
|
|
2522
|
+
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
2523
|
+
parsedSpoolData.period
|
|
2524
|
+
);
|
|
2525
|
+
const remainingPeriod = pointPerSec.gt(0) ? BigNumber(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec) : BigNumber(0);
|
|
2526
|
+
const startDate = parsedSpoolData.createdAt;
|
|
2527
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
2528
|
+
const timeDelta = BigNumber(
|
|
2529
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
2530
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
2531
|
+
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
2532
|
+
parsedSpoolData.distributedPoint
|
|
2533
|
+
);
|
|
2534
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
2535
|
+
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
2536
|
+
remainingPoints
|
|
2537
|
+
);
|
|
2538
|
+
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
2539
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
2540
|
+
);
|
|
2541
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
2542
|
+
parsedSpoolData.distributedPoint
|
|
2543
|
+
).plus(accumulatedPoints);
|
|
2544
|
+
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
2545
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
2546
|
+
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
2547
|
+
return {
|
|
2548
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
2549
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
2550
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
2551
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
2552
|
+
startDate: new Date(startDate * 1e3),
|
|
2553
|
+
endDate: new Date(endDate * 1e3),
|
|
2554
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
2555
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
2556
|
+
stakedValue: stakedValue.toNumber()
|
|
2557
|
+
};
|
|
2558
|
+
};
|
|
2559
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
2560
|
+
return {
|
|
2561
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
2562
|
+
exchangeRateDenominator: Number(
|
|
2563
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
2564
|
+
),
|
|
2565
|
+
exchangeRateNumerator: Number(
|
|
2566
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
2567
|
+
),
|
|
2568
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
2569
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
2570
|
+
};
|
|
2571
|
+
};
|
|
2572
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
2573
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
2574
|
+
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
2575
|
+
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
2576
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
2577
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
2578
|
+
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
2579
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
2580
|
+
-1 * rewardCoinDecimal
|
|
2581
|
+
);
|
|
2582
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
2583
|
+
const claimedRewardAmount = BigNumber(
|
|
2584
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
2585
|
+
);
|
|
2586
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
2587
|
+
-1 * rewardCoinDecimal
|
|
2588
|
+
);
|
|
2589
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
2590
|
+
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
2591
|
+
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
2592
|
+
if (parsedSpoolData.maxPoint <= parsedSpoolData.distributedPoint || parsedSpoolData.pointPerPeriod === 0) {
|
|
2593
|
+
rewardRate = Infinity;
|
|
2594
|
+
}
|
|
2595
|
+
return {
|
|
2596
|
+
rewardApr: rewardRate,
|
|
2597
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
2598
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
2599
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
2600
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
2601
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
2602
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
2603
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
2604
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
2605
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
2606
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
2607
|
+
};
|
|
2608
|
+
};
|
|
2609
|
+
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
2610
|
+
return {
|
|
2611
|
+
pointType: normalizeStructTag2(
|
|
2612
|
+
originBorrowIncentivePoolPointData.point_type.name
|
|
2613
|
+
),
|
|
2614
|
+
distributedPointPerPeriod: Number(
|
|
2615
|
+
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
2616
|
+
),
|
|
2617
|
+
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
2618
|
+
distributedPoint: Number(
|
|
2619
|
+
originBorrowIncentivePoolPointData.distributed_point
|
|
2620
|
+
),
|
|
2621
|
+
points: Number(originBorrowIncentivePoolPointData.points),
|
|
2622
|
+
index: Number(originBorrowIncentivePoolPointData.index),
|
|
2623
|
+
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
2624
|
+
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
2625
|
+
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update),
|
|
2626
|
+
createdAt: Number(originBorrowIncentivePoolPointData.created_at)
|
|
2627
|
+
};
|
|
2628
|
+
};
|
|
2629
|
+
var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
|
|
2630
|
+
return {
|
|
2631
|
+
poolType: normalizeStructTag2(originBorrowIncentivePoolData.pool_type.name),
|
|
2632
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
2633
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
2634
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
2635
|
+
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
2636
|
+
(acc, point) => {
|
|
2637
|
+
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
2638
|
+
const name = utils.parseSCoinTypeNameToMarketCoinName(
|
|
2639
|
+
parseStructTag2(parsed.pointType).name.toLowerCase()
|
|
2640
|
+
);
|
|
2641
|
+
acc[name] = parsed;
|
|
2642
|
+
return acc;
|
|
2518
2643
|
},
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2644
|
+
{}
|
|
2645
|
+
)
|
|
2646
|
+
};
|
|
2647
|
+
};
|
|
2648
|
+
var calculateBorrowIncentivePoolPointData = (parsedBorrowIncentivePoolPointData, rewardCoinPrice, rewardCoinDecimal, poolCoinPrice, poolCoinDecimal) => {
|
|
2649
|
+
const baseIndexRate = 1e9;
|
|
2650
|
+
const distributedPointPerSec = BigNumber(
|
|
2651
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
2652
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
2653
|
+
const timeDelta = BigNumber(
|
|
2654
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolPointData.lastUpdate
|
|
2655
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period).toFixed(0);
|
|
2656
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
2657
|
+
BigNumber(timeDelta).multipliedBy(
|
|
2658
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
2659
|
+
),
|
|
2660
|
+
BigNumber(parsedBorrowIncentivePoolPointData.points)
|
|
2661
|
+
);
|
|
2662
|
+
const currentPointIndex = BigNumber(
|
|
2663
|
+
parsedBorrowIncentivePoolPointData.index
|
|
2664
|
+
).plus(
|
|
2665
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount) : 0
|
|
2666
|
+
);
|
|
2667
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
2668
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
2669
|
+
).plus(accumulatedPoints);
|
|
2670
|
+
const baseWeight = BigNumber(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
2671
|
+
const weightedStakedAmount = BigNumber(
|
|
2672
|
+
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
2673
|
+
);
|
|
2674
|
+
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
2675
|
+
-1 * poolCoinDecimal
|
|
2676
|
+
);
|
|
2677
|
+
const weightedStakedValue = weightedStakedCoin.multipliedBy(poolCoinPrice);
|
|
2678
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
2679
|
+
const rewardPerSec = BigNumber(distributedPointPerSec).shiftedBy(
|
|
2680
|
+
-1 * rewardCoinDecimal
|
|
2681
|
+
);
|
|
2682
|
+
const rewardValueForYear = BigNumber(rewardPerSec).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
2683
|
+
const weightScale = BigNumber(1e12);
|
|
2684
|
+
const rewardRate = rewardValueForYear.multipliedBy(
|
|
2685
|
+
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
2686
|
+
weightScale
|
|
2687
|
+
)
|
|
2688
|
+
).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
|
|
2689
|
+
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
2690
|
+
weightScale
|
|
2691
|
+
)
|
|
2692
|
+
).dividedBy(weightedStakedValue).toNumber() : Infinity;
|
|
2693
|
+
return {
|
|
2694
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
2695
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
2696
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
2697
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
2698
|
+
baseWeight: baseWeight.toNumber(),
|
|
2699
|
+
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
2700
|
+
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
2701
|
+
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
2702
|
+
rewardApr: rewardRate,
|
|
2703
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
2704
|
+
};
|
|
2705
|
+
};
|
|
2706
|
+
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
2707
|
+
return {
|
|
2708
|
+
pointType: normalizeStructTag2(
|
|
2709
|
+
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
2710
|
+
),
|
|
2711
|
+
weightedAmount: Number(
|
|
2712
|
+
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
2713
|
+
),
|
|
2714
|
+
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
2715
|
+
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
2716
|
+
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
2717
|
+
};
|
|
2718
|
+
};
|
|
2719
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
2720
|
+
return {
|
|
2721
|
+
poolType: normalizeStructTag2(
|
|
2722
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
2723
|
+
),
|
|
2724
|
+
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
2725
|
+
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
2726
|
+
(acc, point) => {
|
|
2727
|
+
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
2728
|
+
const name = parseStructTag2(
|
|
2729
|
+
parsed.pointType
|
|
2730
|
+
).name.toLowerCase();
|
|
2731
|
+
acc[name] = parsed;
|
|
2732
|
+
return acc;
|
|
2522
2733
|
},
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2734
|
+
{}
|
|
2735
|
+
)
|
|
2736
|
+
};
|
|
2737
|
+
};
|
|
2738
|
+
var minBigNumber = (...args) => {
|
|
2739
|
+
return BigNumber(
|
|
2740
|
+
args.reduce(
|
|
2741
|
+
(min, current) => new BigNumber(current).lt(min) ? current : min
|
|
2742
|
+
)
|
|
2743
|
+
);
|
|
2744
|
+
};
|
|
2745
|
+
var estimatedFactor = (amount, scaleStep, type) => {
|
|
2746
|
+
const amountOfDigits = Math.max(
|
|
2747
|
+
1,
|
|
2748
|
+
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
2749
|
+
);
|
|
2750
|
+
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
2751
|
+
let adjustFactor = Math.pow(10, -adjustScale);
|
|
2752
|
+
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
2753
|
+
return adjustFactor;
|
|
2754
|
+
};
|
|
2755
|
+
|
|
2756
|
+
// src/utils/util.ts
|
|
2757
|
+
var COIN_SET = Array.from(
|
|
2758
|
+
/* @__PURE__ */ new Set([
|
|
2759
|
+
...SUPPORT_POOLS,
|
|
2760
|
+
...SUPPORT_COLLATERALS,
|
|
2761
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
2762
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
2763
|
+
...SUPPORT_SCOIN
|
|
2764
|
+
])
|
|
2765
|
+
);
|
|
2766
|
+
var isMarketCoin = (coinName) => {
|
|
2767
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
2768
|
+
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
2529
2769
|
};
|
|
2530
|
-
var
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
baseURL: API_BASE_URL,
|
|
2540
|
-
headers: {
|
|
2541
|
-
"Content-Type": "application/json",
|
|
2542
|
-
Accept: "application/json"
|
|
2543
|
-
},
|
|
2544
|
-
timeout: 8e3
|
|
2545
|
-
});
|
|
2546
|
-
if (auth)
|
|
2547
|
-
this._auth = auth;
|
|
2548
|
-
this._id = id;
|
|
2549
|
-
this._network = network ?? "mainnet";
|
|
2550
|
-
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
2551
|
-
if (USE_TEST_ADDRESS)
|
|
2552
|
-
this._currentAddresses = TEST_ADDRESSES;
|
|
2553
|
-
if (forceInterface) {
|
|
2554
|
-
for (const [network2, addresses] of Object.entries(
|
|
2555
|
-
forceInterface
|
|
2556
|
-
)) {
|
|
2557
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2558
|
-
if (network2 === this._network)
|
|
2559
|
-
this._currentAddresses = addresses;
|
|
2560
|
-
this._addressesMap.set(network2, addresses);
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
/**
|
|
2566
|
-
* Get addresses API id.
|
|
2567
|
-
*
|
|
2568
|
-
* @return The addresses API id.
|
|
2569
|
-
*/
|
|
2570
|
-
getId() {
|
|
2571
|
-
return this._id || void 0;
|
|
2572
|
-
}
|
|
2573
|
-
/**
|
|
2574
|
-
* Get the address at the provided path.
|
|
2575
|
-
*
|
|
2576
|
-
* @param path - The path of the address to get.
|
|
2577
|
-
* @return The address at the provided path.
|
|
2578
|
-
*/
|
|
2579
|
-
get(path) {
|
|
2580
|
-
if (this._currentAddresses) {
|
|
2581
|
-
const value = path.split(".").reduce(
|
|
2582
|
-
(nestedAddressObj, key) => typeof nestedAddressObj === "object" ? nestedAddressObj[key] : nestedAddressObj,
|
|
2583
|
-
this._currentAddresses
|
|
2584
|
-
);
|
|
2585
|
-
return value || void 0;
|
|
2586
|
-
} else {
|
|
2587
|
-
return void 0;
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
/**
|
|
2591
|
-
* Sets the address for the specified path, it does not interact with the API.
|
|
2592
|
-
*
|
|
2593
|
-
* @param path - The path of the address to set.
|
|
2594
|
-
* @param address - The address be setted to the tartget path.
|
|
2595
|
-
* @return The addresses.
|
|
2596
|
-
*/
|
|
2597
|
-
set(path, address) {
|
|
2598
|
-
if (this._currentAddresses) {
|
|
2599
|
-
const keys = path.split(".");
|
|
2600
|
-
keys.reduce((nestedAddressObj, key, index) => {
|
|
2601
|
-
if (index === keys.length - 1) {
|
|
2602
|
-
nestedAddressObj[key] = address;
|
|
2603
|
-
} else {
|
|
2604
|
-
return nestedAddressObj[key];
|
|
2605
|
-
}
|
|
2606
|
-
}, this._currentAddresses);
|
|
2607
|
-
}
|
|
2608
|
-
return this._currentAddresses;
|
|
2609
|
-
}
|
|
2610
|
-
/**
|
|
2611
|
-
* Synchronize the specified network addresses from the addresses map to the
|
|
2612
|
-
* current addresses and change the default network to specified network.
|
|
2613
|
-
*
|
|
2614
|
-
* @param network - Specifies which network's addresses you want to get.
|
|
2615
|
-
* @return Current addresses.
|
|
2616
|
-
*/
|
|
2617
|
-
switchCurrentAddresses(network) {
|
|
2618
|
-
if (this._addressesMap.has(network)) {
|
|
2619
|
-
this._currentAddresses = this._addressesMap.get(network);
|
|
2620
|
-
this._network = network;
|
|
2621
|
-
}
|
|
2622
|
-
return this._currentAddresses;
|
|
2623
|
-
}
|
|
2624
|
-
/**
|
|
2625
|
-
* Get the addresses, If `network` is not provided, returns the current
|
|
2626
|
-
* addresses or the default network addresses in the addresses map.
|
|
2627
|
-
*
|
|
2628
|
-
* @param network - Specifies which network's addresses you want to get.
|
|
2629
|
-
*/
|
|
2630
|
-
getAddresses(network) {
|
|
2631
|
-
if (network) {
|
|
2632
|
-
return this._addressesMap.get(network);
|
|
2633
|
-
} else {
|
|
2634
|
-
return this._currentAddresses ?? this._addressesMap.get(this._network);
|
|
2635
|
-
}
|
|
2770
|
+
var isSuiBridgeAsset = (coinName) => {
|
|
2771
|
+
return SUPPORT_SUI_BRIDGE.includes(coinName);
|
|
2772
|
+
};
|
|
2773
|
+
var isWormholeAsset = (coinName) => {
|
|
2774
|
+
return SUPPORT_WORMHOLE.includes(coinName);
|
|
2775
|
+
};
|
|
2776
|
+
var parseAssetSymbol = (coinName) => {
|
|
2777
|
+
if (isWormholeAsset(coinName)) {
|
|
2778
|
+
return `w${coinName.slice(1).toUpperCase()}`;
|
|
2636
2779
|
}
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
* as the current network, the current addresses will be updated at the same time.
|
|
2640
|
-
*
|
|
2641
|
-
* @param addresses - The addresses be setted to the tartget network.
|
|
2642
|
-
* @param network - Specifies which network's addresses you want to set.
|
|
2643
|
-
* @return The addresses.
|
|
2644
|
-
*/
|
|
2645
|
-
setAddresses(addresses, network) {
|
|
2646
|
-
const targetNetwork = network || this._network;
|
|
2647
|
-
if (targetNetwork === this._network)
|
|
2648
|
-
this._currentAddresses = addresses;
|
|
2649
|
-
this._addressesMap.set(targetNetwork, addresses);
|
|
2780
|
+
if (isSuiBridgeAsset(coinName)) {
|
|
2781
|
+
return `sb${coinName.slice(2).toUpperCase()}`;
|
|
2650
2782
|
}
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
* @return All addresses.
|
|
2655
|
-
*/
|
|
2656
|
-
getAllAddresses() {
|
|
2657
|
-
return Object.fromEntries(this._addressesMap);
|
|
2783
|
+
if (isMarketCoin(coinName)) {
|
|
2784
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
2785
|
+
return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
|
|
2658
2786
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
* This function only allows for one addresses to be input into a specific network
|
|
2669
|
-
* at a time, and does not provide an addresses map for setting addresses
|
|
2670
|
-
* across all networks at once.
|
|
2671
|
-
*
|
|
2672
|
-
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2673
|
-
* @param params.network - Specifies which network's addresses you want to set.
|
|
2674
|
-
* @param params.auth - The authentication API key.
|
|
2675
|
-
* @param params.memo - Add memo to the addresses created in the API.
|
|
2676
|
-
* @return All addresses.
|
|
2677
|
-
*/
|
|
2678
|
-
async create(params) {
|
|
2679
|
-
const { addresses, network, auth, memo } = params ?? {};
|
|
2680
|
-
const apiKey = auth || this._auth || void 0;
|
|
2681
|
-
const targetNetwork = network || this._network;
|
|
2682
|
-
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2683
|
-
if (apiKey !== void 0) {
|
|
2684
|
-
this._addressesMap.clear();
|
|
2685
|
-
this.setAddresses(targetAddresses, targetNetwork);
|
|
2686
|
-
const response = await this._requestClient.post(
|
|
2687
|
-
`/addresses`,
|
|
2688
|
-
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2689
|
-
{
|
|
2690
|
-
headers: {
|
|
2691
|
-
"Content-Type": "application/json",
|
|
2692
|
-
"api-key": auth || this._auth
|
|
2693
|
-
}
|
|
2694
|
-
}
|
|
2695
|
-
);
|
|
2696
|
-
if (response.status === 201) {
|
|
2697
|
-
for (const [network2, addresses2] of Object.entries(
|
|
2698
|
-
response.data
|
|
2699
|
-
)) {
|
|
2700
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2701
|
-
if (network2 === this._network)
|
|
2702
|
-
this._currentAddresses = addresses2;
|
|
2703
|
-
this._addressesMap.set(network2, addresses2);
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
this._id = response.data.id;
|
|
2707
|
-
return this.getAllAddresses();
|
|
2708
|
-
} else {
|
|
2709
|
-
throw Error("Failed to create addresses.");
|
|
2710
|
-
}
|
|
2711
|
-
} else {
|
|
2712
|
-
throw Error("You don't have permission to access this request.");
|
|
2713
|
-
}
|
|
2787
|
+
switch (coinName) {
|
|
2788
|
+
case "afsui":
|
|
2789
|
+
return "afSUI";
|
|
2790
|
+
case "hasui":
|
|
2791
|
+
return "haSUI";
|
|
2792
|
+
case "vsui":
|
|
2793
|
+
return "vSUI";
|
|
2794
|
+
default:
|
|
2795
|
+
return coinName.toUpperCase();
|
|
2714
2796
|
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
const
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
}
|
|
2731
|
-
});
|
|
2732
|
-
}
|
|
2733
|
-
});
|
|
2734
|
-
if (response.status === 200) {
|
|
2735
|
-
for (const [network, addresses] of Object.entries(
|
|
2736
|
-
response.data
|
|
2737
|
-
)) {
|
|
2738
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network)) {
|
|
2739
|
-
if (network === this._network)
|
|
2740
|
-
this._currentAddresses = addresses;
|
|
2741
|
-
this._addressesMap.set(network, addresses);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
this._id = response.data.id;
|
|
2745
|
-
return this.getAllAddresses();
|
|
2746
|
-
} else {
|
|
2747
|
-
throw Error("Failed to create addresses.");
|
|
2748
|
-
}
|
|
2749
|
-
} else {
|
|
2750
|
-
throw Error("Please provide API addresses id.");
|
|
2751
|
-
}
|
|
2797
|
+
};
|
|
2798
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
2799
|
+
const assetCoinNames = COIN_SET;
|
|
2800
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
2801
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
2802
|
+
});
|
|
2803
|
+
if (assetCoinName) {
|
|
2804
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
2805
|
+
return {
|
|
2806
|
+
coinName: assetCoinName,
|
|
2807
|
+
price,
|
|
2808
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
2809
|
+
};
|
|
2810
|
+
} else {
|
|
2811
|
+
throw new Error("Invalid feed id");
|
|
2752
2812
|
}
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
* all empty strings is created by default.
|
|
2761
|
-
*
|
|
2762
|
-
* This function only allows for one addresses to be input into a specific network
|
|
2763
|
-
* at a time, and does not provide an addresses map for setting addresses
|
|
2764
|
-
* across all networks at once.
|
|
2765
|
-
*
|
|
2766
|
-
* @param params.id - The id of the addresses to update.
|
|
2767
|
-
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2768
|
-
* @param params.network - Specifies which network's addresses you want to set.
|
|
2769
|
-
* @param params.auth - The authentication api key.
|
|
2770
|
-
* @param params.memo - Add memo to the addresses created in the API.
|
|
2771
|
-
* @return All addresses.
|
|
2772
|
-
*/
|
|
2773
|
-
async update(params) {
|
|
2774
|
-
const { id, addresses, network, auth, memo } = params ?? {};
|
|
2775
|
-
const apiKey = auth || this._auth || void 0;
|
|
2776
|
-
const targetId = id || this._id || void 0;
|
|
2777
|
-
const targetNetwork = network || this._network;
|
|
2778
|
-
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2779
|
-
if (targetId === void 0)
|
|
2780
|
-
throw Error("Require specific addresses id to be updated.");
|
|
2781
|
-
if (apiKey !== void 0) {
|
|
2782
|
-
if (id !== this._id) {
|
|
2783
|
-
this._addressesMap.clear();
|
|
2784
|
-
}
|
|
2785
|
-
this.setAddresses(targetAddresses, targetNetwork);
|
|
2786
|
-
const response = await this._requestClient.put(
|
|
2787
|
-
`/addresses/${targetId}`,
|
|
2788
|
-
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2789
|
-
{
|
|
2790
|
-
headers: {
|
|
2791
|
-
"Content-Type": "application/json",
|
|
2792
|
-
"api-key": auth || this._auth
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
);
|
|
2796
|
-
if (response.status === 200) {
|
|
2797
|
-
for (const [network2, addresses2] of Object.entries(
|
|
2798
|
-
response.data
|
|
2799
|
-
)) {
|
|
2800
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2801
|
-
if (network2 === this._network)
|
|
2802
|
-
this._currentAddresses = addresses2;
|
|
2803
|
-
this._addressesMap.set(network2, addresses2);
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
this._id = response.data.id;
|
|
2807
|
-
return this.getAllAddresses();
|
|
2808
|
-
} else {
|
|
2809
|
-
throw Error("Failed to update addresses.");
|
|
2810
|
-
}
|
|
2811
|
-
} else {
|
|
2812
|
-
throw Error("You don't have permission to access this request.");
|
|
2813
|
-
}
|
|
2813
|
+
};
|
|
2814
|
+
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
2815
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
2816
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
2817
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
2818
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
2819
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
2814
2820
|
}
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2821
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
2822
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
2823
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
2824
|
+
}
|
|
2825
|
+
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
2826
|
+
};
|
|
2827
|
+
var partitionArray = (array, chunkSize) => {
|
|
2828
|
+
const result = [];
|
|
2829
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
2830
|
+
result.push(array.slice(i, i + chunkSize));
|
|
2831
|
+
}
|
|
2832
|
+
return result;
|
|
2833
|
+
};
|
|
2834
|
+
|
|
2835
|
+
// src/utils/indexer.ts
|
|
2836
|
+
async function callMethodWithIndexerFallback(method, context, ...args) {
|
|
2837
|
+
const lastArgs = args[args.length - 1];
|
|
2838
|
+
if (typeof lastArgs === "object" && lastArgs.indexer) {
|
|
2839
|
+
try {
|
|
2840
|
+
return await method.apply(context, args);
|
|
2841
|
+
} catch (e) {
|
|
2842
|
+
console.warn(
|
|
2843
|
+
`Indexer requests failed: ${e.message}. Retrying without indexer..`
|
|
2844
|
+
);
|
|
2845
|
+
return await method.apply(context, [
|
|
2846
|
+
...args.slice(0, -1),
|
|
2830
2847
|
{
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
"api-key": auth || this._auth
|
|
2834
|
-
}
|
|
2848
|
+
...lastArgs,
|
|
2849
|
+
indexer: false
|
|
2835
2850
|
}
|
|
2836
|
-
);
|
|
2837
|
-
if (response.status === 200) {
|
|
2838
|
-
this._id = void 0;
|
|
2839
|
-
this._currentAddresses = void 0;
|
|
2840
|
-
this._addressesMap.clear();
|
|
2841
|
-
} else {
|
|
2842
|
-
throw Error("Failed to delete addresses.");
|
|
2843
|
-
}
|
|
2844
|
-
} else {
|
|
2845
|
-
throw Error("You don't have permission to access this request.");
|
|
2851
|
+
]);
|
|
2846
2852
|
}
|
|
2847
2853
|
}
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2854
|
+
return await method.apply(context, args);
|
|
2855
|
+
}
|
|
2856
|
+
function withIndexerFallback(method) {
|
|
2857
|
+
return (...args) => {
|
|
2858
|
+
return callMethodWithIndexerFallback(method, this, ...args);
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2852
2861
|
|
|
2853
|
-
// src/
|
|
2854
|
-
|
|
2855
|
-
|
|
2862
|
+
// src/utils/core.ts
|
|
2863
|
+
var parseObjectAs = (object) => {
|
|
2864
|
+
if (!(object && object.content && "fields" in object.content))
|
|
2865
|
+
throw new Error(`Failed to parse object`);
|
|
2866
|
+
const fields = object.content.fields;
|
|
2867
|
+
if (typeof fields === "object" && "value" in fields) {
|
|
2868
|
+
const value = fields.value;
|
|
2869
|
+
if (typeof value === "object" && "fields" in value)
|
|
2870
|
+
return value.fields;
|
|
2871
|
+
return value;
|
|
2872
|
+
} else if (typeof fields === "object") {
|
|
2873
|
+
return fields;
|
|
2874
|
+
}
|
|
2875
|
+
return fields;
|
|
2876
|
+
};
|
|
2856
2877
|
|
|
2857
2878
|
// src/queries/borrowIncentiveQuery.ts
|
|
2858
|
-
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui/utils";
|
|
2859
2879
|
import BigNumber2 from "bignumber.js";
|
|
2860
2880
|
var queryBorrowIncentivePools = async (address) => {
|
|
2861
2881
|
const queryPkgId = address.get("borrowIncentive.query");
|
|
@@ -3881,11 +3901,11 @@ var getCoinAmounts = async (query, assetCoinNames = [...SUPPORT_POOLS], ownerAdd
|
|
|
3881
3901
|
var getCoinAmount = async (query, assetCoinName, ownerAddress) => {
|
|
3882
3902
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3883
3903
|
const coinType = query.utils.parseCoinType(assetCoinName);
|
|
3884
|
-
const
|
|
3904
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
3885
3905
|
owner,
|
|
3886
3906
|
coinType
|
|
3887
3907
|
});
|
|
3888
|
-
return BigNumber3(
|
|
3908
|
+
return BigNumber3(coinBalance?.totalBalance ?? "0").toNumber();
|
|
3889
3909
|
};
|
|
3890
3910
|
var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
3891
3911
|
marketCoinNames = marketCoinNames || [...SUPPORT_POOLS].map(
|
|
@@ -3908,11 +3928,11 @@ var getMarketCoinAmounts = async (query, marketCoinNames, ownerAddress) => {
|
|
|
3908
3928
|
var getMarketCoinAmount = async (query, marketCoinName, ownerAddress) => {
|
|
3909
3929
|
const owner = ownerAddress ?? query.suiKit.currentAddress();
|
|
3910
3930
|
const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
|
|
3911
|
-
const
|
|
3931
|
+
const coinBalance = await query.cache.queryGetCoinBalance({
|
|
3912
3932
|
owner,
|
|
3913
3933
|
coinType: marketCoinType
|
|
3914
3934
|
});
|
|
3915
|
-
return BigNumber3(
|
|
3935
|
+
return BigNumber3(coinBalance?.totalBalance ?? "0").toNumber();
|
|
3916
3936
|
};
|
|
3917
3937
|
var getFlashLoanFees = async (query, assetNames) => {
|
|
3918
3938
|
const FEE_RATE = 1e4;
|
|
@@ -4026,7 +4046,8 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4026
4046
|
|
|
4027
4047
|
// src/queries/portfolioQuery.ts
|
|
4028
4048
|
import BigNumber5 from "bignumber.js";
|
|
4029
|
-
|
|
4049
|
+
import { normalizeStructTag as normalizeStructTag5, SUI_TYPE_ARG } from "@scallop-io/sui-kit";
|
|
4050
|
+
var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress, marketPools, indexer = false) => {
|
|
4030
4051
|
const marketCoinNames = poolCoinNames.map(
|
|
4031
4052
|
(poolCoinName) => query.utils.parseMarketCoinName(poolCoinName)
|
|
4032
4053
|
);
|
|
@@ -4034,7 +4055,7 @@ var getLendings = async (query, poolCoinNames = [...SUPPORT_POOLS], ownerAddress
|
|
|
4034
4055
|
(marketCoinName) => SUPPORT_SPOOLS.includes(marketCoinName)
|
|
4035
4056
|
);
|
|
4036
4057
|
const coinPrices = await query.utils.getCoinPrices();
|
|
4037
|
-
|
|
4058
|
+
marketPools = marketPools ?? (await query.getMarketPools(poolCoinNames, {
|
|
4038
4059
|
indexer,
|
|
4039
4060
|
coinPrices
|
|
4040
4061
|
})).pools;
|
|
@@ -4204,8 +4225,8 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
4204
4225
|
};
|
|
4205
4226
|
return lending;
|
|
4206
4227
|
};
|
|
4207
|
-
var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
4208
|
-
|
|
4228
|
+
var getObligationAccounts = async (query, ownerAddress, market, indexer = false) => {
|
|
4229
|
+
market = market ?? await query.getMarketPools(void 0, { indexer });
|
|
4209
4230
|
const coinPrices = await query.getAllCoinPrices({
|
|
4210
4231
|
marketPools: market.pools
|
|
4211
4232
|
});
|
|
@@ -4247,7 +4268,6 @@ var getObligationAccount = async (query, obligation, ownerAddress, indexer = fal
|
|
|
4247
4268
|
query.queryObligation(obligation),
|
|
4248
4269
|
query.getBorrowIncentivePools(void 0, {
|
|
4249
4270
|
coinPrices,
|
|
4250
|
-
indexer,
|
|
4251
4271
|
marketPools: market.pools
|
|
4252
4272
|
}),
|
|
4253
4273
|
query.getBorrowIncentiveAccounts(obligation)
|
|
@@ -4566,6 +4586,154 @@ var getTotalValueLocked = async (query, indexer = false) => {
|
|
|
4566
4586
|
};
|
|
4567
4587
|
return tvl;
|
|
4568
4588
|
};
|
|
4589
|
+
var getUserPortfolio = async (query, walletAddress, indexer = false) => {
|
|
4590
|
+
const market = await query.getMarketPools();
|
|
4591
|
+
const [lendings, obligationAccounts, borrowIncentivePools] = await Promise.all([
|
|
4592
|
+
query.getLendings(void 0, walletAddress, {
|
|
4593
|
+
indexer,
|
|
4594
|
+
marketPools: market.pools
|
|
4595
|
+
}),
|
|
4596
|
+
query.getObligationAccounts(walletAddress, {
|
|
4597
|
+
indexer,
|
|
4598
|
+
market
|
|
4599
|
+
}),
|
|
4600
|
+
query.getBorrowIncentivePools(void 0, {
|
|
4601
|
+
marketPools: market.pools
|
|
4602
|
+
})
|
|
4603
|
+
]);
|
|
4604
|
+
const parsedLendings = Object.values(lendings).filter((t) => t.availableWithdrawCoin > 0).map((lending) => ({
|
|
4605
|
+
suppliedCoin: lending.availableWithdrawCoin,
|
|
4606
|
+
suppliedValue: lending.suppliedValue,
|
|
4607
|
+
stakedCoin: lending.availableUnstakeCoin,
|
|
4608
|
+
coinName: lending.coinName,
|
|
4609
|
+
symbol: lending.symbol,
|
|
4610
|
+
coinType: lending.coinType,
|
|
4611
|
+
coinPrice: lending.coinPrice,
|
|
4612
|
+
coinDecimals: lending.coinDecimal,
|
|
4613
|
+
supplyApr: lending.supplyApr,
|
|
4614
|
+
supplyApy: lending.supplyApy,
|
|
4615
|
+
incentiveApr: isFinite(lending.rewardApr) ? lending.rewardApr : 0
|
|
4616
|
+
}));
|
|
4617
|
+
const parsedObligationAccounts = Object.values(obligationAccounts).filter(
|
|
4618
|
+
(t) => !!t && t.totalBorrowedValueWithWeight > 0
|
|
4619
|
+
).map((obligationAccount) => {
|
|
4620
|
+
return {
|
|
4621
|
+
obligationId: obligationAccount.obligationId,
|
|
4622
|
+
totalDebtsInUsd: obligationAccount.totalBorrowedValueWithWeight,
|
|
4623
|
+
totalCollateralInUsd: obligationAccount.totalDepositedValue,
|
|
4624
|
+
riskLevel: obligationAccount.totalRiskLevel,
|
|
4625
|
+
availableCollateralInUsd: obligationAccount.totalAvailableCollateralValue,
|
|
4626
|
+
totalUnhealthyCollateralInUsd: obligationAccount.totalUnhealthyCollateralValue,
|
|
4627
|
+
borrowedPools: Object.values(obligationAccount.debts).filter((debt) => debt.borrowedCoin > 0).map((debt) => ({
|
|
4628
|
+
coinName: debt.coinName,
|
|
4629
|
+
symbol: debt.symbol,
|
|
4630
|
+
coinDecimals: debt.coinDecimal,
|
|
4631
|
+
coinType: debt.coinType,
|
|
4632
|
+
coinPrice: debt.coinPrice,
|
|
4633
|
+
borrowedCoin: debt.borrowedCoin,
|
|
4634
|
+
borrowedValueInUsd: debt.borrowedValueWithWeight,
|
|
4635
|
+
borrowApr: market.pools[debt.coinName]?.borrowApr,
|
|
4636
|
+
borrowApy: market.pools[debt.coinName]?.borrowApy,
|
|
4637
|
+
incentiveInfos: Object.values(
|
|
4638
|
+
borrowIncentivePools[debt.coinName]?.points ?? {}
|
|
4639
|
+
).filter((t) => isFinite(t.rewardApr)).map((t) => ({
|
|
4640
|
+
coinName: t.coinName,
|
|
4641
|
+
symbol: t.symbol,
|
|
4642
|
+
coinType: t.coinType,
|
|
4643
|
+
incentiveApr: t.rewardApr
|
|
4644
|
+
}))
|
|
4645
|
+
}))
|
|
4646
|
+
};
|
|
4647
|
+
});
|
|
4648
|
+
const pendingLendingRewards = Object.values(lendings).reduce(
|
|
4649
|
+
(acc, reward) => {
|
|
4650
|
+
if (reward.availableClaimCoin === 0)
|
|
4651
|
+
return acc;
|
|
4652
|
+
if (!acc[reward.symbol]) {
|
|
4653
|
+
acc[reward.symbol] = {
|
|
4654
|
+
symbol: reward.symbol,
|
|
4655
|
+
coinType: normalizeStructTag5(SUI_TYPE_ARG),
|
|
4656
|
+
// @TODO: for now lending reward is all in SUI
|
|
4657
|
+
coinPrice: reward.coinPrice,
|
|
4658
|
+
pendingRewardInCoin: reward.availableClaimCoin
|
|
4659
|
+
};
|
|
4660
|
+
} else {
|
|
4661
|
+
acc[reward.symbol].pendingRewardInCoin += reward.availableClaimCoin;
|
|
4662
|
+
}
|
|
4663
|
+
return acc;
|
|
4664
|
+
},
|
|
4665
|
+
{}
|
|
4666
|
+
);
|
|
4667
|
+
const pendingBorrowIncentiveRewards = Object.values(obligationAccounts).filter((t) => !!t).reduce(
|
|
4668
|
+
(acc, curr) => {
|
|
4669
|
+
Object.values(curr.borrowIncentives).forEach((incentive) => {
|
|
4670
|
+
incentive.rewards.forEach((reward) => {
|
|
4671
|
+
if (reward.availableClaimCoin === 0)
|
|
4672
|
+
return acc;
|
|
4673
|
+
if (!acc[reward.coinName]) {
|
|
4674
|
+
acc[reward.coinName] = {
|
|
4675
|
+
symbol: reward.symbol,
|
|
4676
|
+
coinType: reward.coinType,
|
|
4677
|
+
coinPrice: reward.coinPrice,
|
|
4678
|
+
pendingRewardInCoin: reward.availableClaimCoin
|
|
4679
|
+
};
|
|
4680
|
+
} else {
|
|
4681
|
+
acc[reward.coinName].pendingRewardInCoin += reward.availableClaimCoin;
|
|
4682
|
+
}
|
|
4683
|
+
});
|
|
4684
|
+
});
|
|
4685
|
+
return acc;
|
|
4686
|
+
},
|
|
4687
|
+
{}
|
|
4688
|
+
);
|
|
4689
|
+
return {
|
|
4690
|
+
lendings: {
|
|
4691
|
+
totalSupplyValue: parsedLendings.reduce((acc, curr) => {
|
|
4692
|
+
acc += curr.suppliedValue;
|
|
4693
|
+
return acc;
|
|
4694
|
+
}, 0),
|
|
4695
|
+
suppliedPools: parsedLendings
|
|
4696
|
+
},
|
|
4697
|
+
borrowings: {
|
|
4698
|
+
...parsedObligationAccounts.reduce(
|
|
4699
|
+
(acc, curr) => {
|
|
4700
|
+
acc.totalDebtValue += curr.totalDebtsInUsd;
|
|
4701
|
+
acc.totalCollateralValue += curr.totalCollateralInUsd;
|
|
4702
|
+
return acc;
|
|
4703
|
+
},
|
|
4704
|
+
{
|
|
4705
|
+
totalDebtValue: 0,
|
|
4706
|
+
totalCollateralValue: 0
|
|
4707
|
+
}
|
|
4708
|
+
),
|
|
4709
|
+
obligations: parsedObligationAccounts
|
|
4710
|
+
},
|
|
4711
|
+
pendingRewards: {
|
|
4712
|
+
lendings: Object.entries(pendingLendingRewards).reduce(
|
|
4713
|
+
(acc, [key, value]) => {
|
|
4714
|
+
acc.push({
|
|
4715
|
+
...value,
|
|
4716
|
+
coinName: key,
|
|
4717
|
+
pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin
|
|
4718
|
+
});
|
|
4719
|
+
return acc;
|
|
4720
|
+
},
|
|
4721
|
+
[]
|
|
4722
|
+
),
|
|
4723
|
+
borrowIncentives: Object.entries(pendingBorrowIncentiveRewards).reduce(
|
|
4724
|
+
(acc, [key, value]) => {
|
|
4725
|
+
acc.push({
|
|
4726
|
+
coinName: key,
|
|
4727
|
+
...value,
|
|
4728
|
+
pendingRewardInUsd: value.coinPrice * value.pendingRewardInCoin
|
|
4729
|
+
});
|
|
4730
|
+
return acc;
|
|
4731
|
+
},
|
|
4732
|
+
[]
|
|
4733
|
+
)
|
|
4734
|
+
}
|
|
4735
|
+
};
|
|
4736
|
+
};
|
|
4569
4737
|
|
|
4570
4738
|
// src/queries/priceQuery.ts
|
|
4571
4739
|
import BigNumber6 from "bignumber.js";
|
|
@@ -4729,11 +4897,11 @@ var getSCoinAmount = async ({
|
|
|
4729
4897
|
}, sCoinName, ownerAddress) => {
|
|
4730
4898
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
4731
4899
|
const sCoinType = utils.parseSCoinType(sCoinName);
|
|
4732
|
-
const
|
|
4900
|
+
const coinBalance = await utils.cache.queryGetCoinBalance({
|
|
4733
4901
|
owner,
|
|
4734
4902
|
coinType: sCoinType
|
|
4735
4903
|
});
|
|
4736
|
-
return BigNumber7(
|
|
4904
|
+
return BigNumber7(coinBalance?.totalBalance ?? "0").toNumber();
|
|
4737
4905
|
};
|
|
4738
4906
|
var isSupportStakeCoins = (value) => {
|
|
4739
4907
|
return SUPPORT_SCOIN.includes(value);
|
|
@@ -4777,7 +4945,7 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4777
4945
|
};
|
|
4778
4946
|
|
|
4779
4947
|
// src/queries/spoolQuery.ts
|
|
4780
|
-
import { normalizeStructTag as
|
|
4948
|
+
import { normalizeStructTag as normalizeStructTag6 } from "@mysten/sui/utils";
|
|
4781
4949
|
var queryRequiredSpoolObjects = async (query, stakePoolCoinNames) => {
|
|
4782
4950
|
const tasks = stakePoolCoinNames.map((t, idx) => ({
|
|
4783
4951
|
poolCoinName: stakePoolCoinNames[idx],
|
|
@@ -5037,14 +5205,14 @@ var getStakeAccounts = async ({
|
|
|
5037
5205
|
svsui: stakeAccounts.svsui,
|
|
5038
5206
|
susdc: stakeAccounts.susdc
|
|
5039
5207
|
};
|
|
5040
|
-
const normalizedType =
|
|
5208
|
+
const normalizedType = normalizeStructTag6(type);
|
|
5041
5209
|
const stakeAccountArray = stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
|
|
5042
5210
|
if (stakeAccountArray) {
|
|
5043
5211
|
stakeAccountArray.push({
|
|
5044
5212
|
id,
|
|
5045
5213
|
type: normalizedType,
|
|
5046
5214
|
stakePoolId,
|
|
5047
|
-
stakeType:
|
|
5215
|
+
stakeType: normalizeStructTag6(stakeType),
|
|
5048
5216
|
staked,
|
|
5049
5217
|
index,
|
|
5050
5218
|
points,
|
|
@@ -5082,13 +5250,13 @@ var getStakePool = async ({
|
|
|
5082
5250
|
const lastUpdate = Number(fields.last_update);
|
|
5083
5251
|
stakePool = {
|
|
5084
5252
|
id,
|
|
5085
|
-
type:
|
|
5253
|
+
type: normalizeStructTag6(type),
|
|
5086
5254
|
maxPoint,
|
|
5087
5255
|
distributedPoint,
|
|
5088
5256
|
pointPerPeriod,
|
|
5089
5257
|
period,
|
|
5090
5258
|
maxStake,
|
|
5091
|
-
stakeType:
|
|
5259
|
+
stakeType: normalizeStructTag6(stakeType),
|
|
5092
5260
|
totalStaked,
|
|
5093
5261
|
index,
|
|
5094
5262
|
createdAt,
|
|
@@ -5127,7 +5295,7 @@ var getStakeRewardPool = async ({
|
|
|
5127
5295
|
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
5128
5296
|
stakeRewardPool = {
|
|
5129
5297
|
id,
|
|
5130
|
-
type:
|
|
5298
|
+
type: normalizeStructTag6(type),
|
|
5131
5299
|
stakePoolId,
|
|
5132
5300
|
ratioNumerator,
|
|
5133
5301
|
ratioDenominator,
|
|
@@ -5381,6 +5549,7 @@ var getAllAddresses = async (query) => {
|
|
|
5381
5549
|
// @ts-ignore
|
|
5382
5550
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
5383
5551
|
);
|
|
5552
|
+
const sCoinType = query.address.get(`scoin.coins.s${coinName}.coinType`);
|
|
5384
5553
|
const sCoinTreasury = query.address.get(
|
|
5385
5554
|
// @ts-ignore
|
|
5386
5555
|
`scoin.coins.s${coinName}.treasury`
|
|
@@ -5401,7 +5570,9 @@ var getAllAddresses = async (query) => {
|
|
|
5401
5570
|
spool,
|
|
5402
5571
|
spoolReward: rewardPool,
|
|
5403
5572
|
sCoinTreasury,
|
|
5404
|
-
|
|
5573
|
+
sCoinType,
|
|
5574
|
+
coinDecimalId,
|
|
5575
|
+
coinType
|
|
5405
5576
|
};
|
|
5406
5577
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
5407
5578
|
})
|
|
@@ -5409,17 +5580,6 @@ var getAllAddresses = async (query) => {
|
|
|
5409
5580
|
return results;
|
|
5410
5581
|
};
|
|
5411
5582
|
|
|
5412
|
-
// src/models/suiKit.ts
|
|
5413
|
-
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
5414
|
-
var newSuiKit = (params) => {
|
|
5415
|
-
return new SuiKit2({
|
|
5416
|
-
...params,
|
|
5417
|
-
fullnodeUrls: Array.from(
|
|
5418
|
-
/* @__PURE__ */ new Set([...params.fullnodeUrls ?? [], ...RPC_PROVIDERS])
|
|
5419
|
-
)
|
|
5420
|
-
});
|
|
5421
|
-
};
|
|
5422
|
-
|
|
5423
5583
|
// src/models/scallopUtils.ts
|
|
5424
5584
|
var ScallopUtils = class {
|
|
5425
5585
|
constructor(params, instance) {
|
|
@@ -5436,18 +5596,15 @@ var ScallopUtils = class {
|
|
|
5436
5596
|
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS["mainnet"],
|
|
5437
5597
|
...params
|
|
5438
5598
|
};
|
|
5439
|
-
this.
|
|
5440
|
-
this.
|
|
5599
|
+
this.walletAddress = params.walletAddress ?? instance?.suiKit?.currentAddress() ?? "";
|
|
5600
|
+
this.suiKit = instance?.suiKit ?? instance?.address?.cache.suiKit ?? newSuiKit(params);
|
|
5441
5601
|
if (instance?.address) {
|
|
5442
5602
|
this.address = instance.address;
|
|
5443
5603
|
this.cache = this.address.cache;
|
|
5444
|
-
this.suiKit = this.address.cache._suiKit;
|
|
5445
5604
|
} else {
|
|
5446
|
-
this.cache = new ScallopCache(
|
|
5447
|
-
this.suiKit
|
|
5448
|
-
|
|
5449
|
-
DEFAULT_CACHE_OPTIONS
|
|
5450
|
-
);
|
|
5605
|
+
this.cache = new ScallopCache(this.params, {
|
|
5606
|
+
suiKit: this.suiKit
|
|
5607
|
+
});
|
|
5451
5608
|
this.address = instance?.address ?? new ScallopAddress(
|
|
5452
5609
|
{
|
|
5453
5610
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -5511,7 +5668,7 @@ var ScallopUtils = class {
|
|
|
5511
5668
|
throw Error(`Coin ${coinName} is not supported`);
|
|
5512
5669
|
}
|
|
5513
5670
|
if (coinName === "sui")
|
|
5514
|
-
return
|
|
5671
|
+
return normalizeStructTag7(`${coinPackageId}::sui::SUI`);
|
|
5515
5672
|
const wormHolePackageIds = [
|
|
5516
5673
|
this.address.get("core.coins.wusdc.id") ?? wormholeCoinIds.wusdc,
|
|
5517
5674
|
this.address.get("core.coins.wusdt.id") ?? wormholeCoinIds.wusdt,
|
|
@@ -5615,7 +5772,7 @@ var ScallopUtils = class {
|
|
|
5615
5772
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
5616
5773
|
}
|
|
5617
5774
|
parseCoinNameFromType(coinType) {
|
|
5618
|
-
coinType =
|
|
5775
|
+
coinType = normalizeStructTag7(coinType);
|
|
5619
5776
|
if (sCoinTypeToName[coinType]) {
|
|
5620
5777
|
return sCoinTypeToName[coinType];
|
|
5621
5778
|
}
|
|
@@ -5699,8 +5856,8 @@ var ScallopUtils = class {
|
|
|
5699
5856
|
* @param coinType - The coin type, default is 0x2::SUI::SUI.
|
|
5700
5857
|
* @return The selected transaction coin arguments.
|
|
5701
5858
|
*/
|
|
5702
|
-
async selectCoins(amount, coinType =
|
|
5703
|
-
ownerAddress = ownerAddress ?? this.
|
|
5859
|
+
async selectCoins(amount, coinType = SUI_TYPE_ARG2, ownerAddress) {
|
|
5860
|
+
ownerAddress = ownerAddress ?? this.walletAddress;
|
|
5704
5861
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
5705
5862
|
ownerAddress,
|
|
5706
5863
|
amount,
|
|
@@ -7557,11 +7714,10 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
7557
7714
|
|
|
7558
7715
|
// src/models/scallopIndexer.ts
|
|
7559
7716
|
import axios2 from "axios";
|
|
7560
|
-
import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
7561
7717
|
var ScallopIndexer = class {
|
|
7562
7718
|
constructor(params, instance) {
|
|
7563
7719
|
this.params = params;
|
|
7564
|
-
this.cache = instance?.cache ?? new ScallopCache(
|
|
7720
|
+
this.cache = instance?.cache ?? new ScallopCache(this.params);
|
|
7565
7721
|
this._requestClient = axios2.create({
|
|
7566
7722
|
baseURL: SDK_API_BASE_URL,
|
|
7567
7723
|
headers: {
|
|
@@ -7746,11 +7902,9 @@ var ScallopQuery = class {
|
|
|
7746
7902
|
this.address = instance.utils.address;
|
|
7747
7903
|
this.cache = this.address.cache;
|
|
7748
7904
|
} else {
|
|
7749
|
-
this.cache = new ScallopCache(
|
|
7750
|
-
this.suiKit
|
|
7751
|
-
|
|
7752
|
-
DEFAULT_CACHE_OPTIONS
|
|
7753
|
-
);
|
|
7905
|
+
this.cache = new ScallopCache(this.params, {
|
|
7906
|
+
suiKit: this.suiKit
|
|
7907
|
+
});
|
|
7754
7908
|
this.address = new ScallopAddress(
|
|
7755
7909
|
{
|
|
7756
7910
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -8105,7 +8259,13 @@ var ScallopQuery = class {
|
|
|
8105
8259
|
* @return All lending and spool infomation.
|
|
8106
8260
|
*/
|
|
8107
8261
|
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, args) {
|
|
8108
|
-
return await getLendings(
|
|
8262
|
+
return await getLendings(
|
|
8263
|
+
this,
|
|
8264
|
+
poolCoinNames,
|
|
8265
|
+
ownerAddress,
|
|
8266
|
+
args?.marketPools,
|
|
8267
|
+
args?.indexer
|
|
8268
|
+
);
|
|
8109
8269
|
}
|
|
8110
8270
|
/**
|
|
8111
8271
|
* Get user lending and spool information for specific pool.
|
|
@@ -8129,7 +8289,12 @@ var ScallopQuery = class {
|
|
|
8129
8289
|
* @return All obligation accounts information.
|
|
8130
8290
|
*/
|
|
8131
8291
|
async getObligationAccounts(ownerAddress = this.walletAddress, args) {
|
|
8132
|
-
return await getObligationAccounts(
|
|
8292
|
+
return await getObligationAccounts(
|
|
8293
|
+
this,
|
|
8294
|
+
ownerAddress,
|
|
8295
|
+
args?.market,
|
|
8296
|
+
args?.indexer
|
|
8297
|
+
);
|
|
8133
8298
|
}
|
|
8134
8299
|
/**
|
|
8135
8300
|
* Get obligation account information for specific id.
|
|
@@ -8304,12 +8469,22 @@ var ScallopQuery = class {
|
|
|
8304
8469
|
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
8305
8470
|
}
|
|
8306
8471
|
/**
|
|
8307
|
-
* Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
|
|
8472
|
+
* Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
|
|
8308
8473
|
* @returns
|
|
8309
8474
|
*/
|
|
8310
8475
|
async getPoolAddresses() {
|
|
8311
8476
|
return getAllAddresses(this);
|
|
8312
8477
|
}
|
|
8478
|
+
/**
|
|
8479
|
+
* Get user portfolio
|
|
8480
|
+
*/
|
|
8481
|
+
async getUserPortfolio(args) {
|
|
8482
|
+
return getUserPortfolio(
|
|
8483
|
+
this,
|
|
8484
|
+
args?.walletAddress ?? this.walletAddress,
|
|
8485
|
+
args?.indexer ?? false
|
|
8486
|
+
);
|
|
8487
|
+
}
|
|
8313
8488
|
};
|
|
8314
8489
|
|
|
8315
8490
|
// src/models/scallopBuilder.ts
|
|
@@ -8326,11 +8501,9 @@ var ScallopBuilder = class {
|
|
|
8326
8501
|
this.address = this.utils.address;
|
|
8327
8502
|
this.cache = this.address.cache;
|
|
8328
8503
|
} else {
|
|
8329
|
-
this.cache = new ScallopCache(
|
|
8330
|
-
this.suiKit
|
|
8331
|
-
|
|
8332
|
-
DEFAULT_CACHE_OPTIONS
|
|
8333
|
-
);
|
|
8504
|
+
this.cache = new ScallopCache(this.params, {
|
|
8505
|
+
suiKit: this.suiKit
|
|
8506
|
+
});
|
|
8334
8507
|
this.address = new ScallopAddress(
|
|
8335
8508
|
{
|
|
8336
8509
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -8476,11 +8649,9 @@ var ScallopClient = class {
|
|
|
8476
8649
|
this.address = this.utils.address;
|
|
8477
8650
|
this.cache = this.address.cache;
|
|
8478
8651
|
} else {
|
|
8479
|
-
this.cache = new ScallopCache(
|
|
8480
|
-
this.suiKit
|
|
8481
|
-
|
|
8482
|
-
DEFAULT_CACHE_OPTIONS
|
|
8483
|
-
);
|
|
8652
|
+
this.cache = new ScallopCache(this.params, {
|
|
8653
|
+
suiKit: this.suiKit
|
|
8654
|
+
});
|
|
8484
8655
|
this.address = new ScallopAddress(
|
|
8485
8656
|
{
|
|
8486
8657
|
id: params?.addressesId ?? ADDRESSES_ID,
|
|
@@ -9154,15 +9325,18 @@ var ScallopClient = class {
|
|
|
9154
9325
|
|
|
9155
9326
|
// src/models/scallop.ts
|
|
9156
9327
|
var Scallop = class {
|
|
9157
|
-
constructor(params, cacheOptions,
|
|
9328
|
+
constructor(params, cacheOptions, queryClient) {
|
|
9158
9329
|
this.params = params;
|
|
9159
9330
|
this.suiKit = newSuiKit(params);
|
|
9160
9331
|
this.cache = new ScallopCache(
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9332
|
+
{
|
|
9333
|
+
...this.params,
|
|
9334
|
+
cacheOptions
|
|
9335
|
+
},
|
|
9336
|
+
{
|
|
9337
|
+
suiKit: this.suiKit,
|
|
9338
|
+
queryClient
|
|
9339
|
+
}
|
|
9166
9340
|
);
|
|
9167
9341
|
this.address = new ScallopAddress(
|
|
9168
9342
|
{
|
|
@@ -9272,8 +9446,6 @@ export {
|
|
|
9272
9446
|
BORROW_FEE_PROTOCOL_ID,
|
|
9273
9447
|
COIN_GECKGO_IDS,
|
|
9274
9448
|
DEFAULT_CACHE_OPTIONS,
|
|
9275
|
-
DEFAULT_INTERVAL_IN_MS,
|
|
9276
|
-
DEFAULT_TOKENS_PER_INTERVAL,
|
|
9277
9449
|
FlashLoanFeeObjectMap,
|
|
9278
9450
|
IS_VE_SCA_TEST,
|
|
9279
9451
|
MAX_LOCK_DURATION,
|
|
@@ -9308,11 +9480,9 @@ export {
|
|
|
9308
9480
|
ScallopQuery,
|
|
9309
9481
|
ScallopUtils,
|
|
9310
9482
|
TEST_ADDRESSES,
|
|
9311
|
-
TokenBucket,
|
|
9312
9483
|
UNLOCK_ROUND_DURATION,
|
|
9313
9484
|
USE_TEST_ADDRESS,
|
|
9314
9485
|
assetCoins,
|
|
9315
|
-
callWithRateLimit,
|
|
9316
9486
|
coinDecimals,
|
|
9317
9487
|
coinIds,
|
|
9318
9488
|
marketCoins,
|