Skip to content

Commit bd019f5

Browse files
Merge pull request #6026 from BitGo/WIN-5030-soneium-txn-builder
feat(sdk-coin-soneium): add transaction builder
2 parents 1c170ea + 921cdbd commit bd019f5

35 files changed

+486
-1
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
/modules/sdk-coin-sol/ @BitGo/ethalt-team
7777
/modules/sdk-coin-stx/ @BitGo/ethalt-team
7878
/modules/sdk-coin-stt/ @BitGo/ethalt-team
79+
/modules/sdk-coin-soneium/ @BitGo/ethalt-team
7980
/modules/sdk-coin-sui/ @BitGo/ethalt-team
8081
/modules/sdk-coin-tao/ @BitGo/ethalt-team
8182
/modules/sdk-coin-ton/ @BitGo/ethalt-team

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ COPY --from=builder /tmp/bitgo/modules/sdk-coin-rune /var/modules/sdk-coin-rune/
9393
COPY --from=builder /tmp/bitgo/modules/sdk-coin-sei /var/modules/sdk-coin-sei/
9494
COPY --from=builder /tmp/bitgo/modules/sdk-coin-sgb /var/modules/sdk-coin-sgb/
9595
COPY --from=builder /tmp/bitgo/modules/sdk-coin-sol /var/modules/sdk-coin-sol/
96+
COPY --from=builder /tmp/bitgo/modules/sdk-coin-soneium /var/modules/sdk-coin-soneium/
9697
COPY --from=builder /tmp/bitgo/modules/sdk-coin-stt /var/modules/sdk-coin-stt/
9798
COPY --from=builder /tmp/bitgo/modules/sdk-coin-stx /var/modules/sdk-coin-stx/
9899
COPY --from=builder /tmp/bitgo/modules/sdk-coin-sui /var/modules/sdk-coin-sui/
@@ -181,6 +182,7 @@ cd /var/modules/sdk-coin-rune && yarn link && \
181182
cd /var/modules/sdk-coin-sei && yarn link && \
182183
cd /var/modules/sdk-coin-sgb && yarn link && \
183184
cd /var/modules/sdk-coin-sol && yarn link && \
185+
cd /var/modules/sdk-coin-soneium && yarn link && \
184186
cd /var/modules/sdk-coin-stt && yarn link && \
185187
cd /var/modules/sdk-coin-stx && yarn link && \
186188
cd /var/modules/sdk-coin-sui && yarn link && \
@@ -272,6 +274,7 @@ RUN cd /var/bitgo-express && \
272274
yarn link @bitgo/sdk-coin-sei && \
273275
yarn link @bitgo/sdk-coin-sgb && \
274276
yarn link @bitgo/sdk-coin-sol && \
277+
yarn link @bitgo/sdk-coin-soneium && \
275278
yarn link @bitgo/sdk-coin-stt && \
276279
yarn link @bitgo/sdk-coin-stx && \
277280
yarn link @bitgo/sdk-coin-sui && \

modules/account-lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@bitgo/sdk-coin-rune": "^1.1.34",
6262
"@bitgo/sdk-coin-sei": "^3.0.46",
6363
"@bitgo/sdk-coin-sgb": "^1.2.1",
64+
"@bitgo/sdk-coin-soneium": "^1.0.0",
6465
"@bitgo/sdk-coin-sol": "^4.10.0",
6566
"@bitgo/sdk-coin-stt": "^1.1.0",
6667
"@bitgo/sdk-coin-stx": "^3.5.6",

modules/account-lib/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ export { World };
173173
import * as Stt from '@bitgo/sdk-coin-stt';
174174
export { Stt };
175175

176+
import * as Soneium from '@bitgo/sdk-coin-soneium';
177+
export { Soneium };
178+
176179
const coinBuilderMap = {
177180
trx: Trx.WrappedBuilder,
178181
ttrx: Trx.WrappedBuilder,
@@ -271,6 +274,8 @@ const coinBuilderMap = {
271274
tworld: World.TransactionBuilder,
272275
stt: Stt.TransactionBuilder,
273276
tstt: Stt.TransactionBuilder,
277+
soneium: Soneium.TransactionBuilder,
278+
tsoneium: Soneium.TransactionBuilder,
274279
};
275280

276281
/**

modules/account-lib/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
{
101101
"path": "../sdk-coin-sol"
102102
},
103+
{
104+
"path": "../sdk-coin-soneium"
105+
},
103106
{
104107
"path": "../sdk-coin-stx"
105108
},

modules/bitgo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"@bitgo/sdk-coin-sei": "^3.0.46",
9999
"@bitgo/sdk-coin-sgb": "^1.2.1",
100100
"@bitgo/sdk-coin-sol": "^4.10.0",
101+
"@bitgo/sdk-coin-soneium": "^1.0.0",
101102
"@bitgo/sdk-coin-stt": "^1.1.0",
102103
"@bitgo/sdk-coin-stx": "^3.5.6",
103104
"@bitgo/sdk-coin-sui": "^5.13.6",

modules/bitgo/src/v2/coinFactory.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import {
7979
Sgb,
8080
Sip10Token,
8181
Sol,
82+
Soneium,
8283
StellarToken,
8384
Stx,
8485
Stt,
@@ -141,6 +142,7 @@ import {
141142
Tsgb,
142143
Tsei,
143144
Tsol,
145+
Tsoneium,
144146
Tstx,
145147
Tstt,
146148
Tsui,
@@ -230,6 +232,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
230232
globalCoinFactory.register('sei', Sei.createInstance);
231233
globalCoinFactory.register('sgb', Sgb.createInstance);
232234
globalCoinFactory.register('sol', Sol.createInstance);
235+
globalCoinFactory.register('soneium', Soneium.createInstance);
233236
globalCoinFactory.register('stx', Stx.createInstance);
234237
globalCoinFactory.register('stt', Stt.createInstance);
235238
globalCoinFactory.register('sui', Sui.createInstance);
@@ -292,6 +295,7 @@ function registerCoinConstructors(globalCoinFactory: CoinFactory): void {
292295
globalCoinFactory.register('trx', Trx.createInstance);
293296
globalCoinFactory.register('tsei', Tsei.createInstance);
294297
globalCoinFactory.register('tsol', Tsol.createInstance);
298+
globalCoinFactory.register('tsoneium', Tsoneium.createInstance);
295299
globalCoinFactory.register('tstx', Tstx.createInstance);
296300
globalCoinFactory.register('tstt', Tstt.createInstance);
297301
globalCoinFactory.register('tsui', Tsui.createInstance);

modules/bitgo/src/v2/coins/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { Polyx, Tpolyx } from '@bitgo/sdk-coin-polyx';
4646
import { Rbtc, Trbtc } from '@bitgo/sdk-coin-rbtc';
4747
import { Rune, Trune } from '@bitgo/sdk-coin-rune';
4848
import { Sei, Tsei } from '@bitgo/sdk-coin-sei';
49+
import { Soneium, Tsoneium } from '@bitgo/sdk-coin-soneium';
4950
import { Stt, Tstt } from '@bitgo/sdk-coin-stt';
5051
import { Sgb, Tsgb } from '@bitgo/sdk-coin-sgb';
5152
import { Sol, Tsol } from '@bitgo/sdk-coin-sol';
@@ -111,6 +112,7 @@ export { Rbtc, Trbtc };
111112
export { Rune, Trune };
112113
export { Sgb, Tsgb };
113114
export { Sol, Tsol };
115+
export { Soneium, Tsoneium };
114116
export { Stt, Tstt };
115117
export { Stx, Tstx, Sip10Token };
116118
export { Sui, Tsui, SuiToken };
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-soneium/.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-soneium/.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-soneium/.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-soneium/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
### Bug Fixes
7+
8+
**Note:** Version bump only for package @bitgo/sdk-coin-soneium
9+
10+
### Features

modules/sdk-coin-soneium/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# BitGo sdk-coin-soneium
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-soneium`.
10+
11+
````shell
12+
npm i @bitgo/sdk-api @bitgo/sdk-coin-soneium```
13+
14+
Next, you will be able to initialize an instance of "bitgo" through `@bitgo/sdk-api` instead of `bitgo`.
15+
16+
```javascript
17+
import { BitGoAPI } from '@bitgo/sdk-api';
18+
import { soneium } from '@bitgo/sdk-coin-soneium';
19+
20+
const sdk = new BitGoAPI();
21+
22+
sdk.register('soneium', Soneium.createInstance);
23+
````
24+
25+
## Development
26+
27+
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.
28+
29+
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-soneium/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-soneium",
3+
"version": "1.0.0",
4+
"description": "BitGo SDK coin library for Soneium",
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-soneium"
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": "^24.3.0",
44+
"@bitgo/sdk-core": "^33.0.0",
45+
"@bitgo/statics": "^52.0.0",
46+
"@ethereumjs/common": "^2.6.5"
47+
},
48+
"devDependencies": {
49+
"@bitgo/sdk-api": "^1.62.1",
50+
"@bitgo/sdk-test": "^8.0.82"
51+
}
52+
}

modules/sdk-coin-soneium/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 './soneium';
3+
export * from './tsoneium';
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/abstract-eth';
6+
export { Utils };
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import EthereumCommon from '@ethereumjs/common';
2+
import { coins, EthereumNetwork } from '@bitgo/statics';
3+
4+
export const testnetCommon = EthereumCommon.custom(
5+
{
6+
name: 'soneium testnet',
7+
networkId: (coins.get('tsoneium').network as EthereumNetwork).chainId,
8+
chainId: (coins.get('tsoneium').network as EthereumNetwork).chainId,
9+
},
10+
{
11+
baseChain: 'sepolia',
12+
hardfork: 'london',
13+
eips: [1559],
14+
}
15+
);
16+
export const mainnetCommon = EthereumCommon.custom(
17+
{
18+
name: 'Soneium mainnet',
19+
networkId: (coins.get('soneium').network as EthereumNetwork).chainId,
20+
chainId: (coins.get('soneium').network as EthereumNetwork).chainId,
21+
},
22+
{
23+
baseChain: 'mainnet',
24+
hardfork: 'london',
25+
eips: [1559],
26+
}
27+
);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { BaseCoin as CoinConfig } from '@bitgo/statics';
2+
import { BuildTransactionError, PublicKey, Signature, 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+
private _signatures: Signature[] = [];
10+
11+
constructor(_coinConfig: Readonly<CoinConfig>) {
12+
super(_coinConfig);
13+
this._common = getCommon(this._coinConfig.network.type);
14+
this.transaction = new Transaction(this._coinConfig, this._common);
15+
}
16+
17+
/** @inheritdoc */
18+
transfer(data?: string): TransferBuilder {
19+
if (this._type !== TransactionType.Send) {
20+
throw new BuildTransactionError('Transfers can only be set for send transactions');
21+
}
22+
if (!this._transfer) {
23+
this._transfer = new TransferBuilder(data);
24+
}
25+
return this._transfer;
26+
}
27+
28+
addSignature(publicKey: PublicKey, signature: Buffer): void {
29+
this._signatures.push({ publicKey, signature });
30+
}
31+
}
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 { mainnetCommon, testnetCommon } 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 { Soneium } from './soneium';
3+
import { Tsoneium } from './tsoneium';
4+
5+
export const register = (sdk: BitGoBase): void => {
6+
sdk.register('soneium', Soneium.createInstance);
7+
sdk.register('tsoneium', Tsoneium.createInstance);
8+
};

0 commit comments

Comments
 (0)