From ee61947c51b7001c7733b8ecb051b26ec57e2bd1 Mon Sep 17 00:00:00 2001 From: defibrain88 Date: Thu, 9 May 2024 15:07:29 +1000 Subject: [PATCH] feat: Deprecated pools lens for binance --- .../DeprecatedBscPoolsLens.sol | 143 ++++++++++++++++++ hardhat.config.js | 12 +- tasks/deployBscDeprecatedPoolsLens.js | 17 +++ test/DeprecatedBscPoolsLens.test.js | 19 +++ test/DeprecatedPoolsLens.test.js | 2 +- verify-args.js | 3 +- 6 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 contracts/powerindex-mining/DeprecatedBscPoolsLens.sol create mode 100644 tasks/deployBscDeprecatedPoolsLens.js create mode 100644 test/DeprecatedBscPoolsLens.test.js diff --git a/contracts/powerindex-mining/DeprecatedBscPoolsLens.sol b/contracts/powerindex-mining/DeprecatedBscPoolsLens.sol new file mode 100644 index 0000000..566ba64 --- /dev/null +++ b/contracts/powerindex-mining/DeprecatedBscPoolsLens.sol @@ -0,0 +1,143 @@ +/* +https://powerpool.finance/ + wrrrw r wrr + ppwr rrr wppr0 prwwwrp prwwwrp wr0 + rr 0rrrwrrprpwp0 pp pr prrrr0 pp 0r prrrr0 0rwrrr pp pr prrrr0 prrrr0 r0 + rrp pr wr00rrp prwww0 pp wr pp w00r prwwwpr 0rw prwww0 pp wr pp wr r0 + r0rprprwrrrp pr0 pp wr pr pp rwwr wr 0r pp wr pr wr pr r0 + prwr wrr0wpwr 00 www0 0w0ww www0 0w 00 www0 www0 0www0 + wrr ww0rrrr +*/ + +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.11; + +interface ILpToken { + function getBalance(address tokenAddress) external view returns (uint256); + function totalSupply() external view returns (uint256); + function allowance(address owner, address spender) external view returns(uint256); + function balanceOf(address wallet) external view returns (uint256); + function symbol() external view returns (string memory); + function decimals() external view returns (uint8); + function getFinalTokens() external view returns (address[] memory); + function getNormalizedWeight(address) external view returns (uint256); + function getSwapFee() external view returns (uint256); + function getCommunityFee() external view returns (Fees memory); +} + +struct EarnListItem { + address lpToken; + uint8 poolType; + uint256 pid; + uint256 totalSupply; + uint256 userTotalBalance; // user wallet balance + user mining balance + PartOfThePool[] tokensDistribution; +} + +struct PartOfThePool { + address tokenAddress; + string symbol; + uint256 percent; +} + +struct LiquidityTokens { + address tokenAddress; + uint256 balance; + uint8 decimals; + string symbol; + uint256 tokenAmountForOneLpMulti; +} + +struct Fees { + uint256 communitySwapFee; + uint256 communityJoinFee; + uint256 communityExitFee; + address communityFeeReceiver; +} + +struct RemoveLiquidityData { + address lpToken; + uint8 poolType; + uint256 pid; + string symbol; + uint256 balance; + uint256 allowance; + Fees fees; + LiquidityTokens[] tokens; +} + +contract DeprecatedBscPoolsLens { + ILpToken public singlePool; + + constructor(ILpToken _pool) { + singlePool = _pool; + } + + function getEarnList(address _user) external view returns (EarnListItem[] memory) { + EarnListItem[] memory earnPools = new EarnListItem[](1); + ILpToken pool = singlePool; + + earnPools[0] = EarnListItem({ + lpToken: address(pool), + poolType: 0, + pid: 0, + totalSupply: pool.totalSupply(), + tokensDistribution: new PartOfThePool[](pool.getFinalTokens().length), + userTotalBalance: 0 + }); + + EarnListItem memory earnPool = earnPools[0]; + + // User balance + if (_user != address(0)) { + earnPool.userTotalBalance = pool.balanceOf(_user); + } + + // get tokens percents + address[] memory finalTokens = pool.getFinalTokens(); + for (uint8 j = 0; j < finalTokens.length; j++) { + earnPool.tokensDistribution[j] = PartOfThePool({ + tokenAddress: finalTokens[j], + symbol: ILpToken(finalTokens[j]).symbol(), + percent: pool.getNormalizedWeight(finalTokens[j]) + }); + } + + return earnPools; + } + + function removeLiquidityInfo(address _user, uint256 _pid) external view returns (RemoveLiquidityData memory) { + ILpToken pool = singlePool; + LiquidityTokens[] memory tokens = new LiquidityTokens[](pool.getFinalTokens().length); + + for (uint8 i = 0; i < pool.getFinalTokens().length; i++) { + LiquidityTokens memory token = tokens[i]; + + token.tokenAddress = pool.getFinalTokens()[i]; + token.balance = ILpToken(pool.getFinalTokens()[i]).balanceOf(_user); + token.decimals = ILpToken(pool.getFinalTokens()[i]).decimals(); + token.symbol = ILpToken(pool.getFinalTokens()[i]).symbol(); + token.tokenAmountForOneLpMulti = getMultiTokensOut(token.tokenAddress, token.decimals); + } + + return RemoveLiquidityData({ + lpToken: address(pool), + poolType: 0, + pid: _pid, + symbol: pool.symbol(), + balance: pool.balanceOf(_user), + allowance: pool.allowance(_user, address(pool)), + fees: pool.getCommunityFee(), + tokens: tokens + }); + } + + function getMultiTokensOut(address _tokenAddress, uint8 _decimals) internal view returns (uint256) { + ILpToken pool = singlePool; + uint256 totalSupply = pool.totalSupply(); + uint256 reserve = pool.getBalance(_tokenAddress); + + return (((1 ether * 10**18) / totalSupply) * (reserve * 10**(18 - _decimals))) / 10**18; + } +} diff --git a/hardhat.config.js b/hardhat.config.js index f598d18..5e4356b 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -12,6 +12,7 @@ require('./tasks/deployMainnetPowerIndexPool'); require('./tasks/deployErc20PiptSwap'); require('./tasks/deployPoolsLens'); require('./tasks/deployDeprecatedPoolsLens'); +require('./tasks/deployBscDeprecatedPoolsLens'); require('./tasks/testMainnetErc20PiptSwap'); require('./tasks/deployPoolRestrictions'); require('./tasks/deployMainnetYeti'); @@ -72,14 +73,14 @@ const config = { }, networks: { hardhat: { - chainId: 1, + chainId: 56, accounts: testAccounts, allowUnlimitedContractSize: true, gas: 12000000, loggingEnabled: true, blockGasLimit: 12000000, forking: { - url: 'https://mainnet-eth.powerpool.finance', + url: 'https://divine-icy-yard.bsc.quiknode.pro/1ec99ee8099d558029e893df069f138441e17e80/', }, }, ganache: { @@ -94,6 +95,13 @@ const config = { gasMultiplier: 1.2, timeout: 2000000, }, + binance: { + url: 'https://divine-icy-yard.bsc.quiknode.pro/1ec99ee8099d558029e893df069f138441e17e80/', + accounts: getAccounts('binance'), + gasPrice: 10 ** 9, + gasMultiplier: 1.2, + timeout: 2000000, + }, sepolia: { url: 'https://rpc.sepolia.org', accounts: getAccounts('sepolia'), diff --git a/tasks/deployBscDeprecatedPoolsLens.js b/tasks/deployBscDeprecatedPoolsLens.js new file mode 100644 index 0000000..11e810f --- /dev/null +++ b/tasks/deployBscDeprecatedPoolsLens.js @@ -0,0 +1,17 @@ +require('@nomiclabs/hardhat-truffle5'); + + +task('deploy-bsc-deprecated-pools-lens', 'Deploy deprecated pools lens').setAction(async (__, {network}) => { + const PoolsLens = artifacts.require('DeprecatedBscPoolsLens'); + + const { web3 } = PoolsLens; + + const [deployer] = await web3.eth.getAccounts(); + console.log('deployer', deployer); + const sendOptions = { from: deployer }; + const poolsLens = await PoolsLens.new( + '0x40E46dE174dfB776BB89E04dF1C47d8a66855EB3', + sendOptions, + ); + console.log('Deprecated bsc pools lens deployed address: ', poolsLens.address); +}); diff --git a/test/DeprecatedBscPoolsLens.test.js b/test/DeprecatedBscPoolsLens.test.js new file mode 100644 index 0000000..8fb677b --- /dev/null +++ b/test/DeprecatedBscPoolsLens.test.js @@ -0,0 +1,19 @@ +// const { expectRevert, time } = require('@openzeppelin/test-helpers'); +const { ethers} = require('hardhat'); +const PoolsLens = artifacts.require('DeprecatedBscPoolsLens'); +const zeroAddress = '0x0000000000000000000000000000000000000000'; + +describe.only('DeprecatedBscPoolsLens', async () => { + try { + it('chore test pass', async () => { + this.poolsLens = await PoolsLens.new( + '0x40E46dE174dfB776BB89E04dF1C47d8a66855EB3' + ); + // const result = await this.poolsLens.getEarnList('0x8b19f6F51501dA80FCEFb578427907f223005F7A'); + const result = await this.poolsLens.removeLiquidityInfo('0x8b19f6F51501dA80FCEFb578427907f223005F7A', 0); + console.log('main: ', result); + }); + } catch (e) { + console.error(e) + } +}); diff --git a/test/DeprecatedPoolsLens.test.js b/test/DeprecatedPoolsLens.test.js index f705c60..83e9b72 100644 --- a/test/DeprecatedPoolsLens.test.js +++ b/test/DeprecatedPoolsLens.test.js @@ -3,7 +3,7 @@ const { ethers} = require('hardhat'); const PoolsLens = artifacts.require('DeprecatedPoolsLens'); const zeroAddress = '0x0000000000000000000000000000000000000000'; -describe.only('DeprecatedPoolsLens', async () => { +describe('DeprecatedPoolsLens', async () => { try { it('chore test pass', async () => { this.poolsLens = await PoolsLens.new( diff --git a/verify-args.js b/verify-args.js index 5e8019a..cdb9574 100644 --- a/verify-args.js +++ b/verify-args.js @@ -1,4 +1,3 @@ module.exports = [ - '0xF09232320eBEAC33fae61b24bB8D7CA192E58507', - '0x38e4adB44ef08F22F5B5b76A8f0c2d0dCbE7DcA1', + '0x40E46dE174dfB776BB89E04dF1C47d8a66855EB3' ]