@scallop-io/sui-scallop-sdk 0.47.2 → 0.47.4

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.
@@ -7,5 +7,8 @@ import type { SupportAssetCoins } from '../types';
7
7
  * @param builder - The scallop builder.
8
8
  * @param txBlock - TxBlock created by SuiKit.
9
9
  * @param assetCoinNames - Specific an array of support asset coin name.
10
+ * @param options - The options for update oracles.
10
11
  */
11
- export declare const updateOracles: (builder: ScallopBuilder, txBlock: SuiKitTxBlock, assetCoinNames?: SupportAssetCoins[]) => Promise<void>;
12
+ export declare const updateOracles: (builder: ScallopBuilder, txBlock: SuiKitTxBlock, assetCoinNames?: SupportAssetCoins[], options?: {
13
+ usePythPullModel: boolean;
14
+ }) => Promise<void>;
package/dist/index.js CHANGED
@@ -4155,7 +4155,7 @@ var getVescaKeys = async (utils, ownerAddress) => {
4155
4155
  };
4156
4156
  var getVeScas = async ({
4157
4157
  utils
4158
- }, ownerAddress) => {
4158
+ }, ownerAddress, excludeEmpty) => {
4159
4159
  const keyObjectDatas = await getVescaKeys(utils, ownerAddress);
4160
4160
  const veScas = Array(keyObjectDatas.length).fill(null);
4161
4161
  const tasks = keyObjectDatas.map(async (veScaKey, idx) => {
@@ -4165,7 +4165,11 @@ var getVeScas = async ({
4165
4165
  }
4166
4166
  });
4167
4167
  await Promise.allSettled(tasks);
4168
- return veScas.filter(Boolean).sort((a, b) => b.currentVeScaBalance - a.currentVeScaBalance);
4168
+ const result = veScas.filter(Boolean).sort((a, b) => b.currentVeScaBalance - a.currentVeScaBalance);
4169
+ if (excludeEmpty) {
4170
+ return result.filter((v) => v.lockedScaAmount !== "0");
4171
+ }
4172
+ return result;
4169
4173
  };
4170
4174
  var SuiObjectRefZod = import_zod2.z.object({
4171
4175
  objectId: import_zod2.z.string(),
@@ -4805,12 +4809,13 @@ var import_sui_kit5 = require("@scallop-io/sui-kit");
4805
4809
  // src/builders/oracle.ts
4806
4810
  var import_utils12 = require("@mysten/sui.js/utils");
4807
4811
  var import_pyth_sui_js2 = require("@pythnetwork/pyth-sui-js");
4808
- var updateOracles = async (builder, txBlock, assetCoinNames) => {
4812
+ var updateOracles = async (builder, txBlock, assetCoinNames, options = { usePythPullModel: true }) => {
4813
+ const usePythPullModel = builder.params.usePythPullModel ?? options.usePythPullModel;
4809
4814
  assetCoinNames = assetCoinNames ?? [
4810
4815
  .../* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
4811
4816
  ];
4812
4817
  const rules = builder.isTestnet ? ["pyth"] : ["pyth"];
4813
- if (rules.includes("pyth")) {
4818
+ if (usePythPullModel && rules.includes("pyth")) {
4814
4819
  const pythClient = new import_pyth_sui_js2.SuiPythClient(
4815
4820
  builder.suiKit.client(),
4816
4821
  builder.address.get("core.oracles.pyth.state"),
@@ -5717,19 +5722,14 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
5717
5722
  );
5718
5723
  if (!obligationLocked || unstakeObligationBeforeStake) {
5719
5724
  const bindedVeScaKey = await builder.query.getBindedVeScaKey(obligationArg);
5720
- if (veScaKey && veScaKey !== bindedVeScaKey) {
5721
- throw new Error(
5722
- "Binded veScaKey is not equal to the provided veScaKey"
5723
- );
5724
- }
5725
- if (bindedVeScaKey) {
5725
+ if (veScaKey && veScaKey !== bindedVeScaKey || !bindedVeScaKey) {
5726
+ txBlock.stakeObligation(obligationArg, obligationKeyArg);
5727
+ } else {
5726
5728
  txBlock.stakeObligationWithVesca(
5727
5729
  obligationArg,
5728
5730
  obligationKeyArg,
5729
5731
  bindedVeScaKey
5730
5732
  );
5731
- } else {
5732
- txBlock.stakeObligation(obligationArg, obligationKeyArg);
5733
5733
  }
5734
5734
  }
5735
5735
  },
@@ -7049,8 +7049,11 @@ var ScallopQuery = class {
7049
7049
  * @param walletAddress
7050
7050
  * @returns array of veSca
7051
7051
  */
7052
- async getVeScas(walletAddress = this.walletAddress) {
7053
- return await getVeScas(this, walletAddress);
7052
+ async getVeScas({
7053
+ walletAddress = this.walletAddress,
7054
+ excludeEmpty = false
7055
+ } = {}) {
7056
+ return await getVeScas(this, walletAddress, excludeEmpty);
7054
7057
  }
7055
7058
  /**
7056
7059
  * Get total vesca treasury with movecall
@@ -7898,7 +7901,9 @@ var ScallopClient = class {
7898
7901
  }
7899
7902
  }
7900
7903
  async claimAllUnlockedSca(sign = true) {
7901
- const veScaKeys = (await this.query.getVeScas(this.walletAddress) ?? []).map(({ keyObject }) => keyObject);
7904
+ const veScaKeys = (await this.query.getVeScas({
7905
+ walletAddress: this.walletAddress
7906
+ }) ?? []).map(({ keyObject }) => keyObject);
7902
7907
  if (veScaKeys.length === 0) {
7903
7908
  throw new Error("No veSCA found in the wallet");
7904
7909
  }
@@ -7995,11 +8000,15 @@ var Scallop = class {
7995
8000
  *
7996
8001
  * @return Scallop Builder.
7997
8002
  */
7998
- async createScallopBuilder() {
8003
+ async createScallopBuilder(params) {
7999
8004
  if (!this.address.getAddresses())
8000
8005
  await this.address.read();
8001
- const scallopBuilder = new ScallopBuilder(this.params, {
8002
- query: await this.createScallopQuery()
8006
+ const builderParams = {
8007
+ ...this.params,
8008
+ ...params
8009
+ };
8010
+ const scallopBuilder = new ScallopBuilder(builderParams, {
8011
+ query: await this.createScallopQuery(builderParams)
8003
8012
  });
8004
8013
  return scallopBuilder;
8005
8014
  }
@@ -8009,13 +8018,16 @@ var Scallop = class {
8009
8018
  * @param walletAddress - When user cannot provide a secret key or mnemonic, the scallop client cannot directly derive the address of the transaction the user wants to sign. This argument specifies the wallet address for signing the transaction.
8010
8019
  * @return Scallop Client.
8011
8020
  */
8012
- async createScallopClient(walletAddress) {
8021
+ async createScallopClient(params) {
8013
8022
  if (!this.address.getAddresses())
8014
8023
  await this.address.read();
8015
- const scallopClient = new ScallopClient(
8016
- { ...this.params, walletAddress },
8017
- { builder: await this.createScallopBuilder() }
8018
- );
8024
+ const clientParams = {
8025
+ ...this.params,
8026
+ ...params
8027
+ };
8028
+ const scallopClient = new ScallopClient(clientParams, {
8029
+ builder: await this.createScallopBuilder(clientParams)
8030
+ });
8019
8031
  return scallopClient;
8020
8032
  }
8021
8033
  /**
@@ -8023,11 +8035,15 @@ var Scallop = class {
8023
8035
  *
8024
8036
  * @return Scallop Query.
8025
8037
  */
8026
- async createScallopQuery() {
8038
+ async createScallopQuery(params) {
8027
8039
  if (!this.address.getAddresses())
8028
8040
  await this.address.read();
8029
- const scallopQuery = new ScallopQuery(this.params, {
8030
- utils: await this.createScallopUtils()
8041
+ const queryParams = {
8042
+ ...this.params,
8043
+ ...params
8044
+ };
8045
+ const scallopQuery = new ScallopQuery(queryParams, {
8046
+ utils: await this.createScallopUtils(queryParams)
8031
8047
  });
8032
8048
  return scallopQuery;
8033
8049
  }
@@ -8047,12 +8063,18 @@ var Scallop = class {
8047
8063
  *
8048
8064
  * @return Scallop Utils.
8049
8065
  */
8050
- async createScallopUtils() {
8066
+ async createScallopUtils(params) {
8051
8067
  if (!this.address.getAddresses())
8052
8068
  await this.address.read();
8053
- const scallopUtils = new ScallopUtils(this.params, {
8054
- address: this.address
8055
- });
8069
+ const scallopUtils = new ScallopUtils(
8070
+ {
8071
+ ...this.params,
8072
+ ...params
8073
+ },
8074
+ {
8075
+ address: this.address
8076
+ }
8077
+ );
8056
8078
  return scallopUtils;
8057
8079
  }
8058
8080
  };