Skip to content

Commit

Permalink
improve: Add test util for requesting refunds (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Jul 6, 2023
1 parent a963dd0 commit 26e18ee
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion test/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { constants as ethersConstants } from "ethers";
import * as utils from "@across-protocol/contracts-v2/dist/test-utils";
import { TokenRolesEnum } from "@uma/common";
export { MAX_SAFE_ALLOWANCE, MAX_UINT_VAL } from "@uma/common";
Expand All @@ -12,7 +13,7 @@ import { MAX_L1_TOKENS_PER_POOL_REBALANCE_LEAF, MAX_REFUNDS_PER_RELAYER_REFUND_L
import { HubPoolClient, ConfigStoreClient, GLOBAL_CONFIG_STORE_KEYS } from "../../src/clients";
import { SpokePoolClient } from "../../src/clients";
import { deposit, Contract, SignerWithAddress, BigNumber } from "./index";
import { Deposit, Fill, RunningBalances } from "../../src/interfaces";
import { Deposit, Fill, FillWithBlock, RefundRequest, RunningBalances } from "../../src/interfaces";
import { buildRelayerRefundTree, toBN, toBNWei, utf8ToHex } from "../../src/utils";
import { providers } from "ethers";

Expand Down Expand Up @@ -632,6 +633,44 @@ export async function buildFillForRepaymentChain(
}
}

export async function buildRefundRequest(
spokePool: Contract,
relayer: SignerWithAddress,
fill: FillWithBlock,
refundToken: string,
maxCount?: BigNumber
): Promise<RefundRequest> {
// @note: These chainIds should align, but don't! @todo: Fix!
// const chainId = (await spokePool.provider.getNetwork()).chainId;
// assert.isTrue(fill.repaymentChainId === chainId);

const {
originChainId,
depositId,
destinationChainId,
fillAmount: amount,
realizedLpFeePct,
blockNumber: fillBlock,
} = fill;

maxCount ??= ethersConstants.MaxUint256;

const refundRequest = await spokePool
.connect(relayer)
.requestRefund(
refundToken,
amount,
originChainId,
destinationChainId,
realizedLpFeePct,
depositId,
fillBlock,
maxCount
);

return refundRequest;
}

// Returns expected leaves ordered by origin chain ID and then deposit ID(ascending). Ordering is implemented
// same way that dataworker orders them.
export function buildSlowRelayLeaves(deposits: Deposit[]) {
Expand Down

0 comments on commit 26e18ee

Please sign in to comment.