Smart Contracts¶
Store Registry¶
The Store Registry is an extension of EIP721.
Therefore each registerd store is an NFT and the contract comes with the accompanied functions, like mint
, ownerOf
, transferFrom
and approve
.
User Invitation¶
The user-facing way to add people to the store is through the use of an invitation (See Onboarding a Clerk). The contract offers these functions:
Store Configuration¶
To add and remove Relays from your Store the contract offers these functions:
Manual User Managment¶
To manually add or remove Users, Admins can call these functions:
Full Contract Listing¶
- contract StoreReg is ERC721¶
-
function mint(uint256 storeId, address owner)¶
public
¶ - Notice:
mint registeres a new store and creates a NFT for it
- Parameters:
storeId – The store nft. Needs to be unique or it will revert
owner – The owner of the store
-
function updateRootHash(uint256 storeId, bytes32 hash)¶
public
¶ - Notice:
updateRootHash updates the state root of the store
- Parameters:
storeId – The store nft
hash – The new state root hash
-
function getAllRelays(uint256 storeId)¶
public
view
returns (uint256[] memory)
¶ - Notice:
getAllRelays returns all relays for a store
- Parameters:
storeId – The store nft
- Return:
An array of relay nfts
-
function addRelay(uint256 storeId, uint256 relayId)¶
public
¶ - Notice:
addRelay adds a relay to the store
- Parameters:
storeId – The store nft
relayId – The relay nft
-
function replaceRelay(uint256 storeId, uint8 idx, uint256 relayId)¶
public
¶ - Notice:
replaceRelay replaces a relay in the store
- Parameters:
storeId – The store nft
idx – The index of the relay to replace
relayId – The new relay nft
-
function removeRelay(uint256 storeId, uint8 idx)¶
public
¶ - Notice:
removeRelay removes a relay from the store
- Parameters:
storeId – The store nft
idx – The index of the relay to remove
-
function publishInviteVerifier(uint256 storeId, address verifier)¶
public
¶ - Notice:
adds a new one-time use registration invite to the store
- Parameters:
storeId – The store nft
verifier – The address of the invite verifier (public key)
-
function redeemInvite(uint256 storeId, uint8 v, bytes32 r, bytes32 s, address user)¶
public
¶ - Notice:
redeem one of the invites. (v,r,s) are the signature
- Parameters:
storeId – The store 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 storeId, address addr, AccessLevel acl)¶
public
¶ manually add user, identified by their wallet addr, to the store
- Parameters:
storeId – The store nft
addr – The address of the user
acl – The access level of the user. can only be clerk or admin.
-
function removeUser(uint256 storeId, address who)¶
public
¶ manually remove user, identified by their wallet addr, from the store
-
function hasAtLeastAccess(uint256 storeId, address addr, AccessLevel want)¶
public
view
returns (bool)
¶ - Notice:
checks if a user has at least a certain access level
- Parameters:
storeId – The store nft
addr – The address of the user
want – The access level to check for
- Return:
true if the user has at least the access level
-
function mint(uint256 storeId, address owner)¶
Relay Registry¶
Just like the Store Registry, the Relay Registry is an extension of EIP721.
Payment Factory¶
First iteration, using counterfactual instantiation via CREATE2
.
- contract PaymentFactory¶
- Title:
Provides functions around payments addresses
-
function getPaymentAddress(address merchant, address proof, uint256 amount, address currency, bytes32 recieptHash)¶
public
view
returns (address)
¶ - Notice:
Calulates the payament address given the following parameters
- Parameters:
merchant – The merchant’s address which the funds get sent to
proof – The address that the receipt or the refund will be sent to
amount – The amount the customer is paying
currency – The address of the ERC20 that is being used as payement. If that currency is Ether then use zero address 0x0000000000000000000000000000000000000000.
recieptHash – The hash of the receipt used as salt for CREATE2
- Return:
The payment address
-
function processPayment(addresspayable merchant, addresspayable proof, uint256 amount, address currency, bytes32 recieptHash)¶
public
¶ - Notice:
Given the parameters used to generate a payement address, this function will forward the payment to the merchant’s address.
- Parameters:
merchant – The merchant’s address which the funds get sent to
proof – The address that the receipt or the refund will be sent to
amount – The amount the customer is paying
currency – The address of the ERC20 that is being used as payement. If that currency is Ether then use zero address 0x0000000000000000000000000000000000000000.
recieptHash – The hash of the receipt
Payments v2¶
Next iteration, using a single contract for all payments. Will support attestations and refunds.
- interface IPayments¶
- Title:
The Payments Contract
- Notice:
The Payments Contract validates a PaymentIntent and forwards the payment to the payee.
-
function payNative(PaymentIntent calldata payment)¶
external
payable
¶ - Notice:
Makes a payment in native currency
- Parameters:
payment – The payment details
-
function payToken(PaymentIntent calldata payment)¶
external
¶ - Notice:
Makes a payment in a ERC20 token
- Parameters:
payment – The payment details
-
function payTokenPreApproved(PaymentIntent calldata payment)¶
external
¶ - Notice:
Makes a payment in a ERC20 token with pre-approval
- Parameters:
payment – The payment details
-
function pay(PaymentIntent calldata payment)¶
external
payable
¶ - Notice:
Makes a payment
- Parameters:
payment – The payment details
-
function multiPay(PaymentIntent[] calldata payments)¶
external
payable
¶ - Notice:
Makes multiple payments
- Parameters:
payments – An array of payment details