@reflectmoney/stable.ts 1.0.2 → 1.0.4
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/README.md +114 -103
- package/dist/classes/ReflectKeeper.d.ts +104 -0
- package/dist/classes/ReflectKeeper.js +219 -0
- package/dist/classes/Stablecoin.d.ts +3 -1
- package/dist/classes/Stablecoin.js +2 -1
- package/dist/classes/index.d.ts +1 -1
- package/dist/classes/index.js +1 -1
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/lookupTables.d.ts +4 -0
- package/dist/constants/lookupTables.js +7 -0
- package/dist/stablecoins/LstStablecoin.js +1 -1
- package/dist/stablecoins/UsdcPlusStablecoin.d.ts +66 -0
- package/dist/stablecoins/UsdcPlusStablecoin.js +197 -0
- package/dist/stablecoins/UsdjStablecoin.d.ts +1 -0
- package/dist/stablecoins/UsdjStablecoin.js +44 -0
- package/dist/stablecoins/index.d.ts +2 -2
- package/dist/stablecoins/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
# Reflect Money
|
|
1
|
+
# Reflect Money SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript SDK for interacting with the Reflect programs on Solana. This SDK provides high-level abstractions for minting, redeeming, and managing stablecoins, administrative operations, and protocol integrations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @reflectmoney/stable.ts
|
|
9
|
+
# or
|
|
10
|
+
yarn add @reflectmoney/stable.ts
|
|
11
|
+
```
|
|
4
12
|
|
|
5
13
|
## Overview
|
|
6
14
|
|
|
7
|
-
The Reflect
|
|
15
|
+
The Reflect SDK enables developers to interact with the protocol via three main Reflect stablecoins:
|
|
8
16
|
|
|
9
|
-
1. **USDC+ (
|
|
10
|
-
2. **JLP Hedged (
|
|
11
|
-
3. **LST Delta-Neutral (
|
|
17
|
+
1. **USDC+ (Index 0)**: Stablecoin backed by USDC deployed in various money markets
|
|
18
|
+
2. **JLP Hedged (Index 1)**: Stablecoin backed by the JLP token, neutralized with perpetual hedging strategies
|
|
19
|
+
3. **LST Delta-Neutral (Index 2)**: Stablecoin backed by LSTs hedged by perpetual futures positions
|
|
12
20
|
|
|
13
21
|
## Architecture
|
|
14
22
|
|
|
@@ -17,153 +25,156 @@ The SDK is organized into several key components:
|
|
|
17
25
|
### Core Classes
|
|
18
26
|
|
|
19
27
|
#### `Stablecoin` (Abstract Base Class)
|
|
20
|
-
The foundation for all stablecoin implementations. Provides common interface for:
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
28
|
+
The foundation for all stablecoin implementations. Provides abstract functions and a common interface for:
|
|
29
|
+
- Minting
|
|
30
|
+
- Redemption
|
|
31
|
+
- Administrative operations
|
|
24
32
|
|
|
25
33
|
**Key Methods:**
|
|
26
|
-
- `initialize()` - Initialize the stablecoin strategy (admin-only)
|
|
27
34
|
- `mint()` - Create mint instructions
|
|
28
35
|
- `redeem()` - Create redemption instructions
|
|
29
|
-
- `rebalance()` - Create
|
|
30
|
-
- `updateCap()` - Update supply cap (admin-only)
|
|
31
|
-
- `updateRecipients()` - Update fee recipients (admin-only)
|
|
36
|
+
- `rebalance()` - Create rebalance instructions (admin-only or permissionless, depending on the strategy)
|
|
32
37
|
|
|
33
|
-
#### `
|
|
34
|
-
Administrative client for protocol-level operations
|
|
35
|
-
- Protocol initialization
|
|
36
|
-
- Role and permission management
|
|
37
|
-
- Action freezing/unfreezing
|
|
38
|
-
- Admin account creation
|
|
39
|
-
|
|
40
|
-
**Key Methods:**
|
|
41
|
-
- `initializeMain()` - Initialize the main program account
|
|
42
|
-
- `freezeProtocolAction()` - Freeze/unfreeze protocol actions
|
|
43
|
-
- `updateRoleHolderProtocol()` - Update protocol-level permissions
|
|
44
|
-
- `createAdminAccount()` - Create new admin accounts
|
|
38
|
+
#### `ReflectKeeper`
|
|
39
|
+
Administrative client for protocol-level operations (admin-only).
|
|
45
40
|
|
|
46
41
|
#### `PdaClient`
|
|
47
|
-
Utility class for deriving
|
|
48
|
-
-
|
|
49
|
-
-
|
|
42
|
+
Utility class for deriving PDAs:
|
|
43
|
+
- Configuration program accounts
|
|
44
|
+
- Stablecoin controllers
|
|
50
45
|
- Permission accounts
|
|
51
|
-
- External protocol integrations (Drift, Jupiter)
|
|
46
|
+
- External protocol integrations (Drift, Jupiter, Tokenized Bond)
|
|
52
47
|
|
|
53
|
-
#### `
|
|
54
|
-
Client for tokenized bonds program
|
|
48
|
+
#### `ReflectTokenizedBond`
|
|
49
|
+
Client for the tokenized bonds program used for wrapping base stablecoins into yield-bearing receipts. Allows for:
|
|
55
50
|
- Vault creation and management
|
|
56
51
|
- Receipt token generation
|
|
57
52
|
- Deposit and withdrawal operations
|
|
58
53
|
|
|
59
54
|
### Stablecoin Implementations
|
|
60
55
|
|
|
61
|
-
#### `
|
|
62
|
-
|
|
56
|
+
#### `UsdcPlusStablecoin`
|
|
57
|
+
USDC+ is a stablecoin backed by USDC deployed in money markets. Implementation details:
|
|
58
|
+
- Status: Live
|
|
63
59
|
- Strategy ID: 0
|
|
64
60
|
- Collateral: USDC
|
|
65
|
-
- Integrated with
|
|
61
|
+
- Integrated with the tokenized bonds program at the protocol level
|
|
62
|
+
- Users only receive the yield-bearing stablecoin
|
|
63
|
+
- Does not require rebalancing
|
|
66
64
|
|
|
67
|
-
#### `
|
|
68
|
-
|
|
65
|
+
#### `UsdjStablecoin`
|
|
66
|
+
Stablecoin backed by JLP neutralized with perpetual hedging:
|
|
67
|
+
- Status: Coming soon
|
|
69
68
|
- Strategy ID: 1
|
|
70
69
|
- Collateral: JLP (Jupiter LP tokens)
|
|
70
|
+
- Requires manual wrapping via the Tokenized Bonds program
|
|
71
|
+
- Requires rebalancing, currently permissioned
|
|
71
72
|
|
|
72
73
|
#### `LstStablecoin`
|
|
73
74
|
Liquid staking token delta-neutral strategy:
|
|
75
|
+
- Status: Live
|
|
74
76
|
- Strategy ID: 2
|
|
75
|
-
- Collateral: Various LSTs (mSOL, jitoSOL, etc.)
|
|
77
|
+
- Collateral: Various LSTs (mSOL, jitoSOL, etc.) - use `load()` functionality to fetch the currently supported list of collateral assets
|
|
78
|
+
- Requires manual wrapping via the Tokenized Bonds program
|
|
79
|
+
- Requires rebalancing, currently permissioned
|
|
76
80
|
|
|
77
|
-
##
|
|
81
|
+
## Usage
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
npm install @reflectmoney/stable.ts
|
|
81
|
-
# or
|
|
82
|
-
yarn add @reflectmoney/stable.ts
|
|
83
|
-
```
|
|
83
|
+
Follow the snippets below to mint and redeem Reflect stablecoins. All Stablecoin subclasses expose methods following the same schema, so the code below works interchangeably with minor changes - simply change between the three:
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
const stablecoin = new UsdcPlusStablecoin(connection);
|
|
87
|
+
const stablecoin = new UsdjStablecoin(connection);
|
|
88
|
+
const stablecoin = new LstStablecoin(connection);
|
|
89
|
+
```
|
|
86
90
|
|
|
87
91
|
### Minting Stablecoins
|
|
88
92
|
|
|
89
93
|
```typescript
|
|
90
|
-
import {
|
|
91
|
-
import { PublicKey } from '@solana/web3.js';
|
|
94
|
+
import { UsdcPlusStablecoin } from '@reflectmoney/stable.ts';
|
|
95
|
+
import { PublicKey, Keypair, Connection, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
|
|
92
96
|
import BN from 'bn.js';
|
|
93
97
|
|
|
94
|
-
|
|
98
|
+
// Use an actual user's public key, read from wallet adapter or local environment.
|
|
99
|
+
const user = Keypair.generate();
|
|
100
|
+
const stablecoin = new UsdcPlusStablecoin(connection);
|
|
101
|
+
|
|
102
|
+
// Load controller data for the most up-to-date stablecoin setup.
|
|
103
|
+
await stablecoin.load(connection);
|
|
104
|
+
|
|
105
|
+
// Mint stablecoins against USDC collateral
|
|
106
|
+
const instructions = await stablecoin.mint(
|
|
107
|
+
user.publicKey,
|
|
108
|
+
new BN(1000 * 1_000_000), // Deposit collateral of 1,000 USDC (6 decimals)
|
|
109
|
+
new BN(999 * 1_000_000), // Minimum received USDC+ (0.1% slippage protection)
|
|
110
|
+
);
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
await lstStablecoin.load(connection);
|
|
112
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
98
113
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
new BN(999000), // Minimum received (slippage protection)
|
|
104
|
-
new PublicKey("<jitoSOL mint>") // LST mint address
|
|
114
|
+
const {
|
|
115
|
+
value: lookupTable
|
|
116
|
+
} = await connection.getAddressLookupTable(
|
|
117
|
+
stablecoin.lookupTable
|
|
105
118
|
);
|
|
119
|
+
|
|
120
|
+
const message = new TransactionMessage({
|
|
121
|
+
instructions,
|
|
122
|
+
payerKey: user.publicKey,
|
|
123
|
+
recentBlockhash: blockhash
|
|
124
|
+
}).compileToV0Message([lookupTable]);
|
|
125
|
+
|
|
126
|
+
const transaction = new VersionedTransaction(message);
|
|
127
|
+
|
|
128
|
+
// Transaction signature and confirmation logic, adjust for your needs.
|
|
129
|
+
transaction.sign([user]);
|
|
130
|
+
await connection.sendRawTransaction(transaction.serialize());
|
|
106
131
|
```
|
|
107
132
|
|
|
108
|
-
###
|
|
133
|
+
### Redeeming Stablecoins
|
|
109
134
|
|
|
110
135
|
```typescript
|
|
111
|
-
import {
|
|
136
|
+
import { UsdcPlusStablecoin } from '@reflectmoney/stable.ts';
|
|
137
|
+
import { PublicKey, Keypair, Connection, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
|
|
138
|
+
import BN from 'bn.js';
|
|
112
139
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
140
|
+
// Use an actual user's public key, read from wallet adapter or local environment.
|
|
141
|
+
const user = Keypair.generate();
|
|
142
|
+
const stablecoin = new UsdcPlusStablecoin(connection);
|
|
117
143
|
|
|
118
|
-
//
|
|
119
|
-
|
|
144
|
+
// Load controller data for the most up-to-date stablecoin setup.
|
|
145
|
+
await stablecoin.load(connection);
|
|
120
146
|
|
|
121
|
-
//
|
|
122
|
-
const
|
|
123
|
-
|
|
147
|
+
// Redeem USDC+ into USDC
|
|
148
|
+
const instructions = await stablecoin.redeem(
|
|
149
|
+
user.publicKey,
|
|
150
|
+
new BN(999 * 1_000_000), // Burn 999 of USDC+
|
|
151
|
+
new BN(1_000 * 1_000_000), // Minimum received USDC (USDC+ is yield bearing, so you'll receive more USDC over time)
|
|
152
|
+
);
|
|
124
153
|
|
|
125
|
-
|
|
154
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
126
155
|
|
|
127
|
-
|
|
156
|
+
const {
|
|
157
|
+
value: lookupTable
|
|
158
|
+
} = await connection.getAddressLookupTable(
|
|
159
|
+
stablecoin.lookupTable
|
|
160
|
+
);
|
|
128
161
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async mint(signer: PublicKey, amount: BN, minimumReceived: BN, ...args: any[]): Promise<TransactionInstruction[]> {
|
|
143
|
-
// Custom minting logic
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async redeem(signer: PublicKey, amount: BN, minimumReceived: BN, ...args: any[]): Promise<TransactionInstruction[]> {
|
|
147
|
-
// Custom redemption logic
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
async rebalance(signer: PublicKey): Promise<TransactionInstruction[]> {
|
|
151
|
-
// Custom rebalancing logic
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async constructAccounts<T>(signer: PublicKey, ...args: any[]): Promise<T> {
|
|
155
|
-
// Custom account construction
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async constructRemainingAccounts(): Promise<AccountMeta[]> {
|
|
159
|
-
// Custom remaining accounts
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
+
const message = new TransactionMessage({
|
|
163
|
+
instructions,
|
|
164
|
+
payerKey: user.publicKey,
|
|
165
|
+
recentBlockhash: blockhash
|
|
166
|
+
}).compileToV0Message([lookupTable]);
|
|
167
|
+
|
|
168
|
+
const transaction = new VersionedTransaction(message);
|
|
169
|
+
|
|
170
|
+
// Transaction signature and confirmation logic, adjust for your needs.
|
|
171
|
+
transaction.sign([user]);
|
|
172
|
+
await connection.sendRawTransaction(transaction.serialize());
|
|
162
173
|
```
|
|
163
174
|
|
|
164
175
|
### Integration with External Protocols
|
|
165
176
|
|
|
166
|
-
The SDK is built
|
|
177
|
+
The SDK is built with integration for:
|
|
167
178
|
- **Drift Protocol**: For perpetual futures and spot trading
|
|
168
179
|
- **Jupiter Protocol**: For LP token operations and swaps
|
|
169
180
|
- **Pyth Network**: For price oracle data
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { Action, Role, Update } from "../generated/reflect_main";
|
|
3
|
+
/**
|
|
4
|
+
* Administrative client for the Reflect protocol.
|
|
5
|
+
* Provides functionality for protocol-level administration including:
|
|
6
|
+
* - Protocol initialization and setup
|
|
7
|
+
* - Role and permission management
|
|
8
|
+
* - Action freezing/unfreezing
|
|
9
|
+
* - Admin account creation and management
|
|
10
|
+
*
|
|
11
|
+
* This class is used by protocol administrators to manage global settings,
|
|
12
|
+
* user permissions, and protocol-wide configurations.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ReflectAdmin {
|
|
15
|
+
/** Public key of the admin user */
|
|
16
|
+
private admin;
|
|
17
|
+
/** Public key of the main program account */
|
|
18
|
+
private main;
|
|
19
|
+
/** Solana connection instance for RPC communication */
|
|
20
|
+
private connection;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ReflectAdmin instance.
|
|
23
|
+
*
|
|
24
|
+
* @param admin - Public key of the admin user
|
|
25
|
+
* @param connection - Solana connection instance
|
|
26
|
+
*/
|
|
27
|
+
constructor({ admin, connection }: {
|
|
28
|
+
admin: PublicKey;
|
|
29
|
+
connection: Connection;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Creates the main program account. This is the initial step of protocol setup.
|
|
33
|
+
*
|
|
34
|
+
* @param admin - Public key of the initial admin
|
|
35
|
+
* @returns TransactionInstruction for initializing the main account
|
|
36
|
+
*/
|
|
37
|
+
static initializeMain(admin: PublicKey): import("@solana/web3.js").TransactionInstruction;
|
|
38
|
+
/**
|
|
39
|
+
* Freezes or unfreezes a specific protocol action.
|
|
40
|
+
*
|
|
41
|
+
* @param freeze - Whether to freeze (true) or unfreeze (false) the action
|
|
42
|
+
* @param action - The action to freeze/unfreeze
|
|
43
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
44
|
+
*/
|
|
45
|
+
freezeProtocolAction(freeze: boolean, action: Action): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
46
|
+
/**
|
|
47
|
+
* Freezes or unfreezes a specific DEX program.
|
|
48
|
+
*
|
|
49
|
+
* @param freeze - Whether to freeze (true) or unfreeze (false) the program
|
|
50
|
+
* @param programIndex - Index of the program to freeze/unfreeze
|
|
51
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
52
|
+
*/
|
|
53
|
+
freezeDex(freeze: boolean, programIndex: number): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new admin account with specified permissions.
|
|
56
|
+
*
|
|
57
|
+
* @param signer - Public key of the caller (must be existing admin)
|
|
58
|
+
* @param newAdmin - Public key of the new admin to create
|
|
59
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
60
|
+
*/
|
|
61
|
+
createAdminAccount(signer: PublicKey, newAdmin: PublicKey): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
62
|
+
/**
|
|
63
|
+
* Updates role holder permissions at the protocol level.
|
|
64
|
+
*
|
|
65
|
+
* @param signer - Public key of the admin signer
|
|
66
|
+
* @param adminToUpdate - Public key of the admin whose permissions are being updated
|
|
67
|
+
* @param affectedRole - The role being modified
|
|
68
|
+
* @param update - The type of update (Grant or Revoke)
|
|
69
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
70
|
+
*/
|
|
71
|
+
updateRoleHolderProtocol(signer: PublicKey, adminToUpdate: PublicKey, affectedRole: Role, update: Update): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
72
|
+
/**
|
|
73
|
+
* Updates role holder permissions for a specific strategy.
|
|
74
|
+
*
|
|
75
|
+
* @param signer - Public key of the admin signer
|
|
76
|
+
* @param strategyId - ID of the strategy to update permissions for
|
|
77
|
+
* @param adminToUpdate - Public key of the admin whose permissions are being updated
|
|
78
|
+
* @param affectedRole - The role being modified
|
|
79
|
+
* @param update - The type of update (Grant or Revoke)
|
|
80
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
81
|
+
*/
|
|
82
|
+
updateRoleHolderStrategy(signer: PublicKey, strategyId: number, adminToUpdate: PublicKey, affectedRole: Role, update: Update): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
83
|
+
/**
|
|
84
|
+
* Updates action role permissions for a specific strategy.
|
|
85
|
+
*
|
|
86
|
+
* @param signer - Public key of the admin signer
|
|
87
|
+
* @param strategyId - ID of the strategy to update permissions for
|
|
88
|
+
* @param action - The action being modified
|
|
89
|
+
* @param affectedRole - The role being modified
|
|
90
|
+
* @param update - The type of update (Grant or Revoke)
|
|
91
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
92
|
+
*/
|
|
93
|
+
updateActionRoleStrategy(signer: PublicKey, strategyId: number, action: Action, affectedRole: Role, update: Update): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
94
|
+
/**
|
|
95
|
+
* Updates action role permissions at the protocol level.
|
|
96
|
+
*
|
|
97
|
+
* @param signer - Public key of the admin signer
|
|
98
|
+
* @param action - The action being modified
|
|
99
|
+
* @param affectedRole - The role being modified
|
|
100
|
+
* @param update - The type of update (Grant or Revoke)
|
|
101
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
102
|
+
*/
|
|
103
|
+
updateActionRoleProtocol(signer: PublicKey, action: Action, affectedRole: Role, update: Update): Promise<import("@solana/web3.js").TransactionInstruction>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ReflectAdmin = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const reflect_main_1 = require("../generated/reflect_main");
|
|
15
|
+
const PdaClient_1 = require("./PdaClient");
|
|
16
|
+
/**
|
|
17
|
+
* Administrative client for the Reflect protocol.
|
|
18
|
+
* Provides functionality for protocol-level administration including:
|
|
19
|
+
* - Protocol initialization and setup
|
|
20
|
+
* - Role and permission management
|
|
21
|
+
* - Action freezing/unfreezing
|
|
22
|
+
* - Admin account creation and management
|
|
23
|
+
*
|
|
24
|
+
* This class is used by protocol administrators to manage global settings,
|
|
25
|
+
* user permissions, and protocol-wide configurations.
|
|
26
|
+
*/
|
|
27
|
+
class ReflectAdmin {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new ReflectAdmin instance.
|
|
30
|
+
*
|
|
31
|
+
* @param admin - Public key of the admin user
|
|
32
|
+
* @param connection - Solana connection instance
|
|
33
|
+
*/
|
|
34
|
+
constructor({ admin, connection }) {
|
|
35
|
+
this.admin = admin;
|
|
36
|
+
this.connection = connection;
|
|
37
|
+
this.main = PdaClient_1.PdaClient.deriveMain();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates the main program account. This is the initial step of protocol setup.
|
|
41
|
+
*
|
|
42
|
+
* @param admin - Public key of the initial admin
|
|
43
|
+
* @returns TransactionInstruction for initializing the main account
|
|
44
|
+
*/
|
|
45
|
+
static initializeMain(admin) {
|
|
46
|
+
const [main] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("main")], reflect_main_1.PROGRAM_ID);
|
|
47
|
+
const ix = (0, reflect_main_1.createInitMainInstruction)({
|
|
48
|
+
main,
|
|
49
|
+
admin,
|
|
50
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
51
|
+
creds: PdaClient_1.PdaClient.derivePermissions(admin)
|
|
52
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
53
|
+
return ix;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Freezes or unfreezes a specific protocol action.
|
|
57
|
+
*
|
|
58
|
+
* @param freeze - Whether to freeze (true) or unfreeze (false) the action
|
|
59
|
+
* @param action - The action to freeze/unfreeze
|
|
60
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
61
|
+
*/
|
|
62
|
+
freezeProtocolAction(freeze, action) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const ix = (0, reflect_main_1.createFreezeProtocolActionInstruction)({
|
|
65
|
+
admin: this.admin,
|
|
66
|
+
main: this.main,
|
|
67
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
68
|
+
adminPermissions: PdaClient_1.PdaClient.derivePermissions(this.admin),
|
|
69
|
+
}, {
|
|
70
|
+
freeze,
|
|
71
|
+
action
|
|
72
|
+
});
|
|
73
|
+
return ix;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Freezes or unfreezes a specific DEX program.
|
|
78
|
+
*
|
|
79
|
+
* @param freeze - Whether to freeze (true) or unfreeze (false) the program
|
|
80
|
+
* @param programIndex - Index of the program to freeze/unfreeze
|
|
81
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
82
|
+
*/
|
|
83
|
+
freezeDex(freeze, programIndex) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const ix = (0, reflect_main_1.createFreezeProgramInstruction)({
|
|
86
|
+
admin: this.admin,
|
|
87
|
+
main: this.main,
|
|
88
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
89
|
+
adminPermissions: PdaClient_1.PdaClient.derivePermissions(this.admin),
|
|
90
|
+
}, {
|
|
91
|
+
freeze,
|
|
92
|
+
programIndex
|
|
93
|
+
});
|
|
94
|
+
return ix;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new admin account with specified permissions.
|
|
99
|
+
*
|
|
100
|
+
* @param signer - Public key of the caller (must be existing admin)
|
|
101
|
+
* @param newAdmin - Public key of the new admin to create
|
|
102
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
103
|
+
*/
|
|
104
|
+
createAdminAccount(signer, newAdmin) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const ix = (0, reflect_main_1.createCreateAdminAccountInstruction)({
|
|
107
|
+
caller: signer,
|
|
108
|
+
newCreds: PdaClient_1.PdaClient.derivePermissions(newAdmin),
|
|
109
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
110
|
+
}, {
|
|
111
|
+
newAdmin
|
|
112
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
113
|
+
return ix;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Updates role holder permissions at the protocol level.
|
|
118
|
+
*
|
|
119
|
+
* @param signer - Public key of the admin signer
|
|
120
|
+
* @param adminToUpdate - Public key of the admin whose permissions are being updated
|
|
121
|
+
* @param affectedRole - The role being modified
|
|
122
|
+
* @param update - The type of update (Grant or Revoke)
|
|
123
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
124
|
+
*/
|
|
125
|
+
updateRoleHolderProtocol(signer, adminToUpdate, affectedRole, update) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const ix = (0, reflect_main_1.createUpdateRoleHolderProtocolInstruction)({
|
|
128
|
+
admin: signer,
|
|
129
|
+
adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
|
|
130
|
+
main: PdaClient_1.PdaClient.deriveMain(),
|
|
131
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
132
|
+
updateAdminPermissions: PdaClient_1.PdaClient.derivePermissions(adminToUpdate),
|
|
133
|
+
// Dummy strategy account.
|
|
134
|
+
strategy: PdaClient_1.PdaClient.deriveController(0)
|
|
135
|
+
}, {
|
|
136
|
+
update,
|
|
137
|
+
accessLevel: affectedRole,
|
|
138
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
139
|
+
return ix;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Updates role holder permissions for a specific strategy.
|
|
144
|
+
*
|
|
145
|
+
* @param signer - Public key of the admin signer
|
|
146
|
+
* @param strategyId - ID of the strategy to update permissions for
|
|
147
|
+
* @param adminToUpdate - Public key of the admin whose permissions are being updated
|
|
148
|
+
* @param affectedRole - The role being modified
|
|
149
|
+
* @param update - The type of update (Grant or Revoke)
|
|
150
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
151
|
+
*/
|
|
152
|
+
updateRoleHolderStrategy(signer, strategyId, adminToUpdate, affectedRole, update) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const ix = (0, reflect_main_1.createUpdateRoleHolderStrategyInstruction)({
|
|
155
|
+
admin: signer,
|
|
156
|
+
adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
|
|
157
|
+
main: PdaClient_1.PdaClient.deriveMain(),
|
|
158
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
159
|
+
updateAdminPermissions: PdaClient_1.PdaClient.derivePermissions(adminToUpdate),
|
|
160
|
+
strategy: PdaClient_1.PdaClient.deriveController(strategyId)
|
|
161
|
+
}, {
|
|
162
|
+
update,
|
|
163
|
+
role: affectedRole,
|
|
164
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
165
|
+
return ix;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Updates action role permissions for a specific strategy.
|
|
170
|
+
*
|
|
171
|
+
* @param signer - Public key of the admin signer
|
|
172
|
+
* @param strategyId - ID of the strategy to update permissions for
|
|
173
|
+
* @param action - The action being modified
|
|
174
|
+
* @param affectedRole - The role being modified
|
|
175
|
+
* @param update - The type of update (Grant or Revoke)
|
|
176
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
177
|
+
*/
|
|
178
|
+
updateActionRoleStrategy(signer, strategyId, action, affectedRole, update) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
const ix = (0, reflect_main_1.createUpdateActionRoleStrategyInstruction)({
|
|
181
|
+
admin: signer,
|
|
182
|
+
adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
|
|
183
|
+
main: PdaClient_1.PdaClient.deriveMain(),
|
|
184
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
185
|
+
strategy: PdaClient_1.PdaClient.deriveController(strategyId)
|
|
186
|
+
}, {
|
|
187
|
+
update,
|
|
188
|
+
role: affectedRole,
|
|
189
|
+
action
|
|
190
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
191
|
+
return ix;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Updates action role permissions at the protocol level.
|
|
196
|
+
*
|
|
197
|
+
* @param signer - Public key of the admin signer
|
|
198
|
+
* @param action - The action being modified
|
|
199
|
+
* @param affectedRole - The role being modified
|
|
200
|
+
* @param update - The type of update (Grant or Revoke)
|
|
201
|
+
* @returns Promise resolving to a TransactionInstruction
|
|
202
|
+
*/
|
|
203
|
+
updateActionRoleProtocol(signer, action, affectedRole, update) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const ix = (0, reflect_main_1.createUpdateActionRoleProtocolInstruction)({
|
|
206
|
+
admin: signer,
|
|
207
|
+
adminPermissions: PdaClient_1.PdaClient.derivePermissions(signer),
|
|
208
|
+
main: PdaClient_1.PdaClient.deriveMain(),
|
|
209
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
210
|
+
}, {
|
|
211
|
+
action,
|
|
212
|
+
role: affectedRole,
|
|
213
|
+
update
|
|
214
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
215
|
+
return ix;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.ReflectAdmin = ReflectAdmin;
|
|
@@ -28,6 +28,8 @@ export declare abstract class Stablecoin {
|
|
|
28
28
|
stablecoinMint: PublicKey;
|
|
29
29
|
/** Optional Drift client instance for DeFi operations */
|
|
30
30
|
driftClient?: DriftClient;
|
|
31
|
+
/** Lookup table with stablecoin-specific accounts. */
|
|
32
|
+
lookupTable: PublicKey;
|
|
31
33
|
/**
|
|
32
34
|
* Creates a new Stablecoin instance.
|
|
33
35
|
*
|
|
@@ -35,7 +37,7 @@ export declare abstract class Stablecoin {
|
|
|
35
37
|
* @param name - Human-readable name for the stablecoin
|
|
36
38
|
* @param connection - Solana connection instance
|
|
37
39
|
*/
|
|
38
|
-
constructor(index: number, name: string, connection: Connection);
|
|
40
|
+
constructor(index: number, name: string, connection: Connection, lookupTable: PublicKey);
|
|
39
41
|
/**
|
|
40
42
|
* Initializes token accounts for the specified owner and mints.
|
|
41
43
|
* Creates associated token accounts if they don't exist.
|
|
@@ -40,11 +40,12 @@ class Stablecoin {
|
|
|
40
40
|
* @param name - Human-readable name for the stablecoin
|
|
41
41
|
* @param connection - Solana connection instance
|
|
42
42
|
*/
|
|
43
|
-
constructor(index, name, connection) {
|
|
43
|
+
constructor(index, name, connection, lookupTable) {
|
|
44
44
|
this.index = index;
|
|
45
45
|
this.name = name;
|
|
46
46
|
this.connection = connection;
|
|
47
47
|
this.controller = PdaClient_1.PdaClient.deriveController(this.index);
|
|
48
|
+
this.lookupTable = lookupTable;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Initializes token accounts for the specified owner and mints.
|
package/dist/classes/index.d.ts
CHANGED
package/dist/classes/index.js
CHANGED
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./ReflectKeeper"), exports);
|
|
18
18
|
__exportStar(require("./PdaClient"), exports);
|
|
19
19
|
__exportStar(require("./Stablecoin"), exports);
|
package/dist/constants/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LST_LOOKUP_TABLE = exports.JLP_LOOKUP_TABLE = exports.USDC_PLUS_LOOKUP_TABLE = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
exports.USDC_PLUS_LOOKUP_TABLE = new web3_js_1.PublicKey(0);
|
|
6
|
+
exports.JLP_LOOKUP_TABLE = new web3_js_1.PublicKey(0);
|
|
7
|
+
exports.LST_LOOKUP_TABLE = new web3_js_1.PublicKey(0);
|
|
@@ -39,7 +39,7 @@ class LstStablecoin extends Stablecoin_1.Stablecoin {
|
|
|
39
39
|
* @param collateralMintsOverride - Optional override for collateral mint addresses
|
|
40
40
|
*/
|
|
41
41
|
constructor(connection, stablecoinMintOverride, collateralMintsOverride) {
|
|
42
|
-
super(2, "
|
|
42
|
+
super(2, "LST Delta-Neutral", connection, constants_1.LST_LOOKUP_TABLE);
|
|
43
43
|
this.driftClient = new sdk_1.DriftClient({
|
|
44
44
|
connection,
|
|
45
45
|
env: "mainnet-beta",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Stablecoin } from "../classes/Stablecoin";
|
|
2
|
+
import { AccountMeta, Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import BN from "bn.js";
|
|
4
|
+
/**
|
|
5
|
+
* USDC+ Stablecoin implementation for the Reflect protocol.
|
|
6
|
+
* Extends the base Stablecoin class to provide USDC-specific functionality
|
|
7
|
+
* including initialization, minting, redemption, and rebalancing operations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UsdcPlusStablecoin extends Stablecoin {
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new USDC+ Stablecoin instance.
|
|
12
|
+
*
|
|
13
|
+
* @param connection - Solana connection instance for RPC communication
|
|
14
|
+
* @param stablecoinMintOverride - Optional override for the stablecoin mint address
|
|
15
|
+
*/
|
|
16
|
+
constructor(connection: Connection, stablecoinMintOverride?: PublicKey);
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the USDC stablecoin with the specified parameters.
|
|
19
|
+
* Creates receipt tokens, initializes vault, and initializes the stablecoin.
|
|
20
|
+
*
|
|
21
|
+
* @param signer - Public key of the signer/initializer
|
|
22
|
+
* @param mint - Public key of the mint to be used for the stablecoin
|
|
23
|
+
* @param cap - Maximum supply cap as a BN (Big Number)
|
|
24
|
+
* @param recipientAddresses - Array of recipient public keys for fee distribution
|
|
25
|
+
* @param recipientCuts - Array of fee cuts (percentages) corresponding to each recipient
|
|
26
|
+
* @returns Promise resolving to an array of TransactionInstruction objects
|
|
27
|
+
*/
|
|
28
|
+
initialize(signer: PublicKey, mint: PublicKey, cap: BN, recipientAddresses: PublicKey[], recipientCuts: number[]): Promise<TransactionInstruction[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Constructs the required accounts for the InitDriftControllerS1 instruction.
|
|
31
|
+
*
|
|
32
|
+
* @param signer - Public key of the signer
|
|
33
|
+
* @returns Promise resolving to the constructed accounts object of type T
|
|
34
|
+
*/
|
|
35
|
+
constructAccounts<T>(signer: PublicKey): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Constructs remaining accounts for transactions.
|
|
38
|
+
* Currently returns an empty array as no additional accounts are needed.
|
|
39
|
+
*
|
|
40
|
+
* @returns Promise resolving to an empty array of AccountMeta objects
|
|
41
|
+
*/
|
|
42
|
+
constructRemainingAccounts(): Promise<AccountMeta[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a mint instruction for the USDC+ stablecoin.
|
|
45
|
+
*
|
|
46
|
+
* @param signer - Public key of the signer
|
|
47
|
+
* @param amount - Amount of USDC to deposit
|
|
48
|
+
* @param minimumReceived - Minimum amount of USDC+ stablecoins to receive (slippage protection)
|
|
49
|
+
* @returns Promise resolving to an array containing a single TransactionInstruction
|
|
50
|
+
*/
|
|
51
|
+
mint(signer: PublicKey, amount: BN | number, minimumReceived: BN | number): Promise<TransactionInstruction[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a redeem instruction for the USDC stablecoin.
|
|
54
|
+
* Currently returns a placeholder instruction - implementation needed.
|
|
55
|
+
*
|
|
56
|
+
* @returns Promise resolving to an array containing a single TransactionInstruction
|
|
57
|
+
*/
|
|
58
|
+
redeem(signer: PublicKey, amount: BN | number, minimumReceived: BN | number): Promise<TransactionInstruction[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a rebalance instruction for the USDC+ stablecoin.
|
|
61
|
+
* Currently returns an empty instruction, as the rebalance is unnecessary.
|
|
62
|
+
*
|
|
63
|
+
* @returns Promise resolving to an array containing a single, empty TransactionInstruction.
|
|
64
|
+
*/
|
|
65
|
+
rebalance(): Promise<TransactionInstruction[]>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UsdcPlusStablecoin = void 0;
|
|
13
|
+
const Stablecoin_1 = require("../classes/Stablecoin");
|
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
+
const classes_1 = require("../classes");
|
|
16
|
+
const constants_1 = require("../constants");
|
|
17
|
+
const reflect_main_1 = require("../generated/reflect_main");
|
|
18
|
+
const sdk_1 = require("@drift-labs/sdk");
|
|
19
|
+
const constants_2 = require("../constants");
|
|
20
|
+
const ReflectTokenisedBond_1 = require("../classes/ReflectTokenisedBond");
|
|
21
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
22
|
+
const __1 = require("..");
|
|
23
|
+
const reflect_tokenised_bonds_1 = require("../generated/reflect_tokenised_bonds");
|
|
24
|
+
/**
|
|
25
|
+
* USDC+ Stablecoin implementation for the Reflect protocol.
|
|
26
|
+
* Extends the base Stablecoin class to provide USDC-specific functionality
|
|
27
|
+
* including initialization, minting, redemption, and rebalancing operations.
|
|
28
|
+
*/
|
|
29
|
+
class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new USDC+ Stablecoin instance.
|
|
32
|
+
*
|
|
33
|
+
* @param connection - Solana connection instance for RPC communication
|
|
34
|
+
* @param stablecoinMintOverride - Optional override for the stablecoin mint address
|
|
35
|
+
*/
|
|
36
|
+
constructor(connection, stablecoinMintOverride) {
|
|
37
|
+
super(0, "USDC Money Market", connection, constants_2.USDC_PLUS_LOOKUP_TABLE);
|
|
38
|
+
this.collaterals = [{ mint: constants_1.USDC_MINT, oracle: "" }];
|
|
39
|
+
// Otherwise has to be loaded first.
|
|
40
|
+
if (stablecoinMintOverride)
|
|
41
|
+
this.stablecoinMint = stablecoinMintOverride;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Initializes the USDC stablecoin with the specified parameters.
|
|
45
|
+
* Creates receipt tokens, initializes vault, and initializes the stablecoin.
|
|
46
|
+
*
|
|
47
|
+
* @param signer - Public key of the signer/initializer
|
|
48
|
+
* @param mint - Public key of the mint to be used for the stablecoin
|
|
49
|
+
* @param cap - Maximum supply cap as a BN (Big Number)
|
|
50
|
+
* @param recipientAddresses - Array of recipient public keys for fee distribution
|
|
51
|
+
* @param recipientCuts - Array of fee cuts (percentages) corresponding to each recipient
|
|
52
|
+
* @returns Promise resolving to an array of TransactionInstruction objects
|
|
53
|
+
*/
|
|
54
|
+
initialize(signer, mint, cap, recipientAddresses, recipientCuts) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const vault = classes_1.PdaClient.deriveLpVault(0);
|
|
57
|
+
const lp = new ReflectTokenisedBond_1.ReflectTokenisedBond(this.connection);
|
|
58
|
+
const { instructions: receiptIx, signers: [receiptKeypair] } = yield lp.createReceiptToken(this.connection, signer, vault);
|
|
59
|
+
const vaultIx = yield lp.initializeVault(signer, mint, receiptKeypair.publicKey);
|
|
60
|
+
const ix = (0, reflect_main_1.createInitDriftControllerS1Instruction)({
|
|
61
|
+
admin: signer,
|
|
62
|
+
adminPermissions: classes_1.PdaClient.derivePermissions(signer),
|
|
63
|
+
main: classes_1.PdaClient.deriveMain(),
|
|
64
|
+
driftUsdcController: this.controller,
|
|
65
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
66
|
+
}, {
|
|
67
|
+
mint,
|
|
68
|
+
cap,
|
|
69
|
+
recipientAddresses,
|
|
70
|
+
recipientCuts,
|
|
71
|
+
lpReciptMint: receiptKeypair.publicKey,
|
|
72
|
+
vault
|
|
73
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
74
|
+
return [...receiptIx, vaultIx, ix];
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Constructs the required accounts for the InitDriftControllerS1 instruction.
|
|
79
|
+
*
|
|
80
|
+
* @param signer - Public key of the signer
|
|
81
|
+
* @returns Promise resolving to the constructed accounts object of type T
|
|
82
|
+
*/
|
|
83
|
+
constructAccounts(signer) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controller);
|
|
86
|
+
const userStats = (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controller);
|
|
87
|
+
const anchorRemainingAccounts = yield this.constructRemainingAccounts();
|
|
88
|
+
const { referrer } = yield (0, sdk_1.fetchUserStatsAccount)(this.connection, this.driftClient.program, userAccount);
|
|
89
|
+
const referrerUser = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, referrer);
|
|
90
|
+
const referrerUserStats = (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, referrer);
|
|
91
|
+
const userUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.controller, signer, true);
|
|
92
|
+
const vault = classes_1.PdaClient.deriveLpVault(0);
|
|
93
|
+
const { depositTokenMint: intermediaryMint, receiptTokenMint } = yield reflect_tokenised_bonds_1.Vault
|
|
94
|
+
.fromAccountAddress(this.connection, vault);
|
|
95
|
+
const userReceiptAta = (0, spl_token_1.getAssociatedTokenAddressSync)(receiptTokenMint, signer, true);
|
|
96
|
+
const controllerIntermediaryAta = (0, spl_token_1.getAssociatedTokenAddressSync)(intermediaryMint, this.controller, true);
|
|
97
|
+
const controllerReceiptAta = (0, spl_token_1.getAssociatedTokenAddressSync)(receiptTokenMint, this.controller, true);
|
|
98
|
+
const controllerUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(constants_1.USDC_MINT, this.controller, true);
|
|
99
|
+
const spotMarketVault = yield (0, sdk_1.getSpotMarketVaultPublicKey)(constants_1.DRIFT_PROGRAM_ID, 0);
|
|
100
|
+
const driftState = yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID);
|
|
101
|
+
const vaultPool = classes_1.PdaClient.deriveLpVaultPool(0);
|
|
102
|
+
const accounts = {
|
|
103
|
+
clock: web3_js_1.SYSVAR_CLOCK_PUBKEY,
|
|
104
|
+
controllerIntermediaryAta,
|
|
105
|
+
controllerReceiptAta,
|
|
106
|
+
controllerUsdcAta,
|
|
107
|
+
drift: constants_1.DRIFT_PROGRAM_ID,
|
|
108
|
+
driftVault: constants_1.DRIFT_VAULT,
|
|
109
|
+
intermediaryMint,
|
|
110
|
+
lpPoolIntermediaryAta: vaultPool,
|
|
111
|
+
lpProgram: __1.TOKENISED_BONDS_PROGRAM_ID,
|
|
112
|
+
main: classes_1.PdaClient.deriveMain(),
|
|
113
|
+
receiptMint: receiptTokenMint,
|
|
114
|
+
referrerUser,
|
|
115
|
+
referrerUserStats,
|
|
116
|
+
spotMarketVault,
|
|
117
|
+
state: driftState,
|
|
118
|
+
usdcController: this.controller,
|
|
119
|
+
user: signer,
|
|
120
|
+
userAccount,
|
|
121
|
+
userReceiptAta,
|
|
122
|
+
userStats,
|
|
123
|
+
userUsdcAta,
|
|
124
|
+
vault,
|
|
125
|
+
adminPermissions: null,
|
|
126
|
+
anchorRemainingAccounts,
|
|
127
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
128
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
|
129
|
+
};
|
|
130
|
+
return accounts;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Constructs remaining accounts for transactions.
|
|
135
|
+
* Currently returns an empty array as no additional accounts are needed.
|
|
136
|
+
*
|
|
137
|
+
* @returns Promise resolving to an empty array of AccountMeta objects
|
|
138
|
+
*/
|
|
139
|
+
constructRemainingAccounts() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
return [];
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a mint instruction for the USDC+ stablecoin.
|
|
147
|
+
*
|
|
148
|
+
* @param signer - Public key of the signer
|
|
149
|
+
* @param amount - Amount of USDC to deposit
|
|
150
|
+
* @param minimumReceived - Minimum amount of USDC+ stablecoins to receive (slippage protection)
|
|
151
|
+
* @returns Promise resolving to an array containing a single TransactionInstruction
|
|
152
|
+
*/
|
|
153
|
+
mint(signer, amount, minimumReceived) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const accounts = yield this.constructAccounts(signer);
|
|
156
|
+
const ix = (0, reflect_main_1.createMintDriftS1Instruction)(accounts, {
|
|
157
|
+
minUsdcAmount: minimumReceived,
|
|
158
|
+
usdcAmount: amount
|
|
159
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
160
|
+
return [ix];
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Creates a redeem instruction for the USDC stablecoin.
|
|
165
|
+
* Currently returns a placeholder instruction - implementation needed.
|
|
166
|
+
*
|
|
167
|
+
* @returns Promise resolving to an array containing a single TransactionInstruction
|
|
168
|
+
*/
|
|
169
|
+
redeem(signer, amount, minimumReceived) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const accounts = yield this.constructAccounts(signer);
|
|
172
|
+
const ix = (0, reflect_main_1.createRedeemDriftS1Instruction)(accounts, {
|
|
173
|
+
canChill: false,
|
|
174
|
+
minLstRedeem: minimumReceived,
|
|
175
|
+
rusdBurnAmount: amount
|
|
176
|
+
}, reflect_main_1.PROGRAM_ID);
|
|
177
|
+
return [ix];
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Creates a rebalance instruction for the USDC+ stablecoin.
|
|
182
|
+
* Currently returns an empty instruction, as the rebalance is unnecessary.
|
|
183
|
+
*
|
|
184
|
+
* @returns Promise resolving to an array containing a single, empty TransactionInstruction.
|
|
185
|
+
*/
|
|
186
|
+
rebalance() {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const ix = new web3_js_1.TransactionInstruction({
|
|
189
|
+
programId: web3_js_1.Keypair.generate().publicKey,
|
|
190
|
+
data: Buffer.from(""),
|
|
191
|
+
keys: []
|
|
192
|
+
});
|
|
193
|
+
return [ix];
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.UsdcPlusStablecoin = UsdcPlusStablecoin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import {Stablecoin} from "../classes/Stablecoin";
|
|
3
|
+
// import {PdaClient} from "../classes/PdaClient";
|
|
4
|
+
// import {
|
|
5
|
+
// createInitDriftControllerS2Instruction,
|
|
6
|
+
// createMintDriftS2Instruction,
|
|
7
|
+
// createRebalanceJlpInstruction,
|
|
8
|
+
// createRedeemDriftS2Instruction,
|
|
9
|
+
// createRedeem2DriftS2Instruction,
|
|
10
|
+
// DriftJlpController,
|
|
11
|
+
// MintDriftS2InstructionAccounts, PerpHedge,
|
|
12
|
+
// PROGRAM_ID
|
|
13
|
+
// } from "../generated/reflect_main";
|
|
14
|
+
// import {
|
|
15
|
+
// AccountMeta,
|
|
16
|
+
// Connection,
|
|
17
|
+
// Keypair,
|
|
18
|
+
// PublicKey,
|
|
19
|
+
// SystemProgram,
|
|
20
|
+
// Transaction,
|
|
21
|
+
// TransactionInstruction
|
|
22
|
+
// } from "@solana/web3.js";
|
|
23
|
+
// import {JLP_MINT, DRIFT_PROGRAM_ID, JUPITER_PROGRAM_ID, USDC_MINT} from "../constants";
|
|
24
|
+
// import {getAccount, getAssociatedTokenAddressSync, getMint, TOKEN_PROGRAM_ID} from "@solana/spl-token";
|
|
25
|
+
// import {
|
|
26
|
+
// getDriftSignerPublicKey,
|
|
27
|
+
// getDriftStateAccountPublicKey,
|
|
28
|
+
// getPerpMarketPublicKeySync,
|
|
29
|
+
// getSpotMarketPublicKey,
|
|
30
|
+
// getSpotMarketPublicKeySync, getSpotMarketVaultPublicKey,
|
|
31
|
+
// getUserAccountPublicKeySync,
|
|
32
|
+
// getUserStatsAccountPublicKey,
|
|
33
|
+
// PerpMarkets,
|
|
34
|
+
// SpotMarkets,
|
|
35
|
+
// MarginCategory,
|
|
36
|
+
// getTokenAmount,
|
|
37
|
+
// SpotBalanceType
|
|
38
|
+
// } from "@drift-labs/sdk";
|
|
39
|
+
// import BN, { min } from "bn.js";
|
|
40
|
+
// import {AnchorProvider, Program} from "@coral-xyz/anchor";
|
|
41
|
+
// import {type Perpetuals, IDL} from "../idl/perpetuals";
|
|
42
|
+
// import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
|
|
43
|
+
// import { JlpPoolInfo, JlpComponent } from "../types";
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./UsdjStablecoin";
|
|
2
2
|
export * from "./LstStablecoin";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./UsdcPlusStablecoin";
|
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./UsdjStablecoin"), exports);
|
|
18
18
|
__exportStar(require("./LstStablecoin"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./UsdcPlusStablecoin"), exports);
|