@anywalletkit/protocol-swap2-across 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/README.md +177 -2
- package/dist/activity.cjs +142 -0
- package/dist/activity.cjs.map +1 -0
- package/dist/activity.d.cts +16 -0
- package/dist/activity.d.ts +16 -0
- package/dist/activity.js +10 -0
- package/dist/activity.js.map +1 -0
- package/dist/api.cjs +441 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +207 -0
- package/dist/api.d.ts +207 -0
- package/dist/api.js +35 -0
- package/dist/api.js.map +1 -0
- package/dist/build.cjs +776 -0
- package/dist/build.cjs.map +1 -0
- package/dist/build.d.cts +93 -0
- package/dist/build.d.ts +93 -0
- package/dist/build.js +14 -0
- package/dist/build.js.map +1 -0
- package/dist/chunk-32YJEBZX.js +125 -0
- package/dist/chunk-32YJEBZX.js.map +1 -0
- package/dist/chunk-3UBRQ3ZE.js +255 -0
- package/dist/chunk-3UBRQ3ZE.js.map +1 -0
- package/dist/chunk-5BDZXOOP.js +21 -0
- package/dist/chunk-5BDZXOOP.js.map +1 -0
- package/dist/chunk-6Z4GXNLE.js +102 -0
- package/dist/chunk-6Z4GXNLE.js.map +1 -0
- package/dist/chunk-AWQT5S4V.js +101 -0
- package/dist/chunk-AWQT5S4V.js.map +1 -0
- package/dist/chunk-E5WFOPN2.js +16 -0
- package/dist/chunk-E5WFOPN2.js.map +1 -0
- package/dist/chunk-GX67FRPG.js +194 -0
- package/dist/chunk-GX67FRPG.js.map +1 -0
- package/dist/chunk-KATEONJQ.js +396 -0
- package/dist/chunk-KATEONJQ.js.map +1 -0
- package/dist/chunk-P32AW6XS.js +27 -0
- package/dist/chunk-P32AW6XS.js.map +1 -0
- package/dist/chunk-PPPZIG7S.js +265 -0
- package/dist/chunk-PPPZIG7S.js.map +1 -0
- package/dist/chunk-SJOFLM27.js +138 -0
- package/dist/chunk-SJOFLM27.js.map +1 -0
- package/dist/chunk-YGNP7KPL.js +311 -0
- package/dist/chunk-YGNP7KPL.js.map +1 -0
- package/dist/config.cjs +214 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +119 -0
- package/dist/config.d.ts +119 -0
- package/dist/config.js +47 -0
- package/dist/config.js.map +1 -0
- package/dist/deposit.cjs +252 -0
- package/dist/deposit.cjs.map +1 -0
- package/dist/deposit.d.cts +95 -0
- package/dist/deposit.d.ts +95 -0
- package/dist/deposit.js +19 -0
- package/dist/deposit.js.map +1 -0
- package/dist/index.cjs +1789 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +242 -0
- package/dist/index.js.map +1 -0
- package/dist/pricing.cjs +132 -0
- package/dist/pricing.cjs.map +1 -0
- package/dist/pricing.d.cts +123 -0
- package/dist/pricing.d.ts +123 -0
- package/dist/pricing.js +42 -0
- package/dist/pricing.js.map +1 -0
- package/dist/protocol.cjs +1596 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +20 -0
- package/dist/protocol.d.ts +20 -0
- package/dist/protocol.js +17 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +1581 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +45 -0
- package/dist/provider.d.ts +45 -0
- package/dist/provider.js +18 -0
- package/dist/provider.js.map +1 -0
- package/dist/remote.cjs +1659 -0
- package/dist/remote.cjs.map +1 -0
- package/dist/remote.d.cts +55 -0
- package/dist/remote.d.ts +55 -0
- package/dist/remote.js +17 -0
- package/dist/remote.js.map +1 -0
- package/dist/status.cjs +443 -0
- package/dist/status.cjs.map +1 -0
- package/dist/status.d.cts +109 -0
- package/dist/status.d.ts +109 -0
- package/dist/status.js +26 -0
- package/dist/status.js.map +1 -0
- package/dist/verify.cjs +690 -0
- package/dist/verify.cjs.map +1 -0
- package/dist/verify.d.cts +245 -0
- package/dist/verify.d.ts +245 -0
- package/dist/verify.js +69 -0
- package/dist/verify.js.map +1 -0
- package/module.json +32 -0
- package/package.json +124 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/status.ts","../src/config.ts","../src/deposit.ts","../src/refusal.ts"],"sourcesContent":["/**\n * Where an Across deposit stands, read from the chains themselves — no Across API.\n *\n * 1. The source receipt: the deposit's `FundsDeposited` event, emitted by the pinned SpokePool of the source chain,\n * carries every field of the relay (V3SpokePoolInterface.sol `FundsDeposited`; `exclusivityDeadline` there is the\n * resolved timestamp, which is what the relay is keyed by). The event taken is the intent's own: the `deposit`\n * calldata its fields make hashes to the intent id's digest ({@link acrossDepositIsIntent}) — another deposit in\n * the same transaction, or another transaction's, is never reported as this one.\n * 2. The relay hash, exactly as the destination SpokePool computes it: `keccak256(abi.encode(relayData, chainId()))`\n * with `relayData` the `V3RelayData` struct (depositor, recipient, exclusiveRelayer, inputToken, outputToken,\n * inputAmount, outputAmount, originChainId, depositId, fillDeadline, exclusivityDeadline, message) and `chainId()`\n * the destination's own `block.chainid` (SpokePool.sol `getV3RelayHash`; no pinned chain overrides it).\n * 3. The destination SpokePool's `fillStatuses(relayHash)`, read at the latest block together with that block's time:\n * 2 is filled; 0 (unfilled) or 1 (slow fill requested) is still open while the block time is at or before the fill\n * deadline, and final after it — every fill path reverts with `ExpiredFillDeadline` once `fillDeadline <\n * block.timestamp`. Such a deposit is reported `expired`, a terminal state: Across refunds it to its depositor on\n * the source chain through its next settlement bundles (hours, not minutes; Across's docs: \"do not tell users to\n * expect immediate refunds\"), and this module does not watch for the refund itself.\n *\n * Display only: nothing is signed on what this reads. A node that does not answer, or a receipt that does not hold\n * exactly the intent's deposit, leaves the status where it was (\"pending\"); a terminal state is reported only from a\n * reverted receipt or a fill status that says so.\n */\nimport {decodeAbiParameters, encodeAbiParameters, keccak256, type Hex} from \"viem\";\nimport type {IntentStatus} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {redactUrls, timeoutSignal} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {ACROSS_FILL_STATUSES, ACROSS_FUNDS_DEPOSITED, ACROSS_MAX_EXCLUSIVITY_PERIOD_S, type AcrossChain} from \"./config.js\";\nimport {acrossAddressOf, encodeAcrossDeposit} from \"./deposit.js\";\n\n/** A deposit as its `FundsDeposited` event states it. Parties and tokens are the raw bytes32 words, lowercase. */\nexport interface AcrossDepositEvent {\n originChainId: number;\n destinationChainId: bigint;\n depositId: bigint;\n depositor: Hex;\n recipient: Hex;\n exclusiveRelayer: Hex;\n inputToken: Hex;\n outputToken: Hex;\n inputAmount: bigint;\n outputAmount: bigint;\n quoteTimestamp: number;\n fillDeadline: number;\n /** The resolved exclusivity deadline (0 for none), not the deposit's raw parameter. */\n exclusivityDeadline: number;\n message: Hex;\n}\n\n/** `fillStatuses` values (V3SpokePoolInterface.sol `FillStatus`). */\nexport const ACROSS_FILL_STATUS = Object.freeze({UNFILLED: 0, REQUESTED_SLOW_FILL: 1, FILLED: 2} as const);\n\n/** A relay's state on the destination. `expired`: unfilled past its fill deadline — refunded on the source chain by Across. */\nexport type AcrossFillState = \"unfilled\" | \"slow-fill-requested\" | \"filled\" | \"expired\";\n\nconst EVENT_DATA = [\n {name: \"inputToken\", type: \"bytes32\"},\n {name: \"outputToken\", type: \"bytes32\"},\n {name: \"inputAmount\", type: \"uint256\"},\n {name: \"outputAmount\", type: \"uint256\"},\n {name: \"quoteTimestamp\", type: \"uint32\"},\n {name: \"fillDeadline\", type: \"uint32\"},\n {name: \"exclusivityDeadline\", type: \"uint32\"},\n {name: \"recipient\", type: \"bytes32\"},\n {name: \"exclusiveRelayer\", type: \"bytes32\"},\n {name: \"message\", type: \"bytes\"},\n] as const;\n\nconst RELAY_DATA = {\n type: \"tuple\",\n components: [\n {name: \"depositor\", type: \"bytes32\"},\n {name: \"recipient\", type: \"bytes32\"},\n {name: \"exclusiveRelayer\", type: \"bytes32\"},\n {name: \"inputToken\", type: \"bytes32\"},\n {name: \"outputToken\", type: \"bytes32\"},\n {name: \"inputAmount\", type: \"uint256\"},\n {name: \"outputAmount\", type: \"uint256\"},\n {name: \"originChainId\", type: \"uint256\"},\n {name: \"depositId\", type: \"uint256\"},\n {name: \"fillDeadline\", type: \"uint32\"},\n {name: \"exclusivityDeadline\", type: \"uint32\"},\n {name: \"message\", type: \"bytes\"},\n ],\n} as const;\n\nconst WORD = /^0x[0-9a-fA-F]{64}$/;\nconst HEX = /^0x(?:[0-9a-fA-F]{2})*$/;\nconst DIGEST = /^[0-9a-f]{32}$/;\nconst QUANTITY = /^0x[0-9a-fA-F]{1,16}$/;\nconst lowerHex = (s: string): Hex => s.toLowerCase() as Hex;\n\n/**\n * Every `FundsDeposited` the pinned SpokePool of `source` emitted in a transaction receipt (an `eth_getTransactionReceipt`\n * answer), in log order. Logs of any other contract, and logs that do not decode as the event, are skipped.\n */\nexport function acrossDepositsInReceipt(receipt: unknown, source: AcrossChain): AcrossDepositEvent[] {\n const logs = (receipt as {logs?: unknown} | null)?.logs;\n if (!Array.isArray(logs)) return [];\n const out: AcrossDepositEvent[] = [];\n for (const log of logs as {address?: unknown; topics?: unknown; data?: unknown; removed?: unknown}[]) {\n if (log === null || typeof log !== \"object\" || log.removed === true) continue;\n if (typeof log.address !== \"string\" || log.address.toLowerCase() !== source.spokePool) continue;\n const topics = log.topics;\n if (!Array.isArray(topics) || topics.length !== 4 || !topics.every((t) => typeof t === \"string\" && WORD.test(t))) continue;\n if ((topics[0] as string).toLowerCase() !== ACROSS_FUNDS_DEPOSITED) continue;\n if (typeof log.data !== \"string\" || !HEX.test(log.data)) continue;\n let d: readonly [Hex, Hex, bigint, bigint, number, number, number, Hex, Hex, Hex];\n try {\n d = decodeAbiParameters(EVENT_DATA, log.data as Hex);\n } catch {\n continue;\n }\n out.push({\n originChainId: source.chainId,\n destinationChainId: BigInt(topics[1] as string),\n depositId: BigInt(topics[2] as string),\n depositor: lowerHex(topics[3] as string),\n inputToken: lowerHex(d[0]),\n outputToken: lowerHex(d[1]),\n inputAmount: d[2],\n outputAmount: d[3],\n quoteTimestamp: d[4],\n fillDeadline: d[5],\n exclusivityDeadline: d[6],\n recipient: lowerHex(d[7]),\n exclusiveRelayer: lowerHex(d[8]),\n message: lowerHex(d[9]),\n });\n }\n return out;\n}\n\n/**\n * The `deposit` calldata an event's fields make with this exclusivity parameter — what an intent id's digest is taken\n * over. Null for a deposit whose parties or tokens are not EVM addresses: not one this module builds.\n */\nfunction depositDataOf(e: AcrossDepositEvent, exclusivityParameter: number): Hex | null {\n const depositor = acrossAddressOf(e.depositor);\n const recipient = acrossAddressOf(e.recipient);\n const inputToken = acrossAddressOf(e.inputToken);\n const outputToken = acrossAddressOf(e.outputToken);\n const exclusiveRelayer = acrossAddressOf(e.exclusiveRelayer);\n if (!depositor || !recipient || !inputToken || !outputToken || !exclusiveRelayer) return null;\n try {\n return encodeAcrossDeposit({\n depositor, recipient, inputToken, outputToken, inputAmount: e.inputAmount, outputAmount: e.outputAmount, destinationChainId: e.destinationChainId,\n exclusiveRelayer, quoteTimestamp: e.quoteTimestamp, fillDeadline: e.fillDeadline, exclusivityParameter, message: e.message,\n });\n } catch {\n return null;\n }\n}\n\n/**\n * Whether a deposit event is the one an intent id names: the canonical `deposit` calldata of its fields hashes to the\n * id's digest (`acrossIntentId`), so every field — parties, tokens, amounts, destination, deadlines, message — is the\n * signed one. The event carries the resolved exclusivity deadline, not the parameter: 0 for none, the parameter itself\n * for a timestamp, and for an offset the time of the block the deposit landed in plus the offset (SpokePool.sol\n * `_depositV3`) — so an offset is recognized only with `sourceBlockTime`.\n */\nexport function acrossDepositIsIntent(e: AcrossDepositEvent, digest: string, sourceBlockTime?: number): boolean {\n if (typeof digest !== \"string\" || !DIGEST.test(digest)) return false;\n const d = e.exclusivityDeadline;\n const candidates: number[] = [];\n if (d === 0) candidates.push(0);\n else {\n if (d > ACROSS_MAX_EXCLUSIVITY_PERIOD_S) candidates.push(d);\n if (sourceBlockTime !== undefined && d - sourceBlockTime > 0 && d - sourceBlockTime <= ACROSS_MAX_EXCLUSIVITY_PERIOD_S) candidates.push(d - sourceBlockTime);\n }\n return candidates.some((p) => {\n const data = depositDataOf(e, p);\n return data !== null && keccak256(data).slice(2, 34) === digest;\n });\n}\n\n/** The relay hash of a deposit — the key of `fillStatuses` on its destination chain. */\nexport function acrossRelayHash(e: AcrossDepositEvent): Hex {\n return keccak256(encodeAbiParameters([RELAY_DATA, {type: \"uint256\"}], [{\n depositor: e.depositor,\n recipient: e.recipient,\n exclusiveRelayer: e.exclusiveRelayer,\n inputToken: e.inputToken,\n outputToken: e.outputToken,\n inputAmount: e.inputAmount,\n outputAmount: e.outputAmount,\n originChainId: BigInt(e.originChainId),\n depositId: e.depositId,\n fillDeadline: e.fillDeadline,\n exclusivityDeadline: e.exclusivityDeadline,\n message: e.message,\n }, e.destinationChainId]));\n}\n\n/** Calldata of `fillStatuses(relayHash)`. */\nexport function acrossFillStatusCall(relayHash: Hex): Hex {\n if (!WORD.test(relayHash)) throw new Error(\"across: a relay hash is 32 bytes\");\n return `${ACROSS_FILL_STATUSES}${relayHash.slice(2).toLowerCase()}` as Hex;\n}\n\n/** A `fillStatuses` answer: 0, 1 or 2; null for anything else (another word, another length). */\nexport function parseAcrossFillStatus(answer: unknown): 0 | 1 | 2 | null {\n if (typeof answer !== \"string\" || !/^0x0{63}[0-2]$/i.test(answer)) return null;\n return Number(answer.slice(-1)) as 0 | 1 | 2;\n}\n\n/** A fill status read at a destination block whose time is `blockTime`. */\nexport function acrossFillState(status: 0 | 1 | 2, fillDeadline: number, blockTime: number): AcrossFillState {\n if (status === ACROSS_FILL_STATUS.FILLED) return \"filled\";\n // `fillDeadline < block.timestamp` reverts every fill, slow or fast: at a later block nothing can fill it any more.\n if (blockTime > fillDeadline) return \"expired\";\n return status === ACROSS_FILL_STATUS.REQUESTED_SLOW_FILL ? \"slow-fill-requested\" : \"unfilled\";\n}\n\n/** A JSON-RPC caller: the `result` of `method`, or a throw. */\nexport type AcrossRpc = (method: string, params: readonly unknown[]) => Promise<unknown>;\n\nconst MAX_RPC_BODY = 8 * 1024 * 1024;\n\n/** A minimal JSON-RPC client over `fetch` (12 s per call); its errors never carry the URL (a keyed RPC has its key there). */\nexport function acrossRpc(url: string, fetchImpl?: typeof fetch, timeoutMs = 12_000): AcrossRpc {\n if (typeof url !== \"string\" || !/^https?:\\/\\//.test(url)) throw new Error(\"across: an RPC URL must use http or https\");\n let id = 0;\n return async (method, params) => {\n let text: string;\n try {\n const res = await (fetchImpl ?? fetch)(url, {\n method: \"POST\",\n headers: {\"content-type\": \"application/json\", accept: \"application/json\"},\n body: JSON.stringify({jsonrpc: \"2.0\", id: ++id, method, params}),\n signal: timeoutSignal(timeoutMs),\n });\n if (!res.ok) throw new Error(`HTTP ${res.status}`);\n text = await res.text();\n } catch (err) {\n throw new Error(`across: ${method} failed — ${redactUrls(err instanceof Error ? err.message : String(err)).slice(0, 160)}`);\n }\n if (text.length > MAX_RPC_BODY) throw new Error(`across: ${method} answered more than ${MAX_RPC_BODY} bytes`);\n let body: {result?: unknown; error?: {message?: unknown}} | null;\n try {\n body = JSON.parse(text) as typeof body;\n } catch {\n throw new Error(`across: ${method} answered something that is not JSON`);\n }\n if (body === null || typeof body !== \"object\") throw new Error(`across: ${method} answered something that is not JSON-RPC`);\n if (body.error !== undefined) throw new Error(`across: ${method} failed — ${redactUrls(String(body.error?.message ?? \"error\")).slice(0, 160)}`);\n if (!Object.prototype.hasOwnProperty.call(body, \"result\")) throw new Error(`across: ${method} answered no result`);\n return body.result;\n };\n}\n\n/** What {@link trackAcrossDeposit} found: the status, and the facts it rests on when they were read. */\nexport interface AcrossTrack {\n status: IntentStatus;\n deposit?: AcrossDepositEvent;\n relayHash?: Hex;\n fill?: AcrossFillState;\n /** The destination block the fill status was read at. */\n destBlock?: {number: string; timestamp: number};\n}\n\nexport interface AcrossTrackInput {\n sourceTxHash: string;\n /** The intent id's digest of the deposit calldata (`parseAcrossIntentId(id).digest`): the deposit looked for. */\n intentDigest: string;\n source: AcrossChain;\n dest: AcrossChain;\n /** The source chain's RPC; without it nothing can be read (\"pending\"). */\n sourceRpc?: AcrossRpc;\n /** The destination chain's RPC; without it the deposit is seen but its fill is not (\"pending\"). */\n destRpc?: AcrossRpc;\n}\n\n/** The time of a source block, by number; null when the node does not say. */\nasync function blockTimeOf(rpc: AcrossRpc, number: unknown): Promise<number | null> {\n if (typeof number !== \"string\" || !QUANTITY.test(number)) return null;\n try {\n const block = (await rpc(\"eth_getBlockByNumber\", [number, false])) as {number?: unknown; timestamp?: unknown} | null;\n const timestamp = block?.timestamp;\n if (typeof block?.number !== \"string\" || block.number.toLowerCase() !== number.toLowerCase()) return null;\n if (typeof timestamp !== \"string\" || !/^0x[0-9a-fA-F]{1,12}$/.test(timestamp)) return null;\n return parseInt(timestamp, 16);\n } catch {\n return null;\n }\n}\n\n/**\n * The intent's deposit in the transaction `sourceTxHash` from `source` to `dest`, and whether it was filled — read on\n * chain only.\n */\nexport async function trackAcrossDeposit(input: AcrossTrackInput): Promise<AcrossTrack> {\n const {source, dest, sourceRpc, destRpc} = input;\n if (typeof input.sourceTxHash !== \"string\" || !WORD.test(input.sourceTxHash) || !sourceRpc) return {status: {state: \"pending\"}};\n if (typeof input.intentDigest !== \"string\" || !DIGEST.test(input.intentDigest)) return {status: {state: \"pending\"}};\n let receipt: unknown;\n try {\n receipt = await sourceRpc(\"eth_getTransactionReceipt\", [input.sourceTxHash]);\n } catch {\n return {status: {state: \"pending\"}};\n }\n // Not mined yet (or not seen by this node).\n if (receipt === null || receipt === undefined) return {status: {state: \"pending\"}};\n if (typeof receipt !== \"object\") return {status: {state: \"pending\"}};\n const status = (receipt as {status?: unknown}).status;\n // The deposit reverted: nothing left the wallet but the gas.\n if (status === \"0x0\") return {status: {state: \"failed\"}};\n if (status !== \"0x1\") return {status: {state: \"pending\"}};\n // A receipt for another transaction is no answer.\n const txHash = (receipt as {transactionHash?: unknown}).transactionHash;\n if (txHash !== undefined && (typeof txHash !== \"string\" || txHash.toLowerCase() !== input.sourceTxHash.toLowerCase())) return {status: {state: \"pending\"}};\n const onRoute = acrossDepositsInReceipt(receipt, source).filter((d) => d.destinationChainId === BigInt(dest.chainId));\n let mine = onRoute.filter((d) => acrossDepositIsIntent(d, input.intentDigest));\n // An offset exclusivity resolves against the source block's time, read only when an event needs it.\n if (mine.length === 0 && onRoute.some((d) => d.exclusivityDeadline !== 0)) {\n const blockTime = await blockTimeOf(sourceRpc, (receipt as {blockNumber?: unknown}).blockNumber);\n if (blockTime === null) return {status: {state: \"pending\"}};\n mine = onRoute.filter((d) => acrossDepositIsIntent(d, input.intentDigest, blockTime));\n }\n // Not exactly the intent's deposit — a node with partial logs, another transaction's hash, the same call twice:\n // nothing is known about this transfer, which is not a failure.\n if (mine.length !== 1) return {status: {state: \"pending\"}};\n const deposit = mine[0]!;\n const relayHash = acrossRelayHash(deposit);\n const seen: AcrossTrack = {status: {state: \"pending\", depositReceived: true}, deposit, relayHash};\n if (!destRpc) return seen;\n try {\n const block = (await destRpc(\"eth_getBlockByNumber\", [\"latest\", false])) as {number?: unknown; timestamp?: unknown} | null;\n const number = block?.number;\n const timestamp = block?.timestamp;\n if (typeof number !== \"string\" || !/^0x[0-9a-fA-F]{1,16}$/.test(number) || typeof timestamp !== \"string\" || !/^0x[0-9a-fA-F]{1,12}$/.test(timestamp)) return seen;\n const blockTime = parseInt(timestamp, 16);\n const fillStatus = parseAcrossFillStatus(await destRpc(\"eth_call\", [{to: dest.spokePool, data: acrossFillStatusCall(relayHash)}, number]));\n if (fillStatus === null) return seen;\n const fill = acrossFillState(fillStatus, deposit.fillDeadline, blockTime);\n const destBlock = {number: number.toLowerCase(), timestamp: blockTime};\n if (fill === \"filled\") return {status: {state: \"completed\", depositReceived: true}, deposit, relayHash, fill, destBlock};\n // Past its fill deadline unfilled: final. Across refunds the depositor on the source chain in the coming hours; the\n // refund is not watched here, so the state is one that ends polling.\n if (fill === \"expired\") return {status: {state: \"expired\", depositReceived: true}, deposit, relayHash, fill, destBlock};\n return {status: {state: \"pending\", depositReceived: true}, deposit, relayHash, fill, destBlock};\n } catch {\n return seen;\n }\n}\n","// Across Protocol — the pins this module signs against. Nothing here is read from an API at run time: the Across API\n// (or an app's own proxy in front of it) is untrusted, and a deposit is signed only for a SpokePool, a chain and a\n// token written in this file.\n//\n// Sources, all read on 2026-11-15:\n// - github.com/across-protocol/contracts @ d652689f67cd9835b9c1ab0acc2f99236902e299, `broadcast/deployed-addresses.json`\n// (\"the current source of truth for deployed contract addresses\", deployments/README.md): `chains.<id>.contracts.\n// SpokePool.address` for every row below, `chains.1.contracts.HubPool.address` for the hub.\n// - On chain, Ethereum: `HubPool.crossChainContracts(chainId)` (selector 0x09474ae2) answers the same SpokePool for\n// every row (publicnode, block 26415696; eth.drpc.org one block later agreed on every row).\n// - On chain, each row over a public RPC: `eth_chainId` and the SpokePool's own `chainId()` are the row's id; the\n// EIP-1967 implementation slot is set (UUPS proxy, upgraded through the HubPool); `crossDomainAdmin()` is the\n// HubPool; `wrappedNativeToken()` is the value pinned below; `depositQuoteTimeBuffer()` = 3600,\n// `fillDeadlineBuffer()` = 21600 and `pausedDeposits()` = false. The implementation carries the `deposit` selector\n// as PUSH4 on every EVM-bytecode chain. zkSync Era runs EraVM bytecode, where that scan does not apply: there a real\n// deposit was traced instead (tx 0x21c702af…f0d96, `debug_traceTransaction` callTracer): a successful call into the\n// SpokePool with selector 0xad5425c6, 420 bytes (empty message), which emitted FundsDeposited.\n// - The contract: contracts/spoke-pools/SpokePool.sol and contracts/interfaces/V3SpokePoolInterface.sol at the same\n// commit (selectors, event, relay hash, fill statuses, the native-coin rules quoted where they are used).\n// - Tokens: Across's own route list (`GET /available-routes`) and token list (`GET /swap/tokens`), read 2026-11-14,\n// intersected with the SDK's asset catalog (`@anywalletkit/swap2-assets`) by address. A token is pinned only when\n// Across bridges it to the SAME asset on another pinned chain with the same decimals; routes Across lists between\n// different assets (USDC → USDC.e, USDC-BNB → USDC, USDT → USDC, USDG → USDC) are not served.\n//\n// Chains Across serves that are NOT pinned, and why:\n// - Scroll (534352): `pausedDeposits()` is true on chain (as on Lens, Mode and Zora, which the SDK does not carry) and\n// it is gone from Across's own chain page.\n// - BNB Chain (56): Across bridges its Binance-Peg USDC and USDT (18 decimals) only into other assets, and its ETH is an\n// ERC-20 the catalog does not list — no same-asset route is left.\n// - Lisk, Soneium, Tempo, Blast, Boba, Solana, Tron, HyperCore, Lighter: not EVM chains of the SDK's catalog.\n// SDK chains Across does not serve: Gnosis, Sonic, Berachain, Celo, Mantle, Katana, Morph, Flare, Elysium, Sei, Plume,\n// X Layer.\n\n/** What a token is across chains. A deposit only ever moves an asset to the same asset. */\nexport type AcrossAsset = \"USDC\" | \"USDT\" | \"ETH\" | \"WBTC\";\n\nexport interface AcrossToken {\n asset: AcrossAsset;\n /** ERC-20 contract on this chain, lowercase. */\n address: string;\n /** The catalog's symbol on this chain (Tether's USDT is `USDT0` where it is issued as USDT0). */\n symbol: string;\n decimals: number;\n}\n\nexport interface AcrossChain {\n caip2: string;\n chainId: number;\n /** The SDK's chain key (`@anywalletkit/swap2-assets`). */\n key: string;\n name: string;\n /** SpokePool proxy on that chain: the only contract a deposit calls and the only spender an approval names. */\n spokePool: string;\n /**\n * `wrappedNativeToken()` of that SpokePool. A deposit that sends the native coin names it as `inputToken`; a fill of\n * it is paid out as the native coin to an EOA. Null where the SpokePool reports the zero address (Arc).\n */\n wrappedNative: string | null;\n /** The chain's native coin is ether, bridged as the ETH asset. */\n nativeIsEth: boolean;\n /** ERC-20s Across bridges to the same asset on another pinned chain. ETH's ERC-20 is the wrapped native token. */\n tokens: readonly AcrossToken[];\n}\n\nconst USDC = (address: string, symbol = \"USDC\"): AcrossToken => Object.freeze({asset: \"USDC\", address, symbol, decimals: 6});\nconst USDT = (address: string, symbol = \"USDT\"): AcrossToken => Object.freeze({asset: \"USDT\", address, symbol, decimals: 6});\nconst WETH = (address: string): AcrossToken => Object.freeze({asset: \"ETH\", address, symbol: \"WETH\", decimals: 18});\nconst WBTC = (address: string): AcrossToken => Object.freeze({asset: \"WBTC\", address, symbol: \"WBTC\", decimals: 8});\n\n/** The OP-stack predeploy WETH9. */\nconst OP_WETH = \"0x4200000000000000000000000000000000000006\";\n\nfunction chain(\n chainId: number, key: string, name: string, spokePool: string, wrappedNative: string | null, nativeIsEth: boolean, tokens: AcrossToken[],\n): AcrossChain {\n return Object.freeze({caip2: `eip155:${chainId}`, chainId, key, name, spokePool, wrappedNative, nativeIsEth, tokens: Object.freeze(tokens)});\n}\n\n/** CAIP-2 → the chain as Across serves it. A null-prototype map: `ACROSS_CHAINS[\"constructor\"]` is undefined. */\nexport const ACROSS_CHAINS: Readonly<Record<string, AcrossChain>> = Object.freeze(Object.assign(Object.create(null) as Record<string, AcrossChain>, Object.fromEntries([\n chain(1, \"ethereum\", \"Ethereum\", \"0x5c7bcd6e7de5423a257d81b442095a1a6ced35c5\", \"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\", true, [\n USDC(\"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\"),\n USDT(\"0xdac17f958d2ee523a2206206994597c13d831ec7\"),\n WETH(\"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2\"),\n WBTC(\"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599\"),\n ]),\n chain(10, \"optimism\", \"Optimism\", \"0x6f26bf09b1c792e3228e5467807a900a503c0281\", OP_WETH, true, [\n USDC(\"0x0b2c639c533813f4aa9d7837caf62653d097ff85\"),\n USDT(\"0x94b008aa00579c1307b0ef2c499ad98a8ce58e58\"),\n WETH(OP_WETH),\n ]),\n chain(130, \"unichain\", \"Unichain\", \"0x09aea4b2242abc8bb4bb78d537a67a245a7bec64\", OP_WETH, true, [\n USDC(\"0x078d782b760474a361dda0af3839290b0ef57ad6\"),\n USDT(\"0x9151434b16b9763660705744891fa906f660ecc5\", \"USDT0\"),\n WETH(OP_WETH),\n ]),\n chain(137, \"polygon\", \"Polygon\", \"0x9295ee1d8c5b022be115a2ad3c30c72e34e7f096\", \"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270\", false, [\n USDC(\"0x3c499c542cef5e3811e1192ce70d8cc03d5c3359\"),\n USDT(\"0xc2132d05d31c914a87c6611c10748aeb04b58e8f\"),\n WBTC(\"0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6\"),\n ]),\n chain(143, \"monad\", \"Monad\", \"0xd2ecb3afe598b746f8123cae365a598da831a449\", \"0x3bd359c1119da7da1d913d1c4d2b7c461115433a\", false, [\n USDC(\"0x754704bc059f8c67012fed69bc8a327a5aafb603\"),\n USDT(\"0xe7cd86e13ac4309349f30b3435a9d337750fc82d\", \"USDT0\"),\n ]),\n chain(324, \"zksync\", \"zkSync Era\", \"0xe0b015e54d54fc84a6cb9b666099c46ade9335ff\", \"0x5aea5775959fbc2557cc8789bc1bf90a239d9a91\", true, [\n USDT(\"0x493257fd37edb34451f62edf8d2a0c418852ba4c\"),\n WETH(\"0x5aea5775959fbc2557cc8789bc1bf90a239d9a91\"),\n WBTC(\"0xbbeb516fb02a01611cbbe0453fe3c580d7281011\"),\n ]),\n chain(480, \"worldchain\", \"World Chain\", \"0x09aea4b2242abc8bb4bb78d537a67a245a7bec64\", OP_WETH, true, [\n USDC(\"0x79a02482a880bce3f13e09da970dc34db4cd24d1\"),\n WETH(OP_WETH),\n WBTC(\"0x03c7054bcb39f7b2e5b2c7acb37583e32d70cfa3\"),\n ]),\n chain(999, \"hyperevm\", \"HyperEVM\", \"0x35e63ea3eb0fb7a3bc543c71fb66412e1f6b0e04\", \"0x5555555555555555555555555555555555555555\", false, [\n USDC(\"0xb88339cb7199b77e23db6e890353e22632ba630f\"),\n USDT(\"0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb\", \"USDT0\"),\n ]),\n chain(4326, \"megaeth\", \"MegaETH\", \"0x3db06da8f0a24a525f314eec954fc5c6a973d40e\", OP_WETH, true, [\n USDT(\"0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb\", \"USDT0\"),\n WETH(OP_WETH),\n ]),\n chain(4663, \"robinhood\", \"Robinhood Chain\", \"0xd29c85f15df544ba632c9e25829fd29d767d7978\", \"0x0bd7d308f8e1639fab988df18a8011f41eacad73\", true, [\n WETH(\"0x0bd7d308f8e1639fab988df18a8011f41eacad73\"),\n ]),\n // Arc's gas coin is USDC; 0x3600… is its 6-decimal ERC-20 interface, which is what Across moves. The SpokePool\n // reports no wrapped native token, so no deposit or fill on Arc involves the native coin.\n chain(5042, \"arc\", \"Arc\", \"0x9b4a302a548c7e313c2b74c461db7b84d3074a84\", null, false, [\n USDC(\"0x3600000000000000000000000000000000000000\"),\n ]),\n chain(8453, \"base\", \"Base\", \"0x09aea4b2242abc8bb4bb78d537a67a245a7bec64\", OP_WETH, true, [\n USDC(\"0x833589fcd6edb6e08f4c7c32d4f71b54bda02913\"),\n USDT(\"0xfde4c96c8593536e31f229ea8f37b2ada2699bb2\"),\n WETH(OP_WETH),\n ]),\n chain(9745, \"plasma\", \"Plasma\", \"0x50039faefebef707cfd94d6d462fe6d10b39207a\", \"0x6100e367285b01f48d07953803a2d8dca5d19873\", false, [\n USDT(\"0xb8ce59fc3717ada4c02eadf9682a9e934f625ebb\", \"USDT0\"),\n ]),\n chain(42161, \"arbitrum\", \"Arbitrum\", \"0xe35e9842fceaca96570b734083f4a58e8f7c5f2a\", \"0x82af49447d8a07e3bd95bd0d56f35241523fbab1\", true, [\n USDC(\"0xaf88d065e77c8cc2239327c5edb3a432268e5831\"),\n USDT(\"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9\", \"USDT0\"),\n WETH(\"0x82af49447d8a07e3bd95bd0d56f35241523fbab1\"),\n WBTC(\"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f\"),\n ]),\n chain(43114, \"avalanche\", \"Avalanche\", \"0xfe9d541c92e4e90437c7152a00244886de37a658\", \"0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7\", false, [\n USDC(\"0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e\"),\n USDT(\"0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7\"),\n ]),\n chain(57073, \"ink\", \"Ink\", \"0xef684c38f94f48775959ecf2012d7e864ffb9dd4\", OP_WETH, true, [\n USDC(\"0x2d270e6886d130d724215a266106e6832161eaed\"),\n USDT(\"0x0200c29006150606b650577bbe7b6248f58470c1\", \"USDT0\"),\n WETH(OP_WETH),\n ]),\n chain(59144, \"linea\", \"Linea\", \"0x7e63a5f1a8f0b4d0934b2f2327daed3f6bb2ee75\", \"0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f\", true, [\n USDC(\"0x176211869ca2b568f2a7d4ee941e073a821ee1ff\"),\n USDT(\"0xa219439258ca9da29e9cc4ce5596924745e12b93\"),\n WETH(\"0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f\"),\n WBTC(\"0x3aab2285ddcddad8edf438c1bab47e1a9d05a9b4\"),\n ]),\n].map((x) => [x.caip2, x]))));\n\n/** The chain for a CAIP-2 id, or undefined — own keys only. */\nexport function acrossChain(caip2: string): AcrossChain | undefined {\n return typeof caip2 === \"string\" && Object.prototype.hasOwnProperty.call(ACROSS_CHAINS, caip2) ? ACROSS_CHAINS[caip2] : undefined;\n}\n\n/** The pinned token at `address` on `chain` (any casing), or undefined. */\nexport function acrossToken(chain: AcrossChain, address: string): AcrossToken | undefined {\n if (typeof address !== \"string\") return undefined;\n const a = address.toLowerCase();\n return chain.tokens.find((t) => t.address === a);\n}\n\n/**\n * The HubPool on Ethereum: `crossChainContracts(chainId)` is the registry every pinned SpokePool was checked against.\n * Not a proxy; owned by a 3-of-5 Safe that can re-point the registry and upgrade every SpokePool — a watched fact.\n */\nexport const ACROSS_HUB_POOL = \"0xc186fa914353c44b2e33ebe05f21846f1048beda\";\n/** `crossChainContracts(uint256)` on the HubPool → `(address adapter, address spokePool)`. */\nexport const ACROSS_HUB_CROSS_CHAIN_CONTRACTS = \"0x09474ae2\";\n\n/**\n * `deposit(bytes32 depositor, bytes32 recipient, bytes32 inputToken, bytes32 outputToken, uint256 inputAmount,\n * uint256 outputAmount, uint256 destinationChainId, bytes32 exclusiveRelayer, uint32 quoteTimestamp,\n * uint32 fillDeadline, uint32 exclusivityParameter, bytes message)` payable — the only call this module builds or signs.\n */\nexport const ACROSS_DEPOSIT = \"0xad5425c6\";\n/** `depositV3(address …)`: the address-typed wrapper of `deposit`. Read in history, never built or signed. */\nexport const ACROSS_DEPOSIT_V3 = \"0x7b939232\";\n/**\n * Calls on a SpokePool that are always refused: `unsafeDeposit` (a caller-chosen deposit id that can collide),\n * `depositNow` / `depositV3Now` (the fill deadline set on chain), `speedUpDeposit` / `speedUpV3Deposit` (a depositor\n * signature that lets a relayer pay another recipient or a lower amount), and `multicall`.\n */\nexport const ACROSS_REFUSED_SELECTORS: Readonly<Record<string, string>> = Object.freeze({\n \"0x8b15788e\": \"unsafeDeposit\",\n \"0xea86bd46\": \"depositNow\",\n \"0x7aef642c\": \"depositV3Now\",\n \"0xbabb6aac\": \"speedUpDeposit\",\n \"0x577f51f8\": \"speedUpV3Deposit\",\n \"0xac9650d8\": \"multicall\",\n});\n\n/**\n * `UpdateDepositDetails(uint256 depositId,uint256 originChainId,uint256 updatedOutputAmount,bytes32 updatedRecipient,\n * bytes updatedMessage)` under the domain `ACROSS-V2` / `1.0.0`: the speed-up signature. It can move a deposit's\n * output to another recipient, so nothing carrying this type (or that domain) is ever signed through this module.\n */\nexport const ACROSS_SPEED_UP_TYPEHASH = \"0x8d1994e2bbbd77564cdca06dd819e7ee2a5efa06c80dcb59a4a7b6e39edc538f\";\nexport const ACROSS_SPEED_UP_TYPE = \"UpdateDepositDetails\";\nexport const ACROSS_SPEED_UP_DOMAIN = \"ACROSS-V2\";\n\n/**\n * `FundsDeposited(bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount,\n * uint256 indexed destinationChainId, uint256 indexed depositId, uint32 quoteTimestamp, uint32 fillDeadline,\n * uint32 exclusivityDeadline, bytes32 indexed depositor, bytes32 recipient, bytes32 exclusiveRelayer, bytes message)`.\n */\nexport const ACROSS_FUNDS_DEPOSITED = \"0x32ed1a409ef04c7b0227189c3a103dc5ac10e775a15b785dcc510201f7c25ad3\";\n/** `fillStatuses(bytes32 relayHash)` → 0 unfilled, 1 slow fill requested, 2 filled. */\nexport const ACROSS_FILL_STATUSES = \"0xc35c83fc\";\n\n/**\n * `keccak256(\"AcrossV5MessagePrefix.V1\")`: a deposit message starting with these 32 bytes is an Across V5 witness,\n * consumable only through the Gateway's V5 fill entry points (SpokePool.sol `V5_MAGIC_PREFIX`). Refused by name —\n * this module signs empty messages only.\n */\nexport const ACROSS_V5_MESSAGE_PREFIX = \"0x89ae4bc75915265a3f10e926c3894a29534f1d6362ee8959cb0e5be00f3527fd\";\n\n/** `depositQuoteTimeBuffer()` on every pinned SpokePool: a deposit's `quoteTimestamp` may be at most this old. */\nexport const ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S = 3600;\n/** `fillDeadlineBuffer()` on every pinned SpokePool: a deposit's `fillDeadline` may be at most this far ahead. */\nexport const ACROSS_FILL_DEADLINE_BUFFER_S = 21_600;\n/** SpokePool `MAX_EXCLUSIVITY_PERIOD_SECONDS`: an `exclusivityParameter` up to this is an offset, above it a timestamp. */\nexport const ACROSS_MAX_EXCLUSIVITY_PERIOD_S = 31_536_000;\n\n/** The native coin in a request (and in Across's own token lists): twenty zero bytes. */\nexport const ACROSS_NATIVE = \"0x0000000000000000000000000000000000000000\";\n\n/** Across API V5: the price source (`api.ts`), with a key from dashboard.across.to kept on a server. */\nexport const ACROSS_API = \"https://api.across.to\";\n\nconst ZERO = /^0x0{40}$/;\nconst isNativeRef = (token: string): boolean => ZERO.test(token);\n\n/** One side of a route: the token as the deposit names it, and whether the user's side of it is the native coin. */\nexport interface AcrossRouteSide {\n chain: AcrossChain;\n /** The token the deposit names: the ERC-20, or the wrapped native token when `native`. */\n token: string;\n native: boolean;\n decimals: number;\n}\n\nexport interface AcrossRoute {\n asset: AcrossAsset;\n input: AcrossRouteSide;\n output: AcrossRouteSide;\n}\n\n/** Why a pair is not served, for a refusal. */\nexport interface AcrossRouteMiss {\n code: \"chain-unsupported\" | \"token-unsupported\" | \"pair-unsupported\" | \"native-unsupported\" | \"wrapped-native-destination\";\n detail: string;\n}\n\n/**\n * The route a request names, or why it is not served. `sourceToken` / `destToken` are contracts (any casing) or the\n * zero address for the native coin. Served: two different pinned chains, the same asset on both sides, the native coin\n * only where it is ether and the SpokePool wraps it, and never the wrapped native token as a destination ERC-20 — an\n * empty-message fill of it pays an EOA the native coin, which is not what was asked for.\n */\nexport function acrossRouteOf(sourceChain: string, sourceToken: string, destChain: string, destToken: string): AcrossRoute | AcrossRouteMiss {\n const src = acrossChain(sourceChain);\n const dst = acrossChain(destChain);\n if (!src) return {code: \"chain-unsupported\", detail: `source chain ${String(sourceChain)} is not a pinned Across chain`};\n if (!dst) return {code: \"chain-unsupported\", detail: `destination chain ${String(destChain)} is not a pinned Across chain`};\n if (src === dst) return {code: \"chain-unsupported\", detail: \"source and destination are the same chain\"};\n if (typeof sourceToken !== \"string\" || typeof destToken !== \"string\") return {code: \"token-unsupported\", detail: \"the tokens are not addresses\"};\n let input: AcrossRouteSide;\n let asset: AcrossAsset;\n if (isNativeRef(sourceToken)) {\n if (!src.nativeIsEth || !src.wrappedNative) return {code: \"native-unsupported\", detail: `${src.name}'s native coin is not bridged by Across`};\n input = {chain: src, token: src.wrappedNative, native: true, decimals: 18};\n asset = \"ETH\";\n } else {\n const t = acrossToken(src, sourceToken);\n if (!t) return {code: \"token-unsupported\", detail: `${sourceToken.toLowerCase()} is not a token pinned on ${src.name}`};\n input = {chain: src, token: t.address, native: false, decimals: t.decimals};\n asset = t.asset;\n }\n let output: AcrossRouteSide;\n if (isNativeRef(destToken)) {\n if (!dst.nativeIsEth || !dst.wrappedNative) return {code: \"native-unsupported\", detail: `${dst.name}'s native coin is not bridged by Across`};\n if (asset !== \"ETH\") return {code: \"pair-unsupported\", detail: `${asset} on ${src.name} is not bridged to ${dst.name}'s native coin`};\n output = {chain: dst, token: dst.wrappedNative, native: true, decimals: 18};\n } else {\n const t = acrossToken(dst, destToken);\n if (!t) return {code: \"token-unsupported\", detail: `${destToken.toLowerCase()} is not a token pinned on ${dst.name}`};\n if (dst.wrappedNative !== null && t.address === dst.wrappedNative) {\n return {code: \"wrapped-native-destination\", detail: `a fill of ${t.symbol} on ${dst.name} pays an EOA the native coin, not ${t.symbol} — ask for the native coin`};\n }\n if (t.asset !== asset) return {code: \"pair-unsupported\", detail: `${asset} is only bridged to ${asset}, not to ${t.symbol}`};\n output = {chain: dst, token: t.address, native: false, decimals: t.decimals};\n }\n if (input.decimals !== output.decimals) return {code: \"pair-unsupported\", detail: \"the two sides have different decimals\"};\n return {asset, input, output};\n}\n\nexport const across = {\n supportsChain(chain: string): boolean {\n return acrossChain(chain) !== undefined;\n },\n /** Two different pinned EVM chains. */\n supports(from: string, to: string): boolean {\n return from !== to && acrossChain(from) !== undefined && acrossChain(to) !== undefined;\n },\n};\n","/**\n * SpokePool `deposit` — built and read here, strictly.\n *\n * `deposit(bytes32 depositor, bytes32 recipient, bytes32 inputToken, bytes32 outputToken, uint256 inputAmount,\n * uint256 outputAmount, uint256 destinationChainId, bytes32 exclusiveRelayer, uint32 quoteTimestamp,\n * uint32 fillDeadline, uint32 exclusivityParameter, bytes message)`, selector 0xad5425c6 (SpokePool.sol at\n * across-protocol/contracts d652689f). Every party and token is a `bytes32`; on an EVM chain it holds a 20-byte address\n * left-padded with zeros, and `depositor` is required to be one on chain (`checkAddress`).\n *\n * The reader accepts exactly the canonical ABI encoding of that call: the selector, eleven static words with clean\n * padding, the one offset the encoding allows (0x180), the message length and the message padded to a word, and\n * nothing after it. Across's own API appends a marker to the calldata it hands out (`73c0de`, and `1dc0de` + an\n * integrator id before it); such bytes are not part of the call and are refused here — this module signs the calldata\n * it builds, which carries none.\n */\nimport {encodeFunctionData, parseAbi, type Hex} from \"viem\";\nimport {ACROSS_DEPOSIT, ACROSS_REFUSED_SELECTORS} from \"./config.js\";\nimport {AcrossRefusal} from \"./refusal.js\";\n\nexport const SPOKE_POOL_ABI = parseAbi([\n \"function deposit(bytes32 depositor, bytes32 recipient, bytes32 inputToken, bytes32 outputToken, uint256 inputAmount, uint256 outputAmount, uint256 destinationChainId, bytes32 exclusiveRelayer, uint32 quoteTimestamp, uint32 fillDeadline, uint32 exclusivityParameter, bytes message) payable\",\n]);\n\n/** The arguments of a deposit. Addresses are 20 bytes, lowercase; the zero address as `exclusiveRelayer` is \"none\". */\nexport interface AcrossDepositArgs {\n depositor: string;\n recipient: string;\n inputToken: string;\n outputToken: string;\n inputAmount: bigint;\n outputAmount: bigint;\n destinationChainId: bigint;\n exclusiveRelayer: string;\n /** Unix seconds. */\n quoteTimestamp: number;\n /** Unix seconds, on the destination chain. */\n fillDeadline: number;\n /** 0 (no exclusivity), an offset up to one year, or a unix timestamp above that. */\n exclusivityParameter: number;\n /** Lowercase hex, `0x` when empty. */\n message: Hex;\n}\n\nconst ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst HEX = /^0x(?:[0-9a-fA-F]{2})*$/;\nconst U256_MAX = (1n << 256n) - 1n;\nconst U32_MAX = 0xffff_ffff;\n/** Static words before the message: eleven arguments and the message's offset. */\nconst HEAD_WORDS = 12;\n/** The only offset a canonical encoding gives the message: right after the head. */\nconst MESSAGE_OFFSET = HEAD_WORDS * 32;\n/** Longest message read (64 KiB): this module refuses every non-empty message anyway, this only bounds the work. */\nexport const ACROSS_MAX_MESSAGE_BYTES = 65_536;\n\n/** An address as the bytes32 a deposit carries. */\nexport function acrossBytes32(address: string): Hex {\n if (typeof address !== \"string\" || !ADDRESS.test(address)) throw new AcrossRefusal(\"request-invalid\", `${String(address)} is not an EVM address`);\n return `0x${\"0\".repeat(24)}${address.slice(2).toLowerCase()}`;\n}\n\n/** The address a bytes32 word holds, or null when its upper twelve bytes are not zero (not an EVM address). */\nexport function acrossAddressOf(word: string): string | null {\n const w = word.startsWith(\"0x\") ? word.slice(2) : word;\n if (!/^[0-9a-fA-F]{64}$/.test(w) || !/^0{24}/.test(w)) return null;\n return `0x${w.slice(24).toLowerCase()}`;\n}\n\nfunction checkArgs(a: AcrossDepositArgs): void {\n const bad = (what: string): never => { throw new AcrossRefusal(\"request-invalid\", `the deposit's ${what}`); };\n if (a === null || typeof a !== \"object\") bad(\"arguments are missing\");\n for (const [k, v] of [[\"depositor\", a.depositor], [\"recipient\", a.recipient], [\"inputToken\", a.inputToken], [\"outputToken\", a.outputToken], [\"exclusiveRelayer\", a.exclusiveRelayer]] as const) {\n if (typeof v !== \"string\" || !ADDRESS.test(v)) bad(`${k} is not an EVM address`);\n }\n for (const [k, v] of [[\"inputAmount\", a.inputAmount], [\"outputAmount\", a.outputAmount], [\"destinationChainId\", a.destinationChainId]] as const) {\n if (typeof v !== \"bigint\" || v < 0n || v > U256_MAX) bad(`${k} is not a uint256`);\n }\n for (const [k, v] of [[\"quoteTimestamp\", a.quoteTimestamp], [\"fillDeadline\", a.fillDeadline], [\"exclusivityParameter\", a.exclusivityParameter]] as const) {\n if (!Number.isInteger(v) || v < 0 || v > U32_MAX) bad(`${k} is not a uint32`);\n }\n if (typeof a.message !== \"string\" || !HEX.test(a.message) || (a.message.length - 2) / 2 > ACROSS_MAX_MESSAGE_BYTES) bad(\"message is not bytes\");\n}\n\n/** The calldata of `deposit(...)` for these arguments: lowercase hex, canonical ABI encoding, nothing appended. */\nexport function encodeAcrossDeposit(a: AcrossDepositArgs): Hex {\n checkArgs(a);\n return encodeFunctionData({\n abi: SPOKE_POOL_ABI,\n functionName: \"deposit\",\n args: [\n acrossBytes32(a.depositor), acrossBytes32(a.recipient), acrossBytes32(a.inputToken), acrossBytes32(a.outputToken),\n a.inputAmount, a.outputAmount, a.destinationChainId, acrossBytes32(a.exclusiveRelayer),\n a.quoteTimestamp, a.fillDeadline, a.exclusivityParameter, a.message.toLowerCase() as Hex,\n ],\n }).toLowerCase() as Hex;\n}\n\n/** A word's value when it fits 32 bits (its upper 28 bytes zero), else null. */\nfunction word32(word: string): number | null {\n return /^0{56}[0-9a-f]{8}$/.test(word) ? parseInt(word.slice(56), 16) : null;\n}\n\n/**\n * The arguments of a `deposit` calldata, read strictly; throws {@link AcrossRefusal} (`tx-selector`, `tx-calldata`,\n * classified `policy_refused`) for anything but the canonical encoding of that one call.\n */\nexport function decodeAcrossDeposit(data: unknown): AcrossDepositArgs {\n const malformed = (what: string): never => { throw new AcrossRefusal(\"tx-calldata\", `the deposit calldata ${what}`, \"policy_refused\"); };\n if (typeof data !== \"string\" || !HEX.test(data) || data.length < 10) malformed(\"is not hex calldata\");\n const hex = (data as string).toLowerCase();\n const selector = hex.slice(0, 10);\n if (selector !== ACROSS_DEPOSIT) {\n const name = Object.prototype.hasOwnProperty.call(ACROSS_REFUSED_SELECTORS, selector) ? ACROSS_REFUSED_SELECTORS[selector] : undefined;\n throw new AcrossRefusal(\"tx-selector\", name ? `the call is ${name} (${selector}), which this module never signs` : `the call is ${selector}, not deposit (${ACROSS_DEPOSIT})`, \"policy_refused\");\n }\n const body = hex.slice(10);\n if (body.length < (HEAD_WORDS + 1) * 64) malformed(`is ${(hex.length - 2) / 2} bytes, shorter than a deposit`);\n const word = (i: number): string => body.slice(64 * i, 64 * i + 64);\n const addr = (i: number, what: string): string => acrossAddressOf(word(i)) ?? malformed(`carries a ${what} that is not an EVM address`);\n const u32 = (i: number, what: string): number => word32(word(i)) ?? malformed(`carries a ${what} wider than 32 bits`);\n const offset = BigInt(`0x${word(11)}`);\n if (offset !== BigInt(MESSAGE_OFFSET)) malformed(`puts the message at offset ${offset}, not ${MESSAGE_OFFSET}`);\n const lengthWord = word(HEAD_WORDS);\n if (!/^0{56}/.test(lengthWord)) malformed(\"states an impossible message length\");\n const length = parseInt(lengthWord.slice(56), 16);\n if (length > ACROSS_MAX_MESSAGE_BYTES) malformed(`carries a ${length}-byte message, over ${ACROSS_MAX_MESSAGE_BYTES}`);\n const padded = Math.ceil(length / 32) * 64;\n const expected = (HEAD_WORDS + 1) * 64 + padded;\n if (body.length !== expected) {\n malformed(body.length > expected\n ? `has ${(body.length - expected) / 2} bytes after the encoded call`\n : `is ${(hex.length - 2) / 2} bytes, the encoding needs ${4 + expected / 2}`);\n }\n const tail = body.slice((HEAD_WORDS + 1) * 64);\n if (!/^0*$/.test(tail.slice(length * 2))) malformed(\"pads the message with non-zero bytes\");\n const args: AcrossDepositArgs = {\n depositor: addr(0, \"depositor\"),\n recipient: addr(1, \"recipient\"),\n inputToken: addr(2, \"input token\"),\n outputToken: addr(3, \"output token\"),\n inputAmount: BigInt(`0x${word(4)}`),\n outputAmount: BigInt(`0x${word(5)}`),\n destinationChainId: BigInt(`0x${word(6)}`),\n exclusiveRelayer: addr(7, \"exclusive relayer\"),\n quoteTimestamp: u32(8, \"quote timestamp\"),\n fillDeadline: u32(9, \"fill deadline\"),\n exclusivityParameter: u32(10, \"exclusivity parameter\"),\n message: `0x${tail.slice(0, length * 2)}`,\n };\n // Whatever the reads above let through, the bytes are the canonical encoding of what was read.\n if (encodeAcrossDeposit(args) !== hex) malformed(\"is not the canonical encoding of its arguments\");\n return args;\n}\n","import {withReason, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\n\n/** Why a request, a deposit, a quote or an API answer was refused. One code per check; the message says what was found. */\nexport type AcrossRefusalCode =\n | \"request-invalid\"\n | \"chain-unsupported\"\n | \"token-unsupported\"\n | \"pair-unsupported\"\n | \"native-unsupported\"\n | \"wrapped-native-destination\"\n | \"route-unpriced\"\n | \"quote-unavailable\"\n | \"quote-normalized\"\n | \"tx-shape\"\n | \"tx-chain\"\n | \"tx-target\"\n | \"tx-selector\"\n | \"tx-calldata\"\n | \"tx-depositor\"\n | \"tx-recipient\"\n | \"tx-input-token\"\n | \"tx-output-token\"\n | \"tx-input-amount\"\n | \"tx-output-amount\"\n | \"tx-fee\"\n | \"tx-destination\"\n | \"tx-message\"\n | \"tx-message-v5\"\n | \"tx-exclusivity\"\n | \"tx-quote-time\"\n | \"tx-fill-deadline\"\n | \"tx-value\"\n | \"tx-approval\"\n | \"speed-up\"\n | \"quote-shape\"\n | \"quote-amounts\"\n | \"quote-expiry\"\n | \"quote-gas\"\n | \"quote-intent\"\n | \"api-error\"\n | \"api-answer\"\n | \"relayer-price\";\n\n/**\n * `code` names the check; `reason` (a `Swap2RefusalReason` from `@anywalletkit/protocol-swap2-core`) is the stable\n * classification an app switches on. It is set where the refusal is raised, so one code can carry different reasons\n * (a fill deadline too far ahead is `policy_refused`, one already too close is `quote_expired`); a malformed request\n * from the caller (a programming error) carries none.\n */\nexport class AcrossRefusal extends Error {\n readonly code: AcrossRefusalCode;\n declare readonly reason?: Swap2RefusalReason;\n constructor(code: AcrossRefusalCode, detail: string, reason?: Swap2RefusalReason) {\n super(`across: ${detail} [${code}]`);\n this.name = \"AcrossRefusal\";\n this.code = code;\n if (reason !== undefined) withReason(this, reason);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,IAAAA,eAA4E;AAE5E,kBAAwC;;;ACuCxC,IAAM,OAAO,CAAC,SAAiB,SAAS,WAAwB,OAAO,OAAO,EAAC,OAAO,QAAQ,SAAS,QAAQ,UAAU,EAAC,CAAC;AAC3H,IAAM,OAAO,CAAC,SAAiB,SAAS,WAAwB,OAAO,OAAO,EAAC,OAAO,QAAQ,SAAS,QAAQ,UAAU,EAAC,CAAC;AAC3H,IAAM,OAAO,CAAC,YAAiC,OAAO,OAAO,EAAC,OAAO,OAAO,SAAS,QAAQ,QAAQ,UAAU,GAAE,CAAC;AAClH,IAAM,OAAO,CAAC,YAAiC,OAAO,OAAO,EAAC,OAAO,QAAQ,SAAS,QAAQ,QAAQ,UAAU,EAAC,CAAC;AAGlH,IAAM,UAAU;AAEhB,SAAS,MACP,SAAiB,KAAa,MAAc,WAAm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,iBAAiB,KAAI,GAAG,SAAS,UAAS;AAChG,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI;AACF,UAAM,QAAS,MAAM,QAAQ,wBAAwB,CAAC,UAAU,KAAK,CAAC;AACtE,UAAM,SAAS,OAAO;AACtB,UAAM,YAAY,OAAO;AACzB,QAAI,OAAO,WAAW,YAAY,CAAC,wBAAwB,KAAK,MAAM,KAAK,OAAO,cAAc,YAAY,CAAC,wBAAwB,KAAK,SAAS,EAAG,QAAO;AAC7J,UAAM,YAAY,SAAS,WAAW,EAAE;AACxC,UAAM,aAAa,sBAAsB,MAAM,QAAQ,YAAY,CAAC,EAAC,IAAI,KAAK,WAAW,MAAM,qBAAqB,SAAS,EAAC,GAAG,MAAM,CAAC,CAAC;AACzI,QAAI,eAAe,KAAM,QAAO;AAChC,UAAM,OAAO,gBAAgB,YAAY,QAAQ,cAAc,SAAS;AACxE,UAAM,YAAY,EAAC,QAAQ,OAAO,YAAY,GAAG,WAAW,UAAS;AACrE,QAAI,SAAS,SAAU,QAAO,EAAC,QAAQ,EAAC,OAAO,aAAa,iBAAiB,KAAI,GAAG,SAAS,WAAW,MAAM,UAAS;AAGvH,QAAI,SAAS,UAAW,QAAO,EAAC,QAAQ,EAAC,OAAO,WAAW,iBAAiB,KAAI,GAAG,SAAS,WAAW,MAAM,UAAS;AACtH,WAAO,EAAC,QAAQ,EAAC,OAAO,WAAW,iBAAiB,KAAI,GAAG,SAAS,WAAW,MAAM,UAAS;AAAA,EAChG,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":["import_viem","HEX"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { IntentStatus } from '@anywalletkit/protocol-swap2-core/types';
|
|
3
|
+
import { AcrossChain } from './config.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where an Across deposit stands, read from the chains themselves — no Across API.
|
|
7
|
+
*
|
|
8
|
+
* 1. The source receipt: the deposit's `FundsDeposited` event, emitted by the pinned SpokePool of the source chain,
|
|
9
|
+
* carries every field of the relay (V3SpokePoolInterface.sol `FundsDeposited`; `exclusivityDeadline` there is the
|
|
10
|
+
* resolved timestamp, which is what the relay is keyed by). The event taken is the intent's own: the `deposit`
|
|
11
|
+
* calldata its fields make hashes to the intent id's digest ({@link acrossDepositIsIntent}) — another deposit in
|
|
12
|
+
* the same transaction, or another transaction's, is never reported as this one.
|
|
13
|
+
* 2. The relay hash, exactly as the destination SpokePool computes it: `keccak256(abi.encode(relayData, chainId()))`
|
|
14
|
+
* with `relayData` the `V3RelayData` struct (depositor, recipient, exclusiveRelayer, inputToken, outputToken,
|
|
15
|
+
* inputAmount, outputAmount, originChainId, depositId, fillDeadline, exclusivityDeadline, message) and `chainId()`
|
|
16
|
+
* the destination's own `block.chainid` (SpokePool.sol `getV3RelayHash`; no pinned chain overrides it).
|
|
17
|
+
* 3. The destination SpokePool's `fillStatuses(relayHash)`, read at the latest block together with that block's time:
|
|
18
|
+
* 2 is filled; 0 (unfilled) or 1 (slow fill requested) is still open while the block time is at or before the fill
|
|
19
|
+
* deadline, and final after it — every fill path reverts with `ExpiredFillDeadline` once `fillDeadline <
|
|
20
|
+
* block.timestamp`. Such a deposit is reported `expired`, a terminal state: Across refunds it to its depositor on
|
|
21
|
+
* the source chain through its next settlement bundles (hours, not minutes; Across's docs: "do not tell users to
|
|
22
|
+
* expect immediate refunds"), and this module does not watch for the refund itself.
|
|
23
|
+
*
|
|
24
|
+
* Display only: nothing is signed on what this reads. A node that does not answer, or a receipt that does not hold
|
|
25
|
+
* exactly the intent's deposit, leaves the status where it was ("pending"); a terminal state is reported only from a
|
|
26
|
+
* reverted receipt or a fill status that says so.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** A deposit as its `FundsDeposited` event states it. Parties and tokens are the raw bytes32 words, lowercase. */
|
|
30
|
+
interface AcrossDepositEvent {
|
|
31
|
+
originChainId: number;
|
|
32
|
+
destinationChainId: bigint;
|
|
33
|
+
depositId: bigint;
|
|
34
|
+
depositor: Hex;
|
|
35
|
+
recipient: Hex;
|
|
36
|
+
exclusiveRelayer: Hex;
|
|
37
|
+
inputToken: Hex;
|
|
38
|
+
outputToken: Hex;
|
|
39
|
+
inputAmount: bigint;
|
|
40
|
+
outputAmount: bigint;
|
|
41
|
+
quoteTimestamp: number;
|
|
42
|
+
fillDeadline: number;
|
|
43
|
+
/** The resolved exclusivity deadline (0 for none), not the deposit's raw parameter. */
|
|
44
|
+
exclusivityDeadline: number;
|
|
45
|
+
message: Hex;
|
|
46
|
+
}
|
|
47
|
+
/** `fillStatuses` values (V3SpokePoolInterface.sol `FillStatus`). */
|
|
48
|
+
declare const ACROSS_FILL_STATUS: Readonly<{
|
|
49
|
+
readonly UNFILLED: 0;
|
|
50
|
+
readonly REQUESTED_SLOW_FILL: 1;
|
|
51
|
+
readonly FILLED: 2;
|
|
52
|
+
}>;
|
|
53
|
+
/** A relay's state on the destination. `expired`: unfilled past its fill deadline — refunded on the source chain by Across. */
|
|
54
|
+
type AcrossFillState = "unfilled" | "slow-fill-requested" | "filled" | "expired";
|
|
55
|
+
/**
|
|
56
|
+
* Every `FundsDeposited` the pinned SpokePool of `source` emitted in a transaction receipt (an `eth_getTransactionReceipt`
|
|
57
|
+
* answer), in log order. Logs of any other contract, and logs that do not decode as the event, are skipped.
|
|
58
|
+
*/
|
|
59
|
+
declare function acrossDepositsInReceipt(receipt: unknown, source: AcrossChain): AcrossDepositEvent[];
|
|
60
|
+
/**
|
|
61
|
+
* Whether a deposit event is the one an intent id names: the canonical `deposit` calldata of its fields hashes to the
|
|
62
|
+
* id's digest (`acrossIntentId`), so every field — parties, tokens, amounts, destination, deadlines, message — is the
|
|
63
|
+
* signed one. The event carries the resolved exclusivity deadline, not the parameter: 0 for none, the parameter itself
|
|
64
|
+
* for a timestamp, and for an offset the time of the block the deposit landed in plus the offset (SpokePool.sol
|
|
65
|
+
* `_depositV3`) — so an offset is recognized only with `sourceBlockTime`.
|
|
66
|
+
*/
|
|
67
|
+
declare function acrossDepositIsIntent(e: AcrossDepositEvent, digest: string, sourceBlockTime?: number): boolean;
|
|
68
|
+
/** The relay hash of a deposit — the key of `fillStatuses` on its destination chain. */
|
|
69
|
+
declare function acrossRelayHash(e: AcrossDepositEvent): Hex;
|
|
70
|
+
/** Calldata of `fillStatuses(relayHash)`. */
|
|
71
|
+
declare function acrossFillStatusCall(relayHash: Hex): Hex;
|
|
72
|
+
/** A `fillStatuses` answer: 0, 1 or 2; null for anything else (another word, another length). */
|
|
73
|
+
declare function parseAcrossFillStatus(answer: unknown): 0 | 1 | 2 | null;
|
|
74
|
+
/** A fill status read at a destination block whose time is `blockTime`. */
|
|
75
|
+
declare function acrossFillState(status: 0 | 1 | 2, fillDeadline: number, blockTime: number): AcrossFillState;
|
|
76
|
+
/** A JSON-RPC caller: the `result` of `method`, or a throw. */
|
|
77
|
+
type AcrossRpc = (method: string, params: readonly unknown[]) => Promise<unknown>;
|
|
78
|
+
/** A minimal JSON-RPC client over `fetch` (12 s per call); its errors never carry the URL (a keyed RPC has its key there). */
|
|
79
|
+
declare function acrossRpc(url: string, fetchImpl?: typeof fetch, timeoutMs?: number): AcrossRpc;
|
|
80
|
+
/** What {@link trackAcrossDeposit} found: the status, and the facts it rests on when they were read. */
|
|
81
|
+
interface AcrossTrack {
|
|
82
|
+
status: IntentStatus;
|
|
83
|
+
deposit?: AcrossDepositEvent;
|
|
84
|
+
relayHash?: Hex;
|
|
85
|
+
fill?: AcrossFillState;
|
|
86
|
+
/** The destination block the fill status was read at. */
|
|
87
|
+
destBlock?: {
|
|
88
|
+
number: string;
|
|
89
|
+
timestamp: number;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
interface AcrossTrackInput {
|
|
93
|
+
sourceTxHash: string;
|
|
94
|
+
/** The intent id's digest of the deposit calldata (`parseAcrossIntentId(id).digest`): the deposit looked for. */
|
|
95
|
+
intentDigest: string;
|
|
96
|
+
source: AcrossChain;
|
|
97
|
+
dest: AcrossChain;
|
|
98
|
+
/** The source chain's RPC; without it nothing can be read ("pending"). */
|
|
99
|
+
sourceRpc?: AcrossRpc;
|
|
100
|
+
/** The destination chain's RPC; without it the deposit is seen but its fill is not ("pending"). */
|
|
101
|
+
destRpc?: AcrossRpc;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The intent's deposit in the transaction `sourceTxHash` from `source` to `dest`, and whether it was filled — read on
|
|
105
|
+
* chain only.
|
|
106
|
+
*/
|
|
107
|
+
declare function trackAcrossDeposit(input: AcrossTrackInput): Promise<AcrossTrack>;
|
|
108
|
+
|
|
109
|
+
export { ACROSS_FILL_STATUS, type AcrossDepositEvent, type AcrossFillState, type AcrossRpc, type AcrossTrack, type AcrossTrackInput, acrossDepositIsIntent, acrossDepositsInReceipt, acrossFillState, acrossFillStatusCall, acrossRelayHash, acrossRpc, parseAcrossFillStatus, trackAcrossDeposit };
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { IntentStatus } from '@anywalletkit/protocol-swap2-core/types';
|
|
3
|
+
import { AcrossChain } from './config.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where an Across deposit stands, read from the chains themselves — no Across API.
|
|
7
|
+
*
|
|
8
|
+
* 1. The source receipt: the deposit's `FundsDeposited` event, emitted by the pinned SpokePool of the source chain,
|
|
9
|
+
* carries every field of the relay (V3SpokePoolInterface.sol `FundsDeposited`; `exclusivityDeadline` there is the
|
|
10
|
+
* resolved timestamp, which is what the relay is keyed by). The event taken is the intent's own: the `deposit`
|
|
11
|
+
* calldata its fields make hashes to the intent id's digest ({@link acrossDepositIsIntent}) — another deposit in
|
|
12
|
+
* the same transaction, or another transaction's, is never reported as this one.
|
|
13
|
+
* 2. The relay hash, exactly as the destination SpokePool computes it: `keccak256(abi.encode(relayData, chainId()))`
|
|
14
|
+
* with `relayData` the `V3RelayData` struct (depositor, recipient, exclusiveRelayer, inputToken, outputToken,
|
|
15
|
+
* inputAmount, outputAmount, originChainId, depositId, fillDeadline, exclusivityDeadline, message) and `chainId()`
|
|
16
|
+
* the destination's own `block.chainid` (SpokePool.sol `getV3RelayHash`; no pinned chain overrides it).
|
|
17
|
+
* 3. The destination SpokePool's `fillStatuses(relayHash)`, read at the latest block together with that block's time:
|
|
18
|
+
* 2 is filled; 0 (unfilled) or 1 (slow fill requested) is still open while the block time is at or before the fill
|
|
19
|
+
* deadline, and final after it — every fill path reverts with `ExpiredFillDeadline` once `fillDeadline <
|
|
20
|
+
* block.timestamp`. Such a deposit is reported `expired`, a terminal state: Across refunds it to its depositor on
|
|
21
|
+
* the source chain through its next settlement bundles (hours, not minutes; Across's docs: "do not tell users to
|
|
22
|
+
* expect immediate refunds"), and this module does not watch for the refund itself.
|
|
23
|
+
*
|
|
24
|
+
* Display only: nothing is signed on what this reads. A node that does not answer, or a receipt that does not hold
|
|
25
|
+
* exactly the intent's deposit, leaves the status where it was ("pending"); a terminal state is reported only from a
|
|
26
|
+
* reverted receipt or a fill status that says so.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** A deposit as its `FundsDeposited` event states it. Parties and tokens are the raw bytes32 words, lowercase. */
|
|
30
|
+
interface AcrossDepositEvent {
|
|
31
|
+
originChainId: number;
|
|
32
|
+
destinationChainId: bigint;
|
|
33
|
+
depositId: bigint;
|
|
34
|
+
depositor: Hex;
|
|
35
|
+
recipient: Hex;
|
|
36
|
+
exclusiveRelayer: Hex;
|
|
37
|
+
inputToken: Hex;
|
|
38
|
+
outputToken: Hex;
|
|
39
|
+
inputAmount: bigint;
|
|
40
|
+
outputAmount: bigint;
|
|
41
|
+
quoteTimestamp: number;
|
|
42
|
+
fillDeadline: number;
|
|
43
|
+
/** The resolved exclusivity deadline (0 for none), not the deposit's raw parameter. */
|
|
44
|
+
exclusivityDeadline: number;
|
|
45
|
+
message: Hex;
|
|
46
|
+
}
|
|
47
|
+
/** `fillStatuses` values (V3SpokePoolInterface.sol `FillStatus`). */
|
|
48
|
+
declare const ACROSS_FILL_STATUS: Readonly<{
|
|
49
|
+
readonly UNFILLED: 0;
|
|
50
|
+
readonly REQUESTED_SLOW_FILL: 1;
|
|
51
|
+
readonly FILLED: 2;
|
|
52
|
+
}>;
|
|
53
|
+
/** A relay's state on the destination. `expired`: unfilled past its fill deadline — refunded on the source chain by Across. */
|
|
54
|
+
type AcrossFillState = "unfilled" | "slow-fill-requested" | "filled" | "expired";
|
|
55
|
+
/**
|
|
56
|
+
* Every `FundsDeposited` the pinned SpokePool of `source` emitted in a transaction receipt (an `eth_getTransactionReceipt`
|
|
57
|
+
* answer), in log order. Logs of any other contract, and logs that do not decode as the event, are skipped.
|
|
58
|
+
*/
|
|
59
|
+
declare function acrossDepositsInReceipt(receipt: unknown, source: AcrossChain): AcrossDepositEvent[];
|
|
60
|
+
/**
|
|
61
|
+
* Whether a deposit event is the one an intent id names: the canonical `deposit` calldata of its fields hashes to the
|
|
62
|
+
* id's digest (`acrossIntentId`), so every field — parties, tokens, amounts, destination, deadlines, message — is the
|
|
63
|
+
* signed one. The event carries the resolved exclusivity deadline, not the parameter: 0 for none, the parameter itself
|
|
64
|
+
* for a timestamp, and for an offset the time of the block the deposit landed in plus the offset (SpokePool.sol
|
|
65
|
+
* `_depositV3`) — so an offset is recognized only with `sourceBlockTime`.
|
|
66
|
+
*/
|
|
67
|
+
declare function acrossDepositIsIntent(e: AcrossDepositEvent, digest: string, sourceBlockTime?: number): boolean;
|
|
68
|
+
/** The relay hash of a deposit — the key of `fillStatuses` on its destination chain. */
|
|
69
|
+
declare function acrossRelayHash(e: AcrossDepositEvent): Hex;
|
|
70
|
+
/** Calldata of `fillStatuses(relayHash)`. */
|
|
71
|
+
declare function acrossFillStatusCall(relayHash: Hex): Hex;
|
|
72
|
+
/** A `fillStatuses` answer: 0, 1 or 2; null for anything else (another word, another length). */
|
|
73
|
+
declare function parseAcrossFillStatus(answer: unknown): 0 | 1 | 2 | null;
|
|
74
|
+
/** A fill status read at a destination block whose time is `blockTime`. */
|
|
75
|
+
declare function acrossFillState(status: 0 | 1 | 2, fillDeadline: number, blockTime: number): AcrossFillState;
|
|
76
|
+
/** A JSON-RPC caller: the `result` of `method`, or a throw. */
|
|
77
|
+
type AcrossRpc = (method: string, params: readonly unknown[]) => Promise<unknown>;
|
|
78
|
+
/** A minimal JSON-RPC client over `fetch` (12 s per call); its errors never carry the URL (a keyed RPC has its key there). */
|
|
79
|
+
declare function acrossRpc(url: string, fetchImpl?: typeof fetch, timeoutMs?: number): AcrossRpc;
|
|
80
|
+
/** What {@link trackAcrossDeposit} found: the status, and the facts it rests on when they were read. */
|
|
81
|
+
interface AcrossTrack {
|
|
82
|
+
status: IntentStatus;
|
|
83
|
+
deposit?: AcrossDepositEvent;
|
|
84
|
+
relayHash?: Hex;
|
|
85
|
+
fill?: AcrossFillState;
|
|
86
|
+
/** The destination block the fill status was read at. */
|
|
87
|
+
destBlock?: {
|
|
88
|
+
number: string;
|
|
89
|
+
timestamp: number;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
interface AcrossTrackInput {
|
|
93
|
+
sourceTxHash: string;
|
|
94
|
+
/** The intent id's digest of the deposit calldata (`parseAcrossIntentId(id).digest`): the deposit looked for. */
|
|
95
|
+
intentDigest: string;
|
|
96
|
+
source: AcrossChain;
|
|
97
|
+
dest: AcrossChain;
|
|
98
|
+
/** The source chain's RPC; without it nothing can be read ("pending"). */
|
|
99
|
+
sourceRpc?: AcrossRpc;
|
|
100
|
+
/** The destination chain's RPC; without it the deposit is seen but its fill is not ("pending"). */
|
|
101
|
+
destRpc?: AcrossRpc;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The intent's deposit in the transaction `sourceTxHash` from `source` to `dest`, and whether it was filled — read on
|
|
105
|
+
* chain only.
|
|
106
|
+
*/
|
|
107
|
+
declare function trackAcrossDeposit(input: AcrossTrackInput): Promise<AcrossTrack>;
|
|
108
|
+
|
|
109
|
+
export { ACROSS_FILL_STATUS, type AcrossDepositEvent, type AcrossFillState, type AcrossRpc, type AcrossTrack, type AcrossTrackInput, acrossDepositIsIntent, acrossDepositsInReceipt, acrossFillState, acrossFillStatusCall, acrossRelayHash, acrossRpc, parseAcrossFillStatus, trackAcrossDeposit };
|
package/dist/status.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACROSS_FILL_STATUS,
|
|
3
|
+
acrossDepositIsIntent,
|
|
4
|
+
acrossDepositsInReceipt,
|
|
5
|
+
acrossFillState,
|
|
6
|
+
acrossFillStatusCall,
|
|
7
|
+
acrossRelayHash,
|
|
8
|
+
acrossRpc,
|
|
9
|
+
parseAcrossFillStatus,
|
|
10
|
+
trackAcrossDeposit
|
|
11
|
+
} from "./chunk-3UBRQ3ZE.js";
|
|
12
|
+
import "./chunk-32YJEBZX.js";
|
|
13
|
+
import "./chunk-GX67FRPG.js";
|
|
14
|
+
import "./chunk-E5WFOPN2.js";
|
|
15
|
+
export {
|
|
16
|
+
ACROSS_FILL_STATUS,
|
|
17
|
+
acrossDepositIsIntent,
|
|
18
|
+
acrossDepositsInReceipt,
|
|
19
|
+
acrossFillState,
|
|
20
|
+
acrossFillStatusCall,
|
|
21
|
+
acrossRelayHash,
|
|
22
|
+
acrossRpc,
|
|
23
|
+
parseAcrossFillStatus,
|
|
24
|
+
trackAcrossDeposit
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|