Address
0x8d9715671dd02ed5f4de4b83196c697ceddbf4c8Current Holdings
$0.00
TXs sent
not counted
First Active
2026-06-12
block 26,768,158
Last Active
98 days ago
block 26,768,158
Funded By
not identified
Net worth historyi
No net-worth snapshots recorded yet
exact matchPulseChainLeverageAndSweepsolc 0.8.34+commit.80d5c536runtime exact · creation exact
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
}
interface ICEther {
function mint() external payable;
}
interface ICDAI {
function mint(uint256 amount) external returns (uint256);
function borrow(uint256 amount) external returns (uint256);
function redeem(uint256 redeemTokens) external returns (uint256);
}
interface IComptroller {
function enterMarkets(address[] calldata markets) external returns (uint256[] memory);
function getAccountLiquidity(address account) external view returns (uint256 errCode, uint256 liquidity, uint256 shortfall);
function oracle() external view returns (address);
}
interface IPriceOracle {
function getUnderlyingPrice(address cToken) external view returns (uint256);
}
interface IBalancerVault {
function flashLoan(
address recipient,
address[] calldata tokens,
uint256[] calldata amounts,
bytes calldata userData
) external;
}
contract PulseChainLeverageAndSweep {
address public immutable owner;
mapping(address => bool) public whitelist;
// Checksummed Contract Addresses (PulseChain Network)
address public constant DAI = 0xefD766cCb38EaF1dfd701853BFCe31359239F305;
address public constant cDAI = 0x62959F4dEb530000000000000000000000000000;
address public constant cETH = 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5;
address public constant COMPTROLLER = 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B;
address public constant BALANCER_VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
// Safety factor: Borrow 95% of max capacity to avoid instant liquidation
uint256 public constant BORROW_SAFETY_FACTOR = 95;
event MaxLeverageExecuted(address indexed caller, uint256 nativeDeposit, uint256 flashLoanedDAI);
event YieldSwept(address indexed owner, uint256 amount);
event WhitelistUpdated(address indexed target, bool status);
modifier onlyOwner() { require(msg.sender == owner, "Owner only"); _; }
modifier onlyWhitelisted() { require(whitelist[msg.sender], "Not authorized"); _; }
constructor() {
owner = msg.sender;
whitelist[msg.sender] = true;
}
receive() external payable {}
/**
* @notice Updates the whitelist access for a specific address.
*/
function setWhitelist(address target, bool status) external onlyOwner {
whitelist[target] = status;
emit WhitelistUpdated(target, status);
}
/**
* @notice Single point of entry. Initiates flash loan, auto-calculates max leverage,
* and sends remaining cDAI yield to the owner at the end of the TX.
*/
function executeAndSweepInOneTx(uint256 flashLoanAmount) external payable onlyWhitelisted {
require(msg.value > 0, "Must deposit initial capital");
address[] memory tokens = new address[](1);
tokens[0] = DAI;
uint256[] memory amounts = new uint256[](1);
amounts[0] = flashLoanAmount;
// Pass the native coin deposit value via context packaging
bytes memory userData = abi.encode(msg.value);
// 1. Trigger Flash loan
IBalancerVault(BALANCER_VAULT).flashLoan(address(this), tokens, amounts, userData);
// 5. Sweep remaining cDAI automatically after the flash loan loop resolves
uint256 remainingCDAI = IERC20(cDAI).balanceOf(address(this));
if (remainingCDAI > 0) {
IERC20(cDAI).transfer(owner, remainingCDAI);
emit YieldSwept(owner, remainingCDAI);
}
}
/**
* @notice Balancer callback context loop
*/
function receiveFlashLoan(
address[] calldata, /* tokens parameter name removed to silence compiler warning */
uint256[] calldata amounts,
uint256[] calldata feeAmounts,
bytes calldata userData
) external {
require(msg.sender == BALANCER_VAULT, "Only Vault");
uint256 nativeDeposit = abi.decode(userData, (uint256));
uint256 daiLoaned = amounts[0];
uint256 totalDaiToRepay = daiLoaned + feeAmounts[0];
// 2. Supply all capital as collateral
address[] memory markets = new address[](2);
markets[0] = cETH;
markets[1] = cDAI;
IComptroller(COMPTROLLER).enterMarkets(markets);
ICEther(cETH).mint{value: nativeDeposit}();
IERC20(DAI).approve(cDAI, daiLoaned);
require(ICDAI(cDAI).mint(daiLoaned) == 0, "cDAI mint failed");
// 3. Dynamic Calculation Step
// Get liquidity value (scaled by 1e18)
(uint256 err, uint256 liquidity, uint256 shortfall) = IComptroller(COMPTROLLER).getAccountLiquidity(address(this));
require(err == 0 && shortfall == 0 && liquidity > 0, "No borrow liquidity available");
// Get oracle price of DAI to translate liquidity value to raw DAI tokens
address oracleAddress = IComptroller(COMPTROLLER).oracle();
uint256 daiPrice = IPriceOracle(oracleAddress).getUnderlyingPrice(cDAI);
require(daiPrice > 0, "Invalid oracle price");
// Max token borrow capacity = (Liquidity * 1e18) / Price
// We add a safety multiplier (95 / 100) so we don't hit 100% capacity limit
uint256 calculatedMaxDaiBorrow = (liquidity * 10**18) / daiPrice;
uint256 safeDaiBorrowAmount = (calculatedMaxDaiBorrow * BORROW_SAFETY_FACTOR) / 100;
// Ensure calculated borrowing capacity is actually enough to settle the flash loan
require(safeDaiBorrowAmount >= totalDaiToRepay, "Collateral insufficient to cover loan cost");
// 4. Borrow calculated safe max amount and pay back flash loan
require(ICDAI(cDAI).borrow(safeDaiBorrowAmount) == 0, "Dynamic borrow failed");
IERC20(DAI).transfer(BALANCER_VAULT, totalDaiToRepay);
emit MaxLeverageExecuted(tx.origin, nativeDeposit, daiLoaned);
}
/**
* @notice Safety sweep function for extra loose ERC20 tokens.
*/
function sweepToken(address token) external onlyOwner {
uint256 balance = IERC20(token).balanceOf(address(this));
require(balance > 0, "No tokens to sweep");
IERC20(token).transfer(owner, balance);
emit YieldSwept(owner, balance);
}
/**
* @notice Safety sweep function for native PLS.
*/
function sweepPLS() external onlyOwner {
uint256 balance = address(this).balance;
require(balance > 0, "No PLS to sweep");
(bool success, ) = owner.call{value: balance}("");
require(success, "PLS sweep failed");
emit YieldSwept(owner, balance);
}
}