Add Funds
To send funds to the liquidity pool, contract calls have to be made to the supplier-interface contract.
A user has to be registered as a swapper with the supplier in order to send funds to the pool. This only has to happen once and is done using the
initialize-swapper()
function on the supplier-interface
contract:(define-public (initialize-swapper))
Once a user has been registered as a swapper, they can begin the add funds flow. In the add funds flow, the supplier generates an address (an HTLC contract) to which the user must send Bitcoin to to advance in the process.
Once this Bitcoin transaction is confirmed on Stacks, the
send-funds()
function on the supplier-interface
contract is called:(define-public (send-funds
(block { header: (buff 80), height: uint })
(prev-blocks (list 10 (buff 80)))
(tx (buff 1024))
(proof { tx-index: uint, hashes: (list 12 (buff 32)), tree-depth: uint })
(output-index uint)
(sender (buff 33))
(recipient (buff 33))
(expiration (buff 4))
(hash (buff 32))
(swapper-buff (buff 4))
(suppler-id uint)
(min-to-receive uint))
)
Field name | Type | Description |
---|---|---|
block | block header, uint , uint | Block header (the 6 fields, unhashed) and Stacks height. The height corresponds to the Stacks block that is associated to the Bitcoin block in which the Bitcoin transaction is in. |
prev-blocks | list of block headers | The block headers of the previous 10 blocks blocks to the one the bitcoin transaction is in. Only used in case of a flash block. |
tx | buff | The raw bitcoin transaction in bytes |
proof | struct | The proof demonstrating that the tx is in the block. tx-index, is the leaf position of the tree in the Merkle Tree. hashes, the leaves of the Merkle Tree of the transactions in the block, tree-depth: the height of the Merkle Tree. |
output-index | uint | The output in the Bitcoin transaction that we need to parse. |
sender | buff | The public key of the sender used to claim back the funds from the HTLC. The private key has to be kept by the user. |
recipient | buff | The public key of the supplier. This can be fetched from the supplier contract (see Magic Contract). |
expiration | buff | The expiration time given in the HTLC (500 is the default) |
hash | buff | Hash of the pre-image used to unlock the HTLC. |
swapper-buff | buff | Supplier id of the supplier supplier in 4 byte little-endian form |
supplier-id | uint | Supplier-id of the chosen supplier |
min-to-receive | uint | Amount of xBTC to be received minus supplier inbound fee. Can fetch inbound-fee from supplier contract (Magic Contract) |
Finally, we finalize the transfer to send funds to the liquidity pool using the
send-funds-finalize()
function on the supplier-interface
contract:(define-public (send-funds-finalize
(txid (buff 32))
(preimage (buff 128))
(factor uint)
(lp-token <lp-token>)
(token-id uint)
(zp-token <dtc>)
(lv <lv>)
(xbtc-ft <ft>)
(rewards-calc <rewards-calc>))
)
Field name | Type | Description |
---|---|---|
txid | buff | Id of the transaction used in the previous send-funds transaction. |
preimage | buff | Preimage of the hash used in the previous send-funds transaction. |
factor | uint | Number of cycles that the user is committing their funds for (range from [1 - 32]). |
lp-token | lp-token | Contract principal using the lp-token-trait (current deployment is .lp-token ). |
token-id | uint | The ID of the pool that the funds are being sent to, first pool is 0. |
zp-token | dtc | Contract principal using the distribution-token-cycles-trait (current deployment is .zest-reward-dist ). |
lv | lv | Contract principal using the liquidity-vault-trait (current deployment is .liquidity-vault-v1-0 ). |
xbtc-ft | ft | Contract principal using the SIP-010 trait of the Bitcoin token (current deployment is .Wrapped-Bitcoin ). |
rewards-calc | rewards-calc | Contract principal using the rewards-calc-trait (current deployment is .rewards-calc ). |
Last modified 25d ago