Methods and Manifests

This page documents all methods available in the Liquify smart contract. Always interact through the Interface Component for stability.


Instant Unstaking Methods

liquify_unstake

Instantly converts LSUs to XRD using available liquidity.

Signature

pub fn liquify_unstake(
    &mut self, 
    lsu_bucket: FungibleBucket, 
    max_iterations: u8
) -> (Bucket, FungibleBucket)

Parameters

lsu_bucket - LSUs from any Radix validator

  • Minimum value: 0 XRD worth (configurable)

  • Maximum value: 10,000,000 XRD worth (configurable)

  • Must be native Radix validator LSU

max_iterations - Maximum liquidity positions to check

  • Recommended: 25-30 for typical orders

  • Maximum effective: ~50 (gas constraints)

  • Higher = better price but more gas

  • Each iteration: ~0.02 XRD gas cost

Returns

(Bucket, FungibleBucket) - Tuple containing:

  1. XRD received (after discounts and fees)

  2. Remaining LSUs if liquidity exhausted

Order Matching Logic

  1. Iterates through liquidity positions by best discount first

  2. Fills orders at progressively worse discounts

  3. Stops when LSUs exhausted or iteration limit reached

  4. Small orders (<1,000 XRD) only match non-automated positions

Platform Fee

  • 0.05% deducted from XRD output

  • Applied after discount calculation

liquify_unstake Manifest


liquify_unstake_off_ledger

Unstakes using pre-computed order matching for optimal rates.

Signature

Parameters

lsu_bucket - LSUs to unstake

  • Same limits as liquify_unstake

  • Must be native Radix validator LSU

order_keys - Pre-computed AVL tree keys

  • Source: From indexer or get_raw_buy_list_range

  • Order: Best discount first for optimal pricing

  • Format: 128-bit unsigned integers

  • Invalid keys are skipped silently

Returns

(Bucket, FungibleBucket) - Tuple containing:

  1. XRD received (after discounts and fees)

  2. Remaining LSUs if liquidity exhausted

Advantages Over On-Ledger

  • No iteration limit (can check 100+ positions)

  • Optimal price discovery via off-chain computation

  • More gas efficient for large orders

  • Deterministic execution

liquify_unstake_off_ledger Manifest

Liquidity Provider Methods

add_liquidity

Deposits XRD to provide liquidity for instant unstaking.

Signature

Parameters

xrd_bucket - Bucket containing XRD tokens

  • Minimum: 10,000 XRD (configurable with owner badge)

  • Maximum: No limit

discount - Discount rate as decimal (not percentage)

  • Range: 0.00 to 0.05 (0% to 5%)

  • Increments: 0.00025 (0.025% steps)

  • Example: 0.01 = 1% discount

auto_unstake - Enable automatic unstaking of received LSUs

  • true: LSUs are immediately unstaked and fills are returned as stake claim NFTs

  • false: LSUs are held for manual collection

auto_refill - Enable automatic liquidity refilling

  • Requires: auto_unstake must be true

  • true: Claimable XRD automatically re-adds to liquidity when another use calls the

  • false: Manual processing required

refill_threshold - Minimum XRD to trigger auto-refill

  • Minimum: 10,000 XRD (configurable by admin)

  • Must be less than total position value

  • Recommended: 50-90% of position size

automation_fee - XRD fee for automation processors

  • Recommended: 5-10 XRD

  • Higher fees = more incentive for others to help automate liquidity

  • Paid per automation cycle

Returns

NonFungibleBucket - Liquidity Receipt NFT tracking your position

add_liquidity Manifest


increase_liquidity

Adds more XRD to an existing liquidity position.

Signature

Parameters

receipt_bucket - Your Liquidity Receipt NFT

  • Must contain exactly one NFT

  • NFT must be from this Liquify instance

xrd_bucket - Additional XRD to add

  • Current + new must be ≥ minimum liquidity (10,000 XRD)

  • No maximum limit

Returns

Bucket - The same Liquidity Receipt NFT

Effects

  • Position moves to back of queue at same discount level

  • Maintains all automation settings

increase_liquidity Manifest


remove_liquidity

Withdraws available XRD from liquidity position(s).

Signature

Parameters

liquidity_receipt_bucket - One or more Liquidity Receipt NFTs

  • Can process multiple receipts in one transaction

  • Only available liquidity is withdrawn

Returns

(Bucket, Bucket) - Tuple containing:

  1. XRD withdrawn from all positions

  2. Receipt NFTs returned

Effects

  • Only withdraws available liquidity (not in active orders)

  • Removes positions from order queue

  • Disables auto_refill if enabled

  • Fills for this receipt must be collected separately

remove_liquidity Manifest

collect_fills

Collects LSUs or stake claim NFTs from filled orders.

Signature

Parameters

liquidity_receipt_bucket - One or more Liquidity Receipt NFTs

  • Processes receipts sequentially

  • Stops when fill limit reached

number_of_fills_to_collect - Maximum fills to process

  • Recommended: 50-100

  • Each fill costs: ~0.03 XRD gas

  • Applies across all receipts

Returns

(Vec<Bucket>, Bucket) - Tuple containing:

  1. Vector of collected asset buckets

  2. Receipt NFTs returned unchanged

Collected Assets

  • If auto_unstake=false: Original LSUs

  • If auto_unstake=true: Stake claim NFTs (unstake receipts)

Multi-Receipt Processing

  • Processes receipts in order provided

  • Continues until limit reached

  • May partially process last receipt

collect_fills Manifest


Automation Methods

cycle_liquidity

Processes automated liquidity refills for eligible positions.

Signature

Parameters

receipt_ids - NFT IDs to process

  • Format: Include hashes (e.g., "#123#")

  • Maximum recommended: 5-10 per transaction

  • Order: Process highest fee positions first

Returns

FungibleBucket - Collected automation fees in XRD

Processing Logic

  1. Checks each receipt for eligibility:

    • auto_refill must be enabled

    • Claimable XRD ≥ refill_threshold

    • Has claimable fills (past unbonding)

  2. Claims all XRD from stake claims

  3. Deducts automation fee

  4. Re-adds remaining XRD to liquidity

  5. Moves position to back of queue

Iteration Limits

  • Max fills per cycle: 50 (configurable by admin)

  • Processes receipts sequentially

  • Skips receipts that can't be fully processed

  • Exception: First receipt can be partially processed

cycle_liquidity Manifest


update_auto_refill_status

Toggles auto-refill for a position.

Signature

Parameters

receipt_bucket - Single Liquidity Receipt NFT

auto_refill - New status

  • Can only enable if auto_unstake=true

  • Disabling removes from automation queue

Returns

Bucket - The same Receipt NFT

update_auto_refill_status Manifest


update_refill_threshold

Changes refill threshold for a position.

Signature

Parameters

receipt_bucket - Single Liquidity Receipt NFT

refill_threshold - New threshold in XRD

  • Minimum: 10,000 XRD (configurable by admin)

  • Must be less than total position value

Returns

Bucket - The same Receipt NFT

update_refill_threshold Manifest


update_automation_fee

Updates fee offered to automation processors.

Signature

Parameters

receipt_bucket - Single Liquidity Receipt NFT

automation_fee - New fee in XRD

  • Can be any positive amount

  • Higher fees incentivize faster processing

Returns

Bucket - The same Receipt NFT

update_automation_fee Manifest


Getter Methods

get_claimable_xrd

Queries claimable XRD for a liquidity position.

Signature

Parameters

receipt_id - NFT ID with hashes (e.g., "#123#")

Returns

(Decimal, u64, Decimal, Decimal) - Tuple containing:

  1. claimable_now - XRD claimable immediately

  2. total_fills - Number of fills to collect

  3. stake_value - Total value in stake claims

  4. lsu_value - Total LSU redemption value

get_claimable_xrd Manifest


get_receipt_detail

Gets complete position information.

Signature

Parameters

receipt_id - NFT ID with hashes (e.g., "#123#")

Returns

ReceiptDetailData - Complete position information:


get_receipt_detail Maniest

get_raw_buy_list_range

Returns raw order book data for indexing.

Signature

Parameters

start_index - Starting position in order book

  • 0-based indexing

  • Use for pagination

count - Number of entries to return

  • Maximum limited by gas

Returns

Vec<(u128, NonFungibleGlobalId)> - Pairs of:

  1. AVL tree key (encodes discount, auto_unstake, position, ID)

  2. Receipt global ID

Key Structure

get_raw_buy_list_range Manifest

get_active_liquidity_positions

Returns detailed info for active positions.

Signature

Parameters

start_index - Starting position

  • 0-based indexing

count - Number to return

  • Limited by gas

Returns

Vec<ReceiptDetailData> - Full details for each active position in order book

get_active_liquidity_positions Manifest

get_automation_ready_receipts

Finds positions ready for automated processing.

Signature

Parameters

start_index - Starting position in automation queue

  • 1-based indexing

  • Use for pagination

batch_size - Number to return

  • Recommended: 10-20

  • Maximum: 100

  • Larger batches = more gas

Returns

Vec<AutomationReadyReceipt> - Ready positions with:

Eligibility Criteria

  • Has auto_refill enabled

  • Claimable XRD ≥ refill threshold

  • Has matured stake claims

get_automation_ready_receipts Manifest

Admin Methods

set_component_status

Enables or disables new liquidity deposits.

Signature

Authorization Required: Owner badge

Parameters

status - Component status

  • false: Prevents new add_liquidity calls

  • true: Normal operation


set_platform_fee

Sets the fee charged on unstaking operations.

Signature

Authorization Required: Owner badge

Parameters

fee - Fee as decimal

  • Example: 0.0005 = 0.05%

  • Reasonable range: 0.01% - 0.5%


set_minimum_liquidity

Sets minimum XRD required for liquidity positions.

Signature

Authorization Required: Owner badge

Parameters

min - Minimum XRD amount

  • Default: 10,000 XRD

  • Trade-off: Higher = more efficient, less accessible


set_unstake_value_range

Sets min/max values for unstaking operations.

Signature

Authorization Required: Owner badge

Parameters

min - Minimum unstake value in XRD

  • Default: 0 XRD

max - Maximum unstake value in XRD

  • Default: 10,000,000 XRD


set_small_order_threshold

Sets threshold for small order routing.

Signature

Authorization Required: Owner badge

Parameters

threshold - XRD value threshold

  • Default: 1,000 XRD

  • Orders below only match manual positions


set_max_fills_per_cycle

Sets maximum fills processed per automation cycle.

Signature

Authorization Required: Owner badge

Parameters

max_fills - Maximum fills per cycle

  • Default: 50

  • Trade-off: Higher = more gas, fewer transactions


collect_platform_fees

Withdraws accumulated platform fees.

Signature

Authorization Required: Owner badge

Returns

Bucket - All accumulated platform fees in XRD

Last updated