Skip to content

Commit

Permalink
Deposit erc20 tokens (#80)
Browse files Browse the repository at this point in the history
* Add ETH L2 contract address

* Start withdraw implementation

* Parse eth amount to wei

* Sign and send withdraw transaction

* Add address of messenger on L1

* Update types to U64 from ethers

* Start finalize withdraw function

* Add test for withdraw function

* Change field name of Proof struct to merkle proof

* Finish finalize withdraw function along with the test

* Fix format

* Add override struct to override transaction fields

* Fix withdraw and test case

* Delete estimate_gas function for ZKSProvider

* Use L1 provider for finalize withdraw

* Revert "Delete estimate_gas function for ZKSProvider"

This reverts commit 70f68ef.

* Add max fee per gas constant

* Change endpoint name to avoid collision between L1 and L2 nodes

* Fix transaction for finalize withdraw

* Fix finalize withdraw test

* Parse withdraw amount to wei

* Cleanup

* Add correct calculation for l2 to l1 log index

* Clean the finalize withdraw function

* Fix panic in finalize withdraw

* Add a sleep to wait to the proof to be posted on L1.

* Move send function to providers

* Fix "unknown account" error

* Fix finalize tx receipt

* Use tokio for sleep when withdrawing

* Add default value for gas

* Fix clippy lints

* Move send test to provider

* Remove FIXME

* Remove FIXME

* Remove FIXME

* Add another wallet in L1 for ZKSWallet creation

* Add address as parameter in withdraw function

* Fix clippy

* Create DepositRequest structure

* Implement other DepositRequest parameters

* Make DepositRequest public

* Use crate types

* Fix gas limit setter

* Fix gas_price setter

* Fix operator tip setter

* Fix l2_gas_limit setter

* Fix gas_per_pubdata_byte setter

* Remove unused sleeps

* Fix operator_tip setter

* Write ERC20 deposit test

* Fix ERC20 deposit test

* WIP ERC20 deposit implementation

* Simplify ERC20 deposit test

* Remove unused imports

* WIP ERC20 deposit implementation

* Include token approval call for erc20 deposit

* Add dep on lazy static

* Fix clippy errors

* Fix clippy errors

* Fix approve_erc20

* Skip ERC20 deposit test

* Add newline at EOF

* Fix lines that were removed by mistake

* Remove outdated comment

* Remove debug prints

* Remove unnecesary setter call

* Replace magic numbers with constants

* Make ABI loader private so we can use expect calls

- Why private?
  - This functionality is out of scope for our SDK.
  - It wasn't being used outside this module.
- I think that it is ok to go with the simplest solution right now. We
  could refactor this to emit an error in the future if necessary.
  - It makes sense to use `expect`/`unwrap` here because the
    `include_str!` macro ensures that the ABI JSON string is present.

* Make Ether the default token for deposit requests

* Remove outdated comment

* Fix ERC20 deposit test

---------

Co-authored-by: IAvecilla <[email protected]>
Co-authored-by: Iván Litteri <[email protected]>
Co-authored-by: Martin Paulucci <[email protected]>
  • Loading branch information
4 people authored Aug 29, 2023
1 parent e0ef89e commit e396a30
Show file tree
Hide file tree
Showing 15 changed files with 11,392 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
ethers = { version = "2.0.4", features = ["rustls"] }
ethers-contract = "2.0.7"
clap = { version = "4.2.7", features = ["derive"] }
lazy_static = "1.4.0"

# Async
tokio = { version = "1", features = ["macros", "process"] }
Expand Down
10,232 changes: 10,232 additions & 0 deletions resources/testing/erc20/ERC20Token.json

Large diffs are not rendered by default.

286 changes: 286 additions & 0 deletions resources/testing/erc20/MyToken.json

Large diffs are not rendered by default.

277 changes: 277 additions & 0 deletions resources/testing/erc20/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "subtractedValue",
"type": "uint256"
}
],
"name": "decreaseAllowance",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "addedValue",
"type": "uint256"
}
],
"name": "increaseAllowance",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
Loading

0 comments on commit e396a30

Please sign in to comment.