-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the prediction of volatility (#84)
* Implement the prediction of volatility * Adapt endpoint * feat: enhance implementation of slippage estimation * feat: implement thorough tests for slippage calculations * chore: make const coherent with the comment Co-authored-by: Leandro <[email protected]> * feat: add volatility details endpoint for investigating issues with slippage calculations * fix: fix comment * chore: simplify variance * docs: improve documentation of tests * chore: use the const for max/min slippage * Fix comment * Use const for max slippage * Fix issue with the return schema * Add shared lib and handle native currency * Add script to easily test slippage tolerances * Upload test-data * Create utilities to better handle supported chains * Remove redundant info * Delete unused --------- Co-authored-by: Leandro <[email protected]>
- Loading branch information
1 parent
2fa7b68
commit be1b58d
Showing
68 changed files
with
36,080 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
const fs = require('fs'); | ||
|
||
const BASE_URL = 'http://localhost:3010/chains'; | ||
|
||
const NetworkToChainId = { | ||
Mainnet: 1, | ||
'Gnosis Chain': 100, | ||
Arbitrum: 42161, | ||
Sepolia: 11155111, | ||
}; | ||
|
||
const PAIRS_TEST = { | ||
Mainnet: [ | ||
{ | ||
pair: 'USDC-DAI', | ||
quoteToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', | ||
baseToken: '0x6B175474E89094C44Da98b954EedeAC495271d0F', | ||
}, | ||
{ | ||
pair: 'DAI-ETH', | ||
quoteToken: '0x6B175474E89094C44Da98b954EedeAC495271d0F', | ||
baseToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', | ||
}, | ||
{ | ||
pair: 'DAI-WETH', | ||
quoteToken: '0x6B175474E89094C44Da98b954EedeAC495271d0F', | ||
baseToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
}, | ||
{ | ||
pair: 'PEPE-DAI', | ||
quoteToken: '0x6982508145454Ce325dDbE47a25d4ec3d2311933', | ||
baseToken: '0x6B175474E89094C44Da98b954EedeAC495271d0F', | ||
}, | ||
{ | ||
pair: 'PEPE-WETH', | ||
quoteToken: '0x6982508145454Ce325dDbE47a25d4ec3d2311933', | ||
baseToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
}, | ||
{ | ||
pair: 'COW-WETH', | ||
quoteToken: '0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB', | ||
baseToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', | ||
}, | ||
], | ||
'Gnosis Chain': [ | ||
{ | ||
pair: 'USDC-xDAI', | ||
quoteToken: '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83', | ||
baseToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', | ||
}, | ||
{ | ||
pair: 'sDAI-xDAI', | ||
quoteToken: '0xaf204776c7245bF4147c2612BF6e5972Ee483701', | ||
baseToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', | ||
}, | ||
{ | ||
pair: 'sDAI-wxDAI', | ||
quoteToken: '0xaf204776c7245bF4147c2612BF6e5972Ee483701', | ||
baseToken: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', | ||
}, | ||
{ | ||
pair: 'WETH-xDAI', | ||
quoteToken: '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1', | ||
baseToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', | ||
}, | ||
], | ||
Arbitrum: [ | ||
{ | ||
pair: 'USDC-DAI', | ||
quoteToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', | ||
baseToken: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', | ||
}, | ||
{ | ||
pair: 'DAI-WETH', | ||
quoteToken: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', | ||
baseToken: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', | ||
}, | ||
{ | ||
pair: 'COW-WETH', | ||
quoteToken: '0xcb8b5CD20BdCaea9a010aC1F8d835824F5C87A04', | ||
baseToken: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', | ||
}, | ||
], | ||
}; | ||
|
||
const fetchForMarket = async (chainId, quoteToken, baseToken, endpoint) => { | ||
const url = `${BASE_URL}/${chainId}/markets/${quoteToken}-${baseToken}/${endpoint}`; | ||
try { | ||
const response = await fetch(url); | ||
return response.json(); | ||
} catch (error) { | ||
console.error( | ||
`Error fetching slippage tolerance for ${quoteToken}-${baseToken} on chain ${chainId}:`, | ||
error | ||
); | ||
return null; | ||
} | ||
}; | ||
|
||
const fetchVolatilityDetails = async (pair, chainId, quoteToken, baseToken) => { | ||
const result = await fetchForMarket( | ||
chainId, | ||
quoteToken, | ||
baseToken, | ||
'volatilityDetails' | ||
); | ||
|
||
fs.writeFileSync( | ||
`${chainId}-${pair}__volatilityDetails.json`, | ||
JSON.stringify(result, null, 2) | ||
); | ||
}; | ||
|
||
const fetchSlippageTolerance = async (pair, chainId, quoteToken, baseToken) => { | ||
const result = await fetchForMarket( | ||
chainId, | ||
quoteToken, | ||
baseToken, | ||
'slippageTolerance' | ||
); | ||
console.log( | ||
`${pair}: ${result ? result.slippageBps : 'Error fetching data'}` | ||
); | ||
fs.writeFileSync( | ||
`${chainId}-${pair}__slippageTolerance.json`, | ||
JSON.stringify(result, null, 2) | ||
); | ||
}; | ||
|
||
(async function () { | ||
for (const chain in PAIRS_TEST) { | ||
console.log(`\nFetching slippage tolerances for ${chain}:`); | ||
const chainId = NetworkToChainId[chain]; | ||
for (const { pair, quoteToken, baseToken } of PAIRS_TEST[chain]) { | ||
await fetchSlippageTolerance(pair, chainId, quoteToken, baseToken); | ||
await fetchVolatilityDetails(pair, chainId, quoteToken, baseToken); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
libs/repositories/src/Erc20Repository/Erc20RepositoryCache.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
libs/repositories/src/Erc20Repository/Erc20RepositoryViem.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.