From 0e6ce183f378968ea1453395ba28f7eb5ab26d96 Mon Sep 17 00:00:00 2001 From: Adarsh Ravichandran Date: Mon, 18 Nov 2024 09:04:26 +0530 Subject: [PATCH] feat(sdk-coin-coredao): add coredao sdk skeleton Ticket: WIN-3696 --- CODEOWNERS | 1 + Dockerfile | 3 ++ modules/account-lib/package.json | 1 + modules/account-lib/src/index.ts | 5 ++ modules/account-lib/tsconfig.json | 3 ++ modules/bitgo/package.json | 1 + modules/bitgo/src/v2/coinFactory.ts | 4 ++ modules/bitgo/src/v2/coins/index.ts | 2 + modules/bitgo/tsconfig.json | 3 ++ modules/sdk-coin-coredao/.eslintignore | 5 ++ modules/sdk-coin-coredao/.gitignore | 3 ++ modules/sdk-coin-coredao/.mocharc.yml | 8 +++ modules/sdk-coin-coredao/.npmignore | 14 +++++ modules/sdk-coin-coredao/.prettierignore | 2 + modules/sdk-coin-coredao/.prettierrc.yml | 3 ++ modules/sdk-coin-coredao/README.md | 30 +++++++++++ modules/sdk-coin-coredao/package.json | 52 +++++++++++++++++++ modules/sdk-coin-coredao/src/coredao.ts | 34 ++++++++++++ modules/sdk-coin-coredao/src/index.ts | 4 ++ modules/sdk-coin-coredao/src/lib/index.ts | 5 ++ modules/sdk-coin-coredao/src/lib/resources.ts | 28 ++++++++++ .../src/lib/transactionBuilder.ts | 30 +++++++++++ .../src/lib/transferBuilder.ts | 1 + modules/sdk-coin-coredao/src/lib/utils.ts | 21 ++++++++ modules/sdk-coin-coredao/src/register.ts | 8 +++ modules/sdk-coin-coredao/src/tcoredao.ts | 18 +++++++ modules/sdk-coin-coredao/test/unit/coredao.ts | 42 +++++++++++++++ .../sdk-coin-coredao/test/unit/getBuilder.ts | 6 +++ .../test/unit/transactionBuilder/send.ts | 16 ++++++ modules/sdk-coin-coredao/test/unit/utils.ts | 29 +++++++++++ modules/sdk-coin-coredao/tsconfig.json | 29 +++++++++++ modules/sdk-core/src/bitgo/environments.ts | 2 + modules/statics/src/networks.ts | 2 + tsconfig.packages.json | 3 ++ 34 files changed, 418 insertions(+) create mode 100644 modules/sdk-coin-coredao/.eslintignore create mode 100644 modules/sdk-coin-coredao/.gitignore create mode 100644 modules/sdk-coin-coredao/.mocharc.yml create mode 100644 modules/sdk-coin-coredao/.npmignore create mode 100644 modules/sdk-coin-coredao/.prettierignore create mode 100644 modules/sdk-coin-coredao/.prettierrc.yml create mode 100644 modules/sdk-coin-coredao/README.md create mode 100644 modules/sdk-coin-coredao/package.json create mode 100644 modules/sdk-coin-coredao/src/coredao.ts create mode 100644 modules/sdk-coin-coredao/src/index.ts create mode 100644 modules/sdk-coin-coredao/src/lib/index.ts create mode 100644 modules/sdk-coin-coredao/src/lib/resources.ts create mode 100644 modules/sdk-coin-coredao/src/lib/transactionBuilder.ts create mode 100644 modules/sdk-coin-coredao/src/lib/transferBuilder.ts create mode 100644 modules/sdk-coin-coredao/src/lib/utils.ts create mode 100644 modules/sdk-coin-coredao/src/register.ts create mode 100644 modules/sdk-coin-coredao/src/tcoredao.ts create mode 100644 modules/sdk-coin-coredao/test/unit/coredao.ts create mode 100644 modules/sdk-coin-coredao/test/unit/getBuilder.ts create mode 100644 modules/sdk-coin-coredao/test/unit/transactionBuilder/send.ts create mode 100644 modules/sdk-coin-coredao/test/unit/utils.ts create mode 100644 modules/sdk-coin-coredao/tsconfig.json diff --git a/CODEOWNERS b/CODEOWNERS index 10644714aa..abc965ec34 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -53,6 +53,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 97fca4b021..19a29f80dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -66,6 +66,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-bera /var/modules/sdk-coin-bera/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-bld /var/modules/sdk-coin-bld/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-bsc /var/modules/sdk-coin-bsc/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-celo /var/modules/sdk-coin-celo/ +COPY --from=builder /tmp/bitgo/modules/sdk-coin-coredao /var/modules/sdk-coin-coredao/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-coreum /var/modules/sdk-coin-coreum/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-cspr /var/modules/sdk-coin-cspr/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-dot /var/modules/sdk-coin-dot/ @@ -139,6 +140,7 @@ cd /var/modules/sdk-coin-bera && yarn link && \ cd /var/modules/sdk-coin-bld && yarn link && \ cd /var/modules/sdk-coin-bsc && yarn link && \ cd /var/modules/sdk-coin-celo && yarn link && \ +cd /var/modules/sdk-coin-coredao && yarn link && \ cd /var/modules/sdk-coin-coreum && yarn link && \ cd /var/modules/sdk-coin-cspr && yarn link && \ cd /var/modules/sdk-coin-dot && yarn link && \ @@ -215,6 +217,7 @@ RUN cd /var/bitgo-express && \ yarn link @bitgo/sdk-coin-bld && \ yarn link @bitgo/sdk-coin-bsc && \ yarn link @bitgo/sdk-coin-celo && \ + yarn link @bitgo/sdk-coin-coredao && \ yarn link @bitgo/sdk-coin-coreum && \ yarn link @bitgo/sdk-coin-cspr && \ yarn link @bitgo/sdk-coin-dot && \ diff --git a/modules/account-lib/package.json b/modules/account-lib/package.json index 5c31f71cda..09e4c2e75f 100644 --- a/modules/account-lib/package.json +++ b/modules/account-lib/package.json @@ -36,6 +36,7 @@ "@bitgo/sdk-coin-bld": "^3.0.15", "@bitgo/sdk-coin-bsc": "^22.1.30", "@bitgo/sdk-coin-celo": "^3.0.38", + "@bitgo/sdk-coin-coredao": "^1.0.0", "@bitgo/sdk-coin-coreum": "^21.0.15", "@bitgo/sdk-coin-cspr": "^2.0.46", "@bitgo/sdk-coin-dot": "^4.1.24", diff --git a/modules/account-lib/src/index.ts b/modules/account-lib/src/index.ts index 041e007f5f..86b74ac61e 100644 --- a/modules/account-lib/src/index.ts +++ b/modules/account-lib/src/index.ts @@ -137,6 +137,9 @@ export { zkEth }; import * as Oas from '@bitgo/sdk-coin-oas'; export { Oas }; +import * as Coredao from '@bitgo/sdk-coin-coredao'; +export { Coredao }; + const coinBuilderMap = { trx: Trx.WrappedBuilder, ttrx: Trx.WrappedBuilder, @@ -209,6 +212,8 @@ const coinBuilderMap = { trune: Rune.TransactionBuilderFactory, oas: Oas.TransactionBuilder, toas: Oas.TransactionBuilder, + coredao: Coredao.TransactionBuilder, + tcoredao: Coredao.TransactionBuilder, }; /** diff --git a/modules/account-lib/tsconfig.json b/modules/account-lib/tsconfig.json index 9e50ca6548..02fd6209e1 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 d6ff4d9d0c..9992c63aa6 100644 --- a/modules/bitgo/package.json +++ b/modules/bitgo/package.json @@ -65,6 +65,7 @@ "@bitgo/sdk-coin-btc": "^2.3.7", "@bitgo/sdk-coin-btg": "^2.0.46", "@bitgo/sdk-coin-celo": "^3.0.38", + "@bitgo/sdk-coin-coredao": "^1.0.0", "@bitgo/sdk-coin-coreum": "^21.0.15", "@bitgo/sdk-coin-cspr": "^2.0.46", "@bitgo/sdk-coin-dash": "^2.0.46", diff --git a/modules/bitgo/src/v2/coinFactory.ts b/modules/bitgo/src/v2/coinFactory.ts index d25334a125..971c30718c 100644 --- a/modules/bitgo/src/v2/coinFactory.ts +++ b/modules/bitgo/src/v2/coinFactory.ts @@ -31,6 +31,7 @@ import { Btg, Celo, CeloToken, + Coredao, Coreum, Cspr, Dash, @@ -91,6 +92,7 @@ import { Tbtc4, Tbtcbgsig, Tcelo, + Tcoredao, Tcoreum, Tcspr, Tdash, @@ -158,6 +160,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); @@ -214,6 +217,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 0621e62902..58330345cc 100644 --- a/modules/bitgo/src/v2/coins/index.ts +++ b/modules/bitgo/src/v2/coins/index.ts @@ -16,6 +16,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'; @@ -69,6 +70,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 b26435eedb..fe18f75b46 100644 --- a/modules/bitgo/tsconfig.json +++ b/modules/bitgo/tsconfig.json @@ -86,6 +86,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..df229e637c --- /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.2", + "@bitgo/sdk-core": "^28.13.2", + "@bitgo/statics": "^50.7.0", + "@ethereumjs/common": "^2.6.5" + }, + "devDependencies": { + "@bitgo/sdk-api": "^1.56.4", + "@bitgo/sdk-test": "^8.0.51" + } +} 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 afa31e3871..c29ba5d22c 100644 --- a/modules/sdk-core/src/bitgo/environments.ts +++ b/modules/sdk-core/src/bitgo/environments.ts @@ -55,6 +55,8 @@ interface EnvironmentTemplate { hmacVerificationEnforced: boolean; suiNodeUrl: string; etcNodeUrl: string; + coredaoExplorerBaseUrl?: string; + coredaoExplorerApiToken?: string; } export interface Environment extends EnvironmentTemplate { diff --git a/modules/statics/src/networks.ts b/modules/statics/src/networks.ts index 86f84bc464..671ee12f36 100644 --- a/modules/statics/src/networks.ts +++ b/modules/statics/src/networks.ts @@ -1095,6 +1095,8 @@ class Coredao extends Mainnet implements EthereumNetwork { accountExplorerUrl = 'https://scan.coredao.org/address/'; chainId = 1116; nativeCoinOperationHashPrefix = '1116'; + forwarderFactoryAddress = '0x37996e762fa8b671869740c79eb33f625b3bf92a'; + forwarderImplementationAddress = '0xd5fe1c1f216b775dfd30638fa7164d41321ef79b'; } class CoredaoTestnet extends Testnet implements EthereumNetwork { diff --git a/tsconfig.packages.json b/tsconfig.packages.json index aca8f6d87a..ae168fd631 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -82,6 +82,9 @@ { "path": "./modules/sdk-coin-celo" }, + { + "path": "./modules/sdk-coin-coredao" + }, { "path": "./modules/sdk-coin-coreum" },