@drift-labs/sdk 2.20.0-beta.1 → 2.20.0-beta.3

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.
@@ -16,3 +16,4 @@ export declare function getDriftSignerPublicKey(programId: PublicKey): PublicKey
16
16
  export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
17
17
  export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
18
18
  export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
19
+ export declare function getReferrerNamePublicKeySync(programId: PublicKey, nameBuffer: number[]): PublicKey;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getReferrerNamePublicKeySync = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@project-serum/anchor"));
29
29
  async function getDriftStateAccountPublicKeyAndNonce(programId) {
@@ -119,3 +119,10 @@ function getSerumFulfillmentConfigPublicKey(programId, market) {
119
119
  ], programId)[0];
120
120
  }
121
121
  exports.getSerumFulfillmentConfigPublicKey = getSerumFulfillmentConfigPublicKey;
122
+ function getReferrerNamePublicKeySync(programId, nameBuffer) {
123
+ return web3_js_1.PublicKey.findProgramAddressSync([
124
+ Buffer.from(anchor.utils.bytes.utf8.encode('referrer_name')),
125
+ Buffer.from(nameBuffer),
126
+ ], programId)[0];
127
+ }
128
+ exports.getReferrerNamePublicKeySync = getReferrerNamePublicKeySync;
@@ -54,6 +54,16 @@ exports.DevnetPerpMarkets = [
54
54
  launchTs: 1677068931000,
55
55
  oracleSource: __1.OracleSource.PYTH_1M,
56
56
  },
57
+ {
58
+ fullName: 'Polygon',
59
+ category: ['L2', 'Infra'],
60
+ symbol: 'MATIC-PERP',
61
+ baseAssetSymbol: 'MATIC',
62
+ marketIndex: 5,
63
+ oracle: new web3_js_1.PublicKey('FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur'),
64
+ launchTs: 1677690149000,
65
+ oracleSource: __1.OracleSource.PYTH,
66
+ },
57
67
  ];
58
68
  exports.MainnetPerpMarkets = [
59
69
  {
@@ -106,6 +116,16 @@ exports.MainnetPerpMarkets = [
106
116
  launchTs: 1677690149000,
107
117
  oracleSource: __1.OracleSource.PYTH_1M,
108
118
  },
119
+ {
120
+ fullName: 'Polygon',
121
+ category: ['L2', 'Infra'],
122
+ symbol: 'MATIC-PERP',
123
+ baseAssetSymbol: 'MATIC',
124
+ marketIndex: 5,
125
+ oracle: new web3_js_1.PublicKey('7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh'),
126
+ launchTs: 1677690149000,
127
+ oracleSource: __1.OracleSource.PYTH,
128
+ },
109
129
  ];
110
130
  exports.PerpMarkets = {
111
131
  devnet: exports.DevnetPerpMarkets,
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, OrderType, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, OrderTriggerCondition, PerpMarketExtendedInfo } from './types';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, OrderType, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo } from './types';
5
5
  import * as anchor from '@project-serum/anchor';
6
6
  import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount } from '@solana/web3.js';
7
7
  import { TokenFaucet } from './tokenFaucet';
@@ -96,6 +96,7 @@ export declare class DriftClient {
96
96
  initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
97
97
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
98
98
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
99
+ initializeReferrerName(name: string): Promise<TransactionSignature>;
99
100
  updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
100
101
  updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
101
102
  updateUserMarginTradingEnabled(marginTradingEnabled: boolean, subAccountId?: number): Promise<TransactionSignature>;
@@ -106,6 +107,7 @@ export declare class DriftClient {
106
107
  getUser(subAccountId?: number): User;
107
108
  getUsers(): User[];
108
109
  getUserStats(): UserStats;
110
+ fetchReferrerNameAccount(name: string): Promise<ReferrerNameAccount | undefined>;
109
111
  userStatsAccountPublicKey: PublicKey;
110
112
  getUserStatsAccountPublicKey(): PublicKey;
111
113
  getUserAccountPublicKey(): Promise<PublicKey>;
@@ -358,6 +358,24 @@ class DriftClient {
358
358
  },
359
359
  });
360
360
  }
361
+ async initializeReferrerName(name) {
362
+ const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, 0);
363
+ const nameBuffer = (0, userName_1.encodeName)(name);
364
+ const referrerNameAccountPublicKey = await (0, pda_1.getReferrerNamePublicKeySync)(this.program.programId, nameBuffer);
365
+ const tx = await this.program.transaction.initializeReferrerName(nameBuffer, {
366
+ accounts: {
367
+ referrerName: referrerNameAccountPublicKey,
368
+ user: userAccountPublicKey,
369
+ authority: this.wallet.publicKey,
370
+ userStats: this.getUserStatsAccountPublicKey(),
371
+ payer: this.wallet.publicKey,
372
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
373
+ systemProgram: anchor.web3.SystemProgram.programId,
374
+ },
375
+ });
376
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
377
+ return txSig;
378
+ }
361
379
  async updateUserName(name, subAccountId = 0) {
362
380
  const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
363
381
  const nameBuffer = (0, userName_1.encodeName)(name);
@@ -459,6 +477,11 @@ class DriftClient {
459
477
  getUserStats() {
460
478
  return this.userStats;
461
479
  }
480
+ async fetchReferrerNameAccount(name) {
481
+ const nameBuffer = (0, userName_1.encodeName)(name);
482
+ const referrerNameAccountPublicKey = (0, pda_1.getReferrerNamePublicKeySync)(this.program.programId, nameBuffer);
483
+ return (await this.program.account.referrerName.fetch(referrerNameAccountPublicKey));
484
+ }
462
485
  getUserStatsAccountPublicKey() {
463
486
  if (this.userStatsAccountPublicKey) {
464
487
  return this.userStatsAccountPublicKey;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.20.0-beta.1",
2
+ "version": "2.20.0-beta.3",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -93,6 +93,57 @@
93
93
  ],
94
94
  "args": []
95
95
  },
96
+ {
97
+ "name": "initializeReferrerName",
98
+ "accounts": [
99
+ {
100
+ "name": "referrerName",
101
+ "isMut": true,
102
+ "isSigner": false
103
+ },
104
+ {
105
+ "name": "user",
106
+ "isMut": true,
107
+ "isSigner": false
108
+ },
109
+ {
110
+ "name": "userStats",
111
+ "isMut": true,
112
+ "isSigner": false
113
+ },
114
+ {
115
+ "name": "authority",
116
+ "isMut": false,
117
+ "isSigner": true
118
+ },
119
+ {
120
+ "name": "payer",
121
+ "isMut": true,
122
+ "isSigner": true
123
+ },
124
+ {
125
+ "name": "rent",
126
+ "isMut": false,
127
+ "isSigner": false
128
+ },
129
+ {
130
+ "name": "systemProgram",
131
+ "isMut": false,
132
+ "isSigner": false
133
+ }
134
+ ],
135
+ "args": [
136
+ {
137
+ "name": "name",
138
+ "type": {
139
+ "array": [
140
+ "u8",
141
+ 32
142
+ ]
143
+ }
144
+ }
145
+ ]
146
+ },
96
147
  {
97
148
  "name": "deposit",
98
149
  "accounts": [
@@ -4607,6 +4658,35 @@
4607
4658
  }
4608
4659
  ]
4609
4660
  }
4661
+ },
4662
+ {
4663
+ "name": "ReferrerName",
4664
+ "type": {
4665
+ "kind": "struct",
4666
+ "fields": [
4667
+ {
4668
+ "name": "authority",
4669
+ "type": "publicKey"
4670
+ },
4671
+ {
4672
+ "name": "user",
4673
+ "type": "publicKey"
4674
+ },
4675
+ {
4676
+ "name": "userStats",
4677
+ "type": "publicKey"
4678
+ },
4679
+ {
4680
+ "name": "name",
4681
+ "type": {
4682
+ "array": [
4683
+ "u8",
4684
+ 32
4685
+ ]
4686
+ }
4687
+ }
4688
+ ]
4689
+ }
4610
4690
  }
4611
4691
  ],
4612
4692
  "types": [
@@ -6208,9 +6288,7 @@
6208
6288
  "name": "Match",
6209
6289
  "fields": [
6210
6290
  "publicKey",
6211
- {
6212
- "defined": "usize"
6213
- }
6291
+ "u16"
6214
6292
  ]
6215
6293
  }
6216
6294
  ]
package/lib/types.d.ts CHANGED
@@ -1010,6 +1010,12 @@ export type SerumV3FulfillmentConfigAccount = {
1010
1010
  serumOpenOrders: PublicKey;
1011
1011
  serumSignerNonce: BN;
1012
1012
  };
1013
+ export type ReferrerNameAccount = {
1014
+ name: number[];
1015
+ user: PublicKey;
1016
+ authority: PublicKey;
1017
+ userStats: PublicKey;
1018
+ };
1013
1019
  export type PerpMarketExtendedInfo = {
1014
1020
  marketIndex: number;
1015
1021
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.20.0-beta.1",
3
+ "version": "2.20.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -188,3 +188,16 @@ export function getSerumFulfillmentConfigPublicKey(
188
188
  programId
189
189
  )[0];
190
190
  }
191
+
192
+ export function getReferrerNamePublicKeySync(
193
+ programId: PublicKey,
194
+ nameBuffer: number[]
195
+ ): PublicKey {
196
+ return PublicKey.findProgramAddressSync(
197
+ [
198
+ Buffer.from(anchor.utils.bytes.utf8.encode('referrer_name')),
199
+ Buffer.from(nameBuffer),
200
+ ],
201
+ programId
202
+ )[0];
203
+ }
@@ -64,6 +64,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
64
64
  launchTs: 1677068931000,
65
65
  oracleSource: OracleSource.PYTH_1M,
66
66
  },
67
+ {
68
+ fullName: 'Polygon',
69
+ category: ['L2', 'Infra'],
70
+ symbol: 'MATIC-PERP',
71
+ baseAssetSymbol: 'MATIC',
72
+ marketIndex: 5,
73
+ oracle: new PublicKey('FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur'),
74
+ launchTs: 1677690149000, //todo
75
+ oracleSource: OracleSource.PYTH,
76
+ },
67
77
  ];
68
78
 
69
79
  export const MainnetPerpMarkets: PerpMarketConfig[] = [
@@ -117,6 +127,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
117
127
  launchTs: 1677690149000,
118
128
  oracleSource: OracleSource.PYTH_1M,
119
129
  },
130
+ {
131
+ fullName: 'Polygon',
132
+ category: ['L2', 'Infra'],
133
+ symbol: 'MATIC-PERP',
134
+ baseAssetSymbol: 'MATIC',
135
+ marketIndex: 5,
136
+ oracle: new PublicKey('7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh'),
137
+ launchTs: 1677690149000, //todo
138
+ oracleSource: OracleSource.PYTH,
139
+ },
120
140
  ];
121
141
 
122
142
  export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
@@ -25,6 +25,7 @@ import {
25
25
  TxParams,
26
26
  SerumV3FulfillmentConfigAccount,
27
27
  isVariant,
28
+ ReferrerNameAccount,
28
29
  OrderTriggerCondition,
29
30
  isOneOfVariant,
30
31
  PostOnlyParams,
@@ -58,6 +59,7 @@ import {
58
59
  getDriftStateAccountPublicKey,
59
60
  getInsuranceFundStakeAccountPublicKey,
60
61
  getPerpMarketPublicKey,
62
+ getReferrerNamePublicKeySync,
61
63
  getSerumFulfillmentConfigPublicKey,
62
64
  getSerumSignerPublicKey,
63
65
  getSpotMarketPublicKey,
@@ -584,6 +586,40 @@ export class DriftClient {
584
586
  });
585
587
  }
586
588
 
589
+ public async initializeReferrerName(
590
+ name: string
591
+ ): Promise<TransactionSignature> {
592
+ const userAccountPublicKey = getUserAccountPublicKeySync(
593
+ this.program.programId,
594
+ this.wallet.publicKey,
595
+ 0
596
+ );
597
+
598
+ const nameBuffer = encodeName(name);
599
+
600
+ const referrerNameAccountPublicKey = await getReferrerNamePublicKeySync(
601
+ this.program.programId,
602
+ nameBuffer
603
+ );
604
+
605
+ const tx = await this.program.transaction.initializeReferrerName(
606
+ nameBuffer,
607
+ {
608
+ accounts: {
609
+ referrerName: referrerNameAccountPublicKey,
610
+ user: userAccountPublicKey,
611
+ authority: this.wallet.publicKey,
612
+ userStats: this.getUserStatsAccountPublicKey(),
613
+ payer: this.wallet.publicKey,
614
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
615
+ systemProgram: anchor.web3.SystemProgram.programId,
616
+ },
617
+ }
618
+ );
619
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
620
+ return txSig;
621
+ }
622
+
587
623
  public async updateUserName(
588
624
  name: string,
589
625
  subAccountId = 0
@@ -760,6 +796,19 @@ export class DriftClient {
760
796
  return this.userStats;
761
797
  }
762
798
 
799
+ public async fetchReferrerNameAccount(
800
+ name: string
801
+ ): Promise<ReferrerNameAccount | undefined> {
802
+ const nameBuffer = encodeName(name);
803
+ const referrerNameAccountPublicKey = getReferrerNamePublicKeySync(
804
+ this.program.programId,
805
+ nameBuffer
806
+ );
807
+ return (await this.program.account.referrerName.fetch(
808
+ referrerNameAccountPublicKey
809
+ )) as ReferrerNameAccount;
810
+ }
811
+
763
812
  userStatsAccountPublicKey: PublicKey;
764
813
  public getUserStatsAccountPublicKey(): PublicKey {
765
814
  if (this.userStatsAccountPublicKey) {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.20.0-beta.1",
2
+ "version": "2.20.0-beta.3",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -93,6 +93,57 @@
93
93
  ],
94
94
  "args": []
95
95
  },
96
+ {
97
+ "name": "initializeReferrerName",
98
+ "accounts": [
99
+ {
100
+ "name": "referrerName",
101
+ "isMut": true,
102
+ "isSigner": false
103
+ },
104
+ {
105
+ "name": "user",
106
+ "isMut": true,
107
+ "isSigner": false
108
+ },
109
+ {
110
+ "name": "userStats",
111
+ "isMut": true,
112
+ "isSigner": false
113
+ },
114
+ {
115
+ "name": "authority",
116
+ "isMut": false,
117
+ "isSigner": true
118
+ },
119
+ {
120
+ "name": "payer",
121
+ "isMut": true,
122
+ "isSigner": true
123
+ },
124
+ {
125
+ "name": "rent",
126
+ "isMut": false,
127
+ "isSigner": false
128
+ },
129
+ {
130
+ "name": "systemProgram",
131
+ "isMut": false,
132
+ "isSigner": false
133
+ }
134
+ ],
135
+ "args": [
136
+ {
137
+ "name": "name",
138
+ "type": {
139
+ "array": [
140
+ "u8",
141
+ 32
142
+ ]
143
+ }
144
+ }
145
+ ]
146
+ },
96
147
  {
97
148
  "name": "deposit",
98
149
  "accounts": [
@@ -4607,6 +4658,35 @@
4607
4658
  }
4608
4659
  ]
4609
4660
  }
4661
+ },
4662
+ {
4663
+ "name": "ReferrerName",
4664
+ "type": {
4665
+ "kind": "struct",
4666
+ "fields": [
4667
+ {
4668
+ "name": "authority",
4669
+ "type": "publicKey"
4670
+ },
4671
+ {
4672
+ "name": "user",
4673
+ "type": "publicKey"
4674
+ },
4675
+ {
4676
+ "name": "userStats",
4677
+ "type": "publicKey"
4678
+ },
4679
+ {
4680
+ "name": "name",
4681
+ "type": {
4682
+ "array": [
4683
+ "u8",
4684
+ 32
4685
+ ]
4686
+ }
4687
+ }
4688
+ ]
4689
+ }
4610
4690
  }
4611
4691
  ],
4612
4692
  "types": [
@@ -6208,9 +6288,7 @@
6208
6288
  "name": "Match",
6209
6289
  "fields": [
6210
6290
  "publicKey",
6211
- {
6212
- "defined": "usize"
6213
- }
6291
+ "u16"
6214
6292
  ]
6215
6293
  }
6216
6294
  ]
package/src/types.ts CHANGED
@@ -999,6 +999,13 @@ export type SerumV3FulfillmentConfigAccount = {
999
999
  serumSignerNonce: BN;
1000
1000
  };
1001
1001
 
1002
+ export type ReferrerNameAccount = {
1003
+ name: number[];
1004
+ user: PublicKey;
1005
+ authority: PublicKey;
1006
+ userStats: PublicKey;
1007
+ };
1008
+
1002
1009
  export type PerpMarketExtendedInfo = {
1003
1010
  marketIndex: number;
1004
1011
  /**