@scallop-io/sui-scallop-sdk 0.46.40 → 0.46.42

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.
Files changed (61) hide show
  1. package/dist/builders/loyaltyProgramBuilder.d.ts +1 -1
  2. package/dist/builders/sCoinBuilder.d.ts +4 -0
  3. package/dist/constants/common.d.ts +3 -1
  4. package/dist/constants/enum.d.ts +12 -10
  5. package/dist/index.js +660 -97
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +658 -92
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/models/scallopBuilder.d.ts +16 -1
  10. package/dist/models/scallopClient.d.ts +5 -0
  11. package/dist/models/scallopQuery.d.ts +21 -2
  12. package/dist/models/scallopUtils.d.ts +32 -2
  13. package/dist/queries/portfolioQuery.d.ts +1 -1
  14. package/dist/queries/sCoinQuery.d.ts +27 -0
  15. package/dist/test.d.ts +1 -0
  16. package/dist/types/address.d.ts +8 -1
  17. package/dist/types/builder/core.d.ts +12 -4
  18. package/dist/types/builder/index.d.ts +6 -1
  19. package/dist/types/builder/sCoin.d.ts +37 -0
  20. package/dist/types/builder/spool.d.ts +2 -1
  21. package/dist/types/constant/common.d.ts +3 -2
  22. package/dist/types/constant/enum.d.ts +13 -1
  23. package/dist/types/query/core.d.ts +2 -1
  24. package/dist/types/query/index.d.ts +1 -0
  25. package/dist/types/query/portfolio.d.ts +1 -0
  26. package/dist/types/query/sCoin.d.ts +1 -0
  27. package/package.json +3 -3
  28. package/src/builders/coreBuilder.ts +72 -17
  29. package/src/builders/index.ts +5 -1
  30. package/src/builders/loyaltyProgramBuilder.ts +1 -1
  31. package/src/builders/referralBuilder.ts +1 -1
  32. package/src/builders/sCoinBuilder.ts +119 -0
  33. package/src/builders/spoolBuilder.ts +1 -1
  34. package/src/builders/vescaBuilder.ts +3 -3
  35. package/src/constants/common.ts +19 -5
  36. package/src/constants/enum.ts +98 -20
  37. package/src/constants/testAddress.ts +115 -21
  38. package/src/models/scallopAddress.ts +44 -3
  39. package/src/models/scallopBuilder.ts +43 -7
  40. package/src/models/scallopCache.ts +32 -4
  41. package/src/models/scallopClient.ts +121 -0
  42. package/src/models/scallopQuery.ts +46 -0
  43. package/src/models/scallopUtils.ts +56 -2
  44. package/src/queries/coreQuery.ts +10 -4
  45. package/src/queries/portfolioQuery.ts +26 -4
  46. package/src/queries/sCoinQuery.ts +94 -0
  47. package/src/queries/vescaQuery.ts +0 -1
  48. package/src/test.ts +19 -0
  49. package/src/types/address.ts +13 -0
  50. package/src/types/builder/core.ts +19 -4
  51. package/src/types/builder/index.ts +11 -3
  52. package/src/types/builder/sCoin.ts +61 -0
  53. package/src/types/builder/spool.ts +2 -0
  54. package/src/types/constant/common.ts +4 -1
  55. package/src/types/constant/enum.ts +17 -0
  56. package/src/types/query/core.ts +3 -0
  57. package/src/types/query/index.ts +1 -0
  58. package/src/types/query/portfolio.ts +1 -0
  59. package/src/types/query/sCoin.ts +1 -0
  60. package/src/utils/builder.ts +1 -1
  61. package/src/utils/util.ts +13 -17
package/dist/index.mjs CHANGED
@@ -1,11 +1,9 @@
1
1
  // src/constants/common.ts
2
- var API_BASE_URL = "https://sui.api.scallop.io";
2
+ var API_BASE_URL = "https://sui.apis.scallop.io";
3
3
  var SDK_API_BASE_URL = "https://sdk.api.scallop.io";
4
4
  var IS_VE_SCA_TEST = false;
5
- var ADDRESSES_ID = IS_VE_SCA_TEST ? (
6
- // ? ('65fb07c39c845425d71d7b18' as const)
7
- "65fb07c39c845425d71d7b18"
8
- ) : "664dfe22898c36c159e28bc8";
5
+ var USE_TEST_ADDRESS = false;
6
+ var ADDRESSES_ID = IS_VE_SCA_TEST || USE_TEST_ADDRESS ? "65fb07c39c845425d71d7b18" : "664dfe22898c36c159e28bc8";
9
7
  var PROTOCOL_OBJECT_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
10
8
  var BORROW_FEE_PROTOCOL_ID = IS_VE_SCA_TEST ? "0xc9f859f98ca352a11b97a038c4b4162bee437b8df8caa047990fe9cb03d4f778" : "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
11
9
  var SCA_COIN_TYPE = IS_VE_SCA_TEST ? `0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` : "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA";
@@ -48,6 +46,17 @@ var SUPPORT_SPOOLS = [
48
46
  "shasui",
49
47
  "svsui"
50
48
  ];
49
+ var SUPPORT_SCOIN = [
50
+ "ssui",
51
+ "susdc",
52
+ "susdt",
53
+ "safsui",
54
+ "shasui",
55
+ "svsui",
56
+ "seth",
57
+ "ssca",
58
+ "scetus"
59
+ ];
51
60
  var SUPPORT_SPOOLS_REWARDS = ["sui"];
52
61
  var SUPPORT_BORROW_INCENTIVE_POOLS = [
53
62
  "sui",
@@ -131,6 +140,17 @@ var marketCoins = {
131
140
  svsui: "svsui",
132
141
  ssca: "ssca"
133
142
  };
143
+ var sCoins = {
144
+ seth: "seth",
145
+ susdc: "susdc",
146
+ susdt: "susdt",
147
+ ssui: "ssui",
148
+ scetus: "scetus",
149
+ safsui: "safsui",
150
+ shasui: "shasui",
151
+ svsui: "svsui",
152
+ ssca: "ssca"
153
+ };
134
154
  var stakeMarketCoins = {
135
155
  seth: "seth",
136
156
  ssui: "ssui",
@@ -186,6 +206,17 @@ var wormholeCoinIds = {
186
206
  var voloCoinIds = {
187
207
  vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
188
208
  };
209
+ var sCoinIds = {
210
+ ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
211
+ scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
212
+ ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
213
+ susdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
214
+ susdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
215
+ seth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
216
+ safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
217
+ shasui: "0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI",
218
+ svsui: "0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI"
219
+ };
189
220
 
190
221
  // src/constants/vesca.ts
191
222
  var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
@@ -215,7 +246,11 @@ import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
215
246
 
216
247
  // src/models/scallopCache.ts
217
248
  import { QueryClient } from "@tanstack/query-core";
218
- import { SuiTxBlock, normalizeStructTag } from "@scallop-io/sui-kit";
249
+ import {
250
+ SuiTxBlock,
251
+ normalizeStructTag,
252
+ normalizeSuiAddress
253
+ } from "@scallop-io/sui-kit";
219
254
 
220
255
  // src/constants/cache.ts
221
256
  var DEFAULT_CACHE_OPTIONS = {
@@ -331,6 +366,8 @@ var ScallopCache = class {
331
366
  * @returns Promise<SuiObjectData[]>
332
367
  */
333
368
  async queryGetObjects(objectIds, options) {
369
+ if (objectIds.length === 0)
370
+ return [];
334
371
  const queryKey = [
335
372
  "getObjects",
336
373
  JSON.stringify(objectIds),
@@ -407,7 +444,7 @@ var ScallopCache = class {
407
444
  queryKey,
408
445
  queryFn: async () => {
409
446
  const allBalances = await this.suiKit.client().getAllBalances({ owner });
410
- return allBalances.reduce(
447
+ const balances = allBalances.reduce(
411
448
  (acc, coinBalance) => {
412
449
  if (coinBalance.totalBalance !== "0") {
413
450
  acc[normalizeStructTag(coinBalance.coinType)] = coinBalance.totalBalance;
@@ -416,11 +453,30 @@ var ScallopCache = class {
416
453
  },
417
454
  {}
418
455
  );
419
- }
456
+ for (const coinType in balances) {
457
+ const coinBalanceQueryKey = [
458
+ "getCoinBalance",
459
+ normalizeSuiAddress(owner),
460
+ normalizeStructTag(coinType)
461
+ ];
462
+ this.queryClient.setQueryData(
463
+ coinBalanceQueryKey,
464
+ balances[coinType]
465
+ );
466
+ }
467
+ return balances;
468
+ },
469
+ staleTime: 5e3
420
470
  });
421
471
  }
422
472
  async queryGetCoinBalance(input) {
423
- const queryKey = ["getCoinBalance", input.owner, input.coinType];
473
+ if (!input.coinType)
474
+ return "0";
475
+ const queryKey = [
476
+ "getCoinBalance",
477
+ normalizeSuiAddress(input.owner),
478
+ normalizeStructTag(input.coinType)
479
+ ];
424
480
  return this.queryClient.fetchQuery({
425
481
  queryKey,
426
482
  queryFn: async () => {
@@ -438,13 +494,21 @@ import axios from "axios";
438
494
  // src/constants/testAddress.ts
439
495
  var TEST_ADDRESSES = {
440
496
  core: {
441
- version: "0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7",
497
+ // version:
498
+ // '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
499
+ version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
442
500
  versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
443
- object: "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf",
444
- market: "0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9",
501
+ // object:
502
+ // '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
503
+ object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
504
+ // market:
505
+ // '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
506
+ market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
445
507
  adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
446
508
  coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
447
- obligationAccessStore: "0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9",
509
+ // obligationAccessStore:
510
+ // '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
511
+ obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
448
512
  coins: {
449
513
  cetus: {
450
514
  id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
@@ -634,15 +698,25 @@ var TEST_ADDRESSES = {
634
698
  upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
635
699
  },
636
700
  protocol: {
637
- id: "0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e",
701
+ id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
638
702
  upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
639
703
  },
704
+ // protocol: {
705
+ // id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
706
+ // upgradeCap:
707
+ // '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
708
+ // },
640
709
  protocolWhitelist: {
641
710
  id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
642
711
  upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
643
712
  },
713
+ // query: {
714
+ // id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
715
+ // upgradeCap:
716
+ // '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
717
+ // },
644
718
  query: {
645
- id: "0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f",
719
+ id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
646
720
  upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
647
721
  },
648
722
  supra: { id: "", upgradeCap: "" },
@@ -659,41 +733,68 @@ var TEST_ADDRESSES = {
659
733
  }
660
734
  },
661
735
  spool: {
662
- id: "0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3",
736
+ // id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
737
+ id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
663
738
  adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
664
- object: "0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a",
739
+ // object:
740
+ // '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
741
+ object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
665
742
  pools: {
666
743
  seth: {
667
744
  id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
668
745
  rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
669
746
  },
670
747
  ssui: {
671
- id: "0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4",
672
- rewardPoolId: "0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9"
748
+ // id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
749
+ id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
750
+ rewardPoolId: (
751
+ // '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
752
+ "0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
753
+ )
673
754
  },
674
755
  susdc: {
675
- id: "0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0",
676
- rewardPoolId: "0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8"
756
+ // id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
757
+ id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
758
+ rewardPoolId: (
759
+ // '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
760
+ "0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
761
+ )
677
762
  },
678
763
  susdt: {
679
- id: "0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f",
680
- rewardPoolId: "0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080"
764
+ // id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
765
+ id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
766
+ rewardPoolId: (
767
+ // '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
768
+ "0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
769
+ )
681
770
  },
682
771
  scetus: {
683
772
  id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
684
773
  rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
685
774
  },
686
775
  safsui: {
687
- id: "0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800",
688
- rewardPoolId: "0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e"
776
+ // id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
777
+ id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
778
+ rewardPoolId: (
779
+ // '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
780
+ "0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
781
+ )
689
782
  },
690
783
  shasui: {
691
- id: "0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa",
692
- rewardPoolId: "0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66"
784
+ // id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
785
+ id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
786
+ rewardPoolId: (
787
+ // '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
788
+ "0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
789
+ )
693
790
  },
694
791
  svsui: {
695
- id: "0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670",
696
- rewardPoolId: "0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a"
792
+ // id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
793
+ id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
794
+ rewardPoolId: (
795
+ // '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
796
+ "0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
797
+ )
697
798
  }
698
799
  },
699
800
  config: ""
@@ -717,7 +818,9 @@ var TEST_ADDRESSES = {
717
818
  revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
718
819
  referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
719
820
  tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
720
- authorizedWitnessList: "0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e",
821
+ // authorizedWitnessList:
822
+ // '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
823
+ authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
721
824
  version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
722
825
  },
723
826
  vesca: {
@@ -734,6 +837,47 @@ var TEST_ADDRESSES = {
734
837
  object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
735
838
  rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
736
839
  userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
840
+ },
841
+ scoin: {
842
+ id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
843
+ coins: {
844
+ ssui: {
845
+ coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
846
+ treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
847
+ },
848
+ scetus: {
849
+ coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
850
+ treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
851
+ },
852
+ ssca: {
853
+ coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
854
+ treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
855
+ },
856
+ susdc: {
857
+ coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
858
+ treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
859
+ },
860
+ susdt: {
861
+ coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
862
+ treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
863
+ },
864
+ seth: {
865
+ coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
866
+ treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
867
+ },
868
+ safsui: {
869
+ coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
870
+ treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
871
+ },
872
+ shasui: {
873
+ coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
874
+ treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
875
+ },
876
+ svsui: {
877
+ coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
878
+ treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
879
+ }
880
+ }
737
881
  }
738
882
  };
739
883
 
@@ -1036,6 +1180,47 @@ var EMPTY_ADDRESSES = {
1036
1180
  object: "",
1037
1181
  rewardPool: "",
1038
1182
  userRewardTableId: ""
1183
+ },
1184
+ scoin: {
1185
+ id: "",
1186
+ coins: {
1187
+ ssui: {
1188
+ coinType: "",
1189
+ treasury: ""
1190
+ },
1191
+ scetus: {
1192
+ coinType: "",
1193
+ treasury: ""
1194
+ },
1195
+ ssca: {
1196
+ coinType: "",
1197
+ treasury: ""
1198
+ },
1199
+ susdc: {
1200
+ coinType: "",
1201
+ treasury: ""
1202
+ },
1203
+ susdt: {
1204
+ coinType: "",
1205
+ treasury: ""
1206
+ },
1207
+ seth: {
1208
+ coinType: "",
1209
+ treasury: ""
1210
+ },
1211
+ safsui: {
1212
+ coinType: "",
1213
+ treasury: ""
1214
+ },
1215
+ shasui: {
1216
+ coinType: "",
1217
+ treasury: ""
1218
+ },
1219
+ svsui: {
1220
+ coinType: "",
1221
+ treasury: ""
1222
+ }
1223
+ }
1039
1224
  }
1040
1225
  };
1041
1226
  var ScallopAddress = class {
@@ -1054,8 +1239,8 @@ var ScallopAddress = class {
1054
1239
  this._auth = auth;
1055
1240
  this._id = id;
1056
1241
  this._network = network || "mainnet";
1057
- this._addressesMap = IS_VE_SCA_TEST ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
1058
- if (IS_VE_SCA_TEST)
1242
+ this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
1243
+ if (USE_TEST_ADDRESS)
1059
1244
  this._currentAddresses = TEST_ADDRESSES;
1060
1245
  }
1061
1246
  /**
@@ -1344,7 +1529,7 @@ var ScallopAddress = class {
1344
1529
  };
1345
1530
 
1346
1531
  // src/models/scallopClient.ts
1347
- import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
1532
+ import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui.js/utils";
1348
1533
  import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
1349
1534
 
1350
1535
  // src/models/scallopUtils.ts
@@ -1388,7 +1573,6 @@ var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, pre
1388
1573
  const availableLockPeriodInDays = Math.floor(
1389
1574
  (newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
1390
1575
  );
1391
- console.log("availableLockPeriodInDays", availableLockPeriodInDays);
1392
1576
  if (lockPeriodInDays > availableLockPeriodInDays) {
1393
1577
  throw new Error(
1394
1578
  `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}`
@@ -1847,16 +2031,18 @@ var estimatedFactor = (amount, scaleStep, type) => {
1847
2031
  };
1848
2032
 
1849
2033
  // src/utils/util.ts
2034
+ var COIN_SET = Array.from(
2035
+ /* @__PURE__ */ new Set([
2036
+ ...SUPPORT_POOLS,
2037
+ ...SUPPORT_COLLATERALS,
2038
+ ...SUPPORT_SPOOLS_REWARDS,
2039
+ ...SUPPORT_BORROW_INCENTIVE_REWARDS,
2040
+ ...SUPPORT_SCOIN
2041
+ ])
2042
+ );
1850
2043
  var isMarketCoin = (coinName) => {
1851
2044
  const assetCoinName = coinName.slice(1).toLowerCase();
1852
- return coinName.charAt(0).toLowerCase() === "s" && [
1853
- .../* @__PURE__ */ new Set([
1854
- ...SUPPORT_POOLS,
1855
- ...SUPPORT_COLLATERALS,
1856
- ...SUPPORT_SPOOLS_REWARDS,
1857
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
1858
- ])
1859
- ].includes(assetCoinName);
2045
+ return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
1860
2046
  };
1861
2047
  var parseAssetSymbol = (coinName) => {
1862
2048
  switch (coinName) {
@@ -1871,14 +2057,7 @@ var parseAssetSymbol = (coinName) => {
1871
2057
  }
1872
2058
  };
1873
2059
  var parseDataFromPythPriceFeed = (feed, address) => {
1874
- const assetCoinNames = [
1875
- .../* @__PURE__ */ new Set([
1876
- ...SUPPORT_POOLS,
1877
- ...SUPPORT_COLLATERALS,
1878
- ...SUPPORT_SPOOLS_REWARDS,
1879
- ...SUPPORT_BORROW_INCENTIVE_REWARDS
1880
- ])
1881
- ];
2060
+ const assetCoinNames = COIN_SET;
1882
2061
  const assetCoinName = assetCoinNames.find((assetCoinName2) => {
1883
2062
  return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
1884
2063
  });
@@ -2152,7 +2331,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2152
2331
  }
2153
2332
  }
2154
2333
  }
2155
- if (balanceSheet && borrowIndex && interestModel && borrowFeeRate) {
2334
+ if (balanceSheet && borrowIndex && interestModel && (USE_TEST_ADDRESS || borrowFeeRate)) {
2156
2335
  const parsedMarketPoolData = parseOriginMarketPoolData({
2157
2336
  type: interestModel.type.fields,
2158
2337
  maxBorrowRate: interestModel.max_borrow_rate.fields,
@@ -2166,7 +2345,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
2166
2345
  reserve: balanceSheet.revenue,
2167
2346
  reserveFactor: interestModel.revenue_factor.fields,
2168
2347
  borrowWeight: interestModel.borrow_weight.fields,
2169
- borrowFeeRate,
2348
+ borrowFeeRate: borrowFeeRate || { value: "0" },
2170
2349
  baseBorrowRatePerSec: interestModel.base_borrow_rate_per_sec.fields,
2171
2350
  borrowRateOnHighKink: interestModel.borrow_rate_on_high_kink.fields,
2172
2351
  borrowRateOnMidKink: interestModel.borrow_rate_on_mid_kink.fields,
@@ -2202,10 +2381,10 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
2202
2381
  collateralCoinNames = collateralCoinNames || [...SUPPORT_COLLATERALS];
2203
2382
  const marketId = query.address.get("core.market");
2204
2383
  const [marketObjectResponse, coinPrices] = await Promise.all([
2205
- query.cache.queryGetObject(marketId, {
2384
+ await query.cache.queryGetObject(marketId, {
2206
2385
  showContent: true
2207
2386
  }),
2208
- query.utils.getCoinPrices(collateralCoinNames ?? [])
2387
+ await query.utils.getCoinPrices(collateralCoinNames ?? [])
2209
2388
  ]);
2210
2389
  const marketCollaterals = {};
2211
2390
  if (indexer) {
@@ -3144,7 +3323,7 @@ var getLendings = async (query, poolCoinNames, ownerAddress, indexer = false) =>
3144
3323
  );
3145
3324
  return lendings;
3146
3325
  };
3147
- var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice) => {
3326
+ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, marketPool, spool, stakeAccounts, coinAmount, marketCoinAmount, coinPrice, sCoinAmount) => {
3148
3327
  const marketCoinName = query.utils.parseMarketCoinName(poolCoinName);
3149
3328
  marketPool = marketPool || await query.getMarketPool(poolCoinName, indexer);
3150
3329
  spool = spool || SUPPORT_SPOOLS.includes(marketCoinName) ? await query.getSpool(marketCoinName, indexer) : void 0;
@@ -3154,6 +3333,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3154
3333
  ) : [];
3155
3334
  coinAmount = coinAmount || await query.getCoinAmount(poolCoinName, ownerAddress);
3156
3335
  marketCoinAmount = marketCoinAmount || await query.getMarketCoinAmount(marketCoinName, ownerAddress);
3336
+ sCoinAmount = sCoinAmount || await query.getSCoinAmount(marketCoinName, ownerAddress);
3157
3337
  coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
3158
3338
  const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
3159
3339
  let stakedMarketAmount = BigNumber4(0);
@@ -3205,9 +3385,7 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
3205
3385
  );
3206
3386
  }
3207
3387
  }
3208
- const suppliedAmount = BigNumber4(marketCoinAmount).multipliedBy(
3209
- marketPool?.conversionRate ?? 1
3210
- );
3388
+ const suppliedAmount = BigNumber4(marketCoinAmount).plus(BigNumber4(sCoinAmount)).multipliedBy(marketPool?.conversionRate ?? 1);
3211
3389
  const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
3212
3390
  const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
3213
3391
  const marketCoinPrice = BigNumber4(coinPrice ?? 0).multipliedBy(
@@ -3309,6 +3487,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3309
3487
  let totalBorrowCapacityValue = BigNumber4(0);
3310
3488
  let totalRequiredCollateralValue = BigNumber4(0);
3311
3489
  let totalBorrowedPools = 0;
3490
+ let totalRewardedPools = 0;
3312
3491
  let totalBorrowedValue = BigNumber4(0);
3313
3492
  let totalBorrowedValueWithWeight = BigNumber4(0);
3314
3493
  for (const assetCoinName of collateralAssetCoinNames) {
@@ -3470,6 +3649,12 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3470
3649
  }
3471
3650
  }
3472
3651
  }
3652
+ if (Object.keys(borrowIncentivePool.points).some((coinName2) => {
3653
+ const rewardApr = borrowIncentivePool.points[coinName2]?.rewardApr;
3654
+ return rewardApr !== Infinity && typeof rewardApr == "number" && rewardApr > 0;
3655
+ }) && borrowIncentiveAccount.debtAmount > 0) {
3656
+ totalRewardedPools++;
3657
+ }
3473
3658
  borrowIncentives[coinName] = {
3474
3659
  coinName: borrowIncentivePool.coinName,
3475
3660
  coinType: borrowIncentivePool.coinType,
@@ -3507,6 +3692,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
3507
3692
  totalRiskLevel: riskLevel.toNumber(),
3508
3693
  totalDepositedPools,
3509
3694
  totalBorrowedPools,
3695
+ totalRewardedPools,
3510
3696
  collaterals,
3511
3697
  debts,
3512
3698
  borrowIncentives
@@ -3749,7 +3935,6 @@ var getVeScaTreasuryInfo = async (query) => {
3749
3935
  if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== "moveObject")
3750
3936
  return null;
3751
3937
  const treasuryFields = veScaTreasury.data.content.fields;
3752
- console.log(treasuryFields);
3753
3938
  const totalLockedSca = BigNumber5(
3754
3939
  treasuryFields.unlock_schedule.fields.locked_sca_amount
3755
3940
  ).shiftedBy(-9).toNumber();
@@ -4001,6 +4186,56 @@ var ScallopIndexer = class {
4001
4186
  }
4002
4187
  };
4003
4188
 
4189
+ // src/queries/sCoinQuery.ts
4190
+ import { bcs as bcs2 } from "@mysten/sui.js/bcs";
4191
+ import assert from "assert";
4192
+ import BigNumber7 from "bignumber.js";
4193
+ var getSCoinTotalSupply = async (query, sCoinName) => {
4194
+ const sCoinPkgId = query.address.get("scoin.id");
4195
+ const args = [query.utils.getSCoinTreasury(sCoinName)];
4196
+ const typeArgs = [
4197
+ query.utils.parseSCoinType(sCoinName),
4198
+ query.utils.parseUnderlyingSCoinType(sCoinName)
4199
+ ];
4200
+ const queryTarget = `${sCoinPkgId}::s_coin_converter::total_supply`;
4201
+ const queryResults = await query.cache.queryInspectTxn({
4202
+ queryTarget,
4203
+ args,
4204
+ typeArgs
4205
+ });
4206
+ const results = queryResults.results;
4207
+ if (results && results[0].returnValues) {
4208
+ const value = Uint8Array.from(results[0].returnValues[0][0]);
4209
+ const type = results[0].returnValues[0][1];
4210
+ assert(type === "u64", "Result type is not u64");
4211
+ return BigNumber7(bcs2.de(type, value)).shiftedBy(
4212
+ query.utils.getCoinDecimal(query.utils.parseCoinName(sCoinName))
4213
+ ).toNumber();
4214
+ }
4215
+ return 0;
4216
+ };
4217
+ var getSCoinAmounts = async (query, sCoinNames, ownerAddress) => {
4218
+ sCoinNames = sCoinNames || [...SUPPORT_SCOIN];
4219
+ const owner = ownerAddress || query.suiKit.currentAddress();
4220
+ const sCoins2 = {};
4221
+ await Promise.allSettled(
4222
+ sCoinNames.map(async (sCoinName) => {
4223
+ const sCoin = await getSCoinAmount(query, sCoinName, owner);
4224
+ sCoins2[sCoinName] = sCoin;
4225
+ })
4226
+ );
4227
+ return sCoins2;
4228
+ };
4229
+ var getSCoinAmount = async (query, sCoinName, ownerAddress) => {
4230
+ const owner = ownerAddress || query.suiKit.currentAddress();
4231
+ const sCoinType = query.utils.parseSCoinType(sCoinName);
4232
+ const amount = await query.cache.queryGetCoinBalance({
4233
+ owner,
4234
+ coinType: sCoinType
4235
+ });
4236
+ return BigNumber7(amount).toNumber();
4237
+ };
4238
+
4004
4239
  // src/models/scallopQuery.ts
4005
4240
  var ScallopQuery = class {
4006
4241
  constructor(params, instance) {
@@ -4417,6 +4652,35 @@ var ScallopQuery = class {
4417
4652
  return await getLoyaltyProgramInformations(this, veScaKey);
4418
4653
  }
4419
4654
  /**
4655
+ * Get total supply of sCoin
4656
+ * @param sCoinName - Supported sCoin name
4657
+ * @returns Total Supply
4658
+ */
4659
+ async getSCoinTotalSupply(sCoinName) {
4660
+ return await getSCoinTotalSupply(this, sCoinName);
4661
+ }
4662
+ /**
4663
+ * Get all sCoin amounts.
4664
+ *
4665
+ * @param sCoinNames - Specific an array of support sCoin name.
4666
+ * @param ownerAddress - The owner address.
4667
+ * @return All market sCoin amounts.
4668
+ */
4669
+ async getSCoinAmounts(sCoinNames, ownerAddress) {
4670
+ return await getSCoinAmounts(this, sCoinNames, ownerAddress);
4671
+ }
4672
+ /**
4673
+ * Get sCoin amount.
4674
+ *
4675
+ * @param coinNames - Specific support sCoin name.
4676
+ * @param ownerAddress - The owner address.
4677
+ * @return sCoin amount.
4678
+ */
4679
+ async getSCoinAmount(sCoinName, ownerAddress) {
4680
+ const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
4681
+ return parsedSCoinName ? await getSCoinAmount(this, parsedSCoinName, ownerAddress) : 0;
4682
+ }
4683
+ /*
4420
4684
  * Get flashloan fee for specified assets
4421
4685
  */
4422
4686
  async getFlashLoanFees(assetCoinNames = [...SUPPORT_POOLS]) {
@@ -4537,6 +4801,48 @@ var ScallopUtils = class {
4537
4801
  return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;
4538
4802
  }
4539
4803
  }
4804
+ /**
4805
+ * Convert coin name to sCoin name.
4806
+ *
4807
+ * @param coinName - Specific support coin name.
4808
+ * @return sCoin name.
4809
+ */
4810
+ parseSCoinName(coinName) {
4811
+ if (isMarketCoin(coinName) && SUPPORT_SCOIN.includes(coinName)) {
4812
+ return coinName;
4813
+ } else {
4814
+ const marketCoinName = `s${coinName}`;
4815
+ if (SUPPORT_SCOIN.includes(marketCoinName)) {
4816
+ return marketCoinName;
4817
+ }
4818
+ return void 0;
4819
+ }
4820
+ }
4821
+ /**
4822
+ * Convert sCoin name into sCoin type
4823
+ * @param sCoinName
4824
+ * @returns sCoin type
4825
+ */
4826
+ parseSCoinType(sCoinName) {
4827
+ return sCoinIds[sCoinName];
4828
+ }
4829
+ /**
4830
+ * Convert sCoin name into its underlying coin type
4831
+ * @param sCoinName
4832
+ * @returns coin type
4833
+ */
4834
+ parseUnderlyingSCoinType(sCoinName) {
4835
+ const coinName = this.parseCoinName(sCoinName);
4836
+ return this.parseCoinType(coinName);
4837
+ }
4838
+ /**
4839
+ * Get sCoin treasury id from sCoin name
4840
+ * @param sCoinName
4841
+ * @returns sCoin treasury id
4842
+ */
4843
+ getSCoinTreasury(sCoinName) {
4844
+ return this._address.get(`scoin.coins.${sCoinName}.treasury`);
4845
+ }
4540
4846
  /**
4541
4847
  * Convert coin name to market coin type.
4542
4848
  *
@@ -4614,14 +4920,14 @@ var ScallopUtils = class {
4614
4920
  * @param coinType - The coin type, default is 0x2::SUI::SUI.
4615
4921
  * @return The selected transaction coin arguments.
4616
4922
  */
4617
- async selectCoinIds(amount, coinType = SUI_TYPE_ARG, ownerAddress) {
4923
+ async selectCoins(amount, coinType = SUI_TYPE_ARG, ownerAddress) {
4618
4924
  ownerAddress = ownerAddress || this._suiKit.currentAddress();
4619
4925
  const coins = await this._suiKit.suiInteractor.selectCoins(
4620
4926
  ownerAddress,
4621
4927
  amount,
4622
4928
  coinType
4623
4929
  );
4624
- return coins.map((c) => c.objectId);
4930
+ return coins;
4625
4931
  }
4626
4932
  /**
4627
4933
  * Get all asset coin names in the obligation record by obligation id.
@@ -4795,7 +5101,7 @@ var ScallopUtils = class {
4795
5101
  };
4796
5102
 
4797
5103
  // src/models/scallopBuilder.ts
4798
- import { normalizeSuiAddress } from "@mysten/sui.js/utils";
5104
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
4799
5105
  import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
4800
5106
 
4801
5107
  // src/builders/coreBuilder.ts
@@ -4977,10 +5283,13 @@ var generateCoreNormalMethod = ({
4977
5283
  const referralPkgId = builder.address.get("referral.id");
4978
5284
  const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
4979
5285
  return {
4980
- openObligation: () => txBlock.moveCall(
4981
- `${coreIds.protocolPkg}::open_obligation::open_obligation`,
4982
- [coreIds.version]
4983
- ),
5286
+ openObligation: () => {
5287
+ const [obligation, obligationKey, obligationHotPotato] = txBlock.moveCall(
5288
+ `${coreIds.protocolPkg}::open_obligation::open_obligation`,
5289
+ [coreIds.version]
5290
+ );
5291
+ return [obligation, obligationKey, obligationHotPotato];
5292
+ },
4984
5293
  returnObligation: (obligation, obligationHotPotato) => txBlock.moveCall(
4985
5294
  `${coreIds.protocolPkg}::open_obligation::return_obligation`,
4986
5295
  [coreIds.version, obligation, obligationHotPotato]
@@ -5174,11 +5483,12 @@ var generateCoreQuickMethod = ({
5174
5483
  collateralCoinName
5175
5484
  );
5176
5485
  },
5177
- depositQuick: async (amount, poolCoinName) => {
5486
+ depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
5178
5487
  const sender = requireSender(txBlock);
5488
+ let marketCoinDeposit;
5179
5489
  if (poolCoinName === "sui") {
5180
5490
  const [suiCoin] = txBlock.splitSUIFromGas([amount]);
5181
- return txBlock.deposit(suiCoin, poolCoinName);
5491
+ marketCoinDeposit = txBlock.deposit(suiCoin, poolCoinName);
5182
5492
  } else {
5183
5493
  const { leftCoin, takeCoin } = await builder.selectCoin(
5184
5494
  txBlock,
@@ -5187,20 +5497,56 @@ var generateCoreQuickMethod = ({
5187
5497
  sender
5188
5498
  );
5189
5499
  txBlock.transferObjects([leftCoin], sender);
5190
- return txBlock.deposit(takeCoin, poolCoinName);
5500
+ marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
5191
5501
  }
5502
+ return returnSCoin ? txBlock.mintSCoin(
5503
+ builder.utils.parseMarketCoinName(poolCoinName),
5504
+ marketCoinDeposit
5505
+ ) : marketCoinDeposit;
5192
5506
  },
5193
5507
  withdrawQuick: async (amount, poolCoinName) => {
5194
5508
  const sender = requireSender(txBlock);
5195
5509
  const marketCoinName = builder.utils.parseMarketCoinName(poolCoinName);
5196
- const { leftCoin, takeCoin } = await builder.selectMarketCoin(
5197
- txBlock,
5198
- marketCoinName,
5199
- amount,
5200
- sender
5201
- );
5202
- txBlock.transferObjects([leftCoin], sender);
5203
- return txBlock.withdraw(takeCoin, poolCoinName);
5510
+ try {
5511
+ const sCoinName = builder.utils.parseSCoinName(poolCoinName);
5512
+ if (!sCoinName)
5513
+ throw new Error(`No sCoin for ${poolCoinName}`);
5514
+ const { leftCoin, takeCoin, totalAmount } = await builder.selectSCoin(
5515
+ txBlock,
5516
+ sCoinName,
5517
+ amount,
5518
+ sender
5519
+ );
5520
+ txBlock.transferObjects([leftCoin], sender);
5521
+ const marketCoin = txBlock.burnSCoin(sCoinName, takeCoin);
5522
+ const txResult = txBlock.withdraw(marketCoin, poolCoinName);
5523
+ amount -= totalAmount;
5524
+ try {
5525
+ if (amount > 0) {
5526
+ const { leftCoin: leftCoin2, takeCoin: takeCoin2 } = await builder.selectMarketCoin(
5527
+ txBlock,
5528
+ marketCoinName,
5529
+ amount,
5530
+ sender
5531
+ );
5532
+ txBlock.transferObjects([leftCoin2], sender);
5533
+ txBlock.mergeCoins(txResult, [
5534
+ txBlock.withdraw(takeCoin2, poolCoinName)
5535
+ ]);
5536
+ }
5537
+ } catch (e) {
5538
+ }
5539
+ return txResult;
5540
+ } catch (e) {
5541
+ const { leftCoin, takeCoin } = await builder.selectMarketCoin(
5542
+ txBlock,
5543
+ marketCoinName,
5544
+ amount,
5545
+ sender
5546
+ );
5547
+ txBlock.transferObjects([leftCoin], sender);
5548
+ return txBlock.withdraw(takeCoin, poolCoinName);
5549
+ }
5204
5550
  },
5205
5551
  borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
5206
5552
  const obligationInfo = await requireObligationInfo(
@@ -5404,7 +5750,7 @@ var generateSpoolQuickMethod = ({
5404
5750
  );
5405
5751
  const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
5406
5752
  if (typeof amountOrMarketCoin === "number") {
5407
- const coins = await builder.utils.selectCoinIds(
5753
+ const coins = await builder.utils.selectCoins(
5408
5754
  amountOrMarketCoin,
5409
5755
  marketCoinType,
5410
5756
  sender
@@ -5619,7 +5965,7 @@ var generateQuickVeScaMethod = ({
5619
5965
  let scaCoin = void 0;
5620
5966
  const transferObjects = [];
5621
5967
  if (amountOrCoin !== void 0 && typeof amountOrCoin === "number") {
5622
- const coins = await builder.utils.selectCoinIds(
5968
+ const coins = await builder.utils.selectCoins(
5623
5969
  amountOrCoin,
5624
5970
  SCA_COIN_TYPE,
5625
5971
  sender
@@ -5691,7 +6037,7 @@ var generateQuickVeScaMethod = ({
5691
6037
  if (autoCheck)
5692
6038
  checkExtendLockAmount(scaAmount, veSca?.unlockAt);
5693
6039
  if (veSca) {
5694
- const scaCoins = await builder.utils.selectCoinIds(
6040
+ const scaCoins = await builder.utils.selectCoins(
5695
6041
  scaAmount,
5696
6042
  SCA_COIN_TYPE,
5697
6043
  sender
@@ -5719,7 +6065,7 @@ var generateQuickVeScaMethod = ({
5719
6065
  const unlockedSca = txBlock.redeemSca(veSca.keyId);
5720
6066
  transferObjects.push(unlockedSca);
5721
6067
  }
5722
- const scaCoins = await builder.utils.selectCoinIds(
6068
+ const scaCoins = await builder.utils.selectCoins(
5723
6069
  scaAmount,
5724
6070
  SCA_COIN_TYPE,
5725
6071
  sender
@@ -6107,7 +6453,7 @@ var generateReferralQuickMethod = ({
6107
6453
  Infinity,
6108
6454
  builder.utils.parseCoinType(coinName)
6109
6455
  );
6110
- txBlock.mergeCoins(rewardCoin, coins);
6456
+ txBlock.mergeCoins(rewardCoin, coins.slice(0, 500));
6111
6457
  } catch (e) {
6112
6458
  } finally {
6113
6459
  objToTransfer.push(rewardCoin);
@@ -6225,6 +6571,98 @@ var newLoyaltyProgramTxBlock = (builder, initTxBlock) => {
6225
6571
  });
6226
6572
  };
6227
6573
 
6574
+ // src/builders/sCoinBuilder.ts
6575
+ import {
6576
+ TransactionBlock as TransactionBlock7,
6577
+ SuiTxBlock as SuiKitTxBlock7
6578
+ } from "@scallop-io/sui-kit";
6579
+ var generateSCoinNormalMethod = ({
6580
+ builder,
6581
+ txBlock
6582
+ }) => {
6583
+ const sCoinPkgIds = {
6584
+ pkgId: builder.address.get("scoin.id")
6585
+ };
6586
+ return {
6587
+ mintSCoin: (marketCoinName, marketCoin) => {
6588
+ return txBlock.moveCall(
6589
+ `${sCoinPkgIds.pkgId}::s_coin_converter::mint_s_coin`,
6590
+ [builder.utils.getSCoinTreasury(marketCoinName), marketCoin],
6591
+ [
6592
+ builder.utils.parseSCoinType(marketCoinName),
6593
+ builder.utils.parseUnderlyingSCoinType(marketCoinName)
6594
+ ]
6595
+ );
6596
+ },
6597
+ burnSCoin: (sCoinName, sCoin) => {
6598
+ return txBlock.moveCall(
6599
+ `${sCoinPkgIds.pkgId}::s_coin_converter::burn_s_coin`,
6600
+ [builder.utils.getSCoinTreasury(sCoinName), sCoin],
6601
+ [
6602
+ builder.utils.parseSCoinType(sCoinName),
6603
+ builder.utils.parseUnderlyingSCoinType(sCoinName)
6604
+ ]
6605
+ );
6606
+ }
6607
+ };
6608
+ };
6609
+ var generateSCoinQuickMethod = ({
6610
+ builder,
6611
+ txBlock
6612
+ }) => {
6613
+ return {
6614
+ mintSCoinQuick: async (marketCoinName, amount) => {
6615
+ const sender = requireSender(txBlock);
6616
+ const { leftCoin, takeCoin } = await builder.selectMarketCoin(
6617
+ txBlock,
6618
+ marketCoinName,
6619
+ amount,
6620
+ sender
6621
+ );
6622
+ txBlock.transferObjects([leftCoin], sender);
6623
+ return txBlock.mintSCoin(marketCoinName, takeCoin);
6624
+ },
6625
+ burnSCoinQuick: async (sCoinName, amount) => {
6626
+ const sender = requireSender(txBlock);
6627
+ const { leftCoin, takeCoin } = await builder.selectSCoin(
6628
+ txBlock,
6629
+ sCoinName,
6630
+ amount,
6631
+ sender
6632
+ );
6633
+ txBlock.transferObjects([leftCoin], sender);
6634
+ return txBlock.burnSCoin(sCoinName, takeCoin);
6635
+ }
6636
+ };
6637
+ };
6638
+ var newSCoinTxBlock = (builder, initTxBlock) => {
6639
+ const txBlock = initTxBlock instanceof TransactionBlock7 ? new SuiKitTxBlock7(initTxBlock) : initTxBlock ? initTxBlock : new SuiKitTxBlock7();
6640
+ const normalMethod = generateSCoinNormalMethod({
6641
+ builder,
6642
+ txBlock
6643
+ });
6644
+ const normalTxBlock = new Proxy(txBlock, {
6645
+ get: (target, prop) => {
6646
+ if (prop in normalMethod) {
6647
+ return Reflect.get(normalMethod, prop);
6648
+ }
6649
+ return Reflect.get(target, prop);
6650
+ }
6651
+ });
6652
+ const quickMethod = generateSCoinQuickMethod({
6653
+ builder,
6654
+ txBlock: normalTxBlock
6655
+ });
6656
+ return new Proxy(normalTxBlock, {
6657
+ get: (target, prop) => {
6658
+ if (prop in quickMethod) {
6659
+ return Reflect.get(quickMethod, prop);
6660
+ }
6661
+ return Reflect.get(target, prop);
6662
+ }
6663
+ });
6664
+ };
6665
+
6228
6666
  // src/builders/index.ts
6229
6667
  var newScallopTxBlock = (builder, initTxBlock) => {
6230
6668
  const vescaTxBlock = newVeScaTxBlock(builder, initTxBlock);
@@ -6235,7 +6673,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
6235
6673
  );
6236
6674
  const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
6237
6675
  const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
6238
- const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
6676
+ const sCoinTxBlock = newSCoinTxBlock(builder, spoolTxBlock);
6677
+ const coreTxBlock = newCoreTxBlock(builder, sCoinTxBlock);
6239
6678
  return new Proxy(coreTxBlock, {
6240
6679
  get: (target, prop) => {
6241
6680
  if (prop in vescaTxBlock) {
@@ -6248,6 +6687,8 @@ var newScallopTxBlock = (builder, initTxBlock) => {
6248
6687
  return Reflect.get(spoolTxBlock, prop);
6249
6688
  } else if (prop in loyaltyTxBlock) {
6250
6689
  return Reflect.get(loyaltyTxBlock, prop);
6690
+ } else if (prop in sCoinTxBlock) {
6691
+ return Reflect.get(sCoinTxBlock, prop);
6251
6692
  }
6252
6693
  return Reflect.get(target, prop);
6253
6694
  }
@@ -6278,7 +6719,7 @@ var ScallopBuilder = class {
6278
6719
  query: this.query,
6279
6720
  cache: this.cache
6280
6721
  });
6281
- this.walletAddress = normalizeSuiAddress(
6722
+ this.walletAddress = normalizeSuiAddress2(
6282
6723
  params?.walletAddress || this.suiKit.currentAddress()
6283
6724
  );
6284
6725
  this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
@@ -6318,7 +6759,7 @@ var ScallopBuilder = class {
6318
6759
  */
6319
6760
  async selectCoin(txBlock, assetCoinName, amount, sender) {
6320
6761
  const coinType = this.utils.parseCoinType(assetCoinName);
6321
- const coins = await this.utils.selectCoinIds(amount, coinType, sender);
6762
+ const coins = await this.utils.selectCoins(amount, coinType, sender);
6322
6763
  const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
6323
6764
  return { takeCoin, leftCoin };
6324
6765
  }
@@ -6333,13 +6774,42 @@ var ScallopBuilder = class {
6333
6774
  */
6334
6775
  async selectMarketCoin(txBlock, marketCoinName, amount, sender) {
6335
6776
  const marketCoinType = this.utils.parseMarketCoinType(marketCoinName);
6336
- const coins = await this.utils.selectCoinIds(
6337
- amount,
6338
- marketCoinType,
6339
- sender
6777
+ const coins = await this.utils.selectCoins(amount, marketCoinType, sender);
6778
+ const totalAmount = coins.reduce((prev, coin) => {
6779
+ prev += Number(coin.balance);
6780
+ return prev;
6781
+ }, 0);
6782
+ const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
6783
+ coins,
6784
+ Math.min(amount, totalAmount)
6340
6785
  );
6341
- const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
6342
- return { takeCoin, leftCoin };
6786
+ return { takeCoin, leftCoin, totalAmount };
6787
+ }
6788
+ /**
6789
+ * Specifying the sender's amount of sCoins to get coins args from transaction result.
6790
+ *
6791
+ * @param txBlock - Scallop txBlock or txBlock created by SuiKit .
6792
+ * @param marketCoinName - Specific support sCoin name.
6793
+ * @param amount - Amount of coins to be selected.
6794
+ * @param sender - Sender address.
6795
+ * @return Take coin and left coin.
6796
+ */
6797
+ async selectSCoin(txBlock, sCoinName, amount, sender) {
6798
+ const sCoinType = this.utils.parseSCoinType(sCoinName);
6799
+ const coins = await this.utils.selectCoins(amount, sCoinType, sender);
6800
+ const totalAmount = coins.reduce((prev, coin) => {
6801
+ prev += Number(coin.balance);
6802
+ return prev;
6803
+ }, 0);
6804
+ const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
6805
+ coins,
6806
+ Math.min(totalAmount, amount)
6807
+ );
6808
+ return {
6809
+ takeCoin,
6810
+ leftCoin,
6811
+ totalAmount
6812
+ };
6343
6813
  }
6344
6814
  /**
6345
6815
  * Execute Scallop txBlock using the `signAndSendTxn` methods in suikit.
@@ -6384,7 +6854,7 @@ var ScallopClient = class {
6384
6854
  utils: this.utils,
6385
6855
  cache: this.cache
6386
6856
  });
6387
- this.walletAddress = normalizeSuiAddress2(
6857
+ this.walletAddress = normalizeSuiAddress3(
6388
6858
  params?.walletAddress || this.suiKit.currentAddress()
6389
6859
  );
6390
6860
  }
@@ -6864,6 +7334,98 @@ var ScallopClient = class {
6864
7334
  return txBlock.txBlock;
6865
7335
  }
6866
7336
  }
7337
+ /* ==================== Migrate market coin to sCoin method ==================== */
7338
+ /**
7339
+ * Function to migrate all market coin in user wallet into sCoin
7340
+ * @returns Transaction response
7341
+ */
7342
+ async migrateAllMarketCoin(sign = true) {
7343
+ const txBlock = this.builder.createTxBlock();
7344
+ txBlock.setSender(this.walletAddress);
7345
+ const toTransfer = [];
7346
+ await Promise.all(
7347
+ SUPPORT_SCOIN.map(async (sCoinName) => {
7348
+ let toDestroyMarketCoin;
7349
+ try {
7350
+ const marketCoins2 = await this.utils.selectCoins(
7351
+ Number.MAX_SAFE_INTEGER,
7352
+ this.utils.parseMarketCoinType(sCoinName),
7353
+ this.walletAddress
7354
+ );
7355
+ const mergedMarketCoin = marketCoins2[0];
7356
+ if (marketCoins2.length > 1) {
7357
+ txBlock.mergeCoins(mergedMarketCoin, marketCoins2.slice(1));
7358
+ }
7359
+ toDestroyMarketCoin = mergedMarketCoin;
7360
+ } catch (e) {
7361
+ const errMsg = e.toString();
7362
+ if (!errMsg.includes("No valid coins found for the transaction"))
7363
+ throw e;
7364
+ }
7365
+ if (SUPPORT_SPOOLS.includes(sCoinName)) {
7366
+ try {
7367
+ const stakedMarketCoins = await txBlock.unstakeQuick(
7368
+ Number.MAX_SAFE_INTEGER,
7369
+ sCoinName
7370
+ );
7371
+ if (stakedMarketCoins.length > 0) {
7372
+ const mergedStakedMarketCoin = stakedMarketCoins[0];
7373
+ if (stakedMarketCoins.length > 1) {
7374
+ txBlock.mergeCoins(
7375
+ mergedStakedMarketCoin,
7376
+ stakedMarketCoins.slice(1)
7377
+ );
7378
+ }
7379
+ if (toDestroyMarketCoin) {
7380
+ txBlock.mergeCoins(toDestroyMarketCoin, [
7381
+ mergedStakedMarketCoin
7382
+ ]);
7383
+ } else {
7384
+ toDestroyMarketCoin = mergedStakedMarketCoin;
7385
+ }
7386
+ }
7387
+ } catch (e) {
7388
+ const errMsg = e.toString();
7389
+ if (!errMsg.includes("No stake account found"))
7390
+ throw e;
7391
+ }
7392
+ }
7393
+ if (toDestroyMarketCoin) {
7394
+ const sCoin = txBlock.mintSCoin(
7395
+ sCoinName,
7396
+ toDestroyMarketCoin
7397
+ );
7398
+ try {
7399
+ const existSCoins = await this.utils.selectCoins(
7400
+ Number.MAX_SAFE_INTEGER,
7401
+ this.utils.parseSCoinType(sCoinName),
7402
+ this.walletAddress
7403
+ );
7404
+ const mergedSCoin = existSCoins[0];
7405
+ if (existSCoins.length > 1) {
7406
+ txBlock.mergeCoins(mergedSCoin, existSCoins.slice(1));
7407
+ }
7408
+ txBlock.mergeCoins(sCoin, [mergedSCoin]);
7409
+ } catch (e) {
7410
+ const errMsg = e.toString();
7411
+ if (!errMsg.includes("No valid coins found for the transaction"))
7412
+ throw e;
7413
+ }
7414
+ toTransfer.push(sCoin);
7415
+ }
7416
+ })
7417
+ );
7418
+ if (toTransfer.length > 0) {
7419
+ txBlock.transferObjects(toTransfer, this.walletAddress);
7420
+ }
7421
+ if (sign) {
7422
+ return await this.suiKit.signAndSendTxn(
7423
+ txBlock
7424
+ );
7425
+ } else {
7426
+ return txBlock.txBlock;
7427
+ }
7428
+ }
6867
7429
  async mintTestCoin(assetCoinName, amount, sign = true, receiveAddress) {
6868
7430
  const isTestnet = this.params.networkType ? this.params.networkType === "testnet" : false;
6869
7431
  if (!isTestnet) {
@@ -7005,6 +7567,7 @@ export {
7005
7567
  SUPPORT_ORACLES,
7006
7568
  SUPPORT_PACKAGES,
7007
7569
  SUPPORT_POOLS,
7570
+ SUPPORT_SCOIN,
7008
7571
  SUPPORT_SPOOLS,
7009
7572
  SUPPORT_SPOOLS_REWARDS,
7010
7573
  Scallop,
@@ -7016,11 +7579,14 @@ export {
7016
7579
  ScallopQuery,
7017
7580
  ScallopUtils,
7018
7581
  UNLOCK_ROUND_DURATION,
7582
+ USE_TEST_ADDRESS,
7019
7583
  assetCoins,
7020
7584
  borrowIncentiveRewardCoins,
7021
7585
  coinDecimals,
7022
7586
  coinIds,
7023
7587
  marketCoins,
7588
+ sCoinIds,
7589
+ sCoins,
7024
7590
  spoolRewardCoins,
7025
7591
  stakeMarketCoins,
7026
7592
  voloCoinIds,