@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,396 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeAcrossDeposit
|
|
3
|
+
} from "./chunk-32YJEBZX.js";
|
|
4
|
+
import {
|
|
5
|
+
ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S,
|
|
6
|
+
ACROSS_FILL_DEADLINE_BUFFER_S,
|
|
7
|
+
ACROSS_NATIVE,
|
|
8
|
+
ACROSS_SPEED_UP_DOMAIN,
|
|
9
|
+
ACROSS_SPEED_UP_TYPE,
|
|
10
|
+
ACROSS_V5_MESSAGE_PREFIX,
|
|
11
|
+
acrossChain,
|
|
12
|
+
acrossRouteOf
|
|
13
|
+
} from "./chunk-GX67FRPG.js";
|
|
14
|
+
import {
|
|
15
|
+
ACROSS_FLOOR_ORIGINS,
|
|
16
|
+
acrossRouteUnpriced
|
|
17
|
+
} from "./chunk-6Z4GXNLE.js";
|
|
18
|
+
import {
|
|
19
|
+
AcrossRefusal
|
|
20
|
+
} from "./chunk-E5WFOPN2.js";
|
|
21
|
+
|
|
22
|
+
// src/verify.ts
|
|
23
|
+
import { keccak256 } from "viem";
|
|
24
|
+
import { bigintToUnits } from "@anywalletkit/core";
|
|
25
|
+
import { refusalNotes, refusalOf } from "@anywalletkit/protocol-swap2-core/errors";
|
|
26
|
+
import { sourceAssetOf } from "@anywalletkit/protocol-swap2-core/util";
|
|
27
|
+
var ACROSS_DEFAULT_MAX_FEE_BPS = 1e3;
|
|
28
|
+
var ACROSS_MAX_FEE_BPS_LIMIT = 5e3;
|
|
29
|
+
var ACROSS_CLOCK_SKEW_S = 120;
|
|
30
|
+
var ACROSS_QUOTE_TIME_AHEAD_S = 15;
|
|
31
|
+
var ACROSS_LANDING_WINDOW_S = 300;
|
|
32
|
+
var ACROSS_MIN_FILL_WINDOW_S = 1800;
|
|
33
|
+
var ACROSS_MAX_FILL_WINDOW_S = 7800;
|
|
34
|
+
var ACROSS_MIN_FEE_PPM = Object.freeze({ stable: 100, ethFromEthereum: 70, ethFromL2: 450, ethFromOtherL2: 70, wbtc: 250 });
|
|
35
|
+
function acrossMinFeePpm(route) {
|
|
36
|
+
if (route.asset === "ETH") {
|
|
37
|
+
const src = route.input.chain.chainId;
|
|
38
|
+
if (src === 1) return ACROSS_MIN_FEE_PPM.ethFromEthereum;
|
|
39
|
+
return ACROSS_FLOOR_ORIGINS.includes(src) ? ACROSS_MIN_FEE_PPM.ethFromL2 : ACROSS_MIN_FEE_PPM.ethFromOtherL2;
|
|
40
|
+
}
|
|
41
|
+
if (route.asset === "WBTC") return ACROSS_MIN_FEE_PPM.wbtc;
|
|
42
|
+
return ACROSS_MIN_FEE_PPM.stable;
|
|
43
|
+
}
|
|
44
|
+
var ACROSS_GAS_FLOOR = 90000n;
|
|
45
|
+
var ACROSS_GAS_CAP = 60000000n;
|
|
46
|
+
var ACROSS_MAX_QUOTE_LIFE_MS = 3e5 + ACROSS_CLOCK_SKEW_S * 1e3;
|
|
47
|
+
var acrossQuoteTimeLimitMs = (quoteTimestamp) => (quoteTimestamp + ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S - ACROSS_LANDING_WINDOW_S) * 1e3;
|
|
48
|
+
var ACROSS_PLACEHOLDER = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
49
|
+
var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
50
|
+
var ZERO = /^0x0{40}$/;
|
|
51
|
+
var U256_MAX = (1n << 256n) - 1n;
|
|
52
|
+
var UINT = /^(?:0|[1-9]\d{0,77})$/;
|
|
53
|
+
var lower = (s) => s.toLowerCase();
|
|
54
|
+
function checkAcrossRequest(r) {
|
|
55
|
+
const invalid = (what, reason) => {
|
|
56
|
+
throw new AcrossRefusal("request-invalid", what, reason);
|
|
57
|
+
};
|
|
58
|
+
if (r === null || typeof r !== "object") invalid("no request to check the deposit against");
|
|
59
|
+
for (const [what, v] of [["input token", r.sourceToken], ["output token", r.destToken], ["depositor", r.depositor], ["recipient", r.recipient]]) {
|
|
60
|
+
if (typeof v !== "string" || !ADDRESS.test(v)) invalid(`the ${what} is not an address`);
|
|
61
|
+
}
|
|
62
|
+
const route = acrossRouteOf(r.sourceChain, r.sourceToken, r.destChain, r.destToken);
|
|
63
|
+
if ("code" in route) throw new AcrossRefusal(route.code, route.detail, "unsupported_pair");
|
|
64
|
+
if (ZERO.test(r.depositor)) invalid("the depositor is the zero address", "recipient_mismatch");
|
|
65
|
+
if (ZERO.test(r.recipient)) invalid("the recipient is the zero address", "recipient_mismatch");
|
|
66
|
+
if (typeof r.amount !== "bigint" || r.amount <= 0n || r.amount > U256_MAX) invalid("the amount is not a positive integer");
|
|
67
|
+
if (r.minAmountOut !== void 0 && (typeof r.minAmountOut !== "bigint" || r.minAmountOut < 0n || r.minAmountOut > U256_MAX)) invalid("the output floor is not an unsigned integer");
|
|
68
|
+
const maxFeeBps = r.maxFeeBps ?? ACROSS_DEFAULT_MAX_FEE_BPS;
|
|
69
|
+
if (!Number.isInteger(maxFeeBps) || maxFeeBps < 0 || maxFeeBps > ACROSS_MAX_FEE_BPS_LIMIT) {
|
|
70
|
+
invalid(`the fee cap must be a whole number of basis points up to ${ACROSS_MAX_FEE_BPS_LIMIT}`, "policy_refused");
|
|
71
|
+
}
|
|
72
|
+
const nowMs = r.nowMs ?? Date.now();
|
|
73
|
+
if (!Number.isFinite(nowMs) || nowMs <= 0) invalid("the clock is not a time");
|
|
74
|
+
return { route, nowS: Math.floor(nowMs / 1e3), maxFeeBps };
|
|
75
|
+
}
|
|
76
|
+
function checkTarget(tx, route) {
|
|
77
|
+
if (tx === null || typeof tx !== "object") throw new AcrossRefusal("tx-shape", "there is no deposit transaction", "policy_refused");
|
|
78
|
+
const src = route.input.chain;
|
|
79
|
+
if (tx.chainId !== src.chainId) throw new AcrossRefusal("tx-chain", `the deposit is for chain ${String(tx.chainId)}, not ${src.name} (${src.chainId})`, "vault_mismatch");
|
|
80
|
+
if (typeof tx.to !== "string" || !ADDRESS.test(tx.to) || lower(tx.to) !== src.spokePool) {
|
|
81
|
+
throw new AcrossRefusal("tx-target", `the deposit calls ${String(tx.to)}, not the ${src.name} SpokePool ${src.spokePool} \u2014 periphery, swap and CCTP / OFT routes are not signed by this module`, "vault_mismatch");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function checkExclusivity(a) {
|
|
85
|
+
if (!ZERO.test(a.exclusiveRelayer) || a.exclusivityParameter !== 0) {
|
|
86
|
+
throw new AcrossRefusal("tx-exclusivity", `the deposit names an exclusive relayer or window (${a.exclusiveRelayer}, ${a.exclusivityParameter}) \u2014 this module signs plain deposits any relayer may fill`, "policy_refused");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function checkDeadlines(a, nowS) {
|
|
90
|
+
const age = nowS - a.quoteTimestamp;
|
|
91
|
+
if (age < -ACROSS_QUOTE_TIME_AHEAD_S) throw new AcrossRefusal("tx-quote-time", `the quote time is ${-age} s in the future (the deposit reverts)`, "policy_refused");
|
|
92
|
+
if (age > ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S - ACROSS_LANDING_WINDOW_S) {
|
|
93
|
+
throw new AcrossRefusal("tx-quote-time", `the quote time is ${age} s old: the SpokePool takes at most ${ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S} s, with ${ACROSS_LANDING_WINDOW_S} s kept to land`, "quote_expired");
|
|
94
|
+
}
|
|
95
|
+
const left = a.fillDeadline - nowS;
|
|
96
|
+
if (left > ACROSS_FILL_DEADLINE_BUFFER_S - ACROSS_CLOCK_SKEW_S) {
|
|
97
|
+
throw new AcrossRefusal("tx-fill-deadline", `the fill deadline is ${left} s away, past the ${ACROSS_FILL_DEADLINE_BUFFER_S} s the SpokePool allows`, "policy_refused");
|
|
98
|
+
}
|
|
99
|
+
const window = a.fillDeadline - a.quoteTimestamp;
|
|
100
|
+
if (window > ACROSS_MAX_FILL_WINDOW_S) {
|
|
101
|
+
throw new AcrossRefusal("tx-fill-deadline", `the fill deadline is ${window} s after the quote time, more than the ${ACROSS_MAX_FILL_WINDOW_S} s an Across quote gives \u2014 unfilled, the deposit would hold the funds that long before its refund`, "policy_refused");
|
|
102
|
+
}
|
|
103
|
+
if (left < ACROSS_MIN_FILL_WINDOW_S) {
|
|
104
|
+
throw new AcrossRefusal("tx-fill-deadline", `the fill deadline is ${left} s away, under the ${ACROSS_MIN_FILL_WINDOW_S} s a relayer is given \u2014 the deposit would expire into a refund`, "quote_expired");
|
|
105
|
+
}
|
|
106
|
+
if (window < ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S + ACROSS_MIN_FILL_WINDOW_S) {
|
|
107
|
+
throw new AcrossRefusal("tx-fill-deadline", `the fill deadline is ${window} s after the quote time: a deposit landing as late as the SpokePool takes it (${ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S} s) would leave a relayer under ${ACROSS_MIN_FILL_WINDOW_S} s`, "policy_refused");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function verifyAcrossDeposit(request, tx) {
|
|
111
|
+
const { route, nowS, maxFeeBps } = checkAcrossRequest(request);
|
|
112
|
+
checkTarget(tx, route);
|
|
113
|
+
const a = decodeAcrossDeposit(tx.data);
|
|
114
|
+
const src = route.input.chain;
|
|
115
|
+
const dst = route.output.chain;
|
|
116
|
+
if (a.depositor !== lower(request.depositor)) {
|
|
117
|
+
throw new AcrossRefusal("tx-depositor", `the deposit is credited to ${a.depositor}, not to the signing account ${lower(request.depositor)} \u2014 the depositor is refunded and can redirect the output`, "recipient_mismatch");
|
|
118
|
+
}
|
|
119
|
+
if (a.recipient !== lower(request.recipient)) throw new AcrossRefusal("tx-recipient", `the deposit pays ${a.recipient}, not the recipient ${lower(request.recipient)}`, "recipient_mismatch");
|
|
120
|
+
if (a.destinationChainId !== BigInt(dst.chainId)) {
|
|
121
|
+
throw new AcrossRefusal("tx-destination", `the deposit is for chain ${a.destinationChainId}, not ${dst.name} (${dst.chainId})`, "recipient_mismatch");
|
|
122
|
+
}
|
|
123
|
+
if (a.inputToken !== route.input.token) throw new AcrossRefusal("tx-input-token", `the deposit takes ${a.inputToken}, the request sends ${route.input.token}${route.input.native ? " (the wrapped native token, for the native coin)" : ""}`, "policy_refused");
|
|
124
|
+
if (a.inputAmount !== request.amount) throw new AcrossRefusal("tx-input-amount", `the deposit takes ${a.inputAmount}, the request sends ${request.amount}`, "policy_refused");
|
|
125
|
+
if (a.outputToken !== route.output.token) throw new AcrossRefusal("tx-output-token", `the deposit pays ${a.outputToken} on ${dst.name}, the request is for ${route.output.token}${route.output.native ? " (the wrapped native token, paid out as the native coin)" : ""}`, "price_check_failed");
|
|
126
|
+
if (a.outputAmount <= 0n) throw new AcrossRefusal("tx-output-amount", "the deposit's output is zero", "price_check_failed");
|
|
127
|
+
if (request.minAmountOut !== void 0 && a.outputAmount < request.minAmountOut) {
|
|
128
|
+
throw new AcrossRefusal("tx-output-amount", `the deposit pays ${a.outputAmount}, under the caller's floor ${request.minAmountOut}`, "price_check_failed");
|
|
129
|
+
}
|
|
130
|
+
if (a.outputAmount > a.inputAmount) {
|
|
131
|
+
throw new AcrossRefusal("tx-output-amount", `the deposit asks relayers for ${a.outputAmount}, more than its ${a.inputAmount} input \u2014 nobody fills it, and the funds wait for a refund`, "price_check_failed");
|
|
132
|
+
}
|
|
133
|
+
const fee = a.inputAmount - a.outputAmount;
|
|
134
|
+
if (fee === 0n) {
|
|
135
|
+
throw new AcrossRefusal("tx-fee", "the deposit leaves relayers no fee \u2014 nobody fills it, and the funds wait for a refund", "price_check_failed");
|
|
136
|
+
}
|
|
137
|
+
const minPpm = acrossMinFeePpm(route);
|
|
138
|
+
if (fee * 1000000n < a.inputAmount * BigInt(minPpm)) {
|
|
139
|
+
throw new AcrossRefusal("tx-fee", `the deposit leaves relayers ${fee} of ${a.inputAmount}, under the ${minPpm}-per-million floor for ${route.asset} from ${src.name} \u2014 relayers do not fill it, and the funds wait for a refund`, "price_check_failed");
|
|
140
|
+
}
|
|
141
|
+
if (fee * 10000n > a.inputAmount * BigInt(maxFeeBps)) {
|
|
142
|
+
throw new AcrossRefusal("tx-fee", `the deposit leaves ${fee} of ${a.inputAmount} as fees, over the ${maxFeeBps} bps cap`, "price_check_failed");
|
|
143
|
+
}
|
|
144
|
+
if (a.message !== "0x") {
|
|
145
|
+
if (a.message.length >= 66 && a.message.slice(0, 66) === ACROSS_V5_MESSAGE_PREFIX) {
|
|
146
|
+
throw new AcrossRefusal("tx-message-v5", "the deposit carries an Across V5 witness message, consumable only through the V5 Gateway", "policy_refused");
|
|
147
|
+
}
|
|
148
|
+
throw new AcrossRefusal("tx-message", `the deposit carries a ${(a.message.length - 2) / 2}-byte message for the destination \u2014 only plain transfers are signed`, "policy_refused");
|
|
149
|
+
}
|
|
150
|
+
checkExclusivity(a);
|
|
151
|
+
checkDeadlines(a, nowS);
|
|
152
|
+
const value = typeof tx.value === "string" && UINT.test(tx.value) ? BigInt(tx.value) : null;
|
|
153
|
+
const wantValue = route.input.native ? a.inputAmount : 0n;
|
|
154
|
+
if (value === null || value !== wantValue) throw new AcrossRefusal("tx-value", `the deposit sends ${String(tx.value)} wei, it must send ${wantValue}`, "policy_refused");
|
|
155
|
+
const approval = tx.approvalAddress;
|
|
156
|
+
if (route.input.native) {
|
|
157
|
+
if (approval !== void 0 && approval !== "") throw new AcrossRefusal("tx-approval", `a native deposit approves nothing, the transaction approves ${String(approval)}`, "vault_mismatch");
|
|
158
|
+
} else if (typeof approval !== "string" || lower(approval) !== src.spokePool) {
|
|
159
|
+
throw new AcrossRefusal("tx-approval", `the deposit approves ${String(approval)}, it must approve the ${src.name} SpokePool ${src.spokePool}`, "vault_mismatch");
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
route,
|
|
163
|
+
args: a,
|
|
164
|
+
deposit: {
|
|
165
|
+
to: src.spokePool,
|
|
166
|
+
data: lower(tx.data),
|
|
167
|
+
value: wantValue.toString(10),
|
|
168
|
+
chainId: src.chainId,
|
|
169
|
+
...route.input.native ? {} : { approvalAddress: src.spokePool }
|
|
170
|
+
},
|
|
171
|
+
fee
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function acrossIntentId(sourceChainId, destChainId, data) {
|
|
175
|
+
return `across:${sourceChainId}:${destChainId}:${keccak256(lower(data)).slice(2, 34)}`;
|
|
176
|
+
}
|
|
177
|
+
function parseAcrossIntentId(intentId) {
|
|
178
|
+
if (typeof intentId !== "string") return null;
|
|
179
|
+
const m = /^across:([1-9]\d{0,15}):([1-9]\d{0,15}):([0-9a-f]{32})(?:~[0-9a-f]{32})?$/.exec(intentId);
|
|
180
|
+
if (!m) return null;
|
|
181
|
+
return { sourceChainId: Number(m[1]), destChainId: Number(m[2]), digest: m[3] };
|
|
182
|
+
}
|
|
183
|
+
function isAcrossSpeedUpTypedData(typedData) {
|
|
184
|
+
let v = typedData;
|
|
185
|
+
if (typeof v === "string") {
|
|
186
|
+
try {
|
|
187
|
+
v = JSON.parse(v);
|
|
188
|
+
} catch {
|
|
189
|
+
return /UpdateDepositDetails|ACROSS-V2/.test(v);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (v === null || typeof v !== "object") return false;
|
|
193
|
+
const t = v;
|
|
194
|
+
if (t.primaryType === ACROSS_SPEED_UP_TYPE) return true;
|
|
195
|
+
if (t.types !== null && typeof t.types === "object" && Object.prototype.hasOwnProperty.call(t.types, ACROSS_SPEED_UP_TYPE)) return true;
|
|
196
|
+
return t.domain !== null && typeof t.domain === "object" && t.domain.name === ACROSS_SPEED_UP_DOMAIN;
|
|
197
|
+
}
|
|
198
|
+
function checkAcrossTxShape(tx) {
|
|
199
|
+
if (tx.typedData !== void 0) {
|
|
200
|
+
if (isAcrossSpeedUpTypedData(tx.typedData)) throw new AcrossRefusal("speed-up", "the request is an Across speed-up signature, which can redirect a deposit's output \u2014 never signed", "policy_refused");
|
|
201
|
+
throw new AcrossRefusal("tx-shape", "an Across deposit is one EVM call, not typed data", "policy_refused");
|
|
202
|
+
}
|
|
203
|
+
if (tx.serializedTx !== void 0 || tx.memo !== void 0 || tx.bodyBoc !== void 0 || tx.stateInitBoc !== void 0 || tx.orderExtension !== void 0) {
|
|
204
|
+
throw new AcrossRefusal("tx-shape", "an Across deposit is one EVM call", "policy_refused");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function acrossRefusalReason(err) {
|
|
208
|
+
if (err instanceof AcrossRefusal) return err.message;
|
|
209
|
+
throw err;
|
|
210
|
+
}
|
|
211
|
+
function acrossRequestOf(params, opts = {}) {
|
|
212
|
+
const invalid = (what, reason) => {
|
|
213
|
+
throw new AcrossRefusal("request-invalid", what, reason);
|
|
214
|
+
};
|
|
215
|
+
if (params === null || typeof params !== "object") invalid("no request");
|
|
216
|
+
if (params.flex) invalid("the amount is part of the deposit (no flexible deposits)", "unsupported_pair");
|
|
217
|
+
if (!acrossChain(params.sourceChain)) throw new AcrossRefusal("chain-unsupported", `source chain ${String(params.sourceChain)} is not a pinned Across chain`, "unsupported_pair");
|
|
218
|
+
if (!acrossChain(params.destChain)) throw new AcrossRefusal("chain-unsupported", `destination chain ${String(params.destChain)} is not a pinned Across chain`, "unsupported_pair");
|
|
219
|
+
if (params.sourceChain === params.destChain) throw new AcrossRefusal("chain-unsupported", "same-chain swaps are not served through a SpokePool", "unsupported_pair");
|
|
220
|
+
let sourceToken;
|
|
221
|
+
if (typeof params.sourceToken === "string" && ADDRESS.test(params.sourceToken)) sourceToken = params.sourceToken;
|
|
222
|
+
else {
|
|
223
|
+
const asset = sourceAssetOf(params);
|
|
224
|
+
if (!asset) invalid(`source token ${String(params.sourceToken)} is not known on ${params.sourceChain}`, "unsupported_pair");
|
|
225
|
+
sourceToken = asset.contract ?? ACROSS_NATIVE;
|
|
226
|
+
if (!ADDRESS.test(sourceToken)) invalid(`source token ${String(params.sourceToken)} has no EVM contract`, "unsupported_pair");
|
|
227
|
+
}
|
|
228
|
+
if (typeof params.destToken !== "string" || !ADDRESS.test(params.destToken)) invalid("the destination token must be an EVM address (zero for the native coin)", "unsupported_pair");
|
|
229
|
+
const route = acrossRouteOf(params.sourceChain, sourceToken, params.destChain, params.destToken);
|
|
230
|
+
if ("code" in route) throw new AcrossRefusal(route.code, route.detail, "unsupported_pair");
|
|
231
|
+
const unpriced = acrossRouteUnpriced(route);
|
|
232
|
+
if (unpriced) throw new AcrossRefusal("route-unpriced", unpriced, "unsupported_pair");
|
|
233
|
+
if (typeof params.amountIn !== "string" || !/^[1-9]\d{0,77}$/.test(params.amountIn)) invalid("amount must be a positive base-unit integer");
|
|
234
|
+
if (params.minAmountOut !== void 0 && !UINT.test(params.minAmountOut)) invalid("the output floor must be a base-unit integer");
|
|
235
|
+
const recipient = params.destAddress || opts.placeholder || "";
|
|
236
|
+
if (!recipient) invalid("a live quote needs a recipient");
|
|
237
|
+
if (!ADDRESS.test(recipient)) invalid("the recipient must be an EVM address");
|
|
238
|
+
const sender = params.sender || "";
|
|
239
|
+
const refund = params.refundAddress || "";
|
|
240
|
+
if (sender && !ADDRESS.test(sender)) invalid("the signing account (sender) must be an EVM address");
|
|
241
|
+
if (refund && !ADDRESS.test(refund)) invalid("the refund address must be an EVM address");
|
|
242
|
+
if (sender && refund && lower(sender) !== lower(refund)) {
|
|
243
|
+
throw new AcrossRefusal("request-invalid", `an Across deposit refunds its depositor, the signing account ${lower(sender)}: refund address ${lower(refund)} is another account, and as the depositor it could also sign a speed-up that re-points the output`, "recipient_mismatch");
|
|
244
|
+
}
|
|
245
|
+
const depositor = sender || (opts.placeholder ? refund || opts.placeholder : "");
|
|
246
|
+
if (!depositor) invalid("a live quote needs the signing account (sender)");
|
|
247
|
+
if (!ADDRESS.test(depositor)) invalid("the depositor must be an EVM address");
|
|
248
|
+
return {
|
|
249
|
+
sourceChain: params.sourceChain,
|
|
250
|
+
destChain: params.destChain,
|
|
251
|
+
sourceToken,
|
|
252
|
+
destToken: params.destToken,
|
|
253
|
+
amount: BigInt(params.amountIn),
|
|
254
|
+
depositor,
|
|
255
|
+
recipient,
|
|
256
|
+
...params.minAmountOut !== void 0 ? { minAmountOut: BigInt(params.minAmountOut) } : {},
|
|
257
|
+
...opts.maxFeeBps !== void 0 ? { maxFeeBps: opts.maxFeeBps } : {},
|
|
258
|
+
...opts.nowMs !== void 0 ? { nowMs: opts.nowMs } : {}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function acrossQuoteFeesOf(route, fee) {
|
|
262
|
+
const usd = route.asset === "USDC" || route.asset === "USDT";
|
|
263
|
+
return {
|
|
264
|
+
feeUsd: usd ? bigintToUnits(fee, route.input.decimals) : 0,
|
|
265
|
+
fees: fee > 0n ? [{ type: "protocol", amount: fee.toString(10), token: route.input.native ? ACROSS_NATIVE : route.input.token, included: true, description: "Across relayer and LP fee" }] : []
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function checkAcrossQuote(request, quote, tx) {
|
|
269
|
+
if (quote === null || typeof quote !== "object" || quote.provider !== "across") throw new AcrossRefusal("quote-shape", "not an Across quote", "policy_refused");
|
|
270
|
+
const t = tx ?? quote.txRequest;
|
|
271
|
+
if (!t) throw new AcrossRefusal("quote-shape", "the quote has no transaction", "policy_refused");
|
|
272
|
+
if (quote.depositAddress) throw new AcrossRefusal("quote-shape", "an Across quote pays the SpokePool through its calldata, never a deposit address", "vault_mismatch");
|
|
273
|
+
const extra = quote.txRequest;
|
|
274
|
+
if (extra?.serializedTx !== void 0 || extra?.nativeFee !== void 0) {
|
|
275
|
+
throw new AcrossRefusal("quote-shape", "an Across deposit carries no extra native fee and no serialized transaction", "policy_refused");
|
|
276
|
+
}
|
|
277
|
+
const v = verifyAcrossDeposit(request, t);
|
|
278
|
+
if (quote.sourceAmount !== v.args.inputAmount.toString(10) || quote.minDestAmount !== v.args.outputAmount.toString(10) || quote.destAmount !== v.args.outputAmount.toString(10) || quote.destDecimals !== v.route.output.decimals) {
|
|
279
|
+
throw new AcrossRefusal("quote-amounts", "the amounts the quote shows are not the deposit's", "price_check_failed");
|
|
280
|
+
}
|
|
281
|
+
const shown = acrossQuoteFeesOf(v.route, v.fee);
|
|
282
|
+
const w = shown.fees[0];
|
|
283
|
+
const g = Array.isArray(quote.fees) && quote.fees.length === 1 ? quote.fees[0] : void 0;
|
|
284
|
+
if (!g || g.type !== w.type || g.amount !== w.amount || typeof g.token !== "string" || lower(g.token) !== w.token || g.included !== true || quote.feeUsd !== shown.feeUsd) {
|
|
285
|
+
throw new AcrossRefusal("quote-amounts", `the fees the quote shows are not the deposit's fee of ${v.fee} (the engine's fee caps read them)`, "price_check_failed");
|
|
286
|
+
}
|
|
287
|
+
const gas = t.gasLimit;
|
|
288
|
+
if (gas !== void 0) {
|
|
289
|
+
if (typeof gas !== "string" || !/^[1-9]\d{0,10}$/.test(gas) || BigInt(gas) < ACROSS_GAS_FLOOR || BigInt(gas) > ACROSS_GAS_CAP) {
|
|
290
|
+
throw new AcrossRefusal("quote-gas", `the gas limit ${String(gas).slice(0, 40)} is outside ${ACROSS_GAS_FLOOR}\u2013${ACROSS_GAS_CAP}`, "policy_refused");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const now = request.nowMs ?? Date.now();
|
|
294
|
+
if (typeof quote.validUntilMs !== "number" || !Number.isFinite(quote.validUntilMs) || quote.validUntilMs > now + ACROSS_MAX_QUOTE_LIFE_MS) {
|
|
295
|
+
throw new AcrossRefusal("quote-expiry", "the quote claims to live longer than an Across quote may", "policy_refused");
|
|
296
|
+
}
|
|
297
|
+
if (quote.validUntilMs > acrossQuoteTimeLimitMs(v.args.quoteTimestamp)) {
|
|
298
|
+
throw new AcrossRefusal("quote-expiry", `the quote claims to live past ${ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S - ACROSS_LANDING_WINDOW_S} s after its quote time \u2014 signed then, the deposit would revert on it`, "policy_refused");
|
|
299
|
+
}
|
|
300
|
+
const intent = parseAcrossIntentId(quote.intentId);
|
|
301
|
+
const want = acrossIntentId(v.route.input.chain.chainId, v.route.output.chain.chainId, v.deposit.data);
|
|
302
|
+
if (!intent || `across:${intent.sourceChainId}:${intent.destChainId}:${intent.digest}` !== want) {
|
|
303
|
+
throw new AcrossRefusal("quote-intent", "the quote's id does not name its deposit", "policy_refused");
|
|
304
|
+
}
|
|
305
|
+
return v;
|
|
306
|
+
}
|
|
307
|
+
var pinNotes = refusalNotes();
|
|
308
|
+
function notedReason(err) {
|
|
309
|
+
const text = acrossRefusalReason(err);
|
|
310
|
+
const info = refusalOf(err);
|
|
311
|
+
return info ? pinNotes.note(text, info) : text;
|
|
312
|
+
}
|
|
313
|
+
var acrossPinsRequestOf = (params, cap = {}) => acrossRequestOf(params, params.dry !== false ? { ...cap, placeholder: ACROSS_PLACEHOLDER } : cap);
|
|
314
|
+
function verifyQuoteWith(params, quote, cap) {
|
|
315
|
+
try {
|
|
316
|
+
checkAcrossQuote(acrossPinsRequestOf(params, cap), quote);
|
|
317
|
+
return null;
|
|
318
|
+
} catch (err) {
|
|
319
|
+
return notedReason(err);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function acrossCheckBuild(quote, tx, params, cap = {}) {
|
|
323
|
+
if (!params) throw new AcrossRefusal("request-invalid", "the request this quote answered is not known on this side \u2014 quote again", "policy_refused");
|
|
324
|
+
if (tx.chain !== params.sourceChain) throw new AcrossRefusal("tx-chain", `the build is for ${tx.chain}, not ${params.sourceChain}`, "vault_mismatch");
|
|
325
|
+
checkAcrossTxShape(tx);
|
|
326
|
+
return checkAcrossQuote(acrossRequestOf(params, cap), quote, tx);
|
|
327
|
+
}
|
|
328
|
+
function verifyBuildWith(quote, tx, params, cap) {
|
|
329
|
+
try {
|
|
330
|
+
acrossCheckBuild(quote, tx, params, cap);
|
|
331
|
+
return null;
|
|
332
|
+
} catch (err) {
|
|
333
|
+
return notedReason(err);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function acrossVerifyQuote(params, quote) {
|
|
337
|
+
return verifyQuoteWith(params, quote, {});
|
|
338
|
+
}
|
|
339
|
+
function acrossVerifyBuild(quote, tx, params) {
|
|
340
|
+
return verifyBuildWith(quote, tx, params, {});
|
|
341
|
+
}
|
|
342
|
+
function acrossPinsWith(opts = {}) {
|
|
343
|
+
const maxFeeBps = opts.maxFeeBps;
|
|
344
|
+
if (maxFeeBps !== void 0 && (!Number.isInteger(maxFeeBps) || maxFeeBps < 0 || maxFeeBps > ACROSS_MAX_FEE_BPS_LIMIT)) {
|
|
345
|
+
throw new Error(`across: maxFeeBps must be an integer between 0 and ${ACROSS_MAX_FEE_BPS_LIMIT}`);
|
|
346
|
+
}
|
|
347
|
+
const cap = Object.freeze(maxFeeBps !== void 0 ? { maxFeeBps } : {});
|
|
348
|
+
return Object.freeze({
|
|
349
|
+
callTargets: (chain) => {
|
|
350
|
+
const c = acrossChain(chain);
|
|
351
|
+
return c ? [c.spokePool] : [];
|
|
352
|
+
},
|
|
353
|
+
spenders: (chain) => {
|
|
354
|
+
const c = acrossChain(chain);
|
|
355
|
+
return c ? [c.spokePool] : [];
|
|
356
|
+
},
|
|
357
|
+
verifyQuote: (params, quote) => verifyQuoteWith(params, quote, cap),
|
|
358
|
+
verifyBuild: (quote, tx, params) => verifyBuildWith(quote, tx, params, cap),
|
|
359
|
+
reasonOf: pinNotes.reasonOf
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
var acrossPins = acrossPinsWith();
|
|
363
|
+
|
|
364
|
+
export {
|
|
365
|
+
ACROSS_DEFAULT_MAX_FEE_BPS,
|
|
366
|
+
ACROSS_MAX_FEE_BPS_LIMIT,
|
|
367
|
+
ACROSS_CLOCK_SKEW_S,
|
|
368
|
+
ACROSS_QUOTE_TIME_AHEAD_S,
|
|
369
|
+
ACROSS_LANDING_WINDOW_S,
|
|
370
|
+
ACROSS_MIN_FILL_WINDOW_S,
|
|
371
|
+
ACROSS_MAX_FILL_WINDOW_S,
|
|
372
|
+
ACROSS_MIN_FEE_PPM,
|
|
373
|
+
acrossMinFeePpm,
|
|
374
|
+
ACROSS_GAS_FLOOR,
|
|
375
|
+
ACROSS_GAS_CAP,
|
|
376
|
+
ACROSS_MAX_QUOTE_LIFE_MS,
|
|
377
|
+
acrossQuoteTimeLimitMs,
|
|
378
|
+
ACROSS_PLACEHOLDER,
|
|
379
|
+
checkAcrossRequest,
|
|
380
|
+
verifyAcrossDeposit,
|
|
381
|
+
acrossIntentId,
|
|
382
|
+
parseAcrossIntentId,
|
|
383
|
+
isAcrossSpeedUpTypedData,
|
|
384
|
+
checkAcrossTxShape,
|
|
385
|
+
acrossRefusalReason,
|
|
386
|
+
acrossRequestOf,
|
|
387
|
+
acrossQuoteFeesOf,
|
|
388
|
+
checkAcrossQuote,
|
|
389
|
+
acrossPinsRequestOf,
|
|
390
|
+
acrossCheckBuild,
|
|
391
|
+
acrossVerifyQuote,
|
|
392
|
+
acrossVerifyBuild,
|
|
393
|
+
acrossPinsWith,
|
|
394
|
+
acrossPins
|
|
395
|
+
};
|
|
396
|
+
//# sourceMappingURL=chunk-KATEONJQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/verify.ts"],"sourcesContent":["/**\n * The device-side check of an Across deposit.\n *\n * An Across deposit is one call, `deposit(...)` on the source chain's SpokePool, and unlike an order-hash deposit its\n * calldata says everything: who is refunded (`depositor`), who is paid (`recipient`), in which token and how much on\n * which chain (`outputToken`, `outputAmount`, `destinationChainId`), by when (`fillDeadline`), and what runs on arrival\n * (`message`). Relayers pay the recipient `outputAmount` of `outputToken` on the destination out of their own funds and\n * are repaid from the deposit; an unfilled deposit is refunded to `depositor` on the source chain after the fill\n * deadline. The SpokePool itself checks almost none of it — no route list, no token pairing, `depositor` not bound\n * to the sender (SpokePool.sol `_depositV3`) — so {@link verifyAcrossDeposit} holds every field to the user's own\n * request and to the pins in `config.ts`, with nothing but the transaction about to be signed:\n *\n * 1. the call is `deposit` on the pinned SpokePool of the source chain, for that chain id, in its canonical encoding;\n * 2. `depositor` is the account that signs and `recipient` the user's recipient; the destination is the requested\n * pinned chain;\n * 3. the input is the pinned token for the request (the wrapped native token, with exactly the amount as value, for\n * the native coin; value 0 and an approval of the SpokePool for an ERC-20), exactly the requested amount;\n * 4. the output is the same asset on the destination (the wrapped native token for the native coin, which the\n * destination SpokePool unwraps for an EOA), at least the caller's floor, and the fee it leaves (input − output)\n * between a floor relayers can be paid with and the cap — a deposit asking relayers for all of its input or more\n * is never filled;\n * 5. the message is empty — the Across V5 witness prefix refused by name — so the tokens land on the recipient and\n * nothing runs;\n * 6. the deadlines are ones the SpokePool accepts and a relayer can still meet, wherever the deposit lands: a quote\n * time not ahead of now (the SpokePool reverts one ahead of its block) and no older than its on-chain buffer\n * allows (with a margin to land); a fill deadline no further from the quote time than an Across quote puts it (so\n * an unfilled deposit holds the funds no longer than that before its refund), and still a fill window away from\n * the last moment the SpokePool takes the deposit (the quote time + 3600 s: nothing on chain refuses a deposit that\n * lands after its own fill deadline); no exclusive relayer (this module never names one).\n *\n * Every refusal is an {@link AcrossRefusal} with its own code. Nothing here is asynchronous and nothing reads the\n * network, so the same function runs when a quote is built, again right before signing, and on the client of a\n * remote provider (`acrossPins.verifyQuote` / `verifyBuild`).\n */\nimport {keccak256, type Hex} from \"viem\";\nimport {bigintToUnits} from \"@anywalletkit/core\";\nimport type {Quote, QuoteParams, RemotePins, UnsignedTx} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {refusalNotes, refusalOf, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {\n ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S, ACROSS_FILL_DEADLINE_BUFFER_S, ACROSS_NATIVE, ACROSS_SPEED_UP_DOMAIN, ACROSS_SPEED_UP_TYPE,\n ACROSS_V5_MESSAGE_PREFIX, acrossChain, acrossRouteOf, type AcrossRoute,\n} from \"./config.js\";\nimport {decodeAcrossDeposit, type AcrossDepositArgs} from \"./deposit.js\";\nimport {ACROSS_FLOOR_ORIGINS, acrossRouteUnpriced} from \"./pricing.js\";\nimport {AcrossRefusal} from \"./refusal.js\";\n\n/** The fee cap when the caller names none: input − output at most 10 % of the input. */\nexport const ACROSS_DEFAULT_MAX_FEE_BPS = 1_000;\n/** The widest fee cap a request may ask for (the Across API's own default `maxFee.bps`). */\nexport const ACROSS_MAX_FEE_BPS_LIMIT = 5_000;\n/** Tolerated difference between the device clock and the chains'. */\nexport const ACROSS_CLOCK_SKEW_S = 120;\n/**\n * How far ahead of the device's clock a quote time may sit: the SpokePool reverts a deposit whose quote time is ahead\n * of its block, and an honest one is a HubPool block time minutes in the past (or the latest Ethereum block − 60 s),\n * so this only absorbs a device clock that runs slow.\n */\nexport const ACROSS_QUOTE_TIME_AHEAD_S = 15;\n/**\n * Time a deposit is given to land after this check. The quote time must leave at least this much of its on-chain\n * buffer (`depositQuoteTimeBuffer`, 3600 s), or the deposit reverts on the way.\n */\nexport const ACROSS_LANDING_WINDOW_S = 300;\n/** The fill deadline must leave relayers at least this long, counted from the last moment the deposit can land. */\nexport const ACROSS_MIN_FILL_WINDOW_S = 1_800;\n/**\n * The furthest a fill deadline may sit from the quote time: two hours, as Across's API puts it on every quote\n * (`fillDeadline = quoteTimestamp + 7200` on every V4 quote and API deposit read 2026-11-14), and ten minutes of margin.\n * An unfilled deposit holds the funds until then, and its refund comes after (Across's settlement bundles).\n */\nexport const ACROSS_MAX_FILL_WINDOW_S = 7_800;\n/**\n * The smallest fee a deposit may leave relayers, in millionths of the input, by what is bridged and from where. A\n * relayer pays the output from its own funds and its gas, so a deposit that leaves less than relayers take is not\n * filled and waits two hours for its deadline and then for a refund — while its output, nearly the whole input, would\n * win any comparison of routes. The floors sit at or under the lowest fees plain deposits were filled at over 24 h\n * (2026-11-14, Ethereum, Optimism, Base and Arbitrum): stablecoins 1.0 bp (Across's capital fee, every fill paid it),\n * ETH from Ethereum 0.7 bp (fills at 0.74–0.84), ETH from Optimism, Base or Arbitrum 4.5 bps (capital 3.0+ and LP\n * 1.77 from those origins: fills at 5.0 and up), WBTC 2.5 bps (fills at 3.1; one at 1.03). ETH from any other L2 is\n * 0.7 bp, the lowest any plain ETH deposit was filled at: Across's own relayer quote prices those origins far lower\n * than the studied ones (Linea → Base 1.27 bps, Ink → Base 2.71 bps, live 2026-11-15) and is what prices them, on the\n * server and on the device, so the floor there only refuses dust. A server that names less — a bug, or a hostile one\n * — is refused here, on the device.\n */\nexport const ACROSS_MIN_FEE_PPM = Object.freeze({stable: 100, ethFromEthereum: 70, ethFromL2: 450, ethFromOtherL2: 70, wbtc: 250});\n\n/** The device's fee floor for a route, millionths of the input ({@link ACROSS_MIN_FEE_PPM}). */\nexport function acrossMinFeePpm(route: AcrossRoute): number {\n if (route.asset === \"ETH\") {\n const src = route.input.chain.chainId;\n if (src === 1) return ACROSS_MIN_FEE_PPM.ethFromEthereum;\n return ACROSS_FLOOR_ORIGINS.includes(src) ? ACROSS_MIN_FEE_PPM.ethFromL2 : ACROSS_MIN_FEE_PPM.ethFromOtherL2;\n }\n if (route.asset === \"WBTC\") return ACROSS_MIN_FEE_PPM.wbtc;\n return ACROSS_MIN_FEE_PPM.stable;\n}\n/** A direct deposit used ~85k gas in Across's own estimate (2026-11-14); a gas limit under this is a paid revert. */\nexport const ACROSS_GAS_FLOOR = 90_000n;\n/** Chains that meter gas differently (zkSync) estimate far higher; a stated limit is taken up to this. */\nexport const ACROSS_GAS_CAP = 60_000_000n;\n/** The longest a quote may claim to live: five minutes plus the clock difference. */\nexport const ACROSS_MAX_QUOTE_LIFE_MS = 300_000 + ACROSS_CLOCK_SKEW_S * 1000;\n/** The latest a quote with this quote time may be signed (ms): while the SpokePool still takes it, with time to land. */\nexport const acrossQuoteTimeLimitMs = (quoteTimestamp: number): number => (quoteTimestamp + ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S - ACROSS_LANDING_WINDOW_S) * 1000;\n\n/**\n * The address a dry quote (pricing only) is asked for when the caller names none. A quote priced with it is never\n * built or signed; the server and a remote client derive the same request from the same parameters with it.\n */\nexport const ACROSS_PLACEHOLDER = \"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\";\n\nconst ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst ZERO = /^0x0{40}$/;\nconst U256_MAX = (1n << 256n) - 1n;\nconst UINT = /^(?:0|[1-9]\\d{0,77})$/;\n\n/** What the user asked for — the only thing a deposit is compared against. Addresses in any casing. */\nexport interface AcrossRequest {\n /** CAIP-2 of the chain the deposit is sent on. */\n sourceChain: string;\n /** CAIP-2 of the chain the output is paid on. */\n destChain: string;\n /** Input token contract; the zero address is the native coin. */\n sourceToken: string;\n /** Output token contract; the zero address is the native coin. */\n destToken: string;\n /** Exact input, base units. */\n amount: bigint;\n /** The account that signs the deposit: its `depositor` (refunds, and the only key that can sign a speed-up). */\n depositor: string;\n /** Who receives the output. */\n recipient: string;\n /** The caller's own floor on the output, base units. */\n minAmountOut?: bigint;\n /** Fee cap in bps of the input (default {@link ACROSS_DEFAULT_MAX_FEE_BPS}). */\n maxFeeBps?: number;\n /** The clock (ms) deadlines are judged against; defaults to `Date.now()`. */\n nowMs?: number;\n}\n\n/** The deposit transaction under check: what is about to be signed, or what a quote carries. */\nexport interface AcrossDepositTx {\n to?: unknown;\n data?: unknown;\n value?: unknown;\n chainId?: unknown;\n approvalAddress?: unknown;\n}\n\n/** A deposit that passed the checks: the only shape of call this module signs. */\nexport interface AcrossDeposit {\n /** The pinned SpokePool, lowercase. */\n to: string;\n /** The canonical calldata, lowercase. */\n data: Hex;\n /** Wei, decimal: the input amount for the native coin, else \"0\". */\n value: string;\n chainId: number;\n /** ERC-20 input: the spender to approve for exactly the input amount — the pinned SpokePool. */\n approvalAddress?: string;\n}\n\nexport interface VerifiedAcrossDeposit {\n route: AcrossRoute;\n args: AcrossDepositArgs;\n deposit: AcrossDeposit;\n /** input − output, in the input token's base units (both sides have the same decimals). */\n fee: bigint;\n}\n\nconst lower = (s: string): string => s.toLowerCase();\n\n/** A request that passed {@link checkAcrossRequest}: its route, the clock it is judged by, its fee cap. */\nexport interface CheckedAcrossRequest {\n route: AcrossRoute;\n nowS: number;\n maxFeeBps: number;\n}\n\n/** The request's own sanity and its route (pinned chains, same asset); throws {@link AcrossRefusal}. */\nexport function checkAcrossRequest(r: AcrossRequest): CheckedAcrossRequest {\n // A malformed request is the caller's own bug and carries no reason; the zero-address parties and the route are refusals.\n const invalid = (what: string, reason?: Swap2RefusalReason): never => { throw new AcrossRefusal(\"request-invalid\", what, reason); };\n if (r === null || typeof r !== \"object\") invalid(\"no request to check the deposit against\");\n for (const [what, v] of [[\"input token\", r.sourceToken], [\"output token\", r.destToken], [\"depositor\", r.depositor], [\"recipient\", r.recipient]] as const) {\n if (typeof v !== \"string\" || !ADDRESS.test(v)) invalid(`the ${what} is not an address`);\n }\n const route = acrossRouteOf(r.sourceChain, r.sourceToken, r.destChain, r.destToken);\n if (\"code\" in route) throw new AcrossRefusal(route.code, route.detail, \"unsupported_pair\");\n if (ZERO.test(r.depositor)) invalid(\"the depositor is the zero address\", \"recipient_mismatch\");\n if (ZERO.test(r.recipient)) invalid(\"the recipient is the zero address\", \"recipient_mismatch\");\n if (typeof r.amount !== \"bigint\" || r.amount <= 0n || r.amount > U256_MAX) invalid(\"the amount is not a positive integer\");\n if (r.minAmountOut !== undefined && (typeof r.minAmountOut !== \"bigint\" || r.minAmountOut < 0n || r.minAmountOut > U256_MAX)) invalid(\"the output floor is not an unsigned integer\");\n const maxFeeBps = r.maxFeeBps ?? ACROSS_DEFAULT_MAX_FEE_BPS;\n if (!Number.isInteger(maxFeeBps) || maxFeeBps < 0 || maxFeeBps > ACROSS_MAX_FEE_BPS_LIMIT) {\n invalid(`the fee cap must be a whole number of basis points up to ${ACROSS_MAX_FEE_BPS_LIMIT}`, \"policy_refused\");\n }\n const nowMs = r.nowMs ?? Date.now();\n if (!Number.isFinite(nowMs) || nowMs <= 0) invalid(\"the clock is not a time\");\n return {route, nowS: Math.floor(nowMs / 1000), maxFeeBps};\n}\n\n/** Where the deposit goes: the pinned SpokePool of the source chain, and nothing else. Checked before the calldata is read. */\nfunction checkTarget(tx: AcrossDepositTx, route: AcrossRoute): void {\n if (tx === null || typeof tx !== \"object\") throw new AcrossRefusal(\"tx-shape\", \"there is no deposit transaction\", \"policy_refused\");\n const src = route.input.chain;\n if (tx.chainId !== src.chainId) throw new AcrossRefusal(\"tx-chain\", `the deposit is for chain ${String(tx.chainId)}, not ${src.name} (${src.chainId})`, \"vault_mismatch\");\n if (typeof tx.to !== \"string\" || !ADDRESS.test(tx.to) || lower(tx.to) !== src.spokePool) {\n throw new AcrossRefusal(\"tx-target\", `the deposit calls ${String(tx.to)}, not the ${src.name} SpokePool ${src.spokePool} — periphery, swap and CCTP / OFT routes are not signed by this module`, \"vault_mismatch\");\n }\n}\n\n/**\n * No exclusivity. This module builds every deposit without an exclusive relayer; one named by a quote source would\n * be the only one allowed to fill for its window (a deposit nobody else may fill for up to an hour, or a fee kept for\n * the relayer the source chose), and nothing this module prices calls for one.\n */\nfunction checkExclusivity(a: AcrossDepositArgs): void {\n if (!ZERO.test(a.exclusiveRelayer) || a.exclusivityParameter !== 0) {\n throw new AcrossRefusal(\"tx-exclusivity\", `the deposit names an exclusive relayer or window (${a.exclusiveRelayer}, ${a.exclusivityParameter}) — this module signs plain deposits any relayer may fill`, \"policy_refused\");\n }\n}\n\n/**\n * The deadlines: what the SpokePool accepts, with room for the deposit to land and for a relayer to fill wherever it\n * lands, and no longer a hold on the funds than an Across quote sets.\n */\nfunction checkDeadlines(a: AcrossDepositArgs, nowS: number): void {\n const age = nowS - a.quoteTimestamp;\n if (age < -ACROSS_QUOTE_TIME_AHEAD_S) throw new AcrossRefusal(\"tx-quote-time\", `the quote time is ${-age} s in the future (the deposit reverts)`, \"policy_refused\");\n if (age > ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S - ACROSS_LANDING_WINDOW_S) {\n throw new AcrossRefusal(\"tx-quote-time\", `the quote time is ${age} s old: the SpokePool takes at most ${ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S} s, with ${ACROSS_LANDING_WINDOW_S} s kept to land`, \"quote_expired\");\n }\n const left = a.fillDeadline - nowS;\n if (left > ACROSS_FILL_DEADLINE_BUFFER_S - ACROSS_CLOCK_SKEW_S) {\n throw new AcrossRefusal(\"tx-fill-deadline\", `the fill deadline is ${left} s away, past the ${ACROSS_FILL_DEADLINE_BUFFER_S} s the SpokePool allows`, \"policy_refused\");\n }\n const window = a.fillDeadline - a.quoteTimestamp;\n if (window > ACROSS_MAX_FILL_WINDOW_S) {\n throw new AcrossRefusal(\"tx-fill-deadline\", `the fill deadline is ${window} s after the quote time, more than the ${ACROSS_MAX_FILL_WINDOW_S} s an Across quote gives — unfilled, the deposit would hold the funds that long before its refund`, \"policy_refused\");\n }\n if (left < ACROSS_MIN_FILL_WINDOW_S) {\n throw new AcrossRefusal(\"tx-fill-deadline\", `the fill deadline is ${left} s away, under the ${ACROSS_MIN_FILL_WINDOW_S} s a relayer is given — the deposit would expire into a refund`, \"quote_expired\");\n }\n // `_depositV3` has no lower bound on the fill deadline: a deposit that waits to be mined lands, expired, as late as\n // its quote time + `depositQuoteTimeBuffer`. The deadline must leave a relayer its window even then.\n if (window < ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S + ACROSS_MIN_FILL_WINDOW_S) {\n throw new AcrossRefusal(\"tx-fill-deadline\", `the fill deadline is ${window} s after the quote time: a deposit landing as late as the SpokePool takes it (${ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S} s) would leave a relayer under ${ACROSS_MIN_FILL_WINDOW_S} s`, \"policy_refused\");\n }\n}\n\n/**\n * Check a deposit transaction against the user's request and the pins. Returns the decoded arguments, the route and\n * the deposit as it will be signed; throws {@link AcrossRefusal} otherwise.\n */\nexport function verifyAcrossDeposit(request: AcrossRequest, tx: AcrossDepositTx): VerifiedAcrossDeposit {\n const {route, nowS, maxFeeBps} = checkAcrossRequest(request);\n checkTarget(tx, route);\n const a = decodeAcrossDeposit(tx.data);\n const src = route.input.chain;\n const dst = route.output.chain;\n\n // Who: the deposit is credited (and refunded) to the account that signs, and pays the recipient.\n if (a.depositor !== lower(request.depositor)) {\n throw new AcrossRefusal(\"tx-depositor\", `the deposit is credited to ${a.depositor}, not to the signing account ${lower(request.depositor)} — the depositor is refunded and can redirect the output`, \"recipient_mismatch\");\n }\n if (a.recipient !== lower(request.recipient)) throw new AcrossRefusal(\"tx-recipient\", `the deposit pays ${a.recipient}, not the recipient ${lower(request.recipient)}`, \"recipient_mismatch\");\n if (a.destinationChainId !== BigInt(dst.chainId)) {\n throw new AcrossRefusal(\"tx-destination\", `the deposit is for chain ${a.destinationChainId}, not ${dst.name} (${dst.chainId})`, \"recipient_mismatch\");\n }\n\n // What goes in: exactly the requested amount of the pinned token.\n if (a.inputToken !== route.input.token) throw new AcrossRefusal(\"tx-input-token\", `the deposit takes ${a.inputToken}, the request sends ${route.input.token}${route.input.native ? \" (the wrapped native token, for the native coin)\" : \"\"}`, \"policy_refused\");\n if (a.inputAmount !== request.amount) throw new AcrossRefusal(\"tx-input-amount\", `the deposit takes ${a.inputAmount}, the request sends ${request.amount}`, \"policy_refused\");\n\n // What comes out: the same asset, at least the floor, and less than went in by a fee relayers can be paid with.\n if (a.outputToken !== route.output.token) throw new AcrossRefusal(\"tx-output-token\", `the deposit pays ${a.outputToken} on ${dst.name}, the request is for ${route.output.token}${route.output.native ? \" (the wrapped native token, paid out as the native coin)\" : \"\"}`, \"price_check_failed\");\n if (a.outputAmount <= 0n) throw new AcrossRefusal(\"tx-output-amount\", \"the deposit's output is zero\", \"price_check_failed\");\n if (request.minAmountOut !== undefined && a.outputAmount < request.minAmountOut) {\n throw new AcrossRefusal(\"tx-output-amount\", `the deposit pays ${a.outputAmount}, under the caller's floor ${request.minAmountOut}`, \"price_check_failed\");\n }\n if (a.outputAmount > a.inputAmount) {\n throw new AcrossRefusal(\"tx-output-amount\", `the deposit asks relayers for ${a.outputAmount}, more than its ${a.inputAmount} input — nobody fills it, and the funds wait for a refund`, \"price_check_failed\");\n }\n const fee = a.inputAmount - a.outputAmount;\n if (fee === 0n) {\n throw new AcrossRefusal(\"tx-fee\", \"the deposit leaves relayers no fee — nobody fills it, and the funds wait for a refund\", \"price_check_failed\");\n }\n const minPpm = acrossMinFeePpm(route);\n if (fee * 1_000_000n < a.inputAmount * BigInt(minPpm)) {\n throw new AcrossRefusal(\"tx-fee\", `the deposit leaves relayers ${fee} of ${a.inputAmount}, under the ${minPpm}-per-million floor for ${route.asset} from ${src.name} — relayers do not fill it, and the funds wait for a refund`, \"price_check_failed\");\n }\n if (fee * 10_000n > a.inputAmount * BigInt(maxFeeBps)) {\n throw new AcrossRefusal(\"tx-fee\", `the deposit leaves ${fee} of ${a.inputAmount} as fees, over the ${maxFeeBps} bps cap`, \"price_check_failed\");\n }\n\n // Nothing runs on arrival.\n if (a.message !== \"0x\") {\n if (a.message.length >= 66 && a.message.slice(0, 66) === ACROSS_V5_MESSAGE_PREFIX) {\n throw new AcrossRefusal(\"tx-message-v5\", \"the deposit carries an Across V5 witness message, consumable only through the V5 Gateway\", \"policy_refused\");\n }\n throw new AcrossRefusal(\"tx-message\", `the deposit carries a ${(a.message.length - 2) / 2}-byte message for the destination — only plain transfers are signed`, \"policy_refused\");\n }\n\n checkExclusivity(a);\n checkDeadlines(a, nowS);\n\n // The money attached: the input itself for the native coin (the SpokePool wraps it), nothing for an ERC-20.\n const value = typeof tx.value === \"string\" && UINT.test(tx.value) ? BigInt(tx.value) : null;\n const wantValue = route.input.native ? a.inputAmount : 0n;\n if (value === null || value !== wantValue) throw new AcrossRefusal(\"tx-value\", `the deposit sends ${String(tx.value)} wei, it must send ${wantValue}`, \"policy_refused\");\n const approval = tx.approvalAddress;\n if (route.input.native) {\n if (approval !== undefined && approval !== \"\") throw new AcrossRefusal(\"tx-approval\", `a native deposit approves nothing, the transaction approves ${String(approval)}`, \"vault_mismatch\");\n } else if (typeof approval !== \"string\" || lower(approval) !== src.spokePool) {\n throw new AcrossRefusal(\"tx-approval\", `the deposit approves ${String(approval)}, it must approve the ${src.name} SpokePool ${src.spokePool}`, \"vault_mismatch\");\n }\n\n return {\n route,\n args: a,\n deposit: {\n to: src.spokePool,\n data: lower(tx.data as string) as Hex,\n value: wantValue.toString(10),\n chainId: src.chainId,\n ...(route.input.native ? {} : {approvalAddress: src.spokePool}),\n },\n fee,\n };\n}\n\n/** The intent id of a deposit: the route and a digest of the exact calldata (`across:<from>:<to>:<16 bytes hex>`). */\nexport function acrossIntentId(sourceChainId: number, destChainId: number, data: Hex): string {\n return `across:${sourceChainId}:${destChainId}:${keccak256(lower(data) as Hex).slice(2, 34)}`;\n}\n\n/** The route an intent id names (a server's `~<tag>` suffix tolerated), or null. */\nexport function parseAcrossIntentId(intentId: string): {sourceChainId: number; destChainId: number; digest: string} | null {\n if (typeof intentId !== \"string\") return null;\n const m = /^across:([1-9]\\d{0,15}):([1-9]\\d{0,15}):([0-9a-f]{32})(?:~[0-9a-f]{32})?$/.exec(intentId);\n if (!m) return null;\n return {sourceChainId: Number(m[1]), destChainId: Number(m[2]), digest: m[3]!};\n}\n\n/**\n * True for typed data an Across speed-up signature would be made over (`UpdateDepositDetails`, or Across's `ACROSS-V2`\n * domain). A wallet can run this on any signing request; nothing this module builds is ever typed data.\n */\nexport function isAcrossSpeedUpTypedData(typedData: unknown): boolean {\n let v: unknown = typedData;\n if (typeof v === \"string\") {\n try { v = JSON.parse(v); } catch { return /UpdateDepositDetails|ACROSS-V2/.test(v as string); }\n }\n if (v === null || typeof v !== \"object\") return false;\n const t = v as {primaryType?: unknown; types?: unknown; domain?: {name?: unknown} | null};\n if (t.primaryType === ACROSS_SPEED_UP_TYPE) return true;\n if (t.types !== null && typeof t.types === \"object\" && Object.prototype.hasOwnProperty.call(t.types, ACROSS_SPEED_UP_TYPE)) return true;\n return t.domain !== null && typeof t.domain === \"object\" && t.domain.name === ACROSS_SPEED_UP_DOMAIN;\n}\n\n/** The one shape a transaction to sign may have: an EVM call — never typed data, a memo or a serialized transaction. */\nexport function checkAcrossTxShape(tx: UnsignedTx): void {\n if (tx.typedData !== undefined) {\n if (isAcrossSpeedUpTypedData(tx.typedData)) throw new AcrossRefusal(\"speed-up\", \"the request is an Across speed-up signature, which can redirect a deposit's output — never signed\", \"policy_refused\");\n throw new AcrossRefusal(\"tx-shape\", \"an Across deposit is one EVM call, not typed data\", \"policy_refused\");\n }\n if (tx.serializedTx !== undefined || tx.memo !== undefined || tx.bodyBoc !== undefined || tx.stateInitBoc !== undefined || tx.orderExtension !== undefined) {\n throw new AcrossRefusal(\"tx-shape\", \"an Across deposit is one EVM call\", \"policy_refused\");\n }\n}\n\n/** A refusal's text for a caller that wants a string (`onRefusal`, remote pins); rethrows anything else. */\nexport function acrossRefusalReason(err: unknown): string {\n if (err instanceof AcrossRefusal) return err.message;\n throw err;\n}\n\n/**\n * The request a `QuoteParams` describes, for the verifier. `placeholder` (a dry quote: pricing only) fills a missing\n * address.\n *\n * The depositor is `sender`, the account that signs — set by the engine on every execution quote. Across refunds the\n * depositor, and the depositor alone can sign a speed-up that a relayer fills to another recipient or for less\n * (SpokePool.sol `fillRelayWithUpdatedDeposit`, an EIP-712 or EIP-1271 signature of `relayData.depositor`): a refund\n * address the caller names is never made the depositor, and one other than the signer is refused. A live request\n * without `sender` is refused; a dry one is priced for `refundAddress` (or the placeholder).\n */\nexport function acrossRequestOf(params: QuoteParams, opts: {placeholder?: string; nowMs?: number; maxFeeBps?: number} = {}): AcrossRequest {\n const invalid = (what: string, reason?: Swap2RefusalReason): never => { throw new AcrossRefusal(\"request-invalid\", what, reason); };\n if (params === null || typeof params !== \"object\") invalid(\"no request\");\n if (params.flex) invalid(\"the amount is part of the deposit (no flexible deposits)\", \"unsupported_pair\");\n if (!acrossChain(params.sourceChain)) throw new AcrossRefusal(\"chain-unsupported\", `source chain ${String(params.sourceChain)} is not a pinned Across chain`, \"unsupported_pair\");\n if (!acrossChain(params.destChain)) throw new AcrossRefusal(\"chain-unsupported\", `destination chain ${String(params.destChain)} is not a pinned Across chain`, \"unsupported_pair\");\n if (params.sourceChain === params.destChain) throw new AcrossRefusal(\"chain-unsupported\", \"same-chain swaps are not served through a SpokePool\", \"unsupported_pair\");\n let sourceToken: string;\n if (typeof params.sourceToken === \"string\" && ADDRESS.test(params.sourceToken)) sourceToken = params.sourceToken;\n else {\n const asset = sourceAssetOf(params);\n if (!asset) invalid(`source token ${String(params.sourceToken)} is not known on ${params.sourceChain}`, \"unsupported_pair\");\n sourceToken = asset!.contract ?? ACROSS_NATIVE;\n if (!ADDRESS.test(sourceToken)) invalid(`source token ${String(params.sourceToken)} has no EVM contract`, \"unsupported_pair\");\n }\n if (typeof params.destToken !== \"string\" || !ADDRESS.test(params.destToken)) invalid(\"the destination token must be an EVM address (zero for the native coin)\", \"unsupported_pair\");\n const route = acrossRouteOf(params.sourceChain, sourceToken, params.destChain, params.destToken);\n if (\"code\" in route) throw new AcrossRefusal(route.code, route.detail, \"unsupported_pair\");\n const unpriced = acrossRouteUnpriced(route);\n if (unpriced) throw new AcrossRefusal(\"route-unpriced\", unpriced, \"unsupported_pair\");\n if (typeof params.amountIn !== \"string\" || !/^[1-9]\\d{0,77}$/.test(params.amountIn)) invalid(\"amount must be a positive base-unit integer\");\n if (params.minAmountOut !== undefined && !UINT.test(params.minAmountOut)) invalid(\"the output floor must be a base-unit integer\");\n const recipient = params.destAddress || opts.placeholder || \"\";\n if (!recipient) invalid(\"a live quote needs a recipient\");\n if (!ADDRESS.test(recipient)) invalid(\"the recipient must be an EVM address\");\n const sender = params.sender || \"\";\n const refund = params.refundAddress || \"\";\n if (sender && !ADDRESS.test(sender)) invalid(\"the signing account (sender) must be an EVM address\");\n if (refund && !ADDRESS.test(refund)) invalid(\"the refund address must be an EVM address\");\n if (sender && refund && lower(sender) !== lower(refund)) {\n throw new AcrossRefusal(\"request-invalid\", `an Across deposit refunds its depositor, the signing account ${lower(sender)}: refund address ${lower(refund)} is another account, and as the depositor it could also sign a speed-up that re-points the output`, \"recipient_mismatch\");\n }\n const depositor = sender || (opts.placeholder ? refund || opts.placeholder : \"\");\n if (!depositor) invalid(\"a live quote needs the signing account (sender)\");\n if (!ADDRESS.test(depositor)) invalid(\"the depositor must be an EVM address\");\n return {\n sourceChain: params.sourceChain,\n destChain: params.destChain,\n sourceToken,\n destToken: params.destToken,\n amount: BigInt(params.amountIn),\n depositor,\n recipient,\n ...(params.minAmountOut !== undefined ? {minAmountOut: BigInt(params.minAmountOut)} : {}),\n ...(opts.maxFeeBps !== undefined ? {maxFeeBps: opts.maxFeeBps} : {}),\n ...(opts.nowMs !== undefined ? {nowMs: opts.nowMs} : {}),\n };\n}\n\n/**\n * What a quote shows of a deposit's fee: `fees` — exactly one included protocol fee of input − output, in the input\n * token (the zero address for the native coin) — and `feeUsd`, the fee itself for a dollar stablecoin (USDC, USDT, one\n * unit a dollar) and 0 for an asset this module has no price for. The engine's fee caps (`maxProtocolFeeBps`) and the\n * router's scoring read these, so a quote is held to them exactly ({@link checkAcrossQuote}).\n */\nexport function acrossQuoteFeesOf(route: AcrossRoute, fee: bigint): Pick<Quote, \"fees\" | \"feeUsd\"> {\n const usd = route.asset === \"USDC\" || route.asset === \"USDT\";\n return {\n feeUsd: usd ? bigintToUnits(fee, route.input.decimals) : 0,\n fees: fee > 0n ? [{type: \"protocol\", amount: fee.toString(10), token: route.input.native ? ACROSS_NATIVE : route.input.token, included: true, description: \"Across relayer and LP fee\"}] : [],\n };\n}\n\n/**\n * A quote of this provider against the request it answers: its transaction passes {@link verifyAcrossDeposit}, its id\n * names that very calldata, and the amounts it shows are the deposit's (`outputAmount` is what the recipient gets —\n * a relayer pays exactly that), its fees too ({@link acrossQuoteFeesOf}: the engine's fee caps read them), and it\n * claims to live no longer than the SpokePool takes its quote time. Throws {@link AcrossRefusal}. Used on the client\n * of a remote provider and again before a build and a signature.\n */\nexport function checkAcrossQuote(request: AcrossRequest, quote: Quote, tx?: AcrossDepositTx & {gasLimit?: unknown}): VerifiedAcrossDeposit {\n if (quote === null || typeof quote !== \"object\" || quote.provider !== \"across\") throw new AcrossRefusal(\"quote-shape\", \"not an Across quote\", \"policy_refused\");\n const t = tx ?? quote.txRequest;\n if (!t) throw new AcrossRefusal(\"quote-shape\", \"the quote has no transaction\", \"policy_refused\");\n if (quote.depositAddress) throw new AcrossRefusal(\"quote-shape\", \"an Across quote pays the SpokePool through its calldata, never a deposit address\", \"vault_mismatch\");\n const extra = quote.txRequest as {serializedTx?: unknown; nativeFee?: unknown} | undefined;\n if (extra?.serializedTx !== undefined || extra?.nativeFee !== undefined) {\n throw new AcrossRefusal(\"quote-shape\", \"an Across deposit carries no extra native fee and no serialized transaction\", \"policy_refused\");\n }\n const v = verifyAcrossDeposit(request, t);\n if (quote.sourceAmount !== v.args.inputAmount.toString(10) || quote.minDestAmount !== v.args.outputAmount.toString(10) || quote.destAmount !== v.args.outputAmount.toString(10)\n || quote.destDecimals !== v.route.output.decimals) {\n throw new AcrossRefusal(\"quote-amounts\", \"the amounts the quote shows are not the deposit's\", \"price_check_failed\");\n }\n // The fee list is what the engine's fee caps add up, and feeUsd what routes are scored by: the deposit's own fee, exactly.\n const shown = acrossQuoteFeesOf(v.route, v.fee);\n const w = shown.fees![0]!;\n const g = Array.isArray(quote.fees) && quote.fees.length === 1 ? quote.fees[0] : undefined;\n if (!g || g.type !== w.type || g.amount !== w.amount || typeof g.token !== \"string\" || lower(g.token) !== w.token || g.included !== true || quote.feeUsd !== shown.feeUsd) {\n throw new AcrossRefusal(\"quote-amounts\", `the fees the quote shows are not the deposit's fee of ${v.fee} (the engine's fee caps read them)`, \"price_check_failed\");\n }\n // Gas is the one number of the call no argument binds: held to a band, so a backend can neither starve the deposit\n // (a paid revert) nor name an absurd limit. Absent = the wallet estimates.\n const gas = (t as {gasLimit?: unknown}).gasLimit;\n if (gas !== undefined) {\n if (typeof gas !== \"string\" || !/^[1-9]\\d{0,10}$/.test(gas) || BigInt(gas) < ACROSS_GAS_FLOOR || BigInt(gas) > ACROSS_GAS_CAP) {\n throw new AcrossRefusal(\"quote-gas\", `the gas limit ${String(gas).slice(0, 40)} is outside ${ACROSS_GAS_FLOOR}–${ACROSS_GAS_CAP}`, \"policy_refused\");\n }\n }\n const now = request.nowMs ?? Date.now();\n if (typeof quote.validUntilMs !== \"number\" || !Number.isFinite(quote.validUntilMs) || quote.validUntilMs > now + ACROSS_MAX_QUOTE_LIFE_MS) {\n throw new AcrossRefusal(\"quote-expiry\", \"the quote claims to live longer than an Across quote may\", \"policy_refused\");\n }\n // Signed as late as the quote says it may be, the deposit must still land while the SpokePool takes its quote time.\n if (quote.validUntilMs > acrossQuoteTimeLimitMs(v.args.quoteTimestamp)) {\n throw new AcrossRefusal(\"quote-expiry\", `the quote claims to live past ${ACROSS_DEPOSIT_QUOTE_TIME_BUFFER_S - ACROSS_LANDING_WINDOW_S} s after its quote time — signed then, the deposit would revert on it`, \"policy_refused\");\n }\n // A server appends its intent token (`<id>~<tag>`); the id before it must name this deposit.\n const intent = parseAcrossIntentId(quote.intentId);\n const want = acrossIntentId(v.route.input.chain.chainId, v.route.output.chain.chainId, v.deposit.data);\n if (!intent || `across:${intent.sourceChainId}:${intent.destChainId}:${intent.digest}` !== want) {\n throw new AcrossRefusal(\"quote-intent\", \"the quote's id does not name its deposit\", \"policy_refused\");\n }\n return v;\n}\n\n// The reason behind each text the pins return (`acrossPins.reasonOf`), bounded.\nconst pinNotes = refusalNotes();\n/** The refusal's text, its reason noted for `acrossPins.reasonOf`; rethrows anything that is not a refusal. */\nfunction notedReason(err: unknown): string {\n const text = acrossRefusalReason(err);\n const info = refusalOf(err);\n return info ? pinNotes.note(text, info) : text;\n}\n\n/** What the pins hold a remote quote to beyond the user's request: the app's own fee cap. */\nexport interface AcrossPinsOptions {\n /** Fee cap in bps of the input (default {@link ACROSS_DEFAULT_MAX_FEE_BPS}, at most {@link ACROSS_MAX_FEE_BPS_LIMIT}) — the app's, never the server's. */\n maxFeeBps?: number;\n}\n\n/** The request a remote quote is held to: the server's own derivation — a dry quote priced for the placeholder where the caller named no address. */\nexport const acrossPinsRequestOf = (params: QuoteParams, cap: {maxFeeBps?: number} = {}): AcrossRequest => acrossRequestOf(params, params.dry !== false ? {...cap, placeholder: ACROSS_PLACEHOLDER} : cap);\n\nfunction verifyQuoteWith(params: QuoteParams, quote: Quote, cap: {maxFeeBps?: number}): string | null {\n try {\n checkAcrossQuote(acrossPinsRequestOf(params, cap), quote);\n return null;\n } catch (err) {\n return notedReason(err);\n }\n}\n\n/**\n * A remote build against the request the app sent, by the device's clock now: the quote's own deposit, verified again\n * ({@link checkAcrossQuote}). Throws {@link AcrossRefusal}. `acrossPins.verifyBuild` and `acrossRemoteProvider`'s\n * preflight (right before signing) run it.\n */\nexport function acrossCheckBuild(quote: Quote, tx: UnsignedTx, params: QuoteParams | undefined, cap: {maxFeeBps?: number} = {}): VerifiedAcrossDeposit {\n if (!params) throw new AcrossRefusal(\"request-invalid\", \"the request this quote answered is not known on this side — quote again\", \"policy_refused\");\n if (tx.chain !== params.sourceChain) throw new AcrossRefusal(\"tx-chain\", `the build is for ${tx.chain}, not ${params.sourceChain}`, \"vault_mismatch\");\n checkAcrossTxShape(tx);\n return checkAcrossQuote(acrossRequestOf(params, cap), quote, tx);\n}\n\nfunction verifyBuildWith(quote: Quote, tx: UnsignedTx, params: QuoteParams | undefined, cap: {maxFeeBps?: number}): string | null {\n try {\n acrossCheckBuild(quote, tx, params, cap);\n return null;\n } catch (err) {\n return notedReason(err);\n }\n}\n\n/** `RemotePins.verifyQuote` with the default fee cap: the reason a remote Across quote fails against the user's own request, or null. */\nexport function acrossVerifyQuote(params: QuoteParams, quote: Quote): string | null {\n return verifyQuoteWith(params, quote, {});\n}\n\n/** `RemotePins.verifyBuild` with the default fee cap: a remote build must be the quote's own (verified) transaction, and is verified again. */\nexport function acrossVerifyBuild(quote: Quote, tx: UnsignedTx, params?: QuoteParams): string | null {\n return verifyBuildWith(quote, tx, params, {});\n}\n\n/**\n * The app's pins for a remote Across provider (`remoteProvider({name: \"across\", ...acrossPinsWith({maxFeeBps})})`): the\n * only contract a build may call or approve is the chain's SpokePool, and every quote and build is verified on the\n * client against the user's own request and the app's fee cap — a server's own cap (`acrossProvider({maxFeeBps})`) is\n * not known on this side, so the app states the one it holds remote quotes to. `reasonOf` classifies a text\n * `verifyQuote` / `verifyBuild` returned. Throws a plain `Error` for a cap out of range.\n */\nexport function acrossPinsWith(opts: AcrossPinsOptions = {}): RemotePins {\n const maxFeeBps = opts.maxFeeBps;\n if (maxFeeBps !== undefined && (!Number.isInteger(maxFeeBps) || maxFeeBps < 0 || maxFeeBps > ACROSS_MAX_FEE_BPS_LIMIT)) {\n throw new Error(`across: maxFeeBps must be an integer between 0 and ${ACROSS_MAX_FEE_BPS_LIMIT}`);\n }\n const cap = Object.freeze(maxFeeBps !== undefined ? {maxFeeBps} : {});\n return Object.freeze({\n callTargets: (chain: string): readonly string[] => { const c = acrossChain(chain); return c ? [c.spokePool] : []; },\n spenders: (chain: string): readonly string[] => { const c = acrossChain(chain); return c ? [c.spokePool] : []; },\n verifyQuote: (params: QuoteParams, quote: Quote): string | null => verifyQuoteWith(params, quote, cap),\n verifyBuild: (quote: Quote, tx: UnsignedTx, params?: QuoteParams): string | null => verifyBuildWith(quote, tx, params, cap),\n reasonOf: pinNotes.reasonOf,\n });\n}\n\n/** {@link acrossPinsWith} with the default fee cap (10 %): `remoteProvider({name: \"across\", ...acrossPins})`. */\nexport const acrossPins: RemotePins = acrossPinsWith();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAQ,iBAA0B;AAClC,SAAQ,qBAAoB;AAE5B,SAAQ,cAAc,iBAAyC;AAC/D,SAAQ,qBAAoB;AAUrB,IAAM,6BAA6B;AAEnC,IAAM,2BAA2B;AAEjC,IAAM,sBAAsB;AAM5B,IAAM,4BAA4B;AAKlC,IAAM,0BAA0B;AAEhC,IAAM,2BAA2B;AAMjC,IAAM,2BAA2B;AAcjC,IAAM,qBAA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I,CAAC,EAAE,SAAS,IAAI,CAAC;AAAA,IAAG;AAAA,IAClH,UAAU,CAAC,UAAqC;AAAE,YAAM,IAAI,YAAY,KAAK;AAAG,aAAO,IAAI,CAAC,EAAE,SAAS,IAAI,CAAC;AAAA,IAAG;AAAA,IAC/G,aAAa,CAAC,QAAqB,UAAgC,gBAAgB,QAAQ,OAAO,GAAG;AAAA,IACrG,aAAa,CAAC,OAAc,IAAgB,WAAwC,gBAAgB,OAAO,IAAI,QAAQ,GAAG;AAAA,IAC1H,UAAU,SAAS;AAAA,EACrB,CAAC;AACH;AAGO,IAAM,aAAyB,eAAe;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
acrossProvider
|
|
3
|
+
} from "./chunk-PPPZIG7S.js";
|
|
4
|
+
import {
|
|
5
|
+
across
|
|
6
|
+
} from "./chunk-GX67FRPG.js";
|
|
7
|
+
|
|
8
|
+
// src/protocol.ts
|
|
9
|
+
import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
|
|
10
|
+
var AcrossSwap2Protocol = class extends SingleProviderSwap2 {
|
|
11
|
+
provider;
|
|
12
|
+
constructor(account, config) {
|
|
13
|
+
super(account, config);
|
|
14
|
+
this.provider = acrossProvider(config);
|
|
15
|
+
}
|
|
16
|
+
chainSupported(caip2) {
|
|
17
|
+
return across.supportsChain(caip2);
|
|
18
|
+
}
|
|
19
|
+
pairSupported(fromChain, toChain) {
|
|
20
|
+
return across.supports(fromChain, toChain);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
AcrossSwap2Protocol
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-P32AW6XS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol.ts"],"sourcesContent":["import {SingleProviderSwap2} from \"@anywalletkit/protocol-swap2-core/swap2/single\";\nimport type {Swap2Account, Swap2EngineConfig} from \"@anywalletkit/protocol-swap2-core/swap2/base\";\nimport {across as acrossCfg} from \"./config.js\";\nimport {acrossProvider, type AcrossProviderConfig} from \"./provider.js\";\n\nexport interface AcrossSwap2Config extends Swap2EngineConfig, AcrossProviderConfig {}\n\n/**\n * Standalone Across swap2: EVM → EVM through the source chain's SpokePool, every deposit built and verified on the\n * device. Quoting needs the Across API V5 key, so this class quotes only on a server (`apiKey`); an app uses\n * `acrossRemoteProvider` in a router instead.\n */\nexport class AcrossSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: AcrossSwap2Config) {\n super(account, config);\n this.provider = acrossProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return acrossCfg.supportsChain(caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return acrossCfg.supports(fromChain, toChain);\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAQ,2BAA0B;AAY3B,IAAM,sBAAN,cAAkC,oBAAoB;AAAA,EACxC;AAAA,EACnB,YAAY,SAAmC,QAA2B;AACxE,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,eAAe,MAAM;AAAA,EACvC;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,OAAU,cAAc,KAAK;AAAA,EACtC;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,OAAU,SAAS,WAAW,OAAO;AAAA,EAC9C;AACF;","names":[]}
|