aiia-vault-sdk 1.2.3 → 1.2.4

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.
@@ -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,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})}};
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 t=require("ethers"),r=e(require("./abis/NFTTicket.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:r,args:a}=e;switch(r){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(t.ethers.formatEther(a.amount)),level:Number(a.level),originalAmount:Number(t.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 t.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 t.ethers.Contract(this.contractAddress,r.default.abi,i)}getRandomProvider(){return(0,s.getRandomProvider)(this.providers)}getContractWithRandomProvider(){return new t.ethers.Contract(this.contractAddress,r.default.abi,this.getRandomProvider())}async bootstrap(){if(this.isBootstrapped)return;const e=await Promise.all(this.providers.map(((e,t)=>(0,s.checkRpcHealth)(e,t))));if(this.providers=this.providers.filter(((t,r)=>e[r])),0===this.providers.length)throw new Error("No active RPC providers available");this.isBootstrapped=!0}async signAndSendTransaction(e,t,r={}){return(0,s.signAndSendTransaction)(e,t,(()=>this.getRandomProvider()),r,this.contract)}async getPrice(){const e=await this.contract.price();return Number(t.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 r=t.ethers.parseEther(e.toString());return await this.contract.setPrice.populateTransaction(r)}async buildBuyNFTTx(e){const r=await this.getPrice(),a=await this.contract.buy.populateTransaction(e);return a.value=t.ethers.parseEther(r.toString()),a}async buildWithdrawTx(e){const r=t.ethers.parseEther(e.toString());return await this.contract.withdraw.populateTransaction(r)}async buildMintToTx(e){return await this.bootstrap(),this.contract.mintTo.populateTransaction(e)}async buildBatchMintTx(e,t){return await this.bootstrap(),this.contract.batchMint.populateTransaction(e,t)}async getOwner(){return await this.contract.owner()}getContractAddress(){return this.contractAddress}async getAllEvents(e,t,r){return await this.bootstrap(),(0,s.getAllEvents)(this.contract,(()=>this.getRandomProvider()),(()=>this.getContractWithRandomProvider()),e,t,r)}async streamEvents(e,t,r,a=1e3,o=5e3){return await this.bootstrap(),(0,s.streamEvents)({getProvider:()=>this.getRandomProvider(),getAllEvents:(e,t)=>this.getAllEvents(e,t),formatEvent:e=>this.formatEventArgs(e),onEvent:t,saveLatestBlock:r,fromBlock:e,batchSize:a,sleepTime:o})}};