• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SetProtocol / set-protocol-contracts / 5673

pending completion
5673

Pull #468

circleci

Alexander Soong
Remove require string message from Admin
Pull Request #468: Add checks to admin functions for adding factories, modules, and pric…

33 of 322 branches covered (10.25%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

117 of 1003 relevant lines covered (11.67%)

2.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/contracts/core/modules/lib/ExchangeIssuanceLibrary.sol
1
/*
2
    Copyright 2018 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

17
pragma solidity 0.5.7;
18

19
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
20

21
import { AddressArrayUtils } from "../../../lib/AddressArrayUtils.sol";
22
import { ICore } from "../../interfaces/ICore.sol";
23
import { ISetToken } from "../../interfaces/ISetToken.sol";
24
import { IVault } from "../../interfaces/IVault.sol";
25

26

27
/**
28
 * @title ExchangeIssuanceLibrary
29
 * @author Set Protocol
30
 *
31
 * The ExchangeIssuanceLibrary contains functions for validating exchange order data
32
 */
33
library ExchangeIssuanceLibrary {
34
    using SafeMath for uint256;
35
    using AddressArrayUtils for address[];
36

37
    // ============ Structs ============
38

39
    struct ExchangeIssuanceParams {
40
        address setAddress;
41
        uint256 quantity;
42
        uint8[] sendTokenExchangeIds;
43
        address[] sendTokens;
44
        uint256[] sendTokenAmounts;
45
        address[] receiveTokens;
46
        uint256[] receiveTokenAmounts;
47
    }
48

49
    /**
50
     * Validates that the quantity to issue is positive and a multiple of the Set natural unit.
51
     *
52
     * @param _set                The address of the Set
53
     * @param _quantity           The quantity of Sets to issue or redeem
54
     */
55
    function validateQuantity(
56
        address _set,
57
        uint256 _quantity
58
    )
59
        internal
60
        view
61
    {
62
        // Make sure quantity to issue is greater than 0
63
        require(
×
64
            _quantity > 0,
65
            "ExchangeIssuanceLibrary.validateQuantity: Quantity must be positive"
66
        );
67

68
        // Make sure Issue quantity is multiple of the Set natural unit
69
        require(
×
70
            _quantity.mod(ISetToken(_set).naturalUnit()) == 0,
71
            "ExchangeIssuanceLibrary.validateQuantity: Quantity must be multiple of natural unit"
72
        );
73
    }
74

75
    /**
76
     * Validates that the required Components and amounts are valid components and positive.
77
     * Duplicate receive token values are not allowed
78
     *
79
     * @param _receiveTokens           The addresses of components required for issuance
80
     * @param _receiveTokenAmounts     The quantities of components required for issuance
81
     */
82
    function validateReceiveTokens(
83
        address[] memory _receiveTokens,
84
        uint256[] memory _receiveTokenAmounts
85
    )
86
        internal
87
        view
88
    {
89
        uint256 receiveTokensCount = _receiveTokens.length;
×
90

91
        // Make sure required components array is non-empty
92
        require(
×
93
            receiveTokensCount > 0,
94
            "ExchangeIssuanceLibrary.validateReceiveTokens: Receive tokens must not be empty"
95
        );
96

97
        // Ensure the receive tokens has no duplicates
98
        require(
×
99
            !_receiveTokens.hasDuplicate(),
100
            "ExchangeIssuanceLibrary.validateReceiveTokens: Receive tokens must not have duplicates"
101
        );
102

103
        // Make sure required components and required component amounts are equal length
104
        require(
×
105
            receiveTokensCount == _receiveTokenAmounts.length,
106
            "ExchangeIssuanceLibrary.validateReceiveTokens: Receive tokens and amounts must be equal length"
107
        );
108

109
        for (uint256 i = 0; i < receiveTokensCount; i++) {
×
110
            // Make sure all required component amounts are non-zero
111
            require(
×
112
                _receiveTokenAmounts[i] > 0,
113
                "ExchangeIssuanceLibrary.validateReceiveTokens: Component amounts must be positive"
114
            );
115
        }
116
    }
117

118
    /**
119
     * Validates that the tokens received exceeds what we expect
120
     *
121
     * @param _vault                        The address of the Vault
122
     * @param _receiveTokens                The addresses of components required for issuance
123
     * @param _requiredBalances             The quantities of components required for issuance
124
     * @param _userToCheck                  The address of the user
125
     */
126
    function validatePostExchangeReceiveTokenBalances(
127
        address _vault,
128
        address[] memory _receiveTokens,
129
        uint256[] memory _requiredBalances,
130
        address _userToCheck
131
    )
132
        internal
133
        view
134
    {
135
        // Get vault instance
136
        IVault vault = IVault(_vault);
×
137

138
        // Check that caller's receive tokens in Vault have been incremented correctly
139
        for (uint256 i = 0; i < _receiveTokens.length; i++) {
×
140
            uint256 currentBal = vault.getOwnerBalance(
×
141
                _receiveTokens[i],
142
                _userToCheck
143
            );
144

145
            require(
×
146
                currentBal >= _requiredBalances[i],
147
                "ExchangeIssuanceLibrary.validatePostExchangeReceiveTokenBalances: Insufficient receive token acquired"
148
            );
149
        }
150
    }
151

152
    /**
153
     * Validates that the send tokens inputs are valid. Since tokens are sent to various exchanges,
154
     * duplicate send tokens are valid
155
     *
156
     * @param _core                         The address of Core
157
     * @param _sendTokenExchangeIds         List of exchange wrapper enumerations corresponding to 
158
     *                                          the wrapper that will handle the component
159
     * @param _sendTokens                   The address of the send tokens
160
     * @param _sendTokenAmounts             The quantities of send tokens
161
     */
162
    function validateSendTokenParams(
163
        address _core,
164
        uint8[] memory _sendTokenExchangeIds,
165
        address[] memory _sendTokens,
166
        uint256[] memory _sendTokenAmounts
167
    )
168
        internal
169
        view
170
    {
171
        require(
×
172
            _sendTokens.length > 0,
173
            "ExchangeIssuanceLibrary.validateSendTokenParams: Send token inputs must not be empty"
174
        );
175

176
        require(
×
177
            _sendTokenExchangeIds.length == _sendTokens.length && 
178
            _sendTokens.length == _sendTokenAmounts.length,
179
            "ExchangeIssuanceLibrary.validateSendTokenParams: Send token inputs must be of the same length"
180
        );
181

182
        ICore core = ICore(_core);
×
183

184
        for (uint256 i = 0; i < _sendTokenExchangeIds.length; i++) {
×
185
            // Make sure all exchanges are valid
186
            require(
×
187
                core.exchangeIds(_sendTokenExchangeIds[i]) != address(0),
188
                "ExchangeIssuanceLibrary.validateSendTokenParams: Must be valid exchange"
189
            );
190

191
            // Make sure all send token amounts are non-zero
192
            require(
×
193
                _sendTokenAmounts[i] > 0,
194
                "ExchangeIssuanceLibrary.validateSendTokenParams: Send amounts must be positive"
195
            );
196
        }
197
    }
198
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc