Skip to content

Commit

Permalink
[peg-arb] refactor stable-arb-x contracts to one contract and add vau…
Browse files Browse the repository at this point in the history
…lt setter (#174)

* comment profit-check from workspace to reveal deps

* remove dependecy on profit-check contract and integrate logic

* add profit queries

* fix gov integration test

* fix missing Profit save

* fix tests

* rm profit check from package

* rm profit check contract

* rm profit check workflow

* update toml

* Set astroport version to 1.0.0 and rename dapp to prevent conflict

* update query to get liquidity token

* create pools map to store luna_ust pool addresses

* add function to change vault addr

* add/fix tests for changes

* rename stable-arb-terra to peg-arb and remove astro-arb

* update workflow

* kerber0x review fixes
  • Loading branch information
CyberHoward authored Feb 4, 2022
1 parent 80b11bb commit a715c71
Show file tree
Hide file tree
Showing 51 changed files with 198 additions and 2,147 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Astroport UST Arb
name: Peg Arb

on:
push:
Expand All @@ -12,7 +12,7 @@ on:

defaults:
run:
working-directory: contracts/stable-arb-astro
working-directory: contracts/peg-arb

jobs:
lint:
Expand Down
59 changes: 0 additions & 59 deletions .github/workflows/stable_arb_terra.yml

This file was deleted.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ members = [
"packages/*",
"contracts/governance",
"contracts/community-fund",
# "contracts/profit-check",
"contracts/stable-arb-terra",
"contracts/stable-arb-astro",
"contracts/peg-arb",
"contracts/stablecoin-vault",
"contracts/emissions",
"contracts/vesting",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "stable-arb-terra"
name = "peg-arb"
version = "0.1.0"
authors = ["CyberHoward", "Kerber0x", "0xFable"]
edition = "2018"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"stable-arb-terra.wasm",
"contract.wasm",
"hash.txt",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

use stable_arb_terra::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use stable_arb_terra::state::State;
use peg_arb::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use peg_arb::state::State;

fn main() {
let mut out_dir = current_dir().unwrap();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,68 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"update_pools"
],
"properties": {
"update_pools": {
"type": "object",
"properties": {
"to_add": {
"type": [
"array",
"null"
],
"items": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "string"
}
],
"maxItems": 2,
"minItems": 2
}
},
"to_remove": {
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
}
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"set_vault"
],
"properties": {
"set_vault": {
"type": "object",
"required": [
"vault"
],
"properties": {
"vault": {
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand All @@ -105,6 +167,7 @@
"required": [
"asset",
"belief_price",
"pool_name",
"slippage"
],
"properties": {
Expand All @@ -114,6 +177,9 @@
"belief_price": {
"$ref": "#/definitions/Decimal"
},
"pool_name": {
"type": "string"
},
"slippage": {
"$ref": "#/definitions/Decimal"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
"type": "object",
"required": [
"asset_info",
"pool_address",
"seignorage_address",
"vault_address"
],
"properties": {
"asset_info": {
"$ref": "#/definitions/AssetInfo"
},
"pool_address": {
"type": "string"
},
"seignorage_address": {
"type": "string"
},
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
"title": "State",
"type": "object",
"required": [
"pool_address",
"seignorage_address",
"vault_address"
],
"properties": {
"pool_address": {
"$ref": "#/definitions/Addr"
},
"seignorage_address": {
"$ref": "#/definitions/Addr"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{
entry_point, to_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
Response, StdResult, WasmMsg,
Response, StdResult, WasmMsg, Order,
};

use terra_cosmwasm::{create_swap_msg, TerraMsgWrapper};
Expand All @@ -26,8 +26,8 @@ use crate::msg::{ArbDetails, CallbackMsg, ExecuteMsg, InstantiateMsg, MigrateMsg

use crate::querier::query_market_price;

use crate::state::{State, ADMIN, ARB_BASE_ASSET, STATE};

use crate::state::{State, ADMIN, ARB_BASE_ASSET, POOLS, STATE};
use white_whale::memory::LIST_SIZE_LIMIT;
type VaultResult = Result<Response<TerraMsgWrapper>, StableArbError>;

// version info for migration info
Expand All @@ -46,7 +46,6 @@ pub fn instantiate(
let state = State {
vault_address: deps.api.addr_validate(&msg.vault_address)?,
seignorage_address: deps.api.addr_validate(&msg.seignorage_address)?,
pool_address: deps.api.addr_validate(&msg.pool_address)?,
};

// Store the initial config
Expand Down Expand Up @@ -78,7 +77,19 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> V
Ok(Response::default()
.add_attribute("previous admin", previous_admin)
.add_attribute("admin", admin))
}
},
ExecuteMsg::SetVault { vault } => {
ADMIN.assert_admin(deps.as_ref(), &info.sender)?;
let vault_addr = deps.api.addr_validate(&vault)?;
let mut state = STATE.load(deps.storage)?;
let previous_vault = state.vault_address;
state.vault_address = vault_addr;
STATE.save(deps.storage,&state)?;
Ok(Response::default()
.add_attribute("previous vault", previous_vault)
.add_attribute("vault", vault))
},
ExecuteMsg::UpdatePools { to_add, to_remove } => update_pools(deps, to_add, to_remove),
ExecuteMsg::Callback(msg) => _handle_callback(deps, env, info, msg),
}
}
Expand Down Expand Up @@ -178,6 +189,7 @@ pub fn try_arb_below_peg(
}

// Set vars
let pool_address = POOLS.load(deps.storage, &details.pool_name)?;
let denom = deposit_info.get_denom()?;
let lent_coin = deduct_tax(
deps.as_ref(),
Expand Down Expand Up @@ -208,7 +220,7 @@ pub fn try_arb_below_peg(

// Terraswap msg, swap LUNA -> STABLE
let terraswap_msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: state.pool_address.to_string(),
contract_addr: pool_address.to_string(),
funds: vec![offer_coin.clone()],
msg: to_binary(&create_terraswap_msg(
offer_coin,
Expand Down Expand Up @@ -252,6 +264,7 @@ pub fn try_arb_above_peg(
}

// Set vars
let pool_address = POOLS.load(deps.storage, &details.pool_name)?;
let denom = deposit_info.get_denom()?;
let lent_coin = deduct_tax(
deps.as_ref(),
Expand All @@ -267,7 +280,7 @@ pub fn try_arb_above_peg(
}
// Simulate first tx with Terraswap
let expected_luna_received =
simulate_terraswap_swap(deps.as_ref(), state.pool_address.clone(), lent_coin.clone())?;
simulate_terraswap_swap(deps.as_ref(), pool_address.clone(), lent_coin.clone())?;

// Construct offer for Market Swap
let offer_coin = Coin {
Expand All @@ -277,7 +290,7 @@ pub fn try_arb_above_peg(

// Terraswap msg, swap STABLE -> LUNA
let terraswap_msg: CosmosMsg<TerraMsgWrapper> = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: state.pool_address.to_string(),
contract_addr: pool_address.to_string(),
funds: vec![lent_coin.clone()],
msg: to_binary(&create_terraswap_msg(
lent_coin.clone(),
Expand Down Expand Up @@ -331,6 +344,40 @@ fn after_successful_trade_callback(deps: DepsMut, env: Env) -> VaultResult {
})))
}

pub fn update_pools(
deps: DepsMut,
to_add: Option<Vec<(String, String)>>,
to_remove: Option<Vec<String>>,
) -> VaultResult {

if let Some(pools_to_add) = to_add {

if POOLS.keys(deps.storage, None, None, Order::Ascending).count() >= LIST_SIZE_LIMIT {
return Err(StableArbError::PoolLimitReached {});
}

for (name, new_address) in pools_to_add.into_iter() {
if name.is_empty() {
return Err(StableArbError::EmptyPoolName {});
};
// validate addr
POOLS.save(
deps.storage,
name.as_str(),
&deps.api.addr_validate(&new_address)?,
)?;
}
}

if let Some(pools_to_remove) = to_remove {
for name in pools_to_remove.into_iter() {
POOLS.remove(deps.storage, name.as_str());
}
}

Ok(Response::new().add_attribute("action", "update pool addresses"))
}

//----------------------------------------------------------------------------------------
// GOVERNANCE CONTROLLED SETTERS
//----------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ pub enum StableArbError {
#[error("Call is not a callback!")]
NotCallback {},

#[error("The requested funds have the wrong denom")]
WrongDenom {},

#[error("Not enough funds to perform arb-trade")]
Broke {},

#[error("The name of the proposed pool can not have length 0.")]
EmptyPoolName {},

#[error("The pool list has reached its limit, can't store more contracts.")]
PoolLimitReached {},
}

impl From<semver::Error> for StableArbError {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit a715c71

Please sign in to comment.