@cryptorubic/web3 1.1.0-alpha-stellar.25 → 1.1.0-alpha-stellar.27
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 +25 -14
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +1 -0
- package/src/lib/adapter/blockchain-adapter-factory.service.js +4 -3
- package/src/lib/adapter/models/create-factory-params.d.ts +2 -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) {
|
|
@@ -91,11 +95,18 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
91
95
|
async addTrustline(tokenAddress) {
|
|
92
96
|
try {
|
|
93
97
|
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
|
+
}
|
|
94
105
|
const { signedTxXdr } = await this.signer.wallet.signTransaction(tx, {
|
|
95
106
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
96
107
|
address: this.signer.walletAddress
|
|
97
108
|
});
|
|
98
|
-
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));
|
|
99
110
|
if (resp.status === 'ERROR') {
|
|
100
111
|
throw new Error('Failed to execute transaction', { cause: resp.errorResult });
|
|
101
112
|
}
|
|
@@ -107,7 +118,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
120
|
async encodeTrustline(tokenAddress, walletAddress) {
|
|
110
|
-
const account = await this.public.getAccount(walletAddress);
|
|
121
|
+
const account = await this.public.soroban.getAccount(walletAddress);
|
|
111
122
|
const tx = new stellar_sdk_1.TransactionBuilder(account, {
|
|
112
123
|
fee: stellar_sdk_1.BASE_FEE,
|
|
113
124
|
networkPassphrase: stellar_sdk_1.Networks.PUBLIC
|
|
@@ -140,7 +151,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
140
151
|
.addOperation(operation)
|
|
141
152
|
.setTimeout(30)
|
|
142
153
|
.build();
|
|
143
|
-
const resp = await this.public.simulateTransaction(tx);
|
|
154
|
+
const resp = await this.public.soroban.simulateTransaction(tx);
|
|
144
155
|
if ('error' in resp) {
|
|
145
156
|
throw new Error(resp.error);
|
|
146
157
|
}
|
|
@@ -149,7 +160,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
149
160
|
}
|
|
150
161
|
async simulateTransaction(config) {
|
|
151
162
|
try {
|
|
152
|
-
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));
|
|
153
164
|
if ('error' in resp) {
|
|
154
165
|
throw new Error(resp.error);
|
|
155
166
|
}
|
|
@@ -162,7 +173,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
162
173
|
}
|
|
163
174
|
async getTransactionStatus(srcTxHash) {
|
|
164
175
|
try {
|
|
165
|
-
const resp = await this.public.pollTransaction(srcTxHash);
|
|
176
|
+
const resp = await this.public.soroban.pollTransaction(srcTxHash);
|
|
166
177
|
if (resp.status === 'SUCCESS') {
|
|
167
178
|
return tx_status_1.TX_STATUS.SUCCESS;
|
|
168
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) {
|
|
@@ -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,9 +1,9 @@
|
|
|
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
|
-
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[]>;
|
|
7
7
|
export interface AdapterFactoryParams {
|
|
8
8
|
rpcList: RpcListType;
|
|
9
9
|
httpClient?: HttpClient;
|