Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Upgrade packages, chains starting #662

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion modules/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"ts-loader": "8.0.7",
"ts-mocha": "8.0.0",
"ts-node": "9.1.1",
"typescript": "4.2.4",
"typescript": "4.3.5",
"webpack": "4.44.2",
"webpack-cli": "4.1.0"
}
Expand Down
14 changes: 7 additions & 7 deletions modules/browser-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"@connext/vector-engine": "0.2.5-beta.21",
"@connext/vector-types": "0.2.5-beta.21",
"@connext/vector-utils": "0.2.5-beta.21",
"@ethersproject/address": "5.2.0",
"@ethersproject/bignumber": "5.2.0",
"@ethersproject/constants": "5.2.0",
"@ethersproject/providers": "5.2.0",
"@ethersproject/solidity": "5.2.0",
"@ethersproject/wallet": "5.2.0",
"@ethersproject/address": "5.4.0",
"@ethersproject/bignumber": "5.4.1",
"@ethersproject/constants": "5.4.0",
"@ethersproject/providers": "5.4.3",
"@ethersproject/solidity": "5.4.0",
"@ethersproject/wallet": "5.4.0",
"@sinclair/typebox": "0.12.7",
"ajv": "6.12.6",
"axios": "0.21.1",
Expand All @@ -52,7 +52,7 @@
"ts-mocha": "8.0.0",
"ts-node": "9.1.1",
"ts-nats": "1.2.15",
"typescript": "4.2.4",
"typescript": "4.3.5",
"webpack": "4.44.2",
"webpack-cli": "4.1.0"
}
Expand Down
2 changes: 1 addition & 1 deletion modules/browser-node/src/services/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class BrowserStore implements IEngineStore, IChainServiceStore {
attempts.push({
// TransactionResponse fields (defined when submitted)
gasLimit: response.gasLimit.toString(),
gasPrice: response.gasPrice.toString(),
gasPrice: (response.gasPrice ?? 0).toString(),
transactionHash: response.hash,

createdAt: new Date(),
Expand Down
4 changes: 2 additions & 2 deletions modules/contracts/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from "@ethersproject/bignumber";
import { EtherSymbol, Zero } from "@ethersproject/constants";
import { EtherSymbol, One, Zero } from "@ethersproject/constants";
import { formatEther, parseEther } from "@ethersproject/units";
import { deployments, ethers, getNamedAccounts, getChainId, network } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
Expand Down Expand Up @@ -58,7 +58,7 @@ const func: DeployFunction = async () => {
log.info(`Sent transaction to deploy ${name}, txHash: ${deployment.transactionHash}`);
log.info(
`Success! Consumed ${receipt?.gasUsed ?? "unknown"} gas worth ${EtherSymbol} ${formatEther(
(receipt?.gasUsed || Zero).mul(tx.gasPrice),
(receipt?.gasUsed ?? Zero).mul(tx.gasPrice ?? One),
)} deploying ${name} to address: ${deployment.address}`,
);
};
Expand Down
4 changes: 2 additions & 2 deletions modules/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const config: HardhatUserConfig = {
networks: {
hardhat: {
accounts: {
accountsBalance: "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
accountsBalance: "57896044618658097711785492504343953926634992332820282019728792003956564819967",
mnemonic,
},
chainId,
Expand All @@ -61,7 +61,7 @@ const config: HardhatUserConfig = {
},
localhost: {
accounts: {
accountsBalance: "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
accountsBalance: "57896044618658097711785492504343953926634992332820282019728792003956564819967",
mnemonic,
},
chainId,
Expand Down
6 changes: 3 additions & 3 deletions modules/contracts/ops/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ rm -f "$chain_addresses"
## Start hardhat testnet

echo "Starting hardhat node.."
hardhat node --hostname 0.0.0.0 --port 8545 --no-deploy --as-network localhost > /tmp/hardhat.log &
hardhat node --hostname 0.0.0.0 --port 8545 --no-deploy --network hardhat > /tmp/hardhat.log &
pid=$!
echo "Waiting for testnet to wake up.."
wait-for -q -t 60 localhost:8545 2>&1 | sed '/nc: bad address/d'
echo "Good morning!"

echo "Deploying contracts..."
mkdir -p deployments
hardhat deploy --network localhost --no-compile --export-all "$ADDRESS_BOOK" | pino-pretty --colorize --translateTime --ignore pid,level,hostname,module
hardhat deploy --network hardhat --no-compile --export-all "$ADDRESS_BOOK" | pino-pretty --colorize --translateTime --ignore pid,level,hostname,module

# jq docs: https://stedolan.github.io/jq/manual/v1.5/#Builtinoperatorsandfunctions
jq '
.["'"$CHAIN_ID"'"].localhost.contracts
.["'"$CHAIN_ID"'"].hardhat.contracts
| map_values(.address)
| to_entries
| map(.key = "\(.key)Address")
Expand Down
4 changes: 2 additions & 2 deletions modules/contracts/ops/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "ethprovider",
"description": "This is only used to install a few packages into the ethprovider docker container",
"dependencies": {
"ethers": "5.2.0",
"hardhat": "2.2.0",
"ethers": "5.4.3",
"hardhat": "2.5.0",
"pino-pretty": "4.6.0"
}
}
46 changes: 23 additions & 23 deletions modules/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,36 @@
"@connext/pure-evm-wasm": "0.1.4",
"@connext/vector-types": "0.2.5-beta.21",
"@connext/vector-utils": "0.2.5-beta.21",
"@ethersproject/abi": "5.2.0",
"@ethersproject/abstract-provider": "5.2.0",
"@ethersproject/abstract-signer": "5.2.0",
"@ethersproject/address": "5.2.0",
"@ethersproject/bignumber": "5.2.0",
"@ethersproject/constants": "5.2.0",
"@ethersproject/contracts": "5.2.0",
"@ethersproject/hdnode": "5.2.0",
"@ethersproject/keccak256": "5.2.0",
"@ethersproject/providers": "5.2.0",
"@ethersproject/solidity": "5.2.0",
"@ethersproject/units": "5.2.0",
"@ethersproject/wallet": "5.2.0",
"@ethersproject/abi": "5.4.0",
"@ethersproject/abstract-provider": "5.4.0",
"@ethersproject/abstract-signer": "5.4.1",
"@ethersproject/address": "5.4.0",
"@ethersproject/bignumber": "5.4.1",
"@ethersproject/constants": "5.4.0",
"@ethersproject/contracts": "5.4.1",
"@ethersproject/hdnode": "5.4.0",
"@ethersproject/keccak256": "5.4.0",
"@ethersproject/providers": "5.4.3",
"@ethersproject/solidity": "5.4.0",
"@ethersproject/units": "5.4.0",
"@ethersproject/wallet": "5.4.0",
"@openzeppelin/contracts": "3.2.1-solc-0.7",
"evt": "1.9.12",
"hardhat": "2.2.0",
"hardhat-deploy": "0.7.5",
"hardhat-deploy-ethers": "0.3.0-beta.7",
"hardhat": "2.5.0",
"hardhat-deploy": "0.8.11",
"hardhat-deploy-ethers": "0.3.0-beta.10",
"keccak": "3.0.1",
"p-queue": "6.6.2",
"pino": "6.11.1",
"pino-pretty": "4.6.0"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-etherscan": "2.1.1",
"@nomiclabs/hardhat-etherscan": "2.1.4",
"@nomiclabs/hardhat-waffle": "2.0.1",
"@tenderly/hardhat-tenderly": "1.0.11",
"@typechain/ethers-v5": "6.0.5",
"@typechain/hardhat": "^1.0.1",
"@tenderly/hardhat-tenderly": "1.0.12",
"@typechain/ethers-v5": "7.0.1",
"@typechain/hardhat": "2.2.0",
"@types/chai": "4.2.15",
"@types/chai-subset": "1.3.3",
"@types/mocha": "8.2.1",
Expand All @@ -70,7 +70,7 @@
"babel-loader": "8.1.0",
"chai": "4.3.1",
"chai-subset": "1.6.0",
"ethereum-waffle": "3.3.0",
"ethereum-waffle": "3.4.0",
"event-target-shim": "5.0.1",
"hardhat-gas-reporter": "1.0.4",
"mocha": "8.3.0",
Expand All @@ -84,8 +84,8 @@
"ts-loader": "8.0.7",
"ts-mocha": "8.0.0",
"ts-node": "9.1.1",
"typechain": "4.0.3",
"typescript": "4.2.4",
"typechain": "5.1.2",
"typescript": "4.3.5",
"webpack": "4.44.2",
"webpack-cli": "4.1.0"
}
Expand Down
6 changes: 3 additions & 3 deletions modules/contracts/src.ts/commitments/withdraw.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { signChannelMessage, expect } from "@connext/vector-utils";
import { BigNumber } from "@ethersproject/bignumber";
import { AddressZero } from "@ethersproject/constants";
import { Contract } from "@ethersproject/contracts";
import { parseEther } from "@ethersproject/units";
import { deployments } from "hardhat";
import { ChannelMastercopy, ERC20 } from "../../typechain";

import { alice, bob, provider } from "../constants";
import { getContract, createChannel } from "../utils";
Expand All @@ -12,8 +12,8 @@ import { WithdrawCommitment } from "./withdraw";

describe("withdrawCommitment", function () {
this.timeout(120_000);
let channel: Contract;
let token: Contract;
let channel: ChannelMastercopy;
let token: ERC20;
const amount = "50";

beforeEach(async () => {
Expand Down
18 changes: 6 additions & 12 deletions modules/contracts/src.ts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { HDNode } from "@ethersproject/hdnode";
import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
import { network, ethers }from "hardhat";
import { network, ethers, waffle } from "hardhat";
import pino from "pino";

// Get defaults from env
const chainProviders = JSON.parse(process.env.CHAIN_PROVIDERS ?? "{}");
const chainId = Object.keys(chainProviders)[0];
const url = Object.values(chainProviders)[0];
const mnemonic = process.env.SUGAR_DADDY ?? "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
const mnemonic =
process.env.SUGAR_DADDY ?? "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";

export const defaultLogLevel = process.env.LOG_LEVEL || "info";
export const logger = pino({ level: defaultLogLevel });
Expand All @@ -17,18 +18,11 @@ export const networkName = network.name;

export const provider = url
? new JsonRpcProvider(url as string, parseInt(chainId))
: ethers.provider as JsonRpcProvider;
: (ethers.provider as JsonRpcProvider);

const hdNode = HDNode.fromMnemonic(mnemonic).derivePath("m/44'/60'/0'/0");
export const wallets = waffle.provider.getWallets();

export const wallets: Wallet[] = Array(20)
.fill(0)
.map((_, idx) => {
const wallet = new Wallet(hdNode.derivePath(idx.toString()).privateKey, provider);
return wallet;
});

export const chainIdReq = provider.getNetwork().then(net => net.chainId);
export const chainIdReq = provider.getNetwork().then((net) => net.chainId);
export const alice = wallets[0];
export const bob = wallets[1];
export const rando = wallets[2];
2 changes: 2 additions & 0 deletions modules/contracts/src.ts/services/ethService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const txReceipt: TransactionReceipt = {
transactionHash: txResponse.hash,
transactionIndex: 1,
status: 1,
type: 0,
effectiveGasPrice: BigNumber.from(21000),
};

const { log } = getTestLoggers("ethService");
Expand Down
4 changes: 2 additions & 2 deletions modules/contracts/src.ts/services/ethService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class EthereumChainService extends EthereumChainReader implements IVector
channelAddress,
reason,
hash: response.hash,
gasPrice: response.gasPrice.toString(),
gasPrice: response.gasPrice?.toString() ?? "unknown",
nonce: response.nonce,
},
"Tx submitted.",
Expand Down Expand Up @@ -428,7 +428,7 @@ export class EthereumChainService extends EthereumChainReader implements IVector
this.log.info(
{
hash: response.hash,
gas: response.gasPrice.toString(),
gas: response.gasPrice?.toString() ?? "unknown",
channelAddress,
method,
methodId,
Expand Down
40 changes: 21 additions & 19 deletions modules/contracts/src.ts/tests/channelFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { AddressZero, Zero } from "@ethersproject/constants";
import { Contract } from "@ethersproject/contracts";
import { deployments, ethers } from "hardhat";
import pino from "pino";
import { ChannelFactory, ChannelMastercopy } from "../../typechain";

import { ChannelMastercopy } from "../artifacts";
import { ChannelMastercopy as ChannelMastercopyArtifact } from "../artifacts";
import { alice, bob, chainIdReq, provider } from "../constants";
import { VectorChainReader } from "../services";
import { createChannel, getContract } from "../utils";
Expand All @@ -23,8 +24,8 @@ describe("ChannelFactory", function () {
const bobPubId = getPublicIdentifierFromPublicKey(bob.publicKey);
let chainId: number;
let chainReader: VectorChainReader;
let channelFactory: Contract;
let channelMastercopy: Contract;
let channelFactory: ChannelFactory;
let channelMastercopy: ChannelMastercopy;

beforeEach(async () => {
await deployments.fixture(); // Start w fresh deployments
Expand Down Expand Up @@ -67,13 +68,11 @@ describe("ChannelFactory", function () {
it("should create a channel with a deposit", async () => {
// Use funded account for alice
const value = BigNumber.from("1000");
await (await (channelFactory.connect(alice).createChannelAndDepositAlice(
alice.address,
bob.address,
AddressZero,
value,
{ value },
))).wait();
await (
await channelFactory
.connect(alice)
.createChannelAndDepositAlice(alice.address, bob.address, AddressZero, value, { value })
).wait();
const channelAddress = await channelFactory.getChannelAddress(alice.address, bob.address);
const computedAddr = await getCreate2MultisigAddress(
alicePubId,
Expand All @@ -91,20 +90,23 @@ describe("ChannelFactory", function () {
const code = await provider.getCode(channelAddress);
expect(code).to.not.be.eq("0x");

const totalDepositsAlice = await new Contract(channelAddress, ChannelMastercopy.abi, alice).getTotalDepositsAlice(
AddressZero,
);
const channel = ((new Contract(
channelAddress,
ChannelMastercopyArtifact.abi,
) as unknown) as ChannelMastercopy).connect(alice);

const totalDepositsAlice = await channel.getTotalDepositsAlice(AddressZero);
expect(totalDepositsAlice).to.be.eq(value);
});

it("should create a different channel with a different mastercopy address", async () => {
const channel = await createChannel(alice.address, bob.address);
const newChannelMastercopy = await (await (
await ethers.getContractFactory("ChannelMastercopy", alice)
).deploy()).deployed();
const newChannelFactory = await (await (
await ethers.getContractFactory("ChannelFactory", alice)
).deploy(newChannelMastercopy.address, Zero)).deployed();
const newChannelMastercopy = await (
await (await ethers.getContractFactory("ChannelMastercopy", alice as any)).deploy()
).deployed();
const newChannelFactory = await (
await (await ethers.getContractFactory("ChannelFactory", alice as any)).deploy(newChannelMastercopy.address, Zero)
).deployed();
const newChannelAddress = await newChannelFactory.getChannelAddress(alice.address, bob.address);
await (await newChannelFactory.createChannel(alice.address, bob.address)).wait();
expect(channel.address).to.not.eq(newChannelAddress);
Expand Down
6 changes: 3 additions & 3 deletions modules/contracts/src.ts/tests/channelMastercopy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from "@connext/vector-utils";
import { AddressZero, HashZero, Zero } from "@ethersproject/constants";
import { Contract } from "@ethersproject/contracts";
import { deployments } from "hardhat";
import { ChannelMastercopy } from "../../typechain";

import { alice } from "../constants";
import { getContract } from "../utils";

describe("ChannelMastercopy", function () {
this.timeout(120_000);
let mastercopy: Contract;
let mastercopy: ChannelMastercopy;

beforeEach(async () => {
await deployments.fixture(); // Start w fresh deployments
Expand Down Expand Up @@ -66,7 +66,7 @@ describe("ChannelMastercopy", function () {
{ name: "disputeTransfer", args: [CoreTransferStateZero, []] },
{ name: "defundTransfer", args: [CoreTransferStateZero, HashZero, HashZero, HashZero] },
]) {
await expect(mastercopy[method.name](...method.args)).to.be.revertedWith("Mastercopy: ONLY_VIA_PROXY");
await expect((mastercopy as any)[method.name](...method.args)).to.be.revertedWith("Mastercopy: ONLY_VIA_PROXY");
}
});

Expand Down
Loading