{"id":13338199,"url":"https://github.com/button-tech/ton-async-payments-channel","last_synced_at":"2026-02-10T12:02:18.951Z","repository":{"id":98851186,"uuid":"215361234","full_name":"button-tech/ton-async-payments-channel","owner":"button-tech","description":"Async implementation of TON payments channel","archived":false,"fork":false,"pushed_at":"2020-01-17T21:07:50.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T08:38:07.869Z","etag":null,"topics":["blockchain","contest","lightning-network","telegram","ton"],"latest_commit_sha":null,"homepage":null,"language":null,"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/button-tech.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-15T17:47:16.000Z","updated_at":"2020-01-17T21:07:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"b4ff4946-28fe-4dc6-9b66-a956b5c48bec","html_url":"https://github.com/button-tech/ton-async-payments-channel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/button-tech/ton-async-payments-channel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/button-tech%2Fton-async-payments-channel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/button-tech%2Fton-async-payments-channel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/button-tech%2Fton-async-payments-channel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/button-tech%2Fton-async-payments-channel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/button-tech","download_url":"https://codeload.github.com/button-tech/ton-async-payments-channel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/button-tech%2Fton-async-payments-channel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29298525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T10:40:02.018Z","status":"ssl_error","status_checked_at":"2026-02-10T10:38:28.459Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["blockchain","contest","lightning-network","telegram","ton"],"created_at":"2024-07-29T19:15:37.293Z","updated_at":"2026-02-10T12:02:18.179Z","avatar_url":"https://github.com/button-tech.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async payment channel for TON\n\nOur team made a sync channel with all wrappers. However, we did not finished yet with the same wrappers to async channel, we decided to apply only with funC smart contract and docs about it.\n\n# Description\n\n### State \n\n\n| Variables |  Size    |       Description           |\n|-----------|----------|-----------------------------|\n| init      |  1 bit   | flag to initialize contract |\n| timeout   | 32 bits  | timeout in second for exit  |\n| timestamp | 48 bits  | unix time in seconds        |\n| pubkA     | 256 bits | pub key of user A           |\n| pubkB     | 256 bits | pub key of user B           |\n| fA        |   1 bit  | flag registry for A         |\n| fB        |   1 bit  | flag registry for B         |\n| X_a       | 214 bits | nanograms registry for A    |\n| X_b       | 214 bits | nanograms registry for B    |\n\nThe total size is 1023 and it is enough to store in 1 Cell.\n214 bits is enough to rotate all balance of TON network for 5e45 times, so, it is safe.\n\n### State evolution\n\n#### Deploy\n\nThe first the state is (0, timeout, 0, pubkA, pubkB, 0, 0, 0, 0)\n\n#### Setup\n\n##### Onchain\n\nUsers can deposit and withdraw grams and store intermediate values into X_a and X_b.\n\n##### Offchain\n\nUsers decide, which amounts __U_a__ and __U_b__ each user needs to deposit to open the channel and which shares __a__ and __b__ will belong to each user as initial.\n\nAt first, A sign and send to B `signed(A, (contract_address, b/2))` and B send to A `signed(B, (contract_address, a/2))`, where __c=a+b__\n\nAfter that A and B sign both and exchanges with`(contract_address, 0, U_a, U_b)`\n\n##### Onchain\n\nAny user send to the contract `(contract_address, U_a, U_b)`, the contract checks, that __X_a__ and __X_b__ more or equal then __U_a__ and __U_b__, after that __init__ flag is set to __1__, remained grams returns to owners, __X_a__ and __X_b__ set to zero.\n\n#### Protocol\n\nEach user stores current value for coins received by another user. When the user needs to send some more value, the user signs new integral value of all amount received by the counterparty as `signed(user, (contract_address, message_code, x))` and send the data to another party.\nThe procedure is unblockable. Technically, the total user's balance may become negative. We consider negative balance as zero balance.\n\n#### Closing\n\nLet's user A decide to close the channel.\n\n* A send to the protocol tuple of separately signed values `(X_a, X_b)` into the contract. The contract set __X_a__, __X_b__, __timestamp:=now+timeout__, and set __F_b:=1__. This means two things:\n    * __F_b__ is fixed and nobody can change it\n    * if anybody preset signed by A __F_b__ more then presented by A, the contract send all money to B.\n\n* B can process the same procedure with one restriction. Both values sent by B must be more or equal than the same sent by A.\n\n\n* If __now \u003e timestamp || F_a \u0026\u0026 F_b__, the contract provide withdrawal procedure for the users.\n\n#### Withdrawal\n\n```\n# Consider C is the total amount, A and B value for users A and B to withdraw\n\na := min(C, max(0, X_a - X_b + C/2))\nb := C - a\n\n```\n\n### Force exit\n\nSend to special method the message (contract_address, exit_code, a), signed by both users, the contract send `a` and `total_amount-a` grams to receivers and close the channel.\n\n# Requirements\n\n- have `func` and `fift` available in `$PATH`\n- have ton lite node running\n- have wallets for Alice and Bob\n- have `alice.addr`, `alice.pk`, `bob.addr`, `bob.pk` in the current dir\n\n# Deployment\n\n- `func stdlib.fc lightning.fc \u003e lightning.fif` - this file is already commited to the repo\n- `./deploy.fif \u003calice addr\u003e \u003cbob addr\u003e \u003cchallenge timeout in sec\u003e`\n- send some test grams to the displayed address\n- in ton node `sendfile deploy.boc`\n\n# Notes\n\nSee [test](./test) dir for more usage examples. It demonstrates work of all functions.\n\nyou can compile using `stdlib_test.fc` to replace `my_address()` and `get_balance()` calls with mocks but \nunfortunately it does not work for `now()` because if compiler bug (function name collides with its opcode), you'll need to disable those calls in code manually to avoid errors.\n\n# Authors\nNick Kozlov - CTO and Co-founder of BUTTON Wallet (@enormousrage, nk@buttonwallet.com)\n\nKirill Kuznecov - Co-founder of BUTTON Wallet (@krboktv, kk@buttonwallet.com)\n\nAlexey Prazdnikov - Fullstack developer at BUTTON Wallet (@noprazd, ap@buttonwallet.com)\n\nMax Spiridonov - Lead Backend developer at BUTTON Wallet (@maxSpt, ms@buttonwallet.com)\n\nIvan Frolov - Backend developer at BUTTON Wallet (@ivnkhh, if@buttonwallet.com)\n\nArtem Vorobev - Lead Developer at BUTTON Wallet ( @artall64 artem@buttonwallet.com )\n\nRoman Semenov - One of founders of Copperbits community, co-author of Tornado.cash Ethereum mixer (@poma, semenov.roma@gmail.com)\n\nIgor Gulamov Blockchain Researcher and Entrepreneur (@igor_gulamov, igor.gulamov@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbutton-tech%2Fton-async-payments-channel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbutton-tech%2Fton-async-payments-channel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbutton-tech%2Fton-async-payments-channel/lists"}