@gearbox-protocol/sdk 3.0.0-vfour.14 → 3.0.0-vfour.140
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 +0 -1
- package/dist/cjs/dev/index.cjs +541 -27
- package/dist/cjs/dev/index.d.ts +115 -4
- package/dist/cjs/sdk/index.cjs +62039 -11380
- package/dist/cjs/sdk/index.d.ts +85278 -10498
- package/dist/esm/dev/index.d.mts +115 -4
- package/dist/esm/dev/index.mjs +536 -29
- package/dist/esm/sdk/index.d.mts +85278 -10498
- package/dist/esm/sdk/index.mjs +62019 -11546
- package/package.json +20 -16
package/README.md
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Gearbox core types SDK
|
|
4
4
|
Contains core datastructures which are used across multiple gearbox services
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
### Important information for contributors
|
|
8
7
|
|
|
9
8
|
As a contributor to the Gearbox Protocol GitHub repository, your pull requests indicate acceptance of our Gearbox Contribution Agreement. This agreement outlines that you assign the Intellectual Property Rights of your contributions to the Gearbox Foundation. This helps safeguard the Gearbox protocol and ensure the accumulation of its intellectual property. Contributions become part of the repository and may be used for various purposes, including commercial. As recognition for your expertise and work, you receive the opportunity to participate in the protocol's development and the potential to see your work integrated within it. The full Gearbox Contribution Agreement is accessible within the [repository](/ContributionAgreement) for comprehensive understanding. [Let's innovate together!]
|
package/dist/cjs/dev/index.cjs
CHANGED
|
@@ -1,9 +1,326 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var sdk = require('../sdk');
|
|
4
3
|
var viem = require('viem');
|
|
4
|
+
var accounts = require('viem/accounts');
|
|
5
|
+
var sdk = require('../sdk');
|
|
6
|
+
var promises = require('fs/promises');
|
|
5
7
|
|
|
6
|
-
// src/dev/
|
|
8
|
+
// src/dev/AccountOpener.ts
|
|
9
|
+
function createAnvilClient({
|
|
10
|
+
chain,
|
|
11
|
+
transport
|
|
12
|
+
}) {
|
|
13
|
+
return viem.createTestClient(
|
|
14
|
+
{
|
|
15
|
+
chain,
|
|
16
|
+
mode: "anvil",
|
|
17
|
+
transport,
|
|
18
|
+
cacheTime: 0
|
|
19
|
+
}
|
|
20
|
+
).extend(viem.publicActions).extend(viem.walletActions).extend((client) => ({
|
|
21
|
+
anvilNodeInfo: () => anvilNodeInfo(client),
|
|
22
|
+
isAnvil: () => isAnvil(client),
|
|
23
|
+
evmMineDetailed: (timestamp) => evmMineDetailed(client, timestamp)
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
async function isAnvil(client) {
|
|
27
|
+
try {
|
|
28
|
+
const resp = await client.request({
|
|
29
|
+
method: "anvil_nodeInfo",
|
|
30
|
+
params: []
|
|
31
|
+
});
|
|
32
|
+
return !!resp.currentBlockNumber;
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function anvilNodeInfo(client) {
|
|
38
|
+
return client.request({
|
|
39
|
+
method: "anvil_nodeInfo",
|
|
40
|
+
params: []
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function evmMineDetailed(client, timestamp) {
|
|
44
|
+
try {
|
|
45
|
+
const [block] = await client.request({
|
|
46
|
+
method: "evm_mine_detailed",
|
|
47
|
+
params: [viem.toHex(timestamp)]
|
|
48
|
+
});
|
|
49
|
+
return block;
|
|
50
|
+
} catch {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/dev/AccountOpener.ts
|
|
56
|
+
var AccountOpener = class {
|
|
57
|
+
#service;
|
|
58
|
+
#anvil;
|
|
59
|
+
#logger;
|
|
60
|
+
#borrower;
|
|
61
|
+
#faucet;
|
|
62
|
+
constructor(service, options = {}) {
|
|
63
|
+
this.#service = service;
|
|
64
|
+
this.#logger = sdk.childLogger("AccountOpener", service.sdk.logger);
|
|
65
|
+
this.#anvil = createAnvilClient({
|
|
66
|
+
chain: service.sdk.provider.chain,
|
|
67
|
+
transport: service.sdk.provider.transport
|
|
68
|
+
});
|
|
69
|
+
this.#faucet = options.faucet ?? service.sdk.addressProvider.getAddress("FAUCET");
|
|
70
|
+
}
|
|
71
|
+
get borrower() {
|
|
72
|
+
if (!this.#borrower) {
|
|
73
|
+
throw new Error("borrower can be used only after openCreditAccounts");
|
|
74
|
+
}
|
|
75
|
+
return this.#borrower.address;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Tries to open account with underlying only in each CM
|
|
79
|
+
*/
|
|
80
|
+
async openCreditAccounts(targets) {
|
|
81
|
+
const borrower = await this.#prepareBorrower(targets);
|
|
82
|
+
for (const target of targets) {
|
|
83
|
+
try {
|
|
84
|
+
await this.#openAccount(target);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
this.#logger?.error(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const accounts = await this.#service.getCreditAccounts({
|
|
90
|
+
owner: borrower.address
|
|
91
|
+
});
|
|
92
|
+
this.#logger?.info(`opened ${accounts.length} accounts`);
|
|
93
|
+
}
|
|
94
|
+
async #openAccount({
|
|
95
|
+
creditManager,
|
|
96
|
+
collateral,
|
|
97
|
+
leverage = 4,
|
|
98
|
+
slippage = 50
|
|
99
|
+
}) {
|
|
100
|
+
const borrower = await this.#getBorrower();
|
|
101
|
+
const cm = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
102
|
+
const symbol = this.sdk.tokensMeta.symbol(collateral);
|
|
103
|
+
const logger = this.#logger?.child?.({
|
|
104
|
+
creditManager: cm.name,
|
|
105
|
+
collateral: symbol
|
|
106
|
+
});
|
|
107
|
+
const { minDebt, underlying } = cm.creditFacade;
|
|
108
|
+
const expectedBalances = [];
|
|
109
|
+
const leftoverBalances = [];
|
|
110
|
+
for (const t of Object.keys(cm.collateralTokens)) {
|
|
111
|
+
const token = t;
|
|
112
|
+
expectedBalances.push({
|
|
113
|
+
token,
|
|
114
|
+
balance: token === underlying ? BigInt(leverage) * minDebt : 1n
|
|
115
|
+
});
|
|
116
|
+
leftoverBalances.push({
|
|
117
|
+
token,
|
|
118
|
+
balance: 1n
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
logger?.debug("looking for open strategy");
|
|
122
|
+
const strategy = await this.sdk.router.findOpenStrategyPath({
|
|
123
|
+
creditManager: cm.creditManager,
|
|
124
|
+
expectedBalances,
|
|
125
|
+
leftoverBalances,
|
|
126
|
+
slippage,
|
|
127
|
+
target: collateral
|
|
128
|
+
});
|
|
129
|
+
logger?.debug("found open strategy");
|
|
130
|
+
const { tx, calls } = await this.#service.openCA({
|
|
131
|
+
creditManager: cm.creditManager.address,
|
|
132
|
+
averageQuota: [],
|
|
133
|
+
minQuota: [],
|
|
134
|
+
collateral: [{ token: underlying, balance: minDebt }],
|
|
135
|
+
debt: minDebt * BigInt(leverage - 1),
|
|
136
|
+
calls: strategy.calls,
|
|
137
|
+
ethAmount: 0n,
|
|
138
|
+
permits: {},
|
|
139
|
+
to: borrower.address,
|
|
140
|
+
referralCode: 0n
|
|
141
|
+
});
|
|
142
|
+
for (let i = 0; i < calls.length; i++) {
|
|
143
|
+
const call = calls[i];
|
|
144
|
+
logger?.debug(
|
|
145
|
+
`call #${i + 1}: ${this.sdk.parseFunctionData(call.target, call.callData)}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
logger?.debug("prepared open account transaction");
|
|
149
|
+
const hash = await sdk.sendRawTx(this.#anvil, {
|
|
150
|
+
tx,
|
|
151
|
+
account: borrower
|
|
152
|
+
});
|
|
153
|
+
logger?.debug(`send transaction ${hash}`);
|
|
154
|
+
const receipt = await this.#anvil.waitForTransactionReceipt({ hash });
|
|
155
|
+
if (receipt.status === "reverted") {
|
|
156
|
+
throw new Error(`open credit account tx ${hash} reverted`);
|
|
157
|
+
}
|
|
158
|
+
logger?.debug(
|
|
159
|
+
`opened credit account in ${cm.name} with collateral ${symbol}`
|
|
160
|
+
);
|
|
161
|
+
return this.getOpenedAccounts();
|
|
162
|
+
}
|
|
163
|
+
async getOpenedAccounts() {
|
|
164
|
+
return await this.#service.getCreditAccounts({
|
|
165
|
+
owner: this.borrower
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates borrower wallet,
|
|
170
|
+
* Sets ETH balance,
|
|
171
|
+
* Gets tokens from faucet,
|
|
172
|
+
* Approves collateral tokens to credit manager,
|
|
173
|
+
* Gets DEGEN_NFT,
|
|
174
|
+
*/
|
|
175
|
+
async #prepareBorrower(targets) {
|
|
176
|
+
const borrower = await this.#getBorrower();
|
|
177
|
+
let claimUSD = 0n;
|
|
178
|
+
let degenNFTS = {};
|
|
179
|
+
for (const target of targets) {
|
|
180
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
181
|
+
target.creditManager
|
|
182
|
+
);
|
|
183
|
+
const market = this.sdk.marketRegister.findByCreditManager(
|
|
184
|
+
target.creditManager
|
|
185
|
+
);
|
|
186
|
+
const { minDebt, degenNFT } = cm.creditFacade;
|
|
187
|
+
claimUSD += market.priceOracle.convertToUSD(cm.underlying, minDebt);
|
|
188
|
+
if (viem.isAddress(degenNFT) && degenNFT !== sdk.ADDRESS_0X0) {
|
|
189
|
+
degenNFTS[degenNFT] = (degenNFTS[degenNFT] ?? 0) + 1;
|
|
190
|
+
}
|
|
191
|
+
for (const t of Object.keys(cm.collateralTokens)) {
|
|
192
|
+
await this.#approve(t, cm);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
claimUSD = claimUSD * 11n / 10n;
|
|
196
|
+
this.#logger?.debug(`claiming ${sdk.formatBN(claimUSD, 8)} USD from faucet`);
|
|
197
|
+
let hash = await this.#anvil.writeContract({
|
|
198
|
+
account: borrower,
|
|
199
|
+
address: this.#faucet,
|
|
200
|
+
abi: [
|
|
201
|
+
{
|
|
202
|
+
type: "function",
|
|
203
|
+
inputs: [
|
|
204
|
+
{ name: "amountUSD", internalType: "uint256", type: "uint256" }
|
|
205
|
+
],
|
|
206
|
+
name: "claim",
|
|
207
|
+
outputs: [],
|
|
208
|
+
stateMutability: "nonpayable"
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
functionName: "claim",
|
|
212
|
+
args: [claimUSD],
|
|
213
|
+
chain: this.#anvil.chain
|
|
214
|
+
});
|
|
215
|
+
let receipt = await this.#anvil.waitForTransactionReceipt({
|
|
216
|
+
hash
|
|
217
|
+
});
|
|
218
|
+
if (receipt.status === "reverted") {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`borrower ${borrower.address} failed to claimed equivalent of ${sdk.formatBN(claimUSD, 8)} USD from faucet, tx: ${hash}`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
this.#logger?.debug(
|
|
224
|
+
`borrower ${borrower.address} claimed equivalent of ${sdk.formatBN(claimUSD, 8)} USD from faucet, tx: ${hash}`
|
|
225
|
+
);
|
|
226
|
+
for (const [degenNFT, amount] of Object.entries(degenNFTS)) {
|
|
227
|
+
await this.#mintDegenNft(degenNFT, borrower.address, amount);
|
|
228
|
+
}
|
|
229
|
+
this.#logger?.debug("prepared borrower");
|
|
230
|
+
return borrower;
|
|
231
|
+
}
|
|
232
|
+
async #approve(token, cm) {
|
|
233
|
+
const borrower = await this.#getBorrower();
|
|
234
|
+
try {
|
|
235
|
+
const hash = await this.#anvil.writeContract({
|
|
236
|
+
account: borrower,
|
|
237
|
+
address: token,
|
|
238
|
+
abi: sdk.ierc20Abi,
|
|
239
|
+
functionName: "approve",
|
|
240
|
+
args: [cm.creditManager.address, sdk.MAX_UINT256],
|
|
241
|
+
chain: this.#anvil.chain
|
|
242
|
+
});
|
|
243
|
+
const receipt = await this.#anvil.waitForTransactionReceipt({
|
|
244
|
+
hash
|
|
245
|
+
});
|
|
246
|
+
if (receipt.status === "reverted") {
|
|
247
|
+
this.#logger?.error(
|
|
248
|
+
`failed to allowed credit manager ${cm.creditManager.name} to spend ${token}, tx reverted: ${hash}`
|
|
249
|
+
);
|
|
250
|
+
} else {
|
|
251
|
+
this.#logger?.debug(
|
|
252
|
+
`allowed credit manager ${cm.creditManager.name} to spend ${token}, tx: ${hash}`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
} catch (e) {
|
|
256
|
+
this.#logger?.error(
|
|
257
|
+
`failed to allowed credit manager ${cm.creditManager.name} to spend ${token}: ${e}`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async #mintDegenNft(degenNFT, to, amount) {
|
|
262
|
+
if (amount <= 0) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
let minter;
|
|
266
|
+
try {
|
|
267
|
+
minter = await this.#anvil.readContract({
|
|
268
|
+
address: degenNFT,
|
|
269
|
+
abi: sdk.iDegenNftv2Abi,
|
|
270
|
+
functionName: "minter"
|
|
271
|
+
});
|
|
272
|
+
} catch (e) {
|
|
273
|
+
this.#logger?.error(`failed to get minter of degenNFT ${degenNFT}: ${e}`);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
await this.#anvil.impersonateAccount({ address: minter });
|
|
278
|
+
await this.#anvil.setBalance({
|
|
279
|
+
address: minter,
|
|
280
|
+
value: viem.parseEther("100")
|
|
281
|
+
});
|
|
282
|
+
const hash = await this.#anvil.writeContract({
|
|
283
|
+
account: minter,
|
|
284
|
+
address: degenNFT,
|
|
285
|
+
abi: sdk.iDegenNftv2Abi,
|
|
286
|
+
functionName: "mint",
|
|
287
|
+
args: [to, BigInt(amount)],
|
|
288
|
+
chain: this.#anvil.chain
|
|
289
|
+
});
|
|
290
|
+
const receipt = await this.#anvil.waitForTransactionReceipt({
|
|
291
|
+
hash
|
|
292
|
+
});
|
|
293
|
+
if (receipt.status === "reverted") {
|
|
294
|
+
this.#logger?.error(
|
|
295
|
+
`failed to mint ${amount} degenNFT ${degenNFT} to borrower ${to}, tx reverted: ${hash}`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
this.#logger?.debug(
|
|
299
|
+
`minted ${amount} degenNFT ${degenNFT} to borrower ${to}, tx: ${hash}`
|
|
300
|
+
);
|
|
301
|
+
} catch (e) {
|
|
302
|
+
this.#logger?.error(
|
|
303
|
+
`failed to mint ${amount} degenNFT ${degenNFT} to borrower ${to}: ${e}`
|
|
304
|
+
);
|
|
305
|
+
} finally {
|
|
306
|
+
await this.#anvil.stopImpersonatingAccount({ address: minter });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
async #getBorrower() {
|
|
310
|
+
if (!this.#borrower) {
|
|
311
|
+
this.#borrower = accounts.privateKeyToAccount(accounts.generatePrivateKey());
|
|
312
|
+
await this.#anvil.setBalance({
|
|
313
|
+
address: this.#borrower.address,
|
|
314
|
+
value: viem.parseEther("100")
|
|
315
|
+
});
|
|
316
|
+
this.#logger?.info(`created borrower ${this.#borrower.address}`);
|
|
317
|
+
}
|
|
318
|
+
return this.#borrower;
|
|
319
|
+
}
|
|
320
|
+
get sdk() {
|
|
321
|
+
return this.#service.sdk;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
7
324
|
async function calcLiquidatableLTs(sdk$1, ca, factor = 9990n, logger) {
|
|
8
325
|
const cm = sdk$1.marketRegister.findCreditManager(ca.creditManager);
|
|
9
326
|
const market = sdk$1.marketRegister.findByCreditManager(ca.creditManager);
|
|
@@ -42,13 +359,101 @@ async function calcLiquidatableLTs(sdk$1, ca, factor = 9990n, logger) {
|
|
|
42
359
|
if (token !== ca.underlying) {
|
|
43
360
|
const newLT = oldLT * k / sdk.WAD;
|
|
44
361
|
logger?.debug(
|
|
45
|
-
`proposed ${sdk$1.
|
|
362
|
+
`proposed ${sdk$1.tokensMeta.symbol(token)} LT change: ${oldLT} => ${newLT} `
|
|
46
363
|
);
|
|
47
364
|
result[token] = Number(newLT);
|
|
48
365
|
}
|
|
49
366
|
}
|
|
50
367
|
return result;
|
|
51
368
|
}
|
|
369
|
+
var SDKExample = class {
|
|
370
|
+
#sdk;
|
|
371
|
+
#logger;
|
|
372
|
+
constructor(logger) {
|
|
373
|
+
this.#logger = logger;
|
|
374
|
+
}
|
|
375
|
+
async run(opts) {
|
|
376
|
+
const {
|
|
377
|
+
addressProvider: ap,
|
|
378
|
+
addressProviderJson,
|
|
379
|
+
marketConfigurator: mc,
|
|
380
|
+
marketConfiguratorJson,
|
|
381
|
+
anvilUrl = "http://127.0.0.1:8545",
|
|
382
|
+
outFile
|
|
383
|
+
} = opts;
|
|
384
|
+
const addressProvider = await this.#readConfigAddress(
|
|
385
|
+
"addressProvider",
|
|
386
|
+
ap,
|
|
387
|
+
addressProviderJson
|
|
388
|
+
);
|
|
389
|
+
const marketConfigurator = await this.#readConfigAddress(
|
|
390
|
+
"marketConfigurator",
|
|
391
|
+
mc,
|
|
392
|
+
marketConfiguratorJson
|
|
393
|
+
);
|
|
394
|
+
this.#sdk = await sdk.GearboxSDK.attach({
|
|
395
|
+
rpcURLs: [anvilUrl],
|
|
396
|
+
timeout: 48e4,
|
|
397
|
+
addressProvider,
|
|
398
|
+
logger: this.#logger,
|
|
399
|
+
ignoreUpdateablePrices: true,
|
|
400
|
+
marketConfigurators: [marketConfigurator]
|
|
401
|
+
});
|
|
402
|
+
const puTx = await this.#sdk.priceFeeds.getUpdatePriceFeedsTx([
|
|
403
|
+
marketConfigurator
|
|
404
|
+
]);
|
|
405
|
+
const updater = viem.createWalletClient({
|
|
406
|
+
account: accounts.privateKeyToAccount(
|
|
407
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
|
|
408
|
+
// well-known anvil private key
|
|
409
|
+
),
|
|
410
|
+
transport: viem.http(anvilUrl)
|
|
411
|
+
});
|
|
412
|
+
const publicClient = viem.createPublicClient({
|
|
413
|
+
transport: viem.http(anvilUrl)
|
|
414
|
+
});
|
|
415
|
+
const hash = await sdk.sendRawTx(updater, { tx: puTx });
|
|
416
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
417
|
+
await this.#sdk.marketRegister.loadMarkets([marketConfigurator], true);
|
|
418
|
+
this.#logger?.info("attached sdk");
|
|
419
|
+
if (outFile) {
|
|
420
|
+
try {
|
|
421
|
+
await promises.writeFile(
|
|
422
|
+
outFile,
|
|
423
|
+
sdk.json_stringify(this.#sdk.stateHuman()),
|
|
424
|
+
"utf-8"
|
|
425
|
+
);
|
|
426
|
+
} catch (e) {
|
|
427
|
+
this.#logger?.error(`failed to write to ${outFile}: ${e}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async #readConfigAddress(name, value, file) {
|
|
432
|
+
let result = value;
|
|
433
|
+
if (!result) {
|
|
434
|
+
if (!file) {
|
|
435
|
+
throw new Error(`${name} is not specified`);
|
|
436
|
+
}
|
|
437
|
+
this.#logger?.debug(`reading ${name} json ${file}`);
|
|
438
|
+
const apFile = await promises.readFile(file, "utf-8").then(JSON.parse);
|
|
439
|
+
result = apFile[name];
|
|
440
|
+
}
|
|
441
|
+
if (!result) {
|
|
442
|
+
throw new Error(`${name} is not specified`);
|
|
443
|
+
}
|
|
444
|
+
if (!viem.isAddress(result)) {
|
|
445
|
+
throw new Error(`${name} is not a valid address: ${result}`);
|
|
446
|
+
}
|
|
447
|
+
this.#logger?.info(`using ${name} ${result}`);
|
|
448
|
+
return result;
|
|
449
|
+
}
|
|
450
|
+
get sdk() {
|
|
451
|
+
if (!this.#sdk) {
|
|
452
|
+
throw new Error("sdk is not attached");
|
|
453
|
+
}
|
|
454
|
+
return this.#sdk;
|
|
455
|
+
}
|
|
456
|
+
};
|
|
52
457
|
|
|
53
458
|
// src/dev/abi/v3.ts
|
|
54
459
|
var iaclAbi = [
|
|
@@ -150,6 +555,21 @@ var iaclAbi = [
|
|
|
150
555
|
name: "AddressNotUnpausableAdminException"
|
|
151
556
|
}
|
|
152
557
|
];
|
|
558
|
+
var iaclTraitAbi = [
|
|
559
|
+
{
|
|
560
|
+
type: "function",
|
|
561
|
+
name: "acl",
|
|
562
|
+
inputs: [],
|
|
563
|
+
outputs: [
|
|
564
|
+
{
|
|
565
|
+
name: "",
|
|
566
|
+
type: "address",
|
|
567
|
+
internalType: "address"
|
|
568
|
+
}
|
|
569
|
+
],
|
|
570
|
+
stateMutability: "view"
|
|
571
|
+
}
|
|
572
|
+
];
|
|
153
573
|
var iCreditConfiguratorV3Abi = [
|
|
154
574
|
{
|
|
155
575
|
type: "function",
|
|
@@ -1413,17 +1833,17 @@ var iCreditManagerV3Abi = [
|
|
|
1413
1833
|
];
|
|
1414
1834
|
|
|
1415
1835
|
// src/dev/setLTs.ts
|
|
1416
|
-
async function setLTs(
|
|
1417
|
-
const aclAddr =
|
|
1418
|
-
|
|
1836
|
+
async function setLTs(anvil, cm, newLTs, logger) {
|
|
1837
|
+
const aclAddr = await anvil.readContract({
|
|
1838
|
+
address: cm.creditConfigurator,
|
|
1839
|
+
abi: iaclTraitAbi,
|
|
1840
|
+
functionName: "acl"
|
|
1841
|
+
});
|
|
1842
|
+
const configuratorAddr = await anvil.readContract({
|
|
1419
1843
|
address: aclAddr,
|
|
1420
1844
|
abi: iaclAbi,
|
|
1421
1845
|
functionName: "owner"
|
|
1422
1846
|
});
|
|
1423
|
-
const anvil = sdk.createAnvilClient({
|
|
1424
|
-
transport: sdk$1.provider.transport,
|
|
1425
|
-
chain: sdk$1.provider.chain
|
|
1426
|
-
});
|
|
1427
1847
|
await anvil.impersonateAccount({
|
|
1428
1848
|
address: configuratorAddr
|
|
1429
1849
|
});
|
|
@@ -1432,28 +1852,122 @@ async function setLTs(sdk$1, cm, newLTs, logger) {
|
|
|
1432
1852
|
value: viem.parseEther("100")
|
|
1433
1853
|
});
|
|
1434
1854
|
for (const [t, lt] of Object.entries(newLTs)) {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
`set ${
|
|
1451
|
-
|
|
1855
|
+
try {
|
|
1856
|
+
await anvil.writeContract({
|
|
1857
|
+
chain: anvil.chain,
|
|
1858
|
+
address: cm.creditConfigurator,
|
|
1859
|
+
account: configuratorAddr,
|
|
1860
|
+
abi: iCreditConfiguratorV3Abi,
|
|
1861
|
+
functionName: "setLiquidationThreshold",
|
|
1862
|
+
args: [t, lt]
|
|
1863
|
+
});
|
|
1864
|
+
const newLT = await anvil.readContract({
|
|
1865
|
+
address: cm.address,
|
|
1866
|
+
abi: iCreditManagerV3Abi,
|
|
1867
|
+
functionName: "liquidationThresholds",
|
|
1868
|
+
args: [t]
|
|
1869
|
+
});
|
|
1870
|
+
logger?.debug(`set ${t} LT to ${newLT}`);
|
|
1871
|
+
} catch {
|
|
1872
|
+
}
|
|
1452
1873
|
}
|
|
1453
1874
|
await anvil.stopImpersonatingAccount({
|
|
1454
1875
|
address: configuratorAddr
|
|
1455
1876
|
});
|
|
1456
1877
|
}
|
|
1878
|
+
async function setLTZero(anvil, cm, logger) {
|
|
1879
|
+
const aclAddr = await anvil.readContract({
|
|
1880
|
+
address: cm.creditConfigurator,
|
|
1881
|
+
abi: iaclTraitAbi,
|
|
1882
|
+
functionName: "acl"
|
|
1883
|
+
});
|
|
1884
|
+
const configuratorAddr = await anvil.readContract({
|
|
1885
|
+
address: aclAddr,
|
|
1886
|
+
abi: iaclAbi,
|
|
1887
|
+
functionName: "owner"
|
|
1888
|
+
});
|
|
1889
|
+
await anvil.impersonateAccount({
|
|
1890
|
+
address: configuratorAddr
|
|
1891
|
+
});
|
|
1892
|
+
await anvil.setBalance({
|
|
1893
|
+
address: configuratorAddr,
|
|
1894
|
+
value: viem.parseEther("100")
|
|
1895
|
+
});
|
|
1896
|
+
let hash = await anvil.writeContract({
|
|
1897
|
+
chain: anvil.chain,
|
|
1898
|
+
address: cm.creditConfigurator,
|
|
1899
|
+
account: configuratorAddr,
|
|
1900
|
+
abi: iCreditConfiguratorV3Abi,
|
|
1901
|
+
functionName: "setFees",
|
|
1902
|
+
args: [
|
|
1903
|
+
cm.feeInterest,
|
|
1904
|
+
cm.liquidationDiscount - 1,
|
|
1905
|
+
Number(sdk.PERCENTAGE_FACTOR) - cm.liquidationDiscount,
|
|
1906
|
+
cm.feeLiquidationExpired,
|
|
1907
|
+
cm.liquidationDiscountExpired
|
|
1908
|
+
]
|
|
1909
|
+
});
|
|
1910
|
+
await anvil.waitForTransactionReceipt({ hash });
|
|
1911
|
+
logger?.debug(`[${cm.name}] setFees part 2`);
|
|
1912
|
+
hash = await anvil.writeContract({
|
|
1913
|
+
chain: anvil.chain,
|
|
1914
|
+
address: cm.creditConfigurator,
|
|
1915
|
+
account: configuratorAddr,
|
|
1916
|
+
abi: iCreditConfiguratorV3Abi,
|
|
1917
|
+
functionName: "setFees",
|
|
1918
|
+
args: [
|
|
1919
|
+
cm.feeInterest,
|
|
1920
|
+
cm.feeLiquidation,
|
|
1921
|
+
Number(sdk.PERCENTAGE_FACTOR) - cm.liquidationDiscount,
|
|
1922
|
+
cm.feeLiquidationExpired,
|
|
1923
|
+
cm.liquidationDiscountExpired
|
|
1924
|
+
]
|
|
1925
|
+
});
|
|
1926
|
+
await anvil.waitForTransactionReceipt({ hash });
|
|
1927
|
+
logger?.debug(`[${cm.name}] setFees done`);
|
|
1928
|
+
await anvil.impersonateAccount({
|
|
1929
|
+
address: cm.creditConfigurator
|
|
1930
|
+
});
|
|
1931
|
+
await anvil.setBalance({
|
|
1932
|
+
address: cm.creditConfigurator,
|
|
1933
|
+
value: viem.parseEther("100")
|
|
1934
|
+
});
|
|
1935
|
+
logger?.debug(
|
|
1936
|
+
`[${cm.name}] impresonating creditConfigurator ${cm.creditConfigurator}`
|
|
1937
|
+
);
|
|
1938
|
+
logger?.debug(`[${cm.name}] setting liquidation threshold`);
|
|
1939
|
+
hash = await anvil.writeContract({
|
|
1940
|
+
chain: anvil.chain,
|
|
1941
|
+
address: cm.baseParams.addr,
|
|
1942
|
+
account: cm.creditConfigurator,
|
|
1943
|
+
abi: iCreditManagerV3Abi,
|
|
1944
|
+
functionName: "setCollateralTokenData",
|
|
1945
|
+
args: [cm.underlying, 1, 1, Number(2n ** 40n - 1n), 0]
|
|
1946
|
+
});
|
|
1947
|
+
await anvil.waitForTransactionReceipt({ hash });
|
|
1948
|
+
logger?.debug(`[${cm.name}] setting configurator ${cm.creditConfigurator}`);
|
|
1949
|
+
hash = await anvil.writeContract({
|
|
1950
|
+
chain: anvil.chain,
|
|
1951
|
+
address: cm.baseParams.addr,
|
|
1952
|
+
account: cm.creditConfigurator,
|
|
1953
|
+
abi: iCreditManagerV3Abi,
|
|
1954
|
+
functionName: "setCreditConfigurator",
|
|
1955
|
+
args: [cm.creditConfigurator]
|
|
1956
|
+
});
|
|
1957
|
+
await anvil.waitForTransactionReceipt({ hash });
|
|
1958
|
+
logger?.debug(`[${cm.name}] done`);
|
|
1959
|
+
await anvil.stopImpersonatingAccount({
|
|
1960
|
+
address: cm.creditConfigurator
|
|
1961
|
+
});
|
|
1962
|
+
await anvil.stopImpersonatingAccount({ address: configuratorAddr });
|
|
1963
|
+
}
|
|
1457
1964
|
|
|
1965
|
+
exports.AccountOpener = AccountOpener;
|
|
1966
|
+
exports.SDKExample = SDKExample;
|
|
1967
|
+
exports.anvilNodeInfo = anvilNodeInfo;
|
|
1458
1968
|
exports.calcLiquidatableLTs = calcLiquidatableLTs;
|
|
1969
|
+
exports.createAnvilClient = createAnvilClient;
|
|
1970
|
+
exports.evmMineDetailed = evmMineDetailed;
|
|
1971
|
+
exports.isAnvil = isAnvil;
|
|
1972
|
+
exports.setLTZero = setLTZero;
|
|
1459
1973
|
exports.setLTs = setLTs;
|