@exponent-labs/generic-sy-sdk 0.9.20 → 0.9.22
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 -3
- package/build/index.js +164 -211
- 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/build/types.d.ts +0 -1
- package/package.json +9 -8
- package/src/index.ts +287 -165
- 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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BN, web3 } from "@coral-xyz/anchor";
|
|
3
2
|
import { GenericSyMetaAccount, GenericSyState, Hook, InterfaceTypeGeneric } from "@exponent-labs/exponent-types";
|
|
4
3
|
import { GenericSyPda } from "@exponent-labs/generic-sy-pda";
|
|
@@ -22,8 +21,11 @@ export declare enum InterfaceType {
|
|
|
22
21
|
Chainlink = 15,
|
|
23
22
|
ChainlinkDataStream = 16,
|
|
24
23
|
Scope = 17,
|
|
25
|
-
SolsticeGlamVault = 18
|
|
24
|
+
SolsticeGlamVault = 18,
|
|
25
|
+
ExponentTranching = 19,
|
|
26
|
+
GlowVault = 20
|
|
26
27
|
}
|
|
28
|
+
export declare function getInterfaceTypeIndex(interfaceType: InterfaceTypeGeneric): InterfaceType;
|
|
27
29
|
export declare function getInterfaceTypeObj(interfaceType: number, scopePriceChain?: number[], scopeMaximumAgeSeconds?: number): InterfaceTypeGeneric;
|
|
28
30
|
export declare function getInterfaceTypeFromString(interfaceType: string): InterfaceTypeGeneric;
|
|
29
31
|
interface GenericSyConfig {
|
|
@@ -55,6 +57,8 @@ export declare class GenericSySdk {
|
|
|
55
57
|
/** Reload the state of the account */
|
|
56
58
|
reload(cnx: web3.Connection): Promise<void>;
|
|
57
59
|
get account(): GenericSyMetaAccount;
|
|
60
|
+
get interfaceType(): InterfaceTypeGeneric;
|
|
61
|
+
get initInterfaceType(): InterfaceTypeGeneric;
|
|
58
62
|
get mintSy(): web3.PublicKey;
|
|
59
63
|
get vrtMint(): web3.PublicKey;
|
|
60
64
|
get maxSySupply(): BN;
|
|
@@ -110,7 +114,11 @@ export declare class GenericSySdk {
|
|
|
110
114
|
baseDst?: web3.PublicKey;
|
|
111
115
|
sySrc?: web3.PublicKey;
|
|
112
116
|
}): Promise<web3.TransactionInstruction>;
|
|
113
|
-
|
|
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[]>;
|
|
114
122
|
getSyState(): Promise<web3.TransactionInstruction>;
|
|
115
123
|
ixAddEmission({ signer, emissionMint, emissionTokenAccount, }: {
|
|
116
124
|
signer: web3.PublicKey;
|
|
@@ -127,6 +135,11 @@ export declare class GenericSySdk {
|
|
|
127
135
|
ixModifyOreInterfaceAccount({ signer }: {
|
|
128
136
|
signer: web3.PublicKey;
|
|
129
137
|
}): Promise<web3.TransactionInstruction>;
|
|
138
|
+
ixChangeInterfaceType({ signer, interfaceAccounts, interfaceType, }: {
|
|
139
|
+
signer: web3.PublicKey;
|
|
140
|
+
interfaceAccounts: web3.PublicKey[];
|
|
141
|
+
interfaceType: InterfaceTypeGeneric;
|
|
142
|
+
}): Promise<web3.TransactionInstruction>;
|
|
130
143
|
}
|
|
131
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>;
|
|
132
145
|
export {};
|
package/build/index.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GenericSySdk = exports.InterfaceType = void 0;
|
|
4
|
+
exports.getInterfaceTypeIndex = getInterfaceTypeIndex;
|
|
5
|
+
exports.getInterfaceTypeObj = getInterfaceTypeObj;
|
|
6
|
+
exports.getInterfaceTypeFromString = getInterfaceTypeFromString;
|
|
7
|
+
exports.initSy = initSy;
|
|
4
8
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
5
9
|
const spl_stake_pool_1 = require("@solana/spl-stake-pool");
|
|
6
10
|
const spl_token_1 = require("@solana/spl-token");
|
|
7
11
|
const exponent_admin_pda_1 = require("@exponent-labs/exponent-admin-pda");
|
|
8
12
|
const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
|
|
13
|
+
const exponent_types_1 = require("@exponent-labs/exponent-types");
|
|
9
14
|
const fragmetric_pda_1 = require("@exponent-labs/fragmetric-pda");
|
|
10
15
|
const generic_sy_idl_1 = require("@exponent-labs/generic-sy-idl");
|
|
11
16
|
const generic_sy_pda_1 = require("@exponent-labs/generic-sy-pda");
|
|
12
17
|
const precise_number_1 = require("@exponent-labs/precise-number");
|
|
18
|
+
const exponentTranching_1 = require("./interfaces/exponentTranching");
|
|
19
|
+
const glowVault_1 = require("./interfaces/glowVault");
|
|
13
20
|
const utils_1 = require("./utils");
|
|
14
21
|
/**
|
|
15
22
|
* Create a custom updateStakePoolBalance instruction using dynamic program ID
|
|
@@ -34,67 +41,7 @@ function createUpdateStakePoolBalanceInstruction({ stakePool, withdrawAuthority,
|
|
|
34
41
|
});
|
|
35
42
|
}
|
|
36
43
|
async function loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType) {
|
|
37
|
-
|
|
38
|
-
if ("pyth" in interfaceType) {
|
|
39
|
-
interfaceIndex = InterfaceType.Pyth;
|
|
40
|
-
}
|
|
41
|
-
else if ("splStakePool" in interfaceType) {
|
|
42
|
-
interfaceIndex = InterfaceType.SplStakePool;
|
|
43
|
-
}
|
|
44
|
-
else if ("one" in interfaceType) {
|
|
45
|
-
interfaceIndex = InterfaceType.One;
|
|
46
|
-
}
|
|
47
|
-
else if ("fragmetric" in interfaceType) {
|
|
48
|
-
interfaceIndex = InterfaceType.Fragmetric;
|
|
49
|
-
}
|
|
50
|
-
else if ("meteora" in interfaceType) {
|
|
51
|
-
interfaceIndex = InterfaceType.Meteora;
|
|
52
|
-
}
|
|
53
|
-
else if ("sanctum" in interfaceType) {
|
|
54
|
-
interfaceIndex = InterfaceType.Sanctum;
|
|
55
|
-
}
|
|
56
|
-
else if ("fragmetricSupportedAsset" in interfaceType) {
|
|
57
|
-
interfaceIndex = InterfaceType.FragmetricSupportedAsset;
|
|
58
|
-
}
|
|
59
|
-
else if ("jupiterPerps" in interfaceType) {
|
|
60
|
-
interfaceIndex = InterfaceType.JupiterPerps;
|
|
61
|
-
}
|
|
62
|
-
else if ("adrena" in interfaceType) {
|
|
63
|
-
interfaceIndex = InterfaceType.Adrena;
|
|
64
|
-
}
|
|
65
|
-
else if ("hyloLpToken" in interfaceType) {
|
|
66
|
-
interfaceIndex = InterfaceType.HyloLpToken;
|
|
67
|
-
}
|
|
68
|
-
else if ("jupiterLend" in interfaceType) {
|
|
69
|
-
interfaceIndex = InterfaceType.JupiterLend;
|
|
70
|
-
}
|
|
71
|
-
else if ("kaminoVault" in interfaceType) {
|
|
72
|
-
interfaceIndex = InterfaceType.KaminoVault;
|
|
73
|
-
}
|
|
74
|
-
else if ("solstice" in interfaceType) {
|
|
75
|
-
interfaceIndex = InterfaceType.Solstice;
|
|
76
|
-
}
|
|
77
|
-
else if ("reflect" in interfaceType) {
|
|
78
|
-
interfaceIndex = InterfaceType.Reflect;
|
|
79
|
-
}
|
|
80
|
-
else if ("ore" in interfaceType) {
|
|
81
|
-
interfaceIndex = InterfaceType.Ore;
|
|
82
|
-
}
|
|
83
|
-
else if ("chainlink" in interfaceType) {
|
|
84
|
-
interfaceIndex = InterfaceType.Chainlink;
|
|
85
|
-
}
|
|
86
|
-
else if ("chainlinkDataStream" in interfaceType) {
|
|
87
|
-
interfaceIndex = InterfaceType.ChainlinkDataStream;
|
|
88
|
-
}
|
|
89
|
-
else if ("scope" in interfaceType) {
|
|
90
|
-
interfaceIndex = InterfaceType.Scope;
|
|
91
|
-
}
|
|
92
|
-
else if ("solsticeGlamVault" in interfaceType) {
|
|
93
|
-
interfaceIndex = InterfaceType.SolsticeGlamVault;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
throw new Error("Unsupported interface type");
|
|
97
|
-
}
|
|
44
|
+
const interfaceIndex = getInterfaceTypeIndex(interfaceType);
|
|
98
45
|
const pda = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex);
|
|
99
46
|
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
|
|
100
47
|
const syMetaAddress = pda.syMeta({ yieldBearingMint });
|
|
@@ -124,7 +71,54 @@ var InterfaceType;
|
|
|
124
71
|
InterfaceType[InterfaceType["ChainlinkDataStream"] = 16] = "ChainlinkDataStream";
|
|
125
72
|
InterfaceType[InterfaceType["Scope"] = 17] = "Scope";
|
|
126
73
|
InterfaceType[InterfaceType["SolsticeGlamVault"] = 18] = "SolsticeGlamVault";
|
|
74
|
+
InterfaceType[InterfaceType["ExponentTranching"] = 19] = "ExponentTranching";
|
|
75
|
+
InterfaceType[InterfaceType["GlowVault"] = 20] = "GlowVault";
|
|
127
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
|
+
}
|
|
128
122
|
function getInterfaceTypeObj(interfaceType, scopePriceChain = [0, 512, 512, 512], scopeMaximumAgeSeconds = 3600) {
|
|
129
123
|
switch (interfaceType) {
|
|
130
124
|
case InterfaceType.Pyth:
|
|
@@ -181,11 +175,14 @@ function getInterfaceTypeObj(interfaceType, scopePriceChain = [0, 512, 512, 512]
|
|
|
181
175
|
return { scope: { priceChain: scopePriceChain, maximumAgeSeconds: new anchor_1.BN(scopeMaximumAgeSeconds) } };
|
|
182
176
|
case InterfaceType.SolsticeGlamVault:
|
|
183
177
|
return { solsticeGlamVault: { padding: [] } };
|
|
178
|
+
case InterfaceType.ExponentTranching:
|
|
179
|
+
return { exponentTranching: {} };
|
|
180
|
+
case InterfaceType.GlowVault:
|
|
181
|
+
return { glowVault: { padding: [] } };
|
|
184
182
|
default:
|
|
185
183
|
throw new Error(`Unsupported interface type: ${interfaceType}`);
|
|
186
184
|
}
|
|
187
185
|
}
|
|
188
|
-
exports.getInterfaceTypeObj = getInterfaceTypeObj;
|
|
189
186
|
function getInterfaceTypeFromString(interfaceType) {
|
|
190
187
|
switch (interfaceType) {
|
|
191
188
|
case "pyth":
|
|
@@ -240,11 +237,14 @@ function getInterfaceTypeFromString(interfaceType) {
|
|
|
240
237
|
return { scope: { priceChain: [0, 512, 512, 512], maximumAgeSeconds: new anchor_1.BN(3600) } };
|
|
241
238
|
case "solstice-glam-vault":
|
|
242
239
|
return { solsticeGlamVault: { padding: [] } };
|
|
240
|
+
case "exponent-tranching":
|
|
241
|
+
return { exponentTranching: {} };
|
|
242
|
+
case "glow-vault":
|
|
243
|
+
return { glowVault: { padding: [] } };
|
|
243
244
|
default:
|
|
244
245
|
throw new Error(`Unsupported interface type: ${interfaceType}`);
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
|
-
exports.getInterfaceTypeFromString = getInterfaceTypeFromString;
|
|
248
248
|
class GenericSySdk {
|
|
249
249
|
state;
|
|
250
250
|
/** Private program for building instructions */
|
|
@@ -256,68 +256,7 @@ class GenericSySdk {
|
|
|
256
256
|
this.config = config;
|
|
257
257
|
// create a fake AnchorProvider -- which is unused
|
|
258
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())));
|
|
259
|
-
|
|
260
|
-
let interfaceIndex;
|
|
261
|
-
if ("pyth" in this.state.account.interfaceType) {
|
|
262
|
-
interfaceIndex = InterfaceType.Pyth;
|
|
263
|
-
}
|
|
264
|
-
else if ("splStakePool" in this.state.account.interfaceType) {
|
|
265
|
-
interfaceIndex = InterfaceType.SplStakePool;
|
|
266
|
-
}
|
|
267
|
-
else if ("one" in this.state.account.interfaceType) {
|
|
268
|
-
interfaceIndex = InterfaceType.One;
|
|
269
|
-
}
|
|
270
|
-
else if ("fragmetricSupportedAsset" in this.state.account.interfaceType) {
|
|
271
|
-
interfaceIndex = InterfaceType.FragmetricSupportedAsset;
|
|
272
|
-
}
|
|
273
|
-
else if ("fragmetric" in this.state.account.interfaceType) {
|
|
274
|
-
interfaceIndex = InterfaceType.Fragmetric;
|
|
275
|
-
}
|
|
276
|
-
else if ("meteora" in this.state.account.interfaceType) {
|
|
277
|
-
interfaceIndex = InterfaceType.Meteora;
|
|
278
|
-
}
|
|
279
|
-
else if ("sanctum" in this.state.account.interfaceType) {
|
|
280
|
-
interfaceIndex = InterfaceType.Sanctum;
|
|
281
|
-
}
|
|
282
|
-
else if ("jupiterPerps" in this.state.account.interfaceType) {
|
|
283
|
-
interfaceIndex = InterfaceType.JupiterPerps;
|
|
284
|
-
}
|
|
285
|
-
else if ("adrena" in this.state.account.interfaceType) {
|
|
286
|
-
interfaceIndex = InterfaceType.Adrena;
|
|
287
|
-
}
|
|
288
|
-
else if ("hyloLpToken" in this.state.account.interfaceType) {
|
|
289
|
-
interfaceIndex = InterfaceType.HyloLpToken;
|
|
290
|
-
}
|
|
291
|
-
else if ("jupiterLend" in this.state.account.interfaceType) {
|
|
292
|
-
interfaceIndex = InterfaceType.JupiterLend;
|
|
293
|
-
}
|
|
294
|
-
else if ("kaminoVault" in this.state.account.interfaceType) {
|
|
295
|
-
interfaceIndex = InterfaceType.KaminoVault;
|
|
296
|
-
}
|
|
297
|
-
else if ("solstice" in this.state.account.interfaceType) {
|
|
298
|
-
interfaceIndex = InterfaceType.Solstice;
|
|
299
|
-
}
|
|
300
|
-
else if ("reflect" in this.state.account.interfaceType) {
|
|
301
|
-
interfaceIndex = InterfaceType.Reflect;
|
|
302
|
-
}
|
|
303
|
-
else if ("ore" in this.state.account.interfaceType) {
|
|
304
|
-
interfaceIndex = InterfaceType.Ore;
|
|
305
|
-
}
|
|
306
|
-
else if ("chainlink" in this.state.account.interfaceType) {
|
|
307
|
-
interfaceIndex = InterfaceType.Chainlink;
|
|
308
|
-
}
|
|
309
|
-
else if ("chainlinkDataStream" in this.state.account.interfaceType) {
|
|
310
|
-
interfaceIndex = InterfaceType.ChainlinkDataStream;
|
|
311
|
-
}
|
|
312
|
-
else if ("scope" in this.state.account.interfaceType) {
|
|
313
|
-
interfaceIndex = InterfaceType.Scope;
|
|
314
|
-
}
|
|
315
|
-
else if ("solsticeGlamVault" in this.state.account.interfaceType) {
|
|
316
|
-
interfaceIndex = InterfaceType.SolsticeGlamVault;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
throw new Error("Unsupported interface type");
|
|
320
|
-
}
|
|
259
|
+
const interfaceIndex = getInterfaceTypeIndex((0, exponent_types_1.getGenericSyMetaInitInterfaceType)(this.state.account));
|
|
321
260
|
this.syPda = new generic_sy_pda_1.GenericSyPda(programId, interfaceIndex);
|
|
322
261
|
}
|
|
323
262
|
static async calculateSyRate(account, interfaceType, cnx) {
|
|
@@ -373,7 +312,7 @@ class GenericSySdk {
|
|
|
373
312
|
}
|
|
374
313
|
else if ("meteora" in interfaceType) {
|
|
375
314
|
const currentTs = Math.floor(Date.now() / 1000);
|
|
376
|
-
|
|
315
|
+
let accounts = {
|
|
377
316
|
pool: account.interfaceAccounts[0],
|
|
378
317
|
vaultA: account.interfaceAccounts[4],
|
|
379
318
|
vaultB: account.interfaceAccounts[5],
|
|
@@ -391,10 +330,9 @@ class GenericSySdk {
|
|
|
391
330
|
return { syRate: exchangeRate };
|
|
392
331
|
}
|
|
393
332
|
else if ("adrena" in interfaceType) {
|
|
394
|
-
|
|
395
|
-
const previousTotalFees = account.interfaceType.adrena.previousTotalFees;
|
|
333
|
+
const previousTotalFees = interfaceType.adrena.previousTotalFees;
|
|
396
334
|
const currentIndex = account.index;
|
|
397
|
-
|
|
335
|
+
const accounts = {
|
|
398
336
|
pool: account.interfaceAccounts[0],
|
|
399
337
|
custody1: account.interfaceAccounts[1],
|
|
400
338
|
custody2: account.interfaceAccounts[2],
|
|
@@ -405,8 +343,7 @@ class GenericSySdk {
|
|
|
405
343
|
return { syRate: syRate.index };
|
|
406
344
|
}
|
|
407
345
|
else if ("jupiterPerps" in interfaceType) {
|
|
408
|
-
|
|
409
|
-
const j = account.interfaceType.jupiterPerps;
|
|
346
|
+
const j = interfaceType.jupiterPerps;
|
|
410
347
|
const { index } = await (0, exponent_fetcher_1.fetchJupiterPerpsIndex)({
|
|
411
348
|
connection: cnx,
|
|
412
349
|
pool: account.interfaceAccounts[0],
|
|
@@ -531,6 +468,30 @@ class GenericSySdk {
|
|
|
531
468
|
});
|
|
532
469
|
return { syRate };
|
|
533
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
|
+
}
|
|
534
495
|
else {
|
|
535
496
|
return { syRate: 1 };
|
|
536
497
|
}
|
|
@@ -539,71 +500,11 @@ class GenericSySdk {
|
|
|
539
500
|
static async load({ cnx, yieldBearingMint, interfaceType, genericStandardProgramId, config = {}, }) {
|
|
540
501
|
const account = await loadAccountState(cnx, yieldBearingMint, genericStandardProgramId, interfaceType);
|
|
541
502
|
const tokenProgramBase = (await cnx.getAccountInfo(yieldBearingMint))?.owner;
|
|
542
|
-
|
|
543
|
-
if ("pyth" in interfaceType) {
|
|
544
|
-
interfaceIndex = InterfaceType.Pyth;
|
|
545
|
-
}
|
|
546
|
-
else if ("splStakePool" in interfaceType) {
|
|
547
|
-
interfaceIndex = InterfaceType.SplStakePool;
|
|
548
|
-
}
|
|
549
|
-
else if ("one" in interfaceType) {
|
|
550
|
-
interfaceIndex = InterfaceType.One;
|
|
551
|
-
}
|
|
552
|
-
else if ("fragmetricSupportedAsset" in interfaceType) {
|
|
553
|
-
interfaceIndex = InterfaceType.FragmetricSupportedAsset;
|
|
554
|
-
}
|
|
555
|
-
else if ("fragmetric" in interfaceType) {
|
|
556
|
-
interfaceIndex = InterfaceType.Fragmetric;
|
|
557
|
-
}
|
|
558
|
-
else if ("meteora" in interfaceType) {
|
|
559
|
-
interfaceIndex = InterfaceType.Meteora;
|
|
560
|
-
}
|
|
561
|
-
else if ("sanctum" in interfaceType) {
|
|
562
|
-
interfaceIndex = InterfaceType.Sanctum;
|
|
563
|
-
}
|
|
564
|
-
else if ("jupiterPerps" in interfaceType) {
|
|
565
|
-
interfaceIndex = InterfaceType.JupiterPerps;
|
|
566
|
-
}
|
|
567
|
-
else if ("adrena" in interfaceType) {
|
|
568
|
-
interfaceIndex = InterfaceType.Adrena;
|
|
569
|
-
}
|
|
570
|
-
else if ("hyloLpToken" in interfaceType) {
|
|
571
|
-
interfaceIndex = InterfaceType.HyloLpToken;
|
|
572
|
-
}
|
|
573
|
-
else if ("jupiterLend" in interfaceType) {
|
|
574
|
-
interfaceIndex = InterfaceType.JupiterLend;
|
|
575
|
-
}
|
|
576
|
-
else if ("kaminoVault" in interfaceType) {
|
|
577
|
-
interfaceIndex = InterfaceType.KaminoVault;
|
|
578
|
-
}
|
|
579
|
-
else if ("solstice" in interfaceType) {
|
|
580
|
-
interfaceIndex = InterfaceType.Solstice;
|
|
581
|
-
}
|
|
582
|
-
else if ("reflect" in interfaceType) {
|
|
583
|
-
interfaceIndex = InterfaceType.Reflect;
|
|
584
|
-
}
|
|
585
|
-
else if ("ore" in interfaceType) {
|
|
586
|
-
interfaceIndex = InterfaceType.Ore;
|
|
587
|
-
}
|
|
588
|
-
else if ("chainlink" in interfaceType) {
|
|
589
|
-
interfaceIndex = InterfaceType.Chainlink;
|
|
590
|
-
}
|
|
591
|
-
else if ("chainlinkDataStream" in interfaceType) {
|
|
592
|
-
interfaceIndex = InterfaceType.ChainlinkDataStream;
|
|
593
|
-
}
|
|
594
|
-
else if ("scope" in interfaceType) {
|
|
595
|
-
interfaceIndex = InterfaceType.Scope;
|
|
596
|
-
}
|
|
597
|
-
else if ("solsticeGlamVault" in interfaceType) {
|
|
598
|
-
interfaceIndex = InterfaceType.SolsticeGlamVault;
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
throw new Error("Unsupported interface type");
|
|
602
|
-
}
|
|
503
|
+
const interfaceIndex = getInterfaceTypeIndex((0, exponent_types_1.getGenericSyMetaInitInterfaceType)(account));
|
|
603
504
|
const selfAddress = new generic_sy_pda_1.GenericSyPda(genericStandardProgramId, interfaceIndex).syMeta({
|
|
604
505
|
yieldBearingMint,
|
|
605
506
|
});
|
|
606
|
-
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account,
|
|
507
|
+
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, (0, exponent_types_1.getGenericSyMetaInterfaceType)(account), cnx);
|
|
607
508
|
const state = {
|
|
608
509
|
selfAddress,
|
|
609
510
|
account,
|
|
@@ -618,7 +519,7 @@ class GenericSySdk {
|
|
|
618
519
|
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId });
|
|
619
520
|
const account = await fetcher.fetchGenericSyMeta(syMetaAddress);
|
|
620
521
|
const tokenProgramBase = (await cnx.getAccountInfo(account.yieldBearingMint))?.owner;
|
|
621
|
-
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, account
|
|
522
|
+
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, (0, exponent_types_1.getGenericSyMetaInterfaceType)(account), cnx);
|
|
622
523
|
const state = {
|
|
623
524
|
selfAddress: syMetaAddress,
|
|
624
525
|
account,
|
|
@@ -630,15 +531,22 @@ class GenericSySdk {
|
|
|
630
531
|
}
|
|
631
532
|
/** Reload the state of the account */
|
|
632
533
|
async reload(cnx) {
|
|
633
|
-
const
|
|
534
|
+
const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection: cnx, genericStandardProgramId: this.program.programId });
|
|
535
|
+
const account = await fetcher.fetchGenericSyMeta(this.state.selfAddress);
|
|
634
536
|
this.state.account = account;
|
|
635
|
-
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, account
|
|
537
|
+
const { syRate, additionalData } = await GenericSySdk.calculateSyRate(account, (0, exponent_types_1.getGenericSyMetaInterfaceType)(account), cnx);
|
|
636
538
|
this.state.syRate = syRate;
|
|
637
539
|
this.state.additionalData = additionalData;
|
|
638
540
|
}
|
|
639
541
|
get account() {
|
|
640
542
|
return this.state.account;
|
|
641
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
|
+
}
|
|
642
550
|
get mintSy() {
|
|
643
551
|
return this.account.mintSy;
|
|
644
552
|
}
|
|
@@ -676,8 +584,7 @@ class GenericSySdk {
|
|
|
676
584
|
return new exponent_admin_pda_1.ExponentAdminPda(exponent_admin_pda_1.EXPONENT_ADMIN_PROGRAM_ID).exponentAdmin();
|
|
677
585
|
}
|
|
678
586
|
get fragmetricData() {
|
|
679
|
-
if (!("fragmetric" in this.
|
|
680
|
-
!("fragmetricSupportedAsset" in this.state.account.interfaceType)) {
|
|
587
|
+
if (!("fragmetric" in this.interfaceType) && !("fragmetricSupportedAsset" in this.interfaceType)) {
|
|
681
588
|
throw new Error("Not a fragmetric interface");
|
|
682
589
|
}
|
|
683
590
|
if (!this.state.additionalData?.fragmetricData) {
|
|
@@ -686,7 +593,7 @@ class GenericSySdk {
|
|
|
686
593
|
return this.state.additionalData.fragmetricData;
|
|
687
594
|
}
|
|
688
595
|
get jupiterLendData() {
|
|
689
|
-
if (!("jupiterLend" in this.
|
|
596
|
+
if (!("jupiterLend" in this.interfaceType)) {
|
|
690
597
|
throw new Error("Not a Jupiter Lend interface");
|
|
691
598
|
}
|
|
692
599
|
if (!this.state.additionalData?.jupiterLendData) {
|
|
@@ -695,7 +602,7 @@ class GenericSySdk {
|
|
|
695
602
|
return this.state.additionalData.jupiterLendData;
|
|
696
603
|
}
|
|
697
604
|
get kaminoVaultData() {
|
|
698
|
-
if (!("kaminoVault" in this.
|
|
605
|
+
if (!("kaminoVault" in this.interfaceType)) {
|
|
699
606
|
throw new Error("Not a Kamino Vault interface");
|
|
700
607
|
}
|
|
701
608
|
if (!this.state.additionalData?.kaminoVaultData) {
|
|
@@ -721,9 +628,7 @@ class GenericSySdk {
|
|
|
721
628
|
isWritable: true,
|
|
722
629
|
}))
|
|
723
630
|
.concat(this.emissions.map((e) => ({ pubkey: e.escrowAccount, isSigner: false, isWritable: false })));
|
|
724
|
-
if (("fragmetric" in this.
|
|
725
|
-
"fragmetricSupportedAsset" in this.state.account.interfaceType) &&
|
|
726
|
-
signer) {
|
|
631
|
+
if (("fragmetric" in this.interfaceType || "fragmetricSupportedAsset" in this.interfaceType) && signer) {
|
|
727
632
|
// If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
|
|
728
633
|
if (this.config.skipWrap) {
|
|
729
634
|
return accounts;
|
|
@@ -759,7 +664,7 @@ class GenericSySdk {
|
|
|
759
664
|
isWritable: false,
|
|
760
665
|
});
|
|
761
666
|
}
|
|
762
|
-
if ("jupiterLend" in this.
|
|
667
|
+
if ("jupiterLend" in this.interfaceType) {
|
|
763
668
|
// If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
|
|
764
669
|
if (this.config.skipWrap) {
|
|
765
670
|
return accounts;
|
|
@@ -854,7 +759,7 @@ class GenericSySdk {
|
|
|
854
759
|
});
|
|
855
760
|
}
|
|
856
761
|
}
|
|
857
|
-
if ("kaminoVault" in this.
|
|
762
|
+
if ("kaminoVault" in this.interfaceType) {
|
|
858
763
|
// If skipWrap is true, return minimal accounts (skip additional interface-specific accounts)
|
|
859
764
|
if (this.config.skipWrap) {
|
|
860
765
|
return accounts;
|
|
@@ -953,9 +858,23 @@ class GenericSySdk {
|
|
|
953
858
|
.remainingAccounts(this.getAccountsWithSigner(redeemer, "redeem"))
|
|
954
859
|
.instruction();
|
|
955
860
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
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) {
|
|
959
878
|
const jupiterLendData = this.state.additionalData?.jupiterLendData;
|
|
960
879
|
if (!jupiterLendData) {
|
|
961
880
|
throw new Error("Jupiter lend data not loaded");
|
|
@@ -993,7 +912,7 @@ class GenericSySdk {
|
|
|
993
912
|
});
|
|
994
913
|
ixs.push(refreshInstruction);
|
|
995
914
|
}
|
|
996
|
-
if ("splStakePool" in this.
|
|
915
|
+
if ("splStakePool" in this.interfaceType) {
|
|
997
916
|
const splStakePoolData = this.state.additionalData?.splStakePoolData;
|
|
998
917
|
if (!splStakePoolData) {
|
|
999
918
|
throw new Error("SPL stake pool data not loaded");
|
|
@@ -1014,6 +933,21 @@ class GenericSySdk {
|
|
|
1014
933
|
}
|
|
1015
934
|
return ixs;
|
|
1016
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
|
+
}
|
|
1017
951
|
getSyState() {
|
|
1018
952
|
return this.program.methods
|
|
1019
953
|
.getState()
|
|
@@ -1079,6 +1013,26 @@ class GenericSySdk {
|
|
|
1079
1013
|
})
|
|
1080
1014
|
.instruction();
|
|
1081
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
|
+
}
|
|
1082
1036
|
}
|
|
1083
1037
|
exports.GenericSySdk = GenericSySdk;
|
|
1084
1038
|
function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex, syToken, initConfig, yieldBearingMintTokenProgram = spl_token_1.TOKEN_PROGRAM_ID, scopePriceChain, scopeMaximumAgeSeconds) {
|
|
@@ -1112,5 +1066,4 @@ function initSy(signer, interfaceAccounts, yieldBearingMint, interfaceIndex, syT
|
|
|
1112
1066
|
.instruction();
|
|
1113
1067
|
return ix;
|
|
1114
1068
|
}
|
|
1115
|
-
exports.initSy = initSy;
|
|
1116
1069
|
//# sourceMappingURL=index.js.map
|