This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b020c5
commit db8ed91
Showing
23 changed files
with
872 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright 2019 ZeroEx Intl. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IEth2Dai.sol"; | ||
import "@0x/contracts-erc20/contracts/test/DummyERC20Token.sol"; | ||
|
||
|
||
contract TestEth2Dai is | ||
IEth2Dai | ||
{ | ||
function sellAllAmount( | ||
address sellTokenAddress, | ||
uint256 sellTokenAmount, | ||
address buyTokenAddress, | ||
uint256 minimumFillAmount | ||
) | ||
external | ||
returns (uint256 fillAmount) | ||
{ | ||
DummyERC20Token(sellTokenAddress).transferFrom( | ||
msg.sender, | ||
address(this), | ||
sellTokenAmount | ||
); | ||
DummyERC20Token buyToken = DummyERC20Token(buyTokenAddress); | ||
buyToken.mint(minimumFillAmount); | ||
buyToken.transfer( | ||
msg.sender, | ||
minimumFillAmount | ||
); | ||
return minimumFillAmount; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
contracts/integrations/contracts/test/TestEth2DaiBridge.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2019 ZeroEx Intl. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "@0x/contracts-asset-proxy/contracts/src/bridges/Eth2DaiBridge.sol"; | ||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IEth2Dai.sol"; | ||
|
||
|
||
contract TestEth2DaiBridge is | ||
Eth2DaiBridge | ||
{ | ||
// solhint-disable var-name-mixedcase | ||
address public TEST_ETH2DAI_ADDRESS; | ||
|
||
constructor (address testEth2Dai) | ||
public | ||
{ | ||
TEST_ETH2DAI_ADDRESS = testEth2Dai; | ||
} | ||
|
||
function _getEth2DaiContract() | ||
internal | ||
view | ||
returns (IEth2Dai exchange) | ||
{ | ||
return IEth2Dai(TEST_ETH2DAI_ADDRESS); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
contracts/integrations/contracts/test/TestUniswapBridge.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright 2019 ZeroEx Intl. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "@0x/contracts-asset-proxy/contracts/src/bridges/UniswapBridge.sol"; | ||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchangeFactory.sol"; | ||
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol"; | ||
|
||
|
||
contract TestUniswapBridge is | ||
UniswapBridge | ||
{ | ||
// solhint-disable var-name-mixedcase | ||
address public TEST_WETH_ADDRESS; | ||
address public TEST_UNISWAP_EXCHANGE_FACTORY_ADDRESS; | ||
|
||
constructor ( | ||
address testWeth, | ||
address testUniswapExchangeFactory | ||
) | ||
public | ||
{ | ||
TEST_WETH_ADDRESS = testWeth; | ||
TEST_UNISWAP_EXCHANGE_FACTORY_ADDRESS = testUniswapExchangeFactory; | ||
} | ||
|
||
function getWethContract() | ||
public | ||
view | ||
returns (IEtherToken token) | ||
{ | ||
return IEtherToken(TEST_WETH_ADDRESS); | ||
} | ||
|
||
function getUniswapExchangeFactoryContract() | ||
public | ||
view | ||
returns (IUniswapExchangeFactory factory) | ||
{ | ||
return IUniswapExchangeFactory(TEST_UNISWAP_EXCHANGE_FACTORY_ADDRESS); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
contracts/integrations/contracts/test/TestUniswapExchange.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright 2019 ZeroEx Intl. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchange.sol"; | ||
import "@0x/contracts-erc20/contracts/test/DummyERC20Token.sol"; | ||
|
||
|
||
contract TestUniswapExchange is | ||
IUniswapExchange | ||
{ | ||
DummyERC20Token public token; | ||
|
||
constructor(address _tokenAddress) public { | ||
token = DummyERC20Token(_tokenAddress); | ||
} | ||
|
||
// solhint-disable no-empty-blocks | ||
/// @dev Used to receive ETH for testing. | ||
function topUpEth() | ||
external | ||
payable | ||
{} | ||
|
||
function ethToTokenTransferInput( | ||
uint256 minTokensBought, | ||
uint256, /* deadline */ | ||
address recipient | ||
) | ||
external | ||
payable | ||
returns (uint256 tokensBought) | ||
{ | ||
token.mint(minTokensBought); | ||
token.transfer(recipient, minTokensBought); | ||
return minTokensBought; | ||
} | ||
|
||
function tokenToEthSwapInput( | ||
uint256 tokensSold, | ||
uint256 minEthBought, | ||
uint256 /* deadline */ | ||
) | ||
external | ||
returns (uint256 ethBought) | ||
{ | ||
token.transferFrom( | ||
msg.sender, | ||
address(this), | ||
tokensSold | ||
); | ||
msg.sender.transfer(minEthBought); | ||
return minEthBought; | ||
} | ||
|
||
function tokenToTokenTransferInput( | ||
uint256 tokensSold, | ||
uint256 minTokensBought, | ||
uint256, /* minEthBought */ | ||
uint256, /* deadline */ | ||
address recipient, | ||
address toTokenAddress | ||
) | ||
external | ||
returns (uint256 tokensBought) | ||
{ | ||
token.transferFrom( | ||
msg.sender, | ||
address(this), | ||
tokensSold | ||
); | ||
DummyERC20Token toToken = DummyERC20Token(toTokenAddress); | ||
toToken.mint(minTokensBought); | ||
toToken.transfer(recipient, minTokensBought); | ||
return minTokensBought; | ||
} | ||
|
||
function toTokenAddress() | ||
external | ||
view | ||
returns (address _tokenAddress) | ||
{ | ||
return address(token); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
contracts/integrations/contracts/test/TestUniswapExchangeFactory.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright 2019 ZeroEx Intl. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.9; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "@0x/contracts-asset-proxy/contracts/src/bridges/UniswapBridge.sol"; | ||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchangeFactory.sol"; | ||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IUniswapExchange.sol"; | ||
|
||
|
||
contract TestUniswapExchangeFactory is | ||
IUniswapExchangeFactory | ||
{ | ||
// Token address to UniswapExchange address. | ||
mapping (address => address) private _testExchanges; | ||
|
||
/// @dev Create a token and exchange (if they don't exist) for a new token | ||
/// and sets the exchange revert and fill behavior. | ||
/// @param tokenAddress The token address. | ||
function addExchange( | ||
address tokenAddress, | ||
address exchangeAddress | ||
) | ||
external | ||
{ | ||
_testExchanges[tokenAddress] = exchangeAddress; | ||
} | ||
|
||
/// @dev `IUniswapExchangeFactory.getExchange` | ||
function getExchange(address tokenAddress) | ||
external | ||
view | ||
returns (IUniswapExchange) | ||
{ | ||
return IUniswapExchange(_testExchanges[tokenAddress]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
contracts/integrations/test/bridges/deploy_eth2dai_bridge.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { artifacts as ERC20Artifacts } from '@0x/contracts-erc20'; | ||
import { BlockchainTestsEnvironment } from '@0x/contracts-test-utils'; | ||
|
||
import { artifacts } from '../artifacts'; | ||
import { DeploymentManager } from '../framework/deployment_manager'; | ||
import { TestEth2DaiBridgeContract, TestEth2DaiContract } from '../wrappers'; | ||
|
||
export async function deployEth2DaiBridgeAsync( | ||
deployment: DeploymentManager, | ||
environment: BlockchainTestsEnvironment, | ||
): Promise<[TestEth2DaiBridgeContract, TestEth2DaiContract]> { | ||
const eth2Dai = await TestEth2DaiContract.deployFrom0xArtifactAsync( | ||
artifacts.TestEth2Dai, | ||
environment.provider, | ||
deployment.txDefaults, | ||
artifacts, | ||
); | ||
|
||
const eth2DaiBridge = await TestEth2DaiBridgeContract.deployFrom0xArtifactAsync( | ||
artifacts.TestEth2DaiBridge, | ||
environment.provider, | ||
deployment.txDefaults, | ||
{ ...ERC20Artifacts, ...artifacts }, | ||
eth2Dai.address, | ||
); | ||
|
||
return [eth2DaiBridge, eth2Dai]; | ||
} |
Oops, something went wrong.