@anywalletkit/protocol-swap2-lifi 0.0.0-stage → 0.2.2
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 +30 -2
- package/dist/activity.cjs +57 -0
- package/dist/activity.cjs.map +1 -0
- package/dist/activity.d.cts +22 -0
- package/dist/activity.d.ts +22 -0
- package/dist/activity.js +11 -0
- package/dist/activity.js.map +1 -0
- package/dist/chunk-2IAHMTPT.js +443 -0
- package/dist/chunk-2IAHMTPT.js.map +1 -0
- package/dist/chunk-6N4HZ5XX.js +22 -0
- package/dist/chunk-6N4HZ5XX.js.map +1 -0
- package/dist/chunk-EU7XQVZQ.js +37 -0
- package/dist/chunk-EU7XQVZQ.js.map +1 -0
- package/dist/chunk-IOX56IRJ.js +27 -0
- package/dist/chunk-IOX56IRJ.js.map +1 -0
- package/dist/config.cjs +42 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +11 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +9 -0
- package/dist/config.js.map +1 -0
- package/dist/index.cjs +528 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +521 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +15 -0
- package/dist/protocol.d.ts +15 -0
- package/dist/protocol.js +10 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +505 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +54 -0
- package/dist/provider.d.ts +54 -0
- package/dist/provider.js +9 -0
- package/dist/provider.js.map +1 -0
- package/module.json +17 -0
- package/package.json +69 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lifiProvider
|
|
3
|
+
} from "./chunk-2IAHMTPT.js";
|
|
4
|
+
import {
|
|
5
|
+
lifi
|
|
6
|
+
} from "./chunk-6N4HZ5XX.js";
|
|
7
|
+
|
|
8
|
+
// src/protocol.ts
|
|
9
|
+
import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
|
|
10
|
+
var LifiSwap2Protocol = class extends SingleProviderSwap2 {
|
|
11
|
+
provider;
|
|
12
|
+
constructor(account, config) {
|
|
13
|
+
super(account, config);
|
|
14
|
+
this.provider = lifiProvider(config);
|
|
15
|
+
}
|
|
16
|
+
chainSupported(caip2) {
|
|
17
|
+
return lifi.supportsChain(caip2);
|
|
18
|
+
}
|
|
19
|
+
pairSupported(fromChain, toChain) {
|
|
20
|
+
return lifi.supports(fromChain, toChain);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
LifiSwap2Protocol
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-IOX56IRJ.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 {lifi as lifiCfg} from \"./config.js\";\nimport {lifiProvider, type LifiProviderConfig} from \"./provider.js\";\n\nexport interface LifiSwap2Config extends Swap2EngineConfig, LifiProviderConfig {}\n\nexport class LifiSwap2Protocol extends SingleProviderSwap2 {\n protected readonly provider;\n constructor(account: Swap2Account | undefined, config: LifiSwap2Config) {\n super(account, config);\n this.provider = lifiProvider(config);\n }\n protected override chainSupported(caip2: string): boolean {\n return lifiCfg.supportsChain(caip2);\n }\n protected override pairSupported(fromChain: string, toChain: string): boolean {\n return lifiCfg.supports(fromChain, toChain);\n }\n}\n"],"mappings":";;;;;;;;AAAA,SAAQ,2BAA0B;AAO3B,IAAM,oBAAN,cAAgC,oBAAoB;AAAA,EACtC;AAAA,EACnB,YAAY,SAAmC,QAAyB;AACtE,UAAM,SAAS,MAAM;AACrB,SAAK,WAAW,aAAa,MAAM;AAAA,EACrC;AAAA,EACmB,eAAe,OAAwB;AACxD,WAAO,KAAQ,cAAc,KAAK;AAAA,EACpC;AAAA,EACmB,cAAc,WAAmB,SAA0B;AAC5E,WAAO,KAAQ,SAAS,WAAW,OAAO;AAAA,EAC5C;AACF;","names":[]}
|
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/config.ts
|
|
21
|
+
var config_exports = {};
|
|
22
|
+
__export(config_exports, {
|
|
23
|
+
LIFI_SOLANA_CAIP2: () => LIFI_SOLANA_CAIP2,
|
|
24
|
+
lifi: () => lifi
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(config_exports);
|
|
27
|
+
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
28
|
+
var LIFI_SOLANA_CAIP2 = "solana:mainnet";
|
|
29
|
+
var LIFI_EVM = /* @__PURE__ */ new Set([1, 8453, 56, 137, 42161, 10, 100, 143, 130, 999, 4663, 43114, 534352, 80094, 324, 42220, 4326, 9745, 59144, 146, 480, 1329, 57073, 98866, 196, 5042, 5e3, 747474, 2818, 14]);
|
|
30
|
+
var lifi = {
|
|
31
|
+
enabled: () => true,
|
|
32
|
+
apiKey: () => void 0,
|
|
33
|
+
integrator: () => "",
|
|
34
|
+
supportsChain(chain) {
|
|
35
|
+
if ((0, import_util.isEvm)(chain)) return LIFI_EVM.has((0, import_util.evmRef)(chain));
|
|
36
|
+
return chain === LIFI_SOLANA_CAIP2;
|
|
37
|
+
},
|
|
38
|
+
supports(from, to) {
|
|
39
|
+
return this.supportsChain(from) && this.supportsChain(to);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=config.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import {evmRef, isEvm} from \"@anywalletkit/protocol-swap2-core/util\";\n\n// ── LI.FI — EVM calldata routes implemented by this contribution adapter ─────\n// 2026-08 sweep (li.quest/v1/chains): + Avalanche 43114, Scroll 534352,\n// Berachain 80094 (HyperEVM 999 / Robinhood 4663 were already routed by the\n// provider's own chain map).\n/** The catalog's Solana id; LI.FI numbers it 1151111081099710. */\nexport const LIFI_SOLANA_CAIP2 = \"solana:mainnet\";\nconst LIFI_EVM = new Set([1, 8453, 56, 137, 42161, 10, 100, 143, 130, 999, 4663, 43114, 534352, 80094, 324, 42220, 4326, 9745, 59144, 146, 480, 1329, 57073, 98866, 196, 5042, 5000, 747474, 2818, 14]);\nexport const lifi = {\n enabled: () => true,\n apiKey: () => undefined,\n integrator: () => \"\",\n supportsChain(chain: string): boolean {\n if (isEvm(chain)) return LIFI_EVM.has(evmRef(chain));\n // Solana legs come back as a serialized transaction the account executes\n // through its `sendSerializedTransaction` guard. Tron is still excluded.\n return chain === LIFI_SOLANA_CAIP2;\n },\n supports(from: string, to: string): boolean {\n return this.supportsChain(from) && this.supportsChain(to);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA4B;AAOrB,IAAM,oBAAoB;AACjC,IAAM,WAAW,oBAAI,IAAI,CAAC,GAAG,MAAM,IAAI,KAAK,OAAO,IAAI,KAAK,KAAK,KAAK,KAAK,MAAM,OAAO,QAAQ,OAAO,KAAK,OAAO,MAAM,MAAM,OAAO,KAAK,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,KAAM,QAAQ,MAAM,EAAE,CAAC;AAC/L,IAAM,OAAO;AAAA,EAClB,SAAS,MAAM;AAAA,EACf,QAAQ,MAAM;AAAA,EACd,YAAY,MAAM;AAAA,EAClB,cAAc,OAAwB;AACpC,YAAI,mBAAM,KAAK,EAAG,QAAO,SAAS,QAAI,oBAAO,KAAK,CAAC;AAGnD,WAAO,UAAU;AAAA,EACnB;AAAA,EACA,SAAS,MAAc,IAAqB;AAC1C,WAAO,KAAK,cAAc,IAAI,KAAK,KAAK,cAAc,EAAE;AAAA,EAC1D;AACF;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The catalog's Solana id; LI.FI numbers it 1151111081099710. */
|
|
2
|
+
declare const LIFI_SOLANA_CAIP2 = "solana:mainnet";
|
|
3
|
+
declare const lifi: {
|
|
4
|
+
enabled: () => boolean;
|
|
5
|
+
apiKey: () => undefined;
|
|
6
|
+
integrator: () => string;
|
|
7
|
+
supportsChain(chain: string): boolean;
|
|
8
|
+
supports(from: string, to: string): boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { LIFI_SOLANA_CAIP2, lifi };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The catalog's Solana id; LI.FI numbers it 1151111081099710. */
|
|
2
|
+
declare const LIFI_SOLANA_CAIP2 = "solana:mainnet";
|
|
3
|
+
declare const lifi: {
|
|
4
|
+
enabled: () => boolean;
|
|
5
|
+
apiKey: () => undefined;
|
|
6
|
+
integrator: () => string;
|
|
7
|
+
supportsChain(chain: string): boolean;
|
|
8
|
+
supports(from: string, to: string): boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { LIFI_SOLANA_CAIP2, lifi };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
LIFI_MODULE: () => LIFI_MODULE,
|
|
24
|
+
LIFI_SAME_CHAIN_SELECTORS: () => LIFI_SAME_CHAIN_SELECTORS,
|
|
25
|
+
LIFI_SOLANA_CAIP2: () => LIFI_SOLANA_CAIP2,
|
|
26
|
+
LifiSwap2Protocol: () => LifiSwap2Protocol,
|
|
27
|
+
default: () => LifiSwap2Protocol,
|
|
28
|
+
describeLifiActivity: () => describeLifiActivity,
|
|
29
|
+
lifi: () => lifi,
|
|
30
|
+
lifiProvider: () => lifiProvider
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(src_exports);
|
|
33
|
+
|
|
34
|
+
// src/config.ts
|
|
35
|
+
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
36
|
+
var LIFI_SOLANA_CAIP2 = "solana:mainnet";
|
|
37
|
+
var LIFI_EVM = /* @__PURE__ */ new Set([1, 8453, 56, 137, 42161, 10, 100, 143, 130, 999, 4663, 43114, 534352, 80094, 324, 42220, 4326, 9745, 59144, 146, 480, 1329, 57073, 98866, 196, 5042, 5e3, 747474, 2818, 14]);
|
|
38
|
+
var lifi = {
|
|
39
|
+
enabled: () => true,
|
|
40
|
+
apiKey: () => void 0,
|
|
41
|
+
integrator: () => "",
|
|
42
|
+
supportsChain(chain) {
|
|
43
|
+
if ((0, import_util.isEvm)(chain)) return LIFI_EVM.has((0, import_util.evmRef)(chain));
|
|
44
|
+
return chain === LIFI_SOLANA_CAIP2;
|
|
45
|
+
},
|
|
46
|
+
supports(from, to) {
|
|
47
|
+
return this.supportsChain(from) && this.supportsChain(to);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/activity.ts
|
|
52
|
+
var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
|
|
53
|
+
var LIFI_MODULE = "@anywalletkit/protocol-swap2-lifi";
|
|
54
|
+
var LIFI_SAME_CHAIN_SELECTORS = /* @__PURE__ */ new Set([
|
|
55
|
+
"0x4666fc80",
|
|
56
|
+
// swapTokensSingleV3ERC20ToERC20(bytes32,string,string,address,uint256,(address,address,address,address,uint256,bytes,bool))
|
|
57
|
+
"0x733214a3",
|
|
58
|
+
// swapTokensSingleV3ERC20ToNative(…)
|
|
59
|
+
"0xaf7060fd",
|
|
60
|
+
// swapTokensSingleV3NativeToERC20(…)
|
|
61
|
+
"0x5fd9ae2e",
|
|
62
|
+
// swapTokensMultipleV3ERC20ToERC20(bytes32,string,string,address,uint256,(…)[])
|
|
63
|
+
"0x2c57e884",
|
|
64
|
+
// swapTokensMultipleV3ERC20ToNative(…[])
|
|
65
|
+
"0x736eac0b"
|
|
66
|
+
// swapTokensMultipleV3NativeToERC20(…[])
|
|
67
|
+
]);
|
|
68
|
+
function describeLifiActivity(tx, ctx, isDiamond) {
|
|
69
|
+
if (!tx.chain.startsWith("eip155:")) return null;
|
|
70
|
+
const to = (0, import_activity.calledContract)(tx);
|
|
71
|
+
if (!to || !isDiamond(tx.chain, to)) return null;
|
|
72
|
+
const selector = (0, import_activity.callSelector)(tx);
|
|
73
|
+
const sameChain = selector !== void 0 && LIFI_SAME_CHAIN_SELECTORS.has(selector);
|
|
74
|
+
return (0, import_activity.describeSwapLike)(tx, ctx, {
|
|
75
|
+
protocol: LIFI_MODULE,
|
|
76
|
+
subtitle: "LI.FI",
|
|
77
|
+
// Unknown selector: trust the legs — both netted here means a same-chain route.
|
|
78
|
+
kind: sameChain ? "swap" : selector === void 0 ? "auto" : "bridge"
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/provider.ts
|
|
83
|
+
var import_swap2_assets = require("@anywalletkit/swap2-assets");
|
|
84
|
+
var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
|
|
85
|
+
var DEFAULT_LIFI_BASE = "https://li.quest/v1";
|
|
86
|
+
var LIFI_CHAIN = {
|
|
87
|
+
"eip155:1": "1",
|
|
88
|
+
"eip155:8453": "8453",
|
|
89
|
+
"eip155:56": "56",
|
|
90
|
+
"eip155:137": "137",
|
|
91
|
+
"eip155:42161": "42161",
|
|
92
|
+
"eip155:10": "10",
|
|
93
|
+
"eip155:100": "100",
|
|
94
|
+
"eip155:143": "143",
|
|
95
|
+
"eip155:130": "130",
|
|
96
|
+
"eip155:999": "999",
|
|
97
|
+
"eip155:4663": "4663",
|
|
98
|
+
// 2026-08 sweep additions (all live on li.quest/v1/chains).
|
|
99
|
+
"eip155:43114": "43114",
|
|
100
|
+
"eip155:534352": "534352",
|
|
101
|
+
"eip155:80094": "80094",
|
|
102
|
+
// 2026-10-12: zkSync Era, Celo, MegaETH (live on li.quest/v1/chains).
|
|
103
|
+
"eip155:324": "324",
|
|
104
|
+
"eip155:42220": "42220",
|
|
105
|
+
"eip155:4326": "4326",
|
|
106
|
+
"eip155:9745": "9745",
|
|
107
|
+
"eip155:59144": "59144",
|
|
108
|
+
"eip155:146": "146",
|
|
109
|
+
// 2026-10-13: World Chain, Sei, Ink, Plume, X Layer (live on li.quest/v1/chains).
|
|
110
|
+
"eip155:480": "480",
|
|
111
|
+
"eip155:1329": "1329",
|
|
112
|
+
"eip155:57073": "57073",
|
|
113
|
+
"eip155:98866": "98866",
|
|
114
|
+
"eip155:196": "196",
|
|
115
|
+
// 2026-10-14: Arc, Mantle, Katana, Morph, Flare (live on li.quest/v1/chains). On Arc LI.FI's "native" is the USDC
|
|
116
|
+
// ERC-20 interface 0x3600…: a 0x0 fromToken is rewritten to it and the Diamond pulls via transferFrom (value 0), so
|
|
117
|
+
// the catalog lists Arc USDC as that token — the engine then runs the ordinary approve + call path.
|
|
118
|
+
"eip155:5042": "5042",
|
|
119
|
+
"eip155:5000": "5000",
|
|
120
|
+
"eip155:747474": "747474",
|
|
121
|
+
"eip155:2818": "2818",
|
|
122
|
+
"eip155:14": "14",
|
|
123
|
+
[LIFI_SOLANA_CAIP2]: "1151111081099710"
|
|
124
|
+
};
|
|
125
|
+
var CAIP2_BY_LIFI_CHAIN = Object.fromEntries(Object.entries(LIFI_CHAIN).map(([caip2, id]) => [id, caip2]));
|
|
126
|
+
var EVM_ZERO = "0x0000000000000000000000000000000000000000";
|
|
127
|
+
var SOLANA_NATIVE = "11111111111111111111111111111111";
|
|
128
|
+
var EVM_PLACEHOLDER = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
|
|
129
|
+
var SOLANA_PLACEHOLDER = "HAgk14JpMQLgt6rVgv7cBQFJWFto5Dqxi472uT3DKpqk";
|
|
130
|
+
var isSolana = (chain) => chain === LIFI_SOLANA_CAIP2;
|
|
131
|
+
var BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
132
|
+
var BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
133
|
+
var SAME_CHAIN_MAX_SECONDS = 90;
|
|
134
|
+
var MAX_INPUT_FEE_BPS = 300;
|
|
135
|
+
function sameChainAddress(chain, actual, expected) {
|
|
136
|
+
if (isSolana(chain)) return !!actual && BASE58.test(actual) && actual === expected;
|
|
137
|
+
return sameAddress(actual, expected);
|
|
138
|
+
}
|
|
139
|
+
function nativeFor(chain, token) {
|
|
140
|
+
if (/^0x0+$/.test(token) || token === SOLANA_NATIVE) return isSolana(chain) ? SOLANA_NATIVE : EVM_ZERO;
|
|
141
|
+
return token;
|
|
142
|
+
}
|
|
143
|
+
var LIFI_DIAMOND = "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE";
|
|
144
|
+
var LIFI_DIAMONDS = {
|
|
145
|
+
"eip155:4663": "0xB477751B76CF82d00a686A1232f5fCD772414Af3",
|
|
146
|
+
// Robinhood Chain (deployments/robinhood.json, verified 2026-10-09)
|
|
147
|
+
"eip155:999": "0x0a0758d937d1059c356D4714e57F5df0239bce1A",
|
|
148
|
+
// HyperEVM (deployments/hyperevm.json, verified 2026-10-09)
|
|
149
|
+
"eip155:143": "0x026F252016A7C47CDEf1F05a3Fc9E20C92a49C37",
|
|
150
|
+
// Monad (deployments/monad.json, verified 2026-10-11)
|
|
151
|
+
"eip155:130": "0x864b314D4C5a0399368609581d3E8933a63b9232",
|
|
152
|
+
// Unichain (deployments/unichain.json, verified 2026-10-11)
|
|
153
|
+
"eip155:80094": "0xf909c4Ae16622898b885B89d7F839E0244851c66",
|
|
154
|
+
// Berachain (deployments/berachain.json, verified 2026-10-11)
|
|
155
|
+
"eip155:324": "0x341e94069f53234fE6DabeF707aD424830525715",
|
|
156
|
+
// zkSync Era (deployments/zksync.json, matches a live quote 2026-10-12)
|
|
157
|
+
"eip155:9745": "0x026F252016A7C47CDEf1F05a3Fc9E20C92a49C37",
|
|
158
|
+
// Plasma (deployments/plasma.json, 2026-10-13)
|
|
159
|
+
"eip155:59144": "0xDE1E598b81620773454588B85D6b5D4eEC32573e",
|
|
160
|
+
// Linea (deployments/linea.json, 2026-10-13)
|
|
161
|
+
"eip155:57073": "0x864b314D4C5a0399368609581d3E8933a63b9232",
|
|
162
|
+
// Ink (deployments/ink.json, 2026-10-13)
|
|
163
|
+
"eip155:98866": "0x6f5C8Bb0C5Fe4ECeAC40EE1C238EaB6bbb29761c",
|
|
164
|
+
// Plume (deployments/plume.json, 2026-10-13)
|
|
165
|
+
// 2026-10-14: li.quest/v1/chains `diamondAddress`, eth_getCode non-empty on each. Mantle and Flare carry the canonical
|
|
166
|
+
// 0x1231… Diamond (the default).
|
|
167
|
+
"eip155:5042": "0xA4072583658Fae592A3506A42431cb6316a8d40b",
|
|
168
|
+
// Arc
|
|
169
|
+
"eip155:747474": "0xC59fe32C9549e3E8B5dCcdAbC45BD287Bd5bA2bc",
|
|
170
|
+
// Katana
|
|
171
|
+
"eip155:2818": "0xF7aB42D00D2399f8A4Fba2F15466Be40709fe307",
|
|
172
|
+
// Morph
|
|
173
|
+
"eip155:14": "0x198FC70Dfe05E755C81e54bd67Bff3F729344B9b",
|
|
174
|
+
// Flare (li.quest diamondAddress 2026-10-14; the canonical 0x1231… has no code there)
|
|
175
|
+
"eip155:4326": "0x026F252016A7C47CDEf1F05a3Fc9E20C92a49C37"
|
|
176
|
+
// MegaETH (deployments/megaeth.json, matches a live quote 2026-10-12)
|
|
177
|
+
};
|
|
178
|
+
var diamondFor = (chain) => LIFI_DIAMONDS[chain] ?? LIFI_DIAMOND;
|
|
179
|
+
var DEFAULT_QUOTE_TTL_MS = 55e3;
|
|
180
|
+
function normalizeAddress(value) {
|
|
181
|
+
return value && /^0x[0-9a-fA-F]{40}$/.test(value) ? value.toLowerCase() : null;
|
|
182
|
+
}
|
|
183
|
+
function sameAddress(actual, expected) {
|
|
184
|
+
return normalizeAddress(actual) === normalizeAddress(expected);
|
|
185
|
+
}
|
|
186
|
+
function isHexData(value) {
|
|
187
|
+
return !!value && /^0x(?:[0-9a-fA-F]{2})+$/.test(value);
|
|
188
|
+
}
|
|
189
|
+
function trustedAddress(chain, address, configured) {
|
|
190
|
+
const normalized = normalizeAddress(address);
|
|
191
|
+
if (!normalized) return false;
|
|
192
|
+
return normalizeAddress(diamondFor(chain)) === normalized || configured.get(chain)?.has(normalized) === true;
|
|
193
|
+
}
|
|
194
|
+
function trustMap(input, label) {
|
|
195
|
+
const out = /* @__PURE__ */ new Map();
|
|
196
|
+
for (const [chain, addresses] of Object.entries(input ?? {})) {
|
|
197
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
198
|
+
for (const address of addresses) {
|
|
199
|
+
const value = normalizeAddress(address);
|
|
200
|
+
if (!value) throw new Error(`lifi: invalid ${label} address for ${chain}`);
|
|
201
|
+
normalized.add(value);
|
|
202
|
+
}
|
|
203
|
+
out.set(chain, normalized);
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
function lifiToken(sourceChain, symbol) {
|
|
208
|
+
const asset = (0, import_swap2_assets.ccAsset)(sourceChain, symbol);
|
|
209
|
+
if (!asset) return null;
|
|
210
|
+
if (asset.contract) return asset.contract;
|
|
211
|
+
return isSolana(sourceChain) ? SOLANA_NATIVE : EVM_ZERO;
|
|
212
|
+
}
|
|
213
|
+
function headers(key) {
|
|
214
|
+
const h = { accept: "application/json" };
|
|
215
|
+
if (key) h["x-lifi-api-key"] = key;
|
|
216
|
+
return h;
|
|
217
|
+
}
|
|
218
|
+
var TOOL_KEY = /^[A-Za-z0-9_-]{1,64}$/;
|
|
219
|
+
function routeOptions(body) {
|
|
220
|
+
const routes = body?.routes;
|
|
221
|
+
if (!Array.isArray(routes)) return [];
|
|
222
|
+
const out = [];
|
|
223
|
+
for (const r of routes) {
|
|
224
|
+
if (!Array.isArray(r?.steps) || r.steps.length !== 1 || r.containsSwitchChain === true) continue;
|
|
225
|
+
const step = r.steps[0];
|
|
226
|
+
const cross = Array.isArray(step.includedSteps) ? step.includedSteps.find((i) => i?.type === "cross")?.tool : void 0;
|
|
227
|
+
const tool = typeof cross === "string" ? cross : step.tool;
|
|
228
|
+
const eta = step.estimate?.executionDuration;
|
|
229
|
+
if (typeof tool !== "string" || !TOOL_KEY.test(tool) || typeof eta !== "number" || !Number.isFinite(eta) || eta < 0) continue;
|
|
230
|
+
if (typeof r.toAmount !== "string" || typeof r.toAmountMin !== "string" || !/^\d{1,60}$/.test(r.toAmount) || !/^\d{1,60}$/.test(r.toAmountMin)) continue;
|
|
231
|
+
out.push({
|
|
232
|
+
tool,
|
|
233
|
+
toAmount: BigInt(r.toAmount),
|
|
234
|
+
toAmountMin: BigInt(r.toAmountMin),
|
|
235
|
+
etaSeconds: eta,
|
|
236
|
+
gasCostUsd: Number(r.gasCostUSD ?? 0) || 0,
|
|
237
|
+
tags: Array.isArray(r.tags) ? r.tags.filter((t) => typeof t === "string") : []
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
function cleanChoice(choice) {
|
|
243
|
+
if (!choice) return null;
|
|
244
|
+
const allow = (choice.allowBridges ?? []).filter((t) => TOOL_KEY.test(t));
|
|
245
|
+
const deny = (choice.denyBridges ?? []).filter((t) => TOOL_KEY.test(t));
|
|
246
|
+
const order = choice.order === "CHEAPEST" || choice.order === "FASTEST" ? choice.order : void 0;
|
|
247
|
+
if (!allow.length && !deny.length && !order) return null;
|
|
248
|
+
return { ...allow.length ? { allowBridges: allow } : {}, ...deny.length ? { denyBridges: deny } : {}, ...order ? { order } : {} };
|
|
249
|
+
}
|
|
250
|
+
function lifiProvider(config = {}) {
|
|
251
|
+
config = Object.freeze({ ...config });
|
|
252
|
+
const apiKey = () => config.apiKey;
|
|
253
|
+
const integrator = () => config.integrator ?? "";
|
|
254
|
+
const parsedApiUrl = new URL(config.apiUrl ?? DEFAULT_LIFI_BASE);
|
|
255
|
+
if (parsedApiUrl.protocol !== "https:" && parsedApiUrl.protocol !== "http:") {
|
|
256
|
+
throw new Error("lifi: apiUrl must use http or https");
|
|
257
|
+
}
|
|
258
|
+
const apiBase = parsedApiUrl.toString().replace(/\/$/, "");
|
|
259
|
+
const trustedTransactionTargets = trustMap(config.trustedTransactionTargets, "transaction target");
|
|
260
|
+
const trustedApprovalAddresses = trustMap(config.trustedApprovalAddresses, "approval");
|
|
261
|
+
const quoteTtlMs = config.quoteTtlMs ?? DEFAULT_QUOTE_TTL_MS;
|
|
262
|
+
const defaultSlippageBps = config.defaultSlippageBps ?? 50;
|
|
263
|
+
if (!Number.isInteger(defaultSlippageBps) || defaultSlippageBps <= 0 || defaultSlippageBps >= 1e4) {
|
|
264
|
+
throw new Error("lifi: defaultSlippageBps must be an integer between 1 and 9999");
|
|
265
|
+
}
|
|
266
|
+
if (!Number.isInteger(quoteTtlMs) || quoteTtlMs <= 0 || quoteTtlMs > 6e4) {
|
|
267
|
+
throw new Error("lifi: quoteTtlMs must be an integer between 1 and 60000");
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
name: "lifi",
|
|
271
|
+
describeActivity: (tx, ctx) => describeLifiActivity(tx, ctx, (chain, address) => trustedAddress(chain, address, trustedTransactionTargets)),
|
|
272
|
+
supportsSameChain: true,
|
|
273
|
+
enabled: () => config.enabled ?? true,
|
|
274
|
+
// Capability discovery comes from the provider itself, so it can run alone
|
|
275
|
+
// or inside the optional aggregator without a central capability table.
|
|
276
|
+
supportsChain: (chain) => lifi.supportsChain(chain),
|
|
277
|
+
supportsChainPair: (fromChain, toChain) => lifi.supports(fromChain, toChain),
|
|
278
|
+
supportsRoute(from, to) {
|
|
279
|
+
return !!LIFI_CHAIN[from.chain] && !!LIFI_CHAIN[to.chain];
|
|
280
|
+
},
|
|
281
|
+
async getQuote(params, signal) {
|
|
282
|
+
const reject = (why) => {
|
|
283
|
+
params.onRefusal?.(`lifi: ${why}`);
|
|
284
|
+
return null;
|
|
285
|
+
};
|
|
286
|
+
if (params.flex) return null;
|
|
287
|
+
const fromChain = LIFI_CHAIN[params.sourceChain];
|
|
288
|
+
const toChain = LIFI_CHAIN[params.destChain];
|
|
289
|
+
if (!fromChain || !toChain) return null;
|
|
290
|
+
const fromToken = lifiToken(params.sourceChain, params.sourceToken);
|
|
291
|
+
if (!fromToken) return null;
|
|
292
|
+
const solanaSource = isSolana(params.sourceChain);
|
|
293
|
+
const fromAddress = params.refundAddress ?? (solanaSource ? SOLANA_PLACEHOLDER : EVM_PLACEHOLDER);
|
|
294
|
+
const slippageBps = params.slippageBps ?? defaultSlippageBps;
|
|
295
|
+
let sentSlippage = slippageBps / 1e4;
|
|
296
|
+
let deadline;
|
|
297
|
+
let choice = null;
|
|
298
|
+
if (config.chooseRoute && params.sourceChain !== params.destChain) {
|
|
299
|
+
try {
|
|
300
|
+
const res = await fetch(`${apiBase}/advanced/routes`, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: { ...headers(apiKey()), "content-type": "application/json" },
|
|
303
|
+
body: JSON.stringify({
|
|
304
|
+
fromChainId: Number(fromChain),
|
|
305
|
+
toChainId: Number(toChain),
|
|
306
|
+
fromTokenAddress: fromToken,
|
|
307
|
+
toTokenAddress: nativeFor(params.destChain, params.destToken),
|
|
308
|
+
fromAmount: params.amountIn,
|
|
309
|
+
fromAddress,
|
|
310
|
+
toAddress: params.destAddress || fromAddress,
|
|
311
|
+
options: { slippage: slippageBps / 1e4, ...integrator().trim() ? { integrator: integrator().trim() } : {} }
|
|
312
|
+
}),
|
|
313
|
+
signal: signal ?? (0, import_util2.timeoutSignal)(8e3)
|
|
314
|
+
});
|
|
315
|
+
if (res.ok) {
|
|
316
|
+
const options = routeOptions(await res.json());
|
|
317
|
+
if (options.length) choice = cleanChoice(config.chooseRoute(options, params));
|
|
318
|
+
}
|
|
319
|
+
} catch {
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
for (let attempt = 0; attempt < 2; attempt++) try {
|
|
323
|
+
const url = new URL(`${apiBase}/quote`);
|
|
324
|
+
url.searchParams.set("fromChain", fromChain);
|
|
325
|
+
url.searchParams.set("toChain", toChain);
|
|
326
|
+
url.searchParams.set("fromToken", fromToken);
|
|
327
|
+
url.searchParams.set("toToken", nativeFor(params.destChain, params.destToken));
|
|
328
|
+
url.searchParams.set("fromAmount", params.amountIn);
|
|
329
|
+
url.searchParams.set("fromAddress", fromAddress);
|
|
330
|
+
const toAddress = params.destAddress || fromAddress;
|
|
331
|
+
url.searchParams.set("toAddress", toAddress);
|
|
332
|
+
const integratorId = integrator().trim();
|
|
333
|
+
if (integratorId) url.searchParams.set("integrator", integratorId);
|
|
334
|
+
if (sentSlippage !== void 0) {
|
|
335
|
+
url.searchParams.set("slippage", String(sentSlippage));
|
|
336
|
+
}
|
|
337
|
+
for (const t of choice?.allowBridges ?? []) url.searchParams.append("allowBridges", t);
|
|
338
|
+
for (const t of choice?.denyBridges ?? []) url.searchParams.append("denyBridges", t);
|
|
339
|
+
if (choice?.order) url.searchParams.set("order", choice.order);
|
|
340
|
+
deadline = signal ? void 0 : (0, import_util2.timeoutSignal)(12e3);
|
|
341
|
+
const res = await fetch(url, { headers: headers(apiKey()), signal: signal ?? deadline });
|
|
342
|
+
if (!res.ok && choice) {
|
|
343
|
+
choice = null;
|
|
344
|
+
attempt--;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (!res.ok) {
|
|
348
|
+
const body = await res.json().catch(() => null);
|
|
349
|
+
const reasons = [...new Set((body?.errors?.filteredOut ?? []).map((f) => f.reason).filter((r) => typeof r === "string"))];
|
|
350
|
+
const why = reasons.length === 1 ? ` (${reasons[0].slice(0, 200)})` : "";
|
|
351
|
+
params.onRefusal?.(`lifi: ${typeof body?.message === "string" ? body.message.slice(0, 200) : `HTTP ${res.status}`}${why}`);
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
const q = await res.json();
|
|
355
|
+
const receivedAt = Date.now();
|
|
356
|
+
const action = q.action;
|
|
357
|
+
const est = q.estimate;
|
|
358
|
+
const tr = q.transactionRequest;
|
|
359
|
+
const expectedToToken = nativeFor(params.destChain, params.destToken);
|
|
360
|
+
const expectedFromChain = Number(fromChain);
|
|
361
|
+
const expectedToChain = Number(toChain);
|
|
362
|
+
if (q.type !== "lifi" || !q.id || !action || !est?.toAmount || !est.fromAmount || !tr) return reject("incomplete quote (no action, estimate or transaction)");
|
|
363
|
+
const mismatch = [
|
|
364
|
+
action.fromChainId !== expectedFromChain && "source chain",
|
|
365
|
+
action.toChainId !== expectedToChain && "destination chain",
|
|
366
|
+
(action.fromToken?.chainId !== expectedFromChain || !sameChainAddress(params.sourceChain, action.fromToken?.address, fromToken)) && "source token",
|
|
367
|
+
(action.toToken?.chainId !== expectedToChain || !sameChainAddress(params.destChain, action.toToken?.address, expectedToToken)) && "destination token",
|
|
368
|
+
action.fromAmount !== params.amountIn && "amount spent",
|
|
369
|
+
!sameChainAddress(params.sourceChain, action.fromAddress, fromAddress) && "sender",
|
|
370
|
+
!sameChainAddress(params.destChain, action.toAddress, toAddress) && "recipient"
|
|
371
|
+
].filter(Boolean);
|
|
372
|
+
if (mismatch.length) return reject(`quote does not match the request (${mismatch.join(", ")})`);
|
|
373
|
+
const bridged = BigInt(est.fromAmount);
|
|
374
|
+
const spent = BigInt(params.amountIn);
|
|
375
|
+
if (bridged > spent) return reject(`the estimate bridges ${est.fromAmount}, more than the ${params.amountIn} spent`);
|
|
376
|
+
if ((spent - bridged) * 10000n > spent * BigInt(MAX_INPUT_FEE_BPS)) {
|
|
377
|
+
return reject(`the route takes ${Number((spent - bridged) * 10000n / spent) / 100}% of the input as a fee (over ${MAX_INPUT_FEE_BPS / 100}%)`);
|
|
378
|
+
}
|
|
379
|
+
if (solanaSource) {
|
|
380
|
+
if (!tr.data || tr.data.length < 64 || tr.data.length % 4 !== 0 || !BASE64.test(tr.data)) return reject("the Solana transaction is not base64");
|
|
381
|
+
if (tr.to !== void 0 || tr.value !== void 0 || tr.gasLimit !== void 0) return reject("the Solana transaction carries EVM fields");
|
|
382
|
+
} else if (!isHexData(tr.data) || !normalizeAddress(tr.to) || !normalizeAddress(tr.from) || tr.chainId !== expectedFromChain || !tr.value || !tr.gasLimit || !trustedAddress(params.sourceChain, tr.to, trustedTransactionTargets) || !sameAddress(tr.from, fromAddress)) return reject("the transaction is malformed or targets an untrusted contract");
|
|
383
|
+
if (sentSlippage !== void 0 && (typeof action.slippage !== "number" || Math.abs(action.slippage - sentSlippage) > 1e-12)) return reject("the quote ignored the requested slippage");
|
|
384
|
+
const sourceIsToken = fromToken !== EVM_ZERO && fromToken !== SOLANA_NATIVE;
|
|
385
|
+
if (solanaSource) {
|
|
386
|
+
} else if (sourceIsToken) {
|
|
387
|
+
if (!trustedAddress(params.sourceChain, est.approvalAddress, trustedApprovalAddresses)) return reject("the approval target is not a trusted LI.FI contract");
|
|
388
|
+
} else if (est.approvalAddress !== void 0) {
|
|
389
|
+
if (!trustedAddress(params.sourceChain, est.approvalAddress, trustedApprovalAddresses)) return reject("the approval target is not a trusted LI.FI contract");
|
|
390
|
+
}
|
|
391
|
+
let txRequest;
|
|
392
|
+
if (solanaSource) {
|
|
393
|
+
txRequest = { serializedTx: tr.data, value: sourceIsToken ? "0" : params.amountIn };
|
|
394
|
+
} else {
|
|
395
|
+
try {
|
|
396
|
+
if (BigInt(tr.value) < 0n || BigInt(tr.gasLimit) <= 0n) return reject("the transaction has a negative value or no gas limit");
|
|
397
|
+
} catch {
|
|
398
|
+
return reject("the transaction value or gas limit is not a number");
|
|
399
|
+
}
|
|
400
|
+
const value = BigInt(tr.value);
|
|
401
|
+
const nativeFee = sourceIsToken ? value : value > BigInt(params.amountIn) ? value - BigInt(params.amountIn) : 0n;
|
|
402
|
+
if (!sourceIsToken && value < BigInt(params.amountIn)) return reject("the transaction sends less native coin than the input");
|
|
403
|
+
txRequest = {
|
|
404
|
+
to: tr.to,
|
|
405
|
+
data: tr.data,
|
|
406
|
+
value: value.toString(),
|
|
407
|
+
chainId: tr.chainId,
|
|
408
|
+
gasLimit: BigInt(tr.gasLimit).toString(),
|
|
409
|
+
...sourceIsToken && est.approvalAddress ? { approvalAddress: est.approvalAddress } : {},
|
|
410
|
+
...nativeFee > 0n ? { nativeFee: nativeFee.toString() } : {}
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
const feeUsd = (est.feeCosts ?? []).reduce((a, f) => a + Number(f.amountUSD ?? 0), 0);
|
|
414
|
+
if (!est.toAmountMin) return reject("the quote has no minimum output");
|
|
415
|
+
const minDestAmount = est.toAmountMin;
|
|
416
|
+
if (sentSlippage !== void 0) {
|
|
417
|
+
const dest = BigInt(est.toAmount);
|
|
418
|
+
const min = BigInt(minDestAmount);
|
|
419
|
+
if (dest > 0n && min < dest * BigInt(1e4 - slippageBps) / 10000n) {
|
|
420
|
+
const effective = Number((dest - min) * 1000000n / dest) / 1e6;
|
|
421
|
+
const requested = slippageBps / 1e4;
|
|
422
|
+
const scaled = Math.floor(sentSlippage * requested / effective * 0.995 * 1e6) / 1e6;
|
|
423
|
+
if (attempt === 0 && effective > 0 && scaled > 0) {
|
|
424
|
+
sentSlippage = scaled;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
params.onRefusal?.(
|
|
428
|
+
`lifi: this route's minimum is ${(effective * 100).toFixed(2)}% under the quote (LI.FI applies slippage on every step) \u2014 more than the requested ${slippageBps / 100}%`
|
|
429
|
+
);
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (params.minAmountOut !== void 0 && BigInt(minDestAmount) < BigInt(params.minAmountOut)) {
|
|
434
|
+
params.onRefusal?.(`lifi: floor breach (min=${minDestAmount} < floor=${params.minAmountOut})`);
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
const duration = est.executionDuration ?? 0;
|
|
438
|
+
if (fromChain === toChain && duration > SAME_CHAIN_MAX_SECONDS) {
|
|
439
|
+
params.onRefusal?.(`lifi: same-chain route settles asynchronously (${duration} s via ${q.tool ?? "unknown tool"}) \u2014 a same-chain swap must deliver in the same transaction`);
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
return {
|
|
443
|
+
provider: "lifi",
|
|
444
|
+
// Status is tracked by SOURCE TX HASH + the chain pair.
|
|
445
|
+
intentId: `lifi:${fromChain}:${toChain}`,
|
|
446
|
+
depositAddress: "",
|
|
447
|
+
depositMemo: null,
|
|
448
|
+
txRequest,
|
|
449
|
+
// What the wallet spends (action.fromAmount, = the input); an input-side bridge fee is inside destAmount.
|
|
450
|
+
sourceAmount: params.amountIn,
|
|
451
|
+
destAmount: est.toAmount,
|
|
452
|
+
minDestAmount,
|
|
453
|
+
feeUsd,
|
|
454
|
+
etaSeconds: est.executionDuration ?? 120,
|
|
455
|
+
reliability: 0.97,
|
|
456
|
+
// LI.FI documents an approximately 60-second lifetime. Use a slightly
|
|
457
|
+
// shorter local deadline and re-quote again at execution time.
|
|
458
|
+
validUntilMs: receivedAt + quoteTtlMs
|
|
459
|
+
};
|
|
460
|
+
} catch {
|
|
461
|
+
if (deadline?.aborted) params.onRefusal?.("lifi: no quote within 12 s");
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
},
|
|
466
|
+
async buildDeposit(quote) {
|
|
467
|
+
const tx = quote.txRequest;
|
|
468
|
+
if (!tx) throw new Error("swap2: LI.FI quote has no transaction request");
|
|
469
|
+
const [, fromChain] = quote.intentId.split(":");
|
|
470
|
+
return {
|
|
471
|
+
chain: tx.serializedTx ? CAIP2_BY_LIFI_CHAIN[fromChain ?? ""] ?? "" : "",
|
|
472
|
+
to: tx.to ?? "",
|
|
473
|
+
value: tx.value ?? "0",
|
|
474
|
+
...tx.data ? { data: tx.data } : {},
|
|
475
|
+
...tx.chainId !== void 0 ? { chainId: tx.chainId } : {},
|
|
476
|
+
...tx.gasLimit ? { gasLimit: tx.gasLimit } : {},
|
|
477
|
+
...tx.approvalAddress ? { approvalAddress: tx.approvalAddress } : {},
|
|
478
|
+
...tx.serializedTx ? { serializedTx: tx.serializedTx } : {}
|
|
479
|
+
};
|
|
480
|
+
},
|
|
481
|
+
async trackIntent(ref) {
|
|
482
|
+
if (!ref.sourceTxHash) return { state: "pending" };
|
|
483
|
+
const [, fromChain, toChain] = ref.intentId.split(":");
|
|
484
|
+
try {
|
|
485
|
+
const url = new URL(`${apiBase}/status`);
|
|
486
|
+
url.searchParams.set("txHash", ref.sourceTxHash);
|
|
487
|
+
if (fromChain) url.searchParams.set("fromChain", fromChain);
|
|
488
|
+
if (toChain) url.searchParams.set("toChain", toChain);
|
|
489
|
+
const res = await fetch(url, { headers: headers(apiKey()), signal: (0, import_util2.timeoutSignal)(12e3) });
|
|
490
|
+
if (!res.ok) return { state: "pending" };
|
|
491
|
+
const s = await res.json();
|
|
492
|
+
const map = {
|
|
493
|
+
DONE: "completed",
|
|
494
|
+
FAILED: "failed",
|
|
495
|
+
PENDING: "pending",
|
|
496
|
+
NOT_FOUND: "pending"
|
|
497
|
+
};
|
|
498
|
+
const state = s.substatus === "REFUNDED" ? "refunded" : s.substatus === "EXPIRED" ? "expired" : s.substatus === "NOT_PROCESSABLE_REFUND_NEEDED" ? "action-required" : s.substatus === "REFUND_IN_PROGRESS" ? "refund-pending" : s.status === "DONE" && s.substatus === "PARTIAL" ? "partial" : map[s.status ?? "PENDING"] ?? "pending";
|
|
499
|
+
const depositReceived = state === "pending" && s.status === "PENDING";
|
|
500
|
+
const destTxHash = typeof s.receiving?.txHash === "string" && s.receiving.txHash.length > 0 ? s.receiving.txHash : void 0;
|
|
501
|
+
return {
|
|
502
|
+
state,
|
|
503
|
+
depositReceived,
|
|
504
|
+
...destTxHash ? { destTxHash } : {}
|
|
505
|
+
};
|
|
506
|
+
} catch {
|
|
507
|
+
return { state: "pending" };
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// src/protocol.ts
|
|
514
|
+
var import_single = require("@anywalletkit/protocol-swap2-core/swap2/single");
|
|
515
|
+
var LifiSwap2Protocol = class extends import_single.SingleProviderSwap2 {
|
|
516
|
+
provider;
|
|
517
|
+
constructor(account, config) {
|
|
518
|
+
super(account, config);
|
|
519
|
+
this.provider = lifiProvider(config);
|
|
520
|
+
}
|
|
521
|
+
chainSupported(caip2) {
|
|
522
|
+
return lifi.supportsChain(caip2);
|
|
523
|
+
}
|
|
524
|
+
pairSupported(fromChain, toChain) {
|
|
525
|
+
return lifi.supports(fromChain, toChain);
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
//# sourceMappingURL=index.cjs.map
|