resolves #42 Co-authored-by: johba <johba@harb.eth> Reviewed-on: https://codeberg.org/johba/harb/pulls/49
18 lines
601 B
TypeScript
18 lines
601 B
TypeScript
import { bytesToUint256LittleEndian } from './subgraph.js';
|
|
|
|
export function toBigIntId(id: string | Uint8Array | number | bigint): bigint {
|
|
if (typeof id === 'bigint') return id;
|
|
if (typeof id === 'number') return BigInt(id);
|
|
if (typeof id === 'string') {
|
|
const trimmed = id.startsWith('0x') ? id : `0x${id}`;
|
|
return BigInt(trimmed);
|
|
}
|
|
if (id instanceof Uint8Array) {
|
|
return bytesToUint256LittleEndian(id);
|
|
}
|
|
throw new Error('Unsupported position id type');
|
|
}
|
|
|
|
export function decodePositionId(id: string | Uint8Array | number | bigint): bigint {
|
|
return toBigIntId(id);
|
|
}
|