@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.
- package/README.md +70 -46
- package/dist/amounts.d.ts +3 -3
- package/dist/amounts.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +406 -344
- package/dist/client.js.map +1 -1
- package/dist/converters.d.ts.map +1 -1
- package/dist/converters.js +221 -199
- package/dist/converters.js.map +1 -1
- package/dist/data-source.d.ts +2 -1
- package/dist/data-source.d.ts.map +1 -1
- package/dist/data-source.js +210 -196
- package/dist/data-source.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -18
- package/dist/index.js.map +1 -1
- package/dist/market-prices.d.ts +8 -0
- package/dist/market-prices.d.ts.map +1 -0
- package/dist/market-prices.js +45 -0
- package/dist/market-prices.js.map +1 -0
- package/dist/native-redemption.d.ts +13 -0
- package/dist/native-redemption.d.ts.map +1 -0
- package/dist/native-redemption.js +154 -0
- package/dist/native-redemption.js.map +1 -0
- package/dist/planner.d.ts +4 -1
- package/dist/planner.d.ts.map +1 -1
- package/dist/planner.js +437 -341
- package/dist/planner.js.map +1 -1
- package/dist/rate-hints.d.ts +8 -0
- package/dist/rate-hints.d.ts.map +1 -0
- package/dist/rate-hints.js +58 -0
- package/dist/rate-hints.js.map +1 -0
- package/dist/types.d.ts +41 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/converters.js
CHANGED
|
@@ -1,94 +1,95 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
7
|
-
import { check as
|
|
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(
|
|
17
|
-
return
|
|
18
|
-
Number.isInteger(
|
|
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
|
-
),
|
|
22
|
+
), n;
|
|
22
23
|
}
|
|
23
|
-
function x(
|
|
24
|
-
const a = C(
|
|
25
|
-
|
|
26
|
-
const
|
|
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:
|
|
29
|
-
input: { coinType:
|
|
30
|
-
expectedOutput: { coinType:
|
|
31
|
-
minOutput: { coinType:
|
|
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:
|
|
34
|
+
data: t
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
43
|
-
|
|
44
|
-
e <=
|
|
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
|
-
),
|
|
48
|
-
Number.isSafeInteger(
|
|
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(
|
|
54
|
-
return p(o, I) && p(
|
|
54
|
+
function V(n, o, i) {
|
|
55
|
+
return p(o, I) && p(i, n) || p(o, n) && p(i, I);
|
|
55
56
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
58
|
-
|
|
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
|
-
),
|
|
62
|
+
), n;
|
|
62
63
|
}
|
|
63
|
-
function C(
|
|
64
|
+
function C(n, o) {
|
|
64
65
|
try {
|
|
65
|
-
return
|
|
66
|
+
return y(n);
|
|
66
67
|
} catch {
|
|
67
|
-
throw new
|
|
68
|
+
throw new Q(o, "Invalid upstream integer amount");
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
71
|
+
function F(n, o) {
|
|
72
|
+
n.moveCall({
|
|
72
73
|
target: `${d.package}::stake_pool::lst_amount_to_sui_amount`,
|
|
73
|
-
arguments: [
|
|
74
|
+
arguments: [n.object(d.pool), n.object(d.metadata), n.pure.u64(o)]
|
|
74
75
|
});
|
|
75
|
-
const
|
|
76
|
+
const i = n.moveCall({
|
|
76
77
|
target: `${d.package}::stake_pool::fee_config`,
|
|
77
|
-
arguments: [
|
|
78
|
+
arguments: [n.object(d.pool)]
|
|
78
79
|
});
|
|
79
|
-
|
|
80
|
+
n.moveCall({ target: `${d.package}::fee_config::unstake_fee_bps`, arguments: [i] });
|
|
80
81
|
}
|
|
81
|
-
function H(
|
|
82
|
+
function H(n, o = 0) {
|
|
82
83
|
try {
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
const e = (
|
|
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: (
|
|
88
|
+
net: (i - e).toString(),
|
|
88
89
|
fees: [
|
|
89
90
|
{
|
|
90
91
|
provider: "volo",
|
|
91
|
-
coinType:
|
|
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
|
|
103
|
-
let
|
|
103
|
+
async function X(n, o) {
|
|
104
|
+
let i;
|
|
104
105
|
try {
|
|
105
|
-
const
|
|
106
|
-
return
|
|
107
|
-
T(
|
|
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
|
-
|
|
110
|
+
i = setTimeout(() => e(void 0), 1500);
|
|
110
111
|
})
|
|
111
112
|
]);
|
|
112
113
|
} catch {
|
|
113
114
|
return;
|
|
114
115
|
} finally {
|
|
115
|
-
|
|
116
|
+
i !== void 0 && clearTimeout(i);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
|
-
function
|
|
119
|
+
function z(n, o) {
|
|
119
120
|
try {
|
|
120
|
-
const
|
|
121
|
-
return p(o.coinIn,
|
|
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
|
|
127
|
-
const o =
|
|
127
|
+
function ae(n = {}) {
|
|
128
|
+
const o = n.client ?? h(), i = {
|
|
128
129
|
id: "volo",
|
|
129
|
-
supports: (
|
|
130
|
-
async quote(
|
|
131
|
-
const e = U(
|
|
132
|
-
|
|
133
|
-
const { object:
|
|
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
|
-
}),
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
const
|
|
140
|
-
return
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
l.object(d.pool),
|
|
145
|
+
l.object(d.metadata),
|
|
146
|
+
l.pure.u64(e.amountIn),
|
|
147
|
+
l.pure.bool(a)
|
|
147
148
|
]
|
|
148
|
-
}),
|
|
149
|
-
},
|
|
150
|
-
a ||
|
|
149
|
+
}), l;
|
|
150
|
+
}, A = m();
|
|
151
|
+
a || F(A, e.amountIn);
|
|
151
152
|
let g;
|
|
152
153
|
try {
|
|
153
|
-
g = await T(o,
|
|
154
|
-
} catch (
|
|
155
|
-
if (a) throw
|
|
156
|
-
g = await T(o,
|
|
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
|
-
|
|
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
|
|
165
|
-
return f && (
|
|
165
|
+
const _ = x("volo", e, b, { version: 1, stake: a });
|
|
166
|
+
return f && (_.fees = f.fees), _;
|
|
166
167
|
},
|
|
167
|
-
async buildPTB(
|
|
168
|
-
|
|
169
|
-
e.converterId === "volo" && V(
|
|
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
|
|
174
|
+
const u = t.moveCall({
|
|
174
175
|
target: `${d.package}::stake_pool::${p(e.input.coinType, I) ? "stake" : "unstake"}`,
|
|
175
|
-
arguments: [
|
|
176
|
+
arguments: [t.object(d.pool), t.object(d.metadata), t.object("0x5"), a]
|
|
176
177
|
});
|
|
177
|
-
return B(
|
|
178
|
+
return B(t, u, e.minOutput.amount), { coinOut: u, change: [] };
|
|
178
179
|
}
|
|
179
180
|
};
|
|
180
|
-
return
|
|
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:
|
|
187
|
-
}),
|
|
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
|
|
190
|
-
const o =
|
|
197
|
+
function re(n = {}) {
|
|
198
|
+
const o = n.client ?? h(), i = {
|
|
191
199
|
id: "haedal",
|
|
192
|
-
supports: (
|
|
193
|
-
async quote(
|
|
194
|
-
const e = U(
|
|
195
|
-
|
|
196
|
-
V(
|
|
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
|
-
),
|
|
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:
|
|
205
|
-
objectId:
|
|
212
|
+
const { object: u } = await o.core.getObject({
|
|
213
|
+
objectId: O.config,
|
|
206
214
|
include: { json: !0 }
|
|
207
|
-
}),
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
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 :
|
|
213
|
-
|
|
214
|
-
const b = a ? null : C(
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
target: `${
|
|
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
|
-
|
|
221
|
-
|
|
228
|
+
l.object(O.config),
|
|
229
|
+
l.pure.u64((a ? _ - _ * g / f : _).toString())
|
|
222
230
|
]
|
|
223
231
|
});
|
|
224
|
-
const
|
|
225
|
-
a || (
|
|
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
|
-
),
|
|
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,
|
|
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:
|
|
243
|
-
amount: ((a ?
|
|
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(
|
|
250
|
-
|
|
251
|
-
e.converterId === "haedal" && V(
|
|
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
|
|
256
|
-
|
|
257
|
-
const
|
|
258
|
-
target: `${
|
|
259
|
-
arguments:
|
|
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(
|
|
269
|
+
return B(t, s, e.minOutput.amount), { coinOut: s, change: [] };
|
|
262
270
|
}
|
|
263
271
|
};
|
|
264
|
-
return
|
|
272
|
+
return i.getStakingSnapshot = M(o, {
|
|
265
273
|
converterId: "haedal",
|
|
266
|
-
packageId:
|
|
267
|
-
pool:
|
|
274
|
+
packageId: O.package,
|
|
275
|
+
pool: O.config,
|
|
268
276
|
coinIn: I,
|
|
269
|
-
coinOut:
|
|
270
|
-
}),
|
|
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
|
|
273
|
-
const o = (
|
|
274
|
-
const e =
|
|
275
|
-
return
|
|
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
|
|
282
|
-
|
|
283
|
-
|
|
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 = (
|
|
288
|
-
|
|
289
|
-
typeof
|
|
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
|
|
294
|
-
return
|
|
295
|
-
|
|
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
|
-
),
|
|
312
|
+
), m;
|
|
299
313
|
};
|
|
300
|
-
a(
|
|
301
|
-
const
|
|
302
|
-
for (const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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: (
|
|
313
|
-
async quote(
|
|
314
|
-
const e = U(
|
|
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
|
|
317
|
-
baseUrl:
|
|
318
|
-
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
(
|
|
335
|
-
(
|
|
345
|
+
(c) => (c.path ?? []).flatMap(
|
|
346
|
+
(s) => typeof s.from == "string" && typeof s.target == "string" ? [
|
|
336
347
|
{
|
|
337
|
-
coinIn:
|
|
338
|
-
coinOut:
|
|
339
|
-
...typeof
|
|
340
|
-
...typeof
|
|
341
|
-
...
|
|
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
|
-
},
|
|
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(
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
|
|
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
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
p(
|
|
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
|
|
365
|
-
|
|
366
|
-
|
|
386
|
+
const A = await G(
|
|
387
|
+
c,
|
|
388
|
+
t,
|
|
367
389
|
o(e.minOutput.amount),
|
|
368
390
|
a,
|
|
369
|
-
|
|
391
|
+
m,
|
|
370
392
|
0,
|
|
371
393
|
!1,
|
|
372
|
-
|
|
373
|
-
{ services:
|
|
394
|
+
n.apiKey,
|
|
395
|
+
{ services: n.services }
|
|
374
396
|
);
|
|
375
|
-
return B(
|
|
397
|
+
return B(t, A, e.minOutput.amount), { coinOut: A, change: [] };
|
|
376
398
|
}
|
|
377
399
|
};
|
|
378
400
|
}
|
|
379
401
|
export {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
402
|
+
ie as astrosConverter,
|
|
403
|
+
re as haedalConverter,
|
|
404
|
+
oe as validateConversion,
|
|
405
|
+
ae as voloConverter
|
|
384
406
|
};
|
|
385
407
|
//# sourceMappingURL=converters.js.map
|