Skip to main content

HelloBitcoin

Git Source

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 ERC-20 contract. You can use this variable for any ERC-20 token, not just USDT (Tether). Make sure to set this to the appropriate ERC-20 contract address.

IERC20 public usdtContractAddress;

nextBtcOrderId

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

uint256 nextBtcOrderId;

nextOrdinalOrderId

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

uint256 nextOrdinalOrderId;

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 _usdtContractAddress);

Parameters

NameTypeDescription
_relayIRelayThe relay contract implementing the IRelay interface.
_usdtContractAddressaddressThe address of the usdt contract.

setRelay

Set the relay contract for the bridge.

function setRelay(IRelay _relay) internal;

Parameters

NameTypeDescription
_relayIRelayThe relay contract implementing the IRelay interface.

placeBtcSellOrder

Initiates a BTC to USDT swap order.

function placeBtcSellOrder(uint256 sellAmountBtc, uint256 buyAmount) public;

Parameters

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

acceptBtcSellOrder

Accepts a BTC to USDT swap order.

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

Parameters

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

completeBtcSellOrder

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

function completeBtcSellOrder(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.

placeOrdinalSellOrder

Initiates an ordinal sell order for swapping Ordinal to USDT.

function placeOrdinalSellOrder(OrdinalId calldata ordinalID, BitcoinTx.UTXO calldata utxo, uint256 buyAmount) public;

Parameters

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

acceptOrdinalSellOrder

Accepts an ordinal sell order for swapping Oridinal to USDT.

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

Parameters

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

completeOrdinalSellOrder

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 completeOrdinalSellOrder(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

btcSellOrderSuccessfullyPlaced

event btcSellOrderSuccessfullyPlaced(uint256 indexed orderId, uint256 sellAmountBtc, uint256 buyAmount);

btcSellOrderBtcSellOrderAccepted

event btcSellOrderBtcSellOrderAccepted(uint256 indexed id, BitcoinAddress bitcoinAddress);

btcSuccessfullySendtoDestination

event btcSuccessfullySendtoDestination(uint256 id);

ordinalSellOrderSuccessfullyPlaced

event ordinalSellOrderSuccessfullyPlaced(uint256 indexed id, OrdinalId ordinalID, uint256 buyAmount);

ordinalSellOrderBtcSellOrderAccepted

event ordinalSellOrderBtcSellOrderAccepted(uint256 indexed id, BitcoinAddress bitcoinAddress);

ordinalSuccessfullySendtoDestination

event ordinalSuccessfullySendtoDestination(uint256 id);

Structs

BtcSellOrder

Struct representing a BTC to USDT swap order.

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

OrdinalSellOrder

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

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

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;
}