Murabaha requires tangible asset existence and cost disclosure.
Using OpenZeppelin ERC-20 as base, adding installment logic.
Compliance rule: late fees must be waived if not stipulated.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Murabaha {
address public buyer;
uint256 public cost;
uint256 public profitMargin;
uint256 public totalPrice;
uint8 public installments;
uint8 public paid;
event InstallmentPaid(address indexed buyer, uint256 amount, uint8 paid);
constructor(address _buyer, uint256 _cost, uint256 _margin, uint8 _installments) {
buyer = _buyer;
cost = _cost;
profitMargin = _margin;
totalPrice = cost + (cost * margin / 100);
installments = _installments;
}
function payInstallment() external payable {
require(msg.sender == buyer, "Only buyer");
require(paid < installments, "Already paid");
uint256 perInstallment = totalPrice / installments;
require(msg.value == perInstallment, "Incorrect amount");
paid++;
emit InstallmentPaid(buyer, msg.value, paid);
}
function getRemaining() external view returns (uint256) {
return (installments - paid) * (totalPrice / installments);
}
}
Generated Murabaha contract with installment payment.
Generate a Murabaha contract with installment payments and late-fee waiver.