File tree Expand file tree Collapse file tree 5 files changed +52
-0
lines changed Expand file tree Collapse file tree 5 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 Environments ,
1313 MPCSweepRecoveryOptions ,
1414 MPCTxs ,
15+ TokenEnablementConfig ,
1516} from '@bitgo/sdk-core' ;
1617import { ApiPromise , WsProvider } from '@polkadot/api' ;
1718import { BaseCoin as StaticsBaseCoin , coins , SubstrateSpecNameType } from '@bitgo/statics' ;
@@ -343,4 +344,23 @@ export class Polyx extends SubstrateCoin {
343344 }
344345 return { transactions : broadcastableTransactions , lastScanIndex } ;
345346 }
347+
348+ /**
349+ * Gets config for how token enablements work for this coin
350+ * @returns
351+ * requiresTokenEnablement: True if tokens need to be enabled for this coin
352+ * supportsMultipleTokenEnablements: True if multiple tokens can be enabled in one transaction
353+ * validateWallet: Function to validate wallet type for token enablement
354+ */
355+ getTokenEnablementConfig ( ) : TokenEnablementConfig {
356+ return {
357+ requiresTokenEnablement : true ,
358+ supportsMultipleTokenEnablements : false ,
359+ validateWallet : ( walletType : string ) => {
360+ if ( walletType !== 'custodial' ) {
361+ throw new Error ( 'Token enablement for Polymesh (polyx) is only supported for custodial wallets' ) ;
362+ }
363+ } ,
364+ } ;
365+ }
346366}
Original file line number Diff line number Diff line change @@ -179,4 +179,24 @@ describe('Polyx:', function () {
179179 should . deepEqual ( txJson . eraPeriod , baseCoin . SWEEP_TXN_DURATION ) ;
180180 } ) ;
181181 } ) ;
182+
183+ describe ( 'Token Enablement:' , function ( ) {
184+ it ( 'should have correct token enablement config' , function ( ) {
185+ const config = baseCoin . getTokenEnablementConfig ( ) ;
186+ should . exist ( config ) ;
187+ config . requiresTokenEnablement . should . equal ( true ) ;
188+ config . supportsMultipleTokenEnablements . should . equal ( false ) ;
189+ } ) ;
190+
191+ it ( 'should validate wallet type for token enablement' , function ( ) {
192+ const config = baseCoin . getTokenEnablementConfig ( ) ;
193+ ( ( ) => config . validateWallet ( 'custodial' ) ) . should . not . throw ( ) ;
194+ ( ( ) => config . validateWallet ( 'hot' ) ) . should . throw (
195+ / T o k e n e n a b l e m e n t f o r P o l y m e s h \( p o l y x \) i s o n l y s u p p o r t e d f o r c u s t o d i a l w a l l e t s /
196+ ) ;
197+ ( ( ) => config . validateWallet ( 'cold' ) ) . should . throw (
198+ / T o k e n e n a b l e m e n t f o r P o l y m e s h \( p o l y x \) i s o n l y s u p p o r t e d f o r c u s t o d i a l w a l l e t s /
199+ ) ;
200+ } ) ;
201+ } ) ;
182202} ) ;
Original file line number Diff line number Diff line change @@ -455,6 +455,7 @@ export interface RecoverTokenTransaction {
455455export interface TokenEnablementConfig {
456456 requiresTokenEnablement : boolean ;
457457 supportsMultipleTokenEnablements : boolean ;
458+ validateWallet ?: ( walletType : string ) => void ;
458459}
459460
460461export interface MessagePrep {
Original file line number Diff line number Diff line change @@ -3118,6 +3118,12 @@ export class Wallet implements IWallet {
31183118 if ( ! teConfig . requiresTokenEnablement ) {
31193119 throw new Error ( `${ this . baseCoin . getFullName ( ) } does not require token enablements` ) ;
31203120 }
3121+
3122+ // Validate wallet type if coin requires it
3123+ if ( typeof teConfig . validateWallet === 'function' && this . _wallet . type ) {
3124+ teConfig . validateWallet ( this . _wallet . type ) ;
3125+ }
3126+
31213127 if ( params . enableTokens . length === 0 ) {
31223128 throw new Error ( 'No tokens are being specified' ) ;
31233129 }
@@ -3185,6 +3191,11 @@ export class Wallet implements IWallet {
31853191 throw new Error ( `${ this . baseCoin . getFullName ( ) } does not require token enablement transactions` ) ;
31863192 }
31873193
3194+ // Validate wallet type if coin requires it
3195+ if ( teConfig . validateWallet && this . _wallet . type ) {
3196+ teConfig . validateWallet ( this . _wallet . type ) ;
3197+ }
3198+
31883199 if ( typeof params . prebuildTx === 'string' || params . prebuildTx ?. buildParams ?. type !== 'enabletoken' ) {
31893200 throw new Error ( 'Invalid build of token enablement.' ) ;
31903201 }
You can’t perform that action at this time.
0 commit comments