Modeling a mudaraba smart contract

2020 Update

I made an eBook:
Flint continues to be developed, so much of my code as written here is outdated.

Enter Flint

In May 2018 the Ethereum Foundation gave grants to several promising projects, including $10k to Flint language for smart contracts. Flint restricts users and mutating functions on a language level, and its compiler is written in Swift. You can read more about it here:

Basics of Mudaraba

A mudaraba is a type of musharaka (profit-sharing contract) which provides capital to a business. The lender and business owner both invest in the success of the business:

  • If the investment loses money, the loss is split proportionally to the initial investment. It’s easy to remember by thinking what would happen in a 100% loss.
  • If the investment is profitable, those profits are split according to an agreed ratio. Lenders will incentivize the business owner, and compete with each other, by offering a greater share of profits. For example, a 80–20 partnership may agree to split profits 70–30. In any case, the success of the investment depends on reliable accounting, which typically involves more overhead and complexity (potentially another crypto solution?).
  • Unlike other types of musharaka, a mudaraba lender is typically a “silent partner” and not deeply involved in business decisions.
  • There are additional rules about adjusting the profit ratio and mutual decisions to end the contract, but I don’t want to code everything at once. For this example, we have a fixed profit ratio and either side can end the contract at any time.

Initial structure

There are contract instance variables, and blocks which contain multiple functions.

What anyone can do

Initializing a contract happens in the (any) block, because no bank or business address has been set yet. An @ payable function is called when money is paid in, in case you have the smart contract reacting to that.

  • if the owner does not invest satisfactory funds or takes time to invest for some reason, the bank can delay calling start() of the contract, or cancel().
  • if the bank does not set the promised profit ratio, or invest satisfactory funds, the owner can cancel() or not move funds into the contract

What business owners can do

What banks can do

The contract closing function

This is the calculation which matters most; canceling or closing the contract with distributed profits. Here I am relying on code in the “future” directory of Flint, so don’t depend on it.

Compiling the contract

Does any of this work yet? The Flint language repo comes with a Dockerfile where you can start compiling contracts to Ethereum-friendly bytecode. By adding and subtracting pieces, and referring to future docs, I corrected the code which you currently see here.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store