@drift-labs/sdk 2.49.0-beta.5 → 2.49.0-beta.7
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.js +12 -4
- package/package.json +1 -1
- package/src/driftClient.ts +13 -4
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.49.0-beta.
|
|
1
|
+
2.49.0-beta.7
|
package/lib/driftClient.js
CHANGED
|
@@ -421,7 +421,7 @@ class DriftClient {
|
|
|
421
421
|
}
|
|
422
422
|
return result;
|
|
423
423
|
}
|
|
424
|
-
async initializeUserAccount(subAccountId = 0, name
|
|
424
|
+
async initializeUserAccount(subAccountId = 0, name, referrerInfo) {
|
|
425
425
|
const initializeIxs = [];
|
|
426
426
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
|
427
427
|
if (subAccountId === 0) {
|
|
@@ -435,7 +435,7 @@ class DriftClient {
|
|
|
435
435
|
await this.addUser(subAccountId);
|
|
436
436
|
return [txSig, userAccountPublicKey];
|
|
437
437
|
}
|
|
438
|
-
async getInitializeUserInstructions(subAccountId = 0, name
|
|
438
|
+
async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
|
|
439
439
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
440
440
|
const remainingAccounts = new Array();
|
|
441
441
|
if (referrerInfo !== undefined) {
|
|
@@ -459,6 +459,14 @@ class DriftClient {
|
|
|
459
459
|
isSigner: false,
|
|
460
460
|
});
|
|
461
461
|
}
|
|
462
|
+
if (name === undefined) {
|
|
463
|
+
if (subAccountId === 0) {
|
|
464
|
+
name = userName_1.DEFAULT_USER_NAME;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
name = `Subaccount ${subAccountId + 1}`;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
462
470
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
463
471
|
const initializeUserAccountIx = await this.program.instruction.initializeUser(subAccountId, nameBuffer, {
|
|
464
472
|
accounts: {
|
|
@@ -975,7 +983,7 @@ class DriftClient {
|
|
|
975
983
|
return txSig;
|
|
976
984
|
}
|
|
977
985
|
async getDepositInstruction(amount, marketIndex, userTokenAccount, subAccountId, reduceOnly = false, userInitialized = true) {
|
|
978
|
-
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId);
|
|
986
|
+
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId);
|
|
979
987
|
let remainingAccounts = [];
|
|
980
988
|
if (userInitialized) {
|
|
981
989
|
remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1055,7 +1063,7 @@ class DriftClient {
|
|
|
1055
1063
|
* @param fromSubAccountId
|
|
1056
1064
|
* @returns
|
|
1057
1065
|
*/
|
|
1058
|
-
async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name
|
|
1066
|
+
async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, txParams) {
|
|
1059
1067
|
var _a;
|
|
1060
1068
|
const ixs = [];
|
|
1061
1069
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -710,7 +710,7 @@ export class DriftClient {
|
|
|
710
710
|
|
|
711
711
|
public async initializeUserAccount(
|
|
712
712
|
subAccountId = 0,
|
|
713
|
-
name
|
|
713
|
+
name?: string,
|
|
714
714
|
referrerInfo?: ReferrerInfo
|
|
715
715
|
): Promise<[TransactionSignature, PublicKey]> {
|
|
716
716
|
const initializeIxs = [];
|
|
@@ -729,6 +729,7 @@ export class DriftClient {
|
|
|
729
729
|
initializeIxs.push(await this.getInitializeUserStatsIx());
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
|
+
|
|
732
733
|
initializeIxs.push(initializeUserAccountIx);
|
|
733
734
|
const tx = await this.buildTransaction(initializeIxs);
|
|
734
735
|
|
|
@@ -741,7 +742,7 @@ export class DriftClient {
|
|
|
741
742
|
|
|
742
743
|
async getInitializeUserInstructions(
|
|
743
744
|
subAccountId = 0,
|
|
744
|
-
name
|
|
745
|
+
name?: string,
|
|
745
746
|
referrerInfo?: ReferrerInfo
|
|
746
747
|
): Promise<[PublicKey, TransactionInstruction]> {
|
|
747
748
|
const userAccountPublicKey = await getUserAccountPublicKey(
|
|
@@ -777,6 +778,14 @@ export class DriftClient {
|
|
|
777
778
|
});
|
|
778
779
|
}
|
|
779
780
|
|
|
781
|
+
if (name === undefined) {
|
|
782
|
+
if (subAccountId === 0) {
|
|
783
|
+
name = DEFAULT_USER_NAME;
|
|
784
|
+
} else {
|
|
785
|
+
name = `Subaccount ${subAccountId + 1}`;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
780
789
|
const nameBuffer = encodeName(name);
|
|
781
790
|
const initializeUserAccountIx =
|
|
782
791
|
await this.program.instruction.initializeUser(subAccountId, nameBuffer, {
|
|
@@ -1677,7 +1686,7 @@ export class DriftClient {
|
|
|
1677
1686
|
const userAccountPublicKey = await getUserAccountPublicKey(
|
|
1678
1687
|
this.program.programId,
|
|
1679
1688
|
this.authority,
|
|
1680
|
-
subAccountId
|
|
1689
|
+
subAccountId ?? this.activeSubAccountId
|
|
1681
1690
|
);
|
|
1682
1691
|
|
|
1683
1692
|
let remainingAccounts = [];
|
|
@@ -1809,7 +1818,7 @@ export class DriftClient {
|
|
|
1809
1818
|
userTokenAccount: PublicKey,
|
|
1810
1819
|
marketIndex = 0,
|
|
1811
1820
|
subAccountId = 0,
|
|
1812
|
-
name
|
|
1821
|
+
name?: string,
|
|
1813
1822
|
fromSubAccountId?: number,
|
|
1814
1823
|
referrerInfo?: ReferrerInfo,
|
|
1815
1824
|
txParams?: TxParams
|