aiia-vault-sdk 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,6 +25,11 @@ export interface ReferralCodeSetEvent {
25
25
  user: string;
26
26
  referralCode: string;
27
27
  }
28
+ export interface TransferEvent {
29
+ from: string;
30
+ to: string;
31
+ tokenId: number;
32
+ }
28
33
  /**
29
34
  * SDK for interacting with the MultiLevelReferralNFT smart contract
30
35
  *
@@ -1 +1 @@
1
- "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MultiLevelReferralNFTSDK=void 0;const r=require("ethers"),t=e(require("./abis/MultiLevelReferralNFT.json")),a=e(require("./contracts.json")),s=require("./utils");exports.MultiLevelReferralNFTSDK=class{constructor(e,n){this.name="NFTTicket",this.isBootstrapped=!1,this.formatEventArgs=e=>{const{eventName:t,args:a}=e;switch(t){case"NFTMinted":return{...e,args:{...a,owner:a.owner.toLowerCase(),tokenId:Number(a.tokenId)}};case"ReferrerSet":return{...e,args:{...a,referrer:a.referrer.toLowerCase(),referee:a.referee.toLowerCase()}};case"ReferralPaid":return{...e,args:{...a,receiver:a.receiver.toLowerCase(),buyer:a.buyer.toLowerCase(),amount:Number(r.ethers.formatEther(a.amount)),level:Number(a.level),originalAmount:Number(r.ethers.formatEther(a.originalAmount))}};case"ReferralCodeSet":return{...e,args:{...a,user:a.user.toLowerCase(),referralCode:a.referralCode}};default:return e}};const o=Array.isArray(e)?e:[e];this.providers=o.map((e=>new r.ethers.JsonRpcProvider(e)));const i=(0,s.getRandomProvider)(this.providers);this.contractAddress=(0,s.resolveContractAddress)(o[0],this.name,a.default,n),this.contract=new r.ethers.Contract(this.contractAddress,t.default.abi,i)}getRandomProvider(){return(0,s.getRandomProvider)(this.providers)}getContractWithRandomProvider(){return new r.ethers.Contract(this.contractAddress,t.default.abi,this.getRandomProvider())}async bootstrap(){if(this.isBootstrapped)return;const e=await Promise.all(this.providers.map(((e,r)=>(0,s.checkRpcHealth)(e,r))));if(this.providers=this.providers.filter(((r,t)=>e[t])),0===this.providers.length)throw new Error("No active RPC providers available");this.isBootstrapped=!0}async signAndSendTransaction(e,r,t={}){return(0,s.signAndSendTransaction)(e,r,(()=>this.getRandomProvider()),t,this.contract)}async getPrice(){const e=await this.contract.price();return Number(r.ethers.formatEther(e))}async getSharePercent(){const e=await this.contract.sharePercent();return Number(e)}async getMaxReferralLevels(){const e=await this.contract.maxReferralLevels();return Number(e)}async getReferrer(e){return await this.contract.referrers(e)}async getReferralCodeOwner(e){return await this.contract.referralCodes(e)}async getUserReferralCode(e){return await this.contract.userReferralCodes(e)}async buildGenerateReferralCodeTx(){return await this.contract.generateReferralCode.populateTransaction()}async buildGenerateReferralCodeForUserTx(e){return await this.contract.generateReferralCodeForUser.populateTransaction(e)}async buildSetPriceTx(e){const t=r.ethers.parseEther(e.toString());return await this.contract.setPrice.populateTransaction(t)}async buildBuyNFTTx(e){const t=await this.getPrice(),a=await this.contract.buy.populateTransaction(e);return a.value=r.ethers.parseEther(t.toString()),a}async buildWithdrawTx(e){const t=r.ethers.parseEther(e.toString());return await this.contract.withdraw.populateTransaction(t)}async buildMintToTx(e){return await this.bootstrap(),this.contract.mintTo.populateTransaction(e)}async buildBatchMintTx(e,r){return await this.bootstrap(),this.contract.batchMint.populateTransaction(e,r)}async getOwner(){return await this.contract.owner()}getContractAddress(){return this.contractAddress}async getAllEvents(e,r,t){return await this.bootstrap(),(0,s.getAllEvents)(this.contract,(()=>this.getRandomProvider()),(()=>this.getContractWithRandomProvider()),e,r,t)}async streamEvents(e,r,t,a=1e3,n=5e3){const o=["NFTMinted","ReferrerSet","ReferralPaid"];return await this.bootstrap(),(0,s.streamEvents)({getProvider:()=>this.getRandomProvider(),getAllEvents:(e,r)=>this.getAllEvents(e,r,o),formatEvent:e=>this.formatEventArgs(e),onEvent:r,saveLatestBlock:t,fromBlock:e,batchSize:a,sleepTime:n})}};
1
+ "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MultiLevelReferralNFTSDK=void 0;const r=require("ethers"),t=e(require("./abis/MultiLevelReferralNFT.json")),a=e(require("./contracts.json")),s=require("./utils");exports.MultiLevelReferralNFTSDK=class{constructor(e,o){this.name="NFTTicket",this.isBootstrapped=!1,this.formatEventArgs=e=>{const{eventName:t,args:a}=e;switch(t){case"NFTMinted":return{...e,args:{...a,owner:a.owner.toLowerCase(),tokenId:Number(a.tokenId)}};case"ReferrerSet":return{...e,args:{...a,referrer:a.referrer.toLowerCase(),referee:a.referee.toLowerCase()}};case"ReferralPaid":return{...e,args:{...a,receiver:a.receiver.toLowerCase(),buyer:a.buyer.toLowerCase(),amount:Number(r.ethers.formatEther(a.amount)),level:Number(a.level),originalAmount:Number(r.ethers.formatEther(a.originalAmount))}};case"ReferralCodeSet":return{...e,args:{...a,user:a.user.toLowerCase(),referralCode:a.referralCode}};case"Transfer":return{...e,args:{...a,from:a.from.toLowerCase(),to:a.to.toLowerCase(),tokenId:Number(a.tokenId)}};default:return e}};const n=Array.isArray(e)?e:[e];this.providers=n.map((e=>new r.ethers.JsonRpcProvider(e)));const i=(0,s.getRandomProvider)(this.providers);this.contractAddress=(0,s.resolveContractAddress)(n[0],this.name,a.default,o),this.contract=new r.ethers.Contract(this.contractAddress,t.default.abi,i)}getRandomProvider(){return(0,s.getRandomProvider)(this.providers)}getContractWithRandomProvider(){return new r.ethers.Contract(this.contractAddress,t.default.abi,this.getRandomProvider())}async bootstrap(){if(this.isBootstrapped)return;const e=await Promise.all(this.providers.map(((e,r)=>(0,s.checkRpcHealth)(e,r))));if(this.providers=this.providers.filter(((r,t)=>e[t])),0===this.providers.length)throw new Error("No active RPC providers available");this.isBootstrapped=!0}async signAndSendTransaction(e,r,t={}){return(0,s.signAndSendTransaction)(e,r,(()=>this.getRandomProvider()),t,this.contract)}async getPrice(){const e=await this.contract.price();return Number(r.ethers.formatEther(e))}async getSharePercent(){const e=await this.contract.sharePercent();return Number(e)}async getMaxReferralLevels(){const e=await this.contract.maxReferralLevels();return Number(e)}async getReferrer(e){return await this.contract.referrers(e)}async getReferralCodeOwner(e){return await this.contract.referralCodes(e)}async getUserReferralCode(e){return await this.contract.userReferralCodes(e)}async buildGenerateReferralCodeTx(){return await this.contract.generateReferralCode.populateTransaction()}async buildGenerateReferralCodeForUserTx(e){return await this.contract.generateReferralCodeForUser.populateTransaction(e)}async buildSetPriceTx(e){const t=r.ethers.parseEther(e.toString());return await this.contract.setPrice.populateTransaction(t)}async buildBuyNFTTx(e){const t=await this.getPrice(),a=await this.contract.buy.populateTransaction(e);return a.value=r.ethers.parseEther(t.toString()),a}async buildWithdrawTx(e){const t=r.ethers.parseEther(e.toString());return await this.contract.withdraw.populateTransaction(t)}async buildMintToTx(e){return await this.bootstrap(),this.contract.mintTo.populateTransaction(e)}async buildBatchMintTx(e,r){return await this.bootstrap(),this.contract.batchMint.populateTransaction(e,r)}async getOwner(){return await this.contract.owner()}getContractAddress(){return this.contractAddress}async getAllEvents(e,r,t){return await this.bootstrap(),(0,s.getAllEvents)(this.contract,(()=>this.getRandomProvider()),(()=>this.getContractWithRandomProvider()),e,r,t)}async streamEvents(e,r,t,a=1e3,o=5e3){const n=["NFTMinted","ReferrerSet","ReferralPaid","ReferralCodeSet","Transfer"];return await this.bootstrap(),(0,s.streamEvents)({getProvider:()=>this.getRandomProvider(),getAllEvents:(e,r)=>this.getAllEvents(e,r,n),formatEvent:e=>this.formatEventArgs(e),onEvent:r,saveLatestBlock:t,fromBlock:e,batchSize:a,sleepTime:o})}};
package/dist/types.d.ts CHANGED
@@ -383,6 +383,11 @@ export interface RawMultiLevelReferralNFTEventTypes {
383
383
  user: string;
384
384
  referralCode: string;
385
385
  };
386
+ Transfer: {
387
+ from: string;
388
+ to: string;
389
+ tokenId: bigint;
390
+ };
386
391
  }
387
392
  export interface MultiLevelReferralNFTEventTypes {
388
393
  NFTMinted: {
@@ -404,6 +409,11 @@ export interface MultiLevelReferralNFTEventTypes {
404
409
  user: string;
405
410
  referralCode: string;
406
411
  };
412
+ Transfer: {
413
+ from: string;
414
+ to: string;
415
+ tokenId: number;
416
+ };
407
417
  }
408
418
  export type ParsedMultiLevelReferralNFTEventRaw = {
409
419
  [K in keyof RawMultiLevelReferralNFTEventTypes]: BaseEventRaw & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiia-vault-sdk",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "SDK for AIIA Vault Contract",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",