Skip to content

Commit 8b17b26

Browse files
committed
fix: throw if multiple zappers found on meta step
1 parent d025c21 commit 8b17b26

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/sdk/market/ZapperRegister.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,20 @@ export class ZapperRegister extends SDKConstruct {
106106
return this.zappers.get(pool) ?? [];
107107
}
108108

109+
/**
110+
* Can return multiple zappers if there are multiple zappers for the same tokenIn and tokenOut
111+
*/
109112
public getZapper(
110113
pool: Address,
111114
tokenIn: Address,
112115
tokenOut: Address,
113-
): ZapperData | undefined {
114-
return this.zappers
116+
): Array<ZapperData> | undefined {
117+
const zappers = this.zappers
115118
.get(pool)
116-
?.find(
119+
?.filter(
117120
z => hexEq(z.tokenIn.addr, tokenIn) && hexEq(z.tokenOut.addr, tokenOut),
118121
);
122+
return zappers;
119123
}
120124
}
121125
/**

src/sdk/pools/PoolService.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,35 @@ export class PoolService extends SDKConstruct implements IPoolsService {
224224

225225
if (result.size === 0) {
226226
throw new Error(
227-
`No tokensOut found for tokenIn ${this.labelAddress(tokenIn)} on pool ${this.labelAddress(poolAddr)}`,
227+
`No tokensOut found for tokenIn ${this.labelAddress(
228+
tokenIn,
229+
)} on pool ${this.labelAddress(poolAddr)}`,
228230
);
229231
}
230232

231233
return result.asArray();
232234
}
233235

236+
#getDepositZapper(
237+
poolAddr: Address,
238+
tokenIn: Address,
239+
tokenOut: Address,
240+
): ZapperData | undefined {
241+
const zappers = this.sdk.marketRegister
242+
.getZapper(poolAddr, tokenIn, tokenOut)
243+
?.filter(z => z.type !== "migration");
244+
if (zappers && zappers.length > 1) {
245+
throw new Error(
246+
`Multiple zappers found for tokenIn ${this.labelAddress(
247+
tokenIn,
248+
)} and tokenOut ${this.labelAddress(
249+
tokenOut,
250+
)} on pool ${this.labelAddress(poolAddr)}`,
251+
);
252+
}
253+
254+
return zappers?.[0];
255+
}
234256
#depositMetadata(
235257
poolAddr: Address,
236258
tokenIn: Address,
@@ -242,14 +264,14 @@ export class PoolService extends SDKConstruct implements IPoolsService {
242264
}
243265
const { pool } = this.sdk.marketRegister.findByPool(poolAddr);
244266

245-
const zapper = this.sdk.marketRegister.getZapper(
246-
poolAddr,
247-
tokenIn,
248-
tokenOut,
249-
);
267+
const zapper = this.#getDepositZapper(poolAddr, tokenIn, tokenOut);
250268
if (!zapper && !allowDirectDeposit) {
251269
throw new Error(
252-
`No zapper found for tokenIn ${this.labelAddress(tokenIn)} and tokenOut ${this.labelAddress(tokenOut)} on pool ${this.labelAddress(poolAddr)}`,
270+
`No zapper found for tokenIn ${this.labelAddress(
271+
tokenIn,
272+
)} and tokenOut ${this.labelAddress(
273+
tokenOut,
274+
)} on pool ${this.labelAddress(poolAddr)}`,
253275
);
254276
}
255277

0 commit comments

Comments
 (0)