@glamsystems/glam-sdk 1.0.6 → 1.0.7

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/index.cjs.js CHANGED
@@ -3015,6 +3015,11 @@ var constants$d = [
3015
3015
  type: "u16",
3016
3016
  value: "1"
3017
3017
  },
3018
+ {
3019
+ name: "PROTO_SYSTEM_PERM_EMERGENCY_UPDATE",
3020
+ type: "u64",
3021
+ value: "4"
3022
+ },
3018
3023
  {
3019
3024
  name: "PROTO_SYSTEM_PERM_TRANSFER",
3020
3025
  type: "u64",
@@ -41803,27 +41808,69 @@ function getExtCctpProgram(provider) {
41803
41808
  return new anchor.Program(ExtCctpIdlJson, provider);
41804
41809
  }
41805
41810
 
41806
- /**
41807
- * Compares two sets for equality
41808
- */ const setsAreEqual = (a, b)=>{
41809
- if (a.size !== b.size) return false;
41810
- for (let item of a){
41811
- if (!b.has(item)) return false;
41812
- }
41813
- return true;
41814
- };
41815
41811
  /**
41816
41812
  * Converts a buffer or array of character codes to a string
41817
- */ function charsToName(chars) {
41813
+ */ function charsToString(chars) {
41818
41814
  return String.fromCharCode(...chars).replace(/\0/g, "").trim();
41819
41815
  }
41820
41816
  /**
41821
- * Converts a string to an array of character codes (max 32 bytes)
41822
- */ function nameToChars(name) {
41823
- return Array.from(Buffer.from(name).subarray(0, 32));
41817
+ * Converts a string to an array of character codes
41818
+ */ function stringToChars(name, length = 32) {
41819
+ return Array.from(Buffer.from(name).subarray(0, length));
41824
41820
  }
41825
- function toUiAmount(amount, decimals) {
41826
- return amount.toNumber() / 10 ** decimals;
41821
+ /**
41822
+ * Safely converts a BN amount to a UI amount (with decimals).
41823
+ *
41824
+ * @param amount - The amount in base units (BN)
41825
+ * @param decimals - The number of decimals (e.g., 9)
41826
+ * @returns The UI amount as a number
41827
+ *
41828
+ * @example
41829
+ * // Convert 10010000000 base units with 9 decimals
41830
+ * const uiAmount = toUiAmount(new BN(10010000000), 9); // Returns 10.01
41831
+ *
41832
+ * @throws Error if the BN amount is too large to safely convert to number
41833
+ */ function toUiAmount(amount, decimals) {
41834
+ const divisor = new anchor.BN(10).pow(new anchor.BN(decimals));
41835
+ const integerPart = amount.div(divisor);
41836
+ const fractionalPart = amount.mod(divisor);
41837
+ // Convert to number - will throw if too large for Number.MAX_SAFE_INTEGER
41838
+ const intNum = integerPart.toNumber();
41839
+ const fracNum = fractionalPart.toNumber();
41840
+ return intNum + fracNum / Math.pow(10, decimals);
41841
+ }
41842
+ /**
41843
+ * Safely converts a UI amount (with decimals) to a BN amount.
41844
+ *
41845
+ * @param amount - The UI amount (e.g., 10.01)
41846
+ * @param decimals - The number of decimals (e.g., 9)
41847
+ * @returns BN representing the amount in base units
41848
+ *
41849
+ * @example
41850
+ * // Convert 10.01 with 9 decimals
41851
+ * const amount = fromUiAmount(10.01, 9); // Returns BN(10010000000)
41852
+ */ function fromUiAmount(amount, decimals) {
41853
+ // Handle scientific notation by converting to fixed-point string
41854
+ let amountStr;
41855
+ if (typeof amount === "number") {
41856
+ // Convert number to fixed-point string to avoid scientific notation
41857
+ amountStr = amount.toFixed(decimals);
41858
+ } else {
41859
+ amountStr = amount;
41860
+ }
41861
+ const [integerPart, fractionalPart = ""] = amountStr.split(".");
41862
+ // Convert integer part
41863
+ const integerBN = new anchor.BN(integerPart || "0");
41864
+ // Convert fractional part
41865
+ let fractionalBN = new anchor.BN(0);
41866
+ if (fractionalPart) {
41867
+ // Pad or truncate fractional part to match decimals
41868
+ const paddedFractional = fractionalPart.padEnd(decimals, "0").slice(0, decimals);
41869
+ fractionalBN = new anchor.BN(paddedFractional);
41870
+ }
41871
+ // Combine: (integer * 10^decimals) + fractional
41872
+ const multiplier = new anchor.BN(10).pow(new anchor.BN(decimals));
41873
+ return integerBN.mul(multiplier).add(fractionalBN);
41827
41874
  }
41828
41875
 
41829
41876
  class MintPolicy {
@@ -42051,7 +42098,7 @@ class MintIdlModel {
42051
42098
  }
42052
42099
  class MintModel extends MintIdlModel {
42053
42100
  get nameStr() {
42054
- return this.name ? charsToName(this.name) : "";
42101
+ return this.name ? charsToString(this.name) : "";
42055
42102
  }
42056
42103
  constructor(data){
42057
42104
  super(data);
@@ -42171,27 +42218,32 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42171
42218
  3: "Exponent Market"
42172
42219
  };
42173
42220
  /**
42174
- * Get protocol and permission mappings at runtime to ensure correct program IDs based on environment
42221
+ * Get protocol and permission mappings at runtime to ensure correct program IDs based on environment.
42222
+ *
42223
+ * This method provides the source of truth for protocol and permission mappings and staging status in SDK.
42175
42224
  */ const getProtocolsAndPermissions = ()=>({
42176
42225
  // Supported protocols and permissions are defined in:
42177
42226
  // @anchor/programs/glam_protocol/src/state/acl.rs
42178
42227
  [getGlamProtocolProgramId().toBase58()]: {
42179
42228
  "0000000000000001": {
42180
- name: "System Program",
42229
+ name: "SystemProgram",
42230
+ staging: false,
42181
42231
  permissions: {
42182
42232
  [1 << 0]: "WSOL",
42183
42233
  [1 << 1]: "Transfer"
42184
42234
  }
42185
42235
  },
42186
42236
  "0000000000000010": {
42187
- name: "Stake Program",
42237
+ name: "StakeProgram",
42238
+ staging: true,
42188
42239
  permissions: {
42189
42240
  [1 << 0]: "Stake",
42190
42241
  [1 << 1]: "Unstake"
42191
42242
  }
42192
42243
  },
42193
42244
  "0000000000000100": {
42194
- name: "Jupiter Swap",
42245
+ name: "JupiterSwap",
42246
+ staging: false,
42195
42247
  permissions: {
42196
42248
  [1 << 0]: "SwapAny",
42197
42249
  [1 << 1]: "SwapLST",
@@ -42203,7 +42255,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42203
42255
  // @anchor/programs/glam_mint/src/state/acl.rs
42204
42256
  [getGlamMintProgramId().toBase58()]: {
42205
42257
  "0000000000000001": {
42206
- name: "Glam Mint",
42258
+ name: "GlamMint",
42259
+ staging: false,
42207
42260
  permissions: {
42208
42261
  [1 << 0]: "MintTokens",
42209
42262
  [1 << 1]: "BurnTokens",
@@ -42221,7 +42274,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42221
42274
  // @anchor/programs/ext_kamino/src/state/acl.rs
42222
42275
  [getExtKaminoProgramId().toBase58()]: {
42223
42276
  "0000000000000001": {
42224
- name: "Kamino Lend",
42277
+ name: "KaminoLend",
42278
+ staging: false,
42225
42279
  permissions: {
42226
42280
  [1 << 0]: "Init",
42227
42281
  [1 << 1]: "Deposit",
@@ -42231,14 +42285,16 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42231
42285
  }
42232
42286
  },
42233
42287
  "0000000000000010": {
42234
- name: "Kamino Vaults",
42288
+ name: "KaminoVaults",
42289
+ staging: false,
42235
42290
  permissions: {
42236
42291
  [1 << 0]: "Deposit",
42237
42292
  [1 << 1]: "Withdraw"
42238
42293
  }
42239
42294
  },
42240
42295
  "0000000000000100": {
42241
- name: "Kamino Farms",
42296
+ name: "KaminoFarms",
42297
+ staging: false,
42242
42298
  permissions: {
42243
42299
  [1 << 0]: "Stake",
42244
42300
  [1 << 1]: "Unstake",
@@ -42250,7 +42306,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42250
42306
  // @anchor/programs/ext_drift/src/state/acl.rs
42251
42307
  [getExtDriftProgramId().toBase58()]: {
42252
42308
  "0000000000000001": {
42253
- name: "Drift Protocol",
42309
+ name: "DriftProtocol",
42310
+ staging: false,
42254
42311
  permissions: {
42255
42312
  [1 << 0]: "InitUser",
42256
42313
  [1 << 1]: "UpdateUser",
@@ -42266,7 +42323,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42266
42323
  }
42267
42324
  },
42268
42325
  "0000000000000010": {
42269
- name: "Drift Vaults",
42326
+ name: "DriftVaults",
42327
+ staging: false,
42270
42328
  permissions: {
42271
42329
  [1 << 0]: "Deposit",
42272
42330
  [1 << 1]: "Withdraw"
@@ -42277,7 +42335,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42277
42335
  // @anchor/programs/ext_spl/src/state/acl.rs
42278
42336
  [getExtSplProgramId().toBase58()]: {
42279
42337
  "0000000000000001": {
42280
- name: "Spl Token",
42338
+ name: "SplToken",
42339
+ staging: false,
42281
42340
  permissions: {
42282
42341
  [1 << 0]: "Transfer"
42283
42342
  }
@@ -42288,6 +42347,7 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42288
42347
  [getExtCctpProgramId().toBase58()]: {
42289
42348
  "0000000000000001": {
42290
42349
  name: "CCTP",
42350
+ staging: false,
42291
42351
  permissions: {
42292
42352
  [1 << 0]: "Transfer"
42293
42353
  }
@@ -42298,6 +42358,7 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42298
42358
  [getExtMarinadeProgramId().toBase58()]: {
42299
42359
  "0000000000000001": {
42300
42360
  name: "Marinade",
42361
+ staging: true,
42301
42362
  permissions: {
42302
42363
  [1 << 0]: "Stake",
42303
42364
  [1 << 1]: "Unstake"
@@ -42308,7 +42369,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42308
42369
  // @anchor/programs/ext_stake_pool/src/state/acl.rs
42309
42370
  [getExtStakePoolProgramId().toBase58()]: {
42310
42371
  "0000000000000001": {
42311
- name: "Stake Pool",
42372
+ name: "StakePool",
42373
+ staging: true,
42312
42374
  permissions: {
42313
42375
  [1 << 0]: "DepositSol",
42314
42376
  [1 << 1]: "DepositStake",
@@ -42319,7 +42381,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42319
42381
  }
42320
42382
  },
42321
42383
  "0000000000000010": {
42322
- name: "Sanctum Single",
42384
+ name: "SanctumSingle",
42385
+ staging: true,
42323
42386
  permissions: {
42324
42387
  [1 << 0]: "DepositSol",
42325
42388
  [1 << 1]: "DepositStake",
@@ -42330,7 +42393,8 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42330
42393
  }
42331
42394
  },
42332
42395
  "0000000000000100": {
42333
- name: "Sanctum Multi",
42396
+ name: "SanctumMulti",
42397
+ staging: true,
42334
42398
  permissions: {
42335
42399
  [1 << 0]: "DepositSol",
42336
42400
  [1 << 1]: "DepositStake",
@@ -42360,7 +42424,7 @@ const GLAM_CONFIG_PROGRAM = new web3_js.PublicKey("gConFzxKL9USmwTdJoeQJvfKmqhJ2
42360
42424
  const mapping = {};
42361
42425
  Object.entries(getProtocolsAndPermissions()).forEach(([programId, protocols])=>{
42362
42426
  Object.entries(protocols).forEach(([bitflag, protocol])=>{
42363
- const name = protocol.name.replace(" ", "");
42427
+ const name = protocol.name;
42364
42428
  mapping[name] = [
42365
42429
  programId,
42366
42430
  bitflag
@@ -42868,6 +42932,37 @@ const getStakeAccountsWithStates = async (connection, withdrawAuthority)=>{
42868
42932
  permissions
42869
42933
  };
42870
42934
  }
42935
+ /**
42936
+ * Given the protocol name and a list of permission names, returns the permissions bitmask.
42937
+ */ function parsePermissionNames({ protocolName, permissionNames }) {
42938
+ const protocolConfig = getProgramAndBitflagByProtocolName()[protocolName];
42939
+ if (!protocolConfig) {
42940
+ throw new Error(`Unknown protocol name ${protocolName}`);
42941
+ }
42942
+ const [programIdStr, bitflagStr] = protocolConfig;
42943
+ const protocolPermissions = getProtocolsAndPermissions()[programIdStr]?.[bitflagStr];
42944
+ if (!protocolPermissions) {
42945
+ throw new Error(`Protocol mapping not found for protocol name ${protocolName}`);
42946
+ }
42947
+ const integrationProgram = new web3_js.PublicKey(programIdStr);
42948
+ const protocolBitflag = parseInt(bitflagStr, 2);
42949
+ // Calculate permissions bitmask
42950
+ const permissionNameToBitflag = {};
42951
+ for (const [bitflag, name] of Object.entries(protocolPermissions.permissions)){
42952
+ permissionNameToBitflag[name] = new anchor.BN(bitflag);
42953
+ }
42954
+ const permissionsBitmask = permissionNames.reduce((mask, p)=>{
42955
+ if (!permissionNameToBitflag[p]) {
42956
+ throw new Error(`Unknown permission name ${p} for protocol name ${protocolName}`);
42957
+ }
42958
+ return mask.or(permissionNameToBitflag[p]);
42959
+ }, new anchor.BN(0));
42960
+ return {
42961
+ integrationProgram,
42962
+ protocolBitflag,
42963
+ permissionsBitmask
42964
+ };
42965
+ }
42871
42966
 
42872
42967
  class BlockhashWithCache {
42873
42968
  async get() {
@@ -42970,6 +43065,12 @@ const publicKeyToEvmAddress = (publicKey)=>{
42970
43065
  const evmAddress = hex.slice(-40);
42971
43066
  return `0x${evmAddress}`;
42972
43067
  };
43068
+ /**
43069
+ * Validates if a string is a valid EVM address (40 hex characters)
43070
+ */ const isValidEvmAddress = (addr)=>{
43071
+ const cleanAddr = addr.startsWith("0x") ? addr.slice(2) : addr;
43072
+ return /^[0-9a-fA-F]{40}$/.test(cleanAddr);
43073
+ };
42973
43074
 
42974
43075
  function getStatePda(initKey, owner, programId) {
42975
43076
  const [pda, _bump] = web3_js.PublicKey.findProgramAddressSync([
@@ -44169,6 +44270,21 @@ function bfToDecimal(x) {
44169
44270
  return new Fraction(accSf).toDecimal();
44170
44271
  }
44171
44272
 
44273
+ class JupTokenList {
44274
+ getByMint(mintAddress) {
44275
+ return this.mintMap.get(mintAddress.toString());
44276
+ }
44277
+ getBySymbol(symbol) {
44278
+ return this.tokens.find((token)=>token.symbol === symbol);
44279
+ }
44280
+ constructor(tokens){
44281
+ this.tokens = tokens;
44282
+ this.mintMap = new Map(tokens.map((token)=>[
44283
+ token.address,
44284
+ token
44285
+ ]));
44286
+ }
44287
+ }
44172
44288
  const TOKEN_LIST_CACHE_TTL = 5 * 60 * 1000; // 5 minutes
44173
44289
  const JUPITER_API_DEFAULT = "https://api.jup.ag";
44174
44290
  // Zod schemas for runtime validation
@@ -44227,11 +44343,12 @@ class JupiterApiClient {
44227
44343
  usdPrice: t.usdPrice,
44228
44344
  slot: t.priceBlockId
44229
44345
  }));
44346
+ const jupTokenList = new JupTokenList(tokenList);
44230
44347
  this.tokenListCache = {
44231
- data: tokenList,
44348
+ data: jupTokenList,
44232
44349
  timestamp: Date.now()
44233
44350
  };
44234
- return tokenList;
44351
+ return jupTokenList;
44235
44352
  }
44236
44353
  async fetchProgramLabels() {
44237
44354
  if (!this.apiKey) {
@@ -44333,7 +44450,7 @@ class JupiterApiClient {
44333
44450
  return this.id?.toBase58() || "";
44334
44451
  }
44335
44452
  get nameStr() {
44336
- return this.name ? charsToName(this.name) : "";
44453
+ return this.name ? charsToString(this.name) : "";
44337
44454
  }
44338
44455
  get productType() {
44339
44456
  // @ts-ignore
@@ -44345,12 +44462,8 @@ class JupiterApiClient {
44345
44462
  return new Date(createdAt * 1000).toISOString().split("T")[0] || "Unknown";
44346
44463
  }
44347
44464
  get sparkleKey() {
44348
- if (!this.mint && !this.id) {
44349
- throw new Error("Cannot generate sparkle key");
44350
- }
44351
- // An edge case is mint is closed but state account is not
44352
- // this.mint would be `null`
44353
- return (!this.mint?.equals(web3_js.PublicKey.default) ? this.id : this.mint)?.toBase58();
44465
+ const pubkey = (this.mint?.equals(web3_js.PublicKey.default) ? this.id : this.mint) || web3_js.PublicKey.default;
44466
+ return pubkey.toBase58();
44354
44467
  }
44355
44468
  get baseAssetTokenProgramId() {
44356
44469
  switch(this.baseAssetTokenProgram){
@@ -44432,7 +44545,7 @@ class JupiterApiClient {
44432
44545
  const extMetadata = splToken.getExtensionData(splToken.ExtensionType.TokenMetadata, glamMint.tlvData);
44433
44546
  const tokenMetadata = extMetadata ? splTokenMetadata.unpack(extMetadata) : {};
44434
44547
  mintModel["symbol"] = tokenMetadata?.symbol;
44435
- mintModel["name"] = nameToChars(tokenMetadata?.name);
44548
+ mintModel["name"] = stringToChars(tokenMetadata?.name);
44436
44549
  mintModel["uri"] = tokenMetadata?.uri;
44437
44550
  if (tokenMetadata?.additionalMetadata) {
44438
44551
  tokenMetadata.additionalMetadata.forEach(([k, v])=>{
@@ -45209,7 +45322,7 @@ DriftVaultDepositor._layout = borsh.struct([
45209
45322
  ]);
45210
45323
  class DriftVault extends Decodable {
45211
45324
  get name() {
45212
- return charsToName(this.nameBytes);
45325
+ return charsToString(this.nameBytes);
45213
45326
  }
45214
45327
  marketPda(marketType, marketIndex) {
45215
45328
  const marketTypeStr = marketType === MarketType.SPOT ? "spot" : "perp";
@@ -45631,7 +45744,7 @@ class DriftUser {
45631
45744
  return instance;
45632
45745
  }
45633
45746
  get name() {
45634
- return charsToName(this.nameBytes);
45747
+ return charsToString(this.nameBytes);
45635
45748
  }
45636
45749
  getAddress() {
45637
45750
  return this._address;
@@ -45639,7 +45752,7 @@ class DriftUser {
45639
45752
  }
45640
45753
  class DriftSpotMarket extends Decodable {
45641
45754
  get name() {
45642
- return charsToName(this.nameBytes);
45755
+ return charsToString(this.nameBytes);
45643
45756
  }
45644
45757
  get oracleSource() {
45645
45758
  return OracleSource.get(this.oracleSourceOrd);
@@ -45681,7 +45794,7 @@ class DriftPerpMarket extends Decodable {
45681
45794
  return instance;
45682
45795
  }
45683
45796
  get name() {
45684
- return charsToName(this.nameBytes);
45797
+ return charsToString(this.nameBytes);
45685
45798
  }
45686
45799
  get oracleSource() {
45687
45800
  return OracleSource.get(this.oracleSourceOrd);
@@ -45704,6 +45817,29 @@ DriftPerpMarket._layout = borsh.struct([
45704
45817
 
45705
45818
  const DRIFT_SIGNER = new web3_js.PublicKey("JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw");
45706
45819
  const DRIFT_MARGIN_PRECISION = 10000;
45820
+ class DriftMarketConfigs {
45821
+ getPerp(marketIndex) {
45822
+ const market = this.perpMarkets[marketIndex];
45823
+ if (market.marketIndex === marketIndex) {
45824
+ return market;
45825
+ }
45826
+ }
45827
+ getSpot(mintOrIndex) {
45828
+ if (typeof mintOrIndex === "number") {
45829
+ const market = this.spotMarkets[mintOrIndex];
45830
+ if (market.marketIndex === mintOrIndex) {
45831
+ return market;
45832
+ }
45833
+ } else {
45834
+ return this.spotMarkets.find(({ mint })=>mint.equals(mintOrIndex));
45835
+ }
45836
+ }
45837
+ constructor(orderConstants, perpMarkets, spotMarkets){
45838
+ this.orderConstants = orderConstants;
45839
+ this.perpMarkets = perpMarkets;
45840
+ this.spotMarkets = spotMarkets;
45841
+ }
45842
+ }
45707
45843
  let TxBuilder$g = class TxBuilder extends BaseTxBuilder {
45708
45844
  async initializeUserStatsIx(glamSigner) {
45709
45845
  const { userStats } = this.client.getDriftUserPdas();
@@ -46105,6 +46241,15 @@ class DriftProtocolClient {
46105
46241
  userStats: this.getUserStatsPda(vault)
46106
46242
  };
46107
46243
  }
46244
+ getSubAccountId(driftUser) {
46245
+ for(let i = 0; i < 100; ++i){
46246
+ const { user } = this.getDriftUserPdas(i);
46247
+ if (user.equals(driftUser)) {
46248
+ return i;
46249
+ }
46250
+ }
46251
+ throw new Error("Sub account not found");
46252
+ }
46108
46253
  get driftStatePda() {
46109
46254
  return web3_js.PublicKey.findProgramAddressSync([
46110
46255
  Buffer.from("drift_state")
@@ -46183,14 +46328,10 @@ class DriftProtocolClient {
46183
46328
  // FIXME: one day the number of markets will exceed 100 and a better solution will be needed
46184
46329
  const perpMarkets = await this.fetchAndParsePerpMarkets(Array.from(Array(100).keys()), skipCache);
46185
46330
  const spotMarkets = await this.fetchAndParseSpotMarkets(Array.from(Array(100).keys()), skipCache);
46186
- this.marketConfigs = {
46187
- orderConstants: {
46188
- perpBaseScale: 9,
46189
- quoteScale: 6
46190
- },
46191
- perpMarkets,
46192
- spotMarkets
46193
- };
46331
+ this.marketConfigs = new DriftMarketConfigs({
46332
+ perpBaseScale: 9,
46333
+ quoteScale: 6
46334
+ }, perpMarkets, spotMarkets);
46194
46335
  return this.marketConfigs;
46195
46336
  }
46196
46337
  async fetchAndParseDriftUser(subAccountId = 0) {
@@ -47571,7 +47712,7 @@ let TxBuilder$b = class TxBuilder extends BaseTxBuilder {
47571
47712
  // stateInitKey = hash state name and get first 8 bytes
47572
47713
  // useful for re-computing state account PDA in the future
47573
47714
  const stateInitKey = [
47574
- ...Buffer.from(anchor__namespace.utils.sha256.hash(charsToName(params.name))).subarray(0, 8)
47715
+ ...Buffer.from(anchor__namespace.utils.sha256.hash(charsToString(params.name))).subarray(0, 8)
47575
47716
  ];
47576
47717
  const created = new CreatedModel({
47577
47718
  key: stateInitKey
@@ -47693,7 +47834,7 @@ const KAMINO_VAULTS_EVENT_AUTHORITY = new web3_js.PublicKey("24tHwQyJJ9akVXxnvke
47693
47834
  const MAX_RESERVES = 25;
47694
47835
  class KVaultState extends Decodable {
47695
47836
  get nameStr() {
47696
- return charsToName(this.name);
47837
+ return charsToString(this.name);
47697
47838
  }
47698
47839
  get validAllocations() {
47699
47840
  return this.vaultAllocationStrategy.filter(({ reserve })=>!reserve.equals(web3_js.PublicKey.default));
@@ -49687,8 +49828,8 @@ class PriceClient {
49687
49828
  }
49688
49829
  // Build a map of token prices (in USD)
49689
49830
  const tokenPricesMap = new PkMap();
49690
- const tokenList = await this.jupiterApi.fetchTokensList();
49691
- tokenList.forEach((item)=>{
49831
+ const tokenList = await this.jupiterApi.fetchTokensList(true);
49832
+ tokenList.tokens.forEach((item)=>{
49692
49833
  const tokenMint = new web3_js.PublicKey(item.address);
49693
49834
  tokenPricesMap.set(tokenMint, item);
49694
49835
  });
@@ -49813,7 +49954,6 @@ class PriceClient {
49813
49954
  }
49814
49955
  for (const pubkey of tokenAccountPubkeys){
49815
49956
  const data = accountsDataMap.get(pubkey);
49816
- if (!data) continue;
49817
49957
  const { amount, mint } = splToken.AccountLayout.decode(data);
49818
49958
  const tokenInfo = tokenPricesMap.get(mint);
49819
49959
  if (tokenInfo) {
@@ -49878,13 +50018,12 @@ class PriceClient {
49878
50018
  const amount = depositor.netShares.mul(aum).div(dvault.totalShares).add(depositor.lastWithdrawRequest.value);
49879
50019
  const { mint, decimals } = dvault.getBaseAsset(spotMarketsMap);
49880
50020
  const tokenPrice = tokenPricesMap.get(mint);
49881
- if (!tokenPrice) continue;
49882
50021
  const { usdPrice, slot } = tokenPrice;
49883
50022
  const holding = new Holding(mint, decimals, amount, usdPrice, {
49884
50023
  slot,
49885
50024
  source: priceSource
49886
50025
  }, "DriftVaults", {
49887
- vault: pubkey,
50026
+ vault: dvault.getAddress(),
49888
50027
  depositor: depositor.getAddress()
49889
50028
  });
49890
50029
  holdings.push(holding);
@@ -49895,16 +50034,13 @@ class PriceClient {
49895
50034
  const holdings = [];
49896
50035
  for (const obligation of obligationPubkeys){
49897
50036
  const obligationData = accountsDataMap.get(obligation);
49898
- if (!obligationData) continue;
49899
50037
  const { activeDeposits, activeBorrows } = Obligation.decode(obligation, obligationData);
49900
50038
  for (const { depositReserve, depositedAmount } of activeDeposits){
49901
50039
  const reserve = reservesMap.get(depositReserve);
49902
- if (!reserve) continue;
49903
50040
  const { collateralExchangeRate, lendingMarket, liquidity } = reserve;
49904
50041
  const supplyAmount = new Decimal(depositedAmount.toString()).div(collateralExchangeRate).floor();
49905
50042
  const amount = new anchor.BN(supplyAmount.toString());
49906
50043
  const tokenPrice = tokenPricesMap.get(liquidity.mintPubkey);
49907
- if (!tokenPrice) continue;
49908
50044
  const { usdPrice, slot } = tokenPrice;
49909
50045
  const holding = new Holding(liquidity.mintPubkey, liquidity.mintDecimals.toNumber(), amount, usdPrice, {
49910
50046
  slot,
@@ -49919,13 +50055,11 @@ class PriceClient {
49919
50055
  }
49920
50056
  for (const { borrowReserve, borrowedAmountSf, cumulativeBorrowRateBsf } of activeBorrows){
49921
50057
  const reserve = reservesMap.get(borrowReserve);
49922
- if (!reserve) continue;
49923
50058
  const { cumulativeBorrowRate, lendingMarket, liquidity } = reserve;
49924
50059
  const obligationCumulativeBorrowRate = bfToDecimal(cumulativeBorrowRateBsf);
49925
50060
  const borrowAmount = new Fraction(borrowedAmountSf).toDecimal().mul(cumulativeBorrowRate).div(obligationCumulativeBorrowRate).ceil();
49926
50061
  const amount = new anchor.BN(borrowAmount.toString());
49927
50062
  const tokenPrice = tokenPricesMap.get(liquidity.mintPubkey);
49928
- if (!tokenPrice) continue;
49929
50063
  const { usdPrice, slot } = tokenPrice;
49930
50064
  const holding = new Holding(liquidity.mintPubkey, liquidity.mintDecimals.toNumber(), amount, usdPrice, {
49931
50065
  slot,
@@ -49945,12 +50079,10 @@ class PriceClient {
49945
50079
  const holdings = [];
49946
50080
  for (const [ata, kvaultState] of kvaultAtasAndStates.pkEntries()){
49947
50081
  const ataData = accountsDataMap.get(ata);
49948
- if (!ataData) continue;
49949
50082
  const tokenAccount = splToken.AccountLayout.decode(ataData);
49950
50083
  let aum = new Decimal(kvaultState.tokenAvailable.toString());
49951
50084
  kvaultState.validAllocations.map((allocation)=>{
49952
50085
  const reserve = reservesMap.get(allocation.reserve);
49953
- if (!reserve) return;
49954
50086
  const { collateralExchangeRate } = reserve;
49955
50087
  // allocation ctoken amount to liq asset amount
49956
50088
  const liqAmount = new Decimal(allocation.ctokenAllocation.toString()).div(collateralExchangeRate).floor();
@@ -49959,7 +50091,6 @@ class PriceClient {
49959
50091
  // calculate liquidity token amount
49960
50092
  const amount = new Decimal(tokenAccount.amount.toString()).div(new Decimal(kvaultState.sharesIssued.toString())).mul(aum).floor();
49961
50093
  const tokenPrice = tokenPricesMap.get(kvaultState.tokenMint);
49962
- if (!tokenPrice) continue;
49963
50094
  const { usdPrice, slot } = tokenPrice;
49964
50095
  const holding = new Holding(kvaultState.tokenMint, kvaultState.tokenMintDecimals.toNumber(), new anchor.BN(amount.toString()), usdPrice, {
49965
50096
  slot,
@@ -50670,7 +50801,7 @@ let TxBuilder$5 = class TxBuilder extends BaseTxBuilder {
50670
50801
  async initializeIxs(initMintParams, stateParams, glamSigner) {
50671
50802
  const decimals = typeof initMintParams.decimals === "number" ? initMintParams.decimals : null;
50672
50803
  const stateInitKey = [
50673
- ...Buffer.from(anchor.utils.sha256.hash(charsToName(initMintParams.name))).subarray(0, 8)
50804
+ ...Buffer.from(anchor.utils.sha256.hash(charsToString(initMintParams.name))).subarray(0, 8)
50674
50805
  ];
50675
50806
  const glamState = getStatePda(stateInitKey, glamSigner, this.client.base.protocolProgram.programId);
50676
50807
  const postInstructions = [];
@@ -51545,11 +51676,12 @@ const MESSAGE_RECEIVED_EVENT_DISCM = new Uint8Array([
51545
51676
  ]);
51546
51677
  const CCTP_DOMAIN_SOLANA = 5;
51547
51678
  class CctpBridgeEvent {
51548
- constructor(amount, sourceDomain, sourceAddress, destinationDomain, destinationAddress, attestation, nonce, status, txHash){
51679
+ constructor(amount, sourceDomain, sourceAddress, destinationDomain, destinationCaller, destinationAddress, attestation, nonce, status, txHash){
51549
51680
  this.amount = amount;
51550
51681
  this.sourceDomain = sourceDomain;
51551
51682
  this.sourceAddress = sourceAddress;
51552
51683
  this.destinationDomain = destinationDomain;
51684
+ this.destinationCaller = destinationCaller;
51553
51685
  this.destinationAddress = destinationAddress;
51554
51686
  this.attestation = attestation;
51555
51687
  this.nonce = nonce;
@@ -51569,7 +51701,7 @@ let TxBuilder = class TxBuilder extends BaseTxBuilder {
51569
51701
  amount,
51570
51702
  destinationDomain: domain,
51571
51703
  mintRecipient: recipient,
51572
- destinationCaller: web3_js.PublicKey.default,
51704
+ destinationCaller: params.destinationCaller || web3_js.PublicKey.default,
51573
51705
  ...params
51574
51706
  };
51575
51707
  const denylistAccount = web3_js.PublicKey.findProgramAddressSync([
@@ -51947,6 +52079,7 @@ class CctpClient {
51947
52079
  const status = message.status;
51948
52080
  const nonce = message.decodedMessage.nonce;
51949
52081
  const destinationDomain = Number(message.decodedMessage.destinationDomain);
52082
+ const destinationCaller = message.decodedMessage.destinationCaller;
51950
52083
  const destinationAddress = message.decodedMessage.decodedMessageBody.mintRecipient;
51951
52084
  const sourceAddress = message.decodedMessage.decodedMessageBody.messageSender;
51952
52085
  const amount = message.decodedMessage.decodedMessageBody.amount;
@@ -51954,7 +52087,7 @@ class CctpClient {
51954
52087
  if (sourceDomain === 5 && token !== USDC.toBase58()) {
51955
52088
  throw new Error("Invalid message, expected burn token to be USDC");
51956
52089
  }
51957
- return new CctpBridgeEvent(new anchor.BN(amount), sourceDomain, sourceAddress, destinationDomain, destinationAddress, attestation, nonce, status, txHash ?? "");
52090
+ return new CctpBridgeEvent(new anchor.BN(amount), sourceDomain, sourceAddress, destinationDomain, destinationCaller, destinationAddress, attestation, nonce, status, txHash ?? "");
51958
52091
  });
51959
52092
  }
51960
52093
  /**
@@ -52228,6 +52361,7 @@ exports.DefaultOrderParams = DefaultOrderParams;
52228
52361
  exports.DelegateAcl = DelegateAcl;
52229
52362
  exports.DepositDirection = DepositDirection;
52230
52363
  exports.DepositExplanation = DepositExplanation;
52364
+ exports.DriftMarketConfigs = DriftMarketConfigs;
52231
52365
  exports.DriftProtocolClient = DriftProtocolClient;
52232
52366
  exports.DriftProtocolPolicy = DriftProtocolPolicy;
52233
52367
  exports.DriftVaultsClient = DriftVaultsClient;
@@ -52240,6 +52374,7 @@ exports.GLAM_CONFIG_PROGRAM = GLAM_CONFIG_PROGRAM;
52240
52374
  exports.GLAM_REFERRER = GLAM_REFERRER;
52241
52375
  exports.GlamClient = GlamClient;
52242
52376
  exports.GlamError = GlamError;
52377
+ exports.Holding = Holding;
52243
52378
  exports.InsuranceFundOperation = InsuranceFundOperation;
52244
52379
  exports.IntegrationAcl = IntegrationAcl;
52245
52380
  exports.IntegrationPermissions = IntegrationPermissions;
@@ -52247,6 +52382,7 @@ exports.JITO_TIP_DEFAULT = JITO_TIP_DEFAULT;
52247
52382
  exports.JUP = JUP;
52248
52383
  exports.JUPITER_API_DEFAULT = JUPITER_API_DEFAULT;
52249
52384
  exports.JUPITER_PROGRAM_ID = JUPITER_PROGRAM_ID;
52385
+ exports.JupTokenList = JupTokenList;
52250
52386
  exports.JupiterApiClient = JupiterApiClient;
52251
52387
  exports.JupiterSwapClient = JupiterSwapClient;
52252
52388
  exports.JupiterSwapPolicy = JupiterSwapPolicy;
@@ -52283,6 +52419,7 @@ exports.PkMap = PkMap;
52283
52419
  exports.PkSet = PkSet;
52284
52420
  exports.PositionDirection = PositionDirection;
52285
52421
  exports.PostOnlyParams = PostOnlyParams;
52422
+ exports.PriceClient = PriceClient;
52286
52423
  exports.PriceDenom = PriceDenom;
52287
52424
  exports.ProtocolPermissions = ProtocolPermissions;
52288
52425
  exports.ProtocolPolicy = ProtocolPolicy;
@@ -52322,13 +52459,14 @@ exports.USDC = USDC;
52322
52459
  exports.USDC_DEVNET = USDC_DEVNET;
52323
52460
  exports.USDC_ORACLE = USDC_ORACLE;
52324
52461
  exports.UserStatus = UserStatus;
52462
+ exports.VaultHoldings = VaultHoldings;
52325
52463
  exports.VoteAuthorize = VoteAuthorize;
52326
52464
  exports.WSOL = WSOL;
52327
52465
  exports.ZERO = ZERO;
52328
52466
  exports.bfToDecimal = bfToDecimal;
52329
52467
  exports.buildComputeBudgetInstructions = buildComputeBudgetInstructions;
52330
52468
  exports.bytesToHex = bytesToHex;
52331
- exports.charsToName = charsToName;
52469
+ exports.charsToString = charsToString;
52332
52470
  exports.compareDelegateAcls = compareDelegateAcls;
52333
52471
  exports.compareIntegrationAcls = compareIntegrationAcls;
52334
52472
  exports.evmAddressToBytes32 = evmAddressToBytes32;
@@ -52341,6 +52479,7 @@ exports.fetchMintsAndTokenPrograms = fetchMintsAndTokenPrograms;
52341
52479
  exports.findGlamLookupTables = findGlamLookupTables;
52342
52480
  exports.findStakeAccounts = findStakeAccounts;
52343
52481
  exports.formatBits = formatBits;
52482
+ exports.fromUiAmount = fromUiAmount;
52344
52483
  exports.getAccountPolicyPda = getAccountPolicyPda;
52345
52484
  exports.getAssetMeta = getAssetMeta;
52346
52485
  exports.getEscrowPda = getEscrowPda;
@@ -52394,8 +52533,9 @@ exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;
52394
52533
  exports.getTriggerMarketOrderParams = getTriggerMarketOrderParams;
52395
52534
  exports.getVaultPda = getVaultPda;
52396
52535
  exports.hexToBytes = hexToBytes;
52397
- exports.nameToChars = nameToChars;
52536
+ exports.isValidEvmAddress = isValidEvmAddress;
52398
52537
  exports.parseMintAccountInfo = parseMintAccountInfo;
52538
+ exports.parsePermissionNames = parsePermissionNames;
52399
52539
  exports.parseProgramLogs = parseProgramLogs;
52400
52540
  exports.parseProtocolPermissionsBitmask = parseProtocolPermissionsBitmask;
52401
52541
  exports.parseProtocolsBitmask = parseProtocolsBitmask;
@@ -52403,5 +52543,5 @@ exports.publicKeyToEvmAddress = publicKeyToEvmAddress;
52403
52543
  exports.readI128LE = readI128LE;
52404
52544
  exports.readSignedBigInt64LE = readSignedBigInt64LE;
52405
52545
  exports.readUnsignedBigInt64LE = readUnsignedBigInt64LE;
52406
- exports.setsAreEqual = setsAreEqual;
52546
+ exports.stringToChars = stringToChars;
52407
52547
  exports.toUiAmount = toUiAmount;