npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@valorem-labs-inc/react-hooks

v0.0.8

Published

> This package provides React hooks for seamless integration with the Valorem > DeFi protocol, enabling the creation of sophisticated financial applications. > This API is not yet stable and subject to change

Downloads

8

Readme

Valorem React Hooks

This package provides React hooks for seamless integration with the Valorem DeFi protocol, enabling the creation of sophisticated financial applications. This API is not yet stable and subject to change

Table of Contents

Background

Valorem, a versatile DeFi protocol, supports physically and cash-settled options trading, including American, European, and Exotic types. The React Hooks package encapsulates interactions with Valorem's signature relay, Seaport, and Clear contract interfaces, offering a set of hooks for intuitive use within any React frontend.

Installation

To install the package, choose one of the following commands based on your package manager:

npm i @valorem-labs-inc/react-hooks
pnpm i @valorem-labs-inc/react-hooks
yarn add @valorem-labs-inc/react-hooks

Getting Started

Wrap your app in the ValoremProvider. This should be done inside of a WagmiConfig provider:

import { ValoremProvider } from '@valorem-labs-inc/react-hooks';
import { WagmiConfig } from 'wagmi';

function App() {
  return (
    <WagmiConfig config={/* see https://wagmi.sh/react/getting-started */}>
      <ValoremProvider>{children}</ValoremProvider>
    </WagmiConfig>
  );
}

Usage

You can use the provided hooks in any component within your app. Here's an example of using useRFQ and useSeaportFulfillOrder:

import { QuoteRequest, NULL_BYTES32 } from '@valorem-labs-inc/sdk';
import { useRFQ, useSeaportFulfillOrder } from '@valorem-labs-inc/react-hooks';

const quoteRequest = new QuoteRequest({
  // your quote request parameters
});

function Component() {
  const { quotes } = useRFQ({ quoteRequest });

  const bestQuote = useMemo(() => {
    if (!quotes) return undefined;

    // add your own logic to filter through offers

    return quotes[0];
  }, [quotes]);

  const { config } = usePrepareSeaportFulfillOrder({
    args:
      bestQuote !== undefined
        ? [
            {
              parameters: bestQuote.order.parameters,
              signature: bestQuote.order.signature,
            },
            NULL_BYTES32,
          ]
        : undefined,
    enabled: bestQuote !== undefined,
  });

  const { write, isLoading } = useSeaportFulfillOrder({
    ...config,
    async onSuccess({ hash }) {
      const { status, transactionHash } = await waitForTransaction({ hash });

      /* ... */
    },
  });

  return (
    <>
      <button
        onClick={write}
        disabled={write === undefined || isLoading === true}
      >
        {bestQuote === undefined
          ? 'Waiting for an RFQ response...'
          : 'Fulfill Order'}
      </button>
    </>
  );
}

Hooks API

The package offers several hooks for various aspects of options trading:

  • useRFQ: Request for quote from market makers.
  • useSoftQuote: Get a soft quote from a market maker.
  • useSeaportFulfillOrder: Fulfill an order via Seaport. Each hook is designed to be intuitive and easy to integrate, abstracting away the complexities of the blockchain interactions.

Development

For local development:

Install dependencies: pnpm i Format code: pnpm format Lint code: pnpm lint Run tests: pnpm test Build the package: pnpm build

Development

Install dependencies with pnpm i, run tests with pnpm test, and build with pnpm build.

Contributing

Contributions are welcome.

License

g This project is licensed under MIT License. Full license text is available in the LICENSE file.