Skip to content

Commit

Permalink
Merge pull request #63 from Premian-Labs/issue/show-hide-errors
Browse files Browse the repository at this point in the history
Show/hide errors for optionAPI.quote
  • Loading branch information
froggiedev committed Nov 14, 2023
2 parents dc2640c + 7ae6b18 commit 4ed1036
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 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.3",
"version": "1.0.4",
"description": "The official SDK for building applications on Premia V3.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
38 changes: 33 additions & 5 deletions src/api/optionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ export class OptionAPI extends BaseAPI {
* @param {BigNumberish} [options.minimumSize] - The minimum size of the trade (optional).
* @param {string} [options.referrer] - The address of the referrer (optional).
* @param {string} [options.taker] - The address of the taker (optional).
* @param {number} [options.maxSlippagePercent] - The maximum slippage percent (optional).
* @param {boolean} [options.showErrors] - Whether to show errors (optional).
* @param {boolean} [options.showPoolErrors] - Whether to show pool errors (optional).
* @param {boolean} [options.showOrderbookErrors] - Whether to show orderbook errors (optional).
* @param {boolean} [options.showVaultErrors] - Whether to show vault errors (optional).
* @returns {Promise<FillableQuote | null>} - A promise that resolves to the best quote.
*/
@withCache(CacheTTL.SECOND)
Expand All @@ -472,6 +477,11 @@ export class OptionAPI extends BaseAPI {
minimumSize?: BigNumberish
referrer?: string
taker?: string
maxSlippagePercent?: number
showErrors?: boolean
showPoolErrors?: boolean
showOrderbookErrors?: boolean
showVaultErrors?: boolean
}): Promise<FillableQuote> {
const [bestRfqQuote, bestPoolQuote, bestVaultQuote] = await Promise.all([
this.premia.orders
Expand All @@ -483,18 +493,28 @@ export class OptionAPI extends BaseAPI {
options.referrer,
options.taker
)
.catch(),
.catch((e) => {
if (options.showErrors || options.showOrderbookErrors) {
console.error('Error getting orderbook quote', e)
}

return null
}),

this.premia.pools
.quote(
options.poolAddress,
options.size,
options.isBuy,
options.referrer,
options.taker
options.taker,
options.maxSlippagePercent
)
.catch((e) => {
console.error('Error in getting pool quote', e)
if (options.showErrors || options.showPoolErrors) {
console.error('Error getting pool quote', e)
}

return null
}),

Expand All @@ -505,9 +525,17 @@ export class OptionAPI extends BaseAPI {
options.isBuy,
options.minimumSize,
options.referrer,
options.taker
options.taker,
options.maxSlippagePercent,
options.showVaultErrors
)
.catch(),
.catch((e) => {
if (options.showErrors || options.showVaultErrors) {
console.error('Error getting vault quote', e)
}

return null
}),
])

const quotes = [bestRfqQuote, bestPoolQuote, bestVaultQuote].filter(
Expand Down
9 changes: 8 additions & 1 deletion src/api/vaultAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ export class VaultAPI extends BaseAPI {
.getQuote(poolKey, _size, isBuy, _taker)
.catch((err) => {
if (showErrors) {
console.error('Error getting vault quote', err)
console.error(
'Error getting vault quote with args:',
poolKey,
_size,
isBuy,
_taker,
err
)
}

return null
Expand Down

0 comments on commit 4ed1036

Please sign in to comment.