hermes-swap 0.3.6 → 0.3.8
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.js +14 -14
- package/dist/esm/index.js +21 -22
- package/package.json +1 -2
package/dist/cjs/index.js
CHANGED
|
@@ -680,15 +680,15 @@ var Hermes = class {
|
|
|
680
680
|
}
|
|
681
681
|
async estimateBridgeFee(params) {
|
|
682
682
|
this.validateParams(params);
|
|
683
|
-
const wallet = this.walletMap.get(params.chain);
|
|
684
|
-
if (!wallet) {
|
|
685
|
-
throw new Error(`Wallet not configured for chain: ${params.chain}`);
|
|
686
|
-
}
|
|
687
683
|
const address = this.getQuoterAddress(params.chain);
|
|
688
684
|
if (!address) {
|
|
689
685
|
throw new Error(`Quoter address not found for chain: ${params.chain}`);
|
|
690
686
|
}
|
|
691
|
-
const
|
|
687
|
+
const provider = this.providerMap.get(params.chain);
|
|
688
|
+
if (!provider) {
|
|
689
|
+
throw new Error(`Chain: ${params.chain} provider is undefined`);
|
|
690
|
+
}
|
|
691
|
+
const quoter = new import_ethers.Contract(address, import_quoter.default, provider);
|
|
692
692
|
const bridgeArgs = {
|
|
693
693
|
bridge: params.bridgeType,
|
|
694
694
|
token: params.tokenAddress,
|
|
@@ -698,7 +698,7 @@ var Hermes = class {
|
|
|
698
698
|
destUser: params.destUser,
|
|
699
699
|
extra: params.extra ?? "0x"
|
|
700
700
|
};
|
|
701
|
-
const bridgeFee = await quoter.quoteBridge.staticCall(bridgeArgs, { from:
|
|
701
|
+
const bridgeFee = await quoter.quoteBridge.staticCall(bridgeArgs, { from: this.config.executor });
|
|
702
702
|
return bridgeFee;
|
|
703
703
|
}
|
|
704
704
|
async swapAndBridge(params, txReq = {}) {
|
|
@@ -763,12 +763,12 @@ var Hermes = class {
|
|
|
763
763
|
}
|
|
764
764
|
async estimateGas(estimateType, params) {
|
|
765
765
|
this.validateParams(params);
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (!wallet) {
|
|
770
|
-
throw new Error(`Wallet not configured for chain: ${params.chain}`);
|
|
766
|
+
const provider = this.providerMap.get(params.chain);
|
|
767
|
+
if (!provider) {
|
|
768
|
+
throw new Error(`Chain: ${params.chain} provider is undefined`);
|
|
771
769
|
}
|
|
770
|
+
const aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
771
|
+
const aggregator = new import_ethers.Contract(aggregatorAddress, import_aggregator.default, provider);
|
|
772
772
|
switch (estimateType) {
|
|
773
773
|
case import_types.IEstimateType.BRIDGE:
|
|
774
774
|
if (!("bridgeType" in params) || !("destChain" in params)) {
|
|
@@ -784,7 +784,7 @@ var Hermes = class {
|
|
|
784
784
|
extra: params.extra ?? "0x"
|
|
785
785
|
};
|
|
786
786
|
const txOverrides1 = {
|
|
787
|
-
from:
|
|
787
|
+
from: this.config.executor,
|
|
788
788
|
value: params.bridgeFee
|
|
789
789
|
};
|
|
790
790
|
const gasInBridge = await aggregator.bridge.estimateGas(params.user, bridgeArgs1, txOverrides1);
|
|
@@ -803,7 +803,7 @@ var Hermes = class {
|
|
|
803
803
|
toCoin: pathItem.toCoinAddress,
|
|
804
804
|
extra: pathItem.extra ?? "0x"
|
|
805
805
|
}));
|
|
806
|
-
const swapGas = await aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, { from:
|
|
806
|
+
const swapGas = await aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, { from: this.config.executor });
|
|
807
807
|
return swapGas;
|
|
808
808
|
case import_types.IEstimateType.SWAPANDBRIDGE:
|
|
809
809
|
if (!("path" in params) || !("bridgeType" in params)) {
|
|
@@ -827,7 +827,7 @@ var Hermes = class {
|
|
|
827
827
|
extra: swapAndBridgeParams.extra ?? "0x"
|
|
828
828
|
};
|
|
829
829
|
const txOverrides = {
|
|
830
|
-
from:
|
|
830
|
+
from: this.config.executor,
|
|
831
831
|
value: swapAndBridgeParams.bridgeFee
|
|
832
832
|
};
|
|
833
833
|
const gas = await aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txOverrides);
|
package/dist/esm/index.js
CHANGED
|
@@ -1419,26 +1419,26 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1419
1419
|
value: function () {
|
|
1420
1420
|
var _estimateBridgeFee = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
|
|
1421
1421
|
var _params$extra4;
|
|
1422
|
-
var
|
|
1422
|
+
var address, provider, quoter, bridgeArgs, bridgeFee;
|
|
1423
1423
|
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1424
1424
|
while (1) switch (_context13.prev = _context13.next) {
|
|
1425
1425
|
case 0:
|
|
1426
1426
|
this.validateParams(params);
|
|
1427
|
-
|
|
1428
|
-
if (
|
|
1427
|
+
address = this.getQuoterAddress(params.chain);
|
|
1428
|
+
if (address) {
|
|
1429
1429
|
_context13.next = 4;
|
|
1430
1430
|
break;
|
|
1431
1431
|
}
|
|
1432
|
-
throw new Error("
|
|
1432
|
+
throw new Error("Quoter address not found for chain: ".concat(params.chain));
|
|
1433
1433
|
case 4:
|
|
1434
|
-
|
|
1435
|
-
if (
|
|
1434
|
+
provider = this.providerMap.get(params.chain);
|
|
1435
|
+
if (provider) {
|
|
1436
1436
|
_context13.next = 7;
|
|
1437
1437
|
break;
|
|
1438
1438
|
}
|
|
1439
|
-
throw new Error("
|
|
1439
|
+
throw new Error("Chain: ".concat(params.chain, " provider is undefined"));
|
|
1440
1440
|
case 7:
|
|
1441
|
-
quoter = new Contract(address, QuoterAbi,
|
|
1441
|
+
quoter = new Contract(address, QuoterAbi, provider);
|
|
1442
1442
|
bridgeArgs = {
|
|
1443
1443
|
bridge: params.bridgeType,
|
|
1444
1444
|
token: params.tokenAddress,
|
|
@@ -1450,7 +1450,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1450
1450
|
};
|
|
1451
1451
|
_context13.next = 11;
|
|
1452
1452
|
return quoter.quoteBridge.staticCall(bridgeArgs, {
|
|
1453
|
-
from:
|
|
1453
|
+
from: this.config.executor
|
|
1454
1454
|
});
|
|
1455
1455
|
case 11:
|
|
1456
1456
|
bridgeFee = _context13.sent;
|
|
@@ -1628,22 +1628,21 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1628
1628
|
value: function () {
|
|
1629
1629
|
var _estimateGas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(estimateType, params) {
|
|
1630
1630
|
var _params$extra6, _swapAndBridgeParams$;
|
|
1631
|
-
var
|
|
1631
|
+
var provider, aggregatorAddress, aggregator, bridgeArgs1, txOverrides1, gasInBridge, swapParams1, swapGas, swapAndBridgeParams, swapParams, bridgeArgs, txOverrides, gas;
|
|
1632
1632
|
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1633
1633
|
while (1) switch (_context15.prev = _context15.next) {
|
|
1634
1634
|
case 0:
|
|
1635
1635
|
this.validateParams(params);
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
wallet = this.walletMap.get(params.chain);
|
|
1640
|
-
aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
|
|
1641
|
-
if (wallet) {
|
|
1642
|
-
_context15.next = 6;
|
|
1636
|
+
provider = this.providerMap.get(params.chain);
|
|
1637
|
+
if (provider) {
|
|
1638
|
+
_context15.next = 4;
|
|
1643
1639
|
break;
|
|
1644
1640
|
}
|
|
1645
|
-
throw new Error("
|
|
1646
|
-
case
|
|
1641
|
+
throw new Error("Chain: ".concat(params.chain, " provider is undefined"));
|
|
1642
|
+
case 4:
|
|
1643
|
+
// call the aggregator swap and bridge
|
|
1644
|
+
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
1645
|
+
aggregator = new Contract(aggregatorAddress, AggregatorAbi, provider);
|
|
1647
1646
|
_context15.t0 = estimateType;
|
|
1648
1647
|
_context15.next = _context15.t0 === IEstimateType.BRIDGE ? 9 : _context15.t0 === IEstimateType.SWAP ? 17 : _context15.t0 === IEstimateType.SWAPANDBRIDGE ? 26 : 36;
|
|
1649
1648
|
break;
|
|
@@ -1664,7 +1663,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1664
1663
|
extra: (_params$extra6 = params.extra) !== null && _params$extra6 !== void 0 ? _params$extra6 : '0x'
|
|
1665
1664
|
};
|
|
1666
1665
|
txOverrides1 = {
|
|
1667
|
-
from:
|
|
1666
|
+
from: this.config.executor,
|
|
1668
1667
|
value: params.bridgeFee
|
|
1669
1668
|
};
|
|
1670
1669
|
_context15.next = 15;
|
|
@@ -1697,7 +1696,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1697
1696
|
});
|
|
1698
1697
|
_context15.next = 24;
|
|
1699
1698
|
return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, {
|
|
1700
|
-
from:
|
|
1699
|
+
from: this.config.executor
|
|
1701
1700
|
});
|
|
1702
1701
|
case 24:
|
|
1703
1702
|
swapGas = _context15.sent;
|
|
@@ -1730,7 +1729,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1730
1729
|
extra: (_swapAndBridgeParams$ = swapAndBridgeParams.extra) !== null && _swapAndBridgeParams$ !== void 0 ? _swapAndBridgeParams$ : '0x'
|
|
1731
1730
|
};
|
|
1732
1731
|
txOverrides = {
|
|
1733
|
-
from:
|
|
1732
|
+
from: this.config.executor,
|
|
1734
1733
|
value: swapAndBridgeParams.bridgeFee
|
|
1735
1734
|
};
|
|
1736
1735
|
_context15.next = 34;
|
package/package.json
CHANGED