@exponent-labs/generic-sy-sdk 0.0.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.
- package/CHANGELOG.md +16 -0
- package/build/index.d.ts +81 -0
- package/build/index.js +395 -0
- package/build/index.js.map +1 -0
- package/build/utils.d.ts +9 -0
- package/build/utils.js +36 -0
- package/build/utils.js.map +1 -0
- package/package.json +25 -0
- package/src/index.ts +534 -0
- package/src/utils.ts +32 -0
- package/tsconfig.json +38 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.0.3](https://github.com/exponent-finance/exponent-core/compare/@exponent-labs/generic-sy-sdk@0.0.2...@exponent-labs/generic-sy-sdk@0.0.3) (2025-03-03)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @exponent-labs/generic-sy-sdk
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.0.2](https://github.com/exponent-finance/exponent-core/compare/@exponent-labs/generic-sy-sdk@0.0.1...@exponent-labs/generic-sy-sdk@0.0.2) (2025-03-03)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @exponent-labs/generic-sy-sdk
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { BN, web3 } from "@coral-xyz/anchor";
|
|
3
|
+
import { GenericSyPda } from "@exponent-labs/generic-sy-pda";
|
|
4
|
+
import { GenericSyState, GenericSyMetaAccount, InterfaceTypeGeneric } from "@exponent-labs/exponent-types";
|
|
5
|
+
export declare enum InterfaceType {
|
|
6
|
+
Pyth = 0,
|
|
7
|
+
SplStakePool = 1,
|
|
8
|
+
One = 2,
|
|
9
|
+
Fragmetric = 3,
|
|
10
|
+
Meteora = 4
|
|
11
|
+
}
|
|
12
|
+
export declare function getInterfaceTypeObj(interfaceType: number): InterfaceTypeGeneric;
|
|
13
|
+
export declare function getInterfaceTypeFromString(interfaceType: string): InterfaceTypeGeneric;
|
|
14
|
+
export declare class GenericSySdk {
|
|
15
|
+
state: GenericSyState;
|
|
16
|
+
/** Private program for building instructions */
|
|
17
|
+
private program;
|
|
18
|
+
syPda: GenericSyPda;
|
|
19
|
+
constructor(state: GenericSyState, programId?: web3.PublicKey);
|
|
20
|
+
private static calculateSyRate;
|
|
21
|
+
/** Load an instance of SyMeta */
|
|
22
|
+
static load({ cnx, yieldBearingMint, interfaceType, genericStandardProgramId, }: {
|
|
23
|
+
cnx: web3.Connection;
|
|
24
|
+
yieldBearingMint: web3.PublicKey;
|
|
25
|
+
interfaceType: InterfaceTypeGeneric;
|
|
26
|
+
genericStandardProgramId: web3.PublicKey;
|
|
27
|
+
}): Promise<GenericSySdk>;
|
|
28
|
+
/** Load an instance of SyMeta from just the syMeta address */
|
|
29
|
+
static loadFromSyMeta({ cnx, syMetaAddress, genericStandardProgramId, }: {
|
|
30
|
+
cnx: web3.Connection;
|
|
31
|
+
syMetaAddress: web3.PublicKey;
|
|
32
|
+
genericStandardProgramId: web3.PublicKey;
|
|
33
|
+
}): Promise<GenericSySdk>;
|
|
34
|
+
/** Reload the state of the account */
|
|
35
|
+
reload(cnx: web3.Connection): Promise<void>;
|
|
36
|
+
get account(): GenericSyMetaAccount;
|
|
37
|
+
get mintSy(): web3.PublicKey;
|
|
38
|
+
get vrtMint(): web3.PublicKey;
|
|
39
|
+
get maxSySupply(): BN;
|
|
40
|
+
get emissions(): import("@exponent-labs/exponent-types").SyEmissionRaw[];
|
|
41
|
+
get minMintSize(): BN;
|
|
42
|
+
get minRedeemSize(): BN;
|
|
43
|
+
get selfAddress(): web3.PublicKey;
|
|
44
|
+
get tokenProgramBase(): web3.PublicKey;
|
|
45
|
+
get tokenVrtEscrow(): web3.PublicKey;
|
|
46
|
+
get tokenSyEscrow(): web3.PublicKey;
|
|
47
|
+
get adminState(): web3.PublicKey;
|
|
48
|
+
get fragmetricData(): {
|
|
49
|
+
receiptTokenMint: web3.PublicKey;
|
|
50
|
+
wrappedTokenMint: web3.PublicKey;
|
|
51
|
+
};
|
|
52
|
+
get remainingAccounts(): {
|
|
53
|
+
pubkey: web3.PublicKey;
|
|
54
|
+
isSigner: boolean;
|
|
55
|
+
isWritable: boolean;
|
|
56
|
+
}[];
|
|
57
|
+
getAccountsWithSigner(signer?: web3.PublicKey): {
|
|
58
|
+
pubkey: web3.PublicKey;
|
|
59
|
+
isSigner: boolean;
|
|
60
|
+
isWritable: boolean;
|
|
61
|
+
}[];
|
|
62
|
+
ixMintSy({ depositor, amountBase, baseSrc, syDst, }: {
|
|
63
|
+
depositor: web3.PublicKey;
|
|
64
|
+
amountBase: string;
|
|
65
|
+
baseSrc?: web3.PublicKey;
|
|
66
|
+
syDst?: web3.PublicKey;
|
|
67
|
+
}): Promise<web3.TransactionInstruction>;
|
|
68
|
+
ixRedeemSy({ redeemer, amountSy, baseDst, sySrc, }: {
|
|
69
|
+
redeemer: web3.PublicKey;
|
|
70
|
+
amountSy: string;
|
|
71
|
+
baseDst?: web3.PublicKey;
|
|
72
|
+
sySrc?: web3.PublicKey;
|
|
73
|
+
}): Promise<web3.TransactionInstruction>;
|
|
74
|
+
getSyState(): Promise<web3.TransactionInstruction>;
|
|
75
|
+
ixAddEmission({ signer, emissionMint, emissionTokenAccount, }: {
|
|
76
|
+
signer: web3.PublicKey;
|
|
77
|
+
emissionMint: web3.PublicKey;
|
|
78
|
+
emissionTokenAccount: web3.PublicKey;
|
|
79
|
+
}): Promise<web3.TransactionInstruction>;
|
|
80
|
+
}
|
|
81
|
+
export declare function initSy(signer: web3.PublicKey, interfaceAccounts: web3.PublicKey[], yieldBearingMint: web3.PublicKey, interfaceIndex: number): Promise<web3.TransactionInstruction>;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initSy = exports.GenericSySdk = exports.getInterfaceTypeFromString = exports.getInterfaceTypeObj = exports.InterfaceType = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
const generic_sy_idl_1 = require("@exponent-labs/generic-sy-idl");
|
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
7
|
+
const generic_sy_pda_1 = require("@exponent-labs/generic-sy-pda");
|
|
8
|
+
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
9
|
+
const exponent_admin_pda_1 = require("@exponent-labs/exponent-admin-pda");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const fragmetric_pda_1 = require("@exponent-labs/fragmetric-pda");
|
|
12
|
+
const generic_sy_idl_2 = require("@exponent-labs/generic-sy-idl");
|
|
13
|
+
async function loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType) {
|
|
14
|
+
let interfaceIndex;
|
|
15
|
+
if ("pyth" in interfaceType) {
|
|
16
|
+
interfaceIndex = InterfaceType.Pyth;
|
|
17
|
+
}
|
|
18
|
+
else if ("splStakePool" in interfaceType) {
|
|
19
|
+
interfaceIndex = InterfaceType.SplStakePool;
|
|
20
|
+
}
|
|
21
|
+
else if ("one" in interfaceType) {
|
|
22
|
+
interfaceIndex = InterfaceType.One;
|
|
23
|
+
}
|
|
24
|
+
else if ("fragmetric" in interfaceType) {
|
|
25
|
+
interfaceIndex = InterfaceType.Fragmetric;
|
|
26
|
+
}
|
|
27
|
+
else if ("meteora" in interfaceType) {
|
|
28
|
+
interfaceIndex = InterfaceType.Meteora;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error("Unsupported interface type");
|
|
32
|
+
}
|
|
33
|
+
const pda = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex);
|
|
34
|
+
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
|
|
35
|
+
const syMetaAddress = pda.syMeta({ yieldBearingMint });
|
|
36
|
+
console.log("syMetaAddress", syMetaAddress.toBase58());
|
|
37
|
+
const data = await fetcher.fetchGenericSyMeta(syMetaAddress);
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
// Interface type enum to match Rust's InterfaceType
|
|
41
|
+
var InterfaceType;
|
|
42
|
+
(function (InterfaceType) {
|
|
43
|
+
InterfaceType[InterfaceType["Pyth"] = 0] = "Pyth";
|
|
44
|
+
InterfaceType[InterfaceType["SplStakePool"] = 1] = "SplStakePool";
|
|
45
|
+
InterfaceType[InterfaceType["One"] = 2] = "One";
|
|
46
|
+
InterfaceType[InterfaceType["Fragmetric"] = 3] = "Fragmetric";
|
|
47
|
+
InterfaceType[InterfaceType["Meteora"] = 4] = "Meteora";
|
|
48
|
+
})(InterfaceType || (exports.InterfaceType = InterfaceType = {}));
|
|
49
|
+
function getInterfaceTypeObj(interfaceType) {
|
|
50
|
+
switch (interfaceType) {
|
|
51
|
+
case InterfaceType.Pyth:
|
|
52
|
+
return { pyth: { lastSlot: new anchor_1.BN(0), maximumAgeSeconds: new anchor_1.BN(3600) } };
|
|
53
|
+
case InterfaceType.SplStakePool:
|
|
54
|
+
return { splStakePool: {} };
|
|
55
|
+
case InterfaceType.One:
|
|
56
|
+
return { one: {} };
|
|
57
|
+
case InterfaceType.Fragmetric:
|
|
58
|
+
return { fragmetric: {} };
|
|
59
|
+
case InterfaceType.Meteora:
|
|
60
|
+
return { meteora: {} };
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(`Unsupported interface type: ${interfaceType}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.getInterfaceTypeObj = getInterfaceTypeObj;
|
|
66
|
+
function getInterfaceTypeFromString(interfaceType) {
|
|
67
|
+
switch (interfaceType) {
|
|
68
|
+
case "pyth":
|
|
69
|
+
return { pyth: { lastSlot: new anchor_1.BN(0), maximumAgeSeconds: new anchor_1.BN(3600) } };
|
|
70
|
+
case "spl-stake-pool":
|
|
71
|
+
return { splStakePool: {} };
|
|
72
|
+
case "one":
|
|
73
|
+
return { one: {} };
|
|
74
|
+
case "fragmetric":
|
|
75
|
+
return { fragmetric: {} };
|
|
76
|
+
case "meteora":
|
|
77
|
+
return { meteora: {} };
|
|
78
|
+
default:
|
|
79
|
+
throw new Error(`Unsupported interface type: ${interfaceType}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.getInterfaceTypeFromString = getInterfaceTypeFromString;
|
|
83
|
+
class GenericSySdk {
|
|
84
|
+
state;
|
|
85
|
+
/** Private program for building instructions */
|
|
86
|
+
program;
|
|
87
|
+
syPda;
|
|
88
|
+
constructor(state, programId = new anchor_1.web3.PublicKey(generic_sy_idl_2.PROGRAM_ID)) {
|
|
89
|
+
this.state = state;
|
|
90
|
+
// create a fake AnchorProvider -- which is unused
|
|
91
|
+
this.program = new anchor_1.Program(generic_sy_idl_1.IDL, new anchor_1.AnchorProvider(new anchor_1.web3.Connection("https://api.devnet.solana.com"), new utils_1.MyWallet(anchor_1.web3.Keypair.generate())));
|
|
92
|
+
// Determine interface index based on the interface type from state
|
|
93
|
+
let interfaceIndex;
|
|
94
|
+
if ("pyth" in this.state.account.interfaceType) {
|
|
95
|
+
interfaceIndex = InterfaceType.Pyth;
|
|
96
|
+
}
|
|
97
|
+
else if ("splStakePool" in this.state.account.interfaceType) {
|
|
98
|
+
interfaceIndex = InterfaceType.SplStakePool;
|
|
99
|
+
}
|
|
100
|
+
else if ("one" in this.state.account.interfaceType) {
|
|
101
|
+
interfaceIndex = InterfaceType.One;
|
|
102
|
+
}
|
|
103
|
+
else if ("fragmetric" in this.state.account.interfaceType) {
|
|
104
|
+
interfaceIndex = InterfaceType.Fragmetric;
|
|
105
|
+
}
|
|
106
|
+
else if ("meteora" in this.state.account.interfaceType) {
|
|
107
|
+
interfaceIndex = InterfaceType.Meteora;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error("Unsupported interface type");
|
|
111
|
+
}
|
|
112
|
+
this.syPda = new generic_sy_pda_1.GenericSyPda(programId, interfaceIndex);
|
|
113
|
+
}
|
|
114
|
+
static async calculateSyRate(account, interfaceType, cnx) {
|
|
115
|
+
if ("pyth" in interfaceType) {
|
|
116
|
+
return { syRate: Number(account.index) };
|
|
117
|
+
}
|
|
118
|
+
else if ("splStakePool" in interfaceType) {
|
|
119
|
+
return { syRate: 1 };
|
|
120
|
+
}
|
|
121
|
+
else if ("fragmetric" in interfaceType) {
|
|
122
|
+
const { index, receiptTokenMint, wrappedTokenMint } = await (0, exponent_fetcher_1.fetchFragmetricIndex)({
|
|
123
|
+
connection: cnx,
|
|
124
|
+
fragmetricFund: account.interfaceAccounts[0],
|
|
125
|
+
});
|
|
126
|
+
return { syRate: index, fragmetricData: { receiptTokenMint, wrappedTokenMint } };
|
|
127
|
+
}
|
|
128
|
+
else if ("meteora" in interfaceType) {
|
|
129
|
+
const currentTs = Math.floor(Date.now() / 1000);
|
|
130
|
+
const accounts = {
|
|
131
|
+
pool: account.interfaceAccounts[0],
|
|
132
|
+
vaultA: account.interfaceAccounts[4],
|
|
133
|
+
vaultB: account.interfaceAccounts[5],
|
|
134
|
+
};
|
|
135
|
+
const virtualPrice = await (0, exponent_fetcher_1.fetchMeteoraUsdcUsdtIndex)({ connection: cnx, accounts, onChainTime: currentTs });
|
|
136
|
+
return { syRate: virtualPrice };
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return { syRate: 1 };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** Load an instance of SyMeta */
|
|
143
|
+
static async load({ cnx, yieldBearingMint, interfaceType, genericStandardProgramId, }) {
|
|
144
|
+
const account = await loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType);
|
|
145
|
+
const tokenProgramBase = spl_token_1.TOKEN_PROGRAM_ID;
|
|
146
|
+
let interfaceIndex;
|
|
147
|
+
if ("pyth" in interfaceType) {
|
|
148
|
+
interfaceIndex = InterfaceType.Pyth;
|
|
149
|
+
}
|
|
150
|
+
else if ("splStakePool" in interfaceType) {
|
|
151
|
+
interfaceIndex = InterfaceType.SplStakePool;
|
|
152
|
+
}
|
|
153
|
+
else if ("one" in interfaceType) {
|
|
154
|
+
interfaceIndex = InterfaceType.One;
|
|
155
|
+
}
|
|
156
|
+
else if ("fragmetric" in interfaceType) {
|
|
157
|
+
interfaceIndex = InterfaceType.Fragmetric;
|
|
158
|
+
}
|
|
159
|
+
else if ("meteora" in interfaceType) {
|
|
160
|
+
interfaceIndex = InterfaceType.Meteora;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
throw new Error("Unsupported interface type");
|
|
164
|
+
}
|
|
165
|
+
const selfAddress = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex).syMeta({
|
|
166
|
+
yieldBearingMint,
|
|
167
|
+
});
|
|
168
|
+
const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, interfaceType, cnx);
|
|
169
|
+
const state = {
|
|
170
|
+
selfAddress,
|
|
171
|
+
account,
|
|
172
|
+
tokenProgramBase,
|
|
173
|
+
syRate,
|
|
174
|
+
fragmetricData,
|
|
175
|
+
};
|
|
176
|
+
return new GenericSySdk(state, genericStandardProgramId);
|
|
177
|
+
}
|
|
178
|
+
/** Load an instance of SyMeta from just the syMeta address */
|
|
179
|
+
static async loadFromSyMeta({ cnx, syMetaAddress, genericStandardProgramId, }) {
|
|
180
|
+
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
|
|
181
|
+
const account = await fetcher.fetchGenericSyMeta(syMetaAddress);
|
|
182
|
+
const tokenProgramBase = spl_token_1.TOKEN_PROGRAM_ID;
|
|
183
|
+
const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx);
|
|
184
|
+
const state = {
|
|
185
|
+
selfAddress: syMetaAddress,
|
|
186
|
+
account,
|
|
187
|
+
tokenProgramBase,
|
|
188
|
+
syRate,
|
|
189
|
+
fragmetricData,
|
|
190
|
+
};
|
|
191
|
+
return new GenericSySdk(state, genericStandardProgramId);
|
|
192
|
+
}
|
|
193
|
+
/** Reload the state of the account */
|
|
194
|
+
async reload(cnx) {
|
|
195
|
+
const account = await loadAccountState(cnx, this.state.account.yieldBearingMint, this.program.programId, this.state.account.interfaceType);
|
|
196
|
+
this.state.account = account;
|
|
197
|
+
const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx);
|
|
198
|
+
this.state.syRate = syRate;
|
|
199
|
+
this.state.fragmetricData = fragmetricData;
|
|
200
|
+
}
|
|
201
|
+
get account() {
|
|
202
|
+
return this.state.account;
|
|
203
|
+
}
|
|
204
|
+
get mintSy() {
|
|
205
|
+
return this.account.mintSy;
|
|
206
|
+
}
|
|
207
|
+
get vrtMint() {
|
|
208
|
+
return this.account.yieldBearingMint;
|
|
209
|
+
}
|
|
210
|
+
get maxSySupply() {
|
|
211
|
+
return this.account.maxSySupply;
|
|
212
|
+
}
|
|
213
|
+
get emissions() {
|
|
214
|
+
return this.account.emissions;
|
|
215
|
+
}
|
|
216
|
+
get minMintSize() {
|
|
217
|
+
return this.account.minMintSize;
|
|
218
|
+
}
|
|
219
|
+
get minRedeemSize() {
|
|
220
|
+
return this.account.minRedeemSize;
|
|
221
|
+
}
|
|
222
|
+
// get mintBase() {
|
|
223
|
+
// return this.state.mintBase
|
|
224
|
+
// }
|
|
225
|
+
get selfAddress() {
|
|
226
|
+
return this.state.selfAddress;
|
|
227
|
+
}
|
|
228
|
+
get tokenProgramBase() {
|
|
229
|
+
return this.state.tokenProgramBase;
|
|
230
|
+
}
|
|
231
|
+
get tokenVrtEscrow() {
|
|
232
|
+
return (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, this.selfAddress, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
233
|
+
}
|
|
234
|
+
get tokenSyEscrow() {
|
|
235
|
+
return this.state.account.tokenSyEscrow;
|
|
236
|
+
}
|
|
237
|
+
get adminState() {
|
|
238
|
+
return new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID).exponentAdmin();
|
|
239
|
+
}
|
|
240
|
+
get fragmetricData() {
|
|
241
|
+
if (!("fragmetric" in this.state.account.interfaceType)) {
|
|
242
|
+
throw new Error("Not a fragmetric interface");
|
|
243
|
+
}
|
|
244
|
+
if (!this.state.fragmetricData) {
|
|
245
|
+
throw new Error("Fragmetric data not loaded");
|
|
246
|
+
}
|
|
247
|
+
return this.state.fragmetricData;
|
|
248
|
+
}
|
|
249
|
+
get remainingAccounts() {
|
|
250
|
+
const accounts = this.account.interfaceAccounts
|
|
251
|
+
.map((a) => ({
|
|
252
|
+
pubkey: a,
|
|
253
|
+
isSigner: false,
|
|
254
|
+
isWritable: true,
|
|
255
|
+
}))
|
|
256
|
+
.concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })));
|
|
257
|
+
return accounts;
|
|
258
|
+
}
|
|
259
|
+
getAccountsWithSigner(signer) {
|
|
260
|
+
const accounts = this.remainingAccounts;
|
|
261
|
+
if ("fragmetric" in this.state.account.interfaceType && signer) {
|
|
262
|
+
const fragmetricReceiptTokenMint = this.state.fragmetricData.receiptTokenMint;
|
|
263
|
+
const fragmetricWrappedTokenMint = this.state.fragmetricData.wrappedTokenMint;
|
|
264
|
+
const fragmetricPda = new fragmetric_pda_1.FragmetricPda();
|
|
265
|
+
const fragmetricFundAccount = fragmetricPda.fundAccount(fragmetricReceiptTokenMint);
|
|
266
|
+
const fragmetricRewardAccount = fragmetricPda.rewardAccount(fragmetricReceiptTokenMint);
|
|
267
|
+
const userReceiptTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(fragmetricReceiptTokenMint, signer, true, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
268
|
+
const userWrappedTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(fragmetricWrappedTokenMint, signer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
269
|
+
const fundWrapAccount = fragmetricPda.fundWrapAccount(fragmetricReceiptTokenMint);
|
|
270
|
+
const receiptTokenWrapAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(fragmetricReceiptTokenMint, fundWrapAccount, true, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
271
|
+
const fundWrapAccountRewardAccount = fragmetricPda.userRewardAccount(fragmetricReceiptTokenMint, fundWrapAccount);
|
|
272
|
+
const userFundAccount = fragmetricPda.userFundAccount(fragmetricReceiptTokenMint, signer);
|
|
273
|
+
const userRewardAccount = fragmetricPda.userRewardAccount(fragmetricReceiptTokenMint, signer);
|
|
274
|
+
const eventAuthority = fragmetricPda.eventAuthority();
|
|
275
|
+
console.log("fund wrap account", fundWrapAccount.toBase58());
|
|
276
|
+
console.log("user fund account", userFundAccount.toBase58());
|
|
277
|
+
console.log("user reward account", userRewardAccount.toBase58());
|
|
278
|
+
console.log("receipt token mint", fragmetricReceiptTokenMint.toBase58());
|
|
279
|
+
console.log("wrapped token mint", fragmetricWrappedTokenMint.toBase58());
|
|
280
|
+
console.log("receipt token wrap account", receiptTokenWrapAccount.toBase58());
|
|
281
|
+
accounts.push(
|
|
282
|
+
// user
|
|
283
|
+
{ pubkey: signer, isSigner: true, isWritable: true },
|
|
284
|
+
// fund wrap account
|
|
285
|
+
{ pubkey: fundWrapAccount, isSigner: false, isWritable: true },
|
|
286
|
+
// receipt token program
|
|
287
|
+
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
288
|
+
// wrapped token program
|
|
289
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: fragmetricReceiptTokenMint, isSigner: false, isWritable: true }, { pubkey: fragmetricWrappedTokenMint, isSigner: false, isWritable: true }, { pubkey: userReceiptTokenAccount, isSigner: false, isWritable: true }, { pubkey: receiptTokenWrapAccount, isSigner: false, isWritable: true }, { pubkey: userWrappedTokenAccount, isSigner: false, isWritable: true }, { pubkey: fragmetricFundAccount, isSigner: false, isWritable: true }, { pubkey: userFundAccount, isSigner: false, isWritable: true }, { pubkey: fragmetricRewardAccount, isSigner: false, isWritable: true }, { pubkey: userRewardAccount, isSigner: false, isWritable: true }, { pubkey: fundWrapAccountRewardAccount, isSigner: false, isWritable: true }, { pubkey: eventAuthority, isSigner: false, isWritable: false }, {
|
|
290
|
+
pubkey: fragmetric_pda_1.FRAGMETRIC_PROGRAM_ID,
|
|
291
|
+
isSigner: false,
|
|
292
|
+
isWritable: false,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return accounts;
|
|
296
|
+
}
|
|
297
|
+
ixMintSy({ depositor, amountBase, baseSrc, syDst, }) {
|
|
298
|
+
baseSrc = baseSrc || (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, depositor, true, this.state.tokenProgramBase);
|
|
299
|
+
console.log("baseSrc", baseSrc.toBase58());
|
|
300
|
+
console.log("depositor", depositor.toBase58());
|
|
301
|
+
syDst = syDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, depositor, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
302
|
+
console.log("this.selfAddress", this.selfAddress.toBase58());
|
|
303
|
+
return this.program.methods
|
|
304
|
+
.mint(new anchor_1.BN(amountBase))
|
|
305
|
+
.accountsStrict({
|
|
306
|
+
meta: this.selfAddress,
|
|
307
|
+
baseTokenProgram: this.tokenProgramBase,
|
|
308
|
+
depositor,
|
|
309
|
+
mintSy: this.mintSy,
|
|
310
|
+
tokenBaseDepositor: baseSrc,
|
|
311
|
+
tokenSyDepositor: syDst,
|
|
312
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
313
|
+
tokenVrtEscrow: this.tokenVrtEscrow,
|
|
314
|
+
})
|
|
315
|
+
.remainingAccounts(this.getAccountsWithSigner(depositor))
|
|
316
|
+
.instruction();
|
|
317
|
+
}
|
|
318
|
+
ixRedeemSy({ redeemer, amountSy, baseDst, sySrc, }) {
|
|
319
|
+
baseDst = baseDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.vrtMint, redeemer, true, this.tokenProgramBase);
|
|
320
|
+
sySrc = sySrc || (0, spl_token_1.getAssociatedTokenAddressSync)(this.mintSy, redeemer, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
321
|
+
return this.program.methods
|
|
322
|
+
.redeem(new anchor_1.BN(amountSy))
|
|
323
|
+
.accountsStrict({
|
|
324
|
+
meta: this.selfAddress,
|
|
325
|
+
mintSy: this.mintSy,
|
|
326
|
+
tokenSySigner: sySrc,
|
|
327
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
328
|
+
signer: redeemer,
|
|
329
|
+
tokenBaseDst: baseDst,
|
|
330
|
+
tokenBaseProgram: this.tokenProgramBase,
|
|
331
|
+
tokenVrtEscrow: this.tokenVrtEscrow,
|
|
332
|
+
})
|
|
333
|
+
.remainingAccounts(this.getAccountsWithSigner(redeemer))
|
|
334
|
+
.instruction();
|
|
335
|
+
}
|
|
336
|
+
getSyState() {
|
|
337
|
+
return this.program.methods
|
|
338
|
+
.getState()
|
|
339
|
+
.accountsStrict({
|
|
340
|
+
meta: this.selfAddress,
|
|
341
|
+
mintSy: this.mintSy,
|
|
342
|
+
tokenSyEscrow: this.tokenSyEscrow,
|
|
343
|
+
})
|
|
344
|
+
.remainingAccounts(this.remainingAccounts)
|
|
345
|
+
.instruction();
|
|
346
|
+
}
|
|
347
|
+
ixAddEmission({ signer, emissionMint, emissionTokenAccount, }) {
|
|
348
|
+
return this.program.methods
|
|
349
|
+
.addEmission()
|
|
350
|
+
.accountsStrict({
|
|
351
|
+
meta: this.selfAddress,
|
|
352
|
+
signer,
|
|
353
|
+
feePayer: signer,
|
|
354
|
+
tokenEmission: emissionTokenAccount,
|
|
355
|
+
mintEmission: emissionMint,
|
|
356
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
357
|
+
adminState: this.adminState,
|
|
358
|
+
})
|
|
359
|
+
.instruction();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
exports.GenericSySdk = GenericSySdk;
|
|
363
|
+
function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex) {
|
|
364
|
+
const program = new anchor_1.Program(generic_sy_idl_1.IDL, new anchor_1.AnchorProvider(new anchor_1.web3.Connection("https://api.devnet.solana.com"), new utils_1.MyWallet(anchor_1.web3.Keypair.generate())));
|
|
365
|
+
console.log("interfaceIndex", interfaceIndex);
|
|
366
|
+
const pda = new generic_sy_pda_1.GenericSyPda(program.programId, interfaceIndex);
|
|
367
|
+
const syMetaAddress = pda.syMeta({ yieldBearingMint });
|
|
368
|
+
console.log("this.selfAddress in sdk", syMetaAddress.toBase58());
|
|
369
|
+
const mintSy = pda.mintSy({ yieldBearingMint });
|
|
370
|
+
console.log("mintSy in sdk", mintSy.toBase58());
|
|
371
|
+
const exponentAdminPda = new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID);
|
|
372
|
+
const metaplexMetadataProgram = new anchor_1.web3.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
373
|
+
const mintSyMetaplexMetadataPda = anchor_1.web3.PublicKey.findProgramAddressSync([Buffer.from("metadata"), metaplexMetadataProgram.toBuffer(), mintSy.toBuffer()], metaplexMetadataProgram)[0];
|
|
374
|
+
const tokenVrtEscrow = (0, spl_token_1.getAssociatedTokenAddressSync)(yieldBearingMint, syMetaAddress, true, spl_token_1.TOKEN_PROGRAM_ID);
|
|
375
|
+
const interfaceType = getInterfaceTypeObj(interfaceIndex);
|
|
376
|
+
const ix = program.methods
|
|
377
|
+
.initSy(new anchor_1.BN(0), new anchor_1.BN(0), "Exponent Wrapped fragSOL", "ewfragSOL", "", interfaceAccounts, interfaceType)
|
|
378
|
+
.accountsStrict({
|
|
379
|
+
syMeta: syMetaAddress,
|
|
380
|
+
mintSy: mintSy,
|
|
381
|
+
adminState: exponentAdminPda.exponentAdmin(),
|
|
382
|
+
admin: signer,
|
|
383
|
+
yieldBearingMint,
|
|
384
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
385
|
+
tokenSyEscrow: pda.syEscrow({ yieldBearingMint }),
|
|
386
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
387
|
+
metadata: mintSyMetaplexMetadataPda,
|
|
388
|
+
tokenMetadataProgram: metaplexMetadataProgram,
|
|
389
|
+
tokenVrtEscrow,
|
|
390
|
+
})
|
|
391
|
+
.instruction();
|
|
392
|
+
return ix;
|
|
393
|
+
}
|
|
394
|
+
exports.initSy = initSy;
|
|
395
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,8CAAqE;AACrE,kEAAoE;AACpE,iDAA0G;AAC1G,kEAA4D;AAE5D,sEAAkH;AAClH,0EAA+F;AAC/F,mCAAkC;AAClC,kEAAoF;AACpF,kEAAyF;AAEzF,KAAK,UAAU,gBAAgB,CAC7B,GAAoB,EACpB,gBAAgC,EAChC,wBAAwC,EACxC,aAAmC;IAEnC,IAAI,cAAsB,CAAA;IAC1B,IAAI,MAAM,IAAI,aAAa,EAAE,CAAC;QAC5B,cAAc,GAAG,aAAa,CAAC,IAAI,CAAA;IACrC,CAAC;SAAM,IAAI,cAAc,IAAI,aAAa,EAAE,CAAC;QAC3C,cAAc,GAAG,aAAa,CAAC,YAAY,CAAA;IAC7C,CAAC;SAAM,IAAI,KAAK,IAAI,aAAa,EAAE,CAAC;QAClC,cAAc,GAAG,aAAa,CAAC,GAAG,CAAA;IACpC,CAAC;SAAM,IAAI,YAAY,IAAI,aAAa,EAAE,CA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A6B,EAAC,gBAAgB,EAAE,aAAa,EAAE,IAAI,EAAE,4BAAgB,CAAC,CAAA;IAE7G,MAAM,aAAa,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAA;IACzD,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO;SACvB,MAAM,CAAC,IAAI,WAAE,CAAC,CAAC,CAAC,EAAE,IAAI,WAAE,CAAC,CAAC,CAAC,EAAE,0BAA0B,EAAE,WAAW,EAAE,EAAE,EAAE,iBAAiB,EAAE,aAAa,CAAC;SAC3G,cAAc,CAAC;QACd,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,gBAAgB,CAAC,aAAa,EAAE;QAC5C,KAAK,EAAE,MAAM;QACb,gBAAgB;QAChB,YAAY,EAAE,4BAAgB;QAC9B,aAAa,EAAE,GAAG,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;QACjD,aAAa,EAAE,aAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,QAAQ,EAAE,yBAAyB;QACnC,oBAAoB,EAAE,uBAAuB;QAC7C,cAAc;KACf,CAAC;SACD,WAAW,EAAE,CAAA;IAEhB,OAAO,EAAE,CAAA;AACX,CAAC;AA9CD,wBA8CC"}
|
package/build/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { web3 } from "@coral-xyz/anchor";
|
|
2
|
+
import type { Wallet } from "@coral-xyz/anchor";
|
|
3
|
+
export declare class MyWallet implements Wallet {
|
|
4
|
+
readonly payer: web3.Keypair;
|
|
5
|
+
constructor(payer: web3.Keypair);
|
|
6
|
+
signTransaction<T extends web3.Transaction | web3.VersionedTransaction>(tx: T): Promise<T>;
|
|
7
|
+
signAllTransactions<T extends web3.Transaction | web3.VersionedTransaction>(txs: T[]): Promise<T[]>;
|
|
8
|
+
get publicKey(): web3.PublicKey;
|
|
9
|
+
}
|
package/build/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MyWallet = void 0;
|
|
4
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
|
+
class MyWallet {
|
|
6
|
+
payer;
|
|
7
|
+
constructor(payer) {
|
|
8
|
+
this.payer = payer;
|
|
9
|
+
this.payer = payer;
|
|
10
|
+
}
|
|
11
|
+
async signTransaction(tx) {
|
|
12
|
+
if (tx instanceof anchor_1.web3.Transaction) {
|
|
13
|
+
tx.partialSign(this.payer);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
tx.sign([this.payer]);
|
|
17
|
+
}
|
|
18
|
+
return tx;
|
|
19
|
+
}
|
|
20
|
+
async signAllTransactions(txs) {
|
|
21
|
+
return txs.map((t) => {
|
|
22
|
+
if (t instanceof anchor_1.web3.Transaction) {
|
|
23
|
+
t.partialSign(this.payer);
|
|
24
|
+
}
|
|
25
|
+
else if (t instanceof anchor_1.web3.VersionedTransaction) {
|
|
26
|
+
t.sign([this.payer]);
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
get publicKey() {
|
|
32
|
+
return this.payer.publicKey;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.MyWallet = MyWallet;
|
|
36
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,8CAAwC;AAGxC,MAAa,QAAQ;IACE;IAArB,YAAqB,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;QACtC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,eAAe,CAAyD,EAAK;QACjF,IAAI,EAAE,YAAY,aAAI,CAAC,WAAW,EAAE,CAAC;YACnC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC5B,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QACvB,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAyD,GAAQ;QACxF,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACnB,IAAI,CAAC,YAAY,aAAI,CAAC,WAAW,EAAE,CAAC;gBAClC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC3B,CAAC;iBAAM,IAAI,CAAC,YAAY,aAAI,CAAC,oBAAoB,EAAE,CAAC;gBAClD,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;YACtB,CAAC;YACD,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAA;IAC7B,CAAC;CACF;AA5BD,4BA4BC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@exponent-labs/generic-sy-sdk",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"main": "build/index.js",
|
|
5
|
+
"types": "build/index.d.ts",
|
|
6
|
+
"license": "AGPL-3.0",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc --build",
|
|
9
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json}\""
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@coral-xyz/anchor": "^0.30.1",
|
|
13
|
+
"@exponent-labs/exponent-admin-pda": "^0.0.3",
|
|
14
|
+
"@exponent-labs/exponent-fetcher": "^0.0.3",
|
|
15
|
+
"@exponent-labs/exponent-types": "^0.0.3",
|
|
16
|
+
"@exponent-labs/fragmetric-pda": "^0.0.3",
|
|
17
|
+
"@exponent-labs/generic-sy-idl": "^0.0.3",
|
|
18
|
+
"@exponent-labs/generic-sy-pda": "^0.0.3",
|
|
19
|
+
"@solana/spl-token": "^0.4.6"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "5.4.5"
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "209b8847e9a0fadb5b5ec96b9b47f0ace4a3bf9d"
|
|
25
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import { AnchorProvider, BN, Program, web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import { IDL, GenericStandard } from "@exponent-labs/generic-sy-idl"
|
|
3
|
+
import { getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
4
|
+
import { GenericSyPda } from "@exponent-labs/generic-sy-pda"
|
|
5
|
+
import { GenericSyState, GenericSyMetaAccount, InterfaceTypeGeneric } from "@exponent-labs/exponent-types"
|
|
6
|
+
import { ExponentFetcher, fetchFragmetricIndex, fetchMeteoraUsdcUsdtIndex } from "@exponent-labs/exponent-fetcher"
|
|
7
|
+
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
8
|
+
import { MyWallet } from "./utils"
|
|
9
|
+
import { FragmetricPda, FRAGMETRIC_PROGRAM_ID } from "@exponent-labs/fragmetric-pda"
|
|
10
|
+
import { PROGRAM_ID as GENERIC_STANDARD_PROGRAM_ID } from "@exponent-labs/generic-sy-idl"
|
|
11
|
+
|
|
12
|
+
async function loadAccountState(
|
|
13
|
+
cnx: web3.Connection,
|
|
14
|
+
yieldBearingMint: web3.PublicKey,
|
|
15
|
+
genericStandardProgramId: web3.PublicKey,
|
|
16
|
+
interfaceType: InterfaceTypeGeneric,
|
|
17
|
+
) {
|
|
18
|
+
let interfaceIndex: number
|
|
19
|
+
if ("pyth" in interfaceType) {
|
|
20
|
+
interfaceIndex = InterfaceType.Pyth
|
|
21
|
+
} else if ("splStakePool" in interfaceType) {
|
|
22
|
+
interfaceIndex = InterfaceType.SplStakePool
|
|
23
|
+
} else if ("one" in interfaceType) {
|
|
24
|
+
interfaceIndex = InterfaceType.One
|
|
25
|
+
} else if ("fragmetric" in interfaceType) {
|
|
26
|
+
interfaceIndex = InterfaceType.Fragmetric
|
|
27
|
+
} else if ("meteora" in interfaceType) {
|
|
28
|
+
interfaceIndex = InterfaceType.Meteora
|
|
29
|
+
} else {
|
|
30
|
+
throw new Error("Unsupported interface type")
|
|
31
|
+
}
|
|
32
|
+
const pda = new GenericSyPda(genericStandardProgramId, interfaceIndex)
|
|
33
|
+
const fetcher = new ExponentFetcher({ connection: cnx, genericStandardProgramId })
|
|
34
|
+
const syMetaAddress = pda.syMeta({ yieldBearingMint })
|
|
35
|
+
console.log("syMetaAddress", syMetaAddress.toBase58())
|
|
36
|
+
const data = await fetcher.fetchGenericSyMeta(syMetaAddress)
|
|
37
|
+
return data
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Interface type enum to match Rust's InterfaceType
|
|
41
|
+
export enum InterfaceType {
|
|
42
|
+
Pyth = 0,
|
|
43
|
+
SplStakePool = 1,
|
|
44
|
+
One = 2,
|
|
45
|
+
Fragmetric = 3,
|
|
46
|
+
Meteora = 4,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function getInterfaceTypeObj(interfaceType: number): InterfaceTypeGeneric {
|
|
50
|
+
switch (interfaceType) {
|
|
51
|
+
case InterfaceType.Pyth:
|
|
52
|
+
return { pyth: { lastSlot: new BN(0), maximumAgeSeconds: new BN(3600) } }
|
|
53
|
+
case InterfaceType.SplStakePool:
|
|
54
|
+
return { splStakePool: {} }
|
|
55
|
+
case InterfaceType.One:
|
|
56
|
+
return { one: {} }
|
|
57
|
+
case InterfaceType.Fragmetric:
|
|
58
|
+
return { fragmetric: {} }
|
|
59
|
+
case InterfaceType.Meteora:
|
|
60
|
+
return { meteora: {} }
|
|
61
|
+
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`Unsupported interface type: ${interfaceType}`)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function getInterfaceTypeFromString(interfaceType: string): InterfaceTypeGeneric {
|
|
68
|
+
switch (interfaceType) {
|
|
69
|
+
case "pyth":
|
|
70
|
+
return { pyth: { lastSlot: new BN(0), maximumAgeSeconds: new BN(3600) } }
|
|
71
|
+
case "spl-stake-pool":
|
|
72
|
+
return { splStakePool: {} }
|
|
73
|
+
case "one":
|
|
74
|
+
return { one: {} }
|
|
75
|
+
case "fragmetric":
|
|
76
|
+
return { fragmetric: {} }
|
|
77
|
+
case "meteora":
|
|
78
|
+
return { meteora: {} }
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(`Unsupported interface type: ${interfaceType}`)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export class GenericSySdk {
|
|
85
|
+
/** Private program for building instructions */
|
|
86
|
+
private program: Program<GenericStandard>
|
|
87
|
+
|
|
88
|
+
syPda: GenericSyPda
|
|
89
|
+
|
|
90
|
+
constructor(
|
|
91
|
+
public state: GenericSyState,
|
|
92
|
+
programId: web3.PublicKey = new web3.PublicKey(GENERIC_STANDARD_PROGRAM_ID),
|
|
93
|
+
) {
|
|
94
|
+
// create a fake AnchorProvider -- which is unused
|
|
95
|
+
this.program = new Program<GenericStandard>(
|
|
96
|
+
IDL,
|
|
97
|
+
new AnchorProvider(new web3.Connection("https://api.devnet.solana.com"), new MyWallet(web3.Keypair.generate())),
|
|
98
|
+
)
|
|
99
|
+
// Determine interface index based on the interface type from state
|
|
100
|
+
let interfaceIndex: number
|
|
101
|
+
if ("pyth" in this.state.account.interfaceType) {
|
|
102
|
+
interfaceIndex = InterfaceType.Pyth
|
|
103
|
+
} else if ("splStakePool" in this.state.account.interfaceType) {
|
|
104
|
+
interfaceIndex = InterfaceType.SplStakePool
|
|
105
|
+
} else if ("one" in this.state.account.interfaceType) {
|
|
106
|
+
interfaceIndex = InterfaceType.One
|
|
107
|
+
} else if ("fragmetric" in this.state.account.interfaceType) {
|
|
108
|
+
interfaceIndex = InterfaceType.Fragmetric
|
|
109
|
+
} else if ("meteora" in this.state.account.interfaceType) {
|
|
110
|
+
interfaceIndex = InterfaceType.Meteora
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error("Unsupported interface type")
|
|
113
|
+
}
|
|
114
|
+
this.syPda = new GenericSyPda(programId, interfaceIndex)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private static async calculateSyRate(
|
|
118
|
+
account: GenericSyMetaAccount,
|
|
119
|
+
interfaceType: InterfaceTypeGeneric,
|
|
120
|
+
cnx: web3.Connection,
|
|
121
|
+
): Promise<{
|
|
122
|
+
syRate: number
|
|
123
|
+
fragmetricData?: { receiptTokenMint: web3.PublicKey; wrappedTokenMint: web3.PublicKey }
|
|
124
|
+
}> {
|
|
125
|
+
if ("pyth" in interfaceType) {
|
|
126
|
+
return { syRate: Number(account.index) }
|
|
127
|
+
} else if ("splStakePool" in interfaceType) {
|
|
128
|
+
return { syRate: 1 }
|
|
129
|
+
} else if ("fragmetric" in interfaceType) {
|
|
130
|
+
const { index, receiptTokenMint, wrappedTokenMint } = await fetchFragmetricIndex({
|
|
131
|
+
connection: cnx,
|
|
132
|
+
fragmetricFund: account.interfaceAccounts[0],
|
|
133
|
+
})
|
|
134
|
+
return { syRate: index, fragmetricData: { receiptTokenMint, wrappedTokenMint } }
|
|
135
|
+
} else if ("meteora" in interfaceType) {
|
|
136
|
+
const currentTs = Math.floor(Date.now() / 1000)
|
|
137
|
+
|
|
138
|
+
const accounts = {
|
|
139
|
+
pool: account.interfaceAccounts[0],
|
|
140
|
+
vaultA: account.interfaceAccounts[4],
|
|
141
|
+
vaultB: account.interfaceAccounts[5],
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const virtualPrice = await fetchMeteoraUsdcUsdtIndex({ connection: cnx, accounts, onChainTime: currentTs })
|
|
145
|
+
|
|
146
|
+
return { syRate: virtualPrice }
|
|
147
|
+
} else {
|
|
148
|
+
return { syRate: 1 }
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Load an instance of SyMeta */
|
|
153
|
+
static async load({
|
|
154
|
+
cnx,
|
|
155
|
+
yieldBearingMint,
|
|
156
|
+
interfaceType,
|
|
157
|
+
genericStandardProgramId,
|
|
158
|
+
}: {
|
|
159
|
+
cnx: web3.Connection
|
|
160
|
+
yieldBearingMint: web3.PublicKey
|
|
161
|
+
interfaceType: InterfaceTypeGeneric
|
|
162
|
+
genericStandardProgramId: web3.PublicKey
|
|
163
|
+
}) {
|
|
164
|
+
const account = await loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType)
|
|
165
|
+
const tokenProgramBase = TOKEN_PROGRAM_ID
|
|
166
|
+
|
|
167
|
+
let interfaceIndex: number
|
|
168
|
+
if ("pyth" in interfaceType) {
|
|
169
|
+
interfaceIndex = InterfaceType.Pyth
|
|
170
|
+
} else if ("splStakePool" in interfaceType) {
|
|
171
|
+
interfaceIndex = InterfaceType.SplStakePool
|
|
172
|
+
} else if ("one" in interfaceType) {
|
|
173
|
+
interfaceIndex = InterfaceType.One
|
|
174
|
+
} else if ("fragmetric" in interfaceType) {
|
|
175
|
+
interfaceIndex = InterfaceType.Fragmetric
|
|
176
|
+
} else if ("meteora" in interfaceType) {
|
|
177
|
+
interfaceIndex = InterfaceType.Meteora
|
|
178
|
+
} else {
|
|
179
|
+
throw new Error("Unsupported interface type")
|
|
180
|
+
}
|
|
181
|
+
const selfAddress = new GenericSyPda(genericStandardProgramId, interfaceIndex).syMeta({
|
|
182
|
+
yieldBearingMint,
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, interfaceType, cnx)
|
|
186
|
+
|
|
187
|
+
const state: GenericSyState = {
|
|
188
|
+
selfAddress,
|
|
189
|
+
account,
|
|
190
|
+
tokenProgramBase,
|
|
191
|
+
syRate,
|
|
192
|
+
fragmetricData,
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return new GenericSySdk(state, genericStandardProgramId)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Load an instance of SyMeta from just the syMeta address */
|
|
199
|
+
static async loadFromSyMeta({
|
|
200
|
+
cnx,
|
|
201
|
+
syMetaAddress,
|
|
202
|
+
genericStandardProgramId,
|
|
203
|
+
}: {
|
|
204
|
+
cnx: web3.Connection
|
|
205
|
+
syMetaAddress: web3.PublicKey
|
|
206
|
+
genericStandardProgramId: web3.PublicKey
|
|
207
|
+
}) {
|
|
208
|
+
const fetcher = new ExponentFetcher({ connection: cnx, genericStandardProgramId })
|
|
209
|
+
const account = await fetcher.fetchGenericSyMeta(syMetaAddress)
|
|
210
|
+
const tokenProgramBase = TOKEN_PROGRAM_ID
|
|
211
|
+
|
|
212
|
+
const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx)
|
|
213
|
+
|
|
214
|
+
const state: GenericSyState = {
|
|
215
|
+
selfAddress: syMetaAddress,
|
|
216
|
+
account,
|
|
217
|
+
tokenProgramBase,
|
|
218
|
+
syRate,
|
|
219
|
+
fragmetricData,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return new GenericSySdk(state, genericStandardProgramId)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Reload the state of the account */
|
|
226
|
+
async reload(cnx: web3.Connection) {
|
|
227
|
+
const account = await loadAccountState(
|
|
228
|
+
cnx,
|
|
229
|
+
this.state.account.yieldBearingMint,
|
|
230
|
+
this.program.programId,
|
|
231
|
+
this.state.account.interfaceType,
|
|
232
|
+
)
|
|
233
|
+
this.state.account = account
|
|
234
|
+
const { syRate, fragmetricData } = await GenericSySdk.calculateSyRate(account, account.interfaceType, cnx)
|
|
235
|
+
this.state.syRate = syRate
|
|
236
|
+
this.state.fragmetricData = fragmetricData
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
get account() {
|
|
240
|
+
return this.state.account
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
get mintSy() {
|
|
244
|
+
return this.account.mintSy
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
get vrtMint() {
|
|
248
|
+
return this.account.yieldBearingMint
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
get maxSySupply() {
|
|
252
|
+
return this.account.maxSySupply
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
get emissions() {
|
|
256
|
+
return this.account.emissions
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
get minMintSize() {
|
|
260
|
+
return this.account.minMintSize
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
get minRedeemSize() {
|
|
264
|
+
return this.account.minRedeemSize
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// get mintBase() {
|
|
268
|
+
// return this.state.mintBase
|
|
269
|
+
// }
|
|
270
|
+
|
|
271
|
+
get selfAddress() {
|
|
272
|
+
return this.state.selfAddress
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
get tokenProgramBase() {
|
|
276
|
+
return this.state.tokenProgramBase
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
get tokenVrtEscrow() {
|
|
280
|
+
return getAssociatedTokenAddressSync(this.vrtMint, this.selfAddress, true, TOKEN_PROGRAM_ID)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
get tokenSyEscrow() {
|
|
284
|
+
return this.state.account.tokenSyEscrow
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
get adminState() {
|
|
288
|
+
return new ExponentAdminPda(EXPONENT_ADMIN_PROGRAM_ID).exponentAdmin()
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
get fragmetricData() {
|
|
292
|
+
if (!("fragmetric" in this.state.account.interfaceType)) {
|
|
293
|
+
throw new Error("Not a fragmetric interface")
|
|
294
|
+
}
|
|
295
|
+
if (!this.state.fragmetricData) {
|
|
296
|
+
throw new Error("Fragmetric data not loaded")
|
|
297
|
+
}
|
|
298
|
+
return this.state.fragmetricData
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
get remainingAccounts() {
|
|
302
|
+
const accounts = this.account.interfaceAccounts
|
|
303
|
+
.map((a) => ({
|
|
304
|
+
pubkey: a,
|
|
305
|
+
isSigner: false,
|
|
306
|
+
isWritable: true,
|
|
307
|
+
}))
|
|
308
|
+
.concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })))
|
|
309
|
+
|
|
310
|
+
return accounts
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
getAccountsWithSigner(signer?: web3.PublicKey) {
|
|
314
|
+
const accounts = this.remainingAccounts
|
|
315
|
+
|
|
316
|
+
if ("fragmetric" in this.state.account.interfaceType && signer) {
|
|
317
|
+
const fragmetricReceiptTokenMint = this.state.fragmetricData.receiptTokenMint
|
|
318
|
+
const fragmetricWrappedTokenMint = this.state.fragmetricData.wrappedTokenMint
|
|
319
|
+
const fragmetricPda = new FragmetricPda()
|
|
320
|
+
const fragmetricFundAccount = fragmetricPda.fundAccount(fragmetricReceiptTokenMint)
|
|
321
|
+
const fragmetricRewardAccount = fragmetricPda.rewardAccount(fragmetricReceiptTokenMint)
|
|
322
|
+
|
|
323
|
+
const userReceiptTokenAccount = getAssociatedTokenAddressSync(
|
|
324
|
+
fragmetricReceiptTokenMint,
|
|
325
|
+
signer,
|
|
326
|
+
true,
|
|
327
|
+
TOKEN_2022_PROGRAM_ID,
|
|
328
|
+
)
|
|
329
|
+
const userWrappedTokenAccount = getAssociatedTokenAddressSync(
|
|
330
|
+
fragmetricWrappedTokenMint,
|
|
331
|
+
signer,
|
|
332
|
+
true,
|
|
333
|
+
TOKEN_PROGRAM_ID,
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
const fundWrapAccount = fragmetricPda.fundWrapAccount(fragmetricReceiptTokenMint)
|
|
337
|
+
|
|
338
|
+
const receiptTokenWrapAccount = getAssociatedTokenAddressSync(
|
|
339
|
+
fragmetricReceiptTokenMint,
|
|
340
|
+
fundWrapAccount,
|
|
341
|
+
true,
|
|
342
|
+
TOKEN_2022_PROGRAM_ID,
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
const fundWrapAccountRewardAccount = fragmetricPda.userRewardAccount(fragmetricReceiptTokenMint, fundWrapAccount)
|
|
346
|
+
|
|
347
|
+
const userFundAccount = fragmetricPda.userFundAccount(fragmetricReceiptTokenMint, signer)
|
|
348
|
+
const userRewardAccount = fragmetricPda.userRewardAccount(fragmetricReceiptTokenMint, signer)
|
|
349
|
+
|
|
350
|
+
const eventAuthority = fragmetricPda.eventAuthority()
|
|
351
|
+
|
|
352
|
+
console.log("fund wrap account", fundWrapAccount.toBase58())
|
|
353
|
+
console.log("user fund account", userFundAccount.toBase58())
|
|
354
|
+
console.log("user reward account", userRewardAccount.toBase58())
|
|
355
|
+
console.log("receipt token mint", fragmetricReceiptTokenMint.toBase58())
|
|
356
|
+
console.log("wrapped token mint", fragmetricWrappedTokenMint.toBase58())
|
|
357
|
+
console.log("receipt token wrap account", receiptTokenWrapAccount.toBase58())
|
|
358
|
+
accounts.push(
|
|
359
|
+
// user
|
|
360
|
+
{ pubkey: signer, isSigner: true, isWritable: true },
|
|
361
|
+
// fund wrap account
|
|
362
|
+
{ pubkey: fundWrapAccount, isSigner: false, isWritable: true },
|
|
363
|
+
// receipt token program
|
|
364
|
+
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
365
|
+
// wrapped token program
|
|
366
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
367
|
+
{ pubkey: fragmetricReceiptTokenMint, isSigner: false, isWritable: true },
|
|
368
|
+
{ pubkey: fragmetricWrappedTokenMint, isSigner: false, isWritable: true },
|
|
369
|
+
{ pubkey: userReceiptTokenAccount, isSigner: false, isWritable: true },
|
|
370
|
+
{ pubkey: receiptTokenWrapAccount, isSigner: false, isWritable: true },
|
|
371
|
+
{ pubkey: userWrappedTokenAccount, isSigner: false, isWritable: true },
|
|
372
|
+
{ pubkey: fragmetricFundAccount, isSigner: false, isWritable: true },
|
|
373
|
+
{ pubkey: userFundAccount, isSigner: false, isWritable: true },
|
|
374
|
+
{ pubkey: fragmetricRewardAccount, isSigner: false, isWritable: true },
|
|
375
|
+
{ pubkey: userRewardAccount, isSigner: false, isWritable: true },
|
|
376
|
+
{ pubkey: fundWrapAccountRewardAccount, isSigner: false, isWritable: true },
|
|
377
|
+
{ pubkey: eventAuthority, isSigner: false, isWritable: false },
|
|
378
|
+
{
|
|
379
|
+
pubkey: FRAGMETRIC_PROGRAM_ID,
|
|
380
|
+
isSigner: false,
|
|
381
|
+
isWritable: false,
|
|
382
|
+
},
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return accounts
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
ixMintSy({
|
|
390
|
+
depositor,
|
|
391
|
+
amountBase,
|
|
392
|
+
baseSrc,
|
|
393
|
+
syDst,
|
|
394
|
+
}: {
|
|
395
|
+
depositor: web3.PublicKey
|
|
396
|
+
amountBase: string
|
|
397
|
+
baseSrc?: web3.PublicKey
|
|
398
|
+
syDst?: web3.PublicKey
|
|
399
|
+
}) {
|
|
400
|
+
baseSrc = baseSrc || getAssociatedTokenAddressSync(this.vrtMint, depositor, true, this.state.tokenProgramBase)
|
|
401
|
+
console.log("baseSrc", baseSrc.toBase58())
|
|
402
|
+
console.log("depositor", depositor.toBase58())
|
|
403
|
+
syDst = syDst || getAssociatedTokenAddressSync(this.mintSy, depositor, true, TOKEN_PROGRAM_ID)
|
|
404
|
+
|
|
405
|
+
console.log("this.selfAddress", this.selfAddress.toBase58())
|
|
406
|
+
return this.program.methods
|
|
407
|
+
.mint(new BN(amountBase))
|
|
408
|
+
.accountsStrict({
|
|
409
|
+
meta: this.selfAddress,
|
|
410
|
+
baseTokenProgram: this.tokenProgramBase,
|
|
411
|
+
depositor,
|
|
412
|
+
mintSy: this.mintSy,
|
|
413
|
+
tokenBaseDepositor: baseSrc,
|
|
414
|
+
tokenSyDepositor: syDst,
|
|
415
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
416
|
+
tokenVrtEscrow: this.tokenVrtEscrow,
|
|
417
|
+
})
|
|
418
|
+
.remainingAccounts(this.getAccountsWithSigner(depositor))
|
|
419
|
+
.instruction()
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
ixRedeemSy({
|
|
423
|
+
redeemer,
|
|
424
|
+
amountSy,
|
|
425
|
+
baseDst,
|
|
426
|
+
sySrc,
|
|
427
|
+
}: {
|
|
428
|
+
redeemer: web3.PublicKey
|
|
429
|
+
amountSy: string
|
|
430
|
+
baseDst?: web3.PublicKey
|
|
431
|
+
sySrc?: web3.PublicKey
|
|
432
|
+
}) {
|
|
433
|
+
baseDst = baseDst || getAssociatedTokenAddressSync(this.vrtMint, redeemer, true, this.tokenProgramBase)
|
|
434
|
+
sySrc = sySrc || getAssociatedTokenAddressSync(this.mintSy, redeemer, true, TOKEN_PROGRAM_ID)
|
|
435
|
+
|
|
436
|
+
return this.program.methods
|
|
437
|
+
.redeem(new BN(amountSy))
|
|
438
|
+
.accountsStrict({
|
|
439
|
+
meta: this.selfAddress,
|
|
440
|
+
mintSy: this.mintSy,
|
|
441
|
+
tokenSySigner: sySrc,
|
|
442
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
443
|
+
signer: redeemer,
|
|
444
|
+
tokenBaseDst: baseDst,
|
|
445
|
+
tokenBaseProgram: this.tokenProgramBase,
|
|
446
|
+
tokenVrtEscrow: this.tokenVrtEscrow,
|
|
447
|
+
})
|
|
448
|
+
.remainingAccounts(this.getAccountsWithSigner(redeemer))
|
|
449
|
+
.instruction()
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
getSyState() {
|
|
453
|
+
return this.program.methods
|
|
454
|
+
.getState()
|
|
455
|
+
.accountsStrict({
|
|
456
|
+
meta: this.selfAddress,
|
|
457
|
+
mintSy: this.mintSy,
|
|
458
|
+
tokenSyEscrow: this.tokenSyEscrow,
|
|
459
|
+
})
|
|
460
|
+
.remainingAccounts(this.remainingAccounts)
|
|
461
|
+
.instruction()
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
ixAddEmission({
|
|
465
|
+
signer,
|
|
466
|
+
emissionMint,
|
|
467
|
+
emissionTokenAccount,
|
|
468
|
+
}: {
|
|
469
|
+
signer: web3.PublicKey
|
|
470
|
+
emissionMint: web3.PublicKey
|
|
471
|
+
emissionTokenAccount: web3.PublicKey
|
|
472
|
+
}) {
|
|
473
|
+
return this.program.methods
|
|
474
|
+
.addEmission()
|
|
475
|
+
.accountsStrict({
|
|
476
|
+
meta: this.selfAddress,
|
|
477
|
+
signer,
|
|
478
|
+
feePayer: signer,
|
|
479
|
+
tokenEmission: emissionTokenAccount,
|
|
480
|
+
mintEmission: emissionMint,
|
|
481
|
+
systemProgram: web3.SystemProgram.programId,
|
|
482
|
+
adminState: this.adminState,
|
|
483
|
+
})
|
|
484
|
+
.instruction()
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export function initSy(
|
|
489
|
+
signer: web3.PublicKey,
|
|
490
|
+
interfaceAccounts: web3.PublicKey[],
|
|
491
|
+
yieldBearingMint: web3.PublicKey,
|
|
492
|
+
interfaceIndex: number,
|
|
493
|
+
) {
|
|
494
|
+
const program = new Program<GenericStandard>(
|
|
495
|
+
IDL,
|
|
496
|
+
new AnchorProvider(new web3.Connection("https://api.devnet.solana.com"), new MyWallet(web3.Keypair.generate())),
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
console.log("interfaceIndex", interfaceIndex)
|
|
500
|
+
const pda = new GenericSyPda(program.programId, interfaceIndex)
|
|
501
|
+
const syMetaAddress = pda.syMeta({ yieldBearingMint })
|
|
502
|
+
console.log("this.selfAddress in sdk", syMetaAddress.toBase58())
|
|
503
|
+
const mintSy = pda.mintSy({ yieldBearingMint })
|
|
504
|
+
console.log("mintSy in sdk", mintSy.toBase58())
|
|
505
|
+
const exponentAdminPda = new ExponentAdminPda(EXPONENT_ADMIN_PROGRAM_ID)
|
|
506
|
+
|
|
507
|
+
const metaplexMetadataProgram = new web3.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
|
|
508
|
+
const mintSyMetaplexMetadataPda = web3.PublicKey.findProgramAddressSync(
|
|
509
|
+
[Buffer.from("metadata"), metaplexMetadataProgram.toBuffer(), mintSy.toBuffer()],
|
|
510
|
+
metaplexMetadataProgram,
|
|
511
|
+
)[0]
|
|
512
|
+
|
|
513
|
+
const tokenVrtEscrow = getAssociatedTokenAddressSync(yieldBearingMint, syMetaAddress, true, TOKEN_PROGRAM_ID)
|
|
514
|
+
|
|
515
|
+
const interfaceType = getInterfaceTypeObj(interfaceIndex)
|
|
516
|
+
const ix = program.methods
|
|
517
|
+
.initSy(new BN(0), new BN(0), "Exponent Wrapped fragSOL", "ewfragSOL", "", interfaceAccounts, interfaceType)
|
|
518
|
+
.accountsStrict({
|
|
519
|
+
syMeta: syMetaAddress,
|
|
520
|
+
mintSy: mintSy,
|
|
521
|
+
adminState: exponentAdminPda.exponentAdmin(),
|
|
522
|
+
admin: signer,
|
|
523
|
+
yieldBearingMint,
|
|
524
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
525
|
+
tokenSyEscrow: pda.syEscrow({ yieldBearingMint }),
|
|
526
|
+
systemProgram: web3.SystemProgram.programId,
|
|
527
|
+
metadata: mintSyMetaplexMetadataPda,
|
|
528
|
+
tokenMetadataProgram: metaplexMetadataProgram,
|
|
529
|
+
tokenVrtEscrow,
|
|
530
|
+
})
|
|
531
|
+
.instruction()
|
|
532
|
+
|
|
533
|
+
return ix
|
|
534
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { web3 } from "@coral-xyz/anchor"
|
|
2
|
+
import type { Wallet } from "@coral-xyz/anchor"
|
|
3
|
+
|
|
4
|
+
export class MyWallet implements Wallet {
|
|
5
|
+
constructor(readonly payer: web3.Keypair) {
|
|
6
|
+
this.payer = payer
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async signTransaction<T extends web3.Transaction | web3.VersionedTransaction>(tx: T): Promise<T> {
|
|
10
|
+
if (tx instanceof web3.Transaction) {
|
|
11
|
+
tx.partialSign(this.payer)
|
|
12
|
+
} else {
|
|
13
|
+
tx.sign([this.payer])
|
|
14
|
+
}
|
|
15
|
+
return tx
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async signAllTransactions<T extends web3.Transaction | web3.VersionedTransaction>(txs: T[]): Promise<T[]> {
|
|
19
|
+
return txs.map((t) => {
|
|
20
|
+
if (t instanceof web3.Transaction) {
|
|
21
|
+
t.partialSign(this.payer)
|
|
22
|
+
} else if (t instanceof web3.VersionedTransaction) {
|
|
23
|
+
t.sign([this.payer])
|
|
24
|
+
}
|
|
25
|
+
return t
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get publicKey(): web3.PublicKey {
|
|
30
|
+
return this.payer.publicKey
|
|
31
|
+
}
|
|
32
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"rootDir": "src",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */,
|
|
6
|
+
"composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */,
|
|
7
|
+
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
|
8
|
+
"module": "CommonJS" /* Specify what module code is generated. */,
|
|
9
|
+
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
|
|
10
|
+
"outDir": "./build" /* Specify an output folder for all emitted files. */,
|
|
11
|
+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
12
|
+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
13
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*.ts", "src/**/*.json"],
|
|
17
|
+
"exclude": ["node_modules", "build"],
|
|
18
|
+
"references": [
|
|
19
|
+
{
|
|
20
|
+
"path": "../generic-sy-idl"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../exponent-types"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../exponent-fetcher"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../generic-sy-pda"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"path": "../exponent-admin-pda"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"path": "../fragmetric-pda"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|