@moonbeam-network/xcm-builder 1.0.0-dev.210 → 1.0.0-dev.211

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
@@ -4,6 +4,7 @@ import { FrameSystemAccountInfo, StagingXcmV3MultiLocation } from '@polkadot/typ
4
4
  import { Struct, u128, Enum } from '@polkadot/types';
5
5
  import { Abi, PublicClient, HttpTransport } from 'viem';
6
6
  import { SubmittableExtrinsicFunction } from '@polkadot/api/types';
7
+ import { EventRecord } from '@polkadot/types/interfaces';
7
8
  import { HexString } from '@polkadot/util/types';
8
9
  import { Wormhole, Network } from '@wormhole-foundation/sdk-connect';
9
10
 
@@ -370,6 +371,7 @@ declare function polkadotXcm$1(): {
370
371
  };
371
372
  transferAssets: () => {
372
373
  here: (parents?: number) => ExtrinsicConfigBuilder;
374
+ X1: () => ExtrinsicConfigBuilder;
373
375
  X2: () => ExtrinsicConfigBuilder;
374
376
  X3: () => ExtrinsicConfigBuilder;
375
377
  X2AndFeeHere: () => ExtrinsicConfigBuilder;
@@ -469,6 +471,51 @@ declare function FeeBuilder(): {
469
471
  xcmPaymentApi: typeof xcmPaymentApi;
470
472
  };
471
473
 
474
+ type SourceChecker = (events: EventRecord[], sourceAddress: string) => {
475
+ matched: boolean;
476
+ messageId?: string;
477
+ event?: EventRecord;
478
+ };
479
+ type DestinationChecker = (events: EventRecord[], messageId?: string) => {
480
+ matched: boolean;
481
+ success: boolean;
482
+ event?: EventRecord;
483
+ };
484
+ interface MonitoringConfig {
485
+ checkSource: SourceChecker;
486
+ checkDestination: DestinationChecker;
487
+ }
488
+ declare function MonitoringBuilder(): {
489
+ xcmPallet: () => {
490
+ messageQueue: () => {
491
+ checkSource: SourceChecker;
492
+ checkDestination: DestinationChecker;
493
+ };
494
+ };
495
+ polkadotXcm: () => {
496
+ messageQueue: () => {
497
+ checkSource: SourceChecker;
498
+ checkDestination: DestinationChecker;
499
+ };
500
+ xcmpQueue: () => {
501
+ checkSource: SourceChecker;
502
+ checkDestination: DestinationChecker;
503
+ };
504
+ };
505
+ xTokens: () => {
506
+ messageQueue: () => {
507
+ checkSource: SourceChecker;
508
+ checkDestination: DestinationChecker;
509
+ };
510
+ };
511
+ bridgeMessages: () => {
512
+ bridgeMessages: () => {
513
+ checkSource: SourceChecker;
514
+ checkDestination: DestinationChecker;
515
+ };
516
+ };
517
+ };
518
+
472
519
  type WormholeTransferFunctions = 'tokenTransfer';
473
520
  type WormholeFunctionArgs = Parameters<Wormhole<Network>[WormholeTransferFunctions]>;
474
521
  interface WormholeConfigConstructorParams {
@@ -646,4 +693,4 @@ declare function MrlBuilder(): {
646
693
 
647
694
  declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
648
695
 
649
- export { AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, ERC20_ABI, type EquilibriumSystemBalanceData, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type PalletBalancesAccountDataOld, type Parents, type QueryConfigConstructorParams, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, substrate, wormhole, wormholeFactory };
696
+ export { AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, type DestinationChecker, ERC20_ABI, type EquilibriumSystemBalanceData, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, MonitoringBuilder, type MonitoringConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type PalletBalancesAccountDataOld, type Parents, type QueryConfigConstructorParams, type SourceChecker, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, substrate, wormhole, wormholeFactory };
package/build/index.mjs CHANGED
@@ -83,6 +83,7 @@ function applyConcreteWrapper(versionedObject) {
83
83
  var BaseConfig = class {
84
84
  module;
85
85
  func;
86
+ // TODO add section and method here or some mapping that transforms the module in section and func in method, for the event monitoring
86
87
  constructor({ module: module5, func }) {
87
88
  this.module = module5;
88
89
  this.func = func;
@@ -1722,6 +1723,36 @@ function polkadotXcm() {
1722
1723
  }
1723
1724
  })
1724
1725
  }),
1726
+ X1: () => ({
1727
+ build: (params) => new ExtrinsicConfig({
1728
+ module: pallet2,
1729
+ func,
1730
+ getArgs: (extrinsicFunction) => {
1731
+ const version = getExtrinsicArgumentVersion(extrinsicFunction);
1732
+ return getPolkadotXcmExtrinsicArgs({
1733
+ ...params,
1734
+ func: extrinsicFunction,
1735
+ asset: [
1736
+ {
1737
+ id: normalizeConcrete(version, {
1738
+ parents: 0,
1739
+ interior: {
1740
+ X1: [
1741
+ {
1742
+ GeneralIndex: params.asset.getAssetId()
1743
+ }
1744
+ ]
1745
+ }
1746
+ }),
1747
+ fun: {
1748
+ Fungible: params.asset.amount
1749
+ }
1750
+ }
1751
+ ]
1752
+ });
1753
+ }
1754
+ })
1755
+ }),
1725
1756
  X2: () => ({
1726
1757
  build: (params) => new ExtrinsicConfig({
1727
1758
  module: pallet2,
@@ -2208,6 +2239,7 @@ function xcmPallet() {
2208
2239
  {
2209
2240
  [version]: {
2210
2241
  parents: 0,
2242
+ // TODO put 1 to force error in source, revert to 0 to fix
2211
2243
  interior: {
2212
2244
  X1: [
2213
2245
  {
@@ -2936,6 +2968,234 @@ function FeeBuilder() {
2936
2968
  };
2937
2969
  }
2938
2970
 
2971
+ // src/monitoring/MonitoringBuilder.ts
2972
+ import { u8aToHex as u8aToHex6 } from "@polkadot/util";
2973
+ import { decodeAddress as decodeAddress6 } from "@polkadot/util-crypto";
2974
+ function GetAddress() {
2975
+ return {
2976
+ fromXcmEvent: () => (event) => {
2977
+ const eventData = event.event.data;
2978
+ const interior = eventData.origin.interior.asX1[0];
2979
+ if (interior.isAccountId32) {
2980
+ return interior.asAccountId32.id.toHex();
2981
+ } else if (interior.isAccountKey20) {
2982
+ return interior.asAccountKey20.key.toString();
2983
+ } else {
2984
+ throw new Error("Unsupported address type");
2985
+ }
2986
+ },
2987
+ fromXTokensEvent: () => (event) => {
2988
+ const eventData = event.event.data;
2989
+ return u8aToHex6(decodeAddress6(eventData.sender.toString()));
2990
+ }
2991
+ };
2992
+ }
2993
+ function GetMessageId() {
2994
+ return {
2995
+ fromXcmEvent: () => (event) => {
2996
+ const eventData = event.event.data;
2997
+ return eventData.messageId.toHex();
2998
+ },
2999
+ fromXcmpQueue: () => (event, events) => {
3000
+ const xcmpEvent = events?.find(
3001
+ (event2) => event2.event.section === "xcmpQueue" && event2.event.method === "XcmpMessageSent"
3002
+ );
3003
+ if (!xcmpEvent) {
3004
+ throw new Error("XcmpMessageSent event not found");
3005
+ }
3006
+ const eventData = xcmpEvent.event.data;
3007
+ return eventData.messageHash.toHex();
3008
+ }
3009
+ };
3010
+ }
3011
+ function MatchMessageId() {
3012
+ return {
3013
+ fromMessageQueueId: () => (event, messageId) => {
3014
+ if (!messageId) return true;
3015
+ try {
3016
+ const eventData = event.event.data;
3017
+ return eventData.id.toString() === messageId;
3018
+ } catch {
3019
+ return false;
3020
+ }
3021
+ },
3022
+ fromXcmpQueueHash: () => (event, messageId) => {
3023
+ if (!messageId) return true;
3024
+ try {
3025
+ const eventData = event.event.data;
3026
+ return eventData.messageHash.toString() === messageId;
3027
+ } catch {
3028
+ return false;
3029
+ }
3030
+ },
3031
+ // TODO
3032
+ never: () => () => true
3033
+ // Always match for cases where messageId is not used
3034
+ };
3035
+ }
3036
+ function GetIsSuccess() {
3037
+ return {
3038
+ fromMessageQueueProcessed: () => (event) => {
3039
+ try {
3040
+ const eventData = event.event.data;
3041
+ return eventData.success.isTrue;
3042
+ } catch {
3043
+ return false;
3044
+ }
3045
+ },
3046
+ fromXcmpQueueEvent: () => (event) => {
3047
+ return event.event.method === "Success";
3048
+ },
3049
+ // TODO
3050
+ alwaysTrue: () => () => true
3051
+ // Always successful for simple cases
3052
+ };
3053
+ }
3054
+ var createDestinationChecker = (section, method, matchMessageId, getIsSuccess) => (events, messageId) => {
3055
+ const methods = Array.isArray(method) ? method : [method];
3056
+ const event = events.find((event2) => {
3057
+ if (event2.event.section !== section || !methods.includes(event2.event.method)) {
3058
+ return false;
3059
+ }
3060
+ return matchMessageId(event2, messageId);
3061
+ });
3062
+ if (!event) {
3063
+ return { matched: false, success: false };
3064
+ }
3065
+ const success = getIsSuccess(event);
3066
+ return { matched: true, success, event };
3067
+ };
3068
+ var createSourceChecker = (section, method, addressExtractor, messageIdExtractor) => (events, sourceAddress) => {
3069
+ const decodedSourceAddress = u8aToHex6(decodeAddress6(sourceAddress));
3070
+ const methods = Array.isArray(method) ? method : [method];
3071
+ const event = events.find((event2) => {
3072
+ if (event2.event.section !== section || !methods.includes(event2.event.method)) {
3073
+ return false;
3074
+ }
3075
+ try {
3076
+ const address = addressExtractor(event2);
3077
+ return address === decodedSourceAddress;
3078
+ } catch {
3079
+ return false;
3080
+ }
3081
+ });
3082
+ if (!event) {
3083
+ return { matched: false };
3084
+ }
3085
+ try {
3086
+ const messageId = messageIdExtractor(event, events);
3087
+ return { matched: true, messageId, event };
3088
+ } catch {
3089
+ return { matched: true, event };
3090
+ }
3091
+ };
3092
+ function CheckSource() {
3093
+ return {
3094
+ xcmPallet: () => createSourceChecker(
3095
+ "xcmPallet",
3096
+ "Sent",
3097
+ GetAddress().fromXcmEvent(),
3098
+ GetMessageId().fromXcmEvent()
3099
+ ),
3100
+ polkadotXcm: () => createSourceChecker(
3101
+ "polkadotXcm",
3102
+ "Sent",
3103
+ GetAddress().fromXcmEvent(),
3104
+ GetMessageId().fromXcmEvent()
3105
+ ),
3106
+ polkadotXcmAndXcmpQueue: () => createSourceChecker(
3107
+ "polkadotXcm",
3108
+ "Sent",
3109
+ GetAddress().fromXcmEvent(),
3110
+ GetMessageId().fromXcmpQueue()
3111
+ ),
3112
+ xTokens: () => createSourceChecker(
3113
+ "xTokens",
3114
+ ["TransferredMultiAssets", "TransferredAssets"],
3115
+ GetAddress().fromXTokensEvent(),
3116
+ GetMessageId().fromXcmpQueue()
3117
+ ),
3118
+ bridgeMessages: () => (events, sourceAddress) => {
3119
+ const event = events.find(
3120
+ (event2) => event2.event.section === "bridgeMessages" && event2.event.method === "MessageAccepted"
3121
+ );
3122
+ return event ? { matched: true, event } : { matched: false };
3123
+ }
3124
+ };
3125
+ }
3126
+ function CheckDestination() {
3127
+ return {
3128
+ messageQueue: () => createDestinationChecker(
3129
+ "messageQueue",
3130
+ "Processed",
3131
+ MatchMessageId().fromMessageQueueId(),
3132
+ GetIsSuccess().fromMessageQueueProcessed()
3133
+ ),
3134
+ xcmpQueue: () => (events, messageId) => {
3135
+ const matchMessageId = MatchMessageId().fromXcmpQueueHash();
3136
+ const successEvent = events.find((event) => {
3137
+ if (event.event.section !== "xcmpQueue" || event.event.method !== "Success") {
3138
+ return false;
3139
+ }
3140
+ return matchMessageId(event, messageId);
3141
+ });
3142
+ const failEvent = events.find((event) => {
3143
+ if (event.event.section !== "xcmpQueue" || event.event.method !== "Fail") {
3144
+ return false;
3145
+ }
3146
+ return matchMessageId(event, messageId);
3147
+ });
3148
+ if (!successEvent && !failEvent) {
3149
+ return { matched: false, success: false };
3150
+ }
3151
+ return {
3152
+ matched: true,
3153
+ success: !!successEvent,
3154
+ event: successEvent || failEvent
3155
+ };
3156
+ },
3157
+ bridgeMessages: () => createDestinationChecker(
3158
+ "bridgeMessages",
3159
+ "MessagesReceived",
3160
+ MatchMessageId().never(),
3161
+ GetIsSuccess().alwaysTrue()
3162
+ )
3163
+ };
3164
+ }
3165
+ function MonitoringBuilder() {
3166
+ return {
3167
+ xcmPallet: () => ({
3168
+ messageQueue: () => ({
3169
+ checkSource: CheckSource().xcmPallet(),
3170
+ checkDestination: CheckDestination().messageQueue()
3171
+ })
3172
+ }),
3173
+ polkadotXcm: () => ({
3174
+ messageQueue: () => ({
3175
+ checkSource: CheckSource().polkadotXcm(),
3176
+ checkDestination: CheckDestination().messageQueue()
3177
+ }),
3178
+ xcmpQueue: () => ({
3179
+ checkSource: CheckSource().polkadotXcmAndXcmpQueue(),
3180
+ checkDestination: CheckDestination().xcmpQueue()
3181
+ })
3182
+ }),
3183
+ xTokens: () => ({
3184
+ messageQueue: () => ({
3185
+ checkSource: CheckSource().xTokens(),
3186
+ checkDestination: CheckDestination().messageQueue()
3187
+ })
3188
+ }),
3189
+ // TODO mjm call ecosystem bridge or something?
3190
+ bridgeMessages: () => ({
3191
+ bridgeMessages: () => ({
3192
+ checkSource: CheckSource().bridgeMessages(),
3193
+ checkDestination: CheckDestination().bridgeMessages()
3194
+ })
3195
+ })
3196
+ };
3197
+ }
3198
+
2939
3199
  // src/mrl/providers/wormhole/contract/Batch/Batch.ts
2940
3200
  import {
2941
3201
  EvmParachain as EvmParachain2
@@ -3838,7 +4098,7 @@ function getCurrencies({ source, moonAsset, asset }) {
3838
4098
  }
3839
4099
 
3840
4100
  // src/mrl/providers/wormhole/contract/Gmp/Gmp.ts
3841
- import { u8aToHex as u8aToHex6 } from "@polkadot/util";
4101
+ import { u8aToHex as u8aToHex7 } from "@polkadot/util";
3842
4102
 
3843
4103
  // src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts
3844
4104
  var GMP_ABI = [
@@ -3864,7 +4124,7 @@ function Gmp() {
3864
4124
  return {
3865
4125
  wormholeTransferERC20: () => ({
3866
4126
  build: ({ bytes }) => {
3867
- const hex = u8aToHex6(bytes);
4127
+ const hex = u8aToHex7(bytes);
3868
4128
  return new ContractConfig({
3869
4129
  address: GMP_CONTRACT_ADDRESS,
3870
4130
  abi: GMP_ABI,
@@ -5611,6 +5871,7 @@ export {
5611
5871
  ExtrinsicBuilder,
5612
5872
  ExtrinsicConfig,
5613
5873
  FeeBuilder,
5874
+ MonitoringBuilder,
5614
5875
  MrlBuilder,
5615
5876
  SubstrateCallConfig,
5616
5877
  SubstrateQueryConfig,