@exponent-labs/kamino-lend-standard 0.9.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 (58) hide show
  1. package/build/anchor/idl.json +2889 -0
  2. package/build/anchor/type.d.ts +2895 -0
  3. package/build/anchor/type.js +3 -0
  4. package/build/anchor/type.js.map +1 -0
  5. package/build/constants.d.ts +44 -0
  6. package/build/constants.js +144 -0
  7. package/build/constants.js.map +1 -0
  8. package/build/index.d.ts +103 -0
  9. package/build/index.js +318 -0
  10. package/build/index.js.map +1 -0
  11. package/build/instructions/addEmission.d.ts +11 -0
  12. package/build/instructions/addEmission.js +58 -0
  13. package/build/instructions/addEmission.js.map +1 -0
  14. package/build/instructions/createStandardToken.d.ts +0 -0
  15. package/build/instructions/createStandardToken.js +56 -0
  16. package/build/instructions/createStandardToken.js.map +1 -0
  17. package/build/instructions/depositInstruction.d.ts +17 -0
  18. package/build/instructions/depositInstruction.js +119 -0
  19. package/build/instructions/depositInstruction.js.map +1 -0
  20. package/build/instructions/getPositionInstruction.d.ts +15 -0
  21. package/build/instructions/getPositionInstruction.js +114 -0
  22. package/build/instructions/getPositionInstruction.js.map +1 -0
  23. package/build/instructions/index.d.ts +2 -0
  24. package/build/instructions/index.js +19 -0
  25. package/build/instructions/index.js.map +1 -0
  26. package/build/instructions/initializeKaminoLendAccount.d.ts +18 -0
  27. package/build/instructions/initializeKaminoLendAccount.js +85 -0
  28. package/build/instructions/initializeKaminoLendAccount.js.map +1 -0
  29. package/build/instructions/initializePositionInstruction.d.ts +8 -0
  30. package/build/instructions/initializePositionInstruction.js +55 -0
  31. package/build/instructions/initializePositionInstruction.js.map +1 -0
  32. package/build/instructions/mintInstruction.d.ts +19 -0
  33. package/build/instructions/mintInstruction.js +132 -0
  34. package/build/instructions/mintInstruction.js.map +1 -0
  35. package/build/instructions/redeemInstruction.d.ts +21 -0
  36. package/build/instructions/redeemInstruction.js +129 -0
  37. package/build/instructions/redeemInstruction.js.map +1 -0
  38. package/build/instructions/withdrawInstruction.d.ts +17 -0
  39. package/build/instructions/withdrawInstruction.js +122 -0
  40. package/build/instructions/withdrawInstruction.js.map +1 -0
  41. package/package.json +22 -0
  42. package/src/anchor/idl.json +2889 -0
  43. package/src/anchor/type.ts +2895 -0
  44. package/src/constants.d.ts +44 -0
  45. package/src/constants.js +133 -0
  46. package/src/constants.ts +205 -0
  47. package/src/index.ts +500 -0
  48. package/src/instructions/addEmission.ts +39 -0
  49. package/src/instructions/createStandardToken.ts +57 -0
  50. package/src/instructions/depositInstruction.ts +130 -0
  51. package/src/instructions/getPositionInstruction.ts +117 -0
  52. package/src/instructions/index.ts +2 -0
  53. package/src/instructions/initializeKaminoLendAccount.ts +101 -0
  54. package/src/instructions/initializePositionInstruction.ts +31 -0
  55. package/src/instructions/mintInstruction.ts +149 -0
  56. package/src/instructions/redeemInstruction.ts +140 -0
  57. package/src/instructions/withdrawInstruction.ts +137 -0
  58. package/tsconfig.json +19 -0
@@ -0,0 +1,137 @@
1
+ import * as anchor from "@coral-xyz/anchor"
2
+ import { KaminoLendStandard } from "../anchor/type"
3
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token"
4
+ import { MarginfiSyPda } from "@exponent-labs/marginfi-sy-pda"
5
+ import {
6
+ getAccountAuthority,
7
+ getAccountAuthorityBaseTokenAccount,
8
+ getEmissionTracker,
9
+ getKaminoFarmsObligationFarm,
10
+ getKaminoFarmsVaultAuthority,
11
+ getKaminoLendObligation,
12
+ getKaminoUserMetadata,
13
+ getMeta,
14
+ getMintAuthority,
15
+ getPosition,
16
+ getStakedReceiptPool,
17
+ getStakedReceiptPoolAuthority,
18
+ getStandardTokenMint,
19
+ } from "../constants"
20
+ import { TransactionInstruction } from "@solana/web3.js"
21
+
22
+ export const withdrawInstruction = async ({
23
+ kaminoLendStandardProgram,
24
+ kaminoFarmsProgramId,
25
+ kaminoLendProgramId,
26
+ amount,
27
+ lendingMarket,
28
+ reserve,
29
+ reserveFarmState,
30
+ signer,
31
+ feePayer,
32
+ remainingAccounts,
33
+ signerReceiptTokenAccount,
34
+ kaminoFarm,
35
+ kaminoGlobalConfig,
36
+ }: {
37
+ kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
38
+ kaminoFarmsProgramId: anchor.web3.PublicKey
39
+ kaminoLendProgramId: anchor.web3.PublicKey
40
+ amount: anchor.BN
41
+ lendingMarket: anchor.web3.PublicKey
42
+ reserve: anchor.web3.PublicKey
43
+ reserveFarmState: anchor.web3.PublicKey
44
+ signer: anchor.web3.PublicKey
45
+ feePayer: anchor.web3.PublicKey
46
+ remainingAccounts: anchor.web3.AccountMeta[]
47
+ signerReceiptTokenAccount: anchor.web3.PublicKey
48
+ kaminoFarm: anchor.web3.PublicKey
49
+ kaminoGlobalConfig: anchor.web3.PublicKey
50
+ }) => {
51
+ const meta = getMeta(reserve, kaminoLendStandardProgram.programId)
52
+
53
+ const obligation = getKaminoLendObligation(meta, lendingMarket, kaminoLendProgramId)
54
+ const userState = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
55
+ const obligationFarm = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
56
+ const standardTokenMint = getStandardTokenMint(reserve, kaminoLendStandardProgram.programId)
57
+ const accountAuthorityBaseToken = getAccountAuthorityBaseTokenAccount(reserve, kaminoLendStandardProgram.programId)
58
+
59
+ // const refreshReserveInstruction = new TransactionInstruction({
60
+ // keys: [
61
+ // {
62
+ // pubkey: reserve,
63
+ // isWritable: true,
64
+ // isSigner: false,
65
+ // },
66
+ // {
67
+ // pubkey: lendingMarket,
68
+ // isWritable: false,
69
+ // isSigner: false,
70
+ // },
71
+ // remainingAccounts[0],
72
+ // { pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
73
+ // { pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
74
+ // remainingAccounts[1],
75
+ // ],
76
+ // programId: kaminoLendProgramId,
77
+ // data: Buffer.from([2, 218, 138, 235, 79, 201, 25, 102]),
78
+ // })
79
+
80
+ // const refreshObligationInstruction = new TransactionInstruction({
81
+ // keys: [
82
+ // { pubkey: lendingMarket, isWritable: false, isSigner: false },
83
+ // { pubkey: obligation, isWritable: true, isSigner: false },
84
+ // ],
85
+ // programId: kaminoLendProgramId,
86
+ // data: Buffer.from([33, 132, 147, 228, 151, 192, 72, 89]),
87
+ // })
88
+
89
+ // const refreshObligationFarmsForReserveInstruction = new TransactionInstruction({
90
+ // keys: [
91
+ // { pubkey: signer, isWritable: true, isSigner: false },
92
+ // { pubkey: obligation, isWritable: true, isSigner: false },
93
+ // { pubkey: lendingMarketAuthority, isWritable: true, isSigner: false },
94
+ // { pubkey: reserve, isWritable: true, isSigner: false },
95
+ // { pubkey: reserveFarmState, isWritable: true, isSigner: false },
96
+ // { pubkey: obligationFarm, isWritable: true, isSigner: false },
97
+ // { pubkey: lendingMarket, isWritable: false, isSigner: false },
98
+ // { pubkey: kaminoFarmsProgramId, isWritable: false, isSigner: false },
99
+ // { pubkey: anchor.web3.SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
100
+ // // { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
101
+ // { pubkey: anchor.web3.SystemProgram.programId, isWritable: false, isSigner: false },
102
+ // ],
103
+ // programId: kaminoLendProgramId,
104
+ // // 8 byte discriminator + 0 byte for "collateral" mode
105
+ // data: Buffer.from([140, 144, 253, 21, 10, 74, 248, 3, 0]),
106
+ // })
107
+
108
+ const emissionTracker = getEmissionTracker(reserve, kaminoLendStandardProgram.programId)
109
+ const position = getPosition(reserve, signer, kaminoLendStandardProgram.programId)
110
+ const kaminoFarmVaultsAuthority = getKaminoFarmsVaultAuthority(kaminoFarm, kaminoFarmsProgramId)
111
+
112
+ const instruction = await kaminoLendStandardProgram.methods
113
+ .withdraw(amount)
114
+ .accountsStrict({
115
+ feePayer,
116
+ meta,
117
+ kaminoReserve: reserve,
118
+ owner: signer,
119
+ position,
120
+ tokenSyEscrow: getStakedReceiptPool(reserve, kaminoLendStandardProgram.programId),
121
+ mintSy: standardTokenMint,
122
+ tokenSySigner: signerReceiptTokenAccount,
123
+ tokenProgram: TOKEN_PROGRAM_ID,
124
+ systemProgram: anchor.web3.SystemProgram.programId,
125
+ kaminoFarmsProgram: kaminoFarmsProgramId,
126
+ kaminoFarm,
127
+ kaminoFarmVaultsAuthority,
128
+ kaminoGlobalConfig,
129
+ // farms program id because scope prices is optional
130
+ kaminoScopePrices: kaminoFarmsProgramId,
131
+ userState,
132
+ })
133
+ .remainingAccounts(remainingAccounts)
134
+ .instruction()
135
+
136
+ return instruction
137
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
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": [{ "path": "../exponent-admin-pda" }]
19
+ }