Skip to content

Commit

Permalink
Merge pull request #1349 from EYBlockchain/david/wallet-local
Browse files Browse the repository at this point in the history
update local wallet deployment
  • Loading branch information
druiz0992 authored Jan 18, 2023
2 parents 5abbb3d + b993980 commit 7f12f8f
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 26 deletions.
5 changes: 5 additions & 0 deletions apps/gas-estimate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Gas Estimate Function
Gas Estimate function provides a simple endpoint to estimate Ethereum mainnet Gas price. It is expected to be used as a
nodejs lambda function. It requires to include an environment variable, `process.env.ETH_GAS_STATION`, which is an Etherscan API Key.

Once this function is deployed, simply configure `GAS_ESTIMATE_ENDPOINT` with the endpoint URL. If this variable is not defined, the estimation is done differently by estimating the price by the last few blocks median gas price.
45 changes: 45 additions & 0 deletions apps/gas-estimate/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const https = require('https');

function getRequest(url) {
return new Promise((resolve, reject) => {
const req = https.get(url, res => {
let rawData = '';

res.on('data', chunk => {
rawData += chunk;
});

res.on('end', () => {
try {
resolve(JSON.parse(rawData));
} catch (err) {
reject(new Error(err));
}
});
});

req.on('error', err => {
reject(new Error(err));
});
});
}

exports.handler = async () => {
try {
console.log('ETH_GAS_STATION', process.env.ETH_GAS_STATION);
const result = await getRequest(
`https://api.etherscan.io/api?module=gastracker&action=gasoracle&apikey=${process.env.ETH_GAS_STATION}`,
);
console.log('result', result);
return {
statusCode: 200,
body: JSON.stringify(result),
};
} catch (error) {
console.log('Error is️:', error);
return {
statusCode: 400,
body: error.message,
};
}
};
4 changes: 1 addition & 3 deletions cli/lib/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ export const GAS_MULTIPLIER = Number(process.env.GAS_MULTIPLIER) || 2;
export const GAS_PRICE_MULTIPLIER = Number(process.env.GAS_PRICE_MULTIPLIER) || 2;
export const GAS = process.env.GAS || 4000000;
export const GAS_PRICE = process.env.GAS_PRICE || '10000000000';
export const GAS_ESTIMATE_ENDPOINT =
process.env.GAS_ESTIMATE_ENDPOINT ||
'https://vqxy02tr5e.execute-api.us-east-2.amazonaws.com/production/estimateGas';
export const { GAS_ESTIMATE_ENDPOINT } = process.env;
2 changes: 2 additions & 0 deletions docker/docker-compose.apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ services:
OPTIMIST_WS_PORT: ${OPTIMIST_WS_PORT:-8080}
PROPOSER_HOST: ${PROPOSER_HOST:-proposer}
PROPOSER_PORT: ${PROPOSER_PORT:-8092}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
networks:
- nightfall_network
volumes:
Expand Down Expand Up @@ -58,6 +59,7 @@ services:
CLIENT_HOST: ${CLIENT_HOST:-client}
CLIENT_PORT: ${CLIENT_PORT:-8080}
CHALLENGER_PORT: ${CHALLENGER_PORT}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
networks:
- nightfall_network
volumes:
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ services:
CIRCOM_WORKER_HOST: worker_1
MONGO_URL: ${CLIENT_MONGO_URL:-mongodb://mongodb_client_1}
CONTRACT_FILES_URL: ${CONTRACT_FILES_URL}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST}
LAUNCH_LOCAL: 1
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'dev']

mongodb_client_1:
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ services:
RABBITMQ_PORT: ${RABBITMQ_PORT:-5672}
STATE_GENESIS_BLOCK: ${STATE_GENESIS_BLOCK:-0}
USE_EXTERNAL_NODE: ${USE_EXTERNAL_NODE}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'start']

deployer:
Expand Down Expand Up @@ -84,6 +85,7 @@ services:
SKIP_DEPLOYMENT: ${SKIP_DEPLOYMENT:-'false'}
WHITELISTING: ${WHITELISTING?WHITELISTING-not-set}
UPGRADE: ${UPGRADE_CONTRACTS}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}

mongodb:
image: mongo:4.4.1-bionic
Expand Down Expand Up @@ -134,6 +136,7 @@ services:
PROPOSER_MAX_BLOCK_PERIOD_MILIS: ${PROPOSER_MAX_BLOCK_PERIOD_MILIS:-0}
USE_EXTERNAL_NODE: ${USE_EXTERNAL_NODE}
WEBSOCKET_PORT: 8080
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'start']

worker:
Expand Down
8 changes: 8 additions & 0 deletions docker/docker-compose.multiproposer-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ services:
UPGRADE: ${UPGRADE_CONTRACTS}
ALWAYS_DO_TRUSTED_SETUP: ${ALWAYS_DO_TRUSTED_SETUP}
DEPLOY_MOCKED_SANCTIONS_CONTRACT: 'true'
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}

hosted-utils-api-server:
build:
Expand Down Expand Up @@ -132,6 +133,7 @@ services:
OPTIMIST_HOST: ${OPTIMIST_HOST:-proposer_optimist_1}
OPTIMIST_PORT: ${OPTIMIST_PORT:-80}
MONGO_URL: ${CLIENT_MONGO_URL:-mongodb://optimist_mongodb_1:27017}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'dev']

client_2:
Expand Down Expand Up @@ -179,6 +181,7 @@ services:
CONTRACT_FILES_URL: ${CONTRACT_FILES_URL}
BLOCKCHAIN_WS_HOST: ${BLOCKCHAIN_WS_HOST:-blockchain}
BLOCKCHAIN_PORT: ${BLOCKCHAIN_PORT:-8546}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'dev']

proposer_optimist_1:
Expand Down Expand Up @@ -212,6 +215,7 @@ services:
LOG_HTTP_FULL_DATA: ${LOG_HTTP_FULL_DATA:-false}
IS_CHALLENGER: ${IS_CHALLENGER:-false}
AUTOSTART_RETRIES: ${AUTOSTART_RETRIES:-100}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'dev']

proposer_optimist_2:
Expand Down Expand Up @@ -256,6 +260,7 @@ services:
# so for adversary default is false unlike optimist
IS_CHALLENGER: ${IS_CHALLENGER:-false}
AUTOSTART_RETRIES: ${AUTOSTART_RETRIES:-100}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'dev']

optimist_mongodb_1:
Expand Down Expand Up @@ -307,6 +312,7 @@ services:
PROPOSER_PORT: 8093
PROPOSER_KEY: ${PROPOSER_KEY:-0xcbbf1d0686738a444cf9f66fdc96289035c384c4e8d26768f94fa81f3ab6596a}
DEPLOYER_HOST: ${DEPLOYER_HOST:-deployer}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
networks:
- nightfall_network
volumes:
Expand Down Expand Up @@ -335,6 +341,7 @@ services:
PROPOSER_PORT: 8094
PROPOSER_KEY: ${PROPOSER2_KEY:-0xabf4ed9f30bd1e4a290310d726c7bbdf39cd75a25eebd9a3a4874e10b4a0c4ce}
DEPLOYER_HOST: ${DEPLOYER_HOST:-deployer}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
networks:
- nightfall_network
volumes:
Expand Down Expand Up @@ -362,6 +369,7 @@ services:
CHALLENGER_PORT: 8192
CHALLENGER_KEY: ${CHALLENGER_KEY:-0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb}
DEPLOYER_HOST: ${DEPLOYER_HOST:-deployer}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
networks:
- nightfall_network
volumes:
Expand Down
3 changes: 3 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ services:
OPTIMIST_PORT: ${OPTIMIST_PORT:-80}
MONGO_URL: ${CLIENT_MONGO_URL:-mongodb://mongodb:27017}
STATE_GENESIS_BLOCK: ${STATE_GENESIS_BLOCK:-0}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
command: ['npm', 'run', 'dev']

# Temporary container to deploy contracts and circuits and populate volumes
Expand Down Expand Up @@ -87,8 +88,10 @@ services:
MATIC_RESTRICT: ${MATIC_RESTRICT}
USDC_RESTRICT: ${USDC_RESTRICT}
DAI_RESTRICT: ${DAI_RESTRICT}
GAS_ESTIMATE_ENDPOINT: ${GAS_ESTIMATE_ENDPOINT}
WHITELISTING: ${WHITELISTING}


hosted-utils-api-server:
build:
dockerfile: docker/hosted-utils-api-server.Dockerfile
Expand Down
1 change: 1 addition & 0 deletions wallet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.*.env
6 changes: 0 additions & 6 deletions wallet/.internal.env

This file was deleted.

6 changes: 0 additions & 6 deletions wallet/.mainnet.env

This file was deleted.

6 changes: 0 additions & 6 deletions wallet/.testnet.env

This file was deleted.

4 changes: 2 additions & 2 deletions wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

### Running the Wallet locally with AWS infrastructure

1. Copy wallet/.template.copy.env to config file .xxx.env and fill the required `PROPOSER_API_URL` and `PROPOSER_WS_URL` with
1. Copy wallet/template.copy.env to config file .xxx.env and fill the required `PROPOSER_API_URL` and `PROPOSER_WS_URL` with
the proposer URL and the proposer websocket URL respectively.

2. Add new environment to `ChainIdMapping`. Open `wallet/src/common-files/utils/web3.js` and
Expand All @@ -33,7 +33,7 @@ deployed to a public testnet.
4. Install dependencies `npm ci`

5. Start the wallet in local development mode. `ENV_NAME=xxx npm run start:env`, where `xxx`is the name of the env config file created
in previous step (without .env extension). For example, if config env file is named `.testnet.env`, wallet is started with `ENV_NAME=testnet make run start:env`.
in previous step (without .env extension). For example, if config env file is named `.testnet.env`, wallet is started with `ENV_NAME=testnet npm run start:env`.

6. Ensure that your account used in metamask has the same tokens as supported by the wallet (See 2);

Expand Down
4 changes: 1 addition & 3 deletions wallet/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const ERROR_AUTO_HIDE_PERIOD = 2000; // 2s
// TODO - verify balance refres rate
const BALANCE_INTERVAL = 60000;

const GAS_ESTIMATE_ENDPOINT =
process.env.GAS_ESTIMATE_ENDPOINT ||
'https://vqxy02tr5e.execute-api.us-east-2.amazonaws.com/production/estimateGas';
const { GAS_ESTIMATE_ENDPOINT } = process.env;

export {
DEFAULT_NF_ADDRESS_INDEX,
Expand Down
5 changes: 5 additions & 0 deletions wallet/.template.copy.env → wallet/template.copy.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
SKIP_PREFLIGHT_CHECK=true

## From Nightfall deployment repository, take ${PROPOSER_HOST}
PROPOSER_API_URL=https://

LOCAL_API_URL=http://localhost:8081

## From Nightfall deployment repository, take ${API_WS_SEND_ENDPOINT}
PROPOSER_WS_URL=wss://

LOCAL_WS_URL=ws://localhost:8082

LOCAL_UTIL_API_URL=http://localhost:8087

0 comments on commit 7f12f8f

Please sign in to comment.