Skip to content

Commit

Permalink
Fix filter and make showing errors optional
Browse files Browse the repository at this point in the history
  • Loading branch information
froggiedev committed Nov 14, 2023
1 parent 243d2e7 commit 0036fbe
Show file tree
Hide file tree
Showing 2 changed files with 23 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": "@premia/v3-sdk",
"version": "1.0.4",
"version": "1.0.5",
"description": "The official SDK for building applications on Premia V3.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
26 changes: 22 additions & 4 deletions src/api/optionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,12 @@ export class OptionAPI extends BaseAPI {
isBuy: boolean
maturity?: BigNumberish
strike?: BigNumberish
showErrors?: boolean
}
): Promise<Pool | null> {
let pools = await this.premia.pools.getPools(baseAddress, false)

pools.filter((p) => p.isCall === options.isCall)
pools = pools.filter((p) => p.isCall === options.isCall)

if (options.maturity) {
pools = pools.filter(
Expand Down Expand Up @@ -279,7 +280,15 @@ export class OptionAPI extends BaseAPI {
)
return quote > 0n
} catch (err) {
console.log('Vault + Pool failed: ', vault.name, pool.name, err)
if (options.showErrors) {
console.log(
'Vault + Pool failed: ',
vault.name,
pool.name,
err
)
}

return false
}
})
Expand Down Expand Up @@ -345,14 +354,15 @@ export class OptionAPI extends BaseAPI {
isBuy: boolean
maturity?: BigNumberish
strike?: BigNumberish
showErrors?: boolean
}
): Promise<PoolMinimal | null> {
let [tokenPair, pools] = await Promise.all([
this.premia.pairs.getPair(pair),
this.premia.pools.getPoolsForPair(pair, false),
])

pools.filter((p) => p.isCall === options.isCall)
pools = pools.filter((p) => p.isCall === options.isCall)

if (options.maturity) {
pools = pools.filter(
Expand Down Expand Up @@ -399,7 +409,15 @@ export class OptionAPI extends BaseAPI {
)
return quote > 0n
} catch (err) {
console.log('Vault + Pool failed: ', vault.name, pool.name, err)
if (options.showErrors) {
console.log(
'Vault + Pool failed: ',
vault.name,
pool.name,
err
)
}

return false
}
})
Expand Down

0 comments on commit 0036fbe

Please sign in to comment.