Worked examples and formulas
One merchant, one lender and one loan, followed through every payment with every balance, using the contracts' exact integer maths. You can reproduce each number in the Simulator.
The setup
- A lender deposits 10,000 USDC into an empty vault. Runway seeds a 100 USDC reserve.
- The INR gateway holds a 5,000 USDC float; the INR treasury holds ₹5,00,000.
- Rate ₹100.00 per USDC, spread 0.5%. The merchant starts with nothing and is paid in USDC.
Step by step
1. The lender deposits 10,000 USDC
2. A 400 USDC crypto sale, no loan
The customer pays about 404 USDC on Base (the extra is swap fees, outside Runway). 1Click delivers exactly 400 USDC to the settlement account. settle(): no loan, so repay = 0 and all 400 go to the merchant. The vault doesn't change: the money only passes through.
3. A ₹10,000 UPI sale, no loan
The treasury gains ₹10,000 (worth 100 USDC), the float pays 99.50. The 0.50 difference is the gateway's spread. The merchant gets 99.50 USDC.
4. The offer (no money moves)
5. The merchant accepts 100 USDC
Cash 10,000 → 9,900, loans outstanding 0 → 100. The vault's value is still 10,000, so the share price doesn't move: lending turns cash into a loan of the same value.
6. A 400 USDC sale during the loan
7. A ₹10,000 UPI sale during the loan
The gateway delivers 99.50 USDC as in step 3, and it is split like any sale: 9.12415 repays the loan, 90.37585 reaches the merchant.
8. A 1,200 USDC sale finishes the loan
Still owed: 110 − 45.80415 = 64.19585. The repay part would be 110.04, but only 64.19585 is needed, so the extra 45.84415 goes back to the merchant: 1,089.96 + 45.84415 = 1,135.80415. The loan is Repaid and later sales go 100% to the merchant.
All the balances
| After | Merchant | Vault cash | Loans out | Vault value | Share price | Reserve | Float | Treasury |
|---|---|---|---|---|---|---|---|---|
| 1 Deposit | 0 | 10,000 | 0 | 10,000 | 1.000000 | 100 | 5,000 | ₹5,00,000 |
| 2 Crypto 400 | 400 | 10,000 | 0 | 10,000 | 1.000000 | 100 | 5,000 | ₹5,00,000 |
| 3 UPI ₹10,000 | 499.50 | 10,000 | 0 | 10,000 | 1.000000 | 100 | 4,900.50 | ₹5,10,000 |
| 5 Loan 100 | 599.50 | 9,900 | 100 | 10,000 | 1.000000 | 100 | 4,900.50 | ₹5,10,000 |
| 6 Crypto 400 | 962.82 | 9,936.35 | 66.65 | 10,003.00 | 1.000300 | 100.33 | 4,900.50 | ₹5,10,000 |
| 7 UPI ₹10,000 | 1,053.20 | 9,945.39 | 58.36 | 10,003.75 | 1.000375 | 100.42 | 4,801.00 | ₹5,20,000 |
| 8 Crypto 1,200 | 2,189.00 | 10,009.00 | 0 | 10,009.00 | 1.000899 | 101.00 | 4,801.00 | ₹5,20,000 |
Check the totals. The merchant's sales were 400 + 400 + 1,200 in crypto plus 2 × 99.50 from UPI = 2,199; add the 100 loan and subtract the 110 repaid = 2,189. The 10 USDC fee went 9.000002 to lenders and 0.999998 to the reserve. The live testnet vault shows almost exactly these numbers after its own test loan: cash 10,009.000002, share price 1.000899.
9. The lender withdraws 1,000 shares
In rupees instead: 1,000.899910 × 100 × 99.5% = ₹99,589.54 to the lender's UPI ID; the float goes up 1,000.90 and the treasury down ₹99,589.54. The share price is unchanged for everyone else.
When a merchant stops paying
Same vault, loan of 100 just disbursed, and no sales at all:
| Moment | Loan | Provisions | Vault cash | Vault value | Share price | Reserve |
|---|---|---|---|---|---|---|
| Disbursed | Active | 0 | 9,900 | 10,000 | 1.000000 | 100 |
| Period 1 ends (repaid 0 of 11 needed) | Delinquent | 50 | 9,900 | 9,950 | 0.995000 | 100 |
| Period 2 ends (missed again) | Defaulted | 0 | 10,000 | 10,000 | 1.000000 | 0 |
The reserve paid the whole 100, so lenders end whole. With only 30 in the reserve, the vault would end at 9,930 and every share would lose 0.7%. If the merchant pays during period 2 instead, the loan returns to Active and the provision is released.
All the formulas
| What | Formula |
|---|---|
| Vault value (NAV) | cash + loans outstanding − provisions |
| Share price | (vault value + 1) ÷ (total shares + 1) |
| Shares for a deposit | deposit × (shares + 1) ÷ (value + 1) |
| USDC for shares at claim | shares × (value + 1) ÷ (shares + 1) |
| Split of each payment | repay = floor(payment × repay share); merchant = the rest; no loan → repay = 0 |
| Fee and amount owed | fee = loan × fee %; owed = loan + fee |
| Principal part of a repayment | floor(total repaid × loan ÷ owed) − principal already repaid |
| Fee part | repayment − principal part; 10% to the reserve, 90% to the vault |
| Minimum per loan period | 10% of owed (or what's left, if less) |
| Provision while delinquent | 50% of the unpaid principal |
| Default | unpaid principal written off; reserve pays first |
| Score | 35 × stability + 25 × history + 15 × diversity + 15 × trend + 10 × corroboration; C ≥ 40, B ≥ 55, A ≥ 75 |
| Limit | min(median window × k, tier cap, 15,000, 3 × median × 25% ÷ (1 + fee)); k = 1.0 / 0.6 / 0.3 for A / B / C |
| Repay share | owed ÷ (3 × median window), between 5% and 25% |
| ₹ → USDC | floor(paise × 1,000,000 × 9,950 ÷ (rate × 10,000)) |
| USDC → ₹ | floor(USDC × rate × 9,950 ÷ (1,000,000 × 10,000)) |