diff --git a/deploy/001.ts b/deploy/001.ts index a5b4998..819da77 100644 --- a/deploy/001.ts +++ b/deploy/001.ts @@ -1,6 +1,12 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { DeployFunction } from "hardhat-deploy/types"; +import { + DeployFunction, + DeployOptions, + DeployResult, +} from "hardhat-deploy/types"; +import { MockERC20Dec18, EntitiesRegistry } from "../typechain"; +import { ethers } from "hardhat"; import { kindsArr, eip712name, @@ -9,8 +15,56 @@ import { protocolFee, retailerFee, minDeposit, + createSupplierId, + kinds, } from "../utils"; +const setupToken = async ( + proxySettings: { owner: string; proxyContract: string }, + owner: string, + deploy: (name: string, options: DeployOptions) => Promise, + name: string, + contractName: string, + tokenName: string, + tokenSymbol: string, + networkName: string +): Promise => { + const options: DeployOptions = { + contract: contractName, + proxy: { + ...proxySettings, + execute: { + methodName: "initialize", + args: [tokenName, tokenSymbol, owner], + }, + }, + from: owner, + log: true, + autoMine: true, + }; + const token = await deploy(name, options); + + if (token.newlyDeployed) { + console.log( + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + `${tokenSymbol} token deployed at ${token.address} using ${token.receipt?.gasUsed} gas` + ); + } + + if (networkName === "hardhat") { + const tokenContract = await ethers.getContract(name); + const signer = await ethers.getSigner(owner); + tokenContract.connect(signer); + await Promise.all( + ["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"].map((addr) => + tokenContract.mint(addr, "1000000000000000000000000") + ) + ); + } + + return token; +}; + const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { network, deployments, getNamedAccounts } = hre; @@ -26,6 +80,56 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { proxyContract: "OpenZeppelinTransparentProxy", }; + // Setup testing stable coins + + // STABLE Decimals 6 no permit + await setupToken( + PROXY_SETTINGS_WITH_UPGRADE, + owner, + deploy, + "STABLE6", + "MockERC20Dec6", + "Stable6NoPermit", + "STABLE6", + network.name + ); + + // STABLE Decimals 6 with permit + await setupToken( + PROXY_SETTINGS_WITH_UPGRADE, + owner, + deploy, + "STABLE6PERMIT", + "MockERC20Dec6Permit", + "Stable6Permit", + "STABLE6PERMIT", + network.name + ); + + // STABLE Decimals 18 no permit + await setupToken( + PROXY_SETTINGS_WITH_UPGRADE, + owner, + deploy, + "STABLE18", + "MockERC20Dec18", + "Stable18NoPermit", + "STABLE18", + network.name + ); + + // STABLE Decimals 18 with permit + await setupToken( + PROXY_SETTINGS_WITH_UPGRADE, + owner, + deploy, + "STABLE18PERMIT", + "MockERC20Dec18Permit", + "Stable18Permit", + "STABLE18PERMIT", + network.name + ); + // Simple ERC20 token const erc20 = await deploy("MockERC20Dec18", { proxy: { @@ -66,6 +170,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `MockERC20Dec18Permit (lif) was deployed at: ${lif.address} using ${lif.receipt?.gasUsed} gas` ); + + if (network.name === "hardhat") { + const lifContract = ( + await ethers.getContract("MockERC20Dec18Permit") + ); + const signer = await ethers.getSigner(owner); + lifContract.connect(signer); + await Promise.all( + ["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"].map((addr) => + lifContract.mint(addr, "1000000000000000000000000") + ) + ); + } } // Protocol Config @@ -117,6 +234,47 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `EntitiesRegistry was deployed at: ${entities.address} using ${entities.receipt?.gasUsed} gas` ); + + if (network.name === "hardhat") { + const supplierOwner = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; + const supplierSalt = + "0x4c51462692236a1cc8dcde78386cb02a1a59828a92932336770a08cae542c2e8"; + const supplierId = createSupplierId( + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + supplierSalt + ); + + const entities = ( + await ethers.getContract("EntitiesRegistry") + ); + const signer = await ethers.getSigner(owner); + entities.connect(signer); + + await entities.register( + kinds.supplier, + supplierSalt, + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" + ); + console.log(`Registered supplier #${supplierId}`); + + const supplierSigner = await ethers.getSigner(supplierOwner); + entities.connect(supplierSigner); + + const lifContract = ( + await ethers.getContract("MockERC20Dec18Permit") + ); + lifContract.connect(supplierSigner); + + await lifContract.approve(entities.address, minDeposit); + + await entities["addDeposit(bytes32,uint256)"](supplierId, minDeposit); + + console.log(`LIF deposit added for supplier #${supplierId}`); + + await entities.toggleEntity(supplierId); + + console.log(`Enabled supplier #${supplierId}`); + } } // Market diff --git a/package/src/constants.ts b/package/src/constants.ts index 827ce88..d0f4b35 100644 --- a/package/src/constants.ts +++ b/package/src/constants.ts @@ -37,3 +37,67 @@ export const OFFER_TYPE_HASH = // ); export const CHECK_IN_TYPE_HASH = '0xf811d7f3ddb148410001929e2cbfb7fea8779b9349b7c2f650fa91840528d69c'; + +/** EIP-712 JSON schema types for offer */ +export const offerEip712Types = { + Offer: [ + { + name: 'id', + type: 'bytes32', + }, + { + name: 'expire', + type: 'uint256', + }, + { + name: 'supplierId', + type: 'bytes32', + }, + { + name: 'chainId', + type: 'uint256', + }, + { + name: 'requestHash', + type: 'bytes32', + }, + { + name: 'optionsHash', + type: 'bytes32', + }, + { + name: 'paymentHash', + type: 'bytes32', + }, + { + name: 'cancelHash', + type: 'bytes32', + }, + { + name: 'transferable', + type: 'bool', + }, + { + name: 'checkIn', + type: 'uint256', + }, + { + name: 'checkOut', + type: 'uint256', + }, + ], +} as const; + +/** EIP-712 JSON schema types for checkIn/Out voucher */ +export const checkInOutEip712Types = { + Voucher: [ + { + name: 'id', + type: 'bytes32', + }, + { + name: 'signer', + type: 'address', + }, + ], +} as const;