@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/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, ZeroExChain, zeroExChain, zeroExChainId, zeroExChains } from './chains.cjs';
|
|
2
|
-
export { R as REGISTRY_OWNER_OF_SELECTOR, a as REGISTRY_PREV_SELECTOR, S as SETTLER_EXECUTE_SELECTOR, b as SETTLER_NATIVE_CHECK_SELECTOR, c as SETTLER_PERMIT_ACTIONS, d as SettlerAction, e as SettlerExecute, f as SettlerResolver, g as SettlerResolverConfig, Z as ZEROEX_MAX_GAS_LIMIT, h as ZEROEX_MAX_NATIVE_QUOTE_SECONDS, i as ZEROEX_MAX_PERMIT_SECONDS, j as ZEROEX_NATIVE_QUOTE_SKEW_SECONDS, k as ZEROEX_SETTLER_LOOKAHEAD, l as ZEROEX_SETTLER_SHIM_INIT_HASH, m as ZeroExCheckedTransaction, n as ZeroExExpectation, o as ZeroExTransaction, p as ZeroExTransactionError, q as
|
|
3
|
-
export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, ZeroExProvider, ZeroExProviderConfig, zeroExFees, zeroExPreflightDeposit, zeroExProvider } from './provider.cjs';
|
|
1
|
+
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_GAS_CAP_CEILING, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, ZeroExChain, isZeroExGasCap, zeroExChain, zeroExChainId, zeroExChains } from './chains.cjs';
|
|
2
|
+
export { R as REGISTRY_OWNER_OF_SELECTOR, a as REGISTRY_PREV_SELECTOR, S as SETTLER_EXECUTE_SELECTOR, b as SETTLER_NATIVE_CHECK_SELECTOR, c as SETTLER_PERMIT_ACTIONS, d as SettlerAction, e as SettlerExecute, f as SettlerResolver, g as SettlerResolverConfig, Z as ZEROEX_MAX_GAS_LIMIT, h as ZEROEX_MAX_NATIVE_QUOTE_SECONDS, i as ZEROEX_MAX_PERMIT_SECONDS, j as ZEROEX_NATIVE_QUOTE_SKEW_SECONDS, k as ZEROEX_SETTLER_LOOKAHEAD, l as ZEROEX_SETTLER_SHIM_INIT_HASH, m as ZeroExCheckedTransaction, n as ZeroExExpectation, o as ZeroExTransaction, p as ZeroExTransactionError, q as checkZeroExGasLimit, r as checkZeroExTransaction, s as createSettlerResolver, t as decodeSettlerExecute, u as isZeroExNative, z as zeroExMaxGasLimit, v as zeroExSettlerAddress, w as zeroExSettlerNonce } from './settler-CeJFLW5t.cjs';
|
|
3
|
+
export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, ZeroExProvider, ZeroExProviderConfig, zeroExFees, zeroExGasEstimate, zeroExPreflightDeposit, zeroExProvider } from './provider.cjs';
|
|
4
4
|
export { ZeroExPinsConfig, ZeroExRemoteOptions, ZeroExRemoteProvider, ZeroExVerifyContext, zeroExKnownSpenders, zeroExPins, zeroExRefusalReason, zeroExRemoteProvider, zeroExVerifyBuild, zeroExVerifyQuote } from './remote.cjs';
|
|
5
5
|
export { ZeroExSwap2Config, ZeroExSwap2Protocol, ZeroExSwap2Protocol as default } from './protocol.cjs';
|
|
6
6
|
export { ZEROEX_MODULE, describeZeroExActivity } from './activity.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, ZeroExChain, zeroExChain, zeroExChainId, zeroExChains } from './chains.js';
|
|
2
|
-
export { R as REGISTRY_OWNER_OF_SELECTOR, a as REGISTRY_PREV_SELECTOR, S as SETTLER_EXECUTE_SELECTOR, b as SETTLER_NATIVE_CHECK_SELECTOR, c as SETTLER_PERMIT_ACTIONS, d as SettlerAction, e as SettlerExecute, f as SettlerResolver, g as SettlerResolverConfig, Z as ZEROEX_MAX_GAS_LIMIT, h as ZEROEX_MAX_NATIVE_QUOTE_SECONDS, i as ZEROEX_MAX_PERMIT_SECONDS, j as ZEROEX_NATIVE_QUOTE_SKEW_SECONDS, k as ZEROEX_SETTLER_LOOKAHEAD, l as ZEROEX_SETTLER_SHIM_INIT_HASH, m as ZeroExCheckedTransaction, n as ZeroExExpectation, o as ZeroExTransaction, p as ZeroExTransactionError, q as
|
|
3
|
-
export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, ZeroExProvider, ZeroExProviderConfig, zeroExFees, zeroExPreflightDeposit, zeroExProvider } from './provider.js';
|
|
1
|
+
export { ZEROEX_ALLOWANCE_HOLDER, ZEROEX_CHAINS, ZEROEX_GAS_CAP_CEILING, ZEROEX_NATIVE, ZEROEX_PERMIT2, ZEROEX_SETTLER_MAX_NONCE, ZEROEX_SETTLER_NONCE_MARGIN, ZEROEX_SETTLER_REGISTRY, ZEROEX_TAKER_FEATURE, ZeroExChain, isZeroExGasCap, zeroExChain, zeroExChainId, zeroExChains } from './chains.js';
|
|
2
|
+
export { R as REGISTRY_OWNER_OF_SELECTOR, a as REGISTRY_PREV_SELECTOR, S as SETTLER_EXECUTE_SELECTOR, b as SETTLER_NATIVE_CHECK_SELECTOR, c as SETTLER_PERMIT_ACTIONS, d as SettlerAction, e as SettlerExecute, f as SettlerResolver, g as SettlerResolverConfig, Z as ZEROEX_MAX_GAS_LIMIT, h as ZEROEX_MAX_NATIVE_QUOTE_SECONDS, i as ZEROEX_MAX_PERMIT_SECONDS, j as ZEROEX_NATIVE_QUOTE_SKEW_SECONDS, k as ZEROEX_SETTLER_LOOKAHEAD, l as ZEROEX_SETTLER_SHIM_INIT_HASH, m as ZeroExCheckedTransaction, n as ZeroExExpectation, o as ZeroExTransaction, p as ZeroExTransactionError, q as checkZeroExGasLimit, r as checkZeroExTransaction, s as createSettlerResolver, t as decodeSettlerExecute, u as isZeroExNative, z as zeroExMaxGasLimit, v as zeroExSettlerAddress, w as zeroExSettlerNonce } from './settler-DBLrnepW.js';
|
|
3
|
+
export { ZEROEX_DEFAULT_BASE_URL, ZEROEX_PROVIDER, ZeroExProvider, ZeroExProviderConfig, zeroExFees, zeroExGasEstimate, zeroExPreflightDeposit, zeroExProvider } from './provider.js';
|
|
4
4
|
export { ZeroExPinsConfig, ZeroExRemoteOptions, ZeroExRemoteProvider, ZeroExVerifyContext, zeroExKnownSpenders, zeroExPins, zeroExRefusalReason, zeroExRemoteProvider, zeroExVerifyBuild, zeroExVerifyQuote } from './remote.js';
|
|
5
5
|
export { ZeroExSwap2Config, ZeroExSwap2Protocol, ZeroExSwap2Protocol as default } from './protocol.js';
|
|
6
6
|
export { ZEROEX_MODULE, describeZeroExActivity } from './activity.js';
|
package/dist/index.js
CHANGED
|
@@ -5,21 +5,22 @@ import {
|
|
|
5
5
|
zeroExRemoteProvider,
|
|
6
6
|
zeroExVerifyBuild,
|
|
7
7
|
zeroExVerifyQuote
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ABT2WYBK.js";
|
|
9
9
|
import {
|
|
10
10
|
ZeroExSwap2Protocol
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KYVRMBZG.js";
|
|
12
12
|
import {
|
|
13
13
|
ZEROEX_DEFAULT_BASE_URL,
|
|
14
14
|
ZEROEX_PROVIDER,
|
|
15
15
|
zeroExFees,
|
|
16
|
+
zeroExGasEstimate,
|
|
16
17
|
zeroExPreflightDeposit,
|
|
17
18
|
zeroExProvider
|
|
18
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-S2RUUV3X.js";
|
|
19
20
|
import {
|
|
20
21
|
ZEROEX_MODULE,
|
|
21
22
|
describeZeroExActivity
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-V4HUFBY2.js";
|
|
23
24
|
import {
|
|
24
25
|
REGISTRY_OWNER_OF_SELECTOR,
|
|
25
26
|
REGISTRY_PREV_SELECTOR,
|
|
@@ -33,26 +34,30 @@ import {
|
|
|
33
34
|
ZEROEX_SETTLER_LOOKAHEAD,
|
|
34
35
|
ZEROEX_SETTLER_SHIM_INIT_HASH,
|
|
35
36
|
ZeroExTransactionError,
|
|
37
|
+
checkZeroExGasLimit,
|
|
36
38
|
checkZeroExTransaction,
|
|
37
39
|
createSettlerResolver,
|
|
38
40
|
decodeSettlerExecute,
|
|
39
41
|
isZeroExNative,
|
|
42
|
+
zeroExMaxGasLimit,
|
|
40
43
|
zeroExSettlerAddress,
|
|
41
44
|
zeroExSettlerNonce
|
|
42
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-YHRPT6BS.js";
|
|
43
46
|
import {
|
|
44
47
|
ZEROEX_ALLOWANCE_HOLDER,
|
|
45
48
|
ZEROEX_CHAINS,
|
|
49
|
+
ZEROEX_GAS_CAP_CEILING,
|
|
46
50
|
ZEROEX_NATIVE,
|
|
47
51
|
ZEROEX_PERMIT2,
|
|
48
52
|
ZEROEX_SETTLER_MAX_NONCE,
|
|
49
53
|
ZEROEX_SETTLER_NONCE_MARGIN,
|
|
50
54
|
ZEROEX_SETTLER_REGISTRY,
|
|
51
55
|
ZEROEX_TAKER_FEATURE,
|
|
56
|
+
isZeroExGasCap,
|
|
52
57
|
zeroExChain,
|
|
53
58
|
zeroExChainId,
|
|
54
59
|
zeroExChains
|
|
55
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-AMZ5DXN2.js";
|
|
56
61
|
export {
|
|
57
62
|
REGISTRY_OWNER_OF_SELECTOR,
|
|
58
63
|
REGISTRY_PREV_SELECTOR,
|
|
@@ -62,6 +67,7 @@ export {
|
|
|
62
67
|
ZEROEX_ALLOWANCE_HOLDER,
|
|
63
68
|
ZEROEX_CHAINS,
|
|
64
69
|
ZEROEX_DEFAULT_BASE_URL,
|
|
70
|
+
ZEROEX_GAS_CAP_CEILING,
|
|
65
71
|
ZEROEX_MAX_GAS_LIMIT,
|
|
66
72
|
ZEROEX_MAX_NATIVE_QUOTE_SECONDS,
|
|
67
73
|
ZEROEX_MAX_PERMIT_SECONDS,
|
|
@@ -78,17 +84,21 @@ export {
|
|
|
78
84
|
ZEROEX_TAKER_FEATURE,
|
|
79
85
|
ZeroExSwap2Protocol,
|
|
80
86
|
ZeroExTransactionError,
|
|
87
|
+
checkZeroExGasLimit,
|
|
81
88
|
checkZeroExTransaction,
|
|
82
89
|
createSettlerResolver,
|
|
83
90
|
decodeSettlerExecute,
|
|
84
91
|
ZeroExSwap2Protocol as default,
|
|
85
92
|
describeZeroExActivity,
|
|
93
|
+
isZeroExGasCap,
|
|
86
94
|
isZeroExNative,
|
|
87
95
|
zeroExChain,
|
|
88
96
|
zeroExChainId,
|
|
89
97
|
zeroExChains,
|
|
90
98
|
zeroExFees,
|
|
99
|
+
zeroExGasEstimate,
|
|
91
100
|
zeroExKnownSpenders,
|
|
101
|
+
zeroExMaxGasLimit,
|
|
92
102
|
zeroExPins,
|
|
93
103
|
zeroExPreflightDeposit,
|
|
94
104
|
zeroExProvider,
|
package/dist/protocol.cjs
CHANGED
|
@@ -41,14 +41,17 @@ var ZEROEX_PERMIT2 = import_util.PERMIT2_ADDRESS;
|
|
|
41
41
|
var ZEROEX_SETTLER_REGISTRY = "0x00000000000004533Fe15556B1E086BB1A72cEae";
|
|
42
42
|
var ZEROEX_TAKER_FEATURE = 2;
|
|
43
43
|
var ZEROEX_NATIVE = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
44
|
+
var ZEROEX_GAS_CAP_CEILING = 30000000n;
|
|
45
|
+
var isZeroExGasCap = (v) => typeof v === "bigint" && v >= 1n && v <= ZEROEX_GAS_CAP_CEILING;
|
|
44
46
|
var ZEROEX_SETTLER_NONCE_MARGIN = 2;
|
|
45
47
|
var ZEROEX_SETTLER_MAX_NONCE = 1024;
|
|
46
|
-
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative });
|
|
48
|
+
var chain = (name, wrappedNative, newestLiveNonce, previousLiveNonce, maxGasLimit) => Object.freeze({ name, registry: ZEROEX_SETTLER_REGISTRY, newestLiveNonce, previousLiveNonce, wrappedNative, ...maxGasLimit !== void 0 ? { maxGasLimit } : {} });
|
|
47
49
|
var ZEROEX_CHAINS = Object.freeze({
|
|
48
50
|
1: chain("Ethereum", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 22, 21),
|
|
49
51
|
10: chain("Optimism", "0x4200000000000000000000000000000000000006", 22, 21),
|
|
50
52
|
56: chain("BNB Smart Chain", "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", 24, 23),
|
|
51
53
|
137: chain("Polygon", "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", 21, 20),
|
|
54
|
+
143: chain("Monad", "0x3bd359C1119dA7Da1D913D1C4D2B7c461115433A", 12, 11, 15000000n),
|
|
52
55
|
8453: chain("Base", "0x4200000000000000000000000000000000000006", 23, 22),
|
|
53
56
|
42161: chain("Arbitrum", "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", 21, 20),
|
|
54
57
|
43114: chain("Avalanche", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", 21, 20)
|
|
@@ -77,7 +80,16 @@ function zeroExChains(overrides) {
|
|
|
77
80
|
if (!Number.isSafeInteger(previous) || previous < 1 || previous > newest) {
|
|
78
81
|
throw new Error(`zeroex: chain ${id} pins no previous live Settler deployment (previousLiveNonce, 1 to its newestLiveNonce)`);
|
|
79
82
|
}
|
|
80
|
-
|
|
83
|
+
const gasCap = entry.maxGasLimit;
|
|
84
|
+
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}`);
|
|
85
|
+
out[id] = Object.freeze({
|
|
86
|
+
name: entry.name,
|
|
87
|
+
registry: entry.registry,
|
|
88
|
+
newestLiveNonce: newest,
|
|
89
|
+
previousLiveNonce: previous,
|
|
90
|
+
...entry.wrappedNative ? { wrappedNative: entry.wrappedNative } : {},
|
|
91
|
+
...gasCap !== void 0 ? { maxGasLimit: gasCap } : {}
|
|
92
|
+
});
|
|
81
93
|
}
|
|
82
94
|
return Object.freeze(out);
|
|
83
95
|
}
|
|
@@ -310,6 +322,19 @@ function decodeSettlerExecute(data) {
|
|
|
310
322
|
return Object.freeze({ recipient, buyToken, minAmountOut, zidAndAffiliate, actions: Object.freeze(actions), bodyLength, word });
|
|
311
323
|
}
|
|
312
324
|
var ZEROEX_MAX_GAS_LIMIT = 6000000n;
|
|
325
|
+
function zeroExMaxGasLimit(chain2, chainId) {
|
|
326
|
+
const cap = chain2.maxGasLimit;
|
|
327
|
+
if (cap === void 0) return ZEROEX_MAX_GAS_LIMIT;
|
|
328
|
+
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}`);
|
|
329
|
+
return cap;
|
|
330
|
+
}
|
|
331
|
+
function checkZeroExGasLimit(gasLimit, chain2, chainId) {
|
|
332
|
+
const cap = zeroExMaxGasLimit(chain2, chainId);
|
|
333
|
+
if (gasLimit === void 0) return;
|
|
334
|
+
if (typeof gasLimit !== "string" || !/^[0-9]{1,12}$/.test(gasLimit) || BigInt(gasLimit) === 0n || BigInt(gasLimit) > cap) {
|
|
335
|
+
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");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
313
338
|
function checkZeroExTransaction(tx, expected) {
|
|
314
339
|
if (!Number.isSafeInteger(expected.chainId) || expected.chainId <= 0) throw refuse("the swap names no EVM chain");
|
|
315
340
|
if (!ADDRESS2.test(expected.recipient) || ZERO_ADDRESS2.test(expected.recipient)) throw refuse("the swap names no recipient");
|
|
@@ -333,9 +358,7 @@ function checkZeroExTransaction(tx, expected) {
|
|
|
333
358
|
if (value > 0n && deployment !== pin.newestLiveNonce && deployment !== pin.previousLiveNonce) {
|
|
334
359
|
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");
|
|
335
360
|
}
|
|
336
|
-
|
|
337
|
-
throw refuse("the transaction asks for more gas than any 0x swap needs", "policy_refused");
|
|
338
|
-
}
|
|
361
|
+
checkZeroExGasLimit(tx.gasLimit, pin, expected.chainId);
|
|
339
362
|
if (typeof tx.data !== "string") throw refuse("the transaction has no data", "policy_refused");
|
|
340
363
|
const execute = decodeSettlerExecute(tx.data);
|
|
341
364
|
if (!same(execute.recipient, expected.recipient)) throw refuse(`the swap pays ${execute.recipient}, not the recipient of this swap`, "recipient_mismatch");
|
|
@@ -379,9 +402,9 @@ function checkZeroExTransaction(tx, expected) {
|
|
|
379
402
|
|
|
380
403
|
// src/activity.ts
|
|
381
404
|
var ZEROEX_MODULE = "@anywalletkit/protocol-swap2-0x";
|
|
382
|
-
function describeZeroExActivity(tx, ctx) {
|
|
405
|
+
function describeZeroExActivity(tx, ctx, chains = ZEROEX_CHAINS) {
|
|
383
406
|
const chainId = zeroExChainId(tx.chain);
|
|
384
|
-
const chain2 = zeroExChain(
|
|
407
|
+
const chain2 = zeroExChain(chains, chainId);
|
|
385
408
|
if (!chain2) return null;
|
|
386
409
|
if ((0, import_activity.callSelector)(tx) !== SETTLER_EXECUTE_SELECTOR) return null;
|
|
387
410
|
const target = tx.call?.to ?? tx.to;
|
|
@@ -503,6 +526,10 @@ function zeroExFees(response, gas) {
|
|
|
503
526
|
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)" });
|
|
504
527
|
return { fees: out, networkFeeKnown: network !== null };
|
|
505
528
|
}
|
|
529
|
+
function zeroExGasEstimate(gas) {
|
|
530
|
+
const units = uint(gas);
|
|
531
|
+
return units !== null && units > 0n && units < 10000000000n ? units.toString() : void 0;
|
|
532
|
+
}
|
|
506
533
|
function taxBps(v) {
|
|
507
534
|
if (v === null || v === void 0) return null;
|
|
508
535
|
if (typeof v === "number" && Number.isFinite(v) && v >= 0) return v;
|
|
@@ -532,7 +559,7 @@ function zeroExProvider(config) {
|
|
|
532
559
|
};
|
|
533
560
|
return {
|
|
534
561
|
name: ZEROEX_PROVIDER,
|
|
535
|
-
describeActivity: describeZeroExActivity,
|
|
562
|
+
describeActivity: (tx, ctx) => describeZeroExActivity(tx, ctx, chains),
|
|
536
563
|
supportsSameChain: true,
|
|
537
564
|
// The quoted gas limit is the API's word: a native sale (like a Permit2 call) goes out with the account's own estimate.
|
|
538
565
|
ownGasEstimate: true,
|
|
@@ -675,6 +702,7 @@ function zeroExProvider(config) {
|
|
|
675
702
|
const tx = plain(transaction) ? transaction : void 0;
|
|
676
703
|
const parsedFees = zeroExFees(r, tx ? { gas: own(tx, "gas"), gasPrice: own(tx, "gasPrice") } : { gas: own(r, "gas"), gasPrice: own(r, "gasPrice") });
|
|
677
704
|
if (typeof parsedFees === "string") return refuse2(parsedFees, parsedFees === UNASKED_INTEGRATOR_FEE ? "policy_refused" : "upstream_unavailable");
|
|
705
|
+
const gasEstimate = zeroExGasEstimate(tx ? own(tx, "gas") : own(r, "gas"));
|
|
678
706
|
const flags = [];
|
|
679
707
|
const issues = own(r, "issues");
|
|
680
708
|
if (plain(issues)) {
|
|
@@ -790,6 +818,7 @@ function zeroExProvider(config) {
|
|
|
790
818
|
minDestAmount: minBuyAmount.toString(),
|
|
791
819
|
feeUsd: 0,
|
|
792
820
|
fees: parsedFees.fees,
|
|
821
|
+
...gasEstimate !== void 0 ? { gasEstimate, gasEstimateSource: "venue" } : {},
|
|
793
822
|
etaSeconds: 15,
|
|
794
823
|
reliability: 0.96,
|
|
795
824
|
validUntilMs,
|
|
@@ -843,7 +872,9 @@ async function zeroExPreflightDeposit(quote, tx, ctx) {
|
|
|
843
872
|
throw (0, import_errors2.refusal)("policy_refused", "zeroex: the transaction is not the quoted swap. Nothing was sent; refresh the quote.");
|
|
844
873
|
}
|
|
845
874
|
const chainId = typeof quote.intentId === "string" ? Number(quote.intentId.split(":")[1]) : NaN;
|
|
846
|
-
|
|
875
|
+
const chain2 = zeroExChain(ctx.chains, chainId);
|
|
876
|
+
if (!chain2) throw (0, import_errors2.refusal)("policy_refused", "zeroex: the quote names no chain this provider serves. Nothing was sent.");
|
|
877
|
+
checkZeroExGasLimit(tx.gasLimit, chain2, chainId);
|
|
847
878
|
const settlers = await ctx.resolver.resolve(chainId, { fresh: true });
|
|
848
879
|
if (!settlers.some((s) => same2(s, quoted.to))) {
|
|
849
880
|
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.");
|