@carrot-protocol/boost-http-client 0.2.16-group-refactor1-dev-50c976e → 0.2.16-token22-dev-998073e
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 +16 -8
- package/dist/index.js +219 -134
- package/dist/types.d.ts +99 -20
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -9
- package/package.json +2 -2
- package/src/index.ts +327 -155
- package/src/types.ts +115 -21
- package/src/utils.ts +0 -8
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, GetGroupsResponse } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export * from "./utils";
|
|
5
5
|
export * as Common from "@carrot-protocol/clend-common";
|
|
@@ -22,12 +22,13 @@ export declare class Client {
|
|
|
22
22
|
* @returns Index details
|
|
23
23
|
*/
|
|
24
24
|
index(): Promise<any>;
|
|
25
|
+
getUser(user: web3.PublicKey, groups: web3.PublicKey[], getClendAccountSummary: boolean): Promise<GetUserResponse>;
|
|
25
26
|
/**
|
|
26
|
-
* Get
|
|
27
|
-
* @param
|
|
28
|
-
* @returns
|
|
27
|
+
* Get all groups
|
|
28
|
+
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
29
|
+
* @returns All groups
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
getGroups(includeBankData: boolean): Promise<GetGroupsResponse>;
|
|
31
32
|
/**
|
|
32
33
|
* Get market details
|
|
33
34
|
* @param groupAddress group public key
|
|
@@ -40,22 +41,29 @@ export declare class Client {
|
|
|
40
41
|
* @returns Bank details
|
|
41
42
|
*/
|
|
42
43
|
getBank(bankAddress: web3.PublicKey): Promise<GetBankResponse>;
|
|
44
|
+
deposit(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, uiAmount: number): Promise<string>;
|
|
45
|
+
withdraw(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, uiAmount: number): Promise<string>;
|
|
43
46
|
/**
|
|
44
47
|
* Deposit collateral and create a leveraged position
|
|
45
48
|
* @param request Deposit leverage request parameters
|
|
46
49
|
* @returns Deposit leverage operation result
|
|
47
50
|
*/
|
|
48
|
-
depositLeverage(
|
|
51
|
+
depositLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number): Promise<string>;
|
|
49
52
|
/**
|
|
50
53
|
* Adjust the leverage of an existing position
|
|
51
54
|
* @param request Adjust leverage request parameters
|
|
52
55
|
* @returns Adjust leverage operation result
|
|
53
56
|
*/
|
|
54
|
-
adjustLeverage(leverage: number, slippageBps: number): Promise<
|
|
57
|
+
adjustLeverage(clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<string>;
|
|
55
58
|
/**
|
|
56
59
|
* Withdraw from or close a leveraged position
|
|
57
60
|
* @param request Withdraw leverage request parameters
|
|
58
61
|
* @returns Withdraw leverage operation result
|
|
59
62
|
*/
|
|
60
|
-
withdrawLeverage(
|
|
63
|
+
withdrawLeverage(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Withdraw emissions from a bank
|
|
66
|
+
* @returns Withdraw emissions operation result
|
|
67
|
+
*/
|
|
68
|
+
withdrawEmissions(): Promise<string>;
|
|
61
69
|
}
|
package/dist/index.js
CHANGED
|
@@ -99,128 +99,160 @@ class Client {
|
|
|
99
99
|
async index() {
|
|
100
100
|
return handleApiCall(() => this.http.get(""));
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*/
|
|
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}`));
|
|
102
|
+
async getUser(user, groups, getClendAccountSummary) {
|
|
103
|
+
// Make the API call to fetch the raw user data as a string.
|
|
104
|
+
const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&groups=${groups.map((g) => g.toString()).join(",")}&getClendAccountSummary=${getClendAccountSummary}`));
|
|
105
|
+
// Parse the raw string body into a JSON object.
|
|
114
106
|
const jsonRawResponse = JSON.parse(body);
|
|
115
|
-
//
|
|
107
|
+
// 1. Parse Wallet Balances
|
|
108
|
+
// This section correctly iterates through the wallet balances and creates typed objects.
|
|
109
|
+
const walletBalances = (jsonRawResponse.wallet.balances || []).map((b) => ({
|
|
110
|
+
mint: new anchor_1.web3.PublicKey(b.mint),
|
|
111
|
+
balance: new anchor_1.BN(b.balance, "hex"),
|
|
112
|
+
balanceUi: Number(b.balanceUi),
|
|
113
|
+
}));
|
|
116
114
|
const wallet = {
|
|
117
|
-
|
|
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),
|
|
115
|
+
balances: walletBalances,
|
|
123
116
|
};
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
117
|
+
// 2. Parse Clend Accounts and their Summaries
|
|
118
|
+
// This is the main refactored section. It iterates through the clendAccounts array
|
|
119
|
+
// from the response, which contains both the account data and its summary.
|
|
120
|
+
const clendAccounts = (jsonRawResponse.clendAccounts || []).map((accountData) => {
|
|
121
|
+
// A. Parse the main ClendAccount object
|
|
122
|
+
const rawClendAccount = accountData.clendAccount;
|
|
123
|
+
const clendAccountBalances = (rawClendAccount.balances || []).map((b) => {
|
|
124
|
+
const liquidation = b.liquidation
|
|
125
|
+
? {
|
|
126
|
+
price: Number(b.liquidation.price),
|
|
127
|
+
changePercentage: Number(b.liquidation.changePercentage),
|
|
128
|
+
}
|
|
129
|
+
: null;
|
|
130
|
+
const emissionsOutstandingAndUnclaimed = new anchor_1.BN(b.emissionsOutstandingAndUnclaimed, "hex");
|
|
131
|
+
return {
|
|
132
|
+
mint: new anchor_1.web3.PublicKey(b.mint),
|
|
133
|
+
bank: new anchor_1.web3.PublicKey(b.bank),
|
|
134
|
+
tokenYieldApy: Number(b.tokenYieldApy),
|
|
135
|
+
assetBalance: new anchor_1.BN(b.assetBalance, "hex"),
|
|
136
|
+
assetBalanceUi: Number(b.assetBalanceUi),
|
|
137
|
+
assetValue: Number(b.assetValue),
|
|
138
|
+
assetEmissionsApy: Number(b.assetEmissionsApy),
|
|
139
|
+
liabilityBalance: new anchor_1.BN(b.liabilityBalance, "hex"),
|
|
140
|
+
liabilityBalanceUi: Number(b.liabilityBalanceUi),
|
|
141
|
+
liabilityValue: Number(b.liabilityValue),
|
|
142
|
+
liabilityBorrowCostApy: Number(b.liabilityBorrowCostApy),
|
|
143
|
+
liabilityEmissionsApy: Number(b.liabilityEmissionsApy),
|
|
144
|
+
emissionsOutstandingAndUnclaimed,
|
|
145
|
+
emissionsOutstandingAndUnclaimedUi: Number(b.emissionsOutstandingAndUnclaimedUi),
|
|
146
|
+
price: Number(b.price),
|
|
147
|
+
liquidation,
|
|
148
|
+
};
|
|
145
149
|
});
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
riskAdjustedLtv: Number(jsonRawResponse.clendAccount.riskAdjustedLtv),
|
|
163
|
-
};
|
|
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: [],
|
|
150
|
+
const clendAccount = {
|
|
151
|
+
key: new anchor_1.web3.PublicKey(rawClendAccount.key),
|
|
152
|
+
group: new anchor_1.web3.PublicKey(rawClendAccount.group),
|
|
153
|
+
balances: clendAccountBalances,
|
|
154
|
+
netValue: Number(rawClendAccount.netValue),
|
|
155
|
+
netApy: Number(rawClendAccount.netApy),
|
|
156
|
+
pnl: Number(rawClendAccount.pnl),
|
|
157
|
+
totalEmissionsApy: Number(rawClendAccount.totalEmissionsApy),
|
|
158
|
+
totalAssetValue: Number(rawClendAccount.totalAssetValue),
|
|
159
|
+
totalLiabilityValue: Number(rawClendAccount.totalLiabilityValue),
|
|
160
|
+
healthFactorNotional: Number(rawClendAccount.healthFactorNotional),
|
|
161
|
+
healthFactorRiskAdjusted: Number(rawClendAccount.healthFactorRiskAdjusted),
|
|
162
|
+
notionalLeverage: Number(rawClendAccount.notionalLeverage),
|
|
163
|
+
riskAdjustedLeverage: Number(rawClendAccount.riskAdjustedLeverage),
|
|
164
|
+
notionalLtv: Number(rawClendAccount.notionalLtv),
|
|
165
|
+
riskAdjustedLtv: Number(rawClendAccount.riskAdjustedLtv),
|
|
176
166
|
};
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
167
|
+
// B. Parse the associated Summary array for the account
|
|
168
|
+
let summary = [];
|
|
169
|
+
if (getClendAccountSummary && accountData.summary) {
|
|
170
|
+
summary = accountData.summary.map((s) => {
|
|
171
|
+
let input = undefined;
|
|
172
|
+
if (s.input) {
|
|
173
|
+
input = {
|
|
174
|
+
apiPath: s.input.apiPath,
|
|
175
|
+
selectedTokenMint: s.input.selectedTokenMint
|
|
176
|
+
? new anchor_1.web3.PublicKey(s.input.selectedTokenMint)
|
|
177
|
+
: null,
|
|
178
|
+
amountUi: s.input.amountUi ? Number(s.input.amountUi) : null,
|
|
179
|
+
leverage: s.input.leverage ? Number(s.input.leverage) : null,
|
|
180
|
+
slippageBps: s.input.slippageBps
|
|
181
|
+
? Number(s.input.slippageBps)
|
|
182
|
+
: null,
|
|
183
|
+
openPosition: s.input.openPosition != null
|
|
184
|
+
? Boolean(s.input.openPosition)
|
|
185
|
+
: null,
|
|
186
|
+
closePosition: s.input.closePosition != null
|
|
187
|
+
? Boolean(s.input.closePosition)
|
|
188
|
+
: null,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const events = (s.events || []).map((event) => {
|
|
192
|
+
let closeBalance = null;
|
|
193
|
+
// Only convert to boolean if the value is not null/undefined to preserve the null state.
|
|
194
|
+
if (event.closeBalance !== null &&
|
|
195
|
+
event.closeBalance !== undefined) {
|
|
196
|
+
closeBalance = Boolean(event.closeBalance);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
eventIndex: event.eventIndex,
|
|
200
|
+
eventName: event.eventName,
|
|
201
|
+
bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
|
|
202
|
+
mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
|
|
203
|
+
amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
|
|
204
|
+
amountUi: event.amountUi ? Number(event.amountUi) : null,
|
|
205
|
+
value: event.value ? Number(event.value) : null,
|
|
206
|
+
price: event.price ? Number(event.price) : null,
|
|
207
|
+
closeBalance,
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
const txSummary = {
|
|
211
|
+
txSig: s.txSig,
|
|
212
|
+
time: s.time,
|
|
213
|
+
clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
|
|
214
|
+
clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
|
|
215
|
+
clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
|
|
216
|
+
action: s.action,
|
|
217
|
+
input,
|
|
218
|
+
events,
|
|
219
|
+
};
|
|
220
|
+
return txSummary;
|
|
221
|
+
});
|
|
215
222
|
}
|
|
216
|
-
summary
|
|
217
|
-
|
|
223
|
+
// C. Combine the parsed account and its summary
|
|
224
|
+
return { clendAccount, summary };
|
|
225
|
+
});
|
|
226
|
+
// 3. Return the final, correctly structured response object.
|
|
218
227
|
return {
|
|
219
228
|
wallet,
|
|
220
|
-
|
|
221
|
-
summary,
|
|
229
|
+
clendAccounts,
|
|
222
230
|
};
|
|
223
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Get all groups
|
|
234
|
+
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
235
|
+
* @returns All groups
|
|
236
|
+
*/
|
|
237
|
+
async getGroups(includeBankData) {
|
|
238
|
+
const body = await handleApiCall(() => this.http.get(`/groups?includeBankData=${includeBankData}`));
|
|
239
|
+
const marketJson = JSON.parse(body);
|
|
240
|
+
const groups = [];
|
|
241
|
+
for (const groupJson of marketJson.groups) {
|
|
242
|
+
const group = new anchor_1.web3.PublicKey(groupJson.group);
|
|
243
|
+
const groupName = groupJson.groupName;
|
|
244
|
+
const banks = [];
|
|
245
|
+
for (const bankJson of groupJson.banks) {
|
|
246
|
+
const bank = parseBank(bankJson);
|
|
247
|
+
banks.push(bank);
|
|
248
|
+
}
|
|
249
|
+
groups.push({ group, groupName, banks });
|
|
250
|
+
}
|
|
251
|
+
const response = {
|
|
252
|
+
groups,
|
|
253
|
+
};
|
|
254
|
+
return response;
|
|
255
|
+
}
|
|
224
256
|
/**
|
|
225
257
|
* Get market details
|
|
226
258
|
* @param groupAddress group public key
|
|
@@ -229,13 +261,17 @@ class Client {
|
|
|
229
261
|
async getGroup(groupAddress) {
|
|
230
262
|
const body = await handleApiCall(() => this.http.get(`/group?group=${groupAddress.toString()}`));
|
|
231
263
|
const marketJson = JSON.parse(body);
|
|
232
|
-
const
|
|
233
|
-
|
|
264
|
+
const group = {
|
|
265
|
+
group: new anchor_1.web3.PublicKey(marketJson.group.group),
|
|
266
|
+
groupName: marketJson.group.groupName,
|
|
267
|
+
banks: [],
|
|
268
|
+
};
|
|
269
|
+
for (const bankJson of marketJson.group.banks) {
|
|
234
270
|
const bank = parseBank(bankJson);
|
|
235
|
-
banks.push(bank);
|
|
271
|
+
group.banks.push(bank);
|
|
236
272
|
}
|
|
237
273
|
const response = {
|
|
238
|
-
|
|
274
|
+
group,
|
|
239
275
|
};
|
|
240
276
|
return response;
|
|
241
277
|
}
|
|
@@ -253,20 +289,47 @@ class Client {
|
|
|
253
289
|
};
|
|
254
290
|
return response;
|
|
255
291
|
}
|
|
292
|
+
async deposit(clendGroup, clendAccount, inputTokenMint, uiAmount) {
|
|
293
|
+
const req = {
|
|
294
|
+
owner: this.address(),
|
|
295
|
+
clendGroup,
|
|
296
|
+
clendAccount,
|
|
297
|
+
inputTokenMint,
|
|
298
|
+
depositAmountUi: uiAmount,
|
|
299
|
+
};
|
|
300
|
+
const body = await handleApiCall(() => this.http.post("deposit", JSON.stringify(req)));
|
|
301
|
+
const depositResponse = JSON.parse(body);
|
|
302
|
+
const txSig = await this.send(depositResponse.unsignedBase64Tx, depositResponse.userRequestId);
|
|
303
|
+
return txSig;
|
|
304
|
+
}
|
|
305
|
+
async withdraw(clendAccount, outputTokenMint, uiAmount) {
|
|
306
|
+
const req = {
|
|
307
|
+
clendAccount,
|
|
308
|
+
outputTokenMint,
|
|
309
|
+
withdrawAmountUi: uiAmount,
|
|
310
|
+
};
|
|
311
|
+
const body = await handleApiCall(() => this.http.post("withdraw", JSON.stringify(req)));
|
|
312
|
+
const withdrawResponse = JSON.parse(body);
|
|
313
|
+
const txSig = await this.send(withdrawResponse.unsignedBase64Tx, withdrawResponse.userRequestId);
|
|
314
|
+
return txSig;
|
|
315
|
+
}
|
|
256
316
|
/**
|
|
257
317
|
* Deposit collateral and create a leveraged position
|
|
258
318
|
* @param request Deposit leverage request parameters
|
|
259
319
|
* @returns Deposit leverage operation result
|
|
260
320
|
*/
|
|
261
|
-
async depositLeverage(
|
|
262
|
-
if (!
|
|
321
|
+
async depositLeverage(clendGroup, clendAccount, inputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, leverage, slippageBps) {
|
|
322
|
+
if (!inputTokenMint.equals(assetTokenMint) &&
|
|
323
|
+
!inputTokenMint.equals(liabilityTokenMint)) {
|
|
263
324
|
throw new Error("Input mint must be the same as the asset or liability mint");
|
|
264
325
|
}
|
|
265
326
|
const req = {
|
|
266
327
|
owner: this.address(),
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
328
|
+
clendGroup,
|
|
329
|
+
clendAccount,
|
|
330
|
+
inputTokenMint,
|
|
331
|
+
assetTokenMint,
|
|
332
|
+
liabilityTokenMint,
|
|
270
333
|
depositAmountUi: uiAmount,
|
|
271
334
|
leverage,
|
|
272
335
|
slippageBps,
|
|
@@ -281,9 +344,11 @@ class Client {
|
|
|
281
344
|
* @param request Adjust leverage request parameters
|
|
282
345
|
* @returns Adjust leverage operation result
|
|
283
346
|
*/
|
|
284
|
-
async adjustLeverage(leverage, slippageBps) {
|
|
347
|
+
async adjustLeverage(clendAccount, assetTokenMint, liabilityTokenMint, leverage, slippageBps) {
|
|
285
348
|
const req = {
|
|
286
|
-
|
|
349
|
+
clendAccount,
|
|
350
|
+
assetTokenMint,
|
|
351
|
+
liabilityTokenMint,
|
|
287
352
|
leverage,
|
|
288
353
|
slippageBps,
|
|
289
354
|
};
|
|
@@ -297,10 +362,12 @@ class Client {
|
|
|
297
362
|
* @param request Withdraw leverage request parameters
|
|
298
363
|
* @returns Withdraw leverage operation result
|
|
299
364
|
*/
|
|
300
|
-
async withdrawLeverage(
|
|
365
|
+
async withdrawLeverage(clendAccount, outputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, slippageBps, withdrawAll) {
|
|
301
366
|
const req = {
|
|
302
|
-
|
|
303
|
-
|
|
367
|
+
clendAccount,
|
|
368
|
+
outputTokenMint,
|
|
369
|
+
assetTokenMint,
|
|
370
|
+
liabilityTokenMint,
|
|
304
371
|
withdrawAmountUi: uiAmount,
|
|
305
372
|
slippageBps,
|
|
306
373
|
withdrawAll,
|
|
@@ -310,16 +377,21 @@ class Client {
|
|
|
310
377
|
const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.userRequestId);
|
|
311
378
|
return txSig;
|
|
312
379
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Withdraw emissions from a bank
|
|
382
|
+
* @returns Withdraw emissions operation result
|
|
383
|
+
*/
|
|
384
|
+
async withdrawEmissions() {
|
|
385
|
+
const req = {
|
|
386
|
+
owner: this.address(),
|
|
387
|
+
};
|
|
388
|
+
const body = await handleApiCall(() => this.http.post("emissions/withdraw", JSON.stringify(req)));
|
|
389
|
+
const withdrawEmissionsResponse = JSON.parse(body);
|
|
390
|
+
const txSig = await this.send(withdrawEmissionsResponse.unsignedBase64Tx, withdrawEmissionsResponse.userRequestId);
|
|
391
|
+
return txSig;
|
|
321
392
|
}
|
|
322
393
|
}
|
|
394
|
+
exports.Client = Client;
|
|
323
395
|
// Helper function to handle API calls
|
|
324
396
|
async function handleApiCall(call) {
|
|
325
397
|
try {
|
|
@@ -344,6 +416,17 @@ function getDummyProvider() {
|
|
|
344
416
|
});
|
|
345
417
|
}
|
|
346
418
|
function parseBank(bankJson) {
|
|
419
|
+
let bankEmissions = null;
|
|
420
|
+
if (bankJson.emissions) {
|
|
421
|
+
bankEmissions = {
|
|
422
|
+
emissionsMode: bankJson.emissions.emissionsMode,
|
|
423
|
+
emissionsApy: Number(bankJson.emissions.emissionsApy),
|
|
424
|
+
emissionsMint: new anchor_1.web3.PublicKey(bankJson.emissions.emissionsMint),
|
|
425
|
+
emissionsTokenPrice: Number(bankJson.emissions.emissionsTokenPrice),
|
|
426
|
+
emissionsRate: new anchor_1.BN(bankJson.emissions.emissionsRate, "hex"),
|
|
427
|
+
emissionsRemainingUi: Number(bankJson.emissions.emissionsRemainingUi),
|
|
428
|
+
};
|
|
429
|
+
}
|
|
347
430
|
return {
|
|
348
431
|
mint: new anchor_1.web3.PublicKey(bankJson.mint),
|
|
349
432
|
key: new anchor_1.web3.PublicKey(bankJson.key),
|
|
@@ -357,6 +440,7 @@ function parseBank(bankJson) {
|
|
|
357
440
|
assetMaintWeight: Number(bankJson.assetMaintWeight),
|
|
358
441
|
totalAssetShares: Number(bankJson.totalAssetShares),
|
|
359
442
|
assetShareValue: Number(bankJson.assetShareValue),
|
|
443
|
+
tokenYieldApy: Number(bankJson.tokenYieldApy),
|
|
360
444
|
liabilityAmount: new anchor_1.BN(bankJson.liabilityAmount, "hex"),
|
|
361
445
|
liabilityAmountUi: Number(bankJson.liabilityAmountUi),
|
|
362
446
|
liabilityInitWeight: Number(bankJson.liabilityInitWeight),
|
|
@@ -368,5 +452,6 @@ function parseBank(bankJson) {
|
|
|
368
452
|
depositLimitUi: Number(bankJson.depositLimitUi),
|
|
369
453
|
borrowLimit: new anchor_1.BN(bankJson.borrowLimit, "hex"),
|
|
370
454
|
borrowLimitUi: Number(bankJson.borrowLimitUi),
|
|
455
|
+
emissions: bankEmissions,
|
|
371
456
|
};
|
|
372
457
|
}
|