forked from fuji-money/tapscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime-safe-liquidation.tapscript
More file actions
76 lines (75 loc) · 1.77 KB
/
Copy pathprime-safe-liquidation.tapscript
File metadata and controls
76 lines (75 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//Liquidation: Treasury can Unlock all collateral
// with Attestation Price below the liquidation target price when Burning Fuji
//
// constructorInputs:
// priceLevel: uint64
// setupTimestamp: uint64
// oraclePk: xonlypubkey
// borrowAsset: asset
// borrowAmount: value
// treasuryPk: value
// assetPair: bytes
//
// functionInputs:
// currentPrice: uint64
// timestamp: uint64
// oracleSig: datasig
// treasurySig: sig
// save $currentPrice
OP_DUP
// check $currentPrice < priceLevel
<$priceLevel>
OP_LESSTHAN64
OP_VERIFY
// copy $timestamp from the witness
OP_OVER
// make sure the $timestamp is after the contract setup time
<$setupTimestamp>
OP_GREATERTHANOREQUAL64
OP_VERIFY
// concatenate $currentPrice to the end of $timestamp
OP_CAT
// concatenate $assetPair to the end of $timestamp.$currentPrice
<$assetPair>
OP_CAT
// check that SHA2($timestamp.$currentPrice.$assetPair) was signed by the oracle
OP_SHA256
<$oraclePk>
OP_CHECKSIGFROMSTACKVERIFY
// get out 0 asset
<0>
OP_INSPECTOUTPUTASSET
// check that out 0 asset is explicit
<1>
OP_EQUALVERIFY
// check that out 0 asset is equal to $borrowAsset
<$borrowAsset>
OP_EQUALVERIFY
// get out 0 value
<0>
OP_INSPECTOUTPUTVALUE
// check that out 0 value is explicit
<1>
OP_EQUALVERIFY
// check that out 0 value is equal to $borrowAmount
<$borrowAmount>
OP_EQUALVERIFY
// take out 0 scriptpubkey
<0>
OP_INSPECTOUTPUTSCRIPTPUBKEY
// OP_RETURN is not a witness scriptPubKey, so its version will be -1
// check that the version is -1
<-1>
OP_EQUALVERIFY
// check that the out 0 scriptpubkey is really just OP_RETURN
<0x6a>
OP_SHA256
OP_EQUALVERIFY
// Check that the nonce on out 0 is empty
<0>
OP_INSPECTOUTPUTNONCE
<0>
OP_EQUALVERIFY
// Require authorization by Treasury
<$treasuryPk>
OP_CHECKSIG