@jup-ag/lend 0.0.107-beta.1 → 0.1.0

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 CHANGED
@@ -11,24 +11,22 @@ npm install @jup-ag/lend
11
11
  #### Earning
12
12
 
13
13
  ```ts
14
- import { getDepositIx, getWithdrawIx } from "@jup-ag/lend/earn";
14
+ import { getDepositIxs, getWithdrawIxs } from "@jup-ag/lend/earn";
15
15
 
16
16
  const connection = new Connection("https://api.mainnet-beta.solana.com");
17
17
  const signer = new PublicKey("signerAddress");
18
18
  const usdc = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
19
19
 
20
- const depositIx = await getDepositIx({
20
+ const { ixs: depositIxs } = await getDepositIxs({
21
21
  amount: new BN(1000000),
22
22
  asset: usdc,
23
-
24
23
  signer,
25
24
  connection,
26
25
  });
27
26
 
28
- const withdrawIx = await getWithdrawIx({
27
+ const { ixs: withdrawIxs } = await getWithdrawIxs({
29
28
  amount: new BN(10000),
30
29
  asset: usdc,
31
-
32
30
  signer,
33
31
  connection,
34
32
  });
@@ -1,5 +1,4 @@
1
- import * as _solana_web3_js from '@solana/web3.js';
2
- import { Connection, PublicKey } from '@solana/web3.js';
1
+ import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
3
2
  import BN from 'bn.js';
4
3
  import { Program } from '@coral-xyz/anchor';
5
4
 
@@ -40,8 +39,26 @@ declare function getDepositContext({ asset, signer, connection, }: DepositContex
40
39
  systemProgram: PublicKey;
41
40
  sysvarInstruction: PublicKey;
42
41
  }>;
43
- declare const getDepositIx: ({ amount, asset, signer, connection, }: DepositParams) => Promise<_solana_web3_js.TransactionInstruction>;
44
- declare const getMintIx: ({ shares, asset, signer, connection, }: MintParams) => Promise<_solana_web3_js.TransactionInstruction>;
42
+ /**
43
+ * @param amount - The amount of assets to deposit
44
+ * @param asset - The asset to deposit (Mint address)
45
+ * @param signer - The signer of the transaction
46
+ * @param connection - The connection
47
+ * @returns { ixs: TransactionInstruction[] } - The instructions to deposit the assets
48
+ */
49
+ declare const getDepositIxs: ({ amount, asset, signer, connection, }: DepositParams) => Promise<{
50
+ ixs: TransactionInstruction[];
51
+ }>;
52
+ /**
53
+ * @param shares - The number of shares to mint
54
+ * @param asset - The asset to mint (Mint address)
55
+ * @param signer - The signer of the transaction
56
+ * @param connection - The connection
57
+ * @returns { ixs: TransactionInstruction[] } - The instructions to mint the shares
58
+ */
59
+ declare const getMintIxs: ({ shares, asset, signer, connection, }: MintParams) => Promise<{
60
+ ixs: TransactionInstruction[];
61
+ }>;
45
62
  type WithdrawContextParams = {
46
63
  asset: PublicKey;
47
64
  signer: PublicKey;
@@ -73,8 +90,26 @@ declare function getWithdrawContext({ asset, signer, connection, }: WithdrawCont
73
90
  systemProgram: PublicKey;
74
91
  sysvarInstruction: PublicKey;
75
92
  }>;
76
- declare const getWithdrawIx: ({ amount, asset, signer, connection, }: WithdrawParams) => Promise<_solana_web3_js.TransactionInstruction>;
77
- declare const getRedeemIx: ({ shares, asset, signer, connection, }: RedeemParams) => Promise<_solana_web3_js.TransactionInstruction>;
93
+ /**
94
+ * @param amount - The amount of assets to withdraw
95
+ * @param asset - The asset to withdraw (Mint address)
96
+ * @param signer - The signer of the transaction
97
+ * @param connection - The connection
98
+ * @returns { ixs: TransactionInstruction[] } - The instructions to withdraw the assets
99
+ */
100
+ declare const getWithdrawIxs: ({ amount, asset, signer, connection, }: WithdrawParams) => Promise<{
101
+ ixs: TransactionInstruction[];
102
+ }>;
103
+ /**
104
+ * @param shares - The number of shares to redeem
105
+ * @param asset - The asset to redeem (Mint address)
106
+ * @param signer - The signer of the transaction
107
+ * @param connection - The connection
108
+ * @returns { ixs: TransactionInstruction[] } - The instructions to redeem the shares
109
+ */
110
+ declare const getRedeemIxs: ({ shares, asset, signer, connection, }: RedeemParams) => Promise<{
111
+ ixs: TransactionInstruction[];
112
+ }>;
78
113
 
79
114
  /**
80
115
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -1824,6 +1859,7 @@ declare const getLendingProgram: ({ connection, signer, }: {
1824
1859
  signer?: PublicKey;
1825
1860
  }) => Program<Lending>;
1826
1861
  declare const getAccountOwner: (account: PublicKey, connection: Connection) => Promise<PublicKey>;
1862
+ declare const getOrCreateATAInstruction: (owner: PublicKey, mint: PublicKey, connection: Connection) => Promise<TransactionInstruction[]>;
1827
1863
 
1828
1864
  declare const getLendingTokens: ({ connection, }: {
1829
1865
  connection: Connection;
@@ -1853,5 +1889,5 @@ declare const getUserLendingPositionByAsset: ({ user, asset, connection, }: {
1853
1889
  underlyingBalance: BN;
1854
1890
  }>;
1855
1891
 
1856
- export { getAccountOwner, getDepositContext, getDepositIx, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIx, getRedeemIx, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIx };
1892
+ export { getAccountOwner, getDepositContext, getDepositIxs, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIxs, getOrCreateATAInstruction, getRedeemIxs, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIxs };
1857
1893
  export type { ConnectionParams, DepositContextParams, DepositParams, MintParams, RedeemParams, WithdrawContextParams, WithdrawParams };
@@ -1,5 +1,4 @@
1
- import * as _solana_web3_js from '@solana/web3.js';
2
- import { Connection, PublicKey } from '@solana/web3.js';
1
+ import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
3
2
  import BN from 'bn.js';
4
3
  import { Program } from '@coral-xyz/anchor';
5
4
 
@@ -40,8 +39,26 @@ declare function getDepositContext({ asset, signer, connection, }: DepositContex
40
39
  systemProgram: PublicKey;
41
40
  sysvarInstruction: PublicKey;
42
41
  }>;
43
- declare const getDepositIx: ({ amount, asset, signer, connection, }: DepositParams) => Promise<_solana_web3_js.TransactionInstruction>;
44
- declare const getMintIx: ({ shares, asset, signer, connection, }: MintParams) => Promise<_solana_web3_js.TransactionInstruction>;
42
+ /**
43
+ * @param amount - The amount of assets to deposit
44
+ * @param asset - The asset to deposit (Mint address)
45
+ * @param signer - The signer of the transaction
46
+ * @param connection - The connection
47
+ * @returns { ixs: TransactionInstruction[] } - The instructions to deposit the assets
48
+ */
49
+ declare const getDepositIxs: ({ amount, asset, signer, connection, }: DepositParams) => Promise<{
50
+ ixs: TransactionInstruction[];
51
+ }>;
52
+ /**
53
+ * @param shares - The number of shares to mint
54
+ * @param asset - The asset to mint (Mint address)
55
+ * @param signer - The signer of the transaction
56
+ * @param connection - The connection
57
+ * @returns { ixs: TransactionInstruction[] } - The instructions to mint the shares
58
+ */
59
+ declare const getMintIxs: ({ shares, asset, signer, connection, }: MintParams) => Promise<{
60
+ ixs: TransactionInstruction[];
61
+ }>;
45
62
  type WithdrawContextParams = {
46
63
  asset: PublicKey;
47
64
  signer: PublicKey;
@@ -73,8 +90,26 @@ declare function getWithdrawContext({ asset, signer, connection, }: WithdrawCont
73
90
  systemProgram: PublicKey;
74
91
  sysvarInstruction: PublicKey;
75
92
  }>;
76
- declare const getWithdrawIx: ({ amount, asset, signer, connection, }: WithdrawParams) => Promise<_solana_web3_js.TransactionInstruction>;
77
- declare const getRedeemIx: ({ shares, asset, signer, connection, }: RedeemParams) => Promise<_solana_web3_js.TransactionInstruction>;
93
+ /**
94
+ * @param amount - The amount of assets to withdraw
95
+ * @param asset - The asset to withdraw (Mint address)
96
+ * @param signer - The signer of the transaction
97
+ * @param connection - The connection
98
+ * @returns { ixs: TransactionInstruction[] } - The instructions to withdraw the assets
99
+ */
100
+ declare const getWithdrawIxs: ({ amount, asset, signer, connection, }: WithdrawParams) => Promise<{
101
+ ixs: TransactionInstruction[];
102
+ }>;
103
+ /**
104
+ * @param shares - The number of shares to redeem
105
+ * @param asset - The asset to redeem (Mint address)
106
+ * @param signer - The signer of the transaction
107
+ * @param connection - The connection
108
+ * @returns { ixs: TransactionInstruction[] } - The instructions to redeem the shares
109
+ */
110
+ declare const getRedeemIxs: ({ shares, asset, signer, connection, }: RedeemParams) => Promise<{
111
+ ixs: TransactionInstruction[];
112
+ }>;
78
113
 
79
114
  /**
80
115
  * Program IDL in camelCase format in order to be used in JS/TS.
@@ -1824,6 +1859,7 @@ declare const getLendingProgram: ({ connection, signer, }: {
1824
1859
  signer?: PublicKey;
1825
1860
  }) => Program<Lending>;
1826
1861
  declare const getAccountOwner: (account: PublicKey, connection: Connection) => Promise<PublicKey>;
1862
+ declare const getOrCreateATAInstruction: (owner: PublicKey, mint: PublicKey, connection: Connection) => Promise<TransactionInstruction[]>;
1827
1863
 
1828
1864
  declare const getLendingTokens: ({ connection, }: {
1829
1865
  connection: Connection;
@@ -1853,5 +1889,5 @@ declare const getUserLendingPositionByAsset: ({ user, asset, connection, }: {
1853
1889
  underlyingBalance: BN;
1854
1890
  }>;
1855
1891
 
1856
- export { getAccountOwner, getDepositContext, getDepositIx, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIx, getRedeemIx, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIx };
1892
+ export { getAccountOwner, getDepositContext, getDepositIxs, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIxs, getOrCreateATAInstruction, getRedeemIxs, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIxs };
1857
1893
  export type { ConnectionParams, DepositContextParams, DepositParams, MintParams, RedeemParams, WithdrawContextParams, WithdrawParams };
@@ -1,5 +1,5 @@
1
1
  import { SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, PublicKey } from '@solana/web3.js';
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
2
+ import { getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
3
3
  import { l as liquidity } from '../shared/lend.CioR9-te.mjs';
4
4
  import { Program } from '@coral-xyz/anchor';
5
5
  import { b as lending, g as getLendingToken, c as getLending, d as getLendingRewardsRateModel, e as getClaimAccount, f as getLendingAdmin } from '../shared/lend.DS0KoPpL.mjs';
@@ -19,6 +19,24 @@ const getAccountOwner = async (account, connection) => {
19
19
  throw new Error(`Account info not found for ${account.toString()}`);
20
20
  return info.owner;
21
21
  };
22
+ const getOrCreateATAInstruction = async (owner, mint, connection) => {
23
+ const associatedTokenAccount = await getAssociatedTokenAddress(mint, owner);
24
+ const account = await getAccount(connection, associatedTokenAccount).catch(
25
+ () => null
26
+ );
27
+ const ixs = [];
28
+ if (!account) {
29
+ ixs.push(
30
+ createAssociatedTokenAccountInstruction(
31
+ owner,
32
+ associatedTokenAccount,
33
+ owner,
34
+ mint
35
+ )
36
+ );
37
+ }
38
+ return ixs;
39
+ };
22
40
 
23
41
  const LIQUIDITY_PROGRAM_ID = new PublicKey(liquidity.address);
24
42
  async function getDepositContext({
@@ -78,7 +96,7 @@ async function getDepositContext({
78
96
  sysvarInstruction: SYSVAR_INSTRUCTIONS_PUBKEY
79
97
  };
80
98
  }
81
- const getDepositIx = async ({
99
+ const getDepositIxs = async ({
82
100
  amount,
83
101
  asset,
84
102
  signer,
@@ -88,15 +106,26 @@ const getDepositIx = async ({
88
106
  connection,
89
107
  signer
90
108
  });
91
- return await program.methods.deposit(amount).accounts(
92
- await getDepositContext({
93
- asset,
109
+ const ixs = [];
110
+ ixs.push(
111
+ ...await getOrCreateATAInstruction(
94
112
  signer,
113
+ getLendingToken(asset),
95
114
  connection
96
- })
97
- ).instruction();
115
+ )
116
+ );
117
+ ixs.push(
118
+ await program.methods.deposit(amount).accounts(
119
+ await getDepositContext({
120
+ asset,
121
+ signer,
122
+ connection
123
+ })
124
+ ).instruction()
125
+ );
126
+ return { ixs };
98
127
  };
99
- const getMintIx = async ({
128
+ const getMintIxs = async ({
100
129
  shares,
101
130
  asset,
102
131
  signer,
@@ -106,13 +135,24 @@ const getMintIx = async ({
106
135
  connection,
107
136
  signer
108
137
  });
109
- return await program.methods.mint(shares).accounts(
110
- await getDepositContext({
111
- asset,
138
+ const ixs = [];
139
+ ixs.push(
140
+ ...await getOrCreateATAInstruction(
112
141
  signer,
142
+ getLendingToken(asset),
113
143
  connection
114
- })
115
- ).instruction();
144
+ )
145
+ );
146
+ ixs.push(
147
+ await program.methods.mint(shares).accounts(
148
+ await getDepositContext({
149
+ asset,
150
+ signer,
151
+ connection
152
+ })
153
+ ).instruction()
154
+ );
155
+ return { ixs };
116
156
  };
117
157
  async function getWithdrawContext({
118
158
  asset,
@@ -166,7 +206,7 @@ async function getWithdrawContext({
166
206
  sysvarInstruction: SYSVAR_INSTRUCTIONS_PUBKEY
167
207
  };
168
208
  }
169
- const getWithdrawIx = async ({
209
+ const getWithdrawIxs = async ({
170
210
  amount,
171
211
  asset,
172
212
  signer,
@@ -176,15 +216,20 @@ const getWithdrawIx = async ({
176
216
  connection,
177
217
  signer
178
218
  });
179
- return await program.methods.withdraw(amount).accounts(
180
- await getWithdrawContext({
181
- asset,
182
- signer,
183
- connection
184
- })
185
- ).instruction();
219
+ const ixs = [];
220
+ ixs.push(...await getOrCreateATAInstruction(signer, asset, connection));
221
+ ixs.push(
222
+ await program.methods.withdraw(amount).accounts(
223
+ await getWithdrawContext({
224
+ asset,
225
+ signer,
226
+ connection
227
+ })
228
+ ).instruction()
229
+ );
230
+ return { ixs };
186
231
  };
187
- const getRedeemIx = async ({
232
+ const getRedeemIxs = async ({
188
233
  shares,
189
234
  asset,
190
235
  signer,
@@ -194,13 +239,18 @@ const getRedeemIx = async ({
194
239
  connection,
195
240
  signer
196
241
  });
197
- return await program.methods.redeem(shares).accounts(
198
- await getWithdrawContext({
199
- asset,
200
- signer,
201
- connection
202
- })
203
- ).instruction();
242
+ const ixs = [];
243
+ ixs.push(...await getOrCreateATAInstruction(signer, asset, connection));
244
+ ixs.push(
245
+ await program.methods.redeem(shares).accounts(
246
+ await getWithdrawContext({
247
+ asset,
248
+ signer,
249
+ connection
250
+ })
251
+ ).instruction()
252
+ );
253
+ return { ixs };
204
254
  };
205
255
 
206
256
  const LENDING_CONSTANTS = {
@@ -536,4 +586,4 @@ const getUserLendingPositionByAsset = async ({
536
586
  };
537
587
  };
538
588
 
539
- export { getAccountOwner, getDepositContext, getDepositIx, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIx, getRedeemIx, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIx };
589
+ export { getAccountOwner, getDepositContext, getDepositIxs, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIxs, getOrCreateATAInstruction, getRedeemIxs, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIxs };
package/dist/index.mjs CHANGED
@@ -8,6 +8,6 @@ import './shared/lend.CioR9-te.mjs';
8
8
  import '@solana/spl-token';
9
9
  import 'bn.js';
10
10
 
11
- const version = "0.0.107-beta.1";
11
+ const version = "0.1.0";
12
12
 
13
13
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jup-ag/lend",
3
- "version": "0.0.107-beta.1",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",