Skip to content

Instantly share code, notes, and snippets.

@this-post
Last active August 7, 2021 17:31
Show Gist options
  • Save this-post/2be3811298979f97932640a573f0d7b0 to your computer and use it in GitHub Desktop.
Save this-post/2be3811298979f97932640a573f0d7b0 to your computer and use it in GitHub Desktop.
function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = PancakeLibrary.sortTokens(input, output);
uint amountOut = amounts[i + 1];
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
address to = i < path.length - 2 ? PancakeLibrary.pairFor(factory, output, path[i + 2]) : _to;
IPancakePair(PancakeLibrary.pairFor(factory, input, output)).swap(
amount0Out, amount1Out, to, new bytes(0)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment