Skip to content

Feat/more const #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 159 additions & 1 deletion deploy/001.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<DeployResult>,
name: string,
contractName: string,
tokenName: string,
tokenSymbol: string,
networkName: string
): Promise<DeployResult> => {
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 = <MockERC20Dec18>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;

Expand All @@ -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: {
Expand Down Expand Up @@ -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 = <MockERC20Dec18>(
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
Expand Down Expand Up @@ -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 = <EntitiesRegistry>(
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 = <MockERC20Dec18>(
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
Expand Down
64 changes: 64 additions & 0 deletions package/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;