Skip to content

Commit

Permalink
Merge branch 'master' into e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
dohaki committed Nov 5, 2024
2 parents 0493208 + f62ad48 commit 3c27fe0
Show file tree
Hide file tree
Showing 131 changed files with 9,062 additions and 1,692 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:

- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 20
registry-url: https://registry.npmjs.org
cache: yarn

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
.env*.local
.env.e2e
src/data/fill-times-preset.json
src/data/exclusive-relayer-configs.json
src/data/exclusive-relayer-weights.json
src/data/exclusivity-strategy.json
src/data/exclusivity-fill-times.json
src/data/rpc-providers.json

# IDE
.idea
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/hydrogen
lts/iron
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

Web UI for Across.

- App: https://app.across.to
- Docs: https://docs.across.to
- Medium: https://medium.com/across-protocol
- App: <https://app.across.to>
- Docs: <https://docs.across.to>
- Medium: <https://medium.com/across-protocol>

## Development

### Requirements

- [yarn v1.22.22](https://classic.yarnpkg.com/en/docs/install)
- NodeJS >=v18
- [Vercel CLI](https://vercel.com/docs/cli)
- NodeJS >=v20
- [Vercel CLI (35 or higher)](https://vercel.com/docs/cli)

### Local setup

Expand All @@ -34,7 +34,7 @@ Adjust values in the created `.env` accordingly.
Start the frontend with a dev server by running:

```bash
PORT=3000 yarn dev
PORT=3000 vercel dev
```

### Build production bundle
Expand Down
19 changes: 17 additions & 2 deletions api-docs-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ paths:
summary: Retrieve suggested fee quote for a deposit.
description: >
Returns suggested fees based `inputToken`+`outputToken`, `originChainId`, `destinationChainId`, and
`amount`.
`amount`. Also includes data used to compute the fees.
parameters:
- name: inputToken
in: query
Expand Down Expand Up @@ -150,7 +150,7 @@ paths:
type: integer
responses:
200:
description: Suggested fees for the transaction
description: Suggested fees for the transaction and supporting data
content:
application/json:
schema:
Expand All @@ -168,6 +168,14 @@ paths:
"isAmountTooLow": false,
"quoteBlock": "19237525",
"spokePoolAddress": "0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A",
"expectedFillTimeSec": "4",
"limits": {
"minDeposit": "7799819",
"maxDeposit": "22287428516241",
"maxDepositInstant": "201958902363",
"maxDepositShortDelay": "2045367713809",
"recommendedDepositInstant": "201958902363"
}
}
"400":
description: Invalid input
Expand Down Expand Up @@ -517,6 +525,13 @@ components:
to "0", relayer exclusivity will be disabled. This value is returned in cases
where using an exclusive relayer is not reccomended.
example: "10"
expectedFillTimeSec:
type: string
description: >
The expected time (in seconds) for a fill to be made. Represents 75th percentile of the 7-day rolling average of times (updated daily). Times are dynamic by origin/destination token/chain for a given amount.
example: "4"
limits:
$ref: '#/components/schemas/TransferLimits'
TransferLimits:
type: object
properties:
Expand Down
19 changes: 19 additions & 0 deletions api/_abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,23 @@ export const MINIMAL_MULTICALL3_ABI = [
stateMutability: "payable",
type: "function",
},
{
inputs: [
{
internalType: "address",
name: "addr",
type: "address",
},
],
name: "getEthBalance",
outputs: [
{
internalType: "uint256",
name: "balance",
type: "uint256",
},
],
stateMutability: "view",
type: "function",
},
];
112 changes: 112 additions & 0 deletions api/_cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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,
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)) ||
(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 (!this.client) {
return null;
}

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 (!this.client) {
return;
}

try {
if (typeof value === "string") {
try {
const parsedJson = JSON.parse(value);
value = parsedJson;
} catch (error) {
// Do nothing
}
}
await this.client.set(key, value, {
ex: ttl === Number.POSITIVE_INFINITY ? 60 : ttl,
});
return key;
} catch (error) {
console.error("[RedisCache] Error while calling set:", error);
throw error;
}
}
}

export const redisCache = new RedisCache();

export function buildCacheKey(
prefix: string,
...args: (string | number)[]
): string {
return `${prefix}:${args.join(":")}`;
}

export function buildInternalCacheKey(...args: (string | number)[]): string {
return buildCacheKey("QUOTES_API", ...args);
}

export async function getCachedValue<T>(
key: string,
ttl: number,
fetcher: () => Promise<T>,
parser?: (value: T) => T
): Promise<T> {
const cachedValue = await redisCache.get<T>(key);
if (cachedValue) {
return parser ? parser(cachedValue) : cachedValue;
}

const value = await fetcher();
await redisCache.set(key, value, ttl);
return value;
}

export function makeCacheGetterAndSetter<T>(
key: string,
ttl: number,
fetcher: () => Promise<T>,
parser?: (value: T) => T
) {
return {
get: async () => {
return getCachedValue(key, ttl, fetcher, parser);
},
set: async (value?: T) => {
if (!value) {
value = await fetcher();
}
await redisCache.set(key, value, ttl);
},
};
}
43 changes: 20 additions & 23 deletions api/_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const defaultRelayerFeeCapitalCostConfig: {
} = {
ETH: {
lowerBound: ethers.utils.parseUnits("0.0001").toString(),
upperBound: ethers.utils.parseUnits("0.0004").toString(),
cutoff: ethers.utils.parseUnits("750").toString(),
upperBound: ethers.utils.parseUnits("0.000075").toString(),
cutoff: ethers.utils.parseUnits("0.3").toString(),
decimals: 18,
},
WETH: {
lowerBound: ethers.utils.parseUnits("0.0001").toString(),
upperBound: ethers.utils.parseUnits("0.0004").toString(),
cutoff: ethers.utils.parseUnits("750").toString(),
upperBound: ethers.utils.parseUnits("0.000075").toString(),
cutoff: ethers.utils.parseUnits("0.3").toString(),
decimals: 18,
},
WBTC: {
Expand All @@ -34,19 +34,19 @@ const defaultRelayerFeeCapitalCostConfig: {
},
DAI: {
lowerBound: ethers.utils.parseUnits("0.0001").toString(),
upperBound: ethers.utils.parseUnits("0.0004").toString(),
upperBound: ethers.utils.parseUnits("0.0001").toString(),
cutoff: ethers.utils.parseUnits("1500000").toString(),
decimals: 18,
},
USDC: {
lowerBound: ethers.utils.parseUnits("0.0001").toString(),
upperBound: ethers.utils.parseUnits("0.0004").toString(),
cutoff: ethers.utils.parseUnits("1500000").toString(),
upperBound: ethers.utils.parseUnits("0").toString(),
cutoff: ethers.utils.parseUnits("100000").toString(),
decimals: 6,
},
USDT: {
lowerBound: ethers.utils.parseUnits("0.0001").toString(),
upperBound: ethers.utils.parseUnits("0.0004").toString(),
upperBound: ethers.utils.parseUnits("0.0001").toString(),
cutoff: ethers.utils.parseUnits("1500000").toString(),
decimals: 6,
},
Expand Down Expand Up @@ -103,6 +103,9 @@ const defaultRelayerFeeCapitalCostConfig: {
defaultRelayerFeeCapitalCostConfig["USDC.e"] = {
...defaultRelayerFeeCapitalCostConfig["USDC"],
};
defaultRelayerFeeCapitalCostConfig["USDzC"] = {
...defaultRelayerFeeCapitalCostConfig["USDC"],
};
defaultRelayerFeeCapitalCostConfig["USDB"] = {
...defaultRelayerFeeCapitalCostConfig["DAI"],
};
Expand All @@ -111,21 +114,15 @@ export const coinGeckoAssetPlatformLookup: Record<string, string> = {
"0x4200000000000000000000000000000000000042": "optimistic-ethereum",
};

export const defaultRelayerAddressOverridePerToken: Record<
string,
{ relayer: string; destinationChains: number[] }
> = {
SNX: {
relayer: "0x19cDc2b23AF0cC791ca64dda5BFc094Cddda31Cd",
destinationChains: [1, 10],
},
};

export const defaultRelayerAddressOverridePerChain: Record<number, string> =
JSON.parse(process.env.RELAYER_ADDRESS_OVERRIDE_PER_CHAIN || "{}");

export const defaultRelayerAddressOverride =
process.env.RELAYER_ADDRESS_OVERRIDE;
export const defaultRelayerAddressOverride: {
defaultAddr?: string;
symbols?: {
[symbol: string]: {
defaultAddr?: string;
chains?: { [chainId: string]: string };
};
};
} = JSON.parse(process.env.RELAYER_ADDRESS_OVERRIDES || "{}");

export const graphAPIKey = process.env.GRAPH_API_KEY;

Expand Down
Loading

0 comments on commit 3c27fe0

Please sign in to comment.