Skip to content

Commit 417e3be

Browse files
committed
feat(sdk-coin-sol): add SPL getTokenType and SolCoin programId guardrails
Ticket: CHALO-506
1 parent f9f8c79 commit 417e3be

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

modules/sdk-coin-sol/src/solToken.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export class SolToken extends Sol {
7575
return Math.pow(10, this.tokenConfig.decimalPlaces);
7676
}
7777

78+
/**
79+
* Token standard for consolidation intents (wallet-platform).
80+
* @returns {string} SPL token type identifier
81+
*/
82+
getTokenType(): string {
83+
return 'SPL';
84+
}
85+
7886
/**
7987
* Flag for sending value of 0
8088
* @returns {boolean} True if okay to send 0 value, false otherwise

modules/sdk-coin-sol/test/unit/solToken.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ describe('SOL Token:', function () {
2828
solTokenCoin.tokenAddress.should.equal('J3NKxxXZcnNiMjKw9hYb2K4LUxgwB6t1FtPtQVsv3KFr');
2929
solTokenCoin.contractAddress.should.equal('J3NKxxXZcnNiMjKw9hYb2K4LUxgwB6t1FtPtQVsv3KFr');
3030
});
31+
32+
it('should return SPL token type for mainnet token', function () {
33+
solTokenCoin.getTokenType().should.equal('SPL');
34+
});
35+
36+
it('should return SPL token type for testnet token', function () {
37+
(bitgo.coin('tsol:usdc') as SolToken).getTokenType().should.equal('SPL');
38+
});
3139
});

modules/statics/test/unit/coins.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
trimmedDynamicBaseChainConfig,
4242
} from './resources/amsTokenConfig';
4343
import { EthLikeErc20Token } from '../../../sdk-coin-evm/src';
44+
import { ProgramID } from '../../src/account';
4445
import { allCoinsAndTokens } from '../../src/allCoinsAndTokens';
4546

4647
interface DuplicateCoinObject {
@@ -1012,6 +1013,15 @@ describe('Token contract address field defaults', () => {
10121013
solToken.contractAddress.should.eql(solToken.tokenAddress);
10131014
});
10141015
});
1016+
1017+
it('have valid programId (SPL or Token-2022)', () => {
1018+
const validProgramIds = [ProgramID.TokenProgramId, ProgramID.Token2022ProgramId];
1019+
coins
1020+
.filter((coin) => coin.family === CoinFamily.SOL && coin instanceof SolCoin)
1021+
.forEach((coin) => {
1022+
validProgramIds.should.containEql((coin as SolCoin).programId);
1023+
});
1024+
});
10151025
});
10161026
describe('XRP tokens', function () {
10171027
it('have `contractAddress` === `issuerAddress::currencyCode`', () => {

0 commit comments

Comments
 (0)