Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Nov 21, 2024
1 parent d26bd1b commit 119c897
Showing 1 changed file with 25 additions and 102 deletions.
127 changes: 25 additions & 102 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ contract Deploy is Script {

//
uint256 public constant ENOUGH_BALANCE = 33e18;
uint256 public constant NOT_ENOUGH_BALANCE = 0.3e18;
uint256 public constant NOT_ENOUGH_BALANCE = 1e18;

error Deploy_InvalidPrecomputedAddress();
error Deploy_DeployerNotEnoughBalance();
Expand Down Expand Up @@ -138,6 +138,7 @@ contract Deploy is Script {

// Deploy `Oracle`
oracle = new Oracle();

console.log('`Oracle` deployed at:', address(oracle));

// Deploy `Arbitrable`
Expand Down Expand Up @@ -204,9 +205,9 @@ contract Deploy is Script {
}

function setupBalances() public {
// checks chain id
// check grt balance
// check ether balance
// deployer funds agent
vm.startBroadcast(deployer);

uint256 _balanceD = address(deployer).balance;
console.log('deployer balance', _balanceD / 1e18);
if (_balanceD < NOT_ENOUGH_BALANCE) {
Expand All @@ -220,21 +221,19 @@ contract Deploy is Script {
console.log('agent balance', address(agent).balance / 1e18);
}

// deployer funds agent
vm.startBroadcast(deployer);
console.log('GRT balance of agent %d', graphToken.balanceOf(agent) / 1e18);
if (graphToken.balanceOf(agent) < NOT_ENOUGH_BALANCE) {
horizonAccountingExtension.GRT().transfer(agent, ENOUGH_BALANCE);
}
console.log('GRT balance of agent %d', graphToken.balanceOf(agent) / 1e18);
vm.stopBroadcast();
}

function setupEBO() public {
string memory chainId = string.concat('eip155:421614');

vm.startBroadcast(deployer);

eboRequestModule.addEBORequestCreator(eboRequestCreator);

string memory chainId = string.concat('eip155:421614');
eboRequestCreator.addChain(chainId);

vm.stopBroadcast();
Expand Down Expand Up @@ -262,109 +261,30 @@ contract Deploy is Script {
vm.stopBroadcast();
}

//
function _labelContracts() internal {
// convert to a loop?
vm.label(address(oracle), 'Oracle');
vm.label(address(eboAccessModule), 'eboAccessModule');
vm.label(address(eboRequestModule), 'RequestModule');
vm.label(address(bondedResponseModule), 'bondedResponseModule');
vm.label(address(bondEscalationModule), 'bondEscalationModule');
vm.label(address(eboRequestCreator), 'EBORequestCreator');
//
vm.label(address(graphToken), 'GraphToken');
vm.label(address(horizonStaking), 'HorizonStaking');
vm.label(address(epochManager), 'EpochManager');
}

function _loadContracts() internal returns (bool) {
if (address(oracle) == address(0)) {
oracle = IOracle(vm.envOr('SETUP_ADDRESS_Oracle', address(0)));
arbitrable = IArbitrable(vm.envOr('SETUP_ADDRESS_Arbitrable', address(0)));
eboRequestModule = IEBORequestModule(vm.envOr('SETUP_ADDRESS_EBORequestModule', address(0)));
bondedResponseModule = IBondedResponseModule(vm.envOr('SETUP_ADDRESS_BondedResponseModule', address(0)));
bondEscalationModule = IBondEscalationModule(vm.envOr('SETUP_ADDRESS_BondEscalationModule', address(0)));
arbitratorModule = IArbitratorModule(vm.envOr('SETUP_ADDRESS_ArbitratorModule', address(0)));
eboFinalityModule = IEBOFinalityModule(vm.envOr('SETUP_ADDRESS_EBOFinalityModule', address(0)));
horizonAccountingExtension =
IHorizonAccountingExtension(vm.envOr('SETUP_ADDRESS_HorizonAccountingExtension', address(0)));
councilArbitrator = ICouncilArbitrator(vm.envOr('SETUP_ADDRESS_CouncilArbitrator', address(0)));
eboAccessModule = IEBOAccessModule(vm.envOr('SETUP_ADDRESS_EBOAccessModule', address(0)));
eboRequestCreator = IEBORequestCreator(vm.envOr('SETUP_ADDRESS_EBORequestCreator', address(0)));
}

// check if the request creator has been instantiated
if (address(eboRequestCreator) == address(0)) {
return false;
}

_labelContracts();
return true;
}

function setupDemo() public {
// if contracts aren't loaded, we deploy them for the demo
if (!_loadContracts()) {
deploy();
}
setupBalances();
setupAgent();

// demo start
}

function all() public {
deploy();
setupDemo();
go();
}

function go() public {
if (!_loadContracts()) {
return;
}

console.log(eboRequestCreator.START_EPOCH());
console.log(eboRequestCreator.epochManager().currentEpoch());
vm.startBroadcast(agent);
// uint256 _epoch = epochManager.currentEpoch();
// return;
console.log(address(eboRequestCreator.epochManager()));
string memory chainId = string.concat('eip155:421614');
console.log('chainId', chainId);
(IOracle.Request memory _request, bytes32 _requestId) = _create();

IAccessController.AccessControl memory _selfAC = IAccessController.AccessControl({user: agent, data: bytes('')});

IOracle.Response memory _goodResponse =
IOracle.Response({proposer: agent, requestId: _requestId, response: bytes('good-data')});
IOracle.Response memory _badResponse =
IOracle.Response({proposer: agent, requestId: _requestId, response: bytes('bad-data')});
oracle.proposeResponse(_request, _badResponse, _selfAC);

IOracle.Dispute memory _dispute = IOracle.Dispute({
disputer: agent,
proposer: agent,
requestId: _requestId,
responseId: keccak256(abi.encode(_badResponse))
});
oracle.disputeResponse(_request, _badResponse, _dispute, _selfAC);

vm.stopBroadcast();
}

function _create() internal returns (IOracle.Request memory, bytes32) {
string memory chainId = string.concat('eip155:421614');
uint256 epoch = epochManager.currentEpoch();
console.log('current epoch', epoch);

vm.recordLogs();

// This is bugged due to a problem in arbitrum block.number estimation in Anvil.
eboRequestCreator.createRequest(epochManager.currentEpoch(), chainId);

Vm.Log[] memory entries = vm.getRecordedLogs();
// assert we only have two events emitted
assert(entries.length == 2);
assert(entries[1].emitter == address(eboRequestCreator));

// decode the full IOracle.Request
bytes32 _requestId = entries[1].topics[1];
(IOracle.Request memory _request) = abi.decode(entries[1].data, (IOracle.Request));
assert(_requestId == keccak256(abi.encode(_request)));
Expand All @@ -375,21 +295,11 @@ contract Deploy is Script {
return (_request, _requestId);
}

function _proposeResponse(
IOracle.Request memory _request,
IOracle.Response memory _response,
IAccessController.AccessControl memory _ac
) internal returns (IOracle.Response memory, bytes32) {
console.log('Proposing bad response');
return (_response, oracle.proposeResponse(_request, _response, _ac));
}

function _instantiateRequestData() internal view returns (IOracle.Request memory _requestData) {
// Set placeholder nonce
_requestData.nonce = 0;

// Set requester and modules

_requestData.requester = address(eboRequestCreator);
_requestData.accessModule = address(eboAccessModule);
_requestData.requestModule = address(eboRequestModule);
Expand Down Expand Up @@ -463,4 +373,17 @@ contract Deploy is Script {
// Precompute address of the target deployment
_targetAddress = vm.computeCreateAddress(tx.origin, _targetNonce);
}

function _labelContracts() internal {
// convert to a loop?
vm.label(address(oracle), 'Oracle');
vm.label(address(eboAccessModule), 'eboAccessModule');
vm.label(address(eboRequestModule), 'RequestModule');
vm.label(address(bondedResponseModule), 'bondedResponseModule');
vm.label(address(bondEscalationModule), 'bondEscalationModule');
vm.label(address(eboRequestCreator), 'EBORequestCreator');
vm.label(address(graphToken), 'GraphToken');
vm.label(address(horizonStaking), 'HorizonStaking');
vm.label(address(epochManager), 'EpochManager');
}
}

0 comments on commit 119c897

Please sign in to comment.