Skip to content

Commit f657ef4

Browse files
committed
chore: wip
1 parent 260f2d5 commit f657ef4

File tree

9 files changed

+1284
-0
lines changed

9 files changed

+1284
-0
lines changed

packages/sbtc/CHANGELOG.md

Lines changed: 484 additions & 0 deletions
Large diffs are not rendered by default.

packages/sbtc/README.md

Lines changed: 667 additions & 0 deletions
Large diffs are not rendered by default.

packages/sbtc/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const makeJestConfig = require('../../configs/jestConfig');
2+
3+
module.exports = makeJestConfig(__dirname);

packages/sbtc/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "@stacks/sbtc",
3+
"version": "6.7.0",
4+
"description": "Library for sBTC.",
5+
"license": "MIT",
6+
"author": "Hiro Systems PBC (https://hiro.so)",
7+
"homepage": "https://hiro.so/stacks-js",
8+
"scripts": {
9+
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:umd",
10+
"build:cjs": "tsc -b tsconfig.build.json",
11+
"build:esm": "tsc -p tsconfig.build.json --module ES6 --outDir ./dist/esm",
12+
"build:umd": "NODE_OPTIONS=--max-old-space-size=8192 webpack --config webpack.config.js",
13+
"clean": "rimraf dist && tsc -b tsconfig.build.json --clean",
14+
"pack": "npm pack",
15+
"prepublishOnly": "npm run test && NODE_ENV=production npm run build",
16+
"start": "tsc -b tsconfig.build.json --watch --verbose",
17+
"test": "jest",
18+
"test:watch": "jest --watch --coverage=false",
19+
"typecheck": "tsc --noEmit",
20+
"typecheck:watch": "npm run typecheck -- --watch"
21+
},
22+
"dependencies": {
23+
"@stacks/encryption": "^6.7.0",
24+
"@stacks/transactions": "^6.7.0"
25+
},
26+
"devDependencies": {
27+
"jest-fetch-mock": "^3.0.3",
28+
"rimraf": "^3.0.2"
29+
},
30+
"sideEffects": false,
31+
"typings": "dist/index.d.ts",
32+
"main": "dist/index.js",
33+
"module": "dist/esm/index.js",
34+
"umd:main": "dist/umd/index.js",
35+
"unpkg": "dist/umd/index.js",
36+
"files": [
37+
"dist",
38+
"src"
39+
],
40+
"keywords": [
41+
"sBTC",
42+
"Stacks"
43+
],
44+
"repository": {
45+
"type": "git",
46+
"url": "git+https://github.com/hirosystems/stacks.js.git"
47+
},
48+
"bugs": {
49+
"url": "https://github.com/hirosystems/stacks.js/issues"
50+
}
51+
}

packages/sbtc/src/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
interface MintOptions {
2+
amount: number; // (amount uint)
3+
destination: string; // (destination principal)
4+
depositTxid: string; // (deposit-txid (buff 32))
5+
burnChainHeight: number; // (burn-chain-height uint)
6+
merkleProof: string[]; // (merkle-proof (list 14 (buff 32)))
7+
txIndex: number; // (tx-index uint)
8+
treeDepth: number; // (tree-depth uint)
9+
blockHeader: string; // (block-header (buff 80)))
10+
}
11+
12+
export class sBTCClient {
13+
constructor(public network: StacksNetwork) {}
14+
15+
/**
16+
17+
*/
18+
async mint(options: MintOptions): Promise<void> {
19+
const [contractAddress, contractName] = this.parseContractId(options?.contractId);
20+
const result = await callReadOnlyFunction({
21+
network: this.network,
22+
senderAddress: this.address,
23+
contractAddress,
24+
contractName,
25+
functionArgs: [uintCV(options.rewardCyleId), uintCV(options.rewardSetIndex)],
26+
functionName: 'get-reward-set-pox-address',
27+
});
28+
29+
return unwrapMap(result as OptionalCV<TupleCV>, tuple => ({
30+
pox_address: {
31+
version: ((tuple.data['pox-addr'] as TupleCV).data['version'] as BufferCV).buffer,
32+
hashbytes: ((tuple.data['pox-addr'] as TupleCV).data['hashbytes'] as BufferCV).buffer,
33+
},
34+
total_ustx: (tuple.data['total-ustx'] as UIntCV).value,
35+
}));
36+
}
37+
}

packages/sbtc/tsconfig.build.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"extends": "../../tsconfig.build.json",
3+
"compilerOptions": {
4+
"noEmit": false,
5+
"outDir": "./dist",
6+
"rootDir": "./src",
7+
"tsBuildInfoFile": "./tsconfig.build.tsbuildinfo",
8+
"composite": true
9+
},
10+
"references": [
11+
{
12+
"path": "../common/tsconfig.build.json"
13+
},
14+
{
15+
"path": "../encryption/tsconfig.build.json"
16+
},
17+
{
18+
"path": "../network/tsconfig.build.json"
19+
},
20+
{
21+
"path": "../transactions/tsconfig.build.json"
22+
}
23+
],
24+
"include": [
25+
"src/**/*"
26+
]
27+
}

packages/sbtc/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["src/**/*", "tests/**/*"],
4+
"typedocOptions": {
5+
"entryPoints": ["src/index.ts"]
6+
}
7+
}

packages/sbtc/webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const config = require('../../configs/webpack.config.js');
2+
3+
config.output.library.name = 'StacksStacking';
4+
5+
config.resolve.fallback = {};
6+
7+
module.exports = config;

packages/transactions/tests/types.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ test('Length prefixed list serialization and deserialization', () => {
5555
expect(deserialized.values.length).toBe(addressList.length);
5656

5757
for (let index = 0; index < addressList.length; index++) {
58+
// todo: toString() doesn't make sense FIX
5859
expect(deserialized.values[index].toString()).toBe(addressList[index].toString());
5960
}
6061
});

0 commit comments

Comments
 (0)