Skip to main content

HelloBitcoin

Git Source

Inherits: ERC2771Recipient

State Variables

btcSellOrders

Mapping to store BTC to USDT swap orders based on their unique identifiers. Each order is associated with a unique ID, and the order details are stored in the BtcSellOrder struct.

mapping(uint256 => BtcSellOrder) public btcSellOrders;

ordinalSellOrders

Mapping to store ordinal sell orders for swapping BTC to USDT based on their unique identifiers. Each ordinal sell order is associated with a unique ID, and the order details are stored in the OrdinalSellOrder struct.

mapping(uint256 => OrdinalSellOrder) public ordinalSellOrders;

usdtContractAddress

The address of the USDT (Tether) ERC-20 contract. Constant variable to store the contract address for USDT tokens.

address public constant usdtContractAddress = 0xF58de5056b7057D74f957e75bFfe865F571c3fB6;

nextOrderId

Counter for generating unique identifiers for BTC to USDT swap orders. The nextOrderId is incremented each time a new BTC to USDT swap order is created, ensuring that each order has a unique identifier.

uint256 nextOrderId;

nextOrdinalId

Counter for generating unique identifiers for ordinal sell orders. The nextOrdinalId is incremented each time a new ordinal sell order is created, ensuring that each ordinal order has a unique identifier.

uint256 nextOrdinalId;

relay

BridgeState.Storage internal relay;

testLightRelay

TestLightRelay internal testLightRelay;

Functions

constructor

Constructor to initialize the contract with the relay and ERC2771 forwarder.

constructor(IRelay _relay, address erc2771Forwarder);

Parameters

NameTypeDescription
_relayIRelayThe relay contract implementing the IRelay interface.
erc2771ForwarderaddressThe address of the ERC2771 forwarder.

setRelay

Set the relay contract for the bridge.

function setRelay(IRelay _relay) internal;

Parameters

NameTypeDescription
_relayIRelayThe relay contract implementing the IRelay interface.

swapBtcForUsdt

Initiates a BTC to USDT swap order.

function swapBtcForUsdt(uint256 sellAmountBtc, uint256 buyAmountUsdt) public;

Parameters

NameTypeDescription
sellAmountBtcuint256The amount of BTC to sell.
buyAmountUsdtuint256The amount of USDT to buy.

acceptBtcToUsdtSwap

Accepts a BTC to USDT swap order.

function acceptBtcToUsdtSwap(uint256 id, BitcoinAddress calldata bitcoinAddress) public;

Parameters

NameTypeDescription
iduint256The ID of the BTC to USDT swap order.
bitcoinAddressBitcoinAddressThe Bitcoin address of the buyer.

proofBtcSendtoDestination

Completes the BTC to USDT swap by validating the BTC transaction proof and transfer USDT to the seller.

function proofBtcSendtoDestination(uint256 id, BitcoinTx.Info calldata transaction, BitcoinTx.Proof calldata proof)
public;

Parameters

NameTypeDescription
iduint256The ID of the BTC to USDT swap order.
transactionBitcoinTx.InfoInformation about the BTC transaction.
proofBitcoinTx.ProofProof of the BTC transaction's inclusion in the Bitcoin blockchain.

swapOrdinalToUsdt

Initiates an ordinal sell order for swapping Ordinal to USDT.

function swapOrdinalToUsdt(OrdinalId calldata ordinalID, BitcoinTx.UTXO calldata utxo, uint256 buyAmountUsdt) public;

Parameters

NameTypeDescription
ordinalIDOrdinalIdThe unique identifier for the ordinal sell order.
utxoBitcoinTx.UTXOThe UTXO (Unspent Transaction Output) associated with the inscription.
buyAmountUsdtuint256The amount of USDT to buy.

acceptOrdinalToUsdtSwap

Accepts an ordinal sell order for swapping Oridinal to USDT.

function acceptOrdinalToUsdtSwap(uint256 id, BitcoinAddress calldata bitcoinAddress) public;

Parameters

NameTypeDescription
iduint256The ID of the ordinal sell order.
bitcoinAddressBitcoinAddressThe Bitcoin address of the buyer.

proofOrdinalSendtoDestination

Completes the ordinal sell order by validating the BTC transaction proof, ensuring that the BTC transaction input spends the specified UTXO associated with the ordinal sell order, and transfer USDT to the seller.

function proofOrdinalSendtoDestination(uint256 id, BitcoinTx.Info calldata transaction, BitcoinTx.Proof calldata proof)
public;

Parameters

NameTypeDescription
iduint256The ID of the ordinal sell order.
transactionBitcoinTx.InfoInformation about the BTC transaction.
proofBitcoinTx.ProofProof of the BTC transaction's inclusion in the Bitcoin blockchain.

_checkBitcoinTxOutput

Checks output script pubkey (recipient address) and amount. Reverts if transaction amount is lower or bitcoin address is not found.

function _checkBitcoinTxOutput(
uint256 expectedBtcAmount,
BitcoinAddress storage bitcoinAddress,
BitcoinTx.Info calldata transaction
) private;

Parameters

NameTypeDescription
expectedBtcAmountuint256BTC amount requested in order.
bitcoinAddressBitcoinAddressRecipient's bitcoin address.
transactionBitcoinTx.InfoTransaction fulfilling the order.

Events

swapBtcForUsdtEvent

event swapBtcForUsdtEvent(uint256 indexed orderId, uint256 sellAmountBtc, uint256 buyAmountUsdt);

acceptBtcToUsdtSwapEvent

event acceptBtcToUsdtSwapEvent(uint256 indexed id, BitcoinAddress bitcoinAddress);

proofBtcSendtoDestinationEvent

event proofBtcSendtoDestinationEvent(uint256 id);

swapOrdinalToUsdtEvent

event swapOrdinalToUsdtEvent(uint256 indexed id, OrdinalId ordinalID, uint256 buyAmountUsdt);

acceptOrdinalToUsdtSwapEvent

event acceptOrdinalToUsdtSwapEvent(uint256 indexed id, BitcoinAddress bitcoinAddress);

proofOrdinalSellOrderEvent

event proofOrdinalSellOrderEvent(uint256 id);

Structs

BtcSellOrder

Struct representing a BTC to USDT swap order.

struct BtcSellOrder {
uint256 sellAmountBtc;
uint256 buyAmountUsdt;
address btcSeller;
BitcoinAddress btcBuyer;
bool isOrderAccepted;
}

OrdinalSellOrder

Struct representing an ordinal sell order for swapping BTC to USDT.

struct OrdinalSellOrder {
OrdinalId ordinalID;
uint256 buyAmountUsdt;
BitcoinTx.UTXO utxo;
address ordinalSeller;
bool isOrderAccepted;
BitcoinAddress ordinalBuyer;
}

OrdinalId

Struct representing a unique identifier for an ordinal sell order.

struct OrdinalId {
bytes32 txId;
uint32 index;
}

BitcoinAddress

Struct representing a Bitcoin address with a scriptPubKey.

struct BitcoinAddress {
bytes scriptPubKey;
}