mainnet connector

Signed-off-by: pradyuman-verma <pradyumnverma27@gmail.com>
This commit is contained in:
pradyuman-verma 2022-07-10 23:41:48 +05:30
parent ff39015e50
commit 9112e025a5
No known key found for this signature in database
GPG Key ID: E36FD6BC8923221F
4 changed files with 106 additions and 0 deletions

View File

@ -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
);
}

View File

@ -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 =
0x49B159E897b7701769B1E66061C8dcCd7240c461;
}

View File

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

View File

@ -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 ConnectV2InstaDexSimulation is InstaDexSimulationResolver {
string public name = "Instadapp-DEX-Simulation-v1";
}