Add helpers contract + optimize

This commit is contained in:
Shriya Tyagi 2023-04-19 21:13:05 +04:00 committed by q1q0
parent a51382d1da
commit a85da7c8c4
4 changed files with 23 additions and 55 deletions

View File

@ -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
);
}

View File

@ -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);
}
}

View File

@ -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";
}

View File

@ -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);