Skip to content

Commit

Permalink
chore: use paymaster and redeploy USDC to mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
fedealconada committed Dec 5, 2024
1 parent 809dd6d commit 48af514
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 14 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ by the [Hardhat](https://hardhat.org/) framework.
- [TypeScript type definition files for the contracts](#typescript-type-definition-files-for-the-contracts)
- [Linting and Formatting](#linting-and-formatting)
- [Testing](#testing)
- [ZK Sync Deployment](#zk-sync-deployment)
- [Deployment](#deployment)
- [Contracts](#contracts)
- [FiatToken features](#fiattoken-features)
Expand Down Expand Up @@ -117,7 +118,7 @@ To check the size of contracts in the repo, run the following command.
$ yarn contract-size # Ignores tests
```

## Deployment
## ZK Sync Deployment

1. Create a copy of the file `.env.example`, and name it `.env`. Fill in
appropriate values in the `.env` file. This file must not be checked into the
Expand Down Expand Up @@ -156,6 +157,45 @@ yarn forge:broadcast scripts/deploy/deploy-fiat-token.s.sol --rpc-url <testnet O
yarn forge:verify scripts/deploy/deploy-fiat-token.s.sol --rpc-url <testnet OR mainnet>
```

## Deployment

1. Create a copy of the file `.env.example`, and name it `.env`. Fill in
appropriate values in the `.env` file. This file must not be checked into the
repository.

```sh
cp .env.example .env
```

2. Create a `blacklist.remote.json` file and populate it with a list of
addresses to be blacklisted. This file must not be checked into the
repository.

```sh
echo "[]" > blacklist.remote.json
```

3. Deploy Signature Checker

```
yarn forge:deploySignatureChecker --rpc-url <testnet OR mainnet>
```

3. Update SIGNATURE_CHECKER_ADDRESS on .env file with the deployed address.

4. Deploy rest of the contracts by running the following command

```sh
yarn forge:broadcastAndVerify scripts/deploy/deploy-fiat-token.s.sol --rpc-url <testnet OR mainnet>
```

1. Verify the contracts on an Etherscan flavored block explorer by running the
following command. Ensure that `ETHERSCAN_KEY` is set in the `.env` file.

```sh
yarn forge:verify scripts/deploy/deploy-fiat-token.s.sol --rpc-url <testnet OR mainnet>
```

## Contracts

The FiatToken contracts adheres to OpenZeppelin's
Expand Down
8 changes: 4 additions & 4 deletions deployments/50104/addresses.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"SignatureChecker": "0xB6494A881006f9C629b0C6a2f57D6d7d41D0bd9A",
"FiatTokenV2_2-impl": "0x35186A46aF280F11E02d2D055b5bf3511562031e",
"FiatTokenV2_2": "0x0f5450df41ea983f4de1de52dd9246e6142be411",
"MasterMinter": "0x2b5392D63Ac0e9c51f72d9e46113DDCc27d12911"
"SignatureChecker": "0xb0A2cf27Bf984bd0c56dCFb37C9DA0F2c5028844",
"FiatTokenV2_2-impl": "0x3E1FCbA109574C17be3053B242BD417A10f29655",
"FiatTokenV2_2": "0x9Aa0F72392B5784Ad86c6f3E899bCc053D00Db4F",
"MasterMinter": "0x4c79285e25c6b9b4c16588a69d2b248624964691"
}
9 changes: 8 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cache_path = "cache/foundry"
script = "scripts"
evm_version = "istanbul"
optimizer_runs = 10000000
solc_version = "0.6.12"
libs = [
"lib",
"node_modules",
Expand All @@ -38,6 +39,12 @@ extra-output-files = [
"metadata"
]

[profile.default.zksync]
zksolc = "1.3.19"
optimizer = true
optimizer_mode = "3"


[rpc_endpoints]
testnet = "${TESTNET_RPC_URL}"
mainnet = "${MAINNET_RPC_URL}"
Expand All @@ -46,4 +53,4 @@ mainnet = "${MAINNET_RPC_URL}"
testnet = { key = "${ETHERSCAN_API_KEY}", url = "${TESTNET_VERIFIER_URL}", chain = 531050104 }
mainnet = { key = "${ETHERSCAN_API_KEY}", url = "${MAINNET_VERIFIER_URL}", chain = 50104 }
etherscanTestnet = { key = "${ETHERSCAN_API_KEY}", url = "${TESTNET_ETHERSCAN_VERIFIER_URL}", chain = 531050104 }
etherscanMainnet = { key = "${ETHERSCAN_API_KEY}", url = "${MAINNET_ETHERSCAN_VERIFIER_URL}", chain = 50104 }
etherscanMainnet = { key = "${ETHERSCAN_API_KEY}", url = "${MAINNET_ETHERSCAN_VERIFIER_URL}", chain = 50104 }
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"test": "test"
},
"scripts": {
"compile": "hardhat compile && forge build --zksync && ./flatten-generated-types.sh",
"compile": "hardhat compile && forge build --zksync --libraries ./contracts/util/SignatureChecker.sol:SignatureChecker:$(dotenv -p SIGNATURE_CHECKER_ADDRESS) && ./flatten-generated-types.sh",
"contract-size": "hardhat size-contracts",
"coverage": "hardhat coverage",
"forge:simulate": "forge script -vv --gas-estimate-multiplier $(dotenv -p GAS_MULTIPLIER) -vvvv --libraries ./contracts/util/SignatureChecker.sol:SignatureChecker:$(dotenv -p SIGNATURE_CHECKER_ADDRESS) --slow --zksync",
"forge:broadcast": "yarn forge:simulate --broadcast --slow",
"forge:simulate": "forge script -vvvv --gas-estimate-multiplier $(dotenv -p GAS_MULTIPLIER) -vvvv --libraries ./contracts/util/SignatureChecker.sol:SignatureChecker:$(dotenv -p SIGNATURE_CHECKER_ADDRESS) --zksync",
"forge:broadcast": "yarn forge:simulate --broadcast --private-key $(dotenv -p DEPLOYER_PRIVATE_KEY) --slow --skip-simulation",
"forge:resume": "yarn forge:broadcast --resume",
"forge:broadcastAndVerify": "yarn forge:broadcast --verify --etherscan-api-key $(dotenv -p ETHERSCAN_KEY)",
"forge:verify": "yarn forge:simulate --verify --resume --etherscan-api-key $(dotenv -p ETHERSCAN_KEY) --private-key $(dotenv -p DEPLOYER_PRIVATE_KEY)",
"forge:broadcastAndVerify": "yarn forge:broadcast --verify",
"forge:deploySignatureChecker": "forge script ./scripts/deploy/deploy-signature-checker.s.sol -vvvv --gas-estimate-multiplier $(dotenv -p GAS_MULTIPLIER) -vvvv --zksync --broadcast --private-key $(dotenv -p DEPLOYER_PRIVATE_KEY) --slow --skip-simulation --verify",
"forge:verify": "yarn forge:simulate --verify --resume --etherscan-api-key $(dotenv -p ETHERSCAN_API_KEY) --private-key $(dotenv -p DEPLOYER_PRIVATE_KEY)",
"fmt:base": "prettier './**/*.sol' './**/*.js' './**/*.ts' './**/*.json' './**/*.md'",
"fmt:check": "yarn fmt:base --check",
"fmt": "yarn fmt:base --write",
Expand Down
26 changes: 25 additions & 1 deletion scripts/deploy/DeployImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ import { FiatTokenV2_2 } from "../../contracts/v2/FiatTokenV2_2.sol";
import {
FiatTokenCeloV2_2
} from "../../contracts/v2/celo/FiatTokenCeloV2_2.sol";
import { Script } from "forge-std/Script.sol";

/**
* @notice A utility contract that exposes a re-useable getOrDeployImpl function.
*/
contract DeployImpl {
contract DeployImpl is Script {
address private immutable THROWAWAY_ADDRESS = address(1);

function _usePaymaster() internal {
address paymaster = vm.envAddress("PAYMASTER_ADDRESS");

// Use paymaster
bytes memory paymaster_encoded_input = abi.encodeWithSelector(
bytes4(keccak256("general(bytes)")),
bytes("0x")
);
(bool success, ) = address(vm).call(
abi.encodeWithSignature(
"zkUsePaymaster(address,bytes)",
paymaster,
paymaster_encoded_input
)
);
require(success, "zkUsePaymaster() call failed");
}

/**
* @notice helper function that either
* 1) deploys the implementation contract if the input is the zero address, or
Expand All @@ -41,12 +60,14 @@ contract DeployImpl {
FiatTokenV2_2 fiatTokenV2_2;

if (impl == address(0)) {
_usePaymaster();
fiatTokenV2_2 = new FiatTokenV2_2();

// Initializing the implementation contract with dummy values here prevents
// the contract from being reinitialized later on with different values.
// Dummy values can be used here as the proxy contract will store the actual values
// for the deployed token.
_usePaymaster();
fiatTokenV2_2.initialize(
"",
"",
Expand All @@ -57,8 +78,11 @@ contract DeployImpl {
THROWAWAY_ADDRESS,
THROWAWAY_ADDRESS
);
_usePaymaster();
fiatTokenV2_2.initializeV2("");
_usePaymaster();
fiatTokenV2_2.initializeV2_1(THROWAWAY_ADDRESS);
_usePaymaster();
fiatTokenV2_2.initializeV2_2(new address[](0), "");
} else {
fiatTokenV2_2 = FiatTokenV2_2(impl);
Expand Down
11 changes: 10 additions & 1 deletion scripts/deploy/deploy-fiat-token.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ contract DeployFiatToken is Script, DeployImpl {
blacklister = vm.envOr("BLACKLISTER_ADDRESS", owner);

deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
// paymaster = vm.envAddress("PAYMASTER_ADDRESS");

console.log("TOKEN_NAME: '%s'", tokenName);
console.log("TOKEN_SYMBOL: '%s'", tokenSymbol);
Expand Down Expand Up @@ -100,24 +101,29 @@ contract DeployFiatToken is Script, DeployImpl {
// Otherwise, deploy the latest implementation contract code to the network.
FiatTokenV2_2 fiatTokenV2_2 = getOrDeployImpl(_impl);

_usePaymaster();
FiatTokenProxy proxy = new FiatTokenProxy(address(fiatTokenV2_2));

// Now that the proxy contract has been deployed, we can deploy the master minter.
// // Now that the proxy contract has been deployed, we can deploy the master minter.
_usePaymaster();
MasterMinter masterMinter = new MasterMinter(address(proxy));

// Change the master minter to be owned by the master minter owner
_usePaymaster();
masterMinter.transferOwnership(masterMinterOwner);

// Now that the master minter is set up, we can go back to setting up the proxy and
// implementation contracts.
// Need to change admin first, or the call to initialize won't work
// since admin can only call methods in the proxy, and not forwarded methods
_usePaymaster();
proxy.changeAdmin(proxyAdmin);

// Do the initial (V1) initialization.
// Note that this takes in the master minter contract's address as the master minter.
// The master minter contract's owner is a separate address.
FiatTokenV2_2 proxyAsV2_2 = FiatTokenV2_2(address(proxy));
_usePaymaster();
proxyAsV2_2.initialize(
tokenName,
tokenSymbol,
Expand All @@ -130,12 +136,15 @@ contract DeployFiatToken is Script, DeployImpl {
);

// Do the V2 initialization
_usePaymaster();
proxyAsV2_2.initializeV2(tokenName);

// Do the V2_1 initialization
_usePaymaster();
proxyAsV2_2.initializeV2_1(owner);

// Do the V2_2 initialization
_usePaymaster();
proxyAsV2_2.initializeV2_2(new address[](0), tokenSymbol);

vm.stopBroadcast();
Expand Down
22 changes: 21 additions & 1 deletion scripts/deploy/deploy-signature-checker.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,28 @@ import { SignatureChecker } from "../../contracts/util/SignatureChecker.sol";
* To build and link: `forge build --zksync --libraries ./contracts/util/SignatureChecker.sol:SignatureChecker:LIBRARY_ADDRESS`
*/
contract DeployLibrary is Script {
address paymaster;
uint256 deployerPrivateKey;

function run() external {
vm.startBroadcast();
deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
paymaster = vm.envAddress("PAYMASTER_ADDRESS");

vm.startBroadcast(deployerPrivateKey);

// Use paymaster
bytes memory paymaster_encoded_input = abi.encodeWithSelector(
bytes4(keccak256("general(bytes)")),
bytes("0x")
);
(bool success, ) = address(vm).call(
abi.encodeWithSignature(
"zkUsePaymaster(address,bytes)",
paymaster,
paymaster_encoded_input
)
);
require(success, "zkUsePaymaster() call failed");

// Deploy library
new SignatureChecker();
Expand Down

0 comments on commit 48af514

Please sign in to comment.