Tutorial: How to use the Red Bank by interacting directly with Mars Protocol’s smart contracts

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 👇

Depositing Assets

Step 1: Go to the Terra Station website: https://station.terra.money/ and connect your Terra Station wallet

Step 2: Head over to the “Contracts” tab and query the Red Bank smart contract

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.

Step 3: Deposit native assets

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.

Step 4: You’ve just completed your first ExecuteMsg for this tutorial!

Step 5: Deposit CW20 Assets

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..."
}
}

Base64 Encoding

Step 6: Head over to the “Contracts” tab and query the ANC token contract

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.

Step 7: Send ANC to the Red Bank

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=="
}
}

Step 8: Congrats! You’ve just completed your first ReceiveMsg for this tutorial!

Withdrawing Assets

Step 1: Head over to the “Contracts” tab and query the Red Bank smart contract

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.

Step 2: Withdraw Native Assets

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..."
}
}

Step 3: Withdraw CW20 Assets (ANC)

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..."
}
}

Borrowing Assets

Step 1: Head over to the “Contracts” tab and query the Red Bank smart contract

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.

Step 2: Borrow Native Assets

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..."
}
}

Step 3: Borrow CW20 Assets (ANC)

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..."
}
}

Repaying your Loan

Step 1: Head over to the “Contracts” tab and query the Red Bank smart contract

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.

Step 2: Repaying native assets

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.

Step 3: Repay CW20 Assets

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..."
}
}`

Base64 Encoding

Step 4: Head over to the “Contracts” tab and query the ANC token contract

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.

Step 5: Send ANC to the Red Bank to Repay Debt

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="
}
}

Congrats! You’ve completed all of the tutorials!

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.

--

--

--

Mars is a credit lending protocol for the Terra blockchain. Official site: https://marsprotocol.io

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Benefits of Blockchain-as-a-Service for Businesses

The Looming Battle Over Ownership of Your Car’s Data

UniChain is about performing hardfork around Oct 20th, 2021

DALP commences planned $9.4m energy-driven SXDT buyback

How to Stake with Cosmostation Wallet

Meta Wizards

Meta Wizards

Introducing Node-A-Team, Titan Genesis Validator in Rizon Blockchain.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mars Protocol

Mars Protocol

Mars is a credit lending protocol for the Terra blockchain. Official site: https://marsprotocol.io

More from Medium

The importance of Mars protocol governance participation

Roadmap and Monthly Update [April 2021]

Astro Wars Proposal

Terra Updates: Mid-April