@drift-labs/sdk 2.104.0-beta.37 → 2.104.0-beta.39

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 CHANGED
@@ -1 +1 @@
1
- 2.104.0-beta.37
1
+ 2.104.0-beta.39
@@ -10,10 +10,11 @@ exports.DevnetPerpMarkets = [
10
10
  symbol: 'SOL-PERP',
11
11
  baseAssetSymbol: 'SOL',
12
12
  marketIndex: 0,
13
- oracle: new web3_js_1.PublicKey('BAtFj4kQttZRVep3UZS2aZRDixkGYgWsbqTBVDbnSsPF'),
13
+ oracle: new web3_js_1.PublicKey('3m6i4RFWEDw2Ft4tFHPJtYgmpPe21k56M3FHeWYrgGBz'),
14
14
  launchTs: 1655751353000,
15
- oracleSource: __1.OracleSource.PYTH_PULL,
15
+ oracleSource: __1.OracleSource.PYTH_LAZER,
16
16
  pythFeedId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
17
+ pythLazerId: 6,
17
18
  },
18
19
  {
19
20
  fullName: 'Bitcoin',
@@ -21,9 +22,9 @@ exports.DevnetPerpMarkets = [
21
22
  symbol: 'BTC-PERP',
22
23
  baseAssetSymbol: 'BTC',
23
24
  marketIndex: 1,
24
- oracle: new web3_js_1.PublicKey('486kr3pmFPfTsS4aZgcsQ7kS4i9rjMsYYZup6HQNSTT4'),
25
+ oracle: new web3_js_1.PublicKey('35MbvS1Juz2wf7GsyHrkCw8yfKciRLxVpEhfZDZFrB4R'),
25
26
  launchTs: 1655751353000,
26
- oracleSource: __1.OracleSource.PYTH_PULL,
27
+ oracleSource: __1.OracleSource.PYTH_LAZER,
27
28
  pythFeedId: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
28
29
  pythLazerId: 1,
29
30
  },
@@ -33,9 +34,9 @@ exports.DevnetPerpMarkets = [
33
34
  symbol: 'ETH-PERP',
34
35
  baseAssetSymbol: 'ETH',
35
36
  marketIndex: 2,
36
- oracle: new web3_js_1.PublicKey('6bEp2MiyoiiiDxcVqE8rUHQWwHirXUXtKfAEATTVqNzT'),
37
+ oracle: new web3_js_1.PublicKey('93FG52TzNKCnMiasV14Ba34BYcHDb9p4zK4GjZnLwqWR'),
37
38
  launchTs: 1637691133472,
38
- oracleSource: __1.OracleSource.PYTH_PULL,
39
+ oracleSource: __1.OracleSource.PYTH_LAZER,
39
40
  pythFeedId: '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
40
41
  pythLazerId: 2,
41
42
  },
@@ -392,8 +392,8 @@ export declare class DriftClient {
392
392
  placeOrdersTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
393
393
  }>;
394
394
  getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number): Promise<TransactionInstruction>;
395
- fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerPublicKey?: number): Promise<TransactionSignature>;
396
- getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number, isSwift?: boolean): Promise<TransactionInstruction>;
395
+ fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerSubAccountId?: number, fillerAuthority?: PublicKey): Promise<TransactionSignature>;
396
+ getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number, isSwift?: boolean, fillerAuthority?: PublicKey): Promise<TransactionInstruction>;
397
397
  getRevertFillIx(fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
398
398
  placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
399
399
  preparePlaceSpotOrderTx(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<{
@@ -108,7 +108,7 @@ class DriftClient {
108
108
  this.authority = (_d = config.authority) !== null && _d !== void 0 ? _d : this.wallet.publicKey;
109
109
  this.activeSubAccountId = (_e = config.activeSubAccountId) !== null && _e !== void 0 ? _e : 0;
110
110
  this.skipLoadUsers = (_f = config.skipLoadUsers) !== null && _f !== void 0 ? _f : false;
111
- this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 'legacy';
111
+ this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 0;
112
112
  this.txParams = {
113
113
  computeUnits: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnits) !== null && _j !== void 0 ? _j : 600000,
114
114
  computeUnitsPrice: (_l = (_k = config.txParams) === null || _k === void 0 ? void 0 : _k.computeUnitsPrice) !== null && _l !== void 0 ? _l : 0,
@@ -2119,14 +2119,26 @@ class DriftClient {
2119
2119
  remainingAccounts,
2120
2120
  });
2121
2121
  }
2122
- async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams, fillerPublicKey) {
2123
- const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerPublicKey), txParams), [], this.opts);
2122
+ async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams, fillerSubAccountId, fillerAuthority) {
2123
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerSubAccountId, undefined, fillerAuthority), txParams), [], this.opts);
2124
2124
  return txSig;
2125
2125
  }
2126
- async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId, isSwift) {
2126
+ async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId, isSwift, fillerAuthority) {
2127
2127
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
2128
- const filler = await this.getUserAccountPublicKey(fillerSubAccountId);
2129
- const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
2128
+ let filler;
2129
+ if (fillerAuthority) {
2130
+ filler = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, fillerAuthority, fillerSubAccountId);
2131
+ }
2132
+ else {
2133
+ filler = await this.getUserAccountPublicKey(fillerSubAccountId);
2134
+ }
2135
+ let fillerStatsPublicKey;
2136
+ if (fillerAuthority) {
2137
+ fillerStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, fillerAuthority);
2138
+ }
2139
+ else {
2140
+ fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
2141
+ }
2130
2142
  const marketIndex = order
2131
2143
  ? order.marketIndex
2132
2144
  : userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1).marketIndex;
@@ -1508,7 +1508,7 @@
1508
1508
  },
1509
1509
  {
1510
1510
  "name": "authority",
1511
- "isMut": false,
1511
+ "isMut": true,
1512
1512
  "isSigner": true
1513
1513
  }
1514
1514
  ],
@@ -4,6 +4,7 @@ exports.TestClient = void 0;
4
4
  const adminClient_1 = require("./adminClient");
5
5
  class TestClient extends adminClient_1.AdminClient {
6
6
  constructor(config) {
7
+ config.txVersion = 'legacy';
7
8
  if (config.accountSubscription.type !== 'polling') {
8
9
  throw new Error('Test client must be polling');
9
10
  }
@@ -1864,7 +1864,15 @@ class User {
1864
1864
  const freeCollateral = this.getFreeCollateral();
1865
1865
  const initialMarginRequirement = this.getInitialMarginRequirement();
1866
1866
  const oracleData = this.getOracleDataForSpotMarket(marketIndex);
1867
- const precisionIncrease = numericConstants_1.TEN.pow(new _1.BN(spotMarket.decimals - 6));
1867
+ const { numeratorScale, denominatorScale } = spotMarket.decimals > 6
1868
+ ? {
1869
+ numeratorScale: new _1.BN(10).pow(new _1.BN(spotMarket.decimals - 6)),
1870
+ denominatorScale: new _1.BN(1),
1871
+ }
1872
+ : {
1873
+ numeratorScale: new _1.BN(1),
1874
+ denominatorScale: new _1.BN(10).pow(new _1.BN(6 - spotMarket.decimals)),
1875
+ };
1868
1876
  const { canBypass, depositAmount: userDepositAmount } = this.canBypassWithdrawLimits(marketIndex);
1869
1877
  if (canBypass) {
1870
1878
  withdrawLimit = _1.BN.max(withdrawLimit, userDepositAmount);
@@ -1878,7 +1886,9 @@ class User {
1878
1886
  amountWithdrawable = userDepositAmount;
1879
1887
  }
1880
1888
  else {
1881
- amountWithdrawable = (0, _1.divCeil)((0, _1.divCeil)(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION), assetWeight).mul(numericConstants_1.PRICE_PRECISION), oracleData.price).mul(precisionIncrease);
1889
+ amountWithdrawable = (0, _1.divCeil)((0, _1.divCeil)(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION), assetWeight).mul(numericConstants_1.PRICE_PRECISION), oracleData.price)
1890
+ .mul(numeratorScale)
1891
+ .div(denominatorScale);
1882
1892
  }
1883
1893
  const maxWithdrawValue = _1.BN.min(_1.BN.min(amountWithdrawable, userDepositAmount), withdrawLimit.abs());
1884
1894
  if (reduceOnly) {
@@ -1894,7 +1904,8 @@ class User {
1894
1904
  .div(new _1.BN(spotMarket.initialLiabilityWeight))
1895
1905
  .mul(numericConstants_1.PRICE_PRECISION)
1896
1906
  .div(oracleData.price)
1897
- .mul(precisionIncrease);
1907
+ .mul(numeratorScale)
1908
+ .div(denominatorScale);
1898
1909
  const maxBorrowValue = _1.BN.min(maxWithdrawValue.add(maxLiabilityAllowed), borrowLimit.abs());
1899
1910
  return _1.BN.max(maxBorrowValue, numericConstants_1.ZERO);
1900
1911
  }
@@ -10,10 +10,11 @@ exports.DevnetPerpMarkets = [
10
10
  symbol: 'SOL-PERP',
11
11
  baseAssetSymbol: 'SOL',
12
12
  marketIndex: 0,
13
- oracle: new web3_js_1.PublicKey('BAtFj4kQttZRVep3UZS2aZRDixkGYgWsbqTBVDbnSsPF'),
13
+ oracle: new web3_js_1.PublicKey('3m6i4RFWEDw2Ft4tFHPJtYgmpPe21k56M3FHeWYrgGBz'),
14
14
  launchTs: 1655751353000,
15
- oracleSource: __1.OracleSource.PYTH_PULL,
15
+ oracleSource: __1.OracleSource.PYTH_LAZER,
16
16
  pythFeedId: '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
17
+ pythLazerId: 6,
17
18
  },
18
19
  {
19
20
  fullName: 'Bitcoin',
@@ -21,9 +22,9 @@ exports.DevnetPerpMarkets = [
21
22
  symbol: 'BTC-PERP',
22
23
  baseAssetSymbol: 'BTC',
23
24
  marketIndex: 1,
24
- oracle: new web3_js_1.PublicKey('486kr3pmFPfTsS4aZgcsQ7kS4i9rjMsYYZup6HQNSTT4'),
25
+ oracle: new web3_js_1.PublicKey('35MbvS1Juz2wf7GsyHrkCw8yfKciRLxVpEhfZDZFrB4R'),
25
26
  launchTs: 1655751353000,
26
- oracleSource: __1.OracleSource.PYTH_PULL,
27
+ oracleSource: __1.OracleSource.PYTH_LAZER,
27
28
  pythFeedId: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
28
29
  pythLazerId: 1,
29
30
  },
@@ -33,9 +34,9 @@ exports.DevnetPerpMarkets = [
33
34
  symbol: 'ETH-PERP',
34
35
  baseAssetSymbol: 'ETH',
35
36
  marketIndex: 2,
36
- oracle: new web3_js_1.PublicKey('6bEp2MiyoiiiDxcVqE8rUHQWwHirXUXtKfAEATTVqNzT'),
37
+ oracle: new web3_js_1.PublicKey('93FG52TzNKCnMiasV14Ba34BYcHDb9p4zK4GjZnLwqWR'),
37
38
  launchTs: 1637691133472,
38
- oracleSource: __1.OracleSource.PYTH_PULL,
39
+ oracleSource: __1.OracleSource.PYTH_LAZER,
39
40
  pythFeedId: '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
40
41
  pythLazerId: 2,
41
42
  },
@@ -392,8 +392,8 @@ export declare class DriftClient {
392
392
  placeOrdersTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
393
393
  }>;
394
394
  getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number): Promise<TransactionInstruction>;
395
- fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerPublicKey?: number): Promise<TransactionSignature>;
396
- getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number, isSwift?: boolean): Promise<TransactionInstruction>;
395
+ fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerSubAccountId?: number, fillerAuthority?: PublicKey): Promise<TransactionSignature>;
396
+ getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number, isSwift?: boolean, fillerAuthority?: PublicKey): Promise<TransactionInstruction>;
397
397
  getRevertFillIx(fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
398
398
  placeSpotOrder(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
399
399
  preparePlaceSpotOrderTx(orderParams: OptionalOrderParams, txParams?: TxParams, subAccountId?: number): Promise<{
@@ -108,7 +108,7 @@ class DriftClient {
108
108
  this.authority = (_d = config.authority) !== null && _d !== void 0 ? _d : this.wallet.publicKey;
109
109
  this.activeSubAccountId = (_e = config.activeSubAccountId) !== null && _e !== void 0 ? _e : 0;
110
110
  this.skipLoadUsers = (_f = config.skipLoadUsers) !== null && _f !== void 0 ? _f : false;
111
- this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 'legacy';
111
+ this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 0;
112
112
  this.txParams = {
113
113
  computeUnits: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnits) !== null && _j !== void 0 ? _j : 600000,
114
114
  computeUnitsPrice: (_l = (_k = config.txParams) === null || _k === void 0 ? void 0 : _k.computeUnitsPrice) !== null && _l !== void 0 ? _l : 0,
@@ -2119,14 +2119,26 @@ class DriftClient {
2119
2119
  remainingAccounts,
2120
2120
  });
2121
2121
  }
2122
- async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams, fillerPublicKey) {
2123
- const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerPublicKey), txParams), [], this.opts);
2122
+ async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams, fillerSubAccountId, fillerAuthority) {
2123
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerSubAccountId, undefined, fillerAuthority), txParams), [], this.opts);
2124
2124
  return txSig;
2125
2125
  }
2126
- async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId, isSwift) {
2126
+ async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId, isSwift, fillerAuthority) {
2127
2127
  const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
2128
- const filler = await this.getUserAccountPublicKey(fillerSubAccountId);
2129
- const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
2128
+ let filler;
2129
+ if (fillerAuthority) {
2130
+ filler = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, fillerAuthority, fillerSubAccountId);
2131
+ }
2132
+ else {
2133
+ filler = await this.getUserAccountPublicKey(fillerSubAccountId);
2134
+ }
2135
+ let fillerStatsPublicKey;
2136
+ if (fillerAuthority) {
2137
+ fillerStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, fillerAuthority);
2138
+ }
2139
+ else {
2140
+ fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
2141
+ }
2130
2142
  const marketIndex = order
2131
2143
  ? order.marketIndex
2132
2144
  : userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1).marketIndex;
@@ -1508,7 +1508,7 @@
1508
1508
  },
1509
1509
  {
1510
1510
  "name": "authority",
1511
- "isMut": false,
1511
+ "isMut": true,
1512
1512
  "isSigner": true
1513
1513
  }
1514
1514
  ],
@@ -4,6 +4,7 @@ exports.TestClient = void 0;
4
4
  const adminClient_1 = require("./adminClient");
5
5
  class TestClient extends adminClient_1.AdminClient {
6
6
  constructor(config) {
7
+ config.txVersion = 'legacy';
7
8
  if (config.accountSubscription.type !== 'polling') {
8
9
  throw new Error('Test client must be polling');
9
10
  }
package/lib/node/user.js CHANGED
@@ -1864,7 +1864,15 @@ class User {
1864
1864
  const freeCollateral = this.getFreeCollateral();
1865
1865
  const initialMarginRequirement = this.getInitialMarginRequirement();
1866
1866
  const oracleData = this.getOracleDataForSpotMarket(marketIndex);
1867
- const precisionIncrease = numericConstants_1.TEN.pow(new _1.BN(spotMarket.decimals - 6));
1867
+ const { numeratorScale, denominatorScale } = spotMarket.decimals > 6
1868
+ ? {
1869
+ numeratorScale: new _1.BN(10).pow(new _1.BN(spotMarket.decimals - 6)),
1870
+ denominatorScale: new _1.BN(1),
1871
+ }
1872
+ : {
1873
+ numeratorScale: new _1.BN(1),
1874
+ denominatorScale: new _1.BN(10).pow(new _1.BN(6 - spotMarket.decimals)),
1875
+ };
1868
1876
  const { canBypass, depositAmount: userDepositAmount } = this.canBypassWithdrawLimits(marketIndex);
1869
1877
  if (canBypass) {
1870
1878
  withdrawLimit = _1.BN.max(withdrawLimit, userDepositAmount);
@@ -1878,7 +1886,9 @@ class User {
1878
1886
  amountWithdrawable = userDepositAmount;
1879
1887
  }
1880
1888
  else {
1881
- amountWithdrawable = (0, _1.divCeil)((0, _1.divCeil)(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION), assetWeight).mul(numericConstants_1.PRICE_PRECISION), oracleData.price).mul(precisionIncrease);
1889
+ amountWithdrawable = (0, _1.divCeil)((0, _1.divCeil)(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION), assetWeight).mul(numericConstants_1.PRICE_PRECISION), oracleData.price)
1890
+ .mul(numeratorScale)
1891
+ .div(denominatorScale);
1882
1892
  }
1883
1893
  const maxWithdrawValue = _1.BN.min(_1.BN.min(amountWithdrawable, userDepositAmount), withdrawLimit.abs());
1884
1894
  if (reduceOnly) {
@@ -1894,7 +1904,8 @@ class User {
1894
1904
  .div(new _1.BN(spotMarket.initialLiabilityWeight))
1895
1905
  .mul(numericConstants_1.PRICE_PRECISION)
1896
1906
  .div(oracleData.price)
1897
- .mul(precisionIncrease);
1907
+ .mul(numeratorScale)
1908
+ .div(denominatorScale);
1898
1909
  const maxBorrowValue = _1.BN.min(maxWithdrawValue.add(maxLiabilityAllowed), borrowLimit.abs());
1899
1910
  return _1.BN.max(maxBorrowValue, numericConstants_1.ZERO);
1900
1911
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.104.0-beta.37",
3
+ "version": "2.104.0-beta.39",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -22,11 +22,12 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
22
22
  symbol: 'SOL-PERP',
23
23
  baseAssetSymbol: 'SOL',
24
24
  marketIndex: 0,
25
- oracle: new PublicKey('BAtFj4kQttZRVep3UZS2aZRDixkGYgWsbqTBVDbnSsPF'),
25
+ oracle: new PublicKey('3m6i4RFWEDw2Ft4tFHPJtYgmpPe21k56M3FHeWYrgGBz'),
26
26
  launchTs: 1655751353000,
27
- oracleSource: OracleSource.PYTH_PULL,
27
+ oracleSource: OracleSource.PYTH_LAZER,
28
28
  pythFeedId:
29
29
  '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
30
+ pythLazerId: 6,
30
31
  },
31
32
  {
32
33
  fullName: 'Bitcoin',
@@ -34,9 +35,9 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
34
35
  symbol: 'BTC-PERP',
35
36
  baseAssetSymbol: 'BTC',
36
37
  marketIndex: 1,
37
- oracle: new PublicKey('486kr3pmFPfTsS4aZgcsQ7kS4i9rjMsYYZup6HQNSTT4'),
38
+ oracle: new PublicKey('35MbvS1Juz2wf7GsyHrkCw8yfKciRLxVpEhfZDZFrB4R'),
38
39
  launchTs: 1655751353000,
39
- oracleSource: OracleSource.PYTH_PULL,
40
+ oracleSource: OracleSource.PYTH_LAZER,
40
41
  pythFeedId:
41
42
  '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
42
43
  pythLazerId: 1,
@@ -47,9 +48,9 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
47
48
  symbol: 'ETH-PERP',
48
49
  baseAssetSymbol: 'ETH',
49
50
  marketIndex: 2,
50
- oracle: new PublicKey('6bEp2MiyoiiiDxcVqE8rUHQWwHirXUXtKfAEATTVqNzT'),
51
+ oracle: new PublicKey('93FG52TzNKCnMiasV14Ba34BYcHDb9p4zK4GjZnLwqWR'),
51
52
  launchTs: 1637691133472,
52
- oracleSource: OracleSource.PYTH_PULL,
53
+ oracleSource: OracleSource.PYTH_LAZER,
53
54
  pythFeedId:
54
55
  '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
55
56
  pythLazerId: 2,
@@ -273,7 +273,7 @@ export class DriftClient {
273
273
  this.authority = config.authority ?? this.wallet.publicKey;
274
274
  this.activeSubAccountId = config.activeSubAccountId ?? 0;
275
275
  this.skipLoadUsers = config.skipLoadUsers ?? false;
276
- this.txVersion = config.txVersion ?? 'legacy';
276
+ this.txVersion = config.txVersion ?? 0;
277
277
  this.txParams = {
278
278
  computeUnits: config.txParams?.computeUnits ?? 600_000,
279
279
  computeUnitsPrice: config.txParams?.computeUnitsPrice ?? 0,
@@ -4006,7 +4006,8 @@ export class DriftClient {
4006
4006
  makerInfo?: MakerInfo | MakerInfo[],
4007
4007
  referrerInfo?: ReferrerInfo,
4008
4008
  txParams?: TxParams,
4009
- fillerPublicKey?: number
4009
+ fillerSubAccountId?: number,
4010
+ fillerAuthority?: PublicKey
4010
4011
  ): Promise<TransactionSignature> {
4011
4012
  const { txSig } = await this.sendTransaction(
4012
4013
  await this.buildTransaction(
@@ -4016,7 +4017,9 @@ export class DriftClient {
4016
4017
  order,
4017
4018
  makerInfo,
4018
4019
  referrerInfo,
4019
- fillerPublicKey
4020
+ fillerSubAccountId,
4021
+ undefined,
4022
+ fillerAuthority
4020
4023
  ),
4021
4024
  txParams
4022
4025
  ),
@@ -4033,15 +4036,36 @@ export class DriftClient {
4033
4036
  makerInfo?: MakerInfo | MakerInfo[],
4034
4037
  referrerInfo?: ReferrerInfo,
4035
4038
  fillerSubAccountId?: number,
4036
- isSwift?: boolean
4039
+ isSwift?: boolean,
4040
+ fillerAuthority?: PublicKey
4037
4041
  ): Promise<TransactionInstruction> {
4038
4042
  const userStatsPublicKey = getUserStatsAccountPublicKey(
4039
4043
  this.program.programId,
4040
4044
  userAccount.authority
4041
4045
  );
4042
4046
 
4043
- const filler = await this.getUserAccountPublicKey(fillerSubAccountId);
4044
- const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
4047
+ let filler;
4048
+
4049
+ if (fillerAuthority) {
4050
+ filler = getUserAccountPublicKeySync(
4051
+ this.program.programId,
4052
+ fillerAuthority,
4053
+ fillerSubAccountId
4054
+ );
4055
+ } else {
4056
+ filler = await this.getUserAccountPublicKey(fillerSubAccountId);
4057
+ }
4058
+
4059
+ let fillerStatsPublicKey;
4060
+
4061
+ if (fillerAuthority) {
4062
+ fillerStatsPublicKey = getUserStatsAccountPublicKey(
4063
+ this.program.programId,
4064
+ fillerAuthority
4065
+ );
4066
+ } else {
4067
+ fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
4068
+ }
4045
4069
 
4046
4070
  const marketIndex = order
4047
4071
  ? order.marketIndex
@@ -1508,7 +1508,7 @@
1508
1508
  },
1509
1509
  {
1510
1510
  "name": "authority",
1511
- "isMut": false,
1511
+ "isMut": true,
1512
1512
  "isSigner": true
1513
1513
  }
1514
1514
  ],
package/src/testClient.ts CHANGED
@@ -6,6 +6,7 @@ import { DriftClientConfig } from './driftClientConfig';
6
6
 
7
7
  export class TestClient extends AdminClient {
8
8
  public constructor(config: DriftClientConfig) {
9
+ config.txVersion = 'legacy';
9
10
  if (config.accountSubscription.type !== 'polling') {
10
11
  throw new Error('Test client must be polling');
11
12
  }
package/src/user.ts CHANGED
@@ -36,7 +36,6 @@ import {
36
36
  QUOTE_PRECISION_EXP,
37
37
  QUOTE_SPOT_MARKET_INDEX,
38
38
  SPOT_MARKET_WEIGHT_PRECISION,
39
- TEN,
40
39
  TEN_THOUSAND,
41
40
  TWO,
42
41
  ZERO,
@@ -3540,7 +3539,16 @@ export class User {
3540
3539
  const freeCollateral = this.getFreeCollateral();
3541
3540
  const initialMarginRequirement = this.getInitialMarginRequirement();
3542
3541
  const oracleData = this.getOracleDataForSpotMarket(marketIndex);
3543
- const precisionIncrease = TEN.pow(new BN(spotMarket.decimals - 6));
3542
+ const { numeratorScale, denominatorScale } =
3543
+ spotMarket.decimals > 6
3544
+ ? {
3545
+ numeratorScale: new BN(10).pow(new BN(spotMarket.decimals - 6)),
3546
+ denominatorScale: new BN(1),
3547
+ }
3548
+ : {
3549
+ numeratorScale: new BN(1),
3550
+ denominatorScale: new BN(10).pow(new BN(6 - spotMarket.decimals)),
3551
+ };
3544
3552
 
3545
3553
  const { canBypass, depositAmount: userDepositAmount } =
3546
3554
  this.canBypassWithdrawLimits(marketIndex);
@@ -3566,7 +3574,9 @@ export class User {
3566
3574
  PRICE_PRECISION
3567
3575
  ),
3568
3576
  oracleData.price
3569
- ).mul(precisionIncrease);
3577
+ )
3578
+ .mul(numeratorScale)
3579
+ .div(denominatorScale);
3570
3580
  }
3571
3581
 
3572
3582
  const maxWithdrawValue = BN.min(
@@ -3592,7 +3602,8 @@ export class User {
3592
3602
  .div(new BN(spotMarket.initialLiabilityWeight))
3593
3603
  .mul(PRICE_PRECISION)
3594
3604
  .div(oracleData.price)
3595
- .mul(precisionIncrease);
3605
+ .mul(numeratorScale)
3606
+ .div(denominatorScale);
3596
3607
 
3597
3608
  const maxBorrowValue = BN.min(
3598
3609
  maxWithdrawValue.add(maxLiabilityAllowed),