Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9c45b3a
feat: add BadDebtHelper for atomic bad debt repayment (VIP-690)
Debugger022 Mar 25, 2026
a30ddc7
test: add fork test for BadDebtHelper against BSC mainnet
Debugger022 Mar 25, 2026
898ef2e
refactor: simplify BadDebtHelper to plain contract and fix some issues
Debugger022 Mar 25, 2026
2695fb3
feat: add deployment script for BadDebtHelper
Debugger022 Mar 25, 2026
abf6b42
chore: add BadDebtHelper deployment artifacts for BSC mainnet
Debugger022 Mar 25, 2026
022ad22
feat: updating deployment files
Debugger022 Mar 25, 2026
984237b
fix(BadDebtHelper): use borrowBalanceCurrent for BNB repayments
Debugger022 Mar 25, 2026
0c633af
feat(BadDebtHelper): add sweep function for emergency token recovery
Debugger022 Mar 25, 2026
8fbb8c8
feat(BadDebtHelper): return all remaining tokens to timelock after ex…
Debugger022 Mar 25, 2026
7425796
test(BadDebtHelper): update fork test for dynamic BNB repayment amounts
Debugger022 Mar 25, 2026
b78c003
fix(BadDebtHelper): send remaining tokens to treasury instead of time…
Debugger022 Mar 26, 2026
edc087a
refactor(BadDebtHelper): replace misleading event with generic Tokens…
Debugger022 Mar 26, 2026
aaa0be2
feat: updating deployment files
Debugger022 Mar 26, 2026
8a8e83b
feat: updating deployment files
Debugger022 Mar 26, 2026
c880669
feat(BadDebtHelper): cap total THE sweep to 4.05M to preserve vTHE ex…
Debugger022 Mar 26, 2026
a533010
feat: redeploy BadDebtHelper to bscmainnet
Debugger022 Mar 26, 2026
95c5c2b
feat: updating deployment files
Debugger022 Mar 26, 2026
133aeb3
fix(BadDebtHelper): send remaining tokens to treasury instead of time…
Debugger022 Mar 26, 2026
915275f
feat: update badDebtHelper deployment
Debugger022 Mar 26, 2026
e46feaa
feat: updating deployment files
Debugger022 Mar 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
447 changes: 447 additions & 0 deletions contracts/Tokens/VTokens/BadDebtHelper.sol

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions deploy/019-deploy-bad-debt-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { skipRemoteNetworks } from "../helpers/deploymentConfig";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

await deploy("BadDebtHelper", {
contract: "BadDebtHelper",
from: deployer,
args: [],
log: true,
autoMine: true,
skipIfAlreadyDeployed: false,
});

return hre.network.live;
};

func.id = "bad_debt_helper_deploy";
func.tags = ["BadDebtHelper"];
func.skip = skipRemoteNetworks();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Narrow this deploy to mainnet-only.

Line 24 reuses skipRemoteNetworks(), which still allows bsctestnet and hardhat. This helper is wired to BSC mainnet markets/borrowers, so a testnet deployment would produce a contract that looks valid but points at the wrong pool state and timelock. Please gate this script to bscmainnet only, or explicitly to forked hardhat if you need local smoke deployments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deploy/019-deploy-bad-debt-helper.ts` at line 24, The deploy script currently
sets func.skip = skipRemoteNetworks(), which still permits bsctestnet and
hardhat; change the skip predicate so the script runs only on BSC mainnet (e.g.,
require network name equals "bscmainnet") and optionally allow local forked
hardhat runs (e.g., allow when network is "hardhat" and FORK env is set); update
the assignment to func.skip to check for those exact network names instead of
calling skipRemoteNetworks(), so this helper cannot run on testnets by accident.


export default func;
176 changes: 176 additions & 0 deletions deployments/bscmainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,182 @@
}
]
},
"BadDebtHelper": {
"address": "0x483F54f175F6863d53705816C43c89e620caf706",
"abi": [
{
"inputs": [],
"name": "ApproveFailed",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "vToken",
"type": "address"
},
{
"internalType": "uint256",
"name": "errorCode",
"type": "uint256"
}
],
"name": "VTokenError",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "vToken",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "borrower",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "repayAmount",
"type": "uint256"
}
],
"name": "BadDebtRepaid",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "RemainingTHETransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "token",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "TokensReturned",
"type": "event"
},
{
"inputs": [],
"name": "NORMAL_TIMELOCK",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "THE_TARGET_RECEIVER",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TOTAL_THE_SWEEP",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "TREASURY",
"outputs": [
{
"internalType": "address payable",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "execute",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "sweep",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
},
"CAKE": {
"address": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
"abi": [
Expand Down
3 changes: 2 additions & 1 deletion deployments/bscmainnet/.migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"xvs_vault_configuration": 1697032901,
"configure_prime": 1697032901,
"configure_xvs_vaults": 1697032901,
"vai_controller_config": 40555052
"vai_controller_config": 40555052,
"bad_debt_helper_deploy": 1774500621
}
Loading
Loading