For straight Bitcoin Cash liquidity, using NFT authentication would allow all liquidity providers to use the same contract. Each thread could have it’s own flat fee, specified in the nft commitment.
Liquidity providers could stake money on an immutable NFT output, then collect it off with the minting NFT of the same category.
There would be no need to broadcast or index specific contracts by pkh.
With each thread having a different fee, a whole market is created on a single contract location.
There’s interesting market dynamics over time with a flat fee. The rates tend downward. That is, since each time a thread is used, the fees accrue toward the principal, but the rate stays fixed, the effective loan rate drops slightly for the next user. This would create a market dynamic where, over time, threads that are not re-balanced will accumulate a lot of principal, on the same initial flat rate, resulting in a very low effective loan rate.
pragma cashscript 0.11.0;
/**
* @title FlashLiquidityMarket
* @notice This contract enables flash loans with a flat fee, only supporting straight BCH loans.
* @dev The contract ensures that the loan is repaid with the required fee in the same transaction.
* It also provides a secure withdrawal function for the contract owner's minting NFT.
* Liquidity providers send funds with an immutable NFT to a common address.
* Liquidity providers withdraw threads using a minting NFT from their token series.
*/
contract FlashLiquidityMarket() {
//
function loan() {
// Ensure transaction version is 2 for compatibility and future-proofing
// OP_TXVERSION OP_2 OP_NUMEQUALVERIFY
require(tx.version == 2);
// If a minitng NFT is given as the first input for a transaction, allow
// withdrawing (or rebalancing) all threads with a matching token category.
// OP_0 OP_UTXOTOKENCATEGORY
// OP_INPUTINDEX OP_UTXOTOKENCATEGORY 20 OP_SPLIT OP_DROP OP_2 OP_CAT OP_EQUAL OP_IF
if(tx.inputs[0].tokenCategory ==
tx.inputs[this.activeInputIndex].tokenCategory.split(32)[0] + 0x02){
// threads of matching category are unencumbered by contract rules
}
// OP_ELSE
else{
// Verify that funds are set back to this contract.
// OP_INPUTINDEX OP_UTXOBYTECODE
// OP_INPUTINDEX OP_OUTPUTBYTECODE OP_EQUALVERIFY
require(tx.inputs[this.activeInputIndex].lockingBytecode ==
tx.outputs[this.activeInputIndex].lockingBytecode);
// Ensure the token category remains unchanged
// OP_INPUTINDEX OP_UTXOTOKENCATEGORY
// OP_INPUTINDEX OP_OUTPUTTOKENCATEGORY OP_EQUALVERIFY
require(tx.inputs[this.activeInputIndex].tokenCategory ==
tx.outputs[this.activeInputIndex].tokenCategory);
// The owner NFT carrying thread sats MUST be immutable.
// The immutable value is the flat fee.
// Require the output have an additional flat fee
// OP_INPUTINDEX OP_OUTPUTVALUE
// OP_INPUTINDEX OP_UTXOVALUE
// OP_UTXOTOKENCOMMITMENT OP_BIN2NUM OP_ADD OP_NUMEQUALVERIFY
require(tx.outputs[this.activeInputIndex].value ==
tx.inputs[this.activeInputIndex].value +
int(tx.inputs[this.activeInputIndex].nftCommitment));
}
} // OP_ENDIF OP_1
}