-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3976 from BitGo/WIN-695-add-opeth-skeleton
feat(sdk-coin-opeth): add opeth sdk skeleton
- Loading branch information
Showing
28 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ | |
{ | ||
"path": "../sdk-coin-near" | ||
}, | ||
{ | ||
"path": "../sdk-coin-opeth" | ||
}, | ||
{ | ||
"path": "../sdk-coin-osmo" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,9 @@ | |
{ | ||
"path": "../sdk-coin-near" | ||
}, | ||
{ | ||
"path": "../sdk-coin-opeth" | ||
}, | ||
{ | ||
"path": "../sdk-coin-osmo" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.idea | ||
public | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.idea/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.nyc_output/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
printWidth: 120 | ||
singleQuote: true | ||
trailingComma: 'es5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# BitGo sdk-coin-opeth | ||
|
||
Integration of this coin is still a Work In Progress. | ||
|
||
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-opeth`. | ||
|
||
```shell | ||
npm i @bitgo/sdk-api @bitgo/sdk-coin-opeth | ||
``` | ||
|
||
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 { Opeth } from '@bitgo/sdk-coin-opeth'; | ||
|
||
const sdk = new BitGoAPI(); | ||
|
||
sdk.register('opeth', Opeth.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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@bitgo/sdk-coin-opeth", | ||
"version": "1.0.0", | ||
"description": "BitGo SDK coin library for Optimism", | ||
"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": ">=16 <19" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/BitGo/BitGoJS.git", | ||
"directory": "modules/sdk-coin-opeth" | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts}": [ | ||
"yarn prettier --write", | ||
"yarn eslint --fix" | ||
] | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".ts" | ||
] | ||
}, | ||
"dependencies": { | ||
"@bitgo/abstract-eth": "^1.4.11", | ||
"@bitgo/sdk-coin-eth": "^4.8.0", | ||
"@bitgo/sdk-core": "^8.24.0", | ||
"@bitgo/statics": "^27.0.0", | ||
"@ethereumjs/common": "^2.4.0" | ||
}, | ||
"devDependencies": { | ||
"@bitgo/sdk-api": "^1.22.0", | ||
"@bitgo/sdk-test": "^1.2.41" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './lib'; | ||
export * from './opeth'; | ||
export * from './topeth'; | ||
export * from './register'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as Utils from './utils'; | ||
|
||
export { TransactionBuilder } from './transactionBuilder'; | ||
export { TransferBuilder } from './transferBuilder'; | ||
export { Transaction, KeyPair } from '@bitgo/sdk-coin-eth'; | ||
export { Utils }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import EthereumCommon from '@ethereumjs/common'; | ||
import { coins, EthereumNetwork } from '@bitgo/statics'; | ||
|
||
export const testnetCommon = EthereumCommon.custom( | ||
{ | ||
name: 'optimistim sepolia', | ||
networkId: (coins.get('topeth').network as EthereumNetwork).chainId, | ||
chainId: (coins.get('topeth').network as EthereumNetwork).chainId, | ||
}, | ||
{ | ||
baseChain: 'sepolia', | ||
} | ||
); | ||
|
||
export const mainnetCommon = EthereumCommon.custom( | ||
{ | ||
name: 'optimism', | ||
networkId: (coins.get('opeth').network as EthereumNetwork).chainId, | ||
chainId: (coins.get('opeth').network as EthereumNetwork).chainId, | ||
}, | ||
{ | ||
baseChain: 'mainnet', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { KeyPair, Transaction, TransactionBuilder as EthTransactionBuilder } from '@bitgo/sdk-coin-eth'; | ||
import { getCommon } from './utils'; | ||
import { TransferBuilder } from './transferBuilder'; | ||
|
||
export class TransactionBuilder extends EthTransactionBuilder { | ||
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; | ||
} | ||
|
||
publicKey(key: string): void { | ||
this._sourceKeyPair = new KeyPair({ pub: key }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { TransferBuilder as EthTransferBuilder } from '@bitgo/sdk-coin-eth'; | ||
|
||
export class TransferBuilder extends EthTransferBuilder { | ||
/** @inheritdoc */ | ||
protected getNativeOperationHashPrefix(): string { | ||
return 'OPETH'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; | ||
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics'; | ||
import { AbstractEthLikeMPCCoin } from '@bitgo/abstract-eth'; | ||
import { TransactionBuilder as EthTransactionBuilder } from '@bitgo/sdk-coin-eth'; | ||
import { TransactionBuilder } from './lib'; | ||
|
||
export class Opeth extends AbstractEthLikeMPCCoin { | ||
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) { | ||
super(bitgo, staticsCoin); | ||
} | ||
|
||
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin { | ||
return new Opeth(bitgo, staticsCoin); | ||
} | ||
|
||
protected getTransactionBuilder(): EthTransactionBuilder { | ||
return new TransactionBuilder(coins.get(this.getBaseChain())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { BitGoBase } from '@bitgo/sdk-core'; | ||
import { Opeth } from './opeth'; | ||
import { Topeth } from './topeth'; | ||
|
||
export const register = (sdk: BitGoBase): void => { | ||
sdk.register('opeth', Opeth.createInstance); | ||
sdk.register('topeth', Topeth.createInstance); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Testnet Opeth | ||
*/ | ||
import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; | ||
import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; | ||
|
||
import { Opeth } from './opeth'; | ||
|
||
export class Topeth extends Opeth { | ||
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) { | ||
super(bitgo, staticsCoin); | ||
} | ||
|
||
static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>): BaseCoin { | ||
return new Topeth(bitgo, staticsCoin); | ||
} | ||
} |
Oops, something went wrong.