Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-coin-coredao): add coredao sdk skeleton #5121

Merged
merged 1 commit into from
Nov 18, 2024
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
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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 && \
Expand Down Expand Up @@ -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 && \
Expand Down
1 change: 1 addition & 0 deletions modules/account-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions modules/account-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -209,6 +212,8 @@ const coinBuilderMap = {
trune: Rune.TransactionBuilderFactory,
oas: Oas.TransactionBuilder,
toas: Oas.TransactionBuilder,
coredao: Coredao.TransactionBuilder,
tcoredao: Coredao.TransactionBuilder,
};

/**
Expand Down
3 changes: 3 additions & 0 deletions modules/account-lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
{
"path": "../sdk-coin-celo"
},
{
"path": "../sdk-coin-coredao"
},
{
"path": "../sdk-coin-coreum"
},
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
Btg,
Celo,
CeloToken,
Coredao,
Coreum,
Cspr,
Dash,
Expand Down Expand Up @@ -91,6 +92,7 @@ import {
Tbtc4,
Tbtcbgsig,
Tcelo,
Tcoredao,
Tcoreum,
Tcspr,
Tdash,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions modules/bitgo/src/v2/coins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 };
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
{
"path": "../sdk-coin-celo"
},
{
"path": "../sdk-coin-coredao"
},
{
"path": "../sdk-coin-coreum"
},
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-coredao/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.idea
public
dist

3 changes: 3 additions & 0 deletions modules/sdk-coin-coredao/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.idea/
dist/
8 changes: 8 additions & 0 deletions modules/sdk-coin-coredao/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require: 'ts-node/register'
timeout: '120000'
reporter: 'min'
reporter-option:
- 'cdn=true'
- 'json=false'
exit: true
spec: ['test/unit/**/*.ts']
14 changes: 14 additions & 0 deletions modules/sdk-coin-coredao/.npmignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions modules/sdk-coin-coredao/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output/
dist/
3 changes: 3 additions & 0 deletions modules/sdk-coin-coredao/.prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
printWidth: 120
singleQuote: true
trailingComma: 'es5'
30 changes: 30 additions & 0 deletions modules/sdk-coin-coredao/README.md
Original file line number Diff line number Diff line change
@@ -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.
52 changes: 52 additions & 0 deletions modules/sdk-coin-coredao/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"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"
}
}
34 changes: 34 additions & 0 deletions modules/sdk-coin-coredao/src/coredao.ts
Original file line number Diff line number Diff line change
@@ -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<StaticsBaseCoin>) {
super(bitgo, staticsCoin);
}

static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): 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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we not have some type of const that can be used instead of the hardcoded string?

}

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);
}
}
4 changes: 4 additions & 0 deletions modules/sdk-coin-coredao/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './lib';
export * from './coredao';
export * from './tcoredao';
export * from './register';
5 changes: 5 additions & 0 deletions modules/sdk-coin-coredao/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as Utils from './utils';

export { TransactionBuilder } from './transactionBuilder';
export { TransferBuilder } from './transferBuilder';
gianchandania marked this conversation as resolved.
Show resolved Hide resolved
export { Utils };
28 changes: 28 additions & 0 deletions modules/sdk-coin-coredao/src/lib/resources.ts
Original file line number Diff line number Diff line change
@@ -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],
}
);
30 changes: 30 additions & 0 deletions modules/sdk-coin-coredao/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
@@ -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<CoinConfig>) {
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.');
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-coredao/src/lib/transferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TransferBuilder } from '@bitgo/abstract-eth';
21 changes: 21 additions & 0 deletions modules/sdk-coin-coredao/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -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<NetworkType, EthereumCommon> = new Map<NetworkType, EthereumCommon>([
[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;
}
8 changes: 8 additions & 0 deletions modules/sdk-coin-coredao/src/register.ts
Original file line number Diff line number Diff line change
@@ -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);
};
Loading
Loading