@gearbox-protocol/sdk 8.3.0-next.2 → 8.3.0
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/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +195 -0
- package/dist/cjs/sdk/market/pricefeeds/updates/PythUpdater.js +6 -5
- package/dist/esm/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.js +157 -0
- package/dist/esm/sdk/market/pricefeeds/updates/PythUpdater.js +6 -5
- package/dist/types/sdk/market/pricefeeds/updates/PythAccumulatorUpdateData.d.ts +41 -0
- package/package.json +9 -12
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var PythAccumulatorUpdateData_exports = {};
|
|
30
|
+
__export(PythAccumulatorUpdateData_exports, {
|
|
31
|
+
isAccumulatorUpdateData: () => isAccumulatorUpdateData,
|
|
32
|
+
parseAccumulatorUpdateData: () => parseAccumulatorUpdateData,
|
|
33
|
+
parsePriceFeedMessage: () => parsePriceFeedMessage,
|
|
34
|
+
parseTwapMessage: () => parseTwapMessage,
|
|
35
|
+
sliceAccumulatorUpdateData: () => sliceAccumulatorUpdateData
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(PythAccumulatorUpdateData_exports);
|
|
38
|
+
var import_bn = __toESM(require("bn.js"));
|
|
39
|
+
var import_buffer = require("buffer");
|
|
40
|
+
const ACCUMULATOR_MAGIC = "504e4155";
|
|
41
|
+
const MAJOR_VERSION = 1;
|
|
42
|
+
const MINOR_VERSION = 0;
|
|
43
|
+
const KECCAK160_HASH_SIZE = 20;
|
|
44
|
+
const PRICE_FEED_MESSAGE_VARIANT = 0;
|
|
45
|
+
const TWAP_MESSAGE_VARIANT = 1;
|
|
46
|
+
function isAccumulatorUpdateData(updateBytes) {
|
|
47
|
+
return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
|
|
48
|
+
}
|
|
49
|
+
function parsePriceFeedMessage(message) {
|
|
50
|
+
let cursor = 0;
|
|
51
|
+
const variant = message.readUInt8(cursor);
|
|
52
|
+
if (variant !== PRICE_FEED_MESSAGE_VARIANT) {
|
|
53
|
+
throw new Error("Not a price feed message");
|
|
54
|
+
}
|
|
55
|
+
cursor += 1;
|
|
56
|
+
const feedId = message.subarray(cursor, cursor + 32);
|
|
57
|
+
cursor += 32;
|
|
58
|
+
const price = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
59
|
+
cursor += 8;
|
|
60
|
+
const confidence = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
61
|
+
cursor += 8;
|
|
62
|
+
const exponent = message.readInt32BE(cursor);
|
|
63
|
+
cursor += 4;
|
|
64
|
+
const publishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
65
|
+
cursor += 8;
|
|
66
|
+
const prevPublishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
67
|
+
cursor += 8;
|
|
68
|
+
const emaPrice = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
69
|
+
cursor += 8;
|
|
70
|
+
const emaConf = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
71
|
+
cursor += 8;
|
|
72
|
+
return {
|
|
73
|
+
feedId,
|
|
74
|
+
price,
|
|
75
|
+
confidence,
|
|
76
|
+
exponent,
|
|
77
|
+
publishTime,
|
|
78
|
+
prevPublishTime,
|
|
79
|
+
emaPrice,
|
|
80
|
+
emaConf
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function parseTwapMessage(message) {
|
|
84
|
+
let cursor = 0;
|
|
85
|
+
const variant = message.readUInt8(cursor);
|
|
86
|
+
if (variant !== TWAP_MESSAGE_VARIANT) {
|
|
87
|
+
throw new Error("Not a twap message");
|
|
88
|
+
}
|
|
89
|
+
cursor += 1;
|
|
90
|
+
const feedId = message.subarray(cursor, cursor + 32);
|
|
91
|
+
cursor += 32;
|
|
92
|
+
const cumulativePrice = new import_bn.default(message.subarray(cursor, cursor + 16), "be");
|
|
93
|
+
cursor += 16;
|
|
94
|
+
const cumulativeConf = new import_bn.default(message.subarray(cursor, cursor + 16), "be");
|
|
95
|
+
cursor += 16;
|
|
96
|
+
const numDownSlots = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
97
|
+
cursor += 8;
|
|
98
|
+
const exponent = message.readInt32BE(cursor);
|
|
99
|
+
cursor += 4;
|
|
100
|
+
const publishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
101
|
+
cursor += 8;
|
|
102
|
+
const prevPublishTime = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
103
|
+
cursor += 8;
|
|
104
|
+
const publishSlot = new import_bn.default(message.subarray(cursor, cursor + 8), "be");
|
|
105
|
+
cursor += 8;
|
|
106
|
+
return {
|
|
107
|
+
feedId,
|
|
108
|
+
cumulativePrice,
|
|
109
|
+
cumulativeConf,
|
|
110
|
+
numDownSlots,
|
|
111
|
+
exponent,
|
|
112
|
+
publishTime,
|
|
113
|
+
prevPublishTime,
|
|
114
|
+
publishSlot
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function sliceAccumulatorUpdateData(data, start, end) {
|
|
118
|
+
if (!isAccumulatorUpdateData(data)) {
|
|
119
|
+
throw new Error("Invalid accumulator message");
|
|
120
|
+
}
|
|
121
|
+
let cursor = 6;
|
|
122
|
+
const trailingPayloadSize = data.readUint8(cursor);
|
|
123
|
+
cursor += 1 + trailingPayloadSize;
|
|
124
|
+
cursor += 1;
|
|
125
|
+
const vaaSize = data.readUint16BE(cursor);
|
|
126
|
+
cursor += 2;
|
|
127
|
+
cursor += vaaSize;
|
|
128
|
+
const endOfVaa = cursor;
|
|
129
|
+
const updates = [];
|
|
130
|
+
const numUpdates = data.readUInt8(cursor);
|
|
131
|
+
cursor += 1;
|
|
132
|
+
for (let i = 0; i < numUpdates; i++) {
|
|
133
|
+
const updateStart = cursor;
|
|
134
|
+
const messageSize = data.readUint16BE(cursor);
|
|
135
|
+
cursor += 2;
|
|
136
|
+
cursor += messageSize;
|
|
137
|
+
const numProofs = data.readUInt8(cursor);
|
|
138
|
+
cursor += 1;
|
|
139
|
+
cursor += KECCAK160_HASH_SIZE * numProofs;
|
|
140
|
+
updates.push(data.subarray(updateStart, cursor));
|
|
141
|
+
}
|
|
142
|
+
if (cursor !== data.length) {
|
|
143
|
+
throw new Error("Didn't reach the end of the message");
|
|
144
|
+
}
|
|
145
|
+
const sliceUpdates = updates.slice(start, end);
|
|
146
|
+
return import_buffer.Buffer.concat([
|
|
147
|
+
data.subarray(0, endOfVaa),
|
|
148
|
+
import_buffer.Buffer.from([sliceUpdates.length]),
|
|
149
|
+
...updates.slice(start, end)
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
function parseAccumulatorUpdateData(data) {
|
|
153
|
+
if (!isAccumulatorUpdateData(data)) {
|
|
154
|
+
throw new Error("Invalid accumulator message");
|
|
155
|
+
}
|
|
156
|
+
let cursor = 6;
|
|
157
|
+
const trailingPayloadSize = data.readUint8(cursor);
|
|
158
|
+
cursor += 1 + trailingPayloadSize;
|
|
159
|
+
cursor += 1;
|
|
160
|
+
const vaaSize = data.readUint16BE(cursor);
|
|
161
|
+
cursor += 2;
|
|
162
|
+
const vaa = data.subarray(cursor, cursor + vaaSize);
|
|
163
|
+
cursor += vaaSize;
|
|
164
|
+
const numUpdates = data.readUInt8(cursor);
|
|
165
|
+
const updates = [];
|
|
166
|
+
cursor += 1;
|
|
167
|
+
for (let i = 0; i < numUpdates; i++) {
|
|
168
|
+
const messageSize = data.readUint16BE(cursor);
|
|
169
|
+
cursor += 2;
|
|
170
|
+
const message = data.subarray(cursor, cursor + messageSize);
|
|
171
|
+
cursor += messageSize;
|
|
172
|
+
const numProofs = data.readUInt8(cursor);
|
|
173
|
+
cursor += 1;
|
|
174
|
+
const proof = [];
|
|
175
|
+
for (let j = 0; j < numProofs; j++) {
|
|
176
|
+
proof.push(
|
|
177
|
+
Array.from(data.subarray(cursor, cursor + KECCAK160_HASH_SIZE))
|
|
178
|
+
);
|
|
179
|
+
cursor += KECCAK160_HASH_SIZE;
|
|
180
|
+
}
|
|
181
|
+
updates.push({ message, proof });
|
|
182
|
+
}
|
|
183
|
+
if (cursor !== data.length) {
|
|
184
|
+
throw new Error("Didn't reach the end of the message");
|
|
185
|
+
}
|
|
186
|
+
return { vaa, updates };
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
isAccumulatorUpdateData,
|
|
191
|
+
parseAccumulatorUpdateData,
|
|
192
|
+
parsePriceFeedMessage,
|
|
193
|
+
parseTwapMessage,
|
|
194
|
+
sliceAccumulatorUpdateData
|
|
195
|
+
});
|
|
@@ -21,12 +21,13 @@ __export(PythUpdater_exports, {
|
|
|
21
21
|
PythUpdater: () => PythUpdater
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(PythUpdater_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_buffer = require("buffer");
|
|
25
25
|
var import_viem = require("viem");
|
|
26
26
|
var import_base = require("../../../base/index.js");
|
|
27
27
|
var import_utils = require("../../../utils/index.js");
|
|
28
28
|
var import_PriceUpdatesCache = require("./PriceUpdatesCache.js");
|
|
29
29
|
var import_PriceUpdateTx = require("./PriceUpdateTx.js");
|
|
30
|
+
var import_PythAccumulatorUpdateData = require("./PythAccumulatorUpdateData.js");
|
|
30
31
|
class PythUpdateTx extends import_PriceUpdateTx.PriceUpdateTx {
|
|
31
32
|
name = "pyth";
|
|
32
33
|
}
|
|
@@ -169,16 +170,16 @@ function respToCalldata(resp) {
|
|
|
169
170
|
});
|
|
170
171
|
}
|
|
171
172
|
function splitAccumulatorUpdates(binary) {
|
|
172
|
-
const data = Buffer.from(binary, "hex");
|
|
173
|
-
const parsed = (0,
|
|
173
|
+
const data = import_buffer.Buffer.from(binary, "hex");
|
|
174
|
+
const parsed = (0, import_PythAccumulatorUpdateData.parseAccumulatorUpdateData)(data);
|
|
174
175
|
const results = [];
|
|
175
176
|
for (let i = 0; i < parsed.updates.length; i++) {
|
|
176
177
|
const upd = parsed.updates[i].message;
|
|
177
|
-
const msg = (0,
|
|
178
|
+
const msg = (0, import_PythAccumulatorUpdateData.parsePriceFeedMessage)(upd);
|
|
178
179
|
results.push({
|
|
179
180
|
dataFeedId: (0, import_viem.toHex)(msg.feedId),
|
|
180
181
|
timestamp: msg.publishTime.toNumber(),
|
|
181
|
-
data: (0, import_viem.toHex)((0,
|
|
182
|
+
data: (0, import_viem.toHex)((0, import_PythAccumulatorUpdateData.sliceAccumulatorUpdateData)(data, i, i + 1))
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
185
|
return results;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import { Buffer } from "buffer";
|
|
3
|
+
const ACCUMULATOR_MAGIC = "504e4155";
|
|
4
|
+
const MAJOR_VERSION = 1;
|
|
5
|
+
const MINOR_VERSION = 0;
|
|
6
|
+
const KECCAK160_HASH_SIZE = 20;
|
|
7
|
+
const PRICE_FEED_MESSAGE_VARIANT = 0;
|
|
8
|
+
const TWAP_MESSAGE_VARIANT = 1;
|
|
9
|
+
function isAccumulatorUpdateData(updateBytes) {
|
|
10
|
+
return updateBytes.toString("hex").slice(0, 8) === ACCUMULATOR_MAGIC && updateBytes[4] === MAJOR_VERSION && updateBytes[5] === MINOR_VERSION;
|
|
11
|
+
}
|
|
12
|
+
function parsePriceFeedMessage(message) {
|
|
13
|
+
let cursor = 0;
|
|
14
|
+
const variant = message.readUInt8(cursor);
|
|
15
|
+
if (variant !== PRICE_FEED_MESSAGE_VARIANT) {
|
|
16
|
+
throw new Error("Not a price feed message");
|
|
17
|
+
}
|
|
18
|
+
cursor += 1;
|
|
19
|
+
const feedId = message.subarray(cursor, cursor + 32);
|
|
20
|
+
cursor += 32;
|
|
21
|
+
const price = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
22
|
+
cursor += 8;
|
|
23
|
+
const confidence = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
24
|
+
cursor += 8;
|
|
25
|
+
const exponent = message.readInt32BE(cursor);
|
|
26
|
+
cursor += 4;
|
|
27
|
+
const publishTime = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
28
|
+
cursor += 8;
|
|
29
|
+
const prevPublishTime = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
30
|
+
cursor += 8;
|
|
31
|
+
const emaPrice = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
32
|
+
cursor += 8;
|
|
33
|
+
const emaConf = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
34
|
+
cursor += 8;
|
|
35
|
+
return {
|
|
36
|
+
feedId,
|
|
37
|
+
price,
|
|
38
|
+
confidence,
|
|
39
|
+
exponent,
|
|
40
|
+
publishTime,
|
|
41
|
+
prevPublishTime,
|
|
42
|
+
emaPrice,
|
|
43
|
+
emaConf
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function parseTwapMessage(message) {
|
|
47
|
+
let cursor = 0;
|
|
48
|
+
const variant = message.readUInt8(cursor);
|
|
49
|
+
if (variant !== TWAP_MESSAGE_VARIANT) {
|
|
50
|
+
throw new Error("Not a twap message");
|
|
51
|
+
}
|
|
52
|
+
cursor += 1;
|
|
53
|
+
const feedId = message.subarray(cursor, cursor + 32);
|
|
54
|
+
cursor += 32;
|
|
55
|
+
const cumulativePrice = new BN(message.subarray(cursor, cursor + 16), "be");
|
|
56
|
+
cursor += 16;
|
|
57
|
+
const cumulativeConf = new BN(message.subarray(cursor, cursor + 16), "be");
|
|
58
|
+
cursor += 16;
|
|
59
|
+
const numDownSlots = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
60
|
+
cursor += 8;
|
|
61
|
+
const exponent = message.readInt32BE(cursor);
|
|
62
|
+
cursor += 4;
|
|
63
|
+
const publishTime = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
64
|
+
cursor += 8;
|
|
65
|
+
const prevPublishTime = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
66
|
+
cursor += 8;
|
|
67
|
+
const publishSlot = new BN(message.subarray(cursor, cursor + 8), "be");
|
|
68
|
+
cursor += 8;
|
|
69
|
+
return {
|
|
70
|
+
feedId,
|
|
71
|
+
cumulativePrice,
|
|
72
|
+
cumulativeConf,
|
|
73
|
+
numDownSlots,
|
|
74
|
+
exponent,
|
|
75
|
+
publishTime,
|
|
76
|
+
prevPublishTime,
|
|
77
|
+
publishSlot
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function sliceAccumulatorUpdateData(data, start, end) {
|
|
81
|
+
if (!isAccumulatorUpdateData(data)) {
|
|
82
|
+
throw new Error("Invalid accumulator message");
|
|
83
|
+
}
|
|
84
|
+
let cursor = 6;
|
|
85
|
+
const trailingPayloadSize = data.readUint8(cursor);
|
|
86
|
+
cursor += 1 + trailingPayloadSize;
|
|
87
|
+
cursor += 1;
|
|
88
|
+
const vaaSize = data.readUint16BE(cursor);
|
|
89
|
+
cursor += 2;
|
|
90
|
+
cursor += vaaSize;
|
|
91
|
+
const endOfVaa = cursor;
|
|
92
|
+
const updates = [];
|
|
93
|
+
const numUpdates = data.readUInt8(cursor);
|
|
94
|
+
cursor += 1;
|
|
95
|
+
for (let i = 0; i < numUpdates; i++) {
|
|
96
|
+
const updateStart = cursor;
|
|
97
|
+
const messageSize = data.readUint16BE(cursor);
|
|
98
|
+
cursor += 2;
|
|
99
|
+
cursor += messageSize;
|
|
100
|
+
const numProofs = data.readUInt8(cursor);
|
|
101
|
+
cursor += 1;
|
|
102
|
+
cursor += KECCAK160_HASH_SIZE * numProofs;
|
|
103
|
+
updates.push(data.subarray(updateStart, cursor));
|
|
104
|
+
}
|
|
105
|
+
if (cursor !== data.length) {
|
|
106
|
+
throw new Error("Didn't reach the end of the message");
|
|
107
|
+
}
|
|
108
|
+
const sliceUpdates = updates.slice(start, end);
|
|
109
|
+
return Buffer.concat([
|
|
110
|
+
data.subarray(0, endOfVaa),
|
|
111
|
+
Buffer.from([sliceUpdates.length]),
|
|
112
|
+
...updates.slice(start, end)
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
function parseAccumulatorUpdateData(data) {
|
|
116
|
+
if (!isAccumulatorUpdateData(data)) {
|
|
117
|
+
throw new Error("Invalid accumulator message");
|
|
118
|
+
}
|
|
119
|
+
let cursor = 6;
|
|
120
|
+
const trailingPayloadSize = data.readUint8(cursor);
|
|
121
|
+
cursor += 1 + trailingPayloadSize;
|
|
122
|
+
cursor += 1;
|
|
123
|
+
const vaaSize = data.readUint16BE(cursor);
|
|
124
|
+
cursor += 2;
|
|
125
|
+
const vaa = data.subarray(cursor, cursor + vaaSize);
|
|
126
|
+
cursor += vaaSize;
|
|
127
|
+
const numUpdates = data.readUInt8(cursor);
|
|
128
|
+
const updates = [];
|
|
129
|
+
cursor += 1;
|
|
130
|
+
for (let i = 0; i < numUpdates; i++) {
|
|
131
|
+
const messageSize = data.readUint16BE(cursor);
|
|
132
|
+
cursor += 2;
|
|
133
|
+
const message = data.subarray(cursor, cursor + messageSize);
|
|
134
|
+
cursor += messageSize;
|
|
135
|
+
const numProofs = data.readUInt8(cursor);
|
|
136
|
+
cursor += 1;
|
|
137
|
+
const proof = [];
|
|
138
|
+
for (let j = 0; j < numProofs; j++) {
|
|
139
|
+
proof.push(
|
|
140
|
+
Array.from(data.subarray(cursor, cursor + KECCAK160_HASH_SIZE))
|
|
141
|
+
);
|
|
142
|
+
cursor += KECCAK160_HASH_SIZE;
|
|
143
|
+
}
|
|
144
|
+
updates.push({ message, proof });
|
|
145
|
+
}
|
|
146
|
+
if (cursor !== data.length) {
|
|
147
|
+
throw new Error("Didn't reach the end of the message");
|
|
148
|
+
}
|
|
149
|
+
return { vaa, updates };
|
|
150
|
+
}
|
|
151
|
+
export {
|
|
152
|
+
isAccumulatorUpdateData,
|
|
153
|
+
parseAccumulatorUpdateData,
|
|
154
|
+
parsePriceFeedMessage,
|
|
155
|
+
parseTwapMessage,
|
|
156
|
+
sliceAccumulatorUpdateData
|
|
157
|
+
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseAccumulatorUpdateData,
|
|
3
|
-
parsePriceFeedMessage,
|
|
4
|
-
sliceAccumulatorUpdateData
|
|
5
|
-
} from "@pythnetwork/price-service-sdk";
|
|
1
|
+
import { Buffer } from "buffer";
|
|
6
2
|
import { encodeAbiParameters, toHex } from "viem";
|
|
7
3
|
import { SDKConstruct } from "../../../base/index.js";
|
|
8
4
|
import { childLogger, retry } from "../../../utils/index.js";
|
|
9
5
|
import { PriceUpdatesCache } from "./PriceUpdatesCache.js";
|
|
10
6
|
import { PriceUpdateTx } from "./PriceUpdateTx.js";
|
|
7
|
+
import {
|
|
8
|
+
parseAccumulatorUpdateData,
|
|
9
|
+
parsePriceFeedMessage,
|
|
10
|
+
sliceAccumulatorUpdateData
|
|
11
|
+
} from "./PythAccumulatorUpdateData.js";
|
|
11
12
|
class PythUpdateTx extends PriceUpdateTx {
|
|
12
13
|
name = "pyth";
|
|
13
14
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is https://github.com/pyth-network/pyth-crosschain/blob/main/price_service/sdk/js/src/AccumulatorUpdateData.ts
|
|
3
|
+
* modified to use buffer from npm package
|
|
4
|
+
*/
|
|
5
|
+
import BN from "bn.js";
|
|
6
|
+
import { Buffer } from "buffer";
|
|
7
|
+
export type AccumulatorUpdateData = {
|
|
8
|
+
vaa: Buffer;
|
|
9
|
+
updates: {
|
|
10
|
+
message: Buffer;
|
|
11
|
+
proof: number[][];
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export type PriceFeedMessage = {
|
|
15
|
+
feedId: Buffer;
|
|
16
|
+
price: BN;
|
|
17
|
+
confidence: BN;
|
|
18
|
+
exponent: number;
|
|
19
|
+
publishTime: BN;
|
|
20
|
+
prevPublishTime: BN;
|
|
21
|
+
emaPrice: BN;
|
|
22
|
+
emaConf: BN;
|
|
23
|
+
};
|
|
24
|
+
export type TwapMessage = {
|
|
25
|
+
feedId: Buffer;
|
|
26
|
+
cumulativePrice: BN;
|
|
27
|
+
cumulativeConf: BN;
|
|
28
|
+
numDownSlots: BN;
|
|
29
|
+
exponent: number;
|
|
30
|
+
publishTime: BN;
|
|
31
|
+
prevPublishTime: BN;
|
|
32
|
+
publishSlot: BN;
|
|
33
|
+
};
|
|
34
|
+
export declare function isAccumulatorUpdateData(updateBytes: Buffer): boolean;
|
|
35
|
+
export declare function parsePriceFeedMessage(message: Buffer): PriceFeedMessage;
|
|
36
|
+
export declare function parseTwapMessage(message: Buffer): TwapMessage;
|
|
37
|
+
/**
|
|
38
|
+
* An AccumulatorUpdateData contains a VAA and a list of updates. This function returns a new serialized AccumulatorUpdateData with only the updates in the range [start, end).
|
|
39
|
+
*/
|
|
40
|
+
export declare function sliceAccumulatorUpdateData(data: Buffer, start?: number, end?: number): Buffer;
|
|
41
|
+
export declare function parseAccumulatorUpdateData(data: Buffer): AccumulatorUpdateData;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "8.3.0
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -44,8 +44,6 @@
|
|
|
44
44
|
"build": "tsup",
|
|
45
45
|
"dev": "tsup --watch",
|
|
46
46
|
"example": "tsx --env-file .env scripts/example.ts | pino-pretty",
|
|
47
|
-
"mega": "tsx --env-file .env scripts/megaeth.ts | pino-pretty",
|
|
48
|
-
"accounts": "tsx --env-file .env scripts/accounts.ts | pino-pretty",
|
|
49
47
|
"test": "vitest",
|
|
50
48
|
"prepare": "husky",
|
|
51
49
|
"check": "biome check --write",
|
|
@@ -53,17 +51,16 @@
|
|
|
53
51
|
"typecheck:ci": "tsc --noEmit"
|
|
54
52
|
},
|
|
55
53
|
"dependencies": {
|
|
56
|
-
"@pythnetwork/price-service-sdk": "^1.8.0",
|
|
57
54
|
"@redstone-finance/evm-connector": "^0.7.5",
|
|
58
55
|
"@redstone-finance/protocol": "^0.7.5",
|
|
59
56
|
"@types/bn.js": "^5.2.0",
|
|
60
57
|
"abitype": "^1.0.8",
|
|
61
58
|
"bn.js": "^5.2.2",
|
|
59
|
+
"buffer": "^6.0.3",
|
|
62
60
|
"date-fns": "^4.1.0",
|
|
63
61
|
"decimal.js-light": "^2.5.1",
|
|
64
|
-
"keyv": "^5.3.3",
|
|
65
62
|
"viem": ">=2.23.15 <3.0.0",
|
|
66
|
-
"zod": "^3.
|
|
63
|
+
"zod": "^3.25.67"
|
|
67
64
|
},
|
|
68
65
|
"devDependencies": {
|
|
69
66
|
"@biomejs/biome": "^2.0.5",
|
|
@@ -71,16 +68,16 @@
|
|
|
71
68
|
"@commitlint/config-conventional": "^19.8.1",
|
|
72
69
|
"@gearbox-protocol/biome-config": "^1.0.0",
|
|
73
70
|
"@types/cross-spawn": "^6.0.6",
|
|
74
|
-
"axios": "^1.
|
|
71
|
+
"axios": "^1.10.0",
|
|
75
72
|
"cross-spawn": "^7.0.6",
|
|
76
73
|
"husky": "^9.1.7",
|
|
77
|
-
"lint-staged": "^16.
|
|
78
|
-
"pino": "^9.
|
|
74
|
+
"lint-staged": "^16.1.2",
|
|
75
|
+
"pino": "^9.7.0",
|
|
79
76
|
"pino-pretty": "^13.0.0",
|
|
80
|
-
"tsup": "^8.
|
|
81
|
-
"tsx": "^4.
|
|
77
|
+
"tsup": "^8.5.0",
|
|
78
|
+
"tsx": "^4.20.3",
|
|
82
79
|
"typescript": "^5.8.3",
|
|
83
|
-
"vitest": "^3.
|
|
80
|
+
"vitest": "^3.2.4"
|
|
84
81
|
},
|
|
85
82
|
"peerDependencies": {
|
|
86
83
|
"axios": "^1.0.0"
|