Swap Tokens on Uniswap

Swapping tokens on Uniswap likely requires some interaction with the Uniswap SDK in order to generate the path and assetAmountparameters shown below.

import {  
		callOnIntegrationArgs, 
		uniswapV2TakeOrderArgs, 
		IntegrationManagerActionId,
		takeOrderSelector, 
		ComptrollerLib 
} from '@enzymefinance/protocol';

// create a local signer connected to your chosen Ethereum node
const provider = providers.StaticJsonRpcProvider(ethNodeAddress, ethNetwork); 
const signer = new Wallet(managerEthPrivateKey, provider);

// the address of the adapter for the extension you wish to use
const uniswapV2Adapter = '0x23sdfsn...'; // for example only

// the address of the protocol release's integration manager contract
const integrationManagerAddress = '0x32sdf...'; // for example only

// the address of your vault's comptroller
const comptrollerAddress = '0x8syweo...'; // for example only

// assemble the arguments for the integration
const takeOrderArgs = uniswapV2TakeOrderArgs({
      path: aPath, // for example only
      minIncomingAssetAmount: aMinIncomingAssetAmount, // for example only
      outgoingAssetAmount: anOutgoingAssetAmount, // for example only
});

// assemble and encode the arguments for callOnExtension()
const callArgs = callOnIntegrationArgs({
      adapter: uniswapV2Adapter,
      selector: takeOrderSelector,
      encodedCallArgs: takeOrderArgs,
});

// instantiate your comptroller
const vaultComptroller = new ComptrollerLib(comptrollerAddress, signer);

const swapTx = vaultComptroller.callOnExtension.args(
		integrationManagerAddress, 
		IntegrationManagerActionId.CallOnIntegration, 
		callArgs
);

const swapTxReceipt = await swapTx.send();

console.log('Pending transaction:', swapTxReceipt.transactionHash);
console.log('Transaction included in block number:', swapTxReceipt.blockNumber);

Last updated