@reflectmoney/oracle.ts 1.0.0 → 1.0.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/README.md +87 -0
- package/package.json +1 -1
package/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# @reflectmoney/oracle.ts
|
2
|
+
|
3
|
+
TypeScript SDK for Doppler, the efficient oracle program implemented by [Blueshift](https://blueshift.gg), used by Reflect.
|
4
|
+
|
5
|
+
## About
|
6
|
+
|
7
|
+
Reflect uses [Doppler](https://github.com/blueshift-gg/doppler) as its oracle solution, enabling oracle updates with just **21 compute units** per call - one of the most efficient implementations on Solana.
|
8
|
+
|
9
|
+
**Program ID:** `PRicevBH6BaeaE8qmrxrwGBZ5hSZ9vjBNue5Ygot1ML`
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
With NPM:
|
14
|
+
```bash
|
15
|
+
npm install @reflectmoney/oracle.ts
|
16
|
+
```
|
17
|
+
|
18
|
+
With Yarn:
|
19
|
+
```bash
|
20
|
+
yarn add @reflectmoney/oracle.ts
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Initialize Doppler
|
26
|
+
|
27
|
+
```typescript
|
28
|
+
import { Doppler, PriceFeedSerializer } from "@reflectmoney/oracle.ts";
|
29
|
+
import { Connection, Keypair } from "@solana/web3.js";
|
30
|
+
|
31
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
32
|
+
const admin = Keypair.fromSecretKey(/* admin keypair */);
|
33
|
+
|
34
|
+
const doppler = new Doppler(connection, admin);
|
35
|
+
```
|
36
|
+
|
37
|
+
### Update an Oracle
|
38
|
+
|
39
|
+
```typescript
|
40
|
+
import { PublicKey } from "@solana/web3.js";
|
41
|
+
|
42
|
+
const oraclePublicKey = new PublicKey("ORACLE_ADDRESS");
|
43
|
+
|
44
|
+
await doppler.updateOracle(
|
45
|
+
oraclePublicKey,
|
46
|
+
{
|
47
|
+
payload: { price: BigInt(Math.pow(10, 6)) },
|
48
|
+
sequence: BigInt(Date.now())
|
49
|
+
},
|
50
|
+
new PriceFeedSerializer(),
|
51
|
+
);
|
52
|
+
```
|
53
|
+
|
54
|
+
### Fetch Oracle Data
|
55
|
+
|
56
|
+
```typescript
|
57
|
+
const oracleData = await doppler.fetchOracle(
|
58
|
+
oraclePublicKey,
|
59
|
+
new PriceFeedSerializer(),
|
60
|
+
);
|
61
|
+
|
62
|
+
console.log(oracleData);
|
63
|
+
// { sequence: 1, payload: { price: 1000000n } }
|
64
|
+
```
|
65
|
+
|
66
|
+
### Create an Oracle Account
|
67
|
+
|
68
|
+
```typescript
|
69
|
+
const oracleAccount = await doppler.createOracleAccount(
|
70
|
+
"my-oracle-seed",
|
71
|
+
new PriceFeedSerializer(),
|
72
|
+
{
|
73
|
+
payload: { price: BigInt(Math.pow(10, 6)) },
|
74
|
+
sequence: 0n
|
75
|
+
}
|
76
|
+
);
|
77
|
+
```
|
78
|
+
|
79
|
+
## Links
|
80
|
+
|
81
|
+
- [GitHub Repository](https://github.com/palindrome-eng/doppler)
|
82
|
+
- [Reflect](https://reflect.money)
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
MIT
|
87
|
+
|