Skip to content

Commit a0d9a39

Browse files
committed
Add base class containing migrated pegin logic
1 parent 210c4e4 commit a0d9a39

File tree

8 files changed

+427
-0
lines changed

8 files changed

+427
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@
2424
"tsup": "^8.3.6",
2525
"typescript": "^5.7.3",
2626
"typescript-eslint": "^8.24.0"
27+
},
28+
"dependencies": {
29+
"@rsksmart/rsk-precompiled-abis": "6.0.0-ARROWHEAD",
30+
"bitcoinjs-lib": "^6.1.7",
31+
"ethers": "^6.13.5"
2732
}
2833
}

pnpm-lock.yaml

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bridge.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { bridge } from '@rsksmart/rsk-precompiled-abis'
2+
import { ethers } from 'ethers'
3+
import type { Network } from './types'
4+
5+
export class Bridge {
6+
provider: ethers.JsonRpcProvider
7+
bridgeContract: ethers.Contract
8+
publicNodes: Record<Network, string> = {
9+
mainnet: 'https://public-node.rsk.co',
10+
testnet: 'https://public-node.testnet.rsk.co',
11+
}
12+
13+
constructor(network: Network, rpcProviderUrl?: string) {
14+
this.provider = new ethers.JsonRpcProvider(rpcProviderUrl ?? this.publicNodes[network])
15+
this.bridgeContract = new ethers.Contract(bridge.address, bridge.abi, this.provider)
16+
}
17+
18+
async getFederationAddress(): Promise<string> {
19+
return this.bridgeContract.getFederationAddress?.()
20+
}
21+
}

src/errors.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class AmountBelowMinError extends Error {
2+
constructor(message?: string) {
3+
super(message)
4+
this.name = 'AmountBelowMinError'
5+
}
6+
}
7+
8+
export class NotEnoughFundsError extends Error {
9+
constructor(message?: string) {
10+
super(message)
11+
this.name = 'NotEnoughFundsError'
12+
}
13+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { PowPegSDK } from './sdk/powpeg'
2+
export * from './types'

0 commit comments

Comments
 (0)