Skip to content

Commit

Permalink
Merge branch 'feat/audit-fixes' into feat/deploy-script
Browse files Browse the repository at this point in the history
  • Loading branch information
faust403 authored Jul 3, 2024
2 parents 839b611 + cf412a8 commit c66870f
Show file tree
Hide file tree
Showing 14 changed files with 7,537 additions and 180 deletions.
18 changes: 10 additions & 8 deletions contracts/staker/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,24 @@ fn execute_stake(
reason: "tx_state is not idle".to_string()
}
);
let amount = NON_STAKED_BALANCE.load(deps.storage)?;
let non_staked_balance = NON_STAKED_BALANCE.load(deps.storage)?;
ensure!(
amount > Uint128::zero(),
non_staked_balance > Uint128::zero(),
ContractError::InvalidFunds {
reason: "no funds to stake".to_string()
}
);
let sum = items
let amount_to_stake = items
.iter()
.fold(Uint128::zero(), |acc, (_, amount)| acc + *amount);
ensure!(
sum >= config.min_staking_amount,
amount_to_stake >= config.min_staking_amount,
ContractError::InvalidFunds {
reason: "amount is less than min_staking_amount".to_string()
}
);
ensure!(
amount >= sum,
non_staked_balance >= amount_to_stake,
ContractError::InvalidFunds {
reason: "not enough funds to stake".to_string()
}
Expand All @@ -242,7 +242,7 @@ fn execute_stake(
attr("action", "stake"),
attr("connection_id", &config.connection_id),
attr("ica_id", ICA_ID),
attr("amount", amount.to_string()),
attr("amount_to_stake", amount_to_stake.to_string()),
];
let fee = query_ibc_fee(deps.as_ref(), LOCAL_DENOM)?;
let ica = ICA.get_address(deps.storage)?;
Expand Down Expand Up @@ -275,7 +275,7 @@ fn execute_stake(
to_address: puppeteer_ica,
amount: vec![cosmos_sdk_proto::cosmos::base::v1beta1::Coin {
denom: config.remote_denom.to_string(),
amount: sum.to_string(),
amount: amount_to_stake.to_string(),
}],
};
let any_msgs: Vec<neutron_sdk::bindings::types::ProtobufAny> = vec![
Expand All @@ -293,7 +293,9 @@ fn execute_stake(
let submsg: SubMsg<NeutronMsg> = msg_with_sudo_callback(
deps,
cosmos_msg,
Transaction::Stake { amount },
Transaction::Stake {
amount: non_staked_balance,
},
ReplyMsg::SudoPayload.to_reply_id(),
Some(info.sender.to_string()),
)?;
Expand Down
31 changes: 28 additions & 3 deletions scripts/generate_activity_script/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MNEMONIC = fire trip collect truth embody hand refuse rural drop engine cross bonus depart photo duty ticket elite width mystery boat wrestle elite rose merry

# Node RPC endpoint to sign & broadcast transactions
# We need it to do bond, unbond and withdraw executions
# We need it to do bond, unbond, ibc send and withdraw executions
NEUTRON_NODE_ADDRESS = https://rpc-falcron.pion-1.ntrn.tech:443

# Core contract is a Drop protocol instance
Expand All @@ -19,9 +19,34 @@ FACTORY_DENOM = factory/neutron1ath9aw6fll2pl5vkqvysa76sel7lq3u8lm6tpnuhnde46rra
# If current balance lower then MAX_BOND, then MAX_BOND is current BASE_DENOM balance
MAX_BOND = 100000
# Maximum FACTORY_DENOM amount that we can unbond.
# If current balance lower then MAX_UNBOND, then MAX_unBOND is current FACTORY_DENOM balance
# If current balance lower then MAX_UNBOND, then MAX_UNBOND is current FACTORY_DENOM balance
MAX_UNBOND = 1000
# Maximum BASE_DENOM amount that we can process as lsm shares.
# If current balance lower then MAX_LSM_PROCESS, then MAX_LSM_PROCESS is current BASE_DENOM balance
MAX_LSM_PROCESS = 100

# Probabitions that each of these actions will be applied
# Probabition should be in interval from 0 to 1
BOND_PROB = 0.5
UNBOND_PROB = 0.5
WITHDRAW_PROB = 0.5
WITHDRAW_PROB = 0.5
PROCESS_LSM_PROB = 1

# Prefix in remote chain account address
# For example in case of cosmoshub it's cosmos, in case of osmosis it's osmo etc...
TARGET_CHAIN_PREFIX = cosmos
# Node RPC endpoint to sign & broadcast transactions
# We need it to do delegate, tokenizeShare and ibc send executions
TARGET_NODE_ADDRESS = http://delta-vorlon.neutron.org:26657
# Base denom on remote chain
TARGET_DENOM = stake

# IBC channel to send from neutron to remote chain
IBC_CHANNEL_TO = channel-1003
# IBC channel to send from remote chain to neutron
IBC_CHANNEL_FROM = channel-11

# Gas price on Neutron chain (by default it's 0.05)
NEUTRON_GASPRICE = 0.05
# Gas price on target chain (by default it's 0.05, but you can easily change it here)
TARGET_GASPRICE = 0.05
9 changes: 9 additions & 0 deletions scripts/generate_activity_script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ To manage script config, open _.env_ file
- BASE_DENOM = is an ibc denom used in given protocol instance for bond requests
- FACTORY_DENOM = is an factory denom used in given protocol instance for unbond requests
- NEUTRON_NODE_ADDRESS = endpoint of node o interact with. Should be taken from [here](https://github.com/cosmos/testnets/tree/master/interchain-security/pion-1#endpoints)
- TARGET_NODE_ADDRESS = Node RPC endpoint to sign & broadcast transactions. We need it to do delegate, tokenizeShare and ibc send executions
- BOND_PROB = probabition 'bond' method will be called on core contract
- UNBOND_PROB = probabition 'unbond' method will be called on core contract
- WITHDRAW_PROB = probabition 'send_nft' method will be called on withdrawal_voucher contract
- PROCESS_LSM_PROB = probabition 'processLSMShares' will be executed
- MAX_BOND = Maximum BASE_DENOM amount that we can bond. If current balance lower then MAX_BOND, then MAX_BOND is current BASE_DENOM balance
- MAX_UNBOND = Maximum FACTORY_DENOM amount that we can unbond. If current balance lower then MAX_UNBOND, then MAX_unBOND is current FACTORY_DENOM balance
- MAX_LSM_PROCESS = Maximum BASE_DENOM amount that we can process as lsm shares. If current balance lower then MAX_LSM_PROCESS, then MAX_LSM_PROCESS is current BASE_DENOM balance
- TARGET_CHAIN_PREFIX = Prefix in remote chain account address. For example in case of cosmoshub it's cosmos, in case of osmosis it's osmo etc...
- TARGET_DENOM = Base denom on remote chain
- IBC_CHANNEL_TO = IBC channel to send from neutron to remote chain
- IBC_CHANNEL_FROM = IBC channel to send from remote chain to neutron
- NEUTRON_GASPRICE = Gas price on Neutron chain
- TARGET_GASPRICE = Gas price on target chain
36 changes: 36 additions & 0 deletions scripts/generate_activity_script/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/generate_activity_script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"eslint-plugin-prettier": "^5.0.1",
"prettier": "^3.0.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
}
Expand Down
Loading

0 comments on commit c66870f

Please sign in to comment.