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?