radFi
  • Overview
  • Economics
  • User Guides
    • Trading Wallet
  • Trading
  • Automated Market Making
  • User Flows
    • Swap Tab
    • Pool Tab
      • Positions
      • Pools
    • Portfolio Tab
  • Walk-Through Video
  • Technical Architecture
    • Automated Market Maker
    • radFi OP_12
    • Bitcoin Data Availability
    • Trading Wallet
  • Validator
  • Smart Contract
  • radFi Actions Flowchart
  • DEV
    • API Endpoints
      • Create Trading Wallet
      • Swap
      • AMM
        • Init Liquidity
        • Supply Liquidity
        • Increase Liquidity
        • Withdraw Liquidity
        • Collect Fees
  • Terms and Conditions
  • Privacy Policy
Powered by GitBook
On this page
  • 1. Init Pool (Create a New Pool and Add Liquidity)
  • 2. Add New Liquidity Position to an Existing Pool
  • 3. Swap in One Pool:
  • 4. Withdraw Liquidity From a Pool
  • 5. Collect Fees From a Pool
  • 6. Increase Liquidity of a Position in a Pool
  • 7. Migrate pool to new address
  • 8. Migrate pool init UTXO to new address
  1. Technical Architecture

Bitcoin Data Availability

PreviousradFi OP_12NextTrading Wallet

Last updated 1 month ago

Each trading transaction includes the tokens from the trading wallet and the pool, a sequence number, and Uniswap data. Users can compare the balance change between transaction inputs and outputs with Uniswap data, and compare the Uniswap data with the EVM contract to verify the Bitcoin transaction. Below is the structure of each type of trading transaction:

1. Init Pool (Create a New Pool and Add Liquidity)

Inputs:

  • Input 0: Pool init UTXO

  • Remaining Inputs: UTXOs from the trading wallet to init the pool

Outputs:

  • Output 0: New pool init UTXO

  • Outputs 1-10: New pool liquidity UTXOs

  • Outputs 11 to m: radFiOP_12 outputs containing pool initialization data

  • Output m+1: Runestone OP_RETURN

  • Output m+2: Trading wallet’s rune change

  • Output m+3: Trading wallet’s Bitcoin change

Example:

Inputs:

  • Input 0: Pool init UTXO (from the previous pool init transaction)

  • Input 1: Trading wallet’s UTXOs containing Bitcoin funds to provide liquidity for the new pool and cover the transaction fee

  • Input 2: Trading wallet’s UTXO containing Rune tokens to provide liquidity for the new pool

Outputs:

  • Output 0: New pool init UTXO (for use in the next pool init transaction)

  • Outputs 1-5: New pool liquidity UTXOs containing the liquidity added for the new pool

  • Outputs 6-10: Additional pool liquidity UTXOs, but containing no liquidity due to the limit on the Runestone OP_RETURN script size

  • Outputs 11-12: Pool initialization data, combining two ScriptPubKey data that follow OP_12:

    • Byte 0 (Flag): 1 (indicates providing liquidity)

    • Bytes 1-4 (UpperTick, big endian int32): 887200

    • Bytes 5-8 (LowerTick, big endian int32): -887200

    • Remaining Bytes: Contain 11 uvarint128 values:

      • Amount0: 10000964745485757151

      • Amount1: 1000

      • InitPrice: 792243410400884224932

      • Token0Decimal: 18

      • Token1Decimal: 8

      • SequenceNumber: 57

      • Fee: 100 (1%)

      • Token0Id - Block: 885548

      • Token0Id - Tx: 319

      • Token1Id - Block: 0

      • Token1Id - Tx: 0

  • Output 13: Runestone OP_RETURN containing data for the liquidity token in the new UTXOs and Rune change for the trading wallet

  • Output 14: Trading wallet’s Rune change UTXO, containing any remaining Rune tokens

  • Output 15: Trading wallet’s Bitcoin change UTXO, containing any remaining Bitcoin

2. Add New Liquidity Position to an Existing Pool

Inputs:

  • n inputs (n <= 10): Pool liquidity UTXOs

  • Remaining inputs: Trading wallet’s UTXOs to add liquidity

Outputs:

  • n outputs: New pool liquidity UTXOs containing the added liquidity

  • Outputs n to m: radFi OP_12 outputs containing added liquidity data

  • Output m+1: Runestone OP_RETURN

  • Output m+2: Trading wallet’s rune change

  • Output m+3: Trading wallet’s Bitcoin change

Inputs:

  • Inputs 0-3: Pool liquidity UTXOs

  • Input 4: Trading wallet’s UTXOs containing Bitcoin funds to provide liquidity for the pool and cover the transaction fee

  • Input 5: Trading wallet’s UTXO containing Rune tokens to provide liquidity for the pool

Outputs:

  • Outputs 0-3: New pool liquidity UTXOs containing the liquidity added for the pool

  • Output 4: radFi OP_12 script containing add liquidity data:

    • Byte 0 (Flag): 1 (Providing liquidity flag)

    • Bytes 1-4 (UpperTick, big endian int32): 887200

    • Bytes 5-8 (LowerTick, big endian int32): -887200

    • Remaining bytes: Contain 11 uvarint128 values:

      • Amount0: 10000964745485757151

      • Amount1: 1000

      • InitPrice: 0

      • Token0Decimal: 18

      • Token1Decimal: 8

      • SequenceNumber: 58

      • Fee: 100 (1%)

      • Token0Id - Block: 885548

      • Token0Id - Tx: 319

      • Token1Id - Block: 0

      • Token1Id - Tx: 0

  • Output 5: Runestone OP_RETURN containing data for the liquidity token in the new UTXOs and Rune change for the trading wallet

  • Output 6: Trading wallet’s Rune change UTXO containing any remaining Rune tokens

  • Output 7: Trading wallet’s Bitcoin change UTXO containing any remaining Bitcoin

3. Swap in One Pool:

Inputs:

  • n inputs (n <= 10): Pool liquidity UTXOs

  • Remaining inputs: Trading wallet’s UTXOs to swap

Outputs:

  • n outputs: New pool liquidity UTXOs

  • Outputs n to m: radFi OP_12 outputs containing swap data

  • Output m+1: Runestone OP_RETURN

  • Output m+2: Trading wallet’s token swap output

  • Output m+3: Trading wallet’s rune change

  • Output m+4: Trading wallet’s Bitcoin change

Inputs:

  • Inputs 0-1: Pool liquidity UTXOs

  • Input 2: Trading wallet’s UTXOs containing Bitcoin funds to swap and cover the transaction fee

Outputs:

  • Outputs 0-1: New pool liquidity UTXOs

  • Output 2: radFi OP_12 script containing swap data:

    • Byte 0 (Flag): 2 (Swap flag)

    • Byte 1:

      • First bit (IsExactIn): true

      • Remaining 7 bits (PoolsCount, uint8): 1

    • Remaining bytes: Contain 8 uvarint128 values:

      • AmountIn: 1000

      • AmountOut: 7444327141368519190

      • SequenceNumber: 66

      • Fee: 100 (1%)

      • Input TokenId - Block: 0

      • Input TokenId - Tx: 0

      • Output TokenId - Block: 885548

      • Output TokenId - Tx: 319

  • Output 3: Runestone OP_RETURN containing data for the liquidity in the new UTXOs and Rune output for the trading wallet

  • Output 4: Trading wallet’s swap output UTXO

  • Output 5: Trading wallet’s Rune change UTXO (contains no Rune in this example due to no trading wallet’s Rune input)

  • Output 6: Trading wallet’s Bitcoin change UTXO containing the remaining Bitcoin for the user

Inputs:

  • Inputs 0-3: Pool liquidity UTXOs

  • Input 4: Trading wallet’s UTXOs containing Bitcoin funds to cover the transaction fee

  • Inputs 5-6: Trading wallet’s UTXOs containing Rune funds to swap

Outputs:

  • Outputs 0-3: New pool liquidity UTXOs

  • Output 4: radFi OP_12 script containing swap data:

    • Byte 0 (Flag): 2 (Swap flag)

    • Byte 1:

      • First bit (IsExactIn): true

      • Remaining 7 bits (PoolsCount, uint8): 1

    • Remaining bytes: Contain 8 uvarint128 values:

      • AmountIn: 11000000000000000000

      • AmountOut: 1299

      • SequenceNumber: 69

      • Fee: 100 (1%)

      • Input TokenId - Block: 885548

      • Input TokenId - Tx: 319

      • Output TokenId - Block: 0

      • Output TokenId - Tx: 0

  • Output 5: Runestone OP_RETURN containing data for the liquidity in the new UTXOs and Rune change for the trading wallet

  • Output 6: Trading wallet’s swap output UTXO

  • Output 7: Trading wallet’s Rune change UTXO

  • Output 8: Trading wallet’s Bitcoin change UTXO containing the remaining Bitcoin for the user

4. Withdraw Liquidity From a Pool

Inputs:

  • n inputs (n <= 10): Pool liquidity UTXOs

  • Remaining inputs: Trading wallet’s Bitcoin UTXOs to pay the transaction fee

Outputs:

  • n outputs: New pool liquidity UTXOs

  • Outputs n to m: radFi OP_12 outputs containing withdraw liquidity data

  • Output m+1: Runestone OP_RETURN

  • Output m+2: Trading wallet’s withdrawn Rune liquidity

  • Output m+3: Trading wallet’s withdrawn Bitcoin liquidity and Bitcoin change

Inputs:

  • Inputs 0-3: Pool liquidity UTXOs

  • Input 4: Trading wallet’s UTXOs containing Bitcoin funds to cover the transaction fee

Outputs:

  • Outputs 0-3: New pool liquidity UTXOs

  • Output 4: radFi OP_12 script containing withdraw liquidity data:

    • Byte 0 (Flag): 3 (Withdraw liquidity flag)

    • Remaining bytes: Contain 10 uvarint128 values:

      • LiquidityValue: 100004823610

      • NftId: 8

      • Amount0: 9621866398363189269

      • Amount1: 1039

      • SequenceNumber: 94

      • Fee: 100 (1%)

      • Token0Id - Block: 885548

      • Token0Id - Tx: 319

      • Token1Id - Block: 0

      • Token1Id - Tx: 0

  • Output 5: Runestone OP_RETURN containing data for the liquidity in the new UTXOs and withdrawn Rune for the trading wallet

  • Output 6: Trading wallet’s Rune change UTXO

  • Output 7: Trading wallet’s withdrawn Bitcoin liquidity and Bitcoin change UTXO

5. Collect Fees From a Pool

Inputs:

  • n inputs (n <= 10): Pool liquidity UTXOs

  • Remaining inputs: Trading wallet’s Bitcoin UTXOs to pay the transaction fee

Outputs:

  • n outputs: New pool liquidity UTXOs

  • Outputs n to m: radFi OP_12 outputs containing collect fees data

  • Output m+1: Runestone OP_RETURN

  • Output m+2: Trading wallet’s collected Rune fees

  • Output m+3: Trading wallet’s collected Bitcoin fees and Bitcoin change

Inputs:

  • Input 0: Pool liquidity UTXO

  • Input 1: Trading wallet’s UTXOs containing Bitcoin funds to cover the transaction fee

Outputs:

  • Output 0: New pool liquidity UTXO

  • Output 1: radFi OP_12 script containing collect fees data:

    • Byte 0 (Flag): 4 (Collect fees flag)

    • Remaining bytes: Contain 9 uvarint128 values:

      • NftId: 8

      • Amount0: 52894105064729815

      • Amount1: 6

      • SequenceNumber: 93

      • Fee: 100 (1%)

      • Token0Id - Block: 885548

      • Token0Id - Tx: 319

      • Token1Id - Block: 0

      • Token1Id - Tx: 0

  • Output 2: Runestone OP_RETURN containing data of liquidity in the new UTXOs and collected Rune fees for the trading wallet

  • Output 3: Trading wallet’s collected Rune fees UTXO

  • Output 4: Trading wallet’s collected Bitcoin fees and Bitcoin change UTXO

6. Increase Liquidity of a Position in a Pool

Inputs:

  • n inputs (n <= 10): Pool liquidity UTXOs

  • Remaining inputs: Trading wallet’s UTXOs to increase liquidity

Outputs:

  • n outputs: New pool liquidity UTXOs

  • Outputs n to m: radFi OP_12 outputs containing increase liquidity data

  • Output m+1: Runestone OP_RETURN

  • Output m+2: Trading wallet’s Rune change

  • Output m+3: Trading wallet’s Bitcoin change

Inputs:

  • Inputs 0-3: Pool liquidity UTXOs

  • Inputs 4-5: Trading wallet’s UTXOs containing Bitcoin funds to increase liquidity for the pool’s position and cover the transaction fee

  • Input 6: Trading wallet’s UTXO containing Rune token to increase liquidity for the pool’s position

Outputs:

  • Outputs 0-3: New pool liquidity UTXOs

  • Output 4: radFi OP_12 script containing increase liquidity data:

    • Byte 0 (Flag): 5 (Increase liquidity flag)

    • Remaining bytes: Contain 11 uvarint128 values:

      • Min0: 0

      • Min1: 0

      • NftId: 14

      • Amount0: 10000964745485757151

      • Amount1: 1000

      • SequenceNumber: 64

      • Fee: 5 (0.05%)

      • Token0Id - Block: 885548

      • Token0Id - Tx: 319

      • Token1Id - Block: 0

      • Token1Id - Tx: 0

  • Output 5: Runestone OP_RETURN containing data of liquidity in the new UTXOs and Rune change for the trading wallet

  • Output 6: Trading wallet’s Rune change UTXO

  • Output 7: Trading wallet’s Bitcoin change UTXO

7. Migrate pool to new address

Inputs:

  • Inputs 0-9: pool liquidity UTXOs from old address

  • Remain inputs: admin wallet’s bitcoin UTXOs to pay transaction fee

Outputs:

  • Outputs 0-9: new pool liquidity UTXOs for new address

  • Output 10: radFi OP_12 outputs contain pool migration data

  • Output 11: runestone OP_RETURN

  • Output 12: admin wallet’s bitcoin change

Inputs:

  • Inputs 0-9: pool liquidity UTXOs from old address

  • Inputs 10-11: admin wallet’s UTXOs contain bitcoin fund to cover the transaction fee

Outputs:

  • Outputs 0-9: new pool liquidity UTXOs for new address

  • Output 10: radFi OP_12 script contain pool migration data:

    • Byte 0 is Flag: 7 (migrate pool flag)

    • The remain bytes: contain 5 uvarint128

      • Fee: 100 (mean 1%)

      • Token0Id - Block: 0

      • Token0Id - Tx: 0

      • Token1Id - Block: 867080

      • Token1Id - Tx: 468

  • Output 11: runestone OP_RETURN contain data of liquidity in the new UTXOs

8. Migrate pool init UTXO to new address

Inputs:

  • Input 0: pool init UTXO from old address

  • Remain inputs: admin wallet’s bitcoin UTXOs to pay transaction fee

Outputs:

  • Output 0: new pool liquidity UTXOs for new address

  • Outputs 1: radFi OP_12 outputs contain pool migration data

  • Output 2: runestone OP_RETURN

  • Output 3: admin wallet’s bitcoin change

Inputs:

  • Input 0: pool init UTXO from old address

  • Input 1: admin wallet’s UTXO contain bitcoin fund to cover the transaction fee

Outputs:

  • Output 0: new pool init UTXO for new address

  • Output 1: radFi OP_12 script contain pool init UTXO migration data:

    • Byte 0 is Flag: 7 (migrate pool flag)

    • The remain bytes: contain 5 uvarint128

      • Fee: 0

      • Token0Id - Block: 0

      • Token0Id - Tx: 0

      • Token1Id - Block: 0

      • Token1Id - Tx: 0

  • Output 2: admin wallet’s bitcoin change

Example:

Example:

Example:

Example:

Example:

Example:

Example:

Example:

Init Pool and Add Liquidity
Add New Liquidity Position
Swap Bitcoin to Rune
s
Swap Runes to Bitcoin
Withdraw Liquidity From a Pool
Collect Fees From a Pool
Increase Liquidity of a Position in a Pool
https://mempool.space/tx/c269695a85fbbe672b46ece887fcb6753f9c6647541b6ef28d0161f0673164d8
https://mempool.space/tx/8962cecd385ba3c6ac6bc30634c4b233f925a580c0c5d2a47867c8986ef1609e