Skip to content

Commit

Permalink
fix: don't mess with amounts, if the allocation is 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
PFC-developer committed May 10, 2024
1 parent 30a57f4 commit 61c7b37
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [
resolver = "2"

[workspace.package]
version = "1.5.1"
version = "1.5.2"
authors = ["PFC <[email protected]>"]
edition = "2021"
rust-version = "1.73.0"
Expand Down
16 changes: 8 additions & 8 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
3d74986751e5ffaee368e2fef48600a2cec7475cf34180bf4416f0bf38f7511b pfc_astroport_generator.wasm
eec5c2393076139c0f3544bfb05421eabdea7ee4a99f907b898d4a732165eb31 pfc_dust_collector_kujira_contract-aarch64.wasm
142656cc27ed5a235b23e7cfe093438970fb2c02f38a3d95376a294652c4ad10 pfc_dust_collector_kujira_contract.wasm
8e2ff6fdb9ac1ed6be069ab1bba90c14630fe78844df5e0d025844cd346a5c29 pfc_fee_splitter-aarch64.wasm
2f89f99e9bd1159ab01bd65933aefb83d48138f260c2b2331f2b6ef27c384b4f pfc_fee_splitter.wasm
fc729d3d8482634b7c902aaf17c5e4ac6dd9e52e3e0039cd9cc544b17713ec7a pfc_treasurechest_contract-aarch64.wasm
efe5d5052f55c0d2eb9329be47851b3d5f49e794edd95dbaea1c50cf55739af8 pfc_treasurechest_contract.wasm
99bc2da7b2de958c7c26953f56dde617c2ed9cccfd178b7093b7dd505da8edfc pfc_vault_contract-aarch64.wasm
8dc45994f074d716f37666b92dad93f1489f77858747c4f68760a27853c29512 pfc_vault_contract.wasm
b99cc69eb23f87c121135c601b5e8355457eaa6305f16601a97e5311287d618d pfc_dust_collector_kujira_contract-aarch64.wasm
b5ee20e9b8a13f3a150b110a17b38c941c868424c28d48d7e849630e4d5214a8 pfc_dust_collector_kujira_contract.wasm
8f791f694d954c809402bbdf4b4659251320f4388bca6ca79c96994b11b71a9c pfc_fee_splitter-aarch64.wasm
1355da8090d3e9eaf108ed120ee97ecddcb1a2188e765b33163ae0006d407334 pfc_fee_splitter.wasm
89df83ccec07e96921362dfaf51b578a3f2b7eed4c7eb421706a1f52386c7775 pfc_treasurechest_contract-aarch64.wasm
b81306493909604e41907049aff88e652008b9c438e41155336dfc87a7138e7e pfc_treasurechest_contract.wasm
78db200e8084a454bf917f3606de49b67cd41bab1c16ba6df5ee403040a0d009 pfc_vault_contract-aarch64.wasm
1b640b8ba0124dc3d234a6f044a799692f9daf5fe820c2a5cc1b044e7f44e7f4 pfc_vault_contract.wasm
Binary file modified artifacts/pfc_dust_collector_kujira_contract.wasm
Binary file not shown.
Binary file modified artifacts/pfc_fee_splitter.wasm
Binary file not shown.
Binary file modified artifacts/pfc_treasurechest_contract.wasm
Binary file not shown.
Binary file modified artifacts/pfc_vault_contract.wasm
Binary file not shown.
28 changes: 17 additions & 11 deletions contracts/pfc-fee-splitter/src/handler/exec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, iter::FromIterator, ops::Mul};
use std::{collections::HashMap, iter::FromIterator, ops::Mul, str::FromStr};

use cosmwasm_std::{
to_json_binary, Addr, AllBalanceResponse, BankMsg, BankQuery, Coin, CosmosMsg, Decimal,
Expand Down Expand Up @@ -349,17 +349,23 @@ pub(crate) fn determine_allocation(
let funds_sent_alloc: HashMap<String, Uint128> = funds_sent
.iter()
.map(|(denom, amount)| {
let dec_amt: Decimal = Decimal::from_atomics(amount.u128(), 0).unwrap();
let portion = dec_amt.mul(fraction);

// ignore dust
if portion.is_zero() || portion < Decimal::from_ratio(1u32, 10_000u32) {
(denom.clone(), Uint128::zero())
// if we are just passing ALL $ through... then don't mess with maths
if allocation_amt == total_allocation {
(denom.clone(), *amount)
} else {
let places = portion.decimal_places();
let portion_u128 =
portion.atomics().checked_div(Uint128::from(10u32).pow(places)).unwrap();
(denom.clone(), portion_u128)
let dec_amt: Decimal = Decimal::from_str(&amount.to_string()).unwrap();
let portion = dec_amt.mul(fraction);

// ignore dust
if portion.is_zero() || portion < Decimal::from_ratio(1u32, 10_000u32) {
(denom.clone(), Uint128::zero())
} else {
let places = portion.decimal_places();
let portion_u128 =
portion.atomics().checked_div(Uint128::from(10u32).pow(places)).unwrap();

(denom.clone(), portion_u128)
}
}
})
.collect();
Expand Down
33 changes: 33 additions & 0 deletions notes/notes_archway.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM=boneLunaAdmin
FROMADDR=archway1lu92zj8q6cmrptu09rp3343x9969r9qrg72hzj
GAS_ADJ=1.4
GAS=$(archwayd q rewards estimate-fees 1 --node 'https://rpc.mainnet.archway.io:443' --output json | jq -r '.gas_unit_price | (.amount + .denom)')

archwayd tx wasm store ./artifacts/pfc_fee_splitter.wasm --from ${FROM} --yes --gas-prices $GAS --gas-adjustment ${GAS_ADJ} --gas auto
tx=F860276EE40CD09C6CEC63F6292763BE03BA5F635456C0E69EC0F29665338119
export FEESPLIT=$(archwayd query --output json tx ${tx} |jq -e -r ' .logs[].events[] | select(.type=="store_code").attributes[] | select(.key=="code_id").value ' | tr -d '"')
echo $FEESPLIT
FEESPLIT=448



json=$(cat ./test_files/archway_instantiate_feesplit.json)
archwayd tx wasm instantiate $FEESPLIT "${json}" --admin $FROMADDR --label pfc-fee-split --from $FROM --gas-prices $GAS --gas-adjustment $GAS_ADJ --gas auto

tx_fee_i=684F1016F6F436DE2F65828F2E72210C3C5583A207FEA1E2CE8421150DE62FDA

export FEE_CONTRACT=$(archwayd query --output=json tx $tx_fee_i|jq -r '.logs[].events[]| select(.type=="instantiate").attributes[] |select(.key=="_contract_address").value '|tr -d '"')

echo $FEE_CONTRACT
FEE_CONTRACT=archway1pzjprqczpn0fvn5kvqzs74mggg4539rt2vpmp07ffp3pufp6cc3qqmhdg3


#
archwayd tx wasm migrate $FEE_CONTRACT $FEESPLIT '{}' --from $FROM --gas-prices $GAS --gas-adjustment $GAS_ADJ --gas auto


add_alloc=$(cat ./test_files/add_allocation_phoenix_vault.json)
migalood tx wasm exec migaloo1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqvk723g "${add_alloc}" --from testadmin --gas-prices 0.025ustars --gas-adjustment 1.7 --gas auto
migalood tx wasm exec migaloo1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqvk723g '{"reconcile":{}}' --from testadmin --gas-prices 0.025ustars --gas-adjustment 1.7 --gas auto --node https://narwhal-rpc.dalnim.finance:443 --chain-id narwhal-1

archwayd query wasm cs smart $FEE_CONTRACT '{"allocations":{}}'
4 changes: 2 additions & 2 deletions notes/notes_inj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# INJ
injectived tx wasm store ./artifacts/pfc_fee_splitter.wasm --from bone-luna --yes --gas-prices 700000000inj --gas-adjustment 1.7 --gas auto
# inj-888
# 539
# 539|9008
json=$(cat ./test_files/inj_instantiate_feesplit.json)
injectived tx wasm instantiate 539 "${json}" --admin inj1d3yya2s4cejxfe5et9djq38qgtvlsmn9nqjeu9 --label pfc-fee-split --from bone-luna --gas-prices 700000000inj --gas-adjustment 1.7 --gas auto

# inj1z7s6eqeql5r23gptjrfhvks3z79vwweuezk77g



injectived tx wasm migrate inj1z7s6eqeql5r23gptjrfhvks3z79vwweuezk77g 834 '{}' --from testadmin --gas-prices 0.025ustars --gas-adjustment 1.7 --gas auto
injectived tx wasm migrate inj1z7s6eqeql5r23gptjrfhvks3z79vwweuezk77g 9007 '{}' --from bone-luna --gas-prices 700000000inj --gas-adjustment 1.7 --gas auto
add_alloc=$(cat ./test_files/add_allocation_phoenix_vault.json)
injectived tx wasm exec inj1z7s6eqeql5r23gptjrfhvks3z79vwweuezk77g "${add_alloc}" --from testadmin --gas-prices 0.025ustars --gas-adjustment 1.7 --gas auto
injectived tx wasm exec inj1z7s6eqeql5r23gptjrfhvks3z79vwweuezk77g '{"reconcile":{}}' --from testadmin --gas-prices 0.025ustars --gas-adjustment 1.7 --gas auto
Expand Down
4 changes: 4 additions & 0 deletions notes/notes_osmosis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ fee_address="osmo1ctrfxgxdjqgd0usaepzdan2razpd3sge7jvckakh036yzm24ymgsnktjf8"


osmosisd query wasm cs smart $fee_address '{"allocations":{}}'

add_alloc=$(cat ./test_files/modify_allocation_osmo_vault.json)
osmosisd tx wasm exec $fee_address "${add_alloc}" --from boneLunaAdmin --gas-prices 0.025uosmo --gas-adjustment 1.7 --gas auto
osmosisd tx wasm exec $fee_address '{"reconcile":{}}' --from boneLunaAdmin --gas-prices 0.025uosmo --gas-adjustment 1.7 --gas auto
11 changes: 7 additions & 4 deletions packages/pfc-fee-split/src/fee_split_msg.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use cosmwasm_std::{
to_json_binary, Addr, Binary, Coin, CosmosMsg, DepsMut, StdError, StdResult, WasmMsg,
};
Expand All @@ -23,9 +25,9 @@ pub enum SendType {
receiver: Addr,
},
}
impl ToString for SendType {
fn to_string(&self) -> String {
match &self {
impl Display for SendType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match &self {
SendType::Wallet {
receiver,
} => format!("Wallet -> {}", receiver),
Expand All @@ -47,7 +49,8 @@ impl ToString for SendType {
} => {
format!("Steak:{} -> {} Transfer", steak, receiver)
},
}
};
write!(f, "{}", str)
}
}
impl SendType {
Expand Down
17 changes: 17 additions & 0 deletions test_files/archway_instantiate_feesplit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "pfc-fee-split",
"gov_contract": "archway1lu92zj8q6cmrptu09rp3343x9969r9qrg72hzj",
"allocation": [
{
"name": "testnet",
"allocation": 1,
"send_after": {"denom": "uarch","amount": "1000000"},
"send_type": { "Wallet": {
"receiver": "archway1lu92zj8q6cmrptu09rp3343x9969r9qrg72hzj"
}
}
}
]

}

2 changes: 1 addition & 1 deletion test_files/inj_instantiate_feesplit.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"allocation": 1,
"send_after": {"denom": "inj","amount": "100000000000000000"},
"send_type": { "Wallet": {
"receiver": "inj1k0sxlweut6nqarhjsd0m52ruepcjp3vvgk3ly5"
"receiver": "inj1k0sxlweut6nqarhjsd0m52ruepcjp3vvgk3ly5"
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions test_files/modify_allocation_osmo_vault.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"add_allocation_detail": {
"name": "gravedigger",
"allocation": 100,
"send_after": {
"denom": "uosmo",
"amount": "100000"
},
"send_type": {
"Wallet": {
"receiver": "osmo1zhlar4sdvar9dqqc29umwarznvap2rrpzqgg66"
}
}
}
}

0 comments on commit 61c7b37

Please sign in to comment.