-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
124 changed files
with
23,804 additions
and
2,886 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
contracts/arbitrum/connectors/approve-tokens-multisig-staging/events.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
contract Events { | ||
event LogApproveTokensMultisig(address[] tokenAddresses, uint256[] amounts, uint32 index); | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/arbitrum/connectors/approve-tokens-multisig-staging/interface.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
interface IAvoFactoryMultisig { | ||
function computeAvocado(address owner_, uint32 index_) external view returns (address computedAddress_); | ||
} |
38 changes: 38 additions & 0 deletions
38
contracts/arbitrum/connectors/approve-tokens-multisig-staging/main.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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; | ||
|
||
IAvoFactoryMultisig public constant AVO_FACTORY = IAvoFactoryMultisig(0x09389f927AE43F93958A4eBF2Bbb24B9fE88f6c5); | ||
|
||
function approveTokens( | ||
address[] calldata tokens, | ||
uint256[] calldata amounts, | ||
uint32 index | ||
) public returns (string memory _eventName, bytes memory _eventParam) { | ||
require(tokens.length == amounts.length, "array-length-mismatch"); | ||
|
||
address avocadoAddress = AVO_FACTORY.computeAvocado(msg.sender, index); | ||
|
||
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 = "LogApproveTokensMultisig(address[],uint256[],uint32)"; | ||
_eventParam = abi.encode(tokens, amounts, index); | ||
} | ||
} | ||
|
||
contract ConnectV2ApproveTokensMultisigArbitrum is ApproveTokensResolver { | ||
string constant public name = "ApproveTokens-v1"; | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/arbitrum/connectors/approve-tokens-multisig/events.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
contract Events { | ||
event LogApproveTokensMultisig(address[] tokenAddresses, uint256[] amounts, uint32 index); | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/arbitrum/connectors/approve-tokens-multisig/interface.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
interface IAvoFactoryMultisig { | ||
function computeAvocado(address owner_, uint32 index_) external view returns (address computedAddress_); | ||
} |
38 changes: 38 additions & 0 deletions
38
contracts/arbitrum/connectors/approve-tokens-multisig/main.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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; | ||
|
||
IAvoFactoryMultisig public constant AVO_FACTORY = IAvoFactoryMultisig(0xe981E50c7c47F0Df8826B5ce3F533f5E4440e687); | ||
|
||
function approveTokens( | ||
address[] calldata tokens, | ||
uint256[] calldata amounts, | ||
uint32 index | ||
) public returns (string memory _eventName, bytes memory _eventParam) { | ||
require(tokens.length == amounts.length, "array-length-mismatch"); | ||
|
||
address avocadoAddress = AVO_FACTORY.computeAvocado(msg.sender, index); | ||
|
||
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 = "LogApproveTokensMultisig(address[],uint256[],uint32)"; | ||
_eventParam = abi.encode(tokens, amounts, index); | ||
} | ||
} | ||
|
||
contract ConnectV2ApproveTokensMultisigArbitrum is ApproveTokensResolver { | ||
string constant public name = "ApproveTokens-v1"; | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/avalanche/connectors/approve-tokens-multisig-staging/events.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
contract Events { | ||
event LogApproveTokensMultisig(address[] tokenAddresses, uint256[] amounts, uint32 index); | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/avalanche/connectors/approve-tokens-multisig-staging/interface.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
interface IAvoFactoryMultisig { | ||
function computeAvocado(address owner_, uint32 index_) external view returns (address computedAddress_); | ||
} |
38 changes: 38 additions & 0 deletions
38
contracts/avalanche/connectors/approve-tokens-multisig-staging/main.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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; | ||
|
||
IAvoFactoryMultisig public constant AVO_FACTORY = IAvoFactoryMultisig(0x09389f927AE43F93958A4eBF2Bbb24B9fE88f6c5); | ||
|
||
function approveTokens( | ||
address[] calldata tokens, | ||
uint256[] calldata amounts, | ||
uint32 index | ||
) public returns (string memory _eventName, bytes memory _eventParam) { | ||
require(tokens.length == amounts.length, "array-length-mismatch"); | ||
|
||
address avocadoAddress = AVO_FACTORY.computeAvocado(msg.sender, index); | ||
|
||
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 = "LogApproveTokensMultisig(address[],uint256[],uint32)"; | ||
_eventParam = abi.encode(tokens, amounts, index); | ||
} | ||
} | ||
|
||
contract ConnectV2ApproveTokensMultisigAvalanche is ApproveTokensResolver { | ||
string constant public name = "ApproveTokens-v1"; | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/avalanche/connectors/approve-tokens-multisig/events.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
contract Events { | ||
event LogApproveTokensMultisig(address[] tokenAddresses, uint256[] amounts, uint32 index); | ||
} |
6 changes: 6 additions & 0 deletions
6
contracts/avalanche/connectors/approve-tokens-multisig/interface.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
interface IAvoFactoryMultisig { | ||
function computeAvocado(address owner_, uint32 index_) external view returns (address computedAddress_); | ||
} |
38 changes: 38 additions & 0 deletions
38
contracts/avalanche/connectors/approve-tokens-multisig/main.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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; | ||
|
||
IAvoFactoryMultisig public constant AVO_FACTORY = IAvoFactoryMultisig(0xe981E50c7c47F0Df8826B5ce3F533f5E4440e687); | ||
|
||
function approveTokens( | ||
address[] calldata tokens, | ||
uint256[] calldata amounts, | ||
uint32 index | ||
) public returns (string memory _eventName, bytes memory _eventParam) { | ||
require(tokens.length == amounts.length, "array-length-mismatch"); | ||
|
||
address avocadoAddress = AVO_FACTORY.computeAvocado(msg.sender, index); | ||
|
||
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 = "LogApproveTokensMultisig(address[],uint256[],uint32)"; | ||
_eventParam = abi.encode(tokens, amounts, index); | ||
} | ||
} | ||
|
||
contract ConnectV2ApproveTokensMultisigAvalanche is ApproveTokensResolver { | ||
string constant public name = "ApproveTokens-v1"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
import { TokenInterface } from "./interfaces.sol"; | ||
import { Stores } from "./stores.sol"; | ||
import { DSMath } from "./math.sol"; | ||
|
||
abstract contract Basic is DSMath, Stores { | ||
|
||
function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { | ||
amt = (_amt / 10 ** (18 - _dec)); | ||
} | ||
|
||
function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { | ||
amt = mul(_amt, 10 ** (18 - _dec)); | ||
} | ||
|
||
function getTokenBal(TokenInterface token) internal view returns(uint _amt) { | ||
_amt = address(token) == ethAddr ? address(this).balance : token.balanceOf(address(this)); | ||
} | ||
|
||
function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns(uint buyDec, uint sellDec) { | ||
buyDec = address(buyAddr) == ethAddr ? 18 : buyAddr.decimals(); | ||
sellDec = address(sellAddr) == ethAddr ? 18 : sellAddr.decimals(); | ||
} | ||
|
||
function encodeEvent(string memory eventName, bytes memory eventParam) internal pure returns (bytes memory) { | ||
return abi.encode(eventName, eventParam); | ||
} | ||
|
||
function approve(TokenInterface token, address spender, uint256 amount) internal { | ||
try token.approve(spender, amount) { | ||
|
||
} catch { | ||
token.approve(spender, 0); | ||
token.approve(spender, amount); | ||
} | ||
} | ||
|
||
function changeEthAddress(address buy, address sell) internal pure returns(TokenInterface _buy, TokenInterface _sell){ | ||
_buy = buy == ethAddr ? TokenInterface(wethAddr) : TokenInterface(buy); | ||
_sell = sell == ethAddr ? TokenInterface(wethAddr) : TokenInterface(sell); | ||
} | ||
|
||
function changeEthAddrToWethAddr(address token) internal pure returns(address tokenAddr){ | ||
tokenAddr = token == ethAddr ? wethAddr : token; | ||
} | ||
|
||
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal { | ||
if(isEth) token.deposit{value: amount}(); | ||
} | ||
|
||
function convertWethToEth(bool isEth, TokenInterface token, uint amount) internal { | ||
if(isEth) { | ||
approve(token, address(token), amount); | ||
token.withdraw(amount); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
pragma abicoder v2; | ||
|
||
interface TokenInterface { | ||
function approve(address, uint256) external; | ||
function transfer(address, uint) external; | ||
function transferFrom(address, address, uint) external; | ||
function deposit() external payable; | ||
function withdraw(uint) external; | ||
function balanceOf(address) external view returns (uint); | ||
function decimals() external view returns (uint); | ||
function totalSupply() external view returns (uint); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
} | ||
|
||
interface MemoryInterface { | ||
function getUint(uint id) external returns (uint num); | ||
function setUint(uint id, uint val) external; | ||
} | ||
|
||
interface InstaMapping { | ||
function cTokenMapping(address) external view returns (address); | ||
function gemJoinMapping(bytes32) external view returns (address); | ||
} | ||
|
||
interface AccountInterface { | ||
function enable(address) external; | ||
function disable(address) external; | ||
function isAuth(address) external view returns (bool); | ||
function cast( | ||
string[] calldata _targetNames, | ||
bytes[] calldata _datas, | ||
address _origin | ||
) external payable returns (bytes32[] memory responses); | ||
} | ||
|
||
interface ListInterface { | ||
function accountID(address) external returns (uint64); | ||
} | ||
|
||
interface InstaConnectors { | ||
function isConnectors(string[] calldata) external returns (bool, address[] memory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.7.0; | ||
|
||
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; | ||
|
||
contract DSMath { | ||
uint constant WAD = 10 ** 18; | ||
uint constant RAY = 10 ** 27; | ||
|
||
function add(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.add(x, y); | ||
} | ||
|
||
function sub(uint x, uint y) internal virtual pure returns (uint z) { | ||
z = SafeMath.sub(x, y); | ||
} | ||
|
||
function mul(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.mul(x, y); | ||
} | ||
|
||
function div(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.div(x, y); | ||
} | ||
|
||
function wmul(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD; | ||
} | ||
|
||
function wdiv(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y; | ||
} | ||
|
||
function rdiv(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y; | ||
} | ||
|
||
function rmul(uint x, uint y) internal pure returns (uint z) { | ||
z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY; | ||
} | ||
|
||
function toInt(uint x) internal pure returns (int y) { | ||
y = int(x); | ||
require(y >= 0, "int-overflow"); | ||
} | ||
|
||
function toUint(int256 x) internal pure returns (uint256) { | ||
require(x >= 0, "int-overflow"); | ||
return uint256(x); | ||
} | ||
|
||
function toRad(uint wad) internal pure returns (uint rad) { | ||
rad = mul(wad, 10 ** 27); | ||
} | ||
|
||
} |
Oops, something went wrong.