dsa-connectors/contracts/fantom/connectors/kyber_aggregator/main.sol
2023-06-15 01:04:18 +05:30

60 lines
1.9 KiB
Solidity

//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @title Kyber.
* @dev DEX Aggregator.
*/
import {TokenInterface} from "../../common/interfaces.sol";
import {Stores} from "../../common/stores.sol";
import {Helpers} from "./helpers.sol";
abstract contract KyberFantomResolver is Helpers {
/**
* @dev Sell ftm/ERC20_Token using KyberSwap.
* @notice Swap tokens from exchanges like kyber, 0x etc, with calculation done off-chain.
* @param buyAddr The address of the token to buy.(For FTM: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAddr The address of the token to sell.(For FTM: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAmt The amount of the token to sell.
* @param unitAmt The amount of buyAmt/sellAmt with slippage.
* @param callData Data from kyberswap API.
* @param setId ID stores the amount of token brought.
*/
function swap(
address buyAddr,
address sellAddr,
uint256 sellAmt,
uint256 unitAmt,
bytes calldata callData,
uint256 setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
Helpers.SwapData memory swapData = Helpers.SwapData({
buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr),
unitAmt: unitAmt,
callData: callData,
_sellAmt: sellAmt,
_buyAmt: 0
});
swapData = _swap(swapData, setId);
_eventName = "LogSwap(address,address,uint256,uint256,uint256)";
_eventParam = abi.encode(
address(swapData.buyToken),
address(swapData.sellToken),
swapData._buyAmt,
swapData._sellAmt,
setId
);
}
}
contract ConnectV2KyberAggregatorFantom is KyberFantomResolver {
string public name = "Kyber-aggregator-v1.0";
}