Skip to content

Commit

Permalink
chore(sdk-coin-bnb): create new bnb module
Browse files Browse the repository at this point in the history
Ticket: EA-709
  • Loading branch information
kxl4126 committed Jul 7, 2023
1 parent 9bff0a9 commit 080e789
Show file tree
Hide file tree
Showing 46 changed files with 829 additions and 10 deletions.
13 changes: 8 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-hash /var/modules/sdk-coin-hash/
RUN cd /var/modules/sdk-coin-hash && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-hbar /var/modules/sdk-coin-hbar/
RUN cd /var/modules/sdk-coin-hbar && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-injective /var/modules/sdk-coin-injective/
RUN cd /var/modules/sdk-coin-injective && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-near /var/modules/sdk-coin-near/
RUN cd /var/modules/sdk-coin-near && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-osmo /var/modules/sdk-coin-osmo/
Expand Down Expand Up @@ -126,6 +128,8 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-bch /var/modules/sdk-coin-bch/
RUN cd /var/modules/sdk-coin-bch && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-bcha /var/modules/sdk-coin-bcha/
RUN cd /var/modules/sdk-coin-bcha && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-bnb /var/modules/sdk-coin-bnb/
RUN cd /var/modules/sdk-coin-bnb && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-bsv /var/modules/sdk-coin-bsv/
RUN cd /var/modules/sdk-coin-bsv && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-btc /var/modules/sdk-coin-btc/
Expand All @@ -142,8 +146,6 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-eos /var/modules/sdk-coin-eos/
RUN cd /var/modules/sdk-coin-eos && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ethw /var/modules/sdk-coin-ethw/
RUN cd /var/modules/sdk-coin-ethw && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-injective /var/modules/sdk-coin-injective/
RUN cd /var/modules/sdk-coin-injective && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ltc /var/modules/sdk-coin-ltc/
RUN cd /var/modules/sdk-coin-ltc && yarn link
COPY --from=builder /tmp/bitgo/modules/sdk-coin-xlm /var/modules/sdk-coin-xlm/
Expand Down Expand Up @@ -186,6 +188,7 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-eth2 && \
yarn link @bitgo/sdk-coin-hash && \
yarn link @bitgo/sdk-coin-hbar && \
yarn link @bitgo/sdk-coin-injective && \
yarn link @bitgo/sdk-coin-near && \
yarn link @bitgo/sdk-coin-osmo && \
yarn link @bitgo/sdk-coin-polygon && \
Expand All @@ -200,6 +203,7 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-ada && \
yarn link @bitgo/sdk-coin-bch && \
yarn link @bitgo/sdk-coin-bcha && \
yarn link @bitgo/sdk-coin-bnb && \
yarn link @bitgo/sdk-coin-bsv && \
yarn link @bitgo/sdk-coin-btc && \
yarn link @bitgo/utxo-ord && \
Expand All @@ -208,17 +212,16 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/sdk-coin-doge && \
yarn link @bitgo/sdk-coin-eos && \
yarn link @bitgo/sdk-coin-ethw && \
yarn link @bitgo/sdk-coin-injective && \
yarn link @bitgo/sdk-coin-ltc && \
yarn link @bitgo/sdk-coin-xlm && \
yarn link @bitgo/sdk-coin-xrp && \
yarn link @bitgo/sdk-coin-zec
#LINK_END

#LABEL_START
LABEL created="Thu, 22 Jun 2023 18:10:16 GMT"
LABEL created="Mon, 03 Jul 2023 18:46:35 GMT"
LABEL version=9.29.0
LABEL git_hash=e8bf1cceea1bff0ee05a38b6f8bbe04c4c4b5588
LABEL git_hash=b33c2ed4c1d1d66c510d468d7969b4402d8361c8
#LABEL_END

USER node
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 @@ -32,6 +32,7 @@
"@bitgo/sdk-coin-avaxc": "^2.4.18",
"@bitgo/sdk-coin-avaxp": "^3.5.18",
"@bitgo/sdk-coin-bld": "^1.1.0",
"@bitgo/sdk-coin-bnb": "^1.0.0",
"@bitgo/sdk-coin-bsc": "^3.6.4",
"@bitgo/sdk-coin-celo": "^1.3.27",
"@bitgo/sdk-coin-cspr": "^1.2.27",
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 @@ -98,6 +98,9 @@ export { Near };
import * as Bsc from '@bitgo/sdk-coin-bsc';
export { Bsc };

import * as Bnb from '@bitgo/sdk-coin-bnb';
export { Bnb };

import * as Polygon from '@bitgo/sdk-coin-polygon';
export { Polygon };

Expand All @@ -122,6 +125,8 @@ const coinBuilderMap = {
tavaxc: AvaxC.TransactionBuilder,
bsc: Bsc.TransactionBuilder,
tbsc: Bsc.TransactionBuilder,
bnb: Bnb.TransactionBuilder,
tbnb: Bnb.TransactionBuilder,
avaxp: AvaxP.TransactionBuilderFactory,
tavaxp: AvaxP.TransactionBuilderFactory,
hbar: Hbar.TransactionBuilderFactory,
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 @@ -25,6 +25,9 @@
{
"path": "../sdk-coin-bsc"
},
{
"path": "../sdk-coin-bnb"
},
{
"path": "../sdk-coin-celo"
},
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@bitgo/sdk-coin-bch": "^1.3.27",
"@bitgo/sdk-coin-bcha": "^1.5.22",
"@bitgo/sdk-coin-bld": "^1.1.0",
"@bitgo/sdk-coin-bnb": "^1.0.0",
"@bitgo/sdk-coin-bsc": "^3.6.4",
"@bitgo/sdk-coin-bsv": "^1.3.27",
"@bitgo/sdk-coin-btc": "^1.5.7",
Expand Down
9 changes: 9 additions & 0 deletions modules/bitgo/src/v2/coinFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
Bld,
Bsc,
BscToken,
Bnb,
BnbToken,
Bsv,
Btc,
Btg,
Expand Down Expand Up @@ -65,6 +67,7 @@ import {
Tbch,
Tbld,
Tbsc,
Tbnb,
Tbsv,
Tbtc,
Tcelo,
Expand Down Expand Up @@ -115,6 +118,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('bcha', Bcha.createInstance);
globalCoinFactory.register('bld', Bld.createInstance);
globalCoinFactory.register('bsc', Bsc.createInstance);
globalCoinFactory.register('bnb', Bnb.createInstance);
globalCoinFactory.register('bsv', Bsv.createInstance);
globalCoinFactory.register('btc', Btc.createInstance);
globalCoinFactory.register('btg', Btg.createInstance);
Expand Down Expand Up @@ -156,6 +160,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register('tbcha', Tbcha.createInstance);
globalCoinFactory.register('tbld', Tbld.createInstance);
globalCoinFactory.register('tbsc', Tbsc.createInstance);
globalCoinFactory.register('tbnb', Tbnb.createInstance);
globalCoinFactory.register('tbsv', Tbsv.createInstance);
globalCoinFactory.register('tbtc', Tbtc.createInstance);
globalCoinFactory.register('tcelo', Tcelo.createInstance);
Expand Down Expand Up @@ -216,6 +221,10 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
globalCoinFactory.register(name, coinConstructor);
});

BnbToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
globalCoinFactory.register(name, coinConstructor);
});

EosToken.createTokenConstructors().forEach(({ name, coinConstructor }) => {
globalCoinFactory.register(name, coinConstructor);
});
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 @@ -8,6 +8,7 @@ import { Bch, Tbch } from '@bitgo/sdk-coin-bch';
import { Bcha, Tbcha } from '@bitgo/sdk-coin-bcha';
import { Bld, Tbld } from '@bitgo/sdk-coin-bld';
import { Bsc, BscToken, Tbsc } from '@bitgo/sdk-coin-bsc';
import { Bnb, BnbToken, Tbnb } from '@bitgo/sdk-coin-bnb';
import { Bsv, Tbsv } from '@bitgo/sdk-coin-bsv';
import { Btc, Tbtc } from '@bitgo/sdk-coin-btc';
import { Btg } from '@bitgo/sdk-coin-btg';
Expand Down Expand Up @@ -46,6 +47,7 @@ export { AvaxC, AvaxCToken, TavaxC };
export { AvaxP, TavaxP };
export { Bch, Tbch };
export { Bsc, BscToken, Tbsc };
export { Bnb, BnbToken, Tbnb };
export { Bsv, Tbsv };
export { Btc, Tbtc };
export { Btg };
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 @@ -21,6 +21,7 @@ describe('Coins', () => {
AvaxCToken: 1,
PolygonToken: 1,
BscToken: 1,
BnbToken: 1,
};
Object.keys(BitGoJS.Coin)
.filter((coinName) => !excludedKeys[coinName])
Expand Down
2 changes: 1 addition & 1 deletion modules/bitgo/test/v2/unit/keychains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('V2 Keychains', function () {
});
});

['tbsc'].forEach((coin) => {
['tbsc', 'tbnb'].forEach((coin) => {
it('should create ECDSA TSS Keychains', async function () {
sandbox.stub(ECDSAUtils.EcdsaUtils.prototype, 'createKeychains').resolves(stubbedKeychainsTriplet);
const keychains = await bitgo.coin(coin).keychains().createMpc({
Expand Down
3 changes: 3 additions & 0 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
{
"path": "../sdk-coin-bsc"
},
{
"path": "../sdk-coin-bnb"
},
{
"path": "../sdk-coin-bsv"
},
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-bnb/.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-bnb/.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-bnb/.mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require: 'ts-node/register'
timeout: '60000'
reporter: 'min'
reporter-option:
- 'cdn=true'
- 'json=false'
exit: true
spec: ['test/unit/**/*.ts']
14 changes: 14 additions & 0 deletions modules/sdk-coin-bnb/.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-bnb/.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-bnb/.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-bnb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-bnb

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-bnb`.

```shell
npm i @bitgo/sdk-api @bitgo/sdk-coin-bnb
```

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 { Bnb } from '@bitgo/sdk-coin-bnb';

const sdk = new BitGoAPI();

sdk.register('bnb', Bnb.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.
53 changes: 53 additions & 0 deletions modules/sdk-coin-bnb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@bitgo/sdk-coin-bnb",
"version": "1.0.0",
"description": "BitGo SDK coin library for Bnb smart chain",
"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": ">=14 <17"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-bnb"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/abstract-eth": "^1.2.27",
"@bitgo/sdk-coin-eth": "^4.5.4",
"@bitgo/sdk-core": "^8.10.0",
"@bitgo/statics": "^17.0.1",
"@ethereumjs/common": "^2.4.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.11.2",
"@bitgo/sdk-test": "^1.2.27"
}
}
29 changes: 29 additions & 0 deletions modules/sdk-coin-bnb/src/bnb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { BaseCoin, BitGoBase, MPCAlgorithm } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
import { AbstractEthLikeCoin } from '@bitgo/abstract-eth';
import { TransactionBuilder as EthTransactionBuilder } from '@bitgo/sdk-coin-eth';
import { TransactionBuilder } from './lib';

export class Bnb extends AbstractEthLikeCoin {
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
super(bitgo, staticsCoin);
}

static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin {
return new Bnb(bitgo, staticsCoin);
}

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

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

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
}
39 changes: 39 additions & 0 deletions modules/sdk-coin-bnb/src/bnbToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @prettier
*/

import { EthLikeTokenConfig } from '@bitgo/statics';
import { BitGoBase, CoinConstructor, MPCAlgorithm, NamedCoinConstructor } from '@bitgo/sdk-core';
import { CoinNames, EthLikeToken } from '@bitgo/abstract-eth';

export { EthLikeTokenConfig };

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

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

getFullName(): string {
return 'Bnb Token';
}

supportsTss(): boolean {
return true;
}

getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}
}
5 changes: 5 additions & 0 deletions modules/sdk-coin-bnb/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './lib';
export * from './bnb';
export * from './tbnb';
export * from './bnbToken';
export * from './register';
Loading

0 comments on commit 080e789

Please sign in to comment.