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

Removes use of User Registry in Preconfirmations flow #64

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
42 changes: 15 additions & 27 deletions contracts/PreConfirmations.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: BSL 1.1
pragma solidity ^0.8.15;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {IProviderRegistry} from "./interfaces/IProviderRegistry.sol";
import {IUserRegistry} from "./interfaces/IUserRegistry.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

/**
Expand Down Expand Up @@ -43,8 +44,8 @@ contract PreConfCommitmentStore is Ownable {
/// @dev Address of provider registry
IProviderRegistry public providerRegistry;

/// @dev Address of userRegistry
IUserRegistry public userRegistry;

IERC20 public nativeToken;

/// @dev Mapping from provider to commitments count
mapping(address => uint256) public commitmentsCount;
Expand Down Expand Up @@ -106,19 +107,18 @@ contract PreConfCommitmentStore is Ownable {
/**
* @dev Initializes the contract with the specified registry addresses, oracle, name, and version.
* @param _providerRegistry The address of the provider registry.
* @param _userRegistry The address of the user registry.
* @param _oracle The address of the oracle.
* @param _owner Owner of the contract, explicitly needed since contract is deployed w/ create2 factory.
*/
constructor(
address _providerRegistry,
address _userRegistry,
address _oracle,
address _owner
address _owner,
address _nativeToken
) {
oracle = _oracle;
providerRegistry = IProviderRegistry(_providerRegistry);
userRegistry = IUserRegistry(_userRegistry);
nativeToken = IERC20(_nativeToken);
_transferOwnership(_owner);

// EIP-712 domain separator
Expand Down Expand Up @@ -165,6 +165,7 @@ contract PreConfCommitmentStore is Ownable {
);
}


/**
* @dev Gives digest to be signed for pre confirmation
* @param _txnHash transaction Hash.
Expand Down Expand Up @@ -207,7 +208,7 @@ contract PreConfCommitmentStore is Ownable {
* @param bidSignature bid signature.
* @return messageDigest returns the bid hash for given bid id.
* @return recoveredAddress the address from the bid hash.
* @return stake the stake amount of the address for bid id user.
* @return allowance the amount extractable from the address of bid id user.
*/
function verifyBid(
uint64 bid,
Expand All @@ -217,12 +218,12 @@ contract PreConfCommitmentStore is Ownable {
)
public
view
returns (bytes32 messageDigest, address recoveredAddress, uint256 stake)
returns (bytes32 messageDigest, address recoveredAddress, uint256 allowance)
{
messageDigest = getBidHash(txnHash, bid, blockNumber);
recoveredAddress = messageDigest.recover(bidSignature);
stake = userRegistry.checkStake(recoveredAddress);
require(stake > (10 * bid), "Invalid bid");
allowance = nativeToken.allowance(recoveredAddress, address(this));
require(allowance >= bid, "Insufficient allowance");
}

/**
Expand Down Expand Up @@ -286,7 +287,7 @@ contract PreConfCommitmentStore is Ownable {
bytes calldata bidSignature,
bytes memory commitmentSignature
) public returns (bytes32 commitmentIndex) {
(bytes32 bHash, address bidderAddress, uint256 stake) = verifyBid(
(bytes32 bHash, address bidderAddress, uint256 allowance) = verifyBid(
bid,
blockNumber,
txnHash,
Expand All @@ -304,7 +305,7 @@ contract PreConfCommitmentStore is Ownable {

address commiterAddress = preConfHash.recover(commitmentSignature);

require(stake > (10 * bid), "Stake too low");
require(allowance > bid, "allowance too low");

PreConfCommitment memory newCommitment = PreConfCommitment(
false,
Expand All @@ -321,7 +322,6 @@ contract PreConfCommitmentStore is Ownable {

commitmentIndex = getCommitmentIndex(newCommitment);


// Store commitment
commitments[commitmentIndex] = newCommitment;

Expand Down Expand Up @@ -421,11 +421,7 @@ contract PreConfCommitmentStore is Ownable {
commitments[commitmentIndex].commitmentUsed = true;
commitmentsCount[commitment.commiter] -= 1;

userRegistry.retrieveFunds(
commitment.bidder,
commitment.bid,
payable(commitment.commiter)
);
nativeToken.transferFrom(commitment.bidder, commitment.commiter, commitment.bid);
}

/**
Expand All @@ -446,14 +442,6 @@ contract PreConfCommitmentStore is Ownable {
providerRegistry = IProviderRegistry(newProviderRegistry);
}

/**
* @dev Updates the address of the user registry.
* @param newUserRegistry The new user registry address.
*/
function updateUserRegistry(address newUserRegistry) external onlyOwner {
userRegistry = IUserRegistry(newUserRegistry);
}

/**
* @dev Internal Function to convert bytes32 to hex string without 0x
* @param _bytes32 the byte array to convert to string
Expand Down
227 changes: 0 additions & 227 deletions contracts/UserRegistry.sol

This file was deleted.

3 changes: 1 addition & 2 deletions contracts/interfaces/IPreConfirmations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface IPreConfCommitmentStore {
uint64 blockNumber,
string memory txnHash,
bytes calldata bidSignature
) external view returns (bytes32 messageDigest, address recoveredAddress, uint256 stake);
) external view returns (bytes32 messageDigest, address recoveredAddress, uint256 allowance);

function storeCommitment(
uint64 bid,
Expand All @@ -79,7 +79,6 @@ interface IPreConfCommitmentStore {

function updateProviderRegistry(address newProviderRegistry) external;

function updateUserRegistry(address newUserRegistry) external;

// Public functions that can be included if they are meant to be called from other contracts

Expand Down
Loading