diff --git a/packages/op-request-plugins/src/UniswapV3Plugin.ts b/packages/op-request-plugins/src/UniswapV3Plugin.ts index 751c77d987..e0aa9fa1e2 100644 --- a/packages/op-request-plugins/src/UniswapV3Plugin.ts +++ b/packages/op-request-plugins/src/UniswapV3Plugin.ts @@ -19,7 +19,7 @@ import { import { ethers } from "ethers"; import ERC20_ABI from "./abis/ERC20.json"; -const SWAP_ROUTER_ADDRESS = "0xE592427A0AEce92De3Edee1F18E0157C05861564"; +const UniswapV3_NAME = "uniswapV3"; export interface UniswapV3PluginMethods { getSwapRouter(): AlphaRouter; @@ -71,6 +71,14 @@ export function UniswapV3Plugin( const prom = new Promise( async (resolve, reject) => { try { + const swapRouterAddress = + this.config.protocolAllowlist.get(UniswapV3_NAME)?.address; + if (!swapRouterAddress) { + throw new Error( + `UniswapV3 not supported on chain with id: ${this._op.chainId}` + ); + } + const router = this.getSwapRouter(); const handlerAddress = this.config.handlerAddress(); @@ -128,7 +136,7 @@ export function UniswapV3Plugin( }; const swapAction: Action = { - contractAddress: SWAP_ROUTER_ADDRESS, + contractAddress: swapRouterAddress, encodedFunction: route.methodParameters!.calldata, }; @@ -145,15 +153,14 @@ export function UniswapV3Plugin( // If router contract doesn't have high enough allowance, set to max for handler -> // router. Anyone can set allowance on handler so might as well set to max. if ( - ( - await erc20InContract.allowance(SWAP_ROUTER_ADDRESS) - ).toBigInt() < inAmount + (await erc20InContract.allowance(swapRouterAddress)).toBigInt() < + inAmount ) { const approveAction: Action = { contractAddress: tokenIn, encodedFunction: erc20InContract.interface.encodeFunctionData( "approve", - [SWAP_ROUTER_ADDRESS, ethers.constants.MaxUint256] + [swapRouterAddress, ethers.constants.MaxUint256] ), }; diff --git a/packages/op-request-plugins/src/WstethAdapterPlugin.ts b/packages/op-request-plugins/src/WstethAdapterPlugin.ts index 35dfd2a2a8..c97359082e 100644 --- a/packages/op-request-plugins/src/WstethAdapterPlugin.ts +++ b/packages/op-request-plugins/src/WstethAdapterPlugin.ts @@ -1,6 +1,5 @@ import { Action, - Address, Asset, AssetTrait, BaseOpRequestBuilder, @@ -12,6 +11,8 @@ import { } from "@nocturne-xyz/core"; import { WstethAdapter__factory } from "@nocturne-xyz/contracts"; +const WSTETH_ADAPTER_NAME = "wstethAdapter"; + export interface WstethAdapterPluginMethods { // adds an ERC20 transfer to the operation // handles encoding, unwrapping, and metadata @@ -38,18 +39,28 @@ export function WstethAdapterPlugin( use: use, convertWethToWsteth(amount: bigint) { const prom = new Promise((resolve) => { - const chainId = this._op.chainId; - - let wethAddress: Address; - let wstethAdapterAddress: Address; - let wstethAddress: Address; - if (chainId === 1n) { - // mainnet - wethAddress = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; - wstethAdapterAddress = "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"; // TODO: fill with real address - wstethAddress = "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"; - } else { - throw new Error(`wsteth not supported on chain with id: ${chainId}`); + const wstethAdapterAddress = + this.config.protocolAllowlist.get(WSTETH_ADAPTER_NAME)?.address; + if (!wstethAdapterAddress) { + throw new Error( + `WstethAdapter not supported on chain with id: ${this._op.chainId}` + ); + } + + const wethAddress = + this.config.erc20s.get(WSTETH_ADAPTER_NAME)?.address; + if (!wethAddress) { + throw new Error( + `Weth not supported on chain with id: ${this._op.chainId}` + ); + } + + const wstethAddress = + this.config.erc20s.get(WSTETH_ADAPTER_NAME)?.address; + if (!wstethAddress) { + throw new Error( + `Wsteth not supported on chain with id: ${this._op.chainId}` + ); } const encodedWeth = AssetTrait.erc20AddressToAsset(wethAddress);