@reflectmoney/oracle.ts 2.2.2 → 3.1.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/index.d.ts CHANGED
@@ -9,6 +9,14 @@ export interface Oracle<T> {
9
9
  slot: bigint;
10
10
  payload: T;
11
11
  }
12
+ /**
13
+ * Price data payload with precision information
14
+ * Matches the Rust PriceData struct
15
+ */
16
+ export interface PriceData {
17
+ price: bigint;
18
+ precision: number;
19
+ }
12
20
  /**
13
21
  * Serializer interface for custom payload types
14
22
  */
@@ -30,10 +38,27 @@ export declare class U8Array8Serializer implements PayloadSerializer<Buffer> {
30
38
  * Helper function to create a [u8; 8] payload from a bigint price value
31
39
  */
32
40
  export declare function createPricePayload(price: bigint): Buffer;
41
+ /**
42
+ * Helper function to create a PriceData payload buffer from price and precision
43
+ */
44
+ export declare function createPriceDataPayload(price: bigint, precision: number): Buffer;
33
45
  /**
34
46
  * Helper function to read a price value from a [u8; 8] payload
35
47
  */
36
48
  export declare function readPriceFromPayload(payload: Buffer): bigint;
49
+ /**
50
+ * Helper function to read PriceData from a buffer payload
51
+ */
52
+ export declare function readPriceDataFromPayload(payload: Buffer): PriceData;
53
+ /**
54
+ * Built-in serializer for PriceData payloads
55
+ * Structure: 8 bytes for price, 1 byte for precision (total 9 bytes)
56
+ */
57
+ export declare class PriceDataSerializer implements PayloadSerializer<PriceData> {
58
+ serialize(payload: PriceData): Buffer;
59
+ deserialize(buffer: Buffer): PriceData;
60
+ size(): number;
61
+ }
37
62
  /**
38
63
  * Transaction builder for Doppler oracle updates
39
64
  */
package/dist/index.js CHANGED
@@ -9,9 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Doppler = exports.TransactionBuilder = exports.U8Array8Serializer = exports.ADMIN_PUBKEY = exports.DOPPLER_PROGRAM_ID = void 0;
12
+ exports.Doppler = exports.TransactionBuilder = exports.PriceDataSerializer = exports.U8Array8Serializer = exports.ADMIN_PUBKEY = exports.DOPPLER_PROGRAM_ID = void 0;
13
13
  exports.createPricePayload = createPricePayload;
14
+ exports.createPriceDataPayload = createPriceDataPayload;
14
15
  exports.readPriceFromPayload = readPriceFromPayload;
16
+ exports.readPriceDataFromPayload = readPriceDataFromPayload;
15
17
  const web3_js_1 = require("@solana/web3.js");
16
18
  const buffer_1 = require("buffer");
17
19
  const compute_budget_1 = require("@solana-program/compute-budget");
@@ -60,6 +62,15 @@ function createPricePayload(price) {
60
62
  buf.writeBigUInt64LE(price);
61
63
  return buf;
62
64
  }
65
+ /**
66
+ * Helper function to create a PriceData payload buffer from price and precision
67
+ */
68
+ function createPriceDataPayload(price, precision) {
69
+ const buf = buffer_1.Buffer.alloc(9);
70
+ buf.writeBigUInt64LE(price, 0);
71
+ buf.writeUInt8(precision, 8);
72
+ return buf;
73
+ }
63
74
  /**
64
75
  * Helper function to read a price value from a [u8; 8] payload
65
76
  */
@@ -69,6 +80,41 @@ function readPriceFromPayload(payload) {
69
80
  }
70
81
  return payload.readBigUInt64LE(0);
71
82
  }
83
+ /**
84
+ * Helper function to read PriceData from a buffer payload
85
+ */
86
+ function readPriceDataFromPayload(payload) {
87
+ if (payload.length < 9) {
88
+ throw new Error('Payload must be at least 9 bytes');
89
+ }
90
+ const price = payload.readBigUInt64LE(0);
91
+ const precision = payload.readUInt8(8);
92
+ return { price, precision };
93
+ }
94
+ /**
95
+ * Built-in serializer for PriceData payloads
96
+ * Structure: 8 bytes for price, 1 byte for precision (total 9 bytes)
97
+ */
98
+ class PriceDataSerializer {
99
+ serialize(payload) {
100
+ const buf = buffer_1.Buffer.alloc(9);
101
+ buf.writeBigUInt64LE(payload.price, 0);
102
+ buf.writeUInt8(payload.precision, 8);
103
+ return buf;
104
+ }
105
+ deserialize(buffer) {
106
+ if (buffer.length < 9) {
107
+ throw new Error('Buffer must be at least 9 bytes');
108
+ }
109
+ const price = buffer.readBigUInt64LE(0);
110
+ const precision = buffer.readUInt8(8);
111
+ return { price, precision };
112
+ }
113
+ size() {
114
+ return 9;
115
+ }
116
+ }
117
+ exports.PriceDataSerializer = PriceDataSerializer;
72
118
  /**
73
119
  * Transaction builder for Doppler oracle updates
74
120
  */
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts"],"version":"5.9.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/oracle.ts",
3
- "version": "2.2.2",
3
+ "version": "3.1.0",
4
4
  "type": "commonjs",
5
5
  "author": "L0STE, stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {