@cryptorubic/web3 1.1.0-alpha-stellar.10 → 1.1.0-alpha-stellar.12

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.10",
3
+ "version": "1.1.0-alpha-stellar.12",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -3,14 +3,14 @@ import { AbstractAdapter } from '../common/abstract-adapter';
3
3
  import { StellarClient } from './models/stellar-client';
4
4
  import { StellarWallet } from './models/stellar-wallet';
5
5
  import { TxStatus } from '../models/web3-public-models/tx-status';
6
- import { StellarTransactionConfig } from '../../../utils/models/stellar-transaction-config';
7
6
  import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
8
7
  import { StellarAdapterSigner } from './signer/stellar-adapter-signer';
9
8
  import BigNumber from 'bignumber.js';
10
- import { Abi } from 'viem';
11
9
  import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
12
- import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
10
+ import { Abi } from 'viem';
13
11
  import { MethodData } from '../models/web3-public-models/method-data';
12
+ import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
13
+ import { StellarTransactionConfig } from '../../../utils/models/stellar-transaction-config';
14
14
  export declare class StellarAdapter extends AbstractAdapter<StellarClient, StellarWallet, StellarBlockchainName> {
15
15
  private readonly rpcList;
16
16
  readonly signer: StellarAdapterSigner;
@@ -25,13 +25,14 @@ export declare class StellarAdapter extends AbstractAdapter<StellarClient, Stell
25
25
  callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
26
26
  callForTokenInfo(tokenAddress: string): Promise<Token<BlockchainName>>;
27
27
  checkEnoughBalance(token: TokenAmount, walletAddress: string): Promise<boolean>;
28
+ checkTrustline(token: TokenAmount, walletAddress: string): Promise<boolean>;
28
29
  getTokenContractId(tokenAddress: string): string;
29
30
  private convertTokenAddressToAsset;
30
31
  read<T>(address: string, method: string, methodArgs?: {
31
32
  value: string;
32
33
  type: string;
33
34
  }[]): Promise<T>;
34
- simulateTransaction(config: StellarTransactionConfig, from: string, timeout?: number): Promise<string>;
35
+ simulateTransaction(config: StellarTransactionConfig): Promise<string>;
35
36
  getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
36
37
  callContractMethod<T extends Web3PrimitiveType = string>(_contractAddress: string, _contractAbi: Abi | undefined, _methodName: string, _methodArguments?: {
37
38
  value: string;
@@ -48,17 +48,15 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
48
48
  async callForTokenInfo(tokenAddress) {
49
49
  const metadata = ['name', 'symbol', 'decimals'];
50
50
  const contract = new stellar_sdk_1.Contract(this.getTokenContractId(tokenAddress));
51
- const builder = new stellar_sdk_1.TransactionBuilder(new stellar_sdk_1.Account(fake_stellar_wallet_1.FAKE_STELLAR_WALLET, '0'), {
52
- fee: stellar_sdk_1.BASE_FEE,
53
- networkPassphrase: stellar_sdk_1.Networks.PUBLIC
54
- })
55
- .setTimeout(30)
56
- .build();
57
- const [name, symbol, decimals] = await Promise.all(metadata.map(async (value) => {
58
- builder.operations.pop();
59
- //@ts-ignore
60
- builder.operations.push(contract.call(value));
61
- const resp = await this.public.simulateTransaction(builder);
51
+ const [name, symbol, decimals] = await Promise.all(metadata.map(async (method) => {
52
+ const tx = new stellar_sdk_1.TransactionBuilder(new stellar_sdk_1.Account(fake_stellar_wallet_1.FAKE_STELLAR_WALLET, '0'), {
53
+ fee: stellar_sdk_1.BASE_FEE,
54
+ networkPassphrase: stellar_sdk_1.Networks.PUBLIC
55
+ })
56
+ .addOperation(contract.call(method))
57
+ .setTimeout(30)
58
+ .build();
59
+ const resp = await this.public.simulateTransaction(tx);
62
60
  if ('error' in resp) {
63
61
  throw new Error(resp.error);
64
62
  }
@@ -77,6 +75,15 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
77
75
  const userBalance = await this.getBalance(walletAddress, token.address);
78
76
  return userBalance.gte(token.weiAmount);
79
77
  }
78
+ async checkTrustline(token, walletAddress) {
79
+ try {
80
+ const trustline = await this.public.getTrustline(walletAddress, this.convertTokenAddressToAsset(token.address));
81
+ return token.weiAmount.gte(trustline.limit().toString());
82
+ }
83
+ catch {
84
+ return false;
85
+ }
86
+ }
80
87
  getTokenContractId(tokenAddress) {
81
88
  if (web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, tokenAddress)) {
82
89
  return stellar_sdk_1.Asset.native().contractId(stellar_sdk_1.Networks.PUBLIC);
@@ -105,10 +112,13 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
105
112
  const rawValue = resp.result.retval;
106
113
  return (0, stellar_sdk_1.scValToNative)(rawValue);
107
114
  }
108
- async simulateTransaction(config, from, timeout = 15000) {
115
+ async simulateTransaction(config) {
109
116
  try {
110
- await this.public.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(config.transaction, stellar_sdk_1.Networks.PUBLIC));
111
- return '0';
117
+ const resp = await this.public.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(config.transaction, stellar_sdk_1.Networks.PUBLIC));
118
+ if ('error' in resp) {
119
+ throw new Error(resp.error);
120
+ }
121
+ return resp.minResourceFee;
112
122
  }
113
123
  catch (err) {
114
124
  this.logger?.customError('Error while simulating transaction', err);