@@ -200,33 +200,44 @@ function createNonceAccountInstruction(data: WalletInit): TransactionInstruction
200200 */
201201function stakingInitializeInstruction ( data : StakingActivate ) : TransactionInstruction [ ] {
202202 const {
203- params : { fromAddress, stakingAddress, amount, validator } ,
203+ params : { fromAddress, stakingAddress, amount, validator, isMarinade } ,
204204 } = data ;
205205 assert ( fromAddress , 'Missing fromAddress param' ) ;
206206 assert ( stakingAddress , 'Missing stakingAddress param' ) ;
207207 assert ( amount , 'Missing amount param' ) ;
208208 assert ( validator , 'Missing validator param' ) ;
209+ assert ( isMarinade !== undefined , 'Missing isMarinade param' ) ;
209210
210211 const fromPubkey = new PublicKey ( fromAddress ) ;
211212 const stakePubkey = new PublicKey ( stakingAddress ) ;
212-
213+ const validatorPubkey = new PublicKey ( validator ) ;
213214 const tx = new Transaction ( ) ;
214215
216+ const stakerPubkey = isMarinade ? validatorPubkey : fromPubkey ;
215217 const walletInitStaking = StakeProgram . createAccount ( {
216218 fromPubkey,
217219 stakePubkey,
218- authorized : new Authorized ( fromPubkey , fromPubkey ) , // staker and withdrawer
219- lockup : new Lockup ( 0 , 0 , fromPubkey ) , // Lookup sets the minimum epoch to withdraw, by default is 0,0 which means there's no minimum limit
220+ authorized : new Authorized ( stakerPubkey , fromPubkey ) , // staker and withdrawer
221+ lockup : new Lockup ( 0 , 0 , fromPubkey ) , // No minimum epoch to withdraw
220222 lamports : new BigNumber ( amount ) . toNumber ( ) ,
221223 } ) ;
222224 tx . add ( walletInitStaking ) ;
223225
224- const delegateStaking = StakeProgram . delegate ( {
225- stakePubkey : new PublicKey ( stakingAddress ) ,
226- authorizedPubkey : new PublicKey ( fromAddress ) ,
227- votePubkey : new PublicKey ( validator ) ,
228- } ) ;
229- tx . add ( delegateStaking ) ;
226+ if ( isMarinade ) {
227+ const initializeStaking = StakeProgram . initialize ( {
228+ stakePubkey,
229+ authorized : new Authorized ( stakerPubkey , fromPubkey ) , // staker and withdrawer
230+ lockup : new Lockup ( 0 , 0 , fromPubkey ) , // No minimum epoch to withdraw
231+ } ) ;
232+ tx . add ( initializeStaking ) ;
233+ } else {
234+ const delegateStaking = StakeProgram . delegate ( {
235+ stakePubkey : new PublicKey ( stakingAddress ) ,
236+ authorizedPubkey : new PublicKey ( fromAddress ) ,
237+ votePubkey : new PublicKey ( validator ) ,
238+ } ) ;
239+ tx . add ( delegateStaking ) ;
240+ }
230241
231242 return tx . instructions ;
232243}
@@ -246,8 +257,8 @@ function stakingDeactivateInstruction(data: StakingDeactivate): TransactionInstr
246257
247258 if ( data . params . amount && data . params . unstakingAddress ) {
248259 const tx = new Transaction ( ) ;
249-
250260 const unstakingAddress = new PublicKey ( data . params . unstakingAddress ) ;
261+
251262 const allocateAccount = SystemProgram . allocate ( {
252263 accountPubkey : unstakingAddress ,
253264 space : StakeProgram . space ,
0 commit comments