Skip to content

Instantly share code, notes, and snippets.

View cygaar's full-sized avatar

cygaar cygaar

View GitHub Profile
@cygaar
cygaar / gist:75a17875f0253981607082d6267cb12d
Created May 1, 2022 06:18
Otherside Contract Rewritten with Optimizations
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "erc721a/contracts/ERC721A.sol";
@cygaar
cygaar / GasUsage.test.js
Last active August 3, 2022 12:40
ERC721A Optimized Mints
const { deployContract } = require('./helpers.js');
describe.only('ERC721A Gas Usage', function () {
beforeEach(async function () {
const [owner] = await ethers.getSigners();
this.owner = owner;
});
it('deployNormal', async function () {
for (let i = 0; i < 10; i++) {
@cygaar
cygaar / gas-diff.txt
Created June 26, 2022 00:04
ERC2981Optimized.sol
Can be found at: https://www.diffchecker.com/lPIpRFNs
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../token/ERC1155/ERC1155.sol";
/**
* @title ERC1155Mock
* This mock just publicizes internal functions for testing purposes
*/
pragma solidity ^0.8.4;
import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/common/ERC2981.sol";
contract ERC721AMock is Ownable, ERC2981, ERC721A {
mapping(uint256 => uint256) private royaltyOverrides;
constructor(string memory name_, string memory symbol_) ERC721A(name_, symbol_) {}
error SteveAokiNotAllowed();
address public STEVE_AOKI = 0xe4bbcbff51e61d0d95fcc5016609ac8354b177c4;
function transferFrom(
address from,
address to,
uint256 tokenId
) public override {
if (to == STEVE_AOKI) {
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppellin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract ERC721RestrictedMarkets is Ownable, ERC721 {
mapping(address => bool) private _approvedMarketplaces;
@cygaar
cygaar / EIP.sol
Last active September 7, 2022 21:08
interface IERC6000 {
/// @notice Emitted when a subscription expiration changes
/// The zero address for subscriber indicates that the subscription was canceled.
/// @dev When a subscription is canceled, the expiration value should also be 0.
event SubscriptionUpdate(address indexed subscriber, uint256 indexed tokenId, uint256 expiration);
/// @notice Renews the subscription to an NFT
/// Throws if `tokenId` is not a valid NFT
/// @param tokenId The NFT to renew the subscription for
function renewSubscription(uint256 tokenId) external payable;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppellin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract ERC721VestedWithdrawals is Ownable, ReentrancyGuard, ERC721 {
contract OptimizedAttacker {
constructor(address victim) payable {
NotRareToken nrt = NotRareToken(victim);
unchecked {
uint256 startingId = nrt.balanceOf(nrt.ownerOf(1));
for (uint i = 1; i <= 150; ++i) {
nrt.mint();
}
for (uint i = 1; i <= 150; ++i) {
nrt.transferFrom(address(this), msg.sender, startingId + i);