Skip to content

Commit

Permalink
πŸ› [ENG-1897] only generate affiliate fee msg send if amount > 0 (#68)
Browse files Browse the repository at this point in the history
* only generate affiliate fee msg send if amount > 0

* πŸ› add forked cosmpy version into scripts folder

---------

Co-authored-by: Jeremy Liu <[email protected]>
  • Loading branch information
dhfang and NotJeremyLiu authored Sep 22, 2023
1 parent 7db25b9 commit 169bd95
Show file tree
Hide file tree
Showing 859 changed files with 30,562 additions and 19 deletions.
40 changes: 21 additions & 19 deletions contracts/entry-point/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,27 @@ pub fn execute_user_swap(
let affiliate_fee_amount =
verify_and_calculate_affiliate_fee_amount(&deps, &min_coin, affiliate)?;

// Add the affiliate fee amount to the total affiliate fee amount
total_affiliate_fee_amount =
total_affiliate_fee_amount.checked_add(affiliate_fee_amount)?;

// Create the affiliate fee bank send message
let affiliate_fee_msg = BankMsg::Send {
to_address: affiliate.address.clone(),
amount: vec![Coin {
denom: min_coin.denom.clone(),
amount: affiliate_fee_amount,
}],
};

// Add the affiliate fee message and attributes to the response
affiliate_response = affiliate_response
.add_message(affiliate_fee_msg)
.add_attribute("action", "dispatch_affiliate_fee_bank_send")
.add_attribute("address", &affiliate.address)
.add_attribute("amount", affiliate_fee_amount);
if affiliate_fee_amount > Uint128::zero() {
// Add the affiliate fee amount to the total affiliate fee amount
total_affiliate_fee_amount =
total_affiliate_fee_amount.checked_add(affiliate_fee_amount)?;

// Create the affiliate fee bank send message
let affiliate_fee_msg = BankMsg::Send {
to_address: affiliate.address.clone(),
amount: vec![Coin {
denom: min_coin.denom.clone(),
amount: affiliate_fee_amount,
}],
};

// Add the affiliate fee message and attributes to the response
affiliate_response = affiliate_response
.add_message(affiliate_fee_msg)
.add_attribute("action", "dispatch_affiliate_fee_bank_send")
.add_attribute("address", &affiliate.address)
.add_attribute("amount", affiliate_fee_amount);
}
}

// Create the user swap message
Expand Down
103 changes: 103 additions & 0 deletions contracts/entry-point/tests/test_user_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,51 @@ struct Params {
expected_error: None,
};
"User Swap Exact Coin In With Multiple Affiliates")]
#[test_case(
Params {
caller: "entry_point".to_string(),
user_swap: Swap::SwapExactCoinIn (
SwapExactCoinIn{
swap_venue_name: "swap_venue_name".to_string(),
operations: vec![
SwapOperation {
pool: "pool".to_string(),
denom_in: "untrn".to_string(),
denom_out: "osmo".to_string(),
}
],
}
),
remaining_coin: Coin::new(1_000_000, "untrn"),
min_coin: Coin::new(1_000_000, "osmo"),
affiliates: vec![Affiliate {
address: "affiliate".to_string(),
basis_points_fee: Uint128::new(0),
}],
expected_messages: vec![
SubMsg {
id: 0,
msg: WasmMsg::Execute {
contract_addr: "swap_venue_adapter".to_string(),
msg: to_binary(&SwapExecuteMsg::Swap {
operations: vec![
SwapOperation {
pool: "pool".to_string(),
denom_in: "untrn".to_string(),
denom_out: "osmo".to_string(),
}
],
}).unwrap(),
funds: vec![Coin::new(1_000_000, "untrn")],
}
.into(),
gas_limit: None,
reply_on: Never,
},
],
expected_error: None,
};
"User Swap Exact Coin In With Zero Fee Affiliate")]
#[test_case(
Params {
caller: "entry_point".to_string(),
Expand Down Expand Up @@ -432,6 +477,64 @@ struct Params {
expected_error: None,
};
"User Swap Exact Coin Out With Multiple Affiliates")]
#[test_case(
Params {
caller: "entry_point".to_string(),
user_swap: Swap::SwapExactCoinOut (
SwapExactCoinOut{
swap_venue_name: "swap_venue_name".to_string(),
operations: vec![
SwapOperation {
pool: "pool".to_string(),
denom_in: "untrn".to_string(),
denom_out: "osmo".to_string(),
}
],
refund_address: Some("refund_address".to_string()),
}
),
remaining_coin: Coin::new(1_000_000, "untrn"),
min_coin: Coin::new(500_000, "osmo"),
affiliates: vec![
Affiliate {
address: "affiliate".to_string(),
basis_points_fee: Uint128::new(0),
},
],
expected_messages: vec![
SubMsg {
id: 0,
msg: BankMsg::Send {
to_address: "refund_address".to_string(),
amount: vec![Coin::new(500_000, "untrn")],
}
.into(),
gas_limit: None,
reply_on: Never,
},
SubMsg {
id: 0,
msg: WasmMsg::Execute {
contract_addr: "swap_venue_adapter".to_string(),
msg: to_binary(&SwapExecuteMsg::Swap {
operations: vec![
SwapOperation {
pool: "pool".to_string(),
denom_in: "untrn".to_string(),
denom_out: "osmo".to_string(),
}
],
}).unwrap(),
funds: vec![Coin::new(500_000, "untrn")],
}
.into(),
gas_limit: None,
reply_on: Never,
},
],
expected_error: None,
};
"User Swap Exact Coin Out With Zero Fee Affiliate")]
#[test_case(
Params {
caller: "entry_point".to_string(),
Expand Down
20 changes: 20 additions & 0 deletions scripts/cosmpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2018-2021 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""Cosmpy source code."""
Binary file added scripts/cosmpy/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
20 changes: 20 additions & 0 deletions scripts/cosmpy/aerial/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2018-2021 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""Cosmpy aerial module."""
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 169bd95

Please sign in to comment.