@carrot-protocol/boost-http-client 0.2.15-swapper1-dev-cda79a9 → 0.2.16-group-refactor1-dev-50c976e
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/dist/index.d.ts +5 -11
- package/dist/index.js +116 -175
- package/dist/types.d.ts +18 -48
- package/package.json +2 -2
- package/src/index.ts +132 -219
- package/src/types.ts +18 -52
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnchorProvider, web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import { GetBankResponse, GetUserResponse, GetGroupResponse,
|
|
2
|
+
import { GetBankResponse, GetUserResponse, GetGroupResponse, GetUserRequest } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export * from "./utils";
|
|
5
5
|
export * as Common from "@carrot-protocol/clend-common";
|
|
@@ -27,13 +27,7 @@ export declare class Client {
|
|
|
27
27
|
* @param user wallet public key
|
|
28
28
|
* @returns User details
|
|
29
29
|
*/
|
|
30
|
-
getUser(
|
|
31
|
-
/**
|
|
32
|
-
* Get all groups
|
|
33
|
-
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
34
|
-
* @returns All groups
|
|
35
|
-
*/
|
|
36
|
-
getGroups(includeBankData: boolean): Promise<GetGroupsResponse>;
|
|
30
|
+
getUser(request: GetUserRequest): Promise<GetUserResponse>;
|
|
37
31
|
/**
|
|
38
32
|
* Get market details
|
|
39
33
|
* @param groupAddress group public key
|
|
@@ -51,17 +45,17 @@ export declare class Client {
|
|
|
51
45
|
* @param request Deposit leverage request parameters
|
|
52
46
|
* @returns Deposit leverage operation result
|
|
53
47
|
*/
|
|
54
|
-
depositLeverage(
|
|
48
|
+
depositLeverage(inputMint: web3.PublicKey, assetMint: web3.PublicKey, liabilityMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number): Promise<string>;
|
|
55
49
|
/**
|
|
56
50
|
* Adjust the leverage of an existing position
|
|
57
51
|
* @param request Adjust leverage request parameters
|
|
58
52
|
* @returns Adjust leverage operation result
|
|
59
53
|
*/
|
|
60
|
-
adjustLeverage(
|
|
54
|
+
adjustLeverage(leverage: number, slippageBps: number): Promise<any>;
|
|
61
55
|
/**
|
|
62
56
|
* Withdraw from or close a leveraged position
|
|
63
57
|
* @param request Withdraw leverage request parameters
|
|
64
58
|
* @returns Withdraw leverage operation result
|
|
65
59
|
*/
|
|
66
|
-
withdrawLeverage(
|
|
60
|
+
withdrawLeverage(selectedTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<any>;
|
|
67
61
|
}
|
package/dist/index.js
CHANGED
|
@@ -104,166 +104,122 @@ class Client {
|
|
|
104
104
|
* @param user wallet public key
|
|
105
105
|
* @returns User details
|
|
106
106
|
*/
|
|
107
|
-
async getUser(
|
|
108
|
-
|
|
107
|
+
async getUser(request) {
|
|
108
|
+
// use loaded wallet if not provided
|
|
109
|
+
let user = request.user;
|
|
110
|
+
if (!user) {
|
|
111
|
+
user = this.address();
|
|
112
|
+
}
|
|
113
|
+
const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&getClendAccountSummary=${request.getClendAccountSummary}`));
|
|
109
114
|
const jsonRawResponse = JSON.parse(body);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
// get tokens still in user wallet
|
|
116
|
+
const wallet = {
|
|
117
|
+
usdcBalance: new anchor_1.BN(jsonRawResponse.wallet.usdcBalance, "hex"),
|
|
118
|
+
usdcBalanceUi: Number(jsonRawResponse.wallet.usdcBalanceUi),
|
|
119
|
+
jlpBalance: new anchor_1.BN(jsonRawResponse.wallet.jlpBalance, "hex"),
|
|
120
|
+
jlpBalanceUi: Number(jsonRawResponse.wallet.jlpBalanceUi),
|
|
121
|
+
solBalance: new anchor_1.BN(jsonRawResponse.wallet.solBalance, "hex"),
|
|
122
|
+
solBalanceUi: Number(jsonRawResponse.wallet.solBalanceUi),
|
|
123
|
+
};
|
|
124
|
+
// if no clend account, return undefined for clend
|
|
125
|
+
if (!jsonRawResponse.clendAccount) {
|
|
126
|
+
return {
|
|
127
|
+
wallet,
|
|
128
|
+
clendAccount: undefined,
|
|
129
|
+
summary: [],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// parse lending account balances
|
|
133
|
+
const balances = [];
|
|
134
|
+
for (const b of jsonRawResponse.clendAccount.balances) {
|
|
135
|
+
balances.push({
|
|
115
136
|
mint: new anchor_1.web3.PublicKey(b.mint),
|
|
116
|
-
|
|
117
|
-
|
|
137
|
+
bank: new anchor_1.web3.PublicKey(b.bank),
|
|
138
|
+
assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
|
|
139
|
+
assetBalanceUi: Number(b.assetBalanceUi),
|
|
140
|
+
assetValue: Number(b.assetValue),
|
|
141
|
+
liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
|
|
142
|
+
liabilityBalanceUi: Number(b.liabilityBalanceUi),
|
|
143
|
+
liabilityValue: Number(b.liabilityValue),
|
|
144
|
+
price: Number(b.price),
|
|
118
145
|
});
|
|
119
146
|
}
|
|
120
|
-
//
|
|
121
|
-
const
|
|
122
|
-
balances
|
|
147
|
+
// create clend account
|
|
148
|
+
const clendAccount = {
|
|
149
|
+
balances,
|
|
150
|
+
netValue: Number(jsonRawResponse.clendAccount.netValue),
|
|
151
|
+
netApy: Number(jsonRawResponse.clendAccount.netApy),
|
|
152
|
+
pnl: Number(jsonRawResponse.clendAccount.pnl),
|
|
153
|
+
totalAssetValue: Number(jsonRawResponse.clendAccount.totalAssetValue),
|
|
154
|
+
totalLiabilityValue: Number(jsonRawResponse.clendAccount.totalLiabilityValue),
|
|
155
|
+
healthFactorNotional: Number(jsonRawResponse.clendAccount.healthFactorNotional),
|
|
156
|
+
healthFactorRiskAdjusted: Number(jsonRawResponse.clendAccount.healthFactorRiskAdjusted),
|
|
157
|
+
notionalLeverage: Number(jsonRawResponse.clendAccount.notionalLeverage),
|
|
158
|
+
riskAdjustedLeverage: Number(jsonRawResponse.clendAccount.riskAdjustedLeverage),
|
|
159
|
+
liquidationPrice: Number(jsonRawResponse.clendAccount.liquidationPrice),
|
|
160
|
+
liquidationPriceChangePercentage: Number(jsonRawResponse.clendAccount.liquidationPriceChangePercentage),
|
|
161
|
+
notionalLtv: Number(jsonRawResponse.clendAccount.notionalLtv),
|
|
162
|
+
riskAdjustedLtv: Number(jsonRawResponse.clendAccount.riskAdjustedLtv),
|
|
123
163
|
};
|
|
124
|
-
// get tx summary for each account
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
164
|
+
// get tx summary for each account
|
|
165
|
+
const summary = [];
|
|
166
|
+
for (const s of jsonRawResponse.summary) {
|
|
167
|
+
const txSummary = {
|
|
168
|
+
txSig: s.txSig,
|
|
169
|
+
time: s.time,
|
|
170
|
+
clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
|
|
171
|
+
clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
|
|
172
|
+
clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
|
|
173
|
+
action: s.action,
|
|
174
|
+
input: undefined,
|
|
175
|
+
events: [],
|
|
176
|
+
};
|
|
177
|
+
// parse inputs if they exist
|
|
178
|
+
if (s.input) {
|
|
179
|
+
const input = {
|
|
180
|
+
apiPath: s.input.apiPath,
|
|
181
|
+
selectedTokenMint: s.input.selectedTokenMint
|
|
182
|
+
? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
|
|
183
|
+
: null,
|
|
184
|
+
amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
|
|
185
|
+
leverage: s.input.leverage ? Number(s.input.leverage) : null,
|
|
186
|
+
slippageBps: s.input.slippageBps ? Number(s.input.slippageBps) : null,
|
|
187
|
+
openPosition: s.input.openPosition
|
|
188
|
+
? Boolean(s.input.openPosition)
|
|
189
|
+
: null,
|
|
190
|
+
closePosition: s.input.closePosition
|
|
191
|
+
? Boolean(s.input.closePosition)
|
|
192
|
+
: null,
|
|
141
193
|
};
|
|
142
|
-
|
|
143
|
-
if (s.input) {
|
|
144
|
-
const input = {
|
|
145
|
-
apiPath: s.input.apiPath,
|
|
146
|
-
selectedTokenMint: s.input.selectedTokenMint
|
|
147
|
-
? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
|
|
148
|
-
: null,
|
|
149
|
-
amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
|
|
150
|
-
leverage: s.input.leverage ? Number(s.input.leverage) : null,
|
|
151
|
-
slippageBps: s.input.slippageBps
|
|
152
|
-
? Number(s.input.slippageBps)
|
|
153
|
-
: null,
|
|
154
|
-
openPosition: s.input.openPosition
|
|
155
|
-
? Boolean(s.input.openPosition)
|
|
156
|
-
: null,
|
|
157
|
-
closePosition: s.input.closePosition
|
|
158
|
-
? Boolean(s.input.closePosition)
|
|
159
|
-
: null,
|
|
160
|
-
};
|
|
161
|
-
txSummary.input = input;
|
|
162
|
-
}
|
|
163
|
-
// get events for each summary
|
|
164
|
-
for (const event of s.events) {
|
|
165
|
-
let closeBalance = null;
|
|
166
|
-
if (event.closeBalance !== null) {
|
|
167
|
-
closeBalance = Boolean(event.closeBalance);
|
|
168
|
-
}
|
|
169
|
-
// parse amount
|
|
170
|
-
const clendAccountEvent = {
|
|
171
|
-
eventIndex: event.eventIndex,
|
|
172
|
-
eventName: event.eventName,
|
|
173
|
-
bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
|
|
174
|
-
mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
|
|
175
|
-
amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
|
|
176
|
-
amountUi: event.amountUi ? Number(event.amountUi) : null,
|
|
177
|
-
value: event.value ? Number(event.value) : null,
|
|
178
|
-
price: event.price ? Number(event.price) : null,
|
|
179
|
-
closeBalance,
|
|
180
|
-
};
|
|
181
|
-
txSummary.events.push(clendAccountEvent);
|
|
182
|
-
}
|
|
183
|
-
summaryByAccount.get(accountAddress).push(txSummary);
|
|
194
|
+
txSummary.input = input;
|
|
184
195
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
: null
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
assetBalanceUi: Number(b.assetBalanceUi),
|
|
205
|
-
assetValue: Number(b.assetValue),
|
|
206
|
-
assetYieldBps: Number(b.assetYieldBps),
|
|
207
|
-
assetYieldApy: Number(b.assetYieldApy),
|
|
208
|
-
liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
|
|
209
|
-
liabilityBalanceUi: Number(b.liabilityBalanceUi),
|
|
210
|
-
liabilityValue: Number(b.liabilityValue),
|
|
211
|
-
liabilityBorrowCostBps: Number(b.liabilityBorrowCostBps),
|
|
212
|
-
liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
|
|
213
|
-
price: Number(b.price),
|
|
214
|
-
liquidation,
|
|
215
|
-
});
|
|
196
|
+
// get events for each summary
|
|
197
|
+
for (const event of s.events) {
|
|
198
|
+
let closeBalance = null;
|
|
199
|
+
if (event.closeBalance !== null) {
|
|
200
|
+
closeBalance = Boolean(event.closeBalance);
|
|
201
|
+
}
|
|
202
|
+
// parse amount
|
|
203
|
+
const clendAccountEvent = {
|
|
204
|
+
eventIndex: event.eventIndex,
|
|
205
|
+
eventName: event.eventName,
|
|
206
|
+
bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
|
|
207
|
+
mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
|
|
208
|
+
amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
|
|
209
|
+
amountUi: event.amountUi ? Number(event.amountUi) : null,
|
|
210
|
+
value: event.value ? Number(event.value) : null,
|
|
211
|
+
price: event.price ? Number(event.price) : null,
|
|
212
|
+
closeBalance,
|
|
213
|
+
};
|
|
214
|
+
txSummary.events.push(clendAccountEvent);
|
|
216
215
|
}
|
|
217
|
-
|
|
218
|
-
const clendAccountAddress = new anchor_1.web3.PublicKey(accountAndSumary.clendAccount.key);
|
|
219
|
-
const clendAccount = {
|
|
220
|
-
key: clendAccountAddress,
|
|
221
|
-
group: new anchor_1.web3.PublicKey(ca.group),
|
|
222
|
-
balances: clendAccountBalances,
|
|
223
|
-
netValue: Number(ca.netValue),
|
|
224
|
-
netApy: Number(ca.netApy),
|
|
225
|
-
pnl: Number(ca.pnl),
|
|
226
|
-
totalAssetValue: Number(ca.totalAssetValue),
|
|
227
|
-
totalLiabilityValue: Number(ca.totalLiabilityValue),
|
|
228
|
-
healthFactorNotional: Number(ca.healthFactorNotional),
|
|
229
|
-
healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
|
|
230
|
-
notionalLeverage: Number(ca.notionalLeverage),
|
|
231
|
-
riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
|
|
232
|
-
notionalLtv: Number(ca.notionalLtv),
|
|
233
|
-
riskAdjustedLtv: Number(ca.riskAdjustedLtv),
|
|
234
|
-
};
|
|
235
|
-
// find corresponding tx summary for account
|
|
236
|
-
const summary = summaryByAccount.get(clendAccountAddress.toString()) || [];
|
|
237
|
-
clendAccounts.push({ clendAccount, summary });
|
|
216
|
+
summary.push(txSummary);
|
|
238
217
|
}
|
|
239
218
|
return {
|
|
240
219
|
wallet,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Get all groups
|
|
246
|
-
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
247
|
-
* @returns All groups
|
|
248
|
-
*/
|
|
249
|
-
async getGroups(includeBankData) {
|
|
250
|
-
const body = await handleApiCall(() => this.http.get(`/groups?includeBankData=${includeBankData}`));
|
|
251
|
-
const marketJson = JSON.parse(body);
|
|
252
|
-
const groups = [];
|
|
253
|
-
for (const groupJson of marketJson.groups) {
|
|
254
|
-
const group = new anchor_1.web3.PublicKey(groupJson.group);
|
|
255
|
-
const groupName = groupJson.groupName;
|
|
256
|
-
const banks = [];
|
|
257
|
-
for (const bankJson of groupJson.banks) {
|
|
258
|
-
const bank = parseBank(bankJson);
|
|
259
|
-
banks.push(bank);
|
|
260
|
-
}
|
|
261
|
-
groups.push({ group, groupName, banks });
|
|
262
|
-
}
|
|
263
|
-
const response = {
|
|
264
|
-
groups,
|
|
220
|
+
clendAccount,
|
|
221
|
+
summary,
|
|
265
222
|
};
|
|
266
|
-
return response;
|
|
267
223
|
}
|
|
268
224
|
/**
|
|
269
225
|
* Get market details
|
|
@@ -273,17 +229,13 @@ class Client {
|
|
|
273
229
|
async getGroup(groupAddress) {
|
|
274
230
|
const body = await handleApiCall(() => this.http.get(`/group?group=${groupAddress.toString()}`));
|
|
275
231
|
const marketJson = JSON.parse(body);
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
groupName: marketJson.group.groupName,
|
|
279
|
-
banks: [],
|
|
280
|
-
};
|
|
281
|
-
for (const bankJson of marketJson.group.banks) {
|
|
232
|
+
const banks = [];
|
|
233
|
+
for (const bankJson of marketJson.banks) {
|
|
282
234
|
const bank = parseBank(bankJson);
|
|
283
|
-
|
|
235
|
+
banks.push(bank);
|
|
284
236
|
}
|
|
285
237
|
const response = {
|
|
286
|
-
|
|
238
|
+
banks,
|
|
287
239
|
};
|
|
288
240
|
return response;
|
|
289
241
|
}
|
|
@@ -306,18 +258,15 @@ class Client {
|
|
|
306
258
|
* @param request Deposit leverage request parameters
|
|
307
259
|
* @returns Deposit leverage operation result
|
|
308
260
|
*/
|
|
309
|
-
async depositLeverage(
|
|
310
|
-
if (!
|
|
311
|
-
!inputTokenMint.equals(liabilityTokenMint)) {
|
|
261
|
+
async depositLeverage(inputMint, assetMint, liabilityMint, uiAmount, leverage, slippageBps) {
|
|
262
|
+
if (!inputMint.equals(assetMint) || !inputMint.equals(liabilityMint)) {
|
|
312
263
|
throw new Error("Input mint must be the same as the asset or liability mint");
|
|
313
264
|
}
|
|
314
265
|
const req = {
|
|
315
266
|
owner: this.address(),
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
assetTokenMint,
|
|
320
|
-
liabilityTokenMint,
|
|
267
|
+
inputMint,
|
|
268
|
+
assetMint,
|
|
269
|
+
liabilityMint,
|
|
321
270
|
depositAmountUi: uiAmount,
|
|
322
271
|
leverage,
|
|
323
272
|
slippageBps,
|
|
@@ -332,13 +281,9 @@ class Client {
|
|
|
332
281
|
* @param request Adjust leverage request parameters
|
|
333
282
|
* @returns Adjust leverage operation result
|
|
334
283
|
*/
|
|
335
|
-
async adjustLeverage(
|
|
284
|
+
async adjustLeverage(leverage, slippageBps) {
|
|
336
285
|
const req = {
|
|
337
286
|
owner: this.address(),
|
|
338
|
-
clendGroup,
|
|
339
|
-
clendAccount,
|
|
340
|
-
assetTokenMint,
|
|
341
|
-
liabilityTokenMint,
|
|
342
287
|
leverage,
|
|
343
288
|
slippageBps,
|
|
344
289
|
};
|
|
@@ -352,14 +297,10 @@ class Client {
|
|
|
352
297
|
* @param request Withdraw leverage request parameters
|
|
353
298
|
* @returns Withdraw leverage operation result
|
|
354
299
|
*/
|
|
355
|
-
async withdrawLeverage(
|
|
300
|
+
async withdrawLeverage(selectedTokenMint, uiAmount, slippageBps, withdrawAll) {
|
|
356
301
|
const req = {
|
|
357
302
|
owner: this.address(),
|
|
358
|
-
|
|
359
|
-
clendAccount,
|
|
360
|
-
outputTokenMint,
|
|
361
|
-
assetTokenMint,
|
|
362
|
-
liabilityTokenMint,
|
|
303
|
+
selectedTokenMint,
|
|
363
304
|
withdrawAmountUi: uiAmount,
|
|
364
305
|
slippageBps,
|
|
365
306
|
withdrawAll,
|
package/dist/types.d.ts
CHANGED
|
@@ -8,11 +8,9 @@ export interface SendRequest {
|
|
|
8
8
|
*/
|
|
9
9
|
export interface DepositLeverageRequest {
|
|
10
10
|
owner: web3.PublicKey;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
assetTokenMint: web3.PublicKey;
|
|
15
|
-
liabilityTokenMint: web3.PublicKey;
|
|
11
|
+
inputMint: web3.PublicKey;
|
|
12
|
+
assetMint: web3.PublicKey;
|
|
13
|
+
liabilityMint: web3.PublicKey;
|
|
16
14
|
depositAmountUi: number;
|
|
17
15
|
leverage: number;
|
|
18
16
|
slippageBps: number;
|
|
@@ -29,10 +27,6 @@ export interface DepositLeverageResponse {
|
|
|
29
27
|
*/
|
|
30
28
|
export interface AdjustLeverageRequest {
|
|
31
29
|
owner: web3.PublicKey;
|
|
32
|
-
clendGroup: web3.PublicKey;
|
|
33
|
-
clendAccount: web3.PublicKey;
|
|
34
|
-
assetTokenMint: web3.PublicKey;
|
|
35
|
-
liabilityTokenMint: web3.PublicKey;
|
|
36
30
|
leverage: number;
|
|
37
31
|
slippageBps: number;
|
|
38
32
|
}
|
|
@@ -48,11 +42,7 @@ export interface AdjustLeverageResponse {
|
|
|
48
42
|
*/
|
|
49
43
|
export interface WithdrawLeverageRequest {
|
|
50
44
|
owner: web3.PublicKey;
|
|
51
|
-
|
|
52
|
-
clendAccount: web3.PublicKey;
|
|
53
|
-
outputTokenMint: web3.PublicKey;
|
|
54
|
-
assetTokenMint: web3.PublicKey;
|
|
55
|
-
liabilityTokenMint: web3.PublicKey;
|
|
45
|
+
selectedTokenMint: web3.PublicKey;
|
|
56
46
|
withdrawAmountUi: number;
|
|
57
47
|
slippageBps: number;
|
|
58
48
|
withdrawAll: boolean;
|
|
@@ -64,41 +54,28 @@ export interface WithdrawLeverageResponse {
|
|
|
64
54
|
userRequestId: string;
|
|
65
55
|
unsignedBase64Tx: string;
|
|
66
56
|
}
|
|
67
|
-
export interface GetGroupsResponse {
|
|
68
|
-
groups: GroupAndBanks[];
|
|
69
|
-
}
|
|
70
57
|
export interface GetGroupResponse {
|
|
71
|
-
group: GroupAndBanks;
|
|
72
|
-
}
|
|
73
|
-
export interface GroupAndBanks {
|
|
74
|
-
group: web3.PublicKey;
|
|
75
|
-
groupName: string;
|
|
76
58
|
banks: Bank[];
|
|
77
59
|
}
|
|
78
60
|
export interface GetUserRequest {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
getClendAccountSummary: boolean;
|
|
61
|
+
user?: web3.PublicKey;
|
|
62
|
+
getClendAccountSummary?: boolean;
|
|
82
63
|
}
|
|
83
64
|
export interface GetUserResponse {
|
|
84
65
|
wallet: UserWallet;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
summary: ClendAccountTxSummary[];
|
|
88
|
-
}[];
|
|
66
|
+
clendAccount: ClendAccount | undefined;
|
|
67
|
+
summary: ClendAccountTxSummary[];
|
|
89
68
|
}
|
|
90
69
|
export interface UserWallet {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
70
|
+
usdcBalance: BN;
|
|
71
|
+
usdcBalanceUi: number;
|
|
72
|
+
jlpBalance: BN;
|
|
73
|
+
jlpBalanceUi: number;
|
|
74
|
+
solBalance: BN;
|
|
75
|
+
solBalanceUi: number;
|
|
97
76
|
}
|
|
98
77
|
export interface ClendAccount {
|
|
99
|
-
|
|
100
|
-
group: web3.PublicKey;
|
|
101
|
-
balances: ClendAccountBalance[];
|
|
78
|
+
balances: Balance[];
|
|
102
79
|
netValue: number;
|
|
103
80
|
netApy: number;
|
|
104
81
|
pnl: number;
|
|
@@ -108,28 +85,21 @@ export interface ClendAccount {
|
|
|
108
85
|
healthFactorRiskAdjusted: number;
|
|
109
86
|
notionalLeverage: number;
|
|
110
87
|
riskAdjustedLeverage: number;
|
|
88
|
+
liquidationPrice: number;
|
|
89
|
+
liquidationPriceChangePercentage: number;
|
|
111
90
|
notionalLtv: number;
|
|
112
91
|
riskAdjustedLtv: number;
|
|
113
92
|
}
|
|
114
|
-
export interface
|
|
93
|
+
export interface Balance {
|
|
115
94
|
mint: web3.PublicKey;
|
|
116
95
|
bank: web3.PublicKey;
|
|
117
96
|
assetBalance: BN;
|
|
118
97
|
assetBalanceUi: number;
|
|
119
98
|
assetValue: number;
|
|
120
|
-
assetYieldBps: number;
|
|
121
|
-
assetYieldApy: number;
|
|
122
99
|
liabilityBalance: BN;
|
|
123
100
|
liabilityBalanceUi: number;
|
|
124
101
|
liabilityValue: number;
|
|
125
|
-
liabilityBorrowCostBps: number;
|
|
126
|
-
liabilityBorrowCostApy: number;
|
|
127
|
-
price: number;
|
|
128
|
-
liquidation: ClendAccountAssetLiquidation | null;
|
|
129
|
-
}
|
|
130
|
-
export interface ClendAccountAssetLiquidation {
|
|
131
102
|
price: number;
|
|
132
|
-
changePercentage: number;
|
|
133
103
|
}
|
|
134
104
|
export interface GetBankResponse {
|
|
135
105
|
bank: Bank;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carrot-protocol/boost-http-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.16-group-refactor1-dev-50c976e",
|
|
4
4
|
"description": "HTTP client for Carrot Boost",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@coral-xyz/anchor": "^0.29.0",
|
|
17
|
-
"@carrot-protocol/clend-common": "0.1.
|
|
17
|
+
"@carrot-protocol/clend-common": "0.1.7",
|
|
18
18
|
"axios": "^1.8.3",
|
|
19
19
|
"bs58": "^6.0.0",
|
|
20
20
|
"decimal.js": "^10.5.0"
|
package/src/index.ts
CHANGED
|
@@ -12,17 +12,13 @@ import {
|
|
|
12
12
|
WithdrawLeverageResponse,
|
|
13
13
|
UserWallet,
|
|
14
14
|
ClendAccount,
|
|
15
|
-
|
|
15
|
+
Balance,
|
|
16
16
|
Bank,
|
|
17
17
|
GetGroupResponse,
|
|
18
18
|
ClendAccountEvent,
|
|
19
19
|
GetUserRequest,
|
|
20
20
|
ClendAccountTxSummary,
|
|
21
21
|
UserRequest,
|
|
22
|
-
UserBalance,
|
|
23
|
-
ClendAccountAssetLiquidation,
|
|
24
|
-
GetGroupsResponse,
|
|
25
|
-
GroupAndBanks,
|
|
26
22
|
} from "./types";
|
|
27
23
|
import encode from "bs58";
|
|
28
24
|
|
|
@@ -107,200 +103,147 @@ export class Client {
|
|
|
107
103
|
* @param user wallet public key
|
|
108
104
|
* @returns User details
|
|
109
105
|
*/
|
|
110
|
-
async getUser(
|
|
111
|
-
|
|
112
|
-
user
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
async getUser(request: GetUserRequest): Promise<GetUserResponse> {
|
|
107
|
+
// use loaded wallet if not provided
|
|
108
|
+
let user = request.user;
|
|
109
|
+
if (!user) {
|
|
110
|
+
user = this.address();
|
|
111
|
+
}
|
|
112
|
+
|
|
115
113
|
const body = await handleApiCall(() =>
|
|
116
114
|
this.http.get(
|
|
117
|
-
`/user?user=${user.toString()}&
|
|
115
|
+
`/user?user=${user.toString()}&getClendAccountSummary=${request.getClendAccountSummary}`,
|
|
118
116
|
),
|
|
119
117
|
);
|
|
120
118
|
|
|
121
119
|
const jsonRawResponse: any = JSON.parse(body);
|
|
122
|
-
console.log(JSON.stringify(jsonRawResponse, null, 2));
|
|
123
120
|
|
|
124
|
-
//
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
// get tokens still in user wallet
|
|
122
|
+
const wallet: UserWallet = {
|
|
123
|
+
usdcBalance: new BN(jsonRawResponse.wallet.usdcBalance, "hex"),
|
|
124
|
+
usdcBalanceUi: Number(jsonRawResponse.wallet.usdcBalanceUi),
|
|
125
|
+
jlpBalance: new BN(jsonRawResponse.wallet.jlpBalance, "hex"),
|
|
126
|
+
jlpBalanceUi: Number(jsonRawResponse.wallet.jlpBalanceUi),
|
|
127
|
+
solBalance: new BN(jsonRawResponse.wallet.solBalance, "hex"),
|
|
128
|
+
solBalanceUi: Number(jsonRawResponse.wallet.solBalanceUi),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// if no clend account, return undefined for clend
|
|
132
|
+
if (!jsonRawResponse.clendAccount) {
|
|
133
|
+
return {
|
|
134
|
+
wallet,
|
|
135
|
+
clendAccount: undefined,
|
|
136
|
+
summary: [],
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// parse lending account balances
|
|
141
|
+
const balances: Balance[] = [];
|
|
142
|
+
for (const b of jsonRawResponse.clendAccount.balances) {
|
|
143
|
+
balances.push({
|
|
128
144
|
mint: new web3.PublicKey(b.mint),
|
|
129
|
-
|
|
130
|
-
|
|
145
|
+
bank: new web3.PublicKey(b.bank),
|
|
146
|
+
assetBalance: new BN(b.assetBalance, "hex"),
|
|
147
|
+
assetBalanceUi: Number(b.assetBalanceUi),
|
|
148
|
+
assetValue: Number(b.assetValue),
|
|
149
|
+
liabilityBalance: new BN(b.liabilityBalance, "hex"),
|
|
150
|
+
liabilityBalanceUi: Number(b.liabilityBalanceUi),
|
|
151
|
+
liabilityValue: Number(b.liabilityValue),
|
|
152
|
+
price: Number(b.price),
|
|
131
153
|
});
|
|
132
154
|
}
|
|
133
155
|
|
|
134
|
-
//
|
|
135
|
-
const
|
|
136
|
-
balances
|
|
156
|
+
// create clend account
|
|
157
|
+
const clendAccount: ClendAccount = {
|
|
158
|
+
balances,
|
|
159
|
+
netValue: Number(jsonRawResponse.clendAccount.netValue),
|
|
160
|
+
netApy: Number(jsonRawResponse.clendAccount.netApy),
|
|
161
|
+
pnl: Number(jsonRawResponse.clendAccount.pnl),
|
|
162
|
+
totalAssetValue: Number(jsonRawResponse.clendAccount.totalAssetValue),
|
|
163
|
+
totalLiabilityValue: Number(
|
|
164
|
+
jsonRawResponse.clendAccount.totalLiabilityValue,
|
|
165
|
+
),
|
|
166
|
+
healthFactorNotional: Number(
|
|
167
|
+
jsonRawResponse.clendAccount.healthFactorNotional,
|
|
168
|
+
),
|
|
169
|
+
healthFactorRiskAdjusted: Number(
|
|
170
|
+
jsonRawResponse.clendAccount.healthFactorRiskAdjusted,
|
|
171
|
+
),
|
|
172
|
+
notionalLeverage: Number(jsonRawResponse.clendAccount.notionalLeverage),
|
|
173
|
+
riskAdjustedLeverage: Number(
|
|
174
|
+
jsonRawResponse.clendAccount.riskAdjustedLeverage,
|
|
175
|
+
),
|
|
176
|
+
liquidationPrice: Number(jsonRawResponse.clendAccount.liquidationPrice),
|
|
177
|
+
liquidationPriceChangePercentage: Number(
|
|
178
|
+
jsonRawResponse.clendAccount.liquidationPriceChangePercentage,
|
|
179
|
+
),
|
|
180
|
+
notionalLtv: Number(jsonRawResponse.clendAccount.notionalLtv),
|
|
181
|
+
riskAdjustedLtv: Number(jsonRawResponse.clendAccount.riskAdjustedLtv),
|
|
137
182
|
};
|
|
138
183
|
|
|
139
|
-
// get tx summary for each account
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
184
|
+
// get tx summary for each account
|
|
185
|
+
const summary: ClendAccountTxSummary[] = [];
|
|
186
|
+
for (const s of jsonRawResponse.summary) {
|
|
187
|
+
const txSummary: ClendAccountTxSummary = {
|
|
188
|
+
txSig: s.txSig,
|
|
189
|
+
time: s.time,
|
|
190
|
+
clendAccount: new web3.PublicKey(s.clendAccount),
|
|
191
|
+
clendAccountAuthority: new web3.PublicKey(s.clendAccountAuthority),
|
|
192
|
+
clendGroup: new web3.PublicKey(s.clendGroup),
|
|
193
|
+
action: s.action,
|
|
194
|
+
input: undefined,
|
|
195
|
+
events: [],
|
|
196
|
+
};
|
|
147
197
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
input:
|
|
156
|
-
|
|
198
|
+
// parse inputs if they exist
|
|
199
|
+
if (s.input) {
|
|
200
|
+
const input: UserRequest = {
|
|
201
|
+
apiPath: s.input.apiPath,
|
|
202
|
+
selectedTokenMint: s.input.selectedTokenMint
|
|
203
|
+
? new web3.PublicKey(s.input.selectedTokenMint)
|
|
204
|
+
: null,
|
|
205
|
+
amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
|
|
206
|
+
leverage: s.input.leverage ? Number(s.input.leverage) : null,
|
|
207
|
+
slippageBps: s.input.slippageBps ? Number(s.input.slippageBps) : null,
|
|
208
|
+
openPosition: s.input.openPosition
|
|
209
|
+
? Boolean(s.input.openPosition)
|
|
210
|
+
: null,
|
|
211
|
+
closePosition: s.input.closePosition
|
|
212
|
+
? Boolean(s.input.closePosition)
|
|
213
|
+
: null,
|
|
157
214
|
};
|
|
215
|
+
txSummary.input = input;
|
|
216
|
+
}
|
|
158
217
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
? new web3.PublicKey(s.input.selectedTokenMint)
|
|
165
|
-
: null,
|
|
166
|
-
amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
|
|
167
|
-
leverage: s.input.leverage ? Number(s.input.leverage) : null,
|
|
168
|
-
slippageBps: s.input.slippageBps
|
|
169
|
-
? Number(s.input.slippageBps)
|
|
170
|
-
: null,
|
|
171
|
-
openPosition: s.input.openPosition
|
|
172
|
-
? Boolean(s.input.openPosition)
|
|
173
|
-
: null,
|
|
174
|
-
closePosition: s.input.closePosition
|
|
175
|
-
? Boolean(s.input.closePosition)
|
|
176
|
-
: null,
|
|
177
|
-
};
|
|
178
|
-
txSummary.input = input;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// get events for each summary
|
|
182
|
-
for (const event of s.events) {
|
|
183
|
-
let closeBalance: boolean | null = null;
|
|
184
|
-
if (event.closeBalance !== null) {
|
|
185
|
-
closeBalance = Boolean(event.closeBalance);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// parse amount
|
|
189
|
-
const clendAccountEvent: ClendAccountEvent = {
|
|
190
|
-
eventIndex: event.eventIndex,
|
|
191
|
-
eventName: event.eventName,
|
|
192
|
-
bank: event.bank ? new web3.PublicKey(event.bank) : null,
|
|
193
|
-
mint: event.mint ? new web3.PublicKey(event.mint) : null,
|
|
194
|
-
amount: event.amount ? new BN(event.amount, "hex") : null,
|
|
195
|
-
amountUi: event.amountUi ? Number(event.amountUi) : null,
|
|
196
|
-
value: event.value ? Number(event.value) : null,
|
|
197
|
-
price: event.price ? Number(event.price) : null,
|
|
198
|
-
closeBalance,
|
|
199
|
-
};
|
|
200
|
-
txSummary.events.push(clendAccountEvent);
|
|
218
|
+
// get events for each summary
|
|
219
|
+
for (const event of s.events) {
|
|
220
|
+
let closeBalance: boolean | null = null;
|
|
221
|
+
if (event.closeBalance !== null) {
|
|
222
|
+
closeBalance = Boolean(event.closeBalance);
|
|
201
223
|
}
|
|
202
224
|
|
|
203
|
-
|
|
225
|
+
// parse amount
|
|
226
|
+
const clendAccountEvent: ClendAccountEvent = {
|
|
227
|
+
eventIndex: event.eventIndex,
|
|
228
|
+
eventName: event.eventName,
|
|
229
|
+
bank: event.bank ? new web3.PublicKey(event.bank) : null,
|
|
230
|
+
mint: event.mint ? new web3.PublicKey(event.mint) : null,
|
|
231
|
+
amount: event.amount ? new BN(event.amount, "hex") : null,
|
|
232
|
+
amountUi: event.amountUi ? Number(event.amountUi) : null,
|
|
233
|
+
value: event.value ? Number(event.value) : null,
|
|
234
|
+
price: event.price ? Number(event.price) : null,
|
|
235
|
+
closeBalance,
|
|
236
|
+
};
|
|
237
|
+
txSummary.events.push(clendAccountEvent);
|
|
204
238
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// if no clend accounts, return empty array
|
|
208
|
-
const clendAccounts: {
|
|
209
|
-
clendAccount: ClendAccount;
|
|
210
|
-
summary: ClendAccountTxSummary[];
|
|
211
|
-
}[] = [];
|
|
212
|
-
for (const accountAndSumary of jsonRawResponse.clendAccounts) {
|
|
213
|
-
const clendAccountBalances: ClendAccountBalance[] = [];
|
|
214
|
-
const ca = accountAndSumary.clendAccount;
|
|
215
|
-
for (const b of ca.balances) {
|
|
216
|
-
// parse liquidation data if exists
|
|
217
|
-
const liquidation: ClendAccountAssetLiquidation | null = b.liquidation
|
|
218
|
-
? {
|
|
219
|
-
price: Number(b.liquidation.price),
|
|
220
|
-
changePercentage: Number(b.liquidation.changePercentage),
|
|
221
|
-
}
|
|
222
|
-
: null;
|
|
223
|
-
|
|
224
|
-
// create clend account balance
|
|
225
|
-
clendAccountBalances.push({
|
|
226
|
-
mint: new web3.PublicKey(b.mint),
|
|
227
|
-
bank: new web3.PublicKey(b.bank),
|
|
228
|
-
assetBalance: new BN(b.assetBalance, "hex"),
|
|
229
|
-
assetBalanceUi: Number(b.assetBalanceUi),
|
|
230
|
-
assetValue: Number(b.assetValue),
|
|
231
|
-
assetYieldBps: Number(b.assetYieldBps),
|
|
232
|
-
assetYieldApy: Number(b.assetYieldApy),
|
|
233
|
-
liabilityBalance: new BN(b.liabilityBalance, "hex"),
|
|
234
|
-
liabilityBalanceUi: Number(b.liabilityBalanceUi),
|
|
235
|
-
liabilityValue: Number(b.liabilityValue),
|
|
236
|
-
liabilityBorrowCostBps: Number(b.liabilityBorrowCostBps),
|
|
237
|
-
liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
|
|
238
|
-
price: Number(b.price),
|
|
239
|
-
liquidation,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// create clend account
|
|
244
|
-
const clendAccountAddress = new web3.PublicKey(
|
|
245
|
-
accountAndSumary.clendAccount.key,
|
|
246
|
-
);
|
|
247
|
-
const clendAccount: ClendAccount = {
|
|
248
|
-
key: clendAccountAddress,
|
|
249
|
-
group: new web3.PublicKey(ca.group),
|
|
250
|
-
balances: clendAccountBalances,
|
|
251
|
-
netValue: Number(ca.netValue),
|
|
252
|
-
netApy: Number(ca.netApy),
|
|
253
|
-
pnl: Number(ca.pnl),
|
|
254
|
-
totalAssetValue: Number(ca.totalAssetValue),
|
|
255
|
-
totalLiabilityValue: Number(ca.totalLiabilityValue),
|
|
256
|
-
healthFactorNotional: Number(ca.healthFactorNotional),
|
|
257
|
-
healthFactorRiskAdjusted: Number(ca.healthFactorRiskAdjusted),
|
|
258
|
-
notionalLeverage: Number(ca.notionalLeverage),
|
|
259
|
-
riskAdjustedLeverage: Number(ca.riskAdjustedLeverage),
|
|
260
|
-
notionalLtv: Number(ca.notionalLtv),
|
|
261
|
-
riskAdjustedLtv: Number(ca.riskAdjustedLtv),
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
// find corresponding tx summary for account
|
|
265
|
-
const summary =
|
|
266
|
-
summaryByAccount.get(clendAccountAddress.toString()) || [];
|
|
267
|
-
clendAccounts.push({ clendAccount, summary });
|
|
239
|
+
summary.push(txSummary);
|
|
268
240
|
}
|
|
269
241
|
|
|
270
242
|
return {
|
|
271
243
|
wallet,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Get all groups
|
|
278
|
-
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
279
|
-
* @returns All groups
|
|
280
|
-
*/
|
|
281
|
-
async getGroups(includeBankData: boolean): Promise<GetGroupsResponse> {
|
|
282
|
-
const body = await handleApiCall(() =>
|
|
283
|
-
this.http.get(`/groups?includeBankData=${includeBankData}`),
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
const marketJson: any = JSON.parse(body);
|
|
287
|
-
const groups: GroupAndBanks[] = [];
|
|
288
|
-
for (const groupJson of marketJson.groups) {
|
|
289
|
-
const group: web3.PublicKey = new web3.PublicKey(groupJson.group);
|
|
290
|
-
const groupName = groupJson.groupName;
|
|
291
|
-
const banks: Bank[] = [];
|
|
292
|
-
for (const bankJson of groupJson.banks) {
|
|
293
|
-
const bank = parseBank(bankJson);
|
|
294
|
-
banks.push(bank);
|
|
295
|
-
}
|
|
296
|
-
groups.push({ group, groupName, banks });
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const response: GetGroupsResponse = {
|
|
300
|
-
groups,
|
|
244
|
+
clendAccount,
|
|
245
|
+
summary,
|
|
301
246
|
};
|
|
302
|
-
|
|
303
|
-
return response;
|
|
304
247
|
}
|
|
305
248
|
|
|
306
249
|
/**
|
|
@@ -314,18 +257,14 @@ export class Client {
|
|
|
314
257
|
);
|
|
315
258
|
|
|
316
259
|
const marketJson: any = JSON.parse(body);
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
groupName: marketJson.group.groupName,
|
|
320
|
-
banks: [],
|
|
321
|
-
};
|
|
322
|
-
for (const bankJson of marketJson.group.banks) {
|
|
260
|
+
const banks: Bank[] = [];
|
|
261
|
+
for (const bankJson of marketJson.banks) {
|
|
323
262
|
const bank = parseBank(bankJson);
|
|
324
|
-
|
|
263
|
+
banks.push(bank);
|
|
325
264
|
}
|
|
326
265
|
|
|
327
266
|
const response: GetGroupResponse = {
|
|
328
|
-
|
|
267
|
+
banks,
|
|
329
268
|
};
|
|
330
269
|
|
|
331
270
|
return response;
|
|
@@ -357,19 +296,14 @@ export class Client {
|
|
|
357
296
|
* @returns Deposit leverage operation result
|
|
358
297
|
*/
|
|
359
298
|
async depositLeverage(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
assetTokenMint: web3.PublicKey,
|
|
364
|
-
liabilityTokenMint: web3.PublicKey,
|
|
299
|
+
inputMint: web3.PublicKey,
|
|
300
|
+
assetMint: web3.PublicKey,
|
|
301
|
+
liabilityMint: web3.PublicKey,
|
|
365
302
|
uiAmount: number,
|
|
366
303
|
leverage: number,
|
|
367
304
|
slippageBps: number,
|
|
368
305
|
): Promise<string> {
|
|
369
|
-
if (
|
|
370
|
-
!inputTokenMint.equals(assetTokenMint) &&
|
|
371
|
-
!inputTokenMint.equals(liabilityTokenMint)
|
|
372
|
-
) {
|
|
306
|
+
if (!inputMint.equals(assetMint) || !inputMint.equals(liabilityMint)) {
|
|
373
307
|
throw new Error(
|
|
374
308
|
"Input mint must be the same as the asset or liability mint",
|
|
375
309
|
);
|
|
@@ -377,11 +311,9 @@ export class Client {
|
|
|
377
311
|
|
|
378
312
|
const req: DepositLeverageRequest = {
|
|
379
313
|
owner: this.address(),
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
assetTokenMint,
|
|
384
|
-
liabilityTokenMint,
|
|
314
|
+
inputMint,
|
|
315
|
+
assetMint,
|
|
316
|
+
liabilityMint,
|
|
385
317
|
depositAmountUi: uiAmount,
|
|
386
318
|
leverage,
|
|
387
319
|
slippageBps,
|
|
@@ -405,20 +337,9 @@ export class Client {
|
|
|
405
337
|
* @param request Adjust leverage request parameters
|
|
406
338
|
* @returns Adjust leverage operation result
|
|
407
339
|
*/
|
|
408
|
-
async adjustLeverage(
|
|
409
|
-
clendGroup: web3.PublicKey,
|
|
410
|
-
clendAccount: web3.PublicKey,
|
|
411
|
-
assetTokenMint: web3.PublicKey,
|
|
412
|
-
liabilityTokenMint: web3.PublicKey,
|
|
413
|
-
leverage: number,
|
|
414
|
-
slippageBps: number,
|
|
415
|
-
): Promise<any> {
|
|
340
|
+
async adjustLeverage(leverage: number, slippageBps: number): Promise<any> {
|
|
416
341
|
const req: AdjustLeverageRequest = {
|
|
417
342
|
owner: this.address(),
|
|
418
|
-
clendGroup,
|
|
419
|
-
clendAccount,
|
|
420
|
-
assetTokenMint,
|
|
421
|
-
liabilityTokenMint,
|
|
422
343
|
leverage,
|
|
423
344
|
slippageBps,
|
|
424
345
|
};
|
|
@@ -442,22 +363,14 @@ export class Client {
|
|
|
442
363
|
* @returns Withdraw leverage operation result
|
|
443
364
|
*/
|
|
444
365
|
async withdrawLeverage(
|
|
445
|
-
|
|
446
|
-
clendAccount: web3.PublicKey,
|
|
447
|
-
outputTokenMint: web3.PublicKey,
|
|
448
|
-
assetTokenMint: web3.PublicKey,
|
|
449
|
-
liabilityTokenMint: web3.PublicKey,
|
|
366
|
+
selectedTokenMint: web3.PublicKey,
|
|
450
367
|
uiAmount: number,
|
|
451
368
|
slippageBps: number,
|
|
452
369
|
withdrawAll: boolean,
|
|
453
370
|
): Promise<any> {
|
|
454
371
|
const req: WithdrawLeverageRequest = {
|
|
455
372
|
owner: this.address(),
|
|
456
|
-
|
|
457
|
-
clendAccount,
|
|
458
|
-
outputTokenMint,
|
|
459
|
-
assetTokenMint,
|
|
460
|
-
liabilityTokenMint,
|
|
373
|
+
selectedTokenMint,
|
|
461
374
|
withdrawAmountUi: uiAmount,
|
|
462
375
|
slippageBps,
|
|
463
376
|
withdrawAll,
|
package/src/types.ts
CHANGED
|
@@ -11,11 +11,9 @@ export interface SendRequest {
|
|
|
11
11
|
*/
|
|
12
12
|
export interface DepositLeverageRequest {
|
|
13
13
|
owner: web3.PublicKey;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
assetTokenMint: web3.PublicKey;
|
|
18
|
-
liabilityTokenMint: web3.PublicKey;
|
|
14
|
+
inputMint: web3.PublicKey;
|
|
15
|
+
assetMint: web3.PublicKey;
|
|
16
|
+
liabilityMint: web3.PublicKey;
|
|
19
17
|
depositAmountUi: number;
|
|
20
18
|
leverage: number;
|
|
21
19
|
slippageBps: number;
|
|
@@ -34,10 +32,6 @@ export interface DepositLeverageResponse {
|
|
|
34
32
|
*/
|
|
35
33
|
export interface AdjustLeverageRequest {
|
|
36
34
|
owner: web3.PublicKey;
|
|
37
|
-
clendGroup: web3.PublicKey;
|
|
38
|
-
clendAccount: web3.PublicKey;
|
|
39
|
-
assetTokenMint: web3.PublicKey;
|
|
40
|
-
liabilityTokenMint: web3.PublicKey;
|
|
41
35
|
leverage: number;
|
|
42
36
|
slippageBps: number;
|
|
43
37
|
}
|
|
@@ -55,11 +49,7 @@ export interface AdjustLeverageResponse {
|
|
|
55
49
|
*/
|
|
56
50
|
export interface WithdrawLeverageRequest {
|
|
57
51
|
owner: web3.PublicKey;
|
|
58
|
-
|
|
59
|
-
clendAccount: web3.PublicKey;
|
|
60
|
-
outputTokenMint: web3.PublicKey;
|
|
61
|
-
assetTokenMint: web3.PublicKey;
|
|
62
|
-
liabilityTokenMint: web3.PublicKey;
|
|
52
|
+
selectedTokenMint: web3.PublicKey;
|
|
63
53
|
withdrawAmountUi: number;
|
|
64
54
|
slippageBps: number;
|
|
65
55
|
withdrawAll: boolean;
|
|
@@ -73,48 +63,32 @@ export interface WithdrawLeverageResponse {
|
|
|
73
63
|
unsignedBase64Tx: string;
|
|
74
64
|
}
|
|
75
65
|
|
|
76
|
-
export interface GetGroupsResponse {
|
|
77
|
-
groups: GroupAndBanks[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
66
|
export interface GetGroupResponse {
|
|
81
|
-
group: GroupAndBanks;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface GroupAndBanks {
|
|
85
|
-
group: web3.PublicKey;
|
|
86
|
-
groupName: string;
|
|
87
67
|
banks: Bank[];
|
|
88
68
|
}
|
|
89
69
|
|
|
90
70
|
export interface GetUserRequest {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
getClendAccountSummary: boolean;
|
|
71
|
+
user?: web3.PublicKey;
|
|
72
|
+
getClendAccountSummary?: boolean;
|
|
94
73
|
}
|
|
95
74
|
|
|
96
75
|
export interface GetUserResponse {
|
|
97
76
|
wallet: UserWallet;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
summary: ClendAccountTxSummary[];
|
|
101
|
-
}[];
|
|
77
|
+
clendAccount: ClendAccount | undefined;
|
|
78
|
+
summary: ClendAccountTxSummary[];
|
|
102
79
|
}
|
|
103
80
|
|
|
104
81
|
export interface UserWallet {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
balanceUi: number;
|
|
82
|
+
usdcBalance: BN;
|
|
83
|
+
usdcBalanceUi: number;
|
|
84
|
+
jlpBalance: BN;
|
|
85
|
+
jlpBalanceUi: number;
|
|
86
|
+
solBalance: BN;
|
|
87
|
+
solBalanceUi: number;
|
|
112
88
|
}
|
|
113
89
|
|
|
114
90
|
export interface ClendAccount {
|
|
115
|
-
|
|
116
|
-
group: web3.PublicKey;
|
|
117
|
-
balances: ClendAccountBalance[];
|
|
91
|
+
balances: Balance[];
|
|
118
92
|
netValue: number;
|
|
119
93
|
netApy: number;
|
|
120
94
|
pnl: number;
|
|
@@ -124,30 +98,22 @@ export interface ClendAccount {
|
|
|
124
98
|
healthFactorRiskAdjusted: number;
|
|
125
99
|
notionalLeverage: number;
|
|
126
100
|
riskAdjustedLeverage: number;
|
|
101
|
+
liquidationPrice: number;
|
|
102
|
+
liquidationPriceChangePercentage: number;
|
|
127
103
|
notionalLtv: number;
|
|
128
104
|
riskAdjustedLtv: number;
|
|
129
105
|
}
|
|
130
106
|
|
|
131
|
-
export interface
|
|
107
|
+
export interface Balance {
|
|
132
108
|
mint: web3.PublicKey;
|
|
133
109
|
bank: web3.PublicKey;
|
|
134
110
|
assetBalance: BN;
|
|
135
111
|
assetBalanceUi: number;
|
|
136
112
|
assetValue: number;
|
|
137
|
-
assetYieldBps: number;
|
|
138
|
-
assetYieldApy: number;
|
|
139
113
|
liabilityBalance: BN;
|
|
140
114
|
liabilityBalanceUi: number;
|
|
141
115
|
liabilityValue: number;
|
|
142
|
-
liabilityBorrowCostBps: number;
|
|
143
|
-
liabilityBorrowCostApy: number;
|
|
144
|
-
price: number;
|
|
145
|
-
liquidation: ClendAccountAssetLiquidation | null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface ClendAccountAssetLiquidation {
|
|
149
116
|
price: number;
|
|
150
|
-
changePercentage: number;
|
|
151
117
|
}
|
|
152
118
|
|
|
153
119
|
export interface GetBankResponse {
|