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

Aburkut/back 1809 bebop insert from amount pos #872

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "4.0.11",
"version": "4.0.12-bebop-insertFromAmountPos.0",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
66 changes: 39 additions & 27 deletions src/dex/bebop/bebop-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function testForNetwork(
const nativeTokenSymbol = NativeTokenSymbols[network];

const sideToContractMethods = new Map([
[SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
// [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
[SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
]);

Expand All @@ -50,34 +50,46 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
100,
);
});
it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[nativeTokenSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
await testE2E(
tokens[tokenASymbol],
tokens[tokenBSymbol],
holders[tokenASymbol],
side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
side,
dexKey,
contractMethod,
network,
provider,
);
});
// it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => {
// await testE2E(
// tokens[tokenASymbol],
// tokens[nativeTokenSymbol],
// holders[tokenASymbol],
// side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// undefined,
// undefined,
// undefined,
// 100,
// );
// });
// it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
// await testE2E(
// tokens[tokenASymbol],
// tokens[tokenBSymbol],
// holders[tokenASymbol],
// side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
// side,
// dexKey,
// contractMethod,
// network,
// provider,
// undefined,
// undefined,
// undefined,
// 100,
// );
// });
});
});
}),
Expand Down
18 changes: 17 additions & 1 deletion src/dex/bebop/bebop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
} from './constants';
import BigNumber from 'bignumber.js';
import { getBigNumberPow } from '../../bignumber-constants';
import { utils } from 'ethers';
import { ethers, utils } from 'ethers';
import qs from 'qs';
import { isEqual } from 'lodash';

Expand Down Expand Up @@ -656,12 +656,28 @@ export class Bebop extends SimpleExchange implements IDex<BebopData> {
srcAmount, // modify filledTakerAmount to make insertFromAmount work
]);

const fromAmount = ethers.utils.defaultAbiCoder.encode(
['uint256'],
[srcAmount],
);

const filledTakerAmountIndex = exchangeData
.replace('0x', '')
.lastIndexOf(fromAmount.replace('0x', ''));

const filledTakerAmountPos =
(filledTakerAmountIndex !== -1
? filledTakerAmountIndex
: exchangeData.length) / 2;

return {
exchangeData: exchangeData,
needWrapNative: this.needWrapNative,
dexFuncHasRecipient: true,
targetExchange: this.settlementAddress,
returnAmountPos: undefined,
sendEthButSupportsInsertFromAmount: true,
insertFromAmountPos: filledTakerAmountPos,
};
} else {
throw new Error('Not supported method');
Expand Down
1 change: 1 addition & 0 deletions src/dex/cables/cables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export class Cables extends SimpleExchange implements IDex<any> {
targetExchange: this.mainnetRFQAddress,
returnAmountPos: undefined,
insertFromAmountPos: filledAmountPos,
sendEthButSupportsInsertFromAmount: true,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/executor/Executor03BytecodeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
ExecutorBytecodeBuilder,
SingleSwapCallDataParams,
} from './ExecutorBytecodeBuilder';
import { assert } from 'ts-essentials';

const {
utils: { hexlify, hexDataLength, hexConcat, hexZeroPad, solidityPack },
Expand Down Expand Up @@ -330,6 +329,7 @@ export class Executor03BytecodeBuilder extends ExecutorBytecodeBuilder<

let fromAmountPos = 0;
let toAmountPos = 0;

if (insertAmount) {
if (exchangeParam.insertFromAmountPos) {
fromAmountPos = exchangeParam.insertFromAmountPos;
Expand Down
Loading