Skip to content

Commit 7706459

Browse files
committed
Codearena findings 8, No related function to set fee protocol
1 parent e87f251 commit 7706459

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc 5262a65e4d12e6199dd5ff8c169e89525fe14e27dd5752dd83f955e6a74f7ee2 # shrinks to fee_protocol_0 = 0, fee_protocol_1 = 0
8+
cc 9e08af991e5365be828ac5d271364b9ee4e5c9a7ab10a60830f95124a9f506fd # shrinks to fee_protocol_0 = 0, fee_protocol_1 = 11
9+
cc d8dba58868686611d78c8e8e10524b381a32134aa4f528793e995e826ff272b6 # shrinks to fee_protocol_0 = 4, fee_protocol_1 = 4

pkg/seawater/src/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ pub enum Error {
245245
// 44 (0x2c)
246246
#[error("Swap sending fee taking overflow")]
247247
TransferToSenderSub,
248+
249+
// 45 (0x2d)
250+
#[error("Bad protocol fee was attempted to be set")]
251+
BadFeeProtocol
248252
}
249253

250254
impl From<Error> for Vec<u8> {

pkg/seawater/src/lib.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,12 @@ impl Pools {
999999
Error::SeawaterAdminOnly
10001000
);
10011001

1002-
self.pools
1003-
.setter(pool)
1004-
.init(price, fee, tick_spacing, max_liquidity_per_tick)?;
1002+
self.pools.setter(pool).init(
1003+
price,
1004+
fee,
1005+
tick_spacing,
1006+
max_liquidity_per_tick,
1007+
)?;
10051008

10061009
// get the decimals for the asset so we can log it's decimals for the indexer
10071010

@@ -1080,6 +1083,36 @@ impl Pools {
10801083
Ok(())
10811084
}
10821085

1086+
pub fn set_fee_protocol(
1087+
&mut self,
1088+
pool: Address,
1089+
fee_protocol_0: u8,
1090+
fee_protocol_1: u8,
1091+
) -> Result<(), Revert> {
1092+
assert_eq_or!(
1093+
msg::sender(),
1094+
self.seawater_admin.get(),
1095+
Error::SeawaterAdminOnly
1096+
);
1097+
1098+
let is_fee_valid = (fee_protocol_0 == 0 || (fee_protocol_0 >= 4 && fee_protocol_0 <= 10))
1099+
&& (fee_protocol_1 == 0 || (fee_protocol_1 >= 4 && fee_protocol_1 <= 10));
1100+
1101+
assert_or!(is_fee_valid, Error::BadFeeProtocol);
1102+
1103+
let fee_protocol = fee_protocol_0 + (fee_protocol_1 << 4);
1104+
1105+
self.pools.setter(pool).set_fee_protocol(fee_protocol);
1106+
1107+
#[cfg(feature = "log-events")]
1108+
evm::log(events::NewFees {
1109+
pool,
1110+
feeProtocol: fee_protocol,
1111+
});
1112+
1113+
Ok(())
1114+
}
1115+
10831116
/// Update the NFT manager that has trusted access to moving tokens on
10841117
/// behalf of users.
10851118
#[allow(non_snake_case)]

pkg/seawater/src/pool.rs

+4
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,10 @@ impl StoragePool {
639639
self.sqrt_price.set(new_price);
640640
}
641641

642+
pub fn set_fee_protocol(&mut self, fee_protocol: u8) {
643+
self.fee_protocol.set(U8::lib(&fee_protocol));
644+
}
645+
642646
pub fn get_enabled(&self) -> bool {
643647
self.enabled.get()
644648
}

pkg/seawater/tests/lib.rs

+31
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,34 @@ fn ethers_suite_swapping_with_permit2_blobs_no_permit2() {
786786
},
787787
);
788788
}
789+
790+
mod proptesting {
791+
use proptest::prelude::*;
792+
793+
use super::*;
794+
795+
fn match_fees(x: u8, y: u8) -> bool {
796+
match (x, y) {
797+
(0, 0) | (0, 1) | (1, 5) | (1, 6) | (1, 7) | (1, 8) | (1, 9) | (1, 10) => true,
798+
_ => false,
799+
}
800+
}
801+
802+
proptest! {
803+
#[test]
804+
fn test_fee_protocol(fee_protocol_0 in any::<u8>(), fee_protocol_1 in any::<u8>()) {
805+
test_utils::with_storage::<_, Pools, _>(
806+
None,
807+
None,
808+
None,
809+
None,
810+
|contract| {
811+
812+
let should_work = match_fees(fee_protocol_0, fee_protocol_1);
813+
814+
let r = contract.set_fee_protocol(Address::ZERO, fee_protocol_0, fee_protocol_1);
815+
assert!((r.is_ok() && should_work) || (r.is_err() && !should_work));
816+
});
817+
}
818+
}
819+
}

pkg/sol/ISeawaterEvents.sol

+9
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,13 @@ interface ISeawaterEvents {
122122
uint256 amount1,
123123
int32 finalTick
124124
);
125+
126+
/// @notice new fees were set!
127+
/// @param pool that the fees are set for.
128+
/// @param fee for the pool given
129+
/// @param feeProtocol that's taken by the protocol
130+
event NewFees(
131+
address indexed pool,
132+
uint8 indexed feeProtocol
133+
);
125134
}

0 commit comments

Comments
 (0)