Smart Contracts

Shop Registry

The Shop Registry is an extension of EIP721. Therefore each registered shop is an NFT and the contract comes with the associated functions, like mint, ownerOf, transferFrom and approve.

The shopId is chosen by the caller. Minting already taken IDs will lead to a revert.

User Invitation

The user-facing way to add Clerks to a shop is through the use of an invitation (See Onboarding a Clerk). The contract offers these functions:

Shop Configuration

To add and remove Relays from your Shop the contract offers these functions:

Manual User Management

To manually add or remove a Clerk (a type of User), an Admin can call these functions:

Full Contract Listing

contract ShopReg is AccessControl
function mint(uint256 shopId, address owner)
public
Notice:

mint registers a new shop and creates a NFT for it

Parameters:
  • shopId – The shop nft. Needs to be unique or it will revert

  • owner – The owner of the shop

function updateRootHash(uint256 shopId, bytes32 hash, uint64 _nonce)
public
Notice:

updateRootHash updates the state root of the shop

Parameters:
  • shopId – The shop nft

  • hash – The new state root hash

function getAllRelays(uint256 shopId)
public
view
returns (uint256[] memory)
Notice:

getAllRelays returns all relays for a shop

Parameters:
  • shopId – The shop nft

Return:

An array of relay nfts

function addRelay(uint256 shopId, uint256 relayId)
public
Notice:

addRelay adds a relay to the shop

Parameters:
  • shopId – The shop nft

  • relayId – The relay nft

function replaceRelay(uint256 shopId, uint8 idx, uint256 relayId)
public
Notice:

replaceRelay replaces a relay in the shop

Parameters:
  • shopId – The shop nft

  • idx – The index of the relay to replace

  • relayId – The new relay nft

function removeRelay(uint256 shopId, uint8 idx)
public
Notice:

removeRelay removes a relay from the shop

Parameters:
  • shopId – The shop nft

  • idx – The index of the relay to remove

function publishInviteVerifier(uint256 shopId, address verifier)
public

INVITES

Notice:

adds a new one-time use registration invite to the shop

Parameters:
  • shopId – The shop nft

  • verifier – The address of the invite verifier (public key)

function redeemInvite(uint256 shopId, uint8 v, bytes32 r, bytes32 s, address user)
public
Notice:

redeem one of the invites. (v,r,s) are the signature

Parameters:
  • shopId – The shop nft

  • v – The recovery id

  • r – The r value of the signature

  • s – The s value of the signature

  • user – The address of the user to register. Will become a Clerk.

function registerUser(uint256 shopId, address user, uint256 perms)
public

manually add user, identified by their wallet addr, to the shop USER CONTROL

Parameters:
  • shopId – The shop nft

  • user – The address of the user

  • perms – The perimission to assign to the new users

function removeUser(uint256 shopId, address user)
public

remove user. The address that is removing the user must have all or more permissions than the user being removed. Or be the owner of the shop

Parameters:
  • shopId – The shop

  • user – The address of the user

contract AccessControl is ERC721

Abstract contract to manage access control to a Shop.

event UserAdded(uint256 indexed shopId, address user, uint256 permissions)
event UserRemoved(uint256 indexed shopId, address users)
event PermissionAdded(uint256 indexed shopId, address user, uint8 permission)
event PermissionRemoved(uint256 indexed shopId, address user, uint8 permission)
function hasPermission(uint256 id, address user, uint8 perm)
public
view
returns (bool)

Checks if a user has a single permission

function getAllPermissions(uint256 id, address user)
public
view
returns (uint256)

Returns a user’s perimsion bitmap

function permsToBitmap(uint8[] memory perms)
public
pure
returns (uint256)

Converts an array of permissions to a bitmap

Relay Registry

Just like the Shop Registry, the Relay Registry is an extension of EIP721.

contract RelayReg is ERC721
uint256 private _relayIds
constructor()
ERC721()
mapping (uint256 => string) public relayURIs
function name()
public
pure
override
returns (string memory)
function symbol()
public
pure
override
returns (string memory)
function mint(uint256 newRelayId, address relay, string memory uri)
public
function updateURI(uint256 relayId, string memory uri)
public
function tokenURI(uint256 id)
public
view
virtual
override
returns (string memory)

Payments v2

Next iteration, using a single contract for all payments. Will support attestations and refunds.

contract Payments is IPayments
IPermit2 permit2
LibBitmap.Bitmap paymentBitmap
constructor(IPermit2 _permit2)
function payNative(PaymentRequest calldata payment)
public
payable
Inheritdoc:

IPaymentFunctions

function payToken(PaymentRequest calldata payment, bytes calldata permit2signature)
public
Inheritdoc:

IPaymentFunctions

function payTokenPreApproved(PaymentRequest calldata payment)
public
Inheritdoc:

IPaymentFunctions

function pay(PaymentRequest calldata payment)
public
payable
Inheritdoc:

IPaymentFunctions

function multiPay(PaymentRequest[] calldata payments, bytes[] calldata permit2Sigs)
public
payable
Inheritdoc:

IPaymentFunctions

function revertPayment(address from, PaymentRequest calldata payment)
public
function hasPaymentBeenMade(address from, PaymentRequest calldata payment)
public
view
returns (bool)
function getPaymentId(PaymentRequest calldata payment)
public
pure
returns (uint256)
function _usePaymentRequest(address from, PaymentRequest calldata payment)
internal
Notice:

Checks whether a payment has been made and sets the bit at the bit position in the bitmap at the word position

Parameters:
  • from – The address to use to make the payment

  • payment – The payment

struct PaymentRequest

Holds the Payment details

Members:
  • chainId (uint256) – The network the payment is supposed to be made on

  • ttl (uint256) – The deadline for the payment (block.timestamp)

  • order (bytes32) – The hash of the order details

  • currency (address) – The address of the ERC20 token to be transferred

  • amount (uint256) – The amount of tokens to be transferred

  • payeeAddress (address) – The address that will receive the payment

  • isPaymentEndpoint (bool) – Whether the payment should be forwarded with another contract call. See IPaymentEndpoint.

  • shopId (uint256) – The token id of the shop

  • shopSignature (bytes) – The signature of a merchant’s relay or signer

PaymentsByAddress

For wallets that don’t support direct function calls to pay, we support the creation of counterfactual instantiation via CREATE2.

contract PaymentsByAddress is Payments
Title:

Provides functions around payments addresses

function getPaymentAddress(PaymentRequest calldata payment, address refund)
public
view
returns (address)
Notice:

Calculates the payament address given the following parameters

Return:

The payment address