@reflectmoney/stable.ts 2.8.3 → 2.8.4

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.
@@ -32,8 +32,6 @@ export declare class UsdcPlusStablecoin extends Stablecoin<DriftUsdcController>
32
32
  * @returns Promise resolving to an array of TransactionInstruction objects
33
33
  */
34
34
  initialize(signer: PublicKey, mint: PublicKey, cap: BN, recipientAddresses: PublicKey[], recipientCuts: number[]): Promise<TransactionInstruction[]>;
35
- initializePollingDriftClient(): void;
36
- initializeWebsocketDriftClient(): void;
37
35
  /**
38
36
  * Initializes the stablecoin drift account for the USDC+ controller.
39
37
  *
@@ -51,11 +51,12 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
51
51
  // Otherwise has to be loaded first.
52
52
  if (stablecoinMintOverride)
53
53
  this.stablecoinMint = stablecoinMintOverride;
54
- // Unless explicitly told to skip, default to polling Drift client.
55
- // This may be skipped, and custom drift client initialization may be handled with `initializePollingDriftClient` or `initializeWebsocketDriftClient`.
56
- if (!skipInitializeDriftClient) {
57
- this.initializePollingDriftClient();
58
- }
54
+ this.driftClient = new sdk_2.DriftClient({
55
+ connection: this.connection,
56
+ env: this.devnet ? "devnet" : "mainnet-beta",
57
+ wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
58
+ authority: this.controllerKey
59
+ });
59
60
  }
60
61
  /**
61
62
  * Loads the USDC+ controller data from the blockchain.
@@ -69,9 +70,6 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
69
70
  this.strategy = baseStrategy;
70
71
  this.controller = controller;
71
72
  yield this.loadMint();
72
- const subscribed = yield this.driftClient.subscribe();
73
- if (!subscribed)
74
- throw new Error("Failed to subscribe to Drift Client");
75
73
  const addedController = yield this.driftClient.addUser(0, this.controllerKey);
76
74
  if (!addedController)
77
75
  throw new Error("Failed to add controller account to Drift Client");
@@ -112,29 +110,6 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
112
110
  return [ix];
113
111
  });
114
112
  }
115
- initializePollingDriftClient() {
116
- this.driftClient = new sdk_2.DriftClient({
117
- connection: this.connection,
118
- env: this.devnet ? "devnet" : "mainnet-beta",
119
- wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
120
- authority: this.controllerKey,
121
- accountSubscription: {
122
- type: "polling",
123
- accountLoader: new sdk_1.BulkAccountLoader(this.connection, "confirmed", 1000),
124
- },
125
- });
126
- }
127
- initializeWebsocketDriftClient() {
128
- this.driftClient = new sdk_2.DriftClient({
129
- connection: this.connection,
130
- env: this.devnet ? "devnet" : "mainnet-beta",
131
- wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
132
- authority: this.controllerKey,
133
- accountSubscription: {
134
- type: "websocket",
135
- },
136
- });
137
- }
138
113
  /**
139
114
  * Initializes the stablecoin drift account for the USDC+ controller.
140
115
  *
@@ -292,8 +267,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
292
267
  */
293
268
  getBaseUsdExchangeRate() {
294
269
  return __awaiter(this, void 0, void 0, function* () {
295
- const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
296
- const spotMarketAccount = this.driftClient.getSpotMarketAccount(0);
270
+ const [userAccount] = yield (0, sdk_1.fetchUserAccounts)(this.connection, this.driftClient.program, this.controllerKey);
271
+ const spotPosition = userAccount.spotPositions[0];
272
+ const { scaledBalance, balanceType } = spotPosition;
273
+ const spotMarketAccount = yield this.driftClient.forceGetSpotMarketAccount(0);
297
274
  const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
298
275
  const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
299
276
  const [{ mint: usdcMint }] = this.collaterals;
@@ -317,8 +294,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
317
294
  */
318
295
  getBaseToCollateralExchangeRate() {
319
296
  return __awaiter(this, void 0, void 0, function* () {
320
- const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
321
- const spotMarketAccount = this.driftClient.getSpotMarketAccount(0);
297
+ const [userAccount] = yield (0, sdk_1.fetchUserAccounts)(this.connection, this.driftClient.program, this.controllerKey);
298
+ const spotPosition = userAccount.spotPositions[0];
299
+ const { scaledBalance, balanceType } = spotPosition;
300
+ const spotMarketAccount = yield this.driftClient.forceGetSpotMarketAccount(0);
322
301
  const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
323
302
  const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
324
303
  const exchangeRate = usdcAmount
@@ -454,7 +433,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
454
433
  }
455
434
  cleanup() {
456
435
  return __awaiter(this, void 0, void 0, function* () {
457
- yield this.driftClient.unsubscribe();
436
+ return;
458
437
  });
459
438
  }
460
439
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/stable.ts",
3
- "version": "2.8.3",
3
+ "version": "2.8.4",
4
4
  "type": "commonjs",
5
5
  "author": "stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {