Search…
Borrow
After funds are sent to the liquidity pool, the borrower can create a loan:

(define-public (create-loan
(lp-token <lp-token>)
(token-id uint)
(loan-amount uint)
(coll-ratio uint)
(coll-token <ft>)
(apr uint)
(maturity-length uint)
(payment-period uint))
)

lp-token: Contract principal using the lp-token trait (current deployment is .lp-token).
token-id: id of the pool on which the loan is created.
loan-amount: amount requested for the loan.
coll-ratio: collateral-to-loan ratio in bps.
maturity-length: length until the loan is matured.
payment-period: intervals at which the payments happen. The maturity-length has to be a factor of the payment-period. This has to be true: maturity-length % payment === 0.
​

(define-public (fund-loan
(loan-id uint)
(lp-token <lp-token>)
(token-id uint)
(lv <lv>)
(amount uint)
(xbtc <ft>))
)

loan-id: id of the loan that was created previously.
lp-token: Contract principal using the lp-token trait (current deployment is .lp-token).
token-id: id of the pool on which the loan is created.
lv: Contract principal using the liquidity-vault-trait (current deployment is .liquidity-vault-v1-0).
amount: amount that the loan is funded for. Has to be the amount that is agreed upon.
xbtc: Contract principal using the SIP-010 trait of the Bitcoin token (current deployment is .Wrapped-Bitcoin).
​

(define-public (drawdown
(loan-id uint)
(lp-token <lp-token>)
(token-id uint)
(coll-token <ft>)
(coll-vault <cv>)
(lv <v>)
(btc-version (buff 1))
(btc-hash (buff 20))
(supplier-id uint)
(xbtc <ft>))
)

loan-id: id of the loan that was created previously.
lp-token: Contract principal using the lp-token trait (current deployment is .lp-token).
token-id: id of the pool on which the loan is created.
coll-token: Contract principal of the asset that is being used as collateral. If collateral ratio is 0, use .Wrapper-Bitcoin as the asset has to be approved before.
coll-vault: Contract principal using the coll-vault-trait (current deployment is coll-vault).
lv: Contract principal using the vault-trait (current deployment is .liquidity-vault-v1-0).
btc-version: Single byte representing the address type. 0x00 for P2PKH, 0x05 for P2SH
supplier-id: supplier-id of the chosen supplier on the bridge contract
xbtc: Contract principal using the SIP-010 trait of the Bitcoin token (current deployment is .Wrapped-Bitcoin).

(define-public (finalize-drawdown
(loan-id uint)
(lp-token <lp-token>)
(token-id uint)
(coll-token <ft>)
(coll-vault <cv>)
(fv <v>)
(xbtc-ft <ft>)
(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)
(swap-id uint))
)
loan-id: id of the loan that was created previously.
lp-token: Contract principal using the lp-token trait (current deployment is .lp-token).
token-id: id of the pool on which the loan is created.
coll-token: Contract principal of the asset that is being used as collateral. If collateral ratio is 0, use .Wrapper-Bitcoin as the asset has to be approved before.
coll-vault: Contract principal using the coll-vault-trait (current deployment is .coll-vault).
fv: Contract principal using the vault-trait (current deployment .funding-vault).
xbtc-ft: Contract principal using the SIP-010 trait of the Bitcoin token (current deployment is .Wrapped-Bitcoin).
block: 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: 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: The raw bitcoin transaction in bytes
proof: 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: output-index: the output in the Bitcoin transaction that we need to parse.
swap-id: The id associated with the outbound swap being processed.
​
​
​
​
Copy link
On this page
1. Borrower creates loan
Parameters
2. The pool delegate calls the fund-loan function to fund the previously created loan (pool-v1-0.clar)
Parameters
3. After the loan has been funded, the borrower has to drawdown the funds (supplier-interface.clar)
Parameters
4. After the drawdown Stacks transaction is confirmed, the bitcoin is sent by the supplier
5. Finalize the drawdown by calling finalize-drawdown, anyone can call