Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nile V3 specific fee support #518

Draft
wants to merge 3 commits into
base: add_linea
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fastlane_bot/data/abi.py

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ lynex_v2,0xA5d10e2350C4794d06de9Ac1B373e4114ff0F0ec
lynex_v2,0x740BB4250398f2b87e70CB21f459DE4Df80012Dc
lynex_v2,0xfb26FDeb0D7151731afcCdFfB0E38D2c5f33C807
lynex_v2,0x8E9f777f2448590ccd9d547f49489948A6001d41
lynex_v2,0x1C843458Ab1D2f8198B632F519232223e9D81370
lynex_v2,0xbB9da18545F6705047b42523AAc1d558260B213c
nile_v2,0x769a64A1C49202E49dC3e20F2B4B42eeb2e2f226
nile_v2,0xEc06f5100758bE74B33762f99123A1b9B9E9A7F2
nile_v2,0x641d5eAa27e516E1CF1F5C84B5EC25C45b7e3f0D
Expand Down
27 changes: 8 additions & 19 deletions fastlane_bot/data/blockchain_data/linea/static_pool_data.csv

Large diffs are not rendered by default.

109 changes: 53 additions & 56 deletions fastlane_bot/data/blockchain_data/linea/tokens.csv
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
address,decimals,symbol
0x82cC61354d78b846016b559e3cCD766fa7E793D5,18,LINDA
0x1bE3735Dd0C0Eb229fB11094B6c277192349EBbf,18,LUBE
0xA219439258ca9da29E9Cc4cE5596924745e12B93,6,USDT
0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5,18,DAI
0x0B1A02A7309dFbfAD1Cd4adC096582C87e8A3Ac1,18,HZN
0x9201f3b9DfAB7C13Cd659ac5695D12D605B5F1e6,18,ECP
0xf3B001D64C656e30a62fbaacA003B1336b4ce12A,18,MIMATIC
0x0B1A02A7309dFbfAD1Cd4adC096582C87e8A3Ac1,18,HZN
0x43E8809ea748EFf3204ee01F08872F063e44065f,18,MENDI
0x82cC61354d78b846016b559e3cCD766fa7E793D5,18,LINDA
0xd83af4fbD77f3AB65C3B1Dc4B38D7e67AEcf599A,18,LXP
0x1E1F509963A6D33e169D9497b11c7DbFe73B7F13,6,USDT+
0x1bE3735Dd0C0Eb229fB11094B6c277192349EBbf,18,LUBE
0x176211869cA2b568f2A7D4EE941E073a821EE1ff,6,USDC
0xd83af4fbD77f3AB65C3B1Dc4B38D7e67AEcf599A,18,LXP
0x9201f3b9DfAB7C13Cd659ac5695D12D605B5F1e6,18,ECP
0xA219439258ca9da29E9Cc4cE5596924745e12B93,6,USDT
0x7d43AABC515C356145049227CeE54B608342c0ad,18,BUSD
0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f,18,WETH
0xAAAac83751090C6ea42379626435f805DDF54DC8,18,NILE
0x43E8809ea748EFf3204ee01F08872F063e44065f,18,MENDI
0xcc22F6AA610D1b2a0e89EF228079cB3e1831b1D1,18,LVC
0x796000FAd0d00B003B9dd8e531BA90cff39E01E0,8,DUCKIES
0x5cc5E64AB764A0f1E97F23984E20fD4528356a6a,18,XRGB
0xEB466342C4d449BC9f53A865D5Cb90586f405215,6,AXLUSDC
0x6EF95B6f3b0F39508e3E04054Be96D5eE39eDE0d,18,SIS
0x5471ea8f739dd37E9B81Be9c5c77754D8AA953E4,18,WAVAX
0x93F4d0ab6a8B4271f4a28Db399b5E30612D21116,18,STONE
0x13a7F090D46C74acBA98c51786a5c46eD9A474F0,18,SCM
0xa334884bF6b0A066d553D19e507315E839409e62,18,ERN
0x5cc5E64AB764A0f1E97F23984E20fD4528356a6a,18,XRGB
0xf5C6825015280CdfD0b56903F9F8B5A2233476F5,18,WBNB
0x265B25e22bcd7f10a5bD6E6410F10537Cc7567e8,18,WMATIC
0xB79DD08EA68A908A97220C76d19A6aA9cBDE4376,6,USD+
0x47C337Bd5b9344a6F3D6f58C474D9D8cd419D8cA,18,DACKIE
0x59DEBED8D46a0cB823D8BE8b957adD987eAd39aa,18,QUACK
0x3d4b2132eD4eA0aa93903713a4dE9F98e625a5c7,18,A3A
0x0018D96C579121a94307249d47F053E2D687b5e7,18,MVX
0x3b2F62d42DB19B30588648bf1c184865D4C3B1D6,18,KNC
0x7a6AA80B49017f3E091574ab5C6977d863ff3865,18,USK
Expand All @@ -37,92 +38,88 @@ address,decimals,symbol
0xDD3B8084AF79B9BaE3D1b668c0De08CCC2C9429A,18,MIM
0x60D01EC2D5E98Ac51C8B4cF84DfCCE98D527c747,18,IZI
0xA88B54E6b76Fb97CdB8eCAE868f1458e18a953F4,18,DUSD
0xc31ab955b9F1834A863e3ddbF6b31508fc10ab19,18,TestLinea
0x445F631a58D188fb80D8B7e0Faeb07A946d72dEb,18,LINU
0x9Dd6EA6f9D1fba5ed640651f06802e32FF455221,18,LIN
0x7796f237D2054717A61c1C3dD2043499885b9BD3,18,LNA
0x2a7f10680a8c3B8a8a6D409fe464324d39660410,18,POLO
0x062FB4625E651dDcE5a368599e9DCd09703A527a,18,SHB
0x445F631a58D188fb80D8B7e0Faeb07A946d72dEb,18,LINU
0xd823B68f66e36f76DF436B5810a043573f4F689A,18,ECHINU
0xc31ab955b9F1834A863e3ddbF6b31508fc10ab19,18,TestLinea
0x9096934bC511ae3406226525E9b35EF4946AF62d,18,LCast
0xc88ae32aD089c1E94bafccFC85fb1F9E2728241d,18,PEPE
0x03CA0C6EfC1c2f7325fb7E9F8c9B861F654C430a,18,PENDLE
0xa61c1d2029CeB1DEcA9D55334C6E76C91E7F2273,18,LiSHIB
0x7f5373AE26c3E8FfC4c77b7255DF7eC1A9aF52a6,6,axlUSDT
0x9Dd6EA6f9D1fba5ed640651f06802e32FF455221,18,LIN
0x1a35EE4640b0A3B87705B0A4B45D227Ba60Ca2ad,8,axlWBTC
0xe8190aF5360B38DC779ccb74Ee4FBCBF6626BC6c,18,LDOGE
0xa2608afdaa8D1Df3d5aaAD96e200BCFfd63EdB71,18,BOB
0x5C7e299CF531eb66f2A1dF637d37AbB78e6200C7,18,axlDAI
0xB25983d38e4Cb5a480CCC8e0Ff6648B0517Fe7BB,18,P3P3
0x2fc30AB12cD4971198d203034048aCa2a7B7da00,18,RBX
0x945C6d2A6ee162A92e7Fed641c85d972Af50eB96,18,SHBL
0xd823B68f66e36f76DF436B5810a043573f4F689A,18,ECHINU
0xc88ae32aD089c1E94bafccFC85fb1F9E2728241d,18,PEPE
0x7796f237D2054717A61c1C3dD2043499885b9BD3,18,LNA
0x46A6ca63CfCF09cbC5E40BF1549F7f626304481A,9,Pepe-X
0x2fc30AB12cD4971198d203034048aCa2a7B7da00,18,RBX
0xa61c1d2029CeB1DEcA9D55334C6E76C91E7F2273,18,LiSHIB
0x10C4b0207aE0ae43593Eee2261b92ca6Ed179CFD,18,LDOGE
0x03CA0C6EfC1c2f7325fb7E9F8c9B861F654C430a,18,PENDLE
0x997BF0ebF2a2a2e8189493cedFd19bCDb077c0d0,18,NBS
0x1a35EE4640b0A3B87705B0A4B45D227Ba60Ca2ad,8,axlWBTC
0x5C7e299CF531eb66f2A1dF637d37AbB78e6200C7,18,axlDAI
0xe8190aF5360B38DC779ccb74Ee4FBCBF6626BC6c,18,LDOGE
0xeC621005472E5E52d205B153eac5E8300a402F42,18,SHERIFF
0x2a7f10680a8c3B8a8a6D409fe464324d39660410,18,POLO
0x4e809820bf4E16CC6Ae86F837e89f63F45437C13,18,Sdoge
0x8fc86f47464d2F36754775E8B4Cb0e8Cb75DDbBA,18,Doge
0xeC621005472E5E52d205B153eac5E8300a402F42,18,SHERIFF
0x997BF0ebF2a2a2e8189493cedFd19bCDb077c0d0,18,NBS
0x10C4b0207aE0ae43593Eee2261b92ca6Ed179CFD,18,LDOGE
0x0fA2155Af678686E4b02c7335872503Af440149f,18,100000000000
0x4e809820bf4E16CC6Ae86F837e89f63F45437C13,18,Sdoge
0x02Ae203A24F655ae1Ea5D38214c3E3069cd0017F,18,btcsb
0xF1890579D7E596a08b0A1CaA82d1Cc13AAaFebB2,18,3
0x60e955B3b0Df66fA4b2f2A992192c3c848b3c915,18,TEST
0xAE7B4Ebf3c7FedA18D5A2a85dC37f40260B40Ac5,18,$Mask
0x9D5d1b60A78b0D10bB7FEb463a12DDC84B080572,18,lin
0x3aAB2285ddcDdaD8edf438C1bAB47e1a9D05a9b4,8,WBTC
0xF1890579D7E596a08b0A1CaA82d1Cc13AAaFebB2,18,3
0xDC32050E9969B8Ea3597123CB31DDF2034CfBF62,18,NTO
0x12fb3e7344AC41aA18dabA9Aeda2d73b8Ded3aFd,18,BIGTIME
0x9921664739FcC77cC43CCa5E6e07F72F80041c78,9,KRILL
0xAE7B4Ebf3c7FedA18D5A2a85dC37f40260B40Ac5,18,$Mask
0xA946E7911fD2F45d9CBD1E92D8324D661865Dd63,18,TL
0x3aAB2285ddcDdaD8edf438C1bAB47e1a9D05a9b4,8,WBTC
0x1097db7625aE0A5e705F153ac25AE4b6eE66cca4,18,VGQ
0x12fb3e7344AC41aA18dabA9Aeda2d73b8Ded3aFd,18,BIGTIME
0xe7446Fe2D090AD80751E7dfe09D0ed420589089C,18,dove
0xEf531B4045616DE43eEeBCAda8D89104869D32F2,18,PALPABLE
0x596B88eA5d6D75E2E2E3f03c5d2C797ECA82258f,18,ULT
0x3705E83d74580631722D7E8A2D86628EE61f5320,18,ZERO
0xB5beDd42000b71FddE22D3eE8a79Bd49A568fC8F,18,wstETH
0x9921664739FcC77cC43CCa5E6e07F72F80041c78,9,KRILL
0xe9503fe0Fd65685CB7e5e7B0e4E1B95266DfA7D7,18,BLOW
0x6Cd70ff7d7415B39485A1424E267eBA435876084,18,DICK
0xEf531B4045616DE43eEeBCAda8D89104869D32F2,18,PALPABLE
0x3705E83d74580631722D7E8A2D86628EE61f5320,18,ZERO
0x53F7B069CAA7Fe942E2f304f3e2987C0B177b1B8,18,PIR
0x6Cd70ff7d7415B39485A1424E267eBA435876084,18,DICK
0xd2dDA4b56bEAe9f8E9C4C83D5159FB092F4b825a,18,lin
0x1a51b19CE03dbE0Cb44C1528E34a7EDD7771E9Af,18,LYNX
0xe8a4c9B6a2b79Fd844c9e3AdBc8Dc841eEce557B,18,bveLYNX
0x4Fa0dE5d9217722A37247808c08Cde1C976879b9,18,LUCIA
0x1a51b19CE03dbE0Cb44C1528E34a7EDD7771E9Af,18,LYNX
0x332c72dd7E77070740F01d2d35851c461585D5d0,18,axlLqdr
0x3d4b2132eD4eA0aa93903713a4dE9F98e625a5c7,18,A3A
0x63349BA5E1F71252eCD56E8F950D1A518B400b60,18,oLYNX
0xa09d7f02BaD175a9d6BcBeDf1A992EEAD1e33604,18,NDX_2412
0x023617bAbEd6CeF5Da825BEa8363A5a9862E120F,18,wDAI
0xA7020f1Cf5d3aAa5f6f9f376d10D0DbFf647C4Cb,18,iNDX_2412
0xbfa536126C1C2b7cbA94807a39213fAb913950A3,18,SATS
0xec45e3C3C5410CBDBCe81dd35Edcf9f0f13fc2cB,18,ORDI
0xe8a4c9B6a2b79Fd844c9e3AdBc8Dc841eEce557B,18,bveLYNX
0x63349BA5E1F71252eCD56E8F950D1A518B400b60,18,oLYNX
0xa09d7f02BaD175a9d6BcBeDf1A992EEAD1e33604,18,NDX_2412
0x3F817b28Da4940F018C6b5c0A11C555ebB1264f9,18,EURO3
0x2Fab0952449378DfdF4625fE37F9603011F189ab,18,LINE
0xCa7d460C83678C358E8FC9b9629E8aC36D67c567,18,LILI
0xec45e3C3C5410CBDBCe81dd35Edcf9f0f13fc2cB,18,ORDI
0xA7020f1Cf5d3aAa5f6f9f376d10D0DbFf647C4Cb,18,iNDX_2412
0xe07C2bdbb8C787962C2C6e93C11a152110E7E4d2,18,LINUS
0xCa7d460C83678C358E8FC9b9629E8aC36D67c567,18,LILI
0x150b1e51738CdF0cCfe472594C62d7D6074921CA,18,sMendi
0xcf8deDCdC62317beAEdfBee3C77C08425F284486,18,uMendi
0x2416092f143378750bb29b79eD961ab195CcEea5,18,ezETH
0x894134a25a5faC1c2C26F1d8fBf05111a3CB9487,18,GRAI
0x2cEFbC78f01590a8961fF9d282726B64635BCb44,18,ITX
0x63bA74893621d3d12F13CEc1e86517eC3d329837,18,LUSD
0x0D1E753a25eBda689453309112904807625bEFBe,18,Cake
0x2cEFbC78f01590a8961fF9d282726B64635BCb44,18,ITX
0x894134a25a5faC1c2C26F1d8fBf05111a3CB9487,18,GRAI
0x2416092f143378750bb29b79eD961ab195CcEea5,18,ezETH
0x808d7c71ad2ba3FA531b068a2417C63106BC0949,18,STG
0x02e47D464c3bB564964fce162e6c8F38eA744f5a,18,TV
0xf1E11408b29611c03E242244A3f37ACF66C2e3fe,18,LEDG
0x0D1E753a25eBda689453309112904807625bEFBe,18,Cake
0x41b94c5867f7F6217C9a30520Cb3e793B1ee1b97,6,axlTIA
0x21d624c846725ABe1e1e7d662E9fB274999009Aa,18,CRYSTAL
0xC935B31C345D59A2396F7fEaC277FC1C981abC38,18,LNU
0x32226588378236Fd0c7c4053999F88aC0e5cAc77,18,A
0x2314342912d9968fd3B40a542Bdb1fC6b918f35E,18,$MENDI
0x808d7c71ad2ba3FA531b068a2417C63106BC0949,18,STG
0x1C7F152e3dB82F92C0e4446A2922975E5d0eFCfE,18,SCB
0x41b94c5867f7F6217C9a30520Cb3e793B1ee1b97,6,axlTIA
0x8cE74e606481BBC7078aF4781f9eB67afC85a0Ce,18,stETH
0x1C7F152e3dB82F92C0e4446A2922975E5d0eFCfE,18,SCB
0x246c82fD3798Af4cc38973c429C18e807016a4BD,18,TM
0x2314342912d9968fd3B40a542Bdb1fC6b918f35E,18,$MENDI
0x0A224Fa31903Bd0AF7b985DD7c07f6806C4b81a6,18,ZOOMER
0x617FeED96d21F938Da4e725e8D460af6De2FaFe0,18,Wrapped BTC
0x98b6D1ebae3B228e5D947f14dA602Ac16f7ee60B,18,Linea Network
0x2598c30330D5771AE9F983979209486aE26dE875,18,AI
0xC935B31C345D59A2396F7fEaC277FC1C981abC38,18,LNU
0x617FeED96d21F938Da4e725e8D460af6De2FaFe0,18,Wrapped BTC
0x3652Fc6EDcbD76161b8554388867d3dAb65eCA93,18,B
0xf1E11408b29611c03E242244A3f37ACF66C2e3fe,18,LEDG
0x7e7679d1aBd9B3508E2A4924664Bbd1533F4ea64,18,LATER
0xfa1E8B0E8ef1C5F978C2885053D706cFB5e35822,18,NOW
0x2140Ea50bc3B6Ac3971F9e9Ea93A1442665670e4,18,NFTE
0x616B5d07B4f73Ae7ebd236D75C26bf313483372c,18,LOYO
0x1eB8266C13Fa1b7134E0e72eb6D182738B3A75A2,18,BLS
0xF2B1745E560df1c0991BD9e7312F07b690FCf844,18,LIMEME
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,3 @@ secta_v3,0x2A7F1baEEf187494759770228A3Ac0ff0d5A5f32
secta_v3,0xC34FA78eabFD8E0a788087C1a73276dF4284ffEd
secta_v3,0xe358f3B4D360E21AE9E84E3d54535F89580eA2E4
secta_v3,0x907045EEcE2891AC0e9189191abb270d6c121855
sushiswap_v3,0xe5Ea78EBbacb76cD430E6832ee3E46EF15a82C56
sushiswap_v3,0x6805f16924d163E515e49cb76cb19643797730A4
sushiswap_v3,0xB273e954983ABAE94ec500C19F1A23790D3553D3
sushiswap_v3,0xEBA4eD4CC80A2Fdc4F69E98245Ffc237e930A733
sushiswap_v3,0x84EA5316BFe6Cfa5EeD19084e4F57583b4bB1C80
sushiswap_v3,0xB1d02037FAD044537ADdb109909d26Cab1EB5e15
sushiswap_v3,0x703B31a28DD44A507f0af7AdaA0cAA0DAF0b41F1
sushiswap_v3,0xBF1Bc56CCeb06AA23CB9341Fa7682B14d1fb5E87
sushiswap_v3,0x67948b5311aD0de95A11131a35331baa36Fc320D
sushiswap_v3,0xE8B893F2Bb7BfE93752082E9Adec269520F34C16
sushiswap_v3,0xb46aB262E3960cbAD5e0b17e0768EEa3B97446A0
sushiswap_v3,0xae1b0c9a3a92Dc0340A17E1Bc7bFdBAc15D86920
sushiswap_v3,0x416e3B622867aa4af98FcF0E0b871a47A80A7d7E
14 changes: 11 additions & 3 deletions fastlane_bot/events/exchanges/uniswap_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

from web3.contract import Contract

from fastlane_bot.config.constants import AGNI_V3_NAME, PANCAKESWAP_V3_NAME, FUSIONX_V3_NAME, ECHODEX_V3_NAME, SECTA_V3_NAME
from fastlane_bot.data.abi import UNISWAP_V3_POOL_ABI, UNISWAP_V3_FACTORY_ABI, PANCAKESWAP_V3_POOL_ABI
from fastlane_bot.config.constants import AGNI_V3_NAME, PANCAKESWAP_V3_NAME, FUSIONX_V3_NAME, ECHODEX_V3_NAME, \
SECTA_V3_NAME, NILE_V3_NAME
from fastlane_bot.data.abi import UNISWAP_V3_POOL_ABI, UNISWAP_V3_FACTORY_ABI, PANCAKESWAP_V3_POOL_ABI, NILE_V3_POOL_ABI
from fastlane_bot.events.exchanges.base import Exchange
from fastlane_bot.events.pools.base import Pool

Expand All @@ -30,7 +31,11 @@ def add_pool(self, pool: Pool):
self.pools[pool.state["address"]] = pool

def get_abi(self):
return UNISWAP_V3_POOL_ABI if self.exchange_name not in [PANCAKESWAP_V3_NAME, AGNI_V3_NAME, FUSIONX_V3_NAME, ECHODEX_V3_NAME, SECTA_V3_NAME] else PANCAKESWAP_V3_POOL_ABI
if self.exchange_name in [PANCAKESWAP_V3_NAME, AGNI_V3_NAME, FUSIONX_V3_NAME, ECHODEX_V3_NAME, SECTA_V3_NAME]:
return PANCAKESWAP_V3_POOL_ABI
elif self.exchange_name == NILE_V3_NAME:
return NILE_V3_POOL_ABI
return UNISWAP_V3_POOL_ABI

@property
def get_factory_abi(self):
Expand All @@ -42,6 +47,9 @@ def get_events(self, contract: Contract) -> List[Type[Contract]]:
async def get_fee(self, address: str, contract: Contract) -> Tuple[str, float]:
fee = await contract.functions.fee().call()
fee_float = float(fee) / 1e6
if self.exchange_name == NILE_V3_NAME:
fee_float = await contract.functions.currentFee().call()
Copy link
Collaborator

@barakman barakman Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something really wrong here, as in one case you are dividing by the resolution, and in one case you don't.
So fee_float is sometimes returned after being divided by 16e, and sometimes being returned as read from the contract.
How could that possibly work correctly further down the road, when the caller of this function receives this returned value and needs to processes it?
Also note that you seem to have made a similar change in file run_blockchain_terraformer.py, where you actually do divide by 1000000 in both cases.
So even without taking the above into consideration, it is pretty clear that at least one of these two changes is incorrect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that, it makes much more sense to implement a separate file called nile_v3.py.
This type of logic becomes increasingly confusing:

if self.exchange_name in [PANCAKESWAP_V3_NAME, AGNI_V3_NAME, FUSIONX_V3_NAME, ECHODEX_V3_NAME, SECTA_V3_NAME]:
    return PANCAKESWAP_V3_POOL_ABI
elif self.exchange_name == NILE_V3_NAME:
    return NILE_V3_POOL_ABI
return UNISWAP_V3_POOL_ABI

The guiding thumb-rule should be that once a simple branching (if/else) becomes too obfuscated, it is time to consider an alternative approach.
Note that an additional logic was also applied in function get_fee further down in this file, and on top of making it more cumbersome, this one actually introduces a bug:

fee_float = float(fee) / 1e6
if self.exchange_name == NILE_V3_NAME:
    fee_float = await contract.functions.currentFee().call()

As the value of fee_float is scaled down by 1e6 in some scenarios, and not scaled down at all in other scenarios.
So unless you apply the same logic (if exchange_name == NILE_V3_NAME) in every function which calls this function, an incorrect calculation most likely takes place.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a short research, the best approach here would be a paradigm similar to the one in solidly_v2.py.


return fee, fee_float

async def get_tkn0(self, address: str, contract: Contract, event: Any) -> str:
Expand Down
4 changes: 2 additions & 2 deletions fastlane_bot/helpers/poolandtokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,10 @@ def _univ3_to_cpc(self) -> List[Any]:
"tick": self.tick,
"liquidity": self.liquidity,
}
feeconst = self.FEE_LOOKUP.get(float(self.fee_float))
feeconst = self.FEE_LOOKUP.get(int(self.fee)/1e6)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this change related to this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I maintained the original format of this by switching fee_float -> fee due to fee_float no longer being reliable. See above.

if feeconst is None:
raise ValueError(
f"Illegal fee for Uniswap v3 pool: {self.fee_float} [{self.FEE_LOOKUP}]]"
f"Illegal fee for Uniswap v3 pool: {int(self.fee)} [{self.FEE_LOOKUP}]]"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this change related to this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above regarding fee_float & fee.

)
uni3 = Univ3Calculator.from_dict(args, feeconst, addrdec=self.ADDRDEC)
params = uni3.cpc_params()
Expand Down
2 changes: 1 addition & 1 deletion fastlane_bot/helpers/tradeinstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def get_custom_int(self) -> int:
pool = self.pool
custom_int = 0
if self.exchange_name in self.ConfigObj.UNI_V3_FORKS:
custom_int = int(Decimal(pool.fee_float) * Decimal("1000000"))
custom_int = int(pool.fee)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this change related to this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nile V3 includes a fee override.

This PR stores the fee override for the pool in the fee_float field, and the original fee (which is necessary for Uniswap V3 details such as tick-spacing etc) in the fee field.

The Fast Lane arb contract must know the fee of the Uni V3 pool being traded on, so using the fee_float to calculate the fee is no longer valid in instances of override.

Consequently the fee field is now used as it does not change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not understand this description.
But Nile V3 should not be handled differently than any other DEX, other than in the dedicated sections (for example, in the uniswap_v3 module, where all of these DEXs are handled).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and to handle it the same, we must now use the fee field - which remains constant, instead of the fee_float which has an override for Nile V3.

elif self.exchange_name in self.ConfigObj.SOLIDLY_V2_FORKS:
custom_int = 0 if pool.pool_type != self.ConfigObj.network.POOL_TYPE_STABLE else 1
elif self.exchange_name in self.ConfigObj.BALANCER_NAME:
Expand Down
18 changes: 12 additions & 6 deletions run_blockchain_terraformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from pandas import DataFrame
from web3.contract import Contract

from fastlane_bot.config.constants import NILE_V3_NAME

load_dotenv()
import os
import requests
Expand Down Expand Up @@ -61,7 +63,7 @@
"coinbase_base": 250000,
"fantom": 2000,
"mantle": 10000000,
"linea": 50000
"linea": 5000
}

ALCHEMY_KEY_DICT = {
Expand Down Expand Up @@ -466,6 +468,10 @@ def organize_pool_details_uni_v3(
return None
pair = pair[:-1]
fee = pool_data["args"]["fee"]
fee_float = float(fee) / 1000000
if exchange == NILE_V3_NAME:
pool = web3.eth.contract(address=web3.to_checksum_address(pool_address), abi=NILE_V3_POOL_ABI)
fee_float = pool.caller.currentFee() / 1000000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why function currentFee and not function fee?
For UniV3 pools, we are using function fee.
Might be worth verifying exactly which function is required here.
You can do that by looking into the source code of this pool contract, checking which fee is used in the swap function, and then following it to see which of these two functions returns that specific fee.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why you using 1000000 in some cases and 1e6 in other cases?

Copy link
Collaborator

@barakman barakman Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, creating a web3.eth.contract instance clearly doesn't belong in here (as evident by how it is done elsewhere in the code).
You can't just "throw stuff in" without taking into consideration the broader SW design and structure.

Copy link
Collaborator

@barakman barakman Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it doesn't make sense that we need to make an RPC at this point, as the fee has already been obtained previously.
So during that previous point - either it was already obtained correctly using this contract function, or it there was an attempt to use the other contract function, which would have reverted for this contract.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The 1000000 vs 1e6 is just poor consistency - I will update this to use 1e6.
  2. Nile V3 uses a fee override function - currentFee. This results in an awkward situation in the Terraformer, as in all other cases the bot obtains the fee from the pool creation event. Due to the override, the best way to obtain the pool's current fee is by directly calling the contract.
  3. Regarding the overall SW design, do you have a suggestion for a more appropriate place for this, given that it's only relevant for Nile V3? I'm happy to move it if it makes more sense elsewhere.

Copy link
Collaborator

@barakman barakman Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the PR spawned off of this one.
In order to handle this in the uniswap_v3 module, for example, I used a paradigm similar to the one implemented in the solidly_v2 module.
That might give you an idea on how to deal with it here.

The part:

pool = web3.eth.contract(address=web3.to_checksum_address(pool_address), abi=NILE_V3_POOL_ABI)
fee_float = pool.caller.currentFee() / 1000000

Doesn't look like it belongs here.
Even without being acquainted with this module, a simple observation reveals that no other DEX requires an RPC for fetching the fee at this point, so why should the Nile V3 DEX require one?
Subsequently, placing it here breaks the structure of the code and the overall design of this module.
Wherever the fee for all the other DEXs is fetched, that's where the fee for Nile V3 should be fetched.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct that no other Uni V3 fork requires an additional call to fetch the fee, however, Nile V3 does.

The fee for other Uni V3 forks is obtained from the pool creation event. However, this is not sufficient for Nile V3 due to implementing a fee override.

Where else do you suggest placing this call given that no other Uni V3 forks require it?


description = exchange + " " + pair + " " + str(fee)

Expand All @@ -478,7 +484,7 @@ def organize_pool_details_uni_v3(
"pair_name": pair,
"exchange_name": exchange,
"fee": fee,
"fee_float": float(fee) / 1000000,
"fee_float": fee_float,
"address": pool_address,
"anchor": "",
"tkn0_address": token_info["tkn0_address"],
Expand Down Expand Up @@ -1182,7 +1188,7 @@ def terraform_blockchain(network_name: str, web3: Web3 = None, async_web3: Async
continue
print(f"********************** Terraforming **********************\nStarting exchange: {exchange_name} from block {from_block}")

if fork in "uniswap_v2":
if fork == UNISWAP_V2_NAME:
if fee == "TBD":
continue
if fork in SOLIDLY_FORKS:
Expand All @@ -1205,7 +1211,7 @@ def terraform_blockchain(network_name: str, web3: Web3 = None, async_web3: Async
)
m_df = m_df.reset_index(drop=True)
univ2_mapdf = pd.concat([univ2_mapdf, m_df], ignore_index=True)
elif fork in "uniswap_v3":
elif fork == UNISWAP_V3_NAME:
if fee == "TBD":
continue
add_to_exchange_ids(exchange=exchange_name, fork=fork)
Expand All @@ -1223,7 +1229,7 @@ def terraform_blockchain(network_name: str, web3: Web3 = None, async_web3: Async
)
m_df = m_df.reset_index(drop=True)
univ3_mapdf = pd.concat([univ3_mapdf, m_df], ignore_index=True)
elif "solidly" in fork:
elif fork == SOLIDLY_V2_NAME:
add_to_exchange_ids(exchange=exchange_name, fork=fork)

factory_abi = SOLIDLY_EXCHANGE_INFO[exchange_name]["factory_abi"]
Expand All @@ -1246,7 +1252,7 @@ def terraform_blockchain(network_name: str, web3: Web3 = None, async_web3: Async
)
m_df = m_df.reset_index(drop=True)
solidly_v2_mapdf = pd.concat([solidly_v2_mapdf, m_df], ignore_index=True)
elif "balancer" in fork:
elif fork == BALANCER_NAME:
try:
subgraph_url = BALANCER_SUBGRAPH_CHAIN_URL[network_name]
u_df = get_balancer_pools(subgraph_url=subgraph_url, web3=web3)
Expand Down
Loading