@drift-labs/sdk 2.87.0-beta.2 → 2.87.0-beta.4
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/VERSION +1 -1
- package/lib/adminClient.js +1 -3
- package/lib/driftClient.d.ts +6 -0
- package/lib/driftClient.js +39 -0
- package/lib/factory/oracleClient.js +4 -0
- package/lib/idl/drift.json +3 -0
- package/lib/idl/switchboard_on_demand_30.json +4383 -0
- package/lib/math/superStake.d.ts +3 -2
- package/lib/oracles/switchboardOnDemandClient.d.ts +11 -0
- package/lib/oracles/switchboardOnDemandClient.js +32 -0
- package/lib/types.d.ts +3 -0
- package/lib/types.js +1 -0
- package/package.json +3 -1
- package/src/adminClient.ts +1 -3
- package/src/driftClient.ts +57 -0
- package/src/factory/oracleClient.ts +5 -0
- package/src/idl/drift.json +3 -0
- package/src/idl/switchboard_on_demand_30.json +4383 -0
- package/src/oracles/switchboardOnDemandClient.ts +56 -0
- package/src/types.ts +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { OracleClient, OraclePriceData } from './types';
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
|
+
import switchboardOnDemandIdl from '../idl/switchboard_on_demand_30.json';
|
|
5
|
+
import { PRICE_PRECISION_EXP } from '../constants/numericConstants';
|
|
6
|
+
import {
|
|
7
|
+
BorshAccountsCoder as BorshAccountsCoder30,
|
|
8
|
+
Idl as Idl30,
|
|
9
|
+
} from '@coral-xyz/anchor-30';
|
|
10
|
+
|
|
11
|
+
const SB_PRECISION_EXP = new BN(18);
|
|
12
|
+
const SB_PRECISION = new BN(10).pow(SB_PRECISION_EXP.sub(PRICE_PRECISION_EXP));
|
|
13
|
+
|
|
14
|
+
type PullFeedAccountData = {
|
|
15
|
+
result: {
|
|
16
|
+
value: BN;
|
|
17
|
+
std_dev: BN;
|
|
18
|
+
mean: BN;
|
|
19
|
+
slot: BN;
|
|
20
|
+
range: BN;
|
|
21
|
+
};
|
|
22
|
+
last_update_timestamp: BN;
|
|
23
|
+
max_variance: BN;
|
|
24
|
+
min_responses: BN;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export class SwitchboardOnDemandClient implements OracleClient {
|
|
28
|
+
connection: Connection;
|
|
29
|
+
coder: BorshAccountsCoder30;
|
|
30
|
+
|
|
31
|
+
public constructor(connection: Connection) {
|
|
32
|
+
this.connection = connection;
|
|
33
|
+
this.coder = new BorshAccountsCoder30(switchboardOnDemandIdl as Idl30);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public async getOraclePriceData(
|
|
37
|
+
pricePublicKey: PublicKey
|
|
38
|
+
): Promise<OraclePriceData> {
|
|
39
|
+
const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
|
|
40
|
+
return this.getOraclePriceDataFromBuffer(accountInfo.data);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData {
|
|
44
|
+
const pullFeedAccountData = this.coder.decodeUnchecked(
|
|
45
|
+
'PullFeedAccountData',
|
|
46
|
+
buffer
|
|
47
|
+
) as PullFeedAccountData;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
price: pullFeedAccountData.result.value.div(SB_PRECISION),
|
|
51
|
+
slot: pullFeedAccountData.result.slot,
|
|
52
|
+
confidence: pullFeedAccountData.result.range.div(SB_PRECISION),
|
|
53
|
+
hasSufficientNumberOfDataPoints: true,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -117,6 +117,7 @@ export class OracleSource {
|
|
|
117
117
|
static readonly PYTH_STABLE_COIN = { pythStableCoin: {} };
|
|
118
118
|
static readonly PYTH_STABLE_COIN_PULL = { pythStableCoinPull: {} };
|
|
119
119
|
static readonly Prelaunch = { prelaunch: {} };
|
|
120
|
+
static readonly SWITCHBOARD_ON_DEMAND = { switchboardOnDemand: {} };
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
export class OrderType {
|