-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add deposit message * chore: add further address utils * feat: add more Msgs and reorganize files Co-authored-by: Markus Waas <[email protected]>
- Loading branch information
1 parent
cb5b322
commit 09b1925
Showing
12 changed files
with
572 additions
and
252 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "injective-cosmwasm" | ||
version = "0.1.9" | ||
version = "0.1.12" | ||
authors = ["Albert Chon <[email protected]>"] | ||
edition = "2018" | ||
description = "Bindings for CosmWasm contracts to call into custom modules of Injective Core" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
use crate::order::OrderInfo; | ||
use injective_math::FPDecimal; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[allow(non_snake_case)] | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct Position { | ||
#[serde(default)] | ||
pub isLong: bool, | ||
pub quantity: FPDecimal, | ||
pub entry_price: FPDecimal, | ||
#[serde(default)] | ||
pub margin: FPDecimal, | ||
pub cumulative_funding_entry: FPDecimal, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct EffectivePosition { | ||
#[serde(default)] | ||
pub is_long: bool, | ||
pub quantity: FPDecimal, | ||
pub entry_price: FPDecimal, | ||
#[serde(default)] | ||
pub effective_margin: FPDecimal, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct DerivativePosition { | ||
pub subaccount_id: String, | ||
pub market_id: String, | ||
pub position: Position, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct DerivativeOrder { | ||
pub market_id: String, | ||
pub order_info: OrderInfo, | ||
pub order_type: i32, | ||
pub margin: FPDecimal, | ||
pub trigger_price: Option<String>, | ||
} | ||
|
||
impl DerivativeOrder { | ||
pub fn new( | ||
price: FPDecimal, | ||
quantity: FPDecimal, | ||
margin: FPDecimal, | ||
is_buy: bool, | ||
market_id: &str, | ||
subaccount_id: &str, | ||
fee_recipient: &str, | ||
) -> Self { | ||
DerivativeOrder { | ||
market_id: market_id.to_string(), | ||
order_info: OrderInfo { | ||
subaccount_id: subaccount_id.to_string(), | ||
fee_recipient: fee_recipient.to_string(), | ||
price, | ||
quantity, | ||
}, | ||
order_type: if is_buy { 1 } else { 2 }, // TODO PO-orders | ||
margin, | ||
trigger_price: None, | ||
} | ||
} | ||
pub fn is_reduce_only(&self) -> bool { | ||
self.margin.is_zero() | ||
} | ||
pub fn get_price(&self) -> FPDecimal { | ||
self.order_info.price | ||
} | ||
pub fn get_qty(&self) -> FPDecimal { | ||
self.order_info.quantity | ||
} | ||
pub fn get_val(&self) -> FPDecimal { | ||
self.get_price() * self.get_qty() | ||
} | ||
pub fn get_margin(&self) -> FPDecimal { | ||
self.margin | ||
} | ||
pub fn non_reduce_only_is_invalid(&self) -> bool { | ||
self.get_margin().is_zero() || self.get_price().is_zero() || self.get_qty().is_zero() | ||
} | ||
pub fn reduce_only_price_is_invalid(&self) -> bool { | ||
self.get_price().is_zero() | ||
} | ||
pub fn reduce_only_qty_is_invalid(&self) -> bool { | ||
self.get_qty().is_zero() | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct DerivativeLimitOrder { | ||
pub order_info: OrderInfo, | ||
pub order_type: i32, | ||
pub margin: FPDecimal, | ||
pub fillable: FPDecimal, | ||
pub trigger_price: Option<FPDecimal>, | ||
pub order_hash: String, | ||
} | ||
|
||
impl DerivativeLimitOrder { | ||
pub fn new( | ||
margin: FPDecimal, | ||
fillable: FPDecimal, | ||
order_hash: String, | ||
trigger_price: Option<FPDecimal>, | ||
order_type: i32, | ||
order_info: OrderInfo, | ||
) -> Self { | ||
DerivativeLimitOrder { | ||
margin, | ||
fillable, | ||
order_hash, | ||
trigger_price, | ||
order_type, | ||
order_info, | ||
} | ||
} | ||
pub fn is_reduce_only(&self) -> bool { | ||
self.margin.is_zero() | ||
} | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct TrimmedDerivativeLimitOrder { | ||
pub price: FPDecimal, | ||
pub quantity: FPDecimal, | ||
pub margin: FPDecimal, | ||
pub fillable: FPDecimal, | ||
pub isBuy: bool, | ||
pub order_hash: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct DerivativeMarketOrder { | ||
pub order_info: OrderInfo, | ||
pub order_type: i32, | ||
pub margin: FPDecimal, | ||
pub fillable: FPDecimal, | ||
pub trigger_price: Option<FPDecimal>, | ||
pub order_hash: String, | ||
} | ||
|
||
impl DerivativeMarketOrder { | ||
pub fn new( | ||
order_info: OrderInfo, | ||
order_type: i32, | ||
margin: FPDecimal, | ||
fillable: FPDecimal, | ||
trigger_price: Option<FPDecimal>, | ||
order_hash: String, | ||
) -> Self { | ||
DerivativeMarketOrder { | ||
margin, | ||
fillable, | ||
order_hash, | ||
trigger_price, | ||
order_type, | ||
order_info, | ||
} | ||
} | ||
pub fn is_reduce_only(&self) -> bool { | ||
self.margin.is_zero() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use injective_math::FPDecimal; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct PerpetualMarketInfo { | ||
pub market_id: String, | ||
#[serde(default)] | ||
pub hourly_funding_rate_cap: FPDecimal, | ||
#[serde(default)] | ||
pub hourly_interest_rate: FPDecimal, | ||
#[serde(default)] | ||
pub next_funding_timestamp: i64, | ||
pub funding_interval: i64, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct PerpetualMarketFunding { | ||
#[serde(default)] | ||
pub cumulative_funding: FPDecimal, | ||
#[serde(default)] | ||
pub cumulative_price: FPDecimal, | ||
#[serde(default)] | ||
pub last_timestamp: i64, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct PerpetualMarketState { | ||
pub market_info: PerpetualMarketInfo, | ||
pub funding_info: PerpetualMarketFunding, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct FullDerivativeMarketPerpetualInfo { | ||
pub perpetual_info: PerpetualMarketState, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct FullDerivativeMarket { | ||
pub market: Option<DerivativeMarket>, | ||
pub info: Option<FullDerivativeMarketPerpetualInfo>, | ||
pub mark_price: FPDecimal, | ||
} | ||
|
||
#[allow(non_snake_case)] | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct DerivativeMarket { | ||
pub ticker: String, | ||
pub oracle_base: String, | ||
pub oracle_quote: String, | ||
#[serde(default)] | ||
pub oracle_type: i32, | ||
#[serde(default)] | ||
pub oracle_scale_factor: u32, | ||
pub quote_denom: String, | ||
pub market_id: String, | ||
pub initial_margin_ratio: FPDecimal, | ||
pub maintenance_margin_ratio: FPDecimal, | ||
pub maker_fee_rate: FPDecimal, | ||
pub taker_fee_rate: FPDecimal, | ||
#[serde(default)] | ||
pub isPerpetual: bool, | ||
#[serde(default)] | ||
pub status: i32, | ||
pub min_price_tick_size: FPDecimal, | ||
pub min_quantity_tick_size: FPDecimal, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use injective_math::FPDecimal; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Deposit is data format for the subaccount deposit | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] | ||
pub struct Deposit { | ||
#[serde(default)] | ||
pub available_balance: FPDecimal, | ||
#[serde(default)] | ||
pub total_balance: FPDecimal, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.