Giter VIP home page Giter VIP logo

pancake-smart-contracts's Introduction

Pancake Contracts 🥞

This repo contains all the contracts used in PancakeSwap. It is divided in independent projects where each of them contains its smart contracts, test environment and unique config files.

Existing projects

Project name Description Solidity version(s)
BSC Library Legacy implementation of BEP20/IBEP20/SafeBEP20. Not to be used for new contracts. 0.6.12
Cake Vault CAKE vault ("AutoPool") contract that allows auto-compounding for CAKE tokens. 0.6.12
Exchange Protocol Based on Uniswap V2, it combines peripheral and core trading and liquidity protocols. It also adds new features like zaps. 0.5.16 / 0.6.6 / 0.8.4
Farms and Pools Based on SushiSwap's MasterChef, it also includes stand-alone pools and pool deployer. 0.6.12
Farm Auctions System for community-based auctions for future CAKE farms. 0.8.4
IFO Initial Farm Offerings. 0.6.12
Lottery V2 Lottery system for CAKE built using Chainlink's VRF. 0.8.4
NFT Markets NFT marketplace for ERC721 tokens. 0.8.4
Pancake Squad Pancake Squad NFT collection. 0.8.4
Predictions Prediction protocol contract built using Chainlink's oracle. 0.6.12 (v1) / 0.8.4 (v2)
Profile, NFT, and Gamification Pancake Bunnies NFT, NFT factories, and Profile system. 0.6.12
SmartChef Factory SmartChef (a.k.a. Syrup Pools) Factory 0.6.12 (v1) / 0.8.4 (v2)

Create a new project

1 - Create a new folder inside projects
2 - Run yarn init

Commands inside the root package.json starting with lerna will run the corresponding command in each subproject.

pancake-smart-contracts's People

Contributors

chef-cheems avatar chefmist avatar chefsnoopy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pancake-smart-contracts's Issues

Access the history.

Hello.

I'd like some hints as to how to get the full history of rounds and bets (including amounts) from the blockchain.
Any information would be helpful.

I'm currently using https://thegraph.com/hosted-service/subgraph/pancakeswap/prediction-v2 but it's broken (things don't add up correctly).

I have my own BSC node so I can query that if needed, or I can call any API.

I just don't know exactly what to query and how.

Any help would be welcome (and rewarded).

Thanks!

运行不了

Normal cases for liquidity provision and zap ins
1) User adds liquidity to LP tokens
Balance tokenA: 0.000000780625765115
Balance WBNB: 0.0
Balance tokenC: 0.0
√ User completes zapIn with tokenA (pair tokenA/tokenC) (1925ms)
2) User completes zapIn with BNB (pair BNB/tokenC)
3) User completes zapInRebalancing with BNB (pair BNB/tokenC)
Balance tokenA: 0.000000780625765115
Balance WBNB: 0.0
Balance tokenC: 0.006099644004121424
√ User completes zapInRebalancing with tokens (tokenA/tokenC) (1864ms)
Balance tokenA: 0.0
Balance WBNB: 0.0
Balance tokenC: 0.0
√ User completes zapOut to token (tokenA/tokenC) (1403ms)
4) User completes zapOut to BNB (BNB/tokenC)
√ Zap estimation fail if wrong tokens (121ms)
√ Zap estimations work as expected (115ms)
5) Cannot zap if wrong direction/tokens used

5 passing (11s)
5 failing

  1. Contract: PancakeZapV1
    Normal cases for liquidity provision and zap ins
    User adds liquidity to LP tokens:
    Error: Returned error: insufficient funds for gas * price + value
    at Context. (test\PancakeZapV1.test.ts:157:42)
    at step (test\PancakeZapV1.test.ts:33:23)
    at Object.next (test\PancakeZapV1.test.ts:14:53)
    at fulfilled (test\PancakeZapV1.test.ts:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

  2. Contract: PancakeZapV1
    Normal cases for liquidity provision and zap ins
    User completes zapIn with BNB (pair BNB/tokenC):
    Error: Returned error: VM Exception while processing transaction: revert PancakeLibrary: INSUFFICIENT_LIQUIDITY
    at Context. (test\PancakeZapV1.test.ts:238:49)
    at step (test\PancakeZapV1.test.ts:33:23)
    at Object.next (test\PancakeZapV1.test.ts:14:53)
    at C:\Users\梦想之家\Desktop\pancake-smart-contracts-master\projects\exchange-protocol\test\PancakeZapV1.test.ts:8:71
    at new Promise ()
    at __awaiter (test\PancakeZapV1.test.ts:4:12)
    at Context. (test\PancakeZapV1.test.ts:362:24)

  3. Contract: PancakeZapV1
    Normal cases for liquidity provision and zap ins
    User completes zapInRebalancing with BNB (pair BNB/tokenC):
    Error: Returned error: VM Exception while processing transaction: revert
    at Context. (test\PancakeZapV1.test.ts:267:49)
    at step (test\PancakeZapV1.test.ts:33:23)
    at Object.next (test\PancakeZapV1.test.ts:14:53)
    at C:\Users\梦想之家\Desktop\pancake-smart-contracts-master\projects\exchange-protocol\test\PancakeZapV1.test.ts:8:71
    at new Promise ()
    at __awaiter (test\PancakeZapV1.test.ts:4:12)
    at Context. (test\PancakeZapV1.test.ts:414:24)

  4. Contract: PancakeZapV1
    Normal cases for liquidity provision and zap ins
    User completes zapOut to BNB (BNB/tokenC):
    Error: Returned error: VM Exception while processing transaction: revert
    at Context. (test\PancakeZapV1.test.ts:389:49)
    at step (test\PancakeZapV1.test.ts:33:23)
    at Object.next (test\PancakeZapV1.test.ts:14:53)
    at C:\Users\梦想之家\Desktop\pancake-smart-contracts-master\projects\exchange-protocol\test\PancakeZapV1.test.ts:8:71
    at new Promise ()
    at __awaiter (test\PancakeZapV1.test.ts:4:12)
    at Context. (test\PancakeZapV1.test.ts:577:24)

  5. Contract: PancakeZapV1
    Normal cases for liquidity provision and zap ins
    Cannot zap if wrong direction/tokens used:

    Wrong kind of exception received

    • expected - actual

    -ds-math-sub-underflow
    +Zap: Token not in LP

    at expectException (C:\Users\梦想之家\Desktop\pancake-smart-contracts-master\node_modules@openzeppelin\test-helpers\src\expectRevert.js:20:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.expectRevert (C:\Users\梦想之家\Desktop\pancake-smart-contracts-master\node_modules@openzeppelin\test-helpers\src\expectRevert.js:75:3)

image

interact with SmartRouter

Does pancake have an example of using swap interaction in a contract? Like uniswap's SwapExmaples?
I want to use my contract to interact with SmartRouter to add pools and swaps, but I can't find any documentation to help me!
https://docs.pancakeswap.finance/developers/smart-contracts/pancakeswap-exchange/v3-contracts
https://docs.uniswap.org/contracts/v3/guides/swaps/single-swaps

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.7.6;
pragma abicoder v2;

import '@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol';
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';

contract SwapExamples {
    // For the scope of these swap examples,
    // we will detail the design considerations when using
    // `exactInput`, `exactInputSingle`, `exactOutput`, and  `exactOutputSingle`.

    // It should be noted that for the sake of these examples, we purposefully pass in the swap router instead of inherit the swap router for simplicity.
    // More advanced example contracts will detail how to inherit the swap router safely.

    ISwapRouter public immutable swapRouter;

    // This example swaps DAI/WETH9 for single path swaps and DAI/USDC/WETH9 for multi path swaps.

    address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
    address public constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;

    // For this example, we will set the pool fee to 0.3%.
    uint24 public constant poolFee = 3000;

    constructor(ISwapRouter _swapRouter) {
        swapRouter = _swapRouter;
    }

    /// @notice swapExactInputSingle swaps a fixed amount of DAI for a maximum possible amount of WETH9
    /// using the DAI/WETH9 0.3% pool by calling `exactInputSingle` in the swap router.
    /// @dev The calling address must approve this contract to spend at least `amountIn` worth of its DAI for this function to succeed.
    /// @param amountIn The exact amount of DAI that will be swapped for WETH9.
    /// @return amountOut The amount of WETH9 received.
    function swapExactInputSingle(uint256 amountIn) external returns (uint256 amountOut) {
        // msg.sender must approve this contract

        // Transfer the specified amount of DAI to this contract.
        TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountIn);

        // Approve the router to spend DAI.
        TransferHelper.safeApprove(DAI, address(swapRouter), amountIn);

        // Naively set amountOutMinimum to 0. In production, use an oracle or other data source to choose a safer value for amountOutMinimum.
        // We also set the sqrtPriceLimitx96 to be 0 to ensure we swap our exact input amount.
        ISwapRouter.ExactInputSingleParams memory params =
            ISwapRouter.ExactInputSingleParams({
                tokenIn: DAI,
                tokenOut: WETH9,
                fee: poolFee,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountIn: amountIn,
                amountOutMinimum: 0,
                sqrtPriceLimitX96: 0
            });

        // The call to `exactInputSingle` executes the swap.
        amountOut = swapRouter.exactInputSingle(params);
    }

    /// @notice swapExactOutputSingle swaps a minimum possible amount of DAI for a fixed amount of WETH.
    /// @dev The calling address must approve this contract to spend its DAI for this function to succeed. As the amount of input DAI is variable,
    /// the calling address will need to approve for a slightly higher amount, anticipating some variance.
    /// @param amountOut The exact amount of WETH9 to receive from the swap.
    /// @param amountInMaximum The amount of DAI we are willing to spend to receive the specified amount of WETH9.
    /// @return amountIn The amount of DAI actually spent in the swap.
    function swapExactOutputSingle(uint256 amountOut, uint256 amountInMaximum) external returns (uint256 amountIn) {
        // Transfer the specified amount of DAI to this contract.
        TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountInMaximum);

        // Approve the router to spend the specifed `amountInMaximum` of DAI.
        // In production, you should choose the maximum amount to spend based on oracles or other data sources to acheive a better swap.
        TransferHelper.safeApprove(DAI, address(swapRouter), amountInMaximum);

        ISwapRouter.ExactOutputSingleParams memory params =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: DAI,
                tokenOut: WETH9,
                fee: poolFee,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountOut: amountOut,
                amountInMaximum: amountInMaximum,
                sqrtPriceLimitX96: 0
            });

        // Executes the swap returning the amountIn needed to spend to receive the desired amountOut.
        amountIn = swapRouter.exactOutputSingle(params);

        // For exact output swaps, the amountInMaximum may not have all been spent.
        // If the actual amount spent (amountIn) is less than the specified maximum amount, we must refund the msg.sender and approve the swapRouter to spend 0.
        if (amountIn < amountInMaximum) {
            TransferHelper.safeApprove(DAI, address(swapRouter), 0);
            TransferHelper.safeTransfer(DAI, msg.sender, amountInMaximum - amountIn);
        }
    }
}

License missing

I don't see license anywhere?
Is it allowed to use code (contracts and test code) in commercial projects?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.