Skip to content

Commit

Permalink
Merge pull request #177 from 0xqd/refactor-4626-batchrequest
Browse files Browse the repository at this point in the history
feat: refactor 4626 batch contract
  • Loading branch information
0xKitsune authored Jun 9, 2024
2 parents e06126f + d50113a commit 0fdbba4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ docs/

# Dotenv file
.env

# intellij
.idea/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde_json = "1.0.116"
thiserror = "1.0.60"
tokio = { version = "1.37.0", default-features = false }
tracing = "0.1.40"
uniswap_v3_math = { git = "https://github.com/0xKitsune/uniswap-v3-math.git", rev = "1120ff6" }
uniswap_v3_math = { git = "https://github.com/0xKitsune/uniswap-v3-math.git", rev = "1120ff6" }
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "dd7a999", features = [
"contract",
"network",
Expand Down
48 changes: 18 additions & 30 deletions contracts/src/GetERC4626VaultDataBatchRequest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,39 +51,31 @@ contract GetERC4626VaultDataBatchRequest {

if (codeSizeIsZero(vaultAddress)) continue;

address assetToken = IERC4626Vault(vaultAddress).asset();
// Check that assetToken exists and get assetTokenDecimals
if (codeSizeIsZero(assetToken)) continue;
(bool assetTokenDecimalsSuccess, bytes memory assetTokenDecimalsData) =
assetToken.call{gas: 20000}(abi.encodeWithSignature("decimals()"));

if (!assetTokenDecimalsSuccess || assetTokenDecimalsData.length == 32) {
continue;
}

(uint256 assetTokenDecimals) = abi.decode(assetTokenDecimalsData, (uint256));
if (assetTokenDecimals == 0 || assetTokenDecimals > 255) {
continue;
}

VaultData memory vaultData;

// Get tokens
vaultData.vaultToken = vaultAddress;
vaultData.assetToken = IERC4626Vault(vaultAddress).asset();

// Check that assetToken exists
if (codeSizeIsZero(vaultData.assetToken)) continue;
vaultData.assetToken = assetToken;

// Get vault token decimals
vaultData.vaultTokenDecimals = IERC4626Vault(vaultAddress).decimals();

// Get asset token decimals
(bool assetTokenDecimalsSuccess, bytes memory assetTokenDecimalsData) =
vaultData.assetToken.call{gas: 20000}(abi.encodeWithSignature("decimals()"));

if (assetTokenDecimalsSuccess) {
uint256 assetTokenDecimals;

if (assetTokenDecimalsData.length == 32) {
(assetTokenDecimals) = abi.decode(assetTokenDecimalsData, (uint256));

if (assetTokenDecimals == 0 || assetTokenDecimals > 255) {
continue;
} else {
vaultData.assetTokenDecimals = uint8(assetTokenDecimals);
}
} else {
continue;
}
} else {
continue;
}
vaultData.assetTokenDecimals = uint8(assetTokenDecimals);

// Get token reserves
vaultData.vaultTokenReserve = IERC4626Vault(vaultAddress).totalSupply();
Expand Down Expand Up @@ -132,10 +124,6 @@ contract GetERC4626VaultDataBatchRequest {
}

function codeSizeIsZero(address target) internal view returns (bool) {
if (target.code.length == 0) {
return true;
} else {
return false;
}
return target.code.length == 0;
}
}

0 comments on commit 0fdbba4

Please sign in to comment.