@drift-labs/sdk 2.23.0-beta.0 → 2.23.0
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/lib/constants/spotMarkets.js +4 -4
- package/lib/driftClient.d.ts +1 -0
- package/lib/driftClient.js +6 -0
- package/lib/idl/drift.json +17 -1
- package/lib/user.js +4 -2
- package/package.json +1 -1
- package/src/constants/spotMarkets.ts +4 -4
- package/src/driftClient.ts +7 -0
- package/src/idl/drift.json +17 -1
- package/src/user.ts +6 -2
|
@@ -9,8 +9,8 @@ exports.DevnetSpotMarkets = [
|
|
|
9
9
|
{
|
|
10
10
|
symbol: 'USDC',
|
|
11
11
|
marketIndex: 0,
|
|
12
|
-
oracle: web3_js_1.PublicKey
|
|
13
|
-
oracleSource: __1.OracleSource.
|
|
12
|
+
oracle: new web3_js_1.PublicKey('5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7'),
|
|
13
|
+
oracleSource: __1.OracleSource.PYTH_STABLE_COIN,
|
|
14
14
|
mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
|
|
15
15
|
precision: new __1.BN(10).pow(numericConstants_1.SIX),
|
|
16
16
|
precisionExp: numericConstants_1.SIX,
|
|
@@ -40,8 +40,8 @@ exports.MainnetSpotMarkets = [
|
|
|
40
40
|
{
|
|
41
41
|
symbol: 'USDC',
|
|
42
42
|
marketIndex: 0,
|
|
43
|
-
oracle: web3_js_1.PublicKey
|
|
44
|
-
oracleSource: __1.OracleSource.
|
|
43
|
+
oracle: new web3_js_1.PublicKey('Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD'),
|
|
44
|
+
oracleSource: __1.OracleSource.PYTH_STABLE_COIN,
|
|
45
45
|
mint: new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
|
|
46
46
|
precision: numericConstants_1.QUOTE_PRECISION,
|
|
47
47
|
precisionExp: numericConstants_1.QUOTE_PRECISION_EXP,
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ export declare class DriftClient {
|
|
|
93
93
|
updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number): Promise<void>;
|
|
94
94
|
switchActiveUser(subAccountId: number): void;
|
|
95
95
|
addUser(subAccountId: number): Promise<void>;
|
|
96
|
+
addAllUsers(): Promise<void>;
|
|
96
97
|
initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
97
98
|
getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
98
99
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -297,6 +297,12 @@ class DriftClient {
|
|
|
297
297
|
await user.subscribe();
|
|
298
298
|
this.users.set(subAccountId, user);
|
|
299
299
|
}
|
|
300
|
+
async addAllUsers() {
|
|
301
|
+
const userAccounts = await this.getUserAccountsForAuthority(this.authority);
|
|
302
|
+
for (const userAccount of userAccounts) {
|
|
303
|
+
await this.addUser(userAccount.subAccountId);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
300
306
|
async initializeUserAccount(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, referrerInfo) {
|
|
301
307
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
|
302
308
|
const tx = new web3_js_1.Transaction();
|
package/lib/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.23.0
|
|
2
|
+
"version": "2.23.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -5994,6 +5994,22 @@
|
|
|
5994
5994
|
]
|
|
5995
5995
|
}
|
|
5996
5996
|
},
|
|
5997
|
+
{
|
|
5998
|
+
"name": "FulfillmentParams",
|
|
5999
|
+
"type": {
|
|
6000
|
+
"kind": "enum",
|
|
6001
|
+
"variants": [
|
|
6002
|
+
{
|
|
6003
|
+
"name": "SerumFulfillmentParams",
|
|
6004
|
+
"fields": [
|
|
6005
|
+
{
|
|
6006
|
+
"defined": "SerumFulfillmentParams<'a,'b>"
|
|
6007
|
+
}
|
|
6008
|
+
]
|
|
6009
|
+
}
|
|
6010
|
+
]
|
|
6011
|
+
}
|
|
6012
|
+
},
|
|
5997
6013
|
{
|
|
5998
6014
|
"name": "SpotFulfillmentType",
|
|
5999
6015
|
"type": {
|
package/lib/user.js
CHANGED
|
@@ -1236,7 +1236,8 @@ class User {
|
|
|
1236
1236
|
return false;
|
|
1237
1237
|
}
|
|
1238
1238
|
const userLastActiveSlot = userAccount.lastActiveSlot;
|
|
1239
|
-
|
|
1239
|
+
const slotsSinceLastActive = slot.sub(userLastActiveSlot);
|
|
1240
|
+
if (slotsSinceLastActive.lt(slotsBeforeIdle)) {
|
|
1240
1241
|
return false;
|
|
1241
1242
|
}
|
|
1242
1243
|
if (this.isBeingLiquidated()) {
|
|
@@ -1248,7 +1249,8 @@ class User {
|
|
|
1248
1249
|
}
|
|
1249
1250
|
}
|
|
1250
1251
|
for (const spotPosition of userAccount.spotPositions) {
|
|
1251
|
-
if ((0, types_1.isVariant)(spotPosition.balanceType, 'borrow')
|
|
1252
|
+
if ((0, types_1.isVariant)(spotPosition.balanceType, 'borrow') &&
|
|
1253
|
+
spotPosition.scaledBalance.gt(numericConstants_1.ZERO)) {
|
|
1252
1254
|
return false;
|
|
1253
1255
|
}
|
|
1254
1256
|
if (spotPosition.openOrders !== 0) {
|
package/package.json
CHANGED
|
@@ -27,8 +27,8 @@ export const DevnetSpotMarkets: SpotMarketConfig[] = [
|
|
|
27
27
|
{
|
|
28
28
|
symbol: 'USDC',
|
|
29
29
|
marketIndex: 0,
|
|
30
|
-
oracle: PublicKey
|
|
31
|
-
oracleSource: OracleSource.
|
|
30
|
+
oracle: new PublicKey('5SSkXsEKQepHHAewytPVwdej4epN1nxgLVM84L4KXgy7'),
|
|
31
|
+
oracleSource: OracleSource.PYTH_STABLE_COIN,
|
|
32
32
|
mint: new PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
|
|
33
33
|
precision: new BN(10).pow(SIX),
|
|
34
34
|
precisionExp: SIX,
|
|
@@ -59,8 +59,8 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
|
|
|
59
59
|
{
|
|
60
60
|
symbol: 'USDC',
|
|
61
61
|
marketIndex: 0,
|
|
62
|
-
oracle: PublicKey
|
|
63
|
-
oracleSource: OracleSource.
|
|
62
|
+
oracle: new PublicKey('Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD'),
|
|
63
|
+
oracleSource: OracleSource.PYTH_STABLE_COIN,
|
|
64
64
|
mint: new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
|
|
65
65
|
precision: QUOTE_PRECISION,
|
|
66
66
|
precisionExp: QUOTE_PRECISION_EXP,
|
package/src/driftClient.ts
CHANGED
|
@@ -499,6 +499,13 @@ export class DriftClient {
|
|
|
499
499
|
this.users.set(subAccountId, user);
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
+
public async addAllUsers(): Promise<void> {
|
|
503
|
+
const userAccounts = await this.getUserAccountsForAuthority(this.authority);
|
|
504
|
+
for (const userAccount of userAccounts) {
|
|
505
|
+
await this.addUser(userAccount.subAccountId);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
502
509
|
public async initializeUserAccount(
|
|
503
510
|
subAccountId = 0,
|
|
504
511
|
name = DEFAULT_USER_NAME,
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.23.0
|
|
2
|
+
"version": "2.23.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -5994,6 +5994,22 @@
|
|
|
5994
5994
|
]
|
|
5995
5995
|
}
|
|
5996
5996
|
},
|
|
5997
|
+
{
|
|
5998
|
+
"name": "FulfillmentParams",
|
|
5999
|
+
"type": {
|
|
6000
|
+
"kind": "enum",
|
|
6001
|
+
"variants": [
|
|
6002
|
+
{
|
|
6003
|
+
"name": "SerumFulfillmentParams",
|
|
6004
|
+
"fields": [
|
|
6005
|
+
{
|
|
6006
|
+
"defined": "SerumFulfillmentParams<'a,'b>"
|
|
6007
|
+
}
|
|
6008
|
+
]
|
|
6009
|
+
}
|
|
6010
|
+
]
|
|
6011
|
+
}
|
|
6012
|
+
},
|
|
5997
6013
|
{
|
|
5998
6014
|
"name": "SpotFulfillmentType",
|
|
5999
6015
|
"type": {
|
package/src/user.ts
CHANGED
|
@@ -2237,7 +2237,8 @@ export class User {
|
|
|
2237
2237
|
}
|
|
2238
2238
|
|
|
2239
2239
|
const userLastActiveSlot = userAccount.lastActiveSlot;
|
|
2240
|
-
|
|
2240
|
+
const slotsSinceLastActive = slot.sub(userLastActiveSlot);
|
|
2241
|
+
if (slotsSinceLastActive.lt(slotsBeforeIdle)) {
|
|
2241
2242
|
return false;
|
|
2242
2243
|
}
|
|
2243
2244
|
|
|
@@ -2252,7 +2253,10 @@ export class User {
|
|
|
2252
2253
|
}
|
|
2253
2254
|
|
|
2254
2255
|
for (const spotPosition of userAccount.spotPositions) {
|
|
2255
|
-
if (
|
|
2256
|
+
if (
|
|
2257
|
+
isVariant(spotPosition.balanceType, 'borrow') &&
|
|
2258
|
+
spotPosition.scaledBalance.gt(ZERO)
|
|
2259
|
+
) {
|
|
2256
2260
|
return false;
|
|
2257
2261
|
}
|
|
2258
2262
|
|