Skip to content

Commit

Permalink
MIT license, support royalties, rework example
Browse files Browse the repository at this point in the history
  • Loading branch information
0xGh committed Dec 18, 2023
1 parent e050910 commit 635c0ea
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 24 deletions.
15 changes: 10 additions & 5 deletions contracts/ERC721Baseline.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand All @@ -10,10 +10,15 @@ import {IERC721Baseline} from "./IERC721Baseline.sol";
* @custom:version v0.1.0-alpha.6
* @notice A minimal proxy contract for ERC721BaselineImplementation.
*
* @dev !!WARNING!! Be careful when defining variables in your proxy as these might clash with the implementation ones.
* This contract makes the assumption that you will define storage slots similarly to EIP-1967 (https://eips.ethereum.org/EIPS/eip-1967)
* defining a struct with your variables and storing it at a specific location eg. bytes32(uint256(keccak256("erc721baseline.storage")) - 1)).
* Alternatively you can fork this contract and add a gap at the beginning, although this approach is discouraged.
* @dev !!WARNING!! Be careful when defining variables in your proxy
* as these might clash with the implementation ones.
*
* This contract makes the assumption that you will define storage slots
* similarly to EIP-1967 (https://eips.ethereum.org/EIPS/eip-1967)
* defining a struct with your variables and storing it at a specific location
* eg. bytes32(uint256(keccak256("erc721baseline.storage")) - 1)).
* Alternatively you can fork this contract and add a gap at the beginning,
* although this approach is discouraged.
*/
contract ERC721Baseline is Proxy {

Expand Down
9 changes: 3 additions & 6 deletions contracts/ERC721BaselineImplementation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand Down Expand Up @@ -33,6 +33,7 @@ contract ERC721BaselineImplementation is ERC721, IERC721Baseline {
_;
}


/************************************************
* Supported Interfaces
************************************************/
Expand Down Expand Up @@ -147,10 +148,6 @@ contract ERC721BaselineImplementation is ERC721, IERC721Baseline {
__baseURI = baseURI;
}

function _baseURI() internal view override returns (string memory) {
return __baseURI;
}

/**
* @notice Returns the URI associated with a token ID.
*
Expand Down Expand Up @@ -178,7 +175,7 @@ contract ERC721BaselineImplementation is ERC721, IERC721Baseline {
}

if (bytes(__baseURI).length > 0) {
return super.tokenURI(tokenId);
return string.concat(__baseURI, this.toString(tokenId));
}

return "";
Expand Down
2 changes: 1 addition & 1 deletion contracts/IERC721Baseline.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand Down
2 changes: 1 addition & 1 deletion contracts/Utils.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC721ConstructorAttackerMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/ERC721ProxyMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand Down
19 changes: 12 additions & 7 deletions examples/Example1.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT

pragma solidity 0.8.21;

Expand All @@ -11,20 +11,25 @@ import {IERC721Baseline} from "erc721baseline/contracts/IERC721Baseline.sol";
* This contract is just an example and MUST NOT be used as a reference
* implementation for a proxy/your project!
*
* Be careful when defining variables in your proxy as these might clash with the implementation ones.
* Be careful when defining variables in your proxy
* as these might clash with the implementation ones.
*
* ERC721Baseline.sol and this example make the assumption that you will define storage slots similarly to EIP-1967 (https://eips.ethereum.org/EIPS/eip-1967)
* defining a struct with your variables and storing it at a specific location eg. bytes32(uint256(keccak256("erc721baseline.storage")) - 1)).
* Alternatively you can fork ERC721Baseline.sol and add a gap at the beginning, although this approach is discouraged.
* ERC721Baseline.sol and this example make the assumption that you will
* define storage slots similarly to EIP-1967 (https://eips.ethereum.org/EIPS/eip-1967)
* using a struct with your variables and storing it at a specific location
* eg. bytes32(uint256(keccak256("erc721baseline.storage")) - 1)).
* Alternatively you can fork ERC721Baseline.sol and add a gap at the beginning,
* although this approach is discouraged.
*/

/**
* @title {title}
* @author {author}
*
* @dev This contract implements an example ERC721 proxy with some custom functionality.
* What is not implemented here is delegated to ERC721BaselineImplementation which will provide standard ERC721 functionality
* along with some custom functionality (see ERC721BaselineImplementation.sol implementation).
* What is not implemented here is delegated to ERC721BaselineImplementation
* which will provide standard ERC721 functionality
* along with some custom functionality (see ERC721BaselineImplementation.sol).
*/
contract Example1 is ERC721Baseline {

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"proxy"
],
"author": "0xG",
"license": "AGPL-3.0-or-later",
"license": "MIT",
"devDependencies": {
"@openzeppelin/test-helpers": "^0.5.16",
"dotenv": "^16.3.1",
Expand Down
64 changes: 64 additions & 0 deletions test/ERC721Baseline.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,27 @@ contract(
assert.equal("altered", await proxy.__baseURI());
assert.equal("", await implementation.__baseURI());
});

it("_update override does not interfere with __update onlyProxy method", async () => {
await proxy.toggleBeforeTokenTransferHook();

const tokenId = 1;
await proxy.adminMint(user, tokenId);

const anotherUser = accounts[0];

const receipt = await proxy.onlyProxy_update(
anotherUser,
tokenId,
ZERO_ADDRESS,
);

await expectEvent.notEmitted.inTransaction(
receipt.tx,
proxy,
"BeforeTokenTransferCalled",
);
});
});

describe("Metadata", () => {
Expand Down Expand Up @@ -458,6 +479,49 @@ contract(
});
});

describe("Royalties", () => {
it("returns zero address and 0 amount when unset", async () => {
const { 0: receiver, 1: amount } = await proxyDelegate.royaltyInfo(
10,
100000,
);
assert.equal(receiver, ZERO_ADDRESS);
assert.equal(amount, 0);
});

it("returns zero address and 0 amount when only one is set", async () => {
await proxy.onlyProxy_configureRoyalties(ZERO_ADDRESS, 1000);

let { 0: receiver, 1: amount } = await proxyDelegate.royaltyInfo(
10,
100000,
);
assert.equal(receiver, ZERO_ADDRESS);
assert.equal(amount, 0);

await proxy.onlyProxy_configureRoyalties(deployer, 0);

({ 0: receiver, 1: amount } = await proxyDelegate.royaltyInfo(
10,
100000,
));
assert.equal(receiver, ZERO_ADDRESS);
assert.equal(amount, 0);
});

it("returns right amount of royalties when configured", async () => {
await proxy.onlyProxy_configureRoyalties(deployer, 1500);

const salePrice = web3.utils.toWei("12.25");
const { 0: receiver, 1: amount } = await proxyDelegate.royaltyInfo(
10,
salePrice,
);
assert.equal(receiver, deployer);
assert.equal(amount, web3.utils.toWei(String(12.25 * 0.15)));
});
});

describe("Utils", () => {
describe("recover", () => {
const signer = web3.eth.accounts.create();
Expand Down

0 comments on commit 635c0ea

Please sign in to comment.