UNPKG

@verified-network/verified-sdk

Version:

An SDK to develop applications on the Verified Network

217 lines (216 loc) 9.97 kB
"use strict"; // SPDX-License-Identifier: BUSL-1.1 // @ts-nocheck Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); const Liquidity_json_1 = require("../../abi/liquidity/Liquidity.json"); var FUNCTIONS; (function (FUNCTIONS) { FUNCTIONS["SUPPORTTOKENS"] = "supportTokens"; FUNCTIONS["REMOVETOKEN"] = "removeToken"; FUNCTIONS["CHECKSUPPORTFORTOKEN"] = "checkSupportForToken"; FUNCTIONS["GETSUPPORTEDTOKENS"] = "getSupportedTokens"; FUNCTIONS["REGISTERPLATFORM"] = "registerPlatform"; FUNCTIONS["SETDISTRIBUTION"] = "setDistribution"; FUNCTIONS["BUY"] = "buy"; FUNCTIONS["GETINVESTORS"] = "getInvestors"; FUNCTIONS["GETINVESTMENT"] = "getInvestment"; FUNCTIONS["WITHDRAW"] = "withdraw"; FUNCTIONS["ADDMANAGER"] = "addManager"; FUNCTIONS["REMOVEMANAGER"] = "removeManager"; FUNCTIONS["GETMANAGERS"] = "getManagers"; FUNCTIONS["GETPLATFORMS"] = "getPlatforms"; FUNCTIONS["GETPLATFORMPERFORMANCE"] = "getPlatformPerformance"; FUNCTIONS["GETMANAGERPERFORMANCE"] = "getManagerPerformance"; FUNCTIONS["PROVIDELIQUIDITY"] = "provideLiquidity"; FUNCTIONS["NOTIFYISSUE"] = "RequestIssue"; FUNCTIONS["GETNAV"] = "getNAVPrice"; })(FUNCTIONS || (FUNCTIONS = {})); class LiquidityContract extends index_1.VerifiedContract { constructor(signer, contractNetworkAddress) { const address = contractNetworkAddress; //const chainId: string = Object.keys(networks) //const address = networks[chainId].address super(address, JSON.stringify(Liquidity_json_1.abi), signer); this.contractAddress = address; } async _getMeeQuote(paymentTokenAddress, functionName, args, apiKey, rpcUrl, isReactNative) { return await this.getQuote(paymentTokenAddress, functionName, args, rpcUrl, apiKey, isReactNative); } /** Specifies list of supported tokens that can be invested in the Verified Liquidity token @param _tokens array of supported token addresses */ async supportTokens(_tokens, _name, _feed, options) { await this.validateInput(index_1.DATATYPES.STRING, _tokens); await this.validateInput(index_1.DATATYPES.STRING, _name); await this.validateInput(index_1.DATATYPES.ADDRESS, _feed); return this.callContract(FUNCTIONS.SUPPORTTOKENS, _tokens, _name, _feed, options); } /** Checks if a specified token is supported for investing in the Verified Liquidity token @param _token token that is supported for investment */ async checkSupportForToken(_token, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _token); return this.callContract(FUNCTIONS.CHECKSUPPORTFORTOKEN, _token, options); } /** Sets distribution contract to receive distribution of returns from @param _distributionContract address of distribution contract */ async setDistribution(_distributionContract, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _distributionContract); return this.callContract(FUNCTIONS.SETDISTRIBUTION, _distributionContract, options); } /** Checks NAV for Verified Liquidity token */ async getNAVPrice() { return this.callContract(FUNCTIONS.GETNAV); } /** Removes support for token for investing in the Verified Liquidity token @param _token token that is supported for investment */ async removeToken(_token, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _token); return this.callContract(FUNCTIONS.REMOVETOKEN, _token, options); } /** * Returns list of supported liquidity tokens (eg, VITTA, USDC, DAI) * @returns array of struct of tokens */ async getSupportedTokens() { return this.callContract(FUNCTIONS.GETSUPPORTEDTOKENS); } /** Registers a liquidity platform (eg, DEX) where Verified Liquidity tokens can be used to underwrite investments @param _liquidityPlatform address of the market making platform */ async registerPlatform(_platform, _name, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); await this.validateInput(index_1.DATATYPES.STRING, _name); return this.callContract(FUNCTIONS.REGISTERPLATFORM, _platform, this.sanitiseInput(index_1.DATATYPES.BYTE32, _name), options); } /** Used by external apps (eg, exchange, wallet) to buy Verified Liquidity token @param _token address of token used by investor to buy the VITTA @param _amount amount of token that is transferred from investor to this VITTA issuing contract's account for the investor */ async buy(_token, _amount, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _token); await this.validateInput(index_1.DATATYPES.NUMBER, _amount); return this.callContract(FUNCTIONS.BUY, _token, _amount, options); } /** Fetches investors in VITTA */ async getInvestors() { return this.callContract(FUNCTIONS.GETINVESTORS); } /** Fetches registered platforms */ async getPlatforms() { return this.callContract(FUNCTIONS.GETPLATFORMS); } /** Fetches investment detail for specific investor in VITTA @param _investor address of investor @param _token address of token invested by investor */ async getInvestment(_investor, _token, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _investor); await this.validateInput(index_1.DATATYPES.ADDRESS, _token); return this.callContract(FUNCTIONS.GETINVESTMENT, _investor, _token, options); } /** Used by VITTA holder to withdraw staked liquidity for underwriting investments @param _fromStake amount of VITTA staked */ async withdraw(_fromStake, options) { await this.validateInput(index_1.DATATYPES.NUMBER, _fromStake); return this.callContract(FUNCTIONS.WITHDRAW, _fromStake, options); } /** * Adds asset manager to manage liquidity * @param _platform address of market making platform (eg Balancer) * @param _manager address of asset manager * @param options * @returns none */ async addManager(_platform, _manager, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); await this.validateInput(index_1.DATATYPES.ADDRESS, _manager); return this.callContract(FUNCTIONS.ADDMANAGER, _platform, _manager, options); } /** * Removes asset manager managing liquidity * @param _platform address of market making platform (eg Balancer) * @param _manager address of asset manager * @param options * @returns none */ async removeManager(_platform, _manager, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); await this.validateInput(index_1.DATATYPES.ADDRESS, _manager); return this.callContract(FUNCTIONS.REMOVEMANAGER, _platform, _manager, options); } /** * Fetches asset managers * @param _platform address of market making platform * @param options * @returns array of asset manager addresses */ async getManagers(_platform, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); return this.callContract(FUNCTIONS.GETMANAGERS, _platform, options); } /** * Gets return on investment performance of market making platform * @param _platform address of market making platform * @param options * @returns uint256 unstakedLiquidity, uint256 balancePlatformLiquidity, uint256 platformLiquidityProvided, uint256 platformCommissionsEarned */ async getPlatformPerformance(_platform, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); return this.callContract(FUNCTIONS.GETPLATFORMPERFORMANCE, _platform, options); } /** * Gets return on investment performance for asset manager * @param _platform address of market making platform (eg Balancer) * @param _manager address of asset manager * @param options * @returns uint256 managerLiquidityProvided, uint256 managerCommissionsEarned */ async getManagerPerformance(_platform, _token, _manager, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); await this.validateInput(index_1.DATATYPES.ADDRESS, _token); await this.validateInput(index_1.DATATYPES.ADDRESS, _manager); return this.callContract(FUNCTIONS.GETMANAGERPERFORMANCE, _platform, _token, _manager, options); } /** * Provides liquidity to asset managers on platform * @param _platform address of market making platform * @param _manager address of asset manager * @param _liquidity amount of liquidity to provision to asset manager on platform * @param options * @returns none */ async provideLiquidity(_platform, _manager, _liquidity, _token, options) { await this.validateInput(index_1.DATATYPES.ADDRESS, _platform); await this.validateInput(index_1.DATATYPES.ADDRESS, _manager); await this.validateInput(index_1.DATATYPES.NUMBER, _liquidity); await this.validateInput(index_1.DATATYPES.ADDRESS, _token); return this.callContract(FUNCTIONS.PROVIDELIQUIDITY, _platform, _manager, _liquidity, _token, options); } notifyIssue(callback) { this.getEvent(FUNCTIONS.NOTIFYISSUE, callback); } } exports.default = LiquidityContract;