@reflectmoney/oracle.ts 3.0.0 → 3.2.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 +4 -13
- package/dist/index.js +15 -34
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,22 +26,13 @@ export interface PayloadSerializer<T> {
|
|
|
26
26
|
size(): number;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
* The payload is simply 8 bytes representing data in little-endian format
|
|
29
|
+
* Helper function to create a PriceData payload buffer from price and precision
|
|
31
30
|
*/
|
|
32
|
-
export declare
|
|
33
|
-
serialize(payload: Buffer): Buffer;
|
|
34
|
-
deserialize(buffer: Buffer): Buffer;
|
|
35
|
-
size(): number;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Helper function to create a [u8; 8] payload from a bigint price value
|
|
39
|
-
*/
|
|
40
|
-
export declare function createPricePayload(price: bigint): Buffer;
|
|
31
|
+
export declare function createPriceDataPayload(price: bigint, precision: number): Buffer;
|
|
41
32
|
/**
|
|
42
|
-
* Helper function to read
|
|
33
|
+
* Helper function to read PriceData from a buffer payload
|
|
43
34
|
*/
|
|
44
|
-
export declare function
|
|
35
|
+
export declare function readPriceDataFromPayload(payload: Buffer): PriceData;
|
|
45
36
|
/**
|
|
46
37
|
* Built-in serializer for PriceData payloads
|
|
47
38
|
* Structure: 8 bytes for price, 1 byte for precision (total 9 bytes)
|
package/dist/index.js
CHANGED
|
@@ -9,9 +9,9 @@ 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.PriceDataSerializer = exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
12
|
+
exports.Doppler = exports.TransactionBuilder = exports.PriceDataSerializer = exports.ADMIN_PUBKEY = exports.DOPPLER_PROGRAM_ID = void 0;
|
|
13
|
+
exports.createPriceDataPayload = createPriceDataPayload;
|
|
14
|
+
exports.readPriceDataFromPayload = readPriceDataFromPayload;
|
|
15
15
|
const web3_js_1 = require("@solana/web3.js");
|
|
16
16
|
const buffer_1 = require("buffer");
|
|
17
17
|
const compute_budget_1 = require("@solana-program/compute-budget");
|
|
@@ -31,43 +31,24 @@ const COMPUTE_BUDGET_PROGRAM_SIZE = 22;
|
|
|
31
31
|
const ORACLE_PROGRAM_SIZE = 36;
|
|
32
32
|
const READ_CLOCK_CU = 11;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
* The payload is simply 8 bytes representing data in little-endian format
|
|
34
|
+
* Helper function to create a PriceData payload buffer from price and precision
|
|
36
35
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
return payload;
|
|
43
|
-
}
|
|
44
|
-
deserialize(buffer) {
|
|
45
|
-
if (buffer.length < 8) {
|
|
46
|
-
throw new Error('Buffer must be at least 8 bytes');
|
|
47
|
-
}
|
|
48
|
-
return buffer.subarray(0, 8);
|
|
49
|
-
}
|
|
50
|
-
size() {
|
|
51
|
-
return 8;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.U8Array8Serializer = U8Array8Serializer;
|
|
55
|
-
/**
|
|
56
|
-
* Helper function to create a [u8; 8] payload from a bigint price value
|
|
57
|
-
*/
|
|
58
|
-
function createPricePayload(price) {
|
|
59
|
-
const buf = buffer_1.Buffer.alloc(8);
|
|
60
|
-
buf.writeBigUInt64LE(price);
|
|
36
|
+
function createPriceDataPayload(price, precision) {
|
|
37
|
+
const buf = buffer_1.Buffer.alloc(9);
|
|
38
|
+
buf.writeBigUInt64LE(price, 0);
|
|
39
|
+
buf.writeUInt8(precision, 8);
|
|
61
40
|
return buf;
|
|
62
41
|
}
|
|
63
42
|
/**
|
|
64
|
-
* Helper function to read
|
|
43
|
+
* Helper function to read PriceData from a buffer payload
|
|
65
44
|
*/
|
|
66
|
-
function
|
|
67
|
-
if (payload.length <
|
|
68
|
-
throw new Error('Payload must be at least
|
|
45
|
+
function readPriceDataFromPayload(payload) {
|
|
46
|
+
if (payload.length < 9) {
|
|
47
|
+
throw new Error('Payload must be at least 9 bytes');
|
|
69
48
|
}
|
|
70
|
-
|
|
49
|
+
const price = payload.readBigUInt64LE(0);
|
|
50
|
+
const precision = payload.readUInt8(8);
|
|
51
|
+
return { price, precision };
|
|
71
52
|
}
|
|
72
53
|
/**
|
|
73
54
|
* Built-in serializer for PriceData payloads
|