Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/provable-things/ptokens-erc777-smart-contract
The ETH smart contract for the Provable Token!
https://github.com/provable-things/ptokens-erc777-smart-contract
Last synced: about 13 hours ago
JSON representation
The ETH smart contract for the Provable Token!
- Host: GitHub
- URL: https://github.com/provable-things/ptokens-erc777-smart-contract
- Owner: provable-things
- License: mit
- Created: 2020-06-25T14:24:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-29T14:41:01.000Z (about 1 year ago)
- Last Synced: 2024-04-21T19:52:55.189Z (10 months ago)
- Language: JavaScript
- Size: 2.45 MB
- Stars: 2
- Watchers: 4
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :page_with_curl: Provable pToken ERC777 Smart-Contract & Deployer
This repo houses the Provable __pToken__ upgradeable ERC777 logic smart-contract, as well as a simple CLI to help with deployment & verification.
## :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 ERC777 Command Line Interface
Copyright Provable Things 2021
Questions: [email protected]❍ Info:
A tool to aid with deployments of & interactions with the upgradeable pToken ERC777 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'NOTE: The tool requires a '.env' file to exist in the root of the repository with the following info:
ENDPOINT=NOTE: To call the 'verifyContract' function, the following extra environment variable is required:
ETHERSCAN_API_KEY=❍ Usage:
cli.js --help
cli.js --version
cli.js showSuggestedFees
cli.js showWalletDetails
cli.js signMessage
cli.js deployWethContract
cli.js checkERC1820Exists
cli.js showExistingContracts
cli.js getAccountNonce
cli.js sendEth
cli.js pushRawSignedTx
cli.js getTransactionCount
cli.js deployContract [--withGSN=]
cli.js flattenContract [--withGSN=]
cli.js getOriginChainId
cli.js getBalanceOf
cli.js hasMinterRole
cli.js grantMinterRole
cli.js revokeMinterRole
cli.js approve
cli.js changeOriginChainId
cli.js transferToken
cli.js verifyContract [--withGSN=]
cli.js encodeInitArgs
cli.js pegOut [--userData=]❍ Commands:
deployContract ❍ Deploy the logic contract.
deployWethContract ❍ Deploy the wrapped ETH contract.
showSuggestedFees ❍ Show 'ethers.js' suggested fees.
pushRawSignedTx ❍ Push to the network.
verifyContract ❍ Verify the deployed logic contract.
sendEth ❍ Send of ETH to .
checkERC1820Exists ❍ Check the ERC1820 exists on this chain.
getTransactionCount ❍ Get the nonce of the passed in .
getAccountNonce ❍ Get the transaction count of the .
getOriginChainId ❍ Get origin chain ID of contract at .
getBalanceOf ❍ Get balance of of pToken at .
transferToken ❍ Transfer of token @ to .
showWalletDetails ❍ Decrypts the private key and shows address & balance information.
encodeInitArgs ❍ Calculate the initializer function arguments in ABI encoded format.
hasMinterRole ❍ See if has minter role on contract @ .
flattenContract ❍ Flatten the pToken contract in case manual verification is required.
grantMinterRole ❍ Grant a minter role to for pToken at .
revokeMinterRole ❍ Revoke a minter role from for pToken at .
approve ❍ Approve a to spend tokens at .
showExistingContracts ❍ Show list of existing pToken logic contract addresses on various blockchains.
changeOriginChainId ❍ Change the origin chain ID to of the contract at .
pegOut ❍ Redeem at to with optional --userData=.❍ Options:
--help ❍ Show this message.
--version ❍ Show tool version.
❍ A valid ETH address.
❍ The name of the pToken.
❍ The symbol of the pToken.
❍ A signed tx in hex format.
❍ The ETH address of the deployed pToken.
❍ The recipient of the pegged out pTokens.
❍ The origin chain ID of this pToken contract.
❍ The ETH address to administrate the pToken.
--userData= ❍ Optional user data in hex format [default: 0x].
❍ An amount in the most granular form of the token.
❍ A destination chain ID as a 'bytes4' solidity type.
❍ An ETH address that may spend tokens on your behalf.
signMessage ❍ Sign the passed in using the gpg encrypted key.
--withGSN= ❍ Use the version of the pToken with GasStationNetwork logic [default: true].
❍ Network the pToken is deployed on. It must exist in the 'hardhat.config.json'.```
### :radioactive: Secrets:
This tool requires a private key in order to sign transactions. GPG is used to protect the private key. To encrypt a private key using a GPG key from your keyring:
```
echo | gpg -e --output private-key.gpg
```Or, if you'd rather use a password to encrypt your keyfile, use this instead:
```
echo | gpg -c --output private-key.gpg
```The CLI also requires a JsonRPC endpoint for the blockchain you're interacting with. To easily provision this, create a `.env` file in the root of the repository and fill it in thusly:
```
ENDPOINT=
```Finally, to verify a contract, you'll need an etherscan API key too. You can add this to your `.env` file thusly:
```
ETHERSCAN_API_KEY=
```NOTE: If you're not verifying contracts, you don't need to provide this environment variable at all.
### :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: Tests:
1) Install dependencies:
```
❍ npm ci
```2) Run the tests:
```
❍ npm run tests
```Test output:
```
pToken ERC777GSN Tests
✓ Should transfer via relayer (396ms)
✓ When transferring via relay, it should pay fee in token (177ms)Admin Operator Tests WITH GSN
✓ Non-owner cannot change the admin operator address
✓ Admin operator CAN change the admin operator address
✓ `adminTransfer()` should fail if the caller is not the admin operator
✓ `adminTransfer()` should transfer tokensAdmin Operator Tests WITHOUT GSN
✓ Non-owner cannot change the admin operator address
✓ Admin operator CAN change the admin operator address
✓ `adminTransfer()` should fail if the caller is not the admin operator
✓ `adminTransfer()` should transfer tokens (38ms)pToken ERC1820 Tests WITH GSN
✓ Should mint to an externally owned account
✓ Should not mint to a contract that does not support ERC1820 (46ms)
✓ Should mint to a contract that supports ERC1820, and call `tokensReceivedHook` (95ms)pToken ERC1820 Tests WITHOUT GSN
✓ Should mint to an externally owned account
✓ Should not mint to a contract that does not support ERC1820 (71ms)
✓ Should mint to a contract that supports ERC1820, and call `tokensReceivedHook` (81ms)Testing Constructor Arg Encoder...
✓ Should get encoded pToken init fxn call
✓ Should get encoded proxy constructor args
✓ Should get encoded constructor argspToken Tests WITH GSN
Initialization Tests
✓ Origin chain id should be set correctly on deployment
Roles Tests
✓ Owner has 'default admin' role
✓ Owner has 'minter' role
✓ Owner can grant `minter` role
✓ Owner can revoke `minter` role (40ms)
✓ Newly added minter should be able to mint tokens & emit correct events (46ms)
✓ Should grant minter role to EOA
Mint Tests
✓ `mint()` w/out data should mint tokens & emit correct events
✓ `mint()` w/out data should return true if successful
✓ `mint()` cannot mint to zero address
✓ `mint()` only owner can mint
✓ `mint()` w/ data should mint tokens & emit correct events
✓ Should revert when minting tokens with the contract address as the recipient
Redeem Tests
✓ `redeem()` function should burn tokens & emit correct events (288ms)
✓ Should get redeem fxn call data correctly
Contract Upgrades Tests
✓ Should upgrade contract (100ms)
✓ User balance should remain after contract upgrade (96ms)
Change Origin ID Tests
✓ Owner can change origin ID
✓ Non owner cannot change origin IDpToken Tests WITHOUT GSN
Initialization Tests
✓ Origin chain id should be set correctly on deployment
Roles Tests
✓ Owner has 'default admin' role
✓ Owner has 'minter' role
✓ Owner can grant `minter` role
✓ Owner can revoke `minter` role (38ms)
✓ Newly added minter should be able to mint tokens & emit correct events (42ms)
✓ Should grant minter role to EOA
Mint Tests
✓ `mint()` w/out data should mint tokens & emit correct events
✓ `mint()` w/out data should return true if successful
✓ `mint()` cannot mint to zero address
✓ `mint()` only owner can mint
✓ `mint()` w/ data should mint tokens & emit correct events
✓ Should revert when minting tokens with the contract address as the recipient
Redeem Tests
✓ `redeem()` function should burn tokens & emit correct events (251ms)
✓ Should get redeem fxn call data correctly
Contract Upgrades Tests
✓ Should upgrade contract (89ms)
✓ User balance should remain after contract upgrade (75ms)
Change Origin ID Tests
✓ Owner can change origin ID
✓ Non owner cannot change origin ID57 passing (12s)
```
## :white_medium_square: To Do:
[x] Add tests for non-gsn version?
[ ] Allow custom gas prices?