@cryptorubic/web3 1.1.0-alpha-stellar.15 → 1.1.0-alpha-stellar.17
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
|
@@ -27,6 +27,7 @@ export declare class StellarAdapter extends AbstractAdapter<StellarClient, Stell
|
|
|
27
27
|
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
28
28
|
checkTrustline(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
29
29
|
addTrustline(tokenAddress: string): Promise<string>;
|
|
30
|
+
encodeTrustline(tokenAddress: string, walletAddress: string): Promise<string>;
|
|
30
31
|
getTokenContractId(tokenAddress: string): string;
|
|
31
32
|
private convertTokenAddressToAsset;
|
|
32
33
|
read<T>(address: string, method: string, methodArgs?: {
|
|
@@ -89,27 +89,35 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
89
89
|
}
|
|
90
90
|
async addTrustline(tokenAddress) {
|
|
91
91
|
try {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
}
|
|
92
|
+
const tx = await this.encodeTrustline(tokenAddress, this.signer.walletAddress);
|
|
93
|
+
const { signedTxXdr } = await this.signer.wallet.signTransaction(tx, {
|
|
94
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
95
|
+
address: this.signer.walletAddress
|
|
106
96
|
});
|
|
97
|
+
const resp = await this.public.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
98
|
+
if (resp.status === 'ERROR') {
|
|
99
|
+
throw new Error('Failed to execute transaction', { cause: resp.errorResult });
|
|
100
|
+
}
|
|
101
|
+
return resp.hash;
|
|
107
102
|
}
|
|
108
103
|
catch (err) {
|
|
109
104
|
this.logger?.customError('FAILED TO ADD TRUSTLINE', err);
|
|
110
105
|
throw err;
|
|
111
106
|
}
|
|
112
107
|
}
|
|
108
|
+
async encodeTrustline(tokenAddress, walletAddress) {
|
|
109
|
+
const account = await this.public.getAccount(walletAddress);
|
|
110
|
+
const tx = new stellar_sdk_1.TransactionBuilder(account, {
|
|
111
|
+
fee: stellar_sdk_1.BASE_FEE,
|
|
112
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
113
|
+
})
|
|
114
|
+
.addOperation(stellar_sdk_1.Operation.changeTrust({
|
|
115
|
+
asset: this.convertTokenAddressToAsset(tokenAddress)
|
|
116
|
+
}))
|
|
117
|
+
.setTimeout(30)
|
|
118
|
+
.build();
|
|
119
|
+
return tx.toXDR();
|
|
120
|
+
}
|
|
113
121
|
getTokenContractId(tokenAddress) {
|
|
114
122
|
if (web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, tokenAddress)) {
|
|
115
123
|
return stellar_sdk_1.Asset.native().contractId(stellar_sdk_1.Networks.PUBLIC);
|