@hyperbridge/sdk 1.4.10 → 1.5.0-rc0000000001
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 +102 -3
- package/dist/browser/index.d.ts +160 -2
- package/dist/browser/index.js +250 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +160 -2
- package/dist/node/index.js +256 -7
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { ConsolaInstance } from 'consola';
|
|
|
2
2
|
import { GraphQLClient } from 'graphql-request';
|
|
3
3
|
import { PublicClient, Hex, ContractFunctionArgs, Log } from 'viem';
|
|
4
4
|
import { ApiPromise } from '@polkadot/api';
|
|
5
|
-
import { SignerOptions } from '@polkadot/api/types';
|
|
5
|
+
import { SignerOptions, SubmittableExtrinsic } from '@polkadot/api/types';
|
|
6
|
+
import { ISubmittableResult } from '@polkadot/types/types';
|
|
6
7
|
import { Chain } from 'viem/chains';
|
|
7
8
|
|
|
8
9
|
declare const _default: {
|
|
@@ -590,6 +591,7 @@ declare class ChainConfigService {
|
|
|
590
591
|
constructor(env?: NodeJS.ProcessEnv);
|
|
591
592
|
getChainConfig(chain: string): ChainConfig;
|
|
592
593
|
getIntentGatewayAddress(chain: string): `0x${string}`;
|
|
594
|
+
getTokenGatewayAddress(chain: string): `0x${string}`;
|
|
593
595
|
getHostAddress(chain: string): `0x${string}`;
|
|
594
596
|
getWrappedNativeAssetWithDecimals(chain: string): {
|
|
595
597
|
asset: HexString;
|
|
@@ -3179,6 +3181,124 @@ type CancelEvent = {
|
|
|
3179
3181
|
};
|
|
3180
3182
|
}[keyof CancelEventMap];
|
|
3181
3183
|
|
|
3184
|
+
/**
|
|
3185
|
+
* Result of the quoteNative fee estimation
|
|
3186
|
+
*/
|
|
3187
|
+
interface QuoteNativeResult {
|
|
3188
|
+
/** Total native token cost including relayer fee and protocol fee with 1% buffer */
|
|
3189
|
+
totalNativeCost: bigint;
|
|
3190
|
+
/** Relayer fee converted to source chain fee token */
|
|
3191
|
+
relayerFeeInSourceFeeToken: bigint;
|
|
3192
|
+
}
|
|
3193
|
+
/**
|
|
3194
|
+
* Parameters for token gateway teleport operations
|
|
3195
|
+
*/
|
|
3196
|
+
interface TeleportParams {
|
|
3197
|
+
/** Amount to be sent */
|
|
3198
|
+
amount: bigint;
|
|
3199
|
+
/** The token identifier to send */
|
|
3200
|
+
assetId: HexString;
|
|
3201
|
+
/** Redeem ERC20 on the destination? */
|
|
3202
|
+
redeem: boolean;
|
|
3203
|
+
/** Recipient address */
|
|
3204
|
+
to: HexString;
|
|
3205
|
+
/** Recipient state machine */
|
|
3206
|
+
dest: string | Uint8Array;
|
|
3207
|
+
/** Request timeout in seconds */
|
|
3208
|
+
timeout: bigint;
|
|
3209
|
+
/** Destination contract call data */
|
|
3210
|
+
data?: HexString | Uint8Array;
|
|
3211
|
+
}
|
|
3212
|
+
/**
|
|
3213
|
+
* TokenGateway class for managing cross-chain token transfers via Hyperbridge
|
|
3214
|
+
*
|
|
3215
|
+
* This class provides methods to interact with the TokenGateway contract, including
|
|
3216
|
+
* estimating fees for cross-chain token teleports.
|
|
3217
|
+
*
|
|
3218
|
+
* Supports both EVM and Substrate chains as destination.
|
|
3219
|
+
*
|
|
3220
|
+
* @example
|
|
3221
|
+
* ```typescript
|
|
3222
|
+
* const tokenGateway = new TokenGateway({
|
|
3223
|
+
* source: sourceChain,
|
|
3224
|
+
* dest: destChain // Can be EvmChain or SubstrateChain
|
|
3225
|
+
* })
|
|
3226
|
+
*
|
|
3227
|
+
* const teleportParams: TeleportParams = {
|
|
3228
|
+
* amount: parseEther("1.0"),
|
|
3229
|
+
* assetId: keccak256(toHex("USDC")),
|
|
3230
|
+
* redeem: true,
|
|
3231
|
+
* to: pad("0xRecipientAddress", { size: 32 }),
|
|
3232
|
+
* dest: "EVM-1",
|
|
3233
|
+
* timeout: 3600n,
|
|
3234
|
+
* }
|
|
3235
|
+
*
|
|
3236
|
+
* // Estimate native cost (relayer fee + protocol fee with 1% buffer)
|
|
3237
|
+
* const { totalNativeCost, relayerFeeInSourceFeeToken } = await tokenGateway.quoteNative(teleportParams)
|
|
3238
|
+
* console.log(`Total native cost: ${formatEther(totalNativeCost)} ETH`)
|
|
3239
|
+
* console.log(`Relayer fee in fee token: ${relayerFeeInSourceFeeToken}`)
|
|
3240
|
+
* ```
|
|
3241
|
+
*/
|
|
3242
|
+
declare class TokenGateway {
|
|
3243
|
+
private readonly source;
|
|
3244
|
+
private readonly dest;
|
|
3245
|
+
constructor(params: {
|
|
3246
|
+
source: EvmChain;
|
|
3247
|
+
dest: EvmChain | SubstrateChain;
|
|
3248
|
+
});
|
|
3249
|
+
/**
|
|
3250
|
+
* Get the TokenGateway contract address for a given chain
|
|
3251
|
+
*
|
|
3252
|
+
* @param chain - The chain identifier (e.g., "EVM-1", "EVM-56")
|
|
3253
|
+
* @returns The TokenGateway contract address
|
|
3254
|
+
*/
|
|
3255
|
+
private getTokenGatewayAddress;
|
|
3256
|
+
/**
|
|
3257
|
+
* Estimate the native token cost for a token gateway teleport operation.
|
|
3258
|
+
* This includes both relayer fees and protocol fees for cross-chain delivery.
|
|
3259
|
+
*
|
|
3260
|
+
* The relayer fee is automatically estimated for EVM destination chains by:
|
|
3261
|
+
* 1. Creating a dummy post request with 191 bytes of random data in the body
|
|
3262
|
+
* 2. Estimating gas for delivery on the destination chain
|
|
3263
|
+
* 3. Converting the gas estimate to native tokens
|
|
3264
|
+
* 4. Adding a 1% buffer to the relayer fee for safety margin
|
|
3265
|
+
*
|
|
3266
|
+
* For non-EVM destination chains, the relayer fee is set to zero.
|
|
3267
|
+
*
|
|
3268
|
+
* The function then constructs a proper post request and calls quoteNative on the
|
|
3269
|
+
* source chain to get protocol fees (with 1% buffer), converts the relayer fee to
|
|
3270
|
+
* source chain fee token using Uniswap V2's getAmountsOut, and returns both values.
|
|
3271
|
+
*
|
|
3272
|
+
* @param params - The teleport parameters
|
|
3273
|
+
* @returns Object containing totalNativeCost (with 1% buffer) and relayerFeeInSourceFeeToken
|
|
3274
|
+
*
|
|
3275
|
+
* @throws Will throw an error if the contract call fails
|
|
3276
|
+
*
|
|
3277
|
+
* @example
|
|
3278
|
+
* ```typescript
|
|
3279
|
+
* const params: TeleportParams = {
|
|
3280
|
+
* amount: parseEther("1.0"),
|
|
3281
|
+
* assetId: keccak256(toHex("USDC")),
|
|
3282
|
+
* redeem: true,
|
|
3283
|
+
* to: pad("0xRecipientAddress", { size: 32 }),
|
|
3284
|
+
* dest: "EVM-1",
|
|
3285
|
+
* timeout: 3600n,
|
|
3286
|
+
* data: "0x"
|
|
3287
|
+
* }
|
|
3288
|
+
*
|
|
3289
|
+
* const { totalNativeCost, relayerFeeInSourceFeeToken } = await tokenGateway.quoteNative(params)
|
|
3290
|
+
* console.log(`Total native cost: ${formatEther(totalNativeCost)} ETH`)
|
|
3291
|
+
* console.log(`Relayer fee in fee token: ${relayerFeeInSourceFeeToken}`)
|
|
3292
|
+
* ```
|
|
3293
|
+
*/
|
|
3294
|
+
quoteNative(params: TeleportParams): Promise<QuoteNativeResult>;
|
|
3295
|
+
/**
|
|
3296
|
+
* Convert native token amount to fee token amount using Uniswap V2 router
|
|
3297
|
+
* @private
|
|
3298
|
+
*/
|
|
3299
|
+
private convertNativeToFeeToken;
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3182
3302
|
/**
|
|
3183
3303
|
* Extracts the IntentGateway OrderPlaced event from a transaction hash.
|
|
3184
3304
|
* @param client - A viem PublicClient-compatible instance
|
|
@@ -3373,6 +3493,44 @@ declare function teleport(teleport_param: {
|
|
|
3373
3493
|
apiPromise: ApiPromise;
|
|
3374
3494
|
options: Partial<SignerOptions>;
|
|
3375
3495
|
}): Promise<ReadableStream<HyperbridgeTxEvents>>;
|
|
3496
|
+
/**
|
|
3497
|
+
* Teleports assets from Substrate to other chains via the token gateway
|
|
3498
|
+
*
|
|
3499
|
+
* Note: There is no guarantee that both Dispatched and Finalized events will be yielded.
|
|
3500
|
+
* Consumers should listen for either one of these events instead of expecting both.
|
|
3501
|
+
*
|
|
3502
|
+
*
|
|
3503
|
+
* @param apiPromise - Polkadot API instance
|
|
3504
|
+
* @param params - Teleport parameters
|
|
3505
|
+
* @param params.symbol - Asset symbol
|
|
3506
|
+
* @param params.destination - Target state machine ID
|
|
3507
|
+
* @param params.recipient - Recipient address
|
|
3508
|
+
* @param params.amount - Amount to teleport
|
|
3509
|
+
* @param params.timeout - Operation timeout
|
|
3510
|
+
* @param params.tokenGatewayAddress - Gateway contract address
|
|
3511
|
+
* @param params.relayerFee - Fee for the relayer
|
|
3512
|
+
* @param params.redeem - Whether to redeem on arrival
|
|
3513
|
+
* @param params.callData - Optional additional call data
|
|
3514
|
+
* @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
|
|
3515
|
+
* @throws Error when asset ID is unknown or transaction fails
|
|
3516
|
+
*/
|
|
3517
|
+
declare function makeTeleportExtrinsics(teleport_param: {
|
|
3518
|
+
params: Params;
|
|
3519
|
+
apiPromise: ApiPromise;
|
|
3520
|
+
}): Promise<SubmittableExtrinsic<"promise", ISubmittableResult>>;
|
|
3521
|
+
/**
|
|
3522
|
+
*
|
|
3523
|
+
* @param extrinsic - SubmittableExtrinsic
|
|
3524
|
+
* @param who - SS58Address
|
|
3525
|
+
* @param options - Signer options
|
|
3526
|
+
* @returns
|
|
3527
|
+
*/
|
|
3528
|
+
declare function submitExtrinsics({ extrinsics: tx, who, options, apiPromise, }: {
|
|
3529
|
+
extrinsics: SubmittableExtrinsic<"promise", any>;
|
|
3530
|
+
apiPromise: ApiPromise;
|
|
3531
|
+
who: string;
|
|
3532
|
+
options: Partial<SignerOptions>;
|
|
3533
|
+
}): ReadableStream<HyperbridgeTxEvents>;
|
|
3376
3534
|
|
|
3377
3535
|
declare enum Chains {
|
|
3378
3536
|
BSC_CHAPEL = "EVM-97",
|
|
@@ -3511,4 +3669,4 @@ declare const popularTokens: {
|
|
|
3511
3669
|
"EVM-130": string[];
|
|
3512
3670
|
};
|
|
3513
3671
|
|
|
3514
|
-
export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, type Transaction, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
|
|
3672
|
+
export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchPost, ERC20Method, type EstimateGasCallData, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, type QuoteNativeResult, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, SubstrateChain, TESTNET_CHAINS, type TeleportParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, TokenGateway, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type TokenRegistry, type TokenRegistryResponse, type Transaction, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, makeTeleportExtrinsics, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, submitExtrinsics, teleport, teleportDot, viemChains };
|
package/dist/node/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { TextDecoder as TextDecoder$1, TextEncoder as TextEncoder$1 } from 'util';
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { TextDecoder as TextDecoder$1, TextEncoder as TextEncoder$1 } from 'node:util';
|
|
4
4
|
import { createConsola, LogLevels } from 'consola';
|
|
5
5
|
import { flatten, zip, capitalize, maxBy, isNil } from 'lodash-es';
|
|
6
6
|
import { toHex, hexToBytes, encodePacked, keccak256, encodeAbiParameters, bytesToHex, concatHex, createPublicClient, http, encodeFunctionData, erc20Abi, bytesToBigInt, pad, toBytes, maxUint256, formatUnits, parseUnits, hexToString as hexToString$1, parseEventLogs, parseAbiParameters, parseAbiItem } from 'viem';
|
|
@@ -176,11 +176,11 @@ function __wbindgen_throw(arg0, arg1) {
|
|
|
176
176
|
function init() {
|
|
177
177
|
console.log("CKB MMR WASM initialized");
|
|
178
178
|
}
|
|
179
|
-
var wasm, full_path, __dirname
|
|
179
|
+
var wasm, full_path, __dirname, cachedTextDecoder, cachedUint8ArrayMemory0, WASM_VECTOR_LEN, cachedTextEncoder, encodeString, cachedDataViewMemory0, KeccakMergeFinalization, KeccakMerge, wasmPath, wasmBytes, bindings, wasmModule, wasmInstance, __wasm;
|
|
180
180
|
var init_node = __esm({
|
|
181
181
|
"src/utils/ckb-mmr-wasm/dist/node/node.js"() {
|
|
182
182
|
full_path = import.meta.url.split("/").slice(1);
|
|
183
|
-
__dirname
|
|
183
|
+
__dirname = `${full_path.slice(0, full_path.length - 1).join("/")}/`;
|
|
184
184
|
cachedTextDecoder = new TextDecoder$1("utf-8", { ignoreBOM: true, fatal: true });
|
|
185
185
|
cachedTextDecoder.decode();
|
|
186
186
|
cachedUint8ArrayMemory0 = null;
|
|
@@ -212,7 +212,7 @@ var init_node = __esm({
|
|
|
212
212
|
wasm.__wbg_keccakmerge_free(ptr, 0);
|
|
213
213
|
}
|
|
214
214
|
};
|
|
215
|
-
wasmPath = join(__dirname
|
|
215
|
+
wasmPath = join(__dirname, "./node_bg.wasm");
|
|
216
216
|
wasmBytes = readFileSync(wasmPath);
|
|
217
217
|
bindings = {
|
|
218
218
|
generate_root_with_proof,
|
|
@@ -3421,6 +3421,17 @@ var addresses = {
|
|
|
3421
3421
|
["EVM-137" /* POLYGON_MAINNET */]: "0x1a4ee689a004b10210a1df9f24a387ea13359acf",
|
|
3422
3422
|
["EVM-130" /* UNICHAIN_MAINNET */]: "0x1a4ee689a004b10210a1df9f24a387ea13359acf"
|
|
3423
3423
|
},
|
|
3424
|
+
TokenGateway: {
|
|
3425
|
+
["EVM-97" /* BSC_CHAPEL */]: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3426
|
+
["EVM-10200" /* GNOSIS_CHIADO */]: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3427
|
+
["EVM-11155111" /* SEPOLIA */]: "0xFcDa26cA021d5535C3059547390E6cCd8De7acA6",
|
|
3428
|
+
["EVM-1" /* MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3429
|
+
["EVM-56" /* BSC_MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3430
|
+
["EVM-42161" /* ARBITRUM_MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3431
|
+
["EVM-8453" /* BASE_MAINNET */]: "0xFd413e3AFe560182C4471F4d143A96d3e259B6dE",
|
|
3432
|
+
["EVM-137" /* POLYGON_MAINNET */]: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E",
|
|
3433
|
+
["EVM-130" /* UNICHAIN_MAINNET */]: "0x8b536105b6Fae2aE9199f5146D3C57Dfe53b614E"
|
|
3434
|
+
},
|
|
3424
3435
|
Host: {
|
|
3425
3436
|
["EVM-97" /* BSC_CHAPEL */]: "0x8Aa0Dea6D675d785A882967Bf38183f6117C09b7",
|
|
3426
3437
|
["EVM-10200" /* GNOSIS_CHIADO */]: "0x58a41b89f4871725e5d898d98ef4bf917601c5eb",
|
|
@@ -3612,6 +3623,9 @@ var ChainConfigService = class {
|
|
|
3612
3623
|
getIntentGatewayAddress(chain) {
|
|
3613
3624
|
return addresses.IntentGateway[chain];
|
|
3614
3625
|
}
|
|
3626
|
+
getTokenGatewayAddress(chain) {
|
|
3627
|
+
return addresses.TokenGateway[chain];
|
|
3628
|
+
}
|
|
3615
3629
|
getHostAddress(chain) {
|
|
3616
3630
|
return addresses.Host[chain];
|
|
3617
3631
|
}
|
|
@@ -13137,6 +13151,140 @@ async function fetchSourceProof(commitment, source, sourceStateMachine, sourceCo
|
|
|
13137
13151
|
proof: proofHex
|
|
13138
13152
|
};
|
|
13139
13153
|
}
|
|
13154
|
+
var TokenGateway = class {
|
|
13155
|
+
source;
|
|
13156
|
+
dest;
|
|
13157
|
+
constructor(params) {
|
|
13158
|
+
this.source = params.source;
|
|
13159
|
+
this.dest = params.dest;
|
|
13160
|
+
}
|
|
13161
|
+
/**
|
|
13162
|
+
* Get the TokenGateway contract address for a given chain
|
|
13163
|
+
*
|
|
13164
|
+
* @param chain - The chain identifier (e.g., "EVM-1", "EVM-56")
|
|
13165
|
+
* @returns The TokenGateway contract address
|
|
13166
|
+
*/
|
|
13167
|
+
getTokenGatewayAddress(chain) {
|
|
13168
|
+
const chainStr = typeof chain === "string" ? chain : new TextDecoder().decode(chain);
|
|
13169
|
+
return this.source.configService.getTokenGatewayAddress(chainStr);
|
|
13170
|
+
}
|
|
13171
|
+
/**
|
|
13172
|
+
* Estimate the native token cost for a token gateway teleport operation.
|
|
13173
|
+
* This includes both relayer fees and protocol fees for cross-chain delivery.
|
|
13174
|
+
*
|
|
13175
|
+
* The relayer fee is automatically estimated for EVM destination chains by:
|
|
13176
|
+
* 1. Creating a dummy post request with 191 bytes of random data in the body
|
|
13177
|
+
* 2. Estimating gas for delivery on the destination chain
|
|
13178
|
+
* 3. Converting the gas estimate to native tokens
|
|
13179
|
+
* 4. Adding a 1% buffer to the relayer fee for safety margin
|
|
13180
|
+
*
|
|
13181
|
+
* For non-EVM destination chains, the relayer fee is set to zero.
|
|
13182
|
+
*
|
|
13183
|
+
* The function then constructs a proper post request and calls quoteNative on the
|
|
13184
|
+
* source chain to get protocol fees (with 1% buffer), converts the relayer fee to
|
|
13185
|
+
* source chain fee token using Uniswap V2's getAmountsOut, and returns both values.
|
|
13186
|
+
*
|
|
13187
|
+
* @param params - The teleport parameters
|
|
13188
|
+
* @returns Object containing totalNativeCost (with 1% buffer) and relayerFeeInSourceFeeToken
|
|
13189
|
+
*
|
|
13190
|
+
* @throws Will throw an error if the contract call fails
|
|
13191
|
+
*
|
|
13192
|
+
* @example
|
|
13193
|
+
* ```typescript
|
|
13194
|
+
* const params: TeleportParams = {
|
|
13195
|
+
* amount: parseEther("1.0"),
|
|
13196
|
+
* assetId: keccak256(toHex("USDC")),
|
|
13197
|
+
* redeem: true,
|
|
13198
|
+
* to: pad("0xRecipientAddress", { size: 32 }),
|
|
13199
|
+
* dest: "EVM-1",
|
|
13200
|
+
* timeout: 3600n,
|
|
13201
|
+
* data: "0x"
|
|
13202
|
+
* }
|
|
13203
|
+
*
|
|
13204
|
+
* const { totalNativeCost, relayerFeeInSourceFeeToken } = await tokenGateway.quoteNative(params)
|
|
13205
|
+
* console.log(`Total native cost: ${formatEther(totalNativeCost)} ETH`)
|
|
13206
|
+
* console.log(`Relayer fee in fee token: ${relayerFeeInSourceFeeToken}`)
|
|
13207
|
+
* ```
|
|
13208
|
+
*/
|
|
13209
|
+
async quoteNative(params) {
|
|
13210
|
+
const dataHex = params.data ? typeof params.data === "string" ? params.data : toHex(params.data) : "0x";
|
|
13211
|
+
const sourceTokenGatewayAddress = this.getTokenGatewayAddress(this.source.config.stateMachineId);
|
|
13212
|
+
const destTokenGatewayAddress = this.getTokenGatewayAddress(params.dest);
|
|
13213
|
+
let relayerFee = 0n;
|
|
13214
|
+
const destChainId = typeof params.dest === "string" ? params.dest : new TextDecoder().decode(params.dest);
|
|
13215
|
+
const isEvmDest = destChainId.startsWith("EVM-") && this.dest instanceof EvmChain;
|
|
13216
|
+
if (isEvmDest) {
|
|
13217
|
+
const randomHex = "0x" + Array.from({ length: 191 * 2 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
13218
|
+
const randomBody = randomHex;
|
|
13219
|
+
const dummyPostRequest = {
|
|
13220
|
+
source: this.source.config.stateMachineId,
|
|
13221
|
+
dest: destChainId,
|
|
13222
|
+
from: sourceTokenGatewayAddress,
|
|
13223
|
+
to: destTokenGatewayAddress,
|
|
13224
|
+
nonce: 0n,
|
|
13225
|
+
body: randomBody,
|
|
13226
|
+
timeoutTimestamp: params.timeout
|
|
13227
|
+
};
|
|
13228
|
+
const { gas } = await this.dest.estimateGas(dummyPostRequest);
|
|
13229
|
+
const gasPrice = await this.dest.client.getGasPrice();
|
|
13230
|
+
const gasCostInNative = gas * gasPrice;
|
|
13231
|
+
relayerFee = gasCostInNative * 101n / 100n;
|
|
13232
|
+
}
|
|
13233
|
+
const teleportBody = encodeAbiParameters(
|
|
13234
|
+
parseAbiParameters("uint256, uint256, bytes32, bool, bytes32, bytes"),
|
|
13235
|
+
[
|
|
13236
|
+
params.amount,
|
|
13237
|
+
relayerFee,
|
|
13238
|
+
// Use the calculated relayer fee (0 for non-EVM destinations)
|
|
13239
|
+
params.assetId,
|
|
13240
|
+
params.redeem,
|
|
13241
|
+
params.to,
|
|
13242
|
+
dataHex
|
|
13243
|
+
]
|
|
13244
|
+
);
|
|
13245
|
+
const postRequest = {
|
|
13246
|
+
source: this.source.config.stateMachineId,
|
|
13247
|
+
dest: destChainId,
|
|
13248
|
+
from: sourceTokenGatewayAddress,
|
|
13249
|
+
to: destTokenGatewayAddress,
|
|
13250
|
+
nonce: 0n,
|
|
13251
|
+
body: teleportBody,
|
|
13252
|
+
timeoutTimestamp: params.timeout
|
|
13253
|
+
};
|
|
13254
|
+
const protocolFeeInNative = await this.source.quoteNative(postRequest, relayerFee);
|
|
13255
|
+
const protocolFeeWithBuffer = protocolFeeInNative * 101n / 100n;
|
|
13256
|
+
let relayerFeeInSourceFeeToken = 0n;
|
|
13257
|
+
if (relayerFee > 0n) {
|
|
13258
|
+
const feeToken = await this.source.getFeeTokenWithDecimals();
|
|
13259
|
+
relayerFeeInSourceFeeToken = await this.convertNativeToFeeToken(
|
|
13260
|
+
relayerFee,
|
|
13261
|
+
feeToken.address,
|
|
13262
|
+
this.source.config.stateMachineId
|
|
13263
|
+
);
|
|
13264
|
+
}
|
|
13265
|
+
return {
|
|
13266
|
+
totalNativeCost: protocolFeeWithBuffer,
|
|
13267
|
+
relayerFeeInSourceFeeToken
|
|
13268
|
+
};
|
|
13269
|
+
}
|
|
13270
|
+
/**
|
|
13271
|
+
* Convert native token amount to fee token amount using Uniswap V2 router
|
|
13272
|
+
* @private
|
|
13273
|
+
*/
|
|
13274
|
+
async convertNativeToFeeToken(nativeAmount, feeTokenAddress, chain) {
|
|
13275
|
+
const v2Router = this.source.configService.getUniswapRouterV2Address(chain);
|
|
13276
|
+
const WETH = this.source.configService.getWrappedNativeAssetWithDecimals(chain).asset;
|
|
13277
|
+
const v2AmountOut = await this.source.client.simulateContract({
|
|
13278
|
+
address: v2Router,
|
|
13279
|
+
abi: uniswapRouterV2_default.ABI,
|
|
13280
|
+
// @ts-ignore
|
|
13281
|
+
functionName: "getAmountsOut",
|
|
13282
|
+
// @ts-ignore
|
|
13283
|
+
args: [nativeAmount, [WETH, feeTokenAddress]]
|
|
13284
|
+
});
|
|
13285
|
+
return v2AmountOut.result[1];
|
|
13286
|
+
}
|
|
13287
|
+
};
|
|
13140
13288
|
async function getOrderPlacedFromTx(client, txHash) {
|
|
13141
13289
|
const receipt = await client.getTransactionReceipt({ hash: txHash });
|
|
13142
13290
|
const events = parseEventLogs({
|
|
@@ -13292,6 +13440,107 @@ function readIsmpCommitmentHash(events) {
|
|
|
13292
13440
|
}
|
|
13293
13441
|
}
|
|
13294
13442
|
}
|
|
13443
|
+
async function makeTeleportExtrinsics(teleport_param) {
|
|
13444
|
+
const { params, apiPromise } = teleport_param;
|
|
13445
|
+
const substrateComplianceAddr = (address, stateMachine) => {
|
|
13446
|
+
if (stateMachine.startsWith("EVM-")) return pad(address, { size: 32, dir: "left" });
|
|
13447
|
+
return address;
|
|
13448
|
+
};
|
|
13449
|
+
const assetId = keccakAsU8a(params.symbol);
|
|
13450
|
+
const scaleEncodedAssetId = await fetchLocalAssetId({ api: apiPromise, assetId });
|
|
13451
|
+
if (scaleEncodedAssetId === null) {
|
|
13452
|
+
throw new Error("Unknown asset id provided");
|
|
13453
|
+
}
|
|
13454
|
+
const destination = convertStateMachineIdToEnum(params.destination);
|
|
13455
|
+
const recipient = hexToBytes(substrateComplianceAddr(params.recipient, params.destination));
|
|
13456
|
+
const teleportParams = {
|
|
13457
|
+
destination,
|
|
13458
|
+
recepient: Array.from(recipient),
|
|
13459
|
+
amount: params.amount,
|
|
13460
|
+
timeout: BigInt(params.timeout),
|
|
13461
|
+
tokenGatewayAddress: Array.from(params.tokenGatewayAddress),
|
|
13462
|
+
relayerFee: BigInt(params.relayerFee),
|
|
13463
|
+
redeem: params.redeem,
|
|
13464
|
+
callData: params.callData ? Array.from(params.callData) : void 0
|
|
13465
|
+
};
|
|
13466
|
+
const encoded = TeleportParams.enc(teleportParams);
|
|
13467
|
+
const fullCallData = new Uint8Array([...scaleEncodedAssetId, ...encoded]);
|
|
13468
|
+
return apiPromise.tx.tokenGateway.teleport(fullCallData);
|
|
13469
|
+
}
|
|
13470
|
+
function submitExtrinsics({
|
|
13471
|
+
extrinsics: tx,
|
|
13472
|
+
who,
|
|
13473
|
+
options,
|
|
13474
|
+
apiPromise
|
|
13475
|
+
}) {
|
|
13476
|
+
let unsub = () => {
|
|
13477
|
+
};
|
|
13478
|
+
let closed = false;
|
|
13479
|
+
const stream = new ReadableStream(
|
|
13480
|
+
{
|
|
13481
|
+
async start(controller) {
|
|
13482
|
+
unsub = await tx.signAndSend(who, options, async (result) => {
|
|
13483
|
+
try {
|
|
13484
|
+
const { isInBlock, isError, dispatchError, txHash, isFinalized, status } = result;
|
|
13485
|
+
const events = result.events;
|
|
13486
|
+
if (isError) {
|
|
13487
|
+
console.error("Transaction failed: ", dispatchError);
|
|
13488
|
+
controller.enqueue({ kind: "Error", error: dispatchError });
|
|
13489
|
+
unsub?.();
|
|
13490
|
+
controller.close();
|
|
13491
|
+
closed = true;
|
|
13492
|
+
return;
|
|
13493
|
+
}
|
|
13494
|
+
if (status.type === "Ready") {
|
|
13495
|
+
controller.enqueue({
|
|
13496
|
+
kind: "Ready",
|
|
13497
|
+
transaction_hash: txHash.toHex()
|
|
13498
|
+
});
|
|
13499
|
+
}
|
|
13500
|
+
if (isInBlock || isFinalized) {
|
|
13501
|
+
const commitment_hash = readIsmpCommitmentHash(events);
|
|
13502
|
+
const blockHash = isInBlock ? status.asInBlock.toHex() : status.asFinalized.toHex();
|
|
13503
|
+
if (!commitment_hash) {
|
|
13504
|
+
controller.enqueue({
|
|
13505
|
+
kind: "Error",
|
|
13506
|
+
error: new Error("Commitment Hash missing")
|
|
13507
|
+
});
|
|
13508
|
+
return controller.close();
|
|
13509
|
+
}
|
|
13510
|
+
const header = await apiPromise.rpc.chain.getHeader(blockHash);
|
|
13511
|
+
controller.enqueue({
|
|
13512
|
+
kind: isInBlock ? "Dispatched" : "Finalized",
|
|
13513
|
+
transaction_hash: txHash.toHex(),
|
|
13514
|
+
block_number: header.number.toBigInt(),
|
|
13515
|
+
commitment: commitment_hash
|
|
13516
|
+
});
|
|
13517
|
+
if (isFinalized) {
|
|
13518
|
+
unsub?.();
|
|
13519
|
+
controller.close();
|
|
13520
|
+
closed = true;
|
|
13521
|
+
return;
|
|
13522
|
+
}
|
|
13523
|
+
}
|
|
13524
|
+
} catch (err) {
|
|
13525
|
+
if (closed) {
|
|
13526
|
+
return;
|
|
13527
|
+
}
|
|
13528
|
+
controller.enqueue({
|
|
13529
|
+
kind: "Error",
|
|
13530
|
+
error: String(err)
|
|
13531
|
+
});
|
|
13532
|
+
}
|
|
13533
|
+
});
|
|
13534
|
+
},
|
|
13535
|
+
cancel: () => unsub?.()
|
|
13536
|
+
},
|
|
13537
|
+
{
|
|
13538
|
+
highWaterMark: 3,
|
|
13539
|
+
size: () => 1
|
|
13540
|
+
}
|
|
13541
|
+
);
|
|
13542
|
+
return stream;
|
|
13543
|
+
}
|
|
13295
13544
|
var MultiAccount = Struct({
|
|
13296
13545
|
substrate_account: Bytes(32),
|
|
13297
13546
|
evm_account: Bytes(20),
|
|
@@ -13452,6 +13701,6 @@ async function teleportDot(param_) {
|
|
|
13452
13701
|
return stream;
|
|
13453
13702
|
}
|
|
13454
13703
|
|
|
13455
|
-
export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, viemChains };
|
|
13704
|
+
export { ADDRESS_ZERO, ChainConfigService, Chains, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DUMMY_PRIVATE_KEY, ERC20Method, EvmChain, HyperClientStatus, IndexerClient, IntentGateway, OrderStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, STATE_COMMITMENTS_SLOT, SubstrateChain, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, USE_ETHERSCAN_CHAINS, WrappedNativeDecimals, __test, addresses, adjustFeeDecimals, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, coingeckoIds, consensusStateIds, constructRedeemEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createChain, createEvmChain, createIndexerClient, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchPrice, generateRootWithProof, getChain, getGasPriceFromEtherscan, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, makeTeleportExtrinsics, maxBigInt, orderCommitment, popularTokens, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, submitExtrinsics, teleport, teleportDot, viemChains };
|
|
13456
13705
|
//# sourceMappingURL=index.js.map
|
|
13457
13706
|
//# sourceMappingURL=index.js.map
|