@gearbox-protocol/sdk 18.2.0-next.12 → 18.2.0-next.13

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.
Files changed (31) hide show
  1. package/dist/cjs/abi/310/iKillSwitchProxy.js +130 -0
  2. package/dist/cjs/permissionless/bindings/bytecode-repository.js +8 -0
  3. package/dist/cjs/permissionless/bindings/governance/governor.js +1 -1
  4. package/dist/cjs/permissionless/bindings/index.js +7 -2
  5. package/dist/cjs/permissionless/bindings/kill-switch-proxy.js +188 -0
  6. package/dist/cjs/permissionless/bindings/market-configurator-factory.js +39 -1
  7. package/dist/cjs/permissionless/bindings/market-configurator.js +142 -0
  8. package/dist/cjs/permissionless/index.js +8 -2
  9. package/dist/cjs/permissionless/utils/index.js +1 -0
  10. package/dist/cjs/permissionless/utils/literals.js +2 -0
  11. package/dist/esm/abi/310/iKillSwitchProxy.js +129 -0
  12. package/dist/esm/permissionless/bindings/bytecode-repository.js +8 -0
  13. package/dist/esm/permissionless/bindings/governance/governor.js +1 -1
  14. package/dist/esm/permissionless/bindings/index.js +4 -3
  15. package/dist/esm/permissionless/bindings/kill-switch-proxy.js +184 -0
  16. package/dist/esm/permissionless/bindings/market-configurator-factory.js +37 -0
  17. package/dist/esm/permissionless/bindings/market-configurator.js +143 -1
  18. package/dist/esm/permissionless/index.js +5 -4
  19. package/dist/esm/permissionless/utils/index.js +2 -2
  20. package/dist/esm/permissionless/utils/literals.js +2 -1
  21. package/dist/types/abi/310/iKillSwitchProxy.d.ts +114 -0
  22. package/dist/types/permissionless/bindings/bytecode-repository.d.ts +10 -1
  23. package/dist/types/permissionless/bindings/index.d.ts +4 -3
  24. package/dist/types/permissionless/bindings/kill-switch-proxy.d.ts +205 -0
  25. package/dist/types/permissionless/bindings/market-configurator-factory.d.ts +30 -0
  26. package/dist/types/permissionless/bindings/market-configurator.d.ts +30 -1
  27. package/dist/types/permissionless/bindings/types.d.ts +27 -0
  28. package/dist/types/permissionless/index.d.ts +5 -4
  29. package/dist/types/permissionless/utils/index.d.ts +2 -2
  30. package/dist/types/permissionless/utils/literals.d.ts +1 -0
  31. package/package.json +1 -1
@@ -0,0 +1,129 @@
1
+ //#region src/abi/310/iKillSwitchProxy.ts
2
+ const iKillSwitchProxyAbi = [
3
+ {
4
+ type: "constructor",
5
+ inputs: [{
6
+ name: "_owner",
7
+ internalType: "address",
8
+ type: "address"
9
+ }, {
10
+ name: "_caller",
11
+ internalType: "address",
12
+ type: "address"
13
+ }],
14
+ stateMutability: "nonpayable"
15
+ },
16
+ {
17
+ type: "function",
18
+ inputs: [],
19
+ name: "caller",
20
+ outputs: [{
21
+ name: "",
22
+ internalType: "address",
23
+ type: "address"
24
+ }],
25
+ stateMutability: "view"
26
+ },
27
+ {
28
+ type: "function",
29
+ inputs: [],
30
+ name: "contractType",
31
+ outputs: [{
32
+ name: "",
33
+ internalType: "bytes32",
34
+ type: "bytes32"
35
+ }],
36
+ stateMutability: "view"
37
+ },
38
+ {
39
+ type: "function",
40
+ inputs: [],
41
+ name: "isKilled",
42
+ outputs: [{
43
+ name: "",
44
+ internalType: "bool",
45
+ type: "bool"
46
+ }],
47
+ stateMutability: "view"
48
+ },
49
+ {
50
+ type: "function",
51
+ inputs: [],
52
+ name: "kill",
53
+ outputs: [],
54
+ stateMutability: "nonpayable"
55
+ },
56
+ {
57
+ type: "function",
58
+ inputs: [],
59
+ name: "owner",
60
+ outputs: [{
61
+ name: "",
62
+ internalType: "address",
63
+ type: "address"
64
+ }],
65
+ stateMutability: "view"
66
+ },
67
+ {
68
+ type: "function",
69
+ inputs: [{
70
+ name: "target",
71
+ internalType: "address",
72
+ type: "address"
73
+ }, {
74
+ name: "data",
75
+ internalType: "bytes",
76
+ type: "bytes"
77
+ }],
78
+ name: "proxyCall",
79
+ outputs: [{
80
+ name: "result",
81
+ internalType: "bytes",
82
+ type: "bytes"
83
+ }],
84
+ stateMutability: "nonpayable"
85
+ },
86
+ {
87
+ type: "function",
88
+ inputs: [],
89
+ name: "version",
90
+ outputs: [{
91
+ name: "",
92
+ internalType: "uint256",
93
+ type: "uint256"
94
+ }],
95
+ stateMutability: "view"
96
+ },
97
+ {
98
+ type: "event",
99
+ anonymous: false,
100
+ inputs: [],
101
+ name: "Killed"
102
+ },
103
+ {
104
+ type: "error",
105
+ inputs: [{
106
+ name: "caller",
107
+ internalType: "address",
108
+ type: "address"
109
+ }],
110
+ name: "CallerIsNotOwnerException"
111
+ },
112
+ {
113
+ type: "error",
114
+ inputs: [],
115
+ name: "KilledException"
116
+ },
117
+ {
118
+ type: "error",
119
+ inputs: [],
120
+ name: "OnlyCallerException"
121
+ },
122
+ {
123
+ type: "error",
124
+ inputs: [],
125
+ name: "OwnerSameAsCallerException"
126
+ }
127
+ ];
128
+ //#endregion
129
+ export { iKillSwitchProxyAbi };
@@ -32,6 +32,14 @@ var BytecodeRepositoryContract = class BytecodeRepositoryContract extends BaseCo
32
32
  async getLatestVersion(type_) {
33
33
  return await this.contract.read.getLatestVersion([stringToHex(type_, { size: 32 })]);
34
34
  }
35
+ /**
36
+ * Returns the latest allowed patch version of the contract type within given minor version
37
+ * @throws if no bytecode of this contract type and minor version is allowed
38
+ */
39
+ async getLatestPatchVersion(type_, minorVersion) {
40
+ const version = await this.contract.read.getLatestPatchVersion([stringToHex(type_, { size: 32 }), BigInt(minorVersion)]);
41
+ return Number(version);
42
+ }
35
43
  async getAllowedBytecodeHash(type_, version) {
36
44
  return await this.contract.read.getAllowedBytecodeHash([stringToHex(type_, { size: 32 }), BigInt(version)]);
37
45
  }
@@ -5,8 +5,8 @@ import "../../../onchain/index.js";
5
5
  import { BytecodeRepositoryContract } from "../bytecode-repository.js";
6
6
  import "../../deployment/addresses.js";
7
7
  import { TreasurySplitterContract } from "../treasury-splitter.js";
8
- import { governorAbi } from "../../../abi/governance/governor.js";
9
8
  import { MarketConfiguratorContract } from "../market-configurator.js";
9
+ import { governorAbi } from "../../../abi/governance/governor.js";
10
10
  import { BatchesChainContract } from "./batches-chain.js";
11
11
  import { encodeAbiParameters, formatEther, keccak256, toBytes } from "viem";
12
12
  import { formatAbiItem } from "viem/utils";
@@ -9,11 +9,12 @@ import { RoutingManagerContract } from "./router/routing-manager.js";
9
9
  import "./router/index.js";
10
10
  import { TreasurySplitterContract } from "./treasury-splitter.js";
11
11
  import { InstanceManagerContract } from "./instance-manager.js";
12
- import { MarketConfiguratorFactoryContract } from "./market-configurator-factory.js";
13
- import { CrossChainMultisigContract } from "./cross-chain-multisig.js";
14
12
  import { AccessMode } from "./types.js";
15
13
  import { MarketConfiguratorContract } from "./market-configurator.js";
14
+ import { KILL_SWITCH_PROXY_MINOR_VERSION, KillSwitchProxyContract, KillSwitchProxyNotAllowedError, killSwitchProxySalt } from "./kill-switch-proxy.js";
15
+ import { MarketConfiguratorFactoryContract } from "./market-configurator-factory.js";
16
+ import { CrossChainMultisigContract } from "./cross-chain-multisig.js";
16
17
  import { GovernorContract } from "./governance/governor.js";
17
18
  import { TimeLockContract } from "./governance/timelock.js";
18
19
  import "./governance/index.js";
19
- export { AccessMode, AddressProviderContract, BytecodeRepositoryContract, CrossChainMultisigContract, GovernorContract, InstanceManagerContract, MarketConfiguratorContract, MarketConfiguratorFactoryContract, PriceFeedStoreContract, RoutingManagerContract, TimeLockContract, TokenCompressorContract, TreasurySplitterContract, WithdrawalCompressorContract, priceFeedSetupParams };
20
+ export { AccessMode, AddressProviderContract, BytecodeRepositoryContract, CrossChainMultisigContract, GovernorContract, InstanceManagerContract, KILL_SWITCH_PROXY_MINOR_VERSION, KillSwitchProxyContract, KillSwitchProxyNotAllowedError, MarketConfiguratorContract, MarketConfiguratorFactoryContract, PriceFeedStoreContract, RoutingManagerContract, TimeLockContract, TokenCompressorContract, TreasurySplitterContract, WithdrawalCompressorContract, killSwitchProxySalt, priceFeedSetupParams };
@@ -0,0 +1,184 @@
1
+ import { json_stringify } from "../../onchain/utils/json.js";
2
+ import { BaseContract } from "../../onchain/base/BaseContract.js";
3
+ import "../../onchain/index.js";
4
+ import { KILL_SWITCH_PROXY } from "../utils/literals.js";
5
+ import { iKillSwitchProxyAbi } from "../../abi/310/iKillSwitchProxy.js";
6
+ import { MarketConfiguratorContract } from "./market-configurator.js";
7
+ import { BaseError, ContractFunctionRevertedError, encodeAbiParameters, isAddressEqual, keccak256, toHex, zeroAddress } from "viem";
8
+ //#region src/permissionless/bindings/kill-switch-proxy.ts
9
+ const abi = iKillSwitchProxyAbi;
10
+ /**
11
+ * Minor version of kill switch proxy, the latest allowed patch of it is deployed
12
+ */
13
+ const KILL_SWITCH_PROXY_MINOR_VERSION = 310;
14
+ /**
15
+ * Salt of kill switch proxy deployed together with market configurator,
16
+ * makes each curator's market configurator get its own proxy
17
+ */
18
+ function killSwitchProxySalt(curatorName) {
19
+ return keccak256(toHex(curatorName));
20
+ }
21
+ /**
22
+ * Thrown when bytecode repository has no allowed kill switch proxy bytecode,
23
+ * so its address can't be computed and it can't be deployed
24
+ */
25
+ var KillSwitchProxyNotAllowedError = class extends BaseError {
26
+ name = "KillSwitchProxyNotAllowedError";
27
+ bytecodeRepository;
28
+ constructor(bytecodeRepository) {
29
+ super(`${KILL_SWITCH_PROXY} v310 is not allowed in bytecode repository ${bytecodeRepository}.`, { metaMessages: ["Its bytecode must be uploaded, audited and allowed before it can be deployed."] });
30
+ this.bytecodeRepository = bytecodeRepository;
31
+ }
32
+ };
33
+ /**
34
+ * Kill switch proxy forwards calls of its `caller` via `proxyCall` until `owner` kills it.
35
+ * It is used as market configurator's emergency admin, so that emergency powers
36
+ * can be revoked instantly without going through the timelock.
37
+ */
38
+ var KillSwitchProxyContract = class KillSwitchProxyContract extends BaseContract {
39
+ constructor(addr, client) {
40
+ super({ client }, {
41
+ abi,
42
+ addr,
43
+ name: "KillSwitchProxy"
44
+ });
45
+ }
46
+ /**
47
+ * Encodes `constructor(address _owner, address _caller)` params
48
+ * @throws if any address is zero or owner equals caller (constructor reverts in that case)
49
+ */
50
+ static encodeConstructorParams(args) {
51
+ const { owner, caller } = args;
52
+ if (isAddressEqual(owner, zeroAddress) || isAddressEqual(caller, zeroAddress)) throw new Error(`${KILL_SWITCH_PROXY} owner and caller must be non-zero`);
53
+ if (isAddressEqual(owner, caller)) throw new Error(`${KILL_SWITCH_PROXY} owner must differ from caller ${caller}, provide another kill switch owner`);
54
+ const [constructorAbi] = abi;
55
+ return encodeAbiParameters(constructorAbi.inputs, [owner, caller]);
56
+ }
57
+ /**
58
+ * Returns whether some patch of kill switch proxy v3.10 is allowed in bytecode repository
59
+ */
60
+ static async isAvailable(bcr) {
61
+ try {
62
+ await KillSwitchProxyContract.#getVersion(bcr);
63
+ return true;
64
+ } catch (e) {
65
+ if (e instanceof KillSwitchProxyNotAllowedError) return false;
66
+ throw e;
67
+ }
68
+ }
69
+ /**
70
+ * Computes address of kill switch proxy and prepares its deployment via bytecode repository
71
+ * @param bcr - bytecode repository
72
+ * @param args.deployer - address that will send deployment transaction, it is mixed into the salt
73
+ * @param args.owner - address that can kill the proxy
74
+ * @param args.caller - address that can call through the proxy
75
+ * @param args.salt - deployment salt
76
+ * @throws {KillSwitchProxyNotAllowedError} if kill switch proxy is not allowed in bytecode repository
77
+ */
78
+ static async prepareDeploy(bcr, args) {
79
+ const { deployer, owner, caller, salt } = args;
80
+ const encodedParams = KillSwitchProxyContract.encodeConstructorParams({
81
+ owner,
82
+ caller
83
+ });
84
+ const version = await KillSwitchProxyContract.#getVersion(bcr);
85
+ const [isAlreadyDeployed, address] = await bcr.isAlreadyDeployedAddress({
86
+ contractType: KILL_SWITCH_PROXY,
87
+ version,
88
+ encodedParams,
89
+ salt,
90
+ owner: deployer
91
+ });
92
+ return {
93
+ address,
94
+ version,
95
+ encodedParams,
96
+ salt,
97
+ isAlreadyDeployed,
98
+ isKilled: isAlreadyDeployed ? await new KillSwitchProxyContract(address, bcr.client).isKilled() : false,
99
+ tx: bcr.deployTx({
100
+ contractType: KILL_SWITCH_PROXY,
101
+ version: BigInt(version),
102
+ encodedParams,
103
+ salt
104
+ })
105
+ };
106
+ }
107
+ static async #getVersion(bcr) {
108
+ try {
109
+ return await bcr.getLatestPatchVersion(KILL_SWITCH_PROXY, 310);
110
+ } catch (e) {
111
+ const revert = e instanceof BaseError ? e.walk((err) => err instanceof ContractFunctionRevertedError) : null;
112
+ if (revert instanceof ContractFunctionRevertedError && revert.data?.errorName === "VersionNotFoundException") throw new KillSwitchProxyNotAllowedError(bcr.address);
113
+ throw e;
114
+ }
115
+ }
116
+ async isKilled() {
117
+ return await this.contract.read.isKilled();
118
+ }
119
+ async state() {
120
+ const [caller, owner, isKilled] = await this.client.multicall({
121
+ allowFailure: false,
122
+ contracts: [
123
+ {
124
+ address: this.address,
125
+ abi,
126
+ functionName: "caller"
127
+ },
128
+ {
129
+ address: this.address,
130
+ abi,
131
+ functionName: "owner"
132
+ },
133
+ {
134
+ address: this.address,
135
+ abi,
136
+ functionName: "isKilled"
137
+ }
138
+ ],
139
+ batchSize: 0
140
+ });
141
+ return {
142
+ caller,
143
+ owner,
144
+ isKilled
145
+ };
146
+ }
147
+ /**
148
+ * Wraps transaction into `proxyCall`, must be sent by proxy's caller
149
+ */
150
+ proxyCallTx(tx) {
151
+ return this.createRawTx({
152
+ functionName: "proxyCall",
153
+ args: [tx.to, tx.callData],
154
+ description: tx.description ? `KillSwitchProxy.proxyCall(${tx.description})` : void 0
155
+ });
156
+ }
157
+ /**
158
+ * Permanently disables `proxyCall`, must be sent by proxy's owner
159
+ */
160
+ killTx() {
161
+ return this.createRawTx({ functionName: "kill" });
162
+ }
163
+ parseFunctionParams(params) {
164
+ const { functionName, args } = params;
165
+ switch (functionName) {
166
+ case "proxyCall": {
167
+ const [target, data] = args;
168
+ const decoded = new MarketConfiguratorContract(target, this.client).parseFunctionData(data);
169
+ if (decoded.functionName.startsWith("Unknown function")) return {
170
+ target,
171
+ data
172
+ };
173
+ return {
174
+ target,
175
+ functionName: decoded.functionName,
176
+ data: json_stringify(decoded.args)
177
+ };
178
+ }
179
+ default: return super.parseFunctionParams(params);
180
+ }
181
+ }
182
+ };
183
+ //#endregion
184
+ export { KILL_SWITCH_PROXY_MINOR_VERSION, KillSwitchProxyContract, KillSwitchProxyNotAllowedError, killSwitchProxySalt };
@@ -1,6 +1,10 @@
1
1
  import { BaseContract } from "../../onchain/base/BaseContract.js";
2
2
  import "../../onchain/index.js";
3
+ import { KILL_SWITCH_PROXY } from "../utils/literals.js";
4
+ import { BytecodeRepositoryContract } from "./bytecode-repository.js";
5
+ import "../deployment/addresses.js";
3
6
  import { iMarketConfiguratorFactoryAbi } from "../../abi/310/iMarketConfiguratorFactory.js";
7
+ import { KillSwitchProxyContract, killSwitchProxySalt } from "./kill-switch-proxy.js";
4
8
  //#region src/permissionless/bindings/market-configurator-factory.ts
5
9
  const abi = iMarketConfiguratorFactoryAbi;
6
10
  var MarketConfiguratorFactoryContract = class extends BaseContract {
@@ -22,6 +26,39 @@ var MarketConfiguratorFactoryContract = class extends BaseContract {
22
26
  ]
23
27
  });
24
28
  }
29
+ /**
30
+ * Builds transactions that deploy market configurator with kill switch proxy as its emergency admin:
31
+ * 1. kill switch proxy deployment via bytecode repository (skipped if already deployed)
32
+ * 2. market configurator creation with proxy as emergency admin
33
+ *
34
+ * Transactions must be sent in this order by `admin`, e.g. as one Safe batch.
35
+ * When `deployGovernor` is true, proxy also becomes governor's veto admin.
36
+ *
37
+ * @param args.admin - address that sends transactions, becomes market configurator admin
38
+ * @param args.emergencyAdmin - address that executes emergency actions through the proxy
39
+ * @param args.killSwitchOwner - address that can kill the proxy, defaults to `admin`
40
+ * @throws {KillSwitchProxyNotAllowedError} if kill switch proxy is not allowed in bytecode repository,
41
+ * use {@link createMarketConfiguratorTx} to deploy market configurator without it
42
+ */
43
+ async createMarketConfiguratorWithKillSwitchTxs(args) {
44
+ const { admin, emergencyAdmin, killSwitchOwner, ...rest } = args;
45
+ const bcr = new BytecodeRepositoryContract("0x1cE2B1BE96a082b1b1539F80d5D8f82Ec06a0f9A", this.client);
46
+ const proxy = await KillSwitchProxyContract.prepareDeploy(bcr, {
47
+ deployer: admin,
48
+ owner: killSwitchOwner ?? admin,
49
+ caller: emergencyAdmin,
50
+ salt: killSwitchProxySalt(args.curatorName)
51
+ });
52
+ if (proxy.isKilled) throw new Error(`${KILL_SWITCH_PROXY} ${proxy.address} is already deployed and killed`);
53
+ return {
54
+ killSwitchProxy: proxy.address,
55
+ isKillSwitchProxyDeployed: proxy.isAlreadyDeployed,
56
+ txs: [...proxy.isAlreadyDeployed ? [] : [proxy.tx], this.createMarketConfiguratorTx({
57
+ ...rest,
58
+ emergencyAdmin: proxy.address
59
+ })]
60
+ };
61
+ }
25
62
  async getMarketConfigurators() {
26
63
  return [...await this.contract.read.getMarketConfigurators()];
27
64
  }
@@ -1,8 +1,11 @@
1
1
  import { iMarketConfiguratorV310Abi } from "../../abi/310/generated.js";
2
2
  import { json_stringify } from "../../onchain/utils/json.js";
3
+ import { createRawTx } from "../../onchain/utils/createRawTx.js";
3
4
  import { BaseContract } from "../../onchain/base/BaseContract.js";
4
5
  import "../../onchain/index.js";
6
+ import { KILL_SWITCH_PROXY } from "../utils/literals.js";
5
7
  import { AddressProviderContract } from "./address-provider.js";
8
+ import { iKillSwitchProxyAbi } from "../../abi/310/iKillSwitchProxy.js";
6
9
  import { creditFacadeParamsAbi, creditManagerParamsAbi } from "../../abi/310/configure/creditSuiteParams.js";
7
10
  import { parseIrmDeployParams } from "../plugins/irm/constructor-params-abi.js";
8
11
  import { parseLossPolicyDeployParams } from "../plugins/loss-policies/constructor-params-abi.js";
@@ -15,7 +18,7 @@ import { LossPolicyFactory } from "./factory/loss-policy-factory.js";
15
18
  import { PoolFactory } from "./factory/pool-factory.js";
16
19
  import { PriceOracleFactory } from "./factory/price-oracle-factory.js";
17
20
  import { RateKeeperFactory } from "./factory/rate-keeper-factory.js";
18
- import { decodeAbiParameters, encodeAbiParameters, encodeFunctionData, erc20Abi, erc4626Abi, hexToString, keccak256, parseAbi, stringToHex, toBytes } from "viem";
21
+ import { decodeAbiParameters, encodeAbiParameters, encodeFunctionData, erc20Abi, erc4626Abi, hexToString, isAddressEqual, keccak256, parseAbi, stringToHex, toBytes } from "viem";
19
22
  //#region src/permissionless/bindings/market-configurator.ts
20
23
  const PERIPHERY_DOMAINS = ["ZAPPER", "DEGEN_NFT"];
21
24
  const abi = iMarketConfiguratorV310Abi;
@@ -395,6 +398,83 @@ var MarketConfiguratorContract = class extends BaseContract {
395
398
  return;
396
399
  }
397
400
  }
401
+ /**
402
+ * Returns emergency admin of the market configurator.
403
+ * If it is a `KILL_SWITCH_PROXY`, emergency transactions must be sent by proxy's caller via `proxyCall`,
404
+ * otherwise directly by emergency admin itself
405
+ * @param emergencyAdmin - emergency admin address, read from the market configurator if not provided
406
+ */
407
+ async getEmergencyAdmin(emergencyAdmin) {
408
+ const address = emergencyAdmin ?? await this.contract.read.emergencyAdmin();
409
+ const [contractType, caller, owner, isKilled] = await this.client.multicall({
410
+ allowFailure: true,
411
+ contracts: [
412
+ {
413
+ address,
414
+ abi: iKillSwitchProxyAbi,
415
+ functionName: "contractType"
416
+ },
417
+ {
418
+ address,
419
+ abi: iKillSwitchProxyAbi,
420
+ functionName: "caller"
421
+ },
422
+ {
423
+ address,
424
+ abi: iKillSwitchProxyAbi,
425
+ functionName: "owner"
426
+ },
427
+ {
428
+ address,
429
+ abi: iKillSwitchProxyAbi,
430
+ functionName: "isKilled"
431
+ }
432
+ ],
433
+ batchSize: 0
434
+ });
435
+ let isKillSwitch = false;
436
+ if (contractType.status === "success") try {
437
+ isKillSwitch = hexToString(contractType.result, { size: 32 }) === KILL_SWITCH_PROXY;
438
+ } catch {}
439
+ if (!isKillSwitch) return {
440
+ type: "direct",
441
+ address,
442
+ executor: address
443
+ };
444
+ if (caller.status !== "success" || owner.status !== "success" || isKilled.status !== "success") throw new Error(`failed to read state of ${KILL_SWITCH_PROXY} emergency admin ${address}`);
445
+ return {
446
+ type: "killSwitch",
447
+ address,
448
+ caller: caller.result,
449
+ owner: owner.result,
450
+ isKilled: isKilled.result,
451
+ executor: caller.result
452
+ };
453
+ }
454
+ /**
455
+ * Routes emergency transaction to the market configurator through its emergency admin:
456
+ * returns transaction as is for direct emergency admin, or wraps it into `proxyCall` of kill switch proxy
457
+ * @param tx - emergency transaction to the market configurator, e.g. built by `emergencyConfigurePool`
458
+ * @param emergencyAdmin - result of {@link getEmergencyAdmin}
459
+ * @throws if transaction is not addressed to this market configurator or kill switch proxy is killed
460
+ */
461
+ wrapEmergencyTx(tx, emergencyAdmin) {
462
+ if (!isAddressEqual(tx.to, this.address)) throw new Error(`emergency tx target ${tx.to} is not market configurator ${this.address}`);
463
+ if (emergencyAdmin.type === "direct") return tx;
464
+ if (emergencyAdmin.isKilled) throw new Error(`${KILL_SWITCH_PROXY} ${emergencyAdmin.address} of market configurator ${this.address} is killed`);
465
+ return createRawTx(emergencyAdmin.address, {
466
+ abi: iKillSwitchProxyAbi,
467
+ functionName: "proxyCall",
468
+ args: [this.address, tx.callData]
469
+ }, tx.description ? `KillSwitchProxy.proxyCall(${tx.description})` : void 0);
470
+ }
471
+ /**
472
+ * Reads emergency admin and routes emergency transaction through it, see {@link wrapEmergencyTx}
473
+ * @param tx - emergency transaction to the market configurator, e.g. built by `emergencyConfigurePool`
474
+ */
475
+ async emergencyTx(tx) {
476
+ return this.wrapEmergencyTx(tx, await this.getEmergencyAdmin());
477
+ }
398
478
  grantRole(role, address) {
399
479
  return this.createRawTx({
400
480
  functionName: "grantRole",
@@ -608,9 +688,53 @@ var MarketConfiguratorContract = class extends BaseContract {
608
688
  role: hexToString(role, { size: 32 })
609
689
  };
610
690
  }
691
+ case "emergencyConfigurePool":
692
+ case "emergencyConfigurePriceOracle":
693
+ case "emergencyConfigureLossPolicy":
694
+ case "emergencyConfigureRateKeeper":
695
+ case "emergencyConfigureInterestRateModel": {
696
+ const [pool, calldata] = args;
697
+ const decoded = this.#decodeEmergencyConfig(functionName, calldata);
698
+ return decoded ? {
699
+ pool,
700
+ data: json_stringify(decoded)
701
+ } : {
702
+ pool,
703
+ calldata
704
+ };
705
+ }
706
+ case "emergencyConfigureCreditSuite": {
707
+ const [creditManager, calldata] = args;
708
+ const decoded = this.#decodeEmergencyConfig(functionName, calldata);
709
+ return decoded ? {
710
+ creditManager,
711
+ data: json_stringify(decoded)
712
+ } : {
713
+ creditManager,
714
+ calldata
715
+ };
716
+ }
611
717
  default: return super.parseFunctionParams(params);
612
718
  }
613
719
  }
720
+ /**
721
+ * Emergency actions share selectors with regular configuration actions only partially
722
+ * (e.g., `pause`, `forbidToken`, `setPriceFeed`), so decoding is best-effort
723
+ */
724
+ #decodeEmergencyConfig(functionName, calldata) {
725
+ const factory = {
726
+ emergencyConfigurePool: this.poolFactory,
727
+ emergencyConfigureCreditSuite: this.creditFactory,
728
+ emergencyConfigurePriceOracle: this.priceOracleFactory,
729
+ emergencyConfigureLossPolicy: this.lossPolicyFactory,
730
+ emergencyConfigureRateKeeper: this.rateKeeperFactory
731
+ }[functionName];
732
+ try {
733
+ return factory?.decodeConfig(calldata) ?? null;
734
+ } catch {
735
+ return null;
736
+ }
737
+ }
614
738
  emergencyConfigurePool(pool, calldata) {
615
739
  return this.createRawTx({
616
740
  functionName: "emergencyConfigurePool",
@@ -635,6 +759,24 @@ var MarketConfiguratorContract = class extends BaseContract {
635
759
  args: [pool, calldata]
636
760
  });
637
761
  }
762
+ /**
763
+ * Note: current interest rate model factory forbids all emergency configuration calls
764
+ */
765
+ emergencyConfigureInterestRateModel(pool, calldata) {
766
+ return this.createRawTx({
767
+ functionName: "emergencyConfigureInterestRateModel",
768
+ args: [pool, calldata]
769
+ });
770
+ }
771
+ /**
772
+ * Note: current rate keeper factory forbids all emergency configuration calls
773
+ */
774
+ emergencyConfigureRateKeeper(pool, calldata) {
775
+ return this.createRawTx({
776
+ functionName: "emergencyConfigureRateKeeper",
777
+ args: [pool, calldata]
778
+ });
779
+ }
638
780
  };
639
781
  //#endregion
640
782
  export { MarketConfiguratorContract };
@@ -2,7 +2,7 @@ import { PermissionlessAnalytics } from "./api/analytics/PermissionlessAnalytics
2
2
  import { PermissionlessChainUnreachableError, PermissionlessNotAttachedError, PriceFeedNotInStoreError, PriceFeedSaltMissingError, PriceFeedStalenessUnknownError } from "./api/errors.js";
3
3
  import { ChainsNamespace } from "./api/chains/ChainsNamespace.js";
4
4
  import { deriveEffectiveStalenessPeriod } from "./api/deploy/effective-staleness.js";
5
- import { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, TOKEN_COMPRESSOR } from "./utils/literals.js";
5
+ import { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, KILL_SWITCH_PROXY, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, TOKEN_COMPRESSOR } from "./utils/literals.js";
6
6
  import { normalizeSignature } from "./utils/signature.js";
7
7
  import { BytecodeRepositoryContract } from "./bindings/bytecode-repository.js";
8
8
  import { priceFeedSetupParams } from "./bindings/pricefeeds/index.js";
@@ -29,13 +29,14 @@ import { getUpdatablePriceFeeds } from "./utils/price-update/get-updatable-feeds
29
29
  import { InstanceOwnerTransactions } from "./api/transactions/InstanceOwnerTransactions.js";
30
30
  import { GearboxPermissionless } from "./api/GearboxPermissionless.js";
31
31
  import "./api/index.js";
32
- import { MarketConfiguratorFactoryContract } from "./bindings/market-configurator-factory.js";
33
- import { CrossChainMultisigContract } from "./bindings/cross-chain-multisig.js";
34
32
  import { PUBLIC_CREATE2_FACTORY, checkCreate2Deployment, checkCreate2DeploymentAddress, createCreate2DeployRawTx, deployUsingPublicCreate2, getCreate2AddressPublicFactory, getCreate2DeploymentAddress, handleSalt } from "./utils/create2.js";
35
33
  import { convertPercent, deepJsonParse, formatBytecodeSize, formatBytecodeVersion, shortenHash, significantTrunc } from "./utils/format.js";
36
34
  import { createCallData } from "./core/raw-tx.js";
37
35
  import { AccessMode } from "./bindings/types.js";
38
36
  import { MarketConfiguratorContract } from "./bindings/market-configurator.js";
37
+ import { KILL_SWITCH_PROXY_MINOR_VERSION, KillSwitchProxyContract, KillSwitchProxyNotAllowedError, killSwitchProxySalt } from "./bindings/kill-switch-proxy.js";
38
+ import { MarketConfiguratorFactoryContract } from "./bindings/market-configurator-factory.js";
39
+ import { CrossChainMultisigContract } from "./bindings/cross-chain-multisig.js";
39
40
  import { GovernorContract } from "./bindings/governance/governor.js";
40
41
  import { TimeLockContract } from "./bindings/governance/timelock.js";
41
42
  import "./bindings/index.js";
@@ -47,4 +48,4 @@ import { getBlockNumberByTimestamp } from "./utils/block-utils.js";
47
48
  import { convertQueueBatchToExecuteTx } from "./utils/governance/timelock-txs.js";
48
49
  import { getPriceUpdateTx } from "./utils/price-update/get-price-update-tx.js";
49
50
  import "./utils/index.js";
50
- export { AccessMode, AddressProviderContract, Addresses, ArchiveTransport, BYTECODE_REPOSITORY, BytecodeRepositoryContract, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, ChainsNamespace, CrossChainMultisigContract, DEFAULT_DEPLOY_SALT, DEFAULT_SCENARIOS, GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, GearboxPermissionless, GovernorContract, INSTANCE_MANAGER, InstanceManagerContract, InstanceOwnerTransactions, MAINNET_CCM_CONSTRUCTOR_PARAMS, MAINNET_DEPLOYMENT_BLOCK, MAINNET_DEPLOYMENT_CCM_SALT, MAINNET_DEPLOYMENT_IM_SALT, MARKET_CONFIGURATOR_FACTORY, MarketConfiguratorContract, MarketConfiguratorFactoryContract, PRICE_FEED_STORE, PUBLIC_CREATE2_FACTORY, PermissionlessAnalytics, PermissionlessChainUnreachableError, PermissionlessDeploy, PermissionlessNotAttachedError, PermissionlessOracles, PriceFeedNotInStoreError, PriceFeedSaltMissingError, PriceFeedStalenessUnknownError, PriceFeedStoreContract, RATE_FEED_TYPE, REVERT_SCORE, RoutingManagerContract, SCORE_MULTIPLIER, TOKEN_COMPRESSOR, TimeLockContract, TokenCompressorContract, TreasurySplitterContract, UNBOUNDED_DOWN, UNBOUNDED_UP, WithdrawalCompressorContract, calculateChecksum, checkCreate2Deployment, checkCreate2DeploymentAddress, chunkedLogsTransport, classifySources, convertPercent, convertQueueBatchToExecuteTx, convertRawTxToSafeMultisigTx, createCallData, createCreate2DeployRawTx, deepJsonParse, deployUsingPublicCreate2, deriveEffectiveStalenessPeriod, encodeFunctionParams, factorOf, finalPrice, formatBytecodeSize, formatBytecodeVersion, getBlockNumberByTimestamp, getCreate2AddressPublicFactory, getCreate2DeploymentAddress, getFeedDecimals, getLatestPrices, getPriceUpdateTx, getPrices, getSafeBatch, getSafeBatches, getUpdatablePriceFeeds, groupOverride, handleSalt, normalizeSignature, perturb, priceFeedSalt, priceFeedSetupParams, rateStub, readForest, readRateTargets, readUnder, roundDataStub, runAssetScores, runStressTest, scoreGroup, scoreOfFactor, shortenHash, significantTrunc, slotHarm, sourcesByFeed, verdictOf, worstOf };
51
+ export { AccessMode, AddressProviderContract, Addresses, ArchiveTransport, BYTECODE_REPOSITORY, BytecodeRepositoryContract, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, ChainsNamespace, CrossChainMultisigContract, DEFAULT_DEPLOY_SALT, DEFAULT_SCENARIOS, GET_PRICES_CHUNK_SIZE, GET_PRICES_GAS_LIMIT_BY_CHAIN_ID, GearboxPermissionless, GovernorContract, INSTANCE_MANAGER, InstanceManagerContract, InstanceOwnerTransactions, KILL_SWITCH_PROXY, KILL_SWITCH_PROXY_MINOR_VERSION, KillSwitchProxyContract, KillSwitchProxyNotAllowedError, MAINNET_CCM_CONSTRUCTOR_PARAMS, MAINNET_DEPLOYMENT_BLOCK, MAINNET_DEPLOYMENT_CCM_SALT, MAINNET_DEPLOYMENT_IM_SALT, MARKET_CONFIGURATOR_FACTORY, MarketConfiguratorContract, MarketConfiguratorFactoryContract, PRICE_FEED_STORE, PUBLIC_CREATE2_FACTORY, PermissionlessAnalytics, PermissionlessChainUnreachableError, PermissionlessDeploy, PermissionlessNotAttachedError, PermissionlessOracles, PriceFeedNotInStoreError, PriceFeedSaltMissingError, PriceFeedStalenessUnknownError, PriceFeedStoreContract, RATE_FEED_TYPE, REVERT_SCORE, RoutingManagerContract, SCORE_MULTIPLIER, TOKEN_COMPRESSOR, TimeLockContract, TokenCompressorContract, TreasurySplitterContract, UNBOUNDED_DOWN, UNBOUNDED_UP, WithdrawalCompressorContract, calculateChecksum, checkCreate2Deployment, checkCreate2DeploymentAddress, chunkedLogsTransport, classifySources, convertPercent, convertQueueBatchToExecuteTx, convertRawTxToSafeMultisigTx, createCallData, createCreate2DeployRawTx, deepJsonParse, deployUsingPublicCreate2, deriveEffectiveStalenessPeriod, encodeFunctionParams, factorOf, finalPrice, formatBytecodeSize, formatBytecodeVersion, getBlockNumberByTimestamp, getCreate2AddressPublicFactory, getCreate2DeploymentAddress, getFeedDecimals, getLatestPrices, getPriceUpdateTx, getPrices, getSafeBatch, getSafeBatches, getUpdatablePriceFeeds, groupOverride, handleSalt, killSwitchProxySalt, normalizeSignature, perturb, priceFeedSalt, priceFeedSetupParams, rateStub, readForest, readRateTargets, readUnder, roundDataStub, runAssetScores, runStressTest, scoreGroup, scoreOfFactor, shortenHash, significantTrunc, slotHarm, sourcesByFeed, verdictOf, worstOf };
@@ -1,4 +1,4 @@
1
- import { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, TOKEN_COMPRESSOR } from "./literals.js";
1
+ import { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, KILL_SWITCH_PROXY, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, TOKEN_COMPRESSOR } from "./literals.js";
2
2
  import { normalizeSignature } from "./signature.js";
3
3
  import { encodeFunctionParams } from "./abi-encoder.js";
4
4
  import { getFeedDecimals, getLatestPrices, getPrices } from "./price-update/get-prices.js";
@@ -11,4 +11,4 @@ import { convertQueueBatchToExecuteTx } from "./governance/timelock-txs.js";
11
11
  import "./governance/index.js";
12
12
  import { getPriceUpdateTx } from "./price-update/get-price-update-tx.js";
13
13
  import "./price-update/index.js";
14
- export { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, PUBLIC_CREATE2_FACTORY, TOKEN_COMPRESSOR, calculateChecksum, checkCreate2Deployment, checkCreate2DeploymentAddress, convertPercent, convertQueueBatchToExecuteTx, convertRawTxToSafeMultisigTx, createCreate2DeployRawTx, deepJsonParse, deployUsingPublicCreate2, encodeFunctionParams, formatBytecodeSize, formatBytecodeVersion, getBlockNumberByTimestamp, getCreate2AddressPublicFactory, getCreate2DeploymentAddress, getFeedDecimals, getLatestPrices, getPriceUpdateTx, getPrices, getSafeBatch, getSafeBatches, getUpdatablePriceFeeds, handleSalt, normalizeSignature, shortenHash, significantTrunc };
14
+ export { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, KILL_SWITCH_PROXY, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, PUBLIC_CREATE2_FACTORY, TOKEN_COMPRESSOR, calculateChecksum, checkCreate2Deployment, checkCreate2DeploymentAddress, convertPercent, convertQueueBatchToExecuteTx, convertRawTxToSafeMultisigTx, createCreate2DeployRawTx, deepJsonParse, deployUsingPublicCreate2, encodeFunctionParams, formatBytecodeSize, formatBytecodeVersion, getBlockNumberByTimestamp, getCreate2AddressPublicFactory, getCreate2DeploymentAddress, getFeedDecimals, getLatestPrices, getPriceUpdateTx, getPrices, getSafeBatch, getSafeBatches, getUpdatablePriceFeeds, handleSalt, normalizeSignature, shortenHash, significantTrunc };
@@ -6,5 +6,6 @@ const TOKEN_COMPRESSOR = "GLOBAL::TOKEN_COMPRESSOR";
6
6
  const CROSS_CHAIN_MULTISIG = "CROSS_CHAIN_MULTISIG";
7
7
  const PRICE_FEED_STORE = "PRICE_FEED_STORE";
8
8
  const MARKET_CONFIGURATOR_FACTORY = "MARKET_CONFIGURATOR_FACTORY";
9
+ const KILL_SWITCH_PROXY = "KILL_SWITCH_PROXY";
9
10
  //#endregion
10
- export { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, TOKEN_COMPRESSOR };
11
+ export { BYTECODE_REPOSITORY, CROSS_CHAIN_GOVERNANCE, CROSS_CHAIN_MULTISIG, INSTANCE_MANAGER, KILL_SWITCH_PROXY, MARKET_CONFIGURATOR_FACTORY, PRICE_FEED_STORE, TOKEN_COMPRESSOR };