Skip to content

Commit

Permalink
Fix order selection (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janaka-Steph authored Sep 21, 2023
1 parent fb432c7 commit a669d39
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 116 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Main
on:
push:
branches: [master]
branches: [ master ]
pull_request:
branches: [master]
branches: [ master ]

jobs:
build:
Expand All @@ -24,7 +24,7 @@ jobs:

- name: Install and Run TDEX Daemon
shell: 'script -q -e -c "bash {0}"'
run: yarn tdex:run-initialized
run: yarn tdex:run-init

- name: Run electrs-batch-server
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ yarn-error.log*

# tdex daemon
/tdexd
# ocean wallet
/oceand

#android
android/app/debug/output-metadata.json
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"tdex:connect": "docker exec -it tdexd tdexdconnect --out url",
"tdex:run": "bash scripts/tdexd-run",
"tdex:run-init": "bash scripts/tdexd-run-initialized.sh",
"tdex:run-initialized": "curl https://raw.githubusercontent.com/TDex-network/tdex-sdk/master/scripts/tdexd-run -o tdex-run && bash tdex-run && rm tdex-run",
"test": "craco test"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions scripts/tdexd-clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -e

docker stop oceand
docker stop tdexd
docker rm oceand
docker rm tdexd
sudo rm -rf ./tdexd
sudo rm -rf ./oceand
138 changes: 44 additions & 94 deletions scripts/tdexd-run-initialized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

set -e

echo ""
echo "starting tdexd"

TDEX_BASE_ASSET="5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"

while getopts a: flag; do
Expand All @@ -17,62 +14,28 @@ while getopts a: flag; do
esac
done

echo "TDEX_BASE_ASSET: $TDEX_BASE_ASSET"
echo ""

mkdir -p tdexd

docker run -it -d --name tdexd \
-p 9945:9945 -p 9000:9000 \
-v "$(pwd)/tdexd:/home/user/.tdex-daemon" \
-e TDEX_NO_MACAROONS=false \
-e TDEX_NETWORK="regtest" \
-e TDEX_BASE_ASSET="$TDEX_BASE_ASSET" \
-e TDEX_LOG_LEVEL=5 \
-e TDEX_EXPLORER_ENDPOINT="http://chopsticks-liquid:3000" \
--network="nigiri" \
ghcr.io/tdex-network/tdexd:latest

echo ""
echo "init wallet"
bash scripts/tdexd-run.sh

tdex='docker exec -it tdexd tdex '
$tdex config init --network "regtest"

mnemonic=$($tdex genseed | grep "\S")
$tdex init --seed "${mnemonic}" --password secret &>/dev/null

echo ""
echo "unlocking wallet"

$tdex unlock --password secret &>/dev/null
echo "funding fee account with 0.3 LBTC"

addressesfee=$($tdex fee deposit --num_of_addresses 3)
addressfee1=$(echo $addressesfee | jq -r '.address_with_blinding_key[0].address')
addressfee2=$(echo $addressesfee | jq -r '.address_with_blinding_key[1].address')
addressfee3=$(echo $addressesfee | jq -r '.address_with_blinding_key[2].address')
addressesfee=$($tdex fee deposit --num-of-addresses 3)
addressfee1=$(echo $addressesfee | jq -r '.addresses[0]')
addressfee2=$(echo $addressesfee | jq -r '.addresses[1]')
addressfee3=$(echo $addressesfee | jq -r '.addresses[2]')

echo ""
echo "fee address 1: ${addressfee1}"
echo "fee address 2: ${addressfee2}"
echo "fee address 3: ${addressfee3}"

feetxid1=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressfee1'", "amount": 0.1}' "http://localhost:3001/faucet" | jq -r '.txId')
feetxid2=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressfee2'", "amount": 0.1}' "http://localhost:3001/faucet" | jq -r '.txId')
feetxid3=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressfee3'", "amount": 0.1}' "http://localhost:3001/faucet" | jq -r '.txId')

sleep 7

feevout1=$(curl -s -X GET "http://localhost:3001/address/$addressfee1/utxo" | jq -r '.[0].vout')
feevout2=$(curl -s -X GET "http://localhost:3001/address/$addressfee2/utxo" | jq -r '.[0].vout')
feevout3=$(curl -s -X GET "http://localhost:3001/address/$addressfee3/utxo" | jq -r '.[0].vout')

echo ""
echo "fee base outpoint 1: ${feetxid1} ${feevout1}"
echo "fee base outpoint 2: ${feetxid2} ${feevout2}"
echo "fee base outpoint 3: ${feetxid3} ${feevout3}"
sleep 1

$tdex fee claim --outpoints '[{"hash":"'$feetxid1'", "index":'$feevout1'}, {"hash":"'$feetxid2'", "index":'$feevout2'}, {"hash":"'$feetxid3'", "index":'$feevout3'}]'
nigiri faucet --liquid ${addressfee1} 0.01
nigiri faucet --liquid ${addressfee2} 0.01
nigiri faucet --liquid ${addressfee3} 0.01

echo ""
echo "////////////////////////"
Expand All @@ -84,45 +47,38 @@ usdt=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$add
"ticker":"USDt"}' "http://localhost:3001/mint" | jq -r '.asset')
sleep 7

$tdex market new --base_asset $TDEX_BASE_ASSET --quote_asset ${usdt} &>/dev/null
$tdex market new --base-asset $TDEX_BASE_ASSET --quote-asset ${usdt} --base-asset-precision 8 --quote-asset-precision 8 &>/dev/null
$tdex config set base_asset $TDEX_BASE_ASSET &>/dev/null
$tdex config set quote_asset $usdt &>/dev/null

echo ""
echo "market base asset: $TDEX_BASE_ASSET"
echo "market quote asset: ${usdt}"

addressesmarket=$($tdex market deposit --num_of_addresses 4)
addressmarket0=$(echo $addressesmarket | jq -r '.address_with_blinding_key[0].address')
addressmarket1=$(echo $addressesmarket | jq -r '.address_with_blinding_key[1].address')
addressmarket2=$(echo $addressesmarket | jq -r '.address_with_blinding_key[2].address')
addressmarket3=$(echo $addressesmarket | jq -r '.address_with_blinding_key[3].address')

echo ""
echo "funding market with 1 LBTC and 20k USDt"

addressesmarket=$($tdex market deposit --num-of-addresses 4)
addressmarket0=$(echo $addressesmarket | jq -r '.addresses[0]')
addressmarket1=$(echo $addressesmarket | jq -r '.addresses[1]')
addressmarket2=$(echo $addressesmarket | jq -r '.addresses[2]')
addressmarket3=$(echo $addressesmarket | jq -r '.addresses[3]')

echo ""
echo "market address 0: ${addressmarket0}"
echo "market address 1: ${addressmarket1}"
echo "market address 2: ${addressmarket2}"
echo "market address 3: ${addressmarket3}"

btctxid=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket0'", "asset": "'$TDEX_BASE_ASSET'", "amount": 100}' "http://localhost:3001/faucet" | jq -r '.txId')
usdttxid1=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket1'", "asset": "'$usdt'", "amount": 1333333}' "http://localhost:3001/faucet" | jq -r '.txId')
usdttxid2=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket2'", "asset": "'$usdt'", "amount": 1333333}' "http://localhost:3001/faucet" | jq -r '.txId')
usdttxid3=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket3'", "asset": "'$usdt'", "amount": 1333333}' "http://localhost:3001/faucet" | jq -r '.txId')
sleep 7
sleep 1

btcvout=$(curl -s -X GET "http://localhost:3001/address/$addressmarket0/utxo" | jq -r '.[0].vout')
usdtvout1=$(curl -s -X GET "http://localhost:3001/address/$addressmarket1/utxo" | jq -r '.[0].vout')
usdtvout2=$(curl -s -X GET "http://localhost:3001/address/$addressmarket2/utxo" | jq -r '.[0].vout')
usdtvout3=$(curl -s -X GET "http://localhost:3001/address/$addressmarket3/utxo" | jq -r '.[0].vout')
nigiri faucet --liquid $addressmarket0 0.5 $TDEX_BASE_ASSET
nigiri faucet --liquid $addressmarket1 0.5 $TDEX_BASE_ASSET
nigiri faucet --liquid $addressmarket2 10000 $usdt
nigiri faucet --liquid $addressmarket3 10000 $usdt

echo ""
echo "market base outpoint: ${btctxid} ${btcvout}"
echo "market quote outpoint 1: ${usdttxid1} ${usdtvout1}"
echo "market quote outpoint 2: ${usdttxid2} ${usdtvout2}"
echo "market quote outpoint 3: ${usdttxid3} ${usdtvout3}"

$tdex market claim --outpoints '[{"hash":"'$btctxid'", "index":'$btcvout'}, {"hash":"'$usdttxid1'", "index":'$usdtvout1'},
{"hash":"'$usdttxid2'", "index":'$usdtvout2'}, {"hash":"'$usdttxid3'", "index":'$usdtvout3'}]'
sleep 7

echo ""
echo "opening market"
Expand All @@ -133,49 +89,43 @@ echo "////////////////////////"
echo "/// LBTC-LCAD Market"

echo "mint 10_000_000 LCAD"
asset=$(nigiri mint $(nigiri rpc --liquid getnewaddress) 10000000 | grep asset)
lcad=${asset//asset: /}
addressnigiri=$(curl -s -X GET "http://localhost:3001/getnewaddress" | jq -r '.address')
lcad=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressnigiri'", "amount":10000000, "name": "Liquid CAD",
"ticker":"LCAD"}' "http://localhost:3001/mint" | jq -r '.asset')

sleep 7

$tdex market new --base_asset $TDEX_BASE_ASSET --quote_asset ${lcad} &>/dev/null
$tdex market new --base-asset $TDEX_BASE_ASSET --quote-asset ${lcad} --base-asset-precision 8 --quote-asset-precision 8 &>/dev/null
$tdex config set quote_asset $lcad &>/dev/null

echo "market base asset: $TDEX_BASE_ASSET"
echo "market quote asset: ${lcad}"

addressesmarket=$($tdex market deposit --num_of_addresses 4)
addressmarket0=$(echo $addressesmarket | jq -r '.address_with_blinding_key[0].address')
addressmarket1=$(echo $addressesmarket | jq -r '.address_with_blinding_key[1].address')
addressmarket2=$(echo $addressesmarket | jq -r '.address_with_blinding_key[2].address')
addressmarket3=$(echo $addressesmarket | jq -r '.address_with_blinding_key[3].address')
echo ""
echo "funding market with 1 LBTC and 20k LCAD"

addressesmarket=$($tdex market deposit --num-of-addresses 4)
addressmarket0=$(echo $addressesmarket | jq -r '.addresses[0]')
addressmarket1=$(echo $addressesmarket | jq -r '.addresses[1]')
addressmarket2=$(echo $addressesmarket | jq -r '.addresses[2]')
addressmarket3=$(echo $addressesmarket | jq -r '.addresses[3]')

echo ""
echo "market address 0: ${addressmarket0}"
echo "market address 1: ${addressmarket1}"
echo "market address 2: ${addressmarket2}"
echo "market address 3: ${addressmarket3}"

btctxid=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket0'", "asset": "'$TDEX_BASE_ASSET'", "amount": 100}' "http://localhost:3001/faucet" | jq -r '.txId')
lcadtxid1=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket1'", "asset": "'$lcad'", "amount": 1666666}' "http://localhost:3001/faucet" | jq -r '.txId')
lcadtxid2=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket2'", "asset": "'$lcad'", "amount": 1666666}' "http://localhost:3001/faucet" | jq -r '.txId')
lcadtxid3=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"address":"'$addressmarket3'", "asset": "'$lcad'", "amount": 1666666}' "http://localhost:3001/faucet" | jq -r '.txId')
sleep 7
sleep 1

btcvout=$(curl -s -X GET "http://localhost:3001/address/$addressmarket0/utxo" | jq -r '.[0].vout')
lcadvout1=$(curl -s -X GET "http://localhost:3001/address/$addressmarket1/utxo" | jq -r '.[0].vout')
lcadvout2=$(curl -s -X GET "http://localhost:3001/address/$addressmarket2/utxo" | jq -r '.[0].vout')
lcadvout3=$(curl -s -X GET "http://localhost:3001/address/$addressmarket3/utxo" | jq -r '.[0].vout')
nigiri faucet --liquid $addressmarket0 0.5 $TDEX_BASE_ASSET
nigiri faucet --liquid $addressmarket1 0.5 $TDEX_BASE_ASSET
nigiri faucet --liquid $addressmarket2 10000 $lcad
nigiri faucet --liquid $addressmarket3 10000 $lcad

echo ""
echo "market base outpoint: ${btctxid} ${btcvout}"
echo "market quote outpoint 1: ${lcadtxid1} ${lcadvout1}"
echo "market quote outpoint 2: ${lcadtxid2} ${lcadvout2}"
echo "market quote outpoint 3: ${lcadtxid3} ${lcadvout3}"

$tdex market claim --outpoints '[{"hash":"'$btctxid'", "index":'$btcvout'}, {"hash":"'$lcadtxid1'", "index":'$lcadvout1'},
{"hash":"'$lcadtxid2'",
"index":'$lcadvout2'}, {"hash":"'$lcadtxid3'", "index":'$lcadvout3'}]'
sleep 7

echo ""
echo "opening market"
Expand Down
53 changes: 37 additions & 16 deletions scripts/tdexd-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

set -e

echo ""
echo "starting tdexd"

TDEX_BASE_ASSET="5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225"

while getopts a: flag
Expand All @@ -19,29 +16,53 @@ done
echo "TDEX_BASE_ASSET: $TDEX_BASE_ASSET";
echo ""

sleep 10

echo "starting oceand"
echo ""

mkdir -p oceand

docker run -it -u 0:0 -d --name oceand \
-p 18000:18000 \
-v "$(pwd)/oceand:/home/ocean/.oceand" \
-e OCEAN_LOG_LEVEL=5 \
-e OCEAN_NO_TLS=true \
-e OCEAN_NETWORK="regtest" \
-e OCEAN_NO_PROFILER=true \
-e OCEAN_ELECTRUM_URL=tcp://electrs-liquid:50001 \
-e OCEAN_UTXO_EXPIRY_DURATION_IN_SECONDS=60 \
-e OCEAN_DB_TYPE=badger \
--network="nigiri" \
ghcr.io/vulpemventures/oceand:v0.1.17

echo "starting tdexd"
echo ""

mkdir -p tdexd

docker run -it -d --name tdexd \
-p 9945:9945 -p 9000:9000 \
-v "$(pwd)/tdexd:/home/user/.tdex-daemon" \
-e TDEX_NO_MACAROONS=false \
-e TDEX_NETWORK="regtest" \
-e TDEX_BASE_ASSET="$TDEX_BASE_ASSET" \
-e TDEX_LOG_LEVEL=5 \
-e TDEX_EXPLORER_ENDPOINT="http://chopsticks-liquid:3000" \
--network="nigiri" \
ghcr.io/tdex-network/tdexd:latest

docker run -it -u 0:0 -d --name tdexd \
-p 9945:9945 -p 9000:9000 \
-v "$(pwd)/tdexd:/home/tdex/.tdex-daemon" \
-e TDEX_BASE_ASSET="$TDEX_BASE_ASSET" \
-e TDEX_LOG_LEVEL=5 \
-e TDEX_WALLET_ADDR=oceand:18000 \
--network="nigiri" \
ghcr.io/tdex-network/tdexd:v1.0.1

echo ""
echo "init wallet"

sleep 10

tdex='docker exec -it tdexd tdex '
$tdex config init --network "regtest"
$tdex config init

mnemonic=$($tdex genseed | grep "\S")
$tdex init --seed "${mnemonic}" --password secret &>/dev/null
$tdex init --seed "${mnemonic}" --password password &>/dev/null

echo ""
echo "unlocking wallet"

$tdex unlock --password secret &>/dev/null
$tdex unlock --password password &>/dev/null
4 changes: 2 additions & 2 deletions src/services/tdexService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export function discoverBestOrder(
return async (sats: number, asset: string): Promise<TradeOrderV1 | TradeOrderV2> => {
if (sats <= 0) {
// return a random order to avoid calling discoverer
return allPossibleOrdersV1[0] ?? allPossibleOrdersV2[0];
return allPossibleOrdersV2[0] ?? allPossibleOrdersV1[0];
}
try {
const discovererV1 = tdex.createDiscovererV1(
Expand All @@ -388,7 +388,7 @@ export function discoverBestOrder(
return bestOrdersV2[0] ?? bestOrdersV1[0];
} catch (err) {
console.error(err);
return allPossibleOrdersV1[0];
return allPossibleOrdersV2[0] ?? allPossibleOrdersV1[0];
}
};
}
Expand Down

0 comments on commit a669d39

Please sign in to comment.