mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge branch 'main' into automation-connector
This commit is contained in:
commit
4eaabe6bf7
11
contracts/arbitrum/connectors/dexSimulation/events.sol
Normal file
11
contracts/arbitrum/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/arbitrum/connectors/dexSimulation/helpers.sol
Normal file
15
contracts/arbitrum/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 =
|
||||||
|
0xa5044f8FfA8FbDdd0781cEDe502F1C493BB6978A;
|
||||||
|
}
|
11
contracts/arbitrum/connectors/dexSimulation/interfaces.sol
Normal file
11
contracts/arbitrum/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;
|
||||||
|
}
|
69
contracts/arbitrum/connectors/dexSimulation/main.sol
Normal file
69
contracts/arbitrum/connectors/dexSimulation/main.sol
Normal 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 ConnectV2InstaDexSimulationArbitrum is InstaDexSimulationResolver {
|
||||||
|
string public name = "Instadapp-DEX-Simulation-v1";
|
||||||
|
}
|
11
contracts/avalanche/connectors/dexSimulation/events.sol
Normal file
11
contracts/avalanche/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/avalanche/connectors/dexSimulation/helpers.sol
Normal file
15
contracts/avalanche/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 =
|
||||||
|
0x266b527deb47eBe327D1933da310ef13Fe76D213;
|
||||||
|
}
|
11
contracts/avalanche/connectors/dexSimulation/interfaces.sol
Normal file
11
contracts/avalanche/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;
|
||||||
|
}
|
69
contracts/avalanche/connectors/dexSimulation/main.sol
Normal file
69
contracts/avalanche/connectors/dexSimulation/main.sol
Normal 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 == 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";
|
||||||
|
}
|
11
contracts/fantom/connectors/dexSimulation/events.sol
Normal file
11
contracts/fantom/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/fantom/connectors/dexSimulation/helpers.sol
Normal file
15
contracts/fantom/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 =
|
||||||
|
0xbD07728E20c49F0Fa22c82915955fbeA5E203a6a;
|
||||||
|
}
|
11
contracts/fantom/connectors/dexSimulation/interfaces.sol
Normal file
11
contracts/fantom/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;
|
||||||
|
}
|
69
contracts/fantom/connectors/dexSimulation/main.sol
Normal file
69
contracts/fantom/connectors/dexSimulation/main.sol
Normal 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 == 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";
|
||||||
|
}
|
11
contracts/mainnet/connectors/dexSimulation/events.sol
Normal file
11
contracts/mainnet/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/mainnet/connectors/dexSimulation/helpers.sol
Normal file
15
contracts/mainnet/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 =
|
||||||
|
0x49B159E897b7701769B1E66061C8dcCd7240c461;
|
||||||
|
}
|
11
contracts/mainnet/connectors/dexSimulation/interfaces.sol
Normal file
11
contracts/mainnet/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;
|
||||||
|
}
|
69
contracts/mainnet/connectors/dexSimulation/main.sol
Normal file
69
contracts/mainnet/connectors/dexSimulation/main.sol
Normal 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";
|
||||||
|
}
|
11
contracts/optimism/connectors/dexSimulation/events.sol
Normal file
11
contracts/optimism/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/optimism/connectors/dexSimulation/helpers.sol
Normal file
15
contracts/optimism/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 =
|
||||||
|
0x718365C3d1aA4c5CcE869E16bE3f6A96EC65200b;
|
||||||
|
}
|
11
contracts/optimism/connectors/dexSimulation/interfaces.sol
Normal file
11
contracts/optimism/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;
|
||||||
|
}
|
69
contracts/optimism/connectors/dexSimulation/main.sol
Normal file
69
contracts/optimism/connectors/dexSimulation/main.sol
Normal 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 ConnectV2InstaDexSimulationOptimism is InstaDexSimulationResolver {
|
||||||
|
string public name = "Instadapp-DEX-Simulation-v1";
|
||||||
|
}
|
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;
|
||||||
|
}
|
69
contracts/polygon/connectors/dexSimulation/main.sol
Normal file
69
contracts/polygon/connectors/dexSimulation/main.sol
Normal 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 == maticAddr) {
|
||||||
|
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 ConnectV2InstaDexSimulationPolygon is InstaDexSimulationResolver {
|
||||||
|
string public name = "Instadapp-DEX-Simulation-v1";
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import hre, { ethers } from "hardhat";
|
import hre, { ethers } from "hardhat";
|
||||||
|
|
||||||
import { execScript } from "../tests/command";
|
import { execScript } from "../tests/command";
|
||||||
|
|
||||||
export const deployConnector = async (connectorName?: string) => {
|
export const deployConnector = async (connectorName?: string) => {
|
||||||
connectorName = String(process.env.connectorName) ?? connectorName;
|
connectorName = String(process.env.connectorName) ?? connectorName;
|
||||||
const Connector = await ethers.getContractFactory(connectorName);
|
const Connector = await ethers.getContractFactory(connectorName);
|
||||||
|
@ -11,19 +11,20 @@ export const deployConnector = async (connectorName?: string) => {
|
||||||
|
|
||||||
const chain = String(hre.network.name);
|
const chain = String(hre.network.name);
|
||||||
if (chain !== "hardhat") {
|
if (chain !== "hardhat") {
|
||||||
|
const allPaths = await hre.artifacts.getArtifactPaths();
|
||||||
|
|
||||||
|
let connectorPath;
|
||||||
|
for (const path of allPaths)
|
||||||
|
if (path.split("/").includes(connectorName + ".json"))
|
||||||
|
connectorPath = path.slice(path.indexOf("contracts"), path.indexOf(connectorName) - 1) + `:${connectorName}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await execScript({
|
await execScript({
|
||||||
cmd: "npx",
|
cmd: "npx",
|
||||||
args: [
|
args: ["hardhat", "verify", "--network", `${chain}`, `${connector.address}`, "--contract", `${connectorPath}`],
|
||||||
"hardhat",
|
|
||||||
"verify",
|
|
||||||
"--network",
|
|
||||||
`${chain}`,
|
|
||||||
`${connector.address}`,
|
|
||||||
],
|
|
||||||
env: {
|
env: {
|
||||||
networkType: chain,
|
networkType: chain
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Failed to verify: ${connectorName}@${connector.address}`);
|
console.log(`Failed to verify: ${connectorName}@${connector.address}`);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user