@clober/v2-sdk 0.0.2-b → 0.0.3-a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/approval.js +0 -26
- package/dist/cjs/approval.js.map +1 -1
- package/dist/cjs/call.js +0 -208
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/constants/fee.js +2 -2
- package/dist/cjs/constants/fee.js.map +1 -1
- package/dist/cjs/index.js +6 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/book.js +145 -112
- package/dist/cjs/model/book.js.map +1 -1
- package/dist/cjs/model/fee-policy.js +71 -21
- package/dist/cjs/model/fee-policy.js.map +1 -1
- package/dist/cjs/model/market.js +235 -171
- package/dist/cjs/model/market.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/signature.js +0 -33
- package/dist/cjs/signature.js.map +1 -1
- package/dist/cjs/utils/market.js +0 -3
- package/dist/cjs/utils/market.js.map +1 -1
- package/dist/cjs/utils/math.js +1 -28
- package/dist/cjs/utils/math.js.map +1 -1
- package/dist/cjs/view.js +0 -92
- package/dist/cjs/view.js.map +1 -1
- package/dist/esm/model/book.js +147 -112
- package/dist/esm/model/book.js.map +1 -1
- package/dist/esm/model/fee-policy.js +71 -21
- package/dist/esm/model/fee-policy.js.map +1 -1
- package/dist/esm/model/market.js +241 -171
- package/dist/esm/model/market.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +5 -11
- package/dist/cjs/tsconfig.build.tsbuildinfo +0 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +0 -1
package/dist/esm/model/market.js
CHANGED
|
@@ -6,17 +6,248 @@ import { MAKER_DEFAULT_POLICY, TAKER_DEFAULT_POLICY } from '../constants/fee';
|
|
|
6
6
|
import { divide } from '../utils/math';
|
|
7
7
|
import { baseToQuote, quoteToBase } from '../utils/decimals';
|
|
8
8
|
export class Market {
|
|
9
|
-
makerFee = (Number(MAKER_DEFAULT_POLICY.rate) * 100) / 1e6;
|
|
10
|
-
takerFee = (Number(TAKER_DEFAULT_POLICY.rate) * 100) / 1e6;
|
|
11
|
-
id;
|
|
12
|
-
quote;
|
|
13
|
-
base;
|
|
14
|
-
bids;
|
|
15
|
-
bidBookOpen;
|
|
16
|
-
asks;
|
|
17
|
-
askBookOpen;
|
|
18
|
-
books;
|
|
19
9
|
constructor({ chainId, tokens, books, }) {
|
|
10
|
+
Object.defineProperty(this, "makerFee", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: (Number(MAKER_DEFAULT_POLICY.rate) * 100) / 1e6
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "takerFee", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: (Number(TAKER_DEFAULT_POLICY.rate) * 100) / 1e6
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "id", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "quote", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "base", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "bids", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(this, "bidBookOpen", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "asks", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(this, "askBookOpen", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: void 0
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(this, "books", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: void 0
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "take", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: ({ takeQuote, limitPrice, amountOut, // quote if takeQuote, base otherwise
|
|
75
|
+
}) => {
|
|
76
|
+
if (takeQuote) {
|
|
77
|
+
const bidDepths = this.books
|
|
78
|
+
.filter((book) => isAddressEqual(book.quote.address, this.quote.address))
|
|
79
|
+
.flatMap((book) => book.depths);
|
|
80
|
+
return this.takeInner({ depths: bidDepths, limitPrice, amountOut });
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const askDepths = this.books
|
|
84
|
+
.filter((book) => isAddressEqual(book.quote.address, this.base.address))
|
|
85
|
+
.flatMap((book) => book.depths);
|
|
86
|
+
return this.takeInner({
|
|
87
|
+
depths: askDepths,
|
|
88
|
+
limitPrice: invertPrice(limitPrice),
|
|
89
|
+
amountOut,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(this, "spend", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
configurable: true,
|
|
97
|
+
writable: true,
|
|
98
|
+
value: ({ spendBase, limitPrice, amountIn, // base if spendBase, quote otherwise
|
|
99
|
+
}) => {
|
|
100
|
+
if (spendBase) {
|
|
101
|
+
const bidDepths = this.books
|
|
102
|
+
.filter((book) => isAddressEqual(book.quote.address, this.quote.address))
|
|
103
|
+
.flatMap((book) => book.depths);
|
|
104
|
+
return this.spendInner({ depths: bidDepths, limitPrice, amountIn });
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const askDepths = this.books
|
|
108
|
+
.filter((book) => isAddressEqual(book.quote.address, this.base.address))
|
|
109
|
+
.flatMap((book) => book.depths);
|
|
110
|
+
return this.spendInner({
|
|
111
|
+
depths: askDepths,
|
|
112
|
+
limitPrice: invertPrice(limitPrice),
|
|
113
|
+
amountIn,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(this, "takeInner", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: ({ depths, // only bid orders
|
|
123
|
+
limitPrice, amountOut, // quote
|
|
124
|
+
}) => {
|
|
125
|
+
if (depths.length === 0) {
|
|
126
|
+
return {};
|
|
127
|
+
}
|
|
128
|
+
const takeResult = {};
|
|
129
|
+
for (const depth of depths) {
|
|
130
|
+
if (!takeResult[depth.bookId]) {
|
|
131
|
+
takeResult[depth.bookId] = {
|
|
132
|
+
takenAmount: 0n,
|
|
133
|
+
spendAmount: 0n,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
let totalTakenQuoteAmount = 0n;
|
|
138
|
+
const ticks = depths
|
|
139
|
+
.sort((a, b) => Number(b.tick) - Number(a.tick))
|
|
140
|
+
.map((depth) => depth.tick);
|
|
141
|
+
let index = 0;
|
|
142
|
+
let tick = ticks[index];
|
|
143
|
+
while (tick > -8388608n) {
|
|
144
|
+
if (limitPrice > toPrice(tick)) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
const currentDepth = depths.find((depth) => depth.tick === tick);
|
|
148
|
+
const currentBook = this.books.find((book) => book.id === BigInt(currentDepth.bookId));
|
|
149
|
+
let maxAmount = TAKER_DEFAULT_POLICY.usesQuote
|
|
150
|
+
? TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountOut - totalTakenQuoteAmount, true)
|
|
151
|
+
: amountOut - totalTakenQuoteAmount;
|
|
152
|
+
maxAmount = divide(maxAmount, currentBook.unit, true);
|
|
153
|
+
if (maxAmount === 0n) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
let quoteAmount = (currentDepth.rawAmount > maxAmount
|
|
157
|
+
? maxAmount
|
|
158
|
+
: currentDepth.rawAmount) * currentBook.unit;
|
|
159
|
+
let baseAmount = quoteToBase(tick, quoteAmount, true);
|
|
160
|
+
if (TAKER_DEFAULT_POLICY.usesQuote) {
|
|
161
|
+
quoteAmount =
|
|
162
|
+
quoteAmount - TAKER_DEFAULT_POLICY.calculateFee(quoteAmount, false);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
baseAmount =
|
|
166
|
+
baseAmount + TAKER_DEFAULT_POLICY.calculateFee(baseAmount, false);
|
|
167
|
+
}
|
|
168
|
+
if (quoteAmount === 0n) {
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
takeResult[currentDepth.bookId].takenAmount += quoteAmount;
|
|
172
|
+
takeResult[currentDepth.bookId].spendAmount += baseAmount;
|
|
173
|
+
totalTakenQuoteAmount += quoteAmount;
|
|
174
|
+
if (amountOut <= totalTakenQuoteAmount) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (ticks.length === index + 1) {
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
index++;
|
|
181
|
+
tick = ticks[index];
|
|
182
|
+
}
|
|
183
|
+
return Object.fromEntries(Object.entries(takeResult).filter(([, value]) => value.spendAmount > 0 && value.takenAmount > 0));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(this, "spendInner", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
configurable: true,
|
|
189
|
+
writable: true,
|
|
190
|
+
value: ({ depths, // only bid orders
|
|
191
|
+
limitPrice, amountIn, // base
|
|
192
|
+
}) => {
|
|
193
|
+
if (depths.length === 0) {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
const spendResult = {};
|
|
197
|
+
for (const depth of depths) {
|
|
198
|
+
if (!spendResult[depth.bookId]) {
|
|
199
|
+
spendResult[depth.bookId] = {
|
|
200
|
+
takenAmount: 0n,
|
|
201
|
+
spendAmount: 0n,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let totalSpendBaseAmount = 0n;
|
|
206
|
+
const ticks = depths
|
|
207
|
+
.sort((a, b) => Number(b.tick) - Number(a.tick))
|
|
208
|
+
.map((depth) => depth.tick);
|
|
209
|
+
let index = 0;
|
|
210
|
+
let tick = ticks[index];
|
|
211
|
+
while (totalSpendBaseAmount <= amountIn && tick > -8388608n) {
|
|
212
|
+
if (limitPrice > toPrice(tick)) {
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
const currentDepth = depths.find((depth) => depth.tick === tick);
|
|
216
|
+
const currentBook = this.books.find((book) => book.id === BigInt(currentDepth.bookId));
|
|
217
|
+
let maxAmount = TAKER_DEFAULT_POLICY.usesQuote
|
|
218
|
+
? amountIn - totalSpendBaseAmount
|
|
219
|
+
: TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountIn - totalSpendBaseAmount, false);
|
|
220
|
+
maxAmount = baseToQuote(tick, maxAmount, false) / currentBook.unit;
|
|
221
|
+
if (maxAmount === 0n) {
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
let quoteAmount = (currentDepth.rawAmount > maxAmount
|
|
225
|
+
? maxAmount
|
|
226
|
+
: currentDepth.rawAmount) * currentBook.unit;
|
|
227
|
+
let baseAmount = quoteToBase(tick, quoteAmount, true);
|
|
228
|
+
if (TAKER_DEFAULT_POLICY.usesQuote) {
|
|
229
|
+
quoteAmount =
|
|
230
|
+
quoteAmount - TAKER_DEFAULT_POLICY.calculateFee(quoteAmount, false);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
baseAmount =
|
|
234
|
+
baseAmount + TAKER_DEFAULT_POLICY.calculateFee(baseAmount, false);
|
|
235
|
+
}
|
|
236
|
+
if (baseAmount === 0n) {
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
spendResult[currentDepth.bookId].takenAmount += quoteAmount;
|
|
240
|
+
spendResult[currentDepth.bookId].spendAmount += baseAmount;
|
|
241
|
+
totalSpendBaseAmount += baseAmount;
|
|
242
|
+
if (ticks.length === index + 1) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
index++;
|
|
246
|
+
tick = ticks[index];
|
|
247
|
+
}
|
|
248
|
+
return Object.fromEntries(Object.entries(spendResult).filter(([, value]) => value.spendAmount > 0 && value.takenAmount > 0));
|
|
249
|
+
}
|
|
250
|
+
});
|
|
20
251
|
const { marketId, quoteTokenAddress, baseTokenAddress } = getMarketId(chainId, tokens.map((token) => token.address));
|
|
21
252
|
this.id = marketId;
|
|
22
253
|
this.quote = tokens.find((token) => isAddressEqual(token.address, quoteTokenAddress));
|
|
@@ -46,166 +277,5 @@ export class Market {
|
|
|
46
277
|
books.filter((book) => isAddressEqual(book.quote.address, this.base.address)).length > 0;
|
|
47
278
|
this.books = books;
|
|
48
279
|
}
|
|
49
|
-
take = ({ takeQuote, limitPrice, amountOut, // quote if takeQuote, base otherwise
|
|
50
|
-
}) => {
|
|
51
|
-
if (takeQuote) {
|
|
52
|
-
const bidDepths = this.books
|
|
53
|
-
.filter((book) => isAddressEqual(book.quote.address, this.quote.address))
|
|
54
|
-
.flatMap((book) => book.depths);
|
|
55
|
-
return this.takeInner({ depths: bidDepths, limitPrice, amountOut });
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const askDepths = this.books
|
|
59
|
-
.filter((book) => isAddressEqual(book.quote.address, this.base.address))
|
|
60
|
-
.flatMap((book) => book.depths);
|
|
61
|
-
return this.takeInner({
|
|
62
|
-
depths: askDepths,
|
|
63
|
-
limitPrice: invertPrice(limitPrice),
|
|
64
|
-
amountOut,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
spend = ({ spendBase, limitPrice, amountIn, // base if spendBase, quote otherwise
|
|
69
|
-
}) => {
|
|
70
|
-
if (spendBase) {
|
|
71
|
-
const bidDepths = this.books
|
|
72
|
-
.filter((book) => isAddressEqual(book.quote.address, this.quote.address))
|
|
73
|
-
.flatMap((book) => book.depths);
|
|
74
|
-
return this.spendInner({ depths: bidDepths, limitPrice, amountIn });
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
const askDepths = this.books
|
|
78
|
-
.filter((book) => isAddressEqual(book.quote.address, this.base.address))
|
|
79
|
-
.flatMap((book) => book.depths);
|
|
80
|
-
return this.spendInner({
|
|
81
|
-
depths: askDepths,
|
|
82
|
-
limitPrice: invertPrice(limitPrice),
|
|
83
|
-
amountIn,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
takeInner = ({ depths, // only bid orders
|
|
88
|
-
limitPrice, amountOut, // quote
|
|
89
|
-
}) => {
|
|
90
|
-
if (depths.length === 0) {
|
|
91
|
-
return {};
|
|
92
|
-
}
|
|
93
|
-
const takeResult = {};
|
|
94
|
-
for (const depth of depths) {
|
|
95
|
-
if (!takeResult[depth.bookId]) {
|
|
96
|
-
takeResult[depth.bookId] = {
|
|
97
|
-
takenAmount: 0n,
|
|
98
|
-
spendAmount: 0n,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
let totalTakenQuoteAmount = 0n;
|
|
103
|
-
const ticks = depths
|
|
104
|
-
.sort((a, b) => Number(b.tick) - Number(a.tick))
|
|
105
|
-
.map((depth) => depth.tick);
|
|
106
|
-
let index = 0;
|
|
107
|
-
let tick = ticks[index];
|
|
108
|
-
while (tick > -8388608n) {
|
|
109
|
-
if (limitPrice > toPrice(tick)) {
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
const currentDepth = depths.find((depth) => depth.tick === tick);
|
|
113
|
-
const currentBook = this.books.find((book) => book.id === BigInt(currentDepth.bookId));
|
|
114
|
-
let maxAmount = TAKER_DEFAULT_POLICY.usesQuote
|
|
115
|
-
? TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountOut - totalTakenQuoteAmount, true)
|
|
116
|
-
: amountOut - totalTakenQuoteAmount;
|
|
117
|
-
maxAmount = divide(maxAmount, currentBook.unit, true);
|
|
118
|
-
if (maxAmount === 0n) {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
let quoteAmount = (currentDepth.rawAmount > maxAmount
|
|
122
|
-
? maxAmount
|
|
123
|
-
: currentDepth.rawAmount) * currentBook.unit;
|
|
124
|
-
let baseAmount = quoteToBase(tick, quoteAmount, true);
|
|
125
|
-
if (TAKER_DEFAULT_POLICY.usesQuote) {
|
|
126
|
-
quoteAmount =
|
|
127
|
-
quoteAmount - TAKER_DEFAULT_POLICY.calculateFee(quoteAmount, false);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
baseAmount =
|
|
131
|
-
baseAmount + TAKER_DEFAULT_POLICY.calculateFee(baseAmount, false);
|
|
132
|
-
}
|
|
133
|
-
if (quoteAmount === 0n) {
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
takeResult[currentDepth.bookId].takenAmount += quoteAmount;
|
|
137
|
-
takeResult[currentDepth.bookId].spendAmount += baseAmount;
|
|
138
|
-
totalTakenQuoteAmount += quoteAmount;
|
|
139
|
-
if (amountOut <= totalTakenQuoteAmount) {
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
if (ticks.length === index + 1) {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
index++;
|
|
146
|
-
tick = ticks[index];
|
|
147
|
-
}
|
|
148
|
-
return Object.fromEntries(Object.entries(takeResult).filter(([, value]) => value.spendAmount > 0 && value.takenAmount > 0));
|
|
149
|
-
};
|
|
150
|
-
spendInner = ({ depths, // only bid orders
|
|
151
|
-
limitPrice, amountIn, // base
|
|
152
|
-
}) => {
|
|
153
|
-
if (depths.length === 0) {
|
|
154
|
-
return {};
|
|
155
|
-
}
|
|
156
|
-
const spendResult = {};
|
|
157
|
-
for (const depth of depths) {
|
|
158
|
-
if (!spendResult[depth.bookId]) {
|
|
159
|
-
spendResult[depth.bookId] = {
|
|
160
|
-
takenAmount: 0n,
|
|
161
|
-
spendAmount: 0n,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
let totalSpendBaseAmount = 0n;
|
|
166
|
-
const ticks = depths
|
|
167
|
-
.sort((a, b) => Number(b.tick) - Number(a.tick))
|
|
168
|
-
.map((depth) => depth.tick);
|
|
169
|
-
let index = 0;
|
|
170
|
-
let tick = ticks[index];
|
|
171
|
-
while (totalSpendBaseAmount <= amountIn && tick > -8388608n) {
|
|
172
|
-
if (limitPrice > toPrice(tick)) {
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
const currentDepth = depths.find((depth) => depth.tick === tick);
|
|
176
|
-
const currentBook = this.books.find((book) => book.id === BigInt(currentDepth.bookId));
|
|
177
|
-
let maxAmount = TAKER_DEFAULT_POLICY.usesQuote
|
|
178
|
-
? amountIn - totalSpendBaseAmount
|
|
179
|
-
: TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountIn - totalSpendBaseAmount, false);
|
|
180
|
-
maxAmount = baseToQuote(tick, maxAmount, false) / currentBook.unit;
|
|
181
|
-
if (maxAmount === 0n) {
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
let quoteAmount = (currentDepth.rawAmount > maxAmount
|
|
185
|
-
? maxAmount
|
|
186
|
-
: currentDepth.rawAmount) * currentBook.unit;
|
|
187
|
-
let baseAmount = quoteToBase(tick, quoteAmount, true);
|
|
188
|
-
if (TAKER_DEFAULT_POLICY.usesQuote) {
|
|
189
|
-
quoteAmount =
|
|
190
|
-
quoteAmount - TAKER_DEFAULT_POLICY.calculateFee(quoteAmount, false);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
baseAmount =
|
|
194
|
-
baseAmount + TAKER_DEFAULT_POLICY.calculateFee(baseAmount, false);
|
|
195
|
-
}
|
|
196
|
-
if (baseAmount === 0n) {
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
spendResult[currentDepth.bookId].takenAmount += quoteAmount;
|
|
200
|
-
spendResult[currentDepth.bookId].spendAmount += baseAmount;
|
|
201
|
-
totalSpendBaseAmount += baseAmount;
|
|
202
|
-
if (ticks.length === index + 1) {
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
index++;
|
|
206
|
-
tick = ticks[index];
|
|
207
|
-
}
|
|
208
|
-
return Object.fromEntries(Object.entries(spendResult).filter(([, value]) => value.spendAmount > 0 && value.takenAmount > 0));
|
|
209
|
-
};
|
|
210
280
|
}
|
|
211
281
|
//# sourceMappingURL=market.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/model/market.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAM5D,MAAM,OAAO,MAAM;
|
|
1
|
+
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/model/market.ts"],"names":[],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