Skip to content

Commit a9d9b8e

Browse files
committed
fix: check btc balance before start order
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
1 parent 0936784 commit a9d9b8e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sdk/src/gateway/client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,16 @@ export class GatewayApiClient {
755755
const { onrampQuote, params } = executeQuoteParams;
756756
const quote = onrampQuote!;
757757

758+
const esploraClient = new EsploraClient(this.chain.id === bob.id ? Network.mainnet : Network.signet);
759+
760+
// TODO: refactor to construct the PSBT instead since it may fund from other inputs
761+
const availableBtcBalance = await esploraClient.getBalance(quote.bitcoinAddress);
762+
if (availableBtcBalance.total < BigInt(quote.satoshis)) {
763+
throw new Error(
764+
`Insufficient BTC balance in address ${quote.bitcoinAddress}. Required: ${formatBtc(BigInt(quote.satoshis))}`
765+
);
766+
}
767+
758768
const { uuid, psbtBase64, bitcoinAddress, satoshis, opReturnHash } = await this.startOnrampOrder(
759769
quote,
760770
params

0 commit comments

Comments
 (0)