@gearbox-protocol/sdk 4.1.8 → 4.1.9

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.
@@ -21,10 +21,9 @@ __reExport(dev_exports, require("./create2.js"), module.exports);
21
21
  __reExport(dev_exports, require("./createAnvilClient.js"), module.exports);
22
22
  __reExport(dev_exports, require("./createTransport.js"), module.exports);
23
23
  __reExport(dev_exports, require("./detectChain.js"), module.exports);
24
+ __reExport(dev_exports, require("./ltUtils.js"), module.exports);
24
25
  __reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
25
26
  __reExport(dev_exports, require("./PriceFeedStore.js"), module.exports);
26
- __reExport(dev_exports, require("./setLTs.js"), module.exports);
27
- __reExport(dev_exports, require("./setLTZero.js"), module.exports);
28
27
  // Annotate the CommonJS export names for ESM import in node:
29
28
  0 && (module.exports = {
30
29
  ...require("./AccountOpener.js"),
@@ -33,8 +32,7 @@ __reExport(dev_exports, require("./setLTZero.js"), module.exports);
33
32
  ...require("./createAnvilClient.js"),
34
33
  ...require("./createTransport.js"),
35
34
  ...require("./detectChain.js"),
35
+ ...require("./ltUtils.js"),
36
36
  ...require("./migrateFaucet.js"),
37
- ...require("./PriceFeedStore.js"),
38
- ...require("./setLTs.js"),
39
- ...require("./setLTZero.js")
37
+ ...require("./PriceFeedStore.js")
40
38
  });
@@ -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 ltUtils_exports = {};
20
+ __export(ltUtils_exports, {
21
+ setLTZero: () => setLTZero,
22
+ setLTs: () => setLTs
23
+ });
24
+ module.exports = __toCommonJS(ltUtils_exports);
25
+ var import_viem = require("viem");
26
+ var import_v300 = require("../abi/v300.js");
27
+ var import_sdk = require("../sdk/index.js");
28
+ var import_abi = require("./abi.js");
29
+ async function setLTs(anvil, cm, newLTs, logger) {
30
+ const configuratorAddr = await impresonateCCOwner(anvil, cm);
31
+ for (const [t, lt] of Object.entries(newLTs)) {
32
+ await anvil.writeContract({
33
+ chain: anvil.chain,
34
+ address: cm.creditConfigurator.baseParams.addr,
35
+ account: configuratorAddr,
36
+ abi: import_v300.iCreditConfiguratorV300Abi,
37
+ functionName: "setLiquidationThreshold",
38
+ args: [t, lt]
39
+ });
40
+ }
41
+ await anvil.stopImpersonatingAccount({
42
+ address: configuratorAddr
43
+ });
44
+ await logLTs(anvil, cm, import_sdk.TypedObjectUtils.keys(newLTs), logger);
45
+ }
46
+ async function setLTZero(anvil, cm, logger) {
47
+ const v = Number(cm.creditConfigurator.baseParams.version);
48
+ if (v >= 300 && v < 310) {
49
+ await setLTZeroV300(anvil, cm, logger);
50
+ } else if (v >= 310 && v < 320) {
51
+ await setLTZeroV310(anvil, cm, logger);
52
+ } else {
53
+ throw new Error(
54
+ `zero LT is not implemented for credit configurator version: ${v}`
55
+ );
56
+ }
57
+ }
58
+ async function setLTZeroV300(anvil, cm, logger) {
59
+ const ccAddr = cm.creditConfigurator.baseParams.addr;
60
+ const cmAddr = cm.creditManager.baseParams.addr;
61
+ const {
62
+ name,
63
+ underlying,
64
+ feeInterest,
65
+ liquidationDiscount,
66
+ feeLiquidation,
67
+ feeLiquidationExpired,
68
+ liquidationDiscountExpired
69
+ } = cm.creditManager;
70
+ const owner = await impresonateCCOwner(anvil, cm);
71
+ let hash = await anvil.writeContract({
72
+ chain: anvil.chain,
73
+ address: ccAddr,
74
+ account: owner,
75
+ abi: import_v300.iCreditConfiguratorV300Abi,
76
+ functionName: "setFees",
77
+ args: [
78
+ feeInterest,
79
+ liquidationDiscount - 1,
80
+ Number(import_sdk.PERCENTAGE_FACTOR) - liquidationDiscount,
81
+ feeLiquidationExpired,
82
+ liquidationDiscountExpired
83
+ ]
84
+ });
85
+ await anvil.waitForTransactionReceipt({ hash });
86
+ logger?.debug(`[${name}] setFees part 2`);
87
+ hash = await anvil.writeContract({
88
+ chain: anvil.chain,
89
+ address: ccAddr,
90
+ account: owner,
91
+ abi: import_v300.iCreditConfiguratorV300Abi,
92
+ functionName: "setFees",
93
+ args: [
94
+ feeInterest,
95
+ feeLiquidation,
96
+ Number(import_sdk.PERCENTAGE_FACTOR) - liquidationDiscount,
97
+ feeLiquidationExpired,
98
+ liquidationDiscountExpired
99
+ ]
100
+ });
101
+ await anvil.waitForTransactionReceipt({ hash });
102
+ logger?.debug(`[${name}] setFees done`);
103
+ await anvil.impersonateAccount({
104
+ address: ccAddr
105
+ });
106
+ await anvil.setBalance({
107
+ address: ccAddr,
108
+ value: (0, import_viem.parseEther)("100")
109
+ });
110
+ logger?.debug(`[${name}] impresonating creditConfigurator ${ccAddr}`);
111
+ logger?.debug(`[${name}] setting liquidation threshold`);
112
+ hash = await anvil.writeContract({
113
+ chain: anvil.chain,
114
+ address: cmAddr,
115
+ account: ccAddr,
116
+ abi: import_v300.iCreditManagerV300Abi,
117
+ functionName: "setCollateralTokenData",
118
+ args: [underlying, 1, 1, Number(2n ** 40n - 1n), 0]
119
+ });
120
+ await anvil.waitForTransactionReceipt({ hash });
121
+ logger?.debug(`[${name}] setting configurator ${ccAddr}`);
122
+ hash = await anvil.writeContract({
123
+ chain: anvil.chain,
124
+ address: cmAddr,
125
+ account: ccAddr,
126
+ abi: import_v300.iCreditManagerV300Abi,
127
+ functionName: "setCreditConfigurator",
128
+ args: [ccAddr]
129
+ });
130
+ await anvil.waitForTransactionReceipt({ hash });
131
+ logger?.debug(`[${name}] done`);
132
+ await anvil.stopImpersonatingAccount({
133
+ address: ccAddr
134
+ });
135
+ await anvil.stopImpersonatingAccount({ address: owner });
136
+ await logLTs(
137
+ anvil,
138
+ cm,
139
+ cm.creditManager.collateralTokens.map((c) => c.token),
140
+ logger
141
+ );
142
+ }
143
+ async function setLTZeroV310(anvil, cm, logger) {
144
+ const newLTs = {};
145
+ for (const { token } of cm.creditManager.collateralTokens) {
146
+ if (!(0, import_sdk.hexEq)(token, cm.creditManager.underlying)) {
147
+ newLTs[token] = 0;
148
+ }
149
+ }
150
+ await setLTs(anvil, cm, newLTs, logger);
151
+ }
152
+ async function impresonateCCOwner(anvil, cm) {
153
+ const aclAddr = await anvil.readContract({
154
+ address: cm.creditConfigurator.baseParams.addr,
155
+ abi: import_abi.iaclTraitAbi,
156
+ functionName: "acl"
157
+ });
158
+ const owner = await anvil.readContract({
159
+ address: aclAddr,
160
+ abi: import_abi.iOwnableAbi,
161
+ functionName: "owner"
162
+ });
163
+ await anvil.impersonateAccount({
164
+ address: owner
165
+ });
166
+ await anvil.setBalance({
167
+ address: owner,
168
+ value: (0, import_viem.parseEther)("100")
169
+ });
170
+ return owner;
171
+ }
172
+ async function logLTs(anvil, cm, tokens, logger) {
173
+ const resp = await anvil.multicall({
174
+ allowFailure: true,
175
+ contracts: tokens.flatMap((t) => [
176
+ {
177
+ abi: import_v300.iCreditManagerV300Abi,
178
+ functionName: "liquidationThresholds",
179
+ address: cm.creditManager.baseParams.addr,
180
+ args: [t]
181
+ },
182
+ {
183
+ abi: import_viem.erc20Abi,
184
+ functionName: "symbol",
185
+ address: t,
186
+ args: []
187
+ }
188
+ ])
189
+ });
190
+ for (let i = 0; i < tokens.length; i++) {
191
+ const lt = resp[i * 2]?.result ?? "error";
192
+ const symbol = resp[i * 2 + 1]?.result ?? tokens[i];
193
+ logger?.debug(`new LT for ${symbol}: ${lt}`);
194
+ }
195
+ }
196
+ // Annotate the CommonJS export names for ESM import in node:
197
+ 0 && (module.exports = {
198
+ setLTZero,
199
+ setLTs
200
+ });
@@ -4,7 +4,6 @@ export * from "./create2.js";
4
4
  export * from "./createAnvilClient.js";
5
5
  export * from "./createTransport.js";
6
6
  export * from "./detectChain.js";
7
+ export * from "./ltUtils.js";
7
8
  export * from "./migrateFaucet.js";
8
9
  export * from "./PriceFeedStore.js";
9
- export * from "./setLTs.js";
10
- export * from "./setLTZero.js";
@@ -0,0 +1,178 @@
1
+ import { erc20Abi, parseEther } from "viem";
2
+ import {
3
+ iCreditConfiguratorV300Abi,
4
+ iCreditManagerV300Abi
5
+ } from "../abi/v300.js";
6
+ import { hexEq, PERCENTAGE_FACTOR, TypedObjectUtils } from "../sdk/index.js";
7
+ import { iaclTraitAbi, iOwnableAbi } from "./abi.js";
8
+ async function setLTs(anvil, cm, newLTs, logger) {
9
+ const configuratorAddr = await impresonateCCOwner(anvil, cm);
10
+ for (const [t, lt] of Object.entries(newLTs)) {
11
+ await anvil.writeContract({
12
+ chain: anvil.chain,
13
+ address: cm.creditConfigurator.baseParams.addr,
14
+ account: configuratorAddr,
15
+ abi: iCreditConfiguratorV300Abi,
16
+ functionName: "setLiquidationThreshold",
17
+ args: [t, lt]
18
+ });
19
+ }
20
+ await anvil.stopImpersonatingAccount({
21
+ address: configuratorAddr
22
+ });
23
+ await logLTs(anvil, cm, TypedObjectUtils.keys(newLTs), logger);
24
+ }
25
+ async function setLTZero(anvil, cm, logger) {
26
+ const v = Number(cm.creditConfigurator.baseParams.version);
27
+ if (v >= 300 && v < 310) {
28
+ await setLTZeroV300(anvil, cm, logger);
29
+ } else if (v >= 310 && v < 320) {
30
+ await setLTZeroV310(anvil, cm, logger);
31
+ } else {
32
+ throw new Error(
33
+ `zero LT is not implemented for credit configurator version: ${v}`
34
+ );
35
+ }
36
+ }
37
+ async function setLTZeroV300(anvil, cm, logger) {
38
+ const ccAddr = cm.creditConfigurator.baseParams.addr;
39
+ const cmAddr = cm.creditManager.baseParams.addr;
40
+ const {
41
+ name,
42
+ underlying,
43
+ feeInterest,
44
+ liquidationDiscount,
45
+ feeLiquidation,
46
+ feeLiquidationExpired,
47
+ liquidationDiscountExpired
48
+ } = cm.creditManager;
49
+ const owner = await impresonateCCOwner(anvil, cm);
50
+ let hash = await anvil.writeContract({
51
+ chain: anvil.chain,
52
+ address: ccAddr,
53
+ account: owner,
54
+ abi: iCreditConfiguratorV300Abi,
55
+ functionName: "setFees",
56
+ args: [
57
+ feeInterest,
58
+ liquidationDiscount - 1,
59
+ Number(PERCENTAGE_FACTOR) - liquidationDiscount,
60
+ feeLiquidationExpired,
61
+ liquidationDiscountExpired
62
+ ]
63
+ });
64
+ await anvil.waitForTransactionReceipt({ hash });
65
+ logger?.debug(`[${name}] setFees part 2`);
66
+ hash = await anvil.writeContract({
67
+ chain: anvil.chain,
68
+ address: ccAddr,
69
+ account: owner,
70
+ abi: iCreditConfiguratorV300Abi,
71
+ functionName: "setFees",
72
+ args: [
73
+ feeInterest,
74
+ feeLiquidation,
75
+ Number(PERCENTAGE_FACTOR) - liquidationDiscount,
76
+ feeLiquidationExpired,
77
+ liquidationDiscountExpired
78
+ ]
79
+ });
80
+ await anvil.waitForTransactionReceipt({ hash });
81
+ logger?.debug(`[${name}] setFees done`);
82
+ await anvil.impersonateAccount({
83
+ address: ccAddr
84
+ });
85
+ await anvil.setBalance({
86
+ address: ccAddr,
87
+ value: parseEther("100")
88
+ });
89
+ logger?.debug(`[${name}] impresonating creditConfigurator ${ccAddr}`);
90
+ logger?.debug(`[${name}] setting liquidation threshold`);
91
+ hash = await anvil.writeContract({
92
+ chain: anvil.chain,
93
+ address: cmAddr,
94
+ account: ccAddr,
95
+ abi: iCreditManagerV300Abi,
96
+ functionName: "setCollateralTokenData",
97
+ args: [underlying, 1, 1, Number(2n ** 40n - 1n), 0]
98
+ });
99
+ await anvil.waitForTransactionReceipt({ hash });
100
+ logger?.debug(`[${name}] setting configurator ${ccAddr}`);
101
+ hash = await anvil.writeContract({
102
+ chain: anvil.chain,
103
+ address: cmAddr,
104
+ account: ccAddr,
105
+ abi: iCreditManagerV300Abi,
106
+ functionName: "setCreditConfigurator",
107
+ args: [ccAddr]
108
+ });
109
+ await anvil.waitForTransactionReceipt({ hash });
110
+ logger?.debug(`[${name}] done`);
111
+ await anvil.stopImpersonatingAccount({
112
+ address: ccAddr
113
+ });
114
+ await anvil.stopImpersonatingAccount({ address: owner });
115
+ await logLTs(
116
+ anvil,
117
+ cm,
118
+ cm.creditManager.collateralTokens.map((c) => c.token),
119
+ logger
120
+ );
121
+ }
122
+ async function setLTZeroV310(anvil, cm, logger) {
123
+ const newLTs = {};
124
+ for (const { token } of cm.creditManager.collateralTokens) {
125
+ if (!hexEq(token, cm.creditManager.underlying)) {
126
+ newLTs[token] = 0;
127
+ }
128
+ }
129
+ await setLTs(anvil, cm, newLTs, logger);
130
+ }
131
+ async function impresonateCCOwner(anvil, cm) {
132
+ const aclAddr = await anvil.readContract({
133
+ address: cm.creditConfigurator.baseParams.addr,
134
+ abi: iaclTraitAbi,
135
+ functionName: "acl"
136
+ });
137
+ const owner = await anvil.readContract({
138
+ address: aclAddr,
139
+ abi: iOwnableAbi,
140
+ functionName: "owner"
141
+ });
142
+ await anvil.impersonateAccount({
143
+ address: owner
144
+ });
145
+ await anvil.setBalance({
146
+ address: owner,
147
+ value: parseEther("100")
148
+ });
149
+ return owner;
150
+ }
151
+ async function logLTs(anvil, cm, tokens, logger) {
152
+ const resp = await anvil.multicall({
153
+ allowFailure: true,
154
+ contracts: tokens.flatMap((t) => [
155
+ {
156
+ abi: iCreditManagerV300Abi,
157
+ functionName: "liquidationThresholds",
158
+ address: cm.creditManager.baseParams.addr,
159
+ args: [t]
160
+ },
161
+ {
162
+ abi: erc20Abi,
163
+ functionName: "symbol",
164
+ address: t,
165
+ args: []
166
+ }
167
+ ])
168
+ });
169
+ for (let i = 0; i < tokens.length; i++) {
170
+ const lt = resp[i * 2]?.result ?? "error";
171
+ const symbol = resp[i * 2 + 1]?.result ?? tokens[i];
172
+ logger?.debug(`new LT for ${symbol}: ${lt}`);
173
+ }
174
+ }
175
+ export {
176
+ setLTZero,
177
+ setLTs
178
+ };
@@ -4,7 +4,6 @@ export * from "./create2.js";
4
4
  export * from "./createAnvilClient.js";
5
5
  export * from "./createTransport.js";
6
6
  export * from "./detectChain.js";
7
+ export * from "./ltUtils.js";
7
8
  export * from "./migrateFaucet.js";
8
9
  export * from "./PriceFeedStore.js";
9
- export * from "./setLTs.js";
10
- export * from "./setLTZero.js";
@@ -0,0 +1,11 @@
1
+ import type { Address } from "viem";
2
+ import type { CreditSuiteState, ILogger } from "../sdk/index.js";
3
+ import type { AnvilClient } from "./createAnvilClient.js";
4
+ /**
5
+ * Helper function to set liquidation thresholds on credit manager via anvil impersonation
6
+ * @param sdk
7
+ * @param cm
8
+ * @param newLTs
9
+ */
10
+ export declare function setLTs(anvil: AnvilClient, cm: CreditSuiteState, newLTs: Record<Address, number>, logger?: ILogger): Promise<void>;
11
+ export declare function setLTZero(anvil: AnvilClient, cm: CreditSuiteState, logger?: ILogger): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "4.1.8",
3
+ "version": "4.1.9",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,124 +0,0 @@
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 setLTZero_exports = {};
20
- __export(setLTZero_exports, {
21
- setLTZero: () => setLTZero
22
- });
23
- module.exports = __toCommonJS(setLTZero_exports);
24
- var import_viem = require("viem");
25
- var import_v300 = require("../abi/v300.js");
26
- var import_sdk = require("../sdk/index.js");
27
- var import_abi = require("./abi.js");
28
- async function setLTZero(anvil, cm, logger) {
29
- const aclAddr = await anvil.readContract({
30
- address: cm.creditConfigurator,
31
- abi: import_abi.iaclTraitAbi,
32
- functionName: "acl"
33
- });
34
- const configuratorAddr = await anvil.readContract({
35
- address: aclAddr,
36
- abi: import_abi.iOwnableAbi,
37
- functionName: "owner"
38
- });
39
- await anvil.impersonateAccount({
40
- address: configuratorAddr
41
- });
42
- await anvil.setBalance({
43
- address: configuratorAddr,
44
- value: (0, import_viem.parseEther)("100")
45
- });
46
- let hash = await anvil.writeContract({
47
- chain: anvil.chain,
48
- address: cm.creditConfigurator,
49
- account: configuratorAddr,
50
- abi: import_v300.iCreditConfiguratorV300Abi,
51
- functionName: "setFees",
52
- args: [
53
- cm.feeInterest,
54
- cm.liquidationDiscount - 1,
55
- Number(import_sdk.PERCENTAGE_FACTOR) - cm.liquidationDiscount,
56
- cm.feeLiquidationExpired,
57
- cm.liquidationDiscountExpired
58
- ]
59
- });
60
- await anvil.waitForTransactionReceipt({ hash });
61
- logger?.debug(`[${cm.name}] setFees part 2`);
62
- hash = await anvil.writeContract({
63
- chain: anvil.chain,
64
- address: cm.creditConfigurator,
65
- account: configuratorAddr,
66
- abi: import_v300.iCreditConfiguratorV300Abi,
67
- functionName: "setFees",
68
- args: [
69
- cm.feeInterest,
70
- cm.feeLiquidation,
71
- Number(import_sdk.PERCENTAGE_FACTOR) - cm.liquidationDiscount,
72
- cm.feeLiquidationExpired,
73
- cm.liquidationDiscountExpired
74
- ]
75
- });
76
- await anvil.waitForTransactionReceipt({ hash });
77
- logger?.debug(`[${cm.name}] setFees done`);
78
- await anvil.impersonateAccount({
79
- address: cm.creditConfigurator
80
- });
81
- await anvil.setBalance({
82
- address: cm.creditConfigurator,
83
- value: (0, import_viem.parseEther)("100")
84
- });
85
- logger?.debug(
86
- `[${cm.name}] impresonating creditConfigurator ${cm.creditConfigurator}`
87
- );
88
- logger?.debug(`[${cm.name}] setting liquidation threshold`);
89
- hash = await anvil.writeContract({
90
- chain: anvil.chain,
91
- address: cm.baseParams.addr,
92
- account: cm.creditConfigurator,
93
- abi: import_v300.iCreditManagerV300Abi,
94
- functionName: "setCollateralTokenData",
95
- args: [cm.underlying, 1, 1, Number(2n ** 40n - 1n), 0]
96
- });
97
- await anvil.waitForTransactionReceipt({ hash });
98
- logger?.debug(`[${cm.name}] setting configurator ${cm.creditConfigurator}`);
99
- hash = await anvil.writeContract({
100
- chain: anvil.chain,
101
- address: cm.baseParams.addr,
102
- account: cm.creditConfigurator,
103
- abi: import_v300.iCreditManagerV300Abi,
104
- functionName: "setCreditConfigurator",
105
- args: [cm.creditConfigurator]
106
- });
107
- await anvil.waitForTransactionReceipt({ hash });
108
- logger?.debug(`[${cm.name}] done`);
109
- await anvil.stopImpersonatingAccount({
110
- address: cm.creditConfigurator
111
- });
112
- await anvil.stopImpersonatingAccount({ address: configuratorAddr });
113
- const lt = await anvil.readContract({
114
- address: cm.baseParams.addr,
115
- abi: import_v300.iCreditManagerV300Abi,
116
- functionName: "liquidationThresholds",
117
- args: [cm.underlying]
118
- });
119
- logger?.debug(`[${cm.name}] underlying lt: ${lt}`);
120
- }
121
- // Annotate the CommonJS export names for ESM import in node:
122
- 0 && (module.exports = {
123
- setLTZero
124
- });
@@ -1,73 +0,0 @@
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 setLTs_exports = {};
20
- __export(setLTs_exports, {
21
- setLTs: () => setLTs
22
- });
23
- module.exports = __toCommonJS(setLTs_exports);
24
- var import_viem = require("viem");
25
- var import_v300 = require("../abi/v300.js");
26
- var import_v310 = require("../abi/v310.js");
27
- var import_abi = require("./abi.js");
28
- async function setLTs(anvil, cm, newLTs, logger) {
29
- const aclAddr = await anvil.readContract({
30
- address: cm.creditConfigurator,
31
- abi: import_abi.iaclTraitAbi,
32
- functionName: "acl"
33
- });
34
- const configuratorAddr = await anvil.readContract({
35
- address: aclAddr,
36
- abi: import_abi.iOwnableAbi,
37
- functionName: "owner"
38
- });
39
- await anvil.impersonateAccount({
40
- address: configuratorAddr
41
- });
42
- await anvil.setBalance({
43
- address: configuratorAddr,
44
- value: (0, import_viem.parseEther)("100")
45
- });
46
- for (const [t, lt] of Object.entries(newLTs)) {
47
- try {
48
- await anvil.writeContract({
49
- chain: anvil.chain,
50
- address: cm.creditConfigurator,
51
- account: configuratorAddr,
52
- abi: import_v300.iCreditConfiguratorV300Abi,
53
- functionName: "setLiquidationThreshold",
54
- args: [t, lt]
55
- });
56
- const newLT = await anvil.readContract({
57
- address: cm.address,
58
- abi: import_v310.iCreditManagerV310Abi,
59
- functionName: "liquidationThresholds",
60
- args: [t]
61
- });
62
- logger?.debug(`set ${t} LT to ${newLT}`);
63
- } catch {
64
- }
65
- }
66
- await anvil.stopImpersonatingAccount({
67
- address: configuratorAddr
68
- });
69
- }
70
- // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {
72
- setLTs
73
- });
@@ -1,103 +0,0 @@
1
- import { parseEther } from "viem";
2
- import {
3
- iCreditConfiguratorV300Abi,
4
- iCreditManagerV300Abi
5
- } from "../abi/v300.js";
6
- import { PERCENTAGE_FACTOR } from "../sdk/index.js";
7
- import { iaclTraitAbi, iOwnableAbi } from "./abi.js";
8
- async function setLTZero(anvil, cm, logger) {
9
- const aclAddr = await anvil.readContract({
10
- address: cm.creditConfigurator,
11
- abi: iaclTraitAbi,
12
- functionName: "acl"
13
- });
14
- const configuratorAddr = await anvil.readContract({
15
- address: aclAddr,
16
- abi: iOwnableAbi,
17
- functionName: "owner"
18
- });
19
- await anvil.impersonateAccount({
20
- address: configuratorAddr
21
- });
22
- await anvil.setBalance({
23
- address: configuratorAddr,
24
- value: parseEther("100")
25
- });
26
- let hash = await anvil.writeContract({
27
- chain: anvil.chain,
28
- address: cm.creditConfigurator,
29
- account: configuratorAddr,
30
- abi: iCreditConfiguratorV300Abi,
31
- functionName: "setFees",
32
- args: [
33
- cm.feeInterest,
34
- cm.liquidationDiscount - 1,
35
- Number(PERCENTAGE_FACTOR) - cm.liquidationDiscount,
36
- cm.feeLiquidationExpired,
37
- cm.liquidationDiscountExpired
38
- ]
39
- });
40
- await anvil.waitForTransactionReceipt({ hash });
41
- logger?.debug(`[${cm.name}] setFees part 2`);
42
- hash = await anvil.writeContract({
43
- chain: anvil.chain,
44
- address: cm.creditConfigurator,
45
- account: configuratorAddr,
46
- abi: iCreditConfiguratorV300Abi,
47
- functionName: "setFees",
48
- args: [
49
- cm.feeInterest,
50
- cm.feeLiquidation,
51
- Number(PERCENTAGE_FACTOR) - cm.liquidationDiscount,
52
- cm.feeLiquidationExpired,
53
- cm.liquidationDiscountExpired
54
- ]
55
- });
56
- await anvil.waitForTransactionReceipt({ hash });
57
- logger?.debug(`[${cm.name}] setFees done`);
58
- await anvil.impersonateAccount({
59
- address: cm.creditConfigurator
60
- });
61
- await anvil.setBalance({
62
- address: cm.creditConfigurator,
63
- value: parseEther("100")
64
- });
65
- logger?.debug(
66
- `[${cm.name}] impresonating creditConfigurator ${cm.creditConfigurator}`
67
- );
68
- logger?.debug(`[${cm.name}] setting liquidation threshold`);
69
- hash = await anvil.writeContract({
70
- chain: anvil.chain,
71
- address: cm.baseParams.addr,
72
- account: cm.creditConfigurator,
73
- abi: iCreditManagerV300Abi,
74
- functionName: "setCollateralTokenData",
75
- args: [cm.underlying, 1, 1, Number(2n ** 40n - 1n), 0]
76
- });
77
- await anvil.waitForTransactionReceipt({ hash });
78
- logger?.debug(`[${cm.name}] setting configurator ${cm.creditConfigurator}`);
79
- hash = await anvil.writeContract({
80
- chain: anvil.chain,
81
- address: cm.baseParams.addr,
82
- account: cm.creditConfigurator,
83
- abi: iCreditManagerV300Abi,
84
- functionName: "setCreditConfigurator",
85
- args: [cm.creditConfigurator]
86
- });
87
- await anvil.waitForTransactionReceipt({ hash });
88
- logger?.debug(`[${cm.name}] done`);
89
- await anvil.stopImpersonatingAccount({
90
- address: cm.creditConfigurator
91
- });
92
- await anvil.stopImpersonatingAccount({ address: configuratorAddr });
93
- const lt = await anvil.readContract({
94
- address: cm.baseParams.addr,
95
- abi: iCreditManagerV300Abi,
96
- functionName: "liquidationThresholds",
97
- args: [cm.underlying]
98
- });
99
- logger?.debug(`[${cm.name}] underlying lt: ${lt}`);
100
- }
101
- export {
102
- setLTZero
103
- };
@@ -1,49 +0,0 @@
1
- import { parseEther } from "viem";
2
- import { iCreditConfiguratorV300Abi } from "../abi/v300.js";
3
- import { iCreditManagerV310Abi } from "../abi/v310.js";
4
- import { iaclTraitAbi, iOwnableAbi } from "./abi.js";
5
- async function setLTs(anvil, cm, newLTs, logger) {
6
- const aclAddr = await anvil.readContract({
7
- address: cm.creditConfigurator,
8
- abi: iaclTraitAbi,
9
- functionName: "acl"
10
- });
11
- const configuratorAddr = await anvil.readContract({
12
- address: aclAddr,
13
- abi: iOwnableAbi,
14
- functionName: "owner"
15
- });
16
- await anvil.impersonateAccount({
17
- address: configuratorAddr
18
- });
19
- await anvil.setBalance({
20
- address: configuratorAddr,
21
- value: parseEther("100")
22
- });
23
- for (const [t, lt] of Object.entries(newLTs)) {
24
- try {
25
- await anvil.writeContract({
26
- chain: anvil.chain,
27
- address: cm.creditConfigurator,
28
- account: configuratorAddr,
29
- abi: iCreditConfiguratorV300Abi,
30
- functionName: "setLiquidationThreshold",
31
- args: [t, lt]
32
- });
33
- const newLT = await anvil.readContract({
34
- address: cm.address,
35
- abi: iCreditManagerV310Abi,
36
- functionName: "liquidationThresholds",
37
- args: [t]
38
- });
39
- logger?.debug(`set ${t} LT to ${newLT}`);
40
- } catch {
41
- }
42
- }
43
- await anvil.stopImpersonatingAccount({
44
- address: configuratorAddr
45
- });
46
- }
47
- export {
48
- setLTs
49
- };
@@ -1,5 +0,0 @@
1
- import type { CreditManagerState, ILogger } from "../sdk/index.js";
2
- import type { AnvilClient } from "./createAnvilClient.js";
3
- type ZeroLTCMSlice = Pick<CreditManagerState, "creditConfigurator" | "feeInterest" | "liquidationDiscount" | "feeLiquidationExpired" | "liquidationDiscountExpired" | "feeLiquidation" | "name" | "underlying" | "baseParams">;
4
- export declare function setLTZero(anvil: AnvilClient, cm: ZeroLTCMSlice, logger?: ILogger): Promise<void>;
5
- export {};
@@ -1,14 +0,0 @@
1
- import type { Address } from "viem";
2
- import type { ILogger } from "../sdk/index.js";
3
- import type { AnvilClient } from "./createAnvilClient.js";
4
- export interface SetLTsCMSlice {
5
- creditConfigurator: Address;
6
- address: Address;
7
- }
8
- /**
9
- * Helper function to set liquidation thresholds on credit manager via anvil impersonation
10
- * @param sdk
11
- * @param cm
12
- * @param newLTs
13
- */
14
- export declare function setLTs(anvil: AnvilClient, cm: SetLTsCMSlice, newLTs: Record<Address, number>, logger?: ILogger): Promise<void>;