Перевести донаты на Stars и обновить Devnet

This commit is contained in:
AidarKC
2026-11-14 00:55:02 +03:00
parent c972a975fd
commit 97db033eb8
39 changed files with 1020 additions and 198 deletions
@@ -18,3 +18,29 @@ export function hexHash32(value) {
if (!/^[0-9a-f]{64}$/.test(hex)) throw new Error('Некорректный 32-байтовый хеш блока канала');
return Uint8Array.from({ length: 32 }, (_, i) => parseInt(hex.slice(i * 2, i * 2 + 2), 16));
}
/** Integer Star cents: 0.10 minimum, exactly two decimal places maximum. */
export function parseStarCents(input) {
const value = String(input ?? '').trim().replace(',', '.');
if (!/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/.test(value)) throw new Error('Введите сумму ⭐ с точностью до 0,01');
const [whole, frac = ''] = value.split('.');
const cents = BigInt(whole) * 100n + BigInt(frac.padEnd(2, '0') || '0');
if (cents < 10n || cents > 0xffff_ffff_ffff_ffffn) throw new Error('Минимальная поддержка — 0,10 ⭐');
return cents;
}
export function formatStars(value) {
const cents = BigInt(value);
return `${cents / 100n}.${String(cents % 100n).padStart(2, '0')} ⭐`;
}
export function splitStarCents(value) {
const cents = BigInt(value);
const dao = (cents + 9n) / 10n;
return { author: cents - dao, dao };
}
/** Quote Pyth prices as USD x 10^8; no Number or rounding-sensitive floats. */
export function starCentsToLamports(starCents, solPriceE8, usdtPriceE8) {
const cents = BigInt(starCents), sol = BigInt(solPriceE8), usdt = BigInt(usdtPriceE8);
if (sol <= 0n || usdt <= 0n) throw new Error('Нет актуального курса');
// ceil ensures enough lamports for the requested Stars.
return (cents * 1_000_000_000n * usdt + 100n * sol - 1n) / (100n * sol);
}