diff --git a/CODEOWNERS b/CODEOWNERS index 1ed00c2a3e..7f7acf9b50 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -52,6 +52,7 @@ /modules/sdk-coin-avaxc/ @BitGo/ethalt-team /modules/sdk-coin-avaxp/ @BitGo/ethalt-team /modules/sdk-coin-bsc/ @BitGo/ethalt-team +/modules/sdk-coin-coredao/ @BitGo/ethalt-team /modules/sdk-coin-cspr/ @BitGo/ethalt-team /modules/sdk-coin-dot/ @BitGo/ethalt-team /modules/sdk-coin-eos/ @BitGo/ethalt-team diff --git a/Dockerfile b/Dockerfile index 3597de6c8f..60f74135c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-hbar /var/modules/sdk-coin-hbar/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-injective /var/modules/sdk-coin-injective/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-islm /var/modules/sdk-coin-islm/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-near /var/modules/sdk-coin-near/ +COPY --from=builder /tmp/bitgo/modules/sdk-coin-coredao /var/modules/sdk-coin-coredao/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-opeth /var/modules/sdk-coin-opeth/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-osmo /var/modules/sdk-coin-osmo/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-polygon /var/modules/sdk-coin-polygon/ @@ -147,6 +148,7 @@ cd /var/modules/sdk-coin-hbar && yarn link && \ cd /var/modules/sdk-coin-injective && yarn link && \ cd /var/modules/sdk-coin-islm && yarn link && \ cd /var/modules/sdk-coin-near && yarn link && \ +cd /var/modules/sdk-coin-coredao && yarn link && \ cd /var/modules/sdk-coin-opeth && yarn link && \ cd /var/modules/sdk-coin-osmo && yarn link && \ cd /var/modules/sdk-coin-polygon && yarn link && \ @@ -221,6 +223,7 @@ RUN cd /var/bitgo-express && \ yarn link @bitgo/sdk-coin-injective && \ yarn link @bitgo/sdk-coin-islm && \ yarn link @bitgo/sdk-coin-near && \ + yarn link @bitgo/sdk-coin-coredao && \ yarn link @bitgo/sdk-coin-opeth && \ yarn link @bitgo/sdk-coin-osmo && \ yarn link @bitgo/sdk-coin-polygon && \ diff --git a/modules/account-lib/package.json b/modules/account-lib/package.json index 3f46bb13a0..a494cc18a1 100644 --- a/modules/account-lib/package.json +++ b/modules/account-lib/package.json @@ -36,6 +36,7 @@ "@bitgo/sdk-coin-bld": "^3.0.14", "@bitgo/sdk-coin-bsc": "^22.1.29", "@bitgo/sdk-coin-celo": "^3.0.37", + "@bitgo/sdk-coin-coredao": "^1.0.0", "@bitgo/sdk-coin-coreum": "^21.0.14", "@bitgo/sdk-coin-cspr": "^2.0.45", "@bitgo/sdk-coin-dot": "^4.1.23", diff --git a/modules/account-lib/src/index.ts b/modules/account-lib/src/index.ts index 45d4771ee9..ac4370694f 100644 --- a/modules/account-lib/src/index.ts +++ b/modules/account-lib/src/index.ts @@ -134,6 +134,9 @@ export { XRP }; import * as zkEth from '@bitgo/sdk-coin-zketh'; export { zkEth }; +import * as Coredao from '@bitgo/sdk-coin-coredao'; +export { Coredao }; + const coinBuilderMap = { trx: Trx.WrappedBuilder, ttrx: Trx.WrappedBuilder, @@ -204,6 +207,8 @@ const coinBuilderMap = { tbera: Bera.TransactionBuilder, rune: Rune.TransactionBuilderFactory, trune: Rune.TransactionBuilderFactory, + coredao: Coredao.TransactionBuilder, + tcoredao: Coredao.TransactionBuilder, }; /** diff --git a/modules/account-lib/tsconfig.json b/modules/account-lib/tsconfig.json index 42b7d6451c..942379200c 100644 --- a/modules/account-lib/tsconfig.json +++ b/modules/account-lib/tsconfig.json @@ -34,6 +34,9 @@ { "path": "../sdk-coin-celo" }, + { + "path": "../sdk-coin-coredao" + }, { "path": "../sdk-coin-coreum" }, diff --git a/modules/bitgo/package.json b/modules/bitgo/package.json index f5a93ab64e..eb29286a2c 100644 --- a/modules/bitgo/package.json +++ b/modules/bitgo/package.json @@ -64,6 +64,7 @@ "@bitgo/sdk-coin-btc": "^2.3.6", "@bitgo/sdk-coin-btg": "^2.0.45", "@bitgo/sdk-coin-celo": "^3.0.37", + "@bitgo/sdk-coin-coredao": "^1.0.0", "@bitgo/sdk-coin-coreum": "^21.0.14", "@bitgo/sdk-coin-cspr": "^2.0.45", "@bitgo/sdk-coin-dash": "^2.0.45", diff --git a/modules/bitgo/src/v2/coinFactory.ts b/modules/bitgo/src/v2/coinFactory.ts index cc5344303a..30405adb1e 100644 --- a/modules/bitgo/src/v2/coinFactory.ts +++ b/modules/bitgo/src/v2/coinFactory.ts @@ -30,6 +30,7 @@ import { Btg, Celo, CeloToken, + Coredao, Coreum, Cspr, Dash, @@ -88,6 +89,7 @@ import { Tbtc4, Tbtcbgsig, Tcelo, + Tcoredao, Tcoreum, Tcspr, Tdash, @@ -153,6 +155,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void { globalCoinFactory.register('btc', Btc.createInstance); globalCoinFactory.register('btg', Btg.createInstance); globalCoinFactory.register('celo', Celo.createInstance); + globalCoinFactory.register('coredao', Coredao.createInstance); globalCoinFactory.register('coreum', Coreum.createInstance); globalCoinFactory.register('cspr', Cspr.createInstance); globalCoinFactory.register('dash', Dash.createInstance); @@ -207,6 +210,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void { globalCoinFactory.register('tbtc4', Tbtc4.createInstance); globalCoinFactory.register('tbtcbgsig', Tbtcbgsig.createInstance); globalCoinFactory.register('tcelo', Tcelo.createInstance); + globalCoinFactory.register('tcoredao', Tcoredao.createInstance); globalCoinFactory.register('tcoreum', Tcoreum.createInstance); globalCoinFactory.register('tcspr', Tcspr.createInstance); globalCoinFactory.register('tdash', Tdash.createInstance); diff --git a/modules/bitgo/src/v2/coins/index.ts b/modules/bitgo/src/v2/coins/index.ts index 23fe90dcb4..874b58a662 100644 --- a/modules/bitgo/src/v2/coins/index.ts +++ b/modules/bitgo/src/v2/coins/index.ts @@ -15,6 +15,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 { Coreum, Tcoreum } from '@bitgo/sdk-coin-coreum'; import { Cspr, Tcspr } from '@bitgo/sdk-coin-cspr'; import { Dash, Tdash } from '@bitgo/sdk-coin-dash'; @@ -66,6 +67,7 @@ export { Bsv, Tbsv }; export { Btc, Tbtc, Tbtcsig, Tbtc4, Tbtcbgsig }; export { Btg }; export { Celo, CeloToken, Tcelo }; +export { Coredao, Tcoredao }; export { Coreum, Tcoreum }; export { Cspr, Tcspr }; export { Dash, Tdash }; diff --git a/modules/bitgo/tsconfig.json b/modules/bitgo/tsconfig.json index cb41ab01da..60244c31b8 100644 --- a/modules/bitgo/tsconfig.json +++ b/modules/bitgo/tsconfig.json @@ -83,6 +83,9 @@ { "path": "../sdk-coin-celo" }, + { + "path": "../sdk-coin-coredao" + }, { "path": "../sdk-coin-coreum" }, diff --git a/modules/sdk-coin-coredao/.eslintignore b/modules/sdk-coin-coredao/.eslintignore new file mode 100644 index 0000000000..190f83e0df --- /dev/null +++ b/modules/sdk-coin-coredao/.eslintignore @@ -0,0 +1,5 @@ +node_modules +.idea +public +dist + diff --git a/modules/sdk-coin-coredao/.gitignore b/modules/sdk-coin-coredao/.gitignore new file mode 100644 index 0000000000..67ccce4c64 --- /dev/null +++ b/modules/sdk-coin-coredao/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.idea/ +dist/ diff --git a/modules/sdk-coin-coredao/.mocharc.yml b/modules/sdk-coin-coredao/.mocharc.yml new file mode 100644 index 0000000000..7b4b0d51f4 --- /dev/null +++ b/modules/sdk-coin-coredao/.mocharc.yml @@ -0,0 +1,8 @@ +require: 'ts-node/register' +timeout: '120000' +reporter: 'min' +reporter-option: + - 'cdn=true' + - 'json=false' +exit: true +spec: ['test/unit/**/*.ts'] diff --git a/modules/sdk-coin-coredao/.npmignore b/modules/sdk-coin-coredao/.npmignore new file mode 100644 index 0000000000..d5fb3a098c --- /dev/null +++ b/modules/sdk-coin-coredao/.npmignore @@ -0,0 +1,14 @@ +!dist/ +dist/test/ +dist/tsconfig.tsbuildinfo +.idea/ +.prettierrc.yml +tsconfig.json +src/ +test/ +scripts/ +.nyc_output +CODEOWNERS +node_modules/ +.prettierignore +.mocharc.js diff --git a/modules/sdk-coin-coredao/.prettierignore b/modules/sdk-coin-coredao/.prettierignore new file mode 100644 index 0000000000..3a11d6af29 --- /dev/null +++ b/modules/sdk-coin-coredao/.prettierignore @@ -0,0 +1,2 @@ +.nyc_output/ +dist/ diff --git a/modules/sdk-coin-coredao/.prettierrc.yml b/modules/sdk-coin-coredao/.prettierrc.yml new file mode 100644 index 0000000000..7c3d8dd32a --- /dev/null +++ b/modules/sdk-coin-coredao/.prettierrc.yml @@ -0,0 +1,3 @@ +printWidth: 120 +singleQuote: true +trailingComma: 'es5' diff --git a/modules/sdk-coin-coredao/README.md b/modules/sdk-coin-coredao/README.md new file mode 100644 index 0000000000..8c1c9589a9 --- /dev/null +++ b/modules/sdk-coin-coredao/README.md @@ -0,0 +1,30 @@ +# BitGo sdk-coin-coredao + +SDK coins provide a modular approach to a monolithic architecture. This and all BitGoJS SDK coins allow developers to use only the coins needed for a given project. + +## Installation + +All coins are loaded traditionally through the `bitgo` package. If you are using coins individually, you will be accessing the coin via the `@bitgo/sdk-api` package. + +In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-coredao`. + +```shell +npm i @bitgo/sdk-api @bitgo/sdk-coin-coredao +``` + +Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`. + +```javascript +import { BitGoAPI } from '@bitgo/sdk-api'; +import { Coredao } from '@bitgo/sdk-coin-coredao'; + +const sdk = new BitGoAPI(); + +sdk.register('coredao', Coredao.createInstance); +``` + +## Development + +Most of the coin implementations are derived from `@bitgo/sdk-core`, `@bitgo/statics`, and coin specific packages. These implementations are used to interact with the BitGo API and BitGo platform services. + +You will notice that the basic version of common class extensions have been provided to you and must be resolved before the package build will succeed. Upon initiation of a given SDK coin, you will need to verify that your coin has been included in the root `tsconfig.packages.json` and that the linting, formatting, and testing succeeds when run both within the coin and from the root of BitGoJS. diff --git a/modules/sdk-coin-coredao/package.json b/modules/sdk-coin-coredao/package.json new file mode 100644 index 0000000000..2784ee8fba --- /dev/null +++ b/modules/sdk-coin-coredao/package.json @@ -0,0 +1,52 @@ +{ + "name": "@bitgo/sdk-coin-coredao", + "version": "1.0.0", + "description": "BitGo SDK coin library for Coredao", + "main": "./dist/src/index.js", + "types": "./dist/src/index.d.ts", + "scripts": { + "build": "yarn tsc --build --incremental --verbose .", + "fmt": "prettier --write .", + "check-fmt": "prettier --check .", + "clean": "rm -r ./dist", + "lint": "eslint --quiet .", + "prepare": "npm run build", + "test": "npm run coverage", + "coverage": "nyc -- npm run unit-test", + "unit-test": "mocha" + }, + "author": "BitGo SDK Team ", + "license": "MIT", + "engines": { + "node": ">=18 <21" + }, + "repository": { + "type": "git", + "url": "https://github.com/BitGo/BitGoJS.git", + "directory": "modules/sdk-coin-coredao" + }, + "lint-staged": { + "*.{js,ts}": [ + "yarn prettier --write", + "yarn eslint --fix" + ] + }, + "publishConfig": { + "access": "public" + }, + "nyc": { + "extension": [ + ".ts" + ] + }, + "dependencies": { + "@bitgo/abstract-eth": "^22.3.1", + "@bitgo/sdk-core": "^28.13.1", + "@bitgo/statics": "^50.6.0", + "@ethereumjs/common": "^2.6.5" + }, + "devDependencies": { + "@bitgo/sdk-api": "^1.56.3", + "@bitgo/sdk-test": "^8.0.50" + } +} diff --git a/modules/sdk-coin-coredao/src/coredao.ts b/modules/sdk-coin-coredao/src/coredao.ts new file mode 100644 index 0000000000..ba81cc8fe5 --- /dev/null +++ b/modules/sdk-coin-coredao/src/coredao.ts @@ -0,0 +1,34 @@ +import { BaseCoin, BitGoBase, common, MPCAlgorithm } from '@bitgo/sdk-core'; +import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics'; +import { AbstractEthLikeNewCoins, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth'; +import { TransactionBuilder } from './lib'; + +export class Coredao extends AbstractEthLikeNewCoins { + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly) { + super(bitgo, staticsCoin); + } + + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly): BaseCoin { + return new Coredao(bitgo, staticsCoin); + } + + protected getTransactionBuilder(): TransactionBuilder { + return new TransactionBuilder(coins.get(this.getBaseChain())); + } + + /** @inheritDoc */ + supportsTss(): boolean { + return true; + } + + /** @inheritDoc */ + getMPCAlgorithm(): MPCAlgorithm { + return 'ecdsa'; + } + + async recoveryBlockchainExplorerQuery(query: Record): Promise> { + const apiToken = common.Environments[this.bitgo.getEnv()].coredaoExplorerApiToken; + const explorerUrl = common.Environments[this.bitgo.getEnv()].coredaoExplorerBaseUrl; + return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken); + } +} diff --git a/modules/sdk-coin-coredao/src/index.ts b/modules/sdk-coin-coredao/src/index.ts new file mode 100644 index 0000000000..efd5a700da --- /dev/null +++ b/modules/sdk-coin-coredao/src/index.ts @@ -0,0 +1,4 @@ +export * from './lib'; +export * from './coredao'; +export * from './tcoredao'; +export * from './register'; diff --git a/modules/sdk-coin-coredao/src/lib/index.ts b/modules/sdk-coin-coredao/src/lib/index.ts new file mode 100644 index 0000000000..838a26ae4e --- /dev/null +++ b/modules/sdk-coin-coredao/src/lib/index.ts @@ -0,0 +1,5 @@ +import * as Utils from './utils'; + +export { TransactionBuilder } from './transactionBuilder'; +export { TransferBuilder } from './transferBuilder'; +export { Utils }; diff --git a/modules/sdk-coin-coredao/src/lib/resources.ts b/modules/sdk-coin-coredao/src/lib/resources.ts new file mode 100644 index 0000000000..dcdeddfdcb --- /dev/null +++ b/modules/sdk-coin-coredao/src/lib/resources.ts @@ -0,0 +1,28 @@ +import EthereumCommon from '@ethereumjs/common'; +import { coins, EthereumNetwork } from '@bitgo/statics'; + +export const testnetCommon = EthereumCommon.custom( + { + name: 'coredao testnet', + networkId: (coins.get('tcoredao').network as EthereumNetwork).chainId, + chainId: (coins.get('tcoredao').network as EthereumNetwork).chainId, + }, + { + baseChain: 'sepolia', + hardfork: 'london', + eips: [1559], + } +); + +export const mainnetCommon = EthereumCommon.custom( + { + name: 'coredao mainnet', + networkId: (coins.get('coredao').network as EthereumNetwork).chainId, + chainId: (coins.get('coredao').network as EthereumNetwork).chainId, + }, + { + baseChain: 'mainnet', + hardfork: 'london', + eips: [1559], + } +); diff --git a/modules/sdk-coin-coredao/src/lib/transactionBuilder.ts b/modules/sdk-coin-coredao/src/lib/transactionBuilder.ts new file mode 100644 index 0000000000..1232e4f26b --- /dev/null +++ b/modules/sdk-coin-coredao/src/lib/transactionBuilder.ts @@ -0,0 +1,30 @@ +import { BaseCoin as CoinConfig } from '@bitgo/statics'; +import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core'; +import { TransactionBuilder as AbstractTransactionBuilder, Transaction } from '@bitgo/abstract-eth'; +import { getCommon } from './utils'; +import { TransferBuilder } from './transferBuilder'; + +export class TransactionBuilder extends AbstractTransactionBuilder { + protected _transfer: TransferBuilder; + + constructor(_coinConfig: Readonly) { + super(_coinConfig); + this._common = getCommon(this._coinConfig.network.type); + this.transaction = new Transaction(this._coinConfig, this._common); + } + + /** @inheritdoc */ + transfer(data?: string): TransferBuilder { + if (this._type !== TransactionType.Send) { + throw new BuildTransactionError('Transfers can only be set for send transactions'); + } + if (!this._transfer) { + this._transfer = new TransferBuilder(data); + } + return this._transfer; + } + + protected getContractData(addresses: string[]): string { + throw new Error('Method not implemented.'); + } +} diff --git a/modules/sdk-coin-coredao/src/lib/transferBuilder.ts b/modules/sdk-coin-coredao/src/lib/transferBuilder.ts new file mode 100644 index 0000000000..7447c0cf3d --- /dev/null +++ b/modules/sdk-coin-coredao/src/lib/transferBuilder.ts @@ -0,0 +1 @@ +export { TransferBuilder } from '@bitgo/abstract-eth'; diff --git a/modules/sdk-coin-coredao/src/lib/utils.ts b/modules/sdk-coin-coredao/src/lib/utils.ts new file mode 100644 index 0000000000..dc81fa08f9 --- /dev/null +++ b/modules/sdk-coin-coredao/src/lib/utils.ts @@ -0,0 +1,21 @@ +import { NetworkType } from '@bitgo/statics'; +import EthereumCommon from '@ethereumjs/common'; +import { InvalidTransactionError } from '@bitgo/sdk-core'; +import { testnetCommon, mainnetCommon } from './resources'; + +const commons: Map = new Map([ + [NetworkType.MAINNET, mainnetCommon], + [NetworkType.TESTNET, testnetCommon], +]); + +/** + * @param {NetworkType} network either mainnet or testnet + * @returns {EthereumCommon} Ethereum common configuration object + */ +export function getCommon(network: NetworkType): EthereumCommon { + const common = commons.get(network); + if (!common) { + throw new InvalidTransactionError('Missing network common configuration'); + } + return common; +} diff --git a/modules/sdk-coin-coredao/src/register.ts b/modules/sdk-coin-coredao/src/register.ts new file mode 100644 index 0000000000..ccdabfa987 --- /dev/null +++ b/modules/sdk-coin-coredao/src/register.ts @@ -0,0 +1,8 @@ +import { BitGoBase } from '@bitgo/sdk-core'; +import { Coredao } from './coredao'; +import { Tcoredao } from './tcoredao'; + +export const register = (sdk: BitGoBase): void => { + sdk.register('coredao', Coredao.createInstance); + sdk.register('tcoredao', Tcoredao.createInstance); +}; diff --git a/modules/sdk-coin-coredao/src/tcoredao.ts b/modules/sdk-coin-coredao/src/tcoredao.ts new file mode 100644 index 0000000000..291aaef904 --- /dev/null +++ b/modules/sdk-coin-coredao/src/tcoredao.ts @@ -0,0 +1,18 @@ +/** + * Testnet Coredao + * + * @format + */ +import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; +import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; +import { Coredao } from './coredao'; + +export class Tcoredao extends Coredao { + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly) { + super(bitgo, staticsCoin); + } + + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly): BaseCoin { + return new Tcoredao(bitgo, staticsCoin); + } +} diff --git a/modules/sdk-coin-coredao/test/unit/coredao.ts b/modules/sdk-coin-coredao/test/unit/coredao.ts new file mode 100644 index 0000000000..b332baaebf --- /dev/null +++ b/modules/sdk-coin-coredao/test/unit/coredao.ts @@ -0,0 +1,42 @@ +import 'should'; + +import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; +import { BitGoAPI } from '@bitgo/sdk-api'; + +import { Coredao, Tcoredao } from '../../src/index'; + +const bitgo: TestBitGoAPI = TestBitGo.decorate(BitGoAPI, { env: 'test' }); + +describe('Coredao', function () { + before(function () { + bitgo.safeRegister('coredao', Coredao.createInstance); + bitgo.safeRegister('tcoredao', Tcoredao.createInstance); + bitgo.initializeTestVars(); + }); + + describe('Basic Coin Info', function () { + it('should return the right info for coredao', function () { + const coredao = bitgo.coin('coredao'); + + coredao.should.be.an.instanceof(Coredao); + coredao.getChain().should.equal('coredao'); + coredao.getFamily().should.equal('coredao'); + coredao.getFullName().should.equal('coredaochain'); + coredao.getBaseFactor().should.equal(1e18); + coredao.supportsTss().should.equal(true); + coredao.allowsAccountConsolidations().should.equal(false); + }); + + it('should return the right info for tcoredao', function () { + const tcoredao = bitgo.coin('tcoredao'); + + tcoredao.should.be.an.instanceof(Tcoredao); + tcoredao.getChain().should.equal('tcoredao'); + tcoredao.getFamily().should.equal('coredao'); + tcoredao.getFullName().should.equal('Testnet coredao chain'); + tcoredao.getBaseFactor().should.equal(1e18); + tcoredao.supportsTss().should.equal(true); + tcoredao.allowsAccountConsolidations().should.equal(false); + }); + }); +}); diff --git a/modules/sdk-coin-coredao/test/unit/getBuilder.ts b/modules/sdk-coin-coredao/test/unit/getBuilder.ts new file mode 100644 index 0000000000..261b490989 --- /dev/null +++ b/modules/sdk-coin-coredao/test/unit/getBuilder.ts @@ -0,0 +1,6 @@ +import { TransactionBuilder } from '../../src'; +import { coins } from '@bitgo/statics'; + +export const getBuilder = (coin: string): TransactionBuilder => { + return new TransactionBuilder(coins.get(coin)); +}; diff --git a/modules/sdk-coin-coredao/test/unit/transactionBuilder/send.ts b/modules/sdk-coin-coredao/test/unit/transactionBuilder/send.ts new file mode 100644 index 0000000000..12b780365f --- /dev/null +++ b/modules/sdk-coin-coredao/test/unit/transactionBuilder/send.ts @@ -0,0 +1,16 @@ +import { getBuilder } from '../getBuilder'; +import should from 'should'; + +describe('Coredao Transfer Builder', () => { + describe('Build from TxHex', function () { + it('Should successfully build from txHex', async function () { + const txBuilder = getBuilder('tcoredao'); + const txHex = + '0x02f86482045b010102825208944943dd2a2494e3ea5937954cb836692a047695b50180c080a0a967298f91f5c8bb735a0837e68cb43d6541f987028b60a10a165f55bca0eda6a04266fc6f2b7b1c55636bbcc2552fbe18930cf0a483ba85d2fa496fe3042f1796'; + txBuilder.from(txHex); + const parsedTx = await txBuilder.build(); + + should.exist(parsedTx.toJson()); + }); + }); +}); diff --git a/modules/sdk-coin-coredao/test/unit/utils.ts b/modules/sdk-coin-coredao/test/unit/utils.ts new file mode 100644 index 0000000000..61c63e42ab --- /dev/null +++ b/modules/sdk-coin-coredao/test/unit/utils.ts @@ -0,0 +1,29 @@ +import assert from 'assert'; +import should from 'should'; +import { NetworkType } from '@bitgo/statics'; +import { getCommon } from '../../src/lib/utils'; + +describe('Network Common Configuration', () => { + it('getCommon for mainnet', () => { + const common = getCommon(NetworkType.MAINNET); + should.equal(common.chainName(), 'coredao mainnet'); + should.equal(common.hardfork(), 'london'); + should.equal(common.chainIdBN().toString(), '1116'); + should.equal(common.networkIdBN().toString(), '1116'); + }); + + it('getCommon for testnet', () => { + const common = getCommon(NetworkType.TESTNET); + should.equal(common.chainName(), 'coredao testnet'); + should.equal(common.hardfork(), 'london'); + should.equal(common.chainIdBN().toString(), '1115'); + should.equal(common.networkIdBN().toString(), '1115'); + }); + + it('getCommon for invalid network', () => { + assert.throws( + () => getCommon('invalidNetwork' as NetworkType), + (e: any) => e.message === 'Missing network common configuration' + ); + }); +}); diff --git a/modules/sdk-coin-coredao/tsconfig.json b/modules/sdk-coin-coredao/tsconfig.json new file mode 100644 index 0000000000..52c51f35c6 --- /dev/null +++ b/modules/sdk-coin-coredao/tsconfig.json @@ -0,0 +1,29 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./", + "strictPropertyInitialization": false, + "esModuleInterop": true, + "typeRoots": ["../../types", "./node_modules/@types", "../../node_modules/@types"] + }, + "include": ["src/**/*", "test/**/*"], + "exclude": ["node_modules"], + "references": [ + { + "path": "../abstract-eth" + }, + { + "path": "../sdk-api" + }, + { + "path": "../sdk-core" + }, + { + "path": "../statics" + }, + { + "path": "../sdk-test" + } + ] +} diff --git a/modules/sdk-core/src/bitgo/environments.ts b/modules/sdk-core/src/bitgo/environments.ts index 525bcba540..964a20f08f 100644 --- a/modules/sdk-core/src/bitgo/environments.ts +++ b/modules/sdk-core/src/bitgo/environments.ts @@ -53,6 +53,8 @@ interface EnvironmentTemplate { hmacVerificationEnforced: boolean; suiNodeUrl: string; etcNodeUrl: string; + coredaoExplorerBaseUrl?: string; + coredaoExplorerApiToken?: string; } export interface Environment extends EnvironmentTemplate { diff --git a/tsconfig.packages.json b/tsconfig.packages.json index add1de9760..f67ed65714 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -79,6 +79,9 @@ { "path": "./modules/sdk-coin-celo" }, + { + "path": "./modules/sdk-coin-coredao" + }, { "path": "./modules/sdk-coin-coreum" },