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