mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add helpers contract + optimize
This commit is contained in:
parent
a51382d1da
commit
a85da7c8c4
|
@ -10,21 +10,12 @@ contract Events {
|
||||||
|
|
||||||
event LogArbTokensDelegated(
|
event LogArbTokensDelegated(
|
||||||
address indexed account,
|
address indexed account,
|
||||||
address indexed delegatee,
|
address indexed delegatee
|
||||||
uint256 indexed delegatedAmount
|
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogArbTokensDelegatedBySig(
|
event LogArbTokensDelegatedBySig(
|
||||||
address indexed account,
|
address indexed account,
|
||||||
address indexed delegatee,
|
address indexed delegatee,
|
||||||
uint256 indexed delegatedAmount,
|
|
||||||
uint256 nonce
|
uint256 nonce
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogArbAirdropClaimedAndDelegated(
|
|
||||||
address indexed account,
|
|
||||||
address indexed delegatee,
|
|
||||||
uint256 indexed claimable,
|
|
||||||
uint256 setId
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
11
contracts/arbitrum/connectors/arb-claim/helpers.sol
Normal file
11
contracts/arbitrum/connectors/arb-claim/helpers.sol
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,16 +2,13 @@
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
import "./variables.sol";
|
import "./helpers.sol";
|
||||||
import { Events } from "./events.sol";
|
import { Events } from "./events.sol";
|
||||||
import { IArbitrumTokenDistributor } from "./interface.sol";
|
import { IArbitrumTokenDistributor } from "./interface.sol";
|
||||||
|
|
||||||
abstract contract ArbitrumAirdrop is Events, Variables {
|
abstract contract ArbitrumAirdrop is Events, Helpers {
|
||||||
function claimableArbTokens(address user) public view returns (uint256) {
|
|
||||||
return ARBITRUM_TOKEN_DISTRIBUTOR.claimableTokens(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
function claimArbAirdrop(uint256 setId)
|
function claimAirdrop(uint256 setId)
|
||||||
public
|
public
|
||||||
returns (string memory eventName_, bytes memory eventParam_)
|
returns (string memory eventName_, bytes memory eventParam_)
|
||||||
{
|
{
|
||||||
|
@ -24,31 +21,21 @@ abstract contract ArbitrumAirdrop is Events, Variables {
|
||||||
eventParam_ = abi.encode(address(this), claimable, setId);
|
eventParam_ = abi.encode(address(this), claimable, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delegateArbTokens(address delegatee)
|
function delegate(address delegatee)
|
||||||
public
|
public
|
||||||
returns (string memory eventName_, bytes memory eventParam_)
|
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);
|
ARB_TOKEN_CONTRACT.delegate(delegatee);
|
||||||
|
|
||||||
eventName_ = "LogArbTokensDelegated(address,address,uint256)";
|
eventName_ = "LogArbTokensDelegated(address,address)";
|
||||||
eventParam_ = abi.encode(address(this), delegatee, balance);
|
eventParam_ = abi.encode(address(this), delegatee);
|
||||||
}
|
}
|
||||||
|
|
||||||
function delegateArbTokensBySig(
|
function delegateBySig(
|
||||||
address delegatee,
|
address delegatee,
|
||||||
uint256 nonce,
|
uint256 nonce,
|
||||||
SignedPermits calldata permits
|
SignedPermits calldata permits
|
||||||
) public returns (string memory eventName_, bytes memory eventParam_) {
|
) 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(
|
ARB_TOKEN_CONTRACT.delegateBySig(
|
||||||
delegatee,
|
delegatee,
|
||||||
nonce,
|
nonce,
|
||||||
|
@ -58,31 +45,11 @@ abstract contract ArbitrumAirdrop is Events, Variables {
|
||||||
permits.s
|
permits.s
|
||||||
);
|
);
|
||||||
|
|
||||||
eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256,uint256)";
|
eventName_ = "LogArbTokensDelegatedBySig(address,address,uint256)";
|
||||||
eventParam_ = abi.encode(address(this), delegatee, balance, nonce);
|
eventParam_ = abi.encode(address(this), delegatee, 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2ArbitrumAirdrop is ArbitrumAirdrop {
|
contract ConnectV2ArbitrumAirdrop is ArbitrumAirdrop {
|
||||||
string public name = "ArbitrumAirdrop-v1";
|
string public constant name = "ArbitrumAirdrop-v1";
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
|
||||||
import "./interface.sol";
|
import "./interface.sol";
|
||||||
import { Basic } from "../../common/basic.sol";
|
|
||||||
|
|
||||||
contract Variables is Basic {
|
contract Variables {
|
||||||
IArbitrumTokenDistributor public constant ARBITRUM_TOKEN_DISTRIBUTOR =
|
IArbitrumTokenDistributor public constant ARBITRUM_TOKEN_DISTRIBUTOR =
|
||||||
IArbitrumTokenDistributor(0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9);
|
IArbitrumTokenDistributor(0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user