  Let $R$ be a polynomial ring in $m$ variables over a field of characteristic
zero. We classify all rank $n$ twisted generalized Weyl algebras over $R$, up
to $\mathbb{Z}^n$-graded isomorphisms, in terms of higher spin 6-vertex
configurations. Examples of such algebras include infinite-dimensional
primitive quotients of $U(\mathfrak{g})$ where $\mathfrak{g}=\mathfrak{gl}_n$,
$\mathfrak{sl}_n$, or $\mathfrak{sp}_{2n}$, algebras related to
$U(\widehat{\mathfrak{sl}}_2)$ and a finite W-algebra associated to
$\mathfrak{sl}_4$. To accomplish this classification we first show that the
problem is equivalent to classifying solutions to the binary and ternary
consistency equations. Secondly, we show that the latter problem can be reduced
to the case $n=2$, which can be solved using methods from previous work by the
authors. As a consequence we obtain the surprising fact that (in the setting of
the present paper) the ternary consistency relation follows from the binary
consistency relation.
