SHA256
Очередь выплат: минимум 0,1 SOL, запрет системных получателей, автопропуск
- shine_payments: минимальная покупка тикета 0,1 SOL для всех способов покупки (ошибка 37 TicketPurchaseTooSmall). - Получателем нельзя указать System Program, sysvar, встроенные и SPL-программы, сжигатель и программы SHiNE (RESERVED_RECIPIENTS): покупка, тикет менеджера, смена получателя. - step_payout: если получатель не может принять перевод (исполняемый, зарезервированный или после зачисления ниже rent-минимума), тикет закрывается пропуском: вызвавший получает награду, деньги остаются в inflow vault, байт статуса тикета = 2, лог SHINE_PAYMENTS_TICKET_SKIPPED. - Модульные тесты программы (Cargo.toml: включён test). - UI кошелька и очереди: статус «закрыт без выплаты», проверка минимума до отправки; тестовые страницы web/: статус пропуска, минимум и тексты ошибок. - Документация: shine_payments.md, FUNDS_FLOW.md, обзор архитектуры. Сборка и тесты Rust ещё не запускались (нет toolchain на этой машине). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
.warn { color: var(--warn); }
|
||||
.err { color: var(--err); white-space: pre-wrap; }
|
||||
.paid { color: var(--ok); font-weight: 700; }
|
||||
.skipped { color: var(--warn); font-weight: 700; }
|
||||
.formula { font-family: monospace; color: #c9d7f0; }
|
||||
code { background: var(--code); padding: 2px 4px; border-radius: 4px; }
|
||||
table { border-collapse: collapse; width: 100%; }
|
||||
@@ -220,11 +221,14 @@
|
||||
const version = data[o++];
|
||||
const queueId = data[o++];
|
||||
const index = readU64(data, o); o += 8;
|
||||
const isPaid = data[o++] === 1;
|
||||
// Байт статуса: 0 — ожидание, 1 — выплачен, 2 — закрыт пропуском без выплаты.
|
||||
const status = data[o++];
|
||||
const isPaid = status !== 0;
|
||||
const isSkipped = status === 2;
|
||||
const recipient = new solanaWeb3.PublicKey(data.slice(o, o + 32)); o += 32;
|
||||
const payout = readU64(data, o); o += 8;
|
||||
const debtBefore = readU64(data, o); o += 8;
|
||||
return { version, queueId, index, isPaid, recipient, payout, debtBefore };
|
||||
return { version, queueId, index, isPaid, isSkipped, recipient, payout, debtBefore };
|
||||
}
|
||||
function parseUsersEconomyConfig(data) {
|
||||
let o = 0;
|
||||
@@ -525,7 +529,7 @@
|
||||
<tr>
|
||||
<td>${t.index.toString()}</td>
|
||||
<td>${t.queueId}</td>
|
||||
<td>${t.isPaid ? '<span class="paid">выплачен</span>' : "ожидание"}</td>
|
||||
<td>${t.isSkipped ? '<span class="skipped">пропущен</span>' : (t.isPaid ? '<span class="paid">выплачен</span>' : "ожидание")}</td>
|
||||
<td><code>${t.recipient.toBase58()}</code></td>
|
||||
<td>${centsToUsdStr(t.payout)} USD</td>
|
||||
<td>${centsToUsdStr(t.debtBefore)} USD</td>
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
<button id="buyUsdBtn">Купить по USD</button>
|
||||
<button id="buySolBtn">Купить по SOL</button>
|
||||
</div>
|
||||
<div class="warn">Минимальная покупка — 0.1 SOL (в пересчёте по текущему курсу).</div>
|
||||
<div class="warn">Дополнительно к сумме покупки кошелек платит сеть за создание записи тикета (обычно около 0.002 SOL).</div>
|
||||
<div id="buyResult" class="muted"></div>
|
||||
</div>
|
||||
@@ -93,6 +94,8 @@
|
||||
const IX = { buyTicketUsd: 5, buyTicketSol: 6 };
|
||||
|
||||
const COEF_SCALE = 1_000_000n;
|
||||
// Минимальная покупка тикета в программе (MIN_TICKET_PURCHASE_LAMPORTS): 0.1 SOL.
|
||||
const MIN_TICKET_LAMPORTS = 100_000_000n;
|
||||
const LAMPORTS_PER_SOL = 1_000_000_000n;
|
||||
let walletPubkey = null;
|
||||
let lastState = null;
|
||||
@@ -234,6 +237,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Коды PaymentsError приходят как «custom program error: 0x..».
|
||||
function explainBuyError(e) {
|
||||
const msg = String(e?.message || e);
|
||||
if (/custom program error: 0x25\b/i.test(msg)) return "Сумма меньше минимальной покупки тикета (0.1 SOL).";
|
||||
if (/custom program error: 0x13\b/i.test(msg)) return "Этот адрес нельзя указать получателем выплаты (системный или программный аккаунт).";
|
||||
return msg;
|
||||
}
|
||||
async function sendInstruction(ix) {
|
||||
const provider = getProvider();
|
||||
if (!walletPubkey) await connectWallet();
|
||||
@@ -287,6 +297,7 @@
|
||||
<div>Возраст цены: <b>${Math.max(0, Math.floor(Date.now()/1000 - Number(lastState.pyth.publishTime)))} сек</b></div>
|
||||
<div>Если покупка по USD: к списанию примерно <b>${lamportsToSolStr(payForUsd)} SOL</b>, с допуском максимум <b>${lamportsToSolStr(maxLamports)} SOL</b>.</div>
|
||||
<div>Если покупка по SOL: это примерно <b>${centsToUsdStr(usdForSol)} USD</b>, с допуском минимум <b>${centsToUsdStr(minUsd)} USD</b>.</div>
|
||||
${payForUsd < MIN_TICKET_LAMPORTS || lamports < MIN_TICKET_LAMPORTS ? `<div class="warn">Меньше минимальной покупки: нужно не меньше 0.1 SOL (≈ ${centsToUsdStr(lamportsToUsdCentsFloor(MIN_TICKET_LAMPORTS, lastState.pyth))} USD).</div>` : ""}
|
||||
`;
|
||||
} catch (e) {
|
||||
el.innerHTML = `<span class="err">${String(e.message || e)}</span>`;
|
||||
@@ -357,6 +368,7 @@
|
||||
const usdCents = usdTextToCents(document.getElementById("amountUsd").value);
|
||||
const slippage = Math.max(0, Number(document.getElementById("slippagePct").value.trim() || "0"));
|
||||
const payLamports = usdCentsToLamportsCeil(usdCents, pyth);
|
||||
if (payLamports < MIN_TICKET_LAMPORTS) throw new Error("Сумма меньше минимальной покупки тикета (0.1 SOL).");
|
||||
const maxPayLamports = applySlippageUp(payLamports, slippage);
|
||||
const recipientRaw = document.getElementById("recipient").value.trim();
|
||||
const recipient = recipientRaw ? new solanaWeb3.PublicKey(recipientRaw) : walletPubkey;
|
||||
@@ -379,7 +391,7 @@
|
||||
out.innerHTML = `<span class="ok">Готово. Tx: <code>${sig}</code></span>`;
|
||||
await refreshState();
|
||||
} catch (e) {
|
||||
out.innerHTML = `<span class="err">${String(e.message || e)}</span>`;
|
||||
out.innerHTML = `<span class="err">${explainBuyError(e)}</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,6 +406,7 @@
|
||||
if (queues.q1SumTotal >= coef.limitUsdCents) throw new Error("Покупка временно приостановлена: лимит заполнен.");
|
||||
|
||||
const lamports = solTextToLamports(document.getElementById("amountSol").value);
|
||||
if (lamports < MIN_TICKET_LAMPORTS) throw new Error("Сумма меньше минимальной покупки тикета (0.1 SOL).");
|
||||
const slippage = Math.max(0, Number(document.getElementById("slippagePct").value.trim() || "0"));
|
||||
const usdCents = lamportsToUsdCentsFloor(lamports, pyth);
|
||||
const minUsdCents = applySlippageDown(usdCents, slippage);
|
||||
@@ -418,7 +431,7 @@
|
||||
out.innerHTML = `<span class="ok">Готово. Tx: <code>${sig}</code></span>`;
|
||||
await refreshState();
|
||||
} catch (e) {
|
||||
out.innerHTML = `<span class="err">${String(e.message || e)}</span>`;
|
||||
out.innerHTML = `<span class="err">${explainBuyError(e)}</span>`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
.err { color: var(--err); white-space: pre-wrap; }
|
||||
.paid { color: var(--ok); font-weight: 700; }
|
||||
.waiting { color: var(--muted); }
|
||||
.skipped { color: var(--warn); font-weight: 700; }
|
||||
.xfer { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
|
||||
code { background: var(--code); padding: 2px 4px; border-radius: 4px; }
|
||||
</style>
|
||||
@@ -198,11 +199,14 @@
|
||||
const version = data[o++];
|
||||
const queueId = data[o++];
|
||||
const index = readU64(data, o); o += 8;
|
||||
const isPaid = data[o++] === 1;
|
||||
// Байт статуса: 0 — ожидание, 1 — выплачен, 2 — закрыт пропуском без выплаты.
|
||||
const status = data[o++];
|
||||
const isPaid = status !== 0;
|
||||
const isSkipped = status === 2;
|
||||
const recipient = new solanaWeb3.PublicKey(data.slice(o, o + 32)); o += 32;
|
||||
const payoutUsdCents = readU64(data, o); o += 8;
|
||||
const debtBeforeUsdCents = readU64(data, o); o += 8;
|
||||
return { version, queueId, index, isPaid, recipient, payoutUsdCents, debtBeforeUsdCents };
|
||||
return { version, queueId, index, isPaid, isSkipped, recipient, payoutUsdCents, debtBeforeUsdCents };
|
||||
}
|
||||
|
||||
function getProvider() {
|
||||
@@ -342,7 +346,9 @@
|
||||
const isNext = !!next && next.queue === t.queueId && next.index === t.index;
|
||||
const isOwner = walletPubkey && walletPubkey.toBase58() === t.recipient.toBase58();
|
||||
const canTransfer = !t.isPaid && isOwner && !isNext;
|
||||
const whyBlocked = t.isPaid
|
||||
const whyBlocked = t.isSkipped
|
||||
? "Тикет закрыт без выплаты"
|
||||
: t.isPaid
|
||||
? "Тикет уже выплачен"
|
||||
: !isOwner
|
||||
? "Передача доступна только текущему получателю тикета"
|
||||
@@ -351,7 +357,7 @@
|
||||
: "";
|
||||
return `
|
||||
<div class="panel">
|
||||
<div>Тикет #<b>${t.index.toString()}</b> (очередь <b>${t.queueId}</b>) (<span class="${t.isPaid ? "paid" : "waiting"}">${t.isPaid ? "выплачен" : "ожидание"}</span>)</div>
|
||||
<div>Тикет #<b>${t.index.toString()}</b> (очередь <b>${t.queueId}</b>) (<span class="${t.isSkipped ? "skipped" : (t.isPaid ? "paid" : "waiting")}">${t.isSkipped ? "пропущен: получатель не может принять перевод" : (t.isPaid ? "выплачен" : "ожидание")}</span>)</div>
|
||||
<div>PDA: <code>${pda.toBase58()}</code></div>
|
||||
<div>Получатель: <code>${t.recipient.toBase58()}</code></div>
|
||||
<div>Сумма выплаты: <b>${centsToUsdStr(t.payoutUsdCents)} USD</b> (~${usdCentsToSolStr(t.payoutUsdCents, core.pyth)} SOL)</div>
|
||||
|
||||
Reference in New Issue
Block a user