Skip to content
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

added deploy script #1

Merged
merged 4 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 39 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build and Test

on:
pull_request:

jobs:
Deploy-Test:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' # This line ensures that this job only runs on pull requests
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.15.0'

- name: Restore cache
id: restore-cache
uses: actions/cache/restore@v3
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
Lomet marked this conversation as resolved.
Show resolved Hide resolved
restore-keys: |
${{ runner.os }}-yarn-

- name: Install HardHat
if: steps.restore-cache.outputs.cache-hit != 'true'
run: npm i hardhat

- name: File Import
run: npx hardhat run ./scripts/fileImport.ts

- name: compile contracts
run: npx hardhat compile

- name: deploy simulation
run: npx hardhat run ./scripts/deploy.ts
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
artifacts
cache
temp.zip
package-lock.json
Lomet marked this conversation as resolved.
Show resolved Hide resolved
yarn.lock
gas-report.txt
typechain-types
coverage
coverage.json
contracts
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# integrate-v3
# integrate-v3

## Deploy

```console
truffle dashboard
```

```console
npx hardhat run ./scripts/fileImport.ts
```

```console
npx hardhat run ./scripts/deploy.ts --network truffleDashboard
```
42 changes: 42 additions & 0 deletions TestSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import axios from 'axios';
import fs from 'fs';
import AdmZip from 'adm-zip';

async function downloadAndExtractZip(url: string, extractPath: string): Promise<void> {
if (!fs.existsSync(extractPath)) {
fs.mkdirSync(extractPath, { recursive: true });
}

const response = await axios({
url,
method: 'GET',
responseType: 'stream',
});

const zipPath = './temp.zip';
const writer = fs.createWriteStream(zipPath);

response.data.pipe(writer);

return new Promise((resolve, reject) => {
writer.on('finish', () => {
const zip = new AdmZip(zipPath);
// Extract the contents to the specified path
zip.extractAllTo(extractPath, /*overwrite*/ true);

// Get the name of the extracted folder (e.g., "LockDealNFT-master")
const extractedFolderName = zip.getEntries()[0].entryName.split('/')[0];

// Remove all words that start with a hyphen from the extracted folder name
const modifiedFolderName = extractedFolderName.replace(/-[^/]+/g, '');

fs.renameSync(`${extractPath}${extractedFolderName}`, `${extractPath}${modifiedFolderName}`);

fs.unlinkSync(zipPath);
resolve();
});
writer.on('error', reject);
});
}

export { downloadAndExtractZip };
79 changes: 79 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import "@nomicfoundation/hardhat-toolbox"
import "@truffle/dashboard-hardhat-plugin"
import "hardhat-gas-reporter"
import { HardhatUserConfig } from "hardhat/config"
import "solidity-coverage"

const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
solidity: {
version: "0.8.21",
settings: {
evmVersion: "byzantium",
optimizer: {
enabled: true,
runs: 200,
},
},
},
networks: {
hardhat: {
blockGasLimit: 130_000_000,
},
ropsten: {
url: "https://ropsten.infura.io/v3/your-infura-project-id",
accounts: [], // Replace with your testnet accounts' private keys
},
rinkeby: {
url: "https://rinkeby.infura.io/v3/your-infura-project-id",
accounts: [], // Replace with your testnet accounts' private keys
},
kovan: {
url: "https://kovan.infura.io/v3/your-infura-project-id",
accounts: [], // Replace with your testnet accounts' private keys
},
goerli: {
url: "https://goerli.infura.io/v3/your-infura-project-id",
accounts: [], // Replace with your testnet accounts' private keys
},
bsc_testnet: {
url: "https://data-seed-prebsc-1-s1.binance.org:8545",
chainId: 97,
accounts: [], // Replace with your testnet accounts' private keys
},
polygon_mumbai: {
url: "https://rpc-mumbai.matic.today",
accounts: [], // Replace with your testnet accounts' private keys
},
fantom_testnet: {
url: "https://rpc.testnet.fantom.network",
accounts: [], // Replace with your testnet accounts' private keys
},
avalanche_fuji: {
url: "https://api.avax-test.network/ext/bc/C/rpc",
accounts: [], // Replace with your testnet accounts' private keys
},
harmony_testnet: {
url: "https://api.s0.b.hmny.io",
accounts: [], // Replace with your testnet accounts' private keys
},
mainnet: {
url: "https://mainnet.infura.io/v3/your-infura-project-id",
accounts: [], // Replace with your mainnet accounts' private keys
},
},
gasReporter: {
enabled: true,
showTimeSpent: true,
showMethodSig: true,
currency: "USD",
token: "BNB",
gasPriceApi:
"https://api.bscscan.com/api?module=proxy&action=eth_gasPrice&apikey=" + process.env.BSCSCAN_API_KEY,
coinmarketcap: process.env.CMC_API_KEY || "",
noColors: true,
outputFile: "gas-report.txt",
},
}

export default config
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "blitzbackcontract",
Lomet marked this conversation as resolved.
Show resolved Hide resolved
"version": "0.0.1",
"description": "Contract for creating fixed price lunch",
"main": "index.js",
"scripts": {
"test": "npx hardhat test"
},
"license": "ISC",
"devDependencies": {
"@ethersproject/bignumber": "^5.7.0",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.4",
"@nomicfoundation/hardhat-network-helpers": "^1.0.6",
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@typechain/ethers-v5": "^10.1.1",
"@typechain/hardhat": "^6.1.4",
"@types/chai": "^4.3.4",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.9",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@truffle/dashboard-hardhat-plugin": "0.2.7",
"@typescript-eslint/parser": "^5.44.0",
"chai": "^4.3.7",
"ethers": "^5.7.2",
"fs-extra": "^10.1.0",
"hardhat": "^2.15.0",
"hardhat-gas-reporter": "^1.0.9",
"lodash": "^4.17.21",
"mocha": "^10.1.0",
"rimraf": "^4.1.2",
"solidity-coverage": "^0.8.2",
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"typescript": "^4.9.3",
"dotenv": "^16.3.1",
"@openzeppelin/contracts": "^4.8.3",
"@poolzfinance/poolz-helper-v2": "^2.1.15"
}
}
78 changes: 78 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
LockDealNFT,
DealProvider,
LockDealProvider,
TimedDealProvider,
CollateralProvider,
RefundProvider,
VaultManager,
SimpleBuilder,
SimpleRefundBuilder,
} from "../typechain-types"
import { ethers } from "hardhat"

export const deployed = async <T>(contractName: string, ...args: string[]): Promise<T> => {
const Contract = await ethers.getContractFactory(contractName)
const contract = await Contract.deploy(...args)
return contract.deployed() as Promise<T>
}

async function deployAllContracts() {
const vaultManager: VaultManager = await deployed("VaultManager")
console.log(`VaultManager contract deployed to ${vaultManager.address}`)

const baseURI = "https://nft.poolz.finance/test/metadata/"

// Deploy LockDealNFT contract
const lockDealNFT: LockDealNFT = await deployed("LockDealNFT", vaultManager.address, baseURI)
console.log(`LockDealNFT contract deployed to ${lockDealNFT.address} with vaultManager ${vaultManager.address}`)

// Deploy DealProvider contract
const dealProvider: DealProvider = await deployed("DealProvider", lockDealNFT.address)
console.log(`DealProvider contract deployed to ${dealProvider.address} with lockDealNFT ${lockDealNFT.address}`)

// Deploy LockDealProvider contract
const lockProvider: LockDealProvider = await deployed("LockDealProvider", lockDealNFT.address, dealProvider.address)
console.log(`LockDealProvider contract deployed to ${lockProvider.address}`)

// Deploy TimedDealProvider contract
const timedDealProvider: TimedDealProvider = await deployed(
"TimedDealProvider",
lockDealNFT.address,
lockProvider.address
)
console.log(`TimedDealProvider contract deployed to ${timedDealProvider.address}`)

// Deploy CollateralProvider contract
const collateralProvider: CollateralProvider = await deployed(
"CollateralProvider",
lockDealNFT.address,
dealProvider.address
)
console.log(`CollateralProvider contract deployed to ${collateralProvider.address}`)

// Deploy RefundProvider contract
const refundProvider: RefundProvider = await deployed(
"RefundProvider",
lockDealNFT.address,
collateralProvider.address
)
console.log(`RefundProvider contract deployed to ${refundProvider.address}`)

// Deploy Buiders
const simpleBuilder: SimpleBuilder = await deployed("SimpleBuilder", lockDealNFT.address)
console.log("Simple Builder deployed to", simpleBuilder.address)

const simpleRefundBuilder: SimpleRefundBuilder = await deployed(
"SimpleRefundBuilder",
lockDealNFT.address,
refundProvider.address,
collateralProvider.address
)
console.log("Simple Refund Builder deployed to", simpleRefundBuilder.address)
}

deployAllContracts().catch((error) => {
console.error(error)
process.exitCode = 1
})
60 changes: 60 additions & 0 deletions scripts/fileImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { downloadAndExtractZip } from "../TestSetup"
import fs from "fs"
import path from "path"

async function downloadAndExtractZipAll() {
try {
await downloadAndExtractZip(
"https://github.com/The-Poolz/LockDealNFT/archive/refs/heads/master.zip",
"contracts/"
)
await downloadAndExtractZip(
"https://github.com/The-Poolz/VaultManager/archive/refs/heads/master.zip",
"contracts/"
)
cleanUpFolders("contracts/LockDealNFT")
cleanUpFolders("contracts/VaultManager")
} catch (error) {
console.error("An error occurred during download and compile:", error)
}
}

function cleanUpFolders(parentDir: string) {
// Get a list of all files and subfolders in the parent directory
const items = fs.readdirSync(parentDir)

for (const item of items) {
const itemPath = path.join(parentDir, item)

// Check if it's a directory
if (fs.lstatSync(itemPath).isDirectory()) {
// If it's not named "contracts," delete it
if (item !== "contracts") {
removeFolderRecursively(itemPath)
}
} else {
// It's a file, so delete it
fs.unlinkSync(itemPath)
}
}
}

function removeFolderRecursively(folderPath: string) {
// Recursively delete the folder and its contents
const items = fs.readdirSync(folderPath)

for (const item of items) {
const itemPath = path.join(folderPath, item)

if (fs.lstatSync(itemPath).isDirectory()) {
removeFolderRecursively(itemPath)
} else {
fs.unlinkSync(itemPath)
}
}

// After all contents are deleted, remove the folder itself
fs.rmdirSync(folderPath)
}

downloadAndExtractZipAll()
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
}
}