Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
deploy (#12)
Browse files Browse the repository at this point in the history
* set ownables to pass in owner; use create2

* deploy

* adjust utils deploymenttype

* tweak

* clean up imports

* fix tests

* fix paymaster deploy tests
  • Loading branch information
coffeexcoin authored Oct 30, 2024
1 parent d4c548b commit b2c88fc
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 49 deletions.
5 changes: 3 additions & 2 deletions contracts/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ contract AccountFactory is Ownable {
address _implementation,
address _registry,
bytes32 _proxyBytecodeHash,
address _deployer
) Ownable(msg.sender) {
address _deployer,
address _owner
) Ownable(_owner) {
implementationAddress = _implementation;
registry = _registry;
proxyBytecodeHash = _proxyBytecodeHash;
Expand Down
2 changes: 1 addition & 1 deletion contracts/ClaveRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract ClaveRegistry is Ownable, IClaveRegistry {
event FactoryUnset(address indexed factory);

// Constructor function of the contracts
constructor() Ownable(msg.sender) {}
constructor(address _owner) Ownable(_owner) {}

/**
* @notice Registers an account as a Clave account
Expand Down
2 changes: 1 addition & 1 deletion contracts/paymasters/ERC20Paymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract ERC20Paymaster is IPaymaster, PrimaryProdDataServiceConsumerBase, Ownab
* @dev Use markup by adding percentage amount to 100, e.g. 10% markup will be 11000
* @dev Make sure to use true decimal values for the tokens, otherwise the conversions will be incorrect
*/
constructor(TokenInput[] memory tokens) Ownable(msg.sender) {
constructor(TokenInput[] memory tokens, address _owner) Ownable(_owner) {
for (uint256 i = 0; i < tokens.length; i++) {
// Decline zero-addresses
if (tokens[i].tokenAddress == address(0)) revert Errors.INVALID_TOKEN();
Expand Down
2 changes: 1 addition & 1 deletion contracts/paymasters/GaslessPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract GaslessPaymaster is IPaymaster, Ownable, BootloaderAuth {
* @param registry address - Clave registry address
* @param limit uint256 - User sponsorship limit
*/
constructor(address registry, uint256 limit) Ownable(msg.sender) {
constructor(address registry, uint256 limit, address _owner) Ownable(_owner) {
claveRegistry = registry;
userLimit = limit;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ERC20PaymasterMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract ERC20PaymasterMock is
* @dev Use markup by adding percentage amount to 100, e.g. 10% markup will be 11000
* @dev Make sure to use true decimal values for the tokens, otherwise the conversions will be incorrect
*/
constructor(TokenInput[] memory tokens) Ownable(msg.sender) {
constructor(TokenInput[] memory tokens, address _owner) Ownable(_owner) {
for (uint256 i = 0; i < tokens.length; i++) {
// Decline zero-addresses
if (tokens[i].tokenAddress == address(0)) revert Errors.INVALID_TOKEN();
Expand Down
57 changes: 20 additions & 37 deletions deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,39 @@
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*/
import type { ec } from 'elliptic';
import {
ZeroAddress,
parseEther,
zeroPadValue
} from 'ethers';
import * as hre from 'hardhat';
import { Contract, Provider, Wallet, utils } from 'zksync-ethers';
import { LOCAL_RICH_WALLETS, deployContract, getWallet, verifyContract } from '../deploy/utils';
import { Contract, Wallet, utils } from 'zksync-ethers';
import { deployContract, getWallet, verifyContract } from '../deploy/utils';
import type { CallStruct } from '../typechain-types/contracts/batch/BatchCaller';
import { genKeyK1, encodePublicKeyK1 } from '../test/utils/p256';
let provider: Provider;
let fundingWallet: Wallet;
let keyPair: ec.KeyPair;

let batchCaller: Contract;
let eoaValidator: Contract;
let implementation: Contract;
let factory: Contract;
let account: Contract;
let registry: Contract;

// An example of a basic deploy script
// Do not push modifications to this file
// Just modify, interact then revert changes
export default async function (): Promise<void> {
provider = new Provider(hre.network.config.url, undefined, {
cacheTimeout: -1,
});

fundingWallet = getWallet(hre);

keyPair = genKeyK1();
const publicKey = encodePublicKeyK1(keyPair);

console.log("authorized signer", publicKey);
const initialOwner = fundingWallet.address;

batchCaller = await deployContract(hre, 'BatchCaller', undefined, {
await deployContract(hre, 'BatchCaller', undefined, {
wallet: fundingWallet,
silent: false,
});
}, 'create');

eoaValidator = await deployContract(hre, 'EOAValidator', undefined, {
wallet: fundingWallet,
silent: false,
});
}, 'create2');

implementation = await deployContract(
hre,
Expand All @@ -58,19 +45,24 @@ export default async function (): Promise<void> {
wallet: fundingWallet,
silent: false,
},
'create2',
);

registry = await deployContract(hre, 'ClaveRegistry', undefined, {
registry = await deployContract(hre, 'ClaveRegistry',
[
initialOwner,
], {
wallet: fundingWallet,
silent: false,
});
}, 'create2');

// Need this so the ClaveProxy artifact is valid
await deployContract(
hre,
'ClaveProxy',
[await implementation.getAddress()],
{ wallet: fundingWallet, silent: true, noVerify: true },
'create2',
);

const accountProxyArtifact = await hre.zksyncEthers.loadArtifact('ClaveProxy');
Expand All @@ -83,23 +75,26 @@ export default async function (): Promise<void> {
await registry.getAddress(),
bytecodeHash,
fundingWallet.address,
initialOwner,
],
{
wallet: fundingWallet,
silent: false,
},
'create2',
);
await registry.setFactory(await factory.getAddress());

const salt = hre.ethers.randomBytes(32);
const abiCoder = hre.ethers.AbiCoder.defaultAbiCoder();
const call: CallStruct = {
target: ZeroAddress,
allowFailure: false,
value: 0,
callData: '0x',
};

const abiCoder = hre.ethers.AbiCoder.defaultAbiCoder();
const salt = initialOwner.padEnd(66, '0');
console.log("salt", salt);
const initializer =
'0xb4e581f5' +
abiCoder
Expand All @@ -111,7 +106,7 @@ export default async function (): Promise<void> {
'tuple(address target,bool allowFailure,uint256 value,bytes calldata)',
],
[
publicKey,
initialOwner,
await eoaValidator.getAddress(),
[],
[call.target, call.allowFailure, call.value, call.callData],
Expand All @@ -123,24 +118,12 @@ export default async function (): Promise<void> {
await tx.wait();

const accountAddress = await factory.getAddressForSalt(salt);

await verifyContract(hre, {
address: accountAddress,
contract: "contracts/ClaveProxy.sol:ClaveProxy",
constructorArguments: zeroPadValue(accountAddress, 32),
bytecode: accountProxyArtifact.bytecode
})
console.log("accountAddress", accountAddress)

// account = new Contract(
// accountAddress,
// implementation.interface,
// fundingWallet,
// );
// // 0.0001 ETH transfered to Account
// await (
// await fundingWallet.sendTransaction({
// to: await account.getAddress(),
// value: parseEther('0.0001'),
// })
// ).wait();
}
5 changes: 4 additions & 1 deletion deploy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '@matterlabs/hardhat-zksync-verify/dist/src/type-extensions';
import { ethers } from 'ethers';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import { Provider, Wallet, utils } from 'zksync-ethers';
import { DeploymentType } from 'zksync-ethers/build/types';

export const getProvider = (hre: HardhatRuntimeEnvironment): Provider => {
const rpcUrl = hre.network.config.url;
Expand Down Expand Up @@ -96,6 +97,8 @@ export const deployContract = async (
contractArtifactName: string,
constructorArguments?: Array<unknown>,
options?: DeployContractOptions,
deploymentType?: DeploymentType,

): Promise<ethers.Contract> => {
const log = (message: string): void => {
if (!options?.silent) console.log(message);
Expand Down Expand Up @@ -133,7 +136,7 @@ export const deployContract = async (
await verifyEnoughBalance(wallet, deploymentFee);

// Deploy the contract to zkSync
const contract = await deployer.deploy(artifact, constructorArguments);
const contract = await deployer.deploy(artifact, constructorArguments, deploymentType);
const address = await contract.getAddress();
const constructorArgs =
contract.interface.encodeDeploy(constructorArguments);
Expand Down
5 changes: 4 additions & 1 deletion test/paymasters/gaslesspaymaster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ describe('Clave Contracts - Gasless Paymaster tests', () => {
await erc20.mint(accountAddress, parseEther('100000'));

gaslessPaymaster = await deployer.paymaster(PAYMASTERS.GASLESS, {
gasless: [await registry.getAddress(), 3],
gasless: {
registryAddress: await registry.getAddress(),
limit: 3
},
});

await deployer.fund(50, await gaslessPaymaster.getAddress());
Expand Down
15 changes: 11 additions & 4 deletions test/utils/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ClaveDeployer {
return await deployContract(
this.hre,
CONTRACT_NAMES.REGISTRY,
undefined,
[this.deployerWallet.address],
{
wallet: this.deployerWallet,
silent: true,
Expand Down Expand Up @@ -91,6 +91,7 @@ export class ClaveDeployer {
await registry.getAddress(),
bytecodeHash,
this.deployerWallet.address,
this.deployerWallet.address,
],
{
wallet: this.deployerWallet,
Expand Down Expand Up @@ -197,8 +198,11 @@ export class ClaveDeployer {

public async paymaster(
name: PAYMASTERS,
config: {
gasless?: [registryAddress: string, limit: number];
config: {
gasless?: {
registryAddress: string,
limit: number
};
erc20?: Array<{
tokenAddress: string;
decimals: number;
Expand All @@ -217,7 +221,10 @@ export class ClaveDeployer {
return await deployContract(
this.hre,
name,
name == PAYMASTERS.GASLESS ? config.gasless : [config.erc20],
[
...Object.values(name == PAYMASTERS.GASLESS ? config.gasless! : [config.erc20!]),
this.deployerWallet.address,
],
{
wallet: this.deployerWallet,
silent: true,
Expand Down

0 comments on commit b2c88fc

Please sign in to comment.