-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconvert-swap.sh
executable file
·123 lines (101 loc) · 4.9 KB
/
convert-swap.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
#!/bin/sh
# Variables
tmpDir="/tmp/cardano-swaps/"
# Make the tmpDir if it doesn't already exist.
mkdir -p $tmpDir
ownerPubKeyFile="$HOME/wallets/01Stake.vkey"
swapAddrFile="${tmpDir}twoWaySwap.addr"
swapDatumFile="${tmpDir}swapDatum.json"
swapRedeemerFile="${tmpDir}twoWaySpendingRedeemer.json"
beaconRedeemerFile="${tmpDir}twoWayBeaconRedeemer.json"
# The reference scripts are permanently locked in the swap address without a staking credential!
# You can use the `cardano-swaps query personal-address` command to see them.
beaconScriptPreprodTestnetRef="115c9ebb9928b8ec6e0c9d1420c43421cfb323639dd9fdcf1e7155e73bec13c5#1"
# beaconScriptSize=4707
spendingScriptPreprodTestnetRef="115c9ebb9928b8ec6e0c9d1420c43421cfb323639dd9fdcf1e7155e73bec13c5#0"
# spendingScriptSize=5343
# Generate the hash for the staking verification key.
echo "Calculating the staking pubkey hash for the borrower..."
ownerPubKeyHash=$(cardano-cli conway stake-address key-hash \
--stake-verification-key-file $ownerPubKeyFile)
# Create the spending redeemer.
echo "Creating the spending redeemer..."
cardano-swaps spending-redeemers two-way \
--update-with-mint \
--out-file $swapRedeemerFile
# Create the swap datum.
echo "Creating the swap datum..."
cardano-swaps datums two-way \
--first-asset lovelace \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--second-price 1000000 \
--first-price '1 / 1000000' \
--out-file $swapDatumFile
# Helper beacon variables.
echo "Calculating the beacon names..."
beaconPolicyId=$(cardano-swaps beacon-info two-way policy-id \
--stdout)
oldPairBeaconName=$(cardano-swaps beacon-info two-way pair-beacon \
--first-asset lovelace \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.54657374546f6b656e31 \
--stdout)
oldAsset1BeaconName=$(cardano-swaps beacon-info two-way asset-beacon \
--first-asset lovelace \
--stdout)
oldAsset2BeaconName=$(cardano-swaps beacon-info two-way asset-beacon \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.54657374546f6b656e31 \
--stdout)
oldPairBeacon="${beaconPolicyId}.${oldPairBeaconName}"
oldAsset1Beacon="${beaconPolicyId}.${oldAsset1BeaconName}"
oldAsset2Beacon="${beaconPolicyId}.${oldAsset2BeaconName}"
newPairBeaconName=$(cardano-swaps beacon-info two-way pair-beacon \
--first-asset lovelace \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--stdout)
newAsset1BeaconName=$(cardano-swaps beacon-info two-way asset-beacon \
--first-asset lovelace \
--stdout)
newAsset2BeaconName=$(cardano-swaps beacon-info two-way asset-beacon \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--stdout)
newPairBeacon="${beaconPolicyId}.${newPairBeaconName}"
newAsset1Beacon="${beaconPolicyId}.${newAsset1BeaconName}"
newAsset2Beacon="${beaconPolicyId}.${newAsset2BeaconName}"
# Create the beacon script redeemer.
echo "Creating the minting redeemer..."
cardano-swaps beacon-redeemers two-way \
--mint-or-burn \
--out-file $beaconRedeemerFile
# Create the transaction.
cardano-cli conway transaction build \
--tx-in 74a88e679036309f21154746ddc813c97f5d5bb0e4ebaa0244997ac13e44eb77#1 \
--tx-in 397ceab35a092814871ba5bf9a946a55508afee4edc26c8728caa53837b67fcf#1 \
--tx-in 74a88e679036309f21154746ddc813c97f5d5bb0e4ebaa0244997ac13e44eb77#0 \
--spending-tx-in-reference $spendingScriptPreprodTestnetRef \
--spending-plutus-script-v2 \
--spending-reference-tx-in-inline-datum-present \
--spending-reference-tx-in-redeemer-file $swapRedeemerFile \
--tx-out "$(cat ${swapAddrFile}) + 3000000 lovelace + 1 ${newPairBeacon} + 1 ${newAsset1Beacon} + 1 ${newAsset2Beacon} + 20 c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a" \
--tx-out-inline-datum-file $swapDatumFile \
--tx-out "$(cat $HOME/wallets/01.addr) + 3000000 lovelace + 11 c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.54657374546f6b656e31" \
--mint "-1 ${oldPairBeacon} + -1 ${oldAsset1Beacon} + -1 ${oldAsset2Beacon} + 1 ${newPairBeacon} + 1 ${newAsset1Beacon} + 1 ${newAsset2Beacon}" \
--mint-tx-in-reference $beaconScriptPreprodTestnetRef \
--mint-plutus-script-v2 \
--mint-reference-tx-in-redeemer-file $beaconRedeemerFile \
--policy-id "$beaconPolicyId" \
--tx-in-collateral 4cc5755712fee56feabad637acf741bc8c36dda5f3d6695ac6487a77c4a92d76#0 \
--change-address "$(cat $HOME/wallets/01.addr)" \
--required-signer-hash "$ownerPubKeyHash" \
--testnet-magic 1 \
--out-file "${tmpDir}tx.body"
cardano-cli conway transaction sign \
--tx-body-file "${tmpDir}tx.body" \
--signing-key-file $HOME/wallets/01.skey \
--signing-key-file $HOME/wallets/01Stake.skey \
--testnet-magic 1 \
--out-file "${tmpDir}tx.signed"
cardano-cli conway transaction submit \
--testnet-magic 1 \
--tx-file "${tmpDir}tx.signed"
# Add a newline after the submission response.
echo ""