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

zksync driver deposit (enter CLI command) #1208

Merged
merged 25 commits into from
Apr 22, 2021

Conversation

pnowosie
Copy link
Contributor

@pnowosie pnowosie commented Apr 6, 2021

Fixes PAY-64

Steps to test the command:

  • prepare .env file
  • provide valid eth node address for ZKSYNC_RINKEBY_GETH_ADDR key (e.g. infura) in the .env
  • run the service cargo run service run
  • open new terminal window and there run the following commands
  • cargo run payment fund --driver erc20
  • cargo run payment init --sender --driver zksync (will fail but unlocks the wallet of the zksync account)
  • cargo run payment enter --amount 5 --driver=zksync starts a deposit transaction. When successful will provide a link to track the transaction on the block explorer, e.g. example1 example2
  • when the transaction completes, funds can be seen with cargo run payment status --driver zksync

On the block explorer for Ethereum testnet you should see also 2 new transactions:

  • allowing ERC20 token deposit on zksync contract such this one
  • deposit transaction from L1 to ZkSync contract example

Copy link
Contributor

@maaktweluit maaktweluit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Left some comments, will approve on reply / fix

.await
.map_err(|err| GenericError::new(err))?;
info!(
"Check out deposit transaction at\nhttps://rinkeby.etherscan.io/tx/0x{}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new line in logs please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not me, cargo fmt is the one to blame ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt does not need to read the logs, our futures selves do ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misunderstood your original message - you mean \n new lines I added 😄

core/model/src/driver.rs Outdated Show resolved Hide resolved
core/payment-driver/zksync/src/zksync/signer.rs Outdated Show resolved Hide resolved
core/payment-driver/zksync/src/zksync/signer.rs Outdated Show resolved Hide resolved
@pnowosie pnowosie force-pushed the pnowosie/pay-65-zksync-driver-deposit branch from cd4cd8e to f7208de Compare April 13, 2021 06:40
@pnowosie
Copy link
Contributor Author

Regarding checking whether ETH balance covers GAS costs. ZkSync's ethereum client don't provide a function to get the actual gas price, their code is hardcoding 300k Wei for the deposit

When enter command is called without funds the following descriptive error is returned

Error: Network error: RPC error: Error { code: ServerError(-32000), message: "insufficient funds for gas * price + value", data: None }

I think it is good enough for now. 🤔 WDYT?

@pnowosie pnowosie marked this pull request as ready for review April 13, 2021 07:34
@pnowosie pnowosie requested a review from a team April 13, 2021 07:34
Copy link
Contributor

@maaktweluit maaktweluit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is good enough for now. 🤔 WDYT?

as long as the input values are logged i think this is sufficient :)

lots of nitty small comments:

  • only newline and std::env are important IMHO
  • formatting {:x} might need .as_bytes() or .as_fixed_bytes() to work

i have tested it OK previous review round, will test and approve on reply / fix

core/payment-driver/zksync/examples/deposit.rs Outdated Show resolved Hide resolved
core/payment-driver/zksync/examples/deposit.rs Outdated Show resolved Hide resolved
core/payment-driver/zksync/src/zksync/wallet.rs Outdated Show resolved Hide resolved
core/payment-driver/zksync/src/zksync/wallet.rs Outdated Show resolved Hide resolved
.await
.map_err(|err| GenericError::new(err))?;
info!(
"Check out deposit transaction at\nhttps://rinkeby.etherscan.io/tx/0x{}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo fmt does not need to read the logs, our futures selves do ;)

@@ -105,3 +113,56 @@ fn sign_tx(
});
Box::pin(fut)
}

pub fn encode_signed_tx(raw_tx: &RawTransaction, signature: Vec<u8>, chain_id: u64) -> Vec<u8> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be pub?

we can also move this to the base crate to share logic with gnt-driver ( i know i recommended against before, but now i see the need )

core/model/src/driver.rs Outdated Show resolved Hide resolved
core/payment-driver/zksync/src/driver.rs Show resolved Hide resolved
.env-template Outdated
@@ -52,6 +52,9 @@ YAGNA_DATADIR="."
## ZkSync driver
#ZKSYNC_RINKEBY_RPC_ADDRESS=https://rinkeby-api.zksync.io/jsrpc
#ZKSYNC_MAINNET_RPC_ADDRESS=https://api.zksync.io/jsrpc
#ZKSYNC_RINKEBY_GETH_ADDR=http://1.geth.testnet.golem.network:55555
#ZKSYNC_MAINNET_GETH_ADDR=http://geth.golem.network:55555
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should have separate env variables here. Are there legit cases when we would use different geth nodes for different drivers?

Copy link
Contributor Author

@pnowosie pnowosie Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was suggested by @maaktweluit

Even when we already have ERC20_MAINNET_GETH_ADDRESS and the RINKEBY version,
they are placed under erc20 driver section, so I think we can either:

  • prepare driver unspecific geth node address variables (supporting all cases)
  • leave it as is.

WDYT?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename he variables and use them in both drivers.
ERC20_RINKEBY_GETH_ADDR -> RINKEBY_GETH_ADDR
ERC20_MAINNET_GETH_ADDR -> MAINNET_GETH_ADDR

@pnowosie pnowosie requested a review from Wiezzel April 14, 2021 12:44
Wiezzel
Wiezzel previously approved these changes Apr 19, 2021
@pnowosie pnowosie requested a review from Wiezzel April 20, 2021 07:07
Wiezzel
Wiezzel previously approved these changes Apr 20, 2021
maaktweluit
maaktweluit previously approved these changes Apr 20, 2021
Copy link
Contributor

@maaktweluit maaktweluit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@pnowosie pnowosie dismissed stale reviews from maaktweluit and Wiezzel via 0271908 April 21, 2021 12:37
@pnowosie pnowosie requested a review from a team April 21, 2021 12:37
@pnowosie pnowosie removed the request for review from a team April 21, 2021 19:48
@pnowosie pnowosie enabled auto-merge (squash) April 22, 2021 05:17
@pnowosie pnowosie merged commit 793e700 into master Apr 22, 2021
@pnowosie pnowosie deleted the pnowosie/pay-65-zksync-driver-deposit branch April 22, 2021 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants