Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(bitcoin): Added support for Bitcoin transfers #389

Merged
merged 93 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
9b40663
feat: btc interfaces
wainola Jun 17, 2024
dcbf033
chore: addressing comments
wainola Jun 17, 2024
2ae5510
chore: rebase with v3
wainola Jun 18, 2024
51990f3
feat: base implementation for btc deposits
wainola Jun 19, 2024
f185139
chore: small change to findResource method on base transfer file
wainola Jun 19, 2024
cb782ea
chore: base files for btc to evm example
wainola Jun 19, 2024
13b51d7
feat: base implementation for btc example
wainola Jun 20, 2024
addaf8c
chore: update env sample file
wainola Jun 20, 2024
20f916b
feat: evm to btc example
wainola Jun 26, 2024
5cd9e4a
feat: adding some updates to btc to evm example
wainola Jun 26, 2024
c40b08f
chore: update env sample file
wainola Jun 26, 2024
ab25db5
chore: update to btc to evm example
wainola Jun 26, 2024
affdcb8
chore: update to btc to evm example
wainola Jun 26, 2024
6647e6d
chore: using fee value
wainola Jun 26, 2024
f1da6f1
feat: adding readme, removing utility function and updating env sampl…
wainola Jul 2, 2024
9691dad
chore: small adjustment to calculate fee
wainola Jul 2, 2024
1585793
chore: update transfer script to use caipId and also update to the sa…
wainola Jul 2, 2024
d21682b
chore: update evm to btc example script
wainola Jul 2, 2024
2de20e6
chore: readme for evm to btc example
wainola Jul 2, 2024
aefdbf2
chore: pr comments
wainola Jul 3, 2024
bb0791d
chore: merge with v3
wainola Jul 4, 2024
0249613
chore: update lock file
wainola Jul 4, 2024
7cdbf7a
chore: fixing lint issues
wainola Jul 4, 2024
f1533ef
feat: returning psbt to sign outside, changes on example and env vars…
wainola Jul 15, 2024
c487cab
chore: remove log
wainola Jul 15, 2024
e229338
chore: p2tr and p2wpkh examples separated
wainola Jul 15, 2024
acba225
chore: remove bip21 method
wainola Jul 17, 2024
9cb72f8
fix: passing correct public key
wainola Jul 19, 2024
213dc31
chore: test for p2tr transaction, fixing linter issues, adding some c…
wainola Jul 24, 2024
9a5a284
chore: update lock file
wainola Jul 24, 2024
cc09767
chore: p2pwkh test
wainola Jul 24, 2024
e44051e
chore: solving conflicts
wainola Jul 24, 2024
0069fc4
chore: update address to hext method, adding test cases and test case…
wainola Jul 29, 2024
00e2ac0
chore: docs for function helpers
wainola Jul 29, 2024
bfa82ee
chore: removing branch condition for fee output
wainola Jul 29, 2024
01f95de
chore: removing table log
wainola Jul 30, 2024
ebbdd9e
chore: removing unused method and types
wainola Jul 30, 2024
19a8269
chore: better env.sample description
wainola Jul 30, 2024
24aa725
chore: small change
wainola Jul 30, 2024
fd52679
chore: remove unused utils method from example
wainola Jul 30, 2024
24b1ca5
chore: typo
wainola Jul 30, 2024
f51eae9
chore: remove log
wainola Jul 30, 2024
df4360e
chore: removing comment
wainola Jul 30, 2024
8a292c9
chore: removing miner fee
wainola Jul 30, 2024
f0956d8
chore: miner free removed from test
wainola Jul 30, 2024
20226a1
chore: removing comment and if branch
wainola Jul 30, 2024
1af4531
chore: pr comments
wainola Jul 31, 2024
d448123
chore: amount and removing duplicate properties from fungible class
wainola Jul 31, 2024
88e3e9f
chore: removed utils file and updated imports
wainola Jul 31, 2024
bb4ca1f
chore: removing utils
wainola Jul 31, 2024
5dc0062
chore: changing name of the type
wainola Jul 31, 2024
3107ecd
chore: removing build:all command
wainola Jul 31, 2024
88090bd
chore: update readme, explaining env vars, minor changes on examples …
wainola Jul 31, 2024
c728966
chore: changing type from number to bigint
wainola Jul 31, 2024
eb55fbc
chore: addressing comments + processing either one or multiple inputs…
wainola Aug 6, 2024
2e7b501
feat: calculating size on example to have reference to pass to the pa…
wainola Aug 7, 2024
4fc94ba
chore: update env sample file
wainola Aug 7, 2024
6e3ad03
chore: addressing last comment from Saad
wainola Aug 7, 2024
b57a8fb
chore: update on comment + update on readme
wainola Aug 7, 2024
06053b3
chore: merge with v3
wainola Aug 8, 2024
083e148
chore: update lock file
wainola Aug 8, 2024
7da382e
chore: fix linter and using base transfer class from core + some modi…
wainola Aug 9, 2024
d0cecb4
chore: update package.json to build with topological flag
wainola Aug 9, 2024
2a18d3d
chore: update lock file
wainola Aug 9, 2024
6a5b637
chore: update test
wainola Aug 9, 2024
e6f6700
chore: update lock file
wainola Aug 9, 2024
dda238b
chore: fixing test
wainola Aug 9, 2024
ccf0c7b
chore: fixing import to validate btc address
wainola Aug 12, 2024
fd672f8
chore: update on package.json file
wainola Aug 14, 2024
17e69aa
chore: adding comment to config class for btc parameter
wainola Aug 14, 2024
7f32d73
chore: change on blockstream utils for example
wainola Aug 14, 2024
35339d5
chore: removing unncessary class + other minor changes
wainola Aug 14, 2024
931f4e9
chore: pr comments, removing clean all packages script
wainola Aug 20, 2024
ea10762
chore: interface for calculate size function + addressing some commen…
wainola Aug 20, 2024
a5ee7d6
chore: inline return + small changes to sample env file
wainola Aug 20, 2024
3a7263c
chore: passing object as parameter into the calculate size function
wainola Aug 20, 2024
6e869cc
chore: pr comments and test update
wainola Aug 21, 2024
f2a1736
chore: ternary operator
wainola Aug 21, 2024
fb71f2b
chore: moving var again to the top
wainola Aug 21, 2024
93c33c9
chore: merge with main
wainola Aug 21, 2024
2497a1a
chore: homologating tsconfig with the other ones in the package and o…
wainola Aug 21, 2024
659b43c
feat: moving some functions to the utils package and make use of them…
wainola Aug 22, 2024
6b4ce47
chore: release workflow file + manifest config files
wainola Aug 22, 2024
b5793e5
chore: renamed examples and addressing some comments from Saad
wainola Aug 27, 2024
ccb9491
chore: update lock file
wainola Aug 27, 2024
2b2ef9e
chore: more pr comments + readme + fixing test
wainola Aug 27, 2024
db0e63f
chore: small adjustments to the example
wainola Aug 27, 2024
b7ab0f0
chore: addressing last pr comment
wainola Aug 27, 2024
9c21334
chore: fixing issue with test
wainola Aug 27, 2024
040fc3c
chore: last pr comments
wainola Sep 4, 2024
b94b67e
chore: merge with main
wainola Sep 4, 2024
f87fdde
chore; fix tests
wainola Sep 4, 2024
dfbbbf0
chore: last comments
wainola Sep 5, 2024
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
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
"evm:lint": "yarn workspace @buildwithsygma/evm lint",
"evm:lint:fix": "yarn workspace @buildwithsygma/evm lint:fix",
"evm:test:unit": "yarn workspace @buildwithsygma/evm test:unit",
"build:all": "yarn workspace @buildwithsygma/core build:all; yarn workspace @buildwithsygma/evm build:all",
"btc:build": "yarn workspace @buildwithsygma/btc build:all",
"btc:cleanDist": "yarn workspace @buildwithsygma/btc clean",
"btc:test": "yarn workspace @buildwithsygma/btc test",
"btc:lint": "yarn workspace @buildwithsygma/btc lint",
"btc:lint:fix": "yarn workspace @buildwithsygma/btc lint:fix",
"build:all": "yarn workspace @buildwithsygma/core build:all; yarn workspace @buildwithsygma/evm build:all; yarn workspace @buildwithsygma/btc build:all",
wainola marked this conversation as resolved.
Show resolved Hide resolved
"clean:all": "yarn workspace @buildwithsygma/core clean; yarn workspace @buildwithsygma/evm clean",
wainola marked this conversation as resolved.
Show resolved Hide resolved
"docs": "typedoc"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/btc/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: '../../.eslintrc.cjs',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
sourceType: 'module',
tsconfigRootDir: __dirname,
},
};
45 changes: 45 additions & 0 deletions packages/btc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
/dist
/dist-cjs
/dist-esm
/types


# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
.vscode
.history

# runtime config
public/chainbridge-runtime-config.js

# IDE
.idea/

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
26 changes: 26 additions & 0 deletions packages/btc/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


integration/
coverage/
dist/
keysN1/
keysN2/
config/
src/

# Ignore configs
setupTests.ts
.eslintrc.cjs
.prettierrc.json
docker-compose.yml
Dockerfile
jest.config.cjs
tsconfig.json
tsconfig.*.json
tsconfig.tsbuildinfo
rollup.config.js
**/__test__/*

# Ignore random junk
.DS_Store
node_modules/**
7 changes: 7 additions & 0 deletions packages/btc/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "all",
"useTabs": false,
"arrowParens": "avoid"
}
1 change: 1 addition & 0 deletions packages/btc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# btc
wainola marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions packages/btc/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
roots: ['<rootDir>/src', '<rootDir>/test'],
extensionsToTreatAsEsm: ['.ts', '.tsx'],
verbose: true,
preset: 'ts-jest/presets/default-esm',
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
testEnvironment: 'jsdom',
testTimeout: 15000,
transform: {
'^.+\\.(ts|tsx)?$': ['ts-jest', { useESM: true }],
},
testPathIgnorePatterns: ['./dist'],
automock: false,
setupFiles: [
"./test/setupJest.js"
]
};
63 changes: 63 additions & 0 deletions packages/btc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@buildwithsygma/btc",
wainola marked this conversation as resolved.
Show resolved Hide resolved
"version": "0.0.1",
"description": "Core primitives for bridging and message passing",
"main": "dist-esm/index.js",
"types": "types/index.d.ts",
"exports": {
".": {
"import": "./dist-esm/index.js",
"require": "./dist-cjs/index.js"
}
},
"type": "module",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/sygmaprotocol/sygma-sdk"
},
"scripts": {
"test": "jest --watchAll --detectOpenHandles --silent",
"test:unit": "jest --detectOpenHandles",
"run:all": "concurrently \"yarn run prepareNodes\" \"yarn run test\"",
"build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > ./dist-esm/package.json",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > ./dist-cjs/package.json",
"build:types": "tsc -p tsconfig.types.json",
"build:all": "yarn build:esm && yarn build:cjs && yarn build:types",
"build:typedocs:html": "typedoc --options typedoc.json",
"build:typedocs:markdown": "typedoc --options typedoc.markdown.json",
"build:typedocs:asjson": "typedoc --options typedoc.asjson.json",
"lint": "eslint 'src/**/*.ts'",
"lint:fix": "yarn run lint --fix",
"run:nodes": "docker-compose -f docker-compose.yml up",
"clean": "rm -rf ./dist ./dist-cjs ./dist-esm ./types"
},
"keywords": [
"sygma",
"sygmaprotocol",
"buildwithsygma",
"web3",
"bridge",
"bitcoin"
],
"author": "Sygmaprotocol Product Team",
"license": "LGPL-3.0-or-later",
"devDependencies": {
"@types/jest": "^29.4.0",
"concurrently": "7.0.0",
"eslint": "8",
"hardhat": "2.8.2",
"jest": "^29.4.1",
"jest-environment-jsdom": "^29.4.1",
"jest-extended": "1.2.0",
"jest-fetch-mock": "^3.0.3",
"ts-jest": "^29.0.5",
"ts-node": "10.9.1",
"typedoc": "^0.24.1",
"typedoc-plugin-markdown": "^3.15.1",
"typescript": "5.0.4"
},
"dependencies": {
"@buildwithsygma/core": "workspace:^"
}
}
65 changes: 34 additions & 31 deletions packages/btc/src/base-transfer.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { BitcoinResource } from "@buildwithsygma/core/src";
import { Config } from "@buildwithsygma/core/types";

type BaseTransferParams = {
destinationAddress: string;
amount: bigint;
};

type BitcoinTransferRequest = {
destinationAddress: string;
amount: bigint;
depositAddress: string;
};

export async function createBitcoinTransferRequest(params: BaseTransferParams): Promise<BaseTransfer> {
throw new Error("Method not implemented");
}
import type { BitcoinResource } from '@buildwithsygma/core/src';
import type { Config, Domain } from '@buildwithsygma/core/types';
import type { BaseTransferParams } from 'types';

export abstract class BaseTransfer {
constructor(transfer: BaseTransferParams, config: Config) {}
protected destinationAddress: string;
protected amount: bigint;
protected config: Config;
protected resource: BitcoinResource;
protected sourceDomain: Domain;

constructor(transfer: BaseTransferParams, config: Config) {
this.destinationAddress = transfer.destinationAddress;
this.amount = transfer.amount;
this.sourceDomain = config.getDomain(transfer.sourceDomain);

wainola marked this conversation as resolved.
Show resolved Hide resolved
const resources = config.getResources(this.sourceDomain) as BitcoinResource[];
const resource = this.findResource(resources, transfer.resource);

if (resource) {
this.resource = resource;
} else {
throw new Error('Resource not found.');
}

this.config = config;
}

private findResource(
resources: BitcoinResource[],
resourceIdentifier: string | BitcoinResource,
): BitcoinResource | undefined {
throw new Error("Method not implemented");
return resources.find(resource => {
if (typeof resourceIdentifier === 'string') {
return resource.resourceId === resourceIdentifier;
}

return resource === resourceIdentifier;
});
}

/**
* Set resource to be transferred.
* @param {BitcoinResource} resource
*/
setResource(resource: BitcoinResource): void {
throw new Error("Method not implemented");
}

getUriEncodedUtxoRequest(btcTransferRequest: BaseTransferParams): string {
throw new Error("Method not implemented");
this.resource = resource;
}

getBTCTransferRequest(): BitcoinTransferRequest {
throw new Error("Method not implemented");
}
}
}
9 changes: 9 additions & 0 deletions packages/btc/src/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Environment } from '@buildwithsygma/core';

declare global {
namespace NodeJS {
interface ProcessEnv {
SYGMA_ENV: Environment;
}
}
}
38 changes: 38 additions & 0 deletions packages/btc/src/fungible.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Config } from '@buildwithsygma/core';
import type { BaseTransferParams, BitcoinTransferRequest } from 'types';

import { BaseTransfer } from './base-transfer.js';

export async function createBitcoinFungibleTransfer(
params: BaseTransferParams,
): Promise<BitcoinTransfer> {
const config = new Config();
await config.init(process.env.SYGMA_ENV);
const transfer = new BitcoinTransfer(params, config);

return transfer;
}

class BitcoinTransfer extends BaseTransfer {
protected destinationAddress: string;
wainola marked this conversation as resolved.
Show resolved Hide resolved
protected amount: bigint;

constructor(transfer: BaseTransferParams, config: Config) {
super(transfer, config);
this.destinationAddress = transfer.destinationAddress;
this.amount = transfer.amount;
}

getUriEncodedUtxoRequest(): string {
const { address } = this.resource;
return `bitcoin:${address}?amount=${this.amount}&destinationAddress=${this.destinationAddress}`;
wainola marked this conversation as resolved.
Show resolved Hide resolved
}

getBTCTransferRequest(): BitcoinTransferRequest {
return {
destinationAddress: this.destinationAddress,
amount: this.amount,
depositAddress: this.resource.address,
};
}
}
3 changes: 2 additions & 1 deletion packages/btc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./base-transfer.js";
export * from './base-transfer.js';
export * from './fungible.js';
14 changes: 14 additions & 0 deletions packages/btc/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { BitcoinResource, Domainlike } from '@buildwithsygma/core';

export type BaseTransferParams = {
wainola marked this conversation as resolved.
Show resolved Hide resolved
sourceDomain: Domainlike;
destinationAddress: string;
amount: bigint;
resource: BitcoinResource | string;
};

export type BitcoinTransferRequest = {
destinationAddress: string;
amount: bigint;
depositAddress: string;
};
2 changes: 2 additions & 0 deletions packages/btc/test/setupTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// setupJest.js or similar file
require('jest-fetch-mock').enableMocks();
13 changes: 13 additions & 0 deletions packages/btc/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"exclude": [
"src/**/__test__/**",
"test/**",
],
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"module": "commonjs",
"outDir": "./dist-cjs"
}
}
12 changes: 12 additions & 0 deletions packages/btc/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"exclude": [
"src/**/__test__/**",
"test/**"
],
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ES2020",
"esModuleInterop": true,
"outDir": "./dist-esm"
}
}
Loading
Loading