Skip to content

Conversation

@chrismaree
Copy link
Member

  • nit
  • nit
  • nit
  • Update contracts/HubPool.sol
  • review nit
  • review nit
  • feat(hubpool): Refactor hub pool to use 1D bitmap integer
  • nit
  • WIP
  • review nit
  • review nit
  • nit
  • nit
  • nit
  • nit
  • nit
  • nit
  • WIP
  • nit
  • nit

chrismaree and others added 27 commits January 28, 2022 14:04
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Co-authored-by: Matt Rice <matthewcrice32@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Comment on lines 295 to 296
_sendTokensToTargetChain(poolRebalance, refundRequestId);
_executeRelayerRefundOnTargetChain(poolRebalance, refundRequestId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the logic of sending tokens to the chains and sending the L1->L2 calls is wrapped into these two functions :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On L2, what happens if the relayer refund method on the spoke pool is executed before tokens arrive there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'll revert as there is not enough money to pay everyone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me be sure I have the right understanding here:

  1. This will just send over a verified root that will be saved on the L2. No funds get automatically distributed.
  2. If funds haven't arrived and someone tried to distribute on the L2, their transaction will revert.

Is my understanding correct? In no situation should the L2 side of the _executeRelayerRefundOnTargetChain transaction revert, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is exactly right @mrice32

Comment on lines +292 to -277
if (refundRequest.unclaimedPoolRebalanceLeafCount == 0)
bondToken.safeTransfer(refundRequest.proposer, bondAmount);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to only pay the relayer back their bond one all bundles are executed.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
AdapterInterface adapter = crossChainContracts[poolRebalance.chainId].adapter;
adapter.relayMessage(
address(adapter),
abi.encodeWithSignature("initializeRelayerRefund(address)", refundRequest.destinationDistributionRoot)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "bytes32" not "address" right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should! fixed.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
emit FilledRelay(relayHash, relayFills[relayHash], repaymentChain, amountToSend, msg.sender, relayData);
}

function initializeRelayerRefund(bytes32 relayerRepaymentDistributionProof) public {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit to give me the required interface. @nicholaspai 's PR implements this actual logic.

@@ -0,0 +1,81 @@
import { expect } from "chai";
Copy link
Member Author

@chrismaree chrismaree Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have split the HubPool rebalance unit tests into 3 separate files: Initialization,Execution and Dispute.

await hubPool.connect(liquidityProvider).addLiquidity(dai.address, consts.amountToLp.mul(10));
});

it("Execute relayer refund correctly produces the refund bundle call and sends cross-chain repayment actions", async function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test covers the main logic added in this PR. please read through it to see how the leafs are created, tree constructed, refund initiated and finally executed.

const { defaultAbiCoder, keccak256 } = ethers.utils;
import { BigNumber, Signer, Contract } from "ethers";

export interface PoolRebalance {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these interfaces were moved to here to from test/MerkleLib.Proofs.ts.

return ethers.utils.getAddress(ethers.utils.hexlify(ethers.utils.randomBytes(20)));
}

export async function getParamType(contractName: string, functionName: string, paramName: string) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new function to return the types of a function's parameters. used when building Merkle trees.


export function randomAddress() {
return ethers.utils.hexlify(ethers.utils.randomBytes(20));
return ethers.utils.getAddress(ethers.utils.hexlify(ethers.utils.randomBytes(20)));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the .getAddress call checksum cases the address.

@@ -0,0 +1,66 @@
import { expect } from "chai";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing changed here, just moved and cut down on redundant imports/method calls.

@@ -1,91 +1,35 @@
import { expect } from "chai";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing changed here, just moved and cut down on redundant imports/method calls.

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Copy link
Contributor

@mrice32 mrice32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few commend threads that still need to be resolved, but otherwise, LGTM!

// The following arrays are required to be the same length. They are parallel arrays for the given chainId and should be ordered by the `l1Token` field.
// All whitelisted tokens with nonzero relays on this chain in this bundle in the order of whitelisting.
address[] tokenAddresses;
address[] l1Token;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
address[] l1Token;
address[] l1Tokens;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we make this change should we make all the arrays plural? netSendAmounts runningBalances?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think arrays should always be plural

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. If we didn't do so before in our structs (which could be my fault), I think we should update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will update accordingly on all variables in all places.

address indexed disputer,
SkinnyOptimisticOracleInterface.Request ooPriceRequest,
RefundRequest refundRequest
event RelayerRefundExecuted(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are any of these events indexable?

Copy link
Member Author

@chrismaree chrismaree Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. will index appropriate ones.

).deploy(weth.address, 0, parentFixtureOutput.timer.address);
await hubPool.setCrossChainContracts(repaymentChainId, mockAdapter.address, mockSpoke.address);

// Deploy mock l2 tokens for each token created before and whitelist the routes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is there any benefit to running all these async funcs in parallel? I know the test network is already super fast but we could possibly get even faster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think really. I think optimising for readability is the most important thing in fixtures IMHO.

// two token to one chain Id with simple lpFee, netSend and running balance amounts.
const wethToSend = toBNWei(100);
const daiToSend = toBNWei(1000);
const leafs = buildPoolRebalanceLeafs(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful function +1

@nicholaspai nicholaspai changed the title feat(HupPool): Add initial L1->L2 call plumbing feat(HubPool): Add initial L1->L2 call plumbing Feb 4, 2022

function executeRelayerRefund(
uint256 relayerRefundRequestId,
uint256 refundRequestId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, i think we can remove refundRequestId, rename poolRebalance to poolRebalanceLeaf and rename proof to inclusionProof

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup!

bytes32 poolRebalanceRoot,
bytes32 destinationDistributionRoot
) public onlyIfNoActiveRequest {
) public noActiveRequests {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed IRL:

  • consider adding a comment that after initiateRelayerRefund is called, if the poolRebalanceRoot, destinationDistributionRoot, poolRebalanceLeafCount, and bundleEvaluationBlockNumbers set is disputable then this can be challenged. Once the challenge period passes, then the roots are no longer disputable, and only executeRelayerRefund can be called and initiateRelayerRefund can't be called again until all leafs are executed.
  • Examples of some characteristics of these roots that could be disputed: poolRebalanceRoot.netSendAmount != destinationDistributionRoot.amountToReturn for example

Copy link
Member

@nicholaspai nicholaspai Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Motivation is updated comments + interface for the spoke pool distributeRelayerRefund in my PR: 8fb750a

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!

Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
Signed-off-by: chrismaree <christopher.maree@gmail.com>
@chrismaree chrismaree merged commit 4b998f9 into master Feb 4, 2022
@chrismaree chrismaree deleted the chrismaree/fourth-pass-repayment-claim branch February 4, 2022 20:07
pxrl pushed a commit that referenced this pull request Feb 13, 2024
pxrl added a commit that referenced this pull request Feb 13, 2024
Original fix from Nick.

Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
pxrl pushed a commit that referenced this pull request Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants