Skip to content

Commit 14f4e89

Browse files
authored
Airdrop Issuance Hook (#75)
* add AirdropIssuanceHook * add AirdropIssuanceHook tests * add invokePreRedeemHook test * improve comments * add comment about positive rebase requirement
1 parent 65e4d04 commit 14f4e89

File tree

10 files changed

+1187
-3
lines changed

10 files changed

+1187
-3
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
17+
pragma solidity 0.6.10;
18+
19+
import { IAirdropModule } from "../interfaces/IAirdropModule.sol";
20+
import { IManagerIssuanceHook } from "../interfaces/IManagerIssuanceHook.sol";
21+
import { ISetToken } from "../interfaces/ISetToken.sol";
22+
23+
/**
24+
* @title AirdropIssuanceHook
25+
* @author Index Coop
26+
*
27+
* Issuance hooks that absorbs all airdropped tokens. Useful for ensuring that rebasing tokens are fully accounted for before issuance. Only works
28+
* with tokens that strictly positively rebase such as aTokens.
29+
*/
30+
contract AirdropIssuanceHook is IManagerIssuanceHook {
31+
32+
/* ============ State Variables ============ */
33+
34+
// Address of Set Protocol AirdropModule
35+
IAirdropModule public airdropModule;
36+
37+
/* ============== Constructor ================ */
38+
39+
/**
40+
* Sets state variables.
41+
*
42+
* @param _airdropModule address of AirdropModule
43+
*/
44+
constructor(IAirdropModule _airdropModule) public {
45+
airdropModule = _airdropModule;
46+
}
47+
48+
/* =========== External Functions =========== */
49+
50+
/**
51+
* Absorbs all airdropped tokens. Called by some issuance modules before issuance.
52+
*
53+
* @param _setToken address of SetToken to absorb airdrops for
54+
*/
55+
function invokePreIssueHook(ISetToken _setToken, uint256 /* _issueQuantity */, address /* _sender */, address /* _to */) external override {
56+
_sync(_setToken);
57+
}
58+
59+
/**
60+
* Absorbs all airdropped tokens. Called by some issuance modules before redemption.
61+
*
62+
* @param _setToken address of SetToken to absorb airdrops for
63+
*/
64+
function invokePreRedeemHook(ISetToken _setToken, uint256 /* _issueQuantity */, address /* _sender */, address /* _to */) external override {
65+
_sync(_setToken);
66+
}
67+
68+
/* =========== Internal Functions ========== */
69+
70+
/**
71+
* Absorbs all airdropped tokens. AirdropModule must be added to an initialized for the SetToken. Must have anyoneAbsorb set to true on
72+
* the AirdropModule.
73+
*
74+
* @param _setToken address of SetToken to absorb airdrops for
75+
*/
76+
function _sync(ISetToken _setToken) internal {
77+
address[] memory airdrops = airdropModule.getAirdrops(_setToken);
78+
airdropModule.batchAbsorb(_setToken, airdrops);
79+
}
80+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
17+
pragma solidity 0.6.10;
18+
19+
import { ISetToken } from "../interfaces/ISetToken.sol";
20+
21+
interface IAirdropModule {
22+
function batchAbsorb(ISetToken _setToken, address[] memory _tokens) external;
23+
function getAirdrops(ISetToken _setToken) external view returns (address[] memory);
24+
}

0 commit comments

Comments
 (0)