gambiarra-v2 / contracts
AGENTS.md0 starsChanged 28 days agoMITView on GitHub
Leia o AGENTS.md da raiz primeiro. Este arquivo cobre apenas a camada Solidity. A v2 é uma camada satélite sobre o MasterChef legado da Gambiarra Finance na BSC. O MasterChef (0x77c1618248358f92Cb144269790103e67378A550) tem owner() == 0x0 e é imutável. Nunca proponha alterá-lo, migrá-lo ou fazer delegatecall nele. Venue (imutável, verificada on-chain): o par GAMB/WBNB é um par PancakeSwap V1 (factory 0xBCfCcbde45cE874adCB698cC183deBcF17952812), então o router do deploy é o V1 Router02 0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F. O Router V2 0x10ED43C7… não roteia este par: a factory…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 32,671 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository6 other files it gives its agents.
- AGENTS.mdAGENTS.md
- web/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/gambiarra.mdcCursor rule
- project-docsSkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
LTV e liquidação: Default 40% LTV / 50% threshold.
- Very specific: line 85
Use mocks em test/mocks/ e interfaces em src/interfaces/ para isolar.
≈ “Common” is an estimate: at least 1 in 5 of the 41,581 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — contratos
Leia o AGENTS.md da raiz primeiro. Este arquivo cobre apenas a
camada Solidity.
Contexto
A v2 é uma camada satélite sobre o MasterChef legado da Gambiarra Finance na
BSC. O MasterChef (0x77c1618248358f92Cb144269790103e67378A550) tem
owner() == 0x0 e é imutável. Nunca proponha alterá-lo, migrá-lo ou fazer
delegatecall nele.
Contratos:
| Arquivo | Papel |
src/GambVault.sol | ERC4626 auto-compounder, stake no pool 25 |
src/GambTwapOracle.sol | TWAP GAMB/WBNB + fair LP value |
src/GambLendingPool.sol | lending isolado de WBNB, colateral em shares |
src/GambLeverageZap.sol | abre/fecha alavancagem via flash swap Pancake V2 (WBNB/BUSD) |
Venue (imutável, verificada on-chain): o par GAMB/WBNB é um par PancakeSwap V1
(factory 0xBCfCcbde45cE874adCB698cC183deBcF17952812), então o router do deploy é o
V1 Router02 0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F. O Router V2
0x10ED43C7… não roteia este par: a factory V2 devolve address(0) e todo
addLiquidity reverte. O par de flash do zap é do V2 de propósito — a fee de 0,25%
dele é a que o zap assume.
Invariantes
- ERC4626 com virtual shares/assets. A proteção contra inflação de shares é obrigatória. Teste: doação direta antes do primeiro depósito não deve roubar valor de quem deposita depois.
- Saques nunca pausáveis. Depósitos podem ser pausados;
withdraw/redeemnão. Não adicionewhenNotPausedneles. - Contabilidade de shares.
totalAssets()deve usar o valor real do pool, não um contador que possa dessincronizar.accrueInterest()antes de qualquer mudança de dívida no lending. - LTV e liquidação. Default 40% LTV / 50% threshold. Liquidação é
permissionless. Não adicione allowlist nem bônus de liquidação acima do
configurado. Uma liquidação quita no máximo 50% da dívida
(
MAX_CLOSE_FACTOR_BPS): quem liquida precisa repetir em rodadas até a posição ficar saudável, e a posição fica saudável antes disso (o bônus desalavanca). Posições com dívida abaixo deDUST_DEBTsão liquidadas em uma chamada só, para o close factor nunca deixar dívida irrecuperável. - Oráculo falha fechado. Preço velho/insuficiente reverte. Nunca use spot como fallback silencioso. A janela mínima é 30 min e o fair value do LP é geométrico.
- Alavancagem. O teto do zap é derivado de
lendingPool.maxLtvBps()com margem de 10%. Não volte para 3x fixo. - Sem proxy, sem upgrade, sem
delegatecall. Contratos imutáveis. evm_version = "paris". BSC historicamente rejeitaPUSH0. Não mude sem validar em testnet.- Pragma exato
0.8.26. Sem ranges. - Checks-effects-interactions em toda função que move fundos; use
ReentrancyGuardonde houver callback externo (flash swap, MasterChef). - Venue do par. O par GAMB/WBNB é PancakeSwap V1. Nunca aponte o
deploy para o Router V2 — reverte. Ver
script/DeployLib.sol(LegacyAddresses). - O oráculo precisa de keeper. O par está dormente, então a janela TWAP só
anda com
GambTwapOracle.poke(). Sem um keeper dando poke a cada 30–120 min, o preço envelhece e o lending pool para de emprestar. O keeper permissionless está emscript/Keeper.s.sol(make keeper) e também chamaGambVault.harvest(); ambos são best-effort (umTooSooné no-op).
Testes
forge fmt
forge fmt --check
forge test -vvv
forge test --match-contract GambLegacyForkTest -vvv # precisa de BSC_RPC_URL
make fork-test # invariantes do legado
make fork-test-v2 # a v2 inteira contra a BSC real
make keeper # poke() no oráculo + harvest() do vault (permissionless)Os fork tests fixam o bloco, então precisam de um RPC archive. Os
bsc-dataseedpúblicos são podados e respondem "missing trie node" para estado histórico;https://bsc-mainnet.public.blastapi.iofunciona. O bloco pode ser trocado comBSC_FORK_BLOCK.
- Adicione teste para toda mudança de comportamento, especialmente falhas (revert esperado), limites e aritmética.
- Use mocks em
test/mocks/e interfaces emsrc/interfaces/para isolar. - O fork test (
test/GambLegacy.fork.t.sol) valida os fatos do legado e é pulado no CI quandoBSC_RPC_URLnão existe. contracts/lib/é vendorizado (forge-std + OpenZeppelin). Não edite.
Segurança
- Rode Aderyn/Slither em mudanças que tocam fundos, shares, juros, LTV,
liquidação ou oráculo. Atualize
AUDIT.mdcom o triage. - Não faça deploy em mainnet. Deploy em testnet só com confirmação explícita.
- Nunca commite chave privada, mnemônico ou
.env.
Commits
Autor codingsh <codingsh@pm.me>, sem Co-authored-by. Conventional Commits em
português. Não use git add -A se houver trabalho de outra sessão no tree.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

