@gearbox-protocol/periphery-v3 1.3.12 → 1.3.14
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.
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
+
pragma solidity ^0.8.10;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
|
|
5
|
+
import {
|
|
6
|
+
IAddressProviderV3,
|
|
7
|
+
AP_TREASURY,
|
|
8
|
+
NO_VERSION_CONTROL
|
|
9
|
+
} from "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
|
|
10
|
+
import {IDegenNFTV2} from "@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFTV2.sol";
|
|
11
|
+
import {IDegenDistributorV3} from "../interfaces/IDegenDistributorV3.sol";
|
|
12
|
+
|
|
13
|
+
contract DegenDistributorV3 is IDegenDistributorV3 {
|
|
14
|
+
uint256 version = 3_00;
|
|
15
|
+
|
|
16
|
+
/// @dev Emits each time when call not by treasury
|
|
17
|
+
error TreasuryOnlyException();
|
|
18
|
+
|
|
19
|
+
/// @dev Returns the token distributed by the contract
|
|
20
|
+
address public immutable override degenNFT;
|
|
21
|
+
|
|
22
|
+
/// @dev DAO Treasury address
|
|
23
|
+
address public immutable treasury;
|
|
24
|
+
|
|
25
|
+
/// @dev The current merkle root of total claimable balances
|
|
26
|
+
bytes32 public override merkleRoot;
|
|
27
|
+
|
|
28
|
+
/// @dev The mapping that stores amounts already claimed by users
|
|
29
|
+
mapping(address => uint256) public claimed;
|
|
30
|
+
|
|
31
|
+
modifier treasuryOnly() {
|
|
32
|
+
if (msg.sender != treasury) revert TreasuryOnlyException();
|
|
33
|
+
_;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
constructor(address addressProvider, address _degenNFT) {
|
|
37
|
+
degenNFT = _degenNFT;
|
|
38
|
+
treasury = IAddressProviderV3(addressProvider).getAddressOrRevert(AP_TREASURY, NO_VERSION_CONTROL);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updateMerkleRoot(bytes32 newRoot) external treasuryOnly {
|
|
42
|
+
bytes32 oldRoot = merkleRoot;
|
|
43
|
+
merkleRoot = newRoot;
|
|
44
|
+
emit RootUpdated(oldRoot, newRoot);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function claim(uint256 index, address account, uint256 totalAmount, bytes32[] calldata merkleProof)
|
|
48
|
+
external
|
|
49
|
+
override
|
|
50
|
+
{
|
|
51
|
+
require(claimed[account] < totalAmount, "MerkleDistributor: Nothing to claim");
|
|
52
|
+
|
|
53
|
+
bytes32 node = keccak256(abi.encodePacked(index, account, totalAmount));
|
|
54
|
+
require(MerkleProof.verify(merkleProof, merkleRoot, node), "MerkleDistributor: Invalid proof.");
|
|
55
|
+
|
|
56
|
+
uint256 claimedAmount = totalAmount - claimed[account];
|
|
57
|
+
claimed[account] += claimedAmount;
|
|
58
|
+
IDegenNFTV2(degenNFT).mint(account, claimedAmount);
|
|
59
|
+
|
|
60
|
+
emit Claimed(account, claimedAmount);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
+
// (c) Gearbox Holdings, 2024
|
|
4
|
+
pragma solidity ^0.8.17;
|
|
5
|
+
|
|
6
|
+
import {ACLNonReentrantTrait} from "@gearbox-protocol/core-v3/contracts/traits/ACLNonReentrantTrait.sol";
|
|
7
|
+
import {
|
|
8
|
+
IAddressProviderV3,
|
|
9
|
+
AP_CONTRACTS_REGISTER,
|
|
10
|
+
NO_VERSION_CONTROL
|
|
11
|
+
} from "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
|
|
12
|
+
import {ContractsRegister} from "@gearbox-protocol/core-v2/contracts/core/ContractsRegister.sol";
|
|
13
|
+
import {
|
|
14
|
+
IAddressProviderV3,
|
|
15
|
+
AP_CONTRACTS_REGISTER
|
|
16
|
+
} from "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
|
|
17
|
+
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
18
|
+
|
|
19
|
+
contract PauseMulticall is ACLNonReentrantTrait {
|
|
20
|
+
ContractsRegister public immutable cr;
|
|
21
|
+
|
|
22
|
+
constructor(address _addressProvider) ACLNonReentrantTrait(_addressProvider) {
|
|
23
|
+
cr = ContractsRegister(
|
|
24
|
+
IAddressProviderV3(_addressProvider).getAddressOrRevert(AP_CONTRACTS_REGISTER, NO_VERSION_CONTROL)
|
|
25
|
+
); // F: [PM-01]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function pauseAllCreditManagers()
|
|
29
|
+
external
|
|
30
|
+
pausableAdminsOnly // F:[PM-05]
|
|
31
|
+
{
|
|
32
|
+
_pauseAllCreditManagers();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function pauseAllPools()
|
|
36
|
+
external
|
|
37
|
+
pausableAdminsOnly // F:[PM-05]
|
|
38
|
+
{
|
|
39
|
+
_pauseAllPools(); // F: [PM-03]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function pauseAllContracts()
|
|
43
|
+
external
|
|
44
|
+
pausableAdminsOnly // F:[PM-05]
|
|
45
|
+
{
|
|
46
|
+
_pauseAllPools();
|
|
47
|
+
_pauseAllCreditManagers();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _pauseAllPools() internal {
|
|
51
|
+
_pauseBatchOfContracts(cr.getPools()); // F: [PM-03]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _pauseAllCreditManagers() internal {
|
|
55
|
+
address[] memory allCreditManagers = cr.getCreditManagers();
|
|
56
|
+
|
|
57
|
+
unchecked {
|
|
58
|
+
for (uint256 i = 0; i < allCreditManagers.length; ++i) {
|
|
59
|
+
uint256 version = ICreditManagerV3(allCreditManagers[i]).version();
|
|
60
|
+
if (version >= 3_00) {
|
|
61
|
+
allCreditManagers[i] = ICreditManagerV3(allCreditManagers[i]).creditFacade();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_pauseBatchOfContracts(allCreditManagers); // F: [PM-04] // F: [PM-02]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _pauseBatchOfContracts(address[] memory contractsToPause) internal {
|
|
70
|
+
uint256 len = contractsToPause.length;
|
|
71
|
+
unchecked {
|
|
72
|
+
for (uint256 i = 0; i < len; ++i) {
|
|
73
|
+
// try-catch block to ignore some contracts which are already paused
|
|
74
|
+
try ACLNonReentrantTrait(contractsToPause[i]).pause() {} catch {}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
+
pragma solidity ^0.8.10;
|
|
3
|
+
|
|
4
|
+
interface IDegenDistributorEventsV3 {
|
|
5
|
+
/// @dev Emits when a user claims tokens
|
|
6
|
+
event Claimed(address indexed account, uint256 amount);
|
|
7
|
+
|
|
8
|
+
/// @dev Emits when the owner replaces the merkle root
|
|
9
|
+
event RootUpdated(bytes32 oldRoot, bytes32 indexed newRoot);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface IDegenDistributorV3 is IDegenDistributorEventsV3 {
|
|
13
|
+
// Returns the address of the token distributed by this contract.
|
|
14
|
+
function degenNFT() external view returns (address);
|
|
15
|
+
|
|
16
|
+
// Returns the merkle root of the merkle tree containing account balances available to claim.
|
|
17
|
+
function merkleRoot() external view returns (bytes32);
|
|
18
|
+
|
|
19
|
+
/// @dev Returns the total amount of token claimed by the user
|
|
20
|
+
function claimed(address user) external view returns (uint256);
|
|
21
|
+
|
|
22
|
+
// Claim the given amount of the token to the given address. Reverts if the inputs are invalid.
|
|
23
|
+
/// @dev Claims the remaining unclaimed amount of the token for the account. Reverts if the inputs are not a leaf in the tree
|
|
24
|
+
/// or the total claimed amount for the account is more than the leaf amount.
|
|
25
|
+
function claim(uint256 index, address account, uint256 totalAmount, bytes32[] calldata merkleProof) external;
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: UNLICENSED
|
|
2
|
+
// Gearbox Protocol. Generalized leverage for DeFi protocols
|
|
3
|
+
// (c) Gearbox Holdings, 2024
|
|
4
|
+
pragma solidity ^0.8.17;
|
|
5
|
+
|
|
6
|
+
import {PauseMulticall} from "../emergency/PauseMulticall.sol";
|
|
7
|
+
import {
|
|
8
|
+
IAddressProviderV3,
|
|
9
|
+
AP_CONTRACTS_REGISTER,
|
|
10
|
+
NO_VERSION_CONTROL
|
|
11
|
+
} from "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
|
|
12
|
+
import {ContractsRegister} from "@gearbox-protocol/core-v2/contracts/core/ContractsRegister.sol";
|
|
13
|
+
import {
|
|
14
|
+
IAddressProviderV3,
|
|
15
|
+
AP_CONTRACTS_REGISTER
|
|
16
|
+
} from "@gearbox-protocol/core-v3/contracts/interfaces/IAddressProviderV3.sol";
|
|
17
|
+
import {ICreditManagerV3} from "@gearbox-protocol/core-v3/contracts/interfaces/ICreditManagerV3.sol";
|
|
18
|
+
import {NetworkDetector} from "@gearbox-protocol/sdk-gov/contracts/NetworkDetector.sol";
|
|
19
|
+
|
|
20
|
+
import {Test} from "forge-std/Test.sol";
|
|
21
|
+
import "forge-std/console.sol";
|
|
22
|
+
|
|
23
|
+
address constant ap = 0x9ea7b04Da02a5373317D745c1571c84aaD03321D;
|
|
24
|
+
|
|
25
|
+
contract PauseMulticallTest is Test {
|
|
26
|
+
uint256 chainId;
|
|
27
|
+
|
|
28
|
+
PauseMulticall pm;
|
|
29
|
+
|
|
30
|
+
constructor() {
|
|
31
|
+
NetworkDetector nd = new NetworkDetector();
|
|
32
|
+
chainId = nd.chainId();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
modifier liveTestOnly() {
|
|
36
|
+
if (chainId == 1) {
|
|
37
|
+
_;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function setUp() public liveTestOnly {
|
|
42
|
+
pm = new PauseMulticall(ap);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
///
|
|
46
|
+
/// TESTS
|
|
47
|
+
///
|
|
48
|
+
}
|
package/package.json
CHANGED