@drift-labs/sdk 2.86.0-beta.22 → 2.86.0-beta.24
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/driftClient.d.ts +5 -10
- package/lib/driftClient.js +39 -6
- package/lib/idl/drift.json +41 -0
- package/lib/idl/pyth_solana_receiver.json +628 -0
- package/lib/types.d.ts +1 -1
- package/lib/user.js +6 -1
- package/package.json +1 -1
- package/src/driftClient.ts +61 -10
- package/src/idl/drift.json +41 -0
- package/src/idl/pyth_solana_receiver.json +628 -0
- package/src/types.ts +1 -1
- package/src/user.ts +18 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.86.0-beta.
|
|
1
|
+
2.86.0-beta.24
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
5
5
|
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, PhoenixV1FulfillmentConfigAccount, ModifyOrderPolicy, SwapReduceOnly, SettlePnlMode, SignedTxData, MappedRecord } from './types';
|
|
6
6
|
import * as anchor from '@coral-xyz/anchor';
|
|
7
|
-
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta,
|
|
7
|
+
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount, TransactionVersion, VersionedTransaction, BlockhashWithExpiryBlockHeight } from '@solana/web3.js';
|
|
8
8
|
import { TokenFaucet } from './tokenFaucet';
|
|
9
9
|
import { EventEmitter } from 'events';
|
|
10
10
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
@@ -712,14 +712,9 @@ export declare class DriftClient {
|
|
|
712
712
|
} | undefined;
|
|
713
713
|
getReceiverProgram(): Program<PythSolanaReceiver>;
|
|
714
714
|
postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
merklePriceUpdate: {
|
|
719
|
-
message: Buffer;
|
|
720
|
-
proof: number[][];
|
|
721
|
-
};
|
|
722
|
-
}, feedId: string, guardianSet: PublicKey): Promise<TransactionInstruction>;
|
|
715
|
+
postMultiPythPullOracleUpdatesAtomic(vaaString: string, feedIds: string[]): Promise<TransactionSignature>;
|
|
716
|
+
getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedIds: string | string[], numSignatures?: number): Promise<TransactionInstruction[]>;
|
|
717
|
+
private getSinglePostPythPullOracleAtomicIx;
|
|
723
718
|
updatePythPullOracle(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
724
719
|
getUpdatePythPullOracleIxs(params: {
|
|
725
720
|
merklePriceUpdate: {
|
|
@@ -727,7 +722,7 @@ export declare class DriftClient {
|
|
|
727
722
|
proof: number[][];
|
|
728
723
|
};
|
|
729
724
|
}, feedId: string, encodedVaaAddress: PublicKey): Promise<TransactionInstruction>;
|
|
730
|
-
getBuildEncodedVaaIxs
|
|
725
|
+
private getBuildEncodedVaaIxs;
|
|
731
726
|
private handleSignedTransaction;
|
|
732
727
|
private handlePreSignedTransaction;
|
|
733
728
|
private isVersionedTransaction;
|
package/lib/driftClient.js
CHANGED
|
@@ -64,6 +64,7 @@ const address_1 = require("@pythnetwork/pyth-solana-receiver/lib/address");
|
|
|
64
64
|
const config_2 = require("./config");
|
|
65
65
|
const pythPullOracleUtils_1 = require("./util/pythPullOracleUtils");
|
|
66
66
|
const utils_2 = require("./tx/utils");
|
|
67
|
+
const pyth_solana_receiver_json_1 = __importDefault(require("./idl/pyth_solana_receiver.json"));
|
|
67
68
|
/**
|
|
68
69
|
* # DriftClient
|
|
69
70
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -3641,7 +3642,7 @@ class DriftClient {
|
|
|
3641
3642
|
}
|
|
3642
3643
|
getReceiverProgram() {
|
|
3643
3644
|
if (this.receiverProgram === undefined) {
|
|
3644
|
-
this.receiverProgram = new anchor_1.Program(
|
|
3645
|
+
this.receiverProgram = new anchor_1.Program(pyth_solana_receiver_json_1.default, pyth_solana_receiver_1.DEFAULT_RECEIVER_PROGRAM_ID, this.provider);
|
|
3645
3646
|
}
|
|
3646
3647
|
return this.receiverProgram;
|
|
3647
3648
|
}
|
|
@@ -3651,18 +3652,50 @@ class DriftClient {
|
|
|
3651
3652
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3652
3653
|
return txSig;
|
|
3653
3654
|
}
|
|
3654
|
-
async
|
|
3655
|
-
|
|
3655
|
+
async postMultiPythPullOracleUpdatesAtomic(vaaString, feedIds) {
|
|
3656
|
+
const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(vaaString, feedIds);
|
|
3657
|
+
const tx = await this.buildTransaction(postIxs);
|
|
3658
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3659
|
+
return txSig;
|
|
3660
|
+
}
|
|
3661
|
+
async getPostPythPullOracleUpdateAtomicIxs(vaaString, feedIds, numSignatures = 2) {
|
|
3656
3662
|
const accumulatorUpdateData = (0, price_service_sdk_1.parseAccumulatorUpdateData)(Buffer.from(vaaString, 'base64'));
|
|
3657
3663
|
const guardianSetIndex = accumulatorUpdateData.vaa.readUInt32BE(1);
|
|
3658
3664
|
const guardianSet = (0, address_1.getGuardianSetPda)(guardianSetIndex, address_1.DEFAULT_WORMHOLE_PROGRAM_ID);
|
|
3659
3665
|
const trimmedVaa = (0, oracles_1.trimVaaSignatures)(accumulatorUpdateData.vaa, numSignatures);
|
|
3660
3666
|
const postIxs = [];
|
|
3661
|
-
|
|
3667
|
+
if (accumulatorUpdateData.updates.length > 1) {
|
|
3668
|
+
const encodedParams = this.getReceiverProgram().coder.types.encode('PostMultiUpdatesAtomicParams', {
|
|
3669
|
+
vaa: trimmedVaa,
|
|
3670
|
+
merklePriceUpdates: accumulatorUpdateData.updates,
|
|
3671
|
+
});
|
|
3672
|
+
const feedIdsToUse = typeof feedIds === 'string' ? [feedIds] : feedIds;
|
|
3673
|
+
const pubkeys = feedIdsToUse.map((feedId) => {
|
|
3674
|
+
return (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, (0, pythPullOracleUtils_1.getFeedIdUint8Array)(feedId));
|
|
3675
|
+
});
|
|
3676
|
+
const remainingAccounts = pubkeys.map((pubkey) => {
|
|
3677
|
+
return {
|
|
3678
|
+
pubkey,
|
|
3679
|
+
isSigner: false,
|
|
3680
|
+
isWritable: true,
|
|
3681
|
+
};
|
|
3682
|
+
});
|
|
3683
|
+
postIxs.push(this.program.instruction.postMultiPythPullOracleUpdatesAtomic(encodedParams, {
|
|
3684
|
+
accounts: {
|
|
3685
|
+
keeper: this.wallet.publicKey,
|
|
3686
|
+
pythSolanaReceiver: config_2.DRIFT_ORACLE_RECEIVER_ID,
|
|
3687
|
+
guardianSet,
|
|
3688
|
+
},
|
|
3689
|
+
remainingAccounts,
|
|
3690
|
+
}));
|
|
3691
|
+
}
|
|
3692
|
+
else {
|
|
3693
|
+
let feedIdToUse = typeof feedIds === 'string' ? feedIds : feedIds[0];
|
|
3694
|
+
feedIdToUse = (0, pythPullOracleUtils_1.trimFeedId)(feedIdToUse);
|
|
3662
3695
|
postIxs.push(await this.getSinglePostPythPullOracleAtomicIx({
|
|
3663
3696
|
vaa: trimmedVaa,
|
|
3664
|
-
merklePriceUpdate:
|
|
3665
|
-
},
|
|
3697
|
+
merklePriceUpdate: accumulatorUpdateData.updates[0],
|
|
3698
|
+
}, feedIdToUse, guardianSet));
|
|
3666
3699
|
}
|
|
3667
3700
|
return postIxs;
|
|
3668
3701
|
}
|
package/lib/idl/drift.json
CHANGED
|
@@ -2663,6 +2663,32 @@
|
|
|
2663
2663
|
}
|
|
2664
2664
|
]
|
|
2665
2665
|
},
|
|
2666
|
+
{
|
|
2667
|
+
"name": "postMultiPythPullOracleUpdatesAtomic",
|
|
2668
|
+
"accounts": [
|
|
2669
|
+
{
|
|
2670
|
+
"name": "keeper",
|
|
2671
|
+
"isMut": true,
|
|
2672
|
+
"isSigner": true
|
|
2673
|
+
},
|
|
2674
|
+
{
|
|
2675
|
+
"name": "pythSolanaReceiver",
|
|
2676
|
+
"isMut": false,
|
|
2677
|
+
"isSigner": false
|
|
2678
|
+
},
|
|
2679
|
+
{
|
|
2680
|
+
"name": "guardianSet",
|
|
2681
|
+
"isMut": false,
|
|
2682
|
+
"isSigner": false
|
|
2683
|
+
}
|
|
2684
|
+
],
|
|
2685
|
+
"args": [
|
|
2686
|
+
{
|
|
2687
|
+
"name": "params",
|
|
2688
|
+
"type": "bytes"
|
|
2689
|
+
}
|
|
2690
|
+
]
|
|
2691
|
+
},
|
|
2666
2692
|
{
|
|
2667
2693
|
"name": "initialize",
|
|
2668
2694
|
"accounts": [
|
|
@@ -12512,6 +12538,21 @@
|
|
|
12512
12538
|
"code": 6275,
|
|
12513
12539
|
"name": "OracleWrongVaaOwner",
|
|
12514
12540
|
"msg": "Oracle vaa owner must be wormhole program"
|
|
12541
|
+
},
|
|
12542
|
+
{
|
|
12543
|
+
"code": 6276,
|
|
12544
|
+
"name": "OracleTooManyPriceAccountUpdates",
|
|
12545
|
+
"msg": "Multi updates must have 2 or fewer accounts passed in remaining accounts"
|
|
12546
|
+
},
|
|
12547
|
+
{
|
|
12548
|
+
"code": 6277,
|
|
12549
|
+
"name": "OracleMismatchedVaaAndPriceUpdates",
|
|
12550
|
+
"msg": "Don't have the same remaining accounts number and merkle price updates left"
|
|
12551
|
+
},
|
|
12552
|
+
{
|
|
12553
|
+
"code": 6278,
|
|
12554
|
+
"name": "OracleBadRemainingAccountPublicKey",
|
|
12555
|
+
"msg": "Remaining account passed is not a valid pda"
|
|
12515
12556
|
}
|
|
12516
12557
|
],
|
|
12517
12558
|
"metadata": {
|