diff --git a/src/action/execute/claim_rewards_request.rs b/src/action/execute/claim_rewards_request.rs new file mode 100644 index 0000000..9351e40 --- /dev/null +++ b/src/action/execute/claim_rewards_request.rs @@ -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, + delegator_address: String, + withdraw_type: EarnType, +) -> Result, ContractError> { + let msg = ElysMsg::withdraw_rewards( + delegator_address, + withdraw_type, + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/execute/claim_validator_commission_request.rs b/src/action/execute/claim_validator_commission_request.rs new file mode 100644 index 0000000..912f092 --- /dev/null +++ b/src/action/execute/claim_validator_commission_request.rs @@ -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, + delegator_address: String, + validator_address: String, +) -> Result, ContractError> { + let msg = ElysMsg::withdraw_validator_commissions( + delegator_address, + validator_address, + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/execute/eden_cancel_vest_request.rs b/src/action/execute/eden_cancel_vest_request.rs new file mode 100644 index 0000000..9033dc1 --- /dev/null +++ b/src/action/execute/eden_cancel_vest_request.rs @@ -0,0 +1,20 @@ +use crate::bindings::query::ElysQuery; + +use super::*; +pub fn eden_cancel_vest_request( + _env: Env, + _info: MessageInfo, + _deps: DepsMut, + creator: String, + amount: u64, +) -> Result, ContractError> { + let msg = ElysMsg::eden_cancel_vesting( + creator, + Int128::from(amount), + "ueden".to_string(), + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/execute/eden_vest_request.rs b/src/action/execute/eden_vest_request.rs new file mode 100644 index 0000000..6db0a86 --- /dev/null +++ b/src/action/execute/eden_vest_request.rs @@ -0,0 +1,20 @@ +use crate::bindings::query::ElysQuery; + +use super::*; +pub fn eden_vest_request( + _env: Env, + _info: MessageInfo, + _deps: DepsMut, + creator: String, + amount: u64, +) -> Result, ContractError> { + let msg: ElysMsg = ElysMsg::eden_vesting( + creator, + Int128::from(amount), + "ueden".to_string(), + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/execute/elys_cancel_unstake_request.rs b/src/action/execute/elys_cancel_unstake_request.rs new file mode 100644 index 0000000..51eb2f1 --- /dev/null +++ b/src/action/execute/elys_cancel_unstake_request.rs @@ -0,0 +1,23 @@ +use crate::bindings::query::ElysQuery; + +use super::*; +pub fn elys_cancel_unstake_request( + _env: Env, + _info: MessageInfo, + _deps: DepsMut, + delegator_address: String, + validator_address: String, + amount: Coin, + creation_height: i64, +) -> Result, ContractError> { + let msg = ElysMsg::cancel_unbonding( + delegator_address, + validator_address, + amount, + creation_height, + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/execute/elys_redelegation_request.rs b/src/action/execute/elys_redelegation_request.rs new file mode 100644 index 0000000..8d929f6 --- /dev/null +++ b/src/action/execute/elys_redelegation_request.rs @@ -0,0 +1,28 @@ +use crate::bindings::query::ElysQuery; + +use super::*; +pub fn elys_redelegation_request( + _env: Env, + _info: MessageInfo, + _deps: DepsMut, + // 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, ContractError> { + let msg = ElysMsg::begin_redelegate( + delegator_address, + validator_src_address, + validator_dst_address, + amount, + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/execute/stake_request.rs b/src/action/execute/stake_request.rs new file mode 100644 index 0000000..6cbe030 --- /dev/null +++ b/src/action/execute/stake_request.rs @@ -0,0 +1,36 @@ +use crate::{bindings::query::ElysQuery, bindings::querier::ElysQuerier}; + +use super::*; + +pub fn stake_request( + _env: Env, + _info: MessageInfo, + deps: DepsMut, + // 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 +) -> Result, 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) +} \ No newline at end of file diff --git a/src/action/execute/unstake_request.rs b/src/action/execute/unstake_request.rs new file mode 100644 index 0000000..b2d8c4f --- /dev/null +++ b/src/action/execute/unstake_request.rs @@ -0,0 +1,29 @@ +use crate::bindings::query::ElysQuery; + +use super::*; + +pub fn unstake_request( + _env: Env, + _info: MessageInfo, + _deps: DepsMut, + // 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 +) -> Result, ContractError> { + let msg = ElysMsg::unstake_token( + address, + Int128::from(amount), + asset, + validator_address, + ); + + let resp = Response::new().add_message(msg); + + Ok(resp) +} \ No newline at end of file diff --git a/src/action/mod.rs b/src/action/mod.rs index f577b38..d763ade 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -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; @@ -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 { diff --git a/src/entry_point/execute.rs b/src/entry_point/execute.rs index 3f67242..941f5ea 100644 --- a/src/entry_point/execute.rs +++ b/src/entry_point/execute.rs @@ -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), } } diff --git a/src/msg/execute_msg.rs b/src/msg/execute_msg.rs index 02b23f4..d6a4c95 100644 --- a/src/msg/execute_msg.rs +++ b/src/msg/execute_msg.rs @@ -36,4 +36,46 @@ pub enum ExecuteMsg { CloseMarginPosition { id: u64, }, + StakeRequest { + address: String, + amount: u64, + asset: String, + validator_address: Option, + }, + UnstakeRequest { + address: String, + amount: u64, + asset: String, + validator_address: Option, + }, + 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, + } } diff --git a/src/types/earn_type.rs b/src/types/earn_type.rs new file mode 100644 index 0000000..5459b86 --- /dev/null +++ b/src/types/earn_type.rs @@ -0,0 +1,10 @@ +use cosmwasm_schema::cw_serde; + +#[cw_serde] +pub enum EarnType { + AllProgram = 0, + UsdcProgram = 1, + ElysProgram = 2, + EdenProgram = 3, + EdenBProgram = 4, +} \ No newline at end of file diff --git a/src/types/mod.rs b/src/types/mod.rs index b152c01..ff910f9 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -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::*; @@ -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;