Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.
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
3 changes: 2 additions & 1 deletion crates/shielder-cli/src/shielder_ops/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ pub async fn withdraw(
protocol_fee_bps
};

let mut amount = U256::from(amount) + quoted_fee.fee_details.total_cost_fee_token;
let protocol_fee = compute_protocol_fee_from_net(U256::from(amount), protocol_fee_bps);

let amount = U256::from(amount) + quoted_fee.fee_details.total_cost_fee_token + protocol_fee;
amount += protocol_fee;

let shielded_amount = app_state.accounts[&token.address()].shielded_amount;

Expand Down
34 changes: 34 additions & 0 deletions scripts/SetProtocolFees.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.14;

import { Script, console2 } from "forge-std/Script.sol";

import { Shielder } from "../contracts/Shielder.sol";

/* solhint-disable no-console */
contract SetProtocolFeesShielderScript is Script {
function run() external {
uint256 privateKey = vm.envUint("PRIVATE_KEY");

uint256 protocolDepositFeeBps = vm.envUint("PROTOCOL_DEPOSIT_FEE_BPS");
uint256 protocolWithdrawFeeBps = vm.envUint(
"PROTOCOL_WITHDRAW_FEE_BPS"
);

Shielder shielder = Shielder(
vm.envAddress("SHIELDER_CONTRACT_ADDRESS")
);

vm.startBroadcast(privateKey);

shielder.setProtocolDepositFeeBps(protocolDepositFeeBps);
shielder.setProtocolWithdrawFeeBps(protocolWithdrawFeeBps);

console2.log("Protocol fees set to:");
console2.log("Desosit fee: ", protocolDepositFeeBps, " bps");
console2.log("Withdraw fee: ", protocolWithdrawFeeBps, " bps");

vm.stopBroadcast();
}
}
38 changes: 25 additions & 13 deletions tooling-e2e-tests/full_scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,32 @@ else
fi
source "${SCRIPT_DIR}/utils.sh"

# ${1} - actor name
# ${2} - actor private key
scenario() {
configure_cli alice ${ALICE_PRIVATE_KEY}
configure_cli ${1} ${2}

log_progress "✅ CLI configured"
alice app-config
${1} app-config

alice new-account $(mtzero 200)
alice deposit $(mtzero 100)
${1} new-account $(mtzero 200)
${1} deposit $(mtzero 100)
log_progress "✅ Native account created and deposited to it"

alice new-account-erc20 $(mtzero 200) "${ERC20_CONTRACT_ADDRESS_1}"
alice deposit-erc20 $(mtzero 100) "${ERC20_CONTRACT_ADDRESS_1}"
${1} new-account-erc20 $(mtzero 200) "${ERC20_CONTRACT_ADDRESS_1}"
${1} deposit-erc20 $(mtzero 100) "${ERC20_CONTRACT_ADDRESS_1}"
log_progress "✅ ERC20 account created and deposited to it"

alice display-account
alice history
${1} display-account
${1} history

withdrawal_amount=$(mtzero 50)

#####################################################################################
################################# Native withdrawal #################################
#####################################################################################
withdrawal_balance_before=$(cast balance -r "${NODE_RPC_URL}" "${WITHDRAWAL_PUBLIC_KEY}")
alice withdraw $withdrawal_amount "${WITHDRAWAL_PUBLIC_KEY}"
${1} withdraw $withdrawal_amount "${WITHDRAWAL_PUBLIC_KEY}"
withdrawal_balance_after=$(cast balance -r "${NODE_RPC_URL}" "${WITHDRAWAL_PUBLIC_KEY}")

withdrawn=$((withdrawal_balance_after - withdrawal_balance_before))
Expand All @@ -54,7 +56,7 @@ scenario() {
relayer_balance_before=$(erc20_balance "${ERC20_CONTRACT_ADDRESS_1}" "${FEE_DESTINATION}")

pocket_money=$(mtzero 1)
alice withdraw-erc20 $withdrawal_amount "${WITHDRAWAL_PUBLIC_KEY}" "${ERC20_CONTRACT_ADDRESS_1}" $pocket_money
${1} withdraw-erc20 $withdrawal_amount "${WITHDRAWAL_PUBLIC_KEY}" "${ERC20_CONTRACT_ADDRESS_1}" $pocket_money

withdrawal_balance_after=$(cast balance -r "${NODE_RPC_URL}" "${WITHDRAWAL_PUBLIC_KEY}")
withdrawal_erc20_balance_after=$(erc20_balance "${ERC20_CONTRACT_ADDRESS_1}" "${WITHDRAWAL_PUBLIC_KEY}")
Expand Down Expand Up @@ -84,15 +86,25 @@ scenario() {
log_progress "✅ ERC20 withdrawal fee successful"
fi

alice display-account
alice history
${1} display-account
${1} history
}

run() {
pushd $SCRIPT_DIR/.. &>> output.log

setup
scenario
scenario alice ${ALICE_PRIVATE_KEY}

log_progress "ℹ️ Scenario with non-zero protocol fees"
log_progress "ℹ️ Setting non-zero protocol fees..."
PRIVATE_KEY="${DEPLOYER_PRIVATE_KEY}" \
PROTOCOL_DEPOSIT_FEE_BPS=25 \
PROTOCOL_WITHDRAW_FEE_BPS=10 \
forge script SetProtocolFeesShielderScript --broadcast --rpc-url ${NODE_RPC_URL} --sender $(cast wallet address ${DEPLOYER_PRIVATE_KEY})
log_progress "✅ Non-zero protocol fees set!"

scenario bob ${BOB_PRIVATE_KEY}

popd &>> output.log
}
Expand Down
10 changes: 10 additions & 0 deletions tooling-e2e-tests/ts_sdk_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ run() {
setup_shielder_sdk
scenario

log_progress "ℹ️ Scenario with non-zero protocol fees"
log_progress "ℹ️ Setting non-zero protocol fees..."
PRIVATE_KEY="${DEPLOYER_PRIVATE_KEY}" \
PROTOCOL_DEPOSIT_FEE_BPS=25 \
PROTOCOL_WITHDRAW_FEE_BPS=10 \
forge script SetProtocolFeesShielderScript --broadcast --rpc-url ${NODE_RPC_URL} --sender $(cast wallet address ${DEPLOYER_PRIVATE_KEY})
log_progress "✅ Non-zero protocol fees set!"

scenario

popd &>> output.log
}

Expand Down
Loading