Skip to content

Commit

Permalink
feat: Deprecated pools lens for binance
Browse files Browse the repository at this point in the history
  • Loading branch information
DeFIBrain88 committed May 9, 2024
1 parent 9be10f4 commit ee61947
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 5 deletions.
143 changes: 143 additions & 0 deletions contracts/powerindex-mining/DeprecatedBscPoolsLens.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 10 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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: {
Expand All @@ -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'),
Expand Down
17 changes: 17 additions & 0 deletions tasks/deployBscDeprecatedPoolsLens.js
Original file line number Diff line number Diff line change
@@ -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);
});
19 changes: 19 additions & 0 deletions test/DeprecatedBscPoolsLens.test.js
Original file line number Diff line number Diff line change
@@ -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)
}
});
2 changes: 1 addition & 1 deletion test/DeprecatedPoolsLens.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions verify-args.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
module.exports = [
'0xF09232320eBEAC33fae61b24bB8D7CA192E58507',
'0x38e4adB44ef08F22F5B5b76A8f0c2d0dCbE7DcA1',
'0x40E46dE174dfB776BB89E04dF1C47d8a66855EB3'
]

0 comments on commit ee61947

Please sign in to comment.