Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinity index queries #25

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/infinity-index/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "infinity-index"
version = "0.1.0"
version = "0.1.1"
edition = { workspace = true }
repository = { workspace = true }
license = { workspace = true }
Expand Down
14 changes: 10 additions & 4 deletions contracts/infinity-index/schema/infinity-index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "infinity-index",
"contract_version": "0.1.0",
"contract_version": "0.1.1",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -160,9 +160,11 @@
"properties": {
"amount": {
"description": "The amount of tokens in being quoted",
"type": "integer",
"format": "uint128",
"minimum": 0.0
"allOf": [
{
"$ref": "#/definitions/Uint128"
}
]
},
"pair": {
"description": "The address of the infinity pair contract",
Expand Down Expand Up @@ -243,6 +245,10 @@
}
},
"additionalProperties": false
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions contracts/infinity-index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod execute;
pub mod helpers;
pub mod instantiate;
pub mod migrate;
pub mod msg;
pub mod query;
pub mod state;
Expand Down
39 changes: 39 additions & 0 deletions contracts/infinity-index/src/migrate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::{
error::ContractError,
instantiate::{CONTRACT_NAME, CONTRACT_VERSION},
};

use cosmwasm_std::{ensure, DepsMut, Empty, Env, Event, StdError};
use sg_std::Response;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;

#[cfg_attr(not(feature = "library"), entry_point)]
#[allow(clippy::cmp_owned)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
let prev_contract_version = cw2::get_contract_version(deps.storage)?;

let valid_contract_names = vec![CONTRACT_NAME.to_string()];
ensure!(
valid_contract_names.contains(&prev_contract_version.contract),
StdError::generic_err("Invalid contract name for migration")
);

ensure!(
prev_contract_version.version < CONTRACT_VERSION.to_string(),
StdError::generic_err("Must upgrade contract version")
);

cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

let response = Response::new().add_event(
Event::new("migrate")
.add_attribute("from_name", prev_contract_version.contract)
.add_attribute("from_version", prev_contract_version.version)
.add_attribute("to_name", CONTRACT_NAME)
.add_attribute("to_version", CONTRACT_VERSION),
);

Ok(response)
}
2 changes: 1 addition & 1 deletion contracts/infinity-index/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct PairQuoteOffset {
/// The address of the infinity pair contract
pub pair: String,
/// The amount of tokens in being quoted
pub amount: u128,
pub amount: Uint128,
}

#[cw_serde]
Expand Down
4 changes: 2 additions & 2 deletions contracts/infinity-index/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn query_sell_to_pair_quotes(
min,
max,
} = query_options.unpack(
&(|offset| (offset.amount, Addr::unchecked(offset.pair.clone()))),
&(|offset| (offset.amount.u128(), Addr::unchecked(offset.pair.clone()))),
None,
None,
);
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn query_buy_from_pair_quotes(
min,
max,
} = query_options.unpack(
&(|offset| (offset.amount, Addr::unchecked(offset.pair.clone()))),
&(|offset| (offset.amount.u128(), Addr::unchecked(offset.pair.clone()))),
None,
None,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> NftsForTokensInfinity<'a> {
if let Some(pair_quote) = pair_quote_option {
self.cursor = Some(PairQuoteOffset {
pair: pair_quote.address.to_string(),
amount: pair_quote.quote.amount.u128(),
amount: pair_quote.quote.amount,
});

let pair = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> TokensForNftsInfinity<'a> {
if let Some(pair_quote) = pair_quote_option {
self.cursor = Some(PairQuoteOffset {
pair: pair_quote.address.to_string(),
amount: pair_quote.quote.amount.u128(),
amount: pair_quote.quote.amount,
});

let pair = self
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@cosmjs/proto-signing": "^0.31.0",
"@cosmjs/stargate": "^0.31.0",
"@stargazezone/launchpad": "^2.3.3",
"@stargazezone/infinity-types": "0.6.0",
"@stargazezone/infinity-types": "0.7.0",
"@stargazezone/core-types": "0.1.0",
"@types/jest": "^29.5.2",
"axios": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/infinity-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stargazezone/infinity-types",
"version": "0.7.0",
"version": "0.8.0",
"description": "The official types package for the Infinity Swap protocol",
"author": "Tasio Victoria",
"homepage": "https://stargaze.zone/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface QueryOptionsForPairQuoteOffset {
min?: QueryBoundForPairQuoteOffset | null;
}
export interface PairQuoteOffset {
amount: number;
amount: Uint128;
pair: string;
}
export type Addr = string;
Expand Down
Loading