hermes-swap 0.0.21 → 0.0.23
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/dist/cjs/abis/aggregator.d.ts +264 -235
- package/dist/cjs/abis/aggregator.js +154 -603
- package/dist/cjs/abis/quoter.d.ts +5 -24
- package/dist/cjs/abis/quoter.js +67 -42
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +103 -4
- package/dist/cjs/types.d.ts +55 -5
- package/dist/cjs/types.js +9 -0
- package/dist/esm/abis/aggregator.d.ts +264 -235
- package/dist/esm/abis/aggregator.js +264 -235
- package/dist/esm/abis/quoter.d.ts +5 -24
- package/dist/esm/abis/quoter.js +54 -35
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +202 -13
- package/dist/esm/types.d.ts +55 -5
- package/dist/esm/types.js +9 -0
- package/package.json +1 -1
|
@@ -40,41 +40,22 @@ declare const QuoterAbi: ({
|
|
|
40
40
|
inputs: {
|
|
41
41
|
name: string;
|
|
42
42
|
type: string;
|
|
43
|
-
|
|
44
|
-
components: ({
|
|
45
|
-
name: string;
|
|
46
|
-
type: string;
|
|
47
|
-
internalType: string;
|
|
48
|
-
components?: undefined;
|
|
49
|
-
} | {
|
|
50
|
-
name: string;
|
|
51
|
-
type: string;
|
|
52
|
-
internalType: string;
|
|
53
|
-
components: {
|
|
54
|
-
name: string;
|
|
55
|
-
type: string;
|
|
56
|
-
internalType: string;
|
|
57
|
-
}[];
|
|
58
|
-
})[];
|
|
59
|
-
}[];
|
|
60
|
-
outputs: {
|
|
61
|
-
name: string;
|
|
62
|
-
type: string;
|
|
43
|
+
indexed: boolean;
|
|
63
44
|
internalType: string;
|
|
64
45
|
}[];
|
|
65
|
-
|
|
66
|
-
|
|
46
|
+
anonymous: boolean;
|
|
47
|
+
stateMutability?: undefined;
|
|
48
|
+
outputs?: undefined;
|
|
67
49
|
} | {
|
|
68
50
|
type: string;
|
|
69
51
|
name: string;
|
|
70
52
|
inputs: {
|
|
71
53
|
name: string;
|
|
72
54
|
type: string;
|
|
73
|
-
indexed: boolean;
|
|
74
55
|
internalType: string;
|
|
75
56
|
}[];
|
|
76
|
-
anonymous: boolean;
|
|
77
57
|
stateMutability?: undefined;
|
|
78
58
|
outputs?: undefined;
|
|
59
|
+
anonymous?: undefined;
|
|
79
60
|
})[];
|
|
80
61
|
export default QuoterAbi;
|
package/dist/cjs/abis/quoter.js
CHANGED
|
@@ -106,7 +106,7 @@ var QuoterAbi = [
|
|
|
106
106
|
internalType: "uint256[][]"
|
|
107
107
|
}
|
|
108
108
|
],
|
|
109
|
-
stateMutability: "
|
|
109
|
+
stateMutability: "nonpayable"
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
type: "function",
|
|
@@ -194,7 +194,7 @@ var QuoterAbi = [
|
|
|
194
194
|
internalType: "bool"
|
|
195
195
|
}
|
|
196
196
|
],
|
|
197
|
-
stateMutability: "
|
|
197
|
+
stateMutability: "nonpayable"
|
|
198
198
|
},
|
|
199
199
|
{
|
|
200
200
|
type: "function",
|
|
@@ -264,7 +264,7 @@ var QuoterAbi = [
|
|
|
264
264
|
internalType: "uint256[]"
|
|
265
265
|
}
|
|
266
266
|
],
|
|
267
|
-
stateMutability: "
|
|
267
|
+
stateMutability: "nonpayable"
|
|
268
268
|
},
|
|
269
269
|
{
|
|
270
270
|
type: "function",
|
|
@@ -328,16 +328,16 @@ var QuoterAbi = [
|
|
|
328
328
|
internalType: "uint256"
|
|
329
329
|
}
|
|
330
330
|
],
|
|
331
|
-
stateMutability: "
|
|
331
|
+
stateMutability: "nonpayable"
|
|
332
332
|
},
|
|
333
333
|
{
|
|
334
334
|
type: "function",
|
|
335
335
|
name: "quoteBridge",
|
|
336
336
|
inputs: [
|
|
337
337
|
{
|
|
338
|
-
name: "
|
|
338
|
+
name: "bridgeParam",
|
|
339
339
|
type: "tuple",
|
|
340
|
-
internalType: "struct
|
|
340
|
+
internalType: "struct BridgeParam",
|
|
341
341
|
components: [
|
|
342
342
|
{
|
|
343
343
|
name: "bridge",
|
|
@@ -345,41 +345,34 @@ var QuoterAbi = [
|
|
|
345
345
|
internalType: "string"
|
|
346
346
|
},
|
|
347
347
|
{
|
|
348
|
-
name: "
|
|
349
|
-
type: "
|
|
350
|
-
internalType: "
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
name: "adapterParams",
|
|
379
|
-
type: "bytes",
|
|
380
|
-
internalType: "bytes"
|
|
381
|
-
}
|
|
382
|
-
]
|
|
348
|
+
name: "token",
|
|
349
|
+
type: "address",
|
|
350
|
+
internalType: "address"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "amount",
|
|
354
|
+
type: "uint256",
|
|
355
|
+
internalType: "uint256"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: "bridgeAddress",
|
|
359
|
+
type: "address",
|
|
360
|
+
internalType: "address"
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
name: "destChain",
|
|
364
|
+
type: "string",
|
|
365
|
+
internalType: "string"
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
name: "destUser",
|
|
369
|
+
type: "address",
|
|
370
|
+
internalType: "address"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
name: "extra",
|
|
374
|
+
type: "bytes",
|
|
375
|
+
internalType: "bytes"
|
|
383
376
|
}
|
|
384
377
|
]
|
|
385
378
|
}
|
|
@@ -391,7 +384,7 @@ var QuoterAbi = [
|
|
|
391
384
|
internalType: "uint256"
|
|
392
385
|
}
|
|
393
386
|
],
|
|
394
|
-
stateMutability: "
|
|
387
|
+
stateMutability: "nonpayable"
|
|
395
388
|
},
|
|
396
389
|
{
|
|
397
390
|
type: "function",
|
|
@@ -519,6 +512,38 @@ var QuoterAbi = [
|
|
|
519
512
|
}
|
|
520
513
|
],
|
|
521
514
|
anonymous: false
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
type: "error",
|
|
518
|
+
name: "NotExecutor",
|
|
519
|
+
inputs: [
|
|
520
|
+
{
|
|
521
|
+
name: "caller",
|
|
522
|
+
type: "address",
|
|
523
|
+
internalType: "address"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
name: "executor",
|
|
527
|
+
type: "address",
|
|
528
|
+
internalType: "address"
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
type: "error",
|
|
534
|
+
name: "NotOwner",
|
|
535
|
+
inputs: [
|
|
536
|
+
{
|
|
537
|
+
name: "caller",
|
|
538
|
+
type: "address",
|
|
539
|
+
internalType: "address"
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
name: "owner",
|
|
543
|
+
type: "address",
|
|
544
|
+
internalType: "address"
|
|
545
|
+
}
|
|
546
|
+
]
|
|
522
547
|
}
|
|
523
548
|
];
|
|
524
549
|
var quoter_default = QuoterAbi;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ declare class Hermes {
|
|
|
12
12
|
expect(params: IExpectParams): Promise<bigint>;
|
|
13
13
|
swap(params: ISwapParams): Promise<IReceipt>;
|
|
14
14
|
bridge(params: IBridgeParams): Promise<IReceipt>;
|
|
15
|
+
estimateBridgeFee(params: IBridgeParams): Promise<bigint>;
|
|
15
16
|
swapAndBridge(params: ISwapAndBridgeParams): Promise<IReceipt>;
|
|
17
|
+
private checkIsEnoughToken;
|
|
16
18
|
private validateParams;
|
|
17
19
|
private getQuoterAddress;
|
|
18
20
|
private getAggregatorAddress;
|
package/dist/cjs/index.js
CHANGED
|
@@ -55,7 +55,6 @@ var Hermes = class {
|
|
|
55
55
|
this.walletMap.set(chainName, new import_ethers.ethers.Wallet(rpc.privateKey, provider));
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
console.log(Object.entries(this.config.rpc), this.walletMap);
|
|
59
58
|
for (const [chainName, quoterAddress] of Object.entries(this.config.quoterAddress)) {
|
|
60
59
|
this.quoterAddressMap.set(chainName, quoterAddress);
|
|
61
60
|
}
|
|
@@ -146,19 +145,119 @@ var Hermes = class {
|
|
|
146
145
|
return {
|
|
147
146
|
fromToken: fromTokenAddress,
|
|
148
147
|
toToken: toTokenAddress,
|
|
149
|
-
amountOut
|
|
148
|
+
amountOut,
|
|
149
|
+
hash: receipt.hash,
|
|
150
|
+
from: receipt.from,
|
|
151
|
+
to: receipt.from,
|
|
152
|
+
logs: receipt.logs
|
|
150
153
|
};
|
|
151
154
|
}
|
|
152
155
|
async bridge(params) {
|
|
153
156
|
this.validateParams(params);
|
|
154
|
-
const
|
|
157
|
+
const aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
158
|
+
const wallet = this.walletMap.get(params.chain);
|
|
159
|
+
if (!wallet) {
|
|
160
|
+
throw new Error(`Wallet not configured for chain: ${params.chain}`);
|
|
161
|
+
}
|
|
162
|
+
if (params.tokenAddress && params.tokenAddress !== import_ethers.ethers.ZeroAddress) {
|
|
163
|
+
await this.checkIsEnoughToken(params.tokenAddress, params.user, params.amountInWei, aggregatorAddress, wallet);
|
|
164
|
+
}
|
|
165
|
+
if (params.bridgeFee > 0n) {
|
|
166
|
+
const provider = this.providerMap.get(params.chain);
|
|
167
|
+
if (!provider) {
|
|
168
|
+
throw new Error(`Provider not configured for chain: ${params.chain}`);
|
|
169
|
+
}
|
|
170
|
+
const nativeBalance = await provider.getBalance(params.user);
|
|
171
|
+
if (nativeBalance < params.bridgeFee) {
|
|
172
|
+
throw new Error("Insufficient native balance for bridge fee");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const aggregator = new import_ethers2.Contract(aggregatorAddress, import_aggregator.default, wallet);
|
|
176
|
+
const bridgeArgs = {
|
|
177
|
+
bridge: params.bridgeType,
|
|
178
|
+
token: params.tokenAddress,
|
|
179
|
+
amount: params.amountInWei,
|
|
180
|
+
bridgeAddress: params.bridgeAddress,
|
|
181
|
+
destChain: params.destChain,
|
|
182
|
+
destUser: params.destUser,
|
|
183
|
+
extra: params.extra ?? "0x"
|
|
184
|
+
};
|
|
185
|
+
const txOverrides = {
|
|
186
|
+
from: wallet.address,
|
|
187
|
+
value: params.bridgeFee
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
await aggregator.bridge.estimateGas(params.user, bridgeArgs, txOverrides);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error("Bridge gas estimation reverted", error);
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
let txResponse;
|
|
196
|
+
try {
|
|
197
|
+
txResponse = await aggregator.bridge(params.user, bridgeArgs, txOverrides);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error("Aggregator swap transaction failed", error);
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
const receipt = {
|
|
203
|
+
fromToken: params.tokenAddress,
|
|
204
|
+
toToken: params.tokenAddress,
|
|
205
|
+
amountOut: params.amountInWei,
|
|
206
|
+
hash: txResponse.hash,
|
|
207
|
+
from: txResponse.from,
|
|
208
|
+
to: txResponse.to,
|
|
209
|
+
logs: txResponse.logs
|
|
210
|
+
};
|
|
155
211
|
return Promise.resolve(receipt);
|
|
156
212
|
}
|
|
213
|
+
async estimateBridgeFee(params) {
|
|
214
|
+
this.validateParams(params);
|
|
215
|
+
const wallet = this.walletMap.get(params.chain);
|
|
216
|
+
if (!wallet) {
|
|
217
|
+
throw new Error(`Wallet not configured for chain: ${params.chain}`);
|
|
218
|
+
}
|
|
219
|
+
const address = this.getQuoterAddress(params.chain);
|
|
220
|
+
if (!address) {
|
|
221
|
+
throw new Error(`Quoter address not found for chain: ${params.chain}`);
|
|
222
|
+
}
|
|
223
|
+
const quoter = new import_ethers2.Contract(address, import_quoter.default, wallet);
|
|
224
|
+
const bridgeArgs = {
|
|
225
|
+
bridge: params.bridgeType,
|
|
226
|
+
token: params.tokenAddress,
|
|
227
|
+
amount: params.amountInWei,
|
|
228
|
+
bridgeAddress: params.bridgeAddress,
|
|
229
|
+
destChain: params.destChain,
|
|
230
|
+
destUser: params.destUser,
|
|
231
|
+
extra: params.extra ?? "0x"
|
|
232
|
+
};
|
|
233
|
+
const bridgeFee = await quoter.quoteBridge.staticCall(bridgeArgs, { from: wallet.address });
|
|
234
|
+
return bridgeFee;
|
|
235
|
+
}
|
|
157
236
|
async swapAndBridge(params) {
|
|
158
237
|
this.validateParams(params);
|
|
159
|
-
const receipt = {
|
|
238
|
+
const receipt = {
|
|
239
|
+
fromToken: params.path[0].fromCoinAddress,
|
|
240
|
+
toToken: params.path[params.path.length - 1].toCoinAddress,
|
|
241
|
+
amountOut: params.minAmountOutList[params.minAmountOutList.length - 1],
|
|
242
|
+
hash: "",
|
|
243
|
+
from: "",
|
|
244
|
+
to: "",
|
|
245
|
+
logs: []
|
|
246
|
+
};
|
|
160
247
|
return Promise.resolve(receipt);
|
|
161
248
|
}
|
|
249
|
+
async checkIsEnoughToken(fromTokenAddress, userAddress, amountInWei, aggregatorAddress, wallet) {
|
|
250
|
+
const erc20 = new import_ethers2.Contract(fromTokenAddress, ["function balanceOf(address) view returns (uint256)", "function allowance(address, address) view returns (uint256)"], wallet);
|
|
251
|
+
const userBalance = await erc20.balanceOf(userAddress);
|
|
252
|
+
if (userBalance < amountInWei) {
|
|
253
|
+
throw new Error("Insufficient balance token amount");
|
|
254
|
+
}
|
|
255
|
+
const currentAllowance = await erc20.allowance(userAddress, aggregatorAddress);
|
|
256
|
+
console.log(currentAllowance);
|
|
257
|
+
if (currentAllowance < amountInWei) {
|
|
258
|
+
throw new Error("Insufficient allowance token amount");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
162
261
|
validateParams(params) {
|
|
163
262
|
if (!params.chain) {
|
|
164
263
|
throw new Error("Chain not found");
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BytesLike } from 'ethers';
|
|
1
|
+
import type { BytesLike, JsonRpcProvider } from 'ethers';
|
|
2
2
|
export interface IConfig {
|
|
3
3
|
rpc: Record<string, IRpcConfig>;
|
|
4
4
|
quoterAddress: Record<string, string>;
|
|
@@ -24,6 +24,8 @@ export interface IBridgeParams {
|
|
|
24
24
|
bridgeAddress: string;
|
|
25
25
|
tokenAddress: string;
|
|
26
26
|
destChain: string;
|
|
27
|
+
destUser: string;
|
|
28
|
+
bridgeFee: bigint;
|
|
27
29
|
extra?: BytesLike;
|
|
28
30
|
}
|
|
29
31
|
export interface ISwapAndBridgeParams {
|
|
@@ -36,15 +38,57 @@ export interface ISwapAndBridgeParams {
|
|
|
36
38
|
bridgeAddress: string;
|
|
37
39
|
tokenAddress: string;
|
|
38
40
|
destChain: string;
|
|
41
|
+
destUser: string;
|
|
42
|
+
bridgeFee: bigint;
|
|
39
43
|
extra?: BytesLike;
|
|
40
44
|
}
|
|
41
45
|
export interface IReceipt {
|
|
42
|
-
fromToken
|
|
43
|
-
toToken
|
|
44
|
-
amountOut
|
|
46
|
+
fromToken: string;
|
|
47
|
+
toToken: string;
|
|
48
|
+
amountOut: bigint;
|
|
49
|
+
hash: string;
|
|
50
|
+
from: string;
|
|
51
|
+
to: string;
|
|
52
|
+
logs: ILog[];
|
|
53
|
+
}
|
|
54
|
+
export interface IEthersReceipt {
|
|
55
|
+
provider: JsonRpcProvider;
|
|
56
|
+
to: string;
|
|
57
|
+
from: string;
|
|
58
|
+
contractAddress: string | null;
|
|
59
|
+
hash: string;
|
|
60
|
+
index: number;
|
|
61
|
+
blockHash: string;
|
|
62
|
+
blockNumber: number;
|
|
63
|
+
logsBloom: string;
|
|
64
|
+
gasUsed: bigint;
|
|
65
|
+
blobGasUsed: null;
|
|
66
|
+
cumulativeGasUsed: bigint;
|
|
67
|
+
gasPrice: bigint;
|
|
68
|
+
blobGasPrice: null;
|
|
69
|
+
type: number;
|
|
70
|
+
status: number;
|
|
71
|
+
root: undefined;
|
|
72
|
+
logs: ILog[];
|
|
73
|
+
}
|
|
74
|
+
export interface ILog {
|
|
75
|
+
provider: JsonRpcProvider;
|
|
76
|
+
transactionHash: string;
|
|
77
|
+
blockHash: string;
|
|
78
|
+
blockNumber: number;
|
|
79
|
+
removed: undefined;
|
|
80
|
+
address: string;
|
|
81
|
+
data: string;
|
|
82
|
+
topics: string[];
|
|
83
|
+
index: number;
|
|
84
|
+
transactionIndex: number;
|
|
85
|
+
args: any[];
|
|
45
86
|
}
|
|
46
87
|
export declare enum DexType {
|
|
47
|
-
FX = "f(x)"
|
|
88
|
+
FX = "f(x)",
|
|
89
|
+
UNISWAPV2 = "uniswapv2",
|
|
90
|
+
CURVE128 = "curve128",
|
|
91
|
+
CURVE256 = "curve256"
|
|
48
92
|
}
|
|
49
93
|
export declare enum ChainNameEnum {
|
|
50
94
|
ETH = "ETH",// Ethereum Mainnet
|
|
@@ -218,6 +262,12 @@ export declare const AddressConst: {
|
|
|
218
262
|
xeth: {
|
|
219
263
|
eth: string;
|
|
220
264
|
};
|
|
265
|
+
arb: {
|
|
266
|
+
arb: string;
|
|
267
|
+
};
|
|
268
|
+
usdc: {
|
|
269
|
+
arb: string;
|
|
270
|
+
};
|
|
221
271
|
};
|
|
222
272
|
export interface IExpectPayload {
|
|
223
273
|
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -26,6 +26,9 @@ __export(types_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(types_exports);
|
|
27
27
|
var DexType = /* @__PURE__ */ ((DexType2) => {
|
|
28
28
|
DexType2["FX"] = "f(x)";
|
|
29
|
+
DexType2["UNISWAPV2"] = "uniswapv2";
|
|
30
|
+
DexType2["CURVE128"] = "curve128";
|
|
31
|
+
DexType2["CURVE256"] = "curve256";
|
|
29
32
|
return DexType2;
|
|
30
33
|
})(DexType || {});
|
|
31
34
|
var ChainNameEnum = /* @__PURE__ */ ((ChainNameEnum2) => {
|
|
@@ -197,6 +200,12 @@ var AddressConst = {
|
|
|
197
200
|
},
|
|
198
201
|
xeth: {
|
|
199
202
|
eth: "0xe063F04f280c60aECa68b38341C2eEcBeC703ae2"
|
|
203
|
+
},
|
|
204
|
+
arb: {
|
|
205
|
+
arb: "0x912CE59144191C1204E64559FE8253a0e49E6548"
|
|
206
|
+
},
|
|
207
|
+
usdc: {
|
|
208
|
+
arb: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"
|
|
200
209
|
}
|
|
201
210
|
};
|
|
202
211
|
// Annotate the CommonJS export names for ESM import in node:
|