Martian Field is a leveraged yield farming strategy utilizing contract-to-contract (C2C) lending from Mars Protocol.
A bug bounty is currently open for these contracts. See details at: https://immunefi.com/bounty/marsprotocol/
A common type of yield farms in the Terra ecosystem works as follows. The user provides a primary asset (e.g. ANC, Anchor Protocol's governance token) and equal value of UST to an AMM pool (e.g. Terraswap), then deposit the AMM's liquidity token into a staking contract. Over time, staking reward is accrued in the form of the primary asset (ANC in this case) and withdrawable by the user.
To reinvest the farming gains, the user needs to
- claim staking reward
- sell half of the reward to UST
- provide the UST and the other half of the reward to the AMM
- deposit the liquidity token to the staking contract
Martian Field is an autocompounder that 1) automates this process, and 2) allow user to take up to 2x leverage utilizing C2C lending from Mars protocol.
Martian Field also tracks each user's loan-to-value ratio (LTV). If a user's LTV exceeds a preset threshold, typically as a result of the primary asset's price falling or debt builds up too quickly, the position is subject to liquidation.
- Rust v1.44.1+
wasm32-unknown-unknown
target- Docker
- LocalTerra
- Node.js v16
-
Install
rustup
via https://rustup.rs/ -
Add
wasm32-unknown-unknown
target
rustup default stable
rustup target add wasm32-unknown-unknown
-
Install Docker
-
Clone the LocalTerra repository, edit
config/genesis.json
as follows. Set the stability fee ("tax") to zero by:
"app_state": {
"treasury": {
"params": {
"tax_policy": {
- "rate_min": "0.000500000000000000",
- "rate_max": "0.010000000000000000",
+ "rate_min": "0.000000000000000000",
+ "rate_max": "0.000000000000000000",
},
- "change_rate_max": "0.000250000000000000"
+ "change_rate_max": "0.000000000000000000"
}
}
}
- Optionally, speed up LocalTerra's blocktime by changing
config/config.toml
as follows:
##### consensus configuration options #####
[consensus]
wal_file = "data/cs.wal/wal"
- timeout_propose = "3s"
- timeout_propose_delta = "500ms"
- timeout_prevote = "1s"
- timeout_prevote_delta = "500ms"
- timeout_precommit_delta = "500ms"
- timeout_commit = "5s"
+ timeout_propose = "200ms"
+ timeout_propose_delta = "200ms"
+ timeout_prevote = "200ms"
+ timeout_prevote_delta = "200ms"
+ timeout_precommit_delta = "200ms"
+ timeout_commit = "200ms"
- Install Node, preferrably using nvm, as well as libraries required for testing:
nvm install 16
nvm alias default 16
cd fields-of-mars/scripts
npm install
Make sure the current working directory is set to the root directory of this repository, then
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.11.5
Start LocalTerra:
cd /path/to/LocalTerra
git checkout main
git pull
docker compose up
Run test scripts: inside scripts
folder,
ts-node tests/1_mock_astro_generator.test.ts
ts-node tests/2_mock_oracle.test.ts
ts-node tests/3_mock_red_bank.test.ts
ts-node tests/4_martian_field.test.ts
Provide seed phrase of the deployer account in scripts/.env
; create an instantiate_msg.json
storing the contract's instantiate message; then
ts-node 1_deploy.ts --network mainnet|testnet --msg /path/to/instantiate_msg.json [--code-id codeId]
-
LocalTerra only works on X86 processors. There is currently no way to run the tests on Macs with the M1 processor.
-
Our development setup includes the VSCode text editor, rust-analyzer for Rust, and ESLint + Prettier for TypeScript.
Contents of this repository are open source under GNU General Public License v3 or later.