@cryptorubic/web3 1.1.0-alpha-stellar.29 → 1.1.0-alpha-stellar.30
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-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 -28
- 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/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
|
@@ -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,7 +80,7 @@ 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) {
|
|
@@ -95,22 +91,16 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
95
91
|
async addTrustline(tokenAddress) {
|
|
96
92
|
try {
|
|
97
93
|
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
94
|
const { signedTxXdr } = await this.signer.wallet.signTransaction(tx, {
|
|
106
95
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
107
96
|
address: this.signer.walletAddress
|
|
108
97
|
});
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
const { hash } = await this.public.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
99
|
+
const resp = await this.public.pollTransaction(hash);
|
|
100
|
+
if (resp.status === 'FAILED') {
|
|
101
|
+
throw new Error('Failed to execute transaction', { cause: resp.resultXdr });
|
|
112
102
|
}
|
|
113
|
-
return resp.
|
|
103
|
+
return resp.txHash;
|
|
114
104
|
}
|
|
115
105
|
catch (err) {
|
|
116
106
|
this.logger?.customError('FAILED TO ADD TRUSTLINE', err);
|
|
@@ -118,7 +108,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
118
108
|
}
|
|
119
109
|
}
|
|
120
110
|
async encodeTrustline(tokenAddress, walletAddress) {
|
|
121
|
-
const account = await this.public.
|
|
111
|
+
const account = await this.public.getAccount(walletAddress);
|
|
122
112
|
const tx = new stellar_sdk_1.TransactionBuilder(account, {
|
|
123
113
|
fee: stellar_sdk_1.BASE_FEE,
|
|
124
114
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
@@ -151,7 +141,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
151
141
|
.addOperation(operation)
|
|
152
142
|
.setTimeout(30)
|
|
153
143
|
.build();
|
|
154
|
-
const resp = await this.public.
|
|
144
|
+
const resp = await this.public.simulateTransaction(tx);
|
|
155
145
|
if ('error' in resp) {
|
|
156
146
|
throw new Error(resp.error);
|
|
157
147
|
}
|
|
@@ -160,7 +150,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
160
150
|
}
|
|
161
151
|
async simulateTransaction(config) {
|
|
162
152
|
try {
|
|
163
|
-
const resp = await this.public.
|
|
153
|
+
const resp = await this.public.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(config.transaction, stellar_sdk_1.Networks.PUBLIC));
|
|
164
154
|
if ('error' in resp) {
|
|
165
155
|
throw new Error(resp.error);
|
|
166
156
|
}
|
|
@@ -173,7 +163,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
173
163
|
}
|
|
174
164
|
async getTransactionStatus(srcTxHash) {
|
|
175
165
|
try {
|
|
176
|
-
const resp = await this.public.
|
|
166
|
+
const resp = await this.public.pollTransaction(srcTxHash);
|
|
177
167
|
if (resp.status === 'SUCCESS') {
|
|
178
168
|
return tx_status_1.TX_STATUS.SUCCESS;
|
|
179
169
|
}
|
|
@@ -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;
|