/ deployment / deploy.js
deploy.js
1 import { ethers, Contract, ContractFactory, Wallet } from "ethers"; 2 import priceOracleArtifact from "../out/PriceOracle.sol/PriceOracle.json" assert { type: 'json' }; 3 import gasBrokerArtifact from "../out/GasBroker.sol/GasBroker.json" assert { type: 'json' }; 4 import fundUSDCArtifact from "../out/FundUSDC.sol/FundUSDC.json" assert { type: 'json' }; 5 import config from "./config.js"; 6 7 const { PROVIDER_URL, SIGNER_PRIVATE_KEY, CUSTOMER_ADDRESS } = config; 8 9 10 const CHAIN_ID = 137; 11 const ONE_ETH = 10n ** 18n; 12 13 const provider = new ethers.providers.JsonRpcProvider(PROVIDER_URL); 14 const signer = new Wallet(SIGNER_PRIVATE_KEY, provider); 15 const USDC = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"; 16 17 const ERC20abi = [ 18 "function balanceOf(address) external view returns (uint256)", 19 "function transfer(address, uint256) external returns (bool)" 20 ] 21 const usdcContract = new Contract(USDC, ERC20abi, provider); 22 23 24 async function setUp() { 25 const priceOracleContract = await deployContract('PriceOracle', priceOracleArtifact); 26 const priceOracleAddress = priceOracleContract.address; 27 28 await deployContract('GasBroker', gasBrokerArtifact, CHAIN_ID, priceOracleAddress); 29 30 const fundUSDCcontract = await deployContract('FundUSDC', fundUSDCArtifact); 31 32 //fund wallet with USDC 33 let tx = await fundUSDCcontract.swapExactOutputSingle(10e6, 100n*ONE_ETH, { value: 100n*ONE_ETH }); 34 await tx.wait(); 35 36 console.log(`Deployer USDC ballance is ${await usdcContract.balanceOf(signer.address)}`); 37 tx = await usdcContract.connect(signer).transfer(CUSTOMER_ADDRESS, 10e6); 38 await tx.wait(); 39 console.log(`Customer USDC ballance is ${await usdcContract.balanceOf(CUSTOMER_ADDRESS)}`); 40 console.log(`Customer ETH ballance is ${await provider.getBalance(CUSTOMER_ADDRESS)}`); 41 42 } 43 44 async function deployContract(name, artifact, ...constructorArgs) { 45 const { abi, bytecode } = artifact 46 const factory = new ContractFactory(abi, bytecode, signer); 47 const contract = await factory.deploy(...constructorArgs); 48 await contract.deployTransaction.wait(); 49 console.log(`Contract ${name} deployed at address ${await contract.address}`); 50 return contract; 51 } 52 53 setUp(); 54