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