@gearbox-protocol/sdk 16.3.1-next.1 → 16.3.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/dist/cjs/plugins/bots/BotsPlugin.js +107 -0
- package/dist/cjs/plugins/bots/PartialLiquidationBotV310Contract.js +47 -0
- package/dist/cjs/plugins/bots/abi/iPartialLiquidationBotV310.js +225 -0
- package/dist/cjs/plugins/bots/abi/index.js +3 -0
- package/dist/cjs/plugins/bots/config.js +39 -0
- package/dist/cjs/plugins/bots/deserializePartialLiquidationBotParams.js +39 -0
- package/dist/cjs/plugins/bots/index.js +17 -0
- package/dist/cjs/plugins/bots/package.json +1 -0
- package/dist/cjs/plugins/bots/types.js +28 -0
- package/dist/esm/plugins/bots/BotsPlugin.js +106 -0
- package/dist/esm/plugins/bots/PartialLiquidationBotV310Contract.js +46 -0
- package/dist/esm/plugins/bots/abi/iPartialLiquidationBotV310.js +224 -0
- package/dist/esm/plugins/bots/abi/index.js +2 -0
- package/dist/esm/plugins/bots/config.js +34 -0
- package/dist/esm/plugins/bots/deserializePartialLiquidationBotParams.js +35 -0
- package/dist/esm/plugins/bots/index.js +7 -0
- package/dist/esm/plugins/bots/package.json +1 -0
- package/dist/esm/plugins/bots/types.js +26 -0
- package/dist/types/plugins/bots/BotsPlugin.d.ts +18 -0
- package/dist/types/plugins/bots/PartialLiquidationBotV310Contract.d.ts +216 -0
- package/dist/types/plugins/bots/abi/iPartialLiquidationBotV310.d.ts +193 -0
- package/dist/types/plugins/bots/abi/index.d.ts +2 -0
- package/dist/types/plugins/bots/config.d.ts +12 -0
- package/dist/types/plugins/bots/deserializePartialLiquidationBotParams.d.ts +7 -0
- package/dist/types/plugins/bots/index.d.ts +7 -0
- package/dist/types/plugins/bots/types.d.ts +53 -0
- package/package.json +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_AddressMap = require("../../onchain/utils/AddressMap.js");
|
|
3
|
+
const require_onchain_chain_chains = require("../../onchain/chain/chains.js");
|
|
4
|
+
const require_onchain_constants_address_provider = require("../../onchain/constants/address-provider.js");
|
|
5
|
+
const require_onchain_utils_hex = require("../../onchain/utils/hex.js");
|
|
6
|
+
const require_onchain_plugins_BasePlugin = require("../../onchain/plugins/BasePlugin.js");
|
|
7
|
+
require("../../onchain/index.js");
|
|
8
|
+
const require_abi_310_iBytecodeRepository = require("../../abi/310/iBytecodeRepository.js");
|
|
9
|
+
const require_plugins_bots_abi_iPartialLiquidationBotV310 = require("./abi/iPartialLiquidationBotV310.js");
|
|
10
|
+
const require_plugins_bots_config = require("./config.js");
|
|
11
|
+
const require_plugins_bots_types = require("./types.js");
|
|
12
|
+
const require_plugins_bots_PartialLiquidationBotV310Contract = require("./PartialLiquidationBotV310Contract.js");
|
|
13
|
+
let viem = require("viem");
|
|
14
|
+
//#region src/plugins/bots/BotsPlugin.ts
|
|
15
|
+
var BotsPlugin = class extends require_onchain_plugins_BasePlugin.BasePlugin {
|
|
16
|
+
#bots;
|
|
17
|
+
get loaded() {
|
|
18
|
+
return !!this.#bots;
|
|
19
|
+
}
|
|
20
|
+
get bots() {
|
|
21
|
+
return this.#bots?.values() ?? [];
|
|
22
|
+
}
|
|
23
|
+
async load(force) {
|
|
24
|
+
if (!force && this.loaded) return this.state;
|
|
25
|
+
const treasury = this.sdk.addressProvider.getAddress(require_onchain_constants_address_provider.AP_TREASURY);
|
|
26
|
+
const bcr = this.sdk.addressProvider.getAddress(require_onchain_constants_address_provider.AP_BYTECODE_REPOSITORY);
|
|
27
|
+
const configs = require_plugins_bots_config.PARTIAL_LIQUIDATION_BOT_CONFIGS[this.sdk.networkType] ?? [];
|
|
28
|
+
this.#bots = new require_onchain_utils_AddressMap.AddressMap();
|
|
29
|
+
if (!configs.length) return this.state;
|
|
30
|
+
const deployedBots = await this.client.multicall({
|
|
31
|
+
contracts: configs.map((config) => ({
|
|
32
|
+
address: bcr,
|
|
33
|
+
abi: require_abi_310_iBytecodeRepository.iBytecodeRepositoryAbi,
|
|
34
|
+
functionName: "computeAddress",
|
|
35
|
+
args: [
|
|
36
|
+
(0, viem.stringToHex)(require_plugins_bots_types.BOT_PARTIAL_LIQUIDATION, { size: 32 }),
|
|
37
|
+
310,
|
|
38
|
+
(0, viem.encodeAbiParameters)(require_plugins_bots_types.BOT_PARAMS_ABI, [
|
|
39
|
+
treasury,
|
|
40
|
+
config.minHealthFactor,
|
|
41
|
+
config.maxHealthFactor,
|
|
42
|
+
config.premiumScaleFactor,
|
|
43
|
+
config.feeScaleFactor
|
|
44
|
+
]),
|
|
45
|
+
(0, viem.stringToHex)(require_plugins_bots_config.PARTIAL_LIQUIDATION_BOT_SALT, { size: 32 }),
|
|
46
|
+
require_plugins_bots_config.PARTIAL_LIQUIDATION_BOT_DEPLOYER
|
|
47
|
+
]
|
|
48
|
+
})),
|
|
49
|
+
allowFailure: true,
|
|
50
|
+
blockNumber: this.sdk.currentBlock,
|
|
51
|
+
batchSize: 0
|
|
52
|
+
});
|
|
53
|
+
const expectedBots = new require_onchain_utils_AddressMap.AddressMap();
|
|
54
|
+
for (let i = 0; i < configs.length; i++) {
|
|
55
|
+
const b = deployedBots[i];
|
|
56
|
+
const { minHealthFactor, maxHealthFactor } = configs[i];
|
|
57
|
+
if (b.status === "success") {
|
|
58
|
+
expectedBots.upsert(b.result, {
|
|
59
|
+
...configs[i],
|
|
60
|
+
treasury
|
|
61
|
+
});
|
|
62
|
+
this.logger?.debug(`expected bot [${minHealthFactor}, ${maxHealthFactor}] at ${b.result}`);
|
|
63
|
+
} else this.logger?.error(`failed compute address for bot [${minHealthFactor}, ${maxHealthFactor}]`, b.error);
|
|
64
|
+
}
|
|
65
|
+
const botAddrs = expectedBots.keys();
|
|
66
|
+
const serializedBots = await this.client.multicall({
|
|
67
|
+
contracts: botAddrs.map((address) => ({
|
|
68
|
+
address,
|
|
69
|
+
abi: require_plugins_bots_abi_iPartialLiquidationBotV310.iPartialLiquidationBotV310Abi,
|
|
70
|
+
functionName: "serialize"
|
|
71
|
+
})),
|
|
72
|
+
allowFailure: true,
|
|
73
|
+
blockNumber: this.sdk.currentBlock,
|
|
74
|
+
batchSize: 0
|
|
75
|
+
});
|
|
76
|
+
for (let i = 0; i < botAddrs.length; i++) {
|
|
77
|
+
const serialized = serializedBots[i];
|
|
78
|
+
const expected = expectedBots.mustGet(botAddrs[i]);
|
|
79
|
+
if (serialized.status === "success") {
|
|
80
|
+
const bot = new require_plugins_bots_PartialLiquidationBotV310Contract.PartialLiquidationBotV310Contract(this.sdk, {
|
|
81
|
+
addr: botAddrs[i],
|
|
82
|
+
version: BigInt(310),
|
|
83
|
+
contractType: require_plugins_bots_types.BOT_PARTIAL_LIQUIDATION,
|
|
84
|
+
serializedParams: serialized.result
|
|
85
|
+
});
|
|
86
|
+
if (!require_onchain_utils_hex.hexEq(treasury, expected.treasury) || bot.minHealthFactor !== expected.minHealthFactor || bot.maxHealthFactor !== expected.maxHealthFactor || bot.premiumScaleFactor !== expected.premiumScaleFactor || bot.feeScaleFactor !== expected.feeScaleFactor) this.logger?.error(`serialized bot ${botAddrs[i]} does not match expected bot`, serialized.error);
|
|
87
|
+
else this.#bots.upsert(botAddrs[i], bot);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.state;
|
|
91
|
+
}
|
|
92
|
+
stateHuman(raw) {
|
|
93
|
+
return { bots: this.#bots?.values().map((bot) => bot.stateHuman(raw)) ?? [] };
|
|
94
|
+
}
|
|
95
|
+
get state() {
|
|
96
|
+
return { bots: this.#bots?.values().map((bot) => bot.state) ?? [] };
|
|
97
|
+
}
|
|
98
|
+
hydrate(state) {
|
|
99
|
+
this.#bots = new require_onchain_utils_AddressMap.AddressMap();
|
|
100
|
+
for (const botState of state.bots) this.#bots.upsert(botState.addr, new require_plugins_bots_PartialLiquidationBotV310Contract.PartialLiquidationBotV310Contract(this.sdk, botState));
|
|
101
|
+
}
|
|
102
|
+
static getMigrationBotData(chainId) {
|
|
103
|
+
return chainId === require_onchain_chain_chains.chains.Mainnet.id ? require_plugins_bots_config.LEGACY_MIGRATION_BOT : void 0;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.BotsPlugin = BotsPlugin;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_formatter = require("../../onchain/utils/formatter.js");
|
|
3
|
+
const require_onchain_base_BaseContract = require("../../onchain/base/BaseContract.js");
|
|
4
|
+
require("../../onchain/index.js");
|
|
5
|
+
const require_plugins_bots_abi_iPartialLiquidationBotV310 = require("./abi/iPartialLiquidationBotV310.js");
|
|
6
|
+
require("./abi/index.js");
|
|
7
|
+
const require_plugins_bots_types = require("./types.js");
|
|
8
|
+
let viem = require("viem");
|
|
9
|
+
//#region src/plugins/bots/PartialLiquidationBotV310Contract.ts
|
|
10
|
+
const abi = require_plugins_bots_abi_iPartialLiquidationBotV310.iPartialLiquidationBotV310Abi;
|
|
11
|
+
var PartialLiquidationBotV310Contract = class extends require_onchain_base_BaseContract.BaseContract {
|
|
12
|
+
treasury;
|
|
13
|
+
minHealthFactor;
|
|
14
|
+
maxHealthFactor;
|
|
15
|
+
premiumScaleFactor;
|
|
16
|
+
feeScaleFactor;
|
|
17
|
+
#serializedParams;
|
|
18
|
+
constructor(sdk, args) {
|
|
19
|
+
super(sdk, {
|
|
20
|
+
...args,
|
|
21
|
+
abi,
|
|
22
|
+
name: "PartialLiquidationBotV310"
|
|
23
|
+
});
|
|
24
|
+
[this.treasury, this.minHealthFactor, this.maxHealthFactor, this.premiumScaleFactor, this.feeScaleFactor] = (0, viem.decodeAbiParameters)(require_plugins_bots_types.BOT_PARAMS_ABI, args.serializedParams);
|
|
25
|
+
this.#serializedParams = args.serializedParams;
|
|
26
|
+
}
|
|
27
|
+
stateHuman(raw) {
|
|
28
|
+
return {
|
|
29
|
+
...super.stateHuman(raw),
|
|
30
|
+
treasury: this.treasury,
|
|
31
|
+
minHealthFactor: require_onchain_utils_formatter.percentFmt(this.minHealthFactor, raw),
|
|
32
|
+
maxHealthFactor: require_onchain_utils_formatter.percentFmt(this.maxHealthFactor, raw),
|
|
33
|
+
premiumScaleFactor: require_onchain_utils_formatter.percentFmt(this.premiumScaleFactor, raw),
|
|
34
|
+
feeScaleFactor: require_onchain_utils_formatter.percentFmt(this.feeScaleFactor, raw)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
get state() {
|
|
38
|
+
return {
|
|
39
|
+
addr: this.address,
|
|
40
|
+
version: BigInt(this.version),
|
|
41
|
+
contractType: (0, viem.stringToHex)(this.contractType, { size: 32 }),
|
|
42
|
+
serializedParams: this.#serializedParams
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.PartialLiquidationBotV310Contract = PartialLiquidationBotV310Contract;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/plugins/bots/abi/iPartialLiquidationBotV310.ts
|
|
3
|
+
const iPartialLiquidationBotV310Abi = [
|
|
4
|
+
{
|
|
5
|
+
type: "function",
|
|
6
|
+
name: "contractType",
|
|
7
|
+
inputs: [],
|
|
8
|
+
outputs: [{
|
|
9
|
+
name: "",
|
|
10
|
+
type: "bytes32",
|
|
11
|
+
internalType: "bytes32"
|
|
12
|
+
}],
|
|
13
|
+
stateMutability: "view"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: "function",
|
|
17
|
+
name: "feeScaleFactor",
|
|
18
|
+
inputs: [],
|
|
19
|
+
outputs: [{
|
|
20
|
+
name: "",
|
|
21
|
+
type: "uint16",
|
|
22
|
+
internalType: "uint16"
|
|
23
|
+
}],
|
|
24
|
+
stateMutability: "view"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
type: "function",
|
|
28
|
+
name: "maxHealthFactor",
|
|
29
|
+
inputs: [],
|
|
30
|
+
outputs: [{
|
|
31
|
+
name: "",
|
|
32
|
+
type: "uint16",
|
|
33
|
+
internalType: "uint16"
|
|
34
|
+
}],
|
|
35
|
+
stateMutability: "view"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "function",
|
|
39
|
+
name: "minHealthFactor",
|
|
40
|
+
inputs: [],
|
|
41
|
+
outputs: [{
|
|
42
|
+
name: "",
|
|
43
|
+
type: "uint16",
|
|
44
|
+
internalType: "uint16"
|
|
45
|
+
}],
|
|
46
|
+
stateMutability: "view"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "function",
|
|
50
|
+
name: "partiallyLiquidate",
|
|
51
|
+
inputs: [
|
|
52
|
+
{
|
|
53
|
+
name: "creditAccount",
|
|
54
|
+
type: "address",
|
|
55
|
+
internalType: "address"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "token",
|
|
59
|
+
type: "address",
|
|
60
|
+
internalType: "address"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "repaidAmount",
|
|
64
|
+
type: "uint256",
|
|
65
|
+
internalType: "uint256"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "minSeizedAmount",
|
|
69
|
+
type: "uint256",
|
|
70
|
+
internalType: "uint256"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "to",
|
|
74
|
+
type: "address",
|
|
75
|
+
internalType: "address"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "priceUpdates",
|
|
79
|
+
type: "tuple[]",
|
|
80
|
+
internalType: "struct PriceUpdate[]",
|
|
81
|
+
components: [{
|
|
82
|
+
name: "priceFeed",
|
|
83
|
+
type: "address",
|
|
84
|
+
internalType: "address"
|
|
85
|
+
}, {
|
|
86
|
+
name: "data",
|
|
87
|
+
type: "bytes",
|
|
88
|
+
internalType: "bytes"
|
|
89
|
+
}]
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
outputs: [{
|
|
93
|
+
name: "seizedAmount",
|
|
94
|
+
type: "uint256",
|
|
95
|
+
internalType: "uint256"
|
|
96
|
+
}],
|
|
97
|
+
stateMutability: "nonpayable"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
type: "function",
|
|
101
|
+
name: "premiumScaleFactor",
|
|
102
|
+
inputs: [],
|
|
103
|
+
outputs: [{
|
|
104
|
+
name: "",
|
|
105
|
+
type: "uint16",
|
|
106
|
+
internalType: "uint16"
|
|
107
|
+
}],
|
|
108
|
+
stateMutability: "view"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
type: "function",
|
|
112
|
+
name: "requiredPermissions",
|
|
113
|
+
inputs: [],
|
|
114
|
+
outputs: [{
|
|
115
|
+
name: "",
|
|
116
|
+
type: "uint192",
|
|
117
|
+
internalType: "uint192"
|
|
118
|
+
}],
|
|
119
|
+
stateMutability: "view"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "function",
|
|
123
|
+
name: "serialize",
|
|
124
|
+
inputs: [],
|
|
125
|
+
outputs: [{
|
|
126
|
+
name: "serializedData",
|
|
127
|
+
type: "bytes",
|
|
128
|
+
internalType: "bytes"
|
|
129
|
+
}],
|
|
130
|
+
stateMutability: "view"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: "function",
|
|
134
|
+
name: "treasury",
|
|
135
|
+
inputs: [],
|
|
136
|
+
outputs: [{
|
|
137
|
+
name: "",
|
|
138
|
+
type: "address",
|
|
139
|
+
internalType: "address"
|
|
140
|
+
}],
|
|
141
|
+
stateMutability: "view"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: "function",
|
|
145
|
+
name: "version",
|
|
146
|
+
inputs: [],
|
|
147
|
+
outputs: [{
|
|
148
|
+
name: "",
|
|
149
|
+
type: "uint256",
|
|
150
|
+
internalType: "uint256"
|
|
151
|
+
}],
|
|
152
|
+
stateMutability: "view"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: "event",
|
|
156
|
+
name: "PartiallyLiquidate",
|
|
157
|
+
inputs: [
|
|
158
|
+
{
|
|
159
|
+
name: "creditManager",
|
|
160
|
+
type: "address",
|
|
161
|
+
indexed: true,
|
|
162
|
+
internalType: "address"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "creditAccount",
|
|
166
|
+
type: "address",
|
|
167
|
+
indexed: true,
|
|
168
|
+
internalType: "address"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: "token",
|
|
172
|
+
type: "address",
|
|
173
|
+
indexed: true,
|
|
174
|
+
internalType: "address"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "liquidator",
|
|
178
|
+
type: "address",
|
|
179
|
+
indexed: false,
|
|
180
|
+
internalType: "address"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "repaidDebt",
|
|
184
|
+
type: "uint256",
|
|
185
|
+
indexed: false,
|
|
186
|
+
internalType: "uint256"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "seizedCollateral",
|
|
190
|
+
type: "uint256",
|
|
191
|
+
indexed: false,
|
|
192
|
+
internalType: "uint256"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "fee",
|
|
196
|
+
type: "uint256",
|
|
197
|
+
indexed: false,
|
|
198
|
+
internalType: "uint256"
|
|
199
|
+
}
|
|
200
|
+
],
|
|
201
|
+
anonymous: false
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: "error",
|
|
205
|
+
name: "LiquidatedLessThanNeededException",
|
|
206
|
+
inputs: []
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
type: "error",
|
|
210
|
+
name: "LiquidatedMoreThanNeededException",
|
|
211
|
+
inputs: []
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
type: "error",
|
|
215
|
+
name: "SeizedLessThanRequiredException",
|
|
216
|
+
inputs: []
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
type: "error",
|
|
220
|
+
name: "UnderlyingNotLiquidatableException",
|
|
221
|
+
inputs: []
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
//#endregion
|
|
225
|
+
exports.iPartialLiquidationBotV310Abi = iPartialLiquidationBotV310Abi;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_plugins_bots_abi_iPartialLiquidationBotV310 = require("./iPartialLiquidationBotV310.js");
|
|
3
|
+
exports.iPartialLiquidationBotV310Abi = require_plugins_bots_abi_iPartialLiquidationBotV310.iPartialLiquidationBotV310Abi;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../../onchain/constants/bot-permissions.js");
|
|
3
|
+
require("../../onchain/index.js");
|
|
4
|
+
//#region src/plugins/bots/config.ts
|
|
5
|
+
const PARTIAL_LIQUIDATION_BOT_CONFIGS = {
|
|
6
|
+
Mainnet: [{
|
|
7
|
+
minHealthFactor: 10300,
|
|
8
|
+
maxHealthFactor: 10700,
|
|
9
|
+
premiumScaleFactor: 1e4,
|
|
10
|
+
feeScaleFactor: 1e4
|
|
11
|
+
}],
|
|
12
|
+
Monad: [{
|
|
13
|
+
minHealthFactor: 10300,
|
|
14
|
+
maxHealthFactor: 10700,
|
|
15
|
+
premiumScaleFactor: 1e4,
|
|
16
|
+
feeScaleFactor: 1e4
|
|
17
|
+
}],
|
|
18
|
+
Plasma: [{
|
|
19
|
+
minHealthFactor: 10300,
|
|
20
|
+
maxHealthFactor: 10700,
|
|
21
|
+
premiumScaleFactor: 1e4,
|
|
22
|
+
feeScaleFactor: 1e4
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
const PARTIAL_LIQUIDATION_BOT_SALT = "GEARBOX";
|
|
26
|
+
const PARTIAL_LIQUIDATION_BOT_DEPLOYER = "0xc93155E0a835Cf4E17a19463Fa67ed43c164d06a";
|
|
27
|
+
const LEGACY_MIGRATION_BOT = {
|
|
28
|
+
address: "0x286Fe53994f5668D56538Aa10eaa3Ac36f878e9C".toLowerCase(),
|
|
29
|
+
previewer: "0x6523B8c9daB92eea7944a79b4Dbb598c7934DCca".toLowerCase(),
|
|
30
|
+
version: 310,
|
|
31
|
+
baseType: "LEGACY_MIGRATION"
|
|
32
|
+
};
|
|
33
|
+
const PERMISSION_BY_TYPE = { LEGACY_MIGRATION: BigInt(65604) };
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.LEGACY_MIGRATION_BOT = LEGACY_MIGRATION_BOT;
|
|
36
|
+
exports.PARTIAL_LIQUIDATION_BOT_CONFIGS = PARTIAL_LIQUIDATION_BOT_CONFIGS;
|
|
37
|
+
exports.PARTIAL_LIQUIDATION_BOT_DEPLOYER = PARTIAL_LIQUIDATION_BOT_DEPLOYER;
|
|
38
|
+
exports.PARTIAL_LIQUIDATION_BOT_SALT = PARTIAL_LIQUIDATION_BOT_SALT;
|
|
39
|
+
exports.PERMISSION_BY_TYPE = PERMISSION_BY_TYPE;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
let viem = require("viem");
|
|
6
|
+
//#region src/plugins/bots/deserializePartialLiquidationBotParams.ts
|
|
7
|
+
function deserializePartialLiquidationBotParams(params) {
|
|
8
|
+
const [treasury, minHealthFactor, maxHealthFactor, premiumScaleFactor, feeScaleFactor] = (0, viem.decodeAbiParameters)([
|
|
9
|
+
{
|
|
10
|
+
name: "treasury",
|
|
11
|
+
type: "address"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "minHealthFactor",
|
|
15
|
+
type: "uint16"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "maxHealthFactor",
|
|
19
|
+
type: "uint16"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "premiumScaleFactor",
|
|
23
|
+
type: "uint16"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "feeScaleFactor",
|
|
27
|
+
type: "uint16"
|
|
28
|
+
}
|
|
29
|
+
], params.serializedParams);
|
|
30
|
+
return {
|
|
31
|
+
treasury,
|
|
32
|
+
minHealthFactor,
|
|
33
|
+
maxHealthFactor,
|
|
34
|
+
premiumScaleFactor,
|
|
35
|
+
feeScaleFactor
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.default = deserializePartialLiquidationBotParams;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_plugins_bots_abi_iPartialLiquidationBotV310 = require("./abi/iPartialLiquidationBotV310.js");
|
|
3
|
+
const require_plugins_bots_config = require("./config.js");
|
|
4
|
+
require("./abi/index.js");
|
|
5
|
+
const require_plugins_bots_types = require("./types.js");
|
|
6
|
+
const require_plugins_bots_PartialLiquidationBotV310Contract = require("./PartialLiquidationBotV310Contract.js");
|
|
7
|
+
const require_plugins_bots_BotsPlugin = require("./BotsPlugin.js");
|
|
8
|
+
exports.BOT_PARAMS_ABI = require_plugins_bots_types.BOT_PARAMS_ABI;
|
|
9
|
+
exports.BOT_PARTIAL_LIQUIDATION = require_plugins_bots_types.BOT_PARTIAL_LIQUIDATION;
|
|
10
|
+
exports.BotsPlugin = require_plugins_bots_BotsPlugin.BotsPlugin;
|
|
11
|
+
exports.LEGACY_MIGRATION_BOT = require_plugins_bots_config.LEGACY_MIGRATION_BOT;
|
|
12
|
+
exports.PARTIAL_LIQUIDATION_BOT_CONFIGS = require_plugins_bots_config.PARTIAL_LIQUIDATION_BOT_CONFIGS;
|
|
13
|
+
exports.PARTIAL_LIQUIDATION_BOT_DEPLOYER = require_plugins_bots_config.PARTIAL_LIQUIDATION_BOT_DEPLOYER;
|
|
14
|
+
exports.PARTIAL_LIQUIDATION_BOT_SALT = require_plugins_bots_config.PARTIAL_LIQUIDATION_BOT_SALT;
|
|
15
|
+
exports.PERMISSION_BY_TYPE = require_plugins_bots_config.PERMISSION_BY_TYPE;
|
|
16
|
+
exports.PartialLiquidationBotV310Contract = require_plugins_bots_PartialLiquidationBotV310Contract.PartialLiquidationBotV310Contract;
|
|
17
|
+
exports.iPartialLiquidationBotV310Abi = require_plugins_bots_abi_iPartialLiquidationBotV310.iPartialLiquidationBotV310Abi;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "commonjs"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/plugins/bots/types.ts
|
|
3
|
+
const BOT_PARTIAL_LIQUIDATION = "BOT::PARTIAL_LIQUIDATION";
|
|
4
|
+
const BOT_PARAMS_ABI = [
|
|
5
|
+
{
|
|
6
|
+
type: "address",
|
|
7
|
+
name: "treasury"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
type: "uint16",
|
|
11
|
+
name: "minHealthFactor"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
type: "uint16",
|
|
15
|
+
name: "maxHealthFactor"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
type: "uint16",
|
|
19
|
+
name: "premiumScaleFactor"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "uint16",
|
|
23
|
+
name: "feeScaleFactor"
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.BOT_PARAMS_ABI = BOT_PARAMS_ABI;
|
|
28
|
+
exports.BOT_PARTIAL_LIQUIDATION = BOT_PARTIAL_LIQUIDATION;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
2
|
+
import { chains } from "../../onchain/chain/chains.js";
|
|
3
|
+
import { AP_BYTECODE_REPOSITORY, AP_TREASURY } from "../../onchain/constants/address-provider.js";
|
|
4
|
+
import { hexEq } from "../../onchain/utils/hex.js";
|
|
5
|
+
import { BasePlugin } from "../../onchain/plugins/BasePlugin.js";
|
|
6
|
+
import "../../onchain/index.js";
|
|
7
|
+
import { iBytecodeRepositoryAbi } from "../../abi/310/iBytecodeRepository.js";
|
|
8
|
+
import { iPartialLiquidationBotV310Abi } from "./abi/iPartialLiquidationBotV310.js";
|
|
9
|
+
import { LEGACY_MIGRATION_BOT, PARTIAL_LIQUIDATION_BOT_CONFIGS, PARTIAL_LIQUIDATION_BOT_DEPLOYER, PARTIAL_LIQUIDATION_BOT_SALT } from "./config.js";
|
|
10
|
+
import { BOT_PARAMS_ABI, BOT_PARTIAL_LIQUIDATION } from "./types.js";
|
|
11
|
+
import { PartialLiquidationBotV310Contract } from "./PartialLiquidationBotV310Contract.js";
|
|
12
|
+
import { encodeAbiParameters, stringToHex } from "viem";
|
|
13
|
+
//#region src/plugins/bots/BotsPlugin.ts
|
|
14
|
+
var BotsPlugin = class extends BasePlugin {
|
|
15
|
+
#bots;
|
|
16
|
+
get loaded() {
|
|
17
|
+
return !!this.#bots;
|
|
18
|
+
}
|
|
19
|
+
get bots() {
|
|
20
|
+
return this.#bots?.values() ?? [];
|
|
21
|
+
}
|
|
22
|
+
async load(force) {
|
|
23
|
+
if (!force && this.loaded) return this.state;
|
|
24
|
+
const treasury = this.sdk.addressProvider.getAddress(AP_TREASURY);
|
|
25
|
+
const bcr = this.sdk.addressProvider.getAddress(AP_BYTECODE_REPOSITORY);
|
|
26
|
+
const configs = PARTIAL_LIQUIDATION_BOT_CONFIGS[this.sdk.networkType] ?? [];
|
|
27
|
+
this.#bots = new AddressMap();
|
|
28
|
+
if (!configs.length) return this.state;
|
|
29
|
+
const deployedBots = await this.client.multicall({
|
|
30
|
+
contracts: configs.map((config) => ({
|
|
31
|
+
address: bcr,
|
|
32
|
+
abi: iBytecodeRepositoryAbi,
|
|
33
|
+
functionName: "computeAddress",
|
|
34
|
+
args: [
|
|
35
|
+
stringToHex(BOT_PARTIAL_LIQUIDATION, { size: 32 }),
|
|
36
|
+
310,
|
|
37
|
+
encodeAbiParameters(BOT_PARAMS_ABI, [
|
|
38
|
+
treasury,
|
|
39
|
+
config.minHealthFactor,
|
|
40
|
+
config.maxHealthFactor,
|
|
41
|
+
config.premiumScaleFactor,
|
|
42
|
+
config.feeScaleFactor
|
|
43
|
+
]),
|
|
44
|
+
stringToHex(PARTIAL_LIQUIDATION_BOT_SALT, { size: 32 }),
|
|
45
|
+
PARTIAL_LIQUIDATION_BOT_DEPLOYER
|
|
46
|
+
]
|
|
47
|
+
})),
|
|
48
|
+
allowFailure: true,
|
|
49
|
+
blockNumber: this.sdk.currentBlock,
|
|
50
|
+
batchSize: 0
|
|
51
|
+
});
|
|
52
|
+
const expectedBots = new AddressMap();
|
|
53
|
+
for (let i = 0; i < configs.length; i++) {
|
|
54
|
+
const b = deployedBots[i];
|
|
55
|
+
const { minHealthFactor, maxHealthFactor } = configs[i];
|
|
56
|
+
if (b.status === "success") {
|
|
57
|
+
expectedBots.upsert(b.result, {
|
|
58
|
+
...configs[i],
|
|
59
|
+
treasury
|
|
60
|
+
});
|
|
61
|
+
this.logger?.debug(`expected bot [${minHealthFactor}, ${maxHealthFactor}] at ${b.result}`);
|
|
62
|
+
} else this.logger?.error(`failed compute address for bot [${minHealthFactor}, ${maxHealthFactor}]`, b.error);
|
|
63
|
+
}
|
|
64
|
+
const botAddrs = expectedBots.keys();
|
|
65
|
+
const serializedBots = await this.client.multicall({
|
|
66
|
+
contracts: botAddrs.map((address) => ({
|
|
67
|
+
address,
|
|
68
|
+
abi: iPartialLiquidationBotV310Abi,
|
|
69
|
+
functionName: "serialize"
|
|
70
|
+
})),
|
|
71
|
+
allowFailure: true,
|
|
72
|
+
blockNumber: this.sdk.currentBlock,
|
|
73
|
+
batchSize: 0
|
|
74
|
+
});
|
|
75
|
+
for (let i = 0; i < botAddrs.length; i++) {
|
|
76
|
+
const serialized = serializedBots[i];
|
|
77
|
+
const expected = expectedBots.mustGet(botAddrs[i]);
|
|
78
|
+
if (serialized.status === "success") {
|
|
79
|
+
const bot = new PartialLiquidationBotV310Contract(this.sdk, {
|
|
80
|
+
addr: botAddrs[i],
|
|
81
|
+
version: BigInt(310),
|
|
82
|
+
contractType: BOT_PARTIAL_LIQUIDATION,
|
|
83
|
+
serializedParams: serialized.result
|
|
84
|
+
});
|
|
85
|
+
if (!hexEq(treasury, expected.treasury) || bot.minHealthFactor !== expected.minHealthFactor || bot.maxHealthFactor !== expected.maxHealthFactor || bot.premiumScaleFactor !== expected.premiumScaleFactor || bot.feeScaleFactor !== expected.feeScaleFactor) this.logger?.error(`serialized bot ${botAddrs[i]} does not match expected bot`, serialized.error);
|
|
86
|
+
else this.#bots.upsert(botAddrs[i], bot);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return this.state;
|
|
90
|
+
}
|
|
91
|
+
stateHuman(raw) {
|
|
92
|
+
return { bots: this.#bots?.values().map((bot) => bot.stateHuman(raw)) ?? [] };
|
|
93
|
+
}
|
|
94
|
+
get state() {
|
|
95
|
+
return { bots: this.#bots?.values().map((bot) => bot.state) ?? [] };
|
|
96
|
+
}
|
|
97
|
+
hydrate(state) {
|
|
98
|
+
this.#bots = new AddressMap();
|
|
99
|
+
for (const botState of state.bots) this.#bots.upsert(botState.addr, new PartialLiquidationBotV310Contract(this.sdk, botState));
|
|
100
|
+
}
|
|
101
|
+
static getMigrationBotData(chainId) {
|
|
102
|
+
return chainId === chains.Mainnet.id ? LEGACY_MIGRATION_BOT : void 0;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { BotsPlugin };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { percentFmt } from "../../onchain/utils/formatter.js";
|
|
2
|
+
import { BaseContract } from "../../onchain/base/BaseContract.js";
|
|
3
|
+
import "../../onchain/index.js";
|
|
4
|
+
import { iPartialLiquidationBotV310Abi } from "./abi/iPartialLiquidationBotV310.js";
|
|
5
|
+
import "./abi/index.js";
|
|
6
|
+
import { BOT_PARAMS_ABI } from "./types.js";
|
|
7
|
+
import { decodeAbiParameters, stringToHex } from "viem";
|
|
8
|
+
//#region src/plugins/bots/PartialLiquidationBotV310Contract.ts
|
|
9
|
+
const abi = iPartialLiquidationBotV310Abi;
|
|
10
|
+
var PartialLiquidationBotV310Contract = class extends BaseContract {
|
|
11
|
+
treasury;
|
|
12
|
+
minHealthFactor;
|
|
13
|
+
maxHealthFactor;
|
|
14
|
+
premiumScaleFactor;
|
|
15
|
+
feeScaleFactor;
|
|
16
|
+
#serializedParams;
|
|
17
|
+
constructor(sdk, args) {
|
|
18
|
+
super(sdk, {
|
|
19
|
+
...args,
|
|
20
|
+
abi,
|
|
21
|
+
name: "PartialLiquidationBotV310"
|
|
22
|
+
});
|
|
23
|
+
[this.treasury, this.minHealthFactor, this.maxHealthFactor, this.premiumScaleFactor, this.feeScaleFactor] = decodeAbiParameters(BOT_PARAMS_ABI, args.serializedParams);
|
|
24
|
+
this.#serializedParams = args.serializedParams;
|
|
25
|
+
}
|
|
26
|
+
stateHuman(raw) {
|
|
27
|
+
return {
|
|
28
|
+
...super.stateHuman(raw),
|
|
29
|
+
treasury: this.treasury,
|
|
30
|
+
minHealthFactor: percentFmt(this.minHealthFactor, raw),
|
|
31
|
+
maxHealthFactor: percentFmt(this.maxHealthFactor, raw),
|
|
32
|
+
premiumScaleFactor: percentFmt(this.premiumScaleFactor, raw),
|
|
33
|
+
feeScaleFactor: percentFmt(this.feeScaleFactor, raw)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
get state() {
|
|
37
|
+
return {
|
|
38
|
+
addr: this.address,
|
|
39
|
+
version: BigInt(this.version),
|
|
40
|
+
contractType: stringToHex(this.contractType, { size: 32 }),
|
|
41
|
+
serializedParams: this.#serializedParams
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { PartialLiquidationBotV310Contract };
|