@yodlpay/tokenlists 1.0.1 → 1.0.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.
@@ -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-QILtCArq.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-BxN39P-j.cjs');
2
2
 
3
3
  class OffchainLookupError extends index.BaseError {
4
4
  constructor({ callbackSelector, cause, data, extraData, sender, urls }){
@@ -16696,7 +16696,7 @@ const schedulerCache = /*#__PURE__*/ new Map();
16696
16696
  } catch (err) {
16697
16697
  const data = getRevertErrorData(err);
16698
16698
  // Check for CCIP-Read offchain lookup signature.
16699
- const { offchainLookup, offchainLookupSignature } = await Promise.resolve().then(function () { return require('./ccip-CTW8a_vN.js'); });
16699
+ const { offchainLookup, offchainLookupSignature } = await Promise.resolve().then(function () { return require('./ccip-BgzcZHmu.cjs'); });
16700
16700
  if (client.ccipRead !== false && data?.slice(0, 10) === offchainLookupSignature && to) return {
16701
16701
  data: await offchainLookup(client, {
16702
16702
  data,