@boostxyz/sdk 8.0.1 → 8.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boostxyz/sdk",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "type": "module",
6
6
  "files": [
@@ -1514,6 +1514,48 @@ describe('decodeAndReorderLogArgs', () => {
1514
1514
  expect(result.args[2]).toBe(1n);
1515
1515
  expect(result.args[3]).toBe(5284n);
1516
1516
  });
1517
+
1518
+ test('handles TransferReference with interleaved indexed params', () => {
1519
+ // TransferReference(address sender, address indexed recipient, uint256 amount, address token, string indexed referenceId, bool indexed success)
1520
+ const event: AbiEvent = {
1521
+ type: 'event',
1522
+ name: 'TransferReference',
1523
+ inputs: [
1524
+ { type: 'address', indexed: false, name: 'sender' },
1525
+ { type: 'address', indexed: true, name: 'recipient' },
1526
+ { type: 'uint256', indexed: false, name: 'amount' },
1527
+ { type: 'address', indexed: false, name: 'token' },
1528
+ { type: 'bytes32', indexed: true, name: 'referenceId' },
1529
+ { type: 'bool', indexed: true, name: 'success' },
1530
+ ],
1531
+ };
1532
+
1533
+ const log: Log = {
1534
+ address: "0xee9f1a50138ba636cd50926b02b644f96f8748c7",
1535
+ blockHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
1536
+ blockNumber: 1n,
1537
+ data: "0x0000000000000000000000003ebc5ada4f198a831472ef19e4001c17320ca9950000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000002cfc85d8e48f8eab294be644d9e25c3030863003",
1538
+ logIndex: 0,
1539
+ removed: false,
1540
+ topics: [
1541
+ "0xa2b940fe4e5490b0393adc0106a79fc2d4d9fb9623ae3fb2ebf0b8fe30d354d2",
1542
+ "0x000000000000000000000000a108fb7a4c41658d4aa7a62f01afdd072c30d22e",
1543
+ "0xde0cdb1d3929682455dae865d1605e27ba4245172afbd52df50ea7b37c81261f",
1544
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
1545
+ ],
1546
+ transactionHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
1547
+ transactionIndex: 0,
1548
+ };
1549
+
1550
+ const result = decodeAndReorderLogArgs(event, log);
1551
+
1552
+ expect(result.args[0]).toBe("0x3eBC5aDA4F198a831472eF19e4001c17320ca995");
1553
+ expect(result.args[1]).toBe("0xA108FB7A4C41658D4AA7a62F01aFDd072c30D22E");
1554
+ expect(result.args[2]).toBe(2000000000000000000n);
1555
+ expect(result.args[3]).toBe("0x2cFc85d8E48F8EAB294be644d9E25C3030863003");
1556
+ expect(result.args[4]).toBe("0xde0cdb1d3929682455dae865d1605e27ba4245172afbd52df50ea7b37c81261f");
1557
+ expect(result.args[5]).toBe(true);
1558
+ });
1517
1559
  });
1518
1560
 
1519
1561
  describe("criteria field index tuple support", () => {
@@ -20,6 +20,7 @@ import {
20
20
  type Hex,
21
21
  type Log,
22
22
  type Transaction,
23
+ decodeAbiParameters,
23
24
  decodeEventLog,
24
25
  decodeFunctionData,
25
26
  encodeAbiParameters,
@@ -1926,8 +1927,7 @@ export function unpackFieldIndexes(packed: number): number[] {
1926
1927
  }
1927
1928
 
1928
1929
  /**
1929
- * Decodes an event log and reorders the arguments to match the original ABI order.
1930
- * This is necessary because viem's decodeEventLog reorders indexed parameters to the front.
1930
+ * Decodes an event log and returns arguments in ABI declaration order.
1931
1931
  *
1932
1932
  * @param event - The event ABI definition
1933
1933
  * @param log - The log to decode
@@ -1945,50 +1945,51 @@ export function decodeAndReorderLogArgs(event: AbiEvent, log: Log) {
1945
1945
  event.inputs[2]!.indexed = true;
1946
1946
  }
1947
1947
 
1948
- const decodedLog = decodeEventLog({
1949
- abi: [event],
1950
- data: log.data,
1951
- topics: log.topics,
1952
- });
1953
-
1954
- const argsArray = Array.isArray(decodedLog.args)
1955
- ? decodedLog.args
1956
- : Object.values(decodedLog.args);
1957
-
1958
- if (!event.inputs.some((input) => input.indexed)) {
1959
- return {
1960
- ...log,
1961
- ...decodedLog,
1962
- } as EventLog;
1963
- }
1948
+ const indexedInputs: AbiParameter[] = [];
1949
+ const nonIndexedInputs: AbiParameter[] = [];
1964
1950
 
1965
- const indexedIndices: number[] = [];
1966
- const nonIndexedIndices: number[] = [];
1967
1951
  for (let i = 0; i < event.inputs.length; i++) {
1968
- if (event.inputs[i]!.indexed) {
1969
- indexedIndices.push(i);
1952
+ const input = event.inputs[i]!;
1953
+ if (input.indexed) {
1954
+ indexedInputs.push(input);
1970
1955
  } else {
1971
- nonIndexedIndices.push(i);
1956
+ nonIndexedInputs.push(input);
1972
1957
  }
1973
1958
  }
1974
1959
 
1975
- const reorderedArgs = Array.from({ length: event.inputs.length });
1976
- let currentIndex = 0;
1977
-
1978
- // Place the indexed arguments in their original positions
1979
- for (let i = 0; i < indexedIndices.length; i++) {
1980
- reorderedArgs[indexedIndices[i]!] = argsArray[currentIndex++];
1960
+ const decodedIndexed: unknown[] = [];
1961
+ for (let i = 0; i < indexedInputs.length; i++) {
1962
+ const topic = log.topics[i + 1];
1963
+ if (!topic) {
1964
+ throw new DecodedArgsError(
1965
+ `Missing topic at index ${i + 1} for indexed parameter "${indexedInputs[i]!.name ?? i}"`,
1966
+ );
1967
+ }
1968
+ const [decoded] = decodeAbiParameters([indexedInputs[i]!], topic);
1969
+ decodedIndexed.push(decoded);
1981
1970
  }
1982
1971
 
1983
- // Place the non-indexed arguments in their original positions
1984
- for (let i = 0; i < nonIndexedIndices.length; i++) {
1985
- reorderedArgs[nonIndexedIndices[i]!] = argsArray[currentIndex++];
1972
+ const decodedNonIndexed =
1973
+ nonIndexedInputs.length > 0 && log.data && log.data !== '0x'
1974
+ ? decodeAbiParameters(nonIndexedInputs, log.data)
1975
+ : [];
1976
+
1977
+ const args: unknown[] = new Array(event.inputs.length);
1978
+ let indexedIdx = 0;
1979
+ let nonIndexedIdx = 0;
1980
+
1981
+ for (let i = 0; i < event.inputs.length; i++) {
1982
+ if (event.inputs[i]!.indexed) {
1983
+ args[i] = decodedIndexed[indexedIdx++];
1984
+ } else {
1985
+ args[i] = decodedNonIndexed[nonIndexedIdx++];
1986
+ }
1986
1987
  }
1987
1988
 
1988
1989
  return {
1989
1990
  ...log,
1990
- eventName: decodedLog.eventName,
1991
- args: reorderedArgs,
1991
+ eventName: event.name,
1992
+ args,
1992
1993
  } as EventLog;
1993
1994
  }
1994
1995