Skip to content

Commit

Permalink
Merge branch 'master' into feat/custom-gas-token
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 committed Nov 14, 2024
2 parents eba042c + 4fe3f0e commit 396210f
Show file tree
Hide file tree
Showing 19 changed files with 726 additions and 363 deletions.
29 changes: 22 additions & 7 deletions api/_cache.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
import { kv } from "@vercel/kv";
import { createClient, VercelKV } from "@vercel/kv";
import { interfaces } from "@across-protocol/sdk";

const {
KV_REST_API_READ_ONLY_TOKEN,
KV_REST_API_TOKEN,
KV_REST_API_URL,
KV_URL,
UPSTASH_REDIS_REST_URL,
UPSTASH_REDIS_REST_TOKEN,
UPSTASH_REDIS_READ_ONLY_TOKEN,
} = process.env;
const isRedisCacheEnabled =
KV_REST_API_URL && KV_REST_API_TOKEN && KV_REST_API_READ_ONLY_TOKEN && KV_URL;
(KV_REST_API_URL && (KV_REST_API_TOKEN || KV_REST_API_READ_ONLY_TOKEN)) ||
(UPSTASH_REDIS_REST_URL &&
(UPSTASH_REDIS_REST_TOKEN || UPSTASH_REDIS_READ_ONLY_TOKEN));

export class RedisCache implements interfaces.CachingMechanismInterface {
private client: VercelKV | undefined;

constructor() {
this.client = isRedisCacheEnabled
? createClient({
url: UPSTASH_REDIS_REST_URL || KV_REST_API_URL,
token: UPSTASH_REDIS_REST_TOKEN || KV_REST_API_TOKEN,
})
: undefined;
}

async get<T>(key: string): Promise<T | null> {
if (!isRedisCacheEnabled) {
if (!this.client) {
return null;
}

const value = await kv.get(key);
const value = await this.client.get(key);
if (value === null || value === undefined) {
return null;
}
return value as T;
}

async set<T>(key: string, value: T, ttl = 10): Promise<string | undefined> {
if (!isRedisCacheEnabled) {
if (!this.client) {
return;
}

Expand All @@ -37,7 +52,7 @@ export class RedisCache implements interfaces.CachingMechanismInterface {
// Do nothing
}
}
await kv.set(key, value, {
await this.client.set(key, value, {
ex: ttl === Number.POSITIVE_INFINITY ? 60 : ttl,
});
return key;
Expand Down
1 change: 1 addition & 0 deletions api/_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export function handleErrorCondition(
const logLevel = acrossApiError.status >= 500 ? "error" : "warn";
logger[logLevel]({
at: endpoint,
code: acrossApiError.code,
message: `Status ${acrossApiError.status} - ${acrossApiError.message}`,
});

Expand Down
5 changes: 4 additions & 1 deletion api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,10 @@ export function getCachedFillGasUsage(
);
const { nativeGasCost } = await relayerFeeCalculatorQueries.getGasCosts(
buildDepositForSimulation(deposit),
overrides?.relayerAddress
overrides?.relayerAddress,
undefined,
undefined,
true
);
return nativeGasCost;
};
Expand Down
4 changes: 2 additions & 2 deletions api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ const handler = async (
message: "Response data",
responseJson,
});
// Respond with a 200 status code and 15 seconds of cache with
// Respond with a 200 status code and 10 seconds of cache with
// 45 seconds of stale-while-revalidate.
sendResponse(response, responseJson, 200, 15, 45);
sendResponse(response, responseJson, 200, 10, 45);
} catch (error: unknown) {
return handleErrorCondition("limits", response, logger, error);
}
Expand Down
6 changes: 5 additions & 1 deletion api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ const handler = async (
responseJson,
});

response.setHeader("Cache-Control", "s-maxage=10");
// Only cache response if exclusivity is not set. This prevents race conditions where
// cached exclusivity data is returned for multiple deposits.
if (exclusiveRelayer === sdk.constants.ZERO_ADDRESS) {
response.setHeader("Cache-Control", "s-maxage=10");
}
response.status(200).json(responseJson);
} catch (error) {
return handleErrorCondition("suggested-fees", response, logger, error);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@across-protocol/constants": "^3.1.16",
"@across-protocol/contracts": "^3.0.11",
"@across-protocol/contracts-v3.0.6": "npm:@across-protocol/[email protected]",
"@across-protocol/sdk": "^3.2.8",
"@across-protocol/sdk": "^3.2.9",
"@amplitude/analytics-browser": "^2.3.5",
"@balancer-labs/sdk": "1.1.6-beta.16",
"@emotion/react": "^11.13.0",
Expand All @@ -26,7 +26,7 @@
"@uniswap/sdk-core": "^4.2.0",
"@uniswap/v3-sdk": "^3.11.0",
"@vercel/kv": "^2.0.0",
"@web3-onboard/coinbase": "^2.2.5",
"@web3-onboard/coinbase": "^2.4.1",
"@web3-onboard/core": "^2.21.2",
"@web3-onboard/gnosis": "^2.2.0",
"@web3-onboard/injected-wallets": "^2.11.1",
Expand Down Expand Up @@ -78,6 +78,7 @@
"generate:routes": "tsx scripts/generate-routes.ts",
"generate:routes:e2e": "tsx scripts/generate-e2e-test-routes.ts",
"generate:routes:mainnet": "yarn generate:routes 1",
"generate:routes:testnet": "yarn generate:routes 11155111",
"generate:chain-config": "tsx scripts/generate-chain-config.ts",
"generate:ui-assets": "tsx scripts/generate-ui-assets.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/chain-configs/optimism-sepolia/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
chainId,
publicRpcUrl: "https://sepolia.optimism.io",
tokens: [],
tokens: ["ETH", "WETH", "USDC"],
enableCCTP: false,
swapTokens: [],
} as ChainConfig;
2 changes: 1 addition & 1 deletion scripts/chain-configs/scroll/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
chainId,
publicRpcUrl: "https://rpc.scroll.io",
blockTimeSeconds: 3,
tokens: ["WETH", "ETH", "USDC", "USDT", "WBTC"],
tokens: ["WETH", "ETH", "USDC", "USDT", "WBTC", "POOL"],
enableCCTP: false,
swapTokens: [],
} as ChainConfig;
24 changes: 15 additions & 9 deletions scripts/generate-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ import { utils as sdkUtils } from "@across-protocol/sdk";
import { utils } from "ethers";
import { writeFileSync } from "fs";
import * as prettier from "prettier";

import path from "path";
import * as chainConfigs from "./chain-configs";

function getTokenSymbolForLogo(tokenSymbol: string): string {
switch (tokenSymbol) {
case "USDC.e":
case "USDbC":
case "USDzC":
return "USDC";
default:
return tokenSymbol;
}
}

function getDeployedAddress(contractName: string, chainId: number): string {
return sdkUtils.getDeployedAddress(contractName, chainId, true) as string;
}
Expand Down Expand Up @@ -60,12 +71,7 @@ const enabledRoutes = {
"0x9040e41eF5E8b281535a96D9a48aCb8cfaBD9a48",
merkleDistributorAddress: "0xE50b2cEAC4f60E840Ae513924033E753e2366487",
claimAndStakeAddress: "0x985e8A89Dd6Af8896Ef075c8dd93512433dc5829",
pools: [
{
tokenSymbol: "BOBA",
isNative: false,
},
],
pools: [],
spokePoolVerifier: {
address: "0xB4A8d45647445EA9FC3E1058096142390683dBC2",
enabledChains: [
Expand Down Expand Up @@ -405,15 +411,15 @@ async function generateRoutes(hubPoolChainId = 1) {
symbol: tokenSymbol,
name: tokenInfo.name,
decimals: tokenInfo.decimals,
logoUrl: `${assetsBaseUrl}/src/assets/token-logos/${tokenSymbol.toLowerCase()}.svg`,
logoUrl: `${assetsBaseUrl}/src/assets/token-logos/${getTokenSymbolForLogo(tokenSymbol).toLowerCase()}.svg`,
};
};
return {
chainId: chainConfig.chainId,
name: chainConfig.name,
publicRpcUrl: chainConfig.publicRpcUrl,
explorerUrl: chainConfig.blockExplorer,
logoUrl: `${assetsBaseUrl}/scripts/chain-configs/${chainKey.toLowerCase()}/assets/logo.svg`,
logoUrl: `${assetsBaseUrl}${path.resolve("/scripts/chain-configs/", chainKey.toLowerCase().replace("_", "-"), chainConfig.logoPath)}`,
spokePool: chainConfig.spokePool.address,
spokePoolBlock: chainConfig.spokePool.blockNumber,
inputTokens: routeFileContent.routes
Expand Down
7 changes: 6 additions & 1 deletion src/components/Wallet/Web3Subscribe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const Web3Subscribe = () => {

// Check if CBWallet is available
useEffect(() => {
setIsCBWallet(wallet?.label === "Coinbase Wallet");
const cbExtensionEnabled =
(window as any)?.coinbaseWalletExtension?.connectionType ===
"extension_connection_type";

const cbWalletSelected = wallet?.label === "Coinbase Wallet";
setIsCBWallet(cbExtensionEnabled && cbWalletSelected);
}, [wallet]);

useEffect(() => {
Expand Down
46 changes: 30 additions & 16 deletions src/data/chains_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0x68f180fcCe6836688e9084f035309E29Bf0A2095",
Expand Down Expand Up @@ -454,7 +454,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
Expand Down Expand Up @@ -614,7 +614,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
Expand Down Expand Up @@ -672,7 +672,7 @@
"name": "zkSync",
"publicRpcUrl": "https://mainnet.era.zksync.io",
"explorerUrl": "https://era.zksync.network",
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/scripts/chain-configs/zk_sync/assets/logo.svg",
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/scripts/chain-configs/zk-sync/assets/logo.svg",
"spokePool": "0xE0B015E54d54fc84a6cB9B666099c46adE9335FF",
"spokePoolBlock": 10352565,
"inputTokens": [
Expand All @@ -695,7 +695,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0xBBeB516fb02a01611cBBE0453Fe3c580D7281011",
Expand Down Expand Up @@ -739,7 +739,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0xBBeB516fb02a01611cBBE0453Fe3c580D7281011",
Expand Down Expand Up @@ -843,7 +843,7 @@
"symbol": "USDbC",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdbc.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
Expand Down Expand Up @@ -896,7 +896,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0xA219439258ca9da29E9Cc4cE5596924745e12B93",
Expand Down Expand Up @@ -940,7 +940,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0x3aAB2285ddcDdaD8edf438C1bAB47e1a9D05a9b4",
Expand Down Expand Up @@ -993,7 +993,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0xf0F161fDA2712DB8b566946122a5af183995e2eD",
Expand Down Expand Up @@ -1030,7 +1030,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0xcDd475325D6F564d27247D1DddBb0DAc6fA0a5CF",
Expand Down Expand Up @@ -1229,6 +1229,13 @@
"name": "Wrapped Bitcoin",
"decimals": 8,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/wbtc.svg"
},
{
"address": "0xF9Af83FC41e0cc2af2fba93644D542Df6eA0F2b7",
"symbol": "POOL",
"name": "PoolTogether",
"decimals": 18,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/pool.svg"
}
],
"outputTokens": [
Expand Down Expand Up @@ -1266,6 +1273,13 @@
"name": "Tether USD",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdt.svg"
},
{
"address": "0xF9Af83FC41e0cc2af2fba93644D542Df6eA0F2b7",
"symbol": "POOL",
"name": "PoolTogether",
"decimals": 18,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/pool.svg"
}
]
},
Expand Down Expand Up @@ -1338,7 +1352,7 @@
"symbol": "USDzC",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdzc.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
}
],
"outputTokens": [
Expand All @@ -1361,7 +1375,7 @@
"symbol": "USDzC",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdzc.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
}
]
},
Expand All @@ -1370,7 +1384,7 @@
"name": "World Chain",
"publicRpcUrl": "https://worldchain-mainnet.g.alchemy.com/public",
"explorerUrl": "https://worldchain-mainnet-explorer.alchemy.com",
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/scripts/chain-configs/world_chain/assets/logo.svg",
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/scripts/chain-configs/world-chain/assets/logo.svg",
"spokePool": "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64",
"spokePoolBlock": 4524742,
"inputTokens": [
Expand Down Expand Up @@ -1400,7 +1414,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
}
],
"outputTokens": [
Expand All @@ -1423,7 +1437,7 @@
"symbol": "USDC.e",
"name": "USD Coin (bridged)",
"decimals": 6,
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.e.svg"
"logoUrl": "https://raw.githubusercontent.com/across-protocol/frontend/master/src/assets/token-logos/usdc.svg"
},
{
"address": "0x03C7054BCB39f7b2e5B2c7AcB37583e32D70Cfa3",
Expand Down
Loading

0 comments on commit 396210f

Please sign in to comment.