@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.
- package/README.md +53 -0
- package/dist/amounts.d.ts +36 -1
- package/dist/amounts.d.ts.map +1 -1
- package/dist/amounts.js +72 -45
- package/dist/amounts.js.map +1 -1
- package/dist/cap-registry.d.ts +11 -2
- package/dist/cap-registry.d.ts.map +1 -1
- package/dist/cap-registry.js +78 -51
- package/dist/cap-registry.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +437 -375
- package/dist/client.js.map +1 -1
- package/dist/converters.d.ts.map +1 -1
- package/dist/converters.js +221 -204
- package/dist/converters.js.map +1 -1
- package/dist/data-source.d.ts +15 -1
- package/dist/data-source.d.ts.map +1 -1
- package/dist/data-source.js +207 -180
- package/dist/data-source.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -17
- package/dist/native-staking.d.ts +13 -0
- package/dist/native-staking.d.ts.map +1 -0
- package/dist/native-staking.js +157 -0
- package/dist/native-staking.js.map +1 -0
- package/dist/planner.d.ts +3 -3
- package/dist/planner.d.ts.map +1 -1
- package/dist/planner.js +391 -264
- package/dist/planner.js.map +1 -1
- package/dist/types.d.ts +48 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +67 -52
- package/dist/utils.js.map +1 -1
- package/package.json +4 -2
package/dist/client.js
CHANGED
|
@@ -1,208 +1,232 @@
|
|
|
1
|
-
import { validateMarketMode as
|
|
2
|
-
import { voloConverter as
|
|
3
|
-
import { defaultClient as
|
|
4
|
-
import { strategies as
|
|
5
|
-
import { indexRegistryStrategies as
|
|
6
|
-
import { validateAction as
|
|
7
|
-
import { positionSides as
|
|
8
|
-
import { check as
|
|
9
|
-
import { validateFunding as
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
for (const e of [...
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
(e) =>
|
|
1
|
+
import { validateMarketMode as q, assertModeExposure as Ce } from "./emode.js";
|
|
2
|
+
import { voloConverter as Ue, haedalConverter as Le, astrosConverter as De, validateConversion as Re } from "./converters.js";
|
|
3
|
+
import { defaultClient as Ve, createNaviDataSource as Pe } from "./data-source.js";
|
|
4
|
+
import { strategies as je } from "./strategies.js";
|
|
5
|
+
import { indexRegistryStrategies as Me, registryKeyString as S, normalizeCapRegistry as Te, MAINNET_CAP_REGISTRY as Qe, normalizeEnv as $e, assertRegistryUsable as ve, accountCapType as he, registerCreatedCapPTB as Fe } from "./cap-registry.js";
|
|
6
|
+
import { validateAction as be, plan as Be, chooseConversion as Ke, metrics as Y } from "./planner.js";
|
|
7
|
+
import { positionSides as re, atomPrices as Ge, isDustClose as Q, tokenDecimals as D, leverageLimit as Ae, amountCushion as _e, withinLtv as ze, supplyCapacity as qe, borrowCapacity as Ye, withinSameReserveCapacity as He } from "./amounts.js";
|
|
8
|
+
import { check as o, jsonCopy as V, coinType as $, sameCoin as k, address as A, uint as H, BN as y, checksum as P, assertAddressPTB as Xe, minOutputGuard as ce } from "./utils.js";
|
|
9
|
+
import { validateFunding as We } from "./funding.js";
|
|
10
|
+
function rt(T = {}) {
|
|
11
|
+
const F = T.client ?? Ve(), X = T.converters ?? [Ue({ client: F }), Le({ client: F })], W = T.fallbackConverter ?? De({ services: T.services, client: F }), B = /* @__PURE__ */ new Map();
|
|
12
|
+
for (const e of [...X, W])
|
|
13
|
+
o(!B.has(e.id), "INVALID_ARGUMENT", `Duplicate converter id: ${e.id}`), B.set(e.id, e);
|
|
14
|
+
const j = (T.strategies ?? Object.values(je)).map(
|
|
15
|
+
(e) => pe(V(e))
|
|
16
16
|
);
|
|
17
|
-
|
|
18
|
-
new Set(
|
|
17
|
+
o(
|
|
18
|
+
new Set(j.map((e) => e.id)).size === j.length,
|
|
19
19
|
"INVALID_ARGUMENT",
|
|
20
20
|
"Strategy registry contains duplicate ids"
|
|
21
21
|
);
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
[...
|
|
22
|
+
const J = Me(j), se = new Set((T.retiredRegistryKeys ?? []).map(S));
|
|
23
|
+
o(
|
|
24
|
+
[...se].every((e) => !J.has(e)),
|
|
25
25
|
"INVALID_ARGUMENT",
|
|
26
26
|
"Active and retired Registry keys overlap"
|
|
27
27
|
);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
const M = Te(T.capRegistry ?? Qe);
|
|
29
|
+
o(
|
|
30
|
+
!(T.dataSource && T.env !== void 0),
|
|
31
|
+
"INVALID_ARGUMENT",
|
|
32
|
+
"env cannot be combined with a custom dataSource; set env on the data source"
|
|
33
|
+
);
|
|
34
|
+
const h = T.dataSource ?? Pe({
|
|
35
|
+
client: F,
|
|
36
|
+
services: T.services,
|
|
37
|
+
capRegistry: T.capRegistry === void 0 ? void 0 : M,
|
|
38
|
+
strategies: j,
|
|
39
|
+
retiredRegistryKeys: T.retiredRegistryKeys,
|
|
40
|
+
// ST-18: passed through as given; the data source normalizes it (omitted stays omitted, ST-01).
|
|
41
|
+
env: T.env
|
|
42
|
+
}), U = $e(h.env), le = T.capRegistry !== void 0;
|
|
43
|
+
function ue(e = "INVALID_ARGUMENT") {
|
|
44
|
+
o(
|
|
45
|
+
h.capRegistry && JSON.stringify(Te(h.capRegistry)) === JSON.stringify(M),
|
|
38
46
|
e,
|
|
39
47
|
"DataSource Registry deployment differs from the execution deployment"
|
|
40
48
|
);
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
async function
|
|
44
|
-
const t =
|
|
45
|
-
return
|
|
46
|
-
g && await
|
|
47
|
-
|
|
50
|
+
ue();
|
|
51
|
+
async function Z(e, l = "INVALID_ARGUMENT") {
|
|
52
|
+
const t = pe(V(e)), g = J.get(S(t.registryKey));
|
|
53
|
+
return o(
|
|
54
|
+
g && await P(g) === await P(t),
|
|
55
|
+
l,
|
|
48
56
|
"Strategy differs from the configured Registry binding"
|
|
49
57
|
), t;
|
|
50
58
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
59
|
+
function pe(e) {
|
|
60
|
+
o(
|
|
53
61
|
typeof e?.id == "string" && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(e.id),
|
|
54
62
|
"INVALID_ARGUMENT",
|
|
55
63
|
"Strategy id must be a stable ASCII slug"
|
|
56
|
-
),
|
|
64
|
+
), o(
|
|
57
65
|
typeof e.market == "string" && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(e.market),
|
|
58
66
|
"INVALID_ARGUMENT",
|
|
59
67
|
"Missing market"
|
|
60
|
-
),
|
|
68
|
+
), o(
|
|
61
69
|
e.emodeId === void 0 || Number.isSafeInteger(e.emodeId) && e.emodeId >= 0,
|
|
62
70
|
"INVALID_ARGUMENT",
|
|
63
71
|
"E-Mode ID must be a nonnegative safe integer"
|
|
64
|
-
),
|
|
65
|
-
const
|
|
72
|
+
), S(e.registryKey);
|
|
73
|
+
const l = {
|
|
66
74
|
...e,
|
|
67
75
|
registryKey: { ...e.registryKey },
|
|
68
|
-
principalCoinType:
|
|
69
|
-
collateralCoinType:
|
|
70
|
-
debtCoinType:
|
|
76
|
+
principalCoinType: $(e.principalCoinType),
|
|
77
|
+
collateralCoinType: $(e.collateralCoinType),
|
|
78
|
+
debtCoinType: $(e.debtCoinType)
|
|
71
79
|
};
|
|
72
|
-
return
|
|
73
|
-
(
|
|
80
|
+
return o(
|
|
81
|
+
(k(l.principalCoinType, l.debtCoinType) || k(l.principalCoinType, l.collateralCoinType)) && !k(l.collateralCoinType, l.debtCoinType),
|
|
74
82
|
"STRATEGY_UNSUPPORTED",
|
|
75
83
|
"Principal must equal collateral or debt, with distinct collateral and debt"
|
|
76
|
-
),
|
|
77
|
-
|
|
78
|
-
(t) => t ===
|
|
84
|
+
), l.acceptedInputCoinTypes = (l.acceptedInputCoinTypes ?? [l.principalCoinType]).map($), o(
|
|
85
|
+
l.acceptedInputCoinTypes.length > 0 && l.acceptedInputCoinTypes[0] === l.principalCoinType && new Set(l.acceptedInputCoinTypes).size === l.acceptedInputCoinTypes.length && l.acceptedInputCoinTypes.every(
|
|
86
|
+
(t) => t === l.collateralCoinType || t === l.debtCoinType
|
|
79
87
|
),
|
|
80
88
|
"STRATEGY_UNSUPPORTED",
|
|
81
89
|
"Accepted inputs must be distinct strategy assets with principal first"
|
|
82
|
-
),
|
|
90
|
+
), l;
|
|
83
91
|
}
|
|
84
|
-
async function
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
return
|
|
88
|
-
const d =
|
|
89
|
-
return
|
|
90
|
-
|
|
92
|
+
async function x(e) {
|
|
93
|
+
ue("STALE_QUOTE");
|
|
94
|
+
const l = await h.listAccountCaps(e), t = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
95
|
+
return l.map((n) => {
|
|
96
|
+
const d = S(n.registryKey), c = J.get(d), r = A(n.id), b = A(n.accountOwner);
|
|
97
|
+
return o(
|
|
98
|
+
r !== A("0x0") && b !== A("0x0"),
|
|
91
99
|
"INVALID_ACCOUNT_CAP",
|
|
92
100
|
"Zero Cap identity"
|
|
93
|
-
),
|
|
94
|
-
!t.has(d) && !g.has(
|
|
101
|
+
), o(
|
|
102
|
+
!t.has(d) && !g.has(r) && !a.has(b),
|
|
95
103
|
"DUPLICATE_ACCOUNT_CAP",
|
|
96
104
|
"Duplicate strategy, Cap or lending account in Registry"
|
|
97
|
-
), t.add(d), g.add(
|
|
98
|
-
|
|
105
|
+
), t.add(d), g.add(r), a.add(b), se.has(d) ? null : (o(c, "UNSUPPORTED_REGISTRY_STRATEGY", "Unknown registered Multiply strategy"), o(
|
|
106
|
+
c.id === n.strategyId,
|
|
99
107
|
"INVALID_ACCOUNT_CAP",
|
|
100
108
|
"Cap numeric binding differs from strategy ID"
|
|
101
|
-
),
|
|
102
|
-
|
|
109
|
+
), o(
|
|
110
|
+
n.transient === void 0 || n.transient === !0,
|
|
111
|
+
"INVALID_ACCOUNT_CAP",
|
|
112
|
+
"Cap transient marker must be true or absent"
|
|
113
|
+
), { ...n, id: r, accountOwner: b, registryKey: { ...n.registryKey } });
|
|
114
|
+
}).filter((n) => n !== null);
|
|
103
115
|
}
|
|
104
|
-
function
|
|
105
|
-
const t =
|
|
106
|
-
return e.find((g) =>
|
|
116
|
+
function ee(e, l) {
|
|
117
|
+
const t = S(l.registryKey);
|
|
118
|
+
return e.find((g) => S(g.registryKey) === t);
|
|
107
119
|
}
|
|
108
|
-
async function
|
|
109
|
-
e =
|
|
110
|
-
const t = [], g = await
|
|
111
|
-
for (const
|
|
112
|
-
const
|
|
120
|
+
async function Ie(e, l = {}) {
|
|
121
|
+
e = A(e);
|
|
122
|
+
const t = [], g = await x(e);
|
|
123
|
+
for (const a of l.strategy ? [l.strategy] : j) {
|
|
124
|
+
const n = await Z(a), d = ee(g, n);
|
|
113
125
|
if (!d) continue;
|
|
114
|
-
const
|
|
115
|
-
|
|
126
|
+
const c = await h.readMarket(n), r = await h.readPosition(d, n, c);
|
|
127
|
+
q(n, c), H(r.collateralAmount), H(r.debtAmount), t.push({
|
|
116
128
|
address: e,
|
|
117
|
-
strategy:
|
|
129
|
+
strategy: n,
|
|
118
130
|
accountCap: d,
|
|
119
|
-
...
|
|
120
|
-
...
|
|
131
|
+
...r,
|
|
132
|
+
...Y(r, c)
|
|
121
133
|
});
|
|
122
134
|
}
|
|
123
135
|
return t;
|
|
124
136
|
}
|
|
125
|
-
async function
|
|
126
|
-
e =
|
|
127
|
-
const
|
|
137
|
+
async function we(e, l, t, g) {
|
|
138
|
+
e = A(e), o(e !== A("0x0"), "INVALID_ARGUMENT", "Multiply owner cannot be zero"), be(t, g);
|
|
139
|
+
const a = await Z(l);
|
|
128
140
|
if (t.type === "open" || t.type === "add_principal") {
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
const m = $(t.inputCoinType ?? a.principalCoinType);
|
|
142
|
+
o(
|
|
143
|
+
a.acceptedInputCoinTypes.includes(m),
|
|
132
144
|
"UNSUPPORTED_INPUT_COIN",
|
|
133
145
|
"Input coin is not accepted by this strategy"
|
|
134
|
-
), t = { ...t, inputCoinType:
|
|
146
|
+
), t = { ...t, inputCoinType: m };
|
|
135
147
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
const n = ee(await x(e), a);
|
|
149
|
+
o(
|
|
150
|
+
n || t.type === "open",
|
|
139
151
|
"POSITION_NOT_FOUND",
|
|
140
152
|
"Only open may create a Multiply Cap"
|
|
141
153
|
);
|
|
142
|
-
const d = await h.readMarket(
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
154
|
+
const d = await h.readMarket(a);
|
|
155
|
+
q(a, d);
|
|
156
|
+
const c = n ? await h.readPosition(n, a, d) : { collateralAmount: "0", debtAmount: "0" };
|
|
157
|
+
H(c.collateralAmount), H(c.debtAmount);
|
|
158
|
+
const r = n ? re(c, d) : { collateral: !1, debt: !1 }, b = !r.collateral && !r.debt;
|
|
159
|
+
if (o(
|
|
148
160
|
t.type !== "open" || b,
|
|
149
161
|
"POSITION_EXISTS",
|
|
150
162
|
"Use add_principal or set_leverage for an existing position"
|
|
151
|
-
),
|
|
163
|
+
), o(
|
|
152
164
|
t.type === "open" || !b,
|
|
153
165
|
"POSITION_NOT_FOUND",
|
|
154
166
|
"Empty position; use open to reuse this Cap"
|
|
155
167
|
), "targetLeverage" in t && t.targetLeverage) {
|
|
156
|
-
const
|
|
157
|
-
new
|
|
158
|
-
),
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
const m = new y(d.liquidationThreshold).div(
|
|
169
|
+
new y(d.borrowWeight).times(g.minHealthFactor)
|
|
170
|
+
), L = new y(1).minus(new y(1).div(t.targetLeverage)), N = Ge(d), te = !["open", "add_principal"].includes(t.type) && L.times(c.collateralAmount).times(N.collateral).lte(new y(c.debtAmount).times(N.debt));
|
|
171
|
+
o(
|
|
172
|
+
L.lte(m) && (L.lte(new y(d.ltv).div(d.borrowWeight)) || te),
|
|
161
173
|
"CONSTRAINT_VIOLATION",
|
|
162
174
|
"Target leverage exceeds protocol or health factor limits"
|
|
163
175
|
);
|
|
164
176
|
}
|
|
165
|
-
const
|
|
166
|
-
|
|
177
|
+
const u = await h.readBorrowFeeBps(d, n?.accountOwner), _ = { coinIn: a.debtCoinType, coinOut: a.collateralCoinType }, O = X.filter((m) => m.supports(_.coinIn, _.coinOut)), i = O.length === 0 ? W : O.length === 1 ? O[0] : void 0, I = await Be(
|
|
178
|
+
a,
|
|
167
179
|
t,
|
|
168
180
|
g,
|
|
169
|
-
|
|
181
|
+
c,
|
|
170
182
|
d,
|
|
171
|
-
|
|
172
|
-
(
|
|
173
|
-
|
|
183
|
+
u,
|
|
184
|
+
(m) => Ke(m, X, W),
|
|
185
|
+
i?.getRateHint ? () => i.getRateHint(_) : void 0,
|
|
186
|
+
i?.getStakingSnapshot ? async () => {
|
|
187
|
+
const m = await i.getStakingSnapshot(_);
|
|
188
|
+
return m && o(
|
|
189
|
+
m.converterId === i.id,
|
|
190
|
+
"INVALID_CONVERSION",
|
|
191
|
+
"Native snapshot provider mismatch"
|
|
192
|
+
), m;
|
|
193
|
+
} : void 0
|
|
194
|
+
);
|
|
195
|
+
n || (ve(U, le), he(U));
|
|
196
|
+
const w = {
|
|
174
197
|
address: e,
|
|
175
|
-
strategy:
|
|
176
|
-
action:
|
|
177
|
-
constraints:
|
|
198
|
+
strategy: a,
|
|
199
|
+
action: V(t),
|
|
200
|
+
constraints: V(g),
|
|
178
201
|
expiresAt: Math.min(
|
|
179
202
|
Date.now() + 12e4,
|
|
180
|
-
...I.execution.conversions.map((
|
|
203
|
+
...I.execution.conversions.map((m) => m.expiresAt)
|
|
181
204
|
),
|
|
182
205
|
estimate: I.estimate,
|
|
183
206
|
execution: {
|
|
184
207
|
...I.execution,
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
env: U,
|
|
209
|
+
capRegistry: { ...M },
|
|
210
|
+
accountCap: n ? { kind: "existing", ...n } : { kind: "create", registryKey: { ...a.registryKey } },
|
|
187
211
|
checksum: ""
|
|
188
212
|
}
|
|
189
213
|
};
|
|
190
|
-
return
|
|
214
|
+
return w.execution.checksum = await P(w), V(w);
|
|
191
215
|
}
|
|
192
|
-
async function
|
|
193
|
-
const t = e.execution, g = e.strategy,
|
|
194
|
-
t.accountCap.kind === "create" ?
|
|
195
|
-
!
|
|
216
|
+
async function Ee(e, l) {
|
|
217
|
+
const t = e.execution, g = e.strategy, a = ee(await x(e.address), g);
|
|
218
|
+
t.accountCap.kind === "create" ? o(
|
|
219
|
+
!a && !l.accountCap,
|
|
196
220
|
"STALE_QUOTE",
|
|
197
221
|
"Cap was created since quote or an unexpected Cap was supplied"
|
|
198
|
-
) : (
|
|
199
|
-
|
|
222
|
+
) : (o(
|
|
223
|
+
a && a.id === t.accountCap.id && a.accountOwner === t.accountCap.accountOwner,
|
|
200
224
|
"STALE_QUOTE",
|
|
201
225
|
"AccountCap changed since quote"
|
|
202
|
-
), typeof
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
for (const
|
|
226
|
+
), typeof l.accountCap == "string" && o(A(l.accountCap) === A(a.id), "INVALID_INPUTS", "Wrong AccountCap"));
|
|
227
|
+
const n = await h.readMarket(g);
|
|
228
|
+
q(g, n), Ce(e.action, e.execution, n);
|
|
229
|
+
for (const i of [
|
|
206
230
|
"package",
|
|
207
231
|
"storage",
|
|
208
232
|
"priceOracle",
|
|
@@ -210,365 +234,397 @@ function We(w = {}) {
|
|
|
210
234
|
"incentiveV3",
|
|
211
235
|
"limter"
|
|
212
236
|
])
|
|
213
|
-
n
|
|
214
|
-
|
|
215
|
-
|
|
237
|
+
o(n.config[i] === t.market.config[i], "STALE_QUOTE", `Market ${i} changed`);
|
|
238
|
+
o(
|
|
239
|
+
n.collateral.contract.pool === t.market.collateral.contract.pool && n.debt.contract.pool === t.market.debt.contract.pool && n.flash.poolId === t.market.flash.poolId && D(n.collateral) === D(t.market.collateral) && D(n.debt) === D(t.market.debt),
|
|
216
240
|
"STALE_QUOTE",
|
|
217
241
|
"Pool configuration changed"
|
|
218
242
|
);
|
|
219
|
-
const d =
|
|
220
|
-
if (
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
e.action.type === "open" == (!
|
|
243
|
+
const d = a ? await h.readPosition(a, g, n) : { collateralAmount: "0", debtAmount: "0" };
|
|
244
|
+
if (a) {
|
|
245
|
+
const i = re(d, n);
|
|
246
|
+
if (o(
|
|
247
|
+
e.action.type === "open" == (!i.collateral && !i.debt),
|
|
224
248
|
"STALE_QUOTE",
|
|
225
249
|
"Position no longer satisfies the action"
|
|
226
250
|
), e.action.type !== "open") {
|
|
227
|
-
|
|
228
|
-
t.snapshot.protocolCollateralAmount !== void 0 ||
|
|
251
|
+
o(
|
|
252
|
+
t.snapshot.protocolCollateralAmount !== void 0 || D(n.collateral) >= 9 || t.snapshot.collateralAmount !== "0",
|
|
229
253
|
"STALE_QUOTE",
|
|
230
254
|
"Quote lacks precise collateral state"
|
|
231
255
|
);
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
256
|
+
const I = re(t.snapshot, n);
|
|
257
|
+
o(
|
|
258
|
+
I.collateral === i.collateral && I.debt === i.debt,
|
|
235
259
|
"STALE_QUOTE",
|
|
236
260
|
"Position crossed a zero balance"
|
|
237
261
|
);
|
|
238
262
|
}
|
|
239
|
-
e.action.type === "close" &&
|
|
240
|
-
|
|
263
|
+
e.action.type === "close" && Q(g, t.snapshot, n) && o(
|
|
264
|
+
Q(g, d, n),
|
|
241
265
|
"STALE_QUOTE",
|
|
242
266
|
"Collateral became transferable; request a new quote"
|
|
243
267
|
);
|
|
244
268
|
}
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
new
|
|
249
|
-
) &&
|
|
250
|
-
new
|
|
269
|
+
const c = new y(d.collateralAmount).minus(t.snapshot.collateralAmount), r = new y(d.debtAmount).minus(t.snapshot.debtAmount);
|
|
270
|
+
o(
|
|
271
|
+
c.gte(0) && c.lte(
|
|
272
|
+
new y(t.snapshot.collateralAmount).times("0.0001").plus(_e(n.collateral))
|
|
273
|
+
) && r.gte(0) && r.lte(
|
|
274
|
+
new y(t.snapshot.debtAmount).times("0.0001").plus(_e(n.debt))
|
|
251
275
|
),
|
|
252
276
|
"STALE_QUOTE",
|
|
253
277
|
"Position changed since quote"
|
|
254
278
|
);
|
|
255
|
-
const b = await h.readBorrowFeeBps(
|
|
256
|
-
|
|
257
|
-
new
|
|
279
|
+
const b = await h.readBorrowFeeBps(n, a?.accountOwner);
|
|
280
|
+
o(
|
|
281
|
+
new y(t.borrowAmount).times(b).div(1e4).integerValue().lte(t.borrowFee),
|
|
258
282
|
"STALE_QUOTE",
|
|
259
283
|
"Borrow fee increased"
|
|
260
|
-
), n
|
|
261
|
-
const
|
|
262
|
-
collateralAmount: new
|
|
263
|
-
debtAmount: new
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
|
|
284
|
+
), o(n.flash.feeBps === t.market.flash.feeBps, "STALE_QUOTE", "Flash fee changed");
|
|
285
|
+
const u = {
|
|
286
|
+
collateralAmount: new y(t.minCollateralAfter).plus(c).toFixed(0),
|
|
287
|
+
debtAmount: new y(t.debtAfter).plus(e.action.type === "close" ? 0 : r).toFixed(0)
|
|
288
|
+
}, _ = Y(u, n);
|
|
289
|
+
o(
|
|
290
|
+
_.healthFactor === null || new y(_.healthFactor).gte(e.constraints.minHealthFactor),
|
|
267
291
|
"STALE_QUOTE",
|
|
268
292
|
"Updated market no longer satisfies HF"
|
|
269
|
-
),
|
|
270
|
-
Number.isSafeInteger(
|
|
293
|
+
), o(
|
|
294
|
+
Number.isSafeInteger(n.observedAt) && Date.now() - n.observedAt <= 12e4,
|
|
271
295
|
"STALE_QUOTE",
|
|
272
296
|
"Current market snapshot is stale"
|
|
273
|
-
)
|
|
274
|
-
|
|
297
|
+
);
|
|
298
|
+
const O = Ae(
|
|
299
|
+
e.constraints.maxLeverage,
|
|
300
|
+
e.action,
|
|
301
|
+
t.direction,
|
|
302
|
+
Y(d, n).leverage
|
|
303
|
+
);
|
|
304
|
+
return O && _.leverage && o(
|
|
305
|
+
new y(_.leverage).lte(O),
|
|
275
306
|
"STALE_QUOTE",
|
|
276
307
|
"Updated market exceeds maximum leverage"
|
|
277
|
-
),
|
|
278
|
-
|
|
308
|
+
), o(
|
|
309
|
+
ze(u, d, n, t.direction !== "increase"),
|
|
279
310
|
"STALE_QUOTE",
|
|
280
311
|
"Updated market exceeds LTV"
|
|
281
|
-
),
|
|
282
|
-
new
|
|
312
|
+
), o(
|
|
313
|
+
new y(t.flashAmount).lte(n.flash.max) && (t.flashAmount === "0" || new y(t.flashAmount).gte(n.flash.min)),
|
|
283
314
|
"CAPACITY_EXCEEDED",
|
|
284
315
|
"Flash capacity changed"
|
|
285
|
-
),
|
|
286
|
-
new
|
|
316
|
+
), o(
|
|
317
|
+
new y(t.collateralAfter).minus(t.snapshot.collateralAmount).lte(qe(n)),
|
|
287
318
|
"CAPACITY_EXCEEDED",
|
|
288
319
|
"Supply capacity changed"
|
|
289
|
-
),
|
|
290
|
-
new
|
|
320
|
+
), o(
|
|
321
|
+
new y(t.borrowAmount).plus(t.borrowFee).lte(Ye(n)),
|
|
291
322
|
"CAPACITY_EXCEEDED",
|
|
292
323
|
"Borrow liquidity changed"
|
|
293
|
-
),
|
|
324
|
+
), o(
|
|
325
|
+
He(g, t, n),
|
|
326
|
+
"CAPACITY_EXCEEDED",
|
|
327
|
+
"Flash and borrow from the same reserve exceed its cash"
|
|
328
|
+
), { fresh: n, now: d };
|
|
294
329
|
}
|
|
295
|
-
async function
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
330
|
+
async function de(e, l, t, g) {
|
|
331
|
+
const a = V(l);
|
|
332
|
+
o(
|
|
333
|
+
a.execution?.version === 4,
|
|
299
334
|
"INVALID_QUOTE",
|
|
300
335
|
"Unknown quote version; request a fresh quote"
|
|
301
336
|
);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
337
|
+
const n = a.execution.checksum;
|
|
338
|
+
a.execution.checksum = "", o(
|
|
339
|
+
n === await P(a),
|
|
305
340
|
"INVALID_QUOTE",
|
|
306
341
|
"Quote contents have changed; request a fresh quote"
|
|
307
|
-
),
|
|
308
|
-
|
|
342
|
+
), a.execution.checksum = n, o(
|
|
343
|
+
a.execution.env !== void 0,
|
|
344
|
+
"INVALID_QUOTE",
|
|
345
|
+
"Quote has no NAVI env (made by an older SDK); request a fresh quote"
|
|
346
|
+
), o(
|
|
347
|
+
a.execution.env === U,
|
|
348
|
+
"INVALID_QUOTE",
|
|
349
|
+
`Quote was made for NAVI env ${String(a.execution.env)}; this client targets ${U}`
|
|
350
|
+
), o(
|
|
351
|
+
Number.isSafeInteger(a.expiresAt) && a.expiresAt > Date.now(),
|
|
309
352
|
"QUOTE_EXPIRED",
|
|
310
353
|
"Multiply quote expired"
|
|
311
|
-
),
|
|
312
|
-
|
|
354
|
+
), o(
|
|
355
|
+
A(a.address) !== A("0x0"),
|
|
313
356
|
"INVALID_ARGUMENT",
|
|
314
357
|
"Multiply owner cannot be zero"
|
|
315
|
-
), await
|
|
316
|
-
await
|
|
358
|
+
), await Z(a.strategy, "STALE_QUOTE"), o(
|
|
359
|
+
await P(a.execution.capRegistry) === await P(M),
|
|
317
360
|
"STALE_QUOTE",
|
|
318
361
|
"Registry deployment changed since quote"
|
|
319
|
-
),
|
|
320
|
-
|
|
362
|
+
), o(
|
|
363
|
+
S(a.execution.accountCap.registryKey) === S(a.strategy.registryKey),
|
|
321
364
|
"INVALID_QUOTE",
|
|
322
365
|
"Quote Cap key differs from strategy"
|
|
323
366
|
);
|
|
324
367
|
const d = e.getData().sender;
|
|
325
|
-
|
|
326
|
-
!d ||
|
|
368
|
+
o(
|
|
369
|
+
!d || A(d) === A(a.address),
|
|
327
370
|
"INVALID_INPUTS",
|
|
328
371
|
"Transaction sender differs from quote wallet"
|
|
329
|
-
),
|
|
330
|
-
const
|
|
331
|
-
|
|
372
|
+
), be(a.action, a.constraints);
|
|
373
|
+
const c = a.execution, r = a.strategy;
|
|
374
|
+
We(a);
|
|
332
375
|
const b = t.coins ?? [];
|
|
333
|
-
|
|
334
|
-
b.length ===
|
|
376
|
+
o(
|
|
377
|
+
b.length === a.estimate.inputs.length,
|
|
335
378
|
"INVALID_INPUTS",
|
|
336
379
|
"Provide exactly the quoted input coins"
|
|
337
380
|
);
|
|
338
|
-
for (const
|
|
339
|
-
|
|
340
|
-
b.filter((
|
|
381
|
+
for (const s of a.estimate.inputs)
|
|
382
|
+
o(
|
|
383
|
+
b.filter((p) => k(p.coinType, s.coinType)).length === 1,
|
|
341
384
|
"INVALID_INPUTS",
|
|
342
|
-
`Missing or duplicate input: ${
|
|
385
|
+
`Missing or duplicate input: ${s.coinType}`
|
|
343
386
|
);
|
|
344
|
-
for (const
|
|
345
|
-
|
|
346
|
-
|
|
387
|
+
for (const s of c.conversions)
|
|
388
|
+
o(
|
|
389
|
+
B.has(s.converterId),
|
|
347
390
|
"INVALID_CONVERSION",
|
|
348
391
|
"Quoted converter is not configured"
|
|
349
|
-
),
|
|
350
|
-
|
|
392
|
+
), Re(
|
|
393
|
+
s,
|
|
351
394
|
{
|
|
352
|
-
coinIn:
|
|
353
|
-
coinOut:
|
|
354
|
-
amountIn:
|
|
355
|
-
slippageBps:
|
|
395
|
+
coinIn: s.input.coinType,
|
|
396
|
+
coinOut: s.expectedOutput.coinType,
|
|
397
|
+
amountIn: s.input.amount,
|
|
398
|
+
slippageBps: a.constraints.maxSlippageBps
|
|
356
399
|
},
|
|
357
|
-
|
|
400
|
+
s.converterId
|
|
358
401
|
);
|
|
359
|
-
const { fresh:
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
402
|
+
const { fresh: u, now: _ } = g ? { fresh: c.market, now: c.snapshot } : await Ee(a, t);
|
|
403
|
+
q(r, u), Ce(a.action, c, u), c.accountCap.kind === "create" && ve(U, le);
|
|
404
|
+
const O = c.accountCap.kind === "existing" && c.accountCap.transient === !0;
|
|
405
|
+
o(
|
|
406
|
+
!O || t.accountCap !== void 0,
|
|
407
|
+
"INVALID_INPUTS",
|
|
408
|
+
"A transient AccountCap must be supplied as a transaction argument"
|
|
409
|
+
), e.setSenderIfNotSet(a.address), await h.prepareOracle(e, r, u);
|
|
410
|
+
const i = u.config, I = c.accountCap.kind === "create" ? e.moveCall({ target: `${i.package}::lending::create_account` }) : void 0, w = I ?? t.accountCap ?? e.object(c.accountCap.id);
|
|
411
|
+
c.accountCap.kind === "existing" && t.accountCap !== void 0 && !O && Xe(
|
|
412
|
+
e,
|
|
413
|
+
e.moveCall({
|
|
414
|
+
target: `${i.package}::account::account_owner`,
|
|
415
|
+
arguments: [w]
|
|
416
|
+
}),
|
|
417
|
+
c.accountCap.accountOwner
|
|
418
|
+
), I && (r.emodeId !== void 0 && e.moveCall({
|
|
419
|
+
target: `${i.package}::lending::enter_emode_with_account_cap`,
|
|
420
|
+
arguments: [e.object(i.storage), e.pure.u64(r.emodeId), I]
|
|
421
|
+
}), Fe(e, I, r.registryKey, M, he(U)));
|
|
422
|
+
const m = [], L = (s, p) => {
|
|
423
|
+
const C = b.find((R) => k(R.coinType, s)), f = e.splitCoins(C.coin, [p])[0];
|
|
424
|
+
return m.push(C), f;
|
|
425
|
+
}, N = (s, p) => e.moveCall({
|
|
370
426
|
target: "0x2::coin::from_balance",
|
|
371
|
-
typeArguments: [
|
|
372
|
-
arguments: [
|
|
373
|
-
}),
|
|
374
|
-
target: `${
|
|
375
|
-
typeArguments: [
|
|
427
|
+
typeArguments: [p],
|
|
428
|
+
arguments: [s]
|
|
429
|
+
}), te = (s, p) => e.moveCall({ target: "0x2::coin::into_balance", typeArguments: [p], arguments: [s] }), ae = (s) => e.moveCall({
|
|
430
|
+
target: `${i.package}::incentive_v3::deposit_with_account_cap`,
|
|
431
|
+
typeArguments: [r.collateralCoinType],
|
|
376
432
|
arguments: [
|
|
377
433
|
e.object("0x6"),
|
|
378
|
-
e.object(
|
|
379
|
-
e.object(
|
|
380
|
-
e.pure.u8(
|
|
381
|
-
|
|
382
|
-
e.object(
|
|
383
|
-
e.object(
|
|
384
|
-
|
|
434
|
+
e.object(i.storage),
|
|
435
|
+
e.object(u.collateral.contract.pool),
|
|
436
|
+
e.pure.u8(u.collateral.id),
|
|
437
|
+
s,
|
|
438
|
+
e.object(i.incentiveV2),
|
|
439
|
+
e.object(i.incentiveV3),
|
|
440
|
+
w
|
|
385
441
|
]
|
|
386
|
-
}),
|
|
442
|
+
}), ge = (s) => N(
|
|
387
443
|
e.moveCall({
|
|
388
|
-
target: `${
|
|
389
|
-
typeArguments: [
|
|
444
|
+
target: `${i.package}::incentive_v3::repay_with_account_cap`,
|
|
445
|
+
typeArguments: [r.debtCoinType],
|
|
390
446
|
arguments: [
|
|
391
447
|
e.object("0x6"),
|
|
392
|
-
e.object(
|
|
393
|
-
e.object(
|
|
394
|
-
e.object(
|
|
395
|
-
e.pure.u8(
|
|
396
|
-
|
|
397
|
-
e.object(
|
|
398
|
-
e.object(
|
|
399
|
-
|
|
448
|
+
e.object(i.priceOracle),
|
|
449
|
+
e.object(i.storage),
|
|
450
|
+
e.object(u.debt.contract.pool),
|
|
451
|
+
e.pure.u8(u.debt.id),
|
|
452
|
+
s,
|
|
453
|
+
e.object(i.incentiveV2),
|
|
454
|
+
e.object(i.incentiveV3),
|
|
455
|
+
w
|
|
400
456
|
]
|
|
401
457
|
}),
|
|
402
|
-
|
|
458
|
+
r.debtCoinType
|
|
403
459
|
);
|
|
404
|
-
let
|
|
405
|
-
if (
|
|
406
|
-
const
|
|
407
|
-
target: `${
|
|
408
|
-
typeArguments: [
|
|
460
|
+
let K, G;
|
|
461
|
+
if (c.flashAmount !== "0") {
|
|
462
|
+
const s = e.moveCall({
|
|
463
|
+
target: `${u.flash.config.package}::lending::flash_loan_with_ctx_v2`,
|
|
464
|
+
typeArguments: [r.debtCoinType],
|
|
409
465
|
arguments: [
|
|
410
|
-
e.object(
|
|
411
|
-
e.object(
|
|
412
|
-
e.pure.u64(
|
|
466
|
+
e.object(u.flash.config.flashloanConfig),
|
|
467
|
+
e.object(u.flash.poolId),
|
|
468
|
+
e.pure.u64(c.flashAmount),
|
|
413
469
|
e.object("0x5")
|
|
414
470
|
]
|
|
415
471
|
});
|
|
416
|
-
|
|
472
|
+
K = N(s[0], r.debtCoinType), G = s[1];
|
|
417
473
|
}
|
|
418
|
-
const
|
|
474
|
+
const me = (s) => G ? N(
|
|
419
475
|
e.moveCall({
|
|
420
|
-
target: `${
|
|
421
|
-
typeArguments: [
|
|
476
|
+
target: `${u.flash.config.package}::lending::flash_repay_with_ctx`,
|
|
477
|
+
typeArguments: [r.debtCoinType],
|
|
422
478
|
arguments: [
|
|
423
479
|
e.object("0x6"),
|
|
424
|
-
e.object(
|
|
425
|
-
e.object(
|
|
426
|
-
|
|
427
|
-
|
|
480
|
+
e.object(u.flash.config.storage),
|
|
481
|
+
e.object(u.flash.poolId),
|
|
482
|
+
G,
|
|
483
|
+
te(s, r.debtCoinType)
|
|
428
484
|
]
|
|
429
485
|
}),
|
|
430
|
-
|
|
431
|
-
) :
|
|
432
|
-
const C = await
|
|
433
|
-
changeRecipient:
|
|
486
|
+
r.debtCoinType
|
|
487
|
+
) : s, ye = async (s, p) => {
|
|
488
|
+
const C = await B.get(p.converterId).buildPTB(e, p, s, {
|
|
489
|
+
changeRecipient: a.address
|
|
434
490
|
});
|
|
435
|
-
return
|
|
491
|
+
return ce(e, C.coinOut, p.minOutput.amount), m.push(...C.change), C.coinOut;
|
|
436
492
|
};
|
|
437
|
-
if (
|
|
438
|
-
|
|
439
|
-
coinType:
|
|
440
|
-
coin:
|
|
493
|
+
if (c.direction === "repay")
|
|
494
|
+
m.push({
|
|
495
|
+
coinType: r.debtCoinType,
|
|
496
|
+
coin: ge(L(r.debtCoinType, a.estimate.inputs[0].amount))
|
|
441
497
|
});
|
|
442
|
-
else if (
|
|
443
|
-
|
|
444
|
-
else if (
|
|
445
|
-
let
|
|
446
|
-
if (
|
|
447
|
-
const
|
|
448
|
-
|
|
498
|
+
else if (c.direction === "add_collateral")
|
|
499
|
+
ae(L(r.collateralCoinType, a.estimate.inputs[0].amount));
|
|
500
|
+
else if (c.direction === "increase") {
|
|
501
|
+
let s = K;
|
|
502
|
+
if (c.funding.kind !== "none") {
|
|
503
|
+
const p = L(c.funding.input.coinType, c.funding.input.amount);
|
|
504
|
+
c.funding.kind === "collateral" ? ae(p) : s ? e.mergeCoins(s, [p]) : s = p;
|
|
449
505
|
}
|
|
450
|
-
for (const
|
|
451
|
-
|
|
452
|
-
if (
|
|
453
|
-
const
|
|
454
|
-
target: `${
|
|
455
|
-
typeArguments: [
|
|
506
|
+
for (const p of c.conversions)
|
|
507
|
+
o(s, "INVALID_QUOTE", "Missing conversion funding"), ae(await ye(s, p)), s = void 0;
|
|
508
|
+
if (G) {
|
|
509
|
+
const p = e.moveCall({
|
|
510
|
+
target: `${i.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
511
|
+
typeArguments: [r.debtCoinType],
|
|
456
512
|
arguments: [
|
|
457
513
|
e.object("0x6"),
|
|
458
|
-
e.object(
|
|
459
|
-
e.object(
|
|
460
|
-
e.object(
|
|
461
|
-
e.pure.u8(
|
|
462
|
-
e.pure.u64(
|
|
463
|
-
e.object(
|
|
464
|
-
e.object(
|
|
465
|
-
|
|
514
|
+
e.object(i.priceOracle),
|
|
515
|
+
e.object(i.storage),
|
|
516
|
+
e.object(u.debt.contract.pool),
|
|
517
|
+
e.pure.u8(u.debt.id),
|
|
518
|
+
e.pure.u64(c.borrowAmount),
|
|
519
|
+
e.object(i.incentiveV2),
|
|
520
|
+
e.object(i.incentiveV3),
|
|
521
|
+
w,
|
|
466
522
|
e.object("0x5")
|
|
467
523
|
]
|
|
468
524
|
});
|
|
469
|
-
|
|
525
|
+
m.push({ coinType: r.debtCoinType, coin: me(N(p, r.debtCoinType)) });
|
|
470
526
|
}
|
|
471
527
|
} else {
|
|
472
|
-
const
|
|
473
|
-
let
|
|
474
|
-
|
|
528
|
+
const s = K ? ge(K) : void 0;
|
|
529
|
+
let p = e.pure.u64(
|
|
530
|
+
c.withdrawAmount
|
|
475
531
|
);
|
|
476
|
-
if (
|
|
477
|
-
const
|
|
478
|
-
target: `${
|
|
479
|
-
arguments: [
|
|
532
|
+
if (a.action.type === "close") {
|
|
533
|
+
const v = e.moveCall({
|
|
534
|
+
target: `${i.package}::account::account_owner`,
|
|
535
|
+
arguments: [w]
|
|
480
536
|
});
|
|
481
537
|
e.moveCall({
|
|
482
|
-
target: `${
|
|
483
|
-
arguments: [e.object("0x6"), e.object(
|
|
538
|
+
target: `${i.package}::lending::update_state_of_user`,
|
|
539
|
+
arguments: [e.object("0x6"), e.object(i.storage), v]
|
|
484
540
|
});
|
|
485
|
-
const
|
|
486
|
-
target: `${
|
|
487
|
-
arguments: [e.object(
|
|
541
|
+
const E = e.moveCall({
|
|
542
|
+
target: `${i.package}::logic::user_collateral_balance`,
|
|
543
|
+
arguments: [e.object(i.storage), e.pure.u8(u.collateral.id), v]
|
|
488
544
|
});
|
|
489
|
-
if (
|
|
490
|
-
for (const [
|
|
491
|
-
[
|
|
492
|
-
[e.pure.u256("999"),
|
|
545
|
+
if (Q(r, c.snapshot, u))
|
|
546
|
+
for (const [ie, Se] of [
|
|
547
|
+
[E, e.pure.u256("1")],
|
|
548
|
+
[e.pure.u256("999"), E]
|
|
493
549
|
]) {
|
|
494
|
-
const
|
|
550
|
+
const ke = e.moveCall({
|
|
495
551
|
target: "0x1::u256::checked_sub",
|
|
496
|
-
arguments: [
|
|
552
|
+
arguments: [ie, Se]
|
|
497
553
|
});
|
|
498
554
|
e.moveCall({
|
|
499
555
|
target: "0x1::option::destroy_some",
|
|
500
556
|
typeArguments: ["u256"],
|
|
501
|
-
arguments: [
|
|
557
|
+
arguments: [ke]
|
|
502
558
|
});
|
|
503
559
|
}
|
|
504
|
-
const
|
|
505
|
-
if (
|
|
560
|
+
const ne = e.moveCall({ target: "0x1::u256::try_as_u64", arguments: [E] });
|
|
561
|
+
if (p = e.moveCall({
|
|
506
562
|
target: "0x1::option::destroy_some",
|
|
507
563
|
typeArguments: ["u64"],
|
|
508
|
-
arguments: [
|
|
509
|
-
}),
|
|
510
|
-
target: `${
|
|
511
|
-
typeArguments: [
|
|
512
|
-
arguments: [e.object(
|
|
513
|
-
}),
|
|
514
|
-
const
|
|
564
|
+
arguments: [ne]
|
|
565
|
+
}), D(u.collateral) !== 9 && (p = e.moveCall({
|
|
566
|
+
target: `${i.package}::pool::unnormal_amount`,
|
|
567
|
+
typeArguments: [r.collateralCoinType],
|
|
568
|
+
arguments: [e.object(u.collateral.contract.pool), p]
|
|
569
|
+
}), D(u.collateral) < 9)) {
|
|
570
|
+
const ie = e.moveCall({
|
|
515
571
|
target: "0x1::u64::checked_add",
|
|
516
|
-
arguments: [
|
|
572
|
+
arguments: [p, e.pure.u64("1")]
|
|
517
573
|
});
|
|
518
|
-
|
|
574
|
+
p = e.moveCall({
|
|
519
575
|
target: "0x1::option::destroy_some",
|
|
520
576
|
typeArguments: ["u64"],
|
|
521
|
-
arguments: [
|
|
577
|
+
arguments: [ie]
|
|
522
578
|
});
|
|
523
579
|
}
|
|
524
580
|
}
|
|
525
|
-
const C =
|
|
581
|
+
const C = N(
|
|
526
582
|
e.moveCall({
|
|
527
|
-
target: `${
|
|
528
|
-
typeArguments: [
|
|
583
|
+
target: `${i.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
584
|
+
typeArguments: [r.collateralCoinType],
|
|
529
585
|
arguments: [
|
|
530
586
|
e.object("0x6"),
|
|
531
|
-
e.object(
|
|
532
|
-
e.object(
|
|
533
|
-
e.object(
|
|
534
|
-
e.pure.u8(
|
|
535
|
-
|
|
536
|
-
e.object(
|
|
537
|
-
e.object(
|
|
538
|
-
|
|
587
|
+
e.object(i.priceOracle),
|
|
588
|
+
e.object(i.storage),
|
|
589
|
+
e.object(u.collateral.contract.pool),
|
|
590
|
+
e.pure.u8(u.collateral.id),
|
|
591
|
+
p,
|
|
592
|
+
e.object(i.incentiveV2),
|
|
593
|
+
e.object(i.incentiveV3),
|
|
594
|
+
w,
|
|
539
595
|
e.object("0x5")
|
|
540
596
|
]
|
|
541
597
|
}),
|
|
542
|
-
|
|
598
|
+
r.collateralCoinType
|
|
543
599
|
);
|
|
544
600
|
let f;
|
|
545
|
-
for (const
|
|
546
|
-
const
|
|
547
|
-
f = await
|
|
601
|
+
for (const v of c.conversions) {
|
|
602
|
+
const E = e.splitCoins(C, [v.input.amount])[0];
|
|
603
|
+
f = await ye(E, v);
|
|
548
604
|
}
|
|
549
|
-
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
for (const
|
|
553
|
-
if (
|
|
605
|
+
s && (f ? e.mergeCoins(f, [s]) : f = s), f && (f = me(f));
|
|
606
|
+
const R = k(r.principalCoinType, r.collateralCoinType) ? C : f, z = a.action.type === "close" && Q(r, _, u) && Q(r, c.snapshot, u);
|
|
607
|
+
z || (o(R, "INVALID_QUOTE", "Missing principal output"), a.action.type === "remove_principal" && ce(e, R, a.action.amount));
|
|
608
|
+
for (const v of a.estimate.minOutputs) {
|
|
609
|
+
if (z && v.amount === "0" && k(v.coinType, r.principalCoinType))
|
|
554
610
|
continue;
|
|
555
|
-
const
|
|
556
|
-
|
|
611
|
+
const E = k(v.coinType, r.collateralCoinType) ? C : f;
|
|
612
|
+
o(E, "INVALID_QUOTE", "Missing minimum output coin"), ce(e, E, v.amount);
|
|
557
613
|
}
|
|
558
|
-
|
|
614
|
+
m.push({ coinType: r.collateralCoinType, coin: C }), f && m.push({ coinType: r.debtCoinType, coin: f });
|
|
559
615
|
}
|
|
560
|
-
const
|
|
561
|
-
target: `${
|
|
562
|
-
arguments: [
|
|
616
|
+
const oe = e.moveCall({
|
|
617
|
+
target: `${i.package}::account::account_owner`,
|
|
618
|
+
arguments: [w]
|
|
563
619
|
});
|
|
564
|
-
if (
|
|
565
|
-
for (const [
|
|
566
|
-
["user_collateral_balance",
|
|
567
|
-
["user_loan_balance",
|
|
620
|
+
if (a.action.type === "close")
|
|
621
|
+
for (const [s, p] of [
|
|
622
|
+
["user_collateral_balance", u.collateral.id],
|
|
623
|
+
["user_loan_balance", u.debt.id]
|
|
568
624
|
]) {
|
|
569
625
|
const C = e.moveCall({
|
|
570
|
-
target: `${
|
|
571
|
-
arguments: [e.object(
|
|
626
|
+
target: `${i.package}::logic::${s}`,
|
|
627
|
+
arguments: [e.object(i.storage), e.pure.u8(p), oe]
|
|
572
628
|
}), f = e.moveCall({
|
|
573
629
|
target: "0x1::u256::checked_sub",
|
|
574
630
|
arguments: [e.pure.u256("0"), C]
|
|
@@ -579,61 +635,67 @@ function We(w = {}) {
|
|
|
579
635
|
arguments: [f]
|
|
580
636
|
});
|
|
581
637
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
638
|
+
const fe = Ae(
|
|
639
|
+
a.constraints.maxLeverage,
|
|
640
|
+
a.action,
|
|
641
|
+
c.direction,
|
|
642
|
+
Y(_, u).leverage
|
|
643
|
+
);
|
|
644
|
+
if (fe) {
|
|
645
|
+
const s = (v, E) => e.moveCall({
|
|
646
|
+
target: `${i.package}::logic::${v}`,
|
|
585
647
|
arguments: [
|
|
586
648
|
e.object("0x6"),
|
|
587
|
-
e.object(
|
|
588
|
-
e.object(
|
|
589
|
-
e.pure.u8(
|
|
590
|
-
|
|
649
|
+
e.object(i.priceOracle),
|
|
650
|
+
e.object(i.storage),
|
|
651
|
+
e.pure.u8(E),
|
|
652
|
+
oe
|
|
591
653
|
]
|
|
592
|
-
}),
|
|
593
|
-
const
|
|
654
|
+
}), p = (v, E) => {
|
|
655
|
+
const ne = e.moveCall({
|
|
594
656
|
target: "0x1::u256::checked_mul",
|
|
595
|
-
arguments: [
|
|
657
|
+
arguments: [v, e.pure.u256(E)]
|
|
596
658
|
});
|
|
597
659
|
return e.moveCall({
|
|
598
660
|
target: "0x1::option::destroy_some",
|
|
599
661
|
typeArguments: ["u256"],
|
|
600
|
-
arguments: [
|
|
662
|
+
arguments: [ne]
|
|
601
663
|
});
|
|
602
|
-
}, C =
|
|
603
|
-
|
|
664
|
+
}, C = fe.shiftedBy(12).integerValue(y.ROUND_FLOOR), f = p(
|
|
665
|
+
s("user_collateral_value", u.collateral.id),
|
|
604
666
|
C.minus("1e12").toFixed(0)
|
|
605
|
-
),
|
|
667
|
+
), R = p(s("user_loan_value", u.debt.id), C.toFixed(0)), z = e.moveCall({
|
|
606
668
|
target: "0x1::u256::checked_sub",
|
|
607
|
-
arguments: [f,
|
|
669
|
+
arguments: [f, R]
|
|
608
670
|
});
|
|
609
671
|
e.moveCall({
|
|
610
672
|
target: "0x1::option::destroy_some",
|
|
611
673
|
typeArguments: ["u256"],
|
|
612
|
-
arguments: [
|
|
674
|
+
arguments: [z]
|
|
613
675
|
});
|
|
614
676
|
}
|
|
615
677
|
return e.moveCall({
|
|
616
|
-
target: `${
|
|
678
|
+
target: `${i.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
617
679
|
arguments: [
|
|
618
680
|
e.object("0x6"),
|
|
619
|
-
e.object(
|
|
620
|
-
e.object(
|
|
621
|
-
|
|
681
|
+
e.object(i.storage),
|
|
682
|
+
e.object(i.priceOracle),
|
|
683
|
+
oe,
|
|
622
684
|
e.pure.u256(
|
|
623
|
-
new
|
|
685
|
+
new y(a.constraints.minHealthFactor).shiftedBy(27).integerValue(y.ROUND_CEIL).toFixed(0)
|
|
624
686
|
)
|
|
625
687
|
]
|
|
626
|
-
}), { coins:
|
|
688
|
+
}), { coins: m, accountCap: w, createdAccountCap: I };
|
|
627
689
|
}
|
|
628
|
-
function
|
|
629
|
-
return
|
|
690
|
+
function Oe(e, l, t) {
|
|
691
|
+
return de(e, l, t, !1);
|
|
630
692
|
}
|
|
631
|
-
function
|
|
632
|
-
return
|
|
693
|
+
function Ne(e, l, t) {
|
|
694
|
+
return de(e, l, { coins: t }, !0);
|
|
633
695
|
}
|
|
634
|
-
return { getPosition:
|
|
696
|
+
return { getPosition: Ie, quote: we, buildPTB: Oe, buildPTBForSimulation: Ne };
|
|
635
697
|
}
|
|
636
698
|
export {
|
|
637
|
-
|
|
699
|
+
rt as createMultiplyClient
|
|
638
700
|
};
|
|
639
701
|
//# sourceMappingURL=client.js.map
|