-
Notifications
You must be signed in to change notification settings - Fork 2
feat/add common protocol fee #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release_0.2.2
Are you sure you want to change the base?
Conversation
2132c76 to
f68848a
Compare
| // https://github.com/MeteoraAg/zap-program/blob/main/idls/dlmm.json#L3413-L3422 | ||
| #[constant] | ||
| pub const DLMM_SWAP2_DISC: [u8; 8] = [65, 75, 63, 76, 235, 91, 91, 136]; | ||
| use protocol_zap::constants::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zap program depends on protocol_zap for these constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets rename it to zap-sdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed and updated to the IDL found on solscan
| fn ensure_route_plan_fully_converges(route_plan_steps: &[RoutePlanStep]) -> Result<()> { | ||
| // Verify each unique input_index sums to exactly 100% | ||
| for (i, step) in route_plan_steps.iter().enumerate() { | ||
| // Only process first occurrence of each input_index | ||
| let seen = route_plan_steps[..i] | ||
| .iter() | ||
| .any(|s| s.input_index == step.input_index); | ||
| if seen { | ||
| continue; | ||
| } | ||
|
|
||
| let percent_sum = route_plan_steps | ||
| .iter() | ||
| .filter(|s| s.input_index == step.input_index) | ||
| .try_fold(0u8, |acc, s| acc.checked_add(s.percent)) | ||
| .ok_or(ProtocolZapError::MathOverflow)?; | ||
|
|
||
| require!( | ||
| percent_sum == 100, | ||
| ProtocolZapError::InvalidZapOutParameters | ||
| ); | ||
| } | ||
|
|
||
| // Count terminal outputs: unique outputs never used as inputs | ||
| let terminal_count = route_plan_steps | ||
| .iter() | ||
| .enumerate() | ||
| .filter(|(i, step)| { | ||
| let is_first = !route_plan_steps[..*i] | ||
| .iter() | ||
| .any(|s| s.output_index == step.output_index); | ||
| let is_terminal = !route_plan_steps | ||
| .iter() | ||
| .any(|s| s.input_index == step.output_index); | ||
| is_first && is_terminal | ||
| }) | ||
| .count(); | ||
|
|
||
| require!( | ||
| terminal_count == 1, | ||
| ProtocolZapError::InvalidZapOutParameters | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks weird because I'm trying to avoid using Map and Set to avoid additional heap allocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need zap_out2 since all the additional verification is only done in zap_protocol_fee ix rather than the zap_out ix that comes right after it in the tx.
| @@ -0,0 +1,11 @@ | |||
| [package] | |||
| name = "protocol-zap" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets rename it to zap-sdk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and separate the code:
- To be used in zap-program
- To be used in protocol-zap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if this is what you have in mind. So there will be zap-sdk, which zap-program and protocol-zap depends on?
zap-sdk -> common code used by zap-program/protocol-zap
protocol-zap -> common code used by other programs to zap protocol fee
|
|
||
| pub const MINTS_DISALLOWED_TO_ZAP_OUT: [Pubkey; 2] = [USDC_ADDRESS, SOL_ADDRESS]; | ||
|
|
||
| pub const TREASURY: Pubkey = pubkey!("6aYhxiNGmG8AyU25rh2R7iFu4pBrqnQHpNUGhmsEXRcm"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't push treasury wallet in the sdk, it should be re-used by other programs, not only Meteora
|
|
||
| pub const TREASURY: Pubkey = pubkey!("6aYhxiNGmG8AyU25rh2R7iFu4pBrqnQHpNUGhmsEXRcm"); | ||
|
|
||
| pub const TREASURY_USDC_ADDRESS: Pubkey = Pubkey::new_from_array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto^, we dont fix treasury wallet, so those addresses will be dynamic
| .0, | ||
| ); | ||
|
|
||
| pub const TREASURY_SOL_ADDRESS: Pubkey = Pubkey::new_from_array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto^
|
|
||
| [dependencies] | ||
| anchor-lang = { workspace = true } | ||
| anchor-spl = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if we can make it no anchor dependencies, so it is easier to being imported from other projects?
|
|
||
| fn ensure_whitelisted_swap_leg(route_plan_steps: &[RoutePlanStep]) -> Result<()> { | ||
| for step in route_plan_steps { | ||
| match step.swap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make it constants? whitelisted_swap_leg
| use anchor_lang::prelude::*; | ||
|
|
||
| // Anchor custom user error codes start at 6000. Adding 1000 to avoid conflict with calling program error codes | ||
| #[error_code(offset = 7000)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is breaking change for zap-program
Lets avoid to use Anchor custom error code here, instead return pure ErrorCode
If other program want to import it, they must map the error back their program (Impl From trait)
| try_into_impl!(usize, u16); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets try to avoid to push test in same file with program code
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets try to avoid to push test in same file with program code
No description provided.