@anywalletkit/protocol-swap2-0x 0.1.6 → 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 +4 -3
- 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 +16 -2
- package/dist/chains.cjs.map +1 -1
- package/dist/chains.d.cts +26 -6
- package/dist/chains.d.ts +26 -6
- package/dist/chains.js +5 -1
- package/dist/{chunk-CWZCAJBY.js → chunk-AMZ5DXN2.js} +17 -3
- package/dist/chunk-AMZ5DXN2.js.map +1 -0
- package/dist/{chunk-RLNXMQJH.js → chunk-PLQSYP6W.js} +9 -6
- package/dist/chunk-PLQSYP6W.js.map +1 -0
- package/dist/{chunk-ALMGGQS4.js → chunk-SAI3RXOP.js} +6 -6
- package/dist/{chunk-ALMGGQS4.js.map → chunk-SAI3RXOP.js.map} +1 -1
- package/dist/{chunk-QFOKBJXP.js → chunk-V4HUFBY2.js} +5 -5
- package/dist/chunk-V4HUFBY2.js.map +1 -0
- package/dist/{chunk-AX4RNHWE.js → chunk-VPQZVV5O.js} +2 -2
- package/dist/{chunk-NK3PQGI4.js → chunk-YHRPT6BS.js} +20 -5
- package/dist/chunk-YHRPT6BS.js.map +1 -0
- package/dist/index.cjs +39 -10
- 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 +34 -9
- 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 +34 -9
- 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 +34 -9
- 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 +20 -4
- 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-CWZCAJBY.js.map +0 -1
- package/dist/chunk-NK3PQGI4.js.map +0 -1
- package/dist/chunk-QFOKBJXP.js.map +0 -1
- package/dist/chunk-RLNXMQJH.js.map +0 -1
- /package/dist/{chunk-AX4RNHWE.js.map → chunk-VPQZVV5O.js.map} +0 -0
package/dist/protocol.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { SingleProviderSwap2 } from '@anywalletkit/protocol-swap2-core/swap2/sin
|
|
|
3
3
|
import { Swap2EngineConfig, Swap2Account } from '@anywalletkit/protocol-swap2-core/swap2/base';
|
|
4
4
|
import '@anywalletkit/protocol-swap2-core/types';
|
|
5
5
|
import './chains.cjs';
|
|
6
|
-
import './settler-
|
|
6
|
+
import './settler-CeJFLW5t.cjs';
|
|
7
7
|
import '@anywalletkit/protocol-swap2-core/errors';
|
|
8
8
|
import '@anywalletkit/protocol-swap2-core/util';
|
|
9
9
|
|
package/dist/protocol.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SingleProviderSwap2 } from '@anywalletkit/protocol-swap2-core/swap2/sin
|
|
|
3
3
|
import { Swap2EngineConfig, Swap2Account } from '@anywalletkit/protocol-swap2-core/swap2/base';
|
|
4
4
|
import '@anywalletkit/protocol-swap2-core/types';
|
|
5
5
|
import './chains.js';
|
|
6
|
-
import './settler-
|
|
6
|
+
import './settler-DBLrnepW.js';
|
|
7
7
|
import '@anywalletkit/protocol-swap2-core/errors';
|
|
8
8
|
import '@anywalletkit/protocol-swap2-core/util';
|
|
9
9
|
|
package/dist/protocol.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ZeroExSwap2Protocol
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-VPQZVV5O.js";
|
|
4
|
+
import "./chunk-PLQSYP6W.js";
|
|
5
|
+
import "./chunk-V4HUFBY2.js";
|
|
6
|
+
import "./chunk-YHRPT6BS.js";
|
|
7
|
+
import "./chunk-AMZ5DXN2.js";
|
|
8
8
|
export {
|
|
9
9
|
ZeroExSwap2Protocol
|
|
10
10
|
};
|
package/dist/provider.cjs
CHANGED
|
@@ -42,14 +42,17 @@ var ZEROEX_PERMIT2 = import_util.PERMIT2_ADDRESS;
|
|
|
42
42
|
var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
|
|
43
43
|
var ZEROEX_TAKER_FEATURE = 2;
|
|
44
44
|
var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
45
|
+
var ZEROEX_GAS_CAP_CEILING = 30000000n;
|
|
46
|
+
var isZeroExGasCap = (v) => typeof v === "bigint" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;
|
|
45
47
|
var ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
46
48
|
var ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
47
|
-
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
|
|
49
|
+
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce, maxGasLimit) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...maxGasLimit !== void 0 ? { maxGasLimit } : {} });
|
|
48
50
|
var ZEROEX_CHAINS = Object.freeze({
|
|
49
51
|
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
|
|
50
52
|
10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
|
|
51
53
|
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
|
|
52
54
|
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
|
|
55
|
+
143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
|
|
53
56
|
8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
|
|
54
57
|
42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
|
|
55
58
|
43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
|
|
@@ -78,7 +81,16 @@ function zeroExChains(overrides) {
|
|
|
78
81
|
if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
|
|
79
82
|
throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
|
|
80
83
|
}
|
|
81
|
-
|
|
84
|
+
const gasCap = entry.maxGasLimit;
|
|
85
|
+
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}`);
|
|
86
|
+
out[id] = Object.freeze({
|
|
87
|
+
name: entry.name,
|
|
88
|
+
registry: entry.registry,
|
|
89
|
+
newestLiveNonce: newest,
|
|
90
|
+
previousLiveNonce: previous,
|
|
91
|
+
...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {},
|
|
92
|
+
...gasCap !== void 0 ? { maxGasLimit: gasCap } : {}
|
|
93
|
+
});
|
|
82
94
|
}
|
|
83
95
|
return Object.freeze(out);
|
|
84
96
|
}
|
|
@@ -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;
|
|
@@ -533,7 +556,7 @@ function zeroExProvider(config) {
|
|
|
533
556
|
};
|
|
534
557
|
return {
|
|
535
558
|
name: ZEROEX_PROVIDER,
|
|
536
|
-
describeActivity: describeZeroExActivity,
|
|
559
|
+
describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, chains),
|
|
537
560
|
supportsSameChain: true,
|
|
538
561
|
// The quoted gas limit is the API's word: a native sale (like a Permit2 call) goes out with the account's own estimate.
|
|
539
562
|
ownGasEstimate: true,
|
|
@@ -844,7 +867,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
|
|
|
844
867
|
throw (0, import_errors2.refusal)("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
|
|
845
868
|
}
|
|
846
869
|
const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
|
|
847
|
-
|
|
870
|
+
const chain2 = zeroExChain(ctx.chains, chainId);
|
|
871
|
+
if (!chain2) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
|
|
872
|
+
checkZeroExGasLimit(tx.gasLimit, chain2, chainId);
|
|
848
873
|
const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
|
|
849
874
|
if (!settlers.some((s) => same2(s, quoted.to))) {
|
|
850
875
|
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.");
|