-
Notifications
You must be signed in to change notification settings - Fork 1
DEX usage fee #230
DEX usage fee #230
Changes from all commits
b0ed43f
9c7cd3b
296ba8c
b4cc26e
4b24d8a
c7b59ff
d4d3ab6
d8c6804
627310a
d95b055
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::contract::{DexApi, DexResult}; | ||
use abstract_os::{ | ||
dex::{state::SWAP_FEE, DexInstantiateMsg}, | ||
objects::fee::UsageFee, | ||
}; | ||
use abstract_sdk::OsVerification; | ||
use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; | ||
|
||
pub fn instantiate_handler( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
api: DexApi, | ||
msg: DexInstantiateMsg, | ||
) -> DexResult { | ||
let recipient = api | ||
.os_registry(deps.as_ref()) | ||
.proxy_address(msg.recipient_os)?; | ||
let fee = UsageFee::new(deps.api, msg.swap_fee, recipient)?; | ||
SWAP_FEE.save(deps.storage, &fee)?; | ||
Ok(Response::default()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod execute; | ||
mod instantiate; | ||
mod query; | ||
|
||
pub use {execute::execute_handler, query::query_handler}; | ||
pub use {execute::execute_handler, instantiate::instantiate_handler, query::query_handler}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,18 +13,47 @@ pub type DexName = String; | |
pub type OfferAsset = AnsAsset; | ||
pub type AskAsset = AnsAsset; | ||
|
||
pub mod state { | ||
use cw_storage_plus::Item; | ||
|
||
use crate::objects::fee::UsageFee; | ||
|
||
pub const SWAP_FEE: Item<UsageFee> = Item::new("swap_fee"); | ||
} | ||
|
||
pub const IBC_DEX_ID: u32 = 11335; | ||
|
||
pub type ExecuteMsg = api::ExecuteMsg<DexExecuteMsg>; | ||
pub type ExecuteMsg = api::ExecuteMsg<DexApiExecuteMsg>; | ||
pub type QueryMsg = api::QueryMsg<DexQueryMsg>; | ||
pub type InstantiateMsg = api::InstantiateMsg<DexInstantiateMsg>; | ||
|
||
impl api::ApiExecuteMsg for DexExecuteMsg {} | ||
|
||
impl api::ApiExecuteMsg for DexApiExecuteMsg {} | ||
impl api::ApiQueryMsg for DexQueryMsg {} | ||
|
||
#[cosmwasm_schema::cw_serde] | ||
pub struct DexInstantiateMsg { | ||
pub swap_fee: Decimal, | ||
pub recipient_os: u32, | ||
CyberHoward marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// Dex Execute msg | ||
#[cosmwasm_schema::cw_serde] | ||
pub enum DexApiExecuteMsg { | ||
Action(DexExecuteMsg), | ||
UpdateFee { | ||
swap_fee: Option<Decimal>, | ||
recipient_os_id: Option<u32>, | ||
}, | ||
} | ||
Comment on lines
+40
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I guess the json would be: {
"app": {
"action": {
"action": {
"swap": {...}
},
"dex": "lolswap",
}
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {
"app": {
"execute": {
"dex": "lolswap",
"action": {
"swap": {...}
},
}
}
} ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The users shouldn't be interacting with the json too much but still the nested duplicate names can be confusing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative to this is to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmmm..... {
"app": {
"dex": "lolswap",
"action": {
"swap": {...}
},
}
} Configuring: {
"configure": {
"update_fee": {...}
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to discuss this during standup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think adding a #[serde(flatten)] tag to the action variant should remove the nested nature of the msg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not even sure if those unit-enum variants actually get their own key or if the inner value name is used as key. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code: use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
struct FooFoo {
x: i32,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
enum Bar {
Foo(FooFoo),
Baz,
}
fn main() {
let bar = Bar::Foo(FooFoo { x: 42 });
println!("bar = {:?}", bar);
println!("bar = {}", serde_json::to_string_pretty(&bar).unwrap());
} Returns: bar = Foo(FooFoo { x: 42 })
bar = {
"Foo": {
"x": 42
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also opt for a "type" tag which would look like:
And change the Action name to something different. |
||
|
||
impl From<DexExecuteMsg> for DexApiExecuteMsg { | ||
fn from(action: DexExecuteMsg) -> Self { | ||
DexApiExecuteMsg::Action(action) | ||
} | ||
} | ||
|
||
/// Dex Execute msg | ||
#[cosmwasm_schema::cw_serde] | ||
// Struct messages not yet supported by BOOT | ||
pub struct DexExecuteMsg { | ||
pub dex: DexName, | ||
pub action: DexAction, | ||
|
@@ -100,4 +129,6 @@ pub struct SimulateSwapResponse { | |
pub spread_amount: Uint128, | ||
/// Commission charged for the swap | ||
pub commission: (AssetEntry, Uint128), | ||
/// API fee charged for the swap (paid in offer asset) | ||
pub api_fee: Uint128, | ||
CyberHoward marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.