hermes-swap 0.2.0 → 0.3.0
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 +4 -3
- package/dist/cjs/index.js +40 -1
- package/dist/cjs/types.d.ts +12 -1
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +484 -414
- package/dist/esm/types.d.ts +12 -1
- package/dist/esm/types.js +0 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -8,9 +8,9 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
8
8
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
9
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
10
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
12
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
12
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
14
14
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
15
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
16
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
@@ -46,7 +46,9 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
46
46
|
_defineProperty(this, "executor", void 0);
|
|
47
47
|
this.config = config;
|
|
48
48
|
this.executor = config.executor;
|
|
49
|
-
|
|
49
|
+
if (config.flashbotSigner) {
|
|
50
|
+
this.flashbotSigner = new ethers.Wallet(config.flashbotSigner);
|
|
51
|
+
}
|
|
50
52
|
if (!config.hermesSignalDomain || config.hermesSignalDomain === '') {
|
|
51
53
|
// 默认 domain
|
|
52
54
|
this.config.hermesSignalDomain = 'http://127.0.0.1:3002';
|
|
@@ -77,22 +79,25 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
_createClass(Hermes, [{
|
|
80
|
-
key: "
|
|
82
|
+
key: "expectWithSplitOrder",
|
|
81
83
|
value: function () {
|
|
82
|
-
var
|
|
84
|
+
var _expectWithSplitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
83
85
|
var response, data;
|
|
84
86
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
85
87
|
while (1) switch (_context.prev = _context.next) {
|
|
86
88
|
case 0:
|
|
87
89
|
_context.next = 2;
|
|
88
|
-
return fetch("".concat(this.config.hermesSignalDomain, "/api/v1/quote"), {
|
|
90
|
+
return fetch("".concat(this.config.hermesSignalDomain, "/api/v1/quote-best"), {
|
|
89
91
|
method: 'POST',
|
|
90
92
|
headers: {
|
|
91
93
|
'Content-Type': 'application/json'
|
|
92
94
|
},
|
|
93
|
-
body: JSON.stringify(
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
body: JSON.stringify({
|
|
96
|
+
chain: params.chain,
|
|
97
|
+
amountInWei: params.amountInWei,
|
|
98
|
+
fromToken: params.fromTokenAddress,
|
|
99
|
+
toToken: params.toTokenAddress
|
|
100
|
+
}, function (sanitizePricing, value) {
|
|
96
101
|
return typeof value === 'bigint' ? value.toString() : value;
|
|
97
102
|
})
|
|
98
103
|
});
|
|
@@ -108,20 +113,79 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
108
113
|
}
|
|
109
114
|
throw new Error("Hermes Signal API \u9519\u8BEF [".concat(data.code, "]: ").concat(data.msg));
|
|
110
115
|
case 8:
|
|
111
|
-
if (data
|
|
116
|
+
if (Array.isArray(data)) {
|
|
112
117
|
_context.next = 10;
|
|
113
118
|
break;
|
|
114
119
|
}
|
|
115
|
-
throw new Error("Invalid response:
|
|
120
|
+
throw new Error("Invalid response: expected array. Response: ".concat(JSON.stringify(data)));
|
|
116
121
|
case 10:
|
|
117
|
-
return _context.abrupt("return",
|
|
122
|
+
return _context.abrupt("return", data.map(function (item) {
|
|
123
|
+
if (!item.poolStepConfig || item.amountInWei == null || item.amountOutWei == null) {
|
|
124
|
+
throw new Error("Invalid response item: ".concat(JSON.stringify(item)));
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
routePath: item.poolStepConfig,
|
|
128
|
+
amountIn: BigInt(item.amountInWei),
|
|
129
|
+
amountOut: BigInt(item.amountOutWei)
|
|
130
|
+
};
|
|
131
|
+
}));
|
|
118
132
|
case 11:
|
|
119
133
|
case "end":
|
|
120
134
|
return _context.stop();
|
|
121
135
|
}
|
|
122
136
|
}, _callee, this);
|
|
123
137
|
}));
|
|
124
|
-
function
|
|
138
|
+
function expectWithSplitOrder(_x) {
|
|
139
|
+
return _expectWithSplitOrder.apply(this, arguments);
|
|
140
|
+
}
|
|
141
|
+
return expectWithSplitOrder;
|
|
142
|
+
}()
|
|
143
|
+
}, {
|
|
144
|
+
key: "expectPriorityLocal",
|
|
145
|
+
value: function () {
|
|
146
|
+
var _expectPriorityLocal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
|
|
147
|
+
var response, data;
|
|
148
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
149
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
150
|
+
case 0:
|
|
151
|
+
_context2.next = 2;
|
|
152
|
+
return fetch("".concat(this.config.hermesSignalDomain, "/api/v1/quote"), {
|
|
153
|
+
method: 'POST',
|
|
154
|
+
headers: {
|
|
155
|
+
'Content-Type': 'application/json'
|
|
156
|
+
},
|
|
157
|
+
body: JSON.stringify(_objectSpread({
|
|
158
|
+
executor: this.config.executor
|
|
159
|
+
}, params), function (sanitizePricing, value) {
|
|
160
|
+
return typeof value === 'bigint' ? value.toString() : value;
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
case 2:
|
|
164
|
+
response = _context2.sent;
|
|
165
|
+
_context2.next = 5;
|
|
166
|
+
return response.json();
|
|
167
|
+
case 5:
|
|
168
|
+
data = _context2.sent;
|
|
169
|
+
if (!(data.code && data.msg)) {
|
|
170
|
+
_context2.next = 8;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
throw new Error("Hermes Signal API \u9519\u8BEF [".concat(data.code, "]: ").concat(data.msg));
|
|
174
|
+
case 8:
|
|
175
|
+
if (data.amountOutWei) {
|
|
176
|
+
_context2.next = 10;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
throw new Error("Invalid response: amountOutWei is undefined. Response: ".concat(JSON.stringify(data)));
|
|
180
|
+
case 10:
|
|
181
|
+
return _context2.abrupt("return", BigInt(data.amountOutWei));
|
|
182
|
+
case 11:
|
|
183
|
+
case "end":
|
|
184
|
+
return _context2.stop();
|
|
185
|
+
}
|
|
186
|
+
}, _callee2, this);
|
|
187
|
+
}));
|
|
188
|
+
function expectPriorityLocal(_x2) {
|
|
125
189
|
return _expectPriorityLocal.apply(this, arguments);
|
|
126
190
|
}
|
|
127
191
|
return expectPriorityLocal;
|
|
@@ -129,22 +193,22 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
129
193
|
}, {
|
|
130
194
|
key: "expect",
|
|
131
195
|
value: function () {
|
|
132
|
-
var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
196
|
+
var _expect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
|
|
133
197
|
var provider, address, quoter, quoteParams, amountOutList;
|
|
134
|
-
return _regeneratorRuntime().wrap(function
|
|
135
|
-
while (1) switch (
|
|
198
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
199
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
136
200
|
case 0:
|
|
137
201
|
// 调用合约
|
|
138
202
|
provider = this.providerMap.get(params.chain);
|
|
139
203
|
if (provider) {
|
|
140
|
-
|
|
204
|
+
_context3.next = 3;
|
|
141
205
|
break;
|
|
142
206
|
}
|
|
143
207
|
throw new Error("Chain: ".concat(params.chain, " provider is undefined"));
|
|
144
208
|
case 3:
|
|
145
209
|
address = this.getQuoterAddress(params.chain);
|
|
146
210
|
if (address) {
|
|
147
|
-
|
|
211
|
+
_context3.next = 6;
|
|
148
212
|
break;
|
|
149
213
|
}
|
|
150
214
|
throw new Error("Quoter address not found for chain: ".concat(params.chain));
|
|
@@ -159,26 +223,26 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
159
223
|
extra: p.extra || '0x'
|
|
160
224
|
};
|
|
161
225
|
});
|
|
162
|
-
|
|
226
|
+
_context3.next = 10;
|
|
163
227
|
return quoter.multiQuote.staticCall(params.amountInWei, quoteParams, {
|
|
164
228
|
from: this.config.executor
|
|
165
229
|
});
|
|
166
230
|
case 10:
|
|
167
|
-
amountOutList =
|
|
231
|
+
amountOutList = _context3.sent;
|
|
168
232
|
if (amountOutList.length) {
|
|
169
|
-
|
|
233
|
+
_context3.next = 13;
|
|
170
234
|
break;
|
|
171
235
|
}
|
|
172
236
|
throw new Error('No expect result return from smart contract');
|
|
173
237
|
case 13:
|
|
174
|
-
return
|
|
238
|
+
return _context3.abrupt("return", amountOutList[amountOutList.length - 1]);
|
|
175
239
|
case 14:
|
|
176
240
|
case "end":
|
|
177
|
-
return
|
|
241
|
+
return _context3.stop();
|
|
178
242
|
}
|
|
179
|
-
},
|
|
243
|
+
}, _callee3, this);
|
|
180
244
|
}));
|
|
181
|
-
function expect(
|
|
245
|
+
function expect(_x3) {
|
|
182
246
|
return _expect.apply(this, arguments);
|
|
183
247
|
}
|
|
184
248
|
return expect;
|
|
@@ -186,27 +250,27 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
186
250
|
}, {
|
|
187
251
|
key: "batchMultiExpect",
|
|
188
252
|
value: function () {
|
|
189
|
-
var _batchMultiExpect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
253
|
+
var _batchMultiExpect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
190
254
|
var provider, address, quoter, quoteParamsArr, amountOutListArr;
|
|
191
|
-
return _regeneratorRuntime().wrap(function
|
|
192
|
-
while (1) switch (
|
|
255
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
256
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
193
257
|
case 0:
|
|
194
258
|
provider = this.providerMap.get(params.chain);
|
|
195
259
|
if (provider) {
|
|
196
|
-
|
|
260
|
+
_context4.next = 3;
|
|
197
261
|
break;
|
|
198
262
|
}
|
|
199
263
|
throw new Error("Chain: ".concat(params.chain, " provider is undefined"));
|
|
200
264
|
case 3:
|
|
201
265
|
if (!(params.amountInWei.length !== params.path.length)) {
|
|
202
|
-
|
|
266
|
+
_context4.next = 5;
|
|
203
267
|
break;
|
|
204
268
|
}
|
|
205
269
|
throw new Error('amountInWei length must match path length');
|
|
206
270
|
case 5:
|
|
207
271
|
address = this.getQuoterAddress(params.chain);
|
|
208
272
|
if (address) {
|
|
209
|
-
|
|
273
|
+
_context4.next = 8;
|
|
210
274
|
break;
|
|
211
275
|
}
|
|
212
276
|
throw new Error("Quoter address not found for chain: ".concat(params.chain));
|
|
@@ -223,19 +287,19 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
223
287
|
};
|
|
224
288
|
});
|
|
225
289
|
});
|
|
226
|
-
|
|
290
|
+
_context4.next = 12;
|
|
227
291
|
return quoter.batchMultiQuote.staticCall(params.amountInWei, quoteParamsArr, {
|
|
228
292
|
from: this.config.executor
|
|
229
293
|
});
|
|
230
294
|
case 12:
|
|
231
|
-
amountOutListArr =
|
|
295
|
+
amountOutListArr = _context4.sent;
|
|
232
296
|
if (amountOutListArr.length) {
|
|
233
|
-
|
|
297
|
+
_context4.next = 15;
|
|
234
298
|
break;
|
|
235
299
|
}
|
|
236
300
|
throw new Error('No expect result return from smart contract');
|
|
237
301
|
case 15:
|
|
238
|
-
return
|
|
302
|
+
return _context4.abrupt("return", amountOutListArr.map(function (list) {
|
|
239
303
|
if (!list.length) {
|
|
240
304
|
throw new Error('No expect result return from smart contract');
|
|
241
305
|
}
|
|
@@ -243,11 +307,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
243
307
|
}));
|
|
244
308
|
case 16:
|
|
245
309
|
case "end":
|
|
246
|
-
return
|
|
310
|
+
return _context4.stop();
|
|
247
311
|
}
|
|
248
|
-
},
|
|
312
|
+
}, _callee4, this);
|
|
249
313
|
}));
|
|
250
|
-
function batchMultiExpect(
|
|
314
|
+
function batchMultiExpect(_x4) {
|
|
251
315
|
return _batchMultiExpect.apply(this, arguments);
|
|
252
316
|
}
|
|
253
317
|
return batchMultiExpect;
|
|
@@ -255,7 +319,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
255
319
|
}, {
|
|
256
320
|
key: "swap",
|
|
257
321
|
value: function () {
|
|
258
|
-
var _swap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
322
|
+
var _swap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
|
|
259
323
|
var txReq,
|
|
260
324
|
fromTokenAddress,
|
|
261
325
|
toTokenAddress,
|
|
@@ -275,14 +339,14 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
275
339
|
_step,
|
|
276
340
|
log,
|
|
277
341
|
parsed,
|
|
278
|
-
|
|
279
|
-
return _regeneratorRuntime().wrap(function
|
|
280
|
-
while (1) switch (
|
|
342
|
+
_args5 = arguments;
|
|
343
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
344
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
281
345
|
case 0:
|
|
282
|
-
txReq =
|
|
346
|
+
txReq = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
283
347
|
this.validateParams(params);
|
|
284
348
|
if (params.path.length) {
|
|
285
|
-
|
|
349
|
+
_context5.next = 4;
|
|
286
350
|
break;
|
|
287
351
|
}
|
|
288
352
|
throw new Error('Swap path not provided');
|
|
@@ -292,7 +356,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
292
356
|
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
293
357
|
wallet = this.walletMap.get(params.chain);
|
|
294
358
|
if (wallet) {
|
|
295
|
-
|
|
359
|
+
_context5.next = 10;
|
|
296
360
|
break;
|
|
297
361
|
}
|
|
298
362
|
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
@@ -309,87 +373,87 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
309
373
|
};
|
|
310
374
|
});
|
|
311
375
|
_txReq = txReq, _ignore = _txReq.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq, _excluded);
|
|
312
|
-
|
|
313
|
-
|
|
376
|
+
_context5.prev = 13;
|
|
377
|
+
_context5.next = 16;
|
|
314
378
|
return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, estimationOverrides);
|
|
315
379
|
case 16:
|
|
316
|
-
estimateGas =
|
|
317
|
-
|
|
380
|
+
estimateGas = _context5.sent;
|
|
381
|
+
_context5.next = 23;
|
|
318
382
|
break;
|
|
319
383
|
case 19:
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
console.warn('Aggregator estimateGas.swap failed',
|
|
323
|
-
throw
|
|
384
|
+
_context5.prev = 19;
|
|
385
|
+
_context5.t0 = _context5["catch"](13);
|
|
386
|
+
console.warn('Aggregator estimateGas.swap failed', _context5.t0);
|
|
387
|
+
throw _context5.t0;
|
|
324
388
|
case 23:
|
|
325
389
|
txReq = this.resolveGasLimit(txReq, estimateGas);
|
|
326
|
-
|
|
390
|
+
_context5.next = 26;
|
|
327
391
|
return this.resolveNonce(wallet.provider, wallet.address, txReq);
|
|
328
392
|
case 26:
|
|
329
|
-
txReq =
|
|
330
|
-
|
|
393
|
+
txReq = _context5.sent;
|
|
394
|
+
_context5.next = 29;
|
|
331
395
|
return this.resolvePricing(wallet.provider, txReq);
|
|
332
396
|
case 29:
|
|
333
|
-
txReq =
|
|
334
|
-
|
|
397
|
+
txReq = _context5.sent;
|
|
398
|
+
_context5.next = 32;
|
|
335
399
|
return aggregator.swap(params.user, params.amountInWei, swapParams, params.minAmountOutList, txReq);
|
|
336
400
|
case 32:
|
|
337
|
-
txResponse =
|
|
338
|
-
|
|
401
|
+
txResponse = _context5.sent;
|
|
402
|
+
_context5.next = 35;
|
|
339
403
|
return txResponse.wait();
|
|
340
404
|
case 35:
|
|
341
|
-
receipt =
|
|
405
|
+
receipt = _context5.sent;
|
|
342
406
|
iface = new ethers.Interface(AggregatorAbi);
|
|
343
407
|
amountOut = null;
|
|
344
408
|
_iterator = _createForOfIteratorHelper(receipt.logs);
|
|
345
|
-
|
|
409
|
+
_context5.prev = 39;
|
|
346
410
|
_iterator.s();
|
|
347
411
|
case 41:
|
|
348
412
|
if ((_step = _iterator.n()).done) {
|
|
349
|
-
|
|
413
|
+
_context5.next = 55;
|
|
350
414
|
break;
|
|
351
415
|
}
|
|
352
416
|
log = _step.value;
|
|
353
417
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
354
|
-
|
|
418
|
+
_context5.next = 53;
|
|
355
419
|
break;
|
|
356
420
|
}
|
|
357
|
-
|
|
421
|
+
_context5.prev = 44;
|
|
358
422
|
parsed = iface.parseLog(log);
|
|
359
423
|
if (!(parsed && parsed.name === 'Swapped' && parsed.args && parsed.args.amountOut !== undefined)) {
|
|
360
|
-
|
|
424
|
+
_context5.next = 49;
|
|
361
425
|
break;
|
|
362
426
|
}
|
|
363
427
|
amountOut = parsed.args.amountOut;
|
|
364
|
-
return
|
|
428
|
+
return _context5.abrupt("break", 55);
|
|
365
429
|
case 49:
|
|
366
|
-
|
|
430
|
+
_context5.next = 53;
|
|
367
431
|
break;
|
|
368
432
|
case 51:
|
|
369
|
-
|
|
370
|
-
|
|
433
|
+
_context5.prev = 51;
|
|
434
|
+
_context5.t1 = _context5["catch"](44);
|
|
371
435
|
case 53:
|
|
372
|
-
|
|
436
|
+
_context5.next = 41;
|
|
373
437
|
break;
|
|
374
438
|
case 55:
|
|
375
|
-
|
|
439
|
+
_context5.next = 60;
|
|
376
440
|
break;
|
|
377
441
|
case 57:
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
_iterator.e(
|
|
442
|
+
_context5.prev = 57;
|
|
443
|
+
_context5.t2 = _context5["catch"](39);
|
|
444
|
+
_iterator.e(_context5.t2);
|
|
381
445
|
case 60:
|
|
382
|
-
|
|
446
|
+
_context5.prev = 60;
|
|
383
447
|
_iterator.f();
|
|
384
|
-
return
|
|
448
|
+
return _context5.finish(60);
|
|
385
449
|
case 63:
|
|
386
450
|
if (amountOut) {
|
|
387
|
-
|
|
451
|
+
_context5.next = 65;
|
|
388
452
|
break;
|
|
389
453
|
}
|
|
390
454
|
throw new Error("Swapped event not found: ".concat(receipt.hash));
|
|
391
455
|
case 65:
|
|
392
|
-
return
|
|
456
|
+
return _context5.abrupt("return", {
|
|
393
457
|
fromToken: fromTokenAddress,
|
|
394
458
|
toToken: toTokenAddress,
|
|
395
459
|
amountOut: amountOut,
|
|
@@ -399,11 +463,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
399
463
|
});
|
|
400
464
|
case 66:
|
|
401
465
|
case "end":
|
|
402
|
-
return
|
|
466
|
+
return _context5.stop();
|
|
403
467
|
}
|
|
404
|
-
},
|
|
468
|
+
}, _callee5, this, [[13, 19], [39, 57, 60, 63], [44, 51]]);
|
|
405
469
|
}));
|
|
406
|
-
function swap(
|
|
470
|
+
function swap(_x5) {
|
|
407
471
|
return _swap.apply(this, arguments);
|
|
408
472
|
}
|
|
409
473
|
return swap;
|
|
@@ -411,7 +475,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
411
475
|
}, {
|
|
412
476
|
key: "batchMultiSwap",
|
|
413
477
|
value: function () {
|
|
414
|
-
var _batchMultiSwap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
478
|
+
var _batchMultiSwap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
415
479
|
var _receipt$to;
|
|
416
480
|
var txReq,
|
|
417
481
|
provider,
|
|
@@ -433,22 +497,22 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
433
497
|
_step2,
|
|
434
498
|
log,
|
|
435
499
|
parsed,
|
|
436
|
-
|
|
437
|
-
return _regeneratorRuntime().wrap(function
|
|
438
|
-
while (1) switch (
|
|
500
|
+
_args6 = arguments;
|
|
501
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
502
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
439
503
|
case 0:
|
|
440
|
-
txReq =
|
|
504
|
+
txReq = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
|
|
441
505
|
// 最基本的检查
|
|
442
506
|
provider = this.providerMap.get(params.chain);
|
|
443
507
|
wallet = this.walletMap.get(params.chain);
|
|
444
508
|
if (!(!wallet || !provider)) {
|
|
445
|
-
|
|
509
|
+
_context6.next = 5;
|
|
446
510
|
break;
|
|
447
511
|
}
|
|
448
512
|
throw new Error("sdk\u4E0D\u652F\u6301\u7684\u94FE\uFF1A ".concat(params.chain));
|
|
449
513
|
case 5:
|
|
450
514
|
if (!(params.amountInWeis.length !== params.paths.length)) {
|
|
451
|
-
|
|
515
|
+
_context6.next = 7;
|
|
452
516
|
break;
|
|
453
517
|
}
|
|
454
518
|
throw new Error('传入参数数量不正确');
|
|
@@ -468,97 +532,97 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
468
532
|
});
|
|
469
533
|
});
|
|
470
534
|
_txReq2 = txReq, _ignore = _txReq2.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq2, _excluded2);
|
|
471
|
-
|
|
472
|
-
|
|
535
|
+
_context6.prev = 11;
|
|
536
|
+
_context6.next = 14;
|
|
473
537
|
return aggregator.batchMultiSwap.estimateGas(params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists, estimationOverrides);
|
|
474
538
|
case 14:
|
|
475
|
-
estimateGas =
|
|
476
|
-
|
|
539
|
+
estimateGas = _context6.sent;
|
|
540
|
+
_context6.next = 21;
|
|
477
541
|
break;
|
|
478
542
|
case 17:
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
console.warn('Aggregator estimateGas.swap failed',
|
|
482
|
-
throw
|
|
543
|
+
_context6.prev = 17;
|
|
544
|
+
_context6.t0 = _context6["catch"](11);
|
|
545
|
+
console.warn('Aggregator estimateGas.swap failed', _context6.t0);
|
|
546
|
+
throw _context6.t0;
|
|
483
547
|
case 21:
|
|
484
548
|
txReq = this.resolveGasLimit(txReq, estimateGas);
|
|
485
|
-
|
|
549
|
+
_context6.next = 24;
|
|
486
550
|
return this.resolveNonce(wallet.provider, wallet.address, txReq);
|
|
487
551
|
case 24:
|
|
488
|
-
txReq =
|
|
489
|
-
|
|
552
|
+
txReq = _context6.sent;
|
|
553
|
+
_context6.next = 27;
|
|
490
554
|
return this.resolvePricing(wallet.provider, txReq);
|
|
491
555
|
case 27:
|
|
492
|
-
txReq =
|
|
493
|
-
|
|
556
|
+
txReq = _context6.sent;
|
|
557
|
+
_context6.next = 30;
|
|
494
558
|
return aggregator.batchMultiSwap(params.users, params.amountInWeis, swapParamsList, params.minAmountOutLists, estimationOverrides);
|
|
495
559
|
case 30:
|
|
496
|
-
txResponse =
|
|
497
|
-
|
|
560
|
+
txResponse = _context6.sent;
|
|
561
|
+
_context6.next = 33;
|
|
498
562
|
return txResponse.wait();
|
|
499
563
|
case 33:
|
|
500
|
-
receipt =
|
|
564
|
+
receipt = _context6.sent;
|
|
501
565
|
iface = new ethers.Interface(AggregatorAbi);
|
|
502
566
|
userList = null;
|
|
503
567
|
amountInList = null;
|
|
504
568
|
amountOutList = null;
|
|
505
569
|
_iterator2 = _createForOfIteratorHelper(receipt.logs);
|
|
506
|
-
|
|
570
|
+
_context6.prev = 39;
|
|
507
571
|
_iterator2.s();
|
|
508
572
|
case 41:
|
|
509
573
|
if ((_step2 = _iterator2.n()).done) {
|
|
510
|
-
|
|
574
|
+
_context6.next = 57;
|
|
511
575
|
break;
|
|
512
576
|
}
|
|
513
577
|
log = _step2.value;
|
|
514
578
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
515
|
-
|
|
579
|
+
_context6.next = 55;
|
|
516
580
|
break;
|
|
517
581
|
}
|
|
518
|
-
|
|
582
|
+
_context6.prev = 44;
|
|
519
583
|
parsed = iface.parseLog(log);
|
|
520
584
|
if (!(parsed && parsed.name === 'MultiSwapped' && parsed.args)) {
|
|
521
|
-
|
|
585
|
+
_context6.next = 51;
|
|
522
586
|
break;
|
|
523
587
|
}
|
|
524
588
|
userList = parsed.args.userList;
|
|
525
589
|
amountInList = parsed.args.amountInList;
|
|
526
590
|
amountOutList = parsed.args.amountOutList;
|
|
527
|
-
return
|
|
591
|
+
return _context6.abrupt("break", 57);
|
|
528
592
|
case 51:
|
|
529
|
-
|
|
593
|
+
_context6.next = 55;
|
|
530
594
|
break;
|
|
531
595
|
case 53:
|
|
532
|
-
|
|
533
|
-
|
|
596
|
+
_context6.prev = 53;
|
|
597
|
+
_context6.t1 = _context6["catch"](44);
|
|
534
598
|
case 55:
|
|
535
|
-
|
|
599
|
+
_context6.next = 41;
|
|
536
600
|
break;
|
|
537
601
|
case 57:
|
|
538
|
-
|
|
602
|
+
_context6.next = 62;
|
|
539
603
|
break;
|
|
540
604
|
case 59:
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
_iterator2.e(
|
|
605
|
+
_context6.prev = 59;
|
|
606
|
+
_context6.t2 = _context6["catch"](39);
|
|
607
|
+
_iterator2.e(_context6.t2);
|
|
544
608
|
case 62:
|
|
545
|
-
|
|
609
|
+
_context6.prev = 62;
|
|
546
610
|
_iterator2.f();
|
|
547
|
-
return
|
|
611
|
+
return _context6.finish(62);
|
|
548
612
|
case 65:
|
|
549
613
|
if (!(!userList || !amountInList || !amountOutList)) {
|
|
550
|
-
|
|
614
|
+
_context6.next = 67;
|
|
551
615
|
break;
|
|
552
616
|
}
|
|
553
617
|
throw new Error("MultiSwapped event not found: ".concat(receipt.hash));
|
|
554
618
|
case 67:
|
|
555
619
|
if (!(userList.length !== params.users.length || amountOutList.length !== params.users.length)) {
|
|
556
|
-
|
|
620
|
+
_context6.next = 69;
|
|
557
621
|
break;
|
|
558
622
|
}
|
|
559
623
|
throw new Error("MultiSwapped event length mismatch: ".concat(receipt.hash));
|
|
560
624
|
case 69:
|
|
561
|
-
return
|
|
625
|
+
return _context6.abrupt("return", {
|
|
562
626
|
hash: receipt.hash,
|
|
563
627
|
from: receipt.from,
|
|
564
628
|
to: (_receipt$to = receipt.to) !== null && _receipt$to !== void 0 ? _receipt$to : null,
|
|
@@ -578,11 +642,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
578
642
|
});
|
|
579
643
|
case 70:
|
|
580
644
|
case "end":
|
|
581
|
-
return
|
|
645
|
+
return _context6.stop();
|
|
582
646
|
}
|
|
583
|
-
},
|
|
647
|
+
}, _callee6, this, [[11, 17], [39, 59, 62, 65], [44, 53]]);
|
|
584
648
|
}));
|
|
585
|
-
function batchMultiSwap(
|
|
649
|
+
function batchMultiSwap(_x6) {
|
|
586
650
|
return _batchMultiSwap.apply(this, arguments);
|
|
587
651
|
}
|
|
588
652
|
return batchMultiSwap;
|
|
@@ -590,7 +654,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
590
654
|
}, {
|
|
591
655
|
key: "swapByFlashbots",
|
|
592
656
|
value: function () {
|
|
593
|
-
var _swapByFlashbots = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
657
|
+
var _swapByFlashbots = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
|
|
594
658
|
var txReq,
|
|
595
659
|
_targetBlockNumber,
|
|
596
660
|
provider,
|
|
@@ -609,20 +673,26 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
609
673
|
txHashes,
|
|
610
674
|
targetBlock,
|
|
611
675
|
resultPromise,
|
|
612
|
-
|
|
613
|
-
return _regeneratorRuntime().wrap(function
|
|
614
|
-
while (1) switch (
|
|
676
|
+
_args8 = arguments;
|
|
677
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
678
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
615
679
|
case 0:
|
|
616
|
-
txReq =
|
|
617
|
-
_targetBlockNumber =
|
|
680
|
+
txReq = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
|
|
681
|
+
_targetBlockNumber = _args8.length > 2 ? _args8[2] : undefined;
|
|
682
|
+
if (this.flashbotSigner) {
|
|
683
|
+
_context8.next = 4;
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
throw new Error('flashbot signer未初始化');
|
|
687
|
+
case 4:
|
|
618
688
|
provider = this.providerMap.get(params.chain);
|
|
619
689
|
wallet = this.walletMap.get(params.chain);
|
|
620
690
|
if (!(!wallet || !provider)) {
|
|
621
|
-
|
|
691
|
+
_context8.next = 8;
|
|
622
692
|
break;
|
|
623
693
|
}
|
|
624
694
|
throw new Error("sdk\u4E0D\u652F\u6301\u7684\u94FE\uFF1A ".concat(params.chain));
|
|
625
|
-
case
|
|
695
|
+
case 8:
|
|
626
696
|
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
627
697
|
aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
|
|
628
698
|
swapParams = params.path.map(function (pathItem) {
|
|
@@ -636,28 +706,28 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
636
706
|
};
|
|
637
707
|
});
|
|
638
708
|
_txReq3 = txReq, _ignore = _txReq3.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq3, _excluded3);
|
|
639
|
-
|
|
640
|
-
|
|
709
|
+
_context8.prev = 12;
|
|
710
|
+
_context8.next = 15;
|
|
641
711
|
return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, estimationOverrides);
|
|
642
|
-
case
|
|
643
|
-
estimateGas =
|
|
644
|
-
|
|
712
|
+
case 15:
|
|
713
|
+
estimateGas = _context8.sent;
|
|
714
|
+
_context8.next = 22;
|
|
645
715
|
break;
|
|
646
|
-
case
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
console.warn('Aggregator estimateGas.swap failed',
|
|
650
|
-
throw
|
|
651
|
-
case
|
|
716
|
+
case 18:
|
|
717
|
+
_context8.prev = 18;
|
|
718
|
+
_context8.t0 = _context8["catch"](12);
|
|
719
|
+
console.warn('Aggregator estimateGas.swap failed', _context8.t0);
|
|
720
|
+
throw _context8.t0;
|
|
721
|
+
case 22:
|
|
652
722
|
txReq = this.resolveGasLimit(txReq, estimateGas);
|
|
653
|
-
|
|
723
|
+
_context8.next = 25;
|
|
654
724
|
return this.resolveNonce(wallet.provider, wallet.address, txReq);
|
|
655
|
-
case
|
|
656
|
-
txReq =
|
|
657
|
-
|
|
725
|
+
case 25:
|
|
726
|
+
txReq = _context8.sent;
|
|
727
|
+
_context8.next = 28;
|
|
658
728
|
return this.resolvePricing(wallet.provider, txReq);
|
|
659
|
-
case
|
|
660
|
-
txReq =
|
|
729
|
+
case 28:
|
|
730
|
+
txReq = _context8.sent;
|
|
661
731
|
this.validateParams(params);
|
|
662
732
|
swapCallData = this.genSwapCalldata(params);
|
|
663
733
|
baseTx = {
|
|
@@ -671,10 +741,10 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
671
741
|
data: swapCallData.data,
|
|
672
742
|
gasLimit: txReq.gasLimit
|
|
673
743
|
};
|
|
674
|
-
|
|
744
|
+
_context8.next = 34;
|
|
675
745
|
return wallet.signTransaction(baseTx);
|
|
676
|
-
case
|
|
677
|
-
signTx =
|
|
746
|
+
case 34:
|
|
747
|
+
signTx = _context8.sent;
|
|
678
748
|
rawTxs = [signTx];
|
|
679
749
|
txHashes = rawTxs.map(function (tx) {
|
|
680
750
|
return ethers.keccak256(tx);
|
|
@@ -683,96 +753,96 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
683
753
|
console.log("Transaction ".concat(i + 1, ": ").concat(hash));
|
|
684
754
|
});
|
|
685
755
|
if (!_targetBlockNumber) {
|
|
686
|
-
|
|
756
|
+
_context8.next = 42;
|
|
687
757
|
break;
|
|
688
758
|
}
|
|
689
759
|
targetBlock = _targetBlockNumber;
|
|
690
|
-
|
|
760
|
+
_context8.next = 46;
|
|
691
761
|
break;
|
|
692
|
-
case 40:
|
|
693
|
-
_context7.next = 42;
|
|
694
|
-
return provider.getBlockNumber();
|
|
695
762
|
case 42:
|
|
696
|
-
|
|
697
|
-
|
|
763
|
+
_context8.next = 44;
|
|
764
|
+
return provider.getBlockNumber();
|
|
698
765
|
case 44:
|
|
766
|
+
_context8.t1 = _context8.sent;
|
|
767
|
+
targetBlock = _context8.t1 + 1;
|
|
768
|
+
case 46:
|
|
699
769
|
// 注册检查是否上链
|
|
700
770
|
resultPromise = new Promise(function (resolve) {
|
|
701
771
|
var onBlock = /*#__PURE__*/function () {
|
|
702
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
772
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(blockNumber) {
|
|
703
773
|
var _receipts$find;
|
|
704
774
|
var receipts, receipt, fromTokenAddress, toTokenAddress, iface, amountOut, _iterator3, _step3, log, parsed;
|
|
705
|
-
return _regeneratorRuntime().wrap(function
|
|
706
|
-
while (1) switch (
|
|
775
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
776
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
707
777
|
case 0:
|
|
708
778
|
if (!(blockNumber < targetBlock)) {
|
|
709
|
-
|
|
779
|
+
_context7.next = 2;
|
|
710
780
|
break;
|
|
711
781
|
}
|
|
712
|
-
return
|
|
782
|
+
return _context7.abrupt("return");
|
|
713
783
|
case 2:
|
|
714
784
|
provider.off('block', onBlock);
|
|
715
|
-
|
|
785
|
+
_context7.next = 5;
|
|
716
786
|
return Promise.all(txHashes.map(function (hash) {
|
|
717
787
|
return provider.getTransactionReceipt(hash);
|
|
718
788
|
}));
|
|
719
789
|
case 5:
|
|
720
|
-
receipts =
|
|
790
|
+
receipts = _context7.sent;
|
|
721
791
|
receipt = (_receipts$find = receipts.find(function (r) {
|
|
722
792
|
return r && r.blockNumber === targetBlock;
|
|
723
793
|
})) !== null && _receipts$find !== void 0 ? _receipts$find : null;
|
|
724
794
|
if (receipt) {
|
|
725
|
-
|
|
795
|
+
_context7.next = 10;
|
|
726
796
|
break;
|
|
727
797
|
}
|
|
728
798
|
resolve(null);
|
|
729
|
-
return
|
|
799
|
+
return _context7.abrupt("return");
|
|
730
800
|
case 10:
|
|
731
801
|
fromTokenAddress = params.path[0].fromCoinAddress;
|
|
732
802
|
toTokenAddress = params.path[params.path.length - 1].toCoinAddress;
|
|
733
803
|
iface = new ethers.Interface(AggregatorAbi);
|
|
734
804
|
amountOut = null;
|
|
735
805
|
_iterator3 = _createForOfIteratorHelper(receipt.logs);
|
|
736
|
-
|
|
806
|
+
_context7.prev = 15;
|
|
737
807
|
_iterator3.s();
|
|
738
808
|
case 17:
|
|
739
809
|
if ((_step3 = _iterator3.n()).done) {
|
|
740
|
-
|
|
810
|
+
_context7.next = 31;
|
|
741
811
|
break;
|
|
742
812
|
}
|
|
743
813
|
log = _step3.value;
|
|
744
814
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
745
|
-
|
|
815
|
+
_context7.next = 29;
|
|
746
816
|
break;
|
|
747
817
|
}
|
|
748
|
-
|
|
818
|
+
_context7.prev = 20;
|
|
749
819
|
parsed = iface.parseLog(log);
|
|
750
820
|
if (!(parsed && parsed.name === 'Swapped' && parsed.args && parsed.args.amountOut !== undefined)) {
|
|
751
|
-
|
|
821
|
+
_context7.next = 25;
|
|
752
822
|
break;
|
|
753
823
|
}
|
|
754
824
|
amountOut = parsed.args.amountOut;
|
|
755
|
-
return
|
|
825
|
+
return _context7.abrupt("break", 31);
|
|
756
826
|
case 25:
|
|
757
|
-
|
|
827
|
+
_context7.next = 29;
|
|
758
828
|
break;
|
|
759
829
|
case 27:
|
|
760
|
-
|
|
761
|
-
|
|
830
|
+
_context7.prev = 27;
|
|
831
|
+
_context7.t0 = _context7["catch"](20);
|
|
762
832
|
case 29:
|
|
763
|
-
|
|
833
|
+
_context7.next = 17;
|
|
764
834
|
break;
|
|
765
835
|
case 31:
|
|
766
|
-
|
|
836
|
+
_context7.next = 36;
|
|
767
837
|
break;
|
|
768
838
|
case 33:
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
_iterator3.e(
|
|
839
|
+
_context7.prev = 33;
|
|
840
|
+
_context7.t1 = _context7["catch"](15);
|
|
841
|
+
_iterator3.e(_context7.t1);
|
|
772
842
|
case 36:
|
|
773
|
-
|
|
843
|
+
_context7.prev = 36;
|
|
774
844
|
_iterator3.f();
|
|
775
|
-
return
|
|
845
|
+
return _context7.finish(36);
|
|
776
846
|
case 39:
|
|
777
847
|
resolve({
|
|
778
848
|
fromToken: fromTokenAddress,
|
|
@@ -784,27 +854,27 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
784
854
|
});
|
|
785
855
|
case 40:
|
|
786
856
|
case "end":
|
|
787
|
-
return
|
|
857
|
+
return _context7.stop();
|
|
788
858
|
}
|
|
789
|
-
},
|
|
859
|
+
}, _callee7, null, [[15, 33, 36, 39], [20, 27]]);
|
|
790
860
|
}));
|
|
791
|
-
return function onBlock(
|
|
861
|
+
return function onBlock(_x8) {
|
|
792
862
|
return _ref.apply(this, arguments);
|
|
793
863
|
};
|
|
794
864
|
}();
|
|
795
865
|
provider.on('block', onBlock);
|
|
796
866
|
});
|
|
797
|
-
|
|
867
|
+
_context8.next = 49;
|
|
798
868
|
return this.sendBundle(rawTxs, targetBlock, this.flashbotSigner);
|
|
799
|
-
case
|
|
800
|
-
return
|
|
801
|
-
case
|
|
869
|
+
case 49:
|
|
870
|
+
return _context8.abrupt("return", resultPromise);
|
|
871
|
+
case 50:
|
|
802
872
|
case "end":
|
|
803
|
-
return
|
|
873
|
+
return _context8.stop();
|
|
804
874
|
}
|
|
805
|
-
},
|
|
875
|
+
}, _callee8, this, [[12, 18]]);
|
|
806
876
|
}));
|
|
807
|
-
function swapByFlashbots(
|
|
877
|
+
function swapByFlashbots(_x7) {
|
|
808
878
|
return _swapByFlashbots.apply(this, arguments);
|
|
809
879
|
}
|
|
810
880
|
return swapByFlashbots;
|
|
@@ -875,7 +945,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
875
945
|
}, {
|
|
876
946
|
key: "bridge",
|
|
877
947
|
value: function () {
|
|
878
|
-
var _bridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
948
|
+
var _bridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
|
|
879
949
|
var _params$extra2;
|
|
880
950
|
var txReq,
|
|
881
951
|
aggregatorAddress,
|
|
@@ -890,46 +960,46 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
890
960
|
estimationOverrides,
|
|
891
961
|
response,
|
|
892
962
|
txReceipt,
|
|
893
|
-
|
|
894
|
-
return _regeneratorRuntime().wrap(function
|
|
895
|
-
while (1) switch (
|
|
963
|
+
_args9 = arguments;
|
|
964
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
965
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
896
966
|
case 0:
|
|
897
|
-
txReq =
|
|
967
|
+
txReq = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {};
|
|
898
968
|
this.validateParams(params);
|
|
899
969
|
|
|
900
970
|
// set up
|
|
901
971
|
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
902
972
|
wallet = this.walletMap.get(params.chain);
|
|
903
973
|
if (wallet) {
|
|
904
|
-
|
|
974
|
+
_context9.next = 6;
|
|
905
975
|
break;
|
|
906
976
|
}
|
|
907
977
|
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
908
978
|
case 6:
|
|
909
979
|
if (!(params.tokenAddress && params.tokenAddress !== ethers.ZeroAddress)) {
|
|
910
|
-
|
|
980
|
+
_context9.next = 9;
|
|
911
981
|
break;
|
|
912
982
|
}
|
|
913
|
-
|
|
983
|
+
_context9.next = 9;
|
|
914
984
|
return this.checkIsEnoughToken(params.tokenAddress, params.user, params.amountInWei, aggregatorAddress, wallet);
|
|
915
985
|
case 9:
|
|
916
986
|
if (!(params.bridgeFee > 0n)) {
|
|
917
|
-
|
|
987
|
+
_context9.next = 18;
|
|
918
988
|
break;
|
|
919
989
|
}
|
|
920
990
|
provider = this.providerMap.get(params.chain);
|
|
921
991
|
if (provider) {
|
|
922
|
-
|
|
992
|
+
_context9.next = 13;
|
|
923
993
|
break;
|
|
924
994
|
}
|
|
925
995
|
throw new Error("Provider not configured for chain: ".concat(params.chain));
|
|
926
996
|
case 13:
|
|
927
|
-
|
|
997
|
+
_context9.next = 15;
|
|
928
998
|
return provider.getBalance(params.user);
|
|
929
999
|
case 15:
|
|
930
|
-
nativeBalance =
|
|
1000
|
+
nativeBalance = _context9.sent;
|
|
931
1001
|
if (!(nativeBalance < params.bridgeFee)) {
|
|
932
|
-
|
|
1002
|
+
_context9.next = 18;
|
|
933
1003
|
break;
|
|
934
1004
|
}
|
|
935
1005
|
throw new Error('Insufficient native balance for bridge fee');
|
|
@@ -952,38 +1022,38 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
952
1022
|
|
|
953
1023
|
// simulate
|
|
954
1024
|
_txReq4 = txReq, _ignore = _txReq4.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq4, _excluded4);
|
|
955
|
-
|
|
956
|
-
|
|
1025
|
+
_context9.prev = 22;
|
|
1026
|
+
_context9.next = 25;
|
|
957
1027
|
return aggregator.bridge.estimateGas(params.user, bridgeArgs, estimationOverrides);
|
|
958
1028
|
case 25:
|
|
959
|
-
estimateGas =
|
|
960
|
-
|
|
1029
|
+
estimateGas = _context9.sent;
|
|
1030
|
+
_context9.next = 32;
|
|
961
1031
|
break;
|
|
962
1032
|
case 28:
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
console.error('Bridge gas estimation reverted',
|
|
966
|
-
throw
|
|
1033
|
+
_context9.prev = 28;
|
|
1034
|
+
_context9.t0 = _context9["catch"](22);
|
|
1035
|
+
console.error('Bridge gas estimation reverted', _context9.t0);
|
|
1036
|
+
throw _context9.t0;
|
|
967
1037
|
case 32:
|
|
968
1038
|
// 构造tx req
|
|
969
1039
|
txReq = this.resolveGasLimit(txReq, estimateGas);
|
|
970
|
-
|
|
1040
|
+
_context9.next = 35;
|
|
971
1041
|
return this.resolveNonce(wallet.provider, wallet.address, txReq);
|
|
972
1042
|
case 35:
|
|
973
|
-
txReq =
|
|
974
|
-
|
|
1043
|
+
txReq = _context9.sent;
|
|
1044
|
+
_context9.next = 38;
|
|
975
1045
|
return this.resolvePricing(wallet.provider, txReq);
|
|
976
1046
|
case 38:
|
|
977
|
-
txReq =
|
|
978
|
-
|
|
1047
|
+
txReq = _context9.sent;
|
|
1048
|
+
_context9.next = 41;
|
|
979
1049
|
return aggregator.bridge(params.user, bridgeArgs, txReq);
|
|
980
1050
|
case 41:
|
|
981
|
-
response =
|
|
982
|
-
|
|
1051
|
+
response = _context9.sent;
|
|
1052
|
+
_context9.next = 44;
|
|
983
1053
|
return response.wait();
|
|
984
1054
|
case 44:
|
|
985
|
-
txReceipt =
|
|
986
|
-
return
|
|
1055
|
+
txReceipt = _context9.sent;
|
|
1056
|
+
return _context9.abrupt("return", {
|
|
987
1057
|
fromToken: params.tokenAddress,
|
|
988
1058
|
toToken: params.tokenAddress,
|
|
989
1059
|
amountOut: params.amountInWei,
|
|
@@ -993,11 +1063,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
993
1063
|
});
|
|
994
1064
|
case 46:
|
|
995
1065
|
case "end":
|
|
996
|
-
return
|
|
1066
|
+
return _context9.stop();
|
|
997
1067
|
}
|
|
998
|
-
},
|
|
1068
|
+
}, _callee9, this, [[22, 28]]);
|
|
999
1069
|
}));
|
|
1000
|
-
function bridge(
|
|
1070
|
+
function bridge(_x9) {
|
|
1001
1071
|
return _bridge.apply(this, arguments);
|
|
1002
1072
|
}
|
|
1003
1073
|
return bridge;
|
|
@@ -1005,23 +1075,23 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1005
1075
|
}, {
|
|
1006
1076
|
key: "estimateBridgeFee",
|
|
1007
1077
|
value: function () {
|
|
1008
|
-
var _estimateBridgeFee = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1078
|
+
var _estimateBridgeFee = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
1009
1079
|
var _params$extra3;
|
|
1010
1080
|
var wallet, address, quoter, bridgeArgs, bridgeFee;
|
|
1011
|
-
return _regeneratorRuntime().wrap(function
|
|
1012
|
-
while (1) switch (
|
|
1081
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1082
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1013
1083
|
case 0:
|
|
1014
1084
|
this.validateParams(params);
|
|
1015
1085
|
wallet = this.walletMap.get(params.chain);
|
|
1016
1086
|
if (wallet) {
|
|
1017
|
-
|
|
1087
|
+
_context10.next = 4;
|
|
1018
1088
|
break;
|
|
1019
1089
|
}
|
|
1020
1090
|
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
1021
1091
|
case 4:
|
|
1022
1092
|
address = this.getQuoterAddress(params.chain);
|
|
1023
1093
|
if (address) {
|
|
1024
|
-
|
|
1094
|
+
_context10.next = 7;
|
|
1025
1095
|
break;
|
|
1026
1096
|
}
|
|
1027
1097
|
throw new Error("Quoter address not found for chain: ".concat(params.chain));
|
|
@@ -1036,20 +1106,20 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1036
1106
|
destUser: params.destUser,
|
|
1037
1107
|
extra: (_params$extra3 = params.extra) !== null && _params$extra3 !== void 0 ? _params$extra3 : '0x'
|
|
1038
1108
|
};
|
|
1039
|
-
|
|
1109
|
+
_context10.next = 11;
|
|
1040
1110
|
return quoter.quoteBridge.staticCall(bridgeArgs, {
|
|
1041
1111
|
from: wallet.address
|
|
1042
1112
|
});
|
|
1043
1113
|
case 11:
|
|
1044
|
-
bridgeFee =
|
|
1045
|
-
return
|
|
1114
|
+
bridgeFee = _context10.sent;
|
|
1115
|
+
return _context10.abrupt("return", bridgeFee);
|
|
1046
1116
|
case 13:
|
|
1047
1117
|
case "end":
|
|
1048
|
-
return
|
|
1118
|
+
return _context10.stop();
|
|
1049
1119
|
}
|
|
1050
|
-
},
|
|
1120
|
+
}, _callee10, this);
|
|
1051
1121
|
}));
|
|
1052
|
-
function estimateBridgeFee(
|
|
1122
|
+
function estimateBridgeFee(_x10) {
|
|
1053
1123
|
return _estimateBridgeFee.apply(this, arguments);
|
|
1054
1124
|
}
|
|
1055
1125
|
return estimateBridgeFee;
|
|
@@ -1057,7 +1127,7 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1057
1127
|
}, {
|
|
1058
1128
|
key: "swapAndBridge",
|
|
1059
1129
|
value: function () {
|
|
1060
|
-
var _swapAndBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1130
|
+
var _swapAndBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
|
|
1061
1131
|
var _params$extra4;
|
|
1062
1132
|
var txReq,
|
|
1063
1133
|
aggregatorAddress,
|
|
@@ -1077,18 +1147,18 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1077
1147
|
_step4,
|
|
1078
1148
|
log,
|
|
1079
1149
|
parsed,
|
|
1080
|
-
|
|
1081
|
-
return _regeneratorRuntime().wrap(function
|
|
1082
|
-
while (1) switch (
|
|
1150
|
+
_args11 = arguments;
|
|
1151
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1152
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1083
1153
|
case 0:
|
|
1084
|
-
txReq =
|
|
1154
|
+
txReq = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : {};
|
|
1085
1155
|
this.validateParams(params);
|
|
1086
1156
|
|
|
1087
1157
|
// call the aggregator swap and bridge
|
|
1088
1158
|
aggregatorAddress = this.getAggregatorAddress(params.chain);
|
|
1089
1159
|
wallet = this.walletMap.get(params.chain);
|
|
1090
1160
|
if (wallet) {
|
|
1091
|
-
|
|
1161
|
+
_context11.next = 6;
|
|
1092
1162
|
break;
|
|
1093
1163
|
}
|
|
1094
1164
|
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
@@ -1120,79 +1190,79 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1120
1190
|
}
|
|
1121
1191
|
_txReq5 = txReq, _ignore = _txReq5.gasLimit, estimationOverrides = _objectWithoutProperties(_txReq5, _excluded5);
|
|
1122
1192
|
aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
|
|
1123
|
-
|
|
1193
|
+
_context11.next = 13;
|
|
1124
1194
|
return aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, estimationOverrides);
|
|
1125
1195
|
case 13:
|
|
1126
|
-
estimateGas =
|
|
1196
|
+
estimateGas = _context11.sent;
|
|
1127
1197
|
txReq = this.resolveGasLimit(txReq, estimateGas);
|
|
1128
|
-
|
|
1198
|
+
_context11.next = 17;
|
|
1129
1199
|
return this.resolveNonce(wallet.provider, wallet.address, txReq);
|
|
1130
1200
|
case 17:
|
|
1131
|
-
txReq =
|
|
1132
|
-
|
|
1201
|
+
txReq = _context11.sent;
|
|
1202
|
+
_context11.next = 20;
|
|
1133
1203
|
return this.resolvePricing(wallet.provider, txReq);
|
|
1134
1204
|
case 20:
|
|
1135
|
-
txReq =
|
|
1136
|
-
|
|
1205
|
+
txReq = _context11.sent;
|
|
1206
|
+
_context11.next = 23;
|
|
1137
1207
|
return aggregator.swapAndBridge(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txReq);
|
|
1138
1208
|
case 23:
|
|
1139
|
-
response =
|
|
1140
|
-
|
|
1209
|
+
response = _context11.sent;
|
|
1210
|
+
_context11.next = 26;
|
|
1141
1211
|
return response.wait();
|
|
1142
1212
|
case 26:
|
|
1143
|
-
txReceipt =
|
|
1213
|
+
txReceipt = _context11.sent;
|
|
1144
1214
|
// 解析 SwapAndBridge 事件
|
|
1145
1215
|
iface = new ethers.Interface(AggregatorAbi);
|
|
1146
1216
|
outputAmountWei = null;
|
|
1147
1217
|
_iterator4 = _createForOfIteratorHelper(txReceipt.logs);
|
|
1148
|
-
|
|
1218
|
+
_context11.prev = 30;
|
|
1149
1219
|
_iterator4.s();
|
|
1150
1220
|
case 32:
|
|
1151
1221
|
if ((_step4 = _iterator4.n()).done) {
|
|
1152
|
-
|
|
1222
|
+
_context11.next = 46;
|
|
1153
1223
|
break;
|
|
1154
1224
|
}
|
|
1155
1225
|
log = _step4.value;
|
|
1156
1226
|
if (!(log.address.toLowerCase() === aggregatorAddress.toLowerCase())) {
|
|
1157
|
-
|
|
1227
|
+
_context11.next = 44;
|
|
1158
1228
|
break;
|
|
1159
1229
|
}
|
|
1160
|
-
|
|
1230
|
+
_context11.prev = 35;
|
|
1161
1231
|
parsed = iface.parseLog(log);
|
|
1162
1232
|
if (!(parsed && parsed.name === 'SwapAndBridge' && parsed.args && parsed.args.amountOut !== undefined)) {
|
|
1163
|
-
|
|
1233
|
+
_context11.next = 40;
|
|
1164
1234
|
break;
|
|
1165
1235
|
}
|
|
1166
1236
|
outputAmountWei = parsed.args.amountOut;
|
|
1167
|
-
return
|
|
1237
|
+
return _context11.abrupt("break", 46);
|
|
1168
1238
|
case 40:
|
|
1169
|
-
|
|
1239
|
+
_context11.next = 44;
|
|
1170
1240
|
break;
|
|
1171
1241
|
case 42:
|
|
1172
|
-
|
|
1173
|
-
|
|
1242
|
+
_context11.prev = 42;
|
|
1243
|
+
_context11.t0 = _context11["catch"](35);
|
|
1174
1244
|
case 44:
|
|
1175
|
-
|
|
1245
|
+
_context11.next = 32;
|
|
1176
1246
|
break;
|
|
1177
1247
|
case 46:
|
|
1178
|
-
|
|
1248
|
+
_context11.next = 51;
|
|
1179
1249
|
break;
|
|
1180
1250
|
case 48:
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
_iterator4.e(
|
|
1251
|
+
_context11.prev = 48;
|
|
1252
|
+
_context11.t1 = _context11["catch"](30);
|
|
1253
|
+
_iterator4.e(_context11.t1);
|
|
1184
1254
|
case 51:
|
|
1185
|
-
|
|
1255
|
+
_context11.prev = 51;
|
|
1186
1256
|
_iterator4.f();
|
|
1187
|
-
return
|
|
1257
|
+
return _context11.finish(51);
|
|
1188
1258
|
case 54:
|
|
1189
1259
|
if (outputAmountWei) {
|
|
1190
|
-
|
|
1260
|
+
_context11.next = 56;
|
|
1191
1261
|
break;
|
|
1192
1262
|
}
|
|
1193
1263
|
throw new Error("SwapAndBridge event not found: ".concat(txReceipt.hash));
|
|
1194
1264
|
case 56:
|
|
1195
|
-
return
|
|
1265
|
+
return _context11.abrupt("return", {
|
|
1196
1266
|
fromToken: params.path[0].fromCoinAddress,
|
|
1197
1267
|
toToken: params.path[params.path.length - 1].toCoinAddress,
|
|
1198
1268
|
amountOut: outputAmountWei,
|
|
@@ -1202,11 +1272,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1202
1272
|
});
|
|
1203
1273
|
case 57:
|
|
1204
1274
|
case "end":
|
|
1205
|
-
return
|
|
1275
|
+
return _context11.stop();
|
|
1206
1276
|
}
|
|
1207
|
-
},
|
|
1277
|
+
}, _callee11, this, [[30, 48, 51, 54], [35, 42]]);
|
|
1208
1278
|
}));
|
|
1209
|
-
function swapAndBridge(
|
|
1279
|
+
function swapAndBridge(_x11) {
|
|
1210
1280
|
return _swapAndBridge.apply(this, arguments);
|
|
1211
1281
|
}
|
|
1212
1282
|
return swapAndBridge;
|
|
@@ -1214,11 +1284,11 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1214
1284
|
}, {
|
|
1215
1285
|
key: "estimateGas",
|
|
1216
1286
|
value: function () {
|
|
1217
|
-
var _estimateGas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1287
|
+
var _estimateGas = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(estimateType, params) {
|
|
1218
1288
|
var _params$extra5, _swapAndBridgeParams$;
|
|
1219
1289
|
var aggregatorAddress, wallet, aggregator, bridgeArgs1, txOverrides1, gasInBridge, swapParams1, swapGas, swapAndBridgeParams, swapParams, bridgeArgs, txOverrides, gas;
|
|
1220
|
-
return _regeneratorRuntime().wrap(function
|
|
1221
|
-
while (1) switch (
|
|
1290
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1291
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1222
1292
|
case 0:
|
|
1223
1293
|
this.validateParams(params);
|
|
1224
1294
|
|
|
@@ -1227,17 +1297,17 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1227
1297
|
wallet = this.walletMap.get(params.chain);
|
|
1228
1298
|
aggregator = new Contract(aggregatorAddress, AggregatorAbi, wallet);
|
|
1229
1299
|
if (wallet) {
|
|
1230
|
-
|
|
1300
|
+
_context12.next = 6;
|
|
1231
1301
|
break;
|
|
1232
1302
|
}
|
|
1233
1303
|
throw new Error("Wallet not configured for chain: ".concat(params.chain));
|
|
1234
1304
|
case 6:
|
|
1235
|
-
|
|
1236
|
-
|
|
1305
|
+
_context12.t0 = estimateType;
|
|
1306
|
+
_context12.next = _context12.t0 === IEstimateType.BRIDGE ? 9 : _context12.t0 === IEstimateType.SWAP ? 17 : _context12.t0 === IEstimateType.SWAPANDBRIDGE ? 26 : 36;
|
|
1237
1307
|
break;
|
|
1238
1308
|
case 9:
|
|
1239
1309
|
if (!(!('bridgeType' in params) || !('destChain' in params))) {
|
|
1240
|
-
|
|
1310
|
+
_context12.next = 11;
|
|
1241
1311
|
break;
|
|
1242
1312
|
}
|
|
1243
1313
|
throw new Error('bridge params required');
|
|
@@ -1255,20 +1325,20 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1255
1325
|
from: wallet.address,
|
|
1256
1326
|
value: params.bridgeFee
|
|
1257
1327
|
};
|
|
1258
|
-
|
|
1328
|
+
_context12.next = 15;
|
|
1259
1329
|
return aggregator.bridge.estimateGas(params.user, bridgeArgs1, txOverrides1);
|
|
1260
1330
|
case 15:
|
|
1261
|
-
gasInBridge =
|
|
1262
|
-
return
|
|
1331
|
+
gasInBridge = _context12.sent;
|
|
1332
|
+
return _context12.abrupt("return", gasInBridge);
|
|
1263
1333
|
case 17:
|
|
1264
1334
|
if (!(!('path' in params) || !Array.isArray(params.path) || params.path.length === 0)) {
|
|
1265
|
-
|
|
1335
|
+
_context12.next = 19;
|
|
1266
1336
|
break;
|
|
1267
1337
|
}
|
|
1268
1338
|
throw new Error('Swap path required for gas estimation');
|
|
1269
1339
|
case 19:
|
|
1270
1340
|
if (!(!('minAmountOutList' in params) || params.minAmountOutList.length === 0)) {
|
|
1271
|
-
|
|
1341
|
+
_context12.next = 21;
|
|
1272
1342
|
break;
|
|
1273
1343
|
}
|
|
1274
1344
|
throw new Error('minAmountOutList required for gas estimation');
|
|
@@ -1283,16 +1353,16 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1283
1353
|
extra: (_pathItem$extra6 = pathItem.extra) !== null && _pathItem$extra6 !== void 0 ? _pathItem$extra6 : '0x'
|
|
1284
1354
|
};
|
|
1285
1355
|
});
|
|
1286
|
-
|
|
1356
|
+
_context12.next = 24;
|
|
1287
1357
|
return aggregator.swap.estimateGas(params.user, params.amountInWei, swapParams1, params.minAmountOutList, {
|
|
1288
1358
|
from: wallet.address
|
|
1289
1359
|
});
|
|
1290
1360
|
case 24:
|
|
1291
|
-
swapGas =
|
|
1292
|
-
return
|
|
1361
|
+
swapGas = _context12.sent;
|
|
1362
|
+
return _context12.abrupt("return", swapGas);
|
|
1293
1363
|
case 26:
|
|
1294
1364
|
if (!(!('path' in params) || !('bridgeType' in params))) {
|
|
1295
|
-
|
|
1365
|
+
_context12.next = 28;
|
|
1296
1366
|
break;
|
|
1297
1367
|
}
|
|
1298
1368
|
throw new Error('swapAndBridge params required');
|
|
@@ -1321,20 +1391,20 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1321
1391
|
from: wallet.address,
|
|
1322
1392
|
value: swapAndBridgeParams.bridgeFee
|
|
1323
1393
|
};
|
|
1324
|
-
|
|
1394
|
+
_context12.next = 34;
|
|
1325
1395
|
return aggregator.swapAndBridge.estimateGas(params.user, params.amountInWei, swapParams, params.minAmountOutList, bridgeArgs, txOverrides);
|
|
1326
1396
|
case 34:
|
|
1327
|
-
gas =
|
|
1328
|
-
return
|
|
1397
|
+
gas = _context12.sent;
|
|
1398
|
+
return _context12.abrupt("return", gas);
|
|
1329
1399
|
case 36:
|
|
1330
1400
|
throw 'Not support method in sdk';
|
|
1331
1401
|
case 37:
|
|
1332
1402
|
case "end":
|
|
1333
|
-
return
|
|
1403
|
+
return _context12.stop();
|
|
1334
1404
|
}
|
|
1335
|
-
},
|
|
1405
|
+
}, _callee12, this);
|
|
1336
1406
|
}));
|
|
1337
|
-
function estimateGas(
|
|
1407
|
+
function estimateGas(_x12, _x13) {
|
|
1338
1408
|
return _estimateGas.apply(this, arguments);
|
|
1339
1409
|
}
|
|
1340
1410
|
return estimateGas;
|
|
@@ -1342,68 +1412,68 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1342
1412
|
}, {
|
|
1343
1413
|
key: "getAggregatorSupportContracts",
|
|
1344
1414
|
value: function () {
|
|
1345
|
-
var _getAggregatorSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1415
|
+
var _getAggregatorSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(chain) {
|
|
1346
1416
|
var aggregatorAddress, provider, aggregator, addressList, supportContracts;
|
|
1347
|
-
return _regeneratorRuntime().wrap(function
|
|
1348
|
-
while (1) switch (
|
|
1417
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1418
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1349
1419
|
case 0:
|
|
1350
1420
|
// 返回传入链支持的dex和桥
|
|
1351
1421
|
// 返回dex type数组
|
|
1352
1422
|
aggregatorAddress = this.getAggregatorAddress(chain);
|
|
1353
1423
|
provider = this.providerMap.get(chain);
|
|
1354
1424
|
if (provider) {
|
|
1355
|
-
|
|
1425
|
+
_context14.next = 4;
|
|
1356
1426
|
break;
|
|
1357
1427
|
}
|
|
1358
1428
|
throw new Error("Provider not configured for chain: ".concat(chain));
|
|
1359
1429
|
case 4:
|
|
1360
1430
|
aggregator = new Contract(aggregatorAddress, AggregatorAbi, provider);
|
|
1361
|
-
|
|
1431
|
+
_context14.next = 7;
|
|
1362
1432
|
return aggregator.getAddressList();
|
|
1363
1433
|
case 7:
|
|
1364
|
-
addressList =
|
|
1434
|
+
addressList = _context14.sent;
|
|
1365
1435
|
if (addressList.length) {
|
|
1366
|
-
|
|
1436
|
+
_context14.next = 10;
|
|
1367
1437
|
break;
|
|
1368
1438
|
}
|
|
1369
|
-
return
|
|
1439
|
+
return _context14.abrupt("return", []);
|
|
1370
1440
|
case 10:
|
|
1371
|
-
|
|
1441
|
+
_context14.next = 12;
|
|
1372
1442
|
return Promise.all(addressList.map( /*#__PURE__*/function () {
|
|
1373
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1443
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(contractAddress, index) {
|
|
1374
1444
|
var _yield$aggregator$con, contractType;
|
|
1375
|
-
return _regeneratorRuntime().wrap(function
|
|
1376
|
-
while (1) switch (
|
|
1445
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1446
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1377
1447
|
case 0:
|
|
1378
|
-
|
|
1448
|
+
_context13.next = 2;
|
|
1379
1449
|
return aggregator.contractList(index);
|
|
1380
1450
|
case 2:
|
|
1381
|
-
_yield$aggregator$con =
|
|
1451
|
+
_yield$aggregator$con = _context13.sent;
|
|
1382
1452
|
contractType = _yield$aggregator$con.contractType;
|
|
1383
|
-
return
|
|
1453
|
+
return _context13.abrupt("return", {
|
|
1384
1454
|
contractType: contractType,
|
|
1385
1455
|
contractAddress: contractAddress
|
|
1386
1456
|
});
|
|
1387
1457
|
case 5:
|
|
1388
1458
|
case "end":
|
|
1389
|
-
return
|
|
1459
|
+
return _context13.stop();
|
|
1390
1460
|
}
|
|
1391
|
-
},
|
|
1461
|
+
}, _callee13);
|
|
1392
1462
|
}));
|
|
1393
|
-
return function (
|
|
1463
|
+
return function (_x15, _x16) {
|
|
1394
1464
|
return _ref2.apply(this, arguments);
|
|
1395
1465
|
};
|
|
1396
1466
|
}()));
|
|
1397
1467
|
case 12:
|
|
1398
|
-
supportContracts =
|
|
1399
|
-
return
|
|
1468
|
+
supportContracts = _context14.sent;
|
|
1469
|
+
return _context14.abrupt("return", supportContracts);
|
|
1400
1470
|
case 14:
|
|
1401
1471
|
case "end":
|
|
1402
|
-
return
|
|
1472
|
+
return _context14.stop();
|
|
1403
1473
|
}
|
|
1404
|
-
},
|
|
1474
|
+
}, _callee14, this);
|
|
1405
1475
|
}));
|
|
1406
|
-
function getAggregatorSupportContracts(
|
|
1476
|
+
function getAggregatorSupportContracts(_x14) {
|
|
1407
1477
|
return _getAggregatorSupportContracts.apply(this, arguments);
|
|
1408
1478
|
}
|
|
1409
1479
|
return getAggregatorSupportContracts;
|
|
@@ -1411,68 +1481,68 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1411
1481
|
}, {
|
|
1412
1482
|
key: "getQuoterSupportContracts",
|
|
1413
1483
|
value: function () {
|
|
1414
|
-
var _getQuoterSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1484
|
+
var _getQuoterSupportContracts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(chain) {
|
|
1415
1485
|
var quoterAddress, provider, quoter, addressList, supportContracts;
|
|
1416
|
-
return _regeneratorRuntime().wrap(function
|
|
1417
|
-
while (1) switch (
|
|
1486
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1487
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1418
1488
|
case 0:
|
|
1419
1489
|
// 返回传入链支持的dex和桥
|
|
1420
1490
|
// 返回dex type数组
|
|
1421
1491
|
quoterAddress = this.getQuoterAddress(chain);
|
|
1422
1492
|
provider = this.providerMap.get(chain);
|
|
1423
1493
|
if (provider) {
|
|
1424
|
-
|
|
1494
|
+
_context16.next = 4;
|
|
1425
1495
|
break;
|
|
1426
1496
|
}
|
|
1427
1497
|
throw new Error("Provider not configured for chain: ".concat(chain));
|
|
1428
1498
|
case 4:
|
|
1429
1499
|
quoter = new Contract(quoterAddress, QuoterAbi, provider);
|
|
1430
|
-
|
|
1500
|
+
_context16.next = 7;
|
|
1431
1501
|
return quoter.getAddressList();
|
|
1432
1502
|
case 7:
|
|
1433
|
-
addressList =
|
|
1503
|
+
addressList = _context16.sent;
|
|
1434
1504
|
if (addressList.length) {
|
|
1435
|
-
|
|
1505
|
+
_context16.next = 10;
|
|
1436
1506
|
break;
|
|
1437
1507
|
}
|
|
1438
|
-
return
|
|
1508
|
+
return _context16.abrupt("return", []);
|
|
1439
1509
|
case 10:
|
|
1440
|
-
|
|
1510
|
+
_context16.next = 12;
|
|
1441
1511
|
return Promise.all(addressList.map( /*#__PURE__*/function () {
|
|
1442
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1512
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(contractAddress, index) {
|
|
1443
1513
|
var _yield$quoter$contrac, contractType;
|
|
1444
|
-
return _regeneratorRuntime().wrap(function
|
|
1445
|
-
while (1) switch (
|
|
1514
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1515
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1446
1516
|
case 0:
|
|
1447
|
-
|
|
1517
|
+
_context15.next = 2;
|
|
1448
1518
|
return quoter.contractList(index);
|
|
1449
1519
|
case 2:
|
|
1450
|
-
_yield$quoter$contrac =
|
|
1520
|
+
_yield$quoter$contrac = _context15.sent;
|
|
1451
1521
|
contractType = _yield$quoter$contrac.contractType;
|
|
1452
|
-
return
|
|
1522
|
+
return _context15.abrupt("return", {
|
|
1453
1523
|
contractType: contractType,
|
|
1454
1524
|
contractAddress: contractAddress
|
|
1455
1525
|
});
|
|
1456
1526
|
case 5:
|
|
1457
1527
|
case "end":
|
|
1458
|
-
return
|
|
1528
|
+
return _context15.stop();
|
|
1459
1529
|
}
|
|
1460
|
-
},
|
|
1530
|
+
}, _callee15);
|
|
1461
1531
|
}));
|
|
1462
|
-
return function (
|
|
1532
|
+
return function (_x18, _x19) {
|
|
1463
1533
|
return _ref3.apply(this, arguments);
|
|
1464
1534
|
};
|
|
1465
1535
|
}()));
|
|
1466
1536
|
case 12:
|
|
1467
|
-
supportContracts =
|
|
1468
|
-
return
|
|
1537
|
+
supportContracts = _context16.sent;
|
|
1538
|
+
return _context16.abrupt("return", supportContracts);
|
|
1469
1539
|
case 14:
|
|
1470
1540
|
case "end":
|
|
1471
|
-
return
|
|
1541
|
+
return _context16.stop();
|
|
1472
1542
|
}
|
|
1473
|
-
},
|
|
1543
|
+
}, _callee16, this);
|
|
1474
1544
|
}));
|
|
1475
|
-
function getQuoterSupportContracts(
|
|
1545
|
+
function getQuoterSupportContracts(_x17) {
|
|
1476
1546
|
return _getQuoterSupportContracts.apply(this, arguments);
|
|
1477
1547
|
}
|
|
1478
1548
|
return getQuoterSupportContracts;
|
|
@@ -1537,10 +1607,10 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1537
1607
|
}, {
|
|
1538
1608
|
key: "sendBundle",
|
|
1539
1609
|
value: function () {
|
|
1540
|
-
var _sendBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1610
|
+
var _sendBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(rawTxs, targetBlock, signer) {
|
|
1541
1611
|
var body, signature, headers, BUILDERS, builderEntries, count, promises;
|
|
1542
|
-
return _regeneratorRuntime().wrap(function
|
|
1543
|
-
while (1) switch (
|
|
1612
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1613
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1544
1614
|
case 0:
|
|
1545
1615
|
console.log("\n--- Sending Bundle for Block ".concat(targetBlock, " ---"));
|
|
1546
1616
|
body = {
|
|
@@ -1552,10 +1622,10 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1552
1622
|
blockNumber: "0x".concat(targetBlock.toString(16))
|
|
1553
1623
|
}]
|
|
1554
1624
|
};
|
|
1555
|
-
|
|
1625
|
+
_context18.next = 4;
|
|
1556
1626
|
return this.signRequestBody(body, signer);
|
|
1557
1627
|
case 4:
|
|
1558
|
-
signature =
|
|
1628
|
+
signature = _context18.sent;
|
|
1559
1629
|
headers = {
|
|
1560
1630
|
'Content-Type': 'application/json',
|
|
1561
1631
|
'X-Flashbots-Signature': signature
|
|
@@ -1570,48 +1640,48 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1570
1640
|
builderEntries = Object.entries(BUILDERS);
|
|
1571
1641
|
count = 0;
|
|
1572
1642
|
promises = builderEntries.map( /*#__PURE__*/function () {
|
|
1573
|
-
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1643
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(_ref4) {
|
|
1574
1644
|
var _ref6, name, url, response, _error$message, msg;
|
|
1575
|
-
return _regeneratorRuntime().wrap(function
|
|
1576
|
-
while (1) switch (
|
|
1645
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1646
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1577
1647
|
case 0:
|
|
1578
1648
|
_ref6 = _slicedToArray(_ref4, 2), name = _ref6[0], url = _ref6[1];
|
|
1579
|
-
|
|
1580
|
-
|
|
1649
|
+
_context17.prev = 1;
|
|
1650
|
+
_context17.next = 4;
|
|
1581
1651
|
return axios.post(url, body, {
|
|
1582
1652
|
headers: headers
|
|
1583
1653
|
});
|
|
1584
1654
|
case 4:
|
|
1585
|
-
response =
|
|
1655
|
+
response = _context17.sent;
|
|
1586
1656
|
count++;
|
|
1587
1657
|
console.log("[".concat(count, "/").concat(builderEntries.length, "] Sent to ").concat(name, ":"), response.data);
|
|
1588
|
-
|
|
1658
|
+
_context17.next = 14;
|
|
1589
1659
|
break;
|
|
1590
1660
|
case 9:
|
|
1591
|
-
|
|
1592
|
-
|
|
1661
|
+
_context17.prev = 9;
|
|
1662
|
+
_context17.t0 = _context17["catch"](1);
|
|
1593
1663
|
count++;
|
|
1594
|
-
msg =
|
|
1664
|
+
msg = _context17.t0 !== null && _context17.t0 !== void 0 && _context17.t0.response ? _context17.t0.response.data : (_error$message = _context17.t0 === null || _context17.t0 === void 0 ? void 0 : _context17.t0.message) !== null && _error$message !== void 0 ? _error$message : _context17.t0;
|
|
1595
1665
|
console.error("[".concat(count, "/").concat(builderEntries.length, "] Error sending to ").concat(name, ":"), msg);
|
|
1596
1666
|
case 14:
|
|
1597
1667
|
case "end":
|
|
1598
|
-
return
|
|
1668
|
+
return _context17.stop();
|
|
1599
1669
|
}
|
|
1600
|
-
},
|
|
1670
|
+
}, _callee17, null, [[1, 9]]);
|
|
1601
1671
|
}));
|
|
1602
|
-
return function (
|
|
1672
|
+
return function (_x23) {
|
|
1603
1673
|
return _ref5.apply(this, arguments);
|
|
1604
1674
|
};
|
|
1605
1675
|
}());
|
|
1606
|
-
|
|
1676
|
+
_context18.next = 12;
|
|
1607
1677
|
return Promise.all(promises);
|
|
1608
1678
|
case 12:
|
|
1609
1679
|
case "end":
|
|
1610
|
-
return
|
|
1680
|
+
return _context18.stop();
|
|
1611
1681
|
}
|
|
1612
|
-
},
|
|
1682
|
+
}, _callee18, this);
|
|
1613
1683
|
}));
|
|
1614
|
-
function sendBundle(
|
|
1684
|
+
function sendBundle(_x20, _x21, _x22) {
|
|
1615
1685
|
return _sendBundle.apply(this, arguments);
|
|
1616
1686
|
}
|
|
1617
1687
|
return sendBundle;
|
|
@@ -1619,31 +1689,31 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1619
1689
|
}, {
|
|
1620
1690
|
key: "resolveNonce",
|
|
1621
1691
|
value: function () {
|
|
1622
|
-
var _resolveNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1692
|
+
var _resolveNonce = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(provider, from, tx) {
|
|
1623
1693
|
var nonce;
|
|
1624
|
-
return _regeneratorRuntime().wrap(function
|
|
1625
|
-
while (1) switch (
|
|
1694
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1695
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1626
1696
|
case 0:
|
|
1627
1697
|
if (!(tx.nonce != null)) {
|
|
1628
|
-
|
|
1698
|
+
_context19.next = 2;
|
|
1629
1699
|
break;
|
|
1630
1700
|
}
|
|
1631
|
-
return
|
|
1701
|
+
return _context19.abrupt("return", tx);
|
|
1632
1702
|
case 2:
|
|
1633
|
-
|
|
1703
|
+
_context19.next = 4;
|
|
1634
1704
|
return provider.getTransactionCount(from, 'latest');
|
|
1635
1705
|
case 4:
|
|
1636
|
-
nonce =
|
|
1637
|
-
return
|
|
1706
|
+
nonce = _context19.sent;
|
|
1707
|
+
return _context19.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
|
|
1638
1708
|
nonce: nonce
|
|
1639
1709
|
}));
|
|
1640
1710
|
case 6:
|
|
1641
1711
|
case "end":
|
|
1642
|
-
return
|
|
1712
|
+
return _context19.stop();
|
|
1643
1713
|
}
|
|
1644
|
-
},
|
|
1714
|
+
}, _callee19);
|
|
1645
1715
|
}));
|
|
1646
|
-
function resolveNonce(
|
|
1716
|
+
function resolveNonce(_x24, _x25, _x26) {
|
|
1647
1717
|
return _resolveNonce.apply(this, arguments);
|
|
1648
1718
|
}
|
|
1649
1719
|
return resolveNonce;
|
|
@@ -1651,47 +1721,47 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1651
1721
|
}, {
|
|
1652
1722
|
key: "resolvePricing",
|
|
1653
1723
|
value: function () {
|
|
1654
|
-
var _resolvePricing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1724
|
+
var _resolvePricing = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(provider, tx) {
|
|
1655
1725
|
var fd;
|
|
1656
|
-
return _regeneratorRuntime().wrap(function
|
|
1657
|
-
while (1) switch (
|
|
1726
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1727
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1658
1728
|
case 0:
|
|
1659
1729
|
if (!(tx.gasPrice != null || tx.maxFeePerGas != null || tx.maxPriorityFeePerGas != null)) {
|
|
1660
|
-
|
|
1730
|
+
_context20.next = 2;
|
|
1661
1731
|
break;
|
|
1662
1732
|
}
|
|
1663
|
-
return
|
|
1733
|
+
return _context20.abrupt("return", this.sanitizePricing(tx));
|
|
1664
1734
|
case 2:
|
|
1665
|
-
|
|
1735
|
+
_context20.next = 4;
|
|
1666
1736
|
return provider.getFeeData();
|
|
1667
1737
|
case 4:
|
|
1668
|
-
fd =
|
|
1738
|
+
fd = _context20.sent;
|
|
1669
1739
|
if (!(fd.maxFeePerGas != null && fd.maxPriorityFeePerGas != null)) {
|
|
1670
|
-
|
|
1740
|
+
_context20.next = 7;
|
|
1671
1741
|
break;
|
|
1672
1742
|
}
|
|
1673
|
-
return
|
|
1743
|
+
return _context20.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
|
|
1674
1744
|
maxFeePerGas: fd.maxFeePerGas * 150n / 100n,
|
|
1675
1745
|
// 上浮50%
|
|
1676
1746
|
maxPriorityFeePerGas: fd.maxPriorityFeePerGas
|
|
1677
1747
|
}));
|
|
1678
1748
|
case 7:
|
|
1679
1749
|
if (!(fd.gasPrice != null)) {
|
|
1680
|
-
|
|
1750
|
+
_context20.next = 9;
|
|
1681
1751
|
break;
|
|
1682
1752
|
}
|
|
1683
|
-
return
|
|
1753
|
+
return _context20.abrupt("return", _objectSpread(_objectSpread({}, tx), {}, {
|
|
1684
1754
|
gasPrice: fd.gasPrice
|
|
1685
1755
|
}));
|
|
1686
1756
|
case 9:
|
|
1687
|
-
return
|
|
1757
|
+
return _context20.abrupt("return", tx);
|
|
1688
1758
|
case 10:
|
|
1689
1759
|
case "end":
|
|
1690
|
-
return
|
|
1760
|
+
return _context20.stop();
|
|
1691
1761
|
}
|
|
1692
|
-
},
|
|
1762
|
+
}, _callee20, this);
|
|
1693
1763
|
}));
|
|
1694
|
-
function resolvePricing(
|
|
1764
|
+
function resolvePricing(_x27, _x28) {
|
|
1695
1765
|
return _resolvePricing.apply(this, arguments);
|
|
1696
1766
|
}
|
|
1697
1767
|
return resolvePricing;
|
|
@@ -1699,26 +1769,26 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1699
1769
|
}, {
|
|
1700
1770
|
key: "signRequestBody",
|
|
1701
1771
|
value: function () {
|
|
1702
|
-
var _signRequestBody = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1772
|
+
var _signRequestBody = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(body, signer) {
|
|
1703
1773
|
var bodyJson, encoder, requestBodyHash, signature;
|
|
1704
|
-
return _regeneratorRuntime().wrap(function
|
|
1705
|
-
while (1) switch (
|
|
1774
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1775
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1706
1776
|
case 0:
|
|
1707
1777
|
bodyJson = JSON.stringify(body);
|
|
1708
1778
|
encoder = new TextEncoder();
|
|
1709
1779
|
requestBodyHash = ethers.keccak256(encoder.encode(bodyJson));
|
|
1710
|
-
|
|
1780
|
+
_context21.next = 5;
|
|
1711
1781
|
return signer.signMessage(requestBodyHash);
|
|
1712
1782
|
case 5:
|
|
1713
|
-
signature =
|
|
1714
|
-
return
|
|
1783
|
+
signature = _context21.sent;
|
|
1784
|
+
return _context21.abrupt("return", "".concat(signer.address, ":").concat(signature));
|
|
1715
1785
|
case 7:
|
|
1716
1786
|
case "end":
|
|
1717
|
-
return
|
|
1787
|
+
return _context21.stop();
|
|
1718
1788
|
}
|
|
1719
|
-
},
|
|
1789
|
+
}, _callee21);
|
|
1720
1790
|
}));
|
|
1721
|
-
function signRequestBody(
|
|
1791
|
+
function signRequestBody(_x29, _x30) {
|
|
1722
1792
|
return _signRequestBody.apply(this, arguments);
|
|
1723
1793
|
}
|
|
1724
1794
|
return signRequestBody;
|
|
@@ -1737,38 +1807,38 @@ var Hermes = /*#__PURE__*/function () {
|
|
|
1737
1807
|
}, {
|
|
1738
1808
|
key: "checkIsEnoughToken",
|
|
1739
1809
|
value: function () {
|
|
1740
|
-
var _checkIsEnoughToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1810
|
+
var _checkIsEnoughToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(fromTokenAddress, userAddress, amountInWei, aggregatorAddress, wallet) {
|
|
1741
1811
|
var erc20, userBalance, currentAllowance;
|
|
1742
|
-
return _regeneratorRuntime().wrap(function
|
|
1743
|
-
while (1) switch (
|
|
1812
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1813
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1744
1814
|
case 0:
|
|
1745
1815
|
erc20 = new Contract(fromTokenAddress, ['function balanceOf(address) view returns (uint256)', 'function allowance(address, address) view returns (uint256)'], wallet);
|
|
1746
|
-
|
|
1816
|
+
_context22.next = 3;
|
|
1747
1817
|
return erc20.balanceOf(userAddress);
|
|
1748
1818
|
case 3:
|
|
1749
|
-
userBalance =
|
|
1819
|
+
userBalance = _context22.sent;
|
|
1750
1820
|
if (!(userBalance < amountInWei)) {
|
|
1751
|
-
|
|
1821
|
+
_context22.next = 6;
|
|
1752
1822
|
break;
|
|
1753
1823
|
}
|
|
1754
1824
|
throw new Error('Insufficient balance token amount');
|
|
1755
1825
|
case 6:
|
|
1756
|
-
|
|
1826
|
+
_context22.next = 8;
|
|
1757
1827
|
return erc20.allowance(userAddress, aggregatorAddress);
|
|
1758
1828
|
case 8:
|
|
1759
|
-
currentAllowance =
|
|
1829
|
+
currentAllowance = _context22.sent;
|
|
1760
1830
|
if (!(currentAllowance < amountInWei)) {
|
|
1761
|
-
|
|
1831
|
+
_context22.next = 11;
|
|
1762
1832
|
break;
|
|
1763
1833
|
}
|
|
1764
1834
|
throw new Error('Insufficient allowance token amount');
|
|
1765
1835
|
case 11:
|
|
1766
1836
|
case "end":
|
|
1767
|
-
return
|
|
1837
|
+
return _context22.stop();
|
|
1768
1838
|
}
|
|
1769
|
-
},
|
|
1839
|
+
}, _callee22);
|
|
1770
1840
|
}));
|
|
1771
|
-
function checkIsEnoughToken(
|
|
1841
|
+
function checkIsEnoughToken(_x31, _x32, _x33, _x34, _x35) {
|
|
1772
1842
|
return _checkIsEnoughToken.apply(this, arguments);
|
|
1773
1843
|
}
|
|
1774
1844
|
return checkIsEnoughToken;
|