From e90fcd590a3349fad11486770582c06d85534c7b Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Wed, 15 Jun 2022 03:38:28 +0530 Subject: [PATCH] updated events --- .../avalanche/connectors/swap/events.sol | 12 +++++++++++ .../avalanche/connectors/swap/helpers.sol | 11 ++++++++-- contracts/avalanche/connectors/swap/main.sol | 21 ++++++++++++------- contracts/mainnet/connectors/swap/events.sol | 12 +++++++++++ contracts/mainnet/connectors/swap/helpers.sol | 11 ++++++++-- contracts/mainnet/connectors/swap/main.sol | 16 +++++++++++--- contracts/polygon/connectors/swap/events.sol | 12 +++++++++++ contracts/polygon/connectors/swap/helpers.sol | 11 ++++++++-- contracts/polygon/connectors/swap/main.sol | 16 +++++++++++--- 9 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 contracts/avalanche/connectors/swap/events.sol create mode 100644 contracts/mainnet/connectors/swap/events.sol create mode 100644 contracts/polygon/connectors/swap/events.sol diff --git a/contracts/avalanche/connectors/swap/events.sol b/contracts/avalanche/connectors/swap/events.sol new file mode 100644 index 00000000..45e71522 --- /dev/null +++ b/contracts/avalanche/connectors/swap/events.sol @@ -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 + ); +} diff --git a/contracts/avalanche/connectors/swap/helpers.sol b/contracts/avalanche/connectors/swap/helpers.sol index bc117d50..0d2292bf 100644 --- a/contracts/avalanche/connectors/swap/helpers.sol +++ b/contracts/avalanche/connectors/swap/helpers.sol @@ -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; + } } } } diff --git a/contracts/avalanche/connectors/swap/main.sol b/contracts/avalanche/connectors/swap/main.sol index 83ce0c26..70deb981 100644 --- a/contracts/avalanche/connectors/swap/main.sol +++ b/contracts/avalanche/connectors/swap/main.sol @@ -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); } } diff --git a/contracts/mainnet/connectors/swap/events.sol b/contracts/mainnet/connectors/swap/events.sol new file mode 100644 index 00000000..cc9ce02e --- /dev/null +++ b/contracts/mainnet/connectors/swap/events.sol @@ -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 + ); +} diff --git a/contracts/mainnet/connectors/swap/helpers.sol b/contracts/mainnet/connectors/swap/helpers.sol index 3e055a61..4cebf70d 100644 --- a/contracts/mainnet/connectors/swap/helpers.sol +++ b/contracts/mainnet/connectors/swap/helpers.sol @@ -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; + } } } } diff --git a/contracts/mainnet/connectors/swap/main.sol b/contracts/mainnet/connectors/swap/main.sol index a98ee841..dac0f835 100644 --- a/contracts/mainnet/connectors/swap/main.sol +++ b/contracts/mainnet/connectors/swap/main.sol @@ -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); } } diff --git a/contracts/polygon/connectors/swap/events.sol b/contracts/polygon/connectors/swap/events.sol new file mode 100644 index 00000000..cc9ce02e --- /dev/null +++ b/contracts/polygon/connectors/swap/events.sol @@ -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 + ); +} diff --git a/contracts/polygon/connectors/swap/helpers.sol b/contracts/polygon/connectors/swap/helpers.sol index 54aa6e43..7e9e133a 100644 --- a/contracts/polygon/connectors/swap/helpers.sol +++ b/contracts/polygon/connectors/swap/helpers.sol @@ -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; + } } } } diff --git a/contracts/polygon/connectors/swap/main.sol b/contracts/polygon/connectors/swap/main.sol index e8c79a42..31ba300e 100644 --- a/contracts/polygon/connectors/swap/main.sol +++ b/contracts/polygon/connectors/swap/main.sol @@ -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); } }