@anywalletkit/protocol-swap2-0x 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/dist/activity.cjs +11 -10
- package/dist/activity.cjs.map +1 -1
- package/dist/activity.d.cts +6 -1
- package/dist/activity.d.ts +6 -1
- package/dist/activity.js +3 -3
- package/dist/chains.cjs +23 -9
- package/dist/chains.cjs.map +1 -1
- package/dist/chains.d.cts +26 -5
- package/dist/chains.d.ts +26 -5
- package/dist/chains.js +5 -1
- package/dist/{chunk-MMOBCJEO.js → chunk-AMZ5DXN2.js} +24 -10
- package/dist/chunk-AMZ5DXN2.js.map +1 -0
- package/dist/{chunk-R7VDTSDK.js → chunk-PLQSYP6W.js} +9 -6
- package/dist/chunk-PLQSYP6W.js.map +1 -0
- package/dist/{chunk-WP7CUXWT.js → chunk-SAI3RXOP.js} +6 -6
- package/dist/{chunk-WP7CUXWT.js.map → chunk-SAI3RXOP.js.map} +1 -1
- package/dist/{chunk-HDMLWKPW.js → chunk-V4HUFBY2.js} +5 -5
- package/dist/chunk-V4HUFBY2.js.map +1 -0
- package/dist/{chunk-7VM4FURF.js → chunk-VPQZVV5O.js} +2 -2
- package/dist/{chunk-VSYAAW22.js → chunk-YHRPT6BS.js} +20 -5
- package/dist/chunk-YHRPT6BS.js.map +1 -0
- package/dist/index.cjs +46 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -6
- package/dist/protocol.cjs +41 -16
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +1 -1
- package/dist/protocol.d.ts +1 -1
- package/dist/protocol.js +5 -5
- package/dist/provider.cjs +41 -16
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +5 -5
- package/dist/provider.d.ts +5 -5
- package/dist/provider.js +4 -4
- package/dist/remote.cjs +41 -16
- package/dist/remote.cjs.map +1 -1
- package/dist/remote.d.cts +1 -1
- package/dist/remote.d.ts +1 -1
- package/dist/remote.js +5 -5
- package/dist/{settler-KDFcfsKv.d.cts → settler-CeJFLW5t.d.cts} +21 -4
- package/dist/{settler-BpRGkBVV.d.ts → settler-DBLrnepW.d.ts} +21 -4
- package/dist/settler.cjs +27 -11
- package/dist/settler.cjs.map +1 -1
- package/dist/settler.d.cts +1 -1
- package/dist/settler.d.ts +1 -1
- package/dist/settler.js +6 -2
- package/module.json +1 -0
- package/package.json +4 -4
- package/dist/chunk-HDMLWKPW.js.map +0 -1
- package/dist/chunk-MMOBCJEO.js.map +0 -1
- package/dist/chunk-R7VDTSDK.js.map +0 -1
- package/dist/chunk-VSYAAW22.js.map +0 -1
- /package/dist/{chunk-7VM4FURF.js.map → chunk-VPQZVV5O.js.map} +0 -0
package/dist/provider.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CrossChainProvider, Quote, UnsignedTx } from '@anywalletkit/protocol-swap2-core/types';
|
|
2
2
|
import { ZeroExChain } from './chains.cjs';
|
|
3
|
-
import { f as SettlerResolver,
|
|
3
|
+
import { f as SettlerResolver, x as RpcUrls } from './settler-CeJFLW5t.cjs';
|
|
4
4
|
import '@anywalletkit/protocol-swap2-core/errors';
|
|
5
5
|
import '@anywalletkit/protocol-swap2-core/util';
|
|
6
6
|
|
|
@@ -71,10 +71,10 @@ type ZeroExProvider = CrossChainProvider & {
|
|
|
71
71
|
declare function zeroExProvider(config: ZeroExProviderConfig): ZeroExProvider;
|
|
72
72
|
/**
|
|
73
73
|
* The device's last check before the engine signs a 0x swap, run by the `preflightDeposit` of both providers (in remote
|
|
74
|
-
* mode before the backend's own preflight is asked): the transaction must be the quoted one,
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* or sent.
|
|
74
|
+
* mode before the backend's own preflight is asked): the transaction must be the quoted one, its gas limit (when it
|
|
75
|
+
* carries one) within the chain's cap, and its target must still be a Settler the registry names now — a fresh read
|
|
76
|
+
* through `resolver` (the device's own RPC), so a Settler paused, replaced or removed since the quote (on the review
|
|
77
|
+
* screen, during an approval) is refused here, with nothing signed or sent.
|
|
78
78
|
*/
|
|
79
79
|
declare function zeroExPreflightDeposit(quote: Quote, tx: UnsignedTx, ctx: {
|
|
80
80
|
chains: Readonly<Record<number, ZeroExChain>>;
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CrossChainProvider, Quote, UnsignedTx } from '@anywalletkit/protocol-swap2-core/types';
|
|
2
2
|
import { ZeroExChain } from './chains.js';
|
|
3
|
-
import { f as SettlerResolver,
|
|
3
|
+
import { f as SettlerResolver, x as RpcUrls } from './settler-DBLrnepW.js';
|
|
4
4
|
import '@anywalletkit/protocol-swap2-core/errors';
|
|
5
5
|
import '@anywalletkit/protocol-swap2-core/util';
|
|
6
6
|
|
|
@@ -71,10 +71,10 @@ type ZeroExProvider = CrossChainProvider & {
|
|
|
71
71
|
declare function zeroExProvider(config: ZeroExProviderConfig): ZeroExProvider;
|
|
72
72
|
/**
|
|
73
73
|
* The device's last check before the engine signs a 0x swap, run by the `preflightDeposit` of both providers (in remote
|
|
74
|
-
* mode before the backend's own preflight is asked): the transaction must be the quoted one,
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* or sent.
|
|
74
|
+
* mode before the backend's own preflight is asked): the transaction must be the quoted one, its gas limit (when it
|
|
75
|
+
* carries one) within the chain's cap, and its target must still be a Settler the registry names now — a fresh read
|
|
76
|
+
* through `resolver` (the device's own RPC), so a Settler paused, replaced or removed since the quote (on the review
|
|
77
|
+
* screen, during an approval) is refused here, with nothing signed or sent.
|
|
78
78
|
*/
|
|
79
79
|
declare function zeroExPreflightDeposit(quote: Quote, tx: UnsignedTx, ctx: {
|
|
80
80
|
chains: Readonly<Record<number, ZeroExChain>>;
|
package/dist/provider.js
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
zeroExFees,
|
|
5
5
|
zeroExPreflightDeposit,
|
|
6
6
|
zeroExProvider
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-PLQSYP6W.js";
|
|
8
|
+
import "./chunk-V4HUFBY2.js";
|
|
9
|
+
import "./chunk-YHRPT6BS.js";
|
|
10
|
+
import "./chunk-AMZ5DXN2.js";
|
|
11
11
|
export {
|
|
12
12
|
ZEROEX_DEFAULT_BASE_URL,
|
|
13
13
|
ZEROEX_PROVIDER,
|
package/dist/remote.cjs
CHANGED
|
@@ -43,17 +43,20 @@ var ZEROEX_PERMIT2 = import_util.PERMIT2_ADDRESS;
|
|
|
43
43
|
var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
|
|
44
44
|
var ZEROEX_TAKER_FEATURE = 2;
|
|
45
45
|
var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
46
|
+
var ZEROEX_GAS_CAP_CEILING = 30000000n;
|
|
47
|
+
var isZeroExGasCap = (v) => typeof v === "bigint" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;
|
|
46
48
|
var ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
47
49
|
var ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
48
|
-
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
|
|
50
|
+
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce, maxGasLimit) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...maxGasLimit !== void 0 ? { maxGasLimit } : {} });
|
|
49
51
|
var ZEROEX_CHAINS = Object.freeze({
|
|
50
|
-
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
51
|
-
10: chain("Optimism", "0x4200000000000000000000000000000000000006",
|
|
52
|
-
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
53
|
-
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
|
|
53
|
+
10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
|
|
54
|
+
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
|
|
55
|
+
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
|
|
56
|
+
143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
|
|
57
|
+
8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
|
|
58
|
+
42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
|
|
59
|
+
43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
|
|
57
60
|
});
|
|
58
61
|
var ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
59
62
|
var ZERO_ADDRESS = /^0x0{40}$/;
|
|
@@ -79,7 +82,16 @@ function zeroExChains(overrides) {
|
|
|
79
82
|
if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
|
|
80
83
|
throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
const gasCap = entry.maxGasLimit;
|
|
86
|
+
if (gasCap !== void 0 && !isZeroExGasCap(gasCap)) throw new Error(`zeroex: chain ${id} gas cap (maxGasLimit) is not a bigint from 1 to ${ZEROEX_GAS_CAP_CEILING}`);
|
|
87
|
+
out[id] = Object.freeze({
|
|
88
|
+
name: entry.name,
|
|
89
|
+
registry: entry.registry,
|
|
90
|
+
newestLiveNonce: newest,
|
|
91
|
+
previousLiveNonce: previous,
|
|
92
|
+
...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {},
|
|
93
|
+
...gasCap !== void 0 ? { maxGasLimit: gasCap } : {}
|
|
94
|
+
});
|
|
83
95
|
}
|
|
84
96
|
return Object.freeze(out);
|
|
85
97
|
}
|
|
@@ -311,6 +323,19 @@ function decodeSettlerExecute(data) {
|
|
|
311
323
|
return Object.freeze({ recipient, buyToken, minAmountOut, zidAndAffiliate, actions: Object.freeze(actions), bodyLength, word });
|
|
312
324
|
}
|
|
313
325
|
var ZEROEX_MAX_GAS_LIMIT = 6000000n;
|
|
326
|
+
function zeroExMaxGasLimit(chain2, chainId) {
|
|
327
|
+
const cap = chain2.maxGasLimit;
|
|
328
|
+
if (cap === void 0) return ZEROEX_MAX_GAS_LIMIT;
|
|
329
|
+
if (!isZeroExGasCap(cap)) throw refuse(`the chain table's gas cap${chainId !== void 0 ? ` for chain ${chainId}` : ""} is not a bigint from 1 to ${ZEROEX_GAS_CAP_CEILING}`);
|
|
330
|
+
return cap;
|
|
331
|
+
}
|
|
332
|
+
function checkZeroExGasLimit(gasLimit, chain2, chainId) {
|
|
333
|
+
const cap = zeroExMaxGasLimit(chain2, chainId);
|
|
334
|
+
if (gasLimit === void 0) return;
|
|
335
|
+
if (typeof gasLimit !== "string" || !/^[0-9]{1,12}$/.test(gasLimit) || BigInt(gasLimit) === 0n || BigInt(gasLimit) > cap) {
|
|
336
|
+
throw refuse(`the transaction asks for more gas than any 0x swap needs (its gas limit must be 1 to ${cap} on chain ${chainId})`, "policy_refused");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
314
339
|
function checkZeroExTransaction(tx, expected) {
|
|
315
340
|
if (!Number.isSafeInteger(expected.chainId) || expected.chainId <= 0) throw refuse("the swap names no EVM chain");
|
|
316
341
|
if (!ADDRESS2.test(expected.recipient) || ZERO_ADDRESS2.test(expected.recipient)) throw refuse("the swap names no recipient");
|
|
@@ -334,9 +359,7 @@ function checkZeroExTransaction(tx, expected) {
|
|
|
334
359
|
if (value > 0n && deployment !== pin.newestLiveNonce && deployment !== pin.previousLiveNonce) {
|
|
335
360
|
throw refuse(deployment > pin.newestLiveNonce ? `the swap sends native coin to Settler deployment ${deployment} (${to}) on chain ${expected.chainId}, newer than the newest one live when this module's chain table was pinned (${pin.newestLiveNonce}) \u2014 a native-coin sale goes only to a pinned Settler: update @anywalletkit/protocol-swap2-0x` : `the swap sends native coin to Settler deployment ${deployment} (${to}) on chain ${expected.chainId}, which was not live when this module's chain table was pinned (${pin.newestLiveNonce} and ${pin.previousLiveNonce} were) \u2014 a native-coin sale goes only to a pinned Settler`, "vault_mismatch");
|
|
336
361
|
}
|
|
337
|
-
|
|
338
|
-
throw refuse("the transaction asks for more gas than any 0x swap needs", "policy_refused");
|
|
339
|
-
}
|
|
362
|
+
checkZeroExGasLimit(tx.gasLimit, pin, expected.chainId);
|
|
340
363
|
if (typeof tx.data !== "string") throw refuse("the transaction has no data", "policy_refused");
|
|
341
364
|
const execute = decodeSettlerExecute(tx.data);
|
|
342
365
|
if (!same(execute.recipient, expected.recipient)) throw refuse(`the swap pays ${execute.recipient}, not the recipient of this swap`, "recipient_mismatch");
|
|
@@ -380,9 +403,9 @@ function checkZeroExTransaction(tx, expected) {
|
|
|
380
403
|
|
|
381
404
|
// src/activity.ts
|
|
382
405
|
var ZEROEX_MODULE = "@anywalletkit/protocol-swap2-0x";
|
|
383
|
-
function describeZeroExActivity(tx, ctx) {
|
|
406
|
+
function describeZeroExActivity(tx, ctx, chains = ZEROEX_CHAINS) {
|
|
384
407
|
const chainId = zeroExChainId(tx.chain);
|
|
385
|
-
const chain2 = zeroExChain(
|
|
408
|
+
const chain2 = zeroExChain(chains, chainId);
|
|
386
409
|
if (!chain2) return null;
|
|
387
410
|
if ((0, import_activity.callSelector)(tx) !== SETTLER_EXECUTE_SELECTOR) return null;
|
|
388
411
|
const target = tx.call?.to ?? tx.to;
|
|
@@ -428,7 +451,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
|
|
|
428
451
|
throw (0, import_errors2.refusal)("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
|
|
429
452
|
}
|
|
430
453
|
const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
|
|
431
|
-
|
|
454
|
+
const chain2 = zeroExChain(ctx.chains, chainId);
|
|
455
|
+
if (!chain2) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
|
|
456
|
+
checkZeroExGasLimit(tx.gasLimit, chain2, chainId);
|
|
432
457
|
const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
|
|
433
458
|
if (!settlers.some((s) => same2(s, quoted.to))) {
|
|
434
459
|
throw (0, import_errors2.refusal)("vault_mismatch", "zeroex: the quoted 0x Settler is no longer in the on-chain registry. Nothing was sent; refresh the quote.");
|
|
@@ -567,7 +592,7 @@ function zeroExRemoteProvider(options) {
|
|
|
567
592
|
});
|
|
568
593
|
return {
|
|
569
594
|
...inner,
|
|
570
|
-
describeActivity: describeZeroExActivity,
|
|
595
|
+
describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, pins.chains),
|
|
571
596
|
// The quoted gas limit is the backend's word: every call goes out with the account's own estimate.
|
|
572
597
|
ownGasEstimate: true,
|
|
573
598
|
settlerResolver: pins.resolver,
|