@naviprotocol/multiply 0.2.0-preview.20261123.1 → 0.2.0-preview.20261124.2

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.
@@ -1,94 +1,95 @@
1
- import { Transaction as D } from "@mysten/sui/transactions";
2
- import { bcs as y } from "@mysten/sui/bcs";
3
- import { buildSwapPTBFromQuote as H, getQuote as F } from "@naviprotocol/astros-aggregator-sdk";
4
- import { defaultClient as B } from "./data-source.js";
5
- import { VSUI as b, HASUI as T, SUI as f } from "./strategies.js";
6
- import { check as i, sameCoin as p, minOutputGuard as k, inspect as S, address as C, coinType as O, uint as R, MultiplyError as $ } from "./utils.js";
7
- const l = {
1
+ import { createStakingSnapshotReader as j } from "./native-staking.js";
2
+ import { Transaction as k } from "@mysten/sui/transactions";
3
+ import { bcs as L } from "@mysten/sui/bcs";
4
+ import { buildSwapPTBFromQuote as P, getQuote as G } from "@naviprotocol/astros-aggregator-sdk";
5
+ import { defaultClient as h } from "./data-source.js";
6
+ import { VSUI as v, SUI as I, HASUI as y } from "./strategies.js";
7
+ import { check as i, address as D, sameCoin as p, minOutputGuard as B, coinType as N, inspect as T, uint as R, MultiplyError as K } from "./utils.js";
8
+ const d = {
8
9
  package: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
9
10
  pool: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
10
11
  metadata: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"
11
- }, V = {
12
+ }, _ = {
12
13
  package: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
13
14
  config: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca"
14
15
  };
15
- function U(n) {
16
- return R(n.amountIn, !1), i(
17
- Number.isInteger(n.slippageBps) && n.slippageBps >= 0 && n.slippageBps < 1e4,
16
+ function U(t) {
17
+ return R(t.amountIn, !1), i(
18
+ Number.isInteger(t.slippageBps) && t.slippageBps >= 0 && t.slippageBps < 1e4,
18
19
  "INVALID_ARGUMENT",
19
20
  "Invalid converter slippage"
20
- ), n;
21
+ ), t;
21
22
  }
22
- function h(n, a, o, e) {
23
- const s = L(o, "INVALID_CONVERSION") * BigInt(1e4 - a.slippageBps) / 10000n;
24
- i(s > 0n, "CONVERSION_AMOUNT_TOO_SMALL", "Conversion minimum rounds below one atom");
25
- const u = s.toString();
23
+ function x(t, o, r, n) {
24
+ const a = C(r, "INVALID_CONVERSION") * BigInt(1e4 - o.slippageBps) / 10000n;
25
+ i(a > 0n, "CONVERSION_AMOUNT_TOO_SMALL", "Conversion minimum rounds below one atom");
26
+ const c = a.toString();
26
27
  return {
27
- converterId: n,
28
- input: { coinType: O(a.coinIn), amount: a.amountIn },
29
- expectedOutput: { coinType: O(a.coinOut), amount: o },
30
- minOutput: { coinType: O(a.coinOut), amount: u },
28
+ converterId: t,
29
+ input: { coinType: N(o.coinIn), amount: o.amountIn },
30
+ expectedOutput: { coinType: N(o.coinOut), amount: r },
31
+ minOutput: { coinType: N(o.coinOut), amount: c },
31
32
  expiresAt: Date.now() + 12e4,
32
- data: e
33
+ data: n
33
34
  };
34
35
  }
35
- function Y(n, a, o) {
36
+ function te(t, o, r) {
36
37
  i(
37
- n.converterId === o && p(n.input.coinType, a.coinIn) && p(n.expectedOutput.coinType, a.coinOut) && p(n.minOutput.coinType, a.coinOut) && n.input.amount === a.amountIn,
38
+ t.converterId === r && p(t.input.coinType, o.coinIn) && p(t.expectedOutput.coinType, o.coinOut) && p(t.minOutput.coinType, o.coinOut) && t.input.amount === o.amountIn,
38
39
  "INVALID_CONVERSION",
39
40
  "Converter returned a mismatched pair or amount"
40
41
  );
41
- const e = R(n.expectedOutput.amount, !1), t = R(n.minOutput.amount, !1);
42
+ const n = R(t.expectedOutput.amount, !1), e = R(t.minOutput.amount, !1);
42
43
  i(
43
- t <= e && t >= e * BigInt(1e4 - a.slippageBps) / 10000n,
44
+ e <= n && e >= n * BigInt(1e4 - o.slippageBps) / 10000n,
44
45
  "INVALID_CONVERSION",
45
46
  "Converter minimum exceeds the slippage budget"
46
47
  ), i(
47
- Number.isSafeInteger(n.expiresAt) && n.expiresAt > Date.now(),
48
+ Number.isSafeInteger(t.expiresAt) && t.expiresAt > Date.now(),
48
49
  "QUOTE_EXPIRED",
49
50
  "Conversion quote expired"
50
51
  );
51
52
  }
52
- function E(n, a, o) {
53
- return p(a, f) && p(o, n) || p(a, n) && p(o, f);
53
+ function V(t, o, r) {
54
+ return p(o, I) && p(r, t) || p(o, t) && p(r, I);
54
55
  }
55
- function v(n, a) {
56
+ function S(t, o) {
56
57
  return i(
57
- n && typeof n == "object" && !Array.isArray(n),
58
+ t && typeof t == "object" && !Array.isArray(t),
58
59
  "READ_FAILED",
59
- `Invalid ${a}`
60
- ), n;
60
+ `Invalid ${o}`
61
+ ), t;
61
62
  }
62
- function L(n, a) {
63
+ function C(t, o) {
63
64
  try {
64
- return R(n);
65
+ return R(t);
65
66
  } catch {
66
- throw new $(a, "Invalid upstream integer amount");
67
+ throw new K(o, "Invalid upstream integer amount");
67
68
  }
68
69
  }
69
- function w(n, a) {
70
- n.moveCall({
71
- target: `${l.package}::stake_pool::lst_amount_to_sui_amount`,
72
- arguments: [n.object(l.pool), n.object(l.metadata), n.pure.u64(a)]
70
+ function M(t, o) {
71
+ t.moveCall({
72
+ target: `${d.package}::stake_pool::lst_amount_to_sui_amount`,
73
+ arguments: [t.object(d.pool), t.object(d.metadata), t.pure.u64(o)]
73
74
  });
74
- const o = n.moveCall({
75
- target: `${l.package}::stake_pool::fee_config`,
76
- arguments: [n.object(l.pool)]
75
+ const r = t.moveCall({
76
+ target: `${d.package}::stake_pool::fee_config`,
77
+ arguments: [t.object(d.pool)]
77
78
  });
78
- n.moveCall({ target: `${l.package}::fee_config::unstake_fee_bps`, arguments: [o] });
79
+ t.moveCall({ target: `${d.package}::fee_config::unstake_fee_bps`, arguments: [r] });
79
80
  }
80
- function j(n, a = 0) {
81
+ function H(t, o = 0) {
81
82
  try {
82
- const o = BigInt(y.u64().parse(n[a].returnValues[0].bcs)), e = BigInt(y.u64().parse(n[a + 2].returnValues[0].bcs));
83
- if (o <= 0n || e > 500n) return;
84
- const t = (o * e + 9999n) / 10000n;
83
+ const r = BigInt(L.u64().parse(t[o].returnValues[0].bcs)), n = BigInt(L.u64().parse(t[o + 2].returnValues[0].bcs));
84
+ if (r <= 0n || n > 500n) return;
85
+ const e = (r * n + 9999n) / 10000n;
85
86
  return {
86
- net: (o - t).toString(),
87
+ net: (r - e).toString(),
87
88
  fees: [
88
89
  {
89
90
  provider: "volo",
90
- coinType: O(f),
91
- amount: t.toString(),
91
+ coinType: N(I),
92
+ amount: e.toString(),
92
93
  feeKind: "redemption",
93
94
  includedInExpectedOutput: !0
94
95
  }
@@ -98,271 +99,287 @@ function j(n, a = 0) {
98
99
  return;
99
100
  }
100
101
  }
101
- async function P(n, a) {
102
- let o;
102
+ async function Q(t, o) {
103
+ let r;
103
104
  try {
104
- const e = new D();
105
- return w(e, a), await Promise.race([
106
- S(n, e).then((t) => j(t)),
107
- new Promise((t) => {
108
- o = setTimeout(() => t(void 0), 1500);
105
+ const n = new k();
106
+ return M(n, o), await Promise.race([
107
+ T(t, n).then((e) => H(e)),
108
+ new Promise((e) => {
109
+ r = setTimeout(() => e(void 0), 1500);
109
110
  })
110
111
  ]);
111
112
  } catch {
112
113
  return;
113
114
  } finally {
114
- o !== void 0 && clearTimeout(o);
115
+ r !== void 0 && clearTimeout(r);
115
116
  }
116
117
  }
117
- function G(n, a) {
118
+ function X(t, o) {
118
119
  try {
119
- const o = n.routes[0], e = o?.path?.[0];
120
- return p(a.coinIn, b) && p(a.coinOut, f) && p(n.from, a.coinIn) && p(n.target, a.coinOut) && n.routes.length === 1 && o.path?.length === 1 && e?.provider === "vSui" && e.a2b === !1 && typeof e.from == "string" && typeof e.target == "string" && p(e.from, b) && p(e.target, f) && String(o.amount_in) === a.amountIn && String(e.amount_in) === a.amountIn;
120
+ const r = t.routes[0], n = r?.path?.[0];
121
+ return p(o.coinIn, v) && p(o.coinOut, I) && p(t.from, o.coinIn) && p(t.target, o.coinOut) && t.routes.length === 1 && r.path?.length === 1 && n?.provider === "vSui" && n.a2b === !1 && typeof n.from == "string" && typeof n.target == "string" && p(n.from, v) && p(n.target, I) && String(r.amount_in) === o.amountIn && String(n.amount_in) === o.amountIn;
121
122
  } catch {
122
123
  return !1;
123
124
  }
124
125
  }
125
- function Z(n = {}) {
126
- const a = n.client ?? B();
127
- return {
126
+ function ne(t = {}) {
127
+ const o = t.client ?? h(), r = {
128
128
  id: "volo",
129
- supports: (o, e) => E(b, o, e),
130
- async quote(o) {
131
- const e = U(o), t = p(e.coinIn, f);
132
- i(E(b, e.coinIn, e.coinOut), "CONVERTER_UNAVAILABLE", "Unsupported Volo pair");
133
- const { object: s } = await a.core.getObject({
134
- objectId: l.pool,
129
+ supports: (n, e) => V(v, n, e),
130
+ async quote(n) {
131
+ const e = U(n), a = p(e.coinIn, I);
132
+ i(V(v, e.coinIn, e.coinOut), "CONVERTER_UNAVAILABLE", "Unsupported Volo pair");
133
+ const { object: c } = await o.core.getObject({
134
+ objectId: d.pool,
135
135
  include: { json: !0 }
136
- }), u = v(s?.json, "Volo pool"), r = v(u.manage, "Volo management state");
137
- i(typeof r.paused == "boolean", "READ_FAILED", "Invalid Volo pause state"), i(!r.paused, "CONVERTER_UNAVAILABLE", "Volo is paused");
138
- const c = () => {
139
- const I = new D();
140
- return I.moveCall({
141
- target: `${l.package}::stake_pool::get_amount_out`,
136
+ }), s = S(c?.json, "Volo pool"), u = S(s.manage, "Volo management state");
137
+ i(typeof u.paused == "boolean", "READ_FAILED", "Invalid Volo pause state"), i(!u.paused, "CONVERTER_UNAVAILABLE", "Volo is paused");
138
+ const l = () => {
139
+ const m = new k();
140
+ return m.moveCall({
141
+ target: `${d.package}::stake_pool::get_amount_out`,
142
142
  arguments: [
143
- I.object(l.pool),
144
- I.object(l.metadata),
145
- I.pure.u64(e.amountIn),
146
- I.pure.bool(t)
143
+ m.object(d.pool),
144
+ m.object(d.metadata),
145
+ m.pure.u64(e.amountIn),
146
+ m.pure.bool(a)
147
147
  ]
148
- }), I;
149
- }, d = c();
150
- t || w(d, e.amountIn);
151
- let m;
148
+ }), m;
149
+ }, O = l();
150
+ a || M(O, e.amountIn);
151
+ let g;
152
152
  try {
153
- m = await S(a, d);
154
- } catch (I) {
155
- if (t) throw I;
156
- m = await S(a, c());
153
+ g = await T(o, O);
154
+ } catch (m) {
155
+ if (a) throw m;
156
+ g = await T(o, l());
157
157
  }
158
- const _ = t ? void 0 : j(m, 1), g = _?.net ?? y.u64().parse(m[0].returnValues[0].bcs);
158
+ const f = a ? void 0 : H(g, 1), b = f?.net ?? L.u64().parse(g[0].returnValues[0].bcs);
159
159
  i(
160
- BigInt(t ? e.amountIn : g) >= 1000000000n,
160
+ BigInt(a ? e.amountIn : b) >= 1000000000n,
161
161
  "CONVERSION_AMOUNT_TOO_SMALL",
162
162
  "Volo requires at least 1 SUI input or redemption output"
163
163
  );
164
- const A = h("volo", e, g, { version: 1, stake: t });
165
- return _ && (A.fees = _.fees), A;
164
+ const A = x("volo", e, b, { version: 1, stake: a });
165
+ return f && (A.fees = f.fees), A;
166
166
  },
167
- async buildPTB(o, e, t) {
167
+ async buildPTB(n, e, a) {
168
168
  i(
169
- e.converterId === "volo" && E(b, e.input.coinType, e.expectedOutput.coinType) && e.expiresAt > Date.now(),
169
+ e.converterId === "volo" && V(v, e.input.coinType, e.expectedOutput.coinType) && e.expiresAt > Date.now(),
170
170
  "INVALID_CONVERSION",
171
171
  "Invalid or expired Volo quote"
172
172
  );
173
- const s = o.moveCall({
174
- target: `${l.package}::stake_pool::${p(e.input.coinType, f) ? "stake" : "unstake"}`,
175
- arguments: [o.object(l.pool), o.object(l.metadata), o.object("0x5"), t]
173
+ const c = n.moveCall({
174
+ target: `${d.package}::stake_pool::${p(e.input.coinType, I) ? "stake" : "unstake"}`,
175
+ arguments: [n.object(d.pool), n.object(d.metadata), n.object("0x5"), a]
176
176
  });
177
- return k(o, s, e.minOutput.amount), { coinOut: s, change: [] };
177
+ return B(n, c, e.minOutput.amount), { coinOut: c, change: [] };
178
178
  }
179
179
  };
180
+ return r.getStakingSnapshot = j(o, {
181
+ converterId: "volo",
182
+ packageId: d.package,
183
+ pool: d.pool,
184
+ metadata: d.metadata,
185
+ coinIn: I,
186
+ coinOut: v
187
+ }), r;
180
188
  }
181
- function q(n = {}) {
182
- const a = n.client ?? B();
183
- return {
189
+ function oe(t = {}) {
190
+ const o = t.client ?? h(), r = {
184
191
  id: "haedal",
185
- supports: (o, e) => E(T, o, e),
186
- async quote(o) {
187
- const e = U(o), t = p(e.coinIn, f);
192
+ supports: (n, e) => V(y, n, e),
193
+ async quote(n) {
194
+ const e = U(n), a = p(e.coinIn, I);
188
195
  i(
189
- E(T, e.coinIn, e.coinOut),
196
+ V(y, e.coinIn, e.coinOut),
190
197
  "CONVERTER_UNAVAILABLE",
191
198
  "Unsupported Haedal pair"
192
199
  ), i(
193
- !t || BigInt(e.amountIn) >= 1000000000n,
200
+ !a || BigInt(e.amountIn) >= 1000000000n,
194
201
  "CONVERSION_AMOUNT_TOO_SMALL",
195
202
  "Haedal requires at least 1 SUI staking input"
196
203
  );
197
- const { object: s } = await a.core.getObject({
198
- objectId: V.config,
204
+ const { object: c } = await o.core.getObject({
205
+ objectId: _.config,
199
206
  include: { json: !0 }
200
- }), u = v(s?.json, "Haedal state"), r = u[t ? "pause_stake" : "pause_unstake"];
201
- i(typeof r == "boolean", "READ_FAILED", "Invalid Haedal pause state");
202
- const c = v(u.config, "Haedal fee configuration"), d = L(c[t ? "deposit_fee" : "service_fee"], "READ_FAILED"), m = 10000000n;
203
- i(d < m, "READ_FAILED", "Invalid Haedal fee");
204
- const _ = t ? null : L(v(u.sui_vault, "Haedal vault").cache_pool, "READ_FAILED");
205
- i(!r, "CONVERTER_UNAVAILABLE", "Haedal is paused");
206
- const g = BigInt(e.amountIn), A = new D();
207
- A.moveCall({
208
- target: `${V.package}::staking::${t ? "get_stsui_by_sui" : "get_sui_by_stsui"}`,
207
+ }), s = S(c?.json, "Haedal state"), u = s[a ? "pause_stake" : "pause_unstake"];
208
+ i(typeof u == "boolean", "READ_FAILED", "Invalid Haedal pause state");
209
+ const l = S(s.config, "Haedal fee configuration"), O = C(
210
+ l[a ? "deposit_fee" : "service_fee"],
211
+ "READ_FAILED"
212
+ ), g = a ? 0n : O, f = 10000000n;
213
+ i(g < f, "READ_FAILED", "Invalid Haedal fee");
214
+ const b = a ? null : C(S(s.sui_vault, "Haedal vault").cache_pool, "READ_FAILED");
215
+ i(!u, "CONVERTER_UNAVAILABLE", "Haedal is paused");
216
+ const A = BigInt(e.amountIn), m = new k();
217
+ m.moveCall({
218
+ target: `${_.package}::staking::${a ? "get_stsui_by_sui" : "get_sui_by_stsui"}`,
209
219
  arguments: [
210
- A.object(V.config),
211
- A.pure.u64((t ? g - g * d / m : g).toString())
220
+ m.object(_.config),
221
+ m.pure.u64((a ? A - A * g / f : A).toString())
212
222
  ]
213
223
  });
214
- const I = await S(a, A), N = BigInt(y.u64().parse(I[0].returnValues[0].bcs)), M = t ? N : N - N * d / m;
215
- t || (i(
216
- N >= 1000000000n,
224
+ const F = await T(o, m), E = BigInt(L.u64().parse(F[0].returnValues[0].bcs)), $ = a ? E : E - E * g / f;
225
+ a || (i(
226
+ E >= 1000000000n,
217
227
  "CONVERSION_AMOUNT_TOO_SMALL",
218
228
  "Haedal requires at least 1 SUI gross redemption output"
219
229
  ), i(
220
- _ !== null && N <= _,
230
+ b !== null && E <= b,
221
231
  "CONVERTER_UNAVAILABLE",
222
232
  "Haedal instant redemption liquidity is insufficient"
223
233
  ));
224
- const x = h("haedal", e, M.toString(), {
234
+ const w = x("haedal", e, $.toString(), {
225
235
  version: 1,
226
- stake: t,
227
- feeRate: d.toString(),
228
- feeDenominator: m.toString()
236
+ stake: a,
237
+ feeRate: g.toString(),
238
+ feeDenominator: f.toString()
229
239
  });
230
- return x.fees = [
240
+ return w.fees = [
231
241
  {
232
- coinType: O(f),
233
- amount: ((t ? g : N) * d / m).toString(),
234
- feeKind: t ? "deposit" : "redemption",
242
+ coinType: N(I),
243
+ amount: ((a ? A : E) * g / f).toString(),
244
+ feeKind: a ? "deposit" : "redemption",
235
245
  includedInExpectedOutput: !0
236
246
  }
237
- ], x;
247
+ ], w;
238
248
  },
239
- async buildPTB(o, e, t) {
249
+ async buildPTB(n, e, a) {
240
250
  i(
241
- e.converterId === "haedal" && E(T, e.input.coinType, e.expectedOutput.coinType) && e.expiresAt > Date.now(),
251
+ e.converterId === "haedal" && V(y, e.input.coinType, e.expectedOutput.coinType) && e.expiresAt > Date.now(),
242
252
  "INVALID_CONVERSION",
243
253
  "Invalid or expired Haedal quote"
244
254
  );
245
- const s = p(e.input.coinType, f), u = [o.object("0x5"), o.object(V.config), t];
246
- s && u.push(o.pure.address(C("0x0")));
247
- const r = o.moveCall({
248
- target: `${V.package}::staking::${s ? "request_stake_coin" : "request_unstake_instant_coin"}`,
249
- arguments: u
255
+ const c = p(e.input.coinType, I), s = [n.object("0x5"), n.object(_.config), a];
256
+ c && s.push(n.pure.address(D("0x0")));
257
+ const u = n.moveCall({
258
+ target: `${_.package}::staking::${c ? "request_stake_coin" : "request_unstake_instant_coin"}`,
259
+ arguments: s
250
260
  });
251
- return k(o, r, e.minOutput.amount), { coinOut: r, change: [] };
261
+ return B(n, u, e.minOutput.amount), { coinOut: u, change: [] };
252
262
  }
253
263
  };
264
+ return r.getStakingSnapshot = j(o, {
265
+ converterId: "haedal",
266
+ packageId: _.package,
267
+ pool: _.config,
268
+ coinIn: I,
269
+ coinOut: y
270
+ }), r;
254
271
  }
255
- function ee(n = {}) {
256
- const a = (e) => {
257
- const t = R(String(e), !1);
272
+ function ae(t = {}) {
273
+ const o = (n) => {
274
+ const e = R(String(n), !1);
258
275
  return i(
259
- t <= BigInt(Number.MAX_SAFE_INTEGER),
276
+ e <= BigInt(Number.MAX_SAFE_INTEGER),
260
277
  "CONVERTER_UNAVAILABLE",
261
278
  "Astros route exceeds the SDK safe-integer limit"
262
- ), Number(t);
279
+ ), Number(e);
263
280
  };
264
- function o(e, t) {
281
+ function r(n, e) {
265
282
  i(
266
- e && Array.isArray(e.routes),
283
+ n && Array.isArray(n.routes),
267
284
  "INVALID_CONVERSION",
268
285
  "Invalid Astros route structure"
269
286
  );
270
- const s = (r, c = !1) => {
287
+ const a = (s, u = !1) => {
271
288
  i(
272
- typeof r == "string" || typeof r == "number" && Number.isSafeInteger(r),
289
+ typeof s == "string" || typeof s == "number" && Number.isSafeInteger(s),
273
290
  "INVALID_CONVERSION",
274
291
  "Invalid Astros amount type"
275
292
  );
276
- const d = L(String(r), "INVALID_CONVERSION");
277
- return i(c || d > 0n, "INVALID_CONVERSION", "Invalid Astros route amount"), i(
278
- d <= BigInt(Number.MAX_SAFE_INTEGER),
293
+ const l = C(String(s), "INVALID_CONVERSION");
294
+ return i(u || l > 0n, "INVALID_CONVERSION", "Invalid Astros route amount"), i(
295
+ l <= BigInt(Number.MAX_SAFE_INTEGER),
279
296
  "CONVERTER_UNAVAILABLE",
280
297
  "Astros route exceeds the SDK safe-integer limit"
281
- ), d;
298
+ ), l;
282
299
  };
283
- s(e.amount_in), i(String(e.amount_in) === t, "INVALID_CONVERSION", "Astros changed input amount");
284
- const u = s(e.amount_out, !0);
285
- for (const r of e.routes)
286
- i(r && typeof r == "object", "INVALID_CONVERSION", "Invalid Astros route leg"), s(r.amount_in), s(r.amount_out);
300
+ a(n.amount_in), i(String(n.amount_in) === e, "INVALID_CONVERSION", "Astros changed input amount");
301
+ const c = a(n.amount_out, !0);
302
+ for (const s of n.routes)
303
+ i(s && typeof s == "object", "INVALID_CONVERSION", "Invalid Astros route leg"), a(s.amount_in), a(s.amount_out);
287
304
  i(
288
- e.routes.length > 0 && u > 0n,
305
+ n.routes.length > 0 && c > 0n,
289
306
  "CONVERTER_UNAVAILABLE",
290
307
  "Astros returned no executable routes"
291
308
  );
292
309
  }
293
310
  return {
294
311
  id: "astros",
295
- supports: (e, t) => !p(e, t),
296
- async quote(e) {
297
- const t = U(e);
298
- a(t.amountIn);
299
- const s = await F(t.coinIn, t.coinOut, t.amountIn, n.apiKey, {
300
- baseUrl: n.baseUrl,
301
- services: n.services,
312
+ supports: (n, e) => !p(n, e),
313
+ async quote(n) {
314
+ const e = U(n);
315
+ o(e.amountIn);
316
+ const a = await G(e.coinIn, e.coinOut, e.amountIn, t.apiKey, {
317
+ baseUrl: t.baseUrl,
318
+ services: t.services,
302
319
  byAmountIn: !0
303
320
  });
304
- o(s, t.amountIn);
305
- const u = h("astros", t, String(s.amount_out), { version: 1, route: s });
306
- if (G(s, t)) {
307
- const r = await P(
308
- n.client ?? B(),
309
- t.amountIn
321
+ r(a, e.amountIn);
322
+ const c = x("astros", e, String(a.amount_out), { version: 1, route: a });
323
+ if (X(a, e)) {
324
+ const s = await Q(
325
+ t.client ?? h(),
326
+ e.amountIn
310
327
  );
311
- r && BigInt(u.expectedOutput.amount) <= BigInt(r.net) && (u.fees = r.fees);
328
+ s && BigInt(c.expectedOutput.amount) <= BigInt(s.net) && (c.fees = s.fees);
312
329
  }
313
- return u.route = {
330
+ return c.route = {
314
331
  provider: "astros",
315
332
  observedAt: Date.now(),
316
- hops: s.routes.flatMap(
317
- (r) => (r.path ?? []).flatMap(
318
- (c) => typeof c.from == "string" && typeof c.target == "string" ? [
333
+ hops: a.routes.flatMap(
334
+ (s) => (s.path ?? []).flatMap(
335
+ (u) => typeof u.from == "string" && typeof u.target == "string" ? [
319
336
  {
320
- coinIn: O(c.from),
321
- coinOut: O(c.target),
322
- ...typeof c.id == "string" ? { poolId: c.id } : {},
323
- ...typeof c.provider == "string" ? { dex: c.provider } : {},
324
- ...c.fee_rate !== void 0 ? { feeRate: String(c.fee_rate) } : {}
337
+ coinIn: N(u.from),
338
+ coinOut: N(u.target),
339
+ ...typeof u.id == "string" ? { poolId: u.id } : {},
340
+ ...typeof u.provider == "string" ? { dex: u.provider } : {},
341
+ ...u.fee_rate !== void 0 ? { feeRate: String(u.fee_rate) } : {}
325
342
  }
326
343
  ] : []
327
344
  )
328
345
  )
329
- }, u;
346
+ }, c;
330
347
  },
331
- async buildPTB(e, t, s, u) {
332
- i(u?.changeRecipient, "INVALID_ARGUMENT", "Astros requires a change recipient");
333
- const r = C(u.changeRecipient);
334
- i(r !== C("0x0"), "INVALID_ARGUMENT", "Change recipient cannot be zero"), i(
335
- t.converterId === "astros" && t.expiresAt > Date.now(),
348
+ async buildPTB(n, e, a, c) {
349
+ i(c?.changeRecipient, "INVALID_ARGUMENT", "Astros requires a change recipient");
350
+ const s = D(c.changeRecipient);
351
+ i(s !== D("0x0"), "INVALID_ARGUMENT", "Change recipient cannot be zero"), i(
352
+ e.converterId === "astros" && e.expiresAt > Date.now(),
336
353
  "INVALID_CONVERSION",
337
354
  "Invalid or expired Astros quote"
338
355
  );
339
- const c = t.data;
340
- i(c?.version === 1, "INVALID_CONVERSION", "Unknown Astros quote version");
341
- const d = c.route;
342
- o(d, t.input.amount), i(
343
- p(d.from, t.input.coinType) && p(d.target, t.expectedOutput.coinType) && String(d.amount_in) === t.input.amount && String(d.amount_out) === t.expectedOutput.amount,
356
+ const u = e.data;
357
+ i(u?.version === 1, "INVALID_CONVERSION", "Unknown Astros quote version");
358
+ const l = u.route;
359
+ r(l, e.input.amount), i(
360
+ p(l.from, e.input.coinType) && p(l.target, e.expectedOutput.coinType) && String(l.amount_in) === e.input.amount && String(l.amount_out) === e.expectedOutput.amount,
344
361
  "INVALID_CONVERSION",
345
362
  "Astros payload differs from the frozen quote"
346
363
  );
347
- const m = await H(
348
- r,
349
- e,
350
- a(t.minOutput.amount),
364
+ const O = await P(
351
365
  s,
352
- d,
366
+ n,
367
+ o(e.minOutput.amount),
368
+ a,
369
+ l,
353
370
  0,
354
371
  !1,
355
- n.apiKey,
356
- { services: n.services }
372
+ t.apiKey,
373
+ { services: t.services }
357
374
  );
358
- return k(e, m, t.minOutput.amount), { coinOut: m, change: [] };
375
+ return B(n, O, e.minOutput.amount), { coinOut: O, change: [] };
359
376
  }
360
377
  };
361
378
  }
362
379
  export {
363
- ee as astrosConverter,
364
- q as haedalConverter,
365
- Y as validateConversion,
366
- Z as voloConverter
380
+ ae as astrosConverter,
381
+ oe as haedalConverter,
382
+ te as validateConversion,
383
+ ne as voloConverter
367
384
  };
368
385
  //# sourceMappingURL=converters.js.map