mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Merge pull request #288 from Instadapp/dsa-approve-connector
Added approve contracts - production
This commit is contained in:
commit
4501d91293
6
contracts/arbitrum/connectors/approve-tokens/events.sol
Normal file
6
contracts/arbitrum/connectors/approve-tokens/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogApproveTokens(address[] tokenAddresses, uint256[] amounts);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IAvoFactory {
|
||||
function computeAddress(address owner_) external view returns (address);
|
||||
}
|
37
contracts/arbitrum/connectors/approve-tokens/main.sol
Normal file
37
contracts/arbitrum/connectors/approve-tokens/main.sol
Normal file
|
@ -0,0 +1,37 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import "./events.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract ApproveTokensResolver is Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
IAvoFactory public constant AVO_FACTORY = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978);
|
||||
|
||||
function approveTokens(
|
||||
address[] calldata tokens,
|
||||
uint256[] calldata amounts
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(tokens.length == amounts.length, "array-length-mismatch");
|
||||
|
||||
address avocadoAddress = AVO_FACTORY.computeAddress(msg.sender);
|
||||
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
uint256 allowanceAmount =
|
||||
amounts[i] == type(uint256).max
|
||||
? IERC20(tokens[i]).balanceOf(address(this))
|
||||
: amounts[i];
|
||||
IERC20(tokens[i]).safeApprove(avocadoAddress, allowanceAmount);
|
||||
}
|
||||
|
||||
_eventName = "LogApproveTokens(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, amounts);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ApproveTokensArbitrum is ApproveTokensResolver {
|
||||
string constant public name = "ApproveTokens-v1";
|
||||
}
|
6
contracts/avalanche/connectors/approve-tokens/events.sol
Normal file
6
contracts/avalanche/connectors/approve-tokens/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogApproveTokens(address[] tokenAddresses, uint256[] amounts);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IAvoFactory {
|
||||
function computeAddress(address owner_) external view returns (address);
|
||||
}
|
37
contracts/avalanche/connectors/approve-tokens/main.sol
Normal file
37
contracts/avalanche/connectors/approve-tokens/main.sol
Normal file
|
@ -0,0 +1,37 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import "./events.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract ApproveTokensResolver is Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
IAvoFactory public constant AVO_FACTORY = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978);
|
||||
|
||||
function approveTokens(
|
||||
address[] calldata tokens,
|
||||
uint256[] calldata amounts
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(tokens.length == amounts.length, "array-length-mismatch");
|
||||
|
||||
address avocadoAddress = AVO_FACTORY.computeAddress(msg.sender);
|
||||
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
uint256 allowanceAmount =
|
||||
amounts[i] == type(uint256).max
|
||||
? IERC20(tokens[i]).balanceOf(address(this))
|
||||
: amounts[i];
|
||||
IERC20(tokens[i]).safeApprove(avocadoAddress, allowanceAmount);
|
||||
}
|
||||
|
||||
_eventName = "LogApproveTokens(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, amounts);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ApproveTokensAvalanche is ApproveTokensResolver {
|
||||
string constant public name = "ApproveTokens-v1";
|
||||
}
|
6
contracts/mainnet/connectors/approve-tokens/events.sol
Normal file
6
contracts/mainnet/connectors/approve-tokens/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogApproveTokens(address[] tokenAddresses, uint256[] amounts);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IAvoFactory {
|
||||
function computeAddress(address owner_) external view returns (address);
|
||||
}
|
37
contracts/mainnet/connectors/approve-tokens/main.sol
Normal file
37
contracts/mainnet/connectors/approve-tokens/main.sol
Normal file
|
@ -0,0 +1,37 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import "./events.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract ApproveTokensResolver is Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
IAvoFactory public constant AVO_FACTORY = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978);
|
||||
|
||||
function approveTokens(
|
||||
address[] calldata tokens,
|
||||
uint256[] calldata amounts
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(tokens.length == amounts.length, "array-length-mismatch");
|
||||
|
||||
address avocadoAddress = AVO_FACTORY.computeAddress(msg.sender);
|
||||
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
uint256 allowanceAmount =
|
||||
amounts[i] == type(uint256).max
|
||||
? IERC20(tokens[i]).balanceOf(address(this))
|
||||
: amounts[i];
|
||||
IERC20(tokens[i]).safeApprove(avocadoAddress, allowanceAmount);
|
||||
}
|
||||
|
||||
_eventName = "LogApproveTokens(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, amounts);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ApproveTokens is ApproveTokensResolver {
|
||||
string constant public name = "ApproveTokens-v1";
|
||||
}
|
6
contracts/optimism/connectors/approve-tokens/events.sol
Normal file
6
contracts/optimism/connectors/approve-tokens/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogApproveTokens(address[] tokenAddresses, uint256[] amounts);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IAvoFactory {
|
||||
function computeAddress(address owner_) external view returns (address);
|
||||
}
|
37
contracts/optimism/connectors/approve-tokens/main.sol
Normal file
37
contracts/optimism/connectors/approve-tokens/main.sol
Normal file
|
@ -0,0 +1,37 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import "./events.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract ApproveTokensResolver is Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
IAvoFactory public constant AVO_FACTORY = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978);
|
||||
|
||||
function approveTokens(
|
||||
address[] calldata tokens,
|
||||
uint256[] calldata amounts
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(tokens.length == amounts.length, "array-length-mismatch");
|
||||
|
||||
address avocadoAddress = AVO_FACTORY.computeAddress(msg.sender);
|
||||
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
uint256 allowanceAmount =
|
||||
amounts[i] == type(uint256).max
|
||||
? IERC20(tokens[i]).balanceOf(address(this))
|
||||
: amounts[i];
|
||||
IERC20(tokens[i]).safeApprove(avocadoAddress, allowanceAmount);
|
||||
}
|
||||
|
||||
_eventName = "LogApproveTokens(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, amounts);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ApproveTokensOptimism is ApproveTokensResolver {
|
||||
string constant public name = "ApproveTokens-v1";
|
||||
}
|
6
contracts/polygon/connectors/approve-tokens/events.sol
Normal file
6
contracts/polygon/connectors/approve-tokens/events.sol
Normal file
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
contract Events {
|
||||
event LogApproveTokens(address[] tokenAddresses, uint256[] amounts);
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
interface IAvoFactory {
|
||||
function computeAddress(address owner_) external view returns (address);
|
||||
}
|
37
contracts/polygon/connectors/approve-tokens/main.sol
Normal file
37
contracts/polygon/connectors/approve-tokens/main.sol
Normal file
|
@ -0,0 +1,37 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.7.0;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import "./events.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract ApproveTokensResolver is Events {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
IAvoFactory public constant AVO_FACTORY = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978);
|
||||
|
||||
function approveTokens(
|
||||
address[] calldata tokens,
|
||||
uint256[] calldata amounts
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
require(tokens.length == amounts.length, "array-length-mismatch");
|
||||
|
||||
address avocadoAddress = AVO_FACTORY.computeAddress(msg.sender);
|
||||
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
uint256 allowanceAmount =
|
||||
amounts[i] == type(uint256).max
|
||||
? IERC20(tokens[i]).balanceOf(address(this))
|
||||
: amounts[i];
|
||||
IERC20(tokens[i]).safeApprove(avocadoAddress, allowanceAmount);
|
||||
}
|
||||
|
||||
_eventName = "LogApproveTokens(address[],uint256[])";
|
||||
_eventParam = abi.encode(tokens, amounts);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2ApproveTokensPolygon is ApproveTokensResolver {
|
||||
string constant public name = "ApproveTokens-v1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user