Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
chore: add execution functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta-elys committed Nov 30, 2023
1 parent d393c74 commit fde26e8
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/action/execute/claim_rewards_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::bindings::query::ElysQuery;
use crate::types::EarnType;

use super::*;
pub fn claim_rewards_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
delegator_address: String,
withdraw_type: EarnType,
) -> Result<Response<ElysMsg>, ContractError> {
let msg = ElysMsg::withdraw_rewards(
delegator_address,
withdraw_type,
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
20 changes: 20 additions & 0 deletions src/action/execute/claim_validator_commission_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::bindings::query::ElysQuery;

use super::*;
// delegator_address, validator_address, denom
pub fn claim_validator_commission_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
delegator_address: String,
validator_address: String,
) -> Result<Response<ElysMsg>, ContractError> {
let msg = ElysMsg::withdraw_validator_commissions(
delegator_address,
validator_address,
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
20 changes: 20 additions & 0 deletions src/action/execute/eden_cancel_vest_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::bindings::query::ElysQuery;

use super::*;
pub fn eden_cancel_vest_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
creator: String,
amount: u64,
) -> Result<Response<ElysMsg>, ContractError> {
let msg = ElysMsg::eden_cancel_vesting(
creator,
Int128::from(amount),
"ueden".to_string(),
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
20 changes: 20 additions & 0 deletions src/action/execute/eden_vest_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::bindings::query::ElysQuery;

use super::*;
pub fn eden_vest_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
creator: String,
amount: u64,
) -> Result<Response<ElysMsg>, ContractError> {
let msg: ElysMsg = ElysMsg::eden_vesting(
creator,
Int128::from(amount),
"ueden".to_string(),
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
23 changes: 23 additions & 0 deletions src/action/execute/elys_cancel_unstake_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::bindings::query::ElysQuery;

use super::*;
pub fn elys_cancel_unstake_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
delegator_address: String,
validator_address: String,
amount: Coin,
creation_height: i64,
) -> Result<Response<ElysMsg>, ContractError> {
let msg = ElysMsg::cancel_unbonding(
delegator_address,
validator_address,
amount,
creation_height,
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
28 changes: 28 additions & 0 deletions src/action/execute/elys_redelegation_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::bindings::query::ElysQuery;

use super::*;
pub fn elys_redelegation_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
// the address of the current user.
delegator_address: String,
// the amount to be staked in base denomination.
validator_src_address: String,
// The asset to be staked
validator_dst_address: String,
// The validator Address is required only if the staked asset is
// uelys.
amount: Coin
) -> Result<Response<ElysMsg>, ContractError> {
let msg = ElysMsg::begin_redelegate(
delegator_address,
validator_src_address,
validator_dst_address,
amount,
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
36 changes: 36 additions & 0 deletions src/action/execute/stake_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use crate::{bindings::query::ElysQuery, bindings::querier::ElysQuerier};

use super::*;

pub fn stake_request(
_env: Env,
_info: MessageInfo,
deps: DepsMut<ElysQuery>,
// the address of the current user.
address: String,
// the amount to be staked in base denomination.
amount: u64,
// The asset to be staked
asset: String,
// The validator Address is required only if the staked asset is
// uelys.
validator_address: Option<String>
) -> Result<Response<ElysMsg>, ContractError> {
let querier = ElysQuerier::new(&deps.querier);
let balance = querier.get_balance(address.to_owned(), asset.to_owned())?;
let token_amount: u128 = balance.amount.into();
if token_amount < amount as u128 {
return Err(ContractError::InsufficientBalanceError { balance: balance.amount.into(), amount: amount });
}

let msg = ElysMsg::stake_token(
address,
Int128::from(amount),
asset,
validator_address,
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
29 changes: 29 additions & 0 deletions src/action/execute/unstake_request.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::bindings::query::ElysQuery;

use super::*;

pub fn unstake_request(
_env: Env,
_info: MessageInfo,
_deps: DepsMut<ElysQuery>,
// the address of the current user.
address: String,
// the amount to be staked in base denomination.
amount: u64,
// The asset to be staked
asset: String,
// The validator Address is required only if the staked asset is
// uelys.
validator_address: Option<String>
) -> Result<Response<ElysMsg>, ContractError> {
let msg = ElysMsg::unstake_token(
address,
Int128::from(amount),
asset,
validator_address,
);

let resp = Response::new().add_message(msg);

Ok(resp)
}
20 changes: 20 additions & 0 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ pub mod execute {
mod close_margin_position;
mod create_margin_order;
mod create_spot_order;

mod stake_request;
mod unstake_request;

mod claim_rewards_request;
mod claim_validator_commission_request;
mod eden_cancel_vest_request;
mod eden_vest_request;
mod elys_cancel_unstake_request;
mod elys_redelegation_request;

use super::*;

pub use cancel_margin_order::cancel_margin_order;
Expand All @@ -43,6 +54,15 @@ pub mod execute {
pub use close_margin_position::close_margin_position;
pub use create_margin_order::create_margin_order;
pub use create_spot_order::create_spot_order;

pub use stake_request::stake_request;
pub use unstake_request::unstake_request;
pub use claim_rewards_request::claim_rewards_request;
pub use claim_validator_commission_request::claim_validator_commission_request;
pub use eden_cancel_vest_request::eden_cancel_vest_request;
pub use eden_vest_request::eden_vest_request;
pub use elys_cancel_unstake_request::elys_cancel_unstake_request;
pub use elys_redelegation_request::elys_redelegation_request;
}

pub mod reply {
Expand Down
9 changes: 9 additions & 0 deletions src/entry_point/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,14 @@ pub fn execute(
),
CancelMarginOrder { order_id } => cancel_margin_order(info, deps, order_id),
CloseMarginPosition { id } => close_margin_position(info, env, id),

StakeRequest { address, amount, asset, validator_address } => stake_request(env, info, deps, address, amount, asset, validator_address),
UnstakeRequest { address, amount, asset, validator_address } => unstake_request(env, info, deps, address, amount, asset, validator_address),
ElysRedelegateRequest { delegator_address, validator_src_address, validator_dst_address, amount} => elys_redelegation_request(env, info, deps, delegator_address, validator_src_address, validator_dst_address, amount),
ElysCancelUnstakeRequest { delegator_address, validator_address, amount, creation_height } => elys_cancel_unstake_request(env, info, deps, delegator_address, validator_address, amount, creation_height),
EdenVestRequest { creator, amount} => eden_vest_request(env, info, deps, creator, amount),
EdenCancelVestRequest { creator, amount } => eden_cancel_vest_request(env, info, deps, creator, amount),
ClaimRewardsRequest { delegator_address, withdraw_type } => claim_rewards_request(env, info, deps, delegator_address, withdraw_type),
ClaimValidatorCommissionRequest { delegator_address, validator_address } => claim_validator_commission_request(env, info, deps, delegator_address, validator_address),
}
}
42 changes: 42 additions & 0 deletions src/msg/execute_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,46 @@ pub enum ExecuteMsg {
CloseMarginPosition {
id: u64,
},
StakeRequest {
address: String,
amount: u64,
asset: String,
validator_address: Option<String>,
},
UnstakeRequest {
address: String,
amount: u64,
asset: String,
validator_address: Option<String>,
},
ElysRedelegateRequest {
delegator_address: String,
validator_src_address: String,
validator_dst_address: String,
amount: Coin,
},
ElysCancelUnstakeRequest {
delegator_address: String,
validator_address: String,
// amount is always less than or equal to unbonding delegation entry balance
amount: Coin,
// creation_height is the height which the unbonding took place.
creation_height: i64,
},
EdenVestRequest {
creator: String,
amount: u64,
},
EdenCancelVestRequest {
creator: String,
amount: u64,
},
ClaimRewardsRequest {
delegator_address: String,
withdraw_type: EarnType,
},
ClaimValidatorCommissionRequest {
delegator_address: String,
validator_address: String,
}
}
10 changes: 10 additions & 0 deletions src/types/earn_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cosmwasm_schema::cw_serde;

#[cw_serde]
pub enum EarnType {
AllProgram = 0,
UsdcProgram = 1,
ElysProgram = 2,
EdenProgram = 3,
EdenBProgram = 4,
}
2 changes: 2 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod date;
mod margin_order;
mod reply_info;
mod status;
mod earn_type;

pub use date::Date;
pub use elys_bindings::types::*;
Expand All @@ -21,3 +22,4 @@ pub use reply_info::ReplyInfo;
pub use spot_order::spot_order::SpotOrder;
pub use spot_order_price::OrderPrice;
pub use status::Status;
pub use earn_type::EarnType;

0 comments on commit fde26e8

Please sign in to comment.