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