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

feat: uniswap v3 exact output support + UniversalSwapAndBridge #1268

Merged
merged 12 commits into from
Nov 10, 2024
Merged
Changes from 11 commits
Commits
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
6 changes: 4 additions & 2 deletions .github/workflows/dependency-review.yaml
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ jobs:
with:
fail-on-severity: high
# Comma-separated list of GHSA IDs to allow.
# We allow @openzeppelin/contracts@3.4.1-solc-0.7-2 critical vulnerabilities
# We allow the following critical vulnerabilities
# because they are not exploitable in our usage of the package.
allow-ghsas: GHSA-fg47-3c2x-m2wr, GHSA-88g8-f5mf-f5rj, GHSA-3h5v-q93c-6h6q
# - @openzeppelin/contracts@3.4.1-solc-0.7-2
# - @openzeppelin/contracts@4.7.0
allow-ghsas: GHSA-fg47-3c2x-m2wr, GHSA-88g8-f5mf-f5rj, GHSA-3h5v-q93c-6h6q, GHSA-qh9x-gcfh-pcrw, GHSA-4g63-c64m-25w9, GHSA-xrc4-737v-9q75, GHSA-4h98-2769-gh6h, GHSA-4h98-2769-gh6h, GHSA-93hq-5wgc-jc82
25 changes: 11 additions & 14 deletions api/_dexes/1inch.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import axios from "axios";

import { AcrossSwap, SwapQuoteAndCalldata } from "./types";
import { Swap, OriginSwapQuoteAndCalldata } from "./types";
import { getSwapAndBridgeAddress } from "./utils";

export async function get1inchQuoteAndCalldata(
swap: AcrossSwap
): Promise<SwapQuoteAndCalldata> {
const swapAndBridgeAddress = getSwapAndBridgeAddress(
"1inch",
swap.swapToken.chainId
);
const apiBaseUrl = `https://api.1inch.dev/swap/v6.0/${swap.swapToken.chainId}`;
export async function get1inchQuoteForOriginSwapExactInput(
swap: Omit<Swap, "recipient">
): Promise<OriginSwapQuoteAndCalldata> {
const swapAndBridgeAddress = getSwapAndBridgeAddress("1inch", swap.chainId);
const apiBaseUrl = `https://api.1inch.dev/swap/v6.0/${swap.chainId}`;
const apiHeaders = {
Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`,
accept: "application/json",
};

const swapParams = {
src: swap.swapToken.address,
dst: swap.acrossInputToken.address,
amount: swap.swapTokenAmount,
src: swap.tokenIn.address,
dst: swap.tokenOut.address,
amount: swap.amount,
from: swapAndBridgeAddress,
slippage: swap.slippage,
slippage: swap.slippageTolerance,
disableEstimate: true,
allowPartialFill: false,
receiver: swapAndBridgeAddress,
@@ -47,6 +44,6 @@ export async function get1inchQuoteAndCalldata(
value: response.data.tx.value,
swapAndBridgeAddress,
dex: "1inch",
slippage: swap.slippage,
slippage: swap.slippageTolerance,
};
}
21 changes: 9 additions & 12 deletions api/_dexes/types.ts
Original file line number Diff line number Diff line change
@@ -5,22 +5,19 @@ export type Token = {
chainId: number;
};

/**
* @property `swapToken` - Address of the token that will be swapped for acrossInputToken.
* @property `acrossInputToken` - Address of the token that will be bridged via Across as the inputToken.
* @property `swapTokenAmount` - The amount of swapToken to be swapped for acrossInputToken.
* @property `slippage` - The slippage tolerance for the swap in decimals, e.g. 1 for 1%.
*/
export type AcrossSwap = {
swapToken: Token;
acrossInputToken: Token;
swapTokenAmount: string;
slippage: number;
export type Swap = {
chainId: number;
tokenIn: Token;
tokenOut: Token;
amount: string;
recipient: string;
slippageTolerance: number;
type: "EXACT_INPUT" | "MIN_OUTPUT";
};

export type SupportedDex = "1inch" | "uniswap";

export type SwapQuoteAndCalldata = {
export type OriginSwapQuoteAndCalldata = {
minExpectedInputTokenAmount: string;
routerCalldata: string;
value: string;
Loading

Unchanged files with check annotations Beta

assert(query, SwapQueryParamsSchema);
let {
inputToken,

Check warning on line 43 in api/swap.ts

GitHub Actions / format-and-lint

'inputToken' is assigned a value but never used
outputToken,

Check warning on line 44 in api/swap.ts

GitHub Actions / format-and-lint

'outputToken' is assigned a value but never used
minOutputAmount,

Check warning on line 45 in api/swap.ts

GitHub Actions / format-and-lint

'minOutputAmount' is assigned a value but never used
originChainId,

Check warning on line 46 in api/swap.ts

GitHub Actions / format-and-lint

'originChainId' is assigned a value but never used
destinationChainId,

Check warning on line 47 in api/swap.ts

GitHub Actions / format-and-lint

'destinationChainId' is assigned a value but never used
recipient,

Check warning on line 48 in api/swap.ts

GitHub Actions / format-and-lint

'recipient' is assigned a value but never used
integratorId,

Check warning on line 49 in api/swap.ts

GitHub Actions / format-and-lint

'integratorId' is assigned a value but never used
refundAddress,

Check warning on line 50 in api/swap.ts

GitHub Actions / format-and-lint

'refundAddress' is assigned a value but never used
refundOnOrigin,
slippageTolerance = "0.5", // Default to 0.5% slippage
} = query;