diff --git a/Makefile b/Makefile index f56811b..d588148 100644 --- a/Makefile +++ b/Makefile @@ -29,5 +29,5 @@ judge: bun --no-env-file scripts/judge.ts break: - cargo test --manifest-path contracts/Cargo.toml -p familiar-root break_ -- --nocapture + cargo test --manifest-path contracts/Cargo.toml -p familiar-root -p familiar-season break_ -- --nocapture bun test services/relayer/src/auth/sign.test.ts diff --git a/PROGRESS.md b/PROGRESS.md index 39df622..b965df5 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -16,6 +16,12 @@ Full earlier progress and acceptance records are preserved in the [archive](docs | 2026-11-13 | Mochi's sealed note on local branch `feat/sealed-note` (flagged off) | `bun run test` 247 pass/15685 assertions; `cargo test --manifest-path contracts/Cargo.toml --workspace` 123 pass/2 ignored; `make build`, `bun run build:release`, `make browser` (Chromium/WebKit), `make evidence` (15 signatures) pass; mocked note UI viewed at 390×844 and 1440×900; `bun --env-file=
scripts/sealed-note-live.ts` | Live 2026-11-13: keyless `GET /v1/model/z-ai%2Fglm-5.3-flash` → `providerType:vllm, attestationSupported:true`; keyless `GET /v1/attestation/report` (ed25519, fresh nonce, `x-no-aliasing`) → 200 with 3 instances sharing key `5a0210f2…0caff`, all verified by SDK 0.3.0 (`UpToDate`, GPU evidence required); CORS allows the production origin. Three live completions with `X-Encryption-Version: 3`: chats `8af36ee4753d4228994b34ee1a8183ab` and `f63baa0caeb549f4932deb02daa59745` were broken (GLM spent all 120 tokens reasoning, `finish_reason:length`, empty content, despite `chat_template_kwargs.enable_thinking:false`); after switching to `thinking_token_budget:0`, chat `daa6b15838fc402689766a28b7826446` returned `provider_tee`, decrypted and **sealed**. Then the real `writeSealedNote` ran inside Playwright Chromium and WebKit (SDK default browser verifiers via NEAR AI's PCCS/NRAS proxies, WebCrypto Ed25519) against the relay code in-process: chats `20d3c9c6263b42edac0533dd02eb89d4` (Chromium) and `d8b367f524824d53ad99bb8f2849d736` (WebKit) both **sealed**, and the note stayed attached after a later accepted return. Five live completions in total. Read-only testnet views: `tidebound_journey` on `familiar-game.testnet` returns `claims` (qa-maker-v2: 2, dadadave80: 0) and `rpcNoteChain` reads them; unregistered keys resolve to no player. Eligibility/identity in the live runs were local stand-ins; no Privy JWT, deployed relay or Vercel variable was exercised. The in-game satchel with the flag on was not viewed; the note component was viewed standalone with mocked results and in the live browser run. No push or deployment. | | 2026-11-14 | Sealed-note review fixes on `feat/sealed-note` (still flagged off) | `bun run typecheck`; `bun run test` 250 pass/15699 assertions; `cargo test --manifest-path contracts/Cargo.toml --workspace` 123 pass/2 ignored; `make build`, `bun run build:release`, `make browser` (Chromium/WebKit), `make evidence` (15 signatures) pass; mocked note UI at 390×844 and 1440×900 (all five states, no horizontal overflow, no console errors); offline in-browser seal check in Chromium and WebKit with a locally signed `provider_tee` record | Relay: the note-once lock is replaced by 3 notes per account per UTC day plus 3/hour per account and 120/hour overall, so a broken note can be asked again; the completion call aborts after 35 s and signature polling runs for up to 10 s (tests cover the daily reset, a hung upstream and the polling window). Browser: a missing signature is a distinct "seal not recorded yet" state that is shown, retryable and never stored; the final Ed25519 check is the SDK's `verifyModelResponse` (tweetnacl), and the offline browser check sealed in both engines with `crypto.subtle.verify`/`importKey` disabled and rejected a flipped signature. The back of each note states only what that note established (sealed: full claim and shared-key limit; not sealed/unrecorded: attestation, encryption and the exact reason; broken: model and what happened). Keyboard focus moves to the note and a polite status region announces the outcome (checked in Chromium via the mocked fixture; no screen reader was run). No live NEAR AI completion was made for these fixes; no push or deployment. | | 2026-11-14 | Sealed-note second review fixes | Independent re-review (2 reviewers, each finding verified) confirmed 5 issues; `bun test services/relayer/src/sealed-note.test.ts web/src/note` 18 pass; full `bun run test`, `make build`, `make browser` (Chromium/WebKit), `make evidence` pass | All three note allowances are checked before any is charged (a refusal no longer uses up the next day); daily refusal is `QUOTA_DAY`, hourly/global `QUOTA` keeps Ask again; register reads (8 s each), completion and signature lookup are bounded from request start (55 s budget) and a late request is refused before charging; invite copy back to “One note per harbor.” to match the component; unrecorded notes offer “Ask for a new note”. Final check of these fixes confirmed two more and both are fixed: a failed retry keeps the readable unrecorded note and says so visibly and to screen readers, and a request refused for lack of time returns `NOTE_LATE` instead of claiming the register was unreadable. The retry-keeps-note path is typechecked but not exercised in a browser. Not run against live NEAR AI. | +| 2026-11-13 | Season 2 contract built locally (`feat/season-two`), not deployed | `cargo test --workspace` 175 passed/2 ignored (52 in `familiar-season`), `bun run test` 238 pass, fmt/clippy (`-D warnings`) clean, `make build`, `make evidence`, 27 season `break_` tests; `scripts/build-contracts.sh` output 232290 bytes, code hash `7EAyjP7NpCMPTiiHMdjtNh3VzkfKekcfFQfhUcjgW4UJ` (reproduced twice). `#[private]`, deposit rejection, JSON argument decoding and the `nft_token` callback gas have not run in Wasm or a sandbox | New self-contained `season` contract: daily court alternating `first_light_v1`/`first_light_v2` by day parity (fresh beacon outing), cargo table lens→glass, chart/salvage→reed, moth/vane unmapped (awaiting David's choice). Best hauls regenerated by exhaustive search on both the TypeScript engines and the contract replay: v1 rope (1 glass, 1 reed), v1 lantern (1, 2), v2 either tool (1, 0), so v2 days can never mint reed. Integer x^0.7 as isqrt × fifth root; `pricing.ts` matches `pricing.rs` on 1,000 seeded cases. Discrepancy: the brief's "her account's balance" purse is a per-pet ledger entry in `season`, not the pet account's balance. Root, Items, Pet and every Season 1 record, hash and fixture unchanged. No deployment, signing or push. | +| 2026-11-13 | Season 2 cargo table moth→reed; season Wasm run in a local sandbox, not deployed | `bun run test:season-sandbox` (near-workspaces 0.24.0 sandbox, real Root/Items/Bakery/Market/mock pool/global Pet stack, day 20770 = `first_light_v1`) 1 passed; `cargo test --workspace` 175 passed/3 ignored; `bun run test` 238 pass; fmt and clippy `-D warnings --all-targets` clean; `scripts/build-contracts.sh` output 233708 bytes, code hash `3FbynwMm2uWs8bahXSCoqDdrKsEJ1on6rR1C277hXNzy` (reproduced twice) | On Wasm: `new`, `on_wish_owner`, `on_storage_withdraw` reject strangers as private; deposits on `claim_daily`/`buy`/`sell`/`set_wish`/`cancel_wish` rejected; doctored courts refused (`ERR_WRONG_COURT`, `ERR_RETURN_REQUIRED`, `ERR_RULES_VERSION`, `ERR_REPLAY_CONTEXT`); second claim `ERR_ALREADY_MINTED`; `max_price`/`min_price` enforced; `set_wish` at 60 Tgas prepaid through Root `nft_token` (1.851 Tgas burnt of 10 attached) and `on_wish_owner` (1.808 refused / 2.363 waiting / 3.189 replace-and-fill of 35 attached), totals 6.910/7.466/8.297 Tgas; non-owner holds no Shells, storage or postcard; cancel refunds. moth→reed gives v1 rope two maximal hauls (1,1)/(0,2), so `BEST_HAUL` is now a Pareto list per tool and v2 best is (1,1) for both tools. Not run on Wasm: the `first_light_v2` court, day rollover/till refill (100k-block fast-forward did not finish in 10 min), trade-triggered wish fills, `storage_withdraw`. | +| 2026-11-13 | Season 2 contract deployed to testnet (David approved deploy and moth→reed) | `bun --env-file=.env.tidebound scripts/deploy-season.ts 3FbynwMm2uWs8bahXSCoqDdrKsEJ1on6rR1C277hXNzy`; create `7dvJZxqvfZxCQAgVoXfuJYaWWXTFF4zESphCkeVNhAy8`, fund `FR1rLGKriDpyF2R5WfCYUb3EVaz1mAbMoJyWiBA2vkTN`, deploy+init `6Bcz3vMmiG2P6P5eySzQNgBh68Frsk3qK7JciPmyk4WD`; independent fastnear `view_account` reads code `3FbynwMm…XNzy`, 234087 bytes | `season.familiar-game.testnet` initialised with root `familiar-game.testnet`; `get_shelf` day 20770, till 300, glass 40 @ 8, reed 40 @ 4. Root paid only 0.05 NEAR to create it; code storage funded by faucet account `familiar-season-fund-mwfjxq50.testnet` (key discarded). Season keeps one FullAccess key (the root's admin key) for fixes before the deadline, disclosed like Root/Items. No UI yet; no player has traded. | +| 2026-11-13 | Season 2 game screens built locally behind `VITE_SEASON2_ENABLED` (`feat/season-two-ui`), not deployed | `bun run test` 259 pass; `cargo test --workspace` 175 passed/3 ignored; `make build`, `make browser` (Chromium/WebKit), `make evidence`; `bun run test:season-browser` at 390×844 and 1440×900 on day 20770 (`first_light_v1`) and day 20771 (`first_light_v2`: the 17-step rope route was played through the real controls, kept as a tide return, First Light home and return memories unchanged) | Bram's shelf and till read live `get_shelf`/`get_today` from `season.familiar-game.testnet`; quotes simulate unit by unit and match the live one-unit `buy_price`/`sell_price`; trades send `max_price`/`min_price` from the shown quote. Signed out, the market is a labelled device preview using `pricing.ts`. Today's tide starts a fresh Beacon Court outing kept apart from First Light progress and docks it with `claim_daily`. Mochi's wish sets/cancels and shows the postcard. Signer allowlist now admits exactly `claim_daily`, `buy`, `sell`, `set_wish`, `cancel_wish` and `storage_deposit` (0.0125 NEAR exactly) on `season.`. Browser check: views live, signed-in ledger and signing mocked in a dev-only harness. **No signed-in trade, claim, wish or registration has run on testnet.** Under the production Privy provider the hosted relayer signs nothing native; season calls are checked by `validateNativeIntent` in the browser (`privy-adapter.ts`), so the allowlist and receiver gates go live on merge even with the flag off (no UI calls them then). The near-auth relayer path uses the same validator but its deployed copy is unchanged. Discrepancy: `web/PRODUCT.md` says Today's Tide is coming soon and not playable; with the flag on it is playable (product docs not edited). Even (`first_light_v1`) days cannot be sailed from the current game. Icons generated with gpt-6-astra via Codex CLI; provenance in `web/public/assets/season/provenance.json`. | +| 2026-11-14 | First live Season 2 day on testnet (day 20771, Beacon Court) | `bun --env-file=.env.tidebound scripts/season-live.ts` (faucet rate-limited, so root created `qa-season-mwfncbhi.familiar-game.testnet` with 0.3 NEAR): storage_deposit `H2JB6GcoiaHURYESUFqbbg6bkLAx8UzTm3AXDsZe6koE` 2.159 Tgas; claim_daily `BPH4quoUi5CnKmkwRoZZExCfs4mZ2zgMFUoKL8Lmayk5` 3.699 Tgas; sell glass `4KZnGDNJV7Hf6PP7MXfxUgqcdG25EYPnq22GM9XgXA5A`, sell reed `DVckVNtfN8cHACkCGCc5QaKJKxbCvyfU7Jw59rPFWecY`, buy reed `4XUZB8QnFvoKBzJMZqXWmGxsB9xzNTYbS2txLPiU9aMZ`, 2.536 Tgas each | The 17-step rope route minted 1 glass + 1 reed with score 10000 (value equals the best haul at docking prices); after two sales and one buy the account holds 5 Shells and 1 reed, matching the contract arithmetic. 100 Tgas prepaid needs about 0.1 NEAR of balance (a 0.1 NEAR account was refused), so the UI's trade gas was lowered to 30 Tgas. Earlier faucet runs also recorded storage `GLhCCAWEA5Nd7Q7m8iUaGsik4UVcbCv2wKs8pLXBZm8k`, claim `FfPPx4LpARtMzk7eXGGHKYvo4uFJpCrSy4aG9K6TKX79`, sell `59PzZGPQ8mJf11edrpfqK3gZkE8dRNcdWmvi2qr2TmYu`, then a script buy refused with ERR_SHELLS (3 Shells could not pay 4). No wish yet: the test account owns no pet. | +| 2026-11-14 | Season 2 UI review fixes; rebased onto `main` (#3–#5); release build carries `VITE_SEASON2_ENABLED` | `bun run typecheck`; `bun run test` 289 pass/17104 assertions; `cargo test --workspace` 182 passed/0 failed/3 ignored; `make build`, `make browser`, `make evidence`, `make break` (now also `familiar-season`: 27 season `break_` tests) ok; `bun run test:season-browser` passed at 390×844 and 1440×900 on 14 Nov UTC (a Beacon Court day); `test:records-browser` passed (one earlier run exited 1 with every check printed as passed and no error; four reruns exited 0). `VERCEL_ENV=production PRIVY_APP_ID=localcheck bun --no-env-file scripts/build-release.ts` with `VITE_SEASON2_ENABLED=true` emits `SeasonBram-*.js` containing the season screens; without the flag, or with `yes`, no season chunk or season strings are in `.vercel/output/static/assets` | Second ledger deposit refused before sending (`get_account` read at final); refusals before sending show the controller's own words (`SeasonNotSent`); wish form hidden without Mochi; buttons stay focusable with `aria-disabled` and focus returns to the status line; the device preview rolls over each day like the contract. Release flag follows the sealed note: production only, Privy app present, exactly `true`. The lazy season import is now behind the flag, so builds without it leave the screens out. The key line's signer-action list names the six season calls. Not deployed; no Vercel env change; nothing signed. | ## Recorded discrepancies (NEAR AI, 2026-11-13) diff --git a/contracts/Cargo.lock b/contracts/Cargo.lock index 1990d5f..4705bb6 100644 --- a/contracts/Cargo.lock +++ b/contracts/Cargo.lock @@ -972,6 +972,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "familiar-season" +version = "0.1.0" +dependencies = [ + "familiar-common", + "near-sdk", + "near-workspaces", + "tokio", +] + [[package]] name = "fastrand" version = "2.5.0" diff --git a/contracts/Cargo.toml b/contracts/Cargo.toml index 5edc74d..fc79205 100644 --- a/contracts/Cargo.toml +++ b/contracts/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["common", "rules-export", "root", "pet", "items", "bakery", "market", "mock-pool"] +members = ["common", "rules-export", "root", "pet", "items", "bakery", "market", "mock-pool", "season"] [workspace.dependencies] near-sdk = { version = "=5.30.0", features = ["legacy", "global-contracts"] } diff --git a/contracts/season/Cargo.toml b/contracts/season/Cargo.toml new file mode 100644 index 0000000..b0f5923 --- /dev/null +++ b/contracts/season/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "familiar-season" +version = "0.1.0" +edition = "2024" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +near-sdk.workspace = true +familiar-common.workspace = true + +[dev-dependencies] +near-sdk = { workspace = true, features = ["unit-testing"] } +near-workspaces = "=0.24.0" +tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/contracts/season/fixtures/best-haul.json b/contracts/season/fixtures/best-haul.json new file mode 100644 index 0000000..a6ad6f8 --- /dev/null +++ b/contracts/season/fixtures/best-haul.json @@ -0,0 +1 @@ +[{"content_version":"first_light_v1","area":"beacon","tools":[{"tool":"rope","hauls":[[1,1],[0,2]]},{"tool":"lantern","hauls":[[1,2]]}]},{"content_version":"first_light_v2","area":"beacon","tools":[{"tool":"rope","hauls":[[1,1]]},{"tool":"lantern","hauls":[[1,1]]}]}] diff --git a/contracts/season/fixtures/pricing-cases.json b/contracts/season/fixtures/pricing-cases.json new file mode 100644 index 0000000..4275d55 --- /dev/null +++ b/contracts/season/fixtures/pricing-cases.json @@ -0,0 +1 @@ +[{"good":"glass","stock":817318,"heat_fp":39000000,"days":13,"heat_now_fp":"4760","pow":"500000","price_fp":"4000068","buyback_fp":"3200054","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":19000000,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":62520,"heat_fp":0,"days":25,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":27,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"1316700","price_fp":"5266800","buyback_fp":"4213440","buy":"6","sell":"4","commission":"15"},{"good":"glass","stock":2,"heat_fp":1223766477,"days":1,"heat_now_fp":"611883238","pow":"3000000","price_fp":"79069488","buyback_fp":"63255590","buy":"80","sell":"63","commission":"36"},{"good":"reed","stock":37,"heat_fp":413150138,"days":16,"heat_now_fp":"6304","pow":"1056088","price_fp":"4224449","buyback_fp":"3379559","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":13,"heat_fp":9000000,"days":56,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":55,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"800178","price_fp":"3200712","buyback_fp":"2560569","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":3,"heat_fp":0,"days":65,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":49,"heat_fp":531507923,"days":30,"heat_now_fp":"0","pow":"867569","price_fp":"3470276","buyback_fp":"2776220","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":813715,"heat_fp":70000000,"days":12,"heat_now_fp":"17089","pow":"500000","price_fp":"4000256","buyback_fp":"3200204","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":9,"heat_fp":60000000,"days":34,"heat_now_fp":"0","pow":"2841004","price_fp":"11364016","buyback_fp":"9091212","buy":"12","sell":"9","commission":"34"},{"good":"glass","stock":379948,"heat_fp":13000000,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":1920958777,"days":45,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":54,"heat_fp":53000000,"days":67,"heat_now_fp":"0","pow":"810523","price_fp":"6484184","buyback_fp":"5187347","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":2,"heat_fp":17000000,"days":61,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":73,"heat_fp":1396007159,"days":62,"heat_now_fp":"0","pow":"656320","price_fp":"5250560","buyback_fp":"4200448","buy":"6","sell":"4","commission":"7"},{"good":"reed","stock":3,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":52,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"832220","price_fp":"6657760","buyback_fp":"5326208","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":0,"heat_fp":1374624017,"days":38,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":60,"heat_fp":2136720695,"days":25,"heat_now_fp":"63","pow":"752896","price_fp":"6023168","buyback_fp":"4818534","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":2,"heat_fp":1282713797,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":326,"heat_fp":28000000,"days":17,"heat_now_fp":"213","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":828874,"heat_fp":10000000,"days":47,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":195,"heat_fp":0,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":226928043,"days":6,"heat_now_fp":"3545750","pow":"3000000","price_fp":"12159552","buyback_fp":"9727641","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":1913172944,"days":27,"heat_now_fp":"14","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":46,"heat_fp":0,"days":38,"heat_now_fp":"0","pow":"906798","price_fp":"3627192","buyback_fp":"2901753","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":23,"heat_fp":53000000,"days":22,"heat_now_fp":"12","pow":"1473099","price_fp":"11784792","buyback_fp":"9427833","buy":"12","sell":"9","commission":"17"},{"good":"reed","stock":118,"heat_fp":1806259386,"days":9,"heat_now_fp":"3527850","pow":"500000","price_fp":"2026458","buyback_fp":"1621166","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":10,"heat_fp":1446666885,"days":58,"heat_now_fp":"0","pow":"2639014","price_fp":"21112112","buyback_fp":"16889689","buy":"22","sell":"16","commission":"31"},{"good":"reed","stock":5,"heat_fp":64000000,"days":60,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":346,"heat_fp":49000000,"days":2,"heat_now_fp":"12250000","pow":"500000","price_fp":"4183748","buyback_fp":"3346998","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":51,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"843611","price_fp":"3374444","buyback_fp":"2699555","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":655284,"heat_fp":65000000,"days":18,"heat_now_fp":"247","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":24898,"heat_fp":49000000,"days":20,"heat_now_fp":"46","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":73000000,"days":33,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":37,"heat_fp":36000000,"days":23,"heat_now_fp":"4","pow":"1056088","price_fp":"4224352","buyback_fp":"3379481","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":50,"heat_fp":1530265621,"days":18,"heat_now_fp":"5837","pow":"855387","price_fp":"6843239","buyback_fp":"5474591","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":262580,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":32,"heat_fp":57000000,"days":22,"heat_now_fp":"13","pow":"1169058","price_fp":"9352464","buyback_fp":"7481971","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":1,"heat_fp":1233826180,"days":48,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":0,"heat_fp":1904008683,"days":69,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":41,"heat_fp":269525652,"days":58,"heat_now_fp":"0","pow":"982862","price_fp":"3931448","buyback_fp":"3145158","buy":"4","sell":"3","commission":"11"},{"good":"glass","stock":34,"heat_fp":57000000,"days":65,"heat_now_fp":"0","pow":"1120485","price_fp":"8963880","buyback_fp":"7171104","buy":"9","sell":"7","commission":"13"},{"good":"reed","stock":109,"heat_fp":1079557797,"days":8,"heat_now_fp":"4217022","pow":"500000","price_fp":"2031626","buyback_fp":"1625300","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":377108,"heat_fp":1732852111,"days":27,"heat_now_fp":"12","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":377,"heat_fp":19000000,"days":21,"heat_now_fp":"9","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":17,"heat_fp":1324948739,"days":37,"heat_now_fp":"0","pow":"1820233","price_fp":"7280932","buyback_fp":"5824745","buy":"8","sell":"5","commission":"21"},{"good":"glass","stock":20,"heat_fp":0,"days":60,"heat_now_fp":"0","pow":"1624503","price_fp":"12996024","buyback_fp":"10396819","buy":"13","sell":"10","commission":"19"},{"good":"reed","stock":1,"heat_fp":75000000,"days":46,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":442990,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":79,"heat_fp":1954101088,"days":4,"heat_now_fp":"122131318","pow":"621015","price_fp":"3621739","buyback_fp":"2897391","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":41,"heat_fp":1383861828,"days":31,"heat_now_fp":"0","pow":"982862","price_fp":"7862896","buyback_fp":"6290316","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":48,"heat_fp":76000000,"days":49,"heat_now_fp":"0","pow":"880181","price_fp":"3520724","buyback_fp":"2816579","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":4,"heat_fp":0,"days":40,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":943396,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":0,"days":18,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":191667,"heat_fp":895570868,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":81,"heat_fp":0,"days":27,"heat_now_fp":"0","pow":"610241","price_fp":"4881928","buyback_fp":"3905542","buy":"5","sell":"3","commission":"7"},{"good":"reed","stock":13,"heat_fp":58000000,"days":43,"heat_now_fp":"0","pow":"2196247","price_fp":"8784988","buyback_fp":"7027990","buy":"9","sell":"7","commission":"26"},{"good":"glass","stock":47,"heat_fp":1028921473,"days":62,"heat_now_fp":"0","pow":"893248","price_fp":"7145984","buyback_fp":"5716787","buy":"8","sell":"5","commission":"10"},{"good":"reed","stock":41,"heat_fp":1855786052,"days":17,"heat_now_fp":"14158","pow":"982862","price_fp":"3931652","buyback_fp":"3145321","buy":"4","sell":"3","commission":"11"},{"good":"glass","stock":15,"heat_fp":1833813614,"days":54,"heat_now_fp":"0","pow":"1986907","price_fp":"15895256","buyback_fp":"12716204","buy":"16","sell":"12","commission":"23"},{"good":"reed","stock":4,"heat_fp":59000000,"days":5,"heat_now_fp":"1843750","pow":"3000000","price_fp":"12082956","buyback_fp":"9666364","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":4,"heat_fp":8000000,"days":37,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":2,"heat_fp":46000000,"days":45,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":4,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":109,"heat_fp":1258048533,"days":29,"heat_now_fp":"2","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":484576611,"days":23,"heat_now_fp":"57","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":279,"heat_fp":2000000,"days":7,"heat_now_fp":"15625","pow":"500000","price_fp":"2000116","buyback_fp":"1600092","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":1368161262,"days":66,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":4,"heat_fp":626055175,"days":21,"heat_now_fp":"298","pow":"3000000","price_fp":"24000024","buyback_fp":"19200019","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":733888,"heat_fp":63000000,"days":2,"heat_now_fp":"15750000","pow":"500000","price_fp":"2118124","buyback_fp":"1694499","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":233,"heat_fp":51000000,"days":23,"heat_now_fp":"6","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":572952,"heat_fp":30000000,"days":12,"heat_now_fp":"7324","pow":"500000","price_fp":"2000054","buyback_fp":"1600043","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":615536,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":56,"heat_fp":47000000,"days":2,"heat_now_fp":"11750000","pow":"790149","price_fp":"3299858","buyback_fp":"2639886","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":3,"heat_fp":1946821096,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":0,"days":7,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":268726,"heat_fp":61000000,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":56,"heat_fp":0,"days":20,"heat_now_fp":"0","pow":"790149","price_fp":"3160596","buyback_fp":"2528476","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":85,"heat_fp":1097291408,"days":5,"heat_now_fp":"34290356","pow":"589994","price_fp":"5326881","buyback_fp":"4261504","buy":"6","sell":"4","commission":"7"},{"good":"reed","stock":1,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":852957,"heat_fp":10000000,"days":23,"heat_now_fp":"1","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":205,"heat_fp":1563290143,"days":55,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":813786,"heat_fp":714650681,"days":17,"heat_now_fp":"5452","pow":"500000","price_fp":"2000040","buyback_fp":"1600032","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":52,"heat_fp":0,"days":37,"heat_now_fp":"0","pow":"832220","price_fp":"6657760","buyback_fp":"5326208","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":385,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":39,"heat_fp":626648771,"days":38,"heat_now_fp":"0","pow":"1017879","price_fp":"8143032","buyback_fp":"6514425","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":969823,"heat_fp":41000000,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":13,"heat_fp":67000000,"days":55,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":908702,"heat_fp":56000000,"days":16,"heat_now_fp":"854","pow":"500000","price_fp":"2000006","buyback_fp":"1600004","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":96887136,"days":49,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":442631,"heat_fp":0,"days":20,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":151,"heat_fp":1148152056,"days":66,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":79939,"heat_fp":42000000,"days":39,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":6,"heat_fp":51000000,"days":69,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":4,"heat_fp":0,"days":45,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":47,"heat_fp":829836657,"days":39,"heat_now_fp":"0","pow":"893248","price_fp":"7145984","buyback_fp":"5716787","buy":"8","sell":"5","commission":"10"},{"good":"reed","stock":1,"heat_fp":30000000,"days":40,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":0,"heat_fp":1348118131,"days":52,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":9,"heat_fp":377351742,"days":1,"heat_now_fp":"188675871","pow":"2841004","price_fp":"19404443","buyback_fp":"15523554","buy":"20","sell":"15","commission":"36"},{"good":"glass","stock":0,"heat_fp":0,"days":17,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":0,"days":10,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":25,"heat_fp":72000000,"days":65,"heat_now_fp":"0","pow":"1389580","price_fp":"11116640","buyback_fp":"8893312","buy":"12","sell":"8","commission":"16"},{"good":"reed","stock":231,"heat_fp":0,"days":63,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":690282,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":12,"heat_fp":108507976,"days":40,"heat_now_fp":"0","pow":"2322815","price_fp":"18582520","buyback_fp":"14866016","buy":"19","sell":"14","commission":"27"},{"good":"reed","stock":3,"heat_fp":215489847,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":9000000,"days":33,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":5,"heat_fp":2038779899,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":345148,"heat_fp":51000000,"days":16,"heat_now_fp":"778","pow":"500000","price_fp":"4000008","buyback_fp":"3200006","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":13,"heat_fp":858493767,"days":3,"heat_now_fp":"107311720","pow":"2196247","price_fp":"12320225","buyback_fp":"9856180","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":183,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":177833365,"days":59,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":0,"days":43,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":21,"heat_fp":0,"days":29,"heat_now_fp":"0","pow":"1569957","price_fp":"6279828","buyback_fp":"5023862","buy":"7","sell":"5","commission":"18"},{"good":"glass","stock":14,"heat_fp":28000000,"days":51,"heat_now_fp":"0","pow":"2085221","price_fp":"16681768","buyback_fp":"13345414","buy":"17","sell":"13","commission":"25"},{"good":"reed","stock":13,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"2196247","price_fp":"8784988","buyback_fp":"7027990","buy":"9","sell":"7","commission":"26"},{"good":"glass","stock":2,"heat_fp":37000000,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":3,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":12,"heat_fp":0,"days":41,"heat_now_fp":"0","pow":"2322815","price_fp":"18582520","buyback_fp":"14866016","buy":"19","sell":"14","commission":"27"},{"good":"reed","stock":119,"heat_fp":1321856277,"days":28,"heat_now_fp":"4","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":178,"heat_fp":0,"days":13,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":59,"heat_fp":1724531132,"days":0,"heat_now_fp":"1724531132","pow":"761806","price_fp":"22753594","buyback_fp":"18202875","buy":"23","sell":"18","commission":"36"},{"good":"glass","stock":87,"heat_fp":5000000,"days":3,"heat_now_fp":"625000","pow":"580467","price_fp":"4654616","buyback_fp":"3723692","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":81752,"heat_fp":1000000,"days":31,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":328,"heat_fp":20000000,"days":11,"heat_now_fp":"9765","pow":"500000","price_fp":"4000144","buyback_fp":"3200115","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":882094558,"days":8,"heat_now_fp":"3445681","pow":"3000000","price_fp":"12155052","buyback_fp":"9724041","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":0,"heat_fp":35000000,"days":45,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":49,"heat_fp":914517441,"days":11,"heat_now_fp":"446541","pow":"867569","price_fp":"3476085","buyback_fp":"2780868","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":23,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"1473099","price_fp":"11784792","buyback_fp":"9427833","buy":"12","sell":"9","commission":"17"},{"good":"reed","stock":278,"heat_fp":44000000,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":575087,"heat_fp":37000000,"days":34,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":146347,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":171,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":34,"heat_fp":893492905,"days":11,"heat_now_fp":"436275","pow":"1120485","price_fp":"4489267","buyback_fp":"3591413","buy":"5","sell":"3","commission":"13"},{"good":"glass","stock":13,"heat_fp":1729825806,"days":9,"heat_now_fp":"3378566","pow":"2196247","price_fp":"17792570","buyback_fp":"14234056","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":46,"heat_fp":16000000,"days":62,"heat_now_fp":"0","pow":"906798","price_fp":"3627192","buyback_fp":"2901753","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":14,"heat_fp":0,"days":47,"heat_now_fp":"0","pow":"2085221","price_fp":"16681768","buyback_fp":"13345414","buy":"17","sell":"13","commission":"25"},{"good":"reed","stock":4,"heat_fp":397196081,"days":16,"heat_now_fp":"6060","pow":"3000000","price_fp":"12000264","buyback_fp":"9600211","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":298,"heat_fp":22000000,"days":27,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":955529,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":32,"heat_fp":9000000,"days":65,"heat_now_fp":"0","pow":"1169058","price_fp":"9352464","buyback_fp":"7481971","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":27,"heat_fp":597119330,"days":33,"heat_now_fp":"0","pow":"1316700","price_fp":"5266800","buyback_fp":"4213440","buy":"6","sell":"4","commission":"15"},{"good":"glass","stock":36,"heat_fp":336260031,"days":28,"heat_now_fp":"1","pow":"1076538","price_fp":"8612304","buyback_fp":"6889843","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":50,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"855387","price_fp":"3421548","buyback_fp":"2737238","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":1,"heat_fp":817812009,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":3,"heat_fp":68000000,"days":1,"heat_now_fp":"34000000","pow":"3000000","price_fp":"13530000","buyback_fp":"10824000","buy":"14","sell":"10","commission":"36"},{"good":"glass","stock":186005,"heat_fp":0,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":207,"heat_fp":49000000,"days":51,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":4000000,"days":4,"heat_now_fp":"250000","pow":"3000000","price_fp":"24022488","buyback_fp":"19217990","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":13,"heat_fp":0,"days":18,"heat_now_fp":"0","pow":"2196247","price_fp":"8784988","buyback_fp":"7027990","buy":"9","sell":"7","commission":"26"},{"good":"glass","stock":328,"heat_fp":61000000,"days":21,"heat_now_fp":"29","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":949103,"heat_fp":0,"days":49,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":101,"heat_fp":1832217261,"days":38,"heat_now_fp":"0","pow":"522896","price_fp":"4183168","buyback_fp":"3346534","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":26000000,"days":19,"heat_now_fp":"49","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":44,"heat_fp":6000000,"days":63,"heat_now_fp":"0","pow":"935458","price_fp":"7483664","buyback_fp":"5986931","buy":"8","sell":"5","commission":"11"},{"good":"reed","stock":644741,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":0,"days":1,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":198169,"heat_fp":18000000,"days":39,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":227558,"heat_fp":0,"days":2,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":835781,"heat_fp":343839850,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":332,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":714008,"heat_fp":679746518,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":201303,"heat_fp":0,"days":56,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":37000000,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":644947197,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":27,"heat_fp":14000000,"days":2,"heat_now_fp":"3500000","pow":"1316700","price_fp":"10671853","buyback_fp":"8537482","buy":"11","sell":"8","commission":"16"},{"good":"reed","stock":47,"heat_fp":1391319946,"days":55,"heat_now_fp":"0","pow":"893248","price_fp":"3572992","buyback_fp":"2858393","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":35,"heat_fp":341295168,"days":4,"heat_now_fp":"21330948","pow":"1097978","price_fp":"9486442","buyback_fp":"7589153","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":45,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"920857","price_fp":"3683428","buyback_fp":"2946742","buy":"4","sell":"2","commission":"11"},{"good":"glass","stock":167,"heat_fp":1051162319,"days":50,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":172933075,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":13,"heat_fp":34000000,"days":58,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":378,"heat_fp":402388471,"days":47,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":183,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":26,"heat_fp":38000000,"days":65,"heat_now_fp":"0","pow":"1351948","price_fp":"5407792","buyback_fp":"4326233","buy":"6","sell":"4","commission":"16"},{"good":"glass","stock":175,"heat_fp":0,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":79000000,"days":25,"heat_now_fp":"2","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":195,"heat_fp":0,"days":7,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":60,"heat_fp":71000000,"days":7,"heat_now_fp":"554687","pow":"752896","price_fp":"3017848","buyback_fp":"2414278","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":186,"heat_fp":0,"days":39,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":73000000,"days":57,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":215,"heat_fp":7000000,"days":24,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":215989,"heat_fp":1995800634,"days":43,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":25,"heat_fp":76000000,"days":41,"heat_now_fp":"0","pow":"1389580","price_fp":"11116640","buyback_fp":"8893312","buy":"12","sell":"8","commission":"16"},{"good":"reed","stock":40,"heat_fp":66000000,"days":19,"heat_now_fp":"125","pow":"1000000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"12"},{"good":"glass","stock":980205,"heat_fp":0,"days":34,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":141,"heat_fp":69000000,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":26,"heat_fp":1274364863,"days":15,"heat_now_fp":"38890","pow":"1351948","price_fp":"10817152","buyback_fp":"8653721","buy":"11","sell":"8","commission":"16"},{"good":"reed","stock":0,"heat_fp":1000000,"days":12,"heat_now_fp":"244","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":289150,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":294,"heat_fp":839768292,"days":12,"heat_now_fp":"205021","pow":"500000","price_fp":"2001536","buyback_fp":"1601228","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":19,"heat_fp":79000000,"days":46,"heat_now_fp":"0","pow":"1683892","price_fp":"13471136","buyback_fp":"10776908","buy":"14","sell":"10","commission":"20"},{"good":"reed","stock":210,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":334,"heat_fp":0,"days":63,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":136,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":18000000,"days":69,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":9,"heat_fp":919539825,"days":14,"heat_now_fp":"56124","pow":"2841004","price_fp":"11366402","buyback_fp":"9093121","buy":"12","sell":"9","commission":"34"},{"good":"glass","stock":0,"heat_fp":0,"days":26,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":34000000,"days":23,"heat_now_fp":"4","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":362044,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":214,"heat_fp":365121578,"days":7,"heat_now_fp":"2852512","pow":"500000","price_fp":"2021392","buyback_fp":"1617113","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":52000000,"days":47,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":270,"heat_fp":44000000,"days":34,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":113,"heat_fp":40000000,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":11899,"heat_fp":0,"days":7,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":12,"heat_fp":0,"days":69,"heat_now_fp":"0","pow":"2322815","price_fp":"9291260","buyback_fp":"7433008","buy":"10","sell":"7","commission":"27"},{"good":"glass","stock":453070,"heat_fp":793126712,"days":21,"heat_now_fp":"378","pow":"500000","price_fp":"4000004","buyback_fp":"3200003","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":953365,"heat_fp":35000000,"days":9,"heat_now_fp":"68359","pow":"500000","price_fp":"2000512","buyback_fp":"1600409","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":588464,"heat_fp":496133532,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":307038872,"days":36,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":4,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":56,"heat_fp":0,"days":59,"heat_now_fp":"0","pow":"790149","price_fp":"3160596","buyback_fp":"2528476","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":1,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":3,"heat_fp":55000000,"days":44,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":15,"heat_fp":5000000,"days":48,"heat_now_fp":"0","pow":"1986907","price_fp":"15895256","buyback_fp":"12716204","buy":"16","sell":"12","commission":"23"},{"good":"reed","stock":12,"heat_fp":0,"days":49,"heat_now_fp":"0","pow":"2322815","price_fp":"9291260","buyback_fp":"7433008","buy":"10","sell":"7","commission":"27"},{"good":"glass","stock":43,"heat_fp":203748498,"days":1,"heat_now_fp":"101874249","pow":"950634","price_fp":"10510422","buyback_fp":"8408337","buy":"11","sell":"8","commission":"15"},{"good":"reed","stock":989515,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":395418,"heat_fp":0,"days":31,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":566001,"heat_fp":49000000,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":18594,"heat_fp":30000000,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":309,"heat_fp":18000000,"days":57,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":390,"heat_fp":0,"days":26,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":46,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"906798","price_fp":"7254384","buyback_fp":"5803507","buy":"8","sell":"5","commission":"10"},{"good":"reed","stock":80739,"heat_fp":67000000,"days":38,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":1075743888,"days":22,"heat_now_fp":"256","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":4,"heat_fp":1944036432,"days":54,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":306,"heat_fp":0,"days":48,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":112,"heat_fp":27000000,"days":57,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":0,"heat_fp":1020858069,"days":52,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":380,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":322344792,"days":46,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":354502,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":3000000,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":3,"heat_fp":74000000,"days":7,"heat_now_fp":"578125","pow":"3000000","price_fp":"12026004","buyback_fp":"9620803","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":958813,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":341,"heat_fp":1006246930,"days":20,"heat_now_fp":"959","pow":"500000","price_fp":"2000006","buyback_fp":"1600004","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":39,"heat_fp":0,"days":17,"heat_now_fp":"0","pow":"1017879","price_fp":"8143032","buyback_fp":"6514425","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":3,"heat_fp":0,"days":65,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":441755,"heat_fp":0,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":285,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":783023,"heat_fp":126148422,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":18,"heat_fp":75000000,"days":17,"heat_now_fp":"572","pow":"1748842","price_fp":"6995381","buyback_fp":"5596304","buy":"7","sell":"5","commission":"20"},{"good":"glass","stock":24,"heat_fp":54000000,"days":20,"heat_now_fp":"51","pow":"1429861","price_fp":"11438888","buyback_fp":"9151110","buy":"12","sell":"9","commission":"17"},{"good":"reed","stock":725457,"heat_fp":958767984,"days":15,"heat_now_fp":"29259","pow":"500000","price_fp":"2000218","buyback_fp":"1600174","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":56000000,"days":51,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":398628,"heat_fp":1454216365,"days":5,"heat_now_fp":"45444261","pow":"500000","price_fp":"2340830","buyback_fp":"1872664","buy":"3","sell":"1","commission":"7"},{"good":"glass","stock":3,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":268,"heat_fp":0,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":124,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":345,"heat_fp":0,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":478941,"heat_fp":0,"days":34,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":222,"heat_fp":556137264,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":51,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"843611","price_fp":"3374444","buyback_fp":"2699555","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":355771,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":851303538,"days":53,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":798138,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":42,"heat_fp":1000000,"days":60,"heat_now_fp":"0","pow":"966422","price_fp":"3865688","buyback_fp":"3092550","buy":"4","sell":"3","commission":"11"},{"good":"glass","stock":15,"heat_fp":28000000,"days":18,"heat_now_fp":"106","pow":"1986907","price_fp":"15895256","buyback_fp":"12716204","buy":"16","sell":"12","commission":"23"},{"good":"reed","stock":25,"heat_fp":13000000,"days":62,"heat_now_fp":"0","pow":"1389580","price_fp":"5558320","buyback_fp":"4446656","buy":"6","sell":"4","commission":"16"},{"good":"glass","stock":311,"heat_fp":85488340,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":335370,"heat_fp":950241348,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":22,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"1519657","price_fp":"12157256","buyback_fp":"9725804","buy":"13","sell":"9","commission":"18"},{"good":"reed","stock":15,"heat_fp":22000000,"days":30,"heat_now_fp":"0","pow":"1986907","price_fp":"7947628","buyback_fp":"6358102","buy":"8","sell":"6","commission":"23"},{"good":"glass","stock":730374,"heat_fp":74000000,"days":46,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":55000000,"days":3,"heat_now_fp":"6875000","pow":"3000000","price_fp":"12309372","buyback_fp":"9847497","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":16,"heat_fp":63000000,"days":58,"heat_now_fp":"0","pow":"1899142","price_fp":"15193136","buyback_fp":"12154508","buy":"16","sell":"12","commission":"22"},{"good":"reed","stock":4,"heat_fp":1353366479,"days":13,"heat_now_fp":"165205","pow":"3000000","price_fp":"12007428","buyback_fp":"9605942","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":537162,"heat_fp":648572884,"days":19,"heat_now_fp":"1237","pow":"500000","price_fp":"4000016","buyback_fp":"3200012","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":57,"heat_fp":0,"days":59,"heat_now_fp":"0","pow":"780421","price_fp":"3121684","buyback_fp":"2497347","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":1,"heat_fp":31000000,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":31,"heat_fp":209776056,"days":0,"heat_now_fp":"209776056","pow":"1195331","price_fp":"8542600","buyback_fp":"6834080","buy":"9","sell":"6","commission":"25"},{"good":"glass","stock":576632,"heat_fp":0,"days":1,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":58,"heat_fp":20000000,"days":19,"heat_now_fp":"38","pow":"770977","price_fp":"3083908","buyback_fp":"2467126","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":686907,"heat_fp":0,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":243,"heat_fp":158337729,"days":18,"heat_now_fp":"604","pow":"500000","price_fp":"2000004","buyback_fp":"1600003","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":22,"heat_fp":1997330964,"days":13,"heat_now_fp":"243814","pow":"1519657","price_fp":"12168367","buyback_fp":"9734693","buy":"13","sell":"9","commission":"18"},{"good":"reed","stock":3,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":369,"heat_fp":69000000,"days":25,"heat_now_fp":"2","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":23000000,"days":8,"heat_now_fp":"89843","pow":"3000000","price_fp":"12004032","buyback_fp":"9603225","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":34,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"1120485","price_fp":"8963880","buyback_fp":"7171104","buy":"9","sell":"7","commission":"13"},{"good":"reed","stock":4,"heat_fp":1983754084,"days":67,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":4,"heat_fp":0,"days":38,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":133,"heat_fp":43000000,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":1296828078,"days":13,"heat_now_fp":"158304","pow":"3000000","price_fp":"24014232","buyback_fp":"19211385","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":821941,"heat_fp":75000000,"days":30,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":57,"heat_fp":832420049,"days":41,"heat_now_fp":"0","pow":"780421","price_fp":"6243368","buyback_fp":"4994694","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":30,"heat_fp":12000000,"days":13,"heat_now_fp":"1464","pow":"1223084","price_fp":"4892360","buyback_fp":"3913888","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":322,"heat_fp":2027331399,"days":47,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":21000000,"days":62,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":482552,"heat_fp":0,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":35,"heat_fp":65000000,"days":32,"heat_now_fp":"0","pow":"1097978","price_fp":"4391912","buyback_fp":"3513529","buy":"5","sell":"3","commission":"13"},{"good":"glass","stock":689543,"heat_fp":0,"days":13,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":258,"heat_fp":1515494395,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":715384,"heat_fp":1000000,"days":48,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":679291,"heat_fp":172909037,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":117396,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":63,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"727616","price_fp":"2910464","buyback_fp":"2328371","buy":"3","sell":"2","commission":"8"},{"good":"glass","stock":63,"heat_fp":565967965,"days":50,"heat_now_fp":"0","pow":"727616","price_fp":"5820928","buyback_fp":"4656742","buy":"6","sell":"4","commission":"8"},{"good":"reed","stock":45,"heat_fp":0,"days":13,"heat_now_fp":"0","pow":"920857","price_fp":"3683428","buyback_fp":"2946742","buy":"4","sell":"2","commission":"11"},{"good":"glass","stock":2,"heat_fp":2000000,"days":38,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":343,"heat_fp":279835750,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":53,"heat_fp":438684995,"days":45,"heat_now_fp":"0","pow":"821197","price_fp":"6569576","buyback_fp":"5255660","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":663513,"heat_fp":1560460313,"days":27,"heat_now_fp":"11","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":152,"heat_fp":4000000,"days":62,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":58,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"770977","price_fp":"3083908","buyback_fp":"2467126","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":111,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":50,"heat_fp":0,"days":3,"heat_now_fp":"0","pow":"855387","price_fp":"3421548","buyback_fp":"2737238","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":171,"heat_fp":1146891896,"days":56,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":183463,"heat_fp":0,"days":22,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":18,"heat_fp":0,"days":65,"heat_now_fp":"0","pow":"1748842","price_fp":"13990736","buyback_fp":"11192588","buy":"14","sell":"11","commission":"20"},{"good":"reed","stock":340541,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":23,"heat_fp":261837082,"days":2,"heat_now_fp":"65459270","pow":"1473099","price_fp":"14677628","buyback_fp":"11742102","buy":"15","sell":"11","commission":"22"},{"good":"reed","stock":7,"heat_fp":46000000,"days":52,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":280,"heat_fp":14000000,"days":13,"heat_now_fp":"1708","pow":"500000","price_fp":"4000024","buyback_fp":"3200019","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":42,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":42,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"966422","price_fp":"7731376","buyback_fp":"6185100","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":671794,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":15,"heat_fp":0,"days":25,"heat_now_fp":"0","pow":"1986907","price_fp":"15895256","buyback_fp":"12716204","buy":"16","sell":"12","commission":"23"},{"good":"reed","stock":820652,"heat_fp":41000000,"days":15,"heat_now_fp":"1251","pow":"500000","price_fp":"2000008","buyback_fp":"1600006","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":9,"heat_fp":0,"days":2,"heat_now_fp":"0","pow":"2841004","price_fp":"22728032","buyback_fp":"18182425","buy":"23","sell":"18","commission":"34"},{"good":"reed","stock":205855,"heat_fp":1288041560,"days":15,"heat_now_fp":"39307","pow":"500000","price_fp":"2000294","buyback_fp":"1600235","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":39,"heat_fp":69000000,"days":44,"heat_now_fp":"0","pow":"1017879","price_fp":"8143032","buyback_fp":"6514425","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":517949,"heat_fp":55000000,"days":16,"heat_now_fp":"839","pow":"500000","price_fp":"2000006","buyback_fp":"1600004","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":192144,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":49,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"867569","price_fp":"3470276","buyback_fp":"2776220","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":13,"heat_fp":2105097700,"days":57,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":3,"heat_fp":46000000,"days":69,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":49,"heat_fp":500992290,"days":28,"heat_now_fp":"1","pow":"867569","price_fp":"6940552","buyback_fp":"5552441","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":317,"heat_fp":1219915763,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":25,"heat_fp":489599129,"days":3,"heat_now_fp":"61199891","pow":"1389580","price_fp":"13667897","buyback_fp":"10934317","buy":"14","sell":"10","commission":"20"},{"good":"reed","stock":2,"heat_fp":214864509,"days":65,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":297,"heat_fp":0,"days":2,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":329,"heat_fp":47000000,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":52,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"832220","price_fp":"6657760","buyback_fp":"5326208","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":2,"heat_fp":3000000,"days":30,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":0,"days":0,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":4,"heat_fp":572965716,"days":48,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":63,"heat_fp":1945959916,"days":40,"heat_now_fp":"0","pow":"727616","price_fp":"5820928","buyback_fp":"4656742","buy":"6","sell":"4","commission":"8"},{"good":"reed","stock":3,"heat_fp":436007773,"days":31,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":18,"heat_fp":57000000,"days":36,"heat_now_fp":"0","pow":"1748842","price_fp":"13990736","buyback_fp":"11192588","buy":"14","sell":"11","commission":"20"},{"good":"reed","stock":136465,"heat_fp":2101176878,"days":57,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":126,"heat_fp":10000000,"days":57,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":478524,"heat_fp":1985748478,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":54,"heat_fp":0,"days":46,"heat_now_fp":"0","pow":"810523","price_fp":"6484184","buyback_fp":"5187347","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":459156,"heat_fp":32000000,"days":29,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":285020,"heat_fp":1912986136,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":46,"heat_fp":1820311253,"days":18,"heat_now_fp":"6943","pow":"906798","price_fp":"3627282","buyback_fp":"2901825","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":2,"heat_fp":0,"days":33,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":1643652233,"days":1,"heat_now_fp":"821826116","pow":"3000000","price_fp":"48982164","buyback_fp":"39185731","buy":"49","sell":"39","commission":"36"},{"good":"glass","stock":367193,"heat_fp":329175404,"days":18,"heat_now_fp":"1255","pow":"500000","price_fp":"4000016","buyback_fp":"3200012","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":13346,"heat_fp":0,"days":4,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":76000000,"days":26,"heat_now_fp":"1","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":261,"heat_fp":1727705647,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":54,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"810523","price_fp":"6484184","buyback_fp":"5187347","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":3,"heat_fp":0,"days":52,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":876946,"heat_fp":390387039,"days":59,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":1012539595,"days":30,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":154,"heat_fp":2101726697,"days":39,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":132,"heat_fp":274769593,"days":16,"heat_now_fp":"4192","pow":"500000","price_fp":"2000030","buyback_fp":"1600024","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":61,"heat_fp":2103256420,"days":47,"heat_now_fp":"0","pow":"744235","price_fp":"5953880","buyback_fp":"4763104","buy":"6","sell":"4","commission":"8"},{"good":"reed","stock":334,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":23,"heat_fp":0,"days":39,"heat_now_fp":"0","pow":"1473099","price_fp":"11784792","buyback_fp":"9427833","buy":"12","sell":"9","commission":"17"},{"good":"reed","stock":847085,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":165,"heat_fp":0,"days":10,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":40000000,"days":12,"heat_now_fp":"9765","pow":"3000000","price_fp":"12000432","buyback_fp":"9600345","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":97,"heat_fp":1883282031,"days":44,"heat_now_fp":"0","pow":"537899","price_fp":"4303192","buyback_fp":"3442553","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":840046,"heat_fp":674964018,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":330162,"heat_fp":1569274081,"days":55,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":189,"heat_fp":672569308,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":611259,"heat_fp":15000000,"days":31,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":380076593,"days":3,"heat_now_fp":"47509574","pow":"3000000","price_fp":"14137920","buyback_fp":"11310336","buy":"15","sell":"11","commission":"36"},{"good":"glass","stock":2,"heat_fp":1769865885,"days":30,"heat_now_fp":"1","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":796557,"heat_fp":0,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":551424,"heat_fp":29000000,"days":50,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":59,"heat_fp":1889369824,"days":65,"heat_now_fp":"0","pow":"761806","price_fp":"3047224","buyback_fp":"2437779","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":59,"heat_fp":1559568801,"days":2,"heat_now_fp":"389892200","pow":"761806","price_fp":"15005109","buyback_fp":"12004087","buy":"16","sell":"12","commission":"22"},{"good":"reed","stock":3,"heat_fp":958938208,"days":22,"heat_now_fp":"228","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":357,"heat_fp":1403944271,"days":59,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":958659,"heat_fp":67000000,"days":65,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":227,"heat_fp":37000000,"days":47,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":32,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"1169058","price_fp":"9352464","buyback_fp":"7481971","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":4,"heat_fp":0,"days":66,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":176,"heat_fp":0,"days":1,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":177140,"heat_fp":50112215,"days":27,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":273,"heat_fp":2000000,"days":24,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":44000000,"days":21,"heat_now_fp":"20","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":695748,"heat_fp":399744974,"days":48,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":367251360,"days":4,"heat_now_fp":"22953210","pow":"3000000","price_fp":"13032888","buyback_fp":"10426310","buy":"14","sell":"10","commission":"36"},{"good":"glass","stock":1,"heat_fp":1526921632,"days":37,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":51,"heat_fp":48000000,"days":36,"heat_now_fp":"0","pow":"843611","price_fp":"3374444","buyback_fp":"2699555","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":3,"heat_fp":1239409259,"days":5,"heat_now_fp":"38731539","pow":"3000000","price_fp":"27485832","buyback_fp":"21988665","buy":"28","sell":"21","commission":"36"},{"good":"reed","stock":17,"heat_fp":1692591081,"days":32,"heat_now_fp":"0","pow":"1820233","price_fp":"7280932","buyback_fp":"5824745","buy":"8","sell":"5","commission":"21"},{"good":"glass","stock":931145,"heat_fp":0,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":829040809,"days":5,"heat_now_fp":"25907525","pow":"3000000","price_fp":"13165836","buyback_fp":"10532668","buy":"14","sell":"10","commission":"36"},{"good":"glass","stock":9,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"2841004","price_fp":"22728032","buyback_fp":"18182425","buy":"23","sell":"18","commission":"34"},{"good":"reed","stock":117,"heat_fp":10000000,"days":38,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":551143,"heat_fp":1066066527,"days":38,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":1066350191,"days":18,"heat_now_fp":"4067","pow":"3000000","price_fp":"12000180","buyback_fp":"9600144","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":315,"heat_fp":2096607375,"days":28,"heat_now_fp":"7","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":62,"heat_fp":0,"days":28,"heat_now_fp":"0","pow":"735812","price_fp":"2943248","buyback_fp":"2354598","buy":"3","sell":"2","commission":"8"},{"good":"glass","stock":44,"heat_fp":23000000,"days":46,"heat_now_fp":"0","pow":"935458","price_fp":"7483664","buyback_fp":"5986931","buy":"8","sell":"5","commission":"11"},{"good":"reed","stock":995828,"heat_fp":388372528,"days":11,"heat_now_fp":"189635","pow":"500000","price_fp":"2001422","buyback_fp":"1601137","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":833610823,"days":42,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":0,"days":67,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":288,"heat_fp":0,"days":65,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":29,"heat_fp":44000000,"days":64,"heat_now_fp":"0","pow":"1252458","price_fp":"10019664","buyback_fp":"8015731","buy":"11","sell":"8","commission":"15"},{"good":"reed","stock":0,"heat_fp":79000000,"days":39,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":295,"heat_fp":1944426160,"days":7,"heat_now_fp":"15190829","pow":"500000","price_fp":"4227860","buyback_fp":"3382288","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":36,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"1076538","price_fp":"4306152","buyback_fp":"3444921","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":214570,"heat_fp":63000000,"days":49,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":52,"heat_fp":21000000,"days":50,"heat_now_fp":"0","pow":"832220","price_fp":"3328880","buyback_fp":"2663104","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":2,"heat_fp":20000000,"days":28,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":852975,"heat_fp":0,"days":14,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":6,"heat_fp":0,"days":38,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":4,"heat_fp":0,"days":7,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":645571,"heat_fp":49000000,"days":11,"heat_now_fp":"23925","pow":"500000","price_fp":"4000356","buyback_fp":"3200284","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":1449787123,"days":8,"heat_now_fp":"5663230","pow":"3000000","price_fp":"12254844","buyback_fp":"9803875","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":53,"heat_fp":291277358,"days":6,"heat_now_fp":"4551208","pow":"821197","price_fp":"6681698","buyback_fp":"5345358","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":3,"heat_fp":35000000,"days":19,"heat_now_fp":"66","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":20,"heat_fp":32000000,"days":4,"heat_now_fp":"2000000","pow":"1624503","price_fp":"13093494","buyback_fp":"10474795","buy":"14","sell":"10","commission":"19"},{"good":"reed","stock":4,"heat_fp":0,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":36222,"heat_fp":562254036,"days":6,"heat_now_fp":"8785219","pow":"500000","price_fp":"4131776","buyback_fp":"3305420","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":21,"heat_fp":0,"days":45,"heat_now_fp":"0","pow":"1569957","price_fp":"6279828","buyback_fp":"5023862","buy":"7","sell":"5","commission":"18"},{"good":"glass","stock":2,"heat_fp":1590074262,"days":11,"heat_now_fp":"776403","pow":"3000000","price_fp":"24069864","buyback_fp":"19255891","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":118,"heat_fp":63000000,"days":0,"heat_now_fp":"63000000","pow":"500000","price_fp":"4945000","buyback_fp":"3956000","buy":"5","sell":"3","commission":"7"},{"good":"reed","stock":320,"heat_fp":1234104161,"days":7,"heat_now_fp":"9641438","pow":"500000","price_fp":"2072310","buyback_fp":"1657848","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":55,"heat_fp":0,"days":24,"heat_now_fp":"0","pow":"800178","price_fp":"6401424","buyback_fp":"5121139","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":16,"heat_fp":317953106,"days":2,"heat_now_fp":"79488276","pow":"1899142","price_fp":"9860952","buyback_fp":"7888761","buy":"10","sell":"7","commission":"29"},{"good":"glass","stock":2,"heat_fp":426695595,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":50,"heat_fp":560996287,"days":21,"heat_now_fp":"267","pow":"855387","price_fp":"3421548","buyback_fp":"2737238","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":140,"heat_fp":1659229206,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":481212,"heat_fp":31000000,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":652396,"heat_fp":0,"days":47,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":252,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":998779,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":29000000,"days":31,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":657897740,"days":1,"heat_now_fp":"328948870","pow":"3000000","price_fp":"53605392","buyback_fp":"42884313","buy":"54","sell":"42","commission":"36"},{"good":"reed","stock":578432,"heat_fp":25000000,"days":46,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":852116,"heat_fp":156839879,"days":66,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":456312,"heat_fp":0,"days":10,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":164,"heat_fp":921330525,"days":20,"heat_now_fp":"878","pow":"500000","price_fp":"4000012","buyback_fp":"3200009","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":839699,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":1727413708,"days":60,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":76000000,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":131207559,"days":19,"heat_now_fp":"250","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":3,"heat_fp":0,"days":7,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":282878,"heat_fp":1864668374,"days":26,"heat_now_fp":"27","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":760317,"heat_fp":10932242,"days":8,"heat_now_fp":"42704","pow":"500000","price_fp":"2000320","buyback_fp":"1600256","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":343,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":782811,"heat_fp":0,"days":4,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":8000000,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":3,"heat_fp":544787823,"days":11,"heat_now_fp":"266009","pow":"3000000","price_fp":"12011964","buyback_fp":"9609571","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":95,"heat_fp":17000000,"days":13,"heat_now_fp":"2075","pow":"545801","price_fp":"4366438","buyback_fp":"3493150","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":28000000,"days":20,"heat_now_fp":"26","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":36,"heat_fp":27000000,"days":31,"heat_now_fp":"0","pow":"1076538","price_fp":"8612304","buyback_fp":"6889843","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":3,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":258,"heat_fp":0,"days":10,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":56,"heat_fp":154610728,"days":8,"heat_now_fp":"603948","pow":"790149","price_fp":"3167751","buyback_fp":"2534200","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":60563,"heat_fp":51000000,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":28,"heat_fp":2030141596,"days":58,"heat_now_fp":"0","pow":"1283603","price_fp":"5134412","buyback_fp":"4107529","buy":"6","sell":"4","commission":"15"},{"good":"glass","stock":13,"heat_fp":583453138,"days":51,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":24,"heat_fp":26000000,"days":18,"heat_now_fp":"99","pow":"1429861","price_fp":"5719444","buyback_fp":"4575555","buy":"6","sell":"4","commission":"17"},{"good":"glass","stock":4,"heat_fp":0,"days":44,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":307,"heat_fp":43000000,"days":48,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":10000000,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":292,"heat_fp":4000000,"days":49,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":99,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"530269","price_fp":"4242152","buyback_fp":"3393721","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":24,"heat_fp":74000000,"days":21,"heat_now_fp":"35","pow":"1429861","price_fp":"5719444","buyback_fp":"4575555","buy":"6","sell":"4","commission":"17"},{"good":"glass","stock":16,"heat_fp":27000000,"days":49,"heat_now_fp":"0","pow":"1899142","price_fp":"15193136","buyback_fp":"12154508","buy":"16","sell":"12","commission":"22"},{"good":"reed","stock":31,"heat_fp":12000000,"days":45,"heat_now_fp":"0","pow":"1195331","price_fp":"4781324","buyback_fp":"3825059","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":56,"heat_fp":10000000,"days":25,"heat_now_fp":"0","pow":"790149","price_fp":"6321192","buyback_fp":"5056953","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":1,"heat_fp":32000000,"days":66,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":880514,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":48,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"880181","price_fp":"3520724","buyback_fp":"2816579","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":558866,"heat_fp":10000000,"days":18,"heat_now_fp":"38","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":283356,"heat_fp":693419006,"days":3,"heat_now_fp":"86677375","pow":"500000","price_fp":"2650080","buyback_fp":"2120064","buy":"3","sell":"2","commission":"7"},{"good":"glass","stock":218,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":191226,"heat_fp":2094411361,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":0,"days":1,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":71,"heat_fp":0,"days":19,"heat_now_fp":"0","pow":"669206","price_fp":"2676824","buyback_fp":"2141459","buy":"3","sell":"2","commission":"8"},{"good":"glass","stock":387,"heat_fp":51000000,"days":38,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":730900,"heat_fp":545860211,"days":14,"heat_now_fp":"33316","pow":"500000","price_fp":"2000248","buyback_fp":"1600198","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":38,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"1036556","price_fp":"8292448","buyback_fp":"6633958","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":83524,"heat_fp":24000000,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":11000000,"days":4,"heat_now_fp":"687500","pow":"3000000","price_fp":"24061872","buyback_fp":"19249497","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":7,"heat_fp":0,"days":49,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":628764,"heat_fp":640630229,"days":19,"heat_now_fp":"1221","pow":"500000","price_fp":"4000016","buyback_fp":"3200012","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":552023,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":907254,"heat_fp":20000000,"days":66,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":51,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":2,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":36,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"1076538","price_fp":"4306152","buyback_fp":"3444921","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":0,"heat_fp":38000000,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":0,"days":22,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":599209,"heat_fp":2050847054,"days":20,"heat_now_fp":"1955","pow":"500000","price_fp":"4000028","buyback_fp":"3200022","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":347997,"heat_fp":1698466469,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":351,"heat_fp":0,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":13,"heat_fp":61000000,"days":36,"heat_now_fp":"0","pow":"2196247","price_fp":"8784988","buyback_fp":"7027990","buy":"9","sell":"7","commission":"26"},{"good":"glass","stock":59,"heat_fp":710447513,"days":19,"heat_now_fp":"1355","pow":"761806","price_fp":"6094472","buyback_fp":"4875577","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":258,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":49000000,"days":2,"heat_now_fp":"12250000","pow":"3000000","price_fp":"25102488","buyback_fp":"20081990","buy":"26","sell":"20","commission":"36"},{"good":"reed","stock":58,"heat_fp":62365577,"days":11,"heat_now_fp":"30451","pow":"770977","price_fp":"3084259","buyback_fp":"2467407","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":36,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"1076538","price_fp":"8612304","buyback_fp":"6889843","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":31,"heat_fp":1317551861,"days":10,"heat_now_fp":"1286671","pow":"1195331","price_fp":"4804389","buyback_fp":"3843511","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":0,"heat_fp":0,"days":2,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":71000000,"days":30,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":55,"heat_fp":72000000,"days":3,"heat_now_fp":"9000000","pow":"800178","price_fp":"6617472","buyback_fp":"5293977","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":1,"heat_fp":54000000,"days":41,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":2,"heat_fp":2012206188,"days":35,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":50000000,"days":59,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":270536,"heat_fp":3000000,"days":52,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":767418,"heat_fp":78000000,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":15,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"1986907","price_fp":"15895256","buyback_fp":"12716204","buy":"16","sell":"12","commission":"23"},{"good":"reed","stock":0,"heat_fp":1315681486,"days":27,"heat_now_fp":"9","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":884332,"heat_fp":28000000,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":577472,"heat_fp":2013183244,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":55,"heat_fp":0,"days":22,"heat_now_fp":"0","pow":"800178","price_fp":"6401424","buyback_fp":"5121139","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":111,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":784554,"heat_fp":74000000,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":240,"heat_fp":1865160424,"days":10,"heat_now_fp":"1821445","pow":"500000","price_fp":"2013660","buyback_fp":"1610928","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":910451,"heat_fp":19000000,"days":16,"heat_now_fp":"289","pow":"500000","price_fp":"4000004","buyback_fp":"3200003","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":36000000,"days":40,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":713582,"heat_fp":1952733941,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":1138122661,"days":60,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":79,"heat_fp":66000000,"days":31,"heat_now_fp":"0","pow":"621015","price_fp":"4968120","buyback_fp":"3974496","buy":"5","sell":"3","commission":"7"},{"good":"reed","stock":4,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":371124,"heat_fp":1228115502,"days":39,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":913079,"heat_fp":1679816298,"days":25,"heat_now_fp":"50","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":451177795,"days":8,"heat_now_fp":"1762413","pow":"3000000","price_fp":"24158616","buyback_fp":"19326892","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":759701,"heat_fp":509427720,"days":5,"heat_now_fp":"15919616","pow":"500000","price_fp":"2119396","buyback_fp":"1695516","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":317,"heat_fp":1775714339,"days":12,"heat_now_fp":"433524","pow":"500000","price_fp":"4006500","buyback_fp":"3205200","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":392204,"heat_fp":76000000,"days":27,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":56,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"790149","price_fp":"6321192","buyback_fp":"5056953","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":0,"heat_fp":1835994741,"days":25,"heat_now_fp":"54","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":391,"heat_fp":15000000,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":414932,"heat_fp":383814017,"days":52,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":19,"heat_fp":14000000,"days":51,"heat_now_fp":"0","pow":"1683892","price_fp":"13471136","buyback_fp":"10776908","buy":"14","sell":"10","commission":"20"},{"good":"reed","stock":30,"heat_fp":0,"days":28,"heat_now_fp":"0","pow":"1223084","price_fp":"4892336","buyback_fp":"3913868","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":308,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":198621,"heat_fp":33000000,"days":23,"heat_now_fp":"3","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":768443,"heat_fp":33000000,"days":10,"heat_now_fp":"32226","pow":"500000","price_fp":"4000480","buyback_fp":"3200384","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":447623,"heat_fp":20000000,"days":28,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":9000000,"days":68,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":29,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"1252458","price_fp":"5009832","buyback_fp":"4007865","buy":"6","sell":"4","commission":"15"},{"good":"glass","stock":30,"heat_fp":55000000,"days":39,"heat_now_fp":"0","pow":"1223084","price_fp":"9784672","buyback_fp":"7827737","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":160,"heat_fp":658508372,"days":6,"heat_now_fp":"10289193","pow":"500000","price_fp":"2077168","buyback_fp":"1661734","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":49,"heat_fp":53000000,"days":66,"heat_now_fp":"0","pow":"867569","price_fp":"6940552","buyback_fp":"5552441","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":260,"heat_fp":1860812241,"days":50,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":19,"heat_fp":74000000,"days":30,"heat_now_fp":"0","pow":"1683892","price_fp":"13471136","buyback_fp":"10776908","buy":"14","sell":"10","commission":"20"},{"good":"reed","stock":0,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":0,"days":56,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":2,"heat_fp":1928333217,"days":24,"heat_now_fp":"114","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":6,"heat_fp":964387076,"days":49,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":37,"heat_fp":116566565,"days":65,"heat_now_fp":"0","pow":"1056088","price_fp":"4224352","buyback_fp":"3379481","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":54,"heat_fp":1302535490,"days":62,"heat_now_fp":"0","pow":"810523","price_fp":"6484184","buyback_fp":"5187347","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":28,"heat_fp":547957630,"days":34,"heat_now_fp":"0","pow":"1283603","price_fp":"5134412","buyback_fp":"4107529","buy":"6","sell":"4","commission":"15"},{"good":"glass","stock":288,"heat_fp":846294583,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":936936,"heat_fp":79000000,"days":48,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":14,"heat_fp":1397655174,"days":69,"heat_now_fp":"0","pow":"2085221","price_fp":"16681768","buyback_fp":"13345414","buy":"17","sell":"13","commission":"25"},{"good":"reed","stock":390,"heat_fp":0,"days":63,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":29,"heat_fp":30000000,"days":54,"heat_now_fp":"0","pow":"1252458","price_fp":"10019664","buyback_fp":"8015731","buy":"11","sell":"8","commission":"15"},{"good":"reed","stock":2,"heat_fp":1442845070,"days":12,"heat_now_fp":"352257","pow":"3000000","price_fp":"12015840","buyback_fp":"9612672","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":146,"heat_fp":31000000,"days":34,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":109292,"heat_fp":1128033879,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":91,"heat_fp":65000000,"days":45,"heat_now_fp":"0","pow":"562486","price_fp":"4499888","buyback_fp":"3599910","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":49,"heat_fp":1620680977,"days":6,"heat_now_fp":"25323140","pow":"867569","price_fp":"3799816","buyback_fp":"3039852","buy":"4","sell":"3","commission":"11"},{"good":"glass","stock":1,"heat_fp":1931333870,"days":53,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":42,"heat_fp":458930058,"days":63,"heat_now_fp":"0","pow":"966422","price_fp":"3865688","buyback_fp":"3092550","buy":"4","sell":"3","commission":"11"},{"good":"glass","stock":360,"heat_fp":7000000,"days":1,"heat_now_fp":"3500000","pow":"500000","price_fp":"4052500","buyback_fp":"3242000","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":21,"heat_fp":1643282933,"days":65,"heat_now_fp":"0","pow":"1569957","price_fp":"6279828","buyback_fp":"5023862","buy":"7","sell":"5","commission":"18"},{"good":"glass","stock":46,"heat_fp":71000000,"days":51,"heat_now_fp":"0","pow":"906798","price_fp":"7254384","buyback_fp":"5803507","buy":"8","sell":"5","commission":"10"},{"good":"reed","stock":0,"heat_fp":67000000,"days":39,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":230,"heat_fp":844461124,"days":27,"heat_now_fp":"6","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":30,"heat_fp":0,"days":53,"heat_now_fp":"0","pow":"1223084","price_fp":"4892336","buyback_fp":"3913868","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":290847,"heat_fp":36580468,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":52,"heat_fp":2029178818,"days":60,"heat_now_fp":"0","pow":"832220","price_fp":"3328880","buyback_fp":"2663104","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":57,"heat_fp":0,"days":52,"heat_now_fp":"0","pow":"780421","price_fp":"6243368","buyback_fp":"4994694","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":178,"heat_fp":78000000,"days":4,"heat_now_fp":"4875000","pow":"500000","price_fp":"2036562","buyback_fp":"1629249","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":135441,"heat_fp":1612308860,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":696442,"heat_fp":0,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":69000000,"days":10,"heat_now_fp":"67382","pow":"3000000","price_fp":"24006048","buyback_fp":"19204838","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":46,"heat_fp":0,"days":26,"heat_now_fp":"0","pow":"906798","price_fp":"3627192","buyback_fp":"2901753","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":989718,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":57,"heat_fp":1282248729,"days":67,"heat_now_fp":"0","pow":"780421","price_fp":"3121684","buyback_fp":"2497347","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":22,"heat_fp":1327384304,"days":38,"heat_now_fp":"0","pow":"1519657","price_fp":"12157256","buyback_fp":"9725804","buy":"13","sell":"9","commission":"18"},{"good":"reed","stock":534165,"heat_fp":1363640890,"days":3,"heat_now_fp":"170455111","pow":"500000","price_fp":"3278412","buyback_fp":"2622729","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":3,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":44,"heat_fp":76000000,"days":60,"heat_now_fp":"0","pow":"935458","price_fp":"3741832","buyback_fp":"2993465","buy":"4","sell":"2","commission":"11"},{"good":"glass","stock":51,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"843611","price_fp":"6748888","buyback_fp":"5399110","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":13,"heat_fp":0,"days":43,"heat_now_fp":"0","pow":"2196247","price_fp":"8784988","buyback_fp":"7027990","buy":"9","sell":"7","commission":"26"},{"good":"glass","stock":1,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":456969,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":8000000,"days":67,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":720539,"heat_fp":571089184,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":17,"heat_fp":0,"days":65,"heat_now_fp":"0","pow":"1820233","price_fp":"14561864","buyback_fp":"11649491","buy":"15","sell":"11","commission":"21"},{"good":"reed","stock":643999,"heat_fp":6000000,"days":16,"heat_now_fp":"91","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":730290539,"days":57,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":58,"heat_fp":0,"days":59,"heat_now_fp":"0","pow":"770977","price_fp":"3083908","buyback_fp":"2467126","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":76,"heat_fp":0,"days":27,"heat_now_fp":"0","pow":"638074","price_fp":"5104592","buyback_fp":"4083673","buy":"6","sell":"4","commission":"7"},{"good":"reed","stock":3,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":43,"heat_fp":35000000,"days":26,"heat_now_fp":"0","pow":"950634","price_fp":"7605072","buyback_fp":"6084057","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":91,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"562486","price_fp":"2249944","buyback_fp":"1799955","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":34,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"1120485","price_fp":"8963880","buyback_fp":"7171104","buy":"9","sell":"7","commission":"13"},{"good":"reed","stock":928479,"heat_fp":70000000,"days":19,"heat_now_fp":"133","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":45,"heat_fp":667583004,"days":66,"heat_now_fp":"0","pow":"920857","price_fp":"7366856","buyback_fp":"5893484","buy":"8","sell":"5","commission":"11"},{"good":"reed","stock":350615,"heat_fp":0,"days":60,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":383629,"heat_fp":1794858495,"days":29,"heat_now_fp":"3","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":63,"heat_fp":48000000,"days":8,"heat_now_fp":"187500","pow":"727616","price_fp":"2912510","buyback_fp":"2330008","buy":"3","sell":"2","commission":"8"},{"good":"glass","stock":370,"heat_fp":44000000,"days":9,"heat_now_fp":"85937","pow":"500000","price_fp":"4001288","buyback_fp":"3201030","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":184,"heat_fp":0,"days":66,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":86621226,"days":12,"heat_now_fp":"21147","pow":"3000000","price_fp":"24001896","buyback_fp":"19201516","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":49,"heat_fp":114990561,"days":13,"heat_now_fp":"14036","pow":"867569","price_fp":"3470456","buyback_fp":"2776364","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":670126,"heat_fp":0,"days":0,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":12000000,"days":65,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":2,"heat_fp":1608800159,"days":2,"heat_now_fp":"402200039","pow":"3000000","price_fp":"60198000","buyback_fp":"48158400","buy":"61","sell":"48","commission":"36"},{"good":"reed","stock":90,"heat_fp":0,"days":48,"heat_now_fp":"0","pow":"566854","price_fp":"2267416","buyback_fp":"1813932","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":537644,"heat_fp":36000000,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":23,"heat_fp":0,"days":52,"heat_now_fp":"0","pow":"1473099","price_fp":"5892396","buyback_fp":"4713916","buy":"6","sell":"4","commission":"17"},{"good":"glass","stock":307,"heat_fp":31000000,"days":16,"heat_now_fp":"473","pow":"500000","price_fp":"4000004","buyback_fp":"3200003","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":54906,"heat_fp":2062833077,"days":62,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":388120,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":397,"heat_fp":11000000,"days":40,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":1323373404,"days":57,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":380,"heat_fp":65000000,"days":50,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":29,"heat_fp":55000000,"days":60,"heat_now_fp":"0","pow":"1252458","price_fp":"10019664","buyback_fp":"8015731","buy":"11","sell":"8","commission":"15"},{"good":"reed","stock":15626,"heat_fp":54916365,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":1021731012,"days":34,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":307,"heat_fp":0,"days":19,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":669338,"heat_fp":4000000,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":22,"heat_fp":1799961389,"days":64,"heat_now_fp":"0","pow":"1519657","price_fp":"12157256","buyback_fp":"9725804","buy":"13","sell":"9","commission":"18"},{"good":"reed","stock":192622,"heat_fp":2022355567,"days":13,"heat_now_fp":"246869","pow":"500000","price_fp":"2001850","buyback_fp":"1601480","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":103,"heat_fp":986904354,"days":52,"heat_now_fp":"0","pow":"515768","price_fp":"4126144","buyback_fp":"3300915","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":769009,"heat_fp":56000000,"days":3,"heat_now_fp":"7000000","pow":"500000","price_fp":"2052500","buyback_fp":"1642000","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":565216,"heat_fp":0,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":9,"heat_fp":0,"days":37,"heat_now_fp":"0","pow":"2841004","price_fp":"11364016","buyback_fp":"9091212","buy":"12","sell":"9","commission":"34"},{"good":"glass","stock":520831,"heat_fp":0,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":19,"heat_fp":78000000,"days":37,"heat_now_fp":"0","pow":"1683892","price_fp":"6735568","buyback_fp":"5388454","buy":"7","sell":"5","commission":"20"},{"good":"glass","stock":17769,"heat_fp":0,"days":19,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":185164,"heat_fp":58000000,"days":28,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":56,"heat_fp":49000000,"days":24,"heat_now_fp":"2","pow":"790149","price_fp":"6321192","buyback_fp":"5056953","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":1,"heat_fp":55000000,"days":26,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":317,"heat_fp":0,"days":43,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":133673,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":279540,"heat_fp":71000000,"days":40,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":222,"heat_fp":0,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":5,"heat_fp":28000000,"days":20,"heat_now_fp":"26","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":2,"heat_fp":0,"days":2,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":52,"heat_fp":2100386287,"days":62,"heat_now_fp":"0","pow":"832220","price_fp":"6657760","buyback_fp":"5326208","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":414551,"heat_fp":424935418,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":10,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"2639014","price_fp":"10556056","buyback_fp":"8444844","buy":"11","sell":"8","commission":"31"},{"good":"glass","stock":37,"heat_fp":47000000,"days":33,"heat_now_fp":"0","pow":"1056088","price_fp":"8448704","buyback_fp":"6758963","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":342,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":162,"heat_fp":40000000,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":51000000,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":146,"heat_fp":1536052673,"days":17,"heat_now_fp":"11719","pow":"500000","price_fp":"4000172","buyback_fp":"3200137","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":13,"heat_fp":58000000,"days":67,"heat_now_fp":"0","pow":"2196247","price_fp":"8784988","buyback_fp":"7027990","buy":"9","sell":"7","commission":"26"},{"good":"glass","stock":283,"heat_fp":70000000,"days":0,"heat_now_fp":"70000000","pow":"500000","price_fp":"5050000","buyback_fp":"4040000","buy":"6","sell":"4","commission":"7"},{"good":"reed","stock":22,"heat_fp":1030829651,"days":55,"heat_now_fp":"0","pow":"1519657","price_fp":"6078628","buyback_fp":"4862902","buy":"7","sell":"4","commission":"18"},{"good":"glass","stock":631376,"heat_fp":599440611,"days":28,"heat_now_fp":"2","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":293897460,"days":33,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":13000000,"days":16,"heat_now_fp":"198","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":809792,"heat_fp":65000000,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":17,"heat_fp":191939579,"days":52,"heat_now_fp":"0","pow":"1820233","price_fp":"7280932","buyback_fp":"5824745","buy":"8","sell":"5","commission":"21"},{"good":"glass","stock":140875,"heat_fp":66000000,"days":37,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":39,"heat_fp":183589288,"days":64,"heat_now_fp":"0","pow":"1017879","price_fp":"4071516","buyback_fp":"3257212","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":14,"heat_fp":23000000,"days":57,"heat_now_fp":"0","pow":"2085221","price_fp":"16681768","buyback_fp":"13345414","buy":"17","sell":"13","commission":"25"},{"good":"reed","stock":12,"heat_fp":2016707397,"days":62,"heat_now_fp":"0","pow":"2322815","price_fp":"9291260","buyback_fp":"7433008","buy":"10","sell":"7","commission":"27"},{"good":"glass","stock":328,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":43000000,"days":20,"heat_now_fp":"41","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":13,"heat_fp":0,"days":49,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":59,"heat_fp":61000000,"days":18,"heat_now_fp":"232","pow":"761806","price_fp":"3047224","buyback_fp":"2437779","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":125,"heat_fp":210133088,"days":6,"heat_now_fp":"3283329","pow":"500000","price_fp":"4049248","buyback_fp":"3239398","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":7,"heat_fp":20000000,"days":9,"heat_now_fp":"39062","pow":"3000000","price_fp":"12001752","buyback_fp":"9601401","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":806866,"heat_fp":74000000,"days":39,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":805591,"heat_fp":2126961267,"days":54,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":1954879785,"days":36,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":163,"heat_fp":0,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":0,"days":23,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":97201,"heat_fp":1033228238,"days":5,"heat_now_fp":"32288382","pow":"500000","price_fp":"2242162","buyback_fp":"1793729","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":57,"heat_fp":0,"days":53,"heat_now_fp":"0","pow":"780421","price_fp":"6243368","buyback_fp":"4994694","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":473758,"heat_fp":54972038,"days":5,"heat_now_fp":"1717876","pow":"500000","price_fp":"2012882","buyback_fp":"1610305","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":45,"heat_fp":0,"days":56,"heat_now_fp":"0","pow":"920857","price_fp":"7366856","buyback_fp":"5893484","buy":"8","sell":"5","commission":"11"},{"good":"reed","stock":4,"heat_fp":46000000,"days":53,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":2,"heat_fp":67000000,"days":1,"heat_now_fp":"33500000","pow":"3000000","price_fp":"27015000","buyback_fp":"21612000","buy":"28","sell":"21","commission":"36"},{"good":"reed","stock":1462,"heat_fp":25000000,"days":65,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":128726,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":44,"heat_fp":0,"days":43,"heat_now_fp":"0","pow":"935458","price_fp":"3741832","buyback_fp":"2993465","buy":"4","sell":"2","commission":"11"},{"good":"glass","stock":3,"heat_fp":53000000,"days":37,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":109910,"heat_fp":0,"days":46,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":24,"heat_fp":1694803008,"days":45,"heat_now_fp":"0","pow":"1429861","price_fp":"11438888","buyback_fp":"9151110","buy":"12","sell":"9","commission":"17"},{"good":"reed","stock":279,"heat_fp":1000000,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":86,"heat_fp":979245273,"days":11,"heat_now_fp":"478147","pow":"585184","price_fp":"2344930","buyback_fp":"1875944","buy":"3","sell":"1","commission":"7"},{"good":"glass","stock":3,"heat_fp":0,"days":45,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":818094136,"days":52,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":72,"heat_fp":1708358917,"days":18,"heat_now_fp":"6516","pow":"662686","price_fp":"5301615","buyback_fp":"4241292","buy":"6","sell":"4","commission":"7"},{"good":"reed","stock":192,"heat_fp":22000000,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":56,"heat_fp":980977795,"days":52,"heat_now_fp":"0","pow":"790149","price_fp":"6321192","buyback_fp":"5056953","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":8,"heat_fp":1032190016,"days":60,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":222,"heat_fp":47000000,"days":30,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":13000000,"days":18,"heat_now_fp":"49","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":681231,"heat_fp":1904312948,"days":4,"heat_now_fp":"119019559","pow":"500000","price_fp":"5785292","buyback_fp":"4628233","buy":"6","sell":"4","commission":"8"},{"good":"reed","stock":88,"heat_fp":0,"days":60,"heat_now_fp":"0","pow":"575842","price_fp":"2303368","buyback_fp":"1842694","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":45,"heat_fp":60000000,"days":35,"heat_now_fp":"0","pow":"920857","price_fp":"7366856","buyback_fp":"5893484","buy":"8","sell":"5","commission":"11"},{"good":"reed","stock":2,"heat_fp":1031568196,"days":6,"heat_now_fp":"16118253","pow":"3000000","price_fp":"12725316","buyback_fp":"10180252","buy":"13","sell":"10","commission":"36"},{"good":"glass","stock":41,"heat_fp":35000000,"days":60,"heat_now_fp":"0","pow":"982862","price_fp":"7862896","buyback_fp":"6290316","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":2,"heat_fp":786963798,"days":29,"heat_now_fp":"1","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":204,"heat_fp":0,"days":46,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":58,"heat_fp":390654474,"days":61,"heat_now_fp":"0","pow":"770977","price_fp":"3083908","buyback_fp":"2467126","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":50,"heat_fp":1649835676,"days":0,"heat_now_fp":"1649835676","pow":"855387","price_fp":"49180530","buyback_fp":"39344424","buy":"50","sell":"39","commission":"36"},{"good":"reed","stock":49,"heat_fp":24000000,"days":52,"heat_now_fp":"0","pow":"867569","price_fp":"3470276","buyback_fp":"2776220","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":3,"heat_fp":10000000,"days":21,"heat_now_fp":"4","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":162,"heat_fp":1164302470,"days":12,"heat_now_fp":"284253","pow":"500000","price_fp":"2002130","buyback_fp":"1601704","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":534397,"heat_fp":0,"days":30,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":93,"heat_fp":664717887,"days":62,"heat_now_fp":"0","pow":"553991","price_fp":"2215964","buyback_fp":"1772771","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":560374,"heat_fp":61000000,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":0,"days":37,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":48,"heat_fp":49000000,"days":51,"heat_now_fp":"0","pow":"880181","price_fp":"7041448","buyback_fp":"5633158","buy":"8","sell":"5","commission":"10"},{"good":"reed","stock":3,"heat_fp":58000000,"days":15,"heat_now_fp":"1770","pow":"3000000","price_fp":"12000072","buyback_fp":"9600057","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":98,"heat_fp":0,"days":62,"heat_now_fp":"0","pow":"534051","price_fp":"4272408","buyback_fp":"3417926","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":300193657,"days":44,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":801358,"heat_fp":526571867,"days":1,"heat_now_fp":"263285933","pow":"500000","price_fp":"7949288","buyback_fp":"6359430","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":4,"heat_fp":2000000,"days":47,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":0,"days":30,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":172,"heat_fp":17000000,"days":25,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":341,"heat_fp":0,"days":26,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":71000000,"days":22,"heat_now_fp":"16","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":967259,"heat_fp":0,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":44,"heat_fp":0,"days":18,"heat_now_fp":"0","pow":"935458","price_fp":"3741832","buyback_fp":"2993465","buy":"4","sell":"2","commission":"11"},{"good":"glass","stock":900371,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":192,"heat_fp":2091354468,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":608337,"heat_fp":0,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":82,"heat_fp":305919943,"days":8,"heat_now_fp":"1194999","pow":"605021","price_fp":"2430928","buyback_fp":"1944742","buy":"3","sell":"1","commission":"7"},{"good":"glass","stock":30,"heat_fp":0,"days":4,"heat_now_fp":"0","pow":"1223084","price_fp":"9784672","buyback_fp":"7827737","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":251,"heat_fp":52000000,"days":57,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":33,"heat_fp":672082681,"days":12,"heat_now_fp":"164082","pow":"1144147","price_fp":"9158805","buyback_fp":"7327044","buy":"10","sell":"7","commission":"13"},{"good":"reed","stock":250,"heat_fp":43000000,"days":38,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":67321,"heat_fp":62000000,"days":57,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":817715,"heat_fp":42000000,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":1572095306,"days":4,"heat_now_fp":"98255956","pow":"3000000","price_fp":"32843016","buyback_fp":"26274412","buy":"33","sell":"26","commission":"36"},{"good":"reed","stock":4,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":37,"heat_fp":0,"days":24,"heat_now_fp":"0","pow":"1056088","price_fp":"8448704","buyback_fp":"6758963","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":48,"heat_fp":39000000,"days":47,"heat_now_fp":"0","pow":"880181","price_fp":"3520724","buyback_fp":"2816579","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":3,"heat_fp":1139162095,"days":53,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":909775,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":36,"heat_fp":0,"days":28,"heat_now_fp":"0","pow":"1076538","price_fp":"8612304","buyback_fp":"6889843","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":4,"heat_fp":0,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":306608,"heat_fp":21000000,"days":7,"heat_now_fp":"164062","pow":"500000","price_fp":"4002460","buyback_fp":"3201968","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":1217120444,"days":36,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":6,"heat_fp":60000000,"days":12,"heat_now_fp":"14648","pow":"3000000","price_fp":"24001296","buyback_fp":"19201036","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":862597,"heat_fp":25000000,"days":22,"heat_now_fp":"5","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":1592441775,"days":12,"heat_now_fp":"388779","pow":"3000000","price_fp":"24034968","buyback_fp":"19227974","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":12,"heat_fp":67000000,"days":67,"heat_now_fp":"0","pow":"2322815","price_fp":"9291260","buyback_fp":"7433008","buy":"10","sell":"7","commission":"27"},{"good":"glass","stock":32,"heat_fp":17000000,"days":69,"heat_now_fp":"0","pow":"1169058","price_fp":"9352464","buyback_fp":"7481971","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":29,"heat_fp":244772957,"days":3,"heat_now_fp":"30596619","pow":"1252458","price_fp":"5584645","buyback_fp":"4467716","buy":"6","sell":"4","commission":"16"},{"good":"glass","stock":10,"heat_fp":1503630694,"days":1,"heat_now_fp":"751815347","pow":"2639014","price_fp":"80633637","buyback_fp":"64506909","buy":"81","sell":"64","commission":"36"},{"good":"reed","stock":1,"heat_fp":514897965,"days":8,"heat_now_fp":"2011320","pow":"3000000","price_fp":"12090504","buyback_fp":"9672403","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":694626,"heat_fp":0,"days":4,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":63,"heat_fp":0,"days":14,"heat_now_fp":"0","pow":"727616","price_fp":"5820928","buyback_fp":"4656742","buy":"6","sell":"4","commission":"8"},{"good":"reed","stock":193999,"heat_fp":2144034175,"days":52,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":0,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":73,"heat_fp":11000000,"days":3,"heat_now_fp":"1375000","pow":"656320","price_fp":"2638815","buyback_fp":"2111052","buy":"3","sell":"2","commission":"7"},{"good":"glass","stock":513315,"heat_fp":0,"days":26,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":16000000,"days":43,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":957340,"heat_fp":159168475,"days":27,"heat_now_fp":"1","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":60,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":37,"heat_fp":10000000,"days":14,"heat_now_fp":"610","pow":"1056088","price_fp":"8448720","buyback_fp":"6758976","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":643425,"heat_fp":8000000,"days":17,"heat_now_fp":"61","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":830307795,"days":6,"heat_now_fp":"12973559","pow":"3000000","price_fp":"25167600","buyback_fp":"20134080","buy":"26","sell":"20","commission":"36"},{"good":"reed","stock":140,"heat_fp":50000000,"days":17,"heat_now_fp":"381","pow":"500000","price_fp":"2000002","buyback_fp":"1600001","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":53000000,"days":58,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":314,"heat_fp":51000000,"days":30,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":3,"heat_fp":813712376,"days":9,"heat_now_fp":"1589281","pow":"3000000","price_fp":"24143016","buyback_fp":"19314412","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":125,"heat_fp":54000000,"days":52,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":475845,"heat_fp":0,"days":52,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":992609318,"days":31,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":247,"heat_fp":1723187087,"days":3,"heat_now_fp":"215398385","pow":"500000","price_fp":"7230972","buyback_fp":"5784777","buy":"8","sell":"5","commission":"10"},{"good":"reed","stock":621554,"heat_fp":0,"days":63,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":0,"heat_fp":70000000,"days":44,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":14,"heat_fp":467834671,"days":6,"heat_now_fp":"7309916","pow":"2085221","price_fp":"8569524","buyback_fp":"6855619","buy":"9","sell":"6","commission":"25"},{"good":"glass","stock":3,"heat_fp":55000000,"days":45,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":215030,"heat_fp":0,"days":22,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":786041,"heat_fp":65000000,"days":46,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":1266714382,"days":6,"heat_now_fp":"19792412","pow":"3000000","price_fp":"12890652","buyback_fp":"10312521","buy":"13","sell":"10","commission":"36"},{"good":"glass","stock":32,"heat_fp":68000000,"days":68,"heat_now_fp":"0","pow":"1169058","price_fp":"9352464","buyback_fp":"7481971","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":61311,"heat_fp":3000000,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":683135,"heat_fp":53000000,"days":67,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":47,"heat_fp":8000000,"days":42,"heat_now_fp":"0","pow":"893248","price_fp":"3572992","buyback_fp":"2858393","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":155,"heat_fp":1752117866,"days":18,"heat_now_fp":"6683","pow":"500000","price_fp":"4000100","buyback_fp":"3200080","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":408736,"heat_fp":27000000,"days":59,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":361556,"heat_fp":2098092939,"days":45,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":386,"heat_fp":48000000,"days":6,"heat_now_fp":"750000","pow":"500000","price_fp":"2005624","buyback_fp":"1604499","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":37,"heat_fp":0,"days":46,"heat_now_fp":"0","pow":"1056088","price_fp":"8448704","buyback_fp":"6758963","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":4,"heat_fp":69000000,"days":19,"heat_now_fp":"131","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":84,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"594902","price_fp":"4759216","buyback_fp":"3807372","buy":"5","sell":"3","commission":"7"},{"good":"reed","stock":319,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":620579,"heat_fp":0,"days":19,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":420242,"heat_fp":0,"days":60,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":946488,"heat_fp":15000000,"days":5,"heat_now_fp":"468750","pow":"500000","price_fp":"4007028","buyback_fp":"3205622","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":239,"heat_fp":79000000,"days":24,"heat_now_fp":"4","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":13,"heat_fp":0,"days":8,"heat_now_fp":"0","pow":"2196247","price_fp":"17569976","buyback_fp":"14055980","buy":"18","sell":"14","commission":"26"},{"good":"reed","stock":185,"heat_fp":34000000,"days":53,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":57,"heat_fp":646658402,"days":26,"heat_now_fp":"9","pow":"780421","price_fp":"3121684","buyback_fp":"2497347","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":561755,"heat_fp":1067262373,"days":65,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":222261,"heat_fp":77000000,"days":6,"heat_now_fp":"1203125","pow":"500000","price_fp":"2009022","buyback_fp":"1607217","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":624429,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":51,"heat_fp":882046749,"days":64,"heat_now_fp":"0","pow":"843611","price_fp":"3374444","buyback_fp":"2699555","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":3,"heat_fp":34000000,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":191,"heat_fp":51000000,"days":61,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":84,"heat_fp":1695638822,"days":39,"heat_now_fp":"0","pow":"594902","price_fp":"4759216","buyback_fp":"3807372","buy":"5","sell":"3","commission":"7"},{"good":"reed","stock":23,"heat_fp":17000000,"days":13,"heat_now_fp":"2075","pow":"1473099","price_fp":"5892437","buyback_fp":"4713949","buy":"6","sell":"4","commission":"17"},{"good":"glass","stock":26,"heat_fp":0,"days":64,"heat_now_fp":"0","pow":"1351948","price_fp":"10815584","buyback_fp":"8652467","buy":"11","sell":"8","commission":"16"},{"good":"reed","stock":40,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"1000000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"12"},{"good":"glass","stock":844189,"heat_fp":1088659239,"days":65,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":31,"heat_fp":32000000,"days":14,"heat_now_fp":"1953","pow":"1195331","price_fp":"4781357","buyback_fp":"3825085","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":40,"heat_fp":53000000,"days":46,"heat_now_fp":"0","pow":"1000000","price_fp":"8000000","buyback_fp":"6400000","buy":"8","sell":"6","commission":"12"},{"good":"reed","stock":176,"heat_fp":111897918,"days":50,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":208,"heat_fp":0,"days":42,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":7,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":8,"heat_fp":0,"days":54,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":26,"heat_fp":0,"days":22,"heat_now_fp":"0","pow":"1351948","price_fp":"5407792","buyback_fp":"4326233","buy":"6","sell":"4","commission":"16"},{"good":"glass","stock":446880,"heat_fp":0,"days":40,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":172,"heat_fp":33000000,"days":24,"heat_now_fp":"1","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":10,"heat_fp":29000000,"days":66,"heat_now_fp":"0","pow":"2639014","price_fp":"21112112","buyback_fp":"16889689","buy":"22","sell":"16","commission":"31"},{"good":"reed","stock":59,"heat_fp":1165651089,"days":67,"heat_now_fp":"0","pow":"761806","price_fp":"3047224","buyback_fp":"2437779","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":342,"heat_fp":34000000,"days":35,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":66000000,"days":53,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":611714,"heat_fp":1006347039,"days":61,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":13,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":125,"heat_fp":258163702,"days":65,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":256805,"heat_fp":19000000,"days":8,"heat_now_fp":"74218","pow":"500000","price_fp":"2000556","buyback_fp":"1600444","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":23,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"1473099","price_fp":"11784792","buyback_fp":"9427833","buy":"12","sell":"9","commission":"17"},{"good":"reed","stock":4,"heat_fp":1231624852,"days":1,"heat_now_fp":"615812426","pow":"3000000","price_fp":"39711552","buyback_fp":"31769241","buy":"40","sell":"31","commission":"36"},{"good":"glass","stock":523938,"heat_fp":720973918,"days":63,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":76000000,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":237985,"heat_fp":1135090769,"days":25,"heat_now_fp":"33","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":6000000,"days":64,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":127,"heat_fp":0,"days":21,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":38,"heat_fp":67000000,"days":68,"heat_now_fp":"0","pow":"1036556","price_fp":"4146224","buyback_fp":"3316979","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":4,"heat_fp":0,"days":18,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":26,"heat_fp":20000000,"days":67,"heat_now_fp":"0","pow":"1351948","price_fp":"5407792","buyback_fp":"4326233","buy":"6","sell":"4","commission":"16"},{"good":"glass","stock":2,"heat_fp":0,"days":37,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":345546,"heat_fp":49000000,"days":54,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":877787,"heat_fp":48000000,"days":27,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":317193609,"days":64,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":228,"heat_fp":857967302,"days":49,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":181,"heat_fp":69000000,"days":7,"heat_now_fp":"539062","pow":"500000","price_fp":"2004042","buyback_fp":"1603233","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":448488,"heat_fp":1616622953,"days":12,"heat_now_fp":"394683","pow":"500000","price_fp":"4005920","buyback_fp":"3204736","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":68000000,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":2,"heat_fp":0,"days":47,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":35,"heat_fp":49000000,"days":44,"heat_now_fp":"0","pow":"1097978","price_fp":"4391912","buyback_fp":"3513529","buy":"5","sell":"3","commission":"13"},{"good":"glass","stock":200880,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":44000000,"days":21,"heat_now_fp":"20","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":57,"heat_fp":0,"days":42,"heat_now_fp":"0","pow":"780421","price_fp":"6243368","buyback_fp":"4994694","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":55,"heat_fp":0,"days":35,"heat_now_fp":"0","pow":"800178","price_fp":"3200712","buyback_fp":"2560569","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":191,"heat_fp":0,"days":61,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":35,"heat_fp":0,"days":40,"heat_now_fp":"0","pow":"1097978","price_fp":"4391912","buyback_fp":"3513529","buy":"5","sell":"3","commission":"13"},{"good":"glass","stock":266,"heat_fp":24000000,"days":21,"heat_now_fp":"11","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":309,"heat_fp":9000000,"days":24,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":30,"heat_fp":1429441578,"days":49,"heat_now_fp":"0","pow":"1223084","price_fp":"9784672","buyback_fp":"7827737","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":4,"heat_fp":0,"days":53,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":257,"heat_fp":0,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":52,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":0,"days":40,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":0,"days":3,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":44,"heat_fp":674367382,"days":8,"heat_now_fp":"2634247","pow":"935458","price_fp":"7557587","buyback_fp":"6046069","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":58,"heat_fp":0,"days":66,"heat_now_fp":"0","pow":"770977","price_fp":"3083908","buyback_fp":"2467126","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":4,"heat_fp":66000000,"days":13,"heat_now_fp":"8056","pow":"3000000","price_fp":"24000720","buyback_fp":"19200576","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":35,"heat_fp":0,"days":53,"heat_now_fp":"0","pow":"1097978","price_fp":"4391912","buyback_fp":"3513529","buy":"5","sell":"3","commission":"13"},{"good":"glass","stock":0,"heat_fp":18000000,"days":33,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":181,"heat_fp":57000000,"days":25,"heat_now_fp":"1","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":40,"heat_fp":56000000,"days":62,"heat_now_fp":"0","pow":"1000000","price_fp":"8000000","buyback_fp":"6400000","buy":"8","sell":"6","commission":"12"},{"good":"reed","stock":624383,"heat_fp":78000000,"days":51,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":8,"heat_fp":59000000,"days":11,"heat_now_fp":"28808","pow":"3000000","price_fp":"24002592","buyback_fp":"19202073","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":555092329,"days":8,"heat_now_fp":"2168329","pow":"3000000","price_fp":"12097572","buyback_fp":"9678057","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":89569,"heat_fp":0,"days":15,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":50,"heat_fp":41000000,"days":60,"heat_now_fp":"0","pow":"855387","price_fp":"3421548","buyback_fp":"2737238","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":327343,"heat_fp":0,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":25,"heat_fp":0,"days":63,"heat_now_fp":"0","pow":"1389580","price_fp":"5558320","buyback_fp":"4446656","buy":"6","sell":"4","commission":"16"},{"good":"glass","stock":28086,"heat_fp":0,"days":68,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":4,"heat_fp":1834322192,"days":1,"heat_now_fp":"917161096","pow":"3000000","price_fp":"53272248","buyback_fp":"42617798","buy":"54","sell":"42","commission":"36"},{"good":"glass","stock":3,"heat_fp":1313165266,"days":69,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":50677,"heat_fp":1089757722,"days":17,"heat_now_fp":"8314","pow":"500000","price_fp":"2000062","buyback_fp":"1600049","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":34,"heat_fp":0,"days":31,"heat_now_fp":"0","pow":"1120485","price_fp":"8963880","buyback_fp":"7171104","buy":"9","sell":"7","commission":"13"},{"good":"reed","stock":6,"heat_fp":3000000,"days":50,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":49,"heat_fp":0,"days":50,"heat_now_fp":"0","pow":"867569","price_fp":"6940552","buyback_fp":"5552441","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":2,"heat_fp":1315244932,"days":7,"heat_now_fp":"10275351","pow":"3000000","price_fp":"12462384","buyback_fp":"9969907","buy":"13","sell":"9","commission":"36"},{"good":"glass","stock":176385,"heat_fp":0,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":32,"heat_fp":52000000,"days":40,"heat_now_fp":"0","pow":"1169058","price_fp":"4676232","buyback_fp":"3740985","buy":"5","sell":"3","commission":"14"},{"good":"glass","stock":148,"heat_fp":0,"days":49,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":1,"heat_fp":0,"days":56,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":0,"heat_fp":7000000,"days":51,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":2,"heat_fp":1000000,"days":13,"heat_now_fp":"122","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":42,"heat_fp":0,"days":37,"heat_now_fp":"0","pow":"966422","price_fp":"7731376","buyback_fp":"6185100","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":85,"heat_fp":0,"days":3,"heat_now_fp":"0","pow":"589994","price_fp":"2359976","buyback_fp":"1887980","buy":"3","sell":"1","commission":"7"},{"good":"glass","stock":36,"heat_fp":57000000,"days":11,"heat_now_fp":"27832","pow":"1076538","price_fp":"8613199","buyback_fp":"6890559","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":299788,"heat_fp":865899689,"days":0,"heat_now_fp":"865899689","pow":"500000","price_fp":"8494246","buyback_fp":"6795396","buy":"9","sell":"6","commission":"25"},{"good":"glass","stock":0,"heat_fp":22000000,"days":63,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":49,"heat_fp":21000000,"days":18,"heat_now_fp":"80","pow":"867569","price_fp":"3470276","buyback_fp":"2776220","buy":"4","sell":"2","commission":"10"},{"good":"glass","stock":4,"heat_fp":0,"days":22,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":18,"heat_fp":29000000,"days":14,"heat_now_fp":"1770","pow":"1748842","price_fp":"6995409","buyback_fp":"5596327","buy":"7","sell":"5","commission":"20"},{"good":"glass","stock":151446,"heat_fp":0,"days":20,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":0,"heat_fp":2025645159,"days":48,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":290121,"heat_fp":330107002,"days":14,"heat_now_fp":"20148","pow":"500000","price_fp":"4000300","buyback_fp":"3200240","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":67,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":27,"heat_fp":50000000,"days":38,"heat_now_fp":"0","pow":"1316700","price_fp":"10533600","buyback_fp":"8426880","buy":"11","sell":"8","commission":"15"},{"good":"reed","stock":262269,"heat_fp":20000000,"days":23,"heat_now_fp":"2","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":39,"heat_fp":0,"days":56,"heat_now_fp":"0","pow":"1017879","price_fp":"8143032","buyback_fp":"6514425","buy":"9","sell":"6","commission":"12"},{"good":"reed","stock":23,"heat_fp":22000000,"days":42,"heat_now_fp":"0","pow":"1473099","price_fp":"5892396","buyback_fp":"4713916","buy":"6","sell":"4","commission":"17"},{"good":"glass","stock":56,"heat_fp":0,"days":11,"heat_now_fp":"0","pow":"790149","price_fp":"6321192","buyback_fp":"5056953","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":315,"heat_fp":766850082,"days":6,"heat_now_fp":"11982032","pow":"500000","price_fp":"2089864","buyback_fp":"1671891","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":18000000,"days":47,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":197,"heat_fp":0,"days":5,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":68000000,"days":49,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":182610,"heat_fp":75000000,"days":18,"heat_now_fp":"286","pow":"500000","price_fp":"2000002","buyback_fp":"1600001","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":59,"heat_fp":0,"days":60,"heat_now_fp":"0","pow":"761806","price_fp":"6094448","buyback_fp":"4875558","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":955578,"heat_fp":11000000,"days":37,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":20000000,"days":14,"heat_now_fp":"1220","pow":"3000000","price_fp":"24000096","buyback_fp":"19200076","buy":"25","sell":"19","commission":"36"},{"good":"reed","stock":343,"heat_fp":71000000,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":304011,"heat_fp":21000000,"days":64,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":42,"heat_fp":0,"days":26,"heat_now_fp":"0","pow":"966422","price_fp":"3865688","buyback_fp":"3092550","buy":"4","sell":"3","commission":"11"},{"good":"glass","stock":5,"heat_fp":0,"days":32,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":534990,"heat_fp":1627488129,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":20,"heat_fp":51000000,"days":66,"heat_now_fp":"0","pow":"1624503","price_fp":"12996024","buyback_fp":"10396819","buy":"13","sell":"10","commission":"19"},{"good":"reed","stock":12,"heat_fp":1884757104,"days":7,"heat_now_fp":"14724664","pow":"2322815","price_fp":"9804295","buyback_fp":"7843436","buy":"10","sell":"7","commission":"29"},{"good":"glass","stock":697435,"heat_fp":978700529,"days":33,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":20,"heat_fp":0,"days":6,"heat_now_fp":"0","pow":"1624503","price_fp":"6498012","buyback_fp":"5198409","buy":"7","sell":"5","commission":"19"},{"good":"glass","stock":0,"heat_fp":0,"days":43,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":635208,"heat_fp":2118517335,"days":55,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":41,"heat_fp":78000000,"days":33,"heat_now_fp":"0","pow":"982862","price_fp":"7862896","buyback_fp":"6290316","buy":"8","sell":"6","commission":"11"},{"good":"reed","stock":884995,"heat_fp":1444287477,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":49,"heat_fp":56000000,"days":29,"heat_now_fp":"0","pow":"867569","price_fp":"6940552","buyback_fp":"5552441","buy":"7","sell":"5","commission":"10"},{"good":"reed","stock":1,"heat_fp":599041794,"days":25,"heat_now_fp":"17","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":1,"heat_fp":54000000,"days":61,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":55,"heat_fp":67000000,"days":3,"heat_now_fp":"8375000","pow":"800178","price_fp":"3301233","buyback_fp":"2640986","buy":"4","sell":"2","commission":"9"},{"good":"glass","stock":369192,"heat_fp":36000000,"days":7,"heat_now_fp":"281250","pow":"500000","price_fp":"4004216","buyback_fp":"3203372","buy":"5","sell":"3","commission":"6"},{"good":"reed","stock":68641,"heat_fp":548382900,"days":44,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":914285,"heat_fp":481752875,"days":48,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":446878,"heat_fp":49000000,"days":6,"heat_now_fp":"765625","pow":"500000","price_fp":"2005742","buyback_fp":"1604593","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":459490,"heat_fp":1107518623,"days":24,"heat_now_fp":"66","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":3,"heat_fp":0,"days":40,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":55,"heat_fp":1822177536,"days":69,"heat_now_fp":"0","pow":"800178","price_fp":"6401424","buyback_fp":"5121139","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":23,"heat_fp":0,"days":47,"heat_now_fp":"0","pow":"1473099","price_fp":"5892396","buyback_fp":"4713916","buy":"6","sell":"4","commission":"17"},{"good":"glass","stock":127,"heat_fp":229204514,"days":41,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":2,"heat_fp":0,"days":12,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":0,"heat_fp":0,"days":8,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":1,"heat_fp":13000000,"days":54,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":59,"heat_fp":0,"days":55,"heat_now_fp":"0","pow":"761806","price_fp":"6094448","buyback_fp":"4875558","buy":"7","sell":"4","commission":"9"},{"good":"reed","stock":814888,"heat_fp":78000000,"days":24,"heat_now_fp":"4","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":515229,"heat_fp":0,"days":37,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":39,"heat_fp":0,"days":30,"heat_now_fp":"0","pow":"1017879","price_fp":"4071516","buyback_fp":"3257212","buy":"5","sell":"3","commission":"12"},{"good":"glass","stock":378,"heat_fp":0,"days":58,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":268493,"heat_fp":33000000,"days":4,"heat_now_fp":"2062500","pow":"500000","price_fp":"2015468","buyback_fp":"1612374","buy":"3","sell":"1","commission":"6"},{"good":"glass","stock":352,"heat_fp":0,"days":36,"heat_now_fp":"0","pow":"500000","price_fp":"4000000","buyback_fp":"3200000","buy":"4","sell":"3","commission":"6"},{"good":"reed","stock":912718,"heat_fp":44000000,"days":21,"heat_now_fp":"20","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":55,"heat_fp":1507928149,"days":67,"heat_now_fp":"0","pow":"800178","price_fp":"6401424","buyback_fp":"5121139","buy":"7","sell":"5","commission":"9"},{"good":"reed","stock":3,"heat_fp":13000000,"days":27,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":2,"heat_fp":337197129,"days":33,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":0,"heat_fp":16000000,"days":30,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"},{"good":"glass","stock":3,"heat_fp":0,"days":40,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":200,"heat_fp":862851622,"days":46,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":31,"heat_fp":6000000,"days":64,"heat_now_fp":"0","pow":"1195331","price_fp":"9562648","buyback_fp":"7650118","buy":"10","sell":"7","commission":"14"},{"good":"reed","stock":117096,"heat_fp":49000000,"days":51,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":2,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":939269,"heat_fp":2094273582,"days":4,"heat_now_fp":"130892098","pow":"500000","price_fp":"2981690","buyback_fp":"2385352","buy":"3","sell":"2","commission":"8"},{"good":"glass","stock":16,"heat_fp":381352209,"days":4,"heat_now_fp":"23834513","pow":"1899142","price_fp":"16551083","buyback_fp":"13240866","buy":"17","sell":"13","commission":"24"},{"good":"reed","stock":374,"heat_fp":29000000,"days":50,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":1,"heat_fp":793285773,"days":55,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":16,"heat_fp":68000000,"days":8,"heat_now_fp":"265625","pow":"1899142","price_fp":"7604134","buyback_fp":"6083307","buy":"8","sell":"6","commission":"22"},{"good":"glass","stock":5,"heat_fp":0,"days":9,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":15,"heat_fp":769864348,"days":61,"heat_now_fp":"0","pow":"1986907","price_fp":"7947628","buyback_fp":"6358102","buy":"8","sell":"6","commission":"23"},{"good":"glass","stock":4,"heat_fp":36000000,"days":67,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":271,"heat_fp":892654868,"days":69,"heat_now_fp":"0","pow":"500000","price_fp":"2000000","buyback_fp":"1600000","buy":"2","sell":"1","commission":"6"},{"good":"glass","stock":4,"heat_fp":0,"days":16,"heat_now_fp":"0","pow":"3000000","price_fp":"24000000","buyback_fp":"19200000","buy":"24","sell":"19","commission":"36"},{"good":"reed","stock":2,"heat_fp":0,"days":28,"heat_now_fp":"0","pow":"3000000","price_fp":"12000000","buyback_fp":"9600000","buy":"12","sell":"9","commission":"36"}] diff --git a/contracts/season/src/lib.rs b/contracts/season/src/lib.rs new file mode 100644 index 0000000..849bfe3 --- /dev/null +++ b/contracts/season/src/lib.rs @@ -0,0 +1,1019 @@ +//! Familiar Season 2: the daily court, Bram's shelf and till, and Mochi's wish. +//! +//! Self-contained ledgers: goods (glass, reed) and Season 2 Shells per account, Bram's till +//! and shelf, and one purse per pet. Shells are bound: there is no cash redemption and no +//! NEAR deposit buys them. The only Shell source is Bram's daily till refill; the only goods +//! source is the daily court mint (plus the opening shelf). +//! +//! Rules (all integer, see `pricing`): +//! - Day = floor(block_timestamp / 24 h). Even days replay `first_light_v1`, odd days +//! `first_light_v2`, as a fresh beacon outing (no banked items) with the player's tool. +//! The first accepted return of an account's day mints its docked cargo via `CARGO_GOODS`; +//! a return that maps to no goods is refused so it does not use up the day. +//! - Score = haul value / best haul value, both at the shelf prices at docking. The best haul +//! per court is the most valuable of every tool's maximal hauls in `BEST_HAUL`. +//! - Trades are priced unit by unit (each unit moves stock and heat before the next). +//! `max_price` / `min_price` bound every unit; 20 units per good per account per day +//! count buys and sells together. Wish fills do not count against the funder's limit. +//! - The opening shelf holds 40 of each good (stock = target, so prices start at base). +//! Buys may lift the till above 300; the daily refill only tops it up to 300. +//! - Commission is exposed as a quoted number in `get_shelf`; nothing pays it yet. +//! +//! Storage: an account registers once with `storage_deposit` (at least `storage_minimum`, +//! 1,250 bytes at the current byte cost: one account record plus one pet record). The +//! account record is charged `ACCOUNT_BYTES`; each pet record (wish, queue slot, postcard) +//! is charged `PET_BYTES` once, to whoever creates it. Charged bytes are never refunded, +//! because records persist. Any deposit above the charged bytes can be taken back with +//! `storage_withdraw` (1 yoctoNEAR); a failed transfer restores it. +pub mod pricing; +#[cfg(test)] +mod tests; + +use familiar_common::{court, historical_returns, storycraft}; +use near_sdk::{ + AccountId, Gas, NearToken, PanicOnDefault, Promise, env, + json_types::U128, + near, require, + serde_json::{self, Value, json}, + store::LookupMap, +}; +use pricing::{S, buy_shells, buyback_fp, commission, decay_heat, price_fp, sell_shells}; + +pub const GOODS: [&str; 2] = ["glass", "reed"]; +pub const GLASS: usize = 0; +pub const REED: usize = 1; +/// Cargo that reaches the dock becomes goods through this one table. `vane` mints nothing. +pub const CARGO_GOODS: [(&str, Option); 5] = [ + ("lens", Some(GLASS)), + ("moth", Some(REED)), + ("chart", Some(REED)), + ("salvage", Some(REED)), + ("vane", None), +]; +pub const BASE: [u128; 2] = [8, 4]; +pub const TARGET: [u128; 2] = [40, 40]; +pub const START_STOCK: [u64; 2] = [40, 40]; +pub const TILL_START: u64 = 300; +pub const TILL_CAP: u64 = 300; +pub const TILL_REFILL: u64 = 60; +pub const DAY_NS: u64 = 86_400_000_000_000; +pub const DAILY_UNITS: u32 = 20; +pub const TRADE_QTY_MAX: u32 = 20; +pub const PURSE_MAX: u64 = 24; +pub const WISH_QTY_MAX: u8 = 2; +pub const FILLS_PER_TX: usize = 3; +/// Bounds the per-trade scan of waiting wishes for one good. +pub const WISH_QUEUE_CAP: usize = 32; +pub const PET_ID_MAX: usize = 64; +pub const COMMAND_LEN_MAX: usize = 24; +pub const COURT_AREA: &str = "beacon"; +/// Even days replay `first_light_v1`, odd days `first_light_v2`, always a fresh beacon outing. +pub const COURTS: [&str; 2] = [storycraft::CONTENT_VERSION, court::CONTENT_VERSION]; +pub const TOOLS: [&str; 2] = ["rope", "lantern"]; +/// Maximal (glass, reed) hauls (the Pareto set) per court and tool, generated by +/// `bun scripts/season-best-haul.ts` into `fixtures/best-haul.json` and checked by tests on both +/// sides. A mint must be dominated by one of its tool's hauls. +pub const BEST_HAUL: [[&[(u64, u64)]; 2]; 2] = + [[&[(1, 1), (0, 2)], &[(1, 2)]], [&[(1, 1)], &[(1, 1)]]]; +/// Storage charged once per account record, and once per pet record (wish, queue slot, postcard). +pub const ACCOUNT_BYTES: u64 = 400; +pub const PET_BYTES: u64 = 850; + +fn day_of(timestamp: u64) -> u64 { + timestamp / DAY_NS +} +fn today() -> u64 { + day_of(env::block_timestamp()) +} +pub fn court_of(day: u64) -> usize { + (day % 2) as usize +} +fn good_index(good: &str) -> Option { + GOODS.iter().position(|g| *g == good) +} +fn to_u64(v: u128) -> u64 { + u64::try_from(v).unwrap_or(u64::MAX) +} +fn bytes_cost(bytes: u64) -> u128 { + env::storage_byte_cost().as_yoctonear() * u128::from(bytes) +} +pub fn min_storage_deposit() -> NearToken { + NearToken::from_yoctonear(bytes_cost(ACCOUNT_BYTES + PET_BYTES)) +} +fn emit(event: &str, data: Value) { + env::log_str(&format!( + "EVENT_JSON:{}", + json!({"standard":"familiar_season","version":"1.0.0","event":event,"data":[data]}) + )); +} +/// Maps docked cargo to goods through CARGO_GOODS. +pub fn cargo_goods(cargo: &[String]) -> [u64; 2] { + let mut out = [0u64; 2]; + for item in cargo { + if let Some((_, Some(g))) = CARGO_GOODS.iter().find(|(name, _)| name == item) { + out[*g] += 1; + } + } + out +} + +#[near(serializers = [borsh, json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Mint { + pub day: u64, + pub content_version: String, + pub tool: String, + pub goods: [u64; 2], + /// Haul and best haul at the shelf prices at docking (fixed point, scale 1e6). + pub value_fp: u64, + pub best_fp: u64, + /// value / best in basis points (10000 = the solver's best haul). + pub score_bp: u32, +} + +#[near(serializers = [borsh, json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Account { + pub shells: u64, + pub goods: [u64; 2], + pub trade_day: u64, + pub traded: [u32; 2], + pub last_mint: Option, + pub storage_deposit: NearToken, + pub storage_bytes: u64, +} +impl Account { + fn storage_available(&self) -> u128 { + self.storage_deposit + .as_yoctonear() + .saturating_sub(bytes_cost(self.storage_bytes)) + } +} + +#[near(serializers = [borsh, json])] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Shelf { + pub stock: u64, + /// Recent units bought, fixed point (scale 1e6), halving at each day boundary. + pub heat_fp: u64, + pub heat_day: u64, +} + +#[near(serializers = [borsh, json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Wish { + pub pet: String, + pub owner: AccountId, + pub good: String, + pub limit: u64, + pub qty: u8, + pub purse: u64, + pub seq: u64, + pub day: u64, +} + +#[near(serializers = [borsh, json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Trigger { + pub trade: u64, + pub account: AccountId, + pub side: String, + pub good: String, +} + +#[near(serializers = [borsh, json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Postcard { + pub pet: String, + pub owner: AccountId, + pub good: String, + pub qty: u8, + pub limit: u64, + /// `filled`, `cancelled` or `replaced`. + pub outcome: String, + /// `FILLED_ON_SET`, `FILLED_BY_TRADE`, `CANCELLED_BY_OWNER` or `REPLACED_BY_OWNER`. + pub reason: String, + pub unit_prices: Vec, + pub paid: u64, + pub refunded: u64, + pub trigger: Option, + pub day: u64, +} + +#[near(serializers = [json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct WishResult { + /// `filled`, `waiting` or `refused`. + pub status: String, + pub reason: String, + pub wish: Option, + pub postcard: Option, +} + +#[near(serializers = [json])] +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Trade { + pub seq: u64, + pub side: String, + pub good: String, + pub qty: u32, + pub unit_prices: Vec, + pub total: u64, + pub fills: Vec, +} + +#[near(serializers = [json])] +pub struct StorageBalance { + pub total: U128, + pub available: U128, +} + +#[near(serializers = [json])] +pub struct GoodView { + pub good: String, + pub stock: u64, + pub target: u64, + pub base: u64, + pub heat_fp: u64, + pub price_fp: u64, + pub buyback_fp: u64, + /// Whole Shells for the next unit bought from / sold to Bram. + pub buy_price: u64, + pub sell_price: u64, + pub waiting_wishes: u32, +} + +#[near(serializers = [json])] +pub struct ShelfView { + pub day: u64, + pub till: u64, + pub till_cap: u64, + pub till_refill: u64, + pub commission: u64, + pub goods: Vec, + pub shells_minted: u64, + pub goods_minted: [u64; 2], + pub trade_seq: u64, +} + +#[near(serializers = [json])] +pub struct ToolHaul { + pub tool: String, + pub hauls: Vec<[u64; 2]>, +} + +#[near(serializers = [json])] +pub struct TodayView { + pub day: u64, + pub next_day_ns: u64, + pub rules_version: String, + pub content_version: String, + pub area: String, + pub command_limit: u32, + pub mapping: Vec<(String, Option)>, + pub best_haul: Vec, + pub best_fp: u64, + pub minted_today: Option, + pub traded_today: Option<[u32; 2]>, +} + +#[near(contract_state)] +#[derive(PanicOnDefault)] +pub struct Season { + root: AccountId, + accounts: LookupMap, + wishes: LookupMap, + postcards: LookupMap, + shelf: [Shelf; 2], + till: u64, + till_day: u64, + queues: [Vec; 2], + trade_seq: u64, + wish_seq: u64, + /// Every Shell ever created (opening till plus refills); conserved across till, players and purses. + shells_minted: u64, + /// Every unit ever created (opening shelf plus daily mints); conserved across shelf and players. + goods_minted: [u64; 2], +} + +/// Pure shelf simulation shared by trades, wish fills and views. +fn quote_buy(shelf: &Shelf, g: usize, qty: u64) -> Result<(Shelf, Vec), &'static str> { + let mut s = *shelf; + let mut prices = Vec::with_capacity(qty as usize); + for _ in 0..qty { + if s.stock == 0 { + return Err("ERR_SHELF_EMPTY"); + } + let p = price_fp( + BASE[g], + TARGET[g], + u128::from(s.stock), + u128::from(s.heat_fp), + ); + prices.push(to_u64(buy_shells(p))); + s.stock -= 1; + s.heat_fp = s.heat_fp.saturating_add(S as u64); + } + Ok((s, prices)) +} +fn quote_sell(shelf: &Shelf, g: usize, qty: u64) -> (Shelf, Vec) { + let mut s = *shelf; + let mut prices = Vec::with_capacity(qty as usize); + for _ in 0..qty { + // Bram pays at the post-unit stock: rounding and order favour the till. + s.stock = s.stock.saturating_add(1); + let p = price_fp( + BASE[g], + TARGET[g], + u128::from(s.stock), + u128::from(s.heat_fp), + ); + prices.push(to_u64(sell_shells(p))); + } + (s, prices) +} +fn shelf_price_fp(s: &Shelf, g: usize) -> u128 { + price_fp( + BASE[g], + TARGET[g], + u128::from(s.stock), + u128::from(s.heat_fp), + ) +} + +#[near] +impl Season { + #[init] + #[private] + pub fn new(root: AccountId) -> Self { + require!( + env::current_account_id().as_str().ends_with(".testnet"), + "ERR_TESTNET_ONLY" + ); + let day = today(); + Self { + root, + accounts: LookupMap::new(b"a"), + wishes: LookupMap::new(b"w"), + postcards: LookupMap::new(b"p"), + shelf: [0, 1].map(|g| Shelf { + stock: START_STOCK[g], + heat_fp: 0, + heat_day: day, + }), + till: TILL_START, + till_day: day, + queues: [vec![], vec![]], + trade_seq: 0, + wish_seq: 0, + shells_minted: TILL_START, + goods_minted: START_STOCK, + } + } + + // ---------- storage ---------- + + /// One-time registration for the predecessor (at least `min_storage_deposit`), or a top-up. + #[payable] + pub fn storage_deposit(&mut self) -> StorageBalance { + let who = env::predecessor_account_id(); + let deposit = env::attached_deposit(); + let account = match self.accounts.get_mut(&who) { + Some(a) => { + a.storage_deposit = a.storage_deposit.saturating_add(deposit); + a.clone() + } + None => { + require!(deposit >= min_storage_deposit(), "ERR_STORAGE_DEPOSIT"); + let a = Account { + shells: 0, + goods: [0, 0], + trade_day: 0, + traded: [0, 0], + last_mint: None, + storage_deposit: deposit, + storage_bytes: ACCOUNT_BYTES, + }; + self.accounts.insert(who, a.clone()); + a + } + }; + Self::balance(&account) + } + + pub fn storage_balance_of(&self, account_id: AccountId) -> Option { + self.accounts.get(&account_id).map(Self::balance) + } + + pub fn storage_minimum(&self) -> NearToken { + min_storage_deposit() + } + + /// Withdraw deposit not covering charged storage. Charged bytes are never refunded: + /// account and pet records persist. Requires exactly one yoctoNEAR (full-access key). + #[payable] + pub fn storage_withdraw(&mut self) -> Promise { + require!( + env::attached_deposit() == NearToken::from_yoctonear(1), + "ERR_ONE_YOCTO" + ); + let who = env::predecessor_account_id(); + let account = self + .accounts + .get_mut(&who) + .unwrap_or_else(|| env::panic_str("ERR_NOT_REGISTERED")); + let amount = account.storage_available(); + require!(amount > 0, "ERR_NOTHING_TO_WITHDRAW"); + account.storage_deposit = + NearToken::from_yoctonear(account.storage_deposit.as_yoctonear() - amount); + Promise::new(who.clone()) + .transfer(NearToken::from_yoctonear(amount + 1)) + .then( + Self::ext(env::current_account_id()) + .with_static_gas(Gas::from_tgas(5)) + .on_storage_withdraw(who, U128(amount)), + ) + } + + /// Restores the deposit if the refund transfer failed. Never panics. + #[private] + pub fn on_storage_withdraw(&mut self, account_id: AccountId, amount: U128) -> bool { + if familiar_common::promise_succeeded() { + return true; + } + if let Some(a) = self.accounts.get_mut(&account_id) { + a.storage_deposit = a + .storage_deposit + .saturating_add(NearToken::from_yoctonear(amount.0)); + } + false + } + + // ---------- daily court ---------- + + /// Replays today's court and mints the cargo that docked, once per account per day. + pub fn claim_daily( + &mut self, + rules_version: String, + content_version: String, + tool: String, + area: String, + commands: Vec, + ) -> Mint { + let who = env::predecessor_account_id(); + let day = today(); + let court_index = court_of(day); + require!( + rules_version == storycraft::RULES_VERSION, + "ERR_RULES_VERSION" + ); + require!(content_version == COURTS[court_index], "ERR_WRONG_COURT"); + let limit = if court_index == 0 { 15 } else { 24 }; + require!( + commands.len() <= limit && commands.iter().all(|s| s.len() <= COMMAND_LEN_MAX), + "ERR_COMMAND_BOUND" + ); + let tool_index = TOOLS + .iter() + .position(|t| *t == tool) + .unwrap_or_else(|| env::panic_str("ERR_REPLAY_CONTEXT")); + require!(area == COURT_AREA, "ERR_REPLAY_CONTEXT"); + let account = self + .accounts + .get(&who) + .unwrap_or_else(|| env::panic_str("ERR_NOT_REGISTERED")); + require!( + account.last_mint.as_ref().is_none_or(|m| m.day != day), + "ERR_ALREADY_MINTED" + ); + let (cargo, outcome) = if court_index == 0 { + let run = historical_returns::replay(&tool, &[], &commands, &area) + .unwrap_or_else(|_| env::panic_str("ERR_REPLAY")); + (run.cargo, run.outcome) + } else { + let run = court::replay(&tool, &[], &commands, &area) + .unwrap_or_else(|_| env::panic_str("ERR_REPLAY")); + (run.cargo, run.outcome) + }; + require!(outcome == "returned", "ERR_RETURN_REQUIRED"); + let goods = cargo_goods(&cargo); + require!(goods[0] + goods[1] > 0, "ERR_NO_GOODS"); + require!( + BEST_HAUL[court_index][tool_index] + .iter() + .any(|b| goods[0] <= b.0 && goods[1] <= b.1), + "ERR_HAUL_BOUND" + ); + self.settle(day); + let prices = [0, 1].map(|g| shelf_price_fp(&self.shelf[g], g)); + let value = |h: (u64, u64)| u128::from(h.0) * prices[0] + u128::from(h.1) * prices[1]; + let value_fp = value((goods[0], goods[1])); + let best_fp = BEST_HAUL[court_index] + .iter() + .flat_map(|t| t.iter()) + .map(|h| value(*h)) + .max() + .unwrap_or(1) + .max(1); + let mint = Mint { + day, + content_version, + tool, + goods, + value_fp: to_u64(value_fp), + best_fp: to_u64(best_fp), + score_bp: u32::try_from(value_fp * 10_000 / best_fp).unwrap_or(10_000), + }; + let account = self.accounts.get_mut(&who).expect("registered"); + for (g, units) in goods.iter().enumerate() { + account.goods[g] += units; + self.goods_minted[g] += units; + } + account.last_mint = Some(mint.clone()); + emit( + "mint", + json!({"account_id": who, "day": day, "content_version": mint.content_version, "tool": mint.tool, + "commands": commands, "cargo": cargo, "glass": goods[0], "reed": goods[1], + "value_fp": mint.value_fp, "best_fp": mint.best_fp, "score_bp": mint.score_bp}), + ); + mint + } + + // ---------- Bram ---------- + + /// Buy `qty` units; refuses if any unit costs more than `max_price` Shells. + pub fn buy(&mut self, good: String, qty: u32, max_price: u64) -> Trade { + self.trade(good, qty, max_price, true) + } + + /// Sell `qty` units; refuses if any unit pays less than `min_price` Shells. + pub fn sell(&mut self, good: String, qty: u32, min_price: u64) -> Trade { + self.trade(good, qty, min_price, false) + } + + // ---------- Mochi's wish ---------- + + /// Places a wish for `pet` (the caller must own it on Root). The purse is `limit × qty` + /// Shells (at most 24), taken only after the owner check succeeds. + pub fn set_wish(&mut self, pet: String, good: String, limit: u64, qty: u8) -> Promise { + let owner = env::predecessor_account_id(); + require!(!pet.is_empty() && pet.len() <= PET_ID_MAX, "ERR_PET_ID"); + require!(good_index(&good).is_some(), "ERR_GOOD"); + require!((1..=WISH_QTY_MAX).contains(&qty), "ERR_WISH_QTY"); + require!( + limit >= 1 && limit.saturating_mul(u64::from(qty)) <= PURSE_MAX, + "ERR_PURSE_LIMIT" + ); + let account = self + .accounts + .get(&owner) + .unwrap_or_else(|| env::panic_str("ERR_NOT_REGISTERED")); + require!(account.shells >= limit * u64::from(qty), "ERR_SHELLS"); + require!(env::prepaid_gas() >= Gas::from_tgas(60), "ERR_GAS"); + Promise::new(self.root.clone()) + .function_call( + "nft_token".to_owned(), + serde_json::to_vec(&json!({ "token_id": pet })).unwrap_or_default(), + NearToken::from_yoctonear(0), + Gas::from_tgas(10), + ) + .then( + Self::ext(env::current_account_id()) + .with_static_gas(Gas::from_tgas(35)) + .on_wish_owner(owner, pet, good, limit, qty), + ) + } + + /// Ownership callback. Never panics; on any failure nothing is held or changed. + #[private] + pub fn on_wish_owner( + &mut self, + owner: AccountId, + pet: String, + good: String, + limit: u64, + qty: u8, + ) -> WishResult { + let reason = match Self::token_owner() { + Err(r) => Some(r), + Ok(found) if found != owner => Some("ERR_NOT_OWNER"), + Ok(_) => None, + }; + let result = match reason { + Some(r) => Err(r), + None => self.place_wish(owner.clone(), pet.clone(), good.clone(), limit, qty), + }; + match result { + Ok(r) => r, + Err(reason) => { + emit( + "wish_refused", + json!({"pet": pet, "owner": owner, "good": good, "limit": limit, "qty": qty, "reason": reason}), + ); + WishResult { + status: "refused".into(), + reason: reason.into(), + wish: None, + postcard: None, + } + } + } + } + + /// Returns the purse to the wish's owner (the account that funded it). + pub fn cancel_wish(&mut self, pet: String) -> Postcard { + let wish = self + .wishes + .get(&pet) + .cloned() + .unwrap_or_else(|| env::panic_str("ERR_NO_WISH")); + require!( + env::predecessor_account_id() == wish.owner, + "ERR_NOT_WISH_OWNER" + ); + let card = self.close_wish(&wish, "cancelled", "CANCELLED_BY_OWNER"); + emit("wish_cancel", json!(card)); + card + } + + // ---------- views ---------- + + pub fn get_shelf(&self) -> ShelfView { + let day = today(); + let (shelf, till, added) = self.settled(day); + let goods = (0..2) + .map(|g| { + let p = shelf_price_fp(&shelf[g], g); + GoodView { + good: GOODS[g].into(), + stock: shelf[g].stock, + target: TARGET[g] as u64, + base: BASE[g] as u64, + heat_fp: shelf[g].heat_fp, + price_fp: to_u64(p), + buyback_fp: to_u64(buyback_fp(p)), + buy_price: quote_buy(&shelf[g], g, 1).map(|(_, p)| p[0]).unwrap_or(0), + sell_price: quote_sell(&shelf[g], g, 1).1[0], + waiting_wishes: self.queues[g].len() as u32, + } + }) + .collect(); + ShelfView { + day, + till, + till_cap: TILL_CAP, + till_refill: TILL_REFILL, + commission: to_u64(commission( + shelf_price_fp(&shelf[GLASS], GLASS), + BASE[GLASS], + )), + goods, + shells_minted: self.shells_minted + added, + goods_minted: self.goods_minted, + trade_seq: self.trade_seq, + } + } + + pub fn get_today(&self, account_id: Option) -> TodayView { + let day = today(); + let c = court_of(day); + let (shelf, _, _) = self.settled(day); + let prices = [0, 1].map(|g| shelf_price_fp(&shelf[g], g)); + let account = account_id.and_then(|a| self.accounts.get(&a).cloned()); + TodayView { + day, + next_day_ns: (day + 1) * DAY_NS, + rules_version: storycraft::RULES_VERSION.into(), + content_version: COURTS[c].into(), + area: COURT_AREA.into(), + command_limit: if c == 0 { 15 } else { 24 }, + mapping: CARGO_GOODS + .iter() + .map(|(item, g)| ((*item).into(), g.map(|g| GOODS[g].to_string()))) + .collect(), + best_haul: (0..2) + .map(|t| ToolHaul { + tool: TOOLS[t].into(), + hauls: BEST_HAUL[c][t].iter().map(|h| [h.0, h.1]).collect(), + }) + .collect(), + best_fp: BEST_HAUL[c] + .iter() + .flat_map(|t| t.iter()) + .map(|h| to_u64(u128::from(h.0) * prices[0] + u128::from(h.1) * prices[1])) + .max() + .unwrap_or(0), + minted_today: account + .as_ref() + .and_then(|a| a.last_mint.clone()) + .filter(|m| m.day == day), + traded_today: account + .as_ref() + .map(|a| if a.trade_day == day { a.traded } else { [0, 0] }), + } + } + + pub fn get_wish(&self, pet: String) -> Option { + self.wishes.get(&pet).cloned() + } + + pub fn get_postcard(&self, pet: String) -> Option { + self.postcards.get(&pet).cloned() + } + + pub fn get_account(&self, account_id: AccountId) -> Option { + self.accounts.get(&account_id).cloned() + } + + pub fn get_wish_queue(&self, good: String) -> Vec { + good_index(&good) + .map(|g| self.queues[g].clone()) + .unwrap_or_default() + } + + pub fn get_root(&self) -> AccountId { + self.root.clone() + } +} + +impl Season { + fn balance(a: &Account) -> StorageBalance { + StorageBalance { + total: U128(a.storage_deposit.as_yoctonear()), + available: U128(a.storage_available()), + } + } + + /// Lazy day effects: heat halving and till refill. Returns the shelf, till and Shells added. + fn settled(&self, day: u64) -> ([Shelf; 2], u64, u64) { + let shelf = self.shelf.map(|s| { + if s.heat_day < day { + Shelf { + stock: s.stock, + heat_fp: to_u64(decay_heat(u128::from(s.heat_fp), day - s.heat_day)), + heat_day: day, + } + } else { + s + } + }); + let mut till = self.till; + if self.till_day < day && till < TILL_CAP { + till = till + .saturating_add(TILL_REFILL.saturating_mul(day - self.till_day)) + .min(TILL_CAP); + } + (shelf, till, till - self.till.min(till)) + } + fn settle(&mut self, day: u64) { + let (shelf, till, added) = self.settled(day); + self.shelf = shelf; + self.till = till; + self.till_day = self.till_day.max(day); + self.shells_minted = self.shells_minted.saturating_add(added); + } + + fn trade(&mut self, good: String, qty: u32, bound: u64, buying: bool) -> Trade { + let who = env::predecessor_account_id(); + let g = good_index(&good).unwrap_or_else(|| env::panic_str("ERR_GOOD")); + require!((1..=TRADE_QTY_MAX).contains(&qty), "ERR_TRADE_QTY"); + let day = today(); + let mut account = self + .accounts + .get(&who) + .cloned() + .unwrap_or_else(|| env::panic_str("ERR_NOT_REGISTERED")); + if account.trade_day != day { + account.trade_day = day; + account.traded = [0, 0]; + } + require!(account.traded[g] + qty <= DAILY_UNITS, "ERR_DAILY_LIMIT"); + self.settle(day); + let (after, prices) = if buying { + quote_buy(&self.shelf[g], g, u64::from(qty)).unwrap_or_else(|e| env::panic_str(e)) + } else { + quote_sell(&self.shelf[g], g, u64::from(qty)) + }; + let total: u64 = prices.iter().sum(); + if buying { + require!(prices.iter().all(|p| *p <= bound), "ERR_MAX_PRICE"); + require!(account.shells >= total, "ERR_SHELLS"); + account.shells -= total; + account.goods[g] += u64::from(qty); + self.till += total; + } else { + require!(prices.iter().all(|p| *p >= bound), "ERR_MIN_PRICE"); + require!(account.goods[g] >= u64::from(qty), "ERR_GOODS"); + require!(self.till >= total, "ERR_TILL_EMPTY"); + account.goods[g] -= u64::from(qty); + account.shells += total; + self.till -= total; + } + account.traded[g] += qty; + self.shelf[g] = after; + self.accounts.insert(who.clone(), account); + self.trade_seq += 1; + let side = if buying { "buy" } else { "sell" }; + emit( + "trade", + json!({"seq": self.trade_seq, "account_id": who, "side": side, "good": good, + "qty": qty, "unit_prices": prices, "total": total, "till": self.till, + "stock": self.shelf[g].stock}), + ); + let trigger = Trigger { + trade: self.trade_seq, + account: who, + side: side.into(), + good: good.clone(), + }; + let fills = self.fill_wishes(g, &trigger); + Trade { + seq: self.trade_seq, + side: side.into(), + good, + qty, + unit_prices: prices, + total, + fills, + } + } + + /// Fills waiting wishes for good `g` in arrival order, at most FILLS_PER_TX. Never panics. + fn fill_wishes(&mut self, g: usize, trigger: &Trigger) -> Vec { + let mut fills = vec![]; + let mut i = 0; + while i < self.queues[g].len() && fills.len() < FILLS_PER_TX { + let pet = self.queues[g][i].clone(); + match self.try_fill(&pet, Some(trigger)) { + Some(card) => { + self.queues[g].remove(i); + fills.push(card); + } + None => i += 1, + } + } + fills + } + + /// Fills one wish if every unit is at or below its limit. Never panics. + fn try_fill(&mut self, pet: &str, trigger: Option<&Trigger>) -> Option { + let wish = self.wishes.get(pet)?.clone(); + let g = good_index(&wish.good)?; + let (after, prices) = quote_buy(&self.shelf[g], g, u64::from(wish.qty)).ok()?; + let paid: u64 = prices.iter().sum(); + if prices.iter().any(|p| *p > wish.limit) || paid > wish.purse { + return None; + } + let refunded = wish.purse - paid; + let owner = self.accounts.get_mut(&wish.owner)?; + owner.goods[g] += u64::from(wish.qty); + owner.shells += refunded; + self.shelf[g] = after; + self.till += paid; + self.wishes.remove(pet); + let card = Postcard { + pet: wish.pet.clone(), + owner: wish.owner.clone(), + good: wish.good.clone(), + qty: wish.qty, + limit: wish.limit, + outcome: "filled".into(), + reason: if trigger.is_some() { + "FILLED_BY_TRADE" + } else { + "FILLED_ON_SET" + } + .into(), + unit_prices: prices, + paid, + refunded, + trigger: trigger.cloned(), + day: today(), + }; + self.postcards.insert(pet.to_owned(), card.clone()); + emit("wish_fill", json!(card)); + Some(card) + } + + /// Removes a waiting wish, refunds its purse to its owner and records the postcard. + fn close_wish(&mut self, wish: &Wish, outcome: &str, reason: &str) -> Postcard { + if let Some(g) = good_index(&wish.good) { + self.queues[g].retain(|p| *p != wish.pet); + } + self.wishes.remove(&wish.pet); + if let Some(a) = self.accounts.get_mut(&wish.owner) { + a.shells += wish.purse; + } + let card = Postcard { + pet: wish.pet.clone(), + owner: wish.owner.clone(), + good: wish.good.clone(), + qty: wish.qty, + limit: wish.limit, + outcome: outcome.into(), + reason: reason.into(), + unit_prices: vec![], + paid: 0, + refunded: wish.purse, + trigger: None, + day: today(), + }; + self.postcards.insert(wish.pet.clone(), card.clone()); + card + } + + /// Owner from Root's `nft_token` result, read defensively. + fn token_owner() -> Result { + if env::promise_results_count() != 1 { + return Err("ERR_OWNER_LOOKUP"); + } + let bytes = env::promise_result_checked(0, 16_384).map_err(|_| "ERR_OWNER_LOOKUP")?; + let value: Value = serde_json::from_slice(&bytes).map_err(|_| "ERR_OWNER_LOOKUP")?; + value + .get("owner_id") + .and_then(Value::as_str) + .and_then(|s| s.parse().ok()) + .ok_or("ERR_NOT_OWNER") + } + + /// All checks run before any write, so a refusal leaves state untouched. + fn place_wish( + &mut self, + owner: AccountId, + pet: String, + good: String, + limit: u64, + qty: u8, + ) -> Result { + let g = good_index(&good).ok_or("ERR_GOOD")?; + if pet.is_empty() || pet.len() > PET_ID_MAX { + return Err("ERR_PET_ID"); + } + if !(1..=WISH_QTY_MAX).contains(&qty) || limit == 0 { + return Err("ERR_WISH_QTY"); + } + let purse = limit.saturating_mul(u64::from(qty)); + if purse > PURSE_MAX { + return Err("ERR_PURSE_LIMIT"); + } + let account = self.accounts.get(&owner).ok_or("ERR_NOT_REGISTERED")?; + let existing = self.wishes.get(&pet).cloned(); + let refund_to_self = existing + .as_ref() + .filter(|w| w.owner == owner) + .map_or(0, |w| w.purse); + if account.shells.saturating_add(refund_to_self) < purse { + return Err("ERR_SHELLS"); + } + let new_record = existing.is_none() && !self.postcards.contains_key(&pet); + if new_record && account.storage_available() < bytes_cost(PET_BYTES) { + return Err("ERR_STORAGE"); + } + let queued = self.queues[g].len().saturating_sub(usize::from( + existing.as_ref().is_some_and(|w| w.good == good), + )); + if queued >= WISH_QUEUE_CAP { + return Err("ERR_WISH_QUEUE_FULL"); + } + // Commit. + if let Some(old) = existing { + let card = self.close_wish(&old, "replaced", "REPLACED_BY_OWNER"); + emit("wish_cancel", json!(card)); + } + let day = today(); + self.settle(day); + let account = self.accounts.get_mut(&owner).ok_or("ERR_NOT_REGISTERED")?; + if new_record { + account.storage_bytes += PET_BYTES; + } + account.shells -= purse; + self.wish_seq += 1; + let wish = Wish { + pet: pet.clone(), + owner, + good, + limit, + qty, + purse, + seq: self.wish_seq, + day, + }; + self.wishes.insert(pet.clone(), wish.clone()); + emit("wish_set", json!(wish)); + if let Some(card) = self.try_fill(&pet, None) { + return Ok(WishResult { + status: "filled".into(), + reason: card.reason.clone(), + wish: None, + postcard: Some(card), + }); + } + self.queues[g].push(pet); + Ok(WishResult { + status: "waiting".into(), + reason: "WAITING".into(), + wish: Some(wish), + postcard: None, + }) + } +} diff --git a/contracts/season/src/pricing.rs b/contracts/season/src/pricing.rs new file mode 100644 index 0000000..0e75faf --- /dev/null +++ b/contracts/season/src/pricing.rs @@ -0,0 +1,140 @@ +//! Bram's integer pricing. Mirrored exactly by `web/src/season/pricing.ts` (BigInt). +//! +//! Every quantity carrying `_fp` is fixed point with scale `S = 1_000_000`. +//! Rounding rule: every division floors (all operands are unsigned). Converting a +//! price to whole Shells rounds in the till's favour: a player buys a unit for +//! `ceil(price_fp / S)` and sells a unit for `floor(buyback_fp / S)`. +//! +//! price(g) = base × clamp((target / max(stock, 1))^0.7, 0.5, 3.0) × (1 + 0.15 × heat) +//! buyback(g) = 0.8 × price(g) +//! heat = heat_units / target, where heat_units halves at each day boundary +//! commission = clamp(12 × price(glass) / base_glass, 6, 36) +//! +//! x^0.7 = x^(1/2) × x^(1/5), computed as floor roots of scaled integers: +//! pow07(X) = floor(isqrt(X × S) × iroot5(X × S^4) / S), with X clamped to +//! [RATIO_MIN, RATIO_MAX] first so every intermediate fits in u128 (≤ 5e30). + +pub const S: u128 = 1_000_000; +/// Ratios outside this range are clamped before the power; 0.3^0.7 < 0.5 and 5^0.7 > 3, +/// so the output clamp still decides the result at both ends. +pub const RATIO_MIN: u128 = 300_000; +pub const RATIO_MAX: u128 = 5_000_000; +pub const POW_MIN: u128 = 500_000; +pub const POW_MAX: u128 = 3_000_000; +/// After this many halvings any reachable heat is zero; also keeps the shift in range. +pub const HEAT_HALVINGS_CAP: u64 = 64; + +pub fn isqrt(n: u128) -> u128 { + let (mut lo, mut hi) = (0u128, 1u128 << 64); + // Invariant: lo^2 <= n < hi^2. + while hi - lo > 1 { + let mid = lo + (hi - lo) / 2; + if mid * mid <= n { lo = mid } else { hi = mid } + } + lo +} + +pub fn iroot5(n: u128) -> u128 { + // 2^25^5 = 2^125 < 2^128, and every n here is below 2^103. + let (mut lo, mut hi) = (0u128, 1u128 << 25); + while hi - lo > 1 { + let mid = lo + (hi - lo) / 2; + if mid * mid * mid * mid * mid <= n { + lo = mid + } else { + hi = mid + } + } + lo +} + +/// x^0.7 for a fixed-point ratio, already clamped to [POW_MIN, POW_MAX]. +pub fn pow07(ratio_fp: u128) -> u128 { + let x = ratio_fp.clamp(RATIO_MIN, RATIO_MAX); + let half = isqrt(x * S); + let fifth = iroot5(x * S * S * S * S); + (half * fifth / S).clamp(POW_MIN, POW_MAX) +} + +/// Heat units (fixed point) after `days` day boundaries of halving. +pub fn decay_heat(heat_units_fp: u128, days: u64) -> u128 { + if days >= HEAT_HALVINGS_CAP { + 0 + } else { + heat_units_fp >> days + } +} + +pub fn price_fp(base: u128, target: u128, stock: u128, heat_units_fp: u128) -> u128 { + let ratio = target * S / stock.max(1); + let heat_fp = heat_units_fp / target; + let mult = S + heat_fp * 3 / 20; + base * pow07(ratio) * mult / S +} + +pub fn buyback_fp(price_fp: u128) -> u128 { + price_fp * 4 / 5 +} + +/// Whole Shells a player pays for one unit. +pub fn buy_shells(price_fp: u128) -> u128 { + price_fp.div_ceil(S) +} + +/// Whole Shells Bram pays for one unit. +pub fn sell_shells(price_fp: u128) -> u128 { + buyback_fp(price_fp) / S +} + +pub fn commission(glass_price_fp: u128, glass_base: u128) -> u128 { + (12 * glass_price_fp / (glass_base * S)).clamp(6, 36) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn roots_are_exact_floors() { + for n in [0u128, 1, 2, 3, 4, 15, 16, 17, 1 << 40, u64::MAX as u128] { + let r = isqrt(n); + assert!(r * r <= n && (r + 1) * (r + 1) > n); + } + for n in [0u128, 1, 31, 32, 33, 243, 5_000_000 * S * S * S * S] { + let r = iroot5(n); + assert!(r.pow(5) <= n && (r + 1).pow(5) > n); + } + } + + #[test] + fn power_matches_the_formula_closely_and_clamps() { + assert_eq!(pow07(S), S); + // 2^0.7 = 1.6245, 0.5^0.7 = 0.6156. + assert!(pow07(2 * S).abs_diff(1_624_504) <= 3); + assert!(pow07(S / 2).abs_diff(615_572) <= 3); + assert_eq!(pow07(0), POW_MIN); + assert_eq!(pow07(u64::MAX as u128), POW_MAX); + let mut last = 0; + for x in (0..6_000_000).step_by(997) { + let p = pow07(x); + assert!(p >= last, "monotone at {x}"); + last = p; + } + } + + #[test] + fn start_prices_and_commission() { + assert_eq!(price_fp(8, 40, 40, 0), 8 * S); + assert_eq!(price_fp(4, 40, 40, 0), 4 * S); + assert_eq!(buy_shells(8 * S), 8); + assert_eq!(sell_shells(8 * S), 6); + assert_eq!(sell_shells(4 * S), 3); + assert_eq!(commission(8 * S, 8), 12); + assert_eq!(commission(price_fp(8, 40, 1, 0), 8), 36); + assert_eq!(commission(price_fp(8, 40, 10_000, 0), 8), 6); + // 40 recent units on a target of 40: heat 1 adds 15%. + assert_eq!(price_fp(8, 40, 40, 40 * S), 9_200_000); + assert_eq!(decay_heat(40 * S, 1), 20 * S); + assert_eq!(decay_heat(u128::MAX, 200), 0); + } +} diff --git a/contracts/season/src/tests.rs b/contracts/season/src/tests.rs new file mode 100644 index 0000000..d57de14 --- /dev/null +++ b/contracts/season/src/tests.rs @@ -0,0 +1,1342 @@ +#![allow(clippy::too_many_arguments, clippy::needless_range_loop)] +use super::*; +use near_sdk::{PromiseResult, test_utils::VMContextBuilder, testing_env}; + +const SEASON: &str = "season.familiar-game.testnet"; +const ROOT: &str = "familiar-game.testnet"; +/// An even day (first_light_v1) a little after midnight. +const DAY0: u64 = 20_400; + +fn id(s: &str) -> AccountId { + s.parse().unwrap() +} +fn ctx(who: &str, day: u64, deposit: u128) -> VMContextBuilder { + let mut b = VMContextBuilder::new(); + b.current_account_id(id(SEASON)) + .predecessor_account_id(id(who)) + .signer_account_id(id(who)) + .block_timestamp(day * DAY_NS + 1_000) + .attached_deposit(NearToken::from_yoctonear(deposit)) + .prepaid_gas(Gas::from_tgas(300)) + .account_balance(NearToken::from_near(100)); + b +} +fn at(who: &str, day: u64) { + testing_env!(ctx(who, day, 0).build()); +} +fn callback(day: u64, result: PromiseResult) { + testing_env!( + ctx(SEASON, day, 0).build(), + near_sdk::test_vm_config(), + near_sdk::RuntimeFeesConfig::test(), + Default::default(), + vec![result] + ); +} +fn owner_is(who: &str) -> PromiseResult { + PromiseResult::Successful( + serde_json::to_vec(&json!({"token_id": "mochi", "owner_id": who, "metadata": null})) + .unwrap(), + ) +} +fn strings(v: &[&str]) -> Vec { + v.iter().map(|s| (*s).into()).collect() +} +fn setup() -> Season { + near_sdk::mock::with_mocked_blockchain(|b| { + b.take_storage(); + }); + at(SEASON, DAY0); + Season::new(id(ROOT)) +} +fn register(c: &mut Season, who: &str, day: u64) { + testing_env!(ctx(who, day, min_storage_deposit().as_yoctonear()).build()); + c.storage_deposit(); +} +/// lens + chart on the v1 lantern route (Season 1 golden fixture). +fn v1_lantern() -> Vec { + strings(&[ + "wait", + "wait", + "lure:left", + "take:chart", + "move:left", + "take:lens", + "move:center", + "return", + ]) +} +fn claim(c: &mut Season, who: &str, day: u64, tool: &str, commands: Vec) -> Mint { + at(who, day); + c.claim_daily( + storycraft::RULES_VERSION.into(), + COURTS[court_of(day)].into(), + tool.into(), + COURT_AREA.into(), + commands, + ) +} +fn wish( + c: &mut Season, + who: &str, + day: u64, + pet: &str, + good: &str, + limit: u64, + qty: u8, + owner: &str, +) -> WishResult { + at(who, day); + let _ = c.set_wish(pet.into(), good.into(), limit, qty); + callback(day, owner_is(owner)); + c.on_wish_owner(id(who), pet.into(), good.into(), limit, qty) +} + +impl Season { + fn credit(&mut self, who: &str, goods: [u64; 2]) { + let a = self.accounts.get_mut(&id(who)).unwrap(); + for g in 0..2 { + a.goods[g] += goods[g]; + self.goods_minted[g] += goods[g]; + } + } + fn assert_conserved(&self, accounts: &[&str]) { + let mut shells = self.till; + let mut goods = [self.shelf[0].stock, self.shelf[1].stock]; + for who in accounts { + if let Some(a) = self.accounts.get(&id(who)) { + shells += a.shells; + goods[0] += a.goods[0]; + goods[1] += a.goods[1]; + } + } + let mut queued = 0; + for q in &self.queues { + for pet in q { + let w = self.wishes.get(pet).expect("queued wish exists"); + assert!(w.purse <= PURSE_MAX); + shells += w.purse; + queued += 1; + } + } + assert!(queued <= 2 * WISH_QUEUE_CAP); + assert_eq!(shells, self.shells_minted, "Shells conserved"); + assert_eq!(goods, self.goods_minted, "goods conserved"); + } + fn shells(&self, who: &str) -> u64 { + self.accounts.get(&id(who)).map_or(0, |a| a.shells) + } + fn goods(&self, who: &str) -> [u64; 2] { + self.accounts.get(&id(who)).map_or([0, 0], |a| a.goods) + } +} + +// ---------- daily court ---------- + +#[test] +fn daily_court_alternates_and_mints_docked_cargo_once() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + let m = claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()); + assert_eq!(m.content_version, "first_light_v1"); + assert_eq!(m.goods, [1, 1]); + // At start prices: 8 + 4 = 12 against the best haul 8 + 2×4 = 16. + assert_eq!(m.value_fp, 12 * S as u64); + assert_eq!(m.best_fp, 16 * S as u64); + assert_eq!(m.score_bp, 7_500); + assert_eq!(c.goods("alice.testnet"), [1, 1]); + // Next day is first_light_v2. + at("alice.testnet", DAY0 + 1); + assert_eq!(c.get_today(None).content_version, "first_light_v2"); + c.assert_conserved(&["alice.testnet"]); +} + +#[test] +fn v2_days_replay_the_spatial_court() { + let mut c = setup(); + let day = DAY0 + 1; + register(&mut c, "alice.testnet", day); + // Dry rope lens route on the spatial court. + let commands = strings(&[ + "step:north", + "step:north", + "step:west", + "wait", + "wait", + "step:east", + "reel:lens", + "step:west", + "step:east", + "step:west", + "step:south", + "step:south", + "step:east", + "return", + ]); + let run = court::replay("rope", &[], &commands, "beacon").unwrap(); + assert_eq!( + (run.outcome.as_str(), run.cargo.clone()), + ("returned", strings(&["lens"])) + ); + let m = claim(&mut c, "alice.testnet", day, "rope", commands); + assert_eq!(m.goods, [1, 0]); + // The best v2 haul is lens + moth: 8 / (8 + 4) at opening prices. + assert_eq!(m.score_bp, 6_666); + // The rope rescue route docks lens and moth: glass + reed, the full score. + register(&mut c, "bob.testnet", day); + let rescue = strings(&[ + "step:north", + "step:north", + "step:west", + "wait", + "wait", + "step:east", + "reel:lens", + "step:east", + "step:west", + "step:east", + "take:moth", + "step:west", + "step:east", + "step:south", + "step:west", + "step:south", + "return", + ]); + let m = claim(&mut c, "bob.testnet", day, "rope", rescue); + assert_eq!(m.goods, [1, 1]); + assert_eq!(m.score_bp, 10_000); +} + +#[test] +fn minted_cargo_never_exceeds_the_best_haul() { + // Every random legal outing that docks mints a haul dominated by BEST_HAUL. + for (court_index, day) in [(0usize, DAY0), (1, DAY0 + 1)] { + for (t, tool) in TOOLS.iter().enumerate() { + let mut seed: u32 = 7 + t as u32; + for _ in 0..300 { + let mut commands: Vec = vec![]; + loop { + let legal = if court_index == 0 { + let r = historical_returns::replay(tool, &[], &commands, "beacon").unwrap(); + if r.outcome != "active" { + break; + } + historical_returns::legal_actions(&r) + } else { + let r = court::replay(tool, &[], &commands, "beacon").unwrap(); + if r.outcome != "active" { + break; + } + court::legal_actions(&r) + }; + if legal.is_empty() { + break; + } + seed = seed.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); + commands.push(legal[(seed >> 8) as usize % legal.len()].clone()); + } + let cargo = if court_index == 0 { + let r = historical_returns::replay(tool, &[], &commands, "beacon").unwrap(); + (r.outcome == "returned").then_some(r.cargo) + } else { + let r = court::replay(tool, &[], &commands, "beacon").unwrap(); + (r.outcome == "returned").then_some(r.cargo) + }; + if let Some(cargo) = cargo { + let g = cargo_goods(&cargo); + assert!( + BEST_HAUL[court_index][t] + .iter() + .any(|b| g[0] <= b.0 && g[1] <= b.1), + "{tool} {commands:?}" + ); + if g[0] + g[1] > 0 { + let mut c = setup(); + register(&mut c, "p.testnet", day); + let m = claim(&mut c, "p.testnet", day, tool, commands); + assert!(m.score_bp <= 10_000 && m.value_fp <= m.best_fp); + } + } + } + } + } +} + +#[test] +fn best_haul_constants_match_the_generated_fixture_and_the_authoritative_replay() { + let fixture: Value = serde_json::from_str(include_str!("../fixtures/best-haul.json")).unwrap(); + for (ci, court_entry) in fixture.as_array().unwrap().iter().enumerate() { + assert_eq!(court_entry["content_version"], COURTS[ci]); + for (ti, tool) in court_entry["tools"].as_array().unwrap().iter().enumerate() { + assert_eq!(tool["tool"], TOOLS[ti]); + let hauls: Vec<(u64, u64)> = tool["hauls"] + .as_array() + .unwrap() + .iter() + .map(|h| (h[0].as_u64().unwrap(), h[1].as_u64().unwrap())) + .collect(); + assert_eq!(hauls, BEST_HAUL[ci][ti]); + } + } + // Exhaustive search over the contract's own replay, independent of the TypeScript solver. + for ci in 0..2 { + for (ti, tool) in TOOLS.iter().enumerate() { + let mut found = std::collections::HashSet::new(); + let mut seen = std::collections::HashSet::new(); + let mut queue: Vec> = vec![vec![]]; + let mut i = 0; + while i < queue.len() { + let commands = queue[i].clone(); + i += 1; + let (legal, key) = if ci == 0 { + let r = historical_returns::replay(tool, &[], &commands, "beacon").unwrap(); + if r.outcome == "returned" { + let g = cargo_goods(&r.cargo); + found.insert((g[0], g[1])); + } + if r.outcome != "active" { + continue; + } + let mut opened = r.opened.clone(); + opened.sort(); + let mut cargo = r.cargo.clone(); + cargo.sort(); + let key = format!( + "{}/{}/{}/{}/{}/{:?}/{:?}/{:?}", + r.lane, + r.turn % 3, + r.resolve, + r.uses, + r.orientation, + r.locked, + opened, + cargo + ); + (historical_returns::legal_actions(&r), key) + } else { + let r = court::replay(tool, &[], &commands, "beacon").unwrap(); + if r.outcome == "returned" { + let g = cargo_goods(&r.cargo); + found.insert((g[0], g[1])); + } + if r.outcome != "active" { + continue; + } + let mut opened = r.opened.clone(); + opened.sort(); + let mut cargo = r.cargo.clone(); + cargo.sort(); + let key = format!( + "{:?}/{}/{}/{}/{}/{:?}/{}/{:?}/{:?}", + r.position, + r.turn % 3, + r.resolve, + r.uses, + r.orientation, + r.locked, + r.bridge, + opened, + cargo + ); + (court::legal_actions(&r), key) + }; + if !seen.insert(key) { + continue; + } + for a in legal { + let mut next = commands.clone(); + next.push(a); + queue.push(next); + } + } + let mut pareto: Vec<(u64, u64)> = found + .iter() + .copied() + .filter(|&(g, r)| { + !found + .iter() + .any(|&(g2, r2)| g2 >= g && r2 >= r && (g2, r2) != (g, r)) + }) + .collect(); + pareto.sort_by(|a, b| b.cmp(a)); + assert_eq!(pareto, BEST_HAUL[ci][ti], "court {ci} tool {tool}"); + } + } +} + +#[test] +fn break_second_mint_same_day() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()); + let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()) + })); + assert!(r.is_err()); + // Two days later (v1 again) the same route mints again. + claim(&mut c, "alice.testnet", DAY0 + 2, "lantern", v1_lantern()); + assert_eq!(c.goods("alice.testnet"), [2, 2]); +} + +#[test] +#[should_panic(expected = "ERR_ALREADY_MINTED")] +fn break_second_mint_same_day_refused_by_contract() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()); + claim( + &mut c, + "alice.testnet", + DAY0, + "rope", + strings(&["move:left", "wait", "move:center", "reel:lens", "return"]), + ); +} + +#[test] +#[should_panic(expected = "ERR_REPLAY")] +fn break_doctored_court_illegal_command() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + // Takes the lens before any wave opened its lane. + claim( + &mut c, + "alice.testnet", + DAY0, + "rope", + strings(&["move:left", "take:lens", "move:center", "return"]), + ); +} + +#[test] +#[should_panic(expected = "ERR_RETURN_REQUIRED")] +fn break_doctored_court_without_return() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + claim( + &mut c, + "alice.testnet", + DAY0, + "rope", + strings(&["move:left", "wait", "move:center", "reel:lens"]), + ); +} + +#[test] +#[should_panic(expected = "ERR_WRONG_COURT")] +fn break_doctored_court_wrong_day_version() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.claim_daily( + storycraft::RULES_VERSION.into(), + "first_light_v2".into(), + "lantern".into(), + "beacon".into(), + v1_lantern(), + ); +} + +#[test] +#[should_panic(expected = "ERR_REPLAY_CONTEXT")] +fn break_doctored_court_other_area() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.claim_daily( + storycraft::RULES_VERSION.into(), + "first_light_v1".into(), + "rope".into(), + "wind".into(), + vec![], + ); +} + +#[test] +#[should_panic(expected = "ERR_COMMAND_BOUND")] +fn break_doctored_court_overlong_commands() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.claim_daily( + storycraft::RULES_VERSION.into(), + "first_light_v1".into(), + "rope".into(), + "beacon".into(), + vec!["wait".into(); 16], + ); +} + +#[test] +#[should_panic(expected = "ERR_RULES_VERSION")] +fn break_doctored_court_rules_version() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.claim_daily( + "tidebound_h2".into(), + "first_light_v1".into(), + "rope".into(), + "beacon".into(), + v1_lantern(), + ); +} + +#[test] +#[should_panic(expected = "ERR_NO_GOODS")] +fn break_return_with_nothing_mappable_keeps_the_day() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + claim(&mut c, "alice.testnet", DAY0, "rope", strings(&["return"])); +} + +#[test] +#[should_panic(expected = "ERR_NOT_REGISTERED")] +fn break_unregistered_mint() { + let mut c = setup(); + claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()); +} + +#[test] +fn day_boundary_is_exact() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()); + // Last nanosecond of the same day is still refused. + let mut b = ctx("alice.testnet", DAY0, 0); + b.block_timestamp((DAY0 + 1) * DAY_NS - 1); + testing_env!(b.build()); + assert_eq!(c.get_today(None).day, DAY0); + // First nanosecond of the next day is the other court. + let mut b = ctx("alice.testnet", DAY0, 0); + b.block_timestamp((DAY0 + 1) * DAY_NS); + testing_env!(b.build()); + assert_eq!(c.get_today(None).day, DAY0 + 1); + assert_eq!(c.get_today(None).content_version, "first_light_v2"); +} + +// ---------- Bram ---------- + +#[test] +fn buy_and_sell_move_shells_through_the_till_and_conserve() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [10, 10]); + at("alice.testnet", DAY0); + let t = c.sell("reed".into(), 10, 0); + // Stock 41..50: post-unit prices floor(0.8 × price). + assert_eq!(t.unit_prices.len(), 10); + assert_eq!(t.unit_prices[0], 3); + assert_eq!(t.total, t.unit_prices.iter().sum::()); + assert_eq!(c.shells("alice.testnet"), t.total); + assert_eq!(c.till, TILL_START - t.total); + let b = c.buy("glass".into(), 1, 100); + assert_eq!(b.unit_prices[0], 8); + c.assert_conserved(&["alice.testnet"]); +} + +#[test] +fn round_trips_never_profit() { + for (g, good) in GOODS.iter().enumerate() { + for n in 1..=20u32 { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + register(&mut c, "bob.testnet", DAY0); + // Move 250 Shells from the till to Bob so he can buy up to 20 units. + c.till -= 250; + c.accounts.get_mut(&id("bob.testnet")).unwrap().shells += 250; + at("bob.testnet", DAY0 + 1); + let bought = c.buy((*good).into(), n, 1_000).total; + // Sold back by another account in the same day. + c.accounts.get_mut(&id("bob.testnet")).unwrap().goods[g] -= u64::from(n); + c.accounts.get_mut(&id("alice.testnet")).unwrap().goods[g] += u64::from(n); + at("alice.testnet", DAY0 + 1); + let back = c.sell((*good).into(), n, 0).total; + assert!(back <= bought, "{good} n={n}: bought {bought} sold {back}"); + c.assert_conserved(&["alice.testnet", "bob.testnet"]); + } + } +} + +#[test] +fn till_refills_lazily_to_the_cap_and_never_underflows() { + let mut c = setup(); + let mut names = vec![]; + for i in 0..30 { + let who = format!("s{i}.testnet"); + register(&mut c, &who, DAY0); + c.credit(&who, [20, 0]); + at(&who, DAY0); + let till = c.till; + let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + c.sell("glass".into(), 20, 0) + })); + names.push(who); + if r.is_err() { + assert_eq!(c.till, till, "refused sale leaves the till"); + break; + } + } + let till = c.till; + assert!(till < 60); + at("s0.testnet", DAY0 + 1); + assert_eq!(c.get_shelf().till, till + 60); + at("s0.testnet", DAY0 + 1000); + assert_eq!(c.get_shelf().till, TILL_CAP); + c.buy("reed".into(), 1, 100); + assert_eq!(c.till, TILL_CAP + 4); + let refs: Vec<&str> = names.iter().map(String::as_str).collect(); + c.assert_conserved(&refs); +} + +#[test] +#[should_panic(expected = "ERR_TILL_EMPTY")] +fn break_sell_into_an_empty_till() { + let mut c = setup(); + for i in 0..30 { + let who = format!("s{i}.testnet"); + register(&mut c, &who, DAY0); + c.credit(&who, [20, 0]); + at(&who, DAY0); + c.sell("glass".into(), 20, 0); + } +} + +#[test] +fn empty_till_reopens_when_someone_buys() { + let mut c = setup(); + let mut sellers = vec![]; + let mut i = 0; + loop { + let who = format!("s{i}.testnet"); + register(&mut c, &who, DAY0); + c.credit(&who, [20, 0]); + at(&who, DAY0); + sellers.push(who.clone()); + if std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + c.sell("glass".into(), 20, 0) + })) + .is_err() + { + break; + } + i += 1; + } + let till = c.till; + let last = sellers.last().unwrap().clone(); + let pay = c.get_shelf().goods[GLASS].sell_price; + assert!(till < pay * 20); + // A buyer refills the till by the purchase price. + let buyer = sellers[0].clone(); + at(&buyer, DAY0); + let bought = c.buy("reed".into(), 5, 100).total; + assert_eq!(c.till, till + bought); + at(&last, DAY0); + c.sell("glass".into(), 1, 0); + let names: Vec<&str> = sellers.iter().map(String::as_str).collect(); + c.assert_conserved(&names); +} + +#[test] +#[should_panic(expected = "ERR_MAX_PRICE")] +fn break_buy_above_max_price() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [0, 20]); + at("alice.testnet", DAY0); + c.sell("reed".into(), 20, 0); + // Units get dearer as stock falls: the second glass unit costs 9. + c.buy("glass".into(), 2, 8); +} + +#[test] +#[should_panic(expected = "ERR_MIN_PRICE")] +fn break_sell_below_min_price() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [20, 0]); + at("alice.testnet", DAY0); + c.sell("glass".into(), 20, 6); +} + +#[test] +#[should_panic(expected = "ERR_DAILY_LIMIT")] +fn break_over_daily_limit() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [21, 0]); + at("alice.testnet", DAY0); + c.sell("glass".into(), 15, 0); + c.sell("glass".into(), 6, 0); +} + +#[test] +fn daily_limit_resets_at_the_day_boundary_and_counts_both_sides() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [40, 0]); + at("alice.testnet", DAY0); + c.sell("glass".into(), 15, 0); + assert!( + std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| c.buy( + "glass".into(), + 6, + 100 + ))) + .is_err() + ); + at("alice.testnet", DAY0 + 1); + c.sell("glass".into(), 20, 0); +} + +#[test] +#[should_panic(expected = "ERR_TRADE_QTY")] +fn break_over_trade_quantity() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.buy("glass".into(), 21, 1_000); +} + +#[test] +#[should_panic(expected = "ERR_SHELLS")] +fn break_buy_without_shells() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.buy("glass".into(), 1, 1_000); +} + +#[test] +#[should_panic(expected = "ERR_GOODS")] +fn break_sell_goods_not_held() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.sell("glass".into(), 1, 0); +} + +#[test] +#[should_panic(expected = "ERR_GOOD")] +fn break_unknown_good() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + c.sell("pearl".into(), 1, 0); +} + +#[test] +fn heat_halves_lazily_each_day() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [20, 0]); + at("alice.testnet", DAY0); + c.sell("glass".into(), 20, 0); + at("alice.testnet", DAY0 + 1); + c.buy("glass".into(), 8, 1_000); + assert_eq!(c.shelf[GLASS].heat_fp, 8 * S as u64); + at("alice.testnet", DAY0 + 2); + assert_eq!(c.get_shelf().goods[GLASS].heat_fp, 4 * S as u64); + at("alice.testnet", DAY0 + 4); + assert_eq!(c.get_shelf().goods[GLASS].heat_fp, S as u64); + at("alice.testnet", DAY0 + 500); + assert_eq!(c.get_shelf().goods[GLASS].heat_fp, 0); +} + +// ---------- Mochi's wish ---------- + +fn funded(c: &mut Season, who: &str, day: u64) { + testing_env!(ctx(who, day, NearToken::from_near(1).as_yoctonear()).build()); + c.storage_deposit(); + c.credit(who, [0, 20]); + at(who, day); + c.sell("reed".into(), 20, 0); +} + +#[test] +fn wish_fills_at_once_when_the_price_is_there() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + let before = c.shells("alice.testnet"); + let r = wish( + &mut c, + "alice.testnet", + DAY0, + "mochi", + "reed", + 12, + 2, + "alice.testnet", + ); + assert_eq!(r.status, "filled"); + let card = c.get_postcard("mochi".into()).unwrap(); + assert_eq!(card.reason, "FILLED_ON_SET"); + assert!(card.unit_prices.iter().all(|p| *p <= 12)); + assert_eq!(card.paid + card.refunded, 24); + assert_eq!(c.shells("alice.testnet"), before - card.paid); + assert_eq!(c.goods("alice.testnet")[REED], 2); + assert!(c.get_wish("mochi".into()).is_none()); + c.assert_conserved(&["alice.testnet"]); +} + +#[test] +fn wish_waits_then_a_sale_that_reaches_the_limit_fills_it() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + register(&mut c, "bob.testnet", DAY0); + c.credit("bob.testnet", [20, 0]); + // Glass is 8 now; wish at 7. + let r = wish( + &mut c, + "alice.testnet", + DAY0, + "mochi", + "glass", + 7, + 1, + "alice.testnet", + ); + assert_eq!(r.status, "waiting"); + assert_eq!(c.get_wish("mochi".into()).unwrap().purse, 7); + c.assert_conserved(&["alice.testnet", "bob.testnet"]); + at("bob.testnet", DAY0); + let mut fills = vec![]; + for _ in 0..20 { + let t = c.sell("glass".into(), 1, 0); + if !t.fills.is_empty() { + fills = t.fills; + break; + } + } + assert_eq!(fills.len(), 1); + let card = c.get_postcard("mochi".into()).unwrap(); + assert_eq!(card.reason, "FILLED_BY_TRADE"); + assert!(card.unit_prices[0] <= 7); + let trig = card.trigger.unwrap(); + assert_eq!(trig.account, id("bob.testnet")); + assert_eq!(trig.side, "sell"); + c.assert_conserved(&["alice.testnet", "bob.testnet"]); +} + +#[test] +fn at_most_three_wishes_fill_per_trade_first_come() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + funded(&mut c, "carol.testnet", DAY0); + register(&mut c, "bob.testnet", DAY0); + c.credit("bob.testnet", [20, 0]); + for (i, who) in [ + "alice.testnet", + "carol.testnet", + "alice.testnet", + "carol.testnet", + "alice.testnet", + ] + .iter() + .enumerate() + { + let r = wish(&mut c, who, DAY0, &format!("pet{i}"), "glass", 7, 1, who); + assert_eq!(r.status, "waiting"); + } + let accounts = ["alice.testnet", "carol.testnet", "bob.testnet"]; + at("bob.testnet", DAY0); + // One large sale brings glass to 7 and keeps it there across three fills. + let first = c.sell("glass".into(), 20, 0).fills; + assert_eq!(first.len(), FILLS_PER_TX); + assert_eq!( + first.iter().map(|p| p.pet.as_str()).collect::>(), + ["pet0", "pet1", "pet2"] + ); + assert_eq!(c.get_wish_queue("glass".into()), strings(&["pet3", "pet4"])); + for p in &first { + assert!(p.unit_prices.iter().all(|u| *u <= p.limit)); + } + c.assert_conserved(&accounts); +} + +#[test] +fn a_wish_never_fills_above_its_limit() { + // Random trading never fills any wish above its limit and keeps every purse in 0..=24. + let mut c = setup(); + let names = ["a.testnet", "b.testnet", "c.testnet", "d.testnet"]; + for who in names { + funded(&mut c, who, DAY0); + c.credit(who, [20, 20]); + } + let mut seed: u32 = 99; + let mut rand = |n: u32| { + seed = seed.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); + (seed >> 8) % n + }; + for step in 0..400u64 { + let day = DAY0 + step / 40; + let who = names[rand(4) as usize]; + let good = GOODS[rand(2) as usize]; + match rand(4) { + 0 => { + let limit = 1 + u64::from(rand(12)); + let qty = 1 + rand(2) as u8; + let pet = format!("pet{}", rand(6)); + let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + wish(&mut c, who, day, &pet, good, limit, qty, who) + })); + if let Ok(WishResult { + postcard: Some(p), .. + }) = r + { + assert!(p.unit_prices.iter().all(|u| *u <= limit)); + } + } + 1 => { + at(who, day); + let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + c.cancel_wish(format!("pet{}", rand(6))) + })); + } + side => { + at(who, day); + let qty = 1 + rand(5); + let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + let t = if side == 2 { + c.buy(good.into(), qty, 1_000) + } else { + c.sell(good.into(), qty, 0) + }; + assert!(t.fills.len() <= FILLS_PER_TX); + for p in t.fills { + assert!(p.unit_prices.iter().all(|u| *u <= p.limit)); + assert!(p.paid <= p.qty as u64 * p.limit); + } + })); + } + } + c.assert_conserved(&names); + } +} + +#[test] +fn cancel_wish_returns_the_purse() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + let before = c.shells("alice.testnet"); + wish( + &mut c, + "alice.testnet", + DAY0, + "mochi", + "glass", + 6, + 2, + "alice.testnet", + ); + assert_eq!(c.shells("alice.testnet"), before - 12); + at("alice.testnet", DAY0); + let card = c.cancel_wish("mochi".into()); + assert_eq!(card.refunded, 12); + assert_eq!(card.reason, "CANCELLED_BY_OWNER"); + assert_eq!(c.shells("alice.testnet"), before); + assert!(c.get_wish_queue("glass".into()).is_empty()); + c.assert_conserved(&["alice.testnet"]); +} + +#[test] +fn replacing_a_wish_refunds_the_old_purse_once() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + funded(&mut c, "bob.testnet", DAY0); + let (a, b) = (c.shells("alice.testnet"), c.shells("bob.testnet")); + wish( + &mut c, + "alice.testnet", + DAY0, + "mochi", + "glass", + 6, + 2, + "alice.testnet", + ); + // Same callback replayed (double set) and then a new owner after a transfer. + wish( + &mut c, + "alice.testnet", + DAY0, + "mochi", + "glass", + 5, + 2, + "alice.testnet", + ); + assert_eq!(c.shells("alice.testnet"), a - 10); + wish( + &mut c, + "bob.testnet", + DAY0, + "mochi", + "glass", + 4, + 1, + "bob.testnet", + ); + assert_eq!(c.shells("alice.testnet"), a); + assert_eq!(c.shells("bob.testnet"), b - 4); + assert_eq!(c.get_wish_queue("glass".into()), strings(&["mochi"])); + c.assert_conserved(&["alice.testnet", "bob.testnet"]); +} + +#[test] +fn break_non_owner_wish_is_refused_without_holding_anything() { + let mut c = setup(); + funded(&mut c, "mallory.testnet", DAY0); + let before = c.shells("mallory.testnet"); + let r = wish( + &mut c, + "mallory.testnet", + DAY0, + "mochi", + "glass", + 6, + 2, + "alice.testnet", + ); + assert_eq!(r.status, "refused"); + assert_eq!(r.reason, "ERR_NOT_OWNER"); + assert_eq!(c.shells("mallory.testnet"), before); + assert!(c.get_wish("mochi".into()).is_none()); + assert!(c.get_postcard("mochi".into()).is_none()); + c.assert_conserved(&["mallory.testnet"]); +} + +#[test] +fn break_failed_or_garbled_owner_lookup_holds_nothing() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + let before = c.shells("alice.testnet"); + for result in [ + PromiseResult::Failed, + PromiseResult::Successful(b"null".to_vec()), + PromiseResult::Successful(b"{not json".to_vec()), + PromiseResult::Successful(b"{\"owner_id\":\"NOT A VALID ID!!\"}".to_vec()), + ] { + at("alice.testnet", DAY0); + let _ = c.set_wish("mochi".into(), "glass".into(), 6, 2); + callback(DAY0, result); + let r = c.on_wish_owner(id("alice.testnet"), "mochi".into(), "glass".into(), 6, 2); + assert_eq!(r.status, "refused"); + assert_eq!(c.shells("alice.testnet"), before); + assert!(c.get_wish("mochi".into()).is_none()); + } + c.assert_conserved(&["alice.testnet"]); +} + +#[test] +fn break_spent_shells_between_call_and_callback_are_rechecked() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + let _ = c.set_wish("mochi".into(), "glass".into(), 12, 2); + // Alice spends almost everything before the callback lands. + let keep = 10; + let spend = c.shells("alice.testnet") - keep; + c.accounts.get_mut(&id("alice.testnet")).unwrap().shells -= spend; + c.till += spend; + callback(DAY0, owner_is("alice.testnet")); + let r = c.on_wish_owner(id("alice.testnet"), "mochi".into(), "glass".into(), 12, 2); + assert_eq!(r.reason, "ERR_SHELLS"); + assert_eq!(c.shells("alice.testnet"), keep); + c.assert_conserved(&["alice.testnet"]); +} + +#[test] +#[should_panic(expected = "ERR_PURSE_LIMIT")] +fn break_purse_above_24() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + let _ = c.set_wish("mochi".into(), "glass".into(), 13, 2); +} + +#[test] +#[should_panic(expected = "ERR_WISH_QTY")] +fn break_wish_quantity_above_two() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + at("alice.testnet", DAY0); + let _ = c.set_wish("mochi".into(), "glass".into(), 2, 3); +} + +#[test] +#[should_panic(expected = "ERR_NOT_WISH_OWNER")] +fn break_cancel_someone_elses_wish() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + register(&mut c, "mallory.testnet", DAY0); + wish( + &mut c, + "alice.testnet", + DAY0, + "mochi", + "glass", + 6, + 2, + "alice.testnet", + ); + at("mallory.testnet", DAY0); + c.cancel_wish("mochi".into()); +} + +#[test] +fn wish_queue_is_capped() { + let mut c = setup(); + funded(&mut c, "alice.testnet", DAY0); + c.accounts + .get_mut(&id("alice.testnet")) + .unwrap() + .storage_deposit = NearToken::from_near(10); + let mut last = None; + for i in 0..=WISH_QUEUE_CAP { + // limit 1 never fills at today's prices; one Shell each. + last = Some(wish( + &mut c, + "alice.testnet", + DAY0, + &format!("p{i}"), + "glass", + 1, + 1, + "alice.testnet", + )); + } + assert_eq!(last.unwrap().reason, "ERR_WISH_QUEUE_FULL"); + assert_eq!(c.get_wish_queue("glass".into()).len(), WISH_QUEUE_CAP); + c.assert_conserved(&["alice.testnet"]); +} + +// ---------- storage ---------- + +#[test] +fn storage_charges_cover_actual_bytes() { + // NEAR charges key + value + 40 bytes per record; measure the largest shapes with Borsh. + let long = id(&format!("{}.testnet", "a".repeat(56))); + let record = |key: usize, value: usize| (key + value + 40) as u64; + let key = |s: &str| 1 + 4 + s.len(); + let mint = Mint { + day: u64::MAX, + content_version: "first_light_v1".into(), + tool: "lantern".into(), + goods: [u64::MAX; 2], + value_fp: u64::MAX, + best_fp: u64::MAX, + score_bp: u32::MAX, + }; + let account = Account { + shells: u64::MAX, + goods: [u64::MAX; 2], + trade_day: u64::MAX, + traded: [u32::MAX; 2], + last_mint: Some(mint), + storage_deposit: NearToken::from_near(1), + storage_bytes: u64::MAX, + }; + let account_bytes = record( + key(long.as_str()), + near_sdk::borsh::to_vec(&account).unwrap().len(), + ); + assert!( + account_bytes <= ACCOUNT_BYTES, + "account uses {account_bytes}" + ); + let pet = "p".repeat(PET_ID_MAX); + let wish = Wish { + pet: pet.clone(), + owner: long.clone(), + good: "glass".into(), + limit: u64::MAX, + qty: 2, + purse: u64::MAX, + seq: u64::MAX, + day: u64::MAX, + }; + let card = Postcard { + pet: pet.clone(), + owner: long.clone(), + good: "glass".into(), + qty: 2, + limit: u64::MAX, + outcome: "cancelled".into(), + reason: "CANCELLED_BY_OWNER".into(), + unit_prices: vec![u64::MAX; 2], + paid: u64::MAX, + refunded: u64::MAX, + trigger: Some(Trigger { + trade: u64::MAX, + account: long.clone(), + side: "sell".into(), + good: "glass".into(), + }), + day: u64::MAX, + }; + let pet_bytes = record(key(&pet), near_sdk::borsh::to_vec(&wish).unwrap().len()) + + record(key(&pet), near_sdk::borsh::to_vec(&card).unwrap().len()) + + (4 + pet.len()) as u64; // queue slot inside contract state + assert!(pet_bytes <= PET_BYTES, "pet uses {pet_bytes}"); +} + +#[test] +#[should_panic(expected = "ERR_STORAGE_DEPOSIT")] +fn break_registration_below_minimum() { + let mut c = setup(); + testing_env!( + ctx( + "alice.testnet", + DAY0, + min_storage_deposit().as_yoctonear() - 1 + ) + .build() + ); + c.storage_deposit(); +} + +#[test] +fn storage_withdraw_returns_only_the_unspent_part_and_restores_on_failure() { + let mut c = setup(); + testing_env!( + ctx( + "alice.testnet", + DAY0, + min_storage_deposit().as_yoctonear() * 3 + ) + .build() + ); + c.storage_deposit(); + let bal = c.storage_balance_of(id("alice.testnet")).unwrap(); + assert_eq!( + bal.available.0, + bytes_cost(PET_BYTES) + 2 * min_storage_deposit().as_yoctonear() + ); + testing_env!(ctx("alice.testnet", DAY0, 1).build()); + let _ = c.storage_withdraw(); + assert_eq!( + c.storage_balance_of(id("alice.testnet")) + .unwrap() + .available + .0, + 0 + ); + callback(DAY0, PromiseResult::Failed); + assert!(!c.on_storage_withdraw(id("alice.testnet"), bal.available)); + assert_eq!( + c.storage_balance_of(id("alice.testnet")).unwrap().available, + bal.available + ); +} + +#[test] +#[should_panic(expected = "ERR_STORAGE")] +fn break_wish_without_storage_for_a_new_pet_record() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + c.credit("alice.testnet", [0, 20]); + at("alice.testnet", DAY0); + c.sell("reed".into(), 20, 0); + wish( + &mut c, + "alice.testnet", + DAY0, + "pet-a", + "glass", + 1, + 1, + "alice.testnet", + ); + let r = wish( + &mut c, + "alice.testnet", + DAY0, + "pet-b", + "glass", + 1, + 1, + "alice.testnet", + ); + env::panic_str(&r.reason); +} + +// ---------- views and events ---------- + +#[test] +fn views_report_the_shelf_today_and_events() { + let mut c = setup(); + register(&mut c, "alice.testnet", DAY0); + claim(&mut c, "alice.testnet", DAY0, "lantern", v1_lantern()); + let logs = near_sdk::test_utils::get_logs(); + assert!(logs.iter().any(|l| l.starts_with("EVENT_JSON:") + && l.contains("\"event\":\"mint\"") + && l.contains("\"standard\":\"familiar_season\""))); + let shelf = c.get_shelf(); + assert_eq!(shelf.commission, 12); + assert_eq!(shelf.goods[GLASS].buy_price, 8); + assert_eq!(shelf.goods[REED].sell_price, 3); + let today = c.get_today(Some(id("alice.testnet"))); + assert_eq!(today.minted_today.unwrap().goods, [1, 1]); + assert_eq!(today.best_fp, 16 * S as u64); + assert_eq!(today.mapping.len(), 5); +} + +#[test] +#[should_panic(expected = "ERR_TESTNET_ONLY")] +fn break_mainnet_init() { + let mut b = ctx("season.near", DAY0, 0); + b.current_account_id(id("season.near")); + testing_env!(b.build()); + Season::new(id(ROOT)); +} + +// ---------- pricing parity ---------- + +#[test] +fn pricing_parity_fixture_is_current() { + let mut seed: u64 = 0x5EA5_0002; + let mut next = |n: u64| { + seed = seed + .wrapping_mul(6_364_136_223_846_793_005) + .wrapping_add(1_442_695_040_888_963_407); + (seed >> 33) % n + }; + let mut cases = vec![]; + for i in 0..1000 { + let g = (i % 2) as usize; + let stock = match next(4) { + 0 => next(5), + 1 => next(60), + 2 => next(400), + _ => next(1_000_000), + }; + let heat = match next(3) { + 0 => 0, + 1 => next(80) * S as u64, + _ => next(5_000 * S as u64), + }; + let days = next(70); + let heat_now = pricing::decay_heat(u128::from(heat), days); + let p = price_fp(BASE[g], TARGET[g], u128::from(stock), heat_now); + let ratio = TARGET[g] * S / u128::from(stock.max(1)); + cases.push(json!({ + "good": GOODS[g], "stock": stock, "heat_fp": heat, "days": days, + "heat_now_fp": heat_now.to_string(), "pow": pricing::pow07(ratio).to_string(), + "price_fp": p.to_string(), "buyback_fp": buyback_fp(p).to_string(), + "buy": buy_shells(p).to_string(), "sell": sell_shells(p).to_string(), + "commission": commission(p * BASE[0] / BASE[g], BASE[0]).to_string(), + })); + } + let generated = serde_json::to_string(&cases).unwrap() + "\n"; + let path = concat!(env!("CARGO_MANIFEST_DIR"), "/fixtures/pricing-cases.json"); + if std::env::var("UPDATE_SEASON_FIXTURES").is_ok() { + std::fs::write(path, &generated).unwrap(); + } + let committed = std::fs::read_to_string(path).expect("run with UPDATE_SEASON_FIXTURES=1"); + assert_eq!( + committed, generated, + "pricing fixture drifted; regenerate and rerun bun test" + ); +} diff --git a/contracts/season/tests/sandbox.rs b/contracts/season/tests/sandbox.rs new file mode 100644 index 0000000..a7708d4 --- /dev/null +++ b/contracts/season/tests/sandbox.rs @@ -0,0 +1,35 @@ +#[tokio::test] +#[ignore = "requires optimized WASM and near-sandbox; run with --ignored"] +async fn season_on_real_wasm_against_the_real_root_stack() -> Result<(), Box> +{ + use near_workspaces::types::{KeyType, NearToken, SecretKey}; + let worker = near_workspaces::sandbox().await?; + let key = SecretKey::from_seed(KeyType::ED25519, "disposable-season-testnet-root"); + let testnet = worker + .create_tla("testnet".parse()?, key) + .await? + .into_result()?; + worker + .root_account()? + .transfer_near(testnet.id(), NearToken::from_near(500)) + .await? + .into_result()?; + let project = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .parent() + .unwrap(); + let status = std::process::Command::new("bun") + .arg("--no-env-file") + .arg("contracts/season/tests/sandbox.ts") + .current_dir(project) + .env("SANDBOX_RPC", worker.rpc_addr()) + .env("SANDBOX_ROOT", testnet.id().as_str()) + .env("SANDBOX_SECRET", testnet.secret_key().to_string()) + .status()?; + assert!( + status.success(), + "Season sandbox checks failed; see child output" + ); + Ok(()) +} diff --git a/contracts/season/tests/sandbox.ts b/contracts/season/tests/sandbox.ts new file mode 100644 index 0000000..73c7c83 --- /dev/null +++ b/contracts/season/tests/sandbox.ts @@ -0,0 +1,279 @@ +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import { Account, JsonRpcProvider, KeyPair, actions, baseEncode, getTransactionLastResult, nearToYocto, teraToGas, type KeyPairString } from "near-api-js"; + +const rpcUrl = process.env.SANDBOX_RPC!; +assert.match(rpcUrl, /^http:\/\/(127\.0\.0\.1|localhost):\d+/); +const provider = new JsonRpcProvider({ url: rpcUrl }); +const sponsor = new Account(process.env.SANDBOX_ROOT!, provider, process.env.SANDBOX_SECRET as KeyPairString); +assert.equal(sponsor.accountId, "testnet"); + +const wasm = async (name: string) => new Uint8Array(await Bun.file(`contracts/target/deploy/familiar_${name}.wasm`).arrayBuffer()); +const hash = (bytes: Uint8Array) => baseEncode(createHash("sha256").update(bytes).digest()); +async function create(parent: Account, prefix: string, funds: `${number}` = "12") { + const key = KeyPair.fromRandom("ed25519"), id = `${prefix}.${parent.accountId}`; + await parent.createAccount({ newAccountId: id, publicKey: key.getPublicKey(), nearToTransfer: nearToYocto(funds) }); + return new Account(id, provider, key.toString()); +} +const view = (contractId: string, method: string, args: Record = {}): Promise => + provider.callFunction({ contractId, method, args, blockQuery: { finality: "final" } }); + +type Gas = { total: bigint; receipts: { executor: string; burnt: bigint }[] }; +/** Signs one function call; throws on any failed receipt; returns the last value and gas burnt. */ +async function exec(account: Account, contractId: string, methodName: string, args: Record = {}, gasT = 100, deposit = 0n) { + const outcome: any = await account.signAndSendTransaction({ + receiverId: contractId, + actions: [actions.functionCall(methodName, args, teraToGas(gasT), deposit)], + waitUntil: "FINAL", + }); + for (const r of outcome.receipts_outcome) { + if (typeof r.outcome.status === "object" && "Failure" in r.outcome.status) throw new Error(JSON.stringify(r.outcome.status.Failure)); + } + const receipts = outcome.receipts_outcome.map((r: any) => ({ executor: r.outcome.executor_id as string, burnt: BigInt(r.outcome.gas_burnt) })); + const total = BigInt(outcome.transaction_outcome.outcome.gas_burnt) + receipts.reduce((s: bigint, r: { burnt: bigint }) => s + r.burnt, 0n); + return { value: getTransactionLastResult(outcome) as any, gas: { total, receipts } as Gas }; +} +const tgas = (g: bigint) => `${(Number(g) / 1e12).toFixed(3)} Tgas`; +const gasLog: string[] = []; +function logGas(label: string, gas: Gas) { + const line = `${label}: total ${tgas(gas.total)} [${gas.receipts.map(r => `${r.executor} ${tgas(r.burnt)}`).join(", ")}]`; + gasLog.push(line); + console.log(`GAS ${line}`); +} +async function rejects(promise: Promise, pattern: RegExp, label: string) { + try { + await promise; + } catch (error) { + const text = error instanceof Error ? `${error.message} ${JSON.stringify((error as any).cause ?? "")}` : String(error); + assert.match(text, pattern, `${label}: wrong failure: ${text}`); + console.log(`PASS ${label}: refused with ${text.match(pattern)![0]}`); + return; + } + assert.fail(`${label}: expected failure ${pattern}`); +} +async function relay(player: Account, receiverId: string, method: string, args: Record = {}, gasT = 180) { + const { signedDelegate } = await player.createSignedMetaTransaction({ receiverId, actions: [actions.functionCall(method, args, teraToGas(gasT), 0n)], blockHeightTtl: 120 }); + const result: any = await sponsor.signAndSendTransaction({ receiverId: player.accountId, actions: [actions.signedDelegate(signedDelegate)], waitUntil: "FINAL" }); + for (const r of result.receipts_outcome) { + if (typeof r.outcome.status === "object" && "Failure" in r.outcome.status) throw new Error(JSON.stringify(r.outcome.status.Failure)); + } + let terminal = result.receipts_outcome.find((r: any) => r.outcome.executor_id === receiverId); + while (terminal && typeof terminal.outcome.status === "object" && "SuccessReceiptId" in terminal.outcome.status) { + terminal = result.receipts_outcome.find((r: any) => r.id === terminal.outcome.status.SuccessReceiptId); + } + return getTransactionLastResult({ status: terminal.outcome.status } as any) as any; +} + +// ---------- the real Root stack (Root, Items, Bakery, Market, mock pool, global Pet) ---------- +const root = await create(sponsor, "familiar", "180"); +const [items, bakery, market, pool, bram, ...dens] = await Promise.all(["items", "bakery", "market", "pool", "bram", "den-1", "den-2", "den-3", "den-4"].map(n => create(root, n))); +const petWasm = await wasm("pet"); +await sponsor.signAndSendTransaction({ receiverId: sponsor.accountId, actions: [actions.deployGlobalContract(petWasm, "codeHash")], waitUntil: "FINAL" }); +for (const [account, name] of [[root, "root"], [items, "items"], [bakery, "bakery"], [market, "market"], [pool, "mock_pool"]] as const) await account.deployContract(await wasm(name)); +await exec(items, items.accountId, "new", { registry: root.accountId, bakery: bakery.accountId, market: market.accountId }); +await exec(bakery, bakery.accountId, "new", { items: items.accountId }); +await exec(market, market.accountId, "new", { registry: root.accountId, items: items.accountId, npc: bram.accountId, dens: dens.map(d => d.accountId) }); +await exec(pool, pool.accountId, "new", { owner: pool.accountId }); +await exec(root, root.accountId, "new", { relayer: sponsor.accountId, pet_code_hash: hash(petWasm), items: items.accountId, bakery: bakery.accountId, market: market.accountId, pool: pool.accountId }); +async function player(username: string, name: string) { + const key = KeyPair.fromRandom("ed25519"); + const { value: id } = await exec(sponsor, root.accountId, "create_named_player", { public_key: key.getPublicKey().toString(), username }); + const account = new Account(String(id), provider, key.toString()); + await sponsor.transfer({ receiverId: account.accountId, amount: nearToYocto("2") }); + const pet = await relay(account, root.accountId, "adopt", { name }); + assert.equal(pet, `${name}.${root.accountId}`); + assert.equal((await view(root.accountId, "nft_token", { token_id: pet })).owner_id, account.accountId); + return { account, pet: String(pet) }; +} +const alice = await player("alice", "mochi"), bob = await player("bob", "bramble"); +const stranger = await create(sponsor, "stranger", "5"); + +// ---------- Season on real Wasm ---------- +const seasonWasm = await wasm("season"); +const seasonHash = hash(seasonWasm); +console.log(`season wasm ${seasonWasm.length} bytes, sha256 ${seasonHash}`); +const season = await create(root, "season", "10"); +await season.signAndSendTransaction({ receiverId: season.accountId, actions: [actions.deployContract(seasonWasm)], waitUntil: "FINAL" }); +assert.equal((await provider.viewAccount({ accountId: season.accountId, blockQuery: { finality: "final" } })).code_hash, seasonHash); +const S = season.accountId; + +// 1. `new` is #[private]. +await rejects(exec(stranger, S, "new", { root: root.accountId }), /Method new is private/, "stranger init"); +await exec(season, S, "new", { root: root.accountId }); +await rejects(exec(season, S, "new", { root: root.accountId }), /The contract has already been initialized/, "second init"); +assert.equal(await view(S, "get_root"), root.accountId); + +// 2. The ownership callback is #[private]. +await rejects(exec(stranger, S, "on_wish_owner", { owner: stranger.accountId, pet: alice.pet, good: "glass", limit: 1, qty: 1 }), /Method on_wish_owner is private/, "direct on_wish_owner"); +await rejects(exec(stranger, S, "on_storage_withdraw", { account_id: stranger.accountId, amount: "1" }), /Method on_storage_withdraw is private/, "direct on_storage_withdraw"); + +// 3/4. Views decode; registration; the daily court. +const minimum = BigInt(await view(S, "storage_minimum")); +assert.equal(minimum, 1250n * 10n ** 19n); +assert.equal(await view(S, "storage_balance_of", { account_id: alice.account.accountId }), null); +await rejects(exec(alice.account, S, "storage_deposit", {}, 30, minimum - 1n), /ERR_STORAGE_DEPOSIT/, "short storage deposit"); +for (const who of [alice.account, bob.account]) { + const { value } = await exec(who, S, "storage_deposit", {}, 30, minimum); + assert.deepEqual(value, { total: minimum.toString(), available: (850n * 10n ** 19n).toString() }); +} +assert.deepEqual(await view(S, "storage_balance_of", { account_id: bob.account.accountId }), { total: minimum.toString(), available: (850n * 10n ** 19n).toString() }); + +const today = await view(S, "get_today", {}); +assert.deepEqual(await view(S, "get_today", { account_id: null }), today); +assert.equal((await view(S, "get_today", { account_id: alice.account.accountId })).minted_today, null); +assert.equal(today.rules_version, "tidebound_h1_v1"); +assert.equal(today.area, "beacon"); +assert.deepEqual(today.mapping, [["lens", "glass"], ["moth", "reed"], ["chart", "reed"], ["salvage", "reed"], ["vane", null]]); +assert.deepEqual(today.best_haul, today.content_version === "first_light_v1" + ? [{ tool: "rope", hauls: [[1, 1], [0, 2]] }, { tool: "lantern", hauls: [[1, 2]] }] + : [{ tool: "rope", hauls: [[1, 1]] }, { tool: "lantern", hauls: [[1, 1]] }]); +const v1 = today.content_version === "first_light_v1"; +assert(v1 || today.content_version === "first_light_v2", today.content_version); +console.log(`court day ${today.day}: ${today.content_version}`); +// v1 lantern: lens + chart (Season 1 golden route). v2 rope: lens + moth rescue route. +const route = v1 + ? { tool: "lantern", goods: [1, 1], commands: ["wait", "wait", "lure:left", "take:chart", "move:left", "take:lens", "move:center", "return"] } + : { tool: "rope", goods: [1, 1], commands: ["step:north", "step:north", "step:west", "wait", "wait", "step:east", "reel:lens", "step:east", "step:west", "step:east", "take:moth", "step:west", "step:east", "step:south", "step:west", "step:south", "return"] }; +const claimArgs = (commands: string[], content_version = today.content_version) => + ({ rules_version: today.rules_version, content_version, tool: route.tool, area: "beacon", commands }); + +const other = v1 ? "first_light_v2" : "first_light_v1"; +await rejects(exec(alice.account, S, "claim_daily", claimArgs(route.commands, other)), /ERR_WRONG_COURT/, "doctored court: other day's version"); +await rejects(exec(alice.account, S, "claim_daily", claimArgs(route.commands.slice(0, -1))), /ERR_RETURN_REQUIRED/, "doctored court: no return"); +await rejects(exec(alice.account, S, "claim_daily", { ...claimArgs(route.commands), rules_version: "tidebound_h2" }), /ERR_RULES_VERSION/, "doctored court: rules version"); +await rejects(exec(alice.account, S, "claim_daily", { ...claimArgs(route.commands), area: "wind" }), /ERR_REPLAY_CONTEXT/, "doctored court: other area"); +await rejects(exec(alice.account, S, "claim_daily", { ...claimArgs(route.commands), commands: "return" }), /Failed to deserialize input from JSON/, "malformed JSON args"); +assert.equal((await view(S, "get_account", { account_id: alice.account.accountId })).last_mint, null, "refused claims mint nothing"); + +// 7. Deposits on non-payable methods are rejected before any effect. +await rejects(exec(alice.account, S, "claim_daily", claimArgs(route.commands), 100, 1n), /Method claim_daily doesn't accept deposit/, "deposit on claim_daily"); + +const shelf0 = await view(S, "get_shelf"); +for (const who of [alice, bob]) { + const { value: mint, gas } = await exec(who.account, S, "claim_daily", claimArgs(route.commands)); + logGas(`claim_daily (${today.content_version}, ${route.tool})`, gas); + assert.equal(mint.day, today.day); + assert.deepEqual(mint.goods, route.goods); + assert.equal(mint.score_bp, Math.floor(mint.value_fp * 10000 / mint.best_fp)); + if (!v1) assert.equal(mint.score_bp, 10000); + assert.deepEqual((await view(S, "get_account", { account_id: who.account.accountId })).goods, route.goods); +} +await rejects(exec(alice.account, S, "claim_daily", claimArgs(route.commands)), /ERR_ALREADY_MINTED/, "second claim same day"); +assert.deepEqual((await view(S, "get_today", { account_id: alice.account.accountId })).minted_today.goods, route.goods); +assert.deepEqual((await view(S, "get_shelf")).goods_minted, [shelf0.goods_minted[0] + 2 * route.goods[0], shelf0.goods_minted[1] + 2 * route.goods[1]]); + +// 5. Bram: guards enforced, then honest trades. +for (const [method, args] of [["buy", { good: "glass", qty: 1, max_price: 99 }], ["sell", { good: "glass", qty: 1, min_price: 0 }], ["set_wish", { pet: alice.pet, good: "glass", limit: 1, qty: 1 }], ["cancel_wish", { pet: alice.pet }]] as const) { + await rejects(exec(alice.account, S, method, args, 100, 1n), new RegExp(`Method ${method} doesn't accept deposit`), `deposit on ${method}`); +} +const glassSell = (await view(S, "get_shelf")).goods[0].sell_price as number; +assert(glassSell > 0); +await rejects(exec(alice.account, S, "sell", { good: "glass", qty: 1, min_price: glassSell + 1 }), /ERR_MIN_PRICE/, "sell below min_price"); +await rejects(exec(alice.account, S, "sell", { good: "glass", qty: 2, min_price: 0 }), /ERR_GOODS/, "sell more than held"); +await rejects(exec(alice.account, S, "sell", { good: "pearl", qty: 1, min_price: 0 }), /ERR_GOOD/, "unknown good"); +for (const who of [alice, bob]) { + const price = (await view(S, "get_shelf")).goods[0].sell_price; + const { value: trade, gas } = await exec(who.account, S, "sell", { good: "glass", qty: 1, min_price: price }); + logGas("sell glass x1", gas); + assert.deepEqual(trade.unit_prices, [price]); + assert.equal(trade.total, price); + assert.equal((await view(S, "get_account", { account_id: who.account.accountId })).shells, price); +} +const aliceAfterSell = await view(S, "get_account", { account_id: alice.account.accountId }); +assert.deepEqual(aliceAfterSell.goods, [0, route.goods[1]]); +const glassBuy = (await view(S, "get_shelf")).goods[0].buy_price as number; +await rejects(exec(alice.account, S, "buy", { good: "glass", qty: 1, max_price: glassBuy - 1 }), /ERR_MAX_PRICE/, "buy above max_price"); +await rejects(exec(alice.account, S, "buy", { good: "glass", qty: 0, max_price: 99 }), /ERR_TRADE_QTY/, "zero-quantity buy"); +assert.deepEqual(await view(S, "get_account", { account_id: alice.account.accountId }), aliceAfterSell, "refused trades change nothing"); +// Reed is cheapest; Alice buys one reed within her Shells. +const reedBuy = (await view(S, "get_shelf")).goods[1].buy_price as number; +assert(reedBuy <= aliceAfterSell.shells, `reed ${reedBuy} > shells ${aliceAfterSell.shells}`); +{ + const { value: trade, gas } = await exec(alice.account, S, "buy", { good: "reed", qty: 1, max_price: reedBuy }); + logGas("buy reed x1", gas); + assert.deepEqual(trade.unit_prices, [reedBuy]); + const after = await view(S, "get_account", { account_id: alice.account.accountId }); + assert.equal(after.shells, aliceAfterSell.shells - reedBuy); + assert.deepEqual(after.goods, [0, route.goods[1] + 1]); + assert.deepEqual(after.traded, [1, 1]); +} + +// 6. Mochi's wish through the real Root ownership view. +const bobBefore = await view(S, "get_account", { account_id: bob.account.accountId }); +assert(bobBefore.shells >= 1); +{ + const { value, gas } = await exec(bob.account, S, "set_wish", { pet: alice.pet, good: "glass", limit: 1, qty: 1 }, 60); + logGas("set_wish by non-owner (60 Tgas prepaid)", gas); + assert.equal(value.status, "refused"); + assert.equal(value.reason, "ERR_NOT_OWNER"); + assert.deepEqual(await view(S, "get_account", { account_id: bob.account.accountId }), bobBefore, "non-owner holds no Shells and is charged no storage"); + assert.equal(await view(S, "get_wish", { pet: alice.pet }), null); + assert.equal(await view(S, "get_postcard", { pet: alice.pet }), null); + assert.deepEqual(await view(S, "get_wish_queue", { good: "glass" }), []); +} +{ + const { value } = await exec(bob.account, S, "set_wish", { pet: `nobody.${root.accountId}`, good: "glass", limit: 1, qty: 1 }, 60); + assert.deepEqual([value.status, value.reason], ["refused", "ERR_NOT_OWNER"], "a missing pet token is refused"); + assert.deepEqual(await view(S, "get_account", { account_id: bob.account.accountId }), bobBefore); +} +await rejects(exec(alice.account, S, "set_wish", { pet: alice.pet, good: "glass", limit: 1, qty: 1 }, 59), /ERR_GAS/, "set_wish under 60 Tgas"); +await rejects(exec(alice.account, S, "set_wish", { pet: alice.pet, good: "glass", limit: 99, qty: 1 }, 60), /ERR_PURSE_LIMIT/, "purse over 24"); + +const aliceBeforeWish = await view(S, "get_account", { account_id: alice.account.accountId }); +// A limit of 1 Shell cannot fill now, so the wish waits holding its purse. +{ + const { value, gas } = await exec(alice.account, S, "set_wish", { pet: alice.pet, good: "glass", limit: 1, qty: 1 }, 60); + logGas("set_wish by owner -> waiting (60 Tgas prepaid)", gas); + assert.equal(value.status, "waiting", JSON.stringify(value)); + assert.equal(value.wish.purse, 1); + const after = await view(S, "get_account", { account_id: alice.account.accountId }); + assert.equal(after.shells, aliceBeforeWish.shells - 1); + assert.equal(after.storage_bytes, 400 + 850); + assert.deepEqual(await view(S, "get_wish_queue", { good: "glass" }), [alice.pet]); + assert.equal((await view(S, "get_wish", { pet: alice.pet })).owner, alice.account.accountId); +} +await rejects(exec(bob.account, S, "cancel_wish", { pet: alice.pet }), /ERR_NOT_WISH_OWNER/, "stranger cancel_wish"); +{ + const { value: card, gas } = await exec(alice.account, S, "cancel_wish", { pet: alice.pet }); + logGas("cancel_wish", gas); + assert.deepEqual([card.outcome, card.reason, card.refunded, card.paid], ["cancelled", "CANCELLED_BY_OWNER", 1, 0]); + assert.equal((await view(S, "get_account", { account_id: alice.account.accountId })).shells, aliceBeforeWish.shells, "cancel refunds the purse"); + assert.equal(await view(S, "get_wish", { pet: alice.pet }), null); + assert.deepEqual(await view(S, "get_wish_queue", { good: "glass" }), []); + assert.equal((await view(S, "get_postcard", { pet: alice.pet })).outcome, "cancelled"); +} +await rejects(exec(alice.account, S, "cancel_wish", { pet: alice.pet }), /ERR_NO_WISH/, "cancel twice"); +// Heaviest path: place a waiting wish, then replace it with one that fills on set. +{ + // Alice sells her reed back to fund the purse. + const held = (await view(S, "get_account", { account_id: alice.account.accountId })).goods[1]; + const { value: trade, gas } = await exec(alice.account, S, "sell", { good: "reed", qty: held, min_price: 1 }); + logGas(`sell reed x${held}`, gas); + assert.equal(trade.unit_prices.length, held); +} +await exec(alice.account, S, "set_wish", { pet: alice.pet, good: "glass", limit: 1, qty: 1 }, 60); +{ + const reed = (await view(S, "get_shelf")).goods[1].buy_price as number; + const before = await view(S, "get_account", { account_id: alice.account.accountId }); + assert(before.shells + 1 >= reed, `reed ${reed} > shells ${before.shells + 1}`); + const { value, gas } = await exec(alice.account, S, "set_wish", { pet: alice.pet, good: "reed", limit: reed, qty: 1 }, 60); + logGas("set_wish by owner replacing a waiting wish -> filled on set (60 Tgas prepaid)", gas); + assert.equal(value.status, "filled", JSON.stringify(value)); + assert.deepEqual([value.postcard.reason, value.postcard.unit_prices, value.postcard.paid, value.postcard.refunded], ["FILLED_ON_SET", [reed], reed, 0]); + const after = await view(S, "get_account", { account_id: alice.account.accountId }); + assert.equal(after.shells, before.shells + 1 - reed); + assert.equal(after.goods[1], before.goods[1] + 1); + assert.equal(after.storage_bytes, 400 + 850, "the pet record is charged once"); + assert.equal(await view(S, "get_wish", { pet: alice.pet }), null); + assert.deepEqual(await view(S, "get_wish_queue", { good: "glass" }), []); + assert.equal((await view(S, "get_postcard", { pet: alice.pet })).outcome, "filled"); +} + +// Conservation across the till, players and purses. +const shelf = await view(S, "get_shelf"); +const accounts = await Promise.all([alice, bob].map(w => view(S, "get_account", { account_id: w.account.accountId }))); +assert.equal(shelf.till + accounts.reduce((s, a) => s + a.shells, 0), shelf.shells_minted, "Shells conserved"); +for (const g of [0, 1]) assert.equal(shelf.goods[g].stock + accounts.reduce((s, a) => s + a.goods[g], 0), shelf.goods_minted[g], "goods conserved"); + +console.log(`PASS season sandbox on real Wasm ${seasonHash} against real Root ${hash(await wasm("root"))}`); +for (const line of gasLog) console.log(`GAS ${line}`); diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index de91293..ed2e9d4 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -42,7 +42,7 @@ flowchart TD Root owns the registry, authorization and accepted journey state. Items owns lantern mint/finish evidence and balances. Predecessor and current-holder checks remain authoritative; callbacks are private and preserve uncertain reservations. `contracts/common/src/court.rs` supplies spatial replay; `historical_returns.rs` preserves old content semantics. Fixture tests compare TypeScript/Rust transitions. -Bakery, Market and configured pool IDs remain part of the existing Pet/Items initialization and historical contract system. Their sources are also used by actual-Wasm upgrade sandboxes. They are not extra current outing activities. The dynamic NPC quote worker has been retired; Bram's current commission runs in Root. The mock pool is local-test infrastructure only. Root/Items administrative keys still exist on testnet; the whole stack is not immutable, even though adopted Pets use pinned global code and no access keys. +Bakery, Market and configured pool IDs remain part of the existing Pet/Items initialization and historical contract system. Their sources are also used by actual-Wasm upgrade sandboxes. They are not extra current outing activities. The dynamic NPC quote worker has been retired; Bram's current commission runs in Root. Season 2 (`contracts/season`, local source only, not deployed) revives Bram's dynamic prices as an on-chain integer formula with no off-chain quote worker; it keeps its own Shell, goods and pet-purse ledgers and reads pet ownership from Root's `nft_token`. The mock pool is local-test infrastructure only. Root/Items administrative keys still exist on testnet; the whole stack is not immutable, even though adopted Pets use pinned global code and no access keys. ## Build and release diff --git a/docs/THREAT-MODEL.md b/docs/THREAT-MODEL.md index dee0939..9b1cb20 100644 --- a/docs/THREAT-MODEL.md +++ b/docs/THREAT-MODEL.md @@ -49,7 +49,7 @@ Historical Pet/building/market operations still have their original serializatio An unforeseen historical callback execution failure can still strand a pending operation, lock, trade or payment. There is no general timeout unlock or operator rescue key for immutable Pets. Keeping those limits explicit is essential; the narrower H1 reconciliation does not solve every historical operation. -The dynamic NPC quote worker and optional AI reasoning have been retired from current source. Existing NPC account/key variables required by isolated contract deployment are not permission to run a quote worker. The local Bun relayer's older protocol support is distinct from the current exact-path H1 HTTP entry. CORS is a browser boundary, not bot protection. Process caches/quotas reset on restart and need durable accounting before multi-instance operation can be treated as a global limit. +The dynamic NPC quote worker and optional AI reasoning have been retired from current source. The local Season 2 contract prices Bram on chain from its own shelf state only; it has no quote worker, oracle or operator key, and is not deployed. Existing NPC account/key variables required by isolated contract deployment are not permission to run a quote worker. The local Bun relayer's older protocol support is distinct from the current exact-path H1 HTTP entry. CORS is a browser boundary, not bot protection. Process caches/quotas reset on restart and need durable accounting before multi-instance operation can be treated as a global limit. ## Delivery and verification limits diff --git a/package.json b/package.json index 668c8bd..5206188 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,13 @@ "rules:export": "cargo run --manifest-path contracts/Cargo.toml -p rules-export > web/src/rules.json", "relayer": "bun services/relayer/src/index.ts", "test:tidebound-sandbox": "cargo test --manifest-path contracts/Cargo.toml -p familiar-root --test tidebound -- --ignored --nocapture", + "test:season-sandbox": "cargo test --manifest-path contracts/Cargo.toml -p familiar-season --test sandbox -- --ignored --nocapture", "preflight:tidebound": "bun scripts/tidebound-preflight.ts", "test:privy-lifecycle-browser": "bun scripts/test-privy-lifecycle-browser.ts", "package:tidebound-review": "bun --env-file=.env.privy.local scripts/package-tidebound-review.ts", "test:routing-browser": "bun scripts/test-routing-browser.ts", - "test:records-browser": "bun scripts/test-records-browser.ts" + "test:records-browser": "bun scripts/test-records-browser.ts", + "test:season-browser": "bun scripts/test-season-browser.ts" }, "dependencies": { "@fontsource-variable/figtree": "5.3.0", diff --git a/scripts/build-contracts.sh b/scripts/build-contracts.sh index 47a21eb..2793efe 100644 --- a/scripts/build-contracts.sh +++ b/scripts/build-contracts.sh @@ -4,9 +4,9 @@ cd "$(dirname "$0")/.." command -v wasm-opt >/dev/null || { echo 'Install Binaryen (wasm-opt) before building.' >&2; exit 1; } # SDK 5.30 needs the near cfg; Binaryen lowers Rust 1.99 bulk-memory instructions for NEAR. RUSTFLAGS='--cfg near' cargo build --manifest-path contracts/Cargo.toml --locked --release --target wasm32-unknown-unknown \ - -p familiar-root -p familiar-pet -p familiar-items -p familiar-bakery -p familiar-market -p familiar-mock-pool + -p familiar-root -p familiar-pet -p familiar-items -p familiar-bakery -p familiar-market -p familiar-mock-pool -p familiar-season mkdir -p contracts/target/deploy -for contract in root pet items bakery market mock_pool; do +for contract in root pet items bakery market mock_pool season; do wasm-opt "contracts/target/wasm32-unknown-unknown/release/familiar_${contract}.wasm" \ --enable-bulk-memory --llvm-memory-copy-fill-lowering --signext-lowering -Oz --strip-debug --strip-producers \ -o "contracts/target/deploy/familiar_${contract}.wasm" diff --git a/scripts/build-release.test.ts b/scripts/build-release.test.ts index 641de6d..ba6f1f2 100644 --- a/scripts/build-release.test.ts +++ b/scripts/build-release.test.ts @@ -6,15 +6,19 @@ import { releaseSettings } from "./build-release"; import { buildAccountFunction,currentRouting,HTTP_PATHS } from "./package-tidebound-review"; test("only production builds receive explicitly allowlisted public account settings",()=>{ - expect(releaseSettings({})).toEqual({appId:"",clientId:"",sealedNote:false,records:false}); - expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"prod-app",VITE_PRIVY_CLIENT_ID:"prod-client",VITE_SEALED_NOTE_ENABLED:"true"})).toEqual({appId:"",clientId:"",sealedNote:false,records:false}); - expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app"})).toEqual({appId:"existing-app",clientId:"",sealedNote:false,records:false}); + expect(releaseSettings({})).toEqual({appId:"",clientId:"",sealedNote:false,records:false,season:false}); + expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"prod-app",VITE_PRIVY_CLIENT_ID:"prod-client",VITE_SEALED_NOTE_ENABLED:"true"})).toEqual({appId:"",clientId:"",sealedNote:false,records:false,season:false}); + expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app"})).toEqual({appId:"existing-app",clientId:"",sealedNote:false,records:false,season:false}); expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_SEALED_NOTE_ENABLED:"1"}).sealedNote).toBe(false); expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_SEALED_NOTE_ENABLED:"true"}).sealedNote).toBe(true); expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_RECORDS_ENABLED:"true"}).records).toBe(true); expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_RECORDS_ENABLED:"yes"}).records).toBe(false); expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"existing-app",VITE_RECORDS_ENABLED:"true"}).records).toBe(false); - expect(releaseSettings({VERCEL_ENV:"production",VITE_PRIVY_APP_ID:"public-app",PRIVY_APP_ID:"fallback",VITE_PRIVY_CLIENT_ID:"public-client"})).toEqual({appId:"public-app",clientId:"public-client",sealedNote:false,records:false}); + expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_SEASON2_ENABLED:"true"}).season).toBe(true); + for(const flag of ["1","TRUE","yes",""," true"])expect(releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:"existing-app",VITE_SEASON2_ENABLED:flag}).season).toBe(false); + expect(releaseSettings({VERCEL_ENV:"preview",PRIVY_APP_ID:"existing-app",VITE_SEASON2_ENABLED:"true"}).season).toBe(false); + expect(()=>releaseSettings({VERCEL_ENV:"production",VITE_SEASON2_ENABLED:"true"})).toThrow(); + expect(releaseSettings({VERCEL_ENV:"production",VITE_PRIVY_APP_ID:"public-app",PRIVY_APP_ID:"fallback",VITE_PRIVY_CLIENT_ID:"public-client"})).toEqual({appId:"public-app",clientId:"public-client",sealedNote:false,records:false,season:false}); for(const id of ["","invalid id", "a".repeat(129)]) expect(()=>releaseSettings({VERCEL_ENV:"production",PRIVY_APP_ID:id})).toThrow(); expect(()=>releaseSettings({VERCEL_ENV:"production",PRIVY_APP_SECRET:"never-an-app-id"})).toThrow(); diff --git a/scripts/build-release.ts b/scripts/build-release.ts index 1f01bf8..400d837 100644 --- a/scripts/build-release.ts +++ b/scripts/build-release.ts @@ -3,13 +3,13 @@ import { join,resolve } from "node:path"; import { buildAccountFunction,buildGameSite,currentRouting } from "./package-tidebound-review"; export function releaseSettings(env:Record){ - if(env.VERCEL_ENV!=="production")return {appId:"",clientId:"",sealedNote:false,records:false}; + if(env.VERCEL_ENV!=="production")return {appId:"",clientId:"",sealedNote:false,records:false,season:false}; const appId=env.VITE_PRIVY_APP_ID??env.PRIVY_APP_ID??"",clientId=env.VITE_PRIVY_CLIENT_ID??""; const id=/^[A-Za-z0-9_-]{1,128}$/; if(!id.test(appId)||(clientId&&!id.test(clientId)))throw Error("Production requires a valid public Privy app ID and, if supplied, a valid public client ID."); // Mochi's sealed note needs the account endpoints, so it is off unless production explicitly opts in. - // Harbor records read public chain state for a signed-in player; also explicit opt-in. - return {appId,clientId,sealedNote:env.VITE_SEALED_NOTE_ENABLED==="true",records:env.VITE_RECORDS_ENABLED==="true"}; + // Harbor records read public chain state for a signed-in player; Season 2 signs season calls. Both are explicit opt-ins. + return {appId,clientId,sealedNote:env.VITE_SEALED_NOTE_ENABLED==="true",records:env.VITE_RECORDS_ENABLED==="true",season:env.VITE_SEASON2_ENABLED==="true"}; } export async function buildRelease(source:string,settings:ReturnType){ @@ -20,7 +20,7 @@ export async function buildRelease(source:string,settings:ReturnType +// Root only creates the account (0.05 NEAR) so live adoption and crafting keep their reserve; +// a fresh faucet account pays for code storage. No key value is ever printed. +import { createHash } from "node:crypto"; +import { mkdir } from "node:fs/promises"; +import { Account, actions, baseEncode, JsonRpcProvider, KeyPair, nearToYocto, teraToGas, type KeyPairString } from "near-api-js"; + +const ROOT = "familiar-game.testnet"; +const SEASON = `season.${ROOT}`; +const expected = process.argv[2]; +if (process.env.NEAR_NETWORK !== "testnet" || process.env.NEAR_ROOT !== ROOT) throw new Error(`Needs NEAR_NETWORK=testnet and NEAR_ROOT=${ROOT}.`); +const secret = process.env.ROOT_PRIVATE_KEY as KeyPairString | undefined; +if (!secret) throw new Error("Missing ROOT_PRIVATE_KEY; no key value was printed."); +const rpc = new JsonRpcProvider({ url: "https://test.rpc.fastnear.com" }); +if ((await rpc.getNetworkId()) !== "testnet") throw new Error("Refusing a non-testnet RPC."); + +const code = new Uint8Array(await Bun.file("contracts/target/deploy/familiar_season.wasm").arrayBuffer()); +const codeHash = baseEncode(createHash("sha256").update(code).digest()); +if (codeHash !== expected) throw new Error(`Built wasm ${codeHash} is not the expected ${expected}.`); + +const evidence: { step: string; account: string; hash: string }[] = []; +await mkdir(".data", { recursive: true }); +async function record(step: string, account: string, result: Awaited>) { + evidence.push({ step, account, hash: result.transaction.hash }); + await Bun.write(".data/season-deploy-evidence.json", JSON.stringify({ network: "testnet", season: SEASON, codeHash, transactions: evidence }, null, 2)); + console.info(`${step}: https://testnet.nearblocks.io/txns/${result.transaction.hash}`); +} +const balance = async (id: string) => { + try { return (await rpc.viewAccount({ accountId: id })).amount; } + catch (e) { if (/UNKNOWN_ACCOUNT|does not exist/i.test(String(e))) return null; throw e; } +}; + +const root = new Account(ROOT, rpc, secret); +const rootKey = KeyPair.fromString(secret).getPublicKey(); +if ((await balance(SEASON)) === null) + await record("create_account", SEASON, await root.signAndSendTransaction({ receiverId: SEASON, actions: [actions.createAccount(), actions.transfer(nearToYocto("0.05")), actions.addFullAccessKey(rootKey)], waitUntil: "FINAL" })); + +const need = nearToYocto("3"); +const have = (await balance(SEASON)) ?? 0n; +if (have < need) { + const funderId = `familiar-season-fund-${Date.now().toString(36)}.testnet`; + const funderKey = KeyPair.fromRandom("ed25519"); + const p = Bun.spawn(["near", "account", "create-account", "sponsor-by-faucet-service", funderId, "use-manually-provided-public-key", funderKey.getPublicKey().toString(), "network-config", "testnet", "create"], { stdout: "inherit", stderr: "inherit" }); + if ((await p.exited) !== 0) throw new Error("Faucet account creation failed."); + for (let i = 0; i < 20 && !(await balance(funderId)); i++) await Bun.sleep(1500); + const funder = new Account(funderId, rpc, funderKey.toString() as KeyPairString); + await record("fund_from_faucet_account", SEASON, await funder.signAndSendTransaction({ receiverId: SEASON, actions: [actions.transfer(need - have)], waitUntil: "FINAL" })); +} + +const season = new Account(SEASON, rpc, secret); +const state = await rpc.viewAccount({ accountId: SEASON }); +if (state.code_hash === codeHash) console.info("Code already deployed."); +else if (state.code_hash === "11111111111111111111111111111111") + await record("deploy_and_init", SEASON, await season.signAndSendTransaction({ receiverId: SEASON, actions: [actions.deployContract(code), actions.functionCall("new", { root: ROOT }, teraToGas(50), 0n)], waitUntil: "FINAL" })); +else throw new Error(`${SEASON} already runs other code ${state.code_hash}; not overwriting.`); + +const after = await rpc.viewAccount({ accountId: SEASON }); +if (after.code_hash !== codeHash) throw new Error(`Deployed code ${after.code_hash} does not match ${codeHash}.`); +console.info(`${SEASON} runs ${after.code_hash}; shelf:`, JSON.stringify(await rpc.callFunction({ contractId: SEASON, method: "get_shelf", args: {} }))); diff --git a/scripts/optimize-season-assets.ts b/scripts/optimize-season-assets.ts new file mode 100644 index 0000000..3fa9a9b --- /dev/null +++ b/scripts/optimize-season-assets.ts @@ -0,0 +1,24 @@ +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import { mkdir, mkdtemp } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join, resolve } from "node:path"; + +// Offline regeneration of the Season 2 icons; masters in web/assets/source/season stay byte-identical. +// The cream backdrop is flood-filled to transparency from the corners, then encoded like the expedition art. +const webRoot=resolve(import.meta.dir,"../web"),target=join(webRoot,"public/assets/season"),work=await mkdtemp(join(tmpdir(),"season-art-")); +const images=[["glass",192],["reed",192],["shelf-till",320],["purse",192],["wish-token",192]] as const; +const hash=(bytes:Uint8Array)=>createHash("sha256").update(bytes).digest("hex"); +await mkdir(target,{recursive:true});const files=[]; +for(const [name,size] of images){ + const master=join(webRoot,"assets/source/season",name+".png"),cut=join(work,name+".png"),output=join(target,name+".webp"),before=await Bun.file(master).bytes(); + const corners=["0,0","1023,0","0,1023","1023,1023"].flatMap(p=>["-draw",`alpha ${p.replace(","," ")} floodfill`]); + const magick=Bun.spawnSync(["magick",master,"-alpha","set","-fuzz","7%","-fill","none",...corners,"-resize",`${size}x${size}`,cut]); + assert.equal(magick.exitCode,0,`magick failed for ${name}: ${magick.stderr.toString()}`); + const encode=Bun.spawnSync(["cwebp","-quiet","-q","85","-m","6","-alpha_q","100",cut,"-o",output]); + assert.equal(encode.exitCode,0,`cwebp failed for ${name}: ${encode.stderr.toString()}`); + const after=await Bun.file(output).bytes();assert.equal(hash(await Bun.file(master).bytes()),hash(before),"Master stays byte-identical"); + files.push({source:`assets/source/season/${name}.png`,output:`assets/season/${name}.webp`,sourceSha256:hash(before),sha256:hash(after),sourceBytes:before.length,bytes:after.length,resizedTo:{width:size,height:size}}); +} +const report={purpose:"Season 2 runtime icons; cream backdrop removed by corner flood fill (fuzz 7%)",encoder:"magick + cwebp quality85 method6 alpha100",files}; +await Bun.write(join(target,"manifest.json"),JSON.stringify(report,null,2)+"\n");console.log(JSON.stringify(report,null,2)); diff --git a/scripts/package-tidebound-review.ts b/scripts/package-tidebound-review.ts index 84785f5..387046a 100644 --- a/scripts/package-tidebound-review.ts +++ b/scripts/package-tidebound-review.ts @@ -131,7 +131,7 @@ export async function buildAccountFunction(source:string,output:string){ return installFunctionAliases(output); } -export async function buildGameSite(source:string,site:string,appId:string,clientId:string,sealedNote=false,records=false){ +export async function buildGameSite(source:string,site:string,appId:string,clientId:string,sealedNote=false,records=false,season=false){ const overlay=await mkdtemp(join(tmpdir(),"familiar-game-static-")); try{ await build({configFile:false,plugins:[react()],root:join(source,"web"),envDir:false,envPrefix:[],publicDir:false,define:{ @@ -141,6 +141,7 @@ export async function buildGameSite(source:string,site:string,appId:string,clien "import.meta.env.VITE_TIDEBOUND_ENABLED":JSON.stringify(appId?"true":"false"), "import.meta.env.VITE_SEALED_NOTE_ENABLED":JSON.stringify(appId&&sealedNote?"true":"false"), "import.meta.env.VITE_RECORDS_ENABLED":JSON.stringify(appId&&records?"true":"false"), + "import.meta.env.VITE_SEASON2_ENABLED":JSON.stringify(appId&&season?"true":"false"), },build:{outDir:overlay,rollupOptions:{input:{home:join(source,"web/index.html"),outing:join(source,"web/outing/index.html")},output:{manualChunks:id=>id.includes("/phaser/")?"phaser":undefined}}}}); const staticReport=await copyGameStatic(overlay,site); const runtimeAssets=await copyRuntimeAssets(join(source,"web/public"),site); diff --git a/scripts/season-best-haul.test.ts b/scripts/season-best-haul.test.ts new file mode 100644 index 0000000..843a856 --- /dev/null +++ b/scripts/season-best-haul.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from "bun:test"; +import committed from "../contracts/season/fixtures/best-haul.json"; +import { CARGO_GOODS, bestHaulTable } from "./season-best-haul"; + +test("Season 2 best-haul constants regenerate exactly from the court search", () => { + expect(bestHaulTable()).toEqual(committed as ReturnType); +}); + +test("the TypeScript cargo table matches the contract's CARGO_GOODS", async () => { + const source = await Bun.file(new URL("../contracts/season/src/lib.rs", import.meta.url)).text(); + const start = source.indexOf("pub const CARGO_GOODS"); + const table = source.slice(start, source.indexOf("];", start)); + const entries = Object.fromEntries([...table.matchAll(/\("(\w+)", (None|Some\((GLASS|REED)\))\)/g)] + .map(m => [m[1], m[3] ? m[3].toLowerCase() : null])); + expect(entries).toEqual(CARGO_GOODS); +}); diff --git a/scripts/season-best-haul.ts b/scripts/season-best-haul.ts new file mode 100644 index 0000000..d1c0381 --- /dev/null +++ b/scripts/season-best-haul.ts @@ -0,0 +1,59 @@ +import { applyCommand, legalCommands, startCourt } from "../web/src/expedition/engine"; +import { applyAction, legalActions, startOuting, type Outing } from "../web/src/compatibility/return-rules"; +import { courtStateKey } from "./court-solver"; +import type { CourtState } from "../web/src/expedition/types"; + +/** Season 2 cargo-to-goods table; must match CARGO_GOODS in contracts/season/src/lib.rs. */ +export const CARGO_GOODS: Record = { lens: "glass", moth: "reed", chart: "reed", salvage: "reed", vane: null }; +export const SEASON_COURTS = ["first_light_v1", "first_light_v2"] as const; + +function goods(cargo: readonly string[]): [number, number] { + let glass = 0, reed = 0; + for (const item of cargo) { if (CARGO_GOODS[item] === "glass") glass++; if (CARGO_GOODS[item] === "reed") reed++; } + return [glass, reed]; +} +function pareto(points: Set): [number, number][] { + const all = [...points].map(p => p.split(",").map(Number) as [number, number]); + return all.filter(([g, r]) => !all.some(([g2, r2]) => g2 >= g && r2 >= r && (g2 > g || r2 > r))) + .sort((a, b) => b[0] - a[0] || b[1] - a[1]); +} +function outingKey(run: Outing): string { + return [run.lane, run.turn % 3, run.resolve, run.uses, run.orientation, run.locked ?? "-", [...run.opened].sort().join(""), [...run.cargo].sort().join("")].join("/"); +} + +/** + * Exhaustive breadth-first search over every legal fresh beacon outing (the court solver's state key, without a goal), + * returning the maximal (glass, reed) hauls. Breadth-first order reaches each key at its earliest turn, so deduplication + * never hides a reachable return. + */ +export function bestHaul(content: typeof SEASON_COURTS[number], tool: "rope" | "lantern"): [number, number][] { + const hauls = new Set(); + if (content === "first_light_v2") { + const initial = startCourt({ area: "beacon", tool, banked: [] }), queue: CourtState[] = [initial], seen = new Set([courtStateKey(initial)]); + for (let i = 0; i < queue.length; i++) for (const command of legalCommands(queue[i]!)) { + const next = applyCommand(queue[i]!, command)!.after; + if (next.outcome === "returned") { hauls.add(goods(next.cargo).join(",")); continue; } + if (next.outcome !== "active") continue; + const key = courtStateKey(next); if (seen.has(key)) continue; seen.add(key); queue.push(next); + } + } else { + const initial = startOuting(tool, [], "beacon"), queue: Outing[] = [initial], seen = new Set([outingKey(initial)]); + for (let i = 0; i < queue.length; i++) for (const action of legalActions(queue[i]!)) { + const next = applyAction(queue[i]!, action); + if (next.outcome === "returned") { hauls.add(goods(next.cargo).join(",")); continue; } + if (next.outcome !== "active") continue; + const key = outingKey(next); if (seen.has(key)) continue; seen.add(key); queue.push(next); + } + } + return pareto(hauls); +} + +export function bestHaulTable() { + return SEASON_COURTS.map(content => ({ content_version: content, area: "beacon", + tools: (["rope", "lantern"] as const).map(tool => ({ tool, hauls: bestHaul(content, tool) })) })); +} + +if (import.meta.main) { + await Bun.write(new URL("../contracts/season/fixtures/best-haul.json", import.meta.url), JSON.stringify(bestHaulTable()) + "\n"); + console.info(JSON.stringify(bestHaulTable())); +} diff --git a/scripts/season-live.ts b/scripts/season-live.ts new file mode 100644 index 0000000..5f4eeba --- /dev/null +++ b/scripts/season-live.ts @@ -0,0 +1,61 @@ +// One honest Season 2 day on live testnet with a fresh faucet account: register, dock the +// Beacon Court rope route, sell what docked, buy one reed back. Testnet only; the key never leaves memory. +// Usage: bun --no-env-file scripts/season-live.ts (works on odd days, which are first_light_v2) +// If the faucet rate-limits, pass the root key (bun --env-file=.env.tidebound ...) and root funds a 0.3 NEAR sub-account instead. +import { mkdir } from "node:fs/promises"; +import { Account, actions, JsonRpcProvider, KeyPair, nearToYocto, teraToGas, type KeyPairString } from "near-api-js"; + +const SEASON = "season.familiar-game.testnet"; +const ROUTE = ["step:north", "step:north", "step:west", "wait", "wait", "step:east", "reel:lens", "step:east", "step:west", "step:east", "take:moth", "step:west", "step:east", "step:south", "step:west", "step:south", "return"]; +const rpc = new JsonRpcProvider({ url: "https://test.rpc.fastnear.com" }); +if ((await rpc.getNetworkId()) !== "testnet") throw new Error("Refusing a non-testnet RPC."); +const view = async (method: string, args: Record = {}): Promise => { + const value = await rpc.callFunction({ contractId: SEASON, method, args }); + if (value === undefined) throw new Error(`${method} returned nothing`); + return value as unknown as T; +}; + +const today = await view<{ day: number; content_version: string }>("get_today"); +if (today.content_version !== "first_light_v2") throw new Error(`Day ${today.day} is ${today.content_version}; run on an odd (Beacon Court) day.`); +const day = today.day; + +const key = KeyPair.fromRandom("ed25519"); +let id = `familiar-season-player-${Date.now().toString(36)}.testnet`; +const made = Bun.spawn(["near", "account", "create-account", "sponsor-by-faucet-service", id, "use-manually-provided-public-key", key.getPublicKey().toString(), "network-config", "testnet", "create"], { stdout: "ignore", stderr: "ignore" }); +if ((await made.exited) !== 0) { + const rootKey = process.env.ROOT_PRIVATE_KEY as KeyPairString | undefined; + if (process.env.NEAR_ROOT !== "familiar-game.testnet" || !rootKey) throw new Error("Faucet account creation failed and no root key was supplied."); + id = `qa-season-${Date.now().toString(36)}.familiar-game.testnet`; + await new Account("familiar-game.testnet", rpc, rootKey).signAndSendTransaction({ receiverId: id, actions: [actions.createAccount(), actions.transfer(nearToYocto("0.3")), actions.addFullAccessKey(key.getPublicKey())], waitUntil: "FINAL" }); + console.info(`faucet busy; root created ${id} with 0.3 NEAR`); +} +for (let i = 0; i < 20; i++) { try { await rpc.viewAccount({ accountId: id }); break; } catch { await Bun.sleep(1500); } } +const player = new Account(id, rpc, key.toString() as KeyPairString); + +const evidence: object[] = []; +async function call(method: string, args: object, tgas: number, deposit = 0n) { + const r = await player.callFunctionRaw({ contractId: SEASON, methodName: method, args, gas: teraToGas(tgas), deposit, waitUntil: "FINAL" }); + const burnt = [r.transaction_outcome, ...r.receipts_outcome].reduce((s, o) => s + BigInt(o.outcome.gas_burnt), 0n); + const status = r.status as { SuccessValue?: string; Failure?: unknown }; + const value = status.SuccessValue !== undefined ? JSON.parse(Buffer.from(status.SuccessValue, "base64").toString() || "null") : null; + const line = { method, hash: r.transaction.hash, tgasBurnt: Number(burnt) / 1e12, ok: status.Failure === undefined, value }; + evidence.push(line); + console.info(`${method}: ${line.ok ? "ok" : "FAILED"} ${line.tgasBurnt.toFixed(3)} Tgas https://testnet.nearblocks.io/txns/${r.transaction.hash}`); + if (!line.ok) throw new Error(`${method} failed: ${JSON.stringify(status.Failure)}`); + return value; +} + +const minimum = BigInt(await view("storage_minimum")); +await call("storage_deposit", {}, 30, minimum); +const mint = await call("claim_daily", { rules_version: "tidebound_h1_v1", content_version: "first_light_v2", tool: "rope", area: "beacon", commands: ROUTE }, 30); +for (const good of ["glass", "reed"]) { + const now = (await view<{ goods: { good: string; sell_price: number }[] }>("get_shelf")).goods.find(g => g.good === good)!; + await call("sell", { good, qty: 1, min_price: now.sell_price }, 30); +} +const after = await view<{ goods: { good: string; buy_price: number }[] }>("get_shelf"); +await call("buy", { good: "reed", qty: 1, max_price: after.goods.find(g => g.good === "reed")!.buy_price }, 30); +const account = await view("get_account", { account_id: id }); + +await mkdir(".data", { recursive: true }); +await Bun.write(`.data/season-live-${day}.json`, JSON.stringify({ network: "testnet", season: SEASON, day, player: id, mint, account, transactions: evidence }, null, 2)); +console.info("mint:", JSON.stringify(mint), "\naccount:", JSON.stringify(account)); diff --git a/scripts/test-season-browser.ts b/scripts/test-season-browser.ts new file mode 100644 index 0000000..5dfe321 --- /dev/null +++ b/scripts/test-season-browser.ts @@ -0,0 +1,121 @@ +import assert from "node:assert/strict"; +import { mkdir, mkdtemp } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join, resolve } from "node:path"; +import { chromium, expect, type Page } from "@playwright/test"; +import { createServer } from "vite"; + +// Season 2 panels with VITE_SEASON2_ENABLED on, against the live season. views (public RPC). +// Signed out uses the real game; signed in uses the dev-only harness, whose signing is mocked. +const shots=resolve(process.argv[2]??await mkdtemp(join(tmpdir(),"season-shots-")));await mkdir(shots,{recursive:true}); +const server=await createServer({root:resolve(import.meta.dir,"../web"),envDir:false,envPrefix:[],cacheDir:await mkdtemp(join(tmpdir(),"familiar-season-")),logLevel:"error", + define:{"import.meta.env.VITE_SEASON2_ENABLED":JSON.stringify("true")},server:{host:"127.0.0.1",port:0,hmr:false,watch:null}}); +async function checkTargets(page:Page,label:string) { + const small=await page.locator(".ss button:visible").evaluateAll(els=>els.filter(e=>{const r=e.getBoundingClientRect();return r.height<44||r.width<44;}).map(e=>e.textContent)); + assert.deepEqual(small,[],`${label}: buttons under 44px`); + const overflow=await page.locator(".exp-panel").evaluate(e=>e.scrollWidth>e.clientWidth+1);assert.equal(overflow,false,`${label}: panel scrolls sideways`); + const priced=await page.locator(".ss button:visible").evaluateAll(els=>els.map(e=>e.textContent??"").filter(t=>/\d+\s*Shell|NEAR/i.test(t))); + assert.deepEqual(priced,[],`${label}: prices on pressables`); +} +try{ + await server.listen();const origin=server.resolvedUrls!.local[0]!; + const browser=await chromium.launch(); + try{ + for(const viewport of [{width:390,height:844},{width:1440,height:900}]){ + const tag=`${viewport.width}x${viewport.height}`,page=await browser.newPage({viewport}); + await page.goto(new URL("/outing/?play",origin).href); + await expect(page.getByTestId("expedition-world")).toHaveAttribute("data-ready","true",{timeout:30000}); + await page.locator(".exp-place-bram").click(); + await expect(page.locator(".ss-mode")).toContainText("Device preview"); + await expect(page.locator(".ss-good").first()).toContainText("on the shelf",{timeout:15000}); + await checkTargets(page,`${tag} shelf`); + await page.screenshot({path:join(shots,`preview-shelf-${tag}.png`)}); + const reed=page.locator(".ss-good").nth(1); + await reed.getByRole("button",{name:"Sell 1"}).click(); + await expect(page.locator(".ss-status")).toContainText("Preview: sold 1 reed bundle"); + await expect(page.locator(".ss-holdings")).toContainText("Shells"); + await page.screenshot({path:join(shots,`preview-sold-${tag}.png`)}); + const tabs=page.getByRole("tab");await tabs.first().focus();await page.keyboard.press("ArrowRight"); + await expect(page.getByRole("tab",{name:"Today’s tide"})).toHaveAttribute("aria-selected","true"); + await expect(page.locator(".ss-court")).toBeVisible(); + await checkTargets(page,`${tag} tide`); + await page.screenshot({path:join(shots,`preview-tide-${tag}.png`)}); + const v2Day=(await page.locator(".ss-court").textContent())==="Beacon Court"; + // The season sandbox's v2 rope route (lens + moth); it docks only on a Beacon Court day. + const route=["step:north","step:north","step:west","wait","wait","step:east","reel:lens","step:east","step:west","step:east","take:moth","step:west","step:east","step:south","step:west","step:south","return"]; + await page.evaluate(commands=>localStorage.setItem("familiar.season.tide.v1:preview",JSON.stringify([{id:"route",contentVersion:"first_light_v2",tool:"rope",commands,cargo:["lens","moth"],outcome:"returned",savedAt:"test"}])),route); + await page.getByRole("tab",{name:"Shelf & till"}).click();await page.getByRole("tab",{name:"Today’s tide"}).click(); + if(v2Day){ + await expect(page.locator(".ss-returns")).toContainText("Rope outing · 1 glass and 1 reed bundle"); + await expect(page.getByRole("button",{name:"Dock this haul"})).toHaveAttribute("aria-disabled","true"); + await page.evaluate(()=>localStorage.removeItem("familiar.season.tide.v1:preview")); + const before=await page.evaluate(()=>({home:JSON.parse(localStorage.getItem("familiar.expedition.local.v2")??"null")?.home??null,returns:localStorage.getItem("familiar.expedition.returns.v2:preview")})); + await page.getByRole("button",{name:"Sail today’s tide"}).click(); + await expect(page.getByTestId("expedition-game")).toHaveAttribute("data-mode","court"); + const save=await page.evaluate(()=>JSON.parse(localStorage.getItem("familiar.expedition.local.v2")!)); + assert.equal(save.active.season,true);assert.deepEqual(save.active.state.banked,[]);assert.equal(save.active.state.area,"beacon"); + await page.screenshot({path:join(shots,`preview-tide-sailing-${tag}.png`)}); + for(const command of route){ + await page.locator(`[data-command="${command}"]`).click(); + await expect(page.getByTestId("expedition-game")).toHaveAttribute("data-busy","false",{timeout:15000}); + } + await expect(page.getByTestId("expedition-game")).toHaveAttribute("data-mode","harbor",{timeout:15000}); + await expect(page.getByTestId("expedition-feedback")).toContainText("Dock today’s haul at Bram’s shelf"); + const after=await page.evaluate(()=>({home:JSON.parse(localStorage.getItem("familiar.expedition.local.v2")!).home,returns:localStorage.getItem("familiar.expedition.returns.v2:preview"),tide:JSON.parse(localStorage.getItem("familiar.season.tide.v1:preview")??"[]")})); + if(before.home)assert.deepEqual(after.home,before.home,"First Light home unchanged by a tide outing");else assert.deepEqual(after.home.banked,[],"tide cargo is not banked"); + assert.equal(after.returns,before.returns,"First Light return memories unchanged"); + assert.equal(after.tide.length,1);assert.deepEqual(after.tide[0].commands,route);assert.deepEqual(after.tide[0].cargo,["lens","moth"]); + await page.locator(".exp-place-bram").click();await page.getByRole("tab",{name:"Today’s tide"}).click(); + await expect(page.locator(".ss-returns")).toContainText("Rope outing · 1 glass and 1 reed bundle"); + await page.screenshot({path:join(shots,`preview-tide-ready-${tag}.png`)}); + await page.evaluate(()=>{localStorage.removeItem("familiar.expedition.local.v2");}); + await page.goto(new URL("/outing/?play",origin).href); + await expect(page.getByTestId("expedition-world")).toHaveAttribute("data-ready","true",{timeout:30000}); + await page.locator(".exp-place-bram").click();await page.getByRole("tab",{name:"Today’s tide"}).click(); + }else{ + await expect(page.locator(".ss-panel")).toContainText("would not dock today"); + await expect(page.getByRole("button",{name:"Sail today’s tide"})).toHaveCount(0); + } + await page.keyboard.press("ArrowRight"); + await expect(page.getByRole("tab",{name:"Mochi’s wish"})).toHaveAttribute("aria-selected","true"); + await expect(page.locator(".ss-panel")).toContainText("Sign in from the menu"); + await page.screenshot({path:join(shots,`preview-wish-${tag}.png`)}); + + await page.goto(new URL("/outing/?season-harness",origin).href); + await expect(page.getByRole("note")).toContainText("signing are mocked"); + await expect(page.getByRole("button",{name:"Open my ledger page"})).toBeVisible({timeout:15000}); + await checkTargets(page,`${tag} harness`); + await page.screenshot({path:join(shots,`harness-ledger-${tag}.png`)}); + await page.getByRole("button",{name:"Open my ledger page"}).click(); + await expect(page.locator(".ss-status")).toHaveAttribute("data-state","pending"); + await expect(page.locator(".ss-status")).not.toContainText("Recorded"); + await expect(page.locator(".ss-status")).toContainText("Recorded",{timeout:10000}); + const focusInside=()=>page.evaluate(()=>!!document.activeElement?.closest(".ss")); + await expect.poll(focusInside,{message:"focus stays in the panel after the ledger offer goes away"}).toBe(true); + await page.locator(".ss-good").first().getByRole("button",{name:"Buy 1"}).click(); + await expect(page.locator(".ss-status")).toContainText("price moved",{timeout:10000}); + await page.screenshot({path:join(shots,`harness-refused-${tag}.png`)}); + await page.locator(".ss-good").nth(1).getByRole("button",{name:"Sell 1"}).click(); + await expect(page.locator(".ss-status")).toContainText("Sold 1 reed bundle",{timeout:10000}); + await page.getByRole("tab",{name:"Mochi’s wish"}).click(); + await page.getByRole("button",{name:"Set Mochi’s wish"}).click(); + await expect(page.locator(".ss-status")).toContainText("waiting",{timeout:10000}); + await expect(page.locator(".ss-wish-head")).toContainText("Mochi is waiting for"); + await checkTargets(page,`${tag} wish`); + await page.screenshot({path:join(shots,`harness-wish-${tag}.png`),fullPage:true}); + await page.getByRole("button",{name:"Take the wish back"}).click(); + await expect(page.locator(".ss-postcard")).toContainText("CANCELLED_BY_OWNER",{timeout:10000}); + await expect.poll(focusInside,{message:"focus stays in the panel after the wish is taken back"}).toBe(true); + await page.screenshot({path:join(shots,`harness-postcard-${tag}.png`),fullPage:true}); + if(v2Day){ + await page.getByRole("tab",{name:"Today’s tide"}).click(); + await page.getByRole("button",{name:"Dock this haul"}).first().click(); + await expect(page.locator(".ss-status")).toContainText("Docked 1 glass and 1 reed bundle: 100% of the best haul",{timeout:10000}); + await page.screenshot({path:join(shots,`harness-docked-${tag}.png`)}); + } + await page.close(); + console.info(`${tag}: preview shelf/sell/tide/wish and harness ledger/refusal/sale/wish/postcard passed`); + } + }finally{await browser.close();} + console.info(`Screenshots: ${shots}`); +}finally{await server.close();} diff --git a/services/relayer/src/auth/sign.test.ts b/services/relayer/src/auth/sign.test.ts index 55d39a5..b1d3f40 100644 --- a/services/relayer/src/auth/sign.test.ts +++ b/services/relayer/src/auth/sign.test.ts @@ -1,6 +1,6 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { KeyPair, actions, base64Encode, createTransaction, encodeTransaction } from "near-api-js"; -import { validateNativeIntent, validateSigningRequest } from "./sign"; +import { SEASON_STORAGE_DEPOSIT, validateNativeIntent, validateSigningRequest } from "./sign"; const key=KeyPair.fromRandom("ed25519").getPublicKey(); const root="tidebound.testnet"; const sender=`p-1.${root}`; const context={root,items:`items.${root}`,clientId:"configured-client",origin:"https://harbor.example",origins:["https://harbor.example"]}; @@ -48,3 +48,40 @@ test("content versions retain their own command language and decision cap",()=>{ for(const changed of [{commands:Array(25).fill("wait")},{commands:["move:left"]},{commands:["take:salvage"]},{content_version:"first_light_v3"},{content_version:"first_light_v1",commands:["step:north"]},{content_version:"first_light_v1",commands:Array(16).fill("wait")}])expect(()=>validateSigningRequest(body(root,actions.functionCall("tidebound_claim",{...args,...changed},50000000000000n,0n)),context)).toThrow(); expect(()=>validateSigningRequest(body(root,actions.functionCall("tidebound_claim",{...args,content_version:"first_light_v1",commands:["move:left","wait","return"]},50000000000000n,0n)),context)).not.toThrow(); }); +describe("season allowlist",()=>{ + const season=`season.${root}`,pet=`mochi-1.${root}`,gas=100000000000000n; + const tx=(method:string,args:Record,deposit=0n,receiver=season,extra=false)=>createTransaction(sender,key,receiver,21n,[actions.functionCall(method,args,gas,deposit),...(extra?[actions.functionCall(method,args,gas,deposit)]:[])],new Uint8Array(32)); + const claim={rules_version:"tidebound_h1_v1",content_version:"first_light_v2",tool:"rope",area:"beacon",commands:["step:north","return"]}; + const cases:[string,Record,bigint][]=[ + ["claim_daily",claim,0n], + ["claim_daily",{...claim,content_version:"first_light_v1",commands:["move:left","take:lens","return"]},0n], + ["buy",{good:"glass",qty:1,max_price:8},0n], + ["sell",{good:"reed",qty:2,min_price:3},0n], + ["set_wish",{pet,good:"glass",limit:12,qty:2},0n], + ["cancel_wish",{pet},0n], + ["storage_deposit",{},SEASON_STORAGE_DEPOSIT], + ]; + for(const [method,args,deposit] of cases) test(`${method} accepts the exact call and refuses variants`,()=>{ + expect(()=>validateNativeIntent(tx(method,args,deposit),context)).not.toThrow(); + expect(()=>validateSigningRequest(body(season,actions.functionCall(method,args,gas,deposit)),context)).not.toThrow(); + for(const receiver of [root,context.items,"season.elsewhere.testnet",`season.${root}.evil.testnet`,sender]) expect(()=>validateNativeIntent(tx(method,args,deposit,receiver),context)).toThrow(); + expect(()=>validateNativeIntent(tx(method,args,deposit,season,true),context)).toThrow(); + for(const wrong of deposit===0n?[1n,10n**24n]:[0n,1n,deposit-1n,deposit+1n]) expect(()=>validateNativeIntent(tx(method,args,wrong),context)).toThrow(); + expect(()=>validateNativeIntent(tx(method,{...args,extra:1},deposit),context)).toThrow(); + }); + test("season arguments are bounded",()=>{ + const bad:[string,Record][]=[ + ["claim_daily",{...claim,area:"wind"}],["claim_daily",{...claim,tool:"net"}],["claim_daily",{...claim,rules_version:"tidebound_h2"}], + ["claim_daily",{...claim,content_version:"first_light_v3"}],["claim_daily",{...claim,commands:["move:left"]}],["claim_daily",{...claim,commands:[]}], + ["claim_daily",{...claim,commands:Array(25).fill("wait")}],["claim_daily",{...claim,content_version:"first_light_v1",commands:Array(16).fill("wait")}], + ["buy",{good:"bread",qty:1,max_price:8}],["buy",{good:"glass",qty:0,max_price:8}],["buy",{good:"glass",qty:21,max_price:8}],["buy",{good:"glass",qty:1,max_price:"8"}],["buy",{good:"glass",qty:1.5,max_price:8}],["buy",{good:"glass",qty:1,min_price:8}], + ["sell",{good:"glass",qty:1,min_price:0}],["sell",{good:"glass",qty:1,max_price:6}], + ["set_wish",{pet,good:"glass",limit:13,qty:2}],["set_wish",{pet,good:"glass",limit:1,qty:3}],["set_wish",{pet,good:"glass",limit:0,qty:1}],["set_wish",{pet:"mochi.elsewhere.testnet",good:"glass",limit:1,qty:1}], + ["cancel_wish",{pet:"elsewhere.testnet"}],["storage_withdraw",{}],["get_shelf",{}],["new",{root}],["on_wish_owner",{owner:sender,pet,good:"glass",limit:1,qty:1}], + ]; + for(const [method,args] of bad) expect(()=>validateNativeIntent(tx(method,args),context)).toThrow(); + expect(()=>validateNativeIntent(tx("storage_deposit",{account_id:sender},SEASON_STORAGE_DEPOSIT),context)).toThrow(); + expect(()=>validateNativeIntent(tx("claim_daily",claim,0n,context.items),context)).toThrow(); + expect(()=>validateNativeIntent(tx("storage_deposit",{},SEASON_STORAGE_DEPOSIT,root),context)).toThrow(); + }); +}); diff --git a/services/relayer/src/auth/sign.ts b/services/relayer/src/auth/sign.ts index 5893871..4df0a0b 100644 --- a/services/relayer/src/auth/sign.ts +++ b/services/relayer/src/auth/sign.ts @@ -6,6 +6,13 @@ import { validName } from "../../../../web/src/rules"; import { ACTION_LIMIT, isTool } from "../../../../web/src/compatibility/return-rules"; import { ITEM_STORAGE_CAP } from "../../../../web/src/tidebound/storage"; +/** Season 2 registration deposit: `storage_minimum` on season. (1,250 bytes at 1e19 yocto per byte). */ +export const SEASON_STORAGE_DEPOSIT=12_500_000_000_000_000_000_000n; +const SEASON_COMMANDS={ + first_light_v1:/^(wait|return|turn:vane|move:(left|center|right)|lure:(left|center|right)|take:(lens|moth|chart|salvage|vane)|reel:(lens|salvage|vane))$/, + first_light_v2:/^(wait|return|turn:vane|step:(north|south|west|east)|lure:(left|center|right)|take:(lens|moth|vane)|reel:(lens|vane))$/, +} as const; +const wholeNumber=(value:unknown,min:number,max:number)=>typeof value==="number" && Number.isSafeInteger(value) && value>=min && value<=max; export interface AuthSigningContext { root:string; items:string; clientId:string; origin:string; origins:readonly string[] } function check(value:unknown):asserts value { if (!value) throw new Error("ERR_AUTH_REQUEST"); } const bounded=(value:unknown,max=128):value is string=>typeof value === "string" && value.length > 0 && value.length <= max; @@ -37,6 +44,28 @@ export function validateNativeIntent(tx:Transaction,context:Pick0 && a.commands.length<=(v2?24:ACTION_LIMIT) && a.commands.every(c=>typeof c==="string" && command.test(c))); + return; + } + case "buy": fields(a,["good","qty","max_price"]); check((a.good==="glass" || a.good==="reed") && wholeNumber(a.qty,1,20) && wholeNumber(a.max_price,1,1000)); return; + case "sell": fields(a,["good","qty","min_price"]); check((a.good==="glass" || a.good==="reed") && wholeNumber(a.qty,1,20) && wholeNumber(a.min_price,1,1000)); return; + case "set_wish": { + fields(a,["pet","good","limit","qty"]); + check(bounded(a.pet,64) && accountId(a.pet) && (a.pet as string).endsWith(`.${context.root}`) && (a.good==="glass" || a.good==="reed") && wholeNumber(a.qty,1,2) && wholeNumber(a.limit,1,24) && (a.limit as number)*(a.qty as number)<=24); + return; + } + case "cancel_wish": fields(a,["pet"]); check(bounded(a.pet,64) && accountId(a.pet) && (a.pet as string).endsWith(`.${context.root}`)); return; + default: throw new Error("ERR_AUTH_METHOD"); + } + } check(tx.receiverId===context.root && call.deposit===0n); const token=(value:unknown)=>bounded(value,64) && accountId(value) && value.endsWith(`.${context.root}`); switch(call.methodName) { diff --git a/web/assets/source/README.md b/web/assets/source/README.md index 73a0512..5647729 100644 --- a/web/assets/source/README.md +++ b/web/assets/source/README.md @@ -7,3 +7,5 @@ The [First Light provenance record](../../public/assets/first-light-motion/prove `expedition/` holds the PNG masters and full-size WebPs for the tide court, stone island and wooden bridge. The other full-size optimizer inputs for Bram, the shell and the wave live in `first-light-motion/`. Run `bun scripts/optimize-expedition-assets.ts` to regenerate the eleven WebPs in `web/public/assets/expedition/runtime/` using cwebp. In the [encoding manifest](../../public/assets/expedition/runtime/manifest.json), source paths are relative to `web/` and output paths to `web/public/`. Five inputs also appear at full size in the game or introduction. + +`season/` holds the five Season 2 icon masters (glass, reed, Bram's shelf and till, Mochi's purse, the wish token), generated with gpt-6-astra through the Codex CLI; prompts and original paths are in the [season provenance record](../../public/assets/season/provenance.json). Run `bun scripts/optimize-season-assets.ts` to regenerate the WebPs and manifest in `web/public/assets/season/`; it removes the cream backdrop by corner flood fill and needs ImageMagick and cwebp. diff --git a/web/assets/source/season/glass.png b/web/assets/source/season/glass.png new file mode 100644 index 0000000..0b12f14 Binary files /dev/null and b/web/assets/source/season/glass.png differ diff --git a/web/assets/source/season/purse.png b/web/assets/source/season/purse.png new file mode 100644 index 0000000..6444927 Binary files /dev/null and b/web/assets/source/season/purse.png differ diff --git a/web/assets/source/season/reed.png b/web/assets/source/season/reed.png new file mode 100644 index 0000000..b2e598b Binary files /dev/null and b/web/assets/source/season/reed.png differ diff --git a/web/assets/source/season/shelf-till.png b/web/assets/source/season/shelf-till.png new file mode 100644 index 0000000..5121e92 Binary files /dev/null and b/web/assets/source/season/shelf-till.png differ diff --git a/web/assets/source/season/wish-token.png b/web/assets/source/season/wish-token.png new file mode 100644 index 0000000..d6ee185 Binary files /dev/null and b/web/assets/source/season/wish-token.png differ diff --git a/web/public/assets/season/glass.webp b/web/public/assets/season/glass.webp new file mode 100644 index 0000000..e0b323e Binary files /dev/null and b/web/public/assets/season/glass.webp differ diff --git a/web/public/assets/season/manifest.json b/web/public/assets/season/manifest.json new file mode 100644 index 0000000..aab1f9d --- /dev/null +++ b/web/public/assets/season/manifest.json @@ -0,0 +1,66 @@ +{ + "purpose": "Season 2 runtime icons; cream backdrop removed by corner flood fill (fuzz 7%)", + "encoder": "magick + cwebp quality85 method6 alpha100", + "files": [ + { + "source": "assets/source/season/glass.png", + "output": "assets/season/glass.webp", + "sourceSha256": "1905c329182860e8ae3b95731110ba7cb46b08994dad17251b44fd7b2201e911", + "sha256": "bd0127d2d701ba993712b57005638c54d7dd1de8192454d54187bd6f283f1d50", + "sourceBytes": 1199881, + "bytes": 3536, + "resizedTo": { + "width": 192, + "height": 192 + } + }, + { + "source": "assets/source/season/reed.png", + "output": "assets/season/reed.webp", + "sourceSha256": "892e41577ba6a8287ba9fe9da52673b8a930867db9a7eeb1bcb8ff2f95ad018a", + "sha256": "7fc0a59b39a02e4532948244c412cc5a95a821fd5b137a2f8135e467e3aaa042", + "sourceBytes": 1195823, + "bytes": 5476, + "resizedTo": { + "width": 192, + "height": 192 + } + }, + { + "source": "assets/source/season/shelf-till.png", + "output": "assets/season/shelf-till.webp", + "sourceSha256": "16ac6c94ff5d3f2d45cb346314f02809d540755457b83a89466c8cfab7eafa87", + "sha256": "3c2e301220b3f6e159f7c3f4cb91800c736c8871e4ce6a34b3f74f345d7dbd5c", + "sourceBytes": 1464913, + "bytes": 14148, + "resizedTo": { + "width": 320, + "height": 320 + } + }, + { + "source": "assets/source/season/purse.png", + "output": "assets/season/purse.webp", + "sourceSha256": "797334a0eb5fbfd99e33a1cf23008ac8a190ef3e3ddff92dfa50c2d75f461420", + "sha256": "2c5ea89a71f3c9a8eb4ffae684896b546bc020ff90dc7a67820628b50e222a0e", + "sourceBytes": 1448233, + "bytes": 6150, + "resizedTo": { + "width": 192, + "height": 192 + } + }, + { + "source": "assets/source/season/wish-token.png", + "output": "assets/season/wish-token.webp", + "sourceSha256": "e33e92d420404f6fbda2a76aba386f9a921bf3ea05c236583991c5b6c00c0905", + "sha256": "2bd518b3eb123a833b0ec084b883eed0406c18011e3f69c452c248b672fbdea2", + "sourceBytes": 1320809, + "bytes": 5416, + "resizedTo": { + "width": 192, + "height": 192 + } + } + ] +} diff --git a/web/public/assets/season/provenance.json b/web/public/assets/season/provenance.json new file mode 100644 index 0000000..1aa592f --- /dev/null +++ b/web/public/assets/season/provenance.json @@ -0,0 +1,44 @@ +{ + "created": "2026-11-13", + "purpose": "Familiar Season 2 icons: glass and reed goods, Bram's shelf and till, Mochi's purse and wish token", + "generator": { + "tool": "Codex CLI codex-cli 0.169.0 (`codex exec`, image generation tool)", + "model": "gpt-6-astra", + "session": "01a1d70e-72cf-7c02-9d2d-1e5bdb89c1e5" + }, + "styleReferences": [ + "web/assets/source/first-light-motion/bram.png", + "web/assets/source/first-light-motion/lens.png", + "web/assets/source/first-light-motion/moth.png", + "web/assets/source/first-light-motion/shell.png" + ], + "delivery": "WebP renditions produced by scripts/optimize-season-assets.ts (see manifest.json). Masters are 1024x1024 PNG on a cream backdrop that is not pixel-exact; the cream is removed by corner flood fill.", + "files": { + "glass.webp": { + "master": "web/assets/source/season/glass.png", + "prompt": "Create one square 1024x1024 PNG game asset for the cozy harbor game Familiar: glass.png. Subject: one small rounded translucent teal-green sea-glass pebble, a chunky irregular chunk with softly frosted edges, crafted as a handmade felt-and-wool stop-motion miniature with visible fine fibres while retaining a gentle glasslike translucency. Match the attached Bram, lens, moth, and shell references in handmade materials, soft warm studio lighting, gentle chunky shapes, and warm muted coastal colors (sea-glass teal, sand, cream, weathered wood brown, brass). Center and isolate the single object on a plain flat solid cream background, exact color #efe4cc, with only a soft contact shadow. Object fills about 70% of the frame with generous clear margins and a silhouette readable at 48px. No text, letters, numbers, logos, UI frames, scenery, extra objects, or border.", + "originalGeneratedPath": "/Users/dadadave/.codex/generated_images/01a1d70e-72cf-7c02-9d2d-1e5bdb89c1e5/exec-5dd310c4-d6fd-40d8-966d-d8c9a238b94c.png" + }, + "reed.webp": { + "master": "web/assets/source/season/reed.png", + "prompt": "Create one square 1024x1024 PNG game asset for the cozy harbor game Familiar: reed.png. Subject: one small tied bundle of felted harbor reeds, golden-green stalks bound around the middle with a twist of natural twine; a few simple soft reed heads and narrow leaves, chunky and tidy enough to read as one trade good. Match the attached Bram, lens, moth, and shell references in handmade felt-and-wool stop-motion miniature style, visible fibre texture, soft warm studio lighting, gentle chunky shapes, and warm muted coastal colors (sea-glass teal, sand, cream, weathered wood brown, brass). Center and isolate the object on a plain flat solid cream background, exact color #efe4cc, with only a soft contact shadow. Object fills about 70% of the frame with generous clear margins and a silhouette readable at 48px. No text, letters, numbers, logos, UI frames, scenery, unrelated objects, or border.", + "originalGeneratedPath": "/Users/dadadave/.codex/generated_images/01a1d70e-72cf-7c02-9d2d-1e5bdb89c1e5/exec-4e043fe4-f103-4c53-b680-36117f05b181.png" + }, + "shelf-till.webp": { + "master": "web/assets/source/season/shelf-till.png", + "prompt": "Create one square 1024x1024 PNG game asset for the cozy harbor game Familiar: shelf-till.png. Subject: Bram's harbor trading shelf, a small weathered wooden shelf with exactly two clearly visible cubbies, one holding teal sea-glass pebbles and the other holding golden-green reed bundles tied with twine. Include a little closed wooden till box with brass corners and a simple scallop shell on its lid, sitting at the shelf's base in front, so shelf and till form one compact readable miniature arrangement. Show the cubby contents and till lid clearly. Match the attached Bram, lens, moth, and shell references in handmade felt-and-wool stop-motion miniature style, visible fibre texture, soft warm studio lighting, gentle chunky shapes, and warm muted coastal colors (sea-glass teal, sand, cream, weathered wood brown, brass). Center and isolate the object on a plain flat solid cream background, exact color #efe4cc, with only a soft contact shadow. Object fills about 70% of the frame with generous clear margins and a silhouette readable at 48px. No text, letters, numbers, logos, UI frames, scenery, unrelated objects, or border.", + "originalGeneratedPath": "/Users/dadadave/.codex/generated_images/01a1d70e-72cf-7c02-9d2d-1e5bdb89c1e5/exec-c1d3def3-4050-4222-baf9-7ca9467c7ae0.png" + }, + "purse.webp": { + "master": "web/assets/source/season/purse.png", + "prompt": "Create one square 1024x1024 PNG game asset for the cozy harbor game Familiar: purse.png. Subject: Mochi's tiny drawstring purse, a rounded soft felt pouch in warm rust and cream, gathered at the top with a natural cord, with a small simple scallop-shell clasp and a few small cream shells peeking out of the opening. Keep the shell clasp and pouch silhouette chunky, warm, and immediately recognizable. Match the attached Bram, lens, moth, and shell references in handmade felt-and-wool stop-motion miniature style, visible fibre texture, soft warm studio lighting, gentle chunky shapes, and warm muted coastal colors (sea-glass teal, sand, cream, weathered wood brown, brass). Center and isolate the object on a plain flat solid cream background, exact color #efe4cc, with only a soft contact shadow. Object fills about 70% of the frame with generous clear margins and a silhouette readable at 48px. No text, letters, numbers, logos, UI frames, scenery, unrelated objects, or border.", + "originalGeneratedPath": "/Users/dadadave/.codex/generated_images/01a1d70e-72cf-7c02-9d2d-1e5bdb89c1e5/exec-d4bbe6c8-80c7-4b3b-b7bd-4edc837b9e21.png" + }, + "wish-token.webp": { + "master": "web/assets/source/season/wish-token.png", + "prompt": "Create one square 1024x1024 PNG game asset for the cozy harbor game Familiar: wish-token.png. Subject: one small round felt-and-wood wish tag tied with string, like a wish pinned to a harbor notice board, but show only the isolated tag with its attached loop of string. A thin weathered wooden edge surrounds a cream felt face embroidered with one simple star and one simple wave in chunky golden and sea-glass teal stitches. The star-and-wave motif is pictorial, never letters. Match the attached Bram, lens, moth, and shell references in handmade felt-and-wool stop-motion miniature style, visible fibre texture, soft warm studio lighting, gentle chunky shapes, and warm muted coastal colors (sea-glass teal, sand, cream, weathered wood brown, brass). Center and isolate the object on a plain flat solid cream background, exact color #efe4cc, with only a soft contact shadow. Object fills about 70% of the frame with generous clear margins and a silhouette readable at 48px. No text, letters, numbers, logos, UI frames, scenery, unrelated objects, or border.", + "originalGeneratedPath": "/Users/dadadave/.codex/generated_images/01a1d70e-72cf-7c02-9d2d-1e5bdb89c1e5/exec-92d8cbb0-259f-4a32-97fe-3f407121cfb2.png" + } + }, + "masters": "Each master is the 1254x1254 generated original resized to 1024x1024 by Codex with `sips -z 1024 1024`; originals stay at the listed paths outside Git." +} \ No newline at end of file diff --git a/web/public/assets/season/purse.webp b/web/public/assets/season/purse.webp new file mode 100644 index 0000000..125f4c0 Binary files /dev/null and b/web/public/assets/season/purse.webp differ diff --git a/web/public/assets/season/reed.webp b/web/public/assets/season/reed.webp new file mode 100644 index 0000000..46311a7 Binary files /dev/null and b/web/public/assets/season/reed.webp differ diff --git a/web/public/assets/season/shelf-till.webp b/web/public/assets/season/shelf-till.webp new file mode 100644 index 0000000..f5f4f42 Binary files /dev/null and b/web/public/assets/season/shelf-till.webp differ diff --git a/web/public/assets/season/wish-token.webp b/web/public/assets/season/wish-token.webp new file mode 100644 index 0000000..c61f126 Binary files /dev/null and b/web/public/assets/season/wish-token.webp differ diff --git a/web/src/account/adapter.ts b/web/src/account/adapter.ts index 049ae40..fcbfc5a 100644 --- a/web/src/account/adapter.ts +++ b/web/src/account/adapter.ts @@ -124,7 +124,7 @@ export class NearAuthAccountAdapter implements RecoverableAccountAdapter { const session=this.session,generation=this.generation;check(session,"Sign in to authorize this action."); const binding=await this.resolveBinding();this.sameSession(session,generation);check(binding,"Sign in to authorize this action."); check(transaction.signerId===binding.nearAccountId && transaction.publicKey.toString()===binding.signerPublicKey); - check(transaction.receiverId===this.options.root || transaction.receiverId===this.options.items || transaction.receiverId===binding.nearAccountId,"The action belongs to a different harbor."); + check(transaction.receiverId===this.options.root || transaction.receiverId===this.options.items || transaction.receiverId===`season.${this.options.root}` || transaction.receiverId===binding.nearAccountId,"The action belongs to a different harbor."); const bytes=encodeTransaction(transaction),encoded=base64Encode(bytes),key=this.pendingKey(operationId,binding); const stored=this.options.storage.getItem(key); const pending:PendingAuthorization=stored?JSON.parse(stored):{operationId,transaction:encoded,state:"prepared"}; diff --git a/web/src/account/privy-adapter.ts b/web/src/account/privy-adapter.ts index 8c59853..911dcb9 100644 --- a/web/src/account/privy-adapter.ts +++ b/web/src/account/privy-adapter.ts @@ -154,7 +154,7 @@ export class PrivyAccountAdapter implements RecoverableAccountAdapter { const identity=await this.identity(),generation=this.generation,binding=await this.resolveBinding(); check(identity && binding,"Sign in to authorize this action."); const wallet=await this.canonicalWallet(false);check(wallet,"The canonical recovery wallet is unavailable."); - check(transaction.signerId===binding.nearAccountId && transaction.publicKey.toString()===binding.signerPublicKey && [this.options.root,this.options.items,binding.nearAccountId].includes(transaction.receiverId),"The native transaction belongs to a different account or harbor."); + check(transaction.signerId===binding.nearAccountId && transaction.publicKey.toString()===binding.signerPublicKey && [this.options.root,this.options.items,`season.${this.options.root}`,binding.nearAccountId].includes(transaction.receiverId),"The native transaction belongs to a different account or harbor."); validateNativeIntent(transaction,{root:this.options.root,items:this.options.items}); const encoded=base64Encode(encodeTransaction(transaction)),digest=await nearSigningDigest(transaction),key=this.pendingKey(operationId,binding); const raw=this.options.storage.getItem(key),pending:PendingAuthorization=raw?JSON.parse(raw):{operationId,transaction:encoded,state:"prepared"}; diff --git a/web/src/expedition/Game.tsx b/web/src/expedition/Game.tsx index b42578d..2caf1ff 100644 --- a/web/src/expedition/Game.tsx +++ b/web/src/expedition/Game.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"; +import { Suspense, lazy, useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import "@fontsource-variable/fraunces"; import "@fontsource-variable/figtree"; import World from "./World"; @@ -18,10 +18,15 @@ import type { HarborSession, HomeCheckpoint, RunContext, WorldIntent } from "./h import type { HarborView, HomePlace } from "./scene"; import { LanternArt, OriginDiorama } from "../tidebound/Storycraft"; import "./game.css"; +import { keepTide } from "../season/data"; + +const SEASON2=import.meta.env.VITE_SEASON2_ENABLED==="true"; +// Behind the flag so a build without Season 2 leaves the screens out entirely. +const SeasonBram=SEASON2?lazy(()=>import("../season/SeasonBram")):()=>null; export const EXPEDITION_SAVE_KEY="familiar.expedition.local.v2"; interface LocalHome extends HomeCheckpoint {lantern:null|{motif:"crest"|"moth";socket:"porch"|"dock"}} -interface ActiveSave {context:RunContext;state:CourtState} +interface ActiveSave {context:RunContext;state:CourtState;season?:true} interface LocalSave {version:2;home:LocalHome;active:ActiveSave|null;last:CourtState|null} const fresh=():LocalSave=>({version:2,home:{banked:[],lit:false,signaled:false,lantern:null},active:null,last:null}); const names={lens:"Beacon Lens",moth:"wind-moth",vane:"Signal Vane"}; @@ -171,13 +176,15 @@ export default function ExpeditionGame({session,accountPanel,audio:titleAudio,in useEffect(()=>{if(!surface&&!session?.state.review)return;const trap=(event:KeyboardEvent)=>{if(event.key!=="Tab")return;const panel=panelRef.current;if(!panel)return;const targets=[...panel.querySelectorAll('button:not(:disabled),a[href],input:not(:disabled),select:not(:disabled),[tabindex="0"]')].filter(n=>n.getClientRects().length);if(!targets.length){event.preventDefault();panel.focus();return;}const first=targets[0]!,last=targets.at(-1)!;if(event.shiftKey&&(document.activeElement===first||document.activeElement===panel)){event.preventDefault();last.focus();}else if(!event.shiftKey&&(document.activeElement===last||document.activeElement===panel)){event.preventDefault();first.focus();}};window.addEventListener("keydown",trap);return()=>window.removeEventListener("keydown",trap);},[surface,session?.state.review?.id]); function persist(next:LocalSave){if(leaseRef.current!=="held"){setNotice("This expedition is open in another tab. Finish there, or close that tab and check again.");return false;}try{writeLocal(next,keyRef.current);saveRef.current=next;setSave(next);setProblem("");return true;}catch(error){setProblem(error instanceof Error?error.message:"This browser could not save the move. No new action was taken.");return false;}} - function begin(){ + /** `tide` starts Season 2's daily outing: a fresh Beacon Court with nothing banked, kept apart from First Light progress. */ + function begin(tide?:{tool:Tool}){ if(showPassage||!worldReady||saveRef.current.active||corruptRef.current||leaseRef.current!=="held")return; - try{const context=sessionRef.current?.runContext(saveRef.current.home)??{authority:"local-preview" as const,banked:[...saveRef.current.home.banked],lit:saveRef.current.home.lit,signaled:saveRef.current.home.signaled}; - if(area==="wind"&&!context.lit){setNotice("Restore the beacon before sailing to Wind Gate.");return;} + try{const harborContext=sessionRef.current?.runContext(saveRef.current.home)??{authority:"local-preview" as const,banked:[...saveRef.current.home.banked],lit:saveRef.current.home.lit,signaled:saveRef.current.home.signaled}; + const context:RunContext=tide?{...harborContext,banked:[]}:harborContext,runArea:Area=tide?"beacon":area,runTool:Tool=tide?.tool??tool; + if(runArea==="wind"&&!context.lit){setNotice("Restore the beacon before sailing to Wind Gate.");return;} setResting(false); - const state=startCourt({area,tool,banked:context.banked});if(!persist({...saveRef.current,active:{context,state},last:null})){sessionRef.current?.setActiveRun(null);return;} - sessionRef.current?.setActiveRun?.(context);audio.current?.playMusic(area==="wind"?"wind-departure":"departure");setSurface(null);setNotice(area==="wind"?"Watch the outlet. The wheel bends a marked surge into a different channel.":"Tap a glowing neighbor to move. Water advances only when you decide.");setTransition(null);buffer.current=null; + const state=startCourt({area:runArea,tool:runTool,banked:context.banked});if(!persist({...saveRef.current,active:{context,state,...(tide?{season:true as const}:{})},last:null})){sessionRef.current?.setActiveRun(null);return;} + sessionRef.current?.setActiveRun?.(context);audio.current?.playMusic(runArea==="wind"?"wind-departure":"departure");setSurface(null);setNotice(runArea==="wind"?"Watch the outlet. The wheel bends a marked surge into a different channel.":"Tap a glowing neighbor to move. Water advances only when you decide.");setTransition(null);buffer.current=null; }catch(error){setProblem(error instanceof Error?error.message:"The outing could not start. Your saved harbor is unchanged.");} } async function complete(){ @@ -185,11 +192,12 @@ export default function ExpeditionGame({session,accountPanel,audio:titleAudio,in if(finishBusy.current)return;finishBusy.current=true;setFinishing(true); const epoch=++finishEpoch.current,branch=keyRef.current,generation=presentation.current,owner=sessionRef.current; try{ - if(owner)await owner.captureReturn(active.state,active.context);else await new ReturnRecords(localStorage).capture(active.state,active.context); + if(active.season)keepTide(active.context.authority==="near-testnet"?active.context.accountId:"preview",{id:crypto.randomUUID(),contentVersion:CONTENT_VERSION,tool:active.state.tool,commands:[...active.state.commands],cargo:[...active.state.cargo],outcome:active.state.outcome==="returned"?"returned":"rescued",savedAt:new Date().toISOString()}); + else if(owner)await owner.captureReturn(active.state,active.context);else await new ReturnRecords(localStorage).capture(active.state,active.context); if(!alive.current||epoch!==finishEpoch.current||branch!==keyRef.current||generation!==presentation.current||saveRef.current.active!==active||sessionRef.current!==owner)return; - const banked=active.context.authority==="local-preview"?[...new Set([...current.home.banked,...(active.state.outcome==="returned"?active.state.cargo:[])])]:current.home.banked; + const banked=!active.season&&active.context.authority==="local-preview"?[...new Set([...current.home.banked,...(active.state.outcome==="returned"?active.state.cargo:[])])]:current.home.banked; const next={...current,home:{...current.home,banked},active:null,last:active.state}; - if(!persist(next))return;sessionRef.current?.setActiveRun?.(null);setTransition(null);setNotice(active.state.outcome==="returned"?(active.state.cargo.length?`Home with ${active.state.cargo.map(i=>names[i]).join(" and ")}.${active.context.authority==="near-testnet"?" Bring the satchel to Bram.":""}`:"Mochi is home, safe and empty-pawed."):eventDescription({kind:"rescue",reason:active.state.resolve<=0?"resolve":"flood"})); + if(!persist(next))return;sessionRef.current?.setActiveRun?.(null);setTransition(null);setNotice(active.state.outcome==="returned"?(active.state.cargo.length?`Home with ${active.state.cargo.map(i=>names[i]).join(" and ")}.${active.season?" Dock today’s haul at Bram’s shelf.":active.context.authority==="near-testnet"?" Bring the satchel to Bram.":""}`:"Mochi is home, safe and empty-pawed."):eventDescription({kind:"rescue",reason:active.state.resolve<=0?"resolve":"flood"})); }catch(error){if(alive.current&&epoch===finishEpoch.current&&branch===keyRef.current)setProblem(error instanceof Error?error.message:"The returned outing could not be recorded. Keep it open and retry saving.");} finally{if(alive.current&&epoch===finishEpoch.current){finishBusy.current=false;setFinishing(false);}} } @@ -327,7 +335,7 @@ export default function ExpeditionGame({session,accountPanel,audio:titleAudio,in
{notice}
{(problem||activeReturn&&!busy)&&

{problem||(finishing?"Keeping the original return safe…":"Mochi’s return is ready to save.")}

{activeReturn&&}{!corrupt&&!activeReturn&&}
} {(lease==="blocked"||lease==="unavailable")&&

{lease==="blocked"?"This expedition is open in another tab. Finish there, or close that tab before continuing here.":"This browser cannot safely coordinate saved expeditions. Web Locks support is required; no move has been taken."}

{lease==="blocked"&&}
} - {(surface||session?.state.review)&&
+ {(surface||session?.state.review)&&
{session?.state.review?<>

{session.state.review.title}

{session.state.review.description}

{session.state.review.costs.length>0&&
    {session.state.review.costs.map(cost=>
  • {cost}
  • )}
}:surface==="account"?<>

Keep your harbor

{accountPanel??

Recoverable account controls are not connected to this local preview. This visit does not prove ownership or device recovery.

}:surface==="menu"?<>

A moment at the water’s edge.

Play at your own pace. Only accepted decisions advance the tide.

{sound&&
Sound mix
}:surface==="lantern"?<>

A light on the water.

Choose a source. The wind-wheel, when present, determines its exit.

{(["left","center","right"] as const).map(lane=>)}:surface==="inspect"&&run?:surface==="guide"?<>

Read the water.

Tap a glowing neighboring platform, use the arrow keys or W A S D, or use the direction buttons. Crossing the open bridge is one decision.

Low: choose your footing. Rising: your resulting column becomes the source. Surge: act first, then the wave opens that column’s bridge and shell. Standing in the wave washes Mochi down one platform.

Rope retrieves an exposed lens or vane from two steps away. Lantern redirects a marked surge. A living moth needs two pack slots. Reach the center dock to return before 24 decisions.

{run?.area==="wind"&&

Current channels: Left → {columns[run.orientation]}, Center → {columns[(1+run.orientation)%3]}, Right → {columns[(2+run.orientation)%3]}. The cradle needs Left and Center charged and wheel alignment zero.

}

E uses a nearby object; Space waits; R returns at the dock. Right-click or hold a world target to inspect for free. Inspection and menus spend no turns.

:surface==="chart"?{setArea(choice);open("sail");}} onCrossing={departPassage} onRepair={()=>open("beacon")} onRest={()=>{setSurface(null);setGreeting(0);setResting(true);if(sound)audio.current?.playMusic("harbor");}}/>:surface==="crossings"?<> @@ -338,7 +346,7 @@ export default function ExpeditionGame({session,accountPanel,audio:titleAudio,in

{passageError||"These crossings and their harbor changes are saved on this device."}

- :surface==="sail"?<>

What shall we bring?

{home.lit&&}
Outing{(["beacon","wind"] as const).map(choice=>)}
{area==="wind"&&

The wheel on the far bank steers the tide. Charge the left and center outlets to free the harbor’s signal vane.

}
One tool{(["rope","lantern"] as const).map(choice=>)}
:surface==="beacon"?<>{(needVane||home.signaled)&&}

{needVane?"One missing piece.":home.signaled?"Wind on the quay.":home.lit?"The beacon knows the way.":"A light for everyone."}

{needVane?"Bram holds the post while Mochi raises the brass arrow to its spindle.":home.signaled?"The signal arrow swings free above the quay. The beacon lights the way home.":home.lit?"The lens is safe in its lantern. Its light belongs to the whole harbor.":home.banked.includes("lens")?"The recovered lens fits the empty lantern. Mochi is ready to lift it into place.":"The missing lens waits in Beacon Court’s left shell. The Tidekeeper can open it."}

{!home.lit&&home.banked.includes("lens")&&}{home.lit&&!home.signaled&&home.banked.includes("vane")&&}:surface==="satchel"?<>

What came home.

{home.banked.length?home.banked.map(i=>i in names?names[i as keyof typeof names]:title(i)).join(" · "):"An empty satchel. There’s room for a small adventure."}

{recordReturns.map(record=>)}{earlierReturns.map(record=>
Earlier {COURTS[record.area].title} memory

This return began at another saved checkpoint. Its original memory is preserved; it cannot be merged into the current harbor.

{record.id}

)}{sealedNoteEnabled()&&savedMode&&session?.noteToken&&session.noteToken!()}/>}{save.last&&

{save.last.outcome==="returned"?`Mochi came home after ${save.last.turn} decisions with ${save.last.resolve}/3 Resolve.`:"Bram brought Mochi home. Only the unbanked cargo was lost."}

}

{authority}. {savedMode?"Only accepted returns change the saved harbor.":"Device saves are not backed up or transferable. Signing in does not replace this preview."}

:surface==="bram"?<>

“You’re back.”

{lastService==="bell"?"Bram shades his eyes. Across the channel his crates are stacked high and dry.":lastService==="reed"?"Bram loops the skiff’s painter around the mooring and checks Mochi’s knot.":home.signaled?"Bram watches the arrow swing. “An easterly. I can tell before I untie a single rope.”":home.banked.includes("moth")?"The little wings sound rather like a kettle beginning to sing. Bram makes room beside the hearth.":home.lit?"Bram puts the kettle on. A harbor looks different when everyone can find it.":"Bram looks across the bay. “A lighthouse shouldn’t have to guess where it’s pointing.”"}

{harbor.heardBell&&

“There’s your bell,” Bram says. “I’ve run a pull to the far-center landing at both crossings. One good tug calls the Tidekeeper’s surge left. Choose when to use it.”

}{passage.watchedReeds&&passageScope===passageKey&&

Mochi settles beside you, one paw tucked under, just as at the reeds.

}{home.lit&&}{session?.state.workshop.commissionAvailable&&}{recordReturns.length>0&&}{(waitingCraft||waitingPolish)&&
Original job details

Bram keeps the original job. An uncertain result never authorizes another lantern, payment or refund.

{session?.state.pending?:<>{waitingPolish&&}}
}{!savedMode&&

The personal Shell commission belongs to an accepted saved return. This preview does not issue currency.

}:surface==="workbench"?<>

A little light of your own.

{savedMode?<>{session?.state.workshop.creditAvailable?<>

Choose an earned motif for one First Light lantern.

{session.state.workshop.motifs.map(m=>)}:

{session?.state.workshop.items.length?"Your owned lantern keeps the maker’s actual accepted story.":"Bring an accepted Beacon Lens return home to earn the first craft."}

}{!!session?.state.workshop.items.length&&
Give a lantern

Gifting moves the owned item. The maker’s achievement stays with its maker. Storage, if needed, is a separate reviewed action.

}{session?.state.workshop.items.map(item=>

{title(item.mint.motif)} lantern · {item.finish==="harbor_polish"?"Harbor polish":"Original finish"}

Origin and maker

Illustrated {item.mint.motif==="moth"?"wind-moth rescue":"Beacon Lens return"}, from the maker’s actual accepted event. This is not a recorded screenshot.

Maker: {item.mint.maker}
Accepted claim: {item.mint.origin_claim_id}
Content: {item.mint.content_version}
Rules: {item.mint.rules_version}

{!item.finish_used&&}
)}:home.lantern?<>

One {title(home.lantern.motif)} lantern. Local preview only; not backed up or transferable.

Light’s origin{previewOrigin?<>

Mochi returned with the {home.lantern.motif==="moth"?"wind-moth":"Beacon Lens"}. {previewOrigin.commands.length} choices with the {title(previewOrigin.tool)}.

Static illustration of this device’s validated return, not a recorded screenshot or an accepted NEAR claim.

Content: {previewOrigin.contentVersion} · memory {previewOrigin.id}

:

The original return is unavailable. This device preview is not proof of an earned event.

}
{(["porch","dock"] as const).map(socket=>)}:canPreviewCrest?<>
{title(motif)} motif

The lens return earned a Crest. A rescued wind-moth earns its own motif.

Motif{(["crest","moth"] as const).map(m=>)}
:

Bring the Beacon Lens home first. A lantern should remember something you actually did.

}:null} + :surface==="sail"?<>

What shall we bring?

{home.lit&&}
Outing{(["beacon","wind"] as const).map(choice=>)}
{area==="wind"&&

The wheel on the far bank steers the tide. Charge the left and center outlets to free the harbor’s signal vane.

}
One tool{(["rope","lantern"] as const).map(choice=>)}
:surface==="beacon"?<>{(needVane||home.signaled)&&}

{needVane?"One missing piece.":home.signaled?"Wind on the quay.":home.lit?"The beacon knows the way.":"A light for everyone."}

{needVane?"Bram holds the post while Mochi raises the brass arrow to its spindle.":home.signaled?"The signal arrow swings free above the quay. The beacon lights the way home.":home.lit?"The lens is safe in its lantern. Its light belongs to the whole harbor.":home.banked.includes("lens")?"The recovered lens fits the empty lantern. Mochi is ready to lift it into place.":"The missing lens waits in Beacon Court’s left shell. The Tidekeeper can open it."}

{!home.lit&&home.banked.includes("lens")&&}{home.lit&&!home.signaled&&home.banked.includes("vane")&&}:surface==="satchel"?<>

What came home.

{home.banked.length?home.banked.map(i=>i in names?names[i as keyof typeof names]:title(i)).join(" · "):"An empty satchel. There’s room for a small adventure."}

{recordReturns.map(record=>)}{earlierReturns.map(record=>
Earlier {COURTS[record.area].title} memory

This return began at another saved checkpoint. Its original memory is preserved; it cannot be merged into the current harbor.

{record.id}

)}{sealedNoteEnabled()&&savedMode&&session?.noteToken&&session.noteToken!()}/>}{save.last&&

{save.last.outcome==="returned"?`Mochi came home after ${save.last.turn} decisions with ${save.last.resolve}/3 Resolve.`:"Bram brought Mochi home. Only the unbanked cargo was lost."}

}

{authority}. {savedMode?"Only accepted returns change the saved harbor.":"Device saves are not backed up or transferable. Signing in does not replace this preview."}

:surface==="bram"?<>

“You’re back.”

{lastService==="bell"?"Bram shades his eyes. Across the channel his crates are stacked high and dry.":lastService==="reed"?"Bram loops the skiff’s painter around the mooring and checks Mochi’s knot.":home.signaled?"Bram watches the arrow swing. “An easterly. I can tell before I untie a single rope.”":home.banked.includes("moth")?"The little wings sound rather like a kettle beginning to sing. Bram makes room beside the hearth.":home.lit?"Bram puts the kettle on. A harbor looks different when everyone can find it.":"Bram looks across the bay. “A lighthouse shouldn’t have to guess where it’s pointing.”"}

{harbor.heardBell&&

“There’s your bell,” Bram says. “I’ve run a pull to the far-center landing at both crossings. One good tug calls the Tidekeeper’s surge left. Choose when to use it.”

}{passage.watchedReeds&&passageScope===passageKey&&

Mochi settles beside you, one paw tucked under, just as at the reeds.

}{home.lit&&}{session?.state.workshop.commissionAvailable&&}{recordReturns.length>0&&}{(waitingCraft||waitingPolish)&&
Original job details

Bram keeps the original job. An uncertain result never authorizes another lantern, payment or refund.

{session?.state.pending?:<>{waitingPolish&&}}
}{!savedMode&&

The personal Shell commission belongs to an accepted saved return. This preview does not issue currency.

}{SEASON2&&Bram is setting out his shelf…

}>begin({tool:choice})} tideScope={savedMode?session!.state.snapshot!.binding.nearAccountId:"preview"}/>
}:surface==="workbench"?<>

A little light of your own.

{savedMode?<>{session?.state.workshop.creditAvailable?<>

Choose an earned motif for one First Light lantern.

{session.state.workshop.motifs.map(m=>)}:

{session?.state.workshop.items.length?"Your owned lantern keeps the maker’s actual accepted story.":"Bring an accepted Beacon Lens return home to earn the first craft."}

}{!!session?.state.workshop.items.length&&
Give a lantern

Gifting moves the owned item. The maker’s achievement stays with its maker. Storage, if needed, is a separate reviewed action.

}{session?.state.workshop.items.map(item=>

{title(item.mint.motif)} lantern · {item.finish==="harbor_polish"?"Harbor polish":"Original finish"}

Origin and maker

Illustrated {item.mint.motif==="moth"?"wind-moth rescue":"Beacon Lens return"}, from the maker’s actual accepted event. This is not a recorded screenshot.

Maker: {item.mint.maker}
Accepted claim: {item.mint.origin_claim_id}
Content: {item.mint.content_version}
Rules: {item.mint.rules_version}

{!item.finish_used&&}
)}:home.lantern?<>

One {title(home.lantern.motif)} lantern. Local preview only; not backed up or transferable.

Light’s origin{previewOrigin?<>

Mochi returned with the {home.lantern.motif==="moth"?"wind-moth":"Beacon Lens"}. {previewOrigin.commands.length} choices with the {title(previewOrigin.tool)}.

Static illustration of this device’s validated return, not a recorded screenshot or an accepted NEAR claim.

Content: {previewOrigin.contentVersion} · memory {previewOrigin.id}

:

The original return is unavailable. This device preview is not proof of an earned event.

}
{(["porch","dock"] as const).map(socket=>)}:canPreviewCrest?<>
{title(motif)} motif

The lens return earned a Crest. A rescued wind-moth earns its own motif.

Motif{(["crest","moth"] as const).map(m=>)}
:

Bring the Beacon Lens home first. A lantern should remember something you actually did.

}:null} {session?.state.message&&

{session.state.message}

}
} } diff --git a/web/src/expedition/harbor-controller.test.ts b/web/src/expedition/harbor-controller.test.ts index 52fec31..1a30f4c 100644 --- a/web/src/expedition/harbor-controller.test.ts +++ b/web/src/expedition/harbor-controller.test.ts @@ -4,6 +4,8 @@ import {createHash} from "node:crypto"; import {syntheticReturnLock} from "./return-record.fixture"; import fixtures from "../../../contracts/common/fixtures/court.json"; import {HarborController,canonicalWorkshop,type HarborConnection,type HarborClient} from "./harbor-controller"; +import {SeasonNotSent} from "./harbor-port"; +import {settleError} from "../season/model"; import {replayCourt} from "./engine"; import {returnRecordKey} from "./return-record"; import type {PlayerBinding} from "../tidebound/domain"; @@ -149,3 +151,35 @@ test("unpacking a historical return keeps its exact checkpoint, content and orig await f.controller.resumeOriginal();expect(f.resumes).toBe(1);expect(f.sent).toHaveLength(1); expect(f.controller.state.returns[0]!.operationId).toBe(record.operationId); }); +test("season actions send one exact allowlisted call to season. and return only that call's final outcome",async()=>{ + const f=fixture();await expect(f.controller.seasonAct({kind:"buy",good:"glass",qty:1,maxPrice:8})).rejects.toThrow();expect(f.sent).toEqual([]); + await saved(f); + const client=(f.controller as unknown as {connection:{client:HarborClient&{lastFinal:unknown}}}).connection.client; + const view=client.view.bind(client);let minimum="12500000000000000000000"; + let ledger:unknown=null; + client.view=(async(contract:string,method:string,args?:Record)=>method==="storage_minimum"?(expect(contract).toBe(`season.${root}`),minimum):method==="get_account"?(expect(args).toEqual({account_id:binding.nearAccountId}),ledger):view(contract,method,args)) as typeof client.view; + f.onSend=(method)=>{client.lastFinal={hash:"h",method,receiver:`season.${root}`,failed:method==="sell",outcome:{status:{SuccessValue:btoa("{}")}}};}; + expect(await f.controller.seasonAct({kind:"buy",good:"glass",qty:2,maxPrice:9})).toEqual({failed:false,outcome:{status:{SuccessValue:btoa("{}")}}}); + expect((await f.controller.seasonAct({kind:"sell",good:"reed",qty:1,minPrice:3}))?.failed).toBe(true); + await f.controller.seasonAct({kind:"claim",contentVersion:"first_light_v2",tool:"rope",commands:["return"]}); + await f.controller.seasonAct({kind:"set-wish",good:"reed",limit:6,qty:2}); + await f.controller.seasonAct({kind:"cancel-wish"}); + await f.controller.seasonAct({kind:"register"}); + const season={receiver:`season.${root}`,deposit:0n}; + expect(f.sent).toEqual([ + {method:"buy",args:{good:"glass",qty:2,max_price:9},options:season}, + {method:"sell",args:{good:"reed",qty:1,min_price:3},options:season}, + {method:"claim_daily",args:{rules_version:"tidebound_h1_v1",content_version:"first_light_v2",tool:"rope",area:"beacon",commands:["return"]},options:season}, + {method:"set_wish",args:{pet:`mochi.${root}`,good:"reed",limit:6,qty:2},options:season}, + {method:"cancel_wish",args:{pet:`mochi.${root}`},options:season}, + {method:"storage_deposit",args:{},options:{receiver:`season.${root}`,deposit:12500000000000000000000n}}, + ]); + minimum="1";await expect(f.controller.seasonAct({kind:"register"})).rejects.toThrow("page size");expect(f.sent.length).toBe(6); + minimum="12500000000000000000000";ledger={shells:0}; + const twice=await f.controller.seasonAct({kind:"register"}).catch(error=>error); + expect(twice).toBeInstanceOf(SeasonNotSent);expect(twice.message).toBe("Your ledger page is already open. Nothing was sent.");expect(f.sent.length).toBe(6); + f.snapshot.pets=[];await f.controller.refresh(); + const nopet=await f.controller.seasonAct({kind:"set-wish",good:"glass",limit:1,qty:1}).catch(error=>error); + expect(nopet).toBeInstanceOf(SeasonNotSent);expect(settleError(nopet)).toEqual({kind:"refused",code:"NOT_SENT",words:"Bring Mochi home before setting a wish."});expect(f.sent.length).toBe(6); + f.onSend=()=>{};expect(await f.controller.seasonAct({kind:"buy",good:"glass",qty:1,maxPrice:8})).toBeNull(); +}); diff --git a/web/src/expedition/harbor-controller.ts b/web/src/expedition/harbor-controller.ts index 027ba27..05c8735 100644 --- a/web/src/expedition/harbor-controller.ts +++ b/web/src/expedition/harbor-controller.ts @@ -4,10 +4,11 @@ import {RULES_VERSION,type PlayerBinding} from "../tidebound/domain"; import type {ChainSnapshot,TideboundClient} from "../tidebound/client"; import {quoteItemStorage,storageNear} from "../tidebound/storage"; import {ReturnRecords,validateRunContext,type ReturnRecord,type ReturnRecordLock} from "./return-record"; -import type {HarborSession,HarborState,HomeCheckpoint,RunContext,WorldIntent,WorldReview,WorkshopModel} from "./harbor-port"; +import {SeasonNotSent,type HarborSession,type HarborState,type HomeCheckpoint,type RunContext,type SeasonFinal,type SeasonIntent,type WorldIntent,type WorldReview,type WorkshopModel} from "./harbor-port"; +import {SEASON_STORAGE_DEPOSIT} from "../../../services/relayer/src/auth/sign"; import type {CourtState,BankedItem} from "./types"; -export type HarborClient=Pick; +export type HarborClient=Pick&{lastFinal?:TideboundClient["lastFinal"]}; export interface HarborConnection {adapter:RecoverableAccountAdapter;client:HarborClient;accountExists(accountId:string):Promise} type Prepared={review:WorldReview;epoch:number;binding:PlayerBinding;revision:number;checkpointHash:string;method:string;args:Record;options?:{receiver:string;deposit:bigint};record?:ReturnRecord}; const blankWorkshop:WorkshopModel={authority:"local-preview",motifs:[],creditAvailable:false,items:[],placement:null,shells:0,commissionAvailable:false}; @@ -76,9 +77,9 @@ export class HarborController implements HarborSession { async noteToken(){const adapter=this.connection?.adapter as {accessToken?():Promise}|undefined;return this.value.mode==="saved"&&this.value.binding&&adapter?.accessToken?adapter.accessToken():null;} async signOut(){this.guard(this.epoch);const epoch=++this.epoch;this.prepared=null;this.update({binding:null,snapshot:null,mode:"preview",review:null,busy:true,message:"Your device previews and original requests are preserved."});try{await this.connection?.adapter.endSession();}finally{if(this.live&&epoch===this.epoch)this.update({busy:false});}} async refresh(){const binding=this.value.binding;check(binding&&this.connection,"Sign in to check the saved harbor.");return this.work(()=>this.load(binding,this.epoch));} - private async work(task:()=>Promise) { + private async work(task:()=>Promise,report=true) { check(this.live&&!this.value.busy,"The original harbor action is still being checked.");const epoch=this.epoch;this.update({busy:true,message:""}); - try{await task();}catch(error){if(epoch===this.epoch)this.update({message:error instanceof Error?error.message:"The original request is still being checked."});throw error;} + try{await task();}catch(error){if(report&&epoch===this.epoch)this.update({message:error instanceof Error?error.message:"The original request is still being checked."});throw error;} finally{if(epoch===this.epoch)this.update({busy:false});} } async selectSaved(){check(!this.active,"Finish this outing before choosing another harbor.");await this.refresh();check(this.value.courtSupported,"The new court is a private preview until both contracts support it. Your existing Mochi and earned progress are preserved.");check(this.value.binding,"Sign in before selecting this harbor.");this.choice(this.value.binding,"saved");this.update({mode:"saved"});this.update({returns:this.recordsFor(this.value.snapshot)});} @@ -168,6 +169,36 @@ export class HarborController implements HarborSession { const hash=await claimHash(record);this.guard(epoch,binding);const claims=(this.value.snapshot?.journey as {claims?:{operation_id:string;input_hash:string;id:string}[]}|undefined)?.claims,accepted=claims?.find(c=>c.operation_id===record.operationId); check(accepted&&accepted.input_hash===hash,"The transaction finalized, but its accepted return still needs checking. Keep the original memory.");await this.records.mark(record.context,record.id,"accepted",accepted.id);this.guard(epoch,binding);this.update({returns:this.recordsFor(this.value.snapshot)}); } + /** Season 2: one typed call on season., sent through the same pending-action path. Returns the final outcome only. */ + async seasonAct(intent:SeasonIntent):Promise { + let final:SeasonFinal|null=null,sending=false; + try{await this.work(async()=>{ + const binding=this.requireSaved(),epoch=this.epoch,client=this.connection!.client,season=`season.${client.root}`; + let method:string,args:Record,deposit=0n; + switch(intent.kind){ + case "register": { + const minimum=await client.view(season,"storage_minimum");this.guard(epoch,binding); + check(BigInt(minimum)===SEASON_STORAGE_DEPOSIT,"Bram’s ledger changed its page size. Nothing was sent."); + // A second tab or a stale view must not pay the deposit twice: the contract would keep it as a top-up. + const existing=await client.view(season,"get_account",{account_id:binding.nearAccountId});this.guard(epoch,binding); + check(existing===null,"Your ledger page is already open. Nothing was sent."); + method="storage_deposit";args={};deposit=SEASON_STORAGE_DEPOSIT;break; + } + case "claim": method="claim_daily";args={rules_version:RULES_VERSION,content_version:intent.contentVersion,tool:intent.tool,area:"beacon",commands:[...intent.commands]};break; + case "buy": method="buy";args={good:intent.good,qty:intent.qty,max_price:intent.maxPrice};break; + case "sell": method="sell";args={good:intent.good,qty:intent.qty,min_price:intent.minPrice};break; + case "set-wish": case "cancel-wish": { + const pet=this.value.snapshot?.pets[0]?.token_id;check(pet,"Bring Mochi home before setting a wish."); + method=intent.kind==="set-wish"?"set_wish":"cancel_wish";args=intent.kind==="set-wish"?{pet,good:intent.good,limit:intent.limit,qty:intent.qty}:{pet};break; + } + } + this.guard(epoch,binding);client.lastFinal=null;sending=true; + await client.send(binding,method,args,{receiver:season,deposit});this.guard(epoch,binding); + const last=client.lastFinal as TideboundClient["lastFinal"]|undefined; + final=last&&last.method===method&&last.receiver===season?{failed:last.failed,outcome:last.outcome}:null; + },false);}catch(error){if(!sending)throw new SeasonNotSent(error instanceof Error?error.message:"Nothing was sent.");throw error;} + return final; + } private async original(kind:"resume"|"check"|"expiry") {return this.work(async()=>{ const binding=this.value.binding,epoch=this.epoch;check(binding&&this.connection,"Sign in with the original identity to check this request."); const result=kind==="resume"?await this.connection.client.resumeNative(binding):kind==="check"?await this.connection.client.reconcileNative(binding):await this.connection.client.resolveExpiredNative(binding); diff --git a/web/src/expedition/harbor-port.ts b/web/src/expedition/harbor-port.ts index bbde6de..be68d00 100644 --- a/web/src/expedition/harbor-port.ts +++ b/web/src/expedition/harbor-port.ts @@ -18,6 +18,17 @@ export type WorldIntent = | {kind:"polish";itemId:string} | {kind:"gift";itemId:string;recipient:string} | {kind:"storage";recipient:string}; +/** Season 2 calls on season.. Each maps to exactly one allowlisted method. */ +export type SeasonIntent = + | {kind:"register"} + | {kind:"claim";contentVersion:"first_light_v1"|"first_light_v2";tool:"rope"|"lantern";commands:readonly string[]} + | {kind:"buy";good:"glass"|"reed";qty:number;maxPrice:number} + | {kind:"sell";good:"glass"|"reed";qty:number;minPrice:number} + | {kind:"set-wish";good:"glass"|"reed";limit:number;qty:number} + | {kind:"cancel-wish"}; +export interface SeasonFinal {failed:boolean;outcome:unknown} +/** Thrown by a season action that stopped before anything was handed to the signer. Its message is player-facing. */ +export class SeasonNotSent extends Error { override name="SeasonNotSent"; } export interface WorldReview {id:string;intent:WorldIntent;title:string;description:string;costs:readonly string[];confirmLabel:string} export interface WorkshopModel { authority:"local-preview"|"near-testnet";motifs:readonly MotifId[];creditAvailable:boolean; @@ -34,6 +45,7 @@ export interface HarborSession { captureReturn(state:CourtState,context:RunContext):Promise; selectSaved():Promise;selectPreview():void; review(intent:WorldIntent):Promise;confirm(reviewId:string):Promise;cancelReview():void; + seasonAct?(intent:SeasonIntent):Promise; refresh():Promise;resumeOriginal():Promise;checkOriginal():Promise;resolveExpired():Promise; /** Short-lived session proof for the sealed-note relay; absent when the account provider cannot supply one. */ noteToken?():Promise; diff --git a/web/src/expedition/records.ts b/web/src/expedition/records.ts index 2a5e09b..93ce531 100644 --- a/web/src/expedition/records.ts +++ b/web/src/expedition/records.ts @@ -5,7 +5,7 @@ export interface HarborRecord {kind:"self"|"key"|"referee"|"admin";title:string; export interface RecordsTarget {rpcUrl:string;root:string;player:string;pet:string;signerKey:string;provider:"privy"|"other"} /** Mirrors validateNativeIntent in services/relayer/src/auth/sign.ts; records.test.ts keeps the two in step. */ -export const SIGNER_ACTIONS:readonly {receiver:"root"|"items"|"self";method:string;label:string}[]=[ +export const SIGNER_ACTIONS:readonly {receiver:"root"|"items"|"season"|"self";method:string;label:string}[]=[ {receiver:"root",method:"adopt",label:"bring Mochi home"}, {receiver:"root",method:"tidebound_claim",label:"record a return"}, {receiver:"root",method:"tidebound_restore",label:"restore the beacon or signal"}, @@ -18,6 +18,12 @@ export const SIGNER_ACTIONS:readonly {receiver:"root"|"items"|"self";method:stri {receiver:"root",method:"tidebound_retry_operation",label:"retry an original request"}, {receiver:"items",method:"mt_transfer",label:"gift a lantern"}, {receiver:"items",method:"storage_deposit",label:"cover a lantern’s storage"}, + {receiver:"season",method:"storage_deposit",label:"open your page in Bram’s ledger"}, + {receiver:"season",method:"claim_daily",label:"dock today’s haul"}, + {receiver:"season",method:"buy",label:"buy from Bram’s shelf"}, + {receiver:"season",method:"sell",label:"sell to Bram’s till"}, + {receiver:"season",method:"set_wish",label:"set Mochi’s wish"}, + {receiver:"season",method:"cancel_wish",label:"take back Mochi’s wish"}, {receiver:"self",method:"transfer",label:"a zero-value transfer to your own account"}, ]; diff --git a/web/src/main.tsx b/web/src/main.tsx index c7e1f94..17e45ce 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -11,6 +11,7 @@ async function entry() { const path = window.location.pathname.replace(/\/index\.html$/, "").replace(/\/$/, ""); if (path === "" || path === "/plan" || path.startsWith("/plan/")) return (await import("./landing/Landing")).Landing; if (import.meta.env.DEV && new URLSearchParams(window.location.search).has("storyboard")) return (await import("./opening/Storyboard")).default; + if (import.meta.env.DEV && new URLSearchParams(window.location.search).has("season-harness")) return (await import("./season/Harness")).default; const game=Promise.all([import("./expedition/Game"),import("./expedition/harbor-session")]); // `?play` skips the title screen (browser tests and direct links into play). if(new URLSearchParams(window.location.search).has("play")){ diff --git a/web/src/season/Harness.tsx b/web/src/season/Harness.tsx new file mode 100644 index 0000000..cd4afcb --- /dev/null +++ b/web/src/season/Harness.tsx @@ -0,0 +1,46 @@ +/** + * Development-only check of the signed-in Season 2 panel (`/outing/?season-harness`, dev server only). + * get_shelf and get_today are read live; this harness account's ledger, wish and postcard are + * mocked, and signing is mocked: nothing is signed or sent. The page says so on screen. + */ +import { useState } from "react"; +import SeasonBram from "./SeasonBram"; +import type { HarborSession, SeasonIntent } from "../expedition/harbor-port"; +import type { Postcard, SeasonAccount, Trade, Wish } from "./model"; +import "../expedition/game.css"; + +const account="harness.familiar-game.testnet",pet="mochi-harness.familiar-game.testnet"; +let ledger:SeasonAccount|null=null,wish:Wish|null=null,postcard:Postcard|null=null; +const mocked:Recordunknown>={get_account:()=>ledger,get_wish:()=>wish,get_postcard:()=>postcard}; +const realFetch=globalThis.fetch.bind(globalThis); +globalThis.fetch=(async(input:RequestInfo|URL,init?:RequestInit)=>{ + try{const body=JSON.parse(String(init?.body??"{}")),method=body?.params?.method_name as string; + if(method in mocked){const bytes=[...new TextEncoder().encode(JSON.stringify(mocked[method]!()))];return new Response(JSON.stringify({result:{result:bytes}}));}}catch{/* not a season view */} + return realFetch(input,init); +}) as typeof fetch; +const ok=(value:unknown)=>({failed:false,outcome:{status:{SuccessValue:btoa(JSON.stringify(value))}}}); +async function seasonAct(intent:SeasonIntent) { + await new Promise(r=>setTimeout(r,900)); + switch(intent.kind){ + case "register":ledger={shells:30,goods:[1,1],trade_day:0,traded:[0,0],last_mint:null};return ok({total:"12500000000000000000000",available:"0"}); + case "buy":return {failed:true,outcome:{status:{Failure:{ActionError:{kind:{FunctionCallError:{ExecutionError:"Smart contract panicked: ERR_MAX_PRICE"}}}}}}}; + case "sell":{const trade:Trade={seq:1,side:"sell",good:intent.good,qty:intent.qty,unit_prices:Array(intent.qty).fill(intent.minPrice),total:intent.minPrice*intent.qty,fills:[]}; + if(ledger){ledger.goods[intent.good==="glass"?0:1]-=intent.qty;ledger.shells+=trade.total;}return ok(trade);} + case "set-wish":wish={pet,owner:account,good:intent.good,limit:intent.limit,qty:intent.qty,purse:intent.limit*intent.qty,seq:1,day:0};if(ledger)ledger.shells-=wish.purse;return ok({status:"waiting",reason:"WAITING",wish,postcard:null}); + case "cancel-wish":{if(!wish)return null;postcard={pet,owner:account,good:wish.good,qty:wish.qty,limit:wish.limit,outcome:"cancelled",reason:"CANCELLED_BY_OWNER",unit_prices:[],paid:0,refunded:wish.purse,trigger:null,day:0};if(ledger)ledger.shells+=wish.purse;wish=null;return ok(postcard);} + case "claim":return ok({day:0,content_version:intent.contentVersion,tool:intent.tool,goods:[1,1],value_fp:12_000_000,best_fp:12_000_000,score_bp:10_000}); + } +} +const session={state:{mode:"saved",busy:false,snapshot:{binding:{nearAccountId:account},pets:[{token_id:pet}]}},seasonAct} as unknown as HarborSession; + +export default function SeasonHarness() { + const [sailed,setSailed]=useState(""); + return
+
+

Development harness. Shelf and today’s tide are read live; this account’s ledger, wish and signing are mocked. Nothing is signed or sent.

+

“You’re back.”

+ setSailed(`Would sail with the ${t}.`)} tideScope="harness"/> + {sailed&&

{sailed}

} +
+
; +} diff --git a/web/src/season/SeasonBram.tsx b/web/src/season/SeasonBram.tsx new file mode 100644 index 0000000..d5e105e --- /dev/null +++ b/web/src/season/SeasonBram.tsx @@ -0,0 +1,227 @@ +import { useCallback, useEffect, useRef, useState, type KeyboardEvent, type ReactNode } from "react"; +import type { HarborSession, SeasonIntent } from "../expedition/harbor-port"; +import { GOODS, type Good } from "./pricing"; +import { + GOOD_INDEX, PURSE_MAX, WISH_QTY_MAX, bestHaulLine, claimable, goodName, haulLine, postcardLines, quoteBuy, quoteLine, quoteSell, reasonLine, scoreLine, + OPEN_REQUEST, settle, settleError, tradeArgs, tradeBlock, wishBlock, wishStatus, + type ActionState, type Mint, type Postcard, type SeasonAccount, type ShelfView, type TodayView, type Trade, type Wish, type WishResult, +} from "./model"; +import { PREVIEW_SAMPLE, previewTrade, rollPreview, previewView, readPreview, readTide, seasonView, seedPreview, writePreview, type PreviewMarket, type TideReturn } from "./data"; +import "./season.css"; + +const ART = "/assets/season/"; +const STORAGE_NEAR = "0.0125"; +type Tab = "shelf" | "tide" | "wish"; +const TABS: [Tab, string][] = [["shelf","Shelf & till"],["tide","Today’s tide"],["wish","Mochi’s wish"]]; + +interface Live { shelf:ShelfView|null;today:TodayView|null;account:SeasonAccount|null|undefined;wish:Wish|null;postcard:Postcard|null;error:string } +const empty:Live = { shelf:null,today:null,account:undefined,wish:null,postcard:null,error:"" }; + +function useSeason(accountId:string|null, pet:string|null) { + const [live,setLive]=useState(empty),[loading,setLoading]=useState(true),request=useRef(0); + const refresh=useCallback(async()=>{ + const id=++request.current;setLoading(true); + try{ + const [shelf,today,account,wish,postcard]=await Promise.all([ + seasonView("get_shelf"), + seasonView("get_today",{account_id:accountId}), + accountId?seasonView("get_account",{account_id:accountId}):Promise.resolve(undefined), + pet?seasonView("get_wish",{pet}):Promise.resolve(null), + pet?seasonView("get_postcard",{pet}):Promise.resolve(null), + ]); + if(id===request.current)setLive({shelf,today,account,wish,postcard,error:""}); + }catch(error){if(id===request.current)setLive(l=>({...l,error:error instanceof Error?error.message:"Bram’s shelf could not be read just now."}));} + finally{if(id===request.current)setLoading(false);} + },[accountId,pet]); + useEffect(()=>{void refresh();},[refresh]); + return {live,loading,refresh}; +} + +const Status=({state,confirmed,ref}:{state:ActionState;confirmed:string;ref:React.Ref})=>{ + const text=state.kind==="pending"?state.label:state.kind==="confirmed"?confirmed:state.kind==="refused"||state.kind==="uncertain"?state.words:""; + return

{text}

; +}; +/** + * A button that stays focusable while unavailable (aria-disabled), so a press that makes it + * unavailable never drops keyboard focus out of the panel. + */ +function Press({off,onPress,children,className,describedBy,label}:{off:boolean;onPress:()=>void;children:ReactNode;className?:string;describedBy?:string;label?:string}) { + return ; +} + +export interface SeasonBramProps { session?:HarborSession;tool:"rope"|"lantern";canSail:boolean;onSailTide:(tool:"rope"|"lantern")=>void;tideScope:string } + +export default function SeasonBram({session,tool,canSail,onSailTide,tideScope}:SeasonBramProps) { + const saved=session?.state.mode==="saved"&&!!session.state.snapshot&&!!session.seasonAct; + const accountId=saved?session!.state.snapshot!.binding.nearAccountId:null,pet=saved?session!.state.snapshot!.pets[0]?.token_id??null:null; + const {live,loading,refresh}=useSeason(accountId,pet); + const [tab,setTab]=useState("shelf"); + const tabRefs=useRef<(HTMLButtonElement|null)[]>([]); + const [action,setAction]=useState>({kind:"idle"}),[confirmedText,setConfirmedText]=useState(""); + const [storedPreview,setPreview]=useState(()=>readPreview()); + const preview=storedPreview&&rollPreview(storedPreview); + useEffect(()=>{if(!saved&&!preview&&live.shelf){const seeded=seedPreview(live.shelf);setPreview(seeded);writePreview(seeded);}},[saved,preview,live.shelf]); + const openRequest=saved&&!!session?.state.pending; + const busy=action.kind==="pending"||!!session?.state.busy||openRequest; + const rootRef=useRef(null),statusRef=useRef(null); + + async function act(intent:SeasonIntent,label:string,done:(value:T)=>string) { + if(!session?.seasonAct||busy)return; + setAction({kind:"pending",label});setConfirmedText(""); + let next:ActionState; + try{next=settle(await session.seasonAct(intent));}catch(error){next=settleError(error);} + if(next.kind==="confirmed")setConfirmedText(done(next.value)); + setAction(next);await refresh(); + // A control that pressed this may be gone now (the ledger offer, a taken-back wish); keep focus in the panel. + requestAnimationFrame(()=>{if(!rootRef.current?.contains(document.activeElement))statusRef.current?.focus();}); + } + function keyTabs(event:KeyboardEvent) { + const i=TABS.findIndex(([t])=>t===tab),step=event.key==="ArrowRight"?1:event.key==="ArrowLeft"?-1:0; + if(!step)return;event.preventDefault();const n=(i+step+TABS.length)%TABS.length;setTab(TABS[n]![0]);tabRefs.current[n]?.focus(); + } + + const registered=saved&&live.account!==undefined&&live.account!==null; + const needsLedger=saved&&live.account===null; + const holdings=saved?live.account:preview?{shells:preview.shells,goods:preview.goods,traded:preview.traded}:null; + + return
+
+ +
+

Bram’s shelf

+

{saved?`Season ledger for ${accountId}`:"Device preview. Prices follow Bram’s formula on this device; nothing here is recorded."}

+
+
+ {holdings&&

{holdings.shells} Shells{holdings.goods[0]} glass{holdings.goods[1]} reed{!saved&&Sample haul of {haulLine(PREVIEW_SAMPLE)} for the preview}

} + {live.error&&

{live.error}

} + {needsLedger&&
+

Bram keeps a ledger page for each harbor. Open yours before your first trade, tide or wish.

+
void act({kind:"register"},"Bram is writing your page…",()=>"Your ledger page is open. Recorded.")}>Open my ledger pageHolds {STORAGE_NEAR} test NEAR as its storage deposit
+
} +
+ {TABS.map(([id,label],i)=>)} +
+ {openRequest&&action.kind!=="pending"&&

{OPEN_REQUEST}

} + +
+ {tab==="shelf"&&{setPreview(next);writePreview(next);setAction({kind:"confirmed",value:null});setConfirmedText(text);}} + onPreviewBlock={words=>setAction({kind:"refused",code:"PREVIEW",words})} + onResetPreview={()=>{const seeded=seedPreview(live.shelf);setPreview(seeded);writePreview(seeded);setAction({kind:"idle"});}} + act={act}/>} + {tab==="tide"&&} + {tab==="wish"&&} +
+
; +} + +type Act=(intent:SeasonIntent,label:string,done:(value:T)=>string)=>Promise; +const tradeText=(t:Trade)=>`${t.side==="buy"?"Bought":"Sold"} ${t.qty} ${goodName(t.good,t.qty)} for ${t.unit_prices.join(" + ")}${t.qty>1?` = ${t.total}`:""} Shells. Recorded.${t.fills.length?` Bram’s trade also filled ${t.fills.length} waiting wish${t.fills.length>1?"es":""}.`:""}`; + +function Stepper({value,min,max,onChange,label}:{value:number;min:number;max:number;onChange:(n:number)=>void;label:string}) { + return
+ onChange(value-1)}>− + {value} + =max} onPress={()=>onChange(value+1)}>+ +
; +} + +function Shelf({live,saved,registered,busy,preview,onPreview,onPreviewBlock,onResetPreview,act}:{live:Live;saved:boolean;registered:boolean;busy:boolean;preview:PreviewMarket|null; + onPreview:(m:PreviewMarket,text:string)=>void;onPreviewBlock:(words:string)=>void;onResetPreview:()=>void;act:Act}) { + const [qty,setQty]=useState>({glass:1,reed:1}); + const till=saved?live.shelf?.till:preview?.till; + if(!live.shelf&&!preview)return

Reading Bram’s shelf…

; + return <> +

Till {till??"…"} Shells{live.shelf?` · tops up by ${live.shelf.till_refill} each morning to ${live.shelf.till_cap}`:""}

+ {GOODS.map(good=>{ + const i=GOOD_INDEX[good]; + const view=saved?live.shelf?.goods.find(g=>g.good===good):preview?previewView(preview,good):undefined; + if(!view)return null; + const n=qty[good],shelfState={stock:view.stock,heat_fp:view.heat_fp}; + const buy=quoteBuy(good,shelfState,n),sell=quoteSell(good,shelfState,n); + const ctx=saved?{shells:live.account?.shells??0,held:live.account?.goods[i]??0,till:live.shelf?.till??0,tradedToday:live.today?.traded_today?.[i]??0} + :{shells:preview!.shells,held:preview!.goods[i]!,till:preview!.till,tradedToday:preview!.traded[i]!}; + const buyBlock=tradeBlock(buy,ctx),sellBlock=tradeBlock(sell,ctx),locked=busy||(saved&&!registered); + function trade(side:"buy"|"sell") { + const quote=side==="buy"?buy:sell;if(!quote)return; + if(!saved){const r=previewTrade(preview!,side,good,n);if("block"in r)onPreviewBlock(r.block);else onPreview(r.market,`Preview: ${side==="buy"?"bought":"sold"} ${n} ${goodName(good,n)} for ${quoteLine(r.quote)}. Not recorded.`);return;} + const args=tradeArgs(quote); + void act(side==="buy"?{kind:"buy",good,qty:n,maxPrice:(args as {max_price:number}).max_price}:{kind:"sell",good,qty:n,minPrice:(args as {min_price:number}).min_price}, + side==="buy"?"Bram is wrapping your goods…":"Bram is counting out Shells…",tradeText); + } + return
+ +
+

{good==="glass"?"Sea glass":"Reed bundles"} {view.stock} on the shelf

+
Bram sells at
{view.buy_price}
Bram pays
{view.sell_price}
+

{reasonLine({...view,buy_price:view.buy_price},till??0)}

+
+ setQty(q=>({...q,[good]:v}))}/> +
trade("buy")}>Buy {n}{buyBlock??`costs ${buy?quoteLine(buy):"…"}`}
+
trade("sell")}>Sell {n}{sellBlock??`pays ${quoteLine(sell)}`}
+
+
+
; + })} +

{saved?"Each trade is priced unit by unit and refused if any unit moves past the quote shown.":"Prices here use the same formula as Bram’s ledger, starting from the shelf as last read."}

+ {!saved&&} + ; +} + +function Tide({live,saved,registered,busy,tool,canSail,onSail,scope,act}:{live:Live;saved:boolean;registered:boolean;busy:boolean;tool:"rope"|"lantern";canSail:boolean;onSail:(tool:"rope"|"lantern")=>void;scope:string;act:Act}) { + const today=live.today,[choice,setChoice]=useState(tool); + const [returns]=useState(()=>scope==="preview"?readTide(scope):[...readTide(scope),...readTide("preview")]); + if(!today)return

Reading today’s tide…

; + const sailable=today.content_version==="first_light_v2"; + const minted=saved?today.minted_today:null; + const candidates=returns.map(r=>({r,c:claimable(today,{tool:r.tool,commands:r.commands,contentVersion:r.contentVersion})})).filter(x=>x.c); + const mapping=today.mapping.map(([item,good])=>`${item} → ${good??"nothing"}`).join(" · "); + return <> +

{sailable?"Beacon Court":"The old First Light route"}

+

Every day’s tide is a fresh outing from the beacon with nothing banked. The first haul you dock each day becomes goods.

+
Cargo to goods
{mapping}
Best haul
{bestHaulLine(today)}
+ {saved&&

{minted?<>Docked today with {haulLine(minted.goods)}: {scoreLine(minted)}.:"Not docked yet today."}

} + {!sailable&&

This route belongs to the first edition, and the harbor only sails Beacon Court now, so today’s tide cannot be sailed or docked from here. Beacon Court comes back with the next day’s tide.

} + {sailable&&!minted&&
Bring one tool + {(["rope","lantern"] as const).map(t=>)} + onSail(choice)}>Sail today’s tide +

Your harbor’s own finds stay as they are. This outing’s haul is kept here for docking.

+
} + {candidates.length>0&&!minted&&
+

Ready to dock

+ {candidates.map(({r,c})=>
+ void act({kind:"claim",contentVersion:r.contentVersion,tool:r.tool,commands:r.commands},"The harbor is replaying Mochi’s steps…",m=>`Docked ${haulLine(m.goods)}: ${scoreLine(m)}. Recorded.`)}>Dock this haul + {r.tool==="rope"?"Rope":"Lantern"} outing · {haulLine(c!.goods)} +
)} + {!saved&&

Docking a haul needs your saved harbor. Sign in from the menu.

} +
} + {!candidates.length&&returns.length>0&&!minted&&

The tide returns kept here would not dock today: they are from the other route, came home empty, or did not reach the dock.

} + ; +} + +function WishTab({live,saved,registered,hasPet,busy,act}:{live:Live;saved:boolean;registered:boolean;hasPet:boolean;busy:boolean;act:Act}) { + const [good,setGood]=useState("glass"),[qty,setQty]=useState(1),[limit,setLimit]=useState(8); + const status=wishStatus(live.wish,live.postcard); + const shells=live.account?.shells??0,maxLimit=Math.floor(PURSE_MAX/qty),block=wishBlock(limit,qty,shells); + const card=status.kind==="filled"||status.kind==="cancelled"?status.card:live.postcard; + return <> +
+

{status.kind==="waiting"?<>Mochi is waiting for {status.wish.qty} {goodName(status.wish.good,status.wish.qty)} at up to {status.wish.limit} Shells each. Her purse holds {status.wish.purse} Shells. + :status.kind==="filled"?"Mochi’s last wish was filled. Her postcard is below.":status.kind==="cancelled"?"Mochi’s last wish was taken back. Her postcard is below.":"Mochi has no wish waiting. She can hold up to 24 Shells in her purse for one."}

+
+ {!saved?

Mochi’s wish lives in your saved harbor. Sign in from the menu to set one.

:!hasPet?

Bring Mochi home in your saved harbor before setting a wish.

:<> + {status.kind==="waiting"&&
void act({kind:"cancel-wish"},"Taking the wish back…",c=>`Wish taken back; ${c.refunded} Shells returned. Recorded.`)}>Take the wish backReturns {status.wish.purse} Shells
} +
+ {status.kind==="waiting"?"Replace the wish":"Set a wish"} + Good
{GOODS.map(g=>)}
+ How many
{Array.from({length:WISH_QTY_MAX},(_,i)=>i+1).map(q=>)}
+
Highest price per unit
+
void act({kind:"set-wish",good,limit,qty},"Bram is checking Mochi’s papers…", + r=>r.status==="filled"?`Filled at once: ${r.postcard?postcardLines(r.postcard)[1]:""} Recorded.`:r.status==="waiting"?`Mochi’s wish is waiting. Her purse holds ${r.wish?.purse??limit*qty} Shells. Recorded.`:"Recorded.")}>Set Mochi’s wish + {block??`Purse ${limit*qty} of ${PURSE_MAX} Shells${status.kind==="waiting"?"; the old purse comes back once the new wish is placed":""}`}
+ {live.shelf&&

Bram sells {goodName(good,2)} at {live.shelf.goods.find(g=>g.good===good)?.buy_price} now. A wish whose limit covers every unit fills at once; otherwise a later trade that brings the price within it does.

} +
+ } + {card&&
{postcardLines(card).map(line=>

{line}

)}
} + ; +} diff --git a/web/src/season/data.test.ts b/web/src/season/data.test.ts new file mode 100644 index 0000000..03578fc --- /dev/null +++ b/web/src/season/data.test.ts @@ -0,0 +1,51 @@ +import { expect, test } from "bun:test"; +import { keepTide, previewTrade, readPreview, readTide, rollPreview, seasonView, seedPreview, writePreview, type TideReturn } from "./data"; + +const memory=()=>{const m=new Map();return {getItem:(k:string)=>m.get(k)??null,setItem:(k:string,v:string)=>{m.set(k,v);}};}; + +test("the device preview prices like the contract and refuses what the contract refuses", () => { + const m=seedPreview(null); + expect(m).toMatchObject({till:300,shells:0,goods:[1,2]}); + expect(previewTrade(m,"buy","glass",1)).toEqual({block:"Not enough Shells for that."}); + const sold=previewTrade(m,"sell","reed",2);if("block"in sold)throw Error(sold.block); + expect(sold.quote.units).toEqual([3,3]); + expect(sold.market).toMatchObject({shells:6,goods:[1,0],till:294,traded:[0,2]}); + expect(sold.market.shelf[1]).toEqual({stock:42,heat_fp:0}); + const bought=previewTrade(sold.market,"buy","reed",1);if("block"in bought)throw Error(bought.block); + expect(bought.market.shelf[1]).toEqual({stock:41,heat_fp:1_000_000}); + expect(bought.market.shells).toBe(6-bought.quote.total); + expect(previewTrade(m,"sell","glass",2)).toEqual({block:"Not enough in your satchel."}); + expect(previewTrade({...m,traded:[20,0]},"sell","glass",1)).toEqual({block:"Bram trades 20 of each good with you a day."}); + const store=memory();writePreview(sold.market,store);expect(readPreview(store)).toEqual(sold.market); + store.setItem("familiar.season.preview.v1",'{"version":1,"shelf":[]}');expect(readPreview(store)).toBeNull(); +}); + +test("the device preview rolls over each day like the contract: heat halves, till refills, limits reset", () => { + const m={...seedPreview(null,100),till:200,traded:[20,3] as [number,number],shelf:[{stock:30,heat_fp:8_000_000},{stock:40,heat_fp:1}]}; + expect(rollPreview(m,100)).toBe(m); + expect(rollPreview(m,101)).toMatchObject({day:101,till:260,traded:[0,0],shelf:[{stock:30,heat_fp:4_000_000},{stock:40,heat_fp:0}]}); + expect(rollPreview(m,103)).toMatchObject({till:300,shelf:[{heat_fp:1_000_000},{heat_fp:0}]}); + expect(rollPreview({...m,till:340},101).till).toBe(340); + expect(rollPreview(m,100+64).shelf[0]!.heat_fp).toBe(0); + expect(previewTrade(m,"sell","glass",1,100)).toEqual({block:"Bram trades 20 of each good with you a day."}); + expect("market"in previewTrade(m,"sell","glass",1,101)).toBe(true); + const store=memory();writePreview(m,store);expect(readPreview(store,102)).toMatchObject({day:102,traded:[0,0],till:300}); + const old=memory();const {day:_,...legacy}=m;old.setItem("familiar.season.preview.v1",JSON.stringify(legacy));expect(readPreview(old,105)?.day).toBe(105); +}); + +test("tide returns are kept per harbor, newest first, ten at most", () => { + const store=memory(); + const entry=(id:string):TideReturn=>({id,contentVersion:"first_light_v2",tool:"rope",commands:["return"],cargo:[],outcome:"returned",savedAt:"t"}); + for(let i=0;i<12;i++)keepTide("preview",entry(String(i)),store); + const kept=readTide("preview",store);expect(kept.map(r=>r.id)).toEqual(["11","10","9","8","7","6","5","4","3","2"]); + expect(readTide("alice.familiar-game.testnet",store)).toEqual([]); +}); + +test("views read final state from season. and decode the result bytes", async () => { + let body:Record={}; + const fetcher=(async(_url:string,init:RequestInit)=>{body=JSON.parse(String(init.body));return new Response(JSON.stringify({result:{result:[...new TextEncoder().encode('{"day":1}')]}}));}) as unknown as typeof fetch; + expect(await seasonView<{day:number}>("get_today",{account_id:null},fetcher)).toEqual({day:1}); + expect(body).toMatchObject({method:"query",params:{request_type:"call_function",finality:"final",account_id:"season.familiar-game.testnet",method_name:"get_today"}}); + const failing=(async()=>new Response(JSON.stringify({error:{}}))) as unknown as typeof fetch; + await expect(seasonView("get_shelf",{},failing)).rejects.toThrow("could not be read"); +}); diff --git a/web/src/season/data.ts b/web/src/season/data.ts new file mode 100644 index 0000000..e18001b --- /dev/null +++ b/web/src/season/data.ts @@ -0,0 +1,72 @@ +/** Season 2 reads (public RPC, finality final), the signed-out device preview and today's tide returns. */ +import { GOODS, type Good } from "./pricing"; +import { quoteBuy, quoteSell, tradeBlock, type GoodView, type Quote, type SeasonAccount, type ShelfView } from "./model"; + +export const SEASON_ROOT = import.meta.env.VITE_NEAR_ROOT || "familiar-game.testnet"; +export const SEASON_CONTRACT = `season.${SEASON_ROOT}`; +const RPC = import.meta.env.VITE_NEAR_RPC_URL || "https://test.rpc.fastnear.com"; + +export async function seasonView(method:string, args:Record={}, fetcher:typeof fetch=fetch):Promise { + const response=await fetcher(RPC,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:"season",method:"query", + params:{request_type:"call_function",finality:"final",account_id:SEASON_CONTRACT,method_name:method,args_base64:btoa(JSON.stringify(args))}})}); + const body=await response.json() as {result?:{result?:number[]};error?:unknown}; + if(!response.ok||!body.result?.result)throw Error("Bram’s shelf could not be read just now."); + return JSON.parse(new TextDecoder().decode(Uint8Array.from(body.result.result))) as T; +} + +// ---------- device preview ---------- + +export interface PreviewMarket { version:1;day:number;shelf:{stock:number;heat_fp:number}[];till:number;shells:number;goods:[number,number];traded:[number,number] } +/** The device's day, on the contract's boundary (floor of UTC time / 24 h). */ +export const deviceDay=(now=Date.now())=>Math.floor(now/86_400_000); +const TILL_CAP=300,TILL_REFILL=60,HEAT_HALVINGS_CAP=64; +/** The contract's lazy day effects: heat halves per day, the till refills toward its cap, daily limits reset. */ +export function rollPreview(m:PreviewMarket,day=deviceDay()):PreviewMarket { + const days=day-m.day;if(days<=0)return m; + return {...m,day,traded:[0,0], + shelf:m.shelf.map(s=>({stock:s.stock,heat_fp:days>=HEAT_HALVINGS_CAP?0:Number(BigInt(s.heat_fp)>>BigInt(days))})), + till:m.till{const v=shelf?.goods.find(x=>x.good===g);return {stock:v?.stock??40,heat_fp:v?.heat_fp??0};}),till:shelf?.till??300,shells:0,goods:[...PREVIEW_SAMPLE],traded:[0,0]}; +} +export function readPreview(store:Pick=localStorage,day=deviceDay()):PreviewMarket|null { + try{const v=JSON.parse(store.getItem(PREVIEW_KEY)??"null") as PreviewMarket; + const n=(x:unknown)=>Number.isSafeInteger(x)&&(x as number)>=0; + if(v?.version!==1||v.shelf?.length!==2||!v.shelf.every(s=>n(s.stock)&&n(s.heat_fp))||![v.till,v.shells,...v.goods,...v.traded].every(n))return null; + return rollPreview({...v,day:n(v.day)?v.day:day},day);}catch{return null;} +} +export function writePreview(value:PreviewMarket,store:Pick=localStorage){try{store.setItem(PREVIEW_KEY,JSON.stringify(value));}catch{/* The preview keeps running in memory. */}} +export const previewView=(m:PreviewMarket,good:Good):Pick=>{ + const i=GOODS.indexOf(good),s=m.shelf[i]!; + return {good,stock:s.stock,heat_fp:s.heat_fp,target:40,base:good==="glass"?8:4,buy_price:quoteBuy(good,s,1)?.units[0]??0,sell_price:quoteSell(good,s,1).units[0]!}; +}; +/** Applies a trade to the preview with the same unit-by-unit pricing and checks as the contract. */ +export function previewTrade(current:PreviewMarket,side:"buy"|"sell",good:Good,qty:number,day=deviceDay()):{market:PreviewMarket;quote:Quote}|{block:string} { + const m=rollPreview(current,day),i=GOODS.indexOf(good),shelf=m.shelf[i]!; + const quote=side==="buy"?quoteBuy(good,shelf,qty):quoteSell(good,shelf,qty); + const block=tradeBlock(quote,{shells:m.shells,held:m.goods[i]!,till:m.till,tradedToday:m.traded[i]!}); + if(block||!quote)return {block:block??"Bram’s shelf does not have that many."}; + const next=structuredClone(m),s=next.shelf[i]!; + if(side==="buy"){s.stock-=qty;s.heat_fp+=qty*1_000_000;next.shells-=quote.total;next.goods[i]!+=qty;next.till+=quote.total;} + else{s.stock+=qty;next.goods[i]!-=qty;next.shells+=quote.total;next.till-=quote.total;} + next.traded[i]!+=qty; + return {market:next,quote}; +} +export const previewAccount=(m:PreviewMarket):Pick=>({shells:m.shells,goods:m.goods,traded:m.traded}); + +// ---------- today's tide returns ---------- + +export interface TideReturn { id:string;contentVersion:"first_light_v2";tool:"rope"|"lantern";commands:string[];cargo:string[];outcome:"returned"|"rescued";savedAt:string } +const tideKey=(scope:string)=>`familiar.season.tide.v1:${scope}`; +export function readTide(scope:string,store:Pick=localStorage):TideReturn[] { + try{const v=JSON.parse(store.getItem(tideKey(scope))??"[]");return Array.isArray(v)?v.filter(r=>r&&typeof r.id==="string"&&Array.isArray(r.commands)&&r.commands.every((c:unknown)=>typeof c==="string")&&(r.tool==="rope"||r.tool==="lantern")):[];}catch{return [];} +} +/** Keeps the latest ten tide returns for this harbor; the oldest drop off first. */ +export function keepTide(scope:string,entry:TideReturn,store:Pick=localStorage) { + const next=[entry,...readTide(scope,store).filter(r=>r.id!==entry.id)].slice(0,10),text=JSON.stringify(next); + store.setItem(tideKey(scope),text);if(store.getItem(tideKey(scope))!==text)throw Error("Today’s tide return could not be saved on this device."); +} diff --git a/web/src/season/model.test.ts b/web/src/season/model.test.ts new file mode 100644 index 0000000..6f19402 --- /dev/null +++ b/web/src/season/model.test.ts @@ -0,0 +1,118 @@ +import { expect, test } from "bun:test"; +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { REFUSALS, claimable, postcardLines, quoteBuy, quoteSell, reasonLine, refusalCode, scoreLine, settle, settleError, successValue, tradeArgs, tradeBlock, wishBlock, wishStatus, type Postcard, type TodayView, type Wish } from "./model"; + +const b64=(value:unknown)=>btoa(JSON.stringify(value)); + +test("one-unit quotes equal the live opening shelf's buy_price and sell_price", () => { + // get_shelf on day 20770: glass 40/40 heat 0 → buy 8, sell 6; reed 40/40 → buy 4, sell 3. + expect(quoteBuy("glass",{stock:40,heat_fp:0},1)).toMatchObject({units:[8],total:8,bound:8}); + expect(quoteSell("glass",{stock:40,heat_fp:0},1)).toMatchObject({units:[6],total:6,bound:6}); + expect(quoteBuy("reed",{stock:40,heat_fp:0},1)!.units).toEqual([4]); + expect(quoteSell("reed",{stock:40,heat_fp:0},1).units).toEqual([3]); +}); + +test("multi-unit quotes move stock and heat unit by unit; bounds are the worst unit", () => { + const buy=quoteBuy("glass",{stock:3,heat_fp:0},3)!; + expect(buy.units.length).toBe(3); + expect(buy.units[0]!<=buy.units[1]! && buy.units[1]!<=buy.units[2]!).toBe(true); + expect(buy.bound).toBe(Math.max(...buy.units)); + expect(tradeArgs(buy)).toEqual({good:"glass",qty:3,max_price:buy.bound}); + expect(quoteBuy("glass",{stock:2,heat_fp:0},3)).toBeNull(); + const sell=quoteSell("reed",{stock:40,heat_fp:0},4); + expect(sell.units[0]!>=sell.units[3]!).toBe(true); + expect(tradeArgs(sell)).toEqual({good:"reed",qty:4,min_price:sell.bound}); + expect(sell.bound).toBe(Math.min(...sell.units)); +}); + +test("trade blocks mirror the contract's checks", () => { + const q=quoteBuy("glass",{stock:40,heat_fp:0},1)!; + expect(tradeBlock(q,{shells:7,held:0,till:300,tradedToday:0})).toMatch(/Shells/); + expect(tradeBlock(q,{shells:8,held:0,till:300,tradedToday:0})).toBeNull(); + expect(tradeBlock(q,{shells:99,held:0,till:300,tradedToday:20})).toMatch(/20/); + const s=quoteSell("glass",{stock:40,heat_fp:0},2); + expect(tradeBlock(s,{shells:0,held:1,till:300,tradedToday:0})).toMatch(/satchel/); + expect(tradeBlock(s,{shells:0,held:2,till:5,tradedToday:0})).toMatch(/till/); + expect(tradeBlock(null,{shells:0,held:0,till:0,tradedToday:0})).toMatch(/shelf/); +}); + +test("Bram's reason line uses only stock, target, heat and the till", () => { + expect(reasonLine({good:"glass",stock:40,target:40,base:8,heat_fp:0,buy_price:8},300)) + .toBe("Glass: 40 on the shelf, right at the 40 he keeps; nobody has bought lately. Next unit 8 (base 8). Till: 300 Shells to pay for what you sell."); + const short=reasonLine({good:"reed",stock:20,target:40,base:4,heat_fp:40_000_000,buy_price:8},120); + expect(short).toContain("20 on the shelf, short of the 40 he keeps, so it costs more"); + expect(short).toContain("about 40 recently bought add 15%; that fades by half each day"); + expect(short).toContain("base 4 × 1.62 for stock"); + expect(short).toContain("Till: 120 Shells"); + expect(reasonLine({good:"glass",stock:80,target:40,base:8,heat_fp:500_000,buy_price:5},0)).toContain("over the 40 he keeps, so it costs less; less than one recently bought adds a little"); +}); + +test("every ERR_ code in the season contract has game words", () => { + const lib=readFileSync(resolve(import.meta.dir,"../../../contracts/season/src/lib.rs"),"utf8"); + const codes=new Set(lib.match(/ERR_[A-Z0-9_]+/g)); + expect(codes.size).toBeGreaterThan(20); + for(const code of codes)expect(REFUSALS[code]).toBeDefined(); + for(const words of Object.values(REFUSALS))expect(words).not.toMatch(/\b(wallet|gas|transaction|tx)\b/i); +}); + +test("state mapping: confirmed only for a final success, refusals named, unknown stays uncertain", () => { + const failure={status:{Failure:{ActionError:{kind:{FunctionCallError:{ExecutionError:"Smart contract panicked: ERR_MAX_PRICE"}}}}}}; + expect(refusalCode(failure)).toBe("ERR_MAX_PRICE"); + expect(settle({failed:true,outcome:failure})).toEqual({kind:"refused",code:"ERR_MAX_PRICE",words:REFUSALS.ERR_MAX_PRICE!}); + const trade={seq:1,side:"buy",good:"glass",qty:1,unit_prices:[8],total:8,fills:[]}; + expect(successValue({status:{SuccessValue:b64(trade)}})).toEqual(trade); + expect(settle({failed:false,outcome:{status:{SuccessValue:b64(trade)}}})).toEqual({kind:"confirmed",value:trade}); + expect(settle({failed:false,outcome:{status:{SuccessValue:"%%"}}}).kind).toBe("uncertain"); + expect(settle(null).kind).toBe("uncertain"); + expect(settle({failed:false,outcome:{status:{SuccessValue:b64({status:"refused",reason:"ERR_NOT_OWNER",wish:null,postcard:null})}}})).toEqual({kind:"refused",code:"ERR_NOT_OWNER",words:REFUSALS.ERR_NOT_OWNER!}); + expect(settleError(new Error("This action may still be executing. Check its original receipt; no new payment or craft has been started.")).kind).toBe("uncertain"); + expect(settleError(new Error("ERR_SHELLS")).kind).toBe("refused"); + const thrown=["This action may still be executing. Check its original receipt; no new payment or craft has been started.", + "This saved account needs more test NEAR for gas prepayment and the attached deposit. No new signature was requested. Keep the same account and original action.", + "An earlier action needs its original receipt checked before another action.","The signing identity changed. Reload the saved harbor.","The signature does not match the original NEAR transaction.", + "The native transaction belongs to a different account or harbor.","nonce changed",""]; + for(const message of thrown){const state=settleError(new Error(message));expect(state.kind).not.toBe("confirmed"); + if(state.kind==="refused"||state.kind==="uncertain")expect(state.words).not.toMatch(/\b(wallet|gas|tx|transaction|signature|nonce|craft|payment|receipt)\b/i);} +}); + +test("wish status and postcard lines", () => { + const wish:Wish={pet:"mochi.r.testnet",owner:"p.r.testnet",good:"glass",limit:9,qty:2,purse:18,seq:1,day:1}; + expect(wishStatus(wish,null)).toEqual({kind:"waiting",wish}); + const card:Postcard={pet:wish.pet,owner:wish.owner,good:"glass",qty:2,limit:9,outcome:"filled",reason:"FILLED_BY_TRADE",unit_prices:[8,9],paid:17,refunded:1,trigger:{trade:7,account:"other.r.testnet",side:"sell",good:"glass"},day:2}; + expect(wishStatus(null,card).kind).toBe("filled"); + expect(wishStatus(null,{...card,outcome:"cancelled"}).kind).toBe("cancelled"); + expect(wishStatus(null,null).kind).toBe("none"); + const lines=postcardLines(card).join(" "); + expect(lines).toContain("Mochi got 2 glass."); + expect(lines).toContain("Paid 8 + 9 = 17 Shells against a limit of 9 each; 1 returned."); + expect(lines).toContain("trade 7: other.r.testnet sold"); + expect(lines).toContain("(FILLED_BY_TRADE)"); + expect(wishBlock(12,2,24)).toBeNull(); + expect(wishBlock(13,2,99)).toMatch(/24/); + expect(wishBlock(5,3,99)).toMatch(/1 or 2/); + expect(wishBlock(5,1,4)).toMatch(/Shells/); + // Replacing a wish: the contract checks the purse against Shells held before the old purse returns. + expect(wishBlock(12,2,20)).toMatch(/Shells/); +}); + +const today=(version:"first_light_v1"|"first_light_v2"):TodayView=>({day:20771,next_day_ns:0,rules_version:"tidebound_h1_v1",content_version:version,area:"beacon",command_limit:version==="first_light_v2"?24:15, + mapping:[["lens","glass"],["moth","reed"],["chart","reed"],["salvage","reed"],["vane",null]], + best_haul:version==="first_light_v2"?[{tool:"rope",hauls:[[1,1]]},{tool:"lantern",hauls:[[1,1]]}]:[{tool:"rope",hauls:[[1,1],[0,2]]},{tool:"lantern",hauls:[[1,2]]}],best_fp:12_000_000,minted_today:null,traded_today:null}); + +test("claimable replays a fresh beacon outing and maps docked cargo to goods", () => { + // The same routes the season sandbox test mints with (contracts/season/tests/sandbox.ts). + const v1=["wait","wait","lure:left","take:chart","move:left","take:lens","move:center","return"]; + const v2=["step:north","step:north","step:west","wait","wait","step:east","reel:lens","step:east","step:west","step:east","take:moth","step:west","step:east","step:south","step:west","step:south","return"]; + expect(claimable(today("first_light_v1"),{tool:"lantern",commands:v1,contentVersion:"first_light_v1"})).toEqual({goods:[1,1],cargo:["chart","lens"]}); + expect(claimable(today("first_light_v2"),{tool:"rope",commands:v2,contentVersion:"first_light_v2"})?.goods).toEqual([1,1]); + expect(claimable(today("first_light_v2"),{tool:"rope",commands:v2.slice(0,-1),contentVersion:"first_light_v2"})).toBeNull(); + expect(claimable(today("first_light_v1"),{tool:"rope",commands:["step:north"],contentVersion:"first_light_v2"})).toBeNull(); + expect(claimable(today("first_light_v2"),{tool:"rope",commands:["wait"],contentVersion:"first_light_v2"})).toBeNull(); + expect(claimable(today("first_light_v2"),{tool:"rope",commands:["return"],contentVersion:"first_light_v2"})).toBeNull(); +}); + +test("score line reads the stored basis points", () => { + expect(scoreLine({score_bp:10_000,value_fp:12_000_000,best_fp:12_000_000})).toBe("100% of the best haul (12.00 of 12.00 Shells at today’s shelf prices)"); + expect(scoreLine({score_bp:6667,value_fp:8_000_000,best_fp:12_000_000})).toBe("66.67% of the best haul (8.00 of 12.00 Shells at today’s shelf prices)"); +}); diff --git a/web/src/season/model.ts b/web/src/season/model.ts new file mode 100644 index 0000000..21e3922 --- /dev/null +++ b/web/src/season/model.ts @@ -0,0 +1,240 @@ +/** + * Season 2 view models: quotes, Bram's reason line, refusal words and state mapping. + * Pure functions only. Every number shown comes from a contract view or from `pricing.ts`. + */ +import { BASE, S, TARGET, buyShells, pow07, priceFp, sellShells, type Good } from "./pricing"; +import { replayCourt } from "../expedition/engine"; +import { replayOuting } from "../compatibility/return-rules"; + +export const SEASON_RULES_VERSION = "tidebound_h1_v1"; +export const DAILY_UNITS = 20; +export const PURSE_MAX = 24; +export const WISH_QTY_MAX = 2; + +export interface GoodView { good:Good;stock:number;target:number;base:number;heat_fp:number;price_fp:number;buyback_fp:number;buy_price:number;sell_price:number;waiting_wishes:number } +export interface ShelfView { day:number;till:number;till_cap:number;till_refill:number;commission:number;goods:GoodView[];shells_minted:number;goods_minted:[number,number];trade_seq:number } +export interface Mint { day:number;content_version:string;tool:string;goods:[number,number];value_fp:number;best_fp:number;score_bp:number } +export interface TodayView { + day:number;next_day_ns:number;rules_version:string;content_version:"first_light_v1"|"first_light_v2";area:string;command_limit:number; + mapping:[string,string|null][];best_haul:{tool:string;hauls:[number,number][]}[];best_fp:number;minted_today:Mint|null;traded_today:[number,number]|null; +} +export interface SeasonAccount { shells:number;goods:[number,number];trade_day:number;traded:[number,number];last_mint:Mint|null } +export interface Wish { pet:string;owner:string;good:Good;limit:number;qty:number;purse:number;seq:number;day:number } +export interface Trigger { trade:number;account:string;side:"buy"|"sell";good:Good } +export interface Postcard { pet:string;owner:string;good:Good;qty:number;limit:number;outcome:"filled"|"cancelled"|"replaced";reason:string;unit_prices:number[];paid:number;refunded:number;trigger:Trigger|null;day:number } +export interface Trade { seq:number;side:"buy"|"sell";good:Good;qty:number;unit_prices:number[];total:number;fills:Postcard[] } +export interface WishResult { status:"filled"|"waiting"|"refused";reason:string;wish:Wish|null;postcard:Postcard|null } + +export const GOOD_INDEX:Record = { glass:0, reed:1 }; +export const goodName = (good:Good, qty=1) => good==="glass" ? "glass" : qty===1 ? "reed bundle" : "reed bundles"; +export const courtName = (version:string) => version==="first_light_v2" ? "Beacon Court" : "the old First Light route"; + +// ---------- quotes ---------- + +export interface Quote { side:"buy"|"sell";good:Good;qty:number;units:number[];total:number;bound:number } +export interface ShelfState { stock:number;heat_fp:number } + +/** Unit-by-unit, exactly as the contract's `quote_buy`: each unit moves stock and heat before the next. */ +export function quoteBuy(good:Good, shelf:ShelfState, qty:number):Quote|null { + let stock=BigInt(shelf.stock), heat=BigInt(shelf.heat_fp); + const units:number[]=[]; + for(let i=0;ia+b,0), bound:Math.max(...units) }; +} +/** As `quote_sell`: Bram pays at the post-unit stock, so each unit pays a little less. */ +export function quoteSell(good:Good, shelf:ShelfState, qty:number):Quote { + let stock=BigInt(shelf.stock);const heat=BigInt(shelf.heat_fp),units:number[]=[]; + for(let i=0;ia+b,0), bound:Math.min(...units) }; +} +/** The bound is the shown quote's worst unit, so any later price movement refuses instead of surprising. */ +export function tradeArgs(quote:Quote) { + return quote.side==="buy" ? { good:quote.good, qty:quote.qty, max_price:quote.bound } : { good:quote.good, qty:quote.qty, min_price:quote.bound }; +} +export const quoteLine = (quote:Quote) => + quote.qty===1 ? `${quote.total} Shell${quote.total===1?"":"s"}` : `${quote.units.join(" + ")} = ${quote.total} Shells`; + +/** Why a trade cannot be offered right now, from the same inputs the contract checks. Null means it can be tried. */ +export function tradeBlock(quote:Quote|null, ctx:{shells:number;held:number;till:number;tradedToday:number}):string|null { + if(!quote)return "Bram’s shelf does not have that many."; + if(ctx.tradedToday+quote.qty>DAILY_UNITS)return `Bram trades ${DAILY_UNITS} of each good with you a day.`; + if(quote.side==="buy"&&ctx.shells, till:number):string { + const name=view.good==="glass"?"Glass":"Reed"; + const stockPart = view.stock===view.target + ? `${view.stock} on the shelf, right at the ${view.target} he keeps` + : view.stock0?` ${heatPct}%`:"s a little"}; that fades by half each day`; + const shapePart = view.stock===view.target ? `base ${view.base}` : `base ${view.base} × ${factor.toFixed(2)} for stock`; + return `${name}: ${stockPart}; ${heatPart}. Next unit ${view.buy_price} (${shapePart}). Till: ${till} Shells to pay for what you sell.`; +} + +// ---------- refusals and outcomes ---------- + +/** Every refusal code the season contract can return, in game words. */ +export const REFUSALS:Record = { + ERR_MAX_PRICE:"The price moved above the quote you saw. Nothing changed; look again.", + ERR_MIN_PRICE:"Bram’s offer fell below the quote you saw. Nothing changed; look again.", + ERR_SHELLS:"Not enough Shells for that.", + ERR_GOODS:"Not enough in your satchel.", + ERR_TILL_EMPTY:"Bram’s till cannot pay that much today. It refills each morning.", + ERR_SHELF_EMPTY:"Bram’s shelf has run out of that.", + ERR_DAILY_LIMIT:`Bram trades ${DAILY_UNITS} of each good with you a day.`, + ERR_TRADE_QTY:`Trade between 1 and ${DAILY_UNITS} at a time.`, + ERR_GOOD:"Bram does not keep that.", + ERR_NOT_REGISTERED:"Open your page in Bram’s ledger first.", + ERR_STORAGE_DEPOSIT:"The ledger page needs its full storage deposit.", + ERR_STORAGE:"Your ledger page has no room for another of Mochi’s records.", + ERR_ALREADY_MINTED:"You have already docked today’s tide. Come back tomorrow.", + ERR_WRONG_COURT:"That return is from a different day’s tide.", + ERR_RULES_VERSION:"That return follows different rules.", + ERR_COMMAND_BOUND:"That return has too many moves for today’s tide.", + ERR_REPLAY_CONTEXT:"Today’s tide is a fresh Beacon Court outing.", + ERR_REPLAY:"The harbor could not replay those steps.", + ERR_RETURN_REQUIRED:"Mochi has to reach the dock for the haul to count.", + ERR_NO_GOODS:"Nothing in that haul becomes a good, so the day is still yours.", + ERR_HAUL_BOUND:"That haul is larger than today’s tide allows.", + ERR_PET_ID:"That is not Mochi’s name.", + ERR_WISH_QTY:`Mochi can wish for 1 or ${WISH_QTY_MAX}.`, + ERR_PURSE_LIMIT:`Mochi’s purse holds at most ${PURSE_MAX} Shells.`, + ERR_GAS:"The wish needed more room to check Mochi’s papers. Nothing was taken.", + ERR_NOT_OWNER:"Only Mochi’s keeper can set her wish.", + ERR_OWNER_LOOKUP:"Mochi’s papers could not be checked. Nothing was taken.", + ERR_WISH_QUEUE_FULL:"Too many wishes are waiting for that good. Try the other one.", + ERR_NO_WISH:"Mochi has no wish waiting.", + ERR_NOT_WISH_OWNER:"Only the keeper who set this wish can cancel it.", + ERR_TESTNET_ONLY:"This harbor only runs on the test network.", + ERR_ONE_YOCTO:"That request needs exactly one unit attached.", + ERR_NOTHING_TO_WITHDRAW:"Nothing to take back.", +}; +export const refusalWords = (code:string) => REFUSALS[code] ?? "Bram could not do that. Nothing changed."; + +export function refusalCode(outcome:unknown):string|null { + const text=JSON.stringify(outcome??""); + return text.match(/ERR_[A-Z0-9_]+/)?.[0] ?? null; +} +/** The final return value of a successful transaction (the outer status), parsed as JSON. */ +export function successValue(outcome:unknown):T|null { + const status=(outcome as {status?:{SuccessValue?:unknown}}|null)?.status; + if(typeof status?.SuccessValue!=="string")return null; + try{return JSON.parse(new TextDecoder().decode(Uint8Array.from(atob(status.SuccessValue),c=>c.charCodeAt(0)))) as T;}catch{return null;} +} + +export type ActionState = + | {kind:"idle"} + | {kind:"pending";label:string} + | {kind:"confirmed";value:T} + | {kind:"refused";code:string;words:string} + | {kind:"uncertain";words:string}; + +/** Maps a reconciled final outcome to a state. Only a final, non-failed receipt is "confirmed". */ +export function settle(final:{failed:boolean;outcome:unknown}|null):ActionState { + if(!final)return {kind:"uncertain",words:"The harbor has not seen the result yet. Check again before trying anything new."}; + if(final.failed){const code=refusalCode(final.outcome)??"ERR_UNKNOWN";return {kind:"refused",code,words:refusalWords(code)};} + const value=successValue(final.outcome); + if(value===null)return {kind:"uncertain",words:"The result arrived but could not be read. Your ledger is read again below."}; + // A refused wish is a successful receipt whose value says so (the owner check runs in a callback that never panics). + const refused=value as {status?:unknown;reason?:unknown}; + if(refused&&typeof refused==="object"&&refused.status==="refused"&&typeof refused.reason==="string")return {kind:"refused",code:refused.reason,words:refusalWords(refused.reason)}; + return {kind:"confirmed",value}; +} +export const OPEN_REQUEST="An earlier request is still open. Finish it in Account & recovery (in the menu) before anything new."; +/** A thrown send is never a refusal: the action may still land. Messages are mapped to season words, never passed through. */ +export function settleError(error:unknown):ActionState { + const message=error instanceof Error?error.message:""; + // Stopped before the signer saw anything: the controller's own words are already player-facing. + if(error instanceof Error&&error.name==="SeasonNotSent")return {kind:"refused",code:"NOT_SENT",words:message}; + const code=message.match(/ERR_[A-Z0-9_]+/)?.[0]; + if(code&&REFUSALS[code])return {kind:"refused",code,words:refusalWords(code)}; + if(/more test NEAR/i.test(message))return {kind:"refused",code:"FUNDS",words:"Your harbor account needs a little more test NEAR before Bram can record this. Nothing was sent."}; + if(/may still be executing/i.test(message))return {kind:"uncertain",words:"Bram has not heard whether this landed yet. Check it in Account & recovery (in the menu) before trying again."}; + if(/earlier action|original request|original action|pending/i.test(message))return {kind:"uncertain",words:OPEN_REQUEST}; + if(/sign in|signed-in|identity|sign-in/i.test(message))return {kind:"refused",code:"SIGN_IN",words:"Sign in again from the menu. Nothing was sent."}; + return {kind:"uncertain",words:"Bram could not finish that just now. If a request was started, it is kept in Account & recovery (in the menu)."}; +} + +// ---------- Mochi's wish ---------- + +export type WishStatus = + | {kind:"none"} + | {kind:"waiting";wish:Wish} + | {kind:"filled";card:Postcard} + | {kind:"cancelled";card:Postcard}; + +export function wishStatus(wish:Wish|null, card:Postcard|null):WishStatus { + if(wish)return {kind:"waiting",wish}; + if(card?.outcome==="filled")return {kind:"filled",card}; + if(card)return {kind:"cancelled",card}; + return {kind:"none"}; +} +export const POSTCARD_REASONS:Record = { + FILLED_ON_SET:"Bram’s price was already within the limit when the wish was set.", + FILLED_BY_TRADE:"A trade at Bram’s shelf brought the price within the limit.", + CANCELLED_BY_OWNER:"The wish was taken back and the purse returned.", + REPLACED_BY_OWNER:"A new wish replaced it and the purse was returned.", +}; +export function postcardLines(card:Postcard):string[] { + const what=`${card.qty} ${goodName(card.good,card.qty)}`; + const lines=[card.outcome==="filled"?`Mochi got ${what}.`:`Mochi’s wish for ${what} was ${card.outcome==="cancelled"?"cancelled":"replaced"}.`]; + if(card.outcome==="filled")lines.push(`Paid ${card.unit_prices.join(" + ")} = ${card.paid} Shells against a limit of ${card.limit} each; ${card.refunded} returned.`); + else lines.push(`${card.refunded} Shells returned from the purse.`); + if(card.trigger)lines.push(`It happened on trade ${card.trigger.trade}: ${card.trigger.account} ${card.trigger.side==="buy"?"bought":"sold"} ${goodName(card.trigger.good,2)}.`); + lines.push(`${POSTCARD_REASONS[card.reason]??"Reason recorded by the harbor."} (${card.reason})`); + return lines; +} +export function wishBlock(limit:number, qty:number, shells:number):string|null { + if(!Number.isInteger(limit)||limit<1)return "Choose a limit of at least 1 Shell."; + if(!Number.isInteger(qty)||qty<1||qty>WISH_QTY_MAX)return `Mochi can wish for 1 or ${WISH_QTY_MAX}.`; + if(limit*qty>PURSE_MAX)return `Mochi’s purse holds at most ${PURSE_MAX} Shells.`; + if(shells, run:ReplayCandidate):Claimable|null { + if(run.contentVersion!==today.content_version||run.commands.length>today.command_limit)return null; + const replay=today.content_version==="first_light_v2" + ? replayCourt({area:"beacon",tool:run.tool,banked:[]},run.commands) + : replayOuting(run.tool,[],run.commands,"beacon"); + if(!replay||replay.outcome!=="returned")return null; + const goods:[number,number]=[0,0]; + for(const item of replay.cargo){const g=today.mapping.find(([name])=>name===item)?.[1];if(g==="glass")goods[0]++;if(g==="reed")goods[1]++;} + if(goods[0]+goods[1]===0)return null; + const hauls=today.best_haul.find(h=>h.tool===run.tool)?.hauls??[]; + if(!hauls.some(([g,r])=>goods[0]<=g&&goods[1]<=r))return null; + return {goods,cargo:[...replay.cargo]}; +} +export const haulLine = (goods:readonly [number,number]) => + [goods[0]?`${goods[0]} glass`:"",goods[1]?`${goods[1]} ${goodName("reed",goods[1])}`:""].filter(Boolean).join(" and ")||"nothing"; +export const scoreLine = (mint:Pick) => + `${(mint.score_bp/100).toFixed(mint.score_bp%100?2:0)}% of the best haul (${(mint.value_fp/1e6).toFixed(2)} of ${(mint.best_fp/1e6).toFixed(2)} Shells at today’s shelf prices)`; +export function bestHaulLine(today:Pick):string { + return today.best_haul.map(t=>`${t.tool}: ${t.hauls.map(h=>haulLine(h)).join(" or ")}`).join(" · "); +} diff --git a/web/src/season/pricing.test.ts b/web/src/season/pricing.test.ts new file mode 100644 index 0000000..4bdf4d2 --- /dev/null +++ b/web/src/season/pricing.test.ts @@ -0,0 +1,15 @@ +import { expect, test } from "bun:test"; +import cases from "../../../contracts/season/fixtures/pricing-cases.json"; +import { BASE, TARGET, S, buyShells, buybackFp, commission, decayHeat, pow07, priceFp, sellShells, type Good } from "./pricing"; + +test("pricing.ts equals pricing.rs on 1,000 seeded cases", () => { + expect(cases.length).toBe(1000); + for (const c of cases) { + const good = c.good as Good; + const heatNow = decayHeat(BigInt(c.heat_fp), BigInt(c.days)); + const price = priceFp(BASE[good], TARGET[good], BigInt(c.stock), heatNow); + const ratio = TARGET[good] * S / (BigInt(c.stock) > 1n ? BigInt(c.stock) : 1n); + expect([heatNow, pow07(ratio), price, buybackFp(price), buyShells(price), sellShells(price), commission(price * BASE.glass / BASE[good])].map(String)) + .toEqual([c.heat_now_fp, c.pow, c.price_fp, c.buyback_fp, c.buy, c.sell, c.commission]); + } +}); diff --git a/web/src/season/pricing.ts b/web/src/season/pricing.ts new file mode 100644 index 0000000..df63fcd --- /dev/null +++ b/web/src/season/pricing.ts @@ -0,0 +1,46 @@ +/** + * Bram's integer pricing, identical to contracts/season/src/pricing.rs. + * Fixed point scale S = 1e6; every division floors (all values are non-negative BigInt). + * A unit bought costs ceil(price / S) Shells; a unit sold pays floor(0.8 × price / S). + */ +export const S = 1_000_000n; +export const RATIO_MIN = 300_000n; +export const RATIO_MAX = 5_000_000n; +export const POW_MIN = 500_000n; +export const POW_MAX = 3_000_000n; +export const HEAT_HALVINGS_CAP = 64n; +export const GOODS = ["glass", "reed"] as const; +export type Good = typeof GOODS[number]; +export const BASE: Record = { glass: 8n, reed: 4n }; +export const TARGET: Record = { glass: 40n, reed: 40n }; + +const clamp = (x: bigint, lo: bigint, hi: bigint) => x < lo ? lo : x > hi ? hi : x; +const max = (a: bigint, b: bigint) => a > b ? a : b; + +export function isqrt(n: bigint): bigint { + let lo = 0n, hi = 1n << 64n; + while (hi - lo > 1n) { const mid = lo + (hi - lo) / 2n; if (mid * mid <= n) lo = mid; else hi = mid; } + return lo; +} +export function iroot5(n: bigint): bigint { + let lo = 0n, hi = 1n << 25n; + while (hi - lo > 1n) { const mid = lo + (hi - lo) / 2n; if (mid ** 5n <= n) lo = mid; else hi = mid; } + return lo; +} +export function pow07(ratioFp: bigint): bigint { + const x = clamp(ratioFp, RATIO_MIN, RATIO_MAX); + return clamp(isqrt(x * S) * iroot5(x * S ** 4n) / S, POW_MIN, POW_MAX); +} +export function decayHeat(heatUnitsFp: bigint, days: bigint): bigint { + return days >= HEAT_HALVINGS_CAP ? 0n : heatUnitsFp >> days; +} +export function priceFp(base: bigint, target: bigint, stock: bigint, heatUnitsFp: bigint): bigint { + const ratio = target * S / max(stock, 1n); + const heatFp = heatUnitsFp / target; + return base * pow07(ratio) * (S + heatFp * 3n / 20n) / S; +} +export const buybackFp = (price: bigint) => price * 4n / 5n; +export const buyShells = (price: bigint) => (price + S - 1n) / S; +export const sellShells = (price: bigint) => buybackFp(price) / S; +export const commission = (glassPriceFp: bigint, glassBase = BASE.glass) => clamp(12n * glassPriceFp / (glassBase * S), 6n, 36n); +export const goodPriceFp = (good: Good, stock: bigint, heatUnitsFp: bigint) => priceFp(BASE[good], TARGET[good], stock, heatUnitsFp); diff --git a/web/src/season/season.css b/web/src/season/season.css new file mode 100644 index 0000000..0519a55 --- /dev/null +++ b/web/src/season/season.css @@ -0,0 +1,68 @@ +.exp-panel.exp-panel-season{width:min(560px,100%)} +.ss{--ss-ink:#2c4335;--ss-soft:#53442b;--ss-line:#c9ad7c;--ss-card:#fbf0d6;--ss-sea:#2f5c4c;margin-top:18px;padding-top:16px;border-top:1px solid var(--ss-line);color:var(--ss-ink)} +.ss h3,.ss h4{font-family:"Fraunces Variable",serif;letter-spacing:-.02em;margin:0} +.ss h3{font-size:22px;line-height:1.15} +.ss h4{font-size:17px;line-height:1.2} +.ss p{font-size:15px;line-height:1.45} +.ss-head{display:flex;gap:12px;align-items:center;margin-bottom:10px} +.ss-head img{flex:0 0 auto;filter:drop-shadow(0 3px 4px #4a35202e)} +.ss-head p{margin:3px 0 0} +.ss-mode{font-size:13px!important;color:var(--ss-soft);overflow-wrap:anywhere} +.ss-mode[data-mode=preview]{display:inline-block;padding:4px 9px;border-radius:7px;background:#ecd6a6;color:#4a3519;font-weight:650} +.ss-holdings{display:flex;flex-wrap:wrap;align-items:center;gap:6px 14px;margin:0 0 12px;padding:8px 12px;background:var(--ss-card);border-radius:10px;font-variant-numeric:tabular-nums} +.ss-holdings small{flex-basis:100%;font-size:12px;color:var(--ss-soft)} +.ss-holdings b{font-size:17px} +.ss-ledger{margin:0 0 14px;padding:12px;border-radius:12px;background:#e9dcb4} +.ss-tabs{display:flex;gap:4px;margin:4px 0 6px;padding:4px;background:#e5cf9f;border-radius:12px} +.exp-game .ss-tabs button{flex:1;min-height:44px;padding:8px 6px;font-size:14px;background:transparent;border-color:transparent;box-shadow:none;color:#3f3420} +.exp-game .ss-tabs button[aria-selected=true]{background:#fbf0d6;border-color:#b99561;color:var(--ss-ink);box-shadow:0 2px 5px #4a35201f} +.ss-status{min-height:22px;margin:6px 0 8px!important;font-size:14px!important;font-weight:650} +.ss-status[data-state=pending]{color:var(--ss-sea)} +.ss-status[data-state=confirmed]{color:#24533f} +.ss-status[data-state=refused],.ss-status[data-state=uncertain]{color:#7a3020} +.ss-problem{color:#7a3020} +.ss-panel{display:grid;gap:12px} +.ss-panel>p{margin:0} +.ss-till{margin:0!important;font-variant-numeric:tabular-nums} +.ss-good{display:grid;grid-template-columns:56px 1fr;gap:12px;padding:12px;background:var(--ss-card);border-radius:14px;box-shadow:0 2px 8px #4a352014} +.ss-good img{filter:drop-shadow(0 2px 3px #4a352030)} +.ss-good h4 span{font-family:"Figtree Variable",sans-serif;font-size:13px;font-weight:600;color:var(--ss-soft);margin-left:6px;font-variant-numeric:tabular-nums} +.ss-good-body{min-width:0} +.ss-prices{display:flex;flex-wrap:wrap;gap:2px 18px;margin:6px 0} +.ss-prices div{display:flex;gap:6px;align-items:baseline;white-space:nowrap} +.ss-prices dt{font-size:13px;color:var(--ss-soft)} +.ss-prices dd{margin:0;font-weight:800;font-size:18px;font-variant-numeric:tabular-nums} +.ss-prices dd::after{content:" Shells";font-size:12px;font-weight:600} +.ss .ss-reason{font-size:13px;line-height:1.4;color:var(--ss-soft);margin:0 0 10px} +.ss-trade{display:grid;gap:6px} +.ss-act{display:flex;align-items:center;gap:10px;flex-wrap:wrap} +.ss-act>button{flex:0 0 auto;min-width:96px} +.ss-info{font-size:13px;color:var(--ss-soft);font-variant-numeric:tabular-nums;flex:1 1 140px} +.ss-stepper{display:inline-flex;align-items:center;gap:4px;margin-bottom:2px} +.exp-game .ss-stepper button{width:44px;padding:0;font-size:20px;line-height:1} +.ss-stepper output{min-width:36px;text-align:center;font-weight:800;font-size:18px;font-variant-numeric:tabular-nums} +.ss .ss-note{font-size:13px;color:var(--ss-soft)} +.exp-game .ss-link{background:transparent;border:0;box-shadow:none;padding:8px 4px;text-decoration:underline;text-underline-offset:3px;font-weight:650} +.ss-court{font-size:20px!important} +.ss-facts{display:grid;gap:6px;margin:0;padding:10px 12px;background:var(--ss-card);border-radius:12px} +.ss-facts div{display:grid;grid-template-columns:112px 1fr;gap:8px} +.ss-facts dt{font-size:13px;color:var(--ss-soft)} +.ss-facts dd{margin:0;font-size:14px} +.ss-docked{font-weight:650;margin:0} +.ss-docked[data-docked=true]{color:#24533f} +.exp-panel .ss-tool,.exp-panel .ss-wish-form{margin:0;padding:12px;border:1px solid var(--ss-line);border-radius:12px;display:grid;gap:6px} +.exp-panel .ss-tool label,.exp-panel .ss-choice label{min-height:44px;padding:4px 6px} +.ss-tool>button{width:100%} +.ss-returns{display:grid;gap:8px} +.ss-wish-head{display:flex;gap:12px;align-items:center} +.ss-wish-head p{margin:0} +.ss-choice{display:flex;gap:4px 14px;flex-wrap:wrap} +.ss-choice img{margin-left:-2px} +.ss-limit{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap} +.ss-postcard{display:grid;grid-template-columns:40px 1fr;gap:10px;padding:12px 14px;background:#fff7e3;border-radius:6px;box-shadow:0 3px 10px #4a35201c;transform:rotate(-.4deg)} +.ss-postcard p{font-size:14px;margin:0 0 4px} +.ss-postcard p:last-child{font-size:12px;color:var(--ss-soft);margin:0} +@media (prefers-reduced-motion:reduce){.ss-postcard{transform:none}} +@media(max-width:480px){.ss-prices{gap:12px}.ss-facts div{grid-template-columns:1fr;gap:2px}.ss-good{grid-template-columns:44px 1fr;gap:10px;padding:10px}.ss-good>img{width:44px;height:44px}.exp-game .ss-tabs button{font-size:13px;padding:6px 4px}} +.ss-field{font-size:13px;font-weight:700;color:var(--ss-soft);margin-top:4px} +.exp-game .ss button[aria-disabled=true]{cursor:default;opacity:.5;box-shadow:none}.exp-game .ss button[aria-disabled=true]:hover{background:#eddbad}.exp-game .ss .exp-primary[aria-disabled=true]:hover{background:#3c6555}.ss-status:focus{outline:none}.ss-status:focus-visible{outline:3px solid #37634b;outline-offset:2px} diff --git a/web/src/tidebound/client.ts b/web/src/tidebound/client.ts index dd9fe66..075c6fa 100644 --- a/web/src/tidebound/client.ts +++ b/web/src/tidebound/client.ts @@ -81,11 +81,16 @@ export function nativeGas(method:string):bigint { if(["tidebound_craft","tidebound_retry_operation"].includes(method))return teraToGas(120); if(["tidebound_polish","tidebound_cancel_polish"].includes(method))return teraToGas(100); if(["tidebound_place","tidebound_reconcile"].includes(method))return teraToGas(80); + // Live day 20771 burnt under 4 Tgas each; 100 Tgas prepaid would reserve about 0.1 NEAR of a player's balance. + if(["claim_daily","buy","sell"].includes(method))return teraToGas(30); + if(method==="set_wish")return teraToGas(80); return teraToGas(50); } /** Fixed testnet tuple, native player-funded transactions, and one persisted uncertain action per account. */ export class TideboundClient { + /** The last reconciled final outcome, so a caller can read a contract's return value or refusal. */ + lastFinal:{hash:string;method:string;receiver:string;failed:boolean;outcome:unknown}|null=null; constructor(readonly root:string,readonly itemsContract:string,readonly provider:JsonRpcProvider,readonly adapter:RecoverableAccountAdapter,private readonly store:Pick) {} async view(contractId:string,method:string,args:Record={},blockId?:string):Promise { return await this.provider.callFunction({contractId,method,args,blockQuery:blockId?{blockId}:{finality:"final"}}) as unknown as T; @@ -165,7 +170,7 @@ export class TideboundClient { check(binding.network==="testnet" && isPlayerAccount(binding.nearAccountId,this.root),"The account belongs to a different testnet harbor."); const tx=decodeTransaction(base64Decode(pending.transaction)); check(base64Encode(encodeTransaction(tx))===pending.transaction && tx.signerId===binding.nearAccountId && tx.receiverId===pending.receiver && - [this.root,this.itemsContract].includes(tx.receiverId) && tx.publicKey.toString()===binding.signerPublicKey && + [this.root,this.itemsContract,`season.${this.root}`].includes(tx.receiverId) && tx.publicKey.toString()===binding.signerPublicKey && tx.actions.length===1 && tx.actions[0]?.functionCall?.methodName===pending.method,"The original signing context changed."); validateNativeIntent(tx,{root:this.root,items:this.itemsContract}); const call=tx.actions[0]?.functionCall; @@ -244,6 +249,7 @@ export class TideboundClient { const current=this.pending(binding); check(current?.operationId===pending.operationId&¤t.hash===pending.hash&¤t.transaction===pending.transaction,"Another tab changed this pending action."); this.store.removeItem(this.pendingKey(binding)); + this.lastFinal={hash:pending.hash,method:pending.method,receiver:pending.receiver,failed,outcome}; return failed ? "A receipt failed. Canonical progress and item state are read separately below; reserved operations still need reconciliation." : "Transaction finalized. Progress and ownership are read separately below."; } export(snapshot:ChainSnapshot) { return JSON.stringify({version:1,authority:"near-testnet",network:"testnet",root:this.root,itemContract:this.itemsContract,accountId:snapshot.binding.nearAccountId,lastReadAt:snapshot.readAt,journey:snapshot.journey,items:snapshot.items,contentVersion:CONTENT_VERSION,rulesVersion:RULES_VERSION},null,2); }