Compare commits

...

76 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 f919e8ef02907f6d74ab01a995b362b0967efc69.

* Revert "Updated CHANGELOGS & MD docs"

This reverts commit dbcc7dd6f4cff6715d2c4308759c9551e0931a61.

* 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 2b13dcfc14ead3aeb676cecb4c5e3814459212c7.

* Revert "Updated CHANGELOGS & MD docs"

This reverts commit d2bea4aa46f5e2860ebe05ccc5adae860aeda4b0.
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
139 changed files with 7928 additions and 15321 deletions

View File

@ -83,28 +83,30 @@ jobs:
-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
forge build --sizes --skip ZRXToken
- name: Run Forge tests for erc20
working-directory: contracts/erc20
run: |
forge test -vvv --gas-report
# - 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: 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: 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
@ -142,19 +144,20 @@ jobs:
forge --version
forge build --sizes
- name: Run Forge tests on governance contracts
working-directory: ./contracts/governance
run: |
forge test -vvv --gas-report
# 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: 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
# - 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: 16
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 }}

4
.gitignore vendored
View File

@ -84,6 +84,9 @@ TODO.md
# IDE file
.vscode
.idea
*~
.\#*
\#*\#
# generated contract artifacts/
generated-artifacts/
@ -99,6 +102,7 @@ foundry-artifacts/
# foundry cache
cache/
foundry-cache/
#foundry output artifacts
out/

View File

@ -1,4 +1,112 @@
[
{
"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",

View File

@ -5,6 +5,54 @@ 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

@ -1 +1 @@
Subproject commit a2edd39db95df7e9dd3f9ef9edc8c55fefddb6df
Subproject commit fc560fa34fa12a335a50c35d92e55a6628ca467c

View File

@ -1,6 +1,6 @@
{
"name": "@0x/contracts-erc20",
"version": "4.0.2",
"version": "4.0.14",
"engines": {
"node": ">=6.12"
},
@ -24,7 +24,7 @@
},
"homepage": "https://github.com/0xProject/protocol",
"devDependencies": {
"@0x/contracts-utils": "^4.8.40",
"@0x/contracts-utils": "^4.8.52",
"@0x/ts-doc-gen": "^0.0.28",
"typedoc": "~0.16.11"
},

View File

@ -39,7 +39,6 @@ contract WETH9V06Test is Test {
function testShouldConvertDepositedETHToWrappedETH() public {
vm.prank(user);
etherToken.deposit{value: 1e20}();
vm.stopPrank();
assertEq(etherToken.balanceOf(user), 1e20);
assertEq(address(etherToken).balance, 1e20);
@ -58,7 +57,6 @@ contract WETH9V06Test is Test {
etherToken.deposit{value: 1e20}();
vm.prank(user);
etherToken.withdraw(100);
vm.stopPrank();
assertEq(etherToken.balanceOf(user), 1e20 - 100);
assertEq(address(etherToken).balance, 1e20 - 100);
@ -68,7 +66,6 @@ contract WETH9V06Test is Test {
function testShouldConvertSentETHToWrappedETH() public {
vm.prank(user);
address(etherToken).call{value: 1e20}(new bytes(0));
vm.stopPrank();
assertEq(etherToken.balanceOf(user), 1e20);
assertEq(address(etherToken).balance, 1e20);

View File

@ -34,7 +34,6 @@ contract ZRXTokenTest is Test {
assembly {
_address := create(0, add(_bytecode, 0x20), mload(_bytecode))
}
vm.stopPrank();
zrxToken = IERC20Token(address(_address));
}
@ -73,7 +72,6 @@ contract ZRXTokenTest is Test {
function testShouldReturnFalseIfSenderHasInsufficientBalance() public {
vm.prank(owner);
zrxToken.approve(user, totalSupply + 1);
vm.stopPrank();
bool success = zrxToken.transferFrom(owner, user, totalSupply + 1);
assertEq(success, false);
@ -82,7 +80,6 @@ contract ZRXTokenTest is Test {
function testShouldReturnFalseIfRecipientHasInsufficientAllowance() public {
vm.prank(owner);
zrxToken.approve(user, totalSupply - 1);
vm.stopPrank();
bool success = zrxToken.transferFrom(owner, user, totalSupply);
assertEq(success, false);
@ -97,7 +94,6 @@ contract ZRXTokenTest is Test {
function testShouldNotModifySenderAllowanceIfSetToUINT256Max() public {
vm.prank(owner);
zrxToken.approve(user, type(uint256).max);
vm.stopPrank();
zrxToken.transferFrom(owner, user, 100);
assertEq(zrxToken.allowance(owner, user), type(uint256).max);
@ -106,7 +102,6 @@ contract ZRXTokenTest is Test {
function testShouldTransferCorrectlyWhenSufficientAllowance() public {
vm.prank(owner);
zrxToken.approve(user, 1000 * 1e18);
vm.stopPrank();
vm.prank(user);
zrxToken.transferFrom(owner, user, 100 * 1e18);

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.

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "@0x/governance",
"version": "1.0.0",
"version": "1.0.5",
"description": "Governance implementation for the 0x protocol and treasury",
"main": "index.js",
"directories": {
@ -20,6 +20,8 @@
"type": "git",
"url": "https://github.com/0xProject/protocol.git"
},
"license": "Apache-2.0",
"dependencies": {}
"publishConfig": {
"access": "public"
},
"license": "Apache-2.0"
}

View File

@ -14,20 +14,20 @@ import "../src/ZeroExProtocolGovernor.sol";
import "../src/ZeroExTreasuryGovernor.sol";
contract Deploy is Script {
address internal constant DEPLOYER = 0xEf37aD2BACD70119F141140f7B5E46Cd53a65fc4;
address internal constant ZRX_TOKEN = 0xE41d2489571d322189246DaFA5ebDe1F4699F498;
address internal constant TREASURY = 0x0bB1810061C2f5b2088054eE184E6C79e1591101;
address internal constant EXCHANGE = 0xDef1C0ded9bec7F1a1670819833240f027b25EfF;
address payable internal constant SECURITY_COUNCIL = payable(DEPLOYER);
address payable internal constant SECURITY_COUNCIL = payable(0x979BDb496e5f0A00af078b7a45F1E9E6bcff170F);
uint256 internal constant QUADRATIC_THRESHOLD = 1000000e18;
function setUp() public {}
function run() external {
vm.startBroadcast(vm.envAddress("DEPLOYER"));
address deployer = vm.envAddress("DEPLOYER");
vm.startBroadcast(deployer);
console2.log("Zrx Token", ZRX_TOKEN);
address wTokenPrediction = predict(DEPLOYER, vm.getNonce(DEPLOYER) + 2);
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)));
@ -41,7 +41,7 @@ contract Deploy is Script {
address[] memory proposers = new address[](0);
address[] memory executors = new address[](0);
ZeroExTimelock protocolTimelock = new ZeroExTimelock(3 days, proposers, executors, DEPLOYER);
ZeroExTimelock protocolTimelock = new ZeroExTimelock(3 days, proposers, executors, deployer);
console2.log("Protocol timelock", address(protocolTimelock));
ZeroExProtocolGovernor protocolGovernor = new ZeroExProtocolGovernor(
@ -52,9 +52,10 @@ contract Deploy is Script {
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);
ZeroExTimelock treasuryTimelock = new ZeroExTimelock(2 days, proposers, executors, deployer);
console2.log("Treasury timelock", address(treasuryTimelock));
ZeroExTreasuryGovernor treasuryGovernor = new ZeroExTreasuryGovernor(
@ -66,6 +67,7 @@ contract Deploy is Script {
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();

View File

@ -23,6 +23,7 @@ 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";
@ -34,6 +35,11 @@ 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;
@ -42,10 +48,25 @@ contract GovernanceE2ETest is BaseTest {
address internal constant EXCHANGE_PROXY = 0xDef1C0ded9bec7F1a1670819833240f027b25EfF;
address internal constant EXCHANGE_GOVERNOR = 0x618F9C67CE7Bf1a50afa1E7e0238422601b0ff6e;
address internal constant TREASURY = 0x0bB1810061C2f5b2088054eE184E6C79e1591101;
address internal constant STAKING = 0xa26e80e7Dea86279c6d778D702Cc413E6CFfA777;
address internal staker = 0x5265Bde27F57E738bE6c1F6AB3544e82cdc92a8f;
bytes32 internal stakerPool = 0x0000000000000000000000000000000000000000000000000000000000000032;
bytes32[] internal staker_operated_poolIds = [stakerPool];
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;
@ -89,7 +110,9 @@ contract GovernanceE2ETest is BaseTest {
IZeroExMock internal exchange;
IZrxTreasuryMock internal treasury;
IZrxVaultMock internal vault;
IStakingMock internal staking;
IERC20 internal weth;
ZRXWrappedToken internal wToken;
ZeroExVotes internal votes;
@ -109,7 +132,9 @@ contract GovernanceE2ETest is BaseTest {
exchange = IZeroExMock(payable(EXCHANGE_PROXY));
treasury = IZrxTreasuryMock(TREASURY);
vault = IZrxVaultMock(ZRX_VAULT);
staking = IStakingMock(STAKING);
weth = IERC20(staking.getWethContract());
address protocolGovernorAddress;
address treasuryGovernorAddress;
@ -142,7 +167,7 @@ contract GovernanceE2ETest is BaseTest {
uint256 currentEpoch = staking.currentEpoch();
uint256 executionEpoch = currentEpoch + 2;
vm.startPrank(staker);
vm.startPrank(voter3);
IZrxTreasuryMock.ProposedAction[] memory actions = new IZrxTreasuryMock.ProposedAction[](4);
@ -182,7 +207,7 @@ contract GovernanceE2ETest is BaseTest {
actions,
executionEpoch,
"Z-5 Migrate to new treasury governor",
staker_operated_poolIds
voter3_operated_poolIds
);
// Once a proposal is created, it becomes open for voting at the epoch after next (currentEpoch + 2)
@ -243,4 +268,187 @@ contract GovernanceE2ETest is BaseTest {
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

@ -17,36 +17,16 @@
*/
import "./IZrxVaultMock.sol";
import "./IStructs.sol";
import "./IStorageMock.sol";
pragma solidity ^0.8.19;
interface IStakingMock {
/// @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 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 Holds the metadata for a staking pool.
/// @param operator Operator of the pool.
/// @param operatorShare Fraction of the total balance owned by the operator, in ppm.
struct Pool {
address operator;
uint32 operatorShare;
}
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.
@ -55,26 +35,105 @@ interface IStakingMock {
/// @return poolId The unique pool id generated for this pool.
function createStakingPool(uint32 operatorShare, bool addOperatorAsMaker) external returns (bytes32 poolId);
/// @dev Returns the current staking epoch number.
/// @return epoch The current epoch.
function currentEpoch() external view returns (uint256 epoch);
/// @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 Returns the time (in seconds) at which the current staking epoch started.
/// @return startTime The start time of the current epoch, in seconds.
function currentEpochStartTimeInSeconds() external view returns (uint256 startTime);
/// @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 Returns the duration of an epoch in seconds. This value can be updated.
/// @return duration The duration of an epoch, in seconds.
function epochDurationInSeconds() external view returns (uint256 duration);
/// @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 Returns a staking pool
/// @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 getStakingPool(bytes32 poolId) external view returns (Pool memory);
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(StakeStatus stakeStatus) external view returns (StoredBalance memory balance);
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.
@ -82,25 +141,56 @@ interface IStakingMock {
/// @return balance Owner's stake balances for given status.
function getOwnerStakeByStatus(
address staker,
StakeStatus stakeStatus
) external view returns (StoredBalance memory balance);
IStructs.StakeStatus stakeStatus
) external view returns (IStructs.StoredBalance memory balance);
/// @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 (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
);
/// @dev Returns the stake delegated to a specific staking pool, by a given staker.
/// @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 (StoredBalance memory balance);
) external view returns (IStructs.StoredBalance memory balance);
function endEpoch() external returns (uint256);
/// @dev Returns a staking pool
/// @param poolId Unique id of pool.
function getStakingPool(bytes32 poolId) external view returns (IStructs.Pool memory);
function finalizePool(bytes32 poolId) external;
/// @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

@ -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

@ -90,7 +90,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);
@ -155,7 +154,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);
@ -266,7 +264,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);
@ -330,7 +327,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);
@ -366,7 +362,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);
@ -402,7 +397,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);
@ -438,7 +432,6 @@ abstract contract ZeroExGovernorBaseTest is BaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);

View File

@ -70,13 +70,12 @@ contract ZeroExProtocolGovernorTest is ZeroExGovernorBaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
vm.prank(account3);
governor.castVote(proposalId, 0); // Vote "against"
vm.stopPrank();
vm.prank(account4);
governor.castVote(proposalId, 2); // Vote "abstain"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);

View File

@ -66,13 +66,12 @@ contract ZeroExTreasuryGovernorTest is ZeroExGovernorBaseTest {
// Vote
vm.prank(account2);
governor.castVote(proposalId, 1); // Vote "for"
vm.stopPrank();
vm.prank(account3);
governor.castVote(proposalId, 0); // Vote "against"
vm.stopPrank();
vm.prank(account4);
governor.castVote(proposalId, 2); // Vote "abstain"
vm.stopPrank();
// Fast forward to vote end
vm.roll(governor.proposalDeadline(proposalId) + 1);

View File

@ -1,4 +1,103 @@
[
{
"timestamp": 1700094997,
"version": "5.4.60",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1693346928,
"version": "5.4.59",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1692368658,
"version": "5.4.58",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1691617396,
"version": "5.4.57",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689974915,
"version": "5.4.56",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689791426,
"version": "5.4.55",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1683749017,
"version": "5.4.54",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1682976338,
"version": "5.4.53",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681969282,
"version": "5.4.52",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681697326,
"version": "5.4.51",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "5.4.50",
"changes": [
{
"note": "Dependencies updated"
}
],
"timestamp": 1681157139
},
{
"timestamp": 1678410794,
"version": "5.4.49",

View File

@ -5,6 +5,50 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v5.4.60 - _November 16, 2023_
* Dependencies updated
## v5.4.59 - _August 29, 2023_
* Dependencies updated
## v5.4.58 - _August 18, 2023_
* Dependencies updated
## v5.4.57 - _August 9, 2023_
* Dependencies updated
## v5.4.56 - _July 21, 2023_
* Dependencies updated
## v5.4.55 - _July 19, 2023_
* Dependencies updated
## v5.4.54 - _May 10, 2023_
* Dependencies updated
## v5.4.53 - _May 1, 2023_
* Dependencies updated
## v5.4.52 - _April 20, 2023_
* Dependencies updated
## v5.4.51 - _April 17, 2023_
* Dependencies updated
## v5.4.50 - _April 10, 2023_
* Dependencies updated
## v5.4.49 - _March 10, 2023_
* Dependencies updated

View File

@ -1,6 +1,6 @@
{
"name": "@0x/contracts-test-utils",
"version": "5.4.49",
"version": "5.4.60",
"engines": {
"node": ">=6.12"
},
@ -39,19 +39,19 @@
"typescript": "4.6.3"
},
"dependencies": {
"@0x/assert": "^3.0.35",
"@0x/assert": "^3.0.36",
"@0x/base-contract": "^7.0.0",
"@0x/contract-addresses": "^8.2.0",
"@0x/dev-utils": "^5.0.0",
"@0x/contract-addresses": "^8.13.0",
"@0x/dev-utils": "^5.0.2",
"@0x/json-schemas": "^6.4.4",
"@0x/order-utils": "^10.4.28",
"@0x/sol-profiler": "^4.1.36",
"@0x/sol-trace": "^3.0.46",
"@0x/subproviders": "^7.0.0",
"@0x/types": "^3.3.6",
"@0x/subproviders": "^8.0.1",
"@0x/types": "^3.3.7",
"@0x/typescript-typings": "^5.3.1",
"@0x/utils": "^7.0.0",
"@0x/web3-wrapper": "^8.0.0",
"@0x/web3-wrapper": "^8.0.1",
"@types/bn.js": "^4.11.0",
"@types/js-combinatorics": "^0.5.29",
"@types/lodash": "4.14.104",

View File

@ -1,12 +1,9 @@
import { devConstants, env, EnvVars, Web3Config, web3Factory } from '@0x/dev-utils';
import { prependSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { logUtils } from '@0x/utils';
import { Web3ProviderEngine } from '@0x/subproviders';
import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
import { constants } from './constants';
import { profiler } from './profiler';
import { revertTrace } from './revert_trace';
export const txDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS,
@ -31,26 +28,9 @@ export const providerConfigs: Web3Config = {
export const provider: Web3ProviderEngine = web3Factory.getRpcProvider(providerConfigs);
provider.stop();
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
const isProfilerEnabled = env.parseBoolean(EnvVars.SolidityProfiler);
const isRevertTraceEnabled = env.parseBoolean(EnvVars.SolidityRevertTrace);
const enabledSubproviderCount = _.filter(
[isCoverageEnabled, isProfilerEnabled, isRevertTraceEnabled],
_.identity.bind(_),
).length;
const enabledSubproviderCount = _.filter([isCoverageEnabled], _.identity.bind(_)).length;
if (enabledSubproviderCount > 1) {
throw new Error(`Only one of profiler or revert trace subproviders can be enabled at a time`);
}
if (isProfilerEnabled) {
const profilerSubprovider = profiler.getProfilerSubproviderSingleton();
logUtils.log(
"By default profilerSubprovider is stopped so that you don't get noise from setup code. Don't forget to start it before the code you want to profile and stop it afterwards",
);
profilerSubprovider.stop();
prependSubprovider(provider, profilerSubprovider);
}
if (isRevertTraceEnabled) {
const revertTraceSubprovider = revertTrace.getRevertTraceSubproviderSingleton();
prependSubprovider(provider, revertTraceSubprovider);
}
export const web3Wrapper = new Web3Wrapper(provider);

View File

@ -1,4 +1,112 @@
[
{
"timestamp": 1700094997,
"version": "1.4.54",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1693346928,
"version": "1.4.53",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1692368658,
"version": "1.4.52",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1691617396,
"version": "1.4.51",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689974915,
"version": "1.4.50",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689791426,
"version": "1.4.49",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1683749017,
"version": "1.4.48",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1682976338,
"version": "1.4.47",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1682334742,
"version": "1.4.46",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681969282,
"version": "1.4.45",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681697326,
"version": "1.4.44",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "1.4.43",
"changes": [
{
"note": "Dependencies updated"
}
],
"timestamp": 1681157139
},
{
"timestamp": 1678410794,
"version": "1.4.42",

View File

@ -5,6 +5,54 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v1.4.54 - _November 16, 2023_
* Dependencies updated
## v1.4.53 - _August 29, 2023_
* Dependencies updated
## v1.4.52 - _August 18, 2023_
* Dependencies updated
## v1.4.51 - _August 9, 2023_
* Dependencies updated
## v1.4.50 - _July 21, 2023_
* Dependencies updated
## v1.4.49 - _July 19, 2023_
* Dependencies updated
## v1.4.48 - _May 10, 2023_
* Dependencies updated
## v1.4.47 - _May 1, 2023_
* Dependencies updated
## v1.4.46 - _April 24, 2023_
* Dependencies updated
## v1.4.45 - _April 20, 2023_
* Dependencies updated
## v1.4.44 - _April 17, 2023_
* Dependencies updated
## v1.4.43 - _April 10, 2023_
* Dependencies updated
## v1.4.42 - _March 10, 2023_
* Dependencies updated

View File

@ -1,6 +1,6 @@
{
"name": "@0x/contracts-treasury",
"version": "1.4.42",
"version": "1.4.54",
"engines": {
"node": ">=6.12"
},
@ -45,13 +45,13 @@
},
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/treasury",
"devDependencies": {
"@0x/abi-gen": "^5.8.1",
"@0x/contract-addresses": "^8.2.0",
"@0x/abi-gen": "^5.8.5",
"@0x/contract-addresses": "^8.13.0",
"@0x/contracts-asset-proxy": "^3.7.19",
"@0x/contracts-erc20": "3.3.57",
"@0x/contracts-gen": "^2.0.48",
"@0x/contracts-gen": "^2.0.50",
"@0x/contracts-staking": "^2.0.45",
"@0x/contracts-test-utils": "^5.4.49",
"@0x/contracts-test-utils": "^5.4.60",
"@0x/sol-compiler": "^4.8.2",
"@0x/ts-doc-gen": "^0.0.28",
"@types/isomorphic-fetch": "^0.0.35",
@ -73,12 +73,12 @@
},
"dependencies": {
"@0x/base-contract": "^7.0.0",
"@0x/protocol-utils": "^11.18.1",
"@0x/subproviders": "^7.0.0",
"@0x/types": "^3.3.6",
"@0x/protocol-utils": "^11.24.2",
"@0x/subproviders": "^8.0.1",
"@0x/types": "^3.3.7",
"@0x/typescript-typings": "^5.3.1",
"@0x/utils": "^7.0.0",
"@0x/web3-wrapper": "^8.0.0",
"@0x/web3-wrapper": "^8.0.1",
"ethereum-types": "^3.7.1",
"ethereumjs-util": "^7.0.10"
},

View File

@ -1,4 +1,112 @@
[
{
"timestamp": 1700094997,
"version": "4.8.52",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1693346928,
"version": "4.8.51",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1692368658,
"version": "4.8.50",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1691617396,
"version": "4.8.49",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689974915,
"version": "4.8.48",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1689791426,
"version": "4.8.47",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1683749017,
"version": "4.8.46",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1682976338,
"version": "4.8.45",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"timestamp": 1681969282,
"version": "4.8.44",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "4.8.43",
"changes": [
{
"note": "Dependencies updated"
}
],
"timestamp": 1681756154
},
{
"timestamp": 1681697326,
"version": "4.8.42",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "4.8.41",
"changes": [
{
"note": "Dependencies updated"
}
],
"timestamp": 1681157139
},
{
"timestamp": 1678410794,
"version": "4.8.40",

View File

@ -5,6 +5,54 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v4.8.52 - _November 16, 2023_
* Dependencies updated
## v4.8.51 - _August 29, 2023_
* Dependencies updated
## v4.8.50 - _August 18, 2023_
* Dependencies updated
## v4.8.49 - _August 9, 2023_
* Dependencies updated
## v4.8.48 - _July 21, 2023_
* Dependencies updated
## v4.8.47 - _July 19, 2023_
* Dependencies updated
## v4.8.46 - _May 10, 2023_
* Dependencies updated
## v4.8.45 - _May 1, 2023_
* Dependencies updated
## v4.8.44 - _April 20, 2023_
* Dependencies updated
## v4.8.43 - _April 17, 2023_
* Dependencies updated
## v4.8.42 - _April 17, 2023_
* Dependencies updated
## v4.8.41 - _April 10, 2023_
* Dependencies updated
## v4.8.40 - _March 10, 2023_
* Dependencies updated

View File

@ -1,6 +1,6 @@
{
"name": "@0x/contracts-utils",
"version": "4.8.40",
"version": "4.8.52",
"engines": {
"node": ">=6.12"
},
@ -15,7 +15,6 @@
"pre_build": "run-s compile contracts:gen generate_contract_wrappers contracts:copy",
"test": "yarn run_mocha",
"rebuild_and_test": "run-s build test",
"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",
@ -44,14 +43,14 @@
},
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/utils",
"devDependencies": {
"@0x/abi-gen": "^5.8.1",
"@0x/contracts-gen": "^2.0.48",
"@0x/contracts-test-utils": "^5.4.49",
"@0x/dev-utils": "^5.0.0",
"@0x/abi-gen": "^5.8.5",
"@0x/contracts-gen": "^2.0.50",
"@0x/contracts-test-utils": "^5.4.60",
"@0x/dev-utils": "^5.0.2",
"@0x/order-utils": "^10.4.28",
"@0x/sol-compiler": "^4.8.2",
"@0x/types": "^3.3.6",
"@0x/web3-wrapper": "^8.0.0",
"@0x/types": "^3.3.7",
"@0x/web3-wrapper": "^8.0.1",
"@types/bn.js": "^4.11.0",
"@types/lodash": "4.14.104",
"@types/mocha": "^5.2.7",

View File

@ -1,4 +1,130 @@
[
{
"version": "0.49.0",
"changes": [
{
"note": "Allowlist Sepolia in AbstractBridgeAdapter"
}
],
"timestamp": 1700094997
},
{
"version": "0.48.0",
"changes": [
{
"note": "Add VelodromeV2 support on Base"
}
],
"timestamp": 1693346928
},
{
"version": "0.47.0",
"changes": [
{
"note": "Add MaverickV1 support on Ethereum, BSC, and Base"
}
],
"timestamp": 1692368658
},
{
"version": "0.46.0",
"changes": [
{
"note": "Add VelodromeV2 support on Optimism"
}
],
"timestamp": 1691617396
},
{
"timestamp": 1689974915,
"version": "0.45.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "0.45.0",
"changes": [
{
"note": "Remove Bancor V1 support"
},
{
"note": "Remove Shell and MStable support"
},
{
"note": "Add Base Mainnet and Goerli BridgeAdapters"
},
{
"note": "Add Uniswap V3 support on Avalanche and BSC"
}
],
"timestamp": 1689791426
},
{
"version": "0.44.0",
"changes": [
{
"note": "Add Trader Joe V2 MixIn to Arbitrum"
}
],
"timestamp": 1683749017
},
{
"version": "0.43.0",
"changes": [
{
"note": "Add Trader Joe V2.1 Router Support for MixIn"
}
],
"timestamp": 1682976338
},
{
"timestamp": 1682334742,
"version": "0.42.1",
"changes": [
{
"note": "Dependencies updated"
}
]
},
{
"version": "0.42.0",
"changes": [
{
"note": "Add Trader Joe V2 support on Avalanche"
}
],
"timestamp": 1681969282
},
{
"version": "0.41.0",
"changes": [
{
"note": "Add Barter support on Ethereum"
}
],
"timestamp": 1681756154
},
{
"version": "0.40.0",
"changes": [
{
"note": "Add Barter support on Ethereum"
}
],
"timestamp": 1681697326
},
{
"version": "0.39.2",
"changes": [
{
"note": "Uprgade dependencies"
}
],
"timestamp": 1681157139
},
{
"version": "0.39.1",
"changes": [

View File

@ -5,6 +5,61 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v0.49.0 - _November 16, 2023_
* Allowlist Sepolia in AbstractBridgeAdapter
## v0.48.0 - _August 29, 2023_
* Add VelodromeV2 support on Base
## v0.47.0 - _August 18, 2023_
* Add MaverickV1 support on Ethereum, BSC, and Base
## v0.46.0 - _August 9, 2023_
* Add VelodromeV2 support on Optimism
## v0.45.1 - _July 21, 2023_
* Dependencies updated
## v0.45.0 - _July 19, 2023_
* Remove Bancor V1 support
* Remove Shell and MStable support
* Add Base Mainnet and Goerli BridgeAdapters
* Add Uniswap V3 support on Avalanche and BSC
## v0.44.0 - _May 10, 2023_
* Add Trader Joe V2 MixIn to Arbitrum
## v0.43.0 - _May 1, 2023_
* Add Trader Joe V2.1 Router Support for MixIn
## v0.42.1 - _April 24, 2023_
* Dependencies updated
## v0.42.0 - _April 20, 2023_
* Add Trader Joe V2 support on Avalanche
## v0.41.0 - _April 17, 2023_
* Add Barter support on Ethereum
## v0.40.0 - _April 17, 2023_
* Add Barter support on Ethereum
## v0.39.2 - _April 10, 2023_
* Uprgade dependencies
## v0.39.1 - _March 10, 2023_
* Add KyberElastic mixin for Optimism and BSC

View File

@ -31,6 +31,7 @@
"./contracts/src/features/FundRecoveryFeature.sol",
"./contracts/src/features/LiquidityProviderFeature.sol",
"./contracts/src/features/MetaTransactionsFeature.sol",
"./contracts/src/features/MetaTransactionsFeatureV2.sol",
"./contracts/src/features/NativeOrdersFeature.sol",
"./contracts/src/features/OtcOrdersFeature.sol",
"./contracts/src/features/OwnableFeature.sol",
@ -48,6 +49,7 @@
"./contracts/src/features/interfaces/IFundRecoveryFeature.sol",
"./contracts/src/features/interfaces/ILiquidityProviderFeature.sol",
"./contracts/src/features/interfaces/IMetaTransactionsFeature.sol",
"./contracts/src/features/interfaces/IMetaTransactionsFeatureV2.sol",
"./contracts/src/features/interfaces/IMultiplexFeature.sol",
"./contracts/src/features/interfaces/INativeOrdersEvents.sol",
"./contracts/src/features/interfaces/INativeOrdersFeature.sol",
@ -113,6 +115,8 @@
"./contracts/src/transformers/bridges/ArbitrumBridgeAdapter.sol",
"./contracts/src/transformers/bridges/AvalancheBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BSCBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BaseBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BaseGoerliBridgeAdapter.sol",
"./contracts/src/transformers/bridges/BridgeProtocols.sol",
"./contracts/src/transformers/bridges/CeloBridgeAdapter.sol",
"./contracts/src/transformers/bridges/EthereumBridgeAdapter.sol",
@ -123,7 +127,6 @@
"./contracts/src/transformers/bridges/mixins/MixinAaveV2.sol",
"./contracts/src/transformers/bridges/mixins/MixinBalancer.sol",
"./contracts/src/transformers/bridges/mixins/MixinBalancerV2Batch.sol",
"./contracts/src/transformers/bridges/mixins/MixinBancor.sol",
"./contracts/src/transformers/bridges/mixins/MixinBancorV3.sol",
"./contracts/src/transformers/bridges/mixins/MixinCompound.sol",
"./contracts/src/transformers/bridges/mixins/MixinCryptoCom.sol",
@ -134,12 +137,10 @@
"./contracts/src/transformers/bridges/mixins/MixinGMX.sol",
"./contracts/src/transformers/bridges/mixins/MixinKyberDmm.sol",
"./contracts/src/transformers/bridges/mixins/MixinLido.sol",
"./contracts/src/transformers/bridges/mixins/MixinMStable.sol",
"./contracts/src/transformers/bridges/mixins/MixinMakerPSM.sol",
"./contracts/src/transformers/bridges/mixins/MixinMooniswap.sol",
"./contracts/src/transformers/bridges/mixins/MixinNerve.sol",
"./contracts/src/transformers/bridges/mixins/MixinPlatypus.sol",
"./contracts/src/transformers/bridges/mixins/MixinShell.sol",
"./contracts/src/transformers/bridges/mixins/MixinSolidly.sol",
"./contracts/src/transformers/bridges/mixins/MixinSynthetix.sol",
"./contracts/src/transformers/bridges/mixins/MixinUniswap.sol",

@ -1 +1 @@
Subproject commit a2edd39db95df7e9dd3f9ef9edc8c55fefddb6df
Subproject commit fc560fa34fa12a335a50c35d92e55a6628ca467c

View File

@ -20,6 +20,7 @@ import "./features/interfaces/ISimpleFunctionRegistryFeature.sol";
import "./features/interfaces/ITokenSpenderFeature.sol";
import "./features/interfaces/ITransformERC20Feature.sol";
import "./features/interfaces/IMetaTransactionsFeature.sol";
import "./features/interfaces/IMetaTransactionsFeatureV2.sol";
import "./features/interfaces/IUniswapFeature.sol";
import "./features/interfaces/IUniswapV3Feature.sol";
import "./features/interfaces/IPancakeSwapFeature.sol";
@ -39,6 +40,7 @@ interface IZeroEx is
ISimpleFunctionRegistryFeature,
ITransformERC20Feature,
IMetaTransactionsFeature,
IMetaTransactionsFeatureV2,
IUniswapFeature,
IUniswapV3Feature,
IPancakeSwapFeature,

View File

@ -0,0 +1,616 @@
// 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 "@0x/contracts-erc20/src/IEtherToken.sol";
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
import "../errors/LibMetaTransactionsRichErrors.sol";
import "../fixins/FixinCommon.sol";
import "../fixins/FixinReentrancyGuard.sol";
import "../fixins/FixinTokenSpender.sol";
import "../fixins/FixinEIP712.sol";
import "../migrations/LibMigrate.sol";
import "../storage/LibMetaTransactionsV2Storage.sol";
import "./interfaces/IFeature.sol";
import "./interfaces/IMetaTransactionsFeatureV2.sol";
import "./interfaces/IMultiplexFeature.sol";
import "./interfaces/INativeOrdersFeature.sol";
import "./interfaces/ITransformERC20Feature.sol";
import "./libs/LibSignature.sol";
/// @dev MetaTransactions feature.
contract MetaTransactionsFeatureV2 is
IFeature,
IMetaTransactionsFeatureV2,
FixinCommon,
FixinReentrancyGuard,
FixinEIP712,
FixinTokenSpender
{
using LibBytesV06 for bytes;
using LibRichErrorsV06 for bytes;
/// @dev Describes the state of a meta transaction.
struct ExecuteState {
// Sender of the meta-transaction.
address sender;
// Hash of the meta-transaction data.
bytes32 hash;
// The meta-transaction data.
MetaTransactionDataV2 mtx;
// The meta-transaction signature (by `mtx.signer`).
LibSignature.Signature signature;
// The selector of the function being called.
bytes4 selector;
// The ETH balance of this contract before performing the call.
uint256 selfBalance;
// The block number at which the meta-transaction was executed.
uint256 executedBlockNumber;
}
/// @dev Arguments for a `TransformERC20.transformERC20()` call.
struct ExternalTransformERC20Args {
IERC20Token inputToken;
IERC20Token outputToken;
uint256 inputTokenAmount;
uint256 minOutputTokenAmount;
ITransformERC20Feature.Transformation[] transformations;
}
/// @dev Name of this feature.
string public constant override FEATURE_NAME = "MetaTransactionsV2";
/// @dev Version of this feature.
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 0, 0);
/// @dev EIP712 typehash of the `MetaTransactionData` struct.
bytes32 public immutable MTX_EIP712_TYPEHASH =
keccak256(
"MetaTransactionDataV2("
"address signer,"
"address sender,"
"uint256 expirationTimeSeconds,"
"uint256 salt,"
"bytes callData,"
"address feeToken,"
"MetaTransactionFeeData[] fees"
")"
"MetaTransactionFeeData("
"address recipient,"
"uint256 amount"
")"
);
bytes32 public immutable MTX_FEE_TYPEHASH =
keccak256(
"MetaTransactionFeeData("
"address recipient,"
"uint256 amount"
")"
);
/// @dev The WETH token contract.
IEtherToken private immutable WETH;
/// @dev Ensures that the ETH balance of `this` does not go below the
/// initial ETH balance before the call (excluding ETH attached to the call).
modifier doesNotReduceEthBalance() {
uint256 initialBalance = address(this).balance;
_;
require(initialBalance <= address(this).balance, "MetaTransactionsFeatureV2/ETH_LEAK");
}
constructor(address zeroExAddress, IEtherToken weth) public FixinCommon() FixinEIP712(zeroExAddress) {
WETH = weth;
}
/// @dev Initialize and register this feature.
/// Should be delegatecalled by `Migrate.migrate()`.
/// @return success `LibMigrate.SUCCESS` on success.
function migrate() external returns (bytes4 success) {
_registerFeatureFunction(this.executeMetaTransactionV2.selector);
_registerFeatureFunction(this.batchExecuteMetaTransactionsV2.selector);
_registerFeatureFunction(this.getMetaTransactionV2ExecutedBlock.selector);
_registerFeatureFunction(this.getMetaTransactionV2HashExecutedBlock.selector);
_registerFeatureFunction(this.getMetaTransactionV2Hash.selector);
return LibMigrate.MIGRATE_SUCCESS;
}
/// @dev Execute a single meta-transaction.
/// @param mtx The meta-transaction.
/// @param signature The signature by `mtx.signer`.
/// @return returnResult The ABI-encoded result of the underlying call.
function executeMetaTransactionV2(
MetaTransactionDataV2 memory mtx,
LibSignature.Signature memory signature
) public override nonReentrant(REENTRANCY_MTX) doesNotReduceEthBalance returns (bytes memory returnResult) {
ExecuteState memory state;
state.sender = msg.sender;
state.mtx = mtx;
state.hash = getMetaTransactionV2Hash(mtx);
state.signature = signature;
returnResult = _executeMetaTransactionPrivate(state);
}
/// @dev Execute multiple meta-transactions.
/// @param mtxs The meta-transactions.
/// @param signatures The signature by each respective `mtx.signer`.
/// @return returnResults The ABI-encoded results of the underlying calls.
function batchExecuteMetaTransactionsV2(
MetaTransactionDataV2[] memory mtxs,
LibSignature.Signature[] memory signatures
) public override nonReentrant(REENTRANCY_MTX) doesNotReduceEthBalance returns (bytes[] memory returnResults) {
if (mtxs.length != signatures.length) {
LibMetaTransactionsRichErrors
.InvalidMetaTransactionsArrayLengthsError(mtxs.length, signatures.length)
.rrevert();
}
returnResults = new bytes[](mtxs.length);
for (uint256 i = 0; i < mtxs.length; ++i) {
ExecuteState memory state;
state.sender = msg.sender;
state.mtx = mtxs[i];
state.hash = getMetaTransactionV2Hash(mtxs[i]);
state.signature = signatures[i];
returnResults[i] = _executeMetaTransactionPrivate(state);
}
}
/// @dev Get the block at which a meta-transaction has been executed.
/// @param mtx The meta-transaction.
/// @return blockNumber The block height when the meta-transactioin was executed.
function getMetaTransactionV2ExecutedBlock(
MetaTransactionDataV2 memory mtx
) public view override returns (uint256 blockNumber) {
return getMetaTransactionV2HashExecutedBlock(getMetaTransactionV2Hash(mtx));
}
/// @dev Get the block at which a meta-transaction hash has been executed.
/// @param mtxHash The meta-transaction hash.
/// @return blockNumber The block height when the meta-transactioin was executed.
function getMetaTransactionV2HashExecutedBlock(bytes32 mtxHash) public view override returns (uint256 blockNumber) {
return LibMetaTransactionsV2Storage.getStorage().mtxHashToExecutedBlockNumber[mtxHash];
}
/// @dev Get the EIP712 hash of a meta-transaction.
/// @param mtx The meta-transaction.
/// @return mtxHash The EIP712 hash of `mtx`.
function getMetaTransactionV2Hash(MetaTransactionDataV2 memory mtx) public view override returns (bytes32 mtxHash) {
bytes32[] memory feeHashes = new bytes32[](mtx.fees.length);
for (uint256 i = 0; i < mtx.fees.length; ++i) {
feeHashes[i] = keccak256(abi.encode(MTX_FEE_TYPEHASH, mtx.fees[i]));
}
return
_getEIP712Hash(
keccak256(
abi.encode(
MTX_EIP712_TYPEHASH,
mtx.signer,
mtx.sender,
mtx.expirationTimeSeconds,
mtx.salt,
keccak256(mtx.callData),
mtx.feeToken,
keccak256(abi.encodePacked(feeHashes))
)
)
);
}
/// @dev Execute a meta-transaction by `sender`. Low-level, hidden variant.
/// @param state The `ExecuteState` for this metatransaction, with `sender`,
/// `hash`, `mtx`, and `signature` fields filled.
/// @return returnResult The ABI-encoded result of the underlying call.
function _executeMetaTransactionPrivate(ExecuteState memory state) private returns (bytes memory returnResult) {
_validateMetaTransaction(state);
// Mark the transaction executed by storing the block at which it was executed.
// Currently the block number just indicates that the mtx was executed and
// serves no other purpose from within this contract.
LibMetaTransactionsV2Storage.getStorage().mtxHashToExecutedBlockNumber[state.hash] = block.number;
// Pay the fees to the fee recipients.
for (uint256 i = 0; i < state.mtx.fees.length; ++i) {
_transferERC20TokensFrom(
state.mtx.feeToken,
state.mtx.signer,
state.mtx.fees[i].recipient,
state.mtx.fees[i].amount
);
}
// Execute the call based on the selector.
state.selector = state.mtx.callData.readBytes4(0);
if (state.selector == ITransformERC20Feature.transformERC20.selector) {
returnResult = _executeTransformERC20Call(state);
} else if (state.selector == INativeOrdersFeature.fillLimitOrder.selector) {
returnResult = _executeFillLimitOrderCall(state);
} else if (state.selector == INativeOrdersFeature.fillRfqOrder.selector) {
returnResult = _executeFillRfqOrderCall(state);
} else if (state.selector == IMultiplexFeature.multiplexBatchSellTokenForToken.selector) {
returnResult = _executeMultiplexBatchSellTokenForTokenCall(state);
} else if (state.selector == IMultiplexFeature.multiplexBatchSellTokenForEth.selector) {
returnResult = _executeMultiplexBatchSellTokenForEthCall(state);
} else if (state.selector == IMultiplexFeature.multiplexMultiHopSellTokenForToken.selector) {
returnResult = _executeMultiplexMultiHopSellTokenForTokenCall(state);
} else if (state.selector == IMultiplexFeature.multiplexMultiHopSellTokenForEth.selector) {
returnResult = _executeMultiplexMultiHopSellTokenForEthCall(state);
} else {
LibMetaTransactionsRichErrors.MetaTransactionUnsupportedFunctionError(state.hash, state.selector).rrevert();
}
emit MetaTransactionExecuted(state.hash, state.selector, state.mtx.signer, state.mtx.sender);
}
/// @dev Validate that a meta-transaction is executable.
function _validateMetaTransaction(ExecuteState memory state) private view {
// Must be from the required sender, if set.
if (state.mtx.sender != address(0) && state.mtx.sender != state.sender) {
LibMetaTransactionsRichErrors
.MetaTransactionWrongSenderError(state.hash, state.sender, state.mtx.sender)
.rrevert();
}
// Must not be expired.
if (state.mtx.expirationTimeSeconds <= block.timestamp) {
LibMetaTransactionsRichErrors
.MetaTransactionExpiredError(state.hash, block.timestamp, state.mtx.expirationTimeSeconds)
.rrevert();
}
if (LibSignature.getSignerOfHash(state.hash, state.signature) != state.mtx.signer) {
LibSignatureRichErrors
.SignatureValidationError(
LibSignatureRichErrors.SignatureValidationErrorCodes.WRONG_SIGNER,
state.hash,
state.mtx.signer,
// TODO: Remove this field from SignatureValidationError
// when rich reverts are part of the protocol repo.
""
)
.rrevert();
}
// Transaction must not have been already executed.
state.executedBlockNumber = LibMetaTransactionsV2Storage.getStorage().mtxHashToExecutedBlockNumber[state.hash];
if (state.executedBlockNumber != 0) {
LibMetaTransactionsRichErrors
.MetaTransactionAlreadyExecutedError(state.hash, state.executedBlockNumber)
.rrevert();
}
}
/// @dev Execute a `ITransformERC20Feature.transformERC20()` meta-transaction call
/// by decoding the call args and translating the call to the internal
/// `ITransformERC20Feature._transformERC20()` variant, where we can override
/// the taker address.
function _executeTransformERC20Call(ExecuteState memory state) private returns (bytes memory returnResult) {
// HACK(dorothy-zbornak): `abi.decode()` with the individual args
// will cause a stack overflow. But we can prefix the call data with an
// offset to transform it into the encoding for the equivalent single struct arg,
// since decoding a single struct arg consumes far less stack space than
// decoding multiple struct args.
// Where the encoding for multiple args (with the selector ommitted)
// would typically look like:
// | argument | offset |
// |--------------------------|---------|
// | inputToken | 0 |
// | outputToken | 32 |
// | inputTokenAmount | 64 |
// | minOutputTokenAmount | 96 |
// | transformations (offset) | 128 | = 32
// | transformations (data) | 160 |
// We will ABI-decode a single struct arg copy with the layout:
// | argument | offset |
// |--------------------------|---------|
// | (arg 1 offset) | 0 | = 32
// | inputToken | 32 |
// | outputToken | 64 |
// | inputTokenAmount | 96 |
// | minOutputTokenAmount | 128 |
// | transformations (offset) | 160 | = 32
// | transformations (data) | 192 |
ExternalTransformERC20Args memory args;
{
bytes memory encodedStructArgs = new bytes(state.mtx.callData.length - 4 + 32);
// Copy the args data from the original, after the new struct offset prefix.
bytes memory fromCallData = state.mtx.callData;
assert(fromCallData.length >= 160);
uint256 fromMem;
uint256 toMem;
assembly {
// Prefix the calldata with a struct offset,
// which points to just one word over.
mstore(add(encodedStructArgs, 32), 32)
// Copy everything after the selector.
fromMem := add(fromCallData, 36)
// Start copying after the struct offset.
toMem := add(encodedStructArgs, 64)
}
LibBytesV06.memCopy(toMem, fromMem, fromCallData.length - 4);
// Decode call args for `ITransformERC20Feature.transformERC20()` as a struct.
args = abi.decode(encodedStructArgs, (ExternalTransformERC20Args));
}
// Call `ITransformERC20Feature._transformERC20()` (internal variant).
return
_callSelf(
state.hash,
abi.encodeWithSelector(
ITransformERC20Feature._transformERC20.selector,
ITransformERC20Feature.TransformERC20Args({
taker: state.mtx.signer, // taker is mtx signer
inputToken: args.inputToken,
outputToken: args.outputToken,
inputTokenAmount: args.inputTokenAmount,
minOutputTokenAmount: args.minOutputTokenAmount,
transformations: args.transformations,
useSelfBalance: false,
recipient: state.mtx.signer
})
)
);
}
/// @dev Extract arguments from call data by copying everything after the
/// 4-byte selector into a new byte array.
/// @param callData The call data from which arguments are to be extracted.
/// @return args The extracted arguments as a byte array.
function _extractArgumentsFromCallData(bytes memory callData) private pure returns (bytes memory args) {
args = new bytes(callData.length - 4);
uint256 fromMem;
uint256 toMem;
assembly {
fromMem := add(callData, 36) // skip length and 4-byte selector
toMem := add(args, 32) // write after length prefix
}
LibBytesV06.memCopy(toMem, fromMem, args.length);
return args;
}
/// @dev Execute a `INativeOrdersFeature.fillLimitOrder()` meta-transaction call
/// by decoding the call args and translating the call to the internal
/// `INativeOrdersFeature._fillLimitOrder()` variant, where we can override
/// the taker address.
function _executeFillLimitOrderCall(ExecuteState memory state) private returns (bytes memory returnResult) {
LibNativeOrder.LimitOrder memory order;
LibSignature.Signature memory signature;
uint128 takerTokenFillAmount;
bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);
(order, signature, takerTokenFillAmount) = abi.decode(
args,
(LibNativeOrder.LimitOrder, LibSignature.Signature, uint128)
);
return
_callSelf(
state.hash,
abi.encodeWithSelector(
INativeOrdersFeature._fillLimitOrder.selector,
order,
signature,
takerTokenFillAmount,
state.mtx.signer, // taker is mtx signer
msg.sender
)
);
}
/// @dev Execute a `INativeOrdersFeature.fillRfqOrder()` meta-transaction call
/// by decoding the call args and translating the call to the internal
/// `INativeOrdersFeature._fillRfqOrder()` variant, where we can override
/// the taker address.
function _executeFillRfqOrderCall(ExecuteState memory state) private returns (bytes memory returnResult) {
LibNativeOrder.RfqOrder memory order;
LibSignature.Signature memory signature;
uint128 takerTokenFillAmount;
bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);
(order, signature, takerTokenFillAmount) = abi.decode(
args,
(LibNativeOrder.RfqOrder, LibSignature.Signature, uint128)
);
return
_callSelf(
state.hash,
abi.encodeWithSelector(
INativeOrdersFeature._fillRfqOrder.selector,
order,
signature,
takerTokenFillAmount,
state.mtx.signer, // taker is mtx signer
false,
state.mtx.signer
)
);
}
/// @dev Execute a `IMultiplexFeature.multiplexBatchSellTokenForToken()` meta-transaction
/// call by decoding the call args and translating the call to the internal
/// `IMultiplexFeature._multiplexBatchSell()` variant, where we can override the
/// payer address.
function _executeMultiplexBatchSellTokenForTokenCall(
ExecuteState memory state
) private returns (bytes memory returnResult) {
IERC20Token inputToken;
IERC20Token outputToken;
IMultiplexFeature.BatchSellSubcall[] memory calls;
uint256 sellAmount;
uint256 minBuyAmount;
bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);
(inputToken, outputToken, calls, sellAmount, minBuyAmount) = abi.decode(
args,
(IERC20Token, IERC20Token, IMultiplexFeature.BatchSellSubcall[], uint256, uint256)
);
return
_callSelf(
state.hash,
abi.encodeWithSelector(
IMultiplexFeature._multiplexBatchSell.selector,
IMultiplexFeature.BatchSellParams({
inputToken: inputToken,
outputToken: outputToken,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: state.mtx.signer,
payer: state.mtx.signer
}),
minBuyAmount
)
);
}
/// @dev Execute a `IMultiplexFeature.multiplexBatchSellTokenForEth()` meta-transaction
/// call by decoding the call args and translating the call to the internal
/// `IMultiplexFeature._multiplexBatchSellTokenForEth()` variant, where we can override the
/// payer address.
function _executeMultiplexBatchSellTokenForEthCall(
ExecuteState memory state
) private returns (bytes memory returnResult) {
IERC20Token inputToken;
IMultiplexFeature.BatchSellSubcall[] memory calls;
uint256 sellAmount;
uint256 minBuyAmount;
bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);
(inputToken, calls, sellAmount, minBuyAmount) = abi.decode(
args,
(IERC20Token, IMultiplexFeature.BatchSellSubcall[], uint256, uint256)
);
returnResult = _callSelf(
state.hash,
abi.encodeWithSelector(
IMultiplexFeature._multiplexBatchSell.selector,
IMultiplexFeature.BatchSellParams({
inputToken: inputToken,
outputToken: IERC20Token(WETH),
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: address(this),
payer: state.mtx.signer
}),
minBuyAmount
)
);
// Unwrap and transfer WETH
uint256 boughtAmount = abi.decode(returnResult, (uint256));
WETH.withdraw(boughtAmount);
_transferEth(state.mtx.signer, boughtAmount);
}
/// @dev Execute a `IMultiplexFeature.multiplexMultiHopSellTokenForToken()` meta-transaction
/// call by decoding the call args and translating the call to the internal
/// `IMultiplexFeature._multiplexMultiHopSell()` variant, where we can override the
/// payer address.
function _executeMultiplexMultiHopSellTokenForTokenCall(
ExecuteState memory state
) private returns (bytes memory returnResult) {
address[] memory tokens;
IMultiplexFeature.MultiHopSellSubcall[] memory calls;
uint256 sellAmount;
uint256 minBuyAmount;
bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);
(tokens, calls, sellAmount, minBuyAmount) = abi.decode(
args,
(address[], IMultiplexFeature.MultiHopSellSubcall[], uint256, uint256)
);
return
_callSelf(
state.hash,
abi.encodeWithSelector(
IMultiplexFeature._multiplexMultiHopSell.selector,
IMultiplexFeature.MultiHopSellParams({
tokens: tokens,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: state.mtx.signer,
payer: state.mtx.signer
}),
minBuyAmount
)
);
}
/// @dev Execute a `IMultiplexFeature.multiplexMultiHopSellTokenForEth()` meta-transaction
/// call by decoding the call args and translating the call to the internal
/// `IMultiplexFeature._multiplexMultiHopSellTokenForEth()` variant, where we can override the
/// payer address.
function _executeMultiplexMultiHopSellTokenForEthCall(
ExecuteState memory state
) private returns (bytes memory returnResult) {
address[] memory tokens;
IMultiplexFeature.MultiHopSellSubcall[] memory calls;
uint256 sellAmount;
uint256 minBuyAmount;
bytes memory args = _extractArgumentsFromCallData(state.mtx.callData);
(tokens, calls, sellAmount, minBuyAmount) = abi.decode(
args,
(address[], IMultiplexFeature.MultiHopSellSubcall[], uint256, uint256)
);
require(
tokens[tokens.length - 1] == address(WETH),
"MetaTransactionsFeature::multiplexMultiHopSellTokenForEth/NOT_WETH"
);
returnResult = _callSelf(
state.hash,
abi.encodeWithSelector(
IMultiplexFeature._multiplexMultiHopSell.selector,
IMultiplexFeature.MultiHopSellParams({
tokens: tokens,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: address(this),
payer: state.mtx.signer
}),
minBuyAmount
)
);
// Unwrap and transfer WETH
uint256 boughtAmount = abi.decode(returnResult, (uint256));
WETH.withdraw(boughtAmount);
_transferEth(state.mtx.signer, boughtAmount);
}
/// @dev Make an arbitrary internal, meta-transaction call.
/// Warning: Do not let unadulterated `callData` into this function.
function _callSelf(bytes32 hash, bytes memory callData) private returns (bytes memory returnResult) {
bool success;
(success, returnResult) = address(this).call(callData);
if (!success) {
LibMetaTransactionsRichErrors.MetaTransactionCallFailedError(hash, callData, returnResult).rrevert();
}
}
}

View File

@ -70,6 +70,7 @@ contract UniswapV3Feature is IFeature, IUniswapV3Feature, FixinCommon, FixinToke
_registerFeatureFunction(this.sellEthForTokenToUniswapV3.selector);
_registerFeatureFunction(this.sellTokenForEthToUniswapV3.selector);
_registerFeatureFunction(this.sellTokenForTokenToUniswapV3.selector);
_registerFeatureFunction(this._sellTokenForTokenToUniswapV3.selector);
_registerFeatureFunction(this._sellHeldTokenForTokenToUniswapV3.selector);
_registerFeatureFunction(this.uniswapV3SwapCallback.selector);
return LibMigrate.MIGRATE_SUCCESS;
@ -139,6 +140,23 @@ contract UniswapV3Feature is IFeature, IUniswapV3Feature, FixinCommon, FixinToke
buyAmount = _swap(encodedPath, sellAmount, minBuyAmount, msg.sender, _normalizeRecipient(recipient));
}
/// @dev Sell a token for another token directly against uniswap v3. Internal variant.
/// @param encodedPath Uniswap-encoded path.
/// @param sellAmount amount of the first token in the path to sell.
/// @param minBuyAmount Minimum amount of the last token in the path to buy.
/// @param recipient The recipient of the bought tokens. Can be zero for payer.
/// @param payer The address to pull the sold tokens from.
/// @return buyAmount Amount of the last token in the path bought.
function _sellTokenForTokenToUniswapV3(
bytes memory encodedPath,
uint256 sellAmount,
uint256 minBuyAmount,
address recipient,
address payer
) public override onlySelf returns (uint256 buyAmount) {
buyAmount = _swap(encodedPath, sellAmount, minBuyAmount, payer, _normalizeRecipient(recipient, payer));
}
/// @dev Sell a token for another token directly against uniswap v3.
/// Private variant, uses tokens held by `address(this)`.
/// @param encodedPath Uniswap-encoded path.
@ -337,8 +355,16 @@ contract UniswapV3Feature is IFeature, IUniswapV3Feature, FixinCommon, FixinToke
}
}
// Convert null address values to alternative address.
function _normalizeRecipient(
address recipient,
address alternative
) private pure returns (address payable normalizedRecipient) {
return recipient == address(0) ? payable(alternative) : payable(recipient);
}
// Convert null address values to msg.sender.
function _normalizeRecipient(address recipient) private view returns (address payable normalizedRecipient) {
return recipient == address(0) ? msg.sender : payable(recipient);
return _normalizeRecipient(recipient, msg.sender);
}
}

View File

@ -0,0 +1,90 @@
// 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 "@0x/contracts-erc20/src/IERC20Token.sol";
import "../libs/LibSignature.sol";
/// @dev Meta-transactions feature.
interface IMetaTransactionsFeatureV2 {
/// @dev Describes an exchange proxy meta transaction.
struct MetaTransactionFeeData {
// ERC20 fee recipient
address recipient;
// ERC20 fee amount
uint256 amount;
}
struct MetaTransactionDataV2 {
// Signer of meta-transaction. On whose behalf to execute the MTX.
address payable signer;
// Required sender, or NULL for anyone.
address sender;
// MTX is invalid after this time.
uint256 expirationTimeSeconds;
// Nonce to make this MTX unique.
uint256 salt;
// Encoded call data to a function on the exchange proxy.
bytes callData;
// ERC20 fee `signer` pays `sender`.
IERC20Token feeToken;
// ERC20 fees.
MetaTransactionFeeData[] fees;
}
/// @dev Emitted whenever a meta-transaction is executed via
/// `executeMetaTransaction()` or `executeMetaTransactions()`.
/// @param hash The EIP712 hash of the MetaTransactionDataV2 struct.
/// @param selector The selector of the function being executed.
/// @param signer Who to execute the meta-transaction on behalf of.
/// @param sender Who executed the meta-transaction.
event MetaTransactionExecuted(bytes32 hash, bytes4 indexed selector, address signer, address sender);
/// @dev Execute a single meta-transaction.
/// @param mtx The meta-transaction.
/// @param signature The signature by `mtx.signer`.
/// @return returnResult The ABI-encoded result of the underlying call.
function executeMetaTransactionV2(
MetaTransactionDataV2 calldata mtx,
LibSignature.Signature calldata signature
) external returns (bytes memory returnResult);
/// @dev Execute multiple meta-transactions.
/// @param mtxs The meta-transactions.
/// @param signatures The signature by each respective `mtx.signer`.
/// @return returnResults The ABI-encoded results of the underlying calls.
function batchExecuteMetaTransactionsV2(
MetaTransactionDataV2[] calldata mtxs,
LibSignature.Signature[] calldata signatures
) external returns (bytes[] memory returnResults);
/// @dev Get the block at which a meta-transaction has been executed.
/// @param mtx The meta-transaction.
/// @return blockNumber The block height when the meta-transactioin was executed.
function getMetaTransactionV2ExecutedBlock(
MetaTransactionDataV2 calldata mtx
) external view returns (uint256 blockNumber);
/// @dev Get the block at which a meta-transaction hash has been executed.
/// @param mtxHash The EIP712 hash of the MetaTransactionDataV2 struct.
/// @return blockNumber The block height when the meta-transactioin was executed.
function getMetaTransactionV2HashExecutedBlock(bytes32 mtxHash) external view returns (uint256 blockNumber);
/// @dev Get the EIP712 hash of a meta-transaction.
/// @param mtx The meta-transaction.
/// @return mtxHash The EIP712 hash of `mtx`.
function getMetaTransactionV2Hash(MetaTransactionDataV2 calldata mtx) external view returns (bytes32 mtxHash);
}

View File

@ -46,6 +46,8 @@ interface IMultiplexFeature {
bool useSelfBalance;
// The recipient of the bought output tokens.
address recipient;
// The sender of the input tokens.
address payer;
}
// Represents a constituent call of a batch sell.
@ -75,6 +77,8 @@ interface IMultiplexFeature {
bool useSelfBalance;
// The recipient of the bought output tokens.
address recipient;
// The sender of the input tokens.
address payer;
}
// Represents a constituent call of a multi-hop sell.
@ -153,6 +157,17 @@ interface IMultiplexFeature {
uint256 minBuyAmount
) external returns (uint256 boughtAmount);
/// @dev Executes a multiplex BatchSell using the given
/// parameters. Internal only.
/// @param params The parameters for the BatchSell.
/// @param minBuyAmount The minimum amount of `params.outputToken`
/// that must be bought for this function to not revert.
/// @return boughtAmount The amount of `params.outputToken` bought.
function _multiplexBatchSell(
BatchSellParams memory params,
uint256 minBuyAmount
) external returns (uint256 boughtAmount);
/// @dev Sells attached ETH via the given sequence of tokens
/// and calls. `tokens[0]` must be WETH.
/// The last token in `tokens` is the output token that
@ -204,4 +219,15 @@ interface IMultiplexFeature {
uint256 sellAmount,
uint256 minBuyAmount
) external returns (uint256 boughtAmount);
/// @dev Executes a multiplex MultiHopSell using the given
/// parameters. Internal only.
/// @param params The parameters for the MultiHopSell.
/// @param minBuyAmount The minimum amount of the output token
/// that must be bought for this function to not revert.
/// @return boughtAmount The amount of the output token bought.
function _multiplexMultiHopSell(
MultiHopSellParams memory params,
uint256 minBuyAmount
) external returns (uint256 boughtAmount);
}

View File

@ -54,6 +54,21 @@ interface IUniswapV3Feature {
address recipient
) external returns (uint256 buyAmount);
/// @dev Sell a token for another token directly against uniswap v3. Internal variant.
/// @param encodedPath Uniswap-encoded path.
/// @param sellAmount amount of the first token in the path to sell.
/// @param minBuyAmount Minimum amount of the last token in the path to buy.
/// @param recipient The recipient of the bought tokens. Can be zero for payer.
/// @param payer The address to pull the sold tokens from.
/// @return buyAmount Amount of the last token in the path bought.
function _sellTokenForTokenToUniswapV3(
bytes memory encodedPath,
uint256 sellAmount,
uint256 minBuyAmount,
address recipient,
address payer
) external returns (uint256 buyAmount);
/// @dev Sell a token for another token directly against uniswap v3.
/// Private variant, uses tokens held by `address(this)`.
/// @param encodedPath Uniswap-encoded path.

View File

@ -80,9 +80,11 @@ contract MultiplexFeature is
_registerFeatureFunction(this.multiplexBatchSellEthForToken.selector);
_registerFeatureFunction(this.multiplexBatchSellTokenForEth.selector);
_registerFeatureFunction(this.multiplexBatchSellTokenForToken.selector);
_registerFeatureFunction(this._multiplexBatchSell.selector);
_registerFeatureFunction(this.multiplexMultiHopSellEthForToken.selector);
_registerFeatureFunction(this.multiplexMultiHopSellTokenForEth.selector);
_registerFeatureFunction(this.multiplexMultiHopSellTokenForToken.selector);
_registerFeatureFunction(this._multiplexMultiHopSell.selector);
return LibMigrate.MIGRATE_SUCCESS;
}
@ -103,14 +105,15 @@ contract MultiplexFeature is
// WETH is now held by this contract,
// so `useSelfBalance` is true.
return
_multiplexBatchSell(
_multiplexBatchSellPrivate(
BatchSellParams({
inputToken: WETH,
outputToken: outputToken,
sellAmount: msg.value,
calls: calls,
useSelfBalance: true,
recipient: msg.sender
recipient: msg.sender,
payer: msg.sender
}),
minBuyAmount
);
@ -133,14 +136,15 @@ contract MultiplexFeature is
// The outputToken is implicitly WETH. The `recipient`
// of the WETH is set to this contract, since we
// must unwrap the WETH and transfer the resulting ETH.
boughtAmount = _multiplexBatchSell(
boughtAmount = _multiplexBatchSellPrivate(
BatchSellParams({
inputToken: inputToken,
outputToken: WETH,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: address(this)
recipient: address(this),
payer: msg.sender
}),
minBuyAmount
);
@ -167,26 +171,40 @@ contract MultiplexFeature is
uint256 minBuyAmount
) public override returns (uint256 boughtAmount) {
return
_multiplexBatchSell(
_multiplexBatchSellPrivate(
BatchSellParams({
inputToken: inputToken,
outputToken: outputToken,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: msg.sender
recipient: msg.sender,
payer: msg.sender
}),
minBuyAmount
);
}
/// @dev Executes a batch sell and checks that at least
/// `minBuyAmount` of `outputToken` was bought. Internal variant.
/// @param params Batch sell parameters.
/// @param minBuyAmount The minimum amount of `outputToken` that
/// must be bought for this function to not revert.
/// @return boughtAmount The amount of `outputToken` bought.
function _multiplexBatchSell(
BatchSellParams memory params,
uint256 minBuyAmount
) public override onlySelf returns (uint256 boughtAmount) {
return _multiplexBatchSellPrivate(params, minBuyAmount);
}
/// @dev Executes a batch sell and checks that at least
/// `minBuyAmount` of `outputToken` was bought.
/// @param params Batch sell parameters.
/// @param minBuyAmount The minimum amount of `outputToken` that
/// must be bought for this function to not revert.
/// @return boughtAmount The amount of `outputToken` bought.
function _multiplexBatchSell(
function _multiplexBatchSellPrivate(
BatchSellParams memory params,
uint256 minBuyAmount
) private returns (uint256 boughtAmount) {
@ -226,13 +244,14 @@ contract MultiplexFeature is
// WETH is now held by this contract,
// so `useSelfBalance` is true.
return
_multiplexMultiHopSell(
_multiplexMultiHopSellPrivate(
MultiHopSellParams({
tokens: tokens,
sellAmount: msg.value,
calls: calls,
useSelfBalance: true,
recipient: msg.sender
recipient: msg.sender,
payer: msg.sender
}),
minBuyAmount
);
@ -262,13 +281,14 @@ contract MultiplexFeature is
);
// The `recipient of the WETH is set to this contract, since
// we must unwrap the WETH and transfer the resulting ETH.
boughtAmount = _multiplexMultiHopSell(
boughtAmount = _multiplexMultiHopSellPrivate(
MultiHopSellParams({
tokens: tokens,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: address(this)
recipient: address(this),
payer: msg.sender
}),
minBuyAmount
);
@ -297,25 +317,38 @@ contract MultiplexFeature is
uint256 minBuyAmount
) public override returns (uint256 boughtAmount) {
return
_multiplexMultiHopSell(
_multiplexMultiHopSellPrivate(
MultiHopSellParams({
tokens: tokens,
sellAmount: sellAmount,
calls: calls,
useSelfBalance: false,
recipient: msg.sender
recipient: msg.sender,
payer: msg.sender
}),
minBuyAmount
);
}
/// @dev Executes a multi-hop sell. Internal variant.
/// @param params Multi-hop sell parameters.
/// @param minBuyAmount The minimum amount of output tokens that
/// must be bought for this function to not revert.
/// @return boughtAmount The amount of output tokens bought.
function _multiplexMultiHopSell(
MultiHopSellParams memory params,
uint256 minBuyAmount
) public override onlySelf returns (uint256 boughtAmount) {
return _multiplexMultiHopSellPrivate(params, minBuyAmount);
}
/// @dev Executes a multi-hop sell and checks that at least
/// `minBuyAmount` of output tokens were bought.
/// @param params Multi-hop sell parameters.
/// @param minBuyAmount The minimum amount of output tokens that
/// must be bought for this function to not revert.
/// @return boughtAmount The amount of output tokens bought.
function _multiplexMultiHopSell(
function _multiplexMultiHopSellPrivate(
MultiHopSellParams memory params,
uint256 minBuyAmount
) private returns (uint256 boughtAmount) {
@ -387,14 +420,14 @@ contract MultiplexFeature is
// amount of the multi-hop fill.
state.outputTokenAmount = params.sellAmount;
// The first call may expect the input tokens to be held by
// `msg.sender`, `address(this)`, or some other address.
// `payer`, `address(this)`, or some other address.
// Compute the expected address and transfer the input tokens
// there if necessary.
state.from = _computeHopTarget(params, 0);
// If the input tokens are currently held by `msg.sender` but
// If the input tokens are currently held by `payer` but
// the first hop expects them elsewhere, perform a `transferFrom`.
if (!params.useSelfBalance && state.from != msg.sender) {
_transferERC20TokensFrom(IERC20Token(params.tokens[0]), msg.sender, state.from, params.sellAmount);
if (!params.useSelfBalance && state.from != params.payer) {
_transferERC20TokensFrom(IERC20Token(params.tokens[0]), params.payer, state.from, params.sellAmount);
}
// If the input tokens are currently held by `address(this)` but
// the first hop expects them elsewhere, perform a `transfer`.
@ -411,11 +444,13 @@ contract MultiplexFeature is
if (subcall.id == MultiplexSubcall.UniswapV2) {
_multiHopSellUniswapV2(state, params, subcall.data);
} else if (subcall.id == MultiplexSubcall.UniswapV3) {
_multiHopSellUniswapV3(state, subcall.data);
_multiHopSellUniswapV3(state, params, subcall.data);
} else if (subcall.id == MultiplexSubcall.LiquidityProvider) {
_multiHopSellLiquidityProvider(state, params, subcall.data);
} else if (subcall.id == MultiplexSubcall.BatchSell) {
_nestedBatchSell(state, params, subcall.data);
} else if (subcall.id == MultiplexSubcall.OTC) {
_multiHopSellOtcOrder(state, params, subcall.data);
} else {
revert("MultiplexFeature::_executeMultiHopSell/INVALID_SUBCALL");
}
@ -443,6 +478,8 @@ contract MultiplexFeature is
// Likewise, the recipient of the multi-hop sell is
// equal to the recipient of its containing batch sell.
multiHopParams.recipient = params.recipient;
// The payer is the same too.
multiHopParams.payer = params.payer;
// Execute the nested multi-hop sell.
uint256 outputTokenAmount = _executeMultiHopSell(multiHopParams).outputTokenAmount;
// Increment the sold and bought amounts.
@ -469,7 +506,7 @@ contract MultiplexFeature is
// If the nested batch sell is the first hop
// and `useSelfBalance` for the containing multi-
// hop sell is false, the nested batch sell should
// pull tokens from `msg.sender` (so `batchSellParams.useSelfBalance`
// pull tokens from `payer` (so `batchSellParams.useSelfBalance`
// should be false). Otherwise `batchSellParams.useSelfBalance`
// should be true.
batchSellParams.useSelfBalance = state.hopIndex > 0 || params.useSelfBalance;
@ -477,6 +514,8 @@ contract MultiplexFeature is
// that should receive the output tokens of the
// batch sell.
batchSellParams.recipient = state.to;
// payer shound be the same too.
batchSellParams.payer = params.payer;
// Execute the nested batch sell.
state.outputTokenAmount = _executeBatchSell(batchSellParams).boughtAmount;
}
@ -505,29 +544,33 @@ contract MultiplexFeature is
// is executed, so we the target is the address encoded
// in the subcall data.
(target, ) = abi.decode(subcall.data, (address, bytes));
} else if (subcall.id == MultiplexSubcall.UniswapV3 || subcall.id == MultiplexSubcall.BatchSell) {
} else if (
subcall.id == MultiplexSubcall.UniswapV3 ||
subcall.id == MultiplexSubcall.BatchSell ||
subcall.id == MultiplexSubcall.OTC
) {
// UniswapV3 uses a callback to pull in the tokens being
// sold to it. The callback implemented in `UniswapV3Feature`
// can either:
// - call `transferFrom` to move tokens from `msg.sender` to the
// - call `transferFrom` to move tokens from `payer` to the
// UniswapV3 pool, or
// - call `transfer` to move tokens from `address(this)` to the
// UniswapV3 pool.
// A nested batch sell is similar, in that it can either:
// - use tokens from `msg.sender`, or
// - use tokens from `payer`, or
// - use tokens held by `address(this)`.
// Suppose UniswapV3/BatchSell is the first call in the multi-hop
// path. The input tokens are either held by `msg.sender`,
// path. The input tokens are either held by `payer`,
// or in the case of `multiplexMultiHopSellEthForToken` WETH is
// held by `address(this)`. The target is set accordingly.
// If this is _not_ the first call in the multi-hop path, we
// are dealing with an "intermediate" token in the multi-hop path,
// which `msg.sender` may not have an allowance set for. Thus
// which `payer` may not have an allowance set for. Thus
// target must be set to `address(this)` for `i > 0`.
if (i == 0 && !params.useSelfBalance) {
target = msg.sender;
target = params.payer;
} else {
target = address(this);
}

View File

@ -67,7 +67,7 @@ abstract contract MultiplexLiquidityProvider is FixinCommon, FixinTokenSpender {
_transferERC20Tokens(params.inputToken, provider, sellAmount);
} else {
// Otherwise, transfer the input tokens from `msg.sender`.
_transferERC20TokensFrom(params.inputToken, msg.sender, provider, sellAmount);
_transferERC20TokensFrom(params.inputToken, params.payer, provider, sellAmount);
}
// Cache the recipient's balance of the output token.
uint256 balanceBefore = params.outputToken.balanceOf(params.recipient);

View File

@ -55,7 +55,7 @@ abstract contract MultiplexOtc is FixinEIP712 {
order,
signature,
sellAmount.safeDowncastToUint128(),
msg.sender,
params.payer,
params.useSelfBalance,
params.recipient
)
@ -65,4 +65,34 @@ abstract contract MultiplexOtc is FixinEIP712 {
state.boughtAmount = state.boughtAmount.safeAdd(makerTokenFilledAmount);
} catch {}
}
function _multiHopSellOtcOrder(
IMultiplexFeature.MultiHopSellState memory state,
IMultiplexFeature.MultiHopSellParams memory params,
bytes memory wrappedCallData
) internal {
// Decode the Otc order, and signature.
(LibNativeOrder.OtcOrder memory order, LibSignature.Signature memory signature) = abi.decode(
wrappedCallData,
(LibNativeOrder.OtcOrder, LibSignature.Signature)
);
//Make sure that the otc orders maker and taker tokens match the fill sequence in params.tokens[]
require(
address(order.takerToken) == params.tokens[state.hopIndex] &&
address(order.makerToken) == params.tokens[state.hopIndex + 1],
"MultiplexOtcOrder::_multiHopSellOtcOrder/INVALID_TOKENS"
);
// Try filling the Otc order. Bubble up reverts.
(uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount) = IOtcOrdersFeature(address(this))
._fillOtcOrder(
order,
signature,
state.outputTokenAmount.safeDowncastToUint128(),
state.from,
params.useSelfBalance,
state.to
);
//store the bought amount for the next hop
state.outputTokenAmount = makerTokenFilledAmount;
}
}

View File

@ -54,7 +54,7 @@ abstract contract MultiplexRfq is FixinEIP712 {
order,
signature,
sellAmount.safeDowncastToUint128(),
msg.sender,
params.payer,
params.useSelfBalance,
params.recipient
)

View File

@ -30,8 +30,8 @@ abstract contract MultiplexTransformERC20 {
) internal {
ITransformERC20Feature.TransformERC20Args memory args;
// We want the TransformedERC20 event to have
// `msg.sender` as the taker.
args.taker = msg.sender;
// `payer` as the taker.
args.taker = payable(params.payer);
args.inputToken = params.inputToken;
args.outputToken = params.outputToken;
args.inputTokenAmount = sellAmount;

View File

@ -77,7 +77,7 @@ abstract contract MultiplexUniswapV2 is FixinCommon, FixinTokenSpender {
if (params.useSelfBalance) {
_transferERC20Tokens(IERC20Token(tokens[0]), firstPairAddress, sellAmount);
} else {
_transferERC20TokensFrom(IERC20Token(tokens[0]), msg.sender, firstPairAddress, sellAmount);
_transferERC20TokensFrom(IERC20Token(tokens[0]), params.payer, firstPairAddress, sellAmount);
}
// Execute the Uniswap/Sushiswap trade.
return _sellToUniswapV2(tokens, sellAmount, isSushi, firstPairAddress, params.recipient);

View File

@ -45,16 +45,16 @@ abstract contract MultiplexUniswapV3 is FixinTokenSpender {
)
);
} else {
// Otherwise, we self-delegatecall the normal variant
// `sellTokenForTokenToUniswapV3`, which pulls the input token
// from `msg.sender`.
(success, resultData) = address(this).delegatecall(
// Otherwise, we self-call `_sellTokenForTokenToUniswapV3`,
// which pulls the input token from a specified `payer`.
(success, resultData) = address(this).call(
abi.encodeWithSelector(
IUniswapV3Feature.sellTokenForTokenToUniswapV3.selector,
IUniswapV3Feature._sellTokenForTokenToUniswapV3.selector,
wrappedCallData,
sellAmount,
0,
params.recipient
params.recipient,
params.payer
)
);
}
@ -69,6 +69,7 @@ abstract contract MultiplexUniswapV3 is FixinTokenSpender {
function _multiHopSellUniswapV3(
IMultiplexFeature.MultiHopSellState memory state,
IMultiplexFeature.MultiHopSellParams memory params,
bytes memory wrappedCallData
) internal {
bool success;
@ -87,16 +88,16 @@ abstract contract MultiplexUniswapV3 is FixinTokenSpender {
)
);
} else {
// Otherwise, we self-delegatecall the normal variant
// `sellTokenForTokenToUniswapV3`, which pulls the input token
// from `msg.sender`.
(success, resultData) = address(this).delegatecall(
// Otherwise, we self-call `_sellTokenForTokenToUniswapV3`,
// which pulls the input token from `payer`.
(success, resultData) = address(this).call(
abi.encodeWithSelector(
IUniswapV3Feature.sellTokenForTokenToUniswapV3.selector,
IUniswapV3Feature._sellTokenForTokenToUniswapV3.selector,
wrappedCallData,
state.outputTokenAmount,
0,
state.to
state.to,
params.payer
)
);
}

View File

@ -0,0 +1,38 @@
// 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 "./LibStorage.sol";
/// @dev Storage helpers for the `MetaTransactions` feature.
library LibMetaTransactionsV2Storage {
/// @dev Storage bucket for this feature.
struct Storage {
// The block number when a hash was executed.
mapping(bytes32 => uint256) mtxHashToExecutedBlockNumber;
}
/// @dev Get the storage bucket for this contract.
function getStorage() internal pure returns (Storage storage stor) {
uint256 storageSlot = LibStorage.getStorageSlot(LibStorage.StorageId.MetaTransactionsV2);
// Dip into assembly to change the slot pointed to by the local variable `stor`.
// solhint-disable-next-line max-line-length
// See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries
assembly {
stor_slot := storageSlot
}
}
}

View File

@ -34,7 +34,8 @@ library LibStorage {
NativeOrders,
OtcOrders,
ERC721Orders,
ERC1155Orders
ERC1155Orders,
MetaTransactionsV2
}
/// @dev Get the storage slot given a storage ID. We assign unique, well-spaced slots to storage bucket variables

View File

@ -23,12 +23,14 @@ abstract contract AbstractBridgeAdapter is IBridgeAdapter {
assembly {
chainId := chainid()
}
// Skip chain id validation on Ganache (1337), Anvil (31337), Goerli (5), Mumbai (80001), Base Goerli (84531)
// Skip chain id validation on Ganache (1337), Anvil (31337), Goerli (5), Mumbai (80001), Base Goerli (84531),
// Sepolia (11155111)
bool skipValidation = (chainId == 1337 ||
chainId == 31337 ||
chainId == 5 ||
chainId == 80001 ||
chainId == 84531);
chainId == 84531 ||
chainId == 11155111);
if (chainId != expectedChainId && !skipValidation) {
revert(string(abi.encodePacked(expectedChainName, "BridgeAdapter.constructor: wrong chain ID")));

View File

@ -26,6 +26,7 @@ import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinKyberElastic.sol";
import "./mixins/MixinGMX.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinTraderJoeV2.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinWOOFi.sol";
@ -42,6 +43,7 @@ contract ArbitrumBridgeAdapter is
MixinKyberElastic,
MixinGMX,
MixinNerve,
MixinTraderJoeV2,
MixinUniswapV3,
MixinUniswapV2,
MixinWOOFi,
@ -97,6 +99,11 @@ contract ArbitrumBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.TRADERJOEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeTraderJoeV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.GMX) {
if (dryRun) {
return (0, true);

View File

@ -26,7 +26,9 @@ import "./mixins/MixinKyberElastic.sol";
import "./mixins/MixinAaveV2.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinPlatypus.sol";
import "./mixins/MixinTraderJoeV2.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
@ -41,7 +43,9 @@ contract AvalancheBridgeAdapter is
MixinAaveV2,
MixinNerve,
MixinPlatypus,
MixinTraderJoeV2,
MixinUniswapV2,
MixinUniswapV3,
MixinWOOFi,
MixinZeroExBridge
{
@ -70,6 +74,11 @@ contract AvalancheBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
@ -100,6 +109,11 @@ contract AvalancheBridgeAdapter is
return (0, true);
}
boughtAmount = _tradePlatypus(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.TRADERJOEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeTraderJoeV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.WOOFI) {
if (dryRun) {
return (0, true);

View File

@ -22,9 +22,11 @@ import "./mixins/MixinDodo.sol";
import "./mixins/MixinDodoV2.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinKyberElastic.sol";
import "./mixins/MixinMaverickV1.sol";
import "./mixins/MixinMooniswap.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
@ -35,9 +37,11 @@ contract BSCBridgeAdapter is
MixinDodoV2,
MixinKyberDmm,
MixinKyberElastic,
MixinMaverickV1,
MixinMooniswap,
MixinNerve,
MixinUniswapV2,
MixinUniswapV3,
MixinWOOFi,
MixinZeroExBridge
{
@ -61,6 +65,11 @@ contract BSCBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MOONISWAP) {
if (dryRun) {
return (0, true);
@ -96,6 +105,11 @@ contract BSCBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeWOOFi(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MAVERICKV1) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMaverickV1(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);

View File

@ -0,0 +1,93 @@
// 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 "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinUniswapV2.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
import "./mixins/MixinMaverickV1.sol";
import "./mixins/MixinSolidly.sol";
import "./mixins/MixinVelodromeV2.sol";
contract BaseBridgeAdapter is
AbstractBridgeAdapter(8453, "Base"),
MixinUniswapV3,
MixinUniswapV2,
MixinBalancerV2Batch,
MixinCurve,
MixinCurveV2,
MixinMaverickV1,
MixinSolidly,
MixinVelodromeV2
{
constructor(IEtherToken weth) public MixinCurve(weth) {}
function _trade(
BridgeOrder memory order,
IERC20Token sellToken,
IERC20Token buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.CURVE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurve(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.CURVEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeCurveV2(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SOLIDLY) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeSolidly(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BALANCERV2BATCH) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MAVERICKV1) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMaverickV1(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.VELODROMEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeVelodromeV2(sellToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@ -0,0 +1,45 @@
// 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 "./AbstractBridgeAdapter.sol";
import "./BridgeProtocols.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinUniswapV2.sol";
contract BaseGoerliBridgeAdapter is AbstractBridgeAdapter(84531, "Base Goerli"), MixinUniswapV3, MixinUniswapV2 {
function _trade(
BridgeOrder memory order,
IERC20Token sellToken,
IERC20Token buyToken,
uint256 sellAmount,
bool dryRun
) internal override returns (uint256 boughtAmount, bool supportedSource) {
uint128 protocolId = uint128(uint256(order.source) >> 128);
if (protocolId == BridgeProtocols.UNISWAPV3) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV3(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNISWAPV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeUniswapV2(buyToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);
}
}

View File

@ -55,4 +55,8 @@ library BridgeProtocols {
uint128 internal constant WOOFI = 31;
uint128 internal constant AAVEV3 = 32;
uint128 internal constant KYBERELASTIC = 33;
uint128 internal constant BARTER = 34;
uint128 internal constant TRADERJOEV2 = 35;
uint128 internal constant VELODROMEV2 = 36;
uint128 internal constant MAVERICKV1 = 37;
}

View File

@ -20,8 +20,8 @@ import "./BridgeProtocols.sol";
import "./mixins/MixinAaveV2.sol";
import "./mixins/MixinBalancer.sol";
import "./mixins/MixinBalancerV2Batch.sol";
import "./mixins/MixinBancor.sol";
import "./mixins/MixinBancorV3.sol";
import "./mixins/MixinBarter.sol";
import "./mixins/MixinCompound.sol";
import "./mixins/MixinCurve.sol";
import "./mixins/MixinCurveV2.sol";
@ -32,9 +32,8 @@ import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinKyberElastic.sol";
import "./mixins/MixinLido.sol";
import "./mixins/MixinMakerPSM.sol";
import "./mixins/MixinMStable.sol";
import "./mixins/MixinMaverickV1.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinShell.sol";
import "./mixins/MixinSynthetix.sol";
import "./mixins/MixinUniswap.sol";
import "./mixins/MixinUniswapV2.sol";
@ -46,8 +45,8 @@ contract EthereumBridgeAdapter is
MixinAaveV2,
MixinBalancer,
MixinBalancerV2Batch,
MixinBancor,
MixinBancorV3,
MixinBarter,
MixinCompound,
MixinCurve,
MixinCurveV2,
@ -58,9 +57,8 @@ contract EthereumBridgeAdapter is
MixinKyberElastic,
MixinLido,
MixinMakerPSM,
MixinMStable,
MixinMaverickV1,
MixinNerve,
MixinShell,
MixinSynthetix,
MixinUniswap,
MixinUniswapV2,
@ -69,15 +67,7 @@ contract EthereumBridgeAdapter is
{
constructor(
IEtherToken weth
)
public
MixinBancor(weth)
MixinBancorV3(weth)
MixinCompound(weth)
MixinCurve(weth)
MixinLido(weth)
MixinUniswap(weth)
{}
) public MixinBancorV3(weth) MixinCompound(weth) MixinCurve(weth) MixinLido(weth) MixinUniswap(weth) {}
function _trade(
BridgeOrder memory order,
@ -127,16 +117,6 @@ contract EthereumBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeMakerPsm(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MSTABLE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMStable(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.SHELL) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeShell(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODO) {
if (dryRun) {
return (0, true);
@ -152,11 +132,6 @@ contract EthereumBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeCryptoCom(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BANCOR) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBancor(buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.NERVE) {
if (dryRun) {
return (0, true);
@ -197,6 +172,16 @@ contract EthereumBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeSynthetix(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.BARTER) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeBarter(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MAVERICKV1) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMaverickV1(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.UNKNOWN) {
if (dryRun) {
return (0, true);

View File

@ -26,6 +26,7 @@ import "./mixins/MixinNerve.sol";
import "./mixins/MixinSolidly.sol";
import "./mixins/MixinSynthetix.sol";
import "./mixins/MixinUniswapV3.sol";
import "./mixins/MixinVelodromeV2.sol";
import "./mixins/MixinWOOFi.sol";
import "./mixins/MixinZeroExBridge.sol";
@ -39,6 +40,7 @@ contract OptimismBridgeAdapter is
MixinNerve,
MixinSynthetix,
MixinUniswapV3,
MixinVelodromeV2,
MixinSolidly,
MixinWOOFi,
MixinZeroExBridge
@ -109,6 +111,11 @@ contract OptimismBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeKyberElastic(sellToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.VELODROMEV2) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeVelodromeV2(sellToken, sellAmount, order.bridgeData);
}
emit BridgeFill(order.source, sellToken, buyToken, sellAmount, boughtAmount);

View File

@ -26,7 +26,6 @@ import "./mixins/MixinDodo.sol";
import "./mixins/MixinDodoV2.sol";
import "./mixins/MixinKyberDmm.sol";
import "./mixins/MixinKyberElastic.sol";
import "./mixins/MixinMStable.sol";
import "./mixins/MixinNerve.sol";
import "./mixins/MixinSolidly.sol";
import "./mixins/MixinUniswapV2.sol";
@ -45,7 +44,6 @@ contract PolygonBridgeAdapter is
MixinDodoV2,
MixinKyberDmm,
MixinKyberElastic,
MixinMStable,
MixinNerve,
MixinUniswapV2,
MixinUniswapV3,
@ -88,11 +86,6 @@ contract PolygonBridgeAdapter is
return (0, true);
}
boughtAmount = _tradeBalancerV2Batch(sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.MSTABLE) {
if (dryRun) {
return (0, true);
}
boughtAmount = _tradeMStable(sellToken, buyToken, sellAmount, order.bridgeData);
} else if (protocolId == BridgeProtocols.DODO) {
if (dryRun) {
return (0, true);

View File

@ -1,93 +0,0 @@
// 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 "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/src/IERC20Token.sol";
import "@0x/contracts-erc20/src/IEtherToken.sol";
import "../IBridgeAdapter.sol";
interface IBancorNetwork {
function convertByPath(
IERC20Token[] calldata _path,
uint256 _amount,
uint256 _minReturn,
address _beneficiary,
address _affiliateAccount,
uint256 _affiliateFee
) external payable returns (uint256);
}
contract MixinBancor {
/// @dev Bancor ETH pseudo-address.
IERC20Token public constant BANCOR_ETH_ADDRESS = IERC20Token(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
IEtherToken private immutable WETH;
constructor(IEtherToken weth) public {
WETH = weth;
}
function _tradeBancor(
IERC20Token buyToken,
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256 boughtAmount) {
// Decode the bridge data.
IBancorNetwork bancorNetworkAddress;
IERC20Token[] memory path;
{
address[] memory _path;
(bancorNetworkAddress, _path) = abi.decode(bridgeData, (IBancorNetwork, address[]));
// To get around `abi.decode()` not supporting interface array types.
assembly {
path := _path
}
}
require(path.length >= 2, "MixinBancor/PATH_LENGTH_MUST_BE_AT_LEAST_TWO");
require(
path[path.length - 1] == buyToken || (path[path.length - 1] == BANCOR_ETH_ADDRESS && buyToken == WETH),
"MixinBancor/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN"
);
uint256 payableAmount = 0;
// If it's ETH in the path then withdraw from WETH
// The Bancor path will have ETH as the 0xeee address
// Bancor expects to be paid in ETH not WETH
if (path[0] == BANCOR_ETH_ADDRESS) {
WETH.withdraw(sellAmount);
payableAmount = sellAmount;
} else {
// Grant an allowance to the Bancor Network.
LibERC20TokenV06.approveIfBelow(path[0], address(bancorNetworkAddress), sellAmount);
}
// Convert the tokens
boughtAmount = bancorNetworkAddress.convertByPath{value: payableAmount}(
path, // path originating with source token and terminating in destination token
sellAmount, // amount of source token to trade
1, // minimum amount of destination token expected to receive
address(this), // beneficiary
address(0), // affiliateAccount; no fee paid
0 // affiliateFee; no fee paid
);
if (path[path.length - 1] == BANCOR_ETH_ADDRESS) {
WETH.deposit{value: boughtAmount}();
}
return boughtAmount;
}
}

View File

@ -17,41 +17,25 @@ pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/src/IERC20Token.sol";
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
interface IShell {
function originSwap(
IERC20Token from,
IERC20Token to,
uint256 fromAmount,
uint256 minTargetAmount,
uint256 deadline
) external returns (uint256 toAmount);
}
contract MixinShell {
contract MixinBarter {
using LibERC20TokenV06 for IERC20Token;
using LibRichErrorsV06 for bytes;
function _tradeShell(
function _tradeBarter(
IERC20Token sellToken,
IERC20Token buyToken,
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256 boughtAmount) {
IShell pool = abi.decode(bridgeData, (IShell));
(address barterRouter, bytes memory data) = abi.decode(bridgeData, (address, bytes));
sellToken.approveIfBelow(barterRouter, sellAmount);
// Grant the Shell contract an allowance to sell the first token.
IERC20Token(sellToken).approveIfBelow(address(pool), sellAmount);
(bool success, bytes memory resultData) = barterRouter.call(data);
if (!success) {
resultData.rrevert();
}
boughtAmount = pool.originSwap(
sellToken,
buyToken,
// Sell all tokens we hold.
sellAmount,
// Minimum buy amount.
1,
// deadline
block.timestamp + 1
);
return boughtAmount;
return abi.decode(resultData, (uint256));
}
}

View File

@ -0,0 +1,63 @@
// 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 "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/src/IERC20Token.sol";
interface IMaverickV1Router {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
address pool;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint256 sqrtPriceLimitD18;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
}
contract MixinMaverickV1 {
using LibERC20TokenV06 for IERC20Token;
function _tradeMaverickV1(
IERC20Token sellToken,
IERC20Token buyToken,
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256 boughtAmount) {
(IMaverickV1Router router, address pool) = abi.decode(bridgeData, (IMaverickV1Router, address));
// Grant the MaverickV1 router an allowance to sell the sellToken
sellToken.approveIfBelow(address(router), sellAmount);
boughtAmount = router.exactInputSingle(
IMaverickV1Router.ExactInputSingleParams({
tokenIn: address(sellToken),
tokenOut: address(buyToken),
pool: pool,
recipient: address(this),
deadline: block.timestamp,
amountIn: sellAmount,
amountOutMinimum: 1,
sqrtPriceLimitD18: 0
})
);
}
}

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.6.5;
pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/src/IERC20Token.sol";
import "../IBridgeAdapter.sol";
interface ILBRouter {
/**
* @dev This enum represents the version of the pair requested
* - V1: Joe V1 pair
* - V2: LB pair V2. Also called legacyPair
* - V2_1: LB pair V2.1 (current version)
*/
enum Version {
V1,
V2,
V2_1
}
/**
* @dev The path parameters, such as:
* - pairBinSteps: The list of bin steps of the pairs to go through
* - versions: The list of versions of the pairs to go through
* - tokenPath: The list of tokens in the path to go through
*/
struct Path {
uint256[] pairBinSteps;
Version[] versions;
IERC20Token[] tokenPath;
}
/**
* @notice Swaps exact tokens for tokens while performing safety checks
* @param amountIn The amount of token to send
* @param amountOutMin The min amount of token to receive
* @param path The path of the swap
* @param to The address of the recipient
* @param deadline The deadline of the tx
* @return amountOut Output amount of the swap
*/
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
Path memory path,
address to,
uint256 deadline
) external returns (uint256 amountOut);
}
contract MixinTraderJoeV2 {
using LibERC20TokenV06 for IERC20Token;
function _tradeTraderJoeV2(
IERC20Token buyToken,
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256 boughtAmount) {
ILBRouter router;
IERC20Token[] memory tokenPath;
uint256[] memory pairBinSteps;
ILBRouter.Version[] memory versions;
{
address[] memory _tokenPath;
(router, _tokenPath, pairBinSteps, versions) = abi.decode(
bridgeData,
(ILBRouter, address[], uint256[], ILBRouter.Version[])
);
// To get around `abi.decode()` not supporting interface array types.
assembly {
tokenPath := _tokenPath
}
}
require(tokenPath.length >= 2, "MixinTraderJoeV2/PATH_LENGTH_MUST_BE_AT_LEAST_TWO");
require(
tokenPath.length == pairBinSteps.length + 1,
"MixinTraderJoeV2/PAIR_BIN_STEPS_LENGTH_MUST_BE_ONE_LESS_THAN_TOKEN_PATH_LENGTH"
);
require(
versions.length == pairBinSteps.length,
"MixinTraderJoeV2/VERSIONS_LENGTH_MUST_BE_EQUAL_TO_PAIR_BIN_STEPS_LENGTH"
);
require(
tokenPath[tokenPath.length - 1] == buyToken,
"MixinTraderJoeV2/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN"
);
// Grant the Trader Joe V2 router an allowance to sell the first token.
tokenPath[0].approveIfBelow(address(router), sellAmount);
ILBRouter.Path memory path = ILBRouter.Path({
pairBinSteps: pairBinSteps,
versions: versions,
tokenPath: tokenPath
});
boughtAmount = router.swapExactTokensForTokens(sellAmount, 1, path, address(this), block.timestamp);
}
}

View File

@ -31,6 +31,18 @@ interface IUniswapV3Router {
function exactInput(ExactInputParams memory params) external payable returns (uint256 amountOut);
}
// https://github.com/Uniswap/swap-router-contracts/blob/main/contracts/interfaces/IV3SwapRouter.sol
interface IUniswapV3Router2 {
struct ExactInputParams {
bytes path;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInput(ExactInputParams memory params) external payable returns (uint256 amountOut);
}
contract MixinUniswapV3 {
using LibERC20TokenV06 for IERC20Token;
@ -39,19 +51,30 @@ contract MixinUniswapV3 {
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256 boughtAmount) {
(IUniswapV3Router router, bytes memory path) = abi.decode(bridgeData, (IUniswapV3Router, bytes));
(address router, bytes memory path, uint256 routerVersion) = abi.decode(bridgeData, (address, bytes, uint256));
// Grant the Uniswap router an allowance to sell the sell token.
sellToken.approveIfBelow(address(router), sellAmount);
sellToken.approveIfBelow(router, sellAmount);
boughtAmount = router.exactInput(
IUniswapV3Router.ExactInputParams({
path: path,
recipient: address(this),
deadline: block.timestamp,
amountIn: sellAmount,
amountOutMinimum: 1
})
);
if (routerVersion != 2) {
boughtAmount = IUniswapV3Router(router).exactInput(
IUniswapV3Router.ExactInputParams({
path: path,
recipient: address(this),
deadline: block.timestamp,
amountIn: sellAmount,
amountOutMinimum: 1
})
);
} else {
boughtAmount = IUniswapV3Router2(router).exactInput(
IUniswapV3Router2.ExactInputParams({
path: path,
recipient: address(this),
amountIn: sellAmount,
amountOutMinimum: 1
})
);
}
}
}

View File

@ -0,0 +1,69 @@
// 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 "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/src/IERC20Token.sol";
interface IVelodromeV2Router {
struct Route {
address from;
address to;
bool stable;
address factory;
}
/// @notice Swap one token for another
/// @param amountIn Amount of token in
/// @param amountOutMin Minimum amount of desired token received
/// @param routes Array of trade routes used in the swap
/// @param to Recipient of the tokens received
/// @param deadline Deadline to receive tokens
/// @return amounts Array of amounts returned per route
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
Route[] calldata routes,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
contract MixinVelodromeV2 {
using LibERC20TokenV06 for IERC20Token;
function _tradeVelodromeV2(
IERC20Token sellToken,
uint256 sellAmount,
bytes memory bridgeData
) internal returns (uint256 boughtAmount) {
(IVelodromeV2Router router, IVelodromeV2Router.Route[] memory routes) = abi.decode(
bridgeData,
(IVelodromeV2Router, IVelodromeV2Router.Route[])
);
sellToken.approveIfBelow(address(router), sellAmount);
uint256[] memory amounts = router.swapExactTokensForTokens(
sellAmount,
1,
routes,
address(this),
block.timestamp + 1
);
return amounts[amounts.length - 1];
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@0x/contracts-zero-ex",
"version": "0.39.1",
"version": "0.49.0",
"engines": {
"node": ">=6.12"
},
@ -36,9 +36,9 @@
"typechain": "typechain --target=ethers-v5 --out-dir='typechain-wrappers' './foundry-artifacts/**/*.json'"
},
"config": {
"publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature,AvalancheBridgeAdapter,BSCBridgeAdapter,CeloBridgeAdapter,EthereumBridgeAdapter,FantomBridgeAdapter,OptimismBridgeAdapter,PolygonBridgeAdapter",
"publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature,AvalancheBridgeAdapter,BaseGoerliBridgeAdapter,BaseBridgeAdapter,BSCBridgeAdapter,CeloBridgeAdapter,EthereumBridgeAdapter,FantomBridgeAdapter,OptimismBridgeAdapter,PolygonBridgeAdapter,MetaTransactionsFeatureV2",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
"abis": "./test/generated-artifacts/@(AbstractBridgeAdapter|AffiliateFeeTransformer|ArbitrumBridgeAdapter|AvalancheBridgeAdapter|BSCBridgeAdapter|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeProtocols|CeloBridgeAdapter|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|EthereumBridgeAdapter|FantomBridgeAdapter|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2Batch|MixinBancor|MixinBancorV3|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinGMX|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinPlatypus|MixinShell|MixinSolidly|MixinSynthetix|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OptimismBridgeAdapter|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PolygonBridgeAdapter|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json"
"abis": "./test/generated-artifacts/@(AbstractBridgeAdapter|AffiliateFeeTransformer|ArbitrumBridgeAdapter|AvalancheBridgeAdapter|BSCBridgeAdapter|BaseBridgeAdapter|BaseGoerliBridgeAdapter|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeProtocols|CeloBridgeAdapter|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|EthereumBridgeAdapter|FantomBridgeAdapter|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMetaTransactionsFeatureV2|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MetaTransactionsFeatureV2|MixinAaveV2|MixinBalancer|MixinBalancerV2Batch|MixinBancorV3|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinGMX|MixinKyberDmm|MixinLido|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinPlatypus|MixinSolidly|MixinSynthetix|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OptimismBridgeAdapter|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PolygonBridgeAdapter|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json"
},
"repository": {
"type": "git",
@ -50,12 +50,12 @@
},
"homepage": "https://github.com/0xProject/protocol/tree/main/contracts/zero-ex",
"devDependencies": {
"@0x/abi-gen": "^5.8.1",
"@0x/contract-addresses": "^8.2.0",
"@0x/abi-gen": "^5.8.5",
"@0x/contract-addresses": "^8.13.0",
"@0x/contracts-erc20": "^3.3.57",
"@0x/contracts-gen": "^2.0.48",
"@0x/contracts-test-utils": "^5.4.49",
"@0x/dev-utils": "^5.0.0",
"@0x/contracts-gen": "^2.0.50",
"@0x/contracts-test-utils": "^5.4.60",
"@0x/dev-utils": "^5.0.2",
"@0x/order-utils": "^10.4.28",
"@0x/sol-compiler": "^4.8.2",
"@0x/ts-doc-gen": "^0.0.28",
@ -80,12 +80,12 @@
},
"dependencies": {
"@0x/base-contract": "^7.0.0",
"@0x/protocol-utils": "^11.18.1",
"@0x/subproviders": "^7.0.0",
"@0x/types": "^3.3.6",
"@0x/protocol-utils": "^11.24.2",
"@0x/subproviders": "^8.0.1",
"@0x/types": "^3.3.7",
"@0x/typescript-typings": "^5.3.1",
"@0x/utils": "^7.0.0",
"@0x/web3-wrapper": "^8.0.0",
"@0x/web3-wrapper": "^8.0.1",
"ethereum-types": "^3.7.1",
"ethereumjs-util": "^7.0.10",
"ethers": "~4.0.4"

View File

@ -1,9 +1,9 @@
import { getContractAddressesForChainOrThrow } from '@0x/contract-addresses';
import { constants } from '@0x/contracts-test-utils';
import { RPCSubprovider, SupportedProvider, Web3ProviderEngine } from '@0x/subproviders';
import { RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { AbiEncoder, BigNumber, logUtils, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { MethodAbi } from 'ethereum-types';
import { MethodAbi, SupportedProvider } from 'ethereum-types';
import * as fetch from 'isomorphic-fetch';
import * as _ from 'lodash';
import * as prompts from 'prompts';

View File

@ -7,6 +7,8 @@ import { ContractArtifact } from 'ethereum-types';
import * as AffiliateFeeTransformer from '../generated-artifacts/AffiliateFeeTransformer.json';
import * as AvalancheBridgeAdapter from '../generated-artifacts/AvalancheBridgeAdapter.json';
import * as BaseBridgeAdapter from '../generated-artifacts/BaseBridgeAdapter.json';
import * as BaseGoerliBridgeAdapter from '../generated-artifacts/BaseGoerliBridgeAdapter.json';
import * as BatchFillNativeOrdersFeature from '../generated-artifacts/BatchFillNativeOrdersFeature.json';
import * as BSCBridgeAdapter from '../generated-artifacts/BSCBridgeAdapter.json';
import * as CeloBridgeAdapter from '../generated-artifacts/CeloBridgeAdapter.json';
@ -32,6 +34,7 @@ import * as IZeroEx from '../generated-artifacts/IZeroEx.json';
import * as LiquidityProviderFeature from '../generated-artifacts/LiquidityProviderFeature.json';
import * as LogMetadataTransformer from '../generated-artifacts/LogMetadataTransformer.json';
import * as MetaTransactionsFeature from '../generated-artifacts/MetaTransactionsFeature.json';
import * as MetaTransactionsFeatureV2 from '../generated-artifacts/MetaTransactionsFeatureV2.json';
import * as MultiplexFeature from '../generated-artifacts/MultiplexFeature.json';
import * as NativeOrdersFeature from '../generated-artifacts/NativeOrdersFeature.json';
import * as OptimismBridgeAdapter from '../generated-artifacts/OptimismBridgeAdapter.json';
@ -78,10 +81,13 @@ export const artifacts = {
OtcOrdersFeature: OtcOrdersFeature as ContractArtifact,
IOtcOrdersFeature: IOtcOrdersFeature as ContractArtifact,
AvalancheBridgeAdapter: AvalancheBridgeAdapter as ContractArtifact,
BaseGoerliBridgeAdapter: BaseGoerliBridgeAdapter as ContractArtifact,
BaseBridgeAdapter: BaseBridgeAdapter as ContractArtifact,
BSCBridgeAdapter: BSCBridgeAdapter as ContractArtifact,
CeloBridgeAdapter: CeloBridgeAdapter as ContractArtifact,
EthereumBridgeAdapter: EthereumBridgeAdapter as ContractArtifact,
FantomBridgeAdapter: FantomBridgeAdapter as ContractArtifact,
OptimismBridgeAdapter: OptimismBridgeAdapter as ContractArtifact,
PolygonBridgeAdapter: PolygonBridgeAdapter as ContractArtifact,
MetaTransactionsFeatureV2: MetaTransactionsFeatureV2 as ContractArtifact,
};

View File

@ -26,6 +26,7 @@ export {
RevertErrorAbi,
StandardContractOutput,
StateMutability,
SupportedProvider,
TupleDataItem,
} from 'ethereum-types';
export { artifacts } from './artifacts';
@ -58,4 +59,3 @@ export {
ZeroExContract,
} from './wrappers';
export { EIP712TypedData } from '@0x/types';
export { SupportedProvider } from '@0x/subproviders';

View File

@ -1,7 +1,6 @@
import { SupportedProvider } from '@0x/subproviders';
import { SimpleContractArtifact } from '@0x/types';
import { NULL_ADDRESS } from '@0x/utils';
import { TxData } from 'ethereum-types';
import { TxData, SupportedProvider } from 'ethereum-types';
import * as _ from 'lodash';
import { artifacts } from './artifacts';

View File

@ -6,6 +6,8 @@
export * from '../generated-wrappers/affiliate_fee_transformer';
export * from '../generated-wrappers/avalanche_bridge_adapter';
export * from '../generated-wrappers/b_s_c_bridge_adapter';
export * from '../generated-wrappers/base_bridge_adapter';
export * from '../generated-wrappers/base_goerli_bridge_adapter';
export * from '../generated-wrappers/batch_fill_native_orders_feature';
export * from '../generated-wrappers/celo_bridge_adapter';
export * from '../generated-wrappers/curve_liquidity_provider';
@ -30,6 +32,7 @@ export * from '../generated-wrappers/initial_migration';
export * from '../generated-wrappers/liquidity_provider_feature';
export * from '../generated-wrappers/log_metadata_transformer';
export * from '../generated-wrappers/meta_transactions_feature';
export * from '../generated-wrappers/meta_transactions_feature_v2';
export * from '../generated-wrappers/multiplex_feature';
export * from '../generated-wrappers/native_orders_feature';
export * from '../generated-wrappers/optimism_bridge_adapter';

View File

@ -9,6 +9,8 @@ import * as AbstractBridgeAdapter from '../test/generated-artifacts/AbstractBrid
import * as AffiliateFeeTransformer from '../test/generated-artifacts/AffiliateFeeTransformer.json';
import * as ArbitrumBridgeAdapter from '../test/generated-artifacts/ArbitrumBridgeAdapter.json';
import * as AvalancheBridgeAdapter from '../test/generated-artifacts/AvalancheBridgeAdapter.json';
import * as BaseBridgeAdapter from '../test/generated-artifacts/BaseBridgeAdapter.json';
import * as BaseGoerliBridgeAdapter from '../test/generated-artifacts/BaseGoerliBridgeAdapter.json';
import * as BatchFillNativeOrdersFeature from '../test/generated-artifacts/BatchFillNativeOrdersFeature.json';
import * as BootstrapFeature from '../test/generated-artifacts/BootstrapFeature.json';
import * as BridgeProtocols from '../test/generated-artifacts/BridgeProtocols.json';
@ -51,6 +53,7 @@ import * as ILiquidityProvider from '../test/generated-artifacts/ILiquidityProvi
import * as ILiquidityProviderFeature from '../test/generated-artifacts/ILiquidityProviderFeature.json';
import * as ILiquidityProviderSandbox from '../test/generated-artifacts/ILiquidityProviderSandbox.json';
import * as IMetaTransactionsFeature from '../test/generated-artifacts/IMetaTransactionsFeature.json';
import * as IMetaTransactionsFeatureV2 from '../test/generated-artifacts/IMetaTransactionsFeatureV2.json';
import * as IMooniswapPool from '../test/generated-artifacts/IMooniswapPool.json';
import * as IMultiplexFeature from '../test/generated-artifacts/IMultiplexFeature.json';
import * as INativeOrdersEvents from '../test/generated-artifacts/INativeOrdersEvents.json';
@ -104,10 +107,10 @@ import * as LiquidityProviderFeature from '../test/generated-artifacts/Liquidity
import * as LiquidityProviderSandbox from '../test/generated-artifacts/LiquidityProviderSandbox.json';
import * as LogMetadataTransformer from '../test/generated-artifacts/LogMetadataTransformer.json';
import * as MetaTransactionsFeature from '../test/generated-artifacts/MetaTransactionsFeature.json';
import * as MetaTransactionsFeatureV2 from '../test/generated-artifacts/MetaTransactionsFeatureV2.json';
import * as MixinAaveV2 from '../test/generated-artifacts/MixinAaveV2.json';
import * as MixinBalancer from '../test/generated-artifacts/MixinBalancer.json';
import * as MixinBalancerV2Batch from '../test/generated-artifacts/MixinBalancerV2Batch.json';
import * as MixinBancor from '../test/generated-artifacts/MixinBancor.json';
import * as MixinBancorV3 from '../test/generated-artifacts/MixinBancorV3.json';
import * as MixinCompound from '../test/generated-artifacts/MixinCompound.json';
import * as MixinCryptoCom from '../test/generated-artifacts/MixinCryptoCom.json';
@ -120,10 +123,8 @@ import * as MixinKyberDmm from '../test/generated-artifacts/MixinKyberDmm.json';
import * as MixinLido from '../test/generated-artifacts/MixinLido.json';
import * as MixinMakerPSM from '../test/generated-artifacts/MixinMakerPSM.json';
import * as MixinMooniswap from '../test/generated-artifacts/MixinMooniswap.json';
import * as MixinMStable from '../test/generated-artifacts/MixinMStable.json';
import * as MixinNerve from '../test/generated-artifacts/MixinNerve.json';
import * as MixinPlatypus from '../test/generated-artifacts/MixinPlatypus.json';
import * as MixinShell from '../test/generated-artifacts/MixinShell.json';
import * as MixinSolidly from '../test/generated-artifacts/MixinSolidly.json';
import * as MixinSynthetix from '../test/generated-artifacts/MixinSynthetix.json';
import * as MixinUniswap from '../test/generated-artifacts/MixinUniswap.json';
@ -236,6 +237,7 @@ export const artifacts = {
FundRecoveryFeature: FundRecoveryFeature as ContractArtifact,
LiquidityProviderFeature: LiquidityProviderFeature as ContractArtifact,
MetaTransactionsFeature: MetaTransactionsFeature as ContractArtifact,
MetaTransactionsFeatureV2: MetaTransactionsFeatureV2 as ContractArtifact,
NativeOrdersFeature: NativeOrdersFeature as ContractArtifact,
OtcOrdersFeature: OtcOrdersFeature as ContractArtifact,
OwnableFeature: OwnableFeature as ContractArtifact,
@ -253,6 +255,7 @@ export const artifacts = {
IFundRecoveryFeature: IFundRecoveryFeature as ContractArtifact,
ILiquidityProviderFeature: ILiquidityProviderFeature as ContractArtifact,
IMetaTransactionsFeature: IMetaTransactionsFeature as ContractArtifact,
IMetaTransactionsFeatureV2: IMetaTransactionsFeatureV2 as ContractArtifact,
IMultiplexFeature: IMultiplexFeature as ContractArtifact,
INativeOrdersEvents: INativeOrdersEvents as ContractArtifact,
INativeOrdersFeature: INativeOrdersFeature as ContractArtifact,
@ -318,6 +321,8 @@ export const artifacts = {
ArbitrumBridgeAdapter: ArbitrumBridgeAdapter as ContractArtifact,
AvalancheBridgeAdapter: AvalancheBridgeAdapter as ContractArtifact,
BSCBridgeAdapter: BSCBridgeAdapter as ContractArtifact,
BaseBridgeAdapter: BaseBridgeAdapter as ContractArtifact,
BaseGoerliBridgeAdapter: BaseGoerliBridgeAdapter as ContractArtifact,
BridgeProtocols: BridgeProtocols as ContractArtifact,
CeloBridgeAdapter: CeloBridgeAdapter as ContractArtifact,
EthereumBridgeAdapter: EthereumBridgeAdapter as ContractArtifact,
@ -328,7 +333,6 @@ export const artifacts = {
MixinAaveV2: MixinAaveV2 as ContractArtifact,
MixinBalancer: MixinBalancer as ContractArtifact,
MixinBalancerV2Batch: MixinBalancerV2Batch as ContractArtifact,
MixinBancor: MixinBancor as ContractArtifact,
MixinBancorV3: MixinBancorV3 as ContractArtifact,
MixinCompound: MixinCompound as ContractArtifact,
MixinCryptoCom: MixinCryptoCom as ContractArtifact,
@ -339,12 +343,10 @@ export const artifacts = {
MixinGMX: MixinGMX as ContractArtifact,
MixinKyberDmm: MixinKyberDmm as ContractArtifact,
MixinLido: MixinLido as ContractArtifact,
MixinMStable: MixinMStable as ContractArtifact,
MixinMakerPSM: MixinMakerPSM as ContractArtifact,
MixinMooniswap: MixinMooniswap as ContractArtifact,
MixinNerve: MixinNerve as ContractArtifact,
MixinPlatypus: MixinPlatypus as ContractArtifact,
MixinShell: MixinShell as ContractArtifact,
MixinSolidly: MixinSolidly as ContractArtifact,
MixinSynthetix: MixinSynthetix as ContractArtifact,
MixinUniswap: MixinUniswap as ContractArtifact,

View File

@ -8,6 +8,8 @@ export * from '../test/generated-wrappers/affiliate_fee_transformer';
export * from '../test/generated-wrappers/arbitrum_bridge_adapter';
export * from '../test/generated-wrappers/avalanche_bridge_adapter';
export * from '../test/generated-wrappers/b_s_c_bridge_adapter';
export * from '../test/generated-wrappers/base_bridge_adapter';
export * from '../test/generated-wrappers/base_goerli_bridge_adapter';
export * from '../test/generated-wrappers/batch_fill_native_orders_feature';
export * from '../test/generated-wrappers/bootstrap_feature';
export * from '../test/generated-wrappers/bridge_protocols';
@ -49,6 +51,7 @@ export * from '../test/generated-wrappers/i_liquidity_provider';
export * from '../test/generated-wrappers/i_liquidity_provider_feature';
export * from '../test/generated-wrappers/i_liquidity_provider_sandbox';
export * from '../test/generated-wrappers/i_meta_transactions_feature';
export * from '../test/generated-wrappers/i_meta_transactions_feature_v2';
export * from '../test/generated-wrappers/i_mooniswap_pool';
export * from '../test/generated-wrappers/i_multiplex_feature';
export * from '../test/generated-wrappers/i_native_orders_events';
@ -102,10 +105,10 @@ export * from '../test/generated-wrappers/liquidity_provider_feature';
export * from '../test/generated-wrappers/liquidity_provider_sandbox';
export * from '../test/generated-wrappers/log_metadata_transformer';
export * from '../test/generated-wrappers/meta_transactions_feature';
export * from '../test/generated-wrappers/meta_transactions_feature_v2';
export * from '../test/generated-wrappers/mixin_aave_v2';
export * from '../test/generated-wrappers/mixin_balancer';
export * from '../test/generated-wrappers/mixin_balancer_v2_batch';
export * from '../test/generated-wrappers/mixin_bancor';
export * from '../test/generated-wrappers/mixin_bancor_v3';
export * from '../test/generated-wrappers/mixin_compound';
export * from '../test/generated-wrappers/mixin_crypto_com';
@ -116,12 +119,10 @@ export * from '../test/generated-wrappers/mixin_dodo_v2';
export * from '../test/generated-wrappers/mixin_g_m_x';
export * from '../test/generated-wrappers/mixin_kyber_dmm';
export * from '../test/generated-wrappers/mixin_lido';
export * from '../test/generated-wrappers/mixin_m_stable';
export * from '../test/generated-wrappers/mixin_maker_p_s_m';
export * from '../test/generated-wrappers/mixin_mooniswap';
export * from '../test/generated-wrappers/mixin_nerve';
export * from '../test/generated-wrappers/mixin_platypus';
export * from '../test/generated-wrappers/mixin_shell';
export * from '../test/generated-wrappers/mixin_solidly';
export * from '../test/generated-wrappers/mixin_synthetix';
export * from '../test/generated-wrappers/mixin_uniswap';

View File

@ -0,0 +1,496 @@
// 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 "./utils/BaseTest.sol";
import "forge-std/Test.sol";
import "./utils/LocalTest.sol";
import "../contracts/src/features/MetaTransactionsFeatureV2.sol";
import "../contracts/src/features/interfaces/IMetaTransactionsFeatureV2.sol";
import "../contracts/src/features/interfaces/IMetaTransactionsFeature.sol";
import "../contracts/test/TestMintTokenERC20Transformer.sol";
import "../contracts/src/features/libs/LibSignature.sol";
import "src/features/libs/LibNativeOrder.sol";
import "../contracts/test/tokens/TestMintableERC20Token.sol";
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-erc20/src/IEtherToken.sol";
contract MetaTransactionTest is LocalTest {
address private constant USER_ADDRESS = 0x6dc3a54FeAE57B65d185A7B159c5d3FA7fD7FD0F;
uint256 private constant USER_KEY = 0x1fc1630343b31e60b7a197a53149ca571ed9d9791e2833337bbd8110c30710ec;
event MetaTransactionExecuted(bytes32 hash, bytes4 indexed selector, address signer, address sender);
function _mtxSignature(
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx
) private returns (LibSignature.Signature memory) {
return _mtxSignatureWithSignerKey(mtx, USER_KEY);
}
function _mtxSignatureWithSignerKey(
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx,
uint256 key
) private returns (LibSignature.Signature memory) {
// Mint fee to signer and approve
for (uint256 i = 0; i < mtx.fees.length; ++i) {
_mintTo(address(weth), mtx.signer, mtx.fees[i].amount);
}
vm.prank(mtx.signer);
mtx.feeToken.approve(address(zeroExDeployed.zeroEx), 1e18);
bytes32 mtxHash = zeroExDeployed.features.metaTransactionsFeatureV2.getMetaTransactionV2Hash(mtx);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(key, mtxHash);
LibSignature.Signature memory sig = LibSignature.Signature(LibSignature.SignatureType.EIP712, v, r, s);
return sig;
}
function _getMetaTransaction(
bytes memory callData
) private view returns (IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory) {
IMetaTransactionsFeatureV2.MetaTransactionFeeData[]
memory fees = new IMetaTransactionsFeatureV2.MetaTransactionFeeData[](1);
fees[0] = IMetaTransactionsFeatureV2.MetaTransactionFeeData({recipient: address(this), amount: 1});
return _getMetaTransactionWithFees(callData, fees);
}
function _getMetaTransactionWithFees(
bytes memory callData,
IMetaTransactionsFeatureV2.MetaTransactionFeeData[] memory fees
) private view returns (IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory) {
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx = IMetaTransactionsFeatureV2.MetaTransactionDataV2({
signer: payable(USER_ADDRESS),
sender: address(this),
expirationTimeSeconds: block.timestamp + 60,
salt: 123,
callData: callData,
feeToken: weth,
fees: fees
});
return mtx;
}
function _badSelectorTransformERC20Call() private pure returns (bytes memory) {
return abi.encodeWithSelector(ITransformERC20Feature.createTransformWallet.selector);
}
function _badTokenTransformERC20Call() private returns (bytes memory) {
ITransformERC20Feature.Transformation[] memory transformations = new ITransformERC20Feature.Transformation[](1);
transformations[0] = ITransformERC20Feature.Transformation(
uint32(transformerNonce),
abi.encode(address(dai), address(weth), 0, 1e18, 0)
);
_mintTo(address(dai), USER_ADDRESS, 1e18);
vm.prank(USER_ADDRESS);
dai.approve(address(zeroExDeployed.zeroEx), 1e18);
return
abi.encodeWithSelector(
zeroExDeployed.zeroEx.transformERC20.selector, // 0x415565b0
dai,
weth,
1e18,
1e18,
transformations
);
}
function _makeTestRfqOrder(
IERC20Token makerToken,
IERC20Token takerToken,
address makerAddress,
address takerAddress,
uint256 makerKey
) internal returns (bytes memory callData) {
LibNativeOrder.RfqOrder memory order = LibNativeOrder.RfqOrder({
makerToken: makerToken,
takerToken: takerToken,
makerAmount: 1e18,
takerAmount: 1e18,
maker: makerAddress,
taker: address(0),
txOrigin: tx.origin,
pool: 0x0000000000000000000000000000000000000000000000000000000000000000,
expiry: uint64(block.timestamp + 60),
salt: 123
});
_mintTo(address(order.makerToken), order.maker, order.makerAmount);
vm.prank(order.maker);
order.makerToken.approve(address(zeroExDeployed.zeroEx), order.makerAmount);
_mintTo(address(order.takerToken), takerAddress, order.takerAmount);
vm.prank(takerAddress);
order.takerToken.approve(address(zeroExDeployed.zeroEx), order.takerAmount);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(
makerKey,
zeroExDeployed.features.nativeOrdersFeature.getRfqOrderHash(order)
);
LibSignature.Signature memory sig = LibSignature.Signature(LibSignature.SignatureType.EIP712, v, r, s);
return
abi.encodeWithSelector(
INativeOrdersFeature.fillRfqOrder.selector, // 0xaa77476c
order, // RFQOrder
sig, // Order Signature
1e18 // Fill Amount
);
}
function _makeTestLimitOrder(
IERC20Token makerToken,
IERC20Token takerToken,
address makerAddress,
address takerAddress,
uint256 makerKey
) internal returns (bytes memory callData) {
LibNativeOrder.LimitOrder memory order = LibNativeOrder.LimitOrder({
makerToken: makerToken,
takerToken: takerToken,
makerAmount: 1e18,
takerAmount: 1e18,
maker: makerAddress,
taker: address(0),
sender: address(0),
takerTokenFeeAmount: 0,
feeRecipient: address(0),
pool: 0x0000000000000000000000000000000000000000000000000000000000000000,
expiry: uint64(block.timestamp + 60),
salt: 123
});
_mintTo(address(order.makerToken), order.maker, order.makerAmount);
vm.prank(order.maker);
order.makerToken.approve(address(zeroExDeployed.zeroEx), order.makerAmount);
_mintTo(address(order.takerToken), takerAddress, order.takerAmount);
vm.prank(takerAddress);
order.takerToken.approve(address(zeroExDeployed.zeroEx), order.takerAmount);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(
makerKey,
zeroExDeployed.features.nativeOrdersFeature.getLimitOrderHash(order)
);
LibSignature.Signature memory sig = LibSignature.Signature(LibSignature.SignatureType.EIP712, v, r, s);
return
abi.encodeWithSelector(
INativeOrdersFeature.fillLimitOrder.selector, // 0xf6274f66
order, // LimitOrder
sig, // Order Signature
1e18 // Fill Amount
);
}
function _transformERC20Call(
IERC20Token makerToken,
IERC20Token takerToken,
address takerAddress
) internal returns (bytes memory) {
ITransformERC20Feature.Transformation[] memory transformations = new ITransformERC20Feature.Transformation[](1);
transformations[0] = ITransformERC20Feature.Transformation(
uint32(transformerNonce),
abi.encode(address(takerToken), address(makerToken), 0, 1e18, 0)
);
_mintTo(address(takerToken), takerAddress, 1e18);
vm.prank(takerAddress);
takerToken.approve(address(zeroExDeployed.zeroEx), 1e18);
return
abi.encodeWithSelector(
zeroExDeployed.zeroEx.transformERC20.selector, // 0x415565b0
takerToken,
makerToken,
1e18,
1e18,
transformations
);
}
function test_createHash() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
bytes32 mtxHash = zeroExDeployed.features.metaTransactionsFeatureV2.getMetaTransactionV2Hash(mtxData);
assertTrue(mtxHash != bytes32(0));
}
function test_EIP_712_signature() external {
// metamask wallet signed data
bytes32 r_mm = 0xcd6c09d558e23803afae870ca53a8e7bfaf5564c64ee29f23dc4a19e7dd9e9b5;
bytes32 s_mm = 0x1ae68e89fadab4a7f4d01fd5543e5e0efd5697e87c993f045f671aba3e1f55ac;
uint8 v_mm = 0x1b;
IMetaTransactionsFeatureV2.MetaTransactionFeeData[]
memory fees = new IMetaTransactionsFeatureV2.MetaTransactionFeeData[](2);
fees[0] = IMetaTransactionsFeatureV2.MetaTransactionFeeData({recipient: address(0), amount: 1000000});
fees[1] = IMetaTransactionsFeatureV2.MetaTransactionFeeData({recipient: address(0), amount: 1000});
IERC20Token usdcToken = IERC20Token(address(0x2e234DAe75C793f67A35089C9d99245E1C58470b));
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx = IMetaTransactionsFeatureV2.MetaTransactionDataV2({
signer: address(0),
sender: address(0),
expirationTimeSeconds: 99999999,
salt: 1234,
callData: new bytes(0),
feeToken: usdcToken,
fees: fees
});
bytes32 mtxHash = zeroExDeployed.features.metaTransactionsFeatureV2.getMetaTransactionV2Hash(mtx);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(USER_KEY, mtxHash);
//emit log_bytes(abi.encodePacked(r, s, bytes1(v)));
// Verify signature matches from what we generated using metamask
assertTrue(v == v_mm);
assertTrue(r == r_mm);
assertTrue(s == s_mm);
}
function test_transformERC20() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
LibSignature.Signature memory sig = _mtxSignature(mtxData);
assertEq(dai.balanceOf(USER_ADDRESS), 1e18);
vm.expectEmit(true, false, false, true);
emit MetaTransactionExecuted(
zeroExDeployed.features.metaTransactionsFeatureV2.getMetaTransactionV2Hash(mtxData),
zeroExDeployed.zeroEx.transformERC20.selector, // 0x415565b0
USER_ADDRESS,
address(this)
);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
assertEq(zrx.balanceOf(USER_ADDRESS), 1e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(weth.balanceOf(address(this)), 1);
}
function test_rfqOrder() external {
bytes memory callData = _makeTestRfqOrder(zrx, dai, signerAddress, USER_ADDRESS, signerKey);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(callData);
LibSignature.Signature memory sig = _mtxSignature(mtxData);
assertEq(dai.balanceOf(USER_ADDRESS), 1e18);
vm.expectEmit(true, false, false, true);
emit MetaTransactionExecuted(
zeroExDeployed.features.metaTransactionsFeatureV2.getMetaTransactionV2Hash(mtxData),
INativeOrdersFeature.fillRfqOrder.selector, // 0xaa77476c
USER_ADDRESS,
address(this)
);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
assertEq(zrx.balanceOf(signerAddress), 0);
assertEq(zrx.balanceOf(USER_ADDRESS), 1e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(dai.balanceOf(signerAddress), 1e18);
assertEq(weth.balanceOf(address(this)), 1);
}
function test_fillLimitOrder() external {
bytes memory callData = _makeTestLimitOrder(zrx, dai, signerAddress, USER_ADDRESS, signerKey);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(callData);
LibSignature.Signature memory sig = _mtxSignature(mtxData);
assertEq(dai.balanceOf(USER_ADDRESS), 1e18);
vm.expectEmit(true, false, false, true);
emit MetaTransactionExecuted(
zeroExDeployed.features.metaTransactionsFeatureV2.getMetaTransactionV2Hash(mtxData),
INativeOrdersFeature.fillLimitOrder.selector, // 0xf6274f66
USER_ADDRESS,
address(this)
);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
assertEq(zrx.balanceOf(signerAddress), 0);
assertEq(zrx.balanceOf(USER_ADDRESS), 1e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(dai.balanceOf(signerAddress), 1e18);
assertEq(weth.balanceOf(address(this)), 1);
}
function test_transformERC20WithAnySender() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
mtxData.sender = address(0);
assertEq(dai.balanceOf(USER_ADDRESS), 1e18);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(
mtxData,
_mtxSignature(mtxData)
);
assertEq(zrx.balanceOf(USER_ADDRESS), 1e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(weth.balanceOf(address(this)), 1);
}
function test_transformERC20WithoutFee() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionFeeData[] memory fees;
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransactionWithFees(
transformCallData,
fees
);
assertEq(dai.balanceOf(USER_ADDRESS), 1e18);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(
mtxData,
_mtxSignature(mtxData)
);
assertEq(zrx.balanceOf(USER_ADDRESS), 1e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(weth.balanceOf(address(this)), 0); // no fee paid out
}
function test_transformERC20MultipleFees() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionFeeData[]
memory fees = new IMetaTransactionsFeatureV2.MetaTransactionFeeData[](2);
fees[0] = IMetaTransactionsFeatureV2.MetaTransactionFeeData({recipient: address(this), amount: 10});
fees[1] = IMetaTransactionsFeatureV2.MetaTransactionFeeData({recipient: signerAddress, amount: 20});
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransactionWithFees(
transformCallData,
fees
);
assertEq(dai.balanceOf(USER_ADDRESS), 1e18);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(
mtxData,
_mtxSignature(mtxData)
);
assertEq(zrx.balanceOf(USER_ADDRESS), 1e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(weth.balanceOf(address(this)), 10);
assertEq(weth.balanceOf(address(signerAddress)), 20);
}
function test_transformERC20TranslatedCallFail() external {
bytes memory transformCallData = _badTokenTransformERC20Call();
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
LibSignature.Signature memory sig = _mtxSignature(mtxData);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
}
function test_transformERC20UnsupportedFunction() external {
bytes memory transformCallData = _badSelectorTransformERC20Call();
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
LibSignature.Signature memory sig = _mtxSignature(mtxData);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
}
function test_transformERC20CantExecuteTwice() external {
bytes memory callData = _makeTestRfqOrder(zrx, dai, signerAddress, USER_ADDRESS, signerKey);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(callData);
LibSignature.Signature memory sig = _mtxSignature(mtxData);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
}
function test_metaTxnFailsIfExpired() external {
bytes memory callData = _makeTestRfqOrder(zrx, dai, signerAddress, USER_ADDRESS, signerKey);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(callData);
mtxData.expirationTimeSeconds = block.timestamp - 1;
LibSignature.Signature memory sig = _mtxSignature(mtxData);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
}
function test_metaTxnFailsIfWrongSender() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
mtxData.sender = USER_ADDRESS;
LibSignature.Signature memory sig = _mtxSignature(mtxData);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
}
function test_metaTxnFailsWrongSignature() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtxData = _getMetaTransaction(transformCallData);
LibSignature.Signature memory sig = _mtxSignatureWithSignerKey(mtxData, signerKey);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).executeMetaTransactionV2(mtxData, sig);
}
function test_batchExecuteMetaTransactionsMultipleTransactions() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
bytes memory rfqCallData = _makeTestRfqOrder(zrx, shib, signerAddress, USER_ADDRESS, signerKey);
IMetaTransactionsFeatureV2.MetaTransactionDataV2[]
memory mtxns = new IMetaTransactionsFeatureV2.MetaTransactionDataV2[](2);
LibSignature.Signature[] memory sigs = new LibSignature.Signature[](2);
mtxns[0] = _getMetaTransaction(transformCallData);
sigs[0] = _mtxSignature(mtxns[0]);
mtxns[1] = _getMetaTransaction(rfqCallData);
sigs[1] = _mtxSignature(mtxns[1]);
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).batchExecuteMetaTransactionsV2(mtxns, sigs);
assertEq(zrx.balanceOf(USER_ADDRESS), 2e18);
assertEq(dai.balanceOf(USER_ADDRESS), 0);
assertEq(shib.balanceOf(USER_ADDRESS), 0);
}
function test_batchExecuteMetaTransactionsCantExecuteSameTxnTwice() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
IMetaTransactionsFeatureV2.MetaTransactionDataV2[]
memory mtxns = new IMetaTransactionsFeatureV2.MetaTransactionDataV2[](2);
LibSignature.Signature[] memory sigs = new LibSignature.Signature[](2);
mtxns[0] = _getMetaTransaction(transformCallData);
sigs[0] = _mtxSignature(mtxns[0]);
mtxns[1] = mtxns[0];
sigs[1] = _mtxSignature(mtxns[1]);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).batchExecuteMetaTransactionsV2(mtxns, sigs);
}
function test_batchExecuteMetaTransactionsFailsIfTransactionFails() external {
bytes memory transformCallData = _transformERC20Call(zrx, dai, USER_ADDRESS);
bytes memory badTransformCallData = _badTokenTransformERC20Call();
IMetaTransactionsFeatureV2.MetaTransactionDataV2[]
memory mtxns = new IMetaTransactionsFeatureV2.MetaTransactionDataV2[](2);
LibSignature.Signature[] memory sigs = new LibSignature.Signature[](2);
mtxns[0] = _getMetaTransaction(transformCallData);
sigs[0] = _mtxSignature(mtxns[0]);
mtxns[1] = _getMetaTransaction(badTransformCallData);
sigs[1] = _mtxSignature(mtxns[1]);
vm.expectRevert();
IMetaTransactionsFeatureV2(address(zeroExDeployed.zeroEx)).batchExecuteMetaTransactionsV2(mtxns, sigs);
}
}

View File

@ -0,0 +1,407 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.6;
pragma experimental ABIEncoderV2;
import {LocalTest} from "utils/LocalTest.sol";
import {MultiplexUtils} from "utils/MultiplexUtils.sol";
import {LibSignature} from "src/features/libs/LibSignature.sol";
import {LibNativeOrder} from "src/features/libs/LibNativeOrder.sol";
import {IMetaTransactionsFeatureV2} from "src/features/interfaces/IMetaTransactionsFeatureV2.sol";
contract MultiplexMetaTransactionsV2 is LocalTest, MultiplexUtils {
function _makeMetaTransactionV2(
bytes memory callData
) private view returns (IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory, LibSignature.Signature memory) {
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx = IMetaTransactionsFeatureV2.MetaTransactionDataV2({
signer: payable(otherSignerAddress),
sender: address(0),
expirationTimeSeconds: block.timestamp + 600,
salt: 123,
callData: callData,
feeToken: dai,
fees: new IMetaTransactionsFeatureV2.MetaTransactionFeeData[](0)
});
bytes32 mtxHash = zeroExDeployed.zeroEx.getMetaTransactionV2Hash(mtx);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(otherSignerKey, mtxHash);
LibSignature.Signature memory sig = LibSignature.Signature(LibSignature.SignatureType.EIP712, v, r, s);
return (mtx, sig);
}
function _executeMetaTransaction(bytes memory callData) private {
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx;
LibSignature.Signature memory sig;
(mtx, sig) = _makeMetaTransactionV2(callData);
zeroExDeployed.zeroEx.executeMetaTransactionV2(mtx, sig);
}
// batch
function test_metaTransaction_multiplexBatchSellTokenForToken_rfqOrder() external {
LibNativeOrder.RfqOrder memory rfqOrder = _makeTestRfqOrder();
rfqOrder.taker = otherSignerAddress;
_mintTo(address(rfqOrder.takerToken), otherSignerAddress, rfqOrder.takerAmount);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeRfqSubcall(rfqOrder)),
rfqOrder.takerAmount,
rfqOrder.makerAmount
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_otcOrder() external {
LibNativeOrder.OtcOrder memory otcOrder = _makeTestOtcOrder();
otcOrder.taker = otherSignerAddress;
_mintTo(address(otcOrder.takerToken), otherSignerAddress, otcOrder.takerAmount);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeOtcSubcall(otcOrder)),
otcOrder.takerAmount,
otcOrder.makerAmount
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_uniswapV2() external {
_createUniswapV2Pool(uniV2Factory, dai, zrx, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeUniswapV2BatchSubcall(_makeArray(address(dai), address(zrx)), 1e18, false)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_uniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(zrx)), 1e18)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_liquidityProvider() external {
_mintTo(address(dai), otherSignerAddress, 1e18);
_mintTo(address(zrx), address(liquidityProvider), 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeMockLiquidityProviderBatchSubcall(1e18)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_transformErc20() external {
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeMockTransformERC20Subcall(dai, zrx, 1e18, 1e18)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_rfqOrderUniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
LibNativeOrder.RfqOrder memory rfqOrder = _makeTestRfqOrder();
rfqOrder.taker = otherSignerAddress;
_mintTo(address(dai), otherSignerAddress, 2e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(
_makeRfqSubcall(rfqOrder),
_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(zrx)), 1e18)
),
2e18,
11e18
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_rfqOrderFallbackUniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 2e18);
LibNativeOrder.RfqOrder memory rfqOrder = _makeTestRfqOrder();
rfqOrder.taker = otherSignerAddress;
rfqOrder.expiry = 1;
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(
_makeRfqSubcall(rfqOrder),
_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(zrx)), 1e18)
),
1e18,
10e18
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForToken_uniswapV3_revertsIfIncorrectAmount() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx;
LibSignature.Signature memory sig;
(mtx, sig) = _makeMetaTransactionV2(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(zrx)), 5e17)),
1e18,
1
)
);
vm.expectRevert();
zeroExDeployed.zeroEx.executeMetaTransactionV2(mtx, sig);
}
// multi hop
function test_metaTransaction_multiplexMultiHopSellTokenForToken_uniswapV2() external {
_createUniswapV2Pool(uniV2Factory, dai, zrx, 10e18, 10e18);
address[] memory tokens = _makeArray(address(dai), address(zrx));
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForToken.selector,
tokens,
_makeArray(_makeUniswapV2MultiHopSubcall(tokens, false)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexMultiHopSellTokenForToken_uniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
address[] memory tokens = _makeArray(address(dai), address(zrx));
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForToken.selector,
tokens,
_makeArray(_makeUniswapV3MultiHopSubcall(tokens)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexMultiHopSellTokenForToken_liquidityProvider() external {
_mintTo(address(dai), otherSignerAddress, 1e18);
_mintTo(address(zrx), address(liquidityProvider), 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForToken.selector,
_makeArray(address(dai), address(zrx)),
_makeArray(_makeMockLiquidityProviderMultiHopSubcall()),
1e18,
1
)
);
}
function test_metaTransaction_multiplexMultiHopSellTokenForToken_uniswapV2UniswapV3() external {
_createUniswapV2Pool(uniV2Factory, dai, shib, 10e18, 10e18);
_createUniswapV3Pool(uniV3Factory, shib, zrx, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForToken.selector,
_makeArray(address(dai), address(shib), address(zrx)),
_makeArray(
_makeUniswapV2MultiHopSubcall(_makeArray(address(dai), address(shib)), false),
_makeUniswapV3MultiHopSubcall(_makeArray(address(shib), address(zrx)))
),
1e18,
10e18
)
);
}
// batch for eth
function test_metaTransaction_multiplexBatchSellTokenForEth_uniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, weth, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForEth.selector,
dai,
_makeArray(_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(weth)), 1e18)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexBatchSellTokenForEth_rfqOrderUniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, weth, 10e18, 10e18);
LibNativeOrder.RfqOrder memory rfqOrder = _makeTestRfqOrder();
rfqOrder.taker = otherSignerAddress;
rfqOrder.makerToken = weth;
_mintTo(address(weth), rfqOrder.maker, rfqOrder.makerAmount);
_mintTo(address(dai), otherSignerAddress, 2e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForEth.selector,
dai,
_makeArray(
_makeRfqSubcall(rfqOrder),
_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(weth)), 1e18)
),
2e18,
11e18
)
);
}
// nested
function test_metaTransaction_multiplexBatchSellTokenForToken_nestedUniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
address[] memory tokens = _makeArray(address(dai), address(zrx));
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexBatchSellTokenForToken.selector,
dai,
zrx,
_makeArray(
_makeNestedMultiHopSellSubcall(tokens, _makeArray(_makeUniswapV3MultiHopSubcall(tokens)), 1e18)
),
1e18,
1
)
);
}
function test_metaTransaction_multiplexMultiHopSellTokenForToken_nestedUniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForToken.selector,
_makeArray(address(dai), address(zrx)),
_makeArray(
_makeNestedBatchSellSubcall(
_makeArray(_makeUniswapV3BatchSubcall(_makeArray(address(dai), address(zrx)), 1e18))
)
),
1e18,
1
)
);
}
// multi hop for eth
function test_metaTransaction_multiplexMultiHopSellTokenForEth_uniswapV3() external {
_createUniswapV3Pool(uniV3Factory, dai, weth, 10e18, 10e18);
address[] memory tokens = _makeArray(address(dai), address(weth));
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForEth.selector,
tokens,
_makeArray(_makeUniswapV3MultiHopSubcall(tokens)),
1e18,
1
)
);
}
function test_metaTransaction_multiplexMultiHopSellTokenForEth_uniswapV3_revertsNotWeth() external {
_createUniswapV3Pool(uniV3Factory, dai, zrx, 10e18, 10e18);
address[] memory tokens = _makeArray(address(dai), address(zrx));
_mintTo(address(dai), otherSignerAddress, 1e18);
IMetaTransactionsFeatureV2.MetaTransactionDataV2 memory mtx;
LibSignature.Signature memory sig;
(mtx, sig) = _makeMetaTransactionV2(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForEth.selector,
tokens,
_makeArray(_makeUniswapV3MultiHopSubcall(tokens)),
1e18,
1
)
);
vm.expectRevert("MetaTransactionsFeature::multiplexMultiHopSellTokenForEth/NOT_WETH");
zeroExDeployed.zeroEx.executeMetaTransactionV2(mtx, sig);
}
function test_metaTransaction_multiplexMultiHopSellTokenForEth_uniswapV2UniswapV3() external {
_createUniswapV2Pool(uniV2Factory, dai, shib, 10e18, 10e18);
_createUniswapV3Pool(uniV3Factory, shib, weth, 10e18, 10e18);
_mintTo(address(dai), otherSignerAddress, 1e18);
_executeMetaTransaction(
abi.encodeWithSelector(
zeroExDeployed.zeroEx.multiplexMultiHopSellTokenForToken.selector,
_makeArray(address(dai), address(shib), address(weth)),
_makeArray(
_makeUniswapV2MultiHopSubcall(_makeArray(address(dai), address(shib)), false),
_makeUniswapV3MultiHopSubcall(_makeArray(address(shib), address(weth)))
),
1e18,
10e18
)
);
}
}

View File

@ -4,48 +4,62 @@
"UniswapV3Router": "0x0000000000000000000000000000000000000000",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0x952ffc4c47d66b454a8181f5c68b6248e18b66ec"
"KyberElasticPool": "0x952ffc4c47d66b454a8181f5c68b6248e18b66ec",
"TraderJoeV2Quoter": "0x0000000000000000000000000000000000000000",
"TraderJoeV2Router": "0x0000000000000000000000000000000000000000"
},
"56": {
"UniswapV2Router": "0x10ed43c718714eb63d5aa57b78b54704e256024e",
"UniswapV3Router": "0x0000000000000000000000000000000000000000",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0xfbfab68ba077d099cd4b66fa76920572cc0b557c"
"KyberElasticPool": "0xfbfab68ba077d099cd4b66fa76920572cc0b557c",
"TraderJoeV2Quoter": "0x0000000000000000000000000000000000000000",
"TraderJoeV2Router": "0x0000000000000000000000000000000000000000"
},
"137": {
"UniswapV2Router": "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506",
"UniswapV3Router": "0x0000000000000000000000000000000000000000",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0xf9cc934753a127100585812181ac04d07158a4c2"
"KyberElasticPool": "0xf9cc934753a127100585812181ac04d07158a4c2",
"TraderJoeV2Quoter": "0x0000000000000000000000000000000000000000",
"TraderJoeV2Router": "0x0000000000000000000000000000000000000000"
},
"43114": {
"UniswapV2Router": "0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10",
"UniswapV3Router": "0x0000000000000000000000000000000000000000",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0x6038373de7f64da99b2a31951628b7d778b2c3cf"
"KyberElasticPool": "0x6038373de7f64da99b2a31951628b7d778b2c3cf",
"TraderJoeV2Quoter": "0x64b57F4249aA99a812212cee7DAEFEDC40B203cD",
"TraderJoeV2Router": "0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30"
},
"250": {
"UniswapV2Router": "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506",
"UniswapV3Router": "0x0000000000000000000000000000000000000000",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0x8dcf5fed6ae6bf0befb5e4f0c9414c2cb9a4ed01"
"KyberElasticPool": "0x8dcf5fed6ae6bf0befb5e4f0c9414c2cb9a4ed01",
"TraderJoeV2Quoter": "0x0000000000000000000000000000000000000000",
"TraderJoeV2Router": "0x0000000000000000000000000000000000000000"
},
"10": {
"UniswapV2Router": "0x0000000000000000000000000000000000000000",
"UniswapV3Router": "0x61ffe014ba17989e743c5f6cb21bf9697530b21e",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0x7e29ccaa4bf2894aca02c77e6b99cafc1d24b2f5"
"KyberElasticPool": "0x7e29ccaa4bf2894aca02c77e6b99cafc1d24b2f5",
"TraderJoeV2Quoter": "0x0000000000000000000000000000000000000000",
"TraderJoeV2Router": "0x0000000000000000000000000000000000000000"
},
"42161": {
"UniswapV2Router": "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506",
"UniswapV3Router": "0x0000000000000000000000000000000000000000",
"KyberElasticQuoter": "0x0d125c15d54ca1f8a813c74a81aee34ebb508c1f",
"KyberElasticRouter": "0xc1e7dfe73e1598e3910ef4c7845b68a9ab6f4c83",
"KyberElasticPool": "0x087abaab9cd85025a8b3916948c69fe173c837ea"
"KyberElasticPool": "0x087abaab9cd85025a8b3916948c69fe173c837ea",
"TraderJoeV2Quoter": "0x64b57F4249aA99a812212cee7DAEFEDC40B203cD",
"TraderJoeV2Router": "0xb4315e873dBcf96Ffd0acd8EA43f689D8c20fB30"
}
}

View File

@ -20,8 +20,8 @@
"43114": {
"WrappedNativeToken": "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
"DAI": "0xd586e7f844cea2f87f50152665bcbc2c279d8d70",
"USDC": "0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664",
"USDT": "0xc7198437980c041c805A1EDcbA50c1Ce5db95118"
"USDC": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
"USDT": "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7"
},
"250": {
"WrappedNativeToken": "0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83",

View File

@ -0,0 +1,219 @@
// 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;
pragma experimental ABIEncoderV2;
import "../utils/ForkUtils.sol";
import "../utils/TestUtils.sol";
import "src/IZeroEx.sol";
import "@0x/contracts-erc20/src/IEtherToken.sol";
import "src/features/TransformERC20Feature.sol";
import "src/features/multiplex/MultiplexFeature.sol";
import "src/external/TransformerDeployer.sol";
import "src/transformers/WethTransformer.sol";
import "src/transformers/FillQuoteTransformer.sol";
import "src/transformers/bridges/BridgeProtocols.sol";
import "src/features/OtcOrdersFeature.sol";
contract MultiplexRfqtTest is Test, ForkUtils, TestUtils {
using LibERC20TokenV06 for IERC20Token;
using LibERC20TokenV06 for IEtherToken;
function setUp() public {
_setup();
}
function test_swapEthForUSDTThroughFqtOtcs() public {
log_string("SwapEthForUSDTThroughFqtOtc");
/* */
for (uint256 i = 0; i < 1; i++) {
//skip fantom/avax failing test
if (i == 3 || i == 4) {
continue;
}
vm.selectFork(forkIds[chains[i]]);
log_named_string(" Selecting Fork On", chains[i]);
vm.deal(address(this), 1e18);
labelAddresses(
chains[i],
indexChainsByChain[chains[i]],
getTokens(i),
getContractAddresses(i),
getLiquiditySourceAddresses(i)
);
//redeploy and migrate multiplexFeature and OtcOrders for logging
MultiplexFeature multiplexFeature = new MultiplexFeature(
address(IZERO_EX),
IEtherToken(tokens.WrappedNativeToken),
ILiquidityProviderSandbox(addresses.exchangeProxyLiquidityProviderSandbox),
address(0), // uniswapFactory
address(0), // sushiswapFactory
bytes32(0), // uniswapPairInitCodeHash
bytes32(0) // sushiswapPairInitCodeHash
);
OtcOrdersFeature otcOrdersFeature = new OtcOrdersFeature(
address(addresses.exchangeProxy),
tokens.WrappedNativeToken
);
vm.label(address(multiplexFeature), "zeroEx/NewMultiplexFeature");
vm.label(address(otcOrdersFeature), "zeroEx/NewOtcOrdersFeature");
vm.prank(IZeroEx(addresses.exchangeProxy).owner());
IZeroEx(addresses.exchangeProxy).migrate(
address(otcOrdersFeature),
abi.encodeWithSelector(OtcOrdersFeature.migrate.selector),
address(addresses.exchangeProxy)
);
vm.prank(IZeroEx(addresses.exchangeProxy).owner());
IZeroEx(addresses.exchangeProxy).migrate(
address(multiplexFeature),
abi.encodeWithSelector(MultiplexFeature.migrate.selector),
address(addresses.exchangeProxy)
);
swapMultihopOtc(getTokens(i), getContractAddresses(i), getLiquiditySourceAddresses(i));
}
}
/* solhint-disable function-max-lines */
function swapMultihopOtc(
TokenAddresses memory tokens,
ContractAddresses memory addresses,
LiquiditySources memory sources
) public onlyForked {
IZERO_EX = IZeroEx(addresses.exchangeProxy);
address[] memory tradeTokens = new address[](3);
tradeTokens[0] = address(tokens.WrappedNativeToken);
tradeTokens[1] = address(tokens.USDC);
tradeTokens[2] = address(tokens.DAI);
deal(tradeTokens[0], address(this), 1e18);
tokens.WrappedNativeToken.approveIfBelow(addresses.exchangeProxy, uint(-1));
uint inputAmount = 1e18;
uint outputAmount = 5e17;
IMultiplexFeature.MultiHopSellSubcall[] memory subcalls = new IMultiplexFeature.MultiHopSellSubcall[](2);
IMultiplexFeature.MultiHopSellSubcall memory subcall1;
subcall1.id = IMultiplexFeature.MultiplexSubcall.OTC;
//subcall.data = abi.encode(address[], LibNativeOrder.OtcOrder, LibSignature.Signature);
(LibNativeOrder.OtcOrder memory order1, LibSignature.Signature memory signature1) = createOtcOrder(
tokens.WrappedNativeToken,
tokens.USDC,
1e18,
5e17,
0
);
subcall1.data = abi.encode(order1, signature1);
IMultiplexFeature.MultiHopSellSubcall memory subcall2;
subcall2.id = IMultiplexFeature.MultiplexSubcall.OTC;
(LibNativeOrder.OtcOrder memory order2, LibSignature.Signature memory signature2) = createOtcOrder(
tokens.USDC,
tokens.DAI,
5e17,
5e17,
1
);
subcall2.data = abi.encode(order2, signature2);
subcalls[0] = subcall1;
subcalls[1] = subcall2;
uint balanceBefore = tokens.DAI.balanceOf(address(this));
emit log_named_uint("DAI Balance Before", balanceBefore);
emit log_string("Multihop Rfqt: WETH->USDC->DAI");
/// @dev Sells `sellAmount` of the input token (`tokens[0]`)
/// via the given sequence of tokens and calls.
/// The last token in `tokens` is the output token that
/// will ultimately be sent to `msg.sender`
/// @param tokens The sequence of tokens to use for the sell,
/// i.e. `tokens[i]` will be sold for `tokens[i+1]` via
/// `calls[i]`.
/// @param calls The sequence of calls to use for the sell.
/// @param sellAmount The amount of `inputToken` to sell.
/// @param minBuyAmount The minimum amount of output tokens that
/// must be bought for this function to not revert.
/// @return boughtAmount The amount of output tokens bought.
IZERO_EX.multiplexMultiHopSellTokenForToken(
// input token[] [input, intermediate, output]
tradeTokens,
//array of subcalls [{},{}]
subcalls,
// input token amount
inputAmount,
// min output token amount
outputAmount
);
uint balanceAfter = tokens.DAI.balanceOf(address(this));
emit log_named_uint("DAI Balance After", balanceAfter - balanceBefore);
require(balanceAfter >= 5e17, "Failed: UNDERBOUGHT");
}
function createOtcOrder(
IERC20Token inputToken,
IERC20Token ouputToken,
uint128 takerAmount,
uint128 makerAmount,
uint bump
) public returns (LibNativeOrder.OtcOrder memory order, LibSignature.Signature memory signature) {
LibNativeOrder.OtcOrder memory order;
LibSignature.Signature memory signature;
order.makerToken = ouputToken;
order.takerToken = inputToken;
order.takerAmount = takerAmount;
order.makerAmount = makerAmount;
uint privateKey;
(order.maker, privateKey) = _getSigner();
deal(address(order.makerToken), order.maker, 2e20);
deal(address(order.takerToken), order.maker, 2e20);
vm.startPrank(order.maker);
IERC20Token(order.makerToken).approveIfBelow(addresses.exchangeProxy, 2e20);
order.taker = address(0);
order.txOrigin = address(tx.origin);
order.expiryAndNonce = encodeExpiryAndNonce(order.maker, bump);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, IZERO_EX.getOtcOrderHash(order));
vm.stopPrank();
signature.signatureType = LibSignature.SignatureType.EIP712;
signature.v = v;
signature.r = r;
signature.s = s;
return (order, signature);
}
/* solhint-enable function-max-lines */
function encodeExpiryAndNonce(address maker, uint bump) public returns (uint256) {
uint256 expiry = (block.timestamp + 120) << 192;
uint256 bucket = (0 + bump) << 128;
uint256 nonce = vm.getNonce(maker);
return expiry | bucket | nonce;
}
}

View File

@ -54,6 +54,76 @@ contract SwapERC20ForERC20Test is Test, ForkUtils, TestUtils {
}
}
function test_swapERC20ForERC20OnTraderJoeV2() public {
for (uint256 i = 0; i < chains.length; i++) {
// TraderJoeV2 mixin only enabled on Avalanche and Arbitrum
if (i != 3 && i != 6) {
continue;
}
vm.selectFork(forkIds[chains[i]]);
labelAddresses(
chains[i],
indexChainsByChain[chains[i]],
getTokens(i),
getContractAddresses(i),
getLiquiditySourceAddresses(i)
);
swapOnTraderJoeV2(getTokens(i), getContractAddresses(i), getLiquiditySourceAddresses(i));
}
}
function swapOnTraderJoeV2(
TokenAddresses memory tokens,
ContractAddresses memory addresses,
LiquiditySources memory sources
) public onlyForked {
if (sources.TraderJoeV2Router == address(0)) {
emit log_string("TraderJoeV2Router not available on this chain");
return;
}
if (sources.TraderJoeV2Quoter == address(0)) {
emit log_string("TraderJoeV2Quoter not available on this chain");
return;
}
FillQuoteTransformer.TransformData memory fqtData;
fqtData.side = FillQuoteTransformer.Side.Sell;
fqtData.sellToken = IERC20Token(address(tokens.USDC));
fqtData.buyToken = IERC20Token(address(tokens.USDT));
fqtData.fillSequence = new FillQuoteTransformer.OrderType[](1);
fqtData.fillSequence[0] = FillQuoteTransformer.OrderType.Bridge;
fqtData.fillAmount = 1e6;
(uint256 amountOut, uint256 binStep, uint256 version) = sampleTraderJoeV2(
fqtData.fillAmount,
address(fqtData.sellToken),
address(fqtData.buyToken),
sources.TraderJoeV2Quoter
);
log_named_uint("amountOut", amountOut);
IBridgeAdapter.BridgeOrder memory order;
{
address[] memory tokenPath = new address[](2);
tokenPath[0] = address(fqtData.sellToken);
tokenPath[1] = address(fqtData.buyToken);
uint256[] memory binSteps = new uint256[](1);
binSteps[0] = binStep;
uint256[] memory versions = new uint256[](1);
versions[0] = version;
order.bridgeData = abi.encode(address(sources.TraderJoeV2Router), tokenPath, binSteps, versions);
}
order.source = bytes32(uint256(BridgeProtocols.TRADERJOEV2) << 128);
order.takerTokenAmount = fqtData.fillAmount;
order.makerTokenAmount = amountOut;
fqtData.bridgeOrders = new IBridgeAdapter.BridgeOrder[](1);
fqtData.bridgeOrders[0] = order;
settleAndLogBalances(fqtData, tokens, addresses);
}
function swapOnKyberElastic(
TokenAddresses memory tokens,
ContractAddresses memory addresses,
@ -71,20 +141,6 @@ contract SwapERC20ForERC20Test is Test, ForkUtils, TestUtils {
emit log_string("KyberElasticPool not available on this chain");
return;
}
ITransformERC20Feature.Transformation[] memory transformations = new ITransformERC20Feature.Transformation[](2);
transformations[0].deploymentNonce = _findTransformerNonce(
address(addresses.transformers.wethTransformer),
address(addresses.exchangeProxyTransformerDeployer)
);
emit log_named_uint("WethTransformer nonce", transformations[0].deploymentNonce);
createNewFQT(tokens.WrappedNativeToken, addresses.exchangeProxy, addresses.exchangeProxyTransformerDeployer);
transformations[0].data = abi.encode(LibERC20Transformer.ETH_TOKEN_ADDRESS, 1e18);
transformations[1].deploymentNonce = _findTransformerNonce(
address(fillQuoteTransformer),
address(addresses.exchangeProxyTransformerDeployer)
);
emit log_named_uint("FillQuoteTransformer nonce", transformations[1].deploymentNonce);
FillQuoteTransformer.TransformData memory fqtData;
fqtData.side = FillQuoteTransformer.Side.Sell;
@ -111,37 +167,8 @@ contract SwapERC20ForERC20Test is Test, ForkUtils, TestUtils {
order.makerTokenAmount = amountOut;
order.bridgeData = abi.encode(address(sources.KyberElasticRouter), path);
fqtData.bridgeOrders[0] = order;
transformations[1].data = abi.encode(fqtData);
vm.deal(address(this), 1e18);
uint256 balanceETHBefore = address(this).balance;
uint256 balanceERC20Before = IERC20Token(tokens.USDT).balanceOf(address(this));
writeTokenBalance(address(this), address(tokens.USDC), 1e16);
uint256 balanceUSDCbefore = IERC20Token(tokens.USDC).balanceOf(address(this));
IERC20Token(address(tokens.USDC)).approve(addresses.exchangeProxy, 1e16);
IZeroEx(payable(addresses.exchangeProxy)).transformERC20{value: 1e18}(
// input token
IERC20Token(address(tokens.USDC)),
// output token
IERC20Token(address(tokens.USDT)),
// input token amount
1e6,
// min output token amount
order.makerTokenAmount,
// list of transform
transformations
);
log_named_uint("NativeAsset balance before", balanceETHBefore);
log_named_uint("ERC-20 balance before", balanceERC20Before);
log_named_uint("NativeAsset balance after", balanceETHBefore - address(this).balance);
log_named_uint("ERC-20 balance after", IERC20Token(tokens.USDT).balanceOf(address(this)) - balanceERC20Before);
log_named_uint("USDC balance before", balanceUSDCbefore);
log_named_uint("USDC balance after", IERC20Token(tokens.USDT).balanceOf(address(tokens.USDC)));
assert(IERC20Token(tokens.USDT).balanceOf(address(this)) > 0);
settleAndLogBalances(fqtData, tokens, addresses);
}
function sampleKyberElastic(
@ -150,7 +177,7 @@ contract SwapERC20ForERC20Test is Test, ForkUtils, TestUtils {
address makerToken,
address quoter,
address pool
) public returns (uint256 makerTokenAmount, bytes memory path) {
) private returns (uint256 makerTokenAmount, bytes memory path) {
log_string(" Sampling KyberElastic for tokens");
log_named_address(" ", takerToken);
log_string(" -> ");
@ -167,4 +194,67 @@ contract SwapERC20ForERC20Test is Test, ForkUtils, TestUtils {
(uint256 amountOut, , , ) = kyberQuoter.quoteExactInput(path, amount);
return (amountOut, path);
}
function sampleTraderJoeV2(
uint256 amount,
address takerToken,
address makerToken,
address quoter
) private returns (uint256 makerTokenAmount, uint256 binStep, uint256 version) {
log_string("Sampling TraderJoeV2");
log_named_address("takerToken", takerToken);
log_named_address("makerToken", makerToken);
log_named_address("quoter", quoter);
address[] memory tokenPath = new address[](2);
tokenPath[0] = takerToken;
tokenPath[1] = makerToken;
ITraderJoeV2Quoter.Quote memory quote = ITraderJoeV2Quoter(quoter).findBestPathFromAmountIn(
tokenPath,
uint128(amount)
);
return (quote.amounts[1], quote.binSteps[0], uint256(quote.versions[0]));
}
function deployFQTAndGetDeploymentNonce(
TokenAddresses memory tokens,
ContractAddresses memory addresses
) private returns (uint32) {
createNewFQT(tokens.WrappedNativeToken, addresses.exchangeProxy, addresses.exchangeProxyTransformerDeployer);
return
_findTransformerNonce(address(fillQuoteTransformer), address(addresses.exchangeProxyTransformerDeployer));
}
function settleAndLogBalances(
FillQuoteTransformer.TransformData memory fqtData,
TokenAddresses memory tokens,
ContractAddresses memory addresses
) private {
ITransformERC20Feature.Transformation[] memory transformations = new ITransformERC20Feature.Transformation[](1);
transformations[0].deploymentNonce = deployFQTAndGetDeploymentNonce(tokens, addresses);
transformations[0].data = abi.encode(fqtData);
address sellToken = address(fqtData.sellToken);
address buyToken = address(fqtData.buyToken);
writeTokenBalance(address(this), sellToken, 1e16);
uint256 sellTokenBalanceBefore = IERC20Token(sellToken).balanceOf(address(this));
uint256 buyTokenBalanceBefore = IERC20Token(buyToken).balanceOf(address(this));
IERC20Token(sellToken).approve(addresses.exchangeProxy, 1e16);
IZeroEx(payable(addresses.exchangeProxy)).transformERC20(
IERC20Token(sellToken),
IERC20Token(buyToken),
fqtData.fillAmount,
fqtData.bridgeOrders[0].makerTokenAmount,
transformations
);
log_named_uint("sellToken balance before", sellTokenBalanceBefore);
log_named_uint("sellToken balance after", IERC20Token(sellToken).balanceOf(address(this)));
log_named_uint("buyToken balance before", buyTokenBalanceBefore);
log_named_uint("buyToken balance after", IERC20Token(buyToken).balanceOf(address(this)));
}
}

View File

@ -0,0 +1,35 @@
// 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 "../../../contracts/src/transformers/bridges/AvalancheBridgeAdapter.sol";
import "../../../contracts/src/transformers/bridges/BridgeProtocols.sol";
contract AvalancheBridgeAdapterTest is Test {
address constant WAVAX = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;
AvalancheBridgeAdapter private adapter;
function setUp() public {
vm.chainId(43114);
adapter = new AvalancheBridgeAdapter(IEtherToken(WAVAX));
}
function testSupportsUniswapV3() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.UNISWAPV3) << 128)));
}
}

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.6.5;
pragma experimental ABIEncoderV2;
import "forge-std/Test.sol";
import "../../../contracts/src/transformers/bridges/BSCBridgeAdapter.sol";
import "../../../contracts/src/transformers/bridges/BridgeProtocols.sol";
contract BSCBridgeAdapterTest is Test {
address constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c;
BSCBridgeAdapter private adapter;
function setUp() public {
vm.chainId(56);
adapter = new BSCBridgeAdapter(IEtherToken(WBNB));
}
function testSupportsUniswapV3() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.UNISWAPV3) << 128)));
}
function testSupportMaverickV1() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.MAVERICKV1) << 128)));
}
}

View File

@ -0,0 +1,47 @@
// 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 "../../../contracts/src/transformers/bridges/BaseBridgeAdapter.sol";
import "../../../contracts/src/transformers/bridges/BridgeProtocols.sol";
contract BaseBridgeAdapterTest is Test {
address constant WETH = 0x4200000000000000000000000000000000000006;
BaseBridgeAdapter private adapter;
function setUp() public {
vm.chainId(8453);
adapter = new BaseBridgeAdapter(IEtherToken(WETH));
}
function testSupportsUniswapV3() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.UNISWAPV3) << 128)));
}
function testSupportMaverickV1() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.MAVERICKV1) << 128)));
}
function testSupportSolidly() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.SOLIDLY) << 128)));
}
function testSupportVelodromeV2() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.VELODROMEV2) << 128)));
}
}

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.6.5;
pragma experimental ABIEncoderV2;
import "forge-std/Test.sol";
import "../../../contracts/src/transformers/bridges/EthereumBridgeAdapter.sol";
import "../../../contracts/src/transformers/bridges/BridgeProtocols.sol";
contract EthereumBridgeAdapterTest is Test {
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
EthereumBridgeAdapter private adapter;
function setUp() public {
vm.chainId(1);
adapter = new EthereumBridgeAdapter(IEtherToken(WETH));
}
function testSupportsUniswapV3() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.UNISWAPV3) << 128)));
}
function testSupportMaverickV1() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.MAVERICKV1) << 128)));
}
}

View File

@ -0,0 +1,35 @@
// 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 "../../../contracts/src/transformers/bridges/OptimismBridgeAdapter.sol";
import "../../../contracts/src/transformers/bridges/BridgeProtocols.sol";
contract OptimismBridgeAdapterTest is Test {
address constant WETH = 0x4200000000000000000000000000000000000006;
OptimismBridgeAdapter private adapter;
function setUp() public {
vm.chainId(10);
adapter = new OptimismBridgeAdapter(IEtherToken(WETH));
}
function testSupportVelodromeV2() public {
assertTrue(adapter.isSupportedSource(bytes32(uint256(BridgeProtocols.VELODROMEV2) << 128)));
}
}

View File

@ -28,6 +28,7 @@ import "src/features/FundRecoveryFeature.sol";
import "src/features/TransformERC20Feature.sol";
import "src/features/OtcOrdersFeature.sol";
import "src/features/MetaTransactionsFeature.sol";
import "src/features/MetaTransactionsFeatureV2.sol";
import "src/features/nft_orders/ERC1155OrdersFeature.sol";
import "src/features/nft_orders/ERC721OrdersFeature.sol";
import "src/features/UniswapFeature.sol";
@ -68,6 +69,7 @@ contract DeployZeroEx is Test {
FundRecoveryFeature fundRecoveryFeature;
TransformERC20Feature transformERC20Feature;
MetaTransactionsFeature metaTransactionsFeature;
MetaTransactionsFeatureV2 metaTransactionsFeatureV2;
ERC1155OrdersFeature erc1155OrdersFeature;
ERC721OrdersFeature erc721OrdersFeature;
MultiplexFeature multiplexFeature;
@ -133,6 +135,10 @@ contract DeployZeroEx is Test {
emit log_named_address("UniswapV3Feature", address(ZERO_EX_DEPLOYED.features.uniswapV3Feature));
emit log_named_address("FundRecoveryFeature", address(ZERO_EX_DEPLOYED.features.fundRecoveryFeature));
emit log_named_address("MetaTransactionsFeature", address(ZERO_EX_DEPLOYED.features.metaTransactionsFeature));
emit log_named_address(
"MetaTransactionsFeatureV2",
address(ZERO_EX_DEPLOYED.features.metaTransactionsFeatureV2)
);
emit log_named_address("ERC1155OrdersFeature", address(ZERO_EX_DEPLOYED.features.erc1155OrdersFeature));
emit log_named_address("ERC721OrdersFeature", address(ZERO_EX_DEPLOYED.features.erc721OrdersFeature));
emit log_named_address("TransformERC20Feature", address(ZERO_EX_DEPLOYED.features.transformERC20Feature));
@ -201,6 +207,10 @@ contract DeployZeroEx is Test {
);
ZERO_EX_DEPLOYED.features.fundRecoveryFeature = new FundRecoveryFeature();
ZERO_EX_DEPLOYED.features.metaTransactionsFeature = new MetaTransactionsFeature(address(ZERO_EX));
ZERO_EX_DEPLOYED.features.metaTransactionsFeatureV2 = new MetaTransactionsFeatureV2(
address(ZERO_EX),
ZERO_EX_DEPLOYED.weth
);
ZERO_EX_DEPLOYED.features.erc1155OrdersFeature = new ERC1155OrdersFeature(
address(ZERO_EX),
ZERO_EX_DEPLOYED.weth
@ -270,6 +280,11 @@ contract DeployZeroEx is Test {
abi.encodeWithSelector(MetaTransactionsFeature.migrate.selector),
address(this)
);
IZERO_EX.migrate(
address(ZERO_EX_DEPLOYED.features.metaTransactionsFeatureV2),
abi.encodeWithSelector(MetaTransactionsFeatureV2.migrate.selector),
address(this)
);
IZERO_EX.migrate(
address(ZERO_EX_DEPLOYED.features.erc1155OrdersFeature),
abi.encodeWithSelector(ERC1155OrdersFeature.migrate.selector),

View File

@ -88,10 +88,13 @@ struct TokenAddresses {
IEtherToken WrappedNativeToken;
}
// keep the names of the struct members in alphabetical order for correct json unparsing
struct LiquiditySources {
address KyberElasticPool;
address KyberElasticQuoter;
address KyberElasticRouter;
address TraderJoeV2Quoter;
address TraderJoeV2Router;
address UniswapV2Router;
address UniswapV3Router;
}
@ -100,6 +103,29 @@ interface IFQT {
function bridgeAdapter() external returns (address);
}
interface ITraderJoeV2Quoter {
enum Version {
V1,
V2,
V2_1
}
struct Quote {
address[] route;
address[] pairs;
uint256[] binSteps;
Version[] versions;
uint128[] amounts;
uint128[] virtualAmountsWithoutSlippage;
uint128[] fees;
}
function findBestPathFromAmountIn(
address[] calldata route,
uint128 amountIn
) external view returns (Quote memory quote);
}
interface IKyberElasticQuoter {
function quoteExactInput(
bytes memory path,

View File

@ -54,6 +54,9 @@ contract LocalTest is Test, TestUtils {
address internal signerAddress;
uint256 internal signerKey;
address internal otherSignerAddress;
uint256 internal otherSignerKey;
function _infiniteApprovals() private {
shib.approve(address(zeroExDeployed.zeroEx), type(uint256).max);
dai.approve(address(zeroExDeployed.zeroEx), type(uint256).max);
@ -92,12 +95,23 @@ contract LocalTest is Test, TestUtils {
zrx = IERC20Token(address(new TestMintableERC20Token()));
weth = zeroExDeployed.weth;
// TODO this should be somewhere else
string memory mnemonic = "conduct into noodle wreck before satisfy alarm vendor dose lunch vapor party";
otherSignerKey = vm.deriveKey(mnemonic, 0);
otherSignerAddress = vm.addr(otherSignerKey);
vm.label(otherSignerAddress, "zeroEx/OtherGuy");
_infiniteApprovals();
vm.startPrank(signerAddress);
_infiniteApprovals();
vm.stopPrank();
vm.deal(address(this), 10e18);
vm.startPrank(otherSignerAddress);
_infiniteApprovals();
vm.stopPrank();
vm.deal(address(this), 20e18);
}
function _mintTo(address token, address recipient, uint256 amount) internal {

View File

@ -20,6 +20,8 @@ import "forge-std/Test.sol";
import "src/transformers/LibERC20Transformer.sol";
contract TestUtils is Test {
address private constant ZERO_ADDRESS = 0x0000000000000000000000000000000000000000;
function _findTransformerNonce(address transformer, address deployer) internal pure returns (uint32) {
address current;
for (uint32 i = 0; i < 1024; i++) {

View File

@ -6,6 +6,8 @@
"generated-artifacts/AffiliateFeeTransformer.json",
"generated-artifacts/AvalancheBridgeAdapter.json",
"generated-artifacts/BSCBridgeAdapter.json",
"generated-artifacts/BaseBridgeAdapter.json",
"generated-artifacts/BaseGoerliBridgeAdapter.json",
"generated-artifacts/BatchFillNativeOrdersFeature.json",
"generated-artifacts/CeloBridgeAdapter.json",
"generated-artifacts/CurveLiquidityProvider.json",
@ -30,6 +32,7 @@
"generated-artifacts/LiquidityProviderFeature.json",
"generated-artifacts/LogMetadataTransformer.json",
"generated-artifacts/MetaTransactionsFeature.json",
"generated-artifacts/MetaTransactionsFeatureV2.json",
"generated-artifacts/MultiplexFeature.json",
"generated-artifacts/NativeOrdersFeature.json",
"generated-artifacts/OptimismBridgeAdapter.json",
@ -47,6 +50,8 @@
"test/generated-artifacts/ArbitrumBridgeAdapter.json",
"test/generated-artifacts/AvalancheBridgeAdapter.json",
"test/generated-artifacts/BSCBridgeAdapter.json",
"test/generated-artifacts/BaseBridgeAdapter.json",
"test/generated-artifacts/BaseGoerliBridgeAdapter.json",
"test/generated-artifacts/BatchFillNativeOrdersFeature.json",
"test/generated-artifacts/BootstrapFeature.json",
"test/generated-artifacts/BridgeProtocols.json",
@ -88,6 +93,7 @@
"test/generated-artifacts/ILiquidityProviderFeature.json",
"test/generated-artifacts/ILiquidityProviderSandbox.json",
"test/generated-artifacts/IMetaTransactionsFeature.json",
"test/generated-artifacts/IMetaTransactionsFeatureV2.json",
"test/generated-artifacts/IMooniswapPool.json",
"test/generated-artifacts/IMultiplexFeature.json",
"test/generated-artifacts/INativeOrdersEvents.json",
@ -141,10 +147,10 @@
"test/generated-artifacts/LiquidityProviderSandbox.json",
"test/generated-artifacts/LogMetadataTransformer.json",
"test/generated-artifacts/MetaTransactionsFeature.json",
"test/generated-artifacts/MetaTransactionsFeatureV2.json",
"test/generated-artifacts/MixinAaveV2.json",
"test/generated-artifacts/MixinBalancer.json",
"test/generated-artifacts/MixinBalancerV2Batch.json",
"test/generated-artifacts/MixinBancor.json",
"test/generated-artifacts/MixinBancorV3.json",
"test/generated-artifacts/MixinCompound.json",
"test/generated-artifacts/MixinCryptoCom.json",
@ -155,12 +161,10 @@
"test/generated-artifacts/MixinGMX.json",
"test/generated-artifacts/MixinKyberDmm.json",
"test/generated-artifacts/MixinLido.json",
"test/generated-artifacts/MixinMStable.json",
"test/generated-artifacts/MixinMakerPSM.json",
"test/generated-artifacts/MixinMooniswap.json",
"test/generated-artifacts/MixinNerve.json",
"test/generated-artifacts/MixinPlatypus.json",
"test/generated-artifacts/MixinShell.json",
"test/generated-artifacts/MixinSolidly.json",
"test/generated-artifacts/MixinSynthetix.json",
"test/generated-artifacts/MixinUniswap.json",

BIN
docs/_static/img/logo.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

15
docs/_static/img/logo.svg generated vendored
View File

@ -1,15 +0,0 @@
<svg width="1028" height="500" viewBox="0 0 1028 500" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0)">
<path fill-rule="evenodd" clip-rule="evenodd" d="M656.054 246.637C656.054 163.677 690.359 122.422 743.722 122.422C796.861 122.422 831.839 164.35 831.839 246.637C831.839 328.924 796.861 370.628 743.722 370.628C690.583 370.628 656.054 328.924 656.054 246.637ZM743.498 149.327C704.933 149.327 685.874 185.426 685.874 246.861C685.874 275.785 690.135 298.206 698.206 314.574L773.991 159.641C765.247 152.691 755.157 149.327 743.498 149.327ZM713.677 334.305C722.197 340.807 732.063 344.171 743.722 344.171C782.287 344.171 801.794 307.848 801.794 246.861C801.794 218.61 797.758 196.413 789.462 179.597L713.677 334.305Z" fill="black"/>
<path d="M1022.87 194.17L973.991 277.13L1027.35 366.368H994.619L951.794 294.17H939.686L895.964 366.368H864.126L917.713 278.251L869.507 194.17H900.449L939.91 262.556H952.242L992.601 194.17H1022.87Z" fill="black"/>
<path d="M105.022 316.009L143.834 275.852L95.583 210.74L34.148 123.812C12.4439 160.852 0 203.969 0 250C0 326.256 34.148 394.529 88.0045 440.381L165.987 385.269C139.462 368.744 118.094 344.686 105.022 316.009Z" fill="black"/>
<path d="M183.991 105.022L224.148 143.834L289.26 95.583L376.188 34.148C339.148 12.4439 296.031 0 250 0C173.744 0 105.471 34.148 59.6188 88.0045L114.731 165.987C131.256 139.462 155.314 118.094 183.991 105.022Z" fill="black"/>
<path d="M356.166 224.148L404.417 289.26L465.852 376.188C487.556 339.148 500 296.031 500 250C500 173.744 465.852 105.471 411.996 59.6188L334.013 114.731C360.538 131.256 381.906 155.314 394.978 183.991L356.166 224.148Z" fill="black"/>
<path d="M440.381 411.996L385.269 334.014C368.744 360.538 344.686 381.906 316.009 394.978L275.852 356.166L210.74 404.417L123.812 465.852C160.852 487.556 203.969 500 250 500C326.256 500 394.529 465.852 440.381 411.996Z" fill="black"/>
</g>
<defs>
<clipPath id="clip0">
<rect width="1027.35" height="500" fill="white"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -4,28 +4,34 @@ Audits
Below are links to our third-party audit reports.
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| **Release** | **Reports** |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| ERC721OrdersFeature | * `ABDK Consulting <https://s3.us-east-2.amazonaws.com/zeips.0x.org/audits/abdk-consulting/ABDK_0x_Solidity_v_1_0.pdf>`__ |
| | |
| | |
| ERC1155OrdersFeature | |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| Exchange V4 | * `Consensys Diligence (December 2020) <https://consensys.net/diligence/audits/2020/12/0x-exchange-v4/>`__ |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| Exchange V3 | * `Trail of Bits <http://zeips.0x.org.s3-website.us-east-2.amazonaws.com/audits/56/trail-of-bits/audit.pdf>`__ |
| | * `Consensys Diligence (Exchange) <https://diligence.consensys.net/audits/2019/09/0x-v3-exchange/>`__ |
| | * `Consensys Diligence (Staking) <https://diligence.consensys.net/audits/2019/10/0x-v3-staking/>`__ |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| Exchange V2.1 | * `First <https://docs.google.com/document/d/1jYv6V21MfCSwCS5fxD6ZyaLWGzkpRSUO0lZpST94XsA/edit>`_ |
| | * `Consensys Diligence <https://github.com/ConsenSys/0x_audit_report_2018-07-23>`_ |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| MultiAssetProxy | * `Consensys Diligence <https://github.com/ConsenSys/0x-audit-report-2018-12>`__ |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| ERC1155Proxy | * `Consensys Diligence <https://github.com/ConsenSys/0x-audit-report-2019-05>`__ |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| StaticCallProxy | * No third-party audit. |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
| ERC20BridgeProxy | * No third-party audit. |
+----------------------+---------------------------------------------------------------------------------------------------------------------------+
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| **Release** | **Reports** |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Governance | * `Ourovoros <https://github.com/0xProject/protocol/blob/development/contracts/governance/audits/0xProtocol-06-04-2023-Final.pdf>`__ |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| MultiplexFeature | * `ABDK Consulting <https://github.com/0xProject/ZEIPs/blob/master/zeip96_images/ABDK_0x_MetaTransaction_v_1_0.pdf>`__ |
| | |
| MetaTransactions | |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ERC721OrdersFeature | * `ABDK Consulting <https://s3.us-east-2.amazonaws.com/zeips.0x.org/audits/abdk-consulting/ABDK_0x_Solidity_v_1_0.pdf>`__ |
| | |
| | |
| ERC1155OrdersFeature | |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V4 | * `Consensys Diligence (December 2020) <https://consensys.net/diligence/audits/2020/12/0x-exchange-v4/>`__ |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V3 | * `Trail of Bits <http://zeips.0x.org.s3-website.us-east-2.amazonaws.com/audits/56/trail-of-bits/audit.pdf>`__ |
| | * `Consensys Diligence (Exchange) <https://diligence.consensys.net/audits/2019/09/0x-v3-exchange/>`__ |
| | * `Consensys Diligence (Staking) <https://diligence.consensys.net/audits/2019/10/0x-v3-staking/>`__ |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V2.1 | * `First <https://docs.google.com/document/d/1jYv6V21MfCSwCS5fxD6ZyaLWGzkpRSUO0lZpST94XsA/edit>`_ |
| | * `Consensys Diligence <https://github.com/ConsenSys/0x_audit_report_2018-07-23>`_ |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| MultiAssetProxy | * `Consensys Diligence <https://github.com/ConsenSys/0x-audit-report-2018-12>`__ |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ERC1155Proxy | * `Consensys Diligence <https://github.com/ConsenSys/0x-audit-report-2019-05>`__ |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| StaticCallProxy | * No third-party audit. |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ERC20BridgeProxy | * No third-party audit. |
+----------------------+--------------------------------------------------------------------------------------------------------------------------------------+

View File

@ -19,14 +19,14 @@ The following contracts are in scope of the bug bounty. Please note that any bug
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| **Release** | **Contracts** | **Commit Hash** |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V4 | * Documentation at `https://protocol.0x.org/en/latest/ <https://protocol.0x.org/en/latest/>`__ | `c1177416f5 <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts>`__ |
| | * `ZeroEx.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/ZeroEx.sol>`__ | |
| | * `ZeroExOptimized.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/ZeroExOptimized.sol>`__ | |
| | * `external/*.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/external>`__ | |
| | * `features/**.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/features>`__ | |
| | * `fixins/*.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/fixins>`__ | |
| | * `migrations/*.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/migrations>`__ | |
| | * `storage/*.sol <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src/storage>`__ | |
| Exchange V4 | * Documentation at `https://docs.0xProtocol.org/en/latest/ <https://docs.0xProtocol.org/en/latest/>`__ | |
| | * `ZeroEx.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/ZeroEx.sol>`__ | |
| | * `ZeroExOptimized.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/ZeroExOptimized.sol>`__ | |
| | * `external/*.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/external>`__ | |
| | * `features/*.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/features>`__ | |
| | * `fixins/*.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/fixins>`__ | |
| | * `migrations/*.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/migrations>`__ | |
| | * `storage/*.sol <https://github.com/0xProject/protocol/tree/development/contracts/zero-ex/contracts/src/storage>`__ | |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Exchange V3 | * `ERC20BridgeProxy.sol <https://github.com/0xProject/0x-monorepo/blob/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts/asset-proxy/contracts/src/ERC20BridgeProxy.sol>`_ (`spec <https://github.com/0xProject/0x-protocol-specification/blob/master/asset-proxy/erc20-bridge-proxy.md>`__) | `fb8360edfd <https://github.com/0xProject/0x-monorepo/tree/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts>`__ |
| | * `Exchange.sol <https://github.com/0xProject/0x-monorepo/blob/fb8360edfd4f42f2d2b127b95c156eb1b0daa02b/contracts/exchange/contracts/src/Exchange.sol>`__ (`spec <https://github.com/0xProject/0x-protocol-specification/blob/master/v3/v3-specification.md>`__) | |
@ -46,8 +46,6 @@ The following contracts are in scope of the bug bounty. Please note that any bug
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ERC20BridgeProxy | * `ERC20BridgeProxy.sol <https://github.com/0xProject/0x-monorepo/blob/281658ba349a2c5088b40b503998bea5020284a6/contracts/asset-proxy/contracts/src/ERC20BridgeProxy.sol>`__ | `281658ba34 <https://github.com/0xProject/0x-monorepo/tree/281658ba349a2c5088b40b503998bea5020284a6/contracts>`_ |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| ExchangeProxy | * `contracts/src <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src>`__ | `c1177416f5 <https://github.com/0xProject/protocol/tree/c1177416f50c2465ee030dacc14ff996eebd4e74/contracts/zero-ex/contracts/src>`_ |
+------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
Bounties
--------
@ -67,19 +65,10 @@ The final reward amount is at the sole discretion of 0x Labs and will be paid in
| Low (CVSS 0.0 - 3.9) | up to $5,000 |
+----------------------------+---------------------+
Recent Inclusions
-----------------
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| **Change** | **** |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
| NFT feature | * Trade ERC721 and ERC1155 assets. See `ZEIP-93 <https://github.com/0xProject/ZEIPs/issues/93>`__ for more details |
+---------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
Disclosures
-----------
Please e-mail all submissions to security@0x.org with the subject "BUG BOUNTY". Your submission
should include any steps required to reproduce or exploit the vulnerability. Please allow time for
the vulnerability to be fixed before discussing any findings publicly. After receiving a submission,
we will contact you with expected timelines for a fix to be implemented.
we will contact you with expected timelines for a fix to be implemented.

View File

@ -62,16 +62,16 @@ Function timelocks are represented in days, where one day is equivalent to 86,40
.. csv-table::
:header: "Contract", "Function", "Selector", "Timelock"
AllowanceTarget, ``addAuthorizedAddress``, ``42f1181e``, 2 days
AllowanceTarget, ``addAuthorizedAddress``, ``42f1181e``, 2 day
AllowanceTarget, ``removeAuthorizedAddress``, ``70712939``, 0 days
AllowanceTarget, ``removeAuthorizedAddressAtIndex``, ``9ad26744``, 0 days
Governor, ``registerFunctionCall``, ``751ad560``, 2 days
ExchangeProxy, ``extend``, ``6eb224cb``, 2 days
ExchangeProxy, ``migrate``, ``261fe679``, 2 days
Governor, ``registerFunctionCall``, ``751ad560``, 2 day
ExchangeProxy, ``extend``, ``6eb224cb``, 2 day
ExchangeProxy, ``migrate``, ``261fe679``, 2 day
ExchangeProxy, ``rollback``, ``9db64a40``, 0 days
ExchangeProxy, ``setQuoteSigner``, ``<deprecation in progress>``, 2 days
ExchangeProxy, ``setTransformerDeployer``, ``87c96419``, 2 days
ExchangeProxy, ``transferOwnership``, ``f2fde38b``, 2 days
ExchangeProxy, ``setQuoteSigner``, ``<deprecation in progress>``, 2 day
ExchangeProxy, ``setTransformerDeployer``, ``87c96419``, 2 day
ExchangeProxy, ``transferOwnership``, ``f2fde38b``, 2 day
StakingProxy, ``addExchangeAddress``, ``8a2e271a``, 14 days
StakingProxy, ``removeExchangeAddress``, ``01e28d84``, 14 days
StakingProxy, ``attachStakingContract``, ``66615d56``, 14 days

View File

@ -2,7 +2,7 @@
Overview
###############################
The 0x Exchange implements a delegate-call proxy pattern to create a system of composable smart contracts. This architecture enables 0x to innovate with minimal friction alongside the growing DeFi ecosystem.
The `ZeroEx` (Exchange Proxy) contract implements a delegate-call proxy pattern to create a system of composable smart contracts. This architecture enables 0x Protocol to innovate with minimal friction alongside the growing DeFi ecosystem.
The diagram below illustrates our system (click to enlarge).
@ -24,13 +24,7 @@ The table below defines our smart contract nomenclature.
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `Flash Wallet <./flash_wallet.html>`_ | The Flash Wallet is a sandboxed escrow contract that holds funds for Transformers to operate on. For example, the ``WETHtransformer`` wraps any Ether in the Flash Wallet. |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `Allowance Target <../basics/allowances.html>`_ | Users set their allowances on this contract. It is scheduled to be deprecated after the official V4 release in January, 2021. After which point allowances will be set directly on the Proxy. |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `Governor <./governor.html>`_ | A MultiSig that governs trusted contracts in the system: Proxy, Features, Flash Wallet. |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `Transformer Deployer <./transformer_deployer.html>`_ | Deploys Transformers. A transformer is authenticated using a nonce of the Transformer Deployer. |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `Fee Collectors <./fee_collectors.html>`_ | `Protocol fees <../basics/protocol_fees.html>`_ are paid into these contracts at time-of-fill. |
| `Governor <./governor.html>`_ | A smart contract that governs trusted contracts in the system: Proxy, Features, Flash Wallet. |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| `PLP Sandbox <./plp_sandbox.html>`_ | `PLP <../advanced/plp.html>`_ liquidity providers are called from this sandbox. |
+-------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

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