@allbridge/bridge-core-sdk 3.35.0-alpha.2 → 3.35.0
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/README.md +212 -75
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/src/client/core-api/core-api.model.d.ts +27 -0
- package/dist/src/client/core-api/core-api.model.js +21 -0
- package/dist/src/client/core-api/core-api.model.js.map +1 -1
- package/dist/src/index.d.ts +24 -17
- package/dist/src/index.js +4 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/index.d.ts +3 -0
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/services/models/index.d.ts +1 -0
- package/dist/src/services/models/index.js.map +1 -1
- package/dist/src/tokens-info/tokens-info.model.d.ts +25 -9
- package/dist/src/tokens-info/tokens-info.model.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,11 +21,14 @@ Provides an easy integration with the Allbridge Core ChainBridgeService for DApp
|
|
|
21
21
|
- [How to use](#how-to-use)
|
|
22
22
|
- [1. Initialize SDK instance](#1-initialize-sdk)
|
|
23
23
|
- [2. Get the list of supported tokens](#2-get-the-list-of-supported-tokens)
|
|
24
|
-
- [3.
|
|
25
|
-
|
|
24
|
+
- [3. Choose a messenger](#3-choose-a-messenger)
|
|
25
|
+
- [CCTP and CCTP V2](#cctp-and-cctp-v2)
|
|
26
|
+
- [OFT](#oft)
|
|
27
|
+
- [X_RESERVE](#x_reserve)
|
|
28
|
+
- [4.1 Approve the transfer of tokens](#41-approve-the-transfer-of-tokens-only-for-evm-tron)
|
|
29
|
+
- [4.2 Send Tokens](#42-send-tokens)
|
|
26
30
|
- [Full example](#full-example)
|
|
27
31
|
- [Other operations](#other-operations)
|
|
28
|
-
- [Liquidity Pools operations](#liquidity-pools-operations)
|
|
29
32
|
- [Transaction builder](#transaction-builder)
|
|
30
33
|
- [Approve Transaction](#approve-transaction)
|
|
31
34
|
- [Send Transaction](#send-transaction)
|
|
@@ -33,7 +36,9 @@ Provides an easy integration with the Allbridge Core ChainBridgeService for DApp
|
|
|
33
36
|
- [Calculating amount of tokens to be received after fee](#calculating-amount-of-tokens-to-be-received-after-fee)
|
|
34
37
|
- [Calculating amount of tokens to send](#calculating-amount-of-tokens-to-send)
|
|
35
38
|
- [Getting the amount of gas fee](#getting-the-amount-of-gas-fee)
|
|
39
|
+
- [Getting the maximum amount of extra gas](#getting-the-maximum-amount-of-extra-gas)
|
|
36
40
|
- [Getting the average transfer time](#getting-the-average-transfer-time)
|
|
41
|
+
- [Known Audit Warning](#known-audit-warning)
|
|
37
42
|
|
|
38
43
|
## Installing
|
|
39
44
|
|
|
@@ -45,10 +50,10 @@ $ npm install @allbridge/bridge-core-sdk
|
|
|
45
50
|
|
|
46
51
|
### Find out how to integrate Allbridge Core SDK and Browser Extension Wallet
|
|
47
52
|
|
|
48
|
-
[***Evm***](https://github.com/allbridge-
|
|
49
|
-
[***Solana***](https://github.com/allbridge-
|
|
50
|
-
[***Stellar***](https://github.com/allbridge-
|
|
51
|
-
[***Tron***](https://github.com/allbridge-
|
|
53
|
+
[***Evm***](https://github.com/allbridge-io/allbridge-core-js-sdk/tree/main/documentation/browser/evm.md)
|
|
54
|
+
[***Solana***](https://github.com/allbridge-io/allbridge-core-js-sdk/tree/main/documentation/browser/solana.md)
|
|
55
|
+
[***Stellar***](https://github.com/allbridge-io/allbridge-core-js-sdk/tree/main/documentation/browser/stellar.md)
|
|
56
|
+
[***Tron***](https://github.com/allbridge-io/allbridge-core-js-sdk/tree/main/documentation/browser/tron.md)
|
|
52
57
|
|
|
53
58
|
### 1. Initialize SDK
|
|
54
59
|
|
|
@@ -83,15 +88,113 @@ const rawTx = await sdk.bridge.rawTxBuilder.send(sendParams, provider);
|
|
|
83
88
|
```ts
|
|
84
89
|
const supportedChains = await sdk.chainDetailsMap();
|
|
85
90
|
// extract information about ETH chain
|
|
86
|
-
const {
|
|
91
|
+
const {tokens, chainId, name, oftBridgeAddress} = supportedChains[ChainSymbol.ETH];
|
|
87
92
|
// Choose one of the tokens supported on ETH
|
|
88
|
-
const
|
|
93
|
+
const usdcOnEthToken = tokens.find(token => token.symbol === 'USDC');
|
|
89
94
|
```
|
|
90
95
|
|
|
91
|
-
|
|
96
|
+
Every token is returned as a `TokenWithChainDetails` object. Besides the general token data (`symbol`, `name`,
|
|
97
|
+
`decimals`, `tokenAddress`) it contains everything needed to find out which messengers the token can be sent with:
|
|
98
|
+
|
|
99
|
+
| Field | Present when | Meaning |
|
|
100
|
+
|-----------------------------------|------------------------------------|----------------------------------------------------------------------------------|
|
|
101
|
+
| `cctpAddress`, `cctpFeeShare` | token is supported by CCTP | CCTP bridge contract address (the approve spender) and CCTP fee share |
|
|
102
|
+
| `cctpV2Address`, `cctpV2FeeShare` | token is supported by CCTP V2 | CCTP V2 bridge contract address (the approve spender) and CCTP V2 fee share |
|
|
103
|
+
| `oftId`, `oftBridgeAddress` | token / chain is supported by OFT | Id shared by the same token on different chains, OFT bridge contract address |
|
|
104
|
+
| `xReserve` | token is supported by xReserve | xReserve bridge contract address (the approve spender), `feeShare` and `feeConst` |
|
|
105
|
+
| `transferTime` | always | Average transfer time to other chains, per messenger |
|
|
106
|
+
| `abrPayer` | chain supports paying fees in ABR | ABR payer contract address and per-messenger availability |
|
|
107
|
+
|
|
108
|
+
### 3. Choose a messenger
|
|
109
|
+
|
|
110
|
+
Every transfer is executed by one of the supported messengers (bridging protocols).
|
|
111
|
+
The messenger is a required parameter of all route-dependent SDK methods:
|
|
112
|
+
`bridge.checkAllowance`, `bridge.rawTxBuilder.approve`, `bridge.rawTxBuilder.send`, `getAmountToBeReceived`,
|
|
113
|
+
`getAmountToSend`, `getGasFeeOptions`, `getExtraGasMaxLimits` and `getAverageTransferTime`.
|
|
114
|
+
|
|
115
|
+
| Messenger | Protocol | Route is supported when |
|
|
116
|
+
|-----------------------|----------------|--------------------------------------------------------------------------------------------------------|
|
|
117
|
+
| `Messenger.CCTP` | Circle CCTP | `cctpAddress` is defined on both source and destination tokens |
|
|
118
|
+
| `Messenger.CCTP_V2` | Circle CCTP V2 | `cctpV2Address` is defined on both source and destination tokens |
|
|
119
|
+
| `Messenger.OFT` | LayerZero OFT | `oftId` is the same on source and destination tokens and `oftBridgeAddress` is defined on both chains |
|
|
120
|
+
| `Messenger.X_RESERVE` | xReserve | `xReserve` is defined on both source and destination tokens |
|
|
121
|
+
|
|
122
|
+
`Messenger.ALLBRIDGE` and `Messenger.WORMHOLE` are deprecated and must not be used.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import {Messenger} from "@allbridge/bridge-core-sdk";
|
|
126
|
+
|
|
127
|
+
function getAvailableMessengers(sourceToken: TokenWithChainDetails, destinationToken: TokenWithChainDetails): Messenger[] {
|
|
128
|
+
const messengers: Messenger[] = [];
|
|
129
|
+
if (sourceToken.cctpAddress && destinationToken.cctpAddress) {
|
|
130
|
+
messengers.push(Messenger.CCTP);
|
|
131
|
+
}
|
|
132
|
+
if (sourceToken.cctpV2Address && destinationToken.cctpV2Address) {
|
|
133
|
+
messengers.push(Messenger.CCTP_V2);
|
|
134
|
+
}
|
|
135
|
+
if (
|
|
136
|
+
sourceToken.oftId &&
|
|
137
|
+
sourceToken.oftId === destinationToken.oftId &&
|
|
138
|
+
sourceToken.oftBridgeAddress &&
|
|
139
|
+
destinationToken.oftBridgeAddress
|
|
140
|
+
) {
|
|
141
|
+
messengers.push(Messenger.OFT);
|
|
142
|
+
}
|
|
143
|
+
if (sourceToken.xReserve && destinationToken.xReserve) {
|
|
144
|
+
messengers.push(Messenger.X_RESERVE);
|
|
145
|
+
}
|
|
146
|
+
return messengers;
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`getAverageTransferTime` returns `null` when the messenger is not available between the source and destination chains,
|
|
151
|
+
so it can be used as an additional check. If a messenger is not supported for the chosen route, the SDK methods throw
|
|
152
|
+
`CCTPDoesNotSupportedError`, `OFTDoesNotSupportedError` or `SdkError` (for xReserve).
|
|
153
|
+
|
|
154
|
+
***TIP:***
|
|
155
|
+
For more details, see [***Example***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/get-available-messengers.ts)
|
|
156
|
+
|
|
157
|
+
#### CCTP and CCTP V2
|
|
158
|
+
|
|
159
|
+
Native USDC transfers through Circle CCTP.
|
|
160
|
+
The bridge contract that has to be approved is `token.cctpAddress` (CCTP) or `token.cctpV2Address` (CCTP V2).
|
|
161
|
+
The fee is a share of the transferred amount, see `token.cctpFeeShare` / `token.cctpV2FeeShare`;
|
|
162
|
+
use [`getAmountToBeReceived`](#calculating-amount-of-tokens-to-be-received-after-fee) to get the exact result.
|
|
163
|
+
|
|
164
|
+
Examples:
|
|
165
|
+
[***EVM (CCTP)***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/send-by-cctp.ts),
|
|
166
|
+
[***EVM (CCTP V2)***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/evm/evm-build-send-tx.ts),
|
|
167
|
+
[***EVM (CCTP V2, gas fee paid with stablecoin)***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/evm/evm-build-send-tx-gas-fee-with-stables.ts),
|
|
168
|
+
[***Solana***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/solana/sol-build-send-tx-cctp.ts),
|
|
169
|
+
[***Sui***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/sui/sui-build-send-tx.ts)
|
|
170
|
+
|
|
171
|
+
#### OFT
|
|
172
|
+
|
|
173
|
+
Transfers through LayerZero OFT. Tokens on different chains are linked by `token.oftId`.
|
|
174
|
+
The bridge contract that has to be approved is `oftBridgeAddress` of the source chain.
|
|
175
|
+
The fee share is provided by the Allbridge Core API for the route,
|
|
176
|
+
use [`getAmountToBeReceived`](#calculating-amount-of-tokens-to-be-received-after-fee) to get the exact result.
|
|
177
|
+
|
|
178
|
+
Examples:
|
|
179
|
+
[***Tron***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/trx/trx-build-send-tx.ts),
|
|
180
|
+
[***Tron (gas fee paid with stablecoin)***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/trx/trx-build-send-tx-gas-fee-with-stables.ts)
|
|
181
|
+
|
|
182
|
+
#### X_RESERVE
|
|
183
|
+
|
|
184
|
+
Transfers through the xReserve protocol. The route configuration is in `token.xReserve`:
|
|
185
|
+
`bridgeAddress` is the contract that has to be approved, `feeShare` and `feeConst` describe the fee.
|
|
186
|
+
Because of the constant part of the fee there is a minimum transfer amount;
|
|
187
|
+
`getAmountToBeReceived` throws an `SdkError` with the minimum amount if the amount is too low.
|
|
188
|
+
Extra gas is not supported by this messenger: `getExtraGasMaxLimits` returns zero limits.
|
|
189
|
+
|
|
190
|
+
Examples:
|
|
191
|
+
[***Stacks***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/stx/stx-build-send-tx.ts)
|
|
192
|
+
|
|
193
|
+
### 4.1 Approve the transfer of tokens (only for Evm, Tron)
|
|
92
194
|
|
|
93
195
|
Before sending tokens, the bridge has to be authorized to use the tokens of the owner.
|
|
94
|
-
This is done by building the `approve` transaction with SDK instance
|
|
196
|
+
This is done by building the `approve` transaction with SDK instance.
|
|
197
|
+
The spender depends on the messenger, so the `messenger` parameter is required.</p>
|
|
95
198
|
For Ethereum USDT - due to specificity of the USDT contract:<br/>
|
|
96
199
|
If the current allowance is not 0,
|
|
97
200
|
this function will perform an additional transaction to set allowance to 0 before setting the new allowance value.
|
|
@@ -99,11 +202,23 @@ this function will perform an additional transaction to set allowance to 0 befor
|
|
|
99
202
|
```ts
|
|
100
203
|
const rawTx = await sdk.bridge.rawTxBuilder.approve({
|
|
101
204
|
token: sourceToken,
|
|
102
|
-
owner: accountAddress
|
|
205
|
+
owner: accountAddress,
|
|
206
|
+
messenger: Messenger.CCTP_V2,
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Use `bridge.checkAllowance` to find out whether the approval is already enough:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
const isApproved = await sdk.bridge.checkAllowance({
|
|
214
|
+
token: sourceToken,
|
|
215
|
+
owner: accountAddress,
|
|
216
|
+
amount: "1.01",
|
|
217
|
+
messenger: Messenger.CCTP_V2,
|
|
103
218
|
});
|
|
104
219
|
```
|
|
105
220
|
|
|
106
|
-
###
|
|
221
|
+
### 4.2 Send Tokens
|
|
107
222
|
|
|
108
223
|
Initiate the transfer of tokens with `send` method on SDK instance.
|
|
109
224
|
|
|
@@ -114,24 +229,25 @@ const rawTx = await sdk.bridge.rawTxBuilder.send({
|
|
|
114
229
|
toAccountAddress: toAddress,
|
|
115
230
|
sourceToken: sourceToken,
|
|
116
231
|
destinationToken: destinationToken,
|
|
117
|
-
messenger: Messenger.
|
|
232
|
+
messenger: Messenger.CCTP_V2,
|
|
118
233
|
});
|
|
119
234
|
```
|
|
120
235
|
|
|
121
236
|
### Full example
|
|
122
237
|
|
|
123
|
-
Swap USDC on ETH chain to USDC on
|
|
238
|
+
Swap USDC on ETH chain to USDC on ARB chain using CCTP V2
|
|
124
239
|
|
|
125
240
|
```ts
|
|
126
241
|
import {
|
|
127
242
|
AllbridgeCoreSdk,
|
|
128
243
|
ChainSymbol,
|
|
129
244
|
Messenger,
|
|
245
|
+
nodeRpcUrlsDefault,
|
|
246
|
+
RawEvmTransaction,
|
|
130
247
|
} from "@allbridge/bridge-core-sdk";
|
|
131
|
-
import Web3 from "web3";
|
|
132
248
|
import * as dotenv from "dotenv";
|
|
133
249
|
// Utils method
|
|
134
|
-
// For more details, see Examples (https://github.com/allbridge-
|
|
250
|
+
// For more details, see Examples (https://github.com/allbridge-io/allbridge-core-js-sdk/tree/main/examples)
|
|
135
251
|
// import { getEnvVar } from "../../../utils/env";
|
|
136
252
|
// import { sendEvmRawTransaction } from "../../../utils/web3";
|
|
137
253
|
// import { ensure } from "../../../utils/utils";
|
|
@@ -139,60 +255,56 @@ import * as dotenv from "dotenv";
|
|
|
139
255
|
dotenv.config({path: ".env"});
|
|
140
256
|
|
|
141
257
|
async function runExample() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
console.log("Approve tx id:", approveTxReceipt.transactionHash);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// initiate transfer
|
|
169
|
-
const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send({
|
|
170
|
-
amount: amount,
|
|
171
|
-
fromAccountAddress: fromAddress,
|
|
172
|
-
toAccountAddress: toAddress,
|
|
173
|
-
sourceToken: sourceToken,
|
|
174
|
-
destinationToken: destinationToken,
|
|
175
|
-
messenger: Messenger.ALLBRIDGE,
|
|
258
|
+
const fromAddress = getEnvVar("ETH_ACCOUNT_ADDRESS"); // sender address
|
|
259
|
+
const toAddress = getEnvVar("ARB_ACCOUNT_ADDRESS"); // recipient address
|
|
260
|
+
|
|
261
|
+
const sdk = new AllbridgeCoreSdk({ ...nodeRpcUrlsDefault, ETH: getEnvVar("WEB3_PROVIDER_URL") });
|
|
262
|
+
|
|
263
|
+
const chains = await sdk.chainDetailsMap();
|
|
264
|
+
|
|
265
|
+
const sourceChain = chains[ChainSymbol.ETH];
|
|
266
|
+
const sourceToken = ensure(sourceChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC"));
|
|
267
|
+
|
|
268
|
+
const destinationChain = chains[ChainSymbol.ARB];
|
|
269
|
+
const destinationToken = ensure(destinationChain.tokens.find((tokenInfo) => tokenInfo.symbol === "USDC"));
|
|
270
|
+
|
|
271
|
+
const amount = "1.01";
|
|
272
|
+
const messenger = Messenger.CCTP_V2;
|
|
273
|
+
|
|
274
|
+
//check if sending tokens already approved
|
|
275
|
+
if (!(await sdk.bridge.checkAllowance({ token: sourceToken, owner: fromAddress, amount, messenger }))) {
|
|
276
|
+
// authorize the bridge to transfer tokens from sender's address
|
|
277
|
+
const rawTransactionApprove = (await sdk.bridge.rawTxBuilder.approve({
|
|
278
|
+
token: sourceToken,
|
|
279
|
+
owner: fromAddress,
|
|
280
|
+
messenger,
|
|
176
281
|
})) as RawEvmTransaction;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
console.log("tx id:", txReceipt.transactionHash);
|
|
282
|
+
const approveTxReceipt = await sendEvmRawTransaction(rawTransactionApprove);
|
|
283
|
+
console.log("Approve tx id:", approveTxReceipt.transactionHash);
|
|
180
284
|
}
|
|
181
285
|
|
|
286
|
+
// initiate transfer
|
|
287
|
+
const rawTransactionTransfer = (await sdk.bridge.rawTxBuilder.send({
|
|
288
|
+
amount: amount,
|
|
289
|
+
fromAccountAddress: fromAddress,
|
|
290
|
+
toAccountAddress: toAddress,
|
|
291
|
+
sourceToken: sourceToken,
|
|
292
|
+
destinationToken: destinationToken,
|
|
293
|
+
messenger,
|
|
294
|
+
})) as RawEvmTransaction;
|
|
295
|
+
console.log(`Sending ${amount} ${sourceToken.symbol}`);
|
|
296
|
+
const txReceipt = await sendEvmRawTransaction(rawTransactionTransfer);
|
|
297
|
+
console.log("tx id:", txReceipt.transactionHash);
|
|
298
|
+
}
|
|
299
|
+
|
|
182
300
|
runExample();
|
|
183
301
|
```
|
|
184
302
|
|
|
185
303
|
***TIP:***
|
|
186
|
-
For more details, see [***Examples***](https://github.com/allbridge-
|
|
304
|
+
For more details, see [***Examples***](https://github.com/allbridge-io/allbridge-core-js-sdk/tree/main/examples)
|
|
187
305
|
|
|
188
306
|
## Other operations
|
|
189
307
|
|
|
190
|
-
### Liquidity pools operations
|
|
191
|
-
|
|
192
|
-
SDK supports operation with **Liquidity Pools**<br/>
|
|
193
|
-
For more details, see [
|
|
194
|
-
***Examples***](https://github.com/allbridge-public/allbridge-core-js-sdk/tree/main/examples/src/examples/liquidity-pool)
|
|
195
|
-
|
|
196
308
|
### Transaction builder
|
|
197
309
|
|
|
198
310
|
#### Approve Transaction
|
|
@@ -213,7 +325,7 @@ const rawTransactionSend = await sdk.bridge.rawTxBuilder.send(sendParams);
|
|
|
213
325
|
|
|
214
326
|
***TIP:***
|
|
215
327
|
For more details, see [***Example
|
|
216
|
-
***](https://github.com/allbridge-
|
|
328
|
+
***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/solana/sol-build-send-tx-cctp.ts)
|
|
217
329
|
|
|
218
330
|
### Get information about sent transaction
|
|
219
331
|
|
|
@@ -226,13 +338,14 @@ const transferStatus = await sdk.getTransferStatus(chainSymbol, txId);
|
|
|
226
338
|
### Calculating amount of tokens to be received after fee
|
|
227
339
|
|
|
228
340
|
SDK method `getAmountToBeReceived` can be used to calculate the amount of tokens the receiving party will get after
|
|
229
|
-
applying the bridging fee.
|
|
341
|
+
applying the bridging fee of the chosen messenger.
|
|
230
342
|
|
|
231
343
|
```ts
|
|
232
344
|
const amountToBeReceived = await sdk.getAmountToBeReceived(
|
|
233
345
|
amountToSend,
|
|
234
346
|
sourceToken,
|
|
235
|
-
destinationToken
|
|
347
|
+
destinationToken,
|
|
348
|
+
Messenger.CCTP_V2
|
|
236
349
|
);
|
|
237
350
|
```
|
|
238
351
|
|
|
@@ -245,28 +358,35 @@ tokens the receiving party should get.
|
|
|
245
358
|
const amountToSend = await sdk.getAmountToSend(
|
|
246
359
|
amountToBeReceived,
|
|
247
360
|
sourceToken,
|
|
248
|
-
destinationToken
|
|
361
|
+
destinationToken,
|
|
362
|
+
Messenger.CCTP_V2
|
|
249
363
|
);
|
|
250
364
|
```
|
|
251
365
|
|
|
366
|
+
***TIP:***
|
|
367
|
+
For more details, see [***Example***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/calculate-amounts.ts)
|
|
368
|
+
|
|
252
369
|
### Getting the amount of gas fee
|
|
253
370
|
|
|
254
371
|
The SDK method `getGasFeeOptions` allows to retrieve information about the available methods to pay the gas fee,
|
|
255
372
|
as well as the amount of gas fee needed to complete a transfer on the destination chain.
|
|
256
|
-
Gas fee is paid during the [send](#
|
|
257
|
-
and can be paid either in the source chain's currency or in
|
|
373
|
+
Gas fee is paid during the [send](#42-send-tokens) operation
|
|
374
|
+
and can be paid either in the source chain's currency, in source tokens or in ABR tokens
|
|
375
|
+
(see `gasFeePaymentMethod` in `SendParams`).
|
|
258
376
|
|
|
259
|
-
The method returns an object with
|
|
377
|
+
The method returns an object with the following properties:
|
|
260
378
|
|
|
261
379
|
- native: The amount of gas fee, denominated in unit of the source chain currency (e.g. wei for Ethereum).
|
|
262
380
|
- stablecoin: (optional) The amount of gas fee, denominated in unit of the source token.
|
|
263
381
|
If this property is not present, it indicates that the stablecoin payment method is not available.
|
|
382
|
+
- abr: (optional) The amount of gas fee, denominated in unit of the ABR token.
|
|
383
|
+
Present only if the source chain has `abrPayer` and the chosen messenger is available for ABR payments.
|
|
264
384
|
|
|
265
385
|
```ts
|
|
266
|
-
const {native, stablecoin} = await sdk.getGasFeeOptions(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
Messenger.
|
|
386
|
+
const {native, stablecoin, abr} = await sdk.getGasFeeOptions(
|
|
387
|
+
usdcOnEthToken, // from ETH
|
|
388
|
+
usdcOnArbToken, // to ARB
|
|
389
|
+
Messenger.CCTP_V2
|
|
270
390
|
);
|
|
271
391
|
console.log(native);
|
|
272
392
|
// Output:
|
|
@@ -278,20 +398,37 @@ console.log(stablecoin);
|
|
|
278
398
|
// Output:
|
|
279
399
|
// {
|
|
280
400
|
// int: "10010000",
|
|
281
|
-
// float: "10.01" // (10.01
|
|
401
|
+
// float: "10.01" // (10.01 USDC)
|
|
282
402
|
// }
|
|
283
403
|
```
|
|
284
404
|
|
|
405
|
+
### Getting the maximum amount of extra gas
|
|
406
|
+
|
|
407
|
+
Extra gas is an additional amount of the destination chain currency that can be delivered together with the transfer
|
|
408
|
+
(see `extraGas` in `SendParams`). SDK method `getExtraGasMaxLimits` returns the maximum extra gas value for every
|
|
409
|
+
gas fee payment method, as well as the maximum amount that can be received on the destination chain.
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
const extraGasLimits = await sdk.getExtraGasMaxLimits(
|
|
413
|
+
sourceToken,
|
|
414
|
+
destinationToken,
|
|
415
|
+
Messenger.CCTP_V2
|
|
416
|
+
);
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
***TIP:***
|
|
420
|
+
For more details, see [***Example***](https://github.com/allbridge-io/allbridge-core-js-sdk/blob/main/examples/src/examples/bridge/get-extra-gas-max-limits.ts)
|
|
421
|
+
|
|
285
422
|
### Getting the average transfer time
|
|
286
423
|
|
|
287
424
|
SDK method `getAverageTransferTime` can be used to get the average time in ms it takes to complete a transfer for a
|
|
288
|
-
given combination of tokens and messenger.
|
|
425
|
+
given combination of tokens and messenger. Returns `null` if the messenger is not supported for the route.
|
|
289
426
|
|
|
290
427
|
```ts
|
|
291
428
|
const transferTimeMs = sdk.getAverageTransferTime(
|
|
292
429
|
sourceToken,
|
|
293
430
|
destinationToken,
|
|
294
|
-
Messenger.
|
|
431
|
+
Messenger.CCTP_V2
|
|
295
432
|
);
|
|
296
433
|
```
|
|
297
434
|
|