This repo houses the Provable pToken v2 upgradeable Router logic smart-contract, as well as a simple CLI to help with deployment of, verification of & interacting with it.
After cloning the repository, first install the dependencies:
> npm ci
Then, to see the usage guide, run:
> ./cli.js --help
Output:
node cli.js --help
❍ pTokens Router Contract Command Line Interface
Copyright Provable Things 2021
Questions: [email protected]
❍ Info:
A tool to aid with deployments of & interactions with the upgradeable pToken Router 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 <your-private-key> | 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=<rpc-endpoint-for-blochain-to-interact-with>
NOTE: To call the 'verifyRouterContract' function, this extra environment variable is required:
ETHERSCAN_API_KEY=<api-key-for-automated-contract-verifications>
❍ Usage:
cli.js --help
cli.js --version
cli.js showChainIds
cli.js showWalletDetails
cli.js deployRouterContract
cli.js showExistingContracts
cli.js deploySafeVaultContract
cli.js getAdmins <deployedAddress>
cli.js encodeInitArgs <ethAddress>
cli.js getRouterState <deployedAddress>
cli.js getVaultAddresses <deployedAddress>
cli.js getSupportedTokens <deployedAddress>
cli.js getSafeVaultAddress <deployedAddress>
cli.js getVaultAddress <deployedAddress> <chainId>
cli.js setFeeAddress <deployedAddress> <ethAddress>
cli.js removeVaultAddress <deployedAddress> <chainId>
cli.js verifyRouterContract <network> <deployedAddress>
cli.js setSafeVaultAddress <deployedAddress> <ethAddress>
cli.js addVaultAddress <deployedAddress> <chainId> <ethAddress>
cli.js transferFromSafeVault <deployedAddress> <tokenAddress> <ethAddress> <amount>
❍ Commands:
deploySafeVaultContract ❍ Deploy the safe vault contract.
deployRouterContract ❍ Deploy the router logic contract.
verifyRouterContract ❍ Verify the router logic contract.
transferFromSafeVault ❍ Transfer tokens from the safe vault.
getVaultAddresses ❍ Gets all set vault addresses at <deployedAddress>.
getAdmins ❍ Get the admins of the contract at <deployedAddress>.
getSupportedTokens ❍ Get list of all supported tokens in the interim vaults
setSafeVaultAddress ❍ Set the address of the safe vault in the router contract.
setFeeAddress ❍ Set the fee contract stored in the router to <ethAddress>.
removeVaultAddress ❍ Removess vault address with <chainId> from <deployedAddress>.
getVaultAddress ❍ Get vault address from router at <deployedAddress> via <chainId>.
showWalletDetails ❍ Decrypts the private key and shows address & balance information.
getSafeVaultAddress ❍ Get the safe vault address set in the router at <deployedAddress>.
getRouterState ❍ Gets all supported tokens from all vaults set in <deployedAddress>.
encodeInitArgs ❍ Calculate the initializer function arguments in ABI encoded format.
addVaultAddress ❍ Adds <ethAddress> as vault address with <chainId> to <deployedAddress>.
showChainIds ❍ Shows a list of the metadata chain IDs for supported pNetwork blockchains.
showExistingContracts ❍ Show list of existing pToken logic contract addresses on various blockchains.
❍ Options:
--help ❍ Show this message.
--version ❍ Show tool version.
<ethAddress> ❍ A valid ETH address.
<tokenAddress> ❍ A valid token address.
<deployedAddress> ❍ The ETH address of the deployed pToken.
<amount> ❍ An amount of tokens, in their most granular unit.
<chainId> ❍ A pToken metadata chain ID, as a 'bytes4' solidity type.
<network> ❍ Network the contract is deployed on. It must exist in the 'hardhat.config.json'.
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 <your-private-key> | gpg -e --output private-key.gpg
Or, if you'd rather use a password to encrypt your keyfile, use this instead:
echo <your-private-key> | 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=<ethRpcEndpoint>
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=<apikey>
NOTE: If you're not verifying contracts, you don't need to provide this environment variable at all.
-
To simplify deployments, the tool uses
ethers.js
suggested fees for deployment. The CLI functionshowSuggestedFees
will show you the currently suggested fees, including EIP1559 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 thepToken
contract into a single.sol
file that can then be used for manual verification.
- Install dependencies:
❍ npm ci
- Run the tests:
❍ npm run tests
Test output:
Convert Address To String
✓ Should convert address type to string correctly (1018ms)
Metadata Encoder
✓ Should encode metadata
✓ Should encode user data
✓ Should encode user data in metadata
pTokens Router Contract
Ownership tests...
✓ Owner can add vault addresses
✓ Owner can remove vault addresses
✓ Non owner cannot add vault addresses (38ms)
✓ Non owner cannot add vault addresses (40ms)
Metadata decoding tests...
✓ Should decode metadata...
✓ Should decode userdata to destination chain and address...
10 passing (2s)
Here is a list of the metadata chain IDs currently supported by the core. Additinally, the file definining them can be found in the pTokens core repository here.
pub enum MetadataChainId {
EthereumMainnet, // 0x005fe7f9
EthereumRopsten, // 0x0069c322
EthereumRinkeby, // 0x00f34368
BitcoinMainnet, // 0x01ec97de
BitcoinTestnet, // 0x018afeb2
EosMainnet, // 0x02e7261c
TelosMainnet, // 0x028c7109
BscMainnet, // 0x00e4b170
EosJungleTestnet, // 0x0282317f
XDaiMainnet, // 0x00f1918e
PolygonMainnet, // 0x0075dd4c
UltraMainnet, // 0x025d3c68
FioMainnet, // 0x02174f20
UltraTestnet, // 0x02b5a4d6
EthUnknown, // 0x00000000
BtcUnknown, // 0x01000000
EosUnknown, // 0x02000000
InterimChain, // 0xffffffff
FantomMainnet, // 0x0022af98
ArbitrumMainnet, // 0x00ce98c4
LuxochainMainnet, // 0x00d5beb0
}
[ ] Allow custom gas prices? [ ] Add tests for non-gsn version?