Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add token to small units conversion #157

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,38 @@ export const compressPublicKey = (pubkey: string): string => {
const compressed_key = Buffer.concat([new Uint8Array(Buffer.from(prefix, 'hex')), x]);
return compressed_key.toString('hex');
};

// Convert ATOM to uATOM
export const atomToUatom = (atom: string): bigint => {
return parseUnits(atom, 6);
};

// Convert DYDX to adydx
export const dydxToAdydx = (dydx: string): bigint => {
return parseUnits(dydx, 18); // adydx uses 18 decimals
};

// Convert ZETA to azeta
export const zetaToAzeta = (zeta: string): bigint => {
return parseUnits(zeta, 18); // azeta uses 18 decimals
};

// Convert OSMO to uosmo
export const osmoToUosmo = (osmo: string): bigint => {
return parseUnits(osmo, 6);
};

// Convert INJ to inj
export const injToInj = (inj: string): bigint => {
return parseUnits(inj, 18); // inj uses 18 decimals
};

// Convert TIA to utia
export const tiaToUtia = (tia: string): bigint => {
return parseUnits(tia, 6);
};

// Convert FET to afet
export const fetToAfet = (fet: string): bigint => {
return parseUnits(fet, 18); // afet uses 18 decimals
};