From 7cb1a1d50b92591fff24b5ceff599348a6c6de69 Mon Sep 17 00:00:00 2001 From: Adarsh Ravichandran Date: Thu, 14 Nov 2024 15:07:42 +0530 Subject: [PATCH] feat(sdk-coin-oas): add oas sdk skeleton Ticket: WIN-3696 --- 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-oas/.eslintignore | 5 ++ modules/sdk-coin-oas/.gitignore | 3 ++ modules/sdk-coin-oas/.mocharc.yml | 8 +++ modules/sdk-coin-oas/.npmignore | 14 +++++ modules/sdk-coin-oas/.prettierignore | 2 + modules/sdk-coin-oas/.prettierrc.yml | 3 ++ modules/sdk-coin-oas/README.md | 30 +++++++++++ modules/sdk-coin-oas/package.json | 52 +++++++++++++++++++ modules/sdk-coin-oas/src/index.ts | 4 ++ modules/sdk-coin-oas/src/lib/index.ts | 6 +++ modules/sdk-coin-oas/src/lib/resources.ts | 28 ++++++++++ .../src/lib/transactionBuilder.ts | 33 ++++++++++++ .../sdk-coin-oas/src/lib/transferBuilder.ts | 1 + modules/sdk-coin-oas/src/lib/utils.ts | 21 ++++++++ modules/sdk-coin-oas/src/oas.ts | 46 ++++++++++++++++ modules/sdk-coin-oas/src/register.ts | 8 +++ modules/sdk-coin-oas/src/toas.ts | 16 ++++++ modules/sdk-coin-oas/test/unit/getBuilder.ts | 6 +++ modules/sdk-coin-oas/test/unit/oas.ts | 42 +++++++++++++++ .../test/unit/transactionBuilder/send.ts | 16 ++++++ modules/sdk-coin-oas/test/unit/utils.ts | 29 +++++++++++ modules/sdk-coin-oas/tsconfig.json | 29 +++++++++++ modules/sdk-core/src/bitgo/environments.ts | 2 + modules/statics/src/networks.ts | 10 ++-- tsconfig.packages.json | 3 ++ 33 files changed, 435 insertions(+), 4 deletions(-) create mode 100644 modules/sdk-coin-oas/.eslintignore create mode 100644 modules/sdk-coin-oas/.gitignore create mode 100644 modules/sdk-coin-oas/.mocharc.yml create mode 100644 modules/sdk-coin-oas/.npmignore create mode 100644 modules/sdk-coin-oas/.prettierignore create mode 100644 modules/sdk-coin-oas/.prettierrc.yml create mode 100644 modules/sdk-coin-oas/README.md create mode 100644 modules/sdk-coin-oas/package.json create mode 100644 modules/sdk-coin-oas/src/index.ts create mode 100644 modules/sdk-coin-oas/src/lib/index.ts create mode 100644 modules/sdk-coin-oas/src/lib/resources.ts create mode 100644 modules/sdk-coin-oas/src/lib/transactionBuilder.ts create mode 100644 modules/sdk-coin-oas/src/lib/transferBuilder.ts create mode 100644 modules/sdk-coin-oas/src/lib/utils.ts create mode 100644 modules/sdk-coin-oas/src/oas.ts create mode 100644 modules/sdk-coin-oas/src/register.ts create mode 100644 modules/sdk-coin-oas/src/toas.ts create mode 100644 modules/sdk-coin-oas/test/unit/getBuilder.ts create mode 100644 modules/sdk-coin-oas/test/unit/oas.ts create mode 100644 modules/sdk-coin-oas/test/unit/transactionBuilder/send.ts create mode 100644 modules/sdk-coin-oas/test/unit/utils.ts create mode 100644 modules/sdk-coin-oas/tsconfig.json diff --git a/Dockerfile b/Dockerfile index 3597de6c8f..9b789f369f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-hbar /var/modules/sdk-coin-hbar/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-injective /var/modules/sdk-coin-injective/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-islm /var/modules/sdk-coin-islm/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-near /var/modules/sdk-coin-near/ +COPY --from=builder /tmp/bitgo/modules/sdk-coin-oas /var/modules/sdk-coin-oas/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-opeth /var/modules/sdk-coin-opeth/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-osmo /var/modules/sdk-coin-osmo/ COPY --from=builder /tmp/bitgo/modules/sdk-coin-polygon /var/modules/sdk-coin-polygon/ @@ -147,6 +148,7 @@ cd /var/modules/sdk-coin-hbar && yarn link && \ cd /var/modules/sdk-coin-injective && yarn link && \ cd /var/modules/sdk-coin-islm && yarn link && \ cd /var/modules/sdk-coin-near && yarn link && \ +cd /var/modules/sdk-coin-oas && yarn link && \ cd /var/modules/sdk-coin-opeth && yarn link && \ cd /var/modules/sdk-coin-osmo && yarn link && \ cd /var/modules/sdk-coin-polygon && yarn link && \ @@ -221,6 +223,7 @@ RUN cd /var/bitgo-express && \ yarn link @bitgo/sdk-coin-injective && \ yarn link @bitgo/sdk-coin-islm && \ yarn link @bitgo/sdk-coin-near && \ + yarn link @bitgo/sdk-coin-oas && \ yarn link @bitgo/sdk-coin-opeth && \ yarn link @bitgo/sdk-coin-osmo && \ yarn link @bitgo/sdk-coin-polygon && \ diff --git a/modules/account-lib/package.json b/modules/account-lib/package.json index 3f46bb13a0..d907c0a7a0 100644 --- a/modules/account-lib/package.json +++ b/modules/account-lib/package.json @@ -47,6 +47,7 @@ "@bitgo/sdk-coin-injective": "^3.0.14", "@bitgo/sdk-coin-islm": "^2.0.45", "@bitgo/sdk-coin-near": "^2.0.45", + "@bitgo/sdk-coin-oas": "^1.0.0", "@bitgo/sdk-coin-opeth": "^18.1.30", "@bitgo/sdk-coin-osmo": "^3.0.14", "@bitgo/sdk-coin-polygon": "^21.0.14", diff --git a/modules/account-lib/src/index.ts b/modules/account-lib/src/index.ts index 45d4771ee9..041e007f5f 100644 --- a/modules/account-lib/src/index.ts +++ b/modules/account-lib/src/index.ts @@ -134,6 +134,9 @@ export { XRP }; import * as zkEth from '@bitgo/sdk-coin-zketh'; export { zkEth }; +import * as Oas from '@bitgo/sdk-coin-oas'; +export { Oas }; + const coinBuilderMap = { trx: Trx.WrappedBuilder, ttrx: Trx.WrappedBuilder, @@ -204,6 +207,8 @@ const coinBuilderMap = { tbera: Bera.TransactionBuilder, rune: Rune.TransactionBuilderFactory, trune: Rune.TransactionBuilderFactory, + oas: Oas.TransactionBuilder, + toas: Oas.TransactionBuilder, }; /** diff --git a/modules/account-lib/tsconfig.json b/modules/account-lib/tsconfig.json index 42b7d6451c..9e50ca6548 100644 --- a/modules/account-lib/tsconfig.json +++ b/modules/account-lib/tsconfig.json @@ -67,6 +67,9 @@ { "path": "../sdk-coin-near" }, + { + "path": "../sdk-coin-oas" + }, { "path": "../sdk-coin-opeth" }, diff --git a/modules/bitgo/package.json b/modules/bitgo/package.json index f5a93ab64e..da398adb37 100644 --- a/modules/bitgo/package.json +++ b/modules/bitgo/package.json @@ -82,6 +82,7 @@ "@bitgo/sdk-coin-lnbtc": "^1.1.23", "@bitgo/sdk-coin-ltc": "^3.0.45", "@bitgo/sdk-coin-near": "^2.0.45", + "@bitgo/sdk-coin-oas": "^1.0.0", "@bitgo/sdk-coin-opeth": "^18.1.30", "@bitgo/sdk-coin-osmo": "^3.0.14", "@bitgo/sdk-coin-polygon": "^21.0.14", diff --git a/modules/bitgo/src/v2/coinFactory.ts b/modules/bitgo/src/v2/coinFactory.ts index cc5344303a..eefa8702a1 100644 --- a/modules/bitgo/src/v2/coinFactory.ts +++ b/modules/bitgo/src/v2/coinFactory.ts @@ -56,6 +56,7 @@ import { Lnbtc, Ltc, Ofc, + Oas, OfcToken, Opeth, OpethToken, @@ -107,6 +108,7 @@ import { Tislm, Tlnbtc, Tltc, + Toas, Tosmo, Topeth, Tpolygon, @@ -177,6 +179,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void { globalCoinFactory.register('injective', Injective.createInstance); globalCoinFactory.register('islm', Islm.createInstance); globalCoinFactory.register('near', Near.createInstance); + globalCoinFactory.register('oas', Oas.createInstance); globalCoinFactory.register('ofc', Ofc.createInstance); globalCoinFactory.register('opeth', Opeth.createInstance); globalCoinFactory.register('osmo', Osmo.createInstance); @@ -226,6 +229,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void { globalCoinFactory.register('tlnbtc', Tlnbtc.createInstance); globalCoinFactory.register('tltc', Tltc.createInstance); globalCoinFactory.register('tnear', TNear.createInstance); + globalCoinFactory.register('toas', Toas.createInstance); globalCoinFactory.register('topeth', Topeth.createInstance); globalCoinFactory.register('tosmo', Tosmo.createInstance); globalCoinFactory.register('tpolygon', Tpolygon.createInstance); diff --git a/modules/bitgo/src/v2/coins/index.ts b/modules/bitgo/src/v2/coins/index.ts index 23fe90dcb4..c2ebb478b9 100644 --- a/modules/bitgo/src/v2/coins/index.ts +++ b/modules/bitgo/src/v2/coins/index.ts @@ -32,6 +32,7 @@ import { Injective, Tinjective } from '@bitgo/sdk-coin-injective'; import { Islm, Tislm } from '@bitgo/sdk-coin-islm'; import { Lnbtc, Tlnbtc } from '@bitgo/sdk-coin-lnbtc'; import { Ltc, Tltc } from '@bitgo/sdk-coin-ltc'; +import { Oas, Toas } from '@bitgo/sdk-coin-oas'; import { Opeth, Topeth, OpethToken } from '@bitgo/sdk-coin-opeth'; import { Osmo, Tosmo } from '@bitgo/sdk-coin-osmo'; import { Polygon, PolygonToken, Tpolygon } from '@bitgo/sdk-coin-polygon'; @@ -82,6 +83,7 @@ export { Hash, Thash }; export { Hbar, Thbar }; export { Lnbtc, Tlnbtc }; export { Ltc, Tltc }; +export { Oas, Toas }; export { Opeth, Topeth, OpethToken }; export { Osmo, Tosmo }; export { Polygon, PolygonToken, Tpolygon }; diff --git a/modules/bitgo/tsconfig.json b/modules/bitgo/tsconfig.json index cb41ab01da..9ca6dd3334 100644 --- a/modules/bitgo/tsconfig.json +++ b/modules/bitgo/tsconfig.json @@ -137,6 +137,9 @@ { "path": "../sdk-coin-near" }, + { + "path": "../sdk-coin-oas" + }, { "path": "../sdk-coin-opeth" }, diff --git a/modules/sdk-coin-oas/.eslintignore b/modules/sdk-coin-oas/.eslintignore new file mode 100644 index 0000000000..190f83e0df --- /dev/null +++ b/modules/sdk-coin-oas/.eslintignore @@ -0,0 +1,5 @@ +node_modules +.idea +public +dist + diff --git a/modules/sdk-coin-oas/.gitignore b/modules/sdk-coin-oas/.gitignore new file mode 100644 index 0000000000..67ccce4c64 --- /dev/null +++ b/modules/sdk-coin-oas/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +.idea/ +dist/ diff --git a/modules/sdk-coin-oas/.mocharc.yml b/modules/sdk-coin-oas/.mocharc.yml new file mode 100644 index 0000000000..7b4b0d51f4 --- /dev/null +++ b/modules/sdk-coin-oas/.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-oas/.npmignore b/modules/sdk-coin-oas/.npmignore new file mode 100644 index 0000000000..d5fb3a098c --- /dev/null +++ b/modules/sdk-coin-oas/.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-oas/.prettierignore b/modules/sdk-coin-oas/.prettierignore new file mode 100644 index 0000000000..3a11d6af29 --- /dev/null +++ b/modules/sdk-coin-oas/.prettierignore @@ -0,0 +1,2 @@ +.nyc_output/ +dist/ diff --git a/modules/sdk-coin-oas/.prettierrc.yml b/modules/sdk-coin-oas/.prettierrc.yml new file mode 100644 index 0000000000..7c3d8dd32a --- /dev/null +++ b/modules/sdk-coin-oas/.prettierrc.yml @@ -0,0 +1,3 @@ +printWidth: 120 +singleQuote: true +trailingComma: 'es5' diff --git a/modules/sdk-coin-oas/README.md b/modules/sdk-coin-oas/README.md new file mode 100644 index 0000000000..a9f2c877e1 --- /dev/null +++ b/modules/sdk-coin-oas/README.md @@ -0,0 +1,30 @@ +# BitGo sdk-coin-oas + +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-oas`. + +```shell +npm i @bitgo/sdk-api @bitgo/sdk-coin-oas +``` + +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 { Oas } from '@bitgo/sdk-coin-oas'; + +const sdk = new BitGoAPI(); + +sdk.register('oas', Oas.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-oas/package.json b/modules/sdk-coin-oas/package.json new file mode 100644 index 0000000000..0741b5105a --- /dev/null +++ b/modules/sdk-coin-oas/package.json @@ -0,0 +1,52 @@ +{ + "name": "@bitgo/sdk-coin-oas", + "version": "1.0.0", + "description": "BitGo SDK coin library for Oasys", + "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-oas" + }, + "lint-staged": { + "*.{js,ts}": [ + "yarn prettier --write", + "yarn eslint --fix" + ] + }, + "publishConfig": { + "access": "public" + }, + "nyc": { + "extension": [ + ".ts" + ] + }, + "dependencies": { + "@bitgo/abstract-eth": "^22.3.1", + "@bitgo/sdk-core": "^28.13.1", + "@bitgo/statics": "^50.6.0", + "@ethereumjs/common": "^2.6.5" + }, + "devDependencies": { + "@bitgo/sdk-api": "^1.56.3", + "@bitgo/sdk-test": "^8.0.50" + } +} diff --git a/modules/sdk-coin-oas/src/index.ts b/modules/sdk-coin-oas/src/index.ts new file mode 100644 index 0000000000..7838621965 --- /dev/null +++ b/modules/sdk-coin-oas/src/index.ts @@ -0,0 +1,4 @@ +export * from './lib'; +export * from './oas'; +export * from './toas'; +export * from './register'; diff --git a/modules/sdk-coin-oas/src/lib/index.ts b/modules/sdk-coin-oas/src/lib/index.ts new file mode 100644 index 0000000000..20f9e761a1 --- /dev/null +++ b/modules/sdk-coin-oas/src/lib/index.ts @@ -0,0 +1,6 @@ +import * as Utils from './utils'; + +export { TransactionBuilder } from './transactionBuilder'; +export { TransferBuilder } from './transferBuilder'; +export { Transaction, KeyPair } from '@bitgo/abstract-eth'; +export { Utils }; diff --git a/modules/sdk-coin-oas/src/lib/resources.ts b/modules/sdk-coin-oas/src/lib/resources.ts new file mode 100644 index 0000000000..231a300ee9 --- /dev/null +++ b/modules/sdk-coin-oas/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: 'oas testnet', + networkId: (coins.get('toas').network as EthereumNetwork).chainId, + chainId: (coins.get('toas').network as EthereumNetwork).chainId, + }, + { + baseChain: 'sepolia', + hardfork: 'london', + eips: [1559], + } +); + +export const mainnetCommon = EthereumCommon.custom( + { + name: 'oas mainnet', + networkId: (coins.get('oas').network as EthereumNetwork).chainId, + chainId: (coins.get('oas').network as EthereumNetwork).chainId, + }, + { + baseChain: 'mainnet', + hardfork: 'london', + eips: [1559], + } +); diff --git a/modules/sdk-coin-oas/src/lib/transactionBuilder.ts b/modules/sdk-coin-oas/src/lib/transactionBuilder.ts new file mode 100644 index 0000000000..d1f0c9f9cd --- /dev/null +++ b/modules/sdk-coin-oas/src/lib/transactionBuilder.ts @@ -0,0 +1,33 @@ +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 { + amount(arg0: number) { + throw new Error('Method not implemented.'); + } + 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-oas/src/lib/transferBuilder.ts b/modules/sdk-coin-oas/src/lib/transferBuilder.ts new file mode 100644 index 0000000000..7447c0cf3d --- /dev/null +++ b/modules/sdk-coin-oas/src/lib/transferBuilder.ts @@ -0,0 +1 @@ +export { TransferBuilder } from '@bitgo/abstract-eth'; diff --git a/modules/sdk-coin-oas/src/lib/utils.ts b/modules/sdk-coin-oas/src/lib/utils.ts new file mode 100644 index 0000000000..dc81fa08f9 --- /dev/null +++ b/modules/sdk-coin-oas/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-oas/src/oas.ts b/modules/sdk-coin-oas/src/oas.ts new file mode 100644 index 0000000000..c0b38b518b --- /dev/null +++ b/modules/sdk-coin-oas/src/oas.ts @@ -0,0 +1,46 @@ +/** + * @prettier + */ +import { BaseCoin, BitGoBase, common, MPCAlgorithm } from '@bitgo/sdk-core'; +import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics'; +import { + AbstractEthLikeNewCoins, + recoveryBlockchainExplorerQuery, + TransactionBuilder as EthLikeTransactionBuilder, +} from '@bitgo/abstract-eth'; +import { TransactionBuilder } from './lib'; + +export class Oas extends AbstractEthLikeNewCoins { + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly) { + super(bitgo, staticsCoin); + } + + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly): BaseCoin { + return new Oas(bitgo, staticsCoin); + } + + protected getTransactionBuilder(): EthLikeTransactionBuilder { + return new TransactionBuilder(coins.get(this.getBaseChain())); + } + + /** @inheritDoc */ + supportsTss(): boolean { + return true; + } + + /** @inheritDoc */ + getMPCAlgorithm(): MPCAlgorithm { + return 'ecdsa'; + } + + /** + * Make a query to Oasys chain explorer for information such as balance, token balance, solidity calls + * @param {Object} query key-value pairs of parameters to append after /api + * @returns {Promise} response Oasys chain explorer + */ + async recoveryBlockchainExplorerQuery(query: Record): Promise> { + const apiToken = common.Environments[this.bitgo.getEnv()].oasExplorerApiToken; + const explorerUrl = common.Environments[this.bitgo.getEnv()].oasExplorerBaseUrl; + return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken); + } +} diff --git a/modules/sdk-coin-oas/src/register.ts b/modules/sdk-coin-oas/src/register.ts new file mode 100644 index 0000000000..64f5a03e2c --- /dev/null +++ b/modules/sdk-coin-oas/src/register.ts @@ -0,0 +1,8 @@ +import { BitGoBase } from '@bitgo/sdk-core'; +import { Oas } from './oas'; +import { Toas } from './toas'; + +export const register = (sdk: BitGoBase): void => { + sdk.register('oas', Oas.createInstance); + sdk.register('toas', Toas.createInstance); +}; diff --git a/modules/sdk-coin-oas/src/toas.ts b/modules/sdk-coin-oas/src/toas.ts new file mode 100644 index 0000000000..fbe1c71177 --- /dev/null +++ b/modules/sdk-coin-oas/src/toas.ts @@ -0,0 +1,16 @@ +/** + * Testnet Oas + */ +import { BaseCoin, BitGoBase } from '@bitgo/sdk-core'; +import { BaseCoin as StaticsBaseCoin } from '@bitgo/statics'; +import { Oas } from './oas'; + +export class Toas extends Oas { + protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly) { + super(bitgo, staticsCoin); + } + + static createInstance(bitgo: BitGoBase, staticsCoin?: Readonly): BaseCoin { + return new Toas(bitgo, staticsCoin); + } +} diff --git a/modules/sdk-coin-oas/test/unit/getBuilder.ts b/modules/sdk-coin-oas/test/unit/getBuilder.ts new file mode 100644 index 0000000000..261b490989 --- /dev/null +++ b/modules/sdk-coin-oas/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-oas/test/unit/oas.ts b/modules/sdk-coin-oas/test/unit/oas.ts new file mode 100644 index 0000000000..a64f903484 --- /dev/null +++ b/modules/sdk-coin-oas/test/unit/oas.ts @@ -0,0 +1,42 @@ +import 'should'; + +import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; +import { BitGoAPI } from '@bitgo/sdk-api'; + +import { Oas, Toas } from '../../src/index'; + +const bitgo: TestBitGoAPI = TestBitGo.decorate(BitGoAPI, { env: 'test' }); + +describe('OASYS chain', function () { + before(function () { + bitgo.safeRegister('oas', Oas.createInstance); + bitgo.safeRegister('toas', Toas.createInstance); + bitgo.initializeTestVars(); + }); + + describe('Basic Coin Info', function () { + it('should return the right info for oas', function () { + const oas = bitgo.coin('oas'); + + oas.should.be.an.instanceof(Oas); + oas.getChain().should.equal('oas'); + oas.getFamily().should.equal('oas'); + oas.getFullName().should.equal('oaschain'); + oas.getBaseFactor().should.equal(1e18); + oas.supportsTss().should.equal(true); + oas.allowsAccountConsolidations().should.equal(false); + }); + + it('should return the right info for toas', function () { + const toas = bitgo.coin('toas'); + + toas.should.be.an.instanceof(Toas); + toas.getChain().should.equal('toas'); + toas.getFamily().should.equal('oas'); + toas.getFullName().should.equal('Testnet oaschain'); + toas.getBaseFactor().should.equal(1e18); + toas.supportsTss().should.equal(true); + toas.allowsAccountConsolidations().should.equal(false); + }); + }); +}); diff --git a/modules/sdk-coin-oas/test/unit/transactionBuilder/send.ts b/modules/sdk-coin-oas/test/unit/transactionBuilder/send.ts new file mode 100644 index 0000000000..d571300d86 --- /dev/null +++ b/modules/sdk-coin-oas/test/unit/transactionBuilder/send.ts @@ -0,0 +1,16 @@ +import { getBuilder } from '../getBuilder'; +import should from 'should'; + +describe('OASYS Transfer Builder', () => { + describe('Build from TxHex', function () { + it('Should successfully build from txHex', async function () { + const txBuilder = getBuilder('toas'); + const txHex = + '0x02f86482249c010102825208944943dd2a2494e3ea5937954cb836692a047695b50180c001a0d3538b0f4f39bdbfa76becc187985c04ee0a01d0bc686a3c004b5f9f5a9a4fa5a036e4917be05a8ac0eb8639187ce746d7c47f74f04213118ba57873ec23ae1c2b'; + txBuilder.from(txHex); + const parsedTx = await txBuilder.build(); + + should.exist(parsedTx.toJson()); + }); + }); +}); diff --git a/modules/sdk-coin-oas/test/unit/utils.ts b/modules/sdk-coin-oas/test/unit/utils.ts new file mode 100644 index 0000000000..e4306e62e0 --- /dev/null +++ b/modules/sdk-coin-oas/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(), 'oas mainnet'); + should.equal(common.hardfork(), 'london'); + should.equal(common.chainIdBN().toString(), '248'); + should.equal(common.networkIdBN().toString(), '248'); + }); + + it('getCommon for testnet', () => { + const common = getCommon(NetworkType.TESTNET); + should.equal(common.chainName(), 'oas testnet'); + should.equal(common.hardfork(), 'london'); + should.equal(common.chainIdBN().toString(), '9372'); + should.equal(common.networkIdBN().toString(), '9372'); + }); + + 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-oas/tsconfig.json b/modules/sdk-coin-oas/tsconfig.json new file mode 100644 index 0000000000..52c51f35c6 --- /dev/null +++ b/modules/sdk-coin-oas/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 525bcba540..afa31e3871 100644 --- a/modules/sdk-core/src/bitgo/environments.ts +++ b/modules/sdk-core/src/bitgo/environments.ts @@ -21,6 +21,8 @@ interface EnvironmentTemplate { polygonscanApiToken?: string; arbiscanBaseUrl?: string; arbiscanApiToken?: string; + oasExplorerApiToken?: string; + oasExplorerBaseUrl?: string; optimisticEtherscanBaseUrl?: string; optimisticEtherscanApiToken?: string; zksyncExplorerBaseUrl?: string; diff --git a/modules/statics/src/networks.ts b/modules/statics/src/networks.ts index e35cfa674a..8af139e378 100644 --- a/modules/statics/src/networks.ts +++ b/modules/statics/src/networks.ts @@ -1068,10 +1068,12 @@ class Oas extends Mainnet implements EthereumNetwork { class OasTestnet extends Testnet implements EthereumNetwork { name = 'OaschainTestnet'; family = CoinFamily.OAS; - explorerUrl = 'https://scan.sandverse.oasys.games/tx/'; - accountExplorerUrl = 'https://scan.sandverse.oasys.games/address/'; - chainId = 20197; - nativeCoinOperationHashPrefix = '20197'; + explorerUrl = 'https://explorer.testnet.oasys.games/tx/'; + accountExplorerUrl = 'https://explorer.testnet.oasys.games/address/'; + chainId = 9372; + nativeCoinOperationHashPrefix = '9372'; + forwarderFactoryAddress = '0x37996E762fA8B671869740C79eB33F625b3bf92a'; + forwarderImplementationAddress = '0xd5fE1C1F216B775dFd30638fA7164D41321ef79B'; } class Coredao extends Mainnet implements EthereumNetwork { diff --git a/tsconfig.packages.json b/tsconfig.packages.json index add1de9760..21435d6c91 100644 --- a/tsconfig.packages.json +++ b/tsconfig.packages.json @@ -133,6 +133,9 @@ { "path": "./modules/sdk-coin-near" }, + { + "path": "./modules/sdk-coin-oas" + }, { "path": "./modules/sdk-coin-opeth" },