IDAv1 Library Example
This is an example implementation of a contract using the Instant Distribution Agreement library.
1
import {
2
ISuperfluid,
3
ISuperfluidToken
4
} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol";
5
​
6
import {
7
IInstantDistributionAgreementV1
8
} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/agreements/IInstantDistributionAgreementV1.sol";
9
​
10
import {
11
IDAv1Library
12
} from "@superfluid-finance/ethereum-contracts/contracts/apps/IDAv1Library.sol";
13
​
14
/// @title Simple Recurring Airdrop contract example.
15
/// @notice This is NOT suitable for production, this is for demonstration ONLY.
16
contract RecurringAirdropper {
17
​
18
using IDAv1Library for IDAv1Library.InitData;
19
IDAv1Library.InitData internal _idav1Lib;
20
21
uint32 internal constant _INDEX_ID = 0;
22
address internal immutable _ADMIN;
23
24
ISuperfluidToken public token;
25
uint256 public lastAirdrop;
26
uint256 public constant AIRDROP_INTERVAL = 30 days;
27
uint256 public constant AIRDROP_AMOUNT = 1e23; // 100_000 * 1e18
28
​
29
constructor(
30
address admin,
31
ISuperfluid _host,
32
IInstantDistributionAgreement _ida,
33
ISuperfluidToken _token
34
) {
35
_ADMIN = admin;
36
token = _token;
37
_idav1Lib = IDAv1Library.InitData(_host, _ida);
38
_idav1Lib.createIndex(_token, _INDEX_ID);
39
}
40
​
41
/// @notice Airdrops a constant amount if the last
42
/// airdrop was at least 30 days ago
43
function airdrop() external {
44
require(_canAirdrop(), "can not air drop yet");
45
_idav1Lib.distribute(token, _INDEX_ID, AIRDROP_AMOUNT);
46
}
47
48
function updateUnits(address subscriber, uint128 units) external {
49
require(msg.sender == _ADMIN, "unathorized");
50
_idav1Lib.updateSubscriptionUnits(
51
token,
52
_INDEX_ID,
53
subscriber,
54
units
55
);
56
}
57
​
58
function _canAirdrop() internal view returns (bool) {
59
return lastAirdrop + airdropInterval <= block.timestamp;
60
}
61
}
Copied!
Copy link