Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ ODOS_REFERRAL_CODE=""
OOGABOOGA_API_KEY=""
OX_API_KEY=""
MAGPIE_API_KEY=""
ENSO_API_KEY=""
ENSO_API_KEY=""
BINANCE_WALLET_API_KEY=""
BINANCE_WALLET_SECRET_KEY=""
49 changes: 48 additions & 1 deletion src/common/utils/contractBook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Address } from "viem"
import { type Address, getAddress } from "viem"
import * as chains from "viem/chains"
import { logWarn } from "./logs"

Expand Down Expand Up @@ -62,6 +62,49 @@ const contractBook: any = {
},
}

const SWAP_VERIFIER_ENV_PREFIX = "EULER_SWAP_VERIFIER_ADDRESS_"

// Per-chain SwapVerifier overrides from env, e.g.
// EULER_SWAP_VERIFIER_ADDRESS_8453=0x... . Applied AFTER
// refreshContractBookAddresses so a custom SwapVerifier deployment is never
// reverted to the canonical EulerChains.json address. This mirrors the override
// the Lite app applies to its /api/euler-chains payload, keeping the quote's
// verify.verifierAddress in sync with the verifier the Lite SDK validates
// against (a mismatch makes the SDK reject every quote).
function readSwapVerifierEnvOverrides(
env: NodeJS.ProcessEnv = process.env,
): Record<number, Address> {
const overrides: Record<number, Address> = {}
for (const [key, rawValue] of Object.entries(env)) {
if (!key.startsWith(SWAP_VERIFIER_ENV_PREFIX)) continue
const value = rawValue?.trim()
if (!value) continue
const chainId = Number(key.slice(SWAP_VERIFIER_ENV_PREFIX.length))
if (!Number.isSafeInteger(chainId) || chainId <= 0) {
logWarn({ name: "Invalid SwapVerifier override env key", key })
continue
}
try {
overrides[chainId] = getAddress(value)
} catch {
logWarn({ name: "Invalid SwapVerifier override address", key, value })
}
}
return overrides
}

function applySwapVerifierEnvOverrides(env: NodeJS.ProcessEnv = process.env) {
for (const [chainId, address] of Object.entries(
readSwapVerifierEnvOverrides(env),
)) {
contractBook.swapVerifier.address[Number(chainId)] = address
}
}

// Apply once at module load so the override holds even before the first
// deployment refresh resolves.
applySwapVerifierEnvOverrides()

let refreshPromise: Promise<void> | null = null

async function queryDeployments(url: string): Promise<Deployment[]> {
Expand Down Expand Up @@ -99,6 +142,10 @@ export async function refreshContractBookAddresses() {
peripheryAddrs.swapVerifier
}
}

// Re-assert env overrides last so a custom SwapVerifier is never reverted
// to the canonical deployment address fetched above.
applySwapVerifierEnvOverrides()
})().finally(() => {
refreshPromise = null
})
Expand Down
2 changes: 2 additions & 0 deletions src/swapService/strategies/aggregators/customSourceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from "@balmy/sdk"
import { LocalSourceList } from "@balmy/sdk/dist/services/quotes/source-lists/local-source-list"
import { CustomZRXQuoteSource } from "./sources/0xMatchaQuoteSource"
import { CustomBinanceWalletQuoteSource } from "./sources/binanceWalletQuoteSource"
import { CustomCoWQuoteSource } from "./sources/cowQuoteSource"
import { CustomEnsoQuoteSource } from "./sources/ensoQuoteSource"
import { CustomKyberswapQuoteSource } from "./sources/kyberswapQuoteSource"
Expand Down Expand Up @@ -59,6 +60,7 @@ const customSources = {
[60808],
),
oku_bob_uniswap: new CustomOkuQuoteSource("usor", "Uniswap", [60808]),
"binance-wallet": new CustomBinanceWalletQuoteSource(),
}
export class CustomSourceList extends LocalSourceList {
constructor({ providerService, fetchService }: ConstructorParameters) {
Expand Down
Loading