# Integrate RSP

## Table of Contents

RSP members (with existing `channel_id`) can integrate RSP through the following three options:

* Option 1 - Through [<mark style="color:purple;">Bifrost SLP API</mark>](#option-1-bifrost-slp-api)
* Option 2 - Through [<mark style="color:purple;">Bifrost SLPx API (Cross-chain)</mark>](#option-2-bifrost-slpx-api-cross-chain)
  * [<mark style="color:purple;">Integrating with EVM Contract</mark>](#integrating-with-evm-contract)
  * [<mark style="color:purple;">Integrating with Parachain</mark>](#integrating-with-parachain)
* Option 3 - Through [<mark style="color:purple;">Bifrost Dapp Portal</mark>](#option-3-bifrost-dapp-portal)

## Option 1 - Bifrost SLP API

{% hint style="success" %}
**Target Audience**: Your front end can directly connect to the Bifrost (Polkadot / Kusama) parachain, such as Wallets and Dapps, etc.
{% endhint %}

#### Showcase 1: [<mark style="color:purple;">Staking Rewards</mark>](https://www.stakingrewards.com/provider/bifrost-finance) - A PoS Data Platform

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2FlzSl39MjraKha0EqVY8I%2Fimage.png?alt=media&#x26;token=92b96074-62d8-4d68-ba80-b6d72f20ffb8" alt=""><figcaption></figcaption></figure>

#### Showcase 2: [<mark style="color:purple;">Subwallet</mark>](https://web.subwallet.app/home/earning/pools) - Polkadot Wallet

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2F6UvmQu8eoCuJP8ARuVc4%2Fimage.png?alt=media&#x26;token=33f0a3d3-601d-4c3c-a984-c0fb2ccf14a7" alt=""><figcaption></figcaption></figure>

### Integrating Steps

1. Get your UI & UX ready.
2. Integrate Bifrost (Polkadot) vToken Mint API: `vtokenminting_mint`

   [<mark style="color:purple;">Call data</mark>](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fhk.p.bifrost-rpc.liebi.com%2Fws#/extrinsics/decode/0x7300080000e40b54020000000000000000000000000100000000): 0x7300080000e40b54020000000000000000000000000100000000

   * Check Bifrost Token indexes and decimals at [<mark style="color:purple;">here</mark>](https://docs.bifrost.io/faq/what-are-vtokens/mint-redeem-vtoken-without-dapp#token-and-vtoken-index-library).
   * Input your `channel_id` (Apply you channel id via [<mark style="color:purple;">here</mark>](https://docs.bifrost.io/for-partners/reward-share-program-rsp/join-the-program))

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2FtDXMtsIwtXXa0YICUpYj%2Fimage.png?alt=media&#x26;token=7ff55b62-ce68-4c28-bb5e-8eebbd9878b8" alt=""><figcaption></figcaption></figure>

## Option 2 - Bifrost SLPx API (Cross-chain)

{% hint style="success" %}
**Target Audience**: Blockchains that can call or deploy Bifrost SLPx across chains, such as Hydration, Moonbeam, Astar, Manta, Ethereum (coming soon), Base etc.
{% endhint %}

### Integrating with EVM Contract

#### **Showcase**: Moonbeam, Astar, Manta ([<mark style="color:purple;">Omni.ls</mark>](https://omni.ls/)) - An omni-chain liquid staking dapp

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2FeblmAUGcoBWvNI9csfFP%2Fimage.png?alt=media&#x26;token=190c00d4-71ac-41b9-8abe-2ca3caed8598" alt=""><figcaption></figcaption></figure>

### Integrating Steps

1. Get your UI & UX ready.
2. Integrate SLPx API in your corresponding environment:
   * [<mark style="color:purple;">Your Dapp deployed on Moonbeam</mark>](https://docs.bifrost.io/for-partners/reward-share-program-rsp/broken-reference)
   * [<mark style="color:purple;">Your Dapp deployed on Moonriver</mark>](https://docs.bifrost.io/for-partners/reward-share-program-rsp/broken-reference)
   * [<mark style="color:purple;">Your Dapp deployed on Astar</mark>](https://docs.bifrost.io/for-partners/reward-share-program-rsp/broken-reference)
   * [<mark style="color:purple;">Your Dapp deployed on Ethereum Mainnet</mark>](https://docs.bifrost.io/for-partners/reward-share-program-rsp/broken-reference) (Coming soon…)

### Integrating with Parachain

#### Showcase: Hydration’s Treasury Minted vDOT via SLPx

Hydration [<mark style="color:purple;">democracy</mark>](https://hydration.subsquare.io/democracy/referenda/138?tab=call) called Bifrost SLPx via XCM and minted 1M DOT to vDOT: [<mark style="color:purple;">https://hydration.subscan.io/referenda/138?tab=preimage</mark>](https://hydration.subscan.io/referenda/138?tab=preimage)

<details>

<summary>Check the Preimage</summary>

```
[
  {
    "name": "calls",
    "type": "Vec<hydradx_runtime:RuntimeCall>",
    "value": [
      {
        "call_module": "Utility",
        "call_name": "dispatch_as",
        "call_index": "0d03",
        "params": [
          {
            "name": "as_origin",
            "type": "hydradx_runtime:OriginCaller",
            "value": {
              "system": {
                "Signed": "0x6d6f646c70792f74727372790000000000000000000000000000000000000000"
              }
            }
          },
          {
            "name": "call",
            "type": "Call",
            "value": {
              "call_index": "8900",
              "call_module": "XTokens",
              "call_name": "transfer",
              "params": [
                {
                  "name": "currency_id",
                  "type": "U32",
                  "value": 5
                },
                {
                  "name": "amount",
                  "type": "U128",
                  "value": "10000000000000000"
                },
                {
                  "name": "dest",
                  "type": "staging_xcm:VersionedMultiLocation",
                  "value": {
                    "V3": {
                      "interior": {
                        "X2": {
                          "col0": {
                            "Parachain": 2030
                          },
                          "col1": {
                            "AccountId32": {
                              "id": "0x5f13cfa22c9625df362d4f8f71647a50ed5d558a0c3d3dc72df679ecd7888d88",
                              "network": null
                            }
                          }
                        }
                      },
                      "parents": 1
                    }
                  }
                },
                {
                  "name": "dest_weight_limit",
                  "type": "staging_xcm:v3:WeightLimit",
                  "value": {
                    "Unlimited": "NULL"
                  }
                }
              ]
            }
          }
        ]
      },
      {
        "call_module": "Scheduler",
        "call_name": "schedule_after",
        "call_index": "0504",
        "params": [
          {
            "name": "after",
            "type": "U32",
            "value": 1
          },
          {
            "name": "maybe_periodic",
            "type": "option<Tuple:U32U32>",
            "value": null
          },
          {
            "name": "priority",
            "type": "U8",
            "value": 0
          },
          {
            "name": "call",
            "type": "Call",
            "value": {
              "call_index": "6b00",
              "call_module": "PolkadotXcm",
              "call_name": "send",
              "params": [
                {
                  "name": "dest",
                  "type": "staging_xcm:VersionedMultiLocation",
                  "value": {
                    "V3": {
                      "interior": {
                        "X1": {
                          "Parachain": 2030
                        }
                      },
                      "parents": 1
                    }
                  }
                },
                {
                  "name": "message",
                  "type": "staging_xcm:VersionedXcm@377",
                  "value": {
                    "V3": [
                      {
                        "DescendOrigin": {
                          "X1": {
                            "AccountId32": {
                              "id": "0x6d6f646c70792f74727372790000000000000000000000000000000000000000",
                              "network": null
                            }
                          }
                        }
                      },
                      {
                        "WithdrawAsset": [
                          {
                            "fun": {
                              "Fungible": "1000000000"
                            },
                            "id": {
                              "Concrete": {
                                "interior": {
                                  "Here": "NULL"
                                },
                                "parents": 1
                              }
                            }
                          }
                        ]
                      },
                      {
                        "BuyExecution": {
                          "fees": {
                            "fun": {
                              "Fungible": "1000000000"
                            },
                            "id": {
                              "Concrete": {
                                "interior": {
                                  "Here": "NULL"
                                },
                                "parents": 1
                              }
                            }
                          },
                          "weight_limit": {
                            "Unlimited": "NULL"
                          }
                        }
                      },
                      {
                        "Transact": {
                          "call": "0x7d0000000000000000000000000000000000000000000800026d6f646c70792f747273727900000000000000000000000000000000000000000467",
                          "origin_kind": "SovereignAccount",
                          "require_weight_at_most": {
                            "proof_size": 100000,
                            "ref_time": 10000000000
                          }
                        }
                      },
                      {
                        "DepositAsset": {
                          "assets": {
                            "Wild": {
                              "All": "NULL"
                            }
                          },
                          "beneficiary": {
                            "interior": {
                              "X1": {
                                "Parachain": 2034
                              }
                            },
                            "parents": 1
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    ]
  }
]
```

</details>

Inside of this preimage, it contained the [call data](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fbifrost.public.curie.radiumblock.co%2Fws#/extrinsics/decode/0x7d0000000000000000000000000000000000000000000800026d6f646c70792f747273727900000000000000000000000000000000000000000467) to call SLPx mint for vDOT.

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2Fwegvlg2v68bkVX3hvm0m%2Fimage.png?alt=media&#x26;token=d4288ba8-7833-4b56-959e-7c170872c153" alt=""><figcaption></figcaption></figure>

### Integrating Steps

1. Construct a XCM batch call to call Bifrost-Polkadot API: `slpx_mint`

{% hint style="info" %}
The cases below demonstrate the workflow of how to mint and redeem vToken on Hydration (parachain) via Bifrost SLPx, which leveraged by XCM.
{% endhint %}

Let’s assume Alice wants to mint DOT to vDOT on Hydration, a utility.batchAll call is needed:

[<mark style="color:purple;">Extrinsic Call Data</mark>](https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fhydradx-rpc.dwellir.com#/extrinsics/decode/0x0d020c89000500000000e40b5402000000000000000000000003010200b91f0100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d17410089000e00000000c817a804000000000000000000000003010200b91f0100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741006b0003010100b91f0310000400000106020001000000000000000000000000000000000000000000000000000000000000000700e40b54021300000106020001000000000000000000000000000000000000000000000000000000000000000700e40b54020006010700e40b5402feff030009017d0d0000000000000000000000000000000000000000080002d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d1074657374000000000d010000010100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741), which includes several calls inside

* Call 1:

Call xToken sending 1 DOT to Alice’s derived account on Bifrost.

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2FnVBvmkvcJ40H0ZuL2MrK%2Fimage.png?alt=media&#x26;token=78108b1b-7d96-4c8c-bcf8-997c070cbfb5" alt=""><figcaption></figcaption></figure>

* Call 2:

Call xToken sending 0.02 BNC to Alice’s derived account on Bifrost.

{% hint style="info" %}
Check Bifrost Token indexes and decimals at [here](https://www.notion.so/485987dfe60d4af9a57d560c8b7f492e?v=20f29c9b48db448dadb63e24358a19c4\&pvs=25).
{% endhint %}

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2F6luOnDVSEkLHVgv87cua%2Fimage.png?alt=media&#x26;token=546970f9-6662-47f6-a629-70cc6ab1345e" alt=""><figcaption></figcaption></figure>

* Call 3:

Execute `slpx_mint`

<figure><img src="https://757947912-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJFtVsA5N3spWTWKvFvv0%2Fuploads%2FQXjfZY8FLmAEaFlh7WpP%2Fimage.png?alt=media&#x26;token=334d32f7-70ba-43e7-83b9-cb0650815394" alt=""><figcaption></figcaption></figure>

#### FAQs:

1. **Why do I need to send 0.02 BNC when minting/redeeming DOT?**

Because after the user on Hydration sends an XCM transact with the command to Bifrost, it needs the derived address of the Hydration user to perform the SLPx mint operation, and there is no asset in the derived address, which will cause the transaction fail.

1. **How that derived account is being calculated?**

{% embed url="<https://www.notion.so/bifrost-io/Integrate-RSP-0ccbbac79c904457b38ba50efcf2da52?pvs=4#337c802b31cb4c0f93f013ecd210eff0>" %}

```bash
# Alice 
yarn calculate-multilocation-derivative-account \\
--ws-provider wss://eu.bifrost-polkadot-rpc.liebi.com/ws \\
--address 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY \\
--para-id 2034 \\
--parents 1

# console
Remote Origin calculated as SiblingChain
ParaID 2034
Parents 1
AccountId32: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
32 byte address is 0xf959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741
20 byte address is 0xf959d131179b0264f98ac96d2c9c13c403129f5d
```

## Option 3 - Bifrost Dapp Portal

{% hint style="success" %}
**Target Audience**: Any entities need a Bifrost Dapp Portol to direct users by attached with your `channel_id`.
{% endhint %}

1. Make sure you already have a `channel_id`
2. Generate your Bifrost Dapp Portal

Bifrost Dapp frontend has adapted to the RSP. Attach your channel ID at the end of [<mark style="color:purple;">app.bifrost.io</mark>](https://app.bifrost.io), for instance, [<mark style="color:purple;">https://app.bifrost.io/?channel=\[channel\_id\]</mark>](https://app.bifrost.io/?channel=%5Bchannel_id%5D). All stakes via this link will be counted as your valid minting.

{% hint style="info" %}
For example, the channel\_id of Staking Rewards is 1, the vToken minting of users who enter the Bifrost Dapp through the [<mark style="color:purple;">https://app.bifrost.io/?channel=1</mark>](https://app.bifrost.io/?channel=1https://app.bifrost.io/?channel=1) will be counted as the effective minting amount of Staking Rewards.
{% endhint %}
