hermes-swap 0.0.28 → 0.0.29
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/index.d.ts +3 -2
- package/dist/cjs/index.js +75 -0
- package/dist/cjs/types.d.ts +5 -0
- package/dist/cjs/types.js +10 -2
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +191 -63
- package/dist/esm/types.d.ts +5 -0
- package/dist/esm/types.js +6 -0
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath } from './types.js';
|
|
2
|
-
import { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts } from './types.js';
|
|
3
|
-
export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath };
|
|
2
|
+
import { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts, IEstimateType } from './types.js';
|
|
3
|
+
export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, IEstimateType };
|
|
4
4
|
export { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts };
|
|
5
5
|
declare class Hermes {
|
|
6
6
|
private config;
|
|
@@ -21,6 +21,7 @@ declare class Hermes {
|
|
|
21
21
|
bridge(params: IBridgeParams): Promise<IReceipt>;
|
|
22
22
|
estimateBridgeFee(params: IBridgeParams): Promise<bigint>;
|
|
23
23
|
swapAndBridge(params: ISwapAndBridgeParams): Promise<IReceipt>;
|
|
24
|
+
estimateGas(estimateType: IEstimateType, params: IBridgeParams | ISwapParams | ISwapAndBridgeParams): Promise<bigint>;
|
|
24
25
|
getAggregatorSupportContracts(chain: ChainNameEnum): Promise<SupportContracts[]>;
|
|
25
26
|
getQuoterSupportContracts(chain: ChainNameEnum): Promise<SupportContracts[]>;
|
|
26
27
|
/**
|
package/dist/cjs/index.js
CHANGED
|
@@ -315,6 +315,81 @@ var Hermes = class {
|
|
|
315
315
|
};
|
|
316
316
|
return Promise.resolve(receipt);
|
|
317
317
|
}
|
|
318
|
+
async estimateGas(estimateType, params) {
|
|
319
|
+
this.validateParams(params);
|
|
320
|
+
const aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
321
|
+
const wallet = this.walletMap.get(params.chain);
|
|
322
|
+
const aggregator = new import_ethers2.Contract(aggregatorAddress, import_aggregator.default, wallet);
|
|
323
|
+
if (!wallet) {
|
|
324
|
+
throw new Error(`Wallet not configured for chain: ${params.chain}`);
|
|
325
|
+
}
|
|
326
|
+
switch (estimateType) {
|
|
327
|
+
case import_types.IEstimateType.BRIDGE:
|
|
328
|
+
if (!("bridgeType" in params) || !("destChain" in params)) {
|
|
329
|
+
throw new Error("bridge params required");
|
|
330
|
+
}
|
|
331
|
+
const bridgeArgs1 = {
|
|
332
|
+
bridge: params.bridgeType,
|
|
333
|
+
token: params.tokenAddress,
|
|
334
|
+
amount: params.amountInWei,
|
|
335
|
+
bridgeAddress: params.bridgeAddress,
|
|
336
|
+
destChain: params.destChain,
|
|
337
|
+
destUser: params.destUser,
|
|
338
|
+
extra: params.extra ?? "0x"
|
|
339
|
+
};
|
|
340
|
+
const txOverrides1 = {
|
|
341
|
+
from: wallet.address,
|
|
342
|
+
value: params.bridgeFee
|
|
343
|
+
};
|
|
344
|
+
const gasInBridge = await aggregator.bridge.estimateGas(params.user, bridgeArgs1, txOverrides1);
|
|
345
|
+
return gasInBridge;
|
|
346
|
+
case import_types.IEstimateType.SWAP:
|
|
347
|
+
if (!("path" in params) || !Array.isArray(params.path) || params.path.length === 0) {
|
|
348
|
+
throw new Error("Swap path required for gas estimation");
|
|
349
|
+
}
|
|
350
|
+
if (!("minAmountOutList" in params) || params.minAmountOutList.length === 0) {
|
|
351
|
+
throw new Error("minAmountOutList required for gas estimation");
|
|
352
|
+
}
|
|
353
|
+
const swapParams1 = params.path.map((pathItem) => ({
|
|
354
|
+
dexType: pathItem.dexType,
|
|
355
|
+
pool: pathItem.poolAddress,
|
|
356
|
+
fromCoin: pathItem.fromCoinAddress,
|
|
357
|
+
toCoin: pathItem.toCoinAddress,
|
|
358
|
+
extra: pathItem.extra ?? "0x"
|
|
359
|
+
}));
|
|
360
|
+
const swapGas = await aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, { from: wallet.address });
|
|
361
|
+
return swapGas;
|
|
362
|
+
case import_types.IEstimateType.SWAPANDBRIDGE:
|
|
363
|
+
if (!("path" in params) || !("bridgeType" in params)) {
|
|
364
|
+
throw new Error("swapAndBridge params required");
|
|
365
|
+
}
|
|
366
|
+
const swapAndBridgeParams = params;
|
|
367
|
+
const swapParams = swapAndBridgeParams.path.map((pathItem) => ({
|
|
368
|
+
dexType: pathItem.dexType,
|
|
369
|
+
pool: pathItem.poolAddress,
|
|
370
|
+
fromCoin: pathItem.fromCoinAddress,
|
|
371
|
+
toCoin: pathItem.toCoinAddress,
|
|
372
|
+
extra: pathItem.extra ?? "0x"
|
|
373
|
+
}));
|
|
374
|
+
const bridgeArgs = {
|
|
375
|
+
bridge: swapAndBridgeParams.bridgeType,
|
|
376
|
+
token: swapAndBridgeParams.tokenAddress,
|
|
377
|
+
amount: swapAndBridgeParams.amountInWei,
|
|
378
|
+
bridgeAddress: swapAndBridgeParams.bridgeAddress,
|
|
379
|
+
destChain: swapAndBridgeParams.destChain,
|
|
380
|
+
destUser: swapAndBridgeParams.destUser,
|
|
381
|
+
extra: swapAndBridgeParams.extra ?? "0x"
|
|
382
|
+
};
|
|
383
|
+
const txOverrides = {
|
|
384
|
+
from: wallet.address,
|
|
385
|
+
value: swapAndBridgeParams.bridgeFee
|
|
386
|
+
};
|
|
387
|
+
const gas = await aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txOverrides);
|
|
388
|
+
return gas;
|
|
389
|
+
default:
|
|
390
|
+
throw "Not support method in sdk";
|
|
391
|
+
}
|
|
392
|
+
}
|
|
318
393
|
async getAggregatorSupportContracts(chain) {
|
|
319
394
|
const aggregatorAddress = this.getAggregatorAddress(chain);
|
|
320
395
|
const provider = this.providerMap.get(chain);
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -108,6 +108,11 @@ export declare enum DexType {
|
|
|
108
108
|
VSDCRVWITHDRAW = "vsdCRV_withdraw",
|
|
109
109
|
VSDCRVDEPOSIT = "vsdCRV_deposit"
|
|
110
110
|
}
|
|
111
|
+
export declare enum IEstimateType {
|
|
112
|
+
BRIDGE = "bridge",
|
|
113
|
+
SWAPANDBRIDGE = "swapAndBridge",
|
|
114
|
+
SWAP = "swap"
|
|
115
|
+
}
|
|
111
116
|
export declare enum BridgeType {
|
|
112
117
|
LAYERZEROV1 = "layerzero_v1",
|
|
113
118
|
LAYERZEROV2 = "layerzero_v2",
|
package/dist/cjs/types.js
CHANGED
|
@@ -22,7 +22,8 @@ __export(types_exports, {
|
|
|
22
22
|
AddressConst: () => AddressConst,
|
|
23
23
|
BridgeType: () => BridgeType,
|
|
24
24
|
ChainNameEnum: () => ChainNameEnum,
|
|
25
|
-
DexType: () => DexType
|
|
25
|
+
DexType: () => DexType,
|
|
26
|
+
IEstimateType: () => IEstimateType
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(types_exports);
|
|
28
29
|
var DexType = /* @__PURE__ */ ((DexType2) => {
|
|
@@ -41,6 +42,12 @@ var DexType = /* @__PURE__ */ ((DexType2) => {
|
|
|
41
42
|
DexType2["VSDCRVDEPOSIT"] = "vsdCRV_deposit";
|
|
42
43
|
return DexType2;
|
|
43
44
|
})(DexType || {});
|
|
45
|
+
var IEstimateType = /* @__PURE__ */ ((IEstimateType2) => {
|
|
46
|
+
IEstimateType2["BRIDGE"] = "bridge";
|
|
47
|
+
IEstimateType2["SWAPANDBRIDGE"] = "swapAndBridge";
|
|
48
|
+
IEstimateType2["SWAP"] = "swap";
|
|
49
|
+
return IEstimateType2;
|
|
50
|
+
})(IEstimateType || {});
|
|
44
51
|
var BridgeType = /* @__PURE__ */ ((BridgeType2) => {
|
|
45
52
|
BridgeType2["LAYERZEROV1"] = "layerzero_v1";
|
|
46
53
|
BridgeType2["LAYERZEROV2"] = "layerzero_v2";
|
|
@@ -254,5 +261,6 @@ var AddressConst = {
|
|
|
254
261
|
AddressConst,
|
|
255
262
|
BridgeType,
|
|
256
263
|
ChainNameEnum,
|
|
257
|
-
DexType
|
|
264
|
+
DexType,
|
|
265
|
+
IEstimateType
|
|
258
266
|
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath } from './types.js';
|
|
2
|
-
import { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts } from './types.js';
|
|
3
|
-
export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath };
|
|
2
|
+
import { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts, IEstimateType } from './types.js';
|
|
3
|
+
export type { IExpectParams, ISwapParams, IBridgeParams, ISwapAndBridgeParams, IReceipt, IConfig, IExpectPayload, IRouterPath, IEstimateType };
|
|
4
4
|
export { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts };
|
|
5
5
|
declare class Hermes {
|
|
6
6
|
private config;
|
|
@@ -21,6 +21,7 @@ declare class Hermes {
|
|
|
21
21
|
bridge(params: IBridgeParams): Promise<IReceipt>;
|
|
22
22
|
estimateBridgeFee(params: IBridgeParams): Promise<bigint>;
|
|
23
23
|
swapAndBridge(params: ISwapAndBridgeParams): Promise<IReceipt>;
|
|
24
|
+
estimateGas(estimateType: IEstimateType, params: IBridgeParams | ISwapParams | ISwapAndBridgeParams): Promise<bigint>;
|
|
24
25
|
getAggregatorSupportContracts(chain: ChainNameEnum): Promise<SupportContracts[]>;
|
|
25
26
|
getQuoterSupportContracts(chain: ChainNameEnum): Promise<SupportContracts[]>;
|
|
26
27
|
/**
|
package/dist/esm/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
15
15
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
16
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
17
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
-
import { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts } from "./types.js";
|
|
18
|
+
import { ChainNameEnum, AddressConst, DexType, BridgeType, SupportContracts, IEstimateType } from "./types.js";
|
|
19
19
|
import { ethers } from 'ethers';
|
|
20
20
|
import { Contract } from 'ethers';
|
|
21
21
|
import QuoterAbi from "./abis/quoter.js";
|
|
@@ -561,71 +561,199 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
561
561
|
}
|
|
562
562
|
return swapAndBridge;
|
|
563
563
|
}()
|
|
564
|
+
}, {
|
|
565
|
+
key: "estimateGas",
|
|
566
|
+
value: function () {
|
|
567
|
+
var _estimateGas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(estimateType, params) {
|
|
568
|
+
var _params$extra4, _swapAndBridgeParams$;
|
|
569
|
+
var aggregatorAddress, wallet, aggregator, bridgeArgs1, txOverrides1, gasInBridge, swapParams1, swapGas, swapAndBridgeParams, swapParams, bridgeArgs, txOverrides, gas;
|
|
570
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
571
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
572
|
+
case 0:
|
|
573
|
+
this.validateParams(params);
|
|
574
|
+
|
|
575
|
+
// call the aggregator swap and bridge
|
|
576
|
+
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
577
|
+
wallet = this.walletMap.get(params.chain);
|
|
578
|
+
aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
|
|
579
|
+
if (wallet) {
|
|
580
|
+
_context6.next = 6;
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
584
|
+
case 6:
|
|
585
|
+
_context6.t0 = estimateType;
|
|
586
|
+
_context6.next = _context6.t0 === IEstimateType.BRIDGE ? 9 : _context6.t0 === IEstimateType.SWAP ? 17 : _context6.t0 === IEstimateType.SWAPANDBRIDGE ? 26 : 36;
|
|
587
|
+
break;
|
|
588
|
+
case 9:
|
|
589
|
+
if (!(!('bridgeType' in params) || !('destChain' in params))) {
|
|
590
|
+
_context6.next = 11;
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
throw new Error('bridge params required');
|
|
594
|
+
case 11:
|
|
595
|
+
bridgeArgs1 = {
|
|
596
|
+
bridge: params.bridgeType,
|
|
597
|
+
token: params.tokenAddress,
|
|
598
|
+
amount: params.amountInWei,
|
|
599
|
+
bridgeAddress: params.bridgeAddress,
|
|
600
|
+
destChain: params.destChain,
|
|
601
|
+
destUser: params.destUser,
|
|
602
|
+
extra: (_params$extra4 = params.extra) !== null && _params$extra4 !== void 0 ? _params$extra4 : '0x'
|
|
603
|
+
};
|
|
604
|
+
txOverrides1 = {
|
|
605
|
+
from: wallet.address,
|
|
606
|
+
value: params.bridgeFee
|
|
607
|
+
};
|
|
608
|
+
_context6.next = 15;
|
|
609
|
+
return aggregator.bridge.estimateGas(params.user, bridgeArgs1, txOverrides1);
|
|
610
|
+
case 15:
|
|
611
|
+
gasInBridge = _context6.sent;
|
|
612
|
+
return _context6.abrupt("return", gasInBridge);
|
|
613
|
+
case 17:
|
|
614
|
+
if (!(!('path' in params) || !Array.isArray(params.path) || params.path.length === 0)) {
|
|
615
|
+
_context6.next = 19;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
throw new Error('Swap path required for gas estimation');
|
|
619
|
+
case 19:
|
|
620
|
+
if (!(!('minAmountOutList' in params) || params.minAmountOutList.length === 0)) {
|
|
621
|
+
_context6.next = 21;
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
throw new Error('minAmountOutList required for gas estimation');
|
|
625
|
+
case 21:
|
|
626
|
+
swapParams1 = params.path.map(function (pathItem) {
|
|
627
|
+
var _pathItem$extra4;
|
|
628
|
+
return {
|
|
629
|
+
dexType: pathItem.dexType,
|
|
630
|
+
pool: pathItem.poolAddress,
|
|
631
|
+
fromCoin: pathItem.fromCoinAddress,
|
|
632
|
+
toCoin: pathItem.toCoinAddress,
|
|
633
|
+
extra: (_pathItem$extra4 = pathItem.extra) !== null && _pathItem$extra4 !== void 0 ? _pathItem$extra4 : '0x'
|
|
634
|
+
};
|
|
635
|
+
});
|
|
636
|
+
_context6.next = 24;
|
|
637
|
+
return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, {
|
|
638
|
+
from: wallet.address
|
|
639
|
+
});
|
|
640
|
+
case 24:
|
|
641
|
+
swapGas = _context6.sent;
|
|
642
|
+
return _context6.abrupt("return", swapGas);
|
|
643
|
+
case 26:
|
|
644
|
+
if (!(!('path' in params) || !('bridgeType' in params))) {
|
|
645
|
+
_context6.next = 28;
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
throw new Error('swapAndBridge params required');
|
|
649
|
+
case 28:
|
|
650
|
+
swapAndBridgeParams = params;
|
|
651
|
+
swapParams = swapAndBridgeParams.path.map(function (pathItem) {
|
|
652
|
+
var _pathItem$extra5;
|
|
653
|
+
return {
|
|
654
|
+
dexType: pathItem.dexType,
|
|
655
|
+
pool: pathItem.poolAddress,
|
|
656
|
+
fromCoin: pathItem.fromCoinAddress,
|
|
657
|
+
toCoin: pathItem.toCoinAddress,
|
|
658
|
+
extra: (_pathItem$extra5 = pathItem.extra) !== null && _pathItem$extra5 !== void 0 ? _pathItem$extra5 : '0x'
|
|
659
|
+
};
|
|
660
|
+
});
|
|
661
|
+
bridgeArgs = {
|
|
662
|
+
bridge: swapAndBridgeParams.bridgeType,
|
|
663
|
+
token: swapAndBridgeParams.tokenAddress,
|
|
664
|
+
amount: swapAndBridgeParams.amountInWei,
|
|
665
|
+
bridgeAddress: swapAndBridgeParams.bridgeAddress,
|
|
666
|
+
destChain: swapAndBridgeParams.destChain,
|
|
667
|
+
destUser: swapAndBridgeParams.destUser,
|
|
668
|
+
extra: (_swapAndBridgeParams$ = swapAndBridgeParams.extra) !== null && _swapAndBridgeParams$ !== void 0 ? _swapAndBridgeParams$ : '0x'
|
|
669
|
+
};
|
|
670
|
+
txOverrides = {
|
|
671
|
+
from: wallet.address,
|
|
672
|
+
value: swapAndBridgeParams.bridgeFee
|
|
673
|
+
};
|
|
674
|
+
_context6.next = 34;
|
|
675
|
+
return aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txOverrides);
|
|
676
|
+
case 34:
|
|
677
|
+
gas = _context6.sent;
|
|
678
|
+
return _context6.abrupt("return", gas);
|
|
679
|
+
case 36:
|
|
680
|
+
throw 'Not support method in sdk';
|
|
681
|
+
case 37:
|
|
682
|
+
case "end":
|
|
683
|
+
return _context6.stop();
|
|
684
|
+
}
|
|
685
|
+
}, _callee6, this);
|
|
686
|
+
}));
|
|
687
|
+
function estimateGas(_x6, _x7) {
|
|
688
|
+
return _estimateGas.apply(this, arguments);
|
|
689
|
+
}
|
|
690
|
+
return estimateGas;
|
|
691
|
+
}()
|
|
564
692
|
}, {
|
|
565
693
|
key: "getAggregatorSupportContracts",
|
|
566
694
|
value: function () {
|
|
567
|
-
var _getAggregatorSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
695
|
+
var _getAggregatorSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(chain) {
|
|
568
696
|
var aggregatorAddress, provider, aggregator, addressList, supportContracts;
|
|
569
|
-
return _regeneratorRuntime().wrap(function
|
|
570
|
-
while (1) switch (
|
|
697
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
698
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
571
699
|
case 0:
|
|
572
700
|
// 返回传入链支持的dex和桥
|
|
573
701
|
// 返回dex type数组
|
|
574
702
|
aggregatorAddress = this.getAggregatorAddress(chain);
|
|
575
703
|
provider = this.providerMap.get(chain);
|
|
576
704
|
if (provider) {
|
|
577
|
-
|
|
705
|
+
_context8.next = 4;
|
|
578
706
|
break;
|
|
579
707
|
}
|
|
580
708
|
throw new Error("Provider not configured for chain: ".concat(chain));
|
|
581
709
|
case 4:
|
|
582
710
|
aggregator = new Contract(aggregatorAddress, AggregatorAbi, provider);
|
|
583
|
-
|
|
711
|
+
_context8.next = 7;
|
|
584
712
|
return aggregator.getAddressList();
|
|
585
713
|
case 7:
|
|
586
|
-
addressList =
|
|
714
|
+
addressList = _context8.sent;
|
|
587
715
|
if (addressList.length) {
|
|
588
|
-
|
|
716
|
+
_context8.next = 10;
|
|
589
717
|
break;
|
|
590
718
|
}
|
|
591
|
-
return
|
|
719
|
+
return _context8.abrupt("return", []);
|
|
592
720
|
case 10:
|
|
593
|
-
|
|
721
|
+
_context8.next = 12;
|
|
594
722
|
return Promise.all(addressList.map( /*#__PURE__*/function () {
|
|
595
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
723
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(contractAddress, index) {
|
|
596
724
|
var _yield$aggregator$con, contractType;
|
|
597
|
-
return _regeneratorRuntime().wrap(function
|
|
598
|
-
while (1) switch (
|
|
725
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
726
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
599
727
|
case 0:
|
|
600
|
-
|
|
728
|
+
_context7.next = 2;
|
|
601
729
|
return aggregator.contractList(index);
|
|
602
730
|
case 2:
|
|
603
|
-
_yield$aggregator$con =
|
|
731
|
+
_yield$aggregator$con = _context7.sent;
|
|
604
732
|
contractType = _yield$aggregator$con.contractType;
|
|
605
|
-
return
|
|
733
|
+
return _context7.abrupt("return", {
|
|
606
734
|
contractType: contractType,
|
|
607
735
|
contractAddress: contractAddress
|
|
608
736
|
});
|
|
609
737
|
case 5:
|
|
610
738
|
case "end":
|
|
611
|
-
return
|
|
739
|
+
return _context7.stop();
|
|
612
740
|
}
|
|
613
|
-
},
|
|
741
|
+
}, _callee7);
|
|
614
742
|
}));
|
|
615
|
-
return function (
|
|
743
|
+
return function (_x9, _x10) {
|
|
616
744
|
return _ref.apply(this, arguments);
|
|
617
745
|
};
|
|
618
746
|
}()));
|
|
619
747
|
case 12:
|
|
620
|
-
supportContracts =
|
|
621
|
-
return
|
|
748
|
+
supportContracts = _context8.sent;
|
|
749
|
+
return _context8.abrupt("return", supportContracts);
|
|
622
750
|
case 14:
|
|
623
751
|
case "end":
|
|
624
|
-
return
|
|
752
|
+
return _context8.stop();
|
|
625
753
|
}
|
|
626
|
-
},
|
|
754
|
+
}, _callee8, this);
|
|
627
755
|
}));
|
|
628
|
-
function getAggregatorSupportContracts(
|
|
756
|
+
function getAggregatorSupportContracts(_x8) {
|
|
629
757
|
return _getAggregatorSupportContracts.apply(this, arguments);
|
|
630
758
|
}
|
|
631
759
|
return getAggregatorSupportContracts;
|
|
@@ -633,68 +761,68 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
633
761
|
}, {
|
|
634
762
|
key: "getQuoterSupportContracts",
|
|
635
763
|
value: function () {
|
|
636
|
-
var _getQuoterSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
764
|
+
var _getQuoterSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(chain) {
|
|
637
765
|
var quoterAddress, provider, quoter, addressList, supportContracts;
|
|
638
|
-
return _regeneratorRuntime().wrap(function
|
|
639
|
-
while (1) switch (
|
|
766
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
767
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
640
768
|
case 0:
|
|
641
769
|
// 返回传入链支持的dex和桥
|
|
642
770
|
// 返回dex type数组
|
|
643
771
|
quoterAddress = this.getQuoterAddress(chain);
|
|
644
772
|
provider = this.providerMap.get(chain);
|
|
645
773
|
if (provider) {
|
|
646
|
-
|
|
774
|
+
_context10.next = 4;
|
|
647
775
|
break;
|
|
648
776
|
}
|
|
649
777
|
throw new Error("Provider not configured for chain: ".concat(chain));
|
|
650
778
|
case 4:
|
|
651
779
|
quoter = new Contract(quoterAddress, QuoterAbi, provider);
|
|
652
|
-
|
|
780
|
+
_context10.next = 7;
|
|
653
781
|
return quoter.getAddressList();
|
|
654
782
|
case 7:
|
|
655
|
-
addressList =
|
|
783
|
+
addressList = _context10.sent;
|
|
656
784
|
if (addressList.length) {
|
|
657
|
-
|
|
785
|
+
_context10.next = 10;
|
|
658
786
|
break;
|
|
659
787
|
}
|
|
660
|
-
return
|
|
788
|
+
return _context10.abrupt("return", []);
|
|
661
789
|
case 10:
|
|
662
|
-
|
|
790
|
+
_context10.next = 12;
|
|
663
791
|
return Promise.all(addressList.map( /*#__PURE__*/function () {
|
|
664
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
792
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(contractAddress, index) {
|
|
665
793
|
var _yield$quoter$contrac, contractType;
|
|
666
|
-
return _regeneratorRuntime().wrap(function
|
|
667
|
-
while (1) switch (
|
|
794
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
795
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
668
796
|
case 0:
|
|
669
|
-
|
|
797
|
+
_context9.next = 2;
|
|
670
798
|
return quoter.contractList(index);
|
|
671
799
|
case 2:
|
|
672
|
-
_yield$quoter$contrac =
|
|
800
|
+
_yield$quoter$contrac = _context9.sent;
|
|
673
801
|
contractType = _yield$quoter$contrac.contractType;
|
|
674
|
-
return
|
|
802
|
+
return _context9.abrupt("return", {
|
|
675
803
|
contractType: contractType,
|
|
676
804
|
contractAddress: contractAddress
|
|
677
805
|
});
|
|
678
806
|
case 5:
|
|
679
807
|
case "end":
|
|
680
|
-
return
|
|
808
|
+
return _context9.stop();
|
|
681
809
|
}
|
|
682
|
-
},
|
|
810
|
+
}, _callee9);
|
|
683
811
|
}));
|
|
684
|
-
return function (
|
|
812
|
+
return function (_x12, _x13) {
|
|
685
813
|
return _ref2.apply(this, arguments);
|
|
686
814
|
};
|
|
687
815
|
}()));
|
|
688
816
|
case 12:
|
|
689
|
-
supportContracts =
|
|
690
|
-
return
|
|
817
|
+
supportContracts = _context10.sent;
|
|
818
|
+
return _context10.abrupt("return", supportContracts);
|
|
691
819
|
case 14:
|
|
692
820
|
case "end":
|
|
693
|
-
return
|
|
821
|
+
return _context10.stop();
|
|
694
822
|
}
|
|
695
|
-
},
|
|
823
|
+
}, _callee10, this);
|
|
696
824
|
}));
|
|
697
|
-
function getQuoterSupportContracts(
|
|
825
|
+
function getQuoterSupportContracts(_x11) {
|
|
698
826
|
return _getQuoterSupportContracts.apply(this, arguments);
|
|
699
827
|
}
|
|
700
828
|
return getQuoterSupportContracts;
|
|
@@ -705,7 +833,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
705
833
|
}, {
|
|
706
834
|
key: "genSwapAndBridgeCalldata",
|
|
707
835
|
value: function genSwapAndBridgeCalldata(params) {
|
|
708
|
-
var _params$
|
|
836
|
+
var _params$extra5;
|
|
709
837
|
this.validateParams(params);
|
|
710
838
|
if (!params.path || params.path.length === 0) {
|
|
711
839
|
throw new Error('Swap path not provided');
|
|
@@ -714,13 +842,13 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
714
842
|
|
|
715
843
|
// 准备 swap 参数
|
|
716
844
|
var swapParams = params.path.map(function (pathItem) {
|
|
717
|
-
var _pathItem$
|
|
845
|
+
var _pathItem$extra6;
|
|
718
846
|
return {
|
|
719
847
|
dexType: pathItem.dexType,
|
|
720
848
|
pool: pathItem.poolAddress,
|
|
721
849
|
fromCoin: pathItem.fromCoinAddress,
|
|
722
850
|
toCoin: pathItem.toCoinAddress,
|
|
723
|
-
extra: (_pathItem$
|
|
851
|
+
extra: (_pathItem$extra6 = pathItem.extra) !== null && _pathItem$extra6 !== void 0 ? _pathItem$extra6 : '0x'
|
|
724
852
|
};
|
|
725
853
|
});
|
|
726
854
|
|
|
@@ -733,7 +861,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
733
861
|
bridgeAddress: params.bridgeAddress,
|
|
734
862
|
refundAddress: params.destUser,
|
|
735
863
|
destinationChain: params.destChain,
|
|
736
|
-
adapterParams: (_params$
|
|
864
|
+
adapterParams: (_params$extra5 = params.extra) !== null && _params$extra5 !== void 0 ? _params$extra5 : '0x'
|
|
737
865
|
}
|
|
738
866
|
};
|
|
739
867
|
|
|
@@ -750,39 +878,39 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
750
878
|
}, {
|
|
751
879
|
key: "checkIsEnoughToken",
|
|
752
880
|
value: function () {
|
|
753
|
-
var _checkIsEnoughToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
881
|
+
var _checkIsEnoughToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(fromTokenAddress, userAddress, amountInWei, aggregatorAddress, wallet) {
|
|
754
882
|
var erc20, userBalance, currentAllowance;
|
|
755
|
-
return _regeneratorRuntime().wrap(function
|
|
756
|
-
while (1) switch (
|
|
883
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
884
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
757
885
|
case 0:
|
|
758
886
|
erc20 = new Contract(fromTokenAddress, ['function balanceOf(address) view returns (uint256)', 'function allowance(address, address) view returns (uint256)'], wallet);
|
|
759
|
-
|
|
887
|
+
_context11.next = 3;
|
|
760
888
|
return erc20.balanceOf(userAddress);
|
|
761
889
|
case 3:
|
|
762
|
-
userBalance =
|
|
890
|
+
userBalance = _context11.sent;
|
|
763
891
|
if (!(userBalance < amountInWei)) {
|
|
764
|
-
|
|
892
|
+
_context11.next = 6;
|
|
765
893
|
break;
|
|
766
894
|
}
|
|
767
895
|
throw new Error('Insufficient balance token amount');
|
|
768
896
|
case 6:
|
|
769
|
-
|
|
897
|
+
_context11.next = 8;
|
|
770
898
|
return erc20.allowance(userAddress, aggregatorAddress);
|
|
771
899
|
case 8:
|
|
772
|
-
currentAllowance =
|
|
900
|
+
currentAllowance = _context11.sent;
|
|
773
901
|
console.log(currentAllowance);
|
|
774
902
|
if (!(currentAllowance < amountInWei)) {
|
|
775
|
-
|
|
903
|
+
_context11.next = 12;
|
|
776
904
|
break;
|
|
777
905
|
}
|
|
778
906
|
throw new Error('Insufficient allowance token amount');
|
|
779
907
|
case 12:
|
|
780
908
|
case "end":
|
|
781
|
-
return
|
|
909
|
+
return _context11.stop();
|
|
782
910
|
}
|
|
783
|
-
},
|
|
911
|
+
}, _callee11);
|
|
784
912
|
}));
|
|
785
|
-
function checkIsEnoughToken(
|
|
913
|
+
function checkIsEnoughToken(_x14, _x15, _x16, _x17, _x18) {
|
|
786
914
|
return _checkIsEnoughToken.apply(this, arguments);
|
|
787
915
|
}
|
|
788
916
|
return checkIsEnoughToken;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -108,6 +108,11 @@ export declare enum DexType {
|
|
|
108
108
|
VSDCRVWITHDRAW = "vsdCRV_withdraw",
|
|
109
109
|
VSDCRVDEPOSIT = "vsdCRV_deposit"
|
|
110
110
|
}
|
|
111
|
+
export declare enum IEstimateType {
|
|
112
|
+
BRIDGE = "bridge",
|
|
113
|
+
SWAPANDBRIDGE = "swapAndBridge",
|
|
114
|
+
SWAP = "swap"
|
|
115
|
+
}
|
|
111
116
|
export declare enum BridgeType {
|
|
112
117
|
LAYERZEROV1 = "layerzero_v1",
|
|
113
118
|
LAYERZEROV2 = "layerzero_v2",
|
package/dist/esm/types.js
CHANGED
|
@@ -14,6 +14,12 @@ export var DexType = /*#__PURE__*/function (DexType) {
|
|
|
14
14
|
DexType["VSDCRVDEPOSIT"] = "vsdCRV_deposit";
|
|
15
15
|
return DexType;
|
|
16
16
|
}({});
|
|
17
|
+
export var IEstimateType = /*#__PURE__*/function (IEstimateType) {
|
|
18
|
+
IEstimateType["BRIDGE"] = "bridge";
|
|
19
|
+
IEstimateType["SWAPANDBRIDGE"] = "swapAndBridge";
|
|
20
|
+
IEstimateType["SWAP"] = "swap";
|
|
21
|
+
return IEstimateType;
|
|
22
|
+
}({});
|
|
17
23
|
export var BridgeType = /*#__PURE__*/function (BridgeType) {
|
|
18
24
|
BridgeType["LAYERZEROV1"] = "layerzero_v1";
|
|
19
25
|
BridgeType["LAYERZEROV2"] = "layerzero_v2";
|