@xswap-link/sdk 0.0.13 → 0.1.1
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/.github/workflows/main.yml +2 -1
- package/.github/workflows/publish.yml +2 -1
- package/.prettierrc +7 -0
- package/CHANGELOG.md +27 -1
- package/README.md +23 -14
- package/dist/index.css +1108 -0
- package/dist/index.d.mts +212 -52
- package/dist/index.d.ts +212 -52
- package/dist/index.js +2184 -85
- package/dist/index.mjs +2148 -76
- package/nodemon.json +5 -0
- package/package.json +20 -3
- package/postcss.config.js +3 -0
- package/src/components/Alert/index.tsx +9 -0
- package/src/components/Skeleton/index.tsx +10 -0
- package/src/components/TxConfigForm/BalanceComponent.tsx +51 -0
- package/src/components/TxConfigForm/ChainListElement.tsx +36 -0
- package/src/components/TxConfigForm/Description.tsx +15 -0
- package/src/components/TxConfigForm/ErrorField.tsx +17 -0
- package/src/components/TxConfigForm/FeesDetails.tsx +105 -0
- package/src/components/TxConfigForm/Form.tsx +250 -0
- package/src/components/TxConfigForm/History.tsx +155 -0
- package/src/components/TxConfigForm/HistoryCard.tsx +209 -0
- package/src/components/TxConfigForm/Settings.tsx +137 -0
- package/src/components/TxConfigForm/Summary.tsx +57 -0
- package/src/components/TxConfigForm/SwapPanel.tsx +191 -0
- package/src/components/TxConfigForm/TokenPicker.tsx +171 -0
- package/src/components/TxConfigForm/TopBar.tsx +53 -0
- package/src/components/TxConfigForm/index.tsx +121 -0
- package/src/components/global.css +34 -0
- package/src/components/icons/ArrowDownIcon.tsx +16 -0
- package/src/components/icons/ArrowRightIcon.tsx +11 -0
- package/src/components/icons/ArrowUpRightIcon.tsx +11 -0
- package/src/components/icons/ChainlinkCCIPIcon.tsx +23 -0
- package/src/components/icons/CheckIcon.tsx +11 -0
- package/src/components/icons/ChevronDownIcon.tsx +15 -0
- package/src/components/icons/ChevronUpIcon.tsx +15 -0
- package/src/components/icons/CircularProgressIcon.tsx +24 -0
- package/src/components/icons/CloseIcon.tsx +15 -0
- package/src/components/icons/CoinsIcon.tsx +17 -0
- package/src/components/icons/DownArrorIcon.tsx +17 -0
- package/src/components/icons/HistoryIcon.tsx +16 -0
- package/src/components/icons/HourGlassIcon.tsx +11 -0
- package/src/components/icons/InfoIcon.tsx +13 -0
- package/src/components/icons/PercentageIcon.tsx +29 -0
- package/src/components/icons/SearchIcon.tsx +15 -0
- package/src/components/icons/SettingsIcon.tsx +16 -0
- package/src/components/icons/TimerIcon.tsx +15 -0
- package/src/components/icons/XMarkIcon.tsx +11 -0
- package/src/components/icons/XSwapBadgeIcon.tsx +23 -0
- package/src/components/icons/index.ts +20 -0
- package/src/components/index.ts +3 -0
- package/src/config/index.ts +1 -0
- package/src/config/wagmiConfig.ts +45 -0
- package/src/constants/index.ts +9 -5
- package/src/contracts/abi/BatchQuery.json +52 -0
- package/src/contracts/abi/index.ts +2 -0
- package/src/contracts/addresses.ts +34 -0
- package/src/contracts/index.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useDebounce.tsx +21 -0
- package/src/index.ts +6 -0
- package/src/models/Addresses.ts +12 -0
- package/src/models/Route.ts +17 -5
- package/src/models/TokenData.ts +45 -0
- package/src/models/TransactionHistory.ts +48 -0
- package/src/models/XSwapConfig.ts +3 -0
- package/src/models/forms/TxConfigFormData.ts +8 -0
- package/src/models/forms/index.ts +1 -0
- package/src/models/index.ts +6 -6
- package/src/models/integrations/GenerateStakingCallsParams.ts +8 -0
- package/src/models/integrations/index.ts +1 -0
- package/src/models/payloads/GetPricesPayload.ts +4 -0
- package/src/models/payloads/GetRoutePayload.ts +1 -3
- package/src/models/payloads/GetSwapTxPayload.ts +8 -0
- package/src/models/payloads/index.ts +2 -0
- package/src/services/api.ts +46 -64
- package/src/services/index.ts +1 -0
- package/src/services/integrations/customCalls/index.ts +1 -0
- package/src/services/integrations/customCalls/staking.ts +83 -0
- package/src/services/integrations/index.ts +2 -0
- package/src/services/integrations/transactions.ts +30 -0
- package/src/utils/contracts.ts +153 -11
- package/src/utils/index.ts +49 -1
- package/src/utils/numbers.ts +47 -0
- package/src/utils/strings.ts +6 -0
- package/tailwind.config.js +19 -0
- package/test/api.test.ts +1 -1
- package/tsconfig.json +10 -1
- package/xswap.config.ts +18 -0
- package/index.ts +0 -5
- package/src/models/ApiOverrides.ts +0 -3
- package/src/models/Chain.ts +0 -20
- package/src/models/Prices.ts +0 -9
- package/src/models/Token.ts +0 -10
- package/src/models/XSwapFee.ts +0 -4
- package/src/models/XSwapFees.ts +0 -7
- package/src/utils/bigNumbers.ts +0 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import { BigNumber, ethers, BigNumberish } from 'ethers';
|
|
1
2
|
import { TransactionRequest } from '@ethersproject/providers';
|
|
2
|
-
import { BigNumber, BigNumberish, ethers } from 'ethers';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
declare const Alert: ({ desc }: {
|
|
5
|
+
desc: string;
|
|
6
|
+
}) => JSX.Element;
|
|
7
|
+
|
|
8
|
+
type Addresses = {
|
|
9
|
+
[chainId: string]: Contracts;
|
|
10
|
+
};
|
|
11
|
+
type Contracts = {
|
|
12
|
+
[contractName in ContractName]: string;
|
|
13
|
+
};
|
|
14
|
+
declare enum ContractName {
|
|
15
|
+
BatchQuery = "BatchQuery",
|
|
16
|
+
FeeCollector = "FeeCollector"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type XSwapConfig = {
|
|
20
|
+
apiUrl: string;
|
|
6
21
|
};
|
|
7
22
|
|
|
8
23
|
type BridgeToken = {
|
|
@@ -15,17 +30,6 @@ declare enum Web3Environment {
|
|
|
15
30
|
MAINNET = "mainnet"
|
|
16
31
|
}
|
|
17
32
|
|
|
18
|
-
type Token = {
|
|
19
|
-
address: string;
|
|
20
|
-
name: string;
|
|
21
|
-
symbol: string;
|
|
22
|
-
decimals: number;
|
|
23
|
-
image: string;
|
|
24
|
-
priority: number;
|
|
25
|
-
quickPick?: boolean;
|
|
26
|
-
supported?: boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
33
|
type Chain = {
|
|
30
34
|
ecosystem: string;
|
|
31
35
|
chainId: string;
|
|
@@ -43,6 +47,27 @@ type Chain = {
|
|
|
43
47
|
privateRpcUrls?: string[];
|
|
44
48
|
scanApiURL?: string;
|
|
45
49
|
};
|
|
50
|
+
type Token = {
|
|
51
|
+
address: string;
|
|
52
|
+
name: string;
|
|
53
|
+
symbol: string;
|
|
54
|
+
decimals: number;
|
|
55
|
+
image: string;
|
|
56
|
+
priority: number;
|
|
57
|
+
quickPick?: boolean;
|
|
58
|
+
supported?: boolean;
|
|
59
|
+
};
|
|
60
|
+
type Prices = {
|
|
61
|
+
blockchainId: string;
|
|
62
|
+
updatedAt: Date;
|
|
63
|
+
prices: TokenPrices;
|
|
64
|
+
};
|
|
65
|
+
type TokenPrices = {
|
|
66
|
+
[tokenAddress: string]: string;
|
|
67
|
+
};
|
|
68
|
+
type TokenBalances = {
|
|
69
|
+
[tokenAddress: string]: BigNumber | undefined;
|
|
70
|
+
};
|
|
46
71
|
|
|
47
72
|
type CoinTypeAddress = {
|
|
48
73
|
coinType: number;
|
|
@@ -80,6 +105,23 @@ declare enum Environment {
|
|
|
80
105
|
LOCAL = "local"
|
|
81
106
|
}
|
|
82
107
|
|
|
108
|
+
type TxConfigFormData = {
|
|
109
|
+
srcChain: string;
|
|
110
|
+
srcToken: string;
|
|
111
|
+
amountIn: string;
|
|
112
|
+
paymentToken: string;
|
|
113
|
+
slippage: number;
|
|
114
|
+
expressDelivery: boolean;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
type GenerateStakingCallsParams = {
|
|
118
|
+
token: string;
|
|
119
|
+
staking: string;
|
|
120
|
+
stakingAbi: string;
|
|
121
|
+
stakingFunName: string;
|
|
122
|
+
stakingFunParams: any[];
|
|
123
|
+
};
|
|
124
|
+
|
|
83
125
|
type GetRoutePayload = {
|
|
84
126
|
fromChain: string;
|
|
85
127
|
toChain: string;
|
|
@@ -106,6 +148,18 @@ type AddReferralPayload = {
|
|
|
106
148
|
address: string;
|
|
107
149
|
};
|
|
108
150
|
|
|
151
|
+
type GetSwapTxPayload = {
|
|
152
|
+
dstChain: string;
|
|
153
|
+
dstToken: string;
|
|
154
|
+
customContractCalls?: ContractCall[];
|
|
155
|
+
desc?: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type GetPricesPayload = {
|
|
159
|
+
chainId: string;
|
|
160
|
+
currency?: string;
|
|
161
|
+
};
|
|
162
|
+
|
|
109
163
|
type Protocol = {
|
|
110
164
|
name: string;
|
|
111
165
|
part: number;
|
|
@@ -113,26 +167,25 @@ type Protocol = {
|
|
|
113
167
|
toTokenAddress: string;
|
|
114
168
|
};
|
|
115
169
|
|
|
116
|
-
type
|
|
117
|
-
|
|
118
|
-
|
|
170
|
+
type Route = {
|
|
171
|
+
estAmountOut: string;
|
|
172
|
+
minAmountOut: string;
|
|
173
|
+
transactions: Transactions;
|
|
174
|
+
xSwapFees: XSwapFees;
|
|
175
|
+
message?: string;
|
|
176
|
+
};
|
|
177
|
+
type Transactions = {
|
|
178
|
+
approve?: TransactionRequest;
|
|
179
|
+
swap: TransactionRequest;
|
|
119
180
|
};
|
|
120
|
-
|
|
121
181
|
type XSwapFees = {
|
|
122
182
|
ccipFee?: string;
|
|
123
183
|
xSwapFee: XSwapFee;
|
|
124
184
|
expressDeliveryFee?: string;
|
|
125
185
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
minAmountOut: string;
|
|
130
|
-
transactions: {
|
|
131
|
-
approve?: TransactionRequest;
|
|
132
|
-
swap: TransactionRequest;
|
|
133
|
-
};
|
|
134
|
-
xSwapFees: XSwapFees;
|
|
135
|
-
message?: string;
|
|
186
|
+
type XSwapFee = {
|
|
187
|
+
tokenFee: string;
|
|
188
|
+
nativeFee: string;
|
|
136
189
|
};
|
|
137
190
|
|
|
138
191
|
type Referral = {
|
|
@@ -145,21 +198,99 @@ type ReferralInfo = {
|
|
|
145
198
|
ipAddress: string;
|
|
146
199
|
};
|
|
147
200
|
|
|
148
|
-
type
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
201
|
+
type TransferType = "CROSS_CHAIN" | "SINGLE_CHAIN";
|
|
202
|
+
type TransactionHistory = {
|
|
203
|
+
history: {
|
|
204
|
+
transferId: string;
|
|
205
|
+
transferType: TransferType;
|
|
206
|
+
walletAddress: string;
|
|
207
|
+
failed: boolean;
|
|
208
|
+
source: {
|
|
209
|
+
blockchainId: string;
|
|
210
|
+
transactionHash: string;
|
|
211
|
+
blockTime: Date;
|
|
212
|
+
tokenAmount: string;
|
|
213
|
+
tokenAddress: string;
|
|
214
|
+
transferredTokenAddress: string;
|
|
215
|
+
transferredTokenAmount: string;
|
|
216
|
+
valueForInstantCcipRecieve: string;
|
|
217
|
+
tokenOutAddress: string;
|
|
218
|
+
estimatedAmountOut: string;
|
|
219
|
+
targetBlockchainId: string;
|
|
220
|
+
} | null;
|
|
221
|
+
target: {
|
|
222
|
+
blockchainId: string;
|
|
223
|
+
transactionHash: string;
|
|
224
|
+
blockTime: Date;
|
|
225
|
+
tokenAmount: string;
|
|
226
|
+
tokenAddress: string;
|
|
227
|
+
} | null;
|
|
228
|
+
}[];
|
|
152
229
|
};
|
|
153
|
-
type
|
|
154
|
-
|
|
230
|
+
type TransactionStatus = "IN_PROGRESS" | "DONE" | "REVERTED";
|
|
231
|
+
type Transaction = {
|
|
232
|
+
hash: string;
|
|
233
|
+
timestamp: number;
|
|
234
|
+
sourceChainId: string;
|
|
235
|
+
targetChainId: string;
|
|
236
|
+
amountWei: string;
|
|
237
|
+
tokenAddress: string;
|
|
238
|
+
tokenOutAddress: string | undefined;
|
|
239
|
+
tokenOutAmount: string | undefined;
|
|
240
|
+
estimatedDeliveryTimestamp: number;
|
|
241
|
+
status: TransactionStatus;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
type TxConfigFormProps = {
|
|
245
|
+
dstChainId: string;
|
|
246
|
+
dstTokenAddr: string;
|
|
247
|
+
customContractCalls: ContractCall[];
|
|
248
|
+
desc?: string;
|
|
249
|
+
supportedChains: Chain[];
|
|
250
|
+
};
|
|
251
|
+
declare const openTxConfigForm: ({ dstChainId, dstTokenAddr, customContractCalls, desc, supportedChains, }: TxConfigFormProps) => Promise<Route>;
|
|
252
|
+
|
|
253
|
+
declare const Skeleton: ({ w, h }: Style) => JSX.Element;
|
|
254
|
+
type Style = {
|
|
255
|
+
w: string;
|
|
256
|
+
h: string;
|
|
155
257
|
};
|
|
156
258
|
|
|
157
|
-
declare const DEFAULT_API_URL = "https://xswap.link/api";
|
|
158
|
-
declare const DEFAULT_DB_ERROR = "No data for provided parameters";
|
|
159
259
|
declare const DEFAULT_ECOSYSTEM = Ecosystem.EVM;
|
|
160
|
-
declare const
|
|
161
|
-
declare const
|
|
260
|
+
declare const NUMBER_INPUT_REGEX: RegExp;
|
|
261
|
+
declare const SLIPPAGE_PRESETS: number[];
|
|
262
|
+
declare const DELIVERY_TIME: number;
|
|
263
|
+
declare const EXPRESS_DELIVERY_TIME: number;
|
|
264
|
+
declare const BALANCES_CHUNK_SIZE = 500;
|
|
265
|
+
declare const BALANCE_DISPLAY_MIN_LIMIT = 0.0001;
|
|
266
|
+
declare const ROUTE_TIMEOUT_MS = 5000;
|
|
267
|
+
declare const MINIMUM_DISPLAYED_TOKEN_AMOUNT = 0.00001;
|
|
162
268
|
|
|
269
|
+
declare const BatchQueryAbi: ({
|
|
270
|
+
inputs: {
|
|
271
|
+
internalType: string;
|
|
272
|
+
name: string;
|
|
273
|
+
type: string;
|
|
274
|
+
}[];
|
|
275
|
+
name: string;
|
|
276
|
+
type: string;
|
|
277
|
+
outputs?: undefined;
|
|
278
|
+
stateMutability?: undefined;
|
|
279
|
+
} | {
|
|
280
|
+
inputs: {
|
|
281
|
+
internalType: string;
|
|
282
|
+
name: string;
|
|
283
|
+
type: string;
|
|
284
|
+
}[];
|
|
285
|
+
name: string;
|
|
286
|
+
outputs: {
|
|
287
|
+
internalType: string;
|
|
288
|
+
name: string;
|
|
289
|
+
type: string;
|
|
290
|
+
}[];
|
|
291
|
+
stateMutability: string;
|
|
292
|
+
type: string;
|
|
293
|
+
})[];
|
|
163
294
|
declare const ERC20Abi: ({
|
|
164
295
|
constant: boolean;
|
|
165
296
|
inputs: {
|
|
@@ -322,41 +453,70 @@ declare const XSwapRouterAbi: ({
|
|
|
322
453
|
outputs?: undefined;
|
|
323
454
|
})[];
|
|
324
455
|
|
|
456
|
+
declare const ADDRESSES: Addresses;
|
|
457
|
+
|
|
325
458
|
/**
|
|
326
459
|
* Get swap route based on provided criteria.
|
|
327
460
|
* @param payload required
|
|
328
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
329
461
|
*/
|
|
330
|
-
declare function getRoute(payload: GetRoutePayload
|
|
462
|
+
declare function getRoute(payload: GetRoutePayload): Promise<Route>;
|
|
331
463
|
/**
|
|
332
464
|
* GET chains based on provided criteria.
|
|
333
465
|
* @param ecosystem optional
|
|
334
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
335
466
|
*/
|
|
336
|
-
declare function getChains(ecosystem?: Ecosystem
|
|
467
|
+
declare function getChains(ecosystem?: Ecosystem): Promise<Chain[]>;
|
|
337
468
|
/**
|
|
338
469
|
* GET chain data based on provided criteria.
|
|
339
470
|
* @param chainId
|
|
340
471
|
* @param ecosystem optional - Default: {@link DEFAULT_ECOSYSTEM}
|
|
341
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
342
472
|
*/
|
|
343
|
-
declare function getChainData(chainId?: string, ecosystem?: Ecosystem
|
|
473
|
+
declare function getChainData(chainId?: string, ecosystem?: Ecosystem): Promise<Chain>;
|
|
344
474
|
/**
|
|
345
475
|
* GET Tokens based on provided criteria
|
|
346
476
|
* @param chainId required
|
|
347
477
|
* @param address optional
|
|
348
478
|
* @param ecosystem optional but {@link DEFAULT_ECOSYSTEM} will be considered
|
|
349
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
350
479
|
*/
|
|
351
|
-
declare function getTokens(chainId: string, address?: string, ecosystem?: Ecosystem
|
|
352
|
-
declare function getBridgeTokens(
|
|
480
|
+
declare function getTokens(chainId: string, address?: string, ecosystem?: Ecosystem): Promise<Token[]>;
|
|
481
|
+
declare function getBridgeTokens(): Promise<BridgeToken[]>;
|
|
482
|
+
declare function getHistory(payload: {
|
|
483
|
+
walletAddress: string;
|
|
484
|
+
}): Promise<TransactionHistory>;
|
|
485
|
+
declare function getPrices(payload: GetPricesPayload): Promise<TokenPrices>;
|
|
486
|
+
|
|
487
|
+
declare const generateStakingCalls: ({ token, staking, stakingAbi, stakingFunName, stakingFunParams, }: GenerateStakingCallsParams) => ContractCall[];
|
|
488
|
+
|
|
489
|
+
declare const getSwapTx: ({ dstChain, dstToken, customContractCalls, desc, }: GetSwapTxPayload) => Promise<Transactions>;
|
|
490
|
+
|
|
491
|
+
declare const IERC20: ethers.utils.Interface;
|
|
492
|
+
declare const getBalanceOf: (wallet: string, token: string, rpcUrl: string) => Promise<string>;
|
|
493
|
+
declare const getBalances: (chain: Chain, wallet: string) => Promise<TokenBalances>;
|
|
494
|
+
declare const generateApproveTxData: (tokenAddress: string, spender: string, amount: BigNumberish) => TransactionRequest | undefined;
|
|
495
|
+
/**
|
|
496
|
+
* Calculate param's value offset within the encoded function's bytecode.
|
|
497
|
+
* @param abi
|
|
498
|
+
* @param funName
|
|
499
|
+
* @param funParams
|
|
500
|
+
* @param placeholderValue
|
|
501
|
+
*/
|
|
502
|
+
declare const findPlaceholderIndex: (abi: string, funName: string, funParams: any[], placeholderValue: BigNumber) => number;
|
|
353
503
|
|
|
354
504
|
declare const safeBigNumberFrom: (value: string) => BigNumber;
|
|
505
|
+
declare const weiToHumanReadable: ({ amount, decimals, precisionFractionalPlaces, prettifySmallNumber, }: {
|
|
506
|
+
amount: string;
|
|
507
|
+
decimals: number;
|
|
508
|
+
precisionFractionalPlaces: number;
|
|
509
|
+
prettifySmallNumber?: boolean;
|
|
510
|
+
}) => string;
|
|
511
|
+
declare const generateRandomBigNumber: (length: number) => BigNumber;
|
|
512
|
+
declare const generateUniqueRandomBigNumber: (length: number, existingValues: any[]) => BigNumber;
|
|
513
|
+
|
|
514
|
+
declare const shortAddress: (address: string) => string;
|
|
355
515
|
|
|
356
|
-
declare const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
data: string;
|
|
516
|
+
declare const replaceNull: (values: any[], newValue: any) => any[];
|
|
517
|
+
declare const deepMergeObjects: (obj1: Record<string, any>, obj2: Record<string, any>) => {
|
|
518
|
+
[x: string]: any;
|
|
360
519
|
};
|
|
520
|
+
declare const chunkArray: (array: any[], chunkSize: number) => any[][];
|
|
361
521
|
|
|
362
|
-
export { type AddReferralPayload, type
|
|
522
|
+
export { ADDRESSES, type AddReferralPayload, type Addresses, Alert, BALANCES_CHUNK_SIZE, BALANCE_DISPLAY_MIN_LIMIT, BatchQueryAbi, type BridgeToken, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, DEFAULT_ECOSYSTEM, DELIVERY_TIME, ERC20Abi, EXPRESS_DELIVERY_TIME, Ecosystem, Environment, type GenerateStakingCallsParams, type GetPricesPayload, type GetRoutePayload, type GetSwapTxPayload, IERC20, MINIMUM_DISPLAYED_TOKEN_AMOUNT, NUMBER_INPUT_REGEX, type Prices, type Protocol, ROUTE_TIMEOUT_MS, type Referral, type ReferralInfo, type Route, SLIPPAGE_PRESETS, Skeleton, type Token, type TokenBalances, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type Transactions, type TxConfigFormData, type TxConfigFormProps, Web3Environment, XSwapCallType, type XSwapConfig, type XSwapFee, type XSwapFees, XSwapRouterAbi, chunkArray, deepMergeObjects, findPlaceholderIndex, generateApproveTxData, generateRandomBigNumber, generateStakingCalls, generateUniqueRandomBigNumber, getBalanceOf, getBalances, getBridgeTokens, getChainData, getChains, getHistory, getPrices, getRoute, getSwapTx, getTokens, openTxConfigForm, replaceNull, safeBigNumberFrom, shortAddress, weiToHumanReadable };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import { BigNumber, ethers, BigNumberish } from 'ethers';
|
|
1
2
|
import { TransactionRequest } from '@ethersproject/providers';
|
|
2
|
-
import { BigNumber, BigNumberish, ethers } from 'ethers';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
declare const Alert: ({ desc }: {
|
|
5
|
+
desc: string;
|
|
6
|
+
}) => JSX.Element;
|
|
7
|
+
|
|
8
|
+
type Addresses = {
|
|
9
|
+
[chainId: string]: Contracts;
|
|
10
|
+
};
|
|
11
|
+
type Contracts = {
|
|
12
|
+
[contractName in ContractName]: string;
|
|
13
|
+
};
|
|
14
|
+
declare enum ContractName {
|
|
15
|
+
BatchQuery = "BatchQuery",
|
|
16
|
+
FeeCollector = "FeeCollector"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type XSwapConfig = {
|
|
20
|
+
apiUrl: string;
|
|
6
21
|
};
|
|
7
22
|
|
|
8
23
|
type BridgeToken = {
|
|
@@ -15,17 +30,6 @@ declare enum Web3Environment {
|
|
|
15
30
|
MAINNET = "mainnet"
|
|
16
31
|
}
|
|
17
32
|
|
|
18
|
-
type Token = {
|
|
19
|
-
address: string;
|
|
20
|
-
name: string;
|
|
21
|
-
symbol: string;
|
|
22
|
-
decimals: number;
|
|
23
|
-
image: string;
|
|
24
|
-
priority: number;
|
|
25
|
-
quickPick?: boolean;
|
|
26
|
-
supported?: boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
33
|
type Chain = {
|
|
30
34
|
ecosystem: string;
|
|
31
35
|
chainId: string;
|
|
@@ -43,6 +47,27 @@ type Chain = {
|
|
|
43
47
|
privateRpcUrls?: string[];
|
|
44
48
|
scanApiURL?: string;
|
|
45
49
|
};
|
|
50
|
+
type Token = {
|
|
51
|
+
address: string;
|
|
52
|
+
name: string;
|
|
53
|
+
symbol: string;
|
|
54
|
+
decimals: number;
|
|
55
|
+
image: string;
|
|
56
|
+
priority: number;
|
|
57
|
+
quickPick?: boolean;
|
|
58
|
+
supported?: boolean;
|
|
59
|
+
};
|
|
60
|
+
type Prices = {
|
|
61
|
+
blockchainId: string;
|
|
62
|
+
updatedAt: Date;
|
|
63
|
+
prices: TokenPrices;
|
|
64
|
+
};
|
|
65
|
+
type TokenPrices = {
|
|
66
|
+
[tokenAddress: string]: string;
|
|
67
|
+
};
|
|
68
|
+
type TokenBalances = {
|
|
69
|
+
[tokenAddress: string]: BigNumber | undefined;
|
|
70
|
+
};
|
|
46
71
|
|
|
47
72
|
type CoinTypeAddress = {
|
|
48
73
|
coinType: number;
|
|
@@ -80,6 +105,23 @@ declare enum Environment {
|
|
|
80
105
|
LOCAL = "local"
|
|
81
106
|
}
|
|
82
107
|
|
|
108
|
+
type TxConfigFormData = {
|
|
109
|
+
srcChain: string;
|
|
110
|
+
srcToken: string;
|
|
111
|
+
amountIn: string;
|
|
112
|
+
paymentToken: string;
|
|
113
|
+
slippage: number;
|
|
114
|
+
expressDelivery: boolean;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
type GenerateStakingCallsParams = {
|
|
118
|
+
token: string;
|
|
119
|
+
staking: string;
|
|
120
|
+
stakingAbi: string;
|
|
121
|
+
stakingFunName: string;
|
|
122
|
+
stakingFunParams: any[];
|
|
123
|
+
};
|
|
124
|
+
|
|
83
125
|
type GetRoutePayload = {
|
|
84
126
|
fromChain: string;
|
|
85
127
|
toChain: string;
|
|
@@ -106,6 +148,18 @@ type AddReferralPayload = {
|
|
|
106
148
|
address: string;
|
|
107
149
|
};
|
|
108
150
|
|
|
151
|
+
type GetSwapTxPayload = {
|
|
152
|
+
dstChain: string;
|
|
153
|
+
dstToken: string;
|
|
154
|
+
customContractCalls?: ContractCall[];
|
|
155
|
+
desc?: string;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type GetPricesPayload = {
|
|
159
|
+
chainId: string;
|
|
160
|
+
currency?: string;
|
|
161
|
+
};
|
|
162
|
+
|
|
109
163
|
type Protocol = {
|
|
110
164
|
name: string;
|
|
111
165
|
part: number;
|
|
@@ -113,26 +167,25 @@ type Protocol = {
|
|
|
113
167
|
toTokenAddress: string;
|
|
114
168
|
};
|
|
115
169
|
|
|
116
|
-
type
|
|
117
|
-
|
|
118
|
-
|
|
170
|
+
type Route = {
|
|
171
|
+
estAmountOut: string;
|
|
172
|
+
minAmountOut: string;
|
|
173
|
+
transactions: Transactions;
|
|
174
|
+
xSwapFees: XSwapFees;
|
|
175
|
+
message?: string;
|
|
176
|
+
};
|
|
177
|
+
type Transactions = {
|
|
178
|
+
approve?: TransactionRequest;
|
|
179
|
+
swap: TransactionRequest;
|
|
119
180
|
};
|
|
120
|
-
|
|
121
181
|
type XSwapFees = {
|
|
122
182
|
ccipFee?: string;
|
|
123
183
|
xSwapFee: XSwapFee;
|
|
124
184
|
expressDeliveryFee?: string;
|
|
125
185
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
minAmountOut: string;
|
|
130
|
-
transactions: {
|
|
131
|
-
approve?: TransactionRequest;
|
|
132
|
-
swap: TransactionRequest;
|
|
133
|
-
};
|
|
134
|
-
xSwapFees: XSwapFees;
|
|
135
|
-
message?: string;
|
|
186
|
+
type XSwapFee = {
|
|
187
|
+
tokenFee: string;
|
|
188
|
+
nativeFee: string;
|
|
136
189
|
};
|
|
137
190
|
|
|
138
191
|
type Referral = {
|
|
@@ -145,21 +198,99 @@ type ReferralInfo = {
|
|
|
145
198
|
ipAddress: string;
|
|
146
199
|
};
|
|
147
200
|
|
|
148
|
-
type
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
201
|
+
type TransferType = "CROSS_CHAIN" | "SINGLE_CHAIN";
|
|
202
|
+
type TransactionHistory = {
|
|
203
|
+
history: {
|
|
204
|
+
transferId: string;
|
|
205
|
+
transferType: TransferType;
|
|
206
|
+
walletAddress: string;
|
|
207
|
+
failed: boolean;
|
|
208
|
+
source: {
|
|
209
|
+
blockchainId: string;
|
|
210
|
+
transactionHash: string;
|
|
211
|
+
blockTime: Date;
|
|
212
|
+
tokenAmount: string;
|
|
213
|
+
tokenAddress: string;
|
|
214
|
+
transferredTokenAddress: string;
|
|
215
|
+
transferredTokenAmount: string;
|
|
216
|
+
valueForInstantCcipRecieve: string;
|
|
217
|
+
tokenOutAddress: string;
|
|
218
|
+
estimatedAmountOut: string;
|
|
219
|
+
targetBlockchainId: string;
|
|
220
|
+
} | null;
|
|
221
|
+
target: {
|
|
222
|
+
blockchainId: string;
|
|
223
|
+
transactionHash: string;
|
|
224
|
+
blockTime: Date;
|
|
225
|
+
tokenAmount: string;
|
|
226
|
+
tokenAddress: string;
|
|
227
|
+
} | null;
|
|
228
|
+
}[];
|
|
152
229
|
};
|
|
153
|
-
type
|
|
154
|
-
|
|
230
|
+
type TransactionStatus = "IN_PROGRESS" | "DONE" | "REVERTED";
|
|
231
|
+
type Transaction = {
|
|
232
|
+
hash: string;
|
|
233
|
+
timestamp: number;
|
|
234
|
+
sourceChainId: string;
|
|
235
|
+
targetChainId: string;
|
|
236
|
+
amountWei: string;
|
|
237
|
+
tokenAddress: string;
|
|
238
|
+
tokenOutAddress: string | undefined;
|
|
239
|
+
tokenOutAmount: string | undefined;
|
|
240
|
+
estimatedDeliveryTimestamp: number;
|
|
241
|
+
status: TransactionStatus;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
type TxConfigFormProps = {
|
|
245
|
+
dstChainId: string;
|
|
246
|
+
dstTokenAddr: string;
|
|
247
|
+
customContractCalls: ContractCall[];
|
|
248
|
+
desc?: string;
|
|
249
|
+
supportedChains: Chain[];
|
|
250
|
+
};
|
|
251
|
+
declare const openTxConfigForm: ({ dstChainId, dstTokenAddr, customContractCalls, desc, supportedChains, }: TxConfigFormProps) => Promise<Route>;
|
|
252
|
+
|
|
253
|
+
declare const Skeleton: ({ w, h }: Style) => JSX.Element;
|
|
254
|
+
type Style = {
|
|
255
|
+
w: string;
|
|
256
|
+
h: string;
|
|
155
257
|
};
|
|
156
258
|
|
|
157
|
-
declare const DEFAULT_API_URL = "https://xswap.link/api";
|
|
158
|
-
declare const DEFAULT_DB_ERROR = "No data for provided parameters";
|
|
159
259
|
declare const DEFAULT_ECOSYSTEM = Ecosystem.EVM;
|
|
160
|
-
declare const
|
|
161
|
-
declare const
|
|
260
|
+
declare const NUMBER_INPUT_REGEX: RegExp;
|
|
261
|
+
declare const SLIPPAGE_PRESETS: number[];
|
|
262
|
+
declare const DELIVERY_TIME: number;
|
|
263
|
+
declare const EXPRESS_DELIVERY_TIME: number;
|
|
264
|
+
declare const BALANCES_CHUNK_SIZE = 500;
|
|
265
|
+
declare const BALANCE_DISPLAY_MIN_LIMIT = 0.0001;
|
|
266
|
+
declare const ROUTE_TIMEOUT_MS = 5000;
|
|
267
|
+
declare const MINIMUM_DISPLAYED_TOKEN_AMOUNT = 0.00001;
|
|
162
268
|
|
|
269
|
+
declare const BatchQueryAbi: ({
|
|
270
|
+
inputs: {
|
|
271
|
+
internalType: string;
|
|
272
|
+
name: string;
|
|
273
|
+
type: string;
|
|
274
|
+
}[];
|
|
275
|
+
name: string;
|
|
276
|
+
type: string;
|
|
277
|
+
outputs?: undefined;
|
|
278
|
+
stateMutability?: undefined;
|
|
279
|
+
} | {
|
|
280
|
+
inputs: {
|
|
281
|
+
internalType: string;
|
|
282
|
+
name: string;
|
|
283
|
+
type: string;
|
|
284
|
+
}[];
|
|
285
|
+
name: string;
|
|
286
|
+
outputs: {
|
|
287
|
+
internalType: string;
|
|
288
|
+
name: string;
|
|
289
|
+
type: string;
|
|
290
|
+
}[];
|
|
291
|
+
stateMutability: string;
|
|
292
|
+
type: string;
|
|
293
|
+
})[];
|
|
163
294
|
declare const ERC20Abi: ({
|
|
164
295
|
constant: boolean;
|
|
165
296
|
inputs: {
|
|
@@ -322,41 +453,70 @@ declare const XSwapRouterAbi: ({
|
|
|
322
453
|
outputs?: undefined;
|
|
323
454
|
})[];
|
|
324
455
|
|
|
456
|
+
declare const ADDRESSES: Addresses;
|
|
457
|
+
|
|
325
458
|
/**
|
|
326
459
|
* Get swap route based on provided criteria.
|
|
327
460
|
* @param payload required
|
|
328
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
329
461
|
*/
|
|
330
|
-
declare function getRoute(payload: GetRoutePayload
|
|
462
|
+
declare function getRoute(payload: GetRoutePayload): Promise<Route>;
|
|
331
463
|
/**
|
|
332
464
|
* GET chains based on provided criteria.
|
|
333
465
|
* @param ecosystem optional
|
|
334
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
335
466
|
*/
|
|
336
|
-
declare function getChains(ecosystem?: Ecosystem
|
|
467
|
+
declare function getChains(ecosystem?: Ecosystem): Promise<Chain[]>;
|
|
337
468
|
/**
|
|
338
469
|
* GET chain data based on provided criteria.
|
|
339
470
|
* @param chainId
|
|
340
471
|
* @param ecosystem optional - Default: {@link DEFAULT_ECOSYSTEM}
|
|
341
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
342
472
|
*/
|
|
343
|
-
declare function getChainData(chainId?: string, ecosystem?: Ecosystem
|
|
473
|
+
declare function getChainData(chainId?: string, ecosystem?: Ecosystem): Promise<Chain>;
|
|
344
474
|
/**
|
|
345
475
|
* GET Tokens based on provided criteria
|
|
346
476
|
* @param chainId required
|
|
347
477
|
* @param address optional
|
|
348
478
|
* @param ecosystem optional but {@link DEFAULT_ECOSYSTEM} will be considered
|
|
349
|
-
* @param overrides optional - e.g. {apiUrl}
|
|
350
479
|
*/
|
|
351
|
-
declare function getTokens(chainId: string, address?: string, ecosystem?: Ecosystem
|
|
352
|
-
declare function getBridgeTokens(
|
|
480
|
+
declare function getTokens(chainId: string, address?: string, ecosystem?: Ecosystem): Promise<Token[]>;
|
|
481
|
+
declare function getBridgeTokens(): Promise<BridgeToken[]>;
|
|
482
|
+
declare function getHistory(payload: {
|
|
483
|
+
walletAddress: string;
|
|
484
|
+
}): Promise<TransactionHistory>;
|
|
485
|
+
declare function getPrices(payload: GetPricesPayload): Promise<TokenPrices>;
|
|
486
|
+
|
|
487
|
+
declare const generateStakingCalls: ({ token, staking, stakingAbi, stakingFunName, stakingFunParams, }: GenerateStakingCallsParams) => ContractCall[];
|
|
488
|
+
|
|
489
|
+
declare const getSwapTx: ({ dstChain, dstToken, customContractCalls, desc, }: GetSwapTxPayload) => Promise<Transactions>;
|
|
490
|
+
|
|
491
|
+
declare const IERC20: ethers.utils.Interface;
|
|
492
|
+
declare const getBalanceOf: (wallet: string, token: string, rpcUrl: string) => Promise<string>;
|
|
493
|
+
declare const getBalances: (chain: Chain, wallet: string) => Promise<TokenBalances>;
|
|
494
|
+
declare const generateApproveTxData: (tokenAddress: string, spender: string, amount: BigNumberish) => TransactionRequest | undefined;
|
|
495
|
+
/**
|
|
496
|
+
* Calculate param's value offset within the encoded function's bytecode.
|
|
497
|
+
* @param abi
|
|
498
|
+
* @param funName
|
|
499
|
+
* @param funParams
|
|
500
|
+
* @param placeholderValue
|
|
501
|
+
*/
|
|
502
|
+
declare const findPlaceholderIndex: (abi: string, funName: string, funParams: any[], placeholderValue: BigNumber) => number;
|
|
353
503
|
|
|
354
504
|
declare const safeBigNumberFrom: (value: string) => BigNumber;
|
|
505
|
+
declare const weiToHumanReadable: ({ amount, decimals, precisionFractionalPlaces, prettifySmallNumber, }: {
|
|
506
|
+
amount: string;
|
|
507
|
+
decimals: number;
|
|
508
|
+
precisionFractionalPlaces: number;
|
|
509
|
+
prettifySmallNumber?: boolean;
|
|
510
|
+
}) => string;
|
|
511
|
+
declare const generateRandomBigNumber: (length: number) => BigNumber;
|
|
512
|
+
declare const generateUniqueRandomBigNumber: (length: number, existingValues: any[]) => BigNumber;
|
|
513
|
+
|
|
514
|
+
declare const shortAddress: (address: string) => string;
|
|
355
515
|
|
|
356
|
-
declare const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
data: string;
|
|
516
|
+
declare const replaceNull: (values: any[], newValue: any) => any[];
|
|
517
|
+
declare const deepMergeObjects: (obj1: Record<string, any>, obj2: Record<string, any>) => {
|
|
518
|
+
[x: string]: any;
|
|
360
519
|
};
|
|
520
|
+
declare const chunkArray: (array: any[], chunkSize: number) => any[][];
|
|
361
521
|
|
|
362
|
-
export { type AddReferralPayload, type
|
|
522
|
+
export { ADDRESSES, type AddReferralPayload, type Addresses, Alert, BALANCES_CHUNK_SIZE, BALANCE_DISPLAY_MIN_LIMIT, BatchQueryAbi, type BridgeToken, type Chain, type CoinTypeAddress, type CollectFees, type ContractCall, ContractName, type Contracts, DEFAULT_ECOSYSTEM, DELIVERY_TIME, ERC20Abi, EXPRESS_DELIVERY_TIME, Ecosystem, Environment, type GenerateStakingCallsParams, type GetPricesPayload, type GetRoutePayload, type GetSwapTxPayload, IERC20, MINIMUM_DISPLAYED_TOKEN_AMOUNT, NUMBER_INPUT_REGEX, type Prices, type Protocol, ROUTE_TIMEOUT_MS, type Referral, type ReferralInfo, type Route, SLIPPAGE_PRESETS, Skeleton, type Token, type TokenBalances, type TokenPrices, type Transaction, type TransactionHistory, type TransactionStatus, type Transactions, type TxConfigFormData, type TxConfigFormProps, Web3Environment, XSwapCallType, type XSwapConfig, type XSwapFee, type XSwapFees, XSwapRouterAbi, chunkArray, deepMergeObjects, findPlaceholderIndex, generateApproveTxData, generateRandomBigNumber, generateStakingCalls, generateUniqueRandomBigNumber, getBalanceOf, getBalances, getBridgeTokens, getChainData, getChains, getHistory, getPrices, getRoute, getSwapTx, getTokens, openTxConfigForm, replaceNull, safeBigNumberFrom, shortAddress, weiToHumanReadable };
|