Skip to content

Levana Well Funded Perpetual Swaps - smart contract, testing, and backend code

License

Notifications You must be signed in to change notification settings

Levana-Protocol/levana-perps

Repository files navigation

Introduction

This is perps v2, following a completely new financial model, without a vAMM

It's also an updated dev environment, with multichain support and a native SDK in both Typescript and Rust/WASM (no Rust binary sdk yet..)

PREREQUISITES

  1. Rust
  2. Docker, used by default for building and optimizing the smart contracts
  3. just, optional, but a recommended way to perform common tasks
  4. (optional, for typescript) Node

Testing

  • cargo test runs the minimal off-chain tests
  • just cargo-test-check runs off-chain tests in more configurations and checks the codebase
  • just build-contracts will build the WASM files
    • alternatively, just build-contracts-native to bypass Docker and build with native tooling

On-chain w/ LocalOsmosis

  • just run-localosmo launches a local Osmosis instance
  • COSMOS_WALLET env var should be set to the correct seed phrase
  • just local-deploy deploys a copy of the contracts to your Local Osmosis
  • just contracts-test will launch Local Osmosis, deploy contracts to it, and then run on-chain tests

Proptests and Fuzz testing

  • cargo test --features proptest runs prop tests
  • cargo install cargo-fuzz to install the fuzz testing tool
  • just fuzz

Getting started with various chains

Faucets

Deploying

Deploying is handled via the perps-deploy tool, located in the packages/perps-deploy directory. The perps-deploy.md includes more details of how deployments work, this file covers the direct steps.

When you deploy, you'll need to have the deployer seed phrase. This is available in a Google Drive sheet. You'll also need to choose which contract family you want to deploy, e.g. dragonci, dragondev, dragonqa. Let's assume you'll be deploying dragonci.

  1. Build the WASM contracts: just build-contracts
    • Or, with native tools: just build-contracts-native
  2. Set your seed phrase to an environment variable: export COSMOS_WALLET="deployer seed phrase"
  3. Set the appropriate contract family: export PERPS_FAMILY=dragonci
  4. Store the WASM code on the blockchain: cargo run --bin perps-deploy testnet store-code
  5. To deploy a fresh set of contracts: cargo run --bin perps-deploy testnet instantiate
  6. To migrate an existing set of contracts: cargo run --bin perps-deploy testnet migrate

Coverage

Installation

  • Install cargo-llvm-cov
  • Install llvm-tools-preview component from rustup:
rustup component add llvm-tools-preview

Usage

Build coverage report by running off chain tests under different configurations:

just off-chain-coverage
...

Then based on the kind of output you want, run these recipies:

  • For an HTML based report:
just off-chain-html-coverage
  • For a summary on the terminal:
just off-chain-term-coverage

About

Levana Well Funded Perpetual Swaps - smart contract, testing, and backend code

Resources

License

Stars

Watchers

Forks

Packages

No packages published