Skip to content

Commit

Permalink
feat(deploy): Mint tokens to multiple addresses (#552)
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Jun 27, 2024
1 parent db93876 commit 8172969
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
additional_addresses_for_minting = []

[tokens.DAI]
name = "DAI"
symbol = "DAI"
Expand Down
23 changes: 15 additions & 8 deletions l1-contracts/deploy-scripts/DeployErc20.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract DeployErc20Script is Script {
struct Config {
TokenDescription[] tokens;
address deployerAddress;
address[] additionalAddressesForMinting;
address create2FactoryAddr;
bytes32 create2FactorySalt;
}
Expand Down Expand Up @@ -61,6 +62,7 @@ contract DeployErc20Script is Script {
// Grab config from custom config file
path = string.concat(root, "/script-config/config-deploy-erc20.toml");
toml = vm.readFile(path);
config.additionalAddressesForMinting = vm.parseTomlAddressArray(toml, "$.additional_addresses_for_minting");

string[] memory tokens = vm.parseTomlKeys(toml, "$.tokens");

Expand All @@ -72,7 +74,6 @@ contract DeployErc20Script is Script {
token.decimals = toml.readUint(string.concat(key, ".decimals"));
token.implementation = toml.readString(string.concat(key, ".implementation"));
token.mint = toml.readUint(string.concat(key, ".mint"));

config.tokens.push(token);
}
}
Expand All @@ -86,7 +87,8 @@ contract DeployErc20Script is Script {
symbol: token.symbol,
decimals: token.decimals,
implementation: token.implementation,
mint: token.mint
mint: token.mint,
additionalAddressesForMinting: config.additionalAddressesForMinting
});
console.log("Token deployed at:", tokenAddress);
token.addr = tokenAddress;
Expand All @@ -98,7 +100,8 @@ contract DeployErc20Script is Script {
string memory symbol,
uint256 decimals,
string memory implementation,
uint256 mint
uint256 mint,
address[] storage additionalAddressesForMinting
) internal returns (address) {
bytes memory args;
// WETH9 constructor has no arguments
Expand All @@ -112,10 +115,14 @@ contract DeployErc20Script is Script {

if (mint > 0) {
vm.broadcast();
(bool success, ) = tokenAddress.call(
abi.encodeWithSignature("mint(address,uint256)", config.deployerAddress, mint)
);
require(success, "Mint failed");
additionalAddressesForMinting.push(config.deployerAddress);
for (uint256 i = 0; i < additionalAddressesForMinting.length; i++) {
(bool success, ) = tokenAddress.call(
abi.encodeWithSignature("mint(address,uint256)", additionalAddressesForMinting[i], mint)
);
require(success, "Mint failed");
console.log("Minting to:", additionalAddressesForMinting[i]);
}
}

return tokenAddress;
Expand All @@ -129,7 +136,7 @@ contract DeployErc20Script is Script {
vm.serializeString(token.symbol, "symbol", token.symbol);
vm.serializeUint(token.symbol, "decimals", token.decimals);
vm.serializeString(token.symbol, "implementation", token.implementation);
vm.serializeUint(token.symbol, "mint", token.mint);
vm.serializeUintToHex(token.symbol, "mint", token.mint);
string memory tokenInfo = vm.serializeAddress(token.symbol, "address", token.addr);

tokens = vm.serializeString("tokens", token.symbol, tokenInfo);
Expand Down

0 comments on commit 8172969

Please sign in to comment.