Skip to content

Commit

Permalink
Revert "Merge pull request #25 from plumenetwork/fix/codesize"
Browse files Browse the repository at this point in the history
This reverts commit 6ce71b7, reversing
changes made to 5ab99d8.
  • Loading branch information
Purva-Chaudhari committed Sep 23, 2024
1 parent 155fa6a commit e7c615f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 35 deletions.
15 changes: 0 additions & 15 deletions smart-wallets/src/WalletUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,4 @@ contract WalletUtils {
_;
}

/**
* @notice Checks if an address is a contract.
* @dev This function uses the `extcodesize` opcode to check if the target address contains contract code.
* It returns false for externally owned accounts (EOA) and true for contracts.
* @param addr The address to check.
* @return bool Returns true if the address is a contract, and false if it's an externally owned account (EOA).
*/
function isContract(address addr) internal view returns (bool) {
uint32 size;
assembly {
size := extcodesize(addr)
}
return size > 0;
}

}
23 changes: 3 additions & 20 deletions smart-wallets/src/token/AssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.25;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import { SmartWallet } from "../SmartWallet.sol";
import { WalletUtils } from "../WalletUtils.sol";
import { IAssetToken } from "../interfaces/IAssetToken.sol";
import { YieldDistributionToken } from "./YieldDistributionToken.sol";

Expand All @@ -14,7 +13,7 @@ import { YieldDistributionToken } from "./YieldDistributionToken.sol";
* @notice ERC20 token that represents a tokenized real world asset
* and distributes yield proportionally to token holders
*/
contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
contract AssetToken is YieldDistributionToken, IAssetToken {

// Storage

Expand Down Expand Up @@ -87,12 +86,6 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
*/
error AddressNotWhitelisted(address user);

/**
* @notice Indicates a failure because the user's SmartWallet call failed
* @param user Address of the user whose SmartWallet call failed
*/
error SmartWalletCallFailed(address user);

// Constructor

/**
Expand Down Expand Up @@ -288,21 +281,11 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {

/**
* @notice Get the available unlocked AssetToken balance of a user
* @dev Attempts to call `getBalanceLocked` on the user if the user is a contract (SmartWallet).
* Reverts if the SmartWallet call fails. If the user is an EOA, it returns the balance directly.
* @param user Address of the user to get the available balance of
* @return balanceAvailable Available unlocked AssetToken balance of the user
*/
function getBalanceAvailable(address user) public view returns (uint256) {
if (isContract(user)) {
try SmartWallet(payable(user)).getBalanceLocked(this) returns (uint256 lockedBalance) {
return balanceOf(user) - lockedBalance;
} catch {
revert SmartWalletCallFailed(user);
}
} else {
return balanceOf(user);
}
function getBalanceAvailable(address user) public view returns (uint256 balanceAvailable) {
return balanceOf(user) - SmartWallet(payable(user)).getBalanceLocked(this);
}

/// @notice Total yield distributed to all AssetTokens for all users
Expand Down

0 comments on commit e7c615f

Please sign in to comment.