@hyperbridge/sdk 1.8.3 → 1.8.4

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.
@@ -1837,6 +1837,10 @@ declare enum TeleportStatus {
1837
1837
  RECEIVED = "RECEIVED",
1838
1838
  REFUNDED = "REFUNDED"
1839
1839
  }
1840
+ interface CancelQuote {
1841
+ nativeValue: bigint;
1842
+ relayerFee: bigint;
1843
+ }
1840
1844
  interface TokenGatewayAssetTeleportedResponse {
1841
1845
  tokenGatewayAssetTeleportedV2s: {
1842
1846
  nodes: Array<{
@@ -3909,16 +3913,17 @@ declare class IntentGateway {
3909
3913
  };
3910
3914
  }): AsyncGenerator<IntentOrderStatusUpdate, void, HexString>;
3911
3915
  /**
3912
- * Quotes the native token cost for cancelling an order.
3916
+ * Returns both the native token cost and the relayer fee for cancelling an
3917
+ * order. Use `relayerFee` to approve the ERC-20 spend before submitting.
3913
3918
  *
3914
- * Delegates to {@link OrderCanceller.quoteCancelNative}.
3919
+ * Delegates to {@link OrderCanceller.quoteCancelOrder}.
3915
3920
  *
3916
3921
  * @param order - The order to quote cancellation for.
3917
3922
  * @param fromDest - If `true`, quotes the destination-initiated cancellation fee.
3918
- * Defaults to `false` (source-side cancellation).
3919
- * @returns The native token amount required to submit the cancel transaction.
3923
+ * @returns `{ nativeValue }` — native token amount (wei) to send as `value`;
3924
+ * `{ relayerFee }` relayer incentive denominated in the chain's fee token.
3920
3925
  */
3921
- quoteCancelNative(order: Order, fromDest?: boolean): Promise<bigint>;
3926
+ quoteCancelOrder(order: Order, fromDest?: boolean): Promise<CancelQuote>;
3922
3927
  /**
3923
3928
  * Async generator that cancels an order and streams status events until
3924
3929
  * cancellation is complete.
@@ -8029,4 +8034,4 @@ declare const getChainId: (stateMachineId: string) => number | undefined;
8029
8034
  declare const getViemChain: (chainId: number) => Chain | undefined;
8030
8035
  declare const hyperbridgeAddress = "";
8031
8036
 
8032
- export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BidStorageEntry, type BidSubmissionResult, type BlockMetadata, type BundlerGasEstimate, BundlerMethod, type CancelEvent, type CancelOptions, type ChainConfig, type ChainConfigData, ChainConfigService, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchInfo, type DispatchPost, ERC20Method, type ERC7821Call, ERC7821_BATCH_MODE, type EstimateFillOrderParams, type EstimateGasCallData, EvmChain, type EvmChainParams, ABI as EvmHostABI, EvmLanguage, type ExecuteIntentOrderOptions, type ExecutionResult, type FillOptions, type FillOrderEstimate, type FillerBid, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmChain, 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 IntentGatewayContext, type IntentGatewayParams, ABI$1 as IntentGatewayV2ABI, IntentOrderStatus, type IntentOrderStatusKey, type IntentOrderStatusUpdate, IntentsCoprocessor, type IsmpRequest, MOCK_ADDRESS, type NewDeployment, ORDER_V2_PARAM_TYPE, type Order, type OrderResponse, OrderStatus, OrderStatusChecker, type OrderStatusMetadata, type OrderWithStatus, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, type PackedUserOperation, 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, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, type SelectBidResult, type SelectOptions, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, type SubmitBidOptions, SubstrateChain, Swap, TESTNET_CHAINS, type TeleportParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, TokenGateway, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type Transaction, TronChain, type TronChainParams, USE_ETHERSCAN_CHAINS, type XcmGatewayParams, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, orderCommitment, parseStateMachineId, polkadotAssetHubPaseo, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
8037
+ export { ADDRESS_ZERO, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BidStorageEntry, type BidSubmissionResult, type BlockMetadata, type BundlerGasEstimate, BundlerMethod, type CancelEvent, type CancelOptions, type CancelQuote, type ChainConfig, type ChainConfigData, ChainConfigService, Chains, type ClientConfig, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DecodedPostRequestEvent, type DecodedPostResponseEvent, type DispatchGet, type DispatchInfo, type DispatchPost, ERC20Method, type ERC7821Call, ERC7821_BATCH_MODE, type EstimateFillOrderParams, type EstimateGasCallData, EvmChain, type EvmChainParams, ABI as EvmHostABI, EvmLanguage, type ExecuteIntentOrderOptions, type ExecutionResult, type FillOptions, type FillOrderEstimate, type FillerBid, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmChain, 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 IntentGatewayContext, type IntentGatewayParams, ABI$1 as IntentGatewayV2ABI, IntentOrderStatus, type IntentOrderStatusKey, type IntentOrderStatusUpdate, IntentsCoprocessor, type IsmpRequest, MOCK_ADDRESS, type NewDeployment, ORDER_V2_PARAM_TYPE, type Order, type OrderResponse, OrderStatus, OrderStatusChecker, type OrderStatusMetadata, type OrderWithStatus, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, type PackedUserOperation, 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, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, type SelectBidResult, type SelectOptions, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, type StorageFacade, type SubmitBidOptions, SubstrateChain, Swap, TESTNET_CHAINS, type TeleportParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, TokenGateway, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, type TokenPrice, type TokenPricesResponse, type Transaction, TronChain, type TronChainParams, USE_ETHERSCAN_CHAINS, type XcmGatewayParams, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeISMPMessage, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, orderCommitment, parseStateMachineId, polkadotAssetHubPaseo, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, requestCommitmentKey, retryPromise, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
@@ -14886,6 +14886,34 @@ async function convertGasToFeeToken(ctx, gasEstimate, gasEstimateIn, evmChainID,
14886
14886
  return parseUnits(gasCostInFeeToken.toFixed(feeToken.decimals), feeToken.decimals);
14887
14887
  }
14888
14888
  }
14889
+ async function convertFeeTokenToWei(ctx, feeTokenAmount, feeTokenIn, evmChainID) {
14890
+ const chain = ctx[feeTokenIn];
14891
+ const client = chain.client;
14892
+ const wethAddr = chain.configService.getWrappedNativeAssetWithDecimals(evmChainID).asset;
14893
+ const feeToken = await getFeeToken(ctx, evmChainID, chain);
14894
+ try {
14895
+ const { amountOut } = await ctx.swap.findBestProtocolWithAmountIn(
14896
+ client,
14897
+ feeToken.address,
14898
+ wethAddr,
14899
+ feeTokenAmount,
14900
+ evmChainID,
14901
+ { selectedProtocol: "v2" }
14902
+ );
14903
+ if (amountOut === 0n) {
14904
+ throw new Error();
14905
+ }
14906
+ return amountOut;
14907
+ } catch {
14908
+ const nativeCurrency = client.chain?.nativeCurrency;
14909
+ const chainId = Number.parseInt(evmChainID.split("-")[1]);
14910
+ const feeTokenAmountInToken = new Decimal2(formatUnits(feeTokenAmount, feeToken.decimals));
14911
+ const nativeTokenPriceUsd = await fetchPrice(nativeCurrency?.symbol, chainId);
14912
+ const feeTokenAmountUsd = feeTokenAmountInToken.times(new Decimal2(1));
14913
+ const nativeAmount = feeTokenAmountUsd.dividedBy(nativeTokenPriceUsd);
14914
+ return parseUnits(nativeAmount.toFixed(nativeCurrency?.decimals ?? 18), nativeCurrency?.decimals ?? 18);
14915
+ }
14916
+ }
14889
14917
 
14890
14918
  // src/protocols/intents/OrderPlacer.ts
14891
14919
  var OrderPlacer = class {
@@ -15217,21 +15245,20 @@ var OrderCanceller = class {
15217
15245
  this.ctx = ctx;
15218
15246
  }
15219
15247
  /**
15220
- * Quotes the native token cost of cancelling an order from the given chain.
15221
- *
15222
- * For same-chain orders the cost is zero. For cross-chain orders, the
15223
- * quote covers the ISMP GET/POST dispatch fee.
15248
+ * Returns both the native token cost and the relayer fee for cancelling an
15249
+ * order. Frontends can use `relayerFee` to approve the ERC-20 spend before
15250
+ * submitting the cancel transaction.
15224
15251
  *
15225
- * @param order - The order to quote a cancellation for.
15226
- * @param fromDest - If `true`, quotes the destination-initiated cancellation fee.
15227
- * Defaults to `false` (source-side cancellation).
15228
- * @returns The native token amount required to submit the cancel transaction.
15252
+ * @param order - The order to quote.
15253
+ * @param fromDest - If `true`, quotes the destination-initiated path.
15254
+ * @returns `{ nativeValue }` — native token amount (wei) to send as `value`;
15255
+ * `{ relayerFee }` relayer incentive denominated in the chain's fee token.
15229
15256
  */
15230
- async quoteCancelNative(order, fromDest = false) {
15257
+ async quoteCancelOrder(order, fromDest = false) {
15231
15258
  if (fromDest) {
15232
- return this.quoteCancelNativeFromDest(order);
15259
+ return this.quoteCancelFromDest(order);
15233
15260
  }
15234
- return this.quoteCancelNativeFromSource(order);
15261
+ return this.quoteCancelFromSource(order);
15235
15262
  }
15236
15263
  /**
15237
15264
  * Quotes the native token cost of a source-initiated cross-chain cancellation.
@@ -15243,8 +15270,9 @@ var OrderCanceller = class {
15243
15270
  * @param order - The order to quote.
15244
15271
  * @returns The native token dispatch fee in wei.
15245
15272
  */
15246
- async quoteCancelNativeFromSource(order) {
15247
- if (order.source === order.destination) return 0n;
15273
+ async quoteCancelFromSource(order) {
15274
+ if (order.source === order.destination) return { nativeValue: 0n, relayerFee: 0n };
15275
+ const sourceStateMachine = order.source.startsWith("0x") ? hexToString(order.source) : order.source;
15248
15276
  const height = order.deadline + 1n;
15249
15277
  const destIntentGateway = this.ctx.dest.configService.getIntentGatewayV2Address(
15250
15278
  hexToString(order.destination)
@@ -15258,7 +15286,7 @@ var OrderCanceller = class {
15258
15286
  const key = concatHex([destIntentGateway, slotHash]);
15259
15287
  const context = encodeWithdrawalRequest(order, order.user);
15260
15288
  const getRequest = {
15261
- source: order.source.startsWith("0x") ? hexToString(order.source) : order.source,
15289
+ source: sourceStateMachine,
15262
15290
  dest: order.destination.startsWith("0x") ? hexToString(order.destination) : order.destination,
15263
15291
  from: this.ctx.source.configService.getIntentGatewayV2Address(hexToString(order.destination)),
15264
15292
  nonce: await this.ctx.source.getHostNonce(),
@@ -15267,7 +15295,10 @@ var OrderCanceller = class {
15267
15295
  timeoutTimestamp: 0n,
15268
15296
  context
15269
15297
  };
15270
- return await this.ctx.source.quoteNative(getRequest, 0n);
15298
+ const feeInSourceFeeToken = await convertGasToFeeToken(this.ctx, 400000n, "source", sourceStateMachine);
15299
+ const relayerFee = feeInSourceFeeToken * 1005n / 1000n;
15300
+ const nativeValue = await this.ctx.source.quoteNative(getRequest, relayerFee);
15301
+ return { nativeValue, relayerFee };
15271
15302
  }
15272
15303
  /**
15273
15304
  * Async generator that cancels an order and streams status events until
@@ -15362,17 +15393,17 @@ var OrderCanceller = class {
15362
15393
  STORAGE_KEYS.getRequest(orderId)
15363
15394
  );
15364
15395
  if (!getRequest) {
15365
- const value = await this.quoteCancelNativeFromSource(order);
15396
+ const quote = await this.quoteCancelFromSource(order);
15366
15397
  const data = encodeFunctionData({
15367
15398
  abi: ABI7,
15368
15399
  functionName: "cancelOrder",
15369
- args: [transformOrderForContract(order), { relayerFee: 0n, height: destIProof.height }]
15400
+ args: [transformOrderForContract(order), { relayerFee: quote.relayerFee, height: destIProof.height }]
15370
15401
  });
15371
15402
  const signedTransaction = yield {
15372
15403
  status: "AWAITING_CANCEL_TRANSACTION",
15373
15404
  data,
15374
15405
  to: intentGatewayAddress,
15375
- value
15406
+ value: quote.nativeValue
15376
15407
  };
15377
15408
  const receipt = signedTransaction.length === 66 ? await this.ctx.source.getTransactionReceipt(signedTransaction) : await this.ctx.source.broadcastTransaction(signedTransaction);
15378
15409
  const events = parseEventLogs({ abi: evmHost_default.ABI, logs: receipt.logs });
@@ -15457,8 +15488,8 @@ var OrderCanceller = class {
15457
15488
  * @param order - The order to quote.
15458
15489
  * @returns The native token dispatch fee in wei.
15459
15490
  */
15460
- async quoteCancelNativeFromDest(order) {
15461
- if (order.source === order.destination) return 0n;
15491
+ async quoteCancelFromDest(order) {
15492
+ if (order.source === order.destination) return { nativeValue: 0n, relayerFee: 0n };
15462
15493
  const destStateMachine = order.destination.startsWith("0x") ? hexToString(order.destination) : order.destination;
15463
15494
  const sourceStateMachine = order.source.startsWith("0x") ? hexToString(order.source) : order.source;
15464
15495
  const destIntentGateway = this.ctx.dest.configService.getIntentGatewayV2Address(destStateMachine);
@@ -15474,7 +15505,8 @@ var OrderCanceller = class {
15474
15505
  body,
15475
15506
  timeoutTimestamp: 0n
15476
15507
  };
15477
- return await this.ctx.dest.quoteNative(postRequest, relayerFee);
15508
+ const nativeValue = await this.ctx.dest.quoteNative(postRequest, relayerFee);
15509
+ return { nativeValue, relayerFee };
15478
15510
  }
15479
15511
  /**
15480
15512
  * Async generator that cancels an order by initiating from the destination
@@ -15507,17 +15539,17 @@ var OrderCanceller = class {
15507
15539
  STORAGE_KEYS.postCommitment(orderId)
15508
15540
  );
15509
15541
  if (!commitment) {
15510
- const value = await this.quoteCancelNativeFromDest(order);
15542
+ const quote = await this.quoteCancelFromDest(order);
15511
15543
  const data = encodeFunctionData({
15512
15544
  abi: ABI7,
15513
15545
  functionName: "cancelOrder",
15514
- args: [transformOrderForContract(order), { relayerFee: 0n, height: 0n }]
15546
+ args: [transformOrderForContract(order), { relayerFee: quote.relayerFee, height: 0n }]
15515
15547
  });
15516
15548
  const signedTransaction = yield {
15517
15549
  status: "AWAITING_CANCEL_TRANSACTION",
15518
15550
  data,
15519
15551
  to: intentGatewayAddress,
15520
- value
15552
+ value: quote.nativeValue
15521
15553
  };
15522
15554
  const receipt = signedTransaction.length === 66 ? await this.ctx.dest.getTransactionReceipt(signedTransaction) : await this.ctx.dest.broadcastTransaction(signedTransaction);
15523
15555
  yield {
@@ -17947,7 +17979,7 @@ var GasEstimator = class {
17947
17979
  }
17948
17980
  }
17949
17981
  const totalGas = callGasLimit + verificationGasLimit + preVerificationGas;
17950
- const totalGasCostWei = totalGas * maxFeePerGas;
17982
+ const rawTotalGasCostWei = totalGas * maxFeePerGas;
17951
17983
  const totalGasInDestFeeToken = await convertGasToFeeToken(
17952
17984
  this.ctx,
17953
17985
  totalGas,
@@ -17955,11 +17987,8 @@ var GasEstimator = class {
17955
17987
  destStateMachineId,
17956
17988
  gasPrice
17957
17989
  );
17958
- const totalGasInSourceFeeToken = adjustDecimals(
17959
- totalGasInDestFeeToken,
17960
- destFeeToken.decimals,
17961
- sourceFeeToken.decimals
17962
- );
17990
+ const totalGasInSourceFeeToken = isSameChain ? totalGasInDestFeeToken : adjustDecimals(totalGasInDestFeeToken, destFeeToken.decimals, sourceFeeToken.decimals);
17991
+ const totalGasCostWei = isSameChain ? rawTotalGasCostWei : await convertFeeTokenToWei(this.ctx, totalGasInSourceFeeToken, "source", souceStateMachineId);
17963
17992
  return {
17964
17993
  callGasLimit,
17965
17994
  verificationGasLimit,
@@ -18400,17 +18429,18 @@ var IntentGateway = class _IntentGateway {
18400
18429
  return;
18401
18430
  }
18402
18431
  /**
18403
- * Quotes the native token cost for cancelling an order.
18432
+ * Returns both the native token cost and the relayer fee for cancelling an
18433
+ * order. Use `relayerFee` to approve the ERC-20 spend before submitting.
18404
18434
  *
18405
- * Delegates to {@link OrderCanceller.quoteCancelNative}.
18435
+ * Delegates to {@link OrderCanceller.quoteCancelOrder}.
18406
18436
  *
18407
18437
  * @param order - The order to quote cancellation for.
18408
18438
  * @param fromDest - If `true`, quotes the destination-initiated cancellation fee.
18409
- * Defaults to `false` (source-side cancellation).
18410
- * @returns The native token amount required to submit the cancel transaction.
18439
+ * @returns `{ nativeValue }` — native token amount (wei) to send as `value`;
18440
+ * `{ relayerFee }` relayer incentive denominated in the chain's fee token.
18411
18441
  */
18412
- async quoteCancelNative(order, fromDest = false) {
18413
- return this.orderCanceller.quoteCancelNative(order, fromDest);
18442
+ async quoteCancelOrder(order, fromDest = false) {
18443
+ return this.orderCanceller.quoteCancelOrder(order, fromDest);
18414
18444
  }
18415
18445
  /**
18416
18446
  * Async generator that cancels an order and streams status events until