@yodlpay/tokenlists 1.0.1 → 1.1.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.
package/README.md CHANGED
@@ -71,6 +71,35 @@ const dai = getTokenBySymbol('DAI', 1);
71
71
  const weth = getNativeWrappedToken(1);
72
72
  ```
73
73
 
74
+ ### Stablecoins
75
+
76
+ ```typescript
77
+ import {
78
+ isStablecoin,
79
+ getStablecoinCurrency,
80
+ getStablecoinInfo,
81
+ getStablecoinsByPeg,
82
+ type FiatCurrency,
83
+ type StablecoinCheckResult
84
+ } from '@yodlpay/tokenlists';
85
+
86
+ // Check if a token is a stablecoin (by coinGeckoId)
87
+ isStablecoin('tether'); // true
88
+ isStablecoin('ethereum'); // false
89
+
90
+ // Get the currency a stablecoin is pegged to
91
+ getStablecoinCurrency('usd-coin'); // 'USD'
92
+ getStablecoinCurrency('euro-coin'); // 'EUR'
93
+
94
+ // Get detailed stablecoin info for a token
95
+ const token = getTokenBySymbol('USDC', 1);
96
+ const info = getStablecoinInfo(token);
97
+ // { isStablecoin: true, peggedTo: 'USD' }
98
+
99
+ // Get all stablecoin coinGeckoIds for a currency
100
+ getStablecoinsByPeg('EUR'); // ['euro-coin', 'monerium-eur-money', ...]
101
+ ```
102
+
74
103
  ### Router ABIs
75
104
 
76
105
  ```typescript
@@ -129,6 +158,23 @@ The package maintains two token lists:
129
158
  - **Featured** (`tokenlist-featured.json`) - Manually curated tokens with metadata updated from on-chain data
130
159
  - **Generated** (`tokenlist-generated.json`) - Auto-fetched tokens from external sources (cross-checked with other services as they are added)
131
160
 
161
+ ### Updating Stablecoin Registry
162
+
163
+ ```bash
164
+ yarn update:stablecoins
165
+ ```
166
+
167
+ Fetches stablecoin data from CoinGecko category APIs and updates `stablecoin-registry.json`. The script:
168
+
169
+ 1. Fetches tokens from CoinGecko stablecoin categories (USD, EUR, GBP, JPY, etc.)
170
+ 2. Filters to only include tokens present in the tokenlists (by coinGeckoId)
171
+ 3. Outputs a simple mapping of `coinGeckoId → peggedTo` currency
172
+
173
+ To update everything at once:
174
+ ```bash
175
+ yarn update:all # Runs update:stablecoins then update
176
+ ```
177
+
132
178
  ### How `yarn update` Works
133
179
 
134
180
  1. **Fetch tokens from Relay Link API** - Discovers tokens across all supported chains
@@ -0,0 +1,181 @@
1
+ import { B as BaseError, g as getUrl, s as stringify, d as decodeErrorResult, i as isAddressEqual, l as localBatchGatewayUrl, a as localBatchGatewayRequest, c as call, b as concat, e as encodeAbiParameters, H as HttpRequestError, f as isHex } from './index-C75unsqB.js';
2
+
3
+ class OffchainLookupError extends BaseError {
4
+ constructor({ callbackSelector, cause, data, extraData, sender, urls }){
5
+ super(cause.shortMessage || 'An error occurred while fetching for an offchain result.', {
6
+ cause,
7
+ metaMessages: [
8
+ ...cause.metaMessages || [],
9
+ cause.metaMessages?.length ? '' : [],
10
+ 'Offchain Gateway Call:',
11
+ urls && [
12
+ ' Gateway URL(s):',
13
+ ...urls.map((url)=>` ${getUrl(url)}`)
14
+ ],
15
+ ` Sender: ${sender}`,
16
+ ` Data: ${data}`,
17
+ ` Callback selector: ${callbackSelector}`,
18
+ ` Extra data: ${extraData}`
19
+ ].flat(),
20
+ name: 'OffchainLookupError'
21
+ });
22
+ }
23
+ }
24
+ class OffchainLookupResponseMalformedError extends BaseError {
25
+ constructor({ result, url }){
26
+ super('Offchain gateway response is malformed. Response data must be a hex value.', {
27
+ metaMessages: [
28
+ `Gateway URL: ${getUrl(url)}`,
29
+ `Response: ${stringify(result)}`
30
+ ],
31
+ name: 'OffchainLookupResponseMalformedError'
32
+ });
33
+ }
34
+ }
35
+ class OffchainLookupSenderMismatchError extends BaseError {
36
+ constructor({ sender, to }){
37
+ super('Reverted sender address does not match target contract address (`to`).', {
38
+ metaMessages: [
39
+ `Contract address: ${to}`,
40
+ `OffchainLookup sender address: ${sender}`
41
+ ],
42
+ name: 'OffchainLookupSenderMismatchError'
43
+ });
44
+ }
45
+ }
46
+
47
+ const offchainLookupSignature = '0x556f1830';
48
+ const offchainLookupAbiItem = {
49
+ name: 'OffchainLookup',
50
+ type: 'error',
51
+ inputs: [
52
+ {
53
+ name: 'sender',
54
+ type: 'address'
55
+ },
56
+ {
57
+ name: 'urls',
58
+ type: 'string[]'
59
+ },
60
+ {
61
+ name: 'callData',
62
+ type: 'bytes'
63
+ },
64
+ {
65
+ name: 'callbackFunction',
66
+ type: 'bytes4'
67
+ },
68
+ {
69
+ name: 'extraData',
70
+ type: 'bytes'
71
+ }
72
+ ]
73
+ };
74
+ async function offchainLookup(client, { blockNumber, blockTag, data, to }) {
75
+ const { args } = decodeErrorResult({
76
+ data,
77
+ abi: [
78
+ offchainLookupAbiItem
79
+ ]
80
+ });
81
+ const [sender, urls, callData, callbackSelector, extraData] = args;
82
+ const { ccipRead } = client;
83
+ const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function' ? ccipRead.request : ccipRequest;
84
+ try {
85
+ if (!isAddressEqual(to, sender)) throw new OffchainLookupSenderMismatchError({
86
+ sender,
87
+ to
88
+ });
89
+ const result = urls.includes(localBatchGatewayUrl) ? await localBatchGatewayRequest({
90
+ data: callData,
91
+ ccipRequest: ccipRequest_
92
+ }) : await ccipRequest_({
93
+ data: callData,
94
+ sender,
95
+ urls
96
+ });
97
+ const { data: data_ } = await call(client, {
98
+ blockNumber,
99
+ blockTag,
100
+ data: concat([
101
+ callbackSelector,
102
+ encodeAbiParameters([
103
+ {
104
+ type: 'bytes'
105
+ },
106
+ {
107
+ type: 'bytes'
108
+ }
109
+ ], [
110
+ result,
111
+ extraData
112
+ ])
113
+ ]),
114
+ to
115
+ });
116
+ return data_;
117
+ } catch (err) {
118
+ throw new OffchainLookupError({
119
+ callbackSelector,
120
+ cause: err,
121
+ data,
122
+ extraData,
123
+ sender,
124
+ urls
125
+ });
126
+ }
127
+ }
128
+ async function ccipRequest({ data, sender, urls }) {
129
+ let error = new Error('An unknown error occurred.');
130
+ for(let i = 0; i < urls.length; i++){
131
+ const url = urls[i];
132
+ const method = url.includes('{data}') ? 'GET' : 'POST';
133
+ const body = method === 'POST' ? {
134
+ data,
135
+ sender
136
+ } : undefined;
137
+ const headers = method === 'POST' ? {
138
+ 'Content-Type': 'application/json'
139
+ } : {};
140
+ try {
141
+ const response = await fetch(url.replace('{sender}', sender.toLowerCase()).replace('{data}', data), {
142
+ body: JSON.stringify(body),
143
+ headers,
144
+ method
145
+ });
146
+ let result;
147
+ if (response.headers.get('Content-Type')?.startsWith('application/json')) {
148
+ result = (await response.json()).data;
149
+ } else {
150
+ result = await response.text();
151
+ }
152
+ if (!response.ok) {
153
+ error = new HttpRequestError({
154
+ body,
155
+ details: result?.error ? stringify(result.error) : response.statusText,
156
+ headers: response.headers,
157
+ status: response.status,
158
+ url
159
+ });
160
+ continue;
161
+ }
162
+ if (!isHex(result)) {
163
+ error = new OffchainLookupResponseMalformedError({
164
+ result,
165
+ url
166
+ });
167
+ continue;
168
+ }
169
+ return result;
170
+ } catch (err) {
171
+ error = new HttpRequestError({
172
+ body,
173
+ details: err.message,
174
+ url
175
+ });
176
+ }
177
+ }
178
+ throw error;
179
+ }
180
+
181
+ export { ccipRequest, offchainLookup, offchainLookupAbiItem, offchainLookupSignature };
@@ -1,4 +1,4 @@
1
- var index = require('./index-Cso5F8p5.js');
1
+ var index = require('./index-DPv0KZek.cjs');
2
2
 
3
3
  class OffchainLookupError extends index.BaseError {
4
4
  constructor({ callbackSelector, cause, data, extraData, sender, urls }){