├── projects ├── masterchef-v3 │ ├── .prettierignore │ ├── deployments │ │ ├── eth.json │ │ ├── goerli.json │ │ ├── hardhat.json │ │ ├── bscMainnet.json │ │ └── bscTestnet.json │ ├── .gitignore │ ├── .eslintrc │ ├── contracts │ │ ├── interfaces │ │ │ ├── IReceiver.sol │ │ │ ├── ILMPoolDeployer.sol │ │ │ ├── IMasterChefV3.sol │ │ │ ├── IWETH.sol │ │ │ ├── ILMPool.sol │ │ │ ├── IPancakeV3Pool.sol │ │ │ ├── IFarmBooster.sol │ │ │ ├── IMasterChefV2.sol │ │ │ └── INonfungiblePositionManagerStruct.sol │ │ └── utils │ │ │ └── Multicall.sol │ ├── docs │ │ ├── interfaces │ │ │ ├── ILMPoolDeployer.md │ │ │ ├── IWETH.md │ │ │ ├── IMasterChefV3.md │ │ │ ├── ILMPool.md │ │ │ ├── IPancakeV3Pool.md │ │ │ ├── IFarmBooster.md │ │ │ ├── INonfungiblePositionManagerStruct.md │ │ │ └── IMasterChefV2.md │ │ ├── utils │ │ │ └── Multicall.md │ │ └── Enumerable.md │ ├── tsconfig.json │ ├── .prettierrc │ ├── config.ts │ ├── test │ │ └── TestLiquidityAmounts.sol │ └── scripts │ │ └── verify.ts ├── v3-core │ ├── .yarnrc │ ├── .gitattributes │ ├── arguments.js │ ├── .gitignore │ ├── .prettierrc │ ├── .solhint.json │ ├── _audits │ │ ├── abdk │ │ │ └── audit.pdf │ │ ├── tob │ │ │ ├── audit.pdf │ │ │ └── contracts │ │ │ │ └── crytic │ │ │ │ ├── echidna │ │ │ │ ├── Other.config.yaml │ │ │ │ ├── E2E_swap.config.yaml │ │ │ │ ├── E2E_mint_burn.config.yaml │ │ │ │ └── Other.sol │ │ │ │ └── manticore │ │ │ │ ├── 003.sol │ │ │ │ ├── 001.sol │ │ │ │ └── 002.sol │ │ └── slowmist │ │ │ └── audit.pdf │ ├── test │ │ ├── __snapshots__ │ │ │ ├── NoDelegateCall.spec.ts.snap │ │ │ ├── LiquidityMath.spec.ts.snap │ │ │ ├── PancakeV3Factory.spec.ts.snap │ │ │ ├── BitMath.spec.ts.snap │ │ │ ├── SwapMath.spec.ts.snap │ │ │ ├── SqrtPriceMath.spec.ts.snap │ │ │ └── TickBitmap.spec.ts.snap │ │ └── shared │ │ │ ├── expect.ts │ │ │ ├── format.ts │ │ │ ├── snapshotGasCost.ts │ │ │ └── checkObservationEquals.ts │ ├── deployments │ │ ├── eth.json │ │ ├── goerli.json │ │ ├── bscMainnet.json │ │ ├── bscTestnet.json │ │ └── hardhat.json │ ├── docs │ │ ├── test │ │ │ ├── OutputCodeHash.md │ │ │ ├── UnsafeMathEchidnaTest.md │ │ │ ├── TickEchidnaTest.md │ │ │ ├── SwapMathEchidnaTest.md │ │ │ ├── TestPancakeV3ReentrantCallee.md │ │ │ ├── FullMathTest.md │ │ │ ├── LiquidityMathTest.md │ │ │ ├── BitMathEchidnaTest.md │ │ │ ├── TickBitmapEchidnaTest.md │ │ │ ├── TickMathEchidnaTest.md │ │ │ ├── TestPancakeV3SwapPay.md │ │ │ ├── FullMathEchidnaTest.md │ │ │ ├── SwapMathTest.md │ │ │ ├── LowGasSafeMathEchidnaTest.md │ │ │ ├── BitMathTest.md │ │ │ ├── TickOverflowSafetyEchidnaTest.md │ │ │ ├── MockTimePancakeV3Pool.md │ │ │ ├── TickBitmapTest.md │ │ │ ├── TickMathTest.md │ │ │ └── MockTimePancakeV3PoolDeployer.md │ │ ├── libraries │ │ │ ├── FixedPoint128.md │ │ │ ├── FixedPoint96.md │ │ │ ├── LiquidityMath.md │ │ │ ├── TransferHelper.md │ │ │ └── UnsafeMath.md │ │ └── interfaces │ │ │ ├── IPancakeV3Pool.md │ │ │ ├── callback │ │ │ ├── IPancakeV3MintCallback.md │ │ │ ├── IPancakeV3FlashCallback.md │ │ │ └── IPancakeV3SwapCallback.md │ │ │ └── IPancakeV3PoolDeployer.md │ ├── scripts │ │ ├── computeV3InitCodeHash.ts │ │ ├── verify.ts │ │ └── deploy_outputCodeHash.ts │ ├── contracts │ │ ├── libraries │ │ │ ├── FixedPoint128.sol │ │ │ ├── FixedPoint96.sol │ │ │ ├── LiquidityMath.sol │ │ │ ├── UnsafeMath.sol │ │ │ ├── TransferHelper.sol │ │ │ └── SafeCast.sol │ │ ├── test │ │ │ ├── OutputCodeHash.sol │ │ │ ├── UnsafeMathEchidnaTest.sol │ │ │ ├── LiquidityMathTest.sol │ │ │ ├── FullMathTest.sol │ │ │ ├── BitMathEchidnaTest.sol │ │ │ ├── MockTimePancakeV3Pool.sol │ │ │ ├── BitMathTest.sol │ │ │ ├── TickMathEchidnaTest.sol │ │ │ ├── TickEchidnaTest.sol │ │ │ ├── SwapMathTest.sol │ │ │ ├── MockTimePancakeV3PoolDeployer.sol │ │ │ ├── LowGasSafeMathEchidnaTest.sol │ │ │ └── TickMathTest.sol │ │ └── interfaces │ │ │ ├── IPancakeV3Pool.sol │ │ │ └── callback │ │ │ ├── IPancakeV3FlashCallback.sol │ │ │ └── IPancakeV3MintCallback.sol │ ├── tsconfig.json │ └── .github │ │ ├── workflows │ │ ├── lint.yml │ │ └── tests.yml │ │ └── stale.yml ├── v3-periphery │ ├── .prettierignore │ ├── .yarnrc │ ├── .gitattributes │ ├── .gitignore │ ├── .prettierrc │ ├── .solhint.json │ ├── docs │ │ ├── test │ │ │ ├── SelfPermitTest.md │ │ │ ├── TestERC20.md │ │ │ ├── TestERC20Metadata.md │ │ │ ├── PeripheryImmutableStateTest.md │ │ │ ├── TickLensTest.md │ │ │ ├── TestCallbackValidation.md │ │ │ ├── Base64Test.md │ │ │ ├── PoolTicksCounterTest.md │ │ │ ├── NonfungiblePositionManagerPositionsGasTest.md │ │ │ ├── PoolAddressTest.md │ │ │ ├── MockObservable.md │ │ │ ├── MockTimeSwapRouter.md │ │ │ ├── PathTest.md │ │ │ ├── MockTimeNonfungiblePositionManager.md │ │ │ ├── TestMulticall.md │ │ │ ├── TestPositionNFTOwner.md │ │ │ ├── PositionValueTest.md │ │ │ ├── TestERC20PermitAllowed.md │ │ │ └── MockObservations.md │ │ ├── base │ │ │ ├── PeripheryValidation.md │ │ │ ├── BlockTimestamp.md │ │ │ ├── PeripheryImmutableState.md │ │ │ ├── Multicall.md │ │ │ ├── PeripheryPaymentsWithFee.md │ │ │ └── PoolInitializer.md │ │ ├── libraries │ │ │ ├── PositionKey.md │ │ │ ├── ChainId.md │ │ │ ├── BytesLib.md │ │ │ ├── TokenRatioSortOrder.md │ │ │ ├── HexStrings.md │ │ │ └── PoolTicksCounter.md │ │ ├── interfaces │ │ │ ├── external │ │ │ │ ├── IWETH9.md │ │ │ │ ├── IERC1271.md │ │ │ │ └── IERC20PermitAllowed.md │ │ │ ├── IMulticall.md │ │ │ ├── IERC20Metadata.md │ │ │ ├── INonfungibleTokenPositionDescriptor.md │ │ │ ├── IPeripheryImmutableState.md │ │ │ ├── IPeripheryPaymentsWithFee.md │ │ │ └── IPoolInitializer.md │ │ ├── lens │ │ │ ├── TickLens.md │ │ │ └── PancakeInterfaceMulticall.md │ │ ├── NonfungibleTokenPositionDescriptorOffChain.md │ │ └── V3Migrator.md │ ├── test │ │ ├── __snapshots__ │ │ │ ├── Path.spec.ts.snap │ │ │ ├── PairFlash.spec.ts.snap │ │ │ ├── SwapRouter.spec.ts.snap │ │ │ ├── V3Migrator.spec.ts.snap │ │ │ ├── OracleLibrary.spec.ts.snap │ │ │ ├── PeripheryImmutableState.spec.ts.snap │ │ │ ├── Multicall.spec.ts.snap │ │ │ ├── TickLens.spec.ts.snap │ │ │ ├── PoolAddress.spec.ts.snap │ │ │ ├── PositionValue.spec.ts.snap │ │ │ ├── LiquidityAmounts.spec.ts.snap │ │ │ └── Base64.spec.ts.snap │ │ └── shared │ │ │ ├── expandTo18Decimals.ts │ │ │ ├── expect.ts │ │ │ ├── base64.ts │ │ │ ├── extractJSONFromURI.ts │ │ │ ├── constants.ts │ │ │ ├── tokenSort.ts │ │ │ ├── poolAtAddress.ts │ │ │ ├── ticks.ts │ │ │ ├── encodePriceSqrt.ts │ │ │ ├── computePoolAddress.ts │ │ │ ├── formatSqrtRatioX96.ts │ │ │ └── snapshotGasCost.ts │ ├── audits │ │ └── abdk │ │ │ └── audit.pdf │ ├── contracts │ │ ├── lens │ │ │ └── README.md │ │ ├── test │ │ │ ├── SelfPermitTest.sol │ │ │ ├── TestERC20.sol │ │ │ ├── PeripheryImmutableStateTest.sol │ │ │ ├── TestERC20Metadata.sol │ │ │ ├── TestCallbackValidation.sol │ │ │ ├── Base64Test.sol │ │ │ ├── MockTimeSwapRouter.sol │ │ │ ├── TickLensTest.sol │ │ │ ├── PoolTicksCounterTest.sol │ │ │ ├── NonfungiblePositionManagerPositionsGasTest.sol │ │ │ ├── MockTimeNonfungiblePositionManager.sol │ │ │ ├── TestMulticall.sol │ │ │ ├── TestERC20PermitAllowed.sol │ │ │ ├── TestPositionNFTOwner.sol │ │ │ ├── PoolAddressTest.sol │ │ │ └── PathTest.sol │ │ ├── base │ │ │ ├── PeripheryValidation.sol │ │ │ ├── BlockTimestamp.sol │ │ │ ├── PeripheryImmutableState.sol │ │ │ └── Multicall.sol │ │ ├── libraries │ │ │ ├── ChainId.sol │ │ │ ├── TokenRatioSortOrder.sol │ │ │ └── PositionKey.sol │ │ ├── interfaces │ │ │ ├── external │ │ │ │ ├── IWETH9.sol │ │ │ │ └── IERC1271.sol │ │ │ ├── IPeripheryImmutableState.sol │ │ │ ├── IERC20Metadata.sol │ │ │ ├── IMulticall.sol │ │ │ ├── INonfungibleTokenPositionDescriptor.sol │ │ │ ├── ITickLens.sol │ │ │ ├── IPoolInitializer.sol │ │ │ └── IPeripheryPaymentsWithFee.sol │ │ └── NonfungibleTokenPositionDescriptorOffChain.sol │ ├── util │ │ └── necessary │ │ │ ├── constants.ts │ │ │ ├── tokenSort.ts │ │ │ └── ticks.ts │ ├── tsconfig.json │ ├── deployments │ │ ├── eth.json │ │ ├── bscMainnet.json │ │ ├── bscTestnet.json │ │ ├── goerli.json │ │ └── hardhat.json │ ├── .github │ │ ├── workflows │ │ │ ├── lint.yml │ │ │ └── tests.yml │ │ └── stale.yml │ └── scripts │ │ ├── deployNonfungibleTokenDescriptorOffChainV2.ts │ │ └── upgradeNonfungibleTokenDescriptorOffChainV2.ts ├── router │ ├── docs │ │ ├── interfaces │ │ │ ├── ISmartRouter.md │ │ │ ├── IStableSwapInfo.md │ │ │ ├── IWETH.md │ │ │ ├── IImmutableState.md │ │ │ ├── IStableSwap.md │ │ │ ├── IStableSwapFactory.md │ │ │ ├── IPeripheryPaymentsWithFeeExtended.md │ │ │ └── IStableSwapRouter.md │ │ ├── base │ │ │ ├── PeripheryValidationExtended.md │ │ │ ├── ImmutableState.md │ │ │ └── PeripheryPaymentsWithFeeExtended.md │ │ ├── SmartRouter.md │ │ └── libraries │ │ │ ├── Constants.md │ │ │ └── PoolTicksCounter.md │ ├── contracts │ │ ├── lens │ │ │ └── README.md │ │ ├── interfaces │ │ │ ├── IWETH.sol │ │ │ ├── IStableSwapInfo.sol │ │ │ ├── IImmutableState.sol │ │ │ ├── ISmartRouter.sol │ │ │ ├── IStableSwap.sol │ │ │ ├── IStableSwapFactory.sol │ │ │ └── IStableSwapRouter.sol │ │ ├── base │ │ │ ├── PeripheryValidationExtended.sol │ │ │ ├── ImmutableState.sol │ │ │ ├── MulticallExtended.sol │ │ │ └── PeripheryPaymentsWithFeeExtended.sol │ │ ├── libraries │ │ │ └── Constants.sol │ │ └── SmartRouter.sol │ ├── deployments │ │ ├── eth.json │ │ ├── goerli.json │ │ ├── bscMainnet.json │ │ ├── bscTestnet.json │ │ └── hardhat.json │ └── .solcover.js └── v3-lm-pool │ ├── deployments │ ├── eth.json │ ├── goerli.json │ ├── bscMainnet.json │ ├── bscTestnet.json │ └── hardhat.json │ ├── .gitignore │ ├── contracts │ └── interfaces │ │ ├── IPancakeV3LmPoolDeveloper.sol │ │ ├── IPancakeV3LmPool.sol │ │ └── IMasterChefV3.sol │ ├── tsconfig.json │ ├── README.md │ ├── scripts │ └── verify.ts │ └── package.json ├── .prettierrc ├── .env.example ├── .prettierignore ├── common ├── sleep.ts └── package.json ├── .gitignore ├── package.json ├── README.md ├── v3-verify.mjs └── deployments ├── eth.json ├── goerli.json ├── bscMainnet.json ├── bscTestnet.json └── hardhat.json /projects/masterchef-v3/.prettierignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /projects/v3-core/.yarnrc: -------------------------------------------------------------------------------- 1 | ignore-scripts true 2 | -------------------------------------------------------------------------------- /projects/v3-periphery/.prettierignore: -------------------------------------------------------------------------------- 1 | .github -------------------------------------------------------------------------------- /projects/v3-periphery/.yarnrc: -------------------------------------------------------------------------------- 1 | ignore-scripts true 2 | -------------------------------------------------------------------------------- /projects/v3-core/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /projects/v3-periphery/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /projects/v3-core/arguments.js: -------------------------------------------------------------------------------- 1 | module.exports = ['0xB0edb49557c583290368e04FffaBb293FC224Ae1']; -------------------------------------------------------------------------------- /projects/router/docs/interfaces/ISmartRouter.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## ISmartRouter 4 | 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "printWidth": 120 5 | } 6 | -------------------------------------------------------------------------------- /projects/v3-core/.gitignore: -------------------------------------------------------------------------------- 1 | artifacts/ 2 | cache/ 3 | crytic-export/ 4 | node_modules/ 5 | typechain/ 6 | -------------------------------------------------------------------------------- /projects/v3-periphery/.gitignore: -------------------------------------------------------------------------------- 1 | artifacts/ 2 | cache/ 3 | crytic-export/ 4 | node_modules/ 5 | typechain/ -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # bscTesnet 2 | KEY_TESTNET= 3 | KEY_MAINNET= 4 | KEY_ETH= 5 | KEY_GOERLI= 6 | ETHERSCAN_API_KEY= -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | projects/**/masterchef-v2/ 2 | projects/bsc-library/ 3 | projects/exchange-protocol/ 4 | .github -------------------------------------------------------------------------------- /projects/v3-core/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "printWidth": 120 5 | } 6 | -------------------------------------------------------------------------------- /projects/masterchef-v3/deployments/eth.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x556B9306565093C855AEA9AE92A594704c2Cd59e" 3 | } -------------------------------------------------------------------------------- /projects/v3-periphery/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "printWidth": 120 5 | } 6 | -------------------------------------------------------------------------------- /projects/masterchef-v3/deployments/goerli.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x864ED564875BdDD6F421e226494a0E7c071C06f8" 3 | } -------------------------------------------------------------------------------- /projects/masterchef-v3/deployments/hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x5FbDB2315678afecb367f032d93F642f64180aa3" 3 | } -------------------------------------------------------------------------------- /common/sleep.ts: -------------------------------------------------------------------------------- 1 | export function sleep(ms: number) { 2 | return new Promise((resolve) => setTimeout(resolve, ms)) 3 | } 4 | -------------------------------------------------------------------------------- /projects/masterchef-v3/deployments/bscMainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x556B9306565093C855AEA9AE92A594704c2Cd59e" 3 | } -------------------------------------------------------------------------------- /projects/masterchef-v3/deployments/bscTestnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x4c650FB471fe4e0f476fD3437C3411B1122c4e3B" 3 | } -------------------------------------------------------------------------------- /projects/v3-lm-pool/deployments/eth.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3LmPoolDeployer": "0x769449da49D1Eb1FF44A6B366BE46960fDF46Ad6" 3 | } -------------------------------------------------------------------------------- /projects/v3-lm-pool/deployments/goerli.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3LmPoolDeployer": "0x556B9306565093C855AEA9AE92A594704c2Cd59e" 3 | } -------------------------------------------------------------------------------- /projects/v3-lm-pool/deployments/bscMainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3LmPoolDeployer": "0x769449da49D1Eb1FF44A6B366BE46960fDF46Ad6" 3 | } -------------------------------------------------------------------------------- /projects/v3-lm-pool/deployments/bscTestnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3LmPoolDeployer": "0x864ED564875BdDD6F421e226494a0E7c071C06f8" 3 | } -------------------------------------------------------------------------------- /projects/v3-lm-pool/deployments/hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3LmPoolDeployer": "0x5FbDB2315678afecb367f032d93F642f64180aa3" 3 | } -------------------------------------------------------------------------------- /projects/v3-core/.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["prettier"], 3 | "rules": { 4 | "prettier/prettier": "error" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /projects/v3-periphery/.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": ["prettier"], 3 | "rules": { 4 | "prettier/prettier": "error" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /projects/masterchef-v3/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | **/artifacts/ 3 | **/cache/ 4 | **/abi 5 | **/typechain 6 | .idea 7 | .vscode 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/abdk/audit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pancakeswap/pancake-v3-contracts/HEAD/projects/v3-core/_audits/abdk/audit.pdf -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/audit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pancakeswap/pancake-v3-contracts/HEAD/projects/v3-core/_audits/tob/audit.pdf -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/SelfPermitTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## SelfPermitTest 4 | 5 | _Same as SelfPermit but not abstract_ 6 | 7 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/Path.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Path gas cost 1`] = `451`; 4 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/slowmist/audit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pancakeswap/pancake-v3-contracts/HEAD/projects/v3-core/_audits/slowmist/audit.pdf -------------------------------------------------------------------------------- /projects/v3-periphery/audits/abdk/audit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pancakeswap/pancake-v3-contracts/HEAD/projects/v3-periphery/audits/abdk/audit.pdf -------------------------------------------------------------------------------- /projects/masterchef-v3/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@pancakeswap/eslint-config-pancake", 3 | "rules": { 4 | "import/no-extraneous-dependencies": 0 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /projects/router/contracts/lens/README.md: -------------------------------------------------------------------------------- 1 | # lens 2 | 3 | These contracts are not designed to be called on-chain. They simplify 4 | fetching on-chain data from off-chain. 5 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/NoDelegateCall.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`NoDelegateCall runtime overhead 1`] = `30`; 4 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/PairFlash.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`PairFlash test flash gas 1`] = `380086`; 4 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/SwapRouter.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SwapRouter bytecode size 1`] = `12244`; 4 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/V3Migrator.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`V3Migrator #migrate gas 1`] = `732912`; 4 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/lens/README.md: -------------------------------------------------------------------------------- 1 | # lens 2 | 3 | These contracts are not designed to be called on-chain. They simplify 4 | fetching on-chain data from off-chain. 5 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | coverage 4 | coverage.json 5 | typechain 6 | typechain-types 7 | 8 | # Hardhat files 9 | cache 10 | artifacts 11 | 12 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/OracleLibrary.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`OracleLibrary #getQuoteAtTick gas test 1`] = `1205`; 4 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/PeripheryImmutableState.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`PeripheryImmutableState bytecode size 1`] = `245`; 4 | -------------------------------------------------------------------------------- /projects/v3-core/deployments/eth.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 3 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9" 4 | } -------------------------------------------------------------------------------- /projects/v3-core/deployments/goerli.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 3 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9" 4 | } -------------------------------------------------------------------------------- /projects/v3-core/deployments/bscMainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 3 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9" 4 | } -------------------------------------------------------------------------------- /projects/v3-core/deployments/bscTestnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 3 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9" 4 | } -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TestERC20.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestERC20 4 | 5 | ### constructor 6 | 7 | ```solidity 8 | constructor(uint256 amountToMint) public 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/base/PeripheryValidation.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PeripheryValidation 4 | 5 | ### checkDeadline 6 | 7 | ```solidity 8 | modifier checkDeadline(uint256 deadline) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/OutputCodeHash.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## OutputCodeHash 4 | 5 | ### getInitCodeHash 6 | 7 | ```solidity 8 | function getInitCodeHash() public pure returns (bytes32) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/expandTo18Decimals.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'ethers' 2 | 3 | export function expandTo18Decimals(n: number): BigNumber { 4 | return BigNumber.from(n).mul(BigNumber.from(10).pow(18)) 5 | } 6 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/echidna/Other.config.yaml: -------------------------------------------------------------------------------- 1 | checkAsserts: true 2 | coverage: true 3 | codeSize: 0x60000 4 | corpusDir: echidna_other_corpus 5 | seqLen: 1000 6 | testLimit: 100000 7 | timeout: 3600 # 1 hour 8 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/LiquidityMath.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`LiquidityMath #addDelta gas add 1`] = `138`; 4 | 5 | exports[`LiquidityMath #addDelta gas sub 1`] = `152`; 6 | -------------------------------------------------------------------------------- /common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pancakeswap/common", 3 | "private": true, 4 | "version": "0.0.0", 5 | "scripts": { 6 | "compile": "echo 'No compile needed'", 7 | "test": "echo 'No test needed'" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/IReceiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IReceiver { 5 | function upkeep(uint256 amount, uint256 duration, bool withUpdate) external; 6 | } 7 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TestERC20Metadata.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestERC20Metadata 4 | 5 | ### constructor 6 | 7 | ```solidity 8 | constructor(uint256 amountToMint, string name, string symbol) public 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/UnsafeMathEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## UnsafeMathEchidnaTest 4 | 5 | ### checkDivRoundingUp 6 | 7 | ```solidity 8 | function checkDivRoundingUp(uint256 x, uint256 d) external pure 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/Multicall.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Multicall gas cost of pay w/ multicall 1`] = `45845`; 4 | 5 | exports[`Multicall gas cost of pay w/o multicall 1`] = `43342`; 6 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/ILMPoolDeployer.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## ILMPoolDeployer 4 | 5 | ### deploy 6 | 7 | ```solidity 8 | function deploy(contract IPancakeV3Pool pool) external returns (contract ILMPool lmPool) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/router/docs/base/PeripheryValidationExtended.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PeripheryValidationExtended 4 | 5 | ### checkPreviousBlockhash 6 | 7 | ```solidity 8 | modifier checkPreviousBlockhash(bytes32 previousBlockhash) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/PeripheryImmutableStateTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PeripheryImmutableStateTest 4 | 5 | ### constructor 6 | 7 | ```solidity 8 | constructor(address _deployer, address _factory, address _WETH9) public 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-core/deployments/hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "PancakeV3Factory": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", 3 | "PancakeV3PoolDeployer": "0x5FbDB2315678afecb367f032d93F642f64180aa3", 4 | "PancakeV3FactoryOwner": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" 5 | } -------------------------------------------------------------------------------- /projects/v3-core/test/shared/expect.ts: -------------------------------------------------------------------------------- 1 | import { expect, use } from 'chai' 2 | import { solidity } from 'ethereum-waffle' 3 | import { jestSnapshotPlugin } from 'mocha-chai-jest-snapshot' 4 | 5 | use(solidity) 6 | use(jestSnapshotPlugin()) 7 | 8 | export { expect } 9 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TickEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickEchidnaTest 4 | 5 | ### checkTickSpacingToParametersInvariants 6 | 7 | ```solidity 8 | function checkTickSpacingToParametersInvariants(int24 tickSpacing) external pure 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/expect.ts: -------------------------------------------------------------------------------- 1 | import { expect, use } from 'chai' 2 | import { solidity } from 'ethereum-waffle' 3 | import { jestSnapshotPlugin } from 'mocha-chai-jest-snapshot' 4 | 5 | use(solidity) 6 | use(jestSnapshotPlugin()) 7 | 8 | export { expect } 9 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IStableSwapInfo.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IStableSwapInfo 4 | 5 | ### get_dx 6 | 7 | ```solidity 8 | function get_dx(address _swap, uint256 i, uint256 j, uint256 dy, uint256 max_dx) external view returns (uint256) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-core/docs/libraries/FixedPoint128.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## FixedPoint128 4 | 5 | A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | 7 | ### Q128 8 | 9 | ```solidity 10 | uint256 Q128 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /projects/v3-core/scripts/computeV3InitCodeHash.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'hardhat' 2 | import PancakeV3PoolArtifact from '../artifacts/contracts/PancakeV3Pool.sol/PancakeV3Pool.json' 3 | 4 | const hash = ethers.utils.keccak256(PancakeV3PoolArtifact.bytecode) 5 | console.log(hash) 6 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/SelfPermitTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../base/SelfPermit.sol'; 5 | 6 | /// @dev Same as SelfPermit but not abstract 7 | contract SelfPermitTest is SelfPermit { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/base64.ts: -------------------------------------------------------------------------------- 1 | export function base64Encode(str: string): string { 2 | return Buffer.from(str, 'utf8').toString('base64') 3 | } 4 | 5 | export function base64Decode(str: string): string { 6 | return Buffer.from(str, 'base64').toString('utf8') 7 | } 8 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/contracts/interfaces/IPancakeV3LmPoolDeveloper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | interface IPancakeV3LmPoolDeveloper { 5 | function parameters() external view returns (address pool, address masterChef); 6 | } 7 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/TickLens.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`TickLens #getPopulatedTicksInWord fully populated ticks 1`] = `2807707`; 4 | 5 | exports[`TickLens #getPopulatedTicksInWord gas for single populated tick 1`] = `55657`; 6 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TickLensTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickLensTest 4 | 5 | ### getGasCostOfGetPopulatedTicksInWord 6 | 7 | ```solidity 8 | function getGasCostOfGetPopulatedTicksInWord(address pool, int16 tickBitmapIndex) external view returns (uint256) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/utils/Multicall.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## Multicall 4 | 5 | Enables calling multiple methods in a single call to the contract 6 | 7 | ### multicall 8 | 9 | ```solidity 10 | function multicall(bytes[] data) public payable returns (bytes[] results) 11 | ``` 12 | 13 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/PoolAddress.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`PoolAddress #computeAddress gas cost 1`] = `642`; 4 | 5 | exports[`PoolAddress #computeAddress matches example from core repo 1`] = `"0xb6bFB8F9f42d29E8D8b194D75999419fEbb91329"`; 6 | -------------------------------------------------------------------------------- /projects/router/docs/SmartRouter.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## SmartRouter 4 | 5 | ### constructor 6 | 7 | ```solidity 8 | constructor(address _factoryV2, address _deployer, address _factoryV3, address _positionManager, address _stableFactory, address _stableInfo, address _WETH9) public 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/contracts/interfaces/IPancakeV3LmPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | interface IPancakeV3LmPool { 5 | function accumulateReward(uint32 currTimestamp) external; 6 | 7 | function crossLmTick(int24 tick, bool zeroForOne) external; 8 | } 9 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/PancakeV3Factory.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`PancakeV3Factory #createPool gas 1`] = `4729417`; 4 | 5 | exports[`PancakeV3Factory factory bytecode size 1`] = `5151`; 6 | 7 | exports[`PancakeV3Factory pool bytecode size 1`] = `22962`; 8 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2020", 4 | "module": "commonjs", 5 | "esModuleInterop": true, 6 | "forceConsistentCasingInFileNames": true, 7 | "strict": true, 8 | "skipLibCheck": true, 9 | "resolveJsonModule": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/masterchef-v3/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2020", 4 | "module": "commonjs", 5 | "esModuleInterop": true, 6 | "forceConsistentCasingInFileNames": true, 7 | "strict": true, 8 | "skipLibCheck": true, 9 | "resolveJsonModule": true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/libraries/PositionKey.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PositionKey 4 | 5 | ### compute 6 | 7 | ```solidity 8 | function compute(address owner, int24 tickLower, int24 tickUpper) internal pure returns (bytes32) 9 | ``` 10 | 11 | _Returns the key of the position in the core library_ 12 | 13 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TestCallbackValidation.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestCallbackValidation 4 | 5 | ### verifyCallback 6 | 7 | ```solidity 8 | function verifyCallback(address factory, address tokenA, address tokenB, uint24 fee) external view returns (contract IPancakeV3Pool pool) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/ILMPoolDeployer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "./IPancakeV3Pool.sol"; 5 | import "./ILMPool.sol"; 6 | 7 | interface ILMPoolDeployer { 8 | function deploy(IPancakeV3Pool pool) external returns (ILMPool lmPool); 9 | } 10 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/echidna/E2E_swap.config.yaml: -------------------------------------------------------------------------------- 1 | checkAsserts: true 2 | coverage: true 3 | codeSize: 0x60000 4 | corpusDir: echidna_e2e_swap_corpus 5 | seqLen: 10 6 | testLimit: 100000 7 | timeout: 3600 # 1 hour 8 | 9 | # blacklist 10 | filterFunctions: ['E2E_swap.viewRandomInit(uint128)'] 11 | -------------------------------------------------------------------------------- /projects/v3-core/docs/interfaces/IPancakeV3Pool.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPancakeV3Pool 4 | 5 | A PancakeSwap pool facilitates swapping and automated market making between any two assets that strictly conform 6 | to the ERC20 specification 7 | 8 | _The pool interface is broken up into many smaller pieces_ 9 | 10 | -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/IWETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | interface IWETH { 5 | function deposit() external payable; 6 | 7 | function transfer(address to, uint256 value) external returns (bool); 8 | 9 | function withdraw(uint256) external; 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/SwapMathEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## SwapMathEchidnaTest 4 | 5 | ### checkComputeSwapStepInvariants 6 | 7 | ```solidity 8 | function checkComputeSwapStepInvariants(uint160 sqrtPriceRaw, uint160 sqrtPriceTargetRaw, uint128 liquidity, int256 amountRemaining, uint24 feePips) external pure 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/Base64Test.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## Base64Test 4 | 5 | ### encode 6 | 7 | ```solidity 8 | function encode(bytes data) external pure returns (string) 9 | ``` 10 | 11 | ### getGasCostOfEncode 12 | 13 | ```solidity 14 | function getGasCostOfEncode(bytes data) external view returns (uint256) 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/PoolTicksCounterTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PoolTicksCounterTest 4 | 5 | ### countInitializedTicksCrossed 6 | 7 | ```solidity 8 | function countInitializedTicksCrossed(contract IPancakeV3Pool pool, int24 tickBefore, int24 tickAfter) external view returns (uint32 initializedTicksCrossed) 9 | ``` 10 | 11 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/manticore/003.sol: -------------------------------------------------------------------------------- 1 | import '../../../../../contracts/libraries/LiquidityMath.sol'; 2 | 3 | contract VerifyLiquidityMathAddDelta { 4 | function verify(uint128 x, int128 y) external { 5 | uint256 z = LiquidityMath.addDelta(x, y); 6 | 7 | require(z != x + uint128(y)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/extractJSONFromURI.ts: -------------------------------------------------------------------------------- 1 | export function extractJSONFromURI(uri: string): { name: string; description: string; image: string } { 2 | const encodedJSON = uri.substr('data:application/json;base64,'.length) 3 | const decodedJSON = Buffer.from(encodedJSON, 'base64').toString('utf8') 4 | return JSON.parse(decodedJSON) 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | **/artifacts/ 3 | **/cache/ 4 | **/typechain/ 5 | **/typechain-types/ 6 | **/data/abi 7 | **/abi 8 | **/coverage 9 | **/coverage.json 10 | **/.env 11 | .idea 12 | .vscode 13 | .DS_Store 14 | bytecode 15 | dist 16 | projects/masterchef-v3/abi/@openzeppelin/contracts/access/Ownable.sol/Ownable.json 17 | projects/router/test/debug.ts -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TestPancakeV3ReentrantCallee.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestPancakeV3ReentrantCallee 4 | 5 | ### swapToReenter 6 | 7 | ```solidity 8 | function swapToReenter(address pool) external 9 | ``` 10 | 11 | ### pancakeV3SwapCallback 12 | 13 | ```solidity 14 | function pancakeV3SwapCallback(int256, int256, bytes) external 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/contracts/interfaces/IMasterChefV3.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | interface IMasterChefV3 { 5 | function nonfungiblePositionManager() external view returns (address); 6 | 7 | function getLatestPeriodInfo(address _v3Pool) external view returns (uint256 cakePerSecond, uint256 endTime); 8 | } 9 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/IWETH.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IWETH 4 | 5 | ### deposit 6 | 7 | ```solidity 8 | function deposit() external payable 9 | ``` 10 | 11 | Deposit ether to get wrapped ether 12 | 13 | ### withdraw 14 | 15 | ```solidity 16 | function withdraw(uint256) external 17 | ``` 18 | 19 | Withdraw wrapped ether to get ether 20 | 21 | -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/IStableSwapInfo.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | interface IStableSwapInfo { 6 | function get_dx( 7 | address _swap, 8 | uint256 i, 9 | uint256 j, 10 | uint256 dy, 11 | uint256 max_dx 12 | ) external view returns (uint256); 13 | } 14 | -------------------------------------------------------------------------------- /projects/router/deployments/eth.json: -------------------------------------------------------------------------------- 1 | { 2 | "SmartRouter": "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", 3 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 4 | "MixedRouteQuoterV1": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86", 5 | "QuoterV2": "0x4c650FB471fe4e0f476fD3437C3411B1122c4e3B", 6 | "TokenValidator": "0x864ED564875BdDD6F421e226494a0E7c071C06f8" 7 | } -------------------------------------------------------------------------------- /projects/router/deployments/goerli.json: -------------------------------------------------------------------------------- 1 | { 2 | "SmartRouter": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 3 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 4 | "MixedRouteQuoterV1": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 5 | "QuoterV2": "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", 6 | "TokenValidator": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86" 7 | } -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/external/IWETH9.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IWETH9 4 | 5 | ### deposit 6 | 7 | ```solidity 8 | function deposit() external payable 9 | ``` 10 | 11 | Deposit ether to get wrapped ether 12 | 13 | ### withdraw 14 | 15 | ```solidity 16 | function withdraw(uint256) external 17 | ``` 18 | 19 | Withdraw wrapped ether to get ether 20 | 21 | -------------------------------------------------------------------------------- /projects/masterchef-v3/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "overrides": [ 4 | { 5 | "files": "*.sol", 6 | "options": { 7 | "printWidth": 120, 8 | "tabWidth": 4, 9 | "useTabs": false, 10 | "singleQuote": false, 11 | "bracketSpacing": false, 12 | "explicitTypes": "always" 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /projects/router/deployments/bscMainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "SmartRouter": "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", 3 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 4 | "MixedRouteQuoterV1": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86", 5 | "QuoterV2": "0x4c650FB471fe4e0f476fD3437C3411B1122c4e3B", 6 | "TokenValidator": "0x864ED564875BdDD6F421e226494a0E7c071C06f8" 7 | } -------------------------------------------------------------------------------- /projects/router/deployments/bscTestnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "SmartRouter": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 3 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 4 | "MixedRouteQuoterV1": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 5 | "QuoterV2": "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", 6 | "TokenValidator": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86" 7 | } -------------------------------------------------------------------------------- /projects/router/deployments/hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "SmartRouter": "0x5579c645590c58E6421341394f82B5b38080cDEA", 3 | "SmartRouterHelper": "0xA2b9C533b5333c1fEc593DA3Dbe1229627490622", 4 | "MixedRouteQuoterV1": "0x0a7DE23cF80aBA83Ca5d4a429D80E1224b3dCC91", 5 | "QuoterV2": "0x9163fe1E8448c237d5e7CEbF428EbA3015841869", 6 | "TokenValidator": "0x023108300557958e6eEf0DCc69e2D3804A6F13a1" 7 | } -------------------------------------------------------------------------------- /projects/v3-core/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/FullMathTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## FullMathTest 4 | 5 | ### mulDiv 6 | 7 | ```solidity 8 | function mulDiv(uint256 x, uint256 y, uint256 z) external pure returns (uint256) 9 | ``` 10 | 11 | ### mulDivRoundingUp 12 | 13 | ```solidity 14 | function mulDivRoundingUp(uint256 x, uint256 y, uint256 z) external pure returns (uint256) 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/LiquidityMathTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## LiquidityMathTest 4 | 5 | ### addDelta 6 | 7 | ```solidity 8 | function addDelta(uint128 x, int128 y) external pure returns (uint128 z) 9 | ``` 10 | 11 | ### getGasCostOfAddDelta 12 | 13 | ```solidity 14 | function getGasCostOfAddDelta(uint128 x, int128 y) external view returns (uint256) 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-core/docs/libraries/FixedPoint96.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## FixedPoint96 4 | 5 | A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | 7 | _Used in SqrtPriceMath.sol_ 8 | 9 | ### RESOLUTION 10 | 11 | ```solidity 12 | uint8 RESOLUTION 13 | ``` 14 | 15 | ### Q96 16 | 17 | ```solidity 18 | uint256 Q96 19 | ``` 20 | 21 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/BitMathEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## BitMathEchidnaTest 4 | 5 | ### mostSignificantBitInvariant 6 | 7 | ```solidity 8 | function mostSignificantBitInvariant(uint256 input) external pure 9 | ``` 10 | 11 | ### leastSignificantBitInvariant 12 | 13 | ```solidity 14 | function leastSignificantBitInvariant(uint256 input) external pure 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TestERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '@openzeppelin/contracts/drafts/ERC20Permit.sol'; 5 | 6 | contract TestERC20 is ERC20Permit { 7 | constructor(uint256 amountToMint) ERC20('Test ERC20', 'TEST') ERC20Permit('Test ERC20') { 8 | _mint(msg.sender, amountToMint); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/libraries/ChainId.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## ChainId 4 | 5 | ### get 6 | 7 | ```solidity 8 | function get() internal pure returns (uint256 chainId) 9 | ``` 10 | 11 | _Gets the current chain ID_ 12 | 13 | #### Return Values 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | chainId | uint256 | The current chain ID | 18 | 19 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TickBitmapEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickBitmapEchidnaTest 4 | 5 | ### flipTick 6 | 7 | ```solidity 8 | function flipTick(int24 tick) external 9 | ``` 10 | 11 | ### checkNextInitializedTickWithinOneWordInvariants 12 | 13 | ```solidity 14 | function checkNextInitializedTickWithinOneWordInvariants(int24 tick, bool lte) external view 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IWETH.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IWETH 4 | 5 | ### deposit 6 | 7 | ```solidity 8 | function deposit() external payable 9 | ``` 10 | 11 | ### transfer 12 | 13 | ```solidity 14 | function transfer(address to, uint256 value) external returns (bool) 15 | ``` 16 | 17 | ### withdraw 18 | 19 | ```solidity 20 | function withdraw(uint256) external 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/manticore/001.sol: -------------------------------------------------------------------------------- 1 | import '../../../../../contracts/libraries/BitMath.sol'; 2 | 3 | contract VerifyBitMathMsb { 4 | function verify(uint256 x) external { 5 | uint256 msb = BitMath.mostSignificantBit(x); 6 | 7 | bool property = x >= 2**msb && (msb == 255 || x < 2**(msb + 1)); 8 | 9 | require(!property); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/base/PeripheryValidation.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | import './BlockTimestamp.sol'; 5 | 6 | abstract contract PeripheryValidation is BlockTimestamp { 7 | modifier checkDeadline(uint256 deadline) { 8 | require(_blockTimestamp() <= deadline, 'Transaction too old'); 9 | _; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/PeripheryImmutableStateTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | import '../base/PeripheryImmutableState.sol'; 5 | 6 | contract PeripheryImmutableStateTest is PeripheryImmutableState { 7 | constructor(address _deployer, address _factory, address _WETH9) PeripheryImmutableState(_deployer, _factory, _WETH9) {} 8 | } 9 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/IMasterChefV3.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IMasterChefV3 { 5 | function latestPeriodEndTime() external view returns (uint256); 6 | 7 | function latestPeriodStartTime() external view returns (uint256); 8 | 9 | function upkeep(uint256 amount, uint256 duration, bool withUpdate) external; 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TickMathEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickMathEchidnaTest 4 | 5 | ### checkGetSqrtRatioAtTickInvariants 6 | 7 | ```solidity 8 | function checkGetSqrtRatioAtTickInvariants(int24 tick) external pure 9 | ``` 10 | 11 | ### checkGetTickAtSqrtRatioInvariants 12 | 13 | ```solidity 14 | function checkGetTickAtSqrtRatioInvariants(uint160 ratio) external pure 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/OutputCodeHash.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import "../PancakeV3Pool.sol"; 6 | 7 | contract OutputCodeHash { 8 | function getInitCodeHash() public pure returns(bytes32){ 9 | bytes memory bytecode = type(PancakeV3Pool).creationCode; 10 | return keccak256(abi.encodePacked(bytecode)); 11 | } 12 | } -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/constants.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'ethers' 2 | 3 | export const MaxUint128 = BigNumber.from(2).pow(128).sub(1) 4 | 5 | export enum FeeAmount { 6 | LOW = 500, 7 | MEDIUM = 2500, 8 | HIGH = 10000, 9 | } 10 | 11 | export const TICK_SPACINGS: { [amount in FeeAmount]: number } = { 12 | [FeeAmount.LOW]: 10, 13 | [FeeAmount.MEDIUM]: 50, 14 | [FeeAmount.HIGH]: 200, 15 | } 16 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/tokenSort.ts: -------------------------------------------------------------------------------- 1 | export function compareToken(a: { address: string }, b: { address: string }): -1 | 1 { 2 | return a.address.toLowerCase() < b.address.toLowerCase() ? -1 : 1 3 | } 4 | 5 | export function sortedTokens( 6 | a: { address: string }, 7 | b: { address: string } 8 | ): [typeof a, typeof b] | [typeof b, typeof a] { 9 | return compareToken(a, b) < 0 ? [a, b] : [b, a] 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/util/necessary/constants.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from "ethers"; 2 | 3 | export const MaxUint128 = BigNumber.from(2).pow(128).sub(1); 4 | 5 | export enum FeeAmount { 6 | LOW = 500, 7 | MEDIUM = 2500, 8 | HIGH = 10000, 9 | } 10 | 11 | export const TICK_SPACINGS: { [amount in FeeAmount]: number } = { 12 | [FeeAmount.LOW]: 10, 13 | [FeeAmount.MEDIUM]: 50, 14 | [FeeAmount.HIGH]: 200, 15 | }; 16 | -------------------------------------------------------------------------------- /projects/v3-periphery/util/necessary/tokenSort.ts: -------------------------------------------------------------------------------- 1 | export function compareToken(a: { address: string }, b: { address: string }): -1 | 1 { 2 | return a.address.toLowerCase() < b.address.toLowerCase() ? -1 : 1; 3 | } 4 | 5 | export function sortedTokens( 6 | a: { address: string }, 7 | b: { address: string } 8 | ): [typeof a, typeof b] | [typeof b, typeof a] { 9 | return compareToken(a, b) < 0 ? [a, b] : [b, a]; 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/poolAtAddress.ts: -------------------------------------------------------------------------------- 1 | import { abi as POOL_ABI } from '@pancakeswap/v3-core/artifacts/contracts/PancakeV3Pool.sol/PancakeV3Pool.json' 2 | import { Contract, Wallet } from 'ethers' 3 | import { IPancakeV3Pool } from '../../typechain-types' 4 | 5 | export default function poolAtAddress(address: string, wallet: Wallet): IPancakeV3Pool { 6 | return new Contract(address, POOL_ABI, wallet) as IPancakeV3Pool 7 | } 8 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TestPancakeV3SwapPay.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestPancakeV3SwapPay 4 | 5 | ### swap 6 | 7 | ```solidity 8 | function swap(address pool, address recipient, bool zeroForOne, uint160 sqrtPriceX96, int256 amountSpecified, uint256 pay0, uint256 pay1) external 9 | ``` 10 | 11 | ### pancakeV3SwapCallback 12 | 13 | ```solidity 14 | function pancakeV3SwapCallback(int256, int256, bytes data) external 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-core/test/shared/format.ts: -------------------------------------------------------------------------------- 1 | import { Decimal } from 'decimal.js' 2 | import { BigNumberish } from 'ethers' 3 | 4 | export function formatTokenAmount(num: BigNumberish): string { 5 | return new Decimal(num.toString()).dividedBy(new Decimal(10).pow(18)).toPrecision(5) 6 | } 7 | 8 | export function formatPrice(price: BigNumberish): string { 9 | return new Decimal(price.toString()).dividedBy(new Decimal(2).pow(96)).pow(2).toPrecision(5) 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "resolveJsonModule": true, 8 | "outDir": "dist", 9 | "typeRoots": ["./typechain", "./node_modules/@types"], 10 | "types": ["@nomiclabs/hardhat-ethers", "@nomiclabs/hardhat-waffle"] 11 | }, 12 | "include": ["./test"], 13 | "files": ["./hardhat.config.ts"] 14 | } 15 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/libraries/ChainId.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Function for getting the current chain ID 5 | library ChainId { 6 | /// @dev Gets the current chain ID 7 | /// @return chainId The current chain ID 8 | function get() internal pure returns (uint256 chainId) { 9 | assembly { 10 | chainId := chainid() 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/IWETH.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | /// @title Interface for WETH9 7 | interface IWETH is IERC20 { 8 | /// @notice Deposit ether to get wrapped ether 9 | function deposit() external payable; 10 | 11 | /// @notice Withdraw wrapped ether to get ether 12 | function withdraw(uint256) external; 13 | } 14 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/libraries/TokenRatioSortOrder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | library TokenRatioSortOrder { 5 | int256 constant NUMERATOR_MOST = 300; 6 | int256 constant NUMERATOR_MORE = 200; 7 | int256 constant NUMERATOR = 100; 8 | 9 | int256 constant DENOMINATOR_MOST = -300; 10 | int256 constant DENOMINATOR_MORE = -200; 11 | int256 constant DENOMINATOR = -100; 12 | } 13 | -------------------------------------------------------------------------------- /projects/router/.solcover.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | skipFiles: [ 3 | "libraries/Babylonian.sol", 4 | "libraries/Math.sol", 5 | "libraries/PancakeLibrary.sol", 6 | "libraries/SafeMath.sol", 7 | "libraries/UQ112x112.sol", 8 | "libraries/WBNB.sol", 9 | "PancakeERC20.sol", 10 | "PancakeFactory.sol", 11 | "PancakePair.sol", 12 | "PancakeRouter.sol", 13 | "PancakeRouter01.sol", 14 | "utils/MockERC20.sol", 15 | ], 16 | }; 17 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/README.md: -------------------------------------------------------------------------------- 1 | # v3-lm-pool 2 | 3 | Liquidity Mining Pool (LM Pool) is a separate contract for liquidity mining 4 | reward accounting. 5 | It is not meant to be deployed manually. 6 | It will be deployed automatically by MasterChefV3 with LmPoolDeployer whenever 7 | there is a new liquidity mining campaign. 8 | As for testing, please check the tests in MasterChefV3 which is the main testing 9 | entry point to test the correctness of the reward calculation. 10 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | library PositionKey { 5 | /// @dev Returns the key of the position in the core library 6 | function compute( 7 | address owner, 8 | int24 tickLower, 9 | int24 tickUpper 10 | ) internal pure returns (bytes32) { 11 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TestERC20Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '@openzeppelin/contracts/drafts/ERC20Permit.sol'; 5 | 6 | contract TestERC20Metadata is ERC20Permit { 7 | constructor( 8 | uint256 amountToMint, 9 | string memory name, 10 | string memory symbol 11 | ) ERC20(name, symbol) ERC20Permit(name) { 12 | _mint(msg.sender, amountToMint); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /projects/v3-periphery/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "resolveJsonModule": true, 8 | "outDir": "dist", 9 | "typeRoots": ["./typechain", "./node_modules/@types"], 10 | "types": ["@nomiclabs/hardhat-ethers", "@nomiclabs/hardhat-waffle"] 11 | }, 12 | "include": ["./test", "./scripts"], 13 | "files": ["./hardhat.config.ts"] 14 | } 15 | -------------------------------------------------------------------------------- /projects/router/contracts/base/PeripheryValidationExtended.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | import '@pancakeswap/v3-periphery/contracts/base/PeripheryValidation.sol'; 5 | 6 | abstract contract PeripheryValidationExtended is PeripheryValidation { 7 | modifier checkPreviousBlockhash(bytes32 previousBlockhash) { 8 | require(blockhash(block.number - 1) == previousBlockhash, 'Blockhash'); 9 | _; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/ILMPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface ILMPool { 5 | function updatePosition(int24 tickLower, int24 tickUpper, int128 liquidityDelta) external; 6 | 7 | function getRewardGrowthInside( 8 | int24 tickLower, 9 | int24 tickUpper 10 | ) external view returns (uint256 rewardGrowthInsideX128); 11 | 12 | function accumulateReward(uint32 currTimestamp) external; 13 | } 14 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/external/IWETH9.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; 5 | 6 | /// @title Interface for WETH9 7 | interface IWETH9 is IERC20 { 8 | /// @notice Deposit ether to get wrapped ether 9 | function deposit() external payable; 10 | 11 | /// @notice Withdraw wrapped ether to get ether 12 | function withdraw(uint256) external; 13 | } 14 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/IPancakeV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.10; 3 | 4 | interface IPancakeV3Pool { 5 | function factory() external view returns (address); 6 | 7 | function token0() external view returns (address); 8 | 9 | function token1() external view returns (address); 10 | 11 | function fee() external view returns (uint24); 12 | 13 | function lmPool() external view returns (address); 14 | } 15 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/ticks.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'ethers' 2 | 3 | export const getMinTick = (tickSpacing: number) => Math.ceil(-887272 / tickSpacing) * tickSpacing 4 | export const getMaxTick = (tickSpacing: number) => Math.floor(887272 / tickSpacing) * tickSpacing 5 | export const getMaxLiquidityPerTick = (tickSpacing: number) => 6 | BigNumber.from(2) 7 | .pow(128) 8 | .sub(1) 9 | .div((getMaxTick(tickSpacing) - getMinTick(tickSpacing)) / tickSpacing + 1) 10 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/IMasterChefV3.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IMasterChefV3 4 | 5 | ### latestPeriodEndTime 6 | 7 | ```solidity 8 | function latestPeriodEndTime() external view returns (uint256) 9 | ``` 10 | 11 | ### latestPeriodStartTime 12 | 13 | ```solidity 14 | function latestPeriodStartTime() external view returns (uint256) 15 | ``` 16 | 17 | ### upkeep 18 | 19 | ```solidity 20 | function upkeep(uint256 amount, uint256 duration, bool withUpdate) external 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/manticore/002.sol: -------------------------------------------------------------------------------- 1 | import '../../../../../contracts/libraries/BitMath.sol'; 2 | 3 | contract VerifyBitMathLsb { 4 | function verify(uint256 x) external { 5 | uint256 lsb = BitMath.leastSignificantBit(x); 6 | 7 | // (x & 2**leastSignificantBit(x)) != 0 and (x & (2**(leastSignificantBit(x)) - 1)) == 0) 8 | bool property = ((x & (2**lsb)) != 0) && ((x & (2**(lsb - 1))) == 0); 9 | 10 | require(!property); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/base/BlockTimestamp.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## BlockTimestamp 4 | 5 | _Base contract that is overridden for tests_ 6 | 7 | ### _blockTimestamp 8 | 9 | ```solidity 10 | function _blockTimestamp() internal view virtual returns (uint256) 11 | ``` 12 | 13 | _Method that exists purely to be overridden for tests_ 14 | 15 | #### Return Values 16 | 17 | | Name | Type | Description | 18 | | ---- | ---- | ----------- | 19 | | [0] | uint256 | The current block timestamp | 20 | 21 | -------------------------------------------------------------------------------- /projects/v3-periphery/util/necessary/ticks.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from "ethers"; 2 | 3 | export const getMinTick = (tickSpacing: number) => Math.ceil(-887272 / tickSpacing) * tickSpacing; 4 | 5 | export const getMaxTick = (tickSpacing: number) => Math.floor(887272 / tickSpacing) * tickSpacing; 6 | 7 | export const getMaxLiquidityPerTick = (tickSpacing: number) => 8 | BigNumber.from(2) 9 | .pow(128) 10 | .sub(1) 11 | .div((getMaxTick(tickSpacing) - getMinTick(tickSpacing)) / tickSpacing + 1); 12 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/libraries/BytesLib.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## BytesLib 4 | 5 | ### slice 6 | 7 | ```solidity 8 | function slice(bytes _bytes, uint256 _start, uint256 _length) internal pure returns (bytes) 9 | ``` 10 | 11 | ### toAddress 12 | 13 | ```solidity 14 | function toAddress(bytes _bytes, uint256 _start) internal pure returns (address) 15 | ``` 16 | 17 | ### toUint24 18 | 19 | ```solidity 20 | function toUint24(bytes _bytes, uint256 _start) internal pure returns (uint24) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/PositionValue.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`PositionValue #fees when price is above the position range gas 1`] = `49833`; 4 | 5 | exports[`PositionValue #fees when price is below the position range gas 1`] = `49801`; 6 | 7 | exports[`PositionValue #fees when price is within the position range gas 1`] = `55369`; 8 | 9 | exports[`PositionValue #principal gas 1`] = `23001`; 10 | 11 | exports[`PositionValue #total gas 1`] = `61930`; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pancake-v3", 3 | "private": true, 4 | "workspaces": [ 5 | "projects/*", 6 | "deployer/*", 7 | "common" 8 | ], 9 | "scripts": { 10 | "compile": "yarn workspaces run compile", 11 | "test": "yarn workspaces run test" 12 | }, 13 | "devDependencies": { 14 | "zx": "^7.2.0", 15 | "@typechain/hardhat": "^6.1.5", 16 | "solidity-docgen": "^0.6.0-beta.35", 17 | "find-config": "^1.0.0" 18 | }, 19 | "volta": { 20 | "node": "16.19.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/FullMathEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## FullMathEchidnaTest 4 | 5 | ### checkMulDivRounding 6 | 7 | ```solidity 8 | function checkMulDivRounding(uint256 x, uint256 y, uint256 d) external pure 9 | ``` 10 | 11 | ### checkMulDiv 12 | 13 | ```solidity 14 | function checkMulDiv(uint256 x, uint256 y, uint256 d) external pure 15 | ``` 16 | 17 | ### checkMulDivRoundingUp 18 | 19 | ```solidity 20 | function checkMulDivRoundingUp(uint256 x, uint256 y, uint256 d) external pure 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/base/BlockTimestamp.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | /// @title Function for getting block timestamp 5 | /// @dev Base contract that is overridden for tests 6 | abstract contract BlockTimestamp { 7 | /// @dev Method that exists purely to be overridden for tests 8 | /// @return The current block timestamp 9 | function _blockTimestamp() internal view virtual returns (uint256) { 10 | return block.timestamp; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TestCallbackValidation.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/CallbackValidation.sol'; 5 | 6 | contract TestCallbackValidation { 7 | function verifyCallback( 8 | address factory, 9 | address tokenA, 10 | address tokenB, 11 | uint24 fee 12 | ) external view returns (IPancakeV3Pool pool) { 13 | return CallbackValidation.verifyCallback(factory, tokenA, tokenB, fee); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/IFarmBooster.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IFarmBooster { 5 | function getUserMultiplier(uint256 _tokenId) external view returns (uint256); 6 | 7 | function whiteList(uint256 _pid) external view returns (bool); 8 | 9 | function updatePositionBoostMultiplier(uint256 _tokenId) external returns (uint256 _multiplier); 10 | 11 | function removeBoostMultiplier(address _user, uint256 _tokenId, uint256 _pid) external; 12 | } 13 | -------------------------------------------------------------------------------- /projects/v3-periphery/deployments/eth.json: -------------------------------------------------------------------------------- 1 | { 2 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 3 | "V3Migrator": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 4 | "QuoterV2": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 5 | "TickLens": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 6 | "NonfungibleTokenPositionDescriptor": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227", 7 | "NonfungiblePositionManager": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 8 | "PancakeInterfaceMulticall": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea" 9 | } -------------------------------------------------------------------------------- /projects/v3-periphery/deployments/bscMainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 3 | "V3Migrator": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 4 | "QuoterV2": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 5 | "TickLens": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 6 | "NonfungibleTokenPositionDescriptor": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227", 7 | "NonfungiblePositionManager": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 8 | "PancakeInterfaceMulticall": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea" 9 | } -------------------------------------------------------------------------------- /projects/v3-periphery/deployments/bscTestnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 3 | "V3Migrator": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 4 | "QuoterV2": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 5 | "TickLens": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea", 6 | "NonfungibleTokenPositionDescriptor": "0xb099b459887bC759dBF0293E12D3DFcD0C456cff", 7 | "NonfungiblePositionManager": "0x427bF5b37357632377eCbEC9de3626C71A5396c1", 8 | "PancakeInterfaceMulticall": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227" 9 | } -------------------------------------------------------------------------------- /projects/v3-periphery/deployments/goerli.json: -------------------------------------------------------------------------------- 1 | { 2 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 3 | "V3Migrator": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 4 | "QuoterV2": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 5 | "TickLens": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea", 6 | "NonfungibleTokenPositionDescriptor": "0xb099b459887bC759dBF0293E12D3DFcD0C456cff", 7 | "NonfungiblePositionManager": "0x427bF5b37357632377eCbEC9de3626C71A5396c1", 8 | "PancakeInterfaceMulticall": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227" 9 | } -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/IImmutableState.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Immutable state 5 | /// @notice Functions that return immutable state of the router 6 | interface IImmutableState { 7 | /// @return Returns the address of the PancakeSwap V2 factory 8 | function factoryV2() external view returns (address); 9 | 10 | /// @return Returns the address of PancakeSwap V3 NFT position manager 11 | function positionManager() external view returns (address); 12 | } 13 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/Base64Test.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import 'base64-sol/base64.sol'; 5 | 6 | contract Base64Test { 7 | function encode(bytes memory data) external pure returns (string memory) { 8 | return Base64.encode(data); 9 | } 10 | 11 | function getGasCostOfEncode(bytes memory data) external view returns (uint256) { 12 | uint256 gasBefore = gasleft(); 13 | Base64.encode(data); 14 | return gasBefore - gasleft(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/ILMPool.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## ILMPool 4 | 5 | ### updatePosition 6 | 7 | ```solidity 8 | function updatePosition(int24 tickLower, int24 tickUpper, int128 liquidityDelta) external 9 | ``` 10 | 11 | ### getRewardGrowthInside 12 | 13 | ```solidity 14 | function getRewardGrowthInside(int24 tickLower, int24 tickUpper) external view returns (uint256 rewardGrowthInsideX128) 15 | ``` 16 | 17 | ### accumulateReward 18 | 19 | ```solidity 20 | function accumulateReward(uint32 currTimestamp) external 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/UnsafeMathEchidnaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/UnsafeMath.sol'; 5 | 6 | contract UnsafeMathEchidnaTest { 7 | function checkDivRoundingUp(uint256 x, uint256 d) external pure { 8 | require(d > 0); 9 | uint256 z = UnsafeMath.divRoundingUp(x, d); 10 | uint256 diff = z - (x / d); 11 | if (x % d == 0) { 12 | assert(diff == 0); 13 | } else { 14 | assert(diff == 1); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/encodePriceSqrt.ts: -------------------------------------------------------------------------------- 1 | import bn from 'bignumber.js' 2 | import { BigNumber, BigNumberish } from 'ethers' 3 | 4 | bn.config({ EXPONENTIAL_AT: 999999, DECIMAL_PLACES: 40 }) 5 | 6 | // returns the sqrt price as a 64x96 7 | export function encodePriceSqrt(reserve1: BigNumberish, reserve0: BigNumberish): BigNumber { 8 | return BigNumber.from( 9 | new bn(reserve1.toString()) 10 | .div(reserve0.toString()) 11 | .sqrt() 12 | .multipliedBy(new bn(2).pow(96)) 13 | .integerValue(3) 14 | .toString() 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/NonfungiblePositionManagerPositionsGasTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## NonfungiblePositionManagerPositionsGasTest 4 | 5 | ### nonfungiblePositionManager 6 | 7 | ```solidity 8 | contract INonfungiblePositionManager nonfungiblePositionManager 9 | ``` 10 | 11 | ### constructor 12 | 13 | ```solidity 14 | constructor(contract INonfungiblePositionManager _nonfungiblePositionManager) public 15 | ``` 16 | 17 | ### getGasCostOfPositions 18 | 19 | ```solidity 20 | function getGasCostOfPositions(uint256 tokenId) external view returns (uint256) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/echidna/E2E_mint_burn.config.yaml: -------------------------------------------------------------------------------- 1 | checkAsserts: true 2 | coverage: true 3 | codeSize: 0x60000 4 | corpusDir: echidna_e2e_mint_burn_corpus 5 | seqLen: 10 6 | testLimit: 100000 7 | timeout: 600 # 10 minutes 8 | 9 | # blacklist 10 | filterFunctions: 11 | [ 12 | 'E2E_mint_burn.viewInitRandomPoolParams(uint128)', 13 | 'E2E_mint_burn.viewMintRandomNewPosition(uint128,int24,uint24,int24)', 14 | 'E2E_mint_burn.viewBurnRandomPositionIdx(uint128,uint128)', 15 | 'E2E_mint_burn.viewBurnRandomPositionBurnAmount(uint128,uint128)', 16 | ] 17 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/LiquidityMathTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/LiquidityMath.sol'; 5 | 6 | contract LiquidityMathTest { 7 | function addDelta(uint128 x, int128 y) external pure returns (uint128 z) { 8 | return LiquidityMath.addDelta(x, y); 9 | } 10 | 11 | function getGasCostOfAddDelta(uint128 x, int128 y) external view returns (uint256) { 12 | uint256 gasBefore = gasleft(); 13 | LiquidityMath.addDelta(x, y); 14 | return gasBefore - gasleft(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/SwapMathTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## SwapMathTest 4 | 5 | ### computeSwapStep 6 | 7 | ```solidity 8 | function computeSwapStep(uint160 sqrtP, uint160 sqrtPTarget, uint128 liquidity, int256 amountRemaining, uint24 feePips) external pure returns (uint160 sqrtQ, uint256 amountIn, uint256 amountOut, uint256 feeAmount) 9 | ``` 10 | 11 | ### getGasCostOfComputeSwapStep 12 | 13 | ```solidity 14 | function getGasCostOfComputeSwapStep(uint160 sqrtP, uint160 sqrtPTarget, uint128 liquidity, int256 amountRemaining, uint24 feePips) external view returns (uint256) 15 | ``` 16 | 17 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/MockTimeSwapRouter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '../SwapRouter.sol'; 6 | 7 | contract MockTimeSwapRouter is SwapRouter { 8 | uint256 time; 9 | 10 | constructor(address _deployer, address _factory, address _WETH9) SwapRouter(_deployer, _factory, _WETH9) {} 11 | 12 | function _blockTimestamp() internal view override returns (uint256) { 13 | return time; 14 | } 15 | 16 | function setTime(uint256 _time) external { 17 | time = _time; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/BitMath.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`BitMath #leastSignificantBit gas cost of max uint128 1`] = `407`; 4 | 5 | exports[`BitMath #leastSignificantBit gas cost of max uint256 1`] = `407`; 6 | 7 | exports[`BitMath #leastSignificantBit gas cost of smaller number 1`] = `408`; 8 | 9 | exports[`BitMath #mostSignificantBit gas cost of max uint128 1`] = `367`; 10 | 11 | exports[`BitMath #mostSignificantBit gas cost of max uint256 1`] = `385`; 12 | 13 | exports[`BitMath #mostSignificantBit gas cost of smaller number 1`] = `295`; 14 | -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/ISmartRouter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.5; 3 | pragma abicoder v2; 4 | 5 | import '@pancakeswap/v3-periphery/contracts/interfaces/ISelfPermit.sol'; 6 | 7 | import './IV2SwapRouter.sol'; 8 | import './IV3SwapRouter.sol'; 9 | import './IStableSwapRouter.sol'; 10 | import './IApproveAndCall.sol'; 11 | import './IMulticallExtended.sol'; 12 | 13 | /// @title Router token swapping functionality 14 | interface ISmartRouter is IV2SwapRouter, IV3SwapRouter, IStableSwapRouter, IApproveAndCall, IMulticallExtended, ISelfPermit { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/FullMathTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/FullMath.sol'; 5 | 6 | contract FullMathTest { 7 | function mulDiv( 8 | uint256 x, 9 | uint256 y, 10 | uint256 z 11 | ) external pure returns (uint256) { 12 | return FullMath.mulDiv(x, y, z); 13 | } 14 | 15 | function mulDivRoundingUp( 16 | uint256 x, 17 | uint256 y, 18 | uint256 z 19 | ) external pure returns (uint256) { 20 | return FullMath.mulDivRoundingUp(x, y, z); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/PoolAddressTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PoolAddressTest 4 | 5 | ### POOL_INIT_CODE_HASH 6 | 7 | ```solidity 8 | function POOL_INIT_CODE_HASH() external pure returns (bytes32) 9 | ``` 10 | 11 | ### computeAddress 12 | 13 | ```solidity 14 | function computeAddress(address deployer, address token0, address token1, uint24 fee) external pure returns (address) 15 | ``` 16 | 17 | ### getGasCostOfComputeAddress 18 | 19 | ```solidity 20 | function getGasCostOfComputeAddress(address deployer, address token0, address token1, uint24 fee) external view returns (uint256) 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/libraries/TokenRatioSortOrder.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TokenRatioSortOrder 4 | 5 | ### NUMERATOR_MOST 6 | 7 | ```solidity 8 | int256 NUMERATOR_MOST 9 | ``` 10 | 11 | ### NUMERATOR_MORE 12 | 13 | ```solidity 14 | int256 NUMERATOR_MORE 15 | ``` 16 | 17 | ### NUMERATOR 18 | 19 | ```solidity 20 | int256 NUMERATOR 21 | ``` 22 | 23 | ### DENOMINATOR_MOST 24 | 25 | ```solidity 26 | int256 DENOMINATOR_MOST 27 | ``` 28 | 29 | ### DENOMINATOR_MORE 30 | 31 | ```solidity 32 | int256 DENOMINATOR_MORE 33 | ``` 34 | 35 | ### DENOMINATOR 36 | 37 | ```solidity 38 | int256 DENOMINATOR 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/IPancakeV3Pool.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPancakeV3Pool 4 | 5 | ### factory 6 | 7 | ```solidity 8 | function factory() external view returns (address) 9 | ``` 10 | 11 | ### token0 12 | 13 | ```solidity 14 | function token0() external view returns (address) 15 | ``` 16 | 17 | ### token1 18 | 19 | ```solidity 20 | function token1() external view returns (address) 21 | ``` 22 | 23 | ### fee 24 | 25 | ```solidity 26 | function fee() external view returns (uint24) 27 | ``` 28 | 29 | ### lmPool 30 | 31 | ```solidity 32 | function lmPool() external view returns (address) 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TickLensTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | pragma abicoder v2; 4 | 5 | import '@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol'; 6 | import '../lens/TickLens.sol'; 7 | 8 | /// @title Tick Lens contract 9 | contract TickLensTest is TickLens { 10 | function getGasCostOfGetPopulatedTicksInWord(address pool, int16 tickBitmapIndex) external view returns (uint256) { 11 | uint256 gasBefore = gasleft(); 12 | getPopulatedTicksInWord(pool, tickBitmapIndex); 13 | return gasBefore - gasleft(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pancake V3 2 | 3 | 4 | ## Deployments 5 | 6 | 1. Add Key in `.env` file. It's a private key of the account that will deploy the contracts and should be gitignored. 7 | 2. bscTestnet `KEY_TESTNET` or bsc `KEY_MAINNET` 8 | 3. add `ETHERSCAN_API_KEY` in `.env` file. It's an API key for etherscan. 9 | 4. `yarn` in root directory 10 | 5. `NETWORK=$NETWORK yarn zx v3-deploy.mjs` where `$NETWORK` is either `eth`, `goerli`, `bscMainnet`, `bscTestnet` or `hardhat` (for local testing) 11 | 6. `NETWORK=$NETWORK yarn zx v3-verify.mjs` where `$NETWORK` is either `eth`, `goerli`, `bscMainnet`, `bscTestnet` or `hardhat` (for local testing) -------------------------------------------------------------------------------- /projects/masterchef-v3/config.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | MASTER_CHEF_v2: { 3 | mainnet: "0x0000000000000000000000000000000000000000", 4 | testnet: "0x0000000000000000000000000000000000000000", 5 | }, 6 | CAKE: { 7 | mainnet: "0x0000000000000000000000000000000000000000", 8 | testnet: "0x0000000000000000000000000000000000000000", 9 | }, 10 | NonfungiblePositionManager: { 11 | mainnet: "0x0000000000000000000000000000000000000000", 12 | testnet: "0x0000000000000000000000000000000000000000", 13 | }, 14 | MASTER_CHEF_V2_PID: { 15 | mainnet: 0, 16 | testnet: 0, 17 | goerli: 0, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /projects/masterchef-v3/test/TestLiquidityAmounts.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | import "@pancakeswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol"; 4 | 5 | contract TestLiquidityAmounts { 6 | function getLiquidityForAmounts( 7 | uint160 sqrtRatioX96, 8 | uint160 sqrtRatioAX96, 9 | uint160 sqrtRatioBX96, 10 | uint256 amount0, 11 | uint256 amount1 12 | ) external pure returns (uint128 liquidity) { 13 | return LiquidityAmounts.getLiquidityForAmounts( 14 | sqrtRatioX96, 15 | sqrtRatioAX96, 16 | sqrtRatioBX96, 17 | amount0, 18 | amount1 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/router/docs/base/ImmutableState.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## ImmutableState 4 | 5 | Immutable state used by the swap router 6 | 7 | ### factoryV2 8 | 9 | ```solidity 10 | address factoryV2 11 | ``` 12 | 13 | #### Return Values 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | 18 | ### positionManager 19 | 20 | ```solidity 21 | address positionManager 22 | ``` 23 | 24 | #### Return Values 25 | 26 | | Name | Type | Description | 27 | | ---- | ---- | ----------- | 28 | 29 | ### constructor 30 | 31 | ```solidity 32 | constructor(address _factoryV2, address _positionManager) internal 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/MockObservable.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## MockObservable 4 | 5 | ### Observation 6 | 7 | ```solidity 8 | struct Observation { 9 | uint32 secondsAgo; 10 | int56 tickCumulatives; 11 | uint160 secondsPerLiquidityCumulativeX128s; 12 | } 13 | ``` 14 | 15 | ### constructor 16 | 17 | ```solidity 18 | constructor(uint32[] secondsAgos, int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulativeX128s) public 19 | ``` 20 | 21 | ### observe 22 | 23 | ```solidity 24 | function observe(uint32[] secondsAgos) external view returns (int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulativeX128s) 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /projects/router/docs/libraries/Constants.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## Constants 4 | 5 | Constant state used by the swap router 6 | 7 | ### CONTRACT_BALANCE 8 | 9 | ```solidity 10 | uint256 CONTRACT_BALANCE 11 | ``` 12 | 13 | _Used for identifying cases when this contract's balance of a token is to be used_ 14 | 15 | ### MSG_SENDER 16 | 17 | ```solidity 18 | address MSG_SENDER 19 | ``` 20 | 21 | _Used as a flag for identifying msg.sender, saves gas by sending more 0 bytes_ 22 | 23 | ### ADDRESS_THIS 24 | 25 | ```solidity 26 | address ADDRESS_THIS 27 | ``` 28 | 29 | _Used as a flag for identifying address(this), saves gas by sending more 0 bytes_ 30 | 31 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/PoolTicksCounterTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | import '@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol'; 3 | 4 | pragma solidity >=0.6.0; 5 | 6 | import '../libraries/PoolTicksCounter.sol'; 7 | 8 | contract PoolTicksCounterTest { 9 | using PoolTicksCounter for IPancakeV3Pool; 10 | 11 | function countInitializedTicksCrossed( 12 | IPancakeV3Pool pool, 13 | int24 tickBefore, 14 | int24 tickAfter 15 | ) external view returns (uint32 initializedTicksCrossed) { 16 | return pool.countInitializedTicksCrossed(tickBefore, tickAfter); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/LowGasSafeMathEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## LowGasSafeMathEchidnaTest 4 | 5 | ### checkAdd 6 | 7 | ```solidity 8 | function checkAdd(uint256 x, uint256 y) external pure 9 | ``` 10 | 11 | ### checkSub 12 | 13 | ```solidity 14 | function checkSub(uint256 x, uint256 y) external pure 15 | ``` 16 | 17 | ### checkMul 18 | 19 | ```solidity 20 | function checkMul(uint256 x, uint256 y) external pure 21 | ``` 22 | 23 | ### checkAddi 24 | 25 | ```solidity 26 | function checkAddi(int256 x, int256 y) external pure 27 | ``` 28 | 29 | ### checkSubi 30 | 31 | ```solidity 32 | function checkSubi(int256 x, int256 y) external pure 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Immutable state 5 | /// @notice Functions that return immutable state of the router 6 | interface IPeripheryImmutableState { 7 | /// @return Returns the address of the PancakeSwap V3 deployer 8 | function deployer() external view returns (address); 9 | 10 | /// @return Returns the address of the PancakeSwap V3 factory 11 | function factory() external view returns (address); 12 | 13 | /// @return Returns the address of WETH9 14 | function WETH9() external view returns (address); 15 | } 16 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/IMasterChefV2.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.10; 3 | 4 | interface IMasterChefV2 { 5 | function deposit(uint256 _pid, uint256 _amount) external; 6 | 7 | function withdraw(uint256 _pid, uint256 _amount) external; 8 | 9 | function pendingCake(uint256 _pid, address _user) external view returns (uint256); 10 | 11 | function userInfo(uint256 _pid, address _user) external view returns (uint256, uint256, uint256); 12 | 13 | function emergencyWithdraw(uint256 _pid) external; 14 | 15 | function updateBoostMultiplier(address _user, uint256 _pid, uint256 _newBoostMulti) external; 16 | } 17 | -------------------------------------------------------------------------------- /projects/v3-core/docs/libraries/LiquidityMath.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## LiquidityMath 4 | 5 | ### addDelta 6 | 7 | ```solidity 8 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) 9 | ``` 10 | 11 | Add a signed liquidity delta to liquidity and revert if it overflows or underflows 12 | 13 | #### Parameters 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | x | uint128 | The liquidity before change | 18 | | y | int128 | The delta by which liquidity should be changed | 19 | 20 | #### Return Values 21 | 22 | | Name | Type | Description | 23 | | ---- | ---- | ----------- | 24 | | z | uint128 | The liquidity delta | 25 | 26 | -------------------------------------------------------------------------------- /projects/router/contracts/base/ImmutableState.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | import '../interfaces/IImmutableState.sol'; 5 | 6 | /// @title Immutable state 7 | /// @notice Immutable state used by the swap router 8 | abstract contract ImmutableState is IImmutableState { 9 | /// @inheritdoc IImmutableState 10 | address public immutable override factoryV2; 11 | /// @inheritdoc IImmutableState 12 | address public immutable override positionManager; 13 | 14 | constructor(address _factoryV2, address _positionManager) { 15 | factoryV2 = _factoryV2; 16 | positionManager = _positionManager; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/IFarmBooster.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IFarmBooster 4 | 5 | ### getUserMultiplier 6 | 7 | ```solidity 8 | function getUserMultiplier(uint256 _tokenId) external view returns (uint256) 9 | ``` 10 | 11 | ### whiteList 12 | 13 | ```solidity 14 | function whiteList(uint256 _pid) external view returns (bool) 15 | ``` 16 | 17 | ### updatePositionBoostMultiplier 18 | 19 | ```solidity 20 | function updatePositionBoostMultiplier(uint256 _tokenId) external returns (uint256 _multiplier) 21 | ``` 22 | 23 | ### removeBoostMultiplier 24 | 25 | ```solidity 26 | function removeBoostMultiplier(address _user, uint256 _tokenId, uint256 _pid) external 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/BitMathTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## BitMathTest 4 | 5 | ### mostSignificantBit 6 | 7 | ```solidity 8 | function mostSignificantBit(uint256 x) external pure returns (uint8 r) 9 | ``` 10 | 11 | ### getGasCostOfMostSignificantBit 12 | 13 | ```solidity 14 | function getGasCostOfMostSignificantBit(uint256 x) external view returns (uint256) 15 | ``` 16 | 17 | ### leastSignificantBit 18 | 19 | ```solidity 20 | function leastSignificantBit(uint256 x) external pure returns (uint8 r) 21 | ``` 22 | 23 | ### getGasCostOfLeastSignificantBit 24 | 25 | ```solidity 26 | function getGasCostOfLeastSignificantBit(uint256 x) external view returns (uint256) 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /projects/v3-periphery/deployments/hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "SwapRouter": "0x5FbDB2315678afecb367f032d93F642f64180aa3", 3 | "V3Migrator": "0x0165878A594ca255338adfa4d48449f69242Eb8F", 4 | "QuoterV2": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6", 5 | "TickLens": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", 6 | "ProxyAdmin": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", 7 | "TransparentUpgradeableProxy": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", 8 | "NonfungibleTokenPositionDescriptor": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", 9 | "NonfungiblePositionManager": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", 10 | "PancakeInterfaceMulticall": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707" 11 | } -------------------------------------------------------------------------------- /projects/router/contracts/libraries/Constants.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | /// @title Constant state 5 | /// @notice Constant state used by the swap router 6 | library Constants { 7 | /// @dev Used for identifying cases when this contract's balance of a token is to be used 8 | uint256 internal constant CONTRACT_BALANCE = 0; 9 | 10 | /// @dev Used as a flag for identifying msg.sender, saves gas by sending more 0 bytes 11 | address internal constant MSG_SENDER = address(1); 12 | 13 | /// @dev Used as a flag for identifying address(this), saves gas by sending more 0 bytes 14 | address internal constant ADDRESS_THIS = address(2); 15 | } 16 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/BitMathEchidnaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/BitMath.sol'; 5 | 6 | contract BitMathEchidnaTest { 7 | function mostSignificantBitInvariant(uint256 input) external pure { 8 | uint8 msb = BitMath.mostSignificantBit(input); 9 | assert(input >= (uint256(2)**msb)); 10 | assert(msb == 255 || input < uint256(2)**(msb + 1)); 11 | } 12 | 13 | function leastSignificantBitInvariant(uint256 input) external pure { 14 | uint8 lsb = BitMath.leastSignificantBit(input); 15 | assert(input & (uint256(2)**lsb) != 0); 16 | assert(input & (uint256(2)**lsb - 1) == 0); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, 'LS'); 13 | } else { 14 | require((z = x + uint128(y)) >= x, 'LA'); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/IERC20Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.7.0; 3 | 4 | import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; 5 | 6 | /// @title IERC20Metadata 7 | /// @title Interface for ERC20 Metadata 8 | /// @notice Extension to IERC20 that includes token metadata 9 | interface IERC20Metadata is IERC20 { 10 | /// @return The name of the token 11 | function name() external view returns (string memory); 12 | 13 | /// @return The symbol of the token 14 | function symbol() external view returns (string memory); 15 | 16 | /// @return The number of decimal places the token has 17 | function decimals() external view returns (uint8); 18 | } 19 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TickOverflowSafetyEchidnaTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickOverflowSafetyEchidnaTest 4 | 5 | ### totalLiquidity 6 | 7 | ```solidity 8 | int256 totalLiquidity 9 | ``` 10 | 11 | ### increaseFeeGrowthGlobal0X128 12 | 13 | ```solidity 14 | function increaseFeeGrowthGlobal0X128(uint256 amount) external 15 | ``` 16 | 17 | ### increaseFeeGrowthGlobal1X128 18 | 19 | ```solidity 20 | function increaseFeeGrowthGlobal1X128(uint256 amount) external 21 | ``` 22 | 23 | ### setPosition 24 | 25 | ```solidity 26 | function setPosition(int24 tickLower, int24 tickUpper, int128 liquidityDelta) external 27 | ``` 28 | 29 | ### moveToTick 30 | 31 | ```solidity 32 | function moveToTick(int24 target) external 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/MockTimeSwapRouter.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## MockTimeSwapRouter 4 | 5 | ### time 6 | 7 | ```solidity 8 | uint256 time 9 | ``` 10 | 11 | ### constructor 12 | 13 | ```solidity 14 | constructor(address _deployer, address _factory, address _WETH9) public 15 | ``` 16 | 17 | ### _blockTimestamp 18 | 19 | ```solidity 20 | function _blockTimestamp() internal view returns (uint256) 21 | ``` 22 | 23 | _Method that exists purely to be overridden for tests_ 24 | 25 | #### Return Values 26 | 27 | | Name | Type | Description | 28 | | ---- | ---- | ----------- | 29 | | [0] | uint256 | The current block timestamp | 30 | 31 | ### setTime 32 | 33 | ```solidity 34 | function setTime(uint256 _time) external 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/libraries/HexStrings.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## HexStrings 4 | 5 | ### ALPHABET 6 | 7 | ```solidity 8 | bytes16 ALPHABET 9 | ``` 10 | 11 | ### toHexString 12 | 13 | ```solidity 14 | function toHexString(uint256 value, uint256 length) internal pure returns (string) 15 | ``` 16 | 17 | Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 18 | 19 | _Credit to Open Zeppelin under MIT license https://github.com/OpenZeppelin/openzeppelin-contracts/blob/243adff49ce1700e0ecb99fe522fb16cff1d1ddc/contracts/utils/Strings.sol#L55_ 20 | 21 | ### toHexStringNoPrefix 22 | 23 | ```solidity 24 | function toHexStringNoPrefix(uint256 value, uint256 length) internal pure returns (string) 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IImmutableState.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IImmutableState 4 | 5 | Functions that return immutable state of the router 6 | 7 | ### factoryV2 8 | 9 | ```solidity 10 | function factoryV2() external view returns (address) 11 | ``` 12 | 13 | #### Return Values 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | [0] | address | Returns the address of the PancakeSwap V2 factory | 18 | 19 | ### positionManager 20 | 21 | ```solidity 22 | function positionManager() external view returns (address) 23 | ``` 24 | 25 | #### Return Values 26 | 27 | | Name | Type | Description | 28 | | ---- | ---- | ----------- | 29 | | [0] | address | Returns the address of PancakeSwap V3 NFT position manager | 30 | 31 | -------------------------------------------------------------------------------- /projects/v3-core/docs/libraries/TransferHelper.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TransferHelper 4 | 5 | Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 6 | 7 | ### safeTransfer 8 | 9 | ```solidity 10 | function safeTransfer(address token, address to, uint256 value) internal 11 | ``` 12 | 13 | Transfers tokens from msg.sender to a recipient 14 | 15 | _Calls transfer on token contract, errors with TF if transfer fails_ 16 | 17 | #### Parameters 18 | 19 | | Name | Type | Description | 20 | | ---- | ---- | ----------- | 21 | | token | address | The contract address of the token which will be transferred | 22 | | to | address | The recipient of the transfer | 23 | | value | uint256 | The value of the transfer | 24 | 25 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-core/docs/libraries/UnsafeMath.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## UnsafeMath 4 | 5 | Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | 7 | ### divRoundingUp 8 | 9 | ```solidity 10 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) 11 | ``` 12 | 13 | Returns ceil(x / y) 14 | 15 | _division by 0 has unspecified behavior, and must be checked externally_ 16 | 17 | #### Parameters 18 | 19 | | Name | Type | Description | 20 | | ---- | ---- | ----------- | 21 | | x | uint256 | The dividend | 22 | | y | uint256 | The divisor | 23 | 24 | #### Return Values 25 | 26 | | Name | Type | Description | 27 | | ---- | ---- | ----------- | 28 | | z | uint256 | The quotient, ceil(x / y) | 29 | 30 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/NonfungiblePositionManagerPositionsGasTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../interfaces/INonfungiblePositionManager.sol'; 5 | 6 | contract NonfungiblePositionManagerPositionsGasTest { 7 | INonfungiblePositionManager immutable nonfungiblePositionManager; 8 | 9 | constructor(INonfungiblePositionManager _nonfungiblePositionManager) { 10 | nonfungiblePositionManager = _nonfungiblePositionManager; 11 | } 12 | 13 | function getGasCostOfPositions(uint256 tokenId) external view returns (uint256) { 14 | uint256 gasBefore = gasleft(); 15 | nonfungiblePositionManager.positions(tokenId); 16 | return gasBefore - gasleft(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /projects/router/docs/libraries/PoolTicksCounter.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PoolTicksCounter 4 | 5 | ### countInitializedTicksCrossed 6 | 7 | ```solidity 8 | function countInitializedTicksCrossed(contract IPancakeV3Pool self, int24 tickBefore, int24 tickAfter) internal view returns (uint32 initializedTicksCrossed) 9 | ``` 10 | 11 | _This function counts the number of initialized ticks that would incur a gas cost between tickBefore and tickAfter. 12 | When tickBefore and/or tickAfter themselves are initialized, the logic over whether we should count them depends on the 13 | direction of the swap. If we are swapping upwards (tickAfter > tickBefore) we don't want to count tickBefore but we do 14 | want to count tickAfter. The opposite is true if we are swapping downwards._ 15 | 16 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/PathTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PathTest 4 | 5 | ### hasMultiplePools 6 | 7 | ```solidity 8 | function hasMultiplePools(bytes path) public pure returns (bool) 9 | ``` 10 | 11 | ### decodeFirstPool 12 | 13 | ```solidity 14 | function decodeFirstPool(bytes path) public pure returns (address tokenA, address tokenB, uint24 fee) 15 | ``` 16 | 17 | ### getFirstPool 18 | 19 | ```solidity 20 | function getFirstPool(bytes path) public pure returns (bytes) 21 | ``` 22 | 23 | ### skipToken 24 | 25 | ```solidity 26 | function skipToken(bytes path) public pure returns (bytes) 27 | ``` 28 | 29 | ### getGasCostOfDecodeFirstPool 30 | 31 | ```solidity 32 | function getGasCostOfDecodeFirstPool(bytes path) public view returns (uint256) 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/MockTimeNonfungiblePositionManager.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '../NonfungiblePositionManager.sol'; 6 | 7 | contract MockTimeNonfungiblePositionManager is NonfungiblePositionManager { 8 | uint256 time; 9 | 10 | constructor( 11 | address _deployer, 12 | address _factory, 13 | address _WETH9, 14 | address _tokenDescriptor 15 | ) NonfungiblePositionManager(_deployer, _factory, _WETH9, _tokenDescriptor) {} 16 | 17 | function _blockTimestamp() internal view override returns (uint256) { 18 | return time; 19 | } 20 | 21 | function setTime(uint256 _time) external { 22 | time = _time; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/libraries/PoolTicksCounter.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PoolTicksCounter 4 | 5 | ### countInitializedTicksCrossed 6 | 7 | ```solidity 8 | function countInitializedTicksCrossed(contract IPancakeV3Pool self, int24 tickBefore, int24 tickAfter) internal view returns (uint32 initializedTicksCrossed) 9 | ``` 10 | 11 | _This function counts the number of initialized ticks that would incur a gas cost between tickBefore and tickAfter. 12 | When tickBefore and/or tickAfter themselves are initialized, the logic over whether we should count them depends on the 13 | direction of the swap. If we are swapping upwards (tickAfter > tickBefore) we don't want to count tickBefore but we do 14 | want to count tickAfter. The opposite is true if we are swapping downwards._ 15 | 16 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IStableSwap.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IStableSwap 4 | 5 | ### get_dy 6 | 7 | ```solidity 8 | function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256 dy) 9 | ``` 10 | 11 | ### exchange 12 | 13 | ```solidity 14 | function exchange(uint256 i, uint256 j, uint256 dx, uint256 minDy) external payable 15 | ``` 16 | 17 | ### coins 18 | 19 | ```solidity 20 | function coins(uint256 i) external view returns (address) 21 | ``` 22 | 23 | ### balances 24 | 25 | ```solidity 26 | function balances(uint256 i) external view returns (uint256) 27 | ``` 28 | 29 | ### A 30 | 31 | ```solidity 32 | function A() external view returns (uint256) 33 | ``` 34 | 35 | ### fee 36 | 37 | ```solidity 38 | function fee() external view returns (uint256) 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/IMulticall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.5; 3 | pragma abicoder v2; 4 | 5 | /// @title Multicall interface 6 | /// @notice Enables calling multiple methods in a single call to the contract 7 | interface IMulticall { 8 | /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed 9 | /// @dev The `msg.value` should not be trusted for any method callable from multicall. 10 | /// @param data The encoded function data for each of the calls to make to this contract 11 | /// @return results The results from each of the calls passed in via data 12 | function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); 13 | } 14 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/MockTimePancakeV3Pool.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## MockTimePancakeV3Pool 4 | 5 | ### time 6 | 7 | ```solidity 8 | uint256 time 9 | ``` 10 | 11 | ### setFeeGrowthGlobal0X128 12 | 13 | ```solidity 14 | function setFeeGrowthGlobal0X128(uint256 _feeGrowthGlobal0X128) external 15 | ``` 16 | 17 | ### setFeeGrowthGlobal1X128 18 | 19 | ```solidity 20 | function setFeeGrowthGlobal1X128(uint256 _feeGrowthGlobal1X128) external 21 | ``` 22 | 23 | ### advanceTime 24 | 25 | ```solidity 26 | function advanceTime(uint256 by) external 27 | ``` 28 | 29 | ### _blockTimestamp 30 | 31 | ```solidity 32 | function _blockTimestamp() internal view returns (uint32) 33 | ``` 34 | 35 | _Returns the block timestamp truncated to 32 bits, i.e. mod 2**32. This method is overridden in tests._ 36 | 37 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/MockTimeNonfungiblePositionManager.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## MockTimeNonfungiblePositionManager 4 | 5 | ### time 6 | 7 | ```solidity 8 | uint256 time 9 | ``` 10 | 11 | ### constructor 12 | 13 | ```solidity 14 | constructor(address _deployer, address _factory, address _WETH9, address _tokenDescriptor) public 15 | ``` 16 | 17 | ### _blockTimestamp 18 | 19 | ```solidity 20 | function _blockTimestamp() internal view returns (uint256) 21 | ``` 22 | 23 | _Method that exists purely to be overridden for tests_ 24 | 25 | #### Return Values 26 | 27 | | Name | Type | Description | 28 | | ---- | ---- | ----------- | 29 | | [0] | uint256 | The current block timestamp | 30 | 31 | ### setTime 32 | 33 | ```solidity 34 | function setTime(uint256 _time) external 35 | ``` 36 | 37 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TestMulticall.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestMulticall 4 | 5 | ### functionThatRevertsWithError 6 | 7 | ```solidity 8 | function functionThatRevertsWithError(string error) external pure 9 | ``` 10 | 11 | ### Tuple 12 | 13 | ```solidity 14 | struct Tuple { 15 | uint256 a; 16 | uint256 b; 17 | } 18 | ``` 19 | 20 | ### functionThatReturnsTuple 21 | 22 | ```solidity 23 | function functionThatReturnsTuple(uint256 a, uint256 b) external pure returns (struct TestMulticall.Tuple tuple) 24 | ``` 25 | 26 | ### paid 27 | 28 | ```solidity 29 | uint256 paid 30 | ``` 31 | 32 | ### pays 33 | 34 | ```solidity 35 | function pays() external payable 36 | ``` 37 | 38 | ### returnSender 39 | 40 | ```solidity 41 | function returnSender() external view returns (address) 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/base/PeripheryImmutableState.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PeripheryImmutableState 4 | 5 | Immutable state used by periphery contracts 6 | 7 | ### deployer 8 | 9 | ```solidity 10 | address deployer 11 | ``` 12 | 13 | #### Return Values 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | 18 | ### factory 19 | 20 | ```solidity 21 | address factory 22 | ``` 23 | 24 | #### Return Values 25 | 26 | | Name | Type | Description | 27 | | ---- | ---- | ----------- | 28 | 29 | ### WETH9 30 | 31 | ```solidity 32 | address WETH9 33 | ``` 34 | 35 | #### Return Values 36 | 37 | | Name | Type | Description | 38 | | ---- | ---- | ----------- | 39 | 40 | ### constructor 41 | 42 | ```solidity 43 | constructor(address _deployer, address _factory, address _WETH9) internal 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/interfaces/INonfungiblePositionManagerStruct.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.10; 3 | 4 | interface INonfungiblePositionManagerStruct { 5 | struct IncreaseLiquidityParams { 6 | uint256 tokenId; 7 | uint256 amount0Desired; 8 | uint256 amount1Desired; 9 | uint256 amount0Min; 10 | uint256 amount1Min; 11 | uint256 deadline; 12 | } 13 | 14 | struct DecreaseLiquidityParams { 15 | uint256 tokenId; 16 | uint128 liquidity; 17 | uint256 amount0Min; 18 | uint256 amount1Min; 19 | uint256 deadline; 20 | } 21 | 22 | struct CollectParams { 23 | uint256 tokenId; 24 | address recipient; 25 | uint128 amount0Max; 26 | uint128 amount1Max; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/INonfungiblePositionManagerStruct.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## INonfungiblePositionManagerStruct 4 | 5 | ### IncreaseLiquidityParams 6 | 7 | ```solidity 8 | struct IncreaseLiquidityParams { 9 | uint256 tokenId; 10 | uint256 amount0Desired; 11 | uint256 amount1Desired; 12 | uint256 amount0Min; 13 | uint256 amount1Min; 14 | uint256 deadline; 15 | } 16 | ``` 17 | 18 | ### DecreaseLiquidityParams 19 | 20 | ```solidity 21 | struct DecreaseLiquidityParams { 22 | uint256 tokenId; 23 | uint128 liquidity; 24 | uint256 amount0Min; 25 | uint256 amount1Min; 26 | uint256 deadline; 27 | } 28 | ``` 29 | 30 | ### CollectParams 31 | 32 | ```solidity 33 | struct CollectParams { 34 | uint256 tokenId; 35 | address recipient; 36 | uint128 amount0Max; 37 | uint128 amount1Max; 38 | } 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TestMulticall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '../base/Multicall.sol'; 6 | 7 | contract TestMulticall is Multicall { 8 | function functionThatRevertsWithError(string memory error) external pure { 9 | revert(error); 10 | } 11 | 12 | struct Tuple { 13 | uint256 a; 14 | uint256 b; 15 | } 16 | 17 | function functionThatReturnsTuple(uint256 a, uint256 b) external pure returns (Tuple memory tuple) { 18 | tuple = Tuple({b: a, a: b}); 19 | } 20 | 21 | uint256 public paid; 22 | 23 | function pays() external payable { 24 | paid += msg.value; 25 | } 26 | 27 | function returnSender() external view returns (address) { 28 | return msg.sender; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/base/PeripheryImmutableState.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | 4 | import '../interfaces/IPeripheryImmutableState.sol'; 5 | 6 | /// @title Immutable state 7 | /// @notice Immutable state used by periphery contracts 8 | abstract contract PeripheryImmutableState is IPeripheryImmutableState { 9 | /// @inheritdoc IPeripheryImmutableState 10 | address public immutable override deployer; 11 | /// @inheritdoc IPeripheryImmutableState 12 | address public immutable override factory; 13 | /// @inheritdoc IPeripheryImmutableState 14 | address public immutable override WETH9; 15 | 16 | constructor(address _deployer, address _factory, address _WETH9) { 17 | deployer = _deployer; 18 | factory = _factory; 19 | WETH9 = _WETH9; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/v3-core/scripts/verify.ts: -------------------------------------------------------------------------------- 1 | import { verifyContract } from '@pancakeswap/common/verify' 2 | import { sleep } from '@pancakeswap/common/sleep' 3 | 4 | async function main() { 5 | const networkName = network.name 6 | const deployedContracts = await import(`@pancakeswap/v3-core/deployments/${networkName}.json`) 7 | 8 | // Verify PancakeV3PoolDeployer 9 | console.log('Verify PancakeV3PoolDeployer') 10 | await verifyContract(deployedContracts.PancakeV3PoolDeployer) 11 | await sleep(10000) 12 | 13 | // Verify pancakeV3Factory 14 | console.log('Verify pancakeV3Factory') 15 | await verifyContract(deployedContracts.PancakeV3Factory, [deployedContracts.PancakeV3PoolDeployer]) 16 | await sleep(10000) 17 | } 18 | 19 | main() 20 | .then(() => process.exit(0)) 21 | .catch((error) => { 22 | console.error(error) 23 | process.exit(1) 24 | }) 25 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/SwapMath.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SwapMath #computeSwapStep gas swap one for zero exact in capped 1`] = `1923`; 4 | 5 | exports[`SwapMath #computeSwapStep gas swap one for zero exact in partial 1`] = `2496`; 6 | 7 | exports[`SwapMath #computeSwapStep gas swap one for zero exact out capped 1`] = `1702`; 8 | 9 | exports[`SwapMath #computeSwapStep gas swap one for zero exact out partial 1`] = `2496`; 10 | 11 | exports[`SwapMath #computeSwapStep gas swap zero for one exact in capped 1`] = `1927`; 12 | 13 | exports[`SwapMath #computeSwapStep gas swap zero for one exact in partial 1`] = `2818`; 14 | 15 | exports[`SwapMath #computeSwapStep gas swap zero for one exact out capped 1`] = `1706`; 16 | 17 | exports[`SwapMath #computeSwapStep gas swap zero for one exact out partial 1`] = `2818`; 18 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/base/Multicall.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## Multicall 4 | 5 | Enables calling multiple methods in a single call to the contract 6 | 7 | ### multicall 8 | 9 | ```solidity 10 | function multicall(bytes[] data) public payable returns (bytes[] results) 11 | ``` 12 | 13 | Call multiple functions in the current contract and return the data from all of them if they all succeed 14 | 15 | _The `msg.value` should not be trusted for any method callable from multicall._ 16 | 17 | #### Parameters 18 | 19 | | Name | Type | Description | 20 | | ---- | ---- | ----------- | 21 | | data | bytes[] | The encoded function data for each of the calls to make to this contract | 22 | 23 | #### Return Values 24 | 25 | | Name | Type | Description | 26 | | ---- | ---- | ----------- | 27 | | results | bytes[] | The results from each of the calls passed in via data | 28 | 29 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/IMulticall.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IMulticall 4 | 5 | Enables calling multiple methods in a single call to the contract 6 | 7 | ### multicall 8 | 9 | ```solidity 10 | function multicall(bytes[] data) external payable returns (bytes[] results) 11 | ``` 12 | 13 | Call multiple functions in the current contract and return the data from all of them if they all succeed 14 | 15 | _The `msg.value` should not be trusted for any method callable from multicall._ 16 | 17 | #### Parameters 18 | 19 | | Name | Type | Description | 20 | | ---- | ---- | ----------- | 21 | | data | bytes[] | The encoded function data for each of the calls to make to this contract | 22 | 23 | #### Return Values 24 | 25 | | Name | Type | Description | 26 | | ---- | ---- | ----------- | 27 | | results | bytes[] | The results from each of the calls passed in via data | 28 | 29 | -------------------------------------------------------------------------------- /projects/v3-core/.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | run-linters: 11 | name: Run linters 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Check out Git repository 16 | uses: actions/checkout@v2 17 | 18 | - name: Set up node 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 12 22 | 23 | - name: Install dependencies 24 | run: yarn install --frozen-lockfile 25 | 26 | - name: Run linters 27 | uses: wearerequired/lint-action@a8497ddb33fb1205941fd40452ca9fff07e0770d 28 | with: 29 | github_token: ${{ secrets.github_token }} 30 | prettier: true 31 | auto_fix: true 32 | prettier_extensions: 'css,html,js,json,jsx,md,sass,scss,ts,tsx,vue,yaml,yml,sol' 33 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/SqrtPriceMath.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`SqrtPriceMath #getAmount0Delta gas cost for amount0 where roundUp = true 1`] = `547`; 4 | 5 | exports[`SqrtPriceMath #getAmount0Delta gas cost for amount0 where roundUp = true 2`] = `415`; 6 | 7 | exports[`SqrtPriceMath #getAmount1Delta gas cost for amount0 where roundUp = false 1`] = `415`; 8 | 9 | exports[`SqrtPriceMath #getAmount1Delta gas cost for amount0 where roundUp = true 1`] = `547`; 10 | 11 | exports[`SqrtPriceMath #getNextSqrtPriceFromInput zeroForOne = false gas 1`] = `464`; 12 | 13 | exports[`SqrtPriceMath #getNextSqrtPriceFromInput zeroForOne = true gas 1`] = `699`; 14 | 15 | exports[`SqrtPriceMath #getNextSqrtPriceFromOutput zeroForOne = false gas 1`] = `782`; 16 | 17 | exports[`SqrtPriceMath #getNextSqrtPriceFromOutput zeroForOne = true gas 1`] = `369`; 18 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/interfaces/IMasterChefV2.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IMasterChefV2 4 | 5 | ### deposit 6 | 7 | ```solidity 8 | function deposit(uint256 _pid, uint256 _amount) external 9 | ``` 10 | 11 | ### withdraw 12 | 13 | ```solidity 14 | function withdraw(uint256 _pid, uint256 _amount) external 15 | ``` 16 | 17 | ### pendingCake 18 | 19 | ```solidity 20 | function pendingCake(uint256 _pid, address _user) external view returns (uint256) 21 | ``` 22 | 23 | ### userInfo 24 | 25 | ```solidity 26 | function userInfo(uint256 _pid, address _user) external view returns (uint256, uint256, uint256) 27 | ``` 28 | 29 | ### emergencyWithdraw 30 | 31 | ```solidity 32 | function emergencyWithdraw(uint256 _pid) external 33 | ``` 34 | 35 | ### updateBoostMultiplier 36 | 37 | ```solidity 38 | function updateBoostMultiplier(address _user, uint256 _pid, uint256 _newBoostMulti) external 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/MockTimePancakeV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../PancakeV3Pool.sol'; 5 | 6 | // used for testing time dependent behavior 7 | contract MockTimePancakeV3Pool is PancakeV3Pool { 8 | // Monday, October 5, 2020 9:00:00 AM GMT-05:00 9 | uint256 public time = 1601906400; 10 | 11 | function setFeeGrowthGlobal0X128(uint256 _feeGrowthGlobal0X128) external { 12 | feeGrowthGlobal0X128 = _feeGrowthGlobal0X128; 13 | } 14 | 15 | function setFeeGrowthGlobal1X128(uint256 _feeGrowthGlobal1X128) external { 16 | feeGrowthGlobal1X128 = _feeGrowthGlobal1X128; 17 | } 18 | 19 | function advanceTime(uint256 by) external { 20 | time += by; 21 | } 22 | 23 | function _blockTimestamp() internal view override returns (uint32) { 24 | return uint32(time); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/INonfungibleTokenPositionDescriptor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import './INonfungiblePositionManager.sol'; 5 | 6 | /// @title Describes position NFT tokens via URI 7 | interface INonfungibleTokenPositionDescriptor { 8 | /// @notice Produces the URI describing a particular token ID for a position manager 9 | /// @dev Note this URI may be a data: URI with the JSON contents directly inlined 10 | /// @param positionManager The position manager for which to describe the token 11 | /// @param tokenId The ID of the token for which to produce a description, which may not be valid 12 | /// @return The URI of the ERC721-compliant metadata 13 | function tokenURI(INonfungiblePositionManager positionManager, uint256 tokenId) 14 | external 15 | view 16 | returns (string memory); 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TestERC20PermitAllowed.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import './TestERC20.sol'; 5 | import '../interfaces/external/IERC20PermitAllowed.sol'; 6 | 7 | // has a fake permit that just uses the other signature type for type(uint256).max 8 | contract TestERC20PermitAllowed is TestERC20, IERC20PermitAllowed { 9 | constructor(uint256 amountToMint) TestERC20(amountToMint) {} 10 | 11 | function permit( 12 | address holder, 13 | address spender, 14 | uint256 nonce, 15 | uint256 expiry, 16 | bool allowed, 17 | uint8 v, 18 | bytes32 r, 19 | bytes32 s 20 | ) external override { 21 | require(this.nonces(holder) == nonce, 'TestERC20PermitAllowed::permit: wrong nonce'); 22 | permit(holder, spender, allowed ? type(uint256).max : 0, expiry, v, r, s); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/TestPositionNFTOwner.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../interfaces/external/IERC1271.sol'; 5 | 6 | contract TestPositionNFTOwner is IERC1271 { 7 | address public owner; 8 | 9 | function setOwner(address _owner) external { 10 | owner = _owner; 11 | } 12 | 13 | function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4 magicValue) { 14 | bytes32 r; 15 | bytes32 s; 16 | uint8 v; 17 | assembly { 18 | r := mload(add(signature, 0x20)) 19 | s := mload(add(signature, 0x40)) 20 | v := byte(0, mload(add(signature, 0x60))) 21 | } 22 | if (ecrecover(hash, v, r, s) == owner) { 23 | return bytes4(0x1626ba7e); 24 | } else { 25 | return bytes4(0); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/lens/TickLens.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickLens 4 | 5 | ### getPopulatedTicksInWord 6 | 7 | ```solidity 8 | function getPopulatedTicksInWord(address pool, int16 tickBitmapIndex) public view returns (struct ITickLens.PopulatedTick[] populatedTicks) 9 | ``` 10 | 11 | Get all the tick data for the populated ticks from a word of the tick bitmap of a pool 12 | 13 | #### Parameters 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | pool | address | The address of the pool for which to fetch populated tick data | 18 | | tickBitmapIndex | int16 | The index of the word in the tick bitmap for which to parse the bitmap and fetch all the populated ticks | 19 | 20 | #### Return Values 21 | 22 | | Name | Type | Description | 23 | | ---- | ---- | ----------- | 24 | | populatedTicks | struct ITickLens.PopulatedTick[] | An array of tick data for the given word in the tick bitmap | 25 | 26 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TickBitmapTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickBitmapTest 4 | 5 | ### bitmap 6 | 7 | ```solidity 8 | mapping(int16 => uint256) bitmap 9 | ``` 10 | 11 | ### flipTick 12 | 13 | ```solidity 14 | function flipTick(int24 tick) external 15 | ``` 16 | 17 | ### getGasCostOfFlipTick 18 | 19 | ```solidity 20 | function getGasCostOfFlipTick(int24 tick) external returns (uint256) 21 | ``` 22 | 23 | ### nextInitializedTickWithinOneWord 24 | 25 | ```solidity 26 | function nextInitializedTickWithinOneWord(int24 tick, bool lte) external view returns (int24 next, bool initialized) 27 | ``` 28 | 29 | ### getGasCostOfNextInitializedTickWithinOneWord 30 | 31 | ```solidity 32 | function getGasCostOfNextInitializedTickWithinOneWord(int24 tick, bool lte) external view returns (uint256) 33 | ``` 34 | 35 | ### isInitialized 36 | 37 | ```solidity 38 | function isInitialized(int24 tick) external view returns (bool) 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/IERC20Metadata.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IERC20Metadata 4 | 5 | Extension to IERC20 that includes token metadata 6 | 7 | ### name 8 | 9 | ```solidity 10 | function name() external view returns (string) 11 | ``` 12 | 13 | #### Return Values 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | [0] | string | The name of the token | 18 | 19 | ### symbol 20 | 21 | ```solidity 22 | function symbol() external view returns (string) 23 | ``` 24 | 25 | #### Return Values 26 | 27 | | Name | Type | Description | 28 | | ---- | ---- | ----------- | 29 | | [0] | string | The symbol of the token | 30 | 31 | ### decimals 32 | 33 | ```solidity 34 | function decimals() external view returns (uint8) 35 | ``` 36 | 37 | #### Return Values 38 | 39 | | Name | Type | Description | 40 | | ---- | ---- | ----------- | 41 | | [0] | uint8 | The number of decimal places the token has | 42 | 43 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/TickMathTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TickMathTest 4 | 5 | ### getSqrtRatioAtTick 6 | 7 | ```solidity 8 | function getSqrtRatioAtTick(int24 tick) external pure returns (uint160) 9 | ``` 10 | 11 | ### getGasCostOfGetSqrtRatioAtTick 12 | 13 | ```solidity 14 | function getGasCostOfGetSqrtRatioAtTick(int24 tick) external view returns (uint256) 15 | ``` 16 | 17 | ### getTickAtSqrtRatio 18 | 19 | ```solidity 20 | function getTickAtSqrtRatio(uint160 sqrtPriceX96) external pure returns (int24) 21 | ``` 22 | 23 | ### getGasCostOfGetTickAtSqrtRatio 24 | 25 | ```solidity 26 | function getGasCostOfGetTickAtSqrtRatio(uint160 sqrtPriceX96) external view returns (uint256) 27 | ``` 28 | 29 | ### MIN_SQRT_RATIO 30 | 31 | ```solidity 32 | function MIN_SQRT_RATIO() external pure returns (uint160) 33 | ``` 34 | 35 | ### MAX_SQRT_RATIO 36 | 37 | ```solidity 38 | function MAX_SQRT_RATIO() external pure returns (uint160) 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/BitMathTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/BitMath.sol'; 5 | 6 | contract BitMathTest { 7 | function mostSignificantBit(uint256 x) external pure returns (uint8 r) { 8 | return BitMath.mostSignificantBit(x); 9 | } 10 | 11 | function getGasCostOfMostSignificantBit(uint256 x) external view returns (uint256) { 12 | uint256 gasBefore = gasleft(); 13 | BitMath.mostSignificantBit(x); 14 | return gasBefore - gasleft(); 15 | } 16 | 17 | function leastSignificantBit(uint256 x) external pure returns (uint8 r) { 18 | return BitMath.leastSignificantBit(x); 19 | } 20 | 21 | function getGasCostOfLeastSignificantBit(uint256 x) external view returns (uint256) { 22 | uint256 gasBefore = gasleft(); 23 | BitMath.leastSignificantBit(x); 24 | return gasBefore - gasleft(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /projects/v3-periphery/.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | run-linters: 11 | name: Run linters 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Check out Git repository 16 | uses: actions/checkout@v2 17 | 18 | - name: Set up node 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: 12.x 22 | registry-url: https://registry.npmjs.org 23 | 24 | - name: Install dependencies 25 | run: yarn install --frozen-lockfile 26 | 27 | - name: Run linters 28 | uses: wearerequired/lint-action@a8497ddb33fb1205941fd40452ca9fff07e0770d 29 | with: 30 | github_token: ${{ secrets.github_token }} 31 | prettier: true 32 | auto_fix: true 33 | prettier_extensions: 'css,html,js,json,jsx,md,sass,scss,ts,tsx,vue,yaml,yml,sol' 34 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/interfaces/IPancakeV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import './pool/IPancakeV3PoolImmutables.sol'; 5 | import './pool/IPancakeV3PoolState.sol'; 6 | import './pool/IPancakeV3PoolDerivedState.sol'; 7 | import './pool/IPancakeV3PoolActions.sol'; 8 | import './pool/IPancakeV3PoolOwnerActions.sol'; 9 | import './pool/IPancakeV3PoolEvents.sol'; 10 | 11 | /// @title The interface for a PancakeSwap V3 Pool 12 | /// @notice A PancakeSwap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IPancakeV3Pool is 16 | IPancakeV3PoolImmutables, 17 | IPancakeV3PoolState, 18 | IPancakeV3PoolDerivedState, 19 | IPancakeV3PoolActions, 20 | IPancakeV3PoolOwnerActions, 21 | IPancakeV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/LiquidityAmounts.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`LiquidityAmounts #getAmount0ForLiquidity gas 1`] = `352`; 4 | 5 | exports[`LiquidityAmounts #getAmountsForLiquidity gas for price above 1`] = `481`; 6 | 7 | exports[`LiquidityAmounts #getAmountsForLiquidity gas for price below 1`] = `502`; 8 | 9 | exports[`LiquidityAmounts #getAmountsForLiquidity gas for price inside 1`] = `840`; 10 | 11 | exports[`LiquidityAmounts #getLiquidityForAmount0 gas 1`] = `565`; 12 | 13 | exports[`LiquidityAmounts #getLiquidityForAmount1 gas 1`] = `362`; 14 | 15 | exports[`LiquidityAmounts #getLiquidityForAmount1 gas 2`] = `368`; 16 | 17 | exports[`LiquidityAmounts #getLiquidityForAmounts gas for price above 1`] = `537`; 18 | 19 | exports[`LiquidityAmounts #getLiquidityForAmounts gas for price below 1`] = `712`; 20 | 21 | exports[`LiquidityAmounts #getLiquidityForAmounts gas for price inside 1`] = `1162`; 22 | -------------------------------------------------------------------------------- /projects/masterchef-v3/docs/Enumerable.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## Enumerable 4 | 5 | This codes were copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol, and did some changes. 6 | 7 | _This implements an optional extension of defined in the EIP that adds 8 | enumerability of all the token ids in the contract as well as all token ids owned by each 9 | account._ 10 | 11 | ### tokenOfOwnerByIndex 12 | 13 | ```solidity 14 | function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) 15 | ``` 16 | 17 | ### balanceOf 18 | 19 | ```solidity 20 | function balanceOf(address owner) public view returns (uint256) 21 | ``` 22 | 23 | ### addToken 24 | 25 | ```solidity 26 | function addToken(address from, uint256 tokenId) internal 27 | ``` 28 | 29 | ### removeToken 30 | 31 | ```solidity 32 | function removeToken(address from, uint256 tokenId) internal 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/external/IERC1271.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Interface for verifying contract-based account signatures 5 | /// @notice Interface that verifies provided signature for the data 6 | /// @dev Interface defined by EIP-1271 7 | interface IERC1271 { 8 | /// @notice Returns whether the provided signature is valid for the provided data 9 | /// @dev MUST return the bytes4 magic value 0x1626ba7e when function passes. 10 | /// MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5). 11 | /// MUST allow external calls. 12 | /// @param hash Hash of the data to be signed 13 | /// @param signature Signature byte array associated with _data 14 | /// @return magicValue The bytes4 magic value 0x1626ba7e 15 | function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); 16 | } 17 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/INonfungibleTokenPositionDescriptor.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## INonfungibleTokenPositionDescriptor 4 | 5 | ### tokenURI 6 | 7 | ```solidity 8 | function tokenURI(contract INonfungiblePositionManager positionManager, uint256 tokenId) external view returns (string) 9 | ``` 10 | 11 | Produces the URI describing a particular token ID for a position manager 12 | 13 | _Note this URI may be a data: URI with the JSON contents directly inlined_ 14 | 15 | #### Parameters 16 | 17 | | Name | Type | Description | 18 | | ---- | ---- | ----------- | 19 | | positionManager | contract INonfungiblePositionManager | The position manager for which to describe the token | 20 | | tokenId | uint256 | The ID of the token for which to produce a description, which may not be valid | 21 | 22 | #### Return Values 23 | 24 | | Name | Type | Description | 25 | | ---- | ---- | ----------- | 26 | | [0] | string | The URI of the ERC721-compliant metadata | 27 | 28 | -------------------------------------------------------------------------------- /projects/masterchef-v3/contracts/utils/Multicall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.10; 3 | 4 | /// @title Multicall 5 | /// @notice Enables calling multiple methods in a single call to the contract 6 | contract Multicall { 7 | function multicall(bytes[] calldata data) public payable returns (bytes[] memory results) { 8 | results = new bytes[](data.length); 9 | for (uint256 i = 0; i < data.length; i++) { 10 | (bool success, bytes memory result) = address(this).delegatecall(data[i]); 11 | 12 | if (!success) { 13 | // Next 5 lines from https://ethereum.stackexchange.com/a/83577 14 | if (result.length < 68) revert(); 15 | assembly { 16 | result := add(result, 0x04) 17 | } 18 | revert(abi.decode(result, (string))); 19 | } 20 | 21 | results[i] = result; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/lens/PancakeInterfaceMulticall.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PancakeInterfaceMulticall 4 | 5 | A fork of Multicall2 specifically tailored for the Pancake Interface 6 | 7 | ### Call 8 | 9 | ```solidity 10 | struct Call { 11 | address target; 12 | uint256 gasLimit; 13 | bytes callData; 14 | } 15 | ``` 16 | 17 | ### Result 18 | 19 | ```solidity 20 | struct Result { 21 | bool success; 22 | uint256 gasUsed; 23 | bytes returnData; 24 | } 25 | ``` 26 | 27 | ### getCurrentBlockTimestamp 28 | 29 | ```solidity 30 | function getCurrentBlockTimestamp() public view returns (uint256 timestamp) 31 | ``` 32 | 33 | ### getEthBalance 34 | 35 | ```solidity 36 | function getEthBalance(address addr) public view returns (uint256 balance) 37 | ``` 38 | 39 | ### multicall 40 | 41 | ```solidity 42 | function multicall(struct PancakeInterfaceMulticall.Call[] calls) public returns (uint256 blockNumber, struct PancakeInterfaceMulticall.Result[] returnData) 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /v3-verify.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zx 2 | // import 'zx/globals' 3 | 4 | const networks = { 5 | eth: 'eth', 6 | goerli: 'goerli', 7 | bscMainnet: 'bscMainnet', 8 | bscTestnet: 'bscTestnet', 9 | hardhat: 'hardhat', 10 | } 11 | 12 | let network = process.env.NETWORK 13 | console.log(network, 'network') 14 | if (!network || !networks[network]) { 15 | throw new Error(`env NETWORK: ${network}`) 16 | } 17 | 18 | await $`yarn workspace @pancakeswap/v3-core run hardhat run scripts/verify.ts --network ${network}` 19 | 20 | await $`yarn workspace @pancakeswap/v3-periphery run hardhat run scripts/verify.ts --network ${network}` 21 | 22 | await $`yarn workspace @pancakeswap/smart-router run hardhat run scripts/verify.ts --network ${network}` 23 | 24 | await $`yarn workspace @pancakeswap/masterchef-v3 run hardhat run scripts/verify.ts --network ${network}` 25 | 26 | await $`yarn workspace @pancakeswap/v3-lm-pool run hardhat run scripts/verify.ts --network ${network}` 27 | 28 | console.log(chalk.blue('Done!')) 29 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/IPeripheryImmutableState.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPeripheryImmutableState 4 | 5 | Functions that return immutable state of the router 6 | 7 | ### deployer 8 | 9 | ```solidity 10 | function deployer() external view returns (address) 11 | ``` 12 | 13 | #### Return Values 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | [0] | address | Returns the address of the PancakeSwap V3 deployer | 18 | 19 | ### factory 20 | 21 | ```solidity 22 | function factory() external view returns (address) 23 | ``` 24 | 25 | #### Return Values 26 | 27 | | Name | Type | Description | 28 | | ---- | ---- | ----------- | 29 | | [0] | address | Returns the address of the PancakeSwap V3 factory | 30 | 31 | ### WETH9 32 | 33 | ```solidity 34 | function WETH9() external view returns (address) 35 | ``` 36 | 37 | #### Return Values 38 | 39 | | Name | Type | Description | 40 | | ---- | ---- | ----------- | 41 | | [0] | address | Returns the address of WETH9 | 42 | 43 | -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/IStableSwap.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | interface IStableSwap { 6 | // solium-disable-next-line mixedcase 7 | function get_dy( 8 | uint256 i, 9 | uint256 j, 10 | uint256 dx 11 | ) external view returns (uint256 dy); 12 | 13 | // solium-disable-next-line mixedcase 14 | function exchange( 15 | uint256 i, 16 | uint256 j, 17 | uint256 dx, 18 | uint256 minDy 19 | ) external payable; 20 | 21 | // solium-disable-next-line mixedcase 22 | function coins(uint256 i) external view returns (address); 23 | 24 | // solium-disable-next-line mixedcase 25 | function balances(uint256 i) external view returns (uint256); 26 | 27 | // solium-disable-next-line mixedcase 28 | function A() external view returns (uint256); 29 | 30 | // solium-disable-next-line mixedcase 31 | function fee() external view returns (uint256); 32 | } 33 | -------------------------------------------------------------------------------- /projects/router/docs/base/PeripheryPaymentsWithFeeExtended.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PeripheryPaymentsWithFeeExtended 4 | 5 | ### unwrapWETH9WithFee 6 | 7 | ```solidity 8 | function unwrapWETH9WithFee(uint256 amountMinimum, uint256 feeBips, address feeRecipient) external payable 9 | ``` 10 | 11 | Unwraps the contract's WETH9 balance and sends it to msg.sender as ETH, with a percentage between 12 | 0 (exclusive), and 1 (inclusive) going to feeRecipient 13 | 14 | _The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users._ 15 | 16 | ### sweepTokenWithFee 17 | 18 | ```solidity 19 | function sweepTokenWithFee(address token, uint256 amountMinimum, uint256 feeBips, address feeRecipient) external payable 20 | ``` 21 | 22 | Transfers the full amount of a token held by this contract to msg.sender, with a percentage between 23 | 0 (exclusive) and 1 (inclusive) going to feeRecipient 24 | 25 | _The amountMinimum parameter prevents malicious contracts from stealing the token from users_ 26 | 27 | -------------------------------------------------------------------------------- /projects/v3-core/.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | unit-tests: 11 | name: Unit Tests 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: 12.x 19 | 20 | - id: yarn-cache 21 | run: echo "::set-output name=dir::$(yarn cache dir)" 22 | 23 | - uses: actions/cache@v1 24 | with: 25 | path: ${{ steps.yarn-cache.outputs.dir }} 26 | key: yarn-${{ hashFiles('**/yarn.lock') }} 27 | restore-keys: | 28 | yarn- 29 | 30 | - name: Install dependencies 31 | run: yarn install --frozen-lockfile 32 | 33 | # This is required separately from yarn test because it generates the typechain definitions 34 | - name: Compile 35 | run: yarn compile 36 | 37 | - name: Run unit tests 38 | run: yarn test 39 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/computePoolAddress.ts: -------------------------------------------------------------------------------- 1 | import { bytecode } from '@pancakeswap/v3-core/artifacts/contracts/PancakeV3Pool.sol/PancakeV3Pool.json' 2 | import { utils } from 'ethers' 3 | 4 | export const POOL_BYTECODE_HASH = utils.keccak256(bytecode) 5 | 6 | export function computePoolAddress(deployerAddress: string, [tokenA, tokenB]: [string, string], fee: number): string { 7 | const [token0, token1] = tokenA.toLowerCase() < tokenB.toLowerCase() ? [tokenA, tokenB] : [tokenB, tokenA] 8 | const constructorArgumentsEncoded = utils.defaultAbiCoder.encode( 9 | ['address', 'address', 'uint24'], 10 | [token0, token1, fee] 11 | ) 12 | const create2Inputs = [ 13 | '0xff', 14 | deployerAddress, 15 | // salt 16 | utils.keccak256(constructorArgumentsEncoded), 17 | // init code hash 18 | POOL_BYTECODE_HASH, 19 | ] 20 | const sanitizedInputs = `0x${create2Inputs.map((i) => i.slice(2)).join('')}` 21 | return utils.getAddress(`0x${utils.keccak256(sanitizedInputs).slice(-40)}`) 22 | } 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/base/PeripheryPaymentsWithFee.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PeripheryPaymentsWithFee 4 | 5 | ### unwrapWETH9WithFee 6 | 7 | ```solidity 8 | function unwrapWETH9WithFee(uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) public payable 9 | ``` 10 | 11 | Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between 12 | 0 (exclusive), and 1 (inclusive) going to feeRecipient 13 | 14 | _The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users._ 15 | 16 | ### sweepTokenWithFee 17 | 18 | ```solidity 19 | function sweepTokenWithFee(address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) public payable 20 | ``` 21 | 22 | Transfers the full amount of a token held by this contract to recipient, with a percentage between 23 | 0 (exclusive) and 1 (inclusive) going to feeRecipient 24 | 25 | _The amountMinimum parameter prevents malicious contracts from stealing the token from users_ 26 | 27 | -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/IStableSwapFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | interface IStableSwapFactory { 6 | struct StableSwapPairInfo { 7 | address swapContract; 8 | address token0; 9 | address token1; 10 | address LPContract; 11 | } 12 | 13 | struct StableSwapThreePoolPairInfo { 14 | address swapContract; 15 | address token0; 16 | address token1; 17 | address token2; 18 | address LPContract; 19 | } 20 | 21 | // solium-disable-next-line mixedcase 22 | function pairLength() external view returns (uint256); 23 | 24 | function getPairInfo(address _tokenA, address _tokenB) 25 | external 26 | view 27 | returns (StableSwapPairInfo memory info); 28 | 29 | function getThreePoolPairInfo(address _tokenA, address _tokenB) 30 | external 31 | view 32 | returns (StableSwapThreePoolPairInfo memory info); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/external/IERC1271.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IERC1271 4 | 5 | Interface that verifies provided signature for the data 6 | 7 | _Interface defined by EIP-1271_ 8 | 9 | ### isValidSignature 10 | 11 | ```solidity 12 | function isValidSignature(bytes32 hash, bytes signature) external view returns (bytes4 magicValue) 13 | ``` 14 | 15 | Returns whether the provided signature is valid for the provided data 16 | 17 | _MUST return the bytes4 magic value 0x1626ba7e when function passes. 18 | MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5). 19 | MUST allow external calls._ 20 | 21 | #### Parameters 22 | 23 | | Name | Type | Description | 24 | | ---- | ---- | ----------- | 25 | | hash | bytes32 | Hash of the data to be signed | 26 | | signature | bytes | Signature byte array associated with _data | 27 | 28 | #### Return Values 29 | 30 | | Name | Type | Description | 31 | | ---- | ---- | ----------- | 32 | | magicValue | bytes4 | The bytes4 magic value 0x1626ba7e | 33 | 34 | -------------------------------------------------------------------------------- /projects/v3-core/_audits/tob/contracts/crytic/echidna/Other.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.7.6; 2 | 3 | import '../../../../../contracts/libraries/SqrtPriceMath.sol'; 4 | import '../../../../../contracts/libraries/TickMath.sol'; 5 | 6 | contract Other { 7 | // prop #30 8 | function test_getNextSqrtPriceFromInAndOutput( 9 | uint160 sqrtPX96, 10 | uint128 liquidity, 11 | uint256 amount, 12 | bool add 13 | ) public { 14 | require(sqrtPX96 >= TickMath.MIN_SQRT_RATIO && sqrtPX96 < TickMath.MAX_SQRT_RATIO); 15 | require(liquidity < 3121856577256316178563069792952001939); // max liquidity per tick 16 | uint256 next_sqrt = SqrtPriceMath.getNextSqrtPriceFromInput(sqrtPX96, liquidity, amount, add); 17 | assert(next_sqrt >= TickMath.MIN_SQRT_RATIO && next_sqrt < TickMath.MAX_SQRT_RATIO); 18 | next_sqrt = SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtPX96, liquidity, amount, add); 19 | assert(next_sqrt >= TickMath.MIN_SQRT_RATIO && next_sqrt < TickMath.MAX_SQRT_RATIO); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /projects/v3-core/docs/interfaces/callback/IPancakeV3MintCallback.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPancakeV3MintCallback 4 | 5 | Any contract that calls IPancakeV3PoolActions#mint must implement this interface 6 | 7 | ### pancakeV3MintCallback 8 | 9 | ```solidity 10 | function pancakeV3MintCallback(uint256 amount0Owed, uint256 amount1Owed, bytes data) external 11 | ``` 12 | 13 | Called to `msg.sender` after minting liquidity to a position from IPancakeV3Pool#mint. 14 | 15 | _In the implementation you must pay the pool tokens owed for the minted liquidity. 16 | The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory._ 17 | 18 | #### Parameters 19 | 20 | | Name | Type | Description | 21 | | ---- | ---- | ----------- | 22 | | amount0Owed | uint256 | The amount of token0 due to the pool for the minted liquidity | 23 | | amount1Owed | uint256 | The amount of token1 due to the pool for the minted liquidity | 24 | | data | bytes | Any data passed through by the caller via the IPancakeV3PoolActions#mint call | 25 | 26 | -------------------------------------------------------------------------------- /projects/v3-periphery/scripts/deployNonfungibleTokenDescriptorOffChainV2.ts: -------------------------------------------------------------------------------- 1 | import { ethers, upgrades } from 'hardhat' 2 | 3 | import NftDescriptorOffchainArtifact from '../artifacts/contracts/NonfungibleTokenPositionDescriptorOffChain.sol/NonfungibleTokenPositionDescriptorOffChain.json' 4 | 5 | async function main() { 6 | const [owner] = await ethers.getSigners() 7 | console.log('owner', owner.address) 8 | 9 | const NonfungibleTokenPositionDescriptor = await ethers.getContractFactoryFromArtifact(NftDescriptorOffchainArtifact) 10 | const baseTokenUri = 'https://nft.pancakeswap.com/v3/' 11 | const nonfungibleTokenPositionDescriptor = await upgrades.deployProxy(NonfungibleTokenPositionDescriptor, [ 12 | baseTokenUri, 13 | ]) 14 | await nonfungibleTokenPositionDescriptor.deployed() 15 | console.log('NonfungibleTokenPositionDescriptor deployed at', nonfungibleTokenPositionDescriptor.address) 16 | } 17 | 18 | main() 19 | .then(() => process.exit(0)) 20 | .catch((error) => { 21 | console.error(error) 22 | process.exit(1) 23 | }) 24 | -------------------------------------------------------------------------------- /projects/router/contracts/interfaces/IStableSwapRouter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | /// @title Router token swapping functionality 6 | /// @notice Functions for swapping tokens via Pancake Stable Swap 7 | interface IStableSwapRouter { 8 | /** 9 | * @param flag token amount in a stable swap pool. 2 for 2pool, 3 for 3pool 10 | */ 11 | function exactInputStableSwap( 12 | address[] calldata path, 13 | uint256[] calldata flag, 14 | uint256 amountIn, 15 | uint256 amountOutMin, 16 | address to 17 | ) external payable returns (uint256 amountOut); 18 | 19 | /** 20 | * @param flag token amount in a stable swap pool. 2 for 2pool, 3 for 3pool 21 | */ 22 | function exactOutputStableSwap( 23 | address[] calldata path, 24 | uint256[] calldata flag, 25 | uint256 amountOut, 26 | uint256 amountInMax, 27 | address to 28 | ) external payable returns (uint256 amountIn); 29 | } 30 | -------------------------------------------------------------------------------- /projects/v3-core/docs/interfaces/callback/IPancakeV3FlashCallback.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPancakeV3FlashCallback 4 | 5 | Any contract that calls IPancakeV3PoolActions#flash must implement this interface 6 | 7 | ### pancakeV3FlashCallback 8 | 9 | ```solidity 10 | function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes data) external 11 | ``` 12 | 13 | Called to `msg.sender` after transferring to the recipient from IPancakeV3Pool#flash. 14 | 15 | _In the implementation you must repay the pool the tokens sent by flash plus the computed fee amounts. 16 | The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory._ 17 | 18 | #### Parameters 19 | 20 | | Name | Type | Description | 21 | | ---- | ---- | ----------- | 22 | | fee0 | uint256 | The fee amount in token0 due to the pool by the end of the flash | 23 | | fee1 | uint256 | The fee amount in token1 due to the pool by the end of the flash | 24 | | data | bytes | Any data passed through by the caller via the IPancakeV3PoolActions#flash call | 25 | 26 | -------------------------------------------------------------------------------- /projects/v3-core/test/shared/snapshotGasCost.ts: -------------------------------------------------------------------------------- 1 | import { TransactionReceipt, TransactionResponse } from '@ethersproject/abstract-provider' 2 | import { expect } from './expect' 3 | import { Contract, BigNumber, ContractTransaction } from 'ethers' 4 | 5 | export default async function snapshotGasCost( 6 | x: 7 | | TransactionResponse 8 | | Promise 9 | | ContractTransaction 10 | | Promise 11 | | TransactionReceipt 12 | | Promise 13 | | BigNumber 14 | | Contract 15 | | Promise 16 | ): Promise { 17 | const resolved = await x 18 | if ('deployTransaction' in resolved) { 19 | const receipt = await resolved.deployTransaction.wait() 20 | expect(receipt.gasUsed.toNumber()).toMatchSnapshot() 21 | } else if ('wait' in resolved) { 22 | const waited = await resolved.wait() 23 | expect(waited.gasUsed.toNumber()).toMatchSnapshot() 24 | } else if (BigNumber.isBigNumber(resolved)) { 25 | expect(resolved.toNumber()).toMatchSnapshot() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IStableSwapFactory.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IStableSwapFactory 4 | 5 | ### StableSwapPairInfo 6 | 7 | ```solidity 8 | struct StableSwapPairInfo { 9 | address swapContract; 10 | address token0; 11 | address token1; 12 | address LPContract; 13 | } 14 | ``` 15 | 16 | ### StableSwapThreePoolPairInfo 17 | 18 | ```solidity 19 | struct StableSwapThreePoolPairInfo { 20 | address swapContract; 21 | address token0; 22 | address token1; 23 | address token2; 24 | address LPContract; 25 | } 26 | ``` 27 | 28 | ### pairLength 29 | 30 | ```solidity 31 | function pairLength() external view returns (uint256) 32 | ``` 33 | 34 | ### getPairInfo 35 | 36 | ```solidity 37 | function getPairInfo(address _tokenA, address _tokenB) external view returns (struct IStableSwapFactory.StableSwapPairInfo info) 38 | ``` 39 | 40 | ### getThreePoolPairInfo 41 | 42 | ```solidity 43 | function getThreePoolPairInfo(address _tokenA, address _tokenB) external view returns (struct IStableSwapFactory.StableSwapThreePoolPairInfo info) 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/formatSqrtRatioX96.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from 'ethers' 2 | import Decimal from 'decimal.js' 3 | 4 | const TWO = BigNumber.from(2) 5 | const TEN = BigNumber.from(10) 6 | const FIVE_SIG_FIGS_POW = new Decimal(10).pow(5) 7 | 8 | export function formatSqrtRatioX96( 9 | sqrtRatioX96: BigNumber | number, 10 | decimalsToken0: number = 18, 11 | decimalsToken1: number = 18 12 | ): string { 13 | Decimal.set({ toExpPos: 9_999_999, toExpNeg: -9_999_999 }) 14 | 15 | let ratioNum = ((parseInt(sqrtRatioX96.toString()) / 2 ** 96) ** 2).toPrecision(5) 16 | let ratio = new Decimal(ratioNum.toString()) 17 | 18 | // adjust for decimals 19 | if (decimalsToken1 < decimalsToken0) { 20 | ratio = ratio.mul(TEN.pow(decimalsToken0 - decimalsToken1).toString()) 21 | } else if (decimalsToken0 < decimalsToken1) { 22 | ratio = ratio.div(TEN.pow(decimalsToken1 - decimalsToken0).toString()) 23 | } 24 | 25 | if (ratio.lessThan(FIVE_SIG_FIGS_POW)) { 26 | return ratio.toPrecision(5) 27 | } 28 | 29 | return ratio.toString() 30 | } 31 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/shared/snapshotGasCost.ts: -------------------------------------------------------------------------------- 1 | import { TransactionReceipt, TransactionResponse } from '@ethersproject/abstract-provider' 2 | import { expect } from './expect' 3 | import { Contract, BigNumber, ContractTransaction } from 'ethers' 4 | 5 | export default async function snapshotGasCost( 6 | x: 7 | | TransactionResponse 8 | | Promise 9 | | ContractTransaction 10 | | Promise 11 | | TransactionReceipt 12 | | Promise 13 | | BigNumber 14 | | Contract 15 | | Promise 16 | ): Promise { 17 | const resolved = await x 18 | if ('deployTransaction' in resolved) { 19 | const receipt = await resolved.deployTransaction.wait() 20 | expect(receipt.gasUsed.toNumber()).toMatchSnapshot() 21 | } else if ('wait' in resolved) { 22 | const waited = await resolved.wait() 23 | expect(waited.gasUsed.toNumber()).toMatchSnapshot() 24 | } else if (BigNumber.isBigNumber(resolved)) { 25 | expect(resolved.toNumber()).toMatchSnapshot() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/TickMathEchidnaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/TickMath.sol'; 5 | 6 | contract TickMathEchidnaTest { 7 | // uniqueness and increasing order 8 | function checkGetSqrtRatioAtTickInvariants(int24 tick) external pure { 9 | uint160 ratio = TickMath.getSqrtRatioAtTick(tick); 10 | assert(TickMath.getSqrtRatioAtTick(tick - 1) < ratio && ratio < TickMath.getSqrtRatioAtTick(tick + 1)); 11 | assert(ratio >= TickMath.MIN_SQRT_RATIO); 12 | assert(ratio <= TickMath.MAX_SQRT_RATIO); 13 | } 14 | 15 | // the ratio is always between the returned tick and the returned tick+1 16 | function checkGetTickAtSqrtRatioInvariants(uint160 ratio) external pure { 17 | int24 tick = TickMath.getTickAtSqrtRatio(ratio); 18 | assert(ratio >= TickMath.getSqrtRatioAtTick(tick) && ratio < TickMath.getSqrtRatioAtTick(tick + 1)); 19 | assert(tick >= TickMath.MIN_TICK); 20 | assert(tick < TickMath.MAX_TICK); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | unit-tests: 11 | name: Unit Tests 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: 12.x 19 | registry-url: https://registry.npmjs.org 20 | 21 | - id: yarn-cache 22 | run: echo "::set-output name=dir::$(yarn cache dir)" 23 | 24 | - uses: actions/cache@v1 25 | with: 26 | path: ${{ steps.yarn-cache.outputs.dir }} 27 | key: yarn-${{ hashFiles('**/yarn.lock') }} 28 | restore-keys: | 29 | yarn- 30 | 31 | - name: Install dependencies 32 | run: yarn install --frozen-lockfile 33 | 34 | # This is required separately from yarn test because it generates the typechain definitions 35 | - name: Compile 36 | run: yarn compile 37 | 38 | - name: Run unit tests 39 | run: yarn test 40 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IPeripheryPaymentsWithFeeExtended.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPeripheryPaymentsWithFeeExtended 4 | 5 | Functions to ease deposits and withdrawals of ETH 6 | 7 | ### unwrapWETH9WithFee 8 | 9 | ```solidity 10 | function unwrapWETH9WithFee(uint256 amountMinimum, uint256 feeBips, address feeRecipient) external payable 11 | ``` 12 | 13 | Unwraps the contract's WETH9 balance and sends it to msg.sender as ETH, with a percentage between 14 | 0 (exclusive), and 1 (inclusive) going to feeRecipient 15 | 16 | _The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users._ 17 | 18 | ### sweepTokenWithFee 19 | 20 | ```solidity 21 | function sweepTokenWithFee(address token, uint256 amountMinimum, uint256 feeBips, address feeRecipient) external payable 22 | ``` 23 | 24 | Transfers the full amount of a token held by this contract to msg.sender, with a percentage between 25 | 0 (exclusive) and 1 (inclusive) going to feeRecipient 26 | 27 | _The amountMinimum parameter prevents malicious contracts from stealing the token from users_ 28 | 29 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import '../interfaces/IERC20Minimal.sol'; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), 'TF'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/PoolAddressTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/PoolAddress.sol'; 5 | 6 | contract PoolAddressTest { 7 | function POOL_INIT_CODE_HASH() external pure returns (bytes32) { 8 | return PoolAddress.POOL_INIT_CODE_HASH; 9 | } 10 | 11 | function computeAddress( 12 | address deployer, 13 | address token0, 14 | address token1, 15 | uint24 fee 16 | ) external pure returns (address) { 17 | return PoolAddress.computeAddress(deployer, PoolAddress.PoolKey({token0: token0, token1: token1, fee: fee})); 18 | } 19 | 20 | function getGasCostOfComputeAddress( 21 | address deployer, 22 | address token0, 23 | address token1, 24 | uint24 fee 25 | ) external view returns (uint256) { 26 | uint256 gasBefore = gasleft(); 27 | PoolAddress.computeAddress(deployer, PoolAddress.PoolKey({token0: token0, token1: token1, fee: fee})); 28 | return gasBefore - gasleft(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/NonfungibleTokenPositionDescriptorOffChain.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## NonfungibleTokenPositionDescriptorOffChain 4 | 5 | ### initialize 6 | 7 | ```solidity 8 | function initialize(string baseTokenURI) external 9 | ``` 10 | 11 | ### tokenURI 12 | 13 | ```solidity 14 | function tokenURI(contract INonfungiblePositionManager positionManager, uint256 tokenId) external view returns (string) 15 | ``` 16 | 17 | Produces the URI describing a particular token ID for a position manager 18 | 19 | _Note this URI may be a data: URI with the JSON contents directly inlined_ 20 | 21 | #### Parameters 22 | 23 | | Name | Type | Description | 24 | | ---- | ---- | ----------- | 25 | | positionManager | contract INonfungiblePositionManager | The position manager for which to describe the token | 26 | | tokenId | uint256 | The ID of the token for which to produce a description, which may not be valid | 27 | 28 | #### Return Values 29 | 30 | | Name | Type | Description | 31 | | ---- | ---- | ----------- | 32 | | [0] | string | The URI of the ERC721-compliant metadata | 33 | 34 | -------------------------------------------------------------------------------- /projects/v3-core/.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | issues: 4 | # Number of days of inactivity before an Issue or Pull Request becomes stale 5 | daysUntilStale: 7 6 | 7 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. 8 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. 9 | daysUntilClose: 7 10 | 11 | # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) 12 | onlyLabels: 13 | - question 14 | - autoclose 15 | 16 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 17 | exemptLabels: 18 | - p0 19 | - bug 20 | 21 | # Comment to post when marking as stale. Set to `false` to disable 22 | markComment: > 23 | This issue has been automatically marked as stale because it has not had 24 | recent activity. It will be closed if no further activity occurs. Thank you 25 | for your contributions. 26 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/scripts/verify.ts: -------------------------------------------------------------------------------- 1 | import { verifyContract } from '@pancakeswap/common/verify' 2 | import { sleep } from '@pancakeswap/common/sleep' 3 | import { configs } from '@pancakeswap/common/config' 4 | 5 | async function main() { 6 | const networkName = network.name 7 | const config = configs[networkName as keyof typeof configs] 8 | 9 | if (!config) { 10 | throw new Error(`No config found for network ${networkName}`) 11 | } 12 | const deployedContracts_masterchef_v3 = await import(`@pancakeswap/masterchef-v3/deployments/${networkName}.json`) 13 | const deployedContracts_v3_lm_pool = await import(`@pancakeswap/v3-lm-pool/deployments/${networkName}.json`) 14 | 15 | // Verify pancakeV3LmPoolDeployer 16 | console.log('Verify pancakeV3LmPoolDeployer') 17 | await verifyContract(deployedContracts_v3_lm_pool.PancakeV3LmPoolDeployer, [ 18 | deployedContracts_masterchef_v3.MasterChefV3, 19 | ]) 20 | await sleep(10000) 21 | } 22 | 23 | main() 24 | .then(() => process.exit(0)) 25 | .catch((error) => { 26 | console.error(error) 27 | process.exit(1) 28 | }) 29 | -------------------------------------------------------------------------------- /projects/v3-periphery/.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Configuration for probot-stale - https://github.com/probot/stale 2 | 3 | issues: 4 | # Number of days of inactivity before an Issue or Pull Request becomes stale 5 | daysUntilStale: 7 6 | 7 | # Number of days of inactivity before an Issue or Pull Request with the stale label is closed. 8 | # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. 9 | daysUntilClose: 7 10 | 11 | # Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) 12 | onlyLabels: 13 | - question 14 | - autoclose 15 | 16 | # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable 17 | exemptLabels: 18 | - p0 19 | - bug 20 | 21 | # Comment to post when marking as stale. Set to `false` to disable 22 | markComment: > 23 | This issue has been automatically marked as stale because it has not had 24 | recent activity. It will be closed if no further activity occurs. Thank you 25 | for your contributions. 26 | -------------------------------------------------------------------------------- /deployments/eth.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x556B9306565093C855AEA9AE92A594704c2Cd59e", 3 | "SmartRouter": "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", 4 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 5 | "MixedRouteQuoterV1": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86", 6 | "QuoterV2": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 7 | "TokenValidator": "0x864ED564875BdDD6F421e226494a0E7c071C06f8", 8 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 9 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9", 10 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 11 | "V3Migrator": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 12 | "TickLens": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 13 | "NonfungibleTokenPositionDescriptor": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227", 14 | "NonfungiblePositionManager": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 15 | "PancakeInterfaceMulticall": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea", 16 | "PancakeV3LmPoolDeployer": "0x769449da49D1Eb1FF44A6B366BE46960fDF46Ad6" 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-core/test/__snapshots__/TickBitmap.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`TickBitmap #flipTick gas cost of flipping a tick that results in deleting a word 1`] = `22053`; 4 | 5 | exports[`TickBitmap #flipTick gas cost of flipping first tick in word to initialized 1`] = `43965`; 6 | 7 | exports[`TickBitmap #flipTick gas cost of flipping second tick in word to initialized 1`] = `26865`; 8 | 9 | exports[`TickBitmap #nextInitializedTickWithinOneWord lte = false gas cost for entire word 1`] = `2627`; 10 | 11 | exports[`TickBitmap #nextInitializedTickWithinOneWord lte = false gas cost just below boundary 1`] = `2627`; 12 | 13 | exports[`TickBitmap #nextInitializedTickWithinOneWord lte = false gas cost on boundary 1`] = `2627`; 14 | 15 | exports[`TickBitmap #nextInitializedTickWithinOneWord lte = true gas cost for entire word 1`] = `2615`; 16 | 17 | exports[`TickBitmap #nextInitializedTickWithinOneWord lte = true gas cost just below boundary 1`] = `2925`; 18 | 19 | exports[`TickBitmap #nextInitializedTickWithinOneWord lte = true gas cost on boundary 1`] = `2615`; 20 | -------------------------------------------------------------------------------- /deployments/goerli.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x864ED564875BdDD6F421e226494a0E7c071C06f8", 3 | "SmartRouter": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 4 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 5 | "MixedRouteQuoterV1": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 6 | "QuoterV2": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 7 | "TokenValidator": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86", 8 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 9 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9", 10 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 11 | "V3Migrator": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 12 | "TickLens": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea", 13 | "NonfungibleTokenPositionDescriptor": "0xb099b459887bC759dBF0293E12D3DFcD0C456cff", 14 | "NonfungiblePositionManager": "0x427bF5b37357632377eCbEC9de3626C71A5396c1", 15 | "PancakeInterfaceMulticall": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227", 16 | "PancakeV3LmPoolDeployer": "0x556B9306565093C855AEA9AE92A594704c2Cd59e" 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/interfaces/callback/IPancakeV3FlashCallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Callback for IPancakeV3PoolActions#flash 5 | /// @notice Any contract that calls IPancakeV3PoolActions#flash must implement this interface 6 | interface IPancakeV3FlashCallback { 7 | /// @notice Called to `msg.sender` after transferring to the recipient from IPancakeV3Pool#flash. 8 | /// @dev In the implementation you must repay the pool the tokens sent by flash plus the computed fee amounts. 9 | /// The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory. 10 | /// @param fee0 The fee amount in token0 due to the pool by the end of the flash 11 | /// @param fee1 The fee amount in token1 due to the pool by the end of the flash 12 | /// @param data Any data passed through by the caller via the IPancakeV3PoolActions#flash call 13 | function pancakeV3FlashCallback( 14 | uint256 fee0, 15 | uint256 fee1, 16 | bytes calldata data 17 | ) external; 18 | } 19 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/interfaces/callback/IPancakeV3MintCallback.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Callback for IPancakeV3PoolActions#mint 5 | /// @notice Any contract that calls IPancakeV3PoolActions#mint must implement this interface 6 | interface IPancakeV3MintCallback { 7 | /// @notice Called to `msg.sender` after minting liquidity to a position from IPancakeV3Pool#mint. 8 | /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity. 9 | /// The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory. 10 | /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity 11 | /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity 12 | /// @param data Any data passed through by the caller via the IPancakeV3PoolActions#mint call 13 | function pancakeV3MintCallback( 14 | uint256 amount0Owed, 15 | uint256 amount1Owed, 16 | bytes calldata data 17 | ) external; 18 | } 19 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/IPeripheryPaymentsWithFee.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPeripheryPaymentsWithFee 4 | 5 | Functions to ease deposits and withdrawals of ETH 6 | 7 | ### unwrapWETH9WithFee 8 | 9 | ```solidity 10 | function unwrapWETH9WithFee(uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) external payable 11 | ``` 12 | 13 | Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between 14 | 0 (exclusive), and 1 (inclusive) going to feeRecipient 15 | 16 | _The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users._ 17 | 18 | ### sweepTokenWithFee 19 | 20 | ```solidity 21 | function sweepTokenWithFee(address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient) external payable 22 | ``` 23 | 24 | Transfers the full amount of a token held by this contract to recipient, with a percentage between 25 | 0 (exclusive) and 1 (inclusive) going to feeRecipient 26 | 27 | _The amountMinimum parameter prevents malicious contracts from stealing the token from users_ 28 | 29 | -------------------------------------------------------------------------------- /deployments/bscMainnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x556B9306565093C855AEA9AE92A594704c2Cd59e", 3 | "SmartRouter": "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4", 4 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 5 | "MixedRouteQuoterV1": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86", 6 | "QuoterV2": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 7 | "TokenValidator": "0x864ED564875BdDD6F421e226494a0E7c071C06f8", 8 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 9 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9", 10 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 11 | "V3Migrator": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 12 | "TickLens": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 13 | "NonfungibleTokenPositionDescriptor": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227", 14 | "NonfungiblePositionManager": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 15 | "PancakeInterfaceMulticall": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea", 16 | "PancakeV3LmPoolDeployer": "0x769449da49D1Eb1FF44A6B366BE46960fDF46Ad6" 17 | } 18 | -------------------------------------------------------------------------------- /deployments/bscTestnet.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x4c650FB471fe4e0f476fD3437C3411B1122c4e3B", 3 | "SmartRouter": "0x9a489505a00cE272eAa5e07Dba6491314CaE3796", 4 | "SmartRouterHelper": "0xdAecee3C08e953Bd5f89A5Cc90ac560413d709E3", 5 | "MixedRouteQuoterV1": "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997", 6 | "QuoterV2": "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2", 7 | "TokenValidator": "0x678Aa4bF4E210cf2166753e054d5b7c31cc7fa86", 8 | "PancakeV3Factory": "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865", 9 | "PancakeV3PoolDeployer": "0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9", 10 | "SwapRouter": "0x1b81D678ffb9C0263b24A97847620C99d213eB14", 11 | "V3Migrator": "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364", 12 | "TickLens": "0xac1cE734566f390A94b00eb9bf561c2625BF44ea", 13 | "NonfungibleTokenPositionDescriptor": "0xb099b459887bC759dBF0293E12D3DFcD0C456cff", 14 | "NonfungiblePositionManager": "0x427bF5b37357632377eCbEC9de3626C71A5396c1", 15 | "PancakeInterfaceMulticall": "0x3D00CdB4785F0ef20C903A13596e0b9B2c652227", 16 | "PancakeV3LmPoolDeployer": "0x864ED564875BdDD6F421e226494a0E7c071C06f8" 17 | } 18 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/TickEchidnaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/Tick.sol'; 5 | 6 | contract TickEchidnaTest { 7 | function checkTickSpacingToParametersInvariants(int24 tickSpacing) external pure { 8 | require(tickSpacing <= TickMath.MAX_TICK); 9 | require(tickSpacing > 0); 10 | 11 | int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing; 12 | int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing; 13 | 14 | uint128 maxLiquidityPerTick = Tick.tickSpacingToMaxLiquidityPerTick(tickSpacing); 15 | 16 | // symmetry around 0 tick 17 | assert(maxTick == -minTick); 18 | // positive max tick 19 | assert(maxTick > 0); 20 | // divisibility 21 | assert((maxTick - minTick) % tickSpacing == 0); 22 | 23 | uint256 numTicks = uint256((maxTick - minTick) / tickSpacing) + 1; 24 | // max liquidity at every tick is less than the cap 25 | assert(uint256(maxLiquidityPerTick) * numTicks <= type(uint128).max); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TestPositionNFTOwner.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestPositionNFTOwner 4 | 5 | ### owner 6 | 7 | ```solidity 8 | address owner 9 | ``` 10 | 11 | ### setOwner 12 | 13 | ```solidity 14 | function setOwner(address _owner) external 15 | ``` 16 | 17 | ### isValidSignature 18 | 19 | ```solidity 20 | function isValidSignature(bytes32 hash, bytes signature) external view returns (bytes4 magicValue) 21 | ``` 22 | 23 | Returns whether the provided signature is valid for the provided data 24 | 25 | _MUST return the bytes4 magic value 0x1626ba7e when function passes. 26 | MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5). 27 | MUST allow external calls._ 28 | 29 | #### Parameters 30 | 31 | | Name | Type | Description | 32 | | ---- | ---- | ----------- | 33 | | hash | bytes32 | Hash of the data to be signed | 34 | | signature | bytes | Signature byte array associated with _data | 35 | 36 | #### Return Values 37 | 38 | | Name | Type | Description | 39 | | ---- | ---- | ----------- | 40 | | magicValue | bytes4 | The bytes4 magic value 0x1626ba7e | 41 | 42 | -------------------------------------------------------------------------------- /projects/router/contracts/SmartRouter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '@pancakeswap/v3-periphery/contracts/base/SelfPermit.sol'; 6 | import '@pancakeswap/v3-periphery/contracts/base/PeripheryImmutableState.sol'; 7 | 8 | import './interfaces/ISmartRouter.sol'; 9 | import './V2SwapRouter.sol'; 10 | import './V3SwapRouter.sol'; 11 | import './StableSwapRouter.sol'; 12 | import './base/ApproveAndCall.sol'; 13 | import './base/MulticallExtended.sol'; 14 | 15 | /// @title Pancake Smart Router 16 | contract SmartRouter is ISmartRouter, V2SwapRouter, V3SwapRouter, StableSwapRouter, ApproveAndCall, MulticallExtended, SelfPermit { 17 | constructor( 18 | address _factoryV2, 19 | address _deployer, 20 | address _factoryV3, 21 | address _positionManager, 22 | address _stableFactory, 23 | address _stableInfo, 24 | address _WETH9 25 | ) ImmutableState(_factoryV2, _positionManager) PeripheryImmutableState(_deployer, _factoryV3, _WETH9) StableSwapRouter(_stableFactory, _stableInfo) {} 26 | } 27 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/base/Multicall.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '../interfaces/IMulticall.sol'; 6 | 7 | /// @title Multicall 8 | /// @notice Enables calling multiple methods in a single call to the contract 9 | abstract contract Multicall is IMulticall { 10 | /// @inheritdoc IMulticall 11 | function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) { 12 | results = new bytes[](data.length); 13 | for (uint256 i = 0; i < data.length; i++) { 14 | (bool success, bytes memory result) = address(this).delegatecall(data[i]); 15 | 16 | if (!success) { 17 | // Next 5 lines from https://ethereum.stackexchange.com/a/83577 18 | if (result.length < 68) revert(); 19 | assembly { 20 | result := add(result, 0x04) 21 | } 22 | revert(abi.decode(result, (string))); 23 | } 24 | 25 | results[i] = result; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /projects/v3-lm-pool/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@pancakeswap/v3-lm-pool", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "compile": "hardhat compile", 8 | "test": "echo 'skip'" 9 | }, 10 | "devDependencies": { 11 | "@ethersproject/abi": "^5.4.7", 12 | "@ethersproject/providers": "^5.4.7", 13 | "@nomicfoundation/hardhat-chai-matchers": "^1.0.0", 14 | "@nomicfoundation/hardhat-network-helpers": "^1.0.0", 15 | "@nomicfoundation/hardhat-toolbox": "^2.0.0", 16 | "@nomiclabs/hardhat-ethers": "^2.0.0", 17 | "@nomiclabs/hardhat-etherscan": "^3.0.0", 18 | "@pancakeswap/v3-core": "*", 19 | "@typechain/ethers-v5": "^10.2.0", 20 | "@typechain/hardhat": "^6.1.5", 21 | "@types/chai": "^4.2.0", 22 | "@types/mocha": ">=9.1.0", 23 | "@types/node": ">=12.0.0", 24 | "chai": "^4.2.0", 25 | "ethers": "^5.4.7", 26 | "hardhat": "^2.12.6", 27 | "hardhat-gas-reporter": "^1.0.8", 28 | "solidity-coverage": "^0.8.0", 29 | "ts-node": ">=8.0.0", 30 | "typechain": "^8.1.1", 31 | "typescript": ">=4.5.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /projects/masterchef-v3/scripts/verify.ts: -------------------------------------------------------------------------------- 1 | import { verifyContract } from "@pancakeswap/common/verify"; 2 | import { sleep } from "@pancakeswap/common/sleep"; 3 | import { configs } from "@pancakeswap/common/config"; 4 | 5 | async function main() { 6 | const networkName = network.name; 7 | const config = configs[networkName as keyof typeof configs]; 8 | 9 | if (!config) { 10 | throw new Error(`No config found for network ${networkName}`); 11 | } 12 | const deployedContracts_masterchef_v3 = await import(`@pancakeswap/masterchef-v3/deployments/${networkName}.json`); 13 | const deployedContracts_v3_periphery = await import(`@pancakeswap/v3-periphery/deployments/${networkName}.json`); 14 | 15 | // Verify masterChefV3 16 | console.log("Verify masterChefV3"); 17 | await verifyContract(deployedContracts_masterchef_v3.MasterChefV3, [ 18 | config.cake, 19 | deployedContracts_v3_periphery.NonfungiblePositionManager, 20 | config.WNATIVE, 21 | ]); 22 | await sleep(10000); 23 | } 24 | 25 | main() 26 | .then(() => process.exit(0)) 27 | .catch((error) => { 28 | console.error(error); 29 | process.exit(1); 30 | }); 31 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/test/PathTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/Path.sol'; 5 | 6 | contract PathTest { 7 | function hasMultiplePools(bytes memory path) public pure returns (bool) { 8 | return Path.hasMultiplePools(path); 9 | } 10 | 11 | function decodeFirstPool(bytes memory path) 12 | public 13 | pure 14 | returns ( 15 | address tokenA, 16 | address tokenB, 17 | uint24 fee 18 | ) 19 | { 20 | return Path.decodeFirstPool(path); 21 | } 22 | 23 | function getFirstPool(bytes memory path) public pure returns (bytes memory) { 24 | return Path.getFirstPool(path); 25 | } 26 | 27 | function skipToken(bytes memory path) public pure returns (bytes memory) { 28 | return Path.skipToken(path); 29 | } 30 | 31 | // gas funcs 32 | function getGasCostOfDecodeFirstPool(bytes memory path) public view returns (uint256) { 33 | uint256 gasBefore = gasleft(); 34 | Path.decodeFirstPool(path); 35 | return gasBefore - gasleft(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/SwapMathTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/SwapMath.sol'; 5 | 6 | contract SwapMathTest { 7 | function computeSwapStep( 8 | uint160 sqrtP, 9 | uint160 sqrtPTarget, 10 | uint128 liquidity, 11 | int256 amountRemaining, 12 | uint24 feePips 13 | ) 14 | external 15 | pure 16 | returns ( 17 | uint160 sqrtQ, 18 | uint256 amountIn, 19 | uint256 amountOut, 20 | uint256 feeAmount 21 | ) 22 | { 23 | return SwapMath.computeSwapStep(sqrtP, sqrtPTarget, liquidity, amountRemaining, feePips); 24 | } 25 | 26 | function getGasCostOfComputeSwapStep( 27 | uint160 sqrtP, 28 | uint160 sqrtPTarget, 29 | uint128 liquidity, 30 | int256 amountRemaining, 31 | uint24 feePips 32 | ) external view returns (uint256) { 33 | uint256 gasBefore = gasleft(); 34 | SwapMath.computeSwapStep(sqrtP, sqrtPTarget, liquidity, amountRemaining, feePips); 35 | return gasBefore - gasleft(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/MockTimePancakeV3PoolDeployer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../interfaces/IPancakeV3PoolDeployer.sol'; 5 | 6 | import './MockTimePancakeV3Pool.sol'; 7 | 8 | contract MockTimePancakeV3PoolDeployer is IPancakeV3PoolDeployer { 9 | struct Parameters { 10 | address factory; 11 | address token0; 12 | address token1; 13 | uint24 fee; 14 | int24 tickSpacing; 15 | } 16 | 17 | Parameters public override parameters; 18 | 19 | event PoolDeployed(address pool); 20 | 21 | function deploy( 22 | address factory, 23 | address token0, 24 | address token1, 25 | uint24 fee, 26 | int24 tickSpacing 27 | ) external override returns (address pool) { 28 | parameters = Parameters({factory: factory, token0: token0, token1: token1, fee: fee, tickSpacing: tickSpacing}); 29 | pool = address( 30 | new MockTimePancakeV3Pool{salt: keccak256(abi.encodePacked(token0, token1, fee, tickSpacing))}() 31 | ); 32 | emit PoolDeployed(pool); 33 | delete parameters; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/NonfungibleTokenPositionDescriptorOffChain.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '@openzeppelin/contracts-upgradeable/proxy/Initializable.sol'; 6 | import '@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol'; 7 | 8 | import './interfaces/INonfungibleTokenPositionDescriptor.sol'; 9 | 10 | /// @title Describes NFT token positions 11 | contract NonfungibleTokenPositionDescriptorOffChain is INonfungibleTokenPositionDescriptor, Initializable { 12 | using StringsUpgradeable for uint256; 13 | 14 | string private _baseTokenURI; 15 | 16 | function initialize(string calldata baseTokenURI) external initializer { 17 | _baseTokenURI = baseTokenURI; 18 | } 19 | 20 | /// @inheritdoc INonfungibleTokenPositionDescriptor 21 | function tokenURI(INonfungiblePositionManager positionManager, uint256 tokenId) 22 | external 23 | view 24 | override 25 | returns (string memory) 26 | { 27 | return bytes(_baseTokenURI).length > 0 ? string(abi.encodePacked(_baseTokenURI, tokenId.toString())) : ""; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /projects/router/contracts/base/MulticallExtended.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity =0.7.6; 3 | pragma abicoder v2; 4 | 5 | import '@pancakeswap/v3-periphery/contracts/base/Multicall.sol'; 6 | 7 | import '../interfaces/IMulticallExtended.sol'; 8 | import '../base/PeripheryValidationExtended.sol'; 9 | 10 | /// @title Multicall 11 | /// @notice Enables calling multiple methods in a single call to the contract 12 | abstract contract MulticallExtended is IMulticallExtended, Multicall, PeripheryValidationExtended { 13 | /// @inheritdoc IMulticallExtended 14 | function multicall(uint256 deadline, bytes[] calldata data) 15 | external 16 | payable 17 | override 18 | checkDeadline(deadline) 19 | returns (bytes[] memory) 20 | { 21 | return multicall(data); 22 | } 23 | 24 | /// @inheritdoc IMulticallExtended 25 | function multicall(bytes32 previousBlockhash, bytes[] calldata data) 26 | external 27 | payable 28 | override 29 | checkPreviousBlockhash(previousBlockhash) 30 | returns (bytes[] memory) 31 | { 32 | return multicall(data); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/base/PoolInitializer.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PoolInitializer 4 | 5 | ### createAndInitializePoolIfNecessary 6 | 7 | ```solidity 8 | function createAndInitializePoolIfNecessary(address token0, address token1, uint24 fee, uint160 sqrtPriceX96) external payable returns (address pool) 9 | ``` 10 | 11 | Creates a new pool if it does not exist, then initializes if not initialized 12 | 13 | _This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool_ 14 | 15 | #### Parameters 16 | 17 | | Name | Type | Description | 18 | | ---- | ---- | ----------- | 19 | | token0 | address | The contract address of token0 of the pool | 20 | | token1 | address | The contract address of token1 of the pool | 21 | | fee | uint24 | The fee amount of the v3 pool for the specified token pair | 22 | | sqrtPriceX96 | uint160 | The initial square root price of the pool as a Q64.96 value | 23 | 24 | #### Return Values 25 | 26 | | Name | Type | Description | 27 | | ---- | ---- | ----------- | 28 | | pool | address | Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary | 29 | 30 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /projects/router/contracts/base/PeripheryPaymentsWithFeeExtended.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.5; 3 | 4 | import '@pancakeswap/v3-periphery/contracts/base/PeripheryPaymentsWithFee.sol'; 5 | 6 | import '../interfaces/IPeripheryPaymentsWithFeeExtended.sol'; 7 | import './PeripheryPaymentsExtended.sol'; 8 | 9 | abstract contract PeripheryPaymentsWithFeeExtended is 10 | IPeripheryPaymentsWithFeeExtended, 11 | PeripheryPaymentsExtended, 12 | PeripheryPaymentsWithFee 13 | { 14 | /// @inheritdoc IPeripheryPaymentsWithFeeExtended 15 | function unwrapWETH9WithFee( 16 | uint256 amountMinimum, 17 | uint256 feeBips, 18 | address feeRecipient 19 | ) external payable override { 20 | unwrapWETH9WithFee(amountMinimum, msg.sender, feeBips, feeRecipient); 21 | } 22 | 23 | /// @inheritdoc IPeripheryPaymentsWithFeeExtended 24 | function sweepTokenWithFee( 25 | address token, 26 | uint256 amountMinimum, 27 | uint256 feeBips, 28 | address feeRecipient 29 | ) external payable override { 30 | sweepTokenWithFee(token, amountMinimum, msg.sender, feeBips, feeRecipient); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /projects/router/docs/interfaces/IStableSwapRouter.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IStableSwapRouter 4 | 5 | Functions for swapping tokens via Pancake Stable Swap 6 | 7 | ### exactInputStableSwap 8 | 9 | ```solidity 10 | function exactInputStableSwap(address[] path, uint256[] flag, uint256 amountIn, uint256 amountOutMin, address to) external payable returns (uint256 amountOut) 11 | ``` 12 | 13 | #### Parameters 14 | 15 | | Name | Type | Description | 16 | | ---- | ---- | ----------- | 17 | | path | address[] | | 18 | | flag | uint256[] | token amount in a stable swap pool. 2 for 2pool, 3 for 3pool | 19 | | amountIn | uint256 | | 20 | | amountOutMin | uint256 | | 21 | | to | address | | 22 | 23 | ### exactOutputStableSwap 24 | 25 | ```solidity 26 | function exactOutputStableSwap(address[] path, uint256[] flag, uint256 amountOut, uint256 amountInMax, address to) external payable returns (uint256 amountIn) 27 | ``` 28 | 29 | #### Parameters 30 | 31 | | Name | Type | Description | 32 | | ---- | ---- | ----------- | 33 | | path | address[] | | 34 | | flag | uint256[] | token amount in a stable swap pool. 2 for 2pool, 3 for 3pool | 35 | | amountOut | uint256 | | 36 | | amountInMax | uint256 | | 37 | | to | address | | 38 | 39 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/ITickLens.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.5; 3 | pragma abicoder v2; 4 | 5 | /// @title Tick Lens 6 | /// @notice Provides functions for fetching chunks of tick data for a pool 7 | /// @dev This avoids the waterfall of fetching the tick bitmap, parsing the bitmap to know which ticks to fetch, and 8 | /// then sending additional multicalls to fetch the tick data 9 | interface ITickLens { 10 | struct PopulatedTick { 11 | int24 tick; 12 | int128 liquidityNet; 13 | uint128 liquidityGross; 14 | } 15 | 16 | /// @notice Get all the tick data for the populated ticks from a word of the tick bitmap of a pool 17 | /// @param pool The address of the pool for which to fetch populated tick data 18 | /// @param tickBitmapIndex The index of the word in the tick bitmap for which to parse the bitmap and 19 | /// fetch all the populated ticks 20 | /// @return populatedTicks An array of tick data for the given word in the tick bitmap 21 | function getPopulatedTicksInWord(address pool, int16 tickBitmapIndex) 22 | external 23 | view 24 | returns (PopulatedTick[] memory populatedTicks); 25 | } 26 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/V3Migrator.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## V3Migrator 4 | 5 | ### nonfungiblePositionManager 6 | 7 | ```solidity 8 | address nonfungiblePositionManager 9 | ``` 10 | 11 | ### constructor 12 | 13 | ```solidity 14 | constructor(address _deployer, address _factory, address _WETH9, address _nonfungiblePositionManager) public 15 | ``` 16 | 17 | ### receive 18 | 19 | ```solidity 20 | receive() external payable 21 | ``` 22 | 23 | ### migrate 24 | 25 | ```solidity 26 | function migrate(struct IV3Migrator.MigrateParams params) external 27 | ``` 28 | 29 | Migrates liquidity to v3 by burning v2 liquidity and minting a new position for v3 30 | 31 | _Slippage protection is enforced via `amount{0,1}Min`, which should be a discount of the expected values of 32 | the maximum amount of v3 liquidity that the v2 liquidity can get. For the special case of migrating to an 33 | out-of-range position, `amount{0,1}Min` may be set to 0, enforcing that the position remains out of range_ 34 | 35 | #### Parameters 36 | 37 | | Name | Type | Description | 38 | | ---- | ---- | ----------- | 39 | | params | struct IV3Migrator.MigrateParams | The params necessary to migrate v2 liquidity, encoded as `MigrateParams` in calldata | 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/LowGasSafeMathEchidnaTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/LowGasSafeMath.sol'; 5 | 6 | contract LowGasSafeMathEchidnaTest { 7 | function checkAdd(uint256 x, uint256 y) external pure { 8 | uint256 z = LowGasSafeMath.add(x, y); 9 | assert(z == x + y); 10 | assert(z >= x && z >= y); 11 | } 12 | 13 | function checkSub(uint256 x, uint256 y) external pure { 14 | uint256 z = LowGasSafeMath.sub(x, y); 15 | assert(z == x - y); 16 | assert(z <= x); 17 | } 18 | 19 | function checkMul(uint256 x, uint256 y) external pure { 20 | uint256 z = LowGasSafeMath.mul(x, y); 21 | assert(z == x * y); 22 | assert(x == 0 || y == 0 || (z >= x && z >= y)); 23 | } 24 | 25 | function checkAddi(int256 x, int256 y) external pure { 26 | int256 z = LowGasSafeMath.add(x, y); 27 | assert(z == x + y); 28 | assert(y < 0 ? z < x : z >= x); 29 | } 30 | 31 | function checkSubi(int256 x, int256 y) external pure { 32 | int256 z = LowGasSafeMath.sub(x, y); 33 | assert(z == x - y); 34 | assert(y < 0 ? z > x : z <= x); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /projects/v3-core/docs/test/MockTimePancakeV3PoolDeployer.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## MockTimePancakeV3PoolDeployer 4 | 5 | ### Parameters 6 | 7 | ```solidity 8 | struct Parameters { 9 | address factory; 10 | address token0; 11 | address token1; 12 | uint24 fee; 13 | int24 tickSpacing; 14 | } 15 | ``` 16 | 17 | ### parameters 18 | 19 | ```solidity 20 | struct MockTimePancakeV3PoolDeployer.Parameters parameters 21 | ``` 22 | 23 | Get the parameters to be used in constructing the pool, set transiently during pool creation. 24 | 25 | _Called by the pool constructor to fetch the parameters of the pool 26 | Returns factory The factory address 27 | Returns token0 The first token of the pool by address sort order 28 | Returns token1 The second token of the pool by address sort order 29 | Returns fee The fee collected upon every swap in the pool, denominated in hundredths of a bip 30 | Returns tickSpacing The minimum number of ticks between initialized ticks_ 31 | 32 | ### PoolDeployed 33 | 34 | ```solidity 35 | event PoolDeployed(address pool) 36 | ``` 37 | 38 | ### deploy 39 | 40 | ```solidity 41 | function deploy(address factory, address token0, address token1, uint24 fee, int24 tickSpacing) external returns (address pool) 42 | ``` 43 | 44 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/PositionValueTest.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## PositionValueTest 4 | 5 | ### total 6 | 7 | ```solidity 8 | function total(contract INonfungiblePositionManager nft, uint256 tokenId, uint160 sqrtRatioX96) external view returns (uint256 amount0, uint256 amount1) 9 | ``` 10 | 11 | ### principal 12 | 13 | ```solidity 14 | function principal(contract INonfungiblePositionManager nft, uint256 tokenId, uint160 sqrtRatioX96) external view returns (uint256 amount0, uint256 amount1) 15 | ``` 16 | 17 | ### fees 18 | 19 | ```solidity 20 | function fees(contract INonfungiblePositionManager nft, uint256 tokenId) external view returns (uint256 amount0, uint256 amount1) 21 | ``` 22 | 23 | ### totalGas 24 | 25 | ```solidity 26 | function totalGas(contract INonfungiblePositionManager nft, uint256 tokenId, uint160 sqrtRatioX96) external view returns (uint256) 27 | ``` 28 | 29 | ### principalGas 30 | 31 | ```solidity 32 | function principalGas(contract INonfungiblePositionManager nft, uint256 tokenId, uint160 sqrtRatioX96) external view returns (uint256) 33 | ``` 34 | 35 | ### feesGas 36 | 37 | ```solidity 38 | function feesGas(contract INonfungiblePositionManager nft, uint256 tokenId) external view returns (uint256) 39 | ``` 40 | 41 | -------------------------------------------------------------------------------- /projects/v3-core/contracts/test/TickMathTest.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: UNLICENSED 2 | pragma solidity =0.7.6; 3 | 4 | import '../libraries/TickMath.sol'; 5 | 6 | contract TickMathTest { 7 | function getSqrtRatioAtTick(int24 tick) external pure returns (uint160) { 8 | return TickMath.getSqrtRatioAtTick(tick); 9 | } 10 | 11 | function getGasCostOfGetSqrtRatioAtTick(int24 tick) external view returns (uint256) { 12 | uint256 gasBefore = gasleft(); 13 | TickMath.getSqrtRatioAtTick(tick); 14 | return gasBefore - gasleft(); 15 | } 16 | 17 | function getTickAtSqrtRatio(uint160 sqrtPriceX96) external pure returns (int24) { 18 | return TickMath.getTickAtSqrtRatio(sqrtPriceX96); 19 | } 20 | 21 | function getGasCostOfGetTickAtSqrtRatio(uint160 sqrtPriceX96) external view returns (uint256) { 22 | uint256 gasBefore = gasleft(); 23 | TickMath.getTickAtSqrtRatio(sqrtPriceX96); 24 | return gasBefore - gasleft(); 25 | } 26 | 27 | function MIN_SQRT_RATIO() external pure returns (uint160) { 28 | return TickMath.MIN_SQRT_RATIO; 29 | } 30 | 31 | function MAX_SQRT_RATIO() external pure returns (uint160) { 32 | return TickMath.MAX_SQRT_RATIO; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/external/IERC20PermitAllowed.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IERC20PermitAllowed 4 | 5 | Interface used by DAI/CHAI for permit 6 | 7 | ### permit 8 | 9 | ```solidity 10 | function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external 11 | ``` 12 | 13 | Approve the spender to spend some tokens via the holder signature 14 | 15 | _This is the permit interface used by DAI and CHAI_ 16 | 17 | #### Parameters 18 | 19 | | Name | Type | Description | 20 | | ---- | ---- | ----------- | 21 | | holder | address | The address of the token holder, the token owner | 22 | | spender | address | The address of the token spender | 23 | | nonce | uint256 | The holder's nonce, increases at each call to permit | 24 | | expiry | uint256 | The timestamp at which the permit is no longer valid | 25 | | allowed | bool | Boolean that sets approval amount, true for type(uint256).max and false for 0 | 26 | | v | uint8 | Must produce valid secp256k1 signature from the holder along with `r` and `s` | 27 | | r | bytes32 | Must produce valid secp256k1 signature from the holder along with `v` and `s` | 28 | | s | bytes32 | Must produce valid secp256k1 signature from the holder along with `r` and `v` | 29 | 30 | -------------------------------------------------------------------------------- /projects/v3-core/scripts/deploy_outputCodeHash.ts: -------------------------------------------------------------------------------- 1 | import bn from "bignumber.js"; 2 | import { Contract, ContractFactory, utils, BigNumber } from "ethers"; 3 | import { ethers, waffle } from "hardhat"; 4 | 5 | const WBNB = "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd"; // BSC TESTNET 6 | 7 | type ContractJson = { abi: any; bytecode: string }; 8 | const artifacts: { [name: string]: ContractJson } = { 9 | // eslint-disable-next-line global-require 10 | OutputCodeHash: require("../artifacts/contracts/test/OutputCodeHash.sol/OutputCodeHash.json"), 11 | }; 12 | 13 | async function main() { 14 | const [owner] = await ethers.getSigners(); 15 | const provider = waffle.provider; 16 | console.log("owner", owner.address); 17 | 18 | const OutputCodeHash = new ContractFactory( 19 | artifacts.OutputCodeHash.abi, 20 | artifacts.OutputCodeHash.bytecode, 21 | owner 22 | ); 23 | const outputCodeHash = await OutputCodeHash.deploy(); 24 | console.log("outputCodeHash", outputCodeHash.address); 25 | 26 | // deployer must set factory address 27 | const hash = await outputCodeHash.getInitCodeHash(); 28 | console.log('hash: ', hash); 29 | } 30 | 31 | main() 32 | .then(() => process.exit(0)) 33 | .catch((error) => { 34 | console.error(error); 35 | process.exit(1); 36 | }); 37 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/IPoolInitializer.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.5; 3 | pragma abicoder v2; 4 | 5 | /// @title Creates and initializes V3 Pools 6 | /// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that 7 | /// require the pool to exist. 8 | interface IPoolInitializer { 9 | /// @notice Creates a new pool if it does not exist, then initializes if not initialized 10 | /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool 11 | /// @param token0 The contract address of token0 of the pool 12 | /// @param token1 The contract address of token1 of the pool 13 | /// @param fee The fee amount of the v3 pool for the specified token pair 14 | /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value 15 | /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary 16 | function createAndInitializePoolIfNecessary( 17 | address token0, 18 | address token1, 19 | uint24 fee, 20 | uint160 sqrtPriceX96 21 | ) external payable returns (address pool); 22 | } 23 | -------------------------------------------------------------------------------- /projects/v3-periphery/scripts/upgradeNonfungibleTokenDescriptorOffChainV2.ts: -------------------------------------------------------------------------------- 1 | import { ethers, upgrades } from 'hardhat' 2 | 3 | import NftDescriptorOffchainV2Artifact from '../artifacts/contracts/NonfungibleTokenPositionDescriptorOffChainV2.sol/NonfungibleTokenPositionDescriptorOffChainV2.json' 4 | 5 | async function main() { 6 | const [owner] = await ethers.getSigners() 7 | console.log('owner', owner.address) 8 | 9 | const network = await ethers.provider.getNetwork() 10 | 11 | const NonfungibleTokenPositionDescriptorV2 = await ethers.getContractFactoryFromArtifact( 12 | NftDescriptorOffchainV2Artifact 13 | ) 14 | const baseTokenUri = `https://nft.pancakeswap.com/v3/${network.chainId}/` 15 | console.log(baseTokenUri) 16 | const nonfungibleTokenPositionDescriptor = await upgrades.upgradeProxy( 17 | process.env.NFT_DESC_OFFCHAIN_ADDRESS!, 18 | NonfungibleTokenPositionDescriptorV2, 19 | { 20 | call: { 21 | fn: 'initializeV2', 22 | args: [baseTokenUri], 23 | }, 24 | } 25 | ) 26 | console.log('NonfungibleTokenPositionDescriptor upgraded at', nonfungibleTokenPositionDescriptor.address) 27 | } 28 | 29 | main() 30 | .then(() => process.exit(0)) 31 | .catch((error) => { 32 | console.error(error) 33 | process.exit(1) 34 | }) 35 | -------------------------------------------------------------------------------- /projects/v3-periphery/test/__snapshots__/Base64.spec.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Base64 #encode gas cost of encode() 1`] = `1497`; 4 | 5 | exports[`Base64 #encode gas cost of encode(aLpHaBeT) 1`] = `1256`; 6 | 7 | exports[`Base64 #encode gas cost of encode(alphabet soup) 1`] = `1727`; 8 | 9 | exports[`Base64 #encode gas cost of encode(f) 1`] = `763`; 10 | 11 | exports[`Base64 #encode gas cost of encode(fo) 1`] = `774`; 12 | 13 | exports[`Base64 #encode gas cost of encode(foo) 1`] = `769`; 14 | 15 | exports[`Base64 #encode gas cost of encode(foob) 1`] = `1004`; 16 | 17 | exports[`Base64 #encode gas cost of encode(fooba) 1`] = `1015`; 18 | 19 | exports[`Base64 #encode gas cost of encode(foobar) 1`] = `1010`; 20 | 21 | exports[`Base64 #encode gas cost of encode(includes 22 | newlines) 1`] = `1979`; 23 | 24 | exports[`Base64 #encode gas cost of encode(test string) 1`] = `1497`; 25 | 26 | exports[`Base64 #encode gas cost of encode(this is a test) 1`] = `1738`; 27 | 28 | exports[`Base64 #encode gas cost of encode(this is a very long string that should cost a lot of gas to encode :)) 1`] = `6083`; 29 | 30 | exports[`Base64 #encode gas cost of encode(😀) 1`] = `1004`; 31 | 32 | exports[`Base64 #encode max size string (24kB) gas cost 1`] = `3731900`; 33 | -------------------------------------------------------------------------------- /projects/v3-core/test/shared/checkObservationEquals.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber, BigNumberish } from 'ethers' 2 | import { expect } from './expect' 3 | 4 | // helper function because we cannot do a simple deep equals with the 5 | // observation result object returned from ethers because it extends array 6 | export default function checkObservationEquals( 7 | { 8 | tickCumulative, 9 | blockTimestamp, 10 | initialized, 11 | secondsPerLiquidityCumulativeX128, 12 | }: { 13 | tickCumulative: BigNumber 14 | secondsPerLiquidityCumulativeX128: BigNumber 15 | initialized: boolean 16 | blockTimestamp: number 17 | }, 18 | expected: { 19 | tickCumulative: BigNumberish 20 | secondsPerLiquidityCumulativeX128: BigNumberish 21 | initialized: boolean 22 | blockTimestamp: number 23 | } 24 | ) { 25 | expect( 26 | { 27 | initialized, 28 | blockTimestamp, 29 | tickCumulative: tickCumulative.toString(), 30 | secondsPerLiquidityCumulativeX128: secondsPerLiquidityCumulativeX128.toString(), 31 | }, 32 | `observation is equivalent` 33 | ).to.deep.eq({ 34 | ...expected, 35 | tickCumulative: expected.tickCumulative.toString(), 36 | secondsPerLiquidityCumulativeX128: expected.secondsPerLiquidityCumulativeX128.toString(), 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /projects/v3-core/docs/interfaces/IPancakeV3PoolDeployer.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPancakeV3PoolDeployer 4 | 5 | A contract that constructs a pool must implement this to pass arguments to the pool 6 | 7 | _This is used to avoid having constructor arguments in the pool contract, which results in the init code hash 8 | of the pool being constant allowing the CREATE2 address of the pool to be cheaply computed on-chain_ 9 | 10 | ### parameters 11 | 12 | ```solidity 13 | function parameters() external view returns (address factory, address token0, address token1, uint24 fee, int24 tickSpacing) 14 | ``` 15 | 16 | Get the parameters to be used in constructing the pool, set transiently during pool creation. 17 | 18 | _Called by the pool constructor to fetch the parameters of the pool 19 | Returns factory The factory address 20 | Returns token0 The first token of the pool by address sort order 21 | Returns token1 The second token of the pool by address sort order 22 | Returns fee The fee collected upon every swap in the pool, denominated in hundredths of a bip 23 | Returns tickSpacing The minimum number of ticks between initialized ticks_ 24 | 25 | ### deploy 26 | 27 | ```solidity 28 | function deploy(address factory, address token0, address token1, uint24 fee, int24 tickSpacing) external returns (address pool) 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/TestERC20PermitAllowed.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## TestERC20PermitAllowed 4 | 5 | ### constructor 6 | 7 | ```solidity 8 | constructor(uint256 amountToMint) public 9 | ``` 10 | 11 | ### permit 12 | 13 | ```solidity 14 | function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external 15 | ``` 16 | 17 | Approve the spender to spend some tokens via the holder signature 18 | 19 | _This is the permit interface used by DAI and CHAI_ 20 | 21 | #### Parameters 22 | 23 | | Name | Type | Description | 24 | | ---- | ---- | ----------- | 25 | | holder | address | The address of the token holder, the token owner | 26 | | spender | address | The address of the token spender | 27 | | nonce | uint256 | The holder's nonce, increases at each call to permit | 28 | | expiry | uint256 | The timestamp at which the permit is no longer valid | 29 | | allowed | bool | Boolean that sets approval amount, true for type(uint256).max and false for 0 | 30 | | v | uint8 | Must produce valid secp256k1 signature from the holder along with `r` and `s` | 31 | | r | bytes32 | Must produce valid secp256k1 signature from the holder along with `v` and `s` | 32 | | s | bytes32 | Must produce valid secp256k1 signature from the holder along with `r` and `v` | 33 | 34 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/test/MockObservations.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## MockObservations 4 | 5 | ### oracleObservations 6 | 7 | ```solidity 8 | struct Oracle.Observation[4] oracleObservations 9 | ``` 10 | 11 | ### slot0Tick 12 | 13 | ```solidity 14 | int24 slot0Tick 15 | ``` 16 | 17 | ### slot0ObservationCardinality 18 | 19 | ```solidity 20 | uint16 slot0ObservationCardinality 21 | ``` 22 | 23 | ### slot0ObservationIndex 24 | 25 | ```solidity 26 | uint16 slot0ObservationIndex 27 | ``` 28 | 29 | ### liquidity 30 | 31 | ```solidity 32 | uint128 liquidity 33 | ``` 34 | 35 | ### lastObservationCurrentTimestamp 36 | 37 | ```solidity 38 | bool lastObservationCurrentTimestamp 39 | ``` 40 | 41 | ### constructor 42 | 43 | ```solidity 44 | constructor(uint32[4] _blockTimestamps, int56[4] _tickCumulatives, uint128[4] _secondsPerLiquidityCumulativeX128s, bool[4] _initializeds, int24 _tick, uint16 _observationCardinality, uint16 _observationIndex, bool _lastObservationCurrentTimestamp, uint128 _liquidity) public 45 | ``` 46 | 47 | ### slot0 48 | 49 | ```solidity 50 | function slot0() external view returns (uint160, int24, uint16, uint16, uint16, uint8, bool) 51 | ``` 52 | 53 | ### observations 54 | 55 | ```solidity 56 | function observations(uint256 index) external view returns (uint32, int56, uint160, bool) 57 | ``` 58 | 59 | -------------------------------------------------------------------------------- /deployments/hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "MasterChefV3": "0x5FbDB2315678afecb367f032d93F642f64180aa3", 3 | "SmartRouter": "0x5579c645590c58E6421341394f82B5b38080cDEA", 4 | "SmartRouterHelper": "0xA2b9C533b5333c1fEc593DA3Dbe1229627490622", 5 | "MixedRouteQuoterV1": "0x0a7DE23cF80aBA83Ca5d4a429D80E1224b3dCC91", 6 | "QuoterV2": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6", 7 | "TokenValidator": "0x023108300557958e6eEf0DCc69e2D3804A6F13a1", 8 | "PancakeV3Factory": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", 9 | "PancakeV3PoolDeployer": "0x5FbDB2315678afecb367f032d93F642f64180aa3", 10 | "PancakeV3FactoryOwner": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", 11 | "SwapRouter": "0x5FbDB2315678afecb367f032d93F642f64180aa3", 12 | "V3Migrator": "0x0165878A594ca255338adfa4d48449f69242Eb8F", 13 | "TickLens": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853", 14 | "ProxyAdmin": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", 15 | "TransparentUpgradeableProxy": "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", 16 | "NonfungibleTokenPositionDescriptor": "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", 17 | "NonfungiblePositionManager": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", 18 | "PancakeInterfaceMulticall": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707", 19 | "PancakeV3LmPoolDeployer": "0x5FbDB2315678afecb367f032d93F642f64180aa3" 20 | } 21 | -------------------------------------------------------------------------------- /projects/v3-core/docs/interfaces/callback/IPancakeV3SwapCallback.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPancakeV3SwapCallback 4 | 5 | Any contract that calls IPancakeV3PoolActions#swap must implement this interface 6 | 7 | ### pancakeV3SwapCallback 8 | 9 | ```solidity 10 | function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes data) external 11 | ``` 12 | 13 | Called to `msg.sender` after executing a swap via IPancakeV3Pool#swap. 14 | 15 | _In the implementation you must pay the pool tokens owed for the swap. 16 | The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory. 17 | amount0Delta and amount1Delta can both be 0 if no tokens were swapped._ 18 | 19 | #### Parameters 20 | 21 | | Name | Type | Description | 22 | | ---- | ---- | ----------- | 23 | | amount0Delta | int256 | The amount of token0 that was sent (negative) or must be received (positive) by the pool by the end of the swap. If positive, the callback must send that amount of token0 to the pool. | 24 | | amount1Delta | int256 | The amount of token1 that was sent (negative) or must be received (positive) by the pool by the end of the swap. If positive, the callback must send that amount of token1 to the pool. | 25 | | data | bytes | Any data passed through by the caller via the IPancakeV3PoolActions#swap call | 26 | 27 | -------------------------------------------------------------------------------- /projects/v3-periphery/docs/interfaces/IPoolInitializer.md: -------------------------------------------------------------------------------- 1 | # Solidity API 2 | 3 | ## IPoolInitializer 4 | 5 | Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that 6 | require the pool to exist. 7 | 8 | ### createAndInitializePoolIfNecessary 9 | 10 | ```solidity 11 | function createAndInitializePoolIfNecessary(address token0, address token1, uint24 fee, uint160 sqrtPriceX96) external payable returns (address pool) 12 | ``` 13 | 14 | Creates a new pool if it does not exist, then initializes if not initialized 15 | 16 | _This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool_ 17 | 18 | #### Parameters 19 | 20 | | Name | Type | Description | 21 | | ---- | ---- | ----------- | 22 | | token0 | address | The contract address of token0 of the pool | 23 | | token1 | address | The contract address of token1 of the pool | 24 | | fee | uint24 | The fee amount of the v3 pool for the specified token pair | 25 | | sqrtPriceX96 | uint160 | The initial square root price of the pool as a Q64.96 value | 26 | 27 | #### Return Values 28 | 29 | | Name | Type | Description | 30 | | ---- | ---- | ----------- | 31 | | pool | address | Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary | 32 | 33 | -------------------------------------------------------------------------------- /projects/v3-periphery/contracts/interfaces/IPeripheryPaymentsWithFee.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.5; 3 | 4 | import './IPeripheryPayments.sol'; 5 | 6 | /// @title Periphery Payments 7 | /// @notice Functions to ease deposits and withdrawals of ETH 8 | interface IPeripheryPaymentsWithFee is IPeripheryPayments { 9 | /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between 10 | /// 0 (exclusive), and 1 (inclusive) going to feeRecipient 11 | /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. 12 | function unwrapWETH9WithFee( 13 | uint256 amountMinimum, 14 | address recipient, 15 | uint256 feeBips, 16 | address feeRecipient 17 | ) external payable; 18 | 19 | /// @notice Transfers the full amount of a token held by this contract to recipient, with a percentage between 20 | /// 0 (exclusive) and 1 (inclusive) going to feeRecipient 21 | /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users 22 | function sweepTokenWithFee( 23 | address token, 24 | uint256 amountMinimum, 25 | address recipient, 26 | uint256 feeBips, 27 | address feeRecipient 28 | ) external payable; 29 | } 30 | --------------------------------------------------------------------------------