Skip to content

Commit

Permalink
Fix exchange rate (#133)
Browse files Browse the repository at this point in the history
Co-authored-by: Albert Andrejev <[email protected]>
  • Loading branch information
mattac21 and albertandrejev authored Aug 13, 2024
1 parent a9baa9a commit eea354b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions contracts/adapters/swap/drop/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
let exchange_rate = get_exchange_rate(deps)?;

to_json_binary(&Asset::Native(Coin::new(
(exchange_rate * asset_in.amount()).into(),
(asset_in.amount().div_floor(exchange_rate)).into(), //(asset_in.amount().div_floor(exchange_rate)).into()
asset_out_denom,
)))
}
Expand All @@ -223,7 +223,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
let exchange_rate = get_exchange_rate(deps)?;

to_json_binary(&Asset::Native(Coin::new(
(asset_out.amount().div_floor(exchange_rate)).into(),
(exchange_rate * asset_out.amount()).into(), //(exchange_rate * asset_out.amount()).into()
asset_in_denom,
)))
}
Expand All @@ -245,7 +245,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {

to_json_binary(&SimulateSwapExactAssetInResponse {
asset_out: Asset::Native(Coin::new(
(exchange_rate * asset_in.amount()).into(),
(asset_in.amount().div_floor(exchange_rate)).into(),
asset_out_denom,
)),
spot_price,
Expand All @@ -269,7 +269,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {

to_json_binary(&SimulateSwapExactAssetOutResponse {
asset_in: Asset::Native(Coin::new(
(asset_out.amount().div_floor(exchange_rate)).into(),
(exchange_rate * asset_out.amount()).into(),
asset_in_denom,
)),
spot_price,
Expand All @@ -282,7 +282,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
let exchange_rate = get_exchange_rate(deps)?;

to_json_binary(&Asset::Native(Coin::new(
(exchange_rate * asset_in.amount()).into(),
(asset_in.amount().div_floor(exchange_rate)).into(),
asset_out_denom,
)))
}
Expand All @@ -304,7 +304,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {

to_json_binary(&SimulateSwapExactAssetInResponse {
asset_out: Asset::Native(Coin::new(
(exchange_rate * asset_in.amount()).into(),
(asset_in.amount().div_floor(exchange_rate)).into(),
asset_out_denom,
)),
spot_price,
Expand Down
9 changes: 5 additions & 4 deletions contracts/adapters/swap/drop/tests/test_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Params {
asset_in: Asset::Native(Coin::new(100, "ibc/uatom")),
},
response: to_json_binary(&Asset::Native(Coin::new(
50,
200,
"factory/uatom",
))).unwrap(),
exchange_rate: Decimal::from_atomics(cosmwasm_std::Uint128::new(5), 1).unwrap(),
Expand Down Expand Up @@ -81,7 +81,7 @@ struct Params {
asset_out: Asset::Native(Coin::new(100, "factory/uatom")),
},
response: to_json_binary(&Asset::Native(Coin::new(
200,
50,
"ibc/uatom",
))).unwrap(),
exchange_rate: Decimal::from_atomics(cosmwasm_std::Uint128::new(5), 1).unwrap(),
Expand Down Expand Up @@ -126,7 +126,7 @@ struct Params {
},
response: to_json_binary(&skip::swap::SimulateSwapExactAssetInResponse{
asset_out: Asset::Native(Coin::new(
50,
200,
"factory/uatom",
)),
spot_price: Some(Decimal::from_atomics(cosmwasm_std::Uint128::new(5), 1).unwrap())
Expand Down Expand Up @@ -186,7 +186,7 @@ struct Params {
},
response: to_json_binary(&skip::swap::SimulateSwapExactAssetOutResponse{
asset_in: Asset::Native(Coin::new(
200,
50,
"ibc/uatom",
)),
spot_price: Some(Decimal::from_atomics(cosmwasm_std::Uint128::new(5), 1).unwrap())
Expand Down Expand Up @@ -261,6 +261,7 @@ fn test_queries(params: Params) -> ContractResult<()> {
assert_eq!(err, params.expected_error.unwrap());
}
}
println!("{:?}", exchange_rate);

Ok(())
}

0 comments on commit eea354b

Please sign in to comment.