@carrot-protocol/boost-http-client 0.2.3-withdraw-jlp-dev-4ead85f → 0.2.3-withdraw-jlp-dev-6a31381
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 +6 -1
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +10 -0
- package/package.json +1 -1
- package/src/index.ts +7 -1
- package/src/types.ts +1 -0
- package/src/utils.ts +9 -1
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ exports.Client = void 0;
|
|
|
21
21
|
const axios_1 = __importDefault(require("axios"));
|
|
22
22
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
23
23
|
const bs58_1 = __importDefault(require("bs58"));
|
|
24
|
+
const utils_1 = require("./utils");
|
|
24
25
|
// Re-export types
|
|
25
26
|
__exportStar(require("./types"), exports);
|
|
26
27
|
__exportStar(require("./utils"), exports);
|
|
@@ -141,6 +142,9 @@ class Client {
|
|
|
141
142
|
if (event.closeBalance !== null) {
|
|
142
143
|
closeBalance = Boolean(event.closeBalance);
|
|
143
144
|
}
|
|
145
|
+
// parse amount
|
|
146
|
+
const amount = event.amount ? new anchor_1.BN(event.amount, "hex") : null;
|
|
147
|
+
const amountUi = amount !== null ? (0, utils_1.amountToUi)(amount, 6) : null;
|
|
144
148
|
const clendAccountEvent = {
|
|
145
149
|
txSig: event.txSig,
|
|
146
150
|
eventIndex: event.eventIndex,
|
|
@@ -152,7 +156,8 @@ class Client {
|
|
|
152
156
|
clendGroup: new anchor_1.web3.PublicKey(event.clendGroup),
|
|
153
157
|
bank: event.bank ? new anchor_1.web3.PublicKey(event.bank) : null,
|
|
154
158
|
mint: event.mint ? new anchor_1.web3.PublicKey(event.mint) : null,
|
|
155
|
-
amount
|
|
159
|
+
amount,
|
|
160
|
+
amountUi,
|
|
156
161
|
closeBalance,
|
|
157
162
|
};
|
|
158
163
|
events.push(clendAccountEvent);
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { web3 } from "@coral-xyz/anchor";
|
|
1
|
+
import { BN, web3 } from "@coral-xyz/anchor";
|
|
2
2
|
import { ClendAccount } from "./types";
|
|
3
|
+
export declare function amountToUi(amount: BN | number, decimals: number): number;
|
|
3
4
|
export declare function netValueInToken(clendAccount: ClendAccount, tokenMint: web3.PublicKey): number;
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.amountToUi = amountToUi;
|
|
3
4
|
exports.netValueInToken = netValueInToken;
|
|
5
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
6
|
+
function amountToUi(amount, decimals) {
|
|
7
|
+
if (amount instanceof anchor_1.BN) {
|
|
8
|
+
return Number(amount.toNumber() / 10 ** decimals);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return Number(amount / 10 ** decimals);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
4
14
|
// returns the net value of the clend account in a given tokens price
|
|
5
15
|
function netValueInToken(clendAccount, tokenMint) {
|
|
6
16
|
const clendAccountTokenBalance = clendAccount.balances.find((balance) => balance.mint.equals(tokenMint));
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
GetUserRequest,
|
|
20
20
|
} from "./types";
|
|
21
21
|
import encode from "bs58";
|
|
22
|
+
import { amountToUi } from "./utils";
|
|
22
23
|
|
|
23
24
|
// Re-export types
|
|
24
25
|
export * from "./types";
|
|
@@ -176,6 +177,10 @@ export class Client {
|
|
|
176
177
|
closeBalance = Boolean(event.closeBalance);
|
|
177
178
|
}
|
|
178
179
|
|
|
180
|
+
// parse amount
|
|
181
|
+
const amount = event.amount ? new BN(event.amount, "hex") : null;
|
|
182
|
+
const amountUi = amount !== null ? amountToUi(amount, 6) : null;
|
|
183
|
+
|
|
179
184
|
const clendAccountEvent: ClendAccountEvent = {
|
|
180
185
|
txSig: event.txSig,
|
|
181
186
|
eventIndex: event.eventIndex,
|
|
@@ -187,7 +192,8 @@ export class Client {
|
|
|
187
192
|
clendGroup: new web3.PublicKey(event.clendGroup),
|
|
188
193
|
bank: event.bank ? new web3.PublicKey(event.bank) : null,
|
|
189
194
|
mint: event.mint ? new web3.PublicKey(event.mint) : null,
|
|
190
|
-
amount
|
|
195
|
+
amount,
|
|
196
|
+
amountUi,
|
|
191
197
|
closeBalance,
|
|
192
198
|
};
|
|
193
199
|
events.push(clendAccountEvent);
|
package/src/types.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { web3 } from "@coral-xyz/anchor";
|
|
1
|
+
import { BN, web3 } from "@coral-xyz/anchor";
|
|
2
2
|
import { ClendAccount } from "./types";
|
|
3
3
|
|
|
4
|
+
export function amountToUi(amount: BN | number, decimals: number): number {
|
|
5
|
+
if (amount instanceof BN) {
|
|
6
|
+
return Number(amount.toNumber() / 10 ** decimals);
|
|
7
|
+
} else {
|
|
8
|
+
return Number(amount / 10 ** decimals);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
// returns the net value of the clend account in a given tokens price
|
|
5
13
|
export function netValueInToken(
|
|
6
14
|
clendAccount: ClendAccount,
|