Skip to content

Commit

Permalink
Update Acre SDK initialization for tBTC module
Browse files Browse the repository at this point in the history
The tBTC module initialization was updated to match the tBTC module
wrapper for tBTC SDK.
  • Loading branch information
nkuba committed Apr 24, 2024
1 parent 3c08bd0 commit a1095d7
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions sdk/src/acre.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { TBTC } from "@keep-network/tbtc-v2.ts"
import { AcreContracts } from "./lib/contracts"
import { ChainEIP712Signer } from "./lib/eip712-signer"
import {
Expand All @@ -7,10 +6,13 @@ import {
getEthereumContracts,
} from "./lib/ethereum"
import { StakingModule } from "./modules/staking"
import Tbtc from "./modules/tbtc"
import { EthereumSignerCompatibleWithEthersV5 } from "./lib/utils"

const TBTC_API_ENDPOINT = process.env.TBTC_API_ENDPOINT ?? ""

class Acre {
readonly #tbtc: TBTC
readonly #tbtc: Tbtc

readonly #messageSigner: ChainEIP712Signer

Expand All @@ -21,7 +23,7 @@ class Acre {
constructor(
_contracts: AcreContracts,
_messageSigner: ChainEIP712Signer,
_tbtc: TBTC,
_tbtc: Tbtc,
) {
this.contracts = _contracts
this.#tbtc = _tbtc
Expand All @@ -37,30 +39,17 @@ class Acre {
signer: EthereumSignerCompatibleWithEthersV5,
network: EthereumNetwork,
): Promise<Acre> {
const tbtc = await Acre.#getTBTCEthereumSDK(signer, network)
const contracts = getEthereumContracts(signer, network)
const messages = new EthereumEIP712Signer(signer)

return new Acre(contracts, messages, tbtc)
}
const tbtc = await Tbtc.initialize(
signer,
network,
TBTC_API_ENDPOINT,
contracts.bitcoinDepositor,
)

static #getTBTCEthereumSDK(
signer: EthereumSignerCompatibleWithEthersV5,
network: EthereumNetwork,
): Promise<TBTC> {
switch (network) {
case "sepolia":
// @ts-expect-error We require the `signer` must include the ether v5
// signer's methods used in tBTC-v2.ts SDK so if we pass signer from
// ethers v6 it won't break the Acre SDK initialization.
return TBTC.initializeSepolia(signer)
case "mainnet":
default:
// @ts-expect-error We require the `signer` must include the ether v5
// signer's methods used in tBTC-v2.ts SDK so if we pass signer from
// ethers v6 it won't break the Acre SDK initialization.
return TBTC.initializeMainnet(signer)
}
return new Acre(contracts, messages, tbtc)
}
}

Expand Down

0 comments on commit a1095d7

Please sign in to comment.