Skip to content

Commit

Permalink
solve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 26, 2024
2 parents cb5b6bb + fb04915 commit 7cf3961
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 15 deletions.
11 changes: 10 additions & 1 deletion src/dex/camelot/camelot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ export class Camelot
isFeeTokenInRoute: Object.values(transferFees).some(f => f !== 0),
pools: [
{
stable: pairParam.stable,
address: pairParam.exchange,
fee: parseInt(pairParam.fee),
direction: pairParam.direction,
Expand Down Expand Up @@ -843,9 +844,17 @@ export class Camelot
if (side === SwapSide.BUY) throw new Error('Buy not supported');
let exchangeDataTypes = ['bytes4', 'bytes32'];

const isStable = data.pools.some(pool => !!pool.stable);
const isStablePoolAndPoolCount = isStable
? BigNumber.from(1)
.shl(255)
.or(BigNumber.from(data.pools.length))
.toHexString()
: hexZeroPad(hexlify(data.pools.length), 32);

let exchangeDataToPack = [
hexZeroPad(hexlify(0), 4),
hexZeroPad(hexlify(data.pools.length), 32),
isStablePoolAndPoolCount,
];

const pools = encodePools(data.pools, this.feeFactor);
Expand Down
11 changes: 10 additions & 1 deletion src/dex/solidly/solidly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export class Solidly extends UniswapV2 {
isFeeTokenInRoute: Object.values(transferFees).some(f => f !== 0),
pools: [
{
stable: pairParam.stable,
address: pairParam.exchange,
fee: parseInt(pairParam.fee),
direction: pairParam.direction,
Expand Down Expand Up @@ -657,9 +658,17 @@ export class Solidly extends UniswapV2 {
if (side === SwapSide.BUY) throw new Error(`Buy not supported`);
let exchangeDataTypes = ['bytes4', 'bytes32'];

const isStable = data.pools.some(pool => !!pool.stable);
const isStablePoolAndPoolCount = isStable
? BigNumber.from(1)
.shl(255)
.or(BigNumber.from(data.pools.length))
.toHexString()
: hexZeroPad(hexlify(data.pools.length), 32);

let exchangeDataToPack = [
hexZeroPad(hexlify(0), 4),
hexZeroPad(hexlify(data.pools.length), 32),
isStablePoolAndPoolCount,
];

const pools = encodePools(data.pools, this.feeFactor);
Expand Down
7 changes: 5 additions & 2 deletions src/dex/solidly/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export interface SolidlyPoolOrderedParams extends UniswapV2PoolOrderedParams {
stable: boolean;
}

export type SolidlyData = UniswapV2Data & { isFeeTokenInRoute: boolean };
export type SolidlyPool = UniswapPool & { stable: boolean };

export type SolidlyPool = UniswapPool;
export type SolidlyData = {
isFeeTokenInRoute: boolean;
pools: SolidlyPool[];
} & UniswapV2Data;

export interface DexParams extends Omit<UniswapV2DexParams, 'feeCode'> {
feeCode: number;
Expand Down
41 changes: 30 additions & 11 deletions src/executor/Executor02BytecodeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@paraswap/core';
import {
DexExchangeBuildParam,
DexExchangeParam,
DexExchangeParamWithBooleanNeedWrapNative,
} from '../types';
import { Executors, Flag, SpecialDex } from './types';
Expand Down Expand Up @@ -475,6 +474,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
swap: OptimalSwap,
swapCallData: string,
flag: Flag,
isRoot = false,
) {
const data = this.packVerticalBranchingData(swapCallData);

Expand All @@ -486,16 +486,34 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
let destTokenPos: number;

if (isEthDest) {
anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
priceRoute,
swap,
exchangeParams,
);
anyDexOnSwapDoesntNeedWrapNative = this.anyDexOnSwapDoesntNeedWrapNative(
priceRoute,
swap,
exchangeParams,
);
if (!isRoot) {
anyDexOnSwapNeedsWrapNative = this.anyDexOnSwapNeedsWrapNative(
priceRoute,
swap,
exchangeParams,
);
anyDexOnSwapDoesntNeedWrapNative =
this.anyDexOnSwapDoesntNeedWrapNative(
priceRoute,
swap,
exchangeParams,
);
} else {
anyDexOnSwapNeedsWrapNative = priceRoute.bestRoute.some(route =>
this.anyDexOnSwapNeedsWrapNative(
priceRoute,
route.swaps[route.swaps.length - 1],
exchangeParams,
),
);
anyDexOnSwapDoesntNeedWrapNative = priceRoute.bestRoute.some(route =>
this.anyDexOnSwapDoesntNeedWrapNative(
priceRoute,
route.swaps[route.swaps.length - 1],
exchangeParams,
),
);
}
}

if (
Expand Down Expand Up @@ -1313,6 +1331,7 @@ export class Executor02BytecodeBuilder extends ExecutorBytecodeBuilder<
needWrapEth
? Flag.DONT_INSERT_FROM_AMOUNT_DONT_CHECK_BALANCE_AFTER_SWAP // 0
: Flag.DONT_INSERT_FROM_AMOUNT_CHECK_SRC_TOKEN_BALANCE_AFTER_SWAP, // 8
true, // isRoot branch
);
}

Expand Down
30 changes: 30 additions & 0 deletions src/executor/executor02-bytecode-builder-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,36 @@ describe('Executor02ByteCodeBuilder e2e tests', () => {
);
});
});

describe('USDCe -> MATIC', () => {
const dexKeys = ['CurveV2', 'UniswapV3', 'SushiSwapV3', 'SwaapV2'];

const tokenASymbol: string = 'USDCe';
const tokenBSymbol: string = 'MATIC';
const tokenAAmount: string = '1978798814';

const side = SwapSide.SELL;

it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[tokenBSymbol],
holders[tokenASymbol],
tokenAAmount,
side,
dexKeys,
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
100,
2000,
false,
);
});
});
});
});

Expand Down

0 comments on commit 7cf3961

Please sign in to comment.