@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.
- package/build/anchor/idl.json +2889 -0
- package/build/anchor/type.d.ts +2895 -0
- package/build/anchor/type.js +3 -0
- package/build/anchor/type.js.map +1 -0
- package/build/constants.d.ts +44 -0
- package/build/constants.js +144 -0
- package/build/constants.js.map +1 -0
- package/build/index.d.ts +103 -0
- package/build/index.js +318 -0
- package/build/index.js.map +1 -0
- package/build/instructions/addEmission.d.ts +11 -0
- package/build/instructions/addEmission.js +58 -0
- package/build/instructions/addEmission.js.map +1 -0
- package/build/instructions/createStandardToken.d.ts +0 -0
- package/build/instructions/createStandardToken.js +56 -0
- package/build/instructions/createStandardToken.js.map +1 -0
- package/build/instructions/depositInstruction.d.ts +17 -0
- package/build/instructions/depositInstruction.js +119 -0
- package/build/instructions/depositInstruction.js.map +1 -0
- package/build/instructions/getPositionInstruction.d.ts +15 -0
- package/build/instructions/getPositionInstruction.js +114 -0
- package/build/instructions/getPositionInstruction.js.map +1 -0
- package/build/instructions/index.d.ts +2 -0
- package/build/instructions/index.js +19 -0
- package/build/instructions/index.js.map +1 -0
- package/build/instructions/initializeKaminoLendAccount.d.ts +18 -0
- package/build/instructions/initializeKaminoLendAccount.js +85 -0
- package/build/instructions/initializeKaminoLendAccount.js.map +1 -0
- package/build/instructions/initializePositionInstruction.d.ts +8 -0
- package/build/instructions/initializePositionInstruction.js +55 -0
- package/build/instructions/initializePositionInstruction.js.map +1 -0
- package/build/instructions/mintInstruction.d.ts +19 -0
- package/build/instructions/mintInstruction.js +132 -0
- package/build/instructions/mintInstruction.js.map +1 -0
- package/build/instructions/redeemInstruction.d.ts +21 -0
- package/build/instructions/redeemInstruction.js +129 -0
- package/build/instructions/redeemInstruction.js.map +1 -0
- package/build/instructions/withdrawInstruction.d.ts +17 -0
- package/build/instructions/withdrawInstruction.js +122 -0
- package/build/instructions/withdrawInstruction.js.map +1 -0
- package/package.json +22 -0
- package/src/anchor/idl.json +2889 -0
- package/src/anchor/type.ts +2895 -0
- package/src/constants.d.ts +44 -0
- package/src/constants.js +133 -0
- package/src/constants.ts +205 -0
- package/src/index.ts +500 -0
- package/src/instructions/addEmission.ts +39 -0
- package/src/instructions/createStandardToken.ts +57 -0
- package/src/instructions/depositInstruction.ts +130 -0
- package/src/instructions/getPositionInstruction.ts +117 -0
- package/src/instructions/index.ts +2 -0
- package/src/instructions/initializeKaminoLendAccount.ts +101 -0
- package/src/instructions/initializePositionInstruction.ts +31 -0
- package/src/instructions/mintInstruction.ts +149 -0
- package/src/instructions/redeemInstruction.ts +140 -0
- package/src/instructions/withdrawInstruction.ts +137 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor"
|
|
2
|
+
import { KaminoLendStandard } from "../anchor/type"
|
|
3
|
+
import { TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
4
|
+
import {
|
|
5
|
+
getAccountAuthority,
|
|
6
|
+
getAccountAuthorityBaseTokenAccount,
|
|
7
|
+
getEmissionTracker,
|
|
8
|
+
getKaminoFarmsObligationFarm,
|
|
9
|
+
getKaminoFarmsVaultAuthority,
|
|
10
|
+
getKaminoLendObligation,
|
|
11
|
+
getMeta,
|
|
12
|
+
getMintAuthority,
|
|
13
|
+
getPosition,
|
|
14
|
+
getStakedReceiptPool,
|
|
15
|
+
getStakedReceiptPoolAuthority,
|
|
16
|
+
getStandardTokenMint,
|
|
17
|
+
} from "../constants"
|
|
18
|
+
|
|
19
|
+
export const depositInstruction = async ({
|
|
20
|
+
kaminoLendStandardProgram,
|
|
21
|
+
kaminoFarmsProgramId,
|
|
22
|
+
kaminoLendProgramId,
|
|
23
|
+
amount,
|
|
24
|
+
lendingMarket,
|
|
25
|
+
reserve,
|
|
26
|
+
reserveFarmState,
|
|
27
|
+
signer,
|
|
28
|
+
feePayer,
|
|
29
|
+
remainingAccounts,
|
|
30
|
+
signerReceiptTokenAccount,
|
|
31
|
+
kaminoFarm,
|
|
32
|
+
kaminoGlobalConfig,
|
|
33
|
+
}: {
|
|
34
|
+
kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
|
|
35
|
+
kaminoFarmsProgramId: anchor.web3.PublicKey
|
|
36
|
+
kaminoLendProgramId: anchor.web3.PublicKey
|
|
37
|
+
amount: anchor.BN
|
|
38
|
+
lendingMarket: anchor.web3.PublicKey
|
|
39
|
+
reserve: anchor.web3.PublicKey
|
|
40
|
+
reserveFarmState: anchor.web3.PublicKey
|
|
41
|
+
signer: anchor.web3.PublicKey
|
|
42
|
+
feePayer: anchor.web3.PublicKey
|
|
43
|
+
remainingAccounts: anchor.web3.AccountMeta[]
|
|
44
|
+
signerReceiptTokenAccount: anchor.web3.PublicKey
|
|
45
|
+
kaminoFarm: anchor.web3.PublicKey
|
|
46
|
+
kaminoGlobalConfig: anchor.web3.PublicKey
|
|
47
|
+
}) => {
|
|
48
|
+
const meta = getMeta(reserve, kaminoLendStandardProgram.programId)
|
|
49
|
+
const obligation = getKaminoLendObligation(meta, lendingMarket, kaminoLendProgramId)
|
|
50
|
+
const userState = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
|
|
51
|
+
const standardTokenMint = getStandardTokenMint(reserve, kaminoLendStandardProgram.programId)
|
|
52
|
+
|
|
53
|
+
// const refreshReserveInstruction = new TransactionInstruction({
|
|
54
|
+
// keys: [
|
|
55
|
+
// {
|
|
56
|
+
// pubkey: reserve,
|
|
57
|
+
// isWritable: true,
|
|
58
|
+
// isSigner: false,
|
|
59
|
+
// },
|
|
60
|
+
// {
|
|
61
|
+
// pubkey: lendingMarket,
|
|
62
|
+
// isWritable: false,
|
|
63
|
+
// isSigner: false,
|
|
64
|
+
// },
|
|
65
|
+
// remainingAccounts[0],
|
|
66
|
+
// { pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
67
|
+
// { pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
68
|
+
// remainingAccounts[1],
|
|
69
|
+
// ],
|
|
70
|
+
// programId: kaminoLendProgramId,
|
|
71
|
+
// data: Buffer.from([2, 218, 138, 235, 79, 201, 25, 102]),
|
|
72
|
+
// })
|
|
73
|
+
|
|
74
|
+
// const refreshObligationInstruction = new TransactionInstruction({
|
|
75
|
+
// keys: [
|
|
76
|
+
// { pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
77
|
+
// { pubkey: obligation, isWritable: true, isSigner: false },
|
|
78
|
+
// ],
|
|
79
|
+
// programId: kaminoLendProgramId,
|
|
80
|
+
// data: Buffer.from([33, 132, 147, 228, 151, 192, 72, 89]),
|
|
81
|
+
// })
|
|
82
|
+
|
|
83
|
+
// const refreshObligationFarmsForReserveInstruction = new TransactionInstruction({
|
|
84
|
+
// keys: [
|
|
85
|
+
// { pubkey: signer, isWritable: true, isSigner: false },
|
|
86
|
+
// { pubkey: obligation, isWritable: true, isSigner: false },
|
|
87
|
+
// { pubkey: lendingMarketAuthority, isWritable: true, isSigner: false },
|
|
88
|
+
// { pubkey: reserve, isWritable: true, isSigner: false },
|
|
89
|
+
// { pubkey: reserveFarmState, isWritable: true, isSigner: false },
|
|
90
|
+
// { pubkey: obligationFarm, isWritable: true, isSigner: false },
|
|
91
|
+
// { pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
92
|
+
// { pubkey: kaminoFarmsProgramId, isWritable: false, isSigner: false },
|
|
93
|
+
// { pubkey: anchor.web3.SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
|
|
94
|
+
// // { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
95
|
+
// { pubkey: anchor.web3.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
96
|
+
// ],
|
|
97
|
+
// programId: kaminoLendProgramId,
|
|
98
|
+
// // 8 byte discriminator + 0 byte for "collateral" mode
|
|
99
|
+
// data: Buffer.from([140, 144, 253, 21, 10, 74, 248, 3, 0]),
|
|
100
|
+
// })
|
|
101
|
+
|
|
102
|
+
const position = getPosition(reserve, signer, kaminoLendStandardProgram.programId)
|
|
103
|
+
const kaminoFarmVaultsAuthority = getKaminoFarmsVaultAuthority(kaminoFarm, kaminoFarmsProgramId)
|
|
104
|
+
|
|
105
|
+
const instruction = await kaminoLendStandardProgram.methods
|
|
106
|
+
.deposit(amount)
|
|
107
|
+
.accountsStrict({
|
|
108
|
+
feePayer,
|
|
109
|
+
meta,
|
|
110
|
+
kaminoReserve: reserve,
|
|
111
|
+
owner: signer,
|
|
112
|
+
position,
|
|
113
|
+
mintSy: standardTokenMint,
|
|
114
|
+
tokenSySigner: signerReceiptTokenAccount,
|
|
115
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
116
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
117
|
+
kaminoFarmsProgram: kaminoFarmsProgramId,
|
|
118
|
+
kaminoFarm,
|
|
119
|
+
kaminoFarmVaultsAuthority,
|
|
120
|
+
kaminoGlobalConfig,
|
|
121
|
+
// farms program id because scope prices is optional
|
|
122
|
+
kaminoScopePrices: kaminoFarmsProgramId,
|
|
123
|
+
tokenSyEscrow: getStakedReceiptPool(reserve, kaminoLendStandardProgram.programId),
|
|
124
|
+
userState,
|
|
125
|
+
})
|
|
126
|
+
.remainingAccounts(remainingAccounts)
|
|
127
|
+
.instruction()
|
|
128
|
+
|
|
129
|
+
return instruction
|
|
130
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor"
|
|
2
|
+
import { KaminoLendStandard } from "../anchor/type"
|
|
3
|
+
import {
|
|
4
|
+
getAccountAuthority,
|
|
5
|
+
getKaminoFarmsObligationFarm,
|
|
6
|
+
getKaminoFarmsVaultAuthority,
|
|
7
|
+
getKaminoLendObligation,
|
|
8
|
+
getMeta,
|
|
9
|
+
getPosition,
|
|
10
|
+
getStakedReceiptPool,
|
|
11
|
+
getStandardTokenMint,
|
|
12
|
+
} from "../constants"
|
|
13
|
+
|
|
14
|
+
export const getPositionInstruction = async ({
|
|
15
|
+
kaminoLendStandardProgram,
|
|
16
|
+
kaminoFarmsProgramId,
|
|
17
|
+
kaminoLendProgramId,
|
|
18
|
+
lendingMarket,
|
|
19
|
+
reserve,
|
|
20
|
+
reserveFarmState,
|
|
21
|
+
signer,
|
|
22
|
+
feePayer,
|
|
23
|
+
remainingAccounts,
|
|
24
|
+
kaminoFarm,
|
|
25
|
+
kaminoGlobalConfig,
|
|
26
|
+
}: {
|
|
27
|
+
kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
|
|
28
|
+
kaminoFarmsProgramId: anchor.web3.PublicKey
|
|
29
|
+
kaminoLendProgramId: anchor.web3.PublicKey
|
|
30
|
+
lendingMarket: anchor.web3.PublicKey
|
|
31
|
+
reserve: anchor.web3.PublicKey
|
|
32
|
+
reserveFarmState: anchor.web3.PublicKey
|
|
33
|
+
signer: anchor.web3.PublicKey
|
|
34
|
+
feePayer: anchor.web3.PublicKey
|
|
35
|
+
remainingAccounts: anchor.web3.AccountMeta[]
|
|
36
|
+
kaminoFarm: anchor.web3.PublicKey
|
|
37
|
+
kaminoGlobalConfig: anchor.web3.PublicKey
|
|
38
|
+
}) => {
|
|
39
|
+
const meta = getMeta(reserve, kaminoLendStandardProgram.programId)
|
|
40
|
+
const obligation = getKaminoLendObligation(meta, lendingMarket, kaminoLendProgramId)
|
|
41
|
+
const userState = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
|
|
42
|
+
const standardTokenMint = getStandardTokenMint(reserve, kaminoLendStandardProgram.programId)
|
|
43
|
+
|
|
44
|
+
// const refreshReserveInstruction = new TransactionInstruction({
|
|
45
|
+
// keys: [
|
|
46
|
+
// {
|
|
47
|
+
// pubkey: reserve,
|
|
48
|
+
// isWritable: true,
|
|
49
|
+
// isSigner: false,
|
|
50
|
+
// },
|
|
51
|
+
// {
|
|
52
|
+
// pubkey: lendingMarket,
|
|
53
|
+
// isWritable: false,
|
|
54
|
+
// isSigner: false,
|
|
55
|
+
// },
|
|
56
|
+
// remainingAccounts[0],
|
|
57
|
+
// { pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
58
|
+
// { pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
59
|
+
// remainingAccounts[1],
|
|
60
|
+
// ],
|
|
61
|
+
// programId: kaminoLendProgramId,
|
|
62
|
+
// data: Buffer.from([2, 218, 138, 235, 79, 201, 25, 102]),
|
|
63
|
+
// })
|
|
64
|
+
|
|
65
|
+
// const refreshObligationInstruction = new TransactionInstruction({
|
|
66
|
+
// keys: [
|
|
67
|
+
// { pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
68
|
+
// { pubkey: obligation, isWritable: true, isSigner: false },
|
|
69
|
+
// ],
|
|
70
|
+
// programId: kaminoLendProgramId,
|
|
71
|
+
// data: Buffer.from([33, 132, 147, 228, 151, 192, 72, 89]),
|
|
72
|
+
// })
|
|
73
|
+
|
|
74
|
+
// const refreshObligationFarmsForReserveInstruction = new TransactionInstruction({
|
|
75
|
+
// keys: [
|
|
76
|
+
// { pubkey: signer, isWritable: true, isSigner: false },
|
|
77
|
+
// { pubkey: obligation, isWritable: true, isSigner: false },
|
|
78
|
+
// { pubkey: lendingMarketAuthority, isWritable: true, isSigner: false },
|
|
79
|
+
// { pubkey: reserve, isWritable: true, isSigner: false },
|
|
80
|
+
// { pubkey: reserveFarmState, isWritable: true, isSigner: false },
|
|
81
|
+
// { pubkey: obligationFarm, isWritable: true, isSigner: false },
|
|
82
|
+
// { pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
83
|
+
// { pubkey: kaminoFarmsProgramId, isWritable: false, isSigner: false },
|
|
84
|
+
// { pubkey: anchor.web3.SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
|
|
85
|
+
// // { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
86
|
+
// { pubkey: anchor.web3.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
87
|
+
// ],
|
|
88
|
+
// programId: kaminoLendProgramId,
|
|
89
|
+
// // 8 byte discriminator + 0 byte for "collateral" mode
|
|
90
|
+
// data: Buffer.from([140, 144, 253, 21, 10, 74, 248, 3, 0]),
|
|
91
|
+
// })
|
|
92
|
+
|
|
93
|
+
const position = getPosition(reserve, signer, kaminoLendStandardProgram.programId)
|
|
94
|
+
const kaminoFarmVaultsAuthority = getKaminoFarmsVaultAuthority(kaminoFarm, kaminoFarmsProgramId)
|
|
95
|
+
|
|
96
|
+
const instruction = await kaminoLendStandardProgram.methods
|
|
97
|
+
.getPosition()
|
|
98
|
+
.accountsStrict({
|
|
99
|
+
meta,
|
|
100
|
+
kaminoReserve: reserve,
|
|
101
|
+
position,
|
|
102
|
+
mintSy: standardTokenMint,
|
|
103
|
+
kaminoFarmsProgram: kaminoFarmsProgramId,
|
|
104
|
+
kaminoFarm,
|
|
105
|
+
kaminoFarmVaultsAuthority,
|
|
106
|
+
kaminoGlobalConfig,
|
|
107
|
+
// farms program id because scope prices is optional
|
|
108
|
+
kaminoScopePrices: kaminoFarmsProgramId,
|
|
109
|
+
tokenSyEscrow: getStakedReceiptPool(reserve, kaminoLendStandardProgram.programId),
|
|
110
|
+
userState,
|
|
111
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
112
|
+
})
|
|
113
|
+
.remainingAccounts(remainingAccounts)
|
|
114
|
+
.instruction()
|
|
115
|
+
|
|
116
|
+
return instruction
|
|
117
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor"
|
|
2
|
+
import { KaminoLendStandard } from "../anchor/type"
|
|
3
|
+
import { TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
4
|
+
import {
|
|
5
|
+
getAccountAuthorityBaseTokenAccount,
|
|
6
|
+
getKaminoFarmsObligationFarm,
|
|
7
|
+
getKaminoLendObligation,
|
|
8
|
+
getKaminoUserMetadata,
|
|
9
|
+
getMeta,
|
|
10
|
+
getStakedReceiptPool,
|
|
11
|
+
getStandardTokenMint,
|
|
12
|
+
METADATA_PROGRAM_ID,
|
|
13
|
+
} from "../constants"
|
|
14
|
+
import { EXPONENT_ADMIN_PROGRAM_ID, ExponentAdminPda } from "@exponent-labs/exponent-admin-pda"
|
|
15
|
+
|
|
16
|
+
export const initializeKaminoLendAccountInstruction = ({
|
|
17
|
+
kaminoLendStandardProgram,
|
|
18
|
+
kaminoFarmsProgramId,
|
|
19
|
+
kaminoLendProgramId,
|
|
20
|
+
lendingMarket,
|
|
21
|
+
lendingMarketAuthority,
|
|
22
|
+
reserve,
|
|
23
|
+
reserveFarmState,
|
|
24
|
+
signer,
|
|
25
|
+
feePayer,
|
|
26
|
+
userLookupTable,
|
|
27
|
+
baseMint,
|
|
28
|
+
baseTokenProgram,
|
|
29
|
+
minMintSize,
|
|
30
|
+
minRedeemSize,
|
|
31
|
+
}: {
|
|
32
|
+
kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
|
|
33
|
+
kaminoFarmsProgramId: anchor.web3.PublicKey
|
|
34
|
+
kaminoLendProgramId: anchor.web3.PublicKey
|
|
35
|
+
lendingMarket: anchor.web3.PublicKey
|
|
36
|
+
lendingMarketAuthority: anchor.web3.PublicKey
|
|
37
|
+
reserve: anchor.web3.PublicKey
|
|
38
|
+
reserveFarmState: anchor.web3.PublicKey
|
|
39
|
+
signer: anchor.web3.PublicKey
|
|
40
|
+
feePayer: anchor.web3.PublicKey
|
|
41
|
+
userLookupTable: anchor.web3.PublicKey
|
|
42
|
+
baseMint: anchor.web3.PublicKey
|
|
43
|
+
baseTokenProgram: anchor.web3.PublicKey
|
|
44
|
+
minMintSize: anchor.BN
|
|
45
|
+
minRedeemSize: anchor.BN
|
|
46
|
+
}) => {
|
|
47
|
+
const meta = getMeta(reserve, kaminoLendStandardProgram.programId)
|
|
48
|
+
const userMetadata = getKaminoUserMetadata(meta, kaminoLendProgramId)
|
|
49
|
+
const obligation = getKaminoLendObligation(meta, lendingMarket, kaminoLendProgramId)
|
|
50
|
+
const obligationFarm = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
|
|
51
|
+
const exponentAdmin = new ExponentAdminPda(EXPONENT_ADMIN_PROGRAM_ID)
|
|
52
|
+
const admin = exponentAdmin.exponentAdmin()
|
|
53
|
+
|
|
54
|
+
const [metadataPda] = anchor.web3.PublicKey.findProgramAddressSync(
|
|
55
|
+
[
|
|
56
|
+
Buffer.from("metadata"),
|
|
57
|
+
METADATA_PROGRAM_ID.toBuffer(),
|
|
58
|
+
getStandardTokenMint(reserve, kaminoLendStandardProgram.programId).toBuffer(),
|
|
59
|
+
],
|
|
60
|
+
METADATA_PROGRAM_ID,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
const instruction = kaminoLendStandardProgram.methods
|
|
64
|
+
.initSy(
|
|
65
|
+
new anchor.BN(0),
|
|
66
|
+
new anchor.BN(0),
|
|
67
|
+
new anchor.BN("18446744073709551615"),
|
|
68
|
+
"Kamino PYUSD",
|
|
69
|
+
"kPYUSD",
|
|
70
|
+
"https://raw.githubusercontent.com/valentinmadrid/exponent-icons/refs/heads/main/lyts/kPYUSD%20-%20Main%20Market.json",
|
|
71
|
+
)
|
|
72
|
+
.accountsStrict({
|
|
73
|
+
adminState: admin,
|
|
74
|
+
feePayer,
|
|
75
|
+
lendingMarket,
|
|
76
|
+
meta,
|
|
77
|
+
reserve,
|
|
78
|
+
lendingMarketAuthority,
|
|
79
|
+
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
80
|
+
signer,
|
|
81
|
+
userMetadata,
|
|
82
|
+
obligation,
|
|
83
|
+
obligationFarm,
|
|
84
|
+
reserveFarmState,
|
|
85
|
+
userLookupTable,
|
|
86
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
87
|
+
kaminoFarmsProgram: kaminoFarmsProgramId,
|
|
88
|
+
kaminoLendProgram: kaminoLendProgramId,
|
|
89
|
+
accountAuthorityBaseToken: getAccountAuthorityBaseTokenAccount(reserve, kaminoLendStandardProgram.programId),
|
|
90
|
+
baseMint,
|
|
91
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
92
|
+
mintSy: getStandardTokenMint(reserve, kaminoLendStandardProgram.programId),
|
|
93
|
+
tokenReceiptPool: getStakedReceiptPool(reserve, kaminoLendStandardProgram.programId),
|
|
94
|
+
tokenProgramBase: baseTokenProgram,
|
|
95
|
+
tokenMetadataProgram: METADATA_PROGRAM_ID,
|
|
96
|
+
metadata: metadataPda,
|
|
97
|
+
})
|
|
98
|
+
.instruction()
|
|
99
|
+
|
|
100
|
+
return instruction
|
|
101
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor"
|
|
2
|
+
import { KaminoLendStandard } from "../anchor/type"
|
|
3
|
+
import { getMeta, getPosition } from "../constants"
|
|
4
|
+
|
|
5
|
+
export const initializePositionInstruction = async ({
|
|
6
|
+
kaminoLendStandardProgram,
|
|
7
|
+
reserve,
|
|
8
|
+
signer,
|
|
9
|
+
feePayer,
|
|
10
|
+
}: {
|
|
11
|
+
kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
|
|
12
|
+
reserve: anchor.web3.PublicKey
|
|
13
|
+
signer: anchor.web3.PublicKey
|
|
14
|
+
feePayer: anchor.web3.PublicKey
|
|
15
|
+
}) => {
|
|
16
|
+
const position = getPosition(reserve, signer, kaminoLendStandardProgram.programId)
|
|
17
|
+
|
|
18
|
+
const instruction = await kaminoLendStandardProgram.methods
|
|
19
|
+
.initializePosition()
|
|
20
|
+
.accountsStrict({
|
|
21
|
+
feePayer,
|
|
22
|
+
meta: getMeta(reserve, kaminoLendStandardProgram.programId),
|
|
23
|
+
kaminoReserve: reserve,
|
|
24
|
+
owner: signer,
|
|
25
|
+
position,
|
|
26
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
27
|
+
})
|
|
28
|
+
.instruction()
|
|
29
|
+
|
|
30
|
+
return instruction
|
|
31
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor"
|
|
2
|
+
import { KaminoLendStandard } from "../anchor/type"
|
|
3
|
+
import { TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
4
|
+
import {
|
|
5
|
+
getAccountAuthority,
|
|
6
|
+
getAccountAuthorityBaseTokenAccount,
|
|
7
|
+
getKaminoFarmsObligationFarm,
|
|
8
|
+
getKaminoLendObligation,
|
|
9
|
+
getKaminoReserveCollateralMint,
|
|
10
|
+
getKaminoReserveCollateralSupply,
|
|
11
|
+
getKaminoReserveLiquiditySupply,
|
|
12
|
+
getKaminoUserMetadata,
|
|
13
|
+
getMeta,
|
|
14
|
+
getMintAuthority,
|
|
15
|
+
getStandardTokenMint,
|
|
16
|
+
} from "../constants"
|
|
17
|
+
import { TransactionInstruction } from "@solana/web3.js"
|
|
18
|
+
|
|
19
|
+
export const mintInstruction = async ({
|
|
20
|
+
kaminoLendStandardProgram,
|
|
21
|
+
kaminoFarmsProgramId,
|
|
22
|
+
kaminoLendProgramId,
|
|
23
|
+
amount,
|
|
24
|
+
lendingMarket,
|
|
25
|
+
lendingMarketAuthority,
|
|
26
|
+
reserve,
|
|
27
|
+
reserveFarmState,
|
|
28
|
+
signer,
|
|
29
|
+
feePayer,
|
|
30
|
+
remainingAccounts,
|
|
31
|
+
baseMint,
|
|
32
|
+
signerBaseTokenAccount,
|
|
33
|
+
signerReceiptTokenAccount,
|
|
34
|
+
tokenProgramBase,
|
|
35
|
+
}: {
|
|
36
|
+
kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
|
|
37
|
+
kaminoFarmsProgramId: anchor.web3.PublicKey
|
|
38
|
+
kaminoLendProgramId: anchor.web3.PublicKey
|
|
39
|
+
amount: anchor.BN
|
|
40
|
+
lendingMarket: anchor.web3.PublicKey
|
|
41
|
+
lendingMarketAuthority: 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
|
+
baseMint: anchor.web3.PublicKey
|
|
48
|
+
signerBaseTokenAccount: anchor.web3.PublicKey
|
|
49
|
+
signerReceiptTokenAccount: anchor.web3.PublicKey
|
|
50
|
+
tokenProgramBase: anchor.web3.PublicKey
|
|
51
|
+
}) => {
|
|
52
|
+
const meta = getMeta(reserve, kaminoLendStandardProgram.programId)
|
|
53
|
+
const userMetadata = getKaminoUserMetadata(meta, kaminoLendProgramId)
|
|
54
|
+
const obligation = getKaminoLendObligation(meta, lendingMarket, kaminoLendProgramId)
|
|
55
|
+
const obligationFarm = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
|
|
56
|
+
const standardTokenMint = getStandardTokenMint(reserve, kaminoLendStandardProgram.programId)
|
|
57
|
+
const accountAuthorityBaseToken = getAccountAuthorityBaseTokenAccount(reserve, kaminoLendStandardProgram.programId)
|
|
58
|
+
const reserveLiquiditySupply = getKaminoReserveLiquiditySupply(lendingMarket, baseMint, kaminoLendProgramId)
|
|
59
|
+
const reserveCollateralMint = getKaminoReserveCollateralMint(lendingMarket, baseMint, kaminoLendProgramId)
|
|
60
|
+
console.log("reserveCollateralMint", reserveCollateralMint.toBase58())
|
|
61
|
+
const reserveDestinationDepositCollateral = getKaminoReserveCollateralSupply(
|
|
62
|
+
lendingMarket,
|
|
63
|
+
baseMint,
|
|
64
|
+
kaminoLendProgramId,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
const refreshReserveInstruction = new TransactionInstruction({
|
|
68
|
+
keys: [
|
|
69
|
+
{
|
|
70
|
+
pubkey: reserve,
|
|
71
|
+
isWritable: true,
|
|
72
|
+
isSigner: false,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
pubkey: lendingMarket,
|
|
76
|
+
isWritable: false,
|
|
77
|
+
isSigner: false,
|
|
78
|
+
},
|
|
79
|
+
{ pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
80
|
+
{ pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
81
|
+
{ pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
82
|
+
remainingAccounts[1],
|
|
83
|
+
],
|
|
84
|
+
programId: kaminoLendProgramId,
|
|
85
|
+
data: Buffer.from([2, 218, 138, 235, 79, 201, 25, 102]),
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const refreshObligationInstruction = new TransactionInstruction({
|
|
89
|
+
keys: [
|
|
90
|
+
{ pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
91
|
+
{ pubkey: obligation, isWritable: true, isSigner: false },
|
|
92
|
+
],
|
|
93
|
+
programId: kaminoLendProgramId,
|
|
94
|
+
data: Buffer.from([33, 132, 147, 228, 151, 192, 72, 89]),
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const refreshObligationFarmsForReserveInstruction = new TransactionInstruction({
|
|
98
|
+
keys: [
|
|
99
|
+
{ pubkey: signer, isWritable: true, isSigner: false },
|
|
100
|
+
{ pubkey: obligation, isWritable: true, isSigner: false },
|
|
101
|
+
{ pubkey: lendingMarketAuthority, isWritable: true, isSigner: false },
|
|
102
|
+
{ pubkey: reserve, isWritable: true, isSigner: false },
|
|
103
|
+
{ pubkey: reserveFarmState, isWritable: true, isSigner: false },
|
|
104
|
+
{ pubkey: obligationFarm, isWritable: true, isSigner: false },
|
|
105
|
+
{ pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
106
|
+
{ pubkey: kaminoFarmsProgramId, isWritable: false, isSigner: false },
|
|
107
|
+
{ pubkey: anchor.web3.SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
|
|
108
|
+
// { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
109
|
+
{ pubkey: anchor.web3.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
110
|
+
],
|
|
111
|
+
programId: kaminoLendProgramId,
|
|
112
|
+
// 8 byte discriminator + 0 byte for "collateral" mode
|
|
113
|
+
data: Buffer.from([140, 144, 253, 21, 10, 74, 248, 3, 0]),
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const instruction = await kaminoLendStandardProgram.methods
|
|
117
|
+
.mint(amount)
|
|
118
|
+
.accountsStrict({
|
|
119
|
+
lendingMarket,
|
|
120
|
+
kaminoReserve: reserve,
|
|
121
|
+
meta,
|
|
122
|
+
lendingMarketAuthority,
|
|
123
|
+
signer,
|
|
124
|
+
kaminoObligation: obligation,
|
|
125
|
+
mintBase: baseMint,
|
|
126
|
+
tokenBaseAccountAuthority: accountAuthorityBaseToken,
|
|
127
|
+
instruction: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
128
|
+
mintSy: standardTokenMint,
|
|
129
|
+
tokenBaseSigner: signerBaseTokenAccount,
|
|
130
|
+
tokenSySigner: signerReceiptTokenAccount,
|
|
131
|
+
reserveLiquiditySupply,
|
|
132
|
+
reserveCollateralMint,
|
|
133
|
+
tokenProgramBase,
|
|
134
|
+
token22Program: TOKEN_PROGRAM_ID,
|
|
135
|
+
kaminoLendProgram: kaminoLendProgramId,
|
|
136
|
+
reserveDestinationDepositCollateral,
|
|
137
|
+
kaminoCollateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
138
|
+
})
|
|
139
|
+
.remainingAccounts(remainingAccounts)
|
|
140
|
+
.instruction()
|
|
141
|
+
|
|
142
|
+
return [
|
|
143
|
+
refreshReserveInstruction,
|
|
144
|
+
refreshObligationInstruction,
|
|
145
|
+
refreshObligationFarmsForReserveInstruction,
|
|
146
|
+
instruction,
|
|
147
|
+
refreshObligationFarmsForReserveInstruction,
|
|
148
|
+
]
|
|
149
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor"
|
|
2
|
+
import { KaminoLendStandard } from "../anchor/type"
|
|
3
|
+
import { TOKEN_PROGRAM_ID } from "@solana/spl-token"
|
|
4
|
+
import {
|
|
5
|
+
getAccountAuthority,
|
|
6
|
+
getAccountAuthorityBaseTokenAccount,
|
|
7
|
+
getKaminoFarmsObligationFarm,
|
|
8
|
+
getKaminoLendObligation,
|
|
9
|
+
getMeta,
|
|
10
|
+
getStandardTokenMint,
|
|
11
|
+
} from "../constants"
|
|
12
|
+
import { TransactionInstruction } from "@solana/web3.js"
|
|
13
|
+
|
|
14
|
+
export const redeemInstruction = async ({
|
|
15
|
+
kaminoLendStandardProgram,
|
|
16
|
+
kaminoFarmsProgramId,
|
|
17
|
+
kaminoLendProgramId,
|
|
18
|
+
amount,
|
|
19
|
+
lendingMarket,
|
|
20
|
+
lendingMarketAuthority,
|
|
21
|
+
reserve,
|
|
22
|
+
reserveFarmState,
|
|
23
|
+
signer,
|
|
24
|
+
remainingAccounts,
|
|
25
|
+
baseMint,
|
|
26
|
+
signerBaseTokenAccount,
|
|
27
|
+
signerReceiptTokenAccount,
|
|
28
|
+
reserveLiquiditySupply,
|
|
29
|
+
reserveCollateralMint,
|
|
30
|
+
reserveSourceCollateral,
|
|
31
|
+
}: {
|
|
32
|
+
kaminoLendStandardProgram: anchor.Program<KaminoLendStandard>
|
|
33
|
+
kaminoFarmsProgramId: anchor.web3.PublicKey
|
|
34
|
+
kaminoLendProgramId: anchor.web3.PublicKey
|
|
35
|
+
amount: anchor.BN
|
|
36
|
+
lendingMarket: anchor.web3.PublicKey
|
|
37
|
+
lendingMarketAuthority: anchor.web3.PublicKey
|
|
38
|
+
reserve: anchor.web3.PublicKey
|
|
39
|
+
reserveFarmState: anchor.web3.PublicKey
|
|
40
|
+
signer: anchor.web3.PublicKey
|
|
41
|
+
feePayer: anchor.web3.PublicKey
|
|
42
|
+
remainingAccounts: anchor.web3.AccountMeta[]
|
|
43
|
+
baseMint: anchor.web3.PublicKey
|
|
44
|
+
signerBaseTokenAccount: anchor.web3.PublicKey
|
|
45
|
+
signerReceiptTokenAccount: anchor.web3.PublicKey
|
|
46
|
+
reserveLiquiditySupply: anchor.web3.PublicKey
|
|
47
|
+
reserveCollateralMint: anchor.web3.PublicKey
|
|
48
|
+
reserveSourceCollateral: anchor.web3.PublicKey
|
|
49
|
+
}) => {
|
|
50
|
+
const meta = getMeta(reserve, kaminoLendStandardProgram.programId)
|
|
51
|
+
const obligation = getKaminoLendObligation(meta, lendingMarket, kaminoLendProgramId)
|
|
52
|
+
const obligationFarm = getKaminoFarmsObligationFarm(obligation, reserveFarmState, kaminoFarmsProgramId)
|
|
53
|
+
const standardTokenMint = getStandardTokenMint(reserve, kaminoLendStandardProgram.programId)
|
|
54
|
+
const accountAuthorityBaseToken = getAccountAuthorityBaseTokenAccount(reserve, kaminoLendStandardProgram.programId)
|
|
55
|
+
|
|
56
|
+
const refreshReserveInstruction = new TransactionInstruction({
|
|
57
|
+
keys: [
|
|
58
|
+
{
|
|
59
|
+
pubkey: reserve,
|
|
60
|
+
isWritable: true,
|
|
61
|
+
isSigner: false,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
pubkey: lendingMarket,
|
|
65
|
+
isWritable: false,
|
|
66
|
+
isSigner: false,
|
|
67
|
+
},
|
|
68
|
+
{ pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
69
|
+
{ pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
70
|
+
{ pubkey: kaminoLendProgramId, isWritable: false, isSigner: false },
|
|
71
|
+
remainingAccounts[1],
|
|
72
|
+
],
|
|
73
|
+
programId: kaminoLendProgramId,
|
|
74
|
+
data: Buffer.from([2, 218, 138, 235, 79, 201, 25, 102]),
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const refreshObligationInstruction = new TransactionInstruction({
|
|
78
|
+
keys: [
|
|
79
|
+
{ pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
80
|
+
{ pubkey: obligation, isWritable: true, isSigner: false },
|
|
81
|
+
{ pubkey: reserve, isWritable: false, isSigner: false },
|
|
82
|
+
],
|
|
83
|
+
programId: kaminoLendProgramId,
|
|
84
|
+
data: Buffer.from([33, 132, 147, 228, 151, 192, 72, 89]),
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const refreshObligationFarmsForReserveInstruction = new TransactionInstruction({
|
|
88
|
+
keys: [
|
|
89
|
+
{ pubkey: signer, isWritable: true, isSigner: false },
|
|
90
|
+
{ pubkey: obligation, isWritable: true, isSigner: false },
|
|
91
|
+
{ pubkey: lendingMarketAuthority, isWritable: true, isSigner: false },
|
|
92
|
+
{ pubkey: reserve, isWritable: true, isSigner: false },
|
|
93
|
+
{ pubkey: reserveFarmState, isWritable: true, isSigner: false },
|
|
94
|
+
{ pubkey: obligationFarm, isWritable: true, isSigner: false },
|
|
95
|
+
{ pubkey: lendingMarket, isWritable: false, isSigner: false },
|
|
96
|
+
{ pubkey: kaminoFarmsProgramId, isWritable: false, isSigner: false },
|
|
97
|
+
{ pubkey: anchor.web3.SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
|
|
98
|
+
// { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
99
|
+
{ pubkey: anchor.web3.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
100
|
+
],
|
|
101
|
+
programId: kaminoLendProgramId,
|
|
102
|
+
// 8 byte discriminator + 0 byte for "collateral" mode
|
|
103
|
+
data: Buffer.from([140, 144, 253, 21, 10, 74, 248, 3, 0]),
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const instruction = await kaminoLendStandardProgram.methods
|
|
107
|
+
.redeem(amount)
|
|
108
|
+
.accountsStrict({
|
|
109
|
+
lendingMarket,
|
|
110
|
+
kaminoReserve: reserve,
|
|
111
|
+
meta,
|
|
112
|
+
lendingMarketAuthority,
|
|
113
|
+
signer,
|
|
114
|
+
kaminoObligation: obligation,
|
|
115
|
+
mintBase: baseMint,
|
|
116
|
+
tokenBaseAccountAuthority: accountAuthorityBaseToken,
|
|
117
|
+
instruction: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
118
|
+
mintSy: standardTokenMint,
|
|
119
|
+
tokenBaseSigner: signerBaseTokenAccount,
|
|
120
|
+
tokenSySigner: signerReceiptTokenAccount,
|
|
121
|
+
reserveLiquiditySupply,
|
|
122
|
+
reserveCollateralMint,
|
|
123
|
+
// TODO - this token program is not known
|
|
124
|
+
tokenProgramBase: TOKEN_PROGRAM_ID,
|
|
125
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
126
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
127
|
+
kaminoLendProgram: kaminoLendProgramId,
|
|
128
|
+
reserveSourceCollateral,
|
|
129
|
+
})
|
|
130
|
+
.remainingAccounts(remainingAccounts)
|
|
131
|
+
.instruction()
|
|
132
|
+
|
|
133
|
+
return [
|
|
134
|
+
refreshReserveInstruction,
|
|
135
|
+
refreshObligationInstruction,
|
|
136
|
+
refreshObligationFarmsForReserveInstruction,
|
|
137
|
+
instruction,
|
|
138
|
+
refreshObligationFarmsForReserveInstruction,
|
|
139
|
+
]
|
|
140
|
+
}
|