Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
"
},
"@openzeppelin/contracts/token/ERC721/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721.sol)
pragma solidity >=0.6.2;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC-721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
},
"@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
"
},
"@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
"
},
"contracts/CigAirdrop.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
/// @title CIG Airdrop with Claim Rounds and Multi-collection Eligibility
/// @notice Allows eligible holders of specific collections to claim a configured amount of CIG per round
/// @dev Eligibility options include: CryptoPhunks (ERC721), CryptoPunks V2 (original contract), and CryptoPunks V1 (ERC721)
interface ICryptoPunks {
function punkIndexToAddress(uint256 punkIndex) external view returns (address);
}
/// @notice Minimal interface for delegate.cash registry
interface IDelegationRegistry {
function checkDelegateForERC721(
address delegate,
address vault,
address contract_,
uint256 tokenId,
bytes32 rights
) external view returns (bool);
function checkDelegateForContract(
address delegate,
address vault,
address contract_,
bytes32 rights
) external view returns (bool);
function checkDelegateForAll(
address delegate,
address vault,
bytes32 rights
) external view returns (bool);
}
contract CigAirdrop is Ownable, ReentrancyGuard {
struct RoundConfig {
uint256 amountPerToken; // CIG per eligible token for this round
uint64 startTime; // claim window start
uint64 endTime; // claim window end
bool allowPhunks721; // allow ERC721 tokens from Phunks
bool allowPunksV2; // allow tokens from CryptoPunks V2 (original non-ERC721)
bool allowPunksV1_721; // allow ERC721 tokens from Punks V1
bool exists; // internal flag
}
IERC20 public immutable cigToken;
IERC721 public immutable phunks721;
ICryptoPunks public immutable punksV2;
IERC721 public immutable punksV2LegacyWrapper; // e.g., 0xb7f7f6c52f2e2fdb1963eab30438024864c313f6
IERC721 public immutable punksV2C721Wrapper; // e.g., 0x000000000000003607fce1ac9e043a86675c5c2f
IERC721 public immutable punksV1_721;
address public immutable delegationRegistry; // delegate.cash registry (optional)
bytes32 private constant DELEGATION_RIGHTS = bytes32(0);
// roundId => config
mapping(uint256 => RoundConfig) public rounds;
uint256 public nextRoundId;
// Per-round per-token claimed flags (for ERC721 collections)
// roundId => tokenId => claimed
mapping(uint256 => mapping(uint256 => bool)) public phunksTokenClaimed;
mapping(uint256 => mapping(uint256 => bool)) public punksV1TokenClaimed;
mapping(uint256 => mapping(uint256 => bool)) public punksV2TokenClaimed;
event RoundCreated(
uint256 indexed roundId,
uint256 amountPerToken,
uint64 startTime,
uint64 endTime,
bool allowPhunks721,
bool allowPunksV2,
bool allowPunksV1_721
);
event RoundUpdated(
uint256 indexed roundId,
uint256 amountPerToken,
uint64 startTime,
uint64 endTime,
bool allowPhunks721,
bool allowPunksV2,
bool allowPunksV1_721
);
event Funded(address indexed funder, uint256 amount);
event Claimed(
uint256 indexed roundId,
address indexed account,
uint256 numPhunks721,
uint256 numPunksV2,
uint256 numPunksV1_721,
uint256 cigAmount
);
constructor(
address cigToken_,
address phunks721_,
address punksV2_,
address punksV1_721_,
address punksV2LegacyWrapper_,
address punksV2C721Wrapper_,
address delegationRegistry_
) Ownable(msg.sender) {
require(cigToken_ != address(0), "cig token");
require(phunks721_ != address(0), "phunks");
require(punksV2_ != address(0), "punksv2");
require(punksV1_721_ != address(0), "punksv1");
cigToken = IERC20(cigToken_);
phunks721 = IERC721(phunks721_);
punksV2 = ICryptoPunks(punksV2_);
punksV1_721 = IERC721(punksV1_721_);
punksV2LegacyWrapper = IERC721(punksV2LegacyWrapper_);
punksV2C721Wrapper = IERC721(punksV2C721Wrapper_);
delegationRegistry = delegationRegistry_;
}
// --------------------------- Admin actions ---------------------------
/// @notice Deposit CIG into the contract to fund claims
function fund(uint256 amount) external {
require(amount > 0, "amount=0");
bool ok = cigToken.transferFrom(msg.sender, address(this), amount);
require(ok, "transfer failed");
emit Funded(msg.sender, amount);
}
/// @notice Create a new claim round
function createRound(RoundConfig calldata cfg) external onlyOwner returns (uint256 roundId) {
_validateConfig(cfg);
roundId = nextRoundId++;
rounds[roundId] = cfg;
rounds[roundId].exists = true;
RoundConfig memory r = rounds[roundId];
emit RoundCreated(
roundId,
r.amountPerToken,
r.startTime,
r.endTime,
r.allowPhunks721,
r.allowPunksV2,
r.allowPunksV1_721
);
}
/// @notice Update an existing round
function updateRound(uint256 roundId, RoundConfig calldata cfg) external onlyOwner {
require(rounds[roundId].exists, "round!exists");
_validateConfig(cfg);
rounds[roundId] = cfg;
rounds[roundId].exists = true;
RoundConfig memory r = rounds[roundId];
emit RoundUpdated(
roundId,
r.amountPerToken,
r.startTime,
r.endTime,
r.allowPhunks721,
r.allowPunksV2,
r.allowPunksV1_721
);
}
function _validateConfig(RoundConfig calldata cfg) internal pure {
require(cfg.amountPerToken > 0, "amountPerToken=0");
require(cfg.startTime < cfg.endTime, "time window");
require(cfg.allowPhunks721 || cfg.allowPunksV2 || cfg.allowPunksV1_721, "no eligibility");
}
// --------------------------- Claims ---------------------------
/// @notice Claim based on specific tokens across supported collections
/// @param roundId The round to claim in
/// @param phunkTokenIds ERC721 tokenIds from Phunks owned by caller
/// @param punksV2TokenIds token indexes from CryptoPunks V2 owned by caller
/// @param punksV1TokenIds ERC721 tokenIds from Punks V1 owned by caller
function claim(
uint256 roundId,
uint256[] calldata phunkTokenIds,
uint256[] calldata punksV2TokenIds,
uint256[] calldata punksV1TokenIds
) external nonReentrant {
RoundConfig memory cfg = rounds[roundId];
require(cfg.exists, "round");
require(block.timestamp >= cfg.startTime && block.timestamp <= cfg.endTime, "window");
uint256 numPhunks = 0;
uint256 numV1 = 0;
uint256 numPunksV2 = 0;
if (cfg.allowPhunks721 && phunkTokenIds.length > 0) {
numPhunks = _consumePhunks(roundId, phunkTokenIds);
} else {
require(phunkTokenIds.length == 0, "phunks not allowed");
}
if (cfg.allowPunksV1_721 && punksV1TokenIds.length > 0) {
numV1 = _consumePunksV1(roundId, punksV1TokenIds);
} else {
require(punksV1TokenIds.length == 0, "punksv1 not allowed");
}
if (cfg.allowPunksV2 && punksV2TokenIds.length > 0) {
numPunksV2 = _consumePunksV2(roundId, punksV2TokenIds);
} else {
require(punksV2TokenIds.length == 0, "punksv2 not allowed");
}
uint256 totalUnits = numPhunks + numV1 + numPunksV2;
require(totalUnits > 0, "nothing to claim");
uint256 amount = cfg.amountPerToken * totalUnits;
require(cigToken.transfer(msg.sender, amount), "cig transfer failed");
emit Claimed(roundId, msg.sender, numPhunks, numPunksV2, numV1, amount);
}
/// @notice Preview how much would be claimed for given inputs, including per-token details
/// @return phunkTokenAmounts Amount of CIG available per `phunkTokenIds` entry (0 if not eligible)
/// @return punksV2TokenAmounts Amount of CIG available per `punksV2TokenIds` entry (0 if not eligible)
/// @return punksV1TokenAmounts Amount of CIG available per `punksV1TokenIds` entry (0 if not eligible)
/// @dev Totals can be derived client-side by summing array entries
function previewClaim(
uint256 roundId,
address account,
uint256[] calldata phunkTokenIds,
uint256[] calldata punksV2TokenIds,
uint256[] calldata punksV1TokenIds
) external view returns (
uint256[] memory phunkTokenAmounts,
uint256[] memory punksV2TokenAmounts,
uint256[] memory punksV1TokenAmounts
) {
RoundConfig storage cfg = rounds[roundId];
// Initialize output arrays with the same length as inputs
phunkTokenAmounts = new uint256[](phunkTokenIds.length);
punksV2TokenAmounts = new uint256[](punksV2TokenIds.length);
punksV1TokenAmounts = new uint256[](punksV1TokenIds.length);
// If round does not exist or window is closed, return zero-initialized arrays
if (!cfg.exists) {
return (phunkTokenAmounts, punksV2TokenAmounts, punksV1TokenAmounts);
}
if (block.timestamp < cfg.startTime || block.timestamp > cfg.endTime) {
return (phunkTokenAmounts, punksV2TokenAmounts, punksV1TokenAmounts);
}
// Delegate to internal helpers to avoid stack depth issues
if (cfg.allowPhunks721 && phunkTokenIds.length > 0) {
_previewPhunks(roundId, account, phunkTokenIds, phunkTokenAmounts, cfg.amountPerToken);
}
if (cfg.allowPunksV1_721 && punksV1TokenIds.length > 0) {
_previewPunksV1(roundId, account, punksV1TokenIds, punksV1TokenAmounts, cfg.amountPerToken);
}
if (cfg.allowPunksV2 && punksV2TokenIds.length > 0) {
_previewPunksV2(roundId, account, punksV2TokenIds, punksV2TokenAmounts, cfg.amountPerToken);
}
}
function _previewPhunks(
uint256 roundId,
address account,
uint256[] calldata tokenIds,
uint256[] memory amounts,
uint256 perTokenAmount
) internal view {
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
address owner = _ownerOfViewSafe(phunks721, tokenId);
if (!phunksTokenClaimed[roundId][tokenId]
&& _isOwnerOrDelegateERC721(owner, address(phunks721), tokenId, account)
) {
amounts[i] = perTokenAmount;
}
}
}
function _previewPunksV1(
uint256 roundId,
address account,
uint256[] calldata tokenIds,
uint256[] memory amounts,
uint256 perTokenAmount
) internal view {
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
address owner = _ownerOfViewSafe(punksV1_721, tokenId);
if (!punksV1TokenClaimed[roundId][tokenId]
&& _isOwnerOrDelegateERC721(owner, address(punksV1_721), tokenId, account)
) {
amounts[i] = perTokenAmount;
}
}
}
function _previewPunksV2(
uint256 roundId,
address account,
uint256[] calldata tokenIds,
uint256[] memory amounts,
uint256 perTokenAmount
) internal view {
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
bool ok = _isOwnerOrDelegatePunksV2(punksV2.punkIndexToAddress(tokenId), tokenId, account);
if (!ok && address(punksV2LegacyWrapper) != address(0)) {
address ownerLegacy = _ownerOfViewSafe(punksV2LegacyWrapper, tokenId);
ok = _isOwnerOrDelegateERC721(ownerLegacy, address(punksV2LegacyWrapper), tokenId, account);
}
if (!ok && address(punksV2C721Wrapper) != address(0)) {
address ownerC721 = _ownerOfViewSafe(punksV2C721Wrapper, tokenId);
ok = _isOwnerOrDelegateERC721(ownerC721, address(punksV2C721Wrapper), tokenId, account);
}
if (ok && !punksV2TokenClaimed[roundId][tokenId]) {
amounts[i] = perTokenAmount;
}
}
}
function _consumePhunks(uint256 roundId, uint256[] calldata tokenIds) internal returns (uint256) {
uint256 consumed = 0;
uint256 len = tokenIds.length;
for (uint256 i = 0; i < len; i++) {
uint256 tokenId = tokenIds[i];
address owner = _ownerOfSafe(phunks721, tokenId);
if (!phunksTokenClaimed[roundId][tokenId] && _isOwnerOrDelegateERC721(owner, address(phunks721), tokenId, msg.sender)) {
phunksTokenClaimed[roundId][tokenId] = true;
consumed++;
}
}
return consumed;
}
function _consumePunksV1(uint256 roundId, uint256[] calldata tokenIds) internal returns (uint256) {
uint256 consumed = 0;
uint256 len = tokenIds.length;
for (uint256 i = 0; i < len; i++) {
uint256 tokenId = tokenIds[i];
address owner = _ownerOfSafe(punksV1_721, tokenId);
if (!punksV1TokenClaimed[roundId][tokenId] && _isOwnerOrDelegateERC721(owner, address(punksV1_721), tokenId, msg.sender)) {
punksV1TokenClaimed[roundId][tokenId] = true;
consumed++;
}
}
return consumed;
}
function _consumePunksV2(uint256 roundId, uint256[] calldata tokenIds) internal returns (uint256) {
uint256 consumed = 0;
uint256 len = tokenIds.length;
for (uint256 i = 0; i < len; i++) {
uint256 tokenId = tokenIds[i];
bool ok = _isOwnerOrDelegatePunksV2(punksV2.punkIndexToAddress(tokenId), tokenId, msg.sender);
if (!ok && address(punksV2LegacyWrapper) != address(0)) {
address tmpOwner = _ownerOfSafe(punksV2LegacyWrapper, tokenId);
ok = _isOwnerOrDelegateERC721(tmpOwner, address(punksV2LegacyWrapper), tokenId, msg.sender);
}
if (!ok && address(punksV2C721Wrapper) != address(0)) {
address tmpOwner2 = _ownerOfSafe(punksV2C721Wrapper, tokenId);
ok = _isOwnerOrDelegateERC721(tmpOwner2, address(punksV2C721Wrapper), tokenId, msg.sender);
}
if (ok && !punksV2TokenClaimed[roundId][tokenId]) {
punksV2TokenClaimed[roundId][tokenId] = true;
consumed++;
}
}
return consumed;
}
function _checkPhunks(
uint256 roundId,
address account,
uint256[] calldata tokenIds
) internal view returns (uint256) {
uint256 count = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
address owner = _ownerOfViewSafe(phunks721, tokenId);
if (!phunksTokenClaimed[roundId][tokenId] && _isOwnerOrDelegateERC721(owner, address(phunks721), tokenId, account)) {
count++;
}
}
return count;
}
function _checkPunksV1(
uint256 roundId,
address account,
uint256[] calldata tokenIds
) internal view returns (uint256) {
uint256 count = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
address owner = _ownerOfViewSafe(punksV1_721, tokenId);
if (!punksV1TokenClaimed[roundId][tokenId] && _isOwnerOrDelegateERC721(owner, address(punksV1_721), tokenId, account)) {
count++;
}
}
return count;
}
function _checkPunksV2(
uint256 roundId,
address account,
uint256[] calldata tokenIds
) internal view returns (uint256) {
uint256 count = 0;
for (uint256 i = 0; i < tokenIds.length; i++) {
uint256 tokenId = tokenIds[i];
bool ok = _isOwnerOrDelegatePunksV2(punksV2.punkIndexToAddress(tokenId), tokenId, account);
if (!ok && address(punksV2LegacyWrapper) != address(0)) {
address tmpOwner = _ownerOfViewSafe(punksV2LegacyWrapper, tokenId);
ok = _isOwnerOrDelegateERC721(tmpOwner, address(punksV2LegacyWrapper), tokenId, account);
}
if (!ok && address(punksV2C721Wrapper) != address(0)) {
address tmpOwner2 = _ownerOfViewSafe(punksV2C721Wrapper, tokenId);
ok = _isOwnerOrDelegateERC721(tmpOwner2, address(punksV2C721Wrapper), tokenId, account);
}
if (ok && !punksV2TokenClaimed[roundId][tokenId]) {
count++;
}
}
return count;
}
function _ownerOfSafe(IERC721 token, uint256 tokenId) private view returns (address) {
// Use try/catch via low-level staticcall to avoid reverts on non-existent tokens
(bool ok, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(IERC721.ownerOf.selector, tokenId));
if (!ok || data.length == 0) return address(0);
return abi.decode(data, (address));
}
function _ownerOfViewSafe(IERC721 token, uint256 tokenId) private view returns (address) {
(bool ok, bytes memory data) = address(token).staticcall(abi.encodeWithSelector(IERC721.ownerOf.selector, tokenId));
if (!ok || data.length == 0) return address(0);
return abi.decode(data, (address));
}
function _isOwnerOrDelegateERC721(
address owner,
address tokenContract,
uint256 tokenId,
address caller
) private view returns (bool) {
if (owner == address(0)) return false;
if (caller == owner) return true;
if (delegationRegistry == address(0)) return false;
IDelegationRegistry reg = IDelegationRegistry(delegationRegistry);
if (reg.checkDelegateForERC721(caller, owner, tokenContract, tokenId, DELEGATION_RIGHTS)) return true;
if (reg.checkDelegateForContract(caller, owner, tokenContract, DELEGATION_RIGHTS)) return true;
if (reg.checkDelegateForAll(caller, owner, DELEGATION_RIGHTS)) return true;
return false;
}
function _isOwnerOrDelegatePunksV2(
address owner,
uint256 tokenId,
address caller
) private view returns (bool) {
if (owner == address(0)) return false;
if (caller == owner) return true;
if (delegationRegistry == address(0)) return false;
IDelegationRegistry reg = IDelegationRegistry(delegationRegistry);
address contractAddr = address(punksV2);
// Support specific-token delegations (even though CryptoPunks is non-ERC721) and broader scopes
if (reg.checkDelegateForERC721(caller, owner, contractAddr, tokenId, DELEGATION_RIGHTS)) return true;
if (reg.checkDelegateForContract(caller, owner, contractAddr, DELEGATION_RIGHTS)) return true;
if (reg.checkDelegateForAll(caller, owner, DELEGATION_RIGHTS)) return true;
return false;
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}
}}
Submitted on: 2025-09-29 10:39:51
Comments
Log in to comment.
No comments yet.