@carrot-protocol/boost-http-client 0.2.6 → 0.2.7-actions1-dev-4c5f4e1
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.js +32 -25
- package/dist/types.d.ts +9 -6
- package/package.json +1 -1
- package/src/index.ts +35 -26
- package/src/types.ts +10 -7
package/dist/index.js
CHANGED
|
@@ -109,7 +109,7 @@ class Client {
|
|
|
109
109
|
if (!user) {
|
|
110
110
|
user = this.address();
|
|
111
111
|
}
|
|
112
|
-
const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&
|
|
112
|
+
const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}&getClendAccountSummary=${request.getClendAccountSummary}`));
|
|
113
113
|
const jsonRawResponse = JSON.parse(body);
|
|
114
114
|
// get tokens still in user wallet
|
|
115
115
|
const wallet = {
|
|
@@ -125,7 +125,7 @@ class Client {
|
|
|
125
125
|
return {
|
|
126
126
|
wallet,
|
|
127
127
|
clendAccount: undefined,
|
|
128
|
-
|
|
128
|
+
summary: [],
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
131
|
// parse lending account balances
|
|
@@ -159,34 +159,41 @@ class Client {
|
|
|
159
159
|
liquidationPriceChangePercentage: Number(jsonRawResponse.clendAccount.liquidationPriceChangePercentage),
|
|
160
160
|
ltv: Number(jsonRawResponse.clendAccount.ltv),
|
|
161
161
|
};
|
|
162
|
-
// get
|
|
163
|
-
const
|
|
164
|
-
for (const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
time: event.time,
|
|
174
|
-
eventName: event.eventName,
|
|
175
|
-
clendAccount: new anchor_1.web3.PublicKey(event.clendAccount),
|
|
176
|
-
signer: event.signer ? new anchor_1.web3.PublicKey(event.signer) : null,
|
|
177
|
-
clendAccountAuthority: new anchor_1.web3.PublicKey(event.clendAccountAuthority),
|
|
178
|
-
clendGroup: new anchor_1.web3.PublicKey(event.clendGroup),
|
|
179
|
-
bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
|
|
180
|
-
mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
|
|
181
|
-
amount: event.amount ? new anchor_1.BN(event.amount) : null,
|
|
182
|
-
closeBalance,
|
|
162
|
+
// get tx summary for each account
|
|
163
|
+
const summary = [];
|
|
164
|
+
for (const s of jsonRawResponse.summary) {
|
|
165
|
+
const txSummary = {
|
|
166
|
+
txSig: s.txSig,
|
|
167
|
+
time: s.time,
|
|
168
|
+
clendAccount: new anchor_1.web3.PublicKey(s.clendAccount),
|
|
169
|
+
clendAccountAuthority: new anchor_1.web3.PublicKey(s.clendAccountAuthority),
|
|
170
|
+
clendGroup: new anchor_1.web3.PublicKey(s.clendGroup),
|
|
171
|
+
action: s.action,
|
|
172
|
+
events: [],
|
|
183
173
|
};
|
|
184
|
-
events
|
|
174
|
+
// get events for each summary
|
|
175
|
+
for (const event of s.events) {
|
|
176
|
+
let closeBalance = null;
|
|
177
|
+
if (event.closeBalance !== null) {
|
|
178
|
+
closeBalance = Boolean(event.closeBalance);
|
|
179
|
+
}
|
|
180
|
+
// parse amount
|
|
181
|
+
const clendAccountEvent = {
|
|
182
|
+
eventIndex: event.eventIndex,
|
|
183
|
+
eventName: event.eventName,
|
|
184
|
+
bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
|
|
185
|
+
mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
|
|
186
|
+
amount: event.amount ? new anchor_1.BN(event.amount, "hex") : null,
|
|
187
|
+
closeBalance,
|
|
188
|
+
};
|
|
189
|
+
txSummary.events.push(clendAccountEvent);
|
|
190
|
+
}
|
|
191
|
+
summary.push(txSummary);
|
|
185
192
|
}
|
|
186
193
|
return {
|
|
187
194
|
wallet,
|
|
188
195
|
clendAccount,
|
|
189
|
-
|
|
196
|
+
summary,
|
|
190
197
|
};
|
|
191
198
|
}
|
|
192
199
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -53,12 +53,12 @@ export interface GetGroupResponse {
|
|
|
53
53
|
}
|
|
54
54
|
export interface GetUserRequest {
|
|
55
55
|
user?: web3.PublicKey;
|
|
56
|
-
|
|
56
|
+
getClendAccountSummary?: boolean;
|
|
57
57
|
}
|
|
58
58
|
export interface GetUserResponse {
|
|
59
59
|
wallet: UserWallet;
|
|
60
60
|
clendAccount: ClendAccount | undefined;
|
|
61
|
-
|
|
61
|
+
summary: ClendAccountTxSummary[];
|
|
62
62
|
}
|
|
63
63
|
export interface UserWallet {
|
|
64
64
|
usdcBalance: BN;
|
|
@@ -122,15 +122,18 @@ export interface Bank {
|
|
|
122
122
|
borrowLimit: BN;
|
|
123
123
|
borrowLimitUi: number;
|
|
124
124
|
}
|
|
125
|
-
export interface
|
|
125
|
+
export interface ClendAccountTxSummary {
|
|
126
126
|
txSig: string;
|
|
127
|
-
eventIndex: number;
|
|
128
127
|
time: Date;
|
|
129
|
-
eventName: string;
|
|
130
128
|
clendAccount: web3.PublicKey;
|
|
131
|
-
signer: web3.PublicKey | null;
|
|
132
129
|
clendAccountAuthority: web3.PublicKey;
|
|
133
130
|
clendGroup: web3.PublicKey;
|
|
131
|
+
action: string;
|
|
132
|
+
events: ClendAccountEvent[];
|
|
133
|
+
}
|
|
134
|
+
export interface ClendAccountEvent {
|
|
135
|
+
eventIndex: number;
|
|
136
|
+
eventName: string;
|
|
134
137
|
bank: web3.PublicKey | null;
|
|
135
138
|
mint: web3.PublicKey | null;
|
|
136
139
|
amount: BN | null;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
GetGroupResponse,
|
|
18
18
|
ClendAccountEvent,
|
|
19
19
|
GetUserRequest,
|
|
20
|
+
ClendAccountTxSummary,
|
|
20
21
|
} from "./types";
|
|
21
22
|
import encode from "bs58";
|
|
22
23
|
|
|
@@ -106,7 +107,7 @@ export class Client {
|
|
|
106
107
|
|
|
107
108
|
const body = await handleApiCall(() =>
|
|
108
109
|
this.http.get(
|
|
109
|
-
`/user?user=${user.toString()}&
|
|
110
|
+
`/user?user=${user.toString()}&getClendAccountSummary=${request.getClendAccountSummary}`,
|
|
110
111
|
),
|
|
111
112
|
);
|
|
112
113
|
|
|
@@ -127,7 +128,7 @@ export class Client {
|
|
|
127
128
|
return {
|
|
128
129
|
wallet,
|
|
129
130
|
clendAccount: undefined,
|
|
130
|
-
|
|
131
|
+
summary: [],
|
|
131
132
|
};
|
|
132
133
|
}
|
|
133
134
|
|
|
@@ -174,36 +175,44 @@ export class Client {
|
|
|
174
175
|
ltv: Number(jsonRawResponse.clendAccount.ltv),
|
|
175
176
|
};
|
|
176
177
|
|
|
177
|
-
// get
|
|
178
|
-
const
|
|
179
|
-
for (const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
eventIndex: event.eventIndex,
|
|
189
|
-
time: event.time,
|
|
190
|
-
eventName: event.eventName,
|
|
191
|
-
clendAccount: new web3.PublicKey(event.clendAccount),
|
|
192
|
-
signer: event.signer ? new web3.PublicKey(event.signer) : null,
|
|
193
|
-
clendAccountAuthority: new web3.PublicKey(event.clendAccountAuthority),
|
|
194
|
-
clendGroup: new web3.PublicKey(event.clendGroup),
|
|
195
|
-
bank: event.bank ? new web3.PublicKey(event.bank) : null,
|
|
196
|
-
mint: event.mint ? new web3.PublicKey(event.mint) : null,
|
|
197
|
-
amount: event.amount ? new BN(event.amount) : null,
|
|
198
|
-
closeBalance,
|
|
178
|
+
// get tx summary for each account
|
|
179
|
+
const summary: ClendAccountTxSummary[] = [];
|
|
180
|
+
for (const s of jsonRawResponse.summary) {
|
|
181
|
+
const txSummary: ClendAccountTxSummary = {
|
|
182
|
+
txSig: s.txSig,
|
|
183
|
+
time: s.time,
|
|
184
|
+
clendAccount: new web3.PublicKey(s.clendAccount),
|
|
185
|
+
clendAccountAuthority: new web3.PublicKey(s.clendAccountAuthority),
|
|
186
|
+
clendGroup: new web3.PublicKey(s.clendGroup),
|
|
187
|
+
action: s.action,
|
|
188
|
+
events: [],
|
|
199
189
|
};
|
|
200
|
-
|
|
190
|
+
|
|
191
|
+
// get events for each summary
|
|
192
|
+
for (const event of s.events) {
|
|
193
|
+
let closeBalance: boolean | null = null;
|
|
194
|
+
if (event.closeBalance !== null) {
|
|
195
|
+
closeBalance = Boolean(event.closeBalance);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// parse amount
|
|
199
|
+
const clendAccountEvent: ClendAccountEvent = {
|
|
200
|
+
eventIndex: event.eventIndex,
|
|
201
|
+
eventName: event.eventName,
|
|
202
|
+
bank: event.bank ? new web3.PublicKey(event.bank) : null,
|
|
203
|
+
mint: event.mint ? new web3.PublicKey(event.mint) : null,
|
|
204
|
+
amount: event.amount ? new BN(event.amount, "hex") : null,
|
|
205
|
+
closeBalance,
|
|
206
|
+
};
|
|
207
|
+
txSummary.events.push(clendAccountEvent);
|
|
208
|
+
}
|
|
209
|
+
summary.push(txSummary);
|
|
201
210
|
}
|
|
202
211
|
|
|
203
212
|
return {
|
|
204
213
|
wallet,
|
|
205
214
|
clendAccount,
|
|
206
|
-
|
|
215
|
+
summary,
|
|
207
216
|
};
|
|
208
217
|
}
|
|
209
218
|
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BN, web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import Decimal from "decimal.js";
|
|
3
2
|
|
|
4
3
|
// Represents a request to send a transaction
|
|
5
4
|
export interface SendRequest {
|
|
@@ -64,13 +63,13 @@ export interface GetGroupResponse {
|
|
|
64
63
|
|
|
65
64
|
export interface GetUserRequest {
|
|
66
65
|
user?: web3.PublicKey;
|
|
67
|
-
|
|
66
|
+
getClendAccountSummary?: boolean;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
export interface GetUserResponse {
|
|
71
70
|
wallet: UserWallet;
|
|
72
71
|
clendAccount: ClendAccount | undefined;
|
|
73
|
-
|
|
72
|
+
summary: ClendAccountTxSummary[];
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
export interface UserWallet {
|
|
@@ -140,15 +139,19 @@ export interface Bank {
|
|
|
140
139
|
borrowLimitUi: number;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
export interface
|
|
142
|
+
export interface ClendAccountTxSummary {
|
|
144
143
|
txSig: string;
|
|
145
|
-
eventIndex: number;
|
|
146
144
|
time: Date;
|
|
147
|
-
eventName: string;
|
|
148
145
|
clendAccount: web3.PublicKey;
|
|
149
|
-
signer: web3.PublicKey | null;
|
|
150
146
|
clendAccountAuthority: web3.PublicKey;
|
|
151
147
|
clendGroup: web3.PublicKey;
|
|
148
|
+
action: string;
|
|
149
|
+
events: ClendAccountEvent[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface ClendAccountEvent {
|
|
153
|
+
eventIndex: number;
|
|
154
|
+
eventName: string;
|
|
152
155
|
bank: web3.PublicKey | null;
|
|
153
156
|
mint: web3.PublicKey | null;
|
|
154
157
|
amount: BN | null;
|