@reflectmoney/stable.ts 2.8.1 → 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.
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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,
|