Skip to content

Commit

Permalink
pre commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramarti authored and ezreal1997 committed Oct 15, 2024
1 parent df220cd commit 879d52e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ ADMIN_ADDRESS=0x123...
UPGRADE_ADMIN_ADDRESS=0x234...
```
- `ADMIN_ADDRESS` will be the owner of `IPTokenStaking` and `UpgradeEntryPoint`, able to execute admin methods.
- `UPGRADE_ADMIN_ADDRESS` will be the owner of the [ProxyAdmin](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/transparent/ProxyAdmin.sol) for each upgradeable predeploy.
- `UPGRADE_ADMIN_ADDRESS` will be the owner of the [ProxyAdmin](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/transparent/ProxyAdmin.sol) for each upgradeable predeploy.

2. Run
```
forge script script/GenerateAlloc.s.sol -vvvv --chain-id <DESIRED_CHAIN_ID>
```

Copy the contents of the resulting JSON file, and paste in the `alloc` item of `story-geth` `genesis.json`
Copy the contents of the resulting JSON file, and paste in the `alloc` item of `story-geth` `genesis.json`
10 changes: 6 additions & 4 deletions contracts/script/GenerateAlloc.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ contract GenerateAlloc is Script {
function setStaking() internal {
address impl = Predeploys.getImplAddress(Predeploys.Staking);

address tmp = address(new IPTokenStaking(
1 gwei, // stakingRounding
1 ether // defaultMinUnjailFee, 1 IP
));
address tmp = address(
new IPTokenStaking(
1 gwei, // stakingRounding
1 ether // defaultMinUnjailFee, 1 IP
)
);
console2.log("tpm", tmp);
vm.etch(impl, tmp.code);

Expand Down
14 changes: 7 additions & 7 deletions contracts/script/TestPrecompileUpgrades.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ contract IPTokenStakingV2 is IPTokenStaking, MockNewFeatures {
constructor(
uint256 stakingRounding,
uint256 defaultMinUnjailFee
) IPTokenStaking(stakingRounding, defaultMinUnjailFee) {

}
) IPTokenStaking(stakingRounding, defaultMinUnjailFee) {}
}

contract UpgradeEntrypointV2 is UpgradeEntrypoint, MockNewFeatures {}
Expand All @@ -52,10 +50,12 @@ contract TestPrecompileUpgrades is Script {
vm.startBroadcast(upgradeKey);

// ---- Staking
address newImpl = address(new IPTokenStakingV2(
1 gwei, // stakingRounding
1 ether
));
address newImpl = address(
new IPTokenStakingV2(
1 gwei, // stakingRounding
1 ether
)
);
ProxyAdmin proxyAdmin = ProxyAdmin(EIP1967Helper.getAdmin(Predeploys.Staking));
console2.log("staking proxy admin", address(proxyAdmin));
console2.log("staking proxy admin owner", proxyAdmin.owner());
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ library Errors {

error IPTokenStaking__FailedRemainerRefund();
error IPTokenStaking__InvalidFeeAmount();
}
}
15 changes: 6 additions & 9 deletions contracts/src/protocol/IPTokenStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import { IIPTokenStaking } from "../interfaces/IIPTokenStaking.sol";
import { Secp256k1 } from "../libraries/Secp256k1.sol";
import { Errors } from "../libraries/Errors.sol";

/**
* @title IPTokenStaking
* @notice The deposit contract for IP token staked validators.
* @dev This contract is a sort of "bridge" to request validator related actions on the consensus chain. The response will
* happen on the consensus chain.
* @dev This contract is a sort of "bridge" to request validator related actions on the consensus chain.
* The response will happen on the consensus chain.
* Since most of the validator related actions are executed on the consensus chain, the methods in this contract
* must be considered requests and not final actions, a successful transaction here does not guarantee the success
* of the transaction on the consensus chain.
* NOTE: All $IP tokens staked to this contract will be burned (transferred to the zero address).
* The flow is as follows:
* 1. User calls a method in this contract, which will emit an event if checks pass.
* 2. Modules on the consensus chain are listening for these events and execute the corresponding logic (e.g. staking, create
* validator, etc.), minting tokens in CL if needed.
* 2. Modules on the consensus chain are listening for these events and execute the corresponding logic
* (e.g. staking, create validator, etc.), minting tokens in CL if needed.
* 3. If the action fails in CL, for example staking on a validator that doesn't exist, the deposited $IP tokens will be
* returned to the user via the partial withdrawal queue, which may take some time. Same with fees. Remember that the EL
* transaction of step 2 would not have reverted.
Expand Down Expand Up @@ -364,7 +363,6 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
_refundRemainder(remainder);
}


// TODO: update validator method (next version)

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -526,7 +524,6 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
_unstake(delegatorUncmpPubkey, validatorUncmpPubkey, delegationId, amount, data);
}


function _unstake(
bytes calldata delegatorUncmpPubkey,
bytes calldata validatorUncmpPubkey,
Expand Down Expand Up @@ -569,7 +566,7 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
/// @dev Emits the Unjail event after burning the fee and burns the fee from the caller.
/// @param fee The fee to unjail the validator.
/// @param validatorUncmpPubkey The validator's 65-byte uncompressed Secp256k1 public key
/// @param data Additional data for the unjail.
/// @param data Additional data for the unjail.
function _unjail(uint256 fee, bytes calldata validatorUncmpPubkey, bytes calldata data) private {
if (fee != unjailFee) {
revert Errors.IPTokenStaking__InvalidFeeAmount();
Expand All @@ -583,7 +580,7 @@ contract IPTokenStaking is IIPTokenStaking, Ownable2StepUpgradeable, ReentrancyG
//////////////////////////////////////////////////////////////////////////*/

/// @dev Refunds the remainder of the stake amount to the msg sender.
/// WARNING: Methods using this function should have nonReentrant modifier
/// WARNING: Methods using this function should have nonReentrant modifier
/// to prevent potential reentrancy attacks.
/// @param remainder The remainder of the stake amount.
function _refundRemainder(uint256 remainder) private {
Expand Down
5 changes: 2 additions & 3 deletions contracts/test/stake/IPTokenStaking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pragma solidity ^0.8.23;
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

import { IPTokenStaking, IIPTokenStaking } from "../../src/protocol/IPTokenStaking.sol";
import { Secp256k1 } from "../../src/libraries/Secp256k1.sol";
import { Errors } from "../../src/libraries/Errors.sol";
import { Test } from "../utils/Test.sol";

Expand Down Expand Up @@ -334,7 +333,7 @@ contract IPTokenStakingTest is Test {
vm.expectRevert(Errors.IPTokenStaking__InvalidPubkeyLength.selector);
ipTokenStaking.redelegate{ value: stakeAmount }(
delegatorUncmpPubkey,
hex"04e38d15ae6cc5d41cce27a2307903cb",
hex"04e38d15ae6cc5d41cce27a2307903cb", // pragma: allowlist secret
validatorUncmpDstPubkey,
delegationId,
stakeAmount
Expand All @@ -346,7 +345,7 @@ contract IPTokenStakingTest is Test {
ipTokenStaking.redelegate{ value: stakeAmount }(
delegatorUncmpPubkey,
validatorUncmpSrcPubkey,
hex"04e38d15ae6cc5d41cce27a2307903cb",
hex"04e38d15ae6cc5d41cce27a2307903cb", // pragma: allowlist secret
delegationId,
stakeAmount
);
Expand Down

0 comments on commit 879d52e

Please sign in to comment.