Skip to content

Commit

Permalink
feat: remove demo related functions out of the deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Nov 26, 2024
1 parent 8f2addf commit 1864b91
Showing 1 changed file with 2 additions and 109 deletions.
111 changes: 2 additions & 109 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,7 @@ contract Deploy is Script {
uint256 public tyingBuffer;
uint256 public disputeDisputeWindow;

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

error Deploy_InvalidPrecomputedAddress();
error Deploy_DeployerNotEnoughBalance();

address deployer;
address agent;

function setUp() public virtual {
// Define The Graph accounts
Expand All @@ -122,15 +114,10 @@ contract Deploy is Script {
disputeDeadline = 10 days;
tyingBuffer = 3 days;
disputeDisputeWindow = 2 weeks;

deployer = vm.rememberKey(vm.envUint('DEPLOYER_PRIVATE_KEY'));
agent = vm.rememberKey(vm.envUint('AGENT_PRIVATE_KEY'));
vm.label(deployer, 'deployer');
vm.label(agent, 'agent');
}

function deploy() public {
vm.startBroadcast(deployer);
vm.startBroadcast();

// Precompute address of `EBORequestCreator`
IEBORequestCreator _precomputedEBORequestCreator =
Expand Down Expand Up @@ -167,7 +154,6 @@ contract Deploy is Script {

// Deploy `HorizonAccountingExtension`
address[] memory _authorizedCallers = _instantiateAuthorizedCallers();
_authorizedCallers[0] = address(bondedResponseModule);

horizonAccountingExtension = new HorizonAccountingExtension({
_horizonStaking: horizonStaking,
Expand Down Expand Up @@ -199,102 +185,9 @@ contract Deploy is Script {

vm.stopBroadcast();

setupEBO();

_labelContracts();
}

function setupBalances() public {
// deployer funds agent
vm.startBroadcast(deployer);

uint256 _balanceD = address(deployer).balance;
console.log('deployer balance', _balanceD / 1e18);
if (_balanceD < NOT_ENOUGH_BALANCE) {
revert Deploy_DeployerNotEnoughBalance();
}
uint256 _balanceA = address(agent).balance;
if (_balanceA < NOT_ENOUGH_BALANCE) {
agent.call{value: ENOUGH_BALANCE}('');
console.log('agent balance from %d to %d', _balanceA / 1e18, agent.balance / 1e18);
} else {
console.log('agent balance', address(agent).balance / 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 {
vm.startBroadcast(deployer);

eboRequestModule.addEBORequestCreator(eboRequestCreator);

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

vm.stopBroadcast();
}

function setupAgent() public {
/// agent setup
vm.startBroadcast(agent);

horizonAccountingExtension.GRT().approve(address(horizonAccountingExtension.HORIZON_STAKING()), 20e18);
horizonAccountingExtension.HORIZON_STAKING().stake(1e18);
// approve EBO modules in HAE
horizonAccountingExtension.approveModule(address(bondEscalationModule));
horizonAccountingExtension.approveModule(address(bondedResponseModule));

horizonAccountingExtension.HORIZON_STAKING().provision(
agent,
address(horizonAccountingExtension),
1e18,
horizonAccountingExtension.MAX_VERIFIER_CUT(),
horizonAccountingExtension.MIN_THAWING_PERIOD()
);
// horizonAccountingExtension.HORIZON_STAKING().addToProvision(agent, address(horizonAccountingExtension), 0.5e18);

vm.stopBroadcast();
}

function setupDemo() public {
setupBalances();
setupAgent();
}

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

function _create() internal returns (IOracle.Request memory, bytes32) {
string memory chainId = string.concat('eip155:421614');

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)));

console.log('request id');
console.logBytes32(_requestId);

return (_request, _requestId);
}

function _instantiateRequestData() internal view returns (IOracle.Request memory _requestData) {
// Set placeholder nonce
_requestData.nonce = 0;
Expand Down Expand Up @@ -363,7 +256,7 @@ contract Deploy is Script {
}

function _instantiateAuthorizedCallers() internal view returns (address[] memory _authorizedCallers) {
_authorizedCallers = new address[](2);
_authorizedCallers = new address[](1);
_authorizedCallers[0] = address(bondEscalationModule);
}

Expand Down

0 comments on commit 1864b91

Please sign in to comment.