diff --git a/src/lib/bundleUtils.ts b/src/lib/bundleUtils.ts index 35a3a27..0d00eb7 100644 --- a/src/lib/bundleUtils.ts +++ b/src/lib/bundleUtils.ts @@ -1,18 +1,17 @@ import { Interface, Transaction, TransactionRequest, Wallet } from "ethers"; import express from "express"; import { FlashbotsBundleProvider } from "flashbots-ethers-v6-provider-bundle"; -import { getBaseFee, getMaxBlockByChainId, getOvalAddresses, getOvalRefundConfig, getProvider } from "./helpers"; +import { getBaseFee, getMaxBlockByChainId, getOvalAddresses, getOvalRefundConfig, getProvider, isOvalSharedUnlockerKey } from "./helpers"; import { WalletManager } from "./walletManager"; import MevShareClient, { BundleParams } from "@flashbots/mev-share-client"; import { JSONRPCID, createJSONRPCSuccessResponse } from "json-rpc-2.0"; import { ovalAbi } from "../abi"; -import { OvalDiscovery } from "./"; import { env } from "./env"; import { Logger } from "./logging"; import { Refund } from "./types"; -const { ovalConfigs } = env; +import { PermissionProxy__factory } from "../contract-types"; export const ovalInterface = Interface.from(ovalAbi); @@ -21,7 +20,7 @@ export const createUnlockLatestValueTx = async ( baseFee: bigint, data: string, chainId: bigint, - ovalAddress: string, + target: string, ) => { const nonce = await wallet.getNonce(); @@ -29,7 +28,7 @@ export const createUnlockLatestValueTx = async ( const unlockTx: TransactionRequest = { type: 2, chainId, - to: ovalAddress, + to: target, nonce, value: 0, gasLimit: 200000, @@ -57,15 +56,24 @@ export const prepareUnlockTransaction = async ( simulate = true, ) => { const provider = getProvider(); - const unlockerWallet = WalletManager.getInstance().getWallet(ovalAddress, targetBlock, req.transactionId); const [baseFee, network] = await Promise.all([getBaseFee(provider, req), provider.getNetwork()]); - const data = ovalInterface.encodeFunctionData("unlockLatestValue"); + const unlockerWallet = WalletManager.getInstance().getWallet(ovalAddress, targetBlock, req.transactionId); + const isSharedWallet = isOvalSharedUnlockerKey(unlockerWallet.address); + + // Encode the unlockLatestValue function call depending on whether the unlocker is a shared wallet or not. + let data = ovalInterface.encodeFunctionData("unlockLatestValue"); + let target = ovalAddress; + if (isSharedWallet) { + target = env.permissionProxyAddress; + data = PermissionProxy__factory.createInterface().encodeFunctionData("execute", [target, data]); + } + const { unlockTxHash, signedUnlockTx } = await createUnlockLatestValueTx( unlockerWallet, baseFee, data, network.chainId, - ovalAddress, + target, ); if (!simulate) return { ovalAddress, unlockTxHash, signedUnlockTx }; diff --git a/src/lib/env.ts b/src/lib/env.ts index b90b396..9ac851c 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -54,6 +54,7 @@ type EnvironmentVariables = { standardChainlinkFactory: string; standardChronicleFactory: string; standardPythFactory: string; + permissionProxyAddress: string; defaultRefundAddress: string; defaultRefundPercent: number; ovalDiscoveryInterval: number; @@ -85,6 +86,7 @@ export const env: EnvironmentVariables = { standardChainlinkFactory: getAddress(getEnvVar("STANDARD_CHAINLINK_FACTORY", "0x6d0cbebdeBc5060E6264fcC497d5A277B5748Cf9")), standardChronicleFactory: getAddress(getEnvVar("STANDARD_CHRONICLE_FACTORY", "0xE0225B5224512868814D9b10A14F705d99Ba0EdF")), standardPythFactory: getAddress(getEnvVar("STANDARD_PYTH_FACTORY", "0x53A2a7C0cBb76B20782C6842A25876C5377B64e8")), + permissionProxyAddress: getAddress(getEnvVar("PERMISSION_PROXY_ADDRESS", "0xb9b7584ea2f605182f73b8c63f116cb3f17086b5")), defaultRefundAddress: getAddress(getEnvVar("DEFAULT_REFUND_ADDRESS", "0x9Cc5b1bc0E1970D44B5Adc7ba51d76a5DD375434")), defaultRefundPercent: getFloat(getEnvVar("DEFAULT_REFUND_PERCENT", fallback.refundPercent)), }; \ No newline at end of file