@reflectmoney/stable.ts 2.3.0 → 2.4.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.
@@ -11,7 +11,7 @@ export declare class PdaClient {
11
11
  *
12
12
  * @returns PublicKey of the main program account
13
13
  */
14
- static deriveMain(): PublicKey;
14
+ static deriveMain(devnet?: boolean): PublicKey;
15
15
  /**
16
16
  * Derives the permissions account address for a specific user.
17
17
  * This account stores the user's role-based permissions within the protocol.
@@ -19,7 +19,7 @@ export declare class PdaClient {
19
19
  * @param user - Public key of the user
20
20
  * @returns PublicKey of the user's permissions account
21
21
  */
22
- static derivePermissions(user: PublicKey): PublicKey;
22
+ static derivePermissions(user: PublicKey, devnet?: boolean): PublicKey;
23
23
  /**
24
24
  * Derives the controller account address for a specific strategy.
25
25
  * Each stablecoin strategy has its own controller account.
@@ -27,7 +27,7 @@ export declare class PdaClient {
27
27
  * @param strategy - Strategy index (0: USDC+, 1: JLP, 2: LST)
28
28
  * @returns PublicKey of the strategy controller account
29
29
  */
30
- static deriveController(strategy: number): PublicKey;
30
+ static deriveController(strategy: number, devnet?: boolean): PublicKey;
31
31
  /**
32
32
  * Derives the controller account address with bump seed for a specific strategy.
33
33
  * Returns both the public key and the bump seed.
@@ -35,7 +35,7 @@ export declare class PdaClient {
35
35
  * @param strategy - Strategy index (0: USDC+, 1: JLP, 2: LST)
36
36
  * @returns Array containing [PublicKey, number] where number is the bump seed
37
37
  */
38
- static deriveControllerWithBump(strategy: number): [PublicKey, number];
38
+ static deriveControllerWithBump(strategy: number, devnet?: boolean): [PublicKey, number];
39
39
  /**
40
40
  * Derives the rebalance details account address for a specific strategy.
41
41
  * This account stores information about rebalancing operations.
@@ -43,14 +43,14 @@ export declare class PdaClient {
43
43
  * @param strategy - Strategy index (0: USDC+, 1: JLP, 2: LST)
44
44
  * @returns PublicKey of the rebalance details account
45
45
  */
46
- static deriveRebalanceDetails(strategy: number): PublicKey;
46
+ static deriveRebalanceDetails(strategy: number, devnet?: boolean): PublicKey;
47
47
  /**
48
48
  * Derives the Jupiter Perpetuals program account address.
49
49
  * Used for integration with Jupiter's perpetuals protocol.
50
50
  *
51
51
  * @returns PublicKey of the Jupiter Perpetuals account
52
52
  */
53
- static deriveJupiterPerpetuals(): PublicKey;
53
+ static deriveJupiterPerpetuals(devnet?: boolean): PublicKey;
54
54
  /**
55
55
  * Derives the Jupiter LP pool account address.
56
56
  * Used for JLP (Jupiter LP) token operations.
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.PdaClient = void 0;
16
16
  const web3_js_1 = require("@solana/web3.js");
17
17
  const reflect_main_1 = require("../generated/reflect_main");
18
+ const devnet_1 = require("../constants/devnet");
18
19
  const reflect_tokenised_bonds_1 = require("../generated/reflect_tokenised_bonds");
19
20
  const constants_1 = require("../constants");
20
21
  const bn_js_1 = __importDefault(require("bn.js"));
@@ -32,8 +33,8 @@ class PdaClient {
32
33
  *
33
34
  * @returns PublicKey of the main program account
34
35
  */
35
- static deriveMain() {
36
- const [main] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("main")], reflect_main_1.PROGRAM_ID);
36
+ static deriveMain(devnet) {
37
+ const [main] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("main")], devnet ? devnet_1.DEVNET_PROGRAM_ID : reflect_main_1.PROGRAM_ID);
37
38
  return main;
38
39
  }
39
40
  /**
@@ -43,11 +44,11 @@ class PdaClient {
43
44
  * @param user - Public key of the user
44
45
  * @returns PublicKey of the user's permissions account
45
46
  */
46
- static derivePermissions(user) {
47
+ static derivePermissions(user, devnet) {
47
48
  const [permissions] = web3_js_1.PublicKey.findProgramAddressSync([
48
49
  Buffer.from("user_permission"),
49
50
  user.toBuffer()
50
- ], reflect_main_1.PROGRAM_ID);
51
+ ], devnet ? devnet_1.DEVNET_PROGRAM_ID : reflect_main_1.PROGRAM_ID);
51
52
  return permissions;
52
53
  }
53
54
  /**
@@ -57,11 +58,11 @@ class PdaClient {
57
58
  * @param strategy - Strategy index (0: USDC+, 1: JLP, 2: LST)
58
59
  * @returns PublicKey of the strategy controller account
59
60
  */
60
- static deriveController(strategy) {
61
+ static deriveController(strategy, devnet) {
61
62
  const [controller] = web3_js_1.PublicKey.findProgramAddressSync([
62
63
  Buffer.from("dex_controller"),
63
64
  Buffer.from([strategy])
64
- ], reflect_main_1.PROGRAM_ID);
65
+ ], devnet ? devnet_1.DEVNET_PROGRAM_ID : reflect_main_1.PROGRAM_ID);
65
66
  return controller;
66
67
  }
67
68
  /**
@@ -71,11 +72,11 @@ class PdaClient {
71
72
  * @param strategy - Strategy index (0: USDC+, 1: JLP, 2: LST)
72
73
  * @returns Array containing [PublicKey, number] where number is the bump seed
73
74
  */
74
- static deriveControllerWithBump(strategy) {
75
+ static deriveControllerWithBump(strategy, devnet) {
75
76
  return web3_js_1.PublicKey.findProgramAddressSync([
76
77
  Buffer.from("dex_controller"),
77
78
  Buffer.from([strategy])
78
- ], reflect_main_1.PROGRAM_ID);
79
+ ], devnet ? devnet_1.DEVNET_PROGRAM_ID : reflect_main_1.PROGRAM_ID);
79
80
  }
80
81
  /**
81
82
  * Derives the rebalance details account address for a specific strategy.
@@ -84,11 +85,11 @@ class PdaClient {
84
85
  * @param strategy - Strategy index (0: USDC+, 1: JLP, 2: LST)
85
86
  * @returns PublicKey of the rebalance details account
86
87
  */
87
- static deriveRebalanceDetails(strategy) {
88
+ static deriveRebalanceDetails(strategy, devnet) {
88
89
  const [rebalanceDetails] = web3_js_1.PublicKey.findProgramAddressSync([
89
90
  Buffer.from("rebalance_details"),
90
91
  this.deriveController(strategy).toBuffer()
91
- ], reflect_main_1.PROGRAM_ID);
92
+ ], devnet ? devnet_1.DEVNET_PROGRAM_ID : reflect_main_1.PROGRAM_ID);
92
93
  return rebalanceDetails;
93
94
  }
94
95
  /**
@@ -97,10 +98,10 @@ class PdaClient {
97
98
  *
98
99
  * @returns PublicKey of the Jupiter Perpetuals account
99
100
  */
100
- static deriveJupiterPerpetuals() {
101
+ static deriveJupiterPerpetuals(devnet) {
101
102
  const [perpetuals] = web3_js_1.PublicKey.findProgramAddressSync([
102
103
  Buffer.from("perpetuals")
103
- ], constants_1.JUPITER_PROGRAM_ID);
104
+ ], devnet ? devnet_1.DEVNET_PROGRAM_ID : constants_1.JUPITER_PROGRAM_ID);
104
105
  return perpetuals;
105
106
  }
106
107
  /**
@@ -66,7 +66,7 @@ export declare abstract class Stablecoin<T extends Controller> {
66
66
  * @param name - Human-readable name for the stablecoin
67
67
  * @param connection - Solana connection instance
68
68
  */
69
- constructor(index: number, name: string, connection: Connection, lookupTable: PublicKey);
69
+ constructor(index: number, name: string, connection: Connection, lookupTable: PublicKey, devnet?: boolean);
70
70
  /**
71
71
  * Initializes token accounts for the specified owner and mints.
72
72
  * Creates associated token accounts if they don't exist.
@@ -126,12 +126,13 @@ class Stablecoin {
126
126
  * @param name - Human-readable name for the stablecoin
127
127
  * @param connection - Solana connection instance
128
128
  */
129
- constructor(index, name, connection, lookupTable) {
129
+ constructor(index, name, connection, lookupTable, devnet) {
130
130
  this.index = index;
131
131
  this.name = name;
132
132
  this.connection = connection;
133
- this.controllerKey = PdaClient_1.PdaClient.deriveController(this.index);
133
+ this.controllerKey = PdaClient_1.PdaClient.deriveController(this.index, devnet);
134
134
  this.lookupTable = lookupTable;
135
+ this.devnet = devnet;
135
136
  }
136
137
  /**
137
138
  * Initializes token accounts for the specified owner and mints.
@@ -173,8 +174,8 @@ class Stablecoin {
173
174
  return __awaiter(this, void 0, void 0, function* () {
174
175
  const ix = (0, reflect_main_1.createUpdateCapInstruction)({
175
176
  admin: signer,
176
- main: PdaClient_1.PdaClient.deriveMain(),
177
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
177
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
178
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
178
179
  systemProgram: web3_js_1.SystemProgram.programId,
179
180
  strategy: this.controllerKey
180
181
  }, {
@@ -193,8 +194,8 @@ class Stablecoin {
193
194
  updateRecipients(signer, recipients) {
194
195
  return __awaiter(this, void 0, void 0, function* () {
195
196
  const ix = (0, reflect_main_1.createUpdateRecipientsInstruction)({
196
- main: PdaClient_1.PdaClient.deriveMain(),
197
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
197
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
198
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
198
199
  systemProgram: web3_js_1.SystemProgram.programId,
199
200
  admin: signer,
200
201
  strategy: this.controllerKey
@@ -230,8 +231,8 @@ class Stablecoin {
230
231
  state: yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID),
231
232
  userStats,
232
233
  userAccount,
233
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
234
- main: PdaClient_1.PdaClient.deriveMain(),
234
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
235
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
235
236
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
236
237
  systemProgram: web3_js_1.SystemProgram.programId,
237
238
  lstController: this.controllerKey,
@@ -252,10 +253,10 @@ class Stablecoin {
252
253
  const userStats = (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey);
253
254
  const ix = (0, reflect_main_1.createCreateUserStatsAccountInstruction)({
254
255
  admin: signer,
255
- main: PdaClient_1.PdaClient.deriveMain(),
256
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
256
257
  drift: constants_1.DRIFT_PROGRAM_ID,
257
258
  userStats,
258
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
259
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
259
260
  controller: this.controllerKey,
260
261
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
261
262
  state: yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID),
@@ -276,8 +277,8 @@ class Stablecoin {
276
277
  return __awaiter(this, void 0, void 0, function* () {
277
278
  const ix = (0, reflect_main_1.createFreezeStrategyActionInstruction)({
278
279
  admin: signer,
279
- main: PdaClient_1.PdaClient.deriveMain(),
280
- adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
280
+ main: PdaClient_1.PdaClient.deriveMain(this.devnet),
281
+ adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer, this.devnet),
281
282
  systemProgram: web3_js_1.SystemProgram.programId,
282
283
  strategy: this.controllerKey,
283
284
  }, {
@@ -38,7 +38,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
38
38
  * @param stablecoinMintOverride - Optional override for the stablecoin mint address
39
39
  */
40
40
  constructor(connection, stablecoinMintOverride, devnet) {
41
- super(0, "USD Coin Plus", connection, devnet ? constants_3.USDC_PLUS_LOOKUP_TABLE_DEVNET : constants_2.USDC_PLUS_LOOKUP_TABLE);
41
+ super(0, "USD Coin Plus", connection, devnet ? constants_3.USDC_PLUS_LOOKUP_TABLE_DEVNET : constants_2.USDC_PLUS_LOOKUP_TABLE, devnet);
42
42
  this.collaterals = [{
43
43
  mint: devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT,
44
44
  oracle: "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
@@ -51,6 +51,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
51
51
  authority: this.controllerKey
52
52
  });
53
53
  this.isPermissioned = true;
54
+ this.devnet = devnet;
54
55
  // Otherwise has to be loaded first.
55
56
  if (stablecoinMintOverride)
56
57
  this.stablecoinMint = stablecoinMintOverride;
@@ -90,14 +91,14 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
90
91
  return __awaiter(this, void 0, void 0, function* () {
91
92
  const ix = (0, reflect_main_1.createInitDriftControllerS1Instruction)({
92
93
  admin: signer,
93
- adminPermissions: classes_1.PdaClient.derivePermissions(signer),
94
- main: classes_1.PdaClient.deriveMain(),
94
+ adminPermissions: classes_1.PdaClient.derivePermissions(signer, this.devnet),
95
+ main: classes_1.PdaClient.deriveMain(this.devnet),
95
96
  driftUsdcController: this.controllerKey,
96
97
  systemProgram: web3_js_1.SystemProgram.programId,
97
98
  anchorRemainingAccounts: [{
98
99
  isSigner: false,
99
100
  isWritable: false,
100
- pubkey: constants_1.USDC_MINT
101
+ pubkey: this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT
101
102
  }]
102
103
  }, {
103
104
  mint,
@@ -126,8 +127,8 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
126
127
  }));
127
128
  const ix = (0, reflect_main_1.createInitDriftAccountsS1Instruction)({
128
129
  admin: signer,
129
- adminPermissions: classes_1.PdaClient.derivePermissions(signer),
130
- main: classes_1.PdaClient.deriveMain(),
130
+ adminPermissions: classes_1.PdaClient.derivePermissions(signer, this.devnet),
131
+ main: classes_1.PdaClient.deriveMain(this.devnet),
131
132
  usdcController: this.controllerKey,
132
133
  systemProgram: web3_js_1.SystemProgram.programId,
133
134
  drift: constants_1.DRIFT_PROGRAM_ID,
@@ -154,9 +155,9 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
154
155
  const { referrer } = yield (0, sdk_1.fetchUserStatsAccount)(this.connection, this.driftClient.program, this.controllerKey);
155
156
  const referrerUser = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, referrer);
156
157
  const referrerUserStats = (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, referrer);
157
- const userUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(constants_1.USDC_MINT, signer, true);
158
+ const userUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT, signer, true);
158
159
  const userReceiptAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.stablecoinMint, signer, true);
159
- const controllerUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(constants_1.USDC_MINT, this.controllerKey, true);
160
+ const controllerUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT, this.controllerKey, true);
160
161
  const spotMarketVault = yield (0, sdk_1.getSpotMarketVaultPublicKey)(constants_1.DRIFT_PROGRAM_ID, 0);
161
162
  const driftState = yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID);
162
163
  const accounts = {
@@ -164,7 +165,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
164
165
  controllerUsdcAta,
165
166
  drift: constants_1.DRIFT_PROGRAM_ID,
166
167
  driftVault: constants_1.DRIFT_VAULT,
167
- main: classes_1.PdaClient.deriveMain(),
168
+ main: classes_1.PdaClient.deriveMain(this.devnet),
168
169
  receiptMint: this.stablecoinMint,
169
170
  referrerUser,
170
171
  referrerUserStats,
@@ -176,7 +177,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
176
177
  userReceiptAta,
177
178
  userStats,
178
179
  userUsdcAta,
179
- adminPermissions: permissions ? classes_1.PdaClient.derivePermissions(signer) : null,
180
+ adminPermissions: permissions ? classes_1.PdaClient.derivePermissions(signer, this.devnet) : null,
180
181
  anchorRemainingAccounts,
181
182
  systemProgram: web3_js_1.SystemProgram.programId,
182
183
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
@@ -389,7 +390,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
389
390
  depositor: signer,
390
391
  spotMarket,
391
392
  controllerTokenAccount,
392
- main: classes_1.PdaClient.deriveMain(),
393
+ main: classes_1.PdaClient.deriveMain(this.devnet),
393
394
  userAccount: (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
394
395
  userStats: (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
395
396
  spotMarketVault: yield (0, sdk_1.getSpotMarketVaultPublicKey)(constants_1.DRIFT_PROGRAM_ID, 0),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reflectmoney/stable.ts",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "type": "commonjs",
5
5
  "author": "stablecoinjesus @ Palindrome Engineering",
6
6
  "repository": {