Moonriver

Introduction

This guide will show how to integrate SLPx in your contact logic. It is based on the SLPx vTokenminting code example. To run this example, check out the guide below.

To get started with local development on Moonriver, check out local development guide.

In this example we will integrate vKSM minting & redemption in our contract logic. The tokens, amount of input token, destination chain id, and channel id can be configured as inputs.

The guide will cover:

  1. Clarifying the contract info

  2. Constructing vKSM minting in your contract

  3. Constructing vKSM redemption in your contract

Network

SLPx contract address under Moonriver network:

Network
Slpx Address

Moonriver

0x6b0A44c64190279f7034b77c13a566E914FE5Ec4

Contract info

/**
    * @dev Create order to mint vAsset or redeem vAsset on bifrost chain
    * @param assetAddress The address of the asset to mint or redeem
    * @param amount The amount of the asset to mint or redeem
    * @param dest_chain_id When order is executed on Bifrost, Asset/vAsset will be transferred to this chain
    * @param receiver The receiver address on the destination chain, 20 bytes for EVM, 32 bytes for Substrate
    * @param remark The remark of the order, less than 32 bytes. For example, "OmniLS"
    * @param channel_id The channel id of the order, you can set it. Bifrost chain will use it to share reward.
    **/
    function create_order(
        address assetAddress,
        uint128 amount,
        uint64 dest_chain_id,
        bytes memory receiver,
        string memory remark,
        uint32 channel_id
    ) external payable;

Before starting, let's talk about the values we fetched here and what they represent:

  • Create order calls the SLPx contract to mint or redeem vAsset on the Bifrost chain.

  • assetAddress is the address of the asset you want to mint or redeem.

  • amount is the amount of the asset you want to mint or redeem.

  • dest_chain_id represents the chain that your contract is deploying on, once that order in Create order is executed on Bifrost, Asset/vAsset will be transferred to this chain.

  • receiver is the asset receiver address on the destination chain, 20 bytes for EVM, 32 bytes for Substrate.

  • remark is the remark of the order, less than 32 bytes. For example, "OmniLS"

  • channel_id is a unique identifier for the order. It's used to join Bifrost Protocol Revenue Sharing Program (RSP). You can set it if you have one. Check here to learn more.

Examples

We assume you're trying to integrate vKSM minting and redemption into your contract. To do this, follow the examples below and adjust your inputs accordingly.

  • Mint 1 KSM into vKSM and send it to Moonriver.

  • Redeem 1 vKSM into KSM and send it to Moonriver.

// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.10;

import "./ISlpx.sol";
import "./IERC20.sol";

contract Example { 
    ISlpx public slpx = ISlpx(0x6b0A44c64190279f7034b77c13a566E914FE5Ec4);
    address ksm = 0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080;
    address vksm = 0xFFffffFFC6DEec7Fc8B11A2C8ddE9a59F8c62EFe;
    // Moonriver parachain id
    uint64 Moonriver_chain_id = 1284;
    // EVM account public key
    bytes20 receiver = 0xa05d045646ecff8760f9bc3ae4266e910a307f0c11250c3f6fe3ae611dbf8f24;
    uint128 amount = 10_000_000_000; 
    string remark = "Hello Slpx";
    uint32 channel_id = 0;
    
    function mint_vksm() public payable {
        IERC20(ksm).transferFrom(msg.sender, address(this), amount);
        IERC20(ksm).approve(address(slpx), amount);
        slpx.create_order(
            ksm,
            amount,
            moonriver_chain_id,
            abi.encodePacked(receiver),
            remark,
            channel_id
        );

        //Your contract logic: 

     }

    // Redeem KSM for 0-7 days, once redeemed, it will be sent to the receiver of dest chain
     function redeem_ksm() public payable {
        IERC20(vksm).transferFrom(msg.sender, address(this), amount);
        IERC20(vksm).approve(address(slpx), amount);
        slpx.create_order(
            vksm,
            amount,
            moonriver_chain_id,
            abi.encodePacked(receiver),
            remark,
            channel_id
        );

        //Your contract logic: 

     }
}

Currency id & Destination Chain id

Configure your currency id and chain id inputs by checking the params below:

Moonriver

Chains

Dest_Chain_Id

Receiver Type

Moonriver

1284

Ethereum Address(Byets20)

Token
Address
CurrencyId
operationalMin

xcBNC

0xFFfFFfFFF075423be54811EcB478e911F22dDe7D

0x0001

1_000_000_000_000

xcKSM

0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080

0x0204

500_000_000_000

MOVR

0x0000000000000000000000000000000000000802

0x020a

500_000_000_000_000_000

Bifrost_Voucher_BNC

0xFFffffff3646A00f78caDf8883c5A2791BfCDdc4

0x0101

800_000_000_000

Bifrost_Voucher_KSM

0xFFffffFFC6DEec7Fc8B11A2C8ddE9a59F8c62EFe

0x0104

400_000_000_000

Bifrost_Voucher_MOVR

0xfFfffFfF98e37bF6a393504b5aDC5B53B4D0ba11

0x010a

400_000_000_000_000_000

XcmOracle

XCM Oracle is a an oracle tool to query Vasset storage from Bifrost chain, you can learn more via here.

Network
XcmOracle Address
Support Asset

Moonriver

0x682D05cD8D96b9904eC2b1B97BD1eb640B10fC2d

KSM / MOVR / BNC

Contract info

// _assetAddress: Asset address, e.g. DOT, KSM
// _assetAmount: Input asset amount, get vAsset amount
// _vAssetAmount: Input vAsset amount, get asset amount
function getVTokenByToken(address _assetAddress, uint256 _assetAmount) public view returns (uint256);
function getTokenByVToken(address _assetAddress, uint256 _vAssetAmount) public view returns (uint256);

Last updated