@scallop-io/sui-scallop-sdk 0.46.49 → 0.46.51

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
@@ -256,7 +256,7 @@ import {
256
256
  var DEFAULT_CACHE_OPTIONS = {
257
257
  defaultOptions: {
258
258
  queries: {
259
- staleTime: 3e3
259
+ staleTime: 1500
260
260
  }
261
261
  }
262
262
  };
@@ -1529,7 +1529,7 @@ var ScallopAddress = class {
1529
1529
  };
1530
1530
 
1531
1531
  // src/models/scallopClient.ts
1532
- import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui.js/utils";
1532
+ import { normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui.js/utils";
1533
1533
  import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
1534
1534
 
1535
1535
  // src/models/scallopUtils.ts
@@ -1962,7 +1962,7 @@ var calculateBorrowIncentivePoolPointData = (parsedBorrowIncentivePoolData, pars
1962
1962
  BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
1963
1963
  weightScale
1964
1964
  )
1965
- ).dividedBy(weightedStakedValue).isFinite() ? rewardValueForYear.multipliedBy(
1965
+ ).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
1966
1966
  BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
1967
1967
  weightScale
1968
1968
  )
@@ -3245,11 +3245,44 @@ var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
3245
3245
  return 0;
3246
3246
  };
3247
3247
  var getPythPrices = async (query, assetCoinNames) => {
3248
+ const pythPriceFeedIds = assetCoinNames.reduce(
3249
+ (prev, assetCoinName) => {
3250
+ const pythPriceFeed = query.address.get(
3251
+ `core.coins.${assetCoinName}.oracle.pyth.feedObject`
3252
+ );
3253
+ if (!prev[pythPriceFeed]) {
3254
+ prev[pythPriceFeed] = [assetCoinName];
3255
+ } else {
3256
+ prev[pythPriceFeed].push(assetCoinName);
3257
+ }
3258
+ return prev;
3259
+ },
3260
+ {}
3261
+ );
3262
+ const priceFeedObjects = await query.cache.queryGetObjects(
3263
+ Object.keys(pythPriceFeedIds),
3264
+ { showContent: true }
3265
+ );
3266
+ const assetToPriceFeedMapping = priceFeedObjects.reduce(
3267
+ (prev, priceFeedObject) => {
3268
+ pythPriceFeedIds[priceFeedObject.objectId].forEach((assetCoinName) => {
3269
+ prev[assetCoinName] = priceFeedObject;
3270
+ });
3271
+ return prev;
3272
+ },
3273
+ {}
3274
+ );
3248
3275
  return (await Promise.all(
3249
- assetCoinNames.map(async (assetCoinName) => ({
3250
- coinName: assetCoinName,
3251
- price: await getPythPrice(query, assetCoinName)
3252
- }))
3276
+ Object.entries(assetToPriceFeedMapping).map(
3277
+ async ([assetCoinName, priceFeedObject]) => ({
3278
+ coinName: assetCoinName,
3279
+ price: await getPythPrice(
3280
+ query,
3281
+ assetCoinName,
3282
+ priceFeedObject
3283
+ )
3284
+ })
3285
+ )
3253
3286
  )).reduce(
3254
3287
  (prev, curr) => {
3255
3288
  prev[curr.coinName] = curr.price;
@@ -4223,6 +4256,7 @@ var getSCoinAmount = async (query, sCoinName, ownerAddress) => {
4223
4256
  };
4224
4257
 
4225
4258
  // src/models/scallopQuery.ts
4259
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
4226
4260
  var ScallopQuery = class {
4227
4261
  constructor(params, instance) {
4228
4262
  this.params = params;
@@ -4242,6 +4276,9 @@ var ScallopQuery = class {
4242
4276
  query: this
4243
4277
  });
4244
4278
  this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
4279
+ this.walletAddress = normalizeSuiAddress2(
4280
+ params?.walletAddress || this.suiKit.currentAddress()
4281
+ );
4245
4282
  }
4246
4283
  /**
4247
4284
  * Request the scallop API to initialize data.
@@ -4320,7 +4357,7 @@ var ScallopQuery = class {
4320
4357
  * @param ownerAddress - The owner address.
4321
4358
  * @return Obligations data.
4322
4359
  */
4323
- async getObligations(ownerAddress) {
4360
+ async getObligations(ownerAddress = this.walletAddress) {
4324
4361
  return await getObligations(this, ownerAddress);
4325
4362
  }
4326
4363
  /**
@@ -4339,7 +4376,7 @@ var ScallopQuery = class {
4339
4376
  * @param ownerAddress - The owner address.
4340
4377
  * @return All coin amounts.
4341
4378
  */
4342
- async getCoinAmounts(assetCoinNames, ownerAddress) {
4379
+ async getCoinAmounts(assetCoinNames, ownerAddress = this.walletAddress) {
4343
4380
  return await getCoinAmounts(this, assetCoinNames, ownerAddress);
4344
4381
  }
4345
4382
  /**
@@ -4349,7 +4386,7 @@ var ScallopQuery = class {
4349
4386
  * @param ownerAddress - The owner address.
4350
4387
  * @return Coin amount.
4351
4388
  */
4352
- async getCoinAmount(assetCoinName, ownerAddress) {
4389
+ async getCoinAmount(assetCoinName, ownerAddress = this.walletAddress) {
4353
4390
  return await getCoinAmount(this, assetCoinName, ownerAddress);
4354
4391
  }
4355
4392
  /**
@@ -4359,7 +4396,7 @@ var ScallopQuery = class {
4359
4396
  * @param ownerAddress - The owner address.
4360
4397
  * @return All market market coin amounts.
4361
4398
  */
4362
- async getMarketCoinAmounts(marketCoinNames, ownerAddress) {
4399
+ async getMarketCoinAmounts(marketCoinNames, ownerAddress = this.walletAddress) {
4363
4400
  return await getMarketCoinAmounts(this, marketCoinNames, ownerAddress);
4364
4401
  }
4365
4402
  /**
@@ -4369,7 +4406,7 @@ var ScallopQuery = class {
4369
4406
  * @param ownerAddress - The owner address.
4370
4407
  * @return Market market coin amount.
4371
4408
  */
4372
- async getMarketCoinAmount(marketCoinName, ownerAddress) {
4409
+ async getMarketCoinAmount(marketCoinName, ownerAddress = this.walletAddress) {
4373
4410
  return await getMarketCoinAmount(this, marketCoinName, ownerAddress);
4374
4411
  }
4375
4412
  /**
@@ -4417,7 +4454,7 @@ var ScallopQuery = class {
4417
4454
  * @param ownerAddress - The owner address.
4418
4455
  * @return All Stake accounts data.
4419
4456
  */
4420
- async getAllStakeAccounts(ownerAddress) {
4457
+ async getAllStakeAccounts(ownerAddress = this.walletAddress) {
4421
4458
  return await getStakeAccounts(this, ownerAddress);
4422
4459
  }
4423
4460
  /**
@@ -4427,7 +4464,7 @@ var ScallopQuery = class {
4427
4464
  * @param ownerAddress - The owner address.
4428
4465
  * @return Stake accounts data.
4429
4466
  */
4430
- async getStakeAccounts(stakeMarketCoinName, ownerAddress) {
4467
+ async getStakeAccounts(stakeMarketCoinName, ownerAddress = this.walletAddress) {
4431
4468
  const allStakeAccount = await this.getAllStakeAccounts(ownerAddress);
4432
4469
  return allStakeAccount[stakeMarketCoinName] ?? [];
4433
4470
  }
@@ -4532,7 +4569,7 @@ var ScallopQuery = class {
4532
4569
  * @param indexer - Whether to use indexer.
4533
4570
  * @return All lending and spool infomation.
4534
4571
  */
4535
- async getLendings(poolCoinNames, ownerAddress, indexer = false) {
4572
+ async getLendings(poolCoinNames, ownerAddress = this.walletAddress, indexer = false) {
4536
4573
  return await getLendings(this, poolCoinNames, ownerAddress, indexer);
4537
4574
  }
4538
4575
  /**
@@ -4543,7 +4580,7 @@ var ScallopQuery = class {
4543
4580
  * @param indexer - Whether to use indexer.
4544
4581
  * @return Lending pool data.
4545
4582
  */
4546
- async getLending(poolCoinName, ownerAddress, indexer = false) {
4583
+ async getLending(poolCoinName, ownerAddress = this.walletAddress, indexer = false) {
4547
4584
  return await getLending(this, poolCoinName, ownerAddress, indexer);
4548
4585
  }
4549
4586
  /**
@@ -4556,7 +4593,7 @@ var ScallopQuery = class {
4556
4593
  * @param indexer - Whether to use indexer.
4557
4594
  * @return All obligation accounts information.
4558
4595
  */
4559
- async getObligationAccounts(ownerAddress, indexer = false) {
4596
+ async getObligationAccounts(ownerAddress = this.walletAddress, indexer = false) {
4560
4597
  return await getObligationAccounts(this, ownerAddress, indexer);
4561
4598
  }
4562
4599
  /**
@@ -4570,7 +4607,7 @@ var ScallopQuery = class {
4570
4607
  * @param indexer - Whether to use indexer.
4571
4608
  * @return Borrowing and collateral information.
4572
4609
  */
4573
- async getObligationAccount(obligationId, ownerAddress, indexer = false) {
4610
+ async getObligationAccount(obligationId, ownerAddress = this.walletAddress, indexer = false) {
4574
4611
  return await getObligationAccount(
4575
4612
  this,
4576
4613
  obligationId,
@@ -4652,7 +4689,7 @@ var ScallopQuery = class {
4652
4689
  * @param ownerAddress - The owner address.
4653
4690
  * @return All market sCoin amounts.
4654
4691
  */
4655
- async getSCoinAmounts(sCoinNames, ownerAddress) {
4692
+ async getSCoinAmounts(sCoinNames, ownerAddress = this.walletAddress) {
4656
4693
  return await getSCoinAmounts(this, sCoinNames, ownerAddress);
4657
4694
  }
4658
4695
  /**
@@ -4662,7 +4699,7 @@ var ScallopQuery = class {
4662
4699
  * @param ownerAddress - The owner address.
4663
4700
  * @return sCoin amount.
4664
4701
  */
4665
- async getSCoinAmount(sCoinName, ownerAddress) {
4702
+ async getSCoinAmount(sCoinName, ownerAddress = this.walletAddress) {
4666
4703
  const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
4667
4704
  return parsedSCoinName ? await getSCoinAmount(this, parsedSCoinName, ownerAddress) : 0;
4668
4705
  }
@@ -5087,7 +5124,7 @@ var ScallopUtils = class {
5087
5124
  };
5088
5125
 
5089
5126
  // src/models/scallopBuilder.ts
5090
- import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
5127
+ import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui.js/utils";
5091
5128
  import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
5092
5129
 
5093
5130
  // src/builders/coreBuilder.ts
@@ -6768,7 +6805,7 @@ var ScallopBuilder = class {
6768
6805
  query: this.query,
6769
6806
  cache: this.cache
6770
6807
  });
6771
- this.walletAddress = normalizeSuiAddress2(
6808
+ this.walletAddress = normalizeSuiAddress3(
6772
6809
  params?.walletAddress || this.suiKit.currentAddress()
6773
6810
  );
6774
6811
  this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
@@ -6806,7 +6843,7 @@ var ScallopBuilder = class {
6806
6843
  * @param sender - Sender address.
6807
6844
  * @return Take coin and left coin.
6808
6845
  */
6809
- async selectCoin(txBlock, assetCoinName, amount, sender) {
6846
+ async selectCoin(txBlock, assetCoinName, amount, sender = this.walletAddress) {
6810
6847
  const coinType = this.utils.parseCoinType(assetCoinName);
6811
6848
  const coins = await this.utils.selectCoins(amount, coinType, sender);
6812
6849
  const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
@@ -6821,7 +6858,7 @@ var ScallopBuilder = class {
6821
6858
  * @param sender - Sender address.
6822
6859
  * @return Take coin and left coin.
6823
6860
  */
6824
- async selectMarketCoin(txBlock, marketCoinName, amount, sender) {
6861
+ async selectMarketCoin(txBlock, marketCoinName, amount, sender = this.walletAddress) {
6825
6862
  const marketCoinType = this.utils.parseMarketCoinType(marketCoinName);
6826
6863
  const coins = await this.utils.selectCoins(amount, marketCoinType, sender);
6827
6864
  const totalAmount = coins.reduce((prev, coin) => {
@@ -6843,7 +6880,7 @@ var ScallopBuilder = class {
6843
6880
  * @param sender - Sender address.
6844
6881
  * @return Take coin and left coin.
6845
6882
  */
6846
- async selectSCoin(txBlock, sCoinName, amount, sender) {
6883
+ async selectSCoin(txBlock, sCoinName, amount, sender = this.walletAddress) {
6847
6884
  const sCoinType = this.utils.parseSCoinType(sCoinName);
6848
6885
  const coins = await this.utils.selectCoins(amount, sCoinType, sender);
6849
6886
  const totalAmount = coins.reduce((prev, coin) => {
@@ -6903,7 +6940,7 @@ var ScallopClient = class {
6903
6940
  utils: this.utils,
6904
6941
  cache: this.cache
6905
6942
  });
6906
- this.walletAddress = normalizeSuiAddress3(
6943
+ this.walletAddress = normalizeSuiAddress4(
6907
6944
  params?.walletAddress || this.suiKit.currentAddress()
6908
6945
  );
6909
6946
  }