Optimism 백서

Optimism

원문

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

ng side. </Step> <Step title="The unlock message is executed"> Once the unlock message is sent, it must be relayed to the receiving side. Message relaying is automatic when sending from Ethereum to OP Mainnet but requires additional user transactions when sending from OP Mainnet to Ethereum. Read more about the message relaying process in the guide to [Sending Data Between L1 and L2](./messaging#communication-speed). When the message is relayed, the `finalizeBridgeERC20` function will be triggered on the receiving Standard Bridge contract. This function will receive the `_minGasLimit` gas defined by the user to execute to completion. </Step> <Step title="The unlock message is authenticated"> Upon execution, `finalizeBridgeERC20` verifies a number of things about the incoming request: * [The request must have originated from the Standard Bridge contract on the other blockchain](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/StandardBridge.sol#L281). * [The Standard Bridge must not be in an emergency paused state](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/StandardBridge.sol#L283). </Step> <Step title="The native token is unlocked"> If the unlock message is fully verified, `finalizeBridgeERC20` will [unlock and transfer tokens to the recipient](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/StandardBridge.sol#L292-L293) equal to the number of tokens originally burned on the other blockchain. This completes the process of bridging native tokens. This process is identical in both the Ethereum to OP Mainnet and OP Mainnet to Ethereum directions. </Step> </Steps> ### Bridging ETH The Standard Bridge contracts can also be used to bridge ETH from Ethereum to OP Mainnet and vice versa. The ETH bridging process is generally less complex than the ERC-20 bridging process. Users simply need to trigger and send ETH to the [`bridgeETH`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/StandardBridge.sol#L166-L168) or [`bridgeETHTo`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/StandardBridge.sol#L182-L184) functions on either blockchain. <Info> Users can also deposit ETH from Ethereum to OP Mainnet by sending a basic ETH transfer from an EOA to the `L1StandardBridgeProxy`. This works because the `L1StandardBridgeProxy` contains a [`receive`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L1/L1StandardBridge.sol#L134-L136) function. You can find the mainnet and testnet addresses on the [Contract Addresses](/op-mainnet/network-information/op-addresses) page. </Info> ## Tutorials * [Learn how to bridge ERC-20 tokens with viem](/app-developers/tutorials/bridging/cross-dom-bridge-erc20) * [Learn how to create a standard or custom bridged token](/app-developers/tutorials/bridging/standard-bridge-standard-token) * [Learn how to submit transactions from L1](/app-developers/tutorials/bridging/cross-dom-bridge-eth) ## Superchain Token List The [Superchain Token List](/app-developers/reference/tokens/tokenlist) exists to help users discover the right bridged token addresses for any given native token. Because a native token may have more than one bridged representation, and different bridged representations are entirely independent tokens, using the wrong one can lock up your native tokens permanently. Follow the guide on [verifying bridged token addresses](/app-developers/guides/bridging/verify-bridged-tokens) to confirm that you're using the correct bridged representation of a token before bridging. Developers who are creating their own bridged tokens should consider [adding their token](https://github.com/ethereum-optimism/ethereum-optimism.github.io#adding-a-token-to-the-list) to the Superchain Token List. Tokens on the Superchain Token List will automatically appear on certain tools like the [Superchain Bridges UI](https://app.optimism.io/bridge?utm_source=op-docs\&utm_medium=docs). # Verifying bridged token addresses Source: https://docs.optimism.io/app-developers/guides/bridging/verify-bridged-tokens Use the Superchain Token List to find and verify the correct bridged representation of a token before using the Standard Bridge. A native token may have more than one bridged representation on the other chain, and different bridged representations of the same native token are entirely independent tokens. Bridging to the wrong representation can lock up your native tokens permanently. This guide shows you how to use the [Superchain Token List](https://github.com/ethereum-optimism/ethereum-optimism.github.io) to find and verify the correct bridged token address before you bridge a token with the [Standard Bridge](/app-developers/guides/bridging/standard-bridge). ## Find the bridged representation of a token for OP Mainnet You can easily find the bridged representation of a token for OP Mainnet on the [Bridged token addresses](/app-developers/reference/tokens/tokenlist) page. That page is generated automatically from the Superchain Token List. ## Find the bridged representation of a token for another chain If you want to find the bridged representation of a token for another chain, use the following steps. <Steps> <Step title="Find the token you want to bridge"> The Superchain Token List is organized by the token's address and native blockchain. [Search the token list](https://github.com/ethereum-optimism/ethereum-optimism.github.io/blob/master/optimism.tokenlist.json) for the token you want to bridge to confirm that it's included in the list. Make sure that the chain ID in the entry matches the chain ID of the blockchain you're bridging from. Retrieve the token's name and symbol from the list. </Step> <Step title="Find the bridged representation of the token"> Once you've found the token you want to bridge, look for the token's name and symbol in the list. Find the entry that matches the name and symbol of the token you want to bridge and where the chain ID matches the chain ID of the blockchain you're bridging to. The address of this entry is the address of the bridged representation of the token you want to bridge. </Step> <Step title="Find the bridge contract address used by the token pair"> Identify the cross-chain bridge contract address used by the token pair. You can observe that some token pairs in the list utilize **custom bridge contracts** instead of the default Standard Bridge. Verify the bridge contract specified in the token list entry to ensure you are interacting with the correct bridge implementation for that token. </Step> </Steps> ## Add a token to the Superchain Token List Developers who are creating their own bridged tokens should consider [adding their token](https://github.com/ethereum-optimism/ethereum-optimism.github.io#adding-a-token-to-the-list) to the Superchain Token List. Tokens on the Superchain Token List will automatically appear on certain tools like the [Superchain Bridges UI](https://app.optimism.io/bridge?utm_source=op-docs\&utm_medium=docs). ## Next steps * Learn how the [Standard Bridge](/app-developers/guides/bridging/standard-bridge) moves tokens between Ethereum and OP Mainnet. * Follow the tutorial to [bridge ERC-20 tokens with viem](/app-developers/tutorials/bridging/cross-dom-bridge-erc20). # Building apps on OP Stack chains Source: https://docs.optimism.io/app-developers/guides/building-apps Learn the basics of building apps on OP Stack chains. This guide explains the basics of OP Stack development. OP Stack chains are [EVM equivalent](https://web.archive.org/web/20231127160757/https://medium.com/ethereum-optimism/introducing-evm-equivalence-5c2021deb306), meaning they run a slightly modified version of the same `geth` you run on mainnet. Therefore, the differences between OP Stack development and Ethereum development are minor. But a few differences [do exist](/op-stack/protocol/differences). ## OP Stack chains endpoint URLs To access any Ethereum type network you need an endpoint. [These providers](/app-developers/reference/rpc-providers) support our networks. ### Network choice For development purposes we recommend you use either a local development network or [OP Sepolia](https://sepolia-optimism.etherscan.io). That way you don't need to spend real money. If you need ETH on OP Sepolia for testing purposes, [you can use this faucet](https://console.optimism.io/faucet?utm_source=op-docs\&utm_medium=docs). ## Interacting with contracts on OP Stack chains We have Hardhat's Greeter contract on OP Sepolia at address [0x9d334aFBa83865E67a9219830ADA57aaA9406681](https://testnet-explorer.optimism.io/address/0x9d334aFBa83865E67a9219830ADA57aaA9406681#code). You can verify your development stack configuration by interacting with it. ## Development stacks As you can see in the different development stacks below, the way you deploy contracts and interact with them on OP Stack chains is almost identical to the way you do it with L1 Ethereum. The most visible difference is that you have to specify a different endpoint (of course). For more detail, see the guide on [Differences between Ethereum and OP Stack Chains](/op-stack/protocol/differences). * [Foundry](https://getfoundry.sh/) * [Hardhat](https://hardhat.org/) * [Apeworx](https://www.apeworx.io/) * [Brownie](https://eth-brownie.readthedocs.io/en/stable/install.html) * [Remix](https://remix.ethereum.org) * [Waffle](https://getwaffle.io/) ## Best practices ### Use provided EVM It is best to start development with the EVM provided by the development stack. Not only is it faster, but such EVMs often have extra features, such as the [ability to log messages from Solidity](https://hardhat.org/tutorial/debugging-with-hardhat-network.html) or a [graphical user interface](https://trufflesuite.com/ganache/). ### Debug before deploying After you are done with that development, debug your decentralized application locally and then on a [Sepolia test network](/op-mainnet/network-information/connecting-to-op). This lets you debug parts that are OP Stack chains specific such as calls to bridges to transfer ETH or tokens between layers. Only when you have a version that works well on a test network should you deploy to the production network, where every transaction has a cost. <Info> **Running your app in production** A production application depends on infrastructure your team does not run: RPC endpoints that hold up under real traffic (the public endpoints are rate-limited and not built for production), bridges your users rely on, and a chain whose operator keeps sequencing, upgrades, and incident response going around the clock. These docs cover building and testing. If your application is growing toward dedicated blockspace of its own, [OP Enterprise](https://optimism.io/op-enterprise?utm_source=docs\&utm_medium=docs\&utm_campaign=op-enterprise) offers managed and supported paths to running a chain. These docs stay the reference for what you build either way. OP Enterprise is Optimism's managed offering. </Info> ### Contract source verification You don't have to upload your source code to [block explorers](/app-developers/tools/infrastructure/block-explorers), but it is a good idea. On the test network, it lets you issue queries and transactions from the explorer's user interface. On the production network, it lets users know exactly what your contract does, which is conducive to trust. Just remember, if you use [the Etherscan API](https://explorer.optimism.io/apis?utm_source=op-docs\&utm_medium=docs), you need one API key for OP Stack chains and a separate one for OP Sepolia. # Configuring Actions SDK Source: https://docs.optimism.io/app-developers/guides/configuring-actions Learn how to configure Actions SDK for your application. Actions SDK lets you choose which assets, markets, chains, protocols, and providers you want to support in your application via configuration file. <Steps> <Step title="Install Actions SDK"> Follow the [quickstart](/app-developers/quickstarts/actions) guide to add Actions SDK as a dependency in your app. </Step> <Step title="Integrate an embedded wallet"> Follow the [connecting a wallet to Actions SDK](/app-developers/guides/connect-wallet-to-actions) guide, choose and install a Wallet Provider. </Step> <Step title="Create a config file"> `actions.ts` - An accessible file that holds all of your configuration preference. </Step> <Step title="Configure a Wallet Provider"> Let Actions SDK know which Wallet Provider you've chosen: <Tabs> <Tab title="Frontend"> Select a wallet provider: <Tabs> <Tab title="Privy"> ```typescript title="actions.ts" theme={null} const walletConfig = { hostedWalletConfig: { provider: { type: "privy" as const, }, }, smartWalletConfig: { provider: { type: "default" as const, attributionSuffix: "actions", }, }, }; ``` </Tab> <Tab title="Turnkey"> ```typescript title="actions.ts" theme={null} const walletConfig = { hostedWalletConfig: { provider: { type: "turnkey" as const, }, }, smartWalletConfig: { provider: { type: "default" as const, attributionSuffix: "actions", }, }, }; ``` </Tab> <Tab title="Dynamic"> ```typescript title="actions.ts" theme={null} const walletConfig = { hostedWalletConfig: { provider: { type: "dynamic" as const, }, }, smartWalletConfig: { provider: { type: "default" as const, attributionSuffix: "actions", }, }, }; ``` </Tab> </Tabs> </Tab> <Tab title="Backend"> Select a wallet provider: <Tabs> <Tab title="Privy"> ```typescript title="actions.ts" theme={null} import { PrivyClient } from '@privy-io/node' const privyClient = new PrivyClient( process.env.PRIVY_APP_ID, process.env.PRIVY_APP_SECRET, ) const walletConfig = { hostedWalletConfig: { provider: { type: "privy" as const, config: { privyClient, }, }, }, smartWalletConfig: { provider: { type: "default" as const, attributionSuffix: "actions", }, }, }; ``` </Tab> <Tab title="Turnkey"> ```typescript title="actions.ts" theme={null} import { Turnkey } from '@turnkey/sdk-server' const turnkeyClient = new Turnkey({ apiBaseUrl: 'https://api.turnkey.com', apiPublicKey: process.env.TURNKEY_API_KEY, apiPrivateKey: process.env.TURNKEY_API_SECRET, defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID, }) const walletConfig = { hostedWalletConfig: { provider: { type: "turnkey" as const, config: { client: turnkeyClient.apiClient(), }, }, }, smartWalletConfig: { provider: { type: "default" as const, attributionSuffix: "actions", }, }, }; ``` </Tab> </Tabs> </Tab> </Tabs> </Step> <Step title="Configure supported assets"> Configure which assets you want to support across all lend providers: ```typescript title="actions.ts" theme={null} // Additional config from previous steps... // Import popular assets import { USDC } from '@eth-optimism/actions-sdk/assets' import type { Asset, AssetsConfig } from "@eth-optimism/actions-sdk"; // Or define custom assets export const CustomToken: Asset = { address: { [mainnet.id]: '0x123...', [unichain.id]: '0x456...', [baseSepolia.id]: '0x789...', }, metadata: { decimals: 6, name: 'Custom Token', symbol: 'CUSTOM', }, type: 'erc20', } // Configure allowed/blocked assets const assetsConfig: AssetsConfig = { allow: [USDC, CustomToken], block: [], // Optional } ``` </Step> <Step title="Configure Markets"> Define which markets you want to support or block within your app: ```typescript title="actions.ts" theme={null} // Additional config from previous steps... export const GauntletUSDC: LendMarketConfig = { address: '0xabc...', chainId: unichain.id, name: 'Gauntlet USDC', asset: USDC, lendProvider: 'morpho', } ``` </Step> <Step title="Configure Lend Providers"> Configure which lend protocols you want to support. You can enable one or multiple providers: ```typescript title="actions.ts" theme={null} // Additional config from previous steps... import type { LendConfig } from "@eth-optimism/actions-sdk"; const lendConfig: LendConfig = { morpho: { marketAllowlist: [GauntletUSDC], marketBlocklist: [], // Optional }, aave: { marketAllowlist: [AaveWETH], marketBlocklist: [], // Optional }, }; ``` </Step> <Step title="Configure supported chains"> Configure supported chains: ```typescript title="actions.ts" theme={null} // Additional config from previous steps... import { optimism, base } from "viem/chains"; // Define any EVM chain const OPTIMISM = { chainId: optimism.id, rpcUrls: env.OPTIMISM_RPC_URL, bundler: { // Bundle and sponsor txs with a gas paymaster type: "simple" as const, url: env.OPTIMISM_BUNDLER_URL, }, }; const BASE = { chainId: base.id, rpcUrls: env.BASE_RPC_URL, bundler: { // Bundle and sponsor txs with a gas paymaster type: "simple" as const, url: env.BASE_BUNDLER_URL, }, }; const chains = [OPTIMISM, BASE]; ``` </Step> <Step title="Initialize Actions"> Finally bring it all together and initialize Actions: ```typescript title="actions.ts" theme={null} // Additional config from previous steps... export const actions = createActions({ wallet: walletConfig, assets: assetsConfig, lend: lendConfig, chains, }); ``` </Step> <Step title="Take Action"> Once you've initialized your actions instance, import it anywhere you need to take action: ```typescript theme={null} import { actions } from './actions'; // Use actions anywhere in your app const market = await actions.lend.getMarket({ ... }); const wallet = await actions.wallet.createSmartWallet({ ... }); const receipt = await wallet.lend.openPosition({ ... }); ``` </Step> </Steps> ## Next Steps For detailed API documentation and type definitions, see the [Actions SDK Reference](/app-developers/reference/actions/integrating-wallets). # Connecting a wallet to Actions SDK Source: https://docs.optimism.io/app-developers/guides/connect-wallet-to-actions Connect an embedded provider wallet to Actions SDK so it can perform DeFi actions like Lend, Borrow, Swap, and Pay. Actions SDK works with wallets from popular embedded wallet providers, regardless of where and how transactions are signed. This guide shows you how to connect a provider wallet to Actions so it can call Actions functions. For help deciding which wallet schema fits your use case, see [Integrating wallets](/app-developers/reference/actions/integrating-wallets). ## Connect your wallet <Steps> <Step title="Choose a wallet provider"> Follow embedded wallet provider documentation and installation steps. Actions works with Typescript clients, both frontend React and backend Node. </Step> <Step title="Import Actions SDK"> Import [Actions SDK](https://actions.money/) alongside your chosen wallet provider SDK. The [quickstart](/app-developers/quickstarts/actions#installation) covers installing Actions SDK in your project. </Step> <Step title="Create and fetch embedded user wallets"> Follow embedded wallet provider documentation for wallet creation and access. </Step> <Step title="Pass the wallet to Actions"> Call `actions.wallet.toActionsWallet(...)`, and [pass in](/app-developers/quickstarts/actions#choose-a-wallet-provider) the provider wallet. The quickstart includes provider-specific code examples for both frontend and backend clients. </Step> <Step title="Take Action"> The returned [Wallet](/app-developers/reference/actions/wallet-definitions) is now capable of calling Actions [functions](/app-developers/quickstarts/actions#take-action) like Lend, Borrow, Swap and Pay! </Step> </Steps> ## Next steps * Follow the [Configuring Actions](/app-developers/guides/configuring-actions) guide to define which protocols
프로젝트로 돌아가기