@gearbox-protocol/sdk 14.0.0-next.5 → 14.0.0-next.7
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/permissionless/utils/create2.js +2 -2
- package/dist/cjs/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +20 -23
- package/dist/cjs/sdk/market/pricefeeds/updates/fetchPythPayloads.js +1 -1
- package/dist/cjs/sdk/utils/formatter.js +99 -20
- package/dist/esm/permissionless/utils/create2.js +1 -1
- package/dist/esm/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +20 -13
- package/dist/esm/sdk/market/pricefeeds/updates/fetchPythPayloads.js +1 -1
- package/dist/esm/sdk/utils/formatter.js +99 -10
- package/dist/types/dev/create2.d.ts +1 -2
- package/dist/types/dev/replaceStorage.d.ts +1 -1
- package/dist/types/sdk/market/credit/types.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.d.ts +12 -13
- package/dist/types/sdk/pools/types.d.ts +1 -2
- package/dist/types/sdk/router/helpers.d.ts +1 -1
- package/dist/types/sdk/utils/formatter.d.ts +1 -1
- package/dist/types/sdk/utils/toAddress.d.ts +1 -1
- package/dist/types/sdk/utils/viem/getLogsPaginated.d.ts +1 -2
- package/dist/types/sdk/utils/viem/getLogsSafe.d.ts +1 -1
- package/dist/types/sdk/utils/viem/simulateWithPriceUpdates.d.ts +1 -2
- package/package.json +5 -8
|
@@ -28,8 +28,8 @@ __export(create2_exports, {
|
|
|
28
28
|
handleSalt: () => handleSalt
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(create2_exports);
|
|
31
|
-
var import_abitype = require("abitype");
|
|
32
31
|
var import_viem = require("viem");
|
|
32
|
+
var import_utils = require("viem/utils");
|
|
33
33
|
const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
|
|
34
34
|
function handleSalt(salt) {
|
|
35
35
|
if (salt.slice(0, 2) !== "0x" || salt.length !== 66) {
|
|
@@ -63,7 +63,7 @@ function createCreate2DeployRawTx(bytecode, salt) {
|
|
|
63
63
|
type: "fallback"
|
|
64
64
|
}
|
|
65
65
|
];
|
|
66
|
-
const signature = (0,
|
|
66
|
+
const signature = (0, import_utils.formatAbiItem)(deterministicDeployerAbi[0]);
|
|
67
67
|
const contractMethod = {
|
|
68
68
|
name: "fallback",
|
|
69
69
|
inputs: [],
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var PythAccumulatorUpdateData_exports = {};
|
|
30
20
|
__export(PythAccumulatorUpdateData_exports, {
|
|
@@ -35,7 +25,6 @@ __export(PythAccumulatorUpdateData_exports, {
|
|
|
35
25
|
sliceAccumulatorUpdateData: () => sliceAccumulatorUpdateData
|
|
36
26
|
});
|
|
37
27
|
module.exports = __toCommonJS(PythAccumulatorUpdateData_exports);
|
|
38
|
-
var import_bn = __toESM(require("bn.js"));
|
|
39
28
|
var import_buffer = require("buffer");
|
|
40
29
|
const ACCUMULATOR_MAGIC = "504e4155";
|
|
41
30
|
const MAJOR_VERSION = 1;
|
|
@@ -43,6 +32,14 @@ const MINOR_VERSION = 0;
|
|
|
43
32
|
const KECCAK160_HASH_SIZE = 20;
|
|
44
33
|
const PRICE_FEED_MESSAGE_VARIANT = 0;
|
|
45
34
|
const TWAP_MESSAGE_VARIANT = 1;
|
|
35
|
+
function bufToBigInt(buf) {
|
|
36
|
+
if (buf.length === 0) return 0n;
|
|
37
|
+
let result = 0n;
|
|
38
|
+
for (let i = 0; i < buf.length; i++) {
|
|
39
|
+
result = result << 8n | BigInt(buf[i]);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
46
43
|
function isAccumulatorUpdateData(updateBytes) {
|
|
47
44
|
return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
|
|
48
45
|
}
|
|
@@ -55,19 +52,19 @@ function parsePriceFeedMessage(message) {
|
|
|
55
52
|
cursor += 1;
|
|
56
53
|
const feedId = message.subarray(cursor, cursor + 32);
|
|
57
54
|
cursor += 32;
|
|
58
|
-
const price =
|
|
55
|
+
const price = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
59
56
|
cursor += 8;
|
|
60
|
-
const confidence =
|
|
57
|
+
const confidence = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
61
58
|
cursor += 8;
|
|
62
59
|
const exponent = message.readInt32BE(cursor);
|
|
63
60
|
cursor += 4;
|
|
64
|
-
const publishTime =
|
|
61
|
+
const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
65
62
|
cursor += 8;
|
|
66
|
-
const prevPublishTime =
|
|
63
|
+
const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
67
64
|
cursor += 8;
|
|
68
|
-
const emaPrice =
|
|
65
|
+
const emaPrice = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
69
66
|
cursor += 8;
|
|
70
|
-
const emaConf =
|
|
67
|
+
const emaConf = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
71
68
|
cursor += 8;
|
|
72
69
|
return {
|
|
73
70
|
feedId,
|
|
@@ -89,19 +86,19 @@ function parseTwapMessage(message) {
|
|
|
89
86
|
cursor += 1;
|
|
90
87
|
const feedId = message.subarray(cursor, cursor + 32);
|
|
91
88
|
cursor += 32;
|
|
92
|
-
const cumulativePrice =
|
|
89
|
+
const cumulativePrice = bufToBigInt(message.subarray(cursor, cursor + 16));
|
|
93
90
|
cursor += 16;
|
|
94
|
-
const cumulativeConf =
|
|
91
|
+
const cumulativeConf = bufToBigInt(message.subarray(cursor, cursor + 16));
|
|
95
92
|
cursor += 16;
|
|
96
|
-
const numDownSlots =
|
|
93
|
+
const numDownSlots = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
97
94
|
cursor += 8;
|
|
98
95
|
const exponent = message.readInt32BE(cursor);
|
|
99
96
|
cursor += 4;
|
|
100
|
-
const publishTime =
|
|
97
|
+
const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
101
98
|
cursor += 8;
|
|
102
|
-
const prevPublishTime =
|
|
99
|
+
const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
103
100
|
cursor += 8;
|
|
104
|
-
const publishSlot =
|
|
101
|
+
const publishSlot = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
105
102
|
cursor += 8;
|
|
106
103
|
return {
|
|
107
104
|
feedId,
|
|
@@ -123,7 +123,7 @@ function splitAccumulatorUpdates(binary) {
|
|
|
123
123
|
const msg = (0, import_PythAccumulatorUpdateData.parsePriceFeedMessage)(upd);
|
|
124
124
|
results.push({
|
|
125
125
|
dataFeedId: (0, import_viem.toHex)(msg.feedId),
|
|
126
|
-
timestamp: msg.publishTime
|
|
126
|
+
timestamp: Number(msg.publishTime),
|
|
127
127
|
data: (0, import_viem.toHex)((0, import_PythAccumulatorUpdateData.sliceAccumulatorUpdateData)(data, i, i + 1))
|
|
128
128
|
});
|
|
129
129
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var formatter_exports = {};
|
|
30
20
|
__export(formatter_exports, {
|
|
@@ -47,7 +37,6 @@ __export(formatter_exports, {
|
|
|
47
37
|
});
|
|
48
38
|
module.exports = __toCommonJS(formatter_exports);
|
|
49
39
|
var import_date_fns = require("date-fns");
|
|
50
|
-
var import_decimal = __toESM(require("decimal.js-light"));
|
|
51
40
|
var import_constants = require("../constants/index.js");
|
|
52
41
|
const toBigInt = (v) => {
|
|
53
42
|
const value = typeof v === "object" && v.type === "BigNumber" ? v.hex : v.toString();
|
|
@@ -151,17 +140,22 @@ function formatTimestamp(timestamp, raw = true) {
|
|
|
151
140
|
function rayToNumber(num) {
|
|
152
141
|
return Number(toBigInt(num) / 10n ** 21n) / 1e6;
|
|
153
142
|
}
|
|
154
|
-
function toSignificant(num, decimals, precision = 6) {
|
|
155
|
-
if (num === 1n) return "0";
|
|
156
|
-
const divider = new import_decimal.default(10).toPower(decimals);
|
|
157
|
-
const number = new import_decimal.default(num.toString()).div(divider);
|
|
158
|
-
return number.toSignificantDigits(precision, 4).toString();
|
|
159
|
-
}
|
|
160
143
|
function toBN(num, decimals) {
|
|
161
144
|
if (num === "") return 0n;
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
|
|
145
|
+
const negative = num.startsWith("-");
|
|
146
|
+
const abs = negative ? num.slice(1) : num;
|
|
147
|
+
const [intPart = "0", fracPart = ""] = abs.split(".");
|
|
148
|
+
let frac = fracPart;
|
|
149
|
+
let roundUp = false;
|
|
150
|
+
if (frac.length > decimals) {
|
|
151
|
+
roundUp = frac.charCodeAt(decimals) >= 53;
|
|
152
|
+
frac = frac.slice(0, decimals);
|
|
153
|
+
} else {
|
|
154
|
+
frac = frac.padEnd(decimals, "0");
|
|
155
|
+
}
|
|
156
|
+
let result = BigInt(intPart + frac);
|
|
157
|
+
if (roundUp) result += 1n;
|
|
158
|
+
return negative ? -result : result;
|
|
165
159
|
}
|
|
166
160
|
function shortAddress(address) {
|
|
167
161
|
return address === void 0 ? "" : `${address.slice(0, 6)}...${address.slice(address.length - 4)}`;
|
|
@@ -175,6 +169,91 @@ function formatPercentage(healthFactor, decimals = 2) {
|
|
|
175
169
|
function formatLeverage(leverage, decimals = 2) {
|
|
176
170
|
return (leverage / Number(import_constants.LEVERAGE_DECIMALS)).toFixed(decimals);
|
|
177
171
|
}
|
|
172
|
+
function formatDecimalJsLikeToString(digits, base10exp) {
|
|
173
|
+
const len = digits.length;
|
|
174
|
+
const isExp = base10exp <= -7 || base10exp >= 21;
|
|
175
|
+
if (isExp) {
|
|
176
|
+
let coeff = digits;
|
|
177
|
+
if (len > 1) {
|
|
178
|
+
coeff = `${digits[0]}.${digits.slice(1)}`;
|
|
179
|
+
}
|
|
180
|
+
const exp = base10exp;
|
|
181
|
+
const expStr = exp < 0 ? `e${exp}` : `e+${exp}`;
|
|
182
|
+
return `${coeff}${expStr}`;
|
|
183
|
+
}
|
|
184
|
+
if (base10exp < 0) {
|
|
185
|
+
return `0.${"0".repeat(-base10exp - 1)}${digits}`;
|
|
186
|
+
}
|
|
187
|
+
if (base10exp >= len) {
|
|
188
|
+
return `${digits}${"0".repeat(base10exp + 1 - len)}`;
|
|
189
|
+
}
|
|
190
|
+
const k = base10exp + 1;
|
|
191
|
+
if (k === len) return digits;
|
|
192
|
+
return `${digits.slice(0, k)}.${digits.slice(k)}`;
|
|
193
|
+
}
|
|
194
|
+
function roundToSignificantDigitsHalfUp(digits, base10exp, precision) {
|
|
195
|
+
if (precision < 1) {
|
|
196
|
+
throw new Error(`Invalid precision: ${precision}`);
|
|
197
|
+
}
|
|
198
|
+
if (digits === "0") return { digits: "0", base10exp: 0 };
|
|
199
|
+
let norm = digits;
|
|
200
|
+
while (norm.length > 1 && norm.endsWith("0")) {
|
|
201
|
+
norm = norm.slice(0, -1);
|
|
202
|
+
}
|
|
203
|
+
digits = norm;
|
|
204
|
+
if (digits.length <= precision) {
|
|
205
|
+
return { digits, base10exp };
|
|
206
|
+
}
|
|
207
|
+
const cut = digits.slice(0, precision).split("");
|
|
208
|
+
const next = digits.charCodeAt(precision) - 48;
|
|
209
|
+
if (next >= 5) {
|
|
210
|
+
let i = cut.length - 1;
|
|
211
|
+
while (i >= 0) {
|
|
212
|
+
const cur = cut[i];
|
|
213
|
+
if (cur === void 0) {
|
|
214
|
+
throw new Error("roundToSignificantDigitsHalfUp: invalid state");
|
|
215
|
+
}
|
|
216
|
+
const d = cur.charCodeAt(0) - 48;
|
|
217
|
+
if (d !== 9) {
|
|
218
|
+
cut[i] = String.fromCharCode(48 + d + 1);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
cut[i] = "0";
|
|
222
|
+
i -= 1;
|
|
223
|
+
}
|
|
224
|
+
if (i < 0) {
|
|
225
|
+
cut.unshift("1");
|
|
226
|
+
base10exp += 1;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let rounded = cut.join("");
|
|
230
|
+
let tz = 0;
|
|
231
|
+
for (let i = rounded.length - 1; i >= 0 && rounded[i] === "0"; i -= 1) {
|
|
232
|
+
tz += 1;
|
|
233
|
+
}
|
|
234
|
+
if (tz > 0) {
|
|
235
|
+
rounded = rounded.slice(0, -tz);
|
|
236
|
+
}
|
|
237
|
+
if (rounded === "") {
|
|
238
|
+
return { digits: "0", base10exp: 0 };
|
|
239
|
+
}
|
|
240
|
+
return { digits: rounded, base10exp };
|
|
241
|
+
}
|
|
242
|
+
function toSignificant(num, decimals, precision = 6) {
|
|
243
|
+
if (num === 1n) return "0";
|
|
244
|
+
if (num === 0n) return "0";
|
|
245
|
+
const negative = num < 0n;
|
|
246
|
+
const abs = negative ? -num : num;
|
|
247
|
+
const rawDigits = abs.toString();
|
|
248
|
+
const base10exp = rawDigits.length - decimals - 1;
|
|
249
|
+
const rounded = roundToSignificantDigitsHalfUp(
|
|
250
|
+
rawDigits,
|
|
251
|
+
base10exp,
|
|
252
|
+
precision
|
|
253
|
+
);
|
|
254
|
+
const body = formatDecimalJsLikeToString(rounded.digits, rounded.base10exp);
|
|
255
|
+
return negative ? `-${body}` : body;
|
|
256
|
+
}
|
|
178
257
|
// Annotate the CommonJS export names for ESM import in node:
|
|
179
258
|
0 && (module.exports = {
|
|
180
259
|
fmtBinaryMask,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { formatAbiItem } from "abitype";
|
|
2
1
|
import {
|
|
3
2
|
getCreate2Address,
|
|
4
3
|
stringToHex
|
|
5
4
|
} from "viem";
|
|
5
|
+
import { formatAbiItem } from "viem/utils";
|
|
6
6
|
const PUBLIC_CREATE2_FACTORY = "0x4e59b44847b379578588920ca78fbf26c0b4956c";
|
|
7
7
|
function handleSalt(salt) {
|
|
8
8
|
if (salt.slice(0, 2) !== "0x" || salt.length !== 66) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import BN from "bn.js";
|
|
2
1
|
import { Buffer } from "buffer";
|
|
3
2
|
const ACCUMULATOR_MAGIC = "504e4155";
|
|
4
3
|
const MAJOR_VERSION = 1;
|
|
@@ -6,6 +5,14 @@ const MINOR_VERSION = 0;
|
|
|
6
5
|
const KECCAK160_HASH_SIZE = 20;
|
|
7
6
|
const PRICE_FEED_MESSAGE_VARIANT = 0;
|
|
8
7
|
const TWAP_MESSAGE_VARIANT = 1;
|
|
8
|
+
function bufToBigInt(buf) {
|
|
9
|
+
if (buf.length === 0) return 0n;
|
|
10
|
+
let result = 0n;
|
|
11
|
+
for (let i = 0; i < buf.length; i++) {
|
|
12
|
+
result = result << 8n | BigInt(buf[i]);
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
9
16
|
function isAccumulatorUpdateData(updateBytes) {
|
|
10
17
|
return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
|
|
11
18
|
}
|
|
@@ -18,19 +25,19 @@ function parsePriceFeedMessage(message) {
|
|
|
18
25
|
cursor += 1;
|
|
19
26
|
const feedId = message.subarray(cursor, cursor + 32);
|
|
20
27
|
cursor += 32;
|
|
21
|
-
const price =
|
|
28
|
+
const price = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
22
29
|
cursor += 8;
|
|
23
|
-
const confidence =
|
|
30
|
+
const confidence = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
24
31
|
cursor += 8;
|
|
25
32
|
const exponent = message.readInt32BE(cursor);
|
|
26
33
|
cursor += 4;
|
|
27
|
-
const publishTime =
|
|
34
|
+
const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
28
35
|
cursor += 8;
|
|
29
|
-
const prevPublishTime =
|
|
36
|
+
const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
30
37
|
cursor += 8;
|
|
31
|
-
const emaPrice =
|
|
38
|
+
const emaPrice = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
32
39
|
cursor += 8;
|
|
33
|
-
const emaConf =
|
|
40
|
+
const emaConf = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
34
41
|
cursor += 8;
|
|
35
42
|
return {
|
|
36
43
|
feedId,
|
|
@@ -52,19 +59,19 @@ function parseTwapMessage(message) {
|
|
|
52
59
|
cursor += 1;
|
|
53
60
|
const feedId = message.subarray(cursor, cursor + 32);
|
|
54
61
|
cursor += 32;
|
|
55
|
-
const cumulativePrice =
|
|
62
|
+
const cumulativePrice = bufToBigInt(message.subarray(cursor, cursor + 16));
|
|
56
63
|
cursor += 16;
|
|
57
|
-
const cumulativeConf =
|
|
64
|
+
const cumulativeConf = bufToBigInt(message.subarray(cursor, cursor + 16));
|
|
58
65
|
cursor += 16;
|
|
59
|
-
const numDownSlots =
|
|
66
|
+
const numDownSlots = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
60
67
|
cursor += 8;
|
|
61
68
|
const exponent = message.readInt32BE(cursor);
|
|
62
69
|
cursor += 4;
|
|
63
|
-
const publishTime =
|
|
70
|
+
const publishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
64
71
|
cursor += 8;
|
|
65
|
-
const prevPublishTime =
|
|
72
|
+
const prevPublishTime = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
66
73
|
cursor += 8;
|
|
67
|
-
const publishSlot =
|
|
74
|
+
const publishSlot = bufToBigInt(message.subarray(cursor, cursor + 8));
|
|
68
75
|
cursor += 8;
|
|
69
76
|
return {
|
|
70
77
|
feedId,
|
|
@@ -104,7 +104,7 @@ function splitAccumulatorUpdates(binary) {
|
|
|
104
104
|
const msg = parsePriceFeedMessage(upd);
|
|
105
105
|
results.push({
|
|
106
106
|
dataFeedId: toHex(msg.feedId),
|
|
107
|
-
timestamp: msg.publishTime
|
|
107
|
+
timestamp: Number(msg.publishTime),
|
|
108
108
|
data: toHex(sliceAccumulatorUpdateData(data, i, i + 1))
|
|
109
109
|
});
|
|
110
110
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { formatDuration as fmtDuration, intervalToDuration } from "date-fns";
|
|
2
|
-
import Decimal from "decimal.js-light";
|
|
3
2
|
import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR } from "../constants/index.js";
|
|
4
3
|
const toBigInt = (v) => {
|
|
5
4
|
const value = typeof v === "object" && v.type === "BigNumber" ? v.hex : v.toString();
|
|
@@ -103,17 +102,22 @@ function formatTimestamp(timestamp, raw = true) {
|
|
|
103
102
|
function rayToNumber(num) {
|
|
104
103
|
return Number(toBigInt(num) / 10n ** 21n) / 1e6;
|
|
105
104
|
}
|
|
106
|
-
function toSignificant(num, decimals, precision = 6) {
|
|
107
|
-
if (num === 1n) return "0";
|
|
108
|
-
const divider = new Decimal(10).toPower(decimals);
|
|
109
|
-
const number = new Decimal(num.toString()).div(divider);
|
|
110
|
-
return number.toSignificantDigits(precision, 4).toString();
|
|
111
|
-
}
|
|
112
105
|
function toBN(num, decimals) {
|
|
113
106
|
if (num === "") return 0n;
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
|
|
107
|
+
const negative = num.startsWith("-");
|
|
108
|
+
const abs = negative ? num.slice(1) : num;
|
|
109
|
+
const [intPart = "0", fracPart = ""] = abs.split(".");
|
|
110
|
+
let frac = fracPart;
|
|
111
|
+
let roundUp = false;
|
|
112
|
+
if (frac.length > decimals) {
|
|
113
|
+
roundUp = frac.charCodeAt(decimals) >= 53;
|
|
114
|
+
frac = frac.slice(0, decimals);
|
|
115
|
+
} else {
|
|
116
|
+
frac = frac.padEnd(decimals, "0");
|
|
117
|
+
}
|
|
118
|
+
let result = BigInt(intPart + frac);
|
|
119
|
+
if (roundUp) result += 1n;
|
|
120
|
+
return negative ? -result : result;
|
|
117
121
|
}
|
|
118
122
|
function shortAddress(address) {
|
|
119
123
|
return address === void 0 ? "" : `${address.slice(0, 6)}...${address.slice(address.length - 4)}`;
|
|
@@ -127,6 +131,91 @@ function formatPercentage(healthFactor, decimals = 2) {
|
|
|
127
131
|
function formatLeverage(leverage, decimals = 2) {
|
|
128
132
|
return (leverage / Number(LEVERAGE_DECIMALS)).toFixed(decimals);
|
|
129
133
|
}
|
|
134
|
+
function formatDecimalJsLikeToString(digits, base10exp) {
|
|
135
|
+
const len = digits.length;
|
|
136
|
+
const isExp = base10exp <= -7 || base10exp >= 21;
|
|
137
|
+
if (isExp) {
|
|
138
|
+
let coeff = digits;
|
|
139
|
+
if (len > 1) {
|
|
140
|
+
coeff = `${digits[0]}.${digits.slice(1)}`;
|
|
141
|
+
}
|
|
142
|
+
const exp = base10exp;
|
|
143
|
+
const expStr = exp < 0 ? `e${exp}` : `e+${exp}`;
|
|
144
|
+
return `${coeff}${expStr}`;
|
|
145
|
+
}
|
|
146
|
+
if (base10exp < 0) {
|
|
147
|
+
return `0.${"0".repeat(-base10exp - 1)}${digits}`;
|
|
148
|
+
}
|
|
149
|
+
if (base10exp >= len) {
|
|
150
|
+
return `${digits}${"0".repeat(base10exp + 1 - len)}`;
|
|
151
|
+
}
|
|
152
|
+
const k = base10exp + 1;
|
|
153
|
+
if (k === len) return digits;
|
|
154
|
+
return `${digits.slice(0, k)}.${digits.slice(k)}`;
|
|
155
|
+
}
|
|
156
|
+
function roundToSignificantDigitsHalfUp(digits, base10exp, precision) {
|
|
157
|
+
if (precision < 1) {
|
|
158
|
+
throw new Error(`Invalid precision: ${precision}`);
|
|
159
|
+
}
|
|
160
|
+
if (digits === "0") return { digits: "0", base10exp: 0 };
|
|
161
|
+
let norm = digits;
|
|
162
|
+
while (norm.length > 1 && norm.endsWith("0")) {
|
|
163
|
+
norm = norm.slice(0, -1);
|
|
164
|
+
}
|
|
165
|
+
digits = norm;
|
|
166
|
+
if (digits.length <= precision) {
|
|
167
|
+
return { digits, base10exp };
|
|
168
|
+
}
|
|
169
|
+
const cut = digits.slice(0, precision).split("");
|
|
170
|
+
const next = digits.charCodeAt(precision) - 48;
|
|
171
|
+
if (next >= 5) {
|
|
172
|
+
let i = cut.length - 1;
|
|
173
|
+
while (i >= 0) {
|
|
174
|
+
const cur = cut[i];
|
|
175
|
+
if (cur === void 0) {
|
|
176
|
+
throw new Error("roundToSignificantDigitsHalfUp: invalid state");
|
|
177
|
+
}
|
|
178
|
+
const d = cur.charCodeAt(0) - 48;
|
|
179
|
+
if (d !== 9) {
|
|
180
|
+
cut[i] = String.fromCharCode(48 + d + 1);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
cut[i] = "0";
|
|
184
|
+
i -= 1;
|
|
185
|
+
}
|
|
186
|
+
if (i < 0) {
|
|
187
|
+
cut.unshift("1");
|
|
188
|
+
base10exp += 1;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
let rounded = cut.join("");
|
|
192
|
+
let tz = 0;
|
|
193
|
+
for (let i = rounded.length - 1; i >= 0 && rounded[i] === "0"; i -= 1) {
|
|
194
|
+
tz += 1;
|
|
195
|
+
}
|
|
196
|
+
if (tz > 0) {
|
|
197
|
+
rounded = rounded.slice(0, -tz);
|
|
198
|
+
}
|
|
199
|
+
if (rounded === "") {
|
|
200
|
+
return { digits: "0", base10exp: 0 };
|
|
201
|
+
}
|
|
202
|
+
return { digits: rounded, base10exp };
|
|
203
|
+
}
|
|
204
|
+
function toSignificant(num, decimals, precision = 6) {
|
|
205
|
+
if (num === 1n) return "0";
|
|
206
|
+
if (num === 0n) return "0";
|
|
207
|
+
const negative = num < 0n;
|
|
208
|
+
const abs = negative ? -num : num;
|
|
209
|
+
const rawDigits = abs.toString();
|
|
210
|
+
const base10exp = rawDigits.length - decimals - 1;
|
|
211
|
+
const rounded = roundToSignificantDigitsHalfUp(
|
|
212
|
+
rawDigits,
|
|
213
|
+
base10exp,
|
|
214
|
+
precision
|
|
215
|
+
);
|
|
216
|
+
const body = formatDecimalJsLikeToString(rounded.digits, rounded.base10exp);
|
|
217
|
+
return negative ? `-${body}` : body;
|
|
218
|
+
}
|
|
130
219
|
export {
|
|
131
220
|
fmtBinaryMask,
|
|
132
221
|
formatBN,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Abi } from "
|
|
2
|
-
import type { Account, Address, Chain, Client, ContractConstructorArgs, GetChainParameter, Hash, Hex, SendTransactionParameters, SendTransactionReturnType, Transport, UnionEvaluate, UnionOmit, WalletClient } from "viem";
|
|
1
|
+
import type { Abi, Account, Address, Chain, Client, ContractConstructorArgs, GetChainParameter, Hash, Hex, SendTransactionParameters, SendTransactionReturnType, Transport, UnionEvaluate, UnionOmit, WalletClient } from "viem";
|
|
3
2
|
import type { OnchainSDK } from "../sdk/index.js";
|
|
4
3
|
import { Construct } from "../sdk/index.js";
|
|
5
4
|
export declare const PUBLIC_CREATE2_FACTORY: Address;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Abi } from "
|
|
1
|
+
import type { Abi } from "viem";
|
|
2
2
|
import { type ContractFunctionArgs, type ContractFunctionName, type ContractFunctionParameters, type ReadContractReturnType } from "viem";
|
|
3
3
|
import type { AnvilClient } from "./createAnvilClient.js";
|
|
4
4
|
export type ReplaceStorageParams<abi extends Abi | readonly unknown[] = Abi, functionName extends ContractFunctionName<abi, "pure" | "view"> = ContractFunctionName<abi, "pure" | "view">, args extends ContractFunctionArgs<abi, "pure" | "view", functionName> = ContractFunctionArgs<abi, "pure" | "view", functionName>> = ContractFunctionParameters<abi, "pure" | "view", functionName, args, false> & {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Address } from "
|
|
1
|
+
import type { Address } from "viem";
|
|
2
2
|
import type { CreditManagerState, IBaseContract } from "../../base/index.js";
|
|
3
3
|
import type { CreditConfiguratorStateHuman, CreditManagerStateHuman } from "../../types/index.js";
|
|
4
4
|
import type { AddressMap } from "../../utils/index.js";
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* This is https://github.com/pyth-network/pyth-crosschain/blob/main/price_service/sdk/js/src/AccumulatorUpdateData.ts
|
|
3
3
|
* modified to use buffer from npm package
|
|
4
4
|
*/
|
|
5
|
-
import BN from "bn.js";
|
|
6
5
|
import { Buffer } from "buffer";
|
|
7
6
|
export type AccumulatorUpdateData = {
|
|
8
7
|
vaa: Buffer;
|
|
@@ -13,23 +12,23 @@ export type AccumulatorUpdateData = {
|
|
|
13
12
|
};
|
|
14
13
|
export type PriceFeedMessage = {
|
|
15
14
|
feedId: Buffer;
|
|
16
|
-
price:
|
|
17
|
-
confidence:
|
|
15
|
+
price: bigint;
|
|
16
|
+
confidence: bigint;
|
|
18
17
|
exponent: number;
|
|
19
|
-
publishTime:
|
|
20
|
-
prevPublishTime:
|
|
21
|
-
emaPrice:
|
|
22
|
-
emaConf:
|
|
18
|
+
publishTime: bigint;
|
|
19
|
+
prevPublishTime: bigint;
|
|
20
|
+
emaPrice: bigint;
|
|
21
|
+
emaConf: bigint;
|
|
23
22
|
};
|
|
24
23
|
export type TwapMessage = {
|
|
25
24
|
feedId: Buffer;
|
|
26
|
-
cumulativePrice:
|
|
27
|
-
cumulativeConf:
|
|
28
|
-
numDownSlots:
|
|
25
|
+
cumulativePrice: bigint;
|
|
26
|
+
cumulativeConf: bigint;
|
|
27
|
+
numDownSlots: bigint;
|
|
29
28
|
exponent: number;
|
|
30
|
-
publishTime:
|
|
31
|
-
prevPublishTime:
|
|
32
|
-
publishSlot:
|
|
29
|
+
publishTime: bigint;
|
|
30
|
+
prevPublishTime: bigint;
|
|
31
|
+
publishSlot: bigint;
|
|
33
32
|
};
|
|
34
33
|
export declare function isAccumulatorUpdateData(updateBytes: Buffer): boolean;
|
|
35
34
|
export declare function parsePriceFeedMessage(message: Buffer): PriceFeedMessage;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Abi } from "
|
|
2
|
-
import type { Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
|
1
|
+
import type { Abi, Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
|
3
2
|
import type { ZapperData } from "../market/index.js";
|
|
4
3
|
import type { Asset } from "../router/index.js";
|
|
5
4
|
interface PermitResult {
|
|
@@ -12,10 +12,10 @@ export declare function formatNumberToString_(value: bigint | number): string;
|
|
|
12
12
|
export declare function formatTimestamp(timestamp: number, raw?: boolean): string;
|
|
13
13
|
type BigNumberish = bigint | number | string;
|
|
14
14
|
export declare function rayToNumber(num: BigNumberish): number;
|
|
15
|
-
export declare function toSignificant(num: bigint, decimals: number, precision?: number): string;
|
|
16
15
|
export declare function toBN(num: string, decimals: number): bigint;
|
|
17
16
|
export declare function shortAddress(address?: string): string;
|
|
18
17
|
export declare function shortHash(address?: string): string;
|
|
19
18
|
export declare function formatPercentage(healthFactor: number, decimals?: number): string;
|
|
20
19
|
export declare function formatLeverage(leverage: number, decimals?: number): string;
|
|
20
|
+
export declare function toSignificant(num: bigint, decimals: number, precision?: number): string;
|
|
21
21
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { AbiEvent } from "
|
|
2
|
-
import type { BlockNumber, Chain, Client, GetLogsParameters, GetLogsReturnType, MaybeAbiEventName, Transport } from "viem";
|
|
1
|
+
import type { AbiEvent, BlockNumber, Chain, Client, GetLogsParameters, GetLogsReturnType, MaybeAbiEventName, Transport } from "viem";
|
|
3
2
|
export type GetLogsPaginatedParameters<abiEvent extends AbiEvent | undefined = undefined, abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined, _eventName extends string | undefined = MaybeAbiEventName<abiEvent>> = GetLogsParameters<abiEvent, abiEvents, strict, BlockNumber, BlockNumber, _eventName> & {
|
|
4
3
|
pageSize: bigint;
|
|
5
4
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AbiEvent } from "
|
|
1
|
+
import type { AbiEvent } from "viem";
|
|
2
2
|
import { type BlockNumber, type Chain, type Client, type GetLogsParameters, type GetLogsReturnType, type Transport } from "viem";
|
|
3
3
|
export declare function getLogsSafe<chain extends Chain | undefined, const abiEvent extends AbiEvent | undefined = undefined, const abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined>(client: Client<Transport, chain>, params?: GetLogsParameters<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>): Promise<GetLogsReturnType<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Narrow } from "
|
|
2
|
-
import type { CallParameters, Chain, Client, ContractFunctionParameters, MulticallContracts, MulticallReturnType, Transport } from "viem";
|
|
1
|
+
import type { CallParameters, Chain, Client, ContractFunctionParameters, MulticallContracts, MulticallReturnType, Narrow, Transport } from "viem";
|
|
3
2
|
import { BaseError } from "viem";
|
|
4
3
|
import type { IPriceUpdateTx } from "../../types/index.js";
|
|
5
4
|
import type { SimulateMulticallParameters } from "./simulateMulticall.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "14.0.0-next.
|
|
3
|
+
"version": "14.0.0-next.7",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -79,21 +79,17 @@
|
|
|
79
79
|
"@redstone-finance/protocol": "^0.9.0",
|
|
80
80
|
"@redstone-finance/sdk": "^0.9.0",
|
|
81
81
|
"@redstone-finance/utils": "^0.9.0",
|
|
82
|
-
"@types/bn.js": "^5.2.0",
|
|
83
82
|
"abitype": "^1.2.3",
|
|
84
|
-
"bn.js": "^5.2.3",
|
|
85
83
|
"buffer": "^6.0.3",
|
|
86
84
|
"date-fns": "^4.1.0",
|
|
87
|
-
"decimal.js-light": "^2.5.1",
|
|
88
85
|
"viem": ">=2.23.15 <3.0.0",
|
|
89
|
-
"yaml": "^2.8.3",
|
|
90
86
|
"zod": "^4.3.6"
|
|
91
87
|
},
|
|
92
88
|
"devDependencies": {
|
|
93
|
-
"@biomejs/biome": "^2.4.
|
|
89
|
+
"@biomejs/biome": "^2.4.12",
|
|
94
90
|
"@commitlint/cli": "^20.5.0",
|
|
95
91
|
"@commitlint/config-conventional": "^20.5.0",
|
|
96
|
-
"@gearbox-protocol/biome-config": "^1.0.
|
|
92
|
+
"@gearbox-protocol/biome-config": "^1.0.27",
|
|
97
93
|
"@types/cross-spawn": "^6.0.6",
|
|
98
94
|
"axios": "^1.15.0",
|
|
99
95
|
"cross-spawn": "^7.0.6",
|
|
@@ -106,7 +102,8 @@
|
|
|
106
102
|
"typescript": "^6.0.2",
|
|
107
103
|
"viem-deal": "^2.0.4",
|
|
108
104
|
"vite": "^8.0.8",
|
|
109
|
-
"vitest": "^4.1.4"
|
|
105
|
+
"vitest": "^4.1.4",
|
|
106
|
+
"yaml": "^2.8.3"
|
|
110
107
|
},
|
|
111
108
|
"peerDependencies": {
|
|
112
109
|
"axios": "^1.0.0",
|