Skip to content

Commit

Permalink
Mint DEX positions in base and quote quantities
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Dec 10, 2024
1 parent a2220e7 commit c2877af
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
42 changes: 42 additions & 0 deletions integration_tests/test_runner/src/dex_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,48 @@ pub async fn dex_mint_ranged_pos(
assert_eq!(range_pos.liq - start_pos.liq, liq);
}

#[allow(clippy::too_many_arguments)]
pub async fn dex_mint_ranged_in_amount(
web3: &Web3,
dex: EthAddress,
evm_privkey: PrivateKey,
base: EthAddress,
quote: EthAddress,
pool_idx: Uint256,
bid_tick: Int256,
ask_tick: Int256,
qty: Uint256, // The amount of a token to mint a position with
in_base: bool, // Whether to mint in the base token or the quote token
) {
assert!(base.lt(&quote), "base must be lexically smaller than quote");

let code = if in_base {
Uint256::from(11u8) // Mint in base amount code
} else {
Uint256::from(12u8) // Mint in quote amount code
};
let mint_ranged_pos_args = UserCmdArgs {
callpath: WARM_PATH, // Warm Path index
cmd: vec![
code.into(),
base.into(), // base
quote.into(), // quote
pool_idx.into(), // poolIdx
bid_tick.into(), // bid (lower) tick
ask_tick.into(), // ask (upper) tick
qty.into(), // liq (in liquidity units, which must be a multiple of 1024)
(*MIN_PRICE).into(), // limitLower
(*MAX_PRICE).into(), // limitHigher
Uint256::from(0u8).into(), // reserveFlags
EthAddress::default().into(), // lpConduit
],
};
info!("Minting position in single token: {mint_ranged_pos_args:?}");
dex_user_cmd(web3, dex, evm_privkey, mint_ranged_pos_args, None, None)
.await
.expect("Failed to mint position in pool");
}

#[allow(clippy::too_many_arguments)]
pub async fn dex_burn_ranged_pos(
web3: &Web3,
Expand Down
31 changes: 23 additions & 8 deletions integration_tests/test_runner/src/tests/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use crate::dex_utils::{
croc_policy_ops_resolution, croc_policy_treasury_resolution, croc_query_curve_tick,
croc_query_dex, croc_query_pool_params, croc_query_pool_template, croc_query_range_position,
dex_authority_transfer, dex_burn_ambient_pos, dex_burn_knockout_pos, dex_burn_ranged_pos,
dex_direct_protocol_cmd, dex_mint_ambient_pos, dex_mint_knockout_pos, dex_mint_ranged_pos,
dex_query_authority, dex_query_safe_mode, dex_swap, dex_user_cmd, OpsResolutionArgs,
ProtocolCmdArgs, SwapArgs, UserCmdArgs, BOOT_PATH, COLD_PATH, MAX_PRICE, MIN_PRICE, WARM_PATH,
dex_direct_protocol_cmd, dex_mint_ambient_pos, dex_mint_knockout_pos,
dex_mint_ranged_in_amount, dex_mint_ranged_pos, dex_query_authority, dex_query_safe_mode,
dex_swap, dex_user_cmd, OpsResolutionArgs, ProtocolCmdArgs, SwapArgs, UserCmdArgs, BOOT_PATH,
COLD_PATH, MAX_PRICE, MIN_PRICE, WARM_PATH,
};
use crate::type_urls::{
COLLECT_TREASURY_PROPOSAL_TYPE_URL, HOT_PATH_OPEN_PROPOSAL_TYPE_URL, OPS_PROPOSAL_TYPE_URL,
Expand Down Expand Up @@ -162,7 +163,7 @@ pub async fn populate_pool_basic(
if range_pos.liq > 0u8.into() {
info!("Range position already exists: {:?}", range_pos);
} else {
let liq: Uint256 = one_atom() * 1024000000u32.into();
let qty: Uint256 = one_eth() * 1024u32.into();
let bb = web3
.get_erc20_balance(base, evm_user.eth_address)
.await
Expand All @@ -180,18 +181,32 @@ pub async fn populate_pool_basic(
.await
.unwrap();
info!("Before minting ranged position: base balance: {}, quote balance: {}, base approved: {}, quote approved: {}", bb, qb, ba, qa);
dex_mint_ranged_pos(
// Mint using the base token
dex_mint_ranged_in_amount(
web3,
dex_contracts.dex,
dex_contracts.query,
evm_user.eth_privkey,
evm_user,
base,
quote,
*POOL_IDX,
bid_tick,
ask_tick,
liq,
qty,
true,
)
.await;
// Mint using the quote token
dex_mint_ranged_in_amount(
web3,
dex_contracts.dex,
evm_user.eth_privkey,
base,
quote,
*POOL_IDX,
bid_tick,
ask_tick,
qty,
false,
)
.await;
}
Expand Down

0 comments on commit c2877af

Please sign in to comment.