@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 +3 -5
- package/dist/earn/index.d.mts +43 -7
- package/dist/earn/index.d.ts +43 -7
- package/dist/earn/index.mjs +80 -30
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,24 +11,22 @@ npm install @jup-ag/lend
|
|
|
11
11
|
#### Earning
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import {
|
|
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
|
|
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
|
|
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
|
});
|
package/dist/earn/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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,
|
|
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 };
|
package/dist/earn/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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,
|
|
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 };
|
package/dist/earn/index.mjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
109
|
+
const ixs = [];
|
|
110
|
+
ixs.push(
|
|
111
|
+
...await getOrCreateATAInstruction(
|
|
94
112
|
signer,
|
|
113
|
+
getLendingToken(asset),
|
|
95
114
|
connection
|
|
96
|
-
|
|
97
|
-
)
|
|
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
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
const ixs = [];
|
|
139
|
+
ixs.push(
|
|
140
|
+
...await getOrCreateATAInstruction(
|
|
112
141
|
signer,
|
|
142
|
+
getLendingToken(asset),
|
|
113
143
|
connection
|
|
114
|
-
|
|
115
|
-
)
|
|
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
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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,
|
|
589
|
+
export { getAccountOwner, getDepositContext, getDepositIxs, getLendingProgram, getLendingTokenDetails, getLendingTokens, getMintIxs, getOrCreateATAInstruction, getRedeemIxs, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIxs };
|
package/dist/index.mjs
CHANGED