Skip to content

Commit ae3ae99

Browse files
authored
Airdrop Extension (#79)
* add AirdropIssuanceHook contracts and tests
1 parent 325c74d commit ae3ae99

File tree

6 files changed

+559
-0
lines changed

6 files changed

+559
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
Copyright 2021 Index Cooperative.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache License, Version 2.0
17+
*/
18+
19+
pragma solidity 0.6.10;
20+
pragma experimental "ABIEncoderV2";
21+
22+
import { BaseExtension } from "../lib/BaseExtension.sol";
23+
import { IAirdropModule } from "../interfaces/IAirdropModule.sol";
24+
import { IBaseManager } from "../interfaces/IBaseManager.sol";
25+
import { ISetToken } from "../interfaces/ISetToken.sol";
26+
27+
/**
28+
* @title AirdropExtension
29+
* @author Index Coop
30+
*
31+
* Manager extension for interacting with AirdropModule
32+
*/
33+
contract AirdropExtension is BaseExtension {
34+
35+
/* ========== State Variables ========= */
36+
37+
// Address of AirdropModule
38+
IAirdropModule public immutable airdropModule;
39+
40+
// Address of Set Token
41+
ISetToken public immutable setToken;
42+
43+
/* ============ Constructor ============ */
44+
45+
/**
46+
* Sets state variables
47+
*
48+
* @param _manager Manager contract
49+
* @param _airdropModule Set Protocol AirdropModule
50+
*/
51+
constructor(IBaseManager _manager, IAirdropModule _airdropModule) public BaseExtension(_manager) {
52+
airdropModule = _airdropModule;
53+
setToken = manager.setToken();
54+
}
55+
56+
/* ========== External Functions ========== */
57+
58+
/**
59+
* OPERATOR ONLY: initializes the AirdropModule. The recipient is always set to the manager and the fee to 0.
60+
*
61+
* @param _airdropSettings Settings to initially the AirdropModule with
62+
*/
63+
function initializeAirdropModule(IAirdropModule.AirdropSettings memory _airdropSettings) external onlyOperator {
64+
_airdropSettings.feeRecipient = address(manager);
65+
_airdropSettings.airdropFee = 0;
66+
67+
invokeManager(
68+
address(airdropModule),
69+
abi.encodeWithSignature("initialize(address,(address[],address,uint256,bool))", setToken, _airdropSettings)
70+
);
71+
}
72+
73+
/**
74+
* OPERATOR ONLY: absorbs airdropped tokens
75+
*
76+
* @param _token Airdropped token to absorb
77+
*/
78+
function absorb(address _token) external onlyAllowedCaller(msg.sender) {
79+
invokeManager(
80+
address(airdropModule),
81+
abi.encodeWithSignature("absorb(address,address)", setToken, _token)
82+
);
83+
}
84+
85+
/**
86+
* OPERATOR ONLY: batch absorbs airdropped tokens
87+
*
88+
* @param _tokens List of airdropped tokens to absorb
89+
*/
90+
function batchAbsorb(address[] memory _tokens) external onlyAllowedCaller(msg.sender) {
91+
invokeManager(
92+
address(airdropModule),
93+
abi.encodeWithSignature("batchAbsorb(address,address[])", setToken, _tokens)
94+
);
95+
}
96+
97+
/**
98+
* OPERATOR ONLY: adds a new airdrop token
99+
*
100+
* @param _token Airdropped token to add
101+
*/
102+
function addAirdrop(address _token) external onlyOperator {
103+
invokeManager(
104+
address(airdropModule),
105+
abi.encodeWithSignature("addAirdrop(address,address)", setToken, _token)
106+
);
107+
}
108+
109+
/**
110+
* OPERATOR ONLY: removes a new airdrop token
111+
*
112+
* @param _token Airdropped token to remove
113+
*/
114+
function removeAirdrop(address _token) external onlyOperator {
115+
invokeManager(
116+
address(airdropModule),
117+
abi.encodeWithSignature("removeAirdrop(address,address)", setToken, _token)
118+
);
119+
}
120+
121+
/**
122+
* OPERATOR ONLY: updates the anyoneAbsorb setting
123+
*
124+
* @param _anyoneAbsorb new anyoneAbsorb setting value
125+
*/
126+
function updateAnyoneAbsorb(bool _anyoneAbsorb) external onlyOperator {
127+
invokeManager(
128+
address(airdropModule),
129+
abi.encodeWithSignature("updateAnyoneAbsorb(address,bool)", setToken, _anyoneAbsorb)
130+
);
131+
}
132+
}

contracts/interfaces/IAirdropModule.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ pragma solidity 0.6.10;
1919
import { ISetToken } from "../interfaces/ISetToken.sol";
2020

2121
interface IAirdropModule {
22+
23+
struct AirdropSettings {
24+
address[] airdrops;
25+
address feeRecipient;
26+
uint256 airdropFee;
27+
bool anyoneAbsorb;
28+
}
29+
2230
function batchAbsorb(ISetToken _setToken, address[] memory _tokens) external;
2331
function getAirdrops(ISetToken _setToken) external view returns (address[] memory);
2432
}

0 commit comments

Comments
 (0)