@glamsystems/glam-cli 0.2.0-alpha.3 → 0.2.0-alpha.4

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 +434 -244
  2. package/package.json +2 -2
package/main.js CHANGED
@@ -170,7 +170,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"address":"G1NTcMDYgNLpDwgnrpSZvoSKQu
170
170
 
171
171
 
172
172
  Object.defineProperty(exports, "__esModule", ({ value: true }));
173
- exports.VoteAuthorize = exports.TimeUnit = exports.PriceDenom = exports.RequestType = exports.StateAccountType = exports.DelegateAcl = exports.IntegrationAcl = exports.ProtocolPolicy = exports.JupiterSwapPolicy = exports.ProtocolPermissions = exports.IntegrationPermissions = exports.EmergencyUpdateMintArgs = exports.EmergencyAccessUpdateArgs = exports.CreatedModel = exports.MintModel = exports.MintIdlModel = exports.StateModel = exports.StateIdlModel = exports.GlamPermissions = exports.GlamIntegrations = void 0;
173
+ exports.VoteAuthorize = exports.TimeUnit = exports.PriceDenom = exports.RequestType = exports.StateAccountType = exports.DelegateAcl = exports.IntegrationAcl = exports.ProtocolPolicy = exports.ProtocolPermissions = exports.IntegrationPermissions = exports.EmergencyUpdateMintArgs = exports.EmergencyAccessUpdateArgs = exports.CreatedModel = exports.MintModel = exports.MintIdlModel = exports.StateModel = exports.StateIdlModel = exports.GlamPermissions = exports.GlamIntegrations = void 0;
174
174
  const glamExports_1 = __webpack_require__(3);
175
175
  const web3_js_1 = __webpack_require__(15);
176
176
  const spl_token_1 = __webpack_require__(16);
@@ -436,13 +436,6 @@ class ProtocolPermissions {
436
436
  }
437
437
  }
438
438
  exports.ProtocolPermissions = ProtocolPermissions;
439
- class JupiterSwapPolicy {
440
- constructor(obj) {
441
- this.maxSlippageBps = obj.maxSlippageBps;
442
- this.swapAllowlist = obj.swapAllowlist ?? null;
443
- }
444
- }
445
- exports.JupiterSwapPolicy = JupiterSwapPolicy;
446
439
  class ProtocolPolicy {
447
440
  constructor(obj) {
448
441
  this.protocolBitflag = obj.protocolBitflag;
@@ -553,7 +546,7 @@ module.exports = require("@solana/spl-token-metadata");
553
546
 
554
547
 
555
548
  Object.defineProperty(exports, "__esModule", ({ value: true }));
556
- exports.PROTOCOLS_AND_PERMISSIONS = exports.PERMISSION_MAPPINGS = exports.DRIFT_POOL_MAPPING = exports.CCTP_DOMAIN_MAPPING = exports.INTEGRATION_MAPPING = exports.GLAM_REFERRER = exports.JUPSOL_STAKE_POOL = exports.JITO_STAKE_POOL = exports.MESSAGE_TRANSMITTER_V2 = exports.TOKEN_MESSENGER_MINTER_V2 = exports.ALT_PROGRAM_ID = exports.MEMO_PROGRAM = exports.KAMINO_FARM_PROGRAM = exports.KAMINO_VAULTS_PROGRAM = exports.KAMINO_LENDING_PROGRAM = exports.METEORA_DLMM_PROGRAM = exports.TRANSFER_HOOK_PROGRAM = exports.MERKLE_DISTRIBUTOR_PROGRAM = exports.JUP_VOTE_PROGRAM = exports.GOVERNANCE_PROGRAM_ID = exports.SANCTUM_STAKE_POOL_PROGRAM_ID = exports.JUPITER_PROGRAM_ID = exports.DRIFT_DISTRIBUTOR_PROGRAM = exports.DRIFT_VAULTS_PROGRAM_ID = exports.DRIFT_PROGRAM_ID = exports.MARINADE_PROGRAM_ID = exports.JUP = exports.USDC_DEVNET = exports.USDC = exports.MSOL = exports.WSOL = exports.MARINADE_NATIVE_STAKE_AUTHORITY = exports.KAMINO_SCOPE_PRICES = exports.JITO_TIP_DEFAULT = exports.JUPITER_API_DEFAULT = exports.DRIFT_VAULT_DEPOSITOR_SIZE = exports.KAMINO_OBTRIGATION_SIZE = exports.METEORA_POSITION_SIZE = exports.STAKE_ACCOUNT_SIZE = exports.SEED_INTEGRATION_AUTHORITY = exports.SEED_GLOBAL_CONFIG = exports.SEED_EXTRA_ACCOUNT_METAS = exports.SEED_ACCOUNT_POLICY = exports.SEED_REQUEST_QUEUE = exports.SEED_ESCROW = exports.SEED_MINT = exports.SEED_METADATA = exports.SEED_VAULT = exports.SEED_STATE = void 0;
549
+ exports.INTEGRATION_MAPPING = exports.PROTOCOLS_AND_PERMISSIONS = exports.DRIFT_POOL_MAPPING = exports.CCTP_DOMAIN_MAPPING = exports.GLAM_REFERRER = exports.JUPSOL_STAKE_POOL = exports.JITO_STAKE_POOL = exports.MESSAGE_TRANSMITTER_V2 = exports.TOKEN_MESSENGER_MINTER_V2 = exports.ALT_PROGRAM_ID = exports.MEMO_PROGRAM = exports.KAMINO_FARM_PROGRAM = exports.KAMINO_VAULTS_PROGRAM = exports.KAMINO_LENDING_PROGRAM = exports.METEORA_DLMM_PROGRAM = exports.TRANSFER_HOOK_PROGRAM = exports.MERKLE_DISTRIBUTOR_PROGRAM = exports.JUP_VOTE_PROGRAM = exports.GOVERNANCE_PROGRAM_ID = exports.SANCTUM_STAKE_POOL_PROGRAM_ID = exports.JUPITER_PROGRAM_ID = exports.DRIFT_DISTRIBUTOR_PROGRAM = exports.DRIFT_VAULTS_PROGRAM_ID = exports.DRIFT_PROGRAM_ID = exports.MARINADE_PROGRAM_ID = exports.JUP = exports.USDC_DEVNET = exports.USDC = exports.MSOL = exports.WSOL = exports.MARINADE_NATIVE_STAKE_AUTHORITY = exports.KAMINO_SCOPE_PRICES = exports.JITO_TIP_DEFAULT = exports.JUPITER_API_DEFAULT = exports.DRIFT_VAULT_DEPOSITOR_SIZE = exports.KAMINO_OBTRIGATION_SIZE = exports.METEORA_POSITION_SIZE = exports.STAKE_ACCOUNT_SIZE = exports.SEED_INTEGRATION_AUTHORITY = exports.SEED_GLOBAL_CONFIG = exports.SEED_EXTRA_ACCOUNT_METAS = exports.SEED_ACCOUNT_POLICY = exports.SEED_REQUEST_QUEUE = exports.SEED_ESCROW = exports.SEED_MINT = exports.SEED_METADATA = exports.SEED_VAULT = exports.SEED_STATE = void 0;
557
550
  const web3_js_1 = __webpack_require__(15);
558
551
  exports.SEED_STATE = "state"; // protocol program
559
552
  exports.SEED_VAULT = "vault"; // protocol program
@@ -615,29 +608,6 @@ exports.JUPSOL_STAKE_POOL = new web3_js_1.PublicKey("8VpRhuxa7sUUepdY3kQiTmX9rS5
615
608
  * Referrers
616
609
  */
617
610
  exports.GLAM_REFERRER = new web3_js_1.PublicKey("GLAMrG37ZqioqvzBNQGCfCUueDz3tsr7MwMFyRk9PS89");
618
- /**
619
- * Integration program mapping
620
- */
621
- exports.INTEGRATION_MAPPING = {
622
- GM1NtvvnSXUptTrMCqbogAdZJydZSNv98DoU5AZVLmGh: {
623
- "0000000000000001": "GLAM Mint Protocol",
624
- },
625
- G1NTcMDYgNLpDwgnrpSZvoSKQuR9NXG7S3DmtNQCDmrK: {
626
- "0000000000000001": "CCTP",
627
- },
628
- G1NTsQ36mjPe89HtPYqxKsjY5HmYsDR6CbD2gd2U2pta: {
629
- "0000000000000001": "Token",
630
- },
631
- G1NTdrBmBpW43msRQmsf7qXSw3MFBNaqJcAkGiRmRq2F: {
632
- "0000000000000001": "Drift Protocol",
633
- "0000000000000010": "Drift Vaults",
634
- },
635
- G1NTkDEUR3pkEqGCKZtmtmVzCUEdYa86pezHkwYbLyde: {
636
- "0000000000000001": "Kamino Lending",
637
- "0000000000000010": "Kamino Vaults",
638
- "0000000000000100": "Kamino Farms",
639
- },
640
- };
641
611
  /**
642
612
  * CCTP domain to chain name mapping
643
613
  */
@@ -671,66 +641,6 @@ exports.DRIFT_POOL_MAPPING = {
671
641
  3: "Exponent Market",
672
642
  };
673
643
  // Permission mappings for each protocol - maps bit positions to permission names
674
- exports.PERMISSION_MAPPINGS = {
675
- // Kamino integration program
676
- G1NTkDEUR3pkEqGCKZtmtmVzCUEdYa86pezHkwYbLyde: {
677
- // Kamino Lending (protocol bitmask: 0000000000000001)
678
- "0000000000000001": {
679
- 0: "Init", // 1 << 0
680
- 1: "Deposit", // 1 << 1
681
- 2: "Withdraw", // 1 << 2
682
- 3: "Borrow", // 1 << 3
683
- 4: "Repay", // 1 << 4
684
- },
685
- // Kamino Vaults (protocol bitmask: 0000000000000010)
686
- "0000000000000010": {
687
- 0: "Deposit", // 1 << 0
688
- 1: "Withdraw", // 1 << 1
689
- },
690
- // Kamino Farms (protocol bitmask: 0000000000000100)
691
- "0000000000000100": {
692
- 0: "Stake", // 1 << 0
693
- 1: "Unstake", // 1 << 1
694
- 2: "HarvestReward", // 1 << 2
695
- },
696
- },
697
- // Drift integration program
698
- G1NTdrBmBpW43msRQmsf7qXSw3MFBNaqJcAkGiRmRq2F: {
699
- // Drift Protocol (protocol bitmask: 0000000000000001)
700
- "0000000000000001": {
701
- 0: "InitUser", // 1 << 0
702
- 1: "UpdateUser", // 1 << 1
703
- 2: "DeleteUser", // 1 << 2
704
- 3: "Deposit", // 1 << 3
705
- 4: "Withdraw", // 1 << 4
706
- 5: "Borrow", // 1 << 5
707
- 6: "CreateModifyOrders", // 1 << 6
708
- 7: "CancelOrders", // 1 << 7
709
- 8: "PerpMarkets", // 1 << 8
710
- 9: "SpotMarkets", // 1 << 9
711
- },
712
- // Drift Vaults (protocol bitmask: 0000000000000010)
713
- "0000000000000010": {
714
- 0: "Deposit", // 1 << 0
715
- 1: "Withdraw", // 1 << 1
716
- },
717
- },
718
- // Token integration program
719
- G1NTsQ36mjPe89HtPYqxKsjY5HmYsDR6CbD2gd2U2pta: {
720
- // Token (protocol bitmask: 0000000000000001)
721
- "0000000000000001": {
722
- 0: "Transfer", // 1 << 0
723
- },
724
- },
725
- // CCTP integration program
726
- G1NTcMDYgNLpDwgnrpSZvoSKQuR9NXG7S3DmtNQCDmrK: {
727
- // CCTP (protocol bitmask: 0000000000000001)
728
- "0000000000000001": {
729
- 0: "Transfer",
730
- },
731
- },
732
- };
733
- // Permission mappings for each protocol - maps bit positions to permission names
734
644
  exports.PROTOCOLS_AND_PERMISSIONS = {
735
645
  // Self integration
736
646
  GLAMpaME8wdTEzxtiYEAa5yD8fZbxZiz2hNtV58RZiEz: {
@@ -838,6 +748,19 @@ exports.PROTOCOLS_AND_PERMISSIONS = {
838
748
  },
839
749
  },
840
750
  };
751
+ /**
752
+ * Integration program mapping - dynamically built from PROTOCOLS_AND_PERMISSIONS
753
+ */
754
+ exports.INTEGRATION_MAPPING = (() => {
755
+ const mapping = {};
756
+ Object.entries(exports.PROTOCOLS_AND_PERMISSIONS).forEach(([programId, protocols]) => {
757
+ mapping[programId] = {};
758
+ Object.entries(protocols).forEach(([bitflag, protocol]) => {
759
+ mapping[programId][bitflag] = protocol.name;
760
+ });
761
+ });
762
+ return mapping;
763
+ })();
841
764
 
842
765
 
843
766
  /***/ }),
@@ -1355,7 +1278,7 @@ module.exports = require("@meteora-ag/dlmm");
1355
1278
 
1356
1279
 
1357
1280
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1358
- exports.CctpPolicy = exports.DriftProtocolPolicy = exports.DriftVaultsPolicy = exports.TransferPolicy = exports.MintPolicy = void 0;
1281
+ exports.CctpPolicy = exports.KaminoVaultsPolicy = exports.KaminoLendingPolicy = exports.DriftProtocolPolicy = exports.DriftVaultsPolicy = exports.TransferPolicy = exports.JupiterSwapPolicy = exports.MintPolicy = void 0;
1359
1282
  const borsh_1 = __webpack_require__(22);
1360
1283
  class MintPolicy {
1361
1284
  constructor(lockupPeriod, maxCap, minSubscription, minRedemption, reserved, allowlist, blocklist) {
@@ -1397,13 +1320,38 @@ MintPolicy._layout = (0, borsh_1.struct)([
1397
1320
  (0, borsh_1.option)((0, borsh_1.vec)((0, borsh_1.publicKey)()), "allowlist"),
1398
1321
  (0, borsh_1.option)((0, borsh_1.vec)((0, borsh_1.publicKey)()), "blocklist"),
1399
1322
  ]);
1323
+ class JupiterSwapPolicy {
1324
+ constructor(maxSlippageBps, swapAllowlist) {
1325
+ this.maxSlippageBps = maxSlippageBps;
1326
+ this.swapAllowlist = swapAllowlist;
1327
+ }
1328
+ static decode(buffer) {
1329
+ const policy = JupiterSwapPolicy._layout.decode(buffer);
1330
+ return new JupiterSwapPolicy(policy.maxSlippageBps, policy.swapAllowlist);
1331
+ }
1332
+ encode() {
1333
+ const swapAllowlistSize = this.swapAllowlist
1334
+ ? 1 + 4 + this.swapAllowlist.length * 32
1335
+ : 1;
1336
+ const totalSize = 4 + swapAllowlistSize;
1337
+ const buffer = Buffer.alloc(totalSize);
1338
+ JupiterSwapPolicy._layout.encode(this, buffer);
1339
+ return buffer;
1340
+ }
1341
+ }
1342
+ exports.JupiterSwapPolicy = JupiterSwapPolicy;
1343
+ JupiterSwapPolicy._layout = (0, borsh_1.struct)([
1344
+ (0, borsh_1.u32)("maxSlippageBps"),
1345
+ (0, borsh_1.option)((0, borsh_1.vec)((0, borsh_1.publicKey)()), "swapAllowlist"),
1346
+ ]);
1347
+ // System Program and Token Program use the same TransferPolicy struct
1400
1348
  class TransferPolicy {
1401
1349
  constructor(allowlist) {
1402
1350
  this.allowlist = allowlist;
1403
1351
  }
1404
1352
  static decode(buffer) {
1405
- const data = TransferPolicy._layout.decode(buffer);
1406
- return data;
1353
+ const { allowlist } = TransferPolicy._layout.decode(buffer);
1354
+ return new TransferPolicy(allowlist);
1407
1355
  }
1408
1356
  encode() {
1409
1357
  const header = Buffer.alloc(4);
@@ -1467,6 +1415,47 @@ DriftProtocolPolicy._layout = (0, borsh_1.struct)([
1467
1415
  (0, borsh_1.vec)((0, borsh_1.u16)(), "perpMarketsAllowlist"),
1468
1416
  (0, borsh_1.vec)((0, borsh_1.publicKey)(), "borrowAllowlist"),
1469
1417
  ]);
1418
+ class KaminoLendingPolicy {
1419
+ constructor(marketsAllowlist, borrowAllowlist) {
1420
+ this.marketsAllowlist = marketsAllowlist;
1421
+ this.borrowAllowlist = borrowAllowlist;
1422
+ }
1423
+ static decode(buffer) {
1424
+ const { marketsAllowlist, borrowAllowlist } = KaminoLendingPolicy._layout.decode(buffer);
1425
+ return new KaminoLendingPolicy(marketsAllowlist, borrowAllowlist);
1426
+ }
1427
+ encode() {
1428
+ const marketsAllowlistSize = 4 + this.marketsAllowlist.length * 32;
1429
+ const borrowAllowlistSize = 4 + this.borrowAllowlist.length * 32;
1430
+ const totalSize = marketsAllowlistSize + borrowAllowlistSize;
1431
+ const buffer = Buffer.alloc(totalSize);
1432
+ KaminoLendingPolicy._layout.encode(this, buffer);
1433
+ return buffer;
1434
+ }
1435
+ }
1436
+ exports.KaminoLendingPolicy = KaminoLendingPolicy;
1437
+ KaminoLendingPolicy._layout = (0, borsh_1.struct)([
1438
+ (0, borsh_1.vec)((0, borsh_1.publicKey)(), "marketsAllowlist"),
1439
+ (0, borsh_1.vec)((0, borsh_1.publicKey)(), "borrowAllowlist"),
1440
+ ]);
1441
+ class KaminoVaultsPolicy {
1442
+ constructor(vaultsAllowlist) {
1443
+ this.vaultsAllowlist = vaultsAllowlist;
1444
+ }
1445
+ static decode(buffer) {
1446
+ const { vaultsAllowlist } = KaminoVaultsPolicy._layout.decode(buffer);
1447
+ return new KaminoVaultsPolicy(vaultsAllowlist);
1448
+ }
1449
+ encode() {
1450
+ const vaultsAllowlistSize = 4 + this.vaultsAllowlist.length * 32;
1451
+ const totalSize = vaultsAllowlistSize;
1452
+ const buffer = Buffer.alloc(totalSize);
1453
+ KaminoVaultsPolicy._layout.encode(this, buffer);
1454
+ return buffer;
1455
+ }
1456
+ }
1457
+ exports.KaminoVaultsPolicy = KaminoVaultsPolicy;
1458
+ KaminoVaultsPolicy._layout = (0, borsh_1.struct)([(0, borsh_1.vec)((0, borsh_1.publicKey)(), "vaultsAllowlist")]);
1470
1459
  class CctpPolicy {
1471
1460
  constructor(allowedDestinations) {
1472
1461
  this.allowedDestinations = allowedDestinations;
@@ -2333,6 +2322,15 @@ class BaseClient {
2333
2322
  return models_1.StateModel.fromOnchainAccounts(publicKey, stateAccount, mintsCache.get(stateAccount.mint.toBase58()), this.protocolProgram.programId);
2334
2323
  });
2335
2324
  }
2325
+ async fetchProtocolPolicy(integProgramId, protocolBitflag, policyClass) {
2326
+ const stateAccount = await this.fetchStateAccount();
2327
+ const integrationPolicy = stateAccount.integrationAcls?.find((acl) => acl.integrationProgram.equals(integProgramId));
2328
+ const policyData = integrationPolicy?.protocolPolicies?.find((policy) => policy.protocolBitflag === protocolBitflag)?.data;
2329
+ if (policyData) {
2330
+ return policyClass.decode(policyData);
2331
+ }
2332
+ return null;
2333
+ }
2336
2334
  }
2337
2335
  exports.BaseClient = BaseClient;
2338
2336
 
@@ -4930,17 +4928,6 @@ class TxBuilder {
4930
4928
  });
4931
4929
  };
4932
4930
  }
4933
- async setJupiterSwapPolicy(policy, txOptions = {}) {
4934
- const glamSigner = txOptions.signer || this.base.getSigner();
4935
- const tx = await this.base.protocolProgram.methods
4936
- .setJupiterSwapPolicy(policy)
4937
- .accounts({
4938
- glamState: this.base.statePda,
4939
- glamSigner,
4940
- })
4941
- .transaction();
4942
- return this.base.intoVersionedTransaction(tx, txOptions);
4943
- }
4944
4931
  async swap(options, txOptions = {}) {
4945
4932
  const glamSigner = txOptions.signer || this.base.getSigner();
4946
4933
  const glamVault = this.base.vaultPda;
@@ -5020,10 +5007,6 @@ class JupiterSwapClient {
5020
5007
  const tx = await this.txBuilder.swap(options, txOptions);
5021
5008
  return await this.base.sendAndConfirm(tx);
5022
5009
  }
5023
- async setJupiterSwapPolicy(policy, txOptions = {}) {
5024
- const tx = await this.txBuilder.setJupiterSwapPolicy(policy, txOptions);
5025
- return await this.base.sendAndConfirm(tx);
5026
- }
5027
5010
  }
5028
5011
  exports.JupiterSwapClient = JupiterSwapClient;
5029
5012
 
@@ -9248,27 +9231,16 @@ const anchor_1 = __webpack_require__(4);
9248
9231
  const glam_sdk_1 = __webpack_require__(1);
9249
9232
  const utils_1 = __webpack_require__(55);
9250
9233
  const web3_js_1 = __webpack_require__(15);
9251
- async function fetchDriftProtocolPolicy(context) {
9252
- const programId = context.glamClient.extDriftProgram.programId;
9253
- const protocolBitflag = 0b01;
9254
- const stateAccount = await context.glamClient.fetchStateAccount();
9255
- const integrationPolicy = stateAccount.integrationAcls?.find((acl) => acl.integrationProgram.toString() === programId.toString());
9256
- const policyData = integrationPolicy?.protocolPolicies?.find((policy) => policy.protocolBitflag === protocolBitflag)?.data;
9257
- if (policyData) {
9258
- return glam_sdk_1.DriftProtocolPolicy.decode(policyData);
9259
- }
9260
- return null;
9261
- }
9262
9234
  function installDriftProtocolCommands(drift, context) {
9263
9235
  drift
9264
9236
  .command("view-policy")
9265
9237
  .description("View drift policy")
9266
9238
  .action(async () => {
9267
- const policy = await fetchDriftProtocolPolicy(context);
9239
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, glam_sdk_1.DriftProtocolPolicy);
9268
9240
  console.log(policy);
9269
9241
  });
9270
9242
  drift
9271
- .command("add-market")
9243
+ .command("allowlist-market")
9272
9244
  .argument("<market_type>", "Market type", (v) => {
9273
9245
  if (v !== "spot" && v !== "perp") {
9274
9246
  console.error("Invalid market type, must be 'spot' or 'perp'");
@@ -9279,8 +9251,7 @@ function installDriftProtocolCommands(drift, context) {
9279
9251
  .argument("<market_index>", "Spot or perp market index", parseInt)
9280
9252
  .description("Add a market to the allowlist")
9281
9253
  .action(async (marketType, marketIndex) => {
9282
- const policy = (await fetchDriftProtocolPolicy(context)) ??
9283
- new glam_sdk_1.DriftProtocolPolicy([], [], []);
9254
+ const policy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, glam_sdk_1.DriftProtocolPolicy)) ?? new glam_sdk_1.DriftProtocolPolicy([], [], []);
9284
9255
  if (marketType === "spot") {
9285
9256
  policy.spotMarketsAllowlist.push(marketIndex);
9286
9257
  }
@@ -9289,7 +9260,7 @@ function installDriftProtocolCommands(drift, context) {
9289
9260
  }
9290
9261
  try {
9291
9262
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, policy.encode(), context.txOptions);
9292
- console.log(`Drift policy updated:`, txSig);
9263
+ console.log(`${marketType} market ${marketIndex} added to allowlist:`, txSig);
9293
9264
  }
9294
9265
  catch (e) {
9295
9266
  console.error((0, utils_1.parseTxError)(e));
@@ -9297,7 +9268,7 @@ function installDriftProtocolCommands(drift, context) {
9297
9268
  }
9298
9269
  });
9299
9270
  drift
9300
- .command("delete-market")
9271
+ .command("remove-market")
9301
9272
  .argument("<market_type>", "Market type", (v) => {
9302
9273
  if (v !== "spot" && v !== "perp") {
9303
9274
  console.error("Invalid market type, must be 'spot' or 'perp'");
@@ -9308,7 +9279,7 @@ function installDriftProtocolCommands(drift, context) {
9308
9279
  .argument("<market_index>", "Spot or perp market index", parseInt)
9309
9280
  .description("Remove a market from the allowlist")
9310
9281
  .action(async (marketType, marketIndex) => {
9311
- const policy = await fetchDriftProtocolPolicy(context);
9282
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, glam_sdk_1.DriftProtocolPolicy);
9312
9283
  if (!policy) {
9313
9284
  console.error("Drift policy not found");
9314
9285
  process.exit(1);
@@ -9321,7 +9292,7 @@ function installDriftProtocolCommands(drift, context) {
9321
9292
  }
9322
9293
  try {
9323
9294
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, policy.encode(), context.txOptions);
9324
- console.log(`Drift policy updated:`, txSig);
9295
+ console.log(`${marketType} market ${marketIndex} removed from allowlist:`, txSig);
9325
9296
  }
9326
9297
  catch (e) {
9327
9298
  console.error((0, utils_1.parseTxError)(e));
@@ -9329,20 +9300,15 @@ function installDriftProtocolCommands(drift, context) {
9329
9300
  }
9330
9301
  });
9331
9302
  drift
9332
- .command("add-borrowable-asset")
9303
+ .command("allowlist-borrowable-asset")
9333
9304
  .argument("<token_mint>", "Token mint public key", utils_1.validatePublicKey)
9334
- .description("Add a borrowable asset")
9305
+ .description("Add a borrowable asset to the allowlist")
9335
9306
  .action(async (tokenMint) => {
9336
- const policy = (await fetchDriftProtocolPolicy(context)) ||
9337
- new glam_sdk_1.DriftProtocolPolicy([], [], []);
9338
- if (!policy) {
9339
- console.error("Drift policy not found");
9340
- process.exit(1);
9341
- }
9307
+ const policy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, glam_sdk_1.DriftProtocolPolicy)) ?? new glam_sdk_1.DriftProtocolPolicy([], [], []);
9342
9308
  policy.borrowAllowlist.push(tokenMint);
9343
9309
  try {
9344
9310
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, policy.encode(), context.txOptions);
9345
- console.log(`Drift policy updated:`, txSig);
9311
+ console.log(`Borrowable asset ${tokenMint} added to allowlist:`, txSig);
9346
9312
  }
9347
9313
  catch (e) {
9348
9314
  console.error((0, utils_1.parseTxError)(e));
@@ -9350,10 +9316,11 @@ function installDriftProtocolCommands(drift, context) {
9350
9316
  }
9351
9317
  });
9352
9318
  drift
9353
- .command("delete-borrowable-asset")
9319
+ .command("remove-borrowable-asset")
9354
9320
  .argument("<token_mint>", "Token mint public key", utils_1.validatePublicKey)
9321
+ .description("Remove a borrowable asset from the allowlist")
9355
9322
  .action(async (tokenMint) => {
9356
- const policy = await fetchDriftProtocolPolicy(context);
9323
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, glam_sdk_1.DriftProtocolPolicy);
9357
9324
  if (!policy) {
9358
9325
  console.error("Drift policy not found");
9359
9326
  process.exit(1);
@@ -9361,7 +9328,7 @@ function installDriftProtocolCommands(drift, context) {
9361
9328
  policy.borrowAllowlist = policy.borrowAllowlist.filter((m) => !m.equals(tokenMint));
9362
9329
  try {
9363
9330
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b01, policy.encode(), context.txOptions);
9364
- console.log(`Drift policy updated:`, txSig);
9331
+ console.log(`Borrowable asset ${tokenMint} removed from allowlist:`, txSig);
9365
9332
  }
9366
9333
  catch (e) {
9367
9334
  console.error((0, utils_1.parseTxError)(e));
@@ -9672,30 +9639,6 @@ function installDriftProtocolCommands(drift, context) {
9672
9639
  process.exit(1);
9673
9640
  }
9674
9641
  });
9675
- // drift
9676
- // .command("claim")
9677
- // .description("")
9678
- // .action(async () => {
9679
- // const response = await fetch(
9680
- // `https://airdrop-fuel-1.drift.trade/eligibility/${context.glamClient.vaultPda}`,
9681
- // );
9682
- // const data = await response.json();
9683
- // const { merkle_tree, proof, claimable_amount, locked_amount } = data;
9684
- // const distributor = new PublicKey(merkle_tree);
9685
- // try {
9686
- // const txSig = await context.glamClient.drift.claim(
9687
- // distributor,
9688
- // new BN(claimable_amount),
9689
- // new BN(locked_amount),
9690
- // proof,
9691
- // context.txOptions,
9692
- // );
9693
- // console.log(`${claimable_amount / 1e6} DRIFT claimed: ${txSig}`);
9694
- // } catch (e) {
9695
- // console.error(e);
9696
- // process.exit(1);
9697
- // }
9698
- // });
9699
9642
  }
9700
9643
 
9701
9644
 
@@ -9711,23 +9654,12 @@ const anchor_1 = __webpack_require__(4);
9711
9654
  const utils_1 = __webpack_require__(55);
9712
9655
  const tokens_verified_json_1 = tslib_1.__importDefault(__webpack_require__(62));
9713
9656
  const glam_sdk_1 = __webpack_require__(1);
9714
- async function fetchDriftVaultsPolicy(context) {
9715
- const programId = context.glamClient.extDriftProgram.programId;
9716
- const protocolBitflag = 0b10;
9717
- const stateAccount = await context.glamClient.fetchStateAccount();
9718
- const integrationPolicy = stateAccount.integrationAcls?.find((acl) => acl.integrationProgram.toString() === programId.toString());
9719
- const policyData = integrationPolicy?.protocolPolicies?.find((policy) => policy.protocolBitflag === protocolBitflag)?.data;
9720
- if (policyData) {
9721
- return glam_sdk_1.DriftVaultsPolicy.decode(policyData);
9722
- }
9723
- return null;
9724
- }
9725
9657
  function installDriftVaultsCommands(driftVaults, context) {
9726
9658
  driftVaults
9727
9659
  .command("view-policy")
9728
9660
  .description("View Drift vaults policy")
9729
9661
  .action(async () => {
9730
- const policy = await fetchDriftVaultsPolicy(context);
9662
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b10, glam_sdk_1.DriftVaultsPolicy);
9731
9663
  if (!policy) {
9732
9664
  console.log("No policy found");
9733
9665
  return;
@@ -9738,19 +9670,19 @@ function installDriftVaultsCommands(driftVaults, context) {
9738
9670
  }
9739
9671
  });
9740
9672
  driftVaults
9741
- .command("add-vault")
9673
+ .command("allowlist-vault")
9742
9674
  .argument("<vault>", "Drift vault public key", utils_1.validatePublicKey)
9743
- .description("Add a vault to the Drift vaults allowlist")
9675
+ .description("Add a Drift vault to the allowlist")
9744
9676
  .action(async (vault) => {
9745
- const policy = (await fetchDriftVaultsPolicy(context)) ?? new glam_sdk_1.DriftVaultsPolicy([]);
9677
+ const policy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b10, glam_sdk_1.DriftVaultsPolicy)) ?? new glam_sdk_1.DriftVaultsPolicy([]);
9746
9678
  if (policy.vaultsAllowlist.find((v) => v.equals(vault))) {
9747
- console.error("Vault already allowed");
9679
+ console.error(`Drift vault ${vault} is already in the allowlist`);
9748
9680
  process.exit(1);
9749
9681
  }
9750
9682
  policy.vaultsAllowlist.push(vault);
9751
9683
  try {
9752
9684
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b10, policy.encode(), context.txOptions);
9753
- console.log(`Drift vaults policy updated:`, txSig);
9685
+ console.log(`Drift vault ${vault} added to allowlist:`, txSig);
9754
9686
  }
9755
9687
  catch (e) {
9756
9688
  console.error((0, utils_1.parseTxError)(e));
@@ -9758,23 +9690,23 @@ function installDriftVaultsCommands(driftVaults, context) {
9758
9690
  }
9759
9691
  });
9760
9692
  driftVaults
9761
- .command("delete-vault")
9693
+ .command("remove-vault")
9762
9694
  .argument("<vault>", "Drift vault public key", utils_1.validatePublicKey)
9763
- .description("Remove a vault from the Drift vaults allowlist")
9695
+ .description("Remove a Drift vault from the allowlist")
9764
9696
  .action(async (vault) => {
9765
- const policy = await fetchDriftVaultsPolicy(context);
9697
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b10, glam_sdk_1.DriftVaultsPolicy);
9766
9698
  if (!policy) {
9767
9699
  console.error("No policy found");
9768
9700
  process.exit(1);
9769
9701
  }
9770
9702
  if (!policy.vaultsAllowlist.find((v) => v.equals(vault))) {
9771
- console.error("Vault not in allowlist.");
9703
+ console.error("Vault not in allowlist. Removal not needed.");
9772
9704
  process.exit(1);
9773
9705
  }
9774
9706
  policy.vaultsAllowlist = policy.vaultsAllowlist.filter((v) => !v.equals(vault));
9775
9707
  try {
9776
9708
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extDriftProgram.programId, 0b10, policy.encode(), context.txOptions);
9777
- console.log(`Drift vaults policy updated:`, txSig);
9709
+ console.log(`Drift vault ${vault} removed from allowlist:`, txSig);
9778
9710
  }
9779
9711
  catch (e) {
9780
9712
  console.error((0, utils_1.parseTxError)(e));
@@ -9997,6 +9929,112 @@ const glam_sdk_1 = __webpack_require__(1);
9997
9929
  const utils_1 = __webpack_require__(55);
9998
9930
  const web3_js_1 = __webpack_require__(15);
9999
9931
  function installKaminoLendCommands(klend, context) {
9932
+ klend
9933
+ .command("view-policy")
9934
+ .description("View Kamino lending policy")
9935
+ .action(async () => {
9936
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, glam_sdk_1.KaminoLendingPolicy);
9937
+ if (!policy) {
9938
+ console.log("No policy found");
9939
+ return;
9940
+ }
9941
+ console.log("Kamino lending markets allowlist:");
9942
+ for (let i = 0; i < policy.marketsAllowlist.length; i++) {
9943
+ console.log(`[${i}] ${policy.marketsAllowlist[i]}`);
9944
+ }
9945
+ console.log("Kamino lending borrowable assets allowlist:");
9946
+ for (let i = 0; i < policy.borrowAllowlist.length; i++) {
9947
+ console.log(`[${i}] ${policy.borrowAllowlist[i]}`);
9948
+ }
9949
+ });
9950
+ klend
9951
+ .command("allowlist-market")
9952
+ .argument("<market>", "Kamino lending market public key", utils_1.validatePublicKey)
9953
+ .description("Add a market to the allowlist")
9954
+ .action(async (market) => {
9955
+ const policy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, glam_sdk_1.KaminoLendingPolicy)) ?? new glam_sdk_1.KaminoLendingPolicy([], []);
9956
+ if (policy.marketsAllowlist.find((m) => m.equals(market))) {
9957
+ console.error(`Kamino market ${market} is already in the allowlist`);
9958
+ process.exit(1);
9959
+ }
9960
+ policy.marketsAllowlist.push(market);
9961
+ try {
9962
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, policy.encode(), context.txOptions);
9963
+ console.log(`Kamino market ${market} added to allowlist:`, txSig);
9964
+ }
9965
+ catch (e) {
9966
+ console.error((0, utils_1.parseTxError)(e));
9967
+ process.exit(1);
9968
+ }
9969
+ });
9970
+ klend
9971
+ .command("remove-market")
9972
+ .argument("<market>", "Kamino lending market public key", utils_1.validatePublicKey)
9973
+ .description("Remove a market from the allowlist")
9974
+ .action(async (market) => {
9975
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, glam_sdk_1.KaminoLendingPolicy);
9976
+ if (!policy) {
9977
+ console.error("No policy found");
9978
+ process.exit(1);
9979
+ }
9980
+ if (!policy.marketsAllowlist.find((m) => m.equals(market))) {
9981
+ console.error("Market not in allowlist. Removal not needed.");
9982
+ process.exit(1);
9983
+ }
9984
+ policy.marketsAllowlist = policy.marketsAllowlist.filter((m) => !m.equals(market));
9985
+ try {
9986
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, policy.encode(), context.txOptions);
9987
+ console.log(`Kamino market ${market} removed from allowlist:`, txSig);
9988
+ }
9989
+ catch (e) {
9990
+ console.error((0, utils_1.parseTxError)(e));
9991
+ process.exit(1);
9992
+ }
9993
+ });
9994
+ klend
9995
+ .command("allowlist-borrowable-asset")
9996
+ .argument("<asset>", "Borrowable asset public key", utils_1.validatePublicKey)
9997
+ .description("Add a borrowable asset to the allowlist")
9998
+ .action(async (asset) => {
9999
+ const policy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, glam_sdk_1.KaminoLendingPolicy)) ?? new glam_sdk_1.KaminoLendingPolicy([], []);
10000
+ if (policy.borrowAllowlist.find((a) => a.equals(asset))) {
10001
+ console.error(`Borrowable asset ${asset} is already in the allowlist`);
10002
+ process.exit(1);
10003
+ }
10004
+ policy.borrowAllowlist.push(asset);
10005
+ try {
10006
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, policy.encode(), context.txOptions);
10007
+ console.log(`Borrowable asset ${asset} added to allowlist:`, txSig);
10008
+ }
10009
+ catch (e) {
10010
+ console.error((0, utils_1.parseTxError)(e));
10011
+ process.exit(1);
10012
+ }
10013
+ });
10014
+ klend
10015
+ .command("remove-borrowable-asset")
10016
+ .argument("<asset>", "Borrowable asset public key", utils_1.validatePublicKey)
10017
+ .description("Remove a borrowable asset from the allowlist")
10018
+ .action(async (asset) => {
10019
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, glam_sdk_1.KaminoLendingPolicy);
10020
+ if (!policy) {
10021
+ console.error("No policy found");
10022
+ process.exit(1);
10023
+ }
10024
+ if (!policy.borrowAllowlist.find((a) => a.equals(asset))) {
10025
+ console.error("Borrowable asset not in allowlist. Removal not needed.");
10026
+ process.exit(1);
10027
+ }
10028
+ policy.borrowAllowlist = policy.borrowAllowlist.filter((a) => !a.equals(asset));
10029
+ try {
10030
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b01, policy.encode(), context.txOptions);
10031
+ console.log(`Borrowable asset ${asset} removed from allowlist:`, txSig);
10032
+ }
10033
+ catch (e) {
10034
+ console.error((0, utils_1.parseTxError)(e));
10035
+ process.exit(1);
10036
+ }
10037
+ });
10000
10038
  klend
10001
10039
  .command("init")
10002
10040
  .description("Initialize Kamino user")
@@ -10115,7 +10153,66 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
10115
10153
  exports.installKaminoVaultsCommands = installKaminoVaultsCommands;
10116
10154
  const anchor_1 = __webpack_require__(4);
10117
10155
  const utils_1 = __webpack_require__(55);
10156
+ const glam_sdk_1 = __webpack_require__(1);
10118
10157
  function installKaminoVaultsCommands(kvaults, context) {
10158
+ kvaults
10159
+ .command("view-policy")
10160
+ .description("View Kamino vaults policy")
10161
+ .action(async () => {
10162
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b10, glam_sdk_1.KaminoVaultsPolicy);
10163
+ if (!policy) {
10164
+ console.log("No policy found");
10165
+ return;
10166
+ }
10167
+ console.log("Kamino vaults allowlist:");
10168
+ for (let i = 0; i < policy.vaultsAllowlist.length; i++) {
10169
+ console.log(`[${i}] ${policy.vaultsAllowlist[i]}`);
10170
+ }
10171
+ });
10172
+ kvaults
10173
+ .command("allowlist-vault")
10174
+ .argument("<vault>", "Kamino vault public key", utils_1.validatePublicKey)
10175
+ .description("Add a vault to the allowlist")
10176
+ .action(async (vault) => {
10177
+ const policy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b10, glam_sdk_1.KaminoVaultsPolicy)) ?? new glam_sdk_1.KaminoVaultsPolicy([]);
10178
+ if (policy.vaultsAllowlist.find((v) => v.equals(vault))) {
10179
+ console.error(`Kamino vault ${vault} is already in the allowlist`);
10180
+ process.exit(1);
10181
+ }
10182
+ policy.vaultsAllowlist.push(vault);
10183
+ try {
10184
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b10, policy.encode(), context.txOptions);
10185
+ console.log(`Kamino vault ${vault} added to allowlist:`, txSig);
10186
+ }
10187
+ catch (e) {
10188
+ console.error((0, utils_1.parseTxError)(e));
10189
+ process.exit(1);
10190
+ }
10191
+ });
10192
+ kvaults
10193
+ .command("remove-vault")
10194
+ .argument("<vault>", "Kamino vault public key", utils_1.validatePublicKey)
10195
+ .description("Remove a vault from the allowlist")
10196
+ .action(async (vault) => {
10197
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b10, glam_sdk_1.KaminoVaultsPolicy);
10198
+ if (!policy) {
10199
+ console.error("No policy found");
10200
+ process.exit(1);
10201
+ }
10202
+ if (!policy.vaultsAllowlist.find((v) => v.equals(vault))) {
10203
+ console.error("Vault not in allowlist. Removal not needed.");
10204
+ process.exit(1);
10205
+ }
10206
+ policy.vaultsAllowlist = policy.vaultsAllowlist.filter((v) => !v.equals(vault));
10207
+ try {
10208
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extKaminoProgram.programId, 0b10, policy.encode(), context.txOptions);
10209
+ console.log(`Kamino vault ${vault} removed from allowlist:`, txSig);
10210
+ }
10211
+ catch (e) {
10212
+ console.error((0, utils_1.parseTxError)(e));
10213
+ process.exit(1);
10214
+ }
10215
+ });
10119
10216
  kvaults
10120
10217
  .command("deposit")
10121
10218
  .argument("<vault>", "Kamino vault public key", utils_1.validatePublicKey)
@@ -10400,6 +10497,110 @@ exports.installJupiterCommands = installJupiterCommands;
10400
10497
  const glam_sdk_1 = __webpack_require__(1);
10401
10498
  const utils_1 = __webpack_require__(55);
10402
10499
  function installJupiterCommands(program, context) {
10500
+ program
10501
+ .command("view-policy")
10502
+ .description("View Jupiter swap policy")
10503
+ .action(async () => {
10504
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, glam_sdk_1.JupiterSwapPolicy);
10505
+ if (!policy) {
10506
+ console.log("No policy found");
10507
+ return;
10508
+ }
10509
+ console.log(`Max slippage BPS: ${policy.maxSlippageBps}`);
10510
+ if (policy.swapAllowlist) {
10511
+ console.log("Swap allowlist:");
10512
+ for (let i = 0; i < policy.swapAllowlist.length; i++) {
10513
+ console.log(`[${i}] ${policy.swapAllowlist[i]}`);
10514
+ }
10515
+ }
10516
+ else {
10517
+ console.log("Swap allowlist: None (all tokens allowed)");
10518
+ }
10519
+ });
10520
+ program
10521
+ .command("set-max-slippage")
10522
+ .argument("<slippage_bps>", "Maximum slippage in basis points", parseInt)
10523
+ .description("Set the maximum allowed slippage for swaps")
10524
+ .action(async (slippageBps) => {
10525
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, glam_sdk_1.JupiterSwapPolicy);
10526
+ const currentAllowlist = policy?.swapAllowlist || null;
10527
+ const newPolicy = new glam_sdk_1.JupiterSwapPolicy(slippageBps, currentAllowlist);
10528
+ try {
10529
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, newPolicy.encode(), context.txOptions);
10530
+ console.log(`Max slippage set to ${slippageBps} BPS:`, txSig);
10531
+ }
10532
+ catch (e) {
10533
+ console.error((0, utils_1.parseTxError)(e));
10534
+ process.exit(1);
10535
+ }
10536
+ });
10537
+ program
10538
+ .command("allowlist-token")
10539
+ .argument("<token>", "Token mint public key", utils_1.validatePublicKey)
10540
+ .description("Add a token to the swap allowlist")
10541
+ .action(async (token) => {
10542
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, glam_sdk_1.JupiterSwapPolicy);
10543
+ const currentSlippage = policy?.maxSlippageBps || 50; // Default 50 BPS
10544
+ const currentAllowlist = policy?.swapAllowlist || [];
10545
+ if (currentAllowlist.find((t) => t.equals(token))) {
10546
+ console.error(`Token ${token} is already in the allowlist`);
10547
+ process.exit(1);
10548
+ }
10549
+ const newAllowlist = [...currentAllowlist, token];
10550
+ const newPolicy = new glam_sdk_1.JupiterSwapPolicy(currentSlippage, newAllowlist);
10551
+ try {
10552
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, newPolicy.encode(), context.txOptions);
10553
+ console.log(`Token ${token} added to swap allowlist:`, txSig);
10554
+ }
10555
+ catch (e) {
10556
+ console.error((0, utils_1.parseTxError)(e));
10557
+ process.exit(1);
10558
+ }
10559
+ });
10560
+ program
10561
+ .command("remove-token")
10562
+ .argument("<token>", "Token mint public key", utils_1.validatePublicKey)
10563
+ .description("Remove a token from the swap allowlist")
10564
+ .action(async (token) => {
10565
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, glam_sdk_1.JupiterSwapPolicy);
10566
+ if (!policy || !policy.swapAllowlist) {
10567
+ console.error("No swap allowlist found");
10568
+ process.exit(1);
10569
+ }
10570
+ if (!policy.swapAllowlist.find((t) => t.equals(token))) {
10571
+ console.error("Token not in allowlist. Removal not needed.");
10572
+ process.exit(1);
10573
+ }
10574
+ const newAllowlist = policy.swapAllowlist.filter((t) => !t.equals(token));
10575
+ const newPolicy = new glam_sdk_1.JupiterSwapPolicy(policy.maxSlippageBps, newAllowlist.length > 0 ? newAllowlist : null);
10576
+ try {
10577
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, newPolicy.encode(), context.txOptions);
10578
+ console.log(`Token ${token} removed from swap allowlist:`, txSig);
10579
+ }
10580
+ catch (e) {
10581
+ console.error((0, utils_1.parseTxError)(e));
10582
+ process.exit(1);
10583
+ }
10584
+ });
10585
+ program
10586
+ .command("clear-allowlist")
10587
+ .description("Clear the swap allowlist (allow all tokens)")
10588
+ .action(async () => {
10589
+ const policy = await context.glamClient.fetchProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, glam_sdk_1.JupiterSwapPolicy);
10590
+ if (!policy) {
10591
+ console.error("No policy found");
10592
+ process.exit(1);
10593
+ }
10594
+ const newPolicy = new glam_sdk_1.JupiterSwapPolicy(policy.maxSlippageBps, null);
10595
+ try {
10596
+ const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.protocolProgram.programId, 0b0000100, newPolicy.encode(), context.txOptions);
10597
+ console.log(`Swap allowlist cleared (all tokens now allowed):`, txSig);
10598
+ }
10599
+ catch (e) {
10600
+ console.error((0, utils_1.parseTxError)(e));
10601
+ process.exit(1);
10602
+ }
10603
+ });
10403
10604
  program
10404
10605
  .command("swap <from> <to> <amount>")
10405
10606
  .description("Swap assets held in the vault")
@@ -11348,58 +11549,12 @@ const anchor_1 = __webpack_require__(4);
11348
11549
  const glam_sdk_1 = __webpack_require__(1);
11349
11550
  const glam_sdk_2 = __webpack_require__(1);
11350
11551
  const web3_js_1 = __webpack_require__(15);
11351
- async function fetchCctpPolicy(context) {
11352
- const cctpProgramId = context.glamClient.extCctpProgram.programId;
11353
- const cctpProtocolBitflag = 0b01;
11354
- const stateAccount = await context.glamClient.fetchStateAccount();
11355
- const cctpIntegrationPolicy = stateAccount.integrationAcls?.find((acl) => acl.integrationProgram.toString() === cctpProgramId.toString());
11356
- const cctpPolicyData = cctpIntegrationPolicy?.protocolPolicies?.find((policy) => policy.protocolBitflag === cctpProtocolBitflag)?.data;
11357
- if (cctpPolicyData) {
11358
- return glam_sdk_1.CctpPolicy.decode(cctpPolicyData);
11359
- }
11360
- return null;
11361
- }
11362
11552
  function installCctpCommands(program, context) {
11363
- // https://developers.circle.com/cctp/cctp-supported-blockchains#cctp-v2-supported-domains
11364
- program
11365
- .command("bridge-usdc")
11366
- .argument("<amount>", "USDC amount to bridge", parseFloat)
11367
- .argument("<domain>", "CCTP domain", parseInt)
11368
- .argument("<destination_address>", "EVM address")
11369
- .option("--base58", "Address is a base58 string")
11370
- .option("--fast", "Fast transfer", false)
11371
- .description("Bridge USDC to an EVM chain")
11372
- .action(async (amount, domain, destinationAddress, { base58, fast }) => {
11373
- const recipientPubkey = base58
11374
- ? new web3_js_1.PublicKey(destinationAddress)
11375
- : (0, glam_sdk_2.evmAddressToPublicKey)(destinationAddress);
11376
- const cctpPolicy = await fetchCctpPolicy(context);
11377
- if (cctpPolicy &&
11378
- !cctpPolicy.allowedDestinations.find((d) => d.domain === domain && d.address.equals(recipientPubkey))) {
11379
- console.error(`Destination (${domain}, ${destinationAddress}) not whitelisted`);
11380
- process.exit(1);
11381
- }
11382
- const amountBN = new anchor_1.BN(amount * 10 ** 6);
11383
- // https://developers.circle.com/cctp/technical-guide#cctp-finality-thresholds
11384
- const maxFee = amountBN.mul(new anchor_1.BN(1)).div(new anchor_1.BN(10 ** 4));
11385
- const minFinalityThreshold = fast ? 1000 : 2000;
11386
- try {
11387
- const txSig = await context.glamClient.vault.bridgeUsdc(amountBN, domain, recipientPubkey, {
11388
- maxFee,
11389
- minFinalityThreshold,
11390
- }, context.txOptions);
11391
- console.log(`Deposit for burn:`, txSig);
11392
- }
11393
- catch (e) {
11394
- console.error((0, utils_1.parseTxError)(e));
11395
- process.exit(1);
11396
- }
11397
- });
11398
11553
  program
11399
11554
  .command("view-policy")
11400
11555
  .description("View CCTP policy")
11401
11556
  .action(async () => {
11402
- const cctpPolicy = await fetchCctpPolicy(context);
11557
+ const cctpPolicy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extCctpProgram.programId, 0b01, glam_sdk_1.CctpPolicy);
11403
11558
  if (!cctpPolicy) {
11404
11559
  console.error("CCTP policy not found");
11405
11560
  process.exit(1);
@@ -11410,24 +11565,24 @@ function installCctpCommands(program, context) {
11410
11565
  }
11411
11566
  });
11412
11567
  program
11413
- .command("add-destination")
11568
+ .command("allowlist-destination")
11414
11569
  .argument("<domain>", "CCTP domain", parseInt)
11415
11570
  .argument("<destination_address>", "Destination address")
11416
11571
  .option("--base58", "Address is a base58 string")
11417
- .description("Whitelist a destination")
11572
+ .description("Add a destination to the allowlist")
11418
11573
  .action(async (domain, destinationAddress, { base58 }) => {
11419
11574
  const recipientPubkey = base58
11420
11575
  ? new web3_js_1.PublicKey(destinationAddress)
11421
11576
  : (0, glam_sdk_2.evmAddressToPublicKey)(destinationAddress);
11422
- const cctpPolicy = (await fetchCctpPolicy(context)) ?? new glam_sdk_1.CctpPolicy([]);
11577
+ const cctpPolicy = (await context.glamClient.fetchProtocolPolicy(context.glamClient.extCctpProgram.programId, 0b01, glam_sdk_1.CctpPolicy)) ?? new glam_sdk_1.CctpPolicy([]);
11423
11578
  if (cctpPolicy.allowedDestinations.find((d) => d.domain === domain && d.address.equals(recipientPubkey))) {
11424
- console.error(`Destination address ${destinationAddress} already whitelisted`);
11579
+ console.error(`Destination address ${destinationAddress} is already in the allowlist`);
11425
11580
  process.exit(1);
11426
11581
  }
11427
11582
  cctpPolicy.allowedDestinations.push({ domain, address: recipientPubkey });
11428
11583
  try {
11429
11584
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extCctpProgram.programId, 0b01, cctpPolicy.encode(), context.txOptions);
11430
- console.log(`CCTP policy updated:`, txSig);
11585
+ console.log(`Destination ${destinationAddress} (domain ${domain}) added to allowlist:`, txSig);
11431
11586
  }
11432
11587
  catch (e) {
11433
11588
  console.error((0, utils_1.parseTxError)(e));
@@ -11435,16 +11590,16 @@ function installCctpCommands(program, context) {
11435
11590
  }
11436
11591
  });
11437
11592
  program
11438
- .command("delete-destination")
11593
+ .command("remove-destination")
11439
11594
  .argument("<domain>", "CCTP domain", parseInt)
11440
11595
  .argument("<destination_address>", "Destination address")
11441
11596
  .option("--base58", "Address is a base58 string")
11442
- .description("Remove a destination address from whitelist")
11597
+ .description("Remove a destination from the allowlist")
11443
11598
  .action(async (domain, destinationAddress, { base58 }) => {
11444
11599
  const recipientPubkey = base58
11445
11600
  ? new web3_js_1.PublicKey(destinationAddress)
11446
11601
  : (0, glam_sdk_2.evmAddressToPublicKey)(destinationAddress);
11447
- const cctpPolicy = await fetchCctpPolicy(context);
11602
+ const cctpPolicy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extCctpProgram.programId, 0b01, glam_sdk_1.CctpPolicy);
11448
11603
  if (!cctpPolicy) {
11449
11604
  console.error(`CCTP policy not found`);
11450
11605
  process.exit(1);
@@ -11452,7 +11607,42 @@ function installCctpCommands(program, context) {
11452
11607
  cctpPolicy.allowedDestinations = cctpPolicy.allowedDestinations.filter((d) => !(d.domain === domain && d.address.equals(recipientPubkey)));
11453
11608
  try {
11454
11609
  const txSig = await context.glamClient.access.setProtocolPolicy(context.glamClient.extCctpProgram.programId, 0b01, cctpPolicy.encode(), context.txOptions);
11455
- console.log(`CCTP policy updated:`, txSig);
11610
+ console.log(`Destination ${destinationAddress} (domain ${domain}) removed from allowlist:`, txSig);
11611
+ }
11612
+ catch (e) {
11613
+ console.error((0, utils_1.parseTxError)(e));
11614
+ process.exit(1);
11615
+ }
11616
+ });
11617
+ // https://developers.circle.com/cctp/cctp-supported-blockchains#cctp-v2-supported-domains
11618
+ program
11619
+ .command("bridge-usdc")
11620
+ .argument("<amount>", "USDC amount to bridge", parseFloat)
11621
+ .argument("<domain>", "CCTP domain", parseInt)
11622
+ .argument("<destination_address>", "EVM address")
11623
+ .option("--base58", "Address is a base58 string")
11624
+ .option("--fast", "Fast transfer", false)
11625
+ .description("Bridge USDC to an EVM chain")
11626
+ .action(async (amount, domain, destinationAddress, { base58, fast }) => {
11627
+ const recipientPubkey = base58
11628
+ ? new web3_js_1.PublicKey(destinationAddress)
11629
+ : (0, glam_sdk_2.evmAddressToPublicKey)(destinationAddress);
11630
+ const cctpPolicy = await context.glamClient.fetchProtocolPolicy(context.glamClient.extCctpProgram.programId, 0b01, glam_sdk_1.CctpPolicy);
11631
+ if (cctpPolicy &&
11632
+ !cctpPolicy.allowedDestinations.find((d) => d.domain === domain && d.address.equals(recipientPubkey))) {
11633
+ console.error(`Destination (${domain}, ${destinationAddress}) not in allowlist`);
11634
+ process.exit(1);
11635
+ }
11636
+ const amountBN = new anchor_1.BN(amount * 10 ** 6);
11637
+ // https://developers.circle.com/cctp/technical-guide#cctp-finality-thresholds
11638
+ const maxFee = amountBN.mul(new anchor_1.BN(1)).div(new anchor_1.BN(10 ** 4));
11639
+ const minFinalityThreshold = fast ? 1000 : 2000;
11640
+ try {
11641
+ const txSig = await context.glamClient.vault.bridgeUsdc(amountBN, domain, recipientPubkey, {
11642
+ maxFee,
11643
+ minFinalityThreshold,
11644
+ }, context.txOptions);
11645
+ console.log(`Deposit for burn:`, txSig);
11456
11646
  }
11457
11647
  catch (e) {
11458
11648
  console.error((0, utils_1.parseTxError)(e));
@@ -11578,7 +11768,7 @@ program
11578
11768
  }
11579
11769
  await (0, idl_1.idlCheck)(context.glamClient);
11580
11770
  })
11581
- .version("0.2.0-alpha.3");
11771
+ .version("0.2.0-alpha.4");
11582
11772
  program
11583
11773
  .command("env")
11584
11774
  .description("Display current environment setup")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glamsystems/glam-cli",
3
- "version": "0.2.0-alpha.3",
3
+ "version": "0.2.0-alpha.4",
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": "0.2.0-alpha.3",
24
+ "@glamsystems/glam-sdk": "0.2.0-alpha.4",
25
25
  "commander": "^11.1.0",
26
26
  "inquirer": "^8.2.6",
27
27
  "@switchboard-xyz/common": "^3.0.0"