Skip to content

Commit 63f3c3d

Browse files
author
Karl Ranna
authored
feat: account for reserved balance (#116)
1 parent bfa283b commit 63f3c3d

File tree

7 files changed

+2427
-1088
lines changed

7 files changed

+2427
-1088
lines changed

src/opendex/assets-utils.spec.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ describe('OpenDEX.assets-utils', () => {
2424
} as unknown) as GetBalanceResponse;
2525
const limitsMap = new Map();
2626
const baseAssetLimits = {
27-
getMaxsell: () => 5000000,
28-
getMaxbuy: () => 5000000,
27+
getMaxSell: () => 2500000,
28+
getMaxBuy: () => 2500000,
29+
getReservedInbound: () => 2500000,
30+
getReservedOutbound: () => 2500000,
2931
};
3032
const quoteAssetLimits = {
31-
getMaxsell: () => 10000000,
32-
getMaxbuy: () => 10000000,
33+
getMaxSell: () => 5000000,
34+
getMaxBuy: () => 5000000,
35+
getReservedInbound: () => 5000000,
36+
getReservedOutbound: () => 5000000,
3337
};
3438
limitsMap.set(config.BASEASSET, baseAssetLimits);
3539
limitsMap.set(config.QUOTEASSET, quoteAssetLimits);
@@ -48,19 +52,27 @@ describe('OpenDEX.assets-utils', () => {
4852
satsToCoinsStr(baseAssetBalance.getChannelBalance())
4953
),
5054
baseAssetMaxOutbound: new BigNumber(
51-
satsToCoinsStr(baseAssetLimits.getMaxsell())
55+
satsToCoinsStr(
56+
baseAssetLimits.getMaxSell() + baseAssetLimits.getReservedOutbound()
57+
)
5258
),
5359
baseAssetMaxInbound: new BigNumber(
54-
satsToCoinsStr(baseAssetLimits.getMaxbuy())
60+
satsToCoinsStr(
61+
baseAssetLimits.getMaxBuy() + baseAssetLimits.getReservedInbound()
62+
)
5563
),
5664
quoteAssetBalance: new BigNumber(
5765
satsToCoinsStr(quoteAssetBalance.getChannelBalance())
5866
),
5967
quoteAssetMaxOutbound: new BigNumber(
60-
satsToCoinsStr(quoteAssetLimits.getMaxsell())
68+
satsToCoinsStr(
69+
quoteAssetLimits.getMaxSell() + quoteAssetLimits.getReservedOutbound()
70+
)
6171
),
6272
quoteAssetMaxInbound: new BigNumber(
63-
satsToCoinsStr(quoteAssetLimits.getMaxbuy())
73+
satsToCoinsStr(
74+
quoteAssetLimits.getMaxBuy() + quoteAssetLimits.getReservedInbound()
75+
)
6476
),
6577
});
6678
});
@@ -153,8 +165,10 @@ describe('OpenDEX.assets-utils', () => {
153165
} as unknown) as GetBalanceResponse;
154166
const limitsMap = new Map();
155167
const baseAssetLimits = {
156-
getMaxsell: () => 5000000,
157-
getMaxbuy: () => 5000000,
168+
getMaxSell: () => 2500000,
169+
getMaxBuy: () => 2500000,
170+
getReservedOutbound: () => 2500000,
171+
getReservedInbound: () => 2500000,
158172
};
159173
limitsMap.set(BASEASSET, baseAssetLimits);
160174
const tradingLimitsResponse = ({

src/opendex/assets-utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@ const parseOpenDEXassets = ({
5858
throw errors.TRADING_LIMITS_MISSING(baseAsset);
5959
}
6060
const baseAssetMaxOutbound = new BigNumber(
61-
satsToCoinsStr(baseAssetLimits.getMaxsell())
62-
);
61+
satsToCoinsStr(baseAssetLimits.getMaxSell())
62+
).plus(new BigNumber(satsToCoinsStr(baseAssetLimits.getReservedOutbound())));
6363
const baseAssetMaxInbound = new BigNumber(
64-
satsToCoinsStr(baseAssetLimits.getMaxbuy())
65-
);
64+
satsToCoinsStr(baseAssetLimits.getMaxBuy())
65+
).plus(new BigNumber(satsToCoinsStr(baseAssetLimits.getReservedInbound())));
6666
const quoteAssetLimits = tradingLimitsMap.get(quoteAsset);
6767
if (!quoteAssetLimits) {
6868
throw errors.TRADING_LIMITS_MISSING(quoteAsset);
6969
}
7070
const quoteAssetMaxOutbound = new BigNumber(
71-
satsToCoinsStr(quoteAssetLimits.getMaxsell())
72-
);
71+
satsToCoinsStr(quoteAssetLimits.getMaxSell())
72+
).plus(new BigNumber(satsToCoinsStr(quoteAssetLimits.getReservedOutbound())));
7373
const quoteAssetMaxInbound = new BigNumber(
74-
satsToCoinsStr(quoteAssetLimits.getMaxbuy())
75-
);
74+
satsToCoinsStr(quoteAssetLimits.getMaxBuy())
75+
).plus(new BigNumber(satsToCoinsStr(quoteAssetLimits.getReservedInbound())));
7676
return {
7777
baseAssetBalance,
7878
quoteAssetBalance,

0 commit comments

Comments
 (0)