mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
Add ARB token claim connector
This commit is contained in:
parent
08f41ca88f
commit
c3c5ce2560
23
contracts/arbitrum/connectors/arb-claim/events.sol
Normal file
23
contracts/arbitrum/connectors/arb-claim/events.sol
Normal file
|
@ -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
|
||||
);
|
||||
}
|
39
contracts/arbitrum/connectors/arb-claim/interface.sol
Normal file
39
contracts/arbitrum/connectors/arb-claim/interface.sol
Normal file
|
@ -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);
|
||||
}
|
60
contracts/arbitrum/connectors/arb-claim/main.sol
Normal file
60
contracts/arbitrum/connectors/arb-claim/main.sol
Normal file
|
@ -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";
|
||||
}
|
20
contracts/arbitrum/connectors/arb-claim/variables.sol
Normal file
20
contracts/arbitrum/connectors/arb-claim/variables.sol
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user