SHA256
Переписать shine_payments и обновить тестовый UI с известным багом state
This commit is contained in:
@@ -85,11 +85,12 @@
|
||||
const connection = new solanaWeb3.Connection(RPC_URL, "confirmed");
|
||||
|
||||
const SEEDS = {
|
||||
config: "shine_payments_v3_config",
|
||||
coef: "shine_payments_v3_coef_limit",
|
||||
queues: "shine_payments_v3_queues",
|
||||
ticketQ1: "shine_payments_v3_q1_ticket",
|
||||
config: "shine_payments_config",
|
||||
coef: "shine_payments_coef_limit",
|
||||
queues: "shine_payments_queues",
|
||||
ticketQ1: "shine_payments_q1_ticket",
|
||||
};
|
||||
const IX = { buyTicketUsd: 5, buyTicketSol: 6 };
|
||||
|
||||
const COEF_SCALE = 1_000_000n;
|
||||
const LAMPORTS_PER_SOL = 1_000_000_000n;
|
||||
@@ -177,10 +178,8 @@
|
||||
return (cents * (10_000n - bp)) / 10_000n;
|
||||
}
|
||||
|
||||
async function ixDiscriminator(name) {
|
||||
const msg = utf8("global:" + name);
|
||||
const hash = await crypto.subtle.digest("SHA-256", msg);
|
||||
return new Uint8Array(hash).slice(0, 8);
|
||||
function ixData(tag, ...parts) {
|
||||
return concat(new Uint8Array([tag]), ...parts);
|
||||
}
|
||||
|
||||
function parseConfig(data) {
|
||||
@@ -209,7 +208,11 @@
|
||||
const q2Paid = readU64(data, o); o += 8;
|
||||
const q2SumTotal = readU64(data, o); o += 8;
|
||||
const q2SumPaid = readU64(data, o); o += 8;
|
||||
return { version, q1Total, q1Paid, q1SumTotal, q1SumPaid, q2Total, q2Paid, q2SumTotal, q2SumPaid };
|
||||
const q3Total = readU64(data, o); o += 8;
|
||||
const q3Paid = readU64(data, o); o += 8;
|
||||
const q3SumTotal = readU64(data, o); o += 8;
|
||||
const q3SumPaid = readU64(data, o); o += 8;
|
||||
return { version, q1Total, q1Paid, q1SumTotal, q1SumPaid, q2Total, q2Paid, q2SumTotal, q2SumPaid, q3Total, q3Paid, q3SumTotal, q3SumPaid };
|
||||
}
|
||||
|
||||
function getProvider() {
|
||||
@@ -354,8 +357,7 @@
|
||||
|
||||
const nextIndex = queues.q1Total + 1n;
|
||||
const [ticketPda] = solanaWeb3.PublicKey.findProgramAddressSync([utf8(SEEDS.ticketQ1), u64ToBytes(nextIndex)], PROGRAM_ID);
|
||||
const disc = await ixDiscriminator("buy_ticket_usd");
|
||||
const data = concat(disc, u64ToBytes(usdCents), u64ToBytes(maxPayLamports), recipient.toBytes());
|
||||
const data = ixData(IX.buyTicketUsd, u64ToBytes(usdCents), u64ToBytes(maxPayLamports), recipient.toBytes());
|
||||
const keys = [
|
||||
{ pubkey: walletPubkey, isSigner: true, isWritable: true },
|
||||
{ pubkey: pdas.configPda, isSigner: false, isWritable: true },
|
||||
@@ -394,8 +396,7 @@
|
||||
|
||||
const nextIndex = queues.q1Total + 1n;
|
||||
const [ticketPda] = solanaWeb3.PublicKey.findProgramAddressSync([utf8(SEEDS.ticketQ1), u64ToBytes(nextIndex)], PROGRAM_ID);
|
||||
const disc = await ixDiscriminator("buy_ticket_sol");
|
||||
const data = concat(disc, u64ToBytes(lamports), u64ToBytes(minUsdCents), recipient.toBytes());
|
||||
const data = ixData(IX.buyTicketSol, u64ToBytes(lamports), u64ToBytes(minUsdCents), recipient.toBytes());
|
||||
const keys = [
|
||||
{ pubkey: walletPubkey, isSigner: true, isWritable: true },
|
||||
{ pubkey: pdas.configPda, isSigner: false, isWritable: true },
|
||||
|
||||
Reference in New Issue
Block a user