@moonbeam-network/xcm-builder 3.3.9 → 4.0.0

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 { TokenId, ChainAddress, TokenTransfer, Wormhole } 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
  declare enum Protocols {
476
523
  TokenBridge = "TokenBridge",
477
524
  AutomaticTokenBridge = "AutomaticTokenBridge",
@@ -661,4 +708,4 @@ declare function MrlBuilder(): {
661
708
 
662
709
  declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
663
710
 
664
- 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, Protocols, 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 };
711
+ 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, Protocols, 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
@@ -3054,6 +3054,263 @@ function FeeBuilder() {
3054
3054
  };
3055
3055
  }
3056
3056
 
3057
+ // src/monitoring/eventMonitoring/eventMonitoring.ts
3058
+ import { u8aToHex as u8aToHex7 } from "@polkadot/util";
3059
+ import { decodeAddress as decodeAddress7 } from "@polkadot/util-crypto";
3060
+
3061
+ // src/monitoring/eventMonitoring/eventMonitoring.utils.ts
3062
+ import { u8aToHex as u8aToHex6 } from "@polkadot/util";
3063
+ import { decodeAddress as decodeAddress6 } from "@polkadot/util-crypto";
3064
+ var createSourceChecker = (section, method, addressExtractor, messageIdExtractor) => (events, sourceAddress) => {
3065
+ const decodedSourceAddress = u8aToHex6(decodeAddress6(sourceAddress));
3066
+ const methods = Array.isArray(method) ? method : [method];
3067
+ const event = events.find((event2) => {
3068
+ if (event2.event.section !== section || !methods.includes(event2.event.method)) {
3069
+ return false;
3070
+ }
3071
+ try {
3072
+ const address = addressExtractor(event2);
3073
+ return address === decodedSourceAddress;
3074
+ } catch {
3075
+ return false;
3076
+ }
3077
+ });
3078
+ if (!event) {
3079
+ return { matched: false };
3080
+ }
3081
+ try {
3082
+ const messageId = messageIdExtractor(event, events);
3083
+ return { matched: true, messageId, event };
3084
+ } catch {
3085
+ return { matched: true, event };
3086
+ }
3087
+ };
3088
+ var createDestinationChecker = (section, method, matchMessageId, getIsSuccess) => (events, messageId) => {
3089
+ const methods = Array.isArray(method) ? method : [method];
3090
+ const event = events.find((event2) => {
3091
+ if (event2.event.section !== section || !methods.includes(event2.event.method)) {
3092
+ return false;
3093
+ }
3094
+ return matchMessageId(event2, messageId);
3095
+ });
3096
+ if (!event) {
3097
+ return { matched: false, success: false };
3098
+ }
3099
+ const success = getIsSuccess(event);
3100
+ return { matched: true, success, event };
3101
+ };
3102
+
3103
+ // src/monitoring/eventMonitoring/eventMonitoring.ts
3104
+ function GetAddress() {
3105
+ return {
3106
+ fromXcmEvent: () => (event) => {
3107
+ const eventData = event.event.data;
3108
+ const interior = eventData.origin.interior.asX1[0];
3109
+ if (interior.isAccountId32) {
3110
+ return interior.asAccountId32.id.toHex();
3111
+ } else if (interior.isAccountKey20) {
3112
+ return interior.asAccountKey20.key.toString();
3113
+ } else {
3114
+ throw new Error("Unsupported address type");
3115
+ }
3116
+ },
3117
+ fromXTokensEvent: () => (event) => {
3118
+ const eventData = event.event.data;
3119
+ return u8aToHex7(decodeAddress7(eventData.sender.toString()));
3120
+ }
3121
+ };
3122
+ }
3123
+ function GetMessageId() {
3124
+ return {
3125
+ fromXcmEvent: () => (event) => {
3126
+ const eventData = event.event.data;
3127
+ return eventData.messageId.toHex();
3128
+ },
3129
+ fromXcmpQueue: () => (_event, events) => {
3130
+ const xcmpEvent = events?.find(
3131
+ (event) => event.event.section === "xcmpQueue" && event.event.method === "XcmpMessageSent"
3132
+ );
3133
+ if (!xcmpEvent) {
3134
+ throw new Error("XcmpMessageSent event not found");
3135
+ }
3136
+ const eventData = xcmpEvent.event.data;
3137
+ return eventData.messageHash.toHex();
3138
+ }
3139
+ };
3140
+ }
3141
+ function MatchMessageId() {
3142
+ return {
3143
+ fromMessageQueueId: () => (event, messageId) => {
3144
+ if (!messageId) return true;
3145
+ try {
3146
+ const eventData = event.event.data;
3147
+ return eventData.id.toString() === messageId;
3148
+ } catch {
3149
+ return false;
3150
+ }
3151
+ },
3152
+ fromXcmpQueueHash: () => (event, messageId) => {
3153
+ if (!messageId) return true;
3154
+ try {
3155
+ const eventData = event.event.data;
3156
+ return eventData.messageHash.toString() === messageId;
3157
+ } catch {
3158
+ return false;
3159
+ }
3160
+ },
3161
+ fromEthereumXcmEvent: () => (event) => {
3162
+ const eventData = event.event.data;
3163
+ return eventData.xcmMsgHash.toHex();
3164
+ },
3165
+ never: () => () => true
3166
+ // Always match for cases where messageId is not used
3167
+ };
3168
+ }
3169
+ function GetIsSuccess() {
3170
+ return {
3171
+ fromMessageQueueProcessed: () => (event) => {
3172
+ try {
3173
+ const eventData = event.event.data;
3174
+ return eventData.success.isTrue;
3175
+ } catch {
3176
+ return false;
3177
+ }
3178
+ },
3179
+ fromXcmpQueueEvent: () => (event) => {
3180
+ return event.event.method === "Success";
3181
+ },
3182
+ alwaysTrue: () => () => true
3183
+ // Always successful for simple cases
3184
+ };
3185
+ }
3186
+ function CheckSource() {
3187
+ return {
3188
+ xcmPallet: () => createSourceChecker(
3189
+ "xcmPallet",
3190
+ "Sent",
3191
+ GetAddress().fromXcmEvent(),
3192
+ GetMessageId().fromXcmEvent()
3193
+ ),
3194
+ polkadotXcm: () => createSourceChecker(
3195
+ "polkadotXcm",
3196
+ "Sent",
3197
+ GetAddress().fromXcmEvent(),
3198
+ GetMessageId().fromXcmEvent()
3199
+ ),
3200
+ polkadotXcmAndXcmpQueue: () => createSourceChecker(
3201
+ "polkadotXcm",
3202
+ "Sent",
3203
+ GetAddress().fromXcmEvent(),
3204
+ GetMessageId().fromXcmpQueue()
3205
+ ),
3206
+ xTokens: () => createSourceChecker(
3207
+ "xTokens",
3208
+ ["TransferredMultiAssets", "TransferredAssets"],
3209
+ GetAddress().fromXTokensEvent(),
3210
+ GetMessageId().fromXcmpQueue()
3211
+ ),
3212
+ bridgeMessages: () => (events) => {
3213
+ const event = events.find(
3214
+ (event2) => event2.event.section === "bridgeMessages" && event2.event.method === "MessageAccepted"
3215
+ );
3216
+ return event ? { matched: true, event } : { matched: false };
3217
+ }
3218
+ };
3219
+ }
3220
+ function CheckDestination() {
3221
+ return {
3222
+ messageQueue: () => createDestinationChecker(
3223
+ "messageQueue",
3224
+ "Processed",
3225
+ MatchMessageId().fromMessageQueueId(),
3226
+ GetIsSuccess().fromMessageQueueProcessed()
3227
+ ),
3228
+ xcmpQueue: () => (events, messageId) => {
3229
+ const messageIdMatcher = MatchMessageId().fromXcmpQueueHash();
3230
+ const successEvent = events.find((event) => {
3231
+ if (event.event.section !== "xcmpQueue" || event.event.method !== "Success") {
3232
+ return false;
3233
+ }
3234
+ return messageIdMatcher(event, messageId);
3235
+ });
3236
+ const failEvent = events.find((event) => {
3237
+ if (event.event.section !== "xcmpQueue" || event.event.method !== "Fail") {
3238
+ return false;
3239
+ }
3240
+ return messageIdMatcher(event, messageId);
3241
+ });
3242
+ if (!successEvent && !failEvent) {
3243
+ return { matched: false, success: false };
3244
+ }
3245
+ return {
3246
+ matched: true,
3247
+ success: !!successEvent,
3248
+ event: successEvent || failEvent
3249
+ };
3250
+ },
3251
+ bridgeMessages: () => createDestinationChecker(
3252
+ "bridgeMessages",
3253
+ "MessagesReceived",
3254
+ // TODO implement message matching
3255
+ MatchMessageId().never(),
3256
+ GetIsSuccess().alwaysTrue()
3257
+ ),
3258
+ ethereumXcm: () => createDestinationChecker(
3259
+ "ethereumXcm",
3260
+ "ExecutedFromXcm",
3261
+ MatchMessageId().never(),
3262
+ GetIsSuccess().alwaysTrue()
3263
+ )
3264
+ };
3265
+ }
3266
+ function monitorEvent() {
3267
+ return {
3268
+ xcmPallet: () => ({
3269
+ messageQueue: () => ({
3270
+ checkSource: CheckSource().xcmPallet(),
3271
+ checkDestination: CheckDestination().messageQueue()
3272
+ })
3273
+ }),
3274
+ polkadotXcm: () => ({
3275
+ messageQueue: () => ({
3276
+ checkSource: CheckSource().polkadotXcm(),
3277
+ checkDestination: CheckDestination().messageQueue()
3278
+ }),
3279
+ mixedQueue: () => ({
3280
+ checkSource: CheckSource().polkadotXcmAndXcmpQueue(),
3281
+ checkDestination: CheckDestination().messageQueue()
3282
+ }),
3283
+ xcmpQueue: () => ({
3284
+ checkSource: CheckSource().polkadotXcmAndXcmpQueue(),
3285
+ checkDestination: CheckDestination().xcmpQueue()
3286
+ })
3287
+ }),
3288
+ xTokens: () => ({
3289
+ messageQueue: () => ({
3290
+ checkSource: CheckSource().xTokens(),
3291
+ checkDestination: CheckDestination().messageQueue()
3292
+ }),
3293
+ ethereumXcm: () => ({
3294
+ checkSource: CheckSource().xTokens(),
3295
+ checkDestination: CheckDestination().ethereumXcm()
3296
+ })
3297
+ }),
3298
+ bridgeMessages: () => ({
3299
+ bridgeMessages: () => ({
3300
+ checkSource: CheckSource().bridgeMessages(),
3301
+ checkDestination: CheckDestination().bridgeMessages()
3302
+ })
3303
+ })
3304
+ };
3305
+ }
3306
+
3307
+ // src/monitoring/MonitoringBuilder.ts
3308
+ function MonitoringBuilder() {
3309
+ return {
3310
+ monitorEvent
3311
+ };
3312
+ }
3313
+
3057
3314
  // src/mrl/providers/wormhole/contract/Batch/Batch.ts
3058
3315
  import {
3059
3316
  EvmParachain as EvmParachain2
@@ -3956,7 +4213,7 @@ function getCurrencies({ source, moonAsset, asset }) {
3956
4213
  }
3957
4214
 
3958
4215
  // src/mrl/providers/wormhole/contract/Gmp/Gmp.ts
3959
- import { u8aToHex as u8aToHex6 } from "@polkadot/util";
4216
+ import { u8aToHex as u8aToHex8 } from "@polkadot/util";
3960
4217
 
3961
4218
  // src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts
3962
4219
  var GMP_ABI = [
@@ -3982,7 +4239,7 @@ function Gmp() {
3982
4239
  return {
3983
4240
  wormholeTransferERC20: () => ({
3984
4241
  build: ({ bytes }) => {
3985
- const hex = u8aToHex6(bytes);
4242
+ const hex = u8aToHex8(bytes);
3986
4243
  return new ContractConfig({
3987
4244
  address: GMP_CONTRACT_ADDRESS,
3988
4245
  abi: GMP_ABI,
@@ -5735,6 +5992,7 @@ export {
5735
5992
  ExtrinsicBuilder,
5736
5993
  ExtrinsicConfig,
5737
5994
  FeeBuilder,
5995
+ MonitoringBuilder,
5738
5996
  MrlBuilder,
5739
5997
  Protocols,
5740
5998
  SubstrateCallConfig,