@reflectmoney/stable.ts 2.8.0 → 2.8.2

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.
@@ -35,8 +35,8 @@ class ReflectKeeper {
35
35
  constructor({ admin, connection, devnet = false, }) {
36
36
  this.admin = admin;
37
37
  this.connection = connection;
38
- this.main = PdaClient_1.PdaClient.deriveMain();
39
38
  this.devnet = devnet;
39
+ this.main = PdaClient_1.PdaClient.deriveMain(devnet);
40
40
  }
41
41
  /**
42
42
  * Creates the main program account. This is the initial step of protocol setup.
@@ -50,7 +50,7 @@ class ReflectKeeper {
50
50
  main,
51
51
  admin,
52
52
  systemProgram: web3_js_1.SystemProgram.programId,
53
- creds: PdaClient_1.PdaClient.derivePermissions(admin),
53
+ creds: PdaClient_1.PdaClient.derivePermissions(admin, devnet),
54
54
  }, devnet ? devnet_1.DEVNET_PROGRAM_ID : reflect_main_1.PROGRAM_ID);
55
55
  return ix;
56
56
  }
@@ -73,7 +73,7 @@ class ReflectKeeper {
73
73
  admin: this.admin,
74
74
  main: this.main,
75
75
  systemProgram: web3_js_1.SystemProgram.programId,
76
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(this.admin),
76
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(this.admin, this.devnet),
77
77
  }, {
78
78
  freeze,
79
79
  action,
@@ -92,7 +92,7 @@ class ReflectKeeper {
92
92
  admin: this.admin,
93
93
  main: this.main,
94
94
  systemProgram: web3_js_1.SystemProgram.programId,
95
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(this.admin),
95
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(this.admin, this.devnet),
96
96
  }, {
97
97
  freeze,
98
98
  programIndex,
@@ -109,7 +109,7 @@ class ReflectKeeper {
109
109
  createAdminAccount(signer, newAdmin, roles = 18) {
110
110
  const ix = (0, reflect_main_1.createCreateAdminAccountInstruction)({
111
111
  caller: signer,
112
- newCreds: PdaClient_1.PdaClient.derivePermissions(newAdmin),
112
+ newCreds: PdaClient_1.PdaClient.derivePermissions(newAdmin, this.devnet),
113
113
  systemProgram: web3_js_1.SystemProgram.programId,
114
114
  }, {
115
115
  newAdmin,
@@ -129,12 +129,12 @@ class ReflectKeeper {
129
129
  updateRoleHolderProtocol(signer, adminToUpdate, affectedRole, update) {
130
130
  const ix = (0, reflect_main_1.createUpdateRoleHolderProtocolInstruction)({
131
131
  admin: signer,
132
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
133
- main: PdaClient_1.PdaClient.deriveMain(),
132
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
133
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
134
134
  systemProgram: web3_js_1.SystemProgram.programId,
135
- updateAdminPermissions: PdaClient_1.PdaClient.derivePermissions(adminToUpdate),
135
+ updateAdminPermissions: PdaClient_1.PdaClient.derivePermissions(adminToUpdate, this.devnet),
136
136
  // Dummy strategy account.
137
- strategy: PdaClient_1.PdaClient.deriveController(0),
137
+ strategy: PdaClient_1.PdaClient.deriveController(0, this.devnet),
138
138
  }, {
139
139
  update,
140
140
  accessLevel: affectedRole,
@@ -154,11 +154,11 @@ class ReflectKeeper {
154
154
  updateRoleHolderStrategy(signer, strategyId, adminToUpdate, affectedRole, update) {
155
155
  const ix = (0, reflect_main_1.createUpdateRoleHolderStrategyInstruction)({
156
156
  admin: signer,
157
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
158
- main: PdaClient_1.PdaClient.deriveMain(),
157
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
158
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
159
159
  systemProgram: web3_js_1.SystemProgram.programId,
160
- updateAdminPermissions: PdaClient_1.PdaClient.derivePermissions(adminToUpdate),
161
- strategy: PdaClient_1.PdaClient.deriveController(strategyId),
160
+ updateAdminPermissions: PdaClient_1.PdaClient.derivePermissions(adminToUpdate, this.devnet),
161
+ strategy: PdaClient_1.PdaClient.deriveController(strategyId, this.devnet),
162
162
  }, {
163
163
  update,
164
164
  role: affectedRole,
@@ -178,10 +178,10 @@ class ReflectKeeper {
178
178
  updateActionRoleStrategy(signer, strategyId, action, affectedRole, update) {
179
179
  const ix = (0, reflect_main_1.createUpdateActionRoleStrategyInstruction)({
180
180
  admin: signer,
181
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
182
- main: PdaClient_1.PdaClient.deriveMain(),
181
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
182
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
183
183
  systemProgram: web3_js_1.SystemProgram.programId,
184
- strategy: PdaClient_1.PdaClient.deriveController(strategyId),
184
+ strategy: PdaClient_1.PdaClient.deriveController(strategyId, this.devnet),
185
185
  }, {
186
186
  update,
187
187
  role: affectedRole,
@@ -201,8 +201,8 @@ class ReflectKeeper {
201
201
  updateActionRoleProtocol(signer, action, affectedRole, update) {
202
202
  const ix = (0, reflect_main_1.createUpdateActionRoleProtocolInstruction)({
203
203
  admin: signer,
204
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
205
- main: PdaClient_1.PdaClient.deriveMain(),
204
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
205
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
206
206
  systemProgram: web3_js_1.SystemProgram.programId,
207
207
  }, {
208
208
  action,
@@ -14,7 +14,7 @@ export declare class UsdcPlusStablecoin extends Stablecoin<DriftUsdcController>
14
14
  * @param connection - Solana connection instance for RPC communication
15
15
  * @param stablecoinMintOverride - Optional override for the stablecoin mint address
16
16
  */
17
- constructor(connection: Connection, stablecoinMintOverride?: PublicKey, devnet?: boolean);
17
+ constructor(connection: Connection, stablecoinMintOverride?: PublicKey, skipInitializeDriftClient?: boolean, devnet?: boolean);
18
18
  /**
19
19
  * Loads the USDC+ controller data from the blockchain.
20
20
  * Updates the stablecoin mint and strategy information.
@@ -32,6 +32,7 @@ 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;
35
36
  /**
36
37
  * Initializes the stablecoin drift account for the USDC+ controller.
37
38
  *
@@ -37,28 +37,23 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
37
37
  * @param connection - Solana connection instance for RPC communication
38
38
  * @param stablecoinMintOverride - Optional override for the stablecoin mint address
39
39
  */
40
- constructor(connection, stablecoinMintOverride, devnet) {
40
+ constructor(connection, stablecoinMintOverride, skipInitializeDriftClient = false, devnet) {
41
41
  super(0, "USD Coin Plus", connection, devnet ? constants_3.USDC_PLUS_LOOKUP_TABLE_DEVNET : constants_2.USDC_PLUS_LOOKUP_TABLE, devnet);
42
- this.collaterals = [{
42
+ this.collaterals = [
43
+ {
43
44
  mint: devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT,
44
45
  oracle: "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
45
- decimals: 6
46
- }];
47
- this.driftClient = new sdk_2.DriftClient({
48
- connection,
49
- env: devnet ? "devnet" : "mainnet-beta",
50
- wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
51
- authority: this.controllerKey,
52
- accountSubscription: {
53
- type: "polling",
54
- accountLoader: new sdk_1.BulkAccountLoader(connection, "confirmed", 1000),
55
- }
56
- });
46
+ decimals: 6,
47
+ },
48
+ ];
57
49
  this.isPermissioned = true;
58
50
  this.devnet = devnet;
59
51
  // Otherwise has to be loaded first.
60
52
  if (stablecoinMintOverride)
61
53
  this.stablecoinMint = stablecoinMintOverride;
54
+ if (!skipInitializeDriftClient) {
55
+ this.initializeDriftClient();
56
+ }
62
57
  }
63
58
  /**
64
59
  * Loads the USDC+ controller data from the blockchain.
@@ -99,11 +94,13 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
99
94
  main: classes_1.PdaClient.deriveMain(this.devnet),
100
95
  driftUsdcController: this.controllerKey,
101
96
  systemProgram: web3_js_1.SystemProgram.programId,
102
- anchorRemainingAccounts: [{
97
+ anchorRemainingAccounts: [
98
+ {
103
99
  isSigner: false,
104
100
  isWritable: false,
105
- pubkey: this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT
106
- }]
101
+ pubkey: this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT,
102
+ },
103
+ ],
107
104
  }, {
108
105
  mint,
109
106
  cap,
@@ -113,6 +110,18 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
113
110
  return [ix];
114
111
  });
115
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
+ }
116
125
  /**
117
126
  * Initializes the stablecoin drift account for the USDC+ controller.
118
127
  *
@@ -121,13 +130,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
121
130
  */
122
131
  initializeStablecoinDriftAccount(signer) {
123
132
  return __awaiter(this, void 0, void 0, function* () {
124
- const anchorRemainingAccounts = [
125
- constants_1.REFERRAL_USER,
126
- constants_1.REFERRAL_USER_STATS
127
- ].map(account => ({
133
+ const anchorRemainingAccounts = [constants_1.REFERRAL_USER, constants_1.REFERRAL_USER_STATS].map((account) => ({
128
134
  isSigner: false,
129
135
  isWritable: true,
130
- pubkey: account
136
+ pubkey: account,
131
137
  }));
132
138
  const ix = (0, reflect_main_1.createInitDriftAccountsS1Instruction)({
133
139
  admin: signer,
@@ -140,7 +146,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
140
146
  userAccount: (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
141
147
  userStats: (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
142
148
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
143
- anchorRemainingAccounts
149
+ anchorRemainingAccounts,
144
150
  }, this.programId);
145
151
  return ix;
146
152
  });
@@ -181,10 +187,12 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
181
187
  userReceiptAta,
182
188
  userStats,
183
189
  userUsdcAta,
184
- adminPermissions: permissions ? classes_1.PdaClient.derivePermissions(signer, this.devnet) : null,
190
+ adminPermissions: permissions
191
+ ? classes_1.PdaClient.derivePermissions(signer, this.devnet)
192
+ : null,
185
193
  anchorRemainingAccounts,
186
194
  systemProgram: web3_js_1.SystemProgram.programId,
187
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
195
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
188
196
  };
189
197
  return accounts;
190
198
  });
@@ -203,17 +211,16 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
203
211
  {
204
212
  pubkey: oracle,
205
213
  isSigner: false,
206
- isWritable: true
214
+ isWritable: true,
207
215
  },
208
216
  {
209
217
  pubkey: spotMarket,
210
218
  isSigner: false,
211
- isWritable: true
219
+ isWritable: true,
212
220
  },
213
221
  ];
214
222
  });
215
223
  }
216
- ;
217
224
  /**
218
225
  * Creates a mint instruction for the USDC+ stablecoin.
219
226
  *
@@ -227,7 +234,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
227
234
  const accounts = yield this.constructAccounts(signer, true);
228
235
  const ix = (0, reflect_main_1.createMintDriftS1Instruction)(accounts, {
229
236
  minUsdcAmount: minimumReceived,
230
- usdcAmount: amount
237
+ usdcAmount: amount,
231
238
  }, this.programId);
232
239
  return [ix];
233
240
  });
@@ -244,7 +251,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
244
251
  const ix = (0, reflect_main_1.createRedeemDriftS1Instruction)(accounts, {
245
252
  canChill: false,
246
253
  minLstRedeem: minimumReceived,
247
- rusdBurnAmount: amount
254
+ rusdBurnAmount: amount,
248
255
  }, this.programId);
249
256
  return [ix];
250
257
  });
@@ -260,7 +267,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
260
267
  const ix = new web3_js_1.TransactionInstruction({
261
268
  programId: web3_js_1.Keypair.generate().publicKey,
262
269
  data: Buffer.from(""),
263
- keys: []
270
+ keys: [],
264
271
  });
265
272
  return [ix];
266
273
  });
@@ -272,16 +279,12 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
272
279
  */
273
280
  getBaseUsdExchangeRate() {
274
281
  return __awaiter(this, void 0, void 0, function* () {
275
- const { scaledBalance, balanceType } = this
276
- .driftClient
277
- .getSpotPosition(0);
278
- const spotMarketAccount = this
279
- .driftClient
280
- .getSpotMarketAccount(0);
282
+ const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
283
+ const spotMarketAccount = this.driftClient.getSpotMarketAccount(0);
281
284
  const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
282
285
  const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
283
286
  const [{ mint: usdcMint }] = this.collaterals;
284
- const { data: [{ price: { expo, price } }] } = yield this.getCollateralPrice(usdcMint);
287
+ const { data: [{ price: { expo, price }, },], } = yield this.getCollateralPrice(usdcMint);
285
288
  const exchangeRate = usdcAmount
286
289
  .mul(new bn_js_1.default(price))
287
290
  .mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION)) // gives us exhcnage rate precision
@@ -301,12 +304,8 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
301
304
  */
302
305
  getBaseToCollateralExchangeRate() {
303
306
  return __awaiter(this, void 0, void 0, function* () {
304
- const { scaledBalance, balanceType } = this
305
- .driftClient
306
- .getSpotPosition(0);
307
- const spotMarketAccount = this
308
- .driftClient
309
- .getSpotMarketAccount(0);
307
+ const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
308
+ const spotMarketAccount = this.driftClient.getSpotMarketAccount(0);
310
309
  const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
311
310
  const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
312
311
  const exchangeRate = usdcAmount
@@ -431,7 +430,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
431
430
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
432
431
  state: yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID),
433
432
  depositorTokenAccount,
434
- drift: constants_1.DRIFT_PROGRAM_ID
433
+ drift: constants_1.DRIFT_PROGRAM_ID,
435
434
  }, {
436
435
  amount,
437
436
  controllerBump: bump,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/stable.ts",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "type": "commonjs",
5
5
  "author": "stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {