@piplabs/story-contracts 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @piplabs/story-contracts might be problematic. Click here for more details.

@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /* solhint-disable max-line-length */
3
+ pragma solidity 0.8.23;
4
+
5
+ import { Vm } from "forge-std/Vm.sol";
6
+
7
+ /// @title EIP1967Helper
8
+ /// @dev Testing library to help with reading EIP 1967 variables from state
9
+ /// @custom:attribution https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/test/mocks/EIP1967Helper.sol
10
+ library EIP1967Helper {
11
+ /// @notice The storage slot that holds the address of a proxy implementation.
12
+ /// @dev `bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)`
13
+ bytes32 internal constant PROXY_IMPLEMENTATION_SLOT =
14
+ 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
15
+
16
+ /// @notice The storage slot that holds the address of the owner.
17
+ /// @dev `bytes32(uint256(keccak256('eip1967.proxy.admin')) - 1)`
18
+ bytes32 internal constant PROXY_ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
19
+
20
+ Vm internal constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
21
+
22
+ function getAdmin(address _proxy) internal view returns (address) {
23
+ return address(uint160(uint256(vm.load(address(_proxy), PROXY_ADMIN_SLOT))));
24
+ }
25
+
26
+ function setAdmin(address _addr, address _admin) internal {
27
+ vm.store(_addr, PROXY_ADMIN_SLOT, bytes32(uint256(uint160(_admin))));
28
+ }
29
+
30
+ function getImplementation(address _proxy) internal view returns (address) {
31
+ return address(uint160(uint256(vm.load(address(_proxy), PROXY_IMPLEMENTATION_SLOT))));
32
+ }
33
+
34
+ function setImplementation(address _addr, address _impl) internal {
35
+ vm.store(_addr, PROXY_IMPLEMENTATION_SLOT, bytes32(uint256(uint160(_impl))));
36
+ }
37
+ }
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity 0.8.23;
3
+
4
+ import { Vm } from "forge-std/Vm.sol";
5
+
6
+ /**
7
+ * @title InitializableHelper
8
+ * @notice Helper library to read / manipulate OpenZeppelin v5 Initializable storage
9
+ */
10
+ library InitializableHelper {
11
+ Vm internal constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
12
+
13
+ // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
14
+ bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
15
+
16
+ // INITIALIZABLE_STORAGE stores the following struct:
17
+ //
18
+ // struct InitializableStorage {
19
+ // /**
20
+ // * @dev Indicates that the contract has been initialized.
21
+ // */
22
+ // uint64 _initialized;
23
+ // /**
24
+ // * @dev Indicates that the contract is in the process of being initialized.
25
+ // */
26
+ // bool _initializing;
27
+ // }
28
+
29
+ /**
30
+ * @notice Returns the Initializable._initialized value for a given address, at slot 0.
31
+ * @dev Reverts in _initializing.
32
+ */
33
+ function getInitialized(address addr) internal view returns (uint64) {
34
+ // _initialized is the first field in the storage layout
35
+ bytes32 slot = vm.load(addr, INITIALIZABLE_STORAGE);
36
+
37
+ // if _initializing is false, it's bit will be 0, and will not affect uint conversion
38
+ // if _initializing is true, it's bit will be 1, and will affect uint conversion
39
+ // we therefore require it is 0
40
+ require(uint256(slot) <= uint256(type(uint64).max), "initializing");
41
+
42
+ return uint64(uint256(slot));
43
+ }
44
+
45
+ /**
46
+ * @notice Returns true if the address has been initialized.
47
+ */
48
+ function isInitialized(address addr) internal view returns (bool) {
49
+ return getInitialized(addr) == uint64(1);
50
+ }
51
+
52
+ /**
53
+ * @notice Returns true if the initializers are disabled for a given address.
54
+ */
55
+ function areInitializersDisabled(address addr) internal view returns (bool) {
56
+ return getInitialized(addr) == type(uint64).max;
57
+ }
58
+
59
+ /**
60
+ * @notice Disables the initializers for a given address.
61
+ * @dev Sets _initialized to max uint64 (0xFFFFFFFFFFFFFFFF), which disables all initializers.
62
+ */
63
+ function disableInitializers(address addr) internal {
64
+ vm.store(addr, INITIALIZABLE_STORAGE, bytes32(uint256(type(uint64).max)));
65
+ }
66
+ }
@@ -0,0 +1,62 @@
1
+ // SPDX-License-Identifier: AGPL-3.0
2
+ pragma solidity 0.8.23;
3
+
4
+ import { CREATE3 } from "solmate/src/utils/CREATE3.sol";
5
+
6
+ /**
7
+ * @title Create3
8
+ * @notice Factory for deploying contracts to deterministic addresses via CREATE3 Enables deploying
9
+ * contracts using CREATE3.
10
+ * It is based on Zefram’s implementation and includes support for deployment using only a salt value.
11
+ * It support two deployment styles:
12
+ * 1. Each deployer (msg.sender) has its own namespace for deployed addresses.
13
+ * 2. Deterministic deployment using a single salt.
14
+ * @custom:attribution zefram.eth (https://github.com/ZeframLou/create3-factory/blob/main/src/CREATE3Factory.sol)
15
+ */
16
+ contract Create3 {
17
+ /**
18
+ * @notice Deploys a contract using CREATE3
19
+ * @dev The provided salt is hashed together with msg.sender to generate the final salt
20
+ * @param salt The deployer-specific salt for determining the deployed contract's address
21
+ * @param creationCode The creation code of the contract to deploy
22
+ * @return deployed The address of the deployed contract
23
+ */
24
+ function deploy(bytes32 salt, bytes memory creationCode) external payable returns (address deployed) {
25
+ // hash salt with the deployer address to give each deployer its own namespace
26
+ salt = keccak256(abi.encodePacked(msg.sender, salt));
27
+ return CREATE3.deploy(salt, creationCode, msg.value);
28
+ }
29
+
30
+ /**
31
+ * @notice Predicts the address of a deployed contract
32
+ * @dev The provided salt is hashed together with the deployer address to generate the final salt
33
+ * @param deployer The deployer account that will call deploy()
34
+ * @param salt The deployer-specific salt for determining the deployed contract's address
35
+ * @return deployed The address of the contract that will be deployed
36
+ */
37
+ function getDeployed(address deployer, bytes32 salt) external view returns (address deployed) {
38
+ // hash salt with the deployer address to give each deployer its own namespace
39
+ salt = keccak256(abi.encodePacked(deployer, salt));
40
+ return CREATE3.getDeployed(salt);
41
+ }
42
+
43
+ /**
44
+ * @notice Deploys a contract using CREATE3
45
+ * @param salt The deployer-specific salt for determining the deployed contract's address
46
+ * @param creationCode The creation code of the contract to deploy
47
+ * @return deployed The address of the deployed contract
48
+ */
49
+ function deployDeterministic(bytes memory creationCode, bytes32 salt) external payable returns (address deployed) {
50
+ return CREATE3.deploy(salt, creationCode, msg.value);
51
+ }
52
+
53
+ /**
54
+ * @notice Predicts the address of a deployed contract
55
+ * @param salt The deployer-specific salt for determining the deployed contract's address
56
+ * @return deployed The address of the contract that will be deployed
57
+ */
58
+ function predictDeterministicAddress(bytes32 salt) external view returns (address deployed) {
59
+ // hash salt with the deployer address to give each deployer its own namespace
60
+ return CREATE3.getDeployed(salt);
61
+ }
62
+ }
@@ -0,0 +1,303 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity 0.8.23;
3
+
4
+ /// @title IIPTokenStaking
5
+ /// @notice Interface for the IPTokenStaking contract
6
+ interface IIPTokenStaking {
7
+ /// @notice Enum representing the different staking periods
8
+ /// @dev FLEXIBLE is used for flexible staking, where the staking period is not fixed and can be changed by the user
9
+ /// SHORT, MEDIUM, and LONG are used for staking with specific periods
10
+ enum StakingPeriod {
11
+ FLEXIBLE,
12
+ SHORT,
13
+ MEDIUM,
14
+ LONG
15
+ }
16
+
17
+ /// @notice Struct for initialize method args
18
+ /// @dev Contains various parameters for the contract's functionality
19
+ /// @param owner The address of the admin addres
20
+ /// @param minStakeAmount Global minimum amount required to stake
21
+ /// @param minUnstakeAmount Global minimum amount required to unstake
22
+ /// @param minCommissionRate Global minimum commission rate for validators
23
+ /// @param fee The fee charged for adding to CL storage
24
+ struct InitializerArgs {
25
+ address owner;
26
+ uint256 minStakeAmount;
27
+ uint256 minUnstakeAmount;
28
+ uint256 minCommissionRate;
29
+ uint256 fee;
30
+ }
31
+
32
+ /// @notice Emitted when the fee charged for adding to CL storage is updated
33
+ /// @param newFee The new fee
34
+ event FeeSet(uint256 newFee);
35
+
36
+ /// @notice Emitted when a new validator is created.
37
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
38
+ /// @param moniker The moniker of the validator.
39
+ /// @param stakeAmount Token staked to the validator as self-delegation.
40
+ /// @param commissionRate The commission rate of the validator.
41
+ /// @param maxCommissionRate The maximum commission rate of the validator.
42
+ /// @param maxCommissionChangeRate The maximum commission change rate of the validator.
43
+ /// @param supportsUnlocked Whether the validator supports unlocked staking
44
+ /// @param operatorAddress The caller's address
45
+ /// @param data Additional data for the validator
46
+ event CreateValidator(
47
+ bytes validatorCmpPubkey,
48
+ string moniker,
49
+ uint256 stakeAmount,
50
+ uint32 commissionRate,
51
+ uint32 maxCommissionRate,
52
+ uint32 maxCommissionChangeRate,
53
+ uint8 supportsUnlocked,
54
+ address operatorAddress,
55
+ bytes data
56
+ );
57
+
58
+ /// @notice Emitted when the withdrawal address is set/changed.
59
+ /// @param delegator The delegator's address
60
+ /// @param executionAddress Left-padded 32 bytes of the EVM address to receive stake and reward withdrawals.
61
+ event SetWithdrawalAddress(address delegator, bytes32 executionAddress);
62
+
63
+ /// @notice Emitted when the rewards address is set/changed.
64
+ /// @param delegator The delegator's address
65
+ /// @param executionAddress Left-padded 32 bytes of the EVM address to receive stake and reward withdrawals.
66
+ event SetRewardAddress(address delegator, bytes32 executionAddress);
67
+
68
+ /// @notice Emitted when the validator commission is updated
69
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
70
+ /// @param commissionRate The new commission rate of the validator.
71
+ event UpdateValidatorCommission(bytes validatorCmpPubkey, uint32 commissionRate);
72
+
73
+ /// @notice Emitted when a user deposits token into the contract.
74
+ /// @param delegator The delegator's address
75
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
76
+ /// @param stakeAmount Token deposited
77
+ /// @param stakingPeriod The staking period of the deposit
78
+ /// @param delegationId The ID of the delegation
79
+ /// @param operatorAddress The caller's address
80
+ /// @param data Additional data for the deposit
81
+ event Deposit(
82
+ address delegator,
83
+ bytes validatorCmpPubkey,
84
+ uint256 stakeAmount,
85
+ uint256 stakingPeriod,
86
+ uint256 delegationId,
87
+ address operatorAddress,
88
+ bytes data
89
+ );
90
+
91
+ /// @notice Emitted when a user withdraws her stake and starts the unbonding period.
92
+ /// @param delegator The delegator's address
93
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
94
+ /// @param stakeAmount Token unstaked. WARNING: This amount is rounded down to STAKE_ROUNDING.
95
+ /// @param delegationId The ID of the delegation, 0 if flexible
96
+ /// @param operatorAddress The caller's address
97
+ /// @param data Additional data for the deposit
98
+ event Withdraw(
99
+ address delegator,
100
+ bytes validatorCmpPubkey,
101
+ uint256 stakeAmount,
102
+ uint256 delegationId,
103
+ address operatorAddress,
104
+ bytes data
105
+ );
106
+
107
+ /// @notice Emitted when a user triggers redelegation of token from source validator to destination validator.
108
+ /// @param delegator The delegator's address
109
+ /// @param validatorSrcCmpPubkey 33 bytes compressed secp256k1 public key.
110
+ /// @param validatorDstCmpPubkey 33 bytes compressed secp256k1 public key.
111
+ /// @param delegationId if delegation has staking period, 0 if flexible
112
+ /// @param operatorAddress The caller's address
113
+ /// @param amount Token redelegated.
114
+ event Redelegate(
115
+ address delegator,
116
+ bytes validatorSrcCmpPubkey,
117
+ bytes validatorDstCmpPubkey,
118
+ uint256 delegationId,
119
+ address operatorAddress,
120
+ uint256 amount
121
+ );
122
+
123
+ /// @notice Emitted to request setting an operator address to a delegator
124
+ /// @param delegator The delegator's address
125
+ /// @param operator The operator's address
126
+ event SetOperator(address delegator, address operator);
127
+
128
+ /// @notice Emitted to request removing the operator address to a delegator
129
+ /// @param delegator The delegator's address
130
+ event UnsetOperator(address delegator);
131
+
132
+ /// @notice Emitted when the minimum stake amount is set.
133
+ /// @param minStakeAmount The new minimum stake amount.
134
+ event MinStakeAmountSet(uint256 minStakeAmount);
135
+
136
+ /// @notice Emitted when the minimum unstake amount is set.
137
+ /// @param minUnstakeAmount The new minimum unstake amount.
138
+ event MinUnstakeAmountSet(uint256 minUnstakeAmount);
139
+
140
+ /// @notice Emitted when the global minimum commission rate is set.
141
+ /// @param minCommissionRate The new global minimum commission rate.
142
+ event MinCommissionRateChanged(uint256 minCommissionRate);
143
+
144
+ /// @notice Emitted when a validator is unjailed.
145
+ /// @param unjailer The unjailer's address
146
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
147
+ /// @param data Additional data for the unjail.
148
+ event Unjail(address unjailer, bytes validatorCmpPubkey, bytes data);
149
+
150
+ /// @notice Returns the rounded stake amount and the remainder.
151
+ /// @param rawAmount The raw stake amount.
152
+ /// @return amount The rounded stake amount.
153
+ /// @return remainder The remainder of the stake amount.
154
+ function roundedStakeAmount(uint256 rawAmount) external view returns (uint256 amount, uint256 remainder);
155
+
156
+ /// @notice Sets an operator for a delegator.
157
+ /// Calling this method will override any existing operator.
158
+ /// @param operator The operator address to add.
159
+ function setOperator(address operator) external payable;
160
+
161
+ /// @notice Removes current operator for a delegator.
162
+ function unsetOperator() external payable;
163
+
164
+ /// @notice Set/Update the withdrawal address that receives the withdrawals.
165
+ /// Charges fee (CL spam prevention). Must be exact amount.
166
+ /// @param newWithdrawalAddress EVM address to receive the withdrawals.
167
+ function setWithdrawalAddress(address newWithdrawalAddress) external payable;
168
+
169
+ /// @notice Set/Update the withdrawal address that receives the stake and reward withdrawals.
170
+ /// Charges fee (CL spam prevention). Must be exact amount.
171
+ /// @param newRewardsAddress EVM address to receive the stake and reward withdrawals.
172
+ function setRewardsAddress(address newRewardsAddress) external payable;
173
+
174
+ /// @notice Update the commission rate of a validator.
175
+ /// Charges fee (CL spam prevention). Must be exact amount.
176
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
177
+ /// @param commissionRate The new commission rate of the validator.
178
+ function updateValidatorCommission(bytes calldata validatorCmpPubkey, uint32 commissionRate) external payable;
179
+
180
+ /// @notice Entry point for creating a new validator with self delegation.
181
+ /// @dev The caller must provide the compressed public key that matches the expected EVM address.
182
+ /// Use this method to make sure the caller is the owner of the validator.
183
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
184
+ /// @param moniker The moniker of the validator.
185
+ /// @param commissionRate The commission rate of the validator.
186
+ /// @param maxCommissionRate The maximum commission rate of the validator.
187
+ /// @param maxCommissionChangeRate The maximum commission change rate of the validator.
188
+ /// @param supportsUnlocked Whether the validator supports unlocked staking.
189
+ /// @param data Additional data for the validator.
190
+ function createValidator(
191
+ bytes calldata validatorCmpPubkey,
192
+ string calldata moniker,
193
+ uint32 commissionRate,
194
+ uint32 maxCommissionRate,
195
+ uint32 maxCommissionChangeRate,
196
+ bool supportsUnlocked,
197
+ bytes calldata data
198
+ ) external payable;
199
+
200
+ /// @notice Entry point to stake (delegate) to the given validator. The consensus client (CL) is notified of
201
+ /// the deposit and manages the stake accounting and validator onboarding. Payer must be the delegator.
202
+ /// @dev Staking burns tokens in Execution Layer (EL). Unstaking (withdrawal) will trigger minting through
203
+ /// withdrawal queue.
204
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
205
+ /// @param stakingPeriod The staking period.
206
+ /// @param data Additional data for the stake.
207
+ /// @return delegationId The delegation ID, always 0 for flexible staking.
208
+ function stake(
209
+ bytes calldata validatorCmpPubkey,
210
+ StakingPeriod stakingPeriod,
211
+ bytes calldata data
212
+ ) external payable returns (uint256 delegationId);
213
+
214
+ /// @notice Entry point for staking IP token to stake to the given validator. The consensus chain is notified of
215
+ /// the stake and manages the stake accounting and validator onboarding. Payer can stake on behalf of another user,
216
+ /// who will be the beneficiary of the stake.
217
+ /// @dev Staking burns tokens in Execution Layer (EL). Unstaking (withdrawal) will trigger minting through
218
+ /// withdrawal queue.
219
+ /// @param delegator The delegator's address
220
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
221
+ /// @param stakingPeriod The staking period.
222
+ /// @param data Additional data for the stake.
223
+ /// @return delegationId The delegation ID, always 0 for flexible staking.
224
+ function stakeOnBehalf(
225
+ address delegator,
226
+ bytes calldata validatorCmpPubkey,
227
+ StakingPeriod stakingPeriod,
228
+ bytes calldata data
229
+ ) external payable returns (uint256 delegationId);
230
+
231
+ /// @notice Entry point for redelegating the stake to another validator.
232
+ /// Charges fee (CL spam prevention). Must be exact amount.
233
+ /// @dev For non flexible staking, your staking period will continue as is.
234
+ /// @dev For locked tokens, this will fail in CL if the validator doesn't support unlocked staking.
235
+ /// @param validatorSrcCmpPubkey 33 bytes compressed secp256k1 public key.
236
+ /// @param validatorDstCmpPubkey 33 bytes compressed secp256k1 public key.
237
+ /// @param delegationId The delegation ID, 0 for flexible staking.
238
+ /// @param amount The amount of stake to redelegate.
239
+ function redelegate(
240
+ bytes calldata validatorSrcCmpPubkey,
241
+ bytes calldata validatorDstCmpPubkey,
242
+ uint256 delegationId,
243
+ uint256 amount
244
+ ) external payable;
245
+
246
+ /// @notice Entry point for redelegating the stake to another validator on behalf of the delegator.
247
+ /// Charges fee (CL spam prevention). Must be exact amount.
248
+ /// @dev For non flexible staking, your staking period will continue as is.
249
+ /// @dev For locked tokens, this will fail in CL if the validator doesn't support unlocked staking.
250
+ /// @dev Caller must be the operator for the delegator, set via `setOperator`. The operator check is done in CL, so
251
+ /// this method will succeed even if the caller is not the operator (but will fail in CL).
252
+ /// @param delegator The delegator's address
253
+ /// @param validatorSrcCmpPubkey 33 bytes compressed secp256k1 public key.
254
+ /// @param validatorDstCmpPubkey 33 bytes compressed secp256k1 public key.
255
+ /// @param delegationId The delegation ID, 0 for flexible staking.
256
+ /// @param amount The amount of stake to redelegate.
257
+ function redelegateOnBehalf(
258
+ address delegator,
259
+ bytes calldata validatorSrcCmpPubkey,
260
+ bytes calldata validatorDstCmpPubkey,
261
+ uint256 delegationId,
262
+ uint256 amount
263
+ ) external payable;
264
+
265
+ /// @notice Entry point for unstaking the previously staked token.
266
+ /// NOTE: If the amount is not divisible by STAKE_ROUNDING, it will be rounded down.
267
+ /// @dev Unstake (withdrawal) will trigger native minting, so token in this contract is considered as burned.
268
+ /// Charges fee (CL spam prevention). Must be exact amount.
269
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
270
+ /// @param delegationId The delegation ID, 0 for flexible staking.
271
+ /// @param amount Token amount to unstake. This amount will be rounded down to STAKE_ROUNDING.
272
+ /// @param data Additional data for the unstake.
273
+ function unstake(
274
+ bytes calldata validatorCmpPubkey,
275
+ uint256 delegationId,
276
+ uint256 amount,
277
+ bytes calldata data
278
+ ) external payable;
279
+
280
+ /// @notice Entry point for unstaking the previously staked token on behalf of the delegator.
281
+ /// Charges fee (CL spam prevention). Must be exact amount.
282
+ /// NOTE: If the amount is not divisible by STAKE_ROUNDING, it will be rounded down.
283
+ /// @dev Caller must be the operator for the delegator, set via `setOperator`. The operator check is done in CL, so
284
+ /// this method will succeed even if the caller is not the operator (but will fail in CL).
285
+ /// @param delegator The delegator's address
286
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
287
+ /// @param delegationId The delegation ID, 0 for flexible staking.
288
+ /// @param amount Token amount to unstake. This amount will be rounded down to STAKE_ROUNDING.
289
+ /// @param data Additional data for the unstake.
290
+ function unstakeOnBehalf(
291
+ address delegator,
292
+ bytes calldata validatorCmpPubkey,
293
+ uint256 delegationId,
294
+ uint256 amount,
295
+ bytes calldata data
296
+ ) external payable;
297
+
298
+ /// @notice Requests to unjail the validator. Caller must pay a fee to prevent spamming.
299
+ /// Fee must be exact amount.
300
+ /// @param validatorCmpPubkey 33 bytes compressed secp256k1 public key.
301
+ /// @param data Additional data for the unjail.
302
+ function unjail(bytes calldata validatorCmpPubkey, bytes calldata data) external payable;
303
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity 0.8.23;
3
+
4
+ /// @title IUBIPool
5
+ /// @notice Interface for the UBI Pool contract
6
+ interface IUBIPool {
7
+ /// @notice Emitted when the UBI percentage is set
8
+ /// @param percentage The percentage of the UBI
9
+ event UBIPercentageSet(uint32 percentage);
10
+
11
+ /// @notice Emitted when the UBI distribution is set
12
+ /// @param totalUBI The total amount of UBI
13
+ /// @param validatorCmpPubKeys The validator compressed public keys
14
+ /// @param amounts The amounts of the UBI for each validator
15
+ event UBIDistributionSet(uint256 month, uint256 totalUBI, bytes[] validatorCmpPubKeys, uint256[] amounts);
16
+
17
+ /// @notice Sets the UBI percentage
18
+ /// @param percentage The percentage of the UBI
19
+ function setUBIPercentage(uint32 percentage) external;
20
+
21
+ /// @notice Sets the UBI distribution
22
+ /// @param totalUBI The total amount of UBI
23
+ /// @param validatorCmpPubKeys The validator compressed public keys
24
+ /// @param amounts The amounts of the UBI for each validator
25
+ /// @return distributionId The distribution id
26
+ function setUBIDistribution(
27
+ uint256 totalUBI,
28
+ bytes[] calldata validatorCmpPubKeys,
29
+ uint256[] calldata amounts
30
+ ) external returns (uint256);
31
+
32
+ /// @notice Claims the UBI for a validator
33
+ /// @dev The validator address must be the one who is set to receive the UBI
34
+ /// @param distributionId The distribution id
35
+ /// @param validatorCmpPubkey The validator compressed public key
36
+ function claimUBI(uint256 distributionId, bytes calldata validatorCmpPubkey) external;
37
+ }
@@ -0,0 +1,33 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity 0.8.23;
3
+
4
+ interface IUpgradeEntrypoint {
5
+ /// PROTO: https://github.com/cosmos/cosmos-sdk/blob/v0.50.9/proto/cosmos/upgrade/v1beta1/upgrade.proto
6
+ /// @notice Emitted when an upgrade is submitted.
7
+ /// @param name Sets the name for the upgrade. This name will be used by the upgraded version of the software to
8
+ /// apply any special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is
9
+ /// also used to detect whether a software version can handle a given upgrade. If no upgrade handler with this name
10
+ /// has been set in the software, it will be assumed that the software is out-of-date when the upgrade Time or
11
+ /// Height is reached and the software will exit.
12
+ /// @param height The height at which the upgrade must be performed.
13
+ /// @param info Any application specific upgrade info to be included on-chain such as a git commit that validators
14
+ /// could automatically upgrade to.
15
+ event SoftwareUpgrade(string name, int64 height, string info);
16
+
17
+ /// @notice Emitted when a planned upgrade is to be cancelled.
18
+ event CancelUpgrade();
19
+
20
+ /// @notice Submits an upgrade plan.
21
+ /// @param name Sets the name for the upgrade. This name will be used by the upgraded version of the software to
22
+ /// apply any special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is
23
+ /// also used to detect whether a software version can handle a given upgrade. If no upgrade handler with this name
24
+ /// has been set in the software, it will be assumed that the software is out-of-date when the upgrade Time or
25
+ /// Height is reached and the software will exit.
26
+ /// @param height The height at which the upgrade must be performed.
27
+ /// @param info Any application specific upgrade info to be included on-chain such as a git commit that validators
28
+ /// could automatically upgrade to.
29
+ function planUpgrade(string calldata name, int64 height, string calldata info) external;
30
+
31
+ /// @notice Cancels an upgrade plan if there is one planned. Otherwise, it does nothing.
32
+ function cancelUpgrade() external;
33
+ }
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: GPL-3.0-only
2
+ pragma solidity 0.8.23;
3
+
4
+ /**
5
+ * @title Predeploys
6
+ * @notice Predeploy addresses (match story/genutil/evm/predeploys.go)
7
+ */
8
+ library Predeploys {
9
+ /// @notice Predeploys
10
+ /// @dev Address reserved for ERC20 wrapper for Story's native token, address starts with
11
+ /// Story mainnet chain ID
12
+ address internal constant WIP = 0x1514000000000000000000000000000000000000;
13
+
14
+ /// @dev We reserve the first 1024 addresses after Namespace for proxied predeploys.
15
+ /// GenerateAlloc.s.sol will set a TransparentUpgradeableProxy for each of them, set to a
16
+ /// deterministic implementation address. Only named predeploys's implementation will have bytecode, the
17
+ /// others will be EOAs. Governance will be able to upgrade to valid implementations later if needed.
18
+ address internal constant Namespace = 0xCCcCCc0000000000000000000000000000000000;
19
+ /// @dev Number of reserved proxied predeploys in the Namespace.
20
+ uint256 internal constant NamespaceSize = 1024;
21
+
22
+ /// @dev IPTokenStaking proxy address
23
+ address internal constant Staking = 0xCCcCcC0000000000000000000000000000000001;
24
+ /// @dev UBIPool proxy address
25
+ address internal constant UBIPool = 0xCccCCC0000000000000000000000000000000002;
26
+ /// @dev UpgradeEntryPoint proxy address
27
+ address internal constant Upgrades = 0xccCCcc0000000000000000000000000000000003;
28
+
29
+ /// @notice Create3 factory address https://github.com/ZeframLou/create3-factory
30
+ /// @dev Since Create3 is deployed using Create2, which is deterministic but depends on the deployer's wallet,
31
+ /// we use a predeploy to maintain compatibility with the contracts deployed by ZeframLou in a permissionless way.
32
+ address internal constant Create3 = 0x9fBB3DF7C40Da2e5A0dE984fFE2CCB7C47cd0ABf;
33
+
34
+ /// @notice ERC6551Registry address Predeploy
35
+ /// @dev Common address for the ERC6551Registry across all chains defined by ERC-6551
36
+ address internal constant ERC6551Registry = 0x000000006551c19487814612e58FE06813775758;
37
+
38
+ /// @notice Return true if `addr` is proxied
39
+ function proxied(address addr) internal pure returns (bool) {
40
+ return addr > Namespace && addr <= address(uint160(Namespace) + uint160(NamespaceSize));
41
+ }
42
+
43
+ /// @notice Return implementation address for a proxied predeploy
44
+ function getImplAddress(address proxyAddress) internal pure returns (address) {
45
+ require(proxied(proxyAddress), "Predeploys: not proxied");
46
+
47
+ // max uint160 is odd, which gives us unique implementation for each predeploy
48
+ return address(type(uint160).max - uint160(proxyAddress));
49
+ }
50
+ }