Any ideas on how to dynamically create fixed-side arrays that doesn't involve a bunch of if statements?
EDIT:
Got this function that needs to produce a fixed-side array which length would depend on the args passed to it. As you can see, it looks a bit ugly with the if statements and it's not that scalable.
struct TokenLiq {
uint amountIn;
uint[2] biLiq;
uint[3] triLiq;
}
function _calculateTokenAmount(
uint amountIn_,
uint length_
) private returns(TokenLiq memory tokens)
{
uint tokenAmount;
if (length_ == 3) {
uint[3] memory amounts;
amounts[0] = 0;
amounts[1] = 0;
amounts[2] = amountIn_;
tokenAmount = s.tricrypto.calc_token_amount(amounts, true);
tokens.amountIn = tokenAmount;
tokens.triLiq = amounts;
} else if (length_ == 2) {
uint[2] memory amounts;
amounts[0] = 0;
amounts[1] = amountIn_;
tokenAmount = s.crv2Pool.calc_token_amount(amounts, true);
tokens.amountIn = tokenAmount;
tokens.biLiq = amounts;
}
}