Skip to content

Commit 69f502f

Browse files
committed
fix: addpair should prevent adding same base and quote assets (#1559)
1 parent c958e86 commit 69f502f

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Diff for: lib/grpc/getGrpcError.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const getGrpcError = (err: any) => {
2222
case orderErrorCodes.MIN_QUANTITY_VIOLATED:
2323
case orderErrorCodes.QUANTITY_DOES_NOT_MATCH:
2424
case swapErrorCodes.REMOTE_IDENTIFIER_MISSING:
25+
case orderErrorCodes.DUPLICATE_PAIR_CURRENCIES:
2526
code = status.INVALID_ARGUMENT;
2627
break;
2728
case orderErrorCodes.PAIR_DOES_NOT_EXIST:

Diff for: lib/orderbook/OrderBook.ts

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ class OrderBook extends EventEmitter {
290290

291291
public addPair = async (pair: Pair) => {
292292
const pairId = derivePairId(pair);
293+
if (pair.baseCurrency.toLowerCase() === pair.quoteCurrency.toLowerCase()) {
294+
throw errors.DUPLICATE_PAIR_CURRENCIES(pair.baseCurrency, pair.quoteCurrency);
295+
}
293296
if (this.pairInstances.has(pairId)) {
294297
throw errors.PAIR_ALREADY_EXISTS(pairId);
295298
}

Diff for: lib/orderbook/errors.ts

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const errorCodes = {
1616
INSUFFICIENT_OUTBOUND_BALANCE: codesPrefix.concat('.12'),
1717
MIN_QUANTITY_VIOLATED: codesPrefix.concat('.13'),
1818
QUANTITY_ON_HOLD: codesPrefix.concat('.15'),
19+
DUPLICATE_PAIR_CURRENCIES: codesPrefix.concat('.16'),
1920
};
2021

2122
const errors = {
@@ -75,6 +76,10 @@ const errors = {
7576
message: `order with local id ${localId} has a quantity of ${holdQuantity} satoshis on hold, try again later`,
7677
code: errorCodes.QUANTITY_DOES_NOT_MATCH,
7778
}),
79+
DUPLICATE_PAIR_CURRENCIES: (baseCurrency: string, quoteCurrency: string) => ({
80+
message: `base asset (${baseCurrency}) and quote asset (${quoteCurrency}) have to be different`,
81+
code: errorCodes.DUPLICATE_PAIR_CURRENCIES,
82+
}),
7883
};
7984

8085
export { errorCodes };

0 commit comments

Comments
 (0)