Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/provable-things/ptokens-erc20-vault
The pToken pERC20-on-EOS smart-contract & management CLI.
https://github.com/provable-things/ptokens-erc20-vault
Last synced: about 14 hours ago
JSON representation
The pToken pERC20-on-EOS smart-contract & management CLI.
- Host: GitHub
- URL: https://github.com/provable-things/ptokens-erc20-vault
- Owner: provable-things
- License: mit
- Created: 2020-09-15T15:43:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-05-17T12:53:34.000Z (over 1 year ago)
- Last Synced: 2024-04-21T19:52:55.202Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.57 MB
- Stars: 2
- Watchers: 6
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :page_with_curl: Provable pToken ERC20 Vault Smart-Contract
This repo houses the upgradeable ERC20-Vault logic smart-contract, as well as a simple CLI to help with deployment, verification & interacting with it.
## :boom: Usage Guide:
After cloning the repository, first install the dependencies:
```
> npm ci
```Then, to see the usage guide, run:
```
> ./cli.js --help
```Output:
```
❍ pTokens ERC20 Vault Command Line InterfaceCopyright Provable Things 2021
Questions: [email protected]❍ Info:
A tool to aid with deployments of & interactions with the upgradeable pToken ERC20 vault logic contract.
NOTE: Functions that make transactions require a private key. Please provide a GPG encrpyted file called
'private-key.gpg' containing your key in the root of the repository. Create one via:
'echo | gpg -c --output private-key.gpg'
Multiple private keys may be provisioned, and the tool will provide you with a list to select from.NOTE: The tool requires a '.env' file to exist in the root of the repository with the following info:
ENDPOINT=
Multiple such files may be provisioned, and the tool will provide you with a list to select from.NOTE: To call functions which verify contracts, the following extra environment variable is required:
ETHERSCAN_API_KEY=❍ Usage:
cli.js --help
cli.js --version
cli.js flattenContract
cli.js showSuggestedFees
cli.js showWalletDetails
cli.js deployVaultContract
cli.js showExistingContracts
cli.js getPNetwork
cli.js getWEthAddress
cli.js getSupportedTokens
cli.js deployUnwrapperContract
cli.js setPNetwork
cli.js verifyVaultContract
cli.js isTokenSupported
cli.js addSupportedToken
cli.js setWEthUnwrapperAddress
cli.js verifyUnwrapperContract
cli.js encodeInitArgs [--token=...]
cli.js pegIn [--userData=]❍ Commands:
setPNetwork ❍ Set the pNetwork address.
showSuggestedFees ❍ Show 'ethers.js' suggested fees.
deployUnwrapperContract ❍ Deploy the WETH unwrapper contract.
deployVaultContract ❍ Deploy the ERC20 vault logic contract.
verifyVaultContract ❍ Verify a deployed pToken logic contract.
verifyUnwrapperContract ❍ Verify a deployed WETH unwrapper contract.
getPNetwork ❍ Show the pNetwork address of the vault at .
getWEthAddress ❍ Show the wETH address set in the vault at .
flattenContract ❍ Flatten the contract in case manual verification is required.
getSupportedTokens ❍ Show list of tokens supprted by the vault at .
showWalletDetails ❍ Decrypts the private key and shows address & balance information.
isTokenSupported ❍ Is token at supported in vault at .
encodeInitArgs ❍ Calculate the initializer function arguments in ABI encoded format.
showExistingContracts ❍ Show list of existing logic contract addresses on various blockchains.
addSupportedToken ❍ Adds token at to the supported tokens in vault at .
pegIn ❍ Peg in of to on .
setWEthUnwrapperAddress ❍ Sets the WETH unwrapper contract at in the vault at .❍ Options:
--help ❍ Show this message.
--version ❍ Show tool version.
❍ A valid ETH address.
❍ ETH address of token.
❍ The ETH address of the deployed vault.
❍ Destination address of a token peg in.
--userData= ❍ User data in hex format [default: 0x].
--token= ❍ ETH addresses of tokens the vault will support.
❍ Amount of tokens in their most granular format.
❍ Metadata chain ID of the chain this contract is deployed to.
❍ Metadata chain ID of the chains this contract supports peg-ins to.
❍ The address for the wrapped ETH token on the blockchain to be deployed to.
❍ Network the vault is deployed on. It must exist in the 'hardhat.config.json'.```
### :black_nib: Notes:
- To simplify deployments, the tool uses __`ethers.js`__ suggested fees for deployment. The CLI function __`showSuggestedFees`__ will show you the currently suggested fees, including __[EIP1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)__ specific values if the chain you're working with is EIP1559 compaible.
- In case the chain you're deploying to does not have etherscan-style contract verification which works with the hardhat plugin, there exists the __`flattenContract`__ command. This will flatten the __`pToken`__ contract into a single __`.sol`__ file that can then be used for manual verification.
### :guardsman: Smart-Contract Tests:
1) Install dependencies
```
❍ npm ci
```2) Run the tests via:
```
❍ npm run tests
```Test output:
```
Erc20Vault Tests
Initalizer Tests
✓ Token addresses sent to constructor should be supported (250ms)
Ownership Tests
✓ PNETWORK_ADDRESS can change PNETWORK_ADDRESS (55ms)
✓ NON_PNETWORK_ADDRESS cannot change PNETWORK_ADDRESS (62ms)
✓ Should not be able to set pNetwork address to the zero address
Token Approval Tests
✓ PNETWORK_ADDRESS can add appoved token address
✓ NON_PNETWORK_ADDRESS cannot add appoved token address
✓ PNETWORK_ADDRESS can remove appoved token address
✓ NON_PNETWORK_ADDRESS cannot remove appoved token address
Peg In Tests
✓ Should NOT peg in if token is not supported
✓ Should NOT peg in if token is supported but insufficient allowance approved
✓ Should NOT peg in supported token if sufficient allowance approved, but token amount is 0
✓ Should peg in if token is supported and sufficient allowance approved (54ms)
✓ Should peg in with user data (47ms)
ERC777 Peg In Tests
✓ Should automatically peg in on ERC777 send (41ms)
✓ Should peg in an ERC777 token
Peg Out Tests
✓ NON_PNETWORK_ADDRESS cannot peg out (45ms)
✓ PNETWORK_ADDRESS cannot peg out if insufficient balance
✓ PNETWORK_ADDRESS can peg out with sufficient balance (61ms)
✓ Can peg out with user data (70ms)
✓ Pegging out to ERC777 recipient with user data will call tokens recieved hook (91ms)
wETH Tests
Peg In wETH Tests
✓ Should peg in wETH
✓ Should peg in wETH with user data
Peg Out wETH Tests
✓ Should peg out wETH without user data
✓ Should peg out wETH with user data
✓ Should peg out wETH to smart-contract w/ expensive fallback function (56ms)
✓ Should be able to peg out wETH with user data to a smart-contract (69ms)
✓ Should not fail to peg out wETH with user data to an EOA
✓ Pegging out wETH Should not be susceptible to re-entrancy attack (55ms)28 passing (8s)
```
## :white_medium_square: To Do:
[ ] Allow custom gas prices in CLI?