Twilight
Search…
Order/LendTx

# OrderTx

In order to hide the amount in the trader's account, the program separates the pedersen commitment for the initial margin from the original value in the account. Yes, the whole account is locked. Though the knowledge of original value in the account remains with the trader.
The program below performs a range check on the resulting expression from V - IM to prove expr ≥ 0 .
1
p.push(Commitment::blinded(v))
2
.var()
3
.expr()
4
.push(Commitment::blinded(IM))
5
.var()
6
.expr()
7
.neg()
8
9
.range()
10
.drop()
Copied!
The blinding factor used for the Initial Margin would then be revealed to the relayer in order to track the solvency of the positions and create settlement transactions.
The relayer would use the execution price of the trade to generate a delegate locking signature on this Tx and relay it forward to the base layer.

# LendTx

The program for LendTx is similar to OrderTx, and instead of IM, we use the commitment on the Deposit to be locked in the Twilight pool.
1
p.push(Commitment::blinded(v))
2
.var()
3
.expr()
4
.push(Committment::blinded(Deposit)
5
.r#const()
6
.neg()
7
8
.range()
9
.drop()
Copied!
The relayer further executes locking constraints on the transaction where:
$TLV_0*PS=TPS_0*Deposit+Error \\ AND \\TPS_1-TPS_0=PS \\ AND \\ TLV_1-TLV_0=Deposit$
• 0 and 1 subscripts are referring to before and after state of the values
• TLV and TPS are abbreviations for total locked value and total pool share.
• AND is a conjunction constraint
• Error is from the rounding error
1
p.push(Commitment::blinded(TLV0)
2
.var()
3
.dup()
4
.expr()
5
.push(Commitment::blinded(poolShare))
6
.var()
7
.dup()
8
.expr()
9
.roll:2()
10
.mul()
11
.push(Commitment::blinded(TPS0))
12
.var()
13
.dup()
14
.expr()
15
.push(Commitment::blinded(Deposit))
16
.var()
17
.dup()
18
.expr()
19
.roll:2()
20
.mul()
21
.push(Commitment::blinded(Error))
22
.var()
23
.expr()
24
25
.roll:3()
26
.eq()
27
.push(commitment::blinded(TPS1)
28
.var()
29
.expr()
30
.roll:3()
31
.expr()
32
.neg()
33
34
.roll:3()
35
.expr()
36
.eq()
37
.and()
38
.push(Commitment::blinded(TLV1))
39
.var()
40
.expr()
41
.roll:3()
42
.expr()
43
.neg()
44
45
.roll:2()
46
.expr()
47
.eq()
48
.and()
49
.verify()
Copied!
The above program holds true for a positive error. For a negative error, expr for the error is negated.
The relayer would use the deposit amount of the transaction to generate a delegate locking signature and relay it to the base layer.