Skip to content
Open
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
7 changes: 6 additions & 1 deletion api/src/lib/brokerCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export async function initializeBrokerCreation(): Promise<void> {
evmPrivateKey = walletKeys.evmPrivateKey;
solanaPrivateKey = walletKeys.solanaPrivateKey;

const evmWallet = new ethers.Wallet(evmPrivateKey);
let evmWallet: ethers.Wallet;
try {
evmWallet = new ethers.Wallet(evmPrivateKey);
} catch {
throw new Error("Invalid broker creation EVM private key");
}
console.log("✅ EVM private key loaded");
console.log(`📍 EVM wallet address: ${evmWallet.address}`);

Expand Down
155 changes: 153 additions & 2 deletions api/src/models/dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { z } from "zod";
import { getPrisma } from "../lib/prisma";
import type { Prisma, Dex, PrismaClient } from "@prisma/client";
import type { DexResult, Result } from "../lib/types";
import { DexErrorType } from "../lib/types";
import { DexErrorType, GitHubErrorType } from "../lib/types";
import {
forkTemplateRepository,
setupRepositoryWithSingleCommit,
deleteRepository,
setCustomDomain,
removeCustomDomain,
checkForTemplateUpdates,
} from "../lib/github";
import { CAMPAIGNS_INTRO_COMMIT_PREFIXES } from "../../../config";
import type { DexConfig } from "../lib/types";
import { generateRepositoryName } from "../lib/nameGenerator";
import { validateTradingViewColorConfig } from "./tradingViewConfig.js";
import { validateCSS } from "../lib/cssValidator.js";

Expand Down Expand Up @@ -59,6 +62,54 @@ export function convertDexToDexConfig(dex: Dex): DexConfig {
};
}

function convertValidatedDataToDexConfig(
validatedData: z.infer<typeof dexSchema>,
brokerId: string,
brokerName: string
): DexConfig {
const decodedAnalyticsScript = validatedData.analyticsScript
? decodeBase64(validatedData.analyticsScript)
: null;

return {
brokerId,
brokerName,
chainIds: validatedData.chainIds ?? null,
defaultChain: validatedData.defaultChain ?? null,
themeCSS: validatedData.themeCSS ?? null,
telegramLink: validatedData.telegramLink ?? null,
discordLink: validatedData.discordLink ?? null,
xLink: validatedData.xLink ?? null,
walletConnectProjectId: validatedData.walletConnectProjectId ?? null,
privyAppId: validatedData.privyAppId ?? null,
privyTermsOfUse: validatedData.privyTermsOfUse ?? null,
privyLoginMethods: validatedData.privyLoginMethods ?? null,
enabledMenus: validatedData.enabledMenus ?? null,
customMenus: validatedData.customMenus ?? null,
enableAbstractWallet: validatedData.enableAbstractWallet ?? null,
disableMainnet: validatedData.disableMainnet ?? null,
disableTestnet: validatedData.disableTestnet ?? null,
disableEvmWallets: validatedData.disableEvmWallets ?? null,
disableSolanaWallets: validatedData.disableSolanaWallets ?? null,
enableServiceDisclaimerDialog:
validatedData.enableServiceDisclaimerDialog ?? null,
enableCampaigns: validatedData.enableCampaigns ?? null,
tradingViewColorConfig: validatedData.tradingViewColorConfig ?? null,
availableLanguages: validatedData.availableLanguages ?? null,
seoSiteName: validatedData.seoSiteName ?? null,
seoSiteDescription: validatedData.seoSiteDescription ?? null,
seoSiteLanguage: validatedData.seoSiteLanguage ?? null,
seoSiteLocale: validatedData.seoSiteLocale ?? null,
seoTwitterHandle: validatedData.seoTwitterHandle ?? null,
seoThemeColor: validatedData.seoThemeColor ?? null,
seoKeywords: validatedData.seoKeywords ?? null,
analyticsScript: decodedAnalyticsScript,
symbolList: validatedData.symbolList ?? null,
restrictedRegions: validatedData.restrictedRegions ?? null,
whitelistedIps: validatedData.whitelistedIps ?? null,
};
}

export type Environment = "mainnet" | "staging" | "qa" | "dev";

export function getCurrentEnvironment(): Environment {
Expand Down Expand Up @@ -435,9 +486,109 @@ export async function createDex(
};
}

const brokerName = validatedData.brokerName || "Orderly DEX";
const integrationType = validatedData.integrationType || "low_code";

const repoUrl: string | null = null;
let repoUrl: string | null = null;

if (integrationType === "low_code") {
const repoName = generateRepositoryName(brokerName);

try {
console.log(
"Creating repository in OrderlyNetworkDexCreator organization..."
);
const forkResult = await forkTemplateRepository(repoName);
if (!forkResult.success) {
switch (forkResult.error.type) {
case GitHubErrorType.REPOSITORY_NAME_EMPTY:
case GitHubErrorType.REPOSITORY_NAME_INVALID:
case GitHubErrorType.REPOSITORY_NAME_TOO_LONG:
return {
success: false,
error: {
type: DexErrorType.VALIDATION_ERROR,
message: forkResult.error.message,
},
};
case GitHubErrorType.FORK_PERMISSION_DENIED:
return {
success: false,
error: {
type: DexErrorType.REPOSITORY_PERMISSION_DENIED,
message: forkResult.error.message,
},
};
case GitHubErrorType.FORK_REPOSITORY_NOT_FOUND:
return {
success: false,
error: {
type: DexErrorType.REPOSITORY_NOT_FOUND,
message: forkResult.error.message,
},
};
case GitHubErrorType.FORK_REPOSITORY_ALREADY_EXISTS:
return {
success: false,
error: {
type: DexErrorType.REPOSITORY_ALREADY_EXISTS,
message: forkResult.error.message,
},
};
default:
return {
success: false,
error: {
type: DexErrorType.REPOSITORY_CREATION_FAILED,
message: forkResult.error.message,
},
};
}
}

repoUrl = forkResult.data;
console.log(`Successfully forked repository: ${repoUrl}`);

const repoInfo = extractRepoInfoFromUrl(repoUrl);
if (!repoInfo) {
return {
success: false,
error: {
type: DexErrorType.REPOSITORY_INFO_EXTRACTION_FAILED,
message: `Failed to extract repository information from URL: ${repoUrl}`,
},
};
}

const brokerId = "demo";

await setupRepositoryWithSingleCommit(
repoInfo.owner,
repoInfo.repo,
convertValidatedDataToDexConfig(validatedData, brokerId, brokerName),
{
primaryLogo: validatedData.primaryLogo ?? null,
secondaryLogo: validatedData.secondaryLogo ?? null,
favicon: validatedData.favicon ?? null,
pnlPosters: validatedData.pnlPosters ?? null,
},
null,
user.address
);
console.log(`Successfully set up repository for ${brokerName}`);
} catch (error) {
console.error("Error setting up repository:", error);
return {
success: false,
error: {
type: DexErrorType.REPOSITORY_CREATION_FAILED,
message: `Repository setup failed: ${
error instanceof Error ? error.message : String(error)
}`,
},
};
}
}

try {
const brokerId = "demo";
Expand Down
1 change: 1 addition & 0 deletions app/scripts/check-i18n-untranslated.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const INTENTIONALLY_IDENTICAL = new Set([
"seoConfig.siteLocalePlaceholder",
"seoConfig.themeColorPlaceholder",
"customDomain.ttl",
"landing.tvl",
"settings.dexId",
]);

Expand Down
8 changes: 4 additions & 4 deletions app/src/components/orderly/ApiKeyRequiredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAccount, useChainId, useWalletClient } from "wagmi";
import { useLocation } from "@remix-run/react";
import { useLocalizedNavigate } from "@/utils/localizedRoute";
import { Modal } from "@/components/orderly/Modal";
import { OdsCheckbox } from "@/components/orderly/OdsCheckbox";
import { getOrderlyEnvConfig } from "@/utils/environment";
import {
hasCompleteStoredAdminApiKey,
Expand Down Expand Up @@ -222,12 +223,11 @@ export function ApiKeyRequiredOverlay() {
</div>
)}
<label className="flex cursor-pointer items-start gap-3 rounded-xl border border-(--line-subtle) bg-(--bg-surface-secondary) px-4 py-3 text-left">
<input
type="checkbox"
<OdsCheckbox
checked={rememberSigningKey}
onChange={event => setRememberSigningKey(event.target.checked)}
onCheckedChange={checked => setRememberSigningKey(checked === true)}
disabled={creating}
className="mt-0.5 h-4 w-4 rounded border-(--line-subtle) bg-transparent accent-(--fg-brand)"
className="mt-0.5"
/>
<span className="text-sm leading-5 text-(--fg-secondary)">
<span className="block font-medium text-(--fg-primary)">
Expand Down
Loading
Loading