@moonbeam-network/xcm-builder 1.0.0-dev.281 → 1.0.0-dev.283

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/build/index.d.ts CHANGED
@@ -494,7 +494,7 @@ declare class SubstrateCallConfig {
494
494
  }
495
495
 
496
496
  type FeeConfigBuilder = ConfigBuilder<SubstrateCallConfig | ContractConfig, FeeConfigBuilderParams>;
497
- type BridgeFeeConfigBuilder = ConfigBuilder<SubstrateQueryConfig | ContractConfig, BridgeFeeConfigBuilderParams>;
497
+ type ProtocolFeeConfigBuilder = ConfigBuilder<SubstrateQueryConfig | ContractConfig, ProtocolFeeConfigBuilderParams>;
498
498
  interface FeeConfigBuilderParams {
499
499
  address: string;
500
500
  api: ApiPromise;
@@ -504,13 +504,8 @@ interface FeeConfigBuilderParams {
504
504
  feeAsset: ChainAsset;
505
505
  source: AnyChain;
506
506
  }
507
- interface BridgeFeeConfigBuilderParams {
508
- asset: ChainAsset;
509
- feeAsset: ChainAsset;
510
- address: string;
511
- balance?: AssetAmount;
512
- destination: AnyChain;
513
- source: AnyChain;
507
+ interface ProtocolFeeConfigBuilderParams extends Omit<FeeConfigBuilderParams, 'api'> {
508
+ bridgeChainFee: AssetAmount;
514
509
  }
515
510
  interface XcmPaymentFeeProps {
516
511
  isAssetReserveChain: boolean;
@@ -526,11 +521,14 @@ interface MoonbeamRuntimeXcmConfigAssetType extends Enum {
526
521
  type GetVersionedAssetId = (params: FeeConfigBuilderParams) => Promise<object> | object;
527
522
 
528
523
  declare function gateway(): {
529
- quoteSendTokenFee(): BridgeFeeConfigBuilder;
524
+ quoteSendTokenFee(): ProtocolFeeConfigBuilder;
530
525
  };
531
526
 
532
527
  declare function outboundQueueApi(): {
533
- calculateFee: () => BridgeFeeConfigBuilder;
528
+ calculateFee: () => {
529
+ mintForeignToken: () => ProtocolFeeConfigBuilder;
530
+ agentExecute: () => ProtocolFeeConfigBuilder;
531
+ };
534
532
  };
535
533
 
536
534
  declare function xcmPaymentApi(): {
@@ -607,6 +605,7 @@ interface SnowbridgeFunctionArgs {
607
605
  destinationParaId: number;
608
606
  amount: bigint;
609
607
  bridgeFeeAmount: bigint;
608
+ bridgeChainFee: bigint;
610
609
  requiresApproval: boolean;
611
610
  }
612
611
  interface SnowbridgeConfigConstructorParams {
@@ -1739,6 +1738,7 @@ type MrlExecuteConfigBuilder = ConfigBuilder<ContractConfig, MrlExecuteBuilderPa
1739
1738
  interface MrlBuilderParams extends BuilderParams<AnyChain> {
1740
1739
  isAutomatic: boolean;
1741
1740
  protocolFee?: AssetAmount;
1741
+ bridgeChainFee?: AssetAmount;
1742
1742
  moonApi: ApiPromise;
1743
1743
  moonAsset: ChainAsset;
1744
1744
  bridgeChain: AnyParachain;
@@ -1931,4 +1931,4 @@ declare function MrlBuilder(): {
1931
1931
 
1932
1932
  declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
1933
1933
 
1934
- export { type AssetAddressFormat, AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, type AssetMultilocation, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BridgeFeeConfigBuilder, type BridgeFeeConfigBuilderParams, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, type DestinationMultilocation, ERC20_ABI, type EquilibriumSystemBalanceData, type EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, GATEWAY_ABI, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type MrlTransferConfig, type PalletBalancesAccountDataOld, type Parents, Protocols, Provider, type QueryConfigConstructorParams, SnowbridgeConfig, type SnowbridgeConfigConstructorParams, type SnowbridgeFunctionArgs, type SnowbridgeFunctions, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, TransferType, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, snowbridge, substrate, wormhole, wormholeFactory };
1934
+ export { type AssetAddressFormat, AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, type AssetMultilocation, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, type DestinationMultilocation, ERC20_ABI, type EquilibriumSystemBalanceData, type EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, GATEWAY_ABI, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type MrlTransferConfig, type PalletBalancesAccountDataOld, type Parents, type ProtocolFeeConfigBuilder, type ProtocolFeeConfigBuilderParams, Protocols, Provider, type QueryConfigConstructorParams, SnowbridgeConfig, type SnowbridgeConfigConstructorParams, type SnowbridgeFunctionArgs, type SnowbridgeFunctions, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, TransferType, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, snowbridge, substrate, wormhole, wormholeFactory };
package/build/index.mjs CHANGED
@@ -3912,7 +3912,7 @@ function gateway() {
3912
3912
  return {
3913
3913
  quoteSendTokenFee() {
3914
3914
  return {
3915
- build: ({ asset, destination, source }) => {
3915
+ build: ({ asset, destination, source, bridgeChainFee }) => {
3916
3916
  if (!asset.address) {
3917
3917
  throw new Error(`Asset ${asset.key} has no address`);
3918
3918
  }
@@ -3932,8 +3932,7 @@ function gateway() {
3932
3932
  args: [
3933
3933
  asset.address,
3934
3934
  destination.parachainId,
3935
- 10000000000000n
3936
- // TODO mjm get from config? if not possible, we could default this, as it doesn't affect when sending to relay chain
3935
+ bridgeChainFee.amount
3937
3936
  ],
3938
3937
  func: "quoteSendTokenFee",
3939
3938
  module: "Gateway"
@@ -3947,8 +3946,8 @@ function gateway() {
3947
3946
  // src/fee/outboundQueueApi/outboundQueueApi.ts
3948
3947
  function outboundQueueApi() {
3949
3948
  return {
3950
- calculateFee: () => {
3951
- return {
3949
+ calculateFee: () => ({
3950
+ mintForeignToken: () => ({
3952
3951
  build: ({ address, balance, feeAsset }) => {
3953
3952
  const args = [
3954
3953
  {
@@ -3968,8 +3967,34 @@ function outboundQueueApi() {
3968
3967
  transform: async (data) => data.local.toBigInt() + data.remote.toBigInt()
3969
3968
  });
3970
3969
  }
3971
- };
3972
- }
3970
+ }),
3971
+ agentExecute: () => ({
3972
+ build: ({ address, balance, destination }) => {
3973
+ const assetInDestination = balance ? destination.getChainAsset(balance) : void 0;
3974
+ const args = [
3975
+ {
3976
+ AgentExecute: {
3977
+ agentId: "0x0000000000000000000000000000000000000000000000000000000000000000",
3978
+ // actual value is not important
3979
+ TokenTransfer: {
3980
+ tokenId: assetInDestination?.address,
3981
+ recipient: address,
3982
+ amount: balance?.amount
3983
+ }
3984
+ }
3985
+ },
3986
+ null
3987
+ ];
3988
+ return new SubstrateQueryConfig({
3989
+ module: "outboundQueueApi",
3990
+ func: "calculateFee",
3991
+ args,
3992
+ queryType: "call",
3993
+ transform: async (data) => data.local.toBigInt() + data.remote.toBigInt()
3994
+ });
3995
+ }
3996
+ })
3997
+ })
3973
3998
  };
3974
3999
  }
3975
4000
 
@@ -4720,27 +4745,49 @@ function Gateway() {
4720
4745
  return {
4721
4746
  sendToken: () => ({
4722
4747
  provider,
4723
- build: ({ asset, destinationAddress, protocolFee, destination }) => callSendToken(asset, protocolFee, destination, destinationAddress)
4748
+ build: ({
4749
+ asset,
4750
+ destinationAddress,
4751
+ protocolFee,
4752
+ destination,
4753
+ bridgeChainFee
4754
+ }) => callSendToken(
4755
+ asset,
4756
+ protocolFee,
4757
+ destination,
4758
+ destinationAddress,
4759
+ bridgeChainFee
4760
+ )
4724
4761
  }),
4725
4762
  approveAndSendToken: () => ({
4726
4763
  provider,
4727
- build: ({ asset, destinationAddress, protocolFee, destination }) => {
4764
+ build: ({
4765
+ asset,
4766
+ destinationAddress,
4767
+ protocolFee,
4768
+ destination,
4769
+ bridgeChainFee
4770
+ }) => {
4728
4771
  const requiresApproval = protocolFee && !protocolFee.isSame(asset);
4729
4772
  return callSendToken(
4730
4773
  asset,
4731
4774
  protocolFee,
4732
4775
  destination,
4733
4776
  destinationAddress,
4777
+ bridgeChainFee,
4734
4778
  requiresApproval
4735
4779
  );
4736
4780
  }
4737
4781
  })
4738
4782
  };
4739
4783
  }
4740
- function callSendToken(asset, protocolFee, destination, destinationAddress, requiresApproval = false) {
4784
+ function callSendToken(asset, protocolFee, destination, destinationAddress, bridgeChainFee, requiresApproval = false) {
4741
4785
  if (!protocolFee) {
4742
4786
  throw new Error("Protocol fee is required for Gateway module");
4743
4787
  }
4788
+ if (!bridgeChainFee) {
4789
+ throw new Error("Bridge chain fee is required for Gateway module");
4790
+ }
4744
4791
  if (!EvmParachain4.isAnyParachain(destination)) {
4745
4792
  throw new Error(
4746
4793
  "Destination must be a Parachain or EvmParachain for sending token with Gateway module"
@@ -4753,6 +4800,7 @@ function callSendToken(asset, protocolFee, destination, destinationAddress, requ
4753
4800
  destinationParaId: destination.parachainId,
4754
4801
  amount: asset.amount,
4755
4802
  bridgeFeeAmount: protocolFee.amount,
4803
+ bridgeChainFee: bridgeChainFee.amount,
4756
4804
  requiresApproval
4757
4805
  },
4758
4806
  func: "sendToken"
@@ -4794,7 +4842,6 @@ function polkadotXcm2() {
4794
4842
  const func = "transferAssetsUsingTypeAndThen";
4795
4843
  const provider = "snowbridge" /* Snowbridge */;
4796
4844
  return {
4797
- // TODO mjm rename ? nativeEth?
4798
4845
  canonicalEth: () => ({
4799
4846
  provider,
4800
4847
  build: ({ asset, destination, destinationAddress, protocolFee }) => {
@@ -4803,6 +4850,11 @@ function polkadotXcm2() {
4803
4850
  "Destination must be an EVM chain for globalConsensus function"
4804
4851
  );
4805
4852
  }
4853
+ if (!protocolFee) {
4854
+ throw new Error(
4855
+ "Bridge chain fee is required for the polkadotXcm.canonicalEth function"
4856
+ );
4857
+ }
4806
4858
  return new ExtrinsicConfig({
4807
4859
  module: pallet7,
4808
4860
  func,
@@ -4821,8 +4873,7 @@ function polkadotXcm2() {
4821
4873
  parents: 1,
4822
4874
  interior: "Here"
4823
4875
  },
4824
- fun: { Fungible: protocolFee?.amount }
4825
- // TODO mjm
4876
+ fun: { Fungible: protocolFee.amount }
4826
4877
  },
4827
4878
  {
4828
4879
  id: {