Skip to content

Commit

Permalink
Add view function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Sep 25, 2024
1 parent 60589f1 commit 751ddf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion contracts/SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ abstract contract SpokePool is
// this is unlikely and we choose to not check it and incur the extra gas cost:
// e.g. if (msg.sender == address(0)) revert InvalidUnsafeDepositor();

uint256 depositId = uint256(bytes32(abi.encodePacked(msg.sender, depositNonce)));
uint256 depositId = getUnsafeDepositId(msg.sender, depositNonce);
_depositV3(
depositor,
recipient,
Expand Down Expand Up @@ -1107,6 +1107,17 @@ abstract contract SpokePool is
return block.timestamp; // solhint-disable-line not-rely-on-time
}

/**
* @notice Returns the deposit ID for an unsafe deposit. This function is used to compute the deposit ID
* in unsafeDepositV3 and is provided as a convenience.
* @param depositor The address used as input to produce the deposit ID.
* @param depositNonce The nonce used as input to produce the deposit ID.
* @return The deposit ID for the unsafe deposit.
*/
function getUnsafeDepositId(address depositor, uint96 depositNonce) public pure returns (uint256) {
return uint256(bytes32(abi.encodePacked(depositor, depositNonce)));
}

/**************************************
* INTERNAL FUNCTIONS *
**************************************/
Expand Down
1 change: 1 addition & 0 deletions test/evm/hardhat/SpokePool.Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ describe("SpokePool Depositor Logic", async function () {
// new deposit ID should be the uint256 equivalent of the keccak256 hash of packed {address, forcedDepositId}.
const forcedDepositId = "99";
const expectedDepositId = ethers.utils.solidityPack(["address", "uint96"], [depositor.address, forcedDepositId]);
expect(await spokePool.getUnsafeDepositId(depositor.address, forcedDepositId)).to.equal(expectedDepositId);
await expect(
spokePool
.connect(depositor)
Expand Down

0 comments on commit 751ddf8

Please sign in to comment.