@anywalletkit/protocol-swap2-across 0.0.0-stage → 0.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/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,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACROSS_DEPOSIT,
|
|
3
|
+
ACROSS_REFUSED_SELECTORS
|
|
4
|
+
} from "./chunk-GX67FRPG.js";
|
|
5
|
+
import {
|
|
6
|
+
AcrossRefusal
|
|
7
|
+
} from "./chunk-E5WFOPN2.js";
|
|
8
|
+
|
|
9
|
+
// src/deposit.ts
|
|
10
|
+
import { encodeFunctionData, parseAbi } from "viem";
|
|
11
|
+
var SPOKE_POOL_ABI = parseAbi([
|
|
12
|
+
"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"
|
|
13
|
+
]);
|
|
14
|
+
var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
15
|
+
var HEX = /^0x(?:[0-9a-fA-F]{2})*$/;
|
|
16
|
+
var U256_MAX = (1n << 256n) - 1n;
|
|
17
|
+
var U32_MAX = 4294967295;
|
|
18
|
+
var HEAD_WORDS = 12;
|
|
19
|
+
var MESSAGE_OFFSET = HEAD_WORDS * 32;
|
|
20
|
+
var ACROSS_MAX_MESSAGE_BYTES = 65536;
|
|
21
|
+
function acrossBytes32(address) {
|
|
22
|
+
if (typeof address !== "string" || !ADDRESS.test(address)) throw new AcrossRefusal("request-invalid", `${String(address)} is not an EVM address`);
|
|
23
|
+
return `0x${"0".repeat(24)}${address.slice(2).toLowerCase()}`;
|
|
24
|
+
}
|
|
25
|
+
function acrossAddressOf(word) {
|
|
26
|
+
const w = word.startsWith("0x") ? word.slice(2) : word;
|
|
27
|
+
if (!/^[0-9a-fA-F]{64}$/.test(w) || !/^0{24}/.test(w)) return null;
|
|
28
|
+
return `0x${w.slice(24).toLowerCase()}`;
|
|
29
|
+
}
|
|
30
|
+
function checkArgs(a) {
|
|
31
|
+
const bad = (what) => {
|
|
32
|
+
throw new AcrossRefusal("request-invalid", `the deposit's ${what}`);
|
|
33
|
+
};
|
|
34
|
+
if (a === null || typeof a !== "object") bad("arguments are missing");
|
|
35
|
+
for (const [k, v] of [["depositor", a.depositor], ["recipient", a.recipient], ["inputToken", a.inputToken], ["outputToken", a.outputToken], ["exclusiveRelayer", a.exclusiveRelayer]]) {
|
|
36
|
+
if (typeof v !== "string" || !ADDRESS.test(v)) bad(`${k} is not an EVM address`);
|
|
37
|
+
}
|
|
38
|
+
for (const [k, v] of [["inputAmount", a.inputAmount], ["outputAmount", a.outputAmount], ["destinationChainId", a.destinationChainId]]) {
|
|
39
|
+
if (typeof v !== "bigint" || v < 0n || v > U256_MAX) bad(`${k} is not a uint256`);
|
|
40
|
+
}
|
|
41
|
+
for (const [k, v] of [["quoteTimestamp", a.quoteTimestamp], ["fillDeadline", a.fillDeadline], ["exclusivityParameter", a.exclusivityParameter]]) {
|
|
42
|
+
if (!Number.isInteger(v) || v < 0 || v > U32_MAX) bad(`${k} is not a uint32`);
|
|
43
|
+
}
|
|
44
|
+
if (typeof a.message !== "string" || !HEX.test(a.message) || (a.message.length - 2) / 2 > ACROSS_MAX_MESSAGE_BYTES) bad("message is not bytes");
|
|
45
|
+
}
|
|
46
|
+
function encodeAcrossDeposit(a) {
|
|
47
|
+
checkArgs(a);
|
|
48
|
+
return encodeFunctionData({
|
|
49
|
+
abi: SPOKE_POOL_ABI,
|
|
50
|
+
functionName: "deposit",
|
|
51
|
+
args: [
|
|
52
|
+
acrossBytes32(a.depositor),
|
|
53
|
+
acrossBytes32(a.recipient),
|
|
54
|
+
acrossBytes32(a.inputToken),
|
|
55
|
+
acrossBytes32(a.outputToken),
|
|
56
|
+
a.inputAmount,
|
|
57
|
+
a.outputAmount,
|
|
58
|
+
a.destinationChainId,
|
|
59
|
+
acrossBytes32(a.exclusiveRelayer),
|
|
60
|
+
a.quoteTimestamp,
|
|
61
|
+
a.fillDeadline,
|
|
62
|
+
a.exclusivityParameter,
|
|
63
|
+
a.message.toLowerCase()
|
|
64
|
+
]
|
|
65
|
+
}).toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
function word32(word) {
|
|
68
|
+
return /^0{56}[0-9a-f]{8}$/.test(word) ? parseInt(word.slice(56), 16) : null;
|
|
69
|
+
}
|
|
70
|
+
function decodeAcrossDeposit(data) {
|
|
71
|
+
const malformed = (what) => {
|
|
72
|
+
throw new AcrossRefusal("tx-calldata", `the deposit calldata ${what}`, "policy_refused");
|
|
73
|
+
};
|
|
74
|
+
if (typeof data !== "string" || !HEX.test(data) || data.length < 10) malformed("is not hex calldata");
|
|
75
|
+
const hex = data.toLowerCase();
|
|
76
|
+
const selector = hex.slice(0, 10);
|
|
77
|
+
if (selector !== ACROSS_DEPOSIT) {
|
|
78
|
+
const name = Object.prototype.hasOwnProperty.call(ACROSS_REFUSED_SELECTORS, selector) ? ACROSS_REFUSED_SELECTORS[selector] : void 0;
|
|
79
|
+
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");
|
|
80
|
+
}
|
|
81
|
+
const body = hex.slice(10);
|
|
82
|
+
if (body.length < (HEAD_WORDS + 1) * 64) malformed(`is ${(hex.length - 2) / 2} bytes, shorter than a deposit`);
|
|
83
|
+
const word = (i) => body.slice(64 * i, 64 * i + 64);
|
|
84
|
+
const addr = (i, what) => acrossAddressOf(word(i)) ?? malformed(`carries a ${what} that is not an EVM address`);
|
|
85
|
+
const u32 = (i, what) => word32(word(i)) ?? malformed(`carries a ${what} wider than 32 bits`);
|
|
86
|
+
const offset = BigInt(`0x${word(11)}`);
|
|
87
|
+
if (offset !== BigInt(MESSAGE_OFFSET)) malformed(`puts the message at offset ${offset}, not ${MESSAGE_OFFSET}`);
|
|
88
|
+
const lengthWord = word(HEAD_WORDS);
|
|
89
|
+
if (!/^0{56}/.test(lengthWord)) malformed("states an impossible message length");
|
|
90
|
+
const length = parseInt(lengthWord.slice(56), 16);
|
|
91
|
+
if (length > ACROSS_MAX_MESSAGE_BYTES) malformed(`carries a ${length}-byte message, over ${ACROSS_MAX_MESSAGE_BYTES}`);
|
|
92
|
+
const padded = Math.ceil(length / 32) * 64;
|
|
93
|
+
const expected = (HEAD_WORDS + 1) * 64 + padded;
|
|
94
|
+
if (body.length !== expected) {
|
|
95
|
+
malformed(body.length > expected ? `has ${(body.length - expected) / 2} bytes after the encoded call` : `is ${(hex.length - 2) / 2} bytes, the encoding needs ${4 + expected / 2}`);
|
|
96
|
+
}
|
|
97
|
+
const tail = body.slice((HEAD_WORDS + 1) * 64);
|
|
98
|
+
if (!/^0*$/.test(tail.slice(length * 2))) malformed("pads the message with non-zero bytes");
|
|
99
|
+
const args = {
|
|
100
|
+
depositor: addr(0, "depositor"),
|
|
101
|
+
recipient: addr(1, "recipient"),
|
|
102
|
+
inputToken: addr(2, "input token"),
|
|
103
|
+
outputToken: addr(3, "output token"),
|
|
104
|
+
inputAmount: BigInt(`0x${word(4)}`),
|
|
105
|
+
outputAmount: BigInt(`0x${word(5)}`),
|
|
106
|
+
destinationChainId: BigInt(`0x${word(6)}`),
|
|
107
|
+
exclusiveRelayer: addr(7, "exclusive relayer"),
|
|
108
|
+
quoteTimestamp: u32(8, "quote timestamp"),
|
|
109
|
+
fillDeadline: u32(9, "fill deadline"),
|
|
110
|
+
exclusivityParameter: u32(10, "exclusivity parameter"),
|
|
111
|
+
message: `0x${tail.slice(0, length * 2)}`
|
|
112
|
+
};
|
|
113
|
+
if (encodeAcrossDeposit(args) !== hex) malformed("is not the canonical encoding of its arguments");
|
|
114
|
+
return args;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
SPOKE_POOL_ABI,
|
|
119
|
+
ACROSS_MAX_MESSAGE_BYTES,
|
|
120
|
+
acrossBytes32,
|
|
121
|
+
acrossAddressOf,
|
|
122
|
+
encodeAcrossDeposit,
|
|
123
|
+
decodeAcrossDeposit
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=chunk-32YJEBZX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deposit.ts"],"sourcesContent":["/**\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"],"mappings":";;;;;;;;;AAeA,SAAQ,oBAAoB,gBAAyB;AAI9C,IAAM,iBAAiB,SAAS;AAAA,EACrC;AACF,CAAC;AAsBD,IAAM,UAAU;AAChB,IAAM,MAAM;AACZ,IAAM,YAAY,MAAM,QAAQ;AAChC,IAAM,UAAU;AAEhB,IAAM,aAAa;AAEnB,IAAM,iBAAiB,aAAa;AAE7B,IAAM,2BAA2B;AAGjC,SAAS,cAAc,SAAsB;AAClD,MAAI,OAAO,YAAY,YAAY,CAAC,QAAQ,KAAK,OAAO,EAAG,OAAM,IAAI,cAAc,mBAAmB,GAAG,OAAO,OAAO,CAAC,wBAAwB;AAChJ,SAAO,KAAK,IAAI,OAAO,EAAE,CAAC,GAAG,QAAQ,MAAM,CAAC,EAAE,YAAY,CAAC;AAC7D;AAGO,SAAS,gBAAgB,MAA6B;AAC3D,QAAM,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,MAAM,CAAC,IAAI;AAClD,MAAI,CAAC,oBAAoB,KAAK,CAAC,KAAK,CAAC,SAAS,KAAK,CAAC,EAAG,QAAO;AAC9D,SAAO,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,CAAC;AACvC;AAEA,SAAS,UAAU,GAA4B;AAC7C,QAAM,MAAM,CAAC,SAAwB;AAAE,UAAM,IAAI,cAAc,mBAAmB,iBAAiB,IAAI,EAAE;AAAA,EAAG;AAC5G,MAAI,MAAM,QAAQ,OAAO,MAAM,SAAU,KAAI,uBAAuB;AACpE,aAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC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MAAM,IAAK,WAAU,gDAAgD;AACjG,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import {
|
|
2
|
+
acrossAddressOf,
|
|
3
|
+
encodeAcrossDeposit
|
|
4
|
+
} from "./chunk-32YJEBZX.js";
|
|
5
|
+
import {
|
|
6
|
+
ACROSS_FILL_STATUSES,
|
|
7
|
+
ACROSS_FUNDS_DEPOSITED,
|
|
8
|
+
ACROSS_MAX_EXCLUSIVITY_PERIOD_S
|
|
9
|
+
} from "./chunk-GX67FRPG.js";
|
|
10
|
+
|
|
11
|
+
// src/status.ts
|
|
12
|
+
import { decodeAbiParameters, encodeAbiParameters, keccak256 } from "viem";
|
|
13
|
+
import { redactUrls, timeoutSignal } from "@anywalletkit/protocol-swap2-core/util";
|
|
14
|
+
var ACROSS_FILL_STATUS = Object.freeze({ UNFILLED: 0, REQUESTED_SLOW_FILL: 1, FILLED: 2 });
|
|
15
|
+
var EVENT_DATA = [
|
|
16
|
+
{ name: "inputToken", type: "bytes32" },
|
|
17
|
+
{ name: "outputToken", type: "bytes32" },
|
|
18
|
+
{ name: "inputAmount", type: "uint256" },
|
|
19
|
+
{ name: "outputAmount", type: "uint256" },
|
|
20
|
+
{ name: "quoteTimestamp", type: "uint32" },
|
|
21
|
+
{ name: "fillDeadline", type: "uint32" },
|
|
22
|
+
{ name: "exclusivityDeadline", type: "uint32" },
|
|
23
|
+
{ name: "recipient", type: "bytes32" },
|
|
24
|
+
{ name: "exclusiveRelayer", type: "bytes32" },
|
|
25
|
+
{ name: "message", type: "bytes" }
|
|
26
|
+
];
|
|
27
|
+
var RELAY_DATA = {
|
|
28
|
+
type: "tuple",
|
|
29
|
+
components: [
|
|
30
|
+
{ name: "depositor", type: "bytes32" },
|
|
31
|
+
{ name: "recipient", type: "bytes32" },
|
|
32
|
+
{ name: "exclusiveRelayer", type: "bytes32" },
|
|
33
|
+
{ name: "inputToken", type: "bytes32" },
|
|
34
|
+
{ name: "outputToken", type: "bytes32" },
|
|
35
|
+
{ name: "inputAmount", type: "uint256" },
|
|
36
|
+
{ name: "outputAmount", type: "uint256" },
|
|
37
|
+
{ name: "originChainId", type: "uint256" },
|
|
38
|
+
{ name: "depositId", type: "uint256" },
|
|
39
|
+
{ name: "fillDeadline", type: "uint32" },
|
|
40
|
+
{ name: "exclusivityDeadline", type: "uint32" },
|
|
41
|
+
{ name: "message", type: "bytes" }
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
var WORD = /^0x[0-9a-fA-F]{64}$/;
|
|
45
|
+
var HEX = /^0x(?:[0-9a-fA-F]{2})*$/;
|
|
46
|
+
var DIGEST = /^[0-9a-f]{32}$/;
|
|
47
|
+
var QUANTITY = /^0x[0-9a-fA-F]{1,16}$/;
|
|
48
|
+
var lowerHex = (s) => s.toLowerCase();
|
|
49
|
+
function acrossDepositsInReceipt(receipt, source) {
|
|
50
|
+
const logs = receipt?.logs;
|
|
51
|
+
if (!Array.isArray(logs)) return [];
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const log of logs) {
|
|
54
|
+
if (log === null || typeof log !== "object" || log.removed === true) continue;
|
|
55
|
+
if (typeof log.address !== "string" || log.address.toLowerCase() !== source.spokePool) continue;
|
|
56
|
+
const topics = log.topics;
|
|
57
|
+
if (!Array.isArray(topics) || topics.length !== 4 || !topics.every((t) => typeof t === "string" && WORD.test(t))) continue;
|
|
58
|
+
if (topics[0].toLowerCase() !== ACROSS_FUNDS_DEPOSITED) continue;
|
|
59
|
+
if (typeof log.data !== "string" || !HEX.test(log.data)) continue;
|
|
60
|
+
let d;
|
|
61
|
+
try {
|
|
62
|
+
d = decodeAbiParameters(EVENT_DATA, log.data);
|
|
63
|
+
} catch {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
out.push({
|
|
67
|
+
originChainId: source.chainId,
|
|
68
|
+
destinationChainId: BigInt(topics[1]),
|
|
69
|
+
depositId: BigInt(topics[2]),
|
|
70
|
+
depositor: lowerHex(topics[3]),
|
|
71
|
+
inputToken: lowerHex(d[0]),
|
|
72
|
+
outputToken: lowerHex(d[1]),
|
|
73
|
+
inputAmount: d[2],
|
|
74
|
+
outputAmount: d[3],
|
|
75
|
+
quoteTimestamp: d[4],
|
|
76
|
+
fillDeadline: d[5],
|
|
77
|
+
exclusivityDeadline: d[6],
|
|
78
|
+
recipient: lowerHex(d[7]),
|
|
79
|
+
exclusiveRelayer: lowerHex(d[8]),
|
|
80
|
+
message: lowerHex(d[9])
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
function depositDataOf(e, exclusivityParameter) {
|
|
86
|
+
const depositor = acrossAddressOf(e.depositor);
|
|
87
|
+
const recipient = acrossAddressOf(e.recipient);
|
|
88
|
+
const inputToken = acrossAddressOf(e.inputToken);
|
|
89
|
+
const outputToken = acrossAddressOf(e.outputToken);
|
|
90
|
+
const exclusiveRelayer = acrossAddressOf(e.exclusiveRelayer);
|
|
91
|
+
if (!depositor || !recipient || !inputToken || !outputToken || !exclusiveRelayer) return null;
|
|
92
|
+
try {
|
|
93
|
+
return encodeAcrossDeposit({
|
|
94
|
+
depositor,
|
|
95
|
+
recipient,
|
|
96
|
+
inputToken,
|
|
97
|
+
outputToken,
|
|
98
|
+
inputAmount: e.inputAmount,
|
|
99
|
+
outputAmount: e.outputAmount,
|
|
100
|
+
destinationChainId: e.destinationChainId,
|
|
101
|
+
exclusiveRelayer,
|
|
102
|
+
quoteTimestamp: e.quoteTimestamp,
|
|
103
|
+
fillDeadline: e.fillDeadline,
|
|
104
|
+
exclusivityParameter,
|
|
105
|
+
message: e.message
|
|
106
|
+
});
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function acrossDepositIsIntent(e, digest, sourceBlockTime) {
|
|
112
|
+
if (typeof digest !== "string" || !DIGEST.test(digest)) return false;
|
|
113
|
+
const d = e.exclusivityDeadline;
|
|
114
|
+
const candidates = [];
|
|
115
|
+
if (d === 0) candidates.push(0);
|
|
116
|
+
else {
|
|
117
|
+
if (d > ACROSS_MAX_EXCLUSIVITY_PERIOD_S) candidates.push(d);
|
|
118
|
+
if (sourceBlockTime !== void 0 && d - sourceBlockTime > 0 && d - sourceBlockTime <= ACROSS_MAX_EXCLUSIVITY_PERIOD_S) candidates.push(d - sourceBlockTime);
|
|
119
|
+
}
|
|
120
|
+
return candidates.some((p) => {
|
|
121
|
+
const data = depositDataOf(e, p);
|
|
122
|
+
return data !== null && keccak256(data).slice(2, 34) === digest;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function acrossRelayHash(e) {
|
|
126
|
+
return keccak256(encodeAbiParameters([RELAY_DATA, { type: "uint256" }], [{
|
|
127
|
+
depositor: e.depositor,
|
|
128
|
+
recipient: e.recipient,
|
|
129
|
+
exclusiveRelayer: e.exclusiveRelayer,
|
|
130
|
+
inputToken: e.inputToken,
|
|
131
|
+
outputToken: e.outputToken,
|
|
132
|
+
inputAmount: e.inputAmount,
|
|
133
|
+
outputAmount: e.outputAmount,
|
|
134
|
+
originChainId: BigInt(e.originChainId),
|
|
135
|
+
depositId: e.depositId,
|
|
136
|
+
fillDeadline: e.fillDeadline,
|
|
137
|
+
exclusivityDeadline: e.exclusivityDeadline,
|
|
138
|
+
message: e.message
|
|
139
|
+
}, e.destinationChainId]));
|
|
140
|
+
}
|
|
141
|
+
function acrossFillStatusCall(relayHash) {
|
|
142
|
+
if (!WORD.test(relayHash)) throw new Error("across: a relay hash is 32 bytes");
|
|
143
|
+
return `${ACROSS_FILL_STATUSES}${relayHash.slice(2).toLowerCase()}`;
|
|
144
|
+
}
|
|
145
|
+
function parseAcrossFillStatus(answer) {
|
|
146
|
+
if (typeof answer !== "string" || !/^0x0{63}[0-2]$/i.test(answer)) return null;
|
|
147
|
+
return Number(answer.slice(-1));
|
|
148
|
+
}
|
|
149
|
+
function acrossFillState(status, fillDeadline, blockTime) {
|
|
150
|
+
if (status === ACROSS_FILL_STATUS.FILLED) return "filled";
|
|
151
|
+
if (blockTime > fillDeadline) return "expired";
|
|
152
|
+
return status === ACROSS_FILL_STATUS.REQUESTED_SLOW_FILL ? "slow-fill-requested" : "unfilled";
|
|
153
|
+
}
|
|
154
|
+
var MAX_RPC_BODY = 8 * 1024 * 1024;
|
|
155
|
+
function acrossRpc(url, fetchImpl, timeoutMs = 12e3) {
|
|
156
|
+
if (typeof url !== "string" || !/^https?:\/\//.test(url)) throw new Error("across: an RPC URL must use http or https");
|
|
157
|
+
let id = 0;
|
|
158
|
+
return async (method, params) => {
|
|
159
|
+
let text;
|
|
160
|
+
try {
|
|
161
|
+
const res = await (fetchImpl ?? fetch)(url, {
|
|
162
|
+
method: "POST",
|
|
163
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
164
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
|
|
165
|
+
signal: timeoutSignal(timeoutMs)
|
|
166
|
+
});
|
|
167
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
168
|
+
text = await res.text();
|
|
169
|
+
} catch (err) {
|
|
170
|
+
throw new Error(`across: ${method} failed \u2014 ${redactUrls(err instanceof Error ? err.message : String(err)).slice(0, 160)}`);
|
|
171
|
+
}
|
|
172
|
+
if (text.length > MAX_RPC_BODY) throw new Error(`across: ${method} answered more than ${MAX_RPC_BODY} bytes`);
|
|
173
|
+
let body;
|
|
174
|
+
try {
|
|
175
|
+
body = JSON.parse(text);
|
|
176
|
+
} catch {
|
|
177
|
+
throw new Error(`across: ${method} answered something that is not JSON`);
|
|
178
|
+
}
|
|
179
|
+
if (body === null || typeof body !== "object") throw new Error(`across: ${method} answered something that is not JSON-RPC`);
|
|
180
|
+
if (body.error !== void 0) throw new Error(`across: ${method} failed \u2014 ${redactUrls(String(body.error?.message ?? "error")).slice(0, 160)}`);
|
|
181
|
+
if (!Object.prototype.hasOwnProperty.call(body, "result")) throw new Error(`across: ${method} answered no result`);
|
|
182
|
+
return body.result;
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async function blockTimeOf(rpc, number) {
|
|
186
|
+
if (typeof number !== "string" || !QUANTITY.test(number)) return null;
|
|
187
|
+
try {
|
|
188
|
+
const block = await rpc("eth_getBlockByNumber", [number, false]);
|
|
189
|
+
const timestamp = block?.timestamp;
|
|
190
|
+
if (typeof block?.number !== "string" || block.number.toLowerCase() !== number.toLowerCase()) return null;
|
|
191
|
+
if (typeof timestamp !== "string" || !/^0x[0-9a-fA-F]{1,12}$/.test(timestamp)) return null;
|
|
192
|
+
return parseInt(timestamp, 16);
|
|
193
|
+
} catch {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async function trackAcrossDeposit(input) {
|
|
198
|
+
const { source, dest, sourceRpc, destRpc } = input;
|
|
199
|
+
if (typeof input.sourceTxHash !== "string" || !WORD.test(input.sourceTxHash) || !sourceRpc) return { status: { state: "pending" } };
|
|
200
|
+
if (typeof input.intentDigest !== "string" || !DIGEST.test(input.intentDigest)) return { status: { state: "pending" } };
|
|
201
|
+
let receipt;
|
|
202
|
+
try {
|
|
203
|
+
receipt = await sourceRpc("eth_getTransactionReceipt", [input.sourceTxHash]);
|
|
204
|
+
} catch {
|
|
205
|
+
return { status: { state: "pending" } };
|
|
206
|
+
}
|
|
207
|
+
if (receipt === null || receipt === void 0) return { status: { state: "pending" } };
|
|
208
|
+
if (typeof receipt !== "object") return { status: { state: "pending" } };
|
|
209
|
+
const status = receipt.status;
|
|
210
|
+
if (status === "0x0") return { status: { state: "failed" } };
|
|
211
|
+
if (status !== "0x1") return { status: { state: "pending" } };
|
|
212
|
+
const txHash = receipt.transactionHash;
|
|
213
|
+
if (txHash !== void 0 && (typeof txHash !== "string" || txHash.toLowerCase() !== input.sourceTxHash.toLowerCase())) return { status: { state: "pending" } };
|
|
214
|
+
const onRoute = acrossDepositsInReceipt(receipt, source).filter((d) => d.destinationChainId === BigInt(dest.chainId));
|
|
215
|
+
let mine = onRoute.filter((d) => acrossDepositIsIntent(d, input.intentDigest));
|
|
216
|
+
if (mine.length === 0 && onRoute.some((d) => d.exclusivityDeadline !== 0)) {
|
|
217
|
+
const blockTime = await blockTimeOf(sourceRpc, receipt.blockNumber);
|
|
218
|
+
if (blockTime === null) return { status: { state: "pending" } };
|
|
219
|
+
mine = onRoute.filter((d) => acrossDepositIsIntent(d, input.intentDigest, blockTime));
|
|
220
|
+
}
|
|
221
|
+
if (mine.length !== 1) return { status: { state: "pending" } };
|
|
222
|
+
const deposit = mine[0];
|
|
223
|
+
const relayHash = acrossRelayHash(deposit);
|
|
224
|
+
const seen = { status: { state: "pending", depositReceived: true }, deposit, relayHash };
|
|
225
|
+
if (!destRpc) return seen;
|
|
226
|
+
try {
|
|
227
|
+
const block = await destRpc("eth_getBlockByNumber", ["latest", false]);
|
|
228
|
+
const number = block?.number;
|
|
229
|
+
const timestamp = block?.timestamp;
|
|
230
|
+
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;
|
|
231
|
+
const blockTime = parseInt(timestamp, 16);
|
|
232
|
+
const fillStatus = parseAcrossFillStatus(await destRpc("eth_call", [{ to: dest.spokePool, data: acrossFillStatusCall(relayHash) }, number]));
|
|
233
|
+
if (fillStatus === null) return seen;
|
|
234
|
+
const fill = acrossFillState(fillStatus, deposit.fillDeadline, blockTime);
|
|
235
|
+
const destBlock = { number: number.toLowerCase(), timestamp: blockTime };
|
|
236
|
+
if (fill === "filled") return { status: { state: "completed", depositReceived: true }, deposit, relayHash, fill, destBlock };
|
|
237
|
+
if (fill === "expired") return { status: { state: "expired", depositReceived: true }, deposit, relayHash, fill, destBlock };
|
|
238
|
+
return { status: { state: "pending", depositReceived: true }, deposit, relayHash, fill, destBlock };
|
|
239
|
+
} catch {
|
|
240
|
+
return seen;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export {
|
|
245
|
+
ACROSS_FILL_STATUS,
|
|
246
|
+
acrossDepositsInReceipt,
|
|
247
|
+
acrossDepositIsIntent,
|
|
248
|
+
acrossRelayHash,
|
|
249
|
+
acrossFillStatusCall,
|
|
250
|
+
parseAcrossFillStatus,
|
|
251
|
+
acrossFillState,
|
|
252
|
+
acrossRpc,
|
|
253
|
+
trackAcrossDeposit
|
|
254
|
+
};
|
|
255
|
+
//# sourceMappingURL=chunk-3UBRQ3ZE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/status.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"],"mappings":";;;;;;;;;;;AAuBA,SAAQ,qBAAqB,qBAAqB,iBAA0B;AAE5E,SAAQ,YAAY,qBAAoB;AAwBjC,IAAM,qBAAqB,OAAO,OAAO,EAAC,UAAU,GAAG,qBAAqB,GAAG,QAAQ,EAAC,CAAU;AAKzG,IAAM,aAAa;AAAA,EACjB,EAAC,MAAM,cAAc,MAAM,UAAS;AAAA,EACpC,EAAC,MAAM,eAAe,MAAM,UAAS;AAAA,EACrC,EAAC,MAAM,eAAe,MAAM,UAAS;AAAA,EACrC,EAAC,MAAM,gBAAgB,MAAM,UAAS;AAAA,EACtC,EAAC,MAAM,kBAAkB,MAAM,SAAQ;AAAA,EACvC,EAAC,MAAM,gBAAgB,MAAM,SAAQ;AAAA,EACrC,EAAC,MAAM,uBAAuB,MAAM,SAAQ;AAAA,EAC5C,EAAC,MAAM,aAAa,MAAM,UAAS;AAAA,EACnC,EAAC,MAAM,oBAAoB,MAAM,UAAS;AAAA,EAC1C,EAAC,MAAM,WAAW,MAAM,QAAO;AACjC;AAEA,IAAM,aAAa;AAAA,EACjB,MAAM;AAAA,EACN,YAAY;AAAA,IACV,EAAC,MAAM,aAAa,MAAM,UAAS;AAAA,IACnC,EAAC,MAAM,aAAa,MAAM,UAAS;AAAA,IACnC,EAAC,MAAM,oBAAoB,MAAM,UAAS;AAAA,IAC1C,EAAC,MAAM,cAAc,MAAM,UAAS;AAAA,IACpC,EAAC,MAAM,eAAe,MAAM,UAAS;AAAA,IACrC,EAAC,MAAM,eAAe,MAAM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AAK,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":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACROSS_DEPOSIT,
|
|
3
|
+
ACROSS_DEPOSIT_V3,
|
|
4
|
+
acrossChain
|
|
5
|
+
} from "./chunk-GX67FRPG.js";
|
|
6
|
+
|
|
7
|
+
// src/activity.ts
|
|
8
|
+
import { chainLabel, describeSwapLike, matchesCall } from "@anywalletkit/protocol-swap2-core/activity";
|
|
9
|
+
var ACROSS_MODULE = "@anywalletkit/protocol-swap2-across";
|
|
10
|
+
function describeAcrossActivity(tx, ctx) {
|
|
11
|
+
const chain = acrossChain(tx.chain);
|
|
12
|
+
if (!chain) return null;
|
|
13
|
+
if (!matchesCall(tx, [chain.spokePool], [ACROSS_DEPOSIT, ACROSS_DEPOSIT_V3])) return null;
|
|
14
|
+
return describeSwapLike(tx, ctx, { protocol: ACROSS_MODULE, subtitle: `Across \xB7 ${chainLabel(tx.chain)}`, kind: "bridge", outVerb: "Bridged" });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
ACROSS_MODULE,
|
|
19
|
+
describeAcrossActivity
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-5BDZXOOP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/activity.ts"],"sourcesContent":["/**\n * Activity recognition for Across on every pinned chain: a `deposit` / `depositV3` call on the chain's SpokePool is our\n * source leg (\"Bridged USDC\").\n *\n * Deposits that reach the SpokePool through another contract (Across's periphery, an aggregator, a Safe) are not\n * claimed: the call the history shows is that contract's. The destination leg is not claimed either — a fill is paid\n * by one of many relayers as an ordinary token transfer (or a native payment when the wrapped native token is\n * unwrapped) and reads as a plain incoming transfer.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {ACROSS_DEPOSIT, ACROSS_DEPOSIT_V3, acrossChain} from \"./config.js\";\n\nexport const ACROSS_MODULE = \"@anywalletkit/protocol-swap2-across\";\n\nexport function describeAcrossActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n const chain = acrossChain(tx.chain);\n if (!chain) return null;\n // Both deposit functions are read here (history is not ours alone); only `deposit` is ever built or signed.\n if (!matchesCall(tx, [chain.spokePool], [ACROSS_DEPOSIT, ACROSS_DEPOSIT_V3])) return null;\n return describeSwapLike(tx, ctx, {protocol: ACROSS_MODULE, subtitle: `Across · ${chainLabel(tx.chain)}`, kind: \"bridge\", outVerb: \"Bridged\"});\n}\n"],"mappings":";;;;;;;AAUA,SAAQ,YAAY,kBAAkB,mBAAkB;AAGjD,IAAM,gBAAgB;AAEtB,SAAS,uBAAuB,IAAa,KAAmD;AACrG,QAAM,QAAQ,YAAY,GAAG,KAAK;AAClC,MAAI,CAAC,MAAO,QAAO;AAEnB,MAAI,CAAC,YAAY,IAAI,CAAC,MAAM,SAAS,GAAG,CAAC,gBAAgB,iBAAiB,CAAC,EAAG,QAAO;AACrF,SAAO,iBAAiB,IAAI,KAAK,EAAC,UAAU,eAAe,UAAU,eAAY,WAAW,GAAG,KAAK,CAAC,IAAI,MAAM,UAAU,SAAS,UAAS,CAAC;AAC9I;","names":[]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AcrossRefusal
|
|
3
|
+
} from "./chunk-E5WFOPN2.js";
|
|
4
|
+
|
|
5
|
+
// src/pricing.ts
|
|
6
|
+
var ACROSS_FILL_WINDOW_S = 7200;
|
|
7
|
+
var ACROSS_QUOTE_TIME_LAG_S = 60;
|
|
8
|
+
var ACROSS_FLOOR_CBPS = Object.freeze({ stable: 100, wbtc: 310, ethFromEthereum: 100 });
|
|
9
|
+
var ACROSS_ETH_L2_CURVE = Object.freeze([
|
|
10
|
+
[0, 477],
|
|
11
|
+
[1e3, 515],
|
|
12
|
+
[2e3, 540],
|
|
13
|
+
[4e3, 605],
|
|
14
|
+
[8e3, 715],
|
|
15
|
+
[16e3, 850],
|
|
16
|
+
[36e3, 920]
|
|
17
|
+
].map((p) => Object.freeze(p)));
|
|
18
|
+
var ACROSS_ETH_L2_FLOOR_MAX_USD = 36e3;
|
|
19
|
+
var ACROSS_FLOOR_ORIGINS = Object.freeze([1, 10, 8453, 42161]);
|
|
20
|
+
var ACROSS_FLOOR_DESTINATIONS = Object.freeze([10, 8453, 42161]);
|
|
21
|
+
function acrossFloorCovers(route) {
|
|
22
|
+
return ACROSS_FLOOR_ORIGINS.includes(route.input.chain.chainId) && ACROSS_FLOOR_DESTINATIONS.includes(route.output.chain.chainId);
|
|
23
|
+
}
|
|
24
|
+
var ACROSS_V5_OTHER_RAIL_FILL_MS = 6e4;
|
|
25
|
+
var acrossV5OtherRail = (expectedFillTimeMs) => expectedFillTimeMs > ACROSS_V5_OTHER_RAIL_FILL_MS;
|
|
26
|
+
function acrossRouteUnpriced(route) {
|
|
27
|
+
if (route.output.chain.chainId === 1) return "plain deposits to Ethereum are not priced yet \u2014 small ones went unfilled in the 2026-11-14 study for reasons the data does not show";
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
function acrossFloorCbps(route, amountUsd) {
|
|
31
|
+
const src = route.input.chain.chainId;
|
|
32
|
+
if (!acrossFloorCovers(route)) {
|
|
33
|
+
return `without Across's relayer fee quote there is no relayer price for ${route.input.chain.name} \u2192 ${route.output.chain.name} (the pinned floor covers Ethereum, Optimism, Base and Arbitrum to Optimism, Base and Arbitrum)`;
|
|
34
|
+
}
|
|
35
|
+
if (route.asset === "USDC" || route.asset === "USDT") return ACROSS_FLOOR_CBPS.stable;
|
|
36
|
+
if (route.asset === "WBTC") return ACROSS_FLOOR_CBPS.wbtc;
|
|
37
|
+
if (src === 1) return ACROSS_FLOOR_CBPS.ethFromEthereum;
|
|
38
|
+
if (amountUsd === void 0 || !Number.isFinite(amountUsd) || amountUsd < 0) return "without Across's relayer fee quote the ETH floor needs the transfer's size in dollars, and the V5 quote states none";
|
|
39
|
+
if (amountUsd > ACROSS_ETH_L2_FLOOR_MAX_USD) return `without Across's relayer fee quote ETH from an L2 is priced up to $${ACROSS_ETH_L2_FLOOR_MAX_USD} (no larger plain deposit was seen)`;
|
|
40
|
+
const c = ACROSS_ETH_L2_CURVE;
|
|
41
|
+
for (let i = 1; i < c.length; i++) {
|
|
42
|
+
const [x1, y1] = c[i];
|
|
43
|
+
if (amountUsd <= x1) {
|
|
44
|
+
const [x0, y0] = c[i - 1];
|
|
45
|
+
return Math.ceil(y0 + (y1 - y0) * (amountUsd - x0) / (x1 - x0));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return c[c.length - 1][1];
|
|
49
|
+
}
|
|
50
|
+
var acrossCbpsOf = (amount, cbps) => (amount * BigInt(cbps) + 999999n) / 1000000n;
|
|
51
|
+
function acrossFloorFee(route, amount, amountUsd, destinationGas) {
|
|
52
|
+
const cbps = acrossFloorCbps(route, amountUsd);
|
|
53
|
+
if (typeof cbps === "string") {
|
|
54
|
+
const tooLarge = acrossFloorCovers(route) && route.asset === "ETH" && route.input.chain.chainId !== 1 && amountUsd !== void 0 && amountUsd > ACROSS_ETH_L2_FLOOR_MAX_USD;
|
|
55
|
+
throw new AcrossRefusal("relayer-price", cbps, tooLarge ? "amount_too_large" : "upstream_unavailable");
|
|
56
|
+
}
|
|
57
|
+
if (destinationGas === null) throw new AcrossRefusal("relayer-price", "without Across's relayer fee quote the floor needs V5's destination gas, and it does not read", "upstream_unavailable");
|
|
58
|
+
return acrossCbpsOf(amount, cbps) + (destinationGas * 3n + 1n) / 2n;
|
|
59
|
+
}
|
|
60
|
+
function acrossPlainFee(amount, v5, need, otherRail = false) {
|
|
61
|
+
const f5 = v5.totalFee - (v5.originGas > v5.totalFee ? v5.totalFee : v5.originGas);
|
|
62
|
+
const fee = otherRail || need > f5 ? need : f5;
|
|
63
|
+
if (fee >= amount) throw new AcrossRefusal("relayer-price", `relayers would keep all of the ${amount} sent (fee ${fee})`, "amount_too_small");
|
|
64
|
+
return { fee, f5, need };
|
|
65
|
+
}
|
|
66
|
+
var ACROSS_RELAYER_FEE_TOLERANCE_PCT = 10;
|
|
67
|
+
function acrossCheckRelayerFee(route, amount, fee, answer) {
|
|
68
|
+
if (answer.kind === "refused") throw new AcrossRefusal("relayer-price", `${answer.detail} (read on this device)`, answer.reason);
|
|
69
|
+
if (answer.kind === "unavailable") {
|
|
70
|
+
if (acrossFloorCovers(route)) return;
|
|
71
|
+
throw new AcrossRefusal("relayer-price", `Across's relayer fee quote did not answer on this device (${answer.detail.slice(0, 120)}), and ${route.input.chain.name} \u2192 ${route.output.chain.name} has no studied floor to stand on`, "upstream_unavailable");
|
|
72
|
+
}
|
|
73
|
+
const need = answer.totalRelayFee;
|
|
74
|
+
if (fee * 100n < need * BigInt(100 - ACROSS_RELAYER_FEE_TOLERANCE_PCT)) {
|
|
75
|
+
throw new AcrossRefusal("relayer-price", `the deposit leaves relayers ${fee} of ${amount}, under the ${need} Across's own relayer fee quote names for it (read on this device) \u2014 relayers would leave it unfilled, and the funds wait for a refund`, "price_check_failed");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function acrossQuoteTimeOf(ethereumBlockTime, originBlockTime) {
|
|
79
|
+
return Math.min(ethereumBlockTime - ACROSS_QUOTE_TIME_LAG_S, originBlockTime);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
ACROSS_FILL_WINDOW_S,
|
|
84
|
+
ACROSS_QUOTE_TIME_LAG_S,
|
|
85
|
+
ACROSS_FLOOR_CBPS,
|
|
86
|
+
ACROSS_ETH_L2_CURVE,
|
|
87
|
+
ACROSS_ETH_L2_FLOOR_MAX_USD,
|
|
88
|
+
ACROSS_FLOOR_ORIGINS,
|
|
89
|
+
ACROSS_FLOOR_DESTINATIONS,
|
|
90
|
+
acrossFloorCovers,
|
|
91
|
+
ACROSS_V5_OTHER_RAIL_FILL_MS,
|
|
92
|
+
acrossV5OtherRail,
|
|
93
|
+
acrossRouteUnpriced,
|
|
94
|
+
acrossFloorCbps,
|
|
95
|
+
acrossCbpsOf,
|
|
96
|
+
acrossFloorFee,
|
|
97
|
+
acrossPlainFee,
|
|
98
|
+
ACROSS_RELAYER_FEE_TOLERANCE_PCT,
|
|
99
|
+
acrossCheckRelayerFee,
|
|
100
|
+
acrossQuoteTimeOf
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=chunk-6Z4GXNLE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/pricing.ts"],"sourcesContent":["/**\n * How much a plain SpokePool deposit leaves to relayers — the one number a quote source decides.\n *\n * The risk is two-sided. Asking relayers for too much (`outputAmount` too high) and nobody fills: the funds wait for\n * the fill deadline (two hours) and then Across's refund bundles (hours more). Asking for too little and the user\n * overpays. Across API V5 is the price source, but it prices V5's OWN route, not a plain deposit: an execution step on\n * the origin chain through Across's Gateway that a plain deposit does not have (the user's own wallet pays the\n * deposit's gas), sometimes another rail (USDT Ethereum → Arbitrum went to a 20-minute rail on 2026-11-14), and an\n * auction whose relayers fill large ETH L2 → L2 transfers at ~1 bp, well below what plain deposits are filled at.\n *\n * The rule (study of 2026-11-15: 27 V5 / suggested-fees pairs and 8 272 deposits on Ethereum, Optimism, Base and\n * Arbitrum over 24 h — 1 369 of 1 369 organic plain deposits to Base, Arbitrum and Optimism priced at or above the\n * relayer fee were filled, p50 2 s, p90 13 s):\n *\n * ```\n * F5 = V5 fee.totalFee − Σ V5 gasEstimates[origin, included_in_transfer_fee] (the add-back rounded down)\n * Fneed = /suggested-fees totalRelayFee.total while Across answers it\n * = floor(asset, origin, size) + 1.5 × V5's destination gas otherwise (studied routes only)\n * fee = max(F5, Fneed); outputAmount = input − fee\n * = Fneed, from /suggested-fees only, when V5's fill estimate is over a minute (V5 prices another rail)\n * quoteTimestamp = /suggested-fees `timestamp` (the LP fee was priced there; never ahead of the server's clock), else\n * min(latest Ethereum block time − 60 s, latest origin block time)\n * fillDeadline = quoteTimestamp + 7200; no exclusivity\n * ```\n *\n * `max()` keeps both bounds: never more than V5 charges for the same transfer (net of the step a plain deposit does\n * not have), never less than plain deposits are filled at today. When V5's fill estimate is over a minute its price\n * is another rail's (a CCTP or OFT transfer, 1 216 s for USDT Ethereum → Arbitrum on 2026-11-15, at 12× the relayer\n * fee), not a bound on a plain deposit: the deposit is then priced on Across's relayer fee alone, and refused without it.\n *\n * The device holds whatever a server says to its own checks (`verify.ts`, `remote.ts`): the user's cap, a per-asset\n * fee floor, and — through `acrossRemoteProvider` — Across's keyless relayer fee read on the device itself\n * ({@link acrossCheckRelayerFee}), so a server can neither take a deposit nor get one signed that relayers leave unfilled.\n */\nimport type {AcrossSuggestedFees} from \"./api.js\";\nimport type {AcrossRoute} from \"./config.js\";\nimport {AcrossRefusal} from \"./refusal.js\";\n\n/** The fill deadline after the quote time: what Across's own quotes give (3 923 of 6 982 plain deposits, 2026-11-14). */\nexport const ACROSS_FILL_WINDOW_S = 7_200;\n/** Without `/suggested-fees`, the quote time lags Ethereum's latest block by this much (the LP fee is priced at a HubPool block). */\nexport const ACROSS_QUOTE_TIME_LAG_S = 60;\n\n/**\n * The relayer-fee floor without `/suggested-fees`, in hundredths of a basis point (millionths) of the input, read off 24 h of\n * fills priced by it (2026-11-14): stablecoins 1.00 bp, WBTC 3.10 bps, ETH from Ethereum 1.00 bp (fills seen at\n * 0.74–0.84), ETH from an L2 on a size curve. Plus 1.5 × V5's destination gas.\n */\nexport const ACROSS_FLOOR_CBPS = Object.freeze({stable: 100, wbtc: 310, ethFromEthereum: 100});\n/** ETH from an L2: [size in USD, hundredths of a bp], linear between points — the curve every plain ETH L2 → L2 deposit of $1 000+ paid. */\nexport const ACROSS_ETH_L2_CURVE: readonly (readonly [number, number])[] = Object.freeze([\n [0, 477], [1_000, 515], [2_000, 540], [4_000, 605], [8_000, 715], [16_000, 850], [36_000, 920],\n].map((p) => Object.freeze(p as [number, number])));\n/** Above this size (USD) no plain ETH L2 deposit was seen: refused when the floor is what prices it. */\nexport const ACROSS_ETH_L2_FLOOR_MAX_USD = 36_000;\n/**\n * The chains the floor was derived on: deposits from Ethereum, Optimism, Base and Arbitrum to Optimism, Base and\n * Arbitrum. Without `/suggested-fees` any other route has no relayer price this module can stand behind.\n */\nexport const ACROSS_FLOOR_ORIGINS: readonly number[] = Object.freeze([1, 10, 8453, 42161]);\nexport const ACROSS_FLOOR_DESTINATIONS: readonly number[] = Object.freeze([10, 8453, 42161]);\n\n/** Whether the pinned floor covers a route (its origin and destination are among the studied chains). */\nexport function acrossFloorCovers(route: AcrossRoute): boolean {\n return ACROSS_FLOOR_ORIGINS.includes(route.input.chain.chainId) && ACROSS_FLOOR_DESTINATIONS.includes(route.output.chain.chainId);\n}\n\n/**\n * Over this fill estimate (ms) a V5 quote prices another rail than an Across relayer fill: Across-rail fills were\n * estimated at 1.3–14 s on every recorded cell, the OFT rail for USDT Ethereum → Arbitrum at 1 216 s (2026-11-15).\n */\nexport const ACROSS_V5_OTHER_RAIL_FILL_MS = 60_000;\n/** True when a V5 fill estimate says V5 priced another rail. */\nexport const acrossV5OtherRail = (expectedFillTimeMs: number): boolean => expectedFillTimeMs > ACROSS_V5_OTHER_RAIL_FILL_MS;\n\n/**\n * Why a route is not priced at all, or null. Ethereum as the destination: small plain deposits to Ethereum went\n * unfilled in the study's window (some paying more than filled ones), for reasons the data does not show — kept out\n * until studied rather than priced on a guess.\n */\nexport function acrossRouteUnpriced(route: AcrossRoute): string | null {\n if (route.output.chain.chainId === 1) return \"plain deposits to Ethereum are not priced yet — small ones went unfilled in the 2026-11-14 study for reasons the data does not show\";\n return null;\n}\n\n/** The floor in hundredths of a bp for a route and size (USD), or a refusal text. */\nexport function acrossFloorCbps(route: AcrossRoute, amountUsd: number | undefined): number | string {\n const src = route.input.chain.chainId;\n if (!acrossFloorCovers(route)) {\n return `without Across's relayer fee quote there is no relayer price for ${route.input.chain.name} → ${route.output.chain.name} (the pinned floor covers Ethereum, Optimism, Base and Arbitrum to Optimism, Base and Arbitrum)`;\n }\n if (route.asset === \"USDC\" || route.asset === \"USDT\") return ACROSS_FLOOR_CBPS.stable;\n if (route.asset === \"WBTC\") return ACROSS_FLOOR_CBPS.wbtc;\n if (src === 1) return ACROSS_FLOOR_CBPS.ethFromEthereum;\n if (amountUsd === undefined || !Number.isFinite(amountUsd) || amountUsd < 0) return \"without Across's relayer fee quote the ETH floor needs the transfer's size in dollars, and the V5 quote states none\";\n if (amountUsd > ACROSS_ETH_L2_FLOOR_MAX_USD) return `without Across's relayer fee quote ETH from an L2 is priced up to $${ACROSS_ETH_L2_FLOOR_MAX_USD} (no larger plain deposit was seen)`;\n const c = ACROSS_ETH_L2_CURVE;\n for (let i = 1; i < c.length; i++) {\n const [x1, y1] = c[i]!;\n if (amountUsd <= x1) {\n const [x0, y0] = c[i - 1]!;\n return Math.ceil(y0 + ((y1 - y0) * (amountUsd - x0)) / (x1 - x0));\n }\n }\n return c[c.length - 1]![1];\n}\n\n/** `amount × cbps / 1 000 000`, rounded up. */\nexport const acrossCbpsOf = (amount: bigint, cbps: number): bigint => (amount * BigInt(cbps) + 999_999n) / 1_000_000n;\n\n/** The pinned-floor relayer need for a route without `/suggested-fees`: floor + 1.5 × V5's destination gas, rounded up. */\nexport function acrossFloorFee(route: AcrossRoute, amount: bigint, amountUsd: number | undefined, destinationGas: bigint | null): bigint {\n const cbps = acrossFloorCbps(route, amountUsd);\n if (typeof cbps === \"string\") {\n // Too large only where the floor covers the route and the size is what it lacks; elsewhere the relayer price is.\n const tooLarge = acrossFloorCovers(route) && route.asset === \"ETH\" && route.input.chain.chainId !== 1 && amountUsd !== undefined && amountUsd > ACROSS_ETH_L2_FLOOR_MAX_USD;\n throw new AcrossRefusal(\"relayer-price\", cbps, tooLarge ? \"amount_too_large\" : \"upstream_unavailable\");\n }\n if (destinationGas === null) throw new AcrossRefusal(\"relayer-price\", \"without Across's relayer fee quote the floor needs V5's destination gas, and it does not read\", \"upstream_unavailable\");\n return acrossCbpsOf(amount, cbps) + (destinationGas * 3n + 1n) / 2n;\n}\n\n/** The fee of a plain deposit: `max(F5, Fneed)`, with both terms. */\nexport interface AcrossPlainFee {\n fee: bigint;\n /** V5's fee net of its origin execution step. */\n f5: bigint;\n /** What a relayer needs (`/suggested-fees`, or the floor). */\n need: bigint;\n}\n\n/**\n * `max(F5, Fneed)`; `Fneed` alone when V5 priced another rail (`otherRail`: F5 is then that rail's price, kept for\n * display only). Refuses a fee that eats the whole input (`amount_too_small`).\n */\nexport function acrossPlainFee(amount: bigint, v5: {totalFee: bigint; originGas: bigint}, need: bigint, otherRail = false): AcrossPlainFee {\n const f5 = v5.totalFee - (v5.originGas > v5.totalFee ? v5.totalFee : v5.originGas);\n const fee = otherRail || need > f5 ? need : f5;\n if (fee >= amount) throw new AcrossRefusal(\"relayer-price\", `relayers would keep all of the ${amount} sent (fee ${fee})`, \"amount_too_small\");\n return {fee, f5, need};\n}\n\n/**\n * How far under Across's own relayer fee a deposit's fee may sit when the device reads that fee itself, in percent of\n * it: the server's read and the device's are seconds apart, and the same quote moved at most 2.2 % over a minute\n * (five corridors, 2026-11-15).\n */\nexport const ACROSS_RELAYER_FEE_TOLERANCE_PCT = 10;\n\n/**\n * The device's own check of a deposit's fee against Across's keyless relayer fee for it, read on the device\n * (`acrossRemoteProvider`): a fee more than {@link ACROSS_RELAYER_FEE_TOLERANCE_PCT} % under it is refused\n * (`price_check_failed` — relayers would leave the deposit unfilled for its two-hour deadline and the refund after);\n * Across refusing the deposit refuses it with Across's reason. Without an answer only a route the pinned floor covers\n * stands, on the per-asset floor the verifier already held it to; any other route is refused (`upstream_unavailable`).\n * Throws {@link AcrossRefusal} `relayer-price`.\n */\nexport function acrossCheckRelayerFee(route: AcrossRoute, amount: bigint, fee: bigint, answer: AcrossSuggestedFees): void {\n if (answer.kind === \"refused\") throw new AcrossRefusal(\"relayer-price\", `${answer.detail} (read on this device)`, answer.reason);\n if (answer.kind === \"unavailable\") {\n if (acrossFloorCovers(route)) return;\n throw new AcrossRefusal(\"relayer-price\", `Across's relayer fee quote did not answer on this device (${answer.detail.slice(0, 120)}), and ${route.input.chain.name} → ${route.output.chain.name} has no studied floor to stand on`, \"upstream_unavailable\");\n }\n const need = answer.totalRelayFee;\n if (fee * 100n < need * BigInt(100 - ACROSS_RELAYER_FEE_TOLERANCE_PCT)) {\n throw new AcrossRefusal(\"relayer-price\", `the deposit leaves relayers ${fee} of ${amount}, under the ${need} Across's own relayer fee quote names for it (read on this device) — relayers would leave it unfilled, and the funds wait for a refund`, \"price_check_failed\");\n }\n}\n\n/** The deposit's quote time without `/suggested-fees`: `min(Ethereum − 60 s, origin)`, from the chains' latest blocks. */\nexport function acrossQuoteTimeOf(ethereumBlockTime: number, originBlockTime: number): number {\n return Math.min(ethereumBlockTime - ACROSS_QUOTE_TIME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