Skip to content

Commit

Permalink
replace all JS code with TS code
Browse files Browse the repository at this point in the history
  • Loading branch information
0xCardinalError committed Mar 6, 2024
1 parent dd45cba commit 9ae347f
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 135 deletions.
29 changes: 0 additions & 29 deletions deploy/local/000_deploy_factory.js

This file was deleted.

30 changes: 30 additions & 0 deletions deploy/local/000_deploy_factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {

const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const waitBlockConfirmations = network.name != "testnet" ? 1 : 6;

log("----------------------------------------------------");

const token = await deploy("TestToken", {
from: deployer,
log: true,
});

log(`Token deployed at address ${token.address}`);

const deployArgs: string[] = [token.address];
const factory = await deploy("SimpleSwapFactory", {
from: deployer,
args: deployArgs,
log: true,
waitConfirmations: waitBlockConfirmations,
});

log(`Factory deployed at address ${factory.address}`);
};

export default func;
func.tags = ["factory"];
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const { network } = require("hardhat");

module.exports = async ({ getNamedAccounts, deployments }) => {
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts }) {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const waitBlockConfirmations = 1;

log("----------------------------------------------------");
const args = [100, 200];
const deployArgs: [number, number] = [100, 200];

// Deploy the PriceOracle contract
const oracle = await deploy('PriceOracle', {
from: deployer,
args: args,
args: deployArgs,
log: true,
waitConfirmations: waitBlockConfirmations,
});

// Log the address at which the Oracle is deployed
console.log('Oracle deployed at address ' + oracle.address);

log(`Oracle deployed at address ${oracle.address}`);
};

module.exports.tags = ["factory"];
export default func;
func.tags = ["factory"];
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const fs = require("fs");
const path = require("path");
import fs from "fs";
import path from "path";
import { DeployFunction } from 'hardhat-deploy/types';

const func = async function ({ deployments }) {

const func: DeployFunction = async function ({ deployments, config }) {
const { get, log } = deployments;

const SimpleSwapFactory = await get("SimpleSwapFactory");
Expand All @@ -20,10 +22,10 @@ const func = async function ({ deployments }) {

// Write the content to the file
fs.writeFileSync(envFilePath, content, { flag: "a" });
console.log(`Exported contract addresses to ${envFilePath}`);
log(`Exported contract addresses to ${envFilePath}`);

log("----------------------------------------------------");
};

module.exports = func;
export default func;
func.tags = ["variables"];
11 changes: 6 additions & 5 deletions deploy/main/000_deploy.js → deploy/main/000_deploy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const { getNamedAccounts, deployments, network, run } = require("hardhat");
const { verify } = require("../../utils/verify");
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {

module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();

// This code is just used for Sepolia testnet deployment
const waitBlockConfirmations = network.name != "mainnet" ? 1 : 6;
const waitBlockConfirmations = network.name !== "mainnet" ? 1 : 6;

log("----------------------------------------------------");
// sBZZ token address
// TODO this still needs to be done for the first time
};

module.exports.tags = ["factory"];
func.tags = ["factory"];
export default func;
30 changes: 0 additions & 30 deletions deploy/test/000_deploy_factory.js

This file was deleted.

31 changes: 31 additions & 0 deletions deploy/test/000_deploy_factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import { verify } from "../../utils/verify";
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();

// This code is just used for Sepolia testnet deployment
const waitBlockConfirmations = network.name !== "testnet" ? 1 : 6;

log("----------------------------------------------------");
const deployArgs: string[] = ["0x543ddb01ba47acb11de34891cd86b675f04840db"];
const factory = await deploy("SimpleSwapFactory", {
from: deployer,
args: deployArgs,
log: true,
waitConfirmations: waitBlockConfirmations,
});

log(`Factory deployed at address ${factory.address}`);

// Verify the deployment
if (network.name === "testnet" && process.env.TESTNET_ETHERSCAN_KEY) {
log("Verifying...");
await verify(factory.address, arguments);
}
};

func.tags = ["factory"];
export default func;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { getNamedAccounts, deployments, network, run } = require("hardhat");
const { verify } = require("../../utils/verify");
import verify from '../../utils/verify';
import { DeployFunction } from 'hardhat-deploy/types';

const func: DeployFunction = async function ({ deployments, getNamedAccounts, network }) {

module.exports = async ({ getNamedAccounts, deployments }) => {
const { deploy, log } = deployments;
const { deployer } = await getNamedAccounts();
const args = [100000, 100];
Expand All @@ -24,4 +25,5 @@ module.exports = async ({ getNamedAccounts, deployments }) => {
}
};

module.exports.tags = ["factory"];
func.tags = ["factory"];
export default func;
18 changes: 18 additions & 0 deletions deployedContracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
echo "----- USE THE COMMANDS BELOW TO SETUP YOUR TERMINALS -----" >&2

export BEE_SWAP_FACTORY_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
export BEE_SWAP_LEGACY_FACTORY_ADDRESSES=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
export BEE_SWAP_PRICE_ORACLE_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
export BEE_SWAP_ENDPOINT=http://localhost:8545
echo "----- USE THE COMMANDS BELOW TO SETUP YOUR TERMINALS -----" >&2

export BEE_SWAP_FACTORY_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
export BEE_SWAP_LEGACY_FACTORY_ADDRESSES=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
export BEE_SWAP_PRICE_ORACLE_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
export BEE_SWAP_ENDPOINT=http://localhost:8545
echo "----- USE THE COMMANDS BELOW TO SETUP YOUR TERMINALS -----" >&2

export BEE_SWAP_FACTORY_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
export BEE_SWAP_LEGACY_FACTORY_ADDRESSES=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
export BEE_SWAP_PRICE_ORACLE_ADDRESS=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
export BEE_SWAP_ENDPOINT=http://localhost:8545
46 changes: 21 additions & 25 deletions hardhat.config.js → hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
require('dotenv/config');
require('solidity-coverage');
require('hardhat-deploy');
require('hardhat-deploy-ethers');
require('@nomiclabs/hardhat-etherscan');
require('hardhat-gas-reporter');
import 'dotenv/config';
import 'solidity-coverage';
import 'hardhat-deploy';
import 'hardhat-deploy-ethers';
import '@nomiclabs/hardhat-etherscan';
import 'hardhat-gas-reporter';
import { HardhatUserConfig } from 'hardhat/types';

const PRIVATE_RPC_MAINNET = !process.env.PRIVATE_RPC_MAINNET
? undefined
: process.env.PRIVATE_RPC_MAINNET;
const PRIVATE_RPC_TESTNET = !process.env.PRIVATE_RPC_TESTNET
? undefined
: process.env.PRIVATE_RPC_TESTNET;
const PRIVATE_RPC_MAINNET: string | undefined = process.env.PRIVATE_RPC_MAINNET;
const PRIVATE_RPC_TESTNET: string | undefined = process.env.PRIVATE_RPC_TESTNET;

const walletSecret =
const walletSecret: string =
process.env.WALLET_SECRET === undefined
? "undefined"
: process.env.WALLET_SECRET;

if (walletSecret === "undefined") {
console.log("Please set your WALLET_SECRET in a .env file");
} else if (walletSecret.length !== 64) {
console.log("WALLET_SECRET must be 64 characters long.");
}

const mainnetEtherscanKey = process.env.MAINNET_ETHERSCAN_KEY;
const testnetEtherscanKey = process.env.TESTNET_ETHERSCAN_KEY;
const accounts =
walletSecret.length === 64 ? [walletSecret] : { mnemonic: walletSecret };
const mainnetEtherscanKey: string | undefined = process.env.MAINNET_ETHERSCAN_KEY;
const testnetEtherscanKey: string | undefined = process.env.TESTNET_ETHERSCAN_KEY;
const accounts: string[] | { mnemonic: string } = walletSecret.length === 64 ? [walletSecret] : { mnemonic: walletSecret };

// Config for hardhat.
module.exports = {
const config: HardhatUserConfig = {
defaultNetwork: "hardhat",
solidity: {
compilers: [
Expand Down Expand Up @@ -61,17 +59,13 @@ module.exports = {
deploy: ["deploy/local/"],
},
testnet: {
url: PRIVATE_RPC_TESTNET
? PRIVATE_RPC_TESTNET
: "https://1rpc.io/sepolia",
url: PRIVATE_RPC_TESTNET || "https://1rpc.io/sepolia",
accounts,
chainId: 11155111,
deploy: ["deploy/test/"],
},
mainnet: {
url: PRIVATE_RPC_MAINNET
? PRIVATE_RPC_MAINNET
: "https://rpc.gnosischain.com",
url: PRIVATE_RPC_MAINNET || "https://rpc.gnosischain.com",
accounts,
chainId: 100,
deploy: ["deploy/main/"],
Expand Down Expand Up @@ -112,3 +106,5 @@ module.exports = {
sources: "contracts",
},
};

export default config;
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@
"hardhat-gas-reporter": "^1.0.9",
"hardhat-tracer": "^2.1.2",
"mocha": "^10.2.0",
"prettier": "^2.1.2",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.0.0-alpha.59",
"solhint": "^4.1.1",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.8.1",
"typescript": "^4.0.5"
},
"scripts": {
"lint": "eslint \"**/*.{js,ts}\"",
"lint:fix": "eslint --fix \"**/*.{js,ts}\"",
"format": "prettier --write \"**/*.{ts,js,sol}\"",
"hardhat": "hardhat",
"coverage": "hardhat coverage",
"compile": "hardhat compile",
"test": "hardhat test",
"abigen": "./abigen/gen.sh ERC20SimpleSwap SimpleSwapFactory",
"lint": "solhint contracts/ERC20SimpleSwap.sol contracts/SimpleSwapFactory.sol",
"coverage": "hardhat coverage"
"test": "hardhat test"
},
"keywords": [],
"author": "",
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2015",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"outDir": "dist",
"resolveJsonModule": true
},
"include": ["hardhat.config.ts", "./scripts", "./deploy", "./test", "./utils", "./tasks"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
24 changes: 0 additions & 24 deletions utils/verify.js

This file was deleted.

Loading

0 comments on commit 9ae347f

Please # to comment.