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

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