├── .circleci └── config.yml ├── .commitlintrc.js ├── .editorconfig ├── .eslintignore ├── .gitattributes ├── .gitignore ├── .huskyrc ├── .prettierignore ├── .prettierrc ├── .solcover.js ├── .solhint.json ├── .solhintignore ├── LICENSE.md ├── README.md ├── babel.config.js ├── lerna.json ├── package.json ├── packages ├── dev-utils │ ├── .eslintrc │ ├── README.md │ ├── package.json │ └── src │ │ ├── chaiPlugin.js │ │ ├── constants.js │ │ ├── errors.js │ │ ├── index.js │ │ └── mochaContexts.js ├── protocol │ ├── .env.example │ ├── .eslintrc │ ├── README.md │ ├── contracts │ │ ├── Migrations.sol │ │ ├── Sablier.sol │ │ ├── Types.sol │ │ ├── interfaces │ │ │ └── ISablier.sol │ │ └── test │ │ │ └── Imports.sol │ ├── migrations │ │ ├── 1_initial_migration.js │ │ └── 2_deploy_sablier.js │ ├── package.json │ ├── scripts │ │ ├── coverage.sh │ │ └── test.sh │ ├── test │ │ ├── .eslintrc │ │ ├── sablier │ │ │ ├── Sablier.behavior.js │ │ │ ├── Sablier.js │ │ │ ├── effects │ │ │ │ └── stream │ │ │ │ │ ├── CancelStream.js │ │ │ │ │ ├── CreateStream.js │ │ │ │ │ └── WithdrawFromStream.js │ │ │ └── view │ │ │ │ ├── BalanceOf.js │ │ │ │ ├── DeltaOf.js │ │ │ │ └── GetStream.js │ │ └── setup.js │ └── truffle-config.js └── shared-contracts │ ├── README.md │ ├── compound │ └── CarefulMath.sol │ ├── mocks │ └── ERC20Mock.sol │ ├── package.json │ └── test │ ├── EvilERC20.sol │ └── NonStandardERC20.sol └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.0 2 | 3 | jobs: 4 | build: 5 | working_directory: ~/repo 6 | docker: 7 | - image: cimg/node:16.20 8 | steps: 9 | - checkout 10 | - run: 11 | name: Change git protocol 12 | command: git config --global url."https://".insteadOf git:// 13 | - run: 14 | name: "Install Dependencies" 15 | command: yarn install 16 | - run: 17 | name: "Build Packages" 18 | command: yarn build 19 | - save_cache: 20 | key: repo-{{ .Environment.CIRCLE_SHA1 }} 21 | paths: 22 | - ~/repo 23 | lint: 24 | working_directory: ~/repo 25 | docker: 26 | - image: cimg/node:16.20 27 | steps: 28 | - restore_cache: 29 | keys: 30 | - repo-{{ .Environment.CIRCLE_SHA1 }} 31 | - run: 32 | name: "Lint Packages" 33 | command: yarn lint 34 | - run: 35 | name: "Prettier Check" 36 | command: yarn prettier:ci 37 | test: 38 | working_directory: ~/repo 39 | docker: 40 | - image: cimg/node:16.20 41 | - image: trufflesuite/ganache-cli:v6.5.1 42 | command: ganache-cli -i 1234 -p 8545 -e 10000000 -l 6721975 43 | steps: 44 | - restore_cache: 45 | keys: 46 | - repo-{{ .Environment.CIRCLE_SHA1 }} 47 | - run: 48 | name: "Test Packages" 49 | command: yarn test 50 | coverage: 51 | working_directory: ~/repo 52 | docker: 53 | - image: cimg/node:16.20 54 | - image: trufflesuite/ganache-cli:v6.5.1 55 | command: ganache-cli -i 1234 -p 8545 -e 10000000 -l 6721975 56 | steps: 57 | - restore_cache: 58 | keys: 59 | - repo-{{ .Environment.CIRCLE_SHA1 }} 60 | - run: 61 | name: "Cover Packages" 62 | command: yarn coverage 63 | - run: 64 | name: "Merge Results and Upload to Coveralls" 65 | command: 'yarn lcov-result-merger "packages/**/coverage/lcov.info"| yarn coveralls' 66 | workflows: 67 | version: 2 68 | main: 69 | jobs: 70 | - build 71 | - lint: 72 | requires: 73 | - build 74 | - test: 75 | requires: 76 | - build 77 | - coverage: 78 | requires: 79 | - lint 80 | - test 81 | -------------------------------------------------------------------------------- /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["@commitlint/config-conventional", "@commitlint/config-lerna-scopes"], 3 | }; 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # All files 7 | [*] 8 | charset = utf-8 9 | end_of_line = lf 10 | indent_size = 4 11 | indent_style = space 12 | insert_final_newline = true 13 | trim_trailing_whitespace = true 14 | 15 | # Css 16 | [*.css] 17 | indent_size=2 18 | 19 | # GraphQL 20 | [*.graphql] 21 | indent_size=2 22 | 23 | # HTML 24 | [*.html] 25 | indent_size=2 26 | 27 | # JavaScript 28 | [*.{js,jsx}] 29 | indent_size=2 30 | 31 | # Scss 32 | [*.scss] 33 | indent_size=2 34 | 35 | # Yaml 36 | [*.{yaml,yml}] 37 | indent_size=2 38 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # folders 2 | artifacts/ 3 | build/ 4 | coverage/ 5 | lib/ 6 | node_modules/ 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol diff linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .coverage_artifacts/ 3 | .coverage_contracts/ 4 | .nyc_output/ 5 | .openzeppelin/dev-*.json 6 | .openzeppelin/.session 7 | artifacts/ 8 | build/ 9 | coverage/ 10 | coverageEnv/ 11 | lib/ 12 | node_modules/ 13 | 14 | # files 15 | .env 16 | *.log 17 | coverage.json 18 | lerna-debug.log* 19 | npm-debug.log* 20 | scTopics 21 | yarn-debug.log* 22 | yarn-error.log* 23 | -------------------------------------------------------------------------------- /.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .nyc_output/ 3 | artifacts/ 4 | build/ 5 | coverage/ 6 | coverageEnv/ 7 | lib/ 8 | node_modules/ 9 | packages/shared-contracts/compound/ 10 | 11 | # files 12 | coverage.json 13 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSpacing": true, 4 | "printWidth": 120, 5 | "singleQuote": false, 6 | "tabWidth": 2, 7 | "trailingComma": "all", 8 | "overrides": [ 9 | { 10 | "files": "*.sol", 11 | "options": { 12 | "tabWidth": 4 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | skipFiles: ["compound", "contracts/Migrations.sol", "interfaces", "mocks", "test"], 3 | }; 4 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:default", 3 | "plugins": [], 4 | "rules": { 5 | "indent": ["error", 4], 6 | "bracket-align": "off", 7 | "compiler-fixed": "off", 8 | "function-max-lines": "off", 9 | "no-complex-fallback": "off", 10 | "no-empty-blocks": "off", 11 | "no-inline-assembly": "off", 12 | "no-simple-event-func-name": "off", 13 | "separate-by-one-line-in-contract": "off", 14 | "two-lines-top-level-separator": "off" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2024 Sablier 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and`show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sablier Legacy [![CircleCI](https://circleci.com/gh/sablier-labs/legacy-contracts.svg?style=svg)](https://circleci.com/gh/sablier-labs/legacy-contracts) [![Coverage Status](https://coveralls.io/repos/github/sablier-labs/legacy-contracts/badge.svg?branch=develop)](https://coveralls.io/github/sablier-labs/legacy-contracts?branch=develop) [![Styled with Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io) [![Commitizen Friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) [![License: LGPL3.0](https://img.shields.io/badge/License-LGPL%20v3-008033.svg)](https://opensource.org/licenses/lgpl-3.0) 2 | 3 | This is the source code of the Sablier Legacy protocol, which has been superseded by [Sablier Lockup](https://github.com/sablier-labs/v2-core). For more details about how Sablier works, check out our docs at [docs.sablier.com](https://docs.sablier.com). 4 | 5 | This repo is structured as a monorepo: 6 | 7 | | Package | Description | 8 | | --------------------------------------------------------- | ----------------------------------------------------------------- | 9 | | [`@sablier/dev-utils`](/packages/dev-utils) | Dev utils to be shared across Sablier projects and packages | 10 | | [`@sablier/protocol`](/packages/protocol) | The core token streaming protocol | 11 | | [`@sablier/shared-contracts`](/packages/shared-contracts) | Smart contracts to be shared across Sablier projects and packages | 12 | 13 | ## Usage :hammer_and_pick: 14 | 15 | To compile the smart contracts, bootstrap the monorepo and open the package you'd like to work on. For example, here are the instructions for `@sablier/protocol`: 16 | 17 | ```bash 18 | $ yarn run bootstrap 19 | $ cd packages/protocol 20 | $ truffle compile --all 21 | $ truffle migrate --reset --network development 22 | ``` 23 | 24 | Alternatively, if you simply want to use the UI, head to 25 | [legacy-recipient.sablier.com](https://legacy-recipient.sablier.com) to withdraw from streams. 26 | 27 | ## Contributing :raising_hand_woman: 28 | 29 | Participation from the community is crucial for shaping the future development of Sablier. If you are interested in 30 | contributing or have any questions, ping us on [Discord](https://discord.gg/KXajCXC). 31 | 32 | We use [Yarn](https://yarnpkg.com/) as a dependency manager and [Truffle](https://github.com/trufflesuite/truffle) 33 | as a development environment for compiling, testing, and deploying our contracts. The contracts were written in [Solidity](https://github.com/ethereum/solidity). 34 | 35 | ### Requirements 36 | 37 | - yarn >=1.17.3 38 | - truffle >= 5.0.35 39 | - solidity 0.5.17 40 | 41 | ### Pre Requisites 42 | 43 | Make sure you are using Yarn >=1.17.3. 44 | 45 | ```bash 46 | $ npm install --global yarn 47 | ``` 48 | 49 | Then, install dependencies: 50 | 51 | ```bash 52 | $ yarn install 53 | ``` 54 | 55 | ### Watch 56 | 57 | To re-build all packages on change: 58 | 59 | ```bash 60 | $ yarn watch 61 | ``` 62 | 63 | ### Clean 64 | 65 | To clean all packages: 66 | 67 | ```bash 68 | $ yarn clean 69 | ``` 70 | 71 | To clean a specific package: 72 | 73 | ```bash 74 | $ PKG=@sablier/protocol yarn clean 75 | ``` 76 | 77 | ### Lint 78 | 79 | To lint all packages: 80 | 81 | ```bash 82 | $ yarn lint 83 | ``` 84 | 85 | To lint a specific package: 86 | 87 | ```bash 88 | $ PKG=@sablier/protocol yarn lint 89 | ``` 90 | 91 | ### Prettier 92 | 93 | To run prettier on all packages: 94 | 95 | ```bash 96 | $ yarn prettier 97 | ``` 98 | 99 | Prettier cannot be run on individual packages. 100 | 101 | ### Test 102 | 103 | To run all tests: 104 | 105 | ```bash 106 | $ yarn test 107 | ``` 108 | 109 | To run tests in a specific package: 110 | 111 | ```bash 112 | $ PKG=@sablier/protocol yarn test 113 | ``` 114 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ["@babel/env"], 3 | plugins: ["@babel/plugin-transform-runtime", "@babel/plugin-proposal-object-rest-spread"], 4 | }; 5 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "3.13.1", 3 | "packages": ["packages/*"], 4 | "version": "independent", 5 | "npmClient": "yarn", 6 | "useWorkspaces": true 7 | } 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sablier", 3 | "devDependencies": { 4 | "@commitlint/cli": "7.5.2", 5 | "@commitlint/config-conventional": "7.5.0", 6 | "@commitlint/config-lerna-scopes": "7.5.1", 7 | "commitizen": "^3.1.2", 8 | "coveralls": "^3.0.6", 9 | "cz-conventional-changelog": "^2.1.0", 10 | "husky": "^1.3.1", 11 | "lcov-result-merger": "^3.1.0", 12 | "lerna": "^3.13.1", 13 | "prettier": "^1.16.4", 14 | "shx": "^0.3.2", 15 | "wsrun": "^3.6.4" 16 | }, 17 | "license": "LGPL-3.0", 18 | "private": true, 19 | "scripts": { 20 | "bootstrap": "yarn install && yarn build", 21 | "build": "lerna link && yarn wsrun --package $PKG --recursive --stages -c build", 22 | "clean": "yarn wsrun --package $PKG --parallel -c clean", 23 | "clean:node_modules": "lerna clean --yes; shx rm -rf node_modules", 24 | "commit": "git-cz", 25 | "coverage": "yarn wsrun --package $PKG --serial -c coverage", 26 | "lerna": "lerna", 27 | "lint": "yarn wsrun --package $PKG --parallel -c lint && yarn prettier:ci", 28 | "prettier": "prettier --config .prettierrc --write '**/*.{js,json,jsx,md,sol,ts,tsx}'", 29 | "prettier:ci": "prettier --config .prettierrc --list-different '**/*.{js,json,jsx,md,sol,ts,tsx}'", 30 | "test": "yarn wsrun --package $PKG --serial -c test", 31 | "watch": "yarn wsrun --package $PKG --parallel -c watch", 32 | "wsrun": "wsrun --exclude-missing --fast-exit" 33 | }, 34 | "workspaces": { 35 | "packages": [ 36 | "packages/*" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/dev-utils/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | }, 5 | "extends": ["airbnb-base", "@paulrberg/eslint-config"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/dev-utils/README.md: -------------------------------------------------------------------------------- 1 | ## Dev Utils 2 | 3 | Dev utils to be shared across Sablier projects and packages. 4 | 5 | ## Usage 6 | 7 | Install the module: 8 | 9 | ```bash 10 | $ yarn add @sablier/dev-utils 11 | ``` 12 | 13 | And import it in your project: 14 | 15 | ```js 16 | const sablierDevUtils = require("@sablier/dev-utils"); 17 | ``` 18 | 19 | ## Contributing 20 | 21 | We highly encourage participation from the community to help shape the development of Sablier. If you are interested in 22 | contributing or have any questions, please ping us on [Discord](https://discord.gg/bSwRCwWRsT). 23 | 24 | ### Install Modules 25 | 26 | ```bash 27 | $ yarn install 28 | ``` 29 | 30 | ### Build 31 | 32 | ```bash 33 | $ yarn build 34 | ``` 35 | 36 | ### Lint 37 | 38 | ```bash 39 | $ yarn lint 40 | ``` 41 | 42 | ### Clean 43 | 44 | ```bash 45 | $ yarn clean 46 | ``` 47 | -------------------------------------------------------------------------------- /packages/dev-utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sablier/dev-utils", 3 | "description": "Dev utils to be shared across Sablier packages", 4 | "version": "1.1.0", 5 | "author": { 6 | "name": "Sablier", 7 | "email": "contact@sablier.com", 8 | "url": "https://sablier.com" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/sablier-labs/legacy-contracts/issues" 12 | }, 13 | "dependencies": { 14 | "bignumber.js": "^9.0.0" 15 | }, 16 | "devDependencies": { 17 | "@babel/cli": "^7.5.5", 18 | "@babel/core": "^7.5.5", 19 | "@babel/plugin-proposal-object-rest-spread": "^7.4.0", 20 | "@babel/plugin-transform-runtime": "^7.6.0", 21 | "@babel/preset-env": "^7.5.5", 22 | "@babel/runtime": "^7.7.6", 23 | "@paulrberg/eslint-config": "1.0.0", 24 | "eslint": "^6.1.0", 25 | "eslint-config-airbnb-base": "^14.0.0", 26 | "eslint-config-prettier": "^6.7.0", 27 | "eslint-plugin-import": "^2.18.2", 28 | "mocha": "^6.2.0", 29 | "shx": "^0.3.2" 30 | }, 31 | "files": [ 32 | "/lib" 33 | ], 34 | "homepage": "https://github.com/sablier-labs/legacy-contracts/tree/develop/packages/dev-utils#readme", 35 | "license": "LGPL-3.0", 36 | "main": "./lib", 37 | "publishConfig": { 38 | "access": "public" 39 | }, 40 | "repository": { 41 | "type": "git", 42 | "url": "https://github.com/sablier-labs/legacy-contracts.git", 43 | "directory": "packages/dev-utils" 44 | }, 45 | "scripts": { 46 | "build": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src", 47 | "clean": "shx rm -rf ./lib", 48 | "lint": "eslint --ignore-path ../../.eslintignore .", 49 | "watch": "yarn build --watch" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/dev-utils/src/chaiPlugin.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names, no-else-return, no-param-reassign */ 2 | const BigNumber = require("bignumber.js"); 3 | 4 | const devConstants = require("./constants"); 5 | 6 | module.exports = (chai, _utils) => { 7 | // See https://twitter.com/nicksdjohnson/status/1132394932361023488 8 | const convert = value => { 9 | let number; 10 | 11 | if (typeof value === "string" || typeof value === "number") { 12 | number = new BigNumber(value); 13 | } else if (BigNumber.isBigNumber(value)) { 14 | number = value; 15 | } else { 16 | new chai.Assertion(value).assert(false, `expected ${value} to be an instance of string, number or BigNumber`); 17 | } 18 | 19 | return number; 20 | }; 21 | 22 | /** 23 | * Performs a boundary check instead of an equality check. In real life circumstances, it can take up to 14 seconds 24 | * for a block to be broadcast on the Ethereum network, so we have to account for this. 25 | * 26 | * Note that we make two assumptions: 27 | * 28 | * 1. The payment rate is 1 token/ second, which is true for all tests in this repo. 29 | * 2. By default, the token has 18 decimals 30 | */ 31 | chai.Assertion.addMethod("tolerateTheBlockTimeVariation", function( 32 | expected, 33 | scale = devConstants.STANDARD_SCALE, 34 | tolerateByAddition = true, 35 | ) { 36 | const actual = convert(this._obj); 37 | expected = convert(expected); 38 | scale = convert(scale); 39 | 40 | const blockTimeAverage = new BigNumber(14).multipliedBy(scale); 41 | if (tolerateByAddition) { 42 | const expectedCeiling = expected.plus(blockTimeAverage); 43 | 44 | return this.assert( 45 | actual.isGreaterThanOrEqualTo(expected) && actual.isLessThanOrEqualTo(expectedCeiling), 46 | `expected ${actual.toString()} to be >= than ${expected.toString()} and <= ${expectedCeiling.toString()}`, 47 | ); 48 | } else { 49 | const expectedFloor = expected.minus(blockTimeAverage); 50 | 51 | return this.assert( 52 | actual.isLessThanOrEqualTo(expected) && actual.isGreaterThanOrEqualTo(expectedFloor), 53 | `expected ${actual.toString()} to be <= than ${expected.toString()} and >= ${expectedFloor.toString()}`, 54 | ); 55 | } 56 | }); 57 | }; 58 | -------------------------------------------------------------------------------- /packages/dev-utils/src/constants.js: -------------------------------------------------------------------------------- 1 | const BigNumber = require("bignumber.js"); 2 | 3 | const STANDARD_SALARY = new BigNumber(3600).multipliedBy(1e18); 4 | 5 | module.exports = { 6 | FIVE_UNITS: new BigNumber(5).multipliedBy(1e18), 7 | GAS_LIMIT: 6721975, 8 | INITIAL_SUPPLY: STANDARD_SALARY.multipliedBy(1000), 9 | ONE_UNIT: new BigNumber(1).multipliedBy(1e18), 10 | RPC_URL: "http://127.0.0.1:8545", 11 | RPC_PORT: 8545, 12 | STANDARD_RATE_PER_SECOND: new BigNumber(1).multipliedBy(1e18), 13 | STANDARD_RECIPIENT_SHARE_PERCENTAGE: new BigNumber(50), 14 | STANDARD_SABLIER_FEE: new BigNumber(10), 15 | STANDARD_SALARY, 16 | STANDARD_SCALE: new BigNumber(1e18), 17 | STANDARD_TIME_DELTA: new BigNumber(3600), 18 | STANDARD_TIME_OFFSET: new BigNumber(300), 19 | ZERO_ADDRESS: "0x0000000000000000000000000000000000000000", 20 | }; 21 | -------------------------------------------------------------------------------- /packages/dev-utils/src/errors.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | AUTH_BOTH: "only the sender or the recipient of the stream can perform this action", 3 | AUTH_RECIPIENT: "only the stream recipient is allowed to perform this action", 4 | AUTH_SENDER: "only the stream sender is allowed to perform this action", 5 | BLOCK_DELTA: "the block difference needs to be higher than the payment interval", 6 | BLOCK_DELTA_MULTIPLICITY: "the block difference needs to be a multiple of the payment interval", 7 | BLOCK_START: "the start block needs to be higher than the current block number", 8 | BLOCK_STOP: "the stop block needs to be higher than the start block", 9 | CONTRACT_ALLOWANCE: "contract not allowed to transfer enough tokens", 10 | CONTRACT_EXISTENCE: "token contract address needs to be provided", 11 | INSOLVENCY: "not enough funds", 12 | STREAM_EXISTENCE: "stream doesn't exist", 13 | TERMS_NOT_CHANGED: "stream has these terms already", 14 | }; 15 | -------------------------------------------------------------------------------- /packages/dev-utils/src/index.js: -------------------------------------------------------------------------------- 1 | const chaiPlugin = require("./chaiPlugin"); 2 | const devConstants = require("./constants"); 3 | const errors = require("./errors"); 4 | const mochaContexts = require("./mochaContexts"); 5 | 6 | module.exports = { 7 | chaiPlugin, 8 | devConstants, 9 | errors, 10 | mochaContexts, 11 | }; 12 | -------------------------------------------------------------------------------- /packages/dev-utils/src/mochaContexts.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable func-names */ 2 | /* global afterEach, beforeEach, describe */ 3 | const BigNumber = require("bignumber.js"); 4 | const dayjs = require("dayjs"); 5 | const traveler = require("ganache-time-traveler"); 6 | 7 | const devConstants = require("./constants"); 8 | 9 | const { STANDARD_TIME_OFFSET, STANDARD_TIME_DELTA } = devConstants; 10 | 11 | function contextForStreamDidStartButNotEnd(functions) { 12 | const now = new BigNumber(dayjs().unix()); 13 | 14 | describe("when the stream did start but not end", function() { 15 | beforeEach(async function() { 16 | await traveler.advanceBlockAndSetTime( 17 | now 18 | .plus(STANDARD_TIME_OFFSET) 19 | .plus(5) 20 | .toNumber(), 21 | ); 22 | }); 23 | 24 | functions(); 25 | 26 | afterEach(async function() { 27 | await traveler.advanceBlockAndSetTime(now.toNumber()); 28 | }); 29 | }); 30 | } 31 | 32 | function contextForStreamDidEnd(functions) { 33 | const now = new BigNumber(dayjs().unix()); 34 | 35 | describe("when the stream did end", function() { 36 | beforeEach(async function() { 37 | await traveler.advanceBlockAndSetTime( 38 | now 39 | .plus(STANDARD_TIME_OFFSET) 40 | .plus(STANDARD_TIME_DELTA) 41 | .plus(5) 42 | .toNumber(), 43 | ); 44 | }); 45 | 46 | functions(); 47 | 48 | afterEach(async function() { 49 | await traveler.advanceBlockAndSetTime(now.toNumber()); 50 | }); 51 | }); 52 | } 53 | 54 | module.exports = { 55 | contextForStreamDidStartButNotEnd, 56 | contextForStreamDidEnd, 57 | }; 58 | -------------------------------------------------------------------------------- /packages/protocol/.env.example: -------------------------------------------------------------------------------- 1 | INFURA_API_KEY=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 2 | MNEMONIC=here is where your twelve words mnemonic should be put my friend 3 | -------------------------------------------------------------------------------- /packages/protocol/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "node": true 4 | }, 5 | "extends": ["airbnb-base", "@paulrberg/eslint-config"] 6 | } 7 | -------------------------------------------------------------------------------- /packages/protocol/README.md: -------------------------------------------------------------------------------- 1 | ## Contracts 2 | 3 | This package contains the Ethereum smart contracts for the Sablier protocol. We use [Truffle](https://github.com/trufflesuite/truffle) 4 | as a development environment for compiling, testing, and deploying our contracts. They were written in [Solidity](https://github.com/ethereum/solidity). 5 | 6 | ## Pre Requisites 7 | 8 | ```bash 9 | $ yarn global add truffle 10 | $ yarn global add ganache-cli 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```bash 16 | truffle compile --all 17 | truffle migrate --network development 18 | ``` 19 | 20 | Make sure to have a running [Ganache](https://truffleframework.com/ganache) instance in the background. 21 | 22 | ## Contributing 23 | 24 | We highly encourage participation from the community to help shape the development of Sablier. If you are interested in 25 | contributing or have any questions, please ping us on [Discord](https://discord.gg/bSwRCwWRsT). 26 | 27 | ### Install Modules 28 | 29 | ```bash 30 | $ yarn install 31 | ``` 32 | 33 | ### Clean 34 | 35 | ```bash 36 | $ yarn clean 37 | ``` 38 | 39 | ### Lint 40 | 41 | ```bash 42 | $ yarn lint 43 | ``` 44 | 45 | ### Test 46 | 47 | ```bash 48 | $ yarn test 49 | ``` 50 | 51 | ### Coverage 52 | 53 | ```bash 54 | $ yarn coverage 55 | ``` 56 | -------------------------------------------------------------------------------- /packages/protocol/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint256 public lastCompletedMigration; 6 | 7 | modifier restricted() { 8 | if (msg.sender == owner) { 9 | _; 10 | } 11 | } 12 | 13 | constructor() public { 14 | owner = msg.sender; 15 | } 16 | 17 | function setCompleted(uint256 _completed) public restricted { 18 | lastCompletedMigration = _completed; 19 | } 20 | 21 | function upgrade(address _newAddress) public restricted { 22 | Migrations upgraded = Migrations(_newAddress); 23 | upgraded.setCompleted(lastCompletedMigration); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/protocol/contracts/Sablier.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 5 | import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; 6 | import "@sablier/shared-contracts/compound/CarefulMath.sol"; 7 | 8 | import "./interfaces/ISablier.sol"; 9 | import "./Types.sol"; 10 | 11 | /** 12 | * @title Sablier 13 | * @author Sablier 14 | * @notice Money streaming. 15 | */ 16 | contract Sablier is ISablier, ReentrancyGuard, CarefulMath { 17 | using SafeERC20 for IERC20; 18 | 19 | /*** Storage Properties ***/ 20 | 21 | /** 22 | * @notice Counter for new stream ids. 23 | */ 24 | uint256 public nextStreamId; 25 | 26 | /** 27 | * @notice The stream objects identifiable by their unsigned integer ids. 28 | */ 29 | mapping(uint256 => Types.Stream) private streams; 30 | 31 | /*** Modifiers ***/ 32 | 33 | /** 34 | * @dev Throws if the caller is not the sender of the recipient of the stream. 35 | */ 36 | modifier onlySenderOrRecipient(uint256 streamId) { 37 | require( 38 | msg.sender == streams[streamId].sender || msg.sender == streams[streamId].recipient, 39 | "caller is not the sender or the recipient of the stream" 40 | ); 41 | _; 42 | } 43 | 44 | /** 45 | * @dev Throws if the provided id does not point to a valid stream. 46 | */ 47 | modifier streamExists(uint256 streamId) { 48 | require(streams[streamId].isEntity, "stream does not exist"); 49 | _; 50 | } 51 | 52 | /*** Contract Logic Starts Here */ 53 | 54 | constructor() public { 55 | nextStreamId = 100000; 56 | } 57 | 58 | /*** View Functions ***/ 59 | 60 | /** 61 | * @notice Returns the stream with all its properties. 62 | * @dev Throws if the id does not point to a valid stream. 63 | * @param streamId The id of the stream to query. 64 | * @return The stream object. 65 | */ 66 | function getStream(uint256 streamId) 67 | external 68 | view 69 | streamExists(streamId) 70 | returns ( 71 | address sender, 72 | address recipient, 73 | uint256 deposit, 74 | address tokenAddress, 75 | uint256 startTime, 76 | uint256 stopTime, 77 | uint256 remainingBalance, 78 | uint256 ratePerSecond 79 | ) 80 | { 81 | sender = streams[streamId].sender; 82 | recipient = streams[streamId].recipient; 83 | deposit = streams[streamId].deposit; 84 | tokenAddress = streams[streamId].tokenAddress; 85 | startTime = streams[streamId].startTime; 86 | stopTime = streams[streamId].stopTime; 87 | remainingBalance = streams[streamId].remainingBalance; 88 | ratePerSecond = streams[streamId].ratePerSecond; 89 | } 90 | 91 | /** 92 | * @notice Returns either the delta in seconds between `block.timestamp` and `startTime` or 93 | * between `stopTime` and `startTime, whichever is smaller. If `block.timestamp` is before 94 | * `startTime`, it returns 0. 95 | * @dev Throws if the id does not point to a valid stream. 96 | * @param streamId The id of the stream for which to query the delta. 97 | * @return The time delta in seconds. 98 | */ 99 | function deltaOf(uint256 streamId) public view streamExists(streamId) returns (uint256 delta) { 100 | Types.Stream memory stream = streams[streamId]; 101 | if (block.timestamp <= stream.startTime) return 0; 102 | if (block.timestamp < stream.stopTime) return block.timestamp - stream.startTime; 103 | return stream.stopTime - stream.startTime; 104 | } 105 | 106 | struct BalanceOfLocalVars { 107 | MathError mathErr; 108 | uint256 recipientBalance; 109 | uint256 withdrawalAmount; 110 | uint256 senderBalance; 111 | } 112 | 113 | /** 114 | * @notice Returns the available funds for the given stream id and address. 115 | * @dev Throws if the id does not point to a valid stream. 116 | * @param streamId The id of the stream for which to query the balance. 117 | * @param who The address for which to query the balance. 118 | * @return The total funds allocated to `who` as uint256. 119 | */ 120 | function balanceOf(uint256 streamId, address who) public view streamExists(streamId) returns (uint256 balance) { 121 | Types.Stream memory stream = streams[streamId]; 122 | BalanceOfLocalVars memory vars; 123 | 124 | uint256 delta = deltaOf(streamId); 125 | (vars.mathErr, vars.recipientBalance) = mulUInt(delta, stream.ratePerSecond); 126 | require(vars.mathErr == MathError.NO_ERROR, "recipient balance calculation error"); 127 | 128 | /* 129 | * If the stream `balance` does not equal `deposit`, it means there have been withdrawals. 130 | * We have to subtract the total amount withdrawn from the amount of money that has been 131 | * streamed until now. 132 | */ 133 | if (stream.deposit > stream.remainingBalance) { 134 | (vars.mathErr, vars.withdrawalAmount) = subUInt(stream.deposit, stream.remainingBalance); 135 | assert(vars.mathErr == MathError.NO_ERROR); 136 | (vars.mathErr, vars.recipientBalance) = subUInt(vars.recipientBalance, vars.withdrawalAmount); 137 | /* `withdrawalAmount` cannot and should not be bigger than `recipientBalance`. */ 138 | assert(vars.mathErr == MathError.NO_ERROR); 139 | } 140 | 141 | if (who == stream.recipient) return vars.recipientBalance; 142 | if (who == stream.sender) { 143 | (vars.mathErr, vars.senderBalance) = subUInt(stream.remainingBalance, vars.recipientBalance); 144 | /* `recipientBalance` cannot and should not be bigger than `remainingBalance`. */ 145 | assert(vars.mathErr == MathError.NO_ERROR); 146 | return vars.senderBalance; 147 | } 148 | return 0; 149 | } 150 | 151 | /*** Public Effects & Interactions Functions ***/ 152 | 153 | struct CreateStreamLocalVars { 154 | MathError mathErr; 155 | uint256 duration; 156 | uint256 ratePerSecond; 157 | } 158 | 159 | /** 160 | * @notice Creates a new stream funded by `msg.sender` and paid towards `recipient`. 161 | * @dev Throws if the recipient is the zero address, the contract itself or the caller. 162 | * Throws if the deposit is 0. 163 | * Throws if the start time is before `block.timestamp`. 164 | * Throws if the stop time is before the start time. 165 | * Throws if the duration calculation has a math error. 166 | * Throws if the deposit is smaller than the duration. 167 | * Throws if the deposit is not a multiple of the duration. 168 | * Throws if the rate calculation has a math error. 169 | * Throws if the next stream id calculation has a math error. 170 | * Throws if the contract is not allowed to transfer enough tokens. 171 | * Throws if there is a token transfer failure. 172 | * @param recipient The address towards which the money is streamed. 173 | * @param deposit The amount of money to be streamed. 174 | * @param tokenAddress The ERC20 token to use as streaming currency. 175 | * @param startTime The unix timestamp for when the stream starts. 176 | * @param stopTime The unix timestamp for when the stream stops. 177 | * @return The uint256 id of the newly created stream. 178 | */ 179 | function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime) 180 | public 181 | returns (uint256) 182 | { 183 | require(recipient != address(0x00), "stream to the zero address"); 184 | require(recipient != address(this), "stream to the contract itself"); 185 | require(recipient != msg.sender, "stream to the caller"); 186 | require(deposit > 0, "deposit is zero"); 187 | require(startTime >= block.timestamp, "start time before block.timestamp"); 188 | require(stopTime > startTime, "stop time before the start time"); 189 | 190 | CreateStreamLocalVars memory vars; 191 | (vars.mathErr, vars.duration) = subUInt(stopTime, startTime); 192 | /* `subUInt` can only return MathError.INTEGER_UNDERFLOW but we know `stopTime` is higher than `startTime`. */ 193 | assert(vars.mathErr == MathError.NO_ERROR); 194 | 195 | /* Without this, the rate per second would be zero. */ 196 | require(deposit >= vars.duration, "deposit smaller than time delta"); 197 | 198 | /* This condition avoids dealing with remainders */ 199 | require(deposit % vars.duration == 0, "deposit not multiple of time delta"); 200 | 201 | (vars.mathErr, vars.ratePerSecond) = divUInt(deposit, vars.duration); 202 | /* `divUInt` can only return MathError.DIVISION_BY_ZERO but we know `duration` is not zero. */ 203 | assert(vars.mathErr == MathError.NO_ERROR); 204 | 205 | /* Create and store the stream object. */ 206 | uint256 streamId = nextStreamId; 207 | streams[streamId] = Types.Stream({ 208 | remainingBalance: deposit, 209 | deposit: deposit, 210 | isEntity: true, 211 | ratePerSecond: vars.ratePerSecond, 212 | recipient: recipient, 213 | sender: msg.sender, 214 | startTime: startTime, 215 | stopTime: stopTime, 216 | tokenAddress: tokenAddress 217 | }); 218 | 219 | /* Increment the next stream id. */ 220 | (vars.mathErr, nextStreamId) = addUInt(nextStreamId, uint256(1)); 221 | require(vars.mathErr == MathError.NO_ERROR, "next stream id calculation error"); 222 | 223 | IERC20(tokenAddress).safeTransferFrom(msg.sender, address(this), deposit); 224 | emit CreateStream(streamId, msg.sender, recipient, deposit, tokenAddress, startTime, stopTime); 225 | return streamId; 226 | } 227 | 228 | /** 229 | * @notice Withdraws from the contract to the recipient's account. 230 | * @dev Throws if the id does not point to a valid stream. 231 | * Throws if the caller is not the sender or the recipient of the stream. 232 | * Throws if the amount exceeds the available balance. 233 | * Throws if there is a token transfer failure. 234 | * @param streamId The id of the stream to withdraw tokens from. 235 | * @param amount The amount of tokens to withdraw. 236 | */ 237 | function withdrawFromStream(uint256 streamId, uint256 amount) 238 | external 239 | nonReentrant 240 | streamExists(streamId) 241 | onlySenderOrRecipient(streamId) 242 | returns (bool) 243 | { 244 | require(amount > 0, "amount is zero"); 245 | Types.Stream memory stream = streams[streamId]; 246 | 247 | uint256 balance = balanceOf(streamId, stream.recipient); 248 | require(balance >= amount, "amount exceeds the available balance"); 249 | 250 | MathError mathErr; 251 | (mathErr, streams[streamId].remainingBalance) = subUInt(stream.remainingBalance, amount); 252 | /** 253 | * `subUInt` can only return MathError.INTEGER_UNDERFLOW but we know that `remainingBalance` is at least 254 | * as big as `amount`. 255 | */ 256 | assert(mathErr == MathError.NO_ERROR); 257 | 258 | if (streams[streamId].remainingBalance == 0) delete streams[streamId]; 259 | 260 | IERC20(stream.tokenAddress).safeTransfer(stream.recipient, amount); 261 | emit WithdrawFromStream(streamId, stream.recipient, amount); 262 | return true; 263 | } 264 | 265 | /** 266 | * @notice Cancels the stream and transfers the tokens back on a pro rata basis. 267 | * @dev Throws if the id does not point to a valid stream. 268 | * Throws if the caller is not the sender or the recipient of the stream. 269 | * Throws if there is a token transfer failure. 270 | * @param streamId The id of the stream to cancel. 271 | * @return bool true=success, otherwise false. 272 | */ 273 | function cancelStream(uint256 streamId) 274 | external 275 | nonReentrant 276 | streamExists(streamId) 277 | onlySenderOrRecipient(streamId) 278 | returns (bool) 279 | { 280 | Types.Stream memory stream = streams[streamId]; 281 | uint256 senderBalance = balanceOf(streamId, stream.sender); 282 | uint256 recipientBalance = balanceOf(streamId, stream.recipient); 283 | 284 | delete streams[streamId]; 285 | 286 | IERC20 token = IERC20(stream.tokenAddress); 287 | if (recipientBalance > 0) token.safeTransfer(stream.recipient, recipientBalance); 288 | if (senderBalance > 0) token.safeTransfer(stream.sender, senderBalance); 289 | 290 | emit CancelStream(streamId, stream.sender, stream.recipient, senderBalance, recipientBalance); 291 | return true; 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /packages/protocol/contracts/Types.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | /** 4 | * @title Sablier Types 5 | * @author Sablier 6 | */ 7 | library Types { 8 | struct Stream { 9 | uint256 deposit; 10 | uint256 ratePerSecond; 11 | uint256 remainingBalance; 12 | uint256 startTime; 13 | uint256 stopTime; 14 | address recipient; 15 | address sender; 16 | address tokenAddress; 17 | bool isEntity; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/protocol/contracts/interfaces/ISablier.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.17; 2 | 3 | /** 4 | * @title ISablier 5 | * @author Sablier 6 | */ 7 | interface ISablier { 8 | /** 9 | * @notice Emits when a stream is successfully created. 10 | */ 11 | event CreateStream( 12 | uint256 indexed streamId, 13 | address indexed sender, 14 | address indexed recipient, 15 | uint256 deposit, 16 | address tokenAddress, 17 | uint256 startTime, 18 | uint256 stopTime 19 | ); 20 | 21 | /** 22 | * @notice Emits when the recipient of a stream withdraws a portion or all their pro rata share of the stream. 23 | */ 24 | event WithdrawFromStream(uint256 indexed streamId, address indexed recipient, uint256 amount); 25 | 26 | /** 27 | * @notice Emits when a stream is successfully cancelled and tokens are transferred back on a pro rata basis. 28 | */ 29 | event CancelStream( 30 | uint256 indexed streamId, 31 | address indexed sender, 32 | address indexed recipient, 33 | uint256 senderBalance, 34 | uint256 recipientBalance 35 | ); 36 | 37 | function balanceOf(uint256 streamId, address who) external view returns (uint256 balance); 38 | 39 | function getStream(uint256 streamId) 40 | external 41 | view 42 | returns ( 43 | address sender, 44 | address recipient, 45 | uint256 deposit, 46 | address token, 47 | uint256 startTime, 48 | uint256 stopTime, 49 | uint256 remainingBalance, 50 | uint256 ratePerSecond 51 | ); 52 | 53 | function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime) 54 | external 55 | returns (uint256 streamId); 56 | 57 | function withdrawFromStream(uint256 streamId, uint256 funds) external returns (bool); 58 | 59 | function cancelStream(uint256 streamId) external returns (bool); 60 | } 61 | -------------------------------------------------------------------------------- /packages/protocol/contracts/test/Imports.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol"; 4 | import "@sablier/shared-contracts/mocks/ERC20Mock.sol"; 5 | import "@sablier/shared-contracts/test/EvilERC20.sol"; 6 | import "@sablier/shared-contracts/test/NonStandardERC20.sol"; 7 | 8 | // You might think this file is a bit odd, but let me explain. 9 | // We only use some contracts in our tests, which means Truffle 10 | // will not compile it for us, because it is from an external 11 | // dependency. 12 | // 13 | // We are now left with three options: 14 | // - Copy/paste these contracts 15 | // - Run the tests with `truffle compile --all` on 16 | // - Or trick Truffle by claiming we use it in a Solidity test 17 | // 18 | // You know which one I went for. 19 | 20 | contract Imports { 21 | constructor() public {} 22 | } 23 | -------------------------------------------------------------------------------- /packages/protocol/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | /* global artifacts */ 2 | const Migrations = artifacts.require("./Migrations.sol"); 3 | 4 | module.exports = async deployer => { 5 | await deployer.deploy(Migrations); 6 | }; 7 | -------------------------------------------------------------------------------- /packages/protocol/migrations/2_deploy_sablier.js: -------------------------------------------------------------------------------- 1 | /* global artifacts, web3 */ 2 | const BigNumber = require("bignumber.js"); 3 | 4 | const ERC20Mock = artifacts.require("./ERC20Mock.sol"); 5 | const Sablier = artifacts.require("./Sablier.sol"); 6 | 7 | module.exports = async (deployer, network, accounts) => { 8 | await deployer.deploy(Sablier); 9 | const sablier = await Sablier.deployed(); 10 | if (network !== "development") { 11 | return; 12 | } 13 | 14 | const allowance = new BigNumber(3600).multipliedBy(1e18).toString(10); 15 | 16 | await deployer.deploy(ERC20Mock); 17 | const erc20 = await ERC20Mock.deployed(); 18 | await erc20.mint(accounts[0], allowance); 19 | await erc20.approve(sablier.address, allowance, { from: accounts[0] }); 20 | 21 | const recipient = accounts[1]; 22 | const deposit = allowance; 23 | const tokenAddress = erc20.address; 24 | const { timestamp } = await web3.eth.getBlock("latest"); 25 | const startTime = new BigNumber(timestamp).plus(300); 26 | const stopTime = startTime.plus(3600); 27 | 28 | await sablier.createStream(recipient, deposit, tokenAddress, startTime, stopTime, { from: accounts[0] }); 29 | }; 30 | -------------------------------------------------------------------------------- /packages/protocol/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sablier/protocol", 3 | "description": "The Sablier token streaming protocol", 4 | "version": "1.1.0", 5 | "author": { 6 | "name": "Sablier", 7 | "email": "contact@sablier.com", 8 | "url": "https://sablier.com" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/sablier-labs/legacy-contracts/issues" 12 | }, 13 | "dependencies": { 14 | "@openzeppelin/contracts": "2.3.0" 15 | }, 16 | "devDependencies": { 17 | "@paulrberg/eslint-config": "1.0.0", 18 | "@sablier/dev-utils": "1.1.0", 19 | "@sablier/shared-contracts": "1.1.0", 20 | "@truffle/hdwallet-provider": "^1.5.0", 21 | "bignumber.js": "8.1.1", 22 | "chai": "^4.2.0", 23 | "chai-bignumber": "3.0.0", 24 | "dayjs": "^1.8.15", 25 | "dotenv": "^7.0.0", 26 | "eslint": "^6.1.0", 27 | "eslint-config-airbnb-base": "^14.0.0", 28 | "eslint-config-prettier": "^6.7.0", 29 | "eslint-plugin-import": "^2.18.2", 30 | "ethers": "^4.0.45", 31 | "ganache-cli": "6.5.1", 32 | "ganache-time-traveler": "^1.0.5", 33 | "istanbul": "^0.4.5", 34 | "prettier-plugin-solidity": "^1.0.0-alpha.34", 35 | "shx": "^0.3.2", 36 | "solc": "0.5.17", 37 | "solhint": "^2.1.2", 38 | "solidity-coverage": "0.7.0-beta.0", 39 | "truffle": "^5.5.3", 40 | "truffle-assertions": "^0.8.2", 41 | "web3": "1.2.1" 42 | }, 43 | "files": [ 44 | "/contracts" 45 | ], 46 | "homepage": "https://github.com/sablier-labs/legacy-contracts/tree/develop/packages/protocol#readme", 47 | "license": "LGPL-3.0", 48 | "publishConfig": { 49 | "access": "public" 50 | }, 51 | "repository": { 52 | "type": "git", 53 | "url": "https://github.com/sablier-labs/legacy-contracts.git", 54 | "directory": "packages/protocol" 55 | }, 56 | "resolutions": { 57 | "ethereumjs-abi": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz" 58 | }, 59 | "scripts": { 60 | "clean": "shx rm -rf ./artifacts ./build ./coverage ./coverage.json", 61 | "coverage": "scripts/coverage.sh", 62 | "lint": "yarn lint:js && yarn lint:sol", 63 | "lint:js": "eslint --ignore-path ../../.eslintignore .", 64 | "lint:sol": "solhint --config ../../.solhint.json --max-warnings 0 'contracts/**/*.sol'", 65 | "test": "scripts/test.sh" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /packages/protocol/scripts/coverage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | MODE=coverage scripts/test.sh 6 | 7 | yarn istanbul report html lcov 8 | -------------------------------------------------------------------------------- /packages/protocol/scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Exit script as soon as a command fails. 4 | set -o errexit 5 | 6 | # Executes cleanup function at script exit. 7 | trap cleanup EXIT 8 | 9 | cleanup() { 10 | # Kill the ganache instance that we started (if we started one and if it's still running). 11 | if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then 12 | kill -9 $ganache_pid 13 | fi 14 | } 15 | 16 | ganache_port=8545 17 | 18 | ganache_running() { 19 | nc -z localhost "$ganache_port" 20 | } 21 | 22 | start_ganache() { 23 | if [ "$MODE" = "coverage" ]; then 24 | echo "Using in-process ganache-core provider for coverage" 25 | return 26 | else 27 | npx ganache-cli --gasLimit 0xfffffffffff --networkId 1234 --port "$ganache_port" > /dev/null & 28 | fi 29 | 30 | ganache_pid=$! 31 | 32 | echo "Waiting for ganache to launch on port "$ganache_port"..." 33 | 34 | while ! ganache_running; do 35 | sleep 0.1 # wait for 1/10 of the second before checking again 36 | done 37 | 38 | echo "Ganache launched!" 39 | } 40 | 41 | if ganache_running; then 42 | echo "Using existing ganache instance" 43 | else 44 | echo "Starting our own ganache instance" 45 | start_ganache 46 | fi 47 | 48 | yarn truffle version 49 | 50 | if [ "$MODE" = "coverage" ]; then 51 | yarn truffle run coverage --solcoverjs ../../.solcover.js 52 | else 53 | yarn truffle test "$@" 54 | fi 55 | -------------------------------------------------------------------------------- /packages/protocol/test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true 4 | }, 5 | "extends": ["../.eslintrc"], 6 | "globals": { 7 | "artifacts": true, 8 | "contract": true, 9 | "describe": true, 10 | "it": true, 11 | "web3": true 12 | }, 13 | "rules": { 14 | "func-names": "off", 15 | "prefer-destructuring": "off" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/Sablier.behavior.js: -------------------------------------------------------------------------------- 1 | const shouldBehaveLikeDeltaOf = require("./view/DeltaOf"); 2 | const shouldBehaveLikeBalanceOf = require("./view/BalanceOf"); 3 | const shouldBehaveLikeGetStream = require("./view/GetStream"); 4 | 5 | const shouldBehaveLikeERC1620CreateStream = require("./effects/stream/CreateStream"); 6 | const shouldBehaveLikeERC1620WithdrawFromStream = require("./effects/stream/WithdrawFromStream"); 7 | // eslint-disable-next-line max-len 8 | const shouldBehaveLikeERC1620CancelStream = require("./effects/stream/CancelStream"); 9 | 10 | function shouldBehaveLikeSablier(alice, bob, carol, eve) { 11 | describe("view functions", function() { 12 | describe("getStream", function() { 13 | shouldBehaveLikeGetStream(alice); 14 | }); 15 | 16 | describe("deltaOf", function() { 17 | shouldBehaveLikeDeltaOf(alice, bob); 18 | }); 19 | 20 | describe("balanceOf", function() { 21 | shouldBehaveLikeBalanceOf(alice, bob, carol); 22 | }); 23 | }); 24 | 25 | describe("effects & interactions functions", function() { 26 | describe("createStream", function() { 27 | shouldBehaveLikeERC1620CreateStream(alice, bob); 28 | }); 29 | 30 | describe("withdrawFromStream", function() { 31 | shouldBehaveLikeERC1620WithdrawFromStream(alice, bob, eve); 32 | }); 33 | 34 | describe("cancelStream", function() { 35 | shouldBehaveLikeERC1620CancelStream(alice, bob, eve); 36 | }); 37 | }); 38 | } 39 | 40 | module.exports = shouldBehaveLikeSablier; 41 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/Sablier.js: -------------------------------------------------------------------------------- 1 | const { devConstants } = require("@sablier/dev-utils"); 2 | const shouldBehaveLikeSablier = require("./Sablier.behavior"); 3 | 4 | const ERC20Mock = artifacts.require("./ERC20Mock.sol"); 5 | const NonStandardERC20 = artifacts.require("./NonStandardERC20.sol"); 6 | const Sablier = artifacts.require("./Sablier.sol"); 7 | 8 | ERC20Mock.numberFormat = "BigNumber"; 9 | NonStandardERC20.numberFormat = "BigNumber"; 10 | Sablier.numberFormat = "BigNumber"; 11 | 12 | const { STANDARD_SALARY } = devConstants; 13 | 14 | contract("Sablier", function sablier([alice, bob, carol, eve]) { 15 | beforeEach(async function() { 16 | const opts = { from: alice }; 17 | this.token = await ERC20Mock.new(opts); 18 | await this.token.mint(alice, STANDARD_SALARY.multipliedBy(3).toString(10), opts); 19 | 20 | this.nonStandardERC20Token = await NonStandardERC20.new(opts); 21 | this.nonStandardERC20Token.mint(alice, STANDARD_SALARY.toString(10), opts); 22 | 23 | this.sablier = await Sablier.new(opts); 24 | }); 25 | 26 | shouldBehaveLikeSablier(alice, bob, carol, eve); 27 | }); 28 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/effects/stream/CancelStream.js: -------------------------------------------------------------------------------- 1 | const { devConstants, mochaContexts } = require("@sablier/dev-utils"); 2 | const BigNumber = require("bignumber.js"); 3 | const dayjs = require("dayjs"); 4 | const truffleAssert = require("truffle-assertions"); 5 | 6 | const { FIVE_UNITS, STANDARD_SALARY, STANDARD_SCALE, STANDARD_TIME_OFFSET, STANDARD_TIME_DELTA } = devConstants; 7 | const { contextForStreamDidEnd, contextForStreamDidStartButNotEnd } = mochaContexts; 8 | 9 | function runTests() { 10 | describe("when the stream did not start", function() { 11 | it("cancels the stream", async function() { 12 | await this.sablier.cancelStream(this.streamId, this.opts); 13 | await truffleAssert.reverts(this.sablier.getStream(this.streamId), "stream does not exist"); 14 | }); 15 | 16 | it("transfers all tokens to the sender of the stream", async function() { 17 | const balance = await this.token.balanceOf(this.sender, this.opts); 18 | await this.sablier.cancelStream(this.streamId, this.opts); 19 | const newBalance = await this.token.balanceOf(this.sender, this.opts); 20 | newBalance.should.be.bignumber.equal(balance.plus(this.deposit)); 21 | }); 22 | 23 | it("emits a cancel event", async function() { 24 | const result = await this.sablier.cancelStream(this.streamId, this.opts); 25 | truffleAssert.eventEmitted(result, "CancelStream"); 26 | }); 27 | }); 28 | 29 | contextForStreamDidStartButNotEnd(function() { 30 | const streamedAmount = FIVE_UNITS.toString(10); 31 | 32 | it("cancels the stream", async function() { 33 | await this.sablier.cancelStream(this.streamId, this.opts); 34 | await truffleAssert.reverts(this.sablier.getStream(this.streamId), "stream does not exist"); 35 | }); 36 | 37 | it("transfers the tokens to the sender of the stream", async function() { 38 | const balance = await this.token.balanceOf(this.sender, this.opts); 39 | await this.sablier.cancelStream(this.streamId, this.opts); 40 | const newBalance = await this.token.balanceOf(this.sender, this.opts); 41 | const tolerateByAddition = false; 42 | newBalance.should.tolerateTheBlockTimeVariation( 43 | balance.minus(streamedAmount).plus(this.deposit), 44 | STANDARD_SCALE, 45 | tolerateByAddition, 46 | ); 47 | }); 48 | 49 | it("transfers the tokens to the recipient of the stream", async function() { 50 | const balance = await this.token.balanceOf(this.recipient, this.opts); 51 | await this.sablier.cancelStream(this.streamId, this.opts); 52 | const newBalance = await this.token.balanceOf(this.recipient, this.opts); 53 | newBalance.should.tolerateTheBlockTimeVariation(balance.plus(streamedAmount), STANDARD_SCALE); 54 | }); 55 | 56 | it("emits a cancel event", async function() { 57 | const result = await this.sablier.cancelStream(this.streamId, this.opts); 58 | truffleAssert.eventEmitted(result, "CancelStream"); 59 | }); 60 | }); 61 | 62 | contextForStreamDidEnd(function() { 63 | const streamedAmount = STANDARD_SALARY.toString(10); 64 | 65 | it("cancels the stream", async function() { 66 | await this.sablier.cancelStream(this.streamId, this.opts); 67 | await truffleAssert.reverts(this.sablier.getStream(this.streamId), "stream does not exist"); 68 | }); 69 | 70 | it("transfers nothing to the sender of the stream", async function() { 71 | const balance = await this.token.balanceOf(this.sender, this.opts); 72 | await this.sablier.cancelStream(this.streamId, this.opts); 73 | const newBalance = await this.token.balanceOf(this.sender, this.opts); 74 | newBalance.should.be.bignumber.equal(balance); 75 | }); 76 | 77 | it("transfers all tokens to the recipient of the stream", async function() { 78 | const balance = await this.token.balanceOf(this.recipient, this.opts); 79 | await this.sablier.cancelStream(this.streamId, this.opts); 80 | const newBalance = await this.token.balanceOf(this.recipient, this.opts); 81 | newBalance.should.be.bignumber.equal(balance.plus(streamedAmount)); 82 | }); 83 | 84 | it("emits a cancel event", async function() { 85 | const result = await this.sablier.cancelStream(this.streamId, this.opts); 86 | truffleAssert.eventEmitted(result, "CancelStream"); 87 | }); 88 | }); 89 | } 90 | 91 | function shouldBehaveLikeERC1620CancelStream(alice, bob, eve) { 92 | const now = new BigNumber(dayjs().unix()); 93 | 94 | describe("when the stream exists", function() { 95 | const startTime = now.plus(STANDARD_TIME_OFFSET); 96 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 97 | 98 | beforeEach(async function() { 99 | this.sender = alice; 100 | this.recipient = bob; 101 | this.deposit = STANDARD_SALARY.toString(10); 102 | const opts = { from: this.sender }; 103 | await this.token.approve(this.sablier.address, this.deposit, opts); 104 | const result = await this.sablier.createStream( 105 | this.recipient, 106 | this.deposit, 107 | this.token.address, 108 | startTime, 109 | stopTime, 110 | opts, 111 | ); 112 | this.streamId = Number(result.logs[0].args.streamId); 113 | }); 114 | 115 | describe("when the caller is the sender of the stream", function() { 116 | beforeEach(function() { 117 | this.opts = { from: this.sender }; 118 | }); 119 | 120 | runTests(); 121 | }); 122 | 123 | describe("when the caller is the recipient of the stream", function() { 124 | beforeEach(function() { 125 | this.opts = { from: this.recipient }; 126 | }); 127 | 128 | runTests(); 129 | }); 130 | 131 | describe("when the caller is not the sender or the recipient of the stream", function() { 132 | const opts = { from: eve }; 133 | 134 | it("reverts", async function() { 135 | await truffleAssert.reverts( 136 | this.sablier.cancelStream(this.streamId, opts), 137 | "caller is not the sender or the recipient of the stream", 138 | ); 139 | }); 140 | }); 141 | }); 142 | 143 | describe("when the stream does not exist", function() { 144 | const recipient = bob; 145 | const opts = { from: recipient }; 146 | 147 | it("reverts", async function() { 148 | const streamId = new BigNumber(419863); 149 | await truffleAssert.reverts(this.sablier.cancelStream(streamId, opts), "stream does not exist"); 150 | }); 151 | }); 152 | } 153 | 154 | module.exports = shouldBehaveLikeERC1620CancelStream; 155 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/effects/stream/CreateStream.js: -------------------------------------------------------------------------------- 1 | const { devConstants } = require("@sablier/dev-utils"); 2 | const BigNumber = require("bignumber.js"); 3 | const dayjs = require("dayjs"); 4 | const truffleAssert = require("truffle-assertions"); 5 | 6 | const { 7 | STANDARD_RATE_PER_SECOND, 8 | STANDARD_SALARY, 9 | STANDARD_TIME_OFFSET, 10 | STANDARD_TIME_DELTA, 11 | ZERO_ADDRESS, 12 | } = devConstants; 13 | 14 | function shouldBehaveLikeERC1620Stream(alice, bob) { 15 | const sender = alice; 16 | const opts = { from: sender }; 17 | const now = new BigNumber(dayjs().unix()); 18 | 19 | describe("when the recipient is valid", function() { 20 | const recipient = bob; 21 | 22 | describe("when the token contract is erc20", function() { 23 | describe("when the sablier contract has enough allowance", function() { 24 | beforeEach(async function() { 25 | await this.token.approve(this.sablier.address, STANDARD_SALARY.toString(10), opts); 26 | }); 27 | 28 | describe("when the sender has enough tokens", function() { 29 | describe("when the deposit is valid", function() { 30 | const deposit = STANDARD_SALARY.toString(10); 31 | 32 | describe("when the start time is after block.timestamp", function() { 33 | describe("when the stop time is after the start time", function() { 34 | const startTime = now.plus(STANDARD_TIME_OFFSET); 35 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 36 | 37 | it("creates the stream", async function() { 38 | const result = await this.sablier.createStream( 39 | recipient, 40 | deposit, 41 | this.token.address, 42 | startTime, 43 | stopTime, 44 | opts, 45 | ); 46 | const streamObject = await this.sablier.getStream(Number(result.logs[0].args.streamId)); 47 | streamObject.sender.should.be.equal(sender); 48 | streamObject.recipient.should.be.equal(recipient); 49 | streamObject.deposit.should.be.bignumber.equal(deposit); 50 | streamObject.tokenAddress.should.be.equal(this.token.address); 51 | streamObject.startTime.should.be.bignumber.equal(startTime); 52 | streamObject.stopTime.should.be.bignumber.equal(stopTime); 53 | streamObject.remainingBalance.should.be.bignumber.equal(deposit); 54 | streamObject.ratePerSecond.should.be.bignumber.equal(STANDARD_RATE_PER_SECOND); 55 | }); 56 | 57 | it("transfers the tokens to the contract", async function() { 58 | const balance = await this.token.balanceOf(sender, opts); 59 | await this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts); 60 | const newBalance = await this.token.balanceOf(sender, opts); 61 | newBalance.should.be.bignumber.equal(balance.minus(STANDARD_SALARY)); 62 | }); 63 | 64 | it("increases the stream next stream id", async function() { 65 | const nextStreamId = await this.sablier.nextStreamId(); 66 | await this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts); 67 | const newNextStreamId = await this.sablier.nextStreamId(); 68 | newNextStreamId.should.be.bignumber.equal(nextStreamId.plus(1)); 69 | }); 70 | 71 | it("emits a stream event", async function() { 72 | const result = await this.sablier.createStream( 73 | recipient, 74 | deposit, 75 | this.token.address, 76 | startTime, 77 | stopTime, 78 | opts, 79 | ); 80 | truffleAssert.eventEmitted(result, "CreateStream"); 81 | }); 82 | }); 83 | 84 | describe("when the stop time is not after the start time", function() { 85 | let startTime; 86 | let stopTime; 87 | 88 | beforeEach(async function() { 89 | startTime = now.plus(STANDARD_TIME_OFFSET); 90 | stopTime = startTime; 91 | }); 92 | 93 | it("reverts", async function() { 94 | await truffleAssert.reverts( 95 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 96 | "stop time before the start time", 97 | ); 98 | }); 99 | }); 100 | }); 101 | 102 | describe("when the start time is not after block.timestamp", function() { 103 | let startTime; 104 | let stopTime; 105 | 106 | beforeEach(async function() { 107 | startTime = now.minus(STANDARD_TIME_OFFSET); 108 | stopTime = startTime.plus(STANDARD_TIME_DELTA); 109 | }); 110 | 111 | it("reverts", async function() { 112 | await truffleAssert.reverts( 113 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 114 | "start time before block.timestamp", 115 | ); 116 | }); 117 | }); 118 | }); 119 | 120 | describe("when the deposit is not valid", function() { 121 | const startTime = now.plus(STANDARD_TIME_OFFSET); 122 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 123 | 124 | describe("when the deposit is zero", function() { 125 | const deposit = new BigNumber(0).toString(10); 126 | 127 | it("reverts", async function() { 128 | await truffleAssert.reverts( 129 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 130 | "deposit is zero", 131 | ); 132 | }); 133 | }); 134 | 135 | describe("when the deposit is smaller than the time delta", function() { 136 | const deposit = STANDARD_TIME_DELTA.minus(1).toString(10); 137 | 138 | it("reverts", async function() { 139 | await truffleAssert.reverts( 140 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 141 | "deposit smaller than time delta", 142 | ); 143 | }); 144 | }); 145 | 146 | describe("when the deposit is not a multiple of the time delta", function() { 147 | const deposit = STANDARD_SALARY.plus(5).toString(10); 148 | 149 | it("reverts", async function() { 150 | await truffleAssert.reverts( 151 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 152 | "deposit not multiple of time delta", 153 | ); 154 | }); 155 | }); 156 | }); 157 | }); 158 | 159 | describe("when the sender does not have enough tokens", function() { 160 | const deposit = STANDARD_SALARY.multipliedBy(2).toString(10); 161 | const startTime = now.plus(STANDARD_TIME_OFFSET); 162 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 163 | 164 | it("reverts", async function() { 165 | await truffleAssert.reverts( 166 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 167 | truffleAssert.ErrorType.REVERT, 168 | ); 169 | }); 170 | }); 171 | }); 172 | 173 | describe("when the sablier contract does not have enough allowance", function() { 174 | let startTime; 175 | let stopTime; 176 | 177 | beforeEach(async function() { 178 | startTime = now.plus(STANDARD_TIME_OFFSET); 179 | stopTime = startTime.plus(STANDARD_TIME_DELTA); 180 | await this.token.approve(this.sablier.address, STANDARD_SALARY.minus(5).toString(10), opts); 181 | }); 182 | 183 | describe("when the sender has enough tokens", function() { 184 | const deposit = STANDARD_SALARY.toString(10); 185 | 186 | it("reverts", async function() { 187 | await truffleAssert.reverts( 188 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 189 | truffleAssert.ErrorType.REVERT, 190 | ); 191 | }); 192 | }); 193 | 194 | describe("when the sender does not have enough tokens", function() { 195 | const deposit = STANDARD_SALARY.multipliedBy(2).toString(10); 196 | 197 | it("reverts", async function() { 198 | await truffleAssert.reverts( 199 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 200 | truffleAssert.ErrorType.REVERT, 201 | ); 202 | }); 203 | }); 204 | }); 205 | }); 206 | 207 | describe("when the token contract is not erc20", function() { 208 | const deposit = STANDARD_SALARY.toString(10); 209 | let startTime; 210 | let stopTime; 211 | 212 | beforeEach(async function() { 213 | startTime = now.plus(STANDARD_TIME_OFFSET); 214 | stopTime = startTime.plus(STANDARD_TIME_DELTA); 215 | }); 216 | 217 | describe("when the token contract does not return true on transfer and transferFrom", function() { 218 | beforeEach(async function() { 219 | await this.nonStandardERC20Token.approve(this.sablier.address, STANDARD_SALARY.toString(10), opts); 220 | }); 221 | 222 | it("creates the stream", async function() { 223 | const result = await this.sablier.createStream( 224 | recipient, 225 | deposit, 226 | this.nonStandardERC20Token.address, 227 | startTime, 228 | stopTime, 229 | opts, 230 | ); 231 | const streamObject = await this.sablier.getStream(Number(result.logs[0].args.streamId)); 232 | streamObject.sender.should.be.equal(sender); 233 | streamObject.recipient.should.be.equal(recipient); 234 | streamObject.deposit.should.be.bignumber.equal(deposit); 235 | streamObject.tokenAddress.should.be.equal(this.nonStandardERC20Token.address); 236 | streamObject.startTime.should.be.bignumber.equal(startTime); 237 | streamObject.stopTime.should.be.bignumber.equal(stopTime); 238 | streamObject.remainingBalance.should.be.bignumber.equal(deposit); 239 | streamObject.ratePerSecond.should.be.bignumber.equal(STANDARD_RATE_PER_SECOND); 240 | }); 241 | }); 242 | 243 | describe("when the token contract is the zero address", function() { 244 | it("reverts", async function() { 245 | await truffleAssert.reverts( 246 | this.sablier.createStream(recipient, deposit, ZERO_ADDRESS, startTime, stopTime, opts), 247 | truffleAssert.ErrorType.REVERT, 248 | ); 249 | }); 250 | }); 251 | }); 252 | }); 253 | 254 | describe("when the recipient is the caller itself", function() { 255 | const recipient = sender; 256 | const deposit = STANDARD_SALARY.toString(10); 257 | const startTime = now.plus(STANDARD_TIME_OFFSET); 258 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 259 | 260 | it("reverts", async function() { 261 | await truffleAssert.reverts( 262 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 263 | "stream to the caller", 264 | ); 265 | }); 266 | }); 267 | 268 | describe("when the recipient is the contract itself", function() { 269 | const deposit = STANDARD_SALARY.toString(10); 270 | const startTime = now.plus(STANDARD_TIME_OFFSET); 271 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 272 | 273 | it("reverts", async function() { 274 | // Can't be defined in the context above because "this.sablier" is undefined there 275 | const recipient = this.sablier.address; 276 | 277 | await truffleAssert.reverts( 278 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 279 | "stream to the contract itself", 280 | ); 281 | }); 282 | }); 283 | 284 | describe("when the recipient is the zero address", function() { 285 | const recipient = ZERO_ADDRESS; 286 | const deposit = STANDARD_SALARY.toString(10); 287 | const startTime = now.plus(STANDARD_TIME_OFFSET); 288 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 289 | 290 | it("reverts", async function() { 291 | await truffleAssert.reverts( 292 | this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts), 293 | "stream to the zero address", 294 | ); 295 | }); 296 | }); 297 | } 298 | 299 | module.exports = shouldBehaveLikeERC1620Stream; 300 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/effects/stream/WithdrawFromStream.js: -------------------------------------------------------------------------------- 1 | const { devConstants, mochaContexts } = require("@sablier/dev-utils"); 2 | const BigNumber = require("bignumber.js"); 3 | const dayjs = require("dayjs"); 4 | const truffleAssert = require("truffle-assertions"); 5 | 6 | const { contextForStreamDidEnd, contextForStreamDidStartButNotEnd } = mochaContexts; 7 | const { FIVE_UNITS, STANDARD_SALARY, STANDARD_SCALE, STANDARD_TIME_OFFSET, STANDARD_TIME_DELTA } = devConstants; 8 | 9 | function runTests() { 10 | describe("when the withdrawal amount is higher than 0", function() { 11 | describe("when the stream did not start", function() { 12 | const withdrawalAmount = FIVE_UNITS.toString(10); 13 | 14 | it("reverts", async function() { 15 | await truffleAssert.reverts( 16 | this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts), 17 | "amount exceeds the available balance", 18 | ); 19 | }); 20 | }); 21 | 22 | contextForStreamDidStartButNotEnd(function() { 23 | describe("when the withdrawal amount does not exceed the available balance", function() { 24 | const withdrawalAmount = FIVE_UNITS.toString(10); 25 | 26 | it("withdraws from the stream", async function() { 27 | const balance = await this.token.balanceOf(this.recipient); 28 | await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 29 | const newBalance = await this.token.balanceOf(this.recipient); 30 | newBalance.should.be.bignumber.equal(balance.plus(FIVE_UNITS)); 31 | }); 32 | 33 | it("emits a withdrawfromstream event", async function() { 34 | const result = await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 35 | truffleAssert.eventEmitted(result, "WithdrawFromStream"); 36 | }); 37 | 38 | it("decreases the stream balance", async function() { 39 | const balance = await this.sablier.balanceOf(this.streamId, this.recipient, this.opts); 40 | await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 41 | const newBalance = await this.sablier.balanceOf(this.streamId, this.recipient, this.opts); 42 | // Intuitively, one may say we don't have to tolerate the block time variation here. 43 | // However, the Sablier balance for the recipient can only go up from the bottom 44 | // low of `balance` - `amount`, due to uncontrollable runtime costs. 45 | newBalance.should.tolerateTheBlockTimeVariation(balance.minus(withdrawalAmount), STANDARD_SCALE); 46 | }); 47 | }); 48 | 49 | describe("when the withdrawal amount exceeds the available balance", function() { 50 | const withdrawalAmount = FIVE_UNITS.multipliedBy(2).toString(10); 51 | 52 | it("reverts", async function() { 53 | await truffleAssert.reverts( 54 | this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts), 55 | "amount exceeds the available balance", 56 | ); 57 | }); 58 | }); 59 | }); 60 | 61 | contextForStreamDidEnd(function() { 62 | describe("when the withdrawal amount does not exceed the available balance", function() { 63 | describe("when the balance is not withdrawn in full", function() { 64 | const withdrawalAmount = STANDARD_SALARY.dividedBy(2).toString(10); 65 | 66 | it("withdraws from the stream", async function() { 67 | const balance = await this.token.balanceOf(this.recipient); 68 | await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 69 | const newBalance = await this.token.balanceOf(this.recipient); 70 | newBalance.should.be.bignumber.equal(balance.plus(withdrawalAmount)); 71 | }); 72 | 73 | it("emits a withdrawfromstream event", async function() { 74 | const result = await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 75 | truffleAssert.eventEmitted(result, "WithdrawFromStream"); 76 | }); 77 | 78 | it("decreases the stream balance", async function() { 79 | const balance = await this.sablier.balanceOf(this.streamId, this.recipient); 80 | await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 81 | const newBalance = await this.sablier.balanceOf(this.streamId, this.recipient); 82 | newBalance.should.be.bignumber.equal(balance.minus(withdrawalAmount)); 83 | }); 84 | }); 85 | 86 | describe("when the balance is withdrawn in full", function() { 87 | const withdrawalAmount = STANDARD_SALARY.toString(10); 88 | 89 | it("withdraws from the stream", async function() { 90 | const balance = await this.token.balanceOf(this.recipient); 91 | await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 92 | const newBalance = await this.token.balanceOf(this.recipient); 93 | newBalance.should.be.bignumber.equal(balance.plus(withdrawalAmount)); 94 | }); 95 | 96 | it("emits a withdrawfromstream event", async function() { 97 | const result = await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 98 | truffleAssert.eventEmitted(result, "WithdrawFromStream"); 99 | }); 100 | 101 | it("deletes the stream object", async function() { 102 | await this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts); 103 | await truffleAssert.reverts(this.sablier.getStream(this.streamId), "stream does not exist"); 104 | }); 105 | }); 106 | }); 107 | 108 | describe("when the withdrawal amount exceeds the available balance", function() { 109 | const withdrawalAmount = STANDARD_SALARY.plus(FIVE_UNITS).toString(10); 110 | 111 | it("reverts", async function() { 112 | await truffleAssert.reverts( 113 | this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts), 114 | "amount exceeds the available balance", 115 | ); 116 | }); 117 | }); 118 | }); 119 | }); 120 | 121 | describe("when the withdrawal amount is zero", function() { 122 | const withdrawalAmount = new BigNumber(0).toString(10); 123 | 124 | it("reverts", async function() { 125 | await truffleAssert.reverts( 126 | this.sablier.withdrawFromStream(this.streamId, withdrawalAmount, this.opts), 127 | "amount is zero", 128 | ); 129 | }); 130 | }); 131 | } 132 | 133 | function shouldBehaveLikeERC1620WithdrawFromStream(alice, bob, eve) { 134 | const now = new BigNumber(dayjs().unix()); 135 | 136 | describe("when the stream exists", function() { 137 | const startTime = now.plus(STANDARD_TIME_OFFSET); 138 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 139 | 140 | beforeEach(async function() { 141 | this.sender = alice; 142 | this.recipient = bob; 143 | this.deposit = STANDARD_SALARY.toString(10); 144 | const opts = { from: this.sender }; 145 | await this.token.approve(this.sablier.address, this.deposit, opts); 146 | const result = await this.sablier.createStream( 147 | this.recipient, 148 | this.deposit, 149 | this.token.address, 150 | startTime, 151 | stopTime, 152 | opts, 153 | ); 154 | this.streamId = Number(result.logs[0].args.streamId); 155 | }); 156 | 157 | describe("when the caller is the sender of the stream", function() { 158 | beforeEach(function() { 159 | this.opts = { from: this.sender }; 160 | }); 161 | 162 | runTests(); 163 | }); 164 | 165 | describe("when the caller is the recipient of the stream", function() { 166 | beforeEach(function() { 167 | this.opts = { from: this.recipient }; 168 | }); 169 | 170 | runTests(); 171 | }); 172 | 173 | describe("when the caller is not the sender or the recipient of the stream", function() { 174 | const opts = { from: eve }; 175 | 176 | it("reverts", async function() { 177 | await truffleAssert.reverts( 178 | this.sablier.withdrawFromStream(this.streamId, FIVE_UNITS, opts), 179 | "caller is not the sender or the recipient of the stream", 180 | ); 181 | }); 182 | }); 183 | }); 184 | 185 | describe("when the stream does not exist", function() { 186 | const recipient = bob; 187 | const opts = { from: recipient }; 188 | 189 | it("reverts", async function() { 190 | const streamId = new BigNumber(419863); 191 | await truffleAssert.reverts(this.sablier.withdrawFromStream(streamId, FIVE_UNITS, opts), "stream does not exist"); 192 | }); 193 | }); 194 | } 195 | 196 | module.exports = shouldBehaveLikeERC1620WithdrawFromStream; 197 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/view/BalanceOf.js: -------------------------------------------------------------------------------- 1 | const { devConstants, mochaContexts } = require("@sablier/dev-utils"); 2 | const BigNumber = require("bignumber.js"); 3 | const dayjs = require("dayjs"); 4 | const truffleAssert = require("truffle-assertions"); 5 | 6 | const { FIVE_UNITS, STANDARD_SALARY, STANDARD_SCALE, STANDARD_TIME_OFFSET, STANDARD_TIME_DELTA } = devConstants; 7 | const { contextForStreamDidEnd, contextForStreamDidStartButNotEnd } = mochaContexts; 8 | 9 | function shouldBehaveLikeBalanceOf(alice, bob, carol) { 10 | const sender = alice; 11 | const opts = { from: sender }; 12 | const now = new BigNumber(dayjs().unix()); 13 | 14 | describe("when the stream exists", function() { 15 | let streamId; 16 | const recipient = bob; 17 | const deposit = STANDARD_SALARY.toString(10); 18 | const startTime = now.plus(STANDARD_TIME_OFFSET); 19 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 20 | 21 | beforeEach(async function() { 22 | await this.token.approve(this.sablier.address, deposit, opts); 23 | const result = await this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts); 24 | streamId = Number(result.logs[0].args.streamId); 25 | }); 26 | 27 | describe("when the stream did not start", function() { 28 | it("returns the whole deposit for the sender of the stream", async function() { 29 | const balance = await this.sablier.balanceOf(streamId, sender, opts); 30 | balance.should.be.bignumber.equal(deposit); 31 | }); 32 | 33 | it("returns 0 for the recipient of the stream", async function() { 34 | const balance = await this.sablier.balanceOf(streamId, recipient, opts); 35 | balance.should.be.bignumber.equal(new BigNumber(0)); 36 | }); 37 | 38 | it("returns 0 for anyone else", async function() { 39 | const balance = await this.sablier.balanceOf(streamId, carol, opts); 40 | balance.should.be.bignumber.equal(new BigNumber(0)); 41 | }); 42 | }); 43 | 44 | contextForStreamDidStartButNotEnd(function() { 45 | const streamedAmount = FIVE_UNITS.toString(10); 46 | 47 | it("returns the pro rata balance for the sender of the stream", async function() { 48 | const balance = await this.sablier.balanceOf(streamId, sender, opts); 49 | const tolerateByAddition = false; 50 | balance.should.tolerateTheBlockTimeVariation( 51 | STANDARD_SALARY.minus(streamedAmount), 52 | STANDARD_SCALE, 53 | tolerateByAddition, 54 | ); 55 | }); 56 | 57 | it("returns the pro rata balance for the recipient of the stream", async function() { 58 | const balance = await this.sablier.balanceOf(streamId, recipient, opts); 59 | balance.should.tolerateTheBlockTimeVariation(streamedAmount, STANDARD_SCALE); 60 | }); 61 | 62 | it("returns 0 for anyone else", async function() { 63 | const balance = await this.sablier.balanceOf(streamId, carol, opts); 64 | balance.should.be.bignumber.equal(new BigNumber(0)); 65 | }); 66 | }); 67 | 68 | contextForStreamDidEnd(function() { 69 | it("returns 0 for the sender of the stream", async function() { 70 | const balance = await this.sablier.balanceOf(streamId, sender, opts); 71 | balance.should.be.bignumber.equal(new BigNumber(0)); 72 | }); 73 | 74 | it("returns the whole deposit for the recipient of the stream", async function() { 75 | const balance = await this.sablier.balanceOf(streamId, recipient, opts); 76 | balance.should.be.bignumber.equal(STANDARD_SALARY); 77 | }); 78 | 79 | it("returns 0 for anyone else", async function() { 80 | const balance = await this.sablier.balanceOf(streamId, carol, opts); 81 | balance.should.be.bignumber.equal(new BigNumber(0)); 82 | }); 83 | }); 84 | }); 85 | 86 | describe("when the stream does not exist", function() { 87 | it("reverts", async function() { 88 | const streamId = new BigNumber(419863); 89 | await truffleAssert.reverts(this.sablier.balanceOf(streamId, sender, opts), "stream does not exist"); 90 | }); 91 | }); 92 | } 93 | 94 | module.exports = shouldBehaveLikeBalanceOf; 95 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/view/DeltaOf.js: -------------------------------------------------------------------------------- 1 | const { devConstants, mochaContexts } = require("@sablier/dev-utils"); 2 | const BigNumber = require("bignumber.js"); 3 | const dayjs = require("dayjs"); 4 | const truffleAssert = require("truffle-assertions"); 5 | 6 | const { STANDARD_SALARY, STANDARD_TIME_OFFSET, STANDARD_TIME_DELTA } = devConstants; 7 | const { contextForStreamDidEnd, contextForStreamDidStartButNotEnd } = mochaContexts; 8 | 9 | function shouldBehaveLikeDeltaOf(alice, bob) { 10 | const sender = alice; 11 | const opts = { from: sender }; 12 | const now = new BigNumber(dayjs().unix()); 13 | 14 | describe("when the stream exists", function() { 15 | let streamId; 16 | const recipient = bob; 17 | const deposit = STANDARD_SALARY.toString(10); 18 | const startTime = now.plus(STANDARD_TIME_OFFSET); 19 | const stopTime = startTime.plus(STANDARD_TIME_DELTA); 20 | 21 | beforeEach(async function() { 22 | await this.token.approve(this.sablier.address, deposit, opts); 23 | const result = await this.sablier.createStream(recipient, deposit, this.token.address, startTime, stopTime, opts); 24 | streamId = Number(result.logs[0].args.streamId); 25 | }); 26 | 27 | describe("when the stream did not start", function() { 28 | it("returns 0", async function() { 29 | const delta = await this.sablier.deltaOf(streamId, opts); 30 | delta.should.be.bignumber.equal(new BigNumber(0)); 31 | }); 32 | }); 33 | 34 | contextForStreamDidStartButNotEnd(function() { 35 | it("returns the time the number of seconds that passed since the start time", async function() { 36 | const delta = await this.sablier.deltaOf(streamId, opts); 37 | delta.should.bignumber.satisfy(function(num) { 38 | return num.isEqualTo(new BigNumber(5)) || num.isEqualTo(new BigNumber(5).plus(1)); 39 | }); 40 | }); 41 | }); 42 | 43 | contextForStreamDidEnd(function() { 44 | it("returns the difference between the stop time and the start time", async function() { 45 | const delta = await this.sablier.deltaOf(streamId, opts); 46 | delta.should.be.bignumber.equal(stopTime.minus(startTime)); 47 | }); 48 | }); 49 | }); 50 | 51 | describe("when the stream does not exist", function() { 52 | it("reverts", async function() { 53 | const streamId = new BigNumber(419863); 54 | await truffleAssert.reverts(this.sablier.deltaOf(streamId, opts), "stream does not exist"); 55 | }); 56 | }); 57 | } 58 | 59 | module.exports = shouldBehaveLikeDeltaOf; 60 | -------------------------------------------------------------------------------- /packages/protocol/test/sablier/view/GetStream.js: -------------------------------------------------------------------------------- 1 | const BigNumber = require("bignumber.js"); 2 | const truffleAssert = require("truffle-assertions"); 3 | 4 | function shouldBehaveLikeGetStream(alice) { 5 | const sender = alice; 6 | const opts = { from: sender }; 7 | 8 | describe("when the stream does not exist", function() { 9 | it("reverts", async function() { 10 | const streamId = new BigNumber(419863); 11 | await truffleAssert.reverts(this.sablier.getStream(streamId, opts), "stream does not exist"); 12 | }); 13 | }); 14 | } 15 | 16 | module.exports = shouldBehaveLikeGetStream; 17 | -------------------------------------------------------------------------------- /packages/protocol/test/setup.js: -------------------------------------------------------------------------------- 1 | const { chaiPlugin } = require("@sablier/dev-utils"); 2 | const traveler = require("ganache-time-traveler"); 3 | 4 | const BigNumber = require("bignumber.js"); 5 | const chai = require("chai"); 6 | const chaiBigNumber = require("chai-bignumber"); 7 | 8 | chai.should(); 9 | chai.use(chaiBigNumber(BigNumber)); 10 | chai.use(chaiPlugin); 11 | 12 | let snapshotId; 13 | 14 | before(async () => { 15 | const snapshot = await traveler.takeSnapshot(); 16 | snapshotId = snapshot.result; 17 | }); 18 | 19 | after(async () => { 20 | await traveler.revertToSnapshot(snapshotId); 21 | }); 22 | -------------------------------------------------------------------------------- /packages/protocol/truffle-config.js: -------------------------------------------------------------------------------- 1 | require("dotenv").config(); 2 | const HDWalletProvider = require("@truffle/hdwallet-provider"); 3 | 4 | // Create a `.env` file by following `.env.example` 5 | const mnemonic = process.env.MNEMONIC; 6 | if (!mnemonic) { 7 | console.log("Please set your MNEMONIC in a .env file"); 8 | process.exit(1); 9 | } 10 | 11 | function createProvider(network) { 12 | if (process.env.CI) { 13 | return {}; 14 | } 15 | if (!process.env.INFURA_API_KEY) { 16 | console.log("Please set your INFURA_API_KEY"); 17 | process.exit(1); 18 | } 19 | return () => { 20 | return new HDWalletProvider(mnemonic, "wss://" + network + ".infura.io/ws/v3/" + process.env.INFURA_API_KEY); 21 | }; 22 | } 23 | 24 | module.exports = { 25 | compilers: { 26 | solc: { 27 | version: "0.5.17", 28 | settings: { 29 | optimizer: { 30 | enabled: true, 31 | runs: 200, 32 | }, 33 | }, 34 | }, 35 | }, 36 | mocha: { 37 | bail: true, 38 | enableTimeouts: false, 39 | }, 40 | networks: { 41 | arbitrum: { 42 | provider: createProvider("arbitrum-mainnet"), 43 | network_id: "42161", 44 | networkCheckTimeout: 1000000, 45 | skipDryRun: true, 46 | timeoutBlocks: 500, 47 | }, 48 | avalanche: { 49 | provider: () => new HDWalletProvider(mnemonic, "https://api.avax.network/ext/bc/C/rpc"), 50 | gas: "6000000", 51 | network_id: "43114", 52 | networkCheckTimeout: 1000000, 53 | skipDryRun: true, 54 | timeoutBlocks: 500, 55 | }, 56 | development: { 57 | host: "127.0.0.1", 58 | gas: "6000000", 59 | network_id: "*", 60 | port: "8545", 61 | skipDryRun: true, 62 | }, 63 | goerli: { 64 | provider: createProvider("goerli"), 65 | gas: "6000000", 66 | network_id: "5", 67 | skipDryRun: true, 68 | }, 69 | mainnet: { 70 | provider: createProvider("mainnet"), 71 | network_id: "1", 72 | skipDryRun: true, 73 | }, 74 | kovan: { 75 | provider: createProvider("kovan"), 76 | gas: "6000000", 77 | network_id: "42", 78 | skipDryRun: true, 79 | }, 80 | optimism: { 81 | provider: createProvider("optimism-mainnet"), 82 | network_id: "10", 83 | networkCheckTimeout: 1000000, 84 | skipDryRun: true, 85 | timeoutBlocks: 500, 86 | }, 87 | rinkeby: { 88 | provider: createProvider("rinkeby"), 89 | gas: "6000000", 90 | network_id: "4", 91 | skipDryRun: true, 92 | }, 93 | ropsten: { 94 | provider: createProvider("ropsten"), 95 | gas: "6000000", 96 | network_id: "3", 97 | skipDryRun: true, 98 | }, 99 | }, 100 | plugins: ["solidity-coverage"], 101 | }; 102 | -------------------------------------------------------------------------------- /packages/shared-contracts/README.md: -------------------------------------------------------------------------------- 1 | ## Shared Contracts 2 | 3 | Smart contracts to be shared across Sablier projects and packages. 4 | 5 | ## Usage 6 | 7 | Install the module: 8 | 9 | ```bash 10 | $ yarn add @sablier/shared-contracts 11 | ``` 12 | 13 | And import it in your solidity project: 14 | 15 | ```solidity 16 | import "@sablier/shared-contracts/mocks/ERC20Mock.sol"; 17 | ``` 18 | 19 | ## Contributing 20 | 21 | We highly encourage participation from the community to help shape the development of Sablier. If you are interested in 22 | contributing or have any questions, please reach out on [Discord](https://discord.gg/bSwRCwWRsT). 23 | 24 | ### Install Modules 25 | 26 | ```bash 27 | $ yarn install 28 | ``` 29 | 30 | ### Build 31 | 32 | ```bash 33 | $ yarn build 34 | ``` 35 | 36 | ### Lint 37 | 38 | ```bash 39 | $ yarn lint 40 | ``` 41 | 42 | ### Clean 43 | 44 | ```bash 45 | $ yarn clean 46 | ``` 47 | -------------------------------------------------------------------------------- /packages/shared-contracts/compound/CarefulMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.17; 2 | 3 | /** 4 | * @title Careful Math 5 | * @author Compound 6 | * @notice Derived from OpenZeppelin's SafeMath library 7 | * https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol 8 | */ 9 | contract CarefulMath { 10 | 11 | /** 12 | * @dev Possible error codes that we can return 13 | */ 14 | enum MathError { 15 | NO_ERROR, 16 | DIVISION_BY_ZERO, 17 | INTEGER_OVERFLOW, 18 | INTEGER_UNDERFLOW 19 | } 20 | 21 | /** 22 | * @dev Multiplies two numbers, returns an error on overflow. 23 | */ 24 | function mulUInt(uint a, uint b) internal pure returns (MathError, uint) { 25 | if (a == 0) { 26 | return (MathError.NO_ERROR, 0); 27 | } 28 | 29 | uint c = a * b; 30 | 31 | if (c / a != b) { 32 | return (MathError.INTEGER_OVERFLOW, 0); 33 | } else { 34 | return (MathError.NO_ERROR, c); 35 | } 36 | } 37 | 38 | /** 39 | * @dev Integer division of two numbers, truncating the quotient. 40 | */ 41 | function divUInt(uint a, uint b) internal pure returns (MathError, uint) { 42 | if (b == 0) { 43 | return (MathError.DIVISION_BY_ZERO, 0); 44 | } 45 | 46 | return (MathError.NO_ERROR, a / b); 47 | } 48 | 49 | /** 50 | * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend). 51 | */ 52 | function subUInt(uint a, uint b) internal pure returns (MathError, uint) { 53 | if (b <= a) { 54 | return (MathError.NO_ERROR, a - b); 55 | } else { 56 | return (MathError.INTEGER_UNDERFLOW, 0); 57 | } 58 | } 59 | 60 | /** 61 | * @dev Adds two numbers, returns an error on overflow. 62 | */ 63 | function addUInt(uint a, uint b) internal pure returns (MathError, uint) { 64 | uint c = a + b; 65 | 66 | if (c >= a) { 67 | return (MathError.NO_ERROR, c); 68 | } else { 69 | return (MathError.INTEGER_OVERFLOW, 0); 70 | } 71 | } 72 | 73 | /** 74 | * @dev add a and b and then subtract c 75 | */ 76 | function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) { 77 | (MathError err0, uint sum) = addUInt(a, b); 78 | 79 | if (err0 != MathError.NO_ERROR) { 80 | return (err0, 0); 81 | } 82 | 83 | return subUInt(sum, c); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /packages/shared-contracts/mocks/ERC20Mock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | 5 | /** 6 | * @title ERC20 Mock 7 | * @dev Mock class using ERC20 8 | * @author Sablier 9 | */ 10 | contract ERC20Mock is ERC20 { 11 | /** 12 | * @dev Allows anyone to mint tokens to any address 13 | * @param to The address that will receive the minted tokens. 14 | * @param amount The amount of tokens to mint. 15 | * @return A boolean that indicates if the operation was successful. 16 | */ 17 | function mint(address to, uint256 amount) public { 18 | _mint(to, amount); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/shared-contracts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@sablier/shared-contracts", 3 | "description": "Solidity contracts to be shared across Sablier packages", 4 | "version": "1.1.0", 5 | "author": { 6 | "name": "Sablier", 7 | "email": "contact@sablier.com", 8 | "url": "https://sablier.com" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/sablier-labs/legacy-contracts/issues" 12 | }, 13 | "dependencies": { 14 | "@openzeppelin/contracts": "2.3.0" 15 | }, 16 | "devDependencies": { 17 | "solc": "0.5.17", 18 | "solhint": "^2.1.2", 19 | "truffle": "^5.5.3" 20 | }, 21 | "files": [ 22 | "/compound", 23 | "/mocks", 24 | "/test" 25 | ], 26 | "homepage": "https://github.com/sablier-labs/legacy-contracts/tree/develop/packages/shared-contracts#readme", 27 | "license": "LGPL-3.0", 28 | "main": "./contracts", 29 | "publishConfig": { 30 | "access": "public" 31 | }, 32 | "repository": { 33 | "type": "git", 34 | "url": "https://github.com/sablier-labs/legacy-contracts.git", 35 | "directory": "packages/shared-contracts" 36 | }, 37 | "resolutions": { 38 | "ethereumjs-abi": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz" 39 | }, 40 | "scripts": { 41 | "lint": "solhint --config ../../.solhint.json --max-warnings 0 'compound/**/*.sol' 'mocks/**/*.sol' 'test/**/*.sol'" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/shared-contracts/test/EvilERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 4 | 5 | /// @dev Mock class using ERC20 6 | /// @author Sablier 7 | 8 | contract EvilERC20 is ERC20 { 9 | bool shouldDisableTransfer; 10 | bool shouldDisableTransferFrom; 11 | 12 | constructor() public { 13 | shouldDisableTransfer = false; 14 | shouldDisableTransferFrom = false; 15 | } 16 | 17 | function setShouldDisableTransfer(bool value) external { 18 | shouldDisableTransfer = value; 19 | } 20 | 21 | function setShouldDisableTransferFrom(bool value) external { 22 | shouldDisableTransferFrom = value; 23 | } 24 | 25 | /** 26 | * @dev Transfers token to a specified address, unless `shouldDisableTransfer` is `true`. 27 | * @param to The address to transfer to. 28 | * @param value The amount to be transferred. 29 | */ 30 | function transfer(address to, uint256 value) public returns (bool) { 31 | if (shouldDisableTransfer) { 32 | return false; 33 | } 34 | return super.transfer(to, value); 35 | } 36 | 37 | /** 38 | * @dev Transfer tokens from one address to another unless `shouldDisableTransferFrom` is `true`. 39 | * @param from address The address which you want to send tokens from 40 | * @param to address The address which you want to transfer to 41 | * @param value uint256 the amount of tokens to be transferred 42 | */ 43 | function transferFrom(address from, address to, uint256 value) public returns (bool) { 44 | if (shouldDisableTransferFrom) { 45 | return false; 46 | } 47 | return super.transferFrom(from, to, value); 48 | } 49 | 50 | /** 51 | * @dev Allows anyone to mint tokens to any address 52 | * @param to The address that will receive the minted tokens. 53 | * @param amount The amount of tokens to mint. 54 | * @return A boolean that indicates if the operation was successful. 55 | */ 56 | function mint(address to, uint256 amount) public { 57 | _mint(to, amount); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/shared-contracts/test/NonStandardERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.17; 2 | 3 | import "@openzeppelin/contracts/math/SafeMath.sol"; 4 | 5 | /** 6 | * @title NonStandardERC20 7 | * @author Sablier 8 | * @dev Does not return a boolean on `transfer` and `transferFrom`. 9 | */ 10 | contract NonStandardERC20 { 11 | using SafeMath for uint256; 12 | 13 | mapping(address => uint256) private _balances; 14 | 15 | mapping(address => mapping(address => uint256)) private _allowances; 16 | 17 | uint256 private _totalSupply; 18 | 19 | event Transfer(address indexed from, address indexed to, uint256 value); 20 | 21 | event Approval(address indexed owner, address indexed spender, uint256 value); 22 | 23 | function totalSupply() public view returns (uint256) { 24 | return _totalSupply; 25 | } 26 | 27 | function balanceOf(address account) public view returns (uint256) { 28 | return _balances[account]; 29 | } 30 | 31 | function transfer(address recipient, uint256 amount) public { 32 | _transfer(msg.sender, recipient, amount); 33 | } 34 | 35 | function allowance(address owner, address spender) public view returns (uint256) { 36 | return _allowances[owner][spender]; 37 | } 38 | 39 | function approve(address spender, uint256 value) public returns (bool) { 40 | _approve(msg.sender, spender, value); 41 | return true; 42 | } 43 | 44 | function transferFrom(address sender, address recipient, uint256 amount) public { 45 | _transfer(sender, recipient, amount); 46 | _approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount)); 47 | } 48 | 49 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 50 | _approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue)); 51 | return true; 52 | } 53 | 54 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 55 | _approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue)); 56 | return true; 57 | } 58 | 59 | function mint(address account, uint256 amount) public { 60 | _mint(account, amount); 61 | } 62 | 63 | function _transfer(address sender, address recipient, uint256 amount) internal { 64 | require(sender != address(0), "NonStandardERC20: transfer from the zero address"); 65 | require(recipient != address(0), "NonStandardERC20: transfer to the zero address"); 66 | 67 | _balances[sender] = _balances[sender].sub(amount); 68 | _balances[recipient] = _balances[recipient].add(amount); 69 | emit Transfer(sender, recipient, amount); 70 | } 71 | 72 | function _mint(address account, uint256 amount) internal { 73 | require(account != address(0), "NonStandardERC20: mint to the zero address"); 74 | 75 | _totalSupply = _totalSupply.add(amount); 76 | _balances[account] = _balances[account].add(amount); 77 | emit Transfer(address(0), account, amount); 78 | } 79 | 80 | function _burn(address account, uint256 value) internal { 81 | require(account != address(0), "NonStandardERC20: burn from the zero address"); 82 | 83 | _totalSupply = _totalSupply.sub(value); 84 | _balances[account] = _balances[account].sub(value); 85 | emit Transfer(account, address(0), value); 86 | } 87 | 88 | function _approve(address owner, address spender, uint256 value) internal { 89 | require(owner != address(0), "NonStandardERC20: nonStandardApprove from the zero address"); 90 | require(spender != address(0), "NonStandardERC20: nonStandardApprove to the zero address"); 91 | 92 | _allowances[owner][spender] = value; 93 | emit Approval(owner, spender, value); 94 | } 95 | 96 | function _burnFrom(address account, uint256 amount) internal { 97 | _burn(account, amount); 98 | _approve(account, msg.sender, _allowances[account][msg.sender].sub(amount)); 99 | } 100 | } 101 | --------------------------------------------------------------------------------