@tokeny/liquidity-provider-sdk
v0.3.1
Published
Harness the power of tokenized assets.
Downloads
12
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