diff --git a/contracts/arbitrum/connectors/dexSimulation/events.sol b/contracts/arbitrum/connectors/dexSimulation/events.sol new file mode 100644 index 00000000..083afebe --- /dev/null +++ b/contracts/arbitrum/connectors/dexSimulation/events.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogSimulateSwap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ); +} diff --git a/contracts/arbitrum/connectors/dexSimulation/helpers.sol b/contracts/arbitrum/connectors/dexSimulation/helpers.sol new file mode 100644 index 00000000..65c56bcf --- /dev/null +++ b/contracts/arbitrum/connectors/dexSimulation/helpers.sol @@ -0,0 +1,15 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "./interfaces.sol"; +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { Stores } from "../../common/stores.sol"; + +abstract contract Helpers is Stores, Basic { + /** + * @dev dexSimulation Address + */ + address internal constant dexSimulation = + 0xa5044f8FfA8FbDdd0781cEDe502F1C493BB6978A; +} diff --git a/contracts/arbitrum/connectors/dexSimulation/interfaces.sol b/contracts/arbitrum/connectors/dexSimulation/interfaces.sol new file mode 100644 index 00000000..bb390ddd --- /dev/null +++ b/contracts/arbitrum/connectors/dexSimulation/interfaces.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface InstaDexSimulation { + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ) external payable; +} diff --git a/contracts/arbitrum/connectors/dexSimulation/main.sol b/contracts/arbitrum/connectors/dexSimulation/main.sol new file mode 100644 index 00000000..4b65de7e --- /dev/null +++ b/contracts/arbitrum/connectors/dexSimulation/main.sol @@ -0,0 +1,69 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +/** + * @title Insta dex simulation. + * @dev swap. + */ + +import { Events } from "./events.sol"; +import "./helpers.sol"; + +abstract contract InstaDexSimulationResolver is Events, Helpers { + /** + * @dev Simulation swap using Insta dex swap contract + * @param sellToken The token to sell/swap + * @param buyToken The token to buy + * @param sellAmount The sell token amount + * @param buyAmount The buy token amount + * @param setId Set token amount at this ID in `InstaMemory` Contract. + * @param getId Get token amount at this ID in `InstaMemory` Contract. + */ + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount, + uint256 setId, + uint256 getId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + sellAmount = getUint(getId, sellAmount); + uint256 nativeAmount; + + if (sellToken == ethAddr) { + sellAmount = sellAmount == uint256(-1) + ? address(this).balance + : sellAmount; + nativeAmount = sellAmount; + } else { + TokenInterface tokenContract = TokenInterface(sellToken); + + sellAmount = sellAmount == uint256(-1) + ? tokenContract.balanceOf(address(this)) + : sellAmount; + + approve(tokenContract, address(dexSimulation), sellAmount); + } + + InstaDexSimulation(dexSimulation).swap{ value: nativeAmount }( + sellToken, + buyToken, + sellAmount, + buyAmount + ); + + setUint(setId, buyAmount); + + _eventName = "LogSimulateSwap(address,address,uint256,uint256)"; + _eventParam = abi.encode(sellToken, buyToken, sellAmount, buyAmount); + } +} + +contract ConnectV2InstaDexSimulationArbitrum is InstaDexSimulationResolver { + string public name = "Instadapp-DEX-Simulation-v1"; +} diff --git a/contracts/avalanche/connectors/dexSimulation/events.sol b/contracts/avalanche/connectors/dexSimulation/events.sol new file mode 100644 index 00000000..083afebe --- /dev/null +++ b/contracts/avalanche/connectors/dexSimulation/events.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogSimulateSwap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ); +} diff --git a/contracts/avalanche/connectors/dexSimulation/helpers.sol b/contracts/avalanche/connectors/dexSimulation/helpers.sol new file mode 100644 index 00000000..6d65ff2c --- /dev/null +++ b/contracts/avalanche/connectors/dexSimulation/helpers.sol @@ -0,0 +1,15 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "./interfaces.sol"; +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { Stores } from "../../common/stores.sol"; + +abstract contract Helpers is Stores, Basic { + /** + * @dev dexSimulation Address + */ + address internal constant dexSimulation = + 0x266b527deb47eBe327D1933da310ef13Fe76D213; +} diff --git a/contracts/avalanche/connectors/dexSimulation/interfaces.sol b/contracts/avalanche/connectors/dexSimulation/interfaces.sol new file mode 100644 index 00000000..bb390ddd --- /dev/null +++ b/contracts/avalanche/connectors/dexSimulation/interfaces.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface InstaDexSimulation { + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ) external payable; +} diff --git a/contracts/avalanche/connectors/dexSimulation/main.sol b/contracts/avalanche/connectors/dexSimulation/main.sol new file mode 100644 index 00000000..6631a066 --- /dev/null +++ b/contracts/avalanche/connectors/dexSimulation/main.sol @@ -0,0 +1,69 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +/** + * @title Insta dex simulation. + * @dev swap. + */ + +import { Events } from "./events.sol"; +import "./helpers.sol"; + +abstract contract InstaDexSimulationResolver is Events, Helpers { + /** + * @dev Simulation swap using Insta dex swap contract + * @param sellToken The token to sell/swap + * @param buyToken The token to buy + * @param sellAmount The sell token amount + * @param buyAmount The buy token amount + * @param setId Set token amount at this ID in `InstaMemory` Contract. + * @param getId Get token amount at this ID in `InstaMemory` Contract. + */ + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount, + uint256 setId, + uint256 getId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + sellAmount = getUint(getId, sellAmount); + uint256 nativeAmount; + + if (sellToken == avaxAddr) { + sellAmount = sellAmount == uint256(-1) + ? address(this).balance + : sellAmount; + nativeAmount = sellAmount; + } else { + TokenInterface tokenContract = TokenInterface(sellToken); + + sellAmount = sellAmount == uint256(-1) + ? tokenContract.balanceOf(address(this)) + : sellAmount; + + approve(tokenContract, address(dexSimulation), sellAmount); + } + + InstaDexSimulation(dexSimulation).swap{ value: nativeAmount }( + sellToken, + buyToken, + sellAmount, + buyAmount + ); + + setUint(setId, buyAmount); + + _eventName = "LogSimulateSwap(address,address,uint256,uint256)"; + _eventParam = abi.encode(sellToken, buyToken, sellAmount, buyAmount); + } +} + +contract ConnectV2InstaDexSimulationAvalanche is InstaDexSimulationResolver { + string public name = "Instadapp-DEX-Simulation-v1"; +} diff --git a/contracts/fantom/connectors/dexSimulation/events.sol b/contracts/fantom/connectors/dexSimulation/events.sol new file mode 100644 index 00000000..083afebe --- /dev/null +++ b/contracts/fantom/connectors/dexSimulation/events.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogSimulateSwap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ); +} diff --git a/contracts/fantom/connectors/dexSimulation/helpers.sol b/contracts/fantom/connectors/dexSimulation/helpers.sol new file mode 100644 index 00000000..d607ad86 --- /dev/null +++ b/contracts/fantom/connectors/dexSimulation/helpers.sol @@ -0,0 +1,15 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "./interfaces.sol"; +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { Stores } from "../../common/stores.sol"; + +abstract contract Helpers is Stores, Basic { + /** + * @dev dexSimulation Address + */ + address internal constant dexSimulation = + 0xbD07728E20c49F0Fa22c82915955fbeA5E203a6a; +} diff --git a/contracts/fantom/connectors/dexSimulation/interfaces.sol b/contracts/fantom/connectors/dexSimulation/interfaces.sol new file mode 100644 index 00000000..bb390ddd --- /dev/null +++ b/contracts/fantom/connectors/dexSimulation/interfaces.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface InstaDexSimulation { + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ) external payable; +} diff --git a/contracts/fantom/connectors/dexSimulation/main.sol b/contracts/fantom/connectors/dexSimulation/main.sol new file mode 100644 index 00000000..2536c69e --- /dev/null +++ b/contracts/fantom/connectors/dexSimulation/main.sol @@ -0,0 +1,69 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +/** + * @title Insta dex simulation. + * @dev swap. + */ + +import { Events } from "./events.sol"; +import "./helpers.sol"; + +abstract contract InstaDexSimulationResolver is Events, Helpers { + /** + * @dev Simulation swap using Insta dex swap contract + * @param sellToken The token to sell/swap + * @param buyToken The token to buy + * @param sellAmount The sell token amount + * @param buyAmount The buy token amount + * @param setId Set token amount at this ID in `InstaMemory` Contract. + * @param getId Get token amount at this ID in `InstaMemory` Contract. + */ + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount, + uint256 setId, + uint256 getId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + sellAmount = getUint(getId, sellAmount); + uint256 nativeAmount; + + if (sellToken == ftmAddr) { + sellAmount = sellAmount == uint256(-1) + ? address(this).balance + : sellAmount; + nativeAmount = sellAmount; + } else { + TokenInterface tokenContract = TokenInterface(sellToken); + + sellAmount = sellAmount == uint256(-1) + ? tokenContract.balanceOf(address(this)) + : sellAmount; + + approve(tokenContract, address(dexSimulation), sellAmount); + } + + InstaDexSimulation(dexSimulation).swap{ value: nativeAmount }( + sellToken, + buyToken, + sellAmount, + buyAmount + ); + + setUint(setId, buyAmount); + + _eventName = "LogSimulateSwap(address,address,uint256,uint256)"; + _eventParam = abi.encode(sellToken, buyToken, sellAmount, buyAmount); + } +} + +contract ConnectV2InstaDexSimulationFantom is InstaDexSimulationResolver { + string public name = "Instadapp-DEX-Simulation-v1"; +} diff --git a/contracts/optimism/connectors/dexSimulation/events.sol b/contracts/optimism/connectors/dexSimulation/events.sol new file mode 100644 index 00000000..083afebe --- /dev/null +++ b/contracts/optimism/connectors/dexSimulation/events.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogSimulateSwap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ); +} diff --git a/contracts/optimism/connectors/dexSimulation/helpers.sol b/contracts/optimism/connectors/dexSimulation/helpers.sol new file mode 100644 index 00000000..13eb5c92 --- /dev/null +++ b/contracts/optimism/connectors/dexSimulation/helpers.sol @@ -0,0 +1,15 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "./interfaces.sol"; +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { Stores } from "../../common/stores.sol"; + +abstract contract Helpers is Stores, Basic { + /** + * @dev dexSimulation Address + */ + address internal constant dexSimulation = + 0x718365C3d1aA4c5CcE869E16bE3f6A96EC65200b; +} diff --git a/contracts/optimism/connectors/dexSimulation/interfaces.sol b/contracts/optimism/connectors/dexSimulation/interfaces.sol new file mode 100644 index 00000000..bb390ddd --- /dev/null +++ b/contracts/optimism/connectors/dexSimulation/interfaces.sol @@ -0,0 +1,11 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface InstaDexSimulation { + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount + ) external payable; +} diff --git a/contracts/optimism/connectors/dexSimulation/main.sol b/contracts/optimism/connectors/dexSimulation/main.sol new file mode 100644 index 00000000..0603811b --- /dev/null +++ b/contracts/optimism/connectors/dexSimulation/main.sol @@ -0,0 +1,69 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +/** + * @title Insta dex simulation. + * @dev swap. + */ + +import { Events } from "./events.sol"; +import "./helpers.sol"; + +abstract contract InstaDexSimulationResolver is Events, Helpers { + /** + * @dev Simulation swap using Insta dex swap contract + * @param sellToken The token to sell/swap + * @param buyToken The token to buy + * @param sellAmount The sell token amount + * @param buyAmount The buy token amount + * @param setId Set token amount at this ID in `InstaMemory` Contract. + * @param getId Get token amount at this ID in `InstaMemory` Contract. + */ + function swap( + address sellToken, + address buyToken, + uint256 sellAmount, + uint256 buyAmount, + uint256 setId, + uint256 getId + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + sellAmount = getUint(getId, sellAmount); + uint256 nativeAmount; + + if (sellToken == ethAddr) { + sellAmount = sellAmount == uint256(-1) + ? address(this).balance + : sellAmount; + nativeAmount = sellAmount; + } else { + TokenInterface tokenContract = TokenInterface(sellToken); + + sellAmount = sellAmount == uint256(-1) + ? tokenContract.balanceOf(address(this)) + : sellAmount; + + approve(tokenContract, address(dexSimulation), sellAmount); + } + + InstaDexSimulation(dexSimulation).swap{ value: nativeAmount }( + sellToken, + buyToken, + sellAmount, + buyAmount + ); + + setUint(setId, buyAmount); + + _eventName = "LogSimulateSwap(address,address,uint256,uint256)"; + _eventParam = abi.encode(sellToken, buyToken, sellAmount, buyAmount); + } +} + +contract ConnectV2InstaDexSimulationOptimism is InstaDexSimulationResolver { + string public name = "Instadapp-DEX-Simulation-v1"; +}