@cryptorubic/web3 1.1.0-alpha-stellar.29 → 1.1.0-alpha-stellar.31
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 +1 -1
- package/src/lib/adapter/adapters/adapter-evm/signer/evm-adapter-signer.d.ts +1 -1
- package/src/lib/adapter/adapters/adapter-evm/signer/evm-adapter-signer.js +7 -7
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-client.d.ts +1 -4
- package/src/lib/adapter/adapters/adapter-stellar/signer/stellar-adapter-signer.js +2 -2
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.d.ts +2 -3
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.js +18 -29
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +0 -1
- package/src/lib/adapter/blockchain-adapter-factory.service.js +5 -6
- package/src/lib/adapter/models/create-factory-params.d.ts +2 -4
- package/src/lib/errors/blockchain/user-reject.error.d.ts +1 -1
- package/src/lib/errors/blockchain/user-reject.error.js +2 -2
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-provider-url.d.ts +0 -4
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-provider-url.js +0 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
+
import { Abi, PublicActions, PublicClient, TransactionReceipt, WalletActions, WalletClient } from 'viem';
|
|
2
3
|
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
3
4
|
import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
|
|
4
|
-
import { Abi, PublicActions, PublicClient, TransactionReceipt, WalletActions, WalletClient } from 'viem';
|
|
5
5
|
import { EvmSendTxParams, EvmTransactionOptions } from '../models/evm-send-tx-params';
|
|
6
6
|
import { Web3Error } from '../utils/parse-evm-error';
|
|
7
7
|
export declare class EvmAdapterSigner extends AbstractAdapterSigner<WalletClient & WalletActions, EvmSendTxParams, TransactionReceipt> {
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EvmAdapterSigner = void 0;
|
|
4
4
|
const core_1 = require("@cryptorubic/core");
|
|
5
|
-
const
|
|
5
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const actions_1 = require("viem/actions");
|
|
8
|
-
const
|
|
8
|
+
const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
|
|
9
|
+
const rubic_sdk_error_1 = require("../../../../errors/rubic-sdk.error");
|
|
9
10
|
const viem_blockchain_mapping_1 = require("../../../constants/viem-blockchain-mapping");
|
|
11
|
+
const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
|
|
12
|
+
const options_1 = require("../../utils/options");
|
|
10
13
|
const parse_evm_error_1 = require("../utils/parse-evm-error");
|
|
11
|
-
const rubic_sdk_error_1 = require("../../../../errors/rubic-sdk.error");
|
|
12
|
-
const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
|
|
13
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
14
14
|
class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
|
|
15
15
|
get publicClient() {
|
|
16
16
|
if (!this.publicRef.public) {
|
|
@@ -73,8 +73,8 @@ class EvmAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
|
|
|
73
73
|
value,
|
|
74
74
|
...(params.txOptions.data && { data: params.txOptions.data })
|
|
75
75
|
};
|
|
76
|
-
const gas = await this.publicClient.estimateGas(gaslessParams);
|
|
77
|
-
const calculatedGas = params.txOptions.gasLimitRatio
|
|
76
|
+
const gas = params.txOptions.gas ? BigInt(params.txOptions.gas) : await this.publicClient.estimateGas(gaslessParams);
|
|
77
|
+
const calculatedGas = !params.txOptions.gas && params.txOptions.gasLimitRatio
|
|
78
78
|
? BigInt(new bignumber_js_1.default(gas.toString()).multipliedBy(params.txOptions.gasLimitRatio).toFixed(0))
|
|
79
79
|
: gas;
|
|
80
80
|
const gasfulParams = {
|
|
@@ -28,12 +28,12 @@ class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSign
|
|
|
28
28
|
const transaction = typeof params.txOptions.transaction === 'string'
|
|
29
29
|
? stellar_sdk_1.TransactionBuilder.fromXDR(params.txOptions.transaction, stellar_sdk_1.Networks.PUBLIC)
|
|
30
30
|
: params.txOptions.transaction;
|
|
31
|
-
const preparedTransaction = await this.publicClient.
|
|
31
|
+
const preparedTransaction = await this.publicClient.prepareTransaction(transaction);
|
|
32
32
|
const { signedTxXdr } = await this.wallet.signTransaction(preparedTransaction.toXDR(), {
|
|
33
33
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
34
34
|
address: this.walletAddress
|
|
35
35
|
});
|
|
36
|
-
const resp = await this.publicClient.
|
|
36
|
+
const resp = await this.publicClient.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
37
37
|
if (resp.status === 'ERROR') {
|
|
38
38
|
throw new Error('Failed to execute transaction', { cause: resp.errorResult });
|
|
39
39
|
}
|
|
@@ -11,11 +11,10 @@ import { Abi } from 'viem';
|
|
|
11
11
|
import { MethodData } from '../models/web3-public-models/method-data';
|
|
12
12
|
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
13
13
|
import { StellarTransactionConfig } from '../../../utils/models/stellar-transaction-config';
|
|
14
|
-
import { StellarProviderUrl } from './models/stellar-provider-url';
|
|
15
14
|
export declare class StellarAdapter extends AbstractAdapter<StellarClient, StellarWallet, StellarBlockchainName> {
|
|
16
|
-
private readonly
|
|
15
|
+
private readonly rpcList;
|
|
17
16
|
readonly signer: StellarAdapterSigner;
|
|
18
|
-
constructor(
|
|
17
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
19
18
|
initWeb3Client(): void;
|
|
20
19
|
getBlockNumber(): Promise<number | {
|
|
21
20
|
blockNumber: number;
|
|
@@ -11,23 +11,19 @@ const bignumber_js_1 = require("bignumber.js");
|
|
|
11
11
|
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
12
12
|
const fake_stellar_wallet_1 = require("./constants/fake-stellar-wallet");
|
|
13
13
|
class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(rpcList, httpClient, logger, clientParams) {
|
|
15
15
|
super(core_1.BLOCKCHAIN_NAME.STELLAR, logger);
|
|
16
|
-
this.
|
|
16
|
+
this.rpcList = rpcList;
|
|
17
17
|
this.signer = new stellar_adapter_signer_1.StellarAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
18
18
|
}
|
|
19
19
|
initWeb3Client() {
|
|
20
|
-
|
|
20
|
+
this.public = new stellar_sdk_2.rpc.Server(this.rpcList[0], {
|
|
21
21
|
allowHttp: true,
|
|
22
22
|
timeout: 5000
|
|
23
|
-
};
|
|
24
|
-
this.public = {
|
|
25
|
-
soroban: new stellar_sdk_2.rpc.Server(this.stellarProviderUrl.sorobanUrl, serverOptions),
|
|
26
|
-
horizon: new stellar_sdk_2.rpc.Server(this.stellarProviderUrl.horizonUrl, serverOptions)
|
|
27
|
-
};
|
|
23
|
+
});
|
|
28
24
|
}
|
|
29
25
|
async getBlockNumber() {
|
|
30
|
-
const { sequence } = await this.public.
|
|
26
|
+
const { sequence } = await this.public.getLatestLedger();
|
|
31
27
|
return sequence;
|
|
32
28
|
}
|
|
33
29
|
async getTokensBalances(userAddress, tokensAddresses) {
|
|
@@ -36,10 +32,10 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
36
32
|
async getBalance(userAddress, tokenAddress) {
|
|
37
33
|
try {
|
|
38
34
|
if (!tokenAddress || web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, tokenAddress)) {
|
|
39
|
-
const resp = await this.public.
|
|
35
|
+
const resp = await this.public.getAccountEntry(userAddress);
|
|
40
36
|
return new bignumber_js_1.default(resp.balance().toString());
|
|
41
37
|
}
|
|
42
|
-
const resp = await this.public.
|
|
38
|
+
const resp = await this.public.getTrustline(userAddress, this.convertTokenAddressToAsset(tokenAddress));
|
|
43
39
|
return new bignumber_js_1.default(resp.balance().toString());
|
|
44
40
|
}
|
|
45
41
|
catch {
|
|
@@ -60,7 +56,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
60
56
|
.addOperation(contract.call(method))
|
|
61
57
|
.setTimeout(30)
|
|
62
58
|
.build();
|
|
63
|
-
const resp = await this.public.
|
|
59
|
+
const resp = await this.public.simulateTransaction(tx);
|
|
64
60
|
if ('error' in resp) {
|
|
65
61
|
throw new Error(resp.error);
|
|
66
62
|
}
|
|
@@ -84,33 +80,26 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
84
80
|
return false;
|
|
85
81
|
}
|
|
86
82
|
try {
|
|
87
|
-
const trustline = await this.public.
|
|
83
|
+
const trustline = await this.public.getTrustline(walletAddress, this.convertTokenAddressToAsset(token.address));
|
|
88
84
|
return new bignumber_js_1.default(trustline.limit().toString()).lt(token.weiAmount);
|
|
89
85
|
}
|
|
90
86
|
catch (err) {
|
|
91
|
-
console.error(err);
|
|
92
87
|
return true;
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
90
|
async addTrustline(tokenAddress) {
|
|
96
91
|
try {
|
|
97
92
|
const tx = await this.encodeTrustline(tokenAddress, this.signer.walletAddress);
|
|
98
|
-
try {
|
|
99
|
-
const resp = await this.public.horizon.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(tx, stellar_sdk_1.Networks.PUBLIC), undefined, 'record_allow_nonroot');
|
|
100
|
-
console.log(resp);
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
console.log(err);
|
|
104
|
-
}
|
|
105
93
|
const { signedTxXdr } = await this.signer.wallet.signTransaction(tx, {
|
|
106
94
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
107
95
|
address: this.signer.walletAddress
|
|
108
96
|
});
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
const { hash } = await this.public.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
98
|
+
const resp = await this.public.pollTransaction(hash);
|
|
99
|
+
if (resp.status === 'FAILED') {
|
|
100
|
+
throw new Error('Failed to execute transaction', { cause: resp.resultXdr });
|
|
112
101
|
}
|
|
113
|
-
return resp.
|
|
102
|
+
return resp.txHash;
|
|
114
103
|
}
|
|
115
104
|
catch (err) {
|
|
116
105
|
this.logger?.customError('FAILED TO ADD TRUSTLINE', err);
|
|
@@ -118,7 +107,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
118
107
|
}
|
|
119
108
|
}
|
|
120
109
|
async encodeTrustline(tokenAddress, walletAddress) {
|
|
121
|
-
const account = await this.public.
|
|
110
|
+
const account = await this.public.getAccount(walletAddress);
|
|
122
111
|
const tx = new stellar_sdk_1.TransactionBuilder(account, {
|
|
123
112
|
fee: stellar_sdk_1.BASE_FEE,
|
|
124
113
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
@@ -151,7 +140,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
151
140
|
.addOperation(operation)
|
|
152
141
|
.setTimeout(30)
|
|
153
142
|
.build();
|
|
154
|
-
const resp = await this.public.
|
|
143
|
+
const resp = await this.public.simulateTransaction(tx);
|
|
155
144
|
if ('error' in resp) {
|
|
156
145
|
throw new Error(resp.error);
|
|
157
146
|
}
|
|
@@ -160,7 +149,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
160
149
|
}
|
|
161
150
|
async simulateTransaction(config) {
|
|
162
151
|
try {
|
|
163
|
-
const resp = await this.public.
|
|
152
|
+
const resp = await this.public.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(config.transaction, stellar_sdk_1.Networks.PUBLIC));
|
|
164
153
|
if ('error' in resp) {
|
|
165
154
|
throw new Error(resp.error);
|
|
166
155
|
}
|
|
@@ -173,7 +162,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
173
162
|
}
|
|
174
163
|
async getTransactionStatus(srcTxHash) {
|
|
175
164
|
try {
|
|
176
|
-
const resp = await this.public.
|
|
165
|
+
const resp = await this.public.pollTransaction(srcTxHash);
|
|
177
166
|
if (resp.status === 'SUCCESS') {
|
|
178
167
|
return tx_status_1.TX_STATUS.SUCCESS;
|
|
179
168
|
}
|
|
@@ -15,7 +15,6 @@ export declare class BlockchainAdapterFactoryService {
|
|
|
15
15
|
private readonly createLogger?;
|
|
16
16
|
private readonly tonParams?;
|
|
17
17
|
private readonly clientParams?;
|
|
18
|
-
private readonly stellarParams?;
|
|
19
18
|
readonly adapterStore: Partial<Record<BlockchainName, AbstractAdapter<unknown, unknown, BlockchainName>>>;
|
|
20
19
|
protected readonly logger?: ICustomLogger;
|
|
21
20
|
private constructor();
|
|
@@ -11,13 +11,12 @@ const tron_adapter_1 = require("./adapters/adapter-tron/tron-adapter");
|
|
|
11
11
|
const sui_adapter_1 = require("./adapters/adapter-sui/sui-adapter");
|
|
12
12
|
const stellar_adapter_1 = require("./adapters/adapter-stellar/stellar-adapter");
|
|
13
13
|
class BlockchainAdapterFactoryService {
|
|
14
|
-
constructor(rpcList, httpClient, createLogger, tonParams, clientParams
|
|
14
|
+
constructor(rpcList, httpClient, createLogger, tonParams, clientParams) {
|
|
15
15
|
this.rpcList = rpcList;
|
|
16
16
|
this.httpClient = httpClient;
|
|
17
17
|
this.createLogger = createLogger;
|
|
18
18
|
this.tonParams = tonParams;
|
|
19
19
|
this.clientParams = clientParams;
|
|
20
|
-
this.stellarParams = stellarParams;
|
|
21
20
|
this.adapterStore = {};
|
|
22
21
|
this.adapterStore = this.createStorage();
|
|
23
22
|
if (this.createLogger) {
|
|
@@ -32,7 +31,7 @@ class BlockchainAdapterFactoryService {
|
|
|
32
31
|
// @TODO Add default logger
|
|
33
32
|
const loggerFn = params.createLogger || undefined;
|
|
34
33
|
const resolvedHttpClient = params.httpClient ?? (await Promise.resolve().then(() => require('axios')));
|
|
35
|
-
return new this(params.rpcList, resolvedHttpClient, params.createLogger, params.tonParams, params.clientParams
|
|
34
|
+
return new this(params.rpcList, resolvedHttpClient, params.createLogger, params.tonParams, params.clientParams);
|
|
36
35
|
}
|
|
37
36
|
getAdapter(blockchain) {
|
|
38
37
|
const adapter = this.adapterStore?.[blockchain];
|
|
@@ -82,6 +81,9 @@ class BlockchainAdapterFactoryService {
|
|
|
82
81
|
if (blockchainType === core_1.CHAIN_TYPE.SOLANA) {
|
|
83
82
|
return new solana_adapter_1.SolanaAdapter(rpcs, this.httpClient, this.createLogger?.(`SOLANA_ADAPTER`), this.clientParams);
|
|
84
83
|
}
|
|
84
|
+
if (blockchain === core_1.BLOCKCHAIN_NAME.STELLAR) {
|
|
85
|
+
return new stellar_adapter_1.StellarAdapter(rpcs, this.httpClient, this.logger, this.clientParams);
|
|
86
|
+
}
|
|
85
87
|
}
|
|
86
88
|
if (blockchain === core_1.BLOCKCHAIN_NAME.TON && this.tonParams?.tonApiConfig && this.tonParams?.tonClientConfig) {
|
|
87
89
|
return new ton_adapter_1.TonAdapter(this.httpClient, this.tonParams, this.createLogger?.(`TON_ADAPTER`), this.clientParams);
|
|
@@ -89,9 +91,6 @@ class BlockchainAdapterFactoryService {
|
|
|
89
91
|
if (blockchain === core_1.BLOCKCHAIN_NAME.BITCOIN && this.httpClient) {
|
|
90
92
|
return new bitcoin_adapter_1.BitcoinAdapter(this.httpClient, this.createLogger?.(`BTC_ADAPTER`), this.clientParams);
|
|
91
93
|
}
|
|
92
|
-
if (blockchain === core_1.BLOCKCHAIN_NAME.STELLAR && this.stellarParams) {
|
|
93
|
-
return new stellar_adapter_1.StellarAdapter(this.stellarParams, this.httpClient, this.logger, this.clientParams);
|
|
94
|
-
}
|
|
95
94
|
return null;
|
|
96
95
|
}
|
|
97
96
|
connectWallet(blockchain, wallet) {
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName, SuiBlockchainName, TronBlockchainName } from '@cryptorubic/core';
|
|
1
|
+
import { EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName, StellarBlockchainName, SuiBlockchainName, TronBlockchainName } from '@cryptorubic/core';
|
|
2
2
|
import { EnvType } from '../constants/models/env-type';
|
|
3
3
|
import { TronWebProvider } from '../adapters/adapter-tron/models/tron-web-provider';
|
|
4
4
|
import { TonAdapterConfig } from '../adapters/models/ton-adapter-config';
|
|
5
5
|
import { FallbackTransportConfig, HttpTransportConfig } from 'viem';
|
|
6
|
-
|
|
7
|
-
export type RpcListType = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<SuiBlockchainName, string[]>;
|
|
6
|
+
export type RpcListType = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<SuiBlockchainName, string[]> & Record<StellarBlockchainName, string[]>;
|
|
8
7
|
export interface AdapterFactoryParams {
|
|
9
8
|
rpcList: RpcListType;
|
|
10
9
|
httpClient?: HttpClient;
|
|
11
10
|
tonParams?: TonAdapterConfig;
|
|
12
11
|
createLogger?: (label: string) => ICustomLogger;
|
|
13
12
|
clientParams?: ClientAdaptersFactoryParams;
|
|
14
|
-
stellarParams: StellarProviderUrl;
|
|
15
13
|
}
|
|
16
14
|
export interface ClientAdaptersFactoryParams {
|
|
17
15
|
envType: EnvType;
|
|
@@ -6,8 +6,8 @@ const rubic_sdk_error_1 = require("../rubic-sdk.error");
|
|
|
6
6
|
* Thrown, when user cancels transaction.
|
|
7
7
|
*/
|
|
8
8
|
class UserRejectError extends rubic_sdk_error_1.RubicSdkError {
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
11
|
Object.setPrototypeOf(this, UserRejectError.prototype);
|
|
12
12
|
}
|
|
13
13
|
}
|