@@ -1579,6 +1579,50 @@ impl BaselineSolvable for QuantAmmPool {
15791579 }
15801580}
15811581
1582+ /// Extract weights and multipliers from packed arrays.
1583+ /// This matches the getFirstFourWeightsAndMultipliers and
1584+ /// getSecondFourWeightsAndMultipliers pattern from balancer-maths.
1585+ fn extract_weights_and_multipliers (
1586+ first_four : & [ I256 ] ,
1587+ second_four : & [ I256 ] ,
1588+ num_tokens : usize ,
1589+ ) -> Option < ( Vec < I256 > , Vec < I256 > ) > {
1590+ let mut weights = Vec :: new ( ) ;
1591+ let mut multipliers = Vec :: new ( ) ;
1592+
1593+ // Process first four tokens (matches balancer-maths
1594+ // getFirstFourWeightsAndMultipliers)
1595+ let first_token_count = std:: cmp:: min ( 4 , num_tokens) ;
1596+ for i in 0 ..first_token_count {
1597+ if i < first_four. len ( ) / 2 {
1598+ weights. push ( first_four[ i] ) ;
1599+ if i + first_token_count < first_four. len ( ) {
1600+ multipliers. push ( first_four[ i + first_token_count] ) ;
1601+ } else {
1602+ multipliers. push ( I256 :: zero ( ) ) ;
1603+ }
1604+ }
1605+ }
1606+
1607+ // Process remaining tokens if any (matches balancer-maths
1608+ // getSecondFourWeightsAndMultipliers)
1609+ if num_tokens > 4 {
1610+ let remaining_count = num_tokens - 4 ;
1611+ for i in 0 ..remaining_count {
1612+ if i < second_four. len ( ) / 2 {
1613+ weights. push ( second_four[ i] ) ;
1614+ if i + remaining_count < second_four. len ( ) {
1615+ multipliers. push ( second_four[ i + remaining_count] ) ;
1616+ } else {
1617+ multipliers. push ( I256 :: zero ( ) ) ;
1618+ }
1619+ }
1620+ }
1621+ }
1622+
1623+ Some ( ( weights, multipliers) )
1624+ }
1625+
15821626#[ cfg( test) ]
15831627mod tests {
15841628 use { super :: * , crate :: sources:: balancer_v3:: pool_fetching:: CommonPoolState } ;
@@ -1819,47 +1863,3 @@ mod tests {
18191863 assert_eq ! ( res_out. unwrap( ) , amount_in. into( ) ) ;
18201864 }
18211865}
1822-
1823- /// Extract weights and multipliers from packed arrays.
1824- /// This matches the getFirstFourWeightsAndMultipliers and
1825- /// getSecondFourWeightsAndMultipliers pattern from balancer-maths.
1826- fn extract_weights_and_multipliers (
1827- first_four : & [ I256 ] ,
1828- second_four : & [ I256 ] ,
1829- num_tokens : usize ,
1830- ) -> Option < ( Vec < I256 > , Vec < I256 > ) > {
1831- let mut weights = Vec :: new ( ) ;
1832- let mut multipliers = Vec :: new ( ) ;
1833-
1834- // Process first four tokens (matches balancer-maths
1835- // getFirstFourWeightsAndMultipliers)
1836- let first_token_count = std:: cmp:: min ( 4 , num_tokens) ;
1837- for i in 0 ..first_token_count {
1838- if i < first_four. len ( ) / 2 {
1839- weights. push ( first_four[ i] ) ;
1840- if i + first_token_count < first_four. len ( ) {
1841- multipliers. push ( first_four[ i + first_token_count] ) ;
1842- } else {
1843- multipliers. push ( I256 :: zero ( ) ) ;
1844- }
1845- }
1846- }
1847-
1848- // Process remaining tokens if any (matches balancer-maths
1849- // getSecondFourWeightsAndMultipliers)
1850- if num_tokens > 4 {
1851- let remaining_count = num_tokens - 4 ;
1852- for i in 0 ..remaining_count {
1853- if i < second_four. len ( ) / 2 {
1854- weights. push ( second_four[ i] ) ;
1855- if i + remaining_count < second_four. len ( ) {
1856- multipliers. push ( second_four[ i + remaining_count] ) ;
1857- } else {
1858- multipliers. push ( I256 :: zero ( ) ) ;
1859- }
1860- }
1861- }
1862- }
1863-
1864- Some ( ( weights, multipliers) )
1865- }
0 commit comments