-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
74 lines (73 loc) · 2.24 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* # Token Offchain Metadata
*
* This library provides a way to retrieve a token image from a token address.
*
* It relies on the parsing of [token lists](https://tokenlists.org/) to retrieve
* the metadata of tokens.
*
* ## Usage
*
* ### Loading token metadata from a token list
*
* Instantiate a {@link TokenMetadataStore}, and then call
* {@link TokenMetadataStore.prototype.fetchTokensFromList | `fetchTokensFromList`}
* with the URL of a token list to fetch and parse the token metadata:
*
* ```typescript
* import { TokenMetadataStore, toHttpsUrl } from "@prgm/token-offchain-metadata";
*
* const metadataStore = new TokenMetadataStore();
* await metadataStore.fetchTokensFromList(toHttpsUrl("ipns://tokens.uniswap.org"));
* ```
*
* ### Retrieving token metadata
*
* You can retrieve the metadata of a token that was added by calling
* {@link TokenMetadataStore.prototype.getTokenFromAddress | `getTokenFromAddress`}
* with the chain ID and address of the token:
*
* ```typescript
* const metadata = metadataStore.getTokenFromAddress({
* chainId: 1,
* address: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
* });
* ```
*
* This will return a {@link TokenMetadata} object that will contain some chain-agnostic
* metadata for the token.
*
* ### Manually adding token image sources
*
* If you have image sources for a token that are not included in the token list,
* you can add them manually by calling
* {@link TokenMetadataStore.prototype.addTokenLogoImageSources | `addTokenLogoImageSources`}.
*
* For example, if you have custom image for the DAI token, add a token image source for DAI:
*
* ```typescript
* metadataStore.addTokenLogoImageSources(
* { chainId: 1, address: "0x6B175474E89094C44Da98b954EedeAC495271d0F" },
* "/static/images/dai.png",
* );
* ```
*
* Note that if it was "bridged" by one of the token lists, it will be added
* to the metadata of _all_ associated tokens across chains.
*
* @module
*/
export type { Address, ChainAddress } from "./chain-address.ts";
export {
type TokenListMetadata,
type TokenMetadata,
TokenMetadataStore,
} from "./tokens.ts";
export {
type HttpsUrlString,
type IpfsUrlString,
type IpnsUrlString,
isHttpsUrl,
toHttpsUrl,
type Web3URL,
} from "./url.ts";