@reflectmoney/stable.ts 2.8.2 → 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,7 +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
- initializeDriftClient(): void;
36
35
  /**
37
36
  * Initializes the stablecoin drift account for the USDC+ controller.
38
37
  *
@@ -51,9 +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
- if (!skipInitializeDriftClient) {
55
- this.initializeDriftClient();
56
- }
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
+ });
57
60
  }
58
61
  /**
59
62
  * Loads the USDC+ controller data from the blockchain.
@@ -67,9 +70,6 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
67
70
  this.strategy = baseStrategy;
68
71
  this.controller = controller;
69
72
  yield this.loadMint();
70
- const subscribed = yield this.driftClient.subscribe();
71
- if (!subscribed)
72
- throw new Error("Failed to subscribe to Drift Client");
73
73
  const addedController = yield this.driftClient.addUser(0, this.controllerKey);
74
74
  if (!addedController)
75
75
  throw new Error("Failed to add controller account to Drift Client");
@@ -110,18 +110,6 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
110
110
  return [ix];
111
111
  });
112
112
  }
113
- initializeDriftClient() {
114
- this.driftClient = new sdk_2.DriftClient({
115
- connection: this.connection,
116
- env: this.devnet ? "devnet" : "mainnet-beta",
117
- wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
118
- authority: this.controllerKey,
119
- accountSubscription: {
120
- type: "polling",
121
- accountLoader: new sdk_1.BulkAccountLoader(this.connection, "confirmed", 1000),
122
- },
123
- });
124
- }
125
113
  /**
126
114
  * Initializes the stablecoin drift account for the USDC+ controller.
127
115
  *
@@ -279,8 +267,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
279
267
  */
280
268
  getBaseUsdExchangeRate() {
281
269
  return __awaiter(this, void 0, void 0, function* () {
282
- const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
283
- 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);
284
274
  const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
285
275
  const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
286
276
  const [{ mint: usdcMint }] = this.collaterals;
@@ -304,8 +294,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
304
294
  */
305
295
  getBaseToCollateralExchangeRate() {
306
296
  return __awaiter(this, void 0, void 0, function* () {
307
- const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
308
- 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);
309
301
  const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
310
302
  const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
311
303
  const exchangeRate = usdcAmount
@@ -441,7 +433,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
441
433
  }
442
434
  cleanup() {
443
435
  return __awaiter(this, void 0, void 0, function* () {
444
- yield this.driftClient.unsubscribe();
436
+ return;
445
437
  });
446
438
  }
447
439
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/stable.ts",
3
- "version": "2.8.2",
3
+ "version": "2.8.4",
4
4
  "type": "commonjs",
5
5
  "author": "stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {