@gearbox-protocol/sdk 18.5.0-next.4 → 18.5.0-next.6
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/onchain/market/loss-policy/AliasLossPolicyV310Contract.js +1 -1
- package/dist/cjs/onchain/market/loss-policy/constants.js +6 -0
- package/dist/cjs/onchain/market/loss-policy/createLossPolicy.js +2 -1
- package/dist/cjs/permissionless/bindings/market-configurator.js +63 -32
- package/dist/cjs/permissionless/curator/actions/addAssetActionData.js +1 -0
- package/dist/cjs/permissionless/curator/actions/addCollateralTokenActionData.js +1 -0
- package/dist/cjs/permissionless/curator/actions/addPeripheryContractActionData.js +4 -4
- package/dist/cjs/permissionless/curator/actions/allowAdapterActionData.js +1 -0
- package/dist/cjs/permissionless/curator/actions/createMarketActionData.js +3 -4
- package/dist/cjs/permissionless/curator/actions/deployContractActionData.js +4 -6
- package/dist/cjs/permissionless/curator/actions/setPriceFeedActionData.js +1 -0
- package/dist/cjs/permissionless/curator/actions/setReservePriceFeedActionData.js +1 -0
- package/dist/cjs/permissionless/curator/actions/updateLossPolicyActionData.js +6 -5
- package/dist/cjs/permissionless/curator/actions/updateRateKeeperActionData.js +2 -1
- package/dist/cjs/permissionless/curator/actions/upgradeCreditFacadeActionData.js +1 -0
- package/dist/cjs/permissionless/curator/actions/utils/priceFeedChecks.js +5 -14
- package/dist/cjs/permissionless/curator/actions/utils/systemContracts.js +35 -0
- package/dist/cjs/permissionless/curator/configurator-actions/addAdminActionData.js +3 -3
- package/dist/cjs/permissionless/curator/configurator-actions/configuratorActionDefinitions.js +4 -0
- package/dist/cjs/permissionless/curator/configurator-actions/configuratorActionHelpers.js +35 -16
- package/dist/cjs/permissionless/curator/configurator-actions/grantRoleActionData.js +31 -0
- package/dist/cjs/permissionless/curator/configurator-actions/index.js +4 -0
- package/dist/cjs/permissionless/curator/configurator-actions/removeAdminActionData.js +3 -3
- package/dist/cjs/permissionless/curator/configurator-actions/revokeRoleActionData.js +38 -0
- package/dist/cjs/permissionless/curator/executor/MarketExecutor.js +44 -8
- package/dist/cjs/permissionless/curator/index.js +9 -0
- package/dist/cjs/permissionless/curator/plugins/adapters/abstract-adapter/getAbstractAdapterPlugin.js +20 -2
- package/dist/cjs/permissionless/curator/plugins/adapters/builtinAdapterPlugins.js +4 -0
- package/dist/cjs/permissionless/curator/plugins/adapters/treehouse-router/setAssetStatusBatchActionData.js +42 -0
- package/dist/cjs/permissionless/curator/plugins/adapters/treehouse-router/treehouseRouterAdapterPlugin.js +36 -0
- package/dist/cjs/permissionless/curator/plugins/index.js +5 -0
- package/dist/cjs/permissionless/curator/plugins/loss-policies/alias/actions/setAccessModeActionData.js +2 -1
- package/dist/cjs/permissionless/curator/plugins/loss-policies/alias/actions/setAliasActionData.js +3 -1
- package/dist/cjs/permissionless/curator/plugins/loss-policies/alias/actions/setChecksEnabledActionData.js +2 -1
- package/dist/cjs/permissionless/curator/plugins/loss-policies/alias/aliasPlugin.js +7 -37
- package/dist/cjs/permissionless/curator/plugins/loss-policies/alias/aliasedLossPolicyPlugin.js +52 -0
- package/dist/cjs/permissionless/curator/plugins/loss-policies/alias/updateAliasLossPolicy.js +6 -2
- package/dist/cjs/permissionless/curator/plugins/loss-policies/lossPolicyPlugins.js +6 -2
- package/dist/cjs/permissionless/curator/plugins/loss-policies/midas-alias/midasAliasPlugin.js +17 -0
- package/dist/cjs/permissionless/curator/session/CuratorSession.js +5 -4
- package/dist/cjs/permissionless/curator/session/rwaPeripheryLookups.js +3 -9
- package/dist/cjs/permissionless/curator/state/configurator/compareConfiguratorStates.js +9 -0
- package/dist/cjs/permissionless/curator/state/configurator/getConfiguratorState.js +2 -1
- package/dist/cjs/permissionless/curator/state/configurator/types.js +27 -1
- package/dist/cjs/permissionless/curator/state/market/buildLossPolicyState.js +3 -1
- package/dist/cjs/permissionless/curator/utils/objectUtils.js +5 -0
- package/dist/cjs/permissionless/index.js +12 -3
- package/dist/cjs/permissionless/plugins/loss-policies/constructor-params-abi.js +4 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/history/trace/extractTransfers.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +4 -4
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +6 -6
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +2 -2
- package/dist/esm/onchain/base/TokensMeta.js +4 -4
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/loss-policy/AliasLossPolicyV310Contract.js +2 -2
- package/dist/esm/onchain/market/loss-policy/constants.js +6 -1
- package/dist/esm/onchain/market/loss-policy/createLossPolicy.js +3 -2
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +3 -3
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +2 -2
- package/dist/esm/onchain/pools/PoolService.js +1 -1
- package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +1 -1
- package/dist/esm/permissionless/bindings/market-configurator.js +63 -32
- package/dist/esm/permissionless/curator/actions/addAssetActionData.js +1 -0
- package/dist/esm/permissionless/curator/actions/addCollateralTokenActionData.js +1 -0
- package/dist/esm/permissionless/curator/actions/addPeripheryContractActionData.js +4 -4
- package/dist/esm/permissionless/curator/actions/allowAdapterActionData.js +1 -0
- package/dist/esm/permissionless/curator/actions/createMarketActionData.js +3 -4
- package/dist/esm/permissionless/curator/actions/deployContractActionData.js +4 -6
- package/dist/esm/permissionless/curator/actions/setPriceFeedActionData.js +1 -0
- package/dist/esm/permissionless/curator/actions/setReservePriceFeedActionData.js +1 -0
- package/dist/esm/permissionless/curator/actions/updateLossPolicyActionData.js +4 -4
- package/dist/esm/permissionless/curator/actions/updateRateKeeperActionData.js +2 -1
- package/dist/esm/permissionless/curator/actions/upgradeCreditFacadeActionData.js +1 -0
- package/dist/esm/permissionless/curator/actions/utils/priceFeedChecks.js +5 -14
- package/dist/esm/permissionless/curator/actions/utils/systemContracts.js +29 -0
- package/dist/esm/permissionless/curator/configurator-actions/addAdminActionData.js +4 -4
- package/dist/esm/permissionless/curator/configurator-actions/configuratorActionDefinitions.js +4 -0
- package/dist/esm/permissionless/curator/configurator-actions/configuratorActionHelpers.js +31 -14
- package/dist/esm/permissionless/curator/configurator-actions/grantRoleActionData.js +30 -0
- package/dist/esm/permissionless/curator/configurator-actions/index.js +3 -1
- package/dist/esm/permissionless/curator/configurator-actions/removeAdminActionData.js +4 -4
- package/dist/esm/permissionless/curator/configurator-actions/revokeRoleActionData.js +37 -0
- package/dist/esm/permissionless/curator/executor/MarketExecutor.js +44 -8
- package/dist/esm/permissionless/curator/index.js +5 -1
- package/dist/esm/permissionless/curator/plugins/adapters/abstract-adapter/getAbstractAdapterPlugin.js +20 -2
- package/dist/esm/permissionless/curator/plugins/adapters/builtinAdapterPlugins.js +4 -0
- package/dist/esm/permissionless/curator/plugins/adapters/treehouse-router/setAssetStatusBatchActionData.js +40 -0
- package/dist/esm/permissionless/curator/plugins/adapters/treehouse-router/treehouseRouterAdapterPlugin.js +35 -0
- package/dist/esm/permissionless/curator/plugins/index.js +3 -1
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/actions/setAccessModeActionData.js +2 -1
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/actions/setAliasActionData.js +3 -1
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/actions/setChecksEnabledActionData.js +2 -1
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/aliasPlugin.js +8 -37
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/aliasedLossPolicyPlugin.js +50 -0
- package/dist/esm/permissionless/curator/plugins/loss-policies/alias/updateAliasLossPolicy.js +6 -2
- package/dist/esm/permissionless/curator/plugins/loss-policies/lossPolicyPlugins.js +6 -2
- package/dist/esm/permissionless/curator/plugins/loss-policies/midas-alias/midasAliasPlugin.js +16 -0
- package/dist/esm/permissionless/curator/session/CuratorSession.js +5 -4
- package/dist/esm/permissionless/curator/session/rwaPeripheryLookups.js +3 -9
- package/dist/esm/permissionless/curator/state/configurator/compareConfiguratorStates.js +10 -1
- package/dist/esm/permissionless/curator/state/configurator/getConfiguratorState.js +2 -1
- package/dist/esm/permissionless/curator/state/configurator/types.js +24 -1
- package/dist/esm/permissionless/curator/state/market/buildLossPolicyState.js +3 -1
- package/dist/esm/permissionless/curator/utils/objectUtils.js +5 -1
- package/dist/esm/permissionless/index.js +8 -4
- package/dist/esm/permissionless/plugins/loss-policies/constructor-params-abi.js +4 -1
- package/dist/types/onchain/market/loss-policy/constants.d.ts +5 -0
- package/dist/types/onchain/types/state-human.d.ts +1 -1
- package/dist/types/permissionless/api/configurators/types.d.ts +2 -0
- package/dist/types/permissionless/bindings/market-configurator.d.ts +15 -0
- package/dist/types/permissionless/curator/actions/defineMarketAction.d.ts +6 -0
- package/dist/types/permissionless/curator/actions/index.d.ts +2 -2
- package/dist/types/permissionless/curator/actions/marketActionDefinitions.d.ts +2 -2
- package/dist/types/permissionless/curator/actions/updateLossPolicyActionData.d.ts +1 -6
- package/dist/types/permissionless/curator/actions/utils/systemContracts.d.ts +40764 -0
- package/dist/types/permissionless/curator/configurator-actions/configuratorActionDefinitions.d.ts +3 -1
- package/dist/types/permissionless/curator/configurator-actions/configuratorActionHelpers.d.ts +16 -6
- package/dist/types/permissionless/curator/configurator-actions/grantRoleActionData.d.ts +15 -0
- package/dist/types/permissionless/curator/configurator-actions/index.d.ts +3 -1
- package/dist/types/permissionless/curator/configurator-actions/revokeRoleActionData.d.ts +15 -0
- package/dist/types/permissionless/curator/index.d.ts +9 -4
- package/dist/types/permissionless/curator/plugins/adapters/abstract-adapter/getAbstractAdapterPlugin.d.ts +1 -1
- package/dist/types/permissionless/curator/plugins/adapters/builtinAdapterPlugins.d.ts +5 -1
- package/dist/types/permissionless/curator/plugins/adapters/treehouse-router/setAssetStatusBatchActionData.d.ts +20 -0
- package/dist/types/permissionless/curator/plugins/adapters/treehouse-router/treehouseRouterAdapterPlugin.d.ts +16 -0
- package/dist/types/permissionless/curator/plugins/index.d.ts +7 -4
- package/dist/types/permissionless/curator/plugins/loss-policies/alias/aliasPlugin.d.ts +8 -16
- package/dist/types/permissionless/curator/plugins/loss-policies/alias/aliasedLossPolicyPlugin.d.ts +37 -0
- package/dist/types/permissionless/curator/plugins/loss-policies/alias/updateAliasLossPolicy.d.ts +6 -3
- package/dist/types/permissionless/curator/plugins/loss-policies/lossPolicyPlugins.d.ts +8 -2
- package/dist/types/permissionless/curator/plugins/loss-policies/midas-alias/midasAliasPlugin.d.ts +13 -0
- package/dist/types/permissionless/curator/state/configurator/compareConfiguratorStates.d.ts +2 -0
- package/dist/types/permissionless/curator/state/configurator/types.d.ts +29 -1
- package/dist/types/permissionless/curator/utils/objectUtils.d.ts +2 -0
- package/dist/types/permissionless/index.d.ts +9 -4
- package/dist/types/permissionless/plugins/loss-policies/constructor-params-abi.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ import { BaseContract } from "../../onchain/base/BaseContract.js";
|
|
|
5
5
|
import { iMarketConfiguratorV310Abi } from "../../abi/310/generated.js";
|
|
6
6
|
import { iKillSwitchProxyAbi } from "../../abi/310/iKillSwitchProxy.js";
|
|
7
7
|
import "../../onchain/index.js";
|
|
8
|
+
import "../deployment/addresses.js";
|
|
8
9
|
import { parseIrmDeployParams } from "../plugins/irm/constructor-params-abi.js";
|
|
9
10
|
import { parseLossPolicyDeployParams } from "../plugins/loss-policies/constructor-params-abi.js";
|
|
10
11
|
import { parseRateKeeperDeployParams } from "../plugins/rate-keepers/constructor-params-abi.js";
|
|
@@ -21,6 +22,19 @@ import { RateKeeperFactory } from "./factory/rate-keeper-factory.js";
|
|
|
21
22
|
import { decodeAbiParameters, encodeAbiParameters, encodeFunctionData, erc20Abi, erc4626Abi, hexToString, isAddressEqual, keccak256, parseAbi, stringToHex, toBytes } from "viem";
|
|
22
23
|
// src/permissionless/bindings/market-configurator.ts
|
|
23
24
|
const PERIPHERY_DOMAINS = ["ZAPPER", "DEGEN_NFT"];
|
|
25
|
+
/** The ACL roles `admins()` reports in fields of their own. **/
|
|
26
|
+
const ADMIN_ROLE_IDS = new Set([
|
|
27
|
+
"PAUSABLE_ADMIN",
|
|
28
|
+
"UNPAUSABLE_ADMIN",
|
|
29
|
+
"LOSS_LIQUIDATOR",
|
|
30
|
+
"EMERGENCY_LIQUIDATOR"
|
|
31
|
+
].map((role) => stringToHex(role, { size: 32 })));
|
|
32
|
+
function aclRoleKey(role) {
|
|
33
|
+
const name = hexToString(role, { size: 32 });
|
|
34
|
+
const id = role.toLowerCase();
|
|
35
|
+
return stringToHex(name).padEnd(id.length, "0") === id ? name : id;
|
|
36
|
+
}
|
|
37
|
+
const aclRolesAbi = parseAbi(["function getRoles() view returns (bytes32[])", "function getRoleHolders(bytes32) view returns (address[])"]);
|
|
24
38
|
const abi = iMarketConfiguratorV310Abi;
|
|
25
39
|
var MarketConfiguratorContract = class extends BaseContract {
|
|
26
40
|
creditFactory;
|
|
@@ -40,9 +54,13 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
40
54
|
this.lossPolicyFactory = new LossPolicyFactory();
|
|
41
55
|
this.rateKeeperFactory = new RateKeeperFactory();
|
|
42
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The v3.1 address provider every market configurator is constructed with:
|
|
59
|
+
* it sits at the same address on every chain (`Addresses.ADDRESS_PROVIDER`),
|
|
60
|
+
* so it is not read from the configurator.
|
|
61
|
+
**/
|
|
43
62
|
async getAddressProvider() {
|
|
44
|
-
|
|
45
|
-
return new AddressProviderContract(addressProvider, this.client);
|
|
63
|
+
return new AddressProviderContract("0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38", this.client);
|
|
46
64
|
}
|
|
47
65
|
async previewCreateMarket(params) {
|
|
48
66
|
return this.contract.read.previewCreateMarket([
|
|
@@ -123,7 +141,6 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
123
141
|
});
|
|
124
142
|
}
|
|
125
143
|
async createCreditSuite(marketInfo, args) {
|
|
126
|
-
const addressProvider = await this.contract.read.addressProvider();
|
|
127
144
|
const creditSuiteParams = encodeAbiParameters([{
|
|
128
145
|
type: "tuple",
|
|
129
146
|
components: [
|
|
@@ -212,7 +229,7 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
212
229
|
accountFactoryParams: {
|
|
213
230
|
postfix: stringToHex(args.params.accountFactoryType, { size: 32 }),
|
|
214
231
|
salt: args.params.accountFactorySalt ? handleSalt(args.params.accountFactorySalt) : handleSalt(keccak256(toBytes(marketInfo.name + args.params.name))),
|
|
215
|
-
constructorParams: encodeAbiParameters([{ type: "address" }], [
|
|
232
|
+
constructorParams: encodeAbiParameters([{ type: "address" }], ["0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38"])
|
|
216
233
|
}
|
|
217
234
|
}, {
|
|
218
235
|
degenNFT: args.params.whitelistPolicy,
|
|
@@ -320,6 +337,10 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
320
337
|
async treasury() {
|
|
321
338
|
return await this.contract.read.treasury();
|
|
322
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Who holds each role of the configurator's ACL: the four admin roles in
|
|
342
|
+
* their own fields, every other role in `otherRoles`, by role name.
|
|
343
|
+
**/
|
|
323
344
|
async admins() {
|
|
324
345
|
const [admin, emergencyAdmin, treasury, acl] = await Promise.all([
|
|
325
346
|
this.contract.read.admin(),
|
|
@@ -327,44 +348,43 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
327
348
|
this.contract.read.treasury(),
|
|
328
349
|
this.contract.read.acl()
|
|
329
350
|
]);
|
|
330
|
-
const
|
|
351
|
+
const holders = (role) => ({
|
|
352
|
+
address: acl,
|
|
353
|
+
abi: aclRolesAbi,
|
|
354
|
+
functionName: "getRoleHolders",
|
|
355
|
+
args: [role]
|
|
356
|
+
});
|
|
357
|
+
const roleHex = (role) => stringToHex(role, { size: 32 });
|
|
358
|
+
const [roles, pausableAdmins, unpausableAdmins, lossLiquidators, emergencyLiquidators] = await this.client.multicall({
|
|
331
359
|
allowFailure: false,
|
|
332
360
|
contracts: [
|
|
333
361
|
{
|
|
334
362
|
address: acl,
|
|
335
|
-
abi:
|
|
336
|
-
functionName: "
|
|
337
|
-
args: [stringToHex("PAUSABLE_ADMIN", { size: 32 })]
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
address: acl,
|
|
341
|
-
abi: parseAbi(["function getRoleHolders(bytes32) view returns (address[])"]),
|
|
342
|
-
functionName: "getRoleHolders",
|
|
343
|
-
args: [stringToHex("UNPAUSABLE_ADMIN", { size: 32 })]
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
address: acl,
|
|
347
|
-
abi: parseAbi(["function getRoleHolders(bytes32) view returns (address[])"]),
|
|
348
|
-
functionName: "getRoleHolders",
|
|
349
|
-
args: [stringToHex("LOSS_LIQUIDATOR", { size: 32 })]
|
|
363
|
+
abi: aclRolesAbi,
|
|
364
|
+
functionName: "getRoles"
|
|
350
365
|
},
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
args: [stringToHex("EMERGENCY_LIQUIDATOR", { size: 32 })]
|
|
356
|
-
}
|
|
366
|
+
holders(roleHex("PAUSABLE_ADMIN")),
|
|
367
|
+
holders(roleHex("UNPAUSABLE_ADMIN")),
|
|
368
|
+
holders(roleHex("LOSS_LIQUIDATOR")),
|
|
369
|
+
holders(roleHex("EMERGENCY_LIQUIDATOR"))
|
|
357
370
|
],
|
|
358
371
|
batchSize: 0
|
|
359
372
|
});
|
|
373
|
+
const otherRoles = roles.filter((role) => !ADMIN_ROLE_IDS.has(role.toLowerCase()));
|
|
374
|
+
const otherHolders = otherRoles.length === 0 ? [] : await this.client.multicall({
|
|
375
|
+
allowFailure: false,
|
|
376
|
+
contracts: otherRoles.map(holders),
|
|
377
|
+
batchSize: 0
|
|
378
|
+
});
|
|
360
379
|
return {
|
|
361
380
|
admin,
|
|
362
381
|
emergencyAdmin,
|
|
363
382
|
treasury,
|
|
364
|
-
pausableAdmins: [...
|
|
365
|
-
unpausableAdmins: [...
|
|
366
|
-
lossLiquidators: [...
|
|
367
|
-
emergencyLiquidators: [...
|
|
383
|
+
pausableAdmins: [...pausableAdmins],
|
|
384
|
+
unpausableAdmins: [...unpausableAdmins],
|
|
385
|
+
lossLiquidators: [...lossLiquidators],
|
|
386
|
+
emergencyLiquidators: [...emergencyLiquidators],
|
|
387
|
+
otherRoles: Object.fromEntries(otherRoles.map((role, i) => [aclRoleKey(role), [...otherHolders[i]]]))
|
|
368
388
|
};
|
|
369
389
|
}
|
|
370
390
|
async multipause() {
|
|
@@ -681,11 +701,12 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
681
701
|
};
|
|
682
702
|
}
|
|
683
703
|
case "revokeRole":
|
|
684
|
-
case "grantRole":
|
|
704
|
+
case "grantRole":
|
|
705
|
+
case "emergencyRevokeRole": {
|
|
685
706
|
const [role, address] = args;
|
|
686
707
|
return {
|
|
687
708
|
address,
|
|
688
|
-
role:
|
|
709
|
+
role: aclRoleKey(role)
|
|
689
710
|
};
|
|
690
711
|
}
|
|
691
712
|
case "emergencyConfigurePool":
|
|
@@ -735,6 +756,16 @@ var MarketConfiguratorContract = class extends BaseContract {
|
|
|
735
756
|
return null;
|
|
736
757
|
}
|
|
737
758
|
}
|
|
759
|
+
/**
|
|
760
|
+
* Revokes `role` from `account` at once, without the timelock that
|
|
761
|
+
* `revokeRole` goes through
|
|
762
|
+
*/
|
|
763
|
+
emergencyRevokeRole(role, account) {
|
|
764
|
+
return this.createRawTx({
|
|
765
|
+
functionName: "emergencyRevokeRole",
|
|
766
|
+
args: [stringToHex(role, { size: 32 }), account]
|
|
767
|
+
});
|
|
768
|
+
}
|
|
738
769
|
emergencyConfigurePool(pool, calldata) {
|
|
739
770
|
return this.createRawTx({
|
|
740
771
|
functionName: "emergencyConfigurePool",
|
|
@@ -18,6 +18,7 @@ const addAssetActionData = defineMarketAction({
|
|
|
18
18
|
token: addressSchema,
|
|
19
19
|
priceFeed: addressSchema
|
|
20
20
|
}),
|
|
21
|
+
resolvesForChecksOnly: true,
|
|
21
22
|
resolve: ({ ctx, params }) => resolvePriceFeed(ctx, params.token, params.priceFeed),
|
|
22
23
|
check: ({ state, params, resolved }) => {
|
|
23
24
|
if (isUnderlying(state, params.token)) return [underlyingNotAllowed()];
|
|
@@ -22,6 +22,7 @@ const addCollateralTokenActionData = defineMarketAction({
|
|
|
22
22
|
token: addressSchema,
|
|
23
23
|
liquidationThreshold: percentageSchema
|
|
24
24
|
}),
|
|
25
|
+
resolvesForChecksOnly: true,
|
|
25
26
|
resolve: async ({ ctx, params }) => {
|
|
26
27
|
const [code, balance, phantom] = await Promise.all([
|
|
27
28
|
readBytecode(ctx, params.token),
|
|
@@ -8,6 +8,7 @@ import { defineMarketAction } from "./defineMarketAction.js";
|
|
|
8
8
|
import { resource } from "./utils/actionKeys.js";
|
|
9
9
|
import { contractRejected, readChain } from "./utils/chainReads.js";
|
|
10
10
|
import { noOp } from "./utils/checkHelpers.js";
|
|
11
|
+
import { BYTECODE_REPOSITORY } from "./utils/systemContracts.js";
|
|
11
12
|
import { getContract, hexToString } from "viem";
|
|
12
13
|
import { z } from "zod/v4";
|
|
13
14
|
// src/permissionless/curator/actions/addPeripheryContractActionData.ts
|
|
@@ -23,19 +24,18 @@ const addPeripheryContractActionData = defineMarketAction({
|
|
|
23
24
|
type: z.string()
|
|
24
25
|
}),
|
|
25
26
|
resolve: async ({ ctx, params }) => {
|
|
26
|
-
const repository = (await readChain(() => ctx.marketConfigurator.contract.read.bytecodeRepository())).value;
|
|
27
27
|
const contract = getContract({
|
|
28
28
|
address: params.peripheryContract,
|
|
29
29
|
abi: iVersionAbi,
|
|
30
30
|
client: ctx.client
|
|
31
31
|
});
|
|
32
32
|
const [eligible, type, version] = await Promise.all([
|
|
33
|
-
|
|
34
|
-
address:
|
|
33
|
+
readChain(() => ctx.client.readContract({
|
|
34
|
+
address: BYTECODE_REPOSITORY,
|
|
35
35
|
abi: iBytecodeRepositoryAbi,
|
|
36
36
|
functionName: "isDeployedFromRepository",
|
|
37
37
|
args: [params.peripheryContract]
|
|
38
|
-
}))
|
|
38
|
+
})),
|
|
39
39
|
readChain(() => contract.read.contractType()),
|
|
40
40
|
readChain(() => contract.read.version())
|
|
41
41
|
]);
|
|
@@ -20,6 +20,7 @@ const allowAdapterActionData = defineMarketAction({
|
|
|
20
20
|
description: "Allow an adapter to be used by the credit manager. Adapter allows Gearbox protocol to interact with particular protocol.",
|
|
21
21
|
schema: allowAdapterSchema(adapterDeployParamsSchema),
|
|
22
22
|
paramsSchema: (registry) => allowAdapterSchema(registry.adapterDeployParamsSchema),
|
|
23
|
+
resolvesForChecksOnly: true,
|
|
23
24
|
resolve: async ({ ctx, params, registry }) => {
|
|
24
25
|
const resolveValidation = registry.adapter(params.adapter.type)?.resolveValidation;
|
|
25
26
|
const [code, validation] = await Promise.all([readBytecode(ctx, params.adapter.target), resolveValidation ? readChain(() => resolveValidation({
|
|
@@ -8,6 +8,7 @@ import { minorVersionSchema, nonEmptyStringSchema, nonZeroAddressSchema } from "
|
|
|
8
8
|
import { actionError } from "./actionDiagnostics.js";
|
|
9
9
|
import { defineMarketAction } from "./defineMarketAction.js";
|
|
10
10
|
import { priceFeedDiagnostics, resolvePriceFeed } from "./utils/priceFeedChecks.js";
|
|
11
|
+
import { ADDRESS_PROVIDER, addressProvider } from "./utils/systemContracts.js";
|
|
11
12
|
import { zeroAddress } from "viem";
|
|
12
13
|
import { z } from "zod/v4";
|
|
13
14
|
// src/permissionless/curator/actions/createMarketActionData.ts
|
|
@@ -36,9 +37,7 @@ const createMarketActionData = defineMarketAction({
|
|
|
36
37
|
name: params.name,
|
|
37
38
|
symbol: params.symbol
|
|
38
39
|
};
|
|
39
|
-
const previewPool = await mc.previewCreateMarket(market);
|
|
40
|
-
const addressProvider = await mc.getAddressProvider();
|
|
41
|
-
const gearStakingAddress = await addressProvider.getAddressOrRevert("GEAR_STAKING");
|
|
40
|
+
const [previewPool, gearStakingAddress] = await Promise.all([mc.previewCreateMarket(market), addressProvider(mc.client).getAddressOrRevert("GEAR_STAKING")]);
|
|
42
41
|
const { tx, pool } = await mc.createMarket({
|
|
43
42
|
...market,
|
|
44
43
|
interestRateModelParams: irmPlugins[params.interestRateModel.type].getDeployParams(params.interestRateModel),
|
|
@@ -49,7 +48,7 @@ const createMarketActionData = defineMarketAction({
|
|
|
49
48
|
}),
|
|
50
49
|
lossPolicyParams: lossPolicyPlugins[params.lossPolicyParams.type].getDeployParams({
|
|
51
50
|
pool: previewPool,
|
|
52
|
-
addressProvider:
|
|
51
|
+
addressProvider: ADDRESS_PROVIDER,
|
|
53
52
|
params: params.lossPolicyParams
|
|
54
53
|
}),
|
|
55
54
|
underlyingPriceFeed: params.underlyingPriceFeed
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { BytecodeRepositoryContract } from "../../bindings/bytecode-repository.js";
|
|
2
|
-
import { BYTECODE_REPOSITORY } from "../../utils/literals.js";
|
|
3
1
|
import { isSameAddress, lowerAddress } from "../utils/addressUtils.js";
|
|
4
2
|
import { bytes32IdSchema, nonZeroAddressSchema } from "../validationSchemas.js";
|
|
5
3
|
import { actionError } from "./actionDiagnostics.js";
|
|
@@ -7,6 +5,7 @@ import { peripheryContractDomains } from "./addPeripheryContractActionData.js";
|
|
|
7
5
|
import { defineMarketAction } from "./defineMarketAction.js";
|
|
8
6
|
import { resource } from "./utils/actionKeys.js";
|
|
9
7
|
import { noOp } from "./utils/checkHelpers.js";
|
|
8
|
+
import { bytecodeRepository } from "./utils/systemContracts.js";
|
|
10
9
|
import { toBytes } from "viem";
|
|
11
10
|
import { z } from "zod/v4";
|
|
12
11
|
// src/permissionless/curator/actions/deployContractActionData.ts
|
|
@@ -30,10 +29,9 @@ const deployContractActionData = defineMarketAction({
|
|
|
30
29
|
schema: deployContractParamsSchema,
|
|
31
30
|
resolve: async ({ ctx, params }) => {
|
|
32
31
|
const mc = ctx.marketConfigurator;
|
|
33
|
-
const
|
|
34
|
-
const bytecodeRepository = new BytecodeRepositoryContract(await addressProvider.getAddressOrRevert(BYTECODE_REPOSITORY), mc.client);
|
|
32
|
+
const bytecodeRepository$1 = bytecodeRepository(mc.client);
|
|
35
33
|
const deployer = await mc.contract.read.admin();
|
|
36
|
-
const computedAddress = await bytecodeRepository.computeAddress({
|
|
34
|
+
const computedAddress = await bytecodeRepository$1.computeAddress({
|
|
37
35
|
contractType: params.contractType,
|
|
38
36
|
version: params.version,
|
|
39
37
|
encodedParams: params.constructorParams,
|
|
@@ -42,7 +40,7 @@ const deployContractActionData = defineMarketAction({
|
|
|
42
40
|
});
|
|
43
41
|
const code = await mc.client.getCode({ address: params.expectedAddress });
|
|
44
42
|
return {
|
|
45
|
-
tx: bytecodeRepository.deployTx({
|
|
43
|
+
tx: bytecodeRepository$1.deployTx({
|
|
46
44
|
contractType: params.contractType,
|
|
47
45
|
version: BigInt(params.version),
|
|
48
46
|
encodedParams: params.constructorParams,
|
|
@@ -19,6 +19,7 @@ It's also used to calculate price of a token during liquidation.`,
|
|
|
19
19
|
token: addressSchema,
|
|
20
20
|
priceFeed: addressSchema
|
|
21
21
|
}),
|
|
22
|
+
resolvesForChecksOnly: true,
|
|
22
23
|
resolve: ({ ctx, params }) => resolvePriceFeed(ctx, params.token, params.priceFeed),
|
|
23
24
|
check: ({ state, params, resolved }) => {
|
|
24
25
|
const current = isUnderlying(state, params.token) ? state.underlyingPriceFeed : findAsset(state, params.token)?.mainPriceFeed;
|
|
@@ -18,6 +18,7 @@ collateral computation. The final price for such computation is a minimum betwee
|
|
|
18
18
|
token: addressSchema,
|
|
19
19
|
priceFeed: addressSchema
|
|
20
20
|
}),
|
|
21
|
+
resolvesForChecksOnly: true,
|
|
21
22
|
resolve: ({ ctx, params }) => resolvePriceFeed(ctx, params.token, params.priceFeed, "reserve"),
|
|
22
23
|
check: ({ state, params, resolved }) => {
|
|
23
24
|
const underlying = isUnderlying(state, params.token);
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { lossPolicyDeployParamsSchema, lossPolicyPlugins } from "../plugins/loss-policies/lossPolicyPlugins.js";
|
|
2
2
|
import { defineMarketAction } from "./defineMarketAction.js";
|
|
3
|
+
import { ADDRESS_PROVIDER } from "./utils/systemContracts.js";
|
|
3
4
|
// src/permissionless/curator/actions/updateLossPolicyActionData.ts
|
|
4
5
|
const updateLossPolicyActionData = defineMarketAction({
|
|
5
6
|
type: "MARKET::updateLossPolicy",
|
|
6
|
-
gas: () =>
|
|
7
|
+
gas: ({ params }) => lossPolicyPlugins[params.type].deployGas,
|
|
7
8
|
description: `Update loss policy. Loss policy is used in cases when bad debt could be accrued. It provides a second opinion
|
|
8
9
|
for particular assets.`,
|
|
9
10
|
schema: lossPolicyDeployParamsSchema,
|
|
10
|
-
resolve: async ({ ctx }) => ({ addressProvider: (await ctx.marketConfigurator.getAddressProvider()).address }),
|
|
11
11
|
apply: ({ state, params }) => ({
|
|
12
12
|
...state,
|
|
13
13
|
lossPolicy: lossPolicyPlugins[params.type].getDeployState(params)
|
|
14
14
|
}),
|
|
15
|
-
encode: ({ ctx, state, params
|
|
15
|
+
encode: ({ ctx, state, params }) => ctx.marketConfigurator.updateLossPolicy(state.address, lossPolicyPlugins[params.type].getDeployParams({
|
|
16
16
|
pool: state.address,
|
|
17
|
-
addressProvider:
|
|
17
|
+
addressProvider: ADDRESS_PROVIDER,
|
|
18
18
|
params
|
|
19
19
|
})),
|
|
20
20
|
key: () => void 0
|
|
@@ -2,6 +2,7 @@ import { rateKeeperDeployParamsSchema, rateKeeperPlugins } from "../plugins/rate
|
|
|
2
2
|
import { tumblerDiagnostics } from "../plugins/rate-keepers/tumbler/tumblerPlugin.js";
|
|
3
3
|
import { defineMarketAction } from "./defineMarketAction.js";
|
|
4
4
|
import { single } from "./utils/actionKeys.js";
|
|
5
|
+
import { addressProvider } from "./utils/systemContracts.js";
|
|
5
6
|
import { zeroHash } from "viem";
|
|
6
7
|
// src/permissionless/curator/actions/updateRateKeeperActionData.ts
|
|
7
8
|
const updateRateKeeperActionData = defineMarketAction({
|
|
@@ -12,7 +13,7 @@ const updateRateKeeperActionData = defineMarketAction({
|
|
|
12
13
|
resolve: async ({ ctx, market, params }) => {
|
|
13
14
|
if (!market) throw new Error("The market to update does not exist");
|
|
14
15
|
const mc = ctx.marketConfigurator;
|
|
15
|
-
const gearStakingAddress = await (
|
|
16
|
+
const gearStakingAddress = await addressProvider(mc.client).getAddressOrRevert("GEAR_STAKING");
|
|
16
17
|
const deployParams = rateKeeperPlugins[params.type].getDeployParams({
|
|
17
18
|
pool: market.address,
|
|
18
19
|
gearStakingAddress,
|
|
@@ -20,6 +20,7 @@ const upgradeCreditFacadeActionData = defineMarketAction({
|
|
|
20
20
|
expirable: z.boolean()
|
|
21
21
|
})
|
|
22
22
|
}),
|
|
23
|
+
resolvesForChecksOnly: true,
|
|
23
24
|
resolve: ({ ctx, params }) => resolveDegenNft(ctx, params.facade.degenNft),
|
|
24
25
|
check: ({ state, params, resolved }) => findCreditManager(state, params.creditManager) ? degenNftDiagnostics(state, params.facade.degenNft, resolved) : [creditManagerNotFound(params.creditManager)],
|
|
25
26
|
apply: ({ state, params, env }) => updateCreditManagerState({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iPriceFeedStoreAbi } from "../../../../abi/310/iPriceFeedStore.js";
|
|
2
1
|
import { iPriceFeedAbi } from "../../../../abi/iPriceFeed.js";
|
|
3
2
|
import { isSameAddress } from "../../utils/addressUtils.js";
|
|
4
3
|
import { actionError, incompleteCheck } from "../actionDiagnostics.js";
|
|
5
4
|
import { contractRejected, isUnknown, readBytecode, readChain } from "./chainReads.js";
|
|
5
|
+
import { priceFeedStore } from "./systemContracts.js";
|
|
6
6
|
import { getContract } from "viem";
|
|
7
7
|
// src/permissionless/curator/actions/utils/priceFeedChecks.ts
|
|
8
8
|
/** Source metadata shared by feed setters, asset admission and aliases. */
|
|
@@ -12,21 +12,12 @@ async function resolvePriceFeed(ctx, token, address, mode = "main") {
|
|
|
12
12
|
abi: iPriceFeedAbi,
|
|
13
13
|
client: ctx.client
|
|
14
14
|
});
|
|
15
|
-
const store =
|
|
16
|
-
const ap = await ctx.marketConfigurator.getAddressProvider();
|
|
17
|
-
return getContract({
|
|
18
|
-
address: await ap.getAddressOrRevert("PRICE_FEED_STORE"),
|
|
19
|
-
abi: iPriceFeedStoreAbi,
|
|
20
|
-
client: ctx.client
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
const storeContract = store.value;
|
|
24
|
-
const withStore = (read) => storeContract ? readChain(() => read(storeContract)) : Promise.resolve({ error: store.error });
|
|
15
|
+
const store = priceFeedStore(ctx.client);
|
|
25
16
|
const [code, allowed, zeroFeed, staleness, decimals, skip] = await Promise.all([
|
|
26
17
|
readBytecode(ctx, address),
|
|
27
|
-
|
|
28
|
-
mode === "reserve" ?
|
|
29
|
-
|
|
18
|
+
readChain(() => mode === "alias" ? store.read.isKnownPriceFeed([address]) : store.read.isAllowedPriceFeed([token, address])),
|
|
19
|
+
mode === "reserve" ? readChain(() => store.read.zeroPriceFeed()) : void 0,
|
|
20
|
+
readChain(() => store.read.getStalenessPeriod([address])),
|
|
30
21
|
readChain(() => feed.read.decimals()),
|
|
31
22
|
readChain(() => feed.read.skipPriceCheck())
|
|
32
23
|
]);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { iPriceFeedStoreAbi } from "../../../../abi/310/iPriceFeedStore.js";
|
|
2
|
+
import { AddressProviderContract } from "../../../bindings/address-provider.js";
|
|
3
|
+
import { BytecodeRepositoryContract } from "../../../bindings/bytecode-repository.js";
|
|
4
|
+
import "../../../deployment/addresses.js";
|
|
5
|
+
import { getContract } from "viem";
|
|
6
|
+
// src/permissionless/curator/actions/utils/systemContracts.ts
|
|
7
|
+
/**
|
|
8
|
+
* The Gearbox v3.1 system contracts a GIP touches. They sit at the same
|
|
9
|
+
* CREATE2 addresses on every chain (see `Addresses`), so they are bound
|
|
10
|
+
* directly instead of being looked up through the market configurator and
|
|
11
|
+
* its address provider: every lookup was a sequential round trip.
|
|
12
|
+
**/
|
|
13
|
+
const ADDRESS_PROVIDER = "0xF7f0a609BfAb9a0A98786951ef10e5FE26cC1E38";
|
|
14
|
+
const PRICE_FEED_STORE = "0x74A868AC479EE145029bB80827BB77F7B7c441cB";
|
|
15
|
+
const BYTECODE_REPOSITORY = "0x1cE2B1BE96a082b1b1539F80d5D8f82Ec06a0f9A";
|
|
16
|
+
function addressProvider(client) {
|
|
17
|
+
return new AddressProviderContract(ADDRESS_PROVIDER, client);
|
|
18
|
+
}
|
|
19
|
+
function bytecodeRepository(client) {
|
|
20
|
+
return new BytecodeRepositoryContract(BYTECODE_REPOSITORY, client);
|
|
21
|
+
}
|
|
22
|
+
function priceFeedStore(client) {
|
|
23
|
+
return getContract({
|
|
24
|
+
address: PRICE_FEED_STORE,
|
|
25
|
+
abi: iPriceFeedStoreAbi,
|
|
26
|
+
client
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export { ADDRESS_PROVIDER, BYTECODE_REPOSITORY, PRICE_FEED_STORE, addressProvider, bytecodeRepository, priceFeedStore };
|
|
@@ -2,19 +2,19 @@ import { noOp } from "../actions/utils/checkHelpers.js";
|
|
|
2
2
|
import { adminRoleSchema } from "../state/configurator/types.js";
|
|
3
3
|
import { lowerAddress } from "../utils/addressUtils.js";
|
|
4
4
|
import { addressSchema } from "../validationSchemas.js";
|
|
5
|
-
import {
|
|
5
|
+
import { byRoleAndAdmin, holdsRole, roleLabel, updateRoleHolders } from "./configuratorActionHelpers.js";
|
|
6
6
|
import { defineConfiguratorAction } from "./defineConfiguratorAction.js";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
// src/permissionless/curator/configurator-actions/addAdminActionData.ts
|
|
9
9
|
const addAdminActionData = defineConfiguratorAction({
|
|
10
10
|
type: "CONFIGURATOR::addAdmin",
|
|
11
|
-
description: `Add a
|
|
11
|
+
description: `Add a pausable admin, unpausable admin, loss liquidator or emergency liquidator for all markets. CONFIGURATOR::grantRole takes any role.`,
|
|
12
12
|
schema: z.object({
|
|
13
13
|
role: adminRoleSchema,
|
|
14
14
|
admin: addressSchema
|
|
15
15
|
}),
|
|
16
|
-
check: ({ state, params }) =>
|
|
17
|
-
apply: ({ state, params }) =>
|
|
16
|
+
check: ({ state, params }) => holdsRole(state, params.role, params.admin) ? [noOp(`${params.admin} is already one of the ${roleLabel(params.role)}`, ["params", "admin"])] : [],
|
|
17
|
+
apply: ({ state, params }) => updateRoleHolders(state, params.role, (holders) => [...holders, lowerAddress(params.admin)]),
|
|
18
18
|
encode: ({ ctx, params }) => ctx.marketConfigurator.grantRole(params.role, params.admin),
|
|
19
19
|
key: byRoleAndAdmin
|
|
20
20
|
});
|
package/dist/esm/permissionless/curator/configurator-actions/configuratorActionDefinitions.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { addAdminActionData } from "./addAdminActionData.js";
|
|
2
2
|
import { cancelConfigureActionData } from "./cancelConfigureActionData.js";
|
|
3
3
|
import { distributeActionData } from "./distributeActionData.js";
|
|
4
|
+
import { grantRoleActionData } from "./grantRoleActionData.js";
|
|
4
5
|
import { removeAdminActionData } from "./removeAdminActionData.js";
|
|
6
|
+
import { revokeRoleActionData } from "./revokeRoleActionData.js";
|
|
5
7
|
import { setDefaultSplitActionData } from "./setDefaultSplitActionData.js";
|
|
6
8
|
import { setEmergencyAdminActionData } from "./setEmergencyAdminActionData.js";
|
|
7
9
|
// src/permissionless/curator/configurator-actions/configuratorActionDefinitions.ts
|
|
@@ -9,6 +11,8 @@ import { setEmergencyAdminActionData } from "./setEmergencyAdminActionData.js";
|
|
|
9
11
|
const configuratorActionDefinitions = [
|
|
10
12
|
addAdminActionData,
|
|
11
13
|
removeAdminActionData,
|
|
14
|
+
grantRoleActionData,
|
|
15
|
+
revokeRoleActionData,
|
|
12
16
|
setEmergencyAdminActionData,
|
|
13
17
|
setDefaultSplitActionData,
|
|
14
18
|
cancelConfigureActionData,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TreasurySplitterContract } from "../../bindings/treasury-splitter.js";
|
|
2
2
|
import { isSameAddress } from "../utils/addressUtils.js";
|
|
3
|
+
import { ownEntry } from "../utils/objectUtils.js";
|
|
3
4
|
// src/permissionless/curator/configurator-actions/configuratorActionHelpers.ts
|
|
4
5
|
async function resolveTreasurySplitter(args) {
|
|
5
6
|
const { treasury } = await args.ctx.marketConfigurator.admins();
|
|
@@ -27,26 +28,42 @@ const ADMIN_ROLE_LISTS = {
|
|
|
27
28
|
label: "emergency liquidators"
|
|
28
29
|
}
|
|
29
30
|
};
|
|
31
|
+
/** The list field of `role` if it has one, `undefined` for any other role. **/
|
|
30
32
|
function adminRoleList(role) {
|
|
31
|
-
|
|
32
|
-
if (!list) throw new Error(`Unknown admin role: ${role}`);
|
|
33
|
-
return list;
|
|
33
|
+
return Object.hasOwn(ADMIN_ROLE_LISTS, role) ? ADMIN_ROLE_LISTS[role] : void 0;
|
|
34
34
|
}
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Who holds `role`: its own list for the four admin roles, `otherRoles` for
|
|
37
|
+
* any other.
|
|
38
|
+
**/
|
|
39
|
+
function roleHolders(state, role) {
|
|
40
|
+
const list = adminRoleList(role);
|
|
41
|
+
return list ? state[list.field] : ownEntry(state.otherRoles, role) ?? [];
|
|
38
42
|
}
|
|
39
|
-
/**
|
|
40
|
-
function
|
|
41
|
-
return
|
|
43
|
+
/** Whether `account` holds `role`. **/
|
|
44
|
+
function holdsRole(state, role, account) {
|
|
45
|
+
return roleHolders(state, role).some((holder) => isSameAddress(holder, account));
|
|
42
46
|
}
|
|
43
|
-
/**
|
|
44
|
-
function
|
|
45
|
-
|
|
47
|
+
/** How diagnostics name the holders of `role`. **/
|
|
48
|
+
function roleLabel(role) {
|
|
49
|
+
return adminRoleList(role)?.label ?? `${role} holders`;
|
|
50
|
+
}
|
|
51
|
+
/** Rewrites the holders of `role`: `update` maps the holders to the new ones. **/
|
|
52
|
+
function updateRoleHolders(state, role, update) {
|
|
53
|
+
const list = adminRoleList(role);
|
|
54
|
+
if (list) return {
|
|
55
|
+
...state,
|
|
56
|
+
[list.field]: update(state[list.field])
|
|
57
|
+
};
|
|
46
58
|
return {
|
|
47
59
|
...state,
|
|
48
|
-
|
|
60
|
+
otherRoles: {
|
|
61
|
+
...state.otherRoles,
|
|
62
|
+
[role]: update([...ownEntry(state.otherRoles, role) ?? []])
|
|
63
|
+
}
|
|
49
64
|
};
|
|
50
65
|
}
|
|
51
66
|
const byRoleAndAdmin = (params) => `${params.role}:${params.admin.toLowerCase()}`;
|
|
52
|
-
|
|
67
|
+
/** Merges `CONFIGURATOR::grantRole` and `revokeRole` per role and account. **/
|
|
68
|
+
const byRoleAndAccount = (params) => `${params.role}:${params.account.toLowerCase()}`;
|
|
69
|
+
export { byRoleAndAccount, byRoleAndAdmin, holdsRole, resolveTreasurySplitter, roleHolders, roleLabel, treasurySplitter, updateRoleHolders };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { actionWarning } from "../actions/actionDiagnostics.js";
|
|
2
|
+
import { noOp } from "../actions/utils/checkHelpers.js";
|
|
3
|
+
import { knownRoleLabelMap, roleNameSchema } from "../state/configurator/types.js";
|
|
4
|
+
import { lowerAddress } from "../utils/addressUtils.js";
|
|
5
|
+
import { addressSchema } from "../validationSchemas.js";
|
|
6
|
+
import { byRoleAndAccount, holdsRole, roleLabel, updateRoleHolders } from "./configuratorActionHelpers.js";
|
|
7
|
+
import { defineConfiguratorAction } from "./defineConfiguratorAction.js";
|
|
8
|
+
import { z } from "zod/v4";
|
|
9
|
+
// src/permissionless/curator/configurator-actions/grantRoleActionData.ts
|
|
10
|
+
/**
|
|
11
|
+
* Grants any role in the configurator's ACL. Covers what
|
|
12
|
+
* `CONFIGURATOR::addAdmin` does and the roles it does not take, such as
|
|
13
|
+
* `OPENING_SIGNER`.
|
|
14
|
+
**/
|
|
15
|
+
const grantRoleActionData = defineConfiguratorAction({
|
|
16
|
+
type: "CONFIGURATOR::grantRole",
|
|
17
|
+
description: `Grant a role in the market configurator's ACL to an account, for all markets.`,
|
|
18
|
+
schema: z.object({
|
|
19
|
+
role: roleNameSchema,
|
|
20
|
+
account: addressSchema
|
|
21
|
+
}),
|
|
22
|
+
check: ({ state, params }) => {
|
|
23
|
+
if (holdsRole(state, params.role, params.account)) return [noOp(`${params.account} is already one of the ${roleLabel(params.role)}`, ["params", "account"])];
|
|
24
|
+
return Object.hasOwn(knownRoleLabelMap, params.role) ? [] : [actionWarning("UNKNOWN_ROLE", `No Gearbox contract checks role ${params.role}; known roles: ${Object.keys(knownRoleLabelMap).join(", ")}`, ["params", "role"])];
|
|
25
|
+
},
|
|
26
|
+
apply: ({ state, params }) => updateRoleHolders(state, params.role, (holders) => [...holders, lowerAddress(params.account)]),
|
|
27
|
+
encode: ({ ctx, params }) => ctx.marketConfigurator.grantRole(params.role, params.account),
|
|
28
|
+
key: byRoleAndAccount
|
|
29
|
+
});
|
|
30
|
+
export { grantRoleActionData };
|
|
@@ -2,7 +2,9 @@ import { addAdminActionData } from "./addAdminActionData.js";
|
|
|
2
2
|
import { cancelConfigureActionData } from "./cancelConfigureActionData.js";
|
|
3
3
|
import { defineConfiguratorAction } from "./defineConfiguratorAction.js";
|
|
4
4
|
import { distributeActionData } from "./distributeActionData.js";
|
|
5
|
+
import { grantRoleActionData } from "./grantRoleActionData.js";
|
|
5
6
|
import { removeAdminActionData } from "./removeAdminActionData.js";
|
|
7
|
+
import { revokeRoleActionData } from "./revokeRoleActionData.js";
|
|
6
8
|
import { setDefaultSplitActionData } from "./setDefaultSplitActionData.js";
|
|
7
9
|
import { setEmergencyAdminActionData } from "./setEmergencyAdminActionData.js";
|
|
8
|
-
export { addAdminActionData, cancelConfigureActionData, defineConfiguratorAction, distributeActionData, removeAdminActionData, setDefaultSplitActionData, setEmergencyAdminActionData };
|
|
10
|
+
export { addAdminActionData, cancelConfigureActionData, defineConfiguratorAction, distributeActionData, grantRoleActionData, removeAdminActionData, revokeRoleActionData, setDefaultSplitActionData, setEmergencyAdminActionData };
|
|
@@ -2,19 +2,19 @@ import { actionError } from "../actions/actionDiagnostics.js";
|
|
|
2
2
|
import { adminRoleSchema } from "../state/configurator/types.js";
|
|
3
3
|
import { isSameAddress } from "../utils/addressUtils.js";
|
|
4
4
|
import { addressSchema } from "../validationSchemas.js";
|
|
5
|
-
import {
|
|
5
|
+
import { byRoleAndAdmin, holdsRole, roleLabel, updateRoleHolders } from "./configuratorActionHelpers.js";
|
|
6
6
|
import { defineConfiguratorAction } from "./defineConfiguratorAction.js";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
// src/permissionless/curator/configurator-actions/removeAdminActionData.ts
|
|
9
9
|
const removeAdminActionData = defineConfiguratorAction({
|
|
10
10
|
type: "CONFIGURATOR::removeAdmin",
|
|
11
|
-
description: `Remove a pausable
|
|
11
|
+
description: `Remove a pausable admin, unpausable admin, loss liquidator or emergency liquidator from all markets. CONFIGURATOR::revokeRole takes any role.`,
|
|
12
12
|
schema: z.object({
|
|
13
13
|
role: adminRoleSchema,
|
|
14
14
|
admin: addressSchema
|
|
15
15
|
}),
|
|
16
|
-
check: ({ state, params }) =>
|
|
17
|
-
apply: ({ state, params }) =>
|
|
16
|
+
check: ({ state, params }) => holdsRole(state, params.role, params.admin) ? [] : [actionError("ADMIN_NOT_FOUND", `${params.admin} is not one of the ${roleLabel(params.role)}`, ["params", "admin"])],
|
|
17
|
+
apply: ({ state, params }) => updateRoleHolders(state, params.role, (holders) => holders.filter((holder) => !isSameAddress(holder, params.admin))),
|
|
18
18
|
encode: ({ ctx, params }) => ctx.marketConfigurator.revokeRole(params.role, params.admin),
|
|
19
19
|
key: byRoleAndAdmin
|
|
20
20
|
});
|