-
Notifications
You must be signed in to change notification settings - Fork 13
/
create-swap.sh
executable file
·91 lines (73 loc) · 3.14 KB
/
create-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
#!/bin/sh
# Variables
dir="../../../ignored/swap-files/"
tmpDir="../../../ignored/tmp/"
swapScriptFile="${dir}oneWaySwap.plutus" # This is used to create the swap address.
ownerPubKeyFile="../../../ignored/wallets/01Stake.vkey"
swapAddrFile="${dir}oneWaySwap.addr"
swapDatumFile="${dir}swapDatum.json"
beaconRedeemerFile="${dir}oneWayBeaconRedeemer.json"
# Export the swap validator script.
echo "Exporting the swap validator script..."
cardano-swaps scripts one-way swap-script \
--out-file $swapScriptFile
# Create the swap address.
echo "Creating the swap address..."
cardano-cli address build \
--payment-script-file $swapScriptFile \
--stake-verification-key-file $ownerPubKeyFile \
--testnet-magic 1 \
--out-file $swapAddrFile
# Helper beacon variables.
echo "Calculating the beacon names..."
beaconPolicyId=$(cardano-swaps beacon-info one-way policy-id \
--stdout)
pairBeaconName=$(cardano-swaps beacon-info one-way pair-beacon \
--ask-asset lovelace \
--offer-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--stdout)
offerBeaconName=$(cardano-swaps beacon-info one-way offer-beacon \
--offer-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--stdout)
askBeaconName=$(cardano-swaps beacon-info one-way ask-beacon \
--ask-asset lovelace \
--stdout)
pairBeacon="${beaconPolicyId}.${pairBeaconName}"
offerBeacon="${beaconPolicyId}.${offerBeaconName}"
askBeacon="${beaconPolicyId}.${askBeaconName}"
# Get the beacon script redeemer.
echo "Creating the minting redeemer..."
cardano-swaps beacon-redeemers one-way \
--mint-or-burn \
--out-file $beaconRedeemerFile
# Create the swap datum.
echo "Creating the swap datum..."
cardano-swaps datums one-way \
--ask-asset lovelace \
--offer-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--offer-price '1000000 / 1' \
--out-file $swapDatumFile
# Create the transaction.
echo "Building the transaction..."
cardano-cli transaction build \
--tx-in e421457ad39e6c01c4ff53343af64b8c26efc22d57e3ea28b219cbb9002aa7ca#0 \
--tx-in 8795ca8ae3ec2fed3813e99f0e9d683c4f3d4e5a7916e5858dab7756c5104589#0 \
--tx-out "$(cat ${swapAddrFile}) + 3000000 lovelace + 1 ${pairBeacon} + 1 ${offerBeacon} + 1 ${askBeacon} + 15 c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a" \
--tx-out-inline-datum-file $swapDatumFile \
--mint "1 ${pairBeacon} + 1 ${offerBeacon} + 1 ${askBeacon}" \
--mint-tx-in-reference 8762f07fef0c5137ee7d6d8bce962f29554f1ddff3883f1b2d2fc39f213df94c#1 \
--mint-plutus-script-v2 \
--mint-reference-tx-in-redeemer-file $beaconRedeemerFile \
--policy-id "$beaconPolicyId" \
--change-address "$(cat ../../../ignored/wallets/01.addr)" \
--tx-in-collateral 4cc5755712fee56feabad637acf741bc8c36dda5f3d6695ac6487a77c4a92d76#0 \
--testnet-magic 1 \
--out-file "${tmpDir}tx.body"
cardano-cli transaction sign \
--tx-body-file "${tmpDir}tx.body" \
--signing-key-file ../../../ignored/wallets/01.skey \
--testnet-magic 1 \
--out-file "${tmpDir}tx.signed"
cardano-cli transaction submit \
--testnet-magic 1 \
--tx-file "${tmpDir}tx.signed"