Skip to content

Commit

Permalink
feat: encode unlock for Permission Proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <[email protected]>
  • Loading branch information
md0x committed Jul 19, 2024
1 parent 31d21c5 commit 69b24fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/lib/bundleUtils.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -21,15 +20,15 @@ export const createUnlockLatestValueTx = async (
baseFee: bigint,
data: string,
chainId: bigint,
ovalAddress: string,
target: string,
) => {
const nonce = await wallet.getNonce();

// Construct transaction to call unlockLatestValue on Oval Oracle from permissioned address.
const unlockTx: TransactionRequest = {
type: 2,
chainId,
to: ovalAddress,
to: target,
nonce,
value: 0,
gasLimit: 200000,
Expand Down Expand Up @@ -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 };
Expand Down
2 changes: 2 additions & 0 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type EnvironmentVariables = {
standardChainlinkFactory: string;
standardChronicleFactory: string;
standardPythFactory: string;
permissionProxyAddress: string;
defaultRefundAddress: string;
defaultRefundPercent: number;
ovalDiscoveryInterval: number;
Expand Down Expand Up @@ -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)),
};

0 comments on commit 69b24fb

Please sign in to comment.