Перевести донаты на 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
+16 -11
View File
@@ -292,10 +292,10 @@ export function parseShineUserPda(dataBytes) {
const unsignedBytes = bytes.slice(0, recordLen - 64);
let supportStats = { version: 0, supportSent: 0n, supportReceived: 0n, daoDirect: 0n };
if (recordLen < bytes.length && bytes[recordLen] !== 0) {
if (bytes[recordLen] !== 1) throw new Error('Неподдерживаемая версия статистики поддержки');
if (bytes[recordLen] !== 2) throw new Error('Неподдерживаемая версия статистики поддержки');
if (recordLen + 25 > bytes.length) throw new Error('Обрезан блок статистики поддержки');
const statsReader = makeReader(bytes.slice(recordLen + 1, recordLen + 25));
supportStats = { version: 1, supportSent: statsReader.readU64(), supportReceived: statsReader.readU64(), daoDirect: statsReader.readU64() };
supportStats = { version: 2, supportSent: statsReader.readU64(), supportReceived: statsReader.readU64(), daoDirect: statsReader.readU64() };
}
const header = { formatMajor, formatMinor, recordLen, createdAtMs, updatedAtMs, recordNumber, prevRecordHash, login, blocksCount, blocksOffset, signature, unsignedBytes, supportStats };
return parseV12Pda(bytes, header);
@@ -825,12 +825,13 @@ export function calcLimitTopupPriceLamports(additionalLimitBytes, lamportsPerLim
export function getLimitStepBytes() { return LIMIT_STEP; }
function supportData(tag, senderLogin, recipientLogin, amountLamports, target) {
function supportData(tag, senderLogin, recipientLogin, amountLamports, starCents, target) {
const out = [tag];
const putString = (value) => { const bytes = new TextEncoder().encode(String(value)); if (bytes.length > 255) throw new Error('Слишком длинный login'); out.push(bytes.length, ...bytes); };
putString(senderLogin);
if (recipientLogin != null) putString(recipientLogin);
pushU64LE(out, amountLamports);
pushU64LE(out, starCents);
if (target != null) {
out.push(target.type);
if (target.type === 1 || target.type === 2) { pushU64LE(out, target.channelBlockNumber); out.push(...toUint8Array(target.channelBlockHash, 32)); }
@@ -840,9 +841,9 @@ function supportData(tag, senderLogin, recipientLogin, amountLamports, target) {
}
/** Выполняет учитываемую поддержку через shine_users без Number и округлений. */
export async function supportShineUserOnSolana({ senderLogin, recipientLogin, amountLamports, target = { type: 0 }, solanaEndpoint, blockchainPrivatePkcs8B64, clientPrivatePkcs8B64 }) {
export async function supportShineUserOnSolana({ senderLogin, recipientLogin, amountLamports, starCents, oracleAccounts, target = { type: 0 }, solanaEndpoint, blockchainPrivatePkcs8B64, clientPrivatePkcs8B64 }) {
const amount = BigInt(amountLamports);
if (amount <= 0n || amount % 10n !== 0n) throw new Error('Сумма учитываемой поддержки должна быть положительной и кратной 10 lamports');
if (amount <= 0n || BigInt(starCents) < 10n) throw new Error('Сумма поддержки должна быть не менее 0,10 ⭐');
const sender = await readShineUserPda({ login: senderLogin, solanaEndpoint });
const recipient = await readShineUserPda({ login: recipientLogin, solanaEndpoint });
const ctx = await buildCommonContext({ login: sender.login, solanaEndpoint, clientPrivatePkcs8B64, payerPrivatePkcs8B64: blockchainPrivatePkcs8B64 });
@@ -855,21 +856,25 @@ export async function supportShineUserOnSolana({ senderLogin, recipientLogin, am
{ pubkey: recipientKey, isSigner: false, isWritable: true }, { pubkey: recipientPda, isSigner: false, isWritable: true },
{ pubkey: ctx.inflowVault, isSigner: false, isWritable: true }, { pubkey: ctx.economyConfigPda, isSigner: false, isWritable: false },
{ pubkey: ctx.solana.SystemProgram.programId, isSigner: false, isWritable: false },
], data: supportData(IX_SUPPORT_USER, sender.login, recipient.login, amount, target) });
{ pubkey: new ctx.solana.PublicKey(oracleAccounts.solUsd), isSigner: false, isWritable: false },
{ pubkey: new ctx.solana.PublicKey(oracleAccounts.usdtUsd), isSigner: false, isWritable: false },
], data: supportData(IX_SUPPORT_USER, sender.login, recipient.login, amount, BigInt(starCents), target) });
const signature = await sendAndConfirmSolanaHttp(ctx.connection, new ctx.solana.Transaction().add(ix), [ctx.payerKeypair]);
return { signature, amountLamports: amount, recipientLamports: amount * 9n / 10n, inflowLamports: amount / 10n };
return { signature, amountLamports: amount, starCents: BigInt(starCents), recipientLamports: amount - (amount + 9n) / 10n, inflowLamports: (amount + 9n) / 10n };
}
export async function supportShineDaoOnSolana({ senderLogin, amountLamports, solanaEndpoint, blockchainPrivatePkcs8B64, clientPrivatePkcs8B64 }) {
export async function supportShineDaoOnSolana({ senderLogin, amountLamports, starCents, oracleAccounts, solanaEndpoint, blockchainPrivatePkcs8B64, clientPrivatePkcs8B64 }) {
const amount = BigInt(amountLamports);
if (amount <= 0n) throw new Error('Сумма пожертвования должна быть положительной');
if (amount <= 0n || BigInt(starCents) < 10n) throw new Error('Минимальный донат 0,10 ⭐');
const sender = await readShineUserPda({ login: senderLogin, solanaEndpoint });
const ctx = await buildCommonContext({ login: sender.login, solanaEndpoint, clientPrivatePkcs8B64, payerPrivatePkcs8B64: blockchainPrivatePkcs8B64 });
const ix = new ctx.solana.TransactionInstruction({ programId: new ctx.solana.PublicKey(SHINE_USERS_PROGRAM_ID), keys: [
{ pubkey: ctx.payerKeypair.publicKey, isSigner: true, isWritable: true }, { pubkey: ctx.userPda, isSigner: false, isWritable: true },
{ pubkey: ctx.inflowVault, isSigner: false, isWritable: true }, { pubkey: ctx.economyConfigPda, isSigner: false, isWritable: false },
{ pubkey: ctx.solana.SystemProgram.programId, isSigner: false, isWritable: false },
], data: supportData(IX_SUPPORT_DAO, sender.login, null, amount, null) });
{ pubkey: new ctx.solana.PublicKey(oracleAccounts.solUsd), isSigner: false, isWritable: false },
{ pubkey: new ctx.solana.PublicKey(oracleAccounts.usdtUsd), isSigner: false, isWritable: false },
], data: supportData(IX_SUPPORT_DAO, sender.login, null, amount, BigInt(starCents), null) });
const signature = await sendAndConfirmSolanaHttp(ctx.connection, new ctx.solana.Transaction().add(ix), [ctx.payerKeypair]);
return { signature, amountLamports: amount };
return { signature, amountLamports: amount, starCents: BigInt(starCents) };
}