renvm-gateway-registry-cli

CLI to interact with RenVM Gateway Registry program for Solana


License
GPL-3.0

Documentation

Gateway Ren-Solana

Ren Gateway implementation for Solana.

Refer the Wiki for an in-depth explanation of the program architecture.

CI

Development

Environment Setup

  1. Install the latest Rust stable from rustup
  2. Install the Solana CLI tools from here

Build and Test

  • Install NPM dependencies
$ npm install
  • Build the program against your host machine
$ cargo build
  • Build the program for Solana BPF target
$ cargo build-bpf
  • Run unit and integration tests
$ cargo test-bpf
  • Format and lint the code before contributing
$ cargo fmt --all
$ cargo clippy

Running locally

If you have Docker installed, you can easily set up a local network with

docker build -t ren-solana .
docker run --network=host ren-solana

This should deploy the gateway program for BTC/toSolana at FDdKRjbBeFtyu5c66cZghJsTTjDTT1aD3zsgTWMTpaifand the gateway-registry at DHpzwsdvAzq61PN9ZwQWg2hzwX8gYNfKAdsNKKtdKDux, along with all initialization steps

Deploy

# localnet
# npm solana-localnet up
$ solana config set --url http://localhost:8899
# Upon such an error: "Error: Connection refused (os error 111)", try:
# solana config set --url http://0.0.0.0:8899
#
# devnet
$ solana config set --url https://devnet.solana.com
# testnet
$ solana config set --url https://testnet.solana.com
# mainnet
$ solana config set --url https://api.mainnet-beta.solana.com
  • Create the deployer key
$ solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/deployer.json
  • Fund the deployer key
# localnet/devnet/testnet
$ solana airdrop 10 <ADDRESS>
# mainnet
# transfer SOL to $(solana address --keypair ~/.config/solana/deployer.json)
  • Create the upgrade-authority key. This key will authorize future upgrades
$ solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/upgrade-authority.json
  • Create the key whose address will hold the deployed gateway program. This is an optional step and if the --program-id flag is skipped, the program will be deployed to a random address.
$ solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/gateway-program.json
  • Deploy the gateway program. At the time of documenting this step, the gateway program's BPF bytecode was 215024 bytes. We allocate a max length of 20x to give enough room for future upgrades.
$ solana program deploy \
    --keypair ~/.config/solana/deployer.json \
    --upgrade-authority ~/.config/solana/upgrade-authority.json \
    --program-id ~/.config/solana/gateway-program.json \
    --max-len 4300480 \
    target/deploy/gateway.so
  • Safely store the deployer.json and upgrade-authority keys, and note down the address to which the program was deployed. That is, either from the solana program deploy command's stdout or
$ solana address --keypair ~/.config/solana/gateway-program.json

Initialize

  • Gateway CLI help menu
$ target/debug/gateway --help
  • Initialize the gateway for a Ren token. Skip the --renvm-authority flag for localnet testing using dummy signatures from the renvm-sig crate.
$ target/debug/gateway initialize \
    --owner ~/.config/solana/deployer.json \
    --fee-payer ~/.config/solana/deployer.json \
    --selector "BTC/toSolana" \
    --renvm-authority fEEfEeFeEfeeFeefeEFEeFeeFeEFEEFeEFeEFeee

Upgrade

  • Make changes to the program, and re-build it
$ cargo build-bpf
  • Upgrade the gateway program
$ solana program deploy \
    --keypair ~/.config/solana/deployer.json \
    --upgrade-authority ~/.config/solana/upgrade-authority.json \
    --program-id <PROGRAM-ADDRESS> \
    target/deploy/gateway.so
  • If you wish to make the program immutable (so that no future upgrades are possible)
$ solana program deploy --final \
    --keypair ~/.config/solana/deployer.json \
    --upgrade-authority ~/.config/solana/upgrade-authority.json \
    --program-id <PROGRAM-ADDRESS> \
    target/deploy/gateway.so

Gateway Registry

Ren-Solana ecosystem also provides support for a Gateway Registry. The registry is supposed to store the gateway program addresses for RenVM cross-chain selectors.

  • Create an owner for the registry
$ solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/gateway-registry-owner.json
  • Gateway registry's program account
$ solana-keygen new --no-bip39-passphrase --outfile ~/.config/solana/gateway-registry-program.json
  • Transfer sufficient funds to the gateway-registry-owner account
  • Deploy the registry
$ solana program deploy \
    --keypair ~/.config/solana/gateway-registry-owner.json \
    --program-id ~/.config/solana/gateway-registry-program.json \
    target/deploy/gateway_registry.so
  • Initialize the registry state
$ target/debug/gateway-registry initialize \
    --owner ~/.config/solana/gateway-registry-owner.json \
    --fee-payer ~/.config/solana/gateway-registry-owner.json
  • Add a gateway address to the registry
$ target/debug/gateway-registry update \
    --owner ~/.config/solana/gateway-registry-owner.json \
    --fee-payer ~/.config/solana/gateway-registry-owner.json \
    --selector "BTC/toSolana" \
    --gateway "9TaQuUfNMC5rFvdtzhHPk84WaFH3SFnweZn4tw9RriDP"
  • Remove a gateway address from the registry
$ target/debug/gateway-registry remove \
    --owner ~/.config/solana/gateway-registry-owner.json \
    --fee-payer ~/.config/solana/gateway-registry-owner.json \
    --selector "BTC/toSolana"