@flapsdk/vault-runtime 0.1.37 → 0.1.38-next.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 +0 -45
- package/{chunk-HYBZWS6U.js → chunk-44P2NRRZ.js} +94 -267
- package/chunk-44P2NRRZ.js.map +1 -0
- package/chunk-A3ER7XYN.js +408 -0
- package/chunk-A3ER7XYN.js.map +1 -0
- package/{chunk-22KTLOYH.js → chunk-FWYBGHBX.js} +17 -4
- package/chunk-FWYBGHBX.js.map +1 -0
- package/{chunk-3X2K7YYU.js → chunk-JVOFLTLD.js} +165 -54
- package/chunk-JVOFLTLD.js.map +1 -0
- package/{chunk-SRZFHGSO.js → chunk-PU7VEZWA.js} +3 -3
- package/{chunk-SRZFHGSO.js.map → chunk-PU7VEZWA.js.map} +1 -1
- package/{chunk-27VBKY3J.js → chunk-SAG36LUR.js} +3 -4
- package/chunk-SAG36LUR.js.map +1 -0
- package/host-client.d.mts +9 -2
- package/host-client.js +5 -5
- package/host.d.mts +5 -5
- package/host.js +4 -4
- package/{hostRuntimeConfig-DM6JjbeO.d.mts → hostRuntimeConfig-DibvcxHE.d.mts} +1 -1
- package/{mpegts-536UQHCG.js → mpegts-J2J6JTD7.js} +6 -6
- package/{mpegts-536UQHCG.js.map → mpegts-J2J6JTD7.js.map} +1 -1
- package/package.json +4 -3
- package/runtime-contract.json +6 -3
- package/sdk.d.mts +40 -6
- package/sdk.js +40 -9
- package/sdk.js.map +1 -1
- package/server.d.mts +3 -3
- package/server.js +2 -2
- package/{txError-vvvBIsa-.d.mts → txError-OBuRV8xN.d.mts} +15 -2
- package/{types-cyAEoeXa.d.mts → types-DUZWZ3mC.d.mts} +98 -6
- package/ui.d.mts +16 -13
- package/ui.js +2 -2
- package/chunk-22KTLOYH.js.map +0 -1
- package/chunk-27VBKY3J.js.map +0 -1
- package/chunk-3X2K7YYU.js.map +0 -1
- package/chunk-AGLB72HK.js +0 -61
- package/chunk-AGLB72HK.js.map +0 -1
- package/chunk-HYBZWS6U.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,8 +6,6 @@ Generated from `flap-vault-ui-template`.
|
|
|
6
6
|
|
|
7
7
|
This package is the shared runtime surface that local preview, Artifact Workbench, and `flap.sh` should agree on.
|
|
8
8
|
|
|
9
|
-
Package version: `0.1.37`. Source commit: `ad40bab7dfc976d20dd82050aeec17fef18a39b3`.
|
|
10
|
-
|
|
11
9
|
## Exports
|
|
12
10
|
|
|
13
11
|
- `./sdk`: component-facing SDK hooks, helpers, types, and local oracle reader helper
|
|
@@ -16,46 +14,3 @@ Package version: `0.1.37`. Source commit: `ad40bab7dfc976d20dd82050aeec17fef18a3
|
|
|
16
14
|
- `./server`: server-side presentation, runtime oracle-registry helpers, controlled image/text upload handler, and the Vault V2 NFT metadata/media resolver
|
|
17
15
|
|
|
18
16
|
See `runtime-contract.json` for the machine-readable subpath contract.
|
|
19
|
-
|
|
20
|
-
## Dynamic IPFS content
|
|
21
|
-
|
|
22
|
-
Stable runtime `0.1.37` introduces `sdk.readIpfsText(cid, path?)`, which returns
|
|
23
|
-
UTF-8 text or JSON as a string, and `IpfsText` for escaped plain-text display.
|
|
24
|
-
`IpfsImage` accepts dynamic bare CIDs from FSI, contract state, or SDK uploads.
|
|
25
|
-
The SDK exports `IPFS_CONTENT_VERSION = 1`; the runtime contract advertises
|
|
26
|
-
`sdkFeatures.ipfsContent = 1`. Stable `0.1.36` lacks the text API/component.
|
|
27
|
-
|
|
28
|
-
Vault source keeps the `@/src/sdk` and `@/src/ui` authoring aliases. Obtain
|
|
29
|
-
`sdk` with `useFlapSdk()`, then call the reader from an async effect or event
|
|
30
|
-
handler. Import `IpfsText` and `IpfsImage` from the UI alias for rendering:
|
|
31
|
-
|
|
32
|
-
```tsx
|
|
33
|
-
const body = await sdk.readIpfsText(textCid);
|
|
34
|
-
// Parse JSON only if the application expects JSON content.
|
|
35
|
-
const post = JSON.parse(await sdk.readIpfsText(jsonCid));
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
```tsx
|
|
39
|
-
<IpfsText cid={item.textCid} fallback={i18n.t("contentLoading")} />
|
|
40
|
-
<IpfsImage cid={item.imageCid} alt={i18n.t("postImageAlt")} />
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Use safe relative `path` values for directory CIDs, never a gateway URL or
|
|
44
|
-
`ipfs://` URI. The runtime controls gateways and validates every CID/path.
|
|
45
|
-
Text reads omit credentials/referrers, reject redirects and HTML responses,
|
|
46
|
-
enforce UTF-8 and a 256 KiB limit, and have an 8-second network/body deadline
|
|
47
|
-
after acquiring an active slot. Reads are deduplicated, cached and concurrency
|
|
48
|
-
limited. `IpfsText` does not interpret HTML or Markdown. Localize loading/error
|
|
49
|
-
and alt text, and paginate feeds. `IpfsBackground` remains static CID-only.
|
|
50
|
-
|
|
51
|
-
Dynamic content sources require human review. Upgrade Workbench and Flap hosts
|
|
52
|
-
to the published runtime and deploy Workbench's matching static checker before
|
|
53
|
-
accepting new components. Reads use platform gateways without a new host route;
|
|
54
|
-
uploads continue through the existing host-owned upload service. Automated
|
|
55
|
-
upload fixtures are mocked and do not verify live gateway availability.
|
|
56
|
-
|
|
57
|
-
Source documentation:
|
|
58
|
-
|
|
59
|
-
- [API guide](https://github.com/flap-sh/flap-vault-component-template/blob/main/docs/ipfs-content.md)
|
|
60
|
-
- [API 说明](https://github.com/flap-sh/flap-vault-component-template/blob/main/docs/ipfs-content.zh-CN.md)
|
|
61
|
-
- [Release and upgrade notes](https://github.com/flap-sh/flap-vault-component-template/blob/main/docs/releases/0.1.37.md)
|
|
@@ -1,259 +1,79 @@
|
|
|
1
|
-
import { createVaultRuntimeContext, chainLabelForChain } from './chunk-
|
|
2
|
-
import {
|
|
1
|
+
import { createVaultRuntimeContext, chainLabelForChain, readContractEventsInBlockRanges, resolveSafeContractWriteFeeOverrides, createFlapChainSdk } from './chunk-A3ER7XYN.js';
|
|
2
|
+
import { createLocalMediaUploader, createLocalNftMetadataReader, vaultV2NftAbi, nftTokenUriAbi } from './chunk-PU7VEZWA.js';
|
|
3
3
|
import { fetchOracleJson } from './chunk-JLI25XFB.js';
|
|
4
|
-
import { RuntimeContext, Alert } from './chunk-
|
|
4
|
+
import { RuntimeContext, Alert } from './chunk-JVOFLTLD.js';
|
|
5
5
|
import { isValidAddress, ZERO_ADDRESS } from './chunk-B4WKI3EW.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { toFunctionSelector, parseAbi, encodeFunctionData,
|
|
6
|
+
import { useRef, useMemo, useState, useCallback, useEffect } from 'react';
|
|
7
|
+
import { useConfig, useAccount, useChainId, useConnect, useDisconnect, useSwitchChain, usePublicClient, useWalletClient, useBalance } from 'wagmi';
|
|
8
|
+
import { switchChain, disconnect, getAccount, getPublicClient, getWalletClient } from 'wagmi/actions';
|
|
9
|
+
import { toFunctionSelector, parseAbi, encodeFunctionData, decodeFunctionResult, formatUnits, decodeAbiParameters, decodeEventLog, getContractAddress, concatHex, encodeAbiParameters, keccak256 } from 'viem';
|
|
10
10
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
11
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
|
-
// src/sdk/fsi.ts
|
|
54
|
-
async function readFsiJson(endpoints, path, params, fetchImpl = fetch) {
|
|
55
|
-
if (!hasFsiQueryDeclaration(endpoints)) {
|
|
56
|
-
throw new Error("FSI requires https://bsc-debug.butterfly.army/fsi/v1 in manifest.endpoints for review.");
|
|
57
|
-
}
|
|
58
|
-
const url = buildFsiQueryUrl(path, params);
|
|
59
|
-
const response = await fetchImpl(url, {
|
|
60
|
-
method: "GET",
|
|
61
|
-
credentials: "omit",
|
|
62
|
-
redirect: "error",
|
|
63
|
-
referrerPolicy: "no-referrer",
|
|
64
|
-
cache: "no-store"
|
|
65
|
-
});
|
|
66
|
-
if (!response.ok) throw new Error(`FSI request returned ${response.status}.`);
|
|
67
|
-
return await response.json();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/sdk/ipfsText.ts
|
|
71
|
-
var MAX_TEXT_BYTES = 256 * 1024;
|
|
72
|
-
var MAX_CONCURRENT_READS = 6;
|
|
73
|
-
var MAX_PENDING_READS = 128;
|
|
74
|
-
var MAX_CACHED_READS = 64;
|
|
75
|
-
var TEXT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text/plain", "application/json", "application/octet-stream"]);
|
|
76
|
-
async function readTextBody(response, signal) {
|
|
77
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
78
|
-
if (!TEXT_MEDIA_TYPES.has(contentType.split(";")[0].trim().toLowerCase())) {
|
|
79
|
-
throw new Error("IPFS text must use text/plain, application/json or application/octet-stream.");
|
|
80
|
-
}
|
|
81
|
-
const charset = /charset\s*=\s*["']?([^;"'\s]+)/i.exec(contentType)?.[1];
|
|
82
|
-
if (charset && !/^utf-?8$/i.test(charset)) throw new Error("IPFS text must use UTF-8.");
|
|
83
|
-
if (Number(response.headers.get("content-length")) > MAX_TEXT_BYTES) {
|
|
84
|
-
await response.body?.cancel();
|
|
85
|
-
throw new Error("IPFS text exceeds 256 KiB.");
|
|
86
|
-
}
|
|
87
|
-
const reader = response.body?.getReader();
|
|
88
|
-
if (!reader) return "";
|
|
89
|
-
const abort = () => {
|
|
90
|
-
void reader.cancel().catch(() => {
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
94
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
95
|
-
let bytes = 0;
|
|
96
|
-
let text = "";
|
|
97
|
-
try {
|
|
98
|
-
while (true) {
|
|
99
|
-
const chunk = await reader.read();
|
|
100
|
-
if (signal.aborted) throw new Error("IPFS text request timed out.");
|
|
101
|
-
if (chunk.done) break;
|
|
102
|
-
bytes += chunk.value.byteLength;
|
|
103
|
-
if (bytes > MAX_TEXT_BYTES) throw new Error("IPFS text exceeds 256 KiB.");
|
|
104
|
-
text += decoder.decode(chunk.value, { stream: true });
|
|
105
|
-
}
|
|
106
|
-
text += decoder.decode();
|
|
107
|
-
if (/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(text)) throw new Error("IPFS content is not plain UTF-8 text.");
|
|
108
|
-
return text;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
void reader.cancel().catch(() => {
|
|
111
|
-
});
|
|
112
|
-
throw error;
|
|
113
|
-
} finally {
|
|
114
|
-
signal.removeEventListener("abort", abort);
|
|
115
|
-
reader.releaseLock();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function createIpfsTextReader({ fetchImpl = fetch, timeoutMs = 8e3 } = {}) {
|
|
119
|
-
const cache = /* @__PURE__ */ new Map();
|
|
120
|
-
const pending = /* @__PURE__ */ new Map();
|
|
121
|
-
const waiting = [];
|
|
122
|
-
let active = 0;
|
|
123
|
-
async function load(urls) {
|
|
124
|
-
if (active >= MAX_CONCURRENT_READS) await new Promise((resolve) => waiting.push(resolve));
|
|
125
|
-
active++;
|
|
126
|
-
const controller = new AbortController();
|
|
127
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
128
|
-
try {
|
|
129
|
-
let lastError;
|
|
130
|
-
for (const url of urls) {
|
|
131
|
-
let response;
|
|
132
|
-
try {
|
|
133
|
-
response = await fetchImpl(url, {
|
|
134
|
-
method: "GET",
|
|
135
|
-
credentials: "omit",
|
|
136
|
-
redirect: "error",
|
|
137
|
-
referrerPolicy: "no-referrer",
|
|
138
|
-
cache: "force-cache",
|
|
139
|
-
signal: controller.signal
|
|
140
|
-
});
|
|
141
|
-
} catch (error) {
|
|
142
|
-
if (controller.signal.aborted) throw new Error("IPFS text request timed out.");
|
|
143
|
-
lastError = error;
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
if (!response.ok) {
|
|
147
|
-
await response.body?.cancel();
|
|
148
|
-
lastError = new Error(`IPFS text request returned ${response.status}.`);
|
|
149
|
-
continue;
|
|
12
|
+
var defaultUploader = createLocalMediaUploader();
|
|
13
|
+
function useFlapWalletRuntime({ connect, readOnly = false, mediaUploader = defaultUploader }) {
|
|
14
|
+
const config = useConfig();
|
|
15
|
+
const account = useAccount();
|
|
16
|
+
const connectRef = useRef(connect);
|
|
17
|
+
connectRef.current = connect;
|
|
18
|
+
return useMemo(() => {
|
|
19
|
+
const publicClient = (chainId) => {
|
|
20
|
+
const client = getPublicClient(config, { chainId });
|
|
21
|
+
if (!client) throw new Error(`No host public client for ${chainId}.`);
|
|
22
|
+
return client;
|
|
23
|
+
};
|
|
24
|
+
const walletClient = async (chainId, expected) => {
|
|
25
|
+
if (readOnly) throw new Error("Preview fixtures cannot authorize transactions.");
|
|
26
|
+
const client = await getWalletClient(config, { chainId });
|
|
27
|
+
const current = getAccount(config);
|
|
28
|
+
if (!current.isConnected || current.chainId !== chainId || current.address?.toLowerCase() !== expected.toLowerCase() || client.account.address.toLowerCase() !== expected.toLowerCase() || client.chain.id !== chainId) throw new Error("The host wallet changed. Review the account and network again.");
|
|
29
|
+
return client;
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
chains: config.chains.map((chain) => ({ id: chain.id, name: chain.name, explorerBaseUrl: chain.blockExplorers?.default.url })),
|
|
33
|
+
readOnly,
|
|
34
|
+
getAccount: () => {
|
|
35
|
+
const current = getAccount(config);
|
|
36
|
+
return { address: current.address, chainId: current.chainId, isConnected: current.isConnected };
|
|
37
|
+
},
|
|
38
|
+
generation: `${account.address ?? ""}:${account.chainId ?? ""}:${account.isConnected}`,
|
|
39
|
+
connect: () => connectRef.current(),
|
|
40
|
+
disconnect: () => {
|
|
41
|
+
void disconnect(config);
|
|
42
|
+
},
|
|
43
|
+
switchChain: async (chainId) => {
|
|
44
|
+
if (readOnly) throw new Error("Preview fixtures cannot switch a wallet.");
|
|
45
|
+
await switchChain(config, { chainId });
|
|
46
|
+
},
|
|
47
|
+
readContract: async (chainId, request) => {
|
|
48
|
+
const client = publicClient(chainId);
|
|
49
|
+
if (request.gasPrice !== void 0) {
|
|
50
|
+
const { data } = await client.call({ to: request.address, data: encodeFunctionData(request), account: request.account, gasPrice: request.gasPrice });
|
|
51
|
+
return decodeFunctionResult({ abi: request.abi, functionName: request.functionName, data: data ?? "0x" });
|
|
150
52
|
}
|
|
151
|
-
return
|
|
53
|
+
return client.readContract(request);
|
|
54
|
+
},
|
|
55
|
+
simulateContract: async (chainId, request) => (await publicClient(chainId).simulateContract(request)).result,
|
|
56
|
+
writeContract: async (chainId, request) => (await walletClient(chainId, request.account)).writeContract(request),
|
|
57
|
+
sendTransaction: async (chainId, request) => (await walletClient(chainId, request.account)).sendTransaction(request),
|
|
58
|
+
waitForTx: async (chainId, hash2) => {
|
|
59
|
+
const receipt = await publicClient(chainId).waitForTransactionReceipt({ hash: hash2 });
|
|
60
|
+
return { hash: receipt.transactionHash, status: receipt.status, blockNumber: receipt.blockNumber, logs: receipt.logs };
|
|
61
|
+
},
|
|
62
|
+
getCode: (chainId, address2) => publicClient(chainId).getCode({ address: address2 }),
|
|
63
|
+
getGasPrice: (chainId) => publicClient(chainId).getGasPrice(),
|
|
64
|
+
getBlockNumber: (chainId) => publicClient(chainId).getBlockNumber(),
|
|
65
|
+
getBalance: (chainId, address2) => publicClient(chainId).getBalance({ address: address2 }),
|
|
66
|
+
getContractEvents: async (chainId, request) => publicClient(chainId).getContractEvents(request),
|
|
67
|
+
upload: mediaUploader,
|
|
68
|
+
openUrl: (url) => {
|
|
69
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
152
70
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
clearTimeout(timer);
|
|
156
|
-
controller.abort();
|
|
157
|
-
active--;
|
|
158
|
-
waiting.shift()?.();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return (cid, path) => {
|
|
162
|
-
const urls = resolveIpfsImageUrls(cid, 56, path);
|
|
163
|
-
if (!urls.length) return Promise.reject(new Error("IPFS text requires a bare CID and an optional safe relative path."));
|
|
164
|
-
const key = urls[0];
|
|
165
|
-
const cached = cache.get(key);
|
|
166
|
-
if (cached !== void 0) {
|
|
167
|
-
cache.delete(key);
|
|
168
|
-
cache.set(key, cached);
|
|
169
|
-
return Promise.resolve(cached);
|
|
170
|
-
}
|
|
171
|
-
const existing = pending.get(key);
|
|
172
|
-
if (existing) return existing;
|
|
173
|
-
if (pending.size >= MAX_PENDING_READS) return Promise.reject(new Error("Too many IPFS text reads; paginate the content."));
|
|
174
|
-
const request = load(urls).then((text) => {
|
|
175
|
-
cache.set(key, text);
|
|
176
|
-
if (cache.size > MAX_CACHED_READS) cache.delete(cache.keys().next().value);
|
|
177
|
-
return text;
|
|
178
|
-
}).finally(() => pending.delete(key));
|
|
179
|
-
pending.set(key, request);
|
|
180
|
-
return request;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/sdk/contractWriteFees.ts
|
|
185
|
-
var MAX_CONTRACT_WRITE_GAS = 5000000n;
|
|
186
|
-
var MAX_GAS_PRICE_MULTIPLIER = 2n;
|
|
187
|
-
async function resolveSafeContractWriteFeeOverrides(request, getNetworkGasPrice) {
|
|
188
|
-
if (request.gas !== void 0) {
|
|
189
|
-
if (request.gas <= 0n) throw new Error("Contract write gas must be greater than zero.");
|
|
190
|
-
if (request.gas > MAX_CONTRACT_WRITE_GAS) {
|
|
191
|
-
throw new Error(`Contract write gas must not exceed ${MAX_CONTRACT_WRITE_GAS.toString()}.`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
if (request.gasPrice !== void 0) {
|
|
195
|
-
if (request.gasPrice <= 0n) throw new Error("Contract write gasPrice must be greater than zero.");
|
|
196
|
-
const networkGasPrice = await getNetworkGasPrice();
|
|
197
|
-
if (networkGasPrice <= 0n) throw new Error("The runtime returned an invalid network gas price.");
|
|
198
|
-
const maximumGasPrice = networkGasPrice * MAX_GAS_PRICE_MULTIPLIER;
|
|
199
|
-
if (request.gasPrice > maximumGasPrice) {
|
|
200
|
-
throw new Error(
|
|
201
|
-
`Contract write gasPrice ${request.gasPrice.toString()} exceeds the runtime safety limit ${maximumGasPrice.toString()}.`
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
...request.gas === void 0 ? {} : { gas: request.gas },
|
|
207
|
-
...request.gasPrice === void 0 ? {} : { gasPrice: request.gasPrice }
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/sdk/contractEvents.ts
|
|
212
|
-
var MAX_CONTRACT_EVENT_BLOCK_SPAN = 1000n;
|
|
213
|
-
var MAX_CONTRACT_EVENT_BLOCK_LOOKBACK = 20000n;
|
|
214
|
-
var CONTRACT_EVENT_QUERY_CONCURRENCY = 4;
|
|
215
|
-
function splitContractEventBlockRanges(fromBlock, toBlock, maxBlockSpan = MAX_CONTRACT_EVENT_BLOCK_SPAN, maxLookback = MAX_CONTRACT_EVENT_BLOCK_LOOKBACK) {
|
|
216
|
-
if (fromBlock < 0n || toBlock < 0n) {
|
|
217
|
-
throw new RangeError("Contract event block numbers must not be negative.");
|
|
218
|
-
}
|
|
219
|
-
if (maxBlockSpan <= 0n) {
|
|
220
|
-
throw new RangeError("Contract event block span must be greater than zero.");
|
|
221
|
-
}
|
|
222
|
-
if (maxLookback < 0n) {
|
|
223
|
-
throw new RangeError("Contract event block lookback must not be negative.");
|
|
224
|
-
}
|
|
225
|
-
if (toBlock < fromBlock) return [];
|
|
226
|
-
if (toBlock - fromBlock > maxLookback) {
|
|
227
|
-
throw new RangeError(`Contract event block range must not exceed ${maxLookback.toString()} blocks.`);
|
|
228
|
-
}
|
|
229
|
-
const ranges = [];
|
|
230
|
-
let cursor = fromBlock;
|
|
231
|
-
while (cursor <= toBlock) {
|
|
232
|
-
const candidateEnd = cursor + maxBlockSpan;
|
|
233
|
-
const chunkEnd = candidateEnd < toBlock ? candidateEnd : toBlock;
|
|
234
|
-
ranges.push({ fromBlock: cursor, toBlock: chunkEnd });
|
|
235
|
-
cursor = chunkEnd + 1n;
|
|
236
|
-
}
|
|
237
|
-
return ranges;
|
|
238
|
-
}
|
|
239
|
-
async function readContractEventsInBlockRanges(input) {
|
|
240
|
-
const concurrency = input.concurrency ?? CONTRACT_EVENT_QUERY_CONCURRENCY;
|
|
241
|
-
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > CONTRACT_EVENT_QUERY_CONCURRENCY) {
|
|
242
|
-
throw new RangeError(`Contract event query concurrency must be between 1 and ${CONTRACT_EVENT_QUERY_CONCURRENCY}.`);
|
|
243
|
-
}
|
|
244
|
-
const ranges = splitContractEventBlockRanges(input.fromBlock, input.toBlock);
|
|
245
|
-
const events = [];
|
|
246
|
-
for (let index2 = 0; index2 < ranges.length; index2 += concurrency) {
|
|
247
|
-
const batch = ranges.slice(index2, index2 + concurrency);
|
|
248
|
-
const batchEvents = await Promise.all(batch.map((range) => input.readRange(range)));
|
|
249
|
-
for (const items of batchEvents) events.push(...items);
|
|
250
|
-
}
|
|
251
|
-
return events;
|
|
71
|
+
};
|
|
72
|
+
}, [config, readOnly, mediaUploader, account.address, account.chainId, account.isConnected]);
|
|
252
73
|
}
|
|
253
74
|
var forbiddenName = /^(?:execute(?:Call|Batch)?|multicall|delegatecall|approve|increaseAllowance|decreaseAllowance|setApprovalForAll|transferOwnership|acceptOwnership|upgradeTo.*|setConfig|setSwapPath|setSplit)$/i;
|
|
254
|
-
var forbiddenSignatures = ["executeCall(address,uint256,bytes)", "approve(address,uint256)", "setApprovalForAll(address,bool)", "transferOwnership(address)", "upgradeTo(address)", "upgradeToAndCall(address,bytes)"];
|
|
75
|
+
var forbiddenSignatures = ["execute(address,uint256,bytes,uint8)", "execute(address,uint256,bytes)", "executeCall(address,uint256,bytes)", "approve(address,uint256)", "setApprovalForAll(address,bool)", "transferOwnership(address)", "upgradeTo(address)", "upgradeToAndCall(address,bytes)"];
|
|
255
76
|
var forbiddenSelectors = new Set(forbiddenSignatures.map(toFunctionSelector));
|
|
256
|
-
var executeSelectors = new Set(["execute(address,uint256,bytes,uint8)", "execute(address,uint256,bytes)"].map(toFunctionSelector));
|
|
257
77
|
var hash = /^0x[0-9a-fA-F]{64}$/;
|
|
258
78
|
var index = (x) => Number.isInteger(x) && x >= 0 && x < 32;
|
|
259
79
|
function requireRule(ok, reason) {
|
|
@@ -280,8 +100,7 @@ function parseResolvedContract(input) {
|
|
|
280
100
|
const seen = /* @__PURE__ */ new Set();
|
|
281
101
|
for (const f of writes) {
|
|
282
102
|
const selector = toFunctionSelector(f);
|
|
283
|
-
|
|
284
|
-
requireRule(!["view", "pure"].includes(f.stateMutability) && (reviewedExecute || !forbiddenName.test(f.name)) && !forbiddenSelectors.has(selector) && (reviewedExecute || !executeSelectors.has(selector) && !f.inputs.some(hasDynamicBytes)), "forbidden-write");
|
|
103
|
+
requireRule(!["view", "pure"].includes(f.stateMutability) && !forbiddenName.test(f.name) && !forbiddenSelectors.has(selector) && !f.inputs.some(hasDynamicBytes), "forbidden-write");
|
|
285
104
|
requireRule(!seen.has(selector), "duplicate-selector");
|
|
286
105
|
seen.add(selector);
|
|
287
106
|
}
|
|
@@ -672,7 +491,7 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
672
491
|
const { address: accountAddress, isConnected } = useAccount();
|
|
673
492
|
const connectedChainId = useChainId();
|
|
674
493
|
const { connect, connectors } = useConnect();
|
|
675
|
-
const { disconnect } = useDisconnect();
|
|
494
|
+
const { disconnect: disconnect2 } = useDisconnect();
|
|
676
495
|
const { switchChainAsync, isPending: isSwitchingChain } = useSwitchChain();
|
|
677
496
|
const effectiveChainId = runtimeOverrides?.chainId ?? hostRuntimeResult?.addresses.chainId ?? connectedChainId ?? manifest.match.bindings[0]?.chainId ?? 56;
|
|
678
497
|
const publicClient = usePublicClient({ chainId: effectiveChainId });
|
|
@@ -761,7 +580,7 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
761
580
|
const connector = connectors[0];
|
|
762
581
|
if (connector) connect({ connector });
|
|
763
582
|
},
|
|
764
|
-
disconnect: () =>
|
|
583
|
+
disconnect: () => disconnect2(),
|
|
765
584
|
switchChain: async () => {
|
|
766
585
|
if (previewWallet) {
|
|
767
586
|
throw new Error(`Switch wallet to ${chainLabelForChain(runtimeContext.chainId)} before continuing.`);
|
|
@@ -773,7 +592,7 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
773
592
|
}
|
|
774
593
|
};
|
|
775
594
|
},
|
|
776
|
-
[accountAddress, connect, connectedChainId, connectors,
|
|
595
|
+
[accountAddress, connect, connectedChainId, connectors, disconnect2, isConnected, isSwitchingChain, nativeBalance, runtimeContext.chainId, runtimeOverrides?.previewWallet, switchChainAsync]
|
|
777
596
|
);
|
|
778
597
|
const assertWalletWriteReady = useCallback(
|
|
779
598
|
(actionLabel) => {
|
|
@@ -890,7 +709,7 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
890
709
|
if (!publicClient || !contractRuntime) throw new Error("resolved-contract/client-unavailable");
|
|
891
710
|
const contract = input.contract;
|
|
892
711
|
const prepared = contractRuntime.snapshot(input);
|
|
893
|
-
|
|
712
|
+
prepared.request = snapshotGenericContractWrite(prepared.request);
|
|
894
713
|
const feeOverrides = await resolveSafeContractWriteFeeOverrides(prepared.request, getGasPrice);
|
|
895
714
|
const checked = await contractRuntime.validate(prepared, true);
|
|
896
715
|
const request = checked.request;
|
|
@@ -914,7 +733,7 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
914
733
|
assertWalletWriteReady(`writing ${input.functionName}`);
|
|
915
734
|
if (!walletClient || !publicClient || !contractRuntime) throw new Error("resolved-contract/client-unavailable");
|
|
916
735
|
const prepared = contractRuntime.snapshot(input);
|
|
917
|
-
|
|
736
|
+
prepared.request = snapshotGenericContractWrite(prepared.request);
|
|
918
737
|
const feeOverrides = await resolveSafeContractWriteFeeOverrides(prepared.request, getGasPrice);
|
|
919
738
|
let checked = await contractRuntime.validate(prepared, true);
|
|
920
739
|
if (prepared.record) {
|
|
@@ -972,13 +791,6 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
972
791
|
},
|
|
973
792
|
[oracleReader, runtimeContext]
|
|
974
793
|
);
|
|
975
|
-
const fsiEndpointsRef = useRef(runtimeContext.manifest.endpoints);
|
|
976
|
-
const readIpfsText = useMemo(() => createIpfsTextReader(), []);
|
|
977
|
-
fsiEndpointsRef.current = runtimeContext.manifest.endpoints;
|
|
978
|
-
const readFsi = useCallback(
|
|
979
|
-
(path, params) => readFsiJson(fsiEndpointsRef.current, path, params),
|
|
980
|
-
[]
|
|
981
|
-
);
|
|
982
794
|
const readNftMetadata = useCallback(
|
|
983
795
|
async (request) => {
|
|
984
796
|
if (request.tokenId < 0n) throw new Error("NFT tokenId must not be negative.");
|
|
@@ -1089,8 +901,25 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
1089
901
|
}
|
|
1090
902
|
}, [assertWalletWriteReady, nftWithdrawalEnvironment, publicClient, refetch, runtimeContext, walletClient]);
|
|
1091
903
|
const componentContext = useMemo(() => structuredClone(runtimeContext), [runtimeContext]);
|
|
904
|
+
const chainRuntime = useFlapWalletRuntime({ connect: wallet.connect, mediaUploader: mediaUploader ?? defaultMediaUploader });
|
|
905
|
+
const forChain = useCallback((chainId) => createFlapChainSdk({
|
|
906
|
+
...chainRuntime,
|
|
907
|
+
// Reuse the Vault's strict target and resolver policies for scoped access too.
|
|
908
|
+
simulateContract: async (_chainId, request) => {
|
|
909
|
+
if (_chainId !== runtimeContext.chainId) throw new Error("Vault writes require the bound network.");
|
|
910
|
+
return (await simulateContract(request)).result;
|
|
911
|
+
},
|
|
912
|
+
writeContract: async (_chainId, request) => {
|
|
913
|
+
if (_chainId !== runtimeContext.chainId) throw new Error("Vault writes require the bound network.");
|
|
914
|
+
return writeContract(request);
|
|
915
|
+
},
|
|
916
|
+
sendTransaction: async () => {
|
|
917
|
+
throw new Error("Raw transactions require a reviewed standalone App.");
|
|
918
|
+
}
|
|
919
|
+
}, { chainId, manifest, writableChains: [runtimeContext.chainId], i18n: i18nApi, notify }), [chainRuntime, manifest, runtimeContext.chainId, i18nApi, notify, simulateContract, writeContract]);
|
|
1092
920
|
const sdk = useMemo(
|
|
1093
921
|
() => ({
|
|
922
|
+
forChain,
|
|
1094
923
|
context: componentContext,
|
|
1095
924
|
i18n: i18nApi,
|
|
1096
925
|
notify,
|
|
@@ -1105,8 +934,6 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
1105
934
|
waitForTx,
|
|
1106
935
|
withdrawNftAccount: withdrawNftAccount2,
|
|
1107
936
|
readOracle,
|
|
1108
|
-
readFsi,
|
|
1109
|
-
readIpfsText,
|
|
1110
937
|
readNftMetadata,
|
|
1111
938
|
uploadImage,
|
|
1112
939
|
uploadText,
|
|
@@ -1114,7 +941,7 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
1114
941
|
refetchNonce: version,
|
|
1115
942
|
openExplorerTx
|
|
1116
943
|
}),
|
|
1117
|
-
[getBlockNumber, getContractEvents, getGasPrice, i18nApi, notify, openExplorerTx, resolveContract, readContract, readNftMetadata, readOracle,
|
|
944
|
+
[forChain, getBlockNumber, getContractEvents, getGasPrice, i18nApi, notify, openExplorerTx, resolveContract, readContract, readNftMetadata, readOracle, refetch, componentContext, simulateContract, uploadImage, uploadText, version, waitForTx, wallet, withdrawNftAccount2, writeContract]
|
|
1118
945
|
);
|
|
1119
946
|
return /* @__PURE__ */ jsxs(RuntimeContext.Provider, { value: sdk, children: [
|
|
1120
947
|
children,
|
|
@@ -1129,6 +956,6 @@ function VaultRuntimeProvider({ children, manifest, i18n, runtimeContext: runtim
|
|
|
1129
956
|
] });
|
|
1130
957
|
}
|
|
1131
958
|
|
|
1132
|
-
export { VaultRuntimeProvider };
|
|
1133
|
-
//# sourceMappingURL=chunk-
|
|
1134
|
-
//# sourceMappingURL=chunk-
|
|
959
|
+
export { VaultRuntimeProvider, useFlapWalletRuntime };
|
|
960
|
+
//# sourceMappingURL=chunk-44P2NRRZ.js.map
|
|
961
|
+
//# sourceMappingURL=chunk-44P2NRRZ.js.map
|