@scallop-io/sui-scallop-sdk 0.44.16 → 0.44.17

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
@@ -31,9 +31,11 @@ var SUPPORT_COLLATERALS = [
31
31
  "vsui"
32
32
  ];
33
33
  var SUPPORT_SPOOLS = [
34
+ "seth",
34
35
  "ssui",
35
36
  "susdc",
36
37
  "susdt",
38
+ "scetus",
37
39
  "safsui",
38
40
  "shasui",
39
41
  "svsui"
@@ -109,17 +111,21 @@ var marketCoins = {
109
111
  svsui: "svsui"
110
112
  };
111
113
  var stakeMarketCoins = {
114
+ seth: "seth",
112
115
  ssui: "ssui",
113
116
  susdc: "susdc",
114
117
  susdt: "susdt",
118
+ scetus: "scetus",
115
119
  safsui: "safsui",
116
120
  shasui: "shasui",
117
121
  svsui: "svsui"
118
122
  };
119
123
  var spoolRewardCoins = {
124
+ seth: "sui",
120
125
  ssui: "sui",
121
126
  susdc: "sui",
122
127
  susdt: "sui",
128
+ scetus: "sui",
123
129
  safsui: "sui",
124
130
  shasui: "sui",
125
131
  svsui: "sui"
@@ -343,6 +349,10 @@ var EMPTY_ADDRESSES = {
343
349
  adminCap: "",
344
350
  object: "",
345
351
  pools: {
352
+ seth: {
353
+ id: "",
354
+ rewardPoolId: ""
355
+ },
346
356
  ssui: {
347
357
  id: "",
348
358
  rewardPoolId: ""
@@ -355,6 +365,10 @@ var EMPTY_ADDRESSES = {
355
365
  id: "",
356
366
  rewardPoolId: ""
357
367
  },
368
+ scetus: {
369
+ id: "",
370
+ rewardPoolId: ""
371
+ },
358
372
  safsui: {
359
373
  id: "",
360
374
  rewardPoolId: ""
@@ -1944,9 +1958,11 @@ var getStakeAccounts = async (query, ownerAddress) => {
1944
1958
  }
1945
1959
  } while (hasNextPage);
1946
1960
  const stakeAccounts = {
1961
+ seth: [],
1947
1962
  ssui: [],
1948
1963
  susdc: [],
1949
1964
  susdt: [],
1965
+ scetus: [],
1950
1966
  safsui: [],
1951
1967
  shasui: [],
1952
1968
  svsui: []
@@ -1973,7 +1989,18 @@ var getStakeAccounts = async (query, ownerAddress) => {
1973
1989
  const index = Number(fields.index);
1974
1990
  const points = Number(fields.points);
1975
1991
  const totalPoints = Number(fields.total_points);
1976
- if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
1992
+ if (normalizeStructTag3(type) === stakeMarketCoinTypes.seth) {
1993
+ stakeAccounts.seth.push({
1994
+ id,
1995
+ type: normalizeStructTag3(type),
1996
+ stakePoolId,
1997
+ stakeType: normalizeStructTag3(stakeType),
1998
+ staked,
1999
+ index,
2000
+ points,
2001
+ totalPoints
2002
+ });
2003
+ } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
1977
2004
  stakeAccounts.ssui.push({
1978
2005
  id,
1979
2006
  type: normalizeStructTag3(type),
@@ -2006,6 +2033,17 @@ var getStakeAccounts = async (query, ownerAddress) => {
2006
2033
  points,
2007
2034
  totalPoints
2008
2035
  });
2036
+ } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.scetus) {
2037
+ stakeAccounts.scetus.push({
2038
+ id,
2039
+ type: normalizeStructTag3(type),
2040
+ stakePoolId,
2041
+ stakeType: normalizeStructTag3(stakeType),
2042
+ staked,
2043
+ index,
2044
+ points,
2045
+ totalPoints
2046
+ });
2009
2047
  } else if (normalizeStructTag3(type) === stakeMarketCoinTypes.safsui) {
2010
2048
  stakeAccounts.safsui.push({
2011
2049
  id,
@@ -2946,13 +2984,16 @@ var ScallopQuery = class {
2946
2984
  /**
2947
2985
  * Request the scallop API to initialize data.
2948
2986
  *
2949
- * @param forece - Whether to force initialization.
2987
+ * @param force - Whether to force initialization.
2988
+ * @param address - ScallopAddress instance.
2950
2989
  */
2951
- async init(forece = false) {
2952
- if (forece || !this.address.getAddresses()) {
2990
+ async init(force = false, address) {
2991
+ if (force || !this.address.getAddresses() || !address?.getAddresses()) {
2953
2992
  await this.address.read();
2993
+ } else {
2994
+ this.address = address;
2954
2995
  }
2955
- await this.utils.init(forece);
2996
+ await this.utils.init(force, this.address);
2956
2997
  }
2957
2998
  /* ==================== Core Query Methods ==================== */
2958
2999
  /**
@@ -3278,6 +3319,12 @@ var ScallopQuery = class {
3278
3319
  }
3279
3320
  };
3280
3321
 
3322
+ // src/constants/pyth.ts
3323
+ var PYTH_ENDPOINTS = {
3324
+ testnet: ["https://hermes-beta.pyth.network"],
3325
+ mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
3326
+ };
3327
+
3281
3328
  // src/models/scallopUtils.ts
3282
3329
  var ScallopUtils = class {
3283
3330
  constructor(params, instance) {
@@ -3315,13 +3362,18 @@ var ScallopUtils = class {
3315
3362
  /**
3316
3363
  * Request the scallop API to initialize data.
3317
3364
  *
3318
- * @param forece - Whether to force initialization.
3365
+ * @param force - Whether to force initialization.
3366
+ * @param address - ScallopAddress instance.
3319
3367
  */
3320
- async init(forece = false) {
3321
- if (forece || !this._address.getAddresses()) {
3368
+ async init(force = false, address) {
3369
+ if (force || !this._address.getAddresses() || !address?.getAddresses()) {
3322
3370
  await this._address.read();
3371
+ } else {
3372
+ this._address = address;
3373
+ }
3374
+ if (!this._query.address.getAddresses()) {
3375
+ await this._query.init(force, this._address);
3323
3376
  }
3324
- await this._query.init(forece);
3325
3377
  }
3326
3378
  /**
3327
3379
  * Convert coin name to symbol.
@@ -3519,22 +3571,31 @@ var ScallopUtils = class {
3519
3571
  }
3520
3572
  }
3521
3573
  if (lackPricesCoinNames.length > 0) {
3522
- const pythConnection = new SuiPriceServiceConnection(
3523
- this.isTestnet ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network"
3524
- );
3525
- const priceIds = lackPricesCoinNames.map(
3526
- (coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
3527
- );
3574
+ const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
3528
3575
  try {
3529
- const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
3530
- for (const [index, feed] of priceFeeds.entries()) {
3531
- const data = parseDataFromPythPriceFeed(feed, this._address);
3532
- const coinName = lackPricesCoinNames[index];
3533
- this._priceMap.set(coinName, {
3534
- price: data.price,
3535
- publishTime: data.publishTime
3536
- });
3537
- coinPrices[coinName] = data.price;
3576
+ for (const endpoint of endpoints) {
3577
+ try {
3578
+ const pythConnection = new SuiPriceServiceConnection(endpoint);
3579
+ const priceIds = lackPricesCoinNames.map(
3580
+ (coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
3581
+ );
3582
+ const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
3583
+ for (const [index, feed] of priceFeeds.entries()) {
3584
+ const data = parseDataFromPythPriceFeed(feed, this._address);
3585
+ const coinName = lackPricesCoinNames[index];
3586
+ this._priceMap.set(coinName, {
3587
+ price: data.price,
3588
+ publishTime: data.publishTime
3589
+ });
3590
+ coinPrices[coinName] = data.price;
3591
+ }
3592
+ break;
3593
+ } catch (e) {
3594
+ console.warn(
3595
+ `Failed to update price feeds with endpoint ${endpoint}: ${e}`
3596
+ );
3597
+ }
3598
+ throw new Error("Failed to update price feeds with all endpoins");
3538
3599
  }
3539
3600
  } catch (_e) {
3540
3601
  for (const coinName of lackPricesCoinNames) {
@@ -3600,15 +3661,23 @@ var updateOracles = async (builder, txBlock, assetCoinNames) => {
3600
3661
  const priceIds = assetCoinNames.map(
3601
3662
  (assetCoinName) => builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
3602
3663
  );
3603
- const pythConnection = new SuiPriceServiceConnection2(
3604
- builder.isTestnet ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network"
3605
- );
3606
- const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(priceIds);
3607
- await pythClient.updatePriceFeeds(
3608
- txBlock.txBlock,
3609
- priceUpdateData,
3610
- priceIds
3611
- );
3664
+ const endpoints = builder.params.pythEndpoints ?? PYTH_ENDPOINTS[builder.isTestnet ? "testnet" : "mainnet"];
3665
+ for (const endpoint of endpoints) {
3666
+ try {
3667
+ const pythConnection = new SuiPriceServiceConnection2(endpoint);
3668
+ const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(priceIds);
3669
+ await pythClient.updatePriceFeeds(
3670
+ txBlock.txBlock,
3671
+ priceUpdateData,
3672
+ priceIds
3673
+ );
3674
+ break;
3675
+ } catch (e) {
3676
+ console.warn(
3677
+ `Failed to update price feeds with endpoint ${endpoint}: ${e}`
3678
+ );
3679
+ }
3680
+ }
3612
3681
  }
3613
3682
  const updateAssetCoinNames = [...new Set(assetCoinNames)];
3614
3683
  for (const assetCoinName of updateAssetCoinNames) {
@@ -4431,13 +4500,16 @@ var ScallopBuilder = class {
4431
4500
  * Request the scallop API to initialize data.
4432
4501
  *
4433
4502
  * @param force - Whether to force initialization.
4503
+ * @param address - ScallopAddress instance.
4434
4504
  */
4435
- async init(force = false) {
4436
- if (force || !this.address.getAddresses()) {
4505
+ async init(force = false, address) {
4506
+ if (force || !this.address.getAddresses() || !address?.getAddresses()) {
4437
4507
  await this.address.read();
4508
+ } else {
4509
+ this.address = address;
4438
4510
  }
4439
- await this.query.init(force);
4440
- await this.utils.init(force);
4511
+ await this.query.init(force, this.address);
4512
+ await this.utils.init(force, this.address);
4441
4513
  }
4442
4514
  /**
4443
4515
  * Create a scallop txBlock instance that enhances transaction block.
@@ -4525,15 +4597,15 @@ var ScallopClient = class {
4525
4597
  /**
4526
4598
  * Request the scallop API to initialize data.
4527
4599
  *
4528
- * @param forece - Whether to force initialization.
4600
+ * @param force - Whether to force initialization.
4529
4601
  */
4530
- async init(forece = false) {
4531
- if (forece || !this.address.getAddresses()) {
4602
+ async init(force = false) {
4603
+ if (force || !this.address.getAddresses()) {
4532
4604
  await this.address.read();
4533
4605
  }
4534
- await this.query.init(forece);
4535
- await this.utils.init(forece);
4536
- await this.builder.init(forece);
4606
+ await this.builder.init(force, this.address);
4607
+ await this.query.init(force, this.address);
4608
+ await this.utils.init(force, this.address);
4537
4609
  }
4538
4610
  /* ==================== Query Method ==================== */
4539
4611
  /**