@t2000/sdk 0.15.1 → 0.15.2

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.js CHANGED
@@ -3944,26 +3944,20 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
3944
3944
  if (depositAmount <= 0) {
3945
3945
  throw new T2000Error("INSUFFICIENT_BALANCE", `No ${params.asset} available to deposit (wallet: ${walletAmount}, gas reserve: ${gasReserve})`);
3946
3946
  }
3947
- const { tx } = await adapter.buildSaveTx(this._address, depositAmount, params.asset);
3948
- const result = await this.client.signAndExecuteTransaction({
3949
- signer: this.keypair,
3950
- transaction: tx,
3951
- options: { showEffects: true }
3947
+ const gasResult = await executeWithGas(this.client, this.keypair, async () => {
3948
+ const { tx } = await adapter.buildSaveTx(this._address, depositAmount, params.asset);
3949
+ return tx;
3952
3950
  });
3953
- await this.client.waitForTransaction({ digest: result.digest });
3954
- const gasCost = result.effects?.gasUsed ? Math.abs(
3955
- (Number(result.effects.gasUsed.computationCost) + Number(result.effects.gasUsed.storageCost) - Number(result.effects.gasUsed.storageRebate)) / 1e9
3956
- ) : 0;
3957
3951
  this.portfolio.recordEarn(params.asset, adapter.id, rate.saveApy);
3958
3952
  return {
3959
3953
  success: true,
3960
- tx: result.digest,
3954
+ tx: gasResult.digest,
3961
3955
  asset: params.asset,
3962
3956
  amount: depositAmount,
3963
3957
  protocol: adapter.name,
3964
3958
  apy: rate.saveApy,
3965
- gasCost,
3966
- gasMethod: "self-funded"
3959
+ gasCost: gasResult.gasCostSui,
3960
+ gasMethod: gasResult.gasMethod
3967
3961
  };
3968
3962
  }
3969
3963
  async investUnearn(params) {
@@ -3982,27 +3976,23 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
3982
3976
  const positions = await adapter.getPositions(this._address);
3983
3977
  const supply = positions.supplies.find((s) => s.asset === params.asset);
3984
3978
  const withdrawAmount = supply?.amount ?? pos.totalAmount;
3985
- const { tx, effectiveAmount } = await adapter.buildWithdrawTx(this._address, withdrawAmount, params.asset);
3986
- const result = await this.client.signAndExecuteTransaction({
3987
- signer: this.keypair,
3988
- transaction: tx,
3989
- options: { showEffects: true }
3990
- });
3991
- await this.client.waitForTransaction({ digest: result.digest });
3992
- const gasCost = result.effects?.gasUsed ? Math.abs(
3993
- (Number(result.effects.gasUsed.computationCost) + Number(result.effects.gasUsed.storageCost) - Number(result.effects.gasUsed.storageRebate)) / 1e9
3994
- ) : 0;
3995
3979
  const protocolName = adapter.name;
3980
+ let effectiveAmount = withdrawAmount;
3981
+ const gasResult = await executeWithGas(this.client, this.keypair, async () => {
3982
+ const result = await adapter.buildWithdrawTx(this._address, withdrawAmount, params.asset);
3983
+ effectiveAmount = result.effectiveAmount;
3984
+ return result.tx;
3985
+ });
3996
3986
  this.portfolio.recordUnearn(params.asset);
3997
3987
  return {
3998
3988
  success: true,
3999
- tx: result.digest,
3989
+ tx: gasResult.digest,
4000
3990
  asset: params.asset,
4001
3991
  amount: effectiveAmount,
4002
3992
  protocol: protocolName,
4003
3993
  apy: 0,
4004
- gasCost,
4005
- gasMethod: "self-funded"
3994
+ gasCost: gasResult.gasCostSui,
3995
+ gasMethod: gasResult.gasMethod
4006
3996
  };
4007
3997
  }
4008
3998
  async getPortfolio() {