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

Update contracts, scripts and guide to work with Aurora #14

Merged
merged 11 commits into from
May 7, 2021
Merged
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
55 changes: 40 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

## Deployments

| Version | Description | Status | Ethereum Connector Address | NEAR Connector Account |
|---------|------------------------|-------------|--------------------------------------------|------------------------|
| v0.1 | NEAR testnet - Ropsten | [Working](https://explorer.testnet.near.org/accounts/v01.kconnector.testnet) | 0xE3eBE85E0c42cC59cF09a1367d2CA30B26639659 | v01.kconnector.testnet |
| v0.2 | NEAR testnet - Ropsten | [Working](https://explorer.testnet.near.org/accounts/v02.kconnector.testnet) | 0x4dE5E423CA193dF67081A1BAb17d253B55d63688 | v02.kconnector.testnet |
| no-std | NEAR testnet - Ropsten | [Working](https://explorer.testnet.near.org/accounts/nostd-v01.kconnector.testnet) | 0x88657f6D4c4bbDB193C2b0B78DD74cD38479f819 | nostd-v01.kconnector.testnet |
| Version | Description | Status | Ethereum Connector Address | NEAR Connector Account |
|----------------|------------------------|-------------|--------------------------------------------|------------------------|
| aurora-v0.1 | NEAR testnet - Ropsten | [Working](https://explorer.testnet.near.org/accounts/v01.kconnector.testnet) | 0x4D8C60b494f02D76CC9D41F835029eC7Ff1A4881 | a01.kconnector.testnet |

# Step-by-step testing guide

Expand Down Expand Up @@ -43,8 +41,8 @@

3. Create `.env` file inside `eth-custodian` directory: `$ touch .env`.

4. Add to the file your Alchemy API key:
`$ echo "ALCHEMY_API_KEY=YOUR_ALCHEMY_API_KEY_HERE" >> .env` <br/>
4. Add to the file your RPC endpoint (with or without API key):
`$ echo "WEB3_RPC_ENDPOINT=YOUR_WEB3_RPC_ENDPOINT_HERE" >> .env` <br/>
RPC access can be easily gained from [Alchemy](https://www.alchemyapi.io/).

5. Add to the file Ropsten Private key:
Expand All @@ -54,6 +52,16 @@ RPC access can be easily gained from [Alchemy](https://www.alchemyapi.io/).
and `/Users/<user>/.near-credentials` on MacOS: <br/>
`$ echo "NEAR_KEY_STORE_PATH=PATH_TO_YOUR_NEAR_CREDENTIALS_HERE" >> .env`

7. Compile Ethereum contracts with: <br/>
`$ make compile`

## Utilities
To get the balance of bridgedETH (NEP-141):
`$ make near-ft-balance-of NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE>`

To get the balance of nETH (native ETH in Aurora-EVM):
`$ make near-ft-balance-of-eth NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE> ETH_ADDRESS=<ETH_ADDRESS_OF_ACCOUNT_IN_EVM_HERE>`

## Ethereum -> Near transfer (ETH -> bridgedETH (NEP-141))
1. Go to _eth-custodian_ directory: `$ cd eth-custodian`.

Expand All @@ -63,16 +71,16 @@ and deposit `AMOUNT` (wei) having `FEE` (wei) to `NEAR_RECIPIENT` account on Nea
Run: `$ make eth-deposit-to-near NEAR_RECIPIENT=<ACCOUNT_ID_OF_RECIPIENT_HERE> AMOUNT=<DEPOSIT_AMOUNT_HERE> FEE=<DEPOSIT_FEE_HERE>`.

3. **Wait sufficiently long**
You need to wait for 30 confirmations for Ropsten blockchain. This is needed to achieve finality of Ropsten block, including locking transaction.
You need to wait for 3 confirmations for Ropsten blockchain. This is needed to achieve finality of Ropsten block, including locking transaction.
The status of syncing of the bridge can be observed [here](http://35.235.76.186:8002/metrics).
First metric (`near_bridge_eth2near_client_block_number`) should become more than the height of a block with transaction from the step 2 at least by 30,
First metric (`near_bridge_eth2near_client_block_number`) should become more than the height of a block with transaction from the step 2 at least by 3,
for successfull finalisation of the transfer.

4. **Finalise deposit to Near**
Call deposit in Near blockchain to finalise the deposit transaction with the given `TX_HASH`. You can find `TX_HASH` in the output of the previous step.
You will need to provide your `NEAR_ACCOUNT` AccountId which will be used to relay the ETH proof to the Near blockchain to mint appropriate amount of
bridgedETH for the `NEAR_RECIPIENT` (this parameter is optional here and only serves for verbose purposes to show the balance of the recipient before and after) <br/>
Run: `$ make eth-finalise-deposit-to-near TX_HASH=<DEPOSIT_TX_HASH_HERE> NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE> NEAR_RECIPIENT=<RECIPIENT_HERE>`
Run: `$ make near-finalise-deposit-from-eth TX_HASH=<DEPOSIT_TX_HASH_HERE> NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE> NEAR_RECIPIENT=<RECIPIENT_HERE>`

## Near -> Ethereum transfer (bridgedETH -> ETH)
1. Go to _eth-custodian_ directory: `$ cd eth-custodian`.
Expand All @@ -81,20 +89,37 @@ Run: `$ make eth-finalise-deposit-to-near TX_HASH=<DEPOSIT_TX_HASH_HERE> NEAR_AC
Send a `withdraw` transaction to the bridgedETH contract to withdraw `AMOUNT` bridgedETH (wei) from the `NEAR_ACCOUNT` and
transfer the appropriate amount of ETH (wei) to `ETH_RECIPIENT` (Specify without '0x' prefix).
During the execution, the contract will issue an execution outcome, which would be used during finalisation step to contruct the proof for the EthCustodian in Ethereum. <br/>
Run: `$ make near-withdraw-to-eth NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE> ETH_RECIPIENT=<ETH_ADDRESS_OF_RECIPIENT_HERE> AMOUNT=<WITHDRAW_AMOUNT_HERE>` FEE=<WITHDRAW_FEE_HERE>
Run: `$ make near-withdraw-to-eth NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE> ETH_RECIPIENT=<ETH_ADDRESS_OF_RECIPIENT_HERE> AMOUNT=<WITHDRAW_AMOUNT_HERE> FEE=<WITHDRAW_FEE_HERE>`

3. **Wait sufficiently long**
This approximately takes 10 minutes for the Ropsten bridge deployment.
This is needed to relay NEAR block with the height higher than the block with transaction from previous step to Ethereum, plus wait a challenge period.
The status of syncing of the bridge can be observed [here](http://35.235.76.186:8001/metrics).
First metric `near_bridge_near2eth_client_height` should become higher than the block height displayed in console during the previous step.
4. **Finalise withdraw to Eth**
Call withdraw in Near blockchain to finalise the deposit transaction with the given `TX_HASH`. You can find `TX_HASH` in the output of the previous step.
Call withdraw in Near blockchain to finalise the deposit transaction with the given `RECEIPT_ID`. You can find `RECEIPT_ID` in the output of the previous step.
Send a `withdraw` transaction to the EthCustodian contract. After bridge syncing we are able to prove the fact of withdrawal transaction on NEAR to the EthCustodian contract. <br/>
Run: `$ make near-finalise-withdraw-to-eth TX_HASH=<WITHDRAW_TX_HASH_HERE>`
Run: `$ make eth-finalise-withdraw-from-near RECEIPT_ID=<RECEIPT_ID_FROM_STEP_2_HERE> NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE>`

## Ethereum -> Near transfer (ETH -> nETH (native ETH in Near-EVM))
WIP
## Ethereum -> Near transfer (ETH -> nETH (native ETH in Aurora-EVM))
1. Go to _eth-custodian_ directory: `$ cd eth-custodian`.

2. **Transfer ETH to EthCustodian**.
Send `depositToEVM` transaction to EthCustodian contract. This will transfer `AMOUNT` (wei) from your account
and deposit `AMOUNT` (wei) having `FEE` (wei) to `NEAR_RECIPIENT` account on Near. <br/>
Run: `$ make eth-deposit-to-evm ETH_RECIPIENT=<ETH_ADDRESS_OF_RECIPIENT_IN_EVM_HERE> AMOUNT=<DEPOSIT_AMOUNT_HERE> FEE=<DEPOSIT_FEE_HERE>`.

3. **Wait sufficiently long**
You need to wait for 3 confirmations for Ropsten blockchain. This is needed to achieve finality of Ropsten block, including locking transaction.
The status of syncing of the bridge can be observed [here](http://35.235.76.186:8002/metrics).
First metric (`near_bridge_eth2near_client_block_number`) should become more than the height of a block with transaction from the step 2 at least by 3,
for successfull finalisation of the transfer.

4. **Finalise deposit to Near**
Call deposit in Near blockchain to finalise the deposit transaction with the given `TX_HASH`. You can find `TX_HASH` in the output of the previous step.
You will need to provide your `NEAR_ACCOUNT` AccountId which will be used to relay the ETH proof to the Near blockchain to mint appropriate amount of
bridgedETH for the `NEAR_RECIPIENT` (this parameter is optional here and only serves for verbose purposes to show the balance of the recipient before and after) <br/>
Run: `$ make near-finalise-deposit-from-eth-to-evm TX_HASH=<DEPOSIT_TX_HASH_HERE> NEAR_ACCOUNT=<YOUR_NEAR_ACCOUNT_HERE> NEAR_RECIPIENT=<RECIPIENT_HERE>`

## Near -> Ethereum transfer (nETH -> ETH)
WIP
45 changes: 27 additions & 18 deletions eth-custodian/Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
.PHONY: compile test

NETWORK=ropsten
VERSION=v02
VERSION=a01
NEAR_EVM_ACCOUNT=${VERSION}.kconnector.testnet
NEAR_ACCOUNT=
RPC_ENDPOINT=https://rpc.testnet.near.org
ETH_RECIPIENT=
ETH_ADDRESS=
AMOUNT=0
FEE=0
PROOF=
TX_HASH=
RECEIPT_ID=
NO_STD=false

NEAR_RECIPIENT=${NEAR_ACCOUNT}

Expand All @@ -37,35 +37,44 @@ eth-withdraw:
yarn hardhat run --network ${NETWORK} scripts/eth_withdraw.js

eth-generate-deposit-proof:
mkdir -p build/proofs && yarn hardhat --network ${NETWORK} eth-generate-deposit-proof --tx-hash ${TX_HASH} --deposited-to-near ${DEPOSITED_TO_NEAR}
mkdir -p build/proofs && yarn hardhat --network ${NETWORK} eth-generate-deposit-proof --tx-hash ${TX_HASH}

eth-finalise-deposit-to-near:
yarn hardhat --network ${NETWORK} eth-finalise-deposit-to-near --tx-hash ${TX_HASH} --near-account ${NEAR_ACCOUNT}
eth-finalise-withdraw-from-near:
yarn hardhat --network ${NETWORK} eth-finalise-withdraw-from-near --receipt-id ${RECEIPT_ID} --near-account ${NEAR_ACCOUNT}

near-get-balance-of:
near view ${NEAR_EVM_ACCOUNT} ft_balance_of '{ "account_id": "${NEAR_ACCOUNT}" }'
near-finalise-deposit-from-eth:
yarn hardhat --network ${NETWORK} near-finalise-deposit-from-eth --tx-hash ${TX_HASH} --near-account ${NEAR_ACCOUNT} --near-recipient ${NEAR_RECIPIENT} --deposited-to-near true

near-call-withdraw-from:
near call ${NEAR_EVM_ACCOUNT} withdraw --account-id ${NEAR_ACCOUNT} \
'{ "recipient_id": "${ETH_RECIPIENT}", "amount": "${AMOUNT}" }'
near-finalise-deposit-from-eth-to-evm:
yarn hardhat --network ${NETWORK} near-finalise-deposit-from-eth --tx-hash ${TX_HASH} --near-account ${NEAR_ACCOUNT} --eth-recipient ${ETH_RECIPIENT}

near-withdraw-to-eth:
yarn hardhat --network ${NETWORK} near-withdraw-to-eth \
--near-account ${NEAR_ACCOUNT} --eth-recipient ${ETH_RECIPIENT} --amount ${AMOUNT} --fee ${FEE} --no-std ${NO_STD}
near-ft-balance-of:
yarn hardhat near-ft-balance-of --near-account ${NEAR_ACCOUNT}

near-finalise-withdraw-to-eth:
yarn hardhat --network ${NETWORK} near-finalise-withdraw-to-eth --receipt-id ${RECEIPT_ID} --near-account ${NEAR_ACCOUNT}
near-ft-balance-of-eth:
yarn hardhat near-ft-balance-of-eth --near-account ${NEAR_ACCOUNT} --eth-address ${ETH_ADDRESS}

near-withdraw-bridged-eth:
yarn hardhat --network ${NETWORK} near-withdraw-bridged-eth \
--near-account ${NEAR_ACCOUNT} --eth-recipient ${ETH_RECIPIENT} --amount ${AMOUNT} --fee ${FEE}

near-get-tx-status:
/usr/bin/http post ${RPC_ENDPOINT} jsonrpc=2.0 method=EXPERIMENTAL_tx_status \
params:='["${TX_HASH}", "${NEAR_ACCOUNT}"]' id=dontcare

near-deposit:
_near-deposit:
near call ${NEAR_EVM_ACCOUNT} deposit --account-id ${NEAR_ACCOUNT} --gas 300000000000000 '{"proof": ${PROOF}}'

near-deposit-to-nostd:
_near-deposit-to-nostd:
near call ${NEAR_EVM_ACCOUNT} deposit '${PROOF}' --account-id ${NEAR_ACCOUNT} --gas 300000000000000

near-call-withdraw-from-nostd:
_near-call-withdraw-from:
near call ${NEAR_EVM_ACCOUNT} withdraw --account-id ${NEAR_ACCOUNT} \
'{ "recipient_id": "${ETH_RECIPIENT}", "amount": "${AMOUNT}" }'

_near-call-withdraw-from-nostd:
near call ${NEAR_EVM_ACCOUNT} withdraw --account-id ${NEAR_ACCOUNT} \
'{ "recipient_id": "${ETH_RECIPIENT}", "amount": ${AMOUNT} }'

aurora-init-eth-connector:
yarn hardhat --network ${NETWORK} aurora-init-eth-connector --near-account ${NEAR_ACCOUNT}
21 changes: 9 additions & 12 deletions eth-custodian/contracts/EthCustodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ import "rainbow-bridge/contracts/eth/nearbridge/contracts/Borsh.sol";
import { INearProver, ProofKeeper } from "./ProofKeeper.sol";

contract EthCustodian is ProofKeeper {
event DepositedToEVM (
event Deposited (
address indexed sender,
address indexed ethRecipientOnNear,
uint256 amount,
uint256 fee
);

event DepositedToNear (
address indexed sender,
string nearRecipient,
string recipient,
uint256 amount,
uint256 fee
);
Expand Down Expand Up @@ -44,12 +37,16 @@ contract EthCustodian is ProofKeeper {
/// Deposits the specified amount of provided ETH (except from the relayer's fee) into the smart contract.
/// `ethRecipientOnNear` - the ETH address of the recipient in NEAR EVM
/// `fee` - the amount of fee that will be paid to the near-relayer in nETH.
function depositToEVM(address ethRecipientOnNear, uint256 fee)
function depositToEVM(string memory ethRecipientOnNear, uint256 fee)
external
payable
{
require(fee < msg.value, "The fee cannot be bigger than the transferred amount.");
emit DepositedToEVM(msg.sender, ethRecipientOnNear, msg.value, fee);

string memory separator = ":";
string memory protocolMessage = string(abi.encodePacked(string(nearProofProducerAccount_), separator, ethRecipientOnNear));

emit Deposited(msg.sender, protocolMessage, msg.value, fee);
}

/// Deposits the specified amount of provided ETH (except from the relayer's fee) into the smart contract.
Expand All @@ -60,7 +57,7 @@ contract EthCustodian is ProofKeeper {
payable
{
require(fee < msg.value, "The fee cannot be bigger than the transferred amount.");
emit DepositedToNear(msg.sender, nearRecipientAccountId, msg.value, fee);
emit Deposited(msg.sender, nearRecipientAccountId, msg.value, fee);
}

/// Withdraws the appropriate amount of ETH which is encoded in `proofData`
Expand Down
23 changes: 10 additions & 13 deletions eth-custodian/dist/EthCustodian.full.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Sources flattened with hardhat v2.0.10 https://hardhat.org

// File @openzeppelin/contracts/math/[email protected].0
// File @openzeppelin/contracts/math/[email protected].1


pragma solidity >=0.6.0 <0.8.0;
Expand Down Expand Up @@ -825,16 +825,9 @@ pragma solidity ^0.6.12;


contract EthCustodian is ProofKeeper {
event DepositedToEVM (
event Deposited (
address indexed sender,
address indexed ethRecipientOnNear,
uint256 amount,
uint256 fee
);

event DepositedToNear (
address indexed sender,
string nearRecipient,
string recipient,
uint256 amount,
uint256 fee
);
Expand Down Expand Up @@ -863,12 +856,16 @@ contract EthCustodian is ProofKeeper {
/// Deposits the specified amount of provided ETH (except from the relayer's fee) into the smart contract.
/// `ethRecipientOnNear` - the ETH address of the recipient in NEAR EVM
/// `fee` - the amount of fee that will be paid to the near-relayer in nETH.
function depositToEVM(address ethRecipientOnNear, uint256 fee)
function depositToEVM(string memory ethRecipientOnNear, uint256 fee)
external
payable
{
require(fee < msg.value, "The fee cannot be bigger than the transferred amount.");
emit DepositedToEVM(msg.sender, ethRecipientOnNear, msg.value, fee);

string memory separator = ":";
string memory protocolMessage = string(abi.encodePacked(string(nearProofProducerAccount_), separator, ethRecipientOnNear));

emit Deposited(msg.sender, protocolMessage, msg.value, fee);
}

/// Deposits the specified amount of provided ETH (except from the relayer's fee) into the smart contract.
Expand All @@ -879,7 +876,7 @@ contract EthCustodian is ProofKeeper {
payable
{
require(fee < msg.value, "The fee cannot be bigger than the transferred amount.");
emit DepositedToNear(msg.sender, nearRecipientAccountId, msg.value, fee);
emit Deposited(msg.sender, nearRecipientAccountId, msg.value, fee);
}

/// Withdraws the appropriate amount of ETH which is encoded in `proofData`
Expand Down
2 changes: 1 addition & 1 deletion eth-custodian/dist/ProofKeeper.full.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface INearProver {
}


// File @openzeppelin/contracts/math/[email protected].0
// File @openzeppelin/contracts/math/[email protected].1


pragma solidity >=0.6.0 <0.8.0;
Expand Down
2 changes: 1 addition & 1 deletion eth-custodian/dist/ProofKeeperInheritorMock.full.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Sources flattened with hardhat v2.0.10 https://hardhat.org

// File @openzeppelin/contracts/math/[email protected].0
// File @openzeppelin/contracts/math/[email protected].1


pragma solidity >=0.6.0 <0.8.0;
Expand Down
Loading