-
Notifications
You must be signed in to change notification settings - Fork 13
/
swap-assets.sh
executable file
·75 lines (61 loc) · 2.88 KB
/
swap-assets.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
#!/bin/sh
# Variables
dir="../../../ignored/swap-files/"
tmpDir="../../../ignored/tmp/"
swapAddr1="addr_test1zzrns8ct7stw9kh8f97nlnvqsl8kw7eukje2aw3kak8c77fualkqngnmdz2w9mv60zuucq0sswtn6lq2lwxwez76x0aq3y05nq"
swapDatumFile1="${dir}swapDatum1.json"
swapRedeemerFile="${dir}oneWaySpendingRedeemer.json"
# Create the Swap redeemer.
echo "Creating the spending redeemer..."
cardano-swaps spending-redeemers two-way \
--ask-asset lovelace \
--offer-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--out-file $swapRedeemerFile
# Create the swap datum.
echo "Creating the swap datum..."
cardano-swaps datums two-way \
--first-asset lovelace \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--first-price '1 / 1000000' \
--second-price 1000000 \
--input-swap-ref f6538bb7a6a0365f3c295aed389df29e752df504ebe691e34f45c0ab9f96272c#0 \
--out-file $swapDatumFile1
# Helper beacon variables.
echo "Calculating the beacon names..."
beaconPolicyId1=$(cardano-swaps beacon-info two-way policy-id \
--stdout)
pairBeaconName1=$(cardano-swaps beacon-info two-way pair-beacon \
--first-asset lovelace \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--stdout)
asset1BeaconName1=$(cardano-swaps beacon-info two-way asset-beacon \
--first-asset lovelace \
--stdout)
asset2BeaconName1=$(cardano-swaps beacon-info two-way asset-beacon \
--second-asset c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a \
--stdout)
pairBeacon1="${beaconPolicyId1}.${pairBeaconName1}"
asset1Beacon1="${beaconPolicyId1}.${asset1BeaconName1}"
asset2Beacon1="${beaconPolicyId1}.${asset2BeaconName1}"
# Create the transaction.
cardano-cli transaction build \
--tx-in 8064545d5c06fcd051eedf4f2d5a2e6efdc08b376720f21b1b3457d48bb536e1#2 \
--tx-in f6538bb7a6a0365f3c295aed389df29e752df504ebe691e34f45c0ab9f96272c#0 \
--spending-tx-in-reference 38fd18f4ca7c6587eb2703ac3bfd42e1406d089901e2c29f158358fdda5b196a#0 \
--spending-plutus-script-v2 \
--spending-reference-tx-in-inline-datum-present \
--spending-reference-tx-in-redeemer-file $swapRedeemerFile \
--tx-out "${swapAddr1} + 13000000 lovelace + 1 ${pairBeacon1} + 1 ${asset1Beacon1} + 1 ${asset2Beacon1} + 10 c0f8644a01a6bf5db02f4afe30d604975e63dd274f1098a1738e561d.4f74686572546f6b656e0a" \
--tx-out-inline-datum-file $swapDatumFile1 \
--tx-in-collateral 11ed603b92e6164c6bb0c83e0f4d54a954976db7c39e2a82d3cbf70f098da1e0#0 \
--change-address "$(cat ../../../ignored/wallets/02.addr)" \
--testnet-magic 1 \
--out-file "${tmpDir}tx.body"
cardano-cli transaction sign \
--tx-body-file "${tmpDir}tx.body" \
--signing-key-file ../../../ignored/wallets/02.skey \
--testnet-magic 1 \
--out-file "${tmpDir}tx.signed"
cardano-cli transaction submit \
--testnet-magic 1 \
--tx-file "${tmpDir}tx.signed"