Skip to content

Commit

Permalink
fix: dont return lp_token twice in create_astroport_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo-sturdy committed Aug 21, 2024
1 parent 5e7a816 commit 0f2e270
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cw-it"
version = "0.4.0-rc.5"
version = "0.4.0-rc.6"
authors = ["Pacman <[email protected]>", "Sturdy <[email protected]>"]
edition = "2021"
license = "MPL-2.0"
Expand Down
11 changes: 5 additions & 6 deletions src/astroport/robot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ where
signer: &SigningAccount,
initial_liquidity: Option<&[u128; 2]>,
decimals: Option<&[u8; 2]>,
) -> (String, String, String) {
) -> (String, String) {
let factory_addr = &self.astroport_contracts().factory.address;

// If decimals are provided, add native coins to registry
Expand Down Expand Up @@ -259,8 +259,7 @@ where
.unwrap();

// Get pair and lp_token addresses from event
let (pair_addr, lp_token_addr, token_denom) =
parse_astroport_create_pair_events(&res.events);
let (pair_addr, lp_token) = parse_astroport_create_pair_events(&res.events);

if let Some(initial_liquidity) = initial_liquidity {
let assets = asset_infos
Expand All @@ -274,7 +273,7 @@ where
self.provide_liquidity(&pair_addr, assets, signer);
}

(pair_addr, lp_token_addr, token_denom)
(pair_addr, lp_token)
}

fn query_simulate_swap(
Expand Down Expand Up @@ -582,7 +581,7 @@ mod tests {

let asset_infos = get_asset_infos(asset_info_choice, &contracts.astro_token.address);

let (pair_addr, _lp_token_addr, lp_token_denom) = robot.create_astroport_pair(
let (pair_addr, lp_token_denom) = robot.create_astroport_pair(
pair_type.clone(),
&asset_infos,
init_params,
Expand Down Expand Up @@ -634,7 +633,7 @@ mod tests {

let asset_infos = get_asset_infos(asset_info_choice, &contracts.astro_token.address);
let initial_liquidity = Some(&[420420u128, 696969u128]);
let (pair_addr, _lp_token_addr, _lp_token_denom) = robot.create_astroport_pair(
let (pair_addr, _lp_token_denom) = robot.create_astroport_pair(
pair_type,
&asset_infos,
init_params,
Expand Down
53 changes: 27 additions & 26 deletions src/astroport/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub fn create_astroport_pair<'a, R>(
signer: &SigningAccount,
initial_liquidity: Option<[Uint128; 2]>,
denom_creation_fee: &[Coin],
) -> (String, String, String)
) -> (String, String)
where
R: Runner<'a>,
{
Expand All @@ -428,7 +428,7 @@ where
.unwrap();

// Get pair and lp_token addresses from event
let (pair_addr, lp_token_addr, token_denom) = parse_astroport_create_pair_events(&res.events);
let (pair_addr, lp_token) = parse_astroport_create_pair_events(&res.events);

if let Some(initial_liquidity) = initial_liquidity {
let assets = asset_infos
Expand All @@ -439,13 +439,13 @@ where
provide_liquidity(app, &pair_addr, assets, signer);
}

(pair_addr, lp_token_addr, token_denom)
(pair_addr, lp_token)
}

pub fn parse_astroport_create_pair_events(events: &[Event]) -> (String, String, String) {
pub fn parse_astroport_create_pair_events(events: &[Event]) -> (String, String) {
let mut pair_addr = String::from("");
let mut lp_token = String::from("");
let mut token_denom = String::from("");
let mut lp_token_addr = String::from("");
let mut lp_token_denom = String::from("");

for event in events {
if event.ty == "wasm" {
Expand All @@ -455,15 +455,22 @@ pub fn parse_astroport_create_pair_events(events: &[Event]) -> (String, String,
pair_addr.clone_from(&attr.value);
}
if attr.key == "liquidity_token_addr" {
lp_token.clone_from(&attr.value);
lp_token_addr.clone_from(&attr.value);
}
if attr.key == "lp_denom" {
token_denom.clone_from(&attr.value);
lp_token_denom.clone_from(&attr.value);
}
}
}
}
(pair_addr, lp_token, token_denom)

let lp_token = if lp_token_denom.is_empty() {
lp_token_addr
} else {
lp_token_denom
};

(pair_addr, lp_token)
}

pub fn get_lp_token_balance<'a, R>(
Expand Down Expand Up @@ -946,20 +953,16 @@ mod tests {
contract_addr: Addr::unchecked(&contracts.astro_token.address),
},
];
let (uluna_astro_pair_addr, uluna_astro_lp_token, uluna_astro_denom) =
create_astroport_pair(
&app,
&contracts.factory.address,
astroport_v5::factory::PairType::Xyk {},
asset_infos,
None,
admin,
None,
&[],
);

println!("uluna_astro_pair_addr: {:?}", uluna_astro_pair_addr);
println!("uluna_astro_lp_token: {:?}", uluna_astro_lp_token);
let (uluna_astro_pair_addr, uluna_astro_lp_token) = create_astroport_pair(
&app,
&contracts.factory.address,
astroport_v5::factory::PairType::Xyk {},
asset_infos,
None,
admin,
None,
&[],
);

// Increase allowance of astro token
let increase_allowance_msg = Cw20ExecuteMsg::IncreaseAllowance {
Expand Down Expand Up @@ -1018,12 +1021,10 @@ mod tests {
admin,
);

println!("uluna_astro_denom {:?}", uluna_astro_denom);

let lp_token_balance = bank
.query_balance(&QueryBalanceRequest {
address: admin.address(),
denom: uluna_astro_denom,
denom: uluna_astro_lp_token,
})
.unwrap();

Expand Down

0 comments on commit 0f2e270

Please sign in to comment.