From 46b12a8857c81fc7a2b95d0236f72248bedb9bc7 Mon Sep 17 00:00:00 2001 From: Sikkra <159844544+Sikkra@users.noreply.github.com> Date: Tue, 19 May 2026 10:49:30 -0500 Subject: [PATCH] Add opt-in pre-commit hooks --- README.md | 30 ++++++++++++++++++++++++++++++ frontend/package.json | 1 + frontend/src/main.ts | 10 ++++++++-- frontend/tsconfig.json | 1 + lefthook.yml | 14 ++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 README.md create mode 100644 lefthook.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..9ca7b48 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# TurboLong + +TurboLong contains the Stellar frontend, alert worker, simulator, and Blend leverage strategy code for the project. + +## Pre-commit Hooks + +This repo uses an opt-in [Lefthook](https://lefthook.dev/) config to run the same local checks before commit that contributors should run before opening a PR. + +Install the hooks from the repo root: + +```sh +npx --yes lefthook install +``` + +The pre-commit hook runs staged-file scoped checks: + +- Frontend changes run `npm run build` and `npm run typecheck` from `frontend/`. +- Rust changes under `src/`, `contracts/`, or `tests/` run `rustfmt --check` on the staged Rust files. + +For emergency commits, bypass hooks with either: + +```sh +git commit --no-verify +``` + +or: + +```sh +LEFTHOOK=0 git commit +``` diff --git a/frontend/package.json b/frontend/package.json index 56b9808..b2f9165 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -5,6 +5,7 @@ "scripts": { "dev": "vite", "build": "vite build", + "typecheck": "tsc --noEmit", "preview": "vite preview" }, "dependencies": { diff --git a/frontend/src/main.ts b/frontend/src/main.ts index fcc1ceb..70a282b 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -1707,7 +1707,7 @@ function showConnected() { async function connect() { try { - const result = await StellarWalletsKit.authModal({ network: getActiveNetwork() === "testnet" ? Networks.TESTNET : Networks.PUBLIC }); + const result = await StellarWalletsKit.authModal(); // Verify wallet network matches app network const networkOk = await verifyWalletNetwork(); if (!networkOk) { @@ -1729,7 +1729,7 @@ async function connect() { /** Re-open wallet modal to switch to a different account without a full page reload. */ async function switchWallet() { try { - const result = await StellarWalletsKit.authModal({ network: getActiveNetwork() === "testnet" ? Networks.TESTNET : Networks.PUBLIC }); + const result = await StellarWalletsKit.authModal(); if (result.address === userAddress) return; // Verify wallet network matches app network const networkOk = await verifyWalletNetwork(); @@ -2238,6 +2238,12 @@ $("demo-btn").addEventListener("click", () => { asset: a, cFactor: a.cFactor, lFactor: 1, interestSupplyApr: 4.2, interestBorrowApr: 6.8, blndSupplyApr: 2.1, blndBorrowApr: 1.5, netSupplyApr: 6.3, netBorrowCost: 5.3, totalSupply: 1000000, totalBorrow: 650000, available: 350000, priceUsd: 1.0, + bRate: 1_000_000_000_000n, dRate: 1_000_000_000_000n, bSupply: 1_000_000_000_000n, dSupply: 650_000_000_000n, + supplyEps: 0n, borrowEps: 0n, supplyEmission: null, borrowEmission: null, + rateConfig: { + rBase: 0, rOne: 500_000, rTwo: 2_000_000, rThree: 150_000_000, + utilOpt: Math.round(a.maxUtil * 10_000_000), irMod: 10_000_000, backstopFP: selectedPool.backstopFP, + }, })); positions = { byAsset: new Map() }; // One sample position diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 1616678..2e6e2a7 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -4,6 +4,7 @@ "lib": ["ES2020", "DOM"], "module": "ESNext", "moduleResolution": "bundler", + "allowImportingTsExtensions": true, "strict": true, "noUnusedLocals": false, "noUnusedParameters": false, diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..0507426 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,14 @@ +pre-commit: + parallel: true + commands: + frontend-build: + root: frontend/ + glob: "frontend/**/*.{ts,html,css,json}" + run: npm run build + frontend-typecheck: + root: frontend/ + glob: "frontend/**/*.{ts,json}" + run: npm run typecheck + rustfmt: + glob: "{src,contracts,tests}/**/*.rs" + run: rustfmt --check {staged_files}