@gearbox-protocol/sdk 16.3.1 → 16.3.2

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.
@@ -10,14 +10,24 @@ const iMidasPausableVaultAbi = (0, viem.parseAbi)([
10
10
  "function paused() external view returns (bool)",
11
11
  "function pause() external",
12
12
  "function unpause() external",
13
+ "function fnPaused(bytes4 fn) external view returns (bool)",
14
+ "function pauseFn(bytes4 fn) external",
15
+ "function unpauseFn(bytes4 fn) external",
13
16
  "function pauseAdminRole() external view returns (bytes32)",
14
17
  "function accessControl() external view returns (address)"
15
18
  ]);
16
19
  const iMidasAccessControlAbi = (0, viem.parseAbi)(["function hasRole(bytes32 role, address account) external view returns (bool)", "function grantRole(bytes32 role, address account) external"]);
17
20
  /**
18
- * Unpauses a globally paused Midas issuance vault on an anvil fork, so that
19
- * `depositInstant` stops reverting with `Pausable: paused`, and returns a
20
- * callback that restores the original pause state.
21
+ * Selector for `DepositVault.depositInstant(address,uint256,uint256,bytes32)`,
22
+ * the 4-arg mint Gearbox adapters encode. Distinct from the custom-recipient
23
+ * overload.
24
+ */
25
+ const DEPOSIT_INSTANT_SELECTOR = (0, viem.toFunctionSelector)("depositInstant(address,uint256,uint256,bytes32)");
26
+ /**
27
+ * Unpauses a Midas issuance vault on an anvil fork so that `depositInstant`
28
+ * stops reverting with `Pausable: paused` (global) or `Pausable: fn paused`
29
+ * (per-selector), and returns a callback that restores the original pause
30
+ * state of each layer that was cleared.
21
31
  *
22
32
  * Impersonates `admin` and grants it `pauseAdminRole()` when missing, same as
23
33
  * `greenlistMidasGateway` does with the greenlist roles. The grant is not
@@ -25,11 +35,20 @@ const iMidasAccessControlAbi = (0, viem.parseAbi)(["function hasRole(bytes32 rol
25
35
  */
26
36
  async function unpauseMidasIssuanceVault(props) {
27
37
  const { anvil, vault, admin, logger } = props;
28
- if (!await anvil.readContract({
29
- address: vault,
30
- abi: iMidasPausableVaultAbi,
31
- functionName: "paused"
32
- })) {
38
+ const [paused, depositInstantPaused] = await anvil.multicall({
39
+ allowFailure: false,
40
+ contracts: [{
41
+ address: vault,
42
+ abi: iMidasPausableVaultAbi,
43
+ functionName: "paused"
44
+ }, {
45
+ address: vault,
46
+ abi: iMidasPausableVaultAbi,
47
+ functionName: "fnPaused",
48
+ args: [DEPOSIT_INSTANT_SELECTOR]
49
+ }]
50
+ });
51
+ if (!paused && !depositInstantPaused) {
33
52
  logger?.debug(`midas: issuance vault ${vault} is not paused`);
34
53
  return async () => {};
35
54
  }
@@ -51,7 +70,7 @@ async function unpauseMidasIssuanceVault(props) {
51
70
  functionName: "hasRole",
52
71
  args: [pauseAdminRole, admin]
53
72
  });
54
- logger?.debug(`midas: unpausing issuance vault ${vault} as ${admin}, access control ${accessControl}, pause admin role ${pauseAdminRole}`);
73
+ logger?.debug(`midas: unpausing issuance vault ${vault} as ${admin}, access control ${accessControl}, pause admin role ${pauseAdminRole}` + (paused ? ", global" : "") + (depositInstantPaused ? ", depositInstant" : ""));
55
74
  await anvil.impersonateAccount({ address: admin });
56
75
  try {
57
76
  await anvil.setBalance({
@@ -69,13 +88,21 @@ async function unpauseMidasIssuanceVault(props) {
69
88
  });
70
89
  logger?.debug(`midas: granted pause admin role to ${admin}`);
71
90
  }
72
- await require_dev_kycUtils.writeAndWait(anvil, {
91
+ if (paused) await require_dev_kycUtils.writeAndWait(anvil, {
73
92
  account: admin,
74
93
  chain: anvil.chain,
75
94
  address: vault,
76
95
  abi: iMidasPausableVaultAbi,
77
96
  functionName: "unpause"
78
97
  });
98
+ if (depositInstantPaused) await require_dev_kycUtils.writeAndWait(anvil, {
99
+ account: admin,
100
+ chain: anvil.chain,
101
+ address: vault,
102
+ abi: iMidasPausableVaultAbi,
103
+ functionName: "unpauseFn",
104
+ args: [DEPOSIT_INSTANT_SELECTOR]
105
+ });
79
106
  } finally {
80
107
  await anvil.stopImpersonatingAccount({ address: admin });
81
108
  }
@@ -90,13 +117,21 @@ async function unpauseMidasIssuanceVault(props) {
90
117
  address: admin,
91
118
  value: (0, viem.parseEther)("100")
92
119
  });
93
- await require_dev_kycUtils.writeAndWait(anvil, {
120
+ if (paused) await require_dev_kycUtils.writeAndWait(anvil, {
94
121
  account: admin,
95
122
  chain: anvil.chain,
96
123
  address: vault,
97
124
  abi: iMidasPausableVaultAbi,
98
125
  functionName: "pause"
99
126
  });
127
+ if (depositInstantPaused) await require_dev_kycUtils.writeAndWait(anvil, {
128
+ account: admin,
129
+ chain: anvil.chain,
130
+ address: vault,
131
+ abi: iMidasPausableVaultAbi,
132
+ functionName: "pauseFn",
133
+ args: [DEPOSIT_INSTANT_SELECTOR]
134
+ });
100
135
  } catch (e) {
101
136
  logger?.warn(`midas: failed to pause issuance vault ${vault} back: ${e}`);
102
137
  } finally {
@@ -1,5 +1,5 @@
1
1
  import { writeAndWait } from "./kycUtils.js";
2
- import { parseAbi, parseEther } from "viem";
2
+ import { parseAbi, parseEther, toFunctionSelector } from "viem";
3
3
  //#region src/dev/midasUtils.ts
4
4
  /**
5
5
  * Midas vaults inherit their own `Pausable`, whose global pause is guarded by
@@ -9,14 +9,24 @@ const iMidasPausableVaultAbi = parseAbi([
9
9
  "function paused() external view returns (bool)",
10
10
  "function pause() external",
11
11
  "function unpause() external",
12
+ "function fnPaused(bytes4 fn) external view returns (bool)",
13
+ "function pauseFn(bytes4 fn) external",
14
+ "function unpauseFn(bytes4 fn) external",
12
15
  "function pauseAdminRole() external view returns (bytes32)",
13
16
  "function accessControl() external view returns (address)"
14
17
  ]);
15
18
  const iMidasAccessControlAbi = parseAbi(["function hasRole(bytes32 role, address account) external view returns (bool)", "function grantRole(bytes32 role, address account) external"]);
16
19
  /**
17
- * Unpauses a globally paused Midas issuance vault on an anvil fork, so that
18
- * `depositInstant` stops reverting with `Pausable: paused`, and returns a
19
- * callback that restores the original pause state.
20
+ * Selector for `DepositVault.depositInstant(address,uint256,uint256,bytes32)`,
21
+ * the 4-arg mint Gearbox adapters encode. Distinct from the custom-recipient
22
+ * overload.
23
+ */
24
+ const DEPOSIT_INSTANT_SELECTOR = toFunctionSelector("depositInstant(address,uint256,uint256,bytes32)");
25
+ /**
26
+ * Unpauses a Midas issuance vault on an anvil fork so that `depositInstant`
27
+ * stops reverting with `Pausable: paused` (global) or `Pausable: fn paused`
28
+ * (per-selector), and returns a callback that restores the original pause
29
+ * state of each layer that was cleared.
20
30
  *
21
31
  * Impersonates `admin` and grants it `pauseAdminRole()` when missing, same as
22
32
  * `greenlistMidasGateway` does with the greenlist roles. The grant is not
@@ -24,11 +34,20 @@ const iMidasAccessControlAbi = parseAbi(["function hasRole(bytes32 role, address
24
34
  */
25
35
  async function unpauseMidasIssuanceVault(props) {
26
36
  const { anvil, vault, admin, logger } = props;
27
- if (!await anvil.readContract({
28
- address: vault,
29
- abi: iMidasPausableVaultAbi,
30
- functionName: "paused"
31
- })) {
37
+ const [paused, depositInstantPaused] = await anvil.multicall({
38
+ allowFailure: false,
39
+ contracts: [{
40
+ address: vault,
41
+ abi: iMidasPausableVaultAbi,
42
+ functionName: "paused"
43
+ }, {
44
+ address: vault,
45
+ abi: iMidasPausableVaultAbi,
46
+ functionName: "fnPaused",
47
+ args: [DEPOSIT_INSTANT_SELECTOR]
48
+ }]
49
+ });
50
+ if (!paused && !depositInstantPaused) {
32
51
  logger?.debug(`midas: issuance vault ${vault} is not paused`);
33
52
  return async () => {};
34
53
  }
@@ -50,7 +69,7 @@ async function unpauseMidasIssuanceVault(props) {
50
69
  functionName: "hasRole",
51
70
  args: [pauseAdminRole, admin]
52
71
  });
53
- logger?.debug(`midas: unpausing issuance vault ${vault} as ${admin}, access control ${accessControl}, pause admin role ${pauseAdminRole}`);
72
+ logger?.debug(`midas: unpausing issuance vault ${vault} as ${admin}, access control ${accessControl}, pause admin role ${pauseAdminRole}` + (paused ? ", global" : "") + (depositInstantPaused ? ", depositInstant" : ""));
54
73
  await anvil.impersonateAccount({ address: admin });
55
74
  try {
56
75
  await anvil.setBalance({
@@ -68,13 +87,21 @@ async function unpauseMidasIssuanceVault(props) {
68
87
  });
69
88
  logger?.debug(`midas: granted pause admin role to ${admin}`);
70
89
  }
71
- await writeAndWait(anvil, {
90
+ if (paused) await writeAndWait(anvil, {
72
91
  account: admin,
73
92
  chain: anvil.chain,
74
93
  address: vault,
75
94
  abi: iMidasPausableVaultAbi,
76
95
  functionName: "unpause"
77
96
  });
97
+ if (depositInstantPaused) await writeAndWait(anvil, {
98
+ account: admin,
99
+ chain: anvil.chain,
100
+ address: vault,
101
+ abi: iMidasPausableVaultAbi,
102
+ functionName: "unpauseFn",
103
+ args: [DEPOSIT_INSTANT_SELECTOR]
104
+ });
78
105
  } finally {
79
106
  await anvil.stopImpersonatingAccount({ address: admin });
80
107
  }
@@ -89,13 +116,21 @@ async function unpauseMidasIssuanceVault(props) {
89
116
  address: admin,
90
117
  value: parseEther("100")
91
118
  });
92
- await writeAndWait(anvil, {
119
+ if (paused) await writeAndWait(anvil, {
93
120
  account: admin,
94
121
  chain: anvil.chain,
95
122
  address: vault,
96
123
  abi: iMidasPausableVaultAbi,
97
124
  functionName: "pause"
98
125
  });
126
+ if (depositInstantPaused) await writeAndWait(anvil, {
127
+ account: admin,
128
+ chain: anvil.chain,
129
+ address: vault,
130
+ abi: iMidasPausableVaultAbi,
131
+ functionName: "pauseFn",
132
+ args: [DEPOSIT_INSTANT_SELECTOR]
133
+ });
99
134
  } catch (e) {
100
135
  logger?.warn(`midas: failed to pause issuance vault ${vault} back: ${e}`);
101
136
  } finally {
@@ -22,9 +22,10 @@ interface UnpauseMidasIssuanceVaultProps {
22
22
  */
23
23
  type RestoreMidasIssuanceVaultPause = () => Promise<void>;
24
24
  /**
25
- * Unpauses a globally paused Midas issuance vault on an anvil fork, so that
26
- * `depositInstant` stops reverting with `Pausable: paused`, and returns a
27
- * callback that restores the original pause state.
25
+ * Unpauses a Midas issuance vault on an anvil fork so that `depositInstant`
26
+ * stops reverting with `Pausable: paused` (global) or `Pausable: fn paused`
27
+ * (per-selector), and returns a callback that restores the original pause
28
+ * state of each layer that was cleared.
28
29
  *
29
30
  * Impersonates `admin` and grants it `pauseAdminRole()` when missing, same as
30
31
  * `greenlistMidasGateway` does with the greenlist roles. The grant is not
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "16.3.1",
3
+ "version": "16.3.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "repository": {