Skip to content

Commit ae706a0

Browse files
committed
feat(sdk-coin-coredao): add coredao sdk skeleton
Ticket: WIN-3696
1 parent c5a1da8 commit ae706a0

24 files changed

+512
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.idea
3+
public
4+
dist
5+

modules/sdk-coin-coredao/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
.idea/
3+
dist/

modules/sdk-coin-coredao/.mocharc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require: 'ts-node/register'
2+
timeout: '120000'
3+
reporter: 'min'
4+
reporter-option:
5+
- 'cdn=true'
6+
- 'json=false'
7+
exit: true
8+
spec: ['test/unit/**/*.ts']

modules/sdk-coin-coredao/.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
!dist/
2+
dist/test/
3+
dist/tsconfig.tsbuildinfo
4+
.idea/
5+
.prettierrc.yml
6+
tsconfig.json
7+
src/
8+
test/
9+
scripts/
10+
.nyc_output
11+
CODEOWNERS
12+
node_modules/
13+
.prettierignore
14+
.mocharc.js
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.nyc_output/
2+
dist/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
printWidth: 120
2+
singleQuote: true
3+
trailingComma: 'es5'

modules/sdk-coin-coredao/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BitGo sdk-coin-coredao
2+
3+
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.
4+
5+
## Installation
6+
7+
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.
8+
9+
In your project install both `@bitgo/sdk-api` and `@bitgo/sdk-coin-coredao`.
10+
11+
```shell
12+
npm i @bitgo/sdk-api @bitgo/sdk-coin-coredao
13+
```
14+
15+
Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`.
16+
17+
```javascript
18+
import { BitGoAPI } from '@bitgo/sdk-api';
19+
import { Coredao } from '@bitgo/sdk-coin-coredao';
20+
21+
const sdk = new BitGoAPI();
22+
23+
sdk.register('coredao', Coredao.createInstance);
24+
```
25+
26+
## Development
27+
28+
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.
29+
30+
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.

modules/sdk-coin-coredao/package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@bitgo/sdk-coin-coredao",
3+
"version": "1.0.0",
4+
"description": "BitGo SDK coin library for Coredao",
5+
"main": "./dist/src/index.js",
6+
"types": "./dist/src/index.d.ts",
7+
"scripts": {
8+
"build": "yarn tsc --build --incremental --verbose .",
9+
"fmt": "prettier --write .",
10+
"check-fmt": "prettier --check .",
11+
"clean": "rm -r ./dist",
12+
"lint": "eslint --quiet .",
13+
"prepare": "npm run build",
14+
"test": "npm run coverage",
15+
"coverage": "nyc -- npm run unit-test",
16+
"unit-test": "mocha"
17+
},
18+
"author": "BitGo SDK Team <[email protected]>",
19+
"license": "MIT",
20+
"engines": {
21+
"node": ">=18 <21"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/BitGo/BitGoJS.git",
26+
"directory": "modules/sdk-coin-coredao"
27+
},
28+
"lint-staged": {
29+
"*.{js,ts}": [
30+
"yarn prettier --write",
31+
"yarn eslint --fix"
32+
]
33+
},
34+
"publishConfig": {
35+
"access": "public"
36+
},
37+
"nyc": {
38+
"extension": [
39+
".ts"
40+
]
41+
},
42+
"dependencies": {
43+
"@bitgo/abstract-eth": "^22.3.1",
44+
"@bitgo/sdk-core": "^28.13.1",
45+
"@bitgo/statics": "^50.6.0",
46+
"@ethereumjs/common": "^2.6.5"
47+
},
48+
"devDependencies": {
49+
"@bitgo/sdk-api": "^1.56.3",
50+
"@bitgo/sdk-test": "^8.0.50"
51+
}
52+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { BaseCoin, BitGoBase, common, MPCAlgorithm } from '@bitgo/sdk-core';
2+
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
3+
import { AbstractEthLikeNewCoins, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';
4+
import { TransactionBuilder } from './lib';
5+
6+
export class Coredao extends AbstractEthLikeNewCoins {
7+
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
8+
super(bitgo, staticsCoin);
9+
}
10+
11+
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
12+
return new Coredao(bitgo, staticsCoin);
13+
}
14+
15+
protected getTransactionBuilder(): TransactionBuilder {
16+
return new TransactionBuilder(coins.get(this.getBaseChain()));
17+
}
18+
19+
/** @inheritDoc */
20+
allowsAccountConsolidations(): boolean {
21+
return true;
22+
}
23+
24+
/** @inheritDoc */
25+
supportsTss(): boolean {
26+
return true;
27+
}
28+
29+
/** @inheritDoc */
30+
getMPCAlgorithm(): MPCAlgorithm {
31+
return 'ecdsa';
32+
}
33+
34+
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<Record<string, unknown>> {
35+
const apiToken = common.Environments[this.bitgo.getEnv()].coredaoExplorerApiToken;
36+
const explorerUrl = common.Environments[this.bitgo.getEnv()].coredaoExplorerBaseUrl;
37+
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
38+
}
39+
}

modules/sdk-coin-coredao/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './lib';
2+
export * from './coredao';
3+
export * from './tcoredao';
4+
export * from './register';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as Utils from './utils';
2+
3+
export { TransactionBuilder } from './transactionBuilder';
4+
export { TransferBuilder } from './transferBuilder';
5+
export { Transaction, KeyPair } from '@bitgo/sdk-coin-eth';
6+
export { Utils };
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import EthereumCommon from '@ethereumjs/common';
2+
import { coins, EthereumNetwork } from '@bitgo/statics';
3+
4+
export const testnetCommon = EthereumCommon.custom(
5+
{
6+
name: 'testnet',
7+
networkId: (coins.get('tcoredao').network as EthereumNetwork).chainId,
8+
chainId: (coins.get('tcoredao').network as EthereumNetwork).chainId,
9+
},
10+
{
11+
baseChain: 'sepolia',
12+
hardfork: 'london',
13+
eips: [1559],
14+
}
15+
);
16+
17+
export const mainnetCommon = EthereumCommon.custom(
18+
{
19+
name: 'mainnet',
20+
networkId: (coins.get('coredao').network as EthereumNetwork).chainId,
21+
chainId: (coins.get('coredao').network as EthereumNetwork).chainId,
22+
},
23+
{
24+
baseChain: 'sepolia',
25+
hardfork: 'london',
26+
eips: [1559],
27+
}
28+
);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { BaseCoin as CoinConfig } from '@bitgo/statics';
2+
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core';
3+
import { TransactionBuilder as AbstractTransactionBuilder, Transaction } from '@bitgo/abstract-eth';
4+
import { getCommon } from './utils';
5+
import { TransferBuilder } from './transferBuilder';
6+
7+
export class TransactionBuilder extends AbstractTransactionBuilder {
8+
protected _transfer: TransferBuilder;
9+
10+
constructor(_coinConfig: Readonly<CoinConfig>) {
11+
super(_coinConfig);
12+
this._common = getCommon(this._coinConfig.network.type);
13+
this.transaction = new Transaction(this._coinConfig, this._common);
14+
}
15+
16+
/** @inheritdoc */
17+
transfer(data?: string): TransferBuilder {
18+
if (this._type !== TransactionType.Send) {
19+
throw new BuildTransactionError('Transfers can only be set for send transactions');
20+
}
21+
if (!this._transfer) {
22+
this._transfer = new TransferBuilder(data);
23+
}
24+
return this._transfer;
25+
}
26+
27+
protected getContractData(addresses: string[]): string {
28+
throw new Error('Method not implemented.');
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { TransferBuilder } from '@bitgo/abstract-eth';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { NetworkType } from '@bitgo/statics';
2+
import EthereumCommon from '@ethereumjs/common';
3+
import { InvalidTransactionError } from '@bitgo/sdk-core';
4+
import { testnetCommon, mainnetCommon } from './resources';
5+
6+
const commons: Map<NetworkType, EthereumCommon> = new Map<NetworkType, EthereumCommon>([
7+
[NetworkType.MAINNET, mainnetCommon],
8+
[NetworkType.TESTNET, testnetCommon],
9+
]);
10+
11+
/**
12+
* @param {NetworkType} network either mainnet or testnet
13+
* @returns {EthereumCommon} Ethereum common configuration object
14+
*/
15+
export function getCommon(network: NetworkType): EthereumCommon {
16+
const common = commons.get(network);
17+
if (!common) {
18+
throw new InvalidTransactionError('Missing network common configuration');
19+
}
20+
return common;
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { BitGoBase } from '@bitgo/sdk-core';
2+
import { Coredao } from './coredao';
3+
import { Tcoredao } from './tcoredao';
4+
5+
export const register = (sdk: BitGoBase): void => {
6+
sdk.register('coredao', Coredao.createInstance);
7+
sdk.register('tcoredao', Tcoredao.createInstance);
8+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Testnet Coredao
3+
*
4+
* @format
5+
*/
6+
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core';
7+
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics';
8+
import { Coredao } from './coredao';
9+
10+
export class Tcoredao extends Coredao {
11+
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
12+
super(bitgo, staticsCoin);
13+
}
14+
15+
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
16+
return new Tcoredao(bitgo, staticsCoin);
17+
}
18+
}

0 commit comments

Comments
 (0)