@naviprotocol/multiply 0.2.0-preview.20261102.2 → 0.2.0-preview.20261103.1
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 +18 -11
- package/dist/cap-registry.d.ts +18 -0
- package/dist/cap-registry.d.ts.map +1 -0
- package/dist/cap-registry.js +85 -0
- package/dist/cap-registry.js.map +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +320 -281
- package/dist/client.js.map +1 -1
- package/dist/data-source.d.ts +4 -2
- package/dist/data-source.d.ts.map +1 -1
- package/dist/data-source.js +216 -170
- package/dist/data-source.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -15
- package/dist/index.js.map +1 -1
- package/dist/planner.d.ts +1 -1
- package/dist/planner.js +1 -1
- package/dist/planner.js.map +1 -1
- package/dist/strategies.d.ts +8 -1
- package/dist/strategies.d.ts.map +1 -1
- package/dist/strategies.js +13 -12
- package/dist/strategies.js.map +1 -1
- package/dist/types.d.ts +17 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -1,198 +1,243 @@
|
|
|
1
|
-
import { voloConverter as
|
|
2
|
-
import { defaultClient as
|
|
3
|
-
import { strategies as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { voloConverter as Ae, haedalConverter as Te, astrosConverter as _e, validateConversion as he } from "./converters.js";
|
|
2
|
+
import { defaultClient as ve, createNaviDataSource as we } from "./data-source.js";
|
|
3
|
+
import { strategies as Ie } from "./strategies.js";
|
|
4
|
+
import { indexRegistryStrategies as Ee, normalizeCapRegistry as ue, MAINNET_CAP_REGISTRY as Oe, registryKeyString as O, registerCreatedCapPTB as ke } from "./cap-registry.js";
|
|
5
|
+
import { validateAction as pe, metrics as de, plan as Ne, chooseConversion as Se } from "./planner.js";
|
|
6
|
+
import { tokenDecimals as N, amountCushion as ge, withinLtv as Ue, supplyCapacity as Le, borrowCapacity as je, atomPrices as De } from "./amounts.js";
|
|
7
|
+
import { check as r, jsonCopy as S, coinType as x, sameCoin as K, checksum as U, address as C, BN as u, minOutputGuard as ee, uint as G } from "./utils.js";
|
|
8
|
+
function Be(T = {}) {
|
|
9
|
+
const z = T.client ?? ve(), te = T.converters ?? [Ae({ client: z }), Te({ client: z })], ae = T.fallbackConverter ?? _e({ services: T.services }), P = /* @__PURE__ */ new Map();
|
|
10
|
+
for (const e of [...te, ae])
|
|
11
|
+
r(!P.has(e.id), "INVALID_ARGUMENT", `Duplicate converter id: ${e.id}`), P.set(e.id, e);
|
|
12
|
+
const L = (T.strategies ?? Object.values(Ie)).map(
|
|
13
|
+
(e) => re(S(e))
|
|
13
14
|
);
|
|
14
|
-
|
|
15
|
-
new Set(
|
|
15
|
+
r(
|
|
16
|
+
new Set(L.map((e) => e.id)).size === L.length,
|
|
16
17
|
"INVALID_ARGUMENT",
|
|
17
18
|
"Strategy registry contains duplicate ids"
|
|
18
19
|
);
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const oe = Ee(L), j = ue(T.capRegistry ?? Oe), b = T.dataSource ?? we({
|
|
21
|
+
client: z,
|
|
22
|
+
services: T.services,
|
|
23
|
+
capRegistry: j,
|
|
24
|
+
strategies: L
|
|
25
|
+
});
|
|
26
|
+
function ne(e = "INVALID_ARGUMENT") {
|
|
27
|
+
r(
|
|
28
|
+
b.capRegistry && JSON.stringify(ue(b.capRegistry)) === JSON.stringify(j),
|
|
29
|
+
e,
|
|
30
|
+
"DataSource Registry deployment differs from the execution deployment"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
ne();
|
|
34
|
+
async function Y(e, d = "INVALID_ARGUMENT") {
|
|
35
|
+
const s = re(S(e)), a = oe.get(O(s.registryKey));
|
|
36
|
+
return r(
|
|
37
|
+
a && await U(a) === await U(s),
|
|
38
|
+
d,
|
|
39
|
+
"Strategy differs from the configured Registry binding"
|
|
40
|
+
), s;
|
|
41
|
+
}
|
|
42
|
+
function re(e) {
|
|
43
|
+
r(
|
|
21
44
|
typeof e?.id == "string" && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(e.id),
|
|
22
45
|
"INVALID_ARGUMENT",
|
|
23
46
|
"Strategy id must be a stable ASCII slug"
|
|
24
|
-
),
|
|
47
|
+
), r(
|
|
25
48
|
typeof e.market == "string" && /^[a-z0-9][a-z0-9_-]{0,63}$/.test(e.market),
|
|
26
49
|
"INVALID_ARGUMENT",
|
|
27
50
|
"Missing market"
|
|
28
|
-
),
|
|
51
|
+
), r(
|
|
29
52
|
e.emodeId === void 0,
|
|
30
53
|
"STRATEGY_UNSUPPORTED",
|
|
31
54
|
"E-Mode risk overrides are not supported in this release"
|
|
32
|
-
);
|
|
33
|
-
const
|
|
55
|
+
), O(e.registryKey);
|
|
56
|
+
const d = {
|
|
34
57
|
...e,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
58
|
+
registryKey: { ...e.registryKey },
|
|
59
|
+
principalCoinType: x(e.principalCoinType),
|
|
60
|
+
collateralCoinType: x(e.collateralCoinType),
|
|
61
|
+
debtCoinType: x(e.debtCoinType)
|
|
38
62
|
};
|
|
39
|
-
return
|
|
40
|
-
|
|
63
|
+
return r(
|
|
64
|
+
K(d.principalCoinType, d.debtCoinType) && !K(d.collateralCoinType, d.debtCoinType),
|
|
41
65
|
"STRATEGY_UNSUPPORTED",
|
|
42
66
|
"Requires principal = debt and a distinct collateral token"
|
|
43
|
-
),
|
|
67
|
+
), d;
|
|
44
68
|
}
|
|
45
|
-
async function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
async function H(e) {
|
|
70
|
+
ne("STALE_QUOTE");
|
|
71
|
+
const d = await b.listAccountCaps(e), s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Set();
|
|
72
|
+
return d.map((p) => {
|
|
73
|
+
const t = O(p.registryKey), c = oe.get(t);
|
|
74
|
+
r(c, "UNSUPPORTED_REGISTRY_STRATEGY", "Unknown registered Multiply strategy"), r(
|
|
75
|
+
c.id === p.strategyId,
|
|
76
|
+
"INVALID_ACCOUNT_CAP",
|
|
77
|
+
"Cap numeric binding differs from strategy ID"
|
|
78
|
+
);
|
|
79
|
+
const g = C(p.id), m = C(p.accountOwner);
|
|
80
|
+
return r(
|
|
81
|
+
g !== C("0x0") && m !== C("0x0"),
|
|
82
|
+
"INVALID_ACCOUNT_CAP",
|
|
83
|
+
"Zero Cap identity"
|
|
84
|
+
), r(
|
|
85
|
+
!s.has(t) && !a.has(g) && !y.has(m),
|
|
86
|
+
"DUPLICATE_ACCOUNT_CAP",
|
|
87
|
+
"Duplicate strategy, Cap or lending account in Registry"
|
|
88
|
+
), s.add(t), a.add(g), y.add(m), { ...p, id: g, accountOwner: m, registryKey: { ...p.registryKey } };
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function X(e, d) {
|
|
92
|
+
const s = O(d.registryKey);
|
|
93
|
+
return e.find((a) => O(a.registryKey) === s);
|
|
62
94
|
}
|
|
63
|
-
async function
|
|
64
|
-
e =
|
|
65
|
-
const
|
|
66
|
-
for (const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const a = await y.readMarket(t), c = await y.readPosition(m, t, a);
|
|
72
|
-
q(c.collateralAmount), q(c.debtAmount), u.push({
|
|
95
|
+
async function me(e, d = {}) {
|
|
96
|
+
e = C(e);
|
|
97
|
+
const s = [], a = await H(e);
|
|
98
|
+
for (const y of d.strategy ? [d.strategy] : L) {
|
|
99
|
+
const p = await Y(y), t = X(a, p);
|
|
100
|
+
if (!t) continue;
|
|
101
|
+
const c = await b.readMarket(p), g = await b.readPosition(t, p, c);
|
|
102
|
+
G(g.collateralAmount), G(g.debtAmount), s.push({
|
|
73
103
|
address: e,
|
|
74
|
-
strategy:
|
|
75
|
-
accountCap:
|
|
76
|
-
...
|
|
77
|
-
...
|
|
104
|
+
strategy: p,
|
|
105
|
+
accountCap: t,
|
|
106
|
+
...g,
|
|
107
|
+
...de(g, c)
|
|
78
108
|
});
|
|
79
109
|
}
|
|
80
|
-
return
|
|
110
|
+
return s;
|
|
81
111
|
}
|
|
82
|
-
async function
|
|
83
|
-
e =
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
112
|
+
async function ye(e, d, s, a) {
|
|
113
|
+
e = C(e), r(e !== C("0x0"), "INVALID_ARGUMENT", "Multiply owner cannot be zero"), pe(s, a);
|
|
114
|
+
const y = await Y(d), p = X(await H(e), y);
|
|
115
|
+
r(
|
|
116
|
+
p || s.type === "open",
|
|
87
117
|
"POSITION_NOT_FOUND",
|
|
88
118
|
"Only open may create a Multiply Cap"
|
|
89
119
|
);
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
|
|
120
|
+
const t = await b.readMarket(y), c = p ? await b.readPosition(p, y, t) : { collateralAmount: "0", debtAmount: "0" };
|
|
121
|
+
G(c.collateralAmount), G(c.debtAmount);
|
|
122
|
+
const g = c.collateralAmount === "0" && c.debtAmount === "0";
|
|
123
|
+
if (r(
|
|
124
|
+
s.type !== "open" || g,
|
|
95
125
|
"POSITION_EXISTS",
|
|
96
126
|
"Use add_principal or set_leverage for an existing position"
|
|
97
|
-
),
|
|
98
|
-
|
|
127
|
+
), r(
|
|
128
|
+
s.type === "open" || !g,
|
|
99
129
|
"POSITION_NOT_FOUND",
|
|
100
130
|
"Empty position; use open to reuse this Cap"
|
|
101
|
-
), "targetLeverage" in
|
|
102
|
-
const
|
|
103
|
-
new
|
|
104
|
-
),
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
), "targetLeverage" in s && s.targetLeverage) {
|
|
132
|
+
const A = new u(t.liquidationThreshold).div(
|
|
133
|
+
new u(t.borrowWeight).times(a.minHealthFactor)
|
|
134
|
+
), v = new u(1).minus(new u(1).div(s.targetLeverage)), M = De(t), F = !["open", "add_principal"].includes(s.type) && v.times(c.collateralAmount).times(M.collateral).lte(new u(c.debtAmount).times(M.debt));
|
|
135
|
+
r(
|
|
136
|
+
v.lte(A) && (v.lte(new u(t.ltv).div(t.borrowWeight)) || F),
|
|
107
137
|
"CONSTRAINT_VIOLATION",
|
|
108
138
|
"Target leverage exceeds protocol or health factor limits"
|
|
109
139
|
);
|
|
110
140
|
}
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
g,
|
|
141
|
+
const m = await b.readBorrowFeeBps(t, p?.accountOwner), o = await Ne(
|
|
142
|
+
y,
|
|
143
|
+
s,
|
|
144
|
+
a,
|
|
116
145
|
c,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
146
|
+
t,
|
|
147
|
+
m,
|
|
148
|
+
(A) => Se(A, te, ae)
|
|
149
|
+
), h = {
|
|
120
150
|
address: e,
|
|
121
|
-
strategy:
|
|
122
|
-
action:
|
|
123
|
-
constraints:
|
|
151
|
+
strategy: y,
|
|
152
|
+
action: S(s),
|
|
153
|
+
constraints: S(a),
|
|
124
154
|
expiresAt: Math.min(
|
|
125
155
|
Date.now() + 12e4,
|
|
126
|
-
...
|
|
156
|
+
...o.execution.conversions.map((A) => A.expiresAt)
|
|
127
157
|
),
|
|
128
|
-
estimate:
|
|
158
|
+
estimate: o.estimate,
|
|
129
159
|
execution: {
|
|
130
|
-
...
|
|
131
|
-
|
|
160
|
+
...o.execution,
|
|
161
|
+
capRegistry: { ...j },
|
|
162
|
+
accountCap: p ? { kind: "existing", ...p } : { kind: "create", registryKey: { ...y.registryKey } },
|
|
132
163
|
checksum: ""
|
|
133
164
|
}
|
|
134
165
|
};
|
|
135
|
-
return
|
|
166
|
+
return h.execution.checksum = await U(h), S(h);
|
|
136
167
|
}
|
|
137
|
-
async function
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
168
|
+
async function fe(e, d, s) {
|
|
169
|
+
const a = S(d);
|
|
170
|
+
r(
|
|
171
|
+
a.execution?.version === 3,
|
|
141
172
|
"INVALID_QUOTE",
|
|
142
173
|
"Unknown quote version; request a fresh quote"
|
|
143
174
|
);
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
175
|
+
const y = a.execution.checksum;
|
|
176
|
+
a.execution.checksum = "", r(
|
|
177
|
+
y === await U(a),
|
|
147
178
|
"INVALID_QUOTE",
|
|
148
179
|
"Quote contents have changed; request a fresh quote"
|
|
149
|
-
),
|
|
150
|
-
Number.isSafeInteger(
|
|
180
|
+
), a.execution.checksum = y, r(
|
|
181
|
+
Number.isSafeInteger(a.expiresAt) && a.expiresAt > Date.now(),
|
|
151
182
|
"QUOTE_EXPIRED",
|
|
152
183
|
"Multiply quote expired"
|
|
153
|
-
),
|
|
154
|
-
|
|
184
|
+
), r(
|
|
185
|
+
C(a.address) !== C("0x0"),
|
|
155
186
|
"INVALID_ARGUMENT",
|
|
156
187
|
"Multiply owner cannot be zero"
|
|
157
|
-
),
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
188
|
+
), await Y(a.strategy, "STALE_QUOTE"), r(
|
|
189
|
+
await U(a.execution.capRegistry) === await U(j),
|
|
190
|
+
"STALE_QUOTE",
|
|
191
|
+
"Registry deployment changed since quote"
|
|
192
|
+
), r(
|
|
193
|
+
O(a.execution.accountCap.registryKey) === O(a.strategy.registryKey),
|
|
194
|
+
"INVALID_QUOTE",
|
|
195
|
+
"Quote Cap key differs from strategy"
|
|
196
|
+
);
|
|
197
|
+
const p = e.getData().sender;
|
|
198
|
+
r(
|
|
199
|
+
!p || C(p) === C(a.address),
|
|
200
|
+
"INVALID_INPUTS",
|
|
201
|
+
"Transaction sender differs from quote wallet"
|
|
202
|
+
), pe(a.action, a.constraints);
|
|
203
|
+
const t = a.execution, c = a.strategy, g = s.coins ?? [];
|
|
204
|
+
r(
|
|
205
|
+
g.length === a.estimate.inputs.length,
|
|
161
206
|
"INVALID_INPUTS",
|
|
162
207
|
"Provide exactly the quoted input coins"
|
|
163
208
|
);
|
|
164
|
-
for (const n of
|
|
165
|
-
|
|
166
|
-
g.filter((
|
|
209
|
+
for (const n of a.estimate.inputs)
|
|
210
|
+
r(
|
|
211
|
+
g.filter((l) => K(l.coinType, n.coinType)).length === 1,
|
|
167
212
|
"INVALID_INPUTS",
|
|
168
213
|
`Missing or duplicate input: ${n.coinType}`
|
|
169
214
|
);
|
|
170
|
-
for (const n of
|
|
171
|
-
|
|
172
|
-
|
|
215
|
+
for (const n of t.conversions)
|
|
216
|
+
r(
|
|
217
|
+
P.has(n.converterId),
|
|
173
218
|
"INVALID_CONVERSION",
|
|
174
219
|
"Quoted converter is not configured"
|
|
175
|
-
),
|
|
220
|
+
), he(
|
|
176
221
|
n,
|
|
177
222
|
{
|
|
178
223
|
coinIn: n.input.coinType,
|
|
179
224
|
coinOut: n.expectedOutput.coinType,
|
|
180
225
|
amountIn: n.input.amount,
|
|
181
|
-
slippageBps:
|
|
226
|
+
slippageBps: a.constraints.maxSlippageBps
|
|
182
227
|
},
|
|
183
228
|
n.converterId
|
|
184
229
|
);
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
!
|
|
230
|
+
const m = X(await H(a.address), c);
|
|
231
|
+
t.accountCap.kind === "create" ? r(
|
|
232
|
+
!m && !s.accountCap,
|
|
188
233
|
"STALE_QUOTE",
|
|
189
234
|
"Cap was created since quote or an unexpected Cap was supplied"
|
|
190
|
-
) : (
|
|
191
|
-
|
|
235
|
+
) : (r(
|
|
236
|
+
m && m.id === t.accountCap.id && m.accountOwner === t.accountCap.accountOwner,
|
|
192
237
|
"STALE_QUOTE",
|
|
193
238
|
"AccountCap changed since quote"
|
|
194
|
-
), typeof
|
|
195
|
-
const o = await
|
|
239
|
+
), typeof s.accountCap == "string" && r(C(s.accountCap) === C(m.id), "INVALID_INPUTS", "Wrong AccountCap"));
|
|
240
|
+
const o = await b.readMarket(c);
|
|
196
241
|
for (const n of [
|
|
197
242
|
"package",
|
|
198
243
|
"storage",
|
|
@@ -201,122 +246,116 @@ function Le(v = {}) {
|
|
|
201
246
|
"incentiveV3",
|
|
202
247
|
"limter"
|
|
203
248
|
])
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
o.collateral.contract.pool ===
|
|
249
|
+
r(o.config[n] === t.market.config[n], "STALE_QUOTE", `Market ${n} changed`);
|
|
250
|
+
r(
|
|
251
|
+
o.collateral.contract.pool === t.market.collateral.contract.pool && o.debt.contract.pool === t.market.debt.contract.pool && o.flash.poolId === t.market.flash.poolId && N(o.collateral) === N(t.market.collateral) && N(o.debt) === N(t.market.debt),
|
|
207
252
|
"STALE_QUOTE",
|
|
208
253
|
"Pool configuration changed"
|
|
209
254
|
);
|
|
210
|
-
const
|
|
211
|
-
|
|
255
|
+
const h = m ? await b.readPosition(m, c, o) : { collateralAmount: "0", debtAmount: "0" }, A = new u(h.collateralAmount).minus(t.snapshot.collateralAmount), v = new u(h.debtAmount).minus(t.snapshot.debtAmount);
|
|
256
|
+
r(
|
|
212
257
|
A.gte(0) && A.lte(
|
|
213
|
-
new
|
|
214
|
-
) &&
|
|
215
|
-
new
|
|
258
|
+
new u(t.snapshot.collateralAmount).times("0.0001").plus(ge(o.collateral))
|
|
259
|
+
) && v.gte(0) && v.lte(
|
|
260
|
+
new u(t.snapshot.debtAmount).times("0.0001").plus(ge(o.debt))
|
|
216
261
|
),
|
|
217
262
|
"STALE_QUOTE",
|
|
218
263
|
"Position changed since quote"
|
|
219
264
|
);
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
new
|
|
265
|
+
const M = await b.readBorrowFeeBps(o, m?.accountOwner);
|
|
266
|
+
r(
|
|
267
|
+
new u(t.borrowAmount).times(M).div(1e4).integerValue().lte(t.borrowFee),
|
|
223
268
|
"STALE_QUOTE",
|
|
224
269
|
"Borrow fee increased"
|
|
225
|
-
),
|
|
226
|
-
const
|
|
227
|
-
collateralAmount: new
|
|
228
|
-
debtAmount: new
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
|
|
270
|
+
), r(o.flash.feeBps === t.market.flash.feeBps, "STALE_QUOTE", "Flash fee changed");
|
|
271
|
+
const F = {
|
|
272
|
+
collateralAmount: new u(t.minCollateralAfter).plus(A).toFixed(0),
|
|
273
|
+
debtAmount: new u(t.debtAfter).plus(a.action.type === "close" ? 0 : v).toFixed(0)
|
|
274
|
+
}, Q = de(F, o);
|
|
275
|
+
r(
|
|
276
|
+
Q.healthFactor === null || new u(Q.healthFactor).gte(a.constraints.minHealthFactor),
|
|
232
277
|
"STALE_QUOTE",
|
|
233
278
|
"Updated market no longer satisfies HF"
|
|
234
|
-
),
|
|
279
|
+
), r(
|
|
235
280
|
Number.isSafeInteger(o.observedAt) && Date.now() - o.observedAt <= 12e4,
|
|
236
281
|
"STALE_QUOTE",
|
|
237
282
|
"Current market snapshot is stale"
|
|
238
|
-
),
|
|
239
|
-
new
|
|
283
|
+
), a.constraints.maxLeverage && Q.leverage && r(
|
|
284
|
+
new u(Q.leverage).lte(a.constraints.maxLeverage),
|
|
240
285
|
"STALE_QUOTE",
|
|
241
286
|
"Updated market exceeds maximum leverage"
|
|
242
|
-
),
|
|
243
|
-
|
|
287
|
+
), r(
|
|
288
|
+
Ue(F, h, o, t.direction !== "increase"),
|
|
244
289
|
"STALE_QUOTE",
|
|
245
290
|
"Updated market exceeds LTV"
|
|
246
|
-
),
|
|
247
|
-
new
|
|
291
|
+
), r(
|
|
292
|
+
new u(t.flashAmount).lte(o.flash.max) && (t.flashAmount === "0" || new u(t.flashAmount).gte(o.flash.min)),
|
|
248
293
|
"CAPACITY_EXCEEDED",
|
|
249
294
|
"Flash capacity changed"
|
|
250
|
-
),
|
|
251
|
-
new
|
|
295
|
+
), r(
|
|
296
|
+
new u(t.collateralAfter).minus(t.snapshot.collateralAmount).lte(Le(o)),
|
|
252
297
|
"CAPACITY_EXCEEDED",
|
|
253
298
|
"Supply capacity changed"
|
|
254
|
-
),
|
|
255
|
-
new
|
|
299
|
+
), r(
|
|
300
|
+
new u(t.borrowAmount).plus(t.borrowFee).lte(je(o)),
|
|
256
301
|
"CAPACITY_EXCEEDED",
|
|
257
302
|
"Borrow liquidity changed"
|
|
258
|
-
), await
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
arguments: [U, e.pure.string(JSON.stringify(c))]
|
|
266
|
-
}));
|
|
267
|
-
const w = [], H = (n, s) => {
|
|
268
|
-
const d = g.find((O) => R(O.coinType, n)), I = e.splitCoins(d.coin, [s])[0];
|
|
269
|
-
return w.push(d), I;
|
|
270
|
-
}, S = (n, s) => e.moveCall({
|
|
303
|
+
), e.setSenderIfNotSet(a.address), await b.prepareOracle(e, c, o);
|
|
304
|
+
const i = o.config, $ = t.accountCap.kind === "create" ? e.moveCall({ target: `${i.package}::lending::create_account` }) : void 0, w = $ ?? s.accountCap ?? e.object(t.accountCap.id);
|
|
305
|
+
$ && ke(e, $, c.registryKey, j);
|
|
306
|
+
const I = [], W = (n, l) => {
|
|
307
|
+
const f = g.find((k) => K(k.coinType, n)), E = e.splitCoins(f.coin, [l])[0];
|
|
308
|
+
return I.push(f), E;
|
|
309
|
+
}, D = (n, l) => e.moveCall({
|
|
271
310
|
target: "0x2::coin::from_balance",
|
|
272
|
-
typeArguments: [
|
|
311
|
+
typeArguments: [l],
|
|
273
312
|
arguments: [n]
|
|
274
|
-
}),
|
|
275
|
-
target: `${
|
|
313
|
+
}), Ce = (n, l) => e.moveCall({ target: "0x2::coin::into_balance", typeArguments: [l], arguments: [n] }), ce = (n) => e.moveCall({
|
|
314
|
+
target: `${i.package}::incentive_v3::deposit_with_account_cap`,
|
|
276
315
|
typeArguments: [c.collateralCoinType],
|
|
277
316
|
arguments: [
|
|
278
317
|
e.object("0x6"),
|
|
279
|
-
e.object(
|
|
318
|
+
e.object(i.storage),
|
|
280
319
|
e.object(o.collateral.contract.pool),
|
|
281
320
|
e.pure.u8(o.collateral.id),
|
|
282
321
|
n,
|
|
283
|
-
e.object(
|
|
284
|
-
e.object(
|
|
285
|
-
|
|
322
|
+
e.object(i.incentiveV2),
|
|
323
|
+
e.object(i.incentiveV3),
|
|
324
|
+
w
|
|
286
325
|
]
|
|
287
|
-
}),
|
|
326
|
+
}), ie = (n) => D(
|
|
288
327
|
e.moveCall({
|
|
289
|
-
target: `${
|
|
328
|
+
target: `${i.package}::incentive_v3::repay_with_account_cap`,
|
|
290
329
|
typeArguments: [c.debtCoinType],
|
|
291
330
|
arguments: [
|
|
292
331
|
e.object("0x6"),
|
|
293
|
-
e.object(
|
|
294
|
-
e.object(
|
|
332
|
+
e.object(i.priceOracle),
|
|
333
|
+
e.object(i.storage),
|
|
295
334
|
e.object(o.debt.contract.pool),
|
|
296
335
|
e.pure.u8(o.debt.id),
|
|
297
336
|
n,
|
|
298
|
-
e.object(
|
|
299
|
-
e.object(
|
|
300
|
-
|
|
337
|
+
e.object(i.incentiveV2),
|
|
338
|
+
e.object(i.incentiveV3),
|
|
339
|
+
w
|
|
301
340
|
]
|
|
302
341
|
}),
|
|
303
342
|
c.debtCoinType
|
|
304
343
|
);
|
|
305
|
-
let
|
|
306
|
-
if (
|
|
344
|
+
let B, q;
|
|
345
|
+
if (t.flashAmount !== "0") {
|
|
307
346
|
const n = e.moveCall({
|
|
308
347
|
target: `${o.flash.config.package}::lending::flash_loan_with_ctx_v2`,
|
|
309
348
|
typeArguments: [c.debtCoinType],
|
|
310
349
|
arguments: [
|
|
311
350
|
e.object(o.flash.config.flashloanConfig),
|
|
312
351
|
e.object(o.flash.poolId),
|
|
313
|
-
e.pure.u64(
|
|
352
|
+
e.pure.u64(t.flashAmount),
|
|
314
353
|
e.object("0x5")
|
|
315
354
|
]
|
|
316
355
|
});
|
|
317
|
-
|
|
356
|
+
B = D(n[0], c.debtCoinType), q = n[1];
|
|
318
357
|
}
|
|
319
|
-
const
|
|
358
|
+
const se = (n) => q ? D(
|
|
320
359
|
e.moveCall({
|
|
321
360
|
target: `${o.flash.config.package}::lending::flash_repay_with_ctx`,
|
|
322
361
|
typeArguments: [c.debtCoinType],
|
|
@@ -324,185 +363,185 @@ function Le(v = {}) {
|
|
|
324
363
|
e.object("0x6"),
|
|
325
364
|
e.object(o.flash.config.storage),
|
|
326
365
|
e.object(o.flash.poolId),
|
|
327
|
-
|
|
328
|
-
|
|
366
|
+
q,
|
|
367
|
+
Ce(n, c.debtCoinType)
|
|
329
368
|
]
|
|
330
369
|
}),
|
|
331
370
|
c.debtCoinType
|
|
332
|
-
) : n,
|
|
333
|
-
const
|
|
334
|
-
changeRecipient:
|
|
371
|
+
) : n, le = async (n) => {
|
|
372
|
+
const l = t.conversions[0], f = await P.get(l.converterId).buildPTB(e, l, n, {
|
|
373
|
+
changeRecipient: a.address
|
|
335
374
|
});
|
|
336
|
-
return
|
|
375
|
+
return ee(e, f.coinOut, l.minOutput.amount), I.push(...f.change), f.coinOut;
|
|
337
376
|
};
|
|
338
|
-
if (
|
|
339
|
-
|
|
377
|
+
if (t.direction === "repay")
|
|
378
|
+
I.push({
|
|
340
379
|
coinType: c.debtCoinType,
|
|
341
|
-
coin:
|
|
380
|
+
coin: ie(W(c.debtCoinType, a.estimate.inputs[0].amount))
|
|
342
381
|
});
|
|
343
|
-
else if (
|
|
344
|
-
|
|
345
|
-
else if (
|
|
346
|
-
let n =
|
|
347
|
-
if (
|
|
348
|
-
const
|
|
349
|
-
n ? e.mergeCoins(n, [
|
|
382
|
+
else if (t.direction === "add_collateral")
|
|
383
|
+
ce(W(c.collateralCoinType, a.estimate.inputs[0].amount));
|
|
384
|
+
else if (t.direction === "increase") {
|
|
385
|
+
let n = B;
|
|
386
|
+
if (a.estimate.inputs.length) {
|
|
387
|
+
const l = W(c.principalCoinType, a.estimate.inputs[0].amount);
|
|
388
|
+
n ? e.mergeCoins(n, [l]) : n = l;
|
|
350
389
|
}
|
|
351
|
-
if (
|
|
352
|
-
const
|
|
353
|
-
target: `${
|
|
390
|
+
if (r(n, "INVALID_QUOTE", "Increase plan has no funds"), ce(await le(n)), q) {
|
|
391
|
+
const l = e.moveCall({
|
|
392
|
+
target: `${i.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
354
393
|
typeArguments: [c.debtCoinType],
|
|
355
394
|
arguments: [
|
|
356
395
|
e.object("0x6"),
|
|
357
|
-
e.object(
|
|
358
|
-
e.object(
|
|
396
|
+
e.object(i.priceOracle),
|
|
397
|
+
e.object(i.storage),
|
|
359
398
|
e.object(o.debt.contract.pool),
|
|
360
399
|
e.pure.u8(o.debt.id),
|
|
361
|
-
e.pure.u64(
|
|
362
|
-
e.object(
|
|
363
|
-
e.object(
|
|
364
|
-
|
|
400
|
+
e.pure.u64(t.borrowAmount),
|
|
401
|
+
e.object(i.incentiveV2),
|
|
402
|
+
e.object(i.incentiveV3),
|
|
403
|
+
w,
|
|
365
404
|
e.object("0x5")
|
|
366
405
|
]
|
|
367
406
|
});
|
|
368
|
-
|
|
407
|
+
I.push({ coinType: c.debtCoinType, coin: se(D(l, c.debtCoinType)) });
|
|
369
408
|
}
|
|
370
409
|
} else {
|
|
371
|
-
const n =
|
|
372
|
-
let
|
|
373
|
-
|
|
410
|
+
const n = B ? ie(B) : void 0;
|
|
411
|
+
let l = e.pure.u64(
|
|
412
|
+
t.withdrawAmount
|
|
374
413
|
);
|
|
375
|
-
if (
|
|
376
|
-
const
|
|
377
|
-
target: `${
|
|
378
|
-
arguments: [
|
|
414
|
+
if (a.action.type === "close") {
|
|
415
|
+
const _ = e.moveCall({
|
|
416
|
+
target: `${i.package}::account::account_owner`,
|
|
417
|
+
arguments: [w]
|
|
379
418
|
});
|
|
380
419
|
e.moveCall({
|
|
381
|
-
target: `${
|
|
382
|
-
arguments: [e.object("0x6"), e.object(
|
|
420
|
+
target: `${i.package}::lending::update_state_of_user`,
|
|
421
|
+
arguments: [e.object("0x6"), e.object(i.storage), _]
|
|
383
422
|
});
|
|
384
423
|
const V = e.moveCall({
|
|
385
|
-
target: `${
|
|
386
|
-
arguments: [e.object(
|
|
387
|
-
}),
|
|
388
|
-
if (
|
|
424
|
+
target: `${i.package}::logic::user_collateral_balance`,
|
|
425
|
+
arguments: [e.object(i.storage), e.pure.u8(o.collateral.id), _]
|
|
426
|
+
}), Z = e.moveCall({ target: "0x1::u256::try_as_u64", arguments: [V] });
|
|
427
|
+
if (l = e.moveCall({
|
|
389
428
|
target: "0x1::option::destroy_some",
|
|
390
429
|
typeArguments: ["u64"],
|
|
391
|
-
arguments: [
|
|
392
|
-
}),
|
|
393
|
-
target: `${
|
|
430
|
+
arguments: [Z]
|
|
431
|
+
}), N(o.collateral) !== 9 && (l = e.moveCall({
|
|
432
|
+
target: `${i.package}::pool::unnormal_amount`,
|
|
394
433
|
typeArguments: [c.collateralCoinType],
|
|
395
|
-
arguments: [e.object(o.collateral.contract.pool),
|
|
396
|
-
}),
|
|
397
|
-
const
|
|
434
|
+
arguments: [e.object(o.collateral.contract.pool), l]
|
|
435
|
+
}), N(o.collateral) < 9)) {
|
|
436
|
+
const be = e.moveCall({
|
|
398
437
|
target: "0x1::u64::checked_add",
|
|
399
|
-
arguments: [
|
|
438
|
+
arguments: [l, e.pure.u64("1")]
|
|
400
439
|
});
|
|
401
|
-
|
|
440
|
+
l = e.moveCall({
|
|
402
441
|
target: "0x1::option::destroy_some",
|
|
403
442
|
typeArguments: ["u64"],
|
|
404
|
-
arguments: [
|
|
443
|
+
arguments: [be]
|
|
405
444
|
});
|
|
406
445
|
}
|
|
407
446
|
}
|
|
408
|
-
const
|
|
447
|
+
const f = D(
|
|
409
448
|
e.moveCall({
|
|
410
|
-
target: `${
|
|
449
|
+
target: `${i.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
411
450
|
typeArguments: [c.collateralCoinType],
|
|
412
451
|
arguments: [
|
|
413
452
|
e.object("0x6"),
|
|
414
|
-
e.object(
|
|
415
|
-
e.object(
|
|
453
|
+
e.object(i.priceOracle),
|
|
454
|
+
e.object(i.storage),
|
|
416
455
|
e.object(o.collateral.contract.pool),
|
|
417
456
|
e.pure.u8(o.collateral.id),
|
|
418
|
-
|
|
419
|
-
e.object(
|
|
420
|
-
e.object(
|
|
421
|
-
|
|
457
|
+
l,
|
|
458
|
+
e.object(i.incentiveV2),
|
|
459
|
+
e.object(i.incentiveV3),
|
|
460
|
+
w,
|
|
422
461
|
e.object("0x5")
|
|
423
462
|
]
|
|
424
463
|
}),
|
|
425
464
|
c.collateralCoinType
|
|
426
|
-
),
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
n && e.mergeCoins(
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
for (const
|
|
433
|
-
|
|
465
|
+
), E = e.splitCoins(f, [t.withdrawAmount])[0];
|
|
466
|
+
I.push({ coinType: c.collateralCoinType, coin: f });
|
|
467
|
+
const k = await le(E);
|
|
468
|
+
n && e.mergeCoins(k, [n]);
|
|
469
|
+
const R = se(k);
|
|
470
|
+
a.action.type === "remove_principal" && ee(e, R, a.action.amount);
|
|
471
|
+
for (const _ of a.estimate.minOutputs) ee(e, R, _.amount);
|
|
472
|
+
I.push({ coinType: c.principalCoinType, coin: R });
|
|
434
473
|
}
|
|
435
|
-
const
|
|
436
|
-
target: `${
|
|
437
|
-
arguments: [
|
|
474
|
+
const J = e.moveCall({
|
|
475
|
+
target: `${i.package}::account::account_owner`,
|
|
476
|
+
arguments: [w]
|
|
438
477
|
});
|
|
439
|
-
if (
|
|
440
|
-
for (const [n,
|
|
478
|
+
if (a.action.type === "close")
|
|
479
|
+
for (const [n, l] of [
|
|
441
480
|
["user_collateral_balance", o.collateral.id],
|
|
442
481
|
["user_loan_balance", o.debt.id]
|
|
443
482
|
]) {
|
|
444
|
-
const
|
|
445
|
-
target: `${
|
|
446
|
-
arguments: [e.object(
|
|
447
|
-
}),
|
|
483
|
+
const f = e.moveCall({
|
|
484
|
+
target: `${i.package}::logic::${n}`,
|
|
485
|
+
arguments: [e.object(i.storage), e.pure.u8(l), J]
|
|
486
|
+
}), E = e.moveCall({
|
|
448
487
|
target: "0x1::u256::checked_sub",
|
|
449
|
-
arguments: [e.pure.u256("0"),
|
|
488
|
+
arguments: [e.pure.u256("0"), f]
|
|
450
489
|
});
|
|
451
490
|
e.moveCall({
|
|
452
491
|
target: "0x1::option::destroy_some",
|
|
453
492
|
typeArguments: ["u256"],
|
|
454
|
-
arguments: [
|
|
493
|
+
arguments: [E]
|
|
455
494
|
});
|
|
456
495
|
}
|
|
457
|
-
if (
|
|
458
|
-
const n = (
|
|
459
|
-
target: `${
|
|
496
|
+
if (a.constraints.maxLeverage !== void 0) {
|
|
497
|
+
const n = (_, V) => e.moveCall({
|
|
498
|
+
target: `${i.package}::logic::${_}`,
|
|
460
499
|
arguments: [
|
|
461
500
|
e.object("0x6"),
|
|
462
|
-
e.object(
|
|
463
|
-
e.object(
|
|
501
|
+
e.object(i.priceOracle),
|
|
502
|
+
e.object(i.storage),
|
|
464
503
|
e.pure.u8(V),
|
|
465
|
-
|
|
504
|
+
J
|
|
466
505
|
]
|
|
467
|
-
}),
|
|
468
|
-
const
|
|
506
|
+
}), l = (_, V) => {
|
|
507
|
+
const Z = e.moveCall({
|
|
469
508
|
target: "0x1::u256::checked_mul",
|
|
470
|
-
arguments: [
|
|
509
|
+
arguments: [_, e.pure.u256(V)]
|
|
471
510
|
});
|
|
472
511
|
return e.moveCall({
|
|
473
512
|
target: "0x1::option::destroy_some",
|
|
474
513
|
typeArguments: ["u256"],
|
|
475
|
-
arguments: [
|
|
514
|
+
arguments: [Z]
|
|
476
515
|
});
|
|
477
|
-
},
|
|
516
|
+
}, f = new u(a.constraints.maxLeverage).shiftedBy(12).integerValue(u.ROUND_FLOOR), E = l(
|
|
478
517
|
n("user_collateral_value", o.collateral.id),
|
|
479
|
-
|
|
480
|
-
),
|
|
518
|
+
f.minus("1e12").toFixed(0)
|
|
519
|
+
), k = l(n("user_loan_value", o.debt.id), f.toFixed(0)), R = e.moveCall({
|
|
481
520
|
target: "0x1::u256::checked_sub",
|
|
482
|
-
arguments: [
|
|
521
|
+
arguments: [E, k]
|
|
483
522
|
});
|
|
484
523
|
e.moveCall({
|
|
485
524
|
target: "0x1::option::destroy_some",
|
|
486
525
|
typeArguments: ["u256"],
|
|
487
|
-
arguments: [
|
|
526
|
+
arguments: [R]
|
|
488
527
|
});
|
|
489
528
|
}
|
|
490
529
|
return e.moveCall({
|
|
491
|
-
target: `${
|
|
530
|
+
target: `${i.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
492
531
|
arguments: [
|
|
493
532
|
e.object("0x6"),
|
|
494
|
-
e.object(
|
|
495
|
-
e.object(
|
|
496
|
-
|
|
533
|
+
e.object(i.storage),
|
|
534
|
+
e.object(i.priceOracle),
|
|
535
|
+
J,
|
|
497
536
|
e.pure.u256(
|
|
498
|
-
new
|
|
537
|
+
new u(a.constraints.minHealthFactor).shiftedBy(27).integerValue(u.ROUND_CEIL).toFixed(0)
|
|
499
538
|
)
|
|
500
539
|
]
|
|
501
|
-
}), { coins:
|
|
540
|
+
}), { coins: I, accountCap: w, createdAccountCap: $ };
|
|
502
541
|
}
|
|
503
|
-
return { getPosition:
|
|
542
|
+
return { getPosition: me, quote: ye, buildPTB: fe };
|
|
504
543
|
}
|
|
505
544
|
export {
|
|
506
|
-
|
|
545
|
+
Be as createMultiplyClient
|
|
507
546
|
};
|
|
508
547
|
//# sourceMappingURL=client.js.map
|