@cryptorubic/web3 1.1.0-alpha-stellar.36 → 1.1.0-alpha-stellar.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cryptorubic/web3",
3
- "version": "1.1.0-alpha-stellar.36",
3
+ "version": "1.1.0-alpha-stellar.38",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -4,6 +4,8 @@ exports.StellarAdapterSigner = void 0;
4
4
  const core_1 = require("@cryptorubic/core");
5
5
  const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
6
6
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
7
+ const bignumber_js_1 = require("bignumber.js");
8
+ const insufficient_funds_gas_price_value_error_1 = require("packages/web3/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error");
7
9
  class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
8
10
  get publicClient() {
9
11
  if (!this.publicRef.public) {
@@ -28,7 +30,14 @@ class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSign
28
30
  const transaction = typeof params.txOptions.transaction === 'string'
29
31
  ? stellar_sdk_1.TransactionBuilder.fromXDR(params.txOptions.transaction, stellar_sdk_1.Networks.PUBLIC)
30
32
  : params.txOptions.transaction;
31
- const preparedTransaction = await this.publicClient.prepareTransaction(transaction);
33
+ const [preparedTransaction, accountInfo] = await Promise.all([
34
+ this.publicClient.prepareTransaction(transaction),
35
+ this.publicClient.getAccountEntry(this.walletAddress)
36
+ ]);
37
+ const necessaryBalance = new bignumber_js_1.default(2 + accountInfo.numSubEntries()).multipliedBy(5000000).plus(preparedTransaction.fee);
38
+ if (necessaryBalance.gt(accountInfo.balance().toString())) {
39
+ throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
40
+ }
32
41
  const { signedTxXdr } = await this.wallet.signTransaction(preparedTransaction.toXDR(), {
33
42
  networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
34
43
  address: this.walletAddress
@@ -40,6 +40,7 @@ export declare class StellarAdapter extends AbstractAdapter<StellarClient, Stell
40
40
  simulateTransaction(config: StellarTransactionConfig): Promise<string>;
41
41
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
42
42
  getMinWeiBalance(userAddress: string): Promise<BigNumber>;
43
+ getFeeFromTransaction(xdr: string): BigNumber;
43
44
  callContractMethod<T extends Web3PrimitiveType = string>(_contractAddress: string, _contractAbi: Abi | undefined, _methodName: string, _methodArguments?: {
44
45
  value: string;
45
46
  type: string;
@@ -209,6 +209,10 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
209
209
  return new bignumber_js_1.default(0);
210
210
  }
211
211
  }
212
+ getFeeFromTransaction(xdr) {
213
+ const parsedTranssaction = stellar_sdk_1.TransactionBuilder.fromXDR(xdr, stellar_sdk_1.Networks.PUBLIC);
214
+ return new bignumber_js_1.default(parsedTranssaction.fee);
215
+ }
212
216
  async callContractMethod(_contractAddress, _contractAbi = [], _methodName, _methodArguments = [], _options) {
213
217
  throw new Error('Method call is not supported');
214
218
  }