Skip to content

Commit b4fc053

Browse files
authored
DG Migration Adapter (#183)
1 parent 9ec1cec commit b4fc053

File tree

9 files changed

+1113
-1
lines changed

9 files changed

+1113
-1
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright 2021 Set Labs Inc.
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+
/**
23+
* @title DgMigrationWrapAdapter
24+
* @author Set Protocol
25+
*
26+
* Wrap adapter for one time token migration from DG V1 to DG V2.
27+
* Note: DG V2 cannot be unwrapped into DG V1, because the migration cannot be reversed.
28+
*/
29+
contract DgMigrationWrapAdapter {
30+
31+
/* ============ State Variables ============ */
32+
33+
address public immutable dgTokenV1;
34+
address public immutable dgTokenV2;
35+
36+
/* ============ Constructor ============ */
37+
38+
/**
39+
* Set state variables
40+
* @param _dgTokenV1 Address of DG token V1
41+
* @param _dgTokenV2 Address of DG token V2
42+
*/
43+
constructor(address _dgTokenV1, address _dgTokenV2) public {
44+
dgTokenV1 = _dgTokenV1;
45+
dgTokenV2 = _dgTokenV2;
46+
}
47+
48+
/* ============ External Getter Functions ============ */
49+
50+
/**
51+
* Generates the calldata to migrate DG V1 tokens to DG V2 tokens.
52+
* @param _underlyingToken Address of the underlying token
53+
* @param _wrappedToken Address of the wrapped token
54+
* @param _notionalUnderlying Total quantity of underlying tokens to migrate
55+
*
56+
* @return address Target contract address
57+
* @return uint256 Total quantity of underlying units (if underlying is ETH)
58+
* @return bytes Wrap calldata
59+
*/
60+
function getWrapCallData(
61+
address _underlyingToken,
62+
address _wrappedToken,
63+
uint256 _notionalUnderlying
64+
) external view returns (address, uint256, bytes memory) {
65+
require(_underlyingToken == dgTokenV1, "Must be DG V1 token");
66+
require(_wrappedToken == dgTokenV2, "Must be DG V2 token");
67+
68+
// goLight(uint256)
69+
bytes memory callData = abi.encodeWithSignature("goLight(uint256)", _notionalUnderlying);
70+
71+
return (dgTokenV2, 0, callData);
72+
}
73+
74+
/**
75+
* This function will revert, since migration cannot be reversed.
76+
*/
77+
function getUnwrapCallData(
78+
address /* _underlyingToken */,
79+
address /* _wrappedToken */,
80+
uint256 /* _notionalWrapped */
81+
) external pure returns (address, uint256, bytes memory) {
82+
revert("DG migration cannot be reversed");
83+
}
84+
85+
/**
86+
* Returns the address to approve source tokens for wrapping.
87+
*
88+
* @return address Address of the contract to approve tokens to
89+
*/
90+
function getSpenderAddress(
91+
address /* _underlyingToken */,
92+
address /* _wrappedToken */
93+
)
94+
external
95+
view
96+
returns (address)
97+
{
98+
return dgTokenV2;
99+
}
100+
}

0 commit comments

Comments
 (0)