Skip to content

Commit

Permalink
feat(walletManager): manually record wallet usage find unlock
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
  • Loading branch information
md0x committed Sep 18, 2024
1 parent 5f05e0c commit 91bc55f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ app.post("/", async (req, res, next) => {
await handleUnsupportedRequest(req, res, "No valid unlock found"); // Pass through if no unlock is found.
return;
}

// FindUnlock does not update wallet usage, so we need to do it manually.
WalletManager.getInstance().updateWalletUsage(unlock.ovalAddress, unlock.unlockerWallet, targetBlock);

// Dynamically adjust refund percent so that builder nets at least configured minimum. We don't need to consider
// refund gas costs as the builder is deducting them from refund and should not include the bundle if refund gas
// costs exceed refund value.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/bundleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export const prepareUnlockTransaction = async (
target,
);

if (!simulate) return { ovalAddress, unlockTxHash, signedUnlockTx };
if (!simulate) return { ovalAddress, unlockTxHash, signedUnlockTx, unlockerWallet };

const simulationResponse = await flashbotsBundleProvider.simulate([signedUnlockTx, ...backrunTxs], targetBlock);

return { ovalAddress, unlockTxHash, signedUnlockTx, simulationResponse };
return { ovalAddress, unlockTxHash, signedUnlockTx, simulationResponse, unlockerWallet };
};

export const getUnlockBundlesFromOvalAddresses = async (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/walletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class WalletManager {
}

// Update the usage statistics for a wallet
private async updateWalletUsage(ovalInstance: string, wallet: Wallet, targetBlock: number): Promise<void> {
public async updateWalletUsage(ovalInstance: string, wallet: Wallet, targetBlock: number): Promise<void> {
const walletPubKey = await wallet.getAddress();
const instanceUsage = this.sharedWalletUsage.get(walletPubKey) || new Map();
const existingRecord = instanceUsage.get(targetBlock);
Expand Down

0 comments on commit 91bc55f

Please sign in to comment.