Zero coupon with insurance
The issue is that the previous zero coupon bond is that the owner has zero guarantee for repay.
The solution is to use a guarantee fund to ensure pay back. This fund plays the role of trusted third party for the zero coupon bond contract.
zcb:with:insurance.arl
1
archetype zero_coupon_bond_with_insurance
2
3
variable issuer : role = @tz1bfVgcJC4ukaQSHUe1EbrUd5SekXeP9CWk (* seller 'Alice' *)
4
5
variable owner : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
6
(* buyer 'Bob'; receives 11 tez in one-year *)
7
8
contract insurance { (* see guarantee_fund.arl *)
9
action credit ()
10
action add_contract (ic_addr : address, ic_max_transfer : tez)
11
action pay (recipient : address, amount : tez)
12
}
13
14
variable zero_insur : insurance = @KT1TJrR7uovV5tFpsLBCKmx3x95pY6hMy775
15
16
variable price : tez = 10tz
17
18
variable payment : tez = 1.1 * price
19
20
variable maturity : date = now
21
22
states =
23
| Created initial
24
| Insured (* Guarantee Fund has accepted issuer *)
25
| Confirmed (* owner has purchased bond *)
26
| Repaid (* issuer has transferred payment to contract *)
27
| Collected (* owner has collected payment *)
28
29
transition insured () {
30
called by zero_insur
31
32
from Created
33
to Insured
34
}
35
36
transition confirm () {
37
specification {
38
s1 : balance = 0tz
39
}
40
41
from Insured
42
to Confirmed
43
when { transferred = price }
44
with effect {
45
maturity := now + 365d;
46
transfer price to issuer
47
}
48
}
49
50
transition repay () {
51
called by issuer
52
53
from Confirmed
54
to Repaid
55
when {
56
transferred = payment
57
}
58
}
59
60
transition collect () {
61
called by owner
62
63
from Repaid
64
to Collected
65
when { now > maturity }
66
with effect {
67
if balance >= payment
68
then transfer balance to owner
69
else transfer 0tz to zero_insur call pay(owner, payment)
70
}
71
}
Copied!
guarantee:fund.arl
1
archetype guarantee_fund
2
3
variable admin : role = @tz1Lc2qBKEWCBeDU8npG6zCeCqpmaegRi6Jg
4
5
asset insured_contract identified by addr {
6
addr : address;
7
max_transfer : tez;
8
}
9
10
action credit () {
11
called by admin
12
require {
13
c1 : transferred > 0tz;
14
}
15
}
16
17
action add_contract (ic_addr : address, ic_max_transfer : tez) {
18
called by admin
19
effect {
20
insured_contract.add({addr = ic_addr; max_transfer = ic_max_transfer})
21
}
22
}
23
24
action pay (recipient : address, amount : tez) {
25
require {
26
c2 : insured_contract.contains(caller);
27
c3 : amount <= insured_contract.get(caller).max_transfer;
28
}
29
30
effect {
31
transfer amount to recipient
32
}
33
}
Copied!
Last modified 1mo ago
Export as PDF
Copy link
Edit on GitHub