@@ -15,6 +15,18 @@ use tg_utils::Expiration;
15
15
const MAX_LIMIT : u32 = 100 ;
16
16
const DEFAULT_LIMIT : u32 = 30 ;
17
17
18
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
19
+ pub ( crate ) struct TokenReleaseInfo {
20
+ pub addr : Addr ,
21
+ pub amount : Uint128 ,
22
+ }
23
+
24
+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
25
+ pub ( crate ) struct ReleaseData {
26
+ pub liquid_releases : Vec < TokenReleaseInfo > ,
27
+ pub vesting_releases : Vec < TokenReleaseInfo > ,
28
+ }
29
+
18
30
#[ derive( Serialize , Deserialize , Clone , Debug , PartialEq , Eq , JsonSchema ) ]
19
31
pub struct Claim {
20
32
/// Address owning the claim
@@ -154,13 +166,14 @@ impl<'a> Claims<'a> {
154
166
155
167
/// This iterates over all mature claims of any addresses, and removes them. Up to `limit`
156
168
/// claims would be processed, starting from the oldest. It removes the finished claims and
157
- /// returns vector of pairs: `(addr, amount)`, representing amount of tokens to be released to particular addresses
158
- pub fn claim_expired (
169
+ /// returns a pair of vectors representing the amounts of liquid and vesting tokens
170
+ /// to be released to particular addresses.
171
+ pub ( crate ) fn claim_expired (
159
172
& self ,
160
173
storage : & mut dyn Storage ,
161
174
block : & BlockInfo ,
162
175
limit : impl Into < Option < u64 > > ,
163
- ) -> StdResult < Vec < ( Addr , Uint128 ) > > {
176
+ ) -> StdResult < ReleaseData > {
164
177
let claims = self
165
178
. claims
166
179
. idx
@@ -176,18 +189,40 @@ impl<'a> Claims<'a> {
176
189
let mut claims = self . collect_claims ( claims, limit. into ( ) ) ?;
177
190
claims. sort_by_key ( |claim| claim. addr . clone ( ) ) ;
178
191
179
- let releases = claims
192
+ let liquid_releases = claims
180
193
. iter ( )
181
194
// TODO: use `slice::group_by` in place of `Itertools::group_by` when `slice_group_by`
182
195
// is stabilized [https://github.com/rust-lang/rust/issues/80552]
183
196
. group_by ( |claim| & claim. addr )
184
197
. into_iter ( )
185
- . map ( |( addr, group) | ( addr. clone ( ) , group. map ( |claim| claim. amount ) . sum ( ) ) )
198
+ . map ( |( addr, group) | TokenReleaseInfo {
199
+ addr : addr. clone ( ) ,
200
+ amount : group. map ( |claim| claim. amount ) . sum ( ) ,
201
+ } )
202
+ . collect ( ) ;
203
+
204
+ let vesting_releases = claims
205
+ . iter ( )
206
+ // TODO: use `slice::group_by` in place of `Itertools::group_by` when `slice_group_by`
207
+ // is stabilized [https://github.com/rust-lang/rust/issues/80552]
208
+ . group_by ( |claim| & claim. addr )
209
+ . into_iter ( )
210
+ . map ( |( addr, group) | TokenReleaseInfo {
211
+ addr : addr. clone ( ) ,
212
+ amount : group
213
+ . map ( |claim| claim. vesting_amount . unwrap_or_default ( ) )
214
+ . sum ( ) ,
215
+ } )
186
216
. collect ( ) ;
187
217
188
218
self . release_claims ( storage, claims) ?;
189
219
190
- Ok ( releases)
220
+ let release_data = ReleaseData {
221
+ liquid_releases,
222
+ vesting_releases,
223
+ } ;
224
+
225
+ Ok ( release_data)
191
226
}
192
227
193
228
/// Processes claims filtering those which are to be released. Returns vector of claims to be
0 commit comments