From c3c5ce25603339d90935d61277a071c9f216d661 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Wed, 19 Apr 2023 20:06:43 +0400 Subject: [PATCH] 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; + } +}