@@ -7,12 +7,15 @@ import { StakingDeactivate, Transfer } from './iface';
77import { Transaction } from './transaction' ;
88import { TransactionBuilder } from './transactionBuilder' ;
99import { isValidStakingAmount , validateAddress } from './utils' ;
10+ import { RecipientEntry } from '@bitgo/public-types' ;
1011
1112export class StakingDeactivateBuilder extends TransactionBuilder {
1213 protected _stakingAddress : string ;
1314 protected _stakingAddresses : string [ ] ;
1415 protected _amount ?: string ;
1516 protected _unstakingAddress : string ;
17+ protected _isMarinade = false ;
18+ protected _recipients : RecipientEntry [ ] ;
1619
1720 constructor ( _coinConfig : Readonly < CoinConfig > ) {
1821 super ( _coinConfig ) ;
@@ -29,7 +32,13 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
2932 for ( const instruction of this . _instructionsData ) {
3033 if ( instruction . type === InstructionBuilderTypes . StakingDeactivate ) {
3134 const deactivateInstruction : StakingDeactivate = instruction ;
32- this . sender ( deactivateInstruction . params . fromAddress ) ;
35+ this . isMarinade ( deactivateInstruction . params . isMarinade ?? false ) ;
36+ if ( ! deactivateInstruction . params . isMarinade ) {
37+ this . sender ( deactivateInstruction . params . fromAddress ) ;
38+ }
39+ if ( deactivateInstruction . params . isMarinade ) {
40+ this . recipients ( deactivateInstruction . params . recipients ?? [ ] ) ;
41+ }
3342 stakingAddresses . push ( deactivateInstruction . params . stakingAddress ) ;
3443 if ( deactivateInstruction . params . amount && deactivateInstruction . params . unstakingAddress ) {
3544 this . amount ( deactivateInstruction . params . amount ) ;
@@ -40,7 +49,9 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
4049 if ( stakingAddresses . length > 1 ) {
4150 this . stakingAddresses ( stakingAddresses ) ;
4251 } else {
43- this . stakingAddress ( stakingAddresses [ 0 ] ) ;
52+ if ( ! this . _isMarinade ) {
53+ this . stakingAddress ( stakingAddresses [ 0 ] ) ;
54+ }
4455 }
4556 }
4657
@@ -91,6 +102,17 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
91102 return this ;
92103 }
93104
105+ /**
106+ * Setter to set the recipients object
107+ *
108+ * @param recipients RecipientEntry[] - The recipients object
109+ * @returns {StakingDeactivateBuilder } This staking builder.
110+ */
111+ recipients ( recipients : RecipientEntry [ ] ) : this {
112+ this . _recipients = recipients ;
113+ return this ;
114+ }
115+
94116 /**
95117 * When partially unstaking move the amount to unstake to this account and initiate the
96118 * unstake process. The original stake account will continue staking.
@@ -106,9 +128,20 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
106128 return this ;
107129 }
108130
131+ /**
132+ * Set isMarinade flag
133+ * @param {boolean } flag - true if the transaction is for Marinade, false by default if not set
134+ * @returns {StakingActivateBuilder } This staking builder
135+ */
136+ isMarinade ( flag : boolean ) : this {
137+ this . _isMarinade = flag ;
138+ return this ;
139+ }
140+
109141 /** @inheritdoc */
110142 protected async buildImplementation ( ) : Promise < Transaction > {
111143 assert ( this . _sender , 'Sender must be set before building the transaction' ) ;
144+ assert ( this . _isMarinade !== undefined , 'isMarinade must be set before building the transaction' ) ;
112145
113146 if ( this . _stakingAddresses && this . _stakingAddresses . length > 0 ) {
114147 this . _instructionsData = [ ] ;
@@ -123,7 +156,10 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
123156 this . _instructionsData . push ( stakingDeactivateData ) ;
124157 }
125158 } else {
126- assert ( this . _stakingAddress , 'Staking address must be set before building the transaction' ) ;
159+ if ( ! this . _isMarinade ) {
160+ // we don't need stakingAddress in marinade staking deactivate txn
161+ assert ( this . _stakingAddress , 'Staking address must be set before building the transaction' ) ;
162+ }
127163
128164 if ( this . _sender === this . _stakingAddress ) {
129165 throw new BuildTransactionError ( 'Sender address cannot be the same as the Staking address' ) ;
@@ -136,7 +172,7 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
136172 ) ;
137173 }
138174 this . _instructionsData = [ ] ;
139- if ( this . _unstakingAddress ) {
175+ if ( this . _unstakingAddress && ! this . _isMarinade ) {
140176 assert (
141177 this . _amount ,
142178 'If an unstaking address is given then a partial amount to unstake must also be set before building the transaction'
@@ -159,6 +195,8 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
159195 stakingAddress : this . _stakingAddress ,
160196 amount : this . _amount ,
161197 unstakingAddress : this . _unstakingAddress ,
198+ isMarinade : this . _isMarinade ,
199+ recipients : this . _recipients ,
162200 } ,
163201 } ;
164202 this . _instructionsData . push ( stakingDeactivateData ) ;
0 commit comments