Skip to content

Commit 8ffd5a1

Browse files
committed
feat: add ofc tokens from ams to coin map
Ticket: WIN-5497
1 parent d84b3e0 commit 8ffd5a1

File tree

6 files changed

+126
-1
lines changed

6 files changed

+126
-1
lines changed

modules/statics/src/coins.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
xrpToken,
4545
zkethErc20,
4646
} from './account';
47+
import { ofcToken } from './ofc';
4748
import { ada } from './ada';
4849
import { avaxp } from './avaxp';
4950
import { BaseCoin, BaseUnit, CoinFeature, KeyCurve, UnderlyingAsset } from './base';
@@ -3337,6 +3338,7 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
33373338
trx: tronToken,
33383339
xlm: stellarToken,
33393340
xrp: xrpToken,
3341+
ofc: ofcToken,
33403342
};
33413343

33423344
const family = token.family;
@@ -3450,7 +3452,13 @@ export function createToken(token: AmsTokenConfig): Readonly<BaseCoin> | undefin
34503452
token.domain, // domain
34513453
...commonArgs.slice(4) // asset, features, prefix, suffix, network, primaryKeyCurve
34523454
);
3453-
3455+
case 'ofc':
3456+
return initializer(
3457+
...commonArgs, // id, name, fullName, decimalPlaces, asset, prefix, suffix, network, primaryKeyCurve
3458+
token.baseUnit, // baseUnit
3459+
token.isToken, // isToken
3460+
token.kind // kind
3461+
);
34543462
default:
34553463
return undefined;
34563464
}

modules/statics/src/networkFeatureMapForTokens.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
STX_TOKEN_FEATURES,
99
SUI_TOKEN_FEATURES,
1010
} from './coinFeatures';
11+
import { OfcCoin } from './ofc';
1112

1213
export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[]>> = {
1314
algo: AccountCoin.DEFAULT_FEATURES,
@@ -28,4 +29,5 @@ export const networkFeatureMapForTokens: Partial<Record<CoinFamily, CoinFeature[
2829
trx: AccountCoin.DEFAULT_FEATURES,
2930
xlm: AccountCoin.DEFAULT_FEATURES,
3031
xrp: AccountCoin.DEFAULT_FEATURES,
32+
ofc: OfcCoin.DEFAULT_FEATURES,
3133
};

modules/statics/src/ofc.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,58 @@ export class OfcCoin extends BaseCoin {
5656
}
5757
}
5858

59+
/**
60+
* Function to convert AMS inputs into OFC coin instance.
61+
*
62+
* @param id uuid v4
63+
* @param name unique identifier of the coin
64+
* @param fullName complete human-readable name of the coin
65+
* @param decimalPlaces Number of decimal places this coin supports (divisibility exponent)
66+
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
67+
* @param features Features of this coin. Defaults to the DEFAULT_FEATURES defined in `OfcCoin`
68+
* @param prefix Optional coin prefix. Defaults to empty string
69+
* @param suffix Optional coin suffix. Defaults to coin name.
70+
* @param network Network object for this coin
71+
* @param primaryKeyCurve The elliptic curve for this chain/token
72+
* @param baseUnit base unit of the token
73+
* @param isToken Whether or not this account coin is a token of another coin
74+
* @param kind Differentiates coins which represent fiat assets from those which represent crypto assets
75+
* @returns {Readonly<OfcCoin>} OFC coin instance
76+
*/
77+
export function ofcToken(
78+
id: string,
79+
name: string,
80+
fullName: string,
81+
decimalPlaces: number,
82+
asset: UnderlyingAsset,
83+
features: CoinFeature[] = OfcCoin.DEFAULT_FEATURES,
84+
prefix = '',
85+
suffix: string = name.replace(/^ofc/, '').toUpperCase(),
86+
network: OfcNetwork = Networks.main.ofc,
87+
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1,
88+
baseUnit: BaseUnit = BaseUnit.OFC,
89+
isToken = true,
90+
kind: CoinKind = CoinKind.CRYPTO
91+
): Readonly<OfcCoin> {
92+
return Object.freeze(
93+
new OfcCoin({
94+
id,
95+
name,
96+
fullName,
97+
network,
98+
prefix,
99+
suffix,
100+
features,
101+
decimalPlaces,
102+
isToken,
103+
asset,
104+
kind: kind,
105+
primaryKeyCurve: primaryKeyCurve,
106+
baseUnit: baseUnit,
107+
})
108+
);
109+
}
110+
59111
/**
60112
* Factory function for ofc coin instances.
61113
*

modules/statics/src/tokenConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ export interface AmsTokenConfig {
259259
domain?: string;
260260
assetId?: string;
261261
isToken: boolean;
262+
baseUnit?: string;
263+
kind?: string;
262264
}
263265

264266
export interface TrimmedAmsNetworkConfig {

modules/statics/test/unit/coins.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ describe('create token map using config details', () => {
10531053
formattedTokens.bitcoin.should.deepEqual(tokens.bitcoin);
10541054
formattedTokens.testnet.eth.should.not.deepEqual(tokens.testnet.eth);
10551055
formattedTokens.testnet.eth.tokens.some((token) => token.type === 'hteth:faketoken').should.eql(true);
1056+
formattedTokens.testnet.ofc.tokens.some((token) => token.type === 'ofcterc2').should.eql(true);
10561057
});
10571058
it('should not create an base coin object in coin map for token with unsupported network', () => {
10581059
const tokenMap = createTokenMapUsingTrimmedConfigDetails(amsTokenWithUnsupportedNetwork);
@@ -1061,12 +1062,18 @@ describe('create token map using config details', () => {
10611062
it('should create a coin map using reduced token config details', () => {
10621063
const coinMap1 = createTokenMapUsingTrimmedConfigDetails(reducedAmsTokenConfig);
10631064
const amsToken1 = coinMap1.get('hteth:faketoken');
1065+
const amsOfcToken1 = coinMap1.get('ofcterc2');
10641066
const coinMap2 = createTokenMapUsingConfigDetails(amsTokenConfigWithCustomToken);
10651067
const amsToken2 = coinMap2.get('hteth:faketoken');
1068+
const amsOfcToken2 = coinMap2.get('ofcterc2');
10661069
const { network: tokenNetwork1, ...tokenRest1 } = amsToken1;
10671070
const { network: tokenNetwork2, ...tokenRest2 } = amsToken2;
1071+
const { network: tokenNetwork3, ...tokenRest3 } = amsOfcToken1;
1072+
const { network: tokenNetwork4, ...tokenRest4 } = amsOfcToken2;
10681073
tokenRest1.should.deepEqual(tokenRest2);
1074+
tokenRest3.should.deepEqual(tokenRest4);
10691075
JSON.stringify(tokenNetwork1).should.eql(JSON.stringify(tokenNetwork2));
1076+
JSON.stringify(tokenNetwork3).should.eql(JSON.stringify(tokenNetwork4));
10701077
});
10711078
it('should be able to add single ams token into coin map', () => {
10721079
const coinMap = CoinMap.fromCoins([]);

modules/statics/test/unit/resources/amsTokenConfig.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,37 @@ export const amsTokenConfigWithCustomToken = {
653653
contractAddress: '0x89a959b9184b4f8c8633646d5dfd049d2ebc983a',
654654
},
655655
],
656+
ofcterc2: [
657+
{
658+
id: '055ebe86-72cc-4f0e-b46f-c517d8e36871',
659+
fullName: 'Test ERC Token2',
660+
name: 'ofcterc2',
661+
prefix: '',
662+
suffix: 'TERC',
663+
baseUnit: 'wei',
664+
kind: 'crypto',
665+
family: 'ofc',
666+
isToken: true,
667+
features: [
668+
'account-model',
669+
'requires-big-number',
670+
'custody',
671+
'custody-bitgo-trust',
672+
'custody-bitgo-mena-fze',
673+
'custody-bitgo-custody-mena-fze',
674+
],
675+
decimalPlaces: 18,
676+
asset: 'terc',
677+
network: {
678+
type: 'testnet',
679+
name: 'OfcTestnet',
680+
family: 'ofc',
681+
},
682+
primaryKeyCurve: 'secp256k1',
683+
addressCoin: 'teth',
684+
minimumDenomination: 1000000000000000000,
685+
},
686+
],
656687
};
657688

658689
export const incorrectAmsTokenConfig = {
@@ -721,6 +752,29 @@ export const reducedAmsTokenConfig = {
721752
contractAddress: '0x89a959b9184b4f8c8633646d5dfd049d2ebc983a',
722753
},
723754
],
755+
ofcterc2: [
756+
{
757+
id: '055ebe86-72cc-4f0e-b46f-c517d8e36871',
758+
fullName: 'Test ERC Token2',
759+
name: 'ofcterc2',
760+
prefix: '',
761+
suffix: 'TERC',
762+
baseUnit: 'wei',
763+
kind: 'crypto',
764+
family: 'ofc',
765+
isToken: true,
766+
decimalPlaces: 18,
767+
asset: 'terc',
768+
additionalFeatures: [],
769+
excludedFeatures: [],
770+
network: {
771+
name: 'OfcTestnet',
772+
},
773+
primaryKeyCurve: 'secp256k1',
774+
addressCoin: 'teth',
775+
minimumDenomination: 1000000000000000000,
776+
},
777+
],
724778
};
725779

726780
export const amsTokenWithUnsupportedNetwork = {

0 commit comments

Comments
 (0)