@zebec-network/zebec-stream-sdk 1.5.1 → 1.6.0
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.
|
@@ -2,7 +2,7 @@ import { Address, BN, Program, Provider } from "@coral-xyz/anchor";
|
|
|
2
2
|
import { Commitment, Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
3
|
import { TransactionPayload } from "@zebec-network/solana-common";
|
|
4
4
|
import { ZebecStreamIdl } from "../artifacts";
|
|
5
|
-
import { Numeric, StreamConfigInfo, StreamMetadataInfo } from "../types";
|
|
5
|
+
import { Numeric, StreamConfigInfo, StreamMetadataInfo, TokenMetadata } from "../types";
|
|
6
6
|
export declare class ZebecStreamService {
|
|
7
7
|
readonly provider: Provider;
|
|
8
8
|
readonly network: "mainnet-beta" | "devnet";
|
|
@@ -58,6 +58,7 @@ export declare class ZebecStreamService {
|
|
|
58
58
|
whiteListTokens(params: WhiteListTokensParams): Promise<TransactionPayload>;
|
|
59
59
|
changeStreamReceiver(params: ChangeStreamReceiverParams): Promise<TransactionPayload>;
|
|
60
60
|
getStreamConfigInfo(commitment?: Commitment): Promise<StreamConfigInfo>;
|
|
61
|
+
getWhitelistedTokens(commitment?: "processed" | "confirmed" | "finalized"): Promise<TokenMetadata[]>;
|
|
61
62
|
getStreamMetadataInfo(streamMetadata: Address, commitment?: Commitment): Promise<StreamMetadataInfo>;
|
|
62
63
|
}
|
|
63
64
|
export type CreateStreamParams = {
|
|
@@ -7,6 +7,9 @@ exports.ZebecStreamService = void 0;
|
|
|
7
7
|
const assert_1 = __importDefault(require("assert"));
|
|
8
8
|
const bignumber_js_1 = require("bignumber.js");
|
|
9
9
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
10
|
+
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
|
|
11
|
+
const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
|
|
12
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
|
10
13
|
const web3_js_1 = require("@solana/web3.js");
|
|
11
14
|
const core_utils_1 = require("@zebec-network/core-utils");
|
|
12
15
|
const solana_common_1 = require("@zebec-network/solana-common");
|
|
@@ -318,6 +321,69 @@ class ZebecStreamService {
|
|
|
318
321
|
frequencies: configInfo.frequencies.map((frequency) => frequency.toNumber()),
|
|
319
322
|
};
|
|
320
323
|
}
|
|
324
|
+
async getWhitelistedTokens(commitment) {
|
|
325
|
+
const [config] = (0, pda_1.deriveStreamConfigPda)(this.programId);
|
|
326
|
+
const configInfo = await this.program.account.streamConfig.fetch(config, commitment ?? this.connection.commitment);
|
|
327
|
+
const whitelistedTokens = configInfo.whitelistedTokens;
|
|
328
|
+
const umi = (0, umi_bundle_defaults_1.createUmi)(this.connection.rpcEndpoint, commitment);
|
|
329
|
+
return Promise.all(whitelistedTokens.map(async (mint) => {
|
|
330
|
+
const mplProgramId = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(mpl_token_metadata_1.MPL_TOKEN_METADATA_PROGRAM_ID);
|
|
331
|
+
const [metadata] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("metadata"), mplProgramId.toBytes(), mint.toBytes()], mplProgramId);
|
|
332
|
+
const mintInfo = await this.connection.getParsedAccountInfo(mint, commitment);
|
|
333
|
+
if (!mintInfo.value) {
|
|
334
|
+
throw new Error(`Failed to fetch mint account: ${mint.toString()}`);
|
|
335
|
+
}
|
|
336
|
+
// Check if the account is a valid mint account
|
|
337
|
+
const mintData = mintInfo.value.data;
|
|
338
|
+
if (Buffer.isBuffer(mintData) || mintData.parsed.type !== "mint") {
|
|
339
|
+
throw new Error(`The provided address is not a valid mint account: ${mint.toString()}`);
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
const metadataInfo = await (0, mpl_token_metadata_1.fetchMetadata)(umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(metadata));
|
|
343
|
+
return {
|
|
344
|
+
mint,
|
|
345
|
+
decimals: Number(mintData.parsed.info.decimals),
|
|
346
|
+
freezeAuthority: mintData.parsed.info.freezeAuthority
|
|
347
|
+
? new web3_js_1.PublicKey(mintData.parsed.info.freezeAuthority)
|
|
348
|
+
: null,
|
|
349
|
+
supply: (0, bignumber_js_1.BigNumber)(mintData.parsed.info.supply).div(solana_common_1.TEN_BIGNUM.pow(mintData.parsed.info.decimals)).toFixed(),
|
|
350
|
+
isInitialized: Boolean(mintData.parsed.info.isInitialized),
|
|
351
|
+
mintAuthority: mintData.parsed.info.mintAuthority
|
|
352
|
+
? new web3_js_1.PublicKey(mintData.parsed.info.mintAuthority)
|
|
353
|
+
: null,
|
|
354
|
+
metadata: {
|
|
355
|
+
address: metadata,
|
|
356
|
+
updateAuthority: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(metadataInfo.updateAuthority),
|
|
357
|
+
name: metadataInfo.name,
|
|
358
|
+
symbol: metadataInfo.symbol,
|
|
359
|
+
uri: metadataInfo.uri,
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
if (error instanceof Error &&
|
|
365
|
+
error.message.includes("The account of type [Metadata] was not found at the provided address")) {
|
|
366
|
+
console.warn(`Failed to fetch metadata for mint: ${mint.toBase58()}`, error);
|
|
367
|
+
return {
|
|
368
|
+
mint,
|
|
369
|
+
decimals: Number(mintData.parsed.info.decimals),
|
|
370
|
+
freezeAuthority: mintData.parsed.info.freezeAuthority
|
|
371
|
+
? new web3_js_1.PublicKey(mintData.parsed.info.freezeAuthority)
|
|
372
|
+
: null,
|
|
373
|
+
supply: (0, bignumber_js_1.BigNumber)(mintData.parsed.info.supply)
|
|
374
|
+
.div(solana_common_1.TEN_BIGNUM.pow(mintData.parsed.info.decimals))
|
|
375
|
+
.toFixed(),
|
|
376
|
+
isInitialized: Boolean(mintData.parsed.info.isInitialized),
|
|
377
|
+
mintAuthority: mintData.parsed.info.mintAuthority
|
|
378
|
+
? new web3_js_1.PublicKey(mintData.parsed.info.mintAuthority)
|
|
379
|
+
: null,
|
|
380
|
+
metadata: null,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
}));
|
|
386
|
+
}
|
|
321
387
|
async getStreamMetadataInfo(streamMetadata, commitment) {
|
|
322
388
|
const metadataInfo = await this.program.account.paymentStream.fetch((0, anchor_1.translateAddress)(streamMetadata), commitment ?? this.connection.commitment);
|
|
323
389
|
const streamToken = metadataInfo.financials.streamToken;
|
package/dist/types.d.ts
CHANGED
|
@@ -43,3 +43,18 @@ export type StreamMetadataInfo = {
|
|
|
43
43
|
};
|
|
44
44
|
streamName: string;
|
|
45
45
|
};
|
|
46
|
+
export type TokenMetadata = {
|
|
47
|
+
mint: PublicKey;
|
|
48
|
+
decimals: number;
|
|
49
|
+
freezeAuthority: PublicKey | null;
|
|
50
|
+
supply: string;
|
|
51
|
+
isInitialized: boolean;
|
|
52
|
+
mintAuthority: PublicKey | null;
|
|
53
|
+
metadata: {
|
|
54
|
+
address: PublicKey;
|
|
55
|
+
updateAuthority: PublicKey;
|
|
56
|
+
name: string;
|
|
57
|
+
symbol: string;
|
|
58
|
+
uri: string;
|
|
59
|
+
} | null;
|
|
60
|
+
};
|