Skip to content

Commit

Permalink
add local deployment scripts, env.example and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kafeikui committed Aug 9, 2023
1 parent c100515 commit 1c778b5
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 1 deletion.
11 changes: 10 additions & 1 deletion contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ MIN_INITIAL_OPERATOR_COUNT=1
MIN_REWARD_DURATION=86400
DELEGATION_RATE_DENOMINATOR=20
UNSTAKE_FREEZING_DURATION=1209600
REWARD_AMOUNT=150000000000000000000000
REWARD_AMOUNT=150000000000000000000000

# Optimism Config
OP_CHAIN_ID=901
OP_CHAIN_MESSENGER_ADDRESS=0x82e01223d51Eb87e16A03E24687EDF0F294da6f1
OP_L1_CROSS_DOMAIN_MESSENGER_ADDRESS=0xa513E6E4b8f2a923D98304ec87F64353C4D5C853
OP_L2_CROSS_DOMAIN_MESSENGER_ADDRESS=0x4200000000000000000000000000000000000007
OP_CONTROLLER_ORACLE_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
OP_ADAPTER_ADDRESS=0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9
OP_ARPA_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
12 changes: 12 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ cast rpc [rpc_method_name] [rpc_method_input_params]
cast receipt [transaction_hash]
```

## Local Test on Optimism Devnet

Deployment steps:

```bash
forge script script/OPControllerOracleLocalTest.s.sol:OPControllerOracleLocalTestScript --fork-url http://localhost:9545 --broadcast
# update the L2 contract addresses in .env
forge script script/ControllerLocalTest.s.sol:ControllerLocalTestScript --fork-url http://localhost:8545 --broadcast
# update the L1 contract addresses in .env
forge script script/OPControllerOracleInitializationLocalTest.s.sol:OPControllerOracleInitializationLocalTestScript --fork-url http://localhost:9545 --broadcast
forge script script/StakeNodeLocalTest.s.sol:StakeNodeLocalTestScript --fork-url http://localhost:8545 --broadcast -g 150
```
18 changes: 18 additions & 0 deletions contracts/script/ControllerLocalTest.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {Controller} from "../src/Controller.sol";
import {ControllerRelayer} from "../src/ControllerRelayer.sol";
import {OPChainMessenger} from "../src/OPChainMessenger.sol";
import {IControllerOwner} from "../src/interfaces/IControllerOwner.sol";
import {Adapter} from "../src/Adapter.sol";
import {IAdapterOwner} from "../src/interfaces/IAdapterOwner.sol";
Expand Down Expand Up @@ -57,8 +59,14 @@ contract ControllerLocalTestScript is Script {
uint256 internal _delegationRateDenominator = vm.envUint("DELEGATION_RATE_DENOMINATOR");
uint256 internal _unstakeFreezingDuration = vm.envUint("UNSTAKE_FREEZING_DURATION");

uint256 internal _opChainId = vm.envUint("OP_CHAIN_ID");
address internal _opControllerOracleAddress = vm.envAddress("OP_CONTROLLER_ORACLE_ADDRESS");
address internal _opL1CrossDomainMessengerAddress = vm.envAddress("OP_L1_CROSS_DOMAIN_MESSENGER_ADDRESS");

function run() external {
Controller controller;
ControllerRelayer controllerRelayer;
OPChainMessenger opChainMessenger;
ERC1967Proxy adapter;
Adapter adapterImpl;
Staking staking;
Expand Down Expand Up @@ -140,5 +148,15 @@ contract ControllerLocalTestScript is Script {

vm.broadcast(_deployerPrivateKey);
staking.setController(address(controller));

vm.broadcast(_deployerPrivateKey);
controllerRelayer = new ControllerRelayer(address(controller));

vm.broadcast(_deployerPrivateKey);
opChainMessenger =
new OPChainMessenger(address(controllerRelayer), _opControllerOracleAddress, _opL1CrossDomainMessengerAddress);

vm.broadcast(_deployerPrivateKey);
controllerRelayer.setChainMessenger(_opChainId, address(opChainMessenger));
}
}
30 changes: 30 additions & 0 deletions contracts/script/OPControllerOracleInitializationLocalTest.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {ControllerOracle} from "../src/ControllerOracle.sol";
import {Adapter} from "../src/Adapter.sol";
import {IAdapterOwner} from "../src/interfaces/IAdapterOwner.sol";
import {Arpa} from "./ArpaLocalTest.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";

// solhint-disable-next-line max-states-count
contract OPControllerOracleInitializationLocalTestScript is Script {
uint256 internal _deployerPrivateKey = vm.envUint("ADMIN_PRIVATE_KEY");

uint256 internal _lastOutput = vm.envUint("LAST_OUTPUT");
address internal _arpaAddress = vm.envAddress("OP_ARPA_ADDRESS");
address internal _controllerOracleAddress = vm.envAddress("OP_CONTROLLER_ORACLE_ADDRESS");
address internal _adapterAddress = vm.envAddress("OP_ADAPTER_ADDRESS");
address internal _opChainMessengerAddress = vm.envAddress("OP_CHAIN_MESSENGER_ADDRESS");
address internal _opL2CrossDomainMessengerAddress = vm.envAddress("OP_L2_CROSS_DOMAIN_MESSENGER_ADDRESS");

function run() external {
vm.broadcast(_deployerPrivateKey);
ControllerOracle(_controllerOracleAddress).initialize(
_arpaAddress, _opChainMessengerAddress, _opL2CrossDomainMessengerAddress, _adapterAddress, _lastOutput
);
}
}
91 changes: 91 additions & 0 deletions contracts/script/OPControllerOracleLocalTest.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {ControllerOracle} from "../src/ControllerOracle.sol";
import {Adapter} from "../src/Adapter.sol";
import {IAdapterOwner} from "../src/interfaces/IAdapterOwner.sol";
import {Arpa} from "./ArpaLocalTest.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {ERC1967Proxy} from "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";

// solhint-disable-next-line max-states-count
contract OPControllerOracleLocalTestScript is Script {
uint256 internal _deployerPrivateKey = vm.envUint("ADMIN_PRIVATE_KEY");

uint256 internal _lastOutput = vm.envUint("LAST_OUTPUT");

uint16 internal _minimumRequestConfirmations = uint16(vm.envUint("MINIMUM_REQUEST_CONFIRMATIONS"));
uint32 internal _maxGasLimit = uint32(vm.envUint("MAX_GAS_LIMIT"));
uint32 internal _gasAfterPaymentCalculation = uint32(vm.envUint("GAS_AFTER_PAYMENT_CALCULATION"));
uint32 internal _gasExceptCallback = uint32(vm.envUint("GAS_EXCEPT_CALLBACK"));
uint256 internal _signatureTaskExclusiveWindow = vm.envUint("SIGNATURE_TASK_EXCLUSIVE_WINDOW");
uint256 internal _rewardPerSignature = vm.envUint("REWARD_PER_SIGNATURE");
uint256 internal _committerRewardPerSignature = vm.envUint("COMMITTER_REWARD_PER_SIGNATURE");

uint32 internal _fulfillmentFlatFeeEthPPMTier1 = uint32(vm.envUint("FULFILLMENT_FLAT_FEE_ARPA_PPM_TIER1"));
uint32 internal _fulfillmentFlatFeeEthPPMTier2 = uint32(vm.envUint("FULFILLMENT_FLAT_FEE_ARPA_PPM_TIER2"));
uint32 internal _fulfillmentFlatFeeEthPPMTier3 = uint32(vm.envUint("FULFILLMENT_FLAT_FEE_ARPA_PPM_TIER3"));
uint32 internal _fulfillmentFlatFeeEthPPMTier4 = uint32(vm.envUint("FULFILLMENT_FLAT_FEE_ARPA_PPM_TIER4"));
uint32 internal _fulfillmentFlatFeeEthPPMTier5 = uint32(vm.envUint("FULFILLMENT_FLAT_FEE_ARPA_PPM_TIER5"));
uint24 internal _reqsForTier2 = uint24(vm.envUint("REQS_FOR_TIER2"));
uint24 internal _reqsForTier3 = uint24(vm.envUint("REQS_FOR_TIER3"));
uint24 internal _reqsForTier4 = uint24(vm.envUint("REQS_FOR_TIER4"));
uint24 internal _reqsForTier5 = uint24(vm.envUint("REQS_FOR_TIER5"));

uint16 internal _flatFeePromotionGlobalPercentage = uint16(vm.envUint("FLAT_FEE_PROMOTION_GLOBAL_PERCENTAGE"));
bool internal _isFlatFeePromotionEnabledPermanently = vm.envBool("IS_FLAT_FEE_PROMOTION_ENABLED_PERMANENTLY");
uint256 internal _flatFeePromotionStartTimestamp = vm.envUint("FLAT_FEE_PROMOTION_START_TIMESTAMP");
uint256 internal _flatFeePromotionEndTimestamp = vm.envUint("FLAT_FEE_PROMOTION_END_TIMESTAMP");

function run() external {
ControllerOracle controllerOracle;
ERC1967Proxy adapter;
Adapter adapterImpl;
IERC20 arpa;

vm.broadcast(_deployerPrivateKey);
arpa = new Arpa();

vm.broadcast(_deployerPrivateKey);
controllerOracle = new ControllerOracle();

vm.broadcast(_deployerPrivateKey);
adapterImpl = new Adapter();

vm.broadcast(_deployerPrivateKey);
adapter =
new ERC1967Proxy(address(adapterImpl),abi.encodeWithSignature("initialize(address)", address(controllerOracle)));

vm.broadcast(_deployerPrivateKey);
IAdapterOwner(address(adapter)).setAdapterConfig(
_minimumRequestConfirmations,
_maxGasLimit,
_gasAfterPaymentCalculation,
_gasExceptCallback,
_signatureTaskExclusiveWindow,
_rewardPerSignature,
_committerRewardPerSignature
);

vm.broadcast(_deployerPrivateKey);
IAdapterOwner(address(adapter)).setFlatFeeConfig(
IAdapterOwner.FeeConfig(
_fulfillmentFlatFeeEthPPMTier1,
_fulfillmentFlatFeeEthPPMTier2,
_fulfillmentFlatFeeEthPPMTier3,
_fulfillmentFlatFeeEthPPMTier4,
_fulfillmentFlatFeeEthPPMTier5,
_reqsForTier2,
_reqsForTier3,
_reqsForTier4,
_reqsForTier5
),
_flatFeePromotionGlobalPercentage,
_isFlatFeePromotionEnabledPermanently,
_flatFeePromotionStartTimestamp,
_flatFeePromotionEndTimestamp
);
}
}

0 comments on commit 1c778b5

Please sign in to comment.