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
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
[Unreleased]
|
|
9
9
|
|
|
10
|
+
## Version 2.1.1
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Missing `GlobalConsensus` junction variant and related helper function in `Junction.sol` and `JunctionCodec.sol`. - [#5592427](https://github.com/LucasGrasso/solidity-scale-codec/commit/5592427)
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Variant checking in `NetworkId`. - [#7e9309d](https://github.com/LucasGrasso/solidity-scale-codec/commit/7e9309d)
|
|
19
|
+
- Decoding of `Index` variant in `BodyId`. - [#75ead59](https://github.com/LucasGrasso/solidity-scale-codec/commit/75ead59)
|
|
20
|
+
- Incorrect encoding/decoding of `GeneralKey` junction variant. - [#4e0f795](https://github.com/LucasGrasso/solidity-scale-codec/commit/4e0f795)
|
|
21
|
+
|
|
10
22
|
## Version 2.0.0
|
|
11
23
|
|
|
12
24
|
### Added
|
package/package.json
CHANGED
|
@@ -31,9 +31,9 @@ library BoolArr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 1);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidBoolArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 1);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidBoolArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library I128Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 16);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidI128ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 16);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidI128ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library I16Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 2);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidI16ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 2);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidI16ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library I256Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 32);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidI256ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 32);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidI256ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library I32Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 4);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidI32ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 4);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidI32ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library I64Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 8);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidI64ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 8);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidI64ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library I8Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 1);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidI8ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 1);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidI8ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library U128Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 16);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidU128ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 16);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidU128ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library U16Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 2);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidU16ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 2);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidU16ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library U256Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 32);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidU256ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 32);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidU256ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library U32Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 4);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidU32ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 4);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidU32ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library U64Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 8);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidU64ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 8);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidU64ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -31,9 +31,9 @@ library U8Arr {
|
|
|
31
31
|
bytes memory data,
|
|
32
32
|
uint256 offset
|
|
33
33
|
) internal pure returns (uint256) {
|
|
34
|
-
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
-
uint256 totalSize = prefixSize + (count * 1);
|
|
36
|
-
if (offset + totalSize > data.length) revert InvalidU8ArrLength();
|
|
34
|
+
(uint256 count, uint256 prefixSize) = Compact.decodeAt(data, offset);
|
|
35
|
+
uint256 totalSize = prefixSize + (count * 1);
|
|
36
|
+
if (offset + totalSize > data.length) revert InvalidU8ArrLength();
|
|
37
37
|
return totalSize;
|
|
38
38
|
}
|
|
39
39
|
|
package/src/Scale/Array.sol
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
|
|
1
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
+
pragma solidity ^0.8.28;
|
|
3
4
|
|
|
4
|
-
import {U8Arr} from "./Array/U8Arr.sol";
|
|
5
|
-
import {U16Arr} from "./Array/U16Arr.sol";
|
|
6
|
-
import {U32Arr} from "./Array/U32Arr.sol";
|
|
7
|
-
import {U64Arr} from "./Array/U64Arr.sol";
|
|
8
|
-
import {U128Arr} from "./Array/U128Arr.sol";
|
|
9
|
-
import {U256Arr} from "./Array/U256Arr.sol";
|
|
10
|
-
import {I8Arr} from "./Array/I8Arr.sol";
|
|
11
|
-
import {I16Arr} from "./Array/I16Arr.sol";
|
|
12
|
-
import {I32Arr} from "./Array/I32Arr.sol";
|
|
13
|
-
import {I64Arr} from "./Array/I64Arr.sol";
|
|
14
|
-
import {I128Arr} from "./Array/I128Arr.sol";
|
|
15
|
-
import {I256Arr} from "./Array/I256Arr.sol";
|
|
16
|
-
import {BoolArr} from "./Array/BoolArr.sol";
|
|
5
|
+
import { U8Arr } from "./Array/U8Arr.sol";
|
|
6
|
+
import { U16Arr } from "./Array/U16Arr.sol";
|
|
7
|
+
import { U32Arr } from "./Array/U32Arr.sol";
|
|
8
|
+
import { U64Arr } from "./Array/U64Arr.sol";
|
|
9
|
+
import { U128Arr } from "./Array/U128Arr.sol";
|
|
10
|
+
import { U256Arr } from "./Array/U256Arr.sol";
|
|
11
|
+
import { I8Arr } from "./Array/I8Arr.sol";
|
|
12
|
+
import { I16Arr } from "./Array/I16Arr.sol";
|
|
13
|
+
import { I32Arr } from "./Array/I32Arr.sol";
|
|
14
|
+
import { I64Arr } from "./Array/I64Arr.sol";
|
|
15
|
+
import { I128Arr } from "./Array/I128Arr.sol";
|
|
16
|
+
import { I256Arr } from "./Array/I256Arr.sol";
|
|
17
|
+
import { BoolArr } from "./Array/BoolArr.sol";
|
|
@@ -105,12 +105,14 @@ library Compact {
|
|
|
105
105
|
} else if (mode == MODE_TWO) {
|
|
106
106
|
if (data.length < offset + 2) revert OffsetOutOfBounds();
|
|
107
107
|
value =
|
|
108
|
-
uint256(LittleEndianU16.fromLittleEndian(data, offset)) >>
|
|
108
|
+
uint256(LittleEndianU16.fromLittleEndian(data, offset)) >>
|
|
109
|
+
2;
|
|
109
110
|
bytesRead = 2;
|
|
110
111
|
} else if (mode == MODE_FOUR) {
|
|
111
112
|
if (data.length < offset + 4) revert OffsetOutOfBounds();
|
|
112
113
|
value =
|
|
113
|
-
uint256(LittleEndianU32.fromLittleEndian(data, offset)) >>
|
|
114
|
+
uint256(LittleEndianU32.fromLittleEndian(data, offset)) >>
|
|
115
|
+
2;
|
|
114
116
|
bytesRead = 4;
|
|
115
117
|
} else {
|
|
116
118
|
uint8 m = (header >> 2) + 4;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {U128} from "../Unsigned/U128.sol";
|
|
4
|
+
import { U128 } from "../Unsigned/U128.sol";
|
|
5
5
|
|
|
6
6
|
/// @title Scale Codec for the `int128` type.
|
|
7
7
|
/// @notice SCALE-compliant encoder/decoder for the `int128` type.
|
|
@@ -9,7 +9,7 @@ import {U128} from "../Unsigned/U128.sol";
|
|
|
9
9
|
library I128 {
|
|
10
10
|
error OffsetOutOfBounds();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/// @notice Encodes an `int128` into SCALE format (16-byte two's-complement little-endian).
|
|
13
13
|
/// @param value The signed 128-bit integer to encode.
|
|
14
14
|
/// @return SCALE-encoded byte sequence.
|
|
15
15
|
function encode(int128 value) internal pure returns (bytes memory) {
|
|
@@ -17,13 +17,10 @@ library I128 {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// @notice Returns the number of bytes that a `int128` would occupy when SCALE-encoded.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function encodedSizeAt(
|
|
24
|
-
bytes memory data,
|
|
25
|
-
uint256 offset
|
|
26
|
-
) internal pure returns (uint256) {
|
|
20
|
+
/// @param data The byte sequence containing the encoded `int128`.
|
|
21
|
+
/// @param offset The starting index in `data` from which to calculate the encoded size of the `int128`.
|
|
22
|
+
/// @return The number of bytes that the `int128` would occupy when SCALE-encoded.
|
|
23
|
+
function encodedSizeAt(bytes memory data, uint256 offset) internal pure returns (uint256) {
|
|
27
24
|
return U128.encodedSizeAt(data, offset);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,12 +43,10 @@ library I128 {
|
|
|
46
43
|
return int128(U128.decodeAt(data, offset));
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
/// @notice Converts an int128 to little-endian bytes16 (two's complement)
|
|
50
47
|
/// @param value The signed 128-bit integer to convert.
|
|
51
48
|
/// @return result Little-endian byte representation of the input value.
|
|
52
|
-
function toLittleEndian(
|
|
53
|
-
int128 value
|
|
54
|
-
) internal pure returns (bytes16 result) {
|
|
49
|
+
function toLittleEndian(int128 value) internal pure returns (bytes16 result) {
|
|
55
50
|
return U128.toLittleEndian(uint128(value));
|
|
56
51
|
}
|
|
57
|
-
}
|
|
52
|
+
}
|
package/src/Scale/Signed/I16.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {U16} from "../Unsigned/U16.sol";
|
|
4
|
+
import { U16 } from "../Unsigned/U16.sol";
|
|
5
5
|
|
|
6
6
|
/// @title Scale Codec for the `int16` type.
|
|
7
7
|
/// @notice SCALE-compliant encoder/decoder for the `int16` type.
|
|
@@ -9,7 +9,7 @@ import {U16} from "../Unsigned/U16.sol";
|
|
|
9
9
|
library I16 {
|
|
10
10
|
error OffsetOutOfBounds();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/// @notice Encodes an `int16` into SCALE format (2-byte two's-complement little-endian).
|
|
13
13
|
/// @param value The signed 16-bit integer to encode.
|
|
14
14
|
/// @return SCALE-encoded byte sequence.
|
|
15
15
|
function encode(int16 value) internal pure returns (bytes memory) {
|
|
@@ -17,13 +17,10 @@ library I16 {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// @notice Returns the number of bytes that a `int16` would occupy when SCALE-encoded.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function encodedSizeAt(
|
|
24
|
-
bytes memory data,
|
|
25
|
-
uint256 offset
|
|
26
|
-
) internal pure returns (uint256) {
|
|
20
|
+
/// @param data The byte sequence containing the encoded `int16`.
|
|
21
|
+
/// @param offset The starting index in `data` from which to calculate the encoded size of the `int16`.
|
|
22
|
+
/// @return The number of bytes that the `int16` would occupy when SCALE-encoded.
|
|
23
|
+
function encodedSizeAt(bytes memory data, uint256 offset) internal pure returns (uint256) {
|
|
27
24
|
return U16.encodedSizeAt(data, offset);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,10 +43,10 @@ library I16 {
|
|
|
46
43
|
return int16(U16.decodeAt(data, offset));
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
/// @notice Converts an int16 to little-endian bytes2 (two's complement)
|
|
50
47
|
/// @param value The signed 16-bit integer to convert.
|
|
51
48
|
/// @return result Little-endian byte representation of the input value.
|
|
52
49
|
function toLittleEndian(int16 value) internal pure returns (bytes2 result) {
|
|
53
50
|
return U16.toLittleEndian(uint16(value));
|
|
54
51
|
}
|
|
55
|
-
}
|
|
52
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {U256} from "../Unsigned/U256.sol";
|
|
4
|
+
import { U256 } from "../Unsigned/U256.sol";
|
|
5
5
|
|
|
6
6
|
/// @title Scale Codec for the `int256` type.
|
|
7
7
|
/// @notice SCALE-compliant encoder/decoder for the `int256` type.
|
|
@@ -9,7 +9,7 @@ import {U256} from "../Unsigned/U256.sol";
|
|
|
9
9
|
library I256 {
|
|
10
10
|
error OffsetOutOfBounds();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/// @notice Encodes an `int256` into SCALE format (32-byte two's-complement little-endian).
|
|
13
13
|
/// @param value The signed 256-bit integer to encode.
|
|
14
14
|
/// @return SCALE-encoded byte sequence.
|
|
15
15
|
function encode(int256 value) internal pure returns (bytes memory) {
|
|
@@ -17,13 +17,10 @@ library I256 {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// @notice Returns the number of bytes that a `int256` would occupy when SCALE-encoded.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function encodedSizeAt(
|
|
24
|
-
bytes memory data,
|
|
25
|
-
uint256 offset
|
|
26
|
-
) internal pure returns (uint256) {
|
|
20
|
+
/// @param data The byte sequence containing the encoded `int256`.
|
|
21
|
+
/// @param offset The starting index in `data` from which to calculate the encoded size of the `int256`.
|
|
22
|
+
/// @return The number of bytes that the `int256` would occupy when SCALE-encoded.
|
|
23
|
+
function encodedSizeAt(bytes memory data, uint256 offset) internal pure returns (uint256) {
|
|
27
24
|
return U256.encodedSizeAt(data, offset);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,12 +43,10 @@ library I256 {
|
|
|
46
43
|
return int256(U256.decodeAt(data, offset));
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
/// @notice Converts an int256 to little-endian bytes32 (two's complement)
|
|
50
47
|
/// @param value The signed 256-bit integer to convert.
|
|
51
48
|
/// @return result Little-endian byte representation of the input value.
|
|
52
|
-
function toLittleEndian(
|
|
53
|
-
int256 value
|
|
54
|
-
) internal pure returns (bytes32 result) {
|
|
49
|
+
function toLittleEndian(int256 value) internal pure returns (bytes32 result) {
|
|
55
50
|
return U256.toLittleEndian(uint256(value));
|
|
56
51
|
}
|
|
57
|
-
}
|
|
52
|
+
}
|
package/src/Scale/Signed/I32.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {U32} from "../Unsigned/U32.sol";
|
|
4
|
+
import { U32 } from "../Unsigned/U32.sol";
|
|
5
5
|
|
|
6
6
|
/// @title Scale Codec for the `int32` type.
|
|
7
7
|
/// @notice SCALE-compliant encoder/decoder for the `int32` type.
|
|
@@ -9,7 +9,7 @@ import {U32} from "../Unsigned/U32.sol";
|
|
|
9
9
|
library I32 {
|
|
10
10
|
error OffsetOutOfBounds();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/// @notice Encodes an `int32` into SCALE format (4-byte two's-complement little-endian).
|
|
13
13
|
/// @param value The signed 32-bit integer to encode.
|
|
14
14
|
/// @return SCALE-encoded byte sequence.
|
|
15
15
|
function encode(int32 value) internal pure returns (bytes memory) {
|
|
@@ -17,13 +17,10 @@ library I32 {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// @notice Returns the number of bytes that a `int32` would occupy when SCALE-encoded.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function encodedSizeAt(
|
|
24
|
-
bytes memory data,
|
|
25
|
-
uint256 offset
|
|
26
|
-
) internal pure returns (uint256) {
|
|
20
|
+
/// @param data The byte sequence containing the encoded `int32`.
|
|
21
|
+
/// @param offset The starting index in `data` from which to calculate the encoded size of the `int32`.
|
|
22
|
+
/// @return The number of bytes that the `int32` would occupy when SCALE-encoded.
|
|
23
|
+
function encodedSizeAt(bytes memory data, uint256 offset) internal pure returns (uint256) {
|
|
27
24
|
return U32.encodedSizeAt(data, offset);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,10 +43,10 @@ library I32 {
|
|
|
46
43
|
return int32(U32.decodeAt(data, offset));
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
/// @notice Converts an int32 to little-endian bytes4 (two's complement)
|
|
50
47
|
/// @param value The signed 32-bit integer to convert.
|
|
51
48
|
/// @return result Little-endian byte representation of the input value.
|
|
52
49
|
function toLittleEndian(int32 value) internal pure returns (bytes4 result) {
|
|
53
50
|
return U32.toLittleEndian(uint32(value));
|
|
54
51
|
}
|
|
55
|
-
}
|
|
52
|
+
}
|
package/src/Scale/Signed/I64.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {U64} from "../Unsigned/U64.sol";
|
|
4
|
+
import { U64 } from "../Unsigned/U64.sol";
|
|
5
5
|
|
|
6
6
|
/// @title Scale Codec for the `int64` type.
|
|
7
7
|
/// @notice SCALE-compliant encoder/decoder for the `int64` type.
|
|
@@ -9,7 +9,7 @@ import {U64} from "../Unsigned/U64.sol";
|
|
|
9
9
|
library I64 {
|
|
10
10
|
error OffsetOutOfBounds();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/// @notice Encodes an `int64` into SCALE format (8-byte two's-complement little-endian).
|
|
13
13
|
/// @param value The signed 64-bit integer to encode.
|
|
14
14
|
/// @return SCALE-encoded byte sequence.
|
|
15
15
|
function encode(int64 value) internal pure returns (bytes memory) {
|
|
@@ -17,13 +17,10 @@ library I64 {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// @notice Returns the number of bytes that a `int64` would occupy when SCALE-encoded.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function encodedSizeAt(
|
|
24
|
-
bytes memory data,
|
|
25
|
-
uint256 offset
|
|
26
|
-
) internal pure returns (uint256) {
|
|
20
|
+
/// @param data The byte sequence containing the encoded `int64`.
|
|
21
|
+
/// @param offset The starting index in `data` from which to calculate the encoded size of the `int64`.
|
|
22
|
+
/// @return The number of bytes that the `int64` would occupy when SCALE-encoded.
|
|
23
|
+
function encodedSizeAt(bytes memory data, uint256 offset) internal pure returns (uint256) {
|
|
27
24
|
return U64.encodedSizeAt(data, offset);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,10 +43,10 @@ library I64 {
|
|
|
46
43
|
return int64(U64.decodeAt(data, offset));
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
/// @notice Converts an int64 to little-endian bytes8 (two's complement)
|
|
50
47
|
/// @param value The signed 64-bit integer to convert.
|
|
51
48
|
/// @return result Little-endian byte representation of the input value.
|
|
52
49
|
function toLittleEndian(int64 value) internal pure returns (bytes8 result) {
|
|
53
50
|
return U64.toLittleEndian(uint64(value));
|
|
54
51
|
}
|
|
55
|
-
}
|
|
52
|
+
}
|
package/src/Scale/Signed/I8.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import {U8} from "../Unsigned/U8.sol";
|
|
4
|
+
import { U8 } from "../Unsigned/U8.sol";
|
|
5
5
|
|
|
6
6
|
/// @title Scale Codec for the `int8` type.
|
|
7
7
|
/// @notice SCALE-compliant encoder/decoder for the `int8` type.
|
|
@@ -9,7 +9,7 @@ import {U8} from "../Unsigned/U8.sol";
|
|
|
9
9
|
library I8 {
|
|
10
10
|
error OffsetOutOfBounds();
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/// @notice Encodes an `int8` into SCALE format (1-byte two's-complement little-endian).
|
|
13
13
|
/// @param value The signed 8-bit integer to encode.
|
|
14
14
|
/// @return SCALE-encoded byte sequence.
|
|
15
15
|
function encode(int8 value) internal pure returns (bytes memory) {
|
|
@@ -17,13 +17,10 @@ library I8 {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/// @notice Returns the number of bytes that a `int8` would occupy when SCALE-encoded.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function encodedSizeAt(
|
|
24
|
-
bytes memory data,
|
|
25
|
-
uint256 offset
|
|
26
|
-
) internal pure returns (uint256) {
|
|
20
|
+
/// @param data The byte sequence containing the encoded `int8`.
|
|
21
|
+
/// @param offset The starting index in `data` from which to calculate the encoded size of the `int8`.
|
|
22
|
+
/// @return The number of bytes that the `int8` would occupy when SCALE-encoded.
|
|
23
|
+
function encodedSizeAt(bytes memory data, uint256 offset) internal pure returns (uint256) {
|
|
27
24
|
return U8.encodedSizeAt(data, offset);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,10 +43,10 @@ library I8 {
|
|
|
46
43
|
return int8(U8.decodeAt(data, offset));
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
/// @notice Converts an int8 to little-endian bytes1 (two's complement)
|
|
50
47
|
/// @param value The signed 8-bit integer to convert.
|
|
51
48
|
/// @return result Little-endian byte representation of the input value.
|
|
52
49
|
function toLittleEndian(int8 value) internal pure returns (bytes1 result) {
|
|
53
50
|
return U8.toLittleEndian(uint8(value));
|
|
54
51
|
}
|
|
55
|
-
}
|
|
52
|
+
}
|
package/src/Scale/Signed.sol
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
|
|
1
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
+
pragma solidity ^0.8.28;
|
|
3
4
|
|
|
4
|
-
import {I8} from "./Signed/I8.sol";
|
|
5
|
-
import {I16} from "./Signed/I16.sol";
|
|
6
|
-
import {I32} from "./Signed/I32.sol";
|
|
7
|
-
import {I64} from "./Signed/I64.sol";
|
|
8
|
-
import {I128} from "./Signed/I128.sol";
|
|
9
|
-
import {I256} from "./Signed/I256.sol";
|
|
5
|
+
import { I8 } from "./Signed/I8.sol";
|
|
6
|
+
import { I16 } from "./Signed/I16.sol";
|
|
7
|
+
import { I32 } from "./Signed/I32.sol";
|
|
8
|
+
import { I64 } from "./Signed/I64.sol";
|
|
9
|
+
import { I128 } from "./Signed/I128.sol";
|
|
10
|
+
import { I256 } from "./Signed/I256.sol";
|
package/src/Scale/Unsigned.sol
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
|
|
1
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.28;
|
|
3
|
+
pragma solidity ^0.8.28;
|
|
3
4
|
|
|
4
|
-
import {U8} from "./Unsigned/U8.sol";
|
|
5
|
-
import {U16} from "./Unsigned/U16.sol";
|
|
6
|
-
import {U32} from "./Unsigned/U32.sol";
|
|
7
|
-
import {U64} from "./Unsigned/U64.sol";
|
|
8
|
-
import {U128} from "./Unsigned/U128.sol";
|
|
9
|
-
import {U256} from "./Unsigned/U256.sol";
|
|
5
|
+
import { U8 } from "./Unsigned/U8.sol";
|
|
6
|
+
import { U16 } from "./Unsigned/U16.sol";
|
|
7
|
+
import { U32 } from "./Unsigned/U32.sol";
|
|
8
|
+
import { U64 } from "./Unsigned/U64.sol";
|
|
9
|
+
import { U128 } from "./Unsigned/U128.sol";
|
|
10
|
+
import { U256 } from "./Unsigned/U256.sol";
|
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import {Bytes} from "../../../Scale/Bytes.sol";
|
|
5
|
-
import {
|
|
6
|
-
MaybeErrorCode,
|
|
7
|
-
MaybeErrorCodeVariant,
|
|
8
|
-
ErrorParams,
|
|
9
|
-
TruncatedErrorParams
|
|
10
|
-
} from "./MaybeErrorCode.sol";
|
|
5
|
+
import {MaybeErrorCode, MaybeErrorCodeVariant, ErrorParams, TruncatedErrorParams} from "./MaybeErrorCode.sol";
|
|
11
6
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
12
7
|
|
|
13
8
|
/// @title SCALE Codec for XCM v3 `MaybeErrorCode`
|
|
@@ -5,12 +5,7 @@ import {Assets} from "../Assets/Assets.sol";
|
|
|
5
5
|
import {AssetsCodec} from "../Assets/AssetsCodec.sol";
|
|
6
6
|
import {WildAsset} from "../WildAsset/WildAsset.sol";
|
|
7
7
|
import {WildAssetCodec} from "../WildAsset/WildAssetCodec.sol";
|
|
8
|
-
import {
|
|
9
|
-
AssetFilter,
|
|
10
|
-
AssetFilterVariant,
|
|
11
|
-
DefiniteParams,
|
|
12
|
-
WildParams
|
|
13
|
-
} from "./AssetFilter.sol";
|
|
8
|
+
import {AssetFilter, AssetFilterVariant, DefiniteParams, WildParams} from "./AssetFilter.sol";
|
|
14
9
|
import {BytesUtils} from "../../../Utils/BytesUtils.sol";
|
|
15
10
|
|
|
16
11
|
/// @title SCALE Codec for XCM v5 `AssetFilter`
|