@reflectmoney/stable.ts 2.3.0 → 2.5.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.
- package/dist/classes/PdaClient.d.ts +6 -6
- package/dist/classes/PdaClient.js +13 -12
- package/dist/classes/Stablecoin.d.ts +11 -1
- package/dist/classes/Stablecoin.js +21 -30
- package/dist/stablecoins/LstStablecoin.d.ts +2 -0
- package/dist/stablecoins/LstStablecoin.js +10 -0
- package/dist/stablecoins/UsdcPlusStablecoin.d.ts +10 -0
- package/dist/stablecoins/UsdcPlusStablecoin.js +41 -11
- package/package.json +3 -2
|
@@ -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.
|
|
@@ -220,6 +220,16 @@ export declare abstract class Stablecoin<T extends Controller> {
|
|
|
220
220
|
* @returns Promise resolving to the USD exchange rate as a number
|
|
221
221
|
*/
|
|
222
222
|
abstract getReceiptUsdExchangeRate(): Promise<number>;
|
|
223
|
+
/**
|
|
224
|
+
* Abstract method to get the Base->Collateral exchange rate.
|
|
225
|
+
* Returned as an integer scaled by EXCHANGE_RATE_PRECISION.
|
|
226
|
+
*/
|
|
227
|
+
abstract getBaseToCollateralExchangeRate(): Promise<number>;
|
|
228
|
+
/**
|
|
229
|
+
* Abstract method to get the Receipt->Collateral exchange rate.
|
|
230
|
+
* Returned as an integer scaled by EXCHANGE_RATE_PRECISION.
|
|
231
|
+
*/
|
|
232
|
+
abstract getReceiptToCollateralExchangeRate(): Promise<number>;
|
|
223
233
|
/**
|
|
224
234
|
* Abstract method to simulate mint math and get the quote for a mint operation.
|
|
225
235
|
* Must be implemented by concrete stablecoin classes.
|
|
@@ -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
|
}, {
|
|
@@ -356,17 +357,12 @@ class Stablecoin {
|
|
|
356
357
|
*/
|
|
357
358
|
stablecoinToCollateralWithSlippage(amount, collateralMint, slippageBips) {
|
|
358
359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
const price = new bn_js_1.default(priceObj.price);
|
|
362
|
-
const expo = priceObj.expo;
|
|
363
|
-
const { decimals } = yield (0, spl_token_1.getMint)(this.connection, collateralMint);
|
|
360
|
+
// Use receipt-to-collateral exchange rate (already accounts for decimals)
|
|
361
|
+
const rate = new bn_js_1.default(yield this.getReceiptToCollateralExchangeRate()); // scaled by EXCHANGE_RATE_PRECISION
|
|
364
362
|
const collateralAmount = new bn_js_1.default(amount)
|
|
365
|
-
.mul(
|
|
363
|
+
.mul(rate)
|
|
366
364
|
.mul(new bn_js_1.default(10000 - slippageBips))
|
|
367
|
-
.div(new bn_js_1.default(
|
|
368
|
-
.div(price)
|
|
369
|
-
.div(new bn_js_1.default(10).pow(new bn_js_1.default(expo)))
|
|
365
|
+
.div(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION))
|
|
370
366
|
.div(new bn_js_1.default(10000));
|
|
371
367
|
return collateralAmount;
|
|
372
368
|
});
|
|
@@ -381,17 +377,12 @@ class Stablecoin {
|
|
|
381
377
|
*/
|
|
382
378
|
collateralToStablecoinWithSlippage(amount, collateralMint, slippageBips) {
|
|
383
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
const price = new bn_js_1.default(priceObj.price);
|
|
387
|
-
const expo = priceObj.expo;
|
|
388
|
-
const { decimals } = yield (0, spl_token_1.getMint)(this.connection, collateralMint);
|
|
380
|
+
// Invert the receipt-to-collateral exchange rate
|
|
381
|
+
const receiptToCollateralRate = new bn_js_1.default(yield this.getReceiptToCollateralExchangeRate()); // scaled
|
|
389
382
|
const stablecoinAmount = new bn_js_1.default(amount)
|
|
390
|
-
.mul(
|
|
391
|
-
.mul(new bn_js_1.default(10).pow(new bn_js_1.default(6))) // stablecoin decimals
|
|
383
|
+
.mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION))
|
|
392
384
|
.mul(new bn_js_1.default(10000 - slippageBips))
|
|
393
|
-
.div(
|
|
394
|
-
.div(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)))
|
|
385
|
+
.div(receiptToCollateralRate)
|
|
395
386
|
.div(new bn_js_1.default(10000));
|
|
396
387
|
return stablecoinAmount;
|
|
397
388
|
});
|
|
@@ -99,7 +99,9 @@ export declare class LstStablecoin extends Stablecoin<DriftLstController> {
|
|
|
99
99
|
* @returns Promise resolving to the USD exchange rate as a number
|
|
100
100
|
*/
|
|
101
101
|
getBaseUsdExchangeRate(): Promise<number>;
|
|
102
|
+
getBaseToCollateralExchangeRate(): Promise<number>;
|
|
102
103
|
getReceiptUsdExchangeRate(): Promise<number>;
|
|
104
|
+
getReceiptToCollateralExchangeRate(): Promise<number>;
|
|
103
105
|
simulateMintMath(): Promise<BN>;
|
|
104
106
|
simulateRedeemMath(): Promise<BN>;
|
|
105
107
|
}
|
|
@@ -312,6 +312,11 @@ class LstStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
312
312
|
return totalUsdValue;
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
|
+
getBaseToCollateralExchangeRate() {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
return this.getBaseUsdExchangeRate();
|
|
318
|
+
});
|
|
319
|
+
}
|
|
315
320
|
getReceiptUsdExchangeRate() {
|
|
316
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
322
|
const baseUsdExchangeRate = yield this.getBaseUsdExchangeRate();
|
|
@@ -325,6 +330,11 @@ class LstStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
325
330
|
return exchangeRate;
|
|
326
331
|
});
|
|
327
332
|
}
|
|
333
|
+
getReceiptToCollateralExchangeRate() {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
+
return this.getReceiptUsdExchangeRate();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
328
338
|
simulateMintMath() {
|
|
329
339
|
return __awaiter(this, void 0, void 0, function* () {
|
|
330
340
|
return new bn_js_1.default(0);
|
|
@@ -83,6 +83,16 @@ export declare class UsdcPlusStablecoin extends Stablecoin<DriftUsdcController>
|
|
|
83
83
|
*/
|
|
84
84
|
getBaseUsdExchangeRate(): Promise<number>;
|
|
85
85
|
getReceiptUsdExchangeRate(): Promise<number>;
|
|
86
|
+
/**
|
|
87
|
+
* Base (USDC) to Collateral (USDC) exchange rate.
|
|
88
|
+
* For USDC+, base and collateral are the same asset/decimals.
|
|
89
|
+
*/
|
|
90
|
+
getBaseToCollateralExchangeRate(): Promise<number>;
|
|
91
|
+
/**
|
|
92
|
+
* Receipt (USDC+) to Collateral (USDC) exchange rate.
|
|
93
|
+
* rate = deposited_vault_value / receipt_supply, scaled by EXCHANGE_RATE_PRECISION
|
|
94
|
+
*/
|
|
95
|
+
getReceiptToCollateralExchangeRate(): Promise<number>;
|
|
86
96
|
/**
|
|
87
97
|
* Math helper function that calculates receipt tokens to issue for a given deposit amount.
|
|
88
98
|
* Mirrors the compute_receipt_token function from Rust.
|
|
@@ -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
|
|
@@ -290,6 +291,35 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
290
291
|
return this.getBaseUsdExchangeRate();
|
|
291
292
|
});
|
|
292
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Base (USDC) to Collateral (USDC) exchange rate.
|
|
296
|
+
* For USDC+, base and collateral are the same asset/decimals.
|
|
297
|
+
*/
|
|
298
|
+
getBaseToCollateralExchangeRate() {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
const { scaledBalance, balanceType } = this
|
|
301
|
+
.driftClient
|
|
302
|
+
.getSpotPosition(0);
|
|
303
|
+
const spotMarketAccount = this
|
|
304
|
+
.driftClient
|
|
305
|
+
.getSpotMarketAccount(0);
|
|
306
|
+
const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
|
|
307
|
+
const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
|
|
308
|
+
const exchangeRate = usdcAmount
|
|
309
|
+
.mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION)) // gives us exhcnage rate precision
|
|
310
|
+
.div(new bn_js_1.default(supply.toString())); // price per stablecoin
|
|
311
|
+
return exchangeRate.toNumber();
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Receipt (USDC+) to Collateral (USDC) exchange rate.
|
|
316
|
+
* rate = deposited_vault_value / receipt_supply, scaled by EXCHANGE_RATE_PRECISION
|
|
317
|
+
*/
|
|
318
|
+
getReceiptToCollateralExchangeRate() {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
return this.getBaseToCollateralExchangeRate();
|
|
321
|
+
});
|
|
322
|
+
}
|
|
293
323
|
/**
|
|
294
324
|
* Math helper function that calculates receipt tokens to issue for a given deposit amount.
|
|
295
325
|
* Mirrors the compute_receipt_token function from Rust.
|
|
@@ -389,7 +419,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
389
419
|
depositor: signer,
|
|
390
420
|
spotMarket,
|
|
391
421
|
controllerTokenAccount,
|
|
392
|
-
main: classes_1.PdaClient.deriveMain(),
|
|
422
|
+
main: classes_1.PdaClient.deriveMain(this.devnet),
|
|
393
423
|
userAccount: (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
|
|
394
424
|
userStats: (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
|
|
395
425
|
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
|
+
"version": "2.5.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "stablecoinjesus @ Palindrome Engineering",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/palindrome-eng/reflect-delta-neutral.git"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "mocha --require ts-node/register ./tests/index.test.ts"
|
|
11
|
+
"test": "mocha --require ts-node/register ./tests/index.test.ts",
|
|
12
|
+
"test:slippage": "mocha --require ts-node/register ./tests/slippage.test.ts"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"@coral-xyz/anchor": "0.29.0",
|