{"version":3,"sources":["../../src/batch-settlement/encoding.ts"],"sourcesContent":["/**\n * @file Encoding helpers for batch-settlement deposit collectors.\n */\nimport { encodeAbiParameters, keccak256 } from \"viem\";\n\n/**\n * Computes the ERC-3009 nonce used by the deposit collector:\n * `keccak256(abi.encode(channelId, salt))`.\n *\n * @param channelId - The `bytes32` channel id binding the authorization to a channel.\n * @param salt - Random salt provided by the client to make the nonce unique per deposit.\n * @returns The `bytes32` ERC-3009 nonce.\n */\nexport function buildErc3009DepositNonce(\n  channelId: `0x${string}`,\n  salt: `0x${string}`,\n): `0x${string}` {\n  return keccak256(\n    encodeAbiParameters([{ type: \"bytes32\" }, { type: \"uint256\" }], [channelId, BigInt(salt)]),\n  );\n}\n\n/**\n * Encodes the `collectorData` payload for `ERC3009DepositCollector.collect()`:\n * `abi.encode(validAfter, validBefore, salt, signature)`.\n *\n * @param validAfter - Earliest unix timestamp the authorization is valid (decimal string).\n * @param validBefore - Latest unix timestamp the authorization is valid (decimal string).\n * @param salt - Random salt provided by the client (hex string).\n * @param signature - ERC-3009 `ReceiveWithAuthorization` signature.\n * @returns ABI-encoded collector data passed to `deposit(..., collector, collectorData)`.\n */\nexport function buildErc3009CollectorData(\n  validAfter: string,\n  validBefore: string,\n  salt: `0x${string}`,\n  signature: `0x${string}`,\n): `0x${string}` {\n  return encodeAbiParameters(\n    [{ type: \"uint256\" }, { type: \"uint256\" }, { type: \"uint256\" }, { type: \"bytes\" }],\n    [BigInt(validAfter), BigInt(validBefore), BigInt(salt), signature],\n  );\n}\n\n/**\n * Encodes optional EIP-2612 permit data consumed by `Permit2DepositCollector`.\n *\n * @param params - Permit amount, deadline, and split signature fields.\n * @param params.value - Approved Permit2 allowance value.\n * @param params.deadline - EIP-2612 permit deadline.\n * @param params.v - Signature recovery id.\n * @param params.r - Signature `r` value.\n * @param params.s - Signature `s` value.\n * @returns ABI-encoded permit segment.\n */\nexport function buildEip2612PermitData(params: {\n  value: string;\n  deadline: string;\n  v: number;\n  r: `0x${string}`;\n  s: `0x${string}`;\n}): `0x${string}` {\n  return encodeAbiParameters(\n    [\n      { type: \"uint256\" },\n      { type: \"uint256\" },\n      { type: \"uint8\" },\n      { type: \"bytes32\" },\n      { type: \"bytes32\" },\n    ],\n    [BigInt(params.value), BigInt(params.deadline), params.v, params.r, params.s],\n  );\n}\n\n/**\n * Encodes the `collectorData` payload for `Permit2DepositCollector.collect()`.\n *\n * @param nonce - Permit2 transfer nonce.\n * @param deadline - Permit2 transfer deadline.\n * @param permit2Signature - Signature over the channel-bound Permit2 authorization.\n * @param eip2612PermitData - Optional encoded EIP-2612 permit segment.\n * @returns ABI-encoded collector data passed to `deposit`.\n */\nexport function buildPermit2CollectorData(\n  nonce: string,\n  deadline: string,\n  permit2Signature: `0x${string}`,\n  eip2612PermitData: `0x${string}` = \"0x\",\n): `0x${string}` {\n  return encodeAbiParameters(\n    [{ type: \"uint256\" }, { type: \"uint256\" }, { type: \"bytes\" }, { type: \"bytes\" }],\n    [BigInt(nonce), BigInt(deadline), permit2Signature, eip2612PermitData],\n  );\n}\n"],"mappings":";AAGA,SAAS,qBAAqB,iBAAiB;AAUxC,SAAS,yBACd,WACA,MACe;AACf,SAAO;AAAA,IACL,oBAAoB,CAAC,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,UAAU,CAAC,GAAG,CAAC,WAAW,OAAO,IAAI,CAAC,CAAC;AAAA,EAC3F;AACF;AAYO,SAAS,0BACd,YACA,aACA,MACA,WACe;AACf,SAAO;AAAA,IACL,CAAC,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,QAAQ,CAAC;AAAA,IACjF,CAAC,OAAO,UAAU,GAAG,OAAO,WAAW,GAAG,OAAO,IAAI,GAAG,SAAS;AAAA,EACnE;AACF;AAaO,SAAS,uBAAuB,QAMrB;AAChB,SAAO;AAAA,IACL;AAAA,MACE,EAAE,MAAM,UAAU;AAAA,MAClB,EAAE,MAAM,UAAU;AAAA,MAClB,EAAE,MAAM,QAAQ;AAAA,MAChB,EAAE,MAAM,UAAU;AAAA,MAClB,EAAE,MAAM,UAAU;AAAA,IACpB;AAAA,IACA,CAAC,OAAO,OAAO,KAAK,GAAG,OAAO,OAAO,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAAA,EAC9E;AACF;AAWO,SAAS,0BACd,OACA,UACA,kBACA,oBAAmC,MACpB;AACf,SAAO;AAAA,IACL,CAAC,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,UAAU,GAAG,EAAE,MAAM,QAAQ,GAAG,EAAE,MAAM,QAAQ,CAAC;AAAA,IAC/E,CAAC,OAAO,KAAK,GAAG,OAAO,QAAQ,GAAG,kBAAkB,iBAAiB;AAAA,EACvE;AACF;","names":[]}