@@ -116,6 +116,48 @@ contract MultiTokenPeriodEnforcer is CaveatEnforcer {
116116 return _getAvailableAmount (allowance_);
117117 }
118118
119+ /**
120+ * @notice Decodes all configurations contained in _terms.
121+ * @dev Expects _terms length to be a multiple of 116.
122+ * @param _terms A concatenation of 116-byte configurations.
123+ * @return tokens_ An array of token addresses.
124+ * @return periodAmounts_ An array of period amounts.
125+ * @return periodDurations_ An array of period durations (in seconds).
126+ * @return startDates_ An array of start dates for the first period.
127+ */
128+ function getAllTermsInfo (bytes calldata _terms )
129+ external
130+ pure
131+ returns (
132+ address [] memory tokens_ ,
133+ uint256 [] memory periodAmounts_ ,
134+ uint256 [] memory periodDurations_ ,
135+ uint256 [] memory startDates_
136+ )
137+ {
138+ uint256 termsLength_ = _terms.length ;
139+ require (termsLength_ % 116 == 0 && termsLength_ != 0 , "MultiTokenPeriodEnforcer:invalid-terms-length " );
140+ uint256 numConfigs_ = termsLength_ / 116 ;
141+ tokens_ = new address [](numConfigs_);
142+ periodAmounts_ = new uint256 [](numConfigs_);
143+ periodDurations_ = new uint256 [](numConfigs_);
144+ startDates_ = new uint256 [](numConfigs_);
145+
146+ // Loop over each configuration using its index.
147+ for (uint256 i = 0 ; i < numConfigs_; ++ i) {
148+ // Calculate the starting offset for this configuration.
149+ uint256 offset_ = i * 116 ;
150+ // Get the token address from the first 20 bytes.
151+ tokens_[i] = address (bytes20 (_terms[offset_:offset_ + 20 ]));
152+ // Get the periodAmount from the next 32 bytes.
153+ periodAmounts_[i] = uint256 (bytes32 (_terms[offset_ + 20 :offset_ + 52 ]));
154+ // Get the periodDuration from the following 32 bytes.
155+ periodDurations_[i] = uint256 (bytes32 (_terms[offset_ + 52 :offset_ + 84 ]));
156+ // Get the startDate from the final 32 bytes.
157+ startDates_[i] = uint256 (bytes32 (_terms[offset_ + 84 :offset_ + 116 ]));
158+ }
159+ }
160+
119161 /**
120162 * @notice Hook called before a transfer to enforce the periodic limit.
121163 * @dev For ERC20 transfers, expects _executionCallData to decode to (target,, callData)
@@ -186,48 +228,6 @@ contract MultiTokenPeriodEnforcer is CaveatEnforcer {
186228 revert ("MultiTokenPeriodEnforcer:token-config-not-found " );
187229 }
188230
189- /**
190- * @notice Decodes all configurations contained in _terms.
191- * @dev Expects _terms length to be a multiple of 116.
192- * @param _terms A concatenation of 116-byte configurations.
193- * @return tokens_ An array of token addresses.
194- * @return periodAmounts_ An array of period amounts.
195- * @return periodDurations_ An array of period durations (in seconds).
196- * @return startDates_ An array of start dates for the first period.
197- */
198- function getAllTermsInfo (bytes calldata _terms )
199- public
200- pure
201- returns (
202- address [] memory tokens_ ,
203- uint256 [] memory periodAmounts_ ,
204- uint256 [] memory periodDurations_ ,
205- uint256 [] memory startDates_
206- )
207- {
208- uint256 termsLength_ = _terms.length ;
209- require (termsLength_ % 116 == 0 && termsLength_ != 0 , "MultiTokenPeriodEnforcer:invalid-terms-length " );
210- uint256 numConfigs_ = termsLength_ / 116 ;
211- tokens_ = new address [](numConfigs_);
212- periodAmounts_ = new uint256 [](numConfigs_);
213- periodDurations_ = new uint256 [](numConfigs_);
214- startDates_ = new uint256 [](numConfigs_);
215-
216- // Loop over each configuration using its index.
217- for (uint256 i = 0 ; i < numConfigs_; ++ i) {
218- // Calculate the starting offset for this configuration.
219- uint256 offset_ = i * 116 ;
220- // Get the token address from the first 20 bytes.
221- tokens_[i] = address (bytes20 (_terms[offset_:offset_ + 20 ]));
222- // Get the periodAmount from the next 32 bytes.
223- periodAmounts_[i] = uint256 (bytes32 (_terms[offset_ + 20 :offset_ + 52 ]));
224- // Get the periodDuration from the following 32 bytes.
225- periodDurations_[i] = uint256 (bytes32 (_terms[offset_ + 52 :offset_ + 84 ]));
226- // Get the startDate from the final 32 bytes.
227- startDates_[i] = uint256 (bytes32 (_terms[offset_ + 84 :offset_ + 116 ]));
228- }
229- }
230-
231231 ////////////////////////////// Internal Methods //////////////////////////////
232232
233233 /**
0 commit comments