@cryptorubic/web3 1.1.0-alpha-stellar.14 → 1.1.0-alpha-stellar.16

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.14",
3
+ "version": "1.1.0-alpha-stellar.16",
4
4
  "dependencies": {
5
5
  "@ethersproject/bignumber": "^5.8.0",
6
6
  "@mysten/sui": "^1.24.0",
@@ -1,7 +1,8 @@
1
1
  import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
2
+ import { Transaction } from '@stellar/stellar-sdk';
2
3
  export interface StellarSendTxParams {
3
4
  txOptions: StellarTransactionOptions;
4
5
  }
5
6
  export interface StellarTransactionOptions extends BasicSendTransactionOptions {
6
- transaction: string;
7
+ transaction: string | Transaction;
7
8
  }
@@ -25,7 +25,10 @@ class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSign
25
25
  }
26
26
  async sendTransaction(params) {
27
27
  try {
28
- const preparedTransaction = await this.publicClient.prepareTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(params.txOptions.transaction, stellar_sdk_1.Networks.PUBLIC));
28
+ const transaction = typeof params.txOptions.transaction === 'string'
29
+ ? stellar_sdk_1.TransactionBuilder.fromXDR(params.txOptions.transaction, stellar_sdk_1.Networks.PUBLIC)
30
+ : params.txOptions.transaction;
31
+ const preparedTransaction = await this.publicClient.prepareTransaction(transaction);
29
32
  const { signedTxXdr } = await this.wallet.signTransaction(preparedTransaction.toXDR(), {
30
33
  networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
31
34
  address: this.walletAddress
@@ -34,7 +37,9 @@ class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSign
34
37
  if (resp.status === 'ERROR') {
35
38
  throw new Error('Failed to execute transaction', { cause: resp.errorResult });
36
39
  }
37
- params.txOptions?.onTransactionHash?.(resp.hash);
40
+ if (params.txOptions.onTransactionHash) {
41
+ params.txOptions.onTransactionHash?.(resp.hash);
42
+ }
38
43
  return resp.hash;
39
44
  }
40
45
  catch (err) {
@@ -26,6 +26,8 @@ export declare class StellarAdapter extends AbstractAdapter<StellarClient, Stell
26
26
  callForTokenInfo(tokenAddress: string): Promise<Token<BlockchainName>>;
27
27
  checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
28
28
  checkTrustline(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
29
+ addTrustline(tokenAddress: string): Promise<string>;
30
+ encodeTrustline(tokenAddress: string, walletAddress: string): Promise<string>;
29
31
  getTokenContractId(tokenAddress: string): string;
30
32
  private convertTokenAddressToAsset;
31
33
  read<T>(address: string, method: string, methodArgs?: {
@@ -87,6 +87,42 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
87
87
  return false;
88
88
  }
89
89
  }
90
+ async addTrustline(tokenAddress) {
91
+ try {
92
+ const account = await this.public.getAccount(this.signer.walletAddress);
93
+ const tx = new stellar_sdk_1.TransactionBuilder(account, {
94
+ fee: stellar_sdk_1.BASE_FEE,
95
+ networkPassphrase: stellar_sdk_1.Networks.PUBLIC
96
+ })
97
+ .addOperation(stellar_sdk_1.Operation.changeTrust({
98
+ asset: this.convertTokenAddressToAsset(tokenAddress)
99
+ }))
100
+ .setTimeout(30)
101
+ .build();
102
+ return this.signer.sendTransaction({
103
+ txOptions: {
104
+ transaction: tx
105
+ }
106
+ });
107
+ }
108
+ catch (err) {
109
+ this.logger?.customError('FAILED TO ADD TRUSTLINE', err);
110
+ throw err;
111
+ }
112
+ }
113
+ async encodeTrustline(tokenAddress, walletAddress) {
114
+ const account = await this.public.getAccount(walletAddress);
115
+ const tx = new stellar_sdk_1.TransactionBuilder(account, {
116
+ fee: stellar_sdk_1.BASE_FEE,
117
+ networkPassphrase: stellar_sdk_1.Networks.PUBLIC
118
+ })
119
+ .addOperation(stellar_sdk_1.Operation.changeTrust({
120
+ asset: this.convertTokenAddressToAsset(tokenAddress)
121
+ }))
122
+ .setTimeout(30)
123
+ .build();
124
+ return tx.toXDR();
125
+ }
90
126
  getTokenContractId(tokenAddress) {
91
127
  if (web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, tokenAddress)) {
92
128
  return stellar_sdk_1.Asset.native().contractId(stellar_sdk_1.Networks.PUBLIC);