@ape.swap/bonds-sdk 4.5.4-test.0 → 4.5.4-test.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/ccip-DOs2Dd5_.js +295 -0
- package/dist/main-B5Z7fuXw.js +112903 -0
- package/dist/main.js +16 -106843
- package/dist/utils/displayHelpers.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { i as isAddress, I as InvalidAddressError, s as slice, t as toFunctionSelector, f as formatAbiItem, A as AbiFunctionSignatureNotFoundError, d as decodeAbiParameters, g as getAbiItem, a as AbiErrorNotFoundError, b as AbiErrorInputsNotFoundError, e as encodeAbiParameters, c as concatHex, h as AbiFunctionNotFoundError, j as AbiFunctionOutputsNotFoundError, k as InvalidArrayError, l as batchGatewayAbi, m as solidityError, B as BaseError, n as getUrl, o as stringify, p as decodeErrorResult, q as call, r as concat, H as HttpRequestError, u as isHex } from './main-B5Z7fuXw.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import '@tanstack/react-query';
|
|
4
|
+
import 'wagmi';
|
|
5
|
+
import 'axios';
|
|
6
|
+
import '@solana/web3.js';
|
|
7
|
+
import '@solana/rpc';
|
|
8
|
+
import '@solana/kit';
|
|
9
|
+
import '@solana/addresses';
|
|
10
|
+
import '@solana/codecs';
|
|
11
|
+
import '@solana/wallet-adapter-react';
|
|
12
|
+
import '@solana/wallet-adapter-react-ui';
|
|
13
|
+
import '@rainbow-me/rainbowkit';
|
|
14
|
+
import '@solana/spl-token';
|
|
15
|
+
|
|
16
|
+
function isAddressEqual(a, b) {
|
|
17
|
+
if (!isAddress(a, { strict: false }))
|
|
18
|
+
throw new InvalidAddressError({ address: a });
|
|
19
|
+
if (!isAddress(b, { strict: false }))
|
|
20
|
+
throw new InvalidAddressError({ address: b });
|
|
21
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function decodeFunctionData(parameters) {
|
|
25
|
+
const { abi, data } = parameters;
|
|
26
|
+
const signature = slice(data, 0, 4);
|
|
27
|
+
const description = abi.find((x) => x.type === 'function' &&
|
|
28
|
+
signature === toFunctionSelector(formatAbiItem(x)));
|
|
29
|
+
if (!description)
|
|
30
|
+
throw new AbiFunctionSignatureNotFoundError(signature, {
|
|
31
|
+
docsPath: '/docs/contract/decodeFunctionData',
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
functionName: description.name,
|
|
35
|
+
args: ('inputs' in description &&
|
|
36
|
+
description.inputs &&
|
|
37
|
+
description.inputs.length > 0
|
|
38
|
+
? decodeAbiParameters(description.inputs, slice(data, 4))
|
|
39
|
+
: undefined),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const docsPath$1 = '/docs/contract/encodeErrorResult';
|
|
44
|
+
function encodeErrorResult(parameters) {
|
|
45
|
+
const { abi, errorName, args } = parameters;
|
|
46
|
+
let abiItem = abi[0];
|
|
47
|
+
if (errorName) {
|
|
48
|
+
const item = getAbiItem({ abi, args, name: errorName });
|
|
49
|
+
if (!item)
|
|
50
|
+
throw new AbiErrorNotFoundError(errorName, { docsPath: docsPath$1 });
|
|
51
|
+
abiItem = item;
|
|
52
|
+
}
|
|
53
|
+
if (abiItem.type !== 'error')
|
|
54
|
+
throw new AbiErrorNotFoundError(undefined, { docsPath: docsPath$1 });
|
|
55
|
+
const definition = formatAbiItem(abiItem);
|
|
56
|
+
const signature = toFunctionSelector(definition);
|
|
57
|
+
let data = '0x';
|
|
58
|
+
if (args && args.length > 0) {
|
|
59
|
+
if (!abiItem.inputs)
|
|
60
|
+
throw new AbiErrorInputsNotFoundError(abiItem.name, { docsPath: docsPath$1 });
|
|
61
|
+
data = encodeAbiParameters(abiItem.inputs, args);
|
|
62
|
+
}
|
|
63
|
+
return concatHex([signature, data]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const docsPath = '/docs/contract/encodeFunctionResult';
|
|
67
|
+
function encodeFunctionResult(parameters) {
|
|
68
|
+
const { abi, functionName, result } = parameters;
|
|
69
|
+
let abiItem = abi[0];
|
|
70
|
+
if (functionName) {
|
|
71
|
+
const item = getAbiItem({ abi, name: functionName });
|
|
72
|
+
if (!item)
|
|
73
|
+
throw new AbiFunctionNotFoundError(functionName, { docsPath });
|
|
74
|
+
abiItem = item;
|
|
75
|
+
}
|
|
76
|
+
if (abiItem.type !== 'function')
|
|
77
|
+
throw new AbiFunctionNotFoundError(undefined, { docsPath });
|
|
78
|
+
if (!abiItem.outputs)
|
|
79
|
+
throw new AbiFunctionOutputsNotFoundError(abiItem.name, { docsPath });
|
|
80
|
+
const values = (() => {
|
|
81
|
+
if (abiItem.outputs.length === 0)
|
|
82
|
+
return [];
|
|
83
|
+
if (abiItem.outputs.length === 1)
|
|
84
|
+
return [result];
|
|
85
|
+
if (Array.isArray(result))
|
|
86
|
+
return result;
|
|
87
|
+
throw new InvalidArrayError(result);
|
|
88
|
+
})();
|
|
89
|
+
return encodeAbiParameters(abiItem.outputs, values);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const localBatchGatewayUrl = 'x-batch-gateway:true';
|
|
93
|
+
async function localBatchGatewayRequest(parameters) {
|
|
94
|
+
const { data, ccipRequest } = parameters;
|
|
95
|
+
const { args: [queries], } = decodeFunctionData({ abi: batchGatewayAbi, data });
|
|
96
|
+
const failures = [];
|
|
97
|
+
const responses = [];
|
|
98
|
+
await Promise.all(queries.map(async (query, i) => {
|
|
99
|
+
try {
|
|
100
|
+
responses[i] = query.urls.includes(localBatchGatewayUrl)
|
|
101
|
+
? await localBatchGatewayRequest({ data: query.data, ccipRequest })
|
|
102
|
+
: await ccipRequest(query);
|
|
103
|
+
failures[i] = false;
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
failures[i] = true;
|
|
107
|
+
responses[i] = encodeError(err);
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
110
|
+
return encodeFunctionResult({
|
|
111
|
+
abi: batchGatewayAbi,
|
|
112
|
+
functionName: 'query',
|
|
113
|
+
result: [failures, responses],
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function encodeError(error) {
|
|
117
|
+
if (error.name === 'HttpRequestError' && error.status)
|
|
118
|
+
return encodeErrorResult({
|
|
119
|
+
abi: batchGatewayAbi,
|
|
120
|
+
errorName: 'HttpError',
|
|
121
|
+
args: [error.status, error.shortMessage],
|
|
122
|
+
});
|
|
123
|
+
return encodeErrorResult({
|
|
124
|
+
abi: [solidityError],
|
|
125
|
+
errorName: 'Error',
|
|
126
|
+
args: ['shortMessage' in error ? error.shortMessage : error.message],
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
class OffchainLookupError extends BaseError {
|
|
131
|
+
constructor({ callbackSelector, cause, data, extraData, sender, urls, }) {
|
|
132
|
+
super(cause.shortMessage ||
|
|
133
|
+
'An error occurred while fetching for an offchain result.', {
|
|
134
|
+
cause,
|
|
135
|
+
metaMessages: [
|
|
136
|
+
...(cause.metaMessages || []),
|
|
137
|
+
cause.metaMessages?.length ? '' : [],
|
|
138
|
+
'Offchain Gateway Call:',
|
|
139
|
+
urls && [
|
|
140
|
+
' Gateway URL(s):',
|
|
141
|
+
...urls.map((url) => ` ${getUrl(url)}`),
|
|
142
|
+
],
|
|
143
|
+
` Sender: ${sender}`,
|
|
144
|
+
` Data: ${data}`,
|
|
145
|
+
` Callback selector: ${callbackSelector}`,
|
|
146
|
+
` Extra data: ${extraData}`,
|
|
147
|
+
].flat(),
|
|
148
|
+
name: 'OffchainLookupError',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
class OffchainLookupResponseMalformedError extends BaseError {
|
|
153
|
+
constructor({ result, url }) {
|
|
154
|
+
super('Offchain gateway response is malformed. Response data must be a hex value.', {
|
|
155
|
+
metaMessages: [
|
|
156
|
+
`Gateway URL: ${getUrl(url)}`,
|
|
157
|
+
`Response: ${stringify(result)}`,
|
|
158
|
+
],
|
|
159
|
+
name: 'OffchainLookupResponseMalformedError',
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
class OffchainLookupSenderMismatchError extends BaseError {
|
|
164
|
+
constructor({ sender, to }) {
|
|
165
|
+
super('Reverted sender address does not match target contract address (`to`).', {
|
|
166
|
+
metaMessages: [
|
|
167
|
+
`Contract address: ${to}`,
|
|
168
|
+
`OffchainLookup sender address: ${sender}`,
|
|
169
|
+
],
|
|
170
|
+
name: 'OffchainLookupSenderMismatchError',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const offchainLookupSignature = '0x556f1830';
|
|
176
|
+
const offchainLookupAbiItem = {
|
|
177
|
+
name: 'OffchainLookup',
|
|
178
|
+
type: 'error',
|
|
179
|
+
inputs: [
|
|
180
|
+
{
|
|
181
|
+
name: 'sender',
|
|
182
|
+
type: 'address',
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: 'urls',
|
|
186
|
+
type: 'string[]',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'callData',
|
|
190
|
+
type: 'bytes',
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: 'callbackFunction',
|
|
194
|
+
type: 'bytes4',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'extraData',
|
|
198
|
+
type: 'bytes',
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
};
|
|
202
|
+
async function offchainLookup(client, { blockNumber, blockTag, data, to, }) {
|
|
203
|
+
const { args } = decodeErrorResult({
|
|
204
|
+
data,
|
|
205
|
+
abi: [offchainLookupAbiItem],
|
|
206
|
+
});
|
|
207
|
+
const [sender, urls, callData, callbackSelector, extraData] = args;
|
|
208
|
+
const { ccipRead } = client;
|
|
209
|
+
const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function'
|
|
210
|
+
? ccipRead.request
|
|
211
|
+
: ccipRequest;
|
|
212
|
+
try {
|
|
213
|
+
if (!isAddressEqual(to, sender))
|
|
214
|
+
throw new OffchainLookupSenderMismatchError({ sender, to });
|
|
215
|
+
const result = urls.includes(localBatchGatewayUrl)
|
|
216
|
+
? await localBatchGatewayRequest({
|
|
217
|
+
data: callData,
|
|
218
|
+
ccipRequest: ccipRequest_,
|
|
219
|
+
})
|
|
220
|
+
: await ccipRequest_({ data: callData, sender, urls });
|
|
221
|
+
const { data: data_ } = await call(client, {
|
|
222
|
+
blockNumber,
|
|
223
|
+
blockTag,
|
|
224
|
+
data: concat([
|
|
225
|
+
callbackSelector,
|
|
226
|
+
encodeAbiParameters([{ type: 'bytes' }, { type: 'bytes' }], [result, extraData]),
|
|
227
|
+
]),
|
|
228
|
+
to,
|
|
229
|
+
});
|
|
230
|
+
return data_;
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
throw new OffchainLookupError({
|
|
234
|
+
callbackSelector,
|
|
235
|
+
cause: err,
|
|
236
|
+
data,
|
|
237
|
+
extraData,
|
|
238
|
+
sender,
|
|
239
|
+
urls,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async function ccipRequest({ data, sender, urls, }) {
|
|
244
|
+
let error = new Error('An unknown error occurred.');
|
|
245
|
+
for (let i = 0; i < urls.length; i++) {
|
|
246
|
+
const url = urls[i];
|
|
247
|
+
const method = url.includes('{data}') ? 'GET' : 'POST';
|
|
248
|
+
const body = method === 'POST' ? { data, sender } : undefined;
|
|
249
|
+
const headers = method === 'POST' ? { 'Content-Type': 'application/json' } : {};
|
|
250
|
+
try {
|
|
251
|
+
const response = await fetch(url.replace('{sender}', sender.toLowerCase()).replace('{data}', data), {
|
|
252
|
+
body: JSON.stringify(body),
|
|
253
|
+
headers,
|
|
254
|
+
method,
|
|
255
|
+
});
|
|
256
|
+
let result;
|
|
257
|
+
if (response.headers.get('Content-Type')?.startsWith('application/json')) {
|
|
258
|
+
result = (await response.json()).data;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
result = (await response.text());
|
|
262
|
+
}
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
error = new HttpRequestError({
|
|
265
|
+
body,
|
|
266
|
+
details: result?.error
|
|
267
|
+
? stringify(result.error)
|
|
268
|
+
: response.statusText,
|
|
269
|
+
headers: response.headers,
|
|
270
|
+
status: response.status,
|
|
271
|
+
url,
|
|
272
|
+
});
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (!isHex(result)) {
|
|
276
|
+
error = new OffchainLookupResponseMalformedError({
|
|
277
|
+
result,
|
|
278
|
+
url,
|
|
279
|
+
});
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
error = new HttpRequestError({
|
|
286
|
+
body,
|
|
287
|
+
details: err.message,
|
|
288
|
+
url,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export { ccipRequest, offchainLookup, offchainLookupAbiItem, offchainLookupSignature };
|