feat: HTTP-шлюз поверх релейера (POST /bet,/close; GET /balance,/state) для пульта без Phantom
This commit is contained in:
+2
-13
@@ -1,4 +1,4 @@
|
||||
import { LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { getMint } from "@solana/spl-token";
|
||||
import { Program } from "@anchor-lang/core";
|
||||
import { loadConfig, loadKeypair, SIDE_UP } from "./config";
|
||||
@@ -11,27 +11,16 @@ import {
|
||||
readGlobal,
|
||||
ensureVaultFunded,
|
||||
ensureBettorTokenAccount,
|
||||
fundBettor,
|
||||
} from "./ops";
|
||||
import { betPda } from "./pda";
|
||||
import { makeConnection, makeProgram } from "./program";
|
||||
|
||||
import type { SmartUpdown } from "../idl/smart_updown";
|
||||
|
||||
const LAMPORTS_PER_SOL_NUM = Number(LAMPORTS_PER_SOL);
|
||||
|
||||
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
const STATUS_OPEN = 0;
|
||||
async function fundBettor(connection: any, bettorPubkey: PublicKey): Promise<void> {
|
||||
// SOL всё ещё нужен беттору: рент PDA-аккаунта ставки + комиссия за tx.
|
||||
// Саму ставку (фантики) он закрывает из своего токен-аккаунта (ATA).
|
||||
const bal = await connection.getBalance(bettorPubkey);
|
||||
if (bal < 2 * LAMPORTS_PER_SOL_NUM) {
|
||||
await connection.requestAirdrop(bettorPubkey, 5 * LAMPORTS_PER_SOL_NUM);
|
||||
await sleep(800);
|
||||
console.log(`bettor funded ${bettorPubkey.toBase58()} (+5 SOL)`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Человекочитаемо-формат: токен-юниты -> "N.NNNNNN" по decimals. */
|
||||
function humanize(units: string | number | bigint, decimals: number): string {
|
||||
|
||||
Reference in New Issue
Block a user