From 3e720803be01f4dd012f0daac1ea9f60d92c2766 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Fri, 14 Apr 2023 15:31:53 +0400 Subject: [PATCH 1/9] Added approve contracts - production --- .../connectors/approve-tokens/events.sol | 6 +++ .../connectors/approve-tokens/interface.sol | 6 +++ .../connectors/approve-tokens/main.sol | 37 +++++++++++++++++++ .../connectors/approve-tokens/events.sol | 6 +++ .../connectors/approve-tokens/interface.sol | 6 +++ .../connectors/approve-tokens/main.sol | 37 +++++++++++++++++++ .../connectors/approve-tokens/events.sol | 6 +++ .../connectors/approve-tokens/interface.sol | 6 +++ .../connectors/approve-tokens/main.sol | 37 +++++++++++++++++++ .../connectors/approve-tokens/events.sol | 6 +++ .../connectors/approve-tokens/interface.sol | 6 +++ .../connectors/approve-tokens/main.sol | 37 +++++++++++++++++++ .../connectors/approve-tokens/events.sol | 6 +++ .../connectors/approve-tokens/interface.sol | 6 +++ .../connectors/approve-tokens/main.sol | 37 +++++++++++++++++++ 15 files changed, 245 insertions(+) create mode 100644 contracts/arbitrum/connectors/approve-tokens/events.sol create mode 100644 contracts/arbitrum/connectors/approve-tokens/interface.sol create mode 100644 contracts/arbitrum/connectors/approve-tokens/main.sol create mode 100644 contracts/avalanche/connectors/approve-tokens/events.sol create mode 100644 contracts/avalanche/connectors/approve-tokens/interface.sol create mode 100644 contracts/avalanche/connectors/approve-tokens/main.sol create mode 100644 contracts/mainnet/connectors/approve-tokens/events.sol create mode 100644 contracts/mainnet/connectors/approve-tokens/interface.sol create mode 100644 contracts/mainnet/connectors/approve-tokens/main.sol create mode 100644 contracts/optimism/connectors/approve-tokens/events.sol create mode 100644 contracts/optimism/connectors/approve-tokens/interface.sol create mode 100644 contracts/optimism/connectors/approve-tokens/main.sol create mode 100644 contracts/polygon/connectors/approve-tokens/events.sol create mode 100644 contracts/polygon/connectors/approve-tokens/interface.sol create mode 100644 contracts/polygon/connectors/approve-tokens/main.sol diff --git a/contracts/arbitrum/connectors/approve-tokens/events.sol b/contracts/arbitrum/connectors/approve-tokens/events.sol new file mode 100644 index 00000000..704273be --- /dev/null +++ b/contracts/arbitrum/connectors/approve-tokens/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogApproveTokens(address[] tokenAddresses, uint256[] amounts); +} \ No newline at end of file diff --git a/contracts/arbitrum/connectors/approve-tokens/interface.sol b/contracts/arbitrum/connectors/approve-tokens/interface.sol new file mode 100644 index 00000000..38abe986 --- /dev/null +++ b/contracts/arbitrum/connectors/approve-tokens/interface.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} \ No newline at end of file diff --git a/contracts/arbitrum/connectors/approve-tokens/main.sol b/contracts/arbitrum/connectors/approve-tokens/main.sol new file mode 100644 index 00000000..9545d04f --- /dev/null +++ b/contracts/arbitrum/connectors/approve-tokens/main.sol @@ -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"; +} \ No newline at end of file diff --git a/contracts/avalanche/connectors/approve-tokens/events.sol b/contracts/avalanche/connectors/approve-tokens/events.sol new file mode 100644 index 00000000..704273be --- /dev/null +++ b/contracts/avalanche/connectors/approve-tokens/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogApproveTokens(address[] tokenAddresses, uint256[] amounts); +} \ No newline at end of file diff --git a/contracts/avalanche/connectors/approve-tokens/interface.sol b/contracts/avalanche/connectors/approve-tokens/interface.sol new file mode 100644 index 00000000..38abe986 --- /dev/null +++ b/contracts/avalanche/connectors/approve-tokens/interface.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} \ No newline at end of file diff --git a/contracts/avalanche/connectors/approve-tokens/main.sol b/contracts/avalanche/connectors/approve-tokens/main.sol new file mode 100644 index 00000000..b7d2cd82 --- /dev/null +++ b/contracts/avalanche/connectors/approve-tokens/main.sol @@ -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"; +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/approve-tokens/events.sol b/contracts/mainnet/connectors/approve-tokens/events.sol new file mode 100644 index 00000000..704273be --- /dev/null +++ b/contracts/mainnet/connectors/approve-tokens/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogApproveTokens(address[] tokenAddresses, uint256[] amounts); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/approve-tokens/interface.sol b/contracts/mainnet/connectors/approve-tokens/interface.sol new file mode 100644 index 00000000..38abe986 --- /dev/null +++ b/contracts/mainnet/connectors/approve-tokens/interface.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/approve-tokens/main.sol b/contracts/mainnet/connectors/approve-tokens/main.sol new file mode 100644 index 00000000..caea31af --- /dev/null +++ b/contracts/mainnet/connectors/approve-tokens/main.sol @@ -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"; +} \ No newline at end of file diff --git a/contracts/optimism/connectors/approve-tokens/events.sol b/contracts/optimism/connectors/approve-tokens/events.sol new file mode 100644 index 00000000..704273be --- /dev/null +++ b/contracts/optimism/connectors/approve-tokens/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogApproveTokens(address[] tokenAddresses, uint256[] amounts); +} \ No newline at end of file diff --git a/contracts/optimism/connectors/approve-tokens/interface.sol b/contracts/optimism/connectors/approve-tokens/interface.sol new file mode 100644 index 00000000..38abe986 --- /dev/null +++ b/contracts/optimism/connectors/approve-tokens/interface.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} \ No newline at end of file diff --git a/contracts/optimism/connectors/approve-tokens/main.sol b/contracts/optimism/connectors/approve-tokens/main.sol new file mode 100644 index 00000000..b1a22daa --- /dev/null +++ b/contracts/optimism/connectors/approve-tokens/main.sol @@ -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"; +} \ No newline at end of file diff --git a/contracts/polygon/connectors/approve-tokens/events.sol b/contracts/polygon/connectors/approve-tokens/events.sol new file mode 100644 index 00000000..704273be --- /dev/null +++ b/contracts/polygon/connectors/approve-tokens/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogApproveTokens(address[] tokenAddresses, uint256[] amounts); +} \ No newline at end of file diff --git a/contracts/polygon/connectors/approve-tokens/interface.sol b/contracts/polygon/connectors/approve-tokens/interface.sol new file mode 100644 index 00000000..38abe986 --- /dev/null +++ b/contracts/polygon/connectors/approve-tokens/interface.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} \ No newline at end of file diff --git a/contracts/polygon/connectors/approve-tokens/main.sol b/contracts/polygon/connectors/approve-tokens/main.sol new file mode 100644 index 00000000..33f1e421 --- /dev/null +++ b/contracts/polygon/connectors/approve-tokens/main.sol @@ -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"; +} \ No newline at end of file From 9523161e69cffc903ab4ecc27c5b7da46ef29af4 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Mon, 17 Apr 2023 13:17:49 +0400 Subject: [PATCH 2/9] Added makerdao import connector - production --- .../connectors/makerdao-import/events.sol | 6 +++ .../connectors/makerdao-import/helpers.sol | 34 ++++++++++++++ .../connectors/makerdao-import/interface.sol | 45 +++++++++++++++++++ .../connectors/makerdao-import/main.sol | 27 +++++++++++ package-lock.json | 20 +++++++++ 5 files changed, 132 insertions(+) create mode 100644 contracts/mainnet/connectors/makerdao-import/events.sol create mode 100644 contracts/mainnet/connectors/makerdao-import/helpers.sol create mode 100644 contracts/mainnet/connectors/makerdao-import/interface.sol create mode 100644 contracts/mainnet/connectors/makerdao-import/main.sol diff --git a/contracts/mainnet/connectors/makerdao-import/events.sol b/contracts/mainnet/connectors/makerdao-import/events.sol new file mode 100644 index 00000000..6f59d9ab --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/events.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogTransferToAvo(uint256 indexed vault, bytes32 indexed ilk, address indexed avoAddress); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/makerdao-import/helpers.sol b/contracts/mainnet/connectors/makerdao-import/helpers.sol new file mode 100644 index 00000000..1c261d28 --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/helpers.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import { ManagerLike, VatLike, IAvoFactory, IAvoCreditManagerAddress } from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + ManagerLike internal constant managerContract = ManagerLike(0x5ef30b9986345249bc32d8928B7ee64DE9435E39); + IAvoFactory internal constant avoFactory = IAvoFactory(0x3AdAE9699029AB2953F607AE1f62372681D35978); + IAvoCreditManagerAddress internal constant avoCreditManager = IAvoCreditManagerAddress(0xE4C9751D5CBCde942165871Ca2089172307F9971); + + function getVaultData(uint vault) internal view returns (bytes32 ilk, address urn) { + ilk = managerContract.ilks(vault); + urn = managerContract.urns(vault); + } + + function stringToBytes32(string memory str) internal pure returns (bytes32 result) { + require(bytes(str).length != 0, "string-empty"); + assembly { + result := mload(add(str, 32)) + } + } + + function getVault(uint vault) internal view returns (uint _vault) { + if (vault == 0) { + require(managerContract.count(address(this)) > 0, "no-vault-opened"); + _vault = managerContract.last(address(this)); + } else { + _vault = vault; + } + } +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/makerdao-import/interface.sol b/contracts/mainnet/connectors/makerdao-import/interface.sol new file mode 100644 index 00000000..7d2d7534 --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/interface.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { TokenInterface } from "../../common/interfaces.sol"; + +interface ManagerLike { + function cdpCan(address, uint, address) external view returns (uint); + function ilks(uint) external view returns (bytes32); + function last(address) external view returns (uint); + function count(address) external view returns (uint); + function owns(uint) external view returns (address); + function urns(uint) external view returns (address); + function vat() external view returns (address); + function open(bytes32, address) external returns (uint); + function give(uint, address) external; + function frob(uint, int, int) external; + function flux(uint, address, uint) external; + function move(uint, address, uint) external; +} + +interface VatLike { + function can(address, address) external view returns (uint); + function ilks(bytes32) external view returns (uint, uint, uint, uint, uint); + function dai(address) external view returns (uint); + function urns(bytes32, address) external view returns (uint, uint); + function frob( + bytes32, + address, + address, + address, + int, + int + ) external; + function hope(address) external; + function move(address, address, uint) external; + function gem(bytes32, address) external view returns (uint); +} + +interface IAvoFactory { + function computeAddress(address owner_) external view returns (address); +} + +interface IAvoCreditManagerAddress { + function dsaMakerImport(uint256 vaultId_, address avoSafe_, address auth_) external; +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/makerdao-import/main.sol b/contracts/mainnet/connectors/makerdao-import/main.sol new file mode 100644 index 00000000..0ca17b80 --- /dev/null +++ b/contracts/mainnet/connectors/makerdao-import/main.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import { TokenInterface, AccountInterface } from "../../common/interfaces.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; + +contract MakerTransferResolver is Helpers, Events { + function transferToAvo(uint256 vaultId) public payable returns (string memory _eventName, bytes memory _eventParam) { + uint256 _vault = getVault(vaultId); + (bytes32 ilk,) = getVaultData(_vault); + + require(managerContract.owns(_vault) == address(this), "not-owner"); + + address avoAddress = avoFactory.computeAddress(msg.sender); + managerContract.give(_vault, avoAddress); + + avoCreditManager.dsaMakerImport(_vault, avoAddress, msg.sender); + + _eventName = "LogTransferToAvo(uint256,bytes32,address)"; + _eventParam = abi.encode(_vault, ilk, avoAddress); + } +} + +contract ConnectV2AvoMakerImport is MakerTransferResolver { + string public constant name = "Avocado-Maker-Import-v1.0"; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bc7ad39e..66958ac1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24015,6 +24015,20 @@ "node": ">=6" } }, + "node_modules/mocha/node_modules/fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "deprecated": "\"Please update to latest v2.3 or v2.2\"", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/mocha/node_modules/glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", @@ -49813,6 +49827,12 @@ "locate-path": "^3.0.0" } }, + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "optional": true + }, "glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", From c3c5ce25603339d90935d61277a071c9f216d661 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 19 Apr 2023 20:06:43 +0400 Subject: [PATCH 3/9] Add ARB token claim connector --- .../arbitrum/connectors/arb-claim/events.sol | 23 +++++++ .../connectors/arb-claim/interface.sol | 39 ++++++++++++ .../arbitrum/connectors/arb-claim/main.sol | 60 +++++++++++++++++++ .../connectors/arb-claim/variables.sol | 20 +++++++ 4 files changed, 142 insertions(+) create mode 100644 contracts/arbitrum/connectors/arb-claim/events.sol create mode 100644 contracts/arbitrum/connectors/arb-claim/interface.sol create mode 100644 contracts/arbitrum/connectors/arb-claim/main.sol create mode 100644 contracts/arbitrum/connectors/arb-claim/variables.sol diff --git a/contracts/arbitrum/connectors/arb-claim/events.sol b/contracts/arbitrum/connectors/arb-claim/events.sol new file mode 100644 index 00000000..788fad86 --- /dev/null +++ b/contracts/arbitrum/connectors/arb-claim/events.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +contract Events { + event LogArbAirdropClaimed( + address indexed account, + uint256 indexed claimable, + uint256 setId + ); + + event LogArbTokensDelegated( + address indexed account, + address indexed delegatee, + uint256 indexed delegatedAmount + ); + + event LogArbTokensDelegatedBySig( + address indexed account, + address indexed delegatee, + uint256 indexed delegatedAmount, + uint256 nonce + ); +} diff --git a/contracts/arbitrum/connectors/arb-claim/interface.sol b/contracts/arbitrum/connectors/arb-claim/interface.sol new file mode 100644 index 00000000..a856d242 --- /dev/null +++ b/contracts/arbitrum/connectors/arb-claim/interface.sol @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +interface IArbitrumTokenDistributor { + function claim() external; + + function claimAndDelegate( + address delegatee, + uint256 expiry, + uint8 v, + bytes32 r, + bytes32 s + ) external; + + function claimableTokens(address) external view returns (uint256); +} + +interface IArbTokenContract { + function delegate(address delegatee) external; + + function delegateBySig( + address delegatee, + uint256 nonce, + uint256 expiry, + uint8 v, + bytes32 r, + bytes32 s + ) external; +} + +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); +} diff --git a/contracts/arbitrum/connectors/arb-claim/main.sol b/contracts/arbitrum/connectors/arb-claim/main.sol new file mode 100644 index 00000000..cda225ff --- /dev/null +++ b/contracts/arbitrum/connectors/arb-claim/main.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +import "./variables.sol"; +import { Events } from "./events.sol"; +import { IArbitrumTokenDistributor } from "./interface.sol"; + +abstract contract ArbitrumAirdrop is Events, Variables { + function claimArbAirdrop(uint256 setId) + public + returns (string memory eventName_, bytes memory eventParam_) + { + uint256 claimable = claimableArbTokens(address(this)); + require(claimable > 0, "0-tokens-claimable"); + ARBITRUM_TOKEN_DISTRIBUTOR.claim(); + setUint(setId, claimable); + + eventName_ = "LogArbAirdropClaimed(address,uint256,uint256)"; + eventParam_ = abi.encode(address(this), claimable, setId); + } + + function delegateArbTokens(address delegatee) + public + returns (string memory eventName_, bytes memory eventParam_) + { + uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf(address(this)); + require(balance > 0, "no-balance-to-delegate"); + + ARB_TOKEN_CONTRACT.delegate(delegatee); + + eventName_ = "LogArbTokensDelegated(address,address,uint256)"; + eventParam_ = abi.encode(address(this), delegatee, balance); + } + + function delegateArbTokensBySig( + address delegatee, + uint256 nonce, + SignedPermits calldata permits + ) + public + returns (string memory eventName_, bytes memory eventParam_) + { + uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf(address(this)); + require(balance > 0, "no-balance-to-delegate"); + + ARB_TOKEN_CONTRACT.delegateBySig(delegatee, nonce, permits.expiry, permits.v, permits.r, permits.s); + + eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256,uint256)"; + eventParam_ = abi.encode(address(this), delegatee, balance, nonce); + } + + function claimableArbTokens(address user) public view returns (uint256) { + return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user); + } +} + +contract ConnectV2ArbitrumAirdrop is ArbitrumAirdrop { + string public name = "ArbitrumAirdrop-v1"; +} diff --git a/contracts/arbitrum/connectors/arb-claim/variables.sol b/contracts/arbitrum/connectors/arb-claim/variables.sol new file mode 100644 index 00000000..b03a6f75 --- /dev/null +++ b/contracts/arbitrum/connectors/arb-claim/variables.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "./interface.sol"; +import { Basic } from "../../common/basic.sol"; + +contract Variables is Basic { + IArbitrumTokenDistributor public constant ARBITRUM_TOKEN_DISTRIBUTOR = + IArbitrumTokenDistributor(0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9); + + IArbTokenContract public constant ARB_TOKEN_CONTRACT = + IArbTokenContract(0x912CE59144191C1204E64559FE8253a0e49E6548); + + struct SignedPermits { + uint8 v; + bytes32 r; + bytes32 s; + uint256 expiry; + } +} From abfab948cda775525e0ab8fdb2a247ab993901da Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 19 Apr 2023 20:10:27 +0400 Subject: [PATCH 4/9] Added claimAndDelegateArbAirdrop + prettier --- .../arbitrum/connectors/arb-claim/events.sol | 7 ++ .../connectors/arb-claim/interface.sol | 38 +++++++---- .../arbitrum/connectors/arb-claim/main.sol | 66 +++++++++++++------ 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/contracts/arbitrum/connectors/arb-claim/events.sol b/contracts/arbitrum/connectors/arb-claim/events.sol index 788fad86..8ecdd7b0 100644 --- a/contracts/arbitrum/connectors/arb-claim/events.sol +++ b/contracts/arbitrum/connectors/arb-claim/events.sol @@ -20,4 +20,11 @@ contract Events { uint256 indexed delegatedAmount, uint256 nonce ); + + event LogArbAirdropClaimedAndDelegated( + address indexed account, + address indexed delegatee, + uint256 indexed claimable, + uint256 setId + ); } diff --git a/contracts/arbitrum/connectors/arb-claim/interface.sol b/contracts/arbitrum/connectors/arb-claim/interface.sol index a856d242..3831a6cf 100644 --- a/contracts/arbitrum/connectors/arb-claim/interface.sol +++ b/contracts/arbitrum/connectors/arb-claim/interface.sol @@ -19,21 +19,31 @@ interface IArbTokenContract { function delegate(address delegatee) external; function delegateBySig( - address delegatee, - uint256 nonce, - uint256 expiry, - uint8 v, - bytes32 r, - bytes32 s - ) external; + address delegatee, + uint256 nonce, + uint256 expiry, + uint8 v, + bytes32 r, + bytes32 s + ) external; } 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 approve(address, uint256) external; + + function transfer(address, uint256) external; + + function transferFrom( + address, + address, + uint256 + ) external; + + function deposit() external payable; + + function withdraw(uint256) external; + + function balanceOf(address) external view returns (uint256); + + function decimals() external view returns (uint256); } diff --git a/contracts/arbitrum/connectors/arb-claim/main.sol b/contracts/arbitrum/connectors/arb-claim/main.sol index cda225ff..9ec1b5e4 100644 --- a/contracts/arbitrum/connectors/arb-claim/main.sol +++ b/contracts/arbitrum/connectors/arb-claim/main.sol @@ -7,6 +7,10 @@ import { Events } from "./events.sol"; import { IArbitrumTokenDistributor } from "./interface.sol"; abstract contract ArbitrumAirdrop is Events, Variables { + function claimableArbTokens(address user) public view returns (uint256) { + return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user); + } + function claimArbAirdrop(uint256 setId) public returns (string memory eventName_, bytes memory eventParam_) @@ -20,12 +24,14 @@ abstract contract ArbitrumAirdrop is Events, Variables { eventParam_ = abi.encode(address(this), claimable, setId); } - function delegateArbTokens(address delegatee) + function delegateArbTokens(address delegatee) public returns (string memory eventName_, bytes memory eventParam_) { - uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf(address(this)); - require(balance > 0, "no-balance-to-delegate"); + uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf( + address(this) + ); + require(balance > 0, "no-balance-to-delegate"); ARB_TOKEN_CONTRACT.delegate(delegatee); @@ -33,25 +39,47 @@ abstract contract ArbitrumAirdrop is Events, Variables { eventParam_ = abi.encode(address(this), delegatee, balance); } - function delegateArbTokensBySig( - address delegatee, - uint256 nonce, - SignedPermits calldata permits - ) - public - returns (string memory eventName_, bytes memory eventParam_) - { - uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf(address(this)); - require(balance > 0, "no-balance-to-delegate"); + function delegateArbTokensBySig( + address delegatee, + uint256 nonce, + SignedPermits calldata permits + ) public returns (string memory eventName_, bytes memory eventParam_) { + uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf( + address(this) + ); + require(balance > 0, "no-balance-to-delegate"); - ARB_TOKEN_CONTRACT.delegateBySig(delegatee, nonce, permits.expiry, permits.v, permits.r, permits.s); + ARB_TOKEN_CONTRACT.delegateBySig( + delegatee, + nonce, + permits.expiry, + permits.v, + permits.r, + permits.s + ); - eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256,uint256)"; - eventParam_ = abi.encode(address(this), delegatee, balance, nonce); - } + eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256,uint256)"; + eventParam_ = abi.encode(address(this), delegatee, balance, nonce); + } - function claimableArbTokens(address user) public view returns (uint256) { - return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user); + function claimAndDelegateArbAirdrop( + address delegatee, + SignedPermits memory permits, + uint256 setId + ) public returns (string memory eventName_, bytes memory eventParam_) { + uint256 claimable = claimableArbTokens(address(this)); + require(claimable > 0, "0-tokens-claimable"); + ARBITRUM_TOKEN_DISTRIBUTOR.claimAndDelegate( + delegatee, + permits.expiry, + permits.v, + permits.r, + permits.s + ); + setUint(setId, claimable); + + eventName_ = "LogArbAirdropClaimedAndDelegated(address,address,uint256,uint256)"; + eventParam_ = abi.encode(address(this), delegatee, claimable, setId); } } From cd2e0b42d87a574bb874250613b9228e9c74fdd0 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 19 Apr 2023 21:13:05 +0400 Subject: [PATCH 5/9] Add helpers contract + optimize --- .../arbitrum/connectors/arb-claim/events.sol | 11 +--- .../arbitrum/connectors/arb-claim/helpers.sol | 11 ++++ .../arbitrum/connectors/arb-claim/main.sol | 53 ++++--------------- .../connectors/arb-claim/variables.sol | 3 +- 4 files changed, 23 insertions(+), 55 deletions(-) create mode 100644 contracts/arbitrum/connectors/arb-claim/helpers.sol diff --git a/contracts/arbitrum/connectors/arb-claim/events.sol b/contracts/arbitrum/connectors/arb-claim/events.sol index 8ecdd7b0..ba1a1835 100644 --- a/contracts/arbitrum/connectors/arb-claim/events.sol +++ b/contracts/arbitrum/connectors/arb-claim/events.sol @@ -10,21 +10,12 @@ contract Events { event LogArbTokensDelegated( address indexed account, - address indexed delegatee, - uint256 indexed delegatedAmount + address indexed delegatee ); event LogArbTokensDelegatedBySig( address indexed account, address indexed delegatee, - uint256 indexed delegatedAmount, uint256 nonce ); - - event LogArbAirdropClaimedAndDelegated( - address indexed account, - address indexed delegatee, - uint256 indexed claimable, - uint256 setId - ); } diff --git a/contracts/arbitrum/connectors/arb-claim/helpers.sol b/contracts/arbitrum/connectors/arb-claim/helpers.sol new file mode 100644 index 00000000..0e91e30e --- /dev/null +++ b/contracts/arbitrum/connectors/arb-claim/helpers.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; + +import "./variables.sol"; +import { Basic } from "../../common/basic.sol"; + +contract Helpers is Variables, Basic { + function claimableArbTokens(address user) internal view returns (uint256) { + return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user); + } +} \ No newline at end of file diff --git a/contracts/arbitrum/connectors/arb-claim/main.sol b/contracts/arbitrum/connectors/arb-claim/main.sol index 9ec1b5e4..e1068821 100644 --- a/contracts/arbitrum/connectors/arb-claim/main.sol +++ b/contracts/arbitrum/connectors/arb-claim/main.sol @@ -2,16 +2,13 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; -import "./variables.sol"; +import "./helpers.sol"; import { Events } from "./events.sol"; import { IArbitrumTokenDistributor } from "./interface.sol"; -abstract contract ArbitrumAirdrop is Events, Variables { - function claimableArbTokens(address user) public view returns (uint256) { - return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user); - } +abstract contract ArbitrumAirdrop is Events, Helpers { - function claimArbAirdrop(uint256 setId) + function claimAirdrop(uint256 setId) public returns (string memory eventName_, bytes memory eventParam_) { @@ -24,31 +21,21 @@ abstract contract ArbitrumAirdrop is Events, Variables { eventParam_ = abi.encode(address(this), claimable, setId); } - function delegateArbTokens(address delegatee) + function delegate(address delegatee) public returns (string memory eventName_, bytes memory eventParam_) { - uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf( - address(this) - ); - require(balance > 0, "no-balance-to-delegate"); - ARB_TOKEN_CONTRACT.delegate(delegatee); - eventName_ = "LogArbTokensDelegated(address,address,uint256)"; - eventParam_ = abi.encode(address(this), delegatee, balance); + eventName_ = "LogArbTokensDelegated(address,address)"; + eventParam_ = abi.encode(address(this), delegatee); } - function delegateArbTokensBySig( + function delegateBySig( address delegatee, uint256 nonce, SignedPermits calldata permits ) public returns (string memory eventName_, bytes memory eventParam_) { - uint256 balance = TokenInterface(address(ARB_TOKEN_CONTRACT)).balanceOf( - address(this) - ); - require(balance > 0, "no-balance-to-delegate"); - ARB_TOKEN_CONTRACT.delegateBySig( delegatee, nonce, @@ -58,31 +45,11 @@ abstract contract ArbitrumAirdrop is Events, Variables { permits.s ); - eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256,uint256)"; - eventParam_ = abi.encode(address(this), delegatee, balance, nonce); - } - - function claimAndDelegateArbAirdrop( - address delegatee, - SignedPermits memory permits, - uint256 setId - ) public returns (string memory eventName_, bytes memory eventParam_) { - uint256 claimable = claimableArbTokens(address(this)); - require(claimable > 0, "0-tokens-claimable"); - ARBITRUM_TOKEN_DISTRIBUTOR.claimAndDelegate( - delegatee, - permits.expiry, - permits.v, - permits.r, - permits.s - ); - setUint(setId, claimable); - - eventName_ = "LogArbAirdropClaimedAndDelegated(address,address,uint256,uint256)"; - eventParam_ = abi.encode(address(this), delegatee, claimable, setId); + eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256)"; + eventParam_ = abi.encode(address(this), delegatee, nonce); } } contract ConnectV2ArbitrumAirdrop is ArbitrumAirdrop { - string public name = "ArbitrumAirdrop-v1"; + string public constant name = "ArbitrumAirdrop-v1"; } diff --git a/contracts/arbitrum/connectors/arb-claim/variables.sol b/contracts/arbitrum/connectors/arb-claim/variables.sol index b03a6f75..4f08a35c 100644 --- a/contracts/arbitrum/connectors/arb-claim/variables.sol +++ b/contracts/arbitrum/connectors/arb-claim/variables.sol @@ -2,9 +2,8 @@ pragma solidity ^0.7.0; import "./interface.sol"; -import { Basic } from "../../common/basic.sol"; -contract Variables is Basic { +contract Variables { IArbitrumTokenDistributor public constant ARBITRUM_TOKEN_DISTRIBUTOR = IArbitrumTokenDistributor(0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9); From 35d0a03a6195b26ec54fc5e29933b869c183d011 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Thu, 20 Apr 2023 01:18:08 +0400 Subject: [PATCH 6/9] Added testcases --- test/arbitrum/arb-claim/test.ts | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/arbitrum/arb-claim/test.ts diff --git a/test/arbitrum/arb-claim/test.ts b/test/arbitrum/arb-claim/test.ts new file mode 100644 index 00000000..eaab4143 --- /dev/null +++ b/test/arbitrum/arb-claim/test.ts @@ -0,0 +1,56 @@ +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { ConnectV2ArbitrumAirdrop, ConnectV2ArbitrumAirdrop__factory } from "../../../typechain"; +import hre, { ethers } from "hardhat"; + +describe("Arbitrum Airdrop Claim Test", () => { + let signer: SignerWithAddress; + let userSigner: SignerWithAddress; + let signer_user: any; + const user = "0x30c3D961a21c2352A6FfAfFd4e8cB8730Bf82757"; + + describe("Arbitrum Airdrop Functions", () => { + let contract: ConnectV2ArbitrumAirdrop; + + //@ts-ignore + console.log('hre.config.networks.hardhat.forking.url: ', hre.config.networks.hardhat.forking.url) + + before(async () => { + await hre.network.provider.request({ + method: "hardhat_reset", + params: [ + { + forking: { + //@ts-ignore + jsonRpcUrl: hre.config.networks.hardhat.forking.url, + blockNumber: 70606643 + } + } + ] + }); + + [signer] = await ethers.getSigners(); + console.log("Signer: ", signer.address); + + userSigner = await ethers.getSigner(user); + + const deployer = new ConnectV2ArbitrumAirdrop__factory(signer); + contract = await deployer.deploy(); + await contract.deployed(); + console.log("Contract deployed at: ", contract.address); + + await hre.network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [user], + }); + + signer_user = await ethers.getSigner(user); + }); + + describe("Arbitrum Arbitrum", async () => { + it("Claims Arbitrum Airdrop", async () => { + const response = await contract.connect(signer_user).claimAirdrop("4256"); + console.log('response: ', response); + }); + }) + }); +}); \ No newline at end of file From 15082a643e90b82809c85afe30d7c2dbef08b30f Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Thu, 20 Apr 2023 01:27:07 +0400 Subject: [PATCH 7/9] Added NatSpec comments --- contracts/arbitrum/connectors/arb-claim/main.sol | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/contracts/arbitrum/connectors/arb-claim/main.sol b/contracts/arbitrum/connectors/arb-claim/main.sol index e1068821..27f0600f 100644 --- a/contracts/arbitrum/connectors/arb-claim/main.sol +++ b/contracts/arbitrum/connectors/arb-claim/main.sol @@ -8,6 +8,10 @@ import { IArbitrumTokenDistributor } from "./interface.sol"; abstract contract ArbitrumAirdrop is Events, Helpers { + /** + * @dev DSA Arbitrum airdrop claim function. + * @param setId ID to set the claimable amount in the DSA + */ function claimAirdrop(uint256 setId) public returns (string memory eventName_, bytes memory eventParam_) @@ -21,6 +25,10 @@ abstract contract ArbitrumAirdrop is Events, Helpers { eventParam_ = abi.encode(address(this), claimable, setId); } + /** + * @dev Delegates votes from signer to `delegatee`. + * @param delegatee The address to delegate the ARB tokens to. + */ function delegate(address delegatee) public returns (string memory eventName_, bytes memory eventParam_) @@ -31,6 +39,12 @@ abstract contract ArbitrumAirdrop is Events, Helpers { eventParam_ = abi.encode(address(this), delegatee); } + /** + * @dev Delegates votes from signer to `delegatee`. + * @param delegatee The address to delegate the ARB tokens to. + * @param nonce The nonce number. + * @param permits The struct containing signed permit data like v,r,s,expiry. + */ function delegateBySig( address delegatee, uint256 nonce, From 374f450605367e635ac1dd61e4cd7b8b7b20208d Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Thu, 20 Apr 2023 15:56:45 +0400 Subject: [PATCH 8/9] Update test --- test/arbitrum/arb-claim/test.ts | 64 ++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/test/arbitrum/arb-claim/test.ts b/test/arbitrum/arb-claim/test.ts index eaab4143..734fc065 100644 --- a/test/arbitrum/arb-claim/test.ts +++ b/test/arbitrum/arb-claim/test.ts @@ -1,19 +1,28 @@ import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { ethers } from "hardhat"; import { ConnectV2ArbitrumAirdrop, ConnectV2ArbitrumAirdrop__factory } from "../../../typechain"; -import hre, { ethers } from "hardhat"; +import hre from "hardhat"; +import { deployAndEnableConnector } from "../../../scripts/tests/deployAndEnableConnector"; +import { buildDSAv2 } from "../../../scripts/tests/buildDSAv2"; +import { encodeSpells } from "../../../scripts/tests/encodeSpells"; +import { getMasterSigner } from "../../../scripts/tests/getMasterSigner"; +import { addresses } from "../../../scripts/tests/arbitrum/addresses"; +import { abis } from "../../../scripts/constant/abis"; describe("Arbitrum Airdrop Claim Test", () => { let signer: SignerWithAddress; - let userSigner: SignerWithAddress; let signer_user: any; const user = "0x30c3D961a21c2352A6FfAfFd4e8cB8730Bf82757"; + const connectorName = "arbitrum-airdrop"; + let dsaWallet0: any; + + before(async () => { + [signer] = await ethers.getSigners(); + }); describe("Arbitrum Airdrop Functions", () => { let contract: ConnectV2ArbitrumAirdrop; - //@ts-ignore - console.log('hre.config.networks.hardhat.forking.url: ', hre.config.networks.hardhat.forking.url) - before(async () => { await hre.network.provider.request({ method: "hardhat_reset", @@ -22,35 +31,50 @@ describe("Arbitrum Airdrop Claim Test", () => { forking: { //@ts-ignore jsonRpcUrl: hre.config.networks.hardhat.forking.url, - blockNumber: 70606643 - } - } - ] + blockNumber: 70606643, + }, + }, + ], }); - [signer] = await ethers.getSigners(); - console.log("Signer: ", signer.address); - - userSigner = await ethers.getSigner(user); - const deployer = new ConnectV2ArbitrumAirdrop__factory(signer); contract = await deployer.deploy(); await contract.deployed(); console.log("Contract deployed at: ", contract.address); + await deployAndEnableConnector({ + connectorName, + contractArtifact: ConnectV2ArbitrumAirdrop__factory, + signer: signer, + connectors: await ethers.getContractAt(abis.core.connectorsV2, addresses.core.connectorsV2), + }); + await hre.network.provider.request({ method: 'hardhat_impersonateAccount', params: [user], }); signer_user = await ethers.getSigner(user); + dsaWallet0 = await buildDSAv2(user); }); - describe("Arbitrum Arbitrum", async () => { - it("Claims Arbitrum Airdrop", async () => { - const response = await contract.connect(signer_user).claimAirdrop("4256"); - console.log('response: ', response); - }); - }) + it("Claims Arbitrum Airdrop and checks claimable tokens", async () => { + const claimableBefore = await contract.claimableArbTokens(user); + console.log("Claimable tokens before: ", claimableBefore.toString()); + + const spells = [ + { + connector: connectorName, + method: "claimAirdrop", + args: ["0"], + }, + ]; + + const tx = await dsaWallet0.connect(signer_user).cast(...encodeSpells(spells), user); + await tx.wait(); + + const claimableAfter = await contract.claimableArbTokens(user); + console.log("Claimable tokens after: ", claimableAfter.toString()); + }); }); }); \ No newline at end of file From ad3ffd0de2259ad3c1f1498562d6904b8b6a34bf Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Thu, 20 Apr 2023 16:55:57 +0400 Subject: [PATCH 9/9] Remove delegateBySig --- .../arbitrum/connectors/arb-claim/events.sol | 6 ----- .../arbitrum/connectors/arb-claim/helpers.sol | 2 +- .../arbitrum/connectors/arb-claim/main.sol | 27 ++----------------- .../connectors/arb-claim/variables.sol | 7 ----- 4 files changed, 3 insertions(+), 39 deletions(-) diff --git a/contracts/arbitrum/connectors/arb-claim/events.sol b/contracts/arbitrum/connectors/arb-claim/events.sol index ba1a1835..6d220d43 100644 --- a/contracts/arbitrum/connectors/arb-claim/events.sol +++ b/contracts/arbitrum/connectors/arb-claim/events.sol @@ -12,10 +12,4 @@ contract Events { address indexed account, address indexed delegatee ); - - event LogArbTokensDelegatedBySig( - address indexed account, - address indexed delegatee, - uint256 nonce - ); } diff --git a/contracts/arbitrum/connectors/arb-claim/helpers.sol b/contracts/arbitrum/connectors/arb-claim/helpers.sol index 0e91e30e..4eb872de 100644 --- a/contracts/arbitrum/connectors/arb-claim/helpers.sol +++ b/contracts/arbitrum/connectors/arb-claim/helpers.sol @@ -5,7 +5,7 @@ import "./variables.sol"; import { Basic } from "../../common/basic.sol"; contract Helpers is Variables, Basic { - function claimableArbTokens(address user) internal view returns (uint256) { + function claimableArbTokens(address user) public view returns (uint256) { return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user); } } \ No newline at end of file diff --git a/contracts/arbitrum/connectors/arb-claim/main.sol b/contracts/arbitrum/connectors/arb-claim/main.sol index 27f0600f..f908b8b1 100644 --- a/contracts/arbitrum/connectors/arb-claim/main.sol +++ b/contracts/arbitrum/connectors/arb-claim/main.sol @@ -17,7 +17,8 @@ abstract contract ArbitrumAirdrop is Events, Helpers { returns (string memory eventName_, bytes memory eventParam_) { uint256 claimable = claimableArbTokens(address(this)); - require(claimable > 0, "0-tokens-claimable"); + + // If claimable <= 0, ARB TokenDistributor will revert on claim. ARBITRUM_TOKEN_DISTRIBUTOR.claim(); setUint(setId, claimable); @@ -38,30 +39,6 @@ abstract contract ArbitrumAirdrop is Events, Helpers { eventName_ = "LogArbTokensDelegated(address,address)"; eventParam_ = abi.encode(address(this), delegatee); } - - /** - * @dev Delegates votes from signer to `delegatee`. - * @param delegatee The address to delegate the ARB tokens to. - * @param nonce The nonce number. - * @param permits The struct containing signed permit data like v,r,s,expiry. - */ - function delegateBySig( - address delegatee, - uint256 nonce, - SignedPermits calldata permits - ) public returns (string memory eventName_, bytes memory eventParam_) { - ARB_TOKEN_CONTRACT.delegateBySig( - delegatee, - nonce, - permits.expiry, - permits.v, - permits.r, - permits.s - ); - - eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256)"; - eventParam_ = abi.encode(address(this), delegatee, nonce); - } } contract ConnectV2ArbitrumAirdrop is ArbitrumAirdrop { diff --git a/contracts/arbitrum/connectors/arb-claim/variables.sol b/contracts/arbitrum/connectors/arb-claim/variables.sol index 4f08a35c..fb3e29d5 100644 --- a/contracts/arbitrum/connectors/arb-claim/variables.sol +++ b/contracts/arbitrum/connectors/arb-claim/variables.sol @@ -9,11 +9,4 @@ contract Variables { IArbTokenContract public constant ARB_TOKEN_CONTRACT = IArbTokenContract(0x912CE59144191C1204E64559FE8253a0e49E6548); - - struct SignedPermits { - uint8 v; - bytes32 r; - bytes32 s; - uint256 expiry; - } }