Spaces:
Sleeping
Sleeping
Download meteora/node_modules/@solana/buffer-layout-utils/src/decimal.ts from Trireme/hyper_dashboard: direct link, hf CLI and curl.
- Browser
- Download file 846 Bytes
-
https://huggingface.co/spaces/Trireme/hyper_dashboard/resolve/main/meteora/node_modules/%40solana/buffer-layout-utils/src/decimal.ts
- Command line
-
hf download hf://spaces/Trireme/hyper_dashboard/meteora/node_modules/@solana/buffer-layout-utils/src/decimal.ts
-
curl -L -o decimal.ts https://huggingface.co/spaces/Trireme/hyper_dashboard/resolve/main/meteora/node_modules/%40solana/buffer-layout-utils/src/decimal.ts
846 Bytes
| import { Layout } from '@solana/buffer-layout'; | |
| import BigNumber from 'bignumber.js'; | |
| import { encodeDecode } from './base'; | |
| import { u128 } from './bigint'; | |
| export const WAD = new BigNumber('1e+18'); | |
| export const decimal = (property?: string): Layout<BigNumber> => { | |
| const layout = u128(property); | |
| const { encode, decode } = encodeDecode(layout); | |
| const decimalLayout = layout as Layout<unknown> as Layout<BigNumber>; | |
| decimalLayout.decode = (buffer: Buffer, offset: number) => { | |
| const src = decode(buffer, offset).toString(); | |
| return new BigNumber(src).div(WAD); | |
| }; | |
| decimalLayout.encode = (decimal: BigNumber, buffer: Buffer, offset: number) => { | |
| const src = BigInt(decimal.times(WAD).integerValue().toString()); | |
| return encode(src, buffer, offset); | |
| }; | |
| return decimalLayout; | |
| }; | |