Skip to content

Commit

Permalink
Updated router sdk (Uniswap#43)
Browse files Browse the repository at this point in the history
* router-sdk 1.0.3 update

* cli tokenIn/Out --> token0/1
  • Loading branch information
ewilz authored Dec 15, 2021
1 parent 76b8046 commit 8b70357
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 53 deletions.
20 changes: 9 additions & 11 deletions cli/commands/quote-to-ratio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,26 @@ export class QuoteToRatio extends BaseCommand {
const tokenAccessor = await tokenProvider.getTokens([token0Str, token1Str]);

const chainId = ID_TO_CHAIN_ID(chainIdNumb);
const tokenIn: Currency =
const token0: Currency =
token0Str == 'ETH'
? Ether.onChain(chainId)
: tokenAccessor.getTokenByAddress(token0Str)!;
const tokenOut: Currency =
const token1: Currency =
token1Str == 'ETH'
? Ether.onChain(chainId)
: tokenAccessor.getTokenByAddress(token1Str)!;

const tokenInBalance = parseAmount(token0BalanceStr, tokenIn);
const tokenOutBalance = parseAmount(token1BalanceStr, tokenOut);
const token0Balance = parseAmount(token0BalanceStr, token0);
const token1Balance = parseAmount(token1BalanceStr, token1);

const poolAccessor = await this.poolProvider.getPools(
[[tokenIn.wrapped, tokenOut.wrapped, feeAmount]],
[[token0.wrapped, token1.wrapped, feeAmount]],
{ blockNumber: this.blockNumber }
);

const pool = poolAccessor.getPool(
tokenIn.wrapped,
tokenOut.wrapped,
token0.wrapped,
token1.wrapped,
feeAmount
);
if (!pool) {
Expand All @@ -105,17 +105,15 @@ export class QuoteToRatio extends BaseCommand {

let swapRoutes: SwapToRatioResponse;
swapRoutes = await router.routeToRatio(
tokenInBalance,
tokenOutBalance,
token0Balance,
token1Balance,
position,
{
ratioErrorTolerance: new Fraction(1, 100),
maxIterations: 6,
},
{
addLiquidityOptions: {
slippageTolerance: new Percent(5, 10_000),
deadline: 100,
recipient: '0x0000000000000000000000000000000000000001',
},
swapOptions: {
Expand Down
45 changes: 9 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/sinon": "^10.0.2",
"@types/stats-lite": "^2.2.0",
"@uniswap/default-token-list": "^2.0.0",
"@uniswap/router-sdk": "^1.0.2",
"@uniswap/router-sdk": "^1.0.3",
"@uniswap/swap-router-contracts": "1.1.0",
"@uniswap/token-lists": "^1.0.0-beta.25",
"@uniswap/v2-core": "^1.0.1",
Expand Down
5 changes: 2 additions & 3 deletions src/routers/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Trade } from '@uniswap/router-sdk';
import { CondensedAddLiquidityOptions, Trade } from '@uniswap/router-sdk';
import {
Currency,
Fraction,
Expand All @@ -8,7 +8,6 @@ import {
} from '@uniswap/sdk-core';
import { Route as V2RouteRaw } from '@uniswap/v2-sdk';
import {
AddLiquidityOptions,
MethodParameters,
Pool,
Position,
Expand Down Expand Up @@ -130,7 +129,7 @@ export type SwapAndAddConfig = {
// If provided, calldata for executing the swap and add will also be returned.
export type SwapAndAddOptions = {
swapOptions: SwapOptions;
addLiquidityOptions: AddLiquidityOptions;
addLiquidityOptions: CondensedAddLiquidityOptions;
};

// SwapAndAddOptions plus all other parameters needed to encode the
Expand Down
2 changes: 0 additions & 2 deletions test/unit/routers/alpha-router/alpha-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ describe('alpha router', () => {

const SWAP_AND_ADD_OPTIONS: SwapAndAddOptions = {
addLiquidityOptions: {
slippageTolerance: new Percent(500, 10_000),
deadline: 100,
recipient: `0x${'00'.repeat(19)}01`,
},
swapOptions: {
Expand Down

0 comments on commit 8b70357

Please sign in to comment.