Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bean UI - Add Uniswap routing #744

Merged
merged 34 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f6dac4b
Route WETH<->USDC swaps through Uniswap
uncoolzero Dec 30, 2023
d572313
Removed exact output quote, cleaned up debug msgs
uncoolzero Jan 5, 2024
fba676f
Tag cleanup
uncoolzero Jan 5, 2024
23ecd37
cleanup, simplify
uncoolzero Jan 6, 2024
fc3b8b1
add clipboard
uncoolzero Jan 7, 2024
0c82cf9
update deposit graph
uncoolzero Jan 7, 2024
585b350
update deposit presets
uncoolzero Jan 7, 2024
5023df6
update deposit workflow
uncoolzero Jan 7, 2024
03a6b01
condense univ3 and well swap steps
uncoolzero Jan 7, 2024
0d18af9
Merge branch 'master' into bean-ui-uniswap-routing
uncoolzero Jan 9, 2024
95732f1
Merge branch 'master' into bean-ui-uniswap-routing
uncoolzero Jan 10, 2024
8c0a87e
Cleanup, formatting
uncoolzero Jan 10, 2024
631931e
comments, formatting, tweaked clipboard settings
uncoolzero Jan 11, 2024
9cfc397
Merge branch 'master' into bean-ui-uniswap-routing
uncoolzero Jan 11, 2024
d8ceb42
use advancedFarm on all swap calls
uncoolzero Jan 12, 2024
94236e5
tweaked clipboard settings
uncoolzero Jan 12, 2024
23f8227
tweaked clipboard settings
uncoolzero Jan 13, 2024
3092aae
exact output support
uncoolzero Jan 13, 2024
4d82ff2
exposed uniswap v3 fee tier setting
uncoolzero Jan 13, 2024
865824f
debug logs
uncoolzero Jan 13, 2024
9de544a
Merge branch 'master' into bean-ui-uniswap-routing
uncoolzero Jan 14, 2024
7f9e92e
use shift instead of swap
uncoolzero Jan 15, 2024
6c9a13b
fix approve/transfer
uncoolzero Jan 15, 2024
1ea34b0
add more deposit routes
uncoolzero Jan 15, 2024
5796b2d
update clipboard settings
uncoolzero Jan 15, 2024
ee93d0d
update deposit settings
uncoolzero Jan 15, 2024
bca6f8c
disable swap output field
uncoolzero Jan 15, 2024
9cab864
enable reverse direction on well shifts
uncoolzero Jan 15, 2024
4c04ba0
use shift on bean weth route
uncoolzero Jan 16, 2024
f4b4d30
updated tests
uncoolzero Jan 17, 2024
9cf81ad
cleanup
uncoolzero Jan 17, 2024
2cb5092
updated clipboard settings
uncoolzero Jan 17, 2024
132af06
cleanup
uncoolzero Jan 18, 2024
62eeaab
Merge branch 'master' into bean-ui-uniswap-routing
uncoolzero Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions projects/sdk/src/classes/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export abstract class Workflow<
this.add(elem, options); // recurse
}
} else {
Workflow.sdk.debug(`[Workflow][${this.name}][add] ${input.name || "<unknown>"}`);

if (input instanceof StepClass) {
input.setSDK(Workflow.sdk);
}
Expand All @@ -297,16 +297,27 @@ export abstract class Workflow<

switch (input.name) {
case "pipelineDeposit":
pipelineOptions = { tag: `deposit${filteredOptions.length + 1}Amount` };
Workflow.sdk.debug(`[Workflow][${this.name}][add] pipelineOptions: `, pipelineOptions);
pipelineOptions = { tag: `deposit${filteredOptions.length}Amount` };
break;
case "pipelineUniV3Deposit":
pipelineOptions = { tag: `depositUniV3${filteredOptions.length}Amount` };
break;
case "pipelineWellSwap":
pipelineOptions = { tag: `wellSwap${filteredOptions.length}Amount` };
break;
case "pipelineUniswapV3Swap":
pipelineOptions = { tag: `uniswapV3Swap${filteredOptions.length}Amount` };
break;
case "pipelineBeanWethSwap":
pipelineOptions = { tag: `beanWethSwap${filteredOptions.length}Amount` };
Workflow.sdk.debug(`[Workflow][${this.name}][add] pipelineOptions: `, pipelineOptions);
case "pipelineUniV3WellSwap":
pipelineOptions = { tag: `uniV3WellSwap${filteredOptions.length}Amount` };
break;
case "pipelineWellSwapUniV3":
pipelineOptions = { tag: `wellSwapUniV3${filteredOptions.length}Amount` };
break;
default:
Workflow.sdk.debug(`[Workflow][${this.name}][add] Not a bundle of Pipeline operations`);
}
};

Workflow.sdk.debug(`[Workflow][${this.name}][add] ${input.name || "<unknown>"}`, pipelineOptions || '');

this._generators.push(input);
this._options.push(pipelineOptions || options || null); // null = no options set
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH9","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"quoteExactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint160[]","name":"sqrtPriceX96AfterList","type":"uint160[]"},{"internalType":"uint32[]","name":"initializedTicksCrossedList","type":"uint32[]"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct IQuoterV2.QuoteExactInputSingleParams","name":"params","type":"tuple"}],"name":"quoteExactInputSingle","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceX96After","type":"uint160"},{"internalType":"uint32","name":"initializedTicksCrossed","type":"uint32"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"quoteExactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint160[]","name":"sqrtPriceX96AfterList","type":"uint160[]"},{"internalType":"uint32[]","name":"initializedTicksCrossedList","type":"uint32[]"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct IQuoterV2.QuoteExactOutputSingleParams","name":"params","type":"tuple"}],"name":"quoteExactOutputSingle","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceX96After","type":"uint160"},{"internalType":"uint32","name":"initializedTicksCrossed","type":"uint32"},{"internalType":"uint256","name":"gasEstimate","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"path","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"view","type":"function"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH9","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"}],"internalType":"struct ISwapRouter.ExactInputParams","name":"params","type":"tuple"}],"name":"exactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct ISwapRouter.ExactInputSingleParams","name":"params","type":"tuple"}],"name":"exactInputSingle","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMaximum","type":"uint256"}],"internalType":"struct ISwapRouter.ExactOutputParams","name":"params","type":"tuple"}],"name":"exactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMaximum","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct ISwapRouter.ExactOutputSingleParams","name":"params","type":"tuple"}],"name":"exactOutputSingle","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"refundETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitAllowed","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitAllowedIfNecessary","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"selfPermitIfNecessary","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"sweepToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"feeBips","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"}],"name":"sweepTokenWithFee","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"unwrapWETH9","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"feeBips","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"}],"name":"unwrapWETH9WithFee","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
6 changes: 6 additions & 0 deletions projects/sdk/src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export const addresses = {
// zap
CURVE_ZAP: Address.make("0xA79828DF1850E8a3A3064576f380D90aECDD3359"),

// Uniswap V3 Router
UNISWAP_V3_ROUTER: Address.make("0xE592427A0AEce92De3Edee1F18E0157C05861564"),

// Uniswap V3 Quoter V2
UNISWAP_V3_QUOTER_V2: Address.make("0x61fFE014bA17989E743c5F6cB21bF9697530B21e"),

// BEAN_ETH_UNIV2_LP !! Deprecated
BEAN_ETH_UNIV2_LP: Address.make("0x87898263B6C5BABe34b4ec53F22d98430b91e371"),

Expand Down
16 changes: 15 additions & 1 deletion projects/sdk/src/lib/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import {
Math,
Math__factory,
UsdOracle,
UsdOracle__factory
UsdOracle__factory,
UniswapV3Router__factory,
UniswapV3Router,
UniswapV3QuoterV2__factory,
UniswapV3QuoterV2,

} from "src/constants/generated";
import { BaseContract } from "ethers";

Expand Down Expand Up @@ -65,6 +70,9 @@ export class Contracts {

public readonly curve: CurveContracts;

public readonly uniswapV3Router: UniswapV3Router;
public readonly uniswapV3QuoterV2: UniswapV3QuoterV2;

// private chain: string;

constructor(sdk: BeanstalkSDK) {
Expand All @@ -89,6 +97,9 @@ export class Contracts {
const cryptoFactoryAddress = sdk.addresses.CRYPTO_FACTORY.get(sdk.chainId);
const zapAddress = sdk.addresses.CURVE_ZAP.get(sdk.chainId);

const uniswapV3RouterAddress = sdk.addresses.UNISWAP_V3_ROUTER.get(sdk.chainId);
const uniswapV3QuoterV2Address = sdk.addresses.UNISWAP_V3_QUOTER_V2.get(sdk.chainId);

// Instances
this.beanstalk = Beanstalk__factory.connect(beanstalkAddress, sdk.providerOrSigner);
this.beanstalkRead = Beanstalk__factory.connect(beanstalkAddress, sdk.readProvider ?? sdk.providerOrSigner);
Expand All @@ -109,6 +120,9 @@ export class Contracts {
const cryptoFactory = CurveCryptoFactory__factory.connect(cryptoFactoryAddress, sdk.providerOrSigner);
const zap = CurveZap__factory.connect(zapAddress, sdk.providerOrSigner);

this.uniswapV3Router = UniswapV3Router__factory.connect(uniswapV3RouterAddress, sdk.providerOrSigner);
this.uniswapV3QuoterV2 = UniswapV3QuoterV2__factory.connect(uniswapV3QuoterV2Address, sdk.providerOrSigner);

this.curve = {
pools: {
beanCrv3,
Expand Down
Loading