Contest ran 24 February 20229 March 2022

13 day contest

Anchor contest

The Benchmark DeFi Yield.

$170,000 UST

Total Awards

Anchor_dark

Anchor contest details

What is Anchor?

Anchor is a decentralized savings protocol offering low-volatile yields on Terra stablecoin deposits. The Anchor rate is powered by a diversified stream of staking rewards from major proof-of-stake blockchains, and therefore can be expected to be much more stable than money market interest rates. The Anchor community believes that a stable, reliable source of yield in Anchor has the opportunity to become the reference interest rate in crypto. The Anchor protocol defines a money market between a lender, looking to earn stable yields on their stablecoins, and a borrower, looking to borrow stablecoins on stakeable assets. To borrow stablecoins, the borrower locks up Bonded Assets (bAssets) as collateral, and borrows stablecoins below the protocol-defined borrowing ratio. The diversified stream of staking rewards accruing to the global pool of collateral then gets converted to stablecoin, and then conferred to the lender in the form of a stable yield.

Deposited stablecoins are represented by Anchor Terra (aTerra). aTerra tokens are redeemable for the initial deposit along with accrued interest, allowing interest collection to be done just by holding on to them. Anchor is structured to provide depositors with: *High, stable deposit yields powered by rewards of bAsset collaterals *Instant withdrawals through pooled lending of stablecoin deposits *Principal protection via liquidation of loans in risk of undercollateralization

Anchor is an open, permissionless savings protocol, meaning that any third-party application is free to connect and earn interest without restrictions. Through Anchor Earn, Anchor.js or EthAnchor, developers can interact with Anchor using just a few lines of code. Further documentation of the Anchor Protocol is provided in the following pages.

For more info see https://docs.anchorprotocol.com/

codecov

Anchor bAsset Contracts

This monorepository contains the source code for the smart contracts implementing bAsset Protocol on the Terra blockchain.

You can find information about the architecture, usage, and function of the smart contracts on the official Anchor documentation site.

Contracts

Contract Reference Description
anchor_basset_hub doc Manages minted bLunas and bonded Lunas
anchor_basset_reward doc Manages the distribution of delegation rewards
anchor_basset_token doc CW20 compliance
anchor_airdrop_registery doc Manages message fabricators for MIR and ANC airdrops

Development

Environment Setup

  • Rust v1.44.1+
  • wasm32-unknown-unknown target
  • Docker
  1. Install rustup via https://rustup.rs/

  2. Run the following:

rustup default stable
rustup target add wasm32-unknown-unknown
  1. Make sure Docker is installed

Unit / Integration Tests

Each contract contains Rust unit tests embedded within the contract source directories. You can run:

cargo test unit-test
cargo test integration-test

Compiling

After making sure tests pass, you can compile each contract with the following:

RUSTFLAGS='-C link-arg=-s' cargo wasm
cp ../../target/wasm32-unknown-unknown/release/cw1_subkeys.wasm .
ls -l cw1_subkeys.wasm
sha256sum cw1_subkeys.wasm

Production

For production builds, run the following:

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

This performs several optimizations which can significantly reduce the final size of the contract binaries, which will be available inside the artifacts/ directory.

Anchor bEth Contracts

This monorepository contains the source code for the smart contracts implementing bEth on the Terra blockchain.

You can find information about the architecture, usage, and function of the smart contracts on the official Anchor documentation site.

Development

Environment Setup

  • Rust v1.44.1+
  • wasm32-unknown-unknown target
  • Docker
  1. Install rustup via https://rustup.rs/

  2. Run the following:

rustup default stable
rustup target add wasm32-unknown-unknown
  1. Make sure Docker is installed

Unit / Integration Tests

Each contract contains Rust unit tests embedded within the contract source directories. You can run:

cargo test unit-test
cargo test integration-test

Compiling

After making sure tests pass, you can compile each contract with the following:

RUSTFLAGS='-C link-arg=-s' cargo wasm
cp ../../target/wasm32-unknown-unknown/release/cw1_subkeys.wasm .
ls -l cw1_subkeys.wasm
sha256sum cw1_subkeys.wasm

Production

For production builds, run the following:

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

This performs several optimizations which can significantly reduce the final size of the contract binaries, which will be available inside the artifacts/ directory.

License

Copyright 2021 Anchor Protocol

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

codecov

Anchor Token (ANC) Contracts

This monorepository contains the source code for the Money Market smart contracts implementing Anchor Protocol on the Terra blockchain.

You can find information about the architecture, usage, and function of the smart contracts on the official Anchor documentation site.

Dependencies

Anchor Token depends on Terraswap and uses its implementation of the CW20 token specification.

Contracts

Contract Reference Description
airdrop doc Holds ANC tokens which are to be used Luna staker incentives
collector doc Accumulates protocol fees, converts them to ANC and distributes to ANC stakers
community doc Manages ANC community grants
distributor doc Holds ANC tokens which are to be used as borrower incentives
gov doc Handles Anchor Governance and reward distribution to ANC stakers
staking doc Handles ANC-UST pair LP token staking
vesting doc Holds ANC tokens which are to be used ANC token allocation vesting

Development

Environment Setup

  • Rust v1.44.1+
  • wasm32-unknown-unknown target
  • Docker
  1. Install rustup via https://rustup.rs/

  2. Run the following:

rustup default stable
rustup target add wasm32-unknown-unknown
  1. Make sure Docker is installed

Unit / Integration Tests

Each contract contains Rust unit and integration tests embedded within the contract source directories. You can run:

cargo unit-test
cargo integration-test

Compiling

After making sure tests pass, you can compile each contract with the following:

RUSTFLAGS='-C link-arg=-s' cargo wasm
cp ../../target/wasm32-unknown-unknown/release/cw1_subkeys.wasm .
ls -l cw1_subkeys.wasm
sha256sum cw1_subkeys.wasm

Production

For production builds, run the following:

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

This performs several optimizations which can significantly reduce the final size of the contract binaries, which will be available inside the artifacts/ directory.

codecov

Anchor Money Market Contracts

A Rust and CosmWasm implementation of the Anchor Protocol money market on the Terra blockchain.

You can find information about the architecture, usage, and function of the smart contracts in the documentation.

Dependencies

Money Market has dependencies on Anchor Token Contracts and bAsset Contracts.

Contracts

Contract Reference Description
overseer doc Manages money market overalls, stores borrower information
market doc Handles Terra stablecoin deposits and borrows, ANC distribution to borrowers
custody_bluna doc Handles bLuna collateral deposits and withdrawals
custody_beth doc Handles bEth collateral deposits and withdrawals
interest_model doc Calculates the current borrow interest rate based on the market situation
distribution_model doc Calculates the borrower ANC emission rate based on the previous emission rate
oracle doc Provides a price feed for bAsset collaterals
liquidation doc OTC exchange contract for bAsset collateral liquidations

Development

Environment Setup

  • Rust v1.44.1+
  • wasm32-unknown-unknown target
  • Docker
  1. Install rustup via https://rustup.rs/

  2. Run the following:

rustup default stable
rustup target add wasm32-unknown-unknown
  1. Make sure Docker is installed.

Unit / Integration Tests

Each contract contains Rust unit and integration tests embedded within the contract source directories. You can run:

cargo unit-test
cargo integration-test

Compiling

After making sure tests pass, you can compile each contract with the following:

RUSTFLAGS='-C link-arg=-s' cargo wasm
cp ../../target/wasm32-unknown-unknown/release/cw1_subkeys.wasm .
ls -l cw1_subkeys.wasm
sha256sum cw1_subkeys.wasm

Production

For production builds, run the following:

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

This performs several optimizations which can significantly reduce the final size of the contract binaries, which will be available inside the artifacts/ directory.

License

This repository is licensed under the Apache 2.0 license. See LICENSE for full disclosure.

© 2021 Anchor Protocol.

Cross-chain Contract (Work in progress, won't change during the contest though):

Smart contract architecture:

AddressProxy:

Terra contract deployed to represent some cross-chain address Interfaces with anchor contracts directly

Core:

Takes all the user facing messages that anchor takes, except they also include information about the cross-chain sender Proxies messages to the appropriate AddressProxy

Wormhole Bridge Endpoints:

Receives data and wrapped tokens from various bridges Parses data into messages readable by Core, and forwards---

Compiling contracts:

npm run compile_eth
npm run compile_terra

Deploying contracts:

env.json contains all relevant information for a testnet deployment. To deploy xAnchor to testnet:

npm run deploy

This will also rewrite the contract addresses in env.json with the most recently deployed set

Testing:

npm run test

This will run tests against the deployed contracts in env.json

Migration

Deploying everything takes a while. Since both of ETH and Terra side contracts are upgradable, we can update them in place to speed up our iteration time.

npm run migrate_terra
npm run migrate_eth

OP Code Specification

Opcodes are specified as 8-bit unsigned integers. We split the opcode into two parts:

  • The first 6 least significant bits are the opcode itself
  • The last 2 bits are the flag bits

We have the following flags defined:

  • 0b10: FLAG_INCOMING_TRANSFER
  • 0b01: FLAG_OUTGOING_TRANSFER
  • 0b11: FLAG_BOTH_TRANSFERS
  • 0b00: FLAG_NO_ASSC_TRANSFERS

We have the following opcodes:

Opcode Flags Full Opcode Decimal
Deposit Stable FLAG_BOTH_TRANSFERS 0b110000 192
Redeem Stable FLAG_BOTH_TRANSFERS 0b110001 193
Repay Stable FLAG_INCOMING_TRANSFER 0b1000000 64
Lock Collateral FLAG_INCOMING_TRANSFER 0b1000001 65
Unlock Collateral FLAG_OUTGOING_TRANSFER 0b0100000 32
Borrow Stable FlAG_OUTGOING_TRANSFER 0b0100001 33
Claim Rewards FLAG_OUTGOING_TRANSFER 0b0100010 34