@glamsystems/glam-cli 1.0.3-alpha.5 → 1.0.3-alpha.6
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/main.js +31 -13
- package/package.json +2 -2
package/main.js
CHANGED
|
@@ -5240,6 +5240,9 @@ async function fetchTokenPrices(pubkeys) {
|
|
|
5240
5240
|
async function fetchTokensList() {
|
|
5241
5241
|
const response = await fetch(`${JUPITER_API}/tokens/v2/tag?query=verified`);
|
|
5242
5242
|
const data = await response.json();
|
|
5243
|
+
if (!response.ok) {
|
|
5244
|
+
throw new Error(`Failed to fetch tokens list and prices from Jupiter: ${response.status} ${data?.message}`);
|
|
5245
|
+
}
|
|
5243
5246
|
const tokenList = data?.map((t) => ({
|
|
5244
5247
|
address: t.id,
|
|
5245
5248
|
name: t.name,
|
|
@@ -5248,6 +5251,7 @@ async function fetchTokensList() {
|
|
|
5248
5251
|
logoURI: t.icon,
|
|
5249
5252
|
tags: t.tags,
|
|
5250
5253
|
usdPrice: t.usdPrice,
|
|
5254
|
+
slot: t.priceBlockId,
|
|
5251
5255
|
}));
|
|
5252
5256
|
return tokenList;
|
|
5253
5257
|
}
|
|
@@ -8363,11 +8367,12 @@ const spl_token_1 = __webpack_require__(17);
|
|
|
8363
8367
|
const constants_1 = __webpack_require__(25);
|
|
8364
8368
|
const jupiter_1 = __webpack_require__(57);
|
|
8365
8369
|
class Holding {
|
|
8366
|
-
constructor(mintAddress, decimals, amount, price, protocol, protocolMeta = {}) {
|
|
8370
|
+
constructor(mintAddress, decimals, amount, price, priceMeta = {}, protocol, protocolMeta = {}) {
|
|
8367
8371
|
this.mintAddress = mintAddress;
|
|
8368
8372
|
this.decimals = decimals;
|
|
8369
8373
|
this.amount = amount;
|
|
8370
8374
|
this.price = price;
|
|
8375
|
+
this.priceMeta = priceMeta;
|
|
8371
8376
|
this.protocol = protocol;
|
|
8372
8377
|
this.protocolMeta = protocolMeta;
|
|
8373
8378
|
this.uiAmount = (0, utils_1.toUiAmount)(this.amount, this.decimals);
|
|
@@ -8506,9 +8511,9 @@ class PriceClient {
|
|
|
8506
8511
|
const tokenMint = new web3_js_1.PublicKey(item.address);
|
|
8507
8512
|
tokenPricesMap.set(tokenMint, item);
|
|
8508
8513
|
});
|
|
8509
|
-
const tokenHoldings = this.getTokenHoldings(tokenPubkeys, accountsDataMap, tokenPricesMap);
|
|
8510
|
-
const driftSpotHoldings = this.getDriftSpotHoldings(driftPubkeys.pkKeys(), driftSpotMarketsMap, accountsDataMap, tokenPricesMap);
|
|
8511
|
-
const kaminoLendHoldings = this.getKaminoLendHoldings(kaminoPubkeys.pkKeys(), kaminoReservesMap, accountsDataMap, tokenPricesMap);
|
|
8514
|
+
const tokenHoldings = this.getTokenHoldings(tokenPubkeys, accountsDataMap, tokenPricesMap, "Jupiter");
|
|
8515
|
+
const driftSpotHoldings = this.getDriftSpotHoldings(driftPubkeys.pkKeys(), driftSpotMarketsMap, accountsDataMap, tokenPricesMap, "Jupiter");
|
|
8516
|
+
const kaminoLendHoldings = this.getKaminoLendHoldings(kaminoPubkeys.pkKeys(), kaminoReservesMap, accountsDataMap, tokenPricesMap, "Jupiter");
|
|
8512
8517
|
const timestamp = accountsDataMap
|
|
8513
8518
|
.get(web3_js_1.SYSVAR_CLOCK_PUBKEY)
|
|
8514
8519
|
.readUInt32LE(32);
|
|
@@ -8569,7 +8574,7 @@ class PriceClient {
|
|
|
8569
8574
|
}
|
|
8570
8575
|
return obligationReservesMap;
|
|
8571
8576
|
}
|
|
8572
|
-
getTokenHoldings(tokenAccountPubkeys, accountsDataMap, tokenPricesMap) {
|
|
8577
|
+
getTokenHoldings(tokenAccountPubkeys, accountsDataMap, tokenPricesMap, priceSource) {
|
|
8573
8578
|
const holdings = [];
|
|
8574
8579
|
if (tokenAccountPubkeys.length === 0) {
|
|
8575
8580
|
return holdings;
|
|
@@ -8579,7 +8584,10 @@ class PriceClient {
|
|
|
8579
8584
|
const tokenInfo = tokenPricesMap.get(mint);
|
|
8580
8585
|
if (tokenInfo) {
|
|
8581
8586
|
const { decimals, usdPrice } = tokenInfo;
|
|
8582
|
-
const holding = new Holding(mint, decimals, new anchor_1.BN(amount), usdPrice,
|
|
8587
|
+
const holding = new Holding(mint, decimals, new anchor_1.BN(amount), usdPrice, {
|
|
8588
|
+
slot: tokenInfo.slot,
|
|
8589
|
+
source: priceSource,
|
|
8590
|
+
}, "Token", {
|
|
8583
8591
|
tokenAccount: pubkey,
|
|
8584
8592
|
});
|
|
8585
8593
|
holdings.push(holding);
|
|
@@ -8587,7 +8595,7 @@ class PriceClient {
|
|
|
8587
8595
|
}
|
|
8588
8596
|
return holdings;
|
|
8589
8597
|
}
|
|
8590
|
-
getDriftSpotHoldings(userPubkeys, spotMarketsMap, accountsDataMap, tokenPricesMap) {
|
|
8598
|
+
getDriftSpotHoldings(userPubkeys, spotMarketsMap, accountsDataMap, tokenPricesMap, priceSource) {
|
|
8591
8599
|
const holdings = [];
|
|
8592
8600
|
for (const userPda of userPubkeys) {
|
|
8593
8601
|
const { spotPositions } = (0, utils_1.decodeUser)(accountsDataMap.get(userPda));
|
|
@@ -8599,7 +8607,10 @@ class PriceClient {
|
|
|
8599
8607
|
: cumulativeDepositInterest;
|
|
8600
8608
|
const amount = this.drift.calcSpotBalanceBn(scaledBalance, decimals, interest);
|
|
8601
8609
|
const direction = Object.keys(balanceType)[0];
|
|
8602
|
-
const holding = new Holding(mint, decimals, amount, tokenPricesMap.get(mint).usdPrice,
|
|
8610
|
+
const holding = new Holding(mint, decimals, amount, tokenPricesMap.get(mint).usdPrice, {
|
|
8611
|
+
slot: tokenPricesMap.get(mint).slot,
|
|
8612
|
+
source: priceSource,
|
|
8613
|
+
}, "DriftProtocol", {
|
|
8603
8614
|
user: userPda,
|
|
8604
8615
|
marketIndex: marketIndex,
|
|
8605
8616
|
direction: direction,
|
|
@@ -8609,7 +8620,7 @@ class PriceClient {
|
|
|
8609
8620
|
}
|
|
8610
8621
|
return holdings;
|
|
8611
8622
|
}
|
|
8612
|
-
getKaminoLendHoldings(obligationPubkeys, reservesMap, accountsDataMap, tokenPricesMap) {
|
|
8623
|
+
getKaminoLendHoldings(obligationPubkeys, reservesMap, accountsDataMap, tokenPricesMap, priceSource) {
|
|
8613
8624
|
const holdings = [];
|
|
8614
8625
|
for (const obligation of obligationPubkeys) {
|
|
8615
8626
|
const { deposits, borrows } = this.klend.parseObligation(obligation, accountsDataMap.get(obligation));
|
|
@@ -8619,7 +8630,10 @@ class PriceClient {
|
|
|
8619
8630
|
.div(parsedReserve.collateralExchangeRate)
|
|
8620
8631
|
.floor();
|
|
8621
8632
|
const amount = new anchor_1.BN(supplyAmount.toString());
|
|
8622
|
-
const holding = new Holding(parsedReserve.liquidityMint, parsedReserve.liquidityMintDecimals, amount, tokenPricesMap.get(parsedReserve.liquidityMint).usdPrice,
|
|
8633
|
+
const holding = new Holding(parsedReserve.liquidityMint, parsedReserve.liquidityMintDecimals, amount, tokenPricesMap.get(parsedReserve.liquidityMint).usdPrice, {
|
|
8634
|
+
slot: tokenPricesMap.get(parsedReserve.liquidityMint).slot,
|
|
8635
|
+
source: priceSource,
|
|
8636
|
+
}, "KaminoLend", {
|
|
8623
8637
|
obligation,
|
|
8624
8638
|
market: parsedReserve.market,
|
|
8625
8639
|
reserve,
|
|
@@ -8636,7 +8650,10 @@ class PriceClient {
|
|
|
8636
8650
|
.div(obligationCumulativeBorrowRate)
|
|
8637
8651
|
.ceil();
|
|
8638
8652
|
const amount = new anchor_1.BN(borrowAmount.toString());
|
|
8639
|
-
const holding = new Holding(parsedReserve.liquidityMint, parsedReserve.liquidityMintDecimals, amount, tokenPricesMap.get(parsedReserve.liquidityMint).usdPrice,
|
|
8653
|
+
const holding = new Holding(parsedReserve.liquidityMint, parsedReserve.liquidityMintDecimals, amount, tokenPricesMap.get(parsedReserve.liquidityMint).usdPrice, {
|
|
8654
|
+
slot: tokenPricesMap.get(parsedReserve.liquidityMint).slot,
|
|
8655
|
+
source: priceSource,
|
|
8656
|
+
}, "KaminoLend", {
|
|
8640
8657
|
obligation,
|
|
8641
8658
|
market: parsedReserve.market,
|
|
8642
8659
|
reserve,
|
|
@@ -10418,7 +10435,8 @@ class CctpClient {
|
|
|
10418
10435
|
const ix = await this.buildReceiveMessageIx(sourceDomain, message);
|
|
10419
10436
|
receiveMessageIxs.push(ix);
|
|
10420
10437
|
}
|
|
10421
|
-
const
|
|
10438
|
+
const createUsdcAtaIx = (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(this.base.signer, this.base.getVaultAta(constants_1.USDC), this.base.vaultPda, constants_1.USDC);
|
|
10439
|
+
const tx = new web3_js_1.Transaction().add(createUsdcAtaIx, ...receiveMessageIxs);
|
|
10422
10440
|
const vTx = await this.base.intoVersionedTransaction(tx, txOptions);
|
|
10423
10441
|
return await this.base.sendAndConfirm(vTx);
|
|
10424
10442
|
}
|
|
@@ -14150,7 +14168,7 @@ program
|
|
|
14150
14168
|
initialize(config, skipSimulation);
|
|
14151
14169
|
await (0, idl_1.idlCheck)(context.glamClient);
|
|
14152
14170
|
})
|
|
14153
|
-
.version("1.0.3-alpha.
|
|
14171
|
+
.version("1.0.3-alpha.6");
|
|
14154
14172
|
program
|
|
14155
14173
|
.command("env")
|
|
14156
14174
|
.description("Display current environment setup")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glamsystems/glam-cli",
|
|
3
|
-
"version": "1.0.3-alpha.
|
|
3
|
+
"version": "1.0.3-alpha.6",
|
|
4
4
|
"description": "CLI for interacting with the GLAM Protocol",
|
|
5
5
|
"main": "./main.js",
|
|
6
6
|
"bin": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"node": ">=20.18.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@glamsystems/glam-sdk": "1.0.3-alpha.
|
|
24
|
+
"@glamsystems/glam-sdk": "1.0.3-alpha.6",
|
|
25
25
|
"@switchboard-xyz/common": "^3.0.0",
|
|
26
26
|
"commander": "^11.1.0",
|
|
27
27
|
"decimal.js": "^10.6.0",
|