Skip to content

feat(sdk-coin-apecoin): add the transaction builder changes #6291

New issue

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

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

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
/modules/abstract-substrate/ @BitGo/ethalt-team
/modules/sdk-coin-ada/ @BitGo/ethalt-team
/modules/sdk-coin-algo/ @BitGo/ethalt-team
/modules/sdk-coin-apecoin/ @BitGo/ethalt-team
/modules/sdk-coin-apt/ @Bitgo/ethalt-team
/modules/sdk-coin-arbeth/ @BitGo/ethalt-team
/modules/sdk-coin-atom/ @BitGo/ethalt-team
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ COPY --from=builder /tmp/bitgo/modules/utxo-core /var/modules/utxo-core/
COPY --from=builder /tmp/bitgo/modules/account-lib /var/modules/account-lib/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-algo /var/modules/sdk-coin-algo/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-apt /var/modules/sdk-coin-apt/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-apecoin /var/modules/sdk-coin-apecoin/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-arbeth /var/modules/sdk-coin-arbeth/
COPY --from=builder /tmp/bitgo/modules/abstract-eth /var/modules/abstract-eth/
COPY --from=builder /tmp/bitgo/modules/sdk-coin-atom /var/modules/sdk-coin-atom/
Expand Down Expand Up @@ -151,6 +152,7 @@ cd /var/modules/utxo-core && yarn link && \
cd /var/modules/account-lib && yarn link && \
cd /var/modules/sdk-coin-algo && yarn link && \
cd /var/modules/sdk-coin-apt && yarn link && \
cd /var/modules/sdk-coin-apecoin && yarn link && \
cd /var/modules/sdk-coin-arbeth && yarn link && \
cd /var/modules/abstract-eth && yarn link && \
cd /var/modules/sdk-coin-atom && yarn link && \
Expand Down Expand Up @@ -247,6 +249,7 @@ RUN cd /var/bitgo-express && \
yarn link @bitgo/account-lib && \
yarn link @bitgo/sdk-coin-algo && \
yarn link @bitgo/sdk-coin-apt && \
yarn link @bitgo/sdk-coin-apecoin && \
yarn link @bitgo/sdk-coin-arbeth && \
yarn link @bitgo/abstract-eth && \
yarn link @bitgo/sdk-coin-atom && \
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 @@ -161,6 +161,9 @@ export { Coredao };
import * as Apt from '@bitgo/sdk-coin-apt';
export { Apt };

import * as Apecoin from '@bitgo/sdk-coin-apecoin';
export { Apecoin };

import * as Tao from '@bitgo/sdk-coin-tao';
export { Tao };

Expand Down Expand Up @@ -262,6 +265,8 @@ const coinBuilderMap = {
toas: Oas.TransactionBuilder,
coredao: Coredao.TransactionBuilder,
tcoredao: Coredao.TransactionBuilder,
apecoin: Apecoin.TransactionBuilder,
tapecoin: Apecoin.TransactionBuilder,
apt: Apt.TransactionBuilder,
tapt: Apt.TransactionBuilder,
tao: Tao.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 @@ -10,6 +10,9 @@
"include": ["src/**/*", "test/**/*", "resources/**/*"],
"exclude": ["node_modules"],
"references": [
{
"path": "../sdk-coin-apecoin"
},
{
"path": "../sdk-coin-algo"
},
Expand Down
1 change: 1 addition & 0 deletions modules/bitgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@bitgo/sdk-api": "^1.63.3",
"@bitgo/sdk-coin-ada": "^4.10.0",
"@bitgo/sdk-coin-algo": "^2.2.0",
"@bitgo/sdk-coin-apecoin": "^1.0.0",
"@bitgo/sdk-coin-apt": "^2.3.0",
"@bitgo/sdk-coin-arbeth": "^21.5.6",
"@bitgo/sdk-coin-atom": "^13.4.14",
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 @@ -13,6 +13,7 @@ import { CoinMap, coins, getFormattedTokens } from '@bitgo/statics';
import {
Ada,
Algo,
Apecoin,
Apt,
AptToken,
Arbeth,
Expand Down Expand Up @@ -95,6 +96,7 @@ import {
Ton,
Tada,
Talgo,
Tapecoin,
Tapt,
Tarbeth,
Tatom,
Expand Down Expand Up @@ -186,6 +188,7 @@ import {
export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: CoinMap = coins): void {
coinFactory.register('ada', Ada.createInstance);
coinFactory.register('algo', Algo.createInstance);
coinFactory.register('apecoin', Apecoin.createInstance);
coinFactory.register('apt', Apt.createInstance);
coinFactory.register('arbeth', Arbeth.createInstance);
coinFactory.register('atom', Atom.createInstance);
Expand Down Expand Up @@ -254,6 +257,7 @@ export function registerCoinConstructors(coinFactory: CoinFactory, coinMap: Coin
coinFactory.register('tia', Tia.createInstance);
coinFactory.register('ton', Ton.createInstance);
coinFactory.register('talgo', Talgo.createInstance);
coinFactory.register('tapecoin', Tapecoin.createInstance);
coinFactory.register('tapt', Tapt.createInstance);
coinFactory.register('tarbeth', Tarbeth.createInstance);
coinFactory.register('tada', Tada.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 @@ -2,6 +2,7 @@ import { AbstractUtxoCoin } from '@bitgo/abstract-utxo';
import { AbstractLightningCoin } from '@bitgo/abstract-lightning';
import { Ada, Tada } from '@bitgo/sdk-coin-ada';
import { Algo, AlgoToken, Talgo } from '@bitgo/sdk-coin-algo';
import { Apecoin, Tapecoin } from '@bitgo/sdk-coin-apecoin';
import { Apt, Tapt, AptToken } from '@bitgo/sdk-coin-apt';
import { Arbeth, Tarbeth, ArbethToken } from '@bitgo/sdk-coin-arbeth';
import { Atom, Tatom } from '@bitgo/sdk-coin-atom';
Expand Down Expand Up @@ -73,6 +74,7 @@ import { Zketh, Tzketh, ZkethToken } from '@bitgo/sdk-coin-zketh';
export { AbstractUtxoCoin };
export { AbstractLightningCoin };
export { Algo, AlgoToken, Talgo };
export { Apecoin, Tapecoin };
export { Apt, Tapt, AptToken };
export { Arbeth, Tarbeth, ArbethToken };
export { Ada, Tada };
Expand Down
10 changes: 8 additions & 2 deletions modules/bitgo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
{
"path": "../sdk-coin-algo"
},
{
"path": "../sdk-coin-apecoin"
},
{
"path": "../sdk-coin-apecoin"
},
{
"path": "../sdk-coin-apt"
},
Expand Down Expand Up @@ -237,10 +243,10 @@
"path": "../sdk-coin-wemix"
},
{
"path": "../sdk-coin-xlm"
"path": "../sdk-coin-xdc"
},
{
"path": "../sdk-coin-xdc"
"path": "../sdk-coin-xlm"
},
{
"path": "../sdk-coin-xrp"
Expand Down
5 changes: 5 additions & 0 deletions modules/sdk-coin-apecoin/.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-apecoin/.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-apecoin/.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-apecoin/.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-apecoin/.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-apecoin/.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-apecoin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# BitGo sdk-coin-apecoin

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

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

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

const sdk = new BitGoAPI();

sdk.register('apecoin', Apecoin.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.
51 changes: 51 additions & 0 deletions modules/sdk-coin-apecoin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@bitgo/sdk-coin-apecoin",
"version": "1.0.0",
"description": "BitGo SDK coin library for Apecoin",
"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 <sdkteam@bitgo.com>",
"license": "MIT",
"engines": {
"node": ">=18 <23"
},
"repository": {
"type": "git",
"url": "https://github.com/BitGo/BitGoJS.git",
"directory": "modules/sdk-coin-apecoin"
},
"lint-staged": {
"*.{js,ts}": [
"yarn prettier --write",
"yarn eslint --fix"
]
},
"publishConfig": {
"access": "public"
},
"nyc": {
"extension": [
".ts"
]
},
"dependencies": {
"@bitgo/abstract-eth": "^24.4.0",
"@bitgo/sdk-core": "^35.1.0",
"@bitgo/statics": "^54.1.0"
},
"devDependencies": {
"@bitgo/sdk-api": "^1.63.3",
"@bitgo/sdk-test": "^8.0.88"
}
}
46 changes: 46 additions & 0 deletions modules/sdk-coin-apecoin/src/apecoin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @prettier
*/
import { BaseCoin, BitGoBase, MPCAlgorithm, MultisigType, multisigTypes } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
import {
AbstractEthLikeNewCoins,
TransactionBuilder as EthLikeTransactionBuilder,
UnsignedSweepTxMPCv2,
RecoverOptions,
OfflineVaultTxInfo,
} from '@bitgo/abstract-eth';
import { TransactionBuilder } from './lib';

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

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

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

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

/** inherited doc */
getDefaultMultisigType(): MultisigType {
return multisigTypes.tss;
}

/** @inheritDoc */
getMPCAlgorithm(): MPCAlgorithm {
return 'ecdsa';
}

protected async buildUnsignedSweepTxnTSS(params: RecoverOptions): Promise<OfflineVaultTxInfo | UnsignedSweepTxMPCv2> {
return this.buildUnsignedSweepTxnMPCv2(params);
}
}
3 changes: 3 additions & 0 deletions modules/sdk-coin-apecoin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './lib';
export * from './apecoin';
export * from './tapecoin';
6 changes: 6 additions & 0 deletions modules/sdk-coin-apecoin/src/lib/index.ts
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/abstract-eth';
export { Utils };
28 changes: 28 additions & 0 deletions modules/sdk-coin-apecoin/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: 'tapecoin testnet',
networkId: (coins.get('tapecoin').network as EthereumNetwork).chainId,
chainId: (coins.get('tapecoin').network as EthereumNetwork).chainId,
},
{
baseChain: 'sepolia',
hardfork: 'london',
eips: [1559],
}
);

export const mainnetCommon = EthereumCommon.custom(
{
name: 'apecoin mainnet',
networkId: (coins.get('apecoin').network as EthereumNetwork).chainId,
chainId: (coins.get('apecoin').network as EthereumNetwork).chainId,
},
{
baseChain: 'mainnet',
hardfork: 'london',
eips: [1559],
}
);
36 changes: 36 additions & 0 deletions modules/sdk-coin-apecoin/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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;
private _signatures: any;

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;
}

addSignature(publicKey, signature) {
this._signatures = [];
this._signatures.push({ publicKey, signature });
}

protected getContractData(addresses: string[]): string {
throw new Error('Method not implemented.');
}
}
1 change: 1 addition & 0 deletions modules/sdk-coin-apecoin/src/lib/transferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TransferBuilder } from '@bitgo/abstract-eth';
Loading