@cryptorubic/web3 1.1.0-alpha-stellar.39 → 1.1.0-alpha-stellar.41
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
|
@@ -3,6 +3,7 @@ import { AbstractAdapter } from '../common/abstract-adapter';
|
|
|
3
3
|
import { StellarClient } from './models/stellar-client';
|
|
4
4
|
import { StellarWallet } from './models/stellar-wallet';
|
|
5
5
|
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
6
|
+
import { Horizon } from '@stellar/stellar-sdk';
|
|
6
7
|
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
7
8
|
import { StellarAdapterSigner } from './signer/stellar-adapter-signer';
|
|
8
9
|
import BigNumber from 'bignumber.js';
|
|
@@ -15,7 +16,7 @@ import { StellarRpcProvider } from './models/stellar-rpc-provider';
|
|
|
15
16
|
export declare class StellarAdapter extends AbstractAdapter<StellarClient, StellarWallet, StellarBlockchainName> {
|
|
16
17
|
private readonly rpc;
|
|
17
18
|
readonly signer: StellarAdapterSigner;
|
|
18
|
-
|
|
19
|
+
readonly horizonClient: Horizon.Server;
|
|
19
20
|
private readonly CLASSIC_TOKEN_DECIMALS;
|
|
20
21
|
constructor(rpc: StellarRpcProvider[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
21
22
|
initWeb3Client(): void;
|
|
@@ -70,30 +70,33 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
70
70
|
if (web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.STELLAR, tokenAddress)) {
|
|
71
71
|
return core_1.nativeTokensList[core_1.BLOCKCHAIN_NAME.STELLAR];
|
|
72
72
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.
|
|
81
|
-
.
|
|
82
|
-
.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
73
|
+
const [code, issuer] = tokenAddress.toUpperCase().split('-');
|
|
74
|
+
try {
|
|
75
|
+
const fetchedTokens = await this.horizonClient.assets().forIssuer(issuer).limit(50).call();
|
|
76
|
+
const fetchedToken = fetchedTokens.records.find((fetchedToken) => (0, core_1.compareAddresses)(fetchedToken.asset_code, code) &&
|
|
77
|
+
(0, core_1.compareAddresses)(fetchedToken.asset_issuer, issuer) &&
|
|
78
|
+
parseFloat(fetchedToken.balances.authorized) > 0);
|
|
79
|
+
if (fetchedToken && 'toml' in fetchedToken._links) {
|
|
80
|
+
const { href } = fetchedToken._links.toml;
|
|
81
|
+
const tomlTokens = await stellar_sdk_1.StellarToml.Resolver.resolve(new URL(href).hostname, { allowHttp: true });
|
|
82
|
+
if (tomlTokens.CURRENCIES) {
|
|
83
|
+
const tomlToken = tomlTokens.CURRENCIES.find((currency) => (0, core_1.compareAddresses)(fetchedToken.asset_code, currency.code) &&
|
|
84
|
+
(0, core_1.compareAddresses)(fetchedToken.asset_issuer, currency.issuer));
|
|
85
|
+
return new core_1.Token({
|
|
86
|
+
name: tomlToken.name || tomlToken.code,
|
|
87
|
+
symbol: tomlToken.code,
|
|
88
|
+
decimals: tomlToken.display_decimals || this.CLASSIC_TOKEN_DECIMALS,
|
|
89
|
+
blockchain: core_1.BLOCKCHAIN_NAME.STELLAR,
|
|
90
|
+
address: `${tomlToken.code}-${tomlToken.issuer}`
|
|
91
|
+
});
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
decimals,
|
|
94
|
-
name,
|
|
95
|
-
symbol
|
|
96
|
-
});
|
|
94
|
+
throw new Error('Token not found');
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
console.error(err);
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
97
100
|
}
|
|
98
101
|
async checkEnoughBalance(token, walletAddress) {
|
|
99
102
|
const userBalance = await this.getBalance(walletAddress, token.address);
|
|
@@ -121,7 +124,7 @@ class StellarAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
|
121
124
|
const { hash } = await this.public.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
122
125
|
const resp = await this.public.pollTransaction(hash);
|
|
123
126
|
if (resp.status === 'FAILED') {
|
|
124
|
-
throw new Error('Failed to execute transaction', { cause: resp.resultXdr });
|
|
127
|
+
throw new Error('Failed to execute transaction', { cause: resp.resultXdr.result() });
|
|
125
128
|
}
|
|
126
129
|
return resp.txHash;
|
|
127
130
|
}
|