Skip to content

Commit

Permalink
Require from in TransferFrom in CW721 pointer to be the owner (#1516)
Browse files Browse the repository at this point in the history
* Require `from` in TransferFrom in CW721 pointer to be the owner

* test
  • Loading branch information
codchen authored and udpatil committed Apr 19, 2024
1 parent c11d647 commit f101bfb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions contracts/src/CW721ERC721Pointer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ contract CW721ERC721Pointer is ERC721 {
if (to == address(0)) {
revert ERC721InvalidReceiver(address(0));
}
require(from == ownerOf(tokenId), "`from` must be the owner");
string memory recipient = _formatPayload("recipient", _doubleQuotes(AddrPrecompile.getSeiAddr(to)));
string memory tId = _formatPayload("token_id", _doubleQuotes(Strings.toString(tokenId)));
string memory req = _curlyBrace(_formatPayload("transfer_nft", _curlyBrace(_join(recipient, tId, ","))));
Expand Down
15 changes: 15 additions & 0 deletions contracts/test/CW721ERC721PointerTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ contract CW721ERC721PointerTest is Test {
}

function testTransferFrom() public {
vm.mockCall(
WASMD_PRECOMPILE_ADDRESS,
abi.encodeWithSignature("query(string,bytes)", MockCWContractAddress, bytes("{\"owner_of\":{\"token_id\":\"1\"}}")),
abi.encode("{\"owner\":\"sei1vldxw5dy5k68hqr4d744rpg9w8cqs54x4asdqe\"}")
);
vm.mockCall(
JSON_PRECOMPILE_ADDRESS,
abi.encodeWithSignature("extractAsBytes(bytes,string)", bytes("{\"owner\":\"sei1vldxw5dy5k68hqr4d744rpg9w8cqs54x4asdqe\"}"), "owner"),
abi.encode(bytes("sei1vldxw5dy5k68hqr4d744rpg9w8cqs54x4asdqe"))
);
vm.mockCall(
ADDR_PRECOMPILE_ADDRESS,
abi.encodeWithSignature("getEvmAddr(string)", "sei1vldxw5dy5k68hqr4d744rpg9w8cqs54x4asdqe"),
abi.encode(address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266))
);
vm.mockCall(
WASMD_PRECOMPILE_ADDRESS,
abi.encodeWithSignature("execute(string,bytes,bytes)", MockCWContractAddress, bytes("{\"transfer_nft\":{\"recipient\":\"sei1vldxw5dy5k68hqr4d744rpg9w8cqs54x4asdqe\",\"token_id\":\"1\"}}"), bytes("[]")),
Expand Down
2 changes: 1 addition & 1 deletion x/evm/artifacts/cw721/CW721ERC721Pointer.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/evm/artifacts/cw721/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 CW721ERC721Pointer.abi
//go:embed CW721ERC721Pointer.bin
Expand Down
3 changes: 2 additions & 1 deletion x/evm/keeper/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/cw20"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/cw721"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/erc20"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/erc721"
"github.com/sei-protocol/sei-chain/x/evm/artifacts/native"
Expand Down Expand Up @@ -55,7 +56,7 @@ func (k *Keeper) DeleteERC20CW20Pointer(ctx sdk.Context, cw20Address string, ver
}

func (k *Keeper) SetERC721CW721Pointer(ctx sdk.Context, cw721Address string, addr common.Address) error {
return k.SetPointerInfo(ctx, types.PointerERC721CW721Key(cw721Address), addr[:], cw20.CurrentVersion)
return k.SetPointerInfo(ctx, types.PointerERC721CW721Key(cw721Address), addr[:], cw721.CurrentVersion)
}

func (k *Keeper) SetERC721CW721PointerWithVersion(ctx sdk.Context, cw721Address string, addr common.Address, version uint16) error {
Expand Down

0 comments on commit f101bfb

Please sign in to comment.