Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: manual rebalancer support #1252

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,11 @@ export const vercelApiBaseUrl =
export const defaultSwapSlippage = Number(
process.env.REACT_APP_DEFAULT_SWAP_SLIPPAGE || 0.5
);

// List of addresses that have special manual rebalancing rights in the FE
export const manualRebalancerAddresses = String(
process.env.REACT_APP_MANUAL_REBALANCER_ADDRESSES ||
"0x1d933Fd71FF07E69f066d50B39a7C34EB3b69F05"
)
.split(",")
.map(ethers.utils.getAddress);
31 changes: 29 additions & 2 deletions src/views/Bridge/hooks/useBridgeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
TransferQuoteReceivedProperties,
ampli,
} from "ampli";
import { BigNumber, constants, providers } from "ethers";
import { BigNumber, constants, providers, utils } from "ethers";
import {
useConnection,
useApprove,
Expand All @@ -23,6 +23,8 @@ import {
sendSpokePoolVerifierDepositTx,
sendDepositV3Tx,
sendSwapAndBridgeTx,
manualRebalancerAddresses,
ChainId,
} from "utils";
import { TransferQuote } from "./useTransferQuote";
import { SelectedRoute } from "../utils";
Expand Down Expand Up @@ -153,7 +155,32 @@ export function useBridgeAction(

let tx: providers.TransactionResponse;

if (isSwapRoute) {
// If the connected wallet is configured as a manual rebalancer and the origin
// chain is mainnet, we force the deposit to be unprofitable with a long
// exclusivity. The idea is to have these deposits paid out as a slow fill, in
// which case the SpokePool's own balance will be used to complete the fill, and
// the HubPool will pull funds back from the mainnet SpokePool instead. This
// allows us to skip the 7 day bridges and ensure a safe level of HubPool liquidity
if (
manualRebalancerAddresses.includes(utils.getAddress(frozenAccount)) &&
frozenRoute.fromChain === ChainId.MAINNET
) {
const { spokePool } = await getSpokePoolAndVerifier(frozenRoute);
tx = await sendDepositV3Tx(
signer,
{
...frozenDepositArgs,
inputTokenAddress: frozenRoute.fromTokenAddress,
outputTokenAddress: frozenRoute.toTokenAddress,
// Force overrides to make deposit unattractive for relayers
relayerFeePct: BigNumber.from(0),
exclusiveRelayer: frozenAccount,
exclusivityDeadline: 30 * 60, // 30 minutes
pxrl marked this conversation as resolved.
Show resolved Hide resolved
},
spokePool,
networkMismatchHandler
);
} else if (isSwapRoute) {
tx = await sendSwapAndBridgeTx(
signer,
{
Expand Down
Loading