boing-sdk 0.3.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/CHANGELOG.md +26 -0
- package/README.md +191 -0
- package/dist/accessList.d.ts +22 -0
- package/dist/accessList.d.ts.map +1 -0
- package/dist/accessList.js +45 -0
- package/dist/bincode.d.ts +92 -0
- package/dist/bincode.d.ts.map +1 -0
- package/dist/bincode.js +154 -0
- package/dist/callAbi.d.ts +119 -0
- package/dist/callAbi.d.ts.map +1 -0
- package/dist/callAbi.js +156 -0
- package/dist/calldata.d.ts +35 -0
- package/dist/calldata.d.ts.map +1 -0
- package/dist/calldata.js +93 -0
- package/dist/canonicalDeployArtifacts.d.ts +154 -0
- package/dist/canonicalDeployArtifacts.d.ts.map +1 -0
- package/dist/canonicalDeployArtifacts.js +271 -0
- package/dist/canonicalTestnet.d.ts +15 -0
- package/dist/canonicalTestnet.d.ts.map +1 -0
- package/dist/canonicalTestnet.js +15 -0
- package/dist/canonicalTestnetDex.d.ts +17 -0
- package/dist/canonicalTestnetDex.d.ts.map +1 -0
- package/dist/canonicalTestnetDex.js +17 -0
- package/dist/chainIds.d.ts +18 -0
- package/dist/chainIds.d.ts.map +1 -0
- package/dist/chainIds.js +56 -0
- package/dist/client.d.ts +223 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +659 -0
- package/dist/connectionMonitor.d.ts +47 -0
- package/dist/connectionMonitor.d.ts.map +1 -0
- package/dist/connectionMonitor.js +93 -0
- package/dist/create2.d.ts +94 -0
- package/dist/create2.d.ts.map +1 -0
- package/dist/create2.js +225 -0
- package/dist/dappDeploy.d.ts +100 -0
- package/dist/dappDeploy.d.ts.map +1 -0
- package/dist/dappDeploy.js +140 -0
- package/dist/dappUiHelpers.d.ts +28 -0
- package/dist/dappUiHelpers.d.ts.map +1 -0
- package/dist/dappUiHelpers.js +69 -0
- package/dist/defaultReferenceFungibleSecuredRuntimeBytecodeHex.d.ts +6 -0
- package/dist/defaultReferenceFungibleSecuredRuntimeBytecodeHex.d.ts.map +1 -0
- package/dist/defaultReferenceFungibleSecuredRuntimeBytecodeHex.js +5 -0
- package/dist/defaultReferenceFungibleSecuredTemplateBytecodeHex.d.ts +6 -0
- package/dist/defaultReferenceFungibleSecuredTemplateBytecodeHex.d.ts.map +1 -0
- package/dist/defaultReferenceFungibleSecuredTemplateBytecodeHex.js +5 -0
- package/dist/defaultReferenceFungibleTemplateBytecodeHex.d.ts +6 -0
- package/dist/defaultReferenceFungibleTemplateBytecodeHex.d.ts.map +1 -0
- package/dist/defaultReferenceFungibleTemplateBytecodeHex.js +5 -0
- package/dist/defaultReferenceNftCollectionTemplateBytecodeHex.d.ts +7 -0
- package/dist/defaultReferenceNftCollectionTemplateBytecodeHex.d.ts.map +1 -0
- package/dist/defaultReferenceNftCollectionTemplateBytecodeHex.js +6 -0
- package/dist/dexIntegration.d.ts +61 -0
- package/dist/dexIntegration.d.ts.map +1 -0
- package/dist/dexIntegration.js +193 -0
- package/dist/erc721Logs.d.ts +21 -0
- package/dist/erc721Logs.d.ts.map +1 -0
- package/dist/erc721Logs.js +69 -0
- package/dist/errors.d.ts +60 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +153 -0
- package/dist/hex.d.ts +27 -0
- package/dist/hex.d.ts.map +1 -0
- package/dist/hex.js +82 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/indexerBatch.d.ts +111 -0
- package/dist/indexerBatch.d.ts.map +1 -0
- package/dist/indexerBatch.js +253 -0
- package/dist/indexerGaps.d.ts +50 -0
- package/dist/indexerGaps.d.ts.map +1 -0
- package/dist/indexerGaps.js +117 -0
- package/dist/indexerSync.d.ts +61 -0
- package/dist/indexerSync.d.ts.map +1 -0
- package/dist/indexerSync.js +100 -0
- package/dist/nativeAmm.d.ts +64 -0
- package/dist/nativeAmm.d.ts.map +1 -0
- package/dist/nativeAmm.js +174 -0
- package/dist/nativeAmmLogs.d.ts +48 -0
- package/dist/nativeAmmLogs.d.ts.map +1 -0
- package/dist/nativeAmmLogs.js +114 -0
- package/dist/nativeAmmLpVault.d.ts +94 -0
- package/dist/nativeAmmLpVault.d.ts.map +1 -0
- package/dist/nativeAmmLpVault.js +205 -0
- package/dist/nativeAmmPool.d.ts +124 -0
- package/dist/nativeAmmPool.d.ts.map +1 -0
- package/dist/nativeAmmPool.js +245 -0
- package/dist/nativeContractSubmit.d.ts +26 -0
- package/dist/nativeContractSubmit.d.ts.map +1 -0
- package/dist/nativeContractSubmit.js +23 -0
- package/dist/nativeDexDirectory.d.ts +83 -0
- package/dist/nativeDexDirectory.d.ts.map +1 -0
- package/dist/nativeDexDirectory.js +147 -0
- package/dist/nativeDexDirectoryApi.d.ts +121 -0
- package/dist/nativeDexDirectoryApi.d.ts.map +1 -0
- package/dist/nativeDexDirectoryApi.js +408 -0
- package/dist/nativeDexFactory.d.ts +25 -0
- package/dist/nativeDexFactory.d.ts.map +1 -0
- package/dist/nativeDexFactory.js +72 -0
- package/dist/nativeDexFactoryLogs.d.ts +19 -0
- package/dist/nativeDexFactoryLogs.d.ts.map +1 -0
- package/dist/nativeDexFactoryLogs.js +61 -0
- package/dist/nativeDexFactoryPool.d.ts +61 -0
- package/dist/nativeDexFactoryPool.d.ts.map +1 -0
- package/dist/nativeDexFactoryPool.js +120 -0
- package/dist/nativeDexIndexerStats.d.ts +96 -0
- package/dist/nativeDexIndexerStats.d.ts.map +1 -0
- package/dist/nativeDexIndexerStats.js +448 -0
- package/dist/nativeDexLedgerRouter.d.ts +67 -0
- package/dist/nativeDexLedgerRouter.d.ts.map +1 -0
- package/dist/nativeDexLedgerRouter.js +108 -0
- package/dist/nativeDexLpPositions.d.ts +39 -0
- package/dist/nativeDexLpPositions.d.ts.map +1 -0
- package/dist/nativeDexLpPositions.js +69 -0
- package/dist/nativeDexNftIndexer.d.ts +26 -0
- package/dist/nativeDexNftIndexer.d.ts.map +1 -0
- package/dist/nativeDexNftIndexer.js +50 -0
- package/dist/nativeDexPoolHistory.d.ts +40 -0
- package/dist/nativeDexPoolHistory.d.ts.map +1 -0
- package/dist/nativeDexPoolHistory.js +110 -0
- package/dist/nativeDexReceiptArchive.d.ts +25 -0
- package/dist/nativeDexReceiptArchive.d.ts.map +1 -0
- package/dist/nativeDexReceiptArchive.js +47 -0
- package/dist/nativeDexRouting.d.ts +160 -0
- package/dist/nativeDexRouting.d.ts.map +1 -0
- package/dist/nativeDexRouting.js +345 -0
- package/dist/nativeDexSeamless.d.ts +86 -0
- package/dist/nativeDexSeamless.d.ts.map +1 -0
- package/dist/nativeDexSeamless.js +131 -0
- package/dist/nativeDexSwap2Router.d.ts +45 -0
- package/dist/nativeDexSwap2Router.d.ts.map +1 -0
- package/dist/nativeDexSwap2Router.js +276 -0
- package/dist/nativeLpShareToken.d.ts +54 -0
- package/dist/nativeLpShareToken.d.ts.map +1 -0
- package/dist/nativeLpShareToken.js +135 -0
- package/dist/nativeTokenSecurity.d.ts +59 -0
- package/dist/nativeTokenSecurity.d.ts.map +1 -0
- package/dist/nativeTokenSecurity.js +59 -0
- package/dist/networkProfile.d.ts +8 -0
- package/dist/networkProfile.d.ts.map +1 -0
- package/dist/networkProfile.js +29 -0
- package/dist/newHeadsWs.d.ts +43 -0
- package/dist/newHeadsWs.d.ts.map +1 -0
- package/dist/newHeadsWs.js +139 -0
- package/dist/preflightGate.d.ts +16 -0
- package/dist/preflightGate.d.ts.map +1 -0
- package/dist/preflightGate.js +29 -0
- package/dist/receiptLogs.d.ts +29 -0
- package/dist/receiptLogs.d.ts.map +1 -0
- package/dist/receiptLogs.js +66 -0
- package/dist/referenceFungibleSecuredDeployBytecode.d.ts +54 -0
- package/dist/referenceFungibleSecuredDeployBytecode.d.ts.map +1 -0
- package/dist/referenceFungibleSecuredDeployBytecode.js +274 -0
- package/dist/referenceNft.d.ts +14 -0
- package/dist/referenceNft.d.ts.map +1 -0
- package/dist/referenceNft.js +34 -0
- package/dist/referenceToken.d.ts +14 -0
- package/dist/referenceToken.d.ts.map +1 -0
- package/dist/referenceToken.js +29 -0
- package/dist/retryAfter.d.ts +6 -0
- package/dist/retryAfter.d.ts.map +1 -0
- package/dist/retryAfter.js +24 -0
- package/dist/rpcCapabilities.d.ts +43 -0
- package/dist/rpcCapabilities.d.ts.map +1 -0
- package/dist/rpcCapabilities.js +159 -0
- package/dist/rpcDoctor.d.ts +27 -0
- package/dist/rpcDoctor.d.ts.map +1 -0
- package/dist/rpcDoctor.js +66 -0
- package/dist/rpcSurfaceUi.d.ts +32 -0
- package/dist/rpcSurfaceUi.d.ts.map +1 -0
- package/dist/rpcSurfaceUi.js +49 -0
- package/dist/submitFlow.d.ts +70 -0
- package/dist/submitFlow.d.ts.map +1 -0
- package/dist/submitFlow.js +121 -0
- package/dist/transactionBuilder.d.ts +55 -0
- package/dist/transactionBuilder.d.ts.map +1 -0
- package/dist/transactionBuilder.js +100 -0
- package/dist/types.d.ts +436 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +4 -0
- package/dist/walletProvider.d.ts +46 -0
- package/dist/walletProvider.d.ts.map +1 -0
- package/dist/walletProvider.js +126 -0
- package/package.json +44 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP JSON for the Cloudflare Worker `workers/native-dex-indexer` D1 directory
|
|
3
|
+
* (`GET /v1/directory/meta`, `GET /v1/directory/pools`). Not Boing JSON-RPC.
|
|
4
|
+
*/
|
|
5
|
+
import { validateHex32 } from './hex.js';
|
|
6
|
+
/** `api` field value on successful directory responses. */
|
|
7
|
+
export const NATIVE_DEX_DIRECTORY_API_ID = 'boing-native-dex-directory/v1';
|
|
8
|
+
/** Bumped when D1 schema or meta semantics change in a breaking way for clients. */
|
|
9
|
+
export const NATIVE_DEX_DIRECTORY_SCHEMA_VERSION = 2;
|
|
10
|
+
export class NativeDexDirectoryHttpError extends Error {
|
|
11
|
+
constructor(message, status, url, bodySnippet) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.url = url;
|
|
15
|
+
this.bodySnippet = bodySnippet;
|
|
16
|
+
this.name = 'NativeDexDirectoryHttpError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Trim and strip a trailing slash (no path segment — base is worker origin). */
|
|
20
|
+
export function normalizeNativeDexDirectoryWorkerBaseUrl(raw) {
|
|
21
|
+
return String(raw || '')
|
|
22
|
+
.trim()
|
|
23
|
+
.replace(/\/+$/, '');
|
|
24
|
+
}
|
|
25
|
+
function isPlainObject(v) {
|
|
26
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
27
|
+
}
|
|
28
|
+
function tryParseIndexerPoolRow(o) {
|
|
29
|
+
if (!isPlainObject(o))
|
|
30
|
+
return null;
|
|
31
|
+
try {
|
|
32
|
+
validateHex32(String(o.poolHex));
|
|
33
|
+
validateHex32(String(o.tokenAHex));
|
|
34
|
+
validateHex32(String(o.tokenBHex));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return o;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse `GET /v1/directory/meta` JSON. Returns `null` if shape is invalid.
|
|
43
|
+
*/
|
|
44
|
+
export function parseNativeDexDirectoryMetaResponse(data) {
|
|
45
|
+
if (!isPlainObject(data))
|
|
46
|
+
return null;
|
|
47
|
+
const api = data.api;
|
|
48
|
+
if (api !== NATIVE_DEX_DIRECTORY_API_ID)
|
|
49
|
+
return null;
|
|
50
|
+
const schemaVersion = data.schemaVersion;
|
|
51
|
+
if (schemaVersion != null && (typeof schemaVersion !== 'number' || !Number.isFinite(schemaVersion) || schemaVersion < 1)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const poolCount = data.poolCount;
|
|
55
|
+
if (typeof poolCount !== 'number' || !Number.isFinite(poolCount) || poolCount < 0)
|
|
56
|
+
return null;
|
|
57
|
+
const latestSyncBatch = data.latestSyncBatch;
|
|
58
|
+
if (latestSyncBatch != null && typeof latestSyncBatch !== 'string')
|
|
59
|
+
return null;
|
|
60
|
+
const eventCount = data.eventCount;
|
|
61
|
+
if (eventCount != null && (typeof eventCount !== 'number' || !Number.isFinite(eventCount) || eventCount < 0)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const indexedTipHeightRaw = data.indexedTipHeight;
|
|
65
|
+
if (indexedTipHeightRaw != null) {
|
|
66
|
+
if (typeof indexedTipHeightRaw !== 'number' || !Number.isFinite(indexedTipHeightRaw) || indexedTipHeightRaw < 0) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const indexedTipBlockHashRaw = data.indexedTipBlockHash;
|
|
71
|
+
if (indexedTipBlockHashRaw != null && typeof indexedTipBlockHashRaw !== 'string')
|
|
72
|
+
return null;
|
|
73
|
+
if (typeof indexedTipBlockHashRaw === 'string' &&
|
|
74
|
+
indexedTipBlockHashRaw !== '' &&
|
|
75
|
+
!/^0x[0-9a-f]{64}$/i.test(indexedTipBlockHashRaw)) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const out = {
|
|
79
|
+
api,
|
|
80
|
+
poolCount,
|
|
81
|
+
latestSyncBatch: latestSyncBatch ?? null,
|
|
82
|
+
};
|
|
83
|
+
if (eventCount != null)
|
|
84
|
+
out.eventCount = eventCount;
|
|
85
|
+
if (data.indexedTipHeight !== undefined) {
|
|
86
|
+
out.indexedTipHeight = indexedTipHeightRaw === null || indexedTipHeightRaw === undefined ? null : indexedTipHeightRaw;
|
|
87
|
+
}
|
|
88
|
+
if (indexedTipBlockHashRaw !== undefined) {
|
|
89
|
+
out.indexedTipBlockHash =
|
|
90
|
+
indexedTipBlockHashRaw == null || indexedTipBlockHashRaw === ''
|
|
91
|
+
? null
|
|
92
|
+
: indexedTipBlockHashRaw.toLowerCase();
|
|
93
|
+
}
|
|
94
|
+
const indexedParentBlockHashRaw = data.indexedParentBlockHash;
|
|
95
|
+
if (indexedParentBlockHashRaw != null && typeof indexedParentBlockHashRaw !== 'string')
|
|
96
|
+
return null;
|
|
97
|
+
if (typeof indexedParentBlockHashRaw === 'string' &&
|
|
98
|
+
indexedParentBlockHashRaw !== '' &&
|
|
99
|
+
!/^0x[0-9a-f]{64}$/i.test(indexedParentBlockHashRaw)) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (indexedParentBlockHashRaw !== undefined) {
|
|
103
|
+
out.indexedParentBlockHash =
|
|
104
|
+
indexedParentBlockHashRaw == null || indexedParentBlockHashRaw === ''
|
|
105
|
+
? null
|
|
106
|
+
: indexedParentBlockHashRaw.toLowerCase();
|
|
107
|
+
}
|
|
108
|
+
const nftOwnerRowCount = data.nftOwnerRowCount;
|
|
109
|
+
if (nftOwnerRowCount != null && (typeof nftOwnerRowCount !== 'number' || !Number.isFinite(nftOwnerRowCount) || nftOwnerRowCount < 0)) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (schemaVersion != null)
|
|
113
|
+
out.schemaVersion = schemaVersion;
|
|
114
|
+
if (nftOwnerRowCount != null)
|
|
115
|
+
out.nftOwnerRowCount = nftOwnerRowCount;
|
|
116
|
+
const receiptLogCount = data.receiptLogCount;
|
|
117
|
+
if (receiptLogCount != null && (typeof receiptLogCount !== 'number' || !Number.isFinite(receiptLogCount) || receiptLogCount < 0)) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (receiptLogCount != null)
|
|
121
|
+
out.receiptLogCount = receiptLogCount;
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Parse `GET /v1/directory/pools` JSON. Drops pool objects that fail minimal hex validation.
|
|
126
|
+
*/
|
|
127
|
+
export function parseNativeDexDirectoryPoolsPageResponse(data) {
|
|
128
|
+
if (!isPlainObject(data))
|
|
129
|
+
return null;
|
|
130
|
+
const api = data.api;
|
|
131
|
+
if (api !== NATIVE_DEX_DIRECTORY_API_ID)
|
|
132
|
+
return null;
|
|
133
|
+
const limit = data.limit;
|
|
134
|
+
if (typeof limit !== 'number' || !Number.isFinite(limit) || limit < 1)
|
|
135
|
+
return null;
|
|
136
|
+
const cursor = data.cursor;
|
|
137
|
+
if (cursor != null && typeof cursor !== 'string')
|
|
138
|
+
return null;
|
|
139
|
+
const nextCursor = data.nextCursor;
|
|
140
|
+
if (nextCursor != null && typeof nextCursor !== 'string')
|
|
141
|
+
return null;
|
|
142
|
+
const hasMore = data.hasMore;
|
|
143
|
+
if (typeof hasMore !== 'boolean')
|
|
144
|
+
return null;
|
|
145
|
+
const rawPools = data.pools;
|
|
146
|
+
if (!Array.isArray(rawPools))
|
|
147
|
+
return null;
|
|
148
|
+
const pools = [];
|
|
149
|
+
for (const row of rawPools) {
|
|
150
|
+
const p = tryParseIndexerPoolRow(row);
|
|
151
|
+
if (p)
|
|
152
|
+
pools.push(p);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
api,
|
|
156
|
+
limit,
|
|
157
|
+
cursor: cursor ?? null,
|
|
158
|
+
nextCursor: nextCursor ?? null,
|
|
159
|
+
hasMore,
|
|
160
|
+
pools,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const NATIVE_AMM_LOG2_KINDS = new Set(['swap', 'addLiquidity', 'removeLiquidity']);
|
|
164
|
+
function tryParseMaterializedPoolEvent(o) {
|
|
165
|
+
if (!isPlainObject(o))
|
|
166
|
+
return null;
|
|
167
|
+
const kind = o.kind;
|
|
168
|
+
if (typeof kind !== 'string' || !NATIVE_AMM_LOG2_KINDS.has(kind))
|
|
169
|
+
return null;
|
|
170
|
+
const poolHex = String(o.poolHex || '').trim().toLowerCase();
|
|
171
|
+
if (!/^0x[0-9a-f]{64}$/.test(poolHex))
|
|
172
|
+
return null;
|
|
173
|
+
const blockHeight = o.blockHeight;
|
|
174
|
+
if (typeof blockHeight !== 'number' || !Number.isFinite(blockHeight))
|
|
175
|
+
return null;
|
|
176
|
+
const txId = o.txId;
|
|
177
|
+
if (typeof txId !== 'string' || !txId.trim())
|
|
178
|
+
return null;
|
|
179
|
+
const logIndex = o.logIndex;
|
|
180
|
+
if (typeof logIndex !== 'number' || !Number.isFinite(logIndex))
|
|
181
|
+
return null;
|
|
182
|
+
const callerHex = String(o.callerHex || '').trim().toLowerCase();
|
|
183
|
+
if (!/^0x[0-9a-f]{64}$/.test(callerHex))
|
|
184
|
+
return null;
|
|
185
|
+
const blockHashRaw = o.blockHash;
|
|
186
|
+
let blockHash = null;
|
|
187
|
+
if (blockHashRaw !== undefined && blockHashRaw !== null) {
|
|
188
|
+
if (typeof blockHashRaw !== 'string' || (blockHashRaw !== '' && !/^0x[0-9a-f]{64}$/i.test(blockHashRaw))) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
blockHash = blockHashRaw === '' ? null : blockHashRaw.toLowerCase();
|
|
192
|
+
}
|
|
193
|
+
const payload = o.payload;
|
|
194
|
+
if (!isPlainObject(payload))
|
|
195
|
+
return null;
|
|
196
|
+
const payloadOut = {};
|
|
197
|
+
for (const [k, v] of Object.entries(payload)) {
|
|
198
|
+
if (typeof v !== 'string')
|
|
199
|
+
return null;
|
|
200
|
+
payloadOut[k] = v;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
kind: kind,
|
|
204
|
+
poolHex,
|
|
205
|
+
blockHeight: Math.floor(blockHeight),
|
|
206
|
+
blockHash,
|
|
207
|
+
txId: txId.trim(),
|
|
208
|
+
logIndex: Math.floor(logIndex),
|
|
209
|
+
callerHex,
|
|
210
|
+
payload: payloadOut,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Parse `GET /v1/history/pool/{pool}/events` JSON. Drops malformed event objects.
|
|
215
|
+
*/
|
|
216
|
+
export function parseNativeDexDirectoryPoolEventsPageResponse(data) {
|
|
217
|
+
if (!isPlainObject(data))
|
|
218
|
+
return null;
|
|
219
|
+
const api = data.api;
|
|
220
|
+
if (api !== NATIVE_DEX_DIRECTORY_API_ID)
|
|
221
|
+
return null;
|
|
222
|
+
const poolHex = String(data.poolHex || '').trim().toLowerCase();
|
|
223
|
+
if (!/^0x[0-9a-f]{64}$/.test(poolHex))
|
|
224
|
+
return null;
|
|
225
|
+
const limit = data.limit;
|
|
226
|
+
if (typeof limit !== 'number' || !Number.isFinite(limit) || limit < 1)
|
|
227
|
+
return null;
|
|
228
|
+
const cursor = data.cursor;
|
|
229
|
+
if (cursor != null && typeof cursor !== 'string')
|
|
230
|
+
return null;
|
|
231
|
+
const nextCursor = data.nextCursor;
|
|
232
|
+
if (nextCursor != null && typeof nextCursor !== 'string')
|
|
233
|
+
return null;
|
|
234
|
+
const hasMore = data.hasMore;
|
|
235
|
+
if (typeof hasMore !== 'boolean')
|
|
236
|
+
return null;
|
|
237
|
+
const rawEvents = data.events;
|
|
238
|
+
if (!Array.isArray(rawEvents))
|
|
239
|
+
return null;
|
|
240
|
+
const events = [];
|
|
241
|
+
for (const row of rawEvents) {
|
|
242
|
+
const e = tryParseMaterializedPoolEvent(row);
|
|
243
|
+
if (e)
|
|
244
|
+
events.push(e);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
api,
|
|
248
|
+
poolHex,
|
|
249
|
+
limit,
|
|
250
|
+
cursor: cursor ?? null,
|
|
251
|
+
nextCursor: nextCursor ?? null,
|
|
252
|
+
hasMore,
|
|
253
|
+
events,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Parse `GET /v1/history/user/{caller}/events` JSON. Drops malformed event objects.
|
|
258
|
+
*/
|
|
259
|
+
export function parseNativeDexDirectoryUserEventsPageResponse(data) {
|
|
260
|
+
if (!isPlainObject(data))
|
|
261
|
+
return null;
|
|
262
|
+
const api = data.api;
|
|
263
|
+
if (api !== NATIVE_DEX_DIRECTORY_API_ID)
|
|
264
|
+
return null;
|
|
265
|
+
const callerHex = String(data.callerHex || '').trim().toLowerCase();
|
|
266
|
+
if (!/^0x[0-9a-f]{64}$/.test(callerHex))
|
|
267
|
+
return null;
|
|
268
|
+
const limit = data.limit;
|
|
269
|
+
if (typeof limit !== 'number' || !Number.isFinite(limit) || limit < 1)
|
|
270
|
+
return null;
|
|
271
|
+
const cursor = data.cursor;
|
|
272
|
+
if (cursor != null && typeof cursor !== 'string')
|
|
273
|
+
return null;
|
|
274
|
+
const nextCursor = data.nextCursor;
|
|
275
|
+
if (nextCursor != null && typeof nextCursor !== 'string')
|
|
276
|
+
return null;
|
|
277
|
+
const hasMore = data.hasMore;
|
|
278
|
+
if (typeof hasMore !== 'boolean')
|
|
279
|
+
return null;
|
|
280
|
+
const rawEvents = data.events;
|
|
281
|
+
if (!Array.isArray(rawEvents))
|
|
282
|
+
return null;
|
|
283
|
+
const events = [];
|
|
284
|
+
for (const row of rawEvents) {
|
|
285
|
+
const e = tryParseMaterializedPoolEvent(row);
|
|
286
|
+
if (e)
|
|
287
|
+
events.push(e);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
api,
|
|
291
|
+
callerHex,
|
|
292
|
+
limit,
|
|
293
|
+
cursor: cursor ?? null,
|
|
294
|
+
nextCursor: nextCursor ?? null,
|
|
295
|
+
hasMore,
|
|
296
|
+
events,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
async function readJsonOrThrow(url, res) {
|
|
300
|
+
const text = await res.text();
|
|
301
|
+
let data;
|
|
302
|
+
try {
|
|
303
|
+
data = JSON.parse(text);
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
throw new NativeDexDirectoryHttpError(`Invalid JSON from directory worker`, res.status, url, text.slice(0, 200));
|
|
307
|
+
}
|
|
308
|
+
if (!res.ok) {
|
|
309
|
+
const errMsg = isPlainObject(data) && typeof data.error === 'string' ? data.error : `HTTP ${res.status}`;
|
|
310
|
+
throw new NativeDexDirectoryHttpError(errMsg, res.status, url, text.slice(0, 200));
|
|
311
|
+
}
|
|
312
|
+
return data;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* `GET {baseUrl}/v1/directory/meta`
|
|
316
|
+
*/
|
|
317
|
+
export async function fetchNativeDexDirectoryMeta(baseUrl, init) {
|
|
318
|
+
const root = normalizeNativeDexDirectoryWorkerBaseUrl(baseUrl);
|
|
319
|
+
const url = `${root}/v1/directory/meta`;
|
|
320
|
+
const res = await fetch(url, { ...init, method: 'GET', headers: { Accept: 'application/json', ...init?.headers } });
|
|
321
|
+
const data = await readJsonOrThrow(url, res);
|
|
322
|
+
const parsed = parseNativeDexDirectoryMetaResponse(data);
|
|
323
|
+
if (!parsed) {
|
|
324
|
+
throw new NativeDexDirectoryHttpError('Unexpected /v1/directory/meta JSON shape', res.status, url);
|
|
325
|
+
}
|
|
326
|
+
return parsed;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* `GET {baseUrl}/v1/directory/pools?limit=&cursor=`
|
|
330
|
+
*/
|
|
331
|
+
export async function fetchNativeDexDirectoryPoolsPage(baseUrl, query = {}, init) {
|
|
332
|
+
const root = normalizeNativeDexDirectoryWorkerBaseUrl(baseUrl);
|
|
333
|
+
const u = new URL(`${root}/v1/directory/pools`);
|
|
334
|
+
if (query.limit != null)
|
|
335
|
+
u.searchParams.set('limit', String(query.limit));
|
|
336
|
+
if (query.cursor != null && query.cursor !== '')
|
|
337
|
+
u.searchParams.set('cursor', query.cursor);
|
|
338
|
+
const url = u.toString();
|
|
339
|
+
const res = await fetch(url, { ...init, method: 'GET', headers: { Accept: 'application/json', ...init?.headers } });
|
|
340
|
+
const data = await readJsonOrThrow(url, res);
|
|
341
|
+
const parsed = parseNativeDexDirectoryPoolsPageResponse(data);
|
|
342
|
+
if (!parsed) {
|
|
343
|
+
throw new NativeDexDirectoryHttpError('Unexpected /v1/directory/pools JSON shape', res.status, url);
|
|
344
|
+
}
|
|
345
|
+
return parsed;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* `GET {baseUrl}/v1/history/pool/{poolHex}/events?limit=&cursor=`
|
|
349
|
+
*/
|
|
350
|
+
export async function fetchNativeDexDirectoryPoolEventsPage(baseUrl, poolHex32, query = {}, init) {
|
|
351
|
+
const root = normalizeNativeDexDirectoryWorkerBaseUrl(baseUrl);
|
|
352
|
+
const pool = validateHex32(String(poolHex32).trim()).toLowerCase();
|
|
353
|
+
const u = new URL(`${root}/v1/history/pool/${pool}/events`);
|
|
354
|
+
if (query.limit != null)
|
|
355
|
+
u.searchParams.set('limit', String(query.limit));
|
|
356
|
+
if (query.cursor != null && query.cursor !== '')
|
|
357
|
+
u.searchParams.set('cursor', query.cursor);
|
|
358
|
+
const url = u.toString();
|
|
359
|
+
const res = await fetch(url, { ...init, method: 'GET', headers: { Accept: 'application/json', ...init?.headers } });
|
|
360
|
+
const data = await readJsonOrThrow(url, res);
|
|
361
|
+
const parsed = parseNativeDexDirectoryPoolEventsPageResponse(data);
|
|
362
|
+
if (!parsed) {
|
|
363
|
+
throw new NativeDexDirectoryHttpError('Unexpected pool events JSON shape', res.status, url);
|
|
364
|
+
}
|
|
365
|
+
return parsed;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* `GET {baseUrl}/v1/history/user/{callerHex}/events?limit=&cursor=`
|
|
369
|
+
*/
|
|
370
|
+
export async function fetchNativeDexDirectoryUserEventsPage(baseUrl, callerHex32, query = {}, init) {
|
|
371
|
+
const root = normalizeNativeDexDirectoryWorkerBaseUrl(baseUrl);
|
|
372
|
+
const caller = validateHex32(String(callerHex32).trim()).toLowerCase();
|
|
373
|
+
const u = new URL(`${root}/v1/history/user/${caller}/events`);
|
|
374
|
+
if (query.limit != null)
|
|
375
|
+
u.searchParams.set('limit', String(query.limit));
|
|
376
|
+
if (query.cursor != null && query.cursor !== '')
|
|
377
|
+
u.searchParams.set('cursor', query.cursor);
|
|
378
|
+
const url = u.toString();
|
|
379
|
+
const res = await fetch(url, { ...init, method: 'GET', headers: { Accept: 'application/json', ...init?.headers } });
|
|
380
|
+
const data = await readJsonOrThrow(url, res);
|
|
381
|
+
const parsed = parseNativeDexDirectoryUserEventsPageResponse(data);
|
|
382
|
+
if (!parsed) {
|
|
383
|
+
throw new NativeDexDirectoryHttpError('Unexpected user pool events JSON shape', res.status, url);
|
|
384
|
+
}
|
|
385
|
+
return parsed;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Walk cursor pages until `hasMore` is false or limits hit.
|
|
389
|
+
*/
|
|
390
|
+
export async function collectAllNativeDexDirectoryPools(baseUrl, opts = {}) {
|
|
391
|
+
const pageLimit = Math.min(100, Math.max(1, opts.pageLimit ?? 100));
|
|
392
|
+
const maxPools = opts.maxPools ?? Number.POSITIVE_INFINITY;
|
|
393
|
+
const maxPages = opts.maxPages ?? 10000;
|
|
394
|
+
const out = [];
|
|
395
|
+
let cursor;
|
|
396
|
+
for (let page = 0; page < maxPages; page++) {
|
|
397
|
+
const pageRes = await fetchNativeDexDirectoryPoolsPage(baseUrl, { limit: pageLimit, cursor: cursor ?? null }, opts.init);
|
|
398
|
+
for (const p of pageRes.pools) {
|
|
399
|
+
out.push(p);
|
|
400
|
+
if (out.length >= maxPools)
|
|
401
|
+
return out.slice(0, maxPools);
|
|
402
|
+
}
|
|
403
|
+
if (!pageRes.hasMore || pageRes.nextCursor == null || pageRes.nextCursor === '')
|
|
404
|
+
break;
|
|
405
|
+
cursor = pageRes.nextCursor;
|
|
406
|
+
}
|
|
407
|
+
return out;
|
|
408
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native DEX **pair directory** calldata (Boing VM). Matches `boing_execution::native_dex_factory`.
|
|
3
|
+
* See `docs/NATIVE-DEX-FACTORY.md`.
|
|
4
|
+
*/
|
|
5
|
+
/** `register_pair(token_a, token_b, pool)` — **128** bytes. */
|
|
6
|
+
export declare const SELECTOR_NATIVE_DEX_REGISTER_PAIR = 208;
|
|
7
|
+
/** `pairs_count` — **32** bytes; return data is one word (count in low **8** bytes). */
|
|
8
|
+
export declare const SELECTOR_NATIVE_DEX_PAIRS_COUNT = 209;
|
|
9
|
+
/** `get_pair_at(index)` — **64** bytes; return data is **96** bytes (three account words). */
|
|
10
|
+
export declare const SELECTOR_NATIVE_DEX_GET_PAIR_AT = 210;
|
|
11
|
+
/** Max pairs the on-chain directory stores (`NATIVE_DEX_FACTORY_MAX_PAIRS`). */
|
|
12
|
+
export declare const NATIVE_DEX_FACTORY_MAX_PAIRS = 4096;
|
|
13
|
+
/** `Log3` topic0 hex after `register_pair` (matches Rust `NATIVE_DEX_FACTORY_TOPIC_REGISTER`). */
|
|
14
|
+
export declare const NATIVE_DEX_FACTORY_TOPIC_REGISTER_HEX: string;
|
|
15
|
+
/** CREATE2 salt v1 (hex `0x` + 64 hex chars). */
|
|
16
|
+
export declare const NATIVE_DEX_FACTORY_CREATE2_SALT_V1_HEX: string;
|
|
17
|
+
/** Build `register_pair` calldata bytes. */
|
|
18
|
+
export declare function encodeNativeDexRegisterPairCalldata(tokenAHex32: string, tokenBHex32: string, poolHex32: string): Uint8Array;
|
|
19
|
+
/** `0x`-prefixed hex calldata for RPC / Express. */
|
|
20
|
+
export declare function encodeNativeDexRegisterPairCalldataHex(tokenAHex32: string, tokenBHex32: string, poolHex32: string): string;
|
|
21
|
+
export declare function encodeNativeDexPairsCountCalldata(): Uint8Array;
|
|
22
|
+
export declare function encodeNativeDexPairsCountCalldataHex(): string;
|
|
23
|
+
export declare function encodeNativeDexGetPairAtCalldata(index: number): Uint8Array;
|
|
24
|
+
export declare function encodeNativeDexGetPairAtCalldataHex(index: number): string;
|
|
25
|
+
//# sourceMappingURL=nativeDexFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeDexFactory.d.ts","sourceRoot":"","sources":["../src/nativeDexFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,+DAA+D;AAC/D,eAAO,MAAM,iCAAiC,MAAO,CAAC;AACtD,wFAAwF;AACxF,eAAO,MAAM,+BAA+B,MAAO,CAAC;AACpD,8FAA8F;AAC9F,eAAO,MAAM,+BAA+B,MAAO,CAAC;AAEpD,gFAAgF;AAChF,eAAO,MAAM,4BAA4B,OAAO,CAAC;AAEjD,kGAAkG;AAClG,eAAO,MAAM,qCAAqC,QAI9C,CAAC;AAEL,iDAAiD;AACjD,eAAO,MAAM,sCAAsC,QAK/C,CAAC;AA4BL,4CAA4C;AAC5C,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,UAAU,CAKZ;AAED,oDAAoD;AACpD,wBAAgB,sCAAsC,CACpD,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,MAAM,CAER;AAED,wBAAgB,iCAAiC,IAAI,UAAU,CAE9D;AAED,wBAAgB,oCAAoC,IAAI,MAAM,CAE7D;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAE1E;AAED,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native DEX **pair directory** calldata (Boing VM). Matches `boing_execution::native_dex_factory`.
|
|
3
|
+
* See `docs/NATIVE-DEX-FACTORY.md`.
|
|
4
|
+
*/
|
|
5
|
+
import { bytesToHex, hexToBytes, validateHex32 } from './hex.js';
|
|
6
|
+
/** `register_pair(token_a, token_b, pool)` — **128** bytes. */
|
|
7
|
+
export const SELECTOR_NATIVE_DEX_REGISTER_PAIR = 0xd0;
|
|
8
|
+
/** `pairs_count` — **32** bytes; return data is one word (count in low **8** bytes). */
|
|
9
|
+
export const SELECTOR_NATIVE_DEX_PAIRS_COUNT = 0xd1;
|
|
10
|
+
/** `get_pair_at(index)` — **64** bytes; return data is **96** bytes (three account words). */
|
|
11
|
+
export const SELECTOR_NATIVE_DEX_GET_PAIR_AT = 0xd2;
|
|
12
|
+
/** Max pairs the on-chain directory stores (`NATIVE_DEX_FACTORY_MAX_PAIRS`). */
|
|
13
|
+
export const NATIVE_DEX_FACTORY_MAX_PAIRS = 4096;
|
|
14
|
+
/** `Log3` topic0 hex after `register_pair` (matches Rust `NATIVE_DEX_FACTORY_TOPIC_REGISTER`). */
|
|
15
|
+
export const NATIVE_DEX_FACTORY_TOPIC_REGISTER_HEX = (() => {
|
|
16
|
+
const u8 = new Uint8Array(32);
|
|
17
|
+
u8.set(new TextEncoder().encode('BOING_NATIVE_DEX_FACTORY_REG1'));
|
|
18
|
+
return bytesToHex(u8);
|
|
19
|
+
})();
|
|
20
|
+
/** CREATE2 salt v1 (hex `0x` + 64 hex chars). */
|
|
21
|
+
export const NATIVE_DEX_FACTORY_CREATE2_SALT_V1_HEX = (() => {
|
|
22
|
+
const u8 = new Uint8Array(32);
|
|
23
|
+
const s = new TextEncoder().encode('BOING_NATIVEDEX_FACTORY_V1');
|
|
24
|
+
u8.set(s);
|
|
25
|
+
return bytesToHex(u8);
|
|
26
|
+
})();
|
|
27
|
+
function selectorWord(selector) {
|
|
28
|
+
const w = new Uint8Array(32);
|
|
29
|
+
w[31] = selector & 0xff;
|
|
30
|
+
return w;
|
|
31
|
+
}
|
|
32
|
+
function u64Word(n) {
|
|
33
|
+
if (!Number.isInteger(n) || n < 0 || n > Number.MAX_SAFE_INTEGER) {
|
|
34
|
+
throw new RangeError('index must be a non-negative safe integer');
|
|
35
|
+
}
|
|
36
|
+
const w = new Uint8Array(32);
|
|
37
|
+
new DataView(w.buffer).setBigUint64(24, BigInt(n), false);
|
|
38
|
+
return w;
|
|
39
|
+
}
|
|
40
|
+
function concatWords(parts) {
|
|
41
|
+
const n = parts.reduce((a, p) => a + p.length, 0);
|
|
42
|
+
const out = new Uint8Array(n);
|
|
43
|
+
let o = 0;
|
|
44
|
+
for (const p of parts) {
|
|
45
|
+
out.set(p, o);
|
|
46
|
+
o += p.length;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** Build `register_pair` calldata bytes. */
|
|
51
|
+
export function encodeNativeDexRegisterPairCalldata(tokenAHex32, tokenBHex32, poolHex32) {
|
|
52
|
+
const a = hexToBytes(validateHex32(tokenAHex32));
|
|
53
|
+
const b = hexToBytes(validateHex32(tokenBHex32));
|
|
54
|
+
const p = hexToBytes(validateHex32(poolHex32));
|
|
55
|
+
return concatWords([selectorWord(SELECTOR_NATIVE_DEX_REGISTER_PAIR), a, b, p]);
|
|
56
|
+
}
|
|
57
|
+
/** `0x`-prefixed hex calldata for RPC / Express. */
|
|
58
|
+
export function encodeNativeDexRegisterPairCalldataHex(tokenAHex32, tokenBHex32, poolHex32) {
|
|
59
|
+
return bytesToHex(encodeNativeDexRegisterPairCalldata(tokenAHex32, tokenBHex32, poolHex32));
|
|
60
|
+
}
|
|
61
|
+
export function encodeNativeDexPairsCountCalldata() {
|
|
62
|
+
return selectorWord(SELECTOR_NATIVE_DEX_PAIRS_COUNT);
|
|
63
|
+
}
|
|
64
|
+
export function encodeNativeDexPairsCountCalldataHex() {
|
|
65
|
+
return bytesToHex(encodeNativeDexPairsCountCalldata());
|
|
66
|
+
}
|
|
67
|
+
export function encodeNativeDexGetPairAtCalldata(index) {
|
|
68
|
+
return concatWords([selectorWord(SELECTOR_NATIVE_DEX_GET_PAIR_AT), u64Word(index)]);
|
|
69
|
+
}
|
|
70
|
+
export function encodeNativeDexGetPairAtCalldataHex(index) {
|
|
71
|
+
return bytesToHex(encodeNativeDexGetPairAtCalldata(index));
|
|
72
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse pair-directory **`Log3`** after `register_pair` (`topic0` + token_a + token_b, **data** = pool).
|
|
3
|
+
* Matches `native_dex_factory::NATIVE_DEX_FACTORY_TOPIC_REGISTER`.
|
|
4
|
+
*/
|
|
5
|
+
import type { ExecutionLog, ExecutionReceipt, RpcLogEntry } from './types.js';
|
|
6
|
+
export type NativeDexFactoryRegisterEvent = {
|
|
7
|
+
tokenAHex: string;
|
|
8
|
+
tokenBHex: string;
|
|
9
|
+
poolHex: string;
|
|
10
|
+
};
|
|
11
|
+
export type NativeDexFactoryRegisterRpcParsed = NativeDexFactoryRegisterEvent & Pick<RpcLogEntry, 'block_height' | 'tx_index' | 'tx_id' | 'log_index' | 'address'>;
|
|
12
|
+
/** True if normalized `topic0` is the factory register topic. */
|
|
13
|
+
export declare function isNativeDexFactoryRegisterTopic0(topic: string): boolean;
|
|
14
|
+
/** `Log3` with known topic0; **data** must be exactly **32** bytes (pool id). */
|
|
15
|
+
export declare function isNativeDexFactoryRegisterLog3Shape(log: Pick<ExecutionLog, 'topics'>): boolean;
|
|
16
|
+
export declare function tryParseNativeDexFactoryRegisterLog3(log: Pick<ExecutionLog, 'topics' | 'data'>): NativeDexFactoryRegisterEvent | null;
|
|
17
|
+
export declare function tryParseNativeDexFactoryRegisterRpcLogEntry(log: RpcLogEntry): NativeDexFactoryRegisterRpcParsed | null;
|
|
18
|
+
export declare function collectNativeDexFactoryRegisterLogsFromReceipt(receipt: ExecutionReceipt): NativeDexFactoryRegisterEvent[];
|
|
19
|
+
//# sourceMappingURL=nativeDexFactoryLogs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeDexFactoryLogs.d.ts","sourceRoot":"","sources":["../src/nativeDexFactoryLogs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9E,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG,6BAA6B,GAC3E,IAAI,CAAC,WAAW,EAAE,cAAc,GAAG,UAAU,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAC,CAAC;AAErF,iEAAiE;AACjE,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAMvE;AAED,iFAAiF;AACjF,wBAAgB,mCAAmC,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,OAAO,CAG9F;AAED,wBAAgB,oCAAoC,CAClD,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,MAAM,CAAC,GACzC,6BAA6B,GAAG,IAAI,CAYtC;AAED,wBAAgB,2CAA2C,CACzD,GAAG,EAAE,WAAW,GACf,iCAAiC,GAAG,IAAI,CAW1C;AAED,wBAAgB,8CAA8C,CAAC,OAAO,EAAE,gBAAgB,GAAG,6BAA6B,EAAE,CAOzH"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse pair-directory **`Log3`** after `register_pair` (`topic0` + token_a + token_b, **data** = pool).
|
|
3
|
+
* Matches `native_dex_factory::NATIVE_DEX_FACTORY_TOPIC_REGISTER`.
|
|
4
|
+
*/
|
|
5
|
+
import { NATIVE_DEX_FACTORY_TOPIC_REGISTER_HEX } from './nativeDexFactory.js';
|
|
6
|
+
import { iterReceiptLogs, normalizeTopicWord } from './receiptLogs.js';
|
|
7
|
+
import { validateHex32 } from './hex.js';
|
|
8
|
+
const T0_REG = normalizeTopicWord(NATIVE_DEX_FACTORY_TOPIC_REGISTER_HEX);
|
|
9
|
+
/** True if normalized `topic0` is the factory register topic. */
|
|
10
|
+
export function isNativeDexFactoryRegisterTopic0(topic) {
|
|
11
|
+
try {
|
|
12
|
+
return normalizeTopicWord(topic) === T0_REG;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** `Log3` with known topic0; **data** must be exactly **32** bytes (pool id). */
|
|
19
|
+
export function isNativeDexFactoryRegisterLog3Shape(log) {
|
|
20
|
+
if (log.topics.length !== 3)
|
|
21
|
+
return false;
|
|
22
|
+
return isNativeDexFactoryRegisterTopic0(log.topics[0]);
|
|
23
|
+
}
|
|
24
|
+
export function tryParseNativeDexFactoryRegisterLog3(log) {
|
|
25
|
+
try {
|
|
26
|
+
if (!isNativeDexFactoryRegisterLog3Shape(log))
|
|
27
|
+
return null;
|
|
28
|
+
const raw = log.data.trim().replace(/^0x/i, '');
|
|
29
|
+
if (raw.length < 64)
|
|
30
|
+
return null;
|
|
31
|
+
const poolHex = validateHex32(`0x${raw.slice(0, 64)}`);
|
|
32
|
+
const tokenAHex = validateHex32(log.topics[1]);
|
|
33
|
+
const tokenBHex = validateHex32(log.topics[2]);
|
|
34
|
+
return { tokenAHex, tokenBHex, poolHex };
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function tryParseNativeDexFactoryRegisterRpcLogEntry(log) {
|
|
41
|
+
const p = tryParseNativeDexFactoryRegisterLog3(log);
|
|
42
|
+
if (!p)
|
|
43
|
+
return null;
|
|
44
|
+
return {
|
|
45
|
+
...p,
|
|
46
|
+
block_height: log.block_height,
|
|
47
|
+
tx_index: log.tx_index,
|
|
48
|
+
tx_id: log.tx_id,
|
|
49
|
+
log_index: log.log_index,
|
|
50
|
+
address: log.address,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function collectNativeDexFactoryRegisterLogsFromReceipt(receipt) {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (const { log } of iterReceiptLogs(receipt)) {
|
|
56
|
+
const p = tryParseNativeDexFactoryRegisterLog3(log);
|
|
57
|
+
if (p)
|
|
58
|
+
out.push(p);
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pair directory contract — access lists, `contract_call` payloads, storage reads.
|
|
3
|
+
* Matches `boing_execution::native_dex_factory` + `native_dex_factory_count_key`.
|
|
4
|
+
*/
|
|
5
|
+
import type { BoingClient } from './client.js';
|
|
6
|
+
import type { SimulateResult } from './types.js';
|
|
7
|
+
import { type Ed25519SecretKey32 } from './transactionBuilder.js';
|
|
8
|
+
/**
|
|
9
|
+
* `boing_getContractStorage` key for pair count (`native_dex_factory::native_dex_factory_count_key`).
|
|
10
|
+
* 16 zero bytes, **`BOINGDEX`** (8 bytes), 4 zero bytes, **`0xffffffff`** (big-endian).
|
|
11
|
+
*/
|
|
12
|
+
export declare const NATIVE_DEX_FACTORY_COUNT_KEY_HEX: `0x${string}424f494e4744455800000000ffffffff`;
|
|
13
|
+
/** `read` / `write`: signer + directory contract (parallel scheduling minimum). */
|
|
14
|
+
export declare function buildNativeDexFactoryAccessList(senderHex32: string, factoryHex32: string): {
|
|
15
|
+
read: string[];
|
|
16
|
+
write: string[];
|
|
17
|
+
};
|
|
18
|
+
export declare function buildNativeDexFactoryContractCallTx(senderHex32: string, factoryHex32: string, calldataHex: string): {
|
|
19
|
+
type: 'contract_call';
|
|
20
|
+
contract: string;
|
|
21
|
+
calldata: string;
|
|
22
|
+
access_list: {
|
|
23
|
+
read: string[];
|
|
24
|
+
write: string[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare function mergeNativeDexFactoryAccessListWithSimulation(senderHex32: string, factoryHex32: string, sim: SimulateResult): {
|
|
28
|
+
read: string[];
|
|
29
|
+
write: string[];
|
|
30
|
+
};
|
|
31
|
+
/** Decode `pairs_count` return data (32-byte word); count is in the low **8** bytes (matches on-chain layout). */
|
|
32
|
+
export declare function decodeNativeDexFactoryPairsCountReturnData(returnDataHex: string): bigint;
|
|
33
|
+
/**
|
|
34
|
+
* Decode `get_pair_at` return data (**96** bytes = three account words).
|
|
35
|
+
*/
|
|
36
|
+
export declare function decodeNativeDexFactoryGetPairAtReturnData(returnDataHex: string): {
|
|
37
|
+
tokenAHex: string;
|
|
38
|
+
tokenBHex: string;
|
|
39
|
+
poolHex: string;
|
|
40
|
+
};
|
|
41
|
+
/** Read registered pair count from contract storage (no simulation). */
|
|
42
|
+
export declare function fetchNativeDexFactoryPairsCount(client: BoingClient, factoryHex32: string): Promise<bigint>;
|
|
43
|
+
export type FindNativeDexFactoryPoolOptions = {
|
|
44
|
+
secretKey32: Ed25519SecretKey32;
|
|
45
|
+
senderHex: string;
|
|
46
|
+
/**
|
|
47
|
+
* Max directory indices to simulate (each index = one `boing_simulateTransaction`).
|
|
48
|
+
* Defaults to **`4096`** (on-chain max). Lower this on slow RPCs.
|
|
49
|
+
*/
|
|
50
|
+
maxPairsToScan?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Find a registered pool address for **`(tokenA, tokenB)`** in either order.
|
|
54
|
+
*
|
|
55
|
+
* There is no on-chain reverse map; this helper reads **`pairs_count`** from storage, then simulates
|
|
56
|
+
* **`get_pair_at(i)`** for each index until a matching triplet is found.
|
|
57
|
+
*
|
|
58
|
+
* Requires a signer because **`boing_simulateTransaction`** expects a signed tx envelope (same as submit).
|
|
59
|
+
*/
|
|
60
|
+
export declare function findNativeDexFactoryPoolByTokens(client: BoingClient, factoryHex32: string, tokenAHex32: string, tokenBHex32: string, options: FindNativeDexFactoryPoolOptions): Promise<string | null>;
|
|
61
|
+
//# sourceMappingURL=nativeDexFactoryPool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeDexFactoryPool.d.ts","sourceRoot":"","sources":["../src/nativeDexFactoryPool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AAgBjC;;;GAGG;AACH,eAAO,MAAM,gCAAgC,+CACoB,CAAC;AAElE,mFAAmF;AACnF,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAIrC;AAED,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,GAClB;IACD,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAClD,CAOA;AAED,wBAAgB,6CAA6C,CAC3D,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,cAAc,GAClB;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAGrC;AAED,kHAAkH;AAClH,wBAAgB,0CAA0C,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAGxF;AAED;;GAEG;AACH,wBAAgB,yCAAyC,CAAC,aAAa,EAAE,MAAM,GAAG;IAChF,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAcA;AAED,wEAAwE;AACxE,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAIjB;AAMD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,WAAW,EAAE,kBAAkB,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,WAAW,EACnB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqCxB"}
|