@@ -96,6 +96,22 @@ impl CallableInstruction {
9696 }
9797}
9898
99+ /// Struct containing revert options
100+ /// # Arguments
101+ /// * `revert_address` Address to receive revert.
102+ /// * `abort_address` Address to receive funds if aborted.
103+ /// * `call_on_revert` Flag if on_revert hook should be called.
104+ /// * `revert_message` Arbitrary data sent back in on_revert.
105+ /// * `on_revert_gas_limit` Gas limit for revert tx.
106+ #[ derive( AnchorSerialize , AnchorDeserialize , Clone , Debug , PartialEq ) ]
107+ pub struct RevertOptions {
108+ pub revert_address : Pubkey ,
109+ pub abort_address : Pubkey ,
110+ pub call_on_revert : bool ,
111+ pub revert_message : Vec < u8 > ,
112+ pub on_revert_gas_limit : u64 ,
113+ }
114+
99115#[ program]
100116pub mod gateway {
101117 use super :: * ;
@@ -104,8 +120,6 @@ pub mod gateway {
104120 const DEPOSIT_FEE : u64 = 2_000_000 ;
105121 /// Prefix used for outbounds message hashes.
106122 pub const ZETACHAIN_PREFIX : & [ u8 ] = b"ZETACHAIN" ;
107- /// Max deposit payload size
108- const MAX_DEPOSIT_PAYLOAD_SIZE : usize = 750 ;
109123
110124 /// Initializes the gateway PDA.
111125 ///
@@ -536,7 +550,15 @@ pub mod gateway {
536550 /// * `ctx` - The instruction context.
537551 /// * `amount` - The amount of lamports to deposit.
538552 /// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
539- pub fn deposit ( ctx : Context < Deposit > , amount : u64 , receiver : [ u8 ; 20 ] ) -> Result < ( ) > {
553+ /// * `revert_options` - Revert options.
554+ pub fn deposit (
555+ ctx : Context < Deposit > ,
556+ amount : u64 ,
557+ receiver : [ u8 ; 20 ] ,
558+ revert_options : Option < RevertOptions > ,
559+ ) -> Result < ( ) > {
560+ verify_payload_size ( None , & revert_options) ?;
561+
540562 let pda = & mut ctx. accounts . pda ;
541563 require ! ( !pda. deposit_paused, Errors :: DepositPaused ) ;
542564 require ! ( receiver != [ 0u8 ; 20 ] , Errors :: EmptyReceiver ) ;
@@ -552,11 +574,12 @@ pub mod gateway {
552574 system_program:: transfer ( cpi_context, amount_with_fees) ?;
553575
554576 msg ! (
555- "Deposit executed: amount = {}, fee = {}, receiver = {:?}, pda = {}" ,
577+ "Deposit executed: amount = {}, fee = {}, receiver = {:?}, pda = {}, revert options = {:?} " ,
556578 amount,
557579 DEPOSIT_FEE ,
558580 receiver,
559- ctx. accounts. pda. key( )
581+ ctx. accounts. pda. key( ) ,
582+ revert_options
560583 ) ;
561584
562585 Ok ( ( ) )
@@ -569,17 +592,17 @@ pub mod gateway {
569592 /// * `amount` - The amount of lamports to deposit.
570593 /// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
571594 /// * `message` - The message passed to the contract.
595+ /// * `revert_options` - Revert options.
572596 pub fn deposit_and_call (
573597 ctx : Context < Deposit > ,
574598 amount : u64 ,
575599 receiver : [ u8 ; 20 ] ,
576600 message : Vec < u8 > ,
601+ revert_options : Option < RevertOptions > ,
577602 ) -> Result < ( ) > {
578- require ! (
579- message. len( ) <= MAX_DEPOSIT_PAYLOAD_SIZE ,
580- Errors :: MemoLengthExceeded
581- ) ;
582- deposit ( ctx, amount, receiver) ?;
603+ verify_payload_size ( Some ( & message) , & revert_options) ?;
604+
605+ deposit ( ctx, amount, receiver, revert_options) ?;
583606
584607 msg ! ( "Deposit and call executed with message = {:?}" , message) ;
585608
@@ -592,11 +615,15 @@ pub mod gateway {
592615 /// * `ctx` - The instruction context.
593616 /// * `amount` - The amount of SPL tokens to deposit.
594617 /// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
618+ /// * `revert_options` - Revert options.
595619 pub fn deposit_spl_token (
596620 ctx : Context < DepositSplToken > ,
597621 amount : u64 ,
598622 receiver : [ u8 ; 20 ] ,
623+ revert_options : Option < RevertOptions > ,
599624 ) -> Result < ( ) > {
625+ verify_payload_size ( None , & revert_options) ?;
626+
600627 let token = & ctx. accounts . token_program ;
601628 let from = & ctx. accounts . from ;
602629
@@ -630,12 +657,13 @@ pub mod gateway {
630657 transfer ( xfer_ctx, amount) ?;
631658
632659 msg ! (
633- "Deposit SPL executed: amount = {}, fee = {}, receiver = {:?}, pda = {}, mint = {}" ,
660+ "Deposit SPL executed: amount = {}, fee = {}, receiver = {:?}, pda = {}, mint = {}, revert options = {:?} " ,
634661 amount,
635662 DEPOSIT_FEE ,
636663 receiver,
637664 ctx. accounts. pda. key( ) ,
638- ctx. accounts. mint_account. key( )
665+ ctx. accounts. mint_account. key( ) ,
666+ revert_options
639667 ) ;
640668
641669 Ok ( ( ) )
@@ -648,17 +676,17 @@ pub mod gateway {
648676 /// * `amount` - The amount of SPL tokens to deposit.
649677 /// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
650678 /// * `message` - The message passed to the contract.
679+ /// * `revert_options` - Revert options.
651680 pub fn deposit_spl_token_and_call (
652681 ctx : Context < DepositSplToken > ,
653682 amount : u64 ,
654683 receiver : [ u8 ; 20 ] ,
655684 message : Vec < u8 > ,
685+ revert_options : Option < RevertOptions > ,
656686 ) -> Result < ( ) > {
657- require ! (
658- message. len( ) <= MAX_DEPOSIT_PAYLOAD_SIZE ,
659- Errors :: MemoLengthExceeded
660- ) ;
661- deposit_spl_token ( ctx, amount, receiver) ?;
687+ verify_payload_size ( Some ( & message) , & revert_options) ?;
688+
689+ deposit_spl_token ( ctx, amount, receiver, revert_options) ?;
662690
663691 msg ! ( "Deposit SPL and call executed with message = {:?}" , message) ;
664692
@@ -671,17 +699,21 @@ pub mod gateway {
671699 /// * `ctx` - The instruction context.
672700 /// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
673701 /// * `message` - The message passed to the contract.
674- pub fn call ( _ctx : Context < Call > , receiver : [ u8 ; 20 ] , message : Vec < u8 > ) -> Result < ( ) > {
702+ /// * `revert_options` - Revert options.
703+ pub fn call (
704+ _ctx : Context < Call > ,
705+ receiver : [ u8 ; 20 ] ,
706+ message : Vec < u8 > ,
707+ revert_options : Option < RevertOptions > ,
708+ ) -> Result < ( ) > {
675709 require ! ( receiver != [ 0u8 ; 20 ] , Errors :: EmptyReceiver ) ;
676- require ! (
677- message. len( ) <= MAX_DEPOSIT_PAYLOAD_SIZE ,
678- Errors :: MemoLengthExceeded
679- ) ;
710+ verify_payload_size ( Some ( & message) , & revert_options) ?;
680711
681712 msg ! (
682- "Call executed: receiver = {:?}, message = {:?}" ,
713+ "Call executed: receiver = {:?}, message = {:?}, revert options = {:?} " ,
683714 receiver,
684- message
715+ message,
716+ revert_options
685717 ) ;
686718
687719 Ok ( ( ) )
@@ -979,6 +1011,26 @@ fn prepare_account_metas(
9791011 Ok ( account_metas)
9801012}
9811013
1014+ fn verify_payload_size (
1015+ message : Option < & Vec < u8 > > ,
1016+ revert_options : & Option < RevertOptions > ,
1017+ ) -> Result < ( ) > {
1018+ /// Max deposit payload size
1019+ const MAX_DEPOSIT_PAYLOAD_SIZE : usize = 745 ;
1020+ let msg_len = message. map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
1021+ let revert_len = revert_options
1022+ . as_ref ( )
1023+ . map ( |opts| opts. revert_message . len ( ) )
1024+ . unwrap_or ( 0 ) ;
1025+
1026+ require ! (
1027+ msg_len + revert_len <= MAX_DEPOSIT_PAYLOAD_SIZE ,
1028+ Errors :: MemoLengthExceeded
1029+ ) ;
1030+
1031+ Ok ( ( ) )
1032+ }
1033+
9821034/// Instruction context for initializing the program.
9831035#[ derive( Accounts ) ]
9841036pub struct Initialize < ' info > {
0 commit comments