@cryptorubic/web3 1.1.0-alpha-stellar.26 → 1.1.0-alpha-stellar.28
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 +4 -1
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-provider-url.d.ts +4 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-provider-url.js +2 -0
- 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 +3 -2
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.js +21 -17
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +1 -0
- package/src/lib/adapter/blockchain-adapter-factory.service.js +5 -4
- package/src/lib/adapter/models/create-factory-params.d.ts +4 -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.prepareTransaction(transaction);
|
|
31
|
+
const preparedTransaction = await this.publicClient.soroban.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.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
36
|
+
const resp = await this.publicClient.soroban.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,10 +11,11 @@ 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';
|
|
14
15
|
export declare class StellarAdapter extends AbstractAdapter<StellarClient, StellarWallet, StellarBlockchainName> {
|
|
15
|
-
private readonly
|
|
16
|
+
private readonly stellarProviderUrl;
|
|
16
17
|
readonly signer: StellarAdapterSigner;
|
|
17
|
-
constructor(
|
|
18
|
+
constructor(stellarProviderUrl: StellarProviderUrl, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
18
19
|
initWeb3Client(): void;
|
|
19
20
|
getBlockNumber(): Promise<number | {
|
|
20
21
|
blockNumber: number;
|
|
@@ -11,19 +11,23 @@ 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(stellarProviderUrl, httpClient, logger, clientParams) {
|
|
15
15
|
super(core_1.BLOCKCHAIN_NAME.STELLAR, logger);
|
|
16
|
-
this.
|
|
16
|
+
this.stellarProviderUrl = stellarProviderUrl;
|
|
17
17
|
this.signer = new stellar_adapter_signer_1.StellarAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
18
18
|
}
|
|
19
19
|
initWeb3Client() {
|
|
20
|
-
|
|
20
|
+
const serverOptions = {
|
|
21
21
|
allowHttp: true,
|
|
22
22
|
timeout: 5000
|
|
23
|
-
}
|
|
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
|
+
};
|
|
24
28
|
}
|
|
25
29
|
async getBlockNumber() {
|
|
26
|
-
const { sequence } = await this.public.getLatestLedger();
|
|
30
|
+
const { sequence } = await this.public.soroban.getLatestLedger();
|
|
27
31
|
return sequence;
|
|
28
32
|
}
|
|
29
33
|
async getTokensBalances(userAddress, tokensAddresses) {
|
|
@@ -32,10 +36,10 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
32
36
|
async getBalance(userAddress, tokenAddress) {
|
|
33
37
|
try {
|
|
34
38
|
if (!tokenAddress || web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, tokenAddress)) {
|
|
35
|
-
const resp = await this.public.getAccountEntry(userAddress);
|
|
39
|
+
const resp = await this.public.soroban.getAccountEntry(userAddress);
|
|
36
40
|
return new bignumber_js_1.default(resp.balance().toString());
|
|
37
41
|
}
|
|
38
|
-
const resp = await this.public.getTrustline(userAddress, this.convertTokenAddressToAsset(tokenAddress));
|
|
42
|
+
const resp = await this.public.soroban.getTrustline(userAddress, this.convertTokenAddressToAsset(tokenAddress));
|
|
39
43
|
return new bignumber_js_1.default(resp.balance().toString());
|
|
40
44
|
}
|
|
41
45
|
catch {
|
|
@@ -56,7 +60,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
56
60
|
.addOperation(contract.call(method))
|
|
57
61
|
.setTimeout(30)
|
|
58
62
|
.build();
|
|
59
|
-
const resp = await this.public.simulateTransaction(tx);
|
|
63
|
+
const resp = await this.public.soroban.simulateTransaction(tx);
|
|
60
64
|
if ('error' in resp) {
|
|
61
65
|
throw new Error(resp.error);
|
|
62
66
|
}
|
|
@@ -80,7 +84,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
80
84
|
return false;
|
|
81
85
|
}
|
|
82
86
|
try {
|
|
83
|
-
const trustline = await this.public.getTrustline(walletAddress, this.convertTokenAddressToAsset(token.address));
|
|
87
|
+
const trustline = await this.public.soroban.getTrustline(walletAddress, this.convertTokenAddressToAsset(token.address));
|
|
84
88
|
return new bignumber_js_1.default(trustline.limit().toString()).lt(token.weiAmount);
|
|
85
89
|
}
|
|
86
90
|
catch (err) {
|
|
@@ -92,17 +96,17 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
92
96
|
try {
|
|
93
97
|
const tx = await this.encodeTrustline(tokenAddress, this.signer.walletAddress);
|
|
94
98
|
try {
|
|
95
|
-
const
|
|
96
|
-
console.log(
|
|
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);
|
|
97
101
|
}
|
|
98
102
|
catch (err) {
|
|
99
|
-
console.
|
|
103
|
+
console.log(err);
|
|
100
104
|
}
|
|
101
105
|
const { signedTxXdr } = await this.signer.wallet.signTransaction(tx, {
|
|
102
106
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
103
107
|
address: this.signer.walletAddress
|
|
104
108
|
});
|
|
105
|
-
const resp = await this.public.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
109
|
+
const resp = await this.public.horizon.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
106
110
|
if (resp.status === 'ERROR') {
|
|
107
111
|
throw new Error('Failed to execute transaction', { cause: resp.errorResult });
|
|
108
112
|
}
|
|
@@ -114,7 +118,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
120
|
async encodeTrustline(tokenAddress, walletAddress) {
|
|
117
|
-
const account = await this.public.getAccount(walletAddress);
|
|
121
|
+
const account = await this.public.soroban.getAccount(walletAddress);
|
|
118
122
|
const tx = new stellar_sdk_1.TransactionBuilder(account, {
|
|
119
123
|
fee: stellar_sdk_1.BASE_FEE,
|
|
120
124
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
@@ -147,7 +151,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
147
151
|
.addOperation(operation)
|
|
148
152
|
.setTimeout(30)
|
|
149
153
|
.build();
|
|
150
|
-
const resp = await this.public.simulateTransaction(tx);
|
|
154
|
+
const resp = await this.public.soroban.simulateTransaction(tx);
|
|
151
155
|
if ('error' in resp) {
|
|
152
156
|
throw new Error(resp.error);
|
|
153
157
|
}
|
|
@@ -156,7 +160,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
156
160
|
}
|
|
157
161
|
async simulateTransaction(config) {
|
|
158
162
|
try {
|
|
159
|
-
const resp = await this.public.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(config.transaction, stellar_sdk_1.Networks.PUBLIC));
|
|
163
|
+
const resp = await this.public.soroban.simulateTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(config.transaction, stellar_sdk_1.Networks.PUBLIC));
|
|
160
164
|
if ('error' in resp) {
|
|
161
165
|
throw new Error(resp.error);
|
|
162
166
|
}
|
|
@@ -169,7 +173,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
169
173
|
}
|
|
170
174
|
async getTransactionStatus(srcTxHash) {
|
|
171
175
|
try {
|
|
172
|
-
const resp = await this.public.pollTransaction(srcTxHash);
|
|
176
|
+
const resp = await this.public.soroban.pollTransaction(srcTxHash);
|
|
173
177
|
if (resp.status === 'SUCCESS') {
|
|
174
178
|
return tx_status_1.TX_STATUS.SUCCESS;
|
|
175
179
|
}
|
|
@@ -15,6 +15,7 @@ export declare class BlockchainAdapterFactoryService {
|
|
|
15
15
|
private readonly createLogger?;
|
|
16
16
|
private readonly tonParams?;
|
|
17
17
|
private readonly clientParams?;
|
|
18
|
+
private readonly stellarParams?;
|
|
18
19
|
readonly adapterStore: Partial<Record<BlockchainName, AbstractAdapter<unknown, unknown, BlockchainName>>>;
|
|
19
20
|
protected readonly logger?: ICustomLogger;
|
|
20
21
|
private constructor();
|
|
@@ -11,12 +11,13 @@ 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, stellarParams) {
|
|
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;
|
|
20
21
|
this.adapterStore = {};
|
|
21
22
|
this.adapterStore = this.createStorage();
|
|
22
23
|
if (this.createLogger) {
|
|
@@ -31,7 +32,7 @@ class BlockchainAdapterFactoryService {
|
|
|
31
32
|
// @TODO Add default logger
|
|
32
33
|
const loggerFn = params.createLogger || undefined;
|
|
33
34
|
const resolvedHttpClient = params.httpClient ?? (await Promise.resolve().then(() => require('axios')));
|
|
34
|
-
return new this(params.rpcList, resolvedHttpClient, params.createLogger, params.tonParams, params.clientParams);
|
|
35
|
+
return new this(params.rpcList, resolvedHttpClient, params.createLogger, params.tonParams, params.clientParams, params.stellarParams);
|
|
35
36
|
}
|
|
36
37
|
getAdapter(blockchain) {
|
|
37
38
|
const adapter = this.adapterStore?.[blockchain];
|
|
@@ -81,8 +82,8 @@ class BlockchainAdapterFactoryService {
|
|
|
81
82
|
if (blockchainType === core_1.CHAIN_TYPE.SOLANA) {
|
|
82
83
|
return new solana_adapter_1.SolanaAdapter(rpcs, this.httpClient, this.createLogger?.(`SOLANA_ADAPTER`), this.clientParams);
|
|
83
84
|
}
|
|
84
|
-
if (blockchain === core_1.BLOCKCHAIN_NAME.STELLAR) {
|
|
85
|
-
return new stellar_adapter_1.StellarAdapter(
|
|
85
|
+
if (blockchain === core_1.BLOCKCHAIN_NAME.STELLAR && this.stellarParams) {
|
|
86
|
+
return new stellar_adapter_1.StellarAdapter(this.stellarParams, this.httpClient, this.logger, this.clientParams);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
if (blockchain === core_1.BLOCKCHAIN_NAME.TON && this.tonParams?.tonApiConfig && this.tonParams?.tonClientConfig) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName,
|
|
1
|
+
import { EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName, 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
|
-
|
|
6
|
+
import { StellarProviderUrl } from '../adapters/adapter-stellar/models/stellar-provider-url';
|
|
7
|
+
export type RpcListType = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<SuiBlockchainName, string[]>;
|
|
7
8
|
export interface AdapterFactoryParams {
|
|
8
9
|
rpcList: RpcListType;
|
|
9
10
|
httpClient?: HttpClient;
|
|
10
11
|
tonParams?: TonAdapterConfig;
|
|
11
12
|
createLogger?: (label: string) => ICustomLogger;
|
|
12
13
|
clientParams?: ClientAdaptersFactoryParams;
|
|
14
|
+
stellarParams: StellarProviderUrl;
|
|
13
15
|
}
|
|
14
16
|
export interface ClientAdaptersFactoryParams {
|
|
15
17
|
envType: EnvType;
|