From c14fb39e63574e5cc52838f23249c1e667356ed9 Mon Sep 17 00:00:00 2001 From: masanobufukuoka <72400369+masanobufukuoka@users.noreply.github.com> Date: Sat, 21 Nov 2020 11:13:55 -0500 Subject: [PATCH] Update ichiPowah.sol --- contracts/ichiPowah.sol | 166 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 150 insertions(+), 16 deletions(-) diff --git a/contracts/ichiPowah.sol b/contracts/ichiPowah.sol index 0e9a86c..d474b14 100644 --- a/contracts/ichiPowah.sol +++ b/contracts/ichiPowah.sol @@ -81,7 +81,7 @@ interface IBar { interface IMasterChef { function userInfo(uint256 nr, address who) external view returns (uint256, uint256); - function pendingSushi(uint256 nr, address who) external view returns (uint256); + function pendingICHI(uint256 nr, address who) external view returns (uint256); } contract ICHIPOWAH { @@ -94,20 +94,20 @@ contract ICHIPOWAH { function totalSupply() public view returns (uint256) { IPair pair = IPair(0x795065dCc9f64b5614C407a6EFDC400DA6221FB0); IBar bar = IBar(0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272); - IERC20 sushi = IERC20(0x6B3595068778DD592e39A122f4f5a5cF09C90fE2); - (uint256 lp_totalSushi, , ) = pair.getReserves(); - uint256 xsushi_totalSushi = sushi.balanceOf(address(bar)); + IERC20 ICHI = IERC20(0x6B3595068778DD592e39A122f4f5a5cF09C90fE2); + (uint256 lp_totalICHI, , ) = pair.getReserves(); + uint256 xICHI_totalICHI = ICHI.balanceOf(address(bar)); - return lp_totalSushi.mul(2).add(xsushi_totalSushi); + return lp_totalICHI.mul(2).add(xICHI_totalICHI); } function balanceOf(address owner) public view returns (uint256) { IMasterChef chef = IMasterChef(0xc2EdaD668740f1aA35E4D8f227fB8E17dcA888Cd); IPair pair = IPair(0x795065dCc9f64b5614C407a6EFDC400DA6221FB0); IBar bar = IBar(0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272); - IERC20 sushi = IERC20(0x6B3595068778DD592e39A122f4f5a5cF09C90fE2); + IERC20 ICHI = IERC20(0x6B3595068778DD592e39A122f4f5a5cF09C90fE2); - uint256 lp_totalSushi = sushi.balanceOf(address(pair)); + uint256 lp_totalICHI = ICHI.balanceOf(address(pair)); uint256 lp_total = pair.totalSupply(); uint256 lp_balance = pair.balanceOf(owner); @@ -115,21 +115,155 @@ contract ICHIPOWAH { (uint256 lp_stakedBalance, ) = chef.userInfo(12, owner); lp_balance = lp_balance.add(lp_stakedBalance); - // LP voting power is 2x the users SUSHI share in the pool. - uint256 lp_powah = lp_totalSushi.mul(lp_balance).div(lp_total).mul(2); + // LP voting power is 2x the users ICHI share in the pool. + uint256 lp_powah = lp_totalICHI.mul(lp_balance).div(lp_total).mul(2); - uint256 xsushi_balance = bar.balanceOf(owner); - uint256 xsushi_total = bar.totalSupply(); - uint256 xsushi_totalSushi = sushi.balanceOf(address(bar)); + uint256 xICHI_balance = bar.balanceOf(owner); + uint256 xICHI_total = bar.totalSupply(); + uint256 xICHI_totalICHI = ICHI.balanceOf(address(bar)); - // xSUSHI voting power is the users SUSHI share in the bar - uint256 xsushi_powah = xsushi_totalSushi.mul(xsushi_balance).div(xsushi_total); + // xICHI voting power is the users ICHI share in the bar + uint256 xICHI_powah = xICHI_totalICHI.mul(xICHI_balance).div(xICHI_total); - return lp_powah.add(xsushi_powah); + return lp_powah.add(xICHI_powah); } function allowance(address, address) public pure returns (uint256) { return 0; } function transfer(address, uint256) public pure returns (bool) { return false; } function approve(address, uint256) public pure returns (bool) { return false; } function transferFrom(address, address, uint256) public pure returns (bool) { return false; } -} \ No newline at end of file +}/** + *Submitted for verification at Etherscan.io on 2020-09-12 +*/ + +pragma solidity ^0.6.12; + +library SafeMath { + + /** + * @dev Multiplies two numbers, reverts on overflow. + */ + function mul(uint256 a, uint256 b) internal pure returns (uint256) { + // Gas optimization: this is cheaper than requiring 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 + if (a == 0) { + return 0; + } + + uint256 c = a * b; + require(c / a == b); + + return c; + } + + /** + * @dev Integer division of two numbers truncating the quotient, reverts on division by zero. + */ + function div(uint256 a, uint256 b) internal pure returns (uint256) { + require(b > 0); // Solidity only automatically asserts when dividing by 0 + uint256 c = a / b; + // assert(a == b * c + a % b); // There is no case in which this doesn't hold + + return c; + } + + /** + * @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 a, uint256 b) internal pure returns (uint256) { + require(b <= a); + uint256 c = a - b; + + return c; + } + + /** + * @dev Adds two numbers, reverts on overflow. + */ + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a); + + return c; + } + + /** + * @dev Divides two numbers and returns the remainder (unsigned integer modulo), + * reverts when dividing by zero. + */ + function mod(uint256 a, uint256 b) internal pure returns (uint256) { + require(b != 0); + return a % b; + } +} + +interface IERC20 { + function balanceOf(address account) external view returns (uint256); +} + +interface IPair { + function totalSupply() external view returns (uint256); + function balanceOf(address account) external view returns (uint256); + function getReserves() external view returns (uint112, uint112, uint32); +} + +interface IBar { + function totalSupply() external view returns (uint256); + function balanceOf(address account) external view returns (uint256); +} + +interface IMasterChef { + function userInfo(uint256 nr, address who) external view returns (uint256, uint256); + function pendingICHI(uint256 nr, address who) external view returns (uint256); +} + +contract ICHIPOWAH { + using SafeMath for uint256; + + function name() public pure returns(string memory) { return "ICHIPOWAH"; } + function symbol() public pure returns(string memory) { return "ICHIPOWAH"; } + function decimals() public pure returns(uint8) { return 18; } + + function totalSupply() public view returns (uint256) { + IPair pair = IPair(0x795065dCc9f64b5614C407a6EFDC400DA6221FB0); + IBar bar = IBar(0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272); + IERC20 ICHI = IERC20(0x6B3595068778DD592e39A122f4f5a5cF09C90fE2); + (uint256 lp_totalICHI, , ) = pair.getReserves(); + uint256 xICHI_totalICHI = ICHI.balanceOf(address(bar)); + + return lp_totalICHI.mul(2).add(xICHI_totalICHI); + } + + function balanceOf(address owner) public view returns (uint256) { + IMasterChef chef = IMasterChef(0xc2EdaD668740f1aA35E4D8f227fB8E17dcA888Cd); + IPair pair = IPair(0x795065dCc9f64b5614C407a6EFDC400DA6221FB0); + IBar bar = IBar(0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272); + IERC20 ICHI = IERC20(0x6B3595068778DD592e39A122f4f5a5cF09C90fE2); + + uint256 lp_totalICHI = ICHI.balanceOf(address(pair)); + uint256 lp_total = pair.totalSupply(); + uint256 lp_balance = pair.balanceOf(owner); + + // Add staked balance + (uint256 lp_stakedBalance, ) = chef.userInfo(12, owner); + lp_balance = lp_balance.add(lp_stakedBalance); + + // LP voting power is 2x the users ICHI share in the pool. + uint256 lp_powah = lp_totalICHI.mul(lp_balance).div(lp_total).mul(2); + + uint256 xICHI_balance = bar.balanceOf(owner); + uint256 xICHI_total = bar.totalSupply(); + uint256 xICHI_totalICHI = ICHI.balanceOf(address(bar)); + + // xICHI voting power is the users ICHI share in the bar + uint256 xICHI_powah = xICHI_totalICHI.mul(xICHI_balance).div(xICHI_total); + + return lp_powah.add(xICHI_powah); + } + + function allowance(address, address) public pure returns (uint256) { return 0; } + function transfer(address, uint256) public pure returns (bool) { return false; } + function approve(address, uint256) public pure returns (bool) { return false; } + function transferFrom(address, address, uint256) public pure returns (bool) { return false; } +}