@reflectmoney/stable.ts 2.8.1 → 2.8.3
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,8 @@ 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
|
+
initializePollingDriftClient(): void;
|
|
36
|
+
initializeWebsocketDriftClient(): void;
|
|
35
37
|
/**
|
|
36
38
|
* Initializes the stablecoin drift account for the USDC+ controller.
|
|
37
39
|
*
|
|
@@ -37,28 +37,25 @@ 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
|
+
// Unless explicitly told to skip, default to polling Drift client.
|
|
55
|
+
// This may be skipped, and custom drift client initialization may be handled with `initializePollingDriftClient` or `initializeWebsocketDriftClient`.
|
|
56
|
+
if (!skipInitializeDriftClient) {
|
|
57
|
+
this.initializePollingDriftClient();
|
|
58
|
+
}
|
|
62
59
|
}
|
|
63
60
|
/**
|
|
64
61
|
* Loads the USDC+ controller data from the blockchain.
|
|
@@ -99,11 +96,13 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
99
96
|
main: classes_1.PdaClient.deriveMain(this.devnet),
|
|
100
97
|
driftUsdcController: this.controllerKey,
|
|
101
98
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
102
|
-
anchorRemainingAccounts: [
|
|
99
|
+
anchorRemainingAccounts: [
|
|
100
|
+
{
|
|
103
101
|
isSigner: false,
|
|
104
102
|
isWritable: false,
|
|
105
|
-
pubkey: this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT
|
|
106
|
-
}
|
|
103
|
+
pubkey: this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
107
106
|
}, {
|
|
108
107
|
mint,
|
|
109
108
|
cap,
|
|
@@ -113,6 +112,29 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
113
112
|
return [ix];
|
|
114
113
|
});
|
|
115
114
|
}
|
|
115
|
+
initializePollingDriftClient() {
|
|
116
|
+
this.driftClient = new sdk_2.DriftClient({
|
|
117
|
+
connection: this.connection,
|
|
118
|
+
env: this.devnet ? "devnet" : "mainnet-beta",
|
|
119
|
+
wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
|
|
120
|
+
authority: this.controllerKey,
|
|
121
|
+
accountSubscription: {
|
|
122
|
+
type: "polling",
|
|
123
|
+
accountLoader: new sdk_1.BulkAccountLoader(this.connection, "confirmed", 1000),
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
initializeWebsocketDriftClient() {
|
|
128
|
+
this.driftClient = new sdk_2.DriftClient({
|
|
129
|
+
connection: this.connection,
|
|
130
|
+
env: this.devnet ? "devnet" : "mainnet-beta",
|
|
131
|
+
wallet: new nodewallet_1.default(web3_js_1.Keypair.generate()),
|
|
132
|
+
authority: this.controllerKey,
|
|
133
|
+
accountSubscription: {
|
|
134
|
+
type: "websocket",
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
116
138
|
/**
|
|
117
139
|
* Initializes the stablecoin drift account for the USDC+ controller.
|
|
118
140
|
*
|
|
@@ -121,13 +143,10 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
121
143
|
*/
|
|
122
144
|
initializeStablecoinDriftAccount(signer) {
|
|
123
145
|
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 => ({
|
|
146
|
+
const anchorRemainingAccounts = [constants_1.REFERRAL_USER, constants_1.REFERRAL_USER_STATS].map((account) => ({
|
|
128
147
|
isSigner: false,
|
|
129
148
|
isWritable: true,
|
|
130
|
-
pubkey: account
|
|
149
|
+
pubkey: account,
|
|
131
150
|
}));
|
|
132
151
|
const ix = (0, reflect_main_1.createInitDriftAccountsS1Instruction)({
|
|
133
152
|
admin: signer,
|
|
@@ -140,7 +159,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
140
159
|
userAccount: (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
|
|
141
160
|
userStats: (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
|
|
142
161
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
143
|
-
anchorRemainingAccounts
|
|
162
|
+
anchorRemainingAccounts,
|
|
144
163
|
}, this.programId);
|
|
145
164
|
return ix;
|
|
146
165
|
});
|
|
@@ -181,10 +200,12 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
181
200
|
userReceiptAta,
|
|
182
201
|
userStats,
|
|
183
202
|
userUsdcAta,
|
|
184
|
-
adminPermissions: permissions
|
|
203
|
+
adminPermissions: permissions
|
|
204
|
+
? classes_1.PdaClient.derivePermissions(signer, this.devnet)
|
|
205
|
+
: null,
|
|
185
206
|
anchorRemainingAccounts,
|
|
186
207
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
187
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
208
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
188
209
|
};
|
|
189
210
|
return accounts;
|
|
190
211
|
});
|
|
@@ -203,17 +224,16 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
203
224
|
{
|
|
204
225
|
pubkey: oracle,
|
|
205
226
|
isSigner: false,
|
|
206
|
-
isWritable: true
|
|
227
|
+
isWritable: true,
|
|
207
228
|
},
|
|
208
229
|
{
|
|
209
230
|
pubkey: spotMarket,
|
|
210
231
|
isSigner: false,
|
|
211
|
-
isWritable: true
|
|
232
|
+
isWritable: true,
|
|
212
233
|
},
|
|
213
234
|
];
|
|
214
235
|
});
|
|
215
236
|
}
|
|
216
|
-
;
|
|
217
237
|
/**
|
|
218
238
|
* Creates a mint instruction for the USDC+ stablecoin.
|
|
219
239
|
*
|
|
@@ -227,7 +247,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
227
247
|
const accounts = yield this.constructAccounts(signer, true);
|
|
228
248
|
const ix = (0, reflect_main_1.createMintDriftS1Instruction)(accounts, {
|
|
229
249
|
minUsdcAmount: minimumReceived,
|
|
230
|
-
usdcAmount: amount
|
|
250
|
+
usdcAmount: amount,
|
|
231
251
|
}, this.programId);
|
|
232
252
|
return [ix];
|
|
233
253
|
});
|
|
@@ -244,7 +264,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
244
264
|
const ix = (0, reflect_main_1.createRedeemDriftS1Instruction)(accounts, {
|
|
245
265
|
canChill: false,
|
|
246
266
|
minLstRedeem: minimumReceived,
|
|
247
|
-
rusdBurnAmount: amount
|
|
267
|
+
rusdBurnAmount: amount,
|
|
248
268
|
}, this.programId);
|
|
249
269
|
return [ix];
|
|
250
270
|
});
|
|
@@ -260,7 +280,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
260
280
|
const ix = new web3_js_1.TransactionInstruction({
|
|
261
281
|
programId: web3_js_1.Keypair.generate().publicKey,
|
|
262
282
|
data: Buffer.from(""),
|
|
263
|
-
keys: []
|
|
283
|
+
keys: [],
|
|
264
284
|
});
|
|
265
285
|
return [ix];
|
|
266
286
|
});
|
|
@@ -272,16 +292,12 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
272
292
|
*/
|
|
273
293
|
getBaseUsdExchangeRate() {
|
|
274
294
|
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);
|
|
295
|
+
const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
|
|
296
|
+
const spotMarketAccount = this.driftClient.getSpotMarketAccount(0);
|
|
281
297
|
const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
|
|
282
298
|
const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
|
|
283
299
|
const [{ mint: usdcMint }] = this.collaterals;
|
|
284
|
-
const { data: [{ price: { expo, price } }] } = yield this.getCollateralPrice(usdcMint);
|
|
300
|
+
const { data: [{ price: { expo, price }, },], } = yield this.getCollateralPrice(usdcMint);
|
|
285
301
|
const exchangeRate = usdcAmount
|
|
286
302
|
.mul(new bn_js_1.default(price))
|
|
287
303
|
.mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION)) // gives us exhcnage rate precision
|
|
@@ -301,12 +317,8 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
301
317
|
*/
|
|
302
318
|
getBaseToCollateralExchangeRate() {
|
|
303
319
|
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);
|
|
320
|
+
const { scaledBalance, balanceType } = this.driftClient.getSpotPosition(0);
|
|
321
|
+
const spotMarketAccount = this.driftClient.getSpotMarketAccount(0);
|
|
310
322
|
const usdcAmount = (0, sdk_2.getTokenAmount)(scaledBalance, spotMarketAccount, balanceType);
|
|
311
323
|
const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
|
|
312
324
|
const exchangeRate = usdcAmount
|
|
@@ -431,7 +443,7 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
431
443
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
432
444
|
state: yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID),
|
|
433
445
|
depositorTokenAccount,
|
|
434
|
-
drift: constants_1.DRIFT_PROGRAM_ID
|
|
446
|
+
drift: constants_1.DRIFT_PROGRAM_ID,
|
|
435
447
|
}, {
|
|
436
448
|
amount,
|
|
437
449
|
controllerBump: bump,
|