Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
Compound Redeem Function Giving False Transaction

I am trying to mint ceth from compound and redeem it. But the withdraw function in which I call redeem function of Compound is giving the following response. enter image description here

pragma solidity ^0.8.3;

interface cETH {

// define functions of COMPOUND we'll be using

function mint() external payable; // to deposit to compound
function redeem(uint redeemTokens) external returns (uint); // to withdraw from compound

//following 2 functions to determine how much you'll be able to withdraw
function exchangeRateStored() external view returns (uint); 
function balanceOf(address owner) external view returns (uint256 balance);

}

contract smartBankContract{ event MyLog(string, uint256);

address COMPOUND_CETH_ADDRESS = 0x859e9d8a4edadfEDb5A2fF311243af80F85A91b8;
cETH ceth = cETH(COMPOUND_CETH_ADDRESS);

uint totalContractBalance = 0; 
mapping(address => uint) balances;
mapping(address => uint) depositTimestamps;


function getContractBalance() public view returns(uint){
    return totalContractBalance;
}

function addBalance() public payable{
    uint balanceBefore = ceth.balanceOf(address(this));
    ceth.mint{value:msg.value}();
    uint balanceAfter = ceth.balanceOf(address(this));

    balances[msg.sender] = balanceAfter - balanceBefore;
    totalContractBalance = totalContractBalance + msg.value;
    depositTimestamps[msg.sender] = block.timestamp;

}

function getBalance(address user) public view returns(uint){
    return balances[user] * ceth.exchangeRateStored() / 1e18 ;
}

function getExchangeRate() public view returns(uint){
    return ceth.exchangeRateStored() / 1e18 ;
}

function getCethBalance(address user) public view returns(uint){
    return balances[user] ;
}


// function withdraw() public payable{

//     address payable withdrawTo = payable(msg.sender);
//     uint user_balance = getBalance(msg.sender);


//     uint redeemResult = ceth.redeem(getCethBalance(msg.sender));

//     emit MyLog("If this is not 0, there was an error", redeemResult);


//     withdrawTo.transfer((98*user_balance)/100);
//     totalContractBalance = totalContractBalance - user_balance;

//     balances[msg.sender] = 0;
// }

function withdraw() public payable {
    ceth.redeem((90*balances[msg.sender])/100);
    balances[msg.sender] = 0;
}

function addMoneyToContract() public payable {
    totalContractBalance += msg.value;
}

}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda