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

Commit

Permalink
Merge pull request #10 from enyalabs/add-chain-picker
Browse files Browse the repository at this point in the history
Add chain picker
  • Loading branch information
boyuan-chen authored May 1, 2021
2 parents cc5cd26 + 21d303b commit 4ad5962
Show file tree
Hide file tree
Showing 49 changed files with 761 additions and 4,819 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Rinkeby
NODE_ENV=local
L1_NODE_WEB3_URL=
L2_NODE_WEB3_URL=
ETH1_ADDRESS_RESOLVER_ADDRESS=
L2_NODE_WEB3_URL=http://54.161.5.63:8545
ETH1_ADDRESS_RESOLVER_ADDRESS=0xa32cf2433ba24595d3aCE5cc9A7079d3f1CC5E0c
TEST_PRIVATE_KEY_1=
TEST_PRIVATE_KEY_2=
TARGET_GAS_LIMIT=9000000000
Expand Down
9 changes: 9 additions & 0 deletions deployment/local/addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"L1LiquidityPool": "0xF7fAA3D69f4D2D774A2746d137D86D13dC4AE576",
"L2LiquidityPool": "0xf7511f94161aA90Da8babc08D7F1D11cD60505F3",
"L1ERC20": "0x56CE6e9946D3a5916497567FE32667fE123caA7B",
"L2DepositedERC20": "0x53B7422Fb733E57C961a25B8Ed8065bac9F0085B",
"L1ERC20Gateway": "0x50996B9b9d354aB9DCa1E9efC7a0d211BA0E3f14",
"l1ETHGatewayAddress": "0x4F53A01556Dc6f120db9a1b4caE786D5f0b5792C",
"l1MessengerAddress": "0xA6404B184Ad3f6F41b6472f02ba45f25C6A66d49"
}
9 changes: 9 additions & 0 deletions deployment/rinkeby/addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"L1LiquidityPool": "0x32D3018746A69C8Fc0585A96492bF2A41c2C316D",
"L2LiquidityPool": "0x7C9b37e50Ea69eB033216A3dce5e758Af086c2b4",
"L1ERC20": "0x9F0C060F2BC5028FBab3b5Fa8ac91104C8BF0a0C",
"L2DepositedERC20": "0x16aB7a77057AaF5ac5dAC5Fc8CC1F19A89F20d33",
"L1ERC20Gateway": "0x7eD811886Dee4CE61785cfF6A10492f5c36E83D2",
"l1ETHGatewayAddress": "0xBa67f68C956178CB7fd1c882f9B882487Fa28898",
"l1MessengerAddress": "0x07A5992d8bE8c271B3baa5320975b6E8d8816e34"
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@enyalabs/integration-tests",
"name": "@enyalabs/OMGX_Wallet",
"version": "0.0.1",
"description": "Integration Tests",
"description": "OMGX Example Wallet and Associated Smart Contracts",
"private": true,
"author": "Optimism PBC",
"author": "OMG",
"license": "MIT",
"files": [
"test/**/*.ts"
Expand Down
8 changes: 0 additions & 8 deletions prettier-config.json

This file was deleted.

3 changes: 2 additions & 1 deletion scripts/copy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rm -rf ./wallet/src/deployment &&
mkdir -p ./wallet/src/deployment &&
cp ./deployment/addresses.json ./wallet/src/deployment/addresses.json &&
cp -Rf ./deployment/local ./wallet/src/deployment &&
cp -Rf ./deployment/rinkeby ./wallet/src/deployment &&
cp -Rf ./artifacts ./wallet/src/deployment/artifacts &&
cp -Rf ./artifacts-ovm ./wallet/src/deployment/artifacts-ovm &&
wait
51 changes: 27 additions & 24 deletions test/setup_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {

console.log(JSON.stringify(addresses, null, 2))

fs.writeFile('./deployment/addresses.json', JSON.stringify(addresses, null, 2), err => {
fs.writeFile('./deployment/local/addresses.json', JSON.stringify(addresses, null, 2), err => {
if (err) {
console.log('Error writing addresses to file:', err)
} else {
Expand All @@ -203,7 +203,7 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {
})

it('should transfer ERC20 from Bob to Alice', async () => {
const transferAmount = utils.parseEther("50")
const transferAmount = utils.parseEther("500")

//L1ERC20 is owned by Bob
const preERC20Balances = await L1ERC20.balanceOf(env.alicel1Wallet.address);
Expand All @@ -226,7 +226,8 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {
// **************************************************
// Only the contract owner (Bob) can deposit ETH into L1 LP
// **************************************************
const addAmount = utils.parseEther("50")
const addETHAmount = utils.parseEther("5")
const addERC20Amount = utils.parseEther("500")

// Add ETH
const preETHBalances = await getBalances("0x0000000000000000000000000000000000000000")
Expand All @@ -238,14 +239,14 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {
const gasEstimate = await env.bobl1Wallet.estimateGas({
from: env.bobl1Wallet.address,
to: L1LiquidityPool.address,
value: addAmount
value: addETHAmount
})

//Bob, the owner of the L1LiquidityPool, sends funds into the L1LP
const depositETHTX = await env.bobl1Wallet.sendTransaction({
from: env.bobl1Wallet.address,
to: L1LiquidityPool.address,
value: addAmount
value: addETHAmount
})
await depositETHTX.wait()

Expand All @@ -261,7 +262,7 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {
console.log('\nFEE DEBUG INFORMATION')
console.log("ChainID:",chainID)
console.log("GasPrice (gWei):",utils.formatUnits(gasPrice, "gwei"))
console.log("Fee actually paid:",utils.formatUnits(preETHBalances.bobL1Balance.sub(addAmount).sub(postETHBalances.bobL1Balance), "gwei"))
console.log("Fee actually paid:",utils.formatUnits(preETHBalances.bobL1Balance.sub(addETHAmount).sub(postETHBalances.bobL1Balance), "gwei"))
console.log("Fee gasLimit*gasPrice:",utils.formatUnits(feeSimple, "gwei"))
console.log("GasEstimate (gWei):",utils.formatUnits(gasEstimate, "gwei"))
console.log("GasUsed (gWei):",utils.formatUnits(receipt.gasUsed, "gwei"))
Expand Down Expand Up @@ -292,12 +293,12 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {

//Bob should have less money now - this breaks for zero value transfer
expect(postETHBalances.bobL1Balance).to.deep.eq(
preETHBalances.bobL1Balance.sub(addAmount).sub(feeSimple)
preETHBalances.bobL1Balance.sub(addETHAmount).sub(feeSimple)
)

//He paid into the L1LP
expect(postETHBalances.L1LPBalance).to.deep.eq(
preETHBalances.L1LPBalance.add(addAmount)
preETHBalances.L1LPBalance.add(addETHAmount)
)

//Alice did not pay, so no change
Expand All @@ -310,88 +311,90 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {

const approveERC20TX = await L1ERC20.approve(
L1LiquidityPool.address,
addAmount,
addERC20Amount,
)
await approveERC20TX.wait()

const depositERC20TX = await L1LiquidityPool.ownerAddERC20Liquidity(
addAmount,
addERC20Amount,
L1ERC20.address,
);
await depositERC20TX.wait();

const postERC20Balance = await getBalances(L1ERC20.address)

expect(postERC20Balance.L1LPBalance).to.deep.eq(
preERC20Balances.L1LPBalance.add(addAmount)
preERC20Balances.L1LPBalance.add(addERC20Amount)
)
})

it('should add initial oWETH and ERC20 to the L2 Liquidity Pool', async () => {
const depositL2Amount = utils.parseEther("50")
const addAmount = utils.parseEther("45")
const depositL2oWETHAmount = utils.parseEther("5.1")
const addoWETHAmount = utils.parseEther("5")
const depositL2ERC20Amount = utils.parseEther("510")
const addERC20Amount = utils.parseEther("500")

// Add ETH
const preETHBalances = await getBalances(env.L2ETHGateway.address)

await env.waitForXDomainTransaction(
env.L1ETHGateway.deposit({ value: depositL2Amount }),
env.L1ETHGateway.deposit({ value: depositL2oWETHAmount }),
Direction.L1ToL2
)

const approveETHTX = await env.L2ETHGateway.approve(
L2LiquidityPool.address,
addAmount,
addoWETHAmount,
);
await approveETHTX.wait()

const depositETHTX = await L2LiquidityPool.ownerAddERC20Liquidity(
addAmount,
addoWETHAmount,
env.L2ETHGateway.address,
);
await depositETHTX.wait()

const postETHBalance = await getBalances(env.L2ETHGateway.address)

expect(postETHBalance.L2LPBalance).to.deep.eq(
preETHBalances.L2LPBalance.add(addAmount)
preETHBalances.L2LPBalance.add(addoWETHAmount)
)
// Add ERC20
const preERC20Balances = await getBalances(L2DepositedERC20.address)

const approveL1ERC20TX = await L1ERC20.approve(
L1ERC20Gateway.address,
depositL2Amount,
depositL2ERC20Amount,
)
await approveL1ERC20TX.wait()

await env.waitForXDomainTransaction(
L1ERC20Gateway.deposit(depositL2Amount),
L1ERC20Gateway.deposit(depositL2ERC20Amount),
Direction.L1ToL2
)

const approveL2ERC20TX = await L2DepositedERC20.approve(
L2LiquidityPool.address,
addAmount,
addERC20Amount,
)
await approveL2ERC20TX.wait()

const depositERC20TX = await L2LiquidityPool.ownerAddERC20Liquidity(
addAmount,
addERC20Amount,
L2DepositedERC20.address,
);
await depositERC20TX.wait()

const postERC20Balances = await getBalances(L2DepositedERC20.address)

expect(postERC20Balances.L2LPBalance).to.deep.eq(
preERC20Balances.L2LPBalance.add(addAmount)
preERC20Balances.L2LPBalance.add(addERC20Amount)
)
})

it('should move ETH from L1 LP to L2', async () => {

const swapAmount = utils.parseEther("1")
const swapAmount = utils.parseEther("0.05")
const preBalances = await getBalances("0x0000000000000000000000000000000000000000")

//this triggers the receive
Expand All @@ -416,7 +419,7 @@ describe('Token, Bridge, and Swap Pool Setup and Test', async () => {

it('should swap wETH from L2 LP to ETH in L1 user wallet', async () => {

const swapAmount = utils.parseEther("1")
const swapAmount = utils.parseEther("0.05")
const preBalances = await getBalances(env.L2ETHGateway.address)

const approveTX = await env.L2ETHGateway.approve(
Expand Down
7 changes: 0 additions & 7 deletions tslint.json

This file was deleted.

4 changes: 0 additions & 4 deletions wallet/.eslintignore

This file was deleted.

43 changes: 0 additions & 43 deletions wallet/.eslintrc.json

This file was deleted.

55 changes: 1 addition & 54 deletions wallet/src/Settings.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,8 @@
export const SELLER_API_URL = "https://s8ry0qo8ql.execute-api.us-west-1.amazonaws.com/prod/";
export const BUYER_API_URL = "https://i1hy90c1db.execute-api.us-west-1.amazonaws.com/prod/";
export const HASHCAST_API_URL = "https://hsj4abmlzi.execute-api.us-west-1.amazonaws.com/prod/";
export const WEBSOCKET_API_URL = "wss://hxpkicwmek.execute-api.us-west-1.amazonaws.com/prod";

export const SELLER_OPTIMISM_API_URL = "https://pm7f0dp9ud.execute-api.us-west-1.amazonaws.com/prod/";
export const BUYER_OPTIMISM_API_URL = "https://n245h0ka3i.execute-api.us-west-1.amazonaws.com/prod/";
export const SERVICE_OPTIMISM_API_URL = "https://zlba6djrv6.execute-api.us-west-1.amazonaws.com/prod/";

export const VERSION = "1.0.26";

// global network
export const SELECT_NETWORK = 'local'; // local || rinkeby
//should really get this from the .env
export const INFURA_ID = "fd76d0a0b9e940058d6d42d5e261f517";

export const NETWORK = (chainId) => {
for (let n in NETWORKS) {
if (NETWORKS[n].chainId === chainId) {
return NETWORKS[n];
}
}
};

export const NETWORKS = {
localL1: {
name: "Local L1 Network",
color: "#666666",
chainId: 31337,
blockExplorer: "",
rpcUrl: "http://" + window.location.hostname + ":9545"
},
localL2: {
name: "Local L2 Network",
color: "#e0bfc3",
chainId: 420,
blockExplorer: "",
rpcUrl: "http://" + window.location.hostname + ":8545",
l2ETHGatewayAddress: '0x4200000000000000000000000000000000000006',
l2MessengerAddress: '0x4200000000000000000000000000000000000007'
},
rinkeby: {
name: "Rinkeby Network",
color: "#7003DD",
chainId: 4,
rpcUrl: `https://rinkeby.infura.io/v3/${INFURA_ID}`,
blockExplorer: `https://rinkeby.etherscan.io/${INFURA_ID}`,
},
rinkebyL2: {
name: "Rinkeby L2 Network",
color: "#e0bfc3",
chainId: 420,
blockExplorer: "",
rpcUrl: "http://54.161.5.63:8545",
l2ETHGatewayAddress: '0x4200000000000000000000000000000000000006',
l2MessengerAddress: '0x4200000000000000000000000000000000000007'
},
};

export const L1ETHGATEWAY = [
{
anonymous: false,
Expand Down
2 changes: 1 addition & 1 deletion wallet/src/actions/createAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function createAction (key, asyncAction) {
? error
: new WebWalletError({
originalError: error,
customErrorMessage: 'Something went wrong',
customErrorMessage: 'Something went wrong and none of the preconfigured error messages are relevant',
reportToSentry: true,
reportToUi: true
});
Expand Down
Loading

0 comments on commit 4ad5962

Please sign in to comment.