From ce457e8c8652921d1f697eb936534c92951d7c55 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Tue, 10 May 2022 14:47:57 +0530 Subject: [PATCH] updated basic connector-all chains --- .../arbitrum/connectors/basic/events.sol | 22 +++++++++++-- contracts/arbitrum/connectors/basic/main.sol | 30 ++++++++++++++++- .../avalanche/connectors/basic/events.sol | 22 +++++++++++-- contracts/avalanche/connectors/basic/main.sol | 30 ++++++++++++++++- contracts/fantom/connectors/basic/events.sol | 22 +++++++++++-- contracts/fantom/connectors/basic/main.sol | 32 +++++++++++++++++-- .../optimism/connectors/basic/events.sol | 22 +++++++++++-- contracts/optimism/connectors/basic/main.sol | 30 ++++++++++++++++- contracts/polygon/connectors/basic/events.sol | 22 +++++++++++-- contracts/polygon/connectors/basic/main.sol | 30 ++++++++++++++++- 10 files changed, 246 insertions(+), 16 deletions(-) diff --git a/contracts/arbitrum/connectors/basic/events.sol b/contracts/arbitrum/connectors/basic/events.sol index 6ce85a22..edcea162 100644 --- a/contracts/arbitrum/connectors/basic/events.sol +++ b/contracts/arbitrum/connectors/basic/events.sol @@ -2,6 +2,24 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); - event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); + event LogDeposit( + address indexed erc20, + uint256 tokenAmt, + uint256 getId, + uint256 setId + ); + event LogWithdraw( + address indexed erc20, + uint256 tokenAmt, + address indexed to, + uint256 getId, + uint256 setId + ); + event LogDepositFrom( + address indexed erc20, + uint256 tokenAmt, + address indexed from, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/arbitrum/connectors/basic/main.sol b/contracts/arbitrum/connectors/basic/main.sol index 42243fee..2f13bfcf 100644 --- a/contracts/arbitrum/connectors/basic/main.sol +++ b/contracts/arbitrum/connectors/basic/main.sol @@ -46,6 +46,34 @@ abstract contract BasicResolver is Events, DSMath, Basic { _eventParam = abi.encode(token, _amt, getId, setId); } + /** + * @dev Deposit Assets To Smart Account From any user. + * @notice Deposit a token to DSA from any user. + * @param token The address of the token to deposit. (Note: ETH is not supported. Use `deposit()`) + * @param amt The amount of tokens to deposit. (For max: `uint256(-1)`) + * @param from The address depositing the token. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function depositFrom( + address token, + uint256 amt, + address from, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + require(token != ethAddr, "eth-not-supported"); + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(from) : _amt; + tokenContract.safeTransferFrom(from, address(this), _amt); + + setUint(setId, _amt); + + _eventName = "LogDepositFrom(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, from, getId, setId); + } + /** * @dev Withdraw Assets from Smart Account * @notice Withdraw a token from DSA @@ -79,5 +107,5 @@ abstract contract BasicResolver is Events, DSMath, Basic { } contract ConnectV2BasicArbitrum is BasicResolver { - string constant public name = "Basic-v1"; + string constant public name = "Basic-v1.1"; } diff --git a/contracts/avalanche/connectors/basic/events.sol b/contracts/avalanche/connectors/basic/events.sol index 6ce85a22..edcea162 100644 --- a/contracts/avalanche/connectors/basic/events.sol +++ b/contracts/avalanche/connectors/basic/events.sol @@ -2,6 +2,24 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); - event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); + event LogDeposit( + address indexed erc20, + uint256 tokenAmt, + uint256 getId, + uint256 setId + ); + event LogWithdraw( + address indexed erc20, + uint256 tokenAmt, + address indexed to, + uint256 getId, + uint256 setId + ); + event LogDepositFrom( + address indexed erc20, + uint256 tokenAmt, + address indexed from, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/avalanche/connectors/basic/main.sol b/contracts/avalanche/connectors/basic/main.sol index 3659b357..741633f1 100644 --- a/contracts/avalanche/connectors/basic/main.sol +++ b/contracts/avalanche/connectors/basic/main.sol @@ -46,6 +46,34 @@ abstract contract BasicResolver is Events, DSMath, Basic { _eventParam = abi.encode(token, _amt, getId, setId); } + /** + * @dev Deposit Assets To Smart Account From any user. + * @notice Deposit a token to DSA from any user. + * @param token The address of the token to deposit. (Note: AVAX is not supported. Use `deposit()`) + * @param amt The amount of tokens to deposit. (For max: `uint256(-1)`) + * @param from The address depositing the token. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function depositFrom( + address token, + uint256 amt, + address from, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + require(token != avaxAddr, "avax-not-supported"); + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(from) : _amt; + tokenContract.safeTransferFrom(from, address(this), _amt); + + setUint(setId, _amt); + + _eventName = "LogDepositFrom(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, from, getId, setId); + } + /** * @dev Withdraw Assets from Smart Account * @notice Withdraw a token from DSA @@ -79,5 +107,5 @@ abstract contract BasicResolver is Events, DSMath, Basic { } contract ConnectV2BasicAvalanche is BasicResolver { - string constant public name = "Basic-v1"; + string constant public name = "Basic-v1.1"; } diff --git a/contracts/fantom/connectors/basic/events.sol b/contracts/fantom/connectors/basic/events.sol index 6ce85a22..edcea162 100644 --- a/contracts/fantom/connectors/basic/events.sol +++ b/contracts/fantom/connectors/basic/events.sol @@ -2,6 +2,24 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); - event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); + event LogDeposit( + address indexed erc20, + uint256 tokenAmt, + uint256 getId, + uint256 setId + ); + event LogWithdraw( + address indexed erc20, + uint256 tokenAmt, + address indexed to, + uint256 getId, + uint256 setId + ); + event LogDepositFrom( + address indexed erc20, + uint256 tokenAmt, + address indexed from, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/fantom/connectors/basic/main.sol b/contracts/fantom/connectors/basic/main.sol index 85aa4af1..98bb541f 100644 --- a/contracts/fantom/connectors/basic/main.sol +++ b/contracts/fantom/connectors/basic/main.sol @@ -20,7 +20,7 @@ abstract contract BasicResolver is Events, DSMath, Basic { /** * @dev Deposit Assets To Smart Account. * @notice Deposit a token to DSA - * @param token The address of the token to deposit. (For MATIC: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param token The address of the token to deposit. (For FTM: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param amt The amount of tokens to deposit. (For max: `uint256(-1)` (Not valid for MATIC)) * @param getId ID to retrieve amt. * @param setId ID stores the amount of tokens deposited. @@ -46,6 +46,34 @@ abstract contract BasicResolver is Events, DSMath, Basic { _eventParam = abi.encode(token, _amt, getId, setId); } + /** + * @dev Deposit Assets To Smart Account From any user. + * @notice Deposit a token to DSA from any user. + * @param token The address of the token to deposit. (Note: FTM is not supported. Use `deposit()`) + * @param amt The amount of tokens to deposit. (For max: `uint256(-1)`) + * @param from The address depositing the token. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function depositFrom( + address token, + uint256 amt, + address from, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + require(token != ftmAddr, "ftm-not-supported"); + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(from) : _amt; + tokenContract.safeTransferFrom(from, address(this), _amt); + + setUint(setId, _amt); + + _eventName = "LogDepositFrom(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, from, getId, setId); + } + /** * @dev Withdraw Assets from Smart Account * @notice Withdraw a token from DSA @@ -79,5 +107,5 @@ abstract contract BasicResolver is Events, DSMath, Basic { } contract ConnectV2BasicFantom is BasicResolver { - string constant public name = "Basic-v1"; + string constant public name = "Basic-v1.1"; } diff --git a/contracts/optimism/connectors/basic/events.sol b/contracts/optimism/connectors/basic/events.sol index 6ce85a22..edcea162 100644 --- a/contracts/optimism/connectors/basic/events.sol +++ b/contracts/optimism/connectors/basic/events.sol @@ -2,6 +2,24 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); - event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); + event LogDeposit( + address indexed erc20, + uint256 tokenAmt, + uint256 getId, + uint256 setId + ); + event LogWithdraw( + address indexed erc20, + uint256 tokenAmt, + address indexed to, + uint256 getId, + uint256 setId + ); + event LogDepositFrom( + address indexed erc20, + uint256 tokenAmt, + address indexed from, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/optimism/connectors/basic/main.sol b/contracts/optimism/connectors/basic/main.sol index ad4bc98d..c52fc024 100644 --- a/contracts/optimism/connectors/basic/main.sol +++ b/contracts/optimism/connectors/basic/main.sol @@ -45,6 +45,34 @@ abstract contract BasicResolver is Events, DSMath, Basic { _eventParam = abi.encode(token, _amt, getId, setId); } + /** + * @dev Deposit Assets To Smart Account From any user. + * @notice Deposit a token to DSA from any user. + * @param token The address of the token to deposit. (Note: ETH is not supported. Use `deposit()`) + * @param amt The amount of tokens to deposit. (For max: `uint256(-1)`) + * @param from The address depositing the token. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function depositFrom( + address token, + uint256 amt, + address from, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + require(token != ethAddr, "eth-not-supported"); + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(from) : _amt; + tokenContract.safeTransferFrom(from, address(this), _amt); + + setUint(setId, _amt); + + _eventName = "LogDepositFrom(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, from, getId, setId); + } + /** * @dev Withdraw Assets from Smart Account * @notice Withdraw a token from DSA @@ -78,5 +106,5 @@ abstract contract BasicResolver is Events, DSMath, Basic { } contract ConnectV2BasicOptimism is BasicResolver { - string constant public name = "Basic-v1"; + string constant public name = "Basic-v1.1"; } diff --git a/contracts/polygon/connectors/basic/events.sol b/contracts/polygon/connectors/basic/events.sol index 6ce85a22..edcea162 100644 --- a/contracts/polygon/connectors/basic/events.sol +++ b/contracts/polygon/connectors/basic/events.sol @@ -2,6 +2,24 @@ pragma solidity ^0.7.0; contract Events { - event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); - event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); + event LogDeposit( + address indexed erc20, + uint256 tokenAmt, + uint256 getId, + uint256 setId + ); + event LogWithdraw( + address indexed erc20, + uint256 tokenAmt, + address indexed to, + uint256 getId, + uint256 setId + ); + event LogDepositFrom( + address indexed erc20, + uint256 tokenAmt, + address indexed from, + uint256 getId, + uint256 setId + ); } diff --git a/contracts/polygon/connectors/basic/main.sol b/contracts/polygon/connectors/basic/main.sol index b2c3ca6d..960c0f36 100644 --- a/contracts/polygon/connectors/basic/main.sol +++ b/contracts/polygon/connectors/basic/main.sol @@ -46,6 +46,34 @@ abstract contract BasicResolver is Events, DSMath, Basic { _eventParam = abi.encode(token, _amt, getId, setId); } + /** + * @dev Deposit Assets To Smart Account From any user. + * @notice Deposit a token to DSA from any user. + * @param token The address of the token to deposit. (Note: MATIC is not supported. Use `deposit()`) + * @param amt The amount of tokens to deposit. (For max: `uint256(-1)`) + * @param from The address depositing the token. + * @param getId ID to retrieve amt. + * @param setId ID stores the amount of tokens deposited. + */ + function depositFrom( + address token, + uint256 amt, + address from, + uint256 getId, + uint256 setId + ) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint _amt = getUint(getId, amt); + require(token != maticAddr, "eth-not-supported"); + IERC20 tokenContract = IERC20(token); + _amt = _amt == uint(-1) ? tokenContract.balanceOf(from) : _amt; + tokenContract.safeTransferFrom(from, address(this), _amt); + + setUint(setId, _amt); + + _eventName = "LogDepositFrom(address,uint256,address,uint256,uint256)"; + _eventParam = abi.encode(token, _amt, from, getId, setId); + } + /** * @dev Withdraw Assets from Smart Account * @notice Withdraw a token from DSA @@ -79,5 +107,5 @@ abstract contract BasicResolver is Events, DSMath, Basic { } contract ConnectV2Basic is BasicResolver { - string constant public name = "Basic-v1"; + string constant public name = "Basic-v1.1"; }