@drift-labs/sdk 2.49.0-beta.13 → 2.49.0-beta.15
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 -1
- package/lib/driftClient.js +28 -7
- package/lib/orderSubscriber/OrderSubscriber.js +1 -1
- package/lib/orderSubscriber/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/driftClient.ts +48 -7
- package/src/orderSubscriber/OrderSubscriber.ts +2 -1
- package/src/orderSubscriber/types.ts +2 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.49.0-beta.
|
|
1
|
+
2.49.0-beta.15
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -228,9 +228,12 @@ export declare class DriftClient {
|
|
|
228
228
|
* @param subAccountId
|
|
229
229
|
* @param name
|
|
230
230
|
* @param fromSubAccountId
|
|
231
|
+
* @param referrerInfo
|
|
232
|
+
* @param donateAmount
|
|
233
|
+
* @param txParams
|
|
231
234
|
* @returns
|
|
232
235
|
*/
|
|
233
|
-
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
|
|
236
|
+
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
|
|
234
237
|
initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
235
238
|
/**
|
|
236
239
|
* Withdraws from a user account. If deposit doesn't already exist, creates a borrow
|
|
@@ -619,6 +622,7 @@ export declare class DriftClient {
|
|
|
619
622
|
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
620
623
|
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
621
624
|
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
625
|
+
getDepositIntoSpotMarketRevenuePoolIx(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
622
626
|
depositIntoSpotMarketRevenuePool(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
623
627
|
getPerpMarketExtendedInfo(marketIndex: number): PerpMarketExtendedInfo;
|
|
624
628
|
/**
|
package/lib/driftClient.js
CHANGED
|
@@ -1061,9 +1061,12 @@ class DriftClient {
|
|
|
1061
1061
|
* @param subAccountId
|
|
1062
1062
|
* @param name
|
|
1063
1063
|
* @param fromSubAccountId
|
|
1064
|
+
* @param referrerInfo
|
|
1065
|
+
* @param donateAmount
|
|
1066
|
+
* @param txParams
|
|
1064
1067
|
* @returns
|
|
1065
1068
|
*/
|
|
1066
|
-
async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, txParams) {
|
|
1069
|
+
async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, txParams) {
|
|
1067
1070
|
var _a;
|
|
1068
1071
|
const ixs = [];
|
|
1069
1072
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
|
@@ -1083,10 +1086,19 @@ class DriftClient {
|
|
|
1083
1086
|
const isFromSubaccount = fromSubAccountId !== null &&
|
|
1084
1087
|
fromSubAccountId !== undefined &&
|
|
1085
1088
|
!isNaN(fromSubAccountId);
|
|
1086
|
-
|
|
1089
|
+
donateAmount = donateAmount ? donateAmount : numericConstants_1.ZERO;
|
|
1090
|
+
const createWSOLTokenAccount = (isSolMarket &&
|
|
1091
|
+
userTokenAccount.equals(authority) &&
|
|
1092
|
+
!isFromSubaccount) ||
|
|
1093
|
+
!donateAmount.eq(numericConstants_1.ZERO);
|
|
1094
|
+
const wSolAmount = isSolMarket ? amount.add(donateAmount) : donateAmount;
|
|
1095
|
+
let wsolTokenAccount;
|
|
1087
1096
|
if (createWSOLTokenAccount) {
|
|
1088
|
-
const { ixs: startIxs, pubkey } = await this.getWrappedSolAccountCreationIxs(
|
|
1089
|
-
|
|
1097
|
+
const { ixs: startIxs, pubkey } = await this.getWrappedSolAccountCreationIxs(wSolAmount, true);
|
|
1098
|
+
wsolTokenAccount = pubkey;
|
|
1099
|
+
if (isSolMarket) {
|
|
1100
|
+
userTokenAccount = pubkey;
|
|
1101
|
+
}
|
|
1090
1102
|
ixs.push(...startIxs);
|
|
1091
1103
|
}
|
|
1092
1104
|
const depositCollateralIx = isFromSubaccount
|
|
@@ -1098,9 +1110,13 @@ class DriftClient {
|
|
|
1098
1110
|
}
|
|
1099
1111
|
}
|
|
1100
1112
|
ixs.push(initializeUserAccountIx, depositCollateralIx);
|
|
1113
|
+
if (!donateAmount.eq(numericConstants_1.ZERO)) {
|
|
1114
|
+
const donateIx = await this.getDepositIntoSpotMarketRevenuePoolIx(1, donateAmount, wsolTokenAccount);
|
|
1115
|
+
ixs.push(donateIx);
|
|
1116
|
+
}
|
|
1101
1117
|
// Close the wrapped sol account at the end of the transaction
|
|
1102
1118
|
if (createWSOLTokenAccount) {
|
|
1103
|
-
ixs.push((0, spl_token_1.createCloseAccountInstruction)(
|
|
1119
|
+
ixs.push((0, spl_token_1.createCloseAccountInstruction)(wsolTokenAccount, authority, authority, []));
|
|
1104
1120
|
}
|
|
1105
1121
|
const tx = await this.buildTransaction(ixs, params);
|
|
1106
1122
|
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
@@ -3237,9 +3253,9 @@ class DriftClient {
|
|
|
3237
3253
|
remainingAccounts: remainingAccounts,
|
|
3238
3254
|
});
|
|
3239
3255
|
}
|
|
3240
|
-
async
|
|
3256
|
+
async getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey) {
|
|
3241
3257
|
const spotMarket = await this.getSpotMarketAccount(marketIndex);
|
|
3242
|
-
const
|
|
3258
|
+
const ix = await this.program.instruction.depositIntoSpotMarketRevenuePool(amount, {
|
|
3243
3259
|
accounts: {
|
|
3244
3260
|
state: await this.getStatePublicKey(),
|
|
3245
3261
|
spotMarket: spotMarket.pubkey,
|
|
@@ -3249,6 +3265,11 @@ class DriftClient {
|
|
|
3249
3265
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3250
3266
|
},
|
|
3251
3267
|
});
|
|
3268
|
+
return ix;
|
|
3269
|
+
}
|
|
3270
|
+
async depositIntoSpotMarketRevenuePool(marketIndex, amount, userTokenAccountPublicKey) {
|
|
3271
|
+
const ix = await this.getDepositIntoSpotMarketRevenuePoolIx(marketIndex, amount, userTokenAccountPublicKey);
|
|
3272
|
+
const tx = await this.buildTransaction([ix]);
|
|
3252
3273
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3253
3274
|
return txSig;
|
|
3254
3275
|
}
|
|
@@ -107,7 +107,7 @@ class OrderSubscriber {
|
|
|
107
107
|
order.slot.toNumber() <= slot;
|
|
108
108
|
});
|
|
109
109
|
if (newOrders.length > 0) {
|
|
110
|
-
this.eventEmitter.emit('onUpdate', userAccount, newOrders, new web3_js_1.PublicKey(key), slot);
|
|
110
|
+
this.eventEmitter.emit('onUpdate', userAccount, newOrders, new web3_js_1.PublicKey(key), slot, dataType);
|
|
111
111
|
}
|
|
112
112
|
if (userAccount.hasOpenOrder) {
|
|
113
113
|
this.usersAccounts.set(key, { slot, userAccount });
|
|
@@ -15,5 +15,5 @@ export type OrderSubscriberConfig = {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
export interface OrderSubscriberEvents {
|
|
18
|
-
onUpdate: (account: UserAccount, updatedOrders: Order[], pubkey: PublicKey, slot: number) => void;
|
|
18
|
+
onUpdate: (account: UserAccount, updatedOrders: Order[], pubkey: PublicKey, slot: number, dataType: 'raw' | 'decoded') => void;
|
|
19
19
|
}
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -1811,6 +1811,9 @@ export class DriftClient {
|
|
|
1811
1811
|
* @param subAccountId
|
|
1812
1812
|
* @param name
|
|
1813
1813
|
* @param fromSubAccountId
|
|
1814
|
+
* @param referrerInfo
|
|
1815
|
+
* @param donateAmount
|
|
1816
|
+
* @param txParams
|
|
1814
1817
|
* @returns
|
|
1815
1818
|
*/
|
|
1816
1819
|
public async initializeUserAccountAndDepositCollateral(
|
|
@@ -1821,6 +1824,7 @@ export class DriftClient {
|
|
|
1821
1824
|
name?: string,
|
|
1822
1825
|
fromSubAccountId?: number,
|
|
1823
1826
|
referrerInfo?: ReferrerInfo,
|
|
1827
|
+
donateAmount?: BN,
|
|
1824
1828
|
txParams?: TxParams
|
|
1825
1829
|
): Promise<[TransactionSignature, PublicKey]> {
|
|
1826
1830
|
const ixs = [];
|
|
@@ -1856,14 +1860,26 @@ export class DriftClient {
|
|
|
1856
1860
|
fromSubAccountId !== undefined &&
|
|
1857
1861
|
!isNaN(fromSubAccountId);
|
|
1858
1862
|
|
|
1863
|
+
donateAmount = donateAmount ? donateAmount : ZERO;
|
|
1864
|
+
|
|
1859
1865
|
const createWSOLTokenAccount =
|
|
1860
|
-
isSolMarket &&
|
|
1866
|
+
(isSolMarket &&
|
|
1867
|
+
userTokenAccount.equals(authority) &&
|
|
1868
|
+
!isFromSubaccount) ||
|
|
1869
|
+
!donateAmount.eq(ZERO);
|
|
1861
1870
|
|
|
1871
|
+
const wSolAmount = isSolMarket ? amount.add(donateAmount) : donateAmount;
|
|
1872
|
+
|
|
1873
|
+
let wsolTokenAccount: PublicKey;
|
|
1862
1874
|
if (createWSOLTokenAccount) {
|
|
1863
1875
|
const { ixs: startIxs, pubkey } =
|
|
1864
|
-
await this.getWrappedSolAccountCreationIxs(
|
|
1876
|
+
await this.getWrappedSolAccountCreationIxs(wSolAmount, true);
|
|
1865
1877
|
|
|
1866
|
-
|
|
1878
|
+
wsolTokenAccount = pubkey;
|
|
1879
|
+
|
|
1880
|
+
if (isSolMarket) {
|
|
1881
|
+
userTokenAccount = pubkey;
|
|
1882
|
+
}
|
|
1867
1883
|
|
|
1868
1884
|
ixs.push(...startIxs);
|
|
1869
1885
|
}
|
|
@@ -1893,11 +1909,21 @@ export class DriftClient {
|
|
|
1893
1909
|
}
|
|
1894
1910
|
ixs.push(initializeUserAccountIx, depositCollateralIx);
|
|
1895
1911
|
|
|
1912
|
+
if (!donateAmount.eq(ZERO)) {
|
|
1913
|
+
const donateIx = await this.getDepositIntoSpotMarketRevenuePoolIx(
|
|
1914
|
+
1,
|
|
1915
|
+
donateAmount,
|
|
1916
|
+
wsolTokenAccount
|
|
1917
|
+
);
|
|
1918
|
+
|
|
1919
|
+
ixs.push(donateIx);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1896
1922
|
// Close the wrapped sol account at the end of the transaction
|
|
1897
1923
|
if (createWSOLTokenAccount) {
|
|
1898
1924
|
ixs.push(
|
|
1899
1925
|
createCloseAccountInstruction(
|
|
1900
|
-
|
|
1926
|
+
wsolTokenAccount,
|
|
1901
1927
|
authority,
|
|
1902
1928
|
authority,
|
|
1903
1929
|
[]
|
|
@@ -5995,13 +6021,13 @@ export class DriftClient {
|
|
|
5995
6021
|
);
|
|
5996
6022
|
}
|
|
5997
6023
|
|
|
5998
|
-
public async
|
|
6024
|
+
public async getDepositIntoSpotMarketRevenuePoolIx(
|
|
5999
6025
|
marketIndex: number,
|
|
6000
6026
|
amount: BN,
|
|
6001
6027
|
userTokenAccountPublicKey: PublicKey
|
|
6002
|
-
): Promise<
|
|
6028
|
+
): Promise<TransactionInstruction> {
|
|
6003
6029
|
const spotMarket = await this.getSpotMarketAccount(marketIndex);
|
|
6004
|
-
const
|
|
6030
|
+
const ix = await this.program.instruction.depositIntoSpotMarketRevenuePool(
|
|
6005
6031
|
amount,
|
|
6006
6032
|
{
|
|
6007
6033
|
accounts: {
|
|
@@ -6015,6 +6041,21 @@ export class DriftClient {
|
|
|
6015
6041
|
}
|
|
6016
6042
|
);
|
|
6017
6043
|
|
|
6044
|
+
return ix;
|
|
6045
|
+
}
|
|
6046
|
+
|
|
6047
|
+
public async depositIntoSpotMarketRevenuePool(
|
|
6048
|
+
marketIndex: number,
|
|
6049
|
+
amount: BN,
|
|
6050
|
+
userTokenAccountPublicKey: PublicKey
|
|
6051
|
+
): Promise<TransactionSignature> {
|
|
6052
|
+
const ix = await this.getDepositIntoSpotMarketRevenuePoolIx(
|
|
6053
|
+
marketIndex,
|
|
6054
|
+
amount,
|
|
6055
|
+
userTokenAccountPublicKey
|
|
6056
|
+
);
|
|
6057
|
+
const tx = await this.buildTransaction([ix]);
|
|
6058
|
+
|
|
6018
6059
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
6019
6060
|
return txSig;
|
|
6020
6061
|
}
|