{"id":25249532,"url":"https://github.com/provable-things/token-swap","last_synced_at":"2025-09-08T19:34:56.505Z","repository":{"id":49234445,"uuid":"367027127","full_name":"provable-things/token-swap","owner":"provable-things","description":"A simple smart-contract to swap a token.","archived":false,"fork":false,"pushed_at":"2021-06-22T15:03:28.000Z","size":221,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T21:43:52.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/provable-things.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-13T11:26:47.000Z","updated_at":"2021-07-05T09:20:49.000Z","dependencies_parsed_at":"2022-09-19T03:21:25.456Z","dependency_job_id":null,"html_url":"https://github.com/provable-things/token-swap","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/provable-things/token-swap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/provable-things%2Ftoken-swap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/provable-things%2Ftoken-swap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/provable-things%2Ftoken-swap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/provable-things%2Ftoken-swap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/provable-things","download_url":"https://codeload.github.com/provable-things/token-swap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/provable-things%2Ftoken-swap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274231435,"owners_count":25245585,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-02-12T03:22:26.746Z","updated_at":"2025-09-08T19:34:56.465Z","avatar_url":"https://github.com/provable-things.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#  :arrows_counterclockwise: __`pLotto \u003c-\u003e Lotto`__ Token Swap Contract MVP\n\nThis repo demonstrates the simple method by which a given ERC777 __`pToken`__ may be swapped for a __`Lotto`__ token. This allows the __`Lotto`__ token to be bridged to other blockchains without changing the overall total supply. Using a swapping contract such as this decouples the __`pLotto`__ \u0026 __`Lotto`__ tokens entirely, allowing each to remain under the purview of their respective owners.\n\n\u0026nbsp;\n\n## :arrow_right: Peg-In Details\n\n - There are __TWO__ ways a user can end up with __`Lotto`__ tokens on the destination chain:\n\n 1) __Via a ONE step process:__ Using __`pTokens`__ metadata, the user can encode the destination address to which they want their destination-chain __`Lotto`__ tokens minted to. They then simply peg-in their origin-chain __`Lotto`__ tokens __TO THE `TOKEN_SWAP_CONTRACT`__, which contract then decodes the __`pTokens`__ metadata and mints the tokens to the desired address. To see this in action, inspect the following test:\n\n ```\n\n// File: ./test/token-swap.test.js\n  it('Should peg-in via a single transaction')\n\n ```\n\n 2) __Via a TWO step process:__ The user uses the pToken bridge to move __`Lotto`__ tokens from the origin chain, result in them owning __`pLotto`__ tokens on the destination chain. They then send their __`pLotto`__ tokens to the __`TOKEN_SWAP`__ contract, resulting in their __`pLotto`__ tokens being swapped to __`Lotto`__ tokens on the destination chain. To see this in action, inspect the following test:\n\n ```\n\n// File: ./test/token-swap.test.js\nit('Should peg-in via two transactions')\n\n ```\n\u0026nbsp;\n\n## :arrow_left: Peg-Out Details\n\n - There are __TWO__ ways a user can peg-out end up back with __`Lotto`__ tokens on the origin-chain:\n\n 1) __Via a ONE step process:__ The user calls the __`redeemOriginChainLottoTokens`__ function in the __`Lotto`__ contract. This function first checks the caller has sufficient balance of the __`Lotto`__ token before calling __`redeemOriginChainLottoTokens`__ in the __`TOKEN_SWAP`__ contract. Which latter function can __only__ be called by the __`Lotto`__ contract, and which function first burns the __`_amount`__ of __`Lotto`__ tokens before calling __`redeem`__ on the `pLotto`__ contract for that same amount of tokens. This results in burning of those __`pLotto`__ tokens, and the emitting of the __`redeem`__ event. The __`pToken bridge`__ witness this event and completes the peg-out to the origin chain. To see this in action, inspect the following test:\n\n ```\n\n// File: ./test/token-swap.test.js\n  it('Should peg-out via a single transaction')\n\n ```\n\n 2) __Via a TWO step process:__ The user uses the __`TOKEN_SWAP`__ contract to redeem an __`_amount`__ of __`pLotto`__ tokens, which process burns the equivalent amount of __`Lotto`__ tokens. The user can then call __`redeem`__ on the __`TOKEN_SWAP`__ contract for up to that same __`_amount`__ of tokens, which function will burn them and emit the __`redeem`__ event which the __`pToken brige`__ sees and acts upon to complete the peg-out to the origin chain. To see this in action, inspect the following test:\n\n ```\n\n// File: ./test/token-swap.test.js\nit('Should peg-out via two transactions')\n\n ```\n\u0026nbsp;\n\n## :clipboard: Notes:\n\n- Notice how the __`./contracts/ILOTTO.sol`__ interface shows the minimum set of methods the __`Lotto`__ contract would need to implement in order to work with the __`TOKEN_SWAP`__ contract. A sample implementation can be seen in __`./contracts/LOTTO.sol`__.\n\n- The __`./contracts/PTOKEN.sol`__ contract is a trimmed down \u0026 non-upgradeable facsimile of the actual __`pToken`__ implementation [that can be seen here](https://github.com/provable-things/ptokens-erc777-smart-contract).\n\n\u0026nbsp;\n\n## :guardsman: Smart-Contract Tests:\n\n1) Clone \u0026 enter the repo:\n\n```\n❍  https://github.com/provable-things/token-swap.git \u0026\u0026 cd token-swap\n```\n\n2) Install dependencies:\n\n```\n❍ npm install\n```\n\n3) Start truffle via:\n\n```\n❍ npx truffle develop\n```\n\n4) Run the tests via:\n\n```\n❍ truffle_develop\u003e test\n```\n\nTest output:\n\n```\n\n  Contract: TOKEN_SWAP\n    Administrative tests:\n      ✓ `OWNER_ADDRESS` can set Lotto contract (1609ms)\n      ✓ `NON_OWNER_ADDRESS` cannot set Lotto contract (1482ms)\n      ✓ `OWNER_ADDRESS` can set pLotto contract (1403ms)\n      ✓ `NON_OWNER_ADDRESS` cannot set pLotto contract (1312ms)\n      ✓ `OWNER_ADDRESS` can renounce ownership (2263ms)\n      ✓ `NON_OWNER_ADDRESS` cannot renounce ownership (1882ms)\n      ✓ Non `LOTTO_ADDRESS` cannot call `redeemOriginChainLotto` function (266ms)\n    Token swapping tests:\n      ONE-STEP peg-in/peg-out tests:\n        ✓ Should peg-in via a single transaction (1649ms)\n        ✓ Should peg-out via a single transaction: (2889ms)\n      TWO-STEP peg-in/peg-out tests:\n        ✓ Should peg-in via two transactions (1883ms)\n        ✓ Should peg out via two transactions (830ms)\n      Misc token-swapping tests:\n        ✓ Sending ERC777 tokens other than `pLOTTO` to the `TOKEN_SWAP` contract should revert (464ms)\n        ✓ Redeeming `pLotto` tokens will burn `Lotto` tokens (518ms)\n\n  13 passing (1m)\n\n```\n\n\u0026nbsp;\n\n\n## :clipboard: To Do:\n\n- [ ]\n\n\u0026nbsp;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprovable-things%2Ftoken-swap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprovable-things%2Ftoken-swap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprovable-things%2Ftoken-swap/lists"}