Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9421692
add custom recipient on unstake operation and add version query
jununifi Aug 30, 2023
c1bc3a1
update unstake amount field to share_amount & replace to use v1 ununi…
jununifi Aug 30, 2023
662de3f
update execute_xxx message params
jununifi Aug 30, 2023
4444dcf
update Epoch message to v1
jununifi Aug 30, 2023
6865f6b
feat: switch to package
kimurayu45z Aug 31, 2023
f8a2680
Merge branch 'main' of https://github.com/UnUniFi/yield-aggregator in…
kimurayu45z Aug 31, 2023
9dc3579
Merge branch 'main' of https://github.com/UnUniFi/yield-aggregator in…
kimurayu45z Aug 31, 2023
b51d095
Merge branch 'osmosis-strategy/v1' of https://github.com/UnUniFi/yiel…
kimurayu45z Aug 31, 2023
78a32a6
Merge branch 'main' of github.com:UnUniFi/yield-aggregator into osmos…
jununifi Aug 31, 2023
2e59789
Merge branch 'osmosis-strategy/v1' of github.com:UnUniFi/yield-aggreg…
jununifi Aug 31, 2023
a1eb15b
update query messages to be v1 compatible
jununifi Aug 31, 2023
8b5bb94
update owner to authority
jununifi Aug 31, 2023
9248889
update config -> params
jununifi Aug 31, 2023
bc4512a
Merge branch 'osmosis-strategy/v1' of github.com:UnUniFi/yield-aggreg…
jununifi Aug 31, 2023
d3fb4c7
Merge pull request #48 from UnUniFi/osmo-package
jununifi Aug 31, 2023
b4acdaf
Merge branch 'main' of github.com:UnUniFi/yield-aggregator into osmos…
jununifi Sep 4, 2023
98d342b
update amount on deposit info to share amount
jununifi Sep 4, 2023
c2e3d51
update share_amount on DepositInfo to share
jununifi Sep 4, 2023
9600aa3
Merge branch 'main' of github.com:UnUniFi/yield-aggregator into osmos…
jununifi Sep 22, 2023
21b4138
resolve issues from superfluid automerge
jununifi Sep 22, 2023
fe6e511
Update osmosis strategy v1 for multiple denoms management
jununifi Oct 20, 2023
6aa931a
update DepositDenomResp for custody strategy
jununifi Oct 20, 2023
2a5066a
add migration script from v0.0.3 to v1.0.0
jununifi Dec 5, 2023
cdbfcaf
Add unbonding_id on execute_unstake events & UpdateLegacyUnbondingRec…
jununifi Dec 5, 2023
9d47467
implement execute_instant_unbondings
jununifi Dec 8, 2023
eac9f5d
remove migration script
jununifi Dec 11, 2023
a191ff8
Upgrade bank store parser for SDK 47 compatibility on Osmosis strategy
jununifi Dec 21, 2023
3787e4f
Merge branch 'main' of github.com:UnUniFi/yield-aggregator into osmos…
jununifi Dec 21, 2023
e914a2c
Add migration script for high TVL issue fix
jununifi Dec 26, 2023
f2b655d
add stride strategy
jununifi Jan 22, 2024
c8ce3b7
Fix typo on osmosis strategy
jununifi Jan 31, 2024
ef1c5c9
Resolve unit test after refactoring osmosis strategy for sustainability
jununifi Feb 7, 2024
6740bcc
add migration related endpoints
jununifi Feb 9, 2024
82875ab
Add migration script from legacy state to new state
jununifi Feb 9, 2024
c66debd
Add missing functionality on BeginUnbondingForPendingRequestsCallback…
jununifi Feb 13, 2024
569af02
Add controller_stacked_amount_to_deposit field increase code on stake…
jununifi Feb 19, 2024
b856c42
update parser for TxMsgData ica response
jununifi Feb 19, 2024
544478f
Fix BondLiquidityCallback handler for ica response parse
jununifi Feb 19, 2024
abaecd3
remove migration script from v105 to v106
jununifi Feb 19, 2024
c94eefa
add unit test for 13909 decoding to check stATOM icq failure
jununifi Feb 22, 2024
b10106a
update icq amount parser
jununifi Feb 23, 2024
16ce1eb
fix ibc_transfer_to_controller when withdrawing quote denom
jununifi Mar 13, 2024
358f0bc
fix to_transfer_amount
jununifi Mar 13, 2024
2f8ae6f
handle zero amount case in distribution
jununifi Mar 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions contracts/strategy-custodian/src/query/deposit_denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ pub fn query_deposit_denom(deps: Deps) -> StdResult<DepositDenomResp> {
let params: Params = PARAMS.load(deps.storage)?;
Ok(DepositDenomResp {
denom: params.deposit_denom,
target_chain_id: "".to_string(),
target_chain_denom: "".to_string(),
target_chain_addr: "".to_string(),
})
}
83 changes: 83 additions & 0 deletions contracts/strategy-osmosis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Osmosis strategy status groups

```rs
// Token transfer to host
// Affected states:
// - controller_stacked_amount_to_deposit
// - controller_pending_transfer_amount
// - controller deposit token amount
// - host deposit token amount
IbcTransferToHost
IbcTransferToHostCallback
// Timeout: can check with controller_pending_transfer_amount if not executed at this step
// Fine to revert back to IbcTransferToHost
RequestIcqAfterIbcTransferToHost
ResponseIcqAfterIbcTransferToHost

// External incentives sell
SellExternTokens
SellExternTokensCallback
RequestIcqAfterSellExternTokens
ResponseIcqAfterSellExternTokens

// Add and bond liquidity
// Affected states:
// - pending_bond_lp_amount
// - bonded_lp_amount
AddLiquidity
AddLiquidityCallback // Timeout: Fine to reset to AddLiquidity
BondLiquidity
BondLiquidityCallback // Timeout: Fine to revert back to BondLiquidity status without any change on pending_bond_lp_amount
RequestIcqAfterBondLiquidity
ResponseIcqAfterBondLiquidity

// Unbonding initialization
// Affected states:
// - unbondings |unbonding.start_time, unbonding.pending_start|
// - unbond_request_lp_amount
// - unbonding_lp_amount
// - bonded_lp_amount
BeginUnbondingForPendingRequests
BeginUnbondingForPendingRequestsCallback // Timeout: Fine to revert back to BeginUnbondingForPendingRequests

// Check if it needs to do the transition to withdraw phase
CheckMaturedUnbondings

// Remove liquidity
// Affected states:
// - unbondings |unbonding.marked|
// - pending_lp_removal_amount
// - unbonding_lp_amount
RemoveLiquidity
RemoveLiquidityCallback // Timeout: Fine to revert back to RemoveLiquidity
RequestIcqAfterRemoveLiquidity
ResponseIcqAfterRemoveLiquidity

// Swap removed liquidity to deposit token
// - host deposit token amount
SwapTwoTokensToDepositToken
SwapTwoTokensToDepositTokenCallback // Timeout: Fine to revert back to SwapTwoTokensToDepositToken
RequestIcqAfterSwapTwoTokensToDepositToken
ResponseIcqAfterSwapTwoTokensToDepositToken

// Token transfer to controller
// - host deposit token amount
// - controller deposit token amount
IbcTransferToController
IbcTransferToControllerCallback // Timeout: Fine to revert back to IbcTransferToController
RequestIcqAfterIbcTransferToController
ResponseIcqAfterIbcTransferToController

// Distribution to users
// Affected states
// - unbondings (remove marked unbondings after distribution)
// - total_withdrawn
// - controller deposit token amount
DistributeToUnbondedUsers
```

## Admin state transition notes

- Phase transition between Deposit & Withdraw should be careful and should carefully consider if anything would be broken.

- Phase step transition should check if the affecting states are safe.
112 changes: 70 additions & 42 deletions contracts/strategy-osmosis/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,38 @@ use crate::error::ContractError;
use crate::execute::epoch::epoch::execute_epoch;
use crate::execute::stake::execute_stake;
use crate::execute::superfluid::execute_superfluid_delegate;
use crate::execute::unstake::execute_unstake;
use crate::execute::update_config::execute_update_config;
use crate::execute::unstake::{
execute_instant_unbondings, execute_reset_unbond_request_lp_amount,
execute_reset_unbondings_to_beginning_state, execute_unstake,
};
use crate::execute::update_params::{execute_update_params, execute_update_state};
use crate::msgs::{ExecuteMsg, InstantiateMsg, MigrateMsg, Phase, PhaseStep, QueryMsg};
use crate::query::amounts::query_amounts;
use crate::query::bonded::query_bonded;
use crate::query::channel::query_channel;
use crate::query::config::query_config;
use crate::query::fee_info::query_fee_info;
use crate::query::kyc::query_kyc_info;
use crate::query::list_channels::query_list_channels;
use crate::query::params::{query_deposit_denom, query_params};
use crate::query::state::query_state;
use crate::query::unbonding::query_unbonding;
use crate::query::unbondings::{query_unbondings, UNBONDING_ITEM_LIMIT};
use crate::state::{
Config, DepositToken, EpochCallSource, State, CONFIG, STAKE_RATE_MULTIPLIER, STATE,
DepositToken, EpochCallSource, Params, State, LEGACY_STATE, PARAMS, STAKE_RATE_MULTIPLIER,
STATE, UNBONDINGS,
};
use crate::sudo::deposit_callback::sudo_deposit_callback;
use crate::sudo::kv_query_result::sudo_kv_query_result;
use crate::sudo::transfer_callback::sudo_transfer_callback;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128,
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128,
};
use cw_utils::one_coin;
use strategy::v0::msgs::SudoMsg;
use ununifi_binding::v0::binding::UnunifiMsg;
use strategy::v1::msgs::SudoMsg;
use strategy::v1::msgs::VersionResp;
use ununifi_binding::v1::binding::UnunifiMsg;

//Initialize the contract.
#[cfg_attr(not(feature = "library"), entry_point)]
Expand All @@ -35,8 +43,8 @@ pub fn instantiate(
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response<UnunifiMsg>, ContractError> {
let config = Config {
owner: info.sender,
let params = Params {
authority: info.sender,
unbond_period: msg.unbond_period,
phase: Phase::Deposit,
phase_step: PhaseStep::IbcTransferToHost,
Expand All @@ -57,7 +65,7 @@ pub fn instantiate(
automate_superfluid: msg.automate_superfluid,
extern_tokens: msg.extern_tokens.clone(),
};
CONFIG.save(deps.storage, &config)?;
PARAMS.save(deps.storage, &params)?;

let state = State {
last_unbonding_id: 1u64,
Expand All @@ -69,6 +77,7 @@ pub fn instantiate(
lp_redemption_rate: Uint128::from(200000u128),
lock_id: 0u64,
bonded_lp_amount: Uint128::from(0u128),
unbond_request_lp_amount: Uint128::from(0u128),
unbonding_lp_amount: Uint128::from(0u128),
free_lp_amount: Uint128::from(0u128),
pending_bond_lp_amount: Uint128::from(0u128),
Expand All @@ -88,29 +97,35 @@ pub fn instantiate(
#[entry_point]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> Result<Response<UnunifiMsg>, ContractError> {
match msg {
SudoMsg::KVQueryResult {
connection_id,
chain_id,
query_prefix,
query_key,
data,
} => sudo_kv_query_result(
SudoMsg::KvIcqCallback(data) => sudo_kv_query_result(
deps,
env,
data.connection_id,
data.chain_id,
data.query_prefix,
data.query_key,
data.data,
),
SudoMsg::TransferCallback(data) => sudo_transfer_callback(
deps,
env,
data.denom,
data.amount,
data.sender,
data.receiver,
data.memo,
data.success,
),
SudoMsg::IBCLifecycleComplete(_) => Ok(Response::new()),
SudoMsg::DepositCallback(data) => sudo_deposit_callback(
deps,
env,
connection_id,
chain_id,
query_prefix,
query_key,
data,
data.denom,
data.amount,
data.sender,
data.receiver,
data.success,
),
SudoMsg::TransferCallback {
denom,
amount,
sender,
receiver,
memo,
success,
} => sudo_transfer_callback(deps, env, denom, amount, sender, receiver, memo, success),
}
}

Expand All @@ -123,27 +138,36 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response<UnunifiMsg>, ContractError> {
match msg {
ExecuteMsg::UpdateConfig(msg) => execute_update_config(deps, env, info, msg),
ExecuteMsg::Stake(_) => {
let coin: Coin = one_coin(&info).map_err(|err| ContractError::Payment(err))?;
execute_stake(deps, env, coin, info.sender)
}
ExecuteMsg::Unstake(msg) => execute_unstake(deps, msg.amount, info.sender),
ExecuteMsg::UpdateParams(msg) => execute_update_params(deps, env, info, msg),
ExecuteMsg::UpdateState(msg) => execute_update_state(deps, env, info, msg),
ExecuteMsg::Stake(msg) => execute_stake(deps, env, info, msg),
ExecuteMsg::Unstake(msg) => execute_unstake(deps, env, info, msg),
ExecuteMsg::SuperfluidDelegate(_) => execute_superfluid_delegate(deps, env, info),
ExecuteMsg::ExecuteEpoch(_) => {
execute_epoch(deps, env, EpochCallSource::NormalEpoch, true, None)
ExecuteMsg::Epoch(_) => execute_epoch(deps, env, EpochCallSource::NormalEpoch, true, None),
ExecuteMsg::ResetUnbondingsToBeginState(msg) => {
execute_reset_unbondings_to_beginning_state(deps, env, info, msg)
}
ExecuteMsg::ResetUnbondRequestLpAmount(msg) => {
execute_reset_unbond_request_lp_amount(deps, env, info, msg)
}
ExecuteMsg::ProcessInstantUnbondings(msg) => {
execute_instant_unbondings(deps, env, info, msg)
}
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => to_binary(&query_config(deps)?),
QueryMsg::Version {} => to_binary(&query_version(deps)?),
QueryMsg::DepositDenom {} => to_binary(&query_deposit_denom(deps)?),
QueryMsg::Fee {} => to_binary(&query_fee_info(deps)?),
QueryMsg::Amounts { addr } => to_binary(&query_amounts(deps, addr)?),
QueryMsg::Kyc {} => to_binary(&query_kyc_info(deps)?),
QueryMsg::Params {} => to_binary(&query_params(deps)?),
QueryMsg::State {} => to_binary(&query_state(deps)?),
QueryMsg::Unbonding { addr } => to_binary(&query_unbonding(deps, addr)?),
QueryMsg::Bonded { addr } => to_binary(&query_bonded(deps, addr)?),
QueryMsg::Fee {} => to_binary(&query_fee_info(deps)?),
QueryMsg::ListChannels {} => to_binary(&query_list_channels(deps)?),
QueryMsg::Channel { id } => to_binary(&query_channel(deps, id)?),
QueryMsg::Unbondings {} => {
Expand All @@ -152,9 +176,13 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
}
}

pub fn query_version(_: Deps) -> StdResult<VersionResp> {
Ok(VersionResp { version: 1u8 })
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(
_deps: DepsMut,
deps: DepsMut,
_env: Env,
_msg: MigrateMsg,
) -> Result<Response<UnunifiMsg>, ContractError> {
Expand Down
12 changes: 11 additions & 1 deletion contracts/strategy-osmosis/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::num::TryFromIntError;
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use thiserror::Error;

Expand All @@ -20,6 +21,9 @@ pub enum ContractError {
#[error("Proto decode error")]
DecodeError(#[from] prost::DecodeError),

#[error("Proto decode error")]
Utf8Error(#[from] Utf8Error),

#[error("{0}")]
Payment(#[from] PaymentError),

Expand All @@ -29,7 +33,7 @@ pub enum ContractError {
#[error("Insufficient funds to redeem voucher on channel")]
InsufficientFunds {},

#[error("Only contract admin can do this")]
#[error("Only contract authority can do this")]
Unauthorized,

#[error("No allowed token")]
Expand All @@ -43,6 +47,12 @@ pub enum ContractError {

#[error("Unbonding item limitation reached")]
UnbondingItemLimitReached {},

#[error("Insufficient bonded lp tokens")]
InsufficientBondedLpTokens {},

#[error("Phase and PhaseStep mismatch")]
PhaseAndPhaseStepMismatch {},
}

impl From<FromUtf8Error> for ContractError {
Expand Down
Loading