diff --git a/README.md b/README.md index 945d4fc63..d94310a72 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,11 @@ The file `common.ts` with type [`AppConfig`](src/config/types.ts) contains impor - `defaultLimitedApproval`: Optional flag to set the default ERC-20 approval to limited approval. For chains where gas is low, it is recommended to set this flag to true. - `gasToken`: Gas token name, symbol, decimals, address and logoURI. This parameter will take priority over the `tokenListOverride`. - `blockExplorer`: The name and URL of the block explorer to be used in the notifications and when the network is added to the injected wallet. - - `rpc`: The RPC url and headers of the network, used to add the network to the injected wallet and to fetch data from the chain. + - `rpc`: + - `url`: RPC url of the network + - `headers`: Headers append to each request to the RPC network + - `batchSize`: The maximum number of JSON-RPC requests to send in a batch + - `wait`: The maximum number of milliseconds to wait before sending a batch - `defaultTokenPair`: Default token pair to be used in the app when opening the trade, explore, and simulation pages. - `popularPairs`: List of popular pairs to be used in the app when opening the token selection modal. - `popularTokens`: List of popular tokens to be used in the app when opening the token selection modal. @@ -276,6 +280,9 @@ The file `common.ts` with type [`AppConfig`](src/config/types.ts) contains impor - `tokenLists`: List of token lists including the uri and the parser name to be used to parse the token list. Please update the tokenParserMap in the `src/config/utils.ts` file to include the parser name and the parser function. - `sdk`: - `cacheTTL`: When the app loads, it will ignore any cached data if it is older than the cacheTTL time in milliseconds. If set to 0, the app will always ignore the cache data and fetch new data on load. + - `pairBatchSize`: Amount of pairs batched together in the same multicall when calling strategiesByPair + - `blockRangeSize`: Max number of blocks to read logs from in a single call. Each time the SDK reads logs since last processed block it will split the total range into smaller ranges according to this configuration. This should be determined according to the RPC limitations. + - `refreshInterval`: interval in millisecond between each cycle of reading latest events from the chain. - `tenderly` - `faucetTokens`: List of address to get tokens from in the debug page - `ui` diff --git a/e2e/screenshots/simulator/recurring/Recurring_range_limit/simulator-input-price.png b/e2e/screenshots/simulator/recurring/Recurring_range_limit/simulator-input-price.png index 21186cabc..6829b3aa2 100644 Binary files a/e2e/screenshots/simulator/recurring/Recurring_range_limit/simulator-input-price.png and b/e2e/screenshots/simulator/recurring/Recurring_range_limit/simulator-input-price.png differ diff --git a/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/form.png b/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/form.png index 51935449f..d4209ac59 100644 Binary files a/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/form.png and b/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/form.png differ diff --git a/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/my-strategy.png b/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/my-strategy.png index d40d85c1c..257b0ee0d 100644 Binary files a/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/my-strategy.png and b/e2e/screenshots/strategy/disposable/Disposable_buy_limit/create/my-strategy.png differ diff --git a/e2e/screenshots/strategy/disposable/Disposable_buy_limit/deposit/form.png b/e2e/screenshots/strategy/disposable/Disposable_buy_limit/deposit/form.png index 3178226d4..ac5d38ff2 100644 Binary files a/e2e/screenshots/strategy/disposable/Disposable_buy_limit/deposit/form.png and b/e2e/screenshots/strategy/disposable/Disposable_buy_limit/deposit/form.png differ diff --git a/e2e/screenshots/strategy/disposable/Disposable_sell_range/create/my-strategy.png b/e2e/screenshots/strategy/disposable/Disposable_sell_range/create/my-strategy.png index 511ee2159..1920c88c0 100644 Binary files a/e2e/screenshots/strategy/disposable/Disposable_sell_range/create/my-strategy.png and b/e2e/screenshots/strategy/disposable/Disposable_sell_range/create/my-strategy.png differ diff --git a/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/form.png b/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/form.png index 84f0d9a22..68ef8c144 100644 Binary files a/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/form.png and b/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/form.png differ diff --git a/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/my-strategy.png b/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/my-strategy.png index 3b6a65ffe..b1fc45e53 100644 Binary files a/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/my-strategy.png and b/e2e/screenshots/strategy/recurring/Recurring_limit_limit/create/my-strategy.png differ diff --git a/e2e/screenshots/strategy/recurring/Recurring_limit_range/create/form.png b/e2e/screenshots/strategy/recurring/Recurring_limit_range/create/form.png index 21673af1f..1c65db83a 100644 Binary files a/e2e/screenshots/strategy/recurring/Recurring_limit_range/create/form.png and b/e2e/screenshots/strategy/recurring/Recurring_limit_range/create/form.png differ diff --git a/e2e/screenshots/strategy/recurring/Recurring_range_limit/create/form.png b/e2e/screenshots/strategy/recurring/Recurring_range_limit/create/form.png index eb51923cf..c7eb6a00f 100644 Binary files a/e2e/screenshots/strategy/recurring/Recurring_range_limit/create/form.png and b/e2e/screenshots/strategy/recurring/Recurring_range_limit/create/form.png differ diff --git a/e2e/screenshots/strategy/recurring/Recurring_range_range/create/form.png b/e2e/screenshots/strategy/recurring/Recurring_range_range/create/form.png index c7b5b79c5..eef9e9ca6 100644 Binary files a/e2e/screenshots/strategy/recurring/Recurring_range_range/create/form.png and b/e2e/screenshots/strategy/recurring/Recurring_range_range/create/form.png differ diff --git a/e2e/screenshots/strategy/recurring/Recurring_range_range/create/my-strategy.png b/e2e/screenshots/strategy/recurring/Recurring_range_range/create/my-strategy.png index 2c3c277f7..b22316490 100644 Binary files a/e2e/screenshots/strategy/recurring/Recurring_range_range/create/my-strategy.png and b/e2e/screenshots/strategy/recurring/Recurring_range_range/create/my-strategy.png differ diff --git a/package.json b/package.json index 12da616f4..50c0e8852 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "dependencies": { "@babel/core": "^7.0.0-0", - "@bancor/carbon-sdk": "0.0.105-DEV", + "@bancor/carbon-sdk": "0.0.106-DEV", "@cloudflare/workers-types": "^4.20230717.0", "@ethersproject/abi": "^5.0.0", "@ethersproject/bytes": "^5.0.0", diff --git a/src/config/configSchema.ts b/src/config/configSchema.ts index e63867716..7b9f1c5c8 100644 --- a/src/config/configSchema.ts +++ b/src/config/configSchema.ts @@ -26,6 +26,8 @@ export const AppConfigSchema = v.object({ rpc: v.object({ url: v.string(), headers: v.optional(v.record(v.string(), v.string())), + batchSize: v.optional(v.number()), + wait: v.optional(v.number()), }), blockExplorer: v.object({ name: v.string(), @@ -42,6 +44,9 @@ export const AppConfigSchema = v.object({ }), sdk: v.object({ cacheTTL: v.number(), + pairBatchSize: v.optional(v.number()), + blockRangeSize: v.optional(v.number()), + refreshInterval: v.optional(v.number()), }), defaultTokenPair: v.tuple([v.string(), v.string()]), popularPairs: v.array(v.tuple([v.string(), v.string()])), diff --git a/src/hooks/useCarbonInit.ts b/src/hooks/useCarbonInit.ts index 341fdb62a..1ab2bbb59 100644 --- a/src/hooks/useCarbonInit.ts +++ b/src/hooks/useCarbonInit.ts @@ -99,7 +99,12 @@ export const useCarbonInit = () => { }, contractsConfig, getTokenDecimalMap(), - cacheData + { + cache: cacheData, + pairBatchSize: config.sdk.pairBatchSize, + blockRangeSize: config.sdk.blockRangeSize, + refreshInterval: config.sdk.refreshInterval, + } ), carbonSDK.setOnChangeHandlers( Comlink.proxy(onPairDataChangedCallback), diff --git a/src/libs/queries/sdk/pairs.ts b/src/libs/queries/sdk/pairs.ts index cdf83a66c..9a759ccfb 100644 --- a/src/libs/queries/sdk/pairs.ts +++ b/src/libs/queries/sdk/pairs.ts @@ -33,18 +33,25 @@ export const useGetTradePairsData = () => { markForMissing(pair[1]); } + const missingTokens: Token[] = []; const getMissing = Array.from(missing).map(async (address) => { const token = await fetchTokenData(Token, address); + missingTokens.push(token); tokens.set(address, token); return token; }); - const missingTokens = await Promise.all(getMissing); + const responses = await Promise.allSettled(getMissing); + for (const response of responses) { + if (response.status === 'rejected') console.error(response.reason); + } importTokens(missingTokens); - const result = pairs.map((pair) => ({ - baseToken: tokens.get(pair[0])!, - quoteToken: tokens.get(pair[1])!, - })); + const result: { baseToken: Token; quoteToken: Token }[] = []; + for (const pair of pairs) { + const baseToken = tokens.get(pair[0]); + const quoteToken = tokens.get(pair[1]); + if (baseToken && quoteToken) result.push({ baseToken, quoteToken }); + } const pairsWithInverse = [ ...result, diff --git a/src/libs/wagmi/chains.ts b/src/libs/wagmi/chains.ts index 6f12ab35a..a4b53dc49 100644 --- a/src/libs/wagmi/chains.ts +++ b/src/libs/wagmi/chains.ts @@ -40,5 +40,9 @@ export const configTransports = { fetchOptions: { headers: RPC_HEADERS[CHAIN_ID], }, + batch: { + batchSize: config.network.rpc.batchSize, + wait: config.network.rpc.wait, + }, }), }; diff --git a/src/workers/sdk.ts b/src/workers/sdk.ts index c06af8342..a287c80ef 100644 --- a/src/workers/sdk.ts +++ b/src/workers/sdk.ts @@ -42,7 +42,12 @@ const init = async ( }, config: ContractsConfig, decimalsMap?: Map, - cachedData?: string + sdkConfig?: { + cache?: string; + pairBatchSize?: number; + blockRangeSize?: number; + refreshInterval?: number; + } ) => { if (isInitialized || isInitializing) return; isInitializing = true; @@ -54,7 +59,13 @@ const init = async ( chainId ); api = new ContractsApi(provider, config); - const { cache, startDataSync } = initSyncedCache(api.reader, cachedData); + const { cache, startDataSync } = initSyncedCache( + api.reader, + sdkConfig?.cache, + sdkConfig?.pairBatchSize, + sdkConfig?.refreshInterval, + sdkConfig?.blockRangeSize + ); sdkCache = cache; carbonSDK = new Toolkit( api, diff --git a/yarn.lock b/yarn.lock index a45f16eb6..8264b94e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1623,17 +1623,17 @@ "@babel/helper-string-parser" "^7.25.9" "@babel/helper-validator-identifier" "^7.25.9" -"@bancor/carbon-sdk@0.0.105-DEV": - version "0.0.105-DEV" - resolved "https://registry.yarnpkg.com/@bancor/carbon-sdk/-/carbon-sdk-0.0.105-DEV.tgz#3001161f694b87ea92dcf5f1980ab0c3a04cb632" - integrity sha512-79gJnx8M5NRz67/gAkFFq1qBd8A5y3mwGbyGM2xsOh2bw2EYmfNdUM5KnCYOgo925oWJRyDuglptf4m5oC1J9Q== +"@bancor/carbon-sdk@0.0.106-DEV": + version "0.0.106-DEV" + resolved "https://registry.yarnpkg.com/@bancor/carbon-sdk/-/carbon-sdk-0.0.106-DEV.tgz#8fcc85a58f220bd7621e021a30078d71a402cb20" + integrity sha512-cErAvJwGmf82d2XnaqCCXuB7DrGHBo9Ktyl2d/eoArH+gkcUZlHwxuv8VryRShmbzQfFPcmXjyBAMEkTpFxOOA== dependencies: "@ethersproject/abi" "^5.7.0" "@ethersproject/bignumber" "^5.7.0" "@ethersproject/contracts" "^5.7.0" "@ethersproject/providers" "^5.7.2" "@ethersproject/units" "^5.7.0" - decimal.js "^10.4.3" + decimal.js "^10.5.0" ethers "^5.7.2" events "^3.3.0" @@ -5786,6 +5786,11 @@ decimal.js@^10.4.2, decimal.js@^10.4.3: resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.4.3.tgz#1044092884d245d1b7f65725fa4ad4c6f781cc23" integrity sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA== +decimal.js@^10.5.0: + version "10.5.0" + resolved "https://registry.yarnpkg.com/decimal.js/-/decimal.js-10.5.0.tgz#0f371c7cf6c4898ce0afb09836db73cd82010f22" + integrity sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw== + decode-uri-component@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.2.tgz#e69dbe25d37941171dd540e024c444cd5188e1e9"