Skip to content

Commit

Permalink
Merge pull request #103 from Premian-Labs/taker-only-rfq
Browse files Browse the repository at this point in the history
Taker only rfq
  • Loading branch information
froggiedev committed Feb 22, 2024
2 parents 4afe7c0 + 15c1201 commit 0aefae8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 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": "2.5.3",
"version": "2.6.3",
"description": "The official SDK for building applications on Premia V3.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
5 changes: 5 additions & 0 deletions src/api/optionAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ 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 {boolean} [options.forceSendRFQ] - Whether to force sending/listening for Request-for-Quotes (optional).
* @param {number} [options.maxSlippagePercent] - The maximum slippage percent (optional).
* @param {function} callback - Function to be called when a new best quote is available.
* @returns {Promise<void>}
Expand All @@ -494,6 +495,7 @@ export class OptionAPI extends BaseAPI {
minimumSize?: BigNumberish
referrer?: string
taker?: string
forceSendRFQ?: boolean
maxSlippagePercent?: number
poolKey?: PoolKey
pool?: PoolMinimal
Expand Down Expand Up @@ -648,6 +650,7 @@ 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 {boolean} [options.forceSendRFQ] - Whether to force sending/listening for Request-for-Quotes (optional).
* @param {number} [options.maxSlippagePercent] - The maximum slippage percent (optional).
* @param {string} [options.priceOracle] - The address of the price oracle (optional).
* @param {string[]} [options.quoteTokens] - Array of quote tokens' addresses (optional).
Expand All @@ -665,6 +668,7 @@ export class OptionAPI extends BaseAPI {
minimumSize?: BigNumberish
referrer?: string
taker?: string
forceSendRFQ?: boolean
maxSlippagePercent?: number
priceOracle?: string
quoteTokens?: string[]
Expand Down Expand Up @@ -718,6 +722,7 @@ export class OptionAPI extends BaseAPI {
minimumSize: options.minimumSize,
referrer: options.referrer,
taker: options.taker,
forceSendRFQ: options.forceSendRFQ,
maxSlippagePercent: options.maxSlippagePercent,
pool,
poolKey,
Expand Down
30 changes: 20 additions & 10 deletions src/api/ordersAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class OrdersAPI extends BaseAPI {
* @param {BigNumberish} [size] - The size of the trade (optional).
* @param {string} [taker] - The address of the taker (optional).
* @param {boolean} [throwError=false] - Whether to throw an error if the quote is invalid (default is false).
* @param {Provider} [provider] - The custom provider to use for this call.
* @param {Provider} [provider] - The custom provider to use for this call (optional).
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the quote is valid.
*/
async isQuoteValid(
Expand Down Expand Up @@ -232,7 +232,9 @@ export class OrdersAPI extends BaseAPI {
* @param {BigNumberish} [minimumSize] - The minimum size of the trade (optional).
* @param {string} [referrer] - The address of the referrer (optional).
* @param {string} [taker] - The address of the taker (optional).
* @param {Provider} [provider] - The custom provider to use for this call.
* @param {Provider} [provider] - The custom provider to use for this call (optional).
* @param {PoolKey} [poolKey] - The pool key to stream quotes from, passed for optimization purposes (optional).
* @param {PoolMinimal} [pool] - The pool to stream quotes from, passed for optimization purposes (optional).
* @returns {Promise<FillableQuote | null>} - The best fillable quote, or null if no quotes available.
*/
async quote(
Expand Down Expand Up @@ -289,7 +291,10 @@ export class OrdersAPI 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 {Provider} [options.provider] - The custom provider to use for this call.
* @param {Provider} [options.provider] - The custom provider to use for this call (optional).
* @param {boolean} [options.forceSendRFQ] - Whether to force sending/listening for Request-for-Quotes (optional).
* @param {PoolKey} [options.poolKey] - The pool key to stream quotes from, passed for optimization purposes (optional).
* @param {PoolMinimal} [options.pool] - The pool to stream quotes from, passed for optimization purposes (optional).
* @param {(quote: FillableQuote | null) => void} callback - The callback to execute for the best quote.
* @returns {Promise<void>}
*/
Expand All @@ -302,6 +307,7 @@ export class OrdersAPI extends BaseAPI {
referrer?: string
taker?: string
provider?: Provider
forceSendRFQ?: boolean
poolKey?: PoolKey
pool?: PoolMinimal
},
Expand All @@ -324,13 +330,15 @@ export class OrdersAPI extends BaseAPI {
))

let [, bestQuote] = await Promise.all([
this.premia.orderbook.publishRFQ({
poolKey,
side: options.isBuy ? 'bid' : 'ask',
chainId: this.premia.chainId.toString(),
size: options.size.toString(),
taker: options.taker ?? ZeroAddress,
}),
options.taker || options.forceSendRFQ
? this.premia.orderbook.publishRFQ({
poolKey,
side: options.isBuy ? 'bid' : 'ask',
chainId: this.premia.chainId.toString(),
size: options.size.toString(),
taker: options.taker ?? ZeroAddress,
})
: Promise.resolve(),
this.quote(
options.poolAddress,
options.size,
Expand All @@ -349,6 +357,8 @@ export class OrdersAPI extends BaseAPI {
callbackIfNotStale(null)
}

if (!options.taker && !options.forceSendRFQ) return

await this.premia.orderbook.subscribe(
{
type: 'FILTER',
Expand Down

0 comments on commit 0aefae8

Please sign in to comment.