@gearbox-protocol/sdk 11.0.0-next.2 → 11.0.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.
@@ -22,18 +22,72 @@ __export(treasury_splitter_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(treasury_splitter_exports);
24
24
  var import_iTreasurySplitter = require("../../abi/310/iTreasurySplitter.js");
25
+ var import_abi_decoder = require("../utils/abi-decoder.js");
25
26
  var import_base_contract = require("./base-contract.js");
26
27
  const abi = import_iTreasurySplitter.ITreasurySplitterAbi;
27
28
  class TreasurySplitterContract extends import_base_contract.BaseContract {
28
29
  constructor(address, client) {
29
30
  super(abi, address, client, "TreasurySplitter");
30
31
  }
32
+ async defaultSplit() {
33
+ return await this.contract.read.defaultSplit();
34
+ }
35
+ async activeProposals() {
36
+ return this.contract.read.activeProposals();
37
+ }
31
38
  distribute(token) {
32
39
  return this.createRawTx({
33
40
  functionName: "distribute",
34
41
  args: [token]
35
42
  });
36
43
  }
44
+ setDefaultSplitTx(receivers, proportions) {
45
+ const rawTx = this.createRawTx({
46
+ functionName: "setDefaultSplit",
47
+ args: [receivers, proportions]
48
+ });
49
+ return this.wrapConfigure(rawTx);
50
+ }
51
+ setTokenSplitTx(token, receivers, proportions, distributeBefore) {
52
+ const rawTx = this.createRawTx({
53
+ functionName: "setTokenSplit",
54
+ args: [token, receivers, proportions, distributeBefore]
55
+ });
56
+ return this.wrapConfigure(rawTx);
57
+ }
58
+ setTokenInsuranceAmountTx(token, amount) {
59
+ const rawTx = this.createRawTx({
60
+ functionName: "setTokenInsuranceAmount",
61
+ args: [token, amount]
62
+ });
63
+ return this.wrapConfigure(rawTx);
64
+ }
65
+ withdrawTokenTx(token, to, amount) {
66
+ const rawTx = this.createRawTx({
67
+ functionName: "withdrawToken",
68
+ args: [token, to, amount]
69
+ });
70
+ return this.wrapConfigure(rawTx);
71
+ }
72
+ configureTx(callData) {
73
+ return this.createRawTx({
74
+ functionName: "configure",
75
+ args: [callData]
76
+ });
77
+ }
78
+ cancelConfigureTx(callData) {
79
+ const rawTx = this.createRawTx({
80
+ functionName: "cancelConfigure",
81
+ args: [callData]
82
+ });
83
+ return rawTx;
84
+ }
85
+ wrapConfigure(rawTx) {
86
+ return this.createRawTx({
87
+ functionName: "configure",
88
+ args: [rawTx.callData]
89
+ });
90
+ }
37
91
  parseFunctionParams(params) {
38
92
  const { functionName, args } = params;
39
93
  switch (functionName) {
@@ -49,6 +103,23 @@ class TreasurySplitterContract extends import_base_contract.BaseContract {
49
103
  }
50
104
  };
51
105
  }
106
+ case "configure": {
107
+ const [callData] = args;
108
+ const decoded = (0, import_abi_decoder.decodeFunctionWithNamedArgs)(abi, callData);
109
+ if (decoded) {
110
+ return {
111
+ chainId: 0,
112
+ target: this.address,
113
+ label: this.name,
114
+ functionName,
115
+ args: {
116
+ functionName: decoded.functionName,
117
+ ...decoded.args
118
+ }
119
+ };
120
+ }
121
+ return void 0;
122
+ }
52
123
  default:
53
124
  return void 0;
54
125
  }
@@ -1,10 +1,474 @@
1
1
  const ITreasurySplitterAbi = [
2
+ {
3
+ type: "function",
4
+ name: "activeProposals",
5
+ inputs: [],
6
+ outputs: [
7
+ {
8
+ name: "",
9
+ type: "tuple[]",
10
+ internalType: "struct TwoAdminProposal[]",
11
+ components: [
12
+ {
13
+ name: "callData",
14
+ type: "bytes",
15
+ internalType: "bytes"
16
+ },
17
+ {
18
+ name: "confirmedByAdmin",
19
+ type: "bool",
20
+ internalType: "bool"
21
+ },
22
+ {
23
+ name: "confirmedByTreasuryProxy",
24
+ type: "bool",
25
+ internalType: "bool"
26
+ }
27
+ ]
28
+ }
29
+ ],
30
+ stateMutability: "view"
31
+ },
32
+ {
33
+ type: "function",
34
+ name: "admin",
35
+ inputs: [],
36
+ outputs: [
37
+ {
38
+ name: "",
39
+ type: "address",
40
+ internalType: "address"
41
+ }
42
+ ],
43
+ stateMutability: "view"
44
+ },
45
+ {
46
+ type: "function",
47
+ name: "cancelConfigure",
48
+ inputs: [
49
+ {
50
+ name: "callData",
51
+ type: "bytes",
52
+ internalType: "bytes"
53
+ }
54
+ ],
55
+ outputs: [],
56
+ stateMutability: "nonpayable"
57
+ },
58
+ {
59
+ type: "function",
60
+ name: "configure",
61
+ inputs: [
62
+ {
63
+ name: "callData",
64
+ type: "bytes",
65
+ internalType: "bytes"
66
+ }
67
+ ],
68
+ outputs: [],
69
+ stateMutability: "nonpayable"
70
+ },
71
+ {
72
+ type: "function",
73
+ name: "contractType",
74
+ inputs: [],
75
+ outputs: [
76
+ {
77
+ name: "",
78
+ type: "bytes32",
79
+ internalType: "bytes32"
80
+ }
81
+ ],
82
+ stateMutability: "view"
83
+ },
84
+ {
85
+ type: "function",
86
+ name: "defaultSplit",
87
+ inputs: [],
88
+ outputs: [
89
+ {
90
+ name: "",
91
+ type: "tuple",
92
+ internalType: "struct Split",
93
+ components: [
94
+ {
95
+ name: "initialized",
96
+ type: "bool",
97
+ internalType: "bool"
98
+ },
99
+ {
100
+ name: "receivers",
101
+ type: "address[]",
102
+ internalType: "address[]"
103
+ },
104
+ {
105
+ name: "proportions",
106
+ type: "uint16[]",
107
+ internalType: "uint16[]"
108
+ }
109
+ ]
110
+ }
111
+ ],
112
+ stateMutability: "view"
113
+ },
2
114
  {
3
115
  type: "function",
4
116
  name: "distribute",
5
- inputs: [{ name: "token", type: "address", internalType: "address" }],
117
+ inputs: [
118
+ {
119
+ name: "token",
120
+ type: "address",
121
+ internalType: "address"
122
+ }
123
+ ],
124
+ outputs: [],
125
+ stateMutability: "nonpayable"
126
+ },
127
+ {
128
+ type: "function",
129
+ name: "getProposal",
130
+ inputs: [
131
+ {
132
+ name: "callDataHash",
133
+ type: "bytes32",
134
+ internalType: "bytes32"
135
+ }
136
+ ],
137
+ outputs: [
138
+ {
139
+ name: "",
140
+ type: "tuple",
141
+ internalType: "struct TwoAdminProposal",
142
+ components: [
143
+ {
144
+ name: "callData",
145
+ type: "bytes",
146
+ internalType: "bytes"
147
+ },
148
+ {
149
+ name: "confirmedByAdmin",
150
+ type: "bool",
151
+ internalType: "bool"
152
+ },
153
+ {
154
+ name: "confirmedByTreasuryProxy",
155
+ type: "bool",
156
+ internalType: "bool"
157
+ }
158
+ ]
159
+ }
160
+ ],
161
+ stateMutability: "view"
162
+ },
163
+ {
164
+ type: "function",
165
+ name: "setDefaultSplit",
166
+ inputs: [
167
+ {
168
+ name: "receivers",
169
+ type: "address[]",
170
+ internalType: "address[]"
171
+ },
172
+ {
173
+ name: "proportions",
174
+ type: "uint16[]",
175
+ internalType: "uint16[]"
176
+ }
177
+ ],
178
+ outputs: [],
179
+ stateMutability: "nonpayable"
180
+ },
181
+ {
182
+ type: "function",
183
+ name: "setTokenInsuranceAmount",
184
+ inputs: [
185
+ {
186
+ name: "token",
187
+ type: "address",
188
+ internalType: "address"
189
+ },
190
+ {
191
+ name: "amount",
192
+ type: "uint256",
193
+ internalType: "uint256"
194
+ }
195
+ ],
196
+ outputs: [],
197
+ stateMutability: "nonpayable"
198
+ },
199
+ {
200
+ type: "function",
201
+ name: "setTokenSplit",
202
+ inputs: [
203
+ {
204
+ name: "token",
205
+ type: "address",
206
+ internalType: "address"
207
+ },
208
+ {
209
+ name: "receivers",
210
+ type: "address[]",
211
+ internalType: "address[]"
212
+ },
213
+ {
214
+ name: "proportions",
215
+ type: "uint16[]",
216
+ internalType: "uint16[]"
217
+ },
218
+ {
219
+ name: "distribute",
220
+ type: "bool",
221
+ internalType: "bool"
222
+ }
223
+ ],
6
224
  outputs: [],
7
225
  stateMutability: "nonpayable"
226
+ },
227
+ {
228
+ type: "function",
229
+ name: "tokenInsuranceAmount",
230
+ inputs: [
231
+ {
232
+ name: "token",
233
+ type: "address",
234
+ internalType: "address"
235
+ }
236
+ ],
237
+ outputs: [
238
+ {
239
+ name: "",
240
+ type: "uint256",
241
+ internalType: "uint256"
242
+ }
243
+ ],
244
+ stateMutability: "view"
245
+ },
246
+ {
247
+ type: "function",
248
+ name: "tokenSplits",
249
+ inputs: [
250
+ {
251
+ name: "token",
252
+ type: "address",
253
+ internalType: "address"
254
+ }
255
+ ],
256
+ outputs: [
257
+ {
258
+ name: "",
259
+ type: "tuple",
260
+ internalType: "struct Split",
261
+ components: [
262
+ {
263
+ name: "initialized",
264
+ type: "bool",
265
+ internalType: "bool"
266
+ },
267
+ {
268
+ name: "receivers",
269
+ type: "address[]",
270
+ internalType: "address[]"
271
+ },
272
+ {
273
+ name: "proportions",
274
+ type: "uint16[]",
275
+ internalType: "uint16[]"
276
+ }
277
+ ]
278
+ }
279
+ ],
280
+ stateMutability: "view"
281
+ },
282
+ {
283
+ type: "function",
284
+ name: "treasuryProxy",
285
+ inputs: [],
286
+ outputs: [
287
+ {
288
+ name: "",
289
+ type: "address",
290
+ internalType: "address"
291
+ }
292
+ ],
293
+ stateMutability: "view"
294
+ },
295
+ {
296
+ type: "function",
297
+ name: "version",
298
+ inputs: [],
299
+ outputs: [
300
+ {
301
+ name: "",
302
+ type: "uint256",
303
+ internalType: "uint256"
304
+ }
305
+ ],
306
+ stateMutability: "view"
307
+ },
308
+ {
309
+ type: "function",
310
+ name: "withdrawToken",
311
+ inputs: [
312
+ {
313
+ name: "token",
314
+ type: "address",
315
+ internalType: "address"
316
+ },
317
+ {
318
+ name: "to",
319
+ type: "address",
320
+ internalType: "address"
321
+ },
322
+ {
323
+ name: "amount",
324
+ type: "uint256",
325
+ internalType: "uint256"
326
+ }
327
+ ],
328
+ outputs: [],
329
+ stateMutability: "nonpayable"
330
+ },
331
+ {
332
+ type: "event",
333
+ name: "DistributeToken",
334
+ inputs: [
335
+ {
336
+ name: "token",
337
+ type: "address",
338
+ indexed: true,
339
+ internalType: "address"
340
+ },
341
+ {
342
+ name: "distributedAmount",
343
+ type: "uint256",
344
+ indexed: false,
345
+ internalType: "uint256"
346
+ }
347
+ ],
348
+ anonymous: false
349
+ },
350
+ {
351
+ type: "event",
352
+ name: "SetDefaultSplit",
353
+ inputs: [
354
+ {
355
+ name: "receivers",
356
+ type: "address[]",
357
+ indexed: false,
358
+ internalType: "address[]"
359
+ },
360
+ {
361
+ name: "proportions",
362
+ type: "uint16[]",
363
+ indexed: false,
364
+ internalType: "uint16[]"
365
+ }
366
+ ],
367
+ anonymous: false
368
+ },
369
+ {
370
+ type: "event",
371
+ name: "SetTokenInsuranceAmount",
372
+ inputs: [
373
+ {
374
+ name: "token",
375
+ type: "address",
376
+ indexed: true,
377
+ internalType: "address"
378
+ },
379
+ {
380
+ name: "amount",
381
+ type: "uint256",
382
+ indexed: false,
383
+ internalType: "uint256"
384
+ }
385
+ ],
386
+ anonymous: false
387
+ },
388
+ {
389
+ type: "event",
390
+ name: "SetTokenSplit",
391
+ inputs: [
392
+ {
393
+ name: "token",
394
+ type: "address",
395
+ indexed: true,
396
+ internalType: "address"
397
+ },
398
+ {
399
+ name: "receivers",
400
+ type: "address[]",
401
+ indexed: false,
402
+ internalType: "address[]"
403
+ },
404
+ {
405
+ name: "proportions",
406
+ type: "uint16[]",
407
+ indexed: false,
408
+ internalType: "uint16[]"
409
+ }
410
+ ],
411
+ anonymous: false
412
+ },
413
+ {
414
+ type: "event",
415
+ name: "WithdrawToken",
416
+ inputs: [
417
+ {
418
+ name: "token",
419
+ type: "address",
420
+ indexed: true,
421
+ internalType: "address"
422
+ },
423
+ {
424
+ name: "to",
425
+ type: "address",
426
+ indexed: true,
427
+ internalType: "address"
428
+ },
429
+ {
430
+ name: "withdrawnAmount",
431
+ type: "uint256",
432
+ indexed: false,
433
+ internalType: "uint256"
434
+ }
435
+ ],
436
+ anonymous: false
437
+ },
438
+ {
439
+ type: "error",
440
+ name: "IncorrectConfigureSelectorException",
441
+ inputs: []
442
+ },
443
+ {
444
+ type: "error",
445
+ name: "OnlyAdminOrTreasuryProxyException",
446
+ inputs: []
447
+ },
448
+ {
449
+ type: "error",
450
+ name: "OnlySelfException",
451
+ inputs: []
452
+ },
453
+ {
454
+ type: "error",
455
+ name: "PropotionSumIncorrectException",
456
+ inputs: []
457
+ },
458
+ {
459
+ type: "error",
460
+ name: "SplitArraysDifferentLengthException",
461
+ inputs: []
462
+ },
463
+ {
464
+ type: "error",
465
+ name: "TreasurySplitterAsReceiverException",
466
+ inputs: []
467
+ },
468
+ {
469
+ type: "error",
470
+ name: "UndefinedSplitException",
471
+ inputs: []
8
472
  }
9
473
  ];
10
474
  export {
@@ -1,9 +1,4 @@
1
- import {
2
- createPublicClient,
3
- testActions,
4
- toHex,
5
- walletActions
6
- } from "viem";
1
+ import { createPublicClient, testActions, toHex, walletActions } from "viem";
7
2
  function extendAnvilClient(client) {
8
3
  return client.extend(testActions({ mode: "anvil" })).extend(walletActions).extend((c) => ({
9
4
  anvilNodeInfo: () => anvilNodeInfo(c),
@@ -10,4 +10,5 @@ export * from "./ltUtils.js";
10
10
  export * from "./migrateFaucet.js";
11
11
  export * from "./mint/index.js";
12
12
  export * from "./RevolverTransport.js";
13
+ export * from "./replaceStorage.js";
13
14
  export * from "./types.js";
@@ -0,0 +1,56 @@
1
+ import {
2
+ encodeFunctionData,
3
+ numberToHex
4
+ } from "viem";
5
+ import { readContract } from "viem/actions";
6
+ async function replaceStorage(client, params) {
7
+ const { value, slotMatch, address, abi, functionName, args } = params;
8
+ const newValHex = numberToHex(params.value, { size: 32 });
9
+ const { accessList } = await client.createAccessList({
10
+ to: address,
11
+ data: encodeFunctionData({
12
+ abi,
13
+ functionName,
14
+ args
15
+ })
16
+ });
17
+ for (const { address: addr_, storageKeys } of accessList) {
18
+ const addr = addr_.toLowerCase();
19
+ for (const slot of storageKeys) {
20
+ try {
21
+ const result = await readContract(client, {
22
+ abi,
23
+ address,
24
+ functionName,
25
+ args,
26
+ stateOverride: [
27
+ {
28
+ address: addr,
29
+ stateDiff: [
30
+ {
31
+ slot,
32
+ value: newValHex
33
+ }
34
+ ]
35
+ }
36
+ ]
37
+ });
38
+ if (slotMatch(
39
+ result,
40
+ value
41
+ )) {
42
+ await client.setStorageAt({
43
+ address,
44
+ index: slot,
45
+ value: newValHex
46
+ });
47
+ return;
48
+ }
49
+ } catch {
50
+ }
51
+ }
52
+ }
53
+ }
54
+ export {
55
+ replaceStorage
56
+ };
@@ -15,6 +15,7 @@ import { BaseContract } from "./base-contract.js";
15
15
  import { WithdrawalCompressorContract } from "./compressors/index.js";
16
16
  import { PriceFeedStoreContract } from "./price-feed-store.js";
17
17
  import { RoutingManagerContract } from "./router/index.js";
18
+ import { TreasurySplitterContract } from "./treasury-splitter.js";
18
19
  const abi = instanceManagerAbi;
19
20
  class InstanceManagerContract extends BaseContract {
20
21
  constructor(address, client) {
@@ -145,6 +146,36 @@ class InstanceManagerContract extends BaseContract {
145
146
  }
146
147
  };
147
148
  }
149
+ case "configureTreasury": {
150
+ const [target, data] = params.args;
151
+ let decoded = void 0;
152
+ try {
153
+ const treasurySplitter = new TreasurySplitterContract(
154
+ target,
155
+ this.client
156
+ );
157
+ const parsedData = treasurySplitter.parseFunctionData(data);
158
+ if (!parsedData.functionName.startsWith("Unknown function")) {
159
+ decoded = parsedData;
160
+ }
161
+ } catch {
162
+ decoded = void 0;
163
+ }
164
+ return {
165
+ chainId: 0,
166
+ target: this.address,
167
+ label: this.name,
168
+ functionName: params.functionName,
169
+ args: decoded ? {
170
+ target,
171
+ functionName: decoded.functionName,
172
+ data: json_stringify(decoded.args)
173
+ } : {
174
+ target,
175
+ data
176
+ }
177
+ };
178
+ }
148
179
  case "activate": {
149
180
  const [instanceOwner, treasury, weth, gear] = params.args;
150
181
  return this.wrapParseCall(params, {
@@ -196,6 +227,13 @@ class InstanceManagerContract extends BaseContract {
196
227
  description: rawTx.description ? `InstanceManager.configureLocal(${rawTx.description})` : void 0
197
228
  });
198
229
  }
230
+ wrapConfigureTreasury(rawTx) {
231
+ return this.createRawTx({
232
+ functionName: "configureTreasury",
233
+ args: [rawTx.to, rawTx.callData],
234
+ description: rawTx.description ? `InstanceManager.configureTreasury(${rawTx.description})` : void 0
235
+ });
236
+ }
199
237
  setLocalAddress(args) {
200
238
  const { key, address, saveVersion } = args;
201
239
  return this.createRawTx({
@@ -444,6 +444,18 @@ class MarketConfiguratorContract extends BaseContract {
444
444
  args: [stringToHex(role, { size: 32 }), address]
445
445
  });
446
446
  }
447
+ revokeRole(role, address) {
448
+ return this.createRawTx({
449
+ functionName: "revokeRole",
450
+ args: [stringToHex(role, { size: 32 }), address]
451
+ });
452
+ }
453
+ setEmergencyAdmin(newEmergencyAdmin) {
454
+ return this.createRawTx({
455
+ functionName: "setEmergencyAdmin",
456
+ args: [newEmergencyAdmin]
457
+ });
458
+ }
447
459
  //
448
460
  // SYNC
449
461
  //