Skip to content

primus-labs/panacakeswapv4-cex-trading-hooks

Repository files navigation

CEX Trading Hooks For PancakeSwap V4

Overview

This repository provides a simple guide for CEX trading hooks, enabling users to verify their 30-day CEX spot trading volume to qualify for a swap fee discount. If a user verifies and submits a successful 30-day CEX trading volume exceeding the threshold of 10k to the BNB Chain, the hook contract will validate the information. When the user performs a swap on PancakeSwap, the contract will apply a fee discount—currently set at 50%—once the conditions are confirmed to be met.

The user can generate a CEX trading proof through an external link on the Swap page, which redirects them to a dApp page utilizing the Primus zkTLS capability to complete the data verification process. Throughout the entire process, the user’s privacy is fully protected.

image

Prerequisite

Install foundry, see https://book.getfoundry.sh/getting-started/installation.

Install

Get the repo:

git clone --recursive https://github.com/primus-labs/pancake-transaction-oracle-hooks.git
cd pancake-transaction-oracle-hooks
forge install
forge build

Primus AttestionRegistry

This contract records the attestation results generated by users as proof that their 30-day CEX spot trading volume, using the Primus zkTLS capability.

The AttestationRegistry contract is used to register the attestation contract.

Below is a detailed introduction to the contract.

AttestationRegistry Contract

CLExchangeVolumeHook

This is the CLHook.

The CLExchangeVolumeHook implements the afterInitialize and beforeSwap hooks.

This is a detailed introduction to the contract: CLExchangeVolumeHook Contract

BinExchangeVolumeHook

This is the BinHook.

The BinExchangeVolumeHook implements the afterInitialize and beforeSwap hooks.

This is a detailed introduction to the contract: BinExchangeVolumeHook Contract

Test Guide

Please follow the steps below to perform the test.

Configurations

Configure the contract address, private key, RPC, and other settings.

  1. Copy ./.env.bsc-testnet to ./.env, and set your private key (PRIVATE_KEY).
  2. The following parameters are already set:

Deployment

Deploy the test token and the test Hook contract.

  • Deploy Token
source .env
forge script script/DeployToken.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

output (sample):

TOKEN0=0x772F5b156EDaa4874F3f4F81c5e4479EE7E1669B
TOKEN1=0x7AA33Aa23aB75D37A9c27B0ba51bb10ed6e41a51

Add/replace the above address in .env.


  • Deploy AttestationRegistry
source .env
forge script script/attestation/AttestationRegistry.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

output (sample):

ATTESTATION_REGISTRY=0x6c2270298b1e6046898a322acB3Cbad6F99f7CBD

  • Deploy Hook
source .env
forge script script/pool-cl/DeployHook.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

output (sample):

HOOK=0xd9Dd1FEaF845Dd036245A504317cCccE7Bc18f49

Add/replace the above address in .env.

Initialize Pool

source .env
forge script script/pool-cl/Test.s.sol:TestInitializeScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --gas-estimate-multiplier 600 --broadcast

This command only needs to be executed once.


Transfer Token (Optional)

Request some tokens from the Token owner. (If needed.)

source .env
export RECEIVER=<the receiver address>
# export RECEIVER=0x...
forge script script/Transfer.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Token Approve

Before performing a swap test, make sure to approve the token first.

source .env
forge script script/pool-cl/Approve.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Add Liquidity

source .env
forge script script/pool-cl/Test.s.sol:TestAddLiquidityScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

Test Swap

source .env
forge script script/pool-cl/Test.s.sol:TestSwapScript --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published