โ˜‘๏ธWhitelist smart contract

๐ŸŒŠ Intro

This repository provides an implementation of Whitelist interface proposed in the TZIP-15 written in SmartPy: Python library for constructing Tezos SC and compiled to Michelson code. The contract is migrated from the Lorentz whitelisting contract.

๐Ÿ’ก Why a whitelist contract?

The purpose of the Whitelist contract is to validate transfers so the token's contract holder can control which users can perform such operations. The Whitelist contract contains a list of users and entities that have satisfied the euroTz KYC/AML compliance procedures and thus are eligible to hold euroTz Tokens.

๐Ÿ”” Specifications

UserID

As userID, we use the user's public key hash, e.g. a tz1 address.

Storage

โ€ข whitelists:

big_map (
         key = whitelistID: Nat,
         value = {
         unrestricted: Bool,
         allowedWhitelists: set(whitelistID)
        })

โ€ข users:

big_map (
         key = userID: address,
         value = whitelistID : Nat
        )

โ€ข admin: address

โ€ข issuer: address

๐Ÿš€ We use the interface as an on-chain wrapper:

  1. The whitelist contract is deployed separately from our euroTz contract.

  2. The assertion entrypoints are called from euroTz contract, without requiring callbacks since they call FAILWITH when they fail.

How does our wrapper whitelist SC work?

๐ŸŽฅ Main scenarios:

  1. Issuer may transfer to bob ONLY if bob's is an asserted receiver, in other words, bob must be added to the users big_map and his whitelistID must be set and unrestricted in the whitelists big_map.

  2. Alice may transfer to Bob ONLY if bob and Alice are asserted users AND Bob's whitelistID is in Alice's allowedWhitelists.

โฌ‡๏ธ Get the Project:

  1. Clone the project & cd to the directory;

  2. Install the packages with yarn install.

๐Ÿ” EntryPoints (SC methods):

Visit TZIP-15 to get a more developed description of the whitelist contract entrypoints.

๐Ÿ‘€ Tests Cases

The smartContract tests are written in smartPy and in JS (with Taquito, Mocha and Chai)

To launch tests, you have to:

  1. Originate the whitelist contract with:

     yarn originate-whitelist
  2. Paste the address of the originated whitelist SC in the conf file under /conf as following:

whitelistContractAddress: KT1-whitelist-address
  1. Originate the euroTz contract with:

     yarn originate-euroTz
  2. Paste the address of the originated euroTz SC in the same conf file as follows:

euroTzContractAddress: KT1-euroTz-address

๐ŸŽ‰ You're ready to launch tests now...

The following tests use as

โ€ข whitelist contract address: KT1PFj9vshZKrHYLCswxUXKtY89SDYkXThDC

โ€ข euroTz contract address: KT1WcxYBrh9WwRo1vkbSJxAqr6ZVAUqDEiFg

Management entrypoints

    yarn test-setAdmin # Test setAdmin entryPoint

Test Output:

Whitelist Smart Contract: SetAdmin Entrypoint tests
initialAdmin:  tz1SVqTz7entj982jDSKcTQNgT7f2cg7C8dk
------------------------------------------------------------
MESSAGE STATEMENT:  only admin may update
โœ“ Update admin as non-admin / Should fail (4409ms)

OpHash :  oo5ofnco8QxcMtjm4Xo3Px93knyssQBLhL2bCTeKHUSbpWW7fX3
Admin from storage:  tz1XrCvviH8CqoHMSKpKuznLArEa1yR9U7ep
โœ“ Update admin as admin / Should succeed (27855ms)

OpHash :  oom91CsjUhFs9ThaSP2S2NgtYK4UT5HnceEHwr27i6bn3kvxeMX
Admin from storage:  tz1SVqTz7entj982jDSKcTQNgT7f2cg7C8dk
โœ“ Reset old admin as admin / Should succeed (46817ms)
3 passing (1m)
โœจ  Done in 82.75s.
    yarn test-setIssuer # Test setIssuer entryPoint

Test Output:

Whitelist Smart Contract: SetIssuer Entrypoint tests
initialIssuer:  tz1SVqTz7entj982jDSKcTQNgT7f2cg7C8dk
------------------------------------------------------------
MESSAGE STATEMENT:  only admin may update
โœ“ Update issuer as non-admin / Should fail (5824ms)

OpHash :  ooERfBcJPaByiUdrhvidyHZEkZ2ki68LbVMz2mbPWrSJMfDwvzU
Issuer from storage:  tz1XrCvviH8CqoHMSKpKuznLArEa1yR9U7ep
โœ“ Update issuer as admin / Should succeed (38408ms)

OpHash :  oooiEXQCbmtAFYZpqvDKbJzeyXvYGYqWatTfGxCYdxxZona1gZz
Issuer from storage:  tz1SVqTz7entj982jDSKcTQNgT7f2cg7C8dk
โœ“ Reset old issuer as admin / Should succeed (52151ms)
3 passing (2m)
โœจ  Done in 101.61s.
    yarn test-addUser # Test addUser entryPoint

Test Output:

Whitelist Smart Contract: AddUser Entrypoint tests

MESSAGE STATEMENT:  only admin may update
โœ“ Add user as non-admin / Should fail (2832ms)

MESSAGE STATEMENT:  issuer is not a user
โœ“ Add Issuer as a standard user as admin / Should fail (3734ms)

OpHash :  opVy3boRogtgpU2fz4wjgMwNEYxogymqGRqsUFzPdc7WChEzviq
โœ“ Add User with None as admin / Should succeed (16585ms)

OpHash :  ooZvAefYT4Q7bqi8K2AJQY1QWi3neMZVxEVqXGeAzsN52pHVKtz
userWhitelistID: 10
โœ“ Add user with Some as admin / Should succeed (116256ms)

4 passing (2m)
โœจ  Done in 142.39s.
    yarn test-setWhitelistOutbound # Test setWhitelistOutbound entryPoint

Test Output:

Whitelist Smart Contract: SetWhitelistOutbound Entrypoint tests

MESSAGE STATEMENT:  only admin may update
โœ“ Set Whitelist Outbound as non-admin / Should fail (3120ms)

OpHash:  ooczsae6WA6xDTGYVhUuk4SS1WC55CFeqcBtPkdhGkVQjfqnrR6
whitelistDetails:  { allowed_whitelists: [], unrestricted: true }
โœ“ Set Whitelist Outbound as admin with Some / Should succeed (177318ms)

OpHash: onjtUV2b4KWD67hNawDmKkndh1Hwa4JWDYmg83iXCrhn4ZDrGMB
whitelistDetails:  {allowed_whitelists: [ 555 ], unrestricted: true}
โœ“ Update existing outbound whitelists as admin / Should succeed (36756ms)

OpHash:  oooTfhZYiiMQUjPpsTMXXdH6KUUQu6a5a4KDqV2k9BPaha798o6
โœ“ Remove outbound whitelist as admin / Should succeed (25887ms)

4 passing (4m)
โœจ  Done in 247.35s.

Informative entrypoints

    yarn test-viewEntryPoints # Test getters entryPoints

Test Output:

Whitelist Smart Contract: Informative Entrypoints tests

viewOpHash :  ooZZfDBazuXBiUsE2Vc3NAfg6f9eWPFdA6RooXqDtguajvpFGiY
Admin from view contract storage:  tz1SVqTz7entj982jDSKcTQNgT7f2cg7C8dk
โœ“ Get Admin Address / Should succeed (84910ms)

viewOpHash :  oofULds4jJv6DyWw6v2nnh3FCogfgZhNvPwPTyica45zZzQAvzD
Issuer from view contract storage:  tz1SVqTz7entj982jDSKcTQNgT7f2cg7C8dk
โœ“ Get Issuer Address / Should succeed (16055ms)

viewOpHash :  op2rGJ3L2oczuUnkfshRetWgAkGSj2Zr6nahuGyzbAHfSJ3wNpw
Whitelist details from view contract storage:  { allowed_whitelists: [], unrestricted: true }
โœ“ Get WhitelistDetails / Should succeed (111324ms)

viewOpHash :  onq4VEiZ6q3SVKp8p1k7fya7auSL2m8WNaaUiphGi6XdJ2hv1NP
whiteListID from view contract storage: 444
โœ“ Get User whitelist ID / Should succeed (75185ms)

MESSAGE STATEMENT:  whitelist not found
โœ“ Get inexistent WhitelistDetails / Should fail (2839ms)

MESSAGE STATEMENT:  user not found
โœ“ Get inexistent User / Should fail (4059ms)

6 passing (5m)
โœจ  Done in 302.18s.

Assertion entrypoints

    yarn test-assertReceiver # Test assertReceiver entryPoint

Test Output:

Whitelist Smart Contract: AssertReceiver Entrypoint tests

opHash :  onsWLrfWngr7PGLjYTJWUE5Fn1N2pGcd8uWPXQb1b2G9TCRqLKn
โœ“ Assert receiver Issuer - Admin mints 50 euroTz to the Issuer / Should succeed (66577ms)

MESSAGE STATEMENT:  user not on a whitelist
โœ“ Assert receiver inexistent User - Admin tries to mint 40 euroTz to an inexistent user / Should fail (4432ms)

OpHash :  op5bsabpVa8FNszZJWmXi5TpDyYjz3AViovU1J3dMafo3Vha6m7
โœ“ Admin adds Ouss in users big_map (26387ms)

MESSAGE STATEMENT:  whitelist does not exist
โœ“ Assert receiver existing User, his associated whitelistID don t refer to an existing whitelist - Admin tries to mint 40 euroTz / Should fail (5517ms)

OpHash :  oodR5jieVi7enfGoVkUZcJdVnep5fyya7DFGQ576rJZzbtSEoAs
โœ“ Admin sets Ouss s whitelist outbound initally restricted (26856ms)

MESSAGE STATEMENT:  outbound restricted
โœ“ Assert receiver existing User, his associated whitelist is restricted - Admin tries to mint 40 euroTz to whitelisted restricted user (Ouss) / Should fail (2814ms)

OpHash :  oneyu5hcCPQopgvuQ2KsV4AjJLrNjkh2iKCWi96tuB9VceChcJX
โœ“ Admin sets Ouss s whitelist outbound unrestricted (106327ms)

opHash :  ooRxZ5HtiEfwtSrMpYgzJ6qWyt6qap87ThpRFP2mNpfjyughTH9
โœ“ Assert receiver existing User, the associated whitelistID refers to an existing whitelist and unrestricted - Admin mints 50 euroTz to Ouss: whitelisted unrestricted user / Should succeed (26285ms)

8 passing (4m)
โœจ  Done in 270.13s.
    yarn test-assertReceivers # Test assertReceivers entryPoint

Test Output:

Whitelist Smart Contract: AssertReceivers Entrypoint tests

MESSAGE STATEMENT:  user not on a whitelist
โœ“ Assert receivers with one inexistent user / Should fail (3127ms)

OpHash :  ooHWW4VusZTuiDREUuXefX7rLbAQw1PZe38Vz8qJXJDdMTTeCDc
โœ“ Admin adds Khaled in whitelst contract (75338ms)

MESSAGE STATEMENT:  whitelist does not exist
โœ“ Assert receivers with one user s whitelistID don t refer to an existing whitelist / Should fail (3524ms)

OpHash:  oo5W1bhrJmmSrv97mc5mS3Ee7Kqgbgu71vxJTYh1JW4jpM7QgZx
โœ“ Admin sets Khaled s whitelist outbound restricted (26590ms)

MESSAGE STATEMENT:  outbound restricted
โœ“ Assert receivers with one user s whitelist restricted / Should fail (6387ms)

OpHash :  opZcnwmQvBPiHReqad11vSB3iFZbto4i5aBsUAH1Ck8k23gxCoQ
โœ“ Admin sets Khaled s whitelist outbound unrestricted (55717ms)

OpHash:  opCXZZmrC4esizqy5trQgTPv3gKv4yE7SHmXMpXRzfgvWcgufV9
โœ“ Assert receivers: all users are existing and unrestricted / Sould succeed (35641ms)

7 passing (5m)
โœจ  Done in 324.29s.
    yarn test-assertTrasnfer # Test assertTrasnfer entryPoint

Test Output:

Whitelist Smart Contract: AssertTransfer Entrypoint tests

MESSAGE STATEMENT:  user not on a whitelist
โœ“ Assert Transfer from Issuer to an inexistent user - Issuer tries to transfer 9 euroTz to Fred / Should fail (3379ms)

OpHash :  oozZLubPscjt5ed9YaQi61Mfq94xNLAYC6bruTy3u2zHvcZSDcR
โœ“ Admin adds Fred in whitelst contract (91502ms)

MESSAGE STATEMENT:  whitelist does not exist
โœ“ Assert Transfer from Issuer to an existing user with whitelistID don t refer to an existing whitelist - Issuer tries to transfer 9 euroTz to Fred / Should fail (5575ms)

OpHash:  ooykfX3jCuioSabk69PV9BpLdxT5BCT7sbJMZB2sRH4sAogk6sW
โœ“ Admin sets Fred s whitelist outbound initally restricted (18412ms)

MESSAGE STATEMENT:  outbound restricted
โœ“ Assert Transfer from Issuer to existing, restricted user - Issuer tries to transfer 9 euroTz to Fred / Should fail (7536ms)

OpHash:  opMY1NtPZC9tmJAP2PCZqXQ6jfzKL6S5XDVvJpu6sYNjPHf8qvD
โœ“ Admin sets Fred s whitelist outbound unrestricted (36973ms)

euroTzTrasnferOpHash:  onxrnAwMs63ZvQKvG5T2GVhohfTuWdVcbKFLq9qQwzPgzTww5tS
โœ“ Assert Transfer from Issuer to an existing, unrestricted user - Issuer transfers 9 euroTz to Fred / Should succeed (27318ms)

MESSAGE STATEMENT:  user not on a whitelist
โœ“ Assert Transfer from existing to an inexistent user - Fred tries to transfer 3 euroTz to Safwen / Should fail (4771ms)

OpHash :  ooeXt7h7WrTsWNhFvwM4MJngD4pWb6eoCiLyDw3GmztBG1WkQU3
โœ“ Admin adds Safwen in whitelst contract (77621ms)

MESSAGE STATEMENT:  whitelist does not exist
โœ“ Assert Transfer between: Two existing users with sender s whitelistID don t refer to an existing whitelist - Fred tries to transfer 3 euroTz to Safwen / Should fail (3318ms)

OpHash:  op6oNdbhSAKixx795dQrogrDC9hzKYJissrJVBZbVeZ4Ldij8Kf
โœ“ Admin sets Safwen s whitelist outbound unrestricted (106412ms)

OpHash:  oobQx7dVeYVtTBs9WSSiBBD4onMQPcHcXwCSwc1nJgDqL7a9hU6
โœ“ Admin sets Fred s whitelist outbound restricted (61054ms)

MESSAGE STATEMENT:  outbound restricted
โœ“ Assert Transfer between: Two existing users while sender is restricted -  Fred tries to transfer 3 euroTz to Safwen / Should fail (3590ms)

OpHash :  ooYvVeAkfasz18E7F935WYeG1B5Ur9RgjHWhJr4ohqtAoxPtDHD
โœ“ Admin sets Fred s whitelist outbound unrestricted and contains Safwen (31729ms)

euroTzTrasnferOpHash :  oorXEA6UpHcQhaFYp51sT11SYf6mpDMbvYDXKfwGawbUDEe5fKP
โœ“ Assert Transfer between: Two existing users, sender and receiver are unrestricted, receiver s whitelistID is in the sender s whitelist - Fred transfers 3 euroTz to Safwen / Should succeed (22084ms)

15 passing (8m)
โœจ  Done in 507.14s.
    yarn test-assertTrasnfers # Test assertTrasnfers entryPoint

Test Output:

Whitelist Smart Contract: AssertTrasnfers Operation Testing


MESSAGE STATEMENT:  user not on a whitelist
โœ“ Assert list of transfers with one inexistent sender / Should fail (4333ms)

MESSAGE STATEMENT:  user not on a whitelist
โœ“ Assert list of transfers with one inexistent receiver / Should fail (2927ms)

OpHash :  opTmp7RmzQS3BypxzahgsjtzemypbLVXiepgsNGgXHqzJGLwecg
โœ“ Admin adds Daly to users big_map in whitelist contract (16347ms)

MESSAGE STATEMENT:  whitelist does not exist
โœ“ Assert list of transfers with one sender s whitelistID don t refer to an existing whitelist / Should fail (3160ms)

OpHash:  oo9HkTbzfvffz8Zi6Avj4rAXqDysC4TtnpcDZt3zEde4vGKRQxU
โœ“ Admin sets Daly s whitelist outbound restricted (25520ms)

MESSAGE STATEMENT:  outbound restricted
โœ“ Assert list of transfers with one restricted sender & restricted receiver / Should fail (2629ms)

OpHash:  op5s6LJTAPrBZ5FvDvNz5KC1V3mpHquef2N5BYP5deFhi5c6FLG
โœ“ Admin sets Daly s whitelist outbound unrestricted (74910ms)

MESSAGE STATEMENT:  outbound not whitelisted
โœ“ Assert list of transfers with one transfer where the receiver s whitelistID is not in the sender s whitelist / Should fail (2550ms)

OpHash:  opEixE7d7tZF9XUcBP7ob6fSj91ifiYm4g4CBuFe43sszKK1TdP
โœ“ Admin adds Thib to Daly s whitelist (34924ms)

OpHash:  oo7ss2kbjivZvchJKRUWdyDGa5LTCJ6Ditb5jFUX6h7wj6pCWVS
โœ“ Assert list of transfers: all senders & receivers are existing and unrestricted, all receivers are whitelisted in the senders' whitelists / Should succeed (2662ms)

10 passing (8m) 
โœจ  Done in 490.57s.

๐Ÿ‘ฎ Roles:

  1. Admin: the contract's owner and manager, he can:

    โ€ข Set a new contract's admin;

    โ€ข Set a new contract's issuer;

    โ€ข Add / Update / Delete any user in the users big_map;

    โ€ข Add / Update / Delete any whitelist in the whitelists big_map.

  2. Issuer:

    โ€ข Can't be explicitly added to users;

    โ€ข Is always unrestricted;

    โ€ข Whose allowedWhitelists is the set of ALL whitelistId's

๐Ÿ”— Implementations

  • An implementation of wrapping and non-wrapping forms in Lorentz may be found here

  • A partial implementation of the compile-time wrapping form in LIGO may be found here

Last updated