April 21, 2022
Unlike Earth, Mars is a place where all control is decentralized. No one person or company “owns” the protocol. Instead, it’s a set of open-sourced smart contracts freely licensed to the public and governed by MARS stakers (xMARS holders).
Since Mars’ smart contracts are published directly on the Terra blockchain, anyone can use the protocol with or without interacting with marsprotocol.io. The website is merely one of many doorways to Mars.
Put another way, Mars runs autonomously on Terra. And that means end users can make deposits in the Red Bank, borrow against them, repay their loans and withdraw their assets without ever touching a website. Instead, they can interact directly with the Terra blockchain.
It’s a radical departure from the way traditional finance works today. And it’s one that gives developers the ability to build applications on top of Mars without seeking permission or paying fees to middlemen.
It’s all part of the vision of decentralized finance. Once upon a time, that vision was theoretical. Today, it’s here.
In the tutorials below, let’s look at exactly how you can use Terra Station to do basic transactions in the Red Bank.
Initiate tutorials now 👇
For this tutorial, we will be using the Red Bank testnet contract address. For a full list of Mars Contract Addresses, search here.
Once you’ve queried the correct address, select “Execute” to move forward. This will display an input field for ExecuteMsg functions.
When depositing assets into the Red Bank, users can choose between native assets such as LUNA or UST, or CW20 tokens such as the recently approved ANC token. For native assets, an address will need to call the DepositNative function to deposit their tokens.
DepositNative
{
"deposit_native": {
"denom": "uusd",
"on_behalf_of": "terra..."
}
}
The deposited coins must be sent in the transaction this call is made in. If you’re using the Terra Station contracts tab,you should be able to select the denomination (abbreviated “denom”), which is the token you plan to deposit, and input an amount to deposit below the Msg input field. UST uses the denom “uusd.” Sign the transaction using your Terra Station wallet to move forward.
As mentioned above, users can choose between depositing native and CW20 Assets into the Red Bank. As of now, ANC is the only available CW20 token to deposit on the protocol and will be used for the rest of this tutorial. For CW20 tokens, an address will first need to wrap the DepositCw20 JSON in a Base64 encoding and then call the Send function of the respective CW20 token contract with this message embedded.
DepositCw20
{
"deposit_cw20": {
"on_behalf_of": "terra..."
}
}
Once you’ve wrapped your DepositCw20 call in a Base64 encoding, head over to the Terra Station contracts page and query the ANC token contract.
This tutorial uses the ANC testnet contract address.
You will need to input the Red Bank contract address and the amount of the respective CW20 token to send. This tutorial uses the Red Bank testnet address.
The Base64 encoding of the DepositCw20 call will be read as an input to the msg parameter.
Send
{
"send": {
"contract": "terra1avkm5w0gzwm92h0dlxymsdhx4l2rm7k0lxnwq7",
"amount": "10000",
"msg": "ewogICJkZXBvc2l0X2N3MjAiOiB7CiAgICAib25fYmVoYWxmX29mIjogInRlcnJhMThteGR6eDJtcXMzMzVrOGF2eTI0YzVlcjBqeDg4YTNnYXUwcjJhIgogIH0KfQ=="
}
}
For this tutorial, we will be using the Red Bank testnet contract address. For a full list of Mars Contract Addresses, search here.
Once you’ve queried the correct address, select “Execute” to move forward. This will display an input field for ExecuteMsg functions.
The asset parameter for the Withdraw function takes in either a native or CW20 asset. For withdrawing native assets, input the denom as either uusd (UST) or uluna (LUNA) to withdraw available tokens.
Withdraw
{
"withdraw": {
"asset": {
"native": {
"denom": "uusd"
}
},
"amount": "100",
"recipient": "terra..."
}
}
For withdrawing CW20 assets, you will need to input the contract_addr for the respective CW20 token you wish to withdraw. For now, ANC is the only available CW20 token for lending and borrowing.
Withdraw
{
"withdraw": {
"asset": {
"cw20": {
"contract_addr": "terra1747mad58h0w4y589y3sk84r5efqdev9q4r02pc"
}
},
"amount": "10",
"recipient": "terra..."
}
}
For this tutorial, we will be using the Red Bank testnet contract address. For a full list of Mars Contract Addresses, search here.
Once you’ve queried the correct address, select “Execute” to move forward. This will display an input field for ExecuteMsg functions.
The asset parameter for the borrow function takes in either a native or CW20 asset. For borrowing native assets, input the denom as either uusd (UST) or uluna (LUNA) to borrow available tokens.
Borrow
{
"borrow": {
"asset": {
"native": {
"denom": "uluna"
}
},
"amount": "10",
"recipient": "terra..."
}
}
For borrowing CW20 assets, you will need to input the contract_addr for the respective CW20 token you wish to borrow. For now, ANC is the only available CW20 token for lending and borrowing.
Borrow
{
"borrow": {
"asset": {
"cw20": {
"contract_addr": "terra1747mad58h0w4y589y3sk84r5efqdev9q4r02pc"
}
},
"amount": "10",
"recipient": "terra..."
}
}
For this tutorial, we will be using the Red Bank testnet contract address. For a full list of Mars Contract Addresses, search here.
Once you’ve queried the correct address, select “Execute” to move forward. This will display an input field for ExecuteMsg functions.
When repaying loans with the Red Bank, users can choose between native assets such as LUNA or UST or CW20 tokens such as the recently approved ANC token depending on borrowed assets. For native assets, an address will need to call the RepayNative function to repay their debt.
RepayNative
{
"repay_native": {
"denom": "uusd",
"on_behalf_of": "terra..."
}
}
Coins used to repay must be sent in the transaction this call is made. If you’re using the Terra Station contracts tab, you should be able to select the denom and input an amount to deposit in the Amount input field. Sign the transaction using your Terra Station wallet to move forward.
As mentioned above, users can choose between repaying native or CW20 Assets with the Red Bank depending on borrowed assets. As of now, ANC is the only available CW20 token to borrow on the protocol and will be used for the rest of this tutorial. For CW20 tokens, an address will first need to wrap the RepayCw20 JSON in a Base64 encoding and then call the Send function of the respective CW20 token contract with this message embedded.
RepayCw20
{
"repay_cw20": {
"on_behalf_of": "terra..."
}
}`
Once you’ve wrapped your RepayCw20 call in a Base64 encoding, head over to the Terra Station contracts page and query the ANC token contract.
This tutorial uses the ANC testnet contract address.
You will need to input the Red Bank contract address and the amount of the respective CW20 token to send.
The Base64 encoding of the RepayCw20 call will be read as an input to the msg parameter.
Send
{
"send": {
"contract": "terra1avkm5w0gzwm92h0dlxymsdhx4l2rm7k0lxnwq7",
"amount": "1000",
"msg": "ewogICJyZXBheV9jdzIwIjogewogICAgIm9uX2JlaGFsZl9vZiI6ICJ0ZXJyYTE4bXhkengybXFzMzM1azhhdnkyNGM1ZXIwang4OGEzZ2F1MHIyYSIKICB9Cn0="
}
}
For more information regarding the Red Bank smart contracts, visit the Mars docs.
Disclaimer
This article does not constitute investment advice. Before interacting with Mars, review the project disclaimers here.
Follow Mars on Twitter for the latest updates from Mission Control.