solidity-scale-codec 2.0.0 → 2.1.1
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/Scale/Array/BoolArr.sol +3 -3
- package/src/Scale/Array/I128Arr.sol +3 -3
- package/src/Scale/Array/I16Arr.sol +3 -3
- package/src/Scale/Array/I256Arr.sol +3 -3
- package/src/Scale/Array/I32Arr.sol +3 -3
- package/src/Scale/Array/I64Arr.sol +3 -3
- package/src/Scale/Array/I8Arr.sol +3 -3
- package/src/Scale/Array/U128Arr.sol +3 -3
- package/src/Scale/Array/U16Arr.sol +3 -3
- package/src/Scale/Array/U256Arr.sol +3 -3
- package/src/Scale/Array/U32Arr.sol +3 -3
- package/src/Scale/Array/U64Arr.sol +3 -3
- package/src/Scale/Array/U8Arr.sol +3 -3
- package/src/Scale/Array.sol +15 -14
- package/src/Scale/Compact/Compact.sol +4 -2
- package/src/Scale/Signed/I128.sol +9 -14
- package/src/Scale/Signed/I16.sol +8 -11
- package/src/Scale/Signed/I256.sol +9 -14
- package/src/Scale/Signed/I32.sol +8 -11
- package/src/Scale/Signed/I64.sol +8 -11
- package/src/Scale/Signed/I8.sol +8 -11
- package/src/Scale/Signed.sol +8 -7
- package/src/Scale/Unsigned.sol +8 -7
- package/src/Xcm/v3/MaybeErrorCode/MaybeErrorCodeCodec.sol +1 -6
- package/src/Xcm/v5/AssetFilter/AssetFilterCodec.sol +1 -6
- package/src/Xcm/v5/AssetInstance/AssetInstanceCodec.sol +1 -9
- package/src/Xcm/v5/AssetTransferFilter/AssetTransferFilterCodec.sol +1 -7
- package/src/Xcm/v5/BodyId/BodyIdCodec.sol +1 -1
- package/src/Xcm/v5/BodyPart/BodyPartCodec.sol +1 -8
- package/src/Xcm/v5/Fungibility/FungibilityCodec.sol +1 -6
- package/src/Xcm/v5/Instruction/InstructionCodec.sol +1246 -1295
- package/src/Xcm/v5/Junction/Junction.sol +22 -5
- package/src/Xcm/v5/Junction/JunctionCodec.sol +16 -17
- package/src/Xcm/v5/NetworkId/NetworkIdCodec.sol +8 -8
- package/src/Xcm/v5/Response/ResponseCodec.sol +1 -9
- package/src/Xcm/v5/WeightLimit/WeightLimitCodec.sol +1 -5
- package/src/Xcm/v5/WildAsset/WildAssetCodec.sol +1 -7
- package/src/Xcm/v5/Xcm/XcmBuilder.sol +1 -101
|
@@ -99,6 +99,12 @@ struct GeneralIndexParams {
|
|
|
99
99
|
uint128 index;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/// @notice Parameters for a `GlobalConsensus` junction.
|
|
103
|
+
struct GlobalConsensusParams {
|
|
104
|
+
/// @custom:property The `NetworkId` associated with the global consensus, See `NetworkId` struct for details.
|
|
105
|
+
NetworkId network;
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
/// @notice A single item in a path to describe the relative location of a consensus system. Each item assumes a pre-existing location as its context and is defined in terms of it.
|
|
103
109
|
struct Junction {
|
|
104
110
|
/// @custom:property variant The type of the junction, determining how to interpret the payload. See `JunctionVariant` enum for possible values.
|
|
@@ -203,11 +209,9 @@ function generalIndex(
|
|
|
203
209
|
function generalKey(
|
|
204
210
|
GeneralKeyParams memory params
|
|
205
211
|
) pure returns (Junction memory) {
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
params.key.length != params.length
|
|
210
|
-
) revert InvalidJunctionPayload();
|
|
212
|
+
if (params.length == 0 || params.length > 32) {
|
|
213
|
+
revert InvalidJunctionPayload();
|
|
214
|
+
}
|
|
211
215
|
return
|
|
212
216
|
Junction({
|
|
213
217
|
variant: JunctionVariant.GeneralKey,
|
|
@@ -221,6 +225,19 @@ function onlyChild() pure returns (Junction memory) {
|
|
|
221
225
|
return Junction({variant: JunctionVariant.OnlyChild, payload: ""});
|
|
222
226
|
}
|
|
223
227
|
|
|
228
|
+
/// @notice Creates a `GlobalConsensus` junction, which represents a global network capable of externalizing its own consensus.
|
|
229
|
+
/// @param params Parameters for the global consensus variant.
|
|
230
|
+
/// @return A `Junction` struct representing the `GlobalConsensus` junction, with the encoded network payload.
|
|
231
|
+
function globalConsensus(
|
|
232
|
+
GlobalConsensusParams memory params
|
|
233
|
+
) pure returns (Junction memory) {
|
|
234
|
+
return
|
|
235
|
+
Junction({
|
|
236
|
+
variant: JunctionVariant.GlobalConsensus,
|
|
237
|
+
payload: params.network.encode()
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
224
241
|
/// @notice Creates a `Plurality` junction with the specified body ID and body part.
|
|
225
242
|
/// @param params Parameters for the plurality variant.
|
|
226
243
|
/// @return A `Junction` struct representing the `Plurality` junction with the provided parameters.
|
|
@@ -10,18 +10,7 @@ import {NetworkIdCodec} from "../NetworkId/NetworkIdCodec.sol";
|
|
|
10
10
|
import {Bytes32} from "../../../Scale/Bytes.sol";
|
|
11
11
|
import {Address} from "../../../Scale/Address.sol";
|
|
12
12
|
import {Compact} from "../../../Scale/Compact.sol";
|
|
13
|
-
import {
|
|
14
|
-
Junction,
|
|
15
|
-
JunctionVariant,
|
|
16
|
-
ParachainParams,
|
|
17
|
-
AccountId32Params,
|
|
18
|
-
PluralityParams,
|
|
19
|
-
AccountIndex64Params,
|
|
20
|
-
AccountKey20Params,
|
|
21
|
-
GeneralKeyParams,
|
|
22
|
-
PalletInstanceParams,
|
|
23
|
-
GeneralIndexParams
|
|
24
|
-
} from "./Junction.sol";
|
|
13
|
+
import {Junction, JunctionVariant, ParachainParams, AccountId32Params, PluralityParams, AccountIndex64Params, AccountKey20Params, GeneralKeyParams, PalletInstanceParams, GeneralIndexParams, GlobalConsensusParams} from "./Junction.sol";
|
|
25
14
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
26
15
|
import {UnsignedUtils} from "../../../Utils/UnsignedUtils.sol";
|
|
27
16
|
|
|
@@ -74,12 +63,12 @@ library JunctionCodec {
|
|
|
74
63
|
} else if (variant == uint8(JunctionVariant.GeneralKey)) {
|
|
75
64
|
if (offset >= data.length) revert InvalidJunctionLength();
|
|
76
65
|
uint8 length = uint8(data[offset]);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
variant == uint8(JunctionVariant.GlobalConsensus)
|
|
81
|
-
) {
|
|
66
|
+
if (length == 0 || length > 32) revert InvalidJunctionPayload();
|
|
67
|
+
payloadLength = 1 + 32; // 1 byte for the length + the fixed key bytes
|
|
68
|
+
} else if (variant == uint8(JunctionVariant.OnlyChild)) {
|
|
82
69
|
payloadLength = 0;
|
|
70
|
+
} else if (variant == uint8(JunctionVariant.GlobalConsensus)) {
|
|
71
|
+
payloadLength = NetworkIdCodec.encodedSizeAt(data, offset);
|
|
83
72
|
} else if (variant == uint8(JunctionVariant.Plurality)) {
|
|
84
73
|
uint256 innerLength = BodyIdCodec.encodedSizeAt(data, offset);
|
|
85
74
|
payloadLength =
|
|
@@ -242,6 +231,16 @@ library JunctionCodec {
|
|
|
242
231
|
);
|
|
243
232
|
}
|
|
244
233
|
|
|
234
|
+
/// @notice Decodes a `GlobalConsensus` junction from a given `Junction` struct, extracting the network information.
|
|
235
|
+
/// @param junction The `Junction` struct to decode, which should represent a `GlobalConsensus` junction.
|
|
236
|
+
/// @return params A `GlobalConsensusParams` struct containing the decoded
|
|
237
|
+
function asGlobalConsensus(
|
|
238
|
+
Junction memory junction
|
|
239
|
+
) internal pure returns (GlobalConsensusParams memory params) {
|
|
240
|
+
_assertVariant(junction, JunctionVariant.GlobalConsensus);
|
|
241
|
+
(params.network, ) = NetworkIdCodec.decode(junction.payload);
|
|
242
|
+
}
|
|
243
|
+
|
|
245
244
|
function _innerNetworkIdSize(
|
|
246
245
|
bytes memory data,
|
|
247
246
|
uint256 offset
|
|
@@ -2,13 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import {Compact} from "../../../Scale/Compact.sol";
|
|
5
|
-
import {
|
|
6
|
-
NetworkId,
|
|
7
|
-
NetworkIdVariant,
|
|
8
|
-
ByForkParams,
|
|
9
|
-
ByGenesisParams,
|
|
10
|
-
EthereumParams
|
|
11
|
-
} from "./NetworkId.sol";
|
|
5
|
+
import {NetworkId, NetworkIdVariant, ByForkParams, ByGenesisParams, EthereumParams} from "./NetworkId.sol";
|
|
12
6
|
import {LittleEndianU64} from "../../../LittleEndian/LittleEndianU64.sol";
|
|
13
7
|
import {Bytes32} from "../../../Scale/Bytes.sol";
|
|
14
8
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
@@ -49,7 +43,13 @@ library NetworkIdCodec {
|
|
|
49
43
|
payloadLen = 40; // 8 (u64) + 32 (bytes32)
|
|
50
44
|
} else if (variant == uint8(NetworkIdVariant.Ethereum)) {
|
|
51
45
|
payloadLen = Compact.encodedSizeAt(data, offset + 1);
|
|
52
|
-
} else if (
|
|
46
|
+
} else if (
|
|
47
|
+
variant == uint8(NetworkIdVariant.Polkadot) ||
|
|
48
|
+
variant == uint8(NetworkIdVariant.Kusama) ||
|
|
49
|
+
variant == uint8(NetworkIdVariant.BitcoinCore) ||
|
|
50
|
+
variant == uint8(NetworkIdVariant.BitcoinCash) ||
|
|
51
|
+
variant == uint8(NetworkIdVariant.PolkadotBulletin)
|
|
52
|
+
) {
|
|
53
53
|
payloadLen = 0; // Static variants
|
|
54
54
|
} else {
|
|
55
55
|
// Reserved or unknown types are invalid
|
|
@@ -11,15 +11,7 @@ import {MaybeErrorCode} from "../../v3/MaybeErrorCode/MaybeErrorCode.sol";
|
|
|
11
11
|
import {MaybeErrorCodeCodec} from "../../v3/MaybeErrorCode/MaybeErrorCodeCodec.sol";
|
|
12
12
|
import {Compact} from "../../../Scale/Compact.sol";
|
|
13
13
|
import {LittleEndianU32} from "../../../LittleEndian/LittleEndianU32.sol";
|
|
14
|
-
import {
|
|
15
|
-
Response,
|
|
16
|
-
ResponseVariant,
|
|
17
|
-
AssetsParams,
|
|
18
|
-
VersionParams,
|
|
19
|
-
DispatchResultParams,
|
|
20
|
-
ExecutionResultParams,
|
|
21
|
-
PalletsInfoParams
|
|
22
|
-
} from "./Response.sol";
|
|
14
|
+
import {Response, ResponseVariant, AssetsParams, VersionParams, DispatchResultParams, ExecutionResultParams, PalletsInfoParams} from "./Response.sol";
|
|
23
15
|
|
|
24
16
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
25
17
|
|
|
@@ -3,11 +3,7 @@ pragma solidity ^0.8.28;
|
|
|
3
3
|
|
|
4
4
|
import {Weight} from "../Weight/Weight.sol";
|
|
5
5
|
import {WeightCodec} from "../Weight/WeightCodec.sol";
|
|
6
|
-
import {
|
|
7
|
-
WeightLimit,
|
|
8
|
-
WeightLimitVariant,
|
|
9
|
-
LimitedParams
|
|
10
|
-
} from "./WeightLimit.sol";
|
|
6
|
+
import {WeightLimit, WeightLimitVariant, LimitedParams} from "./WeightLimit.sol";
|
|
11
7
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
12
8
|
|
|
13
9
|
/// @title SCALE Codec for XCM v5 `WeightLimit`
|
|
@@ -6,13 +6,7 @@ import {AssetIdCodec} from "../AssetId/AssetIdCodec.sol";
|
|
|
6
6
|
import {WildFungibilityCodec} from "../WildFungibility/WildFungibilityCodec.sol";
|
|
7
7
|
import {AssetId} from "../AssetId/AssetId.sol";
|
|
8
8
|
import {WildFungibility} from "../WildFungibility/WildFungibility.sol";
|
|
9
|
-
import {
|
|
10
|
-
WildAsset,
|
|
11
|
-
WildAssetVariant,
|
|
12
|
-
AllOfParams,
|
|
13
|
-
AllCountedParams,
|
|
14
|
-
AllOfCountedParams
|
|
15
|
-
} from "./WildAsset.sol";
|
|
9
|
+
import {WildAsset, WildAssetVariant, AllOfParams, AllCountedParams, AllOfCountedParams} from "./WildAsset.sol";
|
|
16
10
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
17
11
|
import {UnsignedUtils} from "../../../Utils/UnsignedUtils.sol";
|
|
18
12
|
|
|
@@ -1,107 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
aliasOrigin as _aliasOrigin,
|
|
6
|
-
burnAsset as _burnAsset,
|
|
7
|
-
buyExecution as _buyExecution,
|
|
8
|
-
claimAsset as _claimAsset,
|
|
9
|
-
clearError as _clearError,
|
|
10
|
-
clearOrigin as _clearOrigin,
|
|
11
|
-
clearTopic as _clearTopic,
|
|
12
|
-
clearTransactStatus as _clearTransactStatus,
|
|
13
|
-
depositAsset as _depositAsset,
|
|
14
|
-
depositReserveAsset as _depositReserveAsset,
|
|
15
|
-
descendOrigin as _descendOrigin,
|
|
16
|
-
executeWithOrigin as _executeWithOrigin,
|
|
17
|
-
expectAsset as _expectAsset,
|
|
18
|
-
expectError as _expectError,
|
|
19
|
-
expectOrigin as _expectOrigin,
|
|
20
|
-
expectPallet as _expectPallet,
|
|
21
|
-
expectTransactStatus as _expectTransactStatus,
|
|
22
|
-
exchangeAsset as _exchangeAsset,
|
|
23
|
-
exportMessage as _exportMessage,
|
|
24
|
-
hrmpChannelAccepted as _hrmpChannelAccepted,
|
|
25
|
-
hrmpChannelClosing as _hrmpChannelClosing,
|
|
26
|
-
hrmpNewChannelOpenRequest as _hrmpNewChannelOpenRequest,
|
|
27
|
-
initiateReserveWithdraw as _initiateReserveWithdraw,
|
|
28
|
-
initiateTeleport as _initiateTeleport,
|
|
29
|
-
initiateTransfer as _initiateTransfer,
|
|
30
|
-
lockAsset as _lockAsset,
|
|
31
|
-
noteUnlockable as _noteUnlockable,
|
|
32
|
-
payFees as _payFees,
|
|
33
|
-
queryPallet as _queryPallet,
|
|
34
|
-
queryResponse as _queryResponse,
|
|
35
|
-
receiveTeleportedAsset as _receiveTeleportedAsset,
|
|
36
|
-
refundSurplus as _refundSurplus,
|
|
37
|
-
reportError as _reportError,
|
|
38
|
-
reportHolding as _reportHolding,
|
|
39
|
-
reportTransactStatus as _reportTransactStatus,
|
|
40
|
-
requestUnlock as _requestUnlock,
|
|
41
|
-
reserveAssetDeposited as _reserveAssetDeposited,
|
|
42
|
-
setAppendix as _setAppendix,
|
|
43
|
-
setErrorHandler as _setErrorHandler,
|
|
44
|
-
setFeesMode as _setFeesMode,
|
|
45
|
-
setHints as _setHints,
|
|
46
|
-
setTopic as _setTopic,
|
|
47
|
-
subscribeVersion as _subscribeVersion,
|
|
48
|
-
transact as _transact,
|
|
49
|
-
transferAsset as _transferAsset,
|
|
50
|
-
transferReserveAsset as _transferReserveAsset,
|
|
51
|
-
trap as _trap,
|
|
52
|
-
universalOrigin as _universalOrigin,
|
|
53
|
-
unpaidExecution as _unpaidExecution,
|
|
54
|
-
unlockAsset as _unlockAsset,
|
|
55
|
-
unsubscribeVersion as _unsubscribeVersion,
|
|
56
|
-
withdrawAsset as _withdrawAsset,
|
|
57
|
-
AliasOriginParams,
|
|
58
|
-
BurnAssetParams,
|
|
59
|
-
BuyExecutionParams,
|
|
60
|
-
ClaimAssetParams,
|
|
61
|
-
DepositAssetParams,
|
|
62
|
-
DepositReserveAssetParams,
|
|
63
|
-
DescendOriginParams,
|
|
64
|
-
ExecuteWithOriginParams,
|
|
65
|
-
ExpectAssetParams,
|
|
66
|
-
ExpectErrorParams,
|
|
67
|
-
ExpectOriginParams,
|
|
68
|
-
ExpectPalletParams,
|
|
69
|
-
ExpectTransactStatusParams,
|
|
70
|
-
ExchangeAssetParams,
|
|
71
|
-
ExportMessageParams,
|
|
72
|
-
HrmpChannelAcceptedParams,
|
|
73
|
-
HrmpChannelClosingParams,
|
|
74
|
-
HrmpNewChannelOpenRequestParams,
|
|
75
|
-
InitiateReserveWithdrawParams,
|
|
76
|
-
InitiateTeleportParams,
|
|
77
|
-
InitiateTransferParams,
|
|
78
|
-
Instruction,
|
|
79
|
-
LockAssetParams,
|
|
80
|
-
NoteUnlockableParams,
|
|
81
|
-
PayFeesParams,
|
|
82
|
-
QueryPalletParams,
|
|
83
|
-
QueryResponseParams,
|
|
84
|
-
ReceiveTeleportedAssetParams,
|
|
85
|
-
ReportErrorParams,
|
|
86
|
-
ReportHoldingParams,
|
|
87
|
-
ReportTransactStatusParams,
|
|
88
|
-
RequestUnlockParams,
|
|
89
|
-
ReserveAssetDepositedParams,
|
|
90
|
-
SetAppendixParams,
|
|
91
|
-
SetErrorHandlerParams,
|
|
92
|
-
SetFeesModeParams,
|
|
93
|
-
SetHintsParams,
|
|
94
|
-
SetTopicParams,
|
|
95
|
-
SubscribeVersionParams,
|
|
96
|
-
TransactParams,
|
|
97
|
-
TransferAssetParams,
|
|
98
|
-
TransferReserveAssetParams,
|
|
99
|
-
TrapParams,
|
|
100
|
-
UniversalOriginParams,
|
|
101
|
-
UnpaidExecutionParams,
|
|
102
|
-
UnlockAssetParams,
|
|
103
|
-
WithdrawAssetParams
|
|
104
|
-
} from "../Instruction/Instruction.sol";
|
|
4
|
+
import {aliasOrigin as _aliasOrigin, burnAsset as _burnAsset, buyExecution as _buyExecution, claimAsset as _claimAsset, clearError as _clearError, clearOrigin as _clearOrigin, clearTopic as _clearTopic, clearTransactStatus as _clearTransactStatus, depositAsset as _depositAsset, depositReserveAsset as _depositReserveAsset, descendOrigin as _descendOrigin, executeWithOrigin as _executeWithOrigin, expectAsset as _expectAsset, expectError as _expectError, expectOrigin as _expectOrigin, expectPallet as _expectPallet, expectTransactStatus as _expectTransactStatus, exchangeAsset as _exchangeAsset, exportMessage as _exportMessage, hrmpChannelAccepted as _hrmpChannelAccepted, hrmpChannelClosing as _hrmpChannelClosing, hrmpNewChannelOpenRequest as _hrmpNewChannelOpenRequest, initiateReserveWithdraw as _initiateReserveWithdraw, initiateTeleport as _initiateTeleport, initiateTransfer as _initiateTransfer, lockAsset as _lockAsset, noteUnlockable as _noteUnlockable, payFees as _payFees, queryPallet as _queryPallet, queryResponse as _queryResponse, receiveTeleportedAsset as _receiveTeleportedAsset, refundSurplus as _refundSurplus, reportError as _reportError, reportHolding as _reportHolding, reportTransactStatus as _reportTransactStatus, requestUnlock as _requestUnlock, reserveAssetDeposited as _reserveAssetDeposited, setAppendix as _setAppendix, setErrorHandler as _setErrorHandler, setFeesMode as _setFeesMode, setHints as _setHints, setTopic as _setTopic, subscribeVersion as _subscribeVersion, transact as _transact, transferAsset as _transferAsset, transferReserveAsset as _transferReserveAsset, trap as _trap, universalOrigin as _universalOrigin, unpaidExecution as _unpaidExecution, unlockAsset as _unlockAsset, unsubscribeVersion as _unsubscribeVersion, withdrawAsset as _withdrawAsset, AliasOriginParams, BurnAssetParams, BuyExecutionParams, ClaimAssetParams, DepositAssetParams, DepositReserveAssetParams, DescendOriginParams, ExecuteWithOriginParams, ExpectAssetParams, ExpectErrorParams, ExpectOriginParams, ExpectPalletParams, ExpectTransactStatusParams, ExchangeAssetParams, ExportMessageParams, HrmpChannelAcceptedParams, HrmpChannelClosingParams, HrmpNewChannelOpenRequestParams, InitiateReserveWithdrawParams, InitiateTeleportParams, InitiateTransferParams, Instruction, LockAssetParams, NoteUnlockableParams, PayFeesParams, QueryPalletParams, QueryResponseParams, ReceiveTeleportedAssetParams, ReportErrorParams, ReportHoldingParams, ReportTransactStatusParams, RequestUnlockParams, ReserveAssetDepositedParams, SetAppendixParams, SetErrorHandlerParams, SetFeesModeParams, SetHintsParams, SetTopicParams, SubscribeVersionParams, TransactParams, TransferAssetParams, TransferReserveAssetParams, TrapParams, UniversalOriginParams, UnpaidExecutionParams, UnlockAssetParams, WithdrawAssetParams} from "../Instruction/Instruction.sol";
|
|
105
5
|
import {Xcm, fromInstructions, newXcm} from "./Xcm.sol";
|
|
106
6
|
|
|
107
7
|
library XcmBuilder {
|