mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
insta simulation dex connector
This commit is contained in:
parent
1ae4a0abef
commit
8ed6524cbb
11
contracts/polygon/connectors/dexSimulation/events.sol
Normal file
11
contracts/polygon/connectors/dexSimulation/events.sol
Normal 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
|
||||
);
|
||||
}
|
15
contracts/polygon/connectors/dexSimulation/helpers.sol
Normal file
15
contracts/polygon/connectors/dexSimulation/helpers.sol
Normal 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 =
|
||||
0x49c8AA422207Dc2709FCdc21CeAD0943578a21e8;
|
||||
}
|
11
contracts/polygon/connectors/dexSimulation/interfaces.sol
Normal file
11
contracts/polygon/connectors/dexSimulation/interfaces.sol
Normal 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;
|
||||
}
|
55
contracts/polygon/connectors/dexSimulation/main.sol
Normal file
55
contracts/polygon/connectors/dexSimulation/main.sol
Normal file
|
@ -0,0 +1,55 @@
|
|||
//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 {
|
||||
function swap(
|
||||
address sellToken,
|
||||
address buyToken,
|
||||
uint256 sellAmount,
|
||||
uint256 buyAmount,
|
||||
uint256 setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
if (sellToken == maticAddr) {
|
||||
sellAmount = sellAmount == uint256(-1)
|
||||
? address(this).balance
|
||||
: sellAmount;
|
||||
} else {
|
||||
TokenInterface tokenContract = TokenInterface(sellToken);
|
||||
|
||||
sellAmount = sellAmount == uint256(-1)
|
||||
? tokenContract.balanceOf(address(this))
|
||||
: sellAmount;
|
||||
|
||||
approve(tokenContract, address(dexSimulation), sellAmount);
|
||||
}
|
||||
|
||||
InstaDexSimulation(dexSimulation).swap{ value: sellAmount }(
|
||||
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 = "InstaDexSimulation-v1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user