Skip to content
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
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 contracts/swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = [ "Markus Waas <markus@injectivelabs.org>" ]
edition = "2021"
name = "swap-contract"
version = "1.1.0"
version = "1.1.1"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
Expand Down
6 changes: 3 additions & 3 deletions contracts/swap/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ pub fn migrate(deps: DepsMut<InjectiveQueryWrapper>, _env: Env, _msg: MigrateMsg
let contract_version = get_contract_version(deps.storage)?;

match contract_version.contract.as_ref() {
"crates.io:swap-contract" => match contract_version.version.as_ref() {
"swap-contract" => match contract_version.version.as_ref() {
"1.0.1" => {
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;
set_contract_version(deps.storage, CONTRACT_NAME.to_string(), CONTRACT_VERSION)?;
}
Comment on lines +124 to 125

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Compile error: passing String to set_contract_version.

set_contract_version expects &str params; CONTRACT_NAME.to_string() passes String by value and won’t compile. Use the &'static str directly.

Apply:

-                set_contract_version(deps.storage, CONTRACT_NAME.to_string(), CONTRACT_VERSION)?;
+                set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set_contract_version(deps.storage, CONTRACT_NAME.to_string(), CONTRACT_VERSION)?;
}
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
}
🤖 Prompt for AI Agents
In contracts/swap/src/contract.rs around lines 124-125, the call to
set_contract_version passes CONTRACT_NAME.to_string() (a String) but
set_contract_version expects &str; remove the .to_string() and pass the string
constants directly (e.g., CONTRACT_NAME and CONTRACT_VERSION as &str / &'static
str) so the function receives &str parameters.

_ => return Err(ContractError::MigrationError {}),
},
Expand All @@ -131,6 +131,6 @@ pub fn migrate(deps: DepsMut<InjectiveQueryWrapper>, _env: Env, _msg: MigrateMsg
Ok(Response::new()
.add_attribute("previous_contract_name", &contract_version.contract)
.add_attribute("previous_contract_version", &contract_version.version)
.add_attribute("new_contract_name", format!("crates.io:{CONTRACT_NAME}"))
.add_attribute("new_contract_name", CONTRACT_NAME.to_string())
.add_attribute("new_contract_version", CONTRACT_VERSION))
}
2 changes: 1 addition & 1 deletion contracts/swap/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn estimate_execution_buy_from_source(

let funds_for_margin = match is_simulation {
false => funds_in_contract, // in execution mode funds_in_contract already contain user funds so we don't want to count them double
true => funds_in_contract + available_swap_quote_funds,
true => funds_in_contract + input_quote_quantity,
};

if required_funds > funds_for_margin {
Expand Down
2 changes: 1 addition & 1 deletion contracts/swap/src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn start_swap_flow(
denom: source_denom.to_owned(),
};

FPDecimal::from(coin_provided.amount) - estimation.result_quantity
FPDecimal::from(coin_provided.amount) - required_input
} else {
FPDecimal::ZERO
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying
let from_balance_after = query_bank_balance(&bank, USDT, swapper.address().as_str());
let to_balance_after = query_bank_balance(&bank, NINJA, swapper.address().as_str());

// from 100000 USDT -> 96201.062128 USDT = 3798.937872 USDT
// from 100000 USDT -> 96201.062127 USDT = 3798.937872 USDT
let expected_from_balance_before = human_to_dec("100000", Decimals::Six);
let expected_from_balance_after = human_to_dec("96201.062128", Decimals::Six);
let expected_from_balance_after = human_to_dec("96201.062127", Decimals::Six);

// from 0 NINJA to 501000 NINJA
let expected_to_balance_before = human_to_dec("0", Decimals::Six);
Expand Down
9 changes: 4 additions & 5 deletions contracts/swap/src/testing/migration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ use injective_testing::test_tube::utils::store_code;
type V101InstantiateMsg = InstantiateMsg;

#[test]
#[cfg_attr(not(feature = "integration"), ignore)]
fn test_migration() {
let app = InjectiveTestApp::new();
let wasm = Wasm::new(&app);

let wasm_byte_code = std::fs::read("../../contracts/swap/src/testing/test_artifacts/swap-contract-v101.wasm").unwrap();
let wasm_byte_code = std::fs::read("../../contracts/swap/src/testing/test_artifacts/swap_contract-v101.wasm").unwrap();
let validator = app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap();

let owner = must_init_account_with_funds_and_setting_denoms(
Expand Down Expand Up @@ -66,14 +65,14 @@ fn test_migration() {
assert_eq!(contract_info.creator, owner.address());
assert_eq!(contract_info.label, "swap-contract");

let swap_v110_code_id = store_code(&wasm, &owner, "swap_contract".to_string());
let swap_v111_code_id = store_code(&wasm, &owner, "swap_contract".to_string());

let _res: ExecuteResponse<MsgMigrateContractResponse> = app
.execute(
MsgMigrateContract {
sender: owner.address(),
contract: swap_v101_address.clone(),
code_id: swap_v110_code_id,
code_id: swap_v111_code_id,
msg: serde_json_wasm::to_vec(&MigrateMsg {}).unwrap(),
},
"/cosmwasm.wasm.v1.MsgMigrateContract",
Expand All @@ -93,7 +92,7 @@ fn test_migration() {
let contract_info = res.contract_info.unwrap();

assert_eq!(res.address, swap_v101_address);
assert_eq!(contract_info.code_id, swap_v110_code_id);
assert_eq!(contract_info.code_id, swap_v111_code_id);
assert_eq!(contract_info.creator, owner.address());
assert_eq!(contract_info.label, "swap-contract");

Expand Down
Binary file not shown.
Loading