Skip to content

Repository files navigation

Panacloud Protocol SDK

Installation

Install the package:

npm install @panacloud/protocol-sdk

Getting Started

1. Set up the SDK using Ethers

To use SDK is using Ethersv5, create an instance of the EthersAdapter.

import{EthersAdapter,PanacloudSDK}from"@panacloud/protocol-sdk";import{ethers}from'ethers';constethAdapter=newEthersAdapter({
ethers,
signer
});constpanacloudSDK=awaitPanacloudSDK.create({ethAdapter});console.log("PanaFactory Contract Address",panacloudSDK.getPanaFactoryAddress());

2. Create API DAO using Ethers

constapiTokenConfig={apiTokenName: "Demo API v1",apiTokenSymbol: "DEMO",maxApiTokenSupply: BigNumber.from("1000000"),// 1 millioninitialApiTokenSupply: BigNumber.from("100000"),// 100kdeveloperSharePercentage: BigNumber.from("80"),apiInvestorSharePercentage: BigNumber.from("10"),thresholdForSubscriberMinting: BigNumber.from("10")}constapiDAOConfig={apiProposalId: "NAN",apiId: "demo-api",daoName: "Demo DAO",votingSupportPercentage: BigNumber.from(50),votingMinimumApprovalPercentage: BigNumber.from(20),voteDuration: BigNumber.from(24).mul(60).mul(60)};consttransactionResult=awaitpanacloudSDK.createAPIDao(apiTokenConfig,apiDAOConfig);console.log("Transaction hash: ",transactionResult.hash);consttransactionReceipt=awaittransactionResult.transactionResponse.wait();console.log("Transaction completed: ",transactionReceipt);

3. Pay Invoices Ethers

// DAI Token address on RinkebyconstdaiToken=newethers.Contract("0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea",DaiABI,signer);console.log("dai token = ",daiToken);//Address of Userconstaddr1DaiBalance=awaitdaiToken.balanceOf("0xb11846818eda46eca2e0481a4a4afebb4cac18d5")console.log("DAI Balance for signer = ",ethers.utils.formatEther(addr1DaiBalance.toString()));consttxt1=awaitdaiToken.approve(panacloudSDK.getPanacloudPlatform().getAddress(),ethers.utils.parseEther("1"));constreceipt=txt1.wait();console.log("Approval done");constinvoice={apiToken:"0x6c6719e351210d651187b9ccb2f4b6e0dc06a7f1",// API Token AddressinvoiceNumber: 1,dueDate: Date.now(),invoiceMonth:1,totalAmount: ethers.utils.parseEther("1"),invoicePayee: signer.getAddress()}constpanacloudPlatformContract=panacloudSDK.getPanacloudPlatform();consttransactionResult=awaitpanacloudPlatformContract.payInvoice("0xb11846818eda46eca2e0481a4a4afebb4cac18d5",// User who created API DAO"0xc6d9af3635b0e8c0f10a264e7fdcc10e2b91890a",// DAO Addressinvoice);console.log("Transaction hash: ",transactionResult.hash);consttransactionReceipt=awaittransactionResult.transactionResponse.wait();console.log("Transaction completed: ",transactionReceipt);

Invoice Data Type

exportinterfaceInvoice{
apiToken: string;// API Token Address
invoiceNumber: BigNumber;
dueDate: BigNumber;
invoiceMonth: BigNumber;// From 1 to 12
totalAmount: BigNumber;
invoicePayee: string;// API Subscriber Address}

4. Get API Developers Earning Details Ethers

constpanacloudPlatformContract=panacloudSDK.getPanacloudPlatform();constapiDetails=awaitpanacloudPlatformContract.getDevEarnings(awaitsigner.getAddress());console.log("API Details = ",apiDetails);console.log("API Details.apiDev = ",apiDetails.apiDev);console.log("API Details.totalClaimable = ",ethers.utils.formatEther(apiDetails.totalClaimable));console.log("API Details.totalClaimed = ",ethers.utils.formatEther(apiDetails.totalClaimed));console.log("API Details.totalEarned = ",ethers.utils.formatEther(apiDetails.totalEarned));console.log("API Details.userDAODetails array = ",apiDetails.userDAODetails);

UserDAODetails and APIDevDetails Data Type

exportinterfaceUserDAODetails{
apiDao: string;
apiToken: string;}exportinterfaceAPIDevDetails{
apiDev: string;
totalEarned: BigNumber
totalClaimable: BigNumber
totalClaimed: BigNumberuserDAODetails: UserDAODetails[]}

5. Get Invoice List of API Ethers

constpanacloudPlatformContract=panacloudSDK.getPanacloudPlatform();constinvoiceList=awaitpanacloudPlatformContract.getAPIInvoices(awaitsigner.getAddress(),"0x6c6719e351210d651187b9ccb2f4b6e0dc06a7f1");console.log("InvoiceList = ",invoiceList);console.log("InvoiceList[0] = ",invoiceList[0]);console.log("InvoiceList[0].apiToken = ",invoiceList[0].apiToken);console.log("InvoiceList[0].dueDate = ",newDate(invoiceList[0].dueDate.toNumber()));console.log("InvoiceList[0].invoiceMonth = ",invoiceList[0].invoiceMonth.toString());console.log("InvoiceList[0].invoiceNumber = ",invoiceList[0].invoiceNumber.toString());console.log("InvoiceList[0].invoicePayee = ",invoiceList[0].invoicePayee);console.log("InvoiceList[0].totalAmount = ",invoiceList[0].totalAmount.toString());

6. Calim Earning by API Developer Ethers

constpanacloudPlatformContract=panacloudSDK.getPanacloudPlatform();// Called for claimEarnings must be API developer and must have records in our contractconsttransactionResult=awaitpanacloudPlatformContract.claimEarnings(ethers.utils.parseEther("0.95"));console.log("Transaction hash: ",transactionResult.hash);consttransactionReceipt=awaittransactionResult.transactionResponse.wait();console.log("Transaction completed: ",transactionReceipt);

7. Get Earning History Ethers

//getClaimHistory will return claim history of function callerconstclaimList=awaitpanacloudPlatformContract.getClaimHistory();console.log("ClaimList = ",claimList);for(leti=0;i<claimList.length;i++){console.log("Claim Amount = ",ethers.utils.formatEther(claimList[i].claimedAmount.toString()));console.log("Claimed Time = ",newDate(claimList[i].timestamp.toNumber()));}

Claim Data Type

export interfaceClaim{apiDev: string
claimedAmount: BigNumber
timestamp: BigNumber}

8. Create Investment Pools (Only Admin or Manager can call this function) Ethers

letwhitelistingStartDate=newDate("1/19/1970");letwhitelistingEndDate=newDate("2/15/1970");constinvestmentPoolsContract=panacloudSDK.getInvestmentPools();consttransactionResult=awaitinvestmentPoolsContract.createInvestmentPool("0xb11846818Eda46eCa2E0481A4A4AFEBB4CAC18d5",// API developer address"0xBc9656979A2486D3fBEB0D2D240cb9032456e245",// API Token AddressBigNumber.from((newDate()).getTime()),// Pool Start Date and timeBigNumber.from(30).mul(24).mul(60).mul(60),// Pool Durationethers.utils.parseEther("1"),// Per API token price in terms of PanaCoin 10000,// Tokens to be issuedethers.utils.parseEther("10"),// Minimum investment required in terms of PanaCon e.g if token price is 50 so 10 tokens * 50 = 500 so 500 panacoin minimum investmentBigNumber.from(100),// Number of Tokens single investor can buy BigNumber.from(whitelistingStartDate.getTime()),// Whitelisting start dateBigNumber.from(whitelistingEndDate.getTime()));// Whitelisting end date// Note: pool duration should be long enough so cover whitelisting start and end date

Pool Info and Pool Investment Details Data Type

exportinterfacePoolInfo{
poolIndex:BigNumber
startDate:BigNumber
duration:BigNumber
tokenPrice:BigNumber
tokensToBeIssued:BigNumber
minimumInvestmentRequired:BigNumber
tokenPerInvestor:BigNumber
apiToken:string
apiDev:string
poolFundingStatus:BigNumber// 1=In Progress, 2=Successfull, 3=Failed 
poolActive:boolean
totalFundApproved:BigNumber
fundsAvailableFromClaim:BigNumber
fundsClaimed:BigNumber}exportinterfacePoolInvestmentDetails{
poolIndex:BigNumber
apiToken: string
whitelistingStartDate:BigNumber
whitelistingEndDate:BigNumber
fundCollected: BigNumber
tokenIssued: BigNumber
fundingFailed: boolean;}

9. Apply for Investment Ethers

constinvestmentPoolsManagerContract=panacloudSDK.getInvestmentPoolsManager();consttransactionResult=awaitinvestmentPoolsManagerContract.applyForInvestmentPool("0xa1182eBDc63a68a5355235132aF9AD7555C39c03");console.log("Transaction hash: ",transactionResult.hash);consttransactionReceipt=awaittransactionResult.transactionResponse.wait();console.log("Transaction completed: ",transactionReceipt);

10. Get Pool Info List Ethers

constinvestmentPoolsContract=panacloudSDK.getInvestmentPools();constpoolInfoList=awaitinvestmentPoolsContract.getPoolInfoList();console.log("poolInfoList = ",poolInfoList);

11. Get Specific Pool Info and Details Ethers

constinvestmentPoolsContract=panacloudSDK.getInvestmentPools();constpoolInfo=awaitinvestmentPoolsContract.getInvestmentPool("0xBc9656979A2486D3fBEB0D2D240cb9032456e245");constpoolInfoDetails=awaitinvestmentPoolsContract.getPoolInvestmentDetails("0xBc9656979A2486D3fBEB0D2D240cb9032456e245");console.log("Pool info = ",poolInfo);console.log("Pool info Details = ",poolInfoDetails);

12. Invest In Pool Ethers

constinvestmentPoolsContract=panacloudSDK.getInvestmentPools();// Panacoin Token address on RinkebyconstpanacoindToken=newethers.Contract("0xbC810553892c750a7518438970216FC836294B91",PanaCoin,signer);console.log("panacoind token = ",panacoindToken);//Address of UserconstownerPanaCoinBalance=awaitpanacoindToken.balanceOf("<Investor Wallet Address>")console.log("Panacloud Balance for investor = ",ethers.utils.formatEther(ownerPanaCoinBalance.toString()));consttxt1=awaitpanacoindToken.approve(investmentPoolsContract.getAddress(),ethers.utils.parseEther("10"));constreceipt=txt1.wait();console.log("Approval done");consttransactionResult=awaitinvestmentPoolsContract.investInPool("0xBc9656979A2486D3fBEB0D2D240cb9032456e245",ethers.utils.parseEther("10"));console.log("Transaction hash: ",transactionResult.hash);consttransactionReceipt=awaittransactionResult.transactionResponse.wait();console.log("Transaction completed: ",transactionReceipt);

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages