Skip to content

Commit

Permalink
Merge pull request #8 from oraichain/feat/zapper
Browse files Browse the repository at this point in the history
Feat/zapper
  • Loading branch information
tubackkhoa authored Sep 18, 2024
2 parents db79ad8 + af34857 commit 684c47c
Show file tree
Hide file tree
Showing 98 changed files with 4,239 additions and 636 deletions.
574 changes: 409 additions & 165 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,20 @@ cw-storage-plus = { version = "1.0.1" }
derive_more = "0.99.17"
decimal-core = { path = "./packages/decimal-core" }
decimal = { path = "./packages/decimal" }
cosmwasm-testing-util = { git = "https://github.com/oraichain/cosmwasm-testing-util.git", rev = "143348c" }
cosmwasm-testing-util = { git = "https://github.com/oraichain/cosmwasm-testing-util.git", rev = "8363328" }
oraiswap-v3-common = { path = "./packages/oraiswap-v3-common" }
incentives-fund-manager = { path = "./contracts/incentives-fund-manager" }
oraiswap = { git = "https://github.com/oraichain/oraiswap.git", rev = "45c1930" }
oraiswap-v3 = { path = "./contracts/oraiswap-v3" }


oraiswap-oracle = { git = "https://github.com/oraichain/oraiswap.git", rev = "45c1930" }
oraiswap-pair = { git = "https://github.com/oraichain/oraiswap.git", rev = "45c1930" }
oraiswap-factory = { git = "https://github.com/oraichain/oraiswap.git", rev = "45c1930" }
oraiswap-mixed-router = { git = "https://github.com/oraichain/oraiswap.git", rev = "45c1930" }

[patch."https://github.com/oraichain/oraiswap-v3"]
oraiswap-v3-common = { path = "./packages/oraiswap-v3-common" }

[profile.release]
opt-level = 3
Expand Down
2 changes: 1 addition & 1 deletion contracts/oraiswap-v3/src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::write_api;
use oraiswap_v3::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use oraiswap_v3_common::oraiswap_v3_msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};

fn main() {
write_api! {
Expand Down
9 changes: 6 additions & 3 deletions contracts/oraiswap-v3/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;

use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use crate::entrypoints::*;
use crate::state::CONFIG;
use crate::{entrypoints::*, Config};
use oraiswap_v3_common::error::ContractError;
use oraiswap_v3_common::{
error::ContractError,
oraiswap_v3_msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
storage::Config,
};

use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cw2::set_contract_version;
Expand Down
18 changes: 10 additions & 8 deletions contracts/oraiswap-v3/src/entrypoints/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ use cw20::Expiration;
use cw_storage_plus::Bound;
use decimal::{CheckedOps, Decimal};

use crate::{
check_tick, compute_swap_step,
interface::{Approval, CalculateSwapResult, SwapHop},
sqrt_price::{get_max_tick, get_min_tick, SqrtPrice},
state::{self},
token_amount::TokenAmount,
PoolKey, Position, Tick, UpdatePoolTick, MAX_SQRT_PRICE, MIN_SQRT_PRICE,
};
use oraiswap_v3_common::{
asset::{Asset, AssetInfo},
error::ContractError,
interface::{Approval, CalculateSwapResult, SwapHop},
math::{
check_tick, compute_swap_step,
sqrt_price::{get_max_tick, get_min_tick, SqrtPrice},
token_amount::TokenAmount,
MAX_SQRT_PRICE, MIN_SQRT_PRICE,
},
storage::{PoolKey, Position, Tick, UpdatePoolTick},
};

use crate::state;

pub trait TimeStampExt {
fn millis(&self) -> u64;
}
Expand Down
17 changes: 9 additions & 8 deletions contracts/oraiswap-v3/src/entrypoints/execute.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::fee_growth::FeeGrowth;
use crate::incentive::IncentiveRecord;
use crate::interface::{CalculateSwapResult, Cw721ReceiveMsg, SwapHop};
use crate::liquidity::Liquidity;
use crate::percentage::Percentage;
use crate::sqrt_price::SqrtPrice;
use crate::state::{self, CONFIG, POOLS};
use crate::token_amount::TokenAmount;
use crate::{calculate_min_amount_out, check_tick, FeeTier, Pool, PoolKey, Position};
use oraiswap_v3_common::asset::{Asset, AssetInfo};
use oraiswap_v3_common::error::ContractError;
use oraiswap_v3_common::incentives_fund_manager;
use oraiswap_v3_common::interface::{CalculateSwapResult, Cw721ReceiveMsg, SwapHop};
use oraiswap_v3_common::math::fee_growth::FeeGrowth;
use oraiswap_v3_common::math::liquidity::Liquidity;
use oraiswap_v3_common::math::percentage::Percentage;
use oraiswap_v3_common::math::sqrt_price::SqrtPrice;
use oraiswap_v3_common::math::token_amount::TokenAmount;
use oraiswap_v3_common::math::{calculate_min_amount_out, check_tick};
use oraiswap_v3_common::storage::incentive::IncentiveRecord;
use oraiswap_v3_common::storage::{FeeTier, Pool, PoolKey, Position};

use super::{
check_can_send, create_tick, remove_tick_and_flip_bitmap, swap_internal, swap_route_internal,
Expand Down
28 changes: 16 additions & 12 deletions contracts/oraiswap-v3/src/entrypoints/query.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use cosmwasm_std::{Addr, Binary, Deps, Env, Order, StdResult, Uint64};
use cw_storage_plus::Bound;

use crate::{
get_max_chunk, get_min_chunk,
use oraiswap_v3_common::{
asset::Asset,
error::ContractError,
interface::{
AllNftInfoResponse, Approval, ApprovedForAllResponse, NftInfoResponse, NumTokensResponse,
OwnerOfResponse, PoolWithPoolKey, QuoteResult, SwapHop, TokensResponse,
OwnerOfResponse, PoolWithPoolKey, PositionTick, QuoteResult, SwapHop, TokensResponse,
},
math::{
percentage::Percentage,
sqrt_price::{get_max_tick, get_min_tick, SqrtPrice},
token_amount::TokenAmount,
},
storage::{
get_max_chunk, get_min_chunk, tick_to_position, FeeTier, LiquidityTick, Pool, PoolKey,
Position, Tick, CHUNK_SIZE, LIQUIDITY_TICK_LIMIT, MAX_TICKMAP_QUERY_SIZE,
POSITION_TICK_LIMIT,
},
percentage::Percentage,
sqrt_price::{get_max_tick, get_min_tick, SqrtPrice},
state::{self, CONFIG, MAX_LIMIT, POSITIONS},
tick_to_position,
token_amount::TokenAmount,
FeeTier, LiquidityTick, Pool, PoolKey, Position, PositionTick, Tick, CHUNK_SIZE,
LIQUIDITY_TICK_LIMIT, MAX_TICKMAP_QUERY_SIZE, POSITION_TICK_LIMIT,
};
use oraiswap_v3_common::{asset::Asset, error::ContractError};

use crate::state::{self, CONFIG, MAX_LIMIT, POSITIONS};

use super::{calculate_swap, route, tickmap_slice, TimeStampExt};

Expand Down
9 changes: 0 additions & 9 deletions contracts/oraiswap-v3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
pub mod contract;
pub mod entrypoints;
pub mod interface;
pub mod msg;
pub mod state;

pub mod logic;
pub mod math;
pub mod storage;

pub use math::*;
pub use storage::*;

#[cfg(test)]
mod tests;
27 changes: 16 additions & 11 deletions contracts/oraiswap-v3/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use cosmwasm_std::{Addr, Order, StdResult, Storage};
use cw20::Expiration;
use cw_storage_plus::{Bound, Item, Map};

use crate::{
flip_bit_at_position, get_bit_at_position, get_search_limit,
incentive::IncentiveRecord,
use oraiswap_v3_common::{
error::ContractError,
interface::PoolWithPoolKey,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
tick_to_position, Config, Pool, PoolKey, Position, Tick, CHUNK_SIZE, MAX_TICK,
math::{
sqrt_price::{calculate_sqrt_price, SqrtPrice},
MAX_TICK,
},
storage::{
flip_bit_at_position, get_bit_at_position, get_search_limit, incentive::IncentiveRecord,
tick_to_position, Config, Pool, PoolKey, Position, Tick, CHUNK_SIZE,
},
};
use oraiswap_v3_common::error::ContractError;

pub const CONFIG: Item<Config> = Item::new("config");

Expand Down Expand Up @@ -474,9 +477,11 @@ mod tests {

use super::*;
use crate::entrypoints::tickmap_slice;
use crate::math::percentage::Percentage;
use crate::sqrt_price::SqrtPrice;
use crate::{state, FeeTier, MAX_TICK, TICK_SEARCH_RANGE};
use crate::state;
use oraiswap_v3_common::math::percentage::Percentage;
use oraiswap_v3_common::math::sqrt_price::SqrtPrice;
use oraiswap_v3_common::math::TICK_SEARCH_RANGE;
use oraiswap_v3_common::storage::FeeTier;

use cosmwasm_std::testing::mock_dependencies;
use cosmwasm_std::Addr;
Expand All @@ -487,7 +492,7 @@ mod tests {
let mut deps = mock_dependencies();
let token_0: String = Addr::unchecked("token_0").to_string().to_string();
let token_1: String = Addr::unchecked("token_1").to_string().to_string();
let fee_tier: FeeTier = FeeTier {
let fee_tier = FeeTier {
fee: Percentage::new(1),
tick_spacing: 1,
};
Expand Down
7 changes: 3 additions & 4 deletions contracts/oraiswap-v3/src/tests/add_fee_tier.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::math::types::percentage::Percentage;
use crate::msg::QueryMsg;
use crate::tests::helper::{macros::*, MockApp, FEE_DENOM};
use crate::FeeTier;
use cosmwasm_std::coins;
use decimal::Decimal;
use oraiswap_v3_common::error::ContractError;
use oraiswap_v3_common::{
error::ContractError, math::percentage::Percentage, oraiswap_v3_msg::QueryMsg, storage::FeeTier,
};

#[test]
fn test_add_multiple_fee_tiers() {
Expand Down
4 changes: 2 additions & 2 deletions contracts/oraiswap-v3/src/tests/admin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::msg::{ExecuteMsg, QueryMsg};
use crate::percentage::Percentage;
use crate::tests::helper::MockApp;
use crate::tests::helper::{macros::*, FEE_DENOM};
use cosmwasm_std::{coins, Addr};
use decimal::Decimal;
use oraiswap_v3_common::error::ContractError;
use oraiswap_v3_common::math::percentage::Percentage;
use oraiswap_v3_common::oraiswap_v3_msg::{ExecuteMsg, QueryMsg};

#[test]
fn test_change_admin() {
Expand Down
7 changes: 4 additions & 3 deletions contracts/oraiswap-v3/src/tests/change_fee_receiver.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::math::types::percentage::Percentage;
use crate::math::types::sqrt_price::calculate_sqrt_price;
use crate::tests::helper::macros::*;
use crate::tests::helper::MockApp;
use crate::tests::helper::FEE_DENOM;
use crate::{FeeTier, PoolKey};
use cosmwasm_std::coins;
use decimal::Decimal;
use oraiswap_v3_common::error::ContractError;
use oraiswap_v3_common::math::percentage::Percentage;
use oraiswap_v3_common::math::sqrt_price::calculate_sqrt_price;
use oraiswap_v3_common::storage::FeeTier;
use oraiswap_v3_common::storage::PoolKey;

#[test]
fn test_change_fee_reciever() {
Expand Down
6 changes: 3 additions & 3 deletions contracts/oraiswap-v3/src/tests/change_protocol_fee.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::msg::{ExecuteMsg, QueryMsg};
use crate::percentage::Percentage;
use crate::tests::helper::MockApp;
use crate::tests::helper::{macros::*, FEE_DENOM};
use cosmwasm_std::{coins, Addr};
use oraiswap_v3_common::error::ContractError;
use decimal::Decimal;
use oraiswap_v3_common::error::ContractError;
use oraiswap_v3_common::math::percentage::Percentage;
use oraiswap_v3_common::oraiswap_v3_msg::{ExecuteMsg, QueryMsg};

#[test]
fn test_change_protocol_fee() {
Expand Down
20 changes: 11 additions & 9 deletions contracts/oraiswap-v3/src/tests/claim.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use cosmwasm_std::coins;
use decimal::{Decimal, Factories};
use oraiswap_v3_common::asset::AssetInfo;

use crate::{
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::{self, calculate_sqrt_price, SqrtPrice},
tests::helper::{macros::*, MockApp, FEE_DENOM},
token_amount::TokenAmount,
FeeTier, PoolKey,
use oraiswap_v3_common::{
asset::AssetInfo,
math::{
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::{self, calculate_sqrt_price, SqrtPrice},
token_amount::TokenAmount,
},
storage::{FeeTier, PoolKey},
};

use crate::tests::helper::{macros::*, MockApp, FEE_DENOM};

#[test]
fn test_claim() {
let (mut app, accounts) = MockApp::new(&[
Expand Down
18 changes: 10 additions & 8 deletions contracts/oraiswap-v3/src/tests/create_pool.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use cosmwasm_std::{coins, Addr};
use decimal::{Decimal, Factories};
use oraiswap_v3_common::error::ContractError;

use crate::{
msg::{ExecuteMsg, QueryMsg},
percentage::Percentage,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
tests::helper::{macros::*, MockApp, FEE_DENOM},
FeeTier, Pool,
use oraiswap_v3_common::{
error::ContractError,
math::{
percentage::Percentage,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
},
oraiswap_v3_msg::{ExecuteMsg, QueryMsg},
storage::{FeeTier, Pool},
};

use crate::tests::helper::{macros::*, MockApp, FEE_DENOM};

#[test]
fn test_create_pool() {
let protocol_fee = Percentage::from_scale(6, 3);
Expand Down
14 changes: 5 additions & 9 deletions contracts/oraiswap-v3/src/tests/cross.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use cosmwasm_std::coins;
use decimal::{Decimal, Factories};

use crate::{
fee_growth::FeeGrowth,
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::SqrtPrice,
tests::helper::{macros::*, MockApp, FEE_DENOM},
token_amount::TokenAmount,
FeeTier, PoolKey, MIN_SQRT_PRICE,
use oraiswap_v3_common::{
math::{fee_growth::FeeGrowth, liquidity::Liquidity, percentage::Percentage},
storage::{FeeTier, PoolKey},
};

use crate::tests::helper::{macros::*, MockApp, FEE_DENOM};

#[test]
fn test_cross() {
let initial_mint = 10u128.pow(10);
Expand Down
23 changes: 13 additions & 10 deletions contracts/oraiswap-v3/src/tests/cross_both_size.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use cosmwasm_std::coins;
use decimal::{Decimal, Factories};
use oraiswap_v3_common::error::ContractError;

use crate::{
fee_growth::FeeGrowth,
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
tests::helper::{macros::*, MockApp, FEE_DENOM},
token_amount::TokenAmount,
FeeTier, PoolKey, MAX_SQRT_PRICE, MIN_SQRT_PRICE,
use oraiswap_v3_common::{
error::ContractError,
math::{
fee_growth::FeeGrowth,
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
token_amount::TokenAmount,
MAX_SQRT_PRICE, MIN_SQRT_PRICE,
},
storage::{FeeTier, PoolKey},
};

use crate::tests::helper::{macros::*, MockApp, FEE_DENOM};

#[test]
fn test_cross_both_side() {
let (mut app, accounts) = MockApp::new(&[
Expand Down
20 changes: 11 additions & 9 deletions contracts/oraiswap-v3/src/tests/get_liquidity_ticks.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use cosmwasm_std::{coins, Addr};
use decimal::{Decimal, Factories};

use crate::{
liquidity::Liquidity,
msg,
percentage::Percentage,
position_to_tick,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
tests::helper::{macros::*, MockApp, FEE_DENOM},
FeeTier, LiquidityTick, PoolKey, CHUNK_SIZE, LIQUIDITY_TICK_LIMIT,
use oraiswap_v3_common::{
math::{
liquidity::Liquidity,
percentage::Percentage,
sqrt_price::{calculate_sqrt_price, SqrtPrice},
},
storage::{
position_to_tick, FeeTier, LiquidityTick, PoolKey, CHUNK_SIZE, LIQUIDITY_TICK_LIMIT,
},
};

use crate::tests::helper::{macros::*, MockApp, FEE_DENOM};

#[test]
fn test_get_liquidity_ticks() {
let (mut app, accounts) = MockApp::new(&[("alice", &coins(100_000_000_000, FEE_DENOM))]);
Expand Down
Loading

0 comments on commit 684c47c

Please sign in to comment.