@cryptorubic/web3 1.7.0-alpha-xrpl-adapter.4 → 1.7.0-alpha.clearswap.2
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 +2 -6
- package/src/index.d.ts +1 -6
- package/src/index.js +1 -6
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.js +26 -0
- package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.d.ts +1 -1
- package/src/lib/adapter/adapters/models/transfer-tx-params.d.ts +13 -0
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +1 -3
- package/src/lib/adapter/blockchain-adapter-factory.service.js +0 -4
- package/src/lib/adapter/constants/models/solana-web3.d.ts +1 -1
- package/src/lib/adapter/constants/models/wallet-provider.d.ts +0 -6
- package/src/lib/adapter/models/create-factory-params.d.ts +2 -2
- package/src/lib/utils/constants/web3-pure-store.js +5 -2
- package/src/lib/adapter/adapters/adapter-ripple/constants/fake-ripple-wallet.d.ts +0 -1
- package/src/lib/adapter/adapters/adapter-ripple/constants/fake-ripple-wallet.js +0 -4
- package/src/lib/adapter/adapters/adapter-ripple/models/ripple-client.d.ts +0 -2
- package/src/lib/adapter/adapters/adapter-ripple/models/ripple-send-tx-params.d.ts +0 -7
- package/src/lib/adapter/adapters/adapter-ripple/models/ripple-send-tx-params.js +0 -2
- package/src/lib/adapter/adapters/adapter-ripple/models/ripple-wallet.d.ts +0 -25
- package/src/lib/adapter/adapters/adapter-ripple/models/ripple-wallet.js +0 -2
- package/src/lib/adapter/adapters/adapter-ripple/ripple-adapter.d.ts +0 -44
- package/src/lib/adapter/adapters/adapter-ripple/ripple-adapter.js +0 -254
- package/src/lib/adapter/adapters/adapter-ripple/signer/ripple-adapter-signer.d.ts +0 -18
- package/src/lib/adapter/adapters/adapter-ripple/signer/ripple-adapter-signer.js +0 -72
- package/src/lib/adapter/adapters/adapter-ripple/utils/parse-ripple-token-address.d.ts +0 -6
- package/src/lib/adapter/adapters/adapter-ripple/utils/parse-ripple-token-address.js +0 -32
- package/src/lib/adapter/adapters/adapter-ripple/utils/ripple-reserve.d.ts +0 -7
- package/src/lib/adapter/adapters/adapter-ripple/utils/ripple-reserve.js +0 -12
- package/src/lib/adapter/adapters/adapter-tron/models/tron-transfer-tx-params.d.ts +0 -7
- package/src/lib/adapter/adapters/adapter-tron/models/tron-transfer-tx-params.js +0 -2
- package/src/lib/utils/web3-types/ripple-web3-pure.d.ts +0 -5
- package/src/lib/utils/web3-types/ripple-web3-pure.js +0 -27
- /package/src/lib/adapter/adapters/{adapter-ripple/models/ripple-client.js → models/transfer-tx-params.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cryptorubic/web3",
|
|
3
|
-
"version": "1.7.0-alpha
|
|
3
|
+
"version": "1.7.0-alpha.clearswap.2",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@ethersproject/bignumber": "^5.8.0",
|
|
6
6
|
"@mysten/sui": "^1.24.0",
|
|
@@ -21,13 +21,9 @@
|
|
|
21
21
|
"js-base64": "^3.7.8",
|
|
22
22
|
"tronweb": "^6.0.0-beta.4",
|
|
23
23
|
"tslib": "*",
|
|
24
|
-
"viem": "^2.33.1"
|
|
25
|
-
"xrpl": "^4.3.0"
|
|
24
|
+
"viem": "^2.33.1"
|
|
26
25
|
},
|
|
27
26
|
"peerDependencies": {},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"xumm": "^1.8.0"
|
|
30
|
-
},
|
|
31
27
|
"type": "commonjs",
|
|
32
28
|
"main": "./src/index.js",
|
|
33
29
|
"typings": "./src/index.d.ts",
|
package/src/index.d.ts
CHANGED
|
@@ -24,10 +24,6 @@ export * from './lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer';
|
|
|
24
24
|
export * from './lib/adapter/adapters/adapter-tron/models/tron-send-tx-params';
|
|
25
25
|
export * from './lib/adapter/adapters/adapter-tron/tron-adapter';
|
|
26
26
|
export * from './lib/adapter/adapters/adapter-tron/utils/parse-tron-error';
|
|
27
|
-
export * from './lib/adapter/adapters/adapter-ripple/ripple-adapter';
|
|
28
|
-
export * from './lib/adapter/adapters/adapter-ripple/signer/ripple-adapter-signer';
|
|
29
|
-
export * from './lib/adapter/adapters/adapter-ripple/models/ripple-wallet';
|
|
30
|
-
export * from './lib/adapter/adapters/adapter-ripple/models/ripple-send-tx-params';
|
|
31
27
|
export * from './lib/adapter/adapters/common/abstract-adapter';
|
|
32
28
|
export * from './lib/adapter/adapters/common/signer/abstract-adapter-signer';
|
|
33
29
|
export * from './lib/adapter/adapters/constants/erc20-token-abi';
|
|
@@ -146,8 +142,7 @@ export * from './lib/utils/web3-types/near-web3-pure';
|
|
|
146
142
|
export * from './lib/utils/web3-types/solana-web3-pure';
|
|
147
143
|
export * from './lib/utils/web3-types/sui-web3-pure';
|
|
148
144
|
export * from './lib/utils/web3-types/ton-web3-pure';
|
|
149
|
-
export * from './lib/utils/web3-types/
|
|
150
|
-
export * from './lib/utils/web3-types/ripple-web3-pure';
|
|
145
|
+
export * from './lib/utils/web3-types/tron-web3-pure';
|
|
151
146
|
export * from './lib/utils/models/primitive-types';
|
|
152
147
|
export * from './lib/utils/models/tron-transaction-info';
|
|
153
148
|
export * from './lib/utils/models/tron-transaction-config';
|
package/src/index.js
CHANGED
|
@@ -27,10 +27,6 @@ tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-tron/signer/tron-ad
|
|
|
27
27
|
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-tron/models/tron-send-tx-params"), exports);
|
|
28
28
|
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-tron/tron-adapter"), exports);
|
|
29
29
|
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-tron/utils/parse-tron-error"), exports);
|
|
30
|
-
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-ripple/ripple-adapter"), exports);
|
|
31
|
-
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-ripple/signer/ripple-adapter-signer"), exports);
|
|
32
|
-
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-ripple/models/ripple-wallet"), exports);
|
|
33
|
-
tslib_1.__exportStar(require("./lib/adapter/adapters/adapter-ripple/models/ripple-send-tx-params"), exports);
|
|
34
30
|
tslib_1.__exportStar(require("./lib/adapter/adapters/common/abstract-adapter"), exports);
|
|
35
31
|
tslib_1.__exportStar(require("./lib/adapter/adapters/common/signer/abstract-adapter-signer"), exports);
|
|
36
32
|
tslib_1.__exportStar(require("./lib/adapter/adapters/constants/erc20-token-abi"), exports);
|
|
@@ -149,8 +145,7 @@ tslib_1.__exportStar(require("./lib/utils/web3-types/near-web3-pure"), exports);
|
|
|
149
145
|
tslib_1.__exportStar(require("./lib/utils/web3-types/solana-web3-pure"), exports);
|
|
150
146
|
tslib_1.__exportStar(require("./lib/utils/web3-types/sui-web3-pure"), exports);
|
|
151
147
|
tslib_1.__exportStar(require("./lib/utils/web3-types/ton-web3-pure"), exports);
|
|
152
|
-
tslib_1.__exportStar(require("./lib/utils/web3-types/
|
|
153
|
-
tslib_1.__exportStar(require("./lib/utils/web3-types/ripple-web3-pure"), exports);
|
|
148
|
+
tslib_1.__exportStar(require("./lib/utils/web3-types/tron-web3-pure"), exports);
|
|
154
149
|
tslib_1.__exportStar(require("./lib/utils/models/primitive-types"), exports);
|
|
155
150
|
tslib_1.__exportStar(require("./lib/utils/models/tron-transaction-info"), exports);
|
|
156
151
|
tslib_1.__exportStar(require("./lib/utils/models/tron-transaction-config"), exports);
|
|
@@ -4,6 +4,7 @@ import { ClientAdaptersFactoryParams } from '../../../models/create-factory-para
|
|
|
4
4
|
import { SolanaSendTxParams } from '../models/solana-send-tx-params';
|
|
5
5
|
import { Connection } from '@solana/web3.js';
|
|
6
6
|
import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
|
|
7
|
+
import { SolanaTransferTxParams } from '../../models/transfer-tx-params';
|
|
7
8
|
export declare class SolanaAdapterSigner extends AbstractAdapterSigner<SolanaWeb3, SolanaSendTxParams, string> {
|
|
8
9
|
private readonly publicRef;
|
|
9
10
|
get publicClient(): Connection;
|
|
@@ -13,5 +14,6 @@ export declare class SolanaAdapterSigner extends AbstractAdapterSigner<SolanaWeb
|
|
|
13
14
|
write<T>(): Promise<T>;
|
|
14
15
|
getBlockchainName(): Promise<BlockchainName>;
|
|
15
16
|
sendTransaction(params: SolanaSendTxParams): Promise<string>;
|
|
17
|
+
transfer(params: SolanaTransferTxParams): Promise<string>;
|
|
16
18
|
private waitForTxConfirmation;
|
|
17
19
|
}
|
|
@@ -9,6 +9,7 @@ const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.e
|
|
|
9
9
|
const errors_1 = require("../../utils/errors");
|
|
10
10
|
const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
|
|
11
11
|
const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
|
|
12
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
12
13
|
class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
|
|
13
14
|
get publicClient() {
|
|
14
15
|
if (!this.publicRef.public) {
|
|
@@ -70,6 +71,31 @@ class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigne
|
|
|
70
71
|
throw (0, errors_1.parseError)(err);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
74
|
+
async transfer(params) {
|
|
75
|
+
const tokenPK = new web3_js_1.PublicKey(params.tokenAddress);
|
|
76
|
+
const senderPK = new web3_js_1.PublicKey(this.walletAddress);
|
|
77
|
+
const receiverPK = new web3_js_1.PublicKey(params.receiver);
|
|
78
|
+
const senderATA = await (0, spl_token_1.getAssociatedTokenAddress)(tokenPK, senderPK, true);
|
|
79
|
+
const receiverATA = await (0, spl_token_1.getAssociatedTokenAddress)(tokenPK, receiverPK, true);
|
|
80
|
+
const receiverAtaInfo = await this.publicClient.getAccountInfo(receiverATA).catch(() => null);
|
|
81
|
+
const instructions = [];
|
|
82
|
+
if (!receiverAtaInfo) {
|
|
83
|
+
instructions.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(senderPK, // payer
|
|
84
|
+
receiverATA, // ATA address
|
|
85
|
+
receiverPK, // owner
|
|
86
|
+
tokenPK // mint
|
|
87
|
+
));
|
|
88
|
+
}
|
|
89
|
+
instructions.push((0, spl_token_1.createTransferInstruction)(senderATA, receiverATA, senderPK, BigInt(params.tokenWeiAmount), [], spl_token_1.TOKEN_PROGRAM_ID));
|
|
90
|
+
const transaction = new web3_js_1.Transaction().add(...instructions);
|
|
91
|
+
const signedTx = await this.wallet.signTransaction(transaction);
|
|
92
|
+
signedTx.feePayer = new web3_js_1.PublicKey(this.walletAddress);
|
|
93
|
+
signedTx.recentBlockhash = (await this.publicClient.getLatestBlockhash()).blockhash;
|
|
94
|
+
const signature = await this.publicClient.sendRawTransaction(signedTx.serialize(), { maxRetries: 3, skipPreflight: false });
|
|
95
|
+
params.txOptions.onTransactionHash?.(signature);
|
|
96
|
+
await this.waitForTxConfirmation(signature);
|
|
97
|
+
return signature;
|
|
98
|
+
}
|
|
73
99
|
async waitForTxConfirmation(signature) {
|
|
74
100
|
const deadline = Date.now() + 3 * 60 * 1000;
|
|
75
101
|
let fetchedTx = null;
|
|
@@ -4,7 +4,7 @@ import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
|
4
4
|
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
5
5
|
import { TronSendTxParams } from '../models/tron-send-tx-params';
|
|
6
6
|
import { TronParameters } from '../../../../utils/models/tron-parameters';
|
|
7
|
-
import { TronTransferTxParams } from '
|
|
7
|
+
import { TronTransferTxParams } from '../../models/transfer-tx-params';
|
|
8
8
|
export declare class TronAdapterSigner extends AbstractAdapterSigner<TronWeb, TronSendTxParams, string> {
|
|
9
9
|
private readonly publicRef;
|
|
10
10
|
get publicClient(): TronWeb;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SolanaTransactionOptions } from '../adapter-solana/models/solana-send-tx-params';
|
|
2
|
+
import { TronTransactionOptions } from '../adapter-tron/models/tron-send-tx-params';
|
|
3
|
+
export interface TransferTxParams {
|
|
4
|
+
receiver: string;
|
|
5
|
+
tokenWeiAmount: string;
|
|
6
|
+
tokenAddress: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TronTransferTxParams extends TransferTxParams {
|
|
9
|
+
txOptions: TronTransactionOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface SolanaTransferTxParams extends TransferTxParams {
|
|
12
|
+
txOptions: SolanaTransactionOptions;
|
|
13
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractAdapter } from './adapters/common/abstract-adapter';
|
|
2
2
|
import { WalletProviderCore } from './constants/models/wallet-provider';
|
|
3
|
-
import { BlockchainName, EvmBlockchainName, SolanaBlockchainName, TronBlockchainName, ICustomLogger, TonBlockchainName, BitcoinBlockchainName, SuiBlockchainName, StellarBlockchainName
|
|
3
|
+
import { BlockchainName, EvmBlockchainName, SolanaBlockchainName, TronBlockchainName, ICustomLogger, TonBlockchainName, BitcoinBlockchainName, SuiBlockchainName, StellarBlockchainName } from '@cryptorubic/core';
|
|
4
4
|
import { TonAdapter } from './adapters/adapter-ton/ton-adapter';
|
|
5
5
|
import { EvmAdapter } from './adapters/adapter-evm/evm-adapter';
|
|
6
6
|
import { BitcoinAdapter } from './adapters/adapter-bitcoin/bitcoin-adapter';
|
|
@@ -9,7 +9,6 @@ import { TronAdapter } from './adapters/adapter-tron/tron-adapter';
|
|
|
9
9
|
import { SuiAdapter } from './adapters/adapter-sui/sui-adapter';
|
|
10
10
|
import { AdapterFactoryParams } from './models/create-factory-params';
|
|
11
11
|
import { StellarAdapter } from './adapters/adapter-stellar/stellar-adapter';
|
|
12
|
-
import { RippleAdapter } from './adapters/adapter-ripple/ripple-adapter';
|
|
13
12
|
export declare class BlockchainAdapterFactoryService {
|
|
14
13
|
private readonly rpcList;
|
|
15
14
|
private readonly httpClient;
|
|
@@ -28,7 +27,6 @@ export declare class BlockchainAdapterFactoryService {
|
|
|
28
27
|
getAdapter(blockchain: BitcoinBlockchainName): BitcoinAdapter;
|
|
29
28
|
getAdapter(blockchain: SuiBlockchainName): SuiAdapter;
|
|
30
29
|
getAdapter(blockchain: StellarBlockchainName): StellarAdapter;
|
|
31
|
-
getAdapter(blockchain: RippleBlockchainName): RippleAdapter;
|
|
32
30
|
private createStorage;
|
|
33
31
|
private createAdapter;
|
|
34
32
|
connectWallet(blockchain: BlockchainName, wallet: WalletProviderCore): void;
|
|
@@ -10,7 +10,6 @@ const solana_adapter_1 = require("./adapters/adapter-solana/solana-adapter");
|
|
|
10
10
|
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
|
-
const ripple_adapter_1 = require("./adapters/adapter-ripple/ripple-adapter");
|
|
14
13
|
class BlockchainAdapterFactoryService {
|
|
15
14
|
constructor(rpcList, httpClient, createLogger, tonParams, clientParams) {
|
|
16
15
|
this.rpcList = rpcList;
|
|
@@ -85,9 +84,6 @@ class BlockchainAdapterFactoryService {
|
|
|
85
84
|
if (blockchain === core_1.BLOCKCHAIN_NAME.STELLAR) {
|
|
86
85
|
return new stellar_adapter_1.StellarAdapter(rpcs, this.httpClient, this.logger, this.clientParams);
|
|
87
86
|
}
|
|
88
|
-
if (blockchain === core_1.BLOCKCHAIN_NAME.RIPPLE) {
|
|
89
|
-
return new ripple_adapter_1.RippleAdapter(rpcs, this.httpClient, this.logger, this.clientParams);
|
|
90
|
-
}
|
|
91
87
|
}
|
|
92
88
|
if (blockchain === core_1.BLOCKCHAIN_NAME.TON && this.tonParams?.tonApiConfig && this.tonParams?.tonClientConfig) {
|
|
93
89
|
return new ton_adapter_1.TonAdapter(this.httpClient, this.tonParams, this.createLogger?.(`TON_ADAPTER`), this.clientParams);
|
|
@@ -4,7 +4,7 @@ export interface SolanaWeb3 {
|
|
|
4
4
|
toBytes(): Uint8Array;
|
|
5
5
|
};
|
|
6
6
|
isConnected: boolean;
|
|
7
|
-
signTransaction
|
|
7
|
+
signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
|
|
8
8
|
signAllTransactions(transactions: Transaction[]): Promise<Transaction[]>;
|
|
9
9
|
signMessage(message: Uint8Array, encoding: string): Promise<{
|
|
10
10
|
signature: Uint8Array;
|
|
@@ -3,8 +3,6 @@ import { SolanaWeb3 } from './solana-web3';
|
|
|
3
3
|
import { TronWeb } from 'tronweb';
|
|
4
4
|
import { BtcWallet } from '../../adapters/models/btc-wallet-provider';
|
|
5
5
|
import { WalletAdapter } from '@suiet/wallet-sdk';
|
|
6
|
-
import { RippleWallet } from '../../adapters/adapter-ripple/models/ripple-wallet';
|
|
7
|
-
import { StellarWallet } from '../../adapters/adapter-stellar/models/stellar-wallet';
|
|
8
6
|
export interface WalletProviderCore<T = any> {
|
|
9
7
|
/**
|
|
10
8
|
* Core provider.
|
|
@@ -23,8 +21,6 @@ export type SolanaWalletProviderCore = WalletProviderCore<SolanaWeb3>;
|
|
|
23
21
|
export type TonWaleltProviderCore = WalletProviderCore<unknown>;
|
|
24
22
|
export type BitcoinWalletProviderCore = WalletProviderCore<BtcWallet>;
|
|
25
23
|
export type SuiWalletProviderCore = WalletProviderCore<WalletAdapter>;
|
|
26
|
-
export type RippleWalletProviderCore = WalletProviderCore<RippleWallet>;
|
|
27
|
-
export type StellarWalletProviderCore = WalletProviderCore<StellarWallet>;
|
|
28
24
|
/**
|
|
29
25
|
* Stores wallet core and information about current user, used to make `send` transactions.
|
|
30
26
|
*/
|
|
@@ -35,8 +31,6 @@ interface IWalletProvider {
|
|
|
35
31
|
readonly [CHAIN_TYPE.TON]?: TonWaleltProviderCore;
|
|
36
32
|
readonly [CHAIN_TYPE.BITCOIN]?: BitcoinWalletProviderCore;
|
|
37
33
|
readonly [CHAIN_TYPE.SUI]?: SuiWalletProviderCore;
|
|
38
|
-
readonly [CHAIN_TYPE.RIPPLE]?: RippleWalletProviderCore;
|
|
39
|
-
readonly [CHAIN_TYPE.STELLAR]?: StellarWalletProviderCore;
|
|
40
34
|
}
|
|
41
35
|
export type WalletProvider = Partial<IWalletProvider>;
|
|
42
36
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { EvmBlockchainName, HttpClient, ICustomLogger, SolanaBlockchainName, StellarBlockchainName,
|
|
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
6
|
import { StellarRpcProvider } from '../adapters/adapter-stellar/models/stellar-rpc-provider';
|
|
7
|
-
export type RpcListType = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<SuiBlockchainName, string[]> & Record<StellarBlockchainName, StellarRpcProvider[]
|
|
7
|
+
export type RpcListType = Record<EvmBlockchainName, string[]> & Record<TronBlockchainName, TronWebProvider[]> & Record<SolanaBlockchainName, string[]> & Record<SuiBlockchainName, string[]> & Record<StellarBlockchainName, StellarRpcProvider[]>;
|
|
8
8
|
export interface AdapterFactoryParams {
|
|
9
9
|
rpcList: RpcListType;
|
|
10
10
|
httpClient?: HttpClient;
|
|
@@ -14,7 +14,6 @@ const tron_web3_pure_1 = require("../web3-types/tron-web3-pure");
|
|
|
14
14
|
const changenow_api_blockchain_1 = require("./changenow-api-blockchain");
|
|
15
15
|
const zcash_web3_pure_1 = require("../web3-types/zcash-web3-pure");
|
|
16
16
|
const stellar_web3_pure_1 = require("../web3-types/stellar-web3-pure");
|
|
17
|
-
const ripple_web3_pure_1 = require("../web3-types/ripple-web3-pure");
|
|
18
17
|
exports.web3PureStore = {
|
|
19
18
|
[core_1.CHAIN_TYPE.EVM]: new evm_web3_pure_1.EvmWeb3Pure(),
|
|
20
19
|
[core_1.CHAIN_TYPE.SUI]: new sui_web3_pure_1.SuiWeb3Pure(),
|
|
@@ -28,7 +27,11 @@ exports.web3PureStore = {
|
|
|
28
27
|
[core_1.CHAIN_TYPE.NEAR]: new near_web3_pure_1.NearWeb3Pure(),
|
|
29
28
|
[core_1.CHAIN_TYPE.ZCASH]: new zcash_web3_pure_1.ZcashWeb3Pure(),
|
|
30
29
|
[core_1.CHAIN_TYPE.STELLAR]: new stellar_web3_pure_1.StellarWeb3Pure(),
|
|
31
|
-
|
|
30
|
+
// Common Web3
|
|
31
|
+
[core_1.CHAIN_TYPE.RIPPLE]: new common_web3_pure_1.CommonWeb3Pure({
|
|
32
|
+
cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.RIPPLE,
|
|
33
|
+
regex: /^r[1-9A-HJ-NP-Za-km-z]{25,34}$/
|
|
34
|
+
}),
|
|
32
35
|
[core_1.CHAIN_TYPE.CARDANO]: new common_web3_pure_1.CommonWeb3Pure({
|
|
33
36
|
/*
|
|
34
37
|
* cnApi returns invalid info
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const FAKE_RIPPLE_WALLET = "rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
|
|
2
|
-
export interface RippleSendTxParams {
|
|
3
|
-
txOptions: RippleTransactionOptions;
|
|
4
|
-
}
|
|
5
|
-
export interface RippleTransactionOptions extends BasicSendTransactionOptions {
|
|
6
|
-
transaction: string | Record<string, unknown>;
|
|
7
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface RippleWallet {
|
|
2
|
-
payload: {
|
|
3
|
-
createAndSubscribe: (txjson: Record<string, unknown>, onEvent: (event: {
|
|
4
|
-
data: Record<string, unknown>;
|
|
5
|
-
}) => void) => Promise<{
|
|
6
|
-
created: {
|
|
7
|
-
refs: {
|
|
8
|
-
qr_png?: string;
|
|
9
|
-
};
|
|
10
|
-
next: {
|
|
11
|
-
always: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
resolved: Promise<{
|
|
15
|
-
signed: boolean;
|
|
16
|
-
txid?: string;
|
|
17
|
-
txhash?: string;
|
|
18
|
-
}>;
|
|
19
|
-
}>;
|
|
20
|
-
};
|
|
21
|
-
user: {
|
|
22
|
-
account: Promise<string | undefined>;
|
|
23
|
-
networkType: Promise<string | undefined>;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { BlockchainName, HttpClient, ICustomLogger, PriceTokenAmount, RippleBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
2
|
-
import { TrustSet } from 'xrpl';
|
|
3
|
-
import BigNumber from 'bignumber.js';
|
|
4
|
-
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
5
|
-
import { RippleClient } from './models/ripple-client';
|
|
6
|
-
import { RippleWallet } from './models/ripple-wallet';
|
|
7
|
-
import { RippleSendTxParams } from './models/ripple-send-tx-params';
|
|
8
|
-
import { RippleAdapterSigner } from './signer/ripple-adapter-signer';
|
|
9
|
-
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
10
|
-
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
11
|
-
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
12
|
-
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
13
|
-
export declare class RippleAdapter extends AbstractAdapter<RippleClient, RippleWallet, RippleBlockchainName, RippleSendTxParams, string> {
|
|
14
|
-
private readonly rpc;
|
|
15
|
-
readonly signer: RippleAdapterSigner;
|
|
16
|
-
private connectPromise;
|
|
17
|
-
private networkReserves;
|
|
18
|
-
private networkReservesPromise;
|
|
19
|
-
constructor(rpc: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
20
|
-
initWeb3Client(): void;
|
|
21
|
-
getBlockNumber(): Promise<number | {
|
|
22
|
-
blockNumber: number;
|
|
23
|
-
workchain: number;
|
|
24
|
-
}>;
|
|
25
|
-
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
26
|
-
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
27
|
-
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
28
|
-
callForTokenInfo(tokenAddress: string): Promise<Token<BlockchainName>>;
|
|
29
|
-
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
30
|
-
needTrustline(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
31
|
-
addTrustline(tokenAddress: string): Promise<string>;
|
|
32
|
-
encodeTrustline(tokenAddress: string, walletAddress: string): Promise<TrustSet>;
|
|
33
|
-
getMinWeiBalance(userAddress: string): Promise<BigNumber>;
|
|
34
|
-
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
35
|
-
read<T>(): Promise<T>;
|
|
36
|
-
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
37
|
-
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
38
|
-
private getNetworkReserves;
|
|
39
|
-
private fetchNetworkReserves;
|
|
40
|
-
private ensureConnected;
|
|
41
|
-
private fetchAccountLines;
|
|
42
|
-
private findAccountLine;
|
|
43
|
-
private decodeHexCurrency;
|
|
44
|
-
}
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RippleAdapter = void 0;
|
|
4
|
-
const core_1 = require("@cryptorubic/core");
|
|
5
|
-
const xrpl_1 = require("xrpl");
|
|
6
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
7
|
-
const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
8
|
-
const ripple_adapter_signer_1 = require("./signer/ripple-adapter-signer");
|
|
9
|
-
const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
10
|
-
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
11
|
-
const parse_ripple_token_address_1 = require("./utils/parse-ripple-token-address");
|
|
12
|
-
const ripple_reserve_1 = require("./utils/ripple-reserve");
|
|
13
|
-
const IOU_DECIMALS = 15;
|
|
14
|
-
class RippleAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
15
|
-
constructor(rpc, httpClient, logger, clientParams) {
|
|
16
|
-
super(core_1.BLOCKCHAIN_NAME.RIPPLE, logger);
|
|
17
|
-
this.rpc = rpc;
|
|
18
|
-
this.connectPromise = null;
|
|
19
|
-
this.networkReserves = null;
|
|
20
|
-
this.networkReservesPromise = null;
|
|
21
|
-
this.signer = new ripple_adapter_signer_1.RippleAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
22
|
-
}
|
|
23
|
-
initWeb3Client() {
|
|
24
|
-
const client = new xrpl_1.Client(this.rpc[0], { timeout: 5000 });
|
|
25
|
-
this.public = client;
|
|
26
|
-
this.connectPromise = client.connect().catch((err) => {
|
|
27
|
-
this.connectPromise = null;
|
|
28
|
-
throw err;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
async getBlockNumber() {
|
|
32
|
-
await this.ensureConnected();
|
|
33
|
-
const response = await this.public.request({ command: 'ledger_current' });
|
|
34
|
-
return response.result.ledger_current_index;
|
|
35
|
-
}
|
|
36
|
-
async getTokensBalances(userAddress, tokensAddresses) {
|
|
37
|
-
try {
|
|
38
|
-
await this.ensureConnected();
|
|
39
|
-
const needsNative = tokensAddresses.some((tokenAddress) => web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.RIPPLE, tokenAddress));
|
|
40
|
-
const needsIou = tokensAddresses.some((tokenAddress) => !web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.RIPPLE, tokenAddress));
|
|
41
|
-
const [nativeBalance, lines] = await Promise.all([
|
|
42
|
-
needsNative ? this.getBalance(userAddress) : Promise.resolve(new bignumber_js_1.default(0)),
|
|
43
|
-
needsIou ? this.fetchAccountLines(userAddress) : Promise.resolve([])
|
|
44
|
-
]);
|
|
45
|
-
return tokensAddresses.map((tokenAddress) => {
|
|
46
|
-
if (web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.RIPPLE, tokenAddress)) {
|
|
47
|
-
return nativeBalance;
|
|
48
|
-
}
|
|
49
|
-
const { currency, issuer } = (0, parse_ripple_token_address_1.parseRippleTokenAddress)(tokenAddress);
|
|
50
|
-
const line = this.findAccountLine(lines, currency, issuer);
|
|
51
|
-
return new bignumber_js_1.default(core_1.Token.toWei(line?.balance || '0', IOU_DECIMALS));
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
this.logger?.customError('Failed to get tokens balances', err);
|
|
56
|
-
return tokensAddresses.map(() => new bignumber_js_1.default(0));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async getBalance(userAddress, tokenAddress) {
|
|
60
|
-
try {
|
|
61
|
-
await this.ensureConnected();
|
|
62
|
-
if (!tokenAddress || web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.RIPPLE, tokenAddress)) {
|
|
63
|
-
const [accountResponse, reserves] = await Promise.all([
|
|
64
|
-
this.public.request({
|
|
65
|
-
command: 'account_info',
|
|
66
|
-
account: userAddress,
|
|
67
|
-
ledger_index: 'validated'
|
|
68
|
-
}),
|
|
69
|
-
this.getNetworkReserves()
|
|
70
|
-
]);
|
|
71
|
-
const totalBalance = new bignumber_js_1.default(accountResponse.result.account_data.Balance);
|
|
72
|
-
const minReserve = (0, ripple_reserve_1.calculateMinReserveDrops)(reserves, accountResponse.result.account_data.OwnerCount);
|
|
73
|
-
return (0, ripple_reserve_1.calculateSpendableNativeBalance)(totalBalance, minReserve);
|
|
74
|
-
}
|
|
75
|
-
const { currency, issuer } = (0, parse_ripple_token_address_1.parseRippleTokenAddress)(tokenAddress);
|
|
76
|
-
const lines = await this.fetchAccountLines(userAddress, issuer);
|
|
77
|
-
const line = this.findAccountLine(lines, currency, issuer);
|
|
78
|
-
return new bignumber_js_1.default(core_1.Token.toWei(line?.balance || '0', IOU_DECIMALS));
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return new bignumber_js_1.default(0);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
async callForTokensInfo(tokenAddresses) {
|
|
85
|
-
return Promise.all(tokenAddresses.map((token) => this.callForTokenInfo(token)));
|
|
86
|
-
}
|
|
87
|
-
async callForTokenInfo(tokenAddress) {
|
|
88
|
-
if (web3_pure_1.Web3Pure.isNativeAddress(core_1.BLOCKCHAIN_NAME.RIPPLE, tokenAddress)) {
|
|
89
|
-
return core_1.nativeTokensList[core_1.BLOCKCHAIN_NAME.RIPPLE];
|
|
90
|
-
}
|
|
91
|
-
const { currency, issuer } = (0, parse_ripple_token_address_1.parseRippleTokenAddress)(tokenAddress);
|
|
92
|
-
const displayCurrency = currency.length === 40 ? this.decodeHexCurrency(currency) : currency;
|
|
93
|
-
return new core_1.Token({
|
|
94
|
-
blockchain: core_1.BLOCKCHAIN_NAME.RIPPLE,
|
|
95
|
-
address: (0, parse_ripple_token_address_1.formatRippleTokenAddress)(currency, issuer),
|
|
96
|
-
name: displayCurrency,
|
|
97
|
-
symbol: displayCurrency,
|
|
98
|
-
decimals: IOU_DECIMALS
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
async checkEnoughBalance(token, walletAddress) {
|
|
102
|
-
const userBalance = await this.getBalance(walletAddress, token.address);
|
|
103
|
-
return userBalance.gte(token.weiAmount);
|
|
104
|
-
}
|
|
105
|
-
async needTrustline(token, walletAddress) {
|
|
106
|
-
const isCorrectWalletAddress = await web3_pure_1.Web3Pure.isAddressCorrect(core_1.BLOCKCHAIN_NAME.RIPPLE, walletAddress);
|
|
107
|
-
if (token.isNative || !isCorrectWalletAddress) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
await this.ensureConnected();
|
|
112
|
-
const { currency, issuer } = (0, parse_ripple_token_address_1.parseRippleTokenAddress)(token.address);
|
|
113
|
-
const lines = await this.fetchAccountLines(walletAddress, issuer);
|
|
114
|
-
const line = this.findAccountLine(lines, currency, issuer);
|
|
115
|
-
if (!line) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
return new bignumber_js_1.default(core_1.Token.toWei(line.limit, IOU_DECIMALS)).lt(token.weiAmount);
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async addTrustline(tokenAddress) {
|
|
125
|
-
try {
|
|
126
|
-
const txjson = await this.encodeTrustline(tokenAddress, this.signer.walletAddress);
|
|
127
|
-
return await this.signer.sendTransaction({
|
|
128
|
-
txOptions: {
|
|
129
|
-
transaction: txjson
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
this.logger?.customError('FAILED TO ADD TRUSTLINE', err);
|
|
135
|
-
throw err;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async encodeTrustline(tokenAddress, walletAddress) {
|
|
139
|
-
await this.ensureConnected();
|
|
140
|
-
const { currency, issuer } = (0, parse_ripple_token_address_1.parseRippleTokenAddress)(tokenAddress);
|
|
141
|
-
const tx = {
|
|
142
|
-
TransactionType: 'TrustSet',
|
|
143
|
-
Account: walletAddress,
|
|
144
|
-
Flags: xrpl_1.TrustSetFlags.tfSetNoRipple,
|
|
145
|
-
LimitAmount: {
|
|
146
|
-
currency,
|
|
147
|
-
issuer,
|
|
148
|
-
value: '1000000000'
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return await this.public.autofill(tx);
|
|
152
|
-
}
|
|
153
|
-
async getMinWeiBalance(userAddress) {
|
|
154
|
-
try {
|
|
155
|
-
await this.ensureConnected();
|
|
156
|
-
const [accountResponse, reserves] = await Promise.all([
|
|
157
|
-
this.public.request({
|
|
158
|
-
command: 'account_info',
|
|
159
|
-
account: userAddress,
|
|
160
|
-
ledger_index: 'validated'
|
|
161
|
-
}),
|
|
162
|
-
this.getNetworkReserves()
|
|
163
|
-
]);
|
|
164
|
-
return (0, ripple_reserve_1.calculateMinReserveDrops)(reserves, accountResponse.result.account_data.OwnerCount);
|
|
165
|
-
}
|
|
166
|
-
catch {
|
|
167
|
-
return new bignumber_js_1.default(0);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async getTransactionStatus(srcTxHash) {
|
|
171
|
-
try {
|
|
172
|
-
await this.ensureConnected();
|
|
173
|
-
const response = await this.public.request({
|
|
174
|
-
command: 'tx',
|
|
175
|
-
transaction: srcTxHash
|
|
176
|
-
});
|
|
177
|
-
if (!response.result.validated) {
|
|
178
|
-
return tx_status_1.TX_STATUS.PENDING;
|
|
179
|
-
}
|
|
180
|
-
const meta = response.result.meta;
|
|
181
|
-
if (typeof meta === 'string' || !meta || !('TransactionResult' in meta)) {
|
|
182
|
-
return tx_status_1.TX_STATUS.PENDING;
|
|
183
|
-
}
|
|
184
|
-
if (meta.TransactionResult === 'tesSUCCESS') {
|
|
185
|
-
return tx_status_1.TX_STATUS.SUCCESS;
|
|
186
|
-
}
|
|
187
|
-
return tx_status_1.TX_STATUS.FAIL;
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
return tx_status_1.TX_STATUS.PENDING;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async read() {
|
|
194
|
-
throw new Error('Not supported');
|
|
195
|
-
}
|
|
196
|
-
async callContractMethod() {
|
|
197
|
-
throw new Error('Not supported');
|
|
198
|
-
}
|
|
199
|
-
multicallContractsMethods() {
|
|
200
|
-
throw new Error('Not supported');
|
|
201
|
-
}
|
|
202
|
-
async getNetworkReserves() {
|
|
203
|
-
if (this.networkReserves) {
|
|
204
|
-
return this.networkReserves;
|
|
205
|
-
}
|
|
206
|
-
if (!this.networkReservesPromise) {
|
|
207
|
-
this.networkReservesPromise = this.fetchNetworkReserves();
|
|
208
|
-
}
|
|
209
|
-
return this.networkReservesPromise;
|
|
210
|
-
}
|
|
211
|
-
async fetchNetworkReserves() {
|
|
212
|
-
await this.ensureConnected();
|
|
213
|
-
const response = await this.public.request({ command: 'server_state' });
|
|
214
|
-
const validatedLedger = response.result.state.validated_ledger;
|
|
215
|
-
if (!validatedLedger) {
|
|
216
|
-
throw new Error('Validated ledger is not available in server_state response');
|
|
217
|
-
}
|
|
218
|
-
this.networkReserves = {
|
|
219
|
-
baseReserveDrops: new bignumber_js_1.default(validatedLedger.reserve_base),
|
|
220
|
-
ownerReserveDrops: new bignumber_js_1.default(validatedLedger.reserve_inc)
|
|
221
|
-
};
|
|
222
|
-
return this.networkReserves;
|
|
223
|
-
}
|
|
224
|
-
async ensureConnected() {
|
|
225
|
-
if (this.connectPromise) {
|
|
226
|
-
await this.connectPromise;
|
|
227
|
-
}
|
|
228
|
-
if (!this.publicRef.public?.isConnected()) {
|
|
229
|
-
await this.publicRef.public?.connect();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
async fetchAccountLines(userAddress, peer) {
|
|
233
|
-
const response = await this.public.request({
|
|
234
|
-
command: 'account_lines',
|
|
235
|
-
account: userAddress,
|
|
236
|
-
...(peer ? { peer } : {}),
|
|
237
|
-
ledger_index: 'validated'
|
|
238
|
-
});
|
|
239
|
-
return (response.result.lines ?? []);
|
|
240
|
-
}
|
|
241
|
-
findAccountLine(lines, currency, issuer) {
|
|
242
|
-
return lines.find((line) => (0, core_1.compareAddresses)(line.currency, currency) && (0, core_1.compareAddresses)(line.account, issuer));
|
|
243
|
-
}
|
|
244
|
-
decodeHexCurrency(hexCurrency) {
|
|
245
|
-
try {
|
|
246
|
-
const decoded = Buffer.from(hexCurrency, 'hex').toString('utf8').replace(/\0/g, '').trim();
|
|
247
|
-
return decoded || hexCurrency;
|
|
248
|
-
}
|
|
249
|
-
catch {
|
|
250
|
-
return hexCurrency;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
exports.RippleAdapter = RippleAdapter;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
-
import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
|
|
3
|
-
import { RippleClient } from '../models/ripple-client';
|
|
4
|
-
import { RippleSendTxParams } from '../models/ripple-send-tx-params';
|
|
5
|
-
import { RippleWallet } from '../models/ripple-wallet';
|
|
6
|
-
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
7
|
-
export declare class RippleAdapterSigner extends AbstractAdapterSigner<RippleWallet, RippleSendTxParams, string> {
|
|
8
|
-
private readonly publicRef;
|
|
9
|
-
get publicClient(): RippleClient;
|
|
10
|
-
constructor(publicRef: {
|
|
11
|
-
public: RippleClient | null;
|
|
12
|
-
}, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
13
|
-
write<T>(): Promise<T>;
|
|
14
|
-
getBlockchainName(): Promise<BlockchainName>;
|
|
15
|
-
sendTransaction(params: RippleSendTxParams): Promise<string>;
|
|
16
|
-
private ensureConnected;
|
|
17
|
-
private parseTxError;
|
|
18
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RippleAdapterSigner = void 0;
|
|
4
|
-
const core_1 = require("@cryptorubic/core");
|
|
5
|
-
const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
|
|
6
|
-
const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
|
|
7
|
-
const insufficient_funds_gas_price_value_error_1 = require("../../../../errors/cross-chain/insufficient-funds-gas-price-value.error");
|
|
8
|
-
const INSUFFICIENT_FUNDS_RESULTS = new Set(['tecUNFUNDED_PAYMENT', 'tecINSUFFICIENT_RESERVE', 'tecINSUFFICIENT_FUNDS']);
|
|
9
|
-
class RippleAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
|
|
10
|
-
get publicClient() {
|
|
11
|
-
if (!this.publicRef.public) {
|
|
12
|
-
const msg = 'Trying to access undefined publicClient in RippleAdapterSigner';
|
|
13
|
-
this.logger?.customLog(msg);
|
|
14
|
-
throw new Error(msg);
|
|
15
|
-
}
|
|
16
|
-
return this.publicRef.public;
|
|
17
|
-
}
|
|
18
|
-
constructor(publicRef, httpClient, logger, clientParams) {
|
|
19
|
-
super(httpClient, logger, clientParams);
|
|
20
|
-
this.publicRef = publicRef;
|
|
21
|
-
}
|
|
22
|
-
async write() {
|
|
23
|
-
throw new Error('Method write is not supported');
|
|
24
|
-
}
|
|
25
|
-
getBlockchainName() {
|
|
26
|
-
return Promise.resolve(core_1.BLOCKCHAIN_NAME.RIPPLE);
|
|
27
|
-
}
|
|
28
|
-
async sendTransaction(params) {
|
|
29
|
-
try {
|
|
30
|
-
await this.ensureConnected();
|
|
31
|
-
const txjson = typeof params.txOptions.transaction === 'string'
|
|
32
|
-
? JSON.parse(params.txOptions.transaction)
|
|
33
|
-
: params.txOptions.transaction;
|
|
34
|
-
const { resolved } = await this.wallet.payload.createAndSubscribe(txjson, () => { });
|
|
35
|
-
const result = await resolved;
|
|
36
|
-
if (!result.signed) {
|
|
37
|
-
throw new user_reject_error_1.UserRejectError();
|
|
38
|
-
}
|
|
39
|
-
const hash = result.txid ?? result.txhash;
|
|
40
|
-
if (!hash) {
|
|
41
|
-
throw new Error('Transaction signed but no hash returned from wallet');
|
|
42
|
-
}
|
|
43
|
-
params.txOptions.onTransactionHash?.(hash);
|
|
44
|
-
return hash;
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
this.parseTxError(err);
|
|
48
|
-
this.logger?.customError('Send transaction error', err);
|
|
49
|
-
throw err;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async ensureConnected() {
|
|
53
|
-
if (!this.publicRef.public) {
|
|
54
|
-
throw new Error('Ripple public client is not initialized');
|
|
55
|
-
}
|
|
56
|
-
if (!this.publicRef.public.isConnected()) {
|
|
57
|
-
await this.publicRef.public.connect();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
parseTxError(err) {
|
|
61
|
-
const message = err?.message ?? String(err);
|
|
62
|
-
if (INSUFFICIENT_FUNDS_RESULTS.has(message)) {
|
|
63
|
-
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
64
|
-
}
|
|
65
|
-
for (const code of INSUFFICIENT_FUNDS_RESULTS) {
|
|
66
|
-
if (message.includes(code)) {
|
|
67
|
-
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.RippleAdapterSigner = RippleAdapterSigner;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export interface ParsedRippleTokenAddress {
|
|
2
|
-
currency: string;
|
|
3
|
-
issuer: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function parseRippleTokenAddress(tokenAddress: string): ParsedRippleTokenAddress;
|
|
6
|
-
export declare function formatRippleTokenAddress(currency: string, issuer: string): string;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRippleTokenAddress = parseRippleTokenAddress;
|
|
4
|
-
exports.formatRippleTokenAddress = formatRippleTokenAddress;
|
|
5
|
-
const HEX_CURRENCY_LENGTH = 40;
|
|
6
|
-
const RIPPLE_ADDRESS_REGEX = /^r[1-9A-HJ-NP-Za-km-z]{25,34}$/;
|
|
7
|
-
function isValidRippleAddress(address) {
|
|
8
|
-
return RIPPLE_ADDRESS_REGEX.test(address);
|
|
9
|
-
}
|
|
10
|
-
function parseRippleTokenAddress(tokenAddress) {
|
|
11
|
-
const separatorIndex = tokenAddress.lastIndexOf('.');
|
|
12
|
-
if (separatorIndex === -1) {
|
|
13
|
-
throw new Error(`Invalid Ripple token address: ${tokenAddress}`);
|
|
14
|
-
}
|
|
15
|
-
const currency = tokenAddress.slice(0, separatorIndex);
|
|
16
|
-
const issuer = tokenAddress.slice(separatorIndex + 1);
|
|
17
|
-
if (!currency || !issuer) {
|
|
18
|
-
throw new Error(`Invalid Ripple token address: ${tokenAddress}`);
|
|
19
|
-
}
|
|
20
|
-
if (!isValidRippleAddress(issuer)) {
|
|
21
|
-
throw new Error(`Invalid Ripple token issuer: ${issuer}`);
|
|
22
|
-
}
|
|
23
|
-
const isStandardCurrency = currency.length === 3;
|
|
24
|
-
const isHexCurrency = currency.length === HEX_CURRENCY_LENGTH && /^[0-9A-Fa-f]+$/.test(currency);
|
|
25
|
-
if (!isStandardCurrency && !isHexCurrency) {
|
|
26
|
-
throw new Error(`Invalid Ripple token currency: ${currency}`);
|
|
27
|
-
}
|
|
28
|
-
return { currency, issuer };
|
|
29
|
-
}
|
|
30
|
-
function formatRippleTokenAddress(currency, issuer) {
|
|
31
|
-
return `${currency}.${issuer}`;
|
|
32
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
export interface RippleNetworkReserves {
|
|
3
|
-
baseReserveDrops: BigNumber;
|
|
4
|
-
ownerReserveDrops: BigNumber;
|
|
5
|
-
}
|
|
6
|
-
export declare function calculateMinReserveDrops(reserves: RippleNetworkReserves, ownerCount: number): BigNumber;
|
|
7
|
-
export declare function calculateSpendableNativeBalance(totalBalanceDrops: BigNumber, minReserveDrops: BigNumber): BigNumber;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateMinReserveDrops = calculateMinReserveDrops;
|
|
4
|
-
exports.calculateSpendableNativeBalance = calculateSpendableNativeBalance;
|
|
5
|
-
const bignumber_js_1 = require("bignumber.js");
|
|
6
|
-
function calculateMinReserveDrops(reserves, ownerCount) {
|
|
7
|
-
return reserves.baseReserveDrops.plus(new bignumber_js_1.default(ownerCount).multipliedBy(reserves.ownerReserveDrops));
|
|
8
|
-
}
|
|
9
|
-
function calculateSpendableNativeBalance(totalBalanceDrops, minReserveDrops) {
|
|
10
|
-
const spendable = totalBalanceDrops.minus(minReserveDrops);
|
|
11
|
-
return spendable.isNegative() ? new bignumber_js_1.default(0) : spendable;
|
|
12
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RippleWeb3Pure = void 0;
|
|
4
|
-
const changenow_api_blockchain_1 = require("../constants/changenow-api-blockchain");
|
|
5
|
-
const common_web3_pure_1 = require("./common-web3-pure");
|
|
6
|
-
const parse_ripple_token_address_1 = require("../../adapter/adapters/adapter-ripple/utils/parse-ripple-token-address");
|
|
7
|
-
class RippleWeb3Pure extends common_web3_pure_1.CommonWeb3Pure {
|
|
8
|
-
constructor() {
|
|
9
|
-
super({
|
|
10
|
-
cnApiKey: changenow_api_blockchain_1.changenowApiBlockchain.RIPPLE,
|
|
11
|
-
regex: /^r[1-9A-HJ-NP-Za-km-z]{25,34}$/
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
async isAddressCorrect(address) {
|
|
15
|
-
try {
|
|
16
|
-
if (address.includes('.')) {
|
|
17
|
-
(0, parse_ripple_token_address_1.parseRippleTokenAddress)(address);
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return this.regEx.test(address);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.RippleWeb3Pure = RippleWeb3Pure;
|
|
File without changes
|