Compare commits

..

524 Commits

Author SHA1 Message Date
wonge97
b319a4dceb [protocol] Add file for OP RPGF Round 4 Funding (#780) 2024-05-24 15:53:41 -04:00
github-actions[bot]
e66307ba31 Publish: CHANGELOG and Package Version Updates into development (#763)
* Updated CHANGELOGS & MD docs

* Publish

 - @0x/contracts-erc20@4.0.14
 - @0x/contracts-test-utils@5.4.60
 - @0x/contracts-treasury@1.4.54
 - @0x/contracts-utils@4.8.52
 - @0x/contracts-zero-ex@0.49.0
 - @0x/contract-addresses@8.13.0
 - @0x/contract-wrappers@13.23.8
 - @0x/protocol-utils@11.24.2

---------

Co-authored-by: Github Actions <github-actions@github.com>
2023-11-15 16:38:36 -08:00
Kyu
652d422622 Add Sepoia addresses (#761) 2023-11-15 15:24:11 -08:00
Kyu
5207565af8 Temporarily disable erc20 and governance in ci (#762) 2023-11-15 14:30:44 -08:00
wonge97
d982d75e2e Update docs with missing chains that 0x protocol is deployed on (#760)
* Update docs with missing chains that 0x protocol is deployed on
2023-11-13 12:58:46 -06:00
David Walsh
c5650da703 [contract-addresses] Add ChainId type predicate (#756) 2023-11-02 16:30:05 -06:00
github-actions[bot]
b19e29e03d Publish: CHANGELOG and Package Version Updates into development (#748)
* Updated CHANGELOGS & MD docs

* Publish

 - @0x/contracts-erc20@4.0.13
 - @0x/contracts-test-utils@5.4.59
 - @0x/contracts-treasury@1.4.53
 - @0x/contracts-utils@4.8.51
 - @0x/contracts-zero-ex@0.48.0
 - @0x/contract-addresses@8.12.0
 - @0x/contract-wrappers@13.23.7
 - @0x/protocol-utils@11.24.1

---------

Co-authored-by: Github Actions <github-actions@github.com>
2023-08-29 15:10:18 -07:00
Kyu
e5cbfd87bc Add Velodrome V2 support on Base (#747) 2023-08-29 14:43:23 -07:00
Savarn Dontamsetti (Sav)
5a49be1322 Create PRs to reflect publish changes (#743)
* Create PRs to reflect publish changes

* Using gh instead of third party action

* Adding github token
2023-08-24 16:35:11 -04:00
Github Actions
ec336b92aa Publish
- @0x/contracts-erc20@4.0.12
 - @0x/contracts-test-utils@5.4.58
 - @0x/contracts-treasury@1.4.52
 - @0x/contracts-utils@4.8.50
 - @0x/contracts-zero-ex@0.47.0
 - @0x/contract-addresses@8.11.0
 - @0x/contract-wrappers@13.23.6
 - @0x/protocol-utils@11.24.0
2023-08-18 14:24:32 +00:00
Github Actions
62a530d7ec Updated CHANGELOGS & MD docs 2023-08-18 14:24:27 +00:00
Savarn Dontamsetti (Sav)
09d6fbce81 Rename Maverick to MaverickV1 and add tests (#742)
* Renaming Maverick and adding tests

* Update Base chain ID
2023-08-17 17:11:05 -04:00
Savarn Dontamsetti (Sav)
7f324dd75d feat/Add Maverick V1 Support (#741)
* Add Maverick V1 Support for Ethereum, BSC, and Base
2023-08-17 12:59:38 -04:00
Github Actions
e1f9e107e9 Publish
- @0x/contracts-erc20@4.0.11
 - @0x/contracts-test-utils@5.4.57
 - @0x/contracts-treasury@1.4.51
 - @0x/contracts-utils@4.8.49
 - @0x/contracts-zero-ex@0.46.0
 - @0x/contract-addresses@8.10.0
 - @0x/contract-wrappers@13.23.5
 - @0x/protocol-utils@11.23.0
2023-08-09 21:43:27 +00:00
Github Actions
3c98225720 Updated CHANGELOGS & MD docs 2023-08-09 21:43:23 +00:00
Savarn Dontamsetti (Sav)
19e0c3364a Add Velodrome V2 compatibility test to Optimism Bridge Adapter Test (#740)
* Add Velodrome V2 compatibility test to Optimism Bridge Adapter Test

* Replace Avalanche Bridge Adapter with Optimism Bridge Adapter
2023-08-09 10:37:13 -04:00
Savarn Dontamsetti (Sav)
43e3dce965 Adding support for Velodrome V2 on Optimism (#739)
* Adding support for Velodrome V2 for Optimism
2023-08-08 16:20:03 -04:00
Github Actions
33ece5aa99 Publish
- @0x/contracts-erc20@4.0.10
 - @0x/contracts-test-utils@5.4.56
 - @0x/contracts-treasury@1.4.50
 - @0x/contracts-utils@4.8.48
 - @0x/contracts-zero-ex@0.45.1
 - @0x/contract-addresses@8.9.0
 - @0x/contract-wrappers@13.23.4
 - @0x/protocol-utils@11.22.4
2023-07-21 21:28:47 +00:00
Github Actions
262d2a8089 Updated CHANGELOGS & MD docs 2023-07-21 21:28:43 +00:00
Kyu
51fa55badd Update Base FillQuoteTransformer address (#738) 2023-07-21 13:58:04 -07:00
Github Actions
8c9917bf03 Publish
- @0x/contracts-erc20@4.0.9
 - @0x/contracts-test-utils@5.4.55
 - @0x/contracts-treasury@1.4.49
 - @0x/contracts-utils@4.8.47
 - @0x/contracts-zero-ex@0.45.0
 - @0x/contract-addresses@8.8.0
 - @0x/contract-wrappers@13.23.3
 - @0x/protocol-utils@11.22.3
2023-07-19 18:30:39 +00:00
Github Actions
b9e80db170 Updated CHANGELOGS & MD docs 2023-07-19 18:30:35 +00:00
Kyu
01e2690b2b Check UniswapV3 support on Avalanche and BSC BridgeAdapters (#737) 2023-07-19 11:05:51 -07:00
Kyu
4835a1b1e7 Add UniswapV3 to Avalanche and BSC bridge adapters (#735)
* Add UniswapV3 to Avalanche and BSC

 * Support v2 router in MixinUniswapV3

* Update Avalanche and BSC FillQuoteTransformer addresses
2023-07-19 09:52:40 -04:00
Savarn Dontamsetti (Sav)
21c8477062 Fixing invalid CHANGELOG.json for contract-addresses (#736) 2023-07-18 18:25:10 -04:00
duncancmt
defdff460a Base mainnet (#734)
* Add BaseGoerliBridgeAdapter

* Ignore Emacs files

* Remove Balancer V1; add Solidly to BaseBridgeAdapter

* Update addresses for both Base Mainnet and Goerli

* Remove Base Goerli testnet

* Prettier, CHANGELOG, and lowercasing addresses

---------

Co-authored-by: Savarn Dontamsetti <sav.dontamsetti@gmail.com>
2023-07-18 17:21:43 -04:00
wonge97
fd68edb239 Fix code block rendering (#729) 2023-06-20 11:22:54 -05:00
Kyu
e5e1393f0e Offboard Shell and MStable (#726)
* Offboard Shell and MStable

* Update README
2023-06-06 11:49:44 +09:00
Andy
20961ef42e Fix usage of expectEmit in MetaTransactionsFeatureV2 tests (#727)
* fix MetaTransactionsFeatureV2 tests

* pretty
2023-06-04 19:32:43 -04:00
Kyu
34febd728a Remove Bancor v1 support from EthereumBridgeAdapter (#724) 2023-05-16 09:38:26 -07:00
Github Actions
c2aed76f2f Publish
- @0x/contracts-erc20@4.0.8
 - @0x/contracts-test-utils@5.4.54
 - @0x/contracts-treasury@1.4.48
 - @0x/contracts-utils@4.8.46
 - @0x/contracts-zero-ex@0.44.0
 - @0x/contract-addresses@8.7.0
 - @0x/contract-wrappers@13.23.2
 - @0x/protocol-utils@11.22.2
2023-05-10 20:03:48 +00:00
Github Actions
198d986fdc Updated CHANGELOGS & MD docs 2023-05-10 20:03:45 +00:00
Savarn Dontamsetti (Sav)
e2e1d1074c feat: Add TraderJoeV2 MixIn to Arbitrum BridgeAdapter (#723)
* Add TraderJoeV2 MixIn to ArbitrumBridgeAdapter
2023-05-10 15:40:36 -04:00
wonge97
6a15dc3f13 update link (#721) 2023-05-08 17:25:34 -05:00
Github Actions
fefa3c13f6 Publish
- @0x/contracts-erc20@4.0.7
 - @0x/governance@1.0.5
 - @0x/contracts-test-utils@5.4.53
 - @0x/contracts-treasury@1.4.47
 - @0x/contracts-utils@4.8.45
 - @0x/contracts-zero-ex@0.43.0
 - @0x/contract-addresses@8.6.0
 - @0x/contract-wrappers@13.23.1
 - @0x/protocol-utils@11.22.1
2023-05-01 21:25:50 +00:00
Github Actions
f1d096a8af Updated CHANGELOGS & MD docs 2023-05-01 21:25:47 +00:00
Savarn Dontamsetti (Sav)
394ccbdc24 feat: Update Trader Joe V2 MixIn to support V2.1 router (#717)
* Add Trader Joe V2.1 Router MixIn

* Update changelog and FQT address

* lowercasing Avalanche FQT
2023-05-01 15:33:35 -04:00
Savarn Dontamsetti (Sav)
5a47f04ffc fix: remove vm.stopPrank if vm.startPrank not present (#719)
* remove vm.stopPrank if vm.startPrank not present

* remove unnecessary vm.stopPrank from governance tests
2023-05-01 14:13:56 -04:00
wonge97
3c414c12e6 fix malformed table (#718)
table was missing one space :(
2023-04-27 13:19:52 -05:00
wonge97
d268a1136c update bounty page (#716) 2023-04-27 11:51:55 -05:00
Github Actions
f8dd7168ee Publish
- @0x/contracts-treasury@1.4.46
 - @0x/contracts-zero-ex@0.42.1
 - @0x/contract-artifacts@3.19.0
 - @0x/contract-wrappers@13.23.0
 - @0x/protocol-utils@11.22.0
2023-04-24 11:12:31 +00:00
Github Actions
527ccf2ae5 Updated CHANGELOGS & MD docs 2023-04-24 11:12:28 +00:00
Andy
a7acf2951d MetaTransaction V2 Utility Packages (#714)
* add utility class for MetaTransactionsV2, update artifacts, update wrappers

* fix exports

* update artifacts, update wrappers

* update changelogs
2023-04-24 06:03:23 -04:00
wonge97
e57fc60a76 add new audits to documentation. fix broken link (#715) 2023-04-20 18:30:29 -05:00
Github Actions
4379e15a4d Publish
- @0x/contracts-erc20@4.0.6
 - @0x/contracts-test-utils@5.4.52
 - @0x/contracts-treasury@1.4.45
 - @0x/contracts-utils@4.8.44
 - @0x/contracts-zero-ex@0.42.0
 - @0x/contract-addresses@8.5.0
 - @0x/contract-wrappers@13.22.21
 - @0x/protocol-utils@11.21.0
2023-04-20 05:41:33 +00:00
Github Actions
b0c37606a8 Updated CHANGELOGS & MD docs 2023-04-20 05:41:30 +00:00
Savarn Dontamsetti (Sav)
da8e43adfe Remove Timestamps from Trader Joe V2 CHANGELOG entries (#713) 2023-04-20 14:10:41 +09:00
Savarn Dontamsetti (Sav)
b483805a22 Add Trader Joe V2 Mixin to Avalanche BridgeAdapter (#686)
* Add Trader Joe V2 Mixin to Avalanche BridgeAdapter

* Add TraderJoeV2 MixIn tests

* update forked function signatures

* Update Avalanche FQT address to reflect Trader Joe V2 MixIn

* Update CHANGELOG
2023-04-20 12:48:21 +09:00
Patrick Dowell
ff104e7505 feat: Multiplex + MetaTransaction integration and MetaTransaction Multi-Fee Support [RFQ-795] [LIT-870] (#665)
* MetaTransactionData changes

* MetaTransactionV2 creation and forge tests

* MetaTransactionData changes

* MetaTransactionV2 creation and forge tests

* add multiplexBatchSellTokenForToken, multiplexMultiHopSellTokenForToken, multiplex TokenForEth functions to metatransactions, add msgSender field to multiplex params

* Ran prettier to clean up

* More linting

* Fixing issues with EIP 712 signature, adding test case against MetaMask, and fixing lint issues

* Addressing suggestions from PR reviewers

* Complex rebase of test code based on changes in #655

* Fixing multiplex test failure

* add some tests for multiplex metatransactions

* prettier

* minor test fix

* cleaning up and adding batchExecuteMetaTransaction tests

* Removing ZERO_ADDRESS

* add multiHopBatchSellOtc to MultiplexFeature, fix _computeHopTarget for MultiplexSubcall.OTC [#667]

* fix _computeHopTarget for otc subcalls

* Fixing multiHopSellOtcOrder when params.useSelfBalance is true

* Making executeMetaTransactionV2 nonpayable and addressing a few other minor issues

* Forge update

* Add MetaTransactionsFeatureV2 to exported contracts

---------

Co-authored-by: abls <112491550+abls@users.noreply.github.com>
Co-authored-by: Duncan Townsend <git@duncancmt.com>
2023-04-19 18:20:28 -04:00
wonge97
8a2305c7b9 minor stylistic edits (#712) 2023-04-19 13:42:25 -05:00
wonge97
d7bc0b79df Doc update (#675)
* Update existing protocol docs to point to protocol-specific resources

Remove documentation of outdated/irrelevant portions of the protocol

* pin jinja version to try to fixbuild failure. (#711)

---------

Co-authored-by: Eric Wong <ewong@Erics-MBP.fios-router.home>
2023-04-19 12:22:58 -05:00
Github Actions
ad2d41fd90 Publish
- @0x/contracts-erc20@4.0.5
 - @0x/governance@1.0.4
 - @0x/contracts-test-utils@5.4.51
 - @0x/contracts-treasury@1.4.44
 - @0x/contracts-utils@4.8.43
 - @0x/contracts-zero-ex@0.41.0
 - @0x/contract-addresses@8.4.0
 - @0x/contract-wrappers@13.22.20
 - @0x/protocol-utils@11.20.0
2023-04-17 18:29:25 +00:00
Github Actions
721b984bbc Updated CHANGELOGS & MD docs 2023-04-17 18:29:22 +00:00
Kyu
72433ea5b7 fix: Revert changelog commits from previous failed publish (#710)
* Revert "Publish"

This reverts commit f919e8ef02.

* Revert "Updated CHANGELOGS & MD docs"

This reverts commit dbcc7dd6f4.

* Bump contracts-erc20 and contracts-utils versions
2023-04-17 10:59:00 -07:00
Github Actions
f919e8ef02 Publish
- @0x/contracts-erc20@4.0.4
 - @0x/contracts-test-utils@5.4.51
 - @0x/contracts-treasury@1.4.44
 - @0x/contracts-utils@4.8.42
 - @0x/contracts-zero-ex@0.41.0
 - @0x/contract-addresses@8.4.0
 - @0x/contract-wrappers@13.22.20
 - @0x/protocol-utils@11.20.0
2023-04-17 03:09:17 +00:00
Github Actions
dbcc7dd6f4 Updated CHANGELOGS & MD docs 2023-04-17 03:09:13 +00:00
Kyu
33b7515734 Bump package versions for lerna (#709) 2023-04-16 19:42:57 -07:00
Github Actions
f96b944cce Updated CHANGELOGS & MD docs 2023-04-17 02:08:53 +00:00
Kyu
0fbdc1dccd fix: Revert changelog commits from previous failed publish (#708)
* Revert "Publish"

This reverts commit 2b13dcfc14.

* Revert "Updated CHANGELOGS & MD docs"

This reverts commit d2bea4aa46.
2023-04-16 18:47:48 -07:00
Github Actions
484d9cafc4 Publish
- @0x/governance@1.0.3
2023-04-17 01:24:55 +00:00
Github Actions
e73885c9a0 Updated CHANGELOGS & MD docs 2023-04-17 01:24:52 +00:00
Kyu
948b17e2ed Add publishConfig in governance/package.json (#707)
* publishConfig is needed for lerna to publish governance as a public
  package
2023-04-16 18:03:23 -07:00
Github Actions
2b13dcfc14 Publish
- @0x/contracts-erc20@4.0.4
 - @0x/governance@1.0.2
 - @0x/contracts-test-utils@5.4.51
 - @0x/contracts-treasury@1.4.44
 - @0x/contracts-utils@4.8.42
 - @0x/contracts-zero-ex@0.40.0
 - @0x/contract-addresses@8.3.0
 - @0x/contract-wrappers@13.22.20
 - @0x/protocol-utils@11.19.0
2023-04-16 23:30:53 +00:00
Github Actions
d2bea4aa46 Updated CHANGELOGS & MD docs 2023-04-16 23:30:50 +00:00
Kyu
dc926a05b3 Update Ethereum FillQuoteTransformer address (#706) 2023-04-14 15:47:20 -07:00
Kyu
5cc53597de feat: Add Barter support to EthereumBridgeAdapter [LIT-981] (#703) 2023-04-12 20:42:55 -07:00
wonge97
57ca2c07bb Correct final audit document (#702) 2023-04-11 15:08:22 -04:00
Github Actions
b0d2dee84d Publish
- @0x/contracts-erc20@4.0.3
 - @0x/governance@1.0.1
 - @0x/contracts-test-utils@5.4.50
 - @0x/contracts-treasury@1.4.43
 - @0x/contracts-utils@4.8.41
 - @0x/contracts-zero-ex@0.39.2
 - @0x/contract-wrappers@13.22.19
 - @0x/protocol-utils@11.18.2
2023-04-10 20:05:52 +00:00
Github Actions
1422ad756d Updated CHANGELOGS & MD docs 2023-04-10 20:05:48 +00:00
David Walsh
9d216f9c1c fix: add version in changelog for utils (#700) 2023-04-07 18:09:09 -06:00
David Walsh
ff74738178 chore: add forge to publish action (#699) 2023-04-07 17:15:00 -06:00
David Walsh
fe4fe48021 chore: update dependencies (#698) 2023-04-07 16:33:59 -06:00
Elena
356e74a645 Integration test for migrating 0x stake (#697)
* Add integration test for withdrawing 0x stake in catastrophic mode

* Add a test for delegating to an external account

* Use startPrank for all calls as all from delegator

* Better use of prank

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

* Add the delegation test under normal operation mode'

---------

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>
2023-04-07 15:59:49 +03:00
duncancmt
70590e3e56 Actual script for governance deployment (#696)
* Renounce deployer timelock roles

* Add readme

* Remove obsoleted import

---------

Co-authored-by: elenadimitrova <elena@arenabg.com>
2023-04-06 19:01:43 +03:00
Elena
4e0b671bd8 Integration test catastrophic mode in staking v3 (#691)
* Integration test catastrophic mode

* Update test for withdrawals in catastrophic mode

* Test withdrawing delegator rewards work in catastrophic mode

* Test top stakers can withdraw

* Test more delegators rewards withdrawals

* Add claiming rewards for a pool owner

* Fix for forge coverage
2023-04-06 16:21:01 +03:00
Elena
ea2ca700c3 Add final report (#695) 2023-04-06 16:20:01 +03:00
Elena
3574ea5b27 Governance deployment scripts (#684)
* Add foundry deployment script and config

* Add generated by foundry build artifact for Treasury

* Add shortcut commands for goerli deployment

* Switch to a production version of predicting a deployment address

* Lower gas price

* Fix a copy-paste error

* Productionise and final test
2023-04-05 10:06:07 +03:00
Elena
b7bf5b5dfe Governance integration testing (#683)
* Segregate tests and mocks and wire up integration test base

* Switch to a production version of predicting a deployment address

* Add integration test for exchange governor migration

* Add integration test for treassury migration

* Add integration test for migrating the treasury

* Add governance upgrade action to transfer ZRX tokens to new governor

* Add governance upgrade action to transfer wCELO tokens to new governor

* Add governance upgrade action to transfer WYV tokens to new governor

* Turn on verbose logging
2023-04-05 09:35:08 +03:00
Elena
cfbb9c6f6c Governance audit and fixes (#690)
* Fix F-3: Explicit Variable Return audit report

* Reuse onlySecurityCouncil modifier and update its revert message

* Fix F-5: modifier Optimization audit report

* Fix F-7: Input Sanity Check audit report

* Add audit report

* Further gas optimise getting a checkpoint function by up to 100 gas

* Fix F-6: return Statement Optimization audit report

* Wrap logic in unchecked block to save 24 gas
in getVotes and getQuadraticVotes each

* Move audit doc into a dedicated folder
2023-04-04 18:06:38 +03:00
Elena
7e40dd1826 Remove offending test (#692) 2023-04-04 17:43:33 +03:00
Elena
bcbfbfa16c Decentralised governance of 0x protocol and treasury (#641)
* Install open zeppelin contracts

* Init foundry in governance

* Add wrapped ZRX token

* Add governance contracts testing to CI

* Set optimizer runs to default

* Upgrade to patched version of openzeppelin/contracts

* Test stakingakng / unwrapping ZRX

* Init npm package

* Lint fix, removing lib from gitignore

* Add openzeppelin contracts git submodule for foundry

* Add vanilla governor contract

* Fix reference paths to imported packages

* Temporarily switch to using a mocked version of ZRX

* Ignore foundry's lib in link checker

* Fix a conflict in gitignore between forge lib adn built lib

* Upload governance code coverage report to coveralls

* Flesh out test scenarios for wrapping/unwrapping

* Add basic ERC20 name and symbol tests

* Wire in basic timelock controller and governor test setup

* Test basic governor properties

* Add basic voting power delegation tests

* Add proposal execution happy path test

* Split ERC20Votes logic between wrapped token
and ZeroExVotes contracts

* Exclude BaseTest from coverage in coveralls

* Add protocol specific governor with produciton governance settings

* Add a dedicated instance for the treasury governor
This is currently using the default 1 token 1 vote mechanism but will be migrated

* Add test for updating governance settings
for voting delay, voting period and proposal threshold

* Create seperate timelock contract instance for treasury and protocol

* Test updating the timlock min delay

* Set timelock delay to 2 days for protocol and 1 sec for treasury

* Remove timelock from treasury governor

* Refactor _checkpointsLookup to return entire Checkpoint
instad of just number of votes

* Update the totalSupply checkpoints updating logic

* Quadratic voting power transfers and delegations

* Fix workflow yaml

* Initialise ZeroExVotes behind a ERC1967Proxy
Test it cannot be reinitialised

* Remove obsoleted console.logs from test

* Storage pack Checkpoint enum

* Remove keeping track of total balances for voting

* Switch to using the foundry artifact in test

* Fix rebase issue

* Add timelock control over the treasury governor

* Add test for wrapped token transfer

* Emit separate events for changing linear and quadratic voting power

* Add the ability to cancel a proposal

* Limit the governors' cancel function to security council only

* Eject security council after a proposal is cancelled

* Add ability for governance to set the security council

* Merge the governors test suites into one reusable set of tests

* Add an empty test function to base test contract
to remove it from coverage reports. Fudge but no other way to ignore it in report

* Security council can rollback protocol upgrades

* Upgrade to solidity 0.8.19

* Move IZeroExGovernor to src

* Abstract Security council interface into its own

* Emit events when assigning and ejecting the security council

* Use a cast to bytes4 instead of LibBytes

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

* Writing total supply checkpoints and setup of
quorum percentage of quadratic total supply for treasure governor

* Add test for transferring tokens when delegating

* Rename IZeroExSecurityCouncil to ISecurityCouncil

* Add security council restrictions to governors

* Remove obsolete overflow check

* Improve test coverage

* Upgrade open-zeppelin contracts to 4.8.2

* Test delegation by signature

* Test non security council requests
to rollback protocol changes cannot be executed

* Better revert messages

* Test correct interfaces are supported

* Remove obsoleted funciton

* Further test delegation by signature scenario

* Split the delegation functionality tests

* Add test for initialisation of voting contract

* Add test for reading checkpoints

* Update code comments

* Fix compilation warnings

* Run smt checker

* Add checkpoint tests

* Rename parameter in moveEntireVotingPower to match the one in movePartialVotingPower

* Switch moveEntireVotingPower to a more generic moveVotingPower implementation
as in the open-zeppelin contracts

* Install foundry earlier in CI

* Switch movePartialVotingPower to the generic moveVotingPower implementation

* Write totalSupplyCheckpoints via the generic _writeCheckpoint

* Add threshold for quadratic voting power

* Remove autoinserted code by OZ

* Add openzeppelin/contracts-upgradable

* Add initializable base to Voting contract

* Fix terminogy error in natspec

* Fix code comment

* Remove obsoleted overrides and add a missing modifier to moveVotingPower

* Remove amount check

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

* Fix a calculation error and clean tests

* Update thresholds for treasury governor

* Fix testShouldNotBeAbleToDelegateWithSignatureAfterExpiry

* Update from @duncancmt

without "memory-safe" the IR optimizer produces significantly worse code and it disables the stack limit evader

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

* Add onlyProxy to initializer

* Fix quadratic voting weight base

* Rename voting parameter for clarity

* Make addresses immutable (#680)

* Make addresses immutable

* Fix linting issues

---------

Co-authored-by: elenadimitrova <elena@arenabg.com>

* Prevent griefing by a malicious ZeroExVotes upgrade (#681)

* Gas optimization

* Minimal change to prevent malicious ZeroExVotes from griefing

* Add demonstration of griefing upgrade

* Fix rebase issues with tests

* Fix prettier issues

* Add checks to test

---------

Co-authored-by: elenadimitrova <elena@arenabg.com>

* Rename SecurityCouncil contract

* Add timestamp to delegator balance updates

* Make quadraticThreshold `immutable` for gas efficiency

* Remove the logic for ejecting security council

* Switch balance timestamp to be a block number

* Test votes migration for adding a new vote weight mechanism (#674)

* Add Emacs files to .gitignore

* Make some functions unproected to demonstrate a migration

* Add example (broken) migration

* Add migration test for voting logic

* Try to simplify tests

* Fix compilation errors

* Fix underflow test with new logic

* Flesh out migration test for voting

* Replace cube root library

* Fix stack too deep in coverage

---------

Co-authored-by: elenadimitrova <elena@arenabg.com>

* Change test case to testFail

* Update contracts/governance/test/ZeroExVotesMigration.sol

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

---------

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>
Co-authored-by: Duncan Townsend <git@duncancmt.com>
2023-03-22 15:03:05 +02:00
Github Actions
03fc744bbd Publish
- @0x/contracts-erc20@4.0.2
 - @0x/contracts-test-utils@5.4.49
 - @0x/contracts-treasury@1.4.42
 - @0x/contracts-utils@4.8.40
 - @0x/contracts-zero-ex@0.39.1
 - @0x/contract-addresses@8.2.0
 - @0x/contract-wrappers@13.22.18
 - @0x/protocol-utils@11.18.1
2023-03-10 01:13:24 +00:00
Github Actions
a23143d1eb Updated CHANGELOGS & MD docs 2023-03-10 01:13:21 +00:00
Savarn Dontamsetti (Sav)
c0ef6fece3 chore: update addresses to reflect AaveV3 L2 encoding removal and KyberElastic Addition (#678)
* Update addresses to reflect AaveV3 L2Encoding removal
2023-03-09 18:35:01 -05:00
Kevin Liao
03ea4e3dba feat:Add Kyber Elastic mixins (#677)
* add kyber elastic mixins

* update changelog

* fix changelog
2023-03-09 12:33:14 -08:00
Savarn Dontamsetti (Sav)
3e939f7780 Removing L2 Encoding from AaveV3 MixIn (#676) 2023-03-09 12:02:36 -05:00
Github Actions
d97dab83cd Publish
- @0x/contracts-erc20@4.0.1
 - @0x/contracts-test-utils@5.4.48
 - @0x/contracts-treasury@1.4.41
 - @0x/contracts-utils@4.8.39
 - @0x/contracts-zero-ex@0.39.0
 - @0x/contract-addresses@8.1.0
 - @0x/contract-wrappers@13.22.17
 - @0x/protocol-utils@11.18.0
2023-03-01 17:58:11 +00:00
Github Actions
f0a4f6aeca Updated CHANGELOGS & MD docs 2023-03-01 17:58:07 +00:00
Kevin Liao
f8a183812e remove test file 2023-03-01 11:17:52 -05:00
Kevin Liao
f6fd374590 testing branch protection 2023-03-01 11:05:03 -05:00
Kevin Liao
09763bcf5e update changelog to reflect adding KyberElastic to BridgeProtocols (#671) 2023-02-28 09:39:57 -05:00
Kevin Liao
3ab12ed254 update erc20 changelog to match .md file (#670) 2023-02-27 22:20:52 -05:00
Kevin Liao
25731653ef chore: update FQT addresses for kyber elastic on mainnet and polygon (#669)
* update FQT addresses for kyber elastic on mainnet and polygon

* lowercase

* update changelog

* remove timestamp
2023-02-27 21:34:41 -05:00
Kyu
ec82c42c1b Skip chain id validation in AbstractBridgeAdapter on testnets (#668) 2023-02-27 18:18:56 -08:00
Andy
38665ffc86 Migrate the multiplex tests to foundry (#655)
* add some tests for multiplex using foundry

* remove try/catch from multiplex foundry tests

* refactor multiplex forge tests

* fix broken import, remove dead code

---------

Co-authored-by: Patrick Dowell <patrick.dowell@gmail.com>
2023-02-22 19:16:48 -05:00
Kevin Liao
459fb3ee28 update changelog (#666) 2023-02-21 11:17:50 -05:00
Kevin Liao
dc8ff32d51 feat: Add Kyber Elastic mixin to Ethereum/Polygon/Arbitrum/Avalanche Bridge Adapters [LIT-753] (#661)
* add kyber elastic to ethereum and polygon

* add to arbitrum and avalanche

* added kyber quoter/router dummy addresses

* move kyberelastic test to a different file, fix some bugs with addresses, blocknumber

* lint
2023-02-21 10:31:05 -05:00
Elena
9f30823d70 Migrate erc20-contracts to foundry (#664)
* Strip erc20 package of legacy nonsense and add foundry basics

* Make foundry build

* Remove obsoleted test/UntransferrableDummyERC20Token.sol contract

* Remove obsoleted ERC20 lib variant contracts

* Remove obsoleted DummyMultipleReturnERC20Token and DummyNoReturnERC20Token contracts

* Move test contract to dedicated folder
and remove obsoleted TypeScript contract wrappers

* Remove src/interfaces/IEtherToken.sol only used in
v3 staking which is being obsoleted [skip ci]

* Add foundry test for token

* Migrate ZRX token tests to foundry

* Fix paths to erc20 contracts

* Remove obsoleted references

* Pin erc20-contracts package on treasury

* Ignore foundry imports in link checker

* Run only forge tests for erc20 contracts

* Remove DummyERC20Token and its dependencies

* Merge IERC20TokenV06 and IERC20TokenV08
into range pragma to cover solidity 0.6.5 to 0.8.x

* Merge IEtherTokenV06 and IEtherTokenV08
into range pragma to cover solidity 0.6.5 to 0.8.x

* Migrate weth9 tests to foundry

* Upload code coverage for erc20 package

* Update changelog

* Fix review comments

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

---------

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>
2023-02-19 20:04:24 +02:00
Elena
f2f835591e Code coverage improvements (#656)
* Add check for coverage threshold

* Rename WrapEth foundry test file to .t.sol
2023-02-08 09:04:17 +02:00
Jacob Evans
8c35931041 fix: Coverage with forked ENV vars (#659)
* fix: Coverage with forked ENV vars

* set foundry env vars at the job level
2023-02-07 13:03:28 +02:00
Jacob Evans
a8539aa66e empty 2023-02-07 18:28:46 +10:00
Elena
4d7df00d5a Fix path to foundry base test (#657) 2023-02-07 10:17:27 +02:00
Jacob Evans
80193215e3 feat: Migrate PositiveSlippage tests [LIT-804] (#650)
* feat: PositiveSlippageTransformer tests

* Remove old tests

* Affilite fee tests

* Create mintable erc20 token for v06

* Update MintableERC20TokenV06 name
2023-02-07 08:22:02 +10:00
Elena
c4b1f043c6 Remove obsoleted code from 0x/contracts-utils (#643)
* Remove TestAuthorizable

* Remove contracts/utils Authorizable and IAuthorizable

* Remove contracts/utils D18 contract

* Remove contracts/utils LibAddress contracts

* Remove contracts/utils LogDecoding contracts

* Remove contracts/utils Refundable contracts

* Remove contracts/utils LibAuthorizableRichErrors contracts

* Remove contracts/utils EIP712 contracts

* Remove contracts/utils TestRefundableReceiver contracts

* Remove contracts/utils EIP1271 contracts

* Remove contracts/utils ReentrancyGuardV06 contracts

* Remove contracts/utils LibMath contracts

* Remove contracts/utils LibFractions contracts

* Remove contracts/utils LibMathRichErrors contracts

* Remove DeploymentConstants as per PR review
https://github.com/0xProject/protocol/pull/643#pullrequestreview-1264963784
2023-02-06 19:35:39 +02:00
Github Actions
a472125c65 Publish
- @0x/contracts-erc20@3.3.57
 - @0x/contracts-test-utils@5.4.47
 - @0x/contracts-treasury@1.4.40
 - @0x/contracts-utils@4.8.38
 - @0x/contracts-zero-ex@0.38.6
 - @0x/contract-addresses@8.0.3
 - @0x/contract-wrappers@13.22.16
 - @0x/protocol-utils@11.17.6
2023-02-01 00:22:23 +00:00
Github Actions
8666121bd9 Updated CHANGELOGS & MD docs 2023-02-01 00:22:20 +00:00
Elyas
8cf1c8bbd2 chore: Add woofi to Arbitrum & Optimism bridge adapters [LIT-774] (#653)
* update arb bridge adapter

* update optimism bridge adapter

* make fixes

* fix lint

* update arbitrum fqt address

* changelog

* fix changelog
2023-01-31 18:02:02 -05:00
Github Actions
d2abe9ad97 Publish
- @0x/contracts-erc20@3.3.56
 - @0x/contracts-test-utils@5.4.46
 - @0x/contracts-treasury@1.4.39
 - @0x/contracts-utils@4.8.37
 - @0x/contracts-zero-ex@0.38.5
 - @0x/contract-addresses@8.0.2
 - @0x/contract-wrappers@13.22.15
 - @0x/protocol-utils@11.17.5
2023-01-30 18:59:56 +00:00
Github Actions
f8b65bd429 Updated CHANGELOGS & MD docs 2023-01-30 18:59:52 +00:00
Noah Khamliche
3a7a5d22a2 Feat: 🛠️ fix protocol release action (#652)
* 🔧 fix  and clean up foundry tests

* fix foundry tests import paths
2023-01-30 12:45:40 -05:00
Noah Khamliche
f87f5a40c0 Feat/Add Foundry Testing Environment s[TKR-525] (#555)
* added initial foundry transformERC20 tests

* added foundry tests into CircleCI flow

* add verbosity for failing tests in CI

* revert wrong CI commands

* feat: Foundry, added some more deployments (#558)

* Added some more deployments

* Rename WETH9 to WETH9V06

* Set to 0.6.x

* fix typo

* remove commit with bad prettier changes

* working bridge Fills through weth transformer

* remove unused reference

* clean up tests

* added working otc fill through transformERC20 in FQT

* resolve file imports, add samplers, arbitrumBridgeAdatper, and new FQT version

* add extra 'v' for debugging verbosity

* add extra 'v' for debugging verbosity in circleci config

* remove old traces

* refactor rpc's out of foundry.toml and into .env for CI compatibility

* remove verbosity from CI command as its now defined in foundry.toml

* setup rpc's

* ignore foundry artifacts in prettier

* change naming in prettierignore

* move /samplers to the tests subdirectory, modify remappings to reflext change

* one more try 🤞

* change CI steps

* remove yarn from CI step

* get to the right directory

* update foundry before tests

* fix tip() deprecation and use deal()

* use deal() instead of vm.deal()

* try to get foundry to have the right directory structure by updating it

* I HATE THIS

* remove foundryup

* Fix prettier issues

* Remove obsoleted import

* Use forge native commands to
install deps and test and add the --root option

* Try using forge with working-directory flag in CI

* Use nightly foundry docker image

* Update rpc endpoints config in foundry

* move tests into /forked and /local

* rename tests

* add foundry profiles to CI

* try to fix CI

* 🔧 add foundry local and forked tests to workflow

* prettier and lint

* revert deps update

* remove all samplers and add uniswapV2 sampler to ForkUtils

* address jacobs comments

* cleanup and comment

* prettier and lint

* bump contracts-zero-ex version

* set func-name-mixedcase to off in solhint for elenas new changes

* max line length to warn

* add --fix for check-md

* Update ci.yml

* fix some nitpcks and leftover code

* fix inconsistent naming

* fix bridge adapter reverts and foundry cache

* migrate foundry integration tests to /tests

* refactor contract-addresses to use the contract-addresses package style nested json

* fix solhint

* fix contract linting errors

* dont check broken links in libraries

* move forge order in gh action for testing

* add env instead of vars

* try again

* fix github actions ordering

* update licence and address comments

* remove verbosity from foundry.toml

* fix contract lint

* move back to emitting an event until samplers can be integrated as some chains dont have uniswap as a source

* add uniswap v3 sampling code for future use

* remove uniswap v3 code as its not used

* fix lint

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
Co-authored-by: Jacob Evans <jacob@dekz.net>
Co-authored-by: elenadimitrova <elena@arenabg.com>
2023-01-26 20:11:16 -05:00
Noah Khamliche
5571d1698d update contract-addresses with new bridge adapters with Woofi enabled (#649) 2023-01-26 18:38:45 -05:00
Noah Khamliche
6f7a7a7291 fix compiler to read in arbitrum bridge adapter (#648) 2023-01-26 17:45:45 -05:00
Elyas
b613de1547 add WooFi V2 Mixin (#644) 2023-01-23 20:48:27 -05:00
Github Actions
6fd269db34 Publish
- @0x/contracts-erc20@3.3.55
 - @0x/contracts-test-utils@5.4.45
 - @0x/contracts-treasury@1.4.38
 - @0x/contracts-utils@4.8.36
 - @0x/contracts-zero-ex@0.38.4
 - @0x/contract-addresses@8.0.1
 - @0x/contract-artifacts@3.18.3
 - @0x/contract-wrappers@13.22.14
 - @0x/protocol-utils@11.17.4
2023-01-23 23:46:11 +00:00
Github Actions
033db23929 Updated CHANGELOGS & MD docs 2023-01-23 23:46:08 +00:00
Savarn Dontamsetti (Sav)
891d173705 chore: adding V08 contracts [LIT-783] (#646)
* Adding V08 contracts

* Removing LibSafeMathV08

* Apply suggestions from code review

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>
2023-01-23 18:00:43 -05:00
Elena
091a10676c Run linter and formatter on staged files (#620)
* Add lint-staged package

* Add husky and configure it to run lint staged

* Fix the yarn lock file
2023-01-19 09:38:56 +02:00
Elena
0ae6f3e64f Remove manual step for code coverage (#642)
as this is no longer necessary since updating the coveralls upload action in https://github.com/0xProject/protocol/pull/640
2023-01-18 08:26:04 +02:00
wonge97
8197fee50a Update timelock days (#628)
* Update timelock days

* Fix spelling

Co-authored-by: Eric Wong <ewong@Erics-MBP.fios-router.home>
Co-authored-by: elenadimitrova <elena@arenabg.com>
2023-01-17 11:39:33 +02:00
Jacob Evans
ee48d4006b chore: Update rollback script (#580) 2023-01-17 10:54:37 +02:00
Elena
d2be56c30f Code coverage fixes (#640)
* Update coveralls link to point to protocol repo coverage

* Remove obsoleted ignores in .gitignore

* Run forge coverage in CI and upload results to coveralls

* Remove unused wrapper

* Remove legacy coverage setup

* Remove lcov-result-merger

* Add base-path setting to coverallsapp in CI
2023-01-17 10:53:43 +02:00
Elena
c4097e4203 Migrate ZeroEx proxy tests to foundry (#638)
* Implement base instantiation of the ZeroEx proxy in foundry
and move TestZeroExFeature contract to the foundry mocks

* Migrate zero-ex tests to foundry

* Update copyright year

* Update contracts/zero-ex/tests/mocks/TestZeroExFeature.sol

Co-authored-by: Jacob Evans <jacob@dekz.net>

Co-authored-by: Jacob Evans <jacob@dekz.net>
2023-01-12 11:45:33 +02:00
Elena
8f21d167cc Remove truffle (#639)
* Remove truffle config from zero-ex

* Remove truffle config erc20

* Remove obsoleted truffle ignores

* Remove truffle config under utils contracts
2023-01-12 11:26:48 +02:00
Elena
b33fc27220 Migrate FlashWallet tests to foundry (#637)
* Remove contracts/zero-ex/contracts/test/TestBridge.sol

* Move foundry tests to their default location

* Wire up base foundry test and start moving
FlashWallet tests and mocks to foundry

* Move remaining FlashWallet contract tests to foundry

* Switch to foundry default cache config
2023-01-10 15:47:25 +02:00
Elena
dcb17768cc Move repo setup to .github folder (#636) 2023-01-01 08:11:34 +02:00
Mimyo
82907f99a2 Update features.rst (#610)
`NativeLiquidityFeature` should be `NativeOrdersFeature`.
2022-12-28 07:29:45 +02:00
Elena
2e157cc307 Closes https://github.com/0xProject/protocol/issues/485 (#635) 2022-12-26 10:34:18 +02:00
Jacob Evans
3164d7882c fix: Bug Bounty git sha c1177416f5 (#626) 2022-12-26 09:54:20 +02:00
Elena
91587efe2e Replace stale bot (#634)
* Replace stale bot

* Update to latest version
2022-12-23 10:29:03 +02:00
Elena
008f00ba2f Update auto labeller and stale bot for issues and PRs (#631)
* Update message when closing stale issues with the correct duration

* Update autolabeller to correctly label

* Reformat the stale yml and change daysUntilClose to 14
2022-12-21 22:01:35 +02:00
elenadimitrova
0e38b0e54a Fix typo in dependabot yml 2022-12-21 17:33:26 +02:00
elenadimitrova
f6af4abd67 Move dependabot yml to root .github folder 2022-12-21 17:31:27 +02:00
Elena
6dc3084c30 Migrate CI to GitHub actions (#625)
* Update cci scrptisdas

* Add github action workflow for installing the solution

* Add building the solution to github actions

* Add linting and formatting checks to github action

* Add deps to list of prettier ignore

* Add tests for @0x/contracts*

* Add dependency checker tests in CI

* Add checks for markdown issues to CI

* Add foundry tests to CI

* Add Test local @0x/contracts-* to CI

* Add tests for doc generation to CI

* Surgeon out leftover circle references and config

* Fix foundry working-directory

* Switch order of generate docs and checks in CI

* Add dependabot action to github

* Run ci on push ot development branch
2022-12-21 16:27:19 +02:00
Github Actions
fd1f7a8a42 Publish
- @0x/contracts-erc20@3.3.54
 - @0x/contracts-test-utils@5.4.44
 - @0x/contracts-treasury@1.4.37
 - @0x/contracts-utils@4.8.35
 - @0x/contracts-zero-ex@0.38.3
 - @0x/contract-addresses@8.0.0
 - @0x/contract-wrappers@13.22.13
 - @0x/protocol-utils@11.17.3
2022-12-12 21:11:50 +00:00
Github Actions
3a03174a92 Updated CHANGELOGS & MD docs 2022-12-12 21:11:47 +00:00
Kyu
f5e34bce3b Remove Kovan and ArbitrumRinkeby from contract-addresses (#630) 2022-12-12 12:55:04 -08:00
Savarn Dontamsetti (Sav)
3f8dbf3fe9 Removing Balancer V2 from Bridge Adapters (#629) 2022-12-12 10:08:15 -05:00
Savarn Dontamsetti (Sav)
b040e55202 chore: removing Aave V2 and Aave V3 from Fantom (#627)
* Removing Aave V2 and Aave V3 from Fantom

* prettier fix for FantomBridgeAdapter.sol
2022-12-01 14:21:21 -05:00
Github Actions
fe0676cec3 Publish
- @0x/contracts-erc20@3.3.53
 - @0x/contracts-test-utils@5.4.43
 - @0x/contracts-treasury@1.4.36
 - @0x/contracts-utils@4.8.34
 - @0x/contracts-zero-ex@0.38.2
 - @0x/contract-addresses@7.4.1
 - @0x/contract-artifacts@3.18.2
 - @0x/contract-wrappers@13.22.12
 - @0x/protocol-utils@11.17.2
2022-11-23 20:25:30 +00:00
Github Actions
b697202e19 Updated CHANGELOGS & MD docs 2022-11-23 20:25:26 +00:00
Savarn Dontamsetti (Sav)
09bc48671c feat: adding AAVE V3 to selected Bridge Adapters [TKR-659] (#624)
* adding AAVE V3 to selected Bridge Adapters

* prettier fix

* Adding L2 optimizations for Arbitrum and Optimism

* Adding l2 encoded parameters to Aave V3 MixIn

* Removing L2 Encoder interface from MixinAaveV3.sol

* Updating FQT addresses

* prettier fix for MixinAaveV3.sol
2022-11-23 15:09:18 -05:00
Savarn Dontamsetti (Sav)
d31cc43ed6 Revert "feat: adding AAVE V3 to selected Bridge Adapters [TKR-659] (#614)" (#623)
This reverts commit 372f23156b.
2022-11-23 14:49:38 -05:00
Savarn Dontamsetti (Sav)
372f23156b feat: adding AAVE V3 to selected Bridge Adapters [TKR-659] (#614)
* adding AAVE V3 to selected Bridge Adapters

* prettier fix

* Adding L2 optimizations for Arbitrum and Optimism

* Adding l2 encoded parameters to Aave V3 MixIn

* Removing L2 Encoder interface from MixinAaveV3.sol

* Updating FQT addresses
2022-11-23 11:34:55 -05:00
Elena
010a926d79 Upgrade prettier-plugin-solidity to stable v1 (#622)
* Upgrade prettier-plugin-solidity to stable v1

* Prettier format contracts
2022-11-23 11:53:40 +02:00
Elena
0000143b4e Check for broken links in markdown (#621)
* Add check-md package and command

* Remove broken references to TESTING.md

* Fix broken link in contributing.md

* Fix staking docs headings

* Add checks for broken links to CI
2022-11-20 11:59:21 +02:00
Elena
22684ff5ba Switch contributor instructions to use github draft mode for PRs (#618)
instead of WIP title
2022-11-20 11:39:45 +02:00
Elena
4d9b68d527 Removes references to tslint (#619)
* Removes references to tslint in contract-wrappers
which are obsoleted since https://github.com/0xProject/protocol/pull/584

* Remove tslint references in contracts/utils and test utils
obsoleted by https://github.com/0xProject/protocol/pull/589

* Remove tslint references in contracts/zeroex and test utils
obsoleted by https://github.com/0xProject/protocol/pull/587

* Remove other obsoleted tslint references

* Update contributing guidelines with eslint

* Fix prettier errors
2022-11-19 17:52:00 +02:00
Kyu
957853788d chore: Delete asset-swapper [GOV-6] (#617)
* Delete `asset-swapper`

* Remove `package/asset-swapper` in CODEOWNERS
2022-11-15 14:02:33 -08:00
Github Actions
28193479c6 Publish
- @0x/contracts-erc20@3.3.52
 - @0x/contracts-test-utils@5.4.42
 - @0x/contracts-treasury@1.4.35
 - @0x/contracts-utils@4.8.33
 - @0x/contracts-zero-ex@0.38.1
 - @0x/asset-swapper@16.66.19
 - @0x/contract-addresses@7.4.0
 - @0x/contract-wrappers@13.22.11
 - @0x/protocol-utils@11.17.1
2022-11-15 01:50:44 +00:00
Github Actions
70212534a1 Updated CHANGELOGS & MD docs 2022-11-15 01:50:40 +00:00
Kyu
ea9575e94d Update Polygon FillQuoteTransformer to support Solidly (and its forks) (#616) 2022-11-14 16:01:08 -08:00
Elena
ca0b074893 Add Solidity linter (#608)
* Add solhint and basic configuration

* Add solhint-plugin-prettier to run prettier via solhint

* Remove all solhint-disable rules in contracts

* Turn off compiler version errors

* Fix max-line-length linter errors

* Fix linting and prettier issues in contracts

* Add global lint command to run both ts and solidity linter
2022-11-08 16:12:42 +02:00
Github Actions
b3281bfdb1 Publish
- @0x/contracts-erc20@3.3.51
 - @0x/contracts-test-utils@5.4.41
 - @0x/contracts-treasury@1.4.34
 - @0x/contracts-utils@4.8.32
 - @0x/contracts-zero-ex@0.38.0
 - @0x/asset-swapper@16.66.18
 - @0x/contract-addresses@7.3.0
 - @0x/contract-wrappers@13.22.10
 - @0x/protocol-utils@11.17.0
2022-11-05 00:19:12 +00:00
Github Actions
1516bf6a24 Updated CHANGELOGS & MD docs 2022-11-05 00:19:08 +00:00
Kyu
ab19bb41c4 Update fee-related transformer addresses (#615) 2022-11-04 17:02:44 -07:00
Kyu
7368aded88 Rename VelodromeMixin to SolidlyMixin and add Solidly support to PolygonBridgeAdapter (#612) 2022-11-04 14:41:35 -07:00
Github Actions
b1f856e7a4 Publish
- @0x/contracts-erc20@3.3.50
 - @0x/contracts-test-utils@5.4.40
 - @0x/contracts-treasury@1.4.33
 - @0x/contracts-utils@4.8.31
 - @0x/contracts-zero-ex@0.37.10
 - @0x/asset-swapper@16.66.17
 - @0x/contract-addresses@7.2.0
 - @0x/contract-wrappers@13.22.9
 - @0x/protocol-utils@11.16.17
2022-11-02 22:16:58 +00:00
Github Actions
9d42018fc6 Updated CHANGELOGS & MD docs 2022-11-02 22:16:54 +00:00
Noah Khamliche
624cbebe27 added new RFQTV2 compliant fqt (#611)
* added new RFQTV2 compliant fqt

* update changelog
2022-11-02 14:58:36 -07:00
Kyu
4ace7c8c43 fix: Migrate transformers to smart contract compatible unsafeTransformerTransfer [TKR-587] (#594)
* Use `call` instead of `transfer` in `LibERC20Transformer`

* Since `transfer` only forwards 2300 gas it can cause an `out of gas`
revert when the receipient is a smart contract.

* Add `unsafeTransformerTransfer` and migrate `transformers` to use
`unsafeTransformerTransfer` instead of `transformerTransfer`

* Update .prettierignore
2022-10-28 11:39:22 -07:00
Github Actions
66846c8aec Publish
- @0x/contracts-erc20@3.3.49
 - @0x/contracts-test-utils@5.4.39
 - @0x/contracts-treasury@1.4.32
 - @0x/contracts-utils@4.8.30
 - @0x/contracts-zero-ex@0.37.9
 - @0x/asset-swapper@16.66.16
 - @0x/contract-addresses@7.1.0
 - @0x/contract-wrappers@13.22.8
 - @0x/protocol-utils@11.16.16
2022-10-24 20:57:19 +00:00
Github Actions
33e38fd0a1 Updated CHANGELOGS & MD docs 2022-10-24 20:57:15 +00:00
Kyu
5a6df5a39a Add BalancerV2Batch support in Fantom FillQuoteTransformer (#607) 2022-10-24 13:39:06 -07:00
Savarn Dontamsetti (Sav)
592e7d34c9 adding BalancerV2 Batch support for Fantom Bridge Adapter (#606) 2022-10-24 14:15:11 -04:00
Github Actions
1776dbef44 Publish
- @0x/contracts-erc20@3.3.48
 - @0x/contracts-test-utils@5.4.38
 - @0x/contracts-treasury@1.4.31
 - @0x/contracts-utils@4.8.29
 - @0x/contracts-zero-ex@0.37.8
 - @0x/asset-swapper@16.66.15
 - @0x/contract-addresses@7.0.0
 - @0x/contract-wrappers@13.22.7
 - @0x/protocol-utils@11.16.15
2022-10-21 19:43:49 +00:00
Github Actions
089718df33 Updated CHANGELOGS & MD docs 2022-10-21 19:43:46 +00:00
Noah Khamliche
7500ac36de update changelog (#605) 2022-10-21 15:28:33 -04:00
Noah Khamliche
f347f4392c update contract fqt in contract-addresses (#604) 2022-10-21 15:02:23 -04:00
Github Actions
10af74e616 Publish
- @0x/contracts-erc20@3.3.47
 - @0x/contracts-treasury@1.4.30
 - @0x/contracts-utils@4.8.28
 - @0x/contracts-zero-ex@0.37.7
 - @0x/asset-swapper@16.66.14
 - @0x/protocol-utils@11.16.14
2022-10-13 14:12:06 +00:00
Github Actions
cfb2392ac7 Updated CHANGELOGS & MD docs 2022-10-13 14:12:02 +00:00
Kyu
5a2447bef3 Upgrade @0x/contracts-gen (#602) 2022-10-12 17:36:25 -07:00
Noah Khamliche
bf1b5c4257 Fix: FQT otc order encoding logic (#596)
* swap rfq and otc in fillQuoteTransformerDataEncoder to match our enum

* changelog

* fix changelog and move otcOrders field to last in fillQuoteTransformerDataEncoder

* prettier

* move otcOrders array to end of fqtTransformData

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-10-12 17:10:16 -04:00
Github Actions
10916205ab Publish
- @0x/contracts-erc20@3.3.46
 - @0x/contracts-test-utils@5.4.37
 - @0x/contracts-treasury@1.4.29
 - @0x/contracts-utils@4.8.27
 - @0x/contracts-zero-ex@0.37.6
 - @0x/asset-swapper@16.66.13
 - @0x/contract-addresses@6.25.0
 - @0x/contract-wrappers@13.22.6
 - @0x/protocol-utils@11.16.13
2022-10-11 23:45:53 +00:00
Github Actions
69f8fd39f7 Updated CHANGELOGS & MD docs 2022-10-11 23:45:49 +00:00
Kyu
0cc2cdd16e Remove Ropsten and Rinkeby addresses (#597) 2022-10-11 16:29:44 -07:00
Kyu
d207a4267e Update forge-std and fix foundry.toml (#600) 2022-10-11 16:18:21 -07:00
Kyu
e846ed2f34 Replace branch-level Circle CI cache with commit-level cache (#599)
* Branch-level cache does not make sense for `lib` because it needs to be
updated whenever there is a change in TS files.
2022-10-11 10:41:36 -07:00
Elyas
b04455c36f chore: Configure prettier-solidity and run prettier-solidity [TKR-532] (#592)
* add prettier-solidity + config

* run prettier

* update lockfile

* run prettier again

* Prettier missed one /:

* keep bridge adapter the same

* yarn prettier
2022-10-06 11:44:57 -04:00
Github Actions
d06f6c8b4d Publish
- @0x/contracts-erc20@3.3.45
 - @0x/contracts-test-utils@5.4.36
 - @0x/contracts-treasury@1.4.28
 - @0x/contracts-utils@4.8.26
 - @0x/contracts-zero-ex@0.37.5
 - @0x/asset-swapper@16.66.12
 - @0x/contract-addresses@6.24.0
 - @0x/contract-wrappers@13.22.5
 - @0x/protocol-utils@11.16.12
2022-10-05 23:42:44 +00:00
Github Actions
a689e98b0f Updated CHANGELOGS & MD docs 2022-10-05 23:42:41 +00:00
Noah Khamliche
6f72a8e8e3 fix: add balancerV2/batch to optimismBridgeAdapter (#578)
* add balancerV2/batch to optimismBridgeAdapter

* changelog

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
Co-authored-by: Savarn Dontamsetti <sav.dontamsetti@gmail.com>
2022-09-29 12:16:34 -04:00
eobbad
422f83fc99 Chore: Remove Solhint + TSlint clean-up [TKR-585] (#593)
* contracts/ERC20

* remove tslint.json from erc20

* remove tslint.json from test-utils

* remove solhint from treasury

* remove tslint.json from treasury

* remove solhint from utils

* remove tslint.json from utils

* remove solhint from zero-ex

* remove lint-contracts
2022-09-27 14:51:47 -04:00
eobbad
b6597df84f ignore generated wrappers and asset-swapper (#591) 2022-09-26 16:05:55 -04:00
eobbad
c9b1aac8a5 remove scripts from asset swapper (#590) 2022-09-26 12:41:38 -04:00
Ido Kleinman
87f4189e93 chore: Replace TSLint with ESLint in contracts/utils,treasury,test-utils,erc20 (#589)
* replace TSLint with ESLint in contracts-utils

* also contracts/treasury

* also do test-utils

* yarn fix

* fix stuff yarn fix could not fix

* eslint erc20 contracts folder too

* changelogs

* actually zeroex was a different pr

* PR #589 in changelogs

* whitespace

* prettier
2022-09-23 12:39:27 -07:00
Ido Kleinman
390e1b8510 chore: Replace TSLint with ESLint in contracts/zeroex (#587)
* replace tslint with eslint

* config file

* fix linting errors

* changelog

* prettier
2022-09-23 12:39:17 -07:00
Ido Kleinman
5645e87aca chore: add ESLint to package contract wrappers (#584)
* replace tslint with eslint + add eslintrc config

* few more missing packages for eslint

* exclude. now eslint is running (but there are errors)

* correct excludes fixes all the linter issues

* no need for max warnings
2022-09-21 17:20:09 -07:00
eobbad
0daa988996 purge tslint comments (#585) 2022-09-21 19:53:47 -04:00
eobbad
b4d6f74d7b [protocol-utils] tslint->eslint (#582)
* initialize eslint and remove tslint

* change some packages + eslintrc

* run eslint fix

* run prettier

* changelog

* update package.json

* changelog update+prettier
2022-09-21 19:37:25 -04:00
Kyu
2163cb221b Add missing Arbitrum ZeroExGovernor address (#583) 2022-09-21 16:16:28 -07:00
Github Actions
4575300016 Publish
- @0x/contracts-erc20@3.3.44
 - @0x/contracts-test-utils@5.4.35
 - @0x/contracts-treasury@1.4.27
 - @0x/contracts-utils@4.8.25
 - @0x/contracts-zero-ex@0.37.4
 - @0x/asset-swapper@16.66.11
 - @0x/contract-addresses@6.23.4
 - @0x/contract-wrappers@13.22.4
 - @0x/protocol-utils@11.16.11
2022-09-21 19:02:46 +00:00
Github Actions
82341c3b9d Updated CHANGELOGS & MD docs 2022-09-21 19:02:43 +00:00
Noah Khamliche
f89c2d2fed feat: add new fqt address containing nerve mixin (#581)
* add new fqt address containing nerve

* changelog

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-09-21 14:44:55 -04:00
Savarn Dontamsetti (Sav)
09419a7909 Adding Nerve Mixin to Arbitrum Bridge Adapter [TKR-554] (#579)
* adding Nerve Mixin to Arbitrum Bridge Adapter

* refactor bridgeAdapter to include currently deployed changes

* remove duplicate DODOV2

* removing DODO V1 from Arbitrum Bridge Adapter

* updating imports

* fixing CI: ganache tests

* Invalid caching configuration

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
Co-authored-by: Marcin Wolny <marcin@0xproject.com>
2022-09-20 10:54:50 -04:00
Github Actions
1fa093be64 Publish
- @0x/contracts-erc20@3.3.43
 - @0x/contracts-test-utils@5.4.34
 - @0x/contracts-treasury@1.4.26
 - @0x/contracts-utils@4.8.24
 - @0x/contracts-zero-ex@0.37.3
 - @0x/asset-swapper@16.66.10
 - @0x/contract-addresses@6.23.3
 - @0x/contract-wrappers@13.22.3
 - @0x/protocol-utils@11.16.10
2022-09-12 15:56:30 +00:00
Github Actions
8e9f358a02 Updated CHANGELOGS & MD docs 2022-09-12 15:56:27 +00:00
Noah Khamliche
0a2e8fc224 feat: add new fqt for optimism with balancerv2 (#577)
* add new fqt for optimism with balancerv2

* changelog

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-09-09 15:50:23 -04:00
Github Actions
5653ee8f86 Publish
- @0x/contracts-erc20@3.3.42
 - @0x/contracts-test-utils@5.4.33
 - @0x/contracts-treasury@1.4.25
 - @0x/contracts-utils@4.8.23
 - @0x/contracts-zero-ex@0.37.2
 - @0x/asset-swapper@16.66.9
 - @0x/contract-addresses@6.23.2
 - @0x/contract-wrappers@13.22.2
 - @0x/protocol-utils@11.16.9
2022-09-07 14:10:14 +00:00
Github Actions
d180d5325d Updated CHANGELOGS & MD docs 2022-09-07 14:10:11 +00:00
Noah Khamliche
d249042b47 nwe fqt address and changelog (#574)
* nwe fqt address and changelog

* add pr

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-09-07 09:52:42 -04:00
Github Actions
d3a6f79015 Publish
- @0x/contracts-erc20@3.3.41
 - @0x/contracts-test-utils@5.4.32
 - @0x/contracts-treasury@1.4.24
 - @0x/contracts-utils@4.8.22
 - @0x/contracts-zero-ex@0.37.1
 - @0x/asset-swapper@16.66.8
 - @0x/contract-addresses@6.23.1
 - @0x/contract-wrappers@13.22.1
 - @0x/protocol-utils@11.16.8
2022-09-02 19:31:26 +00:00
Github Actions
8c9dc96e5d Updated CHANGELOGS & MD docs 2022-09-02 19:31:23 +00:00
Noah Khamliche
fc0edba46b Fix/new arbitrum bridge adapter (#572)
* added new fqt with new bridge adapter for Arbitrum

* changelog

* changelog add pr

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-09-02 15:16:00 -04:00
Github Actions
37dc99181e Publish
- @0x/contracts-erc20@3.3.40
 - @0x/contracts-test-utils@5.4.31
 - @0x/contracts-treasury@1.4.23
 - @0x/contracts-utils@4.8.21
 - @0x/contracts-zero-ex@0.37.0
 - @0x/asset-swapper@16.66.7
 - @0x/contract-addresses@6.23.0
 - @0x/contract-wrappers@13.22.0
 - @0x/protocol-utils@11.16.7
2022-09-01 15:27:33 +00:00
Github Actions
6efb9f532b Updated CHANGELOGS & MD docs 2022-09-01 15:27:30 +00:00
Noah Khamliche
9b7d88e136 change weth from OPWeth to ARBWeth (#571)
* change weth from OPWeth to ARBWeth

* udpate changelog

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-09-01 11:12:46 -04:00
Noah Khamliche
e51e1f1674 added otc order array to createTranformData (#569)
* added otc order array to createTranformData

* changelog

* fix linting

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-08-31 11:37:50 -04:00
Noah Khamliche
036a263267 prereq code for otc orders in asset-swapper (#565)
* prereq code for otc orders in asset-swapper

* update changelog

* add pr to changelog

Co-authored-by: Noah Khamliche <0xnoah@Noahs-MacBook-Pro-2.local>
2022-08-31 11:08:28 -04:00
Marcin Wolny
1fb44a55b4 Invalid working_directory (#568)
* Invalid working_directory

Invalid working_directory leads to a bug where some of commands are
executed incorrect code version.

* Fix prettier
2022-08-31 16:37:39 +02:00
Kyu
d738eede0e chore: Cleanup contract addresses [TKR-530] (#564)
* Delete unused addresses in addresses.json

* Update contract wrappers

* Update CHANGELOG.json
2022-08-29 20:10:53 +09:00
Github Actions
a99c916100 Publish
- @0x/contracts-erc20@3.3.39
 - @0x/contracts-test-utils@5.4.30
 - @0x/contracts-treasury@1.4.22
 - @0x/contracts-utils@4.8.20
 - @0x/contracts-zero-ex@0.36.6
 - @0x/asset-swapper@16.66.6
 - @0x/contract-addresses@6.22.0
 - @0x/contract-wrappers@13.21.3
 - @0x/protocol-utils@11.16.6
2022-08-25 21:18:21 +00:00
Github Actions
2abb00b5e2 Updated CHANGELOGS & MD docs 2022-08-25 21:18:18 +00:00
eobbad
ef723e6f36 Empty commit 2022-08-25 17:02:48 -04:00
Ido Kleinman
1fc139886e Arbitrum-rinkeby support in AS + contracts-addresses (#552)
* Arbitrum-rinkeby support in AS + contracts-addresses

* fix UniV3 router+quoter addresses to standard ones

* changelog update
2022-08-25 13:51:37 -07:00
Github Actions
2be10bc72f Publish
- @0x/contracts-erc20@3.3.38
 - @0x/contracts-test-utils@5.4.29
 - @0x/contracts-treasury@1.4.21
 - @0x/contracts-utils@4.8.19
 - @0x/contracts-zero-ex@0.36.5
 - @0x/asset-swapper@16.66.5
 - @0x/contract-addresses@6.21.0
 - @0x/contract-wrappers@13.21.2
 - @0x/protocol-utils@11.16.5
2022-08-25 20:34:36 +00:00
Github Actions
abdc02f066 Updated CHANGELOGS & MD docs 2022-08-25 20:34:30 +00:00
eobbad
b7ef5473cd update FQT address on Arbitrum 2022-08-25 15:49:17 -04:00
eobbad
e43cdda22f Arbitrum support (#560)
* Arbitrum support

* fix typo in bridge adapter

* changelog

* remove timestamp from changelog

* fix typo in brige adapter

* add new addresses

* Fix build error

* adjust DodoV2 arguments
2022-08-25 10:37:26 -04:00
Marcin Wolny
416f2ec24c CircleCI candies 🍬 (#550)
* Re-usable cache

By use of branch as a cache key, we invalidate the cache very often.
This leads to incresed builds time. By use of cache based on checksum of
yarn.lock, we may drop the build time.

It will increase the time every time checksum has changed. In our case,
it happens multiple times per month.

* Skip job run if no changes applied

* Skip tests if no changes applied

* Skip tests if no changes applied
2022-08-25 10:08:28 +02:00
Kyu
4f7fe66d74 Fix asset-swapper deprecation notice (#561) 2022-08-24 09:49:46 +09:00
Kyu
eb394383d8 chore: Deprecate asset-swapper [TKR-484] (#559)
* Add asset-swapper deprecation notice in README.md

* Remove asset-swapper references from the top-level README

* Remove asset-swapper from circleci config

* Set asset-swapper private to prevent it from being published

* Remove asset-swapper from `nonContractPackages`

* Disable asset-swapper build and test scripts
2022-08-24 09:30:52 +09:00
Github Actions
92e681f21b Publish
- @0x/contracts-erc20@3.3.37
 - @0x/contracts-test-utils@5.4.28
 - @0x/contracts-treasury@1.4.20
 - @0x/contracts-utils@4.8.18
 - @0x/contracts-zero-ex@0.36.4
 - @0x/asset-swapper@16.66.4
 - @0x/contract-addresses@6.20.1
 - @0x/contract-artifacts@3.18.1
 - @0x/contract-wrappers@13.21.1
 - @0x/protocol-utils@11.16.4
2022-08-22 05:20:31 +00:00
Github Actions
3f65dd6049 Updated CHANGELOGS & MD docs 2022-08-22 05:20:26 +00:00
Jacob Evans
4425c316a3 chore: update packages (#553)
* Update package.jsons to latest tools packages

* Skip tests relying on gasPrice > 0

* Yarn.lock

* Fix linter

* Update Balance checker, new ganache gets more ETH

* Fix new Ganache insufficient assertion string

* Temporarily set QuoteRequestor to skip

* Fix headers Axios now requests with
2022-08-22 14:55:42 +10:00
eobbad
9058839645 WooFi Gas Estimates (#551)
* change gas estimates

* changelog

* remove comments

* fix lerna run lint error
2022-08-16 14:10:53 -04:00
Ido Kleinman
46a7a2e620 Revert "chore: Remove unused addresses in addresses.json [TKR-519] (#548)"
This reverts commit 8aa313a437.
2022-08-11 13:31:47 -07:00
eobbad
b35dccd43d Offboard Cream (#546)
* offboard cream

* changelog

* remove BalancerFillData (unused)
2022-08-10 08:42:43 -04:00
Kyu
08e0c2ebb9 chore: Add checks for addresses.json [TKR-519] (#549) 2022-08-10 17:35:38 +09:00
Kyu
8aa313a437 chore: Remove unused addresses in addresses.json [TKR-519] (#548)
* Delete unused addresses in addresses.json and update index.ts

* Update contract wrappers

* Remove outdated references to `exchange` contract in `asset-swapper`

* Update CHANGELOG.json
2022-08-10 16:59:21 +09:00
Github Actions
8e9699c340 Publish
- @0x/contracts-erc20@3.3.36
 - @0x/contracts-test-utils@5.4.27
 - @0x/contracts-treasury@1.4.19
 - @0x/contracts-utils@4.8.17
 - @0x/contracts-zero-ex@0.36.3
 - @0x/asset-swapper@16.66.3
 - @0x/contract-addresses@6.19.2
 - @0x/contract-wrappers@13.20.8
 - @0x/protocol-utils@11.16.3
2022-08-10 01:12:34 +00:00
Github Actions
939b708e63 Updated CHANGELOGS & MD docs 2022-08-10 01:12:31 +00:00
Kyu
1617e3fc44 Fix Polygon and Ganache FillQuoteTransformer addresses (#547)
* Revert Ganache (1337) FQT address as it was mistakenly updated.
* Update Polygon (137) FQT address with the new one.
2022-08-10 09:43:42 +09:00
Github Actions
e0d705703d Publish
- @0x/contracts-erc20@3.3.35
 - @0x/contracts-test-utils@5.4.26
 - @0x/contracts-treasury@1.4.18
 - @0x/contracts-utils@4.8.16
 - @0x/contracts-zero-ex@0.36.2
 - @0x/asset-swapper@16.66.2
 - @0x/contract-addresses@6.19.1
 - @0x/contract-wrappers@13.20.7
 - @0x/protocol-utils@11.16.2
2022-08-09 19:27:28 +00:00
Github Actions
01a6d933ca Updated CHANGELOGS & MD docs 2022-08-09 19:27:24 +00:00
Kyu
9b9f0b91d7 Move woofi tokens to constant.ts and run prettier (#544) 2022-08-09 13:31:37 +09:00
Ido Kleinman
0d0fef841d PR # 2022-08-08 19:04:04 -05:00
Ido Kleinman
17adfbea32 changelogs 2022-08-08 19:04:04 -05:00
Noah Khamliche
80594622b2 empty commit to run workflow 2022-08-08 18:55:39 -05:00
Ido Kleinman
0dba5a5a3a lowercase addresses (#542) 2022-08-08 16:40:31 -07:00
phil-ociraptor
4dae8de1b6 feat: add Foundry support to contracts/zero-ex (#534)
Co-authored-by: Michael Zhu <mchl.zhu.96@gmail.com>
2022-08-08 11:46:50 -05:00
eobbad
0046bb26d8 Update WooFi sampler logicand addresses.json w/ new FQT's 2022-08-08 12:27:45 -04:00
Kyu
fe935f787c Use @0x/fast-abi instead of deprecated fast-abi (#540) 2022-08-08 14:34:48 +09:00
Kyu
1b527ffcd8 Clean up Mirror and UST related stuff (#539) 2022-08-08 12:29:33 +09:00
Github Actions
9f5324d9c3 Publish
- @0x/asset-swapper@16.66.1
2022-08-08 02:47:26 +00:00
Github Actions
3647392a04 Updated CHANGELOGS & MD docs 2022-08-08 02:47:21 +00:00
Kyu
1d49662c58 Upgrade fast-abi (#538) 2022-08-08 11:27:44 +09:00
Github Actions
6324b08b4d Publish
- @0x/contracts-erc20@3.3.34
 - @0x/contracts-test-utils@5.4.25
 - @0x/contracts-treasury@1.4.17
 - @0x/contracts-utils@4.8.15
 - @0x/contracts-zero-ex@0.36.1
 - @0x/asset-swapper@16.66.0
 - @0x/contract-addresses@6.19.0
 - @0x/contract-wrappers@13.20.6
 - @0x/protocol-utils@11.16.1
2022-08-06 01:52:58 +00:00
Github Actions
fe73b63aaa Updated CHANGELOGS & MD docs 2022-08-06 01:52:55 +00:00
Kyu
192d0b17d9 Empty commit to trigger CI (something is wrong with Ido's account lol) 2022-08-06 10:34:15 +09:00
Ido Kleinman
aa74d04083 new contract address for goerli verified deploy (#537)
* new contract address for goerli verified deploy

* v6.18.0

* updated addresses for goerli + mumbai to verified contracts

* contract addresses changelog update

* unbump package version
2022-08-05 18:22:06 -07:00
Kyu
d586f5727d Rename Balancer pool cache files (#536) 2022-08-05 17:53:55 +09:00
Kyu
98fc79a085 Upgrade dependencies in asset-swapper to match the versions used in 0x-api [TKR-484] (#535)
* Upgrade dependencies to match the versions used in 0x-api

* Fix/disable tslint issues from the new version
2022-08-05 14:26:18 +09:00
eobbad
c12a10b96e Add WooFI support (#513)
* Add WooFI interface for sampling

* WooFi Sampler

* Add mixin

* Update bridge adapters

* fix some bugs

* update transformer_utils

* Add BSC support

* yarn prettier

* Capitalize WOOFI in bridge adapters

* Put rebateAddress in a constant, fixed some other stylistic errors

* bug fixes

* Updated CHANGELOGS & MD docs

* Publish

 - @0x/contracts-erc20@3.3.33
 - @0x/contracts-test-utils@5.4.24
 - @0x/contracts-treasury@1.4.16
 - @0x/contracts-utils@4.8.14
 - @0x/contracts-zero-ex@0.36.0
 - @0x/asset-swapper@16.64.0
 - @0x/contract-addresses@6.17.0
 - @0x/contract-wrappers@13.20.5
 - @0x/protocol-utils@11.16.0

* Update reference.mdx (#531)

Align with `DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE` value from c74e31c219/src/constants.ts (L26)

* code cleanup

* remove deusdc curve pool from this pr

* Refactor PoolsCache (part 1) [TKR-500] (#525)

* Make _refreshPoolCacheIfRequiredAsync type-safe and remove Promise.all

* Factor out PoolsCache key logic into a function

* Use Map instead of object in PoolsCache and increase the default timeout

* Clean up PoolsCache and simplify its public interface

* Refactor PoolsCache (part 2) [TKR-500]  (#526)

* Introduce NoOpPoolsCache and use it in unsupported chains for BeethovenX

* Use `NoOpPoolsCache` for `CreamPoolsCache` and `BalancerPoolsCache` on unsupported chains

* Remove `getBidAskLiquidityForMakerTakerAssetPairAsync` (#528)

* Add transfer approval for quote token for multi-hops and fix buy sampler typo

* Use 0x gas api instead of eth gas station api [TKR-502] (#532)

* Use 0x gas api instead of eth gas station api

* Add integration test for `ProtocolFeeUtils`

* Update CHANGELOG.json

* Add polygon, fantom, avalanche support

* yarn prettier

* Updated CHANGELOGS & MD docs

* Publish

 - @0x/asset-swapper@16.65.0

* Remove references to `custom-no-magic-numbers` ts lint rule [TKR-484] (#533)

* Remove references to `custom-no-magic-numbers ts` lint rule

* Run prettier

* resolve Kyu's comments

* remove fqt change

* Add WooFI interface for sampling

* WooFi Sampler

* Add mixin

* Update bridge adapters

* fix some bugs

* update transformer_utils

* Add BSC support

* yarn prettier

* Capitalize WOOFI in bridge adapters

* Put rebateAddress in a constant, fixed some other stylistic errors

* bug fixes

* code cleanup

* remove deusdc curve pool from this pr

* Add transfer approval for quote token for multi-hops and fix buy sampler typo

* Add polygon, fantom, avalanche support

* yarn prettier

* resolve Kyu's comments

* remove fqt change

* merge types.ts

* WOOFi -> WOOFI

* fix lerna run lint

* Changelog

* nit changes

Co-authored-by: Github Actions <github-actions@github.com>
Co-authored-by: Pavel <51318041+pavel-bc@users.noreply.github.com>
Co-authored-by: Kyu <kyuhyun217@gmail.com>
2022-08-03 15:54:09 -04:00
Kyu
d3d4a08f91 Remove references to custom-no-magic-numbers ts lint rule [TKR-484] (#533)
* Remove references to `custom-no-magic-numbers ts` lint rule

* Run prettier
2022-08-01 17:50:40 -07:00
Github Actions
9ce090c8cd Publish
- @0x/asset-swapper@16.65.0
2022-08-01 22:10:47 +00:00
Github Actions
980d60deb8 Updated CHANGELOGS & MD docs 2022-08-01 22:10:42 +00:00
Kyu
d6d79e51e7 Use 0x gas api instead of eth gas station api [TKR-502] (#532)
* Use 0x gas api instead of eth gas station api

* Add integration test for `ProtocolFeeUtils`

* Update CHANGELOG.json
2022-08-01 14:42:45 -07:00
Kyu
3ef5de93bb Remove getBidAskLiquidityForMakerTakerAssetPairAsync (#528) 2022-07-28 09:26:07 -07:00
Kyu
ab7dc33ca4 Refactor PoolsCache (part 2) [TKR-500] (#526)
* Introduce NoOpPoolsCache and use it in unsupported chains for BeethovenX

* Use `NoOpPoolsCache` for `CreamPoolsCache` and `BalancerPoolsCache` on unsupported chains
2022-07-28 09:12:02 -07:00
Kyu
14dcee5bb6 Refactor PoolsCache (part 1) [TKR-500] (#525)
* Make _refreshPoolCacheIfRequiredAsync type-safe and remove Promise.all

* Factor out PoolsCache key logic into a function

* Use Map instead of object in PoolsCache and increase the default timeout

* Clean up PoolsCache and simplify its public interface
2022-07-28 09:04:42 -07:00
Pavel
9856e78609 Update reference.mdx (#531)
Align with `DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE` value from c74e31c219/src/constants.ts (L26)
2022-07-27 12:35:16 -07:00
Github Actions
2801b066b3 Publish
- @0x/contracts-erc20@3.3.33
 - @0x/contracts-test-utils@5.4.24
 - @0x/contracts-treasury@1.4.16
 - @0x/contracts-utils@4.8.14
 - @0x/contracts-zero-ex@0.36.0
 - @0x/asset-swapper@16.64.0
 - @0x/contract-addresses@6.17.0
 - @0x/contract-wrappers@13.20.5
 - @0x/protocol-utils@11.16.0
2022-07-27 19:32:19 +00:00
Github Actions
5bc8b13fc3 Updated CHANGELOGS & MD docs 2022-07-27 19:32:17 +00:00
Kyu
36dba8f5be Update FQT addresses on mainnet and Optimism (#530) 2022-07-27 09:56:50 -07:00
Kyu
ee2c069889 Remove Mooniswap on Ethereum Mainnet (#529)
* Remove Mooniswap from EthereumBridgeAdapter

* Remove Mooniswap sampling on mainnet

* Update CHANGELOG.json
2022-07-27 08:09:27 -07:00
Kyu
6ca14ed7b2 Fix Beethoven X Cache Issue [TKR-486] (#519)
* Replace Beethoven X subgraph url and add a test

* Simplify PoolsCacheMap type

* Make `BalancerV2PoolsCache` optional for Beethoven X

* Update CHANGELOG.json
2022-07-26 09:54:05 -07:00
Kyu
a5babb9a34 Add Synthetix Atomic Swap support [TKR-324] (#518)
* Implement SyntehtixSampler

* Implement MixinSynthetix

* Update transformer_utils.ts

* Add Synthetix mainnet support

* Add Synthetix optimism support

* Fine-tune gas schedule

* Pass read proxy dynamically to SynthetixSampler

* Pass read proxy dynamically to SynthetixMixin

* Fetch Synthetix address from sampler

* Pass Synthetix address directly to MixinSynthetix

* Update CHANGELOG.json
2022-07-25 21:17:27 -07:00
Kyu
661cc4669d Fix formatting 2022-07-22 16:25:31 -07:00
Ido Kleinman
553ba5c868 Add Goerli and Mumbai liquidity and support [TKR-493] (#523)
* deployment contract addresses on goerli

* add Goerli chainID and liquidity support for Sushi, Uni1,2,3

* UniV1 fix for Goerli

* add UniV3 to Mumbai

* remove comments

* lowercase addresses

* update contract-addresses package version

* reset package.json's states
2022-07-22 16:12:58 -07:00
Kyu
d03d2f254d Remove unused dependencies in asset-swapper [TKR-484] (#521)
* Remove unused dependencies

* Remove unused devDependencies
2022-07-19 16:44:40 -07:00
Kyu
feb91a04b0 Fix typos in GMX sampling logic (#520) 2022-07-19 16:18:37 -07:00
Kyu
4d63f33aba Update CODEOWNERS (#522) 2022-07-19 16:09:42 -07:00
Kyu
b72b8b5ffd Refactor TokenAdjacency and TokenAdjacencyBuilder [TKR-324] (#517)
* Add a new TokenAdjacencyGraph implementation

* Replace old TokenAdjacencyGraph with new implementation

* Simplify token adjacency graph in constants.ts

* Fix lint error

* Update CHANGELOG.json
2022-07-18 13:02:56 -07:00
Github Actions
f7cb7a0f51 Publish
- @0x/asset-swapper@16.63.1
2022-07-12 21:26:51 +00:00
Github Actions
9fcb28f5d8 Updated CHANGELOGS & MD docs 2022-07-12 21:26:48 +00:00
Kyu
982173471c Wrap balancer fetch top pools with try and catch [TKR-481] (#515)
* Wrap balancer fetch top pool with try and catch

* Update CHANGELOG.json
2022-07-12 13:50:07 -07:00
Github Actions
e77958425f Publish
- @0x/asset-swapper@16.63.0
2022-06-29 08:36:38 +00:00
Github Actions
6af4d71573 Updated CHANGELOGS & MD docs 2022-06-29 08:36:34 +00:00
Jacob Evans
ee985240fb chore: FillAdjustor and clean up JS router and unused functions [TKR-403] (#480)
* Remove old JS router and add a FillAdjustor

Clean up JS router and unused functions

Remove more unused functions, add adjustment of fills

Comment on why we use fill over sample

update CODEOWNERS

lint

Clean up Fill removing unused properties

Remove CollapsedFills, omit flags bigint

Create GasSchedule vs FeeSchedule, return Fill and gas on OptimizedOrder

Use Fill Adjustment in Phase2 of routing

Fix Limit orders being treated as VIP

* Fix case where dex liquidity is empty

* Use best gas adjusted pricing for fee sources

* CHANGELOG
2022-06-29 18:10:56 +10:00
eobbad
2aadbda527 Offboard Smoothy and ComethSwap (#509)
* Offboard ComethSwap

* offboard smoothy

* Changelog + yarn prettier
2022-06-22 18:36:52 +02:00
Github Actions
297c73abcc Publish
- @0x/asset-swapper@16.62.1
2022-06-15 00:40:27 +00:00
Github Actions
4c9e1b21ec Updated CHANGELOGS & MD docs 2022-06-15 00:40:24 +00:00
Kyu
41685d1545 Empty commit to trigger CI 2022-06-14 17:16:23 -07:00
Ido Kleinman
b9c25112ed Remove nUSD from intermediate liquidity to save on sampler gas (#505)
* remote nUSD from intermediate liquidity

* changelog
2022-06-14 16:07:47 -07:00
Github Actions
f0738fc122 Publish
- @0x/contracts-erc20@3.3.32
 - @0x/contracts-test-utils@5.4.23
 - @0x/contracts-treasury@1.4.15
 - @0x/contracts-utils@4.8.13
 - @0x/contracts-zero-ex@0.35.0
 - @0x/asset-swapper@16.62.0
 - @0x/contract-addresses@6.16.0
 - @0x/contract-wrappers@13.20.4
 - @0x/protocol-utils@11.15.0
2022-06-14 22:16:09 +00:00
Github Actions
42baf504b7 Updated CHANGELOGS & MD docs 2022-06-14 22:16:07 +00:00
Kyu
56038d122f Update Ethereum and Optimism FQT addresses (#504) 2022-06-14 14:45:26 -07:00
eobbad
c4446b6c0e Offboard Jetswap, CafeSwap, JulSwap, and PolyDex (#503)
* Offboard Jetswap

* Offboarded CafeSwap

* Offboarded JulSwap

* Offboarded PolyDex

* Changelog

* Update changelog

* Changelog update
2022-06-14 23:05:53 +02:00
eobbad
eaed2958c3 KnightSwap and Mdex cosmetic changes (#502)
* Lowercased KnightSwap and MDEX router address

* Changelog.JSON
2022-06-14 14:45:47 +02:00
Jorge Pérez
a045a3afb8 Chore: Do not send empty entries on Quote Report (#501)
* Chore: Do not send empty entries on Quote Report

* Changelog
2022-06-13 15:52:59 -05:00
Kyu
1cc59ab1ab feat: Add Velodrome support [TKR-432] (#494)
* Implement MixinVelodrome

* Add preliminary implementation of VelodromeSampler

* Add Velodrome in BridgeProtocol of transformer_utils.ts

* Fix MixinVelodrome

* Wire Velodrome sampler in market_operation_utils

* Fix lint error

* Remove gas schedule TODO

* Format VelodromeSampler.sol

* Fix MixinVelodrome

* Update CHANGELOG.json
2022-06-13 11:55:40 -07:00
Kyu
2c6a714b71 Fix a lint error in CHANGELOG.json 2022-06-13 10:41:58 -07:00
Kyu
d8c97d6720 Fix a lint error introduced in earlier PRs 2022-06-13 09:09:13 -07:00
eobbad
d6bc702550 Add KnightSwap on BSC (#498)
* Curve pool script to generate pools and their info. Still need to integrate into API

* Added MDEX to BSC

* Removed curve automation scripts from this PR

* Fixed typo

* Changelog

* fix formatting

* Fixed yarn lint

* Add KnightSwap

* Changelog

* update changelog

* changelog again...
2022-06-10 16:57:42 +02:00
eobbad
2838cb9420 Add MDEX support (BSC) [TKR-426] (#496)
* Curve pool script to generate pools and their info. Still need to integrate into API

* Added MDEX to BSC

* Removed curve automation scripts from this PR

* Fixed typo

* Changelog

* fix formatting

* Fixed yarn lint
2022-06-10 14:14:08 +02:00
Github Actions
b10cfc50d3 Publish
- @0x/contracts-erc20@3.3.31
 - @0x/contracts-test-utils@5.4.22
 - @0x/contracts-treasury@1.4.14
 - @0x/contracts-utils@4.8.12
 - @0x/contracts-zero-ex@0.34.0
 - @0x/asset-swapper@16.61.0
 - @0x/contract-addresses@6.15.0
 - @0x/contract-wrappers@13.20.3
 - @0x/protocol-utils@11.14.0
2022-06-03 19:20:52 +00:00
Github Actions
2e6317b01e Updated CHANGELOGS & MD docs 2022-06-03 19:20:49 +00:00
Noah Khamliche
50e99e6eac address comments 2022-06-03 15:03:00 -04:00
Noah Khamliche
8f2f4554eb fix linting 2022-06-03 15:03:00 -04:00
Noah Khamliche
67d9678a3a fix linting 2022-06-03 15:03:00 -04:00
Noah Khamliche
f70341fb48 rebase development 2022-06-03 15:03:00 -04:00
Megan
14cd24ea47 feat/add MeshSwap on Polygon [TKR-374] (#491)
* Added MeshSwap on Polygon

* Updated changelog
2022-06-03 15:03:00 -04:00
Noah Khamliche
78328056d7 Added BancorV3 to fqt, and added support in asset-swapper 2022-06-03 15:03:00 -04:00
Noah Khamliche
0045a60b0f updated contract-addresses with new ethereum fqt 2022-06-03 15:03:00 -04:00
Noah Khamliche
e4e71c76e1 add weth/eth wrap/unwrap support for bancorv3 2022-06-03 15:03:00 -04:00
Megan
ca8127545f feat/add MeshSwap on Polygon [TKR-374] (#491)
* Added MeshSwap on Polygon

* Updated changelog
2022-06-03 15:03:00 -04:00
Noah Khamliche
7b709089ce fix versioning issue on protocol-utils 2022-06-03 15:03:00 -04:00
Noah Khamliche
190f7e45f2 final changes 2022-06-03 15:03:00 -04:00
Noah Khamliche
0dcc3a6fc3 nitpicks 2022-06-03 15:03:00 -04:00
Noah Khamliche
c2e8cae293 added changelog entries 2022-06-03 15:03:00 -04:00
Noah Khamliche
83da7caab4 fixed bancor sell quotes 2022-06-03 15:03:00 -04:00
Noah Khamliche
fd69a0c273 added weth/eth support to sampler 2022-06-03 15:03:00 -04:00
Noah Khamliche
9b131199ad add weth/eth wrap/unwrap support for bancorv3 2022-06-03 15:03:00 -04:00
Noah Khamliche
f5c486050b added bancor mixin/sampler and started linking up with asset-swapper 2022-06-03 15:03:00 -04:00
Megan
1f41fe6a20 feat/add MeshSwap on Polygon [TKR-374] (#491)
* Added MeshSwap on Polygon

* Updated changelog
2022-06-02 19:11:25 +02:00
Kyu
7f4080e0a2 Delete packages/migrations (#488)
* Delete packages/migrations

* Remove 0x/migrations from asset-swapper dev dependency

* Remove 0x/migrations references
2022-06-02 10:00:50 -07:00
Kyu
db76da58d7 Add stETH wrap/unwrap support [TKR-377] (#476)
* Update MixinLido to support stETH wrapping/unwrapping

* Update LidoSampler and asset-swapper

* Re-use token address constants in LIDO_INFO_BY_CHAIN

* Update CHANGELOG.json

* Add stETH <-> wstETH to TokenAdjacencyGraph

* Change lido gas schedule code style

* Move allowance approval inside the wrap branch

* Refactor LidoSampler to reduce its bytecode size
2022-05-31 09:58:44 -07:00
mzhu25
cf8fc0ff8e Split up BridgeAdapter by chain [TKR-402] (#487)
* Split up BridgeAdapter by chain

* Fix BridgeProtocols enum

* Add isSupportedSource to bridge adapter contracts

* Add bridge adapter tests

* Fix FQT test
2022-05-25 14:18:24 -04:00
Kyu
2d16f83e37 Offboard/clean up Oasis, CoFix, and legacy Kyber [TKR-405] (#482)
* Remove Oasis

* Remove CoFix code

* Remove MixinKyber

* Remove Kyber from asset-swapper

* Delete unused imports, interface, and etc.

* Fix the test failure issue when it's run with neon-router

* Update CHANGELOG.json
2022-05-19 17:39:02 -07:00
Github Actions
4057bdab91 Publish
- @0x/asset-swapper@16.60.1
2022-05-19 03:40:00 +00:00
Github Actions
1cd10f0ac9 Updated CHANGELOGS & MD docs 2022-05-19 03:39:57 +00:00
Jacob Evans
68f87b2432 fix: BalancerV2 sor alias (#481)
* Install both Balancer sor and rename early version to v1

* yarn.lock

* CHANGELOG
2022-05-19 13:19:25 +10:00
Github Actions
69bafc3bcd Publish
- @0x/contracts-erc20@3.3.30
 - @0x/contracts-test-utils@5.4.21
 - @0x/contracts-treasury@1.4.13
 - @0x/contracts-utils@4.8.11
 - @0x/contracts-zero-ex@0.33.0
 - @0x/asset-swapper@16.60.0
 - @0x/contract-addresses@6.14.0
 - @0x/contract-wrappers@13.20.2
 - @0x/migrations@8.1.19
 - @0x/protocol-utils@11.13.0
2022-05-19 00:21:50 +00:00
Github Actions
2c44b06b7b Updated CHANGELOGS & MD docs 2022-05-19 00:21:47 +00:00
Kyu
0233f00b4e Increase KyberDMM base gas [TKR-317] (#479)
* Increase KyberDMM base gas

* Update CHANGELOG.json
2022-05-18 17:00:11 -07:00
Kyu
fedb53187d Add Yoshi Exchange support (Fantom) [TKR-270] (#473)
* Resolve conflicts

* Update CHANGELOG.json
2022-05-18 16:58:41 -07:00
Noah Khamliche
6774d2f588 prettier and lint everything 2022-05-18 19:53:50 -04:00
Noah Khamliche
cf740b74f5 removed extraneous comments in sampler 2022-05-18 19:53:50 -04:00
Noah Khamliche
177c00463a comments and nits 2022-05-18 19:53:50 -04:00
Noah Khamliche
49b0e32129 added address ref from AVALANCHE_TOKENS for mim instead of raw address 2022-05-18 19:53:50 -04:00
Noah Khamliche
938fc94756 final deployments and updates for bridge adapter and fqt on avax/bsc 2022-05-18 19:53:50 -04:00
Noah Khamliche
1561d91c2b added changelog entries 2022-05-18 19:53:50 -04:00
Noah Khamliche
9a28e51f51 rebased dev and merged 2022-05-18 19:53:50 -04:00
Ido Kleinman
f55eaa867b Add BiSwap (as UniV2 clone) on BSC (#471)
* Add BiSwap (as UniV2 clone) on BSC

* changelog PR number

* add BSW

* remove BiSwap from transformer_utils

* Do not initialize BalancerV2SwapInfoCache on unsupported chains [TKR-365] (#472)

* Do not initialize BalancerV2SwapInfoCache on unsupported chains
* Update CHANGELOG.json

* Updated CHANGELOGS & MD docs

* Publish

 - @0x/asset-swapper@16.57.3

* chore: Decomission SnowSwap [TKR-356] (#468)

* Decomission SnowSwap

* SnowSwap doesn't have much liquidity anymore (the largest pool has ~$50k)

* Update CHANGELOG.json

* Update CHANGELOG.json

* chore: Offboard Swerve Finance and LinkSwap [TKR-356] (#469)

* Offboard swerve

* Update CHANGELOG.json

* Offboard LinkSwap

* Remove unused import

* Fix CHANGELOG.json

* chore: Offboard Eth2Dai [TKR-356] (#470)

* Offboard Eth2Dai

* Update CHANGELOG.json

* feat: add IRfqClient (#467)

* add message to changelog for #467 (#474)

* Update saddle mainnet pools (#450)

* Add saddle v2 pools

* remove outdated pools

* add two saddle meta pools

* forgot changelog

* remove saddle metapools

* changelog update

* Fix a lint issue (#475)

* Updated CHANGELOGS & MD docs

* Publish

 - @0x/asset-swapper@16.59.0

* Add BiSwap (as UniV2 clone) on BSC

* rebase new changes for balv2, up changelog, quotes working

* remove Biswap from transformer_utils once again

Co-authored-by: Kyu <kyuhyun217@gmail.com>
Co-authored-by: Github Actions <github-actions@github.com>
Co-authored-by: phil-ociraptor <phil@0x.org>
Co-authored-by: Cece Z <me@cecez.xyz>
Co-authored-by: Noah Khamliche <noah@0xproject.com>
2022-05-16 17:11:23 -07:00
Github Actions
6b2856424a Publish
- @0x/asset-swapper@16.59.0
2022-05-13 00:07:18 +00:00
Github Actions
da757c4700 Updated CHANGELOGS & MD docs 2022-05-13 00:07:16 +00:00
Kyu
75e6654884 Fix a lint issue (#475) 2022-05-12 16:49:10 -07:00
Cece Z
87308e7693 Update saddle mainnet pools (#450)
* Add saddle v2 pools

* remove outdated pools

* add two saddle meta pools

* forgot changelog

* remove saddle metapools

* changelog update
2022-05-12 18:59:55 -04:00
phil-ociraptor
d5eef93a76 add message to changelog for #467 (#474) 2022-05-11 22:17:17 -05:00
phil-ociraptor
a7f23a982e feat: add IRfqClient (#467) 2022-05-11 12:35:05 -05:00
Kyu
9eadc5fc28 chore: Offboard Eth2Dai [TKR-356] (#470)
* Offboard Eth2Dai

* Update CHANGELOG.json
2022-05-10 13:54:28 -07:00
Kyu
92ad1a612e chore: Offboard Swerve Finance and LinkSwap [TKR-356] (#469)
* Offboard swerve

* Update CHANGELOG.json

* Offboard LinkSwap

* Remove unused import

* Fix CHANGELOG.json
2022-05-10 13:13:18 -07:00
Kyu
09413c0e12 chore: Decomission SnowSwap [TKR-356] (#468)
* Decomission SnowSwap

* SnowSwap doesn't have much liquidity anymore (the largest pool has ~$50k)

* Update CHANGELOG.json

* Update CHANGELOG.json
2022-05-10 09:55:43 -07:00
Github Actions
23788b41d5 Publish
- @0x/asset-swapper@16.57.3
2022-05-10 01:41:10 +00:00
Github Actions
ccf999a495 Updated CHANGELOGS & MD docs 2022-05-10 01:41:06 +00:00
Kyu
aa1016ee5f Do not initialize BalancerV2SwapInfoCache on unsupported chains [TKR-365] (#472)
* Do not initialize BalancerV2SwapInfoCache on unsupported chains
* Update CHANGELOG.json
2022-05-09 18:21:04 -07:00
Github Actions
423ef57344 Publish
- @0x/asset-swapper@16.57.2
2022-05-02 21:22:37 +00:00
Github Actions
c18149e82f Updated CHANGELOGS & MD docs 2022-05-02 21:22:33 +00:00
Jorge Pérez
d14aebf724 Fix the filter for considered sources on indicative sells for Quote Report (#466) 2022-05-02 15:45:15 -05:00
Kyu
ba719a9631 Add cvxfxs-fxs curve pool on Ethereum mainnet (#465)
* Add cvxfxs-fxs curve pool on Ethereum mainnet

* Update CHANGELOG.json

* Fix an existing formatting issue

* Adjust gasSchedule and merge the change under 16.57.1
2022-04-27 17:07:36 -07:00
eobbad
d36034d958 chore/ANY-QUICK on polygon MAG-MIM on avax (#464)
* Added ANY/QUICK pair on Polygon

* Updated changelog.json

* Update CHANGELOG.json
2022-04-26 10:55:03 -04:00
Github Actions
7750c57620 Publish
- @0x/contracts-erc20@3.3.29
 - @0x/contracts-test-utils@5.4.20
 - @0x/contracts-treasury@1.4.12
 - @0x/contracts-utils@4.8.10
 - @0x/contracts-zero-ex@0.32.0
 - @0x/asset-swapper@16.57.0
 - @0x/contract-addresses@6.13.0
 - @0x/contract-wrappers@13.20.1
 - @0x/migrations@8.1.18
 - @0x/protocol-utils@11.12.0
2022-04-22 07:05:10 +00:00
Github Actions
4d027e11d1 Updated CHANGELOGS & MD docs 2022-04-22 07:05:06 +00:00
Lawrence Forman
470e9a4697 AS: Balancer V2 batchSwap (#462)
* Draft. PoC pseudo code showing general idea for resuing SOR path creation logic and adding multihop support.

* Add actual Balancer SDK function calls.

* Update to handle buys.

* Correct taker>maker for buy.

* Draft. PoC pseudo code showing general idea for resuing SOR path creation logic and adding multihop support.

* make it build

* rebase

* add BalancerV2Batch protocol

* add BalancerV2Batch protocol

* get balancer v2 multihop working

* fix BalancerV2Batch for sells (buys still iffy)

* fix buys, appease linter and prettier

* remove unused RPC URL from balancer sdk construction

* update changelogs

* clean up comments
add event loop yield in `BalancerV2SwapInfoCache.loadTopPools()`

* add negative result check on balancerv2batch swap output

* compiler hack

* reintroduce CompilerHack

* delete unused multibridge sampler

* remove compilerhack

* reintroduce compilerhack

* try to fix CI compile errors

* plz work

* plz work

* pretty plz work

* yay it works, also address feedback

* appease linter

* deploy new FQTs

Co-authored-by: johngrantuk <johngrantuk@googlemail.com>
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2022-04-22 02:43:41 -04:00
Github Actions
7c51412e2f Publish
- @0x/asset-swapper@16.56.0
2022-04-21 21:16:27 +00:00
Github Actions
b3d1f3cd10 Updated CHANGELOGS & MD docs 2022-04-21 21:16:23 +00:00
mzhu25
389bb77439 Add estimatedGas to ExtendedQuoteReport (#463) 2022-04-21 13:52:13 -07:00
Github Actions
4327885a00 Publish
- @0x/asset-swapper@16.55.0
2022-04-07 16:07:52 +00:00
Github Actions
0aef0afbbb Updated CHANGELOGS & MD docs 2022-04-07 16:07:49 +00:00
Lawrence Forman
fa4c3a4f5f fix quote consumer RFQ VIP code path not checking if transfromERC20 is required (#461)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2022-04-07 11:58:07 -04:00
Github Actions
1d7c527c5c Publish
- @0x/asset-swapper@16.54.0
2022-04-06 03:26:22 +00:00
Github Actions
cbe3135e4b Updated CHANGELOGS & MD docs 2022-04-06 03:26:18 +00:00
Lawrence Forman
955ad49711 add real VIP support for eligible RFQT swaps (#458)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2022-04-05 23:00:12 -04:00
Github Actions
8d6f6e76e0 Publish
- @0x/contracts-erc20@3.3.28
 - @0x/contracts-test-utils@5.4.19
 - @0x/contracts-treasury@1.4.11
 - @0x/contracts-utils@4.8.9
 - @0x/contracts-zero-ex@0.31.2
 - @0x/asset-swapper@16.53.0
 - @0x/contract-addresses@6.12.1
 - @0x/contract-artifacts@3.18.0
 - @0x/contract-wrappers@13.20.0
 - @0x/migrations@8.1.17
 - @0x/protocol-utils@1.11.2
2022-03-31 15:09:24 +00:00
Github Actions
9337115650 Updated CHANGELOGS & MD docs 2022-03-31 15:09:21 +00:00
Kim Persson
fa45a44fe4 fix: use Node 16 for publish GH action (#457) 2022-03-31 16:47:02 +02:00
Kim Persson
c9c7ac8559 feat: add block number to quote report data [TKR-314] (#448)
* feat: add blockNumber to MarketSideLiquidity response

* fix: return block number back in swap quote response

* chore: add asset-swapper changelog entry
2022-03-31 15:42:34 +02:00
Kim Persson
c881723578 feat: use neon-router in CI tests (#453)
* fix: initially skip all tests that don't work with the Rust router

* fix: enable rust router for CircleCI tests

* fix: handle invalid output sampels & enable numSamples tests

* chore: add comments about disabled tests

* chore: add asset-swapper changelog entry
2022-03-31 14:32:59 +02:00
Kim Persson
c9c30d3a76 chore: bump ts version to solve type issue with ethereumjs (#455) 2022-03-31 13:55:17 +02:00
Noah Khamliche
73dfdb5b69 fixed gas estimation and removed hint from intermediate tokens 2022-03-21 14:51:23 -04:00
Noah Khamliche
e638268f94 updated routing 2022-03-21 14:51:23 -04:00
Noah Khamliche
0bfd765481 updating changelog 2022-03-21 14:51:23 -04:00
Noah Khamliche
1f12893735 fixing routing 2022-03-21 14:51:23 -04:00
Noah Khamliche
dd3d9337c4 Added Stargate curve pool 2022-03-21 14:51:23 -04:00
Lawrence Forman
904214f4a8 ugprade tools deps and regenerate wrappers (#449)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2022-03-16 12:14:31 -04:00
Noah Khamliche
64c090c4b4 removed local bignumber resolution 2022-03-10 21:22:28 -05:00
Noah Khamliche
e24474f152 lint and prettier 2022-03-10 21:22:28 -05:00
Noah Khamliche
29fa408256 final nitpicks 2022-03-10 21:22:28 -05:00
Noah Khamliche
1b94cc68af fixed gas schedule 2022-03-10 21:22:28 -05:00
Noah Khamliche
f5b4bb3035 removed low liquidity pools, and fixed some routing 2022-03-10 21:22:28 -05:00
Noah Khamliche
afd880f28c poolAddress -> NULL_ADDRESS for consitent types 2022-03-10 21:22:28 -05:00
Noah Khamliche
cd14cdd168 fixed lint 2022-03-10 21:22:28 -05:00
Noah Khamliche
c8ff53a75f fixed mobius common argument abstraction 2022-03-10 21:22:28 -05:00
Noah Khamliche
6d08add20b minimized reused code for mobius pairs 2022-03-10 21:22:28 -05:00
Noah Khamliche
29f9c725e3 bump changelog to version after feat/BTRFLYCurve 2022-03-10 21:22:28 -05:00
Noah Khamliche
a83453f07f prettier and lint 2022-03-10 21:22:28 -05:00
Noah Khamliche
ae365ce92c finished off mobius money pairs 2022-03-10 21:22:28 -05:00
Noah Khamliche
77a592e891 added mobius config for celo and some inital test pools 2022-03-10 21:22:28 -05:00
Github Actions
9a1df67d6b Publish
- @0x/asset-swapper@16.51.0
2022-03-10 04:58:07 +00:00
Github Actions
4b91411faf Updated CHANGELOGS & MD docs 2022-03-10 04:58:04 +00:00
Jacob Evans
622a542d57 feat: Curve YFI-ETH (#444)
* feat: Curve YFI-ETH

* CHANGELOG
2022-03-10 14:36:59 +10:00
Github Actions
cba53a9a50 Publish
- @0x/asset-swapper@16.50.3
2022-03-09 14:59:25 +00:00
Github Actions
e186f27f63 Updated CHANGELOGS & MD docs 2022-03-09 14:59:22 +00:00
Kim Persson
4cd767ecb8 feat: VIP routing in the router, don't create fallback orders for native [TKR-243] (#440)
* feat: calculate all routes and VIP only routes in a single router call

* fix: Try to disable using fallback orders for quotes with native orders

* fix: create VIP sources set once per routing call

* chore: use private publish version of neon-router to test

* chore(lint): comment out unused fn _addOptionalFallbackAsync

* chore: update to latest private publish of neon-router

* refactor: fix router metrics beforeTimeMs naming

* feat: don't recompute isVip for ever sample of a source

* chore: update neon-router to real published version

* fix: merge conflict resolution issue

* chore: add asset-swapper changelog entry
2022-03-09 15:39:47 +01:00
Shawn
f6e85aedf1 Fix/routing glue optimization (#439)
* fix: only create fills if using js router, remove `unoptimizedPath`

* minor optimizations

* remove the cap of route output in buys

* change PR number

* fix: Update Ropsten UniswapV3 Router address (#441)

* fix: Update Ropsten UniswapV3 Router address

* Update CHANGELOG

* Updated CHANGELOGS & MD docs

* Publish

 - @0x/asset-swapper@16.50.2

* change PR number

Co-authored-by: Kim Persson <kimpersson88@gmail.com>
Co-authored-by: Jacob Evans <jacob@dekz.net>
Co-authored-by: Github Actions <github-actions@github.com>
2022-03-08 16:26:22 -08:00
Github Actions
b3ee294ba5 Publish
- @0x/asset-swapper@16.50.2
2022-03-07 01:37:11 +00:00
Github Actions
1c242def93 Updated CHANGELOGS & MD docs 2022-03-07 01:37:07 +00:00
Jacob Evans
f0fe6f2f69 fix: Update Ropsten UniswapV3 Router address (#441)
* fix: Update Ropsten UniswapV3 Router address

* Update CHANGELOG
2022-03-07 11:18:25 +10:00
Github Actions
f86d555e49 Publish
- @0x/asset-swapper@16.50.1
2022-03-03 13:04:04 +00:00
Github Actions
b0f2c40463 Updated CHANGELOGS & MD docs 2022-03-03 13:04:00 +00:00
Kim Persson
87be6fbb8a fix: lower UniswapV3Sampler quote gas allowance to 700k (#438)
* fix: lower UniswapV3Sampler quote gas allowance to 700k

* chore: add asset-swapper changelog entry
2022-03-03 13:45:20 +01:00
Noah Khamliche
9141a9d2c8 feat: BTRFLY/WETH factory pool (#437)
* added curve support for BTRFLY/WETH factory pool

* prettier and lint

* remove timestamp

* fixed gas schedule for btrflyweth pool

* chore: update Node16 (#384)


* Node 16

* update yarn.lock

* Update ganache-cli and merkle-patricia-tree

* [TKR-275] Add Geist on Fantom (#398)

* Add Geist on Fantom

* nvm there is not subgraph for it

* finish giest utils

* Address pr comments

* lowercase gtoken addresses

* return undefined instead of error for unsupported pairs

* another lower case

* Update fantom fillQuoteTransformer address

* more const clean up

* feat: Improve Uniswap V3 gas schedule redux (#424)

* Revert "fix: Revert Improve Uniswap V3 gas schedule (#397) (#419)"

This reverts commit df0e0866e4.

* fix: UniswapV3Sampler return token amounts as the last value in return tuple

* fix: bump Uniswap V3 quote max gas because QuoterV2 is more expensive

* fix: don't try to rout 0 sellAmount/buyAmount quotes

* fix: Linting issue

* fix: use median gas usage instead of mean in UniV3 gas schedule

* chore: add asset-swapper changelog entry

* fix: remove contract-addresses changelog empty row failing linting

* Updated CHANGELOGS & MD docs

* Publish

 - @0x/contracts-erc20@3.3.27
 - @0x/contracts-test-utils@5.4.18
 - @0x/contracts-treasury@1.4.10
 - @0x/contracts-utils@4.8.8
 - @0x/contracts-zero-ex@0.31.1
 - @0x/asset-swapper@16.50.0
 - @0x/contract-addresses@6.12.0
 - @0x/contract-wrappers@13.19.1
 - @0x/migrations@8.1.16
 - @0x/protocol-utils@1.11.1

* Add v4 NFT Audits (#435)

* prettier and lint

Co-authored-by: Jacob Evans <jacob@dekz.net>
Co-authored-by: Cece Z <cece@0xproject.com>
Co-authored-by: Kim Persson <kimpers@users.noreply.github.com>
Co-authored-by: Github Actions <github-actions@github.com>
Co-authored-by: Jessica Lin <jlin2700@gmail.com>
2022-03-02 21:18:40 -05:00
Jessica Lin
7f75de347e Add v4 NFT Audits (#435) 2022-03-02 10:46:00 -08:00
Github Actions
329f7761c3 Publish
- @0x/contracts-erc20@3.3.27
 - @0x/contracts-test-utils@5.4.18
 - @0x/contracts-treasury@1.4.10
 - @0x/contracts-utils@4.8.8
 - @0x/contracts-zero-ex@0.31.1
 - @0x/asset-swapper@16.50.0
 - @0x/contract-addresses@6.12.0
 - @0x/contract-wrappers@13.19.1
 - @0x/migrations@8.1.16
 - @0x/protocol-utils@1.11.1
2022-03-02 12:55:58 +00:00
Github Actions
0d8e83cd75 Updated CHANGELOGS & MD docs 2022-03-02 12:55:55 +00:00
Kim Persson
e5d60b8077 feat: Improve Uniswap V3 gas schedule redux (#424)
* Revert "fix: Revert Improve Uniswap V3 gas schedule (#397) (#419)"

This reverts commit df0e0866e4.

* fix: UniswapV3Sampler return token amounts as the last value in return tuple

* fix: bump Uniswap V3 quote max gas because QuoterV2 is more expensive

* fix: don't try to rout 0 sellAmount/buyAmount quotes

* fix: Linting issue

* fix: use median gas usage instead of mean in UniV3 gas schedule

* chore: add asset-swapper changelog entry

* fix: remove contract-addresses changelog empty row failing linting
2022-03-02 13:36:12 +01:00
Cece Z
ae2fe55efa [TKR-275] Add Geist on Fantom (#398)
* Add Geist on Fantom

* nvm there is not subgraph for it

* finish giest utils

* Address pr comments

* lowercase gtoken addresses

* return undefined instead of error for unsupported pairs

* another lower case

* Update fantom fillQuoteTransformer address

* more const clean up
2022-03-02 01:34:30 -05:00
Jacob Evans
6073607d3e chore: update Node16 (#384)
* Node 16

* update yarn.lock

* Update ganache-cli and merkle-patricia-tree
2022-03-02 11:50:35 +10:00
Github Actions
389ebb5df8 Publish
- @0x/asset-swapper@16.49.9
2022-02-24 09:52:41 +00:00
Github Actions
fd9655e9d4 Updated CHANGELOGS & MD docs 2022-02-24 09:52:38 +00:00
Kim Persson
6480aaa189 fix: native order scaling & don't try to route 1 wei trades (it will fail) (#430)
* feat: scale oversized native orders to quote amount for fake samples

* chore: temporarily use private publish neon-router version

* fix: short circuit 1 base unit trades to avoid router error

* chore: use published version of `neon-router`

* chore: add changelog entry for asset-swapper
2022-02-24 10:34:17 +01:00
Github Actions
38969bb0a8 Publish
- @0x/contracts-erc20@3.3.26
 - @0x/contracts-test-utils@5.4.17
 - @0x/contracts-treasury@1.4.9
 - @0x/contracts-utils@4.8.7
 - @0x/contracts-zero-ex@0.31.0
 - @0x/asset-swapper@16.49.8
 - @0x/contract-artifacts@3.17.0
 - @0x/contract-wrappers@13.19.0
 - @0x/migrations@8.1.15
 - @0x/protocol-utils@1.11.0
2022-02-22 22:32:24 +00:00
Github Actions
1847ab93af Updated CHANGELOGS & MD docs 2022-02-22 22:32:20 +00:00
mzhu25
c1177416f5 [Final] ERC721 and ERC1155 Orders (#429)
* add LibERC721Order.sol

* Add ERC721 interface to vendor/

* Add ERC721OrdersFeature interface

* Storage lib for ERC721 orders feature

* Implement basic functionality for ERC721 orders (buy, sell, cancel, etc)

* Add isValidERC721OrderSignature to interface

* implement onERC721Received

* Implement batchBuyERC721s

* left/right orders -> sell/buy orders

* Add missing @return comments

* Implement matching functions

* Use SafeMath where necessary

* add rich errors for ERC721OrdersFeature

* Add comments

* Add presign support for ERC721 orders

* Cancel using just the order nonce

* Add IERC721OrdersFeature to IZeroEx

* Add taker callback

* Assembly optimizations in LibERC721Order

* Add ERC721Orders TS class

* create zero-ex/contracts/test/integration/ and tokens/ directories

* TestMintableERC721Token

* tmp

* address feedback from original PR (#391)

* address feedback from original PR

* Update contracts/zero-ex/contracts/src/features/ERC721OrdersFeature.sol

Co-authored-by: Kim Persson <kimpers@users.noreply.github.com>

* address review feedback and improve order parameter naming

* Add batchCancel function

* Emit order fields in preSign

* Fix tests

Co-authored-by: Lawrence Forman <me@merklejerk.com>
Co-authored-by: Kim Persson <kimpers@users.noreply.github.com>
Co-authored-by: Michael Zhu <mchl.zhu.96@gmail.com>

* Remove revertIfIncomplete from batchMatch

* Sanity check maker address in preSign

* ERC1155OrdersFeature contracts

* Commence refactor, abstract base contract

* ERC721OrdersFeature inherits from NFTOrders

* Refactor ERC1155OrdersFeature to inherit from NFTOrders

* Fix order hashing

* Fix ERC721OrdersFeature tests

* Typos

* Remove maker address from preSigned mapping

* disable dex sampler tests

* Refactor TS tooling

* Address PR feedback

* Rearrange event fields to better align with struct fields

* Update comments

* update AbiEncoder.create params

* Add ERC1155Order to protocol-utils

* Add ERC1155OrdersFeeature tests

* Bump package versions and regenerate contract wrappers

* Add ERC165Feature

* NFT orders: address audit findings (#417)

* CVF-1: use pragma solidity ^0.6 instead of ^0.6.5

* CVF-11: fix inaccurate comment

* CVF-16: Enable taker callbacks for batchBuyERC1155s

* CVF-17: use internal call if revertIfIncomplete is true

* CVF-21: avoid duplicate SLOAD

* CVF-23: merge if statements

* CVF-24: Reorder status checks to be consistent with ERC721OrdersFeature

* CVF-25: Update unclear comment (canonical hash -> EIP-712 hash)

* CVF-31: Document keys of orderState mapping

* CVF-45: DRY up fees/properties hashing

* CVF-47, CVF-50, CVF-57: calculate properties.length once; hash propertyStructHashArray in-place using assembly

* CVF-56: More descriptive names for assembly variables

* CVF-71: Update confusing comment about rounding in _payFees

* CVF-72: Move ETH assertions outside of loop in _payFees

* CVF-74: Move property validation loop to else branch

* CVF-82: Update inaccurate comment

* CVF-86: Enable taker callbacks for batchBuyERC721s

* CVF-87: use internal call if revertIfIncomplete is true

* CVF-89: Perform token mismatch checks before stateful operations

* CVF-90, CVF-91: Defer ERC20 token mismatch check

* CVF-93: Add inline comments for _payFees parameters in matchERC721Orders

* CVF-94: Fix comment (Step 7 -> Step 5)

* CVF-98: Use binary & operator instead of mod

* CVF-99: Update unclear comment (canonical hash -> EIP-712 hash)

* CVF-65, CVF-66, CVF-67: Copy params.ethAvailable into local variable; check that ethSpent does not exceed ethAvailable; remove ethAvailable < erc20FillAmount check

* CVF-52, CVF-55, CVF-59: calculate fees.length once; hash feeStructHashArray in-place using assembly

* CVF-14, CVF-32: OrderState struct; separate storage mapping for 1155 cancellations so orders can be cancelled by nonce

* Update changelogs, IZeroEx artifact/wrapper

Co-authored-by: Lawrence Forman <lawrence@0xproject.com>
Co-authored-by: Lawrence Forman <me@merklejerk.com>
Co-authored-by: Kim Persson <kimpers@users.noreply.github.com>
2022-02-22 10:00:22 -08:00
Github Actions
4fdd203211 Publish
- @0x/asset-swapper@16.49.7
2022-02-22 12:50:50 +00:00
Github Actions
4bc11776d7 Updated CHANGELOGS & MD docs 2022-02-22 12:50:47 +00:00
Kim Persson
eb12eac5f3 fix: start native orders "samples" at 0 & don't skip neg adj orders (#425)
* fix: start native orders "samples" at 0 & don't skip neg adj orders

* fix: bail on routes with invalid output estimation (no valid route)

* chore: bump neon-router version

* chore: add asset-swapper changelog entry
2022-02-22 13:31:47 +01:00
Github Actions
5f5b951998 Publish
- @0x/asset-swapper@16.49.6
2022-02-17 16:02:38 +00:00
Github Actions
8e90547604 Updated CHANGELOGS & MD docs 2022-02-17 16:02:34 +00:00
Noah Khamliche
fbea74d7ff remove comments 2022-02-17 10:40:59 -05:00
Noah Khamliche
dcea16bc13 removed ohmv2/dai and ohmv2/weth, routing is the same without the search overhead 2022-02-17 10:40:59 -05:00
Noah Khamliche
d59a074bd7 updated changelog 2022-02-17 10:40:59 -05:00
Noah Khamliche
39cc4f4dbf fixed btrfly routing to include the ohmV2/dai, ohmV2/btfly, and ohmV2/weth pools 2022-02-17 10:40:59 -05:00
Github Actions
85bcf87af8 Publish
- @0x/asset-swapper@16.49.5
2022-02-14 13:12:38 +00:00
Github Actions
a0fe1c610f Updated CHANGELOGS & MD docs 2022-02-14 13:12:35 +00:00
Kim Persson
5d21af1a0a fix: 1 base unit output amount being scale down, rounding to 0 output (#422)
* fix: 1 base unit output amount being scale down, rounding to 0 output

* chore: add asset-swapper changelog entry

* fix: round scaled output to base units before clamping
2022-02-14 13:54:53 +01:00
Jacob Evans
f6edbd210c Update protocol docs (#421)
* Update protocol docs

* Added functions

* fix table

* eligbility section?

* Trader.xyz shoutout

* Up to
2022-02-11 22:53:49 +10:00
Github Actions
e084807a8f Publish
- @0x/asset-swapper@16.49.4
2022-02-10 15:34:41 +00:00
Github Actions
1c7d512829 Updated CHANGELOGS & MD docs 2022-02-10 15:34:38 +00:00
Kim Persson
df0e0866e4 fix: Revert Improve Uniswap V3 gas schedule (#397) (#419)
* Revert "feat: Improve Uniswap V3 gas schedule (#397)"

This reverts commit 84e4819e6e.

* chore: Add changelog entry
2022-02-10 16:15:54 +01:00
Github Actions
9e6efc3676 Publish
- @0x/asset-swapper@16.49.3
2022-02-10 12:12:08 +00:00
Github Actions
3aef29dace Updated CHANGELOGS & MD docs 2022-02-10 12:12:05 +00:00
Kim Persson
9a16e00577 fix: router RFQ underutilization (#413)
* fix: pass EP overhead to Path & use path comparison all & vip routes

* chore: add changelog entry for asset-swapper
2022-02-10 12:55:30 +01:00
Kim Persson
84e4819e6e feat: Improve Uniswap V3 gas schedule (#397)
* feat: UniswapV3Sampler use QuoterV2 for sells WIP

* feat: UniswapV3Sampler for QuoterV2 buys WIP

* refactor: separate logic to remove stack too deep issue

* feat: Use initializedTicksCrossed from Uniswap QuoterV2 for gas est.

* fix: use Quoter gasUsed instead of estimating gas from pools + ticks

* refactor: clean up UniswapV3Sampler & remove old Quoter interface

* refactor: unify code for buys and sells while handling stack too deep

* fix: use mean gas price from all sample estimating UniV3 gas schedule

* fix: fallback to legacy Uniswap V3 gas estimate if we can't get gasUsed

* refactor: use named function instead of fat arrow

* chore: add asset-swapper changelog entry
2022-02-10 11:16:24 +01:00
Kim Persson
25dd6bc79a fix: incorrect output scaling when input is less than desired amount (#401)
* fix: incorrect output scaling when input is less than desired amount

* chore: bump fast-abi

* chore: add changelog entry for asset-swapper
2022-02-10 10:43:44 +01:00
Jacob Evans
5d2cdb00c2 fix: slippage inconsistency when recalculated in exchange proxy quote consumer (#412)
* fix: Pass slippage down rather than recalculate due to accuracy

* CHANGELOG
2022-02-04 10:37:38 +10:00
Github Actions
0f701f42d3 Publish
- @0x/asset-swapper@16.49.2
2022-01-31 18:24:47 +00:00
Github Actions
3e3e82d3f7 Updated CHANGELOGS & MD docs 2022-01-31 18:24:44 +00:00
Lawrence Forman
c57bf86273 Fix ABI encoding error with two hop buys due to applying slippage to uint(-1) values (#410)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2022-01-31 12:51:17 -05:00
Github Actions
f470d282ee Publish
- @0x/asset-swapper@16.49.1
2022-01-31 07:20:03 +00:00
Github Actions
b8a2526da5 Updated CHANGELOGS & MD docs 2022-01-31 07:19:59 +00:00
Jacob Evans
97575bbde9 fix: worstCaseQuoteInfo calculating buys incorrectly [TKR-296] (#402)
* fix: WorstCaseQuoteInfo buy encoding

* CHANGELOG
2022-01-31 17:01:17 +10:00
Github Actions
e5ed8b2c81 Publish
- @0x/asset-swapper@16.49.0
2022-01-28 22:11:46 +00:00
Github Actions
61fbae3ae2 Updated CHANGELOGS & MD docs 2022-01-28 22:11:42 +00:00
Shawn
5c2255c841 feat: add curve pools (#409)
* feat: Additional Curve pools

* more pools

* fix the format

* changlog

* lowercase address

Co-authored-by: Jacob Evans <jacob@dekz.net>
2022-01-28 12:08:28 -08:00
Github Actions
e036dee6c5 Publish
- @0x/asset-swapper@16.48.0
2022-01-25 22:00:25 +00:00
Github Actions
8583aab241 Updated CHANGELOGS & MD docs 2022-01-25 22:00:21 +00:00
Jacob Evans
5d05b62821 chore: Use MIM on Fantom as an intermediary asset (#405) 2022-01-26 07:42:29 +10:00
Github Actions
0063e8178f Publish
- @0x/asset-swapper@16.47.0
2022-01-25 18:51:07 +00:00
Github Actions
ec6e5dd517 Updated CHANGELOGS & MD docs 2022-01-25 18:51:04 +00:00
Noah Khamliche
9d08fefa1c Feat/synapse (#400)
* added synapse support
2022-01-25 13:21:07 -05:00
Github Actions
2fdca24d4e Publish
- @0x/asset-swapper@16.46.0
2022-01-11 01:10:02 +00:00
Github Actions
42ec0b144e Updated CHANGELOGS & MD docs 2022-01-11 01:09:58 +00:00
Jacob Evans
3f6ce78b46 chore: Enable Curve ETH/CVX (#394)
* chore: Enable Curve ETH/CVX

* pr number
2022-01-11 09:32:07 +10:00
Github Actions
c1300c1068 Publish
- @0x/asset-swapper@16.45.2
2022-01-10 15:09:26 +00:00
Github Actions
9a641cfab6 Updated CHANGELOGS & MD docs 2022-01-10 15:09:23 +00:00
Kim Persson
60345d4465 fix: don't create fills for 0 output samples and negative adjusted rate orders (#387)
* fix: don't try to create fills for 0 output samples

* fix: negative adjusted output native orders causing undefined fills

* fix: make sure to use the same sourcePathId for fills from same source

* fix: should be same sourcePathId within the same DexSample[]

* fix: split native orders into 13 samples to align with interpolation

* chore: add changelog entry for asset-swapper
2022-01-10 14:55:03 +01:00
Github Actions
11dfea47a6 Publish
- @0x/asset-swapper@16.45.1
2022-01-05 05:08:43 +00:00
Github Actions
55e9dd39a2 Updated CHANGELOGS & MD docs 2022-01-05 05:08:41 +00:00
Jacob Evans
1993929bed chore: Celo Update certain tokens since Optics v2 (#390)
* chore: Celo Update certain tokens since Optics v2

* Changelog
2022-01-05 14:44:29 +10:00
Oskar Paolini
e1d81de517 fixes axios object dumping in logs (#345) 2022-01-05 09:46:01 +10:00
Github Actions
a6b3a21635 Publish
- @0x/asset-swapper@16.45.0
2022-01-04 15:00:16 +00:00
Github Actions
fd59cdc2db Updated CHANGELOGS & MD docs 2022-01-04 15:00:13 +00:00
Jacob Evans
98e11b5189 feat: Capture Routing timing metrics (#388) 2022-01-04 15:42:14 +01:00
Github Actions
3bebc7cd62 Publish
- @0x/asset-swapper@16.44.0
2021-12-29 11:45:33 +00:00
Github Actions
56dab6ae8c Updated CHANGELOGS & MD docs 2021-12-29 11:45:30 +00:00
Kim Persson
285f98e9e9 feat: Udate neon-router and use router estimated output amount (#354)
* feat: use Rust router estimated output amount when possible

* fix: use strings for sample ids, and increase samples in the rust router

* fix: remove unnecessary interpolation of out of range values

* fix: don't recalculate sampled dist sum in a loop

* fix: use 14 samples for rust router to work around interpolation issues

* fix: unintentional logic change

* fix: remove local dev plotting param from route fn call

* feat: make neon-router number of samples configurable

* chore: bump to newly published neon-router version

* fix: handle insufficient liquidity at all requested sources

* chore: update asset-swapper changelog
2021-12-29 12:08:24 +01:00
Github Actions
8ae9f59f20 Publish
- @0x/contracts-erc20@3.3.25
 - @0x/contracts-test-utils@5.4.16
 - @0x/contracts-treasury@1.4.8
 - @0x/contracts-utils@4.8.6
 - @0x/contracts-zero-ex@0.30.1
 - @0x/asset-swapper@16.43.0
 - @0x/contract-addresses@6.11.0
 - @0x/contract-wrappers@13.18.5
 - @0x/migrations@8.1.14
 - @0x/protocol-utils@1.10.1
2021-12-24 16:45:24 +00:00
Github Actions
4c341c5ca3 Updated CHANGELOGS & MD docs 2021-12-24 16:45:21 +00:00
Shawn
a3c912c2af feat/optimism [TKR-280] (#385)
* rebase and remove WIP Clipper new weth router test

* remove clipper test

* restore from clipper test

* add uniswapV3 on optimism

* modify token addresses and add EP-related addresses on optimism

* prettier

* modify CHANGLOG.json

* convert addresses to lowercase

* remove testnet addresses

Co-authored-by: Romain Butteaud <romain.butteaud@gmail.com>
2021-12-24 08:28:06 -08:00
Github Actions
5e72eb9af9 Publish
- @0x/asset-swapper@16.42.0
2021-12-21 22:02:45 +00:00
Github Actions
9b08b73c06 Updated CHANGELOGS & MD docs 2021-12-21 22:02:41 +00:00
Jacob Evans
76c7eb7c3e fix: Beethovenx graphql endpoint (#383) 2021-12-22 07:44:25 +10:00
Jacob Evans
9b2e5a3adb fix: PR number in CHANGELOG 2021-12-22 08:11:28 +11:00
Jacob Evans
813d703d12 feat: UniswapV3 on Polygon (#382) 2021-12-22 07:10:21 +10:00
Github Actions
83005d0f3d Publish
- @0x/asset-swapper@16.41.0
2021-12-06 21:48:27 +00:00
Github Actions
d07ffd2688 Updated CHANGELOGS & MD docs 2021-12-06 21:48:24 +00:00
Noah Khamliche
4170f970d0 Sushi router celo fix (#376)
* Updated Sushiswap router on CELO 

Sushi address in the docs was incorrect, this is the correct address `0x1421bDe4B10e8dd459b3BCb598810B1337D56842`.

* address to lowercase

* Update CHANGELOG.json

* fixed sushi router address, replaced celo ref with wcelo, fixed mcusd address

* celo->wcelo

* Update packages/asset-swapper/CHANGELOG.json

Co-authored-by: Jacob Evans <jacob@dekz.net>

* changelog

* version bump

Co-authored-by: Jacob Evans <jacob@dekz.net>
2021-12-06 13:31:45 -08:00
Github Actions
dcde12dd70 Publish
- @0x/contracts-erc20@3.3.24
 - @0x/contracts-test-utils@5.4.15
 - @0x/contracts-treasury@1.4.7
 - @0x/contracts-utils@4.8.5
 - @0x/contracts-zero-ex@0.30.0
 - @0x/asset-swapper@16.40.0
 - @0x/contract-addresses@6.10.0
 - @0x/contract-wrappers@13.18.4
 - @0x/migrations@8.1.13
 - @0x/protocol-utils@1.10.0
2021-12-01 20:22:43 +00:00
Github Actions
84a60ec982 Updated CHANGELOGS & MD docs 2021-12-01 20:22:39 +00:00
Kim Persson
9615570dc6 feat: deploy interest tokens (#321)
* feat: Aave aToken deposit/withdrawal [TKR-111] (#293)

* feat: AaveV2 deposit/withdrawal integration WIP

* feat: add basic Aave Reserves cache with data from subgraphs WIP

* feat: hook up Aave Reserves integration

* fix: set allowance before trade & use ERC20 token interface

* refactor: pass aToken to mixin to avoid lookup

* fix: migrate from swap/revert to normal sampling

* fix: Aave gas estimate & refactor to clean up code

* feat: Create a sampler no operation type and make AaveV2Sampler a no-op

* fix: Clipper merge conflict resolution issues

* fix: don't fetch unnecessary Aave pool data & clean up code

* chore: Add changelog entries

* feat: cToken deposit/withdrawal [TKR-222] (#294)

* feat: first stab at a CompoundSampler implementation

* feat: MixinCompound implementation WIP

* feat: Compound integration with cache WIP

* fix: decimals scaling in CompoundSampler

* feat: handle minting and redeeming of cETH

* fix: adjust Compound gas schedule

* refactor: clean up code and add comments in cToken cache

* fix: MixinCompound check allowance on WETH withdrawal & fix indentation

* fix: address review comments and clean up code

* chore: add changelog entries

* feat: enable AaveV2 on Avalanche

* chore: add freshly deployed FQT on Polygon, Avalanche

* fix: temporarily disable on Ethereum mainnet until we redeploy EP

* fix: address PR comments and update changelogs

* fix: correct contract-addresses changelog note
2021-12-01 17:10:22 +01:00
Jacob Evans
880a9c3da0 chore: Curve added ETH/CRV pool (#378) 2021-12-01 14:51:47 +10:00
Jacob Evans
c44bd9d42d Revert "chore: Curve added ETH/CRV pool"
This reverts commit 90b441330b.
2021-12-01 14:19:49 +10:00
Jacob Evans
90b441330b chore: Curve added ETH/CRV pool 2021-12-01 14:17:40 +10:00
Github Actions
e12ed1eddf Publish
- @0x/asset-swapper@16.38.0
2021-11-29 23:23:57 +00:00
Github Actions
ac94023ab3 Updated CHANGELOGS & MD docs 2021-11-29 23:23:54 +00:00
Jacob Evans
281e6acca5 chore: Add ability to capture sampler metrics (#374)
* chore: Add ability to capture sampler metrics

* Added block number metrics
2021-11-30 09:06:05 +10:00
Github Actions
2f1b520409 Publish
- @0x/asset-swapper@16.37.0
2021-11-19 19:15:43 +00:00
Github Actions
21b4eb3d26 Updated CHANGELOGS & MD docs 2021-11-19 19:15:40 +00:00
Noah Khamliche
644f6c7d28 removed comma 2021-11-19 13:46:57 -05:00
Noah Khamliche
0647b9e4f8 Update CHANGELOG.json 2021-11-19 13:46:57 -05:00
Noah Khamliche
82d42eeede address to lowercase 2021-11-19 13:46:57 -05:00
Noah Khamliche
6ef4d95043 Updated Sushiswap router on CELO
Sushi address in the docs was incorrect, this is the correct address `0x1421bDe4B10e8dd459b3BCb598810B1337D56842`.
2021-11-19 13:46:57 -05:00
Github Actions
6044140f86 Publish
- @0x/asset-swapper@16.36.0
2021-11-19 02:59:33 +00:00
Github Actions
4da1ef0f56 Updated CHANGELOGS & MD docs 2021-11-19 02:59:30 +00:00
Jacob Evans
8c668a3918 feat: Specify FEI/TRIBE liquid pool (#371)
* feat: Specify FEI/TRIBE liquid pool

* CHANGELOG

* FXS/FRAX and OHM/FRAX
2021-11-18 15:39:07 +10:00
Github Actions
f1ff1cde39 Publish
- @0x/asset-swapper@16.35.0
2021-11-18 03:31:36 +00:00
Github Actions
1668a24e31 Updated CHANGELOGS & MD docs 2021-11-18 03:31:32 +00:00
Shawn
4b7c376d96 feat: Add Beethoven X, MorpheusSwap and JetSwap on Fantom (#370)
* Rebase to development branch

* add support for MorpheusSwap and JetSwap on Fantom

* fix lint

* modify changelog.json for asset-swapper

* fix the comments

* prettier

* Use BalancerV2PoolsCache for BeethovenX

Co-authored-by: Romain Butteaud <romain.butteaud@gmail.com>
2021-11-17 19:14:01 -08:00
Github Actions
bb4a9c656c Publish
- @0x/contracts-erc20@3.3.23
 - @0x/contracts-test-utils@5.4.14
 - @0x/contracts-treasury@1.4.6
 - @0x/contracts-utils@4.8.4
 - @0x/contracts-zero-ex@0.29.5
 - @0x/asset-swapper@16.34.0
 - @0x/contract-addresses@6.9.0
 - @0x/contract-wrappers@13.18.3
 - @0x/migrations@8.1.12
 - @0x/protocol-utils@1.9.5
2021-11-16 22:49:46 +00:00
Github Actions
6ab07b6304 Updated CHANGELOGS & MD docs 2021-11-16 22:49:43 +00:00
Noah Khamliche
8903f1ab01 Update packages/contract-addresses/CHANGELOG.json
Co-authored-by: Lawrence Forman <lawrence@0xproject.com>
2021-11-16 16:55:57 -05:00
Noah Khamliche
415535612a removed duplicate celo code 2021-11-16 16:55:57 -05:00
Noah Khamliche
5248a135c3 upped versions in changelog 2021-11-16 16:55:57 -05:00
Lawrence Forman
602290925c fix celo rebase 2021-11-16 16:55:57 -05:00
Github Actions
01813746e8 Publish
- @0x/contracts-zero-ex@0.29.4
 - @0x/asset-swapper@16.33.0
 - @0x/migrations@8.1.11
2021-11-16 12:27:06 +00:00
Github Actions
7d668d8801 Updated CHANGELOGS & MD docs 2021-11-16 12:27:02 +00:00
Jacob Evans
797a00a33a feat: Uniswap V3 1bps pools [TKR-263] (#366)
* feat: Uniswap V3 1bps pools

* Update CHANGELOG
2021-11-16 08:15:24 +10:00
Lawrence Forman
4b3d98f43c @0x/contracts-zero-ex: Prevent EP ETH balance from reducing when executin mtxs (#365)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2021-11-09 22:11:36 -05:00
Github Actions
9ff77c1cd5 Publish
- @0x/asset-swapper@16.32.0
2021-11-09 19:36:14 +00:00
Github Actions
18a8351671 Updated CHANGELOGS & MD docs 2021-11-09 19:36:10 +00:00
Jorge Pérez
9a994dfcd3 fix: Extended Quote Report Changelog typo 2021-11-09 13:17:14 -06:00
Jorge Pérez
b7adc5a889 feat: Extended Quote Report
* Extended Quote report for indicative quote

* feat: Only save 'full' quotes on quote report

* Unify extended quote report
2021-11-09 13:05:01 -06:00
Github Actions
10b0d7f363 Publish
- @0x/asset-swapper@16.31.0
2021-11-04 06:52:28 +00:00
Github Actions
e2c905a15f Updated CHANGELOGS & MD docs 2021-11-04 06:52:25 +00:00
Jacob Evans
8589ba728c feat: [Avalanche] Add Curve, CurveV2 and KyberDMM (#363)
* feat: [Avalanche] Add Curve, CurveV2 and KyberDMM

* CHANGELOG

* fix missing file

* lint
2021-11-04 16:34:48 +10:00
Github Actions
43512fd07a Publish
- @0x/contracts-erc20@3.3.22
 - @0x/contracts-test-utils@5.4.13
 - @0x/contracts-treasury@1.4.5
 - @0x/contracts-utils@4.8.3
 - @0x/contracts-zero-ex@0.29.3
 - @0x/asset-swapper@16.30.1
 - @0x/contract-addresses@6.8.1
 - @0x/contract-wrappers@13.18.2
 - @0x/migrations@8.1.10
 - @0x/protocol-utils@1.9.4
2021-11-03 01:40:34 +00:00
Github Actions
c090608d99 Updated CHANGELOGS & MD docs 2021-11-03 01:40:30 +00:00
phil-ociraptor
89817428ed chore: add OtcOrder feature to fullMigrateAsync (#350) 2021-11-02 20:19:27 -05:00
Lawrence Forman
fce3664258 @0x/contracts-zero-ex: Register transformERC20() and remove transformERC20Staging() (#355)
Co-authored-by: Lawrence Forman <me@merklejerk.com>
2021-10-25 20:08:58 -04:00
Github Actions
aa522fe49b Publish
- @0x/contracts-erc20@3.3.21
 - @0x/contracts-test-utils@5.4.12
 - @0x/contracts-treasury@1.4.4
 - @0x/contracts-utils@4.8.2
 - @0x/contracts-zero-ex@0.29.2
 - @0x/asset-swapper@16.30.0
 - @0x/contract-addresses@6.8.0
 - @0x/contract-wrappers@13.18.1
 - @0x/migrations@8.1.9
 - @0x/protocol-utils@1.9.3
2021-10-19 18:27:29 +00:00
Github Actions
c03653ebd7 Updated CHANGELOGS & MD docs 2021-10-19 18:27:25 +00:00
Shawn
ae08f77381 Feat/ftm (#347)
* ftm deployment

* add Fantom Curve

* add support for ftm

* add more Fantom liquidity sources

* clean up codes

* lint

* prettier codes

* modify CHANGLOG

* undo some changes

* use lowercase addresses

* Update EP FlashWallet

* Update addresses and remove timestamps

Co-authored-by: Jacob Evans <jacob@dekz.net>

* Cleanup

* cleanup json

Co-authored-by: Romain Butteaud <romain.butteaud@gmail.com>
Co-authored-by: Jacob Evans <jacob@dekz.net>
2021-10-19 09:51:07 -07:00
761 changed files with 52883 additions and 65860 deletions

View File

@@ -1,209 +0,0 @@
version: 2.1
jobs:
build:
resource_class: xlarge
docker:
- image: node:12
environment:
NODE_OPTIONS: '--max-old-space-size=16384'
working_directory: ~/repo
steps:
- checkout
- run: echo 'export PATH=$HOME/CIRCLE_PROJECT_REPONAME/node_modules/.bin:$PATH' >> $BASH_ENV
- run:
name: install-yarn
command: npm install --force --global yarn@1.22.0
- run:
name: yarn
command: yarn --frozen-lockfile --ignore-engines install || yarn --frozen-lockfile --ignore-engines install
- setup_remote_docker
- run: yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci || yarn build:ci
- run: yarn build:ts || yarn build:ts || yarn build:ts || yarn build:ts || yarn build:ts || yarn build:ts
- save_cache:
key: repo-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo
- store_artifacts:
path: ~/repo/packages/abi-gen/test-cli/output
- store_artifacts:
path: ~/repo/packages/contract-wrappers/generated_docs
test-exchange-ganache:
resource_class: medium+
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun -p @0x/contracts-exchange -m --serial -c test:circleci
test-integrations-ganache:
resource_class: medium+
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun -p @0x/contracts-integrations -m --serial -c test:circleci
test-contracts-staking-ganache:
resource_class: medium+
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun -p @0x/contracts-staking -m --serial -c test:circleci
test-contracts-extra-ganache:
resource_class: medium+
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun -p @0x/contracts-exchange-forwarder -p @0x/contracts-coordinator -m --serial -c test:circleci
test-contracts-rest-ganache:
resource_class: medium+
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun -p @0x/contracts-multisig -p @0x/contracts-utils -p @0x/contracts-exchange-libs -p @0x/contracts-erc20 -p @0x/contracts-erc721 -p @0x/contracts-erc1155 -p @0x/contracts-asset-proxy -p @0x/contracts-broker -p @0x/contracts-zero-ex -m --serial -c test:circleci
test-publish:
resource_class: large
environment:
NODE_OPTIONS: '--max-old-space-size=6442'
docker:
- image: node:12
- image: 0xorg/verdaccio
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: yarn test:publish:circleci
no_output_timeout: 1800
- store_artifacts:
path: ~/.npm/_logs
test-doc-generation:
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run:
command: yarn test:generate_docs:circleci
no_output_timeout: 1200
test-rest:
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn wsrun -p @0x/contracts-test-utils -m --serial -c test:circleci
- run: yarn wsrun -p @0x/contract-artifacts -m --serial -c test:circleci
- run: yarn wsrun -p @0x/contract-wrappers-test -m --serial -c test:circleci
- run: yarn wsrun -p @0x/migrations -m --serial -c test:circleci
- run: yarn wsrun -p @0x/order-utils -m --serial -c test:circleci
- run: yarn wsrun -p @0x/asset-swapper -m --serial -c test:circleci
- save_cache:
key: coverage-contract-wrappers-test-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/packages/contract-wrappers-test/coverage/lcov.info
- save_cache:
key: coverage-order-utils-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/packages/order-utils/coverage/lcov.info
- save_cache:
key: coverage-web3-wrapper-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/packages/web3-wrapper/coverage/lcov.info
static-tests:
resource_class: large
working_directory: ~/repo
docker:
- image: node:12
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn lerna run lint
- run: yarn prettier:ci
- run: yarn deps_versions:ci
- run: yarn diff_md_docs:ci
submit-coverage:
docker:
- image: node:12
working_directory: ~/repo
steps:
- restore_cache:
keys:
- repo-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-contract-wrappers-test-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-order-utils-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-contracts-{{ .Environment.CIRCLE_SHA1 }}
- run: yarn report_coverage
workflows:
version: 2
main:
jobs:
- build
# Disabled until we begin actively developing on these packages again.
# - test-exchange-ganache:
# requires:
# - build
# - test-integrations-ganache:
# requires:
# - build
# - test-contracts-staking-ganache:
# requires:
# - build
# - test-contracts-extra-ganache:
# requires:
# - build
- test-contracts-rest-ganache:
requires:
- build
- test-rest:
requires:
- build
- static-tests:
requires:
- build
- test-publish:
requires:
- build
- test-doc-generation:
requires:
- build
# Disabled until this repo has a coveralls API key
# - submit-coverage:
# requires:
# # Disabled until we begin actively developing on these packages again.
# # - test-exchange-ganache
# # - test-integrations-ganache
# # - test-contracts-staking-ganache
# # - test-contracts-extra-ganache
# - test-contracts-rest-ganache
# - test-rest
# - static-tests

18
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1,18 @@
# See https://help.github.com/articles/about-codeowners/
# for more info about CODEOWNERS file
# It uses the same pattern rule for gitignore file
# https://git-scm.com/docs/gitignore#_pattern_format
# Dev tools & setup
.github/ @dekz
packages/contract-addresses/ @dekz @dextracker @kyu-c
packages/contract-artifacts/ @dekz
packages/protocol-utils/ @dekz
# Protocol/smart contracts
contracts/ @dekz @dextracker

View File

@@ -8,13 +8,13 @@ We welcome contributions from anyone on the internet and are grateful for even t
2. Clone your fork
3. Follow the [installation & build steps](https://github.com/0xProject/0x-tools#install-dependencies) in the repo's top-level README.
4. Setup the recommended [Development Tooling](#development-tooling).
5. Open a PR with the `[WIP]` flag against the `development` branch and describe the change you are intending to undertake in the PR description. (see [our branch naming conventions](#branch-structure))
5. Open a [draft PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/) against the `development` branch and describe the change you are intending to undertake in the PR description. (see [our branch naming conventions](#branch-structure))
Before removing the `[WIP]` tag and submitting the PR for review, make sure:
Before making the PR "Ready for review", make sure:
- It passes our linter checks (`yarn lint`)
- It is properly formatted with Prettier (`yarn prettier`)
- It passes our continuous integration tests (See: [Enabling code coverage checks on your fork](#enabling-code-coverage-checks-on-your-fork) for instructions on getting the `submit-coverage` test to pass on forks)
- It passes our continuous integration tests (See: [Enabling code coverage checks on your fork](#fix-submit-coverage-ci-failure) for instructions on getting the `submit-coverage` test to pass on forks)
- You've created/updated the corresponding [CHANGELOG](#CHANGELOGs) entries.
- Your changes have sufficient test coverage (e.g regression tests have been added for bug fixes)
@@ -59,16 +59,14 @@ We strongly recommend you use the [VSCode](https://code.visualstudio.com/) text
#### Linter
We use [TSLint](https://palantir.github.io/tslint/) with [custom configs](https://github.com/0xProject/0x-tools/tree/development/packages/tslint-config) to keep our code-style consistent.
We use [ESLint](https://eslint.org/docs/latest/) to keep our code-style consistent.
Use `yarn:lint` to lint the entire monorepo, and `PKG={PACKAGE_NAME} yarn lint` to lint a specific package.
If you want to change a rule, or add a custom rule, please make these changes to our [tslint-config](https://github.com/0xProject/0x-tools/tree/development/packages/tslint-config) package. All other packages have it as a dependency.
Use `yarn lint` to lint the entire monorepo, and `PKG={PACKAGE_NAME} yarn lint` to lint a specific package.
Integrate it into your text editor:
- VSCode: [vscode-tslint](https://marketplace.visualstudio.com/items?itemName=eg2.tslint)
- Atom: [linter-tslint](https://atom.io/packages/linter-tslint)
- VSCode: [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- Atom: [ESLint](https://atom.io/packages/eslint)
#### Auto-formatter
@@ -91,15 +89,3 @@ A few of our coding conventions are not yet enforced by the linter/auto-formatte
1. If you _must_ cast a variable to any - try to type it back as fast as possible. (e.g., `const cw = ((zeroEx as any)._contractWrappers as ContractWrappers);`). This ensures subsequent code is type-safe.
1. Our enum conventions coincide with the recommended TypeScript conventions, using capitalized keys, and all-caps snake-case values. Eg `GetStats = 'GET_STATS'`
1. All public, exported methods/functions/classes must have associated Javadoc-style comments.
### Fix `submit-coverage` CI failure
If you simply fork the repo and then create a PR from it, your PR will fail the `submit-coverage` check on CI. This is because the 0x CircleCI configuration sets the `COVERALLS_REPO_TOKEN` environment variable to the token for `0xProject/0x-tools`, but when running the check against your fork the token needs to match your repo's name `your-username/0x-tools`.
To facilitate this check, after creating your fork, but before creating the branch for your PR, do the following:
1. Log in to [coveralls.io](https://coveralls.io/), go to `Add Repos`, and enable your fork. Then go to the settings for that repo, and copy the `Repo Token` identifier.
2. Log in to [CircleCI](https://circleci.com/login), go to `Add Projects`, click the `Set Up Project` button corresponding to your fork, and then click `Start Building`. (Aside from step 3 below, no actual set up is needed, since it will use the `.circleci/config.yml` file in 0x-tools, so you can ignore all of the instruction/explanation given on the page with the `Start Building` button.)
3. In CircleCI, configure your project to add an environment variable, with name `COVERALLS_REPO_TOKEN`, and for the value paste in the `Repo Token` you copied in step 1.
Now, when you push to your branch, CircleCI will automatically run all of the checks in your own instance, and the coverage check will work since it has the proper `Repo Token`, and the PR will magically refer to your own checks rather than running them in the 0x CircleCI instance.

View File

@@ -2,15 +2,13 @@
<!--- Before submitting please check to see if this issue was already reported -->
<!--- Prefix your issue title with the package name it relates to (e.g., `0x.js: ` or `general:`) -->
## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a package change/improvement, tell us how it should work -->
<!--- If you're suggesting a contract or protocol change/improvement, visit our ZEIPs repo -->
<!--- If you're suggesting a contract or protocol change/improvement, visit our ZEIPs repo https://github.com/0xProject/ZEIPs -->
## Current Behavior
@@ -50,8 +48,8 @@
| ------: | :------ |
<!-- For example:
| `0x.js` | 2.0.4 |
| `Exchange Contract` | v2 |
| `protocol-utils` | 2.0.4 |
| `Exchange Contract` | v3 |
-->
| Network |
@@ -60,6 +58,6 @@
<!-- For example:
| mainnet |
| kovan |
| testrpc |
| goerli |
| development |
-->

View File

@@ -20,7 +20,6 @@
<!--- The following points should be used to indicate the progress of your PR. Put an `x` in all the boxes that apply right now, and come back over time and check them off as you make progress. If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] Prefix PR title with `[WIP]` if necessary.
- [ ] Add tests to cover changes as needed.
- [ ] Update documentation as needed.
- [ ] Add new entries to the relevant CHANGELOG.jsons.

View File

@@ -1,7 +1,2 @@
python: ['python-packages']
contracts: ['contracts']
@0x/contract-addresses: ['packages/contract-addresses']
@0x/migrations: ['packages/migrations']
@0x/order-utils: ['packages/order-utils']
@0x/contract-artifacts: ['packages/contract-artifacts']
@0x/contract-wrappers: ['packages/contract-wrappers']
documentation: ['docs']
liquidity integrations: ['contracts/zero-ex/contracts/src/transformers']

7
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
target-branch: "development"

19
.github/stale.yml vendored
View File

@@ -1,19 +0,0 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 30
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 30
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: >
This issue has been automatically closed because no activity occured in 7 days after being marked as stale. If it's still relevant - feel free to reopen. Thank you
for your contributions.

163
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,163 @@
name: Continuous Integration
on:
push:
branches:
- main
- development
pull_request:
jobs:
build:
name: Build and test
runs-on: ubuntu-latest
env:
ARBITRUM_RPC_URL: ${{ secrets.ARBITRUM_RPC_URL }}
AVALANCHE_RPC_URL: ${{ secrets.AVALANCHE_RPC_URL }}
BSC_RPC_URL: ${{ secrets.BSC_RPC_URL }}
FANTOM_RPC_URL: ${{ secrets.FANTOM_RPC_URL }}
MAINNET_RPC_URL: ${{ secrets.MAINNET_RPC_URL }}
OPTIMISM_RPC_URL: ${{ secrets.OPTIMISM_RPC_URL }}
POLYGON_RPC_URL: ${{ secrets.POLYGON_RPC_URL }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Add foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build solution
run: yarn build
- name: Lint typescript
run: yarn lint:ts
- name: Lint solidity
run: yarn lint:contracts
- name: Run prettier
run: yarn prettier:ci
- name: Check dependent packages have consistent versions
run: yarn deps_versions:ci
- name: Check diff in docs
run: yarn diff_md_docs:ci
- name: Check for broken links in markdown files
run: yarn test:links
- name: Test doc generation
run: yarn test:generate_docs:ci
- name: Test @0x/contracts-*
run: |
yarn wsrun \
-p @0x/contracts-multisig \
-p @0x/contracts-utils \
-p @0x/contracts-exchange-libs \
-p @0x/contracts-erc721 \
-p @0x/contracts-erc1155 \
-p @0x/contracts-asset-proxy \
-p @0x/contracts-broker \
-p @0x/contracts-zero-ex \
-m --serial -c test:ci
- name: Test local @0x/contracts-*
run: |
yarn wsrun \
-p @0x/contracts-test-utils \
-p @0x/contract-addresses \
-p @0x/contract-artifacts \
-p @0x/contract-wrappers-test \
-p @0x/order-utils \
-m --serial -c test:ci
# NOTE: disabled as ZRXToken.sol did not compile with the latest forge.
# TODO: re-enable once the issue is resolved.
- name: Run Forge build for erc20
working-directory: contracts/erc20
run: |
forge --version
forge build --sizes --skip ZRXToken
# - name: Run Forge tests for erc20
# working-directory: contracts/erc20
# run: |
# forge test -vvv --gas-report
# - name: Run Forge coverage for erc20
# working-directory: contracts/erc20
# run: |
# forge coverage --report summary --report lcov
# - name: Upload the coverage report to Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# base-path: ./contracts/erc20/
# path-to-lcov: ./contracts/erc20/lcov.info
- name: Run Forge build for zero-ex
working-directory: contracts/zero-ex
run: |
forge --version
forge build --sizes
- name: Run Forge tests for zero-ex
working-directory: contracts/zero-ex
run: |
forge test -vvv --gas-report
- name: Run Forge coverage for zero-ex
working-directory: contracts/zero-ex
run: |
forge coverage --report summary --report lcov
- name: Upload the coverage report to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
base-path: ./contracts/zero-ex/
path-to-lcov: ./contracts/zero-ex/lcov.info
- name: Check coverage threshold
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: ./contracts/zero-ex/lcov.info
min_coverage: 6.98
exclude: '**/tests'
- name: Run Forge build on governance contracts
working-directory: ./contracts/governance
run: |
forge --version
forge build --sizes
# TODO: re-enable once the issue is resolved.
# - name: Run Forge tests on governance contracts
# working-directory: ./contracts/governance
# run: |
# forge test -vvv --gas-report
# - name: Run Forge coverage on governance contracts
# working-directory: ./contracts/governance
# run: |
# forge coverage --report lcov
# - name: Upload the coverage report to Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# base-path: ./contracts/governance/
# path-to-lcov: ./contracts/governance/lcov.info

View File

@@ -1,19 +1,21 @@
name: publish
on:
workflow_dispatch:
inputs:
ci_status:
description: 'required CI status'
default: 'success'
required: true
prerelease:
description: 'prerelease name'
required: false
workflow_dispatch:
inputs:
ci_status:
description: 'required CI status'
default: 'success'
required: true
prerelease:
description: 'prerelease name'
required: false
jobs:
publish:
runs-on: ubuntu-latest
env:
PublishBranch: publish/${{github.ref_name }}-${{ github.run_id }}-${{ github.run_number }}
steps:
- name: 'check successful status'
run: |
@@ -22,18 +24,26 @@ jobs:
| jq .state)
[[ "${REF_STATUS}" == '"${{ github.event.inputs.ci_status }}"' ]] || \
(echo "::error ::${{ github.ref }} does not have a successful CI status" && false)
- name: Add foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
fetch-depth: 0
ref: ${{ github.ref }}
fetch-depth: 0
- uses: actions/setup-node@v1
with:
node-version: 10
node-version: 16
- uses: actions/setup-python@v2
- name: 'configure git'
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "Github Actions"
- name: 'Checkout new branch'
run: |
git checkout -b $PublishBranch
git push -u origin $PublishBranch
- name: 'install dependencies'
run: |
yarn -D
@@ -45,9 +55,23 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PUBLISH_PRERELEASE: ${{ github.event.inputs.prerelease }}
- name: 'merge into main branch'
if: github.event.inputs.prerelease == '' # unless it's a prerelease
- name: 'Create PR to merge into ref branch'
run: |
git checkout main && \
git merge ${{ github.ref }} && \
git push
gh pr create \
-B ${{ github.ref_name }} \
-H $PublishBranch \
--title "Publish: CHANGELOG and Package Version Updates into ${{ github.ref_name }}" \
--body "Syncing CHANGELOG and package version updates from publish action ${{github.run_id}}-${{github.run_number}} into ${{ github.ref_name}} branch" \
--reviewer ${{ github.actor }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: 'Create PR to merge ref branch into main'
run: |
gh pr create \
-B main \
-H ${{ github.ref_name }} \
--title "Publish: Sync ${{ github.ref_name }} into main " \
--body "Syncing ${{ github.ref_name }} back into main after publish action. NOTE: this PR should be merged after CHANGELOG and package version updates have been merged into ${{ github.ref_name }}" \
--reviewer ${{ github.actor }}
env:
GITHUB_TOKEN: ${{ github.token }}

40
.github/workflows/stale.yml vendored Normal file
View File

@@ -0,0 +1,40 @@
name: "Close stale issues and PRs"
on:
schedule:
- cron: "0 8 * * 1-5" # This is in UTC.
# Do a dry-run (debug-only: true) whenever this workflow itself is changed.
pull_request:
paths:
- .github/workflows/stale.yml
types:
- opened
- synchronize
permissions:
issues: write
pull-requests: write
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v7
with:
ascending: true # Spend API operations budget on older, more-likely-to-get-closed issues first
close-issue-message: "" # Leave no comment when closing
close-pr-message: "" # Leave no comment when closing
days-before-issue-stale: 30
days-before-pr-stale: 30
days-before-close: 14
debug-only: ${{ github.event_name == 'pull_request' }} # Dry-run when true.
exempt-issue-labels: bug,enhancement,feature,question
# No actual changes get made in debug-only mode, so we can raise the operations ceiling.
operations-per-run: ${{ github.event_name == 'pull_request' && 100 || 30}}
stale-issue-label: stale
stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions."
stale-pr-label: stale
stale-pr-message: "This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions."
# Time immemorial when in debug-only mode (ie. on pull requests).
# `STALEBOT_START_DATE` otherwise.
# You can use this as a killswitch by setting `STALEBOT_START_DATE` in the far future.
start-date: ${{ github.event_name == 'pull_request' && '1970-01-01T00:00:00Z' || secrets.STALEBOT_START_DATE }} # ISO 8601 or RFC 2822

132
.gitignore vendored
View File

@@ -15,9 +15,6 @@ pids
*.db
*.sqlite
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
@@ -66,7 +63,16 @@ typings/
.env
# built library using in commonjs module syntax
lib/
contracts/erc20/lib/
contracts/test-utils/lib/
contracts/treasury/lib/
contracts/utils/lib/
contracts/zero-ex/lib/
packages/contract-addresses/lib/
packages/contract-artifacts/lib/
packages/contract-wrappers/lib/
packages/protocol-utils/lib/
# UMD bundles that export the global variable
_bundles
@@ -78,105 +84,43 @@ TODO.md
# IDE file
.vscode
.idea
*~
.\#*
\#*\#
# generated contract artifacts/
contracts/broker/generated-artifacts/
contracts/broker/test/generated-artifacts/
contracts/erc20-bridge-sampler/generated-artifacts/
contracts/erc20-bridge-sampler/test/generated-artifacts/
contracts/integrations/generated-artifacts/
contracts/integrations/test/generated-artifacts/
contracts/staking/generated-artifacts/
contracts/staking/test/generated-artifacts/
contracts/coordinator/generated-artifacts/
contracts/coordinator/test/generated-artifacts/
contracts/exchange/generated-artifacts/
contracts/exchange/test/generated-artifacts/
contracts/asset-proxy/generated-artifacts/
contracts/asset-proxy/test/generated-artifacts/
contracts/multisig/generated-artifacts/
contracts/multisig/test/generated-artifacts/
contracts/utils/generated-artifacts/
contracts/utils/test/generated-artifacts/
contracts/exchange-libs/generated-artifacts/
contracts/exchange-libs/test/generated-artifacts/
contracts/erc20/generated-artifacts/
contracts/erc20/test/generated-artifacts/
contracts/erc721/generated-artifacts/
contracts/erc721/test/generated-artifacts/
contracts/erc1155/generated-artifacts/
contracts/erc1155/test/generated-artifacts/
contracts/extensions/generated-artifacts/
contracts/extensions/test/generated-artifacts/
contracts/exchange-forwarder/generated-artifacts/
contracts/exchange-forwarder/test/generated-artifacts/
contracts/dev-utils/generated-artifacts/
contracts/dev-utils/test/generated-artifacts/
contracts/zero-ex/generated-artifacts/
contracts/zero-ex/test/generated-artifacts/
contracts/treasury/generated-artifacts/
contracts/treasury/test/generated-artifacts/
# generated truffle contract artifacts/
contracts/broker/build/
contracts/erc20-bridge-sampler/build/
contracts/staking/build/
contracts/coordinator/build/
contracts/exchange/build/
contracts/asset-proxy/build/
contracts/multisig/build/
contracts/utils/build/
contracts/exchange-libs/build/
contracts/erc20/build/
contracts/erc721/build/
contracts/erc1155/build/
contracts/extensions/build/
contracts/exchange-forwarder/build/
contracts/dev-utils/build/
generated-artifacts/
# generated contract wrappers
contracts/broker/generated-wrappers/
contracts/broker/test/generated-wrappers/
packages/python-contract-wrappers/generated/
contracts/erc20-bridge-sampler/generated-wrappers/
contracts/erc20-bridge-sampler/test/generated-wrappers/
contracts/integrations/generated-wrappers/
contracts/integrations/test/generated-wrappers/
contracts/staking/generated-wrappers/
contracts/staking/test/generated-wrappers/
contracts/coordinator/generated-wrappers/
contracts/coordinator/test/generated-wrappers/
contracts/exchange/generated-wrappers/
contracts/exchange/test/generated-wrappers/
contracts/asset-proxy/generated-wrappers/
contracts/asset-proxy/test/generated-wrappers/
contracts/multisig/generated-wrappers/
contracts/multisig/test/generated-wrappers/
contracts/utils/generated-wrappers/
contracts/utils/test/generated-wrappers/
contracts/exchange-libs/generated-wrappers/
contracts/exchange-libs/test/generated-wrappers/
contracts/erc20/generated-wrappers/
contracts/erc20/test/generated-wrappers/
contracts/erc721/generated-wrappers/
contracts/erc721/test/generated-wrappers/
contracts/erc1155/generated-wrappers/
contracts/erc1155/test/generated-wrappers/
contracts/extensions/generated-wrappers/
contracts/extensions/test/generated-wrappers/
contracts/exchange-forwarder/generated-wrappers/
contracts/exchange-forwarder/test/generated-wrappers/
contracts/dev-utils/generated-wrappers/
contracts/dev-utils/test/generated-wrappers/
contracts/zero-ex/generated-wrappers/
contracts/zero-ex/test/generated-wrappers/
contracts/treasury/generated-wrappers/
contracts/treasury/test/generated-wrappers/
generated-wrappers/
# forge std-lib
contracts/zero-ex/contracts/deps/forge-std
# foundry artifacts
foundry-artifacts/
# foundry cache
cache/
foundry-cache/
#foundry output artifacts
out/
# typechain wrappers
contracts/zero-ex/typechain-wrappers/
# foundry packages
contracts/governance/cache
contracts/governance/out
# Doc README copy
packages/*/docs/README.md
.DS_Store
*~
\#*\#
.\#*
# the snapshot that gets built for migrations sure does have a ton of files
packages/migrations/0x_ganache_snapshot*

17
.gitmodules vendored Normal file
View File

@@ -0,0 +1,17 @@
[submodule "contracts/zero-ex/contracts/deps/forge-std"]
path = contracts/zero-ex/contracts/deps/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/erc20/lib/forge-std"]
path = contracts/erc20/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/governance/lib/forge-std"]
path = contracts/governance/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/governance/lib/openzeppelin-contracts"]
path = contracts/governance/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "contracts/governance/lib/openzeppelin-contracts-upgradeable"]
path = contracts/governance/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/openzeppelin-contracts-upgradeable"]
branch = v4.8.2

4
.husky/pre-commit Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged --no-stash

View File

@@ -1,90 +1,10 @@
lib
deps
.nyc_output
/contracts/broker/generated-wrappers
/contracts/broker/test/generated-wrappers
/contracts/broker/generated-artifacts
/contracts/broker/test/generated-artifacts
/contracts/integrations/generated-wrappers
/contracts/integrations/test/generated-wrappers
/contracts/integrations/generated-artifacts
/contracts/integrations/test/generated-artifacts
/contracts/staking/generated-wrappers
/contracts/staking/test/generated-wrappers
/contracts/staking/generated-artifacts
/contracts/staking/test/generated-artifacts
/contracts/coordinator/generated-wrappers
/contracts/coordinator/test/generated-wrappers
/contracts/coordinator/generated-artifacts
/contracts/coordinator/test/generated-artifacts
/contracts/exchange/generated-wrappers
/contracts/exchange/test/generated-wrappers
/contracts/exchange/generated-artifacts
/contracts/exchange/test/generated-artifacts
/contracts/asset-proxy/generated-wrappers
/contracts/asset-proxy/test/generated-wrappers
/contracts/asset-proxy/generated-artifacts
/contracts/asset-proxy/test/generated-artifacts
/contracts/multisig/generated-wrappers
/contracts/multisig/test/generated-wrappers
/contracts/multisig/generated-artifacts
/contracts/multisig/test/generated-artifacts
/contracts/utils/generated-wrappers
/contracts/utils/test/generated-wrappers
/contracts/utils/generated-artifacts
/contracts/utils/test/generated-artifacts
/contracts/exchange-libs/generated-wrappers
/contracts/exchange-libs/test/generated-wrappers
/contracts/exchange-libs/generated-artifacts
/contracts/exchange-libs/test/generated-artifacts
/contracts/erc20/generated-wrappers
/contracts/erc20/test/generated-wrappers
/contracts/erc20/generated-artifacts
/contracts/erc20/test/generated-artifacts
/contracts/erc721/generated-wrappers
/contracts/erc721/test/generated-wrappers
/contracts/erc721/generated-artifacts
/contracts/erc721/test/generated-artifacts
/contracts/erc1155/generated-wrappers
/contracts/erc1155/test/generated-wrappers
/contracts/erc1155/generated-artifacts
/contracts/erc1155/test/generated-artifacts
/contracts/extensions/generated-wrappers
/contracts/extensions/test/generated-wrappers
/contracts/extensions/generated-artifacts
/contracts/extensions/test/generated-artifacts
/contracts/exchange-forwarder/generated-wrappers
/contracts/exchange-forwarder/test/generated-wrappers
/contracts/exchange-forwarder/generated-artifacts
/contracts/exchange-forwarder/test/generated-artifacts
/contracts/dev-utils/generated-wrappers
/contracts/dev-utils/test/generated-wrappers
/contracts/dev-utils/generated-artifacts
/contracts/dev-utils/test/generated-artifacts
/contracts/zero-ex/generated-wrappers
/contracts/zero-ex/test/generated-wrappers
/contracts/zero-ex/generated-artifacts
/contracts/zero-ex/test/generated-artifacts
/contracts/treasury/generated-wrappers
/contracts/treasury/test/generated-wrappers
/contracts/treasury/generated-artifacts
/contracts/treasury/test/generated-artifacts
/contracts/staking/build/
/contracts/coordinator/build/
/contracts/exchange/build/
/contracts/asset-proxy/build/
/contracts/multisig/build/
/contracts/utils/build/
/contracts/exchange-libs/build/
/contracts/erc20/build/
/contracts/erc721/build/
/contracts/erc1155/build/
/contracts/extensions/build/
/contracts/exchange-forwarder/build/
/packages/asset-swapper/generated-artifacts
/packages/asset-swapper/generated-wrappers
/packages/asset-swapper/test/generated-artifacts
/packages/asset-swapper/test/generated-wrappers
generated-artifacts/
generated-wrappers/
foundry-artifacts/
out/
cache/
package.json
packages/*/docs
docs/
*.sol
packages

View File

@@ -4,5 +4,17 @@
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid"
"arrowParens": "avoid",
"overrides": [
{
"files": "**/*.sol",
"options": {
"printWidth": 120,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
}
]
}

17
.solhint.json Normal file
View File

@@ -0,0 +1,17 @@
{
"extends": "solhint:recommended",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"avoid-low-level-calls": "off",
"avoid-tx-origin": "warn",
"code-complexity": "off",
"const-name-snakecase": "error",
"function-max-lines": ["error", 350],
"max-line-length": ["error", 120],
"no-inline-assembly": "off",
"quotes": ["error", "double"],
"no-empty-blocks": "off",
"compiler-version": "off"
}
}

9
.solhintignore Normal file
View File

@@ -0,0 +1,9 @@
contracts/erc20/src/ZRXToken.sol
node_modules/
lib
deps
generated-artifacts/
generated-wrappers/
foundry-artifacts/
out/
cache/

View File

@@ -1,18 +0,0 @@
# See https://help.github.com/articles/about-codeowners/
# for more info about CODEOWNERS file
# It uses the same pattern rule for gitignore file
# https://git-scm.com/docs/gitignore#_pattern_format
# Website
packages/asset-swapper/ @BMillman19 @fragosti @dave4506
packages/instant/ @BMillman19 @fragosti @dave4506
# Dev tools & setup
.circleci/ @dorothy-zbornak
packages/contract-addresses/ @abandeali1
packages/contract-artifacts/ @abandeali1
packages/order-utils/ @dorothy-zbornak
# Protocol/smart contracts
contracts/ @abandeali1 @hysz @dorothy-zbornak @mzhu25

View File

@@ -8,8 +8,7 @@ This repository is a monorepo including the 0x protocol smart contracts and nume
[website-url]: https://0x.org
[![CircleCI](https://circleci.com/gh/0xProject/protocol.svg?style=svg&circle-token=61bf7cd8c9b4e11b132089dfcffdd1be277d1e0c)](https://circleci.com/gh/0xProject/protocool)
[![Coverage Status](https://coveralls.io/repos/github/0xProject/0x-monorepo/badge.svg?branch=development)](https://coveralls.io/github/0xProject/0x-monorepo?branch=development)
[![Coverage Status](https://coveralls.io/repos/github/0xProject/protocol/badge.svg?branch=development)](https://coveralls.io/github/0xProject/protocol?branch=development)
[![Discord](https://img.shields.io/badge/chat-discord.chat-yellow.svg?style=flat)](https://discordapp.com/invite/d3FTX3M)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
@@ -34,11 +33,9 @@ These packages are all under development. See [/contracts/README.md](/contracts/
| Package | Version | Description |
| -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [`@0x/asset-swapper`](/packages/asset-swapper) | [![npm](https://img.shields.io/npm/v/@0x/asset-swapper.svg)](https://www.npmjs.com/package/@0x/asset-swapper) | Package used to find and create aggregated swaps |
| [`@0x/protocol-utils`](/packages/protocol-utils) | [![npm](https://img.shields.io/npm/v/@0x/protocol-utils.svg)](https://www.npmjs.com/package/@0x/protocol-utils) | A set of utilities for generating, parsing, signing and validating 0x orders |
| [`@0x/contract-addresses`](/packages/contract-addresses) | [![npm](https://img.shields.io/npm/v/@0x/contract-addresses.svg)](https://www.npmjs.com/package/@0x/contract-addresses) | A tiny utility library for getting known deployed contract addresses for a particular network. |
| [`@0x/contract-wrappers`](/packages/contract-wrappers) | [![npm](https://img.shields.io/npm/v/@0x/contract-wrappers.svg)](https://www.npmjs.com/package/@0x/contract-wrappers) | JS/TS wrappers for interacting with the 0x smart contracts |
| [`@0x/migrations`](/packages/migrations) | [![npm](https://img.shields.io/npm/v/@0x/migrations.svg)](https://www.npmjs.com/package/@0x/migrations) | Migration tool for deploying 0x smart contracts on private testnets |
| [`@0x/contract-artifacts`](/packages/contract-artifacts) | [![npm](https://img.shields.io/npm/v/@0x/contract-artifacts.svg)](https://www.npmjs.com/package/@0x/contract-artifacts) | 0x smart contract compilation artifacts | |
## Usage
@@ -56,7 +53,7 @@ You can include those by prepending the `@0x/typescript-typings` package to your
We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository.
#### Read our [contribution guidelines](./CONTRIBUTING.md).
#### Read our [contribution guidelines](.github/CONTRIBUTING.md).
### Install dependencies
@@ -83,7 +80,7 @@ yarn build
To build a specific package:
```bash
PKG=@0x/asset-swapper yarn build
PKG=@0x/protocol-utils yarn build
```
To build all contracts packages:
@@ -106,7 +103,7 @@ To watch a specific package and all it's dependent packages:
PKG=[NPM_PACKAGE_NAME] yarn watch
e.g
PKG=@0x/asset-swapper yarn watch
PKG=@0x/protocol-utils yarn watch
```
### Clean
@@ -120,7 +117,7 @@ yarn clean
Clean a specific package
```bash
PKG=@0x/asset-swapper yarn clean
PKG=@0x/protocol-utils yarn clean
```
### Rebuild
@@ -134,7 +131,7 @@ yarn rebuild
To re-build (clean & build) a specific package & it's deps:
```bash
PKG=@0x/asset-swapper yarn rebuild
PKG=@0x/protocol-utils yarn rebuild
```
### Lint
@@ -148,7 +145,7 @@ yarn lint
Lint a specific package:
```bash
PKG=@0x/asset-swapper yarn lint
PKG=@0x/protocol-utils yarn lint
```
### Run Tests
@@ -162,7 +159,7 @@ yarn test
Run a specific package's test:
```bash
PKG=@0x/asset-swapper yarn test
PKG=@0x/protocol-utils yarn test
```
Run all contracts packages tests:

View File

@@ -1,22 +0,0 @@
{
"extends": "default",
"rules": {
"avoid-low-level-calls": false,
"avoid-tx-origin": "warn",
"bracket-align": false,
"code-complexity": false,
"compiler-fixed": false,
"const-name-snakecase": "error",
"expression-indent": "error",
"function-max-lines": false,
"func-order": "error",
"indent": ["error", 4],
"max-line-length": ["warn", 160],
"no-inline-assembly": false,
"quotes": ["error", "double"],
"separate-by-one-line-in-contract": "error",
"space-after-comma": "error",
"statement-indent": "error",
"no-empty-blocks": false
}
}

View File

@@ -1 +0,0 @@
contracts/src/ZRXToken.sol

View File

@@ -1,4 +1,472 @@
[
{
"timestamp": 1700094997,
"version": "4.0.14",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1693346928,
"version": "4.0.13",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1692368658,
"version": "4.0.12",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1691617396,
"version": "4.0.11",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689974915,
"version": "4.0.10",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689791426,
"version": "4.0.9",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1683749017,
"version": "4.0.8",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1682976338,
"version": "4.0.7",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681969282,
"version": "4.0.6",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "4.0.5",
"changes": [
{
"note": "Dependencies updated"
}
],
"timestamp": 1681756154
},
{
"timestamp": 1681697326,
"version": "4.0.4",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681157139,
"version": "4.0.3",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1678410794,
"version": "4.0.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1677693479,
"version": "4.0.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "4.0.0",
"changes": [
{
"note": "Migrated package to foundry"
}
]
},
{
"timestamp": 1675210931,
"version": "3.3.57",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1675105183,
"version": "3.3.56",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1674517560,
"version": "3.3.55",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1670879498,
"version": "3.3.54",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1669235113,
"version": "3.3.53",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1668477029,
"version": "3.3.52",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1667607537,
"version": "3.3.51",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1667427402,
"version": "3.3.50",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1666645023,
"version": "3.3.49",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1666381417,
"version": "3.3.48",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1665670315,
"version": "3.3.47",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1665531940,
"version": "3.3.46",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "3.3.45",
"changes": [
{
"note": "Migrate from TSLint to ESLint and fix linting errors",
"pr": 589
}
],
"timestamp": 1665013355
},
{
"timestamp": 1663786955,
"version": "3.3.44",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1662998180,
"version": "3.3.43",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1662559804,
"version": "3.3.42",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1662147076,
"version": "3.3.41",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1662046042,
"version": "3.3.40",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1661462289,
"version": "3.3.39",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1661459661,
"version": "3.3.38",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1661145612,
"version": "3.3.37",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1660093941,
"version": "3.3.36",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1660073235,
"version": "3.3.35",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1659750766,
"version": "3.3.34",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1658950329,
"version": "3.3.33",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1655244958,
"version": "3.3.32",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1654284040,
"version": "3.3.31",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1652919697,
"version": "3.3.30",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1650611093,
"version": "3.3.29",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1648739346,
"version": "3.3.28",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1646225739,
"version": "3.3.27",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1645569128,
"version": "3.3.26",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1640364306,
"version": "3.3.25",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1638390144,
"version": "3.3.24",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1637102971,
"version": "3.3.23",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1635903615,
"version": "3.3.22",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1634668033,
"version": "3.3.21",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1631710679,
"version": "3.3.20",

View File

@@ -5,6 +5,214 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v4.0.14 - _November 16, 2023_
* Dependencies updated
## v4.0.13 - _August 29, 2023_
* Dependencies updated
## v4.0.12 - _August 18, 2023_
* Dependencies updated
## v4.0.11 - _August 9, 2023_
* Dependencies updated
## v4.0.10 - _July 21, 2023_
* Dependencies updated
## v4.0.9 - _July 19, 2023_
* Dependencies updated
## v4.0.8 - _May 10, 2023_
* Dependencies updated
## v4.0.7 - _May 1, 2023_
* Dependencies updated
## v4.0.6 - _April 20, 2023_
* Dependencies updated
## v4.0.5 - _April 17, 2023_
* Dependencies updated
## v4.0.4 - _April 17, 2023_
* Dependencies updated
## v4.0.3 - _April 10, 2023_
* Dependencies updated
## v4.0.2 - _March 10, 2023_
* Dependencies updated
## v4.0.1 - _March 1, 2023_
* Dependencies updated
## v4.0.0 - _Invalid date_
* Migrated package to foundry
## v3.3.57 - _February 1, 2023_
* Dependencies updated
## v3.3.56 - _January 30, 2023_
* Dependencies updated
## v3.3.55 - _January 23, 2023_
* Dependencies updated
## v3.3.54 - _December 12, 2022_
* Dependencies updated
## v3.3.53 - _November 23, 2022_
* Dependencies updated
## v3.3.52 - _November 15, 2022_
* Dependencies updated
## v3.3.51 - _November 5, 2022_
* Dependencies updated
## v3.3.50 - _November 2, 2022_
* Dependencies updated
## v3.3.49 - _October 24, 2022_
* Dependencies updated
## v3.3.48 - _October 21, 2022_
* Dependencies updated
## v3.3.47 - _October 13, 2022_
* Dependencies updated
## v3.3.46 - _October 11, 2022_
* Dependencies updated
## v3.3.45 - _October 5, 2022_
* Migrate from TSLint to ESLint and fix linting errors (#589)
## v3.3.44 - _September 21, 2022_
* Dependencies updated
## v3.3.43 - _September 12, 2022_
* Dependencies updated
## v3.3.42 - _September 7, 2022_
* Dependencies updated
## v3.3.41 - _September 2, 2022_
* Dependencies updated
## v3.3.40 - _September 1, 2022_
* Dependencies updated
## v3.3.39 - _August 25, 2022_
* Dependencies updated
## v3.3.38 - _August 25, 2022_
* Dependencies updated
## v3.3.37 - _August 22, 2022_
* Dependencies updated
## v3.3.36 - _August 10, 2022_
* Dependencies updated
## v3.3.35 - _August 9, 2022_
* Dependencies updated
## v3.3.34 - _August 6, 2022_
* Dependencies updated
## v3.3.33 - _July 27, 2022_
* Dependencies updated
## v3.3.32 - _June 14, 2022_
* Dependencies updated
## v3.3.31 - _June 3, 2022_
* Dependencies updated
## v3.3.30 - _May 19, 2022_
* Dependencies updated
## v3.3.29 - _April 22, 2022_
* Dependencies updated
## v3.3.28 - _March 31, 2022_
* Dependencies updated
## v3.3.27 - _March 2, 2022_
* Dependencies updated
## v3.3.26 - _February 22, 2022_
* Dependencies updated
## v3.3.25 - _December 24, 2021_
* Dependencies updated
## v3.3.24 - _December 1, 2021_
* Dependencies updated
## v3.3.23 - _November 16, 2021_
* Dependencies updated
## v3.3.22 - _November 3, 2021_
* Dependencies updated
## v3.3.21 - _October 19, 2021_
* Dependencies updated
## v3.3.20 - _September 15, 2021_
* Dependencies updated

View File

@@ -20,7 +20,7 @@ We strongly recommend that the community help us make improvements and determine
For proposals regarding the 0x protocol's smart contract architecture, message format, or additional functionality, go to the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository and follow the contribution guidelines provided therein.
Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started.
Please read our [contribution guidelines](../../.github/CONTRIBUTING.md) before getting started.
### Install Dependencies
@@ -67,7 +67,3 @@ yarn lint
```bash
yarn test
```
#### Testing options
Contracts testing options like coverage, profiling, revert traces or backing node choosing - are described [here](../TESTING.md).

View File

@@ -1,28 +0,0 @@
{
"artifactsDir": "./test/generated-artifacts",
"contractsDir": "./contracts",
"useDockerisedSolc": false,
"isOfflineMode": false,
"shouldSaveStandardInput": true,
"compilerSettings": {
"evmVersion": "istanbul",
"optimizer": {
"enabled": true,
"runs": 1000000,
"details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true }
},
"outputSelection": {
"*": {
"*": [
"abi",
"devdoc",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap",
"devdoc"
]
}
}
}
}

View File

@@ -1,148 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
import "./interfaces/IERC20Token.sol";
contract ERC20Token is
IERC20Token
{
mapping (address => uint256) internal balances;
mapping (address => mapping (address => uint256)) internal allowed;
uint256 internal _totalSupply;
/// @dev send `value` token to `to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transfer(address _to, uint256 _value)
external
returns (bool)
{
require(
balances[msg.sender] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(
msg.sender,
_to,
_value
);
return true;
}
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
require(
balances[_from] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
allowed[_from][msg.sender] >= _value,
"ERC20_INSUFFICIENT_ALLOWANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
emit Transfer(
_from,
_to,
_value
);
return true;
}
/// @dev `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Always true if the call has enough gas to complete execution
function approve(address _spender, uint256 _value)
external
returns (bool)
{
allowed[msg.sender][_spender] = _value;
emit Approval(
msg.sender,
_spender,
_value
);
return true;
}
/// @dev Query total supply of token
/// @return Total supply of token
function totalSupply()
external
view
returns (uint256)
{
return _totalSupply;
}
/// @dev Query the balance of owner
/// @param _owner The address from which the balance will be retrieved
/// @return Balance of owner
function balanceOf(address _owner)
external
view
returns (uint256)
{
return balances[_owner];
}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender)
external
view
returns (uint256)
{
return allowed[_owner][_spender];
}
}

View File

@@ -1,199 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "../src/interfaces/IERC20Token.sol";
library LibERC20Token {
bytes constant private DECIMALS_CALL_DATA = hex"313ce567";
/// @dev Calls `IERC20Token(token).approve()`.
/// Reverts if `false` is returned or if the return
/// data length is nonzero and not 32 bytes.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
/// @param allowance The allowance to set.
function approve(
address token,
address spender,
uint256 allowance
)
internal
{
bytes memory callData = abi.encodeWithSelector(
IERC20Token(0).approve.selector,
spender,
allowance
);
_callWithOptionalBooleanResult(token, callData);
}
/// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the
/// maximum if the current approval is not already >= an amount.
/// Reverts if `false` is returned or if the return
/// data length is nonzero and not 32 bytes.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
/// @param amount The minimum allowance needed.
function approveIfBelow(
address token,
address spender,
uint256 amount
)
internal
{
if (IERC20Token(token).allowance(address(this), spender) < amount) {
approve(token, spender, uint256(-1));
}
}
/// @dev Calls `IERC20Token(token).transfer()`.
/// Reverts if `false` is returned or if the return
/// data length is nonzero and not 32 bytes.
/// @param token The address of the token contract.
/// @param to The address that receives the tokens
/// @param amount Number of tokens to transfer.
function transfer(
address token,
address to,
uint256 amount
)
internal
{
bytes memory callData = abi.encodeWithSelector(
IERC20Token(0).transfer.selector,
to,
amount
);
_callWithOptionalBooleanResult(token, callData);
}
/// @dev Calls `IERC20Token(token).transferFrom()`.
/// Reverts if `false` is returned or if the return
/// data length is nonzero and not 32 bytes.
/// @param token The address of the token contract.
/// @param from The owner of the tokens.
/// @param to The address that receives the tokens
/// @param amount Number of tokens to transfer.
function transferFrom(
address token,
address from,
address to,
uint256 amount
)
internal
{
bytes memory callData = abi.encodeWithSelector(
IERC20Token(0).transferFrom.selector,
from,
to,
amount
);
_callWithOptionalBooleanResult(token, callData);
}
/// @dev Retrieves the number of decimals for a token.
/// Returns `18` if the call reverts.
/// @param token The address of the token contract.
/// @return tokenDecimals The number of decimals places for the token.
function decimals(address token)
internal
view
returns (uint8 tokenDecimals)
{
tokenDecimals = 18;
(bool didSucceed, bytes memory resultData) = token.staticcall(DECIMALS_CALL_DATA);
if (didSucceed && resultData.length == 32) {
tokenDecimals = uint8(LibBytes.readUint256(resultData, 0));
}
}
/// @dev Retrieves the allowance for a token, owner, and spender.
/// Returns `0` if the call reverts.
/// @param token The address of the token contract.
/// @param owner The owner of the tokens.
/// @param spender The address the spender.
/// @return allowance The allowance for a token, owner, and spender.
function allowance(address token, address owner, address spender)
internal
view
returns (uint256 allowance_)
{
(bool didSucceed, bytes memory resultData) = token.staticcall(
abi.encodeWithSelector(
IERC20Token(0).allowance.selector,
owner,
spender
)
);
if (didSucceed && resultData.length == 32) {
allowance_ = LibBytes.readUint256(resultData, 0);
}
}
/// @dev Retrieves the balance for a token owner.
/// Returns `0` if the call reverts.
/// @param token The address of the token contract.
/// @param owner The owner of the tokens.
/// @return balance The token balance of an owner.
function balanceOf(address token, address owner)
internal
view
returns (uint256 balance)
{
(bool didSucceed, bytes memory resultData) = token.staticcall(
abi.encodeWithSelector(
IERC20Token(0).balanceOf.selector,
owner
)
);
if (didSucceed && resultData.length == 32) {
balance = LibBytes.readUint256(resultData, 0);
}
}
/// @dev Executes a call on address `target` with calldata `callData`
/// and asserts that either nothing was returned or a single boolean
/// was returned equal to `true`.
/// @param target The call target.
/// @param callData The abi-encoded call data.
function _callWithOptionalBooleanResult(
address target,
bytes memory callData
)
private
{
(bool didSucceed, bytes memory resultData) = target.call(callData);
if (didSucceed) {
if (resultData.length == 0) {
return;
}
if (resultData.length == 32) {
uint256 result = LibBytes.readUint256(resultData, 0);
if (result == 1) {
return;
}
}
}
LibRichErrors.rrevert(resultData);
}
}

View File

@@ -1,61 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "./UnlimitedAllowanceERC20Token.sol";
contract MintableERC20Token is
UnlimitedAllowanceERC20Token
{
using LibSafeMath for uint256;
/// @dev Mints new tokens
/// @param _to Address of the beneficiary that will own the minted token
/// @param _value Amount of tokens to mint
function _mint(address _to, uint256 _value)
internal
{
balances[_to] = _value.safeAdd(balances[_to]);
_totalSupply = _totalSupply.safeAdd(_value);
emit Transfer(
address(0),
_to,
_value
);
}
/// @dev Mints new tokens
/// @param _owner Owner of tokens that will be burned
/// @param _value Amount of tokens to burn
function _burn(address _owner, uint256 _value)
internal
{
balances[_owner] = balances[_owner].safeSub(_value);
_totalSupply = _totalSupply.safeSub(_value);
emit Transfer(
_owner,
address(0),
_value
);
}
}

View File

@@ -1,70 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
import "./ERC20Token.sol";
contract UnlimitedAllowanceERC20Token is
ERC20Token
{
uint256 constant internal MAX_UINT = 2**256 - 1;
/// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance. See https://github.com/ethereum/EIPs/issues/717
/// @param _from Address to transfer from.
/// @param _to Address to transfer to.
/// @param _value Amount to transfer.
/// @return Success of transfer.
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
uint256 allowance = allowed[_from][msg.sender];
require(
balances[_from] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
allowance >= _value,
"ERC20_INSUFFICIENT_ALLOWANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT) {
allowed[_from][msg.sender] -= _value;
}
emit Transfer(
_from,
_to,
_value
);
return true;
}
}

View File

@@ -1,87 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
contract IERC20Token {
// solhint-disable no-simple-event-func-name
event Transfer(
address indexed _from,
address indexed _to,
uint256 _value
);
event Approval(
address indexed _owner,
address indexed _spender,
uint256 _value
);
/// @dev send `value` token to `to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transfer(address _to, uint256 _value)
external
returns (bool);
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return True if transfer was successful
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool);
/// @dev `msg.sender` approves `_spender` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Always true if the call has enough gas to complete execution
function approve(address _spender, uint256 _value)
external
returns (bool);
/// @dev Query total supply of token
/// @return Total supply of token
function totalSupply()
external
view
returns (uint256);
/// @param _owner The address from which the balance will be retrieved
/// @return Balance of owner
function balanceOf(address _owner)
external
view
returns (uint256);
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender)
external
view
returns (uint256);
}

View File

@@ -1,33 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
import "./IERC20Token.sol";
contract IEtherToken is
IERC20Token
{
function deposit()
public
payable;
function withdraw(uint256 amount)
public;
}

View File

@@ -1,80 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.5;
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "@0x/contracts-utils/contracts/src/Ownable.sol";
import "../src/MintableERC20Token.sol";
contract DummyERC20Token is
Ownable,
MintableERC20Token
{
using LibSafeMath for uint256;
string public name;
string public symbol;
uint256 public decimals;
uint256 public constant MAX_MINT_AMOUNT = 10000000000000000000000;
constructor (
string memory _name,
string memory _symbol,
uint256 _decimals,
uint256 _totalSupply
)
public
{
name = _name;
symbol = _symbol;
decimals = _decimals;
_totalSupply = _totalSupply;
balances[msg.sender] = _totalSupply;
}
/// @dev Sets the balance of target address
/// @param _target Address or which balance will be updated
/// @param _value New balance of target address
function setBalance(address _target, uint256 _value)
external
onlyOwner
{
uint256 currBalance = balances[_target];
if (_value < currBalance) {
_totalSupply = _totalSupply.safeSub(currBalance.safeSub(_value));
} else {
_totalSupply = _totalSupply.safeAdd(_value.safeSub(currBalance));
}
balances[_target] = _value;
}
/// @dev Mints new tokens for sender
/// @param _value Amount of tokens to mint
function mint(uint256 _value)
external
{
require(
_value <= MAX_MINT_AMOUNT,
"VALUE_TOO_LARGE"
);
_mint(msg.sender, _value);
}
}

View File

@@ -1,69 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.5;
import "./DummyERC20Token.sol";
// solhint-disable no-empty-blocks
contract DummyMultipleReturnERC20Token is
DummyERC20Token
{
constructor (
string memory _name,
string memory _symbol,
uint256 _decimals,
uint256 _totalSupply
)
public
DummyERC20Token(
_name,
_symbol,
_decimals,
_totalSupply
)
{}
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
emit Transfer(
_from,
_to,
_value
);
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return 64 bytes (equiavalent to true, true)
assembly {
mstore(0, 1)
mstore(32, 1)
return(0, 64)
}
}
}

View File

@@ -1,115 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.5;
import "./DummyERC20Token.sol";
// solhint-disable no-empty-blocks
contract DummyNoReturnERC20Token is
DummyERC20Token
{
constructor (
string memory _name,
string memory _symbol,
uint256 _decimals,
uint256 _totalSupply
)
public
DummyERC20Token(
_name,
_symbol,
_decimals,
_totalSupply
)
{}
/// @dev send `value` token to `to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transfer(address _to, uint256 _value)
external
returns (bool)
{
require(
balances[msg.sender] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[msg.sender] -= _value;
balances[_to] += _value;
emit Transfer(
msg.sender,
_to,
_value
);
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
assembly {
return(0, 0)
}
}
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
require(
balances[_from] >= _value,
"ERC20_INSUFFICIENT_BALANCE"
);
require(
allowed[_from][msg.sender] >= _value,
"ERC20_INSUFFICIENT_ALLOWANCE"
);
require(
balances[_to] + _value >= balances[_to],
"UINT256_OVERFLOW"
);
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
emit Transfer(
_from,
_to,
_value
);
// HACK: This contract will not compile if we remove `returns (bool)`, so we manually return no data
assembly {
return(0, 0)
}
}
}

View File

@@ -1,84 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
import "../src/LibERC20Token.sol";
import "./TestLibERC20TokenTarget.sol";
contract TestLibERC20Token {
TestLibERC20TokenTarget public target;
constructor() public {
target = new TestLibERC20TokenTarget();
}
function testApprove(
bool shouldRevert,
bytes calldata revertData,
bytes calldata returnData,
address spender,
uint256 allowance
)
external
{
target.setBehavior(shouldRevert, revertData, returnData);
LibERC20Token.approve(address(target), spender, allowance);
}
function testTransfer(
bool shouldRevert,
bytes calldata revertData,
bytes calldata returnData,
address to,
uint256 amount
)
external
{
target.setBehavior(shouldRevert, revertData, returnData);
LibERC20Token.transfer(address(target), to, amount);
}
function testTransferFrom(
bool shouldRevert,
bytes calldata revertData,
bytes calldata returnData,
address from,
address to,
uint256 amount
)
external
{
target.setBehavior(shouldRevert, revertData, returnData);
LibERC20Token.transferFrom(address(target), from, to, amount);
}
function testDecimals(
bool shouldRevert,
bytes calldata revertData,
bytes calldata returnData
)
external
returns (uint8)
{
target.setBehavior(shouldRevert, revertData, returnData);
return LibERC20Token.decimals(address(target));
}
}

View File

@@ -1,106 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.9;
contract TestLibERC20TokenTarget {
event ApproveCalled(
address spender,
uint256 allowance
);
event TransferCalled(
address to,
uint256 amount
);
event TransferFromCalled(
address from,
address to,
uint256 amount
);
bool private _shouldRevert;
bytes private _revertData;
bytes private _returnData;
function setBehavior(
bool shouldRevert,
bytes calldata revertData,
bytes calldata returnData
)
external
{
_shouldRevert = shouldRevert;
_revertData = revertData;
_returnData = returnData;
}
function approve(
address spender,
uint256 allowance
)
external
returns (bool)
{
emit ApproveCalled(spender, allowance);
_execute();
}
function transfer(
address to,
uint256 amount
)
external
returns (bool)
{
emit TransferCalled(to, amount);
_execute();
}
function transferFrom(
address from,
address to,
uint256 amount
)
external
returns (bool)
{
emit TransferFromCalled(from, to, amount);
_execute();
}
function decimals()
external
view
returns (uint8)
{
_execute();
}
function _execute() private view {
if (_shouldRevert) {
bytes memory revertData = _revertData;
assembly { revert(add(revertData, 0x20), mload(revertData)) }
}
bytes memory returnData = _returnData;
assembly { return(add(returnData, 0x20), mload(returnData)) }
}
}

View File

@@ -1,62 +0,0 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.5;
import "./DummyERC20Token.sol";
// solhint-disable no-empty-blocks
// solhint-disable no-unused-vars
contract UntransferrableDummyERC20Token is
DummyERC20Token
{
constructor (
string memory _name,
string memory _symbol,
uint256 _decimals,
uint256 _totalSupply
)
public
DummyERC20Token(
_name,
_symbol,
_decimals,
_totalSupply
)
{}
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(
address _from,
address _to,
uint256 _value
)
external
returns (bool)
{
require(
false,
"TRANSFER_DISABLED"
);
}
}

View File

@@ -0,0 +1,18 @@
[profile.default]
src = 'src'
out = 'out'
libs = [
'lib',
'node_modules',
]
remappings = [
'@0x/contracts-utils/=../utils/'
]
allow_paths = [
'../utils/'
]
fs_permissions = [{ access = "read", path = "./out/ZRXToken.sol" }]
optimizer_runs = 1_000_000
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-erc20",
"version": "3.3.20",
"version": "4.0.14",
"engines": {
"node": ">=6.12"
},
@@ -10,37 +10,10 @@
"test": "test"
},
"scripts": {
"build": "yarn pre_build && tsc -b",
"build:ci": "yarn build",
"pre_build": "run-s compile contracts:gen generate_contract_wrappers contracts:copy",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov",
"test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html",
"test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit",
"compile": "sol-compiler",
"watch": "sol-compiler -w",
"clean": "shx rm -rf lib test/generated-artifacts test/generated-wrappers generated-artifacts generated-wrappers",
"generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output test/generated-wrappers --backend ethers",
"lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
"fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
"coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html",
"profiler:report:html": "istanbul report html && open coverage/index.html",
"coverage:report:lcov": "istanbul report lcov",
"test:circleci": "yarn test",
"contracts:gen": "contracts-gen generate",
"contracts:copy": "contracts-gen copy",
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol",
"test:ci": "forge test",
"docs:md": "ts-doc-gen --sourceDir='$PROJECT_FILES' --output=$MD_FILE_DIR --fileExtension=mdx --tsconfig=./typedoc-tsconfig.json",
"docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"publicInterfaceContracts": "DummyERC20Token,ERC20Token,WETH9,ZRXToken,DummyNoReturnERC20Token,DummyMultipleReturnERC20Token",
"abis": "./test/generated-artifacts/@(DummyERC20Token|DummyMultipleReturnERC20Token|DummyNoReturnERC20Token|ERC20Token|IERC20Token|IERC20TokenV06|IEtherToken|IEtherTokenV06|LibERC20Token|LibERC20TokenV06|MintableERC20Token|TestLibERC20Token|TestLibERC20TokenTarget|UnlimitedAllowanceERC20Token|UntransferrableDummyERC20Token|WETH9|ZRXToken).json",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/protocol.git"
@@ -49,41 +22,11 @@
"bugs": {
"url": "https://github.com/0xProject/protocol/issues"
},
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/tokens",
"homepage": "https://github.com/0xProject/protocol",
"devDependencies": {
"@0x/abi-gen": "^5.6.2",
"@0x/contracts-gen": "^2.0.40",
"@0x/contracts-test-utils": "^5.4.11",
"@0x/contracts-utils": "^4.8.1",
"@0x/dev-utils": "^4.2.9",
"@0x/sol-compiler": "^4.7.5",
"@0x/contracts-utils": "^4.8.52",
"@0x/ts-doc-gen": "^0.0.28",
"@0x/tslint-config": "^4.1.4",
"@0x/types": "^3.3.4",
"@0x/typescript-typings": "^5.2.1",
"@0x/utils": "^6.4.4",
"@0x/web3-wrapper": "^7.6.0",
"@types/lodash": "4.14.104",
"@types/mocha": "^5.2.7",
"@types/node": "12.12.54",
"chai": "^4.0.1",
"chai-as-promised": "^7.1.0",
"chai-bignumber": "^3.0.0",
"dirty-chai": "^2.0.1",
"ethereum-types": "^3.6.0",
"lodash": "^4.17.11",
"make-promises-safe": "^1.1.0",
"mocha": "^6.2.0",
"npm-run-all": "^4.1.2",
"shx": "^0.2.2",
"solhint": "^1.4.1",
"tslint": "5.11.0",
"typedoc": "~0.16.11",
"typescript": "4.2.2"
},
"dependencies": {
"@0x/base-contract": "^6.4.2",
"ethers": "~4.0.4"
"typedoc": "~0.16.11"
},
"publishConfig": {
"access": "public"

View File

@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2020 ZeroEx Intl.
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,80 +17,47 @@
*/
pragma solidity ^0.6.5;
pragma solidity >=0.6.5 <0.9;
interface IERC20Token {
event Transfer(address indexed from, address indexed to, uint256 value);
interface IERC20TokenV06 {
// solhint-disable no-simple-event-func-name
event Transfer(
address indexed from,
address indexed to,
uint256 value
);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event Approval(address indexed owner, address indexed spender, uint256 value);
/// @dev send `value` token to `to` from `msg.sender`
/// @param to The address of the recipient
/// @param value The amount of token to be transferred
/// @return True if transfer was successful
function transfer(address to, uint256 value)
external
returns (bool);
function transfer(address to, uint256 value) external returns (bool);
/// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
/// @param from The address of the sender
/// @param to The address of the recipient
/// @param value The amount of token to be transferred
/// @return True if transfer was successful
function transferFrom(
address from,
address to,
uint256 value
)
external
returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
/// @dev `msg.sender` approves `spender` to spend `value` tokens
/// @param spender The address of the account able to transfer the tokens
/// @param value The amount of wei to be approved for transfer
/// @return Always true if the call has enough gas to complete execution
function approve(address spender, uint256 value)
external
returns (bool);
function approve(address spender, uint256 value) external returns (bool);
/// @dev Query total supply of token
/// @return Total supply of token
function totalSupply()
external
view
returns (uint256);
function totalSupply() external view returns (uint256);
/// @dev Get the balance of `owner`.
/// @param owner The address from which the balance will be retrieved
/// @return Balance of owner
function balanceOf(address owner)
external
view
returns (uint256);
function balanceOf(address owner) external view returns (uint256);
/// @dev Get the allowance for `spender` to spend from `owner`.
/// @param owner The address of the account owning tokens
/// @param spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address owner, address spender)
external
view
returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
/// @dev Get the number of decimals this token has.
function decimals()
external
view
returns (uint8);
function decimals() external view returns (uint8);
}

View File

@@ -19,12 +19,9 @@
pragma solidity ^0.6.5;
import "./IERC20TokenV06.sol";
import "./IERC20Token.sol";
interface IEtherTokenV06 is
IERC20TokenV06
{
interface IEtherToken is IERC20Token {
/// @dev Wrap ether.
function deposit() external payable;

View File

@@ -13,58 +13,55 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// solhint-disable
pragma solidity ^0.5.9;
contract WETH9 {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
event Approval(address indexed _owner, address indexed _spender, uint _value);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Deposit(address indexed _owner, uint _value);
event Withdrawal(address indexed _owner, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Deposit(address indexed _owner, uint256 _value);
event Withdrawal(address indexed _owner, uint256 _value);
mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
function() external payable {
deposit();
}
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint wad) public {
function withdraw(uint256 wad) public {
require(balanceOf[msg.sender] >= wad);
balanceOf[msg.sender] -= wad;
msg.sender.transfer(wad);
emit Withdrawal(msg.sender, wad);
}
function totalSupply() public view returns (uint) {
function totalSupply() public view returns (uint256) {
return address(this).balance;
}
function approve(address guy, uint wad) public returns (bool) {
function approve(address guy, uint256 wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
function transfer(address dst, uint wad) public returns (bool) {
function transfer(address dst, uint256 wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint wad)
public
returns (bool)
{
function transferFrom(address src, address dst, uint256 wad) public returns (bool) {
require(balanceOf[src] >= wad);
if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
if (src != msg.sender && allowance[src][msg.sender] != uint256(-1)) {
require(allowance[src][msg.sender] >= wad);
allowance[src][msg.sender] -= wad;
}
@@ -78,7 +75,6 @@ contract WETH9 {
}
}
/*
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

View File

@@ -18,105 +18,99 @@
pragma solidity 0.4.11;
contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract ERC20Token is Token {
function transfer(address _to, uint _value) returns (bool) {
function transfer(address _to, uint256 _value) returns (bool) {
//Default assumes totalSupply can't be over max (2^256 - 1).
if (balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]) {
balances[msg.sender] -= _value;
balances[_to] += _value;
Transfer(msg.sender, _to, _value);
return true;
} else { return false; }
} else {
return false;
}
}
function transferFrom(address _from, address _to, uint _value) returns (bool) {
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]) {
function transferFrom(address _from, address _to, uint256 _value) returns (bool) {
if (
balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value >= balances[_to]
) {
balances[_to] += _value;
balances[_from] -= _value;
allowed[_from][msg.sender] -= _value;
Transfer(_from, _to, _value);
return true;
} else { return false; }
} else {
return false;
}
}
function balanceOf(address _owner) constant returns (uint) {
function balanceOf(address _owner) constant returns (uint256) {
return balances[_owner];
}
function approve(address _spender, uint _value) returns (bool) {
function approve(address _spender, uint256 _value) returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) constant returns (uint) {
function allowance(address _owner, address _spender) constant returns (uint256) {
return allowed[_owner][_spender];
}
mapping (address => uint) balances;
mapping (address => mapping (address => uint)) allowed;
uint public totalSupply;
mapping(address => uint256) balances;
mapping(address => mapping(address => uint256)) allowed;
uint256 public totalSupply;
}
contract UnlimitedAllowanceToken is ERC20Token {
uint constant MAX_UINT = 2**256 - 1;
uint256 constant MAX_UINT = 2 ** 256 - 1;
/// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance.
/// @param _from Address to transfer from.
/// @param _to Address to transfer to.
/// @param _value Amount to transfer.
/// @return Success of transfer.
function transferFrom(address _from, address _to, uint _value)
public
returns (bool)
{
uint allowance = allowed[_from][msg.sender];
if (balances[_from] >= _value
&& allowance >= _value
&& balances[_to] + _value >= balances[_to]
) {
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
uint256 allowance = allowed[_from][msg.sender];
if (balances[_from] >= _value && allowance >= _value && balances[_to] + _value >= balances[_to]) {
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT) {
@@ -130,21 +124,13 @@ contract UnlimitedAllowanceToken is ERC20Token {
}
}
contract ZRXToken is UnlimitedAllowanceToken {
uint8 public constant decimals = 18;
uint256 public totalSupply = 10 ** 27; // 1 billion tokens, 18 decimal places
string public constant name = "0x Protocol Token";
string public constant symbol = "ZRX";
contract ZRXToken is
UnlimitedAllowanceToken
{
// solhint-disable const-name-snakecase
uint8 constant public decimals = 18;
uint256 public totalSupply = 10**27; // 1 billion tokens, 18 decimal places
string constant public name = "0x Protocol Token";
string constant public symbol = "ZRX";
// solhint-enableconst-name-snakecase
function ZRXToken()
public
{
function ZRXToken() public {
balances[msg.sender] = totalSupply;
}
}

View File

@@ -1,21 +0,0 @@
/*
* -----------------------------------------------------------------------------
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* -----------------------------------------------------------------------------
*/
import { ContractArtifact } from 'ethereum-types';
import * as DummyERC20Token from '../generated-artifacts/DummyERC20Token.json';
import * as DummyMultipleReturnERC20Token from '../generated-artifacts/DummyMultipleReturnERC20Token.json';
import * as DummyNoReturnERC20Token from '../generated-artifacts/DummyNoReturnERC20Token.json';
import * as ERC20Token from '../generated-artifacts/ERC20Token.json';
import * as WETH9 from '../generated-artifacts/WETH9.json';
import * as ZRXToken from '../generated-artifacts/ZRXToken.json';
export const artifacts = {
DummyERC20Token: DummyERC20Token as ContractArtifact,
ERC20Token: ERC20Token as ContractArtifact,
WETH9: WETH9 as ContractArtifact,
ZRXToken: (ZRXToken as any) as ContractArtifact,
DummyNoReturnERC20Token: DummyNoReturnERC20Token as ContractArtifact,
DummyMultipleReturnERC20Token: DummyMultipleReturnERC20Token as ContractArtifact,
};

View File

@@ -1,47 +0,0 @@
export {
DummyERC20TokenContract,
DummyMultipleReturnERC20TokenContract,
DummyNoReturnERC20TokenContract,
WETH9Contract,
WETH9Events,
WETH9DepositEventArgs,
WETH9TransferEventArgs,
WETH9WithdrawalEventArgs,
ZRXTokenContract,
DummyERC20TokenTransferEventArgs,
ERC20TokenEventArgs,
ERC20TokenEvents,
ERC20TokenTransferEventArgs,
ERC20TokenApprovalEventArgs,
ERC20TokenContract,
} from './wrappers';
export { artifacts } from './artifacts';
export {
ContractArtifact,
ContractChains,
CompilerOpts,
StandardContractOutput,
CompilerSettings,
ContractChainData,
ContractAbi,
DevdocOutput,
EvmOutput,
CompilerSettingsMetadata,
OptimizerSettings,
OutputField,
ParamDescription,
EvmBytecodeOutput,
EvmBytecodeOutputLinkReferences,
AbiDefinition,
FunctionAbi,
EventAbi,
RevertErrorAbi,
EventParameter,
DataItem,
MethodAbi,
ConstructorAbi,
FallbackAbi,
ConstructorStateMutability,
TupleDataItem,
StateMutability,
} from 'ethereum-types';

View File

@@ -21,90 +21,51 @@ pragma solidity ^0.6.5;
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol";
import "./IERC20TokenV06.sol";
import "../IERC20Token.sol";
library LibERC20TokenV06 {
bytes constant private DECIMALS_CALL_DATA = hex"313ce567";
bytes private constant DECIMALS_CALL_DATA = hex"313ce567";
/// @dev Calls `IERC20TokenV06(token).approve()`.
/// @dev Calls `IERC20Token(token).approve()`.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
/// @param allowance The allowance to set.
function compatApprove(
IERC20TokenV06 token,
address spender,
uint256 allowance
)
internal
{
bytes memory callData = abi.encodeWithSelector(
token.approve.selector,
spender,
allowance
);
function compatApprove(IERC20Token token, address spender, uint256 allowance) internal {
bytes memory callData = abi.encodeWithSelector(token.approve.selector, spender, allowance);
_callWithOptionalBooleanResult(address(token), callData);
}
/// @dev Calls `IERC20TokenV06(token).approve()` and sets the allowance to the
/// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the
/// maximum if the current approval is not already >= an amount.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
/// @param amount The minimum allowance needed.
function approveIfBelow(
IERC20TokenV06 token,
address spender,
uint256 amount
)
internal
{
function approveIfBelow(IERC20Token token, address spender, uint256 amount) internal {
if (token.allowance(address(this), spender) < amount) {
compatApprove(token, spender, uint256(-1));
}
}
/// @dev Calls `IERC20TokenV06(token).transfer()`.
/// @dev Calls `IERC20Token(token).transfer()`.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param to The address that receives the tokens
/// @param amount Number of tokens to transfer.
function compatTransfer(
IERC20TokenV06 token,
address to,
uint256 amount
)
internal
{
bytes memory callData = abi.encodeWithSelector(
token.transfer.selector,
to,
amount
);
function compatTransfer(IERC20Token token, address to, uint256 amount) internal {
bytes memory callData = abi.encodeWithSelector(token.transfer.selector, to, amount);
_callWithOptionalBooleanResult(address(token), callData);
}
/// @dev Calls `IERC20TokenV06(token).transferFrom()`.
/// @dev Calls `IERC20Token(token).transferFrom()`.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param from The owner of the tokens.
/// @param to The address that receives the tokens
/// @param amount Number of tokens to transfer.
function compatTransferFrom(
IERC20TokenV06 token,
address from,
address to,
uint256 amount
)
internal
{
bytes memory callData = abi.encodeWithSelector(
token.transferFrom.selector,
from,
to,
amount
);
function compatTransferFrom(IERC20Token token, address from, address to, uint256 amount) internal {
bytes memory callData = abi.encodeWithSelector(token.transferFrom.selector, from, to, amount);
_callWithOptionalBooleanResult(address(token), callData);
}
@@ -112,11 +73,7 @@ library LibERC20TokenV06 {
/// Returns `18` if the call reverts.
/// @param token The address of the token contract.
/// @return tokenDecimals The number of decimals places for the token.
function compatDecimals(IERC20TokenV06 token)
internal
view
returns (uint8 tokenDecimals)
{
function compatDecimals(IERC20Token token) internal view returns (uint8 tokenDecimals) {
tokenDecimals = 18;
(bool didSucceed, bytes memory resultData) = address(token).staticcall(DECIMALS_CALL_DATA);
if (didSucceed && resultData.length >= 32) {
@@ -130,17 +87,13 @@ library LibERC20TokenV06 {
/// @param owner The owner of the tokens.
/// @param spender The address the spender.
/// @return allowance_ The allowance for a token, owner, and spender.
function compatAllowance(IERC20TokenV06 token, address owner, address spender)
internal
view
returns (uint256 allowance_)
{
function compatAllowance(
IERC20Token token,
address owner,
address spender
) internal view returns (uint256 allowance_) {
(bool didSucceed, bytes memory resultData) = address(token).staticcall(
abi.encodeWithSelector(
token.allowance.selector,
owner,
spender
)
abi.encodeWithSelector(token.allowance.selector, owner, spender)
);
if (didSucceed && resultData.length >= 32) {
allowance_ = LibBytesV06.readUint256(resultData, 0);
@@ -152,16 +105,9 @@ library LibERC20TokenV06 {
/// @param token The address of the token contract.
/// @param owner The owner of the tokens.
/// @return balance The token balance of an owner.
function compatBalanceOf(IERC20TokenV06 token, address owner)
internal
view
returns (uint256 balance)
{
function compatBalanceOf(IERC20Token token, address owner) internal view returns (uint256 balance) {
(bool didSucceed, bytes memory resultData) = address(token).staticcall(
abi.encodeWithSelector(
token.balanceOf.selector,
owner
)
abi.encodeWithSelector(token.balanceOf.selector, owner)
);
if (didSucceed && resultData.length >= 32) {
balance = LibBytesV06.readUint256(resultData, 0);
@@ -173,12 +119,7 @@ library LibERC20TokenV06 {
/// was returned equal to `true`.
/// @param target The call target.
/// @param callData The abi-encoded call data.
function _callWithOptionalBooleanResult(
address target,
bytes memory callData
)
private
{
function _callWithOptionalBooleanResult(address target, bytes memory callData) private {
(bool didSucceed, bytes memory resultData) = target.call(callData);
// Revert if the call reverted.
if (!didSucceed) {
@@ -188,7 +129,9 @@ library LibERC20TokenV06 {
// does not return a boolean. Check that it at least contains code.
if (resultData.length == 0) {
uint256 size;
assembly { size := extcodesize(target) }
assembly {
size := extcodesize(target)
}
require(size > 0, "invalid token address, contains no code");
return;
}

View File

@@ -0,0 +1,755 @@
// Copyright (C) 2015, 2016, 2017 Dapphub
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// solhint-disable
pragma solidity ^0.6.0;
contract WETH9V06 {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;
event Approval(address indexed _owner, address indexed _spender, uint _value);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Deposit(address indexed _owner, uint _value);
event Withdrawal(address indexed _owner, uint _value);
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
receive() external payable {
deposit();
}
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint wad) public {
require(balanceOf[msg.sender] >= wad);
balanceOf[msg.sender] -= wad;
msg.sender.transfer(wad);
emit Withdrawal(msg.sender, wad);
}
function totalSupply() public view returns (uint) {
return address(this).balance;
}
function approve(address guy, uint wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}
function transfer(address dst, uint wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint wad) public returns (bool) {
require(balanceOf[src] >= wad);
if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
require(allowance[src][msg.sender] >= wad);
allowance[src][msg.sender] -= wad;
}
balanceOf[src] -= wad;
balanceOf[dst] += wad;
emit Transfer(src, dst, wad);
return true;
}
}
/*
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
*/

View File

@@ -0,0 +1,146 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2020 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.0;
import "@0x/contracts-utils/contracts/src/v08/errors/LibRichErrorsV08.sol";
import "@0x/contracts-utils/contracts/src/v08/LibBytesV08.sol";
import "../IERC20Token.sol";
library LibERC20TokenV08 {
bytes private constant DECIMALS_CALL_DATA = hex"313ce567";
/// @dev Calls `IERC20Token(token).approve()`.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
/// @param allowance The allowance to set.
function compatApprove(IERC20Token token, address spender, uint256 allowance) internal {
bytes memory callData = abi.encodeCall(token.approve, (spender, allowance));
_callWithOptionalBooleanResult(address(token), callData);
}
/// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the
/// maximum if the current approval is not already >= an amount.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param spender The address that receives an allowance.
/// @param amount The minimum allowance needed.
function approveIfBelow(IERC20Token token, address spender, uint256 amount) internal {
if (token.allowance(address(this), spender) < amount) {
compatApprove(token, spender, type(uint256).max);
}
}
/// @dev Calls `IERC20Token(token).transfer()`.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param to The address that receives the tokens
/// @param amount Number of tokens to transfer.
function compatTransfer(IERC20Token token, address to, uint256 amount) internal {
bytes memory callData = abi.encodeCall(token.transfer, (to, amount));
_callWithOptionalBooleanResult(address(token), callData);
}
/// @dev Calls `IERC20Token(token).transferFrom()`.
/// Reverts if the return data is invalid or the call reverts.
/// @param token The address of the token contract.
/// @param from The owner of the tokens.
/// @param to The address that receives the tokens
/// @param amount Number of tokens to transfer.
function compatTransferFrom(IERC20Token token, address from, address to, uint256 amount) internal {
bytes memory callData = abi.encodeCall(token.transferFrom, (from, to, amount));
_callWithOptionalBooleanResult(address(token), callData);
}
/// @dev Retrieves the number of decimals for a token.
/// Returns `18` if the call reverts.
/// @param token The address of the token contract.
/// @return tokenDecimals The number of decimals places for the token.
function compatDecimals(IERC20Token token) internal view returns (uint8 tokenDecimals) {
tokenDecimals = 18;
(bool didSucceed, bytes memory resultData) = address(token).staticcall(DECIMALS_CALL_DATA);
if (didSucceed && resultData.length >= 32) {
tokenDecimals = abi.decode(resultData, (uint8));
}
}
/// @dev Retrieves the allowance for a token, owner, and spender.
/// Returns `0` if the call reverts.
/// @param token The address of the token contract.
/// @param owner The owner of the tokens.
/// @param spender The address the spender.
/// @return allowance_ The allowance for a token, owner, and spender.
function compatAllowance(
IERC20Token token,
address owner,
address spender
) internal view returns (uint256 allowance_) {
(bool didSucceed, bytes memory resultData) = address(token).staticcall(
abi.encodeCall(token.allowance, (owner, spender))
);
if (didSucceed && resultData.length >= 32) {
allowance_ = abi.decode(resultData, (uint256));
}
}
/// @dev Retrieves the balance for a token owner.
/// Returns `0` if the call reverts.
/// @param token The address of the token contract.
/// @param owner The owner of the tokens.
/// @return balance The token balance of an owner.
function compatBalanceOf(IERC20Token token, address owner) internal view returns (uint256 balance) {
(bool didSucceed, bytes memory resultData) = address(token).staticcall(
abi.encodeCall(token.balanceOf, (owner))
);
if (didSucceed && resultData.length >= 32) {
balance = abi.decode(resultData, (uint256));
}
}
/// @dev Executes a call on address `target` with calldata `callData`
/// and asserts that either nothing was returned or a single boolean
/// was returned equal to `true`.
/// @param target The call target.
/// @param callData The abi-encoded call data.
function _callWithOptionalBooleanResult(address target, bytes memory callData) private {
(bool didSucceed, bytes memory resultData) = target.call(callData);
// Revert if the call reverted.
if (!didSucceed) {
LibRichErrorsV08.rrevert(resultData);
}
// If we get back 0 returndata, this may be a non-standard ERC-20 that
// does not return a boolean. Check that it at least contains code.
if (resultData.length == 0) {
require(target.code.length > 0, "invalid token address, contains no code");
return;
}
// If we get back at least 32 bytes, we know the target address
// contains code, and we assume it is a token that returned a boolean
// success value, which must be true.
if (resultData.length >= 32) {
if (!abi.decode(resultData, (bool))) {
LibRichErrorsV08.rrevert(resultData);
}
}
// If 0 < returndatasize < 32, the target is a contract, but not a
// valid token.
LibRichErrorsV08.rrevert(resultData);
}
}

View File

@@ -1,11 +0,0 @@
/*
* -----------------------------------------------------------------------------
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* -----------------------------------------------------------------------------
*/
export * from '../generated-wrappers/dummy_erc20_token';
export * from '../generated-wrappers/dummy_multiple_return_erc20_token';
export * from '../generated-wrappers/dummy_no_return_erc20_token';
export * from '../generated-wrappers/erc20_token';
export * from '../generated-wrappers/weth9';
export * from '../generated-wrappers/zrx_token';

View File

@@ -0,0 +1,73 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6.5;
pragma experimental ABIEncoderV2;
import "forge-std/Test.sol";
import "../src/v06/WETH9V06.sol";
contract WETH9V06Test is Test {
address payable internal owner = payable(vm.addr(1));
address payable internal user = payable(vm.addr(2));
WETH9V06 internal etherToken;
function setUp() public {
vm.deal(owner, 1e20);
vm.deal(user, 1e20);
etherToken = new WETH9V06();
}
function testShouldRevertIfCallerAttemptsToDepositMoreThanTheirBalance() public {
vm.prank(user);
vm.expectRevert();
etherToken.deposit{value: 1e20 + 1}();
}
function testShouldConvertDepositedETHToWrappedETH() public {
vm.prank(user);
etherToken.deposit{value: 1e20}();
assertEq(etherToken.balanceOf(user), 1e20);
assertEq(address(etherToken).balance, 1e20);
}
function testShouldRevertIfCallerAttemptsToWithdrawMoreThanTheirBalance() public {
vm.prank(user);
etherToken.deposit{value: 1e20}();
vm.expectRevert();
etherToken.withdraw(1e20 + 1);
}
function testShouldConvertWithdrawWrappedETHToETH() public {
vm.prank(user);
etherToken.deposit{value: 1e20}();
vm.prank(user);
etherToken.withdraw(100);
assertEq(etherToken.balanceOf(user), 1e20 - 100);
assertEq(address(etherToken).balance, 1e20 - 100);
assertEq(user.balance, 100);
}
function testShouldConvertSentETHToWrappedETH() public {
vm.prank(user);
address(etherToken).call{value: 1e20}(new bytes(0));
assertEq(etherToken.balanceOf(user), 1e20);
assertEq(address(etherToken).balance, 1e20);
}
}

View File

@@ -0,0 +1,112 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.17;
import "forge-std/Test.sol";
import "../src/IERC20Token.sol";
contract ZRXTokenTest is Test {
address payable internal owner = payable(vm.addr(1));
address payable internal user = payable(vm.addr(2));
address payable internal anotherUser = payable(vm.addr(3));
uint256 internal totalSupply = 1_000_000_000 * 1e18;
IERC20Token zrxToken;
function setUp() public {
vm.deal(owner, 1e20);
vm.deal(user, 1e20);
vm.prank(owner);
bytes memory _bytecode = vm.getCode("./out/ZRXToken.sol/ZRXToken.json");
address _address;
assembly {
_address := create(0, add(_bytecode, 0x20), mload(_bytecode))
}
zrxToken = IERC20Token(address(_address));
}
function testShouldHave18Decimals() public {
assertEq(zrxToken.decimals(), 18);
}
function testShouldHaveTotalSupplyOf1Billion() public {
assertEq(zrxToken.totalSupply(), totalSupply);
}
function testShouldInitializeOwnerBalanceToTotalSupply() public {
assertEq(zrxToken.balanceOf(owner), totalSupply);
}
function testShouldTransferBalanceCorrectly() public {
vm.prank(owner);
zrxToken.transfer(user, 100);
assertEq(zrxToken.balanceOf(user), 100);
assertEq(zrxToken.balanceOf(owner), totalSupply - 100);
}
function testShouldReturnTrueOnAZeroValueTransfer() public {
vm.prank(owner);
bool success = zrxToken.transfer(user, 0);
assertTrue(success);
}
function testShouldReturnTrueOnAZeroValueTransferByUserWithZeroBalance() public {
vm.prank(anotherUser);
bool success = zrxToken.transfer(user, 0);
assertTrue(success);
}
function testShouldReturnFalseIfSenderHasInsufficientBalance() public {
vm.prank(owner);
zrxToken.approve(user, totalSupply + 1);
bool success = zrxToken.transferFrom(owner, user, totalSupply + 1);
assertEq(success, false);
}
function testShouldReturnFalseIfRecipientHasInsufficientAllowance() public {
vm.prank(owner);
zrxToken.approve(user, totalSupply - 1);
bool success = zrxToken.transferFrom(owner, user, totalSupply);
assertEq(success, false);
}
function testShouldReturnTrueOnAZeroValueApprovedTransfer() public {
vm.prank(user);
bool success = zrxToken.transferFrom(owner, user, 0);
assertEq(success, true);
}
function testShouldNotModifySenderAllowanceIfSetToUINT256Max() public {
vm.prank(owner);
zrxToken.approve(user, type(uint256).max);
zrxToken.transferFrom(owner, user, 100);
assertEq(zrxToken.allowance(owner, user), type(uint256).max);
}
function testShouldTransferCorrectlyWhenSufficientAllowance() public {
vm.prank(owner);
zrxToken.approve(user, 1000 * 1e18);
vm.prank(user);
zrxToken.transferFrom(owner, user, 100 * 1e18);
assertEq(zrxToken.allowance(owner, user), 900 * 1e18);
assertEq(zrxToken.balanceOf(user), 100 * 1e18);
assertEq(zrxToken.balanceOf(owner), totalSupply - 100 * 1e18);
}
}

View File

@@ -1,43 +0,0 @@
/*
* -----------------------------------------------------------------------------
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* -----------------------------------------------------------------------------
*/
import { ContractArtifact } from 'ethereum-types';
import * as DummyERC20Token from '../test/generated-artifacts/DummyERC20Token.json';
import * as DummyMultipleReturnERC20Token from '../test/generated-artifacts/DummyMultipleReturnERC20Token.json';
import * as DummyNoReturnERC20Token from '../test/generated-artifacts/DummyNoReturnERC20Token.json';
import * as ERC20Token from '../test/generated-artifacts/ERC20Token.json';
import * as IERC20Token from '../test/generated-artifacts/IERC20Token.json';
import * as IERC20TokenV06 from '../test/generated-artifacts/IERC20TokenV06.json';
import * as IEtherToken from '../test/generated-artifacts/IEtherToken.json';
import * as IEtherTokenV06 from '../test/generated-artifacts/IEtherTokenV06.json';
import * as LibERC20Token from '../test/generated-artifacts/LibERC20Token.json';
import * as LibERC20TokenV06 from '../test/generated-artifacts/LibERC20TokenV06.json';
import * as MintableERC20Token from '../test/generated-artifacts/MintableERC20Token.json';
import * as TestLibERC20Token from '../test/generated-artifacts/TestLibERC20Token.json';
import * as TestLibERC20TokenTarget from '../test/generated-artifacts/TestLibERC20TokenTarget.json';
import * as UnlimitedAllowanceERC20Token from '../test/generated-artifacts/UnlimitedAllowanceERC20Token.json';
import * as UntransferrableDummyERC20Token from '../test/generated-artifacts/UntransferrableDummyERC20Token.json';
import * as WETH9 from '../test/generated-artifacts/WETH9.json';
import * as ZRXToken from '../test/generated-artifacts/ZRXToken.json';
export const artifacts = {
ERC20Token: ERC20Token as ContractArtifact,
LibERC20Token: LibERC20Token as ContractArtifact,
MintableERC20Token: MintableERC20Token as ContractArtifact,
UnlimitedAllowanceERC20Token: UnlimitedAllowanceERC20Token as ContractArtifact,
WETH9: WETH9 as ContractArtifact,
ZRXToken: (ZRXToken as any) as ContractArtifact,
IERC20Token: IERC20Token as ContractArtifact,
IEtherToken: IEtherToken as ContractArtifact,
IERC20TokenV06: IERC20TokenV06 as ContractArtifact,
IEtherTokenV06: IEtherTokenV06 as ContractArtifact,
LibERC20TokenV06: LibERC20TokenV06 as ContractArtifact,
DummyERC20Token: DummyERC20Token as ContractArtifact,
DummyMultipleReturnERC20Token: DummyMultipleReturnERC20Token as ContractArtifact,
DummyNoReturnERC20Token: DummyNoReturnERC20Token as ContractArtifact,
TestLibERC20Token: TestLibERC20Token as ContractArtifact,
TestLibERC20TokenTarget: TestLibERC20TokenTarget as ContractArtifact,
UntransferrableDummyERC20Token: UntransferrableDummyERC20Token as ContractArtifact,
};

View File

@@ -1,19 +0,0 @@
import { env, EnvVars } from '@0x/dev-utils';
import { coverage, profiler, provider } from '@0x/contracts-test-utils';
import { providerUtils } from '@0x/utils';
before('start web3 provider', () => {
providerUtils.startProviderEngine(provider);
});
after('generate coverage report', async () => {
if (env.parseBoolean(EnvVars.SolidityCoverage)) {
const coverageSubprovider = coverage.getCoverageSubproviderSingleton();
await coverageSubprovider.writeCoverageAsync();
}
if (env.parseBoolean(EnvVars.SolidityProfiler)) {
const profilerSubprovider = profiler.getProfilerSubproviderSingleton();
await profilerSubprovider.writeProfilerOutputAsync();
}
provider.stop();
});

View File

@@ -1,335 +0,0 @@
import {
blockchainTests,
constants,
expect,
getRandomInteger,
randomAddress,
verifyEventsFromLogs,
} from '@0x/contracts-test-utils';
import { hexUtils, RawRevertError, StringRevertError } from '@0x/utils';
import { TestLibERC20TokenContract, TestLibERC20TokenTargetEvents } from './wrappers';
import { artifacts } from './artifacts';
blockchainTests('LibERC20Token', env => {
let testContract: TestLibERC20TokenContract;
const REVERT_STRING = 'WHOOPSIE';
const ENCODED_REVERT = new StringRevertError(REVERT_STRING).encode();
const ENCODED_TRUE = hexUtils.leftPad(1);
const ENCODED_FALSE = hexUtils.leftPad(0);
const ENCODED_TWO = hexUtils.leftPad(2);
const ENCODED_SHORT_TRUE = hexUtils.leftPad(2, 31);
const ENCODED_LONG_TRUE = hexUtils.leftPad(2, 33);
before(async () => {
testContract = await TestLibERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.TestLibERC20Token,
env.provider,
env.txDefaults,
artifacts,
);
});
describe('approve()', () => {
it('calls the target with the correct arguments', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const { logs } = await testContract
.testApprove(false, ENCODED_REVERT, ENCODED_TRUE, spender, allowance)
.awaitTransactionSuccessAsync();
expect(logs).to.be.length(1);
verifyEventsFromLogs(logs, [{ spender, allowance }], TestLibERC20TokenTargetEvents.ApproveCalled);
});
it('succeeds if the target returns true', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
await testContract
.testApprove(false, ENCODED_REVERT, ENCODED_TRUE, spender, allowance)
.awaitTransactionSuccessAsync();
});
it('succeeds if the target returns nothing', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
await testContract
.testApprove(false, ENCODED_REVERT, constants.NULL_BYTES, spender, allowance)
.awaitTransactionSuccessAsync();
});
it('fails if the target returns false', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const tx = testContract
.testApprove(false, ENCODED_REVERT, ENCODED_FALSE, spender, allowance)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_FALSE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns nonzero and not true', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const tx = testContract
.testApprove(false, ENCODED_REVERT, ENCODED_TWO, spender, allowance)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_TWO);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns less than 32 bytes', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const tx = testContract
.testApprove(false, ENCODED_REVERT, ENCODED_SHORT_TRUE, spender, allowance)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_SHORT_TRUE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns greater than 32 bytes', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const tx = testContract
.testApprove(false, ENCODED_REVERT, ENCODED_LONG_TRUE, spender, allowance)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_LONG_TRUE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target reverts', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const tx = testContract
.testApprove(true, ENCODED_REVERT, ENCODED_TRUE, spender, allowance)
.awaitTransactionSuccessAsync();
return expect(tx).to.revertWith(REVERT_STRING);
});
it('fails if the target reverts with no data', async () => {
const spender = randomAddress();
const allowance = getRandomInteger(0, 100e18);
const tx = testContract
.testApprove(true, constants.NULL_BYTES, ENCODED_TRUE, spender, allowance)
.awaitTransactionSuccessAsync();
return expect(tx).to.be.rejectedWith('revert');
});
});
describe('transfer()', () => {
it('calls the target with the correct arguments', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const { logs } = await testContract
.testTransfer(false, ENCODED_REVERT, ENCODED_TRUE, to, amount)
.awaitTransactionSuccessAsync();
expect(logs).to.be.length(1);
verifyEventsFromLogs(logs, [{ to, amount }], TestLibERC20TokenTargetEvents.TransferCalled);
});
it('succeeds if the target returns true', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
await testContract
.testTransfer(false, ENCODED_REVERT, ENCODED_TRUE, to, amount)
.awaitTransactionSuccessAsync();
});
it('succeeds if the target returns nothing', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
await testContract
.testTransfer(false, ENCODED_REVERT, constants.NULL_BYTES, to, amount)
.awaitTransactionSuccessAsync();
});
it('fails if the target returns false', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransfer(false, ENCODED_REVERT, ENCODED_FALSE, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_FALSE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns nonzero and not true', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransfer(false, ENCODED_REVERT, ENCODED_TWO, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_TWO);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns less than 32 bytes', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransfer(false, ENCODED_REVERT, ENCODED_SHORT_TRUE, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_SHORT_TRUE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns greater than 32 bytes', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransfer(false, ENCODED_REVERT, ENCODED_LONG_TRUE, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_LONG_TRUE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target reverts', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransfer(true, ENCODED_REVERT, ENCODED_TRUE, to, amount)
.awaitTransactionSuccessAsync();
return expect(tx).to.revertWith(REVERT_STRING);
});
it('fails if the target reverts with no data', async () => {
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransfer(true, constants.NULL_BYTES, ENCODED_TRUE, to, amount)
.awaitTransactionSuccessAsync();
return expect(tx).to.be.rejectedWith('revert');
});
});
describe('transferFrom()', () => {
it('calls the target with the correct arguments', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const { logs } = await testContract
.testTransferFrom(false, ENCODED_REVERT, ENCODED_TRUE, owner, to, amount)
.awaitTransactionSuccessAsync();
expect(logs).to.be.length(1);
verifyEventsFromLogs(logs, [{ from: owner, to, amount }], TestLibERC20TokenTargetEvents.TransferFromCalled);
});
it('succeeds if the target returns true', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
await testContract
.testTransferFrom(false, ENCODED_REVERT, ENCODED_TRUE, owner, to, amount)
.awaitTransactionSuccessAsync();
});
it('succeeds if the target returns nothing', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
await testContract
.testTransferFrom(false, ENCODED_REVERT, constants.NULL_BYTES, owner, to, amount)
.awaitTransactionSuccessAsync();
});
it('fails if the target returns false', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransferFrom(false, ENCODED_REVERT, ENCODED_FALSE, owner, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_FALSE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns nonzero and not true', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransferFrom(false, ENCODED_REVERT, ENCODED_TWO, owner, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_TWO);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns less than 32 bytes', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransferFrom(false, ENCODED_REVERT, ENCODED_SHORT_TRUE, owner, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_SHORT_TRUE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target returns greater than 32 bytes', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransferFrom(false, ENCODED_REVERT, ENCODED_LONG_TRUE, owner, to, amount)
.awaitTransactionSuccessAsync();
const expectedError = new RawRevertError(ENCODED_LONG_TRUE);
return expect(tx).to.revertWith(expectedError);
});
it('fails if the target reverts', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransferFrom(true, ENCODED_REVERT, ENCODED_TRUE, owner, to, amount)
.awaitTransactionSuccessAsync();
return expect(tx).to.revertWith(REVERT_STRING);
});
it('fails if the target reverts with no data', async () => {
const owner = randomAddress();
const to = randomAddress();
const amount = getRandomInteger(0, 100e18);
const tx = testContract
.testTransferFrom(true, constants.NULL_BYTES, ENCODED_TRUE, owner, to, amount)
.awaitTransactionSuccessAsync();
return expect(tx).to.be.rejectedWith('revert');
});
});
describe('decimals()', () => {
const DEFAULT_DECIMALS = 18;
const ENCODED_ZERO = hexUtils.leftPad(0);
const ENCODED_SHORT_ZERO = hexUtils.leftPad(0, 31);
const ENCODED_LONG_ZERO = hexUtils.leftPad(0, 33);
const randomDecimals = () => Math.floor(Math.random() * 256) + 1;
it('returns the number of decimals defined by the token', async () => {
const decimals = randomDecimals();
const encodedDecimals = hexUtils.leftPad(decimals);
const result = await testContract.testDecimals(false, ENCODED_REVERT, encodedDecimals).callAsync();
return expect(result).to.bignumber.eq(decimals);
});
it('returns 0 if the token returns 0', async () => {
const result = await testContract.testDecimals(false, ENCODED_REVERT, ENCODED_ZERO).callAsync();
return expect(result).to.bignumber.eq(0);
});
it('returns 18 if the token returns less than 32 bytes', async () => {
const result = await testContract.testDecimals(false, ENCODED_REVERT, ENCODED_SHORT_ZERO).callAsync();
return expect(result).to.bignumber.eq(DEFAULT_DECIMALS);
});
it('returns 18 if the token returns greater than 32 bytes', async () => {
const result = await testContract.testDecimals(false, ENCODED_REVERT, ENCODED_LONG_ZERO).callAsync();
return expect(result).to.bignumber.eq(DEFAULT_DECIMALS);
});
it('returns 18 if the token reverts', async () => {
const result = await testContract.testDecimals(true, ENCODED_REVERT, ENCODED_ZERO).callAsync();
return expect(result).to.bignumber.eq(DEFAULT_DECIMALS);
});
});
});

View File

@@ -1,187 +0,0 @@
import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai';
import { DummyERC20TokenContract } from './wrappers';
import { artifacts } from './artifacts';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('UnlimitedAllowanceToken', () => {
let owner: string;
let spender: string;
const MAX_MINT_VALUE = new BigNumber(10000000000000000000000);
let token: DummyERC20TokenContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
spender = accounts[1];
token = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC20Token,
provider,
txDefaults,
artifacts,
constants.DUMMY_TOKEN_NAME,
constants.DUMMY_TOKEN_SYMBOL,
constants.DUMMY_TOKEN_DECIMALS,
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.mint(MAX_MINT_VALUE).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('transfer', () => {
it('should revert if owner has insufficient balance', async () => {
const ownerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = ownerBalance.plus(1);
return expect(token.transfer(spender, amountToTransfer).callAsync({ from: owner })).to.revertWith(
RevertReason.Erc20InsufficientBalance,
);
});
it('should transfer balance from sender to receiver', async () => {
const receiver = spender;
const initOwnerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = new BigNumber(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.transfer(receiver, amountToTransfer).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const finalOwnerBalance = await token.balanceOf(owner).callAsync();
const finalReceiverBalance = await token.balanceOf(receiver).callAsync();
const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer);
const expectedFinalReceiverBalance = amountToTransfer;
expect(finalOwnerBalance).to.be.bignumber.equal(expectedFinalOwnerBalance);
expect(finalReceiverBalance).to.be.bignumber.equal(expectedFinalReceiverBalance);
});
it('should return true on a 0 value transfer', async () => {
const didReturnTrue = await token.transfer(spender, new BigNumber(0)).callAsync({
from: owner,
});
expect(didReturnTrue).to.be.true();
});
});
describe('transferFrom', () => {
it('should revert if owner has insufficient balance', async () => {
const ownerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = ownerBalance.plus(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.approve(spender, amountToTransfer).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
return expect(
token.transferFrom(owner, spender, amountToTransfer).callAsync({
from: spender,
}),
).to.revertWith(RevertReason.Erc20InsufficientBalance);
});
it('should revert if spender has insufficient allowance', async () => {
const ownerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = ownerBalance;
const spenderAllowance = await token.allowance(owner, spender).callAsync();
const isSpenderAllowanceInsufficient = spenderAllowance.comparedTo(amountToTransfer) < 0;
expect(isSpenderAllowanceInsufficient).to.be.true();
return expect(
token.transferFrom(owner, spender, amountToTransfer).callAsync({
from: spender,
}),
).to.revertWith(RevertReason.Erc20InsufficientAllowance);
});
it('should return true on a 0 value transfer', async () => {
const amountToTransfer = new BigNumber(0);
const didReturnTrue = await token.transferFrom(owner, spender, amountToTransfer).callAsync({
from: spender,
});
expect(didReturnTrue).to.be.true();
});
it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => {
const initOwnerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
await web3Wrapper.awaitTransactionSuccessAsync(
await token.approve(spender, initSpenderAllowance).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
from: spender,
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newSpenderAllowance = await token.allowance(owner, spender).callAsync();
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
});
it('should transfer the correct balances if spender has sufficient allowance', async () => {
const initOwnerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
await web3Wrapper.awaitTransactionSuccessAsync(
await token.approve(spender, initSpenderAllowance).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
from: spender,
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newOwnerBalance = await token.balanceOf(owner).callAsync();
const newSpenderBalance = await token.balanceOf(spender).callAsync();
expect(newOwnerBalance).to.be.bignumber.equal(0);
expect(newSpenderBalance).to.be.bignumber.equal(initOwnerBalance);
});
it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => {
const initOwnerBalance = await token.balanceOf(owner).callAsync();
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
await web3Wrapper.awaitTransactionSuccessAsync(
await token.approve(spender, initSpenderAllowance).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
from: spender,
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newSpenderAllowance = await token.allowance(owner, spender).callAsync();
expect(newSpenderAllowance).to.be.bignumber.equal(0);
});
});
});

View File

@@ -1,149 +0,0 @@
import {
chaiSetup,
constants,
expectInsufficientFundsAsync,
expectTransactionFailedWithoutReasonAsync,
provider,
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import { WETH9Contract } from './wrappers';
import { artifacts } from './artifacts';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('EtherToken', () => {
let account: string;
const gasPrice = new BigNumber(constants.DEFAULT_GAS_PRICE);
let etherToken: WETH9Contract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
account = accounts[0];
etherToken = await WETH9Contract.deployFrom0xArtifactAsync(
artifacts.WETH9,
provider,
{
...txDefaults,
gasPrice,
},
artifacts,
);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('deposit', () => {
it('should revert if caller attempts to deposit more Ether than caller balance', async () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethToDeposit = initEthBalance.plus(1);
return expectInsufficientFundsAsync(etherToken.deposit().sendTransactionAsync({ value: ethToDeposit }));
});
it('should convert deposited Ether to wrapped Ether tokens', async () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
const txHash = await etherToken.deposit().sendTransactionAsync({ value: ethToDeposit });
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(
txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const finalEthTokenBalance = await etherToken.balanceOf(account).callAsync();
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
});
});
describe('withdraw', () => {
it('should revert if caller attempts to withdraw greater than caller balance', async () => {
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
const ethTokensToWithdraw = initEthTokenBalance.plus(1);
return expectTransactionFailedWithoutReasonAsync(
etherToken.withdraw(ethTokensToWithdraw).sendTransactionAsync(),
);
});
it('should convert ether tokens to ether with sufficient balance', async () => {
const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1)));
await web3Wrapper.awaitTransactionSuccessAsync(
await etherToken.deposit().sendTransactionAsync({ value: ethToDeposit }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethTokensToWithdraw = initEthTokenBalance;
expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0);
const txHash = await etherToken.withdraw(ethTokensToWithdraw).sendTransactionAsync({
gas: constants.MAX_ETHERTOKEN_WITHDRAW_GAS,
});
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(
txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const finalEthTokenBalance = await etherToken.balanceOf(account).callAsync();
expect(finalEthBalance).to.be.bignumber.equal(
initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)),
);
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw));
});
});
describe('fallback', () => {
it('should convert sent ether to ether tokens', async () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const initEthTokenBalance = await etherToken.balanceOf(account).callAsync();
const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18);
const txHash = await web3Wrapper.sendTransactionAsync({
from: account,
to: etherToken.address,
value: ethToDeposit,
gasPrice,
});
const receipt = await web3Wrapper.awaitTransactionSuccessAsync(
txHash,
constants.AWAIT_TRANSACTION_MINED_MS,
);
const ethSpentOnGas = gasPrice.times(receipt.gasUsed);
const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const finalEthTokenBalance = await etherToken.balanceOf(account).callAsync();
expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas)));
expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit));
});
});
});

View File

@@ -1,22 +0,0 @@
/*
* -----------------------------------------------------------------------------
* Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* -----------------------------------------------------------------------------
*/
export * from '../test/generated-wrappers/dummy_erc20_token';
export * from '../test/generated-wrappers/dummy_multiple_return_erc20_token';
export * from '../test/generated-wrappers/dummy_no_return_erc20_token';
export * from '../test/generated-wrappers/erc20_token';
export * from '../test/generated-wrappers/i_erc20_token';
export * from '../test/generated-wrappers/i_erc20_token_v06';
export * from '../test/generated-wrappers/i_ether_token';
export * from '../test/generated-wrappers/i_ether_token_v06';
export * from '../test/generated-wrappers/lib_erc20_token';
export * from '../test/generated-wrappers/lib_erc20_token_v06';
export * from '../test/generated-wrappers/mintable_erc20_token';
export * from '../test/generated-wrappers/test_lib_erc20_token';
export * from '../test/generated-wrappers/test_lib_erc20_token_target';
export * from '../test/generated-wrappers/unlimited_allowance_erc20_token';
export * from '../test/generated-wrappers/untransferrable_dummy_erc20_token';
export * from '../test/generated-wrappers/weth9';
export * from '../test/generated-wrappers/zrx_token';

View File

@@ -1,210 +0,0 @@
import { chaiSetup, constants, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai';
import { ZRXTokenContract } from './wrappers';
import { artifacts } from './artifacts';
chaiSetup.configure();
const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
describe('ZRXToken', () => {
let owner: string;
let spender: string;
let MAX_UINT: BigNumber;
let zrxToken: ZRXTokenContract;
before(async () => {
await blockchainLifecycle.startAsync();
});
after(async () => {
await blockchainLifecycle.revertAsync();
});
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
owner = accounts[0];
spender = accounts[1];
zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(
artifacts.ZRXToken,
provider,
txDefaults,
artifacts,
);
MAX_UINT = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('constants', () => {
it('should have 18 decimals', async () => {
const decimals = new BigNumber(await zrxToken.decimals().callAsync());
const expectedDecimals = 18;
expect(decimals).to.be.bignumber.equal(expectedDecimals);
});
it('should have a total supply of 1 billion tokens', async () => {
const totalSupply = new BigNumber(await zrxToken.totalSupply().callAsync());
const expectedTotalSupply = 1000000000;
expect(Web3Wrapper.toUnitAmount(totalSupply, 18)).to.be.bignumber.equal(expectedTotalSupply);
});
it('should be named 0x Protocol Token', async () => {
const name = await zrxToken.name().callAsync();
const expectedName = '0x Protocol Token';
expect(name).to.be.equal(expectedName);
});
it('should have the symbol ZRX', async () => {
const symbol = await zrxToken.symbol().callAsync();
const expectedSymbol = 'ZRX';
expect(symbol).to.be.equal(expectedSymbol);
});
});
describe('constructor', () => {
it('should initialize owner balance to totalSupply', async () => {
const ownerBalance = await zrxToken.balanceOf(owner).callAsync();
const totalSupply = new BigNumber(await zrxToken.totalSupply().callAsync());
expect(totalSupply).to.be.bignumber.equal(ownerBalance);
});
});
describe('transfer', () => {
it('should transfer balance from sender to receiver', async () => {
const receiver = spender;
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
const amountToTransfer = new BigNumber(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.transfer(receiver, amountToTransfer).sendTransactionAsync({ from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const finalOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
const finalReceiverBalance = await zrxToken.balanceOf(receiver).callAsync();
const expectedFinalOwnerBalance = initOwnerBalance.minus(amountToTransfer);
const expectedFinalReceiverBalance = amountToTransfer;
expect(finalOwnerBalance).to.be.bignumber.equal(expectedFinalOwnerBalance);
expect(finalReceiverBalance).to.be.bignumber.equal(expectedFinalReceiverBalance);
});
it('should return true on a 0 value transfer', async () => {
const didReturnTrue = await zrxToken.transfer(spender, new BigNumber(0)).callAsync({
from: owner,
});
expect(didReturnTrue).to.be.true();
});
});
describe('transferFrom', () => {
it('should return false if owner has insufficient balance', async () => {
const ownerBalance = await zrxToken.balanceOf(owner).callAsync();
const amountToTransfer = ownerBalance.plus(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve(spender, amountToTransfer).sendTransactionAsync({
from: owner,
gas: constants.MAX_TOKEN_APPROVE_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const didReturnTrue = await zrxToken.transferFrom(owner, spender, amountToTransfer).callAsync({
from: spender,
});
expect(didReturnTrue).to.be.false();
});
it('should return false if spender has insufficient allowance', async () => {
const ownerBalance = await zrxToken.balanceOf(owner).callAsync();
const amountToTransfer = ownerBalance;
const spenderAllowance = await zrxToken.allowance(owner, spender).callAsync();
const isSpenderAllowanceInsufficient = spenderAllowance.comparedTo(amountToTransfer) < 0;
expect(isSpenderAllowanceInsufficient).to.be.true();
const didReturnTrue = await zrxToken.transferFrom(owner, spender, amountToTransfer).callAsync({
from: spender,
});
expect(didReturnTrue).to.be.false();
});
it('should return true on a 0 value transfer', async () => {
const amountToTransfer = new BigNumber(0);
const didReturnTrue = await zrxToken.transferFrom(owner, spender, amountToTransfer).callAsync({
from: spender,
});
expect(didReturnTrue).to.be.true();
});
it('should not modify spender allowance if spender allowance is 2^256 - 1', async () => {
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = MAX_UINT;
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve(spender, initSpenderAllowance).sendTransactionAsync({
from: owner,
gas: constants.MAX_TOKEN_APPROVE_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
from: spender,
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newSpenderAllowance = await zrxToken.allowance(owner, spender).callAsync();
expect(initSpenderAllowance).to.be.bignumber.equal(newSpenderAllowance);
});
it('should transfer the correct balances if spender has sufficient allowance', async () => {
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
const initSpenderBalance = await zrxToken.balanceOf(spender).callAsync();
const amountToTransfer = initOwnerBalance;
const initSpenderAllowance = initOwnerBalance;
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve(spender, initSpenderAllowance).sendTransactionAsync(),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
from: spender,
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
const newSpenderBalance = await zrxToken.balanceOf(spender).callAsync();
expect(newOwnerBalance).to.be.bignumber.equal(0);
expect(newSpenderBalance).to.be.bignumber.equal(initSpenderBalance.plus(initOwnerBalance));
});
it('should modify allowance if spender has sufficient allowance less than 2^256 - 1', async () => {
const initOwnerBalance = await zrxToken.balanceOf(owner).callAsync();
const amountToTransfer = initOwnerBalance;
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.approve(spender, amountToTransfer).sendTransactionAsync(),
constants.AWAIT_TRANSACTION_MINED_MS,
);
await web3Wrapper.awaitTransactionSuccessAsync(
await zrxToken.transferFrom(owner, spender, amountToTransfer).sendTransactionAsync({
from: spender,
gas: constants.MAX_TOKEN_TRANSFERFROM_GAS,
}),
constants.AWAIT_TRANSACTION_MINED_MS,
);
const newSpenderAllowance = await zrxToken.allowance(owner, spender).callAsync();
expect(newSpenderAllowance).to.be.bignumber.equal(0);
});
});
});

View File

@@ -1,96 +0,0 @@
/**
* Use this file to configure your truffle project. It's seeded with some
* common settings for different networks and features like migrations,
* compilation and testing. Uncomment the ones you need or modify
* them to suit your project as necessary.
*
* More information about configuration can be found at:
*
* truffleframework.com/docs/advanced/configuration
*
* To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider)
* to sign your transactions before they're sent to a remote public node. Infura accounts
* are available for free at: infura.io/register.
*
* You'll also need a mnemonic - the twelve word phrase the wallet uses to generate
* public/private key pairs. If you're publishing your code to GitHub make sure you load this
* phrase from a file you've .gitignored so it doesn't accidentally become public.
*
*/
// const HDWalletProvider = require('truffle-hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
// const fs = require('fs');
// const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
/**
* Networks define how you connect to your ethereum client and let you set the
* defaults web3 uses to send transactions. If you don't specify one truffle
* will spin up a development blockchain for you on port 9545 when you
* run `develop` or `test`. You can ask a truffle command to use a specific
* network from the command line, e.g
*
* $ truffle test --network <network-name>
*/
networks: {
// Useful for testing. The `development` name is special - truffle uses it by default
// if it's defined here and no other network is specified at the command line.
// You should run a client (like ganache-cli, geth or parity) in a separate terminal
// tab if you use this network and you must also set the `host`, `port` and `network_id`
// options below to some value.
//
// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },
// Another network with more advanced options...
// advanced: {
// port: 8777, // Custom port
// network_id: 1342, // Custom network
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
// from: <address>, // Account to send txs from (default: accounts[0])
// websockets: true // Enable EventEmitter interface for web3 (default: false)
// },
// Useful for deploying to a public network.
// NB: It's important to wrap the provider as a function.
// ropsten: {
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
// network_id: 3, // Ropsten's id
// gas: 5500000, // Ropsten has a lower block limit than mainnet
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
// },
// Useful for private networks
// private: {
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// }
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: '0.5.9',
settings: {
evmVersion: 'constantinople',
optimizer: {
enabled: true,
runs: 1000000,
details: { yul: true, deduplicate: true, cse: true, constantOptimizer: true },
},
},
},
},
};

View File

@@ -1,31 +0,0 @@
{
"extends": "../../tsconfig",
"compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true },
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
"files": [
"generated-artifacts/DummyERC20Token.json",
"generated-artifacts/DummyMultipleReturnERC20Token.json",
"generated-artifacts/DummyNoReturnERC20Token.json",
"generated-artifacts/ERC20Token.json",
"generated-artifacts/WETH9.json",
"generated-artifacts/ZRXToken.json",
"test/generated-artifacts/DummyERC20Token.json",
"test/generated-artifacts/DummyMultipleReturnERC20Token.json",
"test/generated-artifacts/DummyNoReturnERC20Token.json",
"test/generated-artifacts/ERC20Token.json",
"test/generated-artifacts/IERC20Token.json",
"test/generated-artifacts/IERC20TokenV06.json",
"test/generated-artifacts/IEtherToken.json",
"test/generated-artifacts/IEtherTokenV06.json",
"test/generated-artifacts/LibERC20Token.json",
"test/generated-artifacts/LibERC20TokenV06.json",
"test/generated-artifacts/MintableERC20Token.json",
"test/generated-artifacts/TestLibERC20Token.json",
"test/generated-artifacts/TestLibERC20TokenTarget.json",
"test/generated-artifacts/UnlimitedAllowanceERC20Token.json",
"test/generated-artifacts/UntransferrableDummyERC20Token.json",
"test/generated-artifacts/WETH9.json",
"test/generated-artifacts/ZRXToken.json"
],
"exclude": ["./deploy/solc/solc_bin"]
}

View File

@@ -1,6 +0,0 @@
{
"extends": ["@0x/tslint-config"],
"rules": {
"custom-no-magic-numbers": false
}
}

View File

@@ -1,7 +0,0 @@
{
"extends": "../../typedoc-tsconfig",
"compilerOptions": {
"outDir": "lib"
},
"include": ["./src/**/*", "./test/**/*"]
}

View File

@@ -0,0 +1,47 @@
[
{
"timestamp": 1682976338,
"version": "1.0.5",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681756154,
"version": "1.0.4",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681694690,
"version": "1.0.3",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681687842,
"version": "1.0.2",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681157139,
"version": "1.0.1",
"changes": [
{
"note": "Dependencies updated"
}
]
}
]

View File

@@ -0,0 +1,26 @@
<!--
changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly.
Edit the package's CHANGELOG.json file only.
-->
CHANGELOG
## v1.0.5 - _May 1, 2023_
* Dependencies updated
## v1.0.4 - _April 17, 2023_
* Dependencies updated
## v1.0.3 - _April 17, 2023_
* Dependencies updated
## v1.0.2 - _April 16, 2023_
* Dependencies updated
## v1.0.1 - _April 10, 2023_
* Dependencies updated

View File

@@ -0,0 +1,74 @@
## Governance
This package contains contracts for the ZeroEx governance of 0x Protocol and Treasury.
## Production deployment
`ZRXWrappedToken` 0xfcfaf7834f134f5146dbb3274bab9bed4bafa917
`ZeroExVotesProxy` 0x9c766e51b46cbc1fa4f8b6718ed4a60ac9d591fb
`ZeroExVotes` 0x8d208c5514b98c5b9ceed650b02df2aeb1c73e6f
Protocol `ZeroExTimelock` 0xb6a1f58c5df9f13312639cddda0d128bf28cdd87
`ZeroExProtocolGovernor` 0xc256035fe8533f9ce362012a6ae0aefed4df30f4
Treasury `ZeroExTimelock` 0x0dcfb77a581bc8fe432e904643a5480cc183f38d
`ZeroExTreasuryGovernor` 0x4822cfc1e7699bdb9551bdfd3a838ee414bc2008
Security council 0x979BDb496e5f0A00af078b7a45F1E9E6bcff170F
## Design
This implementation fully decentralises governance of 0x Protocol and Treasury. This is enabled via a wrapped ZRX token and a Compound-like governors design. There are two separate governors for Protocol - `ZeroExProtocolGovernor` and Treasury - `ZeroExTreasuryGovernor` respectively working with two separate Timelock instances of the same contract implementation - `ZeroExTimelock`.
### Upgradability
`ZRXWrappedToken` , `ZeroExProtocolGovernor` and `ZeroExTreasuryGovernor` governors are non-upgradable by design. However the voting implementation the governors use - `ZeroExVotes` is upgradable and using the OZ `ERC1967Proxy`.
### Wrapped ZRX
wZRX will be issued 1-to-1 for ZRX. No locking/vesting mechanisms will exist between wZRX and ZRX and the two will be freely interchangeable. The ZRX token is non-upgradable and same will be valid for its wrapped equivalent.
The token supports delegation which allows a user to delegate their entire voting power to another account (which doesn't necessarily need to be a token holder). This is modelled on the standard OpenZeppelin `ERC20Votes` implementation. We have added logic for block number stamping delegators' balance changes stored in the `DelegateInfo.balanceLastUpdated` property. This block number information is sent in calls to `ZeroExVotes.moveVotingPower` in order to provide support for future upgrades to the vote power calculation.
Note that for consistency `block.number` is used for the governor settings, voting checkpoints and this delegators' balance last updated property while timelock logic for the governor uses block.timestamp.
### Governors' settings
Changing governors' settings for `votingDelay`, `votingPeriod` and `proposalThreshold` can be done via the normal proposal mechanism. Governors are deployed with the following initial settings:
| | voting delay | voting period | proposal threshold |
|-------------------|--------------|---------------|--------------------|
| Protocol governor | 2 days | 7 days | 1000000e18 |
| Treasury governor | 2 days | 7 days | 250000e18 |
This is using standard openzeppelin `GovernorSettings` implementation.
### Quorum
Quorum for Protocol is fixed at 10m (10000000e18) while for Treasury this is calculated as 10% of voting power of the total supply (see voting strategies below for quadratic voting power implementation specifics). The quorum calculations for Treasury are using OpenZeppelin's `GovernorVotesQuorumFraction`.
Note that in-place updates to the quorum are not supported and will need to go through a governance upgrade. Reasoning behind this can be found in this discussion https://forum.openzeppelin.com/t/quorum-default-behaviour-on-governors/34560.
### Voting strategies
The voting strategy will be linear 1-token-1-vote for Protocol and quadratic with threshold of 1000000e18 for Treasury (i.e. voting weight is linear up to 1m tokens and balance above that threshold is quadratic).
Worth noting is the `Checkpoint` struct design. For packing every `Checkpoint` into a single storage slot we are using the minimum uint type size for `votes` and `quadraticVotes` members, e.g.
```
struct Checkpoint {
uint32 fromBlock;
uint96 votes;
uint96 quadraticVotes;
}
```
since the maximum token supply is 1bn we can have maximum value for:
`votes` : 1bn *10^18 => can be stored in 90 bits
`quadraticVotes` : due to the likelihood of threshold changing and potentially bringing it closer to a linear vote, we are preemptively keeping this to the same size as linear votes slot.
### Time locks
Governance proposals are subject to a 3 days delay for Protocol and 2 days for Treasury. This delay allows Security Council time to review passed proposals and take action where needed.
### Security Council
The concept of a Security council is introduced which allows a multisig of security council members to cancel a proposal on the treasury or protocol governors and also rollback the protocol to an earlier version.
When no security council is assigned the following apply:
- ongoing proposals can still be voted on
- new proposals cannot be created - except assignSecurityCouncil
- expired proposals that are successful cannot be queued - excepted assignSecurityCouncil
There is a provision for the governors to have different security council set although initially these are the same.

View File

@@ -0,0 +1,505 @@
{
"abi": [
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"type": "function"
},
{
"inputs": [],
"payable": false,
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "_to",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_owner",
"type": "address"
},
{
"indexed": true,
"name": "_spender",
"type": "address"
},
{
"indexed": false,
"name": "_value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
}
],
"bytecode": {
"object": "0x60606040526b033b2e3c9fd0803ce8000000600355341561001c57fe5b5b600354600160a060020a0333166000908152602081905260409020555b5b61078d8061004a6000396000f300606060405236156100965763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610098578063095ea7b31461014657806318160ddd1461018657806323b872dd146101a8578063313ce567146101ee57806370a082311461021457806395d89b411461024f578063a9059cbb146102fd578063dd62ed3e1461033d575bfe5b34156100a057fe5b6100a861037e565b60408051602080825283518183015283519192839290830191850190808383821561010c575b80518252602083111561010c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016100ce565b505050905090810190601f1680156101385780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014e57fe5b61017273ffffffffffffffffffffffffffffffffffffffff600435166024356103b5565b604080519115158252519081900360200190f35b341561018e57fe5b61019661042d565b60408051918252519081900360200190f35b34156101b057fe5b61017273ffffffffffffffffffffffffffffffffffffffff60043581169060243516604435610433565b604080519115158252519081900360200190f35b34156101f657fe5b6101fe6105d4565b6040805160ff9092168252519081900360200190f35b341561021c57fe5b61019673ffffffffffffffffffffffffffffffffffffffff600435166105d9565b60408051918252519081900360200190f35b341561025757fe5b6100a8610605565b60408051602080825283518183015283519192839290830191850190808383821561010c575b80518252602083111561010c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016100ce565b505050905090810190601f1680156101385780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561030557fe5b61017273ffffffffffffffffffffffffffffffffffffffff6004351660243561063c565b604080519115158252519081900360200190f35b341561034557fe5b61019673ffffffffffffffffffffffffffffffffffffffff60043581169060243516610727565b60408051918252519081900360200190f35b60408051808201909152601181527f30782050726f746f636f6c20546f6b656e000000000000000000000000000000602082015281565b73ffffffffffffffffffffffffffffffffffffffff338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60035481565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832033909516835293815283822054928252819052918220548390108015906104835750828110155b80156104b6575073ffffffffffffffffffffffffffffffffffffffff841660009081526020819052604090205483810110155b156105c65773ffffffffffffffffffffffffffffffffffffffff808516600090815260208190526040808220805487019055918716815220805484900390557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156105585773ffffffffffffffffffffffffffffffffffffffff808616600090815260016020908152604080832033909416835292905220805484900390555b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3600191506105cb565b600091505b5b509392505050565b601281565b73ffffffffffffffffffffffffffffffffffffffff81166000908152602081905260409020545b919050565b60408051808201909152600381527f5a52580000000000000000000000000000000000000000000000000000000000602082015281565b73ffffffffffffffffffffffffffffffffffffffff3316600090815260208190526040812054829010801590610699575073ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604090205482810110155b156107185773ffffffffffffffffffffffffffffffffffffffff33811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a3506001610427565b506000610427565b5b92915050565b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600160209081526040808320938516835292905220545b929150505600a165627a7a723058202dbef854545f38e5b78ec251d65db5fa0f12b6f2f0a0039063735c2dc416d6310029",
"sourceMap": "4935:353:0:-;;;5056:8;5027:37;;5208:78;;;;;;;5268:11;;-1:-1:-1;;;;;5254:10:0;5245:20;:8;:20;;;;;;;;;;:34;5208:78;4935:353;;;;;;;",
"linkReferences": {}
},
"deployedBytecode": {
"object": "0x606060405236156100965763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde038114610098578063095ea7b31461014657806318160ddd1461018657806323b872dd146101a8578063313ce567146101ee57806370a082311461021457806395d89b411461024f578063a9059cbb146102fd578063dd62ed3e1461033d575bfe5b34156100a057fe5b6100a861037e565b60408051602080825283518183015283519192839290830191850190808383821561010c575b80518252602083111561010c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016100ce565b505050905090810190601f1680156101385780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561014e57fe5b61017273ffffffffffffffffffffffffffffffffffffffff600435166024356103b5565b604080519115158252519081900360200190f35b341561018e57fe5b61019661042d565b60408051918252519081900360200190f35b34156101b057fe5b61017273ffffffffffffffffffffffffffffffffffffffff60043581169060243516604435610433565b604080519115158252519081900360200190f35b34156101f657fe5b6101fe6105d4565b6040805160ff9092168252519081900360200190f35b341561021c57fe5b61019673ffffffffffffffffffffffffffffffffffffffff600435166105d9565b60408051918252519081900360200190f35b341561025757fe5b6100a8610605565b60408051602080825283518183015283519192839290830191850190808383821561010c575b80518252602083111561010c577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016100ce565b505050905090810190601f1680156101385780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561030557fe5b61017273ffffffffffffffffffffffffffffffffffffffff6004351660243561063c565b604080519115158252519081900360200190f35b341561034557fe5b61019673ffffffffffffffffffffffffffffffffffffffff60043581169060243516610727565b60408051918252519081900360200190f35b60408051808201909152601181527f30782050726f746f636f6c20546f6b656e000000000000000000000000000000602082015281565b73ffffffffffffffffffffffffffffffffffffffff338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b60035481565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260016020908152604080832033909516835293815283822054928252819052918220548390108015906104835750828110155b80156104b6575073ffffffffffffffffffffffffffffffffffffffff841660009081526020819052604090205483810110155b156105c65773ffffffffffffffffffffffffffffffffffffffff808516600090815260208190526040808220805487019055918716815220805484900390557fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156105585773ffffffffffffffffffffffffffffffffffffffff808616600090815260016020908152604080832033909416835292905220805484900390555b8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef856040518082815260200191505060405180910390a3600191506105cb565b600091505b5b509392505050565b601281565b73ffffffffffffffffffffffffffffffffffffffff81166000908152602081905260409020545b919050565b60408051808201909152600381527f5a52580000000000000000000000000000000000000000000000000000000000602082015281565b73ffffffffffffffffffffffffffffffffffffffff3316600090815260208190526040812054829010801590610699575073ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604090205482810110155b156107185773ffffffffffffffffffffffffffffffffffffffff33811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a3506001610427565b506000610427565b5b92915050565b73ffffffffffffffffffffffffffffffffffffffff8083166000908152600160209081526040808320938516835292905220545b929150505600a165627a7a723058202dbef854545f38e5b78ec251d65db5fa0f12b6f2f0a0039063735c2dc416d6310029",
"sourceMap": "4935:353:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5109:49;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;18:2:-1;;13:3;7:5;32;59:3;53:5;48:3;41:6;93:2;88:3;85:2;78:6;73:3;67:5;152:3;;;;;117:2;108:3;;;;130;172:5;167:4;181:3;3:186;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3523:190:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5027:37;;;;;;;;;;;;;;;;;;;;;;;;;;4369:562;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4986:35;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3415:102;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5164:37;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;18:2:-1;;13:3;7:5;32;59:3;53:5;48:3;41:6;93:2;88:3;85:2;78:6;73:3;67:5;152:3;;;;;117:2;108:3;;;;130;172:5;167:4;181:3;3:186;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2490:433:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3719:129;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5109:49;;;;;;;;;;;;;;;;;;;:::o;3523:190::-;3599:19;3607:10;3599:19;;3583:4;3599:19;;;:7;:19;;;;;;;;:29;;;;;;;;;;;;:38;;;3647;;;;;;;3583:4;;3599:29;:19;3647:38;;;;;;;;;;;-1:-1:-1;3702:4:0;3523:190;;;;;:::o;5027:37::-;;;;:::o;4369:562::-;4487:14;;;;4451:4;4487:14;;;:7;:14;;;;;;;;4502:10;4487:26;;;;;;;;;;;;4527:15;;;;;;;;;;:25;;;;;;:48;;;4569:6;4556:9;:19;;4527:48;:91;;;;-1:-1:-1;4605:13:0;;;:8;:13;;;;;;;;;;;4579:22;;;:39;;4527:91;4523:402;;;4634:13;;;;:8;:13;;;;;;;;;;;:23;;;;;;4671:15;;;;;;:25;;;;;;;4069:12;4714:20;;4710:95;;;4754:14;;;;;;;;:7;:14;;;;;;;;4769:10;4754:26;;;;;;;;;:36;;;;;;;4710:95;4834:3;4818:28;;4827:5;4818:28;;;4839:6;4818:28;;;;;;;;;;;;;;;;;;4867:4;4860:11;;;;4523:402;4909:5;4902:12;;4523:402;4369:562;;;;;;;:::o;4986:35::-;5019:2;4986:35;:::o;3415:102::-;3494:16;;;3468:7;3494:16;;;;;;;;;;;3415:102;;;;:::o;5164:37::-;;;;;;;;;;;;;;;;;;;:::o;2490:433::-;2635:20;2644:10;2635:20;2546:4;2635:20;;;;;;;;;;;:30;;;;;;:73;;-1:-1:-1;2695:13:0;;;:8;:13;;;;;;;;;;;2669:22;;;:39;;2635:73;2631:286;;;2724:20;2733:10;2724:20;;:8;:20;;;;;;;;;;;:30;;;;;;;2768:13;;;;;;;;;;:23;;;;;;2805:33;;;;;;;2768:13;;2805:33;;;;;;;;;;;-1:-1:-1;2859:4:0;2852:11;;2631:286;-1:-1:-1;2901:5:0;2894:12;;2631:286;2490:433;;;;;:::o;3719:129::-;3816:15;;;;3790:7;3816:15;;;:7;:15;;;;;;;;:25;;;;;;;;;;3719:129;;;;;:::o",
"linkReferences": {}
},
"methodIdentifiers": {
"allowance(address,address)": "dd62ed3e",
"approve(address,uint256)": "095ea7b3",
"balanceOf(address)": "70a08231",
"decimals()": "313ce567",
"name()": "06fdde03",
"symbol()": "95d89b41",
"totalSupply()": "18160ddd",
"transfer(address,uint256)": "a9059cbb",
"transferFrom(address,address,uint256)": "23b872dd"
},
"rawMetadata": "{\"compiler\":{\"version\":\"0.4.11+commit.68ef5810\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"},{\"name\":\"_spender\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"_owner\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"_spender\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"Approval\",\"type\":\"event\"}],\"devdoc\":{\"methods\":{\"transferFrom(address,address,uint256)\":{\"details\":\"ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance.\",\"params\":{\"_from\":\"Address to transfer from.\",\"_to\":\"Address to transfer to.\",\"_value\":\"Amount to transfer.\"},\"return\":\"Success of transfer.\"}}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"contracts/erc20/src/ZRXToken.sol\":\"ZRXToken\"},\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":1000000},\"remappings\":[\":@0x/contracts-erc20/=contracts/erc20/\",\":@0x/contracts-utils/=contracts/utils/\",\":ds-test/=contracts/erc20/lib/forge-std/lib/ds-test/src/\",\":forge-std/=contracts/erc20/lib/forge-std/src/\"]},\"sources\":{\"contracts/erc20/src/ZRXToken.sol\":{\"keccak256\":\"0x8582c06b20f8b7d3d603b485b5d26f840e01d1986381b334a856833edcff0d47\",\"urls\":[\"bzzr://ef728dddbaa1e26baa6cc9fe0f83de5055bc0b17dfe488018f4ee59d68ccb5dd\"]}},\"version\":1}",
"metadata": {
"compiler": {
"version": "0.4.11+commit.68ef5810"
},
"language": "Solidity",
"output": {
"abi": [
{
"inputs": [],
"type": "function",
"name": "name",
"outputs": [
{
"internalType": null,
"name": "",
"type": "string"
}
]
},
{
"inputs": [
{
"internalType": null,
"name": "_spender",
"type": "address"
},
{
"internalType": null,
"name": "_value",
"type": "uint256"
}
],
"type": "function",
"name": "approve",
"outputs": [
{
"internalType": null,
"name": "",
"type": "bool"
}
]
},
{
"inputs": [],
"type": "function",
"name": "totalSupply",
"outputs": [
{
"internalType": null,
"name": "",
"type": "uint256"
}
]
},
{
"inputs": [
{
"internalType": null,
"name": "_from",
"type": "address"
},
{
"internalType": null,
"name": "_to",
"type": "address"
},
{
"internalType": null,
"name": "_value",
"type": "uint256"
}
],
"type": "function",
"name": "transferFrom",
"outputs": [
{
"internalType": null,
"name": "",
"type": "bool"
}
]
},
{
"inputs": [],
"type": "function",
"name": "decimals",
"outputs": [
{
"internalType": null,
"name": "",
"type": "uint8"
}
]
},
{
"inputs": [
{
"internalType": null,
"name": "_owner",
"type": "address"
}
],
"type": "function",
"name": "balanceOf",
"outputs": [
{
"internalType": null,
"name": "",
"type": "uint256"
}
]
},
{
"inputs": [],
"type": "function",
"name": "symbol",
"outputs": [
{
"internalType": null,
"name": "",
"type": "string"
}
]
},
{
"inputs": [
{
"internalType": null,
"name": "_to",
"type": "address"
},
{
"internalType": null,
"name": "_value",
"type": "uint256"
}
],
"type": "function",
"name": "transfer",
"outputs": [
{
"internalType": null,
"name": "",
"type": "bool"
}
]
},
{
"inputs": [
{
"internalType": null,
"name": "_owner",
"type": "address"
},
{
"internalType": null,
"name": "_spender",
"type": "address"
}
],
"type": "function",
"name": "allowance",
"outputs": [
{
"internalType": null,
"name": "",
"type": "uint256"
}
]
},
{
"inputs": [],
"type": "constructor"
},
{
"inputs": [
{
"internalType": null,
"name": "_from",
"type": "address",
"indexed": true
},
{
"internalType": null,
"name": "_to",
"type": "address",
"indexed": true
},
{
"internalType": null,
"name": "_value",
"type": "uint256",
"indexed": false
}
],
"type": "event",
"name": "Transfer",
"anonymous": false
},
{
"inputs": [
{
"internalType": null,
"name": "_owner",
"type": "address",
"indexed": true
},
{
"internalType": null,
"name": "_spender",
"type": "address",
"indexed": true
},
{
"internalType": null,
"name": "_value",
"type": "uint256",
"indexed": false
}
],
"type": "event",
"name": "Approval",
"anonymous": false
}
],
"devdoc": {
"methods": {
"transferFrom(address,address,uint256)": {
"details": "ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited allowance.",
"params": {
"_from": "Address to transfer from.",
"_to": "Address to transfer to.",
"_value": "Amount to transfer."
},
"return": "Success of transfer."
}
}
},
"userdoc": {
"methods": {}
}
},
"settings": {
"remappings": [
":@0x/contracts-erc20/=contracts/erc20/",
":@0x/contracts-utils/=contracts/utils/",
":ds-test/=contracts/erc20/lib/forge-std/lib/ds-test/src/",
":forge-std/=contracts/erc20/lib/forge-std/src/"
],
"optimizer": {
"enabled": true,
"runs": 1000000
},
"compilationTarget": {
"contracts/erc20/src/ZRXToken.sol": "ZRXToken"
},
"libraries": {}
},
"sources": {
"contracts/erc20/src/ZRXToken.sol": {
"keccak256": "0x8582c06b20f8b7d3d603b485b5d26f840e01d1986381b334a856833edcff0d47",
"urls": ["bzzr://ef728dddbaa1e26baa6cc9fe0f83de5055bc0b17dfe488018f4ee59d68ccb5dd"],
"license": null
}
},
"version": 1
},
"id": 0
}

View File

@@ -0,0 +1,37 @@
[profile.default]
src = 'src'
out = 'out'
libs = ['lib', "../utils/contracts/src/"]
match_path = "test/unit/*.sol"
fs_permissions = [{ access = "read", path = "./" }]
remappings = [
'@openzeppelin/=./lib/openzeppelin-contracts/contracts/',
'@openzeppelin-contracts-upgradeable/=./lib/openzeppelin-contracts-upgradeable/contracts/',
'@0x/contracts-utils/=../utils/',
]
solc = '0.8.19'
optimizer_runs = 20_000
via_ir = true
[profile.integration]
match_path = "test/integration/*.sol"
gas_price = 31_000_000_000
[rpc_endpoints]
goerli = "${GOERLI_RPC_URL}"
mainnet = "${MAINNET_RPC_URL}"
[etherscan]
goerli = { key = "${ETHERSCAN_API_KEY}" }
[profile.smt.model_checker]
engine = 'chc'
timeout = 10_000
targets = [
'assert',
'constantCondition',
'divByZero',
'outOfBounds',
'underflow'
]
contracts = { 'src/ZeroExProtocolGovernor.sol' = [ 'ZeroExProtocolGovernor' ] }

View File

@@ -0,0 +1,27 @@
{
"name": "@0x/governance",
"version": "1.0.5",
"description": "Governance implementation for the 0x protocol and treasury",
"main": "index.js",
"directories": {
"lib": "lib",
"test": "test"
},
"scripts": {
"test": "forge test",
"build": "forge build",
"build:smt": "FOUNDRY_PROFILE=smt forge build",
"test:integration": "source .env && FOUNDRY_PROFILE=integration forge test --fork-url $MAINNET_RPC_URL --fork-block-number 16884148 -vvv",
"goerli:deploy:zrxtoken": "source .env && forge script script/DeployToken.s.sol:Deploy --rpc-url $GOERLI_RPC_URL --broadcast --slow -vvvv",
"goerli:deploy:governance": "source .env && forge script script/DeployGovernance.s.sol:Deploy --rpc-url $GOERLI_RPC_URL --broadcast --slow -vvvv",
"mainnet:deploy:governance": "source .env && forge script script/DeployGovernance.s.sol:Deploy --rpc-url $MAINNET_RPC_URL --broadcast --slow -vvvv"
},
"repository": {
"type": "git",
"url": "https://github.com/0xProject/protocol.git"
},
"publishConfig": {
"access": "public"
},
"license": "Apache-2.0"
}

View File

@@ -0,0 +1,80 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
import "forge-std/console.sol";
import "forge-std/console2.sol";
import "@openzeppelin/token/ERC20/IERC20.sol";
import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import "../src/ZRXWrappedToken.sol";
import "../src/ZeroExVotes.sol";
import "../src/ZeroExTimelock.sol";
import "../src/ZeroExProtocolGovernor.sol";
import "../src/ZeroExTreasuryGovernor.sol";
contract Deploy is Script {
address internal constant ZRX_TOKEN = 0xE41d2489571d322189246DaFA5ebDe1F4699F498;
address internal constant TREASURY = 0x0bB1810061C2f5b2088054eE184E6C79e1591101;
address internal constant EXCHANGE = 0xDef1C0ded9bec7F1a1670819833240f027b25EfF;
address payable internal constant SECURITY_COUNCIL = payable(0x979BDb496e5f0A00af078b7a45F1E9E6bcff170F);
uint256 internal constant QUADRATIC_THRESHOLD = 1000000e18;
function setUp() public {}
function run() external {
address deployer = vm.envAddress("DEPLOYER");
vm.startBroadcast(deployer);
console2.log("Zrx Token", ZRX_TOKEN);
address wTokenPrediction = predict(deployer, vm.getNonce(deployer) + 2);
ZeroExVotes votesImpl = new ZeroExVotes(wTokenPrediction, QUADRATIC_THRESHOLD);
ERC1967Proxy votesProxy = new ERC1967Proxy(address(votesImpl), abi.encodeCall(votesImpl.initialize, ()));
ZRXWrappedToken wToken = new ZRXWrappedToken(IERC20(ZRX_TOKEN), ZeroExVotes(address(votesProxy)));
assert(address(wToken) == wTokenPrediction);
console2.log("Wrapped Token", address(wToken));
ZeroExVotes votes = ZeroExVotes(address(votesProxy));
console2.log("Votes", address(votes));
address[] memory proposers = new address[](0);
address[] memory executors = new address[](0);
ZeroExTimelock protocolTimelock = new ZeroExTimelock(3 days, proposers, executors, deployer);
console2.log("Protocol timelock", address(protocolTimelock));
ZeroExProtocolGovernor protocolGovernor = new ZeroExProtocolGovernor(
IVotes(address(votes)),
protocolTimelock,
SECURITY_COUNCIL
);
protocolTimelock.grantRole(protocolTimelock.PROPOSER_ROLE(), address(protocolGovernor));
protocolTimelock.grantRole(protocolTimelock.EXECUTOR_ROLE(), address(protocolGovernor));
protocolTimelock.grantRole(protocolTimelock.CANCELLER_ROLE(), address(protocolGovernor));
protocolTimelock.renounceRole(protocolTimelock.TIMELOCK_ADMIN_ROLE(), deployer);
console2.log("Protocol governor", address(protocolGovernor));
ZeroExTimelock treasuryTimelock = new ZeroExTimelock(2 days, proposers, executors, deployer);
console2.log("Treasury timelock", address(treasuryTimelock));
ZeroExTreasuryGovernor treasuryGovernor = new ZeroExTreasuryGovernor(
IVotes(address(votes)),
treasuryTimelock,
SECURITY_COUNCIL
);
treasuryTimelock.grantRole(treasuryTimelock.PROPOSER_ROLE(), address(treasuryGovernor));
treasuryTimelock.grantRole(treasuryTimelock.EXECUTOR_ROLE(), address(treasuryGovernor));
treasuryTimelock.grantRole(treasuryTimelock.CANCELLER_ROLE(), address(treasuryGovernor));
treasuryTimelock.renounceRole(treasuryTimelock.TIMELOCK_ADMIN_ROLE(), deployer);
console2.log("Treasury governor", address(treasuryGovernor));
console2.log(unicode"0x governance deployed successfully 🎉");
vm.stopBroadcast();
}
function predict(address deployer, uint256 nonce) internal pure returns (address) {
require(nonce > 0 && nonce < 128, "Invalid nonce");
return address(uint160(uint256(keccak256(abi.encodePacked(bytes2(0xd694), deployer, bytes1(uint8(nonce)))))));
}
}

View File

@@ -0,0 +1,22 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
import "forge-std/console2.sol";
contract Deploy is Script {
function setUp() public {}
function run() external {
vm.startBroadcast(vm.envAddress("DEPLOYER"));
bytes memory _bytecode = vm.getCode("./ZRXToken.json");
address zrxToken;
assembly {
zrxToken := create(0, add(_bytecode, 0x20), mload(_bytecode))
}
console2.log("Zrx Token", zrxToken);
console2.log(unicode"Zrx Token deployed successfully 🎉");
vm.stopBroadcast();
}
}

View File

@@ -0,0 +1,169 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
library CallWithGas {
/**
* @notice `staticcall` another contract forwarding a precomputed amount of
* gas.
* @dev contains protections against EIP-150-induced insufficient gas
* griefing
* @dev reverts iff the target is not a contract or we encounter an
* out-of-gas
* @return success true iff the call succeded and returned no more than
* `maxReturnBytes` of return data
* @return returnData the return data or revert reason of the call
* @param target the contract (reverts if non-contract) on which to make the
* `staticcall`
* @param data the calldata to pass
* @param callGas the gas to pass for the call. If the call requires more than
* the specified amount of gas and the caller didn't provide at
* least `callGas`, triggers an out-of-gas in the caller.
* @param maxReturnBytes Only this many bytes of return data are read back
* from the call. This prevents griefing the caller. If
* more bytes are returned or the revert reason is
* longer, success will be false and returnData will be
* `abi.encodeWithSignature("Error(string)", "CallWithGas: returnData too long")`
*/
function functionStaticCallWithGas(
address target,
bytes memory data,
uint256 callGas,
uint256 maxReturnBytes
) internal view returns (bool success, bytes memory returnData) {
assembly ("memory-safe") {
returnData := mload(0x40)
success := staticcall(callGas, target, add(data, 0x20), mload(data), add(returnData, 0x20), maxReturnBytes)
// As of the time this contract was written, `verbatim` doesn't work in
// inline assembly. Assignment of a value to a variable costs gas
// (although how much is unpredictable because it depends on the Yul/IR
// optimizer), as does the `GAS` opcode itself. Also solc tends to reorder
// the call to `gas()` with preparing the arguments for `div`. Therefore,
// the `gas()` below returns less than the actual amount of gas available
// for computation at the end of the call. That makes this check slightly
// too conservative. However, we do not correct for this because the
// correction would become outdated (possibly too permissive) if the
// opcodes are repriced.
// https://eips.ethereum.org/EIPS/eip-150
// https://ronan.eth.link/blog/ethereum-gas-dangers/
if iszero(or(success, or(returndatasize(), lt(div(callGas, 63), gas())))) {
// The call failed due to not enough gas left. We deliberately consume
// all remaining gas with `invalid` (instead of `revert`) to make this
// failure distinguishable to our caller.
invalid()
}
switch gt(returndatasize(), maxReturnBytes)
case 0 {
switch returndatasize()
case 0 {
returnData := 0x60
success := and(success, iszero(iszero(extcodesize(target))))
}
default {
mstore(returnData, returndatasize())
mstore(0x40, add(returnData, add(0x20, returndatasize())))
}
}
default {
// returnData = abi.encodeWithSignature("Error(string)", "CallWithGas: returnData too long")
success := 0
mstore(returnData, 0) // clear potentially dirty bits
mstore(add(returnData, 0x04), 0x6408c379a0) // length and selector
mstore(add(returnData, 0x24), 0x20)
mstore(add(returnData, 0x44), 0x20)
mstore(add(returnData, 0x64), "CallWithGas: returnData too long")
mstore(0x40, add(returnData, 0x84))
}
}
}
/// See `functionCallWithGasAndValue`
function functionCallWithGas(
address target,
bytes memory data,
uint256 callGas,
uint256 maxReturnBytes
) internal returns (bool success, bytes memory returnData) {
return functionCallWithGasAndValue(payable(target), data, callGas, 0, maxReturnBytes);
}
/**
* @notice `call` another contract forwarding a precomputed amount of gas.
* @notice Unlike `functionStaticCallWithGas`, a failure is not signaled if
* there is too much return data. Instead, it is simply truncated.
* @dev contains protections against EIP-150-induced insufficient gas griefing
* @dev reverts iff caller doesn't have enough native asset balance, the
* target is not a contract, or due to out-of-gas
* @return success true iff the call succeded
* @return returnData the return data or revert reason of the call
* @param target the contract (reverts if non-contract) on which to make the
* `call`
* @param data the calldata to pass
* @param callGas the gas to pass for the call. If the call requires more than
* the specified amount of gas and the caller didn't provide at
* least `callGas`, triggers an out-of-gas in the caller.
* @param value the amount of the native asset in wei to pass to the callee
* with the call
* @param maxReturnBytes Only this many bytes of return data/revert reason are
* read back from the call. This prevents griefing the
* caller. If more bytes are returned or the revert
* reason is longer, returnData will be truncated
*/
function functionCallWithGasAndValue(
address payable target,
bytes memory data,
uint256 callGas,
uint256 value,
uint256 maxReturnBytes
) internal returns (bool success, bytes memory returnData) {
if (value > 0 && (address(this).balance < value || target.code.length == 0)) {
return (success, returnData);
}
assembly ("memory-safe") {
returnData := mload(0x40)
success := call(callGas, target, value, add(data, 0x20), mload(data), add(returnData, 0x20), maxReturnBytes)
// As of the time this contract was written, `verbatim` doesn't work in
// inline assembly. Assignment of a value to a variable costs gas
// (although how much is unpredictable because it depends on the Yul/IR
// optimizer), as does the `GAS` opcode itself. Also solc tends to reorder
// the call to `gas()` with preparing the arguments for `div`. Therefore,
// the `gas()` below returns less than the actual amount of gas available
// for computation at the end of the call. That makes this check slightly
// too conservative. However, we do not correct for this because the
// correction would become outdated (possibly too permissive) if the
// opcodes are repriced.
// https://eips.ethereum.org/EIPS/eip-150
// https://ronan.eth.link/blog/ethereum-gas-dangers/
if iszero(or(success, or(returndatasize(), lt(div(callGas, 63), gas())))) {
// The call failed due to not enough gas left. We deliberately consume
// all remaining gas with `invalid` (instead of `revert`) to make this
// failure distinguishable to our caller.
invalid()
}
switch gt(returndatasize(), maxReturnBytes)
case 0 {
switch returndatasize()
case 0 {
returnData := 0x60
if iszero(value) {
success := and(success, iszero(iszero(extcodesize(target))))
}
}
default {
mstore(returnData, returndatasize())
mstore(0x40, add(returnData, add(0x20, returndatasize())))
}
}
default {
mstore(returnData, maxReturnBytes)
mstore(0x40, add(returnData, add(0x20, maxReturnBytes)))
}
}
}
}

View File

@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "./SecurityCouncil.sol";
import "@openzeppelin/governance/IGovernor.sol";
import "@openzeppelin/governance/extensions/IGovernorTimelock.sol";
abstract contract IZeroExGovernor is SecurityCouncil, IGovernor, IGovernorTimelock {
function token() public virtual returns (address);
function proposalThreshold() public view virtual returns (uint256);
function setVotingDelay(uint256 newVotingDelay) public virtual;
function setVotingPeriod(uint256 newVotingPeriod) public virtual;
function setProposalThreshold(uint256 newProposalThreshold) public virtual;
function proposalVotes(
uint256 proposalId
) public view virtual returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes);
}

View File

@@ -0,0 +1,132 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
interface IZeroExVotes {
struct Checkpoint {
uint32 fromBlock;
uint96 votes;
uint96 quadraticVotes;
}
/**
* @dev Emitted when a token transfer or delegate change,
* results in changes to a delegate's quadratic number of votes.
*/
event DelegateQuadraticVotesChanged(
address indexed delegate,
uint256 previousQuadraticBalance,
uint256 newQuadraticBalance
);
/**
* @dev Emitted when a token transfer or delegate change, results in changes to a delegate's number of votes.
*/
event DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance);
/**
* @dev Emitted when the total supply of the token is changed due to minting and burning which results in
* the total supply checkpoint being writtenor updated.
*/
event TotalSupplyChanged(uint256 totalSupplyVotes, uint256 totalSupplyQuadraticVotes);
/**
* @dev Get the `pos`-th checkpoint for `account`.
*/
function checkpoints(address account, uint32 pos) external view returns (Checkpoint memory);
/**
* @dev Get number of checkpoints for `account`.
*/
function numCheckpoints(address account) external view returns (uint32);
/**
* @dev Gets the current votes balance for `account`
*/
function getVotes(address account) external view returns (uint256);
/**
* @dev Gets the current quadratic votes balance for `account`
*/
function getQuadraticVotes(address account) external view returns (uint256);
/**
* @dev Retrieve the number of votes for `account` at the end of `blockNumber`.
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastVotes(address account, uint256 blockNumber) external view returns (uint256);
/**
* @dev Retrieve the number of quadratic votes for `account` at the end of `blockNumber`.
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastQuadraticVotes(address account, uint256 blockNumber) external view returns (uint256);
/**
* @dev Retrieve the `totalSupply` at the end of `blockNumber`. Note, this value is the sum of all balances.
* It is but NOT the sum of all the delegated votes!
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastTotalSupply(uint256 blockNumber) external view returns (uint256);
/**
* @dev Retrieve the sqrt of `totalSupply` at the end of `blockNumber`. Note, this value is the square root of the
* sum of all balances.
* It is but NOT the sum of all the sqrt of the delegated votes!
*
* Requirements:
*
* - `blockNumber` must have been already mined
*/
function getPastQuadraticTotalSupply(uint256 blockNumber) external view returns (uint256);
/**
* @dev Moves the voting power corresponding to `amount` number of tokens from `src` to `dst`.
* Note that if the delegator isn't delegating to anyone before the function call `src` = address(0)
* @param src the delegatee we are moving voting power away from
* @param dst the delegatee we are moving voting power to
* @param srcBalance balance of the delegator whose delegatee is `src`. This is value _after_ the transfer.
* @param dstBalance balance of the delegator whose delegatee is `dst`. This is value _after_ the transfer.
* @param srcBalanceLastUpdated block number when balance of `src` was last updated.
* @param dstBalanceLastUpdated block number when balance of `dst` was last updated.
* @param amount The amount of tokens transferred from the source delegate to destination delegate.
*/
function moveVotingPower(
address src,
address dst,
uint256 srcBalance,
uint256 dstBalance,
uint96 srcBalanceLastUpdated,
uint96 dstBalanceLastUpdated,
uint256 amount
) external returns (bool);
function writeCheckpointTotalSupplyMint(uint256 accountBalance, uint256 amount) external returns (bool);
function writeCheckpointTotalSupplyBurn(uint256 accountBalance, uint256 amount) external returns (bool);
}

View File

@@ -0,0 +1,85 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
abstract contract SecurityCouncil {
address public securityCouncil;
event SecurityCouncilAssigned(address securityCouncil);
event SecurityCouncilEjected();
modifier onlySecurityCouncil() {
_checkSenderIsSecurityCouncil();
_;
}
/**
* @dev Checks that either a security council is assigned or the payloads array is a council assignment call.
*/
modifier securityCouncilAssigned(bytes[] memory payloads) {
if (securityCouncil == address(0) && !_payloadIsAssignSecurityCouncil(payloads)) {
revert("SecurityCouncil: security council not assigned and this is not an assignment call");
}
_;
}
/**
* @dev Assigns new security council.
*/
function assignSecurityCouncil(address _securityCouncil) public virtual {
securityCouncil = _securityCouncil;
emit SecurityCouncilAssigned(securityCouncil);
}
/**
* @dev Ejects the current security council via setting the security council address to 0.
* Security council is ejected after they either cancel a proposal or execute a protocol rollback.
*/
function ejectSecurityCouncil() internal {
securityCouncil = address(0);
emit SecurityCouncilEjected();
}
/**
* @dev Cancel existing proposal with the submitted `targets`, `values`, `calldatas` and `descriptionHash`.
*/
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual;
function _payloadIsAssignSecurityCouncil(bytes[] memory payloads) private pure returns (bool) {
require(payloads.length == 1, "SecurityCouncil: more than 1 transaction in proposal");
bytes memory payload = payloads[0];
// Check this is as assignSecurityCouncil(address) transaction
// function signature for assignSecurityCouncil(address)
// = bytes4(keccak256("assignSecurityCouncil(address)"))
// = 0x2761c3cd
if (bytes4(payload) == bytes4(0x2761c3cd)) return true;
else return false;
}
function _checkSenderIsSecurityCouncil() private view {
require(msg.sender == securityCouncil, "SecurityCouncil: only security council allowed");
}
}

View File

@@ -0,0 +1,164 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "@openzeppelin/token/ERC20/ERC20.sol";
import "@openzeppelin/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/token/ERC20/extensions/ERC20Wrapper.sol";
import "@openzeppelin/governance/utils/IVotes.sol";
import "@openzeppelin/utils/math/SafeCast.sol";
import "./IZeroExVotes.sol";
import "./CallWithGas.sol";
contract ZRXWrappedToken is ERC20, ERC20Permit, ERC20Wrapper {
using CallWithGas for address;
struct DelegateInfo {
address delegate;
uint96 balanceLastUpdated;
}
constructor(
IERC20 wrappedToken,
IZeroExVotes _zeroExVotes
) ERC20("Wrapped ZRX", "wZRX") ERC20Permit("Wrapped ZRX") ERC20Wrapper(wrappedToken) {
zeroExVotes = _zeroExVotes;
}
IZeroExVotes public immutable zeroExVotes;
mapping(address => DelegateInfo) private _delegates;
bytes32 private constant _DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
/**
* @dev Emitted when an account changes their delegate.
*/
event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);
// The functions below are the required overrides from the base contracts
function decimals() public pure override(ERC20, ERC20Wrapper) returns (uint8) {
return 18;
}
function _afterTokenTransfer(address from, address to, uint256 amount) internal override(ERC20) {
super._afterTokenTransfer(from, to, amount);
DelegateInfo memory fromDelegate = delegateInfo(from);
DelegateInfo memory toDelegate = delegateInfo(to);
uint256 fromBalance = fromDelegate.delegate == address(0) ? 0 : balanceOf(from) + amount;
uint256 toBalance = toDelegate.delegate == address(0) ? 0 : balanceOf(to) - amount;
if (fromDelegate.delegate != address(0)) _delegates[from].balanceLastUpdated = SafeCast.toUint96(block.number);
if (toDelegate.delegate != address(0)) _delegates[to].balanceLastUpdated = SafeCast.toUint96(block.number);
zeroExVotes.moveVotingPower(
fromDelegate.delegate,
toDelegate.delegate,
fromBalance,
toBalance,
fromDelegate.balanceLastUpdated,
toDelegate.balanceLastUpdated,
amount
);
}
function _mint(address account, uint256 amount) internal override(ERC20) {
super._mint(account, amount);
zeroExVotes.writeCheckpointTotalSupplyMint(balanceOf(account) - amount, amount);
}
function _burn(address account, uint256 amount) internal override(ERC20) {
super._burn(account, amount);
address(zeroExVotes).functionCallWithGas(
abi.encodeCall(zeroExVotes.writeCheckpointTotalSupplyBurn, (balanceOf(account) + amount, amount)),
500_000,
32
);
}
/**
* @dev Get the address `account` is currently delegating to.
*/
function delegates(address account) public view returns (address) {
return _delegates[account].delegate;
}
/**
* @dev Get the last block number when `account`'s balance changed.
*/
function delegatorBalanceLastUpdated(address account) public view returns (uint96) {
return _delegates[account].balanceLastUpdated;
}
function delegateInfo(address account) public view returns (DelegateInfo memory) {
return _delegates[account];
}
/**
* @dev Delegate votes from the sender to `delegatee`.
*/
function delegate(address delegatee) public {
_delegate(_msgSender(), delegatee);
}
/**
* @dev Delegates votes from signer to `delegatee`
*/
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public {
require(block.timestamp <= expiry, "ERC20Votes: signature expired");
address signer = ECDSA.recover(
_hashTypedDataV4(keccak256(abi.encode(_DELEGATION_TYPEHASH, delegatee, nonce, expiry))),
v,
r,
s
);
require(nonce == _useNonce(signer), "ERC20Votes: invalid nonce");
_delegate(signer, delegatee);
}
/**
* @dev Change delegation for `delegator` to `delegatee`.
*
* Emits events {DelegateChanged} and {IZeroExVotes-DelegateVotesChanged}.
*/
function _delegate(address delegator, address delegatee) internal virtual {
DelegateInfo memory delegateInfo = delegateInfo(delegator);
uint256 delegatorBalance = balanceOf(delegator);
_delegates[delegator] = DelegateInfo(delegatee, SafeCast.toUint96(block.timestamp));
emit DelegateChanged(delegator, delegateInfo.delegate, delegatee);
zeroExVotes.moveVotingPower(
delegateInfo.delegate,
delegatee,
delegatorBalance,
0,
delegateInfo.balanceLastUpdated,
0,
delegatorBalance
);
}
}

View File

@@ -0,0 +1,145 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "./SecurityCouncil.sol";
import "./ZeroExTimelock.sol";
import "@openzeppelin/governance/Governor.sol";
import "@openzeppelin/governance/extensions/GovernorSettings.sol";
import "@openzeppelin/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/governance/extensions/GovernorTimelockControl.sol";
contract ZeroExProtocolGovernor is
SecurityCouncil,
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorTimelockControl
{
constructor(
IVotes _votes,
ZeroExTimelock _timelock,
address _securityCouncil
)
Governor("ZeroExProtocolGovernor")
GovernorSettings(14400 /* 2 days */, 50400 /* 7 days */, 1000000e18)
GovernorVotes(_votes)
GovernorTimelockControl(TimelockController(payable(_timelock)))
{
securityCouncil = _securityCouncil;
}
function quorum(uint256 blockNumber) public pure override returns (uint256) {
return 10000000e18;
}
// The following functions are overrides required by Solidity.
function votingDelay() public view override(IGovernor, GovernorSettings) returns (uint256) {
return super.votingDelay();
}
function votingPeriod() public view override(IGovernor, GovernorSettings) returns (uint256) {
return super.votingPeriod();
}
function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
return super.state(proposalId);
}
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public override(Governor, IGovernor) securityCouncilAssigned(calldatas) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}
function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
return super.proposalThreshold();
}
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public override onlySecurityCouncil {
_cancel(targets, values, calldatas, descriptionHash);
}
// Like the GovernorTimelockControl.queue function but without the proposal checks,
// (as there's effectively no proposal).
// And also using a delay of 0 as opposed to the minimum delay of the timelock
function executeRollback(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public onlySecurityCouncil {
// Execute the batch of rollbacks via the timelock controller
ZeroExTimelock timelockController = ZeroExTimelock(payable(timelock()));
timelockController.executeRollbackBatch(targets, values, calldatas, 0, descriptionHash);
}
function assignSecurityCouncil(address _securityCouncil) public override onlyGovernance {
super.assignSecurityCouncil(_securityCouncil);
}
function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public override securityCouncilAssigned(calldatas) returns (uint256) {
return super.queue(targets, values, calldatas, descriptionHash);
}
function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) returns (uint256) {
return super._cancel(targets, values, calldatas, descriptionHash);
}
function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
return super._executor();
}
function supportsInterface(
bytes4 interfaceId
) public view override(Governor, GovernorTimelockControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
}

View File

@@ -0,0 +1,70 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "@openzeppelin/governance/TimelockController.sol";
contract ZeroExTimelock is TimelockController {
// minDelay is how long you have to wait before executing
// proposers is the list of addresses that can propose
// executors is the list of addresses that can execute
constructor(
uint256 minDelay,
address[] memory proposers,
address[] memory executors,
address admin
) TimelockController(minDelay, proposers, executors, admin) {}
/**
* @dev Execute a batch of rollback transactions. Similar to TimelockController.executeBatch function but without
* the timelock checks.
* Emits one {CallExecuted} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/
function executeRollbackBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata payloads,
bytes32 predecessor,
bytes32 salt
) public payable onlyRoleOrOpenRole(EXECUTOR_ROLE) {
require(targets.length > 0, "ZeroExTimelock: empty targets");
require(targets.length == values.length, "ZeroExTimelock: length mismatch");
require(targets.length == payloads.length, "ZeroExTimelock: length mismatch");
bytes32 id = hashOperationBatch(targets, values, payloads, predecessor, salt);
for (uint256 i = 0; i < targets.length; ++i) {
address target = targets[i];
uint256 value = values[i];
bytes calldata payload = payloads[i];
// Check this is a rollback transaction
// function signature for rollback(bytes4,address)
// = bytes4(keccak256("rollback(bytes4,address)"))
// = 0x9db64a40
require(bytes4(payload) == bytes4(0x9db64a40), "ZeroExTimelock: not rollback");
_execute(target, value, payload);
emit CallExecuted(id, i, target, value, payload);
}
}
}

View File

@@ -0,0 +1,154 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "@openzeppelin/governance/Governor.sol";
import "@openzeppelin/governance/extensions/GovernorSettings.sol";
import "@openzeppelin/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/governance/extensions/GovernorVotesQuorumFraction.sol";
import "@openzeppelin/governance/extensions/GovernorTimelockControl.sol";
import "./IZeroExVotes.sol";
import "./SecurityCouncil.sol";
contract ZeroExTreasuryGovernor is
SecurityCouncil,
Governor,
GovernorSettings,
GovernorCountingSimple,
GovernorVotes,
GovernorVotesQuorumFraction,
GovernorTimelockControl
{
constructor(
IVotes votes,
TimelockController _timelock,
address _securityCouncil
)
Governor("ZeroExTreasuryGovernor")
GovernorSettings(14400 /* 2 days */, 50400 /* 7 days */, 250000e18)
GovernorVotes(votes)
GovernorVotesQuorumFraction(10)
GovernorTimelockControl(_timelock)
{
securityCouncil = _securityCouncil;
}
/**
* @dev Returns the "quadratic" quorum for a block number, in terms of number of votes:
* `quadratic total supply * numerator / denominator`
*/
function quorum(
uint256 blockNumber
) public view override(IGovernor, GovernorVotesQuorumFraction) returns (uint256) {
IZeroExVotes votes = IZeroExVotes(address(token));
return (votes.getPastQuadraticTotalSupply(blockNumber) * quorumNumerator(blockNumber)) / quorumDenominator();
}
// The following functions are overrides required by Solidity.
function votingDelay() public view override(IGovernor, GovernorSettings) returns (uint256) {
return super.votingDelay();
}
function votingPeriod() public view override(IGovernor, GovernorSettings) returns (uint256) {
return super.votingPeriod();
}
function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256) {
return super.proposalThreshold();
}
/**
* Overwritten GovernorVotes implementation
* Read the quadratic voting weight from the token's built in snapshot mechanism (see {Governor-_getVotes}).
*/
function _getVotes(
address account,
uint256 blockNumber,
bytes memory /*params*/
) internal view virtual override(Governor, GovernorVotes) returns (uint256) {
return IZeroExVotes(address(token)).getPastQuadraticVotes(account, blockNumber);
}
function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState) {
return super.state(proposalId);
}
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public override(Governor, IGovernor) securityCouncilAssigned(calldatas) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public override onlySecurityCouncil {
_cancel(targets, values, calldatas, descriptionHash);
}
function assignSecurityCouncil(address _securityCouncil) public override onlyGovernance {
super.assignSecurityCouncil(_securityCouncil);
}
function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public override securityCouncilAssigned(calldatas) returns (uint256) {
return super.queue(targets, values, calldatas, descriptionHash);
}
function _execute(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) {
super._execute(proposalId, targets, values, calldatas, descriptionHash);
}
function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl) returns (uint256) {
return super._cancel(targets, values, calldatas, descriptionHash);
}
function _executor() internal view override(Governor, GovernorTimelockControl) returns (address) {
return super._executor();
}
function supportsInterface(
bytes4 interfaceId
) public view override(Governor, GovernorTimelockControl) returns (bool) {
return super.supportsInterface(interfaceId);
}
}

View File

@@ -0,0 +1,336 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "@openzeppelin/utils/math/SafeCast.sol";
import "@openzeppelin/utils/math/Math.sol";
import "@openzeppelin/token/ERC20/ERC20.sol";
import "@openzeppelin/governance/utils/IVotes.sol";
import "@openzeppelin-contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin-contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import "./IZeroExVotes.sol";
contract ZeroExVotes is IZeroExVotes, Initializable, OwnableUpgradeable, UUPSUpgradeable {
address public immutable token;
uint256 public immutable quadraticThreshold;
mapping(address => Checkpoint[]) internal _checkpoints;
Checkpoint[] private _totalSupplyCheckpoints;
constructor(address _token, uint256 _quadraticThreshold) {
require(_token != address(0), "ZeroExVotes: token cannot be 0");
token = _token;
quadraticThreshold = _quadraticThreshold;
_disableInitializers();
}
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
modifier onlyToken() {
_checkSenderIsToken();
_;
}
function initialize() public virtual onlyProxy initializer {
__Ownable_init();
__UUPSUpgradeable_init();
}
/**
* @inheritdoc IZeroExVotes
*/
function checkpoints(address account, uint32 pos) public view returns (Checkpoint memory) {
return _checkpoints[account][pos];
}
/**
* @inheritdoc IZeroExVotes
*/
function numCheckpoints(address account) public view returns (uint32) {
return SafeCast.toUint32(_checkpoints[account].length);
}
/**
* @inheritdoc IZeroExVotes
*/
function getVotes(address account) public view returns (uint256) {
unchecked {
uint256 pos = _checkpoints[account].length;
return pos == 0 ? 0 : _unsafeAccess(_checkpoints[account], pos - 1).votes;
}
}
/**
* @inheritdoc IZeroExVotes
*/
function getQuadraticVotes(address account) public view returns (uint256) {
unchecked {
uint256 pos = _checkpoints[account].length;
return pos == 0 ? 0 : _unsafeAccess(_checkpoints[account], pos - 1).quadraticVotes;
}
}
/**
* @inheritdoc IZeroExVotes
*/
function getPastVotes(address account, uint256 blockNumber) public view returns (uint256) {
require(blockNumber < block.number, "ZeroExVotes: block not yet mined");
Checkpoint memory checkpoint = _checkpointsLookup(_checkpoints[account], blockNumber);
return checkpoint.votes;
}
/**
* @inheritdoc IZeroExVotes
*/
function getPastQuadraticVotes(address account, uint256 blockNumber) public view returns (uint256) {
require(blockNumber < block.number, "ZeroExVotes: block not yet mined");
Checkpoint memory checkpoint = _checkpointsLookup(_checkpoints[account], blockNumber);
return checkpoint.quadraticVotes;
}
/**
* @inheritdoc IZeroExVotes
*/
function getPastTotalSupply(uint256 blockNumber) public view returns (uint256) {
require(blockNumber < block.number, "ZeroExVotes: block not yet mined");
// Note that due to the disabled updates of `_totalSupplyCheckpoints` in `writeCheckpointTotalSupply` function
// this always returns 0.
Checkpoint memory checkpoint = _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
return checkpoint.votes;
}
/**
* @inheritdoc IZeroExVotes
*/
function getPastQuadraticTotalSupply(uint256 blockNumber) public view returns (uint256) {
require(blockNumber < block.number, "ZeroExVotes: block not yet mined");
// Note that due to the disabled updates of `_totalSupplyCheckpoints` in `writeCheckpointTotalSupply` function
// this always returns 0.
Checkpoint memory checkpoint = _checkpointsLookup(_totalSupplyCheckpoints, blockNumber);
return checkpoint.quadraticVotes;
}
/**
* @inheritdoc IZeroExVotes
*/
function moveVotingPower(
address src,
address dst,
uint256 srcBalance,
uint256 dstBalance,
uint96 srcBalanceLastUpdated,
uint96 dstBalanceLastUpdated,
uint256 amount
) public virtual onlyToken returns (bool) {
if (src != dst) {
if (src != address(0)) {
(
uint256 oldWeight,
uint256 newWeight,
uint256 oldQuadraticWeight,
uint256 newQuadraticWeight
) = _writeCheckpoint(_checkpoints[src], _subtract, srcBalance, srcBalanceLastUpdated, amount);
emit DelegateVotesChanged(src, oldWeight, newWeight);
emit DelegateQuadraticVotesChanged(src, oldQuadraticWeight, newQuadraticWeight);
}
if (dst != address(0)) {
(
uint256 oldWeight,
uint256 newWeight,
uint256 oldQuadraticWeight,
uint256 newQuadraticWeight
) = _writeCheckpoint(_checkpoints[dst], _add, dstBalance, dstBalanceLastUpdated, amount);
emit DelegateVotesChanged(dst, oldWeight, newWeight);
emit DelegateQuadraticVotesChanged(dst, oldQuadraticWeight, newQuadraticWeight);
}
}
return true;
}
/**
* @inheritdoc IZeroExVotes
*/
function writeCheckpointTotalSupplyMint(
uint256 accountBalance,
uint256 amount
) public virtual onlyToken returns (bool) {
(, uint256 newWeight, , uint256 newQuadraticWeight) = _writeCheckpoint(
_totalSupplyCheckpoints,
_add,
accountBalance,
0,
amount
);
emit TotalSupplyChanged(newWeight, newQuadraticWeight);
return true;
}
/**
* @inheritdoc IZeroExVotes
*/
function writeCheckpointTotalSupplyBurn(
uint256 accountBalance,
uint256 amount
) public virtual onlyToken returns (bool) {
(, uint256 newWeight, , uint256 newQuadraticWeight) = _writeCheckpoint(
_totalSupplyCheckpoints,
_subtract,
accountBalance,
0,
amount
);
emit TotalSupplyChanged(newWeight, newQuadraticWeight);
return true;
}
/**
* @dev Lookup a value in a list of (sorted) checkpoints.
* Implementation as in openzeppelin/token/ERC20/extensions/ERC20Votes.sol except here we return the entire
* checkpoint rather than part of it
*/
function _checkpointsLookup(
Checkpoint[] storage ckpts,
uint256 blockNumber
) internal view returns (Checkpoint memory checkpoint) {
// We run a binary search to look for the earliest checkpoint taken after `blockNumber`.
//
// Initially we check if the block is recent to narrow the search range.
// During the loop, the index of the wanted checkpoint remains in the range [low-1, high).
// With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the
// invariant.
// - If the middle checkpoint is after `blockNumber`, we look in [low, mid)
// - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)
// Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not
// out of bounds (in which case we're looking too far in the past and the result is 0).
// Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is
// past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out
// the same.
uint256 length = ckpts.length;
uint256 low = 0;
uint256 high = length;
if (length > 5) {
uint256 mid = length - Math.sqrt(length);
if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {
high = mid;
} else {
low = mid + 1;
}
}
while (low < high) {
uint256 mid = Math.average(low, high);
if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {
high = mid;
} else {
low = mid + 1;
}
}
// Leaving here for posterity this is the original OZ implementation which we've replaced
// return high == 0 ? 0 : _unsafeAccess(ckpts, high - 1).votes;
if (high != 0) checkpoint = _unsafeAccess(ckpts, high - 1);
}
function _writeCheckpoint(
Checkpoint[] storage ckpts,
function(uint256, uint256) view returns (uint256) op,
uint256 userBalance,
uint96 balanceLastUpdated,
uint256 delta
)
internal
virtual
returns (uint256 oldWeight, uint256 newWeight, uint256 oldQuadraticWeight, uint256 newQuadraticWeight)
{
uint256 pos = ckpts.length;
Checkpoint memory oldCkpt = pos == 0 ? Checkpoint(0, 0, 0) : _unsafeAccess(ckpts, pos - 1);
oldWeight = oldCkpt.votes;
newWeight = op(oldWeight, delta);
oldQuadraticWeight = oldCkpt.quadraticVotes;
// Remove the entire sqrt userBalance from quadratic voting power.
// Note that `userBalance` is value _after_ transfer.
if (pos > 0) {
uint256 oldQuadraticVotingPower = userBalance <= quadraticThreshold
? userBalance
: quadraticThreshold + Math.sqrt((userBalance - quadraticThreshold) * 1e18);
oldCkpt.quadraticVotes -= SafeCast.toUint96(oldQuadraticVotingPower);
}
// if wallet > threshold, calculate quadratic power over the treshold only, below threshold is linear
uint256 newBalance = op(userBalance, delta);
uint256 newQuadraticBalance = newBalance <= quadraticThreshold
? newBalance
: quadraticThreshold + Math.sqrt((newBalance - quadraticThreshold) * 1e18);
newQuadraticWeight = oldCkpt.quadraticVotes + newQuadraticBalance;
if (pos > 0 && oldCkpt.fromBlock == block.number) {
Checkpoint storage chpt = _unsafeAccess(ckpts, pos - 1);
chpt.votes = SafeCast.toUint96(newWeight);
chpt.quadraticVotes = SafeCast.toUint96(newQuadraticWeight);
} else {
ckpts.push(
Checkpoint({
fromBlock: SafeCast.toUint32(block.number),
votes: SafeCast.toUint96(newWeight),
quadraticVotes: SafeCast.toUint96(newQuadraticWeight)
})
);
}
}
function _add(uint256 a, uint256 b) private pure returns (uint256) {
return a + b;
}
function _subtract(uint256 a, uint256 b) private pure returns (uint256) {
return a - b;
}
/**
* @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.
* Implementation from openzeppelin/token/ERC20/extensions/ERC20Votes.sol
* https://github.com/ethereum/solidity/issues/9117
*/
function _unsafeAccess(Checkpoint[] storage ckpts, uint256 pos) internal pure returns (Checkpoint storage result) {
assembly ("memory-safe") {
mstore(0, ckpts.slot)
result.slot := add(keccak256(0, 0x20), pos)
}
}
function _checkSenderIsToken() private {
require(msg.sender == token, "ZeroExVotes: only token allowed");
}
}

View File

@@ -0,0 +1,167 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "forge-std/console.sol";
import "@openzeppelin/token/ERC20/ERC20.sol";
import "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import "./mocks/ZRXMock.sol";
import "../src/ZRXWrappedToken.sol";
import "../src/ZeroExVotes.sol";
import "../src/ZeroExTimelock.sol";
import "../src/ZeroExProtocolGovernor.sol";
import "../src/ZeroExTreasuryGovernor.sol";
contract BaseTest is Test {
address payable internal account1 = payable(vm.addr(1));
address payable internal account2 = payable(vm.addr(2));
address payable internal account3 = payable(vm.addr(3));
address payable internal account4 = payable(vm.addr(4));
address payable internal securityCouncil = payable(vm.addr(5));
uint256 internal quadraticThreshold = 1000000e18;
bytes32 internal constant DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
constructor() {
vm.deal(account1, 1e20);
vm.deal(account2, 1e20);
vm.deal(account3, 1e20);
vm.deal(account4, 1e20);
vm.deal(securityCouncil, 1e20);
}
function setupGovernance(
IERC20 zrxToken
) internal returns (ZRXWrappedToken, ZeroExVotes, ZeroExTimelock, ZeroExTimelock, address, address) {
(ZRXWrappedToken token, ZeroExVotes votes) = setupZRXWrappedToken(zrxToken);
vm.startPrank(account1);
address[] memory proposers = new address[](0);
address[] memory executors = new address[](0);
ZeroExTimelock protocolTimelock = new ZeroExTimelock(3 days, proposers, executors, account1);
ZeroExProtocolGovernor protocolGovernor = new ZeroExProtocolGovernor(
IVotes(address(votes)),
protocolTimelock,
securityCouncil
);
protocolTimelock.grantRole(protocolTimelock.PROPOSER_ROLE(), address(protocolGovernor));
protocolTimelock.grantRole(protocolTimelock.EXECUTOR_ROLE(), address(protocolGovernor));
protocolTimelock.grantRole(protocolTimelock.CANCELLER_ROLE(), address(protocolGovernor));
ZeroExTimelock treasuryTimelock = new ZeroExTimelock(2 days, proposers, executors, account1);
ZeroExTreasuryGovernor treasuryGovernor = new ZeroExTreasuryGovernor(
IVotes(address(votes)),
treasuryTimelock,
securityCouncil
);
treasuryTimelock.grantRole(treasuryTimelock.PROPOSER_ROLE(), address(treasuryGovernor));
treasuryTimelock.grantRole(treasuryTimelock.EXECUTOR_ROLE(), address(treasuryGovernor));
treasuryTimelock.grantRole(treasuryTimelock.CANCELLER_ROLE(), address(treasuryGovernor));
vm.stopPrank();
return (token, votes, protocolTimelock, treasuryTimelock, address(protocolGovernor), address(treasuryGovernor));
}
function setupZRXWrappedToken(IERC20 zrxToken) internal returns (ZRXWrappedToken, ZeroExVotes) {
vm.startPrank(account1);
address wTokenPrediction = predictAddress(account1, vm.getNonce(account1) + 2);
ZeroExVotes votesImpl = new ZeroExVotes(wTokenPrediction, quadraticThreshold);
ERC1967Proxy votesProxy = new ERC1967Proxy(address(votesImpl), abi.encodeCall(votesImpl.initialize, ()));
ZRXWrappedToken wToken = new ZRXWrappedToken(zrxToken, ZeroExVotes(address(votesProxy)));
vm.stopPrank();
assert(address(wToken) == wTokenPrediction);
return (wToken, ZeroExVotes(address(votesProxy)));
}
function mockZRXToken() internal returns (IERC20 zrxToken) {
vm.startPrank(account1);
bytes memory _bytecode = vm.getCode("./ZRXToken.json");
assembly {
zrxToken := create(0, add(_bytecode, 0x20), mload(_bytecode))
}
vm.stopPrank();
}
// Sourced from https://github.com/grappafinance/core/blob/master/src/test/utils/Utilities.sol
function predictAddress(address _origin, uint256 _nonce) public pure returns (address) {
if (_nonce == 0x00) {
return
address(
uint160(uint256(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), _origin, bytes1(0x80)))))
);
}
if (_nonce <= 0x7f) {
return
address(
uint160(uint256(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), _origin, uint8(_nonce)))))
);
}
if (_nonce <= 0xff) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(bytes1(0xd7), bytes1(0x94), _origin, bytes1(0x81), uint8(_nonce))
)
)
)
);
}
if (_nonce <= 0xffff) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(bytes1(0xd8), bytes1(0x94), _origin, bytes1(0x82), uint16(_nonce))
)
)
)
);
}
if (_nonce <= 0xffffff) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(bytes1(0xd9), bytes1(0x94), _origin, bytes1(0x83), uint24(_nonce))
)
)
)
);
}
return
address(
uint160(
uint256(
keccak256(abi.encodePacked(bytes1(0xda), bytes1(0x94), _origin, bytes1(0x84), uint32(_nonce)))
)
)
);
}
}

View File

@@ -0,0 +1,454 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "@openzeppelin/token/ERC20/IERC20.sol";
import "../mocks/IZeroExMock.sol";
import "../mocks/IZrxTreasuryMock.sol";
import "../mocks/IStakingMock.sol";
import "../mocks/IZrxVaultMock.sol";
import "../BaseTest.t.sol";
import "../../src/ZRXWrappedToken.sol";
import "../../src/ZeroExVotes.sol";
import "../../src/ZeroExTimelock.sol";
import "../../src/ZeroExProtocolGovernor.sol";
import "../../src/ZeroExTreasuryGovernor.sol";
contract GovernanceE2ETest is BaseTest {
uint256 internal mainnetFork;
string internal MAINNET_RPC_URL = vm.envString("MAINNET_RPC_URL");
struct DelegatorPool {
address delegator;
bytes32 pool;
}
address internal constant ZRX_TOKEN = 0xE41d2489571d322189246DaFA5ebDe1F4699F498;
address internal constant MATIC_TOKEN = 0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0;
address internal constant WCELO_TOKEN = 0xE452E6Ea2dDeB012e20dB73bf5d3863A3Ac8d77a;
address internal constant WYV_TOKEN = 0x056017c55aE7AE32d12AeF7C679dF83A85ca75Ff;
address internal constant EXCHANGE_PROXY = 0xDef1C0ded9bec7F1a1670819833240f027b25EfF;
address internal constant EXCHANGE_GOVERNOR = 0x618F9C67CE7Bf1a50afa1E7e0238422601b0ff6e;
address internal constant TREASURY = 0x0bB1810061C2f5b2088054eE184E6C79e1591101;
address internal constant STAKING = 0xa26e80e7Dea86279c6d778D702Cc413E6CFfA777; // Holds ~$262K in WETH for rewards
address internal constant ZRX_VAULT = 0xBa7f8b5fB1b19c1211c5d49550fcD149177A5Eaf; // Holds ~$10m in staked ZRX
address internal constant STAKING_AND_VAULT_OWNER = 0x7D3455421BbC5Ed534a83c88FD80387dc8271392;
address internal staker1 = 0x885c327cAD2aebb969dfaAb4c928B73CA17e3887;
address internal staker2 = 0x03c823e96F6964076C118395F08a2D7edF0f8a8C;
address[] internal topStakers = [
0x5775afA796818ADA27b09FaF5c90d101f04eF600,
0xE1bdcd3B70e077D2d66ADcbe78be3941F0BF380B,
0xcCa71809E8870AFEB72c4720d0fe50d5C3230e05,
0x828FD91d3e3a9FFa6305e78B9aE2Cfbc5B5D9f6B,
0x4A36C3DA5d367B148d17265e7d7feafcf8fb4a21,
0xEeff6fd32DeaFe1a9d3258A51c7F952F9FF0B2Ce,
0x1D0738b927dFCBFBD59A9F0944BbD1860d3B9248,
0x0C073E7248C1b548a08b27dD3af5D0f39c774280,
0xA178FF321335BB777A7E21A56376592F69556b9c,
0xD06CfBb59d2e8918F84D99d981039d7706DCA288
];
// voting power 1500000e18
address internal voter1 = 0x292c6DAE7417B3D31d8B6e1d2EeA0258d14C4C4b;
bytes32 internal voter1Pool = 0x0000000000000000000000000000000000000000000000000000000000000030;
bytes32[] internal voter1_operated_poolIds = [voter1Pool];
// voting power 1500000.5e18
address internal voter2 = 0x4990cE223209FCEc4ec4c1ff6E0E81eebD8Cca08;
bytes32 internal voter2Pool = 0x0000000000000000000000000000000000000000000000000000000000000031;
bytes32[] internal voter2_operated_poolIds = [voter2Pool];
// voting power 1500000e18
address internal voter3 = 0x5265Bde27F57E738bE6c1F6AB3544e82cdc92a8f;
bytes32 internal voter3Pool = 0x0000000000000000000000000000000000000000000000000000000000000032;
bytes32[] internal voter3_operated_poolIds = [voter3Pool];
// voting power 1500000e18
address internal voter4 = 0xcA9F5049c1Ea8FC78574f94B7Cf5bE5fEE354C31;
bytes32 internal voter4Pool = 0x0000000000000000000000000000000000000000000000000000000000000034;
bytes32[] internal voter4_operated_poolIds = [voter4Pool];
// voting power 1500000e18
address internal voter5 = 0xDBB5664a9DBCB98F6365804880e5b277B3155422;
bytes32 internal voter5Pool = 0x0000000000000000000000000000000000000000000000000000000000000035;
bytes32[] internal voter5_operated_poolIds = [voter5Pool];
// voting power 2291490.952353335e18
address internal voter6 = 0x9a4Eb1101C0c053505Bd71d2fFa27Ed902DEaD85;
bytes32 internal voter6Pool = 0x0000000000000000000000000000000000000000000000000000000000000029;
bytes32[] internal voter6_operated_poolIds = [voter6Pool];
// voting power 4575984.325e18
address internal voter7 = 0x9564177EC8052C92752a488a71769F710aA0A41D;
bytes32 internal voter7Pool = 0x0000000000000000000000000000000000000000000000000000000000000025;
bytes32[] internal voter7_operated_poolIds = [voter7Pool];
IERC20 internal token;
IERC20 internal maticToken;
IERC20 internal wceloToken;
IERC20 internal wyvToken;
IZeroExMock internal exchange;
IZrxTreasuryMock internal treasury;
IZrxVaultMock internal vault;
IStakingMock internal staking;
IERC20 internal weth;
ZRXWrappedToken internal wToken;
ZeroExVotes internal votes;
ZeroExTimelock internal protocolTimelock;
ZeroExTimelock internal treasuryTimelock;
ZeroExProtocolGovernor internal protocolGovernor;
ZeroExTreasuryGovernor internal treasuryGovernor;
function setUp() public {
mainnetFork = vm.createFork(MAINNET_RPC_URL);
vm.selectFork(mainnetFork);
token = IERC20(ZRX_TOKEN);
maticToken = IERC20(MATIC_TOKEN);
wceloToken = IERC20(WCELO_TOKEN);
wyvToken = IERC20(WYV_TOKEN);
exchange = IZeroExMock(payable(EXCHANGE_PROXY));
treasury = IZrxTreasuryMock(TREASURY);
vault = IZrxVaultMock(ZRX_VAULT);
staking = IStakingMock(STAKING);
weth = IERC20(staking.getWethContract());
address protocolGovernorAddress;
address treasuryGovernorAddress;
(
wToken,
votes,
protocolTimelock,
treasuryTimelock,
protocolGovernorAddress,
treasuryGovernorAddress
) = setupGovernance(token);
protocolGovernor = ZeroExProtocolGovernor(payable(protocolGovernorAddress));
treasuryGovernor = ZeroExTreasuryGovernor(payable(treasuryGovernorAddress));
}
function testProtocolGovernanceMigration() public {
// initially the zrx exchange is owned by the legacy exchange governor
assertEq(exchange.owner(), EXCHANGE_GOVERNOR);
// transfer ownership to new protocol governor
vm.prank(EXCHANGE_GOVERNOR);
exchange.transferOwnership(address(protocolGovernor));
assertEq(exchange.owner(), address(protocolGovernor));
}
function testTreasuryGovernanceMigration() public {
// Create a proposal to migrate to new governor
uint256 currentEpoch = staking.currentEpoch();
uint256 executionEpoch = currentEpoch + 2;
vm.startPrank(voter3);
IZrxTreasuryMock.ProposedAction[] memory actions = new IZrxTreasuryMock.ProposedAction[](4);
// Transfer MATIC
uint256 maticBalance = maticToken.balanceOf(address(treasury));
actions[0] = IZrxTreasuryMock.ProposedAction({
target: MATIC_TOKEN,
data: abi.encodeCall(maticToken.transfer, (address(treasuryGovernor), maticBalance)),
value: 0
});
// Transfer ZRX
uint256 zrxBalance = token.balanceOf(address(treasury));
actions[1] = IZrxTreasuryMock.ProposedAction({
target: ZRX_TOKEN,
data: abi.encodeCall(token.transfer, (address(treasuryGovernor), zrxBalance)),
value: 0
});
// Transfer wCELO
uint256 wceloBalance = wceloToken.balanceOf(address(treasury));
actions[2] = IZrxTreasuryMock.ProposedAction({
target: WCELO_TOKEN,
data: abi.encodeCall(wceloToken.transfer, (address(treasuryGovernor), wceloBalance)),
value: 0
});
// Transfer WYV
uint256 wyvBalance = wyvToken.balanceOf(address(treasury));
actions[3] = IZrxTreasuryMock.ProposedAction({
target: WYV_TOKEN,
data: abi.encodeCall(wyvToken.transfer, (address(treasuryGovernor), wyvBalance)),
value: 0
});
uint256 proposalId = treasury.propose(
actions,
executionEpoch,
"Z-5 Migrate to new treasury governor",
voter3_operated_poolIds
);
// Once a proposal is created, it becomes open for voting at the epoch after next (currentEpoch + 2)
// and is open for the voting period (currently set to 3 days).
uint256 epochDurationInSeconds = staking.epochDurationInSeconds(); // Currently set to 604800 seconds = 7 days
uint256 currentEpochEndTime = staking.currentEpochStartTimeInSeconds() + epochDurationInSeconds;
vm.warp(currentEpochEndTime + 1);
staking.endEpoch();
vm.warp(block.timestamp + epochDurationInSeconds + 1);
staking.endEpoch();
vm.stopPrank();
// quorum is 10,000,000e18 so reach that via the following votes
vm.prank(voter1);
treasury.castVote(proposalId, true, voter1_operated_poolIds);
vm.stopPrank();
vm.prank(voter2);
treasury.castVote(proposalId, true, voter2_operated_poolIds);
vm.stopPrank();
vm.prank(voter3);
treasury.castVote(proposalId, true, voter3_operated_poolIds);
vm.stopPrank();
vm.prank(voter4);
treasury.castVote(proposalId, true, voter4_operated_poolIds);
vm.stopPrank();
vm.prank(voter5);
treasury.castVote(proposalId, true, voter5_operated_poolIds);
vm.stopPrank();
vm.prank(voter6);
treasury.castVote(proposalId, true, voter6_operated_poolIds);
vm.stopPrank();
vm.prank(voter7);
treasury.castVote(proposalId, true, voter7_operated_poolIds);
vm.stopPrank();
vm.warp(block.timestamp + 3 days + 1);
// Execute proposal
treasury.execute(proposalId, actions);
// Assert value of treasury has correctly transferred
uint256 maticBalanceNewTreasury = maticToken.balanceOf(address(treasuryGovernor));
assertEq(maticBalanceNewTreasury, maticBalance);
uint256 zrxBalanceNewTreasury = token.balanceOf(address(treasuryGovernor));
assertEq(zrxBalanceNewTreasury, zrxBalance);
uint256 wceloBalanceNewTreasury = wceloToken.balanceOf(address(treasuryGovernor));
assertEq(wceloBalanceNewTreasury, wceloBalance);
uint256 wyvBalanceNewTreasury = wyvToken.balanceOf(address(treasuryGovernor));
assertEq(wyvBalanceNewTreasury, wyvBalance);
}
// Test entering catastrophic failure mode on the zrx vault to decomission v3 staking
function testCatastrophicFailureModeOnStaking() public {
DelegatorPool[5] memory delegatorPools = [
DelegatorPool(
0x0ee1F33A2EB0da738FdF035C48d62d75e996a3bd,
0x0000000000000000000000000000000000000000000000000000000000000016
),
DelegatorPool(
0xcAb3d8cBBb3dA1bDabfB003B9C828B27a821717f,
0x0000000000000000000000000000000000000000000000000000000000000017
),
DelegatorPool(
0x7f88b00Db27a500fBfA7EbC9c3CaA2Dea6F59d5b,
0x0000000000000000000000000000000000000000000000000000000000000014
),
DelegatorPool(
0xcE266E6123B682f7A7388097e2155b5379D9AC78,
0x0000000000000000000000000000000000000000000000000000000000000014
),
DelegatorPool(
0xBa4f44E774158408E2DC6c5cb65BC995F0a89180, // pool operator
0x0000000000000000000000000000000000000000000000000000000000000017
)
];
// Enter catastrophic failure mode on the zrx vault
vm.prank(STAKING_AND_VAULT_OWNER);
vault.enterCatastrophicFailure();
vm.stopPrank();
// Stakes can still be withdrawn
// staker1 withdraws
uint256 stake1 = vault.balanceOf(staker1);
uint256 balance1 = token.balanceOf(staker1);
assertGt(stake1, 0);
vm.prank(staker1);
vault.withdrawAllFrom(staker1);
vm.stopPrank();
assertEq(vault.balanceOf(staker1), 0);
assertEq(token.balanceOf(staker1), stake1 + balance1);
// staker2 withdraws
uint256 stake2 = vault.balanceOf(staker2);
uint256 balance2 = token.balanceOf(staker2);
assertGt(stake2, 0);
vm.prank(staker2);
vault.withdrawAllFrom(staker2);
vm.stopPrank();
assertEq(vault.balanceOf(staker2), 0);
assertEq(token.balanceOf(staker2), stake2 + balance2);
// Test top stakers can withdraw
for (uint256 i = 0; i < topStakers.length; i++) {
address staker = topStakers[i];
uint256 stake = vault.balanceOf(staker);
uint256 balance = token.balanceOf(staker);
assertGt(stake, 0);
vm.prank(staker);
vault.withdrawAllFrom(staker);
vm.stopPrank();
assertEq(vault.balanceOf(staker), 0);
assertEq(token.balanceOf(staker), stake + balance);
}
// Delegator can withdraw rewards
for (uint256 i = 0; i < delegatorPools.length; i++) {
address delegator = delegatorPools[i].delegator;
bytes32 pool = delegatorPools[i].pool;
uint256 reward = staking.computeRewardBalanceOfDelegator(pool, delegator);
assertGt(reward, 0);
uint256 balanceBeforeReward = weth.balanceOf(delegator);
vm.prank(delegator);
staking.withdrawDelegatorRewards(pool);
vm.stopPrank();
assertEq(weth.balanceOf(delegator), balanceBeforeReward + reward);
}
}
function testSwitchDelegationInCatastrophicMode() public {
// Enter catastrophic failure mode on the zrx vault
vm.prank(STAKING_AND_VAULT_OWNER);
vault.enterCatastrophicFailure();
// 0x delegator
address delegator = 0x5775afA796818ADA27b09FaF5c90d101f04eF600;
uint256 stake = vault.balanceOf(delegator);
uint256 balance = token.balanceOf(delegator);
assertGt(stake, 0);
// Withdraw stake all at once
vm.startPrank(delegator);
vault.withdrawAllFrom(delegator);
assertEq(vault.balanceOf(delegator), 0);
assertEq(token.balanceOf(delegator), stake + balance);
// delegate 1M ZRX to 0x4990cE223209FCEc4ec4c1ff6E0E81eebD8Cca08
vm.roll(block.number + 1);
address delegate = 0x4990cE223209FCEc4ec4c1ff6E0E81eebD8Cca08;
uint256 amountToDelegate = 1000000e18;
// Approve the wrapped token and deposit 1m ZRX
token.approve(address(wToken), amountToDelegate);
wToken.depositFor(delegator, amountToDelegate);
assertEq(wToken.balanceOf(delegator), amountToDelegate);
vm.roll(block.number + 1);
wToken.delegate(delegate);
vm.stopPrank();
assertEq(votes.getVotes(delegate), amountToDelegate);
assertEq(votes.getQuadraticVotes(delegate), amountToDelegate);
}
function testSwitchDelegationInNormalOperationMode() public {
// 0x delegator
address delegator = 0x5775afA796818ADA27b09FaF5c90d101f04eF600;
uint256 balance = token.balanceOf(delegator);
// Undelegate stake from pool 0x35
vm.startPrank(delegator);
staking.moveStake(
IStructs.StakeInfo(
IStructs.StakeStatus.DELEGATED,
0x0000000000000000000000000000000000000000000000000000000000000035
),
IStructs.StakeInfo(IStructs.StakeStatus.UNDELEGATED, bytes32(0)),
3000000000000000000000000
);
// Undelegate stake from pool 0x38
IStructs.StoredBalance memory storedBalance38 = staking.getStakeDelegatedToPoolByOwner(
delegator,
0x0000000000000000000000000000000000000000000000000000000000000038
);
staking.moveStake(
IStructs.StakeInfo(
IStructs.StakeStatus.DELEGATED,
0x0000000000000000000000000000000000000000000000000000000000000038
),
IStructs.StakeInfo(IStructs.StakeStatus.UNDELEGATED, bytes32(0)),
storedBalance38.currentEpochBalance
);
// Warp past an epochs and unstake
uint256 epochEndTime = staking.getCurrentEpochEarliestEndTimeInSeconds();
vm.warp(epochEndTime + 1);
staking.endEpoch();
staking.unstake(6000000000000000000000000);
vm.stopPrank();
assertEq(token.balanceOf(delegator), balance + 2 * 3000000000000000000000000);
// delegate 1M ZRX to 0x4990cE223209FCEc4ec4c1ff6E0E81eebD8Cca08
vm.roll(block.number + 1);
address delegate = 0x4990cE223209FCEc4ec4c1ff6E0E81eebD8Cca08;
uint256 amountToDelegate = 1000000e18;
// Approve the wrapped token and deposit 1m ZRX
token.approve(address(wToken), amountToDelegate);
wToken.depositFor(delegator, amountToDelegate);
assertEq(wToken.balanceOf(delegator), amountToDelegate);
vm.roll(block.number + 1);
wToken.delegate(delegate);
vm.stopPrank();
assertEq(votes.getVotes(delegate), amountToDelegate);
assertEq(votes.getQuadraticVotes(delegate), amountToDelegate);
}
}

View File

@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
library CubeRoot {
/// @dev Returns the cube root of `x`.
/// Credit to pleasemarkdarkly under MIT license
// Originaly from https://github.com/pleasemarkdarkly/fei-protocol-core-hh/blob/main/contracts/utils/Roots.sol
function cbrt(uint y) internal pure returns (uint z) {
// Newton's method https://en.wikipedia.org/wiki/Cube_root#Numerical_methods
if (y > 7) {
z = y;
uint x = y / 3 + 1;
while (x < z) {
z = x;
x = (y / (x * x) + (2 * x)) / 3;
}
} else if (y != 0) {
z = 1;
}
}
}

View File

@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "@0x/contracts-utils/contracts/src/v08/interfaces/IOwnableV08.sol";
/// @dev Owner management and migration features.
interface IOwnableFeature is IOwnableV08 {
/// @dev Emitted when `migrate()` is called.
/// @param caller The caller of `migrate()`.
/// @param migrator The migration contract.
/// @param newOwner The address of the new owner.
event Migrated(address caller, address migrator, address newOwner);
/// @dev Execute a migration function in the context of the ZeroEx contract.
/// The result of the function being called should be the magic bytes
/// 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner.
/// The owner will be temporarily set to `address(this)` inside the call.
/// Before returning, the owner will be set to `newOwner`.
/// @param target The migrator contract address.
/// @param newOwner The address of the new owner.
/// @param data The call data.
function migrate(address target, bytes calldata data, address newOwner) external;
}

View File

@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
pragma experimental ABIEncoderV2;
/// @dev Basic registry management features.
interface ISimpleFunctionRegistryFeature {
/// @dev A function implementation was updated via `extend()` or `rollback()`.
/// @param selector The function selector.
/// @param oldImpl The implementation contract address being replaced.
/// @param newImpl The replacement implementation contract address.
event ProxyFunctionUpdated(bytes4 indexed selector, address oldImpl, address newImpl);
/// @dev Roll back to a prior implementation of a function.
/// @param selector The function selector.
/// @param targetImpl The address of an older implementation of the function.
function rollback(bytes4 selector, address targetImpl) external;
/// @dev Register or replace a function.
/// @param selector The function selector.
/// @param impl The implementation contract for the function.
function extend(bytes4 selector, address impl) external;
/// @dev Retrieve the length of the rollback history for a function.
/// @param selector The function selector.
/// @return rollbackLength The number of items in the rollback history for
/// the function.
function getRollbackLength(bytes4 selector) external view returns (uint256 rollbackLength);
/// @dev Retrieve an entry in the rollback history for a function.
/// @param selector The function selector.
/// @param idx The index in the rollback history.
/// @return impl An implementation address for the function at
/// index `idx`.
function getRollbackEntryAtIndex(bytes4 selector, uint256 idx) external view returns (address impl);
}

View File

@@ -0,0 +1,196 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import "./IZrxVaultMock.sol";
import "./IStructs.sol";
import "./IStorageMock.sol";
pragma solidity ^0.8.19;
interface IStakingMock is IStorageMock {
/// @dev Adds a new exchange address
/// @param addr Address of exchange contract to add
function addExchangeAddress(address addr) external;
/// @dev Create a new staking pool. The sender will be the operator of this pool.
/// Note that an operator must be payable.
/// @param operatorShare Portion of rewards owned by the operator, in ppm.
/// @param addOperatorAsMaker Adds operator to the created pool as a maker for convenience iff true.
/// @return poolId The unique pool id generated for this pool.
function createStakingPool(uint32 operatorShare, bool addOperatorAsMaker) external returns (bytes32 poolId);
/// @dev Decreases the operator share for the given pool (i.e. increases pool rewards for members).
/// @param poolId Unique Id of pool.
/// @param newOperatorShare The newly decreased percentage of any rewards owned by the operator.
function decreaseStakingPoolOperatorShare(bytes32 poolId, uint32 newOperatorShare) external;
/// @dev Begins a new epoch, preparing the prior one for finalization.
/// Throws if not enough time has passed between epochs or if the
/// previous epoch was not fully finalized.
/// @return numPoolsToFinalize The number of unfinalized pools.
function endEpoch() external returns (uint256);
/// @dev Instantly finalizes a single pool that earned rewards in the previous
/// epoch, crediting it rewards for members and withdrawing operator's
/// rewards as WETH. This can be called by internal functions that need
/// to finalize a pool immediately. Does nothing if the pool is already
/// finalized or did not earn rewards in the previous epoch.
/// @param poolId The pool ID to finalize.
function finalizePool(bytes32 poolId) external;
/// @dev Initialize storage owned by this contract.
/// This function should not be called directly.
/// The StakingProxy contract will call it in `attachStakingContract()`.
function init() external;
/// @dev Allows caller to join a staking pool as a maker.
/// @param poolId Unique id of pool.
function joinStakingPoolAsMaker(bytes32 poolId) external;
/// @dev Moves stake between statuses: 'undelegated' or 'delegated'.
/// Delegated stake can also be moved between pools.
/// This change comes into effect next epoch.
/// @param from status to move stake out of.
/// @param to status to move stake into.
/// @param amount of stake to move.
function moveStake(IStructs.StakeInfo calldata from, IStructs.StakeInfo calldata to, uint256 amount) external;
/// @dev Pays a protocol fee in ETH.
/// @param makerAddress The address of the order's maker.
/// @param payerAddress The address that is responsible for paying the protocol fee.
/// @param protocolFee The amount of protocol fees that should be paid.
function payProtocolFee(address makerAddress, address payerAddress, uint256 protocolFee) external payable;
/// @dev Removes an existing exchange address
/// @param addr Address of exchange contract to remove
function removeExchangeAddress(address addr) external;
/// @dev Set all configurable parameters at once.
/// @param _epochDurationInSeconds Minimum seconds between epochs.
/// @param _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
/// @param _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
/// @param _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
/// @param _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
function setParams(
uint256 _epochDurationInSeconds,
uint32 _rewardDelegatedStakeWeight,
uint256 _minimumPoolStake,
uint32 _cobbDouglasAlphaNumerator,
uint32 _cobbDouglasAlphaDenominator
) external;
/// @dev Stake ZRX tokens. Tokens are deposited into the ZRX Vault.
/// Unstake to retrieve the ZRX. Stake is in the 'Active' status.
/// @param amount of ZRX to stake.
function stake(uint256 amount) external;
/// @dev Unstake. Tokens are withdrawn from the ZRX Vault and returned to
/// the staker. Stake must be in the 'undelegated' status in both the
/// current and next epoch in order to be unstaked.
/// @param amount of ZRX to unstake.
function unstake(uint256 amount) external;
/// @dev Withdraws the caller's WETH rewards that have accumulated
/// until the last epoch.
/// @param poolId Unique id of pool.
function withdrawDelegatorRewards(bytes32 poolId) external;
/// @dev Computes the reward balance in ETH of a specific member of a pool.
/// @param poolId Unique id of pool.
/// @param member The member of the pool.
/// @return reward Balance in ETH.
function computeRewardBalanceOfDelegator(bytes32 poolId, address member) external view returns (uint256 reward);
/// @dev Computes the reward balance in ETH of the operator of a pool.
/// @param poolId Unique id of pool.
/// @return reward Balance in ETH.
function computeRewardBalanceOfOperator(bytes32 poolId) external view returns (uint256 reward);
/// @dev Returns the earliest end time in seconds of this epoch.
/// The next epoch can begin once this time is reached.
/// Epoch period = [startTimeInSeconds..endTimeInSeconds)
/// @return Time in seconds.
function getCurrentEpochEarliestEndTimeInSeconds() external view returns (uint256);
/// @dev Gets global stake for a given status.
/// @param stakeStatus UNDELEGATED or DELEGATED
/// @return balance Global stake for given status.
function getGlobalStakeByStatus(
IStructs.StakeStatus stakeStatus
) external view returns (IStructs.StoredBalance memory balance);
/// @dev Gets an owner's stake balances by status.
/// @param staker Owner of stake.
/// @param stakeStatus UNDELEGATED or DELEGATED
/// @return balance Owner's stake balances for given status.
function getOwnerStakeByStatus(
address staker,
IStructs.StakeStatus stakeStatus
) external view returns (IStructs.StoredBalance memory balance);
/// @dev Retrieves all configurable parameter values.
/// @return _epochDurationInSeconds Minimum seconds between epochs.
/// @return _rewardDelegatedStakeWeight How much delegated stake is weighted vs operator stake, in ppm.
/// @return _minimumPoolStake Minimum amount of stake required in a pool to collect rewards.
/// @return _cobbDouglasAlphaNumerator Numerator for cobb douglas alpha factor.
/// @return _cobbDouglasAlphaDenominator Denominator for cobb douglas alpha factor.
function getParams()
external
view
returns (
uint256 _epochDurationInSeconds,
uint32 _rewardDelegatedStakeWeight,
uint256 _minimumPoolStake,
uint32 _cobbDouglasAlphaNumerator,
uint32 _cobbDouglasAlphaDenominator
);
/// @param staker of stake.
/// @param poolId Unique Id of pool.
/// @return balance Stake delegated to pool by staker.
function getStakeDelegatedToPoolByOwner(
address staker,
bytes32 poolId
) external view returns (IStructs.StoredBalance memory balance);
/// @dev Returns a staking pool
/// @param poolId Unique id of pool.
function getStakingPool(bytes32 poolId) external view returns (IStructs.Pool memory);
/// @dev Get stats on a staking pool in this epoch.
/// @param poolId Pool Id to query.
/// @return PoolStats struct for pool id.
function getStakingPoolStatsThisEpoch(bytes32 poolId) external view returns (IStructs.PoolStats memory);
/// @dev Returns the total stake delegated to a specific staking pool,
/// across all members.
/// @param poolId Unique Id of pool.
/// @return balance Total stake delegated to pool.
function getTotalStakeDelegatedToPool(bytes32 poolId) external view returns (IStructs.StoredBalance memory balance);
/// @dev An overridable way to access the deployed WETH contract.
/// Must be view to allow overrides to access state.
/// @return wethContract The WETH contract instance.
function getWethContract() external view returns (address wethContract);
/// @dev An overridable way to access the deployed zrxVault.
/// Must be view to allow overrides to access state.
/// @return zrxVault The zrxVault contract.
function getZrxVault() external view returns (IZrxVaultMock zrxVault);
}

View File

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "./IZrxVaultMock.sol";
import "./IStructs.sol";
interface IStorageMock {
function stakingContract() external view returns (address);
function lastPoolId() external view returns (bytes32);
function numMakersByPoolId(bytes32 poolId) external view returns (uint256);
function currentEpoch() external view returns (uint256);
function currentEpochStartTimeInSeconds() external view returns (uint256);
function protocolFeesThisEpochByPool(bytes32 poolId) external view returns (uint256);
function validExchanges(address exchangeAddress) external view returns (bool);
function epochDurationInSeconds() external view returns (uint256);
function rewardDelegatedStakeWeight() external view returns (uint32);
function minimumPoolStake() external view returns (uint256);
function cobbDouglasAlphaNumerator() external view returns (uint32);
function cobbDouglasAlphaDenominator() external view returns (uint32);
}

View File

@@ -0,0 +1,92 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
interface IStructs {
/// @dev Stats for a pool that earned rewards.
/// @param feesCollected Fees collected in ETH by this pool.
/// @param weightedStake Amount of weighted stake in the pool.
/// @param membersStake Amount of non-operator stake in the pool.
struct PoolStats {
uint256 feesCollected;
uint256 weightedStake;
uint256 membersStake;
}
/// @dev Holds stats aggregated across a set of pools.
/// @param rewardsAvailable Rewards (ETH) available to the epoch
/// being finalized (the previous epoch). This is simply the balance
/// of the contract at the end of the epoch.
/// @param numPoolsToFinalize The number of pools that have yet to be finalized through `finalizePools()`.
/// @param totalFeesCollected The total fees collected for the epoch being finalized.
/// @param totalWeightedStake The total fees collected for the epoch being finalized.
/// @param totalRewardsFinalized Amount of rewards that have been paid during finalization.
struct AggregatedStats {
uint256 rewardsAvailable;
uint256 numPoolsToFinalize;
uint256 totalFeesCollected;
uint256 totalWeightedStake;
uint256 totalRewardsFinalized;
}
/// @dev Encapsulates a balance for the current and next epochs.
/// Note that these balances may be stale if the current epoch
/// is greater than `currentEpoch`.
/// @param currentEpoch the current epoch
/// @param currentEpochBalance balance in the current epoch.
/// @param nextEpochBalance balance in `currentEpoch+1`.
struct StoredBalance {
uint64 currentEpoch;
uint96 currentEpochBalance;
uint96 nextEpochBalance;
}
/// @dev Statuses that stake can exist in.
/// Any stake can be (re)delegated effective at the next epoch
/// Undelegated stake can be withdrawn if it is available in both the current and next epoch
enum StakeStatus {
UNDELEGATED,
DELEGATED
}
/// @dev Info used to describe a status.
/// @param status of the stake.
/// @param poolId Unique Id of pool. This is set when status=DELEGATED.
struct StakeInfo {
StakeStatus status;
bytes32 poolId;
}
/// @dev Struct to represent a fraction.
/// @param numerator of fraction.
/// @param denominator of fraction.
struct Fraction {
uint256 numerator;
uint256 denominator;
}
/// @dev Holds the metadata for a staking pool.
/// @param operator of the pool.
/// @param operatorShare Fraction of the total balance owned by the operator, in ppm.
struct Pool {
address operator;
uint32 operatorShare;
}
}

View File

@@ -1,34 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2020 ZeroEx Intl.
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.6;
pragma solidity ^0.8.19;
import "./IOwnableFeature.sol";
import "./ISimpleFunctionRegistryFeature.sol";
interface IUniswapV2Router01 {
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
/// @dev Minimal viable Exchange Proxy interface for governance use.
interface IZeroExMock is IOwnableFeature, ISimpleFunctionRegistryFeature {
/// @dev Fallback for just receiving ether.
receive() external payable;
}

View File

@@ -0,0 +1,159 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2021 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "./IStakingMock.sol";
/// @dev Minimal viable Treasury interface for governance use.
interface IZrxTreasuryMock {
struct TreasuryParameters {
uint256 votingPeriod;
uint256 proposalThreshold;
uint256 quorumThreshold;
bytes32 defaultPoolId;
}
struct ProposedAction {
address target;
bytes data;
uint256 value;
}
struct Proposal {
bytes32 actionsHash;
uint256 executionEpoch;
uint256 voteEpoch;
uint256 votesFor;
uint256 votesAgainst;
bool executed;
}
event ProposalCreated(
address proposer,
bytes32[] operatedPoolIds,
uint256 proposalId,
ProposedAction[] actions,
uint256 executionEpoch,
string description
);
event VoteCast(address voter, bytes32[] operatedPoolIds, uint256 proposalId, bool support, uint256 votingPower);
event ProposalExecuted(uint256 proposalId);
function stakingProxy() external view returns (IStakingMock);
function defaultPoolId() external view returns (bytes32);
function votingPeriod() external view returns (uint256);
function proposalThreshold() external view returns (uint256);
function quorumThreshold() external view returns (uint256);
/// @dev Updates the proposal and quorum thresholds to the given
/// values. Note that this function is only callable by the
/// treasury contract itself, so the threshold can only be
/// updated via a successful treasury proposal.
/// @param newProposalThreshold The new value for the proposal threshold.
/// @param newQuorumThreshold The new value for the quorum threshold.
function updateThresholds(uint256 newProposalThreshold, uint256 newQuorumThreshold) external;
/// @dev Creates a proposal to send ZRX from this treasury on the
/// the given actions. Must have at least `proposalThreshold`
/// of voting power to call this function. See `getVotingPower`
/// for how voting power is computed. If a proposal is successfully
/// created, voting starts at the epoch after next (currentEpoch + 2).
/// If the vote passes, the proposal is executable during the
/// `executionEpoch`. See `hasProposalPassed` for the passing criteria.
/// @param actions The proposed ZRX actions. An action specifies a
/// contract call.
/// @param executionEpoch The epoch during which the proposal is to
/// be executed if it passes. Must be at least two epochs
/// from the current epoch.
/// @param description A text description for the proposal.
/// @param operatedPoolIds The pools operated by `msg.sender`. The
/// ZRX currently delegated to those pools will be accounted
/// for in the voting power.
/// @return proposalId The ID of the newly created proposal.
function propose(
ProposedAction[] calldata actions,
uint256 executionEpoch,
string calldata description,
bytes32[] calldata operatedPoolIds
) external returns (uint256 proposalId);
/// @dev Casts a vote for the given proposal. Only callable
/// during the voting period for that proposal.
/// One address can only vote once.
/// See `getVotingPower` for how voting power is computed.
/// @param proposalId The ID of the proposal to vote on.
/// @param support Whether to support the proposal or not.
/// @param operatedPoolIds The pools operated by `msg.sender`. The
/// ZRX currently delegated to those pools will be accounted
/// for in the voting power.
function castVote(uint256 proposalId, bool support, bytes32[] calldata operatedPoolIds) external;
/// @dev Casts a vote for the given proposal, by signature.
/// Only callable during the voting period for that proposal.
/// One address/voter can only vote once.
/// See `getVotingPower` for how voting power is computed.
/// @param proposalId The ID of the proposal to vote on.
/// @param support Whether to support the proposal or not.
/// @param operatedPoolIds The pools operated by the signer. The
/// ZRX currently delegated to those pools will be accounted
/// for in the voting power.
/// @param v the v field of the signature
/// @param r the r field of the signature
/// @param s the s field of the signature
function castVoteBySignature(
uint256 proposalId,
bool support,
bytes32[] memory operatedPoolIds,
uint8 v,
bytes32 r,
bytes32 s
) external;
/// @dev Executes a proposal that has passed and is
/// currently executable.
/// @param proposalId The ID of the proposal to execute.
/// @param actions Actions associated with the proposal to execute.
function execute(uint256 proposalId, ProposedAction[] memory actions) external payable;
/// @dev Returns the total number of proposals.
/// @return count The number of proposals.
function proposalCount() external view returns (uint256 count);
/// @dev Computes the current voting power of the given account.
/// Voting power is equal to:
/// (ZRX delegated to the default pool) +
/// 0.5 * (ZRX delegated to other pools) +
/// 0.5 * (ZRX delegated to pools operated by account)
/// @param account The address of the account.
/// @param operatedPoolIds The pools operated by `account`. The
/// ZRX currently delegated to those pools will be accounted
/// for in the voting power.
/// @return votingPower The current voting power of the given account.
function getVotingPower(
address account,
bytes32[] calldata operatedPoolIds
) external view returns (uint256 votingPower);
}

View File

@@ -0,0 +1,83 @@
/*
Copyright 2019 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
interface IZrxVaultMock {
/// @dev Emmitted whenever a StakingProxy is set in a vault.
event StakingProxySet(address stakingProxyAddress);
/// @dev Emitted when the Staking contract is put into Catastrophic Failure Mode
/// @param sender Address of sender (`msg.sender`)
event InCatastrophicFailureMode(address sender);
/// @dev Emitted when Zrx Tokens are deposited into the vault.
/// @param staker of Zrx Tokens.
/// @param amount of Zrx Tokens deposited.
event Deposit(address indexed staker, uint256 amount);
/// @dev Emitted when Zrx Tokens are withdrawn from the vault.
/// @param staker of Zrx Tokens.
/// @param amount of Zrx Tokens withdrawn.
event Withdraw(address indexed staker, uint256 amount);
/// @dev Emitted whenever the ZRX AssetProxy is set.
event ZrxProxySet(address zrxProxyAddress);
/// @dev Sets the address of the StakingProxy contract.
/// Note that only the contract staker can call this function.
/// @param _stakingProxyAddress Address of Staking proxy contract.
function setStakingProxy(address _stakingProxyAddress) external;
/// @dev Vault enters into Catastrophic Failure Mode.
/// *** WARNING - ONCE IN CATOSTROPHIC FAILURE MODE, YOU CAN NEVER GO BACK! ***
/// Note that only the contract staker can call this function.
function enterCatastrophicFailure() external;
/// @dev Sets the Zrx proxy.
/// Note that only the contract staker can call this.
/// Note that this can only be called when *not* in Catastrophic Failure mode.
/// @param zrxProxyAddress Address of the 0x Zrx Proxy.
function setZrxProxy(address zrxProxyAddress) external;
/// @dev Deposit an `amount` of Zrx Tokens from `staker` into the vault.
/// Note that only the Staking contract can call this.
/// Note that this can only be called when *not* in Catastrophic Failure mode.
/// @param staker of Zrx Tokens.
/// @param amount of Zrx Tokens to deposit.
function depositFrom(address staker, uint256 amount) external;
/// @dev Withdraw an `amount` of Zrx Tokens to `staker` from the vault.
/// Note that only the Staking contract can call this.
/// Note that this can only be called when *not* in Catastrophic Failure mode.
/// @param staker of Zrx Tokens.
/// @param amount of Zrx Tokens to withdraw.
function withdrawFrom(address staker, uint256 amount) external;
/// @dev Withdraw ALL Zrx Tokens to `staker` from the vault.
/// Note that this can only be called when *in* Catastrophic Failure mode.
/// @param staker of Zrx Tokens.
function withdrawAllFrom(address staker) external returns (uint256);
/// @dev Returns the balance in Zrx Tokens of the `staker`
/// @return Balance in Zrx.
function balanceOf(address staker) external view returns (uint256);
/// @dev Returns the entire balance of Zrx tokens in the vault.
function balanceOfZrxVault() external view returns (uint256);
}

View File

@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2023 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "@openzeppelin/token/ERC20/ERC20.sol";
// TODO remove this contract and work with an instance of ZRX compiled with 0.4
// when the following is resolved https://linear.app/0xproject/issue/PRO-44/zrx-artifact-is-incompatible-with-foundry
contract ZRXMock is ERC20 {
constructor() ERC20("0x Protocol Token", "ZRX") {
_mint(msg.sender, 10 ** 27);
}
}

View File

@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract ZeroExMock {
mapping(bytes4 => address) public implementations;
function rollback(bytes4 selector, address targetImpl) public {
implementations[selector] = targetImpl;
}
}

Some files were not shown because too many files have changed in this diff Show More