solidity-scale-codec 0.1.3 → 0.3.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.
Files changed (104) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/DEFINITIONS.md +132 -0
  3. package/README.md +97 -1
  4. package/package.json +16 -4
  5. package/src/LittleEndian/LittleEndianU128.sol +4 -2
  6. package/src/LittleEndian/LittleEndianU16.sol +2 -2
  7. package/src/LittleEndian/LittleEndianU256.sol +4 -2
  8. package/src/LittleEndian/LittleEndianU32.sol +4 -2
  9. package/src/LittleEndian/LittleEndianU64.sol +4 -2
  10. package/src/LittleEndian/LittleEndianU8.sol +2 -2
  11. package/src/Scale/Address/Address.sol +55 -0
  12. package/src/Scale/Address.sol +4 -0
  13. package/src/Scale/Array/BoolArr.sol +16 -2
  14. package/src/Scale/Array/I128Arr.sol +16 -2
  15. package/src/Scale/Array/I16Arr.sol +16 -2
  16. package/src/Scale/Array/I256Arr.sol +16 -2
  17. package/src/Scale/Array/I32Arr.sol +16 -2
  18. package/src/Scale/Array/I64Arr.sol +16 -2
  19. package/src/Scale/Array/I8Arr.sol +16 -2
  20. package/src/Scale/Array/U128Arr.sol +16 -2
  21. package/src/Scale/Array/U16Arr.sol +16 -2
  22. package/src/Scale/Array/U256Arr.sol +16 -2
  23. package/src/Scale/Array/U32Arr.sol +16 -2
  24. package/src/Scale/Array/U64Arr.sol +16 -2
  25. package/src/Scale/Array/U8Arr.sol +16 -2
  26. package/src/Scale/Bool/Bool.sol +12 -0
  27. package/src/Scale/Bytes/Bytes.sol +63 -0
  28. package/src/Scale/Bytes/Bytes16.sol +53 -0
  29. package/src/Scale/Bytes/Bytes2.sol +53 -0
  30. package/src/Scale/Bytes/Bytes32.sol +53 -0
  31. package/src/Scale/Bytes/Bytes4.sol +53 -0
  32. package/src/Scale/Bytes/Bytes8.sol +53 -0
  33. package/src/Scale/Bytes.sol +8 -0
  34. package/src/Scale/Compact/Compact.sol +37 -3
  35. package/src/Scale/Signed/I128.sol +11 -0
  36. package/src/Scale/Signed/I16.sol +11 -0
  37. package/src/Scale/Signed/I256.sol +11 -0
  38. package/src/Scale/Signed/I32.sol +11 -0
  39. package/src/Scale/Signed/I64.sol +11 -0
  40. package/src/Scale/Signed/I8.sol +11 -0
  41. package/src/Scale/Unsigned/U128.sol +16 -2
  42. package/src/Scale/Unsigned/U16.sol +16 -2
  43. package/src/Scale/Unsigned/U256.sol +16 -2
  44. package/src/Scale/Unsigned/U32.sol +16 -2
  45. package/src/Scale/Unsigned/U64.sol +16 -2
  46. package/src/Scale/Unsigned/U8.sol +16 -2
  47. package/src/Xcm/Types/Version.sol +5 -0
  48. package/src/Xcm/VersionedXcm/VersionedXcm.sol +27 -0
  49. package/src/Xcm/VersionedXcm/VersionedXcmCodec.sol +70 -0
  50. package/src/Xcm/v3/Constants.sol +5 -0
  51. package/src/Xcm/v3/MaybeErrorCode/MaybeErrorCode.sol +73 -0
  52. package/src/Xcm/v3/MaybeErrorCode/MaybeErrorCodeCodec.sol +94 -0
  53. package/src/Xcm/v5/Asset/Asset.sol +13 -0
  54. package/src/Xcm/v5/Asset/AssetCodec.sol +72 -0
  55. package/src/Xcm/v5/AssetFilter/AssetFilter.sol +61 -0
  56. package/src/Xcm/v5/AssetFilter/AssetFilterCodec.sol +105 -0
  57. package/src/Xcm/v5/AssetId/AssetId.sol +10 -0
  58. package/src/Xcm/v5/AssetId/AssetIdCodec.sol +57 -0
  59. package/src/Xcm/v5/AssetInstance/AssetInstance.sol +139 -0
  60. package/src/Xcm/v5/AssetInstance/AssetInstanceCodec.sol +174 -0
  61. package/src/Xcm/v5/AssetTransferFilter/AssetTransferFilter.sol +82 -0
  62. package/src/Xcm/v5/AssetTransferFilter/AssetTransferFilterCodec.sol +95 -0
  63. package/src/Xcm/v5/Assets/Assets.sol +14 -0
  64. package/src/Xcm/v5/Assets/AssetsCodec.sol +94 -0
  65. package/src/Xcm/v5/BodyId/BodyId.sol +121 -0
  66. package/src/Xcm/v5/BodyId/BodyIdCodec.sol +128 -0
  67. package/src/Xcm/v5/BodyPart/BodyPart.sol +105 -0
  68. package/src/Xcm/v5/BodyPart/BodyPartCodec.sol +134 -0
  69. package/src/Xcm/v5/Constants.sol +15 -0
  70. package/src/Xcm/v5/Fungibility/Fungibility.sol +60 -0
  71. package/src/Xcm/v5/Fungibility/FungibilityCodec.sol +128 -0
  72. package/src/Xcm/v5/Hint/Hint.sol +40 -0
  73. package/src/Xcm/v5/Hint/HintCodec.sol +82 -0
  74. package/src/Xcm/v5/Instruction/Instruction.sol +1217 -0
  75. package/src/Xcm/v5/Instruction/InstructionCodec.sol +321 -0
  76. package/src/Xcm/v5/Junction/Junction.sol +258 -0
  77. package/src/Xcm/v5/Junction/JunctionCodec.sol +329 -0
  78. package/src/Xcm/v5/Junctions/Junctions.sol +12 -0
  79. package/src/Xcm/v5/Junctions/JunctionsCodec.sol +120 -0
  80. package/src/Xcm/v5/Location/Location.sol +12 -0
  81. package/src/Xcm/v5/Location/LocationCodec.sol +68 -0
  82. package/src/Xcm/v5/NetworkId/NetworkId.sol +115 -0
  83. package/src/Xcm/v5/NetworkId/NetworkIdCodec.sol +114 -0
  84. package/src/Xcm/v5/OriginKind/OriginKind.sol +14 -0
  85. package/src/Xcm/v5/OriginKind/OriginKindCodec.sol +66 -0
  86. package/src/Xcm/v5/PalletInfo/PalletInfo.sol +18 -0
  87. package/src/Xcm/v5/PalletInfo/PalletInfoCodec.sol +119 -0
  88. package/src/Xcm/v5/QueryResponseInfo/QueryResponseInfo.sol +16 -0
  89. package/src/Xcm/v5/QueryResponseInfo/QueryResponseInfoCodec.sol +91 -0
  90. package/src/Xcm/v5/Response/Response.sol +145 -0
  91. package/src/Xcm/v5/Response/ResponseCodec.sol +174 -0
  92. package/src/Xcm/v5/Types/QueryId.sol +5 -0
  93. package/src/Xcm/v5/Weight/Weight.sol +10 -0
  94. package/src/Xcm/v5/Weight/WeightCodec.sol +87 -0
  95. package/src/Xcm/v5/WeightLimit/WeightLimit.sol +48 -0
  96. package/src/Xcm/v5/WeightLimit/WeightLimitCodec.sol +88 -0
  97. package/src/Xcm/v5/WildAsset/WildAsset.sol +112 -0
  98. package/src/Xcm/v5/WildAsset/WildAssetCodec.sol +166 -0
  99. package/src/Xcm/v5/WildFungibility/WildFungibility.sol +10 -0
  100. package/src/Xcm/v5/WildFungibility/WildFungibilityCodec.sol +74 -0
  101. package/src/Xcm/v5/Xcm/Xcm.sol +27 -0
  102. package/src/Xcm/v5/Xcm/XcmCodec.sol +83 -0
  103. package/src/Xcm/v5/XcmError/XcmError.sol +122 -0
  104. package/src/Xcm/v5/XcmError/XcmErrorCodec.sol +85 -0
@@ -0,0 +1,1217 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {Asset} from "../Asset/Asset.sol";
5
+ import {AssetFilter} from "../AssetFilter/AssetFilter.sol";
6
+ import {Assets} from "../Assets/Assets.sol";
7
+ import {AssetTransferFilter} from "../AssetTransferFilter/AssetTransferFilter.sol";
8
+ import {Hint} from "../Hint/Hint.sol";
9
+ import {Junction} from "../Junction/Junction.sol";
10
+ import {Junctions} from "../Junctions/Junctions.sol";
11
+ import {Location} from "../Location/Location.sol";
12
+ import {NetworkId} from "../NetworkId/NetworkId.sol";
13
+ import {OriginKind} from "../OriginKind/OriginKind.sol";
14
+ import {QueryResponseInfo} from "../QueryResponseInfo/QueryResponseInfo.sol";
15
+ import {Response} from "../Response/Response.sol";
16
+ import {Weight} from "../Weight/Weight.sol";
17
+ import {WeightLimit} from "../WeightLimit/WeightLimit.sol";
18
+ import {XcmError} from "../XcmError/XcmError.sol";
19
+ import {QueryId} from "../Types/QueryId.sol";
20
+ import {MaybeErrorCode} from "../../v3/MaybeErrorCode/MaybeErrorCode.sol";
21
+ import {AssetsCodec} from "../Assets/AssetsCodec.sol";
22
+ import {AssetCodec} from "../Asset/AssetCodec.sol";
23
+ import {LocationCodec} from "../Location/LocationCodec.sol";
24
+ import {JunctionsCodec} from "../Junctions/JunctionsCodec.sol";
25
+ import {JunctionCodec} from "../Junction/JunctionCodec.sol";
26
+ import {AssetFilterCodec} from "../AssetFilter/AssetFilterCodec.sol";
27
+ import {AssetTransferFilterCodec} from "../AssetTransferFilter/AssetTransferFilterCodec.sol";
28
+ import {QueryResponseInfoCodec} from "../QueryResponseInfo/QueryResponseInfoCodec.sol";
29
+ import {ResponseCodec} from "../Response/ResponseCodec.sol";
30
+ import {XcmErrorCodec} from "../XcmError/XcmErrorCodec.sol";
31
+ import {NetworkIdCodec} from "../NetworkId/NetworkIdCodec.sol";
32
+ import {OriginKindCodec} from "../OriginKind/OriginKindCodec.sol";
33
+ import {WeightCodec} from "../Weight/WeightCodec.sol";
34
+ import {WeightLimitCodec} from "../WeightLimit/WeightLimitCodec.sol";
35
+ import {HintCodec} from "../Hint/HintCodec.sol";
36
+ import {MaybeErrorCodeCodec} from "../../v3/MaybeErrorCode/MaybeErrorCodeCodec.sol";
37
+
38
+ import {MAX_ASSET_TRANSFER_FILTERS, HINT_NUM_VARIANTS} from "../Constants.sol";
39
+
40
+ import {Compact} from "../../../Scale/Compact.sol";
41
+ import {Bool} from "../../../Scale/Bool/Bool.sol";
42
+ import {Bytes32} from "../../../Scale/Bytes/Bytes32.sol";
43
+ import {LittleEndianU32} from "../../../LittleEndian/LittleEndianU32.sol";
44
+ import {LittleEndianU64} from "../../../LittleEndian/LittleEndianU64.sol";
45
+ import {Bytes} from "../../../Scale/Bytes/Bytes.sol";
46
+
47
+ /// @notice An error indicating that an instruction was invalid in some way, such as having malformed parameters or parameters that violate expected bounds.
48
+ error InvalidInstruction();
49
+
50
+ /// @notice Discriminant for the `Instruction` enum, representing the type of instruction being executed.
51
+ enum InstructionType {
52
+ /// @custom:variant Withdraw asset(s) from the ownership of `origin` and place them into the Holding Register.
53
+ WithdrawAsset,
54
+ /// @custom:variant Asset(s) have been received into the ownership of this system on the `origin` system and equivalent derivatives should be placed into the Holding Register.
55
+ ReserveAssetDeposited,
56
+ /// @custom:variant Asset(s) have been destroyed on the `origin` system and equivalent assets should be created and placed into the Holding Register.
57
+ ReceiveTeleportedAsset,
58
+ /// @custom:variant Respond with information that the local system is expecting.
59
+ QueryResponse,
60
+ /// @custom:variant Withdraw asset(s) from the ownership of `origin` and place equivalent assets under the ownership of `beneficiary`.
61
+ TransferAsset,
62
+ /// @custom:variant Withdraw asset(s) from the ownership of `origin` and place equivalent assets under the ownership of `dest` within this consensus system.
63
+ TransferReserveAsset,
64
+ /// @custom:variant Apply the encoded transaction `call`, whose dispatch-origin should be `origin` as expressed by the kind of origin `origin_kind`.
65
+ Transact,
66
+ /// @custom:variant A message to notify about a new incoming HRMP channel.
67
+ HrmpNewChannelOpenRequest,
68
+ /// @custom:variant A message to notify about that a previously sent open channel request has been accepted by the recipient.
69
+ HrmpChannelAccepted,
70
+ /// @custom:variant A message to notify that the other party in an open channel decided to close it.
71
+ HrmpChannelClosing,
72
+ /// @custom:variant Clear the origin.
73
+ ClearOrigin,
74
+ /// @custom:variant Mutate the origin to some interior location.
75
+ DescendOrigin,
76
+ /// @custom:variant Immediately report the contents of the Error Register to the given destination via XCM.
77
+ ReportError,
78
+ /// @custom:variant Remove the asset(s) from the Holding Register and place equivalent assets under the ownership of `beneficiary`.
79
+ DepositAsset,
80
+ /// @custom:variant Remove the asset(s) from the Holding Register and place equivalent assets under the ownership of `dest`, then send a `ReserveAssetDeposited` onward message.
81
+ DepositReserveAsset,
82
+ /// @custom:variant Remove the asset(s) from the Holding Register and replace them with alternative assets.
83
+ ExchangeAsset,
84
+ /// @custom:variant Remove the asset(s) from holding and send a `WithdrawAsset` XCM message to a reserve location.
85
+ InitiateReserveWithdraw,
86
+ /// @custom:variant Remove the asset(s) from holding and send a `ReceiveTeleportedAsset` XCM message to a `dest` location.
87
+ InitiateTeleport,
88
+ /// @custom:variant Report to a given destination the contents of the Holding Register.
89
+ ReportHolding,
90
+ /// @custom:variant Pay for the execution of some XCM with up to `weight` picoseconds of execution time, paying with up to `fees` from the Holding Register.
91
+ BuyExecution,
92
+ /// @custom:variant Refund any surplus weight previously bought with `BuyExecution`.
93
+ RefundSurplus,
94
+ /// @custom:variant Set the Error Handler Register to code that should be called in the case of an error.
95
+ SetErrorHandler,
96
+ /// @custom:variant Set the Appendix Register to code that should be called after execution (including error handler) is finished.
97
+ SetAppendix,
98
+ /// @custom:variant Clear the Error Register.
99
+ ClearError,
100
+ /// @custom:variant Create some assets which are being held on behalf of the origin.
101
+ ClaimAsset,
102
+ /// @custom:variant Always throws an error of type `Trap`.
103
+ Trap,
104
+ /// @custom:variant Ask the destination system to respond with the most recent version of XCM that they support.
105
+ SubscribeVersion,
106
+ /// @custom:variant Cancel the effect of a previous `SubscribeVersion` instruction.
107
+ UnsubscribeVersion,
108
+ /// @custom:variant Reduce Holding by up to the given assets.
109
+ BurnAsset,
110
+ /// @custom:variant Throw an error if Holding does not contain at least the given assets.
111
+ ExpectAsset,
112
+ /// @custom:variant Ensure that the Origin Register equals some given value and throw an error if not.
113
+ ExpectOrigin,
114
+ /// @custom:variant Ensure that the Error Register equals some given value and throw an error if not.
115
+ ExpectError,
116
+ /// @custom:variant Ensure that the Transact Status Register equals some given value and throw an error if not.
117
+ ExpectTransactStatus,
118
+ /// @custom:variant Query the existence of a particular pallet type.
119
+ QueryPallet,
120
+ /// @custom:variant Ensure that a particular pallet with a particular version exists.
121
+ ExpectPallet,
122
+ /// @custom:variant Send a `QueryResponse` message containing the value of the Transact Status Register to some destination.
123
+ ReportTransactStatus,
124
+ /// @custom:variant Set the Transact Status Register to its default, cleared, value.
125
+ ClearTransactStatus,
126
+ /// @custom:variant Set the Origin Register to be some child of the Universal Ancestor.
127
+ UniversalOrigin,
128
+ /// @custom:variant Send a message on to Non-Local Consensus system.
129
+ ExportMessage,
130
+ /// @custom:variant Lock the locally held asset and prevent further transfer or withdrawal.
131
+ LockAsset,
132
+ /// @custom:variant Remove the lock over `asset` on this chain and allow the asset to be transferred.
133
+ UnlockAsset,
134
+ /// @custom:variant Asset has been locked on the `origin` system and may not be transferred.
135
+ NoteUnlockable,
136
+ /// @custom:variant Send an `UnlockAsset` instruction to the `locker` for the given `asset`.
137
+ RequestUnlock,
138
+ /// @custom:variant Sets the Fees Mode Register.
139
+ SetFeesMode,
140
+ /// @custom:variant Set the Topic Register.
141
+ SetTopic,
142
+ /// @custom:variant Clear the Topic Register.
143
+ ClearTopic,
144
+ /// @custom:variant Alter the current Origin to another given origin.
145
+ AliasOrigin,
146
+ /// @custom:variant A directive to indicate that the origin expects free execution of the message.
147
+ UnpaidExecution,
148
+ /// @custom:variant Takes an asset, uses it to pay for execution and puts the rest in the fees register. Successor to `BuyExecution`.
149
+ PayFees,
150
+ /// @custom:variant Initiates cross-chain transfer of assets in the holding register using specified asset transfer filters.
151
+ InitiateTransfer,
152
+ /// @custom:variant Executes inner `xcm` with origin set to the provided `descendant_origin`, then restores the original origin.
153
+ ExecuteWithOrigin,
154
+ /// @custom:variant Set hints for XCM execution, changing the behaviour of the XCM program.
155
+ SetHints
156
+ }
157
+
158
+ /// @notice Params for `WithdrawAsset`.
159
+ struct WithdrawAssetParams {
160
+ /// @custom:property The asset(s) to be withdrawn into holding.
161
+ Assets assets;
162
+ }
163
+
164
+ /// @notice Params for `ReserveAssetDeposited`.
165
+ struct ReserveAssetDepositedParams {
166
+ /// @custom:property The asset(s) that are minted into holding.
167
+ Assets assets;
168
+ }
169
+
170
+ /// @notice Params for `ReceiveTeleportedAsset`.
171
+ struct ReceiveTeleportedAssetParams {
172
+ /// @custom:property The asset(s) minted into the Holding Register.
173
+ Assets assets;
174
+ }
175
+
176
+ /// @notice Params for `QueryResponse`.
177
+ struct QueryResponseParams {
178
+ /// @custom:property The identifier of the query that resulted in this response.
179
+ QueryId queryId;
180
+ /// @custom:property The message content.
181
+ Response response;
182
+ /// @custom:property The maximum weight that handling this response should take.
183
+ Weight maxWeight;
184
+ /// @custom:property Whether `querier` is present.
185
+ bool hasQuerier;
186
+ /// @custom:property The location responsible for initiating the response, when present.
187
+ Location querier;
188
+ }
189
+
190
+ /// @notice Params for `TransferAsset`.
191
+ struct TransferAssetParams {
192
+ /// @custom:property The asset(s) to be withdrawn.
193
+ Assets assets;
194
+ /// @custom:property The new owner for the assets.
195
+ Location beneficiary;
196
+ }
197
+
198
+ /// @notice Params for `TransferReserveAsset`.
199
+ struct TransferReserveAssetParams {
200
+ /// @custom:property The asset(s) to be withdrawn.
201
+ Assets assets;
202
+ /// @custom:property The location whose sovereign account will own the assets.
203
+ Location dest;
204
+ /// @custom:property Instructions that follow `ReserveAssetDeposited`. SCALE-encoded Xcm<()>.
205
+ bytes xcm;
206
+ }
207
+
208
+ /// @notice Params for `Transact`.
209
+ struct TransactParams {
210
+ /// @custom:property The means of expressing message origin as dispatch origin.
211
+ OriginKind originKind;
212
+ /// @custom:property Whether `fallbackMaxWeight` is present.
213
+ bool hasFallbackMaxWeight;
214
+ /// @custom:property Compatibility fallback weight, corresponding to v4 `require_weight_at_most`.
215
+ Weight fallbackMaxWeight;
216
+ /// @custom:property The raw encoded call bytes (`DoubleEncoded<Call>.encoded`, equivalent to Rust `Vec<u8>`). The `Transact` factory SCALE-encodes this as `Vec<u8>` (Compact length + bytes).
217
+ bytes call;
218
+ }
219
+
220
+ /// @notice Params for `HrmpNewChannelOpenRequest`.
221
+ struct HrmpNewChannelOpenRequestParams {
222
+ /// @custom:property The sender in the to-be-opened channel.
223
+ uint32 sender;
224
+ /// @custom:property The maximum size of a message proposed by the sender.
225
+ uint32 maxMessageSize;
226
+ /// @custom:property The maximum number of messages that can be queued in the channel.
227
+ uint32 maxCapacity;
228
+ }
229
+
230
+ /// @notice Params for `HrmpChannelAccepted`.
231
+ struct HrmpChannelAcceptedParams {
232
+ /// @custom:property The recipient whose open-channel request was accepted.
233
+ uint32 recipient;
234
+ }
235
+
236
+ /// @notice Params for `HrmpChannelClosing`.
237
+ struct HrmpChannelClosingParams {
238
+ /// @custom:property The party initiating the channel closure.
239
+ uint32 initiator;
240
+ /// @custom:property The channel sender.
241
+ uint32 sender;
242
+ /// @custom:property The channel recipient.
243
+ uint32 recipient;
244
+ }
245
+
246
+ /// @notice Params for `DescendOrigin`.
247
+ struct DescendOriginParams {
248
+ /// @custom:property Interior location to descend origin into.
249
+ Junctions interior;
250
+ }
251
+
252
+ /// @notice Params for `ReportError`.
253
+ struct ReportErrorParams {
254
+ /// @custom:property Information for constructing and sending the query response.
255
+ QueryResponseInfo responseInfo;
256
+ }
257
+
258
+ /// @notice Params for `DepositAsset`.
259
+ struct DepositAssetParams {
260
+ /// @custom:property Asset filter selecting assets removed from holding.
261
+ AssetFilter assets;
262
+ /// @custom:property The new owner for the assets.
263
+ Location beneficiary;
264
+ }
265
+
266
+ /// @notice Params for `DepositReserveAsset`.
267
+ struct DepositReserveAssetParams {
268
+ /// @custom:property Asset filter selecting assets removed from holding.
269
+ AssetFilter assets;
270
+ /// @custom:property The location whose sovereign account will own the assets.
271
+ Location dest;
272
+ /// @custom:property Orders that follow `ReserveAssetDeposited`. SCALE-encoded Xcm<()>.
273
+ bytes xcm;
274
+ }
275
+
276
+ /// @notice Params for `ExchangeAsset`.
277
+ struct ExchangeAssetParams {
278
+ /// @custom:property Maximum assets to remove from holding.
279
+ AssetFilter give;
280
+ /// @custom:property Minimum assets expected in exchange.
281
+ Assets want;
282
+ /// @custom:property If true, prefer maximal exchange up to `give`; otherwise minimal exchange satisfying `want`.
283
+ bool maximal;
284
+ }
285
+
286
+ /// @notice Params for `InitiateReserveWithdraw`.
287
+ struct InitiateReserveWithdrawParams {
288
+ /// @custom:property Asset filter selecting assets removed from holding.
289
+ AssetFilter assets;
290
+ /// @custom:property Reserve location for all selected assets.
291
+ Location reserve;
292
+ /// @custom:property Instructions to execute once withdrawn on reserve. SCALE-encoded Xcm<()>.
293
+ bytes xcm;
294
+ }
295
+
296
+ /// @notice Params for `InitiateTeleport`.
297
+ struct InitiateTeleportParams {
298
+ /// @custom:property Asset filter selecting assets removed from holding.
299
+ AssetFilter assets;
300
+ /// @custom:property Destination location that accepts teleports from this origin.
301
+ Location dest;
302
+ /// @custom:property Instructions to execute on destination. SCALE-encoded Xcm<()>.
303
+ bytes xcm;
304
+ }
305
+
306
+ /// @notice Params for `ReportHolding`.
307
+ struct ReportHoldingParams {
308
+ /// @custom:property Information for constructing and sending the query response.
309
+ QueryResponseInfo responseInfo;
310
+ /// @custom:property Filter over holdings to be reported.
311
+ AssetFilter assets;
312
+ }
313
+
314
+ /// @notice Params for `BuyExecution`.
315
+ struct BuyExecutionParams {
316
+ /// @custom:property The asset(s) used to pay fees.
317
+ Asset fees;
318
+ /// @custom:property The maximum amount of weight to purchase.
319
+ WeightLimit weightLimit;
320
+ }
321
+
322
+ /// @notice Params for `SetErrorHandler`.
323
+ struct SetErrorHandlerParams {
324
+ /// @custom:property Error handler code. SCALE-encoded Xcm<Call>.
325
+ bytes xcm;
326
+ }
327
+
328
+ /// @notice Params for `SetAppendix`.
329
+ struct SetAppendixParams {
330
+ /// @custom:property Appendix code executed after program completion. SCALE-encoded Xcm<Call>.
331
+ bytes xcm;
332
+ }
333
+
334
+ /// @notice Params for `ClaimAsset`.
335
+ struct ClaimAssetParams {
336
+ /// @custom:property Assets to claim; must exactly match claimable assets for ticket origin.
337
+ Assets assets;
338
+ /// @custom:property Ticket identifier used to locate the claimable asset.
339
+ Location ticket;
340
+ }
341
+
342
+ /// @notice Params for `Trap`.
343
+ struct TrapParams {
344
+ /// @custom:property Trap code used as the inner value of the `Trap` error.
345
+ uint64 code;
346
+ }
347
+
348
+ /// @notice Params for `SubscribeVersion`.
349
+ struct SubscribeVersionParams {
350
+ /// @custom:property Query identifier replicated into the response message.
351
+ QueryId queryId;
352
+ /// @custom:property Maximum weight allowed for the responding `QueryResponse` execution.
353
+ Weight maxResponseWeight;
354
+ }
355
+
356
+ /// @notice Params for `BurnAsset`.
357
+ struct BurnAssetParams {
358
+ /// @custom:property Assets to burn from holding up to the provided amount.
359
+ Assets assets;
360
+ }
361
+
362
+ /// @notice Params for `ExpectAsset`.
363
+ struct ExpectAssetParams {
364
+ /// @custom:property Assets that must be present in holding.
365
+ Assets assets;
366
+ }
367
+
368
+ /// @notice Params for `ExpectOrigin`.
369
+ struct ExpectOriginParams {
370
+ /// @custom:property Whether an expected origin is provided.
371
+ bool hasOrigin;
372
+ /// @custom:property Expected origin location when `hasOrigin` is true.
373
+ Location origin;
374
+ }
375
+
376
+ /// @notice Params for `ExpectError`.
377
+ struct ExpectErrorParams {
378
+ /// @custom:property Whether an expected error tuple is provided.
379
+ bool hasError;
380
+ /// @custom:property Expected instruction index when `hasError` is true.
381
+ uint32 index;
382
+ /// @custom:property Expected XCM error when `hasError` is true.
383
+ XcmError err;
384
+ }
385
+
386
+ /// @notice Params for `ExpectTransactStatus`.
387
+ struct ExpectTransactStatusParams {
388
+ /// @custom:property Expected transact status register value.
389
+ MaybeErrorCode transactStatus;
390
+ }
391
+
392
+ /// @notice Params for `QueryPallet`.
393
+ struct QueryPalletParams {
394
+ /// @custom:property Pallet module name to query.
395
+ bytes moduleName;
396
+ /// @custom:property Information for constructing and sending the query response.
397
+ QueryResponseInfo responseInfo;
398
+ }
399
+
400
+ /// @notice Params for `ExpectPallet`.
401
+ struct ExpectPalletParams {
402
+ /// @custom:property Expected pallet index.
403
+ uint32 index;
404
+ /// @custom:property Expected pallet name.
405
+ bytes name;
406
+ /// @custom:property Expected pallet module name.
407
+ bytes moduleName;
408
+ /// @custom:property Expected crate major version.
409
+ uint32 crateMajor;
410
+ /// @custom:property Minimum acceptable crate minor version.
411
+ uint32 minCrateMinor;
412
+ }
413
+
414
+ /// @notice Params for `ReportTransactStatus`.
415
+ struct ReportTransactStatusParams {
416
+ /// @custom:property Information for constructing and sending the query response.
417
+ QueryResponseInfo responseInfo;
418
+ }
419
+
420
+ /// @notice Params for `UniversalOrigin`.
421
+ struct UniversalOriginParams {
422
+ /// @custom:property Child junction of the Universal Ancestor to set as origin.
423
+ Junction junction;
424
+ }
425
+
426
+ /// @notice Params for `ExportMessage`.
427
+ struct ExportMessageParams {
428
+ /// @custom:property Remote consensus system to export to.
429
+ NetworkId network;
430
+ /// @custom:property Destination interior location relative to the remote consensus system.
431
+ Junctions destination;
432
+ /// @custom:property Message to export. SCALE-encoded Xcm<()>.
433
+ bytes xcm;
434
+ }
435
+
436
+ /// @notice Params for `LockAsset`.
437
+ struct LockAssetParams {
438
+ /// @custom:property Asset to lock.
439
+ Asset asset;
440
+ /// @custom:property Origin required to unlock via a corresponding `UnlockAsset`.
441
+ Location unlocker;
442
+ }
443
+
444
+ /// @notice Params for `UnlockAsset`.
445
+ struct UnlockAssetParams {
446
+ /// @custom:property Asset to unlock.
447
+ Asset asset;
448
+ /// @custom:property Asset owner on the local chain.
449
+ Location target;
450
+ }
451
+
452
+ /// @notice Params for `NoteUnlockable`.
453
+ struct NoteUnlockableParams {
454
+ /// @custom:property Asset that is now unlockable from this origin.
455
+ Asset asset;
456
+ /// @custom:property Owner of the asset on the chain where it was locked.
457
+ Location owner;
458
+ }
459
+
460
+ /// @notice Params for `RequestUnlock`.
461
+ struct RequestUnlockParams {
462
+ /// @custom:property Asset requested for unlock.
463
+ Asset asset;
464
+ /// @custom:property Location of the locker from prior `NoteUnlockable`.
465
+ Location locker;
466
+ }
467
+
468
+ /// @notice Params for `SetFeesMode`.
469
+ struct SetFeesModeParams {
470
+ /// @custom:property If true, fees are withdrawn just-in-time for instructions.
471
+ bool jitWithdraw;
472
+ }
473
+
474
+ /// @notice Params for `SetTopic`.
475
+ struct SetTopicParams {
476
+ /// @custom:property 32-byte topic identifier.
477
+ bytes32 topic;
478
+ }
479
+
480
+ /// @notice Params for `AliasOrigin`.
481
+ struct AliasOriginParams {
482
+ /// @custom:property New origin to alias to.
483
+ Location location;
484
+ }
485
+
486
+ /// @notice Params for `UnpaidExecution`.
487
+ struct UnpaidExecutionParams {
488
+ /// @custom:property Free-execution weight limit.
489
+ WeightLimit weightLimit;
490
+ /// @custom:property Whether a specific origin check is required.
491
+ bool hasCheckOrigin;
492
+ /// @custom:property Expected origin when `hasCheckOrigin` is true.
493
+ Location checkOrigin;
494
+ }
495
+
496
+ /// @notice Params for `PayFees`.
497
+ struct PayFeesParams {
498
+ /// @custom:property Asset used to pay execution fees.
499
+ Asset asset;
500
+ }
501
+
502
+ /// @notice Params for `InitiateTransfer`.
503
+ struct InitiateTransferParams {
504
+ /// @custom:property Location of the program next hop.
505
+ Location destination;
506
+ /// @custom:property Whether `remoteFees` is provided.
507
+ bool hasRemoteFees;
508
+ /// @custom:property Optional fee-reserved transfer filter used first on remote side.
509
+ AssetTransferFilter remoteFees;
510
+ /// @custom:property Whether to preserve origin (`AliasOrigin`) instead of clearing it.
511
+ bool preserveOrigin;
512
+ /// @custom:property Transfer filters matched against holding assets for this leg.
513
+ AssetTransferFilter[] assets;
514
+ /// @custom:property Custom instructions to run on destination. SCALE-encoded Xcm<()>.
515
+ bytes remoteXcm;
516
+ }
517
+
518
+ /// @notice Params for `ExecuteWithOrigin`.
519
+ struct ExecuteWithOriginParams {
520
+ /// @custom:property Whether `descendantOrigin` is provided.
521
+ bool hasDescendantOrigin;
522
+ /// @custom:property Optional descendant origin for executing inner XCM.
523
+ Junctions descendantOrigin;
524
+ /// @custom:property Inner instructions executed under the derived origin. SCALE-encoded Xcm<Call>.
525
+ bytes xcm;
526
+ }
527
+
528
+ /// @notice Params for `SetHints`.
529
+ struct SetHintsParams {
530
+ /// @custom:property A bounded vector of execution hints.
531
+ Hint[] hints;
532
+ }
533
+
534
+ /// @notice Cross-Consensus Message: A message from one consensus system to another.
535
+ /// @dev This is the inner XCM format and is version-sensitive. Messages are typically passed using the outer XCM format, known as `VersionedXcm`.
536
+ struct Instruction {
537
+ /// @custom:property The type of the instruction. See `InstructionType` enum for possible values.
538
+ InstructionType iType;
539
+ /// @custom:property SCALE-encoded instruction parameters. The type of the parameters depends on the instruction type; see the corresponding `Params` struct for each variant.
540
+ bytes payload;
541
+ }
542
+
543
+ // ============ Factory Functions ============
544
+
545
+ /// @notice Creates an `Instruction` struct representing the `WithdrawAsset` variant with the provided `params`.
546
+ function withdrawAsset(
547
+ WithdrawAssetParams memory params
548
+ ) pure returns (Instruction memory) {
549
+ return
550
+ Instruction({
551
+ iType: InstructionType.WithdrawAsset,
552
+ payload: AssetsCodec.encode(params.assets)
553
+ });
554
+ }
555
+
556
+ /// @notice Creates an `Instruction` struct representing the `ReserveAssetDeposited` variant with the provided `params`.
557
+ function reserveAssetDeposited(
558
+ ReserveAssetDepositedParams memory params
559
+ ) pure returns (Instruction memory) {
560
+ return
561
+ Instruction({
562
+ iType: InstructionType.ReserveAssetDeposited,
563
+ payload: AssetsCodec.encode(params.assets)
564
+ });
565
+ }
566
+
567
+ /// @notice Creates an `Instruction` struct representing the `ReceiveTeleportedAsset` variant with the provided `params`.
568
+ function receiveTeleportedAsset(
569
+ ReceiveTeleportedAssetParams memory params
570
+ ) pure returns (Instruction memory) {
571
+ return
572
+ Instruction({
573
+ iType: InstructionType.ReceiveTeleportedAsset,
574
+ payload: AssetsCodec.encode(params.assets)
575
+ });
576
+ }
577
+
578
+ /// @notice Creates an `Instruction` struct representing the `QueryResponse` variant with the provided `params`.
579
+ function queryResponse(
580
+ QueryResponseParams memory params
581
+ ) pure returns (Instruction memory) {
582
+ bytes memory payload = abi.encodePacked(
583
+ Compact.encode(uint256(QueryId.unwrap(params.queryId))),
584
+ ResponseCodec.encode(params.response),
585
+ WeightCodec.encode(params.maxWeight),
586
+ Bool.encode(params.hasQuerier)
587
+ );
588
+ if (params.hasQuerier) {
589
+ payload = abi.encodePacked(
590
+ payload,
591
+ LocationCodec.encode(params.querier)
592
+ );
593
+ }
594
+ return
595
+ Instruction({iType: InstructionType.QueryResponse, payload: payload});
596
+ }
597
+
598
+ /// @notice Creates an `Instruction` struct representing the `TransferAsset` variant with the provided `params`.
599
+ function transferAsset(
600
+ TransferAssetParams memory params
601
+ ) pure returns (Instruction memory) {
602
+ return
603
+ Instruction({
604
+ iType: InstructionType.TransferAsset,
605
+ payload: abi.encodePacked(
606
+ AssetsCodec.encode(params.assets),
607
+ LocationCodec.encode(params.beneficiary)
608
+ )
609
+ });
610
+ }
611
+
612
+ /// @notice Creates an `Instruction` struct representing the `TransferReserveAsset` variant with the provided `params`.
613
+ function transferReserveAsset(
614
+ TransferReserveAssetParams memory params
615
+ ) pure returns (Instruction memory) {
616
+ return
617
+ Instruction({
618
+ iType: InstructionType.TransferReserveAsset,
619
+ payload: abi.encodePacked(
620
+ AssetsCodec.encode(params.assets),
621
+ LocationCodec.encode(params.dest),
622
+ params.xcm
623
+ )
624
+ });
625
+ }
626
+
627
+ /// @notice Creates an `Instruction` struct representing the `Transact` variant with the provided `params`.
628
+ function transact(
629
+ TransactParams memory params
630
+ ) pure returns (Instruction memory) {
631
+ bytes memory payload = abi.encodePacked(
632
+ OriginKindCodec.encode(params.originKind),
633
+ Bool.encode(params.hasFallbackMaxWeight)
634
+ );
635
+ if (params.hasFallbackMaxWeight) {
636
+ payload = abi.encodePacked(
637
+ payload,
638
+ WeightCodec.encode(params.fallbackMaxWeight)
639
+ );
640
+ }
641
+ payload = abi.encodePacked(payload, Bytes.encode(params.call));
642
+ return Instruction({iType: InstructionType.Transact, payload: payload});
643
+ }
644
+
645
+ /// @notice Creates an `Instruction` struct representing the `HrmpNewChannelOpenRequest` variant with the provided `params`.
646
+ function hrmpNewChannelOpenRequest(
647
+ HrmpNewChannelOpenRequestParams memory params
648
+ ) pure returns (Instruction memory) {
649
+ return
650
+ Instruction({
651
+ iType: InstructionType.HrmpNewChannelOpenRequest,
652
+ payload: abi.encodePacked(
653
+ Compact.encode(params.sender),
654
+ Compact.encode(params.maxMessageSize),
655
+ Compact.encode(params.maxCapacity)
656
+ )
657
+ });
658
+ }
659
+
660
+ /// @notice Creates an `Instruction` struct representing the `HrmpChannelAccepted` variant with the provided `params`.
661
+ function hrmpChannelAccepted(
662
+ HrmpChannelAcceptedParams memory params
663
+ ) pure returns (Instruction memory) {
664
+ return
665
+ Instruction({
666
+ iType: InstructionType.HrmpChannelAccepted,
667
+ payload: Compact.encode(params.recipient)
668
+ });
669
+ }
670
+
671
+ /// @notice Creates an `Instruction` struct representing the `HrmpChannelClosing` variant with the provided `params`.
672
+ function hrmpChannelClosing(
673
+ HrmpChannelClosingParams memory params
674
+ ) pure returns (Instruction memory) {
675
+ return
676
+ Instruction({
677
+ iType: InstructionType.HrmpChannelClosing,
678
+ payload: abi.encodePacked(
679
+ Compact.encode(params.initiator),
680
+ Compact.encode(params.sender),
681
+ Compact.encode(params.recipient)
682
+ )
683
+ });
684
+ }
685
+
686
+ /// @notice Creates an `Instruction` struct representing the `ClearOrigin` variant.
687
+ function clearOrigin() pure returns (Instruction memory) {
688
+ return Instruction({iType: InstructionType.ClearOrigin, payload: ""});
689
+ }
690
+
691
+ /// @notice Creates an `Instruction` struct representing the `DescendOrigin` variant with the provided `params`.
692
+ function descendOrigin(
693
+ DescendOriginParams memory params
694
+ ) pure returns (Instruction memory) {
695
+ return
696
+ Instruction({
697
+ iType: InstructionType.DescendOrigin,
698
+ payload: JunctionsCodec.encode(params.interior)
699
+ });
700
+ }
701
+
702
+ /// @notice Creates an `Instruction` struct representing the `ReportError` variant with the provided `params`.
703
+ function reportError(
704
+ ReportErrorParams memory params
705
+ ) pure returns (Instruction memory) {
706
+ return
707
+ Instruction({
708
+ iType: InstructionType.ReportError,
709
+ payload: QueryResponseInfoCodec.encode(params.responseInfo)
710
+ });
711
+ }
712
+
713
+ /// @notice Creates an `Instruction` struct representing the `DepositAsset` variant with the provided `params`.
714
+ function depositAsset(
715
+ DepositAssetParams memory params
716
+ ) pure returns (Instruction memory) {
717
+ return
718
+ Instruction({
719
+ iType: InstructionType.DepositAsset,
720
+ payload: abi.encodePacked(
721
+ AssetFilterCodec.encode(params.assets),
722
+ LocationCodec.encode(params.beneficiary)
723
+ )
724
+ });
725
+ }
726
+
727
+ /// @notice Creates an `Instruction` struct representing the `DepositReserveAsset` variant with the provided `params`.
728
+ function depositReserveAsset(
729
+ DepositReserveAssetParams memory params
730
+ ) pure returns (Instruction memory) {
731
+ return
732
+ Instruction({
733
+ iType: InstructionType.DepositReserveAsset,
734
+ payload: abi.encodePacked(
735
+ AssetFilterCodec.encode(params.assets),
736
+ LocationCodec.encode(params.dest),
737
+ params.xcm
738
+ )
739
+ });
740
+ }
741
+
742
+ /// @notice Creates an `Instruction` struct representing the `ExchangeAsset` variant with the provided `params`.
743
+ function exchangeAsset(
744
+ ExchangeAssetParams memory params
745
+ ) pure returns (Instruction memory) {
746
+ return
747
+ Instruction({
748
+ iType: InstructionType.ExchangeAsset,
749
+ payload: abi.encodePacked(
750
+ AssetFilterCodec.encode(params.give),
751
+ AssetsCodec.encode(params.want),
752
+ Bool.encode(params.maximal)
753
+ )
754
+ });
755
+ }
756
+
757
+ /// @notice Creates an `Instruction` struct representing the `InitiateReserveWithdraw` variant with the provided `params`.
758
+ function initiateReserveWithdraw(
759
+ InitiateReserveWithdrawParams memory params
760
+ ) pure returns (Instruction memory) {
761
+ return
762
+ Instruction({
763
+ iType: InstructionType.InitiateReserveWithdraw,
764
+ payload: abi.encodePacked(
765
+ AssetFilterCodec.encode(params.assets),
766
+ LocationCodec.encode(params.reserve),
767
+ params.xcm
768
+ )
769
+ });
770
+ }
771
+
772
+ /// @notice Creates an `Instruction` struct representing the `InitiateTeleport` variant with the provided `params`.
773
+ function initiateTeleport(
774
+ InitiateTeleportParams memory params
775
+ ) pure returns (Instruction memory) {
776
+ return
777
+ Instruction({
778
+ iType: InstructionType.InitiateTeleport,
779
+ payload: abi.encodePacked(
780
+ AssetFilterCodec.encode(params.assets),
781
+ LocationCodec.encode(params.dest),
782
+ params.xcm
783
+ )
784
+ });
785
+ }
786
+
787
+ /// @notice Creates an `Instruction` struct representing the `ReportHolding` variant with the provided `params`.
788
+ function reportHolding(
789
+ ReportHoldingParams memory params
790
+ ) pure returns (Instruction memory) {
791
+ return
792
+ Instruction({
793
+ iType: InstructionType.ReportHolding,
794
+ payload: abi.encodePacked(
795
+ QueryResponseInfoCodec.encode(params.responseInfo),
796
+ AssetFilterCodec.encode(params.assets)
797
+ )
798
+ });
799
+ }
800
+
801
+ /// @notice Creates an `Instruction` struct representing the `BuyExecution` variant with the provided `params`.
802
+ function buyExecution(
803
+ BuyExecutionParams memory params
804
+ ) pure returns (Instruction memory) {
805
+ return
806
+ Instruction({
807
+ iType: InstructionType.BuyExecution,
808
+ payload: abi.encodePacked(
809
+ AssetCodec.encode(params.fees),
810
+ WeightLimitCodec.encode(params.weightLimit)
811
+ )
812
+ });
813
+ }
814
+
815
+ /// @notice Creates an `Instruction` struct representing the `RefundSurplus` variant.
816
+ function refundSurplus() pure returns (Instruction memory) {
817
+ return Instruction({iType: InstructionType.RefundSurplus, payload: ""});
818
+ }
819
+
820
+ /// @notice Creates an `Instruction` struct representing the `SetErrorHandler` variant with the provided `params`.
821
+ function setErrorHandler(
822
+ SetErrorHandlerParams memory params
823
+ ) pure returns (Instruction memory) {
824
+ return
825
+ Instruction({
826
+ iType: InstructionType.SetErrorHandler,
827
+ payload: params.xcm
828
+ });
829
+ }
830
+
831
+ /// @notice Creates an `Instruction` struct representing the `SetAppendix` variant with the provided `params`.
832
+ function setAppendix(
833
+ SetAppendixParams memory params
834
+ ) pure returns (Instruction memory) {
835
+ return
836
+ Instruction({iType: InstructionType.SetAppendix, payload: params.xcm});
837
+ }
838
+
839
+ /// @notice Creates an `Instruction` struct representing the `ClearError` variant.
840
+ function clearError() pure returns (Instruction memory) {
841
+ return Instruction({iType: InstructionType.ClearError, payload: ""});
842
+ }
843
+
844
+ /// @notice Creates an `Instruction` struct representing the `ClaimAsset` variant with the provided `params`.
845
+ function claimAsset(
846
+ ClaimAssetParams memory params
847
+ ) pure returns (Instruction memory) {
848
+ return
849
+ Instruction({
850
+ iType: InstructionType.ClaimAsset,
851
+ payload: abi.encodePacked(
852
+ AssetsCodec.encode(params.assets),
853
+ LocationCodec.encode(params.ticket)
854
+ )
855
+ });
856
+ }
857
+
858
+ /// @notice Creates an `Instruction` struct representing the `Trap` variant with the provided `params`.
859
+ function trap(TrapParams memory params) pure returns (Instruction memory) {
860
+ return
861
+ Instruction({
862
+ iType: InstructionType.Trap,
863
+ payload: Compact.encode(params.code)
864
+ });
865
+ }
866
+
867
+ /// @notice Creates an `Instruction` struct representing the `SubscribeVersion` variant with the provided `params`.
868
+ function subscribeVersion(
869
+ SubscribeVersionParams memory params
870
+ ) pure returns (Instruction memory) {
871
+ return
872
+ Instruction({
873
+ iType: InstructionType.SubscribeVersion,
874
+ payload: abi.encodePacked(
875
+ Compact.encode(uint256(QueryId.unwrap(params.queryId))),
876
+ WeightCodec.encode(params.maxResponseWeight)
877
+ )
878
+ });
879
+ }
880
+
881
+ /// @notice Creates an `Instruction` struct representing the `UnsubscribeVersion` variant.
882
+ function unsubscribeVersion() pure returns (Instruction memory) {
883
+ return
884
+ Instruction({iType: InstructionType.UnsubscribeVersion, payload: ""});
885
+ }
886
+
887
+ /// @notice Creates an `Instruction` struct representing the `BurnAsset` variant with the provided `params`.
888
+ function burnAsset(
889
+ BurnAssetParams memory params
890
+ ) pure returns (Instruction memory) {
891
+ return
892
+ Instruction({
893
+ iType: InstructionType.BurnAsset,
894
+ payload: AssetsCodec.encode(params.assets)
895
+ });
896
+ }
897
+
898
+ /// @notice Creates an `Instruction` struct representing the `ExpectAsset` variant with the provided `params`.
899
+ function expectAsset(
900
+ ExpectAssetParams memory params
901
+ ) pure returns (Instruction memory) {
902
+ return
903
+ Instruction({
904
+ iType: InstructionType.ExpectAsset,
905
+ payload: AssetsCodec.encode(params.assets)
906
+ });
907
+ }
908
+
909
+ /// @notice Creates an `Instruction` struct representing the `ExpectOrigin` variant with the provided `params`.
910
+ function expectOrigin(
911
+ ExpectOriginParams memory params
912
+ ) pure returns (Instruction memory) {
913
+ bytes memory payload = Bool.encode(params.hasOrigin);
914
+ if (params.hasOrigin) {
915
+ payload = abi.encodePacked(
916
+ payload,
917
+ LocationCodec.encode(params.origin)
918
+ );
919
+ }
920
+ return Instruction({iType: InstructionType.ExpectOrigin, payload: payload});
921
+ }
922
+
923
+ /// @notice Creates an `Instruction` struct representing the `ExpectError` variant with the provided `params`.
924
+ function expectError(
925
+ ExpectErrorParams memory params
926
+ ) pure returns (Instruction memory) {
927
+ bytes memory payload = Bool.encode(params.hasError);
928
+ if (params.hasError) {
929
+ payload = abi.encodePacked(
930
+ payload,
931
+ Compact.encode(params.index),
932
+ XcmErrorCodec.encode(params.err)
933
+ );
934
+ }
935
+ return Instruction({iType: InstructionType.ExpectError, payload: payload});
936
+ }
937
+
938
+ /// @notice Creates an `Instruction` struct representing the `ExpectTransactStatus` variant with the provided `params`.
939
+ function expectTransactStatus(
940
+ ExpectTransactStatusParams memory params
941
+ ) pure returns (Instruction memory) {
942
+ return
943
+ Instruction({
944
+ iType: InstructionType.ExpectTransactStatus,
945
+ payload: MaybeErrorCodeCodec.encode(params.transactStatus)
946
+ });
947
+ }
948
+
949
+ /// @notice Creates an `Instruction` struct representing the `QueryPallet` variant with the provided `params`.
950
+ function queryPallet(
951
+ QueryPalletParams memory params
952
+ ) pure returns (Instruction memory) {
953
+ return
954
+ Instruction({
955
+ iType: InstructionType.QueryPallet,
956
+ payload: abi.encodePacked(
957
+ Bytes.encode(params.moduleName),
958
+ QueryResponseInfoCodec.encode(params.responseInfo)
959
+ )
960
+ });
961
+ }
962
+
963
+ /// @notice Creates an `Instruction` struct representing the `ExpectPallet` variant with the provided `params`.
964
+ function expectPallet(
965
+ ExpectPalletParams memory params
966
+ ) pure returns (Instruction memory) {
967
+ return
968
+ Instruction({
969
+ iType: InstructionType.ExpectPallet,
970
+ payload: abi.encodePacked(
971
+ Compact.encode(params.index),
972
+ Bytes.encode(params.name),
973
+ Bytes.encode(params.moduleName),
974
+ Compact.encode(params.crateMajor),
975
+ Compact.encode(params.minCrateMinor)
976
+ )
977
+ });
978
+ }
979
+
980
+ /// @notice Creates an `Instruction` struct representing the `ReportTransactStatus` variant with the provided `params`.
981
+ function reportTransactStatus(
982
+ ReportTransactStatusParams memory params
983
+ ) pure returns (Instruction memory) {
984
+ return
985
+ Instruction({
986
+ iType: InstructionType.ReportTransactStatus,
987
+ payload: QueryResponseInfoCodec.encode(params.responseInfo)
988
+ });
989
+ }
990
+
991
+ /// @notice Creates an `Instruction` struct representing the `ClearTransactStatus` variant.
992
+ function clearTransactStatus() pure returns (Instruction memory) {
993
+ return
994
+ Instruction({iType: InstructionType.ClearTransactStatus, payload: ""});
995
+ }
996
+
997
+ /// @notice Creates an `Instruction` struct representing the `UniversalOrigin` variant with the provided `params`.
998
+ function universalOrigin(
999
+ UniversalOriginParams memory params
1000
+ ) pure returns (Instruction memory) {
1001
+ return
1002
+ Instruction({
1003
+ iType: InstructionType.UniversalOrigin,
1004
+ payload: JunctionCodec.encode(params.junction)
1005
+ });
1006
+ }
1007
+
1008
+ /// @notice Creates an `Instruction` struct representing the `ExportMessage` variant with the provided `params`.
1009
+ function exportMessage(
1010
+ ExportMessageParams memory params
1011
+ ) pure returns (Instruction memory) {
1012
+ return
1013
+ Instruction({
1014
+ iType: InstructionType.ExportMessage,
1015
+ payload: abi.encodePacked(
1016
+ NetworkIdCodec.encode(params.network),
1017
+ JunctionsCodec.encode(params.destination),
1018
+ params.xcm
1019
+ )
1020
+ });
1021
+ }
1022
+
1023
+ /// @notice Creates an `Instruction` struct representing the `LockAsset` variant with the provided `params`.
1024
+ function lockAsset(
1025
+ LockAssetParams memory params
1026
+ ) pure returns (Instruction memory) {
1027
+ return
1028
+ Instruction({
1029
+ iType: InstructionType.LockAsset,
1030
+ payload: abi.encodePacked(
1031
+ AssetCodec.encode(params.asset),
1032
+ LocationCodec.encode(params.unlocker)
1033
+ )
1034
+ });
1035
+ }
1036
+
1037
+ /// @notice Creates an `Instruction` struct representing the `UnlockAsset` variant with the provided `params`.
1038
+ function unlockAsset(
1039
+ UnlockAssetParams memory params
1040
+ ) pure returns (Instruction memory) {
1041
+ return
1042
+ Instruction({
1043
+ iType: InstructionType.UnlockAsset,
1044
+ payload: abi.encodePacked(
1045
+ AssetCodec.encode(params.asset),
1046
+ LocationCodec.encode(params.target)
1047
+ )
1048
+ });
1049
+ }
1050
+
1051
+ /// @notice Creates an `Instruction` struct representing the `NoteUnlockable` variant with the provided `params`.
1052
+ function noteUnlockable(
1053
+ NoteUnlockableParams memory params
1054
+ ) pure returns (Instruction memory) {
1055
+ return
1056
+ Instruction({
1057
+ iType: InstructionType.NoteUnlockable,
1058
+ payload: abi.encodePacked(
1059
+ AssetCodec.encode(params.asset),
1060
+ LocationCodec.encode(params.owner)
1061
+ )
1062
+ });
1063
+ }
1064
+
1065
+ /// @notice Creates an `Instruction` struct representing the `RequestUnlock` variant with the provided `params`.
1066
+ function requestUnlock(
1067
+ RequestUnlockParams memory params
1068
+ ) pure returns (Instruction memory) {
1069
+ return
1070
+ Instruction({
1071
+ iType: InstructionType.RequestUnlock,
1072
+ payload: abi.encodePacked(
1073
+ AssetCodec.encode(params.asset),
1074
+ LocationCodec.encode(params.locker)
1075
+ )
1076
+ });
1077
+ }
1078
+
1079
+ /// @notice Creates an `Instruction` struct representing the `SetFeesMode` variant with the provided `params`.
1080
+ function setFeesMode(
1081
+ SetFeesModeParams memory params
1082
+ ) pure returns (Instruction memory) {
1083
+ return
1084
+ Instruction({
1085
+ iType: InstructionType.SetFeesMode,
1086
+ payload: Bool.encode(params.jitWithdraw)
1087
+ });
1088
+ }
1089
+
1090
+ /// @notice Creates an `Instruction` struct representing the `SetTopic` variant with the provided `params`.
1091
+ function setTopic(
1092
+ SetTopicParams memory params
1093
+ ) pure returns (Instruction memory) {
1094
+ return
1095
+ Instruction({
1096
+ iType: InstructionType.SetTopic,
1097
+ payload: Bytes32.encode(params.topic)
1098
+ });
1099
+ }
1100
+
1101
+ /// @notice Creates an `Instruction` struct representing the `ClearTopic` variant.
1102
+ function clearTopic() pure returns (Instruction memory) {
1103
+ return Instruction({iType: InstructionType.ClearTopic, payload: ""});
1104
+ }
1105
+
1106
+ /// @notice Creates an `Instruction` struct representing the `AliasOrigin` variant with the provided `params`.
1107
+ function aliasOrigin(
1108
+ AliasOriginParams memory params
1109
+ ) pure returns (Instruction memory) {
1110
+ return
1111
+ Instruction({
1112
+ iType: InstructionType.AliasOrigin,
1113
+ payload: LocationCodec.encode(params.location)
1114
+ });
1115
+ }
1116
+
1117
+ /// @notice Creates an `Instruction` struct representing the `UnpaidExecution` variant with the provided `params`.
1118
+ function unpaidExecution(
1119
+ UnpaidExecutionParams memory params
1120
+ ) pure returns (Instruction memory) {
1121
+ bytes memory payload = abi.encodePacked(
1122
+ WeightLimitCodec.encode(params.weightLimit),
1123
+ Bool.encode(params.hasCheckOrigin)
1124
+ );
1125
+ if (params.hasCheckOrigin) {
1126
+ payload = abi.encodePacked(
1127
+ payload,
1128
+ LocationCodec.encode(params.checkOrigin)
1129
+ );
1130
+ }
1131
+ return
1132
+ Instruction({iType: InstructionType.UnpaidExecution, payload: payload});
1133
+ }
1134
+
1135
+ /// @notice Creates an `Instruction` struct representing the `PayFees` variant with the provided `params`.
1136
+ function payFees(
1137
+ PayFeesParams memory params
1138
+ ) pure returns (Instruction memory) {
1139
+ return
1140
+ Instruction({
1141
+ iType: InstructionType.PayFees,
1142
+ payload: AssetCodec.encode(params.asset)
1143
+ });
1144
+ }
1145
+
1146
+ /// @notice Creates an `Instruction` struct representing the `InitiateTransfer` variant with the provided `params`.
1147
+ function initiateTransfer(
1148
+ InitiateTransferParams memory params
1149
+ ) pure returns (Instruction memory) {
1150
+ if (params.assets.length > MAX_ASSET_TRANSFER_FILTERS) {
1151
+ revert InvalidInstruction();
1152
+ }
1153
+ bytes memory payload = abi.encodePacked(
1154
+ LocationCodec.encode(params.destination),
1155
+ Bool.encode(params.hasRemoteFees)
1156
+ );
1157
+ if (params.hasRemoteFees) {
1158
+ payload = abi.encodePacked(
1159
+ payload,
1160
+ AssetTransferFilterCodec.encode(params.remoteFees)
1161
+ );
1162
+ }
1163
+ payload = abi.encodePacked(
1164
+ payload,
1165
+ Bool.encode(params.preserveOrigin),
1166
+ Compact.encode(params.assets.length)
1167
+ );
1168
+ for (uint256 i = 0; i < params.assets.length; i++) {
1169
+ payload = abi.encodePacked(
1170
+ payload,
1171
+ AssetTransferFilterCodec.encode(params.assets[i])
1172
+ );
1173
+ }
1174
+ payload = abi.encodePacked(
1175
+ payload,
1176
+ Compact.encode(params.remoteXcm.length),
1177
+ params.remoteXcm
1178
+ );
1179
+ return
1180
+ Instruction({
1181
+ iType: InstructionType.InitiateTransfer,
1182
+ payload: payload
1183
+ });
1184
+ }
1185
+
1186
+ /// @notice Creates an `Instruction` struct representing the `ExecuteWithOrigin` variant with the provided `params`.
1187
+ function executeWithOrigin(
1188
+ ExecuteWithOriginParams memory params
1189
+ ) pure returns (Instruction memory) {
1190
+ bytes memory payload = Bool.encode(params.hasDescendantOrigin);
1191
+ if (params.hasDescendantOrigin) {
1192
+ payload = abi.encodePacked(
1193
+ payload,
1194
+ JunctionsCodec.encode(params.descendantOrigin)
1195
+ );
1196
+ }
1197
+ payload = abi.encodePacked(payload, params.xcm);
1198
+ return
1199
+ Instruction({
1200
+ iType: InstructionType.ExecuteWithOrigin,
1201
+ payload: payload
1202
+ });
1203
+ }
1204
+
1205
+ /// @notice Creates an `Instruction` struct representing the `SetHints` variant with the provided `params`.
1206
+ function setHints(
1207
+ SetHintsParams memory params
1208
+ ) pure returns (Instruction memory) {
1209
+ if (params.hints.length > HINT_NUM_VARIANTS) {
1210
+ revert InvalidInstruction();
1211
+ }
1212
+ bytes memory payload = Compact.encode(params.hints.length);
1213
+ for (uint256 i = 0; i < params.hints.length; i++) {
1214
+ payload = abi.encodePacked(payload, HintCodec.encode(params.hints[i]));
1215
+ }
1216
+ return Instruction({iType: InstructionType.SetHints, payload: payload});
1217
+ }