Skip to content

Commit

Permalink
adjust value to use in recording
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov committed Aug 14, 2023
1 parent 87b3cd7 commit 753a753
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ pragma solidity 0.8.15;
import "./ZkBobPool.sol";

/**
* @title ZkBobDirectTokenOwnership
* @title ZkBobDTO
*/
abstract contract ZkBobDirectTokenOwnership is ZkBobPool {
abstract contract ZkBobDTO is ZkBobPool {
function _beforeWithdrawal(uint256 _tokenAmount) internal view override returns (address, uint256) {
return (token, _tokenAmount);
}

function _adjustPriorRecord(int256 _amount) internal view override returns (int256) {
return _amount;
}
}
13 changes: 9 additions & 4 deletions src/zkbob/ZkBobERC4626Extended.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ pragma solidity 0.8.15;

import "../interfaces/IATokenVault.sol";
import "./ZkBobPool.sol";
import "./ZkBobWETHMixin.sol";

/**
* @title ZkBobERC4626Extended
*/
abstract contract ZkBobERC4626Extended is ZkBobPool, ZkBobWETHMixin {
abstract contract ZkBobERC4626Extended is ZkBobPool {
function _beforeWithdrawal(uint256 _tokenAmount) internal override returns (address, uint256) {
uint256 amount = IATokenVault(token).redeem(_tokenAmount, address(this), address(this));
address token_out = address(IATokenVault(token).UNDERLYING());
return (token_out, amount);
}

function checkOnReceivingETH() internal override {
require(msg.sender == IATokenVault(token).UNDERLYING(), "Not a WETH withdrawal");
function _adjustPriorRecord(int256 _amount) internal view override returns (int256) {
if (_amount == 0) {
return 0;
} else if (_amount > 0) {
return int256(IATokenVault(token).previewRedeem(uint256(_amount)));
} else {
return -int256(IATokenVault(token).previewRedeem(uint256(-_amount)));
}
}
}
4 changes: 3 additions & 1 deletion src/zkbob/ZkBobPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk

function _beforeWithdrawal(uint256 _tokenAmount) internal virtual returns (address, uint256);

function _adjustPriorRecord(int256 _amount) internal view virtual returns (int256);

/**
* @dev Converts given amount of tokens into native coins sent to the provided address.
* @param _token token address to unwrap native coins.
Expand Down Expand Up @@ -210,7 +212,7 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
// not from the pool funds.
// For withdrawals, withdrawal amount that is checked against limits for specific user is already inclusive
// of operator's fee, thus there is no need to consider it separately.
(,, uint256 txCount) = _recordOperation(user, transfer_token_delta);
(,, uint256 txCount) = _recordOperation(user, _adjustPriorRecord(transfer_token_delta));

uint256 nullifier = _transfer_nullifier();
{
Expand Down
4 changes: 2 additions & 2 deletions src/zkbob/ZkBobPoolBOB.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity 0.8.15;

import "./ZkBobPool.sol";
import "./ZkBobDirectTokenOwnership.sol";
import "./ZkBobDTO.sol";
import "./ZkBobTokenSellerMixin.sol";
import "./ZkBobSaltedPermitMixin.sol";

/**
* @title ZkBobPoolBOB
* Shielded transactions pool for BOB tokens.
*/
contract ZkBobPoolBOB is ZkBobPool, ZkBobDirectTokenOwnership, ZkBobTokenSellerMixin, ZkBobSaltedPermitMixin {
contract ZkBobPoolBOB is ZkBobPool, ZkBobDTO, ZkBobTokenSellerMixin, ZkBobSaltedPermitMixin {
constructor(
uint256 __pool_id,
address _token,
Expand Down
4 changes: 2 additions & 2 deletions src/zkbob/ZkBobPoolERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity 0.8.15;

import "./ZkBobPool.sol";
import "./ZkBobDirectTokenOwnership.sol";
import "./ZkBobDTO.sol";
import "./ZkBobTokenSellerMixin.sol";
import "./ZkBobPermit2Mixin.sol";

/**
* @title ZkBobPoolERC20
* Shielded transactions pool for ERC20 tokens
*/
contract ZkBobPoolERC20 is ZkBobPool, ZkBobDirectTokenOwnership, ZkBobTokenSellerMixin, ZkBobPermit2Mixin {
contract ZkBobPoolERC20 is ZkBobPool, ZkBobDTO, ZkBobTokenSellerMixin, ZkBobPermit2Mixin {
constructor(
uint256 __pool_id,
address _token,
Expand Down
4 changes: 2 additions & 2 deletions src/zkbob/ZkBobPoolETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity 0.8.15;

import "./ZkBobPool.sol";
import "./ZkBobDirectTokenOwnership.sol";
import "./ZkBobDTO.sol";
import "./ZkBobWETHMixin.sol";
import "./ZkBobPermit2Mixin.sol";

/**
* @title ZkBobPoolETH
* Shielded transactions pool for native and wrapped native tokens.
*/
contract ZkBobPoolETH is ZkBobPool, ZkBobDirectTokenOwnership, ZkBobWETHMixin, ZkBobPermit2Mixin {
contract ZkBobPoolETH is ZkBobPool, ZkBobDTO, ZkBobWETHMixin, ZkBobPermit2Mixin {
constructor(
uint256 __pool_id,
address _token,
Expand Down
6 changes: 5 additions & 1 deletion src/zkbob/ZkBobPoolETHERC4625Extended.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "./ZkBobPermit2Mixin.sol";
* @title ZkBobPoolETHERC4625Extended
* Shielded transactions ERC4626 based pool for native and wrapped native tokens.
*/
contract ZkBobPoolETHERC4625Extended is ZkBobPool, ZkBobERC4626Extended, ZkBobPermit2Mixin {
contract ZkBobPoolETHERC4625Extended is ZkBobPool, ZkBobWETHMixin, ZkBobERC4626Extended, ZkBobPermit2Mixin {
constructor(
uint256 __pool_id,
address _token,
Expand All @@ -34,6 +34,10 @@ contract ZkBobPoolETHERC4625Extended is ZkBobPool, ZkBobERC4626Extended, ZkBobPe
ZkBobPermit2Mixin(_permit2)
{}

function checkOnReceivingETH() internal override {
require(msg.sender == IATokenVault(token).UNDERLYING(), "Not a WETH withdrawal");
}

// There is no need in this method if a new pool is deployed
function migrationToERC4626() external {
require(msg.sender == address(this), "Incorrect invoker");
Expand Down
4 changes: 2 additions & 2 deletions src/zkbob/ZkBobPoolUSDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
pragma solidity 0.8.15;

import "./ZkBobPool.sol";
import "./ZkBobDirectTokenOwnership.sol";
import "./ZkBobDTO.sol";
import "./ZkBobTokenSellerMixin.sol";
import "./ZkBobUSDCPermitMixin.sol";

/**
* @title ZkBobPoolUSDC
* Shielded transactions pool for USDC tokens supporting USDC transfer authorizations
*/
contract ZkBobPoolUSDC is ZkBobPool, ZkBobDirectTokenOwnership, ZkBobTokenSellerMixin, ZkBobUSDCPermitMixin {
contract ZkBobPoolUSDC is ZkBobPool, ZkBobDTO, ZkBobTokenSellerMixin, ZkBobUSDCPermitMixin {
constructor(
uint256 __pool_id,
address _token,
Expand Down
4 changes: 2 additions & 2 deletions src/zkbob/ZkBobPoolUSDCMigrated.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity 0.8.15;

import "./ZkBobPool.sol";
import "./ZkBobDirectTokenOwnership.sol";
import "./ZkBobDTO.sol";
import "./ZkBobTokenSellerMixin.sol";
import "./ZkBobUSDCPermitMixin.sol";

Expand All @@ -13,7 +13,7 @@ import "./ZkBobUSDCPermitMixin.sol";
* It is intended to be deployed as implemenation of the pool for BOB tokens that is
* why it supports the same nomination
*/
contract ZkBobPoolUSDCMigrated is ZkBobPool, ZkBobDirectTokenOwnership, ZkBobTokenSellerMixin, ZkBobUSDCPermitMixin {
contract ZkBobPoolUSDCMigrated is ZkBobPool, ZkBobDTO, ZkBobTokenSellerMixin, ZkBobUSDCPermitMixin {
constructor(
uint256 __pool_id,
address _token,
Expand Down

0 comments on commit 753a753

Please sign in to comment.