### Execute SUI Gateway Initialization TypeScript Script Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/sui/deploy_l2/docs/mintercap-fix-deployment-guide.md These bash commands prepare the environment by installing the necessary SUI JavaScript SDK, then execute the TypeScript initialization script using `ts-node`. This script orchestrates the setup process for the SUI Gateway, leveraging the configured parameters. ```bash npm install @mysten/sui.js npx ts-node scripts/initialize_gateway_with_ptb.ts ``` -------------------------------- ### Install SUI SDK Dependency for tBTC-v2 Integration Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Provides the npm command necessary to install the `@mysten/sui` package, which is a fundamental prerequisite for developing applications that integrate tBTC-v2 with the SUI blockchain. ```bash npm install @mysten/sui@1.34.0 ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/threshold-network/tbtc-v2/blob/main/CONTRIBUTING.adoc This command installs pre-commit hooks, which automate linter checks before commits. This helps ensure code compliance and prevents non-compliant code from being pushed to the repository. ```Bash pre-commit install ``` -------------------------------- ### Install tBTC SDK Development Dependencies Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/README.md Installs all necessary development dependencies for the tBTC SDK project. This command should be run after cloning the repository to set up the development environment. ```bash yarn install ``` -------------------------------- ### Run Gateway Initialization Script Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/sui/deploy_l2/docs/devnet-testing-plan.md Commands to install Node.js dependencies and execute a TypeScript script responsible for initializing the Gateway with pre-tBTC. This script requires Node.js and npm to be installed and configured. ```bash npm install @mysten/sui.js npx ts-node scripts/initialize_gateway_with_ptb.ts ``` -------------------------------- ### Perform a Complete Cross-Chain BTC Deposit to SUI Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Outlines the comprehensive, multi-step process for initiating and completing a cross-chain Bitcoin deposit to SUI using the tBTC SDK. This includes SDK initialization, SUI cross-chain setup, generating a Bitcoin deposit address, and performing the initial 'reveal' step, with subsequent steps handled by a relayer. ```typescript import { TBTC } from "@keep-network/tbtc-v2.ts" async function performCrossChainDeposit() { // 1. Initialize TBTC SDK const tbtc = await TBTC.initializeSepolia() // 2. Create a SUI keypair or use wallet const suiKeypair = new Ed25519Keypair() // 3. Initialize cross-chain for SUI await tbtc.initializeCrossChain("Sui", suiKeypair) // 4. Generate deposit address (Step 0 of the flow) const deposit = await tbtc.deposits.initiateCrossChainDeposit( "tb1q...", // Bitcoin recovery address "Sui" ) console.log("Send BTC to:", deposit.getBitcoinAddress()) // 5. After BTC is sent and confirmed, initialize on SUI (Step 1) await deposit.initializeReveal() // The relayer handles steps 2-13 automatically console.log( "Deposit initialized! The relayer will complete the cross-chain transfer." ) } ``` -------------------------------- ### Install Node.js dependencies for tBTC v2 contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/solidity/README.adoc Installs all required Node.js packages for the tBTC v2 smart contracts project using Yarn. This command should be executed before attempting to build or test the contracts to ensure all dependencies are available. ```Bash yarn install ``` -------------------------------- ### Install tBTC SDK Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/README.md Installs the tBTC v2 SDK into your project, providing core functionalities for the tBTC Bitcoin bridge. This library is essential for integrating tBTC into your application. ```bash yarn add @keep-network/tbtc-v2.ts ``` ```bash npm i @keep-network/tbtc-v2.ts ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/threshold-network/tbtc-v2/blob/main/system-tests/README.adoc Installs all required project dependencies as defined in the `package.json` file. This command ensures that the development environment is set up correctly by fetching and linking necessary packages. ```Shell yarn install ``` -------------------------------- ### Install tBTC v2 Monitoring Tool Dependencies Source: https://github.com/threshold-network/tbtc-v2/blob/main/monitoring/README.adoc Instructions to install project dependencies using Yarn. This command fetches all required packages for the monitoring tool, ensuring the environment is set up correctly for development or execution. ```Shell yarn install ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/starknet/README.md Installs all required Node.js and Yarn dependencies for the tBTC v2 StarkNet integration project. This command should be run after cloning the repository to set up the development environment. ```bash yarn install ``` -------------------------------- ### Start Hardhat Local Ethereum Network Source: https://github.com/threshold-network/tbtc-v2/blob/main/system-tests/README.adoc Launches a local Ethereum network using Hardhat in a standalone node mode. The `--no-deploy` flag prevents automatic contract deployment, providing a clean and flexible environment for manual deployment or specific test setups. ```Shell npx hardhat node --no-deploy ``` -------------------------------- ### Install Ethers v5 Dependency Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/README.md Installs the Ethers.js v5 library, a crucial dependency for the tBTC SDK to initialize a signer or provider. It's important to use this specific version as compatibility with newer Ethers versions is not guaranteed. ```bash yarn add ethers@legacy-v5 ``` ```bash npm i ethers@legacy-v5 ``` -------------------------------- ### Build and Deploy SUI Move Contract to Testnet Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/sui/deploy_l2/docs/mintercap-fix-deployment-guide.md These bash commands are used to compile the updated SUI Move contract and then publish it to a SUI testnet. A `gas-budget` is specified to ensure the transaction has sufficient gas for deployment. ```bash sui move build sui client publish --gas-budget 100000000 ``` -------------------------------- ### Initialize tBTC SDK for SUI Cross-Chain Integration Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/README.md This TypeScript example demonstrates how to load the necessary SUI cross-chain interfaces for the tBTC SDK. It shows two common methods for initialization: one using a wallet adapter and another using an `Ed25519Keypair` for programmatic control. ```typescript import { loadSuiCrossChainInterfaces } from "@keep-network/tbtc-v2.ts/lib/sui" import { SuiClient } from "@mysten/sui/client" // Using wallet adapter const suiInterfaces = await loadSuiCrossChainInterfaces( walletAdapter, Chains.Sui.Testnet ) // Using keypair import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519" const keypair = new Ed25519Keypair() const suiInterfaces = await loadSuiCrossChainInterfaces( keypair, Chains.Sui.Testnet ) ``` -------------------------------- ### SUI Network Production Considerations Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Provides critical information for deploying SUI integrations in a production environment. This includes warnings about rate limits on public RPC endpoints, recommending dedicated nodes, and listing the official RPC endpoints for SUI Mainnet, Testnet, and Devnet. ```APIDOC Warning: Using public SUI RPC endpoint. Consider using a dedicated node for production. Mainnet: https://fullnode.mainnet.sui.io:443 Testnet: https://fullnode.testnet.sui.io:443 Devnet: https://fullnode.devnet.sui.io:443 ``` -------------------------------- ### Initialize SUI Cross-Chain Interfaces with Keypair or Wallet Adapter Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Demonstrates two distinct methods for initializing SUI cross-chain interfaces using the `@keep-network/tbtc-v2.ts` library. The first method utilizes an `Ed25519Keypair` for direct control, while the second integrates with a generic wallet adapter, providing flexibility for different application architectures. ```typescript import { SuiClient } from "@mysten/sui/client" import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519" import { loadSuiCrossChainInterfaces } from "@keep-network/tbtc-v2.ts" import { Chains } from "@keep-network/tbtc-v2.ts" // Initialize with a keypair async function initializeWithKeypair() { // Create or import a keypair const keypair = new Ed25519Keypair() // Load SUI interfaces const suiInterfaces = await loadSuiCrossChainInterfaces( keypair, Chains.Sui.Testnet ) return suiInterfaces } // Initialize with a wallet adapter async function initializeWithWallet(walletAdapter: any) { // Wallet adapter should have signAndExecuteTransaction method const suiInterfaces = await loadSuiCrossChainInterfaces( walletAdapter, Chains.Sui.Testnet ) return suiInterfaces } ``` -------------------------------- ### Install Node.js Dependencies for Smart Contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/yearn/README.adoc Installs all required Node.js packages and dependencies for the smart contract project using Yarn. This step should be performed before building or testing the contracts. ```Shell yarn install ``` -------------------------------- ### Build tBTC v2 smart contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/solidity/README.adoc Compiles the tBTC v2 smart contracts using Yarn and the Hardhat development environment. Upon successful compilation, the generated contract artifacts will be stored in the project's `build` directory. ```Bash yarn build ``` -------------------------------- ### TypeScript Configuration for SUI Gateway Initialization Script Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/sui/deploy_l2/docs/mintercap-fix-deployment-guide.md This TypeScript object defines the essential configuration parameters required for the SUI Gateway initialization script. It includes identifiers for the deployed package, various admin capabilities, shared object states, Wormhole details, and SUI RPC connection information with the admin's private key. ```typescript const config = { packageId: 'YOUR_PACKAGE_ID', adminCaps: { tbtc: 'YOUR_TBTC_ADMIN_CAP', gateway: 'YOUR_GATEWAY_ADMIN_CAP', treasuryCap: 'YOUR_TREASURY_CAP' }, sharedObjects: { tokenState: 'YOUR_TOKEN_STATE', gatewayState: 'YOUR_GATEWAY_STATE' }, wormhole: { coreState: 'YOUR_WORMHOLE_STATE', wrappedTbtcType: 'YOUR_WRAPPED_TBTC_TYPE' }, sui: { rpc: 'https://fullnode.testnet.sui.io:443', privateKey: 'YOUR_ADMIN_PRIVATE_KEY' } }; ``` -------------------------------- ### tBTC v2 StarkNet Project Yarn Command Reference Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/starknet/README.md A comprehensive reference for all Yarn commands used in the tBTC v2 StarkNet integration project. This includes commands for installation, development tasks (cleaning, building, testing), deployment to various networks, contract verification, and exporting deployment artifacts. ```APIDOC Installation: yarn install: Installs all required Node.js and Yarn dependencies. Development Commands: yarn clean: Cleans build artifacts and cache. yarn build: Compiles contracts. yarn test: Runs tests with external deployments. yarn test:integration: Runs integration tests. Deployment Commands: yarn deploy:test: Deploys contracts with test stubs for local testing. yarn deploy:sepolia: Deploys contracts to the Sepolia testnet. yarn deploy:mainnet: Deploys contracts to the Ethereum mainnet. Verification Command: yarn verify --network : Verifies deployed contracts on Etherscan for the specified network. Requires ETHERSCAN_API_KEY. Artifact Export Commands: yarn export-artifacts:sepolia: Exports deployment artifacts for the Sepolia testnet. yarn export-artifacts:mainnet: Exports deployment artifacts for the mainnet. ``` -------------------------------- ### Full Flow for Creating a SUI Cross-Chain Deposit with tBTC SDK Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/README.md This comprehensive TypeScript example illustrates the end-to-end process of initiating a cross-chain deposit to SUI. It covers initializing the tBTC SDK with SUI, generating a Bitcoin deposit address, and triggering the `initializeReveal()` call on SUI after the Bitcoin transaction has been confirmed. ```typescript // Initialize TBTC SDK with SUI const tbtc = await TBTC.initializeCrossChain("Sui", ethereumProvider, suiWallet) // Create deposit const deposit = await tbtc.deposits.initiateCrossChainDeposit( bitcoinRecoveryAddress, "Sui" ) // Get deposit address and fund with Bitcoin console.log("Send BTC to:", await deposit.getBitcoinAddress()) // After Bitcoin confirmation, initialize on SUI await deposit.initializeReveal() ``` -------------------------------- ### Deploy tBTC v2 contracts to a specified network Source: https://github.com/threshold-network/tbtc-v2/blob/main/solidity/README.adoc Deploys all tBTC v2 smart contracts to the target blockchain network specified by ``. This task automatically builds the contracts if they haven't been built or if changes are detected, and it produces an `export.json` file containing deployment information. ```Bash yarn deploy --network ``` -------------------------------- ### Monitor SUI DepositInitialized Events for Debugging Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Describes the structure of the `DepositInitialized` event emitted by the SDK, which is vital for debugging and confirming that a deposit has been successfully initiated on SUI. It details the `type` and `parsedJson` fields, including `deposit_key`, `funding_tx`, `deposit_reveal`, `deposit_owner`, and `sender`. ```APIDOC SUI DepositInitialized event: { type: '0x1db1fc...::BitcoinDepositor::DepositInitialized', parsedJson: { deposit_key: '0x...', funding_tx: '0x...', deposit_reveal: '0x...', deposit_owner: '0x...', sender: '0x...' } } ``` -------------------------------- ### Alternative Two-Transaction Gateway Initialization in TypeScript Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/sui/deploy_l2/docs/mintercap-fix-deployment-guide.md This TypeScript snippet outlines an alternative two-transaction flow for Gateway initialization, suitable when a single Programmable Transaction Block (PTB) is not feasible or preferred. The first transaction adds the minter and returns the MinterCap to the admin, while the second uses that MinterCap to initialize the Gateway. ```typescript // Transaction 1: Add minter and send MinterCap to admin add_minter_to_recipient(adminCap, tokenState, gatewayAddress, adminAddress) // Transaction 2: Initialize with MinterCap initialize_gateway(adminCap, gatewayState, wormholeState, minterCapId, treasuryCap) ``` -------------------------------- ### Handle Deposit Initialization Without Vault for SUI Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Explains a specific difference in deposit handling for SUI: the 'vault' parameter, typically used in EVM chains, is ignored. For SUI, deposits are directed straight to user addresses, simplifying the deposit initialization process. ```typescript // The vault parameter is ignored for SUI await depositor.initializeDeposit(tx, index, receipt) // No vault needed ``` -------------------------------- ### Execute SUI Transactions Using SuiClient Pattern Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Details the internal mechanism for executing transactions on the SUI blockchain. It shows how the SDK leverages the `SuiClient`'s `signAndExecuteTransaction` method, including options to display transaction effects, events, and object changes for comprehensive feedback. ```typescript // Internally, the SDK uses: const result = await client.signAndExecuteTransaction({ signer: keypair, transaction: tx, options: { showEffects: true, showEvents: true, showObjectChanges: true, }, }) ``` -------------------------------- ### New `add_minter_with_cap` Function for SUI TBTC Module Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/sui/deploy_l2/docs/mintercap-fix-deployment-guide.md This new `public fun` in the SUI TBTC Move module resolves the MinterCap ownership issue by returning the `MinterCap` to the caller instead of transferring it. This enables shared objects like the Gateway to be properly initialized, while maintaining existing security checks and event emissions. ```Move /// Add a new minter and return the MinterCap to the caller /// This variant is designed for cases where the minter is a shared object /// and cannot receive the MinterCap directly (e.g., Gateway) public fun add_minter_with_cap( _: &AdminCap, state: &mut TokenState, minter: address, ctx: &mut TxContext, ): MinterCap { assert!(!is_minter(state, minter), E_ALREADY_MINTER); vector::push_back(&mut state.minters, minter); let minter_cap = MinterCap { id: object::new(ctx), minter, }; event::emit(MinterAdded { minter }); minter_cap // Return instead of transfer } ``` -------------------------------- ### Initialize and Use tBTC SDK Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/README.md Demonstrates how to import, initialize, and access features of the tBTC SDK. It shows how to create an SDK instance using an Ethers signer and then interact with deposits, redemptions, contracts, and the Bitcoin client. ```typescript // Import SDK entrypoint component. import { TBTC } from "@keep-network/tbtc-v2.ts" // Create an instance of ethers signer. const signer = (...) // Initialize the SDK. const sdk = await TBTC.initializeMainnet(signer) // Access SDK features. sdk.deposits.(...) sdk.redemptions.(...) // Access tBTC smart contracts directly. sdk.tbtcContracts.(...) // Access Bitcoin client directly. sdk.bitcoinClient.(...) ``` -------------------------------- ### Get Events from Ethereum Contract API Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/ArbitrumBitcoinDepositor.md Retrieves events emitted by an Ethereum contract. The search for events starts from a specified block number, or from a default block if not provided. This method is inherited from `EthersContractHandle.getEvents`. ```APIDOC getEvents(eventName: string, options?: Options, ...filterArgs: unknown[]): Promise - Description: Get events emitted by the Ethereum contract. It starts searching from provided block number. If the GetEvents.Options#fromBlock option is missing it looks for a contract's defined property _deployedAtBlockNumber. If the property is missing starts searching from block 0. - Parameters: - eventName: string - Name of the event. - options?: Options - Options for events fetching. - ...filterArgs: unknown[] - Arguments for events filtering. - Returns: Promise - Array of found events. - Inherited from: EthersContractHandle.getEvents ``` -------------------------------- ### StarkNetTBTCToken Class Constructor Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/StarkNetTBTCToken.md Initializes a new instance of the StarkNetTBTCToken class. It requires a configuration object containing chain-specific details and a StarkNet provider for blockchain interaction. An error is thrown if the provider is not supplied or the configuration is invalid. ```APIDOC new StarkNetTBTCToken(config: StarkNetTBTCTokenConfig, provider: StarkNetProvider): StarkNetTBTCToken - Description: Creates a new StarkNetTBTCToken instance. - Parameters: - config: StarkNetTBTCTokenConfig - Configuration containing chainId and token contract address - provider: StarkNetProvider - StarkNet provider for blockchain interaction - Returns: StarkNetTBTCToken - Throws: Error if provider is not provided or config is invalid ``` -------------------------------- ### Configure Git to use HTTPS instead of Git protocol Source: https://github.com/threshold-network/tbtc-v2/blob/main/solidity/README.adoc Provides a workaround for the 'The unauthenticated git protocol on port 9418 is no longer supported' error. This command globally reconfigures Git to use the HTTPS protocol for repository access instead of the deprecated `git://` protocol, resolving dependency installation issues. ```Bash git config --global url."https://".insteadOf git:// ``` -------------------------------- ### StarkNet Depositor Class Methods Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/StarkNetBitcoinDepositor.md Comprehensive API documentation for the `StarkNetDepositor` class, detailing its methods for managing cross-chain deposits, formatting StarkNet addresses, and querying chain-specific properties. ```APIDOC StarkNetDepositor Class Methods: formatStarkNetAddressAsBytes32(address: string): string - Description: Formats a StarkNet address to ensure it's a valid bytes32 value. - Parameters: - address: string - The StarkNet address to format. - Returns: string - The formatted address with 0x prefix and 64 hex characters. - Throws: Error if the address is invalid. getChainIdentifier(): ChainIdentifier - Description: Gets the chain-specific identifier of this contract. - Returns: ChainIdentifier - Throws: Always throws since StarkNet deposits are handled via L1. - Implements: BitcoinDepositor.getChainIdentifier getChainName(): string - Description: Gets the chain name for this depositor. - Returns: string - The chain name (e.g., "StarkNet"). getDepositOwner(): undefined | ChainIdentifier - Description: Gets the identifier that should be used as the owner of deposits. - Returns: undefined | ChainIdentifier - The StarkNet address set as deposit owner, or undefined if not set. - Implements: BitcoinDepositor.getDepositOwner getProvider(): StarkNetProvider - Description: Gets the StarkNet provider used by this depositor. - Returns: StarkNetProvider - The StarkNet provider instance. initializeDeposit(depositTx: BitcoinRawTxVectors, depositOutputIndex: number, deposit: DepositReceipt, vault?: ChainIdentifier): Promise - Description: Initializes a cross-chain deposit by calling the external relayer service. This method calls the external service to trigger the deposit transaction via a relayer off-chain process. It returns the transaction hash as a Hex or a full transaction receipt. - Parameters: - depositTx: BitcoinRawTxVectors - The Bitcoin transaction data. - depositOutputIndex: number - The output index of the deposit. - deposit: DepositReceipt - The deposit receipt containing all deposit parameters. - vault?: ChainIdentifier - Optional vault address. - Returns: Promise - The transaction hash or full transaction receipt from the relayer response. - Throws: Error if deposit owner not set or relayer returns unexpected response. - Implements: BitcoinDepositor.initializeDeposit isRetryableError(error: any): boolean - Description: Determines if an error is retryable. - Parameters: - error: any - The error to check. - Returns: boolean - True if the error is retryable. setDepositOwner(depositOwner: ChainIdentifier): void - Description: Sets the identifier that should be used as the owner of deposits. ``` -------------------------------- ### Initialize tBTC v2 SDK for Various Networks Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/TBTC.md Comprehensive API documentation for the tBTC v2 SDK's initialization functions. This includes the general `initialize` function for custom network configurations, `initializeMainnet` for Ethereum and Bitcoin mainnets, and `initializeSepolia` for Ethereum Sepolia and Bitcoin testnet. Each function requires an Ethereum signer and optionally supports cross-chain functionality. ```APIDOC initialize(signer: EthereumSigner, ethereumChainId: Ethereum, bitcoinNetwork: BitcoinNetwork, crossChainSupport: boolean = false): Promise - Description: Initializes the tBTC v2 SDK entrypoint. Throws an error if the underlying signer's Ethereum network is other than the given Ethereum network. - Parameters: - signer: EthereumSigner (default: undefined) - Ethereum signer. - ethereumChainId: Ethereum (default: undefined) - Ethereum chain ID. - bitcoinNetwork: BitcoinNetwork (default: undefined) - Bitcoin network. - crossChainSupport: boolean (default: false) - Whether to enable cross-chain support. False by default. - Returns: Promise initializeMainnet(signer: EthereumSigner, crossChainSupport?: boolean = false): Promise - Description: Initializes the tBTC v2 SDK entrypoint for Ethereum and Bitcoin mainnets. The initialized instance uses default Electrum servers to interact with Bitcoin mainnet. Throws an error if the signer's Ethereum network is other than Ethereum mainnet. - Parameters: - signer: EthereumSigner (default: undefined) - Ethereum signer. - crossChainSupport: boolean (default: false) - Whether to enable cross-chain support. False by default. - Returns: Promise initializeSepolia(signer: EthereumSigner, crossChainSupport?: boolean = false): Promise - Description: Initializes the tBTC v2 SDK entrypoint for Ethereum Sepolia and Bitcoin testnet. The initialized instance uses default Electrum servers to interact with Bitcoin testnet. Throws an error if the signer's Ethereum network is other than Ethereum mainnet. - Parameters: - signer: EthereumSigner (default: undefined) - Ethereum signer. - crossChainSupport: boolean (default: false) - Whether to enable cross-chain support. False by default. - Returns: Promise ``` -------------------------------- ### Get Deposit Owner for Bitcoin Depositor API Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/ArbitrumBitcoinDepositor.md Fetches the current owner of a deposit. This method is an implementation of the `BitcoinDepositor.getDepositOwner` interface. ```APIDOC getDepositOwner(): undefined | ChainIdentifier - Returns: undefined | ChainIdentifier - Implementation of: BitcoinDepositor.getDepositOwner ``` -------------------------------- ### Get Chain Identifier for Bitcoin Depositor API Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/ArbitrumBitcoinDepositor.md Retrieves the chain identifier associated with the Bitcoin depositor. This method is an implementation of the `BitcoinDepositor.getChainIdentifier` interface. ```APIDOC getChainIdentifier(): undefined | ChainIdentifier - Returns: undefined | ChainIdentifier - Implementation of: BitcoinDepositor.getChainIdentifier ``` -------------------------------- ### Determine Coordination Block Source: https://github.com/threshold-network/tbtc-v2/blob/main/docs/rfc/rfc-12.adoc Checks if the current Ethereum block is a coordination block by verifying if its number is a multiple of the 'coordination_frequency'. This condition signals the start of a new coordination window. ```Solidity current_block % coordination_frequency == 0 ``` -------------------------------- ### Initialize tBTC v2 SDK with Custom Contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/TBTC.md Initializes the tBTC v2 SDK entrypoint using custom tBTC contracts and a custom Bitcoin client implementation. This is particularly useful for local development and testing with different contract and Bitcoin network configurations. ```APIDOC initializeCustom(tbtcContracts: TBTCContracts, bitcoinClient: BitcoinClient): Promise - Description: Initializes the tBTC v2 SDK entrypoint with custom tBTC contracts and Bitcoin client. - Parameters: - tbtcContracts: TBTCContracts - Custom tBTC contracts handle. - bitcoinClient: BitcoinClient - Custom Bitcoin client implementation. - Returns: Promise - Initialized tBTC v2 SDK entrypoint. - Dev: This function is especially useful for local development as it gives flexibility to combine different implementations of tBTC v2 contracts with different Bitcoin networks. ``` -------------------------------- ### Get Cross-Chain Contracts for L2 Chain Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/TBTC.md Retrieves cross-chain contract interfaces for a specified Layer 2 blockchain. This function returns the relevant interfaces if initialized, otherwise undefined. ```APIDOC getCrossChainContracts(l2ChainName: DestinationChainName) - Parameters: - l2ChainName: DestinationChainName - Name of the L2 chain for which to get cross-chain contracts. - Returns: undefined | CrossChainInterfaces - Cross-chain contracts for the given L2 chain or undefined if not initialized. ``` -------------------------------- ### StarkNetBitcoinDepositor Class API Reference Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/StarkNetBitcoinDepositor.md Comprehensive API documentation for the StarkNetBitcoinDepositor class, detailing its constructor, properties, and key methods for managing Bitcoin deposits on StarkNet. This class implements the BitcoinDepositor interface and interacts with a StarkNet provider. ```APIDOC Class: StarkNetBitcoinDepositor Description: Full implementation of the BitcoinDepositor interface for StarkNet. This implementation uses a StarkNet provider for operations and supports deposit initialization through the relayer endpoint. Unlike other destination chains, StarkNet deposits are primarily handled through L1 contracts, with this depositor serving as a provider-aware interface for future L2 functionality and relayer integration. Implements: BitcoinDepositor Constructor: new StarkNetBitcoinDepositor(config: StarkNetBitcoinDepositorConfig, chainName: string, provider: StarkNetProvider): StarkNetBitcoinDepositor Description: Creates a new StarkNetBitcoinDepositor instance. Parameters: config: StarkNetBitcoinDepositorConfig - Configuration containing chainId and other chain-specific settings. chainName: string - Name of the chain (should be "StarkNet"). provider: StarkNetProvider - StarkNet provider for blockchain interactions (Provider or Account). Returns: StarkNetBitcoinDepositor Throws: Error if provider is not provided Properties: #chainName: Private Readonly string #config: Private Readonly StarkNetBitcoinDepositorConfig #depositOwner: Private undefined | ChainIdentifier #extraDataEncoder: Private Readonly StarkNetExtraDataEncoder #provider: Private Readonly StarkNetProvider Methods: extraDataEncoder(): ExtraDataEncoder Description: Returns the extra data encoder for StarkNet. Returns: ExtraDataEncoder - The StarkNetExtraDataEncoder instance. Implements: BitcoinDepositor.extraDataEncoder formatRelayerError(error: any): string Description: Formats relayer errors into user-friendly messages. Parameters: error: any - The error to format. Returns: string - Formatted error message. ``` -------------------------------- ### Retrieve General Contract Information: Ethereum Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/EthereumTBTCVault.md Provides methods to get the contract's Ethereum address and its associated chain identifier. These methods are fundamental for identifying and interacting with the deployed contract instance. ```APIDOC getAddress(): EthereumAddress - Description: Returns the Ethereum address of this contract instance. - Returns: EthereumAddress - The contract's address. getChainIdentifier(): ChainIdentifier - Description: Retrieves the unique identifier for the blockchain chain the contract is deployed on. - Returns: ChainIdentifier - The identifier of the chain. ``` -------------------------------- ### Deploy Threshold Contracts on Base Network Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/base/README.adoc This command initiates the deployment of all Threshold contracts to a specified network. It supports local development via `hardhat`, testnets like `baseGoerli` and `baseSepolia`, and the `base` mainnet. The deployment process automatically builds contracts if necessary and generates an `export.json` file containing deployment information. For non-`hardhat` chains, specific environment variables (`L2_CHAIN_API_URL`, `L2_ACCOUNTS_PRIVATE_KEYS`, `BASESCAN_API_KEY`) are required. ```bash yarn deploy --network ``` -------------------------------- ### Get Chain Identifier for Ethereum Depositor Proxy Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/EthereumDepositorProxy.md Retrieves the chain identifier associated with the Ethereum depositor proxy contract. This method implements the `getChainIdentifier` interface from `DepositorProxy`, providing a standardized way to identify the blockchain context. ```APIDOC getChainIdentifier(): ChainIdentifier - Returns: The chain identifier. - Implements: DepositorProxy.getChainIdentifier ``` -------------------------------- ### Fetch Generic Events from Ethereum Contract Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/EthereumWalletRegistry.md Retrieves generic events emitted by an Ethereum contract. The search for events starts from a specified block number, or from a contract's `_deployedAtBlockNumber` property if available, defaulting to block `0`. ```APIDOC getEvents(eventName: string, options?: Options, ...filterArgs: unknown[]): Promise - Description: Get events emitted by the Ethereum contract. It starts searching from provided block number. If the GetEvents.Options#fromBlock option is missing it looks for a contract's defined property _deployedAtBlockNumber. If the property is missing starts searching from block 0. - Parameters: - eventName: string: Name of the event to fetch. - options?: Options: Options for events fetching, including `fromBlock`. - ...filterArgs: unknown[]: Arguments for filtering the events. - Returns: Promise: A promise that resolves to an array of found events. - Inherited From: EthersContractHandle.getEvents ``` -------------------------------- ### Display Git Commit History Graphically Source: https://github.com/threshold-network/tbtc-v2/blob/main/CONTRIBUTING.adoc Use this Git command to display a concise, graphical representation of the entire commit history. It includes all branches, one-line summaries, and decorated references, making it useful for reviewing local changes before pushing. ```Git git log --graph --all --oneline --decorate ``` -------------------------------- ### Deploying tBTC Contracts on Arbitrum Networks Source: https://github.com/threshold-network/tbtc-v2/blob/main/cross-chain/arbitrum/README.adoc This command initiates the deployment of all tBTC-related smart contracts to a specified network. It automatically builds contracts if changes are detected and generates an `export.json` file containing contract deployment information. This process requires specific environment variables for non-`hardhat` networks. ```Shell yarn deploy --network ``` -------------------------------- ### Get Bitcoin Network from Genesis Hash (APIDOC) Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/modules/BitcoinNetwork.md Documents the `fromGenesisHash` function within the `BitcoinNetwork` namespace, which determines the Bitcoin network type by comparing a provided block hash against known genesis block hashes. It returns `BitcoinNetwork.Unknown` if no match is found. ```APIDOC Namespace: BitcoinNetwork fromGenesisHash(hash: Hex): BitcoinNetwork - Gets Bitcoin Network type by comparing a provided hash to known genesis block hashes. - Returns BitcoinNetwork.Unknown if the hash does not match any known genesis block. - Parameters: - hash: Hex - Hash of a block. - Returns: BitcoinNetwork - Bitcoin Network. ``` -------------------------------- ### Implement SUI-Specific Error Handling Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/src/lib/sui/USAGE_EXAMPLE.md Demonstrates a robust approach to error handling for SUI-specific issues. It shows how to use a `try-catch` block to specifically identify and log `SuiError` instances, enabling targeted debugging and recovery strategies in applications. ```typescript try { await deposit.initializeReveal() } catch (error) { if (error instanceof SuiError) { console.error("SUI-specific error:", error.message) } } ``` -------------------------------- ### DepositScript Class API Reference Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/DepositScript.md Comprehensive API documentation for the `DepositScript` class, detailing its constructor, properties, and methods for managing Bitcoin scripts related to tBTC v2 deposits. ```APIDOC Class: DepositScript Represents a Bitcoin script corresponding to a tBTC v2 deposit. On a high-level, the script is used to derive the Bitcoin address that is used to fund the deposit with BTC. On a low-level, the script is used to produce a properly locked funding transaction output that can be unlocked by the target wallet during the deposit sweep process. Constructors: constructor(receipt: DepositReceipt, witness: boolean): DepositScript - Parameters: - receipt: DepositReceipt - Deposit receipt holding the most important information about the deposit. - witness: boolean - Flag indicating whether the generated Bitcoin deposit script (and address) should be a witness P2WSH one. If false, legacy P2SH will be used instead. - Returns: DepositScript Properties: receipt: DepositReceipt (Readonly) - Deposit receipt holding the most important information about the deposit and allowing to build a unique deposit script (and address) on Bitcoin chain. witness: boolean (Readonly) - Flag indicating whether the generated Bitcoin deposit script (and address) should be a witness P2WSH one. If false, legacy P2SH will be used instead. Methods: deriveAddress(bitcoinNetwork: BitcoinNetwork): Promise - Derives a Bitcoin address for the given network for this deposit script. - Parameters: - bitcoinNetwork: BitcoinNetwork - Bitcoin network the address should be derived for. - Returns: Promise - Bitcoin address corresponding to this deposit script. getHash(): Promise> - Returns: Promise> - Hashed deposit script as Buffer. getPlainText(): Promise - Returns: Promise - Plain-text deposit script as a hex string. fromReceipt(receipt: DepositReceipt, witness?: boolean = true): DepositScript - Parameters: - receipt: DepositReceipt - witness: boolean (Optional, default: true) - Returns: DepositScript ``` -------------------------------- ### Load Base Cross-Chain Contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/README.md Loads cross-chain contract interfaces for the Base network and attaches a signer. This function handles the initial setup for interacting with tBTC v2 contracts on Base, ensuring the signer's chain ID matches the loaded contracts. ```APIDOC loadBaseCrossChainContracts(signer: EthereumSigner, chainId: Chains.Base): Promise - Description: Loads cross-chain contract interfaces for the Base network. - Parameters: - signer: EthereumSigner - Signer that should be attached to the contracts. - chainId: Chains.Base - Base chain ID. - Returns: Promise - Handle to the contracts. - Throws: Throws an error if the signer's Base chain ID is other than the one used to load contracts. ``` -------------------------------- ### Build tBTC SDK Library Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/README.md Compiles the tBTC SDK source code into distributable artifacts. The compiled output will be placed in the `dist` directory, ready for use or publishing. ```bash yarn build ``` -------------------------------- ### Initialize tBTC v2 SDK for Ethereum Network Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/TBTC.md Initializes the tBTC v2 SDK entrypoint for a specified Ethereum network and Bitcoin network. The SDK instance will use default Electrum servers for Bitcoin network interactions. ```APIDOC initializeEthereum(signer, ethereumChainId, bitcoinNetwork, crossChainSupport?): Promise - Description: Initializes the tBTC v2 SDK entrypoint for the given Ethereum network and Bitcoin network. The initialized instance uses default Electrum servers to interact with Bitcoin network. ``` -------------------------------- ### Run integration tests for tBTC v2 contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/solidity/README.adoc Executes the integration tests specifically designed for the tBTC v2 smart contracts. These tests provide broader system validation by testing interactions between multiple components, complementing the unit tests. ```Bash yarn test:integration ``` -------------------------------- ### DepositsService Class Constructor Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/DepositsService.md Initializes a new instance of the DepositsService class, setting up essential contract and client dependencies for managing tBTC v2 deposits. It requires handles to tBTC contracts, a Bitcoin client, and a function to retrieve cross-chain interfaces. ```APIDOC new DepositsService(tbtcContracts, bitcoinClient, crossChainContracts) - Parameters: - tbtcContracts: TBTCContracts - bitcoinClient: BitcoinClient - crossChainContracts: (DestinationChainName) => undefined | CrossChainInterfaces - Returns: DepositsService ``` -------------------------------- ### Run unit tests for tBTC v2 contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/solidity/README.adoc Executes the unit tests defined within the `test` directory for the tBTC v2 smart contracts. This command focuses on individual component validation and does not include integration tests, which are typically marked as 'pending'. ```Bash yarn test ``` -------------------------------- ### Build Docker image for tBTC v2 monitoring tool Source: https://github.com/threshold-network/tbtc-v2/blob/main/monitoring/README.adoc Constructs a Docker image for the tBTC v2 monitoring tool from the Dockerfile located in the current directory. The image is tagged as `tbtc-v2-monitoring`, making it ready for containerized deployment. ```bash docker build -t tbtc-v2-monitoring . ``` -------------------------------- ### Build Solidity Contracts Source: https://github.com/threshold-network/tbtc-v2/blob/main/system-tests/README.adoc Compiles the Solidity contracts within the project, producing the necessary contract artifacts. This step is crucial before deploying the contracts or running any tests that interact with them, ensuring that the latest contract logic is available. ```Shell yarn build ``` -------------------------------- ### Fetch Generic Ethereum Contract Events Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/EthereumTBTCVault.md A versatile method to retrieve events emitted by an Ethereum contract. It supports filtering by event name and arguments, and allows specifying a starting block number for the search, defaulting to the contract's deployment block or block 0 if not specified. ```APIDOC getEvents(eventName: string, options?: GetChainEvents.Options, ...filterArgs: unknown[]): Promise - Description: Get events emitted by the Ethereum contract. It starts searching from provided block number. If the GetEvents.Options#fromBlock option is missing it looks for a contract's defined property _deployedAtBlockNumber. If the property is missing starts searching from block 0. - Parameters: - eventName: string - Name of the event. - options?: GetChainEvents.Options - Options for events fetching, including 'fromBlock'. - ...filterArgs: unknown[] - Arguments for events filtering. - Returns: Promise - Array of found events. ``` -------------------------------- ### Display Hardhat Test Utilities Help Source: https://github.com/threshold-network/tbtc-v2/blob/main/system-tests/README.adoc Displays the help documentation for Hardhat tasks, specifically filtering for entries related to 'test-utils'. This command is useful for discovering and understanding the available utility functions provided by the `solidity` module for testing purposes. ```Shell npx hardhat --help | grep test-utils ``` -------------------------------- ### Core Bitcoin Depositor and Event Handling API Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/BaseBitcoinDepositor.md Comprehensive API documentation for managing Bitcoin deposits and retrieving contract events within the tBTC v2 system. This includes methods for getting and setting deposit owners, initializing new deposits, and fetching historical contract events. ```APIDOC getDepositOwner(): undefined | ChainIdentifier - Returns the current deposit owner. - Returns: `undefined` | `ChainIdentifier` - See: `BitcoinDepositor.getDepositOwner` getEvents(eventName: string, options?: GetChainEvents.Options, ...filterArgs: unknown[]): Promise - Get events emitted by the Ethereum contract. - It starts searching from provided block number. If the GetEvents.Options#fromBlock option is missing it looks for a contract's defined property `_deployedAtBlockNumber`. If the property is missing starts searching from block `0`. - Parameters: - `eventName`: `string` - Name of the event. - `options?`: `GetChainEvents.Options` - Options for events fetching. - `...filterArgs`: `unknown[]` - Arguments for events filtering. - Returns: `Promise` - Array of found events. - Inherited from: `EthersContractHandle.getEvents` initializeDeposit(depositTx: BitcoinRawTxVectors, depositOutputIndex: number, deposit: DepositReceipt, vault?: ChainIdentifier): Promise - Initializes a new deposit with the provided transaction details. - Parameters: - `depositTx`: `BitcoinRawTxVectors` - `depositOutputIndex`: `number` - `deposit`: `DepositReceipt` - `vault?`: `ChainIdentifier` - Returns: `Promise` - See: `BitcoinDepositor.initializeDeposit` setDepositOwner(depositOwner: undefined | ChainIdentifier): void - Sets the owner of a deposit. - Parameters: - `depositOwner`: `undefined` | `ChainIdentifier` - Returns: `void` - See: `BitcoinDepositor.setDepositOwner` ``` -------------------------------- ### Generate tBTC SDK API Reference Documentation Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/README.md Generates the API reference documentation for the tBTC SDK. This command should be run manually or via a pre-commit hook whenever source code modifications require updating the documentation. ```bash yarn docs ``` -------------------------------- ### MaintenanceService Class API Reference Source: https://github.com/threshold-network/tbtc-v2/blob/main/typescript/api-reference/classes/MaintenanceService.md API documentation for the `MaintenanceService` class, detailing its constructor for initialization and properties for accessing optimistic minting and SPV proof features. ```APIDOC Class: MaintenanceService Description: Service exposing features relevant to authorized maintainers and operators of the tBTC v2 system. Constructor: new MaintenanceService(tbtcContracts: TBTCContracts, bitcoinClient: BitcoinClient) - Description: Initializes the MaintenanceService instance with contract and Bitcoin client dependencies. - Parameters: - tbtcContracts: TBTCContracts - An interface to interact with tBTC contracts. - bitcoinClient: BitcoinClient - A client for Bitcoin network interactions. - Returns: MaintenanceService - An instance of the MaintenanceService class. Properties: optimisticMinting: OptimisticMinting (Readonly) - Description: Provides access to features specifically for optimistic minting maintainers. spv: Spv (Readonly) - Description: Provides access to features specifically for SPV proof maintainers. ```