@exponent-labs/generic-sy-sdk 0.9.19 → 0.9.21
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/build/index.d.ts +16 -2
- package/build/index.js +160 -207
- package/build/index.js.map +1 -1
- package/build/interfaces/exponentTranching.d.ts +12 -0
- package/build/interfaces/exponentTranching.js +75 -0
- package/build/interfaces/exponentTranching.js.map +1 -0
- package/build/interfaces/glowVault.d.ts +7 -0
- package/build/interfaces/glowVault.js +46 -0
- package/build/interfaces/glowVault.js.map +1 -0
- package/package.json +10 -10
- package/src/index.ts +179 -159
- package/src/interfaces/exponentTranching.ts +125 -0
- package/src/interfaces/glowVault.ts +55 -0
- package/tsconfig.json +3 -0
package/build/index.d.ts
CHANGED
|
@@ -21,8 +21,11 @@ export declare enum InterfaceType {
|
|
|
21
21
|
Chainlink = 15,
|
|
22
22
|
ChainlinkDataStream = 16,
|
|
23
23
|
Scope = 17,
|
|
24
|
-
SolsticeGlamVault = 18
|
|
24
|
+
SolsticeGlamVault = 18,
|
|
25
|
+
ExponentTranching = 19,
|
|
26
|
+
GlowVault = 20
|
|
25
27
|
}
|
|
28
|
+
export declare function getInterfaceTypeIndex(interfaceType: InterfaceTypeGeneric): InterfaceType;
|
|
26
29
|
export declare function getInterfaceTypeObj(interfaceType: number, scopePriceChain?: number[], scopeMaximumAgeSeconds?: number): InterfaceTypeGeneric;
|
|
27
30
|
export declare function getInterfaceTypeFromString(interfaceType: string): InterfaceTypeGeneric;
|
|
28
31
|
interface GenericSyConfig {
|
|
@@ -54,6 +57,8 @@ export declare class GenericSySdk {
|
|
|
54
57
|
/** Reload the state of the account */
|
|
55
58
|
reload(cnx: web3.Connection): Promise<void>;
|
|
56
59
|
get account(): GenericSyMetaAccount;
|
|
60
|
+
get interfaceType(): InterfaceTypeGeneric;
|
|
61
|
+
get initInterfaceType(): InterfaceTypeGeneric;
|
|
57
62
|
get mintSy(): web3.PublicKey;
|
|
58
63
|
get vrtMint(): web3.PublicKey;
|
|
59
64
|
get maxSySupply(): BN;
|
|
@@ -109,7 +114,11 @@ export declare class GenericSySdk {
|
|
|
109
114
|
baseDst?: web3.PublicKey;
|
|
110
115
|
sySrc?: web3.PublicKey;
|
|
111
116
|
}): Promise<web3.TransactionInstruction>;
|
|
112
|
-
|
|
117
|
+
private getFragmetricReceiptTokenAccountSetupInstruction;
|
|
118
|
+
/** Returns interface-specific setup instructions for the signer. */
|
|
119
|
+
preInstructions(signer?: web3.PublicKey): web3.TransactionInstruction[];
|
|
120
|
+
/** Returns signer setup and refresh instructions, including those that require live interface state. */
|
|
121
|
+
getPreInstructions(cnx: web3.Connection, signer?: web3.PublicKey): Promise<web3.TransactionInstruction[]>;
|
|
113
122
|
getSyState(): Promise<web3.TransactionInstruction>;
|
|
114
123
|
ixAddEmission({ signer, emissionMint, emissionTokenAccount, }: {
|
|
115
124
|
signer: web3.PublicKey;
|
|
@@ -126,6 +135,11 @@ export declare class GenericSySdk {
|
|
|
126
135
|
ixModifyOreInterfaceAccount({ signer }: {
|
|
127
136
|
signer: web3.PublicKey;
|
|
128
137
|
}): Promise<web3.TransactionInstruction>;
|
|
138
|
+
ixChangeInterfaceType({ signer, interfaceAccounts, interfaceType, }: {
|
|
139
|
+
signer: web3.PublicKey;
|
|
140
|
+
interfaceAccounts: web3.PublicKey[];
|
|
141
|
+
interfaceType: InterfaceTypeGeneric;
|
|
142
|
+
}): Promise<web3.TransactionInstruction>;
|
|
129
143
|
}
|
|
130
144
|
export declare function initSy(signer: web3.PublicKey, interfaceAccounts: web3.PublicKey[], yieldBearingMint: web3.PublicKey, interfaceIndex: number, syToken?: SyTokenMetadata, initConfig?: SyInitializeConfig, yieldBearingMintTokenProgram?: web3.PublicKey, scopePriceChain?: number[], scopeMaximumAgeSeconds?: number): Promise<web3.TransactionInstruction>;
|
|
131
145
|
export {};
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GenericSySdk = exports.InterfaceType = void 0;
|
|
4
|
+
exports.getInterfaceTypeIndex = getInterfaceTypeIndex;
|
|
4
5
|
exports.getInterfaceTypeObj = getInterfaceTypeObj;
|
|
5
6
|
exports.getInterfaceTypeFromString = getInterfaceTypeFromString;
|
|
6
7
|
exports.initSy = initSy;
|
|
@@ -9,10 +10,13 @@ const spl_stake_pool_1 = require("@solana/spl-stake-pool");
|
|
|
9
10
|
const spl_token_1 = require("@solana/spl-token");
|
|
10
11
|
const exponent_admin_pda_1 = require("@exponent-labs/exponent-admin-pda");
|
|
11
12
|
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
13
|
+
const exponent_types_1 = require("@exponent-labs/exponent-types");
|
|
12
14
|
const fragmetric_pda_1 = require("@exponent-labs/fragmetric-pda");
|
|
13
15
|
const generic_sy_idl_1 = require("@exponent-labs/generic-sy-idl");
|
|
14
16
|
const generic_sy_pda_1 = require("@exponent-labs/generic-sy-pda");
|
|
15
17
|
const precise_number_1 = require("@exponent-labs/precise-number");
|
|
18
|
+
const exponentTranching_1 = require("./interfaces/exponentTranching");
|
|
19
|
+
const glowVault_1 = require("./interfaces/glowVault");
|
|
16
20
|
const utils_1 = require("./utils");
|
|
17
21
|
/**
|
|
18
22
|
* Create a custom updateStakePoolBalance instruction using dynamic program ID
|
|
@@ -37,67 +41,7 @@ function createUpdateStakePoolBalanceInstruction({ stakePool, withdrawAuthority,
|
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
43
|
async function loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType) {
|
|
40
|
-
|
|
41
|
-
if ("pyth" in interfaceType) {
|
|
42
|
-
interfaceIndex = InterfaceType.Pyth;
|
|
43
|
-
}
|
|
44
|
-
else if ("splStakePool" in interfaceType) {
|
|
45
|
-
interfaceIndex = InterfaceType.SplStakePool;
|
|
46
|
-
}
|
|
47
|
-
else if ("one" in interfaceType) {
|
|
48
|
-
interfaceIndex = InterfaceType.One;
|
|
49
|
-
}
|
|
50
|
-
else if ("fragmetric" in interfaceType) {
|
|
51
|
-
interfaceIndex = InterfaceType.Fragmetric;
|
|
52
|
-
}
|
|
53
|
-
else if ("meteora" in interfaceType) {
|
|
54
|
-
interfaceIndex = InterfaceType.Meteora;
|
|
55
|
-
}
|
|
56
|
-
else if ("sanctum" in interfaceType) {
|
|
57
|
-
interfaceIndex = InterfaceType.Sanctum;
|
|
58
|
-
}
|
|
59
|
-
else if ("fragmetricSupportedAsset" in interfaceType) {
|
|
60
|
-
interfaceIndex = InterfaceType.FragmetricSupportedAsset;
|
|
61
|
-
}
|
|
62
|
-
else if ("jupiterPerps" in interfaceType) {
|
|
63
|
-
interfaceIndex = InterfaceType.JupiterPerps;
|
|
64
|
-
}
|
|
65
|
-
else if ("adrena" in interfaceType) {
|
|
66
|
-
interfaceIndex = InterfaceType.Adrena;
|
|
67
|
-
}
|
|
68
|
-
else if ("hyloLpToken" in interfaceType) {
|
|
69
|
-
interfaceIndex = InterfaceType.HyloLpToken;
|
|
70
|
-
}
|
|
71
|
-
else if ("jupiterLend" in interfaceType) {
|
|
72
|
-
interfaceIndex = InterfaceType.JupiterLend;
|
|
73
|
-
}
|
|
74
|
-
else if ("kaminoVault" in interfaceType) {
|
|
75
|
-
interfaceIndex = InterfaceType.KaminoVault;
|
|
76
|
-
}
|
|
77
|
-
else if ("solstice" in interfaceType) {
|
|
78
|
-
interfaceIndex = InterfaceType.Solstice;
|
|
79
|
-
}
|
|
80
|
-
else if ("reflect" in interfaceType) {
|
|
81
|
-
interfaceIndex = InterfaceType.Reflect;
|
|
82
|
-
}
|
|
83
|
-
else if ("ore" in interfaceType) {
|
|
84
|
-
interfaceIndex = InterfaceType.Ore;
|
|
85
|
-
}
|
|
86
|
-
else if ("chainlink" in interfaceType) {
|
|
87
|
-
interfaceIndex = InterfaceType.Chainlink;
|
|
88
|
-
}
|
|
89
|
-
else if ("chainlinkDataStream" in interfaceType) {
|
|
90
|
-
interfaceIndex = InterfaceType.ChainlinkDataStream;
|
|
91
|
-
}
|
|
92
|
-
else if ("scope" in interfaceType) {
|
|
93
|
-
interfaceIndex = InterfaceType.Scope;
|
|
94
|
-
}
|
|
95
|
-
else if ("solsticeGlamVault" in interfaceType) {
|
|
96
|
-
interfaceIndex = InterfaceType.SolsticeGlamVault;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
throw new Error("Unsupported interface type");
|
|
100
|
-
}
|
|
44
|
+
const interfaceIndex = getInterfaceTypeIndex(interfaceType);
|
|
101
45
|
const pda = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex);
|
|
102
46
|
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
|
|
103
47
|
const syMetaAddress = pda.syMeta({ yieldBearingMint });
|
|
@@ -127,7 +71,54 @@ var InterfaceType;
|
|
|
127
71
|
InterfaceType[InterfaceType["ChainlinkDataStream"] = 16] = "ChainlinkDataStream";
|
|
128
72
|
InterfaceType[InterfaceType["Scope"] = 17] = "Scope";
|
|
129
73
|
InterfaceType[InterfaceType["SolsticeGlamVault"] = 18] = "SolsticeGlamVault";
|
|
74
|
+
InterfaceType[InterfaceType["ExponentTranching"] = 19] = "ExponentTranching";
|
|
75
|
+
InterfaceType[InterfaceType["GlowVault"] = 20] = "GlowVault";
|
|
130
76
|
})(InterfaceType || (exports.InterfaceType = InterfaceType = {}));
|
|
77
|
+
function getInterfaceTypeIndex(interfaceType) {
|
|
78
|
+
if ("pyth" in interfaceType)
|
|
79
|
+
return InterfaceType.Pyth;
|
|
80
|
+
if ("splStakePool" in interfaceType)
|
|
81
|
+
return InterfaceType.SplStakePool;
|
|
82
|
+
if ("one" in interfaceType)
|
|
83
|
+
return InterfaceType.One;
|
|
84
|
+
if ("fragmetricSupportedAsset" in interfaceType)
|
|
85
|
+
return InterfaceType.FragmetricSupportedAsset;
|
|
86
|
+
if ("fragmetric" in interfaceType)
|
|
87
|
+
return InterfaceType.Fragmetric;
|
|
88
|
+
if ("meteora" in interfaceType)
|
|
89
|
+
return InterfaceType.Meteora;
|
|
90
|
+
if ("sanctum" in interfaceType)
|
|
91
|
+
return InterfaceType.Sanctum;
|
|
92
|
+
if ("jupiterPerps" in interfaceType)
|
|
93
|
+
return InterfaceType.JupiterPerps;
|
|
94
|
+
if ("adrena" in interfaceType)
|
|
95
|
+
return InterfaceType.Adrena;
|
|
96
|
+
if ("hyloLpToken" in interfaceType)
|
|
97
|
+
return InterfaceType.HyloLpToken;
|
|
98
|
+
if ("jupiterLend" in interfaceType)
|
|
99
|
+
return InterfaceType.JupiterLend;
|
|
100
|
+
if ("kaminoVault" in interfaceType)
|
|
101
|
+
return InterfaceType.KaminoVault;
|
|
102
|
+
if ("solstice" in interfaceType)
|
|
103
|
+
return InterfaceType.Solstice;
|
|
104
|
+
if ("reflect" in interfaceType)
|
|
105
|
+
return InterfaceType.Reflect;
|
|
106
|
+
if ("ore" in interfaceType)
|
|
107
|
+
return InterfaceType.Ore;
|
|
108
|
+
if ("chainlinkDataStream" in interfaceType)
|
|
109
|
+
return InterfaceType.ChainlinkDataStream;
|
|
110
|
+
if ("chainlink" in interfaceType)
|
|
111
|
+
return InterfaceType.Chainlink;
|
|
112
|
+
if ("scope" in interfaceType)
|
|
113
|
+
return InterfaceType.Scope;
|
|
114
|
+
if ("solsticeGlamVault" in interfaceType)
|
|
115
|
+
return InterfaceType.SolsticeGlamVault;
|
|
116
|
+
if ("exponentTranching" in interfaceType)
|
|
117
|
+
return InterfaceType.ExponentTranching;
|
|
118
|
+
if ("glowVault" in interfaceType)
|
|
119
|
+
return InterfaceType.GlowVault;
|
|
120
|
+
throw new Error("Unsupported interface type");
|
|
121
|
+
}
|
|
131
122
|
function getInterfaceTypeObj(interfaceType, scopePriceChain = [0, 512, 512, 512], scopeMaximumAgeSeconds = 3600) {
|
|
132
123
|
switch (interfaceType) {
|
|
133
124
|
case InterfaceType.Pyth:
|
|
@@ -184,6 +175,10 @@ function getInterfaceTypeObj(interfaceType, scopePriceChain = [0, 512, 512, 512]
|
|
|
184
175
|
return { scope: { priceChain: scopePriceChain, maximumAgeSeconds: new anchor_1.BN(scopeMaximumAgeSeconds) } };
|
|
185
176
|
case InterfaceType.SolsticeGlamVault:
|
|
186
177
|
return { solsticeGlamVault: { padding: [] } };
|
|
178
|
+
case InterfaceType.ExponentTranching:
|
|
179
|
+
return { exponentTranching: {} };
|
|
180
|
+
case InterfaceType.GlowVault:
|
|
181
|
+
return { glowVault: { padding: [] } };
|
|
187
182
|
default:
|
|
188
183
|
throw new Error(`Unsupported interface type: ${interfaceType}`);
|
|
189
184
|
}
|
|
@@ -242,6 +237,10 @@ function getInterfaceTypeFromString(interfaceType) {
|
|
|
242
237
|
return { scope: { priceChain: [0, 512, 512, 512], maximumAgeSeconds: new anchor_1.BN(3600) } };
|
|
243
238
|
case "solstice-glam-vault":
|
|
244
239
|
return { solsticeGlamVault: { padding: [] } };
|
|
240
|
+
case "exponent-tranching":
|
|
241
|
+
return { exponentTranching: {} };
|
|
242
|
+
case "glow-vault":
|
|
243
|
+
return { glowVault: { padding: [] } };
|
|
245
244
|
default:
|
|
246
245
|
throw new Error(`Unsupported interface type: ${interfaceType}`);
|
|
247
246
|
}
|
|
@@ -257,68 +256,7 @@ class GenericSySdk {
|
|
|
257
256
|
this.config = config;
|
|
258
257
|
// create a fake AnchorProvider -- which is unused
|
|
259
258
|
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())));
|
|
260
|
-
|
|
261
|
-
let interfaceIndex;
|
|
262
|
-
if ("pyth" in this.state.account.interfaceType) {
|
|
263
|
-
interfaceIndex = InterfaceType.Pyth;
|
|
264
|
-
}
|
|
265
|
-
else if ("splStakePool" in this.state.account.interfaceType) {
|
|
266
|
-
interfaceIndex = InterfaceType.SplStakePool;
|
|
267
|
-
}
|
|
268
|
-
else if ("one" in this.state.account.interfaceType) {
|
|
269
|
-
interfaceIndex = InterfaceType.One;
|
|
270
|
-
}
|
|
271
|
-
else if ("fragmetricSupportedAsset" in this.state.account.interfaceType) {
|
|
272
|
-
interfaceIndex = InterfaceType.FragmetricSupportedAsset;
|
|
273
|
-
}
|
|
274
|
-
else if ("fragmetric" in this.state.account.interfaceType) {
|
|
275
|
-
interfaceIndex = InterfaceType.Fragmetric;
|
|
276
|
-
}
|
|
277
|
-
else if ("meteora" in this.state.account.interfaceType) {
|
|
278
|
-
interfaceIndex = InterfaceType.Meteora;
|
|
279
|
-
}
|
|
280
|
-
else if ("sanctum" in this.state.account.interfaceType) {
|
|
281
|
-
interfaceIndex = InterfaceType.Sanctum;
|
|
282
|
-
}
|
|
283
|
-
else if ("jupiterPerps" in this.state.account.interfaceType) {
|
|
284
|
-
interfaceIndex = InterfaceType.JupiterPerps;
|
|
285
|
-
}
|
|
286
|
-
else if ("adrena" in this.state.account.interfaceType) {
|
|
287
|
-
interfaceIndex = InterfaceType.Adrena;
|
|
288
|
-
}
|
|
289
|
-
else if ("hyloLpToken" in this.state.account.interfaceType) {
|
|
290
|
-
interfaceIndex = InterfaceType.HyloLpToken;
|
|
291
|
-
}
|
|
292
|
-
else if ("jupiterLend" in this.state.account.interfaceType) {
|
|
293
|
-
interfaceIndex = InterfaceType.JupiterLend;
|
|
294
|
-
}
|
|
295
|
-
else if ("kaminoVault" in this.state.account.interfaceType) {
|
|
296
|
-
interfaceIndex = InterfaceType.KaminoVault;
|
|
297
|
-
}
|
|
298
|
-
else if ("solstice" in this.state.account.interfaceType) {
|
|
299
|
-
interfaceIndex = InterfaceType.Solstice;
|
|
300
|
-
}
|
|
301
|
-
else if ("reflect" in this.state.account.interfaceType) {
|
|
302
|
-
interfaceIndex = InterfaceType.Reflect;
|
|
303
|
-
}
|
|
304
|
-
else if ("ore" in this.state.account.interfaceType) {
|
|
305
|
-
interfaceIndex = InterfaceType.Ore;
|
|
306
|
-
}
|
|
307
|
-
else if ("chainlink" in this.state.account.interfaceType) {
|
|
308
|
-
interfaceIndex = InterfaceType.Chainlink;
|
|
309
|
-
}
|
|
310
|
-
else if ("chainlinkDataStream" in this.state.account.interfaceType) {
|
|
311
|
-
interfaceIndex = InterfaceType.ChainlinkDataStream;
|
|
312
|
-
}
|
|
313
|
-
else if ("scope" in this.state.account.interfaceType) {
|
|
314
|
-
interfaceIndex = InterfaceType.Scope;
|
|
315
|
-
}
|
|
316
|
-
else if ("solsticeGlamVault" in this.state.account.interfaceType) {
|
|
317
|
-
interfaceIndex = InterfaceType.SolsticeGlamVault;
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
throw new Error("Unsupported interface type");
|
|
321
|
-
}
|
|
259
|
+
const interfaceIndex = getInterfaceTypeIndex((0, exponent_types_1.getGenericSyMetaInitInterfaceType)(this.state.account));
|
|
322
260
|
this.syPda = new generic_sy_pda_1.GenericSyPda(programId, interfaceIndex);
|
|
323
261
|
}
|
|
324
262
|
static async calculateSyRate(account, interfaceType, cnx) {
|
|
@@ -374,7 +312,7 @@ class GenericSySdk {
|
|
|
374
312
|
}
|
|
375
313
|
else if ("meteora" in interfaceType) {
|
|
376
314
|
const currentTs = Math.floor(Date.now() / 1000);
|
|
377
|
-
|
|
315
|
+
let accounts = {
|
|
378
316
|
pool: account.interfaceAccounts[0],
|
|
379
317
|
vaultA: account.interfaceAccounts[4],
|
|
380
318
|
vaultB: account.interfaceAccounts[5],
|
|
@@ -392,10 +330,9 @@ class GenericSySdk {
|
|
|
392
330
|
return { syRate: exchangeRate };
|
|
393
331
|
}
|
|
394
332
|
else if ("adrena" in interfaceType) {
|
|
395
|
-
|
|
396
|
-
const previousTotalFees = account.interfaceType.adrena.previousTotalFees;
|
|
333
|
+
const previousTotalFees = interfaceType.adrena.previousTotalFees;
|
|
397
334
|
const currentIndex = account.index;
|
|
398
|
-
|
|
335
|
+
const accounts = {
|
|
399
336
|
pool: account.interfaceAccounts[0],
|
|
400
337
|
custody1: account.interfaceAccounts[1],
|
|
401
338
|
custody2: account.interfaceAccounts[2],
|
|
@@ -406,8 +343,7 @@ class GenericSySdk {
|
|
|
406
343
|
return { syRate: syRate.index };
|
|
407
344
|
}
|
|
408
345
|
else if ("jupiterPerps" in interfaceType) {
|
|
409
|
-
|
|
410
|
-
const j = account.interfaceType.jupiterPerps;
|
|
346
|
+
const j = interfaceType.jupiterPerps;
|
|
411
347
|
const { index } = await (0, exponent_fetcher_1.fetchJupiterPerpsIndex)({
|
|
412
348
|
connection: cnx,
|
|
413
349
|
pool: account.interfaceAccounts[0],
|
|
@@ -532,6 +468,30 @@ class GenericSySdk {
|
|
|
532
468
|
});
|
|
533
469
|
return { syRate };
|
|
534
470
|
}
|
|
471
|
+
else if ("exponentTranching" in interfaceType) {
|
|
472
|
+
const marketAddress = account.interfaceAccounts[0];
|
|
473
|
+
if (account.interfaceAccounts.length !== 1 || !marketAddress) {
|
|
474
|
+
throw new Error("Exponent Tranching interface requires exactly one market account");
|
|
475
|
+
}
|
|
476
|
+
const syRate = await (0, exponentTranching_1.fetchExponentTranchingRate)({
|
|
477
|
+
connection: cnx,
|
|
478
|
+
marketAddress,
|
|
479
|
+
yieldBearingMint: account.yieldBearingMint,
|
|
480
|
+
});
|
|
481
|
+
return { syRate };
|
|
482
|
+
}
|
|
483
|
+
else if ("glowVault" in interfaceType) {
|
|
484
|
+
const vaultAddress = account.interfaceAccounts[0];
|
|
485
|
+
if (account.interfaceAccounts.length !== 1 || !vaultAddress) {
|
|
486
|
+
throw new Error("Glow Vault interface requires exactly one vault account");
|
|
487
|
+
}
|
|
488
|
+
const syRate = await (0, glowVault_1.fetchGlowVaultRate)({
|
|
489
|
+
connection: cnx,
|
|
490
|
+
vaultAddress,
|
|
491
|
+
expectedShareMint: account.yieldBearingMint,
|
|
492
|
+
});
|
|
493
|
+
return { syRate };
|
|
494
|
+
}
|
|
535
495
|
else {
|
|
536
496
|
return { syRate: 1 };
|
|
537
497
|
}
|
|
@@ -540,71 +500,11 @@ class GenericSySdk {
|
|
|
540
500
|
static async load({ cnx, yieldBearingMint, interfaceType, genericStandardProgramId, config = {}, }) {
|
|
541
501
|
const account = await loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType);
|
|
542
502
|
const tokenProgramBase = (await cnx.getAccountInfo(yieldBearingMint))?.owner;
|
|
543
|
-
|
|
544
|
-
if ("pyth" in interfaceType) {
|
|
545
|
-
interfaceIndex = InterfaceType.Pyth;
|
|
546
|
-
}
|
|
547
|
-
else if ("splStakePool" in interfaceType) {
|
|
548
|
-
interfaceIndex = InterfaceType.SplStakePool;
|
|
549
|
-
}
|
|
550
|
-
else if ("one" in interfaceType) {
|
|
551
|
-
interfaceIndex = InterfaceType.One;
|
|
552
|
-
}
|
|
553
|
-
else if ("fragmetricSupportedAsset" in interfaceType) {
|
|
554
|
-
interfaceIndex = InterfaceType.FragmetricSupportedAsset;
|
|
555
|
-
}
|
|
556
|
-
else if ("fragmetric" in interfaceType) {
|
|
557
|
-
interfaceIndex = InterfaceType.Fragmetric;
|
|
558
|
-
}
|
|
559
|
-
else if ("meteora" in interfaceType) {
|
|
560
|
-
interfaceIndex = InterfaceType.Meteora;
|
|
561
|
-
}
|
|
562
|
-
else if ("sanctum" in interfaceType) {
|
|
563
|
-
interfaceIndex = InterfaceType.Sanctum;
|
|
564
|
-
}
|
|
565
|
-
else if ("jupiterPerps" in interfaceType) {
|
|
566
|
-
interfaceIndex = InterfaceType.JupiterPerps;
|
|
567
|
-
}
|
|
568
|
-
else if ("adrena" in interfaceType) {
|
|
569
|
-
interfaceIndex = InterfaceType.Adrena;
|
|
570
|
-
}
|
|
571
|
-
else if ("hyloLpToken" in interfaceType) {
|
|
572
|
-
interfaceIndex = InterfaceType.HyloLpToken;
|
|
573
|
-
}
|
|
574
|
-
else if ("jupiterLend" in interfaceType) {
|
|
575
|
-
interfaceIndex = InterfaceType.JupiterLend;
|
|
576
|
-
}
|
|
577
|
-
else if ("kaminoVault" in interfaceType) {
|
|
578
|
-
interfaceIndex = InterfaceType.KaminoVault;
|
|
579
|
-
}
|
|
580
|
-
else if ("solstice" in interfaceType) {
|
|
581
|
-
interfaceIndex = InterfaceType.Solstice;
|
|
582
|
-
}
|
|
583
|
-
else if ("reflect" in interfaceType) {
|
|
584
|
-
interfaceIndex = InterfaceType.Reflect;
|
|
585
|
-
}
|
|
586
|
-
else if ("ore" in interfaceType) {
|
|
587
|
-
interfaceIndex = InterfaceType.Ore;
|
|
588
|
-
}
|
|
589
|
-
else if ("chainlink" in interfaceType) {
|
|
590
|
-
interfaceIndex = InterfaceType.Chainlink;
|
|
591
|
-
}
|
|
592
|
-
else if ("chainlinkDataStream" in interfaceType) {
|
|
593
|
-
interfaceIndex = InterfaceType.ChainlinkDataStream;
|
|
594
|
-
}
|
|
595
|
-
else if ("scope" in interfaceType) {
|
|
596
|
-
interfaceIndex = InterfaceType.Scope;
|
|
597
|
-
}
|
|
598
|
-
else if ("solsticeGlamVault" in interfaceType) {
|
|
599
|
-
interfaceIndex = InterfaceType.SolsticeGlamVault;
|
|
600
|
-
}
|
|
601
|
-
else {
|
|
602
|
-
throw new Error("Unsupported interface type");
|
|
603
|
-
}
|
|
503
|
+
const interfaceIndex = getInterfaceTypeIndex((0, exponent_types_1.getGenericSyMetaInitInterfaceType)(account));
|
|
604
504
|
const selfAddress = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex).syMeta({
|
|
605
505
|
yieldBearingMint,
|
|
606
506
|
});
|
|
607
|
-
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account,
|
|
507
|
+
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, (0, exponent_types_1.getGenericSyMetaInterfaceType)(account), cnx);
|
|
608
508
|
const state = {
|
|
609
509
|
selfAddress,
|
|
610
510
|
account,
|
|
@@ -619,7 +519,7 @@ class GenericSySdk {
|
|
|
619
519
|
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
|
|
620
520
|
const account = await fetcher.fetchGenericSyMeta(syMetaAddress);
|
|
621
521
|
const tokenProgramBase = (await cnx.getAccountInfo(account.yieldBearingMint))?.owner;
|
|
622
|
-
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, account
|
|
522
|
+
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, (0, exponent_types_1.getGenericSyMetaInterfaceType)(account), cnx);
|
|
623
523
|
const state = {
|
|
624
524
|
selfAddress: syMetaAddress,
|
|
625
525
|
account,
|
|
@@ -631,15 +531,22 @@ class GenericSySdk {
|
|
|
631
531
|
}
|
|
632
532
|
/** Reload the state of the account */
|
|
633
533
|
async reload(cnx) {
|
|
634
|
-
const
|
|
534
|
+
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId: this.program.programId });
|
|
535
|
+
const account = await fetcher.fetchGenericSyMeta(this.state.selfAddress);
|
|
635
536
|
this.state.account = account;
|
|
636
|
-
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, account
|
|
537
|
+
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, (0, exponent_types_1.getGenericSyMetaInterfaceType)(account), cnx);
|
|
637
538
|
this.state.syRate = syRate;
|
|
638
539
|
this.state.additionalData = additionalData;
|
|
639
540
|
}
|
|
640
541
|
get account() {
|
|
641
542
|
return this.state.account;
|
|
642
543
|
}
|
|
544
|
+
get interfaceType() {
|
|
545
|
+
return (0, exponent_types_1.getGenericSyMetaInterfaceType)(this.account);
|
|
546
|
+
}
|
|
547
|
+
get initInterfaceType() {
|
|
548
|
+
return (0, exponent_types_1.getGenericSyMetaInitInterfaceType)(this.account);
|
|
549
|
+
}
|
|
643
550
|
get mintSy() {
|
|
644
551
|
return this.account.mintSy;
|
|
645
552
|
}
|
|
@@ -677,8 +584,7 @@ class GenericSySdk {
|
|
|
677
584
|
return new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID).exponentAdmin();
|
|
678
585
|
}
|
|
679
586
|
get fragmetricData() {
|
|
680
|
-
if (!("fragmetric" in this.
|
|
681
|
-
!("fragmetricSupportedAsset" in this.state.account.interfaceType)) {
|
|
587
|
+
if (!("fragmetric" in this.interfaceType) && !("fragmetricSupportedAsset" in this.interfaceType)) {
|
|
682
588
|
throw new Error("Not a fragmetric interface");
|
|
683
589
|
}
|
|
684
590
|
if (!this.state.additionalData?.fragmetricData) {
|
|
@@ -687,7 +593,7 @@ class GenericSySdk {
|
|
|
687
593
|
return this.state.additionalData.fragmetricData;
|
|
688
594
|
}
|
|
689
595
|
get jupiterLendData() {
|
|
690
|
-
if (!("jupiterLend" in this.
|
|
596
|
+
if (!("jupiterLend" in this.interfaceType)) {
|
|
691
597
|
throw new Error("Not a Jupiter Lend interface");
|
|
692
598
|
}
|
|
693
599
|
if (!this.state.additionalData?.jupiterLendData) {
|
|
@@ -696,7 +602,7 @@ class GenericSySdk {
|
|
|
696
602
|
return this.state.additionalData.jupiterLendData;
|
|
697
603
|
}
|
|
698
604
|
get kaminoVaultData() {
|
|
699
|
-
if (!("kaminoVault" in this.
|
|
605
|
+
if (!("kaminoVault" in this.interfaceType)) {
|
|
700
606
|
throw new Error("Not a Kamino Vault interface");
|
|
701
607
|
}
|
|
702
608
|
if (!this.state.additionalData?.kaminoVaultData) {
|
|
@@ -722,9 +628,7 @@ class GenericSySdk {
|
|
|
722
628
|
isWritable: true,
|
|
723
629
|
}))
|
|
724
630
|
.concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })));
|
|
725
|
-
if (("fragmetric" in this.
|
|
726
|
-
"fragmetricSupportedAsset" in this.state.account.interfaceType) &&
|
|
727
|
-
signer) {
|
|
631
|
+
if (("fragmetric" in this.interfaceType || "fragmetricSupportedAsset" in this.interfaceType) && signer) {
|
|
728
632
|
// If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
|
|
729
633
|
if (this.config.skipWrap) {
|
|
730
634
|
return accounts;
|
|
@@ -760,7 +664,7 @@ class GenericSySdk {
|
|
|
760
664
|
isWritable: false,
|
|
761
665
|
});
|
|
762
666
|
}
|
|
763
|
-
if ("jupiterLend" in this.
|
|
667
|
+
if ("jupiterLend" in this.interfaceType) {
|
|
764
668
|
// If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
|
|
765
669
|
if (this.config.skipWrap) {
|
|
766
670
|
return accounts;
|
|
@@ -855,7 +759,7 @@ class GenericSySdk {
|
|
|
855
759
|
});
|
|
856
760
|
}
|
|
857
761
|
}
|
|
858
|
-
if ("kaminoVault" in this.
|
|
762
|
+
if ("kaminoVault" in this.interfaceType) {
|
|
859
763
|
// If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
|
|
860
764
|
if (this.config.skipWrap) {
|
|
861
765
|
return accounts;
|
|
@@ -954,9 +858,23 @@ class GenericSySdk {
|
|
|
954
858
|
.remainingAccounts(this.getAccountsWithSigner(redeemer, "redeem"))
|
|
955
859
|
.instruction();
|
|
956
860
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
if (
|
|
861
|
+
getFragmetricReceiptTokenAccountSetupInstruction(signer) {
|
|
862
|
+
const isFragmetric = "fragmetric" in this.interfaceType || "fragmetricSupportedAsset" in this.interfaceType;
|
|
863
|
+
if (!signer || !isFragmetric || this.config.skipWrap) {
|
|
864
|
+
return null;
|
|
865
|
+
}
|
|
866
|
+
const { receiptTokenMint } = this.fragmetricData;
|
|
867
|
+
const userReceiptTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(receiptTokenMint, signer, true, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
868
|
+
return (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(signer, userReceiptTokenAccount, signer, receiptTokenMint, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
869
|
+
}
|
|
870
|
+
/** Returns interface-specific setup instructions for the signer. */
|
|
871
|
+
preInstructions(signer) {
|
|
872
|
+
const ixs = [];
|
|
873
|
+
const receiptTokenAccountSetupIx = this.getFragmetricReceiptTokenAccountSetupInstruction(signer);
|
|
874
|
+
if (receiptTokenAccountSetupIx) {
|
|
875
|
+
ixs.push(receiptTokenAccountSetupIx);
|
|
876
|
+
}
|
|
877
|
+
if ("jupiterLend" in this.interfaceType) {
|
|
960
878
|
const jupiterLendData = this.state.additionalData?.jupiterLendData;
|
|
961
879
|
if (!jupiterLendData) {
|
|
962
880
|
throw new Error("Jupiter lend data not loaded");
|
|
@@ -994,7 +912,7 @@ class GenericSySdk {
|
|
|
994
912
|
});
|
|
995
913
|
ixs.push(refreshInstruction);
|
|
996
914
|
}
|
|
997
|
-
if ("splStakePool" in this.
|
|
915
|
+
if ("splStakePool" in this.interfaceType) {
|
|
998
916
|
const splStakePoolData = this.state.additionalData?.splStakePoolData;
|
|
999
917
|
if (!splStakePoolData) {
|
|
1000
918
|
throw new Error("SPL stake pool data not loaded");
|
|
@@ -1015,6 +933,21 @@ class GenericSySdk {
|
|
|
1015
933
|
}
|
|
1016
934
|
return ixs;
|
|
1017
935
|
}
|
|
936
|
+
/** Returns signer setup and refresh instructions, including those that require live interface state. */
|
|
937
|
+
async getPreInstructions(cnx, signer) {
|
|
938
|
+
const instructions = this.preInstructions(signer);
|
|
939
|
+
if (!("exponentTranching" in this.interfaceType))
|
|
940
|
+
return instructions;
|
|
941
|
+
const marketAddress = this.account.interfaceAccounts[0];
|
|
942
|
+
if (this.account.interfaceAccounts.length !== 1 || !marketAddress) {
|
|
943
|
+
throw new Error("Exponent Tranching interface requires exactly one market account");
|
|
944
|
+
}
|
|
945
|
+
const updateMarket = await (0, exponentTranching_1.buildExponentTranchingUpdateMarketInstruction)({
|
|
946
|
+
connection: cnx,
|
|
947
|
+
marketAddress,
|
|
948
|
+
});
|
|
949
|
+
return [updateMarket, ...instructions];
|
|
950
|
+
}
|
|
1018
951
|
getSyState() {
|
|
1019
952
|
return this.program.methods
|
|
1020
953
|
.getState()
|
|
@@ -1080,6 +1013,26 @@ class GenericSySdk {
|
|
|
1080
1013
|
})
|
|
1081
1014
|
.instruction();
|
|
1082
1015
|
}
|
|
1016
|
+
ixChangeInterfaceType({ signer, interfaceAccounts, interfaceType, }) {
|
|
1017
|
+
return this.program.methods
|
|
1018
|
+
.changeInterfaceType(interfaceAccounts, interfaceType)
|
|
1019
|
+
.accountsStrict({
|
|
1020
|
+
adminState: this.adminState,
|
|
1021
|
+
feePayer: signer,
|
|
1022
|
+
meta: this.selfAddress,
|
|
1023
|
+
mintSy: this.mintSy,
|
|
1024
|
+
signer,
|
|
1025
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
1026
|
+
tokenSyEscrow: this.tokenSyEscrow,
|
|
1027
|
+
yieldBearingMint: this.vrtMint,
|
|
1028
|
+
})
|
|
1029
|
+
.remainingAccounts(interfaceAccounts.map((pubkey) => ({
|
|
1030
|
+
pubkey,
|
|
1031
|
+
isSigner: false,
|
|
1032
|
+
isWritable: true,
|
|
1033
|
+
})))
|
|
1034
|
+
.instruction();
|
|
1035
|
+
}
|
|
1083
1036
|
}
|
|
1084
1037
|
exports.GenericSySdk = GenericSySdk;
|
|
1085
1038
|
function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex, syToken, initConfig, yieldBearingMintTokenProgram = spl_token_1.TOKEN_PROGRAM_ID, scopePriceChain, scopeMaximumAgeSeconds) {
|