@glamsystems/glam-cli 1.0.3-alpha.4 → 1.0.3-alpha.5

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.
Files changed (2) hide show
  1. package/main.js +89 -45
  2. package/package.json +2 -2
package/main.js CHANGED
@@ -8481,7 +8481,7 @@ class PriceClient {
8481
8481
  .map((v) => Array.from(v.pkValues()))
8482
8482
  .flat();
8483
8483
  // Dedupe keys and fetch all accounts in a single RPC call
8484
- const pubkeys = Array.from(new utils_1.PkSet(tokenPubkeys.concat(...driftUsers, ...driftSpotMarkets, ...kaminoObligations, ...kaminoReserves)));
8484
+ const pubkeys = Array.from(new utils_1.PkSet(tokenPubkeys.concat(...driftUsers, ...driftSpotMarkets, ...kaminoObligations, ...kaminoReserves, web3_js_1.SYSVAR_CLOCK_PUBKEY)));
8485
8485
  const { context: { slot }, value: accountsInfo, } = await this.base.provider.connection.getMultipleAccountsInfoAndContext(pubkeys, commitment);
8486
8486
  // Build a map of pubkey to account data for quick lookup
8487
8487
  const accountsDataMap = new utils_1.PkMap();
@@ -8509,7 +8509,9 @@ class PriceClient {
8509
8509
  const tokenHoldings = this.getTokenHoldings(tokenPubkeys, accountsDataMap, tokenPricesMap);
8510
8510
  const driftSpotHoldings = this.getDriftSpotHoldings(driftPubkeys.pkKeys(), driftSpotMarketsMap, accountsDataMap, tokenPricesMap);
8511
8511
  const kaminoLendHoldings = this.getKaminoLendHoldings(kaminoPubkeys.pkKeys(), kaminoReservesMap, accountsDataMap, tokenPricesMap);
8512
- const timestamp = await this.base.connection.getBlockTime(slot);
8512
+ const timestamp = accountsDataMap
8513
+ .get(web3_js_1.SYSVAR_CLOCK_PUBKEY)
8514
+ .readUInt32LE(32);
8513
8515
  const ret = new VaultHoldings(this.base.statePda, this.base.vaultPda, priceBaseAssetMint, slot, timestamp, commitment);
8514
8516
  tokenHoldings.forEach((holding) => ret.add(holding));
8515
8517
  driftSpotHoldings.forEach((holding) => ret.add(holding));
@@ -10468,9 +10470,17 @@ class CctpClient {
10468
10470
  ];
10469
10471
  }
10470
10472
  async buildReceiveMessageIx(sourceDomain, messageObj) {
10471
- const { message, attestation, eventNonce, decodedMessage: { decodedMessageBody: { burnToken }, }, } = messageObj;
10473
+ const { message, attestation, eventNonce, decodedMessage, status } = messageObj;
10474
+ if (status !== "complete") {
10475
+ throw new Error(`Attestation status is ${status}, expected "complete"`);
10476
+ }
10477
+ if (!decodedMessage ||
10478
+ !decodedMessage?.decodedMessageBody ||
10479
+ !decodedMessage?.decodedMessageBody?.burnToken) {
10480
+ throw new Error("Invalid message object: missing burnToken in decodedMessage");
10481
+ }
10472
10482
  // message, attestation, eventNonce, burnToken are hex strings
10473
- const pdas = await this.getReceiveMessagePdas(constants_1.MESSAGE_TRANSMITTER_V2, constants_1.TOKEN_MESSENGER_MINTER_V2, constants_1.USDC, burnToken, sourceDomain.toString(), eventNonce);
10483
+ const pdas = await this.getReceiveMessagePdas(constants_1.MESSAGE_TRANSMITTER_V2, constants_1.TOKEN_MESSENGER_MINTER_V2, constants_1.USDC, decodedMessage.decodedMessageBody.burnToken, sourceDomain.toString(), eventNonce);
10474
10484
  // raw ix data: [discriminator][message][attestation]
10475
10485
  const messageBuffer = Buffer.from(message.replace("0x", ""), "hex");
10476
10486
  const attestationBuffer = Buffer.from(attestation.replace("0x", ""), "hex");
@@ -10674,7 +10684,14 @@ class CctpClient {
10674
10684
  queryParams.set("transactionHash", txHash);
10675
10685
  }
10676
10686
  const resonse = await fetch(`https://iris-api.circle.com/v2/messages/${sourceDomain}?${queryParams}`);
10687
+ if (resonse.status !== 200) {
10688
+ const { error } = await resonse.json();
10689
+ throw new Error(`Failed to fetch messages from Circle API: ${resonse.status} ${error}`);
10690
+ }
10677
10691
  const { messages } = await resonse.json();
10692
+ if (!(messages instanceof Array)) {
10693
+ throw new Error("Invalid response from Circle API: messages not found");
10694
+ }
10678
10695
  return messages;
10679
10696
  }
10680
10697
  /**
@@ -13067,37 +13084,6 @@ function installVaultCommands(program, context) {
13067
13084
  process.exit(1);
13068
13085
  }
13069
13086
  });
13070
- program
13071
- .command("add-asset")
13072
- .argument("<asset>", "Asset mint public key", utils_1.validatePublicKey)
13073
- .description("Add a new asset to allowlist")
13074
- .action(async (asset) => {
13075
- const stateModel = await context.glamClient.fetchStateModel();
13076
- const assetsSet = new Set([...stateModel.assets, asset].map((a) => a.toBase58()));
13077
- const assets = Array.from(assetsSet).map((a) => new web3_js_1.PublicKey(a));
13078
- const txSig = await context.glamClient.state.update({ assets }, context.txOptions);
13079
- console.log(`Added asset ${asset}: ${txSig}`);
13080
- });
13081
- program
13082
- .command("delete-asset")
13083
- .argument("<asset>", "Asset mint public key", utils_1.validatePublicKey)
13084
- .description("Delete an asset from allowlist")
13085
- .action(async (asset) => {
13086
- const stateModel = await context.glamClient.fetchStateModel();
13087
- if (asset.equals(stateModel.baseAssetMint)) {
13088
- console.error("Base asset cannot be deleted from allowlist");
13089
- process.exit(1);
13090
- }
13091
- const assetsSet = new Set(stateModel.assets.map((a) => a.toBase58()));
13092
- let removed = assetsSet.delete(asset.toBase58());
13093
- if (!removed) {
13094
- console.error("Asset not found in allowlist, nothing to delete");
13095
- process.exit(1);
13096
- }
13097
- const assets = Array.from(assetsSet).map((a) => new web3_js_1.PublicKey(a));
13098
- const txSig = await context.glamClient.state.update({ assets }, context.txOptions);
13099
- console.log(`Deleted asset ${asset}: ${txSig}`);
13100
- });
13101
13087
  program
13102
13088
  .command("set-enabled <enabled>")
13103
13089
  .description("Set GLAM state enabled or disabled")
@@ -13319,6 +13305,58 @@ function installVaultCommands(program, context) {
13319
13305
  }
13320
13306
  });
13321
13307
  });
13308
+ program
13309
+ .command("asset-allowlist")
13310
+ .description("Get asset allowlist and corresponding token account")
13311
+ .action(async () => {
13312
+ const state = await context.glamClient.fetchStateAccount();
13313
+ const mints = await (0, glam_sdk_1.fetchMintsAndTokenPrograms)(context.glamClient.connection, state.assets);
13314
+ const data = mints.map(({ mint: { address, decimals }, tokenProgram }) => {
13315
+ const tokenAccount = context.glamClient.getVaultAta(address, tokenProgram);
13316
+ return {
13317
+ assetMint: address,
13318
+ decimals,
13319
+ tokenAccount,
13320
+ tokenProgram,
13321
+ };
13322
+ });
13323
+ console.log(JSON.stringify(data, null, 2));
13324
+ });
13325
+ program
13326
+ .command("add-asset")
13327
+ .argument("<asset>", "Asset mint public key", utils_1.validatePublicKey)
13328
+ .description("Add a new asset to allowlist")
13329
+ .action(async (asset) => {
13330
+ const state = await context.glamClient.fetchStateAccount();
13331
+ const assetsSet = new glam_sdk_1.PkSet(state.assets);
13332
+ if (assetsSet.has(asset)) {
13333
+ console.error(`Asset ${asset} already allowlisted`);
13334
+ process.exit(1);
13335
+ }
13336
+ const assets = Array.from(assetsSet.add(asset));
13337
+ const txSig = await context.glamClient.state.update({ assets }, context.txOptions);
13338
+ console.log(`Allowlisted asset ${asset}: ${txSig}`);
13339
+ });
13340
+ program
13341
+ .command("delete-asset")
13342
+ .argument("<asset>", "Asset mint public key", utils_1.validatePublicKey)
13343
+ .description("Delete an asset from allowlist")
13344
+ .action(async (asset) => {
13345
+ const state = await context.glamClient.fetchStateAccount();
13346
+ if (asset.equals(state.baseAssetMint)) {
13347
+ console.error("Base asset should not be deleted from allowlist");
13348
+ process.exit(1);
13349
+ }
13350
+ const assetsSet = new glam_sdk_1.PkSet(state.assets);
13351
+ let removed = assetsSet.delete(asset);
13352
+ if (!removed) {
13353
+ console.error(`${asset} not found in allowlist, nothing to delete`);
13354
+ process.exit(1);
13355
+ }
13356
+ const assets = Array.from(assetsSet);
13357
+ const txSig = await context.glamClient.state.update({ assets }, context.txOptions);
13358
+ console.log(`Deleted asset ${asset} from allowlist: ${txSig}`);
13359
+ });
13322
13360
  program
13323
13361
  .command("holdings")
13324
13362
  .description("Get vault holdings")
@@ -13666,15 +13704,21 @@ function installCctpCommands(program, context) {
13666
13704
  .option("-n, --nonce <nonce>", "Nonce hex string (start with 0x)")
13667
13705
  .description("Receive USDC from an EVM chain. Either txHash or nonce is required.")
13668
13706
  .action(async (sourceDomain, { txHash, nonce }) => {
13669
- await context.glamClient.cctp.receiveUsdc(sourceDomain, {
13670
- txHash,
13671
- nonce,
13672
- }, {
13673
- ...context.txOptions,
13674
- lookupTables: [
13675
- new web3_js_1.PublicKey("qj4EYgsGpnRdt9rvQW3wWZR8JVaKPg9rG9EB8DNgfz8"), // CCTP lookup table
13676
- ],
13677
- });
13707
+ try {
13708
+ await context.glamClient.cctp.receiveUsdc(sourceDomain, {
13709
+ txHash,
13710
+ nonce,
13711
+ }, {
13712
+ ...context.txOptions,
13713
+ lookupTables: [
13714
+ new web3_js_1.PublicKey("qj4EYgsGpnRdt9rvQW3wWZR8JVaKPg9rG9EB8DNgfz8"), // CCTP lookup table
13715
+ ],
13716
+ });
13717
+ }
13718
+ catch (e) {
13719
+ console.error((0, utils_1.parseTxError)(e));
13720
+ process.exit(1);
13721
+ }
13678
13722
  });
13679
13723
  program
13680
13724
  .command("list")
@@ -14106,7 +14150,7 @@ program
14106
14150
  initialize(config, skipSimulation);
14107
14151
  await (0, idl_1.idlCheck)(context.glamClient);
14108
14152
  })
14109
- .version("1.0.3-alpha.4");
14153
+ .version("1.0.3-alpha.5");
14110
14154
  program
14111
14155
  .command("env")
14112
14156
  .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.4",
3
+ "version": "1.0.3-alpha.5",
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.4",
24
+ "@glamsystems/glam-sdk": "1.0.3-alpha.5",
25
25
  "@switchboard-xyz/common": "^3.0.0",
26
26
  "commander": "^11.1.0",
27
27
  "decimal.js": "^10.6.0",