Enso 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 35쪽 중 24쪽

oute Widget Flow" /> ## How it Works The widget connects to the connected wallet and allows user to: 1. Select token 2. Enter amount to spend 3. Check quote execution quote and parameters 4. Execute operation and track progress including cross-chain execution ## Integrate <Steps> <Step title="Install the package"> Install the widget: ``` npm i @ensofinance/checkout-widget ``` </Step> <Step title="API key"> You can get an API key from the [Developer Portal](https://developers.enso.build). </Step> <Step title="Basic implementation"> Import and configure the widget. <Info> Any of the [tokens](/api-reference/tokens/tokens) or [nontokenized positions](/api-reference/tokens/nontokenized-positions) can be used as `tokenOut` </Info> <Tabs> <Tab title="Checkout Modal"> ```tsx theme={null} import { CheckoutModal } from '@ensofinance/checkout-widget'; export function MyCheckoutComponentModal() { const [isCheckoutActive, setIsCheckoutActive] = useState(false); return ( <CheckoutModal config={{ apiKey: "YOUR_API_KEY", tokenOut: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", chainIdOut: 8453 }} isActive={isCheckoutActive} setIsActive={setIsCheckoutActive} /> ); } ``` </Tab> <Tab title="Standalone Checkout"> ```tsx theme={null} import { Checkout } from '@ensofinance/checkout-widget'; export function MyCheckoutComponent() { return ( <div className="checkout-container"> <Checkout config={{ apiKey: "YOUR_API_KEY", tokenOut: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", chainIdOut: 8453 }} /> </div> ); } ``` </Tab> </Tabs> </Step> <Step title="Setup Web3 providers"> The widget requires Wagmi and React Query providers. Set up your app's root component: ```tsx theme={null} import { WagmiProvider, createConfig, http } from 'wagmi'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { base, mainnet, arbitrum } from 'wagmi/chains'; import { injected, walletConnect } from 'wagmi/connectors'; // Configure supported chains and connectors const config = createConfig({ chains: [mainnet, base, arbitrum], connectors: [ injected(), // MetaMask, Rabby, etc. walletConnect({ projectId: 'YOUR_WALLETCONNECT_PROJECT_ID' }), ], transports: { [mainnet.id]: http(), [base.id]: http(), [arbitrum.id]: http(), }, }); const queryClient = new QueryClient(); function App() { return ( <WagmiProvider config={config}> <QueryClientProvider client={queryClient}> {/* Your app components */} <MyCheckoutComponent /> </QueryClientProvider> </WagmiProvider> ) } ``` </Step> <Step title="Theme customization"> The widget accepts a complete Chakra UI v3 `SystemConfig` for theming. <Tip> For advanced theming, refer to the [Chakra UI theming documentation](https://v3.chakra-ui.com/docs/theming/semantic-tokens). </Tip> ```tsx theme={null} import { CheckoutModal, type WidgetTheme } from '@ensofinance/checkout-widget'; const customTheme: WidgetTheme = { theme: { semanticTokens: { colors: { // Background colors bg: { value: "#ffffff" }, "bg.subtle": { value: "#f8fafc" }, "bg.emphasized": { value: "#f1f5f9" }, // Foreground/text colors fg: { value: "#0f172a" }, "fg.muted": { value: "#64748b" }, "fg.subtle": { value: "#94a3b8" }, // Border colors border: { value: "#e2e8f0" }, "border.emphasized": { value: "#cbd5e1" }, // Primary accent color primary: { value: "#3b82f6" }, "primary.emphasis": { value: "#2563eb" }, // Status colors success: { value: "#10b981" }, warning: { value: "#f59e0b" }, error: { value: "#ef4444" }, }, }, // Custom button variants recipes: { button: { variants: { solid: { bg: "primary", color: "white", _hover: { bg: "primary.emphasis" } } } } } } }; function App() { return ( <CheckoutModal config={{ apiKey: "YOUR_API_KEY", tokenOut: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", chainIdOut: 8453, theme: customTheme }} isActive={isCheckoutActive} setIsActive={setIsCheckoutActive} /> ); } ``` </Step> </Steps> ## Configuration Props ### CheckoutConfig Properties The following checkout config exists: | Parameter | Type | Description | Required | | - | - | - | - | | `apiKey` | `string` | Your Enso API key | Yes | | `tokenOut` | `string` | Destination token address | Yes | | `chainIdOut` | `number` | Destination chain ID | Yes | | `recipient` | `string` | Recipient address for the output tokens | No | | `theme` | `WidgetTheme` | Custom Chakra UI theme config | No | ### CheckoutModalProps The `CheckoutModal` expands `CheckoutConfig` with modal-related properties and callbacks: | Parameter | Type | Description | Required | | - | - | - | - | | `config` | `CheckoutConfig` | Widget [configuration object](#checkout-config-properties) | Yes | | `isActive` | `boolean` | Controls modal visibility | Yes | | `setIsActive` | `(active: boolean) => void` | Modal state setter | Yes | | `onClose` | `() => void` | Close callback function | No | ## Supported Networks The widget supports deposits across all networks: * Ethereum (Chain ID: 1) * Base (Chain ID: 8453) * Arbitrum (Chain ID: 42161) * Optimism (Chain ID: 10) * Polygon (Chain ID: 137) * Avalanche (Chain ID: 43114) * BSC (Chain ID: 56) * And [many more](/pages/build/reference/supported-networks) ## Learn more * [Crosschain routing](/pages/build/get-started/crosschain-routing) * [Use Cases](/pages/use-cases) <div> <p>Updated </p> </div> # Cross-chain Route Widget Source: https://docs.enso.build/pages/templates/cross-chain-route-widget A React component and web app for cross-chain routing of DeFi positions and tokens. The Cross-chain Route Widget lets you add cross-chain token routing feature to your app. Under the hood, it uses the Enso API to find the best route, and bridge the tokens to the destination chain via Stargate. Highly customizable, the widget allows you to configure various parameters, including: * **Source and destination chains**: configure specific source and destination chains for the routing process. * **input and output tokens**: allow free choice or restrict to specific tokens for specialized use cases. * **The output project**: destination project for the output token for building protocol-specific flows. <CardGroup> <Card title="Cross-chain Widget" icon="play" href="https://happypath.enso.build/"> Try it out! </Card> <Card title="Cross-chain Widget" icon="github" href="https://github.com/EnsoBuild/shortcuts-widget"> Source code </Card> <Card title="Integrate" icon="hammer" href="#integrate"> Integrate cross-chain routing widget in your app </Card> </CardGroup> ## How it Works After selecting the input token on the source chain, and the output token on the destination chain, the widget will show the best route for the tokens before you sign and send the transaction. <img alt="Route Widget Flow" /> ## Integrate Follow these steps to integrate the Cross-Chain Route Widget into your React application. <Steps> <Step title="Install your project"> Install the package: ```bash theme={null} npm install @ensofinance/shortcuts-widget ``` </Step> <Step title="Import and use the component"> Import the component and use it in your app. To get your API key, visit the [Developer portal](https://developers.enso.build). <Tip> The widget must be used within a `WagmiConfig` provider. </Tip> ```tsx theme={null} import SwapWidget from '@ensofinance/shortcuts-widget'; function App() { return <SwapWidget apiKey="YOUR_API_KEY" /> } export default App; ``` </Step> <Step title="Customize the theme"> ```tsx theme={null} import SwapWidget from '@ensofinance/shortcuts-widget'; function App() { return <SwapWidget apiKey="YOUR_API_KEY" themeConfig={darkThemeConfig} /> } const darkThemeConfig = { theme: { tokens: { spacing: { 1: "10px", 2: "20px", }, }, semanticTokens: { colors: { // Background colors bg: { value: "#0f172a" }, // Dark blue-gray "bg.subtle": { value: "#1e293b" }, // Lighter blue-gray "bg.emphasized": { value: "#334155" }, // Medium blue-gray "bg.muted": { value: "#141e33" }, // Slightly lighter than base bg // Foreground colors fg: { value: "#f8fafc" }, // Almost white "fg.muted": { value: "#cbd5e1" }, // Light gray "fg.subtle": { value: "#94a3b8" }, // Medium gray // Border colors border: { value: "#334155" }, // Medium blue-gray "border.emphasized": { value: "#475569" }, // Darker blue-gray "border.subtle": { value: "#1e293b" }, // Lighter blue-gray // Primary accent colors primary: { value: "#3b82f6" }, // Vibrant blue "primary.emphasis": { value: "#2563eb" }, // Darker blue "primary.muted": { value: "#60a5fa" }, // Lighter blue // Status colors success: { value: "#10b981" }, // Green warning: { value: "#f59e0b" }, // Amber error: { value: "#ef4444" }, // Red info: { value: "#0ea5e9" }, // Sky blue }, }, }, }; export default App; ``` </Step> <Step title="Props & Configuration"> Here are the available props for the widget: | Parameter | Description | Required | | - | - | - | | `apiKey` | Your Enso API key | Yes | | `tokenIn` | The input token address (you can use to pin the input token) | No | | `tokenOut` | The output token address (you can use to pin the output token) | No | | `chainId` | The starting position's chain ID (required with token addresses) | Yes\* | | `destinationChainId` | The destination chain ID (you can use to pin the destination chain) | No | | `themeConfig` | Theme settings | No | | `enableShare` | Enable route sharing functionality copy with button | No | | `obligateSelection` | Force token selection | No | | `indicateRoute` | Show swap route path | No | | `showRoute` | Show the route | No | | `showRouteDetails` | Show route details | No | | `themeConfig` | Customize the Widget theme | No | \*Required when using token addresses </Step> </Steps> ## Next Steps From here, you can explore the API and the widget further: * [Explore the Bundle API](/api-reference/defi-shortcuts/bundle-a-list-of-actions) * [`Explore the bridge action`](/pages/build/reference/actions#bridge) <div> <p>Updated </p> </div> # Feeling Lucky Source: https://docs.enso.build/pages/templates/feeling-lucky A dApp that helps users diversify into random tokens from selected sectors using the Enso SDK. Can't decide where to ape in? Feeling lucky is here to help you out. <CardGroup> <Card href="https://github.com/EnsoBuild/shortcuts-ui-examples/tree/main/apps/feeling-lucky" title="Github" icon="github"> Source code </Card> <Card href="https://templates.enso.build/feeling-lucky" title="Feeling Lucky Live Demo" icon="play"> Try it out! </Card> </CardGroup> ## Overview Feeling Lucky is a Next.js application that enables users to "ape" into random tokens from their preferred sectors. The app leverages Enso's Router API to execute token swaps with optimal routing across multiple exchanges and protocols. ## Features * **Random Token Selection**: Discover and invest in random tokens from specific sectors * **Any-to-Any Swaps**: Use any token in your wallet to purchase the randomly selected token * **Optimal Routing**: Get the best execution price through Enso's aggregation * **Transaction Preview**: View expected output amount and price impact before execution * **Wallet Integration**: Connect easily via Privy or WalletConnect ## Technology Stack * **Frontend**: React, Next.js, Chakra UI * **Web3**: wagmi, viem, Privy * **DeFi Integration**: Enso Finance SDK * **Build Tools**: TypeScript ## Implementation Example ```tsx theme={null} import { useEnsoRouterData } from '@ensofinance/sdk-ts'; function FeelingLuckySwap({ tokenIn, randomToken }) { const { data, isLoading } = useEnsoRouterData({ fromAddress: address, chainId: 1, tokenIn: tokenIn.address, tokenOut: randomToken.address, amountIn: swapValue, slippage: 200, // 2% }); async function executeSwap() { // Using ethers/viem to send the transaction const tx = await walletClient.sendTransaction({ to: data.tx.to, data: data.tx.data, value: data.tx.value, }); await publicClient.waitForTransactionReceipt({ hash: tx }); } return ( <Button onClick={executeSwap} isLoading={isLoading} loadingText="Finding best route" > Feeling Lucky! </Button> ); } ``` ## Environment Setup Required environment variables: * `NEXT_PUBLIC_ENSO_API_KEY`: Your Enso API key * `NEXT_PUBLIC_PRIVY_KEY`: Privy authentication key ## Key Components * **TokenSelector**: Interface for selecting input tokens * **SectorSelector**: UI for choosing token categories * **TransactionPreview**: Displays swap details before execution ## Development ```bash theme={null} # Install dependencies pnpm install # Start development server pnpm dev ``` <div> <p>Updated </p> </div> # Enso DeFi Navigator Source: https://docs.enso.build/pages/templates/navigator A UI to navigate projects, protocols, and positions in the Enso ecosystem, always up-to-date with live integrations. The Enso DeFi Navigator is a helper tool to explore and interact with the Enso ecosystem. This tool is designed to make it easier to assemble and debug routes, by finding the accurate information about projets, tokens and their primary contracts. <CardGroup> <Card href="https://navigator.enso.build" title="Live app" icon="play"> Use the Enso DeFi Navigator </Card> <Card href="https://github.com/EnsoBuild/defi-navigator" title="Github" icon="github"> Source code </Card> </CardGroup> <div> <div> <img alt="Uniswap Migrator Flow" /> </div> <div> <img alt="Uniswap Migrator Flow" /> </div> </div> It provides an interface to navigate through supported projects, protocols, and positions. * **Projects**: Browse integrated networks and projects * **Protocols**: View supported projects versinons and access supported tokens * **Tokens**: Query supported tokens by address, symbol, primary address, underlying tokens and more Next steps: * [Try the Navigator](https://navigator.enso.build/) * [Learn about Enso's APIs](/pages/build/get-started/overview) * [Integrate the SDK](https://github.com/EnsoBuild/sdk-ts) <div> <p>Updated </p> </div> # Overview Source: https://docs.enso.build/pages/templates/overview Ready-to-use components and applications that leverage Enso's APIs for immediate integration into your frontend. <CardGroup> <Card title="Enso Checkout" icon="ticket" href="/pages/templates/checkout-widget"> Seamless cryptocurrency deposits with wallet and exchange integration </Card> <Card title="Crosschain Route Widget" icon="swap" href="/pages/templates/cross-chain-route-widget"> Crosschain position routing feature to your app. </Card> <Card title="Uniswap Migrator" icon="unicorn" href="/pages/templates/uniswap-migrator"> Migration of base tokens and DeFi positions from Uniswap V3 to V4 across leading chains. </Card> </CardGroup> <CardGroup> <Card title="Enso DeFi Navigator" icon="compass" href="/pages/templates/navigator"> A UI to navigate projects, protocols, and positions in the Enso ecosystem, always up-to-date with live integrations. </Card> <Card title="Yield Migrator" icon="arrow-right-arrow-left" href="/pages/templates/yield-migrator"> Helps users migrate between yield-bearing positions to optimize returns across protocols. </Card> <Card title="Feeling Lucky" icon="dice" href="/pages/templates/feeling-lucky"> Lets users "ape" into random tokens from selected sectors with optimal routing. </Card> </CardGroup> ## Why Use Enso Widgets * **Zero Integration Effort**: Drop-in components with minimal configuration * **Full DeFi Functionality**: Access to complex DeFi operations through simple UI * **Pre-built User Experiences**: Tested interfaces for common DeFi actions * **Customizable Themes**: Adapt to your application's design system ## Quick Implementation All widgets require just a few lines of code to implement: ```jsx theme={null} // Example: Route Widget implementation import SwapWidget from '@ensofinance/shortcuts-widget'; function App() { return <SwapWidget apiKey="YOUR_API_KEY" />; } ``` ## Try Before You Integrate Test any widget functionality with our live demos to see how they work before adding them to your application. ## Get Started 1. Choose a widget that fits your use case 2. Get your [Enso API key](https://developers.enso.build) 3. Install the package and add the component to your application 4. Customize appearance and behavior as needed Each widget documentation page includes detailed implementation examples and configuration options. <div> <p>Updated </p> </div> # Uniswap Migrator Source: https://docs.enso.build/pages/templates/uniswap-migrator A React component and web app that enables migration of base tokens and DeFi positions from Uniswap V3 to V4 across all supported chains. The Uniswap Migrator Widget allows users to: * migrate base tokens to any chain and * migrate Uniswap liquidity positions Uniswap V4 pools. <CardGroup> <Card href="https://migrate.enso.build/" title="Uniswap Migrator" icon="play"> Migrate positions to Uniswap V4 pools </Card> <Card href="#integrate" title="Integrate" icon="hammer"> Integrate Uniswap Migrator widget in your app </Card> </CardGroup> ## How it Works The Uniswap Migrator Widget is an interface to an orchestration of Enso's routing capacities, Stargate bridging system, and Layer0's notification system. Roughly, the flow is as follows: 1. The user selects the asset to migrate, and the destination Uniswap V4 pool. The user approves Enso's contracts to spend the asset.<br /> 2. The user initiates the migration.<br /> 2.1. The user initiates the migration.<br /> Enso issues a [transaction bundle](/pages/build/get-started/bundling-actions) that: <br /> 2.2. [Redeems](/pages/build/reference/actions#redeem) the assets underlying the user's position on Uniswap V3.<br /> 2.3. Swaps the assets to bridge tokens.<br /> 3. Bridging takes place<br /> 3.1. Enso sends the assets to Stargate.<br /> 3.2. Stargate bridges them to the destination chain.<br /> 3.3. Stargate notifies Layer0, which notifies Enso.<br /> 4. Enso issues a transaction on the destination chain that deposits the assets into the destination V4 pool. <img alt="Uniswap Migrator Flow" /> <img alt="Uniswap Migrator Flow" /> ## Integrate To integrate the Uniswap yield migrator widget, follow the steps below. <iframe title="YouTube video player" /> <Steps> <Step title="Install your project"> ```bash theme={null} pnpm i @ensofinance/uniswap-migrator ``` In case you're starting from scratch, set up a RainbowKit project: ```bash theme={null} pnpm install @rainbow-me/rainbowkit wagmi viem@2.x @tanstack/react-query ``` Then, edit `package.json` and adjust the version for `viem` to `2.x`: ```json theme={null} "viem": "2.x", ``` </Step> <Step title="Integrate the Widget Component"> Include the `WidgetWrapper` component in your `/src/pages/index.tsx` file. ```tsx src/App.tsx {6-12, 21} theme={null} import { ConnectButton } from '@rainbow-me/rainbowkit'; import type { NextPage } from 'next'; import styles from '../styles/Home.module.css'; import dynamic from 'next/dynamic'; const WidgetWrapper = dynamic( () => import("@ensofinance/uniswap-migrator").then((mod) => mod.WidgetWrapper), { ssr: false, } ); const apiKey = process.env.NEXT_PUBLIC_ENSO_API_KEY || "1e02632d-6feb-4a75-a157-documentation"; const Home: NextPage = () => { return ( <div className={styles.container}> <main className={styles.main}> <ConnectButton /> <WidgetWrapper apiKey={apiKey}/> </main> </div> ); }; export default Home; ``` </Step> <Step title="Test it out"> Now you can run your app and see the Uniswap Migrator widget in action! ```bash theme={null} pnpm run dev ``` Open your browser and navigate to `http://localhost:3000` 🎉 </Step> </Steps> ## Next Steps * [Try the Uniswap Migrator Widget](https://migrate.enso.build/) * [Learn more about Stargate](https://stargateprotoco
프로젝트로 돌아가기