-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake-payment.sh
executable file
·205 lines (176 loc) · 8.51 KB
/
make-payment.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/sh
## Variables
mainDir="../../ignored/"
walletDir="${mainDir}wallets/"
loanDir="${mainDir}loan-files/"
tmpDir="${mainDir}tmp/"
paymentObserverScript="${loanDir}payment_observer.plutus"
lenderAddress="addr_test1vpz6g5ecxv6mc036lckg6w06wmj7vr073j73llzpsn5t0pguw7m5u"
borrowerStakePubKeyFile="${walletDir}01Stake.vkey"
borrowerLoanAddr="addr_test1zzc8hkkr9ygdfs02gf0d4hu8awlp8yeefm3kvglf0cw3fnpualkqngnmdz2w9mv60zuucq0sswtn6lq2lwxwez76x0aqwr65gm"
activeDatumFile="${loanDir}activeDatum.json"
paymentDatumFile="${loanDir}paymentDatum.json"
observerRedeemerFile="${loanDir}observePayment.json"
loanRedeemerFile="${loanDir}makePayment.json"
loanAsset='lovelace'
collateral1='c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a'
collateral2='c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.54657374546f6b656e31'
paymentAmount=14500000
loanUTxO='5c43cd80fb435163364854733c7db24af17984ab031e9a6a9aed8f0ff7b5ed28#0'
loanIdTokenName='9d364a309553f27e02028d0cef816bfcb3cfdd6ae60556c15e49eb557f52a368'
# Either the next epoch boundary or the loan expiration; whichever is first. This is used for
# invalid-hereafter.
### IMPORTANT: The invalid-hereafter can be set to a maximum of 1.5 days (129600 slots) passed the
### current slot. If the loan expiration is beyond this "horizon", the node will reject the
### transaction. This is because hardforks can change slot lengths and, therefore, the node doesn't
### want to make guarantees about time too far into the future. If the loan's expiration is more
### than 1.5 days away, set the invalid-hereafter to be: `current_slot + 129600`.
expirationTime=$((1726408979000+1200000))
## Convert the posix time to a slot number for invalid-hereafter.
echo "Calculating the required slot number..."
expirationSlot=$(cardano-loans convert-time \
--posix-time $expirationTime \
--testnet)
## Generate the hash for the staking verification key.
echo "Calculating the staking pubkey hash for the borrower..."
borrowerStakePubKeyHash=$(cardano-cli stake-address key-hash \
--stake-verification-key-file $borrowerStakePubKeyFile)
## Export the payment observer script so you can generate its required stake address.
echo "Exporting the payment observer script..."
cardano-loans scripts \
--payment-script \
--out-file $paymentObserverScript
## Build the observer script's stake address.
echo "Building the observer script's stake address..."
observerAddress=$(cardano-cli stake-address build \
--testnet-magic 1 \
--stake-script-file $paymentObserverScript)
## Create the Active datum.
echo "Creating the active datum..."
cardano-loans datums active post-payment auto \
--testnet \
--loan-ref $loanUTxO \
--payment-amount $paymentAmount \
--out-file $activeDatumFile
# cardano-loans datums active post-payment manual \
# --payment-address $lenderAddress \
# --loan-asset $loanAsset \
# --principal 10000000 \
# --loan-term '10800 slots' \
# --interest '3602879701896397 / 36028797018963968' \
# --compounding-interest \
# --epoch-duration '1200 slots' \
# --minimum-payment 2000000 \
# --fixed-penalty 500000 \
# --collateral-asset $collateral1 \
# --relative-rate '1 / 1000000' \
# --collateral-asset $collateral2 \
# --relative-rate '1 / 500000' \
# --claim-expiration '1726420979000' \
# --loan-expiration '1726417379000' \
# --last-epoch-boundary '1726407779000' \
# --total-epoch-payments 0 \
# --outstanding-balance '128286240743096816698103759582003203125 / 10141204801825835211973625643008' \
# --borrower-staking-pubkey-hash $borrowerStakePubKeyHash \
# --loan-id $loanIdTokenName \
# --payment-amount $paymentAmount \
# --out-file $activeDatumFile
## Create the required redeemers.
echo "Creating the observer redeemer..."
cardano-loans redeemers payment-script observe-payment \
--out-file $observerRedeemerFile
echo "Creating the loan spending redeemer..."
cardano-loans redeemers loan-script make-payment \
--payment-amount $paymentAmount \
--out-file $loanRedeemerFile
## Get the active beacon policy id.
echo "Calculating the active beacon policy id..."
activePolicyId=$(cardano-loans beacon-name policy-id \
--active-beacons \
--stdout)
## Get the required beacon names.
activeTokenName=$(cardano-loans beacon-name asset-name \
--active-beacon \
--stdout)
assetTokenName=$(cardano-loans beacon-name asset-name \
--loan-asset $loanAsset \
--stdout)
activeBeacon="${activePolicyId}.${activeTokenName}"
activeAssetBeacon="${activePolicyId}.${assetTokenName}"
borrowerId="${activePolicyId}.${borrowerStakePubKeyHash}"
loanId="${activePolicyId}.${loanIdTokenName}"
## Create the payment datum.
echo "Creating the payment datum..."
cardano-loans datums payment \
--loan-id $loanIdTokenName \
--out-file $paymentDatumFile
# If you are making a full payment, you will also need these.
activeRedeemerFile="${loanDir}burnActive.json"
echo "Creating the active beacon redeemer..."
cardano-loans redeemers active-script burn-all \
--out-file $activeRedeemerFile
## Create and submit the transaction.
# Full payment transaction.
cardano-cli conway transaction build \
--tx-in $loanUTxO \
--spending-tx-in-reference 50f14254697370b7db435f93abff6e5952a6e0b7f267b033d96bac22d88c766b#0 \
--spending-plutus-script-v2 \
--spending-reference-tx-in-inline-datum-present \
--spending-reference-tx-in-redeemer-file $loanRedeemerFile \
--tx-in c835095f3339fd84276e87539a329615e8a11f286e3f76dbf9daeef93b0a0ea8#1 \
--tx-in 5c43cd80fb435163364854733c7db24af17984ab031e9a6a9aed8f0ff7b5ed28#1 \
--tx-in 85783aed629ea0fdee95e63d234f10c71775794c365299ca408e1bd6b8218911#1 \
--tx-out "${lenderAddress} + ${paymentAmount} ${loanAsset}" \
--tx-out-inline-datum-file $paymentDatumFile \
--tx-out "$(cat ${walletDir}01.addr) + 3000000 lovelace + 8 ${collateral1}" \
--tx-out "$(cat ${walletDir}01.addr) + 3000000 lovelace + 4 ${collateral2}" \
--mint "-1 ${borrowerId} + -1 ${activeBeacon} + -1 ${activeAssetBeacon} + -1 ${loanId}" \
--mint-tx-in-reference 03d6221ffb7a85284a8871a18b6276788f99ec5caff69af098d7e9b4a6e14dec#0 \
--mint-plutus-script-v2 \
--mint-reference-tx-in-redeemer-file $activeRedeemerFile \
--policy-id $activePolicyId \
--withdrawal "${observerAddress}+0" \
--withdrawal-tx-in-reference 670526b45c968321def17ca18cf0e507383e7fd596c45dd5a87b92d1f97943bc#0 \
--withdrawal-plutus-script-v2 \
--withdrawal-reference-tx-in-redeemer-file $observerRedeemerFile \
--required-signer-hash $borrowerStakePubKeyHash \
--change-address "$(cat ${walletDir}01.addr)" \
--tx-in-collateral 4cc5755712fee56feabad637acf741bc8c36dda5f3d6695ac6487a77c4a92d76#0 \
--testnet-magic 1 \
--invalid-hereafter $expirationSlot \
--out-file "${tmpDir}tx.body"
# # Parial payment transaction.
# cardano-cli conway transaction build \
# --tx-in $loanUTxO \
# --spending-tx-in-reference 50f14254697370b7db435f93abff6e5952a6e0b7f267b033d96bac22d88c766b#0 \
# --spending-plutus-script-v2 \
# --spending-reference-tx-in-inline-datum-present \
# --spending-reference-tx-in-redeemer-file $loanRedeemerFile \
# --tx-in c835095f3339fd84276e87539a329615e8a11f286e3f76dbf9daeef93b0a0ea8#1 \
# --tx-in 95de5a789ccedbf1444b8668e5724aa4ed95d799d616aae1e4d408d56c2c3485#0 \
# --tx-in 85783aed629ea0fdee95e63d234f10c71775794c365299ca408e1bd6b8218911#1 \
# --tx-out "${lenderAddress} + ${paymentAmount} ${loanAsset}" \
# --tx-out-inline-datum-file $paymentDatumFile \
# --tx-out "${borrowerLoanAddr} + 4000000 lovelace + 1 ${loanId} + 1 ${borrowerId} + 1 ${activeBeacon} + 1 ${activeAssetBeacon} + 2 ${collateral2}" \
# --tx-out-inline-datum-file $activeDatumFile \
# --tx-out "$(cat ${walletDir}01.addr) + 3000000 lovelace + 8 ${collateral1}" \
# --tx-out "$(cat ${walletDir}01.addr) + 3000000 lovelace + 2 ${collateral2}" \
# --withdrawal "${observerAddress}+0" \
# --withdrawal-tx-in-reference 670526b45c968321def17ca18cf0e507383e7fd596c45dd5a87b92d1f97943bc#0 \
# --withdrawal-plutus-script-v2 \
# --withdrawal-reference-tx-in-redeemer-file $observerRedeemerFile \
# --required-signer-hash $borrowerStakePubKeyHash \
# --change-address "$(cat ${walletDir}01.addr)" \
# --tx-in-collateral 4cc5755712fee56feabad637acf741bc8c36dda5f3d6695ac6487a77c4a92d76#0 \
# --testnet-magic 1 \
# --invalid-hereafter $expirationSlot \
# --out-file "${tmpDir}tx.body"
cardano-cli transaction sign \
--tx-body-file "${tmpDir}tx.body" \
--signing-key-file "${walletDir}/01.skey" \
--signing-key-file "${walletDir}/01Stake.skey" \
--testnet-magic 1 \
--out-file "${tmpDir}tx.signed"
cardano-cli transaction submit \
--testnet-magic 1 \
--tx-file "${tmpDir}tx.signed"