Skip to content

Commit

Permalink
fix: omit astroport whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloGie authored and Oracle Public Cloud User committed Jun 18, 2024
1 parent bbcee81 commit 1349819
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 139 deletions.
12 changes: 11 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ allow = ["Apache-2.0", "MIT", "BSD-3-Clause", "MPL-2.0", "ISC"]
exceptions = [
{ allow = ["Unicode-DFS-2016"], name = "unicode-ident" },
{ allow = ["OpenSSL"], name = "ring" },
{ allow = ["GPL-3.0"], name = "astroport-incentives" }
{ allow = ["GPL-3.0"], name = "astroport-incentives" },
{ allow = ["GPL-3.0"], name = "astroport-factory" },
{ allow = ["GPL-3.0"], name = "astroport-generator" },
{ allow = ["GPL-3.0"], name = "astroport-maker" },
{ allow = ["GPL-3.0"], name = "astroport-pair" },
{ allow = ["GPL-3.0"], name = "astroport-pair-concentrated" },
{ allow = ["GPL-3.0"], name = "astroport-pair-stable" },
{ allow = ["GPL-3.0"], name = "astroport-pcl-common" },
{ allow = ["GPL-3.0"], name = "astroport-router" },
{ allow = ["GPL-3.0"], name = "astroport-vesting" }
]

[[licenses.clarify]]
Expand All @@ -49,3 +58,4 @@ name = "ring"
# OpenSSL - Obviously
expression = "ISC AND MIT AND OpenSSL"
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]

79 changes: 48 additions & 31 deletions src/astroport/robot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use astroport::asset::{Asset, AssetInfo};
use astroport::factory::{ConfigResponse, ExecuteMsg as AstroportFactoryExecuteMsg, PairType};
use astroport_v5::asset::{Asset, AssetInfo};
use astroport_v5::factory::{ConfigResponse, ExecuteMsg as AstroportFactoryExecuteMsg, PairType};
use cosmwasm_std::{Binary, Coin, Decimal, Uint128};
use cw20::{BalanceResponse, Cw20ExecuteMsg, Cw20QueryMsg};
use std::collections::HashMap;
Expand Down Expand Up @@ -113,10 +113,10 @@ where
/// Queries the LP token balance given the pair's address and the address of the account.
fn query_lp_token_balance(&self, pair_addr: &str, address: &str) -> Uint128 {
// Get lp token address
let msg = astroport::pair::QueryMsg::Pair {};
let msg = astroport_v5::pair::QueryMsg::Pair {};
let lp_token_addr = self
.wasm()
.query::<_, astroport::asset::PairInfo>(pair_addr, &msg)
.query::<_, astroport_v5::asset::PairInfo>(pair_addr, &msg)
.unwrap()
.liquidity_token;

Expand All @@ -125,24 +125,24 @@ where
}

/// Queries the PairInfo of the given pair.
fn query_pair_info(&self, pair_addr: &str) -> astroport::asset::PairInfo {
let msg = astroport::pair::QueryMsg::Pair {};
fn query_pair_info(&self, pair_addr: &str) -> astroport_v5::asset::PairInfo {
let msg = astroport_v5::pair::QueryMsg::Pair {};
self.wasm()
.query::<_, astroport::asset::PairInfo>(pair_addr, &msg)
.query::<_, astroport_v5::asset::PairInfo>(pair_addr, &msg)
.unwrap()
}

/// Queries the PoolInfo of the given pair (contains the reserves and the total supply of LP tokens).
fn query_pool(&self, pair_addr: &str) -> astroport::pair::PoolResponse {
let msg = astroport::pair::QueryMsg::Pool {};
fn query_pool(&self, pair_addr: &str) -> astroport_v5::pair::PoolResponse {
let msg = astroport_v5::pair::QueryMsg::Pool {};
self.wasm()
.query::<_, astroport::pair::PoolResponse>(pair_addr, &msg)
.query::<_, astroport_v5::pair::PoolResponse>(pair_addr, &msg)
.unwrap()
}

/// Queries the Config of the Astroport Factory contract.
fn query_factory_config(&self, factory_addr: &str) -> ConfigResponse {
let msg = astroport::factory::QueryMsg::Config {};
let msg = astroport_v5::factory::QueryMsg::Config {};
self.wasm()
.query::<_, ConfigResponse>(factory_addr, &msg)
.unwrap()
Expand All @@ -152,7 +152,7 @@ where
fn query_native_coin_registry(&self, denom: &str) -> RunnerResult<u8> {
let contracts = self.astroport_contracts();
let registry_addr = contracts.coin_registry.address.as_str();
let msg = astroport::native_coin_registry::QueryMsg::NativeToken {
let msg = astroport_v5::native_coin_registry::QueryMsg::NativeToken {
denom: denom.to_string(),
};
self.wasm().query::<_, u8>(registry_addr, &msg)
Expand All @@ -165,7 +165,7 @@ where
native_coins: Vec<(String, u8)>,
signer: &SigningAccount,
) -> &Self {
let msg = astroport::native_coin_registry::ExecuteMsg::Add { native_coins };
let msg = astroport_v5::native_coin_registry::ExecuteMsg::Add { native_coins };
self.wasm()
.execute(registry_addr, &msg, &[], signer)
.unwrap();
Expand Down Expand Up @@ -205,11 +205,12 @@ where
funds.sort_by(|a, b| a.denom.cmp(&b.denom));

// Provide liquidity
let msg = astroport::pair::ExecuteMsg::ProvideLiquidity {
let msg = astroport_v5::pair::ExecuteMsg::ProvideLiquidity {
assets,
slippage_tolerance: None,
receiver: None,
auto_stake: Some(false),
min_lp_to_receive: None,
};
self.wasm()
.execute(pair_addr, &msg, &funds, signer)
Expand All @@ -228,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 @@ -258,7 +259,8 @@ where
.unwrap();

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

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

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

fn query_simulate_swap(
&self,
pair_addr: &str,
offer_asset: Asset,
ask_asset_info: Option<AssetInfo>,
) -> astroport::pair::SimulationResponse {
let msg = astroport::pair::QueryMsg::Simulation {
) -> astroport_v5::pair::SimulationResponse {
let msg = astroport_v5::pair::QueryMsg::Simulation {
offer_asset,
ask_asset_info,
};
self.wasm()
.query::<_, astroport::pair::SimulationResponse>(pair_addr, &msg)
.query::<_, astroport_v5::pair::SimulationResponse>(pair_addr, &msg)
.unwrap()
}

Expand Down Expand Up @@ -321,7 +323,7 @@ where
}
};

let msg = astroport::pair::ExecuteMsg::Swap {
let msg = astroport_v5::pair::ExecuteMsg::Swap {
offer_asset,
ask_asset_info,
belief_price,
Expand All @@ -340,7 +342,7 @@ where
precision: u8,
signer: &SigningAccount,
) -> &Self {
let msg = astroport::native_coin_registry::ExecuteMsg::Add {
let msg = astroport_v5::native_coin_registry::ExecuteMsg::Add {
native_coins: vec![(denom.into(), precision)],
};
self.wasm()
Expand Down Expand Up @@ -424,7 +426,7 @@ where
mod tests {
use std::str::FromStr;

use astroport::{
use astroport_v5::{
asset::{Asset, AssetInfo},
factory::PairType,
pair::StablePoolParams,
Expand All @@ -434,13 +436,13 @@ mod tests {
use test_tube::{Account, SigningAccount};

use super::AstroportTestRobot;
use crate::traits::CwItRunner;
use crate::{
astroport::utils::{cw20_info, native_info, AstroportContracts},
robot::TestRobot,
ContractMap, OwnedTestRunner, TestRunner,
};

use crate::traits::CwItRunner;
use cosmwasm_std::Addr;

struct TestingRobot<'a> {
runner: &'a TestRunner<'a>,
Expand Down Expand Up @@ -503,7 +505,14 @@ mod tests {

/// Helper to get a pair of native token asset infos.
fn native_native_pair() -> [AssetInfo; 2] {
[native_info("uatom"), native_info("uion")]
[
AssetInfo::NativeToken {
denom: "uatom".to_string(),
},
AssetInfo::NativeToken {
denom: "uion".to_string(),
},
]
}

/// Helper enum for choice of asset infos.
Expand All @@ -516,7 +525,14 @@ mod tests {
fn get_asset_infos(choice: AssetChoice, astro_token: &str) -> [AssetInfo; 2] {
match choice {
AssetChoice::NativeNative => native_native_pair(),
AssetChoice::NativeCw20 => [native_info("uatom"), cw20_info(astro_token)],
AssetChoice::NativeCw20 => [
AssetInfo::NativeToken {
denom: "uatom".to_string(),
},
AssetInfo::Token {
contract_addr: Addr::unchecked(astro_token),
},
],
}
}

Expand Down Expand Up @@ -567,7 +583,7 @@ mod tests {

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

let (pair_addr, lp_token_addr) = robot.create_astroport_pair(
let (pair_addr, lp_token_addr, lp_token_denom) = robot.create_astroport_pair(
pair_type.clone(),
&asset_infos,
init_params,
Expand All @@ -580,11 +596,12 @@ mod tests {
let pair_info = robot.query_pair_info(&pair_addr);
assert_eq!(pair_info.pair_type, pair_type);
assert_eq!(pair_info.asset_infos, asset_infos.to_vec());
assert_eq!(pair_info.liquidity_token.to_string(), lp_token_addr);
assert_eq!(pair_info.liquidity_token.to_string(), lp_token_denom);

if let Some(initial_liq) = initial_liquidity {
// Check lp token balance
let lp_token_balance = robot.query_cw20_balance(&lp_token_addr, &admin.address());
let lp_token_balance =
robot.query_native_token_balance(&admin.address(), lp_token_denom);
assert_ne!(lp_token_balance, Uint128::zero());

// Check pair reserves
Expand Down Expand Up @@ -618,7 +635,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) = robot.create_astroport_pair(
let (pair_addr, _lp_token_addr, lp_token_denom) = robot.create_astroport_pair(
pair_type,
&asset_infos,
init_params,
Expand Down
Loading

0 comments on commit 1349819

Please sign in to comment.