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

feat: rewrite dex_stargate and stargate_querier to use new helpers #NTRN-326 #59

Merged
merged 6 commits into from
Aug 13, 2024
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
637 changes: 525 additions & 112 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ neutron-sdk = { package = "neutron-sdk", git = "https://github.com/neutron-org/n
prost = "0.12.4"
prost-types = "0.12.4"
cosmos-sdk-proto = { version = "0.20.0", default-features = false }
cosmwasm-std = { version = "2.0.4", features = [
cosmwasm-std = { version = "2.1.0", features = [
"stargate",
"staking",
"cosmwasm_1_1",
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
"cosmwasm_2_0",
] }
cw2 = "2.0.0"
cw-storage-plus = "2.0.0"
schemars = "0.8.15"
serde = { version = "1.0.189", default-features = false }
cosmwasm-schema = { version = "2.0.4", default-features = false }
cosmwasm-schema = { version = "2.1.0", default-features = false }
serde-json-wasm = "1.0.0"
base64 = "0.21.7"
thiserror = "1.0.49"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ compile:

check_contracts:
@cargo install cosmwasm-check --version 2.0.4 --locked
@cosmwasm-check --available-capabilities iterator,staking,stargate,neutron,cosmwasm_1_1,cosmwasm_1_2 artifacts/*.wasm
@cosmwasm-check --available-capabilities iterator,staking,stargate,neutron,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0 artifacts/*.wasm

build: schema clippy test fmt compile check_contracts
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The following contracts are maintained here:

| Contract | Reference | Description |
|--------------------------------------------------|-------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Neutron Interchain Queries Example Contract | https://github.com/neutron-org/neutron-contracts/tree/main/contracts/neutron-interchain-queries | The contract shows how to properly work with [Interchain Queries Module](https://github.com/neutron-org/neutron/tree/master/x/interchainqueries) using [Interchain Queries SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_queries) via CosmWasm smart-contract. |
| Neutron Interchain Transactions Example Contract | https://github.com/neutron-org/neutron-contracts/tree/main/contracts/neutron_interchain_txs | The contract shows how to properly work with [Neutron Interchain Transactions Module](https://github.com/neutron-org/neutron/tree/master/x/interchaintxs) using [Interchain Transactions SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_txs) via CosmWasm smart-contract. |
| Neutron IBC Transfer Example Contract | https://github.com/neutron-org/neutron-contracts/tree/main/contracts/ibc_transfer | The contract shows how to properly work with [Neutron Sudo Package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron_sudo) to handle a callback from IBC transfer. |
| Neutron dex module + Stargate Example Contract | https://github.com/neutron-org/neutron-contracts/tree/main/contracts/dex_stargate | The contract shows a way to use [Neutron SDK's Stargate package](https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate) to interact with Neutron dex module via stargate |
| Reflect | https://github.com/neutron-org/neutron-contracts/tree/main/contracts/reflect | This contract is used for tests in the main neutron repository. |
| Neutron Interchain Queries Example Contract | <https://github.com/neutron-org/neutron-contracts/tree/main/contracts/neutron-interchain-queries> | The contract shows how to properly work with [Interchain Queries Module](https://github.com/neutron-org/neutron/tree/master/x/interchainqueries) using [Interchain Queries SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_queries) via CosmWasm smart-contract. |
| Neutron Interchain Transactions Example Contract | <https://github.com/neutron-org/neutron-contracts/tree/main/contracts/neutron_interchain_txs> | The contract shows how to properly work with [Neutron Interchain Transactions Module](https://github.com/neutron-org/neutron/tree/master/x/interchaintxs) using [Interchain Transactions SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_txs) via CosmWasm smart-contract. |
| Neutron IBC Transfer Example Contract | <https://github.com/neutron-org/neutron-contracts/tree/main/contracts/ibc_transfer> | The contract shows how to properly work with [Neutron Sudo Package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron_sudo) to handle a callback from IBC transfer. |
| Neutron dex module + Grpc Example Contract | <https://github.com/neutron-org/neutron-contracts/tree/main/contracts/dex_grpc> | The contract shows a way to use [Neutron SDK's Grpc package](https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/grpc) to interact with Neutron dex module via grpc |
| Reflect | <https://github.com/neutron-org/neutron-contracts/tree/main/contracts/reflect> | This contract is used for tests in the main neutron repository. |

## Development

Expand All @@ -24,7 +24,7 @@ The following contracts are maintained here:
- `wasm32-unknown-unknown` target
- Docker

1. Install `rustup` via https://rustup.rs/
1. Install `rustup` via <https://rustup.rs/>

2. Run the following:

Expand Down
2 changes: 1 addition & 1 deletion contracts/balance-tracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ cosmwasm-std = "1.5"
cw-storage-plus = "1.2"
cosmwasm-schema = "1.5"
thiserror = "1"
astroport = { git = "https://github.com/astroport-fi/astroport-core", version = "4" }
astroport = { git = "https://github.com/astroport-fi/astroport-core", version = "5" }
17 changes: 8 additions & 9 deletions contracts/balance-tracker/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,33 @@ use crate::state::{BALANCES, CONFIG, TOTAL_SUPPLY_HISTORY};
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::BalanceAt { address, timestamp } => {
to_json_binary(&balance_at(deps, env, address, timestamp)?)
}
QueryMsg::TotalSupplyAt { timestamp } => {
to_json_binary(&total_supply_at(deps, env, timestamp)?)
QueryMsg::BalanceAt { address, unit } => {
to_json_binary(&balance_at(deps, env, address, unit)?)
}
QueryMsg::TotalSupplyAt { unit } => to_json_binary(&total_supply_at(deps, env, unit)?),
QueryMsg::Config {} => {
let config = CONFIG.load(deps.storage)?;
to_json_binary(&ConfigResponse {
tracked_denom: config.d,
token_factory_module: config.m,
track_over_seconds: true,
})
}
}
}

fn balance_at(deps: Deps, env: Env, address: String, timestamp: Option<u64>) -> StdResult<Uint128> {
fn balance_at(deps: Deps, env: Env, address: String, unit: Option<u64>) -> StdResult<Uint128> {
let block_time = env.block.time.seconds();
match timestamp.unwrap_or(block_time) {
match unit.unwrap_or(block_time) {
timestamp if timestamp == block_time => BALANCES.may_load(deps.storage, &address),
timestamp => BALANCES.may_load_at_height(deps.storage, &address, timestamp),
}
.map(|balance| balance.unwrap_or_default())
}

fn total_supply_at(deps: Deps, env: Env, timestamp: Option<u64>) -> StdResult<Uint128> {
fn total_supply_at(deps: Deps, env: Env, unit: Option<u64>) -> StdResult<Uint128> {
let block_time = env.block.time.seconds();
match timestamp.unwrap_or(block_time) {
match unit.unwrap_or(block_time) {
timestamp if timestamp == block_time => TOTAL_SUPPLY_HISTORY.may_load(deps.storage),
timestamp => TOTAL_SUPPLY_HISTORY.may_load_at_height(deps.storage, timestamp),
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/before-send-hook/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object"
"type": "object",
"additionalProperties": false
}
3 changes: 2 additions & 1 deletion contracts/before-send-hook/schema/migrate_msg.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"type": "object"
"type": "object",
"additionalProperties": false
}
6 changes: 4 additions & 2 deletions contracts/before-send-hook/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"properties": {
"sudo_result_block_before": {
"type": "object"
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -21,7 +22,8 @@
],
"properties": {
"sudo_result_track_before": {
"type": "object"
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
3 changes: 2 additions & 1 deletion contracts/client_updater/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"title": {
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
3 changes: 2 additions & 1 deletion contracts/client_updater/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object"
"type": "object",
"additionalProperties": false
}
27 changes: 18 additions & 9 deletions contracts/dex/schema/dex_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"description": "Denom for the opposing side of the deposit",
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down Expand Up @@ -131,7 +132,8 @@
"description": "Denom for the opposing side of the deposit",
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down Expand Up @@ -212,7 +214,8 @@
"description": "Token being “bought”",
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -234,7 +237,8 @@
"description": "TrancheKey for the target limit order",
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -256,7 +260,8 @@
"description": "TrancheKey for the target limit order",
"type": "string"
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down Expand Up @@ -309,7 +314,8 @@
"$ref": "#/definitions/MultiHopRoute"
}
}
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand All @@ -325,7 +331,8 @@
"disable_swap": {
"type": "boolean"
}
}
},
"additionalProperties": false
},
"LimitOrderType": {
"oneOf": [
Expand Down Expand Up @@ -378,7 +385,8 @@
"type": "string"
}
}
}
},
"additionalProperties": false
},
"PrecDec": {
"type": "object",
Expand All @@ -389,7 +397,8 @@
"i": {
"type": "string"
}
}
},
"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); ```",
Expand Down
Loading
Loading