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

@tokeny/liquidity-provider-sdk

v0.3.1

Published

Harness the power of tokenized assets.

Downloads

5

Readme

Liquidity Provider SDK

Functionality

  • Verify if a wallet is linked to an Identity.
  • Validate that an Identity is compliant with requirements of a Token.
  • Pre-validate a transfer according to token compliance.

The Liquidity Provider SDK is intended to work in a NodeJS runtime, or in-browser for DApp.

Installation

Install with npm install @tokeny/liquidity-provider-sdk

Then require with:

const LiquiditySDK = require('@tokeny/liquidity-provider-sdk');

Usage

Configuration

BlockChain Provider

const LiquiditySDK = require('@tokeny/liquidity-provider-sdk');

LiquiditySDK.Config.setProvider('ropsten');

Identities

The LiquiditySDK.Identity module is used to retrieve information about Identities.

const LiquiditySDK = require('@tokeny/liquidity-provider-sdk');

LiquiditySDK.Config.setProvider(provider);

const identity = new LiquiditySDK.Identity('0x5CD462D81c0b42914A17B24b0129980E79080B09');
console.log(identity.address); // -> 0x5CD462D81c0b42914A17B24b0129980E79080B09

(async () => {
  // Check if Identity has a claim (from any issuer, included untrusted ones)
  console.log(await identity.hasClaim(10101000042003)); // -> true
  console.log(await identity.hasClaim(42)); // -> false
  
  // Check if Identity has a claim from a specific issuer
  console.log(await identity.hasClaim(10101000042003, '0xbCeE33f1bE60D8707786152BDEc67EE8c5950e06')); // -> true
  
  // Retrieve a specific claim by type for a specific issuer.
  console.log(await identity.getClaim(10101000042003, '0xbCeE33f1bE60D8707786152BDEc67EE8c5950e06')); // -> { ... }
})();

Tokens

The LiquiditySDK.Token module is used to retrieve information about an existing token.

const LiquiditySDK = require('@tokeny/liquidity-provider-sdk');

LiquiditySDK.Config.setProvider(provider);

const token = new LiquiditySDK.Token('0xbEA1e86d493116615eef93559B1c2e6E02620601');
console.identity(token.address); // -> 0x57a29006A9daa81390d5e0B72Aeda96E13995fF9

(async () => {
  const { name, symbol } = await token.getInformation();
    
  // token.name and token.symbol are now also populated.
  console.log(token.name === name); // -> true
  console.log(token.symbol === symbol); // -> true
})();

Compliance

sequenceDiagram
  participant A as Investor A
  participant B as Investor B
  participant D as Exchange
  participant SDK as Liquidity Provider SDK

  note over A: puts token in DEx
  A->>D: put token

  note over B: wants token
  B->>+D: Create order
  activate D
  D->>+SDK: Check if transfer is possible
  SDK-->>+T: BlockChain interaction
  T-->>-SDK: BlockChain interaction
  SDK->>-D: Transfer possibility
  D->>-B: Notification of possibility

  B->>+D: Confirm Order
  D-->>D: DEx internal operations
  D->>-B: Order confirmed
  
  note over B: retrieve tokens from DEx
  B->>+D: retrieve tokens action
  D->>D: DEx internal operations/checks
  D->>-SDK: Transfer token from DEx to B
  activate SDK
  SDK-->>+T: BlockChain interaction
  T-->>T: Compliance final check on blockchain
  T-->>-SDK: BlockChain interaction
  SDK->>+D: Transfer confirmation
  deactivate SDK
  D->>-B: Notification of transfer
Check Identity Compliance

Use token.isIdentityCompliant(identityAddressOrObject) to validate that an Identity has all claims required by the token smart contract.

const LiquiditySDK = require('@tokeny/liquidity-provider-sdk');

LiquiditySDK.Config.setProvider(provider);

const token = new LiquiditySDK.Token('0xbEA1e86d493116615eef93559B1c2e6E02620601');

(async () => {
  console.log(await token.isIdentityCompliant('0x57a29006A9daa81390d5e0B72Aeda96E13995fF9')); // -> true/false
  console.log(await token.isIdentityInRegistry('0x57a29006A9daa81390d5e0B72Aeda96E13995fF9')); // -> true/false
})();

To get the compliance breakdown for a non-valid Identity, call token.getIdentityOfWalletComplianceDetails(wallet, cache).

Check Transfer Compliance

Use token.isTransferValid(from, to, amount) to validate that an Identity has all claims required by the token smart contract.

const LiquiditySDK = require('@tokeny/liquidity-provider-sdk');

LiquiditySDK.Config.setProvider(provider);

const token = new LiquiditySDK.Token('0xbEA1e86d493116615eef93559B1c2e6E02620601');

(async () => {
  console.log(await token.isTransferValid('0x13A4CC8Dc7a98A1c6A064E83504C6Bbc45a299aC', '0x57a29006A9daa81390d5e0B72Aeda96E13995fF9', 42));
})();

To get the compliance breakdown for a non-valid transfer, call token.getTransferValidityDetails(from, to, quantity). It will check for sender's balance, recipient identity compliance, and token compliance rules.

In Browser

async function loadToken(address) {
  const {web3, ethereum} = window;

  if (!web3 || !ethereum) {
    throw new Error('No web3 or ethereum available.');
  }

  await ethereum.enable();

  const provider = new LiquiditySDK.Providers.Web3Provider(web3.currentProvider);

  const token = new LiquiditySDK.Token(address);
  await token.getIdentityRegistryInstance(provider);
  await token.getComplianceInstance(provider);
  await token.getInformation(provider);

  return {address: token.address, name: token.name, symbol: token.symbol, identityRegistry: token.identityRegistry, compliance: token.compliance};
}

Development

Don't forget to npm install first.

Build with npm run build.

This will build package into the dist/ folder from the TypeScript sources. This will also build the TypeDoc website into docs/type_doc.

Lint with npm run lint