nansen-cli 2.0.1 → 2.2.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 +53 -0
- package/package.json +2 -2
- package/src/auth-credentials.js +15 -3
- package/src/auth-state.js +8 -6
- package/src/auth-store-worker.js +4 -3
- package/src/bridge.js +105 -77
- package/src/cache-inspect.js +3 -7
- package/src/doctor.js +1 -1
- package/src/local-file.js +75 -0
- package/src/schema.json +27 -2
- package/src/solana-tx.js +74 -0
- package/src/trading.js +723 -160
- package/src/wallet.js +16 -35
- package/src/walletconnect-trading.js +50 -13
- package/src/x402-svm.js +165 -7
package/src/solana-tx.js
CHANGED
|
@@ -151,3 +151,77 @@ export function resolveStaticAccount(parsed, index) {
|
|
|
151
151
|
if (index < parsed.staticAccountKeys.length) return parsed.staticAccountKeys[index];
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
|
+
|
|
155
|
+
// Owner of every address-lookup-table account.
|
|
156
|
+
export const ADDRESS_LOOKUP_TABLE_PROGRAM = 'AddressLookupTab1e1111111111111111111111111';
|
|
157
|
+
// LookupTableMeta: typeIndex u32, deactivationSlot u64, lastExtendedSlot u64,
|
|
158
|
+
// lastExtendedSlotStartIndex u8, authority Option<Pubkey>, padding. The
|
|
159
|
+
// 32-byte addresses start right after it.
|
|
160
|
+
// The program always reserves all 56 bytes, even when authority is None.
|
|
161
|
+
const LOOKUP_TABLE_META_SIZE = 56;
|
|
162
|
+
const LOOKUP_TABLE_TYPE_INDEX = 1;
|
|
163
|
+
// Lookups index a table with a single byte.
|
|
164
|
+
const LOOKUP_TABLE_MAX_ADDRESSES = 256;
|
|
165
|
+
// A table that has never been deactivated stores u64::MAX here.
|
|
166
|
+
const LOOKUP_TABLE_ACTIVE_SLOT = 0xffffffffffffffffn;
|
|
167
|
+
// The SlotHashes sysvar: the recent slots a deactivating table stays usable for.
|
|
168
|
+
export const SLOT_HASHES_SYSVAR = 'SysvarS1otHashes111111111111111111111111111';
|
|
169
|
+
export const SYSVAR_PROGRAM = 'Sysvar1111111111111111111111111111111111111';
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Parse the raw data of an address-lookup-table account into its addresses and
|
|
173
|
+
* its deactivation slot (null when it has never been deactivated). Throws on
|
|
174
|
+
* anything that isn't an initialized table, so a truncated or foreign account
|
|
175
|
+
* can't be read as a short or shifted address list.
|
|
176
|
+
*/
|
|
177
|
+
export function parseAddressLookupTable(data) {
|
|
178
|
+
if (data.length < LOOKUP_TABLE_META_SIZE || (data.length - LOOKUP_TABLE_META_SIZE) % 32 !== 0) {
|
|
179
|
+
throw new Error('Malformed address lookup table: unexpected account data length');
|
|
180
|
+
}
|
|
181
|
+
if ((data.length - LOOKUP_TABLE_META_SIZE) / 32 > LOOKUP_TABLE_MAX_ADDRESSES) {
|
|
182
|
+
throw new Error(`Malformed address lookup table: more than ${LOOKUP_TABLE_MAX_ADDRESSES} addresses`);
|
|
183
|
+
}
|
|
184
|
+
if (data.readUInt32LE(0) !== LOOKUP_TABLE_TYPE_INDEX) {
|
|
185
|
+
throw new Error('Malformed address lookup table: account is not an initialized lookup table');
|
|
186
|
+
}
|
|
187
|
+
const addresses = [];
|
|
188
|
+
for (let offset = LOOKUP_TABLE_META_SIZE; offset < data.length; offset += 32) {
|
|
189
|
+
addresses.push(base58Encode(data.subarray(offset, offset + 32)));
|
|
190
|
+
}
|
|
191
|
+
const deactivationSlot = data.readBigUInt64LE(4);
|
|
192
|
+
return {
|
|
193
|
+
deactivationSlot: deactivationSlot === LOOKUP_TABLE_ACTIVE_SLOT ? null : deactivationSlot,
|
|
194
|
+
addresses,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Parse the SlotHashes sysvar (u64 count, then count × (u64 slot, 32-byte
|
|
200
|
+
* hash)) into its slots.
|
|
201
|
+
*/
|
|
202
|
+
export function parseSlotHashes(data) {
|
|
203
|
+
if (data.length < 8) throw new Error('Malformed SlotHashes sysvar: unexpected account data length');
|
|
204
|
+
const count = data.readBigUInt64LE(0);
|
|
205
|
+
if (8n + count * 40n > BigInt(data.length)) {
|
|
206
|
+
throw new Error('Malformed SlotHashes sysvar: unexpected account data length');
|
|
207
|
+
}
|
|
208
|
+
const slots = [];
|
|
209
|
+
for (let i = 0; i < Number(count); i++) slots.push(data.readBigUInt64LE(8 + i * 40));
|
|
210
|
+
return slots;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Whether the runtime still resolves addresses through a table, mirroring its
|
|
215
|
+
* LookupTableMeta status rule. Deactivating a table doesn't disable it at
|
|
216
|
+
* once: it stays usable while its deactivation slot is the current slot or is
|
|
217
|
+
* still in SlotHashes, and only then becomes deactivated.
|
|
218
|
+
*
|
|
219
|
+
* A deactivation slot past `currentSlot` also counts as usable. Our two RPC
|
|
220
|
+
* reads can come from nodes at different heights, and a slot we haven't seen
|
|
221
|
+
* yet can't have left SlotHashes.
|
|
222
|
+
*/
|
|
223
|
+
export function isLookupTableUsable(deactivationSlot, currentSlot, slotHashes) {
|
|
224
|
+
if (deactivationSlot === null) return true;
|
|
225
|
+
if (deactivationSlot >= currentSlot) return true;
|
|
226
|
+
return slotHashes.includes(deactivationSlot);
|
|
227
|
+
}
|