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