injectivelabs / cw-injective Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
An example would be From<Decimal256> for FPDecimal
pub fn into_fp_decimal(value: Decimal256) -> FPDecimal {
let atomics = value.atomics().to_be_bytes();
FPDecimal { num: atomics.into(), sign: 1 }
}
but there are many more. As well some conversions seem to be using implementations for Display
which likely isn't best practice.
Commented by Dara and I agree:
Maybe we can impl a trait on injective_math so that we can use +, +=, -, -=, /, etc. Obviously for things like sub_abs we would still need to use the util though. For example impl Add for Decimal here:
docs.rs/cosmwasm-std/0.10.0/cosmwasm_std/struct.Decimal.html#impl-Add%3CDecimal%3EHere's a list of options to give you some ideas, if we're interested in doing this.
doc.rust-lang.org/nightly/core/ops/index.html
when I try to use
docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.13.0
it spits out issues about the use of is_some_and.
now version 0.14.0 of the workspace-optimizer doesn't fail.
but then it refuses to upload the wasm generated to injective-888
We currently pass in i32
for chain enum types like the order type or cancellation strategy. Wonder if we instead could use a Rust enum type or use some kind of alias to actually know what the i32 stands for.
and pow() returns that error
pub enum InjectiveQuery {
// Missing fields
SpotMarket {
market_id: String,
},
TraderSpotOrders {
market_id: String,
subaccount_id: String,
},
SpotMarketInfo {
market_id: String,
},
}
[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SpotLimitOrder {
pub order_info: OrderInfo,
pub order_type: i32,
pub fillable: FPDecimal,
pub trigger_price: Option<FPDecimal>,
pub order_hash: String,
}
impl SpotLimitOrder {
pub fn new(
fillable: FPDecimal,
order_hash: String,
trigger_price: Option<FPDecimal>,
order_type: i32,
order_info: OrderInfo,
) -> SpotLimitOrder {
SpotLimitOrder {
fillable,
order_hash,
trigger_price,
order_type,
order_info,
}
}
}
[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SpotMarketOrder {
pub order_info: OrderInfo,
pub order_type: i32,
pub fillable: FPDecimal,
pub trigger_price: Option<FPDecimal>,
pub order_hash: String,
}
impl SpotMarketOrder {
pub fn new(
fillable: FPDecimal,
order_hash: String,
trigger_price: Option<FPDecimal>,
order_type: i32,
order_info: OrderInfo,
) -> SpotLimitOrder {
SpotLimitOrder {
fillable,
order_hash,
trigger_price,
order_type,
order_info,
}
}
}
#[allow(non_snake_case)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct TrimmedSpotLimitOrder {
pub price: FPDecimal,
pub quantity: FPDecimal,
pub fillable: FPDecimal,
pub isBuy: bool,
pub order_hash: String,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct TraderSpotOrdersResponse {
pub orders: Option<Vec<TrimmedSpotLimitOrder>>,
}
#[allow(non_snake_case)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SpotMarket {
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 maker_fee_rate: FPDecimal,
pub taker_fee_rate: FPDecimal,
#[serde(default)]
pub isPerpetual: bool, // this is from DerivativeMarket, not sure if this is necessary
#[serde(default)]
pub status: i32,
pub min_price_tick_size: FPDecimal,
pub min_quantity_tick_size: FPDecimal,
}
#[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(
margin: FPDecimal,
fillable: FPDecimal,
order_hash: String,
trigger_price: Option<FPDecimal>,
order_type: i32,
order_info: OrderInfo,
) -> DerivativeLimitOrder {
DerivativeLimitOrder {
margin,
fillable,
order_hash,
trigger_price,
order_type,
order_info,
}
}
pub fn is_reduce_only(&self) -> bool {
self.margin.is_zero()
}
}
DerivativeMarketOrder
is possible missing.
specifically the error is
error[E0432]: unresolved import `test_helpers::testing_helpers`
--> /Users/ewoolsey/.cargo/registry/src/github.com-1ecc6299db9ec823/injective-cosmwasm-0.2.1/src/lib.rs:51:23
|
51 | pub use test_helpers::testing_helpers::{
| ^^^^^^^^^^^^^^^ could not find `testing_helpers` in `test_helpers`
All the query
in this enum is single market query, I suggest we also add multi-market query.
A user case would be Spot-Perp arbritage on ETH/USDT Perp, and WETH/USDT market.
cw-injective/packages/injective-cosmwasm/src/query.rs
Lines 22 to 65 in 2625e48
What we already do inside https://github.com/InjectiveLabs/swap-contract/blob/d56991ca20784a5e0c1d35ed648e3f4da001777f/contracts/swap/src/queries.rs#L94 would be pretty useful to integrate as proper API inside injective-cosmwasm
The Cosmos-SDK's empty sdk.Dec (e.g. sdk.Dec{}
) string form is represented as "<nil>"
(proof below).
However, FPDecimals' from_str
method won't be able to convert this value.
cw-injective/packages/injective-math/src/fp_decimal/from_str.rs
Lines 10 to 45 in 09b1925
Should we handle this case? If so, how? @DrunkRandomWalker @gorgos
Proof:
type Dec struct {
i *big.Int
}
func (d Dec) String() string {
if d.i == nil {
return d.i.String()
}
...
}
and big.Int's String method is simply
// String returns the decimal representation of x as generated by
// x.Text(10).
func (x *Int) String() string {
return x.Text(10)
}
// Text returns the string representation of x in the given base.
// Base must be between 2 and 62, inclusive. The result uses the
// lower-case letters 'a' to 'z' for digit values 10 to 35, and
// the upper-case letters 'A' to 'Z' for digit values 36 to 61.
// No prefix (such as "0x") is added to the string. If x is a nil
// pointer it returns "<nil>".
func (x *Int) Text(base int) string {
if x == nil {
return "<nil>"
}
return string(x.abs.itoa(x.neg, base))
}
Can we please keep the power functions as simple as - a^(x) = e ^ (x * log (a)) - this might be slightly expensive (roughly 26 iterations from taylor ex + dunno if we're using karastuba-offman multiplication ) but we will get very stable results. We can further optimize both log and exp implementations - via bilinear transformations.
Right now I am unable to handle governance proposals containing MsgUpdateParams /cosmos.mint.v1beta1.MsgUpdateParams
fix is to do the following in cargo.toml
primitive-types = {version= "0.12.2" ,default-features = false}
to injective-math's cargo.toml.
I found that primitive-types was including 'random', and causing wasm-bindgen to be included in smart contracts (and failing to store on injective-888).
Code to move: https://github.com/InjectiveLabs/cw-injective/blob/dev/packages/injective-cosmwasm/src/exchange_mock_querier.rs
It's only being used by Mito Contracts anyway, but having it in a separate package just makes our life more difficult.
#[allow(clippy::upper_case_acronyms)]
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, JsonSchema)]
pub struct FPDecimal {
#[schemars(with = "String")]
pub num: U256,
pub sign: i8,
}
FPDecimal
implemented Copy
trait, parameter in associated functions in below are passed parameters by value. So values are copied, I think we are safe to pass parameters by reference, and copy when it is necessary.
cw-injective/packages/injective-math/src/fp_decimal/mod.rs
Lines 116 to 121 in cb5b322
cw-injective/packages/injective-math/src/fp_decimal/mod.rs
Lines 131 to 137 in cb5b322
The new Name
trait in prost 0.12 brings a lot more ease of use for consumers. Would love to see these deps updated.
No reason to use unchecked()
if we can use must_new()
and skip handling of Result<ShortSubaccountId, Error>
For the moment, to get the Uint256 type from a FPDecimal, we need to use to_u256(). However, this is a bit restrictive when we need to convert several different types into Uint256 inside a macro, for example.
The solution would be to add just this feature to the structure
Currently if there exist deactivated (not executable) contracts in the CONTRACTS map, query_active_contracts
can return fewer contracts than the limit
in the paginated query.
cw-injective/contracts/registry/src/contract.rs
Lines 258 to 265 in 7aa376f
We can use an IndexedMap to iterate solely over the executable contracts to resolve this issue.
Add integration tests on the CI for the cosmwasm using a smart contract to consume the cw, and calling the sc on test-tube's chain.
I noticed you've been maintaining your own decimal type. A while ago, I worked on [a basic SignedDecimal type for CosmWasm]( (https://github.com/atomiklabs/atl-cw/blob/master/packages/signed-decimal/src/signed_decimal.rs). It is based on cosmwasm_std::Decimal
type.
Perhaps you'd like to use this type which is interoperable with the underlying type from CosmWasm STD.
I was wondering what are your thoughts about it? Thank you in advance for taking a look ๐
Perhaps there is a reason for this that I'm not aware of, but it seems injective-protobuf is not building all of the types defined in the .proto
files. An example being EthAccount
. This can be fixed by simply adding the paths to the missing proto files into the inputs in build.rs
. I would be happy to submit a PR for this if it will be accepted.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.