@gearbox-protocol/sdk 8.3.2 → 8.4.0
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/dist/cjs/abi/routerV310.js +31 -0
- package/dist/cjs/sdk/accounts/{CreditAccountsService.js → AbstractCreditAccountsService.js} +34 -407
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV300.js +363 -0
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +200 -0
- package/dist/cjs/sdk/accounts/constants.js +33 -0
- package/dist/cjs/sdk/accounts/createCreditAccountService.js +39 -0
- package/dist/cjs/sdk/accounts/index.js +4 -2
- package/dist/cjs/sdk/router/RouterV300Contract.js +8 -0
- package/dist/cjs/sdk/router/RouterV310Contract.js +24 -0
- package/dist/esm/abi/routerV310.js +31 -0
- package/dist/esm/sdk/accounts/{CreditAccountsService.js → AbstractCreditAccountsService.js} +31 -417
- package/dist/esm/sdk/accounts/CreditAccountsServiceV300.js +351 -0
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +176 -0
- package/dist/esm/sdk/accounts/constants.js +9 -0
- package/dist/esm/sdk/accounts/createCreditAccountService.js +15 -0
- package/dist/esm/sdk/accounts/index.js +2 -1
- package/dist/esm/sdk/router/RouterV300Contract.js +8 -0
- package/dist/esm/sdk/router/RouterV310Contract.js +25 -1
- package/dist/types/abi/routerV310.d.ts +48 -0
- package/dist/types/dev/AccountOpener.d.ts +2 -2
- package/dist/types/sdk/accounts/{CreditAccountsService.d.ts → AbstractCreditAccountsService.d.ts} +12 -67
- package/dist/types/sdk/accounts/CreditAccountsServiceV300.d.ts +25 -0
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +24 -0
- package/dist/types/sdk/accounts/constants.d.ts +2 -0
- package/dist/types/sdk/accounts/createCreditAccountService.d.ts +8 -0
- package/dist/types/sdk/accounts/index.d.ts +2 -1
- package/dist/types/sdk/accounts/types.d.ts +130 -1
- package/dist/types/sdk/router/RouterV300Contract.d.ts +5 -1
- package/dist/types/sdk/router/RouterV310Contract.d.ts +53 -1
- package/dist/types/sdk/router/types.d.ts +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var CreditAccountsServiceV300_exports = {};
|
|
20
|
+
__export(CreditAccountsServiceV300_exports, {
|
|
21
|
+
CreditAccountServiceV300: () => CreditAccountServiceV300
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(CreditAccountsServiceV300_exports);
|
|
24
|
+
var import_abitype = require("abitype");
|
|
25
|
+
var import_viem = require("viem");
|
|
26
|
+
var import_addresses = require("../constants/addresses.js");
|
|
27
|
+
var import_math = require("../constants/math.js");
|
|
28
|
+
var import_sdk_gov_legacy = require("../sdk-gov-legacy/index.js");
|
|
29
|
+
var import_AbstractCreditAccountsService = require("./AbstractCreditAccountsService.js");
|
|
30
|
+
class CreditAccountServiceV300 extends import_AbstractCreditAccountsService.AbstractCreditAccountService {
|
|
31
|
+
/**
|
|
32
|
+
* Implements {@link ICreditAccountsService.setBot}
|
|
33
|
+
*/
|
|
34
|
+
setBot(_) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Not implemented in router v3.0. Try direct call setBotPermissions instead."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Implements {@link ICreditAccountsService.withdrawCollateral}
|
|
41
|
+
*/
|
|
42
|
+
async withdrawCollateral({
|
|
43
|
+
creditAccount,
|
|
44
|
+
assetsToWithdraw: wrapped,
|
|
45
|
+
to,
|
|
46
|
+
minQuota,
|
|
47
|
+
averageQuota
|
|
48
|
+
}) {
|
|
49
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
50
|
+
creditAccount.creditManager
|
|
51
|
+
);
|
|
52
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
53
|
+
creditAccount.creditManager,
|
|
54
|
+
creditAccount,
|
|
55
|
+
void 0
|
|
56
|
+
);
|
|
57
|
+
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
58
|
+
wrapped,
|
|
59
|
+
false,
|
|
60
|
+
false,
|
|
61
|
+
creditAccount.creditManager
|
|
62
|
+
);
|
|
63
|
+
const calls = [
|
|
64
|
+
...priceUpdatesCalls,
|
|
65
|
+
...unwrapCalls,
|
|
66
|
+
...assetsToWithdraw.map(
|
|
67
|
+
(a) => this.prepareWithdrawToken(
|
|
68
|
+
creditAccount.creditFacade,
|
|
69
|
+
a.token,
|
|
70
|
+
a.balance,
|
|
71
|
+
to
|
|
72
|
+
)
|
|
73
|
+
),
|
|
74
|
+
...this.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
75
|
+
minQuota,
|
|
76
|
+
averageQuota
|
|
77
|
+
})
|
|
78
|
+
];
|
|
79
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
80
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Implements {@link ICreditAccountsService.repayCreditAccount}
|
|
84
|
+
*/
|
|
85
|
+
async repayCreditAccount({
|
|
86
|
+
operation,
|
|
87
|
+
collateralAssets,
|
|
88
|
+
assetsToWithdraw: wrapped,
|
|
89
|
+
creditAccount: ca,
|
|
90
|
+
permits,
|
|
91
|
+
to
|
|
92
|
+
}) {
|
|
93
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
94
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
95
|
+
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
96
|
+
ca.creditManager,
|
|
97
|
+
ca,
|
|
98
|
+
void 0
|
|
99
|
+
);
|
|
100
|
+
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
101
|
+
wrapped,
|
|
102
|
+
true,
|
|
103
|
+
true,
|
|
104
|
+
ca.creditManager
|
|
105
|
+
);
|
|
106
|
+
const calls = [
|
|
107
|
+
...operation === "close" ? [] : priceUpdates,
|
|
108
|
+
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
109
|
+
...this.prepareDisableQuotas(ca),
|
|
110
|
+
...this.prepareDecreaseDebt(ca),
|
|
111
|
+
...unwrapCalls,
|
|
112
|
+
...this.prepareDisableTokens(ca),
|
|
113
|
+
...assetsToWithdraw.map(
|
|
114
|
+
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
115
|
+
)
|
|
116
|
+
];
|
|
117
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
118
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
|
|
122
|
+
*/
|
|
123
|
+
async repayAndLiquidateCreditAccount({
|
|
124
|
+
collateralAssets,
|
|
125
|
+
assetsToWithdraw: wrapped,
|
|
126
|
+
creditAccount: ca,
|
|
127
|
+
permits,
|
|
128
|
+
to
|
|
129
|
+
}) {
|
|
130
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
131
|
+
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
132
|
+
ca.creditManager,
|
|
133
|
+
ca,
|
|
134
|
+
void 0
|
|
135
|
+
);
|
|
136
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
137
|
+
const { unwrapCalls, assetsToWithdraw } = this.#prepareUnwrapAndWithdrawCallsV3(
|
|
138
|
+
wrapped,
|
|
139
|
+
true,
|
|
140
|
+
true,
|
|
141
|
+
ca.creditManager
|
|
142
|
+
);
|
|
143
|
+
const calls = [
|
|
144
|
+
...priceUpdates,
|
|
145
|
+
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
146
|
+
...unwrapCalls,
|
|
147
|
+
...assetsToWithdraw.map(
|
|
148
|
+
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
149
|
+
)
|
|
150
|
+
];
|
|
151
|
+
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
152
|
+
ca.creditAccount,
|
|
153
|
+
to,
|
|
154
|
+
calls
|
|
155
|
+
);
|
|
156
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Implements {@link ICreditAccountsService.claimFarmRewards}
|
|
160
|
+
*/
|
|
161
|
+
async claimFarmRewards({
|
|
162
|
+
tokensToDisable,
|
|
163
|
+
calls: claimCalls,
|
|
164
|
+
creditAccount: ca,
|
|
165
|
+
minQuota,
|
|
166
|
+
averageQuota
|
|
167
|
+
}) {
|
|
168
|
+
if (claimCalls.length === 0) throw new Error("No path to execute");
|
|
169
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
170
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
171
|
+
ca.creditManager,
|
|
172
|
+
ca,
|
|
173
|
+
averageQuota
|
|
174
|
+
);
|
|
175
|
+
const calls = [
|
|
176
|
+
...priceUpdatesCalls,
|
|
177
|
+
...claimCalls,
|
|
178
|
+
...tokensToDisable.map(
|
|
179
|
+
(a) => this.prepareDisableToken(ca.creditFacade, a.token)
|
|
180
|
+
),
|
|
181
|
+
...this.prepareUpdateQuotas(ca.creditFacade, { minQuota, averageQuota })
|
|
182
|
+
];
|
|
183
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
184
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* unwraps staked tokens and optionally claims associated rewards; Should be remove after transition to 3.1
|
|
188
|
+
* @param acc
|
|
189
|
+
* @returns
|
|
190
|
+
*/
|
|
191
|
+
#prepareUnwrapAndWithdrawCallsV3(assets, claim, withdrawAll, creditManager) {
|
|
192
|
+
const network = this.sdk.provider.networkType;
|
|
193
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
194
|
+
const cmAdapters = suite.creditManager.adapters.values().reduce((acc, a) => {
|
|
195
|
+
const contractLc = a.targetContract.toLowerCase();
|
|
196
|
+
const adapterLc = a.address.toLowerCase();
|
|
197
|
+
acc[contractLc] = adapterLc;
|
|
198
|
+
return acc;
|
|
199
|
+
}, {});
|
|
200
|
+
const currentContractsData = Object.entries(
|
|
201
|
+
import_sdk_gov_legacy.contractsByNetwork[network]
|
|
202
|
+
).reduce(
|
|
203
|
+
(acc, [symbol, address]) => {
|
|
204
|
+
if (!!address && address !== import_addresses.NOT_DEPLOYED) {
|
|
205
|
+
acc[symbol] = address.toLowerCase();
|
|
206
|
+
}
|
|
207
|
+
return acc;
|
|
208
|
+
},
|
|
209
|
+
{}
|
|
210
|
+
);
|
|
211
|
+
const currentTokenData = Object.entries(import_sdk_gov_legacy.tokenDataByNetwork[network]).reduce(
|
|
212
|
+
(acc, [symbol, address]) => {
|
|
213
|
+
if (!!address && address !== import_addresses.NOT_DEPLOYED) {
|
|
214
|
+
acc[symbol] = address.toLowerCase();
|
|
215
|
+
}
|
|
216
|
+
return acc;
|
|
217
|
+
},
|
|
218
|
+
{}
|
|
219
|
+
);
|
|
220
|
+
const { aura, convex, sky } = assets.reduce(
|
|
221
|
+
(acc, a) => {
|
|
222
|
+
const symbol = import_sdk_gov_legacy.tokenSymbolByAddress[a.token];
|
|
223
|
+
if ((0, import_sdk_gov_legacy.isConvexStakedPhantomToken)(symbol)) {
|
|
224
|
+
acc.convex.push(a);
|
|
225
|
+
} else if ((0, import_sdk_gov_legacy.isAuraStakedToken)(symbol)) {
|
|
226
|
+
acc.aura.push(a);
|
|
227
|
+
} else if ((0, import_sdk_gov_legacy.isStakingRewardsPhantomToken)(symbol)) {
|
|
228
|
+
acc.sky.push(a);
|
|
229
|
+
}
|
|
230
|
+
return acc;
|
|
231
|
+
},
|
|
232
|
+
{ convex: [], aura: [], sky: [] }
|
|
233
|
+
);
|
|
234
|
+
const getWithdrawCall = (pool, a) => {
|
|
235
|
+
return withdrawAll ? this.#withdrawAllAndUnwrap_Convex(pool, claim) : this.#withdrawAndUnwrap_Convex(pool, a.balance, claim);
|
|
236
|
+
};
|
|
237
|
+
const getWithdrawCall_Rewards = (pool, a) => {
|
|
238
|
+
const calls = [
|
|
239
|
+
withdrawAll ? this.#withdrawAll_Rewards(pool) : this.#withdraw_Rewards(pool, a.balance),
|
|
240
|
+
...claim ? [this.#claim_Rewards(pool)] : []
|
|
241
|
+
];
|
|
242
|
+
return calls;
|
|
243
|
+
};
|
|
244
|
+
const convexStkCalls = convex.map((a) => {
|
|
245
|
+
const symbol = import_sdk_gov_legacy.tokenSymbolByAddress[a.token];
|
|
246
|
+
const { pool } = import_sdk_gov_legacy.convexTokens[symbol];
|
|
247
|
+
const poolAddress = currentContractsData[pool];
|
|
248
|
+
if (!poolAddress) {
|
|
249
|
+
throw new Error("Can't withdrawAllAndUnwrap_Convex (convex)");
|
|
250
|
+
}
|
|
251
|
+
const poolAddressLc = poolAddress.toLowerCase();
|
|
252
|
+
return getWithdrawCall(cmAdapters[poolAddressLc], a);
|
|
253
|
+
});
|
|
254
|
+
const auraStkCalls = aura.map((a) => {
|
|
255
|
+
const symbol = import_sdk_gov_legacy.tokenSymbolByAddress[a.token];
|
|
256
|
+
const { pool } = import_sdk_gov_legacy.auraTokens[symbol];
|
|
257
|
+
const poolAddress = currentContractsData[pool];
|
|
258
|
+
if (!poolAddress) {
|
|
259
|
+
throw new Error("Can't withdrawAllAndUnwrap_Convex (aura)");
|
|
260
|
+
}
|
|
261
|
+
const poolAddressLc = poolAddress.toLowerCase();
|
|
262
|
+
return getWithdrawCall(cmAdapters[poolAddressLc], a);
|
|
263
|
+
});
|
|
264
|
+
const skyStkCalls = sky.flatMap((a) => {
|
|
265
|
+
const symbol = import_sdk_gov_legacy.tokenSymbolByAddress[a.token];
|
|
266
|
+
const { pool } = import_sdk_gov_legacy.stakingRewardsTokens[symbol];
|
|
267
|
+
const poolAddress = currentContractsData[pool];
|
|
268
|
+
if (!poolAddress) {
|
|
269
|
+
throw new Error("Can't withdrawAllAndUnwrap_Convex (sky)");
|
|
270
|
+
}
|
|
271
|
+
const poolAddressLc = poolAddress.toLowerCase();
|
|
272
|
+
return getWithdrawCall_Rewards(cmAdapters[poolAddressLc], a);
|
|
273
|
+
});
|
|
274
|
+
const unwrapCalls = [...convexStkCalls, ...auraStkCalls, ...skyStkCalls];
|
|
275
|
+
const withdraw = assets.map((a) => {
|
|
276
|
+
const symbol = import_sdk_gov_legacy.tokenSymbolByAddress[a.token];
|
|
277
|
+
if ((0, import_sdk_gov_legacy.isConvexStakedPhantomToken)(symbol)) {
|
|
278
|
+
return {
|
|
279
|
+
...a,
|
|
280
|
+
token: currentTokenData[import_sdk_gov_legacy.convexStakedPhantomTokens[symbol].underlying]
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if ((0, import_sdk_gov_legacy.isAuraStakedToken)(symbol)) {
|
|
284
|
+
return {
|
|
285
|
+
...a,
|
|
286
|
+
token: currentTokenData[import_sdk_gov_legacy.auraStakedTokens[symbol].underlying]
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if ((0, import_sdk_gov_legacy.isStakingRewardsPhantomToken)(symbol)) {
|
|
290
|
+
return {
|
|
291
|
+
...a,
|
|
292
|
+
token: currentTokenData[import_sdk_gov_legacy.stakingRewardsTokens[symbol].underlying]
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return a;
|
|
296
|
+
});
|
|
297
|
+
return { unwrapCalls, assetsToWithdraw: withdraw };
|
|
298
|
+
}
|
|
299
|
+
#withdrawAndUnwrap_Convex(address, amount, claim) {
|
|
300
|
+
return {
|
|
301
|
+
target: address,
|
|
302
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
303
|
+
abi: (0, import_abitype.parseAbi)([
|
|
304
|
+
"function withdrawAndUnwrap(uint256, bool claim) returns (uint256 tokensToEnable, uint256 tokensToDisable)"
|
|
305
|
+
]),
|
|
306
|
+
functionName: "withdrawAndUnwrap",
|
|
307
|
+
args: [amount, claim]
|
|
308
|
+
})
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
#withdrawAllAndUnwrap_Convex(address, claim) {
|
|
312
|
+
return {
|
|
313
|
+
target: address,
|
|
314
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
315
|
+
abi: (0, import_abitype.parseAbi)([
|
|
316
|
+
"function withdrawDiffAndUnwrap(uint256 leftoverAmount, bool claim) returns (uint256 tokensToEnable, uint256 tokensToDisable)"
|
|
317
|
+
]),
|
|
318
|
+
functionName: "withdrawDiffAndUnwrap",
|
|
319
|
+
args: [1n, claim]
|
|
320
|
+
})
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
#withdrawAll_Rewards(address) {
|
|
324
|
+
return {
|
|
325
|
+
target: address,
|
|
326
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
327
|
+
abi: (0, import_abitype.parseAbi)([
|
|
328
|
+
"function withdrawDiff(uint256 leftoverAmount) external returns (bool useSafePrices)"
|
|
329
|
+
]),
|
|
330
|
+
functionName: "withdrawDiff",
|
|
331
|
+
args: [1n]
|
|
332
|
+
})
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
#withdraw_Rewards(address, amount) {
|
|
336
|
+
return {
|
|
337
|
+
target: address,
|
|
338
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
339
|
+
abi: (0, import_abitype.parseAbi)([
|
|
340
|
+
"function withdraw(uint256 amount) external returns (bool useSafePrices)"
|
|
341
|
+
]),
|
|
342
|
+
functionName: "withdraw",
|
|
343
|
+
args: [amount]
|
|
344
|
+
})
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
#claim_Rewards(address) {
|
|
348
|
+
return {
|
|
349
|
+
target: address,
|
|
350
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
351
|
+
abi: (0, import_abitype.parseAbi)([
|
|
352
|
+
"function getReward() external returns (bool useSafePrices)"
|
|
353
|
+
]),
|
|
354
|
+
functionName: "getReward",
|
|
355
|
+
args: []
|
|
356
|
+
})
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
361
|
+
0 && (module.exports = {
|
|
362
|
+
CreditAccountServiceV300
|
|
363
|
+
});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var CreditAccountsServiceV310_exports = {};
|
|
20
|
+
__export(CreditAccountsServiceV310_exports, {
|
|
21
|
+
CreditAccountServiceV310: () => CreditAccountServiceV310
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(CreditAccountsServiceV310_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
25
|
+
var import_v310 = require("../../abi/v310.js");
|
|
26
|
+
var import_math = require("../constants/math.js");
|
|
27
|
+
var import_AbstractCreditAccountsService = require("./AbstractCreditAccountsService.js");
|
|
28
|
+
var import_constants = require("./constants.js");
|
|
29
|
+
class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.AbstractCreditAccountService {
|
|
30
|
+
/**
|
|
31
|
+
* Implements {@link ICreditAccountsService.setBot}
|
|
32
|
+
*/
|
|
33
|
+
async setBot({
|
|
34
|
+
botAddress,
|
|
35
|
+
botBaseType,
|
|
36
|
+
stopBot,
|
|
37
|
+
creditAccount: ca
|
|
38
|
+
}) {
|
|
39
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
40
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
41
|
+
ca.creditManager,
|
|
42
|
+
ca,
|
|
43
|
+
void 0
|
|
44
|
+
);
|
|
45
|
+
const addBotCall = {
|
|
46
|
+
target: ca.creditFacade,
|
|
47
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
48
|
+
abi: import_v310.iCreditFacadeMulticallV310Abi,
|
|
49
|
+
functionName: "setBotPermissions",
|
|
50
|
+
args: [botAddress, stopBot ? 0n : import_constants.PERMISSION_BY_TYPE[botBaseType]]
|
|
51
|
+
})
|
|
52
|
+
};
|
|
53
|
+
const calls = [...priceUpdatesCalls, addBotCall];
|
|
54
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
55
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Implements {@link ICreditAccountsService.withdrawCollateral}
|
|
59
|
+
*/
|
|
60
|
+
async withdrawCollateral({
|
|
61
|
+
creditAccount,
|
|
62
|
+
assetsToWithdraw,
|
|
63
|
+
to,
|
|
64
|
+
minQuota,
|
|
65
|
+
averageQuota
|
|
66
|
+
}) {
|
|
67
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
68
|
+
creditAccount.creditManager
|
|
69
|
+
);
|
|
70
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
71
|
+
creditAccount.creditManager,
|
|
72
|
+
creditAccount,
|
|
73
|
+
void 0
|
|
74
|
+
);
|
|
75
|
+
const calls = [
|
|
76
|
+
...priceUpdatesCalls,
|
|
77
|
+
...assetsToWithdraw.map(
|
|
78
|
+
(a) => this.prepareWithdrawToken(
|
|
79
|
+
creditAccount.creditFacade,
|
|
80
|
+
a.token,
|
|
81
|
+
a.balance,
|
|
82
|
+
to
|
|
83
|
+
)
|
|
84
|
+
),
|
|
85
|
+
...this.prepareUpdateQuotas(creditAccount.creditFacade, {
|
|
86
|
+
minQuota,
|
|
87
|
+
averageQuota
|
|
88
|
+
})
|
|
89
|
+
];
|
|
90
|
+
const tx = cm.creditFacade.multicall(creditAccount.creditAccount, calls);
|
|
91
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Implements {@link ICreditAccountsService.repayCreditAccount}
|
|
95
|
+
*/
|
|
96
|
+
async repayCreditAccount({
|
|
97
|
+
operation,
|
|
98
|
+
collateralAssets,
|
|
99
|
+
assetsToWithdraw,
|
|
100
|
+
creditAccount: ca,
|
|
101
|
+
permits,
|
|
102
|
+
to
|
|
103
|
+
}) {
|
|
104
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
105
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
106
|
+
const router = this.sdk.routerFor(ca);
|
|
107
|
+
const claimPath = await router.findClaimAllRewards({
|
|
108
|
+
calls: [],
|
|
109
|
+
creditAccount: ca
|
|
110
|
+
});
|
|
111
|
+
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
112
|
+
ca.creditManager,
|
|
113
|
+
ca,
|
|
114
|
+
void 0
|
|
115
|
+
);
|
|
116
|
+
const calls = [
|
|
117
|
+
...operation === "close" ? [] : priceUpdates,
|
|
118
|
+
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
119
|
+
...this.prepareDisableQuotas(ca),
|
|
120
|
+
...this.prepareDecreaseDebt(ca),
|
|
121
|
+
...claimPath.calls,
|
|
122
|
+
...this.prepareDisableTokens(ca),
|
|
123
|
+
...assetsToWithdraw.map(
|
|
124
|
+
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
125
|
+
)
|
|
126
|
+
];
|
|
127
|
+
const tx = operation === "close" ? cm.creditFacade.closeCreditAccount(ca.creditAccount, calls) : cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
128
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Implements {@link ICreditAccountsService.repayAndLiquidateCreditAccount}
|
|
132
|
+
*/
|
|
133
|
+
async repayAndLiquidateCreditAccount({
|
|
134
|
+
collateralAssets,
|
|
135
|
+
assetsToWithdraw,
|
|
136
|
+
creditAccount: ca,
|
|
137
|
+
permits,
|
|
138
|
+
to
|
|
139
|
+
}) {
|
|
140
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
141
|
+
const router = this.sdk.routerFor(ca);
|
|
142
|
+
const claimPath = await router.findClaimAllRewards({
|
|
143
|
+
calls: [],
|
|
144
|
+
creditAccount: ca
|
|
145
|
+
});
|
|
146
|
+
const priceUpdates = await this.getPriceUpdatesForFacade(
|
|
147
|
+
ca.creditManager,
|
|
148
|
+
ca,
|
|
149
|
+
void 0
|
|
150
|
+
);
|
|
151
|
+
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
152
|
+
const calls = [
|
|
153
|
+
...priceUpdates,
|
|
154
|
+
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
155
|
+
...claimPath.calls,
|
|
156
|
+
...assetsToWithdraw.map(
|
|
157
|
+
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
158
|
+
)
|
|
159
|
+
];
|
|
160
|
+
const tx = cm.creditFacade.liquidateCreditAccount(
|
|
161
|
+
ca.creditAccount,
|
|
162
|
+
to,
|
|
163
|
+
calls
|
|
164
|
+
);
|
|
165
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Implements {@link ICreditAccountsService.claimFarmRewards}
|
|
169
|
+
*/
|
|
170
|
+
async claimFarmRewards({
|
|
171
|
+
calls: legacyCalls,
|
|
172
|
+
creditAccount: ca,
|
|
173
|
+
minQuota,
|
|
174
|
+
averageQuota
|
|
175
|
+
}) {
|
|
176
|
+
const cm = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
177
|
+
const router = this.sdk.routerFor(ca);
|
|
178
|
+
const claimPath = await router.findClaimAllRewards({
|
|
179
|
+
calls: legacyCalls,
|
|
180
|
+
creditAccount: ca
|
|
181
|
+
});
|
|
182
|
+
if (claimPath.calls.length === 0) throw new Error("No path to execute");
|
|
183
|
+
const priceUpdatesCalls = await this.getPriceUpdatesForFacade(
|
|
184
|
+
ca.creditManager,
|
|
185
|
+
ca,
|
|
186
|
+
averageQuota
|
|
187
|
+
);
|
|
188
|
+
const calls = [
|
|
189
|
+
...priceUpdatesCalls,
|
|
190
|
+
...claimPath.calls,
|
|
191
|
+
...this.prepareUpdateQuotas(ca.creditFacade, { minQuota, averageQuota })
|
|
192
|
+
];
|
|
193
|
+
const tx = cm.creditFacade.multicall(ca.creditAccount, calls);
|
|
194
|
+
return { tx, calls, creditFacade: cm.creditFacade };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {
|
|
199
|
+
CreditAccountServiceV310
|
|
200
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
PERMISSION_BY_TYPE: () => PERMISSION_BY_TYPE
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
var import_bot_permissions = require("../constants/bot-permissions.js");
|
|
25
|
+
const PERMISSION_BY_TYPE = {
|
|
26
|
+
LIQUIDATION_PROTECTION: BigInt(
|
|
27
|
+
import_bot_permissions.BotPermissions.ADD_COLLATERAL | import_bot_permissions.BotPermissions.WITHDRAW_COLLATERAL | import_bot_permissions.BotPermissions.DECREASE_DEBT
|
|
28
|
+
)
|
|
29
|
+
};
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
PERMISSION_BY_TYPE
|
|
33
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createCreditAccountService_exports = {};
|
|
20
|
+
__export(createCreditAccountService_exports, {
|
|
21
|
+
createCreditAccountService: () => createCreditAccountService
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createCreditAccountService_exports);
|
|
24
|
+
var import_constants = require("../constants/index.js");
|
|
25
|
+
var import_CreditAccountsServiceV300 = require("./CreditAccountsServiceV300.js");
|
|
26
|
+
var import_CreditAccountsServiceV310 = require("./CreditAccountsServiceV310.js");
|
|
27
|
+
function createCreditAccountService(sdk, version) {
|
|
28
|
+
if ((0, import_constants.isV300)(version)) {
|
|
29
|
+
return new import_CreditAccountsServiceV300.CreditAccountServiceV300(sdk);
|
|
30
|
+
}
|
|
31
|
+
if ((0, import_constants.isV310)(version)) {
|
|
32
|
+
return new import_CreditAccountsServiceV310.CreditAccountServiceV310(sdk);
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`Unsupported Credit Account Service version ${version}`);
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
createCreditAccountService
|
|
39
|
+
});
|
|
@@ -15,10 +15,12 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var accounts_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(accounts_exports);
|
|
18
|
-
__reExport(accounts_exports, require("./
|
|
18
|
+
__reExport(accounts_exports, require("./constants.js"), module.exports);
|
|
19
|
+
__reExport(accounts_exports, require("./createCreditAccountService.js"), module.exports);
|
|
19
20
|
__reExport(accounts_exports, require("./types.js"), module.exports);
|
|
20
21
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
22
|
0 && (module.exports = {
|
|
22
|
-
...require("./
|
|
23
|
+
...require("./constants.js"),
|
|
24
|
+
...require("./createCreditAccountService.js"),
|
|
23
25
|
...require("./types.js")
|
|
24
26
|
});
|
|
@@ -179,6 +179,14 @@ class RouterV300Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
179
179
|
calls: [...result.calls]
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Implements {@link IRouterContract.findClaimAllRewards}
|
|
184
|
+
*/
|
|
185
|
+
async findClaimAllRewards(props) {
|
|
186
|
+
return {
|
|
187
|
+
calls: props.calls
|
|
188
|
+
};
|
|
189
|
+
}
|
|
182
190
|
/**
|
|
183
191
|
* Implements {@link IRouterContract.findBestClosePath}
|
|
184
192
|
*/
|
|
@@ -141,6 +141,30 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
141
141
|
calls: [...result.calls]
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Implements {@link IRouterContract.findClaimAllRewards}
|
|
146
|
+
*/
|
|
147
|
+
async findClaimAllRewards(props) {
|
|
148
|
+
const tData = props.creditAccount.tokens.map((a) => ({
|
|
149
|
+
balance: a.balance,
|
|
150
|
+
claimRewards: true,
|
|
151
|
+
leftoverBalance: a.balance,
|
|
152
|
+
numSplits: 0n,
|
|
153
|
+
token: a.token
|
|
154
|
+
}));
|
|
155
|
+
return {
|
|
156
|
+
calls: [
|
|
157
|
+
{
|
|
158
|
+
target: this.address,
|
|
159
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
160
|
+
abi: this.abi,
|
|
161
|
+
functionName: "processClaims",
|
|
162
|
+
args: [props.creditAccount.creditAccount, tData]
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
144
168
|
/**
|
|
145
169
|
* Implements {@link IRouterContract.findBestClosePath}
|
|
146
170
|
*/
|