Code Monkey home page Code Monkey logo

ptokens-router's Introduction

๐Ÿ“ƒ Provable pToken Router Smart Contract

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.

ย 

๐Ÿ’ฅ Usage Guide:

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'.

ย 

โ˜ข๏ธ 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 <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.

ย 

โœ’๏ธ 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 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.

ย 

๐Ÿ’‚โ€โ™‚๏ธ Tests:

  1. Install dependencies:
โ npm ci
  1. 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)

ย 

๐Ÿค– Metadata Chain Ids

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
}

ย 

โ—ป๏ธ To Do:

[ ] Allow custom gas prices? [ ] Add tests for non-gsn version?

ptokens-router's People

Contributors

gskapka avatar gitmp01 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.