{"id":20049007,"url":"https://github.com/unlock-protocol/discount-hook","last_synced_at":"2025-05-05T10:31:46.342Z","repository":{"id":107046269,"uuid":"586919552","full_name":"unlock-protocol/discount-hook","owner":"unlock-protocol","description":"A Hook for the Unlock Protocol locks that lets lock manager add discount codes.","archived":false,"fork":false,"pushed_at":"2025-04-26T00:13:51.000Z","size":233,"stargazers_count":3,"open_issues_count":11,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-26T01:21:09.746Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unlock-protocol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-09T14:41:52.000Z","updated_at":"2023-12-14T03:36:51.000Z","dependencies_parsed_at":"2024-01-11T00:59:10.286Z","dependency_job_id":"9297859a-5603-4711-aa62-e2a78468a56f","html_url":"https://github.com/unlock-protocol/discount-hook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlock-protocol%2Fdiscount-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlock-protocol%2Fdiscount-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlock-protocol%2Fdiscount-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unlock-protocol%2Fdiscount-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unlock-protocol","download_url":"https://codeload.github.com/unlock-protocol/discount-hook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252480529,"owners_count":21754787,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T11:47:56.419Z","updated_at":"2025-05-05T10:31:44.790Z","avatar_url":"https://github.com/unlock-protocol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Discount Hook for Locks\n\nThis project implements an Unlock [PublicLock Hook](https://docs.unlock-protocol.com/core-protocol/public-lock/hooks) that can be used on Locks smart contracts to support a discount code or coupon.\n\nThis process is _secured_ and cannot be bypassed by calling the contract directly as the discount code is used to submit the transaction on-chain.\n\nWhen the user enters a discount code on the frontend application, it is used to generate a private key that is then used to sign the recipient's address. That signature is passed as the data argument on the `purchase` call.\n\nA lock manager can add any number of discount code to their lock by calling the function `setDiscountCodeForLock` multiple times.\n\nThe Unlock Protocol team has deployed and verified a version of this hook on the following networks:\n\nProduction networks:\n\n- [Optimism: `0x8e0B46ec3B95c81355175693dA0083b00fCc1326`](https://optimistic.etherscan.io/address/0x8e0B46ec3B95c81355175693dA0083b00fCc1326)\n- [Polygon: `0x93E160838c529873cB7565106bBb79a3226FE07A`](https://polygonscan.com/address/0x93E160838c529873cB7565106bBb79a3226FE07A)\n\nTest networks:\n\n- [Goerli: `0x850c015A6A88756a59Dc025fca988494fF90DBB7`](https://goerli.etherscan.io/address/0x850c015A6A88756a59Dc025fca988494fF90DBB7)\n\n## Example\n\n[This example lock](https://goerli.etherscan.io/address/0x2490f447fdb7b259bc454871806b6b794de65944) is deployed on Goerli and uses this discount hook with 2 different discounts:\n\n- `FRIENDS` for a 50% discount\n- `FAMILY` for a 100% discount\n\nThis means if you purchase a key [through this checkout URL](https://app.unlock-protocol.com/checkout?paywallConfig=%7B%22locks%22%3A%7B%220x2490f447fdb7b259bc454871806b6b794de65944%22%3A%7B%22network%22%3A5%2C%22name%22%3A%22%22%2C%22captcha%22%3Afalse%2C%22password%22%3Afalse%2C%22promo%22%3Atrue%2C%22emailRequired%22%3Afalse%2C%22maxRecipients%22%3Anull%2C%22dataBuilder%22%3A%22%22%2C%22skipRecipient%22%3Afalse%7D%7D%2C%22pessimistic%22%3Atrue%2C%22skipRecipient%22%3Atrue%2C%22title%22%3A%22Try+Discounts%21%22%2C%22icon%22%3A%22%22%7D) and enter any of the 2 discount codes you will see a discounted price on the final confirmation screen!\n\nIf you don't enter a discount code, you will pay the full price of 0.01 Eth.\n\n## Using the hook for your own lock\n\n1. First, you need to generate promo codes, then [go to this page to generate the corresponding signer address](https://unlock-protocol.github.io/discount-hook/). You can also generate this locally if needed by checking out the repo and switching to the `gh-page` branch. \n\n\u003cimg width=\"1044\" alt=\"Screen Shot 2023-01-09 at 12 55 04 PM\" src=\"https://user-images.githubusercontent.com/17735/211374963-b9fc6999-50ce-4e91-8ae4-4a5a55db91e8.png\"\u003e\n\n\n2. Then, click on the network your lock has been deployed on (list above) and head to `Contract` \u003e `Write Contract`. Connect your wallet (you need to be connected as one of the lock's manager) and click on `setDiscountForLock`. There, enter the lock address, and then the signer address generated in the previous step and the discount amount to be applied. Since the EVM does not support floating numbers, you have to enter the discount percentage in [basis points](https://en.wikipedia.org/wiki/Basis_point). For example for a 100% discount, you would enter `10000`. For a 3% discount, you would enter `300`.\n\n\u003cimg width=\"696\" alt=\"Screen Shot 2023-01-09 at 12 56 45 PM\" src=\"https://user-images.githubusercontent.com/17735/211375263-029bfd0a-a421-4188-b329-b664819bf5e4.png\"\u003e\n\n3. After that, you need to point your lock to the hook. You can do that by going to your lock's settings page on the Unlock Dashboard. Then check the Advanced tab and the Hooks section.  Add the address of the key purchase hook for the network your lock is deployed on. You can find a list of all the key purchase hook addresses listed above (and please get in touch with us if you need it to be deployed on more networks).\n\n\u003cimg width=\"1266\" alt=\"Screen Shot 2023-01-09 at 12 57 19 PM\" src=\"https://user-images.githubusercontent.com/17735/211375358-c00fecba-d4e5-46d9-a8cb-2ab00aec9731.png\"\u003e\n\n4. Finally, [build a Checkout URL](https://unlock-protocol.com/blog/checkout-builder-release) and make sure you tick `Promo Codes` option for the lock to which you are applying a discount!\n\n\u003cimg width=\"751\" alt=\"Screen Shot 2023-01-09 at 12 57 52 PM\" src=\"https://user-images.githubusercontent.com/17735/211375444-f59089c9-c320-4c3f-8db0-c85a15836466.png\"\u003e\n\n\n## Dev\n\nYou can deploy the hook on other chains by adding the chain to the `hardhat.config.js` config file and calling:\n\n```\nyarn run hardhat run scripts/deploy.js --network my-network\n```\n\nTo verify the contract on block explorers, call :\n\n```\nyarn run hardhat verify --network my-network 0xhook-address\n```\n\nRunning tests:\n\n```\nyarn run hardhat test test/sample-test.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funlock-protocol%2Fdiscount-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funlock-protocol%2Fdiscount-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funlock-protocol%2Fdiscount-hook/lists"}