@clober/v2-sdk 0.0.11 → 0.0.13
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/README.md +14 -4
- package/dist/cjs/abis/core/book-viewer-abi.js +2 -2
- package/dist/cjs/call.js +29 -19
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/model/book.js +11 -11
- package/dist/cjs/model/market.js +2 -2
- package/dist/cjs/view.js +5 -5
- package/dist/esm/abis/core/book-viewer-abi.js +2 -2
- package/dist/esm/call.js +31 -21
- package/dist/esm/call.js.map +1 -1
- package/dist/esm/model/book.js +11 -11
- package/dist/esm/model/market.js +2 -2
- package/dist/esm/view.js +8 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/abis/core/book-viewer-abi.d.ts +2 -2
- package/dist/types/call.d.ts +6 -6
- package/dist/types/call.d.ts.map +1 -1
- package/dist/types/model/book.d.ts +2 -2
- package/dist/types/model/market.d.ts +4 -4
- package/dist/types/view.d.ts +5 -5
- package/package.json +1 -1
package/dist/esm/model/book.js
CHANGED
|
@@ -47,11 +47,11 @@ export class Book {
|
|
|
47
47
|
value: ({ limitPrice, amountOut, // quote
|
|
48
48
|
}) => {
|
|
49
49
|
let takenQuoteAmount = 0n;
|
|
50
|
-
let
|
|
50
|
+
let spentBaseAmount = 0n;
|
|
51
51
|
if (this.depths.length === 0) {
|
|
52
52
|
return {
|
|
53
53
|
takenQuoteAmount,
|
|
54
|
-
|
|
54
|
+
spentBaseAmount,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
const ticks = this.depths
|
|
@@ -87,7 +87,7 @@ export class Book {
|
|
|
87
87
|
break;
|
|
88
88
|
}
|
|
89
89
|
takenQuoteAmount += quoteAmount;
|
|
90
|
-
|
|
90
|
+
spentBaseAmount += baseAmount;
|
|
91
91
|
if (amountOut <= takenQuoteAmount) {
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
@@ -96,7 +96,7 @@ export class Book {
|
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
98
|
takenQuoteAmount,
|
|
99
|
-
|
|
99
|
+
spentBaseAmount,
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
});
|
|
@@ -107,11 +107,11 @@ export class Book {
|
|
|
107
107
|
value: ({ limitPrice, amountIn, // base
|
|
108
108
|
}) => {
|
|
109
109
|
let takenQuoteAmount = 0n;
|
|
110
|
-
let
|
|
110
|
+
let spentBaseAmount = 0n;
|
|
111
111
|
if (this.depths.length === 0) {
|
|
112
112
|
return {
|
|
113
113
|
takenQuoteAmount,
|
|
114
|
-
|
|
114
|
+
spentBaseAmount,
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
const ticks = this.depths
|
|
@@ -119,13 +119,13 @@ export class Book {
|
|
|
119
119
|
.map((depth) => depth.tick);
|
|
120
120
|
let index = 0;
|
|
121
121
|
let tick = ticks[index];
|
|
122
|
-
while (
|
|
122
|
+
while (spentBaseAmount <= amountIn && tick > -8388608n) {
|
|
123
123
|
if (limitPrice > toPrice(tick)) {
|
|
124
124
|
break;
|
|
125
125
|
}
|
|
126
126
|
let maxAmount = TAKER_DEFAULT_POLICY.usesQuote
|
|
127
|
-
? amountIn -
|
|
128
|
-
: TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountIn -
|
|
127
|
+
? amountIn - spentBaseAmount
|
|
128
|
+
: TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountIn - spentBaseAmount, false);
|
|
129
129
|
maxAmount = baseToQuote(tick, maxAmount, false) / this.unit;
|
|
130
130
|
if (maxAmount === 0n) {
|
|
131
131
|
break;
|
|
@@ -147,13 +147,13 @@ export class Book {
|
|
|
147
147
|
break;
|
|
148
148
|
}
|
|
149
149
|
takenQuoteAmount += quoteAmount;
|
|
150
|
-
|
|
150
|
+
spentBaseAmount += baseAmount;
|
|
151
151
|
index++;
|
|
152
152
|
tick = ticks[index];
|
|
153
153
|
}
|
|
154
154
|
return {
|
|
155
155
|
takenQuoteAmount,
|
|
156
|
-
|
|
156
|
+
spentBaseAmount,
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
});
|
package/dist/esm/model/market.js
CHANGED
|
@@ -102,9 +102,9 @@ export class Market {
|
|
|
102
102
|
enumerable: true,
|
|
103
103
|
configurable: true,
|
|
104
104
|
writable: true,
|
|
105
|
-
value: ({
|
|
105
|
+
value: ({ spentBase, limitPrice, amountIn, // base if spentBase, quote otherwise
|
|
106
106
|
}) => {
|
|
107
|
-
if (
|
|
107
|
+
if (spentBase) {
|
|
108
108
|
return {
|
|
109
109
|
bookId: this.bidBook.id,
|
|
110
110
|
...this.bidBook.spend({
|
package/dist/esm/view.js
CHANGED
|
@@ -56,7 +56,7 @@ export const getMarket = decorator(async ({ chainId, token0, token1, options, })
|
|
|
56
56
|
* @example
|
|
57
57
|
* import { getExpectedOutput } from '@clober/v2-sdk'
|
|
58
58
|
*
|
|
59
|
-
* const { takenAmount,
|
|
59
|
+
* const { takenAmount, spentAmount } = await getExpectedOutput({
|
|
60
60
|
* chainId: 421614,
|
|
61
61
|
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
62
62
|
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
@@ -72,14 +72,14 @@ export const getExpectedOutput = decorator(async ({ chainId, inputToken, outputT
|
|
|
72
72
|
? MAX_PRICE
|
|
73
73
|
: 0n;
|
|
74
74
|
const inputCurrency = isBid ? market.quote : market.base;
|
|
75
|
-
const { takenQuoteAmount,
|
|
76
|
-
|
|
75
|
+
const { takenQuoteAmount, spentBaseAmount, bookId } = market.spend({
|
|
76
|
+
spentBase: !isBid,
|
|
77
77
|
limitPrice: rawLimitPrice,
|
|
78
78
|
amountIn: parseUnits(amountIn, inputCurrency.decimals),
|
|
79
79
|
});
|
|
80
80
|
return {
|
|
81
81
|
takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
|
|
82
|
-
|
|
82
|
+
spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
|
|
83
83
|
bookId,
|
|
84
84
|
};
|
|
85
85
|
});
|
|
@@ -93,11 +93,11 @@ export const getExpectedOutput = decorator(async ({ chainId, inputToken, outputT
|
|
|
93
93
|
* @param options
|
|
94
94
|
* @param options.limitPrice The maximum limit price to take.
|
|
95
95
|
* @param options.rpcUrl The RPC URL of the blockchain.
|
|
96
|
-
* @returns A Promise resolving to an object containing the taken amount,
|
|
96
|
+
* @returns A Promise resolving to an object containing the taken amount, spent amount and result of the calculation.
|
|
97
97
|
* @example
|
|
98
98
|
* import { getExpectedInput } from '@clober/v2-sdk'
|
|
99
99
|
*
|
|
100
|
-
* const { takenAmount,
|
|
100
|
+
* const { takenAmount, spentAmount } = await getExpectedInput({
|
|
101
101
|
* chainId: 421614,
|
|
102
102
|
* inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
|
|
103
103
|
* outputToken: '0x0000000000000000000000000000000000000000',
|
|
@@ -113,14 +113,14 @@ export const getExpectedInput = decorator(async ({ chainId, inputToken, outputTo
|
|
|
113
113
|
? MAX_PRICE
|
|
114
114
|
: 0n;
|
|
115
115
|
const outputCurrency = isBid ? market.base : market.quote;
|
|
116
|
-
const { takenQuoteAmount,
|
|
116
|
+
const { takenQuoteAmount, spentBaseAmount, bookId } = market.take({
|
|
117
117
|
takeQuote: !isBid,
|
|
118
118
|
limitPrice: rawLimitPrice,
|
|
119
119
|
amountOut: parseUnits(amountOut, outputCurrency.decimals),
|
|
120
120
|
});
|
|
121
121
|
return {
|
|
122
122
|
takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
|
|
123
|
-
|
|
123
|
+
spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
|
|
124
124
|
bookId,
|
|
125
125
|
};
|
|
126
126
|
});
|