@glamsystems/glam-sdk 1.0.14-alpha.0 → 1.0.14-alpha.2

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
@@ -18891,6 +18891,7 @@ var instructions$8 = [
18891
18891
  },
18892
18892
  {
18893
18893
  name: "glam_vault",
18894
+ writable: true,
18894
18895
  pda: {
18895
18896
  seeds: [
18896
18897
  {
@@ -19160,6 +19161,7 @@ var instructions$8 = [
19160
19161
  },
19161
19162
  {
19162
19163
  name: "glam_vault",
19164
+ writable: true,
19163
19165
  pda: {
19164
19166
  seeds: [
19165
19167
  {
@@ -19483,6 +19485,7 @@ var instructions$8 = [
19483
19485
  },
19484
19486
  {
19485
19487
  name: "glam_vault",
19488
+ writable: true,
19486
19489
  pda: {
19487
19490
  seeds: [
19488
19491
  {
@@ -47096,19 +47099,51 @@ class BaseClient {
47096
47099
  this._assetMetasPromise = undefined;
47097
47100
  }
47098
47101
  const fetchPromise = this.fetchGlobalConfig(options).then(async (globalConfig)=>{
47099
- // FIX: this could be perf bottleneck if there are many assets
47100
- const mintInfos = await fetchMintsAndTokenPrograms(this.connection, globalConfig.assetMetas.map((am)=>am.asset));
47101
- // Transforms onchain asset meta to client asset meta
47102
- const assetMetaMap = new Map(globalConfig.assetMetas.map(({ asset, decimals, oracle, oracleSource }, i)=>[
47103
- asset.toBase58(),
47104
- {
47105
- asset,
47106
- decimals,
47107
- oracle,
47108
- oracleSource,
47109
- programId: mintInfos[i].tokenProgram
47102
+ const assets = globalConfig.assetMetas.map((am)=>am.asset);
47103
+ const tokenProgramsByAsset = new Map();
47104
+ try {
47105
+ // Fast path when every global-config mint account is available.
47106
+ const mintInfos = await fetchMintsAndTokenPrograms(this.connection, assets);
47107
+ assets.forEach((asset, i)=>{
47108
+ tokenProgramsByAsset.set(asset.toBase58(), mintInfos[i].tokenProgram);
47109
+ });
47110
+ } catch {
47111
+ // Local validators may clone a newer global config than the set of
47112
+ // mint accounts they have available. Resolve what we can and let
47113
+ // downstream callers request only the assets they actually use.
47114
+ const accountsInfo = await this.connection.getMultipleAccountsInfo(assets, "confirmed");
47115
+ accountsInfo.forEach((accountInfo, i)=>{
47116
+ const asset = assets[i];
47117
+ const assetKey = asset.toBase58();
47118
+ if (accountInfo) {
47119
+ tokenProgramsByAsset.set(assetKey, parseMintAccountInfo(accountInfo, asset).tokenProgram);
47120
+ return;
47121
+ }
47122
+ const fallback = ASSETS_MAINNET.get(assetKey);
47123
+ if (fallback) {
47124
+ tokenProgramsByAsset.set(assetKey, fallback.programId);
47110
47125
  }
47111
- ]));
47126
+ });
47127
+ }
47128
+ // Transforms onchain asset meta to client asset meta
47129
+ const assetMetaMap = new Map(globalConfig.assetMetas.flatMap(({ asset, decimals, oracle, oracleSource })=>{
47130
+ const programId = tokenProgramsByAsset.get(asset.toBase58());
47131
+ if (!programId) {
47132
+ return [];
47133
+ }
47134
+ return [
47135
+ [
47136
+ asset.toBase58(),
47137
+ {
47138
+ asset,
47139
+ decimals,
47140
+ oracle,
47141
+ oracleSource,
47142
+ programId
47143
+ }
47144
+ ]
47145
+ ];
47146
+ }));
47112
47147
  if (useCache) {
47113
47148
  this._assetMetas = assetMetaMap;
47114
47149
  }
package/index.esm.js CHANGED
@@ -18871,6 +18871,7 @@ var instructions$8 = [
18871
18871
  },
18872
18872
  {
18873
18873
  name: "glam_vault",
18874
+ writable: true,
18874
18875
  pda: {
18875
18876
  seeds: [
18876
18877
  {
@@ -19140,6 +19141,7 @@ var instructions$8 = [
19140
19141
  },
19141
19142
  {
19142
19143
  name: "glam_vault",
19144
+ writable: true,
19143
19145
  pda: {
19144
19146
  seeds: [
19145
19147
  {
@@ -19463,6 +19465,7 @@ var instructions$8 = [
19463
19465
  },
19464
19466
  {
19465
19467
  name: "glam_vault",
19468
+ writable: true,
19466
19469
  pda: {
19467
19470
  seeds: [
19468
19471
  {
@@ -47076,19 +47079,51 @@ class BaseClient {
47076
47079
  this._assetMetasPromise = undefined;
47077
47080
  }
47078
47081
  const fetchPromise = this.fetchGlobalConfig(options).then(async (globalConfig)=>{
47079
- // FIX: this could be perf bottleneck if there are many assets
47080
- const mintInfos = await fetchMintsAndTokenPrograms(this.connection, globalConfig.assetMetas.map((am)=>am.asset));
47081
- // Transforms onchain asset meta to client asset meta
47082
- const assetMetaMap = new Map(globalConfig.assetMetas.map(({ asset, decimals, oracle, oracleSource }, i)=>[
47083
- asset.toBase58(),
47084
- {
47085
- asset,
47086
- decimals,
47087
- oracle,
47088
- oracleSource,
47089
- programId: mintInfos[i].tokenProgram
47082
+ const assets = globalConfig.assetMetas.map((am)=>am.asset);
47083
+ const tokenProgramsByAsset = new Map();
47084
+ try {
47085
+ // Fast path when every global-config mint account is available.
47086
+ const mintInfos = await fetchMintsAndTokenPrograms(this.connection, assets);
47087
+ assets.forEach((asset, i)=>{
47088
+ tokenProgramsByAsset.set(asset.toBase58(), mintInfos[i].tokenProgram);
47089
+ });
47090
+ } catch {
47091
+ // Local validators may clone a newer global config than the set of
47092
+ // mint accounts they have available. Resolve what we can and let
47093
+ // downstream callers request only the assets they actually use.
47094
+ const accountsInfo = await this.connection.getMultipleAccountsInfo(assets, "confirmed");
47095
+ accountsInfo.forEach((accountInfo, i)=>{
47096
+ const asset = assets[i];
47097
+ const assetKey = asset.toBase58();
47098
+ if (accountInfo) {
47099
+ tokenProgramsByAsset.set(assetKey, parseMintAccountInfo(accountInfo, asset).tokenProgram);
47100
+ return;
47101
+ }
47102
+ const fallback = ASSETS_MAINNET.get(assetKey);
47103
+ if (fallback) {
47104
+ tokenProgramsByAsset.set(assetKey, fallback.programId);
47090
47105
  }
47091
- ]));
47106
+ });
47107
+ }
47108
+ // Transforms onchain asset meta to client asset meta
47109
+ const assetMetaMap = new Map(globalConfig.assetMetas.flatMap(({ asset, decimals, oracle, oracleSource })=>{
47110
+ const programId = tokenProgramsByAsset.get(asset.toBase58());
47111
+ if (!programId) {
47112
+ return [];
47113
+ }
47114
+ return [
47115
+ [
47116
+ asset.toBase58(),
47117
+ {
47118
+ asset,
47119
+ decimals,
47120
+ oracle,
47121
+ oracleSource,
47122
+ programId
47123
+ }
47124
+ ]
47125
+ ];
47126
+ }));
47092
47127
  if (useCache) {
47093
47128
  this._assetMetas = assetMetaMap;
47094
47129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glamsystems/glam-sdk",
3
- "version": "1.0.14-alpha.0",
3
+ "version": "1.0.14-alpha.2",
4
4
  "description": "TypeScript SDK for the GLAM Protocol",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
@@ -104,6 +104,7 @@ export type ExtBridge = {
104
104
  },
105
105
  {
106
106
  "name": "glamVault";
107
+ "writable": true;
107
108
  "pda": {
108
109
  "seeds": [
109
110
  {
@@ -373,6 +374,7 @@ export type ExtBridge = {
373
374
  },
374
375
  {
375
376
  "name": "glamVault";
377
+ "writable": true;
376
378
  "pda": {
377
379
  "seeds": [
378
380
  {
@@ -696,6 +698,7 @@ export type ExtBridge = {
696
698
  },
697
699
  {
698
700
  "name": "glamVault";
701
+ "writable": true;
699
702
  "pda": {
700
703
  "seeds": [
701
704
  {