Skip to content

Commit

Permalink
fix: reuse function for offset
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Apr 2, 2021
1 parent 7fb80bc commit 19da691
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/tx-builder/services/LiquiditySwapAdapterParaswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { LiquiditySwapValidator } from '../validators/methodValidators';
import { IsEthAddress, IsPositiveAmount } from '../validators/paramValidators';
import BaseService from './BaseService';

function augustusFromAmountOffsetFromCalldata(calldata: string) {
export function augustusFromAmountOffsetFromCalldata(calldata: string) {
switch (calldata.slice(0, 10)) {
case '0xda8567c8': // Augustus V3 multiSwap
return 4 + 32 + 2 * 32;
Expand Down
30 changes: 4 additions & 26 deletions src/tx-builder/services/v2/LendingPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import LiquiditySwapAdapterInterface from '../../interfaces/LiquiditySwapAdapterParaswap';
import RepayWithCollateralAdapterInterface from '../../interfaces/RepayWithCollateralAdapter';
import BaseService from '../BaseService';
import { augustusFromAmountOffsetFromCalldata } from '../LiquiditySwapAdapterParaswap';

const buildParaSwapLiquiditySwapParams = (
assetToSwapTo: tEthereumAddress,
Expand Down Expand Up @@ -79,15 +80,6 @@ const buildParaSwapLiquiditySwapParams = (
);
};

function augustusFromAmountOffsetFromCalldata(calldata: string) {
switch (calldata.slice(0, 10)) {
case '0xda8567c8': // Augustus V3 multiSwap
return 4 + 32 + 2 * 32;
default:
throw new Error('Unrecognized function selector for Augustus');
}
}

export default class LendingPool
extends BaseService<ILendingPool>
implements LendingPoolInterface {
Expand Down Expand Up @@ -593,22 +585,6 @@ export default class LendingPool
swapCallData,
}: LPSwapCollateral
): Promise<EthereumTransactionTypeExtended[]> {
console.log('inParams', {
user,
flash,
fromAsset,
fromAToken,
toAsset,
fromAmount,
toAmount,
maxSlippage,
permitSignature,
swapAll,
onBehalfOf,
referralCode,
augustus,
swapCallData,
});
const txs: EthereumTransactionTypeExtended[] = [];

const permitParams = permitSignature || {
Expand Down Expand Up @@ -664,7 +640,9 @@ export default class LendingPool
const params = buildParaSwapLiquiditySwapParams(
toAsset,
amountSlippageConverted,
swapAll ? 4 + 2 * 32 : 0,
swapAll
? augustusFromAmountOffsetFromCalldata(swapCallData as string)
: 0,
swapCallData,
augustus,
permitParams.amount,
Expand Down

0 comments on commit 19da691

Please sign in to comment.