mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
updated events
This commit is contained in:
parent
16ef3fc9f4
commit
e90fcd590a
12
contracts/avalanche/connectors/swap/events.sol
Normal file
12
contracts/avalanche/connectors/swap/events.sol
Normal file
|
@ -0,0 +1,12 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma abicoder v2;
|
||||
|
||||
contract Events {
|
||||
event LogSwapAggregator(
|
||||
string[] connectors,
|
||||
string connectorName,
|
||||
string eventName,
|
||||
bytes eventParam
|
||||
);
|
||||
}
|
|
@ -18,7 +18,11 @@ contract SwapHelpers {
|
|||
*/
|
||||
function _swap(string[] memory _connectors, bytes[] memory _data)
|
||||
internal
|
||||
returns (bool success, bytes memory returnData)
|
||||
returns (
|
||||
bool success,
|
||||
bytes memory returnData,
|
||||
string memory connector
|
||||
)
|
||||
{
|
||||
uint256 _length = _connectors.length;
|
||||
require(_length > 0, "zero-length-not-allowed");
|
||||
|
@ -28,7 +32,10 @@ contract SwapHelpers {
|
|||
(success, returnData) = instaConnectors
|
||||
.connectors(_connectors[i])
|
||||
.delegatecall(_data[i]);
|
||||
if (success) break;
|
||||
if (success) {
|
||||
connector = _connectors[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,26 +9,33 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
// import files
|
||||
import { SwapHelpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract Swap is SwapHelpers {
|
||||
abstract contract Swap is SwapHelpers, Events {
|
||||
/**
|
||||
* @dev Swap ETH/ERC20_Token using dex aggregators.
|
||||
* @notice Swap tokens from exchanges like 1INCH, 0x etc, with calculation done off-chain.
|
||||
* @param _connectors The name of the connectors like 1INCH-A, 0x etc, in order of their priority.
|
||||
* @param _data Encoded function call data including function selector encoded with parameters.
|
||||
*/
|
||||
function swap(
|
||||
string[] memory _connectors,
|
||||
bytes[] memory _data
|
||||
)
|
||||
function swap(string[] memory _connectors, bytes[] memory _data)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(bool success, bytes memory returnData) = _swap(_connectors, _data);
|
||||
(bool success, bytes memory returnData, string memory connector) = _swap(
|
||||
_connectors,
|
||||
_data
|
||||
);
|
||||
|
||||
require(success, "swap-Aggregator-failed");
|
||||
(_eventName, _eventParam) = abi.decode(returnData, (string, bytes));
|
||||
(string memory eventName, bytes memory eventParam) = abi.decode(
|
||||
returnData,
|
||||
(string, bytes)
|
||||
);
|
||||
|
||||
_eventName = "LogSwapAggregator(string[],string,string,bytes)";
|
||||
_eventParam = abi.encode(_connectors, connector, eventName, eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
contracts/mainnet/connectors/swap/events.sol
Normal file
12
contracts/mainnet/connectors/swap/events.sol
Normal file
|
@ -0,0 +1,12 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma abicoder v2;
|
||||
|
||||
contract Events {
|
||||
event SwapAggregator(
|
||||
string[] connectors,
|
||||
string connectorName,
|
||||
string eventName,
|
||||
bytes eventParam
|
||||
);
|
||||
}
|
|
@ -18,7 +18,11 @@ contract SwapHelpers {
|
|||
*/
|
||||
function _swap(string[] memory _connectors, bytes[] memory _data)
|
||||
internal
|
||||
returns (bool success, bytes memory returnData)
|
||||
returns (
|
||||
bool success,
|
||||
bytes memory returnData,
|
||||
string memory connector
|
||||
)
|
||||
{
|
||||
uint256 _length = _connectors.length;
|
||||
require(_length > 0, "zero-length-not-allowed");
|
||||
|
@ -28,7 +32,10 @@ contract SwapHelpers {
|
|||
(success, returnData) = instaConnectors
|
||||
.connectors(_connectors[i])
|
||||
.delegatecall(_data[i]);
|
||||
if (success) break;
|
||||
if (success) {
|
||||
connector = _connectors[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
// import files
|
||||
import { SwapHelpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract Swap is SwapHelpers {
|
||||
abstract contract Swap is SwapHelpers, Events {
|
||||
/**
|
||||
* @dev Swap ETH/ERC20_Token using dex aggregators.
|
||||
* @notice Swap tokens from exchanges like 1INCH, 0x etc, with calculation done off-chain.
|
||||
|
@ -22,10 +23,19 @@ abstract contract Swap is SwapHelpers {
|
|||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(bool success, bytes memory returnData) = _swap(_connectors, _data);
|
||||
(bool success, bytes memory returnData, string memory connector) = _swap(
|
||||
_connectors,
|
||||
_data
|
||||
);
|
||||
|
||||
require(success, "swap-Aggregator-failed");
|
||||
(_eventName, _eventParam) = abi.decode(returnData, (string, bytes));
|
||||
(string memory eventName, bytes memory eventParam) = abi.decode(
|
||||
returnData,
|
||||
(string, bytes)
|
||||
);
|
||||
|
||||
_eventName = "LogSwapAggregator(string[],string,string,bytes)";
|
||||
_eventParam = abi.encode(_connectors, connector, eventName, eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
contracts/polygon/connectors/swap/events.sol
Normal file
12
contracts/polygon/connectors/swap/events.sol
Normal file
|
@ -0,0 +1,12 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
pragma abicoder v2;
|
||||
|
||||
contract Events {
|
||||
event SwapAggregator(
|
||||
string[] connectors,
|
||||
string connectorName,
|
||||
string eventName,
|
||||
bytes eventParam
|
||||
);
|
||||
}
|
|
@ -18,7 +18,11 @@ contract SwapHelpers {
|
|||
*/
|
||||
function _swap(string[] memory _connectors, bytes[] memory _data)
|
||||
internal
|
||||
returns (bool success, bytes memory returnData)
|
||||
returns (
|
||||
bool success,
|
||||
bytes memory returnData,
|
||||
string memory connector
|
||||
)
|
||||
{
|
||||
uint256 _length = _connectors.length;
|
||||
require(_length > 0, "zero-length-not-allowed");
|
||||
|
@ -28,7 +32,10 @@ contract SwapHelpers {
|
|||
(success, returnData) = instaConnectors
|
||||
.connectors(_connectors[i])
|
||||
.delegatecall(_data[i]);
|
||||
if (success) break;
|
||||
if (success) {
|
||||
connector = _connectors[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
// import files
|
||||
import { SwapHelpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
|
||||
abstract contract Swap is SwapHelpers {
|
||||
abstract contract Swap is SwapHelpers, Events {
|
||||
/**
|
||||
* @dev Swap ETH/ERC20_Token using dex aggregators.
|
||||
* @notice Swap tokens from exchanges like 1INCH, 0x etc, with calculation done off-chain.
|
||||
|
@ -22,10 +23,19 @@ abstract contract Swap is SwapHelpers {
|
|||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
(bool success, bytes memory returnData) = _swap(_connectors, _data);
|
||||
(bool success, bytes memory returnData, string memory connector) = _swap(
|
||||
_connectors,
|
||||
_data
|
||||
);
|
||||
|
||||
require(success, "swap-Aggregator-failed");
|
||||
(_eventName, _eventParam) = abi.decode(returnData, (string, bytes));
|
||||
(string memory eventName, bytes memory eventParam) = abi.decode(
|
||||
returnData,
|
||||
(string, bytes)
|
||||
);
|
||||
|
||||
_eventName = "LogSwapAggregator(string[],string,string,bytes)";
|
||||
_eventParam = abi.encode(_connectors, connector, eventName, eventParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user