@reflectmoney/oracle.ts 3.2.4 → 4.0.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +29 -85
  2. package/dist/index.js +127 -176
  3. package/package.json +6 -17
package/dist/index.d.ts CHANGED
@@ -1,116 +1,60 @@
1
- import { Connection, PublicKey, Transaction, Keypair } from '@solana/web3.js';
2
- import { Buffer } from 'buffer';
3
- export declare const DOPPLER_PROGRAM_ID: PublicKey;
4
- export declare const ADMIN_PUBKEY: PublicKey;
5
- /**
6
- * Generic Oracle data structure matching Rust implementation
7
- */
1
+ import { type Address, type KeyPairSigner, type Blockhash, type Rpc, type SolanaRpcApi } from '@solana/kit';
2
+ export declare const DOPPLER_PROGRAM_ID: Address;
3
+ export declare const ADMIN_PUBKEY: Address;
8
4
  export interface Oracle<T> {
9
5
  slot: bigint;
10
6
  payload: T;
11
7
  }
12
- /**
13
- * Price data payload with precision information
14
- * Matches the Rust PriceData struct
15
- */
16
8
  export interface PriceData {
17
9
  price: bigint;
18
10
  precision: number;
19
11
  }
20
- /**
21
- * Serializer interface for custom payload types
22
- */
23
12
  export interface PayloadSerializer<T> {
24
- serialize(payload: T): Buffer;
25
- deserialize(buffer: Buffer): T;
13
+ serialize(payload: T): Uint8Array;
14
+ deserialize(buffer: Uint8Array): T;
26
15
  size(): number;
27
16
  }
28
- /**
29
- * Helper function to create a PriceData payload buffer from price and precision
30
- */
31
- export declare function createPriceDataPayload(price: bigint, precision: number): Buffer;
32
- /**
33
- * Helper function to read PriceData from a buffer payload
34
- */
35
- export declare function readPriceDataFromPayload(payload: Buffer): PriceData;
36
- /**
37
- * Built-in serializer for PriceData payloads
38
- * Structure: 8 bytes for price, 1 byte for precision (total 9 bytes)
39
- */
17
+ export declare function createPriceDataPayload(price: bigint, precision: number): Uint8Array;
18
+ export declare function readPriceDataFromPayload(payload: Uint8Array): PriceData;
40
19
  export declare class PriceDataSerializer implements PayloadSerializer<PriceData> {
41
- serialize(payload: PriceData): Buffer;
42
- deserialize(buffer: Buffer): PriceData;
20
+ serialize(payload: PriceData): Uint8Array;
21
+ deserialize(buffer: Uint8Array): PriceData;
43
22
  size(): number;
44
23
  }
45
- /**
46
- * Transaction builder for Doppler oracle updates
47
- */
48
24
  export declare class TransactionBuilder {
49
25
  private admin;
50
26
  private oracleUpdateInstructions;
51
27
  private unitPrice?;
52
28
  private computeUnits;
53
29
  private loadedAccountDataSize;
54
- constructor(admin: Keypair);
55
- /**
56
- * Add an oracle update instruction to the transaction
57
- */
58
- addOracleUpdate<T>(oraclePubkey: PublicKey, payload: T, serializer: PayloadSerializer<T>): this;
59
- /**
60
- * Set the compute unit price in micro-lamports
61
- */
30
+ constructor(admin: KeyPairSigner);
31
+ addOracleUpdate<T>(oracleAddress: Address, payload: T, serializer: PayloadSerializer<T>): this;
62
32
  withUnitPrice(microLamports: bigint): this;
63
- /**
64
- * Build the final transaction
65
- */
66
- build(recentBlockhash: string): Transaction;
33
+ build(latestBlockhash: Readonly<{
34
+ blockhash: Blockhash;
35
+ lastValidBlockHeight: bigint;
36
+ }>): Promise<import("@solana/kit").FullySignedTransaction & import("@solana/kit").TransactionWithinSizeLimit & Readonly<{
37
+ messageBytes: import("@solana/kit").TransactionMessageBytes;
38
+ signatures: import("@solana/kit").SignaturesMap;
39
+ }> & import("@solana/kit").TransactionWithLifetime & import("@solana/kit").TransactionWithBlockhashLifetime>;
67
40
  private createUpdateInstruction;
68
41
  }
69
- /**
70
- * Main Doppler class for interacting with oracle accounts
71
- */
72
42
  export declare class Doppler {
73
- private connection;
74
43
  private admin;
75
- constructor(connection: Connection, admin: Keypair);
76
- /**
77
- * Create a new transaction builder
78
- */
44
+ private rpc;
45
+ private rpcSubscriptions;
46
+ constructor(rpcUrl: string, rpcSubscriptionsUrl: string, admin: KeyPairSigner);
79
47
  createTransactionBuilder(): TransactionBuilder;
80
- /**
81
- * Fetch oracle account data and deserialize it
82
- */
83
- fetchOracle<T>(oraclePubkey: PublicKey, serializer: PayloadSerializer<T>): Promise<Oracle<T> | null>;
84
- /**
85
- * Deserialize oracle data from a buffer
86
- */
87
- deserializeOracle<T>(data: Buffer, serializer: PayloadSerializer<T>): Oracle<T>;
88
- /**
89
- * Create an oracle account from a keypair
90
- */
91
- createOracleAccount<T>(oracleKeypair: Keypair, serializer: PayloadSerializer<T>): Promise<PublicKey>;
92
- /**
93
- * Create an oracle account with a seed
94
- */
95
- createOracleAccountWithSeed<T>(seed: string, serializer: PayloadSerializer<T>): Promise<PublicKey>;
96
- /**
97
- * Update a single oracle account
98
- */
99
- updateOracle<T>(oraclePubkey: PublicKey, payload: T, serializer: PayloadSerializer<T>, unitPrice?: bigint): Promise<string>;
100
- /**
101
- * Update multiple oracle accounts in a single transaction
102
- */
48
+ fetchOracle<T>(oracleAddress: Address, serializer: PayloadSerializer<T>): Promise<Oracle<T> | null>;
49
+ deserializeOracle<T>(data: Uint8Array, serializer: PayloadSerializer<T>): Oracle<T>;
50
+ createOracleAccount<T>(oracleKeypair: KeyPairSigner, serializer: PayloadSerializer<T>): Promise<Address>;
51
+ createOracleAccountWithSeed<T>(seed: string, serializer: PayloadSerializer<T>): Promise<Address>;
52
+ updateOracle<T>(oracleAddress: Address, payload: T, serializer: PayloadSerializer<T>, unitPrice?: bigint): Promise<string>;
103
53
  updateMultipleOracles<T>(updates: Array<{
104
- oraclePubkey: PublicKey;
54
+ oracleAddress: Address;
105
55
  payload: T;
106
56
  serializer: PayloadSerializer<T>;
107
57
  }>, unitPrice?: bigint): Promise<string>;
108
- /**
109
- * Get the admin keypair
110
- */
111
- getAdmin(): Keypair;
112
- /**
113
- * Get the connection
114
- */
115
- getConnection(): Connection;
58
+ getAdmin(): KeyPairSigner;
59
+ getRpc(): Rpc<SolanaRpcApi>;
116
60
  }
package/dist/index.js CHANGED
@@ -12,14 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Doppler = exports.TransactionBuilder = exports.PriceDataSerializer = exports.ADMIN_PUBKEY = exports.DOPPLER_PROGRAM_ID = void 0;
13
13
  exports.createPriceDataPayload = createPriceDataPayload;
14
14
  exports.readPriceDataFromPayload = readPriceDataFromPayload;
15
- const web3_js_1 = require("@solana/web3.js");
16
- const buffer_1 = require("buffer");
15
+ const kit_1 = require("@solana/kit");
17
16
  const compute_budget_1 = require("@solana-program/compute-budget");
18
- // Program ID: PRicevBH6BaeaE8qmrxrwGBZ5hSZ9vjBNue5Ygot1ML
19
- exports.DOPPLER_PROGRAM_ID = new web3_js_1.PublicKey('PRicevBH6BaeaE8qmrxrwGBZ5hSZ9vjBNue5Ygot1ML');
20
- // Admin public key: pRiCEzwgkSi7KTsQHdyfuRbPEuCFoK9sA5QVn2hvABV
21
- exports.ADMIN_PUBKEY = new web3_js_1.PublicKey('pRiCEzwgkSi7KTsQHdyfuRbPEuCFoK9sA5QVn2hvABV');
22
- // Constants for compute unit calculations
17
+ const system_1 = require("@solana-program/system");
18
+ const sysvars_1 = require("@solana/sysvars");
19
+ exports.DOPPLER_PROGRAM_ID = (0, kit_1.address)('PRicevBH6BaeaE8qmrxrwGBZ5hSZ9vjBNue5Ygot1ML');
20
+ exports.ADMIN_PUBKEY = (0, kit_1.address)('pRiCEzwgkSi7KTsQHdyfuRbPEuCFoK9sA5QVn2hvABV');
23
21
  const SEQUENCE_CHECK_CU = 5;
24
22
  const ADMIN_VERIFICATION_CU = 6;
25
23
  const PAYLOAD_WRITE_CU = 8;
@@ -30,53 +28,34 @@ const COMPUTE_BUDGET_DATA_LIMIT_SIZE = 5;
30
28
  const COMPUTE_BUDGET_PROGRAM_SIZE = 22;
31
29
  const ORACLE_PROGRAM_SIZE = 36;
32
30
  const READ_CLOCK_CU = 11;
33
- /**
34
- * Helper function to create a PriceData payload buffer from price and precision
35
- */
36
31
  function createPriceDataPayload(price, precision) {
37
- const buf = buffer_1.Buffer.alloc(9);
38
- buf.writeBigUInt64LE(price, 0);
39
- buf.writeUInt8(precision, 8);
40
- return buf;
32
+ const buf = new ArrayBuffer(9);
33
+ const view = new DataView(buf);
34
+ view.setBigUint64(0, price, true);
35
+ view.setUint8(8, precision);
36
+ return new Uint8Array(buf);
41
37
  }
42
- /**
43
- * Helper function to read PriceData from a buffer payload
44
- */
45
38
  function readPriceDataFromPayload(payload) {
46
39
  if (payload.length < 9) {
47
40
  throw new Error('Payload must be at least 9 bytes');
48
41
  }
49
- const price = payload.readBigUInt64LE(0);
50
- const precision = payload.readUInt8(8);
42
+ const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
43
+ const price = view.getBigUint64(0, true);
44
+ const precision = view.getUint8(8);
51
45
  return { price, precision };
52
46
  }
53
- /**
54
- * Built-in serializer for PriceData payloads
55
- * Structure: 8 bytes for price, 1 byte for precision (total 9 bytes)
56
- */
57
47
  class PriceDataSerializer {
58
48
  serialize(payload) {
59
- const buf = buffer_1.Buffer.alloc(9);
60
- buf.writeBigUInt64LE(payload.price, 0);
61
- buf.writeUInt8(payload.precision, 8);
62
- return buf;
49
+ return createPriceDataPayload(payload.price, payload.precision);
63
50
  }
64
51
  deserialize(buffer) {
65
- if (buffer.length < 9) {
66
- throw new Error('Buffer must be at least 9 bytes');
67
- }
68
- const price = buffer.readBigUInt64LE(0);
69
- const precision = buffer.readUInt8(8);
70
- return { price, precision };
52
+ return readPriceDataFromPayload(buffer);
71
53
  }
72
54
  size() {
73
55
  return 9;
74
56
  }
75
57
  }
76
58
  exports.PriceDataSerializer = PriceDataSerializer;
77
- /**
78
- * Transaction builder for Doppler oracle updates
79
- */
80
59
  class TransactionBuilder {
81
60
  constructor(admin) {
82
61
  this.admin = admin;
@@ -88,115 +67,91 @@ class TransactionBuilder {
88
67
  COMPUTE_BUDGET_DATA_LIMIT_SIZE +
89
68
  2;
90
69
  }
91
- /**
92
- * Add an oracle update instruction to the transaction
93
- */
94
- addOracleUpdate(oraclePubkey, payload, serializer) {
95
- const instruction = this.createUpdateInstruction(oraclePubkey, payload, serializer);
70
+ addOracleUpdate(oracleAddress, payload, serializer) {
71
+ const instruction = this.createUpdateInstruction(oracleAddress, payload, serializer);
96
72
  const payloadSize = serializer.size();
97
- const oracleSize = 8 + payloadSize; // slot + payload
73
+ const oracleSize = 8 + payloadSize;
98
74
  this.computeUnits +=
99
75
  SEQUENCE_CHECK_CU +
100
76
  ADMIN_VERIFICATION_CU +
101
77
  PAYLOAD_WRITE_CU +
102
78
  Math.floor(oracleSize / 4) +
103
79
  READ_CLOCK_CU;
104
- this.loadedAccountDataSize += oracleSize * 4;
80
+ this.loadedAccountDataSize += oracleSize * 200;
105
81
  this.oracleUpdateInstructions.push(instruction);
106
82
  return this;
107
83
  }
108
- /**
109
- * Set the compute unit price in micro-lamports
110
- */
111
84
  withUnitPrice(microLamports) {
112
85
  this.unitPrice = microLamports;
113
86
  return this;
114
87
  }
115
- /**
116
- * Build the final transaction
117
- */
118
- build(recentBlockhash) {
119
- const instructions = [];
120
- let loadedAccountDataSize = this.loadedAccountDataSize;
121
- let computeUnits = this.computeUnits;
122
- if (this.unitPrice !== undefined) {
123
- instructions.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
124
- microLamports: this.unitPrice,
88
+ build(latestBlockhash) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const instructions = [];
91
+ let loadedAccountDataSize = this.loadedAccountDataSize;
92
+ let computeUnits = this.computeUnits;
93
+ if (this.unitPrice !== undefined) {
94
+ instructions.push((0, compute_budget_1.getSetComputeUnitPriceInstruction)({
95
+ microLamports: this.unitPrice,
96
+ }));
97
+ loadedAccountDataSize += COMPUTE_BUDGET_UNIT_PRICE_SIZE;
98
+ computeUnits += COMPUTE_BUDGET_IX_CU;
99
+ }
100
+ instructions.push((0, compute_budget_1.getSetLoadedAccountsDataSizeLimitInstruction)({
101
+ accountDataSizeLimit: loadedAccountDataSize * 2,
125
102
  }));
126
- loadedAccountDataSize += COMPUTE_BUDGET_UNIT_PRICE_SIZE;
127
- computeUnits += COMPUTE_BUDGET_IX_CU;
128
- }
129
- const loadedAccountsDataSizeLimitInstruction = (0, compute_budget_1.getSetLoadedAccountsDataSizeLimitInstruction)({
130
- accountDataSizeLimit: loadedAccountDataSize * 2
131
- });
132
- instructions.push(new web3_js_1.TransactionInstruction({
133
- keys: [],
134
- programId: new web3_js_1.PublicKey(loadedAccountsDataSizeLimitInstruction.programAddress.toString()),
135
- data: buffer_1.Buffer.from(loadedAccountsDataSizeLimitInstruction.data),
136
- }));
137
- instructions.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
138
- units: computeUnits,
139
- }));
140
- instructions.push(...this.oracleUpdateInstructions);
141
- const transaction = new web3_js_1.Transaction({
142
- feePayer: this.admin.publicKey,
143
- recentBlockhash,
103
+ instructions.push((0, compute_budget_1.getSetComputeUnitLimitInstruction)({
104
+ units: computeUnits,
105
+ }));
106
+ instructions.push(...this.oracleUpdateInstructions);
107
+ const transactionMessage = (0, kit_1.pipe)((0, kit_1.createTransactionMessage)({ version: 0 }), (m) => (0, kit_1.setTransactionMessageFeePayerSigner)(this.admin, m), (m) => (0, kit_1.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, m), (m) => (0, kit_1.appendTransactionMessageInstructions)(instructions, m));
108
+ const signedTransaction = yield (0, kit_1.signTransactionMessageWithSigners)(transactionMessage);
109
+ (0, kit_1.assertIsSendableTransaction)(signedTransaction);
110
+ (0, kit_1.assertIsTransactionWithBlockhashLifetime)(signedTransaction);
111
+ return signedTransaction;
144
112
  });
145
- transaction.add(...instructions);
146
- transaction.sign(this.admin);
147
- return transaction;
148
113
  }
149
- createUpdateInstruction(oraclePubkey, payload, serializer) {
114
+ createUpdateInstruction(oracleAddress, payload, serializer) {
150
115
  const data = serializer.serialize(payload);
151
- return new web3_js_1.TransactionInstruction({
152
- programId: exports.DOPPLER_PROGRAM_ID,
153
- keys: [
116
+ return {
117
+ programAddress: exports.DOPPLER_PROGRAM_ID,
118
+ accounts: [
154
119
  {
155
- pubkey: this.admin.publicKey,
156
- isSigner: true,
157
- isWritable: false,
120
+ address: this.admin.address,
121
+ role: kit_1.AccountRole.READONLY_SIGNER,
122
+ signer: this.admin,
158
123
  },
159
124
  {
160
- pubkey: oraclePubkey,
161
- isSigner: false,
162
- isWritable: true,
125
+ address: oracleAddress,
126
+ role: kit_1.AccountRole.WRITABLE,
163
127
  },
164
128
  {
165
- pubkey: web3_js_1.SYSVAR_CLOCK_PUBKEY,
166
- isSigner: false,
167
- isWritable: false,
129
+ address: sysvars_1.SYSVAR_CLOCK_ADDRESS,
130
+ role: kit_1.AccountRole.READONLY,
168
131
  },
169
132
  ],
170
133
  data,
171
- });
134
+ };
172
135
  }
173
136
  }
174
137
  exports.TransactionBuilder = TransactionBuilder;
175
- /**
176
- * Main Doppler class for interacting with oracle accounts
177
- */
178
138
  class Doppler {
179
- constructor(connection, admin) {
180
- this.connection = connection;
139
+ constructor(rpcUrl, rpcSubscriptionsUrl, admin) {
181
140
  this.admin = admin;
141
+ this.rpc = (0, kit_1.createSolanaRpc)(rpcUrl);
142
+ this.rpcSubscriptions = (0, kit_1.createSolanaRpcSubscriptions)(rpcSubscriptionsUrl);
182
143
  }
183
- /**
184
- * Create a new transaction builder
185
- */
186
144
  createTransactionBuilder() {
187
145
  return new TransactionBuilder(this.admin);
188
146
  }
189
- /**
190
- * Fetch oracle account data and deserialize it
191
- */
192
- fetchOracle(oraclePubkey, serializer) {
147
+ fetchOracle(oracleAddress, serializer) {
193
148
  return __awaiter(this, void 0, void 0, function* () {
194
149
  try {
195
- const accountInfo = yield this.connection.getAccountInfo(oraclePubkey);
196
- if (!accountInfo || !accountInfo.data) {
150
+ const maybeAccount = yield (0, kit_1.fetchEncodedAccount)(this.rpc, oracleAddress);
151
+ if (!maybeAccount.exists) {
197
152
  return null;
198
153
  }
199
- return this.deserializeOracle(accountInfo.data, serializer);
154
+ return this.deserializeOracle(maybeAccount.data, serializer);
200
155
  }
201
156
  catch (error) {
202
157
  console.error('Error fetching oracle account:', error);
@@ -204,121 +159,117 @@ class Doppler {
204
159
  }
205
160
  });
206
161
  }
207
- /**
208
- * Deserialize oracle data from a buffer
209
- */
210
162
  deserializeOracle(data, serializer) {
211
163
  const expectedSize = 8 + serializer.size();
212
164
  if (data.length < expectedSize) {
213
165
  throw new Error(`Invalid oracle data size. Expected at least ${expectedSize}, got ${data.length}`);
214
166
  }
215
- const slot = data.readBigUInt64LE(0);
216
- const payloadBuffer = data.subarray(8, 8 + serializer.size());
167
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
168
+ const slot = view.getBigUint64(0, true);
169
+ const payloadBuffer = data.slice(8, 8 + serializer.size());
217
170
  const payload = serializer.deserialize(payloadBuffer);
218
171
  return { slot, payload };
219
172
  }
220
- /**
221
- * Create an oracle account from a keypair
222
- */
223
173
  createOracleAccount(oracleKeypair, serializer) {
224
174
  return __awaiter(this, void 0, void 0, function* () {
225
175
  const oracleSize = 8 + serializer.size();
226
- const lamports = yield this.connection.getMinimumBalanceForRentExemption(oracleSize);
227
- const createAccountInstruction = web3_js_1.SystemProgram.createAccount({
228
- fromPubkey: this.admin.publicKey,
229
- newAccountPubkey: oracleKeypair.publicKey,
230
- lamports,
176
+ const rentLamports = yield this.rpc
177
+ .getMinimumBalanceForRentExemption(BigInt(oracleSize))
178
+ .send();
179
+ const createAccountIx = (0, system_1.getCreateAccountInstruction)({
180
+ payer: this.admin,
181
+ newAccount: oracleKeypair,
182
+ lamports: rentLamports,
231
183
  space: oracleSize,
232
- programId: exports.DOPPLER_PROGRAM_ID,
184
+ programAddress: exports.DOPPLER_PROGRAM_ID,
233
185
  });
234
- const recentBlockhash = yield this.connection.getLatestBlockhash();
235
- const transaction = new web3_js_1.Transaction({
236
- feePayer: this.admin.publicKey,
237
- recentBlockhash: recentBlockhash.blockhash,
186
+ const { value: latestBlockhash } = yield this.rpc.getLatestBlockhash().send();
187
+ const transactionMessage = (0, kit_1.pipe)((0, kit_1.createTransactionMessage)({ version: 0 }), (m) => (0, kit_1.setTransactionMessageFeePayerSigner)(this.admin, m), (m) => (0, kit_1.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, m), (m) => (0, kit_1.appendTransactionMessageInstructions)([createAccountIx], m));
188
+ const signedTransaction = yield (0, kit_1.signTransactionMessageWithSigners)(transactionMessage);
189
+ (0, kit_1.assertIsSendableTransaction)(signedTransaction);
190
+ (0, kit_1.assertIsTransactionWithBlockhashLifetime)(signedTransaction);
191
+ const sendAndConfirm = (0, kit_1.sendAndConfirmTransactionFactory)({
192
+ rpc: this.rpc,
193
+ rpcSubscriptions: this.rpcSubscriptions,
238
194
  });
239
- transaction.add(createAccountInstruction);
240
- transaction.sign(this.admin, oracleKeypair);
241
- yield (0, web3_js_1.sendAndConfirmTransaction)(this.connection, transaction, [
242
- this.admin,
243
- oracleKeypair,
244
- ]);
245
- return oracleKeypair.publicKey;
195
+ yield sendAndConfirm(signedTransaction, { commitment: 'confirmed' });
196
+ return oracleKeypair.address;
246
197
  });
247
198
  }
248
- /**
249
- * Create an oracle account with a seed
250
- */
251
199
  createOracleAccountWithSeed(seed, serializer) {
252
200
  return __awaiter(this, void 0, void 0, function* () {
253
201
  const oracleSize = 8 + serializer.size();
254
- const lamports = yield this.connection.getMinimumBalanceForRentExemption(oracleSize);
255
- const oraclePubkey = yield web3_js_1.PublicKey.createWithSeed(this.admin.publicKey, seed, exports.DOPPLER_PROGRAM_ID);
256
- const createAccountInstruction = web3_js_1.SystemProgram.createAccountWithSeed({
257
- fromPubkey: this.admin.publicKey,
258
- newAccountPubkey: oraclePubkey,
259
- basePubkey: this.admin.publicKey,
202
+ const rentLamports = yield this.rpc
203
+ .getMinimumBalanceForRentExemption(BigInt(oracleSize))
204
+ .send();
205
+ const oracleAddress = yield (0, kit_1.createAddressWithSeed)({
206
+ baseAddress: this.admin.address,
207
+ programAddress: exports.DOPPLER_PROGRAM_ID,
260
208
  seed,
261
- lamports,
209
+ });
210
+ const createAccountIx = (0, system_1.getCreateAccountWithSeedInstruction)({
211
+ payer: this.admin,
212
+ newAccount: oracleAddress,
213
+ base: this.admin.address,
214
+ baseAccount: this.admin,
215
+ seed,
216
+ amount: rentLamports,
262
217
  space: oracleSize,
263
- programId: exports.DOPPLER_PROGRAM_ID,
218
+ programAddress: exports.DOPPLER_PROGRAM_ID,
264
219
  });
265
- const recentBlockhash = yield this.connection.getLatestBlockhash();
266
- const transaction = new web3_js_1.Transaction({
267
- feePayer: this.admin.publicKey,
268
- recentBlockhash: recentBlockhash.blockhash,
220
+ const { value: latestBlockhash } = yield this.rpc.getLatestBlockhash().send();
221
+ const transactionMessage = (0, kit_1.pipe)((0, kit_1.createTransactionMessage)({ version: 0 }), (m) => (0, kit_1.setTransactionMessageFeePayerSigner)(this.admin, m), (m) => (0, kit_1.setTransactionMessageLifetimeUsingBlockhash)(latestBlockhash, m), (m) => (0, kit_1.appendTransactionMessageInstructions)([createAccountIx], m));
222
+ const signedTransaction = yield (0, kit_1.signTransactionMessageWithSigners)(transactionMessage);
223
+ (0, kit_1.assertIsSendableTransaction)(signedTransaction);
224
+ (0, kit_1.assertIsTransactionWithBlockhashLifetime)(signedTransaction);
225
+ const sendAndConfirm = (0, kit_1.sendAndConfirmTransactionFactory)({
226
+ rpc: this.rpc,
227
+ rpcSubscriptions: this.rpcSubscriptions,
269
228
  });
270
- transaction.add(createAccountInstruction);
271
- transaction.sign(this.admin);
272
- yield (0, web3_js_1.sendAndConfirmTransaction)(this.connection, transaction, [this.admin]);
273
- return oraclePubkey;
229
+ yield sendAndConfirm(signedTransaction, { commitment: 'confirmed' });
230
+ return oracleAddress;
274
231
  });
275
232
  }
276
- /**
277
- * Update a single oracle account
278
- */
279
- updateOracle(oraclePubkey, payload, serializer, unitPrice) {
233
+ updateOracle(oracleAddress, payload, serializer, unitPrice) {
280
234
  return __awaiter(this, void 0, void 0, function* () {
281
- const recentBlockhash = yield this.connection.getLatestBlockhash();
282
- let builder = this.createTransactionBuilder().addOracleUpdate(oraclePubkey, payload, serializer);
235
+ const { value: latestBlockhash } = yield this.rpc.getLatestBlockhash().send();
236
+ let builder = this.createTransactionBuilder().addOracleUpdate(oracleAddress, payload, serializer);
283
237
  if (unitPrice !== undefined) {
284
238
  builder = builder.withUnitPrice(unitPrice);
285
239
  }
286
- const transaction = builder.build(recentBlockhash.blockhash);
287
- const signature = yield (0, web3_js_1.sendAndConfirmTransaction)(this.connection, transaction, [this.admin], {
288
- skipPreflight: true
240
+ const signedTransaction = yield builder.build(latestBlockhash);
241
+ const sendAndConfirm = (0, kit_1.sendAndConfirmTransactionFactory)({
242
+ rpc: this.rpc,
243
+ rpcSubscriptions: this.rpcSubscriptions,
289
244
  });
290
- return signature;
245
+ yield sendAndConfirm(signedTransaction, { commitment: 'confirmed' });
246
+ return (0, kit_1.getSignatureFromTransaction)(signedTransaction);
291
247
  });
292
248
  }
293
- /**
294
- * Update multiple oracle accounts in a single transaction
295
- */
296
249
  updateMultipleOracles(updates, unitPrice) {
297
250
  return __awaiter(this, void 0, void 0, function* () {
298
- const recentBlockhash = yield this.connection.getLatestBlockhash();
251
+ const { value: latestBlockhash } = yield this.rpc.getLatestBlockhash().send();
299
252
  let builder = this.createTransactionBuilder();
300
253
  for (const update of updates) {
301
- builder = builder.addOracleUpdate(update.oraclePubkey, update.payload, update.serializer);
254
+ builder = builder.addOracleUpdate(update.oracleAddress, update.payload, update.serializer);
302
255
  }
303
256
  if (unitPrice !== undefined) {
304
257
  builder = builder.withUnitPrice(unitPrice);
305
258
  }
306
- const transaction = builder.build(recentBlockhash.blockhash);
307
- const signature = yield (0, web3_js_1.sendAndConfirmTransaction)(this.connection, transaction, [this.admin]);
308
- return signature;
259
+ const signedTransaction = yield builder.build(latestBlockhash);
260
+ const sendAndConfirm = (0, kit_1.sendAndConfirmTransactionFactory)({
261
+ rpc: this.rpc,
262
+ rpcSubscriptions: this.rpcSubscriptions,
263
+ });
264
+ yield sendAndConfirm(signedTransaction, { commitment: 'confirmed' });
265
+ return (0, kit_1.getSignatureFromTransaction)(signedTransaction);
309
266
  });
310
267
  }
311
- /**
312
- * Get the admin keypair
313
- */
314
268
  getAdmin() {
315
269
  return this.admin;
316
270
  }
317
- /**
318
- * Get the connection
319
- */
320
- getConnection() {
321
- return this.connection;
271
+ getRpc() {
272
+ return this.rpc;
322
273
  }
323
274
  }
324
275
  exports.Doppler = Doppler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/oracle.ts",
3
- "version": "3.2.4",
3
+ "version": "4.0.0",
4
4
  "type": "commonjs",
5
5
  "author": "L0STE, stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {
@@ -11,25 +11,14 @@
11
11
  "build": "tsc"
12
12
  },
13
13
  "dependencies": {
14
- "@solana-program/compute-budget": "^0.9.0",
15
- "@solana-program/token": "^0.6.0",
16
- "@solana/buffer-layout": "^4.0.1",
17
- "@solana/kit": "^3.0.3",
18
- "@solana/web3.js": "^1.98.4",
19
- "bn.js": "^5.2.2",
20
- "buffer": "^6.0.3"
14
+ "@solana-program/compute-budget": "^0.12.0",
15
+ "@solana-program/system": "^0.10.0",
16
+ "@solana/kit": "5.5.1"
21
17
  },
22
18
  "devDependencies": {
23
- "@types/bn.js": "5.1.6",
24
- "@types/chai": "^4.3.11",
25
- "@types/mocha": "^10.0.6",
26
19
  "@types/node": "^24.7.2",
27
- "bs58": "^6.0.0",
28
- "chai": "^4.3.10",
29
- "commander": "^14.0.1",
30
- "mocha": "^10.2.0",
31
- "ts-node": "^10.9.2",
32
- "tsx": "^4.20.6"
20
+ "tsx": "^4.20.6",
21
+ "typescript": "^5.7.0"
33
22
  },
34
23
  "license": "MIT",
35
24
  "main": "./dist/index.js",