@clober/v2-sdk 0.0.3 → 0.0.5
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/abis/core/book-viewer-abi.js +189 -0
- package/dist/cjs/abis/core/book-viewer-abi.js.map +1 -0
- package/dist/cjs/apis/market.js +42 -33
- package/dist/cjs/apis/market.js.map +1 -1
- package/dist/cjs/apis/open-order.js +10 -7
- package/dist/cjs/apis/open-order.js.map +1 -1
- package/dist/cjs/apis/subgraph.js.map +1 -1
- package/dist/cjs/approval.js +4 -4
- package/dist/cjs/approval.js.map +1 -1
- package/dist/cjs/call.js +197 -186
- package/dist/cjs/call.js.map +1 -1
- package/dist/cjs/constants/client.js +14 -0
- package/dist/cjs/constants/client.js.map +1 -0
- package/dist/cjs/model/book.js +8 -1
- package/dist/cjs/model/book.js.map +1 -1
- package/dist/cjs/model/market.js +44 -171
- package/dist/cjs/model/market.js.map +1 -1
- package/dist/cjs/signature.js +7 -11
- package/dist/cjs/signature.js.map +1 -1
- package/dist/cjs/utils/approval.js +3 -8
- package/dist/cjs/utils/approval.js.map +1 -1
- package/dist/cjs/utils/build-transaction.js +4 -8
- package/dist/cjs/utils/build-transaction.js.map +1 -1
- package/dist/cjs/{apis → utils}/currency.js +3 -7
- package/dist/cjs/utils/currency.js.map +1 -0
- package/dist/cjs/utils/decorator.js +13 -0
- package/dist/cjs/utils/decorator.js.map +1 -0
- package/dist/cjs/utils/open.js +36 -0
- package/dist/cjs/utils/open.js.map +1 -0
- package/dist/cjs/utils/unit.js +3 -7
- package/dist/cjs/utils/unit.js.map +1 -1
- package/dist/cjs/view.js +24 -44
- package/dist/cjs/view.js.map +1 -1
- package/dist/esm/abis/core/book-viewer-abi.js +186 -0
- package/dist/esm/abis/core/book-viewer-abi.js.map +1 -0
- package/dist/esm/apis/market.js +43 -34
- package/dist/esm/apis/market.js.map +1 -1
- package/dist/esm/apis/open-order.js +10 -7
- package/dist/esm/apis/open-order.js.map +1 -1
- package/dist/esm/apis/subgraph.js.map +1 -1
- package/dist/esm/approval.js +5 -4
- package/dist/esm/approval.js.map +1 -1
- package/dist/esm/call.js +213 -191
- package/dist/esm/call.js.map +1 -1
- package/dist/esm/constants/client.js +10 -0
- package/dist/esm/constants/client.js.map +1 -0
- package/dist/esm/model/book.js +8 -1
- package/dist/esm/model/book.js.map +1 -1
- package/dist/esm/model/market.js +45 -176
- package/dist/esm/model/market.js.map +1 -1
- package/dist/esm/signature.js +8 -11
- package/dist/esm/signature.js.map +1 -1
- package/dist/esm/utils/approval.js +3 -8
- package/dist/esm/utils/approval.js.map +1 -1
- package/dist/esm/utils/build-transaction.js +5 -9
- package/dist/esm/utils/build-transaction.js.map +1 -1
- package/dist/esm/{apis → utils}/currency.js +4 -8
- package/dist/esm/utils/currency.js.map +1 -0
- package/dist/esm/utils/decorator.js +9 -0
- package/dist/esm/utils/decorator.js.map +1 -0
- package/dist/esm/utils/open.js +32 -0
- package/dist/esm/utils/open.js.map +1 -0
- package/dist/esm/utils/unit.js +4 -8
- package/dist/esm/utils/unit.js.map +1 -1
- package/dist/esm/view.js +25 -39
- package/dist/esm/view.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/abis/core/book-viewer-abi.d.ts +141 -0
- package/dist/types/abis/core/book-viewer-abi.d.ts.map +1 -0
- package/dist/types/apis/market.d.ts +1 -1
- package/dist/types/apis/market.d.ts.map +1 -1
- package/dist/types/apis/open-order.d.ts +3 -3
- package/dist/types/apis/open-order.d.ts.map +1 -1
- package/dist/types/approval.d.ts +6 -3
- package/dist/types/approval.d.ts.map +1 -1
- package/dist/types/call.d.ts +82 -31
- package/dist/types/call.d.ts.map +1 -1
- package/dist/types/constants/client.d.ts +5 -0
- package/dist/types/constants/client.d.ts.map +1 -0
- package/dist/types/model/book.d.ts +3 -1
- package/dist/types/model/book.d.ts.map +1 -1
- package/dist/types/model/depth.d.ts +0 -2
- package/dist/types/model/depth.d.ts.map +1 -1
- package/dist/types/model/market.d.ts +11 -13
- package/dist/types/model/market.d.ts.map +1 -1
- package/dist/types/model/open-order.d.ts +5 -2
- package/dist/types/model/open-order.d.ts.map +1 -1
- package/dist/types/signature.d.ts +7 -3
- package/dist/types/signature.d.ts.map +1 -1
- package/dist/types/type.d.ts +14 -6
- package/dist/types/type.d.ts.map +1 -1
- package/dist/types/utils/approval.d.ts +1 -1
- package/dist/types/utils/approval.d.ts.map +1 -1
- package/dist/types/utils/build-transaction.d.ts +3 -4
- package/dist/types/utils/build-transaction.d.ts.map +1 -1
- package/dist/types/{apis → utils}/currency.d.ts +1 -1
- package/dist/types/utils/currency.d.ts.map +1 -0
- package/dist/types/utils/decorator.d.ts +6 -0
- package/dist/types/utils/decorator.d.ts.map +1 -0
- package/dist/types/utils/open.d.ts +3 -0
- package/dist/types/utils/open.d.ts.map +1 -0
- package/dist/types/utils/unit.d.ts +2 -2
- package/dist/types/utils/unit.d.ts.map +1 -1
- package/dist/types/view.d.ts +36 -24
- package/dist/types/view.d.ts.map +1 -1
- package/package.json +1 -8
- package/dist/cjs/apis/currency.js.map +0 -1
- package/dist/esm/apis/currency.js.map +0 -1
- package/dist/types/apis/currency.d.ts.map +0 -1
package/dist/cjs/model/market.js
CHANGED
|
@@ -6,10 +6,9 @@ const market_1 = require("../utils/market");
|
|
|
6
6
|
const tick_1 = require("../utils/tick");
|
|
7
7
|
const prices_1 = require("../utils/prices");
|
|
8
8
|
const fee_1 = require("../constants/fee");
|
|
9
|
-
const math_1 = require("../utils/math");
|
|
10
9
|
const decimals_1 = require("../utils/decimals");
|
|
11
10
|
class Market {
|
|
12
|
-
constructor({ chainId, tokens,
|
|
11
|
+
constructor({ chainId, tokens, bidBook, askBook, }) {
|
|
13
12
|
Object.defineProperty(this, "makerFee", {
|
|
14
13
|
enumerable: true,
|
|
15
14
|
configurable: true,
|
|
@@ -64,7 +63,13 @@ class Market {
|
|
|
64
63
|
writable: true,
|
|
65
64
|
value: void 0
|
|
66
65
|
});
|
|
67
|
-
Object.defineProperty(this, "
|
|
66
|
+
Object.defineProperty(this, "bidBook", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: void 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "askBook", {
|
|
68
73
|
enumerable: true,
|
|
69
74
|
configurable: true,
|
|
70
75
|
writable: true,
|
|
@@ -76,20 +81,22 @@ class Market {
|
|
|
76
81
|
writable: true,
|
|
77
82
|
value: ({ takeQuote, limitPrice, amountOut, }) => {
|
|
78
83
|
if (takeQuote) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
.
|
|
82
|
-
|
|
84
|
+
return {
|
|
85
|
+
bookId: this.bidBook.id,
|
|
86
|
+
...this.bidBook.take({
|
|
87
|
+
limitPrice,
|
|
88
|
+
amountOut,
|
|
89
|
+
}),
|
|
90
|
+
};
|
|
83
91
|
}
|
|
84
92
|
else {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
+
return {
|
|
94
|
+
bookId: this.askBook.id,
|
|
95
|
+
...this.askBook.take({
|
|
96
|
+
limitPrice: (0, tick_1.invertPrice)(limitPrice),
|
|
97
|
+
amountOut,
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
});
|
|
@@ -99,180 +106,46 @@ class Market {
|
|
|
99
106
|
writable: true,
|
|
100
107
|
value: ({ spendBase, limitPrice, amountIn, }) => {
|
|
101
108
|
if (spendBase) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
.
|
|
105
|
-
|
|
109
|
+
return {
|
|
110
|
+
bookId: this.bidBook.id,
|
|
111
|
+
...this.bidBook.spend({
|
|
112
|
+
limitPrice,
|
|
113
|
+
amountIn,
|
|
114
|
+
}),
|
|
115
|
+
};
|
|
106
116
|
}
|
|
107
117
|
else {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
Object.defineProperty(this, "takeInner", {
|
|
120
|
-
enumerable: true,
|
|
121
|
-
configurable: true,
|
|
122
|
-
writable: true,
|
|
123
|
-
value: ({ depths, limitPrice, amountOut, }) => {
|
|
124
|
-
if (depths.length === 0) {
|
|
125
|
-
return {};
|
|
126
|
-
}
|
|
127
|
-
const takeResult = {};
|
|
128
|
-
for (const depth of depths) {
|
|
129
|
-
if (!takeResult[depth.bookId]) {
|
|
130
|
-
takeResult[depth.bookId] = {
|
|
131
|
-
takenAmount: 0n,
|
|
132
|
-
spendAmount: 0n,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
let totalTakenQuoteAmount = 0n;
|
|
137
|
-
const ticks = depths
|
|
138
|
-
.sort((a, b) => Number(b.tick) - Number(a.tick))
|
|
139
|
-
.map((depth) => depth.tick);
|
|
140
|
-
let index = 0;
|
|
141
|
-
let tick = ticks[index];
|
|
142
|
-
while (tick > -8388608n) {
|
|
143
|
-
if (limitPrice > (0, tick_1.toPrice)(tick)) {
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
const currentDepth = depths.find((depth) => depth.tick === tick);
|
|
147
|
-
const currentBook = this.books.find((book) => book.id === BigInt(currentDepth.bookId));
|
|
148
|
-
let maxAmount = fee_1.TAKER_DEFAULT_POLICY.usesQuote
|
|
149
|
-
? fee_1.TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountOut - totalTakenQuoteAmount, true)
|
|
150
|
-
: amountOut - totalTakenQuoteAmount;
|
|
151
|
-
maxAmount = (0, math_1.divide)(maxAmount, currentBook.unit, true);
|
|
152
|
-
if (maxAmount === 0n) {
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
let quoteAmount = (currentDepth.rawAmount > maxAmount
|
|
156
|
-
? maxAmount
|
|
157
|
-
: currentDepth.rawAmount) * currentBook.unit;
|
|
158
|
-
let baseAmount = (0, decimals_1.quoteToBase)(tick, quoteAmount, true);
|
|
159
|
-
if (fee_1.TAKER_DEFAULT_POLICY.usesQuote) {
|
|
160
|
-
quoteAmount =
|
|
161
|
-
quoteAmount - fee_1.TAKER_DEFAULT_POLICY.calculateFee(quoteAmount, false);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
baseAmount =
|
|
165
|
-
baseAmount + fee_1.TAKER_DEFAULT_POLICY.calculateFee(baseAmount, false);
|
|
166
|
-
}
|
|
167
|
-
if (quoteAmount === 0n) {
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
takeResult[currentDepth.bookId].takenAmount += quoteAmount;
|
|
171
|
-
takeResult[currentDepth.bookId].spendAmount += baseAmount;
|
|
172
|
-
totalTakenQuoteAmount += quoteAmount;
|
|
173
|
-
if (amountOut <= totalTakenQuoteAmount) {
|
|
174
|
-
break;
|
|
175
|
-
}
|
|
176
|
-
if (ticks.length === index + 1) {
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
index++;
|
|
180
|
-
tick = ticks[index];
|
|
181
|
-
}
|
|
182
|
-
return Object.fromEntries(Object.entries(takeResult).filter(([, value]) => value.spendAmount > 0 && value.takenAmount > 0));
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
Object.defineProperty(this, "spendInner", {
|
|
186
|
-
enumerable: true,
|
|
187
|
-
configurable: true,
|
|
188
|
-
writable: true,
|
|
189
|
-
value: ({ depths, limitPrice, amountIn, }) => {
|
|
190
|
-
if (depths.length === 0) {
|
|
191
|
-
return {};
|
|
192
|
-
}
|
|
193
|
-
const spendResult = {};
|
|
194
|
-
for (const depth of depths) {
|
|
195
|
-
if (!spendResult[depth.bookId]) {
|
|
196
|
-
spendResult[depth.bookId] = {
|
|
197
|
-
takenAmount: 0n,
|
|
198
|
-
spendAmount: 0n,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
let totalSpendBaseAmount = 0n;
|
|
203
|
-
const ticks = depths
|
|
204
|
-
.sort((a, b) => Number(b.tick) - Number(a.tick))
|
|
205
|
-
.map((depth) => depth.tick);
|
|
206
|
-
let index = 0;
|
|
207
|
-
let tick = ticks[index];
|
|
208
|
-
while (totalSpendBaseAmount <= amountIn && tick > -8388608n) {
|
|
209
|
-
if (limitPrice > (0, tick_1.toPrice)(tick)) {
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
const currentDepth = depths.find((depth) => depth.tick === tick);
|
|
213
|
-
const currentBook = this.books.find((book) => book.id === BigInt(currentDepth.bookId));
|
|
214
|
-
let maxAmount = fee_1.TAKER_DEFAULT_POLICY.usesQuote
|
|
215
|
-
? amountIn - totalSpendBaseAmount
|
|
216
|
-
: fee_1.TAKER_DEFAULT_POLICY.calculateOriginalAmount(amountIn - totalSpendBaseAmount, false);
|
|
217
|
-
maxAmount = (0, decimals_1.baseToQuote)(tick, maxAmount, false) / currentBook.unit;
|
|
218
|
-
if (maxAmount === 0n) {
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
let quoteAmount = (currentDepth.rawAmount > maxAmount
|
|
222
|
-
? maxAmount
|
|
223
|
-
: currentDepth.rawAmount) * currentBook.unit;
|
|
224
|
-
let baseAmount = (0, decimals_1.quoteToBase)(tick, quoteAmount, true);
|
|
225
|
-
if (fee_1.TAKER_DEFAULT_POLICY.usesQuote) {
|
|
226
|
-
quoteAmount =
|
|
227
|
-
quoteAmount - fee_1.TAKER_DEFAULT_POLICY.calculateFee(quoteAmount, false);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
baseAmount =
|
|
231
|
-
baseAmount + fee_1.TAKER_DEFAULT_POLICY.calculateFee(baseAmount, false);
|
|
232
|
-
}
|
|
233
|
-
if (baseAmount === 0n) {
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
spendResult[currentDepth.bookId].takenAmount += quoteAmount;
|
|
237
|
-
spendResult[currentDepth.bookId].spendAmount += baseAmount;
|
|
238
|
-
totalSpendBaseAmount += baseAmount;
|
|
239
|
-
if (ticks.length === index + 1) {
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
index++;
|
|
243
|
-
tick = ticks[index];
|
|
118
|
+
return {
|
|
119
|
+
bookId: this.askBook.id,
|
|
120
|
+
...this.askBook.spend({
|
|
121
|
+
limitPrice: (0, tick_1.invertPrice)(limitPrice),
|
|
122
|
+
amountIn,
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
244
125
|
}
|
|
245
|
-
return Object.fromEntries(Object.entries(spendResult).filter(([, value]) => value.spendAmount > 0 && value.takenAmount > 0));
|
|
246
126
|
}
|
|
247
127
|
});
|
|
248
128
|
const { marketId, quoteTokenAddress, baseTokenAddress } = (0, market_1.getMarketId)(chainId, tokens.map((token) => token.address));
|
|
249
129
|
this.id = marketId;
|
|
250
130
|
this.quote = tokens.find((token) => (0, viem_1.isAddressEqual)(token.address, quoteTokenAddress));
|
|
251
131
|
this.base = tokens.find((token) => (0, viem_1.isAddressEqual)(token.address, baseTokenAddress));
|
|
252
|
-
this.bids =
|
|
253
|
-
.filter((book) => (0, viem_1.isAddressEqual)(book.quote.address, this.quote.address))
|
|
254
|
-
.flatMap((book) => book.depths)
|
|
255
|
-
.map((depth) => ({
|
|
132
|
+
this.bids = bidBook.depths.map((depth) => ({
|
|
256
133
|
price: (0, prices_1.formatPrice)((0, tick_1.toPrice)(depth.tick), this.quote.decimals, this.base.decimals),
|
|
257
|
-
baseAmount: (0, decimals_1.quoteToBase)(depth.tick, depth.rawAmount *
|
|
134
|
+
baseAmount: (0, decimals_1.quoteToBase)(depth.tick, depth.rawAmount * bidBook.unit, false),
|
|
258
135
|
}));
|
|
259
|
-
this.bidBookOpen =
|
|
260
|
-
|
|
261
|
-
this.asks = books
|
|
262
|
-
.filter((book) => (0, viem_1.isAddressEqual)(book.quote.address, this.base.address))
|
|
263
|
-
.flatMap((book) => book.depths)
|
|
264
|
-
.map((depth) => {
|
|
136
|
+
this.bidBookOpen = bidBook.isOpened;
|
|
137
|
+
this.asks = askBook.depths.map((depth) => {
|
|
265
138
|
const price = (0, tick_1.invertPrice)((0, tick_1.toPrice)(depth.tick));
|
|
266
139
|
const readablePrice = (0, prices_1.formatPrice)(price, this.quote.decimals, this.base.decimals);
|
|
267
|
-
const baseAmount = depth.rawAmount *
|
|
140
|
+
const baseAmount = depth.rawAmount * askBook.unit;
|
|
268
141
|
return {
|
|
269
142
|
price: readablePrice,
|
|
270
143
|
baseAmount,
|
|
271
144
|
};
|
|
272
145
|
});
|
|
273
|
-
this.askBookOpen =
|
|
274
|
-
|
|
275
|
-
this.
|
|
146
|
+
this.askBookOpen = askBook.isOpened;
|
|
147
|
+
this.bidBook = bidBook;
|
|
148
|
+
this.askBook = askBook;
|
|
276
149
|
}
|
|
277
150
|
}
|
|
278
151
|
exports.Market = Market;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/model/market.ts"],"names":[],"mappings":";;;AAAA,+BAAqC;AAErC,4CAA6C;AAE7C,wCAAoD;AACpD,4CAA6C;AAC7C,0CAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/model/market.ts"],"names":[],"mappings":";;;AAAA,+BAAqC;AAErC,4CAA6C;AAE7C,wCAAoD;AACpD,4CAA6C;AAC7C,0CAA6E;AAC7E,gDAA+C;AAM/C,MAAa,MAAM;IAcjB,YAAY,EACV,OAAO,EACP,MAAM,EACN,OAAO,EACP,OAAO,GAMR;QAvBQ;;;;mBAAW,CAAC,MAAM,CAAC,0BAAoB,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG;WAAA;QAC1D;;;;mBAAW,CAAC,MAAM,CAAC,0BAAoB,CAAC,IAAI,CAAC,GAAG,GAAG,CAA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QAAQ,EACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CACnB,CAAA;YACD,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,GAAG,OAAO,CAAC,IAAI,CAAA;YACjD,OAAO;gBACL,KAAK,EAAE,aAAa;gBACpB,UAAU;aACF,CAAA;QACZ,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAA;QAEnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CAyDF;AAhID,wBAgIC"}
|
package/dist/cjs/signature.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.signERC20Permit = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const chain_1 = require("./constants/chain");
|
|
6
5
|
const time_1 = require("./utils/time");
|
|
7
6
|
const addresses_1 = require("./constants/addresses");
|
|
8
|
-
const currency_1 = require("./
|
|
7
|
+
const currency_1 = require("./utils/currency");
|
|
8
|
+
const client_1 = require("./constants/client");
|
|
9
|
+
const decorator_1 = require("./utils/decorator");
|
|
9
10
|
const _abi = [
|
|
10
11
|
{
|
|
11
12
|
inputs: [],
|
|
@@ -53,15 +54,11 @@ const _abi = [
|
|
|
53
54
|
type: 'function',
|
|
54
55
|
},
|
|
55
56
|
];
|
|
56
|
-
|
|
57
|
-
const currency = await (0, currency_1.fetchCurrency)(chainId, token
|
|
57
|
+
exports.signERC20Permit = (0, decorator_1.decorator)(async ({ chainId, account, token, amount, }) => {
|
|
58
|
+
const currency = await (0, currency_1.fetchCurrency)(chainId, token);
|
|
58
59
|
const spender = addresses_1.CONTRACT_ADDRESSES[chainId].Controller;
|
|
59
|
-
const publicClient = (0, viem_1.createPublicClient)({
|
|
60
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
61
|
-
transport: options?.rpcUrl ? (0, viem_1.http)(options.rpcUrl) : (0, viem_1.http)(),
|
|
62
|
-
});
|
|
63
60
|
const value = (0, viem_1.parseUnits)(amount, currency.decimals);
|
|
64
|
-
const [{ result: nonce }, { result: version }, { result: name }] = await
|
|
61
|
+
const [{ result: nonce }, { result: version }, { result: name }] = await client_1.cachedPublicClients[chainId].multicall({
|
|
65
62
|
allowFailure: true,
|
|
66
63
|
contracts: [
|
|
67
64
|
{
|
|
@@ -140,6 +137,5 @@ const signERC20Permit = async (chainId, account, token, amount, options) => {
|
|
|
140
137
|
r,
|
|
141
138
|
deadline,
|
|
142
139
|
};
|
|
143
|
-
};
|
|
144
|
-
exports.signERC20Permit = signERC20Permit;
|
|
140
|
+
});
|
|
145
141
|
//# sourceMappingURL=signature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../../src/signature.ts"],"names":[],"mappings":";;;AAAA,+BAOa;AAGb,uCAA4D;AAC5D,qDAA0D;AAC1D,+CAAgD;AAEhD,+CAAwD;AACxD,iDAA6C;AAE7C,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;QACf,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,QAAQ;gBACtB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,QAAQ;aACf;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EA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ACR,CAAC,CAAA;IACF,MAAM,KAAK,GAAG,MAAM,IAAA,sBAAe,EAAC;QAClC,GAAG,IAAI;QACP,SAAS;QACT,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAA;IACF,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;IACtC,CAAC;IACD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,IAAA,qBAAc,EAAC,SAAS,CAAC,CAAA;IAC7C,OAAO;QACL,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;QACZ,CAAC;QACD,CAAC;QACD,QAAQ;KACT,CAAA;AACH,CAAC,CACF,CAAA"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchIsApprovedForAll = void 0;
|
|
4
|
-
const viem_1 = require("viem");
|
|
5
|
-
const chain_1 = require("../constants/chain");
|
|
6
4
|
const addresses_1 = require("../constants/addresses");
|
|
5
|
+
const client_1 = require("../constants/client");
|
|
7
6
|
const _abi = [
|
|
8
7
|
{
|
|
9
8
|
inputs: [
|
|
@@ -30,12 +29,8 @@ const _abi = [
|
|
|
30
29
|
type: 'function',
|
|
31
30
|
},
|
|
32
31
|
];
|
|
33
|
-
async function fetchIsApprovedForAll(chainId, owner
|
|
34
|
-
|
|
35
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
36
|
-
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
37
|
-
});
|
|
38
|
-
return publicClient.readContract({
|
|
32
|
+
async function fetchIsApprovedForAll(chainId, owner) {
|
|
33
|
+
return client_1.cachedPublicClients[chainId].readContract({
|
|
39
34
|
address: addresses_1.CONTRACT_ADDRESSES[chainId].BookManager,
|
|
40
35
|
abi: _abi,
|
|
41
36
|
functionName: 'isApprovedForAll',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../../src/utils/approval.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../../src/utils/approval.ts"],"names":[],"mappings":";;;AACA,sDAA2D;AAC3D,gDAAyD;AAEzD,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;aAChB;YACD;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,MAAM;gBACpB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,MAAM;aACb;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEH,KAAK,UAAU,qBAAqB,CACzC,OAAkB,EAClB,KAAoB;IAEpB,OAAO,4BAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;QAC/C,OAAO,EAAE,8BAAkB,CAAC,OAAO,CAAE,CAAC,WAAW;QACjD,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,kBAAkB;QAChC,IAAI,EAAE,CAAC,KAAK,EAAE,8BAAkB,CAAC,OAAO,CAAE,CAAC,UAAU,CAAC;KACvD,CAAC,CAAA;AACJ,CAAC;AAVD,sDAUC"}
|
|
@@ -2,21 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildTransaction = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
6
|
-
const buildTransaction = async (chainId, args
|
|
7
|
-
const publicClient = (0, viem_1.createPublicClient)({
|
|
8
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
9
|
-
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
10
|
-
});
|
|
5
|
+
const client_1 = require("../constants/client");
|
|
6
|
+
const buildTransaction = async (chainId, args) => {
|
|
11
7
|
const data = (0, viem_1.encodeFunctionData)(args);
|
|
12
8
|
const [gas, gasPrice] = await Promise.all([
|
|
13
|
-
|
|
9
|
+
client_1.cachedPublicClients[chainId].estimateGas({
|
|
14
10
|
account: args.account,
|
|
15
11
|
data,
|
|
16
12
|
to: args.address,
|
|
17
13
|
value: args.value || 0n,
|
|
18
14
|
}),
|
|
19
|
-
|
|
15
|
+
client_1.cachedPublicClients[chainId].getGasPrice(),
|
|
20
16
|
]);
|
|
21
17
|
return {
|
|
22
18
|
gas,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-transaction.js","sourceRoot":"","sources":["../../../src/utils/build-transaction.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"build-transaction.js","sourceRoot":"","sources":["../../../src/utils/build-transaction.ts"],"names":[],"mappings":";;;AAAA,+BAIa;AAGb,gDAAyD;AAElD,MAAM,gBAAgB,GAAG,KAAK,EACnC,OAAkB,EAClB,IAA0D,EACpC,EAAE;IACxB,MAAM,IAAI,GAAG,IAAA,yBAAkB,EAAC,IAAI,CAAC,CAAA;IACrC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACxC,4BAAmB,CAAC,OAAO,CAAE,CAAC,WAAW,CAAC;YACxC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI;YACJ,EAAE,EAAE,IAAI,CAAC,OAAO;YAChB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;SACxB,CAAC;QACF,4BAAmB,CAAC,OAAO,CAAE,CAAC,WAAW,EAAE;KAC5C,CAAC,CAAA;IACF,OAAO;QACL,GAAG;QACH,QAAQ;QACR,IAAI;QACJ,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;QACvB,EAAE,EAAE,IAAI,CAAC,OAAO;QAChB,IAAI,EAAE,IAAI,CAAC,OAAO;KACnB,CAAA;AACH,CAAC,CAAA;AAtBY,QAAA,gBAAgB,oBAsB5B"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchCurrency = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const client_1 = require("../constants/client");
|
|
6
6
|
const _abi = [
|
|
7
7
|
{
|
|
8
8
|
inputs: [],
|
|
@@ -44,7 +44,7 @@ const _abi = [
|
|
|
44
44
|
type: 'function',
|
|
45
45
|
},
|
|
46
46
|
];
|
|
47
|
-
const fetchCurrency = async (chainId, address
|
|
47
|
+
const fetchCurrency = async (chainId, address) => {
|
|
48
48
|
if ((0, viem_1.isAddressEqual)(address, viem_1.zeroAddress)) {
|
|
49
49
|
return {
|
|
50
50
|
address: viem_1.zeroAddress,
|
|
@@ -53,11 +53,7 @@ const fetchCurrency = async (chainId, address, rpcUrl) => {
|
|
|
53
53
|
decimals: 18,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
58
|
-
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
59
|
-
});
|
|
60
|
-
const [{ result: name }, { result: symbol }, { result: decimals }] = await publicClient.multicall({
|
|
56
|
+
const [{ result: name }, { result: symbol }, { result: decimals }] = await client_1.cachedPublicClients[chainId].multicall({
|
|
61
57
|
contracts: [
|
|
62
58
|
{
|
|
63
59
|
address,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/currency.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAIlD,gDAAyD;AAEzD,MAAM,IAAI,GAAG;IACX;QACE,MA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AQ;aACvB;YACD;gBACE,OAAO;gBACP,GAAG,EAAE,IAAI;gBACT,YAAY,EAAE,UAAU;aACzB;SACF;KACF,CAAC,CAAA;IACJ,OAAO;QACL,OAAO;QACP,IAAI,EAAE,IAAI,IAAI,SAAS;QACvB,MAAM,EAAE,MAAM,IAAI,SAAS;QAC3B,QAAQ,EAAE,QAAQ,IAAI,EAAE;KACzB,CAAA;AACH,CAAC,CAAA;AAvCY,QAAA,aAAa,iBAuCzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decorator = void 0;
|
|
4
|
+
const client_1 = require("../constants/client");
|
|
5
|
+
function decorator(fn) {
|
|
6
|
+
return async (args) => {
|
|
7
|
+
const { chainId, options } = args;
|
|
8
|
+
(0, client_1.buildPublicClient)(chainId, options?.rpcUrl);
|
|
9
|
+
return fn(args);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.decorator = decorator;
|
|
13
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../src/utils/decorator.ts"],"names":[],"mappings":";;;AACA,gDAAuD;AAEvD,SAAgB,SAAS,CAMvB,EAA8B;IAC9B,OAAO,KAAK,EAAE,IAAU,EAAE,EAAE;QAC1B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAG5B,CAAA;QACD,IAAA,0BAAiB,EAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QAC3C,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;IACjB,CAAC,CAAA;AACH,CAAC;AAfD,8BAeC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchIsOpened = void 0;
|
|
4
|
+
const client_1 = require("../constants/client");
|
|
5
|
+
const addresses_1 = require("../constants/addresses");
|
|
6
|
+
const _abi = [
|
|
7
|
+
{
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
internalType: 'BookId',
|
|
11
|
+
name: 'id',
|
|
12
|
+
type: 'uint192',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
name: 'isOpened',
|
|
16
|
+
outputs: [
|
|
17
|
+
{
|
|
18
|
+
internalType: 'bool',
|
|
19
|
+
name: '',
|
|
20
|
+
type: 'bool',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
stateMutability: 'view',
|
|
24
|
+
type: 'function',
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
async function fetchIsOpened(chainId, bookId) {
|
|
28
|
+
return client_1.cachedPublicClients[chainId].readContract({
|
|
29
|
+
address: addresses_1.CONTRACT_ADDRESSES[chainId].BookManager,
|
|
30
|
+
abi: _abi,
|
|
31
|
+
functionName: 'isOpened',
|
|
32
|
+
args: [bookId],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.fetchIsOpened = fetchIsOpened;
|
|
36
|
+
//# sourceMappingURL=open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.js","sourceRoot":"","sources":["../../../src/utils/open.ts"],"names":[],"mappings":";;;AACA,gDAAyD;AACzD,sDAA2D;AAE3D,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,QAAQ;gBACtB,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,MAAM;gBACpB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,MAAM;aACb;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEH,KAAK,UAAU,aAAa,CAAC,OAAkB,EAAE,MAAc;IACpE,OAAO,4BAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;QAC/C,OAAO,EAAE,8BAAkB,CAAC,OAAO,CAAE,CAAC,WAAW;QACjD,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,UAAU;QACxB,IAAI,EAAE,CAAC,MAAM,CAAC;KACf,CAAC,CAAA;AACJ,CAAC;AAPD,sCAOC"}
|
package/dist/cjs/utils/unit.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateUnit = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const client_1 = require("../constants/client");
|
|
6
6
|
const _abi = [
|
|
7
7
|
{
|
|
8
8
|
inputs: [],
|
|
@@ -18,15 +18,11 @@ const _abi = [
|
|
|
18
18
|
type: 'function',
|
|
19
19
|
},
|
|
20
20
|
];
|
|
21
|
-
const calculateUnit = async (chainId, quote
|
|
21
|
+
const calculateUnit = async (chainId, quote) => {
|
|
22
22
|
if ((0, viem_1.isAddressEqual)(quote.address, viem_1.zeroAddress)) {
|
|
23
23
|
return 10n ** 12n;
|
|
24
24
|
}
|
|
25
|
-
const
|
|
26
|
-
chain: chain_1.CHAIN_MAP[chainId],
|
|
27
|
-
transport: rpcUrl ? (0, viem_1.http)(rpcUrl) : (0, viem_1.http)(),
|
|
28
|
-
});
|
|
29
|
-
const totalSupply = await publicClient.readContract({
|
|
25
|
+
const totalSupply = await client_1.cachedPublicClients[chainId].readContract({
|
|
30
26
|
address: quote.address,
|
|
31
27
|
abi: _abi,
|
|
32
28
|
functionName: 'totalSupply',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit.js","sourceRoot":"","sources":["../../../src/utils/unit.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"unit.js","sourceRoot":"","sources":["../../../src/utils/unit.ts"],"names":[],"mappings":";;;AAAA,+BAAkD;AAIlD,gDAAyD;AAEzD,MAAM,IAAI,GAAG;IACX;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA;AAEH,MAAM,aAAa,GAAG,KAAK,EAAE,OAAkB,EAAE,KAAe,EAAE,EAAE;IACzE,IAAI,IAAA,qBAAc,EAAC,KAAK,CAAC,OAAO,EAAE,kBAAW,CAAC,EAAE,CAAC;QAC/C,OAAO,GAAG,IAAI,GAAG,CAAA;IACnB,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,4BAAmB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC;QAClE,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,GAAG,EAAE,IAAI;QACT,YAAY,EAAE,aAAa;KAC5B,CAAC,CAAA;IACF,OAAO,CACL,GAAG;QACH,MAAM,CAAC,WAAW,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CACxE,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,aAAa,iBAazB"}
|