hermes-swap 0.1.3 → 0.1.4
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 +5 -9
- package/dist/cjs/types.d.ts +1 -0
- package/dist/esm/index.js +16 -23
- package/dist/esm/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -73,10 +73,6 @@ var Hermes = class {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async expectPriorityLocal(params) {
|
|
76
|
-
const wallet = this.walletMap.get(params.chain);
|
|
77
|
-
if (!wallet) {
|
|
78
|
-
throw new Error(`Wallet not configured for chain: ${params.chain}`);
|
|
79
|
-
}
|
|
80
76
|
const response = await fetch(`${this.config.hermesSignalDomain}/api/v1/quote`, {
|
|
81
77
|
method: "POST",
|
|
82
78
|
headers: {
|
|
@@ -94,15 +90,15 @@ var Hermes = class {
|
|
|
94
90
|
return BigInt(data.amountOutWei);
|
|
95
91
|
}
|
|
96
92
|
async expect(params) {
|
|
97
|
-
const
|
|
98
|
-
if (!
|
|
99
|
-
throw new Error(`
|
|
93
|
+
const provider = this.providerMap.get(params.chain);
|
|
94
|
+
if (!provider) {
|
|
95
|
+
throw new Error(`Chain: ${params.chain} provider is undefined`);
|
|
100
96
|
}
|
|
101
97
|
const address = this.getQuoterAddress(params.chain);
|
|
102
98
|
if (!address) {
|
|
103
99
|
throw new Error(`Quoter address not found for chain: ${params.chain}`);
|
|
104
100
|
}
|
|
105
|
-
const quoter = new import_ethers.Contract(address, import_quoter.default,
|
|
101
|
+
const quoter = new import_ethers.Contract(address, import_quoter.default, provider);
|
|
106
102
|
const quoteParams = params.path.map((p) => ({
|
|
107
103
|
dexType: p.dexType,
|
|
108
104
|
pool: p.poolAddress,
|
|
@@ -110,7 +106,7 @@ var Hermes = class {
|
|
|
110
106
|
toCoin: p.toCoinAddress,
|
|
111
107
|
extra: p.extra || "0x"
|
|
112
108
|
}));
|
|
113
|
-
const amountOutList = await quoter.multiQuote.staticCall(params.amountInWei, quoteParams, { from:
|
|
109
|
+
const amountOutList = await quoter.multiQuote.staticCall(params.amountInWei, quoteParams, { from: this.config.executor });
|
|
114
110
|
if (!amountOutList.length) {
|
|
115
111
|
throw new Error("No expect result return from smart contract");
|
|
116
112
|
}
|
package/dist/cjs/types.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -73,18 +73,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
73
73
|
key: "expectPriorityLocal",
|
|
74
74
|
value: function () {
|
|
75
75
|
var _expectPriorityLocal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
76
|
-
var
|
|
76
|
+
var response, data;
|
|
77
77
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
78
78
|
while (1) switch (_context.prev = _context.next) {
|
|
79
79
|
case 0:
|
|
80
|
-
|
|
81
|
-
if (wallet) {
|
|
82
|
-
_context.next = 3;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
86
|
-
case 3:
|
|
87
|
-
_context.next = 5;
|
|
80
|
+
_context.next = 2;
|
|
88
81
|
return fetch("".concat(this.config.hermesSignalDomain, "/api/v1/quote"), {
|
|
89
82
|
method: 'POST',
|
|
90
83
|
headers: {
|
|
@@ -94,26 +87,26 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
94
87
|
return typeof value === 'bigint' ? value.toString() : value;
|
|
95
88
|
})
|
|
96
89
|
});
|
|
97
|
-
case
|
|
90
|
+
case 2:
|
|
98
91
|
response = _context.sent;
|
|
99
|
-
_context.next =
|
|
92
|
+
_context.next = 5;
|
|
100
93
|
return response.json();
|
|
101
|
-
case
|
|
94
|
+
case 5:
|
|
102
95
|
data = _context.sent;
|
|
103
96
|
if (!(data.message && !data.amountOutWei)) {
|
|
104
|
-
_context.next =
|
|
97
|
+
_context.next = 8;
|
|
105
98
|
break;
|
|
106
99
|
}
|
|
107
100
|
throw new Error("Hermes Signal API \u9519\u8BEF: ".concat(data.message));
|
|
108
|
-
case
|
|
101
|
+
case 8:
|
|
109
102
|
if (data.amountOutWei) {
|
|
110
|
-
_context.next =
|
|
103
|
+
_context.next = 10;
|
|
111
104
|
break;
|
|
112
105
|
}
|
|
113
106
|
throw new Error("Invalid response: amountOutWei is undefined. Response: ".concat(JSON.stringify(data)));
|
|
114
|
-
case
|
|
107
|
+
case 10:
|
|
115
108
|
return _context.abrupt("return", BigInt(data.amountOutWei));
|
|
116
|
-
case
|
|
109
|
+
case 11:
|
|
117
110
|
case "end":
|
|
118
111
|
return _context.stop();
|
|
119
112
|
}
|
|
@@ -128,17 +121,17 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
128
121
|
key: "expect",
|
|
129
122
|
value: function () {
|
|
130
123
|
var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
131
|
-
var
|
|
124
|
+
var provider, address, quoter, quoteParams, amountOutList;
|
|
132
125
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
133
126
|
while (1) switch (_context2.prev = _context2.next) {
|
|
134
127
|
case 0:
|
|
135
128
|
// 调用合约
|
|
136
|
-
|
|
137
|
-
if (
|
|
129
|
+
provider = this.providerMap.get(params.chain);
|
|
130
|
+
if (provider) {
|
|
138
131
|
_context2.next = 3;
|
|
139
132
|
break;
|
|
140
133
|
}
|
|
141
|
-
throw new Error("
|
|
134
|
+
throw new Error("Chain: ".concat(params.chain, " provider is undefined"));
|
|
142
135
|
case 3:
|
|
143
136
|
address = this.getQuoterAddress(params.chain);
|
|
144
137
|
if (address) {
|
|
@@ -147,7 +140,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
147
140
|
}
|
|
148
141
|
throw new Error("Quoter address not found for chain: ".concat(params.chain));
|
|
149
142
|
case 6:
|
|
150
|
-
quoter = new Contract(address, QuoterAbi,
|
|
143
|
+
quoter = new Contract(address, QuoterAbi, provider); // 转换字段名以匹配合约 ABI
|
|
151
144
|
quoteParams = params.path.map(function (p) {
|
|
152
145
|
return {
|
|
153
146
|
dexType: p.dexType,
|
|
@@ -159,7 +152,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
159
152
|
});
|
|
160
153
|
_context2.next = 10;
|
|
161
154
|
return quoter.multiQuote.staticCall(params.amountInWei, quoteParams, {
|
|
162
|
-
from:
|
|
155
|
+
from: this.config.executor
|
|
163
156
|
});
|
|
164
157
|
case 10:
|
|
165
158
|
amountOutList = _context2.sent;
|
package/dist/esm/types.d.ts
CHANGED