Skip to content

Commit

Permalink
Merge pull request #156 from bancorprotocol/81-add-support-for-pancak…
Browse files Browse the repository at this point in the history
…eswap-on-ethereum-exchange

81 add support for pancakeswap on ethereum exchange
  • Loading branch information
mikewcasale authored Oct 12, 2023
2 parents 5efb66c + e7bf624 commit b2b436e
Show file tree
Hide file tree
Showing 37 changed files with 6,924 additions and 356 deletions.
2 changes: 1 addition & 1 deletion fastlane_bot/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Config():
LL_WARN = S.LOGLEVEL_WARNING
LL_ERR = S.LOGLEVEL_ERROR

SUPPORTED_EXCHANGES = ['carbon_v1', 'bancor_v2', 'bancor_v3', 'uniswap_v2', 'uniswap_v3', 'sushiswap_v2', 'bancor_pol']
SUPPORTED_EXCHANGES = ['carbon_v1', 'bancor_v2', 'bancor_v3', 'uniswap_v2', 'uniswap_v3', 'sushiswap_v2', 'bancor_pol', 'pancakeswap_v2', 'pancakeswap_v3']
connection = EthereumNetwork(
network_id=NETWORK_ID,
network_name=NETWORK_NAME,
Expand Down
116 changes: 98 additions & 18 deletions fastlane_bot/config/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,31 @@ class ConfigNetwork(ConfigBase):
UNISWAP_V3_NAME = "uniswap_v3"
SUSHISWAP_V2_NAME = "sushiswap_v2"
CARBON_V1_NAME = "carbon_v1"
BANCOR_POL_NAME = "bancor_pol"
CARBON_POL_NAME = "bancor_pol"
PANCAKESWAP_V2_NAME = "pancakeswap_v2"
PANCAKESWAP_V3_NAME = "pancakeswap_v3"
BALANCER_NAME = "balancer"
BANCOR_POL_NAME = "bancor_pol"
SUSHISWAP_V3_NAME = "sushiswap_v3"
SHIBA_V2_NAME = "shiba_v2"
EXCHANGE_IDS = {
CARBON_V1_NAME: 6,
UNISWAP_V2_NAME: 3,
UNISWAP_V3_NAME: 4,
BANCOR_V2_NAME: 1,
BANCOR_V3_NAME: 2,
UNISWAP_V2_NAME: 3,
UNISWAP_V3_NAME: 4,
SUSHISWAP_V2_NAME: 5,
CARBON_V1_NAME: 6,
BALANCER_NAME: 7,
BANCOR_POL_NAME: 8,
CARBON_POL_NAME: 8,
}
UNI_V2_FORKS = [UNISWAP_V2_NAME, SUSHISWAP_V2_NAME]
UNI_V3_FORKS = [UNISWAP_V3_NAME]
UNI_V2_FORKS = [UNISWAP_V2_NAME, SUSHISWAP_V2_NAME, PANCAKESWAP_V2_NAME, SHIBA_V2_NAME]
UNI_V3_FORKS = [UNISWAP_V3_NAME, SUSHISWAP_V3_NAME, PANCAKESWAP_V3_NAME, ]

UNI_V2_FEE_MAPPING = {UNISWAP_V2_NAME: 0.003, SUSHISWAP_V2_NAME: 0.0025, PANCAKESWAP_V2_NAME: 0.0025}

SUPPORTED_EXCHANGES = list(EXCHANGE_IDS)
MULTICALLABLE_EXCHANGES = [BANCOR_V3_NAME, BANCOR_POL_NAME, BALANCER_NAME]
# BANCOR POL
# TODO ADD BLOCK CONTRACT WAS CREATED
BANCOR_POL_START_BLOCK = 18184448
BANCOR_POL_ADDRESS = "0xD06146D292F9651C1D7cf54A3162791DFc2bEf46"

Expand Down Expand Up @@ -152,18 +159,48 @@ class _ConfigNetworkMainnet(ConfigNetwork):
BANCOR_V3_NETWORK_INFO_ADDRESS = "0x8E303D296851B320e6a697bAcB979d13c9D6E760"
BANCOR_V3_NETWORK_ADDRESS = "0xeEF417e1D5CC832e619ae18D2F140De2999dD4fB"
BANCOR_V3_NETWORK_SETTINGS = "0x83E1814ba31F7ea95D216204BB45FE75Ce09b14F"
UNISWAP_V2_FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
UNISWAP_V2_ROUTER_ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
SUSHISWAP_FACTORY_ADDRESS = "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac"
UNISWAP_V3_FACTORY_ADDRESS = "0x1F98431c8aD98523631AE4a59f267346ea31F984"
BANCOR_V3_VAULT = "0x649765821D9f64198c905eC0B2B037a4a52Bc373"
BANCOR_V3_POOL_COLLECTOR_ADDRESS = "0xde1B3CcfC45e3F5bff7f43516F2Cd43364D883E4"
BANCOR_V2_CONVERTER_REGISTRY_ADDRESS = "0xC0205e203F423Bcd8B2a4d6f8C8A154b0Aa60F19"
# FASTLANE_CONTRACT_ADDRESS = "0x51a6D03B156af044bda570CF35a919DB851Cebd1"
FASTLANE_CONTRACT_ADDRESS = "0x41Eeba3355d7D6FF628B7982F3F9D055c39488cB"
CARBON_CONTROLLER_ADDRESS = "0xC537e898CD774e2dCBa3B14Ea6f34C93d5eA45e1"
CARBON_CONTROLLER_VOUCHER = "0x3660F04B79751e31128f6378eAC70807e38f554E"
MULTICALL_CONTRACT_ADDRESS = "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
BANCOR_V3_VAULT = "0x649765821D9f64198c905eC0B2B037a4a52Bc373"

# Uniswap
UNISWAP_V2_ROUTER_ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
UNISWAP_V2_FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
UNISWAP_V3_ROUTER_ADDRESS = "0xE592427A0AEce92De3Edee1F18E0157C05861564"
UNISWAP_V3_FACTORY_ADDRESS = "0x1F98431c8aD98523631AE4a59f267346ea31F984"

# Pancake
PANCAKESWAP_V2_ROUTER_ADDRESS = "0xEfF92A263d31888d860bD50809A8D171709b7b1c"
PANCAKESWAP_V2_FACTORY_ADDRESS = "0x1097053Fd2ea711dad45caCcc45EfF7548fCB362"
PANCAKESWAP_V3_ROUTER_ADDRESS = "0x1b81D678ffb9C0263b24A97847620C99d213eB14"
PANCAKESWAP_V3_FACTORY_ADDRESS = "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865"

# Sushi
SUSHISWAP_V2_ROUTER_ADDRESS = "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"
SUSHISWAP_V2_FACTORY_ADDRESS = "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac"
SUSHISWAP_V3_ROUTER_ADDRESS = "0x2E6cd2d30aa43f40aa81619ff4b6E0a41479B13F"
SUSHISWAP_V3_FACTORY_ADDRESS = "0xbACEB8eC6b9355Dfc0269C18bac9d6E2Bdc29C4F"

# Shiba
SHIBA_V2_ROUTER_ADDRESS = "0x03f7724180AA6b939894B5Ca4314783B0b36b329"
SHIBA_V2_FACTORY_ADDRESS = "0x115934131916C8b277DD010Ee02de363c09d037c"

# Uni V2 & V3 Router Mapping
UNI_V2_ROUTER_MAPPING = {ConfigNetwork.UNISWAP_V2_NAME: UNISWAP_V2_ROUTER_ADDRESS, ConfigNetwork.SUSHISWAP_V2_NAME: SUSHISWAP_V2_ROUTER_ADDRESS, ConfigNetwork.PANCAKESWAP_V2_NAME: PANCAKESWAP_V2_ROUTER_ADDRESS, ConfigNetwork.SHIBA_V2_NAME: SHIBA_V2_ROUTER_ADDRESS}
UNI_V3_ROUTER_MAPPING = {ConfigNetwork.UNISWAP_V3_NAME: UNISWAP_V3_ROUTER_ADDRESS, ConfigNetwork.SUSHISWAP_V3_NAME: SUSHISWAP_V3_ROUTER_ADDRESS, ConfigNetwork.PANCAKESWAP_V3_NAME: PANCAKESWAP_V3_ROUTER_ADDRESS}
UNI_V2_FORK_FACTORY_ADDRESS_TO_EXCHANGE_NAME = {UNISWAP_V2_FACTORY_ADDRESS: ConfigNetwork.UNISWAP_V2_NAME, SUSHISWAP_V2_FACTORY_ADDRESS: ConfigNetwork.SUSHISWAP_V2_NAME, PANCAKESWAP_V2_FACTORY_ADDRESS: ConfigNetwork.PANCAKESWAP_V2_NAME, SHIBA_V2_FACTORY_ADDRESS: ConfigNetwork.SHIBA_V2_NAME}

UNI_V2_FORK_FACTORY_ADDRESS_TO_ROUTER = {UNISWAP_V2_FACTORY_ADDRESS: UNISWAP_V2_ROUTER_ADDRESS, SUSHISWAP_V2_FACTORY_ADDRESS: SUSHISWAP_V2_ROUTER_ADDRESS, PANCAKESWAP_V2_FACTORY_ADDRESS: PANCAKESWAP_V2_ROUTER_ADDRESS, SHIBA_V2_FACTORY_ADDRESS: SHIBA_V2_ROUTER_ADDRESS}
UNI_V3_FORK_FACTORY_ADDRESS_TO_ROUTER = {UNISWAP_V3_FACTORY_ADDRESS: UNISWAP_V3_ROUTER_ADDRESS, SUSHISWAP_V3_FACTORY_ADDRESS: SUSHISWAP_V3_ROUTER_ADDRESS, PANCAKESWAP_V3_FACTORY_ADDRESS: PANCAKESWAP_V3_ROUTER_ADDRESS}
UNI_V3_FORK_FACTORY_ADDRESS_TO_EXCHANGE_NAME = {UNISWAP_V3_FACTORY_ADDRESS: ConfigNetwork.UNISWAP_V3_NAME, SUSHISWAP_V3_FACTORY_ADDRESS: ConfigNetwork.SUSHISWAP_V3_NAME, PANCAKESWAP_V3_FACTORY_ADDRESS: ConfigNetwork.PANCAKESWAP_V3_NAME}

# FRAX

BALANCER_VAULT_ADDRESS = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"

class _ConfigNetworkTenderly(ConfigNetwork):
Expand All @@ -182,18 +219,61 @@ class _ConfigNetworkTenderly(ConfigNetwork):
BANCOR_V3_NETWORK_INFO_ADDRESS = "0x8E303D296851B320e6a697bAcB979d13c9D6E760"
BANCOR_V3_NETWORK_ADDRESS = "0xeEF417e1D5CC832e619ae18D2F140De2999dD4fB"
BANCOR_V3_NETWORK_SETTINGS = "0x83E1814ba31F7ea95D216204BB45FE75Ce09b14F"
UNISWAP_V2_FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
UNISWAP_V2_ROUTER_ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
SUSHISWAP_FACTORY_ADDRESS = "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac"
UNISWAP_V3_FACTORY_ADDRESS = "0x1F98431c8aD98523631AE4a59f267346ea31F984"
BANCOR_V3_VAULT = "0x649765821D9f64198c905eC0B2B037a4a52Bc373"
BANCOR_V3_POOL_COLLECTOR_ADDRESS = "0xde1B3CcfC45e3F5bff7f43516F2Cd43364D883E4"
BANCOR_V2_CONVERTER_REGISTRY_ADDRESS = "0xC0205e203F423Bcd8B2a4d6f8C8A154b0Aa60F19"
# FASTLANE_CONTRACT_ADDRESS = "0x51a6D03B156af044bda570CF35a919DB851Cebd1"
FASTLANE_CONTRACT_ADDRESS = "0x41Eeba3355d7D6FF628B7982F3F9D055c39488cB"
CARBON_CONTROLLER_ADDRESS = "0xC537e898CD774e2dCBa3B14Ea6f34C93d5eA45e1"
CARBON_CONTROLLER_VOUCHER = "0x3660F04B79751e31128f6378eAC70807e38f554E"
MULTICALL_CONTRACT_ADDRESS = "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"
BANCOR_V3_VAULT = "0x649765821D9f64198c905eC0B2B037a4a52Bc373"

# Uniswap
UNISWAP_V2_ROUTER_ADDRESS = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
UNISWAP_V2_FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
UNISWAP_V3_ROUTER_ADDRESS = "0xE592427A0AEce92De3Edee1F18E0157C05861564"
UNISWAP_V3_FACTORY_ADDRESS = "0x1F98431c8aD98523631AE4a59f267346ea31F984"

# Pancake
PANCAKESWAP_V2_ROUTER_ADDRESS = "0xEfF92A263d31888d860bD50809A8D171709b7b1c"
PANCAKESWAP_V2_FACTORY_ADDRESS = "0x1097053Fd2ea711dad45caCcc45EfF7548fCB362"
PANCAKESWAP_V3_ROUTER_ADDRESS = "0x1b81D678ffb9C0263b24A97847620C99d213eB14"
PANCAKESWAP_V3_FACTORY_ADDRESS = "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865"

# Sushi
SUSHISWAP_V2_ROUTER_ADDRESS = "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"
SUSHISWAP_V2_FACTORY_ADDRESS = "0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac"
SUSHISWAP_V3_ROUTER_ADDRESS = "0x2E6cd2d30aa43f40aa81619ff4b6E0a41479B13F"
SUSHISWAP_V3_FACTORY_ADDRESS = "0xbACEB8eC6b9355Dfc0269C18bac9d6E2Bdc29C4F"

# Shiba
SHIBA_V2_ROUTER_ADDRESS = "0x03f7724180AA6b939894B5Ca4314783B0b36b329"
SHIBA_V2_FACTORY_ADDRESS = "0x115934131916C8b277DD010Ee02de363c09d037c"

BALANCER_VAULT_ADDRESS = "0xBA12222222228d8Ba445958a75a0704d566BF2C8"

UNI_V2_ROUTER_MAPPING = {ConfigNetwork.UNISWAP_V2_NAME: UNISWAP_V2_ROUTER_ADDRESS,
ConfigNetwork.SUSHISWAP_V2_NAME: SUSHISWAP_V2_ROUTER_ADDRESS,
ConfigNetwork.PANCAKESWAP_V2_NAME: PANCAKESWAP_V2_ROUTER_ADDRESS,
ConfigNetwork.SHIBA_V2_NAME: SHIBA_V2_ROUTER_ADDRESS}
UNI_V3_ROUTER_MAPPING = {ConfigNetwork.UNISWAP_V3_NAME: UNISWAP_V3_ROUTER_ADDRESS,
ConfigNetwork.SUSHISWAP_V3_NAME: SUSHISWAP_V3_ROUTER_ADDRESS,
ConfigNetwork.PANCAKESWAP_V3_NAME: PANCAKESWAP_V3_ROUTER_ADDRESS}
UNI_V2_FORK_FACTORY_ADDRESS_TO_EXCHANGE_NAME = {UNISWAP_V2_FACTORY_ADDRESS: ConfigNetwork.UNISWAP_V2_NAME,
SUSHISWAP_V2_FACTORY_ADDRESS: ConfigNetwork.SUSHISWAP_V2_NAME,
PANCAKESWAP_V2_FACTORY_ADDRESS: ConfigNetwork.PANCAKESWAP_V2_NAME,
SHIBA_V2_FACTORY_ADDRESS: ConfigNetwork.SHIBA_V2_NAME}

UNI_V2_FORK_FACTORY_ADDRESS_TO_ROUTER = {UNISWAP_V2_FACTORY_ADDRESS: UNISWAP_V2_ROUTER_ADDRESS,
SUSHISWAP_V2_FACTORY_ADDRESS: SUSHISWAP_V2_ROUTER_ADDRESS,
PANCAKESWAP_V2_FACTORY_ADDRESS: PANCAKESWAP_V2_ROUTER_ADDRESS,
SHIBA_V2_FACTORY_ADDRESS: SHIBA_V2_ROUTER_ADDRESS}
UNI_V3_FORK_FACTORY_ADDRESS_TO_ROUTER = {UNISWAP_V3_FACTORY_ADDRESS: UNISWAP_V3_ROUTER_ADDRESS,
SUSHISWAP_V3_FACTORY_ADDRESS: SUSHISWAP_V3_ROUTER_ADDRESS,
PANCAKESWAP_V3_FACTORY_ADDRESS: PANCAKESWAP_V3_ROUTER_ADDRESS}
UNI_V3_FORK_FACTORY_ADDRESS_TO_EXCHANGE_NAME = {UNISWAP_V3_FACTORY_ADDRESS: ConfigNetwork.UNISWAP_V3_NAME,
SUSHISWAP_V3_FACTORY_ADDRESS: ConfigNetwork.SUSHISWAP_V3_NAME,
PANCAKESWAP_V3_FACTORY_ADDRESS: ConfigNetwork.PANCAKESWAP_V3_NAME}

def __init__(self, **kwargs):
super().__init__(**kwargs)
22 changes: 22 additions & 0 deletions fastlane_bot/data/abi.py

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions fastlane_bot/data/event_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
"blockHash": "0xefc338e7672291a889029a206f93a50feba92ba7be9e1210f382d79cf2fc9972",
"blockNumber": 17613685
},
"pancakeswap_v2_event": {
"args": {
"reserve0": 6543521908014628725401090,
"reserve1": 2535973648121313922634
},
"event": "Sync",
"logIndex": 93,
"transactionIndex": 38,
"transactionHash": "0xc7c0560a8829fb43e05003ef07de8ce682167bb8a16a5e73d832a6a15513dace",
"address": "0x4A86C01d67965f8cB3d0AAA2c655705E64097C31",
"blockHash": "0xefc338e7672291a889029a206f93a50feba92ba7be9e1210f382d79cf2fc9972",
"blockNumber": 17613685
},
"uniswap_v3_event": {
"args": {
"sender": "0x0000000000a84D1a9B0063A910315C7fFA9Cd248",
Expand All @@ -43,6 +56,26 @@
"blockHash": "0xc4c2ffbf7e0a2b94721eee92a8acaed343d2f332bcd83bf0b66d63b826d78cf6",
"blockNumber": 17613637
},
"pancakeswap_v3_event": {
"args": {
"sender": "0x0000000000a84D1a9B0063A910315C7fFA9Cd248",
"recipient": "0x0000000000a84D1a9B0063A910315C7fFA9Cd248",
"amount0": 100153166149054480779,
"amount1": -156077720804642502,
"sqrtPriceX96": 314113692261321808510033604,
"liquidity": 2727127977604947233926,
"tick": -64560,
"protocolFeesToken0": 1,
"protocolFeesToken1": 1
},
"event": "Swap",
"logIndex": 48,
"transactionIndex": 4,
"transactionHash": "0x2063e741127ec1a61b03f5c1e01a5ba83c695606e56b8b705b69f0218c6433f4",
"address": "0xcBcC3cBaD991eC59204be2963b4a87951E4d292B",
"blockHash": "0xc4c2ffbf7e0a2b94721eee92a8acaed343d2f332bcd83bf0b66d63b826d78cf6",
"blockNumber": 17613637
},
"bancor_v3_event": {
"args": {
"pool": "0x4691937a7508860F876c9c0a2a617E7d9E945D4B",
Expand Down
13 changes: 13 additions & 0 deletions fastlane_bot/data/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@
if static_data[idx]["exchange_name"] == "uniswap_v3"
]

# get all pancakeswap v2 pools
pancakeswap_v2_pools = [
static_data[idx]["address"]
for idx in range(len(static_data))
if static_data[idx]["exchange_name"] == "pancakeswap_v2"
]

pancakeswap_v3_pools = [
static_data[idx]["address"]
for idx in range(len(static_data))
if static_data[idx]["exchange_name"] == "pancakeswap_v3"
]

del static_data # clear static data to save memory
Loading

0 comments on commit b2b436e

Please sign in to comment.