From 2dd6321f5acdf674b2e1fb5348dfb3304bdacbf0 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Mon, 20 Jun 2022 18:48:38 +0530 Subject: [PATCH] updated castAny(), comments --- .../arbitrum/connectors/dsa-spell/events.sol | 8 +++- .../arbitrum/connectors/dsa-spell/main.sol | 43 ++++++++++++------- .../avalanche/connectors/dsa-spell/events.sol | 8 +++- .../avalanche/connectors/dsa-spell/main.sol | 43 ++++++++++++------- .../fantom/connectors/dsa-spell/events.sol | 8 +++- .../fantom/connectors/dsa-spell/main.sol | 43 ++++++++++++------- .../mainnet/connectors/dsa-spell/events.sol | 8 +++- .../mainnet/connectors/dsa-spell/main.sol | 43 ++++++++++++------- .../optimism/connectors/dsa-spell/events.sol | 8 +++- .../optimism/connectors/dsa-spell/main.sol | 43 ++++++++++++------- .../polygon/connectors/dsa-spell/events.sol | 8 +++- .../polygon/connectors/dsa-spell/main.sol | 43 ++++++++++++------- 12 files changed, 210 insertions(+), 96 deletions(-) diff --git a/contracts/arbitrum/connectors/dsa-spell/events.sol b/contracts/arbitrum/connectors/dsa-spell/events.sol index b3e455d6..a48b295a 100644 --- a/contracts/arbitrum/connectors/dsa-spell/events.sol +++ b/contracts/arbitrum/connectors/dsa-spell/events.sol @@ -8,5 +8,11 @@ contract Events { string[] connectors, bytes[] datas ); - event LogSpellFactory(string[] eventNames, bytes[] eventParams); + event LogCastAny( + string indexed connector, + string connectorName, + string[] connectors, + string eventName, + bytes eventParam + ); } diff --git a/contracts/arbitrum/connectors/dsa-spell/main.sol b/contracts/arbitrum/connectors/dsa-spell/main.sol index 553bee32..89cb38dd 100644 --- a/contracts/arbitrum/connectors/dsa-spell/main.sol +++ b/contracts/arbitrum/connectors/dsa-spell/main.sol @@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2; * @dev Cast spells on DSA. */ -// import files import { AccountInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; import { Events } from "./events.sol"; abstract contract DSASpellsResolver is Events, Stores { /** - *@dev Cast spells on DSA. + *@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed. + *@notice Interact with a target DSA by casting spells on it. *@param targetDSA target DSA to cast spells on. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ function castOnDSA( address targetDSA, @@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores { } /** - *@dev Perform spells. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully. + * Reverts if none of the spells is successful. + *@notice Casts the first successful spell on the DSA. + *@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ - function spellFactory(string[] memory connectors, bytes[] memory datas) + function castAny(string[] memory connectors, bytes[] memory datas) external payable returns (string memory eventName, bytes memory eventParam) @@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores { .isConnectors(connectors); require(isOk, "connector-names-invalid"); - string[] memory _eventNames = new string[](_length); - bytes[] memory _eventParams = new bytes[](_length); + string memory _connectorName; + string memory _eventName; + bytes memory _eventParam; + bytes memory returnData; + bool success; for (uint256 i = 0; i < _length; i++) { - (bool success, bytes memory returnData) = _connectors[i] - .delegatecall(datas[i]); + (success, returnData) = _connectors[i].delegatecall(datas[i]); if (success) { - (_eventNames[i], _eventParams[i]) = abi.decode( + _connectorName = connectors[i]; + (_eventName, _eventParam) = abi.decode( returnData, (string, bytes) ); + break; } } + require(success, "dsa-spells-failed"); - eventName = "LogSpellFactory(string[],bytes[])"; - eventParam = abi.encode(_eventNames, _eventParams); + eventName = "LogCastAny(string,string,string[],string,bytes)"; + eventParam = abi.encode( + _connectorName, + _connectorName, + connectors, + _eventName, + _eventParam + ); } } diff --git a/contracts/avalanche/connectors/dsa-spell/events.sol b/contracts/avalanche/connectors/dsa-spell/events.sol index b3e455d6..a48b295a 100644 --- a/contracts/avalanche/connectors/dsa-spell/events.sol +++ b/contracts/avalanche/connectors/dsa-spell/events.sol @@ -8,5 +8,11 @@ contract Events { string[] connectors, bytes[] datas ); - event LogSpellFactory(string[] eventNames, bytes[] eventParams); + event LogCastAny( + string indexed connector, + string connectorName, + string[] connectors, + string eventName, + bytes eventParam + ); } diff --git a/contracts/avalanche/connectors/dsa-spell/main.sol b/contracts/avalanche/connectors/dsa-spell/main.sol index bccc11d2..32da1e8b 100644 --- a/contracts/avalanche/connectors/dsa-spell/main.sol +++ b/contracts/avalanche/connectors/dsa-spell/main.sol @@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2; * @dev Cast spells on DSA. */ -// import files import { AccountInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; import { Events } from "./events.sol"; abstract contract DSASpellsResolver is Events, Stores { /** - *@dev Cast spells on DSA. + *@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed. + *@notice Interact with a target DSA by casting spells on it. *@param targetDSA target DSA to cast spells on. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ function castOnDSA( address targetDSA, @@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores { } /** - *@dev Perform spells. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully. + * Reverts if none of the spells is successful. + *@notice Casts the first successful spell on the DSA. + *@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ - function spellFactory(string[] memory connectors, bytes[] memory datas) + function castAny(string[] memory connectors, bytes[] memory datas) external payable returns (string memory eventName, bytes memory eventParam) @@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores { .isConnectors(connectors); require(isOk, "connector-names-invalid"); - string[] memory _eventNames = new string[](_length); - bytes[] memory _eventParams = new bytes[](_length); + string memory _connectorName; + string memory _eventName; + bytes memory _eventParam; + bytes memory returnData; + bool success; for (uint256 i = 0; i < _length; i++) { - (bool success, bytes memory returnData) = _connectors[i] - .delegatecall(datas[i]); + (success, returnData) = _connectors[i].delegatecall(datas[i]); if (success) { - (_eventNames[i], _eventParams[i]) = abi.decode( + _connectorName = connectors[i]; + (_eventName, _eventParam) = abi.decode( returnData, (string, bytes) ); + break; } } + require(success, "dsa-spells-failed"); - eventName = "LogSpellFactory(string[],bytes[])"; - eventParam = abi.encode(_eventNames, _eventParams); + eventName = "LogCastAny(string,string,string[],string,bytes)"; + eventParam = abi.encode( + _connectorName, + _connectorName, + connectors, + _eventName, + _eventParam + ); } } diff --git a/contracts/fantom/connectors/dsa-spell/events.sol b/contracts/fantom/connectors/dsa-spell/events.sol index b3e455d6..a48b295a 100644 --- a/contracts/fantom/connectors/dsa-spell/events.sol +++ b/contracts/fantom/connectors/dsa-spell/events.sol @@ -8,5 +8,11 @@ contract Events { string[] connectors, bytes[] datas ); - event LogSpellFactory(string[] eventNames, bytes[] eventParams); + event LogCastAny( + string indexed connector, + string connectorName, + string[] connectors, + string eventName, + bytes eventParam + ); } diff --git a/contracts/fantom/connectors/dsa-spell/main.sol b/contracts/fantom/connectors/dsa-spell/main.sol index 62bdb130..d467ab14 100644 --- a/contracts/fantom/connectors/dsa-spell/main.sol +++ b/contracts/fantom/connectors/dsa-spell/main.sol @@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2; * @dev Cast spells on DSA. */ -// import files import { AccountInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; import { Events } from "./events.sol"; abstract contract DSASpellsResolver is Events, Stores { /** - *@dev Cast spells on DSA. + *@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed. + *@notice Interact with a target DSA by casting spells on it. *@param targetDSA target DSA to cast spells on. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ function castOnDSA( address targetDSA, @@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores { } /** - *@dev Perform spells. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully. + * Reverts if none of the spells is successful. + *@notice Casts the first successful spell on the DSA. + *@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ - function spellFactory(string[] memory connectors, bytes[] memory datas) + function castAny(string[] memory connectors, bytes[] memory datas) external payable returns (string memory eventName, bytes memory eventParam) @@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores { .isConnectors(connectors); require(isOk, "connector-names-invalid"); - string[] memory _eventNames = new string[](_length); - bytes[] memory _eventParams = new bytes[](_length); + string memory _connectorName; + string memory _eventName; + bytes memory _eventParam; + bytes memory returnData; + bool success; for (uint256 i = 0; i < _length; i++) { - (bool success, bytes memory returnData) = _connectors[i] - .delegatecall(datas[i]); + (success, returnData) = _connectors[i].delegatecall(datas[i]); if (success) { - (_eventNames[i], _eventParams[i]) = abi.decode( + _connectorName = connectors[i]; + (_eventName, _eventParam) = abi.decode( returnData, (string, bytes) ); + break; } } + require(success, "dsa-spells-failed"); - eventName = "LogSpellFactory(string[],bytes[])"; - eventParam = abi.encode(_eventNames, _eventParams); + eventName = "LogCastAny(string,string,string[],string,bytes)"; + eventParam = abi.encode( + _connectorName, + _connectorName, + connectors, + _eventName, + _eventParam + ); } } diff --git a/contracts/mainnet/connectors/dsa-spell/events.sol b/contracts/mainnet/connectors/dsa-spell/events.sol index b3e455d6..a48b295a 100644 --- a/contracts/mainnet/connectors/dsa-spell/events.sol +++ b/contracts/mainnet/connectors/dsa-spell/events.sol @@ -8,5 +8,11 @@ contract Events { string[] connectors, bytes[] datas ); - event LogSpellFactory(string[] eventNames, bytes[] eventParams); + event LogCastAny( + string indexed connector, + string connectorName, + string[] connectors, + string eventName, + bytes eventParam + ); } diff --git a/contracts/mainnet/connectors/dsa-spell/main.sol b/contracts/mainnet/connectors/dsa-spell/main.sol index 34458953..7b255b17 100644 --- a/contracts/mainnet/connectors/dsa-spell/main.sol +++ b/contracts/mainnet/connectors/dsa-spell/main.sol @@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2; * @dev Cast spells on DSA. */ -// import files import { AccountInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; import { Events } from "./events.sol"; abstract contract DSASpellsResolver is Events, Stores { /** - *@dev Cast spells on DSA. + *@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed. + *@notice Interact with a target DSA by casting spells on it. *@param targetDSA target DSA to cast spells on. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ function castOnDSA( address targetDSA, @@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores { } /** - *@dev Perform spells. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully. + * Reverts if none of the spells is successful. + *@notice Casts the first successful spell on the DSA. + *@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ - function spellFactory(string[] memory connectors, bytes[] memory datas) + function castAny(string[] memory connectors, bytes[] memory datas) external payable returns (string memory eventName, bytes memory eventParam) @@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores { .isConnectors(connectors); require(isOk, "connector-names-invalid"); - string[] memory _eventNames = new string[](_length); - bytes[] memory _eventParams = new bytes[](_length); + string memory _connectorName; + string memory _eventName; + bytes memory _eventParam; + bytes memory returnData; + bool success; for (uint256 i = 0; i < _length; i++) { - (bool success, bytes memory returnData) = _connectors[i] - .delegatecall(datas[i]); + (success, returnData) = _connectors[i].delegatecall(datas[i]); if (success) { - (_eventNames[i], _eventParams[i]) = abi.decode( + _connectorName = connectors[i]; + (_eventName, _eventParam) = abi.decode( returnData, (string, bytes) ); + break; } } + require(success, "dsa-spells-failed"); - eventName = "LogSpellFactory(string[],bytes[])"; - eventParam = abi.encode(_eventNames, _eventParams); + eventName = "LogCastAny(string,string,string[],string,bytes)"; + eventParam = abi.encode( + _connectorName, + _connectorName, + connectors, + _eventName, + _eventParam + ); } } diff --git a/contracts/optimism/connectors/dsa-spell/events.sol b/contracts/optimism/connectors/dsa-spell/events.sol index b3e455d6..a48b295a 100644 --- a/contracts/optimism/connectors/dsa-spell/events.sol +++ b/contracts/optimism/connectors/dsa-spell/events.sol @@ -8,5 +8,11 @@ contract Events { string[] connectors, bytes[] datas ); - event LogSpellFactory(string[] eventNames, bytes[] eventParams); + event LogCastAny( + string indexed connector, + string connectorName, + string[] connectors, + string eventName, + bytes eventParam + ); } diff --git a/contracts/optimism/connectors/dsa-spell/main.sol b/contracts/optimism/connectors/dsa-spell/main.sol index c98c97d4..cf1e4941 100644 --- a/contracts/optimism/connectors/dsa-spell/main.sol +++ b/contracts/optimism/connectors/dsa-spell/main.sol @@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2; * @dev Cast spells on DSA. */ -// import files import { AccountInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; import { Events } from "./events.sol"; abstract contract DSASpellsResolver is Events, Stores { /** - *@dev Cast spells on DSA. + *@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed. + *@notice Interact with a target DSA by casting spells on it. *@param targetDSA target DSA to cast spells on. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ function castOnDSA( address targetDSA, @@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores { } /** - *@dev Perform spells. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully. + * Reverts if none of the spells is successful. + *@notice Casts the first successful spell on the DSA. + *@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ - function spellFactory(string[] memory connectors, bytes[] memory datas) + function castAny(string[] memory connectors, bytes[] memory datas) external payable returns (string memory eventName, bytes memory eventParam) @@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores { .isConnectors(connectors); require(isOk, "connector-names-invalid"); - string[] memory _eventNames = new string[](_length); - bytes[] memory _eventParams = new bytes[](_length); + string memory _connectorName; + string memory _eventName; + bytes memory _eventParam; + bytes memory returnData; + bool success; for (uint256 i = 0; i < _length; i++) { - (bool success, bytes memory returnData) = _connectors[i] - .delegatecall(datas[i]); + (success, returnData) = _connectors[i].delegatecall(datas[i]); if (success) { - (_eventNames[i], _eventParams[i]) = abi.decode( + _connectorName = connectors[i]; + (_eventName, _eventParam) = abi.decode( returnData, (string, bytes) ); + break; } } + require(success, "dsa-spells-failed"); - eventName = "LogSpellFactory(string[],bytes[])"; - eventParam = abi.encode(_eventNames, _eventParams); + eventName = "LogCastAny(string,string,string[],string,bytes)"; + eventParam = abi.encode( + _connectorName, + _connectorName, + connectors, + _eventName, + _eventParam + ); } } diff --git a/contracts/polygon/connectors/dsa-spell/events.sol b/contracts/polygon/connectors/dsa-spell/events.sol index b3e455d6..a48b295a 100644 --- a/contracts/polygon/connectors/dsa-spell/events.sol +++ b/contracts/polygon/connectors/dsa-spell/events.sol @@ -8,5 +8,11 @@ contract Events { string[] connectors, bytes[] datas ); - event LogSpellFactory(string[] eventNames, bytes[] eventParams); + event LogCastAny( + string indexed connector, + string connectorName, + string[] connectors, + string eventName, + bytes eventParam + ); } diff --git a/contracts/polygon/connectors/dsa-spell/main.sol b/contracts/polygon/connectors/dsa-spell/main.sol index 023a7ee7..b8f896a4 100644 --- a/contracts/polygon/connectors/dsa-spell/main.sol +++ b/contracts/polygon/connectors/dsa-spell/main.sol @@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2; * @dev Cast spells on DSA. */ -// import files import { AccountInterface } from "../../common/interfaces.sol"; import { Stores } from "../../common/stores.sol"; import { Events } from "./events.sol"; abstract contract DSASpellsResolver is Events, Stores { /** - *@dev Cast spells on DSA. + *@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed. + *@notice Interact with a target DSA by casting spells on it. *@param targetDSA target DSA to cast spells on. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ function castOnDSA( address targetDSA, @@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores { } /** - *@dev Perform spells. - *@param connectors Array of connector names. - *@param datas Array of connector calldatas. + *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully. + * Reverts if none of the spells is successful. + *@notice Casts the first successful spell on the DSA. + *@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]). + *@param datas Array of connector calldatas (function selectors encoded with parameters). */ - function spellFactory(string[] memory connectors, bytes[] memory datas) + function castAny(string[] memory connectors, bytes[] memory datas) external payable returns (string memory eventName, bytes memory eventParam) @@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores { .isConnectors(connectors); require(isOk, "connector-names-invalid"); - string[] memory _eventNames = new string[](_length); - bytes[] memory _eventParams = new bytes[](_length); + string memory _connectorName; + string memory _eventName; + bytes memory _eventParam; + bytes memory returnData; + bool success; for (uint256 i = 0; i < _length; i++) { - (bool success, bytes memory returnData) = _connectors[i] - .delegatecall(datas[i]); + (success, returnData) = _connectors[i].delegatecall(datas[i]); if (success) { - (_eventNames[i], _eventParams[i]) = abi.decode( + _connectorName = connectors[i]; + (_eventName, _eventParam) = abi.decode( returnData, (string, bytes) ); + break; } } + require(success, "dsa-spells-failed"); - eventName = "LogSpellFactory(string[],bytes[])"; - eventParam = abi.encode(_eventNames, _eventParams); + eventName = "LogCastAny(string,string,string[],string,bytes)"; + eventParam = abi.encode( + _connectorName, + _connectorName, + connectors, + _eventName, + _eventParam + ); } }