Skip to content

Commit

Permalink
feat: non-eth price lookup support (#1276)
Browse files Browse the repository at this point in the history
* feat: non-eth price lookup support

Signed-off-by: james-a-morris <[email protected]>

* fix: unit test

Signed-off-by: james-a-morris <[email protected]>

---------

Signed-off-by: james-a-morris <[email protected]>
  • Loading branch information
james-a-morris authored Nov 16, 2024
1 parent 3f2169e commit 7809358
Show file tree
Hide file tree
Showing 6 changed files with 587 additions and 45 deletions.
9 changes: 8 additions & 1 deletion api/_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ export const BLOCK_TAG_LAG = -1;
// we've decided to keep this list small for now.
export const SUPPORTED_CG_BASE_CURRENCIES = new Set(["eth", "usd"]);
// Note: this is a small set of currencies that the API will derive from the base currencies by using USD as an intermediary.
export const SUPPORTED_CG_DERIVED_CURRENCIES = new Set(["matic"]);
export const SUPPORTED_CG_DERIVED_CURRENCIES = new Set(["azero", "matic"]);
export const CG_CONTRACTS_DEFERRED_TO_ID = new Set([
TOKEN_SYMBOLS_MAP.AZERO.addresses[CHAIN_IDs.MAINNET],
]);

// 1:1 because we don't need to handle underlying tokens on FE
export const EXTERNAL_POOL_TOKEN_EXCHANGE_RATE = utils.fixedPointAdjustment;
Expand All @@ -181,6 +184,10 @@ export const ENABLED_POOLS_UNDERLYING_TOKENS = [
export const SECONDS_PER_YEAR = 365 * 24 * 60 * 60;

export const MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
export const MULTICALL3_ADDRESS_OVERRIDES = {
[CHAIN_IDs.ALEPH_ZERO]: "0x3CA11702f7c0F28e0b4e03C31F7492969862C569",
[CHAIN_IDs.ZK_SYNC]: "0xF9cda624FBC7e059355ce98a31693d299FACd963",
};

export const DEFI_LLAMA_POOL_LOOKUP: Record<string, string> = {
"0x36Be1E97eA98AB43b4dEBf92742517266F5731a3":
Expand Down
9 changes: 4 additions & 5 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
DOMAIN_CALLDATA_DELIMITER,
EXTERNAL_POOL_TOKEN_EXCHANGE_RATE,
MULTICALL3_ADDRESS,
MULTICALL3_ADDRESS_OVERRIDES,
SECONDS_PER_YEAR,
TOKEN_SYMBOLS_MAP,
defaultRelayerAddressOverride,
Expand Down Expand Up @@ -1621,8 +1622,9 @@ export async function callViaMulticall3(
}[],
overrides: ethers.CallOverrides = {}
): Promise<ethers.utils.Result[]> {
const chainId = provider.network.chainId;
const multicall3 = new ethers.Contract(
MULTICALL3_ADDRESS,
MULTICALL3_ADDRESS_OVERRIDES[chainId] ?? MULTICALL3_ADDRESS,
MINIMAL_MULTICALL3_ABI,
provider
);
Expand Down Expand Up @@ -1905,10 +1907,7 @@ export function getCachedFillGasUsage(
);
const { nativeGasCost } = await relayerFeeCalculatorQueries.getGasCosts(
buildDepositForSimulation(deposit),
overrides?.relayerAddress,
undefined,
undefined,
true
overrides?.relayerAddress
);
return nativeGasCost;
};
Expand Down
16 changes: 11 additions & 5 deletions api/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getCachedTokenPrice,
} from "./_utils";
import {
CG_CONTRACTS_DEFERRED_TO_ID,
CHAIN_IDs,
SUPPORTED_CG_BASE_CURRENCIES,
SUPPORTED_CG_DERIVED_CURRENCIES,
Expand Down Expand Up @@ -121,11 +122,16 @@ const handler = async (
modifiedBaseCurrency
);
} else {
[, price] = await coingeckoClient.getCurrentPriceByContract(
l1Token,
modifiedBaseCurrency,
platformId
);
[, price] = CG_CONTRACTS_DEFERRED_TO_ID.has(l1Token)
? await coingeckoClient.getCurrentPriceById(
l1Token,
modifiedBaseCurrency
)
: await coingeckoClient.getCurrentPriceByContract(
l1Token,
modifiedBaseCurrency,
platformId
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"private": true,
"license": "AGPL-3.0-only",
"dependencies": {
"@across-protocol/constants": "^3.1.16",
"@across-protocol/contracts": "^3.0.11",
"@across-protocol/constants": "^3.1.20",
"@across-protocol/contracts": "^3.0.16",
"@across-protocol/contracts-v3.0.6": "npm:@across-protocol/[email protected]",
"@across-protocol/sdk": "^3.2.9",
"@across-protocol/sdk": "^3.2.14",
"@amplitude/analytics-browser": "^2.3.5",
"@balancer-labs/sdk": "1.1.6-beta.16",
"@emotion/react": "^11.13.0",
Expand Down
1 change: 1 addition & 0 deletions test/api/_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe("_utils", () => {
"ETH",
"DAI",
"USDC",
"WBTC",
...constants.BRIDGED_USDC_SYMBOLS,
].includes(route.fromTokenSymbol)
)
Expand Down
Loading

0 comments on commit 7809358

Please sign in to comment.