Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
Celo,
CeloToken,
Coredao,
CoredaoToken,
Coreum,
Cronos,
Cspr,
Expand Down Expand Up @@ -405,6 +406,10 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
coinFactory.register(name, coinConstructor);
});

CoredaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
coinFactory.register(name, coinConstructor);
});

SolToken.createTokenConstructors([...tokens.bitcoin.sol.tokens, ...tokens.testnet.sol.tokens]).forEach(
({ name, coinConstructor }) => {
coinFactory.register(name, coinConstructor);
Expand Down
4 changes: 2 additions & 2 deletions modules/bitgo/src/v2/coins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Bsv, Tbsv } from '@bitgo/sdk-coin-bsv';
import { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig } from '@bitgo/sdk-coin-btc';
import { Btg } from '@bitgo/sdk-coin-btg';
import { Celo, CeloToken, Tcelo } from '@bitgo/sdk-coin-celo';
import { Coredao, Tcoredao } from '@bitgo/sdk-coin-coredao';
import { Coredao, Tcoredao, CoredaoToken } from '@bitgo/sdk-coin-coredao';
import { Coreum, Tcoreum } from '@bitgo/sdk-coin-coreum';
import { Cronos, Tcronos } from '@bitgo/sdk-coin-cronos';
import { Cspr, Tcspr } from '@bitgo/sdk-coin-cspr';
Expand Down Expand Up @@ -86,7 +86,7 @@ export { Bsv, Tbsv };
export { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig };
export { Btg };
export { Celo, CeloToken, Tcelo };
export { Coredao, Tcoredao };
export { Coredao, Tcoredao, CoredaoToken };
export { Coreum, Tcoreum };
export { Cronos, Tcronos };
export { Cspr, Tcspr };
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/test/browser/browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('Coins', () => {
SoneiumToken: 1,
Polyx: 1,
Tpolyx: 1,
CoredaoToken: 1,
};
Object.keys(BitGoJS.Coin)
.filter((coinName) => !excludedKeys[coinName])
Expand Down
57 changes: 57 additions & 0 deletions modules/sdk-coin-coredao/src/coredaoToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @prettier
*/
import { coins, EthLikeTokenConfig } from '@bitgo/statics';
import { BitGoBase, CoinConstructor, common, MPCAlgorithm, NamedCoinConstructor } from '@bitgo/sdk-core';
import { CoinNames, EthLikeToken, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';

import { TransactionBuilder } from './lib';

export { EthLikeTokenConfig };

export class CoredaoToken extends EthLikeToken {
public readonly tokenConfig: EthLikeTokenConfig;
static coinNames: CoinNames = {
Mainnet: 'coredao',
Testnet: 'tcoredao',
};
constructor(bitgo: BitGoBase, tokenConfig: EthLikeTokenConfig) {
super(bitgo, tokenConfig, CoredaoToken.coinNames);
}
static createTokenConstructor(config: EthLikeTokenConfig): CoinConstructor {
return super.createTokenConstructor(config, CoredaoToken.coinNames);
}

static createTokenConstructors(): NamedCoinConstructor[] {
return super.createTokenConstructors(CoredaoToken.coinNames);
}

protected getTransactionBuilder(): TransactionBuilder {
return new TransactionBuilder(coins.get(this.getBaseChain()));
}

/** @inheritDoc **/
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}

/** @inheritDoc */
supportsTss(): boolean {
return true;
}

/**
* Make a query to Coredao explorer for information such as balance, token balance, solidity calls
* @param {Object} query key-value pairs of parameters to append after /api
* @returns {Promise<Object>} response Coredao explorer
*/
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> {
const apiToken = common.Environments[this.bitgo.getEnv()].coredaoExplorerApiToken;
const explorerUrl = common.Environments[this.bitgo.getEnv()].coredaoExplorerBaseUrl;
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
}

getFullName(): string {
return 'Coredao Token';
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-coredao/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './lib';
export * from './coredao';
export * from './tcoredao';
export * from './coredaoToken';
export * from './register';
4 changes: 4 additions & 0 deletions modules/sdk-coin-coredao/src/register.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { BitGoBase } from '@bitgo/sdk-core';
import { Coredao } from './coredao';
import { Tcoredao } from './tcoredao';
import { CoredaoToken } from './coredaoToken';

export const register = (sdk: BitGoBase): void => {
sdk.register('coredao', Coredao.createInstance);
sdk.register('tcoredao', Tcoredao.createInstance);
CoredaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
sdk.register(name, coinConstructor);
});
};
31 changes: 31 additions & 0 deletions modules/sdk-coin-coredao/test/unit/coredaoToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';

import { CoredaoToken } from '../../src';

describe('Coredao Token:', function () {
let bitgo: TestBitGoAPI;
let coredaoTokenCoin;
const tokenName = 'tcoredao:stcore';

before(function () {
bitgo = TestBitGo.decorate(BitGoAPI, { env: 'test' });
CoredaoToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
bitgo.safeRegister(name, coinConstructor);
});
bitgo.initializeTestVars();
coredaoTokenCoin = bitgo.coin(tokenName);
});

it('should return constants', function () {
coredaoTokenCoin.getChain().should.equal('tcoredao:stcore');
coredaoTokenCoin.getBaseChain().should.equal('tcoredao');
coredaoTokenCoin.getFullName().should.equal('Coredao Token');
coredaoTokenCoin.getBaseFactor().should.equal(1e18);
coredaoTokenCoin.type.should.equal(tokenName);
coredaoTokenCoin.name.should.equal('Testnet stCore token');
coredaoTokenCoin.coin.should.equal('tcoredao');
coredaoTokenCoin.network.should.equal('Testnet');
coredaoTokenCoin.decimalPlaces.should.equal(18);
});
});
100 changes: 100 additions & 0 deletions modules/statics/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,16 @@ export class BeraERC20Token extends ContractAddressDefinedToken {
}
}

/**
* The Coredao Chain network support tokens
* Coredao Chain Tokens are ERC20 tokens
*/
export class CoredaoERC20Token extends ContractAddressDefinedToken {
constructor(options: Erc20ConstructorOptions) {
super(options);
}
}

/**
* The Xrp network supports tokens
* Xrp tokens are identified by their issuer address
Expand Down Expand Up @@ -2280,6 +2290,96 @@ export function tberaErc20(
);
}

/**
* Factory function for CoredaoErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to coredao mainnet network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function coredaoErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = [...AccountCoin.DEFAULT_FEATURES, CoinFeature.EIP1559],
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.main.coredao,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return Object.freeze(
new CoredaoERC20Token({
id,
name,
fullName,
network,
contractAddress,
prefix,
suffix,
features,
decimalPlaces,
asset,
isToken: true,
primaryKeyCurve,
baseUnit: BaseUnit.ETH,
})
);
}

/**
* Factory function for coredao testnet coredaoErc20 token instances.
*
* @param id uuid v4
* @param name unique identifier of the token
* @param fullName Complete human-readable name of the token
* @param decimalPlaces Number of decimal places this token supports (divisibility exponent)
* @param contractAddress Contract address of this token
* @param asset Asset which this coin represents. This is the same for both mainnet and testnet variants of a coin.
* @param prefix? Optional token prefix. Defaults to empty string
* @param suffix? Optional token suffix. Defaults to token name.
* @param network? Optional token network. Defaults to the coredao test network.
* @param features? Features of this coin. Defaults to the DEFAULT_FEATURES defined in `AccountCoin`
* @param primaryKeyCurve The elliptic curve for this chain/token
*/
export function tcoredaoErc20(
id: string,
name: string,
fullName: string,
decimalPlaces: number,
contractAddress: string,
asset: UnderlyingAsset,
features: CoinFeature[] = AccountCoin.DEFAULT_FEATURES,
prefix = '',
suffix: string = name.toUpperCase(),
network: AccountNetwork = Networks.test.coredao,
primaryKeyCurve: KeyCurve = KeyCurve.Secp256k1
) {
return coredaoErc20(
id,
name,
fullName,
decimalPlaces,
contractAddress,
asset,
features,
prefix,
suffix,
network,
primaryKeyCurve
);
}

/**
* Factory function for xrp token instances.
*
Expand Down
6 changes: 6 additions & 0 deletions modules/statics/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,12 @@ export enum UnderlyingAsset {
'erc721:soneiumtoken' = 'erc721:soneiumtoken',
'erc1155:soneiumtoken' = 'erc1155:soneiumtoken',

// coredao mainnet tokens
'coredao:stcore' = 'coredao:stcore',

// coredao testnet tokens
'tcoredao:stcore' = 'tcoredao:stcore',

ERC721 = 'erc721',
ERC1155 = 'erc1155',
NONSTANDARD = 'nonstandard',
Expand Down
18 changes: 18 additions & 0 deletions modules/statics/src/coins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
beraErc20,
bscToken,
celoToken,
coredaoErc20,
eosToken,
erc1155,
erc20,
Expand All @@ -31,6 +32,7 @@ import {
tarbethErc20,
tberaErc20,
tceloToken,
tcoredaoErc20,
teosToken,
terc1155,
terc721,
Expand Down Expand Up @@ -2952,6 +2954,22 @@ export const coins = CoinMap.fromCoins([
'0x5bdc3cae6fb270ef07579c428bb630e73c8d623b',
UnderlyingAsset['tbera:ibera']
),
coredaoErc20(
'7dfd048f-7718-46e7-8cdb-864a3fc27b1b',
'coredao:stcore',
'stCore Token',
18,
'0xb3a8f0f0da9ffc65318aa39e55079796093029ad',
UnderlyingAsset['coredao:stcore']
),
tcoredaoErc20(
'b4448868-8beb-4dd8-b607-3b36e11f1df4',
'tcoredao:stcore',
'Testnet stCore token',
18,
'0x6401f24ef7c54032f4f54e67492928973ab87650',
UnderlyingAsset['tcoredao:stcore']
),
txrpToken(
'8ef16158-1015-4a67-b6fe-db669c18ab2b',
'txrp:tst-rP9jPyP5kyvFRb6ZiRghAGw5u8SGAmU4bd',
Expand Down
28 changes: 28 additions & 0 deletions modules/statics/src/tokenConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BeraERC20Token,
BscCoin,
CeloCoin,
CoredaoERC20Token,
EosCoin,
Erc1155Coin,
Erc20Coin,
Expand Down Expand Up @@ -138,6 +139,9 @@ export interface Tokens {
opeth: {
tokens: EthLikeTokenConfig[];
};
coredao: {
tokens: EthLikeTokenConfig[];
};
sol: {
tokens: SolTokenConfig[];
};
Expand Down Expand Up @@ -230,6 +234,9 @@ export interface Tokens {
bera: {
tokens: EthLikeTokenConfig[];
};
coredao: {
tokens: EthLikeTokenConfig[];
};
apt: {
tokens: AptTokenConfig[];
};
Expand Down Expand Up @@ -509,6 +516,21 @@ const getFormattedBeraTokens = (customCoinMap = coins) =>
return acc;
}, []);

const getFormattedCoredaoTokens = (customCoinMap = coins) =>
customCoinMap.reduce((acc: EthLikeTokenConfig[], coin) => {
if (coin instanceof CoredaoERC20Token) {
acc.push({
type: coin.name,
coin: coin.network.type === NetworkType.MAINNET ? 'coredao' : 'tcoredao',
network: coin.network.type === NetworkType.MAINNET ? 'Mainnet' : 'Testnet',
name: coin.fullName,
tokenContractAddress: coin.contractAddress.toString().toLowerCase(),
decimalPlaces: coin.decimalPlaces,
});
}
return acc;
}, []);

const getFormattedSolTokens = (customCoinMap = coins) =>
customCoinMap.reduce((acc: SolTokenConfig[], coin) => {
if (coin instanceof SolCoin) {
Expand Down Expand Up @@ -719,6 +741,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
bera: {
tokens: getFormattedBeraTokens(coinMap).filter((token) => token.network === 'Mainnet'),
},
coredao: {
tokens: getFormattedCoredaoTokens(coinMap).filter((token) => token.network === 'Mainnet'),
},
apt: {
tokens: getFormattedAptTokens(coinMap).filter((token) => token.network === 'Mainnet'),
},
Expand Down Expand Up @@ -795,6 +820,9 @@ export const getFormattedTokens = (coinMap = coins): Tokens => {
stx: {
tokens: getFormattedSip10Tokens(coinMap).filter((token) => token.network === 'Testnet'),
},
coredao: {
tokens: getFormattedCoredaoTokens(coinMap).filter((token) => token.network === 'Testnet'),
},
},
};
};
Expand Down