@reflectmoney/oracle.ts 2.0.0 → 2.1.1
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 -5
- package/dist/index.js +10 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -47,7 +47,7 @@ export declare class TransactionBuilder {
|
|
47
47
|
/**
|
48
48
|
* Add an oracle update instruction to the transaction
|
49
49
|
*/
|
50
|
-
addOracleUpdate<T>(oraclePubkey: PublicKey,
|
50
|
+
addOracleUpdate<T>(oraclePubkey: PublicKey, payload: T, serializer: PayloadSerializer<T>): this;
|
51
51
|
/**
|
52
52
|
* Set the compute unit price in micro-lamports
|
53
53
|
*/
|
@@ -57,7 +57,6 @@ export declare class TransactionBuilder {
|
|
57
57
|
*/
|
58
58
|
build(recentBlockhash: string): Transaction;
|
59
59
|
private createUpdateInstruction;
|
60
|
-
private serializeOracle;
|
61
60
|
}
|
62
61
|
/**
|
63
62
|
* Main Doppler class for interacting with oracle accounts
|
@@ -81,17 +80,17 @@ export declare class Doppler {
|
|
81
80
|
/**
|
82
81
|
* Create an oracle account with a seed
|
83
82
|
*/
|
84
|
-
createOracleAccount<T>(seed: string, serializer: PayloadSerializer<T
|
83
|
+
createOracleAccount<T>(seed: string, serializer: PayloadSerializer<T>): Promise<PublicKey>;
|
85
84
|
/**
|
86
85
|
* Update a single oracle account
|
87
86
|
*/
|
88
|
-
updateOracle<T>(oraclePubkey: PublicKey,
|
87
|
+
updateOracle<T>(oraclePubkey: PublicKey, payload: T, serializer: PayloadSerializer<T>, unitPrice?: bigint): Promise<string>;
|
89
88
|
/**
|
90
89
|
* Update multiple oracle accounts in a single transaction
|
91
90
|
*/
|
92
91
|
updateMultipleOracles<T>(updates: Array<{
|
93
92
|
oraclePubkey: PublicKey;
|
94
|
-
|
93
|
+
payload: T;
|
95
94
|
serializer: PayloadSerializer<T>;
|
96
95
|
}>, unitPrice?: bigint): Promise<string>;
|
97
96
|
/**
|
package/dist/index.js
CHANGED
@@ -85,15 +85,16 @@ class TransactionBuilder {
|
|
85
85
|
/**
|
86
86
|
* Add an oracle update instruction to the transaction
|
87
87
|
*/
|
88
|
-
addOracleUpdate(oraclePubkey,
|
89
|
-
const instruction = this.createUpdateInstruction(oraclePubkey,
|
88
|
+
addOracleUpdate(oraclePubkey, payload, serializer) {
|
89
|
+
const instruction = this.createUpdateInstruction(oraclePubkey, payload, serializer);
|
90
90
|
const payloadSize = serializer.size();
|
91
91
|
const oracleSize = 8 + payloadSize; // slot + payload
|
92
92
|
this.computeUnits +=
|
93
93
|
SEQUENCE_CHECK_CU +
|
94
94
|
ADMIN_VERIFICATION_CU +
|
95
95
|
PAYLOAD_WRITE_CU +
|
96
|
-
Math.floor(oracleSize / 4)
|
96
|
+
Math.floor(oracleSize / 4) +
|
97
|
+
500;
|
97
98
|
this.loadedAccountDataSize += oracleSize * 2;
|
98
99
|
this.oracleUpdateInstructions.push(instruction);
|
99
100
|
return this;
|
@@ -139,8 +140,8 @@ class TransactionBuilder {
|
|
139
140
|
transaction.sign(this.admin);
|
140
141
|
return transaction;
|
141
142
|
}
|
142
|
-
createUpdateInstruction(oraclePubkey,
|
143
|
-
const data =
|
143
|
+
createUpdateInstruction(oraclePubkey, payload, serializer) {
|
144
|
+
const data = serializer.serialize(payload);
|
144
145
|
return new web3_js_1.TransactionInstruction({
|
145
146
|
programId: exports.DOPPLER_PROGRAM_ID,
|
146
147
|
keys: [
|
@@ -163,12 +164,6 @@ class TransactionBuilder {
|
|
163
164
|
data,
|
164
165
|
});
|
165
166
|
}
|
166
|
-
serializeOracle(oracle, serializer) {
|
167
|
-
const slotBuffer = buffer_1.Buffer.alloc(8);
|
168
|
-
slotBuffer.writeBigUInt64LE(oracle.slot);
|
169
|
-
const payloadBuffer = serializer.serialize(oracle.payload);
|
170
|
-
return buffer_1.Buffer.concat([slotBuffer, payloadBuffer]);
|
171
|
-
}
|
172
167
|
}
|
173
168
|
exports.TransactionBuilder = TransactionBuilder;
|
174
169
|
/**
|
@@ -219,7 +214,7 @@ class Doppler {
|
|
219
214
|
/**
|
220
215
|
* Create an oracle account with a seed
|
221
216
|
*/
|
222
|
-
createOracleAccount(seed, serializer
|
217
|
+
createOracleAccount(seed, serializer) {
|
223
218
|
return __awaiter(this, void 0, void 0, function* () {
|
224
219
|
const oracleSize = 8 + serializer.size();
|
225
220
|
const lamports = yield this.connection.getMinimumBalanceForRentExemption(oracleSize);
|
@@ -247,10 +242,10 @@ class Doppler {
|
|
247
242
|
/**
|
248
243
|
* Update a single oracle account
|
249
244
|
*/
|
250
|
-
updateOracle(oraclePubkey,
|
245
|
+
updateOracle(oraclePubkey, payload, serializer, unitPrice) {
|
251
246
|
return __awaiter(this, void 0, void 0, function* () {
|
252
247
|
const recentBlockhash = yield this.connection.getLatestBlockhash();
|
253
|
-
let builder = this.createTransactionBuilder().addOracleUpdate(oraclePubkey,
|
248
|
+
let builder = this.createTransactionBuilder().addOracleUpdate(oraclePubkey, payload, serializer);
|
254
249
|
if (unitPrice !== undefined) {
|
255
250
|
builder = builder.withUnitPrice(unitPrice);
|
256
251
|
}
|
@@ -267,7 +262,7 @@ class Doppler {
|
|
267
262
|
const recentBlockhash = yield this.connection.getLatestBlockhash();
|
268
263
|
let builder = this.createTransactionBuilder();
|
269
264
|
for (const update of updates) {
|
270
|
-
builder = builder.addOracleUpdate(update.oraclePubkey, update.
|
265
|
+
builder = builder.addOracleUpdate(update.oraclePubkey, update.payload, update.serializer);
|
271
266
|
}
|
272
267
|
if (unitPrice !== undefined) {
|
273
268
|
builder = builder.withUnitPrice(unitPrice);
|