Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query owner on ERC-721 and ERC-1155 pointers #2043

Merged
merged 10 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/forge-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Run Forge build
run: |
forge --version
forge build --sizes --evm-version=cancun
forge build --evm-version=cancun
id: build

- name: Run Forge tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
NUM_SPLIT=20
make test-group-${{matrix.part}} NUM_SPLIT=20

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
jewei1997 marked this conversation as resolved.
Show resolved Hide resolved
with:
name: "${{ github.sha }}-${{ matrix.part }}-coverage"
path: ./${{ matrix.part }}.profile.out
Expand All @@ -59,7 +59,7 @@ jobs:

# Download all coverage reports from the 'tests' job
- name: Download coverage reports
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Set GOPATH
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
Expand Down
11 changes: 9 additions & 2 deletions contracts/src/CW1155ERC1155Pointer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ contract CW1155ERC1155Pointer is ERC1155, ERC2981 {
}

// Queries
function owner() public view returns (address) {
string memory req = _curlyBrace(_formatPayload("ownership", "{}"));
bytes memory response = WasmdPrecompile.query(Cw1155Address, bytes(req));
bytes memory owner_bytes = JsonPrecompile.extractAsBytes(response, "owner");
return AddrPrecompile.getEvmAddr(string(owner_bytes));
}

function balanceOf(address account, uint256 id) public view override returns (uint256) {
require(account != address(0), "ERC1155: cannot query balance of zero address");
string memory own = _formatPayload("owner", _doubleQuotes(AddrPrecompile.getSeiAddr(account)));
Expand Down Expand Up @@ -238,8 +245,8 @@ contract CW1155ERC1155Pointer is ERC1155, ERC2981 {
return string(JsonPrecompile.extractAsBytes(response, "token_uri"));
}

function isApprovedForAll(address owner, address operator) public view override returns (bool) {
string memory own = _formatPayload("owner", _doubleQuotes(AddrPrecompile.getSeiAddr(owner)));
function isApprovedForAll(address owner_, address operator) public view override returns (bool) {
string memory own = _formatPayload("owner", _doubleQuotes(AddrPrecompile.getSeiAddr(owner_)));
string memory op = _formatPayload("operator", _doubleQuotes(AddrPrecompile.getSeiAddr(operator)));
string memory req = _curlyBrace(_formatPayload("is_approved_for_all", _curlyBrace(_join(own, ",", op))));
bytes32 response = keccak256(WasmdPrecompile.query(Cw1155Address, bytes(req)));
Expand Down
22 changes: 15 additions & 7 deletions contracts/src/CW721ERC721Pointer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ contract CW721ERC721Pointer is ERC721,ERC2981 {
}

// Queries
function balanceOf(address owner) public view override returns (uint256) {
if (owner == address(0)) {
// owner of the entire collection, not specific to a token id
function owner() public view returns (address) {
string memory req = _curlyBrace(_formatPayload("ownership", "{}"));
bytes memory response = WasmdPrecompile.query(Cw721Address, bytes(req));
bytes memory owner_bytes = JsonPrecompile.extractAsBytes(response, "owner");
return AddrPrecompile.getEvmAddr(string(owner_bytes));
}

function balanceOf(address owner_) public view override returns (uint256) {
if (owner_ == address(0)) {
revert ERC721InvalidOwner(address(0));
}
uint256 numTokens = 0;
string memory startAfter;
string memory qb = string.concat(
string.concat("\"limit\":1000,\"owner\":\"", AddrPrecompile.getSeiAddr(owner)),
string.concat("\"limit\":1000,\"owner\":\"", AddrPrecompile.getSeiAddr(owner_)),
"\""
);
bytes32 terminator = keccak256("{\"tokens\":[]}");
Expand All @@ -74,8 +82,8 @@ contract CW721ERC721Pointer is ERC721,ERC2981 {
string memory tId = _formatPayload("token_id", _doubleQuotes(Strings.toString(tokenId)));
string memory req = _curlyBrace(_formatPayload("owner_of", _curlyBrace(tId)));
bytes memory response = WasmdPrecompile.query(Cw721Address, bytes(req));
bytes memory owner = JsonPrecompile.extractAsBytes(response, "owner");
return AddrPrecompile.getEvmAddr(string(owner));
bytes memory owner_ = JsonPrecompile.extractAsBytes(response, "owner");
return AddrPrecompile.getEvmAddr(string(owner_));
}

function getApproved(uint256 tokenId) public view override returns (address) {
Expand All @@ -90,8 +98,8 @@ contract CW721ERC721Pointer is ERC721,ERC2981 {
return address(0);
}

function isApprovedForAll(address owner, address operator) public view override returns (bool) {
string memory o = _formatPayload("owner", _doubleQuotes(AddrPrecompile.getSeiAddr(owner)));
function isApprovedForAll(address owner_, address operator) public view override returns (bool) {
string memory o = _formatPayload("owner", _doubleQuotes(AddrPrecompile.getSeiAddr(owner_)));
string memory req = _curlyBrace(_formatPayload("all_operators", _curlyBrace(o)));
bytes memory response = WasmdPrecompile.query(Cw721Address, bytes(req));
bytes[] memory approvals = JsonPrecompile.extractAsBytesList(response, "operators");
Expand Down
9 changes: 9 additions & 0 deletions contracts/test/CW1155ERC1155PointerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ contract CW1155ERC1155PointerTest is Test {
pointer.balanceOf(MockZeroAddress, 1);
}

function testOwner() public {
vm.mockCall(
WASMD_PRECOMPILE_ADDRESS,
abi.encodeWithSignature("query(string,bytes)", MockCWContractAddress, bytes("{\"ownership\":{}}")),
abi.encode("{\"owner\":\"sei19zhelek4q5lt4zam8mcarmgv92vzgqd3ux32jw\"}")
);
assertEq(pointer.owner(), MockOperatorEVMAddr);
}

function testBalanceOfBatch() public {
vm.mockCall(
ADDR_PRECOMPILE_ADDRESS,
Expand Down
5 changes: 5 additions & 0 deletions contracts/test/ERC1155toCW1155PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ describe("ERC1155 to CW1155 Pointer", function () {
})

describe("read", function(){
it("owner of collection", async function () {
const owner = await pointerAcc0.owner();
expect(owner).to.equal(admin.evmAddress);
});

it("get name", async function () {
const name = await pointerAcc0.name();
expect(name).to.equal("Test");
Expand Down
5 changes: 5 additions & 0 deletions contracts/test/ERC721toCW721PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ describe("ERC721 to CW721 Pointer", function () {
expect(symbol).to.equal("TEST");
});

it("owner of collection", async function () {
const owner = await pointerAcc0.owner();
expect(owner).to.equal(admin.evmAddress);
});

it("owner of", async function () {
const owner = await pointerAcc0.ownerOf(1);
expect(owner).to.equal(admin.evmAddress);
Expand Down
2 changes: 2 additions & 0 deletions contracts/test/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const ABI = {
"event ApprovalForAll(address indexed owner, address indexed operator, bool approved)",
"function name() view returns (string)",
"function symbol() view returns (string)",
"function owner() view returns (address)",
"function totalSupply() view returns (uint256)",
"function tokenURI(uint256 tokenId) view returns (string)",
"function royaltyInfo(uint256 tokenId, uint256 salePrice) view returns (address, uint256)",
Expand All @@ -42,6 +43,7 @@ const ABI = {
"event URI(string _value, uint256 indexed _id)",
"function name() view returns (string)",
"function symbol() view returns (string)",
"function owner() view returns (address)",
"function uri(uint256 _id) view returns (string)",
"function royaltyInfo(uint256 tokenId, uint256 salePrice) view returns (address, uint256)",
"function balanceOf(address _owner, uint256 _id) view returns (uint256)",
Expand Down
2 changes: 1 addition & 1 deletion x/evm/artifacts/cw1155/CW1155ERC1155Pointer.abi

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/artifacts/cw1155/CW1155ERC1155Pointer.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/artifacts/cw1155/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
)

const CurrentVersion uint16 = 1
const CurrentVersion uint16 = 2

//go:embed CW1155ERC1155Pointer.abi
//go:embed CW1155ERC1155Pointer.bin
Expand Down
Loading
Loading