@drift-labs/sdk 2.86.0-beta.22 → 2.86.0-beta.23
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/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/driftClient.ts
CHANGED
|
@@ -132,7 +132,6 @@ import { isOracleValid, trimVaaSignatures } from './math/oracles';
|
|
|
132
132
|
import { TxHandler } from './tx/txHandler';
|
|
133
133
|
import {
|
|
134
134
|
wormholeCoreBridgeIdl,
|
|
135
|
-
pythSolanaReceiverIdl,
|
|
136
135
|
DEFAULT_RECEIVER_PROGRAM_ID,
|
|
137
136
|
} from '@pythnetwork/pyth-solana-receiver';
|
|
138
137
|
import { parseAccumulatorUpdateData } from '@pythnetwork/price-service-sdk';
|
|
@@ -145,6 +144,7 @@ import { WormholeCoreBridgeSolana } from '@pythnetwork/pyth-solana-receiver/lib/
|
|
|
145
144
|
import { PythSolanaReceiver } from '@pythnetwork/pyth-solana-receiver/lib/idl/pyth_solana_receiver';
|
|
146
145
|
import { getFeedIdUint8Array, trimFeedId } from './util/pythPullOracleUtils';
|
|
147
146
|
import { isVersionedTransaction } from './tx/utils';
|
|
147
|
+
import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json';
|
|
148
148
|
|
|
149
149
|
type RemainingAccountParams = {
|
|
150
150
|
userAccounts: UserAccount[];
|
|
@@ -6913,7 +6913,7 @@ export class DriftClient {
|
|
|
6913
6913
|
public getReceiverProgram(): Program<PythSolanaReceiver> {
|
|
6914
6914
|
if (this.receiverProgram === undefined) {
|
|
6915
6915
|
this.receiverProgram = new Program(
|
|
6916
|
-
pythSolanaReceiverIdl,
|
|
6916
|
+
pythSolanaReceiverIdl as PythSolanaReceiver,
|
|
6917
6917
|
DEFAULT_RECEIVER_PROGRAM_ID,
|
|
6918
6918
|
this.provider
|
|
6919
6919
|
);
|
|
@@ -6935,12 +6935,25 @@ export class DriftClient {
|
|
|
6935
6935
|
return txSig;
|
|
6936
6936
|
}
|
|
6937
6937
|
|
|
6938
|
+
public async postMultiPythPullOracleUpdatesAtomic(
|
|
6939
|
+
vaaString: string,
|
|
6940
|
+
feedIds: string[]
|
|
6941
|
+
): Promise<TransactionSignature> {
|
|
6942
|
+
const postIxs = await this.getPostPythPullOracleUpdateAtomicIxs(
|
|
6943
|
+
vaaString,
|
|
6944
|
+
feedIds
|
|
6945
|
+
);
|
|
6946
|
+
const tx = await this.buildTransaction(postIxs);
|
|
6947
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6948
|
+
|
|
6949
|
+
return txSig;
|
|
6950
|
+
}
|
|
6951
|
+
|
|
6938
6952
|
public async getPostPythPullOracleUpdateAtomicIxs(
|
|
6939
6953
|
vaaString: string,
|
|
6940
|
-
|
|
6954
|
+
feedIds: string | string[],
|
|
6941
6955
|
numSignatures = 2
|
|
6942
6956
|
): Promise<TransactionInstruction[]> {
|
|
6943
|
-
feedId = trimFeedId(feedId);
|
|
6944
6957
|
const accumulatorUpdateData = parseAccumulatorUpdateData(
|
|
6945
6958
|
Buffer.from(vaaString, 'base64')
|
|
6946
6959
|
);
|
|
@@ -6955,23 +6968,61 @@ export class DriftClient {
|
|
|
6955
6968
|
);
|
|
6956
6969
|
|
|
6957
6970
|
const postIxs: TransactionInstruction[] = [];
|
|
6958
|
-
|
|
6971
|
+
if (accumulatorUpdateData.updates.length > 1) {
|
|
6972
|
+
const encodedParams = this.getReceiverProgram().coder.types.encode(
|
|
6973
|
+
'PostMultiUpdatesAtomicParams',
|
|
6974
|
+
{
|
|
6975
|
+
vaa: trimmedVaa,
|
|
6976
|
+
merklePriceUpdates: accumulatorUpdateData.updates,
|
|
6977
|
+
}
|
|
6978
|
+
);
|
|
6979
|
+
const feedIdsToUse: string[] =
|
|
6980
|
+
typeof feedIds === 'string' ? [feedIds] : feedIds;
|
|
6981
|
+
const pubkeys = feedIdsToUse.map((feedId) => {
|
|
6982
|
+
return getPythPullOraclePublicKey(
|
|
6983
|
+
this.program.programId,
|
|
6984
|
+
getFeedIdUint8Array(feedId)
|
|
6985
|
+
);
|
|
6986
|
+
});
|
|
6987
|
+
|
|
6988
|
+
const remainingAccounts: Array<AccountMeta> = pubkeys.map((pubkey) => {
|
|
6989
|
+
return {
|
|
6990
|
+
pubkey,
|
|
6991
|
+
isSigner: false,
|
|
6992
|
+
isWritable: true,
|
|
6993
|
+
};
|
|
6994
|
+
});
|
|
6995
|
+
postIxs.push(
|
|
6996
|
+
this.program.instruction.postMultiPythPullOracleUpdatesAtomic(
|
|
6997
|
+
encodedParams,
|
|
6998
|
+
{
|
|
6999
|
+
accounts: {
|
|
7000
|
+
keeper: this.wallet.publicKey,
|
|
7001
|
+
pythSolanaReceiver: DRIFT_ORACLE_RECEIVER_ID,
|
|
7002
|
+
guardianSet,
|
|
7003
|
+
},
|
|
7004
|
+
remainingAccounts,
|
|
7005
|
+
}
|
|
7006
|
+
)
|
|
7007
|
+
);
|
|
7008
|
+
} else {
|
|
7009
|
+
let feedIdToUse = typeof feedIds === 'string' ? feedIds : feedIds[0];
|
|
7010
|
+
feedIdToUse = trimFeedId(feedIdToUse);
|
|
6959
7011
|
postIxs.push(
|
|
6960
7012
|
await this.getSinglePostPythPullOracleAtomicIx(
|
|
6961
7013
|
{
|
|
6962
7014
|
vaa: trimmedVaa,
|
|
6963
|
-
merklePriceUpdate:
|
|
7015
|
+
merklePriceUpdate: accumulatorUpdateData.updates[0],
|
|
6964
7016
|
},
|
|
6965
|
-
|
|
7017
|
+
feedIdToUse,
|
|
6966
7018
|
guardianSet
|
|
6967
7019
|
)
|
|
6968
7020
|
);
|
|
6969
7021
|
}
|
|
6970
|
-
|
|
6971
7022
|
return postIxs;
|
|
6972
7023
|
}
|
|
6973
7024
|
|
|
6974
|
-
|
|
7025
|
+
private async getSinglePostPythPullOracleAtomicIx(
|
|
6975
7026
|
params: {
|
|
6976
7027
|
vaa: Buffer;
|
|
6977
7028
|
merklePriceUpdate: {
|
|
@@ -7083,7 +7134,7 @@ export class DriftClient {
|
|
|
7083
7134
|
);
|
|
7084
7135
|
}
|
|
7085
7136
|
|
|
7086
|
-
|
|
7137
|
+
private async getBuildEncodedVaaIxs(
|
|
7087
7138
|
vaa: Buffer,
|
|
7088
7139
|
guardianSet: PublicKey
|
|
7089
7140
|
): Promise<[TransactionInstruction[], Keypair]> {
|
package/src/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": {
|