@talismn/chaindata-provider 2.3.0 → 2.3.1
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/dist/index.d.mts +105 -105
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +28 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -8764,6 +8764,11 @@ var ChaindataProvider = class {
|
|
|
8764
8764
|
this.#dynamicTokensWriteQueue = result.catch(() => void 0);
|
|
8765
8765
|
return result;
|
|
8766
8766
|
}
|
|
8767
|
+
/** ids of the tokens in the default (curated) chaindata */
|
|
8768
|
+
async #getCuratedTokenIds() {
|
|
8769
|
+
const defaultStorage = await firstValueFrom(this.#storage$);
|
|
8770
|
+
return new Set(defaultStorage.tokens.map((t) => t.id));
|
|
8771
|
+
}
|
|
8767
8772
|
/**
|
|
8768
8773
|
* Registers token dynamically a runtime. used for SPL and dTAO tokens.
|
|
8769
8774
|
* @param tokens
|
|
@@ -8772,9 +8777,12 @@ var ChaindataProvider = class {
|
|
|
8772
8777
|
if (!tokens.length) return;
|
|
8773
8778
|
await forEachWithYield(tokens, (t) => void TokenSchema.parse(t));
|
|
8774
8779
|
await this.#enqueueDynamicTokensWrite(async () => {
|
|
8780
|
+
const curatedTokenIds = await this.#getCuratedTokenIds();
|
|
8781
|
+
const newTokens = tokens.filter((t) => !isShadowingCuratedToken(t, curatedTokenIds));
|
|
8782
|
+
if (!newTokens.length) return;
|
|
8775
8783
|
const currentStorage = await firstValueFrom(this.#dynamicTokens$);
|
|
8776
8784
|
const currentById = keyBy(currentStorage, (t) => t.id);
|
|
8777
|
-
const newById = keyBy(
|
|
8785
|
+
const newById = keyBy(newTokens, (t) => t.id);
|
|
8778
8786
|
const dynamicTokens = values({
|
|
8779
8787
|
...currentById,
|
|
8780
8788
|
...newById
|
|
@@ -8791,12 +8799,11 @@ var ChaindataProvider = class {
|
|
|
8791
8799
|
await this.#enqueueDynamicTokensWrite(async () => {
|
|
8792
8800
|
const dynamicTokens = await firstValueFrom(this.#dynamicTokens$);
|
|
8793
8801
|
if (!dynamicTokens.length) return;
|
|
8794
|
-
const
|
|
8795
|
-
const defaultTokenIds = new Set(defaultStorage.tokens.map((t) => t.id));
|
|
8802
|
+
const defaultTokenIds = await this.#getCuratedTokenIds();
|
|
8796
8803
|
const next = [];
|
|
8797
8804
|
let changed = false;
|
|
8798
8805
|
for (const token of dynamicTokens) {
|
|
8799
|
-
if ((token
|
|
8806
|
+
if (isShadowingCuratedToken(token, defaultTokenIds)) {
|
|
8800
8807
|
changed = true;
|
|
8801
8808
|
continue;
|
|
8802
8809
|
}
|
|
@@ -8895,6 +8902,11 @@ const withErrorReason = async (reason, task) => {
|
|
|
8895
8902
|
throw new Error(reason, { cause });
|
|
8896
8903
|
}
|
|
8897
8904
|
};
|
|
8905
|
+
/**
|
|
8906
|
+
* A dynamic Solana token whose id is also in the curated chaindata. Combined chaindata
|
|
8907
|
+
* keeps the last token per id, so such an entry would replace the curated one.
|
|
8908
|
+
*/
|
|
8909
|
+
const isShadowingCuratedToken = (token, curatedTokenIds) => (token.type === "sol-spl" || token.type === "sol-token2022") && curatedTokenIds.has(token.id);
|
|
8898
8910
|
//#endregion
|
|
8899
8911
|
//#region src/state/schema.ts
|
|
8900
8912
|
const ChaindataFileSchema = z.object({
|