Moonbeam
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.
In this example we will integrate vDOT 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:
Clarifying the contract info
Constructing vDOT minting in your contract
Constructing vDOT redemption in your contract
Network
SLPx contract address under Moonbeam network:
Moonbeam
0xF1d4797E51a4640a76769A50b57abE7479ADd3d8
Integration
MoonbeamSLPx contract does not support atomic contract calls. That means you can't integrate within your contract logic. The reason are as follows:
there is a wait time of about 45s to 60s to receive the
vAsset
token.
However, you can still interact with the contract directly from the frontend or use another contract but the call is structured at the end of the logic.
There are 2 main functions you use to integrate with MoonbeamSlpx
:
addressToAssetInfo
(derived from the public mapping addressToAssetInfo
)
function addressToAssetInfo(address assetAddress) public view returns (currencyId bytes2, operationalMin uint256)
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 thatorder
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 theorder
, less than 32 bytes. For example, "OmniLS"channel_id
is a unique identifier for theorder
. It's used to join Bifrost Protocol Revenue Sharing Program (RSP). You can set it if you have one. Check here to learn more.
Example Wagmi integration
addressToAssetInfo
const { data: assetInfo } = useReadContract({
...wagmiContractConfig,
address: "0xF1d4797E51a4640a76769A50b57abE7479ADd3d8",
abi: moonbeamSLPxAbi,
functionName: "addressToAssetInfo",
args: ["0x0000000000000000000000000000000000000802"],
});
console.log("assetInfo", assetInfo);
// Output: assetInfo { currencyId: '0x0801', operationalMin: 5000000000000000000n }
create_order
for ERC20 token
const {
data: hash,
error,
isPending,
writeContract
} = useWriteContract()
async function approveLstContract() {
writeContract({
account: currentAddress, // connected address
address: "0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080",
abi: erc20Abi,
functionName: "approve",
args: [
"0xF1d4797E51a4640a76769A50b57abE7479ADd3d8",
parseUnits(1, 10), // 1 xcDOT is operationalMin and 10 is the token decimals
],
})
}
async function mintLst() {
writeContract({
address: "0xF1d4797E51a4640a76769A50b57abE7479ADd3d8",
abi: moonbeamSLPxAbi,
functionName: "create_order",
args: [
"0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080", // xcDOT token address
parseUnits(1, 10), // amount
1284, // Moonbeam chain id
receiverAddress, // receiver
"bifrost", // sample remark
0, // sample channel_id
],
})
}
const { isLoading: isConfirming, isSuccess: isConfirmed } =
useWaitForTransactionReceipt({
hash,
})
for GLMR token
const {
data: hash,
error,
isPending,
writeContract
} = useWriteContract()
async function mintLst() {
writeContract({
address: "0xF1d4797E51a4640a76769A50b57abE7479ADd3d8",
abi: moonbeamSLPxAbi,
functionName: "create_order",
args: [
"0x0000000000000000000000000000000000000802", // xcDOT token address
parseUnits(5, 18), // amount
1284, // Moonbeam chain id
receiverAddress, // receiver
"bifrost", // sample remark
0, // sample channel_id
],
value: parseUnits(5, 18) // 5 GLMR
})
}
const { isLoading: isConfirming, isSuccess: isConfirmed } =
useWaitForTransactionReceipt({
hash,
})
Currency id & Destination Chain id
Configure your currency id and chain id inputs by checking the params below:
Moonbeam
Chains
Dest_Chain_Id
Receiver Type
Moonbeam
1284
Ethereum Address(Byets20)
Token
Address
CurrencyId
operationalMin
BNC
0xFFffffFf7cC06abdF7201b350A1265c62C8601d2
0x0001
1_000_000_000_000
xcDOT
0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080
0x0800
10_000_000_000
GLMR
0x0000000000000000000000000000000000000802
0x0801
5_000_000_000_000_000_000
ASTR
0xFfFFFfffA893AD19e540E172C10d78D4d479B5Cf
0x0803
5_000_000_000_000_000_000
Bifrost_Filecoin_Native_Token
0xfFFfFFFF6C57e17D210DF507c82807149fFd70B2
0x0804
1_000_000_000_000_000_000
Bifrost_Voucher_DOT
0xFFFfffFf15e1b7E3dF971DD813Bc394deB899aBf
0x0900
8_000_000_000
Bifrost_Voucher_GLMR
0xFfFfFFff99dABE1a8De0EA22bAa6FD48fdE96F6c
0x0901
4_000_000_000_000_000_000
Bifrost_Voucher_ASTR
0xFffFffff55C732C47639231a4C4373245763d26E
0x0903
4_000_000_000_000_000_000
Bifrost_Voucher_FIL
0xFffffFffCd0aD0EA6576B7b285295c85E94cf4c1
0x0904
800_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.
Moonbeam
0xEF81930Aa8ed07C17948B2E26b7bfAF20144eF2a
DOT / GLMR / FIL
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
Was this helpful?