This file contains hidden or 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
let mesGenerated = | |
ethers.utils.solidityKeccak256( | |
['bytes'], | |
[ | |
ethers.utils.solidityPack( | |
['address', 'address'], | |
[refUser.address, user1] | |
) | |
] | |
) |
This file contains hidden or 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 processSignature(address userFrom, address userTo, bytes memory signature) external operatorOnly { | |
if (hasSignature(userTo)) { | |
return; | |
} | |
bytes32 message = formMessage(userFrom, userTo); | |
require(userFrom == recoverAddress(message, signature), "Invalid signature provided"); | |
signatures[userTo] = userFrom; | |
} |
This file contains hidden or 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 getSigner( | |
bytes32 message, | |
uint8 v, | |
bytes32 r, | |
bytes32 s | |
) internal pure returns (address) { | |
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, | |
"invalid signature 's' value"); | |
require(v == 27 || v == 28, "invalid signature 'v' value"); | |
address signer = ecrecover(hashMessage(message), v, r, s); |
This file contains hidden or 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 recoverAddress( | |
bytes32 message, | |
bytes memory signature | |
) internal pure returns (address) { | |
if (signature.length != 65) { | |
revert("invalid signature length"); | |
} | |
bytes32 r; | |
bytes32 s; | |
uint8 v; |
This file contains hidden or 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 hashMessage(bytes32 message) internal pure returns (bytes32) { | |
bytes memory prefix = "\x19Ethereum Signed Message:\n32"; | |
return keccak256(abi.encodePacked(prefix, message)); | |
} |
This file contains hidden or 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
///@notice Returns simple message - hashed concatenation of 2 addresses | |
///@param from - address from | |
///@param to - address to | |
///@return message in a form of hash | |
function formMessage(address from, address to) public pure | |
returns (bytes32) | |
{ | |
bytes32 message = keccak256(abi.encodePacked(from, to)); | |
return message; | |
} |
This file contains hidden or 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 multiStepWithdraw(uint256[4] memory _amounts) public { | |
address[4] memory stablecoins = ICurveFi_DepositY(curveFi_Deposit).underlying_coins(); | |
//Step 1 - Calculate amount of Curve LP-tokens to unstake | |
uint256 nWithdraw; | |
uint256 i; | |
for (i = 0; i < stablecoins.length; i++) { | |
nWithdraw = nWithdraw.add(normalize(stablecoins[i], _amounts[i])); | |
} | |
uint256 withdrawShares = calculateShares(nWithdraw); |
This file contains hidden or 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 multiStepDeposit(uint256[4] memory _amounts) public { | |
address[4] memory stablecoins = ICurveFi_DepositY(curveFi_Deposit).underlying_coins(); | |
for (uint256 i = 0; i < stablecoins.length; i++) { | |
IERC20(stablecoins[i]).safeTransferFrom(_msgSender(), address(this), _amounts[i]); | |
IERC20(stablecoins[i]).safeApprove(curveFi_Deposit, _amounts[i]); | |
} | |
//Step 1 - deposit stablecoins and get Curve.Fi LP tokens | |
ICurveFi_DepositY(curveFi_Deposit).add_liquidity(_amounts, 0); //0 to mint all Curve has to |
This file contains hidden or 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
contract IYERC20 { | |
//ERC20 functions | |
// | |
// | |
//Y-token functions | |
function deposit(uint256 amount) external; | |
function withdraw(uint256 shares) external; | |
function getPricePerFullShare() external view returns (uint256); |
This file contains hidden or 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
contract ICurveFi_Minter { | |
function mint(address gauge_addr) external; | |
function minted(address _for, address gauge_addr) external view returns(uint256); | |
function toggle_approve_mint(address minting_user) external; | |
function token() external view returns(address); | |
} |