storyprotocol / sdk

Story Protocol TypeScript SDK
MIT License
55 stars 39 forks source link

Remove Check for payerIpId in `payRoyaltyOnBehalf` #264

Closed jacob-tucker closed 1 month ago

jacob-tucker commented 1 month ago

When using royalty.payRoyaltyOnBehalf, user should be able to pass address(0) as the payerIpId

In the SDK, you can see here that it is checking if the payer IP ID exists. However I believe we should remove this line.

bonnie57 commented 1 month ago

Hi @jacob-tucker , If the user should be able to pass address(0), I think a good practice is to add a condition like the one below:

if(payerId !== address(0)){
const isPayerRegistered = await this.ipAssetRegistryClient.isRegistered({
        id: getAddress(request.payerIpId, "request.payerIpId"),
      });
      if (!isPayerRegistered) {
        throw new Error(`The payer IP with id ${request.payerIpId} is not registered.`);
      }
}

This is because the isRegistered method's logic not only includes checking for a zero address but also other logic:

function _isRegistered(address id) internal view override returns (bool) {
        if (id == address(0)) return false;
        if (id.code.length == 0) return false;
        if (!ERC165Checker.supportsInterface(id, type(IIPAccount).interfaceId)) return false;
        (uint chainId, address tokenContract, uint tokenId) = IIPAccount(payable(id)).token();
        if (id != ipAccount(chainId, tokenContract, tokenId)) return false;
        return bytes(IIPAccount(payable(id)).getString("NAME")).length != 0;
    }