@scallop-io/sui-scallop-sdk 0.47.3 → 0.47.5

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/index.mjs CHANGED
@@ -11,6 +11,8 @@ var OLD_BORROW_INCENTIVE_PROTOCOL_ID = "0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d
11
11
  var SUPPORT_POOLS = [
12
12
  "usdc",
13
13
  // native USDC
14
+ "sbeth",
15
+ // native ETH
14
16
  "weth",
15
17
  "wbtc",
16
18
  "wusdc",
@@ -26,6 +28,9 @@ var SUPPORT_POOLS = [
26
28
  ];
27
29
  var SUPPORT_COLLATERALS = [
28
30
  "usdc",
31
+ // native USDC
32
+ "sbeth",
33
+ // native ETH
29
34
  "weth",
30
35
  "wbtc",
31
36
  "wusdc",
@@ -52,6 +57,7 @@ var SUPPORT_SPOOLS = [
52
57
  ];
53
58
  var SUPPORT_SCOIN = [
54
59
  "susdc",
60
+ "ssbeth",
55
61
  "ssui",
56
62
  "swusdc",
57
63
  "swusdt",
@@ -64,6 +70,15 @@ var SUPPORT_SCOIN = [
64
70
  "swsol",
65
71
  "swbtc"
66
72
  ];
73
+ var SUPPORT_SUI_BRIDGE = ["sbeth"];
74
+ var SUPPORT_WORMHOLE = [
75
+ "wusdc",
76
+ "wusdt",
77
+ "weth",
78
+ "wbtc",
79
+ "wapt",
80
+ "wsol"
81
+ ];
67
82
  var SUPPORT_SPOOLS_REWARDS = ["sui"];
68
83
  var SUPPORT_BORROW_INCENTIVE_POOLS = [
69
84
  "sui",
@@ -73,6 +88,7 @@ var SUPPORT_BORROW_INCENTIVE_POOLS = [
73
88
  "hasui",
74
89
  "vsui",
75
90
  "weth",
91
+ "sbeth",
76
92
  "sca",
77
93
  "usdc"
78
94
  ];
@@ -96,6 +112,7 @@ var SUPPORT_PACKAGES = [
96
112
  // src/constants/enum.ts
97
113
  var coinDecimals = {
98
114
  usdc: 6,
115
+ sbeth: 8,
99
116
  weth: 8,
100
117
  wbtc: 8,
101
118
  wusdc: 6,
@@ -110,6 +127,7 @@ var coinDecimals = {
110
127
  sca: 9,
111
128
  susdc: 6,
112
129
  sweth: 8,
130
+ ssbeth: 8,
113
131
  swbtc: 8,
114
132
  swusdc: 6,
115
133
  swusdt: 6,
@@ -124,6 +142,7 @@ var coinDecimals = {
124
142
  };
125
143
  var assetCoins = {
126
144
  usdc: "usdc",
145
+ sbeth: "sbeth",
127
146
  weth: "weth",
128
147
  wbtc: "wbtc",
129
148
  wusdc: "wusdc",
@@ -139,6 +158,7 @@ var assetCoins = {
139
158
  };
140
159
  var marketCoins = {
141
160
  susdc: "susdc",
161
+ ssbeth: "ssbeth",
142
162
  sweth: "sweth",
143
163
  swbtc: "swbtc",
144
164
  swusdc: "swusdc",
@@ -154,6 +174,7 @@ var marketCoins = {
154
174
  };
155
175
  var sCoins = {
156
176
  susdc: "susdc",
177
+ ssbeth: "ssbeth",
157
178
  sweth: "sweth",
158
179
  swusdc: "swusdc",
159
180
  swusdt: "swusdt",
@@ -188,6 +209,9 @@ var spoolRewardCoins = {
188
209
  svsui: "sui",
189
210
  susdc: "sui"
190
211
  };
212
+ var suiBridgeCoins = {
213
+ sbeth: "sbeth"
214
+ };
191
215
  var borrowIncentiveRewardCoins = {
192
216
  usdc: ["sui", "sca"],
193
217
  sui: ["sui", "sca"],
@@ -197,11 +221,13 @@ var borrowIncentiveRewardCoins = {
197
221
  afsui: ["sui"],
198
222
  hasui: ["sui"],
199
223
  vsui: ["sui"],
200
- weth: ["sui"]
224
+ weth: ["sui"],
225
+ sbeth: ["sui"]
201
226
  };
202
227
  var coinIds = {
203
228
  usdc: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7",
204
229
  sui: "0x0000000000000000000000000000000000000000000000000000000000000002",
230
+ sbeth: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29",
205
231
  weth: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
206
232
  wbtc: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
207
233
  wusdc: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
@@ -227,6 +253,7 @@ var voloCoinIds = {
227
253
  };
228
254
  var sCoinIds = {
229
255
  susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
256
+ ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
230
257
  ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
231
258
  scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
232
259
  ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
@@ -787,11 +814,23 @@ var isMarketCoin = (coinName) => {
787
814
  const assetCoinName = coinName.slice(1).toLowerCase();
788
815
  return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
789
816
  };
817
+ var isSuiBridgeAsset = (coinName) => {
818
+ return SUPPORT_SUI_BRIDGE.includes(coinName);
819
+ };
820
+ var isWormholeAsset = (coinName) => {
821
+ return SUPPORT_WORMHOLE.includes(coinName);
822
+ };
790
823
  var parseAssetSymbol = (coinName) => {
791
- const isWormhole = coinName.charAt(0) === "w";
792
- if (isWormhole) {
824
+ if (isWormholeAsset(coinName)) {
793
825
  return `w${coinName.slice(1).toUpperCase()}`;
794
826
  }
827
+ if (isSuiBridgeAsset(coinName)) {
828
+ return `sb${coinName.slice(2).toUpperCase()}`;
829
+ }
830
+ if (isMarketCoin(coinName)) {
831
+ const assetCoinName = coinName.slice(1).toLowerCase();
832
+ return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
833
+ }
795
834
  switch (coinName) {
796
835
  case "afsui":
797
836
  return "afSUI";
@@ -3035,18 +3074,13 @@ var getStakeAccounts = async ({
3035
3074
  hasNextPage = false;
3036
3075
  }
3037
3076
  } while (hasNextPage);
3038
- const stakeAccounts = {
3039
- susdc: [],
3040
- sweth: [],
3041
- ssui: [],
3042
- swusdc: [],
3043
- swusdt: [],
3044
- scetus: [],
3045
- safsui: [],
3046
- shasui: [],
3047
- svsui: []
3048
- // ssca: [],
3049
- };
3077
+ const stakeAccounts = SUPPORT_SPOOLS.reduce(
3078
+ (acc, stakeName) => {
3079
+ acc[stakeName] = [];
3080
+ return acc;
3081
+ },
3082
+ {}
3083
+ );
3050
3084
  const stakeMarketCoinTypes = Object.keys(stakeAccounts).reduce(
3051
3085
  (types, stakeMarketCoinName) => {
3052
3086
  const stakeCoinName = utils.parseCoinName(stakeMarketCoinName);
@@ -3056,6 +3090,13 @@ var getStakeAccounts = async ({
3056
3090
  },
3057
3091
  {}
3058
3092
  );
3093
+ const reversedStakeMarketCoinTypes = Object.entries(stakeMarketCoinTypes).reduce(
3094
+ (reversedTypes, [key, value]) => {
3095
+ reversedTypes[value] = key;
3096
+ return reversedTypes;
3097
+ },
3098
+ {}
3099
+ );
3059
3100
  const stakeObjectIds = stakeObjectsResponse.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
3060
3101
  const stakeObjects = await utils.cache.queryGetObjects(stakeObjectIds, {
3061
3102
  showContent: true,
@@ -3072,98 +3113,23 @@ var getStakeAccounts = async ({
3072
3113
  const index = Number(fields.index);
3073
3114
  const points = Number(fields.points);
3074
3115
  const totalPoints = Number(fields.total_points);
3075
- if (normalizeStructTag4(type) === stakeMarketCoinTypes.sweth) {
3076
- stakeAccounts.sweth.push({
3077
- id,
3078
- type: normalizeStructTag4(type),
3079
- stakePoolId,
3080
- stakeType: normalizeStructTag4(stakeType),
3081
- staked,
3082
- index,
3083
- points,
3084
- totalPoints
3085
- });
3086
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.ssui) {
3087
- stakeAccounts.ssui.push({
3088
- id,
3089
- type: normalizeStructTag4(type),
3090
- stakePoolId,
3091
- stakeType: normalizeStructTag4(stakeType),
3092
- staked,
3093
- index,
3094
- points,
3095
- totalPoints
3096
- });
3097
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.swusdc) {
3098
- stakeAccounts.swusdc.push({
3099
- id,
3100
- type: normalizeStructTag4(type),
3101
- stakePoolId,
3102
- stakeType: normalizeStructTag4(stakeType),
3103
- staked,
3104
- index,
3105
- points,
3106
- totalPoints
3107
- });
3108
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.swusdt) {
3109
- stakeAccounts.swusdt.push({
3110
- id,
3111
- type: normalizeStructTag4(type),
3112
- stakePoolId,
3113
- stakeType: normalizeStructTag4(stakeType),
3114
- staked,
3115
- index,
3116
- points,
3117
- totalPoints
3118
- });
3119
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.scetus) {
3120
- stakeAccounts.scetus.push({
3121
- id,
3122
- type: normalizeStructTag4(type),
3123
- stakePoolId,
3124
- stakeType: normalizeStructTag4(stakeType),
3125
- staked,
3126
- index,
3127
- points,
3128
- totalPoints
3129
- });
3130
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.safsui) {
3131
- stakeAccounts.safsui.push({
3132
- id,
3133
- type: normalizeStructTag4(type),
3134
- stakePoolId,
3135
- stakeType: normalizeStructTag4(stakeType),
3136
- staked,
3137
- index,
3138
- points,
3139
- totalPoints
3140
- });
3141
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.shasui) {
3142
- stakeAccounts.shasui.push({
3143
- id,
3144
- type: normalizeStructTag4(type),
3145
- stakePoolId,
3146
- stakeType: normalizeStructTag4(stakeType),
3147
- staked,
3148
- index,
3149
- points,
3150
- totalPoints
3151
- });
3152
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.svsui) {
3153
- stakeAccounts.svsui.push({
3154
- id,
3155
- type: normalizeStructTag4(type),
3156
- stakePoolId,
3157
- stakeType: normalizeStructTag4(stakeType),
3158
- staked,
3159
- index,
3160
- points,
3161
- totalPoints
3162
- });
3163
- } else if (normalizeStructTag4(type) === stakeMarketCoinTypes.susdc) {
3164
- stakeAccounts.susdc.push({
3116
+ const stakeMarketCoinTypeMap = {
3117
+ sweth: stakeAccounts.sweth,
3118
+ ssui: stakeAccounts.ssui,
3119
+ swusdc: stakeAccounts.swusdc,
3120
+ swusdt: stakeAccounts.swusdt,
3121
+ scetus: stakeAccounts.scetus,
3122
+ safsui: stakeAccounts.safsui,
3123
+ shasui: stakeAccounts.shasui,
3124
+ svsui: stakeAccounts.svsui,
3125
+ susdc: stakeAccounts.susdc
3126
+ };
3127
+ const normalizedType = normalizeStructTag4(type);
3128
+ const stakeAccountArray = stakeMarketCoinTypeMap[reversedStakeMarketCoinTypes[normalizedType]];
3129
+ if (stakeAccountArray) {
3130
+ stakeAccountArray.push({
3165
3131
  id,
3166
- type: normalizeStructTag4(type),
3132
+ type: normalizedType,
3167
3133
  stakePoolId,
3168
3134
  stakeType: normalizeStructTag4(stakeType),
3169
3135
  staked,
@@ -4081,7 +4047,7 @@ var getVescaKeys = async (utils, ownerAddress) => {
4081
4047
  };
4082
4048
  var getVeScas = async ({
4083
4049
  utils
4084
- }, ownerAddress) => {
4050
+ }, ownerAddress, excludeEmpty) => {
4085
4051
  const keyObjectDatas = await getVescaKeys(utils, ownerAddress);
4086
4052
  const veScas = Array(keyObjectDatas.length).fill(null);
4087
4053
  const tasks = keyObjectDatas.map(async (veScaKey, idx) => {
@@ -4091,7 +4057,11 @@ var getVeScas = async ({
4091
4057
  }
4092
4058
  });
4093
4059
  await Promise.allSettled(tasks);
4094
- return veScas.filter(Boolean).sort((a, b) => b.currentVeScaBalance - a.currentVeScaBalance);
4060
+ const result = veScas.filter(Boolean).sort((a, b) => b.currentVeScaBalance - a.currentVeScaBalance);
4061
+ if (excludeEmpty) {
4062
+ return result.filter((v) => v.lockedScaAmount !== "0");
4063
+ }
4064
+ return result;
4095
4065
  };
4096
4066
  var SuiObjectRefZod = zod2.object({
4097
4067
  objectId: zod2.string(),
@@ -4334,6 +4304,13 @@ var ScallopUtils = class {
4334
4304
  }
4335
4305
  this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
4336
4306
  }
4307
+ // -------------- TYPE GUARDS --------------
4308
+ isSuiBridgeAsset(coinName) {
4309
+ return isSuiBridgeAsset(coinName);
4310
+ }
4311
+ isWormholeAsset(coinName) {
4312
+ return isWormholeAsset(coinName);
4313
+ }
4337
4314
  /**
4338
4315
  * Request the scallop API to initialize data.
4339
4316
  *
@@ -4354,12 +4331,7 @@ var ScallopUtils = class {
4354
4331
  * @return Symbol string.
4355
4332
  */
4356
4333
  parseSymbol(coinName) {
4357
- if (isMarketCoin(coinName)) {
4358
- const assetCoinName = coinName.slice(1).toLowerCase();
4359
- return coinName.slice(0, 1).toLowerCase() + parseAssetSymbol(assetCoinName);
4360
- } else {
4361
- return parseAssetSymbol(coinName);
4362
- }
4334
+ return parseAssetSymbol(coinName);
4363
4335
  }
4364
4336
  /**
4365
4337
  * Convert coin name to coin type.
@@ -4391,10 +4363,21 @@ var ScallopUtils = class {
4391
4363
  const voloPackageIds = [
4392
4364
  this.address.get("core.coins.vsui.id") ?? voloCoinIds.vsui
4393
4365
  ];
4366
+ const suiBridgePackageIds = Object.values(
4367
+ suiBridgeCoins
4368
+ ).reduce((curr, coinName2) => {
4369
+ curr.push(
4370
+ this.address.get(`core.coins.${coinName2}.id`) ?? coinIds[coinName2]
4371
+ );
4372
+ return curr;
4373
+ }, []);
4394
4374
  if (wormHolePackageIds.includes(coinPackageId)) {
4395
4375
  return `${coinPackageId}::coin::COIN`;
4396
4376
  } else if (voloPackageIds.includes(coinPackageId)) {
4397
4377
  return `${coinPackageId}::cert::CERT`;
4378
+ } else if (suiBridgePackageIds.includes(coinPackageId)) {
4379
+ const typeCoinName = coinName.slice(2);
4380
+ return `${coinPackageId}::${typeCoinName}::${typeCoinName.toUpperCase()}`;
4398
4381
  } else {
4399
4382
  return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;
4400
4383
  }
@@ -4470,11 +4453,20 @@ var ScallopUtils = class {
4470
4453
  const voloCoinTypeMap = {
4471
4454
  [`${this.address.get("core.coins.vsui.id") ?? voloCoinIds.vsui}::cert::CERT`]: "vsui"
4472
4455
  };
4473
- const assetCoinName = wormHoleCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
4456
+ const suiBridgeTypeMap = Object.values(
4457
+ suiBridgeCoins
4458
+ ).reduce(
4459
+ (curr, coinName) => {
4460
+ curr[this.parseCoinType(coinName)] = coinName;
4461
+ return curr;
4462
+ },
4463
+ {}
4464
+ );
4465
+ const assetCoinName = wormHoleCoinTypeMap[coinType] || voloCoinTypeMap[coinType] || suiBridgeTypeMap[coinType] || coinType.split("::")[2].toLowerCase();
4474
4466
  return isMarketCoinType ? this.parseMarketCoinName(assetCoinName) : assetCoinName;
4475
4467
  }
4476
4468
  /**
4477
- * Convert marke coin name to coin name.
4469
+ * Convert market coin name to coin name.
4478
4470
  *
4479
4471
  * @param marketCoinName - Specific support market coin name.
4480
4472
  * @return Coin Name.
@@ -4505,10 +4497,18 @@ var ScallopUtils = class {
4505
4497
  * return Coin wrapped type.
4506
4498
  */
4507
4499
  getCoinWrappedType(assetCoinName) {
4508
- return assetCoinName === "wusdc" || assetCoinName === "wusdt" || assetCoinName === "weth" || assetCoinName === "wbtc" || assetCoinName === "wapt" || assetCoinName === "wsol" ? {
4509
- from: "Wormhole",
4510
- type: "Portal from Ethereum"
4511
- } : void 0;
4500
+ if (this.isSuiBridgeAsset(assetCoinName)) {
4501
+ return {
4502
+ from: "Sui Bridge",
4503
+ type: "Asset from Sui Bridge"
4504
+ };
4505
+ } else if (this.isWormholeAsset(assetCoinName)) {
4506
+ return {
4507
+ from: "Wormhole",
4508
+ type: "Portal from Ethereum"
4509
+ };
4510
+ }
4511
+ return void 0;
4512
4512
  }
4513
4513
  /**
4514
4514
  * Select coin id that add up to the given amount as transaction arguments.
@@ -6985,8 +6985,11 @@ var ScallopQuery = class {
6985
6985
  * @param walletAddress
6986
6986
  * @returns array of veSca
6987
6987
  */
6988
- async getVeScas(walletAddress = this.walletAddress) {
6989
- return await getVeScas(this, walletAddress);
6988
+ async getVeScas({
6989
+ walletAddress = this.walletAddress,
6990
+ excludeEmpty = false
6991
+ } = {}) {
6992
+ return await getVeScas(this, walletAddress, excludeEmpty);
6990
6993
  }
6991
6994
  /**
6992
6995
  * Get total vesca treasury with movecall
@@ -7834,7 +7837,9 @@ var ScallopClient = class {
7834
7837
  }
7835
7838
  }
7836
7839
  async claimAllUnlockedSca(sign = true) {
7837
- const veScaKeys = (await this.query.getVeScas(this.walletAddress) ?? []).map(({ keyObject }) => keyObject);
7840
+ const veScaKeys = (await this.query.getVeScas({
7841
+ walletAddress: this.walletAddress
7842
+ }) ?? []).map(({ keyObject }) => keyObject);
7838
7843
  if (veScaKeys.length === 0) {
7839
7844
  throw new Error("No veSCA found in the wallet");
7840
7845
  }
@@ -8032,6 +8037,8 @@ export {
8032
8037
  SUPPORT_SCOIN,
8033
8038
  SUPPORT_SPOOLS,
8034
8039
  SUPPORT_SPOOLS_REWARDS,
8040
+ SUPPORT_SUI_BRIDGE,
8041
+ SUPPORT_WORMHOLE,
8035
8042
  Scallop,
8036
8043
  ScallopAddress,
8037
8044
  ScallopBuilder,
@@ -8051,6 +8058,7 @@ export {
8051
8058
  sCoins,
8052
8059
  spoolRewardCoins,
8053
8060
  stakeMarketCoins,
8061
+ suiBridgeCoins,
8054
8062
  voloCoinIds,
8055
8063
  wormholeCoinIds
8056
8064
  };