Skip to content

Commit

Permalink
adds BSC deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
CelaPablo committed Jan 4, 2024
1 parent c4484f9 commit cb81298
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 40 deletions.
12 changes: 5 additions & 7 deletions contracts/AMM/PancakeAMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ contract PancakeAMM {
* @dev Get the quote for selling 1 unit of a token.
*/
function getTWAPrice() external view returns (uint256 amountOut) {
uint8 sweepDecimals = sweep.decimals();
uint8 baseDecimals = base.decimals();

uint256 price = ChainlinkLibrary.getPrice(
oracleBase,
sequencer,
oracleBaseUpdateFrequency
);
uint8 decimals = ChainlinkLibrary.getDecimals(oracleBase);

// Get the average price tick first
(int24 arithmeticMeanTick, ) = OracleLibrary.consult(pool, LOOKBACK);
Expand All @@ -125,8 +121,10 @@ contract PancakeAMM {
address(base)
);

amountOut = quote.mulDiv(price, 10 ** decimals);
if(sweepDecimals == baseDecimals) amountOut = amountOut.mulDiv(PRECISION, 10 ** baseDecimals);
uint8 quoteDecimals = base.decimals();
uint8 priceDecimals = ChainlinkLibrary.getDecimals(oracleBase);

amountOut = PRECISION.mulDiv(quote * price, 10 ** (quoteDecimals + priceDecimals));
}

function getPositions(uint256 tokenId)
Expand Down Expand Up @@ -222,7 +220,7 @@ contract PancakeAMM {
}

function setPool(address poolAddress) external {
require(msg.sender == sweep.owner(), "BalancerAMM: Not Governance");
require(msg.sender == sweep.owner(), "PancakeAMM: Not Governance");
pool = poolAddress;
}
}
3 changes: 1 addition & 2 deletions contracts/Balancer/PancakeMarketMaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,8 @@ contract PancakeMarketMaker is IERC721Receiver, Stabilizer {
*/
function showTicks() internal view returns (int24 minTick, int24 maxTick) {
uint8 decimals = sweep.decimals();
uint8 baseDecimals = usdx.decimals();
uint256 sweepPrice = sweep.targetPrice();
if(decimals == baseDecimals) sweepPrice = sweepPrice * ((10 ** baseDecimals) / PRECISION);
sweepPrice = sweepPrice * ((10 ** decimals) / PRECISION);

uint256 minPrice = (sweepPrice * 99) / 100;
uint256 maxPrice = (sweepPrice * 101) / 100;
Expand Down
14 changes: 6 additions & 8 deletions scripts/deploy/amms/pancake_amm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ async function main() {
[deployer] = await ethers.getSigners();

const sweep = tokens.sweep;
const usdc = tokens.usdc;
const oracle = chainlink.usdc_usd;;
const base = tokens.usdt;
const oracle = chainlink.usdt_usd;;
const frequency = 86400;
const sequencer = chainlink.sequencer;
const helper = deployments.liquidity_helper;
const fee = 100;

console.log("===========================================");
console.log("PANCAKE AMM PLUGIN DEPLOY");
Expand All @@ -20,10 +19,9 @@ async function main() {
console.log("Deployer:", deployer.address);
console.log("===========================================");
console.log("SWEEP:", sweep);
console.log("USDC:", usdc);
console.log("USDT:", base);
console.log("Sequencer:", sequencer);
console.log("Fee:", fee);
console.log("USDC/USD Chainlink Oracle:", oracle);
console.log("USDT/USD Chainlink Oracle:", oracle);
console.log("Oracle Frequency:", frequency);
console.log("Liquidity helper:", helper);
console.log("===========================================");
Expand All @@ -32,11 +30,11 @@ async function main() {
console.log("Deploying...");

const pancakeAMMInstance = await ethers.getContractFactory("PancakeAMM");
const amm = await pancakeAMMInstance.deploy(sweep, usdc, sequencer, fee, oracle, frequency, helper);
const amm = await pancakeAMMInstance.deploy(sweep, base, sequencer, oracle, frequency, helper);

console.log("===========================================");
console.log(`PancakeAMM Deployed to:${amm.address}`);
console.log(`\nnpx hardhat verify --network ${network.name} ${amm.address} ${sweep} ${usdc} ${sequencer} ${fee} ${oracle} ${frequency} ${helper}`);
console.log(`\nnpx hardhat verify --network ${network.name} ${amm.address} ${sweep} ${base} ${sequencer} ${oracle} ${frequency} ${helper}`);
}

main();
22 changes: 11 additions & 11 deletions scripts/deploy/assets/pancake_market_maker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const { ethers } = require("hardhat");
const { addresses } = require("../../../utils/address");
const { network, tokens, chainlink, deployments, wallets } = require("../../../utils/constants");
const { ask } = require("../../../utils/helper_functions");

async function main() {
[deployer] = await ethers.getSigners();
const assetName = 'Pancake Market Maker';
const sweep = addresses.sweep;
const usdc = addresses.usdc;
const liquidityHelper = addresses.liquidity_helper;
const oracleUsdc = addresses.oracle_usdc_usd;
const borrower = addresses.multisig;
const sweep = tokens.sweep;
const base = tokens.usdt;
const liquidityHelper = deployments.liquidity_helper;
const oracle = chainlink.usdt_usd;
const borrower = wallets.multisig;

console.log("===========================================");
console.log("PANCAKE MARKET MAKER ASSET DEPLOY");
Expand All @@ -19,9 +19,9 @@ async function main() {
console.log("===========================================");
console.log("Asset Name:", assetName);
console.log("SWEEP:", sweep);
console.log("USDC:", usdc);
console.log("USDC:", base);
console.log("Liquidity Helper:", liquidityHelper);
console.log("USDC/USD Chainlink Oracle:", oracleUsdc);
console.log("BASE/USD Chainlink Oracle:", oracle);
console.log("Borrower:", borrower);
console.log("===========================================");
const answer = (await ask("continue? y/n: "));
Expand All @@ -32,15 +32,15 @@ async function main() {
const stabilizer = await MarketMaker.deploy(
assetName,
sweep,
usdc,
base,
liquidityHelper,
oracleUsdc,
oracle,
borrower
);

console.log("===========================================");
console.log("MarketMaker deployed to: ", stabilizer.address);
console.log(`\nnpx hardhat verify --network ${network.name} ${stabilizer.address} "${assetName}" ${sweep} ${usdc} ${liquidityHelper} ${oracleUsdc} ${borrower}`);
console.log(`\nnpx hardhat verify --network ${network.name} ${stabilizer.address} "${assetName}" ${sweep} ${base} ${liquidityHelper} ${oracle} ${borrower}`);
}

main();
Expand Down
12 changes: 6 additions & 6 deletions scripts/deploy/pools/create_pancake_pool.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { ethers } = require('hardhat');
const { network, tokens, pancake } = require("../../../utils/constants");
const { getPriceAndData, ask } = require('../../../utils/helper_functions');
const { getPriceAndData, ask, toBN } = require('../../../utils/helper_functions');

async function main() {
const { token0, token1 } = getPriceAndData(tokens.sweep, tokens.usdc, 0, 0);
const { token0, token1 } = getPriceAndData(tokens.sweep, tokens.usdt, 0, 0);
const sqrtPriceX96 = toBN("79228162514264337593543950336", 0);
const FEE = 500;

Expand All @@ -12,10 +12,10 @@ async function main() {
console.log("===========================================");
console.log("Network:", network.name);
console.log("===========================================");
console.log("SWEEP:", tokens.sweep);
console.log("USDC:", tokens.usdc);
console.log("UniswapFactory:", pancake.factory);
console.log("UniswapPositionManager:", pancake.positions_manager);
console.log("TOKEN 0:", token0);
console.log("TOKEN 1:", token1);
console.log("PancakeFactory:", pancake.factory);
console.log("PancakePositionManager:", pancake.positions_manager);
console.log("sqrtPriceX96:", sqrtPriceX96);
console.log("FEE:", FEE);
console.log("Cardinality:", pancake.observationCardinality);
Expand Down
4 changes: 1 addition & 3 deletions scripts/deploy/utils/pancake_liquidity_helper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const { ethers } = require("hardhat");
const { network } = require("../../../utils/address");
const { network } = require("../../../utils/constants");
const { ask } = require("../../../utils/helper_functions");

async function main() {
[deployer] = await ethers.getSigners();


console.log("===========================================");
console.log("PANCAKE LIQUIDITY HELPER DEPLOY");
console.log("===========================================");
Expand All @@ -17,7 +16,6 @@ async function main() {
if(answer !== 'y'){ process.exit(); }
console.log("Creating...");


const LiquidityHelper = await ethers.getContractFactory("PancakeLiquidityHelper");
const liquidityHelper = await LiquidityHelper.deploy();

Expand Down
9 changes: 6 additions & 3 deletions utils/networks/bsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
sweep: '0xB88a5Ac00917a02d82c7cd6CEBd73E2852d43574',
sweepr: '0x89B1e7068bF8E3232dD8f16c35cAc45bDA584f4E',
usdc: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d',
usdt: '0x55d398326f99059fF775485246999027B3197955',
},

assets: {
Expand All @@ -35,6 +36,7 @@ module.exports = {

chainlink: {
usdc_usd: '0x51597f405303c4377e36123cbc172b13269ea163',
usdt_usd: '0xB97Ad0E74fa7d920791E90258A6E2085088b4320',
sequencer: '0x0000000000000000000000000000000000000000',
},

Expand All @@ -49,12 +51,13 @@ module.exports = {
balancer: '0xa884970F06Dda7BedD86829E14BeCa2c8fEd5220',
treasury: '0x7c9131d7E2bEdb29dA39503DD8Cf809739f047B3',
proposal_executor: '0xE7b247DBbb1bFdC8E223e78F9585ACF93Df297f5',
balancer_amm: '',
liquidity_helper: '',
pancake_amm: '0xa5Dd492674f8C68C89b403BDFd0e794db42f2b92',
liquidity_helper: '0xD50DC42d95407F271c1380AE2aCa3F327F4C1cca',
pancake_pool: '0x05668AcDa068038d4bb34cF1ee17b264099afB80',

assets: {
uniswap: '',
market_maker: '',
market_maker: '0x7685fc882c91936BF94974916cC410028F73C957',
usd_plus: '',
maple: '',
}
Expand Down

0 comments on commit cb81298

Please sign in to comment.