From 9ae752f49532b0786623968eec72a17399403a5c Mon Sep 17 00:00:00 2001 From: imajindev Date: Sat, 10 Aug 2024 17:58:12 +0800 Subject: [PATCH] add redeem resolver --- .gitignore | 11 +- apps/contract/.env.sample | 1 + apps/contract/.solhint.json | 7 + apps/contract/.solhintignore | 1 + apps/contract/hardhat.config.js | 105 + apps/contract/scripts/deploy-ticket-redeem.js | 33 + apps/contract/src/RedeemResolver.sol | 53 + package-lock.json | 2768 ++++++++++++++++- package.json | 9 + 9 files changed, 2975 insertions(+), 13 deletions(-) create mode 100644 apps/contract/.env.sample create mode 100644 apps/contract/.solhint.json create mode 100644 apps/contract/.solhintignore create mode 100644 apps/contract/hardhat.config.js create mode 100644 apps/contract/scripts/deploy-ticket-redeem.js create mode 100644 apps/contract/src/RedeemResolver.sol diff --git a/.gitignore b/.gitignore index dc3e3d5..f9c10e6 100644 --- a/.gitignore +++ b/.gitignore @@ -129,4 +129,13 @@ dist .yarn/install-state.gz .pnp.* -.nx \ No newline at end of file +.nx + +#Hardhat files +coverage +coverage.json +typechain +cache +artifacts +.openzeppelin +build diff --git a/apps/contract/.env.sample b/apps/contract/.env.sample new file mode 100644 index 0000000..628fa73 --- /dev/null +++ b/apps/contract/.env.sample @@ -0,0 +1 @@ +TESTNET_PRIVATE_KEY= \ No newline at end of file diff --git a/apps/contract/.solhint.json b/apps/contract/.solhint.json new file mode 100644 index 0000000..f3e31e8 --- /dev/null +++ b/apps/contract/.solhint.json @@ -0,0 +1,7 @@ +{ + "extends": "solhint:recommended", + "rules": { + "compiler-version": ["error", "^0.8.0"], + "func-visibility": ["warn", { "ignoreConstructors": true }] + } +} diff --git a/apps/contract/.solhintignore b/apps/contract/.solhintignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/apps/contract/.solhintignore @@ -0,0 +1 @@ +node_modules diff --git a/apps/contract/hardhat.config.js b/apps/contract/hardhat.config.js new file mode 100644 index 0000000..f80e118 --- /dev/null +++ b/apps/contract/hardhat.config.js @@ -0,0 +1,105 @@ +const fs = require('fs') +const fsExtra = require('fs-extra') +const { subtask, task } = require('hardhat/config') +const { TASK_CLEAN, TASK_COMPILE } = require('hardhat/builtin-tasks/task-names') +// require('@nomiclabs/hardhat-waffle') +// require('@nomiclabs/hardhat-ethers') +require('hardhat-deploy') +require('hardhat-contract-sizer') +require('@openzeppelin/hardhat-upgrades') + +require('dotenv').config({ path: './.env' }) + +let mnemonic = process.env.MNEMONIC +if (!mnemonic) { + mnemonic = 'test test test test test test test test test test test junk' +} +const mnemonicAccounts = { + mnemonic, +} + +const account = { + Testnet: process.env.TESTNET_PRIVATE_KEY, + Mainnet: process.env.MAINNET_PRIVATE_KEY, +} + +// Default output dir to abi contracts in frontend +const contractsFrontDir = './compiled' + +// You need to export an object to set up your config +// Go to https://hardhat.org/config/ to learn more + +/** + * @type import('hardhat/config').HardhatUserConfig + */ +const config = { + solidity: { + version: '0.8.20', + settings: { + evmVersion: "paris", + optimizer: { + enabled: true, + runs: 200, + }, + }, + }, + paths: { + sources: './src', + tests: './test', + cache: './cache', + artifacts: './artifacts', + }, + defaultNetwork: 'optimismSepolia', + networks: { + hardhat: { + accounts: mnemonicAccounts, + }, + optimismSepolia: { + url: 'https://sepolia.optimism.io', + chainId: 11155420, + accounts: account.Testnet ? [account.Testnet] : mnemonicAccounts, + }, + }, + namedAccounts: { + deployer: { + default: 0, // here this will by default take the first account as deployer + }, + }, + mocha: { + timeout: 50000, // 50 seconds timeout + }, +} + +// // This is a sample Hardhat task. To learn how to create your own go to +// // https://hardhat.org/guides/create-task.html +// task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => { +// const accounts = await hre.ethers.getSigners() +// accounts.forEach((acc) => { +// console.log(acc.address) +// }) +// }) + +task(TASK_CLEAN, 'Clean all artifacts & folder contracts in frontend').setAction(async (taskArgs, hre, runSuper) => { + await runSuper() + if (fs.existsSync('./deployments')) { + fs.rmdirSync('./deployments', { recursive: true }) + } + await hre.run('clean-front-contracts') +}) + +subtask('clean-front-contracts', 'Clear frontend contracts folder').setAction(async () => { + // Clear if exist + if (fs.existsSync(contractsFrontDir)) { + fsExtra.emptyDirSync(contractsFrontDir) + } +}) + +task(TASK_COMPILE, 'Deploy contracts').setAction(async (taskArgs, hre, runSuper) => { + console.log('TASK_COMPILE', taskArgs) + if (!fs.existsSync(contractsFrontDir)) { + fs.mkdirSync(contractsFrontDir, { recursive: true }) + } + await runSuper(taskArgs) +}) + +module.exports = config diff --git a/apps/contract/scripts/deploy-ticket-redeem.js b/apps/contract/scripts/deploy-ticket-redeem.js new file mode 100644 index 0000000..ca8a979 --- /dev/null +++ b/apps/contract/scripts/deploy-ticket-redeem.js @@ -0,0 +1,33 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node