Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: create foundry deployment scripts #89

Closed
wants to merge 32 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b1b6367
feat: add disputer contract, scripts and tests
nlecoufl Oct 25, 2024
a70fa12
chore: uniformize hardhat config accounts
nlecoufl Oct 28, 2024
0f9b66e
feat: handle infinite approval & format headers
nlecoufl Oct 28, 2024
99f9376
scripts: skip some chains
nlecoufl Oct 30, 2024
b0894b2
fix: dispute test
nlecoufl Nov 4, 2024
bd948c7
feat: add whitelisted addresses
nlecoufl Nov 4, 2024
bf452ae
fix: deployer address
Picodes Nov 4, 2024
cc37f37
chore: deployments
Picodes Nov 4, 2024
1ba3b4b
feat: add set distributor and owner scripts
nlecoufl Nov 4, 2024
6418975
feat: add normal deploy Disputer script
nlecoufl Nov 4, 2024
9eb6140
fix: set correctly owner and deployer of disputer
nlecoufl Nov 4, 2024
289b1e4
refactor: revert owner to deployer
nlecoufl Nov 4, 2024
df5e203
feat: import CoreBorrow contract
nlecoufl Nov 14, 2024
9a9eb0f
feat: add foundry deploy scripts
nlecoufl Nov 14, 2024
cb25940
Merge branch 'feat/disputer' into refactor/deployment
nlecoufl Nov 14, 2024
094165e
wip: prepare sdk bump
nlecoufl Nov 17, 2024
37ad4bd
feat: bump sdk
nlecoufl Nov 18, 2024
ce8b427
feat: add setters to deploy script
nlecoufl Nov 18, 2024
aa2c067
feat: add fund disputer whitelist script
nlecoufl Nov 18, 2024
5b2a55e
feat: add mintAgla script
nlecoufl Nov 19, 2024
2336c92
feat: add deployCreateX script
nlecoufl Nov 20, 2024
5f69c90
feat: update merklDeploy script
nlecoufl Nov 20, 2024
ddf53c2
feat: add some control on deployer address and multisig address
nlecoufl Nov 20, 2024
ac40793
feat: verify createX is deployed
nlecoufl Nov 20, 2024
0c2b2ec
feat: deploy script improvements
nlecoufl Nov 21, 2024
b760b03
refactor: create transferInitialFunds function for better readability
nlecoufl Nov 22, 2024
c0397f7
fix: initialize core args
nlecoufl Nov 22, 2024
ae03b27
fix: add missing merkl deployer in funding
nlecoufl Nov 22, 2024
8557c31
chore: update foundry.toml
nlecoufl Nov 22, 2024
d73c9ed
feat: remove CreateX deployment from main script
nlecoufl Nov 29, 2024
178f501
feat: add Distributor, DistributorCreator and Disputer scripts
nlecoufl Nov 29, 2024
28896dc
refactor: improve scripts
nlecoufl Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: create transferInitialFunds function for better readability
nlecoufl committed Nov 22, 2024
commit b760b03f2b7204ca4ee4ac7d4dd2f23e67ce69a8
94 changes: 53 additions & 41 deletions deploy/foundry/merklDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -52,8 +52,6 @@ contract MainDeployScript is Script, JsonReader, TokensUtils, CreateXConstants {
address public MERKL_DEPLOYER_ADDRESS;
address public DISPUTE_TOKEN;

JsonReader public reader;

struct DeploymentAddresses {
address proxy;
address implementation;
@@ -130,33 +128,11 @@ contract MainDeployScript is Script, JsonReader, TokensUtils, CreateXConstants {
// 1. Deploy using DEPLOYER_PRIVATE_KEY
vm.startBroadcast(DEPLOYER_PRIVATE_KEY);

// Check if deployer has enough balance to transfer to KEEPER, DUMPER, DISPUTER_WHITELIST and CreateX deployer
if (
DEPLOYER_ADDRESS.balance <
FUND_AMOUNT * (2 + DISPUTER_WHITELIST.length + (CREATEX.code.length == 0 ? 1 : 0))
) {
revert(
"DEPLOYER_ADDRESS does not have enough balance to transfer to KEEPER, DUMPER, DISPUTER_WHITELIST and CreateX deployer, please fund the deployer and check FUND_AMOUNT if needed"
);
}

// Transfer funds to KEEPER, DUMPER and DISPUTER_WHITELIST
address[] memory recipients = new address[](2 + DISPUTER_WHITELIST.length);
recipients[0] = KEEPER;
recipients[1] = DUMPER;
for (uint256 i = 0; i < DISPUTER_WHITELIST.length; i++) {
recipients[i + 2] = DISPUTER_WHITELIST[i];
}

uint256[] memory amounts = new uint256[](2 + DISPUTER_WHITELIST.length);
amounts[0] = FUND_AMOUNT;
amounts[1] = FUND_AMOUNT;
for (uint256 i = 0; i < DISPUTER_WHITELIST.length; i++) {
amounts[i + 2] = FUND_AMOUNT;
}
// Transfer initial funds to required addresses
transferInitialFunds();

console.log("Transferring to KEEPER, DUMPER and DISPUTER_WHITELIST native tokens:", FUND_AMOUNT);
transferNativeTokens(recipients, amounts);
// Deploy CreateX (if contract not found on this chain)
deployCreateX();

// Deploy ProxyAdmin
address proxyAdmin = deployProxyAdmin();
@@ -165,12 +141,6 @@ contract MainDeployScript is Script, JsonReader, TokensUtils, CreateXConstants {
// Deploy AglaMerkl
address aglaMerkl = deployAglaMerkl();

// If needed, send funds to CreateX deployer and deploy CreateX
if (CREATEX.code.length == 0) {
transferNativeTokens(CREATEX_DEPLOYER, FUND_AMOUNT); // recommended by https://github.com/pcaversaccio/createx to send FUND_AMOUNT to the deployer
deployCreateX();
}

vm.stopBroadcast();

// 2. Deploy using MERKL_DEPLOYER_PRIVATE_KEY
@@ -365,13 +335,15 @@ contract MainDeployScript is Script, JsonReader, TokensUtils, CreateXConstants {
}

function deployCreateX() public returns (address) {
console.log("\n=== Deploying CreateX ===");
// Deploy the contract using the provided bytecode (see https://github.com/pcaversaccio/createx/blob/main/scripts/presigned-createx-deployment-transactions/signed_serialised_transaction_gaslimit_3000000_.json)
// Broadcast the raw transaction
vm.broadcastRawTransaction(CREATEX_RAW_RX);
if (CREATEX.code.length != 0) {
console.log("CreateX:", CREATEX);
} else console.log("Failed to deploy CreateX");
if (CREATEX.code.length == 0) {
console.log("\n=== Deploying CreateX ===");
// Deploy the contract using the provided bytecode (see https://github.com/pcaversaccio/createx/blob/main/scripts/presigned-createx-deployment-transactions/signed_serialised_transaction_gaslimit_3000000_.json)
// Broadcast the raw transaction
vm.broadcastRawTransaction(CREATEX_RAW_RX);
if (CREATEX.code.length != 0) {
console.log("CreateX:", CREATEX);
} else console.log("Failed to deploy CreateX");
}
}

/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -455,4 +427,44 @@ contract MainDeployScript is Script, JsonReader, TokensUtils, CreateXConstants {
if (EXPECTED_DISTRIBUTION_CREATOR_PROXY_ADDRESS != vm.computeCreateAddress(MERKL_DEPLOYER_ADDRESS, 4))
revert("DISTRIBUTION_CREATOR_PROXY_ADDRESS_MISMATCH");
}

function transferInitialFunds() internal {
console.log("\n=== Transferring initial funds ===");

// Calculate total recipients including KEEPER, DUMPER, DISPUTER_WHITELIST and optionally CreateX deployer
uint256 transferLength = 2 + DISPUTER_WHITELIST.length + (CREATEX.code.length == 0 ? 1 : 0);

// Check deployer balance
if (DEPLOYER_ADDRESS.balance < FUND_AMOUNT * transferLength) {
revert(
"DEPLOYER_ADDRESS does not have enough balance to transfer to KEEPER, DUMPER, DISPUTER_WHITELIST and CreateX deployer, please fund the deployer and check FUND_AMOUNT if needed"
);
}

// Prepare recipient and amount arrays
address[] memory recipients = new address[](transferLength);
uint256[] memory amounts = new uint256[](transferLength);

// Add KEEPER and DUMPER
recipients[0] = KEEPER;
recipients[1] = DUMPER;
amounts[0] = FUND_AMOUNT;
amounts[1] = FUND_AMOUNT;

// Add DISPUTER_WHITELIST
for (uint256 i = 0; i < DISPUTER_WHITELIST.length; i++) {
recipients[i + 2] = DISPUTER_WHITELIST[i];
amounts[i + 2] = FUND_AMOUNT;
}

// Add CreateX deployer if needed
if (CREATEX.code.length == 0) {
recipients[transferLength - 1] = CREATEX_DEPLOYER;
amounts[transferLength - 1] = FUND_AMOUNT;
}

console.log("Transferring funds to required addresses:", FUND_AMOUNT);
console.log("Total amount transferred:", FUND_AMOUNT * transferLength);
transferNativeTokens(recipients, amounts);
}
}