Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# QUICK START:
# 1. cp .env.local.example .env
# 2. docker-compose up -d
# 2. docker compose up -d
# 3. npm run setup
#
# That's it! The setup script will:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ npm install
cp .env.local.example .env

# 3. Start database
docker-compose up -d
docker compose up -d

# 4. Run setup (generates seeds, starts API, registers admin)
npm run setup
Expand Down Expand Up @@ -251,10 +251,10 @@ Seed data is stored in `migration/seed/` and can be customized as needed.
### Docker Commands

```bash
docker-compose up -d # Start database
docker-compose logs db-init # Check if database was created
docker-compose down # Stop database
docker-compose down -v # Stop and delete data
docker compose up -d # Start database
docker compose logs db-init # Check if database was created
docker compose down # Stop database
docker compose down -v # Stop and delete data
docker logs dfx-mssql # View database logs
```

Expand Down
4 changes: 2 additions & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ fi
# Start database
echo ""
echo "🗄️ Starting database..."
docker-compose up -d
docker compose up -d

# Wait for database initialization
echo "⏳ Waiting for database initialization..."
for i in {1..30}; do
if docker-compose logs db-init 2>&1 | grep -q "Database 'dfx' ready"; then
if docker compose logs db-init 2>&1 | grep -q "Database 'dfx' ready"; then
echo "✅ Database ready"
break
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,28 @@ export class BinanceAdapter extends CcxtExchangeAdapter {
const network = this.exchangeService.mapNetwork(Blockchain.LIGHTNING) || undefined;
const balance = await this.exchangeService.getAvailableBalance(asset);

const withdrawalFee = await this.exchangeService.getWithdrawalFee(asset, network);

const amount = Util.floor(
Math.min(order.maxAmount, balance - withdrawalFee, BINANCE_LIGHTNING_MAX_WITHDRAWAL_BTC),
8,
);
const amount = Util.floor(Math.min(order.maxAmount, balance * 0.99, BINANCE_LIGHTNING_MAX_WITHDRAWAL_BTC), 8);

if (amount <= 0)
throw new OrderNotProcessableException(
`${this.exchangeService.name}: not enough balance for ${asset} (balance: ${balance}, min. requested: ${order.minAmount}, max. requested: ${order.maxAmount})`,
);

const amountSats = LightningHelper.btcToSat(amount);

// Generate invoice via LnBits for the target amount (excluding fee)
// Generate invoice via LnBits for the target amount
const invoice = await this.lightningClient.getLnBitsWalletPayment({
amount: amountSats,
memo: `LM Order ${order.id}`,
expirySec: 1800, // 30 min (Binance limit)
});

order.inputAmount = amount + withdrawalFee;
order.inputAmount = amount;
order.inputAsset = asset;
order.outputAsset = asset;

// Send invoice to Binance - amount must be invoice_amount + withdrawal_fee
const response = await this.exchangeService.withdrawFunds(
asset,
amount + withdrawalFee,
invoice.pr,
undefined,
network,
);
// Send only the invoice amount — Binance deducts the fee from the balance separately
const response = await this.exchangeService.withdrawFunds(asset, amount, invoice.pr, undefined, network);

return response.id;
}
Expand Down
Loading