Skip to content

Commit

Permalink
Merge pull request paraswap#169 from paraswap/feat/optimism-fees-est
Browse files Browse the repository at this point in the history
Feat/optimism fees est
  • Loading branch information
mwamedacen authored Aug 18, 2022
2 parents b37c184 + 4ccf0f7 commit b1e29fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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": "2.4.0",
"version": "2.5.0",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
17 changes: 13 additions & 4 deletions src/dex/paraswap-limit-orders/paraswap-limit-orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export class ParaSwapLimitOrders
prices: [unit],
} = this._getPrices([unitVolume], orderBook, isSell);

const { prices, gasCosts } = this._getPrices(amounts, orderBook, isSell);
const { prices, gasCosts, maxOrdersCount } = this._getPrices(
amounts,
orderBook,
isSell,
);

if (unit === 0n) {
// If we didn't fulfill unit amount, scale up latest amount till unit
Expand All @@ -148,7 +152,10 @@ export class ParaSwapLimitOrders
{
unit,
prices,
data: { orderInfos: null },
data: {
orderInfos: null,
maxOrdersCount,
},
poolIdentifier: expectedIdentifier,
exchange: this.dexKey,
gasCost: gasCosts.map(v => Number(v)),
Expand Down Expand Up @@ -409,9 +416,10 @@ export class ParaSwapLimitOrders
amounts: bigint[],
orderBook: ParaSwapOrderBook[],
isSell: boolean,
): { prices: bigint[]; gasCosts: bigint[] } {
): { prices: bigint[]; gasCosts: bigint[]; maxOrdersCount: number } {
const prices = new Array<bigint>(amounts.length).fill(0n);
const gasCosts = new Array<bigint>(amounts.length).fill(0n);
let maxOrdersCount = 0;

const calcOutFunc = isSell
? this._calcMakerFromTakerAmount
Expand Down Expand Up @@ -488,13 +496,14 @@ export class ParaSwapLimitOrders
} else if (toFill === 0n) {
prices[i] = filled;
gasCosts[i] = numberOfOrders * ONE_ORDER_GASCOST;
maxOrdersCount = Math.max(maxOrdersCount, +numberOfOrders.toString());
} else {
prices[i] = 0n;
gasCosts[i] = 0n;
}
}
}
return { prices, gasCosts };
return { prices, gasCosts, maxOrdersCount };
}

private _calcTakerFromMakerAmount(
Expand Down
1 change: 1 addition & 0 deletions src/dex/paraswap-limit-orders/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type ParaSwapOrderBook = {

export type ParaSwapLimitOrdersData = {
orderInfos: OrderInfo[] | null;
maxOrdersCount?: number;
};

export type DexParams = {
Expand Down

0 comments on commit b1e29fc

Please sign in to comment.