@jup-ag/lend 0.0.1

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/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @jup-ag/lend
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ npm install @jup-ag/lend
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ #### Earning
12
+
13
+ ```ts
14
+ import { getDepositIx, getWithdrawIx } from "@jup-ag/lend/earn";
15
+
16
+ const connection = new Connection("https://api.devnet.solana.com");
17
+ const signer = new PublicKey("signerAddress");
18
+ const usdc = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
19
+
20
+ const depositIx = await getDepositIx({
21
+ amount: new BN(1000000),
22
+ asset: usdc,
23
+
24
+ signer,
25
+ connection,
26
+ });
27
+
28
+ const withdrawIx = await getWithdrawIx({
29
+ amount: new BN(10000),
30
+ asset: usdc,
31
+
32
+ signer,
33
+ connection,
34
+ });
35
+ ```
36
+
37
+ #### Borrowing
38
+
39
+ ```ts
40
+ import { getOperateIx } from "@jup-ag/lend/borrow";
41
+
42
+ const connection = new Connection("https://api.devnet.solana.com");
43
+ const signer = new PublicKey("signerAddress");
44
+ const usdc = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU");
45
+
46
+ const ixs = await getOperateIx({
47
+ vaultId: 1,
48
+ positionId: 0,
49
+
50
+ colAmount: new BN(1000000),
51
+ debtAmount: new BN(1000),
52
+
53
+ signer,
54
+ connection,
55
+ });
56
+ ```
@@ -0,0 +1,19 @@
1
+ import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+
4
+ type ConnectionParams = {
5
+ connection: Connection;
6
+ signer: PublicKey;
7
+ };
8
+ type OperateParams = {
9
+ vaultId: number;
10
+ positionId: number;
11
+ colAmount: BN;
12
+ debtAmount: BN;
13
+ positionOwner?: PublicKey;
14
+ recipient: PublicKey;
15
+ } & ConnectionParams;
16
+ declare const getOperateIx: (_params: OperateParams) => Promise<TransactionInstruction[]>;
17
+
18
+ export { getOperateIx };
19
+ export type { ConnectionParams, OperateParams };
@@ -0,0 +1,19 @@
1
+ import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+
4
+ type ConnectionParams = {
5
+ connection: Connection;
6
+ signer: PublicKey;
7
+ };
8
+ type OperateParams = {
9
+ vaultId: number;
10
+ positionId: number;
11
+ colAmount: BN;
12
+ debtAmount: BN;
13
+ positionOwner?: PublicKey;
14
+ recipient: PublicKey;
15
+ } & ConnectionParams;
16
+ declare const getOperateIx: (_params: OperateParams) => Promise<TransactionInstruction[]>;
17
+
18
+ export { getOperateIx };
19
+ export type { ConnectionParams, OperateParams };
@@ -0,0 +1,5 @@
1
+ const getOperateIx = async (_params) => {
2
+ throw new Error("Not implemented");
3
+ };
4
+
5
+ export { getOperateIx };
@@ -0,0 +1,29 @@
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { Connection, PublicKey } from '@solana/web3.js';
3
+ import BN from 'bn.js';
4
+
5
+ type ConnectionParams = {
6
+ connection: Connection;
7
+ signer: PublicKey;
8
+ };
9
+ type DepositContextParams = {
10
+ asset: PublicKey;
11
+ receipient?: PublicKey;
12
+ signer: PublicKey;
13
+ };
14
+ type DepositParams = {
15
+ amount: BN;
16
+ } & DepositContextParams & ConnectionParams;
17
+ declare const getDepositIx: ({ amount, asset, receipient, signer, connection, }: DepositParams) => Promise<_solana_web3_js.TransactionInstruction>;
18
+ type WithdrawContextParams = {
19
+ asset: PublicKey;
20
+ receipient?: PublicKey;
21
+ signer: PublicKey;
22
+ };
23
+ type WithdrawParams = {
24
+ amount: BN;
25
+ } & WithdrawContextParams & ConnectionParams;
26
+ declare const getWithdrawIx: ({ amount, asset, receipient, signer, connection, }: DepositParams) => Promise<_solana_web3_js.TransactionInstruction>;
27
+
28
+ export { getDepositIx, getWithdrawIx };
29
+ export type { ConnectionParams, DepositContextParams, DepositParams, WithdrawContextParams, WithdrawParams };
@@ -0,0 +1,29 @@
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { Connection, PublicKey } from '@solana/web3.js';
3
+ import BN from 'bn.js';
4
+
5
+ type ConnectionParams = {
6
+ connection: Connection;
7
+ signer: PublicKey;
8
+ };
9
+ type DepositContextParams = {
10
+ asset: PublicKey;
11
+ receipient?: PublicKey;
12
+ signer: PublicKey;
13
+ };
14
+ type DepositParams = {
15
+ amount: BN;
16
+ } & DepositContextParams & ConnectionParams;
17
+ declare const getDepositIx: ({ amount, asset, receipient, signer, connection, }: DepositParams) => Promise<_solana_web3_js.TransactionInstruction>;
18
+ type WithdrawContextParams = {
19
+ asset: PublicKey;
20
+ receipient?: PublicKey;
21
+ signer: PublicKey;
22
+ };
23
+ type WithdrawParams = {
24
+ amount: BN;
25
+ } & WithdrawContextParams & ConnectionParams;
26
+ declare const getWithdrawIx: ({ amount, asset, receipient, signer, connection, }: DepositParams) => Promise<_solana_web3_js.TransactionInstruction>;
27
+
28
+ export { getDepositIx, getWithdrawIx };
29
+ export type { ConnectionParams, DepositContextParams, DepositParams, WithdrawContextParams, WithdrawParams };
@@ -0,0 +1,146 @@
1
+ import { SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, PublicKey } from '@solana/web3.js';
2
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { c as lending, g as getLendingToken, d as getLending, e as getLiquidity, f as getLendingRewardsRateModel, h as getRateModel, i as getUserBorrowPosition, j as getUserSupplyPosition, k as getTokenReserveFromAsset, m as getClaimAccount, n as getLendingAdmin, o as liquidity } from '../shared/lend.DVqn4Bgr.mjs';
5
+
6
+ function getDepositContext({
7
+ receipient,
8
+ asset,
9
+ signer
10
+ }) {
11
+ const lendingToken = getLendingToken(asset);
12
+ const lending2 = getLending(asset);
13
+ const liquidityKey = getLiquidity();
14
+ receipient = receipient ?? signer;
15
+ return {
16
+ signer,
17
+ depositorTokenAccount: getAssociatedTokenAddressSync(asset, signer),
18
+ receipientTokenAccount: getAssociatedTokenAddressSync(
19
+ lendingToken,
20
+ receipient,
21
+ false
22
+ ),
23
+ lendingAdmin: getLendingAdmin(),
24
+ lending: lending2,
25
+ fTokenMint: lendingToken,
26
+ claimAccount: getClaimAccount(
27
+ asset,
28
+ getLendingAdmin()
29
+ ),
30
+ supplyTokenReservesLiquidity: getTokenReserveFromAsset(asset),
31
+ borrowTokenReservesLiquidity: getTokenReserveFromAsset(asset),
32
+ lendingSupplyPositionOnLiquidity: getUserSupplyPosition(
33
+ asset,
34
+ lending2
35
+ ),
36
+ lendingBorrowPositionOnLiquidity: getUserBorrowPosition(
37
+ asset,
38
+ lending2
39
+ ),
40
+ rateModel: getRateModel(asset),
41
+ vault: getAssociatedTokenAddressSync(
42
+ asset,
43
+ liquidityKey,
44
+ true,
45
+ TOKEN_PROGRAM_ID
46
+ ),
47
+ liquidity: liquidityKey,
48
+ liquidityProgram: new PublicKey(liquidity.address),
49
+ rewardsRateModel: getLendingRewardsRateModel(asset),
50
+ tokenProgram: TOKEN_PROGRAM_ID,
51
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
52
+ systemProgram: SystemProgram.programId,
53
+ sysvarInstruction: SYSVAR_INSTRUCTIONS_PUBKEY
54
+ };
55
+ }
56
+ const getDepositIx = async ({
57
+ amount,
58
+ asset,
59
+ receipient,
60
+ signer,
61
+ connection
62
+ }) => {
63
+ const program = new Program(lending, {
64
+ connection,
65
+ publicKey: signer
66
+ });
67
+ return await program.methods.deposit(amount).accounts(
68
+ getDepositContext({
69
+ asset,
70
+ receipient,
71
+ signer
72
+ })
73
+ ).instruction();
74
+ };
75
+ function getWithdrawContext({
76
+ asset,
77
+ receipient,
78
+ signer
79
+ }) {
80
+ const lendingToken = getLendingToken(asset);
81
+ const lending2 = getLending(asset);
82
+ const liquidityKey = getLiquidity();
83
+ receipient = receipient ?? signer;
84
+ return {
85
+ signer,
86
+ ownerTokenAccount: getAssociatedTokenAddressSync(lendingToken, signer),
87
+ receipientTokenAccount: getAssociatedTokenAddressSync(
88
+ asset,
89
+ receipient,
90
+ false
91
+ ),
92
+ lendingAdmin: getLendingAdmin(),
93
+ lending: lending2,
94
+ mint: asset,
95
+ fTokenMint: lendingToken,
96
+ claimAccount: getClaimAccount(
97
+ asset,
98
+ getLendingAdmin()
99
+ ),
100
+ supplyTokenReservesLiquidity: getTokenReserveFromAsset(asset),
101
+ borrowTokenReservesLiquidity: getTokenReserveFromAsset(asset),
102
+ lendingSupplyPositionOnLiquidity: getUserSupplyPosition(
103
+ asset,
104
+ lending2
105
+ ),
106
+ lendingBorrowPositionOnLiquidity: getUserBorrowPosition(
107
+ asset,
108
+ lending2
109
+ ),
110
+ rateModel: getRateModel(asset),
111
+ vault: getAssociatedTokenAddressSync(
112
+ asset,
113
+ liquidityKey,
114
+ true,
115
+ TOKEN_PROGRAM_ID
116
+ ),
117
+ liquidity: liquidityKey,
118
+ liquidityProgram: new PublicKey(liquidity.address),
119
+ rewardsRateModel: getLendingRewardsRateModel(asset),
120
+ tokenProgram: TOKEN_PROGRAM_ID,
121
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
122
+ systemProgram: SystemProgram.programId,
123
+ sysvarInstruction: SYSVAR_INSTRUCTIONS_PUBKEY
124
+ };
125
+ }
126
+ const getWithdrawIx = async ({
127
+ amount,
128
+ asset,
129
+ receipient,
130
+ signer,
131
+ connection
132
+ }) => {
133
+ const program = new Program(lending, {
134
+ connection,
135
+ publicKey: signer
136
+ });
137
+ return await program.methods.withdraw(amount).accounts(
138
+ getWithdrawContext({
139
+ asset,
140
+ receipient,
141
+ signer
142
+ })
143
+ ).instruction();
144
+ };
145
+
146
+ export { getDepositIx, getWithdrawIx };
@@ -0,0 +1,57 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+
3
+ declare const getLendingToken: (assetAddress: PublicKey) => PublicKey;
4
+ declare const getLendingAdmin: () => PublicKey;
5
+ declare const getLending: (assetAddress: PublicKey) => PublicKey;
6
+ declare const getClaimAccount: (assetAddress: PublicKey, user: PublicKey) => PublicKey;
7
+
8
+ declare const lending_getClaimAccount: typeof getClaimAccount;
9
+ declare const lending_getLending: typeof getLending;
10
+ declare const lending_getLendingAdmin: typeof getLendingAdmin;
11
+ declare const lending_getLendingToken: typeof getLendingToken;
12
+ declare namespace lending {
13
+ export {
14
+ lending_getClaimAccount as getClaimAccount,
15
+ lending_getLending as getLending,
16
+ lending_getLendingAdmin as getLendingAdmin,
17
+ lending_getLendingToken as getLendingToken,
18
+ };
19
+ }
20
+
21
+ declare const getSupportedTokenList: () => PublicKey;
22
+ declare const getTokenReserveFromAsset: (asset: PublicKey) => PublicKey;
23
+ declare const getUserSupplyPosition: (asset: PublicKey, protocol: PublicKey) => PublicKey;
24
+ declare const getUserBorrowPosition: (asset: PublicKey, protocol: PublicKey) => PublicKey;
25
+ declare const getRateModel: (asset: PublicKey) => PublicKey;
26
+ declare const getReserve: (asset: PublicKey) => PublicKey;
27
+ declare const getLiquidity: () => PublicKey;
28
+
29
+ declare const liquidity_getLiquidity: typeof getLiquidity;
30
+ declare const liquidity_getRateModel: typeof getRateModel;
31
+ declare const liquidity_getReserve: typeof getReserve;
32
+ declare const liquidity_getSupportedTokenList: typeof getSupportedTokenList;
33
+ declare const liquidity_getTokenReserveFromAsset: typeof getTokenReserveFromAsset;
34
+ declare const liquidity_getUserBorrowPosition: typeof getUserBorrowPosition;
35
+ declare const liquidity_getUserSupplyPosition: typeof getUserSupplyPosition;
36
+ declare namespace liquidity {
37
+ export {
38
+ liquidity_getLiquidity as getLiquidity,
39
+ liquidity_getRateModel as getRateModel,
40
+ liquidity_getReserve as getReserve,
41
+ liquidity_getSupportedTokenList as getSupportedTokenList,
42
+ liquidity_getTokenReserveFromAsset as getTokenReserveFromAsset,
43
+ liquidity_getUserBorrowPosition as getUserBorrowPosition,
44
+ liquidity_getUserSupplyPosition as getUserSupplyPosition,
45
+ };
46
+ }
47
+
48
+ declare const getLendingRewardsRateModel: (assetAddress: PublicKey) => PublicKey;
49
+
50
+ declare const lendingRewardRateModel_getLendingRewardsRateModel: typeof getLendingRewardsRateModel;
51
+ declare namespace lendingRewardRateModel {
52
+ export {
53
+ lendingRewardRateModel_getLendingRewardsRateModel as getLendingRewardsRateModel,
54
+ };
55
+ }
56
+
57
+ export { lending as lendingPda, lendingRewardRateModel as lendingRewardRateModelPda, liquidity as liquidityPda };
@@ -0,0 +1,57 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+
3
+ declare const getLendingToken: (assetAddress: PublicKey) => PublicKey;
4
+ declare const getLendingAdmin: () => PublicKey;
5
+ declare const getLending: (assetAddress: PublicKey) => PublicKey;
6
+ declare const getClaimAccount: (assetAddress: PublicKey, user: PublicKey) => PublicKey;
7
+
8
+ declare const lending_getClaimAccount: typeof getClaimAccount;
9
+ declare const lending_getLending: typeof getLending;
10
+ declare const lending_getLendingAdmin: typeof getLendingAdmin;
11
+ declare const lending_getLendingToken: typeof getLendingToken;
12
+ declare namespace lending {
13
+ export {
14
+ lending_getClaimAccount as getClaimAccount,
15
+ lending_getLending as getLending,
16
+ lending_getLendingAdmin as getLendingAdmin,
17
+ lending_getLendingToken as getLendingToken,
18
+ };
19
+ }
20
+
21
+ declare const getSupportedTokenList: () => PublicKey;
22
+ declare const getTokenReserveFromAsset: (asset: PublicKey) => PublicKey;
23
+ declare const getUserSupplyPosition: (asset: PublicKey, protocol: PublicKey) => PublicKey;
24
+ declare const getUserBorrowPosition: (asset: PublicKey, protocol: PublicKey) => PublicKey;
25
+ declare const getRateModel: (asset: PublicKey) => PublicKey;
26
+ declare const getReserve: (asset: PublicKey) => PublicKey;
27
+ declare const getLiquidity: () => PublicKey;
28
+
29
+ declare const liquidity_getLiquidity: typeof getLiquidity;
30
+ declare const liquidity_getRateModel: typeof getRateModel;
31
+ declare const liquidity_getReserve: typeof getReserve;
32
+ declare const liquidity_getSupportedTokenList: typeof getSupportedTokenList;
33
+ declare const liquidity_getTokenReserveFromAsset: typeof getTokenReserveFromAsset;
34
+ declare const liquidity_getUserBorrowPosition: typeof getUserBorrowPosition;
35
+ declare const liquidity_getUserSupplyPosition: typeof getUserSupplyPosition;
36
+ declare namespace liquidity {
37
+ export {
38
+ liquidity_getLiquidity as getLiquidity,
39
+ liquidity_getRateModel as getRateModel,
40
+ liquidity_getReserve as getReserve,
41
+ liquidity_getSupportedTokenList as getSupportedTokenList,
42
+ liquidity_getTokenReserveFromAsset as getTokenReserveFromAsset,
43
+ liquidity_getUserBorrowPosition as getUserBorrowPosition,
44
+ liquidity_getUserSupplyPosition as getUserSupplyPosition,
45
+ };
46
+ }
47
+
48
+ declare const getLendingRewardsRateModel: (assetAddress: PublicKey) => PublicKey;
49
+
50
+ declare const lendingRewardRateModel_getLendingRewardsRateModel: typeof getLendingRewardsRateModel;
51
+ declare namespace lendingRewardRateModel {
52
+ export {
53
+ lendingRewardRateModel_getLendingRewardsRateModel as getLendingRewardsRateModel,
54
+ };
55
+ }
56
+
57
+ export { lending as lendingPda, lendingRewardRateModel as lendingRewardRateModelPda, liquidity as liquidityPda };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { l as lendingPda, b as lendingRewardRateModelPda, a as liquidityPda } from './shared/lend.DVqn4Bgr.mjs';
2
+ import '@solana/web3.js';