This repository is now deprecated. We moved to a mono repository architecture containing all of Mars core contracts that you can find here.
A generalized credit protocol built on Mars lending market
DeFi lending protocols, such as Aave and Compound, typically require users to first deposit some collateral assets before they can borrow. Once deposited, this collateral is locked inside the lending market smart contracts; the users are not allowed to put them into productive use as they see fit.
Rover takes a different approach for Mars protocol, which utilizes a generalized credit account manager built on top of Mars' Red Bank. This approach will allow borrowers to retain control of their collateral assets, while at the same time providing a return for lenders.
The target audience of the credit manager is risk-seeking investors who wish to undertake leveraged trading or yield farming activities.
To start, a user first needs to access the Mars credit manager contract and request the opening of a credit account. The credit account is analogous to a "sub-account" on centralized trading platforms and is represented by a non-fungible token (NFT).
pub enum ExecuteMsg {
/// Create a new account
CreateCreditAccount {},
/// Take actions on account
UpdateCreditAccount {
account_id: String,
actions: Vec<Action>,
},
}
Users interact with their credit accounts by executing the following actions:
pub enum Action {
Deposit(Coin),
Withdraw(Coin),
Borrow(Coin),
/// The sender will repay on behalf of the recipient account. If 'recipient_account_id: None',
/// the sender repays to its own account.
Repay {
recipient_account_id: Option<String>,
coin: ActionCoin,
},
EnterVault {
vault: VaultUnchecked,
denom: String,
amount: Option<Uint128>,
},
ExitVault {
vault: VaultUnchecked,
amount: Uint128,
},
RequestVaultUnlock {
vault: VaultUnchecked,
amount: Uint128,
},
ExitVaultUnlocked { id: u64, vault: VaultUnchecked },
LiquidateCoin {
liquidatee_account_id: String,
debt_coin: Coin,
request_coin_denom: String,
},
LiquidateVault {
liquidatee_account_id: String,
debt_coin: Coin,
request_vault: VaultUnchecked,
},
SwapExactIn {
coin_in: Coin,
denom_out: String,
slippage: Decimal,
},
ProvideLiquidity {
coins_in: Vec<Coin>,
lp_token_out: String,
minimum_receive: Uint128,
},
WithdrawLiquidity { lp_token: Coin },
RefundAllCoinBalances {},
}
The credit manager contract executes the list of actions specified by ExecuteMsg::UpdateCreditAccount { actions }
in order. After all actions have been executed, it calculates the overall health factor of the credit account. If the account is unhealthy as a result of the actions, an error is thrown and all actions reverted.
You may have noticed that this design resembles the Fields of Mars contract in Mars V1. Indeed, Credit Manager can be considered a direct extension of Fields.
Vault writers interested in integrating with Rover must write their vaults to abide by the Cosmos Vault Standard and make a governance proposal.
The mars-rover-health-{types,computer}
crates have two use cases:
-
To be imported into CosmWasm contracts as libraries. When doing this, do not enable the
javascript
feature:[dependencies] # the `javascript` feature is disabled by default. do not enable unless needed! mars-rover-health-types = { path = "./packages/health-types" }
-
To be compiled into a Wasm binary and run in the browser. To do this, use the following command; do enable the
javascript
feature. The compiled Wasm binary can be found in the./target/wasm32-unknown-unknown/release/
folder.cargo build --release -p mars-rover-health-computer --target wasm32-unknown-unknown --features javascript
A generalized credit protocol would enable leveraged trading or yield farming capabilities that are largely available only on centralized exchanges today. End users would be able to borrow more than they've deposited into the lending protocol while still ensuring all credit accounts are fully collateralized. Mars Hub's decentralized architecture would also give third parties the ability to propose and write new trading and yield farming strategies that could tap Red Bank deposits on any supported blockchain. The proposed protocol would increase utility for traders. This new source of demand may generate higher yields for depositors and more fees for Mars Hub and MARS stakers.
- Install rustup. Once installed, make sure you have the wasm32 target:
rustup default stable
rustup update stable
rustup target add wasm32-unknown-unknown
- Install cargo make
cargo install --force cargo-make
-
Install Docker
-
Install Node.js v16
-
Install Yarn
-
Also note that Intel/Amd 64-bit processor is required. While there is experimental ARM support for CosmWasm/rust-optimizer, it's discouraged to use in production and LocalOsmosis is likely to have issues.
Pull down Rover repo locally
git clone https://github.com/mars-protocol/rover
cd rover
Run cargo build
to ensure it compiles fine.
Requires building the wasm binaries for the contracts:
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.13.0
For Rust cw-multi tests + osmosis-testing suite (requires mars_swapper_osmosis.wasm from previous step):
cargo test
For Typescript testnet deployment with the deployer address being the owner and admin of the contracts & end-to-end tests:
cd scripts
yarn install
yarn deploy:osmosis:testnet-deployer
For Typescript testnet deployment with the multisig address being the owner and admin of the contracts & end-to-end tests:
cd scripts
yarn install
yarn deploy:osmosis:testnet-multisig
For mainnet:
cd scripts
yarn install
yarn deploy:osmosis:mainnet
- osmosis-1 (TBD)
- osmo-test-4 with deployer owner
Contents of this repository are open source under GNU General Public License v3 or later.