@moonbeam-network/xcm-builder 1.0.0-dev.219 → 1.0.0-dev.220

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
 
@@ -472,6 +473,52 @@ declare function FeeBuilder(): {
472
473
  xcmPaymentApi: typeof xcmPaymentApi;
473
474
  };
474
475
 
476
+ type SourceChecker = (events: EventRecord[], sourceAddress: string) => {
477
+ matched: boolean;
478
+ messageId?: string;
479
+ event?: EventRecord;
480
+ };
481
+ type DestinationChecker = (events: EventRecord[], messageId?: string) => {
482
+ matched: boolean;
483
+ success: boolean;
484
+ event?: EventRecord;
485
+ };
486
+ interface MonitorEventReturn {
487
+ xcmPallet: () => {
488
+ messageQueue: () => EventMonitoringConfig$1;
489
+ };
490
+ polkadotXcm: () => {
491
+ messageQueue: () => EventMonitoringConfig$1;
492
+ mixedQueue: () => EventMonitoringConfig$1;
493
+ xcmpQueue: () => EventMonitoringConfig$1;
494
+ };
495
+ xTokens: () => {
496
+ messageQueue: () => EventMonitoringConfig$1;
497
+ ethereumXcm: () => EventMonitoringConfig$1;
498
+ };
499
+ bridgeMessages: () => {
500
+ bridgeMessages: () => EventMonitoringConfig$1;
501
+ };
502
+ }
503
+ interface EventMonitoringConfig$1 {
504
+ checkSource: SourceChecker;
505
+ checkDestination: DestinationChecker;
506
+ }
507
+
508
+ declare function monitorEvent(): MonitorEventReturn;
509
+
510
+ declare function MonitoringBuilder(): {
511
+ monitorEvent: typeof monitorEvent;
512
+ };
513
+
514
+ interface MonitoringBuilderConfig {
515
+ eventMonitoring: EventMonitoringConfig;
516
+ }
517
+ interface EventMonitoringConfig {
518
+ checkSource: SourceChecker;
519
+ checkDestination: DestinationChecker;
520
+ }
521
+
475
522
  type WormholeTransferFunctions = 'tokenTransfer';
476
523
  type WormholeFunctionArgs = Parameters<Wormhole<Network>[WormholeTransferFunctions]>;
477
524
  interface WormholeConfigConstructorParams {
@@ -649,4 +696,4 @@ declare function MrlBuilder(): {
649
696
 
650
697
  declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
651
698
 
652
- 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 };
699
+ 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 EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, 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 };
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;
@@ -2326,6 +2327,7 @@ function xcmPallet() {
2326
2327
  {
2327
2328
  [version]: {
2328
2329
  parents: 0,
2330
+ // TODO put 1 to force error in source, revert to 0 to fix
2329
2331
  interior: {
2330
2332
  X1: [
2331
2333
  {
@@ -3054,6 +3056,263 @@ function FeeBuilder() {
3054
3056
  };
3055
3057
  }
3056
3058
 
3059
+ // src/monitoring/eventMonitoring/eventMonitoring.ts
3060
+ import { u8aToHex as u8aToHex7 } from "@polkadot/util";
3061
+ import { decodeAddress as decodeAddress7 } from "@polkadot/util-crypto";
3062
+
3063
+ // src/monitoring/eventMonitoring/eventMonitoring.utils.ts
3064
+ import { u8aToHex as u8aToHex6 } from "@polkadot/util";
3065
+ import { decodeAddress as decodeAddress6 } from "@polkadot/util-crypto";
3066
+ var createSourceChecker = (section, method, addressExtractor, messageIdExtractor) => (events, sourceAddress) => {
3067
+ const decodedSourceAddress = u8aToHex6(decodeAddress6(sourceAddress));
3068
+ const methods = Array.isArray(method) ? method : [method];
3069
+ const event = events.find((event2) => {
3070
+ if (event2.event.section !== section || !methods.includes(event2.event.method)) {
3071
+ return false;
3072
+ }
3073
+ try {
3074
+ const address = addressExtractor(event2);
3075
+ return address === decodedSourceAddress;
3076
+ } catch {
3077
+ return false;
3078
+ }
3079
+ });
3080
+ if (!event) {
3081
+ return { matched: false };
3082
+ }
3083
+ try {
3084
+ const messageId = messageIdExtractor(event, events);
3085
+ return { matched: true, messageId, event };
3086
+ } catch {
3087
+ return { matched: true, event };
3088
+ }
3089
+ };
3090
+ var createDestinationChecker = (section, method, matchMessageId, getIsSuccess) => (events, messageId) => {
3091
+ const methods = Array.isArray(method) ? method : [method];
3092
+ const event = events.find((event2) => {
3093
+ if (event2.event.section !== section || !methods.includes(event2.event.method)) {
3094
+ return false;
3095
+ }
3096
+ return matchMessageId(event2, messageId);
3097
+ });
3098
+ if (!event) {
3099
+ return { matched: false, success: false };
3100
+ }
3101
+ const success = getIsSuccess(event);
3102
+ return { matched: true, success, event };
3103
+ };
3104
+
3105
+ // src/monitoring/eventMonitoring/eventMonitoring.ts
3106
+ function GetAddress() {
3107
+ return {
3108
+ fromXcmEvent: () => (event) => {
3109
+ const eventData = event.event.data;
3110
+ const interior = eventData.origin.interior.asX1[0];
3111
+ if (interior.isAccountId32) {
3112
+ return interior.asAccountId32.id.toHex();
3113
+ } else if (interior.isAccountKey20) {
3114
+ return interior.asAccountKey20.key.toString();
3115
+ } else {
3116
+ throw new Error("Unsupported address type");
3117
+ }
3118
+ },
3119
+ fromXTokensEvent: () => (event) => {
3120
+ const eventData = event.event.data;
3121
+ return u8aToHex7(decodeAddress7(eventData.sender.toString()));
3122
+ }
3123
+ };
3124
+ }
3125
+ function GetMessageId() {
3126
+ return {
3127
+ fromXcmEvent: () => (event) => {
3128
+ const eventData = event.event.data;
3129
+ return eventData.messageId.toHex();
3130
+ },
3131
+ fromXcmpQueue: () => (_event, events) => {
3132
+ const xcmpEvent = events?.find(
3133
+ (event) => event.event.section === "xcmpQueue" && event.event.method === "XcmpMessageSent"
3134
+ );
3135
+ if (!xcmpEvent) {
3136
+ throw new Error("XcmpMessageSent event not found");
3137
+ }
3138
+ const eventData = xcmpEvent.event.data;
3139
+ return eventData.messageHash.toHex();
3140
+ }
3141
+ };
3142
+ }
3143
+ function MatchMessageId() {
3144
+ return {
3145
+ fromMessageQueueId: () => (event, messageId) => {
3146
+ if (!messageId) return true;
3147
+ try {
3148
+ const eventData = event.event.data;
3149
+ return eventData.id.toString() === messageId;
3150
+ } catch {
3151
+ return false;
3152
+ }
3153
+ },
3154
+ fromXcmpQueueHash: () => (event, messageId) => {
3155
+ if (!messageId) return true;
3156
+ try {
3157
+ const eventData = event.event.data;
3158
+ return eventData.messageHash.toString() === messageId;
3159
+ } catch {
3160
+ return false;
3161
+ }
3162
+ },
3163
+ fromEthereumXcmEvent: () => (event) => {
3164
+ const eventData = event.event.data;
3165
+ return eventData.xcmMsgHash.toHex();
3166
+ },
3167
+ never: () => () => true
3168
+ // Always match for cases where messageId is not used
3169
+ };
3170
+ }
3171
+ function GetIsSuccess() {
3172
+ return {
3173
+ fromMessageQueueProcessed: () => (event) => {
3174
+ try {
3175
+ const eventData = event.event.data;
3176
+ return eventData.success.isTrue;
3177
+ } catch {
3178
+ return false;
3179
+ }
3180
+ },
3181
+ fromXcmpQueueEvent: () => (event) => {
3182
+ return event.event.method === "Success";
3183
+ },
3184
+ alwaysTrue: () => () => true
3185
+ // Always successful for simple cases
3186
+ };
3187
+ }
3188
+ function CheckSource() {
3189
+ return {
3190
+ xcmPallet: () => createSourceChecker(
3191
+ "xcmPallet",
3192
+ "Sent",
3193
+ GetAddress().fromXcmEvent(),
3194
+ GetMessageId().fromXcmEvent()
3195
+ ),
3196
+ polkadotXcm: () => createSourceChecker(
3197
+ "polkadotXcm",
3198
+ "Sent",
3199
+ GetAddress().fromXcmEvent(),
3200
+ GetMessageId().fromXcmEvent()
3201
+ ),
3202
+ polkadotXcmAndXcmpQueue: () => createSourceChecker(
3203
+ "polkadotXcm",
3204
+ "Sent",
3205
+ GetAddress().fromXcmEvent(),
3206
+ GetMessageId().fromXcmpQueue()
3207
+ ),
3208
+ xTokens: () => createSourceChecker(
3209
+ "xTokens",
3210
+ ["TransferredMultiAssets", "TransferredAssets"],
3211
+ GetAddress().fromXTokensEvent(),
3212
+ GetMessageId().fromXcmpQueue()
3213
+ ),
3214
+ bridgeMessages: () => (events) => {
3215
+ const event = events.find(
3216
+ (event2) => event2.event.section === "bridgeMessages" && event2.event.method === "MessageAccepted"
3217
+ );
3218
+ return event ? { matched: true, event } : { matched: false };
3219
+ }
3220
+ };
3221
+ }
3222
+ function CheckDestination() {
3223
+ return {
3224
+ messageQueue: () => createDestinationChecker(
3225
+ "messageQueue",
3226
+ "Processed",
3227
+ MatchMessageId().fromMessageQueueId(),
3228
+ GetIsSuccess().fromMessageQueueProcessed()
3229
+ ),
3230
+ xcmpQueue: () => (events, messageId) => {
3231
+ const matchMessageId = MatchMessageId().fromXcmpQueueHash();
3232
+ const successEvent = events.find((event) => {
3233
+ if (event.event.section !== "xcmpQueue" || event.event.method !== "Success") {
3234
+ return false;
3235
+ }
3236
+ return matchMessageId(event, messageId);
3237
+ });
3238
+ const failEvent = events.find((event) => {
3239
+ if (event.event.section !== "xcmpQueue" || event.event.method !== "Fail") {
3240
+ return false;
3241
+ }
3242
+ return matchMessageId(event, messageId);
3243
+ });
3244
+ if (!successEvent && !failEvent) {
3245
+ return { matched: false, success: false };
3246
+ }
3247
+ return {
3248
+ matched: true,
3249
+ success: !!successEvent,
3250
+ event: successEvent || failEvent
3251
+ };
3252
+ },
3253
+ bridgeMessages: () => createDestinationChecker(
3254
+ "bridgeMessages",
3255
+ "MessagesReceived",
3256
+ // TODO implement message matching
3257
+ MatchMessageId().never(),
3258
+ GetIsSuccess().alwaysTrue()
3259
+ ),
3260
+ ethereumXcm: () => createDestinationChecker(
3261
+ "ethereumXcm",
3262
+ "ExecutedFromXcm",
3263
+ MatchMessageId().never(),
3264
+ GetIsSuccess().alwaysTrue()
3265
+ )
3266
+ };
3267
+ }
3268
+ function monitorEvent() {
3269
+ return {
3270
+ xcmPallet: () => ({
3271
+ messageQueue: () => ({
3272
+ checkSource: CheckSource().xcmPallet(),
3273
+ checkDestination: CheckDestination().messageQueue()
3274
+ })
3275
+ }),
3276
+ polkadotXcm: () => ({
3277
+ messageQueue: () => ({
3278
+ checkSource: CheckSource().polkadotXcm(),
3279
+ checkDestination: CheckDestination().messageQueue()
3280
+ }),
3281
+ mixedQueue: () => ({
3282
+ checkSource: CheckSource().polkadotXcmAndXcmpQueue(),
3283
+ checkDestination: CheckDestination().messageQueue()
3284
+ }),
3285
+ xcmpQueue: () => ({
3286
+ checkSource: CheckSource().polkadotXcmAndXcmpQueue(),
3287
+ checkDestination: CheckDestination().xcmpQueue()
3288
+ })
3289
+ }),
3290
+ xTokens: () => ({
3291
+ messageQueue: () => ({
3292
+ checkSource: CheckSource().xTokens(),
3293
+ checkDestination: CheckDestination().messageQueue()
3294
+ }),
3295
+ ethereumXcm: () => ({
3296
+ checkSource: CheckSource().xTokens(),
3297
+ checkDestination: CheckDestination().ethereumXcm()
3298
+ })
3299
+ }),
3300
+ bridgeMessages: () => ({
3301
+ bridgeMessages: () => ({
3302
+ checkSource: CheckSource().bridgeMessages(),
3303
+ checkDestination: CheckDestination().bridgeMessages()
3304
+ })
3305
+ })
3306
+ };
3307
+ }
3308
+
3309
+ // src/monitoring/MonitoringBuilder.ts
3310
+ function MonitoringBuilder() {
3311
+ return {
3312
+ monitorEvent
3313
+ };
3314
+ }
3315
+
3057
3316
  // src/mrl/providers/wormhole/contract/Batch/Batch.ts
3058
3317
  import {
3059
3318
  EvmParachain as EvmParachain2
@@ -3956,7 +4215,7 @@ function getCurrencies({ source, moonAsset, asset }) {
3956
4215
  }
3957
4216
 
3958
4217
  // src/mrl/providers/wormhole/contract/Gmp/Gmp.ts
3959
- import { u8aToHex as u8aToHex6 } from "@polkadot/util";
4218
+ import { u8aToHex as u8aToHex8 } from "@polkadot/util";
3960
4219
 
3961
4220
  // src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts
3962
4221
  var GMP_ABI = [
@@ -3982,7 +4241,7 @@ function Gmp() {
3982
4241
  return {
3983
4242
  wormholeTransferERC20: () => ({
3984
4243
  build: ({ bytes }) => {
3985
- const hex = u8aToHex6(bytes);
4244
+ const hex = u8aToHex8(bytes);
3986
4245
  return new ContractConfig({
3987
4246
  address: GMP_CONTRACT_ADDRESS,
3988
4247
  abi: GMP_ABI,
@@ -5729,6 +5988,7 @@ export {
5729
5988
  ExtrinsicBuilder,
5730
5989
  ExtrinsicConfig,
5731
5990
  FeeBuilder,
5991
+ MonitoringBuilder,
5732
5992
  MrlBuilder,
5733
5993
  SubstrateCallConfig,
5734
5994
  SubstrateQueryConfig,