Last active
February 11, 2020 02:33
-
-
Save ajb413/4f438c3d6430ddbf9ea1d1a4889c3e5e to your computer and use it in GitHub Desktop.
snippet from my Solidity smart contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function supplyErc20ToCompound( | |
address _erc20Contract, | |
address _cErc20Contract, | |
uint256 _numTokensToSupply | |
) public returns (uint) { | |
// Create a reference to the underlying asset contract, like DAI. | |
Erc20 underlying = Erc20(_erc20Contract); | |
// Create a reference to the corresponding cToken contract, like cDAI | |
CErc20 cToken = CErc20(_cErc20Contract); | |
// Approve transfer on the ERC20 contract | |
underlying.approve(_cErc20Contract, _numTokensToSupply); | |
// Mint cTokens and return the result | |
uint mintResult = cToken.mint(_numTokensToSupply); | |
return mintResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment