@anywalletkit/protocol-swap2-0x 0.1.6 → 0.3.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 +31 -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-ALMGGQS4.js → chunk-ABT2WYBK.js} +6 -6
- package/dist/{chunk-ALMGGQS4.js.map → chunk-ABT2WYBK.js.map} +1 -1
- package/dist/{chunk-CWZCAJBY.js → chunk-AMZ5DXN2.js} +17 -3
- package/dist/chunk-AMZ5DXN2.js.map +1 -0
- package/dist/{chunk-AX4RNHWE.js → chunk-KYVRMBZG.js} +2 -2
- package/dist/{chunk-RLNXMQJH.js → chunk-S2RUUV3X.js} +16 -6
- package/dist/chunk-S2RUUV3X.js.map +1 -0
- package/dist/{chunk-QFOKBJXP.js → chunk-V4HUFBY2.js} +5 -5
- package/dist/chunk-V4HUFBY2.js.map +1 -0
- package/dist/{chunk-NK3PQGI4.js → chunk-YHRPT6BS.js} +20 -5
- package/dist/chunk-YHRPT6BS.js.map +1 -0
- package/dist/index.cjs +46 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -6
- package/dist/protocol.cjs +40 -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 +41 -9
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +13 -6
- package/dist/provider.d.ts +13 -6
- package/dist/provider.js +6 -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 +6 -6
- 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-KYVRMBZG.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-KYVRMBZG.js";
|
|
4
|
+
import "./chunk-S2RUUV3X.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
|
@@ -23,6 +23,7 @@ __export(provider_exports, {
|
|
|
23
23
|
ZEROEX_DEFAULT_BASE_URL: () => ZEROEX_DEFAULT_BASE_URL,
|
|
24
24
|
ZEROEX_PROVIDER: () => ZEROEX_PROVIDER,
|
|
25
25
|
zeroExFees: () => zeroExFees,
|
|
26
|
+
zeroExGasEstimate: () => zeroExGasEstimate,
|
|
26
27
|
zeroExPreflightDeposit: () => zeroExPreflightDeposit,
|
|
27
28
|
zeroExProvider: () => zeroExProvider
|
|
28
29
|
});
|
|
@@ -42,14 +43,17 @@ var ZEROEX_PERMIT2 = import_util.PERMIT2_ADDRESS;
|
|
|
42
43
|
var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
|
|
43
44
|
var ZEROEX_TAKER_FEATURE = 2;
|
|
44
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;
|
|
45
48
|
var ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
46
49
|
var ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
47
|
-
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 } : {} });
|
|
48
51
|
var ZEROEX_CHAINS = Object.freeze({
|
|
49
52
|
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
|
|
50
53
|
10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
|
|
51
54
|
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
|
|
52
55
|
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
|
|
56
|
+
143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
|
|
53
57
|
8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
|
|
54
58
|
42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
|
|
55
59
|
43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
|
|
@@ -78,7 +82,16 @@ function zeroExChains(overrides) {
|
|
|
78
82
|
if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
|
|
79
83
|
throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
|
|
80
84
|
}
|
|
81
|
-
|
|
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
|
+
});
|
|
82
95
|
}
|
|
83
96
|
return Object.freeze(out);
|
|
84
97
|
}
|
|
@@ -311,6 +324,19 @@ function decodeSettlerExecute(data) {
|
|
|
311
324
|
return Object.freeze({ recipient, buyToken, minAmountOut, zidAndAffiliate, actions: Object.freeze(actions), bodyLength, word });
|
|
312
325
|
}
|
|
313
326
|
var ZEROEX_MAX_GAS_LIMIT = 6000000n;
|
|
327
|
+
function zeroExMaxGasLimit(chain2, chainId) {
|
|
328
|
+
const cap = chain2.maxGasLimit;
|
|
329
|
+
if (cap === void 0) return ZEROEX_MAX_GAS_LIMIT;
|
|
330
|
+
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}`);
|
|
331
|
+
return cap;
|
|
332
|
+
}
|
|
333
|
+
function checkZeroExGasLimit(gasLimit, chain2, chainId) {
|
|
334
|
+
const cap = zeroExMaxGasLimit(chain2, chainId);
|
|
335
|
+
if (gasLimit === void 0) return;
|
|
336
|
+
if (typeof gasLimit !== "string" || !/^[0-9]{1,12}$/.test(gasLimit) || BigInt(gasLimit) === 0n || BigInt(gasLimit) > cap) {
|
|
337
|
+
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");
|
|
338
|
+
}
|
|
339
|
+
}
|
|
314
340
|
function checkZeroExTransaction(tx, expected) {
|
|
315
341
|
if (!Number.isSafeInteger(expected.chainId) || expected.chainId <= 0) throw refuse("the swap names no EVM chain");
|
|
316
342
|
if (!ADDRESS2.test(expected.recipient) || ZERO_ADDRESS2.test(expected.recipient)) throw refuse("the swap names no recipient");
|
|
@@ -334,9 +360,7 @@ function checkZeroExTransaction(tx, expected) {
|
|
|
334
360
|
if (value > 0n && deployment !== pin.newestLiveNonce && deployment !== pin.previousLiveNonce) {
|
|
335
361
|
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
362
|
}
|
|
337
|
-
|
|
338
|
-
throw refuse("the transaction asks for more gas than any 0x swap needs", "policy_refused");
|
|
339
|
-
}
|
|
363
|
+
checkZeroExGasLimit(tx.gasLimit, pin, expected.chainId);
|
|
340
364
|
if (typeof tx.data !== "string") throw refuse("the transaction has no data", "policy_refused");
|
|
341
365
|
const execute = decodeSettlerExecute(tx.data);
|
|
342
366
|
if (!same(execute.recipient, expected.recipient)) throw refuse(`the swap pays ${execute.recipient}, not the recipient of this swap`, "recipient_mismatch");
|
|
@@ -380,9 +404,9 @@ function checkZeroExTransaction(tx, expected) {
|
|
|
380
404
|
|
|
381
405
|
// src/activity.ts
|
|
382
406
|
var ZEROEX_MODULE = "@anywalletkit/protocol-swap2-0x";
|
|
383
|
-
function describeZeroExActivity(tx, ctx) {
|
|
407
|
+
function describeZeroExActivity(tx, ctx, chains = ZEROEX_CHAINS) {
|
|
384
408
|
const chainId = zeroExChainId(tx.chain);
|
|
385
|
-
const chain2 = zeroExChain(
|
|
409
|
+
const chain2 = zeroExChain(chains, chainId);
|
|
386
410
|
if (!chain2) return null;
|
|
387
411
|
if ((0, import_activity.callSelector)(tx) !== SETTLER_EXECUTE_SELECTOR) return null;
|
|
388
412
|
const target = tx.call?.to ?? tx.to;
|
|
@@ -504,6 +528,10 @@ function zeroExFees(response, gas) {
|
|
|
504
528
|
if (network !== null) out.push({ type: "network", amount: network.toString(), token: "native", included: false, description: "Estimated network fee (gas \xD7 gas price, as 0x reports it)" });
|
|
505
529
|
return { fees: out, networkFeeKnown: network !== null };
|
|
506
530
|
}
|
|
531
|
+
function zeroExGasEstimate(gas) {
|
|
532
|
+
const units = uint(gas);
|
|
533
|
+
return units !== null && units > 0n && units < 10000000000n ? units.toString() : void 0;
|
|
534
|
+
}
|
|
507
535
|
function taxBps(v) {
|
|
508
536
|
if (v === null || v === void 0) return null;
|
|
509
537
|
if (typeof v === "number" && Number.isFinite(v) && v >= 0) return v;
|
|
@@ -533,7 +561,7 @@ function zeroExProvider(config) {
|
|
|
533
561
|
};
|
|
534
562
|
return {
|
|
535
563
|
name: ZEROEX_PROVIDER,
|
|
536
|
-
describeActivity: describeZeroExActivity,
|
|
564
|
+
describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, chains),
|
|
537
565
|
supportsSameChain: true,
|
|
538
566
|
// 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
567
|
ownGasEstimate: true,
|
|
@@ -676,6 +704,7 @@ function zeroExProvider(config) {
|
|
|
676
704
|
const tx = plain(transaction) ? transaction : void 0;
|
|
677
705
|
const parsedFees = zeroExFees(r, tx ? { gas: own(tx, "gas"), gasPrice: own(tx, "gasPrice") } : { gas: own(r, "gas"), gasPrice: own(r, "gasPrice") });
|
|
678
706
|
if (typeof parsedFees === "string") return refuse2(parsedFees, parsedFees === UNASKED_INTEGRATOR_FEE ? "policy_refused" : "upstream_unavailable");
|
|
707
|
+
const gasEstimate = zeroExGasEstimate(tx ? own(tx, "gas") : own(r, "gas"));
|
|
679
708
|
const flags = [];
|
|
680
709
|
const issues = own(r, "issues");
|
|
681
710
|
if (plain(issues)) {
|
|
@@ -791,6 +820,7 @@ function zeroExProvider(config) {
|
|
|
791
820
|
minDestAmount: minBuyAmount.toString(),
|
|
792
821
|
feeUsd: 0,
|
|
793
822
|
fees: parsedFees.fees,
|
|
823
|
+
...gasEstimate !== void 0 ? { gasEstimate, gasEstimateSource: "venue" } : {},
|
|
794
824
|
etaSeconds: 15,
|
|
795
825
|
reliability: 0.96,
|
|
796
826
|
validUntilMs,
|
|
@@ -844,7 +874,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
|
|
|
844
874
|
throw (0, import_errors2.refusal)("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
|
|
845
875
|
}
|
|
846
876
|
const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
|
|
847
|
-
|
|
877
|
+
const chain2 = zeroExChain(ctx.chains, chainId);
|
|
878
|
+
if (!chain2) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
|
|
879
|
+
checkZeroExGasLimit(tx.gasLimit, chain2, chainId);
|
|
848
880
|
const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
|
|
849
881
|
if (!settlers.some((s) => same2(s, quoted.to))) {
|
|
850
882
|
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.");
|