@exponent-labs/exponent-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.
Files changed (68) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/addressLookupTableUtil.d.ts +12 -0
  3. package/build/addressLookupTableUtil.js +32 -0
  4. package/build/addressLookupTableUtil.js.map +1 -0
  5. package/build/environment.d.ts +10 -0
  6. package/build/environment.js +13 -0
  7. package/build/environment.js.map +1 -0
  8. package/build/events.d.ts +339 -0
  9. package/build/events.js +231 -0
  10. package/build/events.js.map +1 -0
  11. package/build/flavors.d.ts +24 -0
  12. package/build/flavors.js +713 -0
  13. package/build/flavors.js.map +1 -0
  14. package/build/index.d.ts +11 -0
  15. package/build/index.js +45 -0
  16. package/build/index.js.map +1 -0
  17. package/build/lpPosition.d.ts +35 -0
  18. package/build/lpPosition.js +103 -0
  19. package/build/lpPosition.js.map +1 -0
  20. package/build/market.d.ts +567 -0
  21. package/build/market.js +1445 -0
  22. package/build/market.js.map +1 -0
  23. package/build/syPosition.d.ts +6 -0
  24. package/build/syPosition.js +115 -0
  25. package/build/syPosition.js.map +1 -0
  26. package/build/tokenUtil.d.ts +3 -0
  27. package/build/tokenUtil.js +23 -0
  28. package/build/tokenUtil.js.map +1 -0
  29. package/build/utils/altUtil.d.ts +8 -0
  30. package/build/utils/altUtil.js +35 -0
  31. package/build/utils/altUtil.js.map +1 -0
  32. package/build/utils/binSolver.d.ts +1 -0
  33. package/build/utils/binSolver.js +45 -0
  34. package/build/utils/binSolver.js.map +1 -0
  35. package/build/utils/binSolver.test.d.ts +1 -0
  36. package/build/utils/binSolver.test.js +15 -0
  37. package/build/utils/binSolver.test.js.map +1 -0
  38. package/build/utils/index.d.ts +6 -0
  39. package/build/utils/index.js +31 -0
  40. package/build/utils/index.js.map +1 -0
  41. package/build/utils/ix.d.ts +6 -0
  42. package/build/utils/ix.js +3 -0
  43. package/build/utils/ix.js.map +1 -0
  44. package/build/vault.d.ts +289 -0
  45. package/build/vault.js +615 -0
  46. package/build/vault.js.map +1 -0
  47. package/build/ytPosition.d.ts +86 -0
  48. package/build/ytPosition.js +231 -0
  49. package/build/ytPosition.js.map +1 -0
  50. package/jest.config.js +5 -0
  51. package/package.json +42 -0
  52. package/src/addressLookupTableUtil.ts +34 -0
  53. package/src/environment.ts +19 -0
  54. package/src/events.ts +595 -0
  55. package/src/flavors.ts +773 -0
  56. package/src/index.ts +11 -0
  57. package/src/lpPosition.ts +129 -0
  58. package/src/market.ts +2338 -0
  59. package/src/syPosition.ts +151 -0
  60. package/src/tokenUtil.ts +20 -0
  61. package/src/utils/altUtil.ts +47 -0
  62. package/src/utils/binSolver.test.ts +15 -0
  63. package/src/utils/binSolver.ts +44 -0
  64. package/src/utils/index.ts +32 -0
  65. package/src/utils/ix.ts +7 -0
  66. package/src/vault.ts +999 -0
  67. package/src/ytPosition.ts +313 -0
  68. package/tsconfig.json +38 -0
@@ -0,0 +1,86 @@
1
+ import { Program, web3 } from "@coral-xyz/anchor";
2
+ import { ExponentCore } from "@exponent-labs/exponent-idl";
3
+ import { Environment } from "./environment";
4
+ import { YtPosition as YtPositionState } from "@exponent-labs/exponent-fetcher";
5
+ import { Vault } from "./vault";
6
+ import { InstructionAccounts } from "./utils";
7
+ import { VaultJson } from "@exponent-labs/exponent-types";
8
+ export declare class YtPosition {
9
+ env: Environment;
10
+ connection: web3.Connection;
11
+ selfAddress: web3.PublicKey;
12
+ state: YtPositionState;
13
+ vault: Vault;
14
+ coreProgram: Program<ExponentCore>;
15
+ constructor(env: Environment, connection: web3.Connection, selfAddress: web3.PublicKey, state: YtPositionState, vault: Vault);
16
+ /** Loads the YT position by address, and loads Vault, too
17
+ * DEPRECATED - use loadByOwner instead - loading the vault is expensive
18
+ */
19
+ static load(env: Environment, connection: web3.Connection, address: web3.PublicKey): Promise<YtPosition>;
20
+ /** Loads the YT position by owner, but require a loaded Vault */
21
+ static loadByOwner(env: Environment, connection: web3.Connection, owner: web3.PublicKey, vault: Vault): Promise<YtPosition>;
22
+ reload(conn?: web3.Connection): Promise<YtPosition>;
23
+ toJson(): YtPositionJson;
24
+ get ytBalance(): bigint;
25
+ get owner(): web3.PublicKey;
26
+ get stagedInterest(): bigint;
27
+ /**
28
+ * Returns the claimable interest in base amount
29
+ * @param currentIndex - The current SY exchange rate for the vault's SY token
30
+ * @returns The claimable interest in raw base token units
31
+ */
32
+ getClaimableInterest(currentIndex: number): number;
33
+ getClaimableEmissions(): {
34
+ mint: web3.PublicKey;
35
+ amount: number;
36
+ }[];
37
+ /** Instruction for depositing YT into the vault */
38
+ ixDepositYt({ amount, ytSrc }: {
39
+ amount: bigint;
40
+ ytSrc?: web3.PublicKey;
41
+ }): Promise<web3.TransactionInstruction>;
42
+ /** Instruction for withdrawing YT from the vault */
43
+ ixWithdrawYt({ amount, ytDst }: {
44
+ amount: bigint;
45
+ ytDst?: web3.PublicKey;
46
+ }): Promise<web3.TransactionInstruction>;
47
+ ixStageYield({ payer }: {
48
+ payer: web3.PublicKey;
49
+ }): Promise<web3.TransactionInstruction>;
50
+ ixCollectInterest({ signer, syDst, amount }: {
51
+ signer: web3.PublicKey;
52
+ syDst?: web3.PublicKey;
53
+ amount?: bigint;
54
+ }): Promise<web3.TransactionInstruction>;
55
+ ixCollectEmission({ owner, emissionIndex, emissionDst, amount, }: {
56
+ owner: web3.PublicKey;
57
+ emissionIndex: number;
58
+ emissionDst?: web3.PublicKey;
59
+ amount?: bigint;
60
+ }): Promise<web3.TransactionInstruction>;
61
+ depositYtAccounts({ ytSrc }: {
62
+ ytSrc?: web3.PublicKey;
63
+ }): InstructionAccounts<DepositYtAccounts>;
64
+ withdrawYtAccounts({ ytDst }: {
65
+ ytDst?: web3.PublicKey;
66
+ }): InstructionAccounts<WithdrawYtAccounts>;
67
+ }
68
+ export type YtPositionJson = {
69
+ owner: string;
70
+ ytBalance: string;
71
+ interest: YieldTokenTrackerJson;
72
+ claimableInterest: number;
73
+ emissions: YieldTokenTrackerJson[];
74
+ vault: VaultJson;
75
+ };
76
+ export type YieldTokenTrackerJson = {
77
+ lastSeenIndex: number;
78
+ staged: string;
79
+ };
80
+ type DepositYtAccounts = {
81
+ [K in "depositor" | "vault" | "userYieldPosition" | "ytSrc" | "escrowYt" | "tokenProgram" | "syProgram" | "addressLookupTable" | "yieldPosition" | "systemProgram" | "eventAuthority" | "program"]: web3.PublicKey;
82
+ };
83
+ type WithdrawYtAccounts = {
84
+ [K in "owner" | "vault" | "userYieldPosition" | "ytDst" | "escrowYt" | "tokenProgram" | "authority" | "syProgram" | "addressLookupTable" | "yieldPosition" | "systemProgram" | "eventAuthority" | "program"]: web3.PublicKey;
85
+ };
86
+ export {};
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YtPosition = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const exponent_idl_1 = require("@exponent-labs/exponent-idl");
6
+ const exponent_fetcher_1 = require("@exponent-labs/exponent-fetcher");
7
+ const vault_1 = require("./vault");
8
+ const spl_token_1 = require("@solana/spl-token");
9
+ const exponent_pda_1 = require("@exponent-labs/exponent-pda");
10
+ const market_1 = require("./market");
11
+ const precise_number_1 = require("@exponent-labs/precise-number");
12
+ class YtPosition {
13
+ env;
14
+ connection;
15
+ selfAddress;
16
+ state;
17
+ vault;
18
+ coreProgram;
19
+ constructor(env, connection, selfAddress, state, vault) {
20
+ this.env = env;
21
+ this.connection = connection;
22
+ this.selfAddress = selfAddress;
23
+ this.state = state;
24
+ this.vault = vault;
25
+ const mockWallet = new market_1.MyWallet(anchor_1.web3.Keypair.generate());
26
+ this.coreProgram = new anchor_1.Program(exponent_idl_1.IDL, new anchor_1.AnchorProvider(connection, mockWallet));
27
+ }
28
+ /** Loads the YT position by address, and loads Vault, too
29
+ * DEPRECATED - use loadByOwner instead - loading the vault is expensive
30
+ */
31
+ static async load(env, connection, address) {
32
+ const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection });
33
+ const x = await fetcher.fetchYtPosition(address);
34
+ const vault = await vault_1.Vault.load(env, connection, x.vault);
35
+ return new YtPosition(env, connection, address, x, vault);
36
+ }
37
+ /** Loads the YT position by owner, but require a loaded Vault */
38
+ static async loadByOwner(env, connection, owner, vault) {
39
+ const pda = new exponent_pda_1.ExponentPDA(env.coreProgramId);
40
+ const address = pda.yieldPosition({ vault: vault.selfAddress, owner });
41
+ const fetcher = new exponent_fetcher_1.ExponentFetcher({ connection });
42
+ const x = await fetcher.fetchYtPosition(address);
43
+ return new YtPosition(env, connection, address, x, vault);
44
+ }
45
+ async reload(conn = this.connection) {
46
+ const x = await YtPosition.load(this.env, conn, this.selfAddress);
47
+ this.state = x.state;
48
+ return x;
49
+ }
50
+ toJson() {
51
+ return ytPositionToJson(this);
52
+ }
53
+ get ytBalance() {
54
+ return this.state.ytBalance;
55
+ }
56
+ get owner() {
57
+ return this.state.owner;
58
+ }
59
+ get stagedInterest() {
60
+ return this.state.interest.staged;
61
+ }
62
+ /**
63
+ * Returns the claimable interest in base amount
64
+ * @param currentIndex - The current SY exchange rate for the vault's SY token
65
+ * @returns The claimable interest in raw base token units
66
+ */
67
+ getClaimableInterest(currentIndex) {
68
+ const interestDelta = 1 / this.state.interest.lastSeenIndex - 1 / currentIndex;
69
+ let toCollectSy = Math.floor(Number(this.state.ytBalance.toString()) * interestDelta + Number(this.state.interest.staged));
70
+ // Ensure toCollectSy is not negative
71
+ toCollectSy = Math.max(0, toCollectSy);
72
+ const feeSy = Math.floor((toCollectSy * this.vault.state.interestBpsFee + 9999) / 10000);
73
+ const userSy = Math.max(0, toCollectSy - feeSy);
74
+ let baseAmount = Math.floor(userSy * currentIndex);
75
+ // Ensure final amount is non-negative
76
+ return Math.max(0, baseAmount > 0 ? baseAmount - 1 : baseAmount);
77
+ }
78
+ getClaimableEmissions() {
79
+ // Calculate total SY balance (staged + converted YT balance)
80
+ const totalSyBalance = Number(this.state.interest.staged) + Number(this.state.ytBalance) / this.vault.currentSyExchangeRate;
81
+ return this.vault.syEmissions.map((e, index) => {
82
+ // Use initial index if user doesn't have a position yet (lastSeenIndex is 0)
83
+ const lastSeenIndex = this.state.emissions[index]?.lastSeenIndex ?? 0;
84
+ const earnedEmission = totalSyBalance * (Number(precise_number_1.PreciseNumber.fromRaw(e.index[0]).valueString) - Number(lastSeenIndex));
85
+ return {
86
+ mint: e.mint,
87
+ amount: Math.floor(earnedEmission) + Number(this.state.emissions[index]?.staged ?? 0),
88
+ };
89
+ });
90
+ }
91
+ /** Instruction for depositing YT into the vault */
92
+ ixDepositYt({ amount, ytSrc }) {
93
+ const { mainAccounts, remainingAccounts } = this.depositYtAccounts({ ytSrc });
94
+ return this.coreProgram.methods
95
+ .depositYt(new anchor_1.BN(amount.toString()))
96
+ .accountsStrict(mainAccounts)
97
+ .remainingAccounts(remainingAccounts)
98
+ .instruction();
99
+ }
100
+ /** Instruction for withdrawing YT from the vault */
101
+ ixWithdrawYt({ amount, ytDst }) {
102
+ const { mainAccounts, remainingAccounts } = this.withdrawYtAccounts({ ytDst });
103
+ return this.coreProgram.methods
104
+ .withdrawYt(new anchor_1.BN(amount.toString()))
105
+ .accountsStrict(mainAccounts)
106
+ .remainingAccounts(remainingAccounts)
107
+ .instruction();
108
+ }
109
+ ixStageYield({ payer }) {
110
+ return this.coreProgram.methods
111
+ .stageYtYield()
112
+ .accountsStrict({
113
+ addressLookupTable: this.vault.addressLookupTable,
114
+ vault: this.vault.selfAddress,
115
+ payer,
116
+ syProgram: this.vault.state.syProgram,
117
+ yieldPosition: this.vault.state.yieldPositonAddress,
118
+ systemProgram: anchor_1.web3.SystemProgram.programId,
119
+ userYieldPosition: this.selfAddress,
120
+ eventAuthority: this.vault.eventAuthority,
121
+ program: this.coreProgram.programId,
122
+ })
123
+ .remainingAccounts(this.vault.cpiAccounts.getSyState)
124
+ .instruction();
125
+ }
126
+ ixCollectInterest({ signer, syDst, amount }) {
127
+ const tokenSyDst = syDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.vault.mintSy, signer, true, spl_token_1.TOKEN_PROGRAM_ID);
128
+ const claimAmount = amount !== undefined ? { some: { 0: new anchor_1.BN(amount.toString()) } } : { all: {} };
129
+ return this.coreProgram.methods
130
+ .collectInterest(claimAmount)
131
+ .accountsStrict({
132
+ addressLookupTable: this.vault.addressLookupTable,
133
+ authority: this.vault.authority,
134
+ vault: this.vault.selfAddress,
135
+ syProgram: this.vault.state.syProgram,
136
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
137
+ yieldPosition: this.selfAddress,
138
+ owner: signer,
139
+ escrowSy: this.vault.state.escrowSy,
140
+ treasurySyTokenAccount: this.vault.state.treasurySyTokenAccount,
141
+ tokenSyDst,
142
+ eventAuthority: this.vault.eventAuthority,
143
+ program: this.coreProgram.programId,
144
+ })
145
+ .remainingAccounts(this.vault.cpiAccounts.withdrawSy)
146
+ .instruction();
147
+ }
148
+ ixCollectEmission({ owner, emissionIndex, emissionDst, amount, }) {
149
+ const emission = this.vault.state.emissions[emissionIndex];
150
+ const emissionSy = this.vault.flavor.emissions[emissionIndex];
151
+ emissionDst = emissionDst || (0, spl_token_1.getAssociatedTokenAddressSync)(emissionSy.mint, owner, true, emissionSy.tokenProgram);
152
+ const claimAmount = amount !== undefined ? { some: { 0: new anchor_1.BN(amount.toString()) } } : { all: {} };
153
+ return this.coreProgram.methods
154
+ .collectEmission(emissionIndex, claimAmount)
155
+ .accountsStrict({
156
+ addressLookupTable: this.vault.addressLookupTable,
157
+ authority: this.vault.authority,
158
+ emissionEscrow: emission.tokenAccount,
159
+ vault: this.selfAddress,
160
+ syProgram: this.vault.state.syProgram,
161
+ owner,
162
+ treasuryEmissionTokenAccount: emission.treasuryTokenAccount,
163
+ emissionDst,
164
+ position: this.selfAddress,
165
+ tokenProgram: this.vault.flavor.emissions[emissionIndex].tokenProgram,
166
+ eventAuthority: this.vault.eventAuthority,
167
+ program: this.coreProgram.programId,
168
+ })
169
+ .remainingAccounts(this.vault.cpiAccounts.claimEmission[emissionIndex])
170
+ .instruction();
171
+ }
172
+ depositYtAccounts({ ytSrc }) {
173
+ ytSrc = ytSrc || (0, spl_token_1.getAssociatedTokenAddressSync)(this.vault.mintYt, this.owner, true, spl_token_1.TOKEN_PROGRAM_ID);
174
+ return {
175
+ mainAccounts: {
176
+ depositor: this.owner,
177
+ ytSrc,
178
+ vault: this.vault.selfAddress,
179
+ userYieldPosition: this.selfAddress,
180
+ escrowYt: this.vault.state.escrowYt,
181
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
182
+ syProgram: this.vault.state.syProgram,
183
+ addressLookupTable: this.vault.addressLookupTable,
184
+ yieldPosition: this.vault.state.yieldPositonAddress,
185
+ systemProgram: anchor_1.web3.SystemProgram.programId,
186
+ eventAuthority: this.vault.eventAuthority,
187
+ program: this.coreProgram.programId,
188
+ },
189
+ remainingAccounts: this.vault.cpiAccounts.getSyState,
190
+ };
191
+ }
192
+ withdrawYtAccounts({ ytDst }) {
193
+ ytDst = ytDst || (0, spl_token_1.getAssociatedTokenAddressSync)(this.vault.mintYt, this.owner, true, spl_token_1.TOKEN_PROGRAM_ID);
194
+ return {
195
+ mainAccounts: {
196
+ owner: this.owner,
197
+ vault: this.vault.selfAddress,
198
+ userYieldPosition: this.selfAddress,
199
+ ytDst,
200
+ escrowYt: this.vault.state.escrowYt,
201
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
202
+ authority: this.vault.authority,
203
+ syProgram: this.vault.state.syProgram,
204
+ addressLookupTable: this.vault.addressLookupTable,
205
+ yieldPosition: this.vault.state.yieldPositonAddress,
206
+ systemProgram: anchor_1.web3.SystemProgram.programId,
207
+ eventAuthority: this.vault.eventAuthority,
208
+ program: this.coreProgram.programId,
209
+ },
210
+ remainingAccounts: this.vault.cpiAccounts.getSyState,
211
+ };
212
+ }
213
+ }
214
+ exports.YtPosition = YtPosition;
215
+ function ytPositionToJson(x) {
216
+ return {
217
+ owner: x.owner.toBase58(),
218
+ ytBalance: x.ytBalance.toString(),
219
+ interest: yieldTokenTrackerToJson(x.state.interest),
220
+ emissions: x.state.emissions.map(yieldTokenTrackerToJson),
221
+ claimableInterest: x.getClaimableInterest(x.vault.currentSyExchangeRate),
222
+ vault: x.vault.toJson(),
223
+ };
224
+ }
225
+ function yieldTokenTrackerToJson(x) {
226
+ return {
227
+ lastSeenIndex: x.lastSeenIndex,
228
+ staged: x.staged.toString(),
229
+ };
230
+ }
231
+ //# sourceMappingURL=ytPosition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ytPosition.js","sourceRoot":"","sources":["../src/ytPosition.ts"],"names":[],"mappings":";;;AAAA,8CAAqE;AACrE,8DAA+D;AAE/D,sEAAmH;AACnH,mCAA+B;AAC/B,iDAAmF;AAGnF,8DAAyD;AACzD,qCAAmC;AAEnC,kEAA6D;AAE7D,MAAa,UAAU;IAGZ;IACA;IACA;IACA;IACA;IANF,WAAW,CAAuB;IACzC,YACS,GAAgB,EAChB,UAA2B,EAC3B,WAA2B,EAC3B,KAAsB,EACtB,KAAY;QAJZ,QAAG,GAAH,GAAG,CAAa;QAChB,eAAU,GAAV,UAAU,CAAiB;QAC3B,gBAAW,GAAX,WAAW,CAAgB;QAC3B,UAAK,GAAL,KAAK,CAAiB;QACtB,UAAK,GAAL,KAAK,CAAO;QAEnB,MAAM,UAAU,GAAG,IAAI,iBAAQ,CAAC,aAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACxD,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAO,CAAC,kBAAmB,EAAE,IAAI,uBAAc,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAA;IACjG,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAgB,EAAE,UAA2B,EAAE,OAAuB;QACtF,MAAM,OAAO,GAAG,IAAI,kCAAe,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;QACnD,MAAM,CAAC,GAAG,MAAM,OA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,CAAC,KAAK,CAAC,mBAAmB;gBACnD,aAAa,EAAE,aAAI,CAAC,aAAa,CAAC,SAAS;gBAC3C,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc;gBACzC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS;aACpC;YACD,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,UAAU;SACrD,CAAA;IACH,CAAC;CACF;AA1OD,gCA0OC;AAgBD,SAAS,gBAAgB,CAAC,CAAa;IACrC,OAAO;QACL,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE;QACzB,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE;QACjC,QAAQ,EAAE,uBAAuB,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;QACnD,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,uBAAuB,CAAC;QACzD,iBAAiB,EAAE,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;QACxE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;KACxB,CAAA;AACH,CAAC;AAED,SAAS,uBAAuB,CAAC,CAAoB;IACnD,OAAO;QACL,aAAa,EAAE,CAAC,CAAC,aAAa;QAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE;KAC5B,CAAA;AACH,CAAC"}
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testRegex: '.*\\.test\\.ts$', // Only match files ending with .test.ts
5
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@exponent-labs/exponent-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
+ "test": "jest"
10
+ },
11
+ "dependencies": {
12
+ "@coral-xyz/anchor": "0.30.1",
13
+ "@exponent-labs/exponent-fetcher": "^0.0.3",
14
+ "@exponent-labs/exponent-idl": "^0.0.3",
15
+ "@exponent-labs/exponent-pda": "^0.0.3",
16
+ "@exponent-labs/exponent-types": "^0.0.3",
17
+ "@exponent-labs/generic-sy-idl": "^0.0.3",
18
+ "@exponent-labs/generic-sy-pda": "^0.0.3",
19
+ "@exponent-labs/generic-sy-sdk": "^0.0.3",
20
+ "@exponent-labs/jito-restaking-sy-idl": "^0.0.3",
21
+ "@exponent-labs/jito-restaking-sy-sdk": "^0.0.3",
22
+ "@exponent-labs/kamino-sy-sdk": "^0.0.3",
23
+ "@exponent-labs/marginfi-sy-pda": "^0.0.3",
24
+ "@exponent-labs/marginfi-sy-sdk": "^0.0.3",
25
+ "@exponent-labs/market-math": "^0.0.3",
26
+ "@exponent-labs/perena-sy-idl": "^0.0.3",
27
+ "@exponent-labs/perena-sy-pda": "^0.0.3",
28
+ "@exponent-labs/perena-sy-sdk": "^0.0.3",
29
+ "@solana/spl-token": "0.4.6"
30
+ },
31
+ "devDependencies": {
32
+ "@types/bn.js": "^5.1.0",
33
+ "@types/bs58": "^4.0.4",
34
+ "@types/chai": "^4.3.0",
35
+ "@types/jest": "^29.5.11",
36
+ "@types/mocha": "^9.0.0",
37
+ "jest": "^29.7.0",
38
+ "ts-jest": "^29.1.1",
39
+ "typescript": "5.4.5"
40
+ },
41
+ "gitHead": "209b8847e9a0fadb5b5ec96b9b47f0ace4a3bf9d"
42
+ }
@@ -0,0 +1,34 @@
1
+ import { web3 } from "@coral-xyz/anchor"
2
+ import { CpiAccountIndexes, CpiAccountIndex } from "@exponent-labs/exponent-types"
3
+
4
+ /** Fetch and deserialize the ALT */
5
+ export async function fetchAddressLookupTable(
6
+ connection: web3.Connection,
7
+ address: web3.PublicKey,
8
+ ): Promise<web3.PublicKey[]> {
9
+ const accountInfo = await connection.getAccountInfo(address)
10
+ if (accountInfo === null) {
11
+ throw new Error("Failed to find address lookup table")
12
+ }
13
+
14
+ const alt = web3.AddressLookupTableAccount.deserialize(new Uint8Array(accountInfo.data))
15
+ return alt.addresses
16
+ }
17
+
18
+ /** Create the CPI accounts lists from the Address Lookup Table and the on-chain stored CPI account indexes */
19
+ export function makeCpiAccountMetaLists(altAddresses: web3.PublicKey[], cpiIndexes: CpiAccountIndexes) {
20
+ const pluckAddress = (index: number) => altAddresses[index]
21
+ const transform = (a: CpiAccountIndex): web3.AccountMeta => ({
22
+ isSigner: false,
23
+ isWritable: a.isWritable,
24
+ pubkey: pluckAddress(a.altIndex),
25
+ })
26
+
27
+ return {
28
+ getSyState: cpiIndexes.getSyState.map(transform),
29
+ withdrawSy: cpiIndexes.withdrawSy.map(transform),
30
+ depositSy: cpiIndexes.depositSy.map(transform),
31
+ claimEmission: cpiIndexes.claimEmission.map((a) => a.map(transform)),
32
+ getPositionState: cpiIndexes.getPositionState.map(transform),
33
+ }
34
+ }
@@ -0,0 +1,19 @@
1
+ import { web3 } from "@coral-xyz/anchor"
2
+
3
+ export type Environment = {
4
+ marginfiSyProgramId: web3.PublicKey
5
+ kaminoSyProgramId: web3.PublicKey
6
+ coreProgramId: web3.PublicKey
7
+ jitoRestakingSyProgramId: web3.PublicKey
8
+ perenaSyProgramId: web3.PublicKey
9
+ genericSyProgramId: web3.PublicKey
10
+ }
11
+
12
+ export const LOCAL_ENV: Environment = {
13
+ marginfiSyProgramId: new web3.PublicKey("XPMfipyhcbq3DBvgvxkbZY7GekwmGNJLMD3wdiCkBc7"),
14
+ kaminoSyProgramId: new web3.PublicKey("XPK1ndTK1xrgRg99ifvdPP1exrx8D1mRXTuxBkkroCx"),
15
+ coreProgramId: new web3.PublicKey("ExponentnaRg3CQbW6dqQNZKXp7gtZ9DGMp1cwC4HAS7"),
16
+ jitoRestakingSyProgramId: new web3.PublicKey("XPJitopeUEhMZVF72CvswnwrS2U2akQvk5s26aEfWv2"),
17
+ perenaSyProgramId: new web3.PublicKey("XPerenaJPyvnjseLCn7rgzxFEum6zX1k89C13SPTyGZ"),
18
+ genericSyProgramId: new web3.PublicKey("XP1BRLn8eCYSygrd8er5P4GKdzqKbC3DLoSsS5UYVZy"),
19
+ }