@drift-labs/sdk 0.1.36-master.3 → 0.1.36-master.6
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/lib/accounts/bulkAccountLoader.d.ts +1 -0
- package/lib/accounts/bulkAccountLoader.js +4 -0
- package/lib/admin.js +1 -1
- package/lib/clearingHouse.d.ts +6 -4
- package/lib/clearingHouse.js +46 -8
- package/lib/examples/makeTradeExample.js +1 -1
- package/lib/factory/clearingHouse.js +4 -4
- package/lib/idl/clearing_house.json +72 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/oracles.d.ts +3 -0
- package/lib/math/oracles.js +26 -0
- package/lib/math/trade.d.ts +10 -6
- package/lib/math/trade.js +68 -13
- package/lib/mockUSDCFaucet.d.ts +2 -2
- package/lib/mockUSDCFaucet.js +3 -3
- package/lib/oracles/pythClient.js +1 -0
- package/lib/oracles/switchboardClient.js +4 -1
- package/lib/oracles/types.d.ts +1 -0
- package/lib/tx/defaultTxSender.d.ts +3 -3
- package/lib/tx/defaultTxSender.js +1 -1
- package/lib/tx/retryTxSender.d.ts +3 -3
- package/package.json +2 -2
- package/src/accounts/bulkAccountLoader.ts +5 -0
- package/src/accounts/webSocketAccountSubscriber.ts +3 -3
- package/src/admin.ts +2 -2
- package/src/clearingHouse.ts +81 -10
- package/src/examples/makeTradeExample.ts +6 -2
- package/src/factory/clearingHouse.ts +13 -5
- package/src/idl/clearing_house.json +72 -1
- package/src/index.ts +1 -0
- package/src/math/oracles.ts +36 -0
- package/src/math/trade.ts +84 -16
- package/src/mockUSDCFaucet.ts +5 -5
- package/src/oracles/pythClient.ts +1 -0
- package/src/oracles/switchboardClient.ts +7 -2
- package/src/oracles/types.ts +1 -0
- package/src/tx/defaultTxSender.ts +4 -4
- package/src/tx/retryTxSender.ts +3 -3
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from '@switchboard-xyz/switchboard-v2';
|
|
5
5
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
6
6
|
import { DriftEnv } from '../config';
|
|
7
|
-
import { BN,
|
|
7
|
+
import { BN, Program, Idl, AnchorProvider } from '@project-serum/anchor';
|
|
8
8
|
import { MARK_PRICE_PRECISION, TEN } from '../constants/numericConstants';
|
|
9
9
|
import { OracleClient, OraclePriceData } from './types';
|
|
10
10
|
import { Wallet } from '../wallet';
|
|
@@ -48,11 +48,16 @@ export class SwitchboardClient implements OracleClient {
|
|
|
48
48
|
.stdDeviation as SwitchboardDecimal
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
+
const hasSufficientNumberOfDataPoints =
|
|
52
|
+
aggregatorAccountData.latestConfirmedRound.numSuccess >=
|
|
53
|
+
aggregatorAccountData.minOracleResults;
|
|
54
|
+
|
|
51
55
|
const slot: BN = aggregatorAccountData.latestConfirmedRound.roundOpenSlot;
|
|
52
56
|
return {
|
|
53
57
|
price,
|
|
54
58
|
slot,
|
|
55
59
|
confidence,
|
|
60
|
+
hasSufficientNumberOfDataPoints,
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -74,7 +79,7 @@ async function getSwitchboardProgram(
|
|
|
74
79
|
const DEFAULT_KEYPAIR = Keypair.fromSeed(new Uint8Array(32).fill(1));
|
|
75
80
|
const programId = getSwitchboardPid(env);
|
|
76
81
|
const wallet = new Wallet(DEFAULT_KEYPAIR);
|
|
77
|
-
const provider = new
|
|
82
|
+
const provider = new AnchorProvider(connection, wallet, {});
|
|
78
83
|
|
|
79
84
|
return new Program(switchboardV2Idl as Idl, programId, provider);
|
|
80
85
|
}
|
package/src/oracles/types.ts
CHANGED
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
Transaction,
|
|
6
6
|
TransactionSignature,
|
|
7
7
|
} from '@solana/web3.js';
|
|
8
|
-
import {
|
|
8
|
+
import { AnchorProvider } from '@project-serum/anchor';
|
|
9
9
|
|
|
10
10
|
export class DefaultTxSender implements TxSender {
|
|
11
|
-
provider:
|
|
11
|
+
provider: AnchorProvider;
|
|
12
12
|
|
|
13
|
-
public constructor(provider:
|
|
13
|
+
public constructor(provider: AnchorProvider) {
|
|
14
14
|
this.provider = provider;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -19,6 +19,6 @@ export class DefaultTxSender implements TxSender {
|
|
|
19
19
|
additionalSigners?: Array<Signer>,
|
|
20
20
|
opts?: ConfirmOptions
|
|
21
21
|
): Promise<TransactionSignature> {
|
|
22
|
-
return this.provider.
|
|
22
|
+
return this.provider.sendAndConfirm(tx, additionalSigners, opts);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
TransactionSignature,
|
|
11
11
|
Connection,
|
|
12
12
|
} from '@solana/web3.js';
|
|
13
|
-
import {
|
|
13
|
+
import { AnchorProvider } from '@project-serum/anchor';
|
|
14
14
|
import assert from 'assert';
|
|
15
15
|
import bs58 from 'bs58';
|
|
16
16
|
|
|
@@ -22,13 +22,13 @@ type ResolveReference = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export class RetryTxSender implements TxSender {
|
|
25
|
-
provider:
|
|
25
|
+
provider: AnchorProvider;
|
|
26
26
|
timeout: number;
|
|
27
27
|
retrySleep: number;
|
|
28
28
|
additionalConnections: Connection[];
|
|
29
29
|
|
|
30
30
|
public constructor(
|
|
31
|
-
provider:
|
|
31
|
+
provider: AnchorProvider,
|
|
32
32
|
timeout?: number,
|
|
33
33
|
retrySleep?: number,
|
|
34
34
|
additionalConnections = new Array<Connection>()
|