aiia-vault-sdk 1.1.18 → 1.1.20
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.
@@ -561,4 +561,39 @@ export declare class SeedRoundFundraiserSDK {
|
|
561
561
|
* - This is typically called by the project owner to fund the contract
|
562
562
|
*/
|
563
563
|
buildTransferProjectTokenToContract(amount: number): Promise<ethers.ContractTransaction>;
|
564
|
+
/**
|
565
|
+
* Checks if an address has the admin role
|
566
|
+
*
|
567
|
+
* @param address - The address to check
|
568
|
+
* @returns Boolean indicating if the address has admin role
|
569
|
+
*
|
570
|
+
* @example
|
571
|
+
* ```typescript
|
572
|
+
* const hasAdminRole = await sdk.hasAdminRole("0x...");
|
573
|
+
* ```
|
574
|
+
*/
|
575
|
+
hasAdminRole(address: string): Promise<boolean>;
|
576
|
+
/**
|
577
|
+
* Builds a transaction to grant admin role to an address
|
578
|
+
*
|
579
|
+
* @param address - The address to grant admin role to
|
580
|
+
* @returns Populated transaction
|
581
|
+
*
|
582
|
+
* @example
|
583
|
+
* ```typescript
|
584
|
+
* const tx = await sdk.buildGrantAdminRoleTx("0x...");
|
585
|
+
* ```
|
586
|
+
*/
|
587
|
+
buildGrantAdminRoleTx(address: string): Promise<ethers.ContractTransaction>;
|
588
|
+
/**
|
589
|
+
* Gets the DEFAULT_ADMIN_ROLE hash
|
590
|
+
*
|
591
|
+
* @returns The DEFAULT_ADMIN_ROLE hash
|
592
|
+
*
|
593
|
+
* @example
|
594
|
+
* ```typescript
|
595
|
+
* const adminRoleHash = await sdk.getAdminRoleHash();
|
596
|
+
* ```
|
597
|
+
*/
|
598
|
+
getAdminRoleHash(): Promise<string>;
|
564
599
|
}
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SeedRoundFundraiserSDK=void 0;const e=require("ethers"),n=t(require("./abis/SeedRoundFundraiser.json")),o=t(require("./contracts.json")),r=require("./utils"),i=t(require("./whitelist-tokens.json"));exports.SeedRoundFundraiserSDK=class{constructor(t,i){this.name="SeedRoundFundraiser",this.isBootstrapped=!1,this.PRICE_PRECISION=1e18,this.whitelistedTokensArray=[],this.projectToken="",this.projectTokenDecimals=0,this.formatEventArgs=t=>{const{eventName:e,args:n}=t;switch(e){case"TokenWhitelisted":return{...t,args:{...n,token:n.token.toLowerCase(),price:Number(n.price)/this.PRICE_PRECISION}};case"TokenPriceUpdated":return{...t,args:{...n,token:n.token.toLowerCase(),oldPrice:Number(n.oldPrice)/this.PRICE_PRECISION,newPrice:Number(n.newPrice)/this.PRICE_PRECISION}};case"TokenRemovedFromWhitelist":return{...t,args:{...n,token:n.token.toLowerCase()}};case"RoundCreated":case"RoundUpdated":return{...t,args:{...n,roundId:Number(n.roundId),startTime:Number(n.startTime),endTime:Number(n.endTime),targetFund:Number(n.targetFund)/this.PRICE_PRECISION,totalAllocation:Number(n.totalAllocation),maxFundPerAccount:Number(n.maxFundPerAccount)/this.PRICE_PRECISION}};case"RoundEnded":return{...t,args:{...n,roundId:Number(n.roundId),raisedFunds:Number(n.raisedFunds)/this.PRICE_PRECISION,participants:Number(n.participants)}};case"Contribution":return{...t,args:{...n,roundId:Number(n.roundId),contributor:n.contributor.toLowerCase(),token:n.token.toLowerCase(),amount:Number(n.amount),fundAmount:Number(n.fundAmount)/this.PRICE_PRECISION,tokenAllocation:Number(n.tokenAllocation)}};case"TokensClaimed":return{...t,args:{...n,roundId:Number(n.roundId),user:n.user.toLowerCase(),amount:Number(n.amount)}};case"ProjectTokenUpdated":return{...t,args:{...n,oldToken:n.oldToken.toLowerCase(),newToken:n.newToken.toLowerCase()}};case"ClaimingEnabledUpdated":case"RefundEnabledUpdated":return{...t,args:{...n,roundId:Number(n.roundId),enabled:n.enabled}};case"Refunded":return{...t,args:{...n,roundId:Number(n.roundId),user:n.user.toLowerCase(),token:n.token.toLowerCase(),amount:Number(n.amount)}};default:return t}};const a=Array.isArray(t)?t:[t];this.providers=a.map((t=>new e.ethers.JsonRpcProvider(t)));const s=(0,r.getRandomProvider)(this.providers);this.contractAddress=(0,r.resolveContractAddress)(a[0],this.name,o.default,i),this.contract=new e.ethers.Contract(this.contractAddress,n.default.abi,s),this.networkName=(0,r.getNetworkFromRpc)(a[0]),this.importWhitelistedTokens()}importWhitelistedTokens(){try{i.default[this.networkName]?(this.whitelistedTokensArray=i.default[this.networkName].map((t=>({name:t.name,address:t.address.toLowerCase(),decimals:t.decimals,symbol:t.symbol,icon:t.icon}))),console.log(`Imported ${this.whitelistedTokensArray.length} whitelisted tokens for ${this.networkName} network`)):console.log(`No whitelisted tokens found for ${this.networkName} network`)}catch(t){console.error("Error importing whitelisted tokens:",t)}}async getWhitelistedTokenInfo(t,e,n,o,r){const i=t.toLowerCase();if(!this.whitelistedTokensArray.some((t=>t.address===i)))return null;const a=await this.getWhitelistedToken(i);if(!a.isWhitelisted)return null;let s=0,d=0n;return r&&r.roundId>=0&&(d=r.maxFundPerAccountRaw*BigInt(10**this.PRICE_PRECISION)/a.priceRaw,s=r.maxFundPerAccount/a.price),{address:i,isWhitelisted:a.isWhitelisted,price:a.price,symbol:e,maxContribution:s,maxContributionRaw:d,decimals:n,icon:o}}async getAllWhitelistedTokensInfo(){const t=await this.getLatestRoundId();let e;if(t>=0){const n=await this.getRound(t);n.exists&&!n.ended&&(e={roundId:t,maxFundPerAccount:n.maxFundPerAccount,maxFundPerAccountRaw:n.maxFundPerAccountRaw})}const n=this.whitelistedTokensArray.map((t=>this.getWhitelistedTokenInfo(t.address,t.symbol,t.decimals,t.icon,e)));return(await Promise.all(n)).filter((t=>null!==t))}getRandomProvider(){return(0,r.getRandomProvider)(this.providers)}getContractWithRandomProvider(){return new e.ethers.Contract(this.contractAddress,n.default.abi,this.getRandomProvider())}async bootstrap(){if(this.isBootstrapped)return;const t=await Promise.all(this.providers.map(((t,e)=>(0,r.checkRpcHealth)(t,e))));if(this.providers=this.providers.filter(((e,n)=>t[n])),0===this.providers.length)throw new Error("No active RPC providers available");this.projectToken=await this.getProjectToken(),this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider()),this.isBootstrapped=!0}async signAndSendTransaction(t,e,n={}){return(0,r.signAndSendTransaction)(t,e,(()=>this.getRandomProvider()),n,this.contract)}async buildAddWhitelistedTokenTx(t,e){const n=BigInt(Math.floor(e*this.PRICE_PRECISION));return await this.contract.addWhitelistedToken.populateTransaction(t,n)}async buildUpdateTokenPriceTx(t,e){const n=BigInt(Math.floor(e*this.PRICE_PRECISION));return await this.contract.updateTokenPrice.populateTransaction(t,n)}async buildRemoveWhitelistedTokenTx(t){return await this.contract.removeWhitelistedToken.populateTransaction(t)}async buildCreateRoundTx(t,e,n,o,i){const a=BigInt(Math.floor(n*this.PRICE_PRECISION)),s=BigInt(Math.floor(i*this.PRICE_PRECISION)),d=await(0,r.getTokenDecimals)(await this.getProjectToken(),this.getRandomProvider()),c=BigInt(Math.floor(o*Math.pow(10,d)));return await this.contract.createRound.populateTransaction(t,e,a,c,s)}async buildUpdateRoundTx(t,e,n,o,i,a){const s=BigInt(Math.floor(o*this.PRICE_PRECISION)),d=BigInt(Math.floor(a*this.PRICE_PRECISION)),c=await(0,r.getTokenDecimals)(await this.getProjectToken(),this.getRandomProvider()),u=BigInt(Math.floor(i*Math.pow(10,c)));return await this.contract.updateRound.populateTransaction(t,e,n,s,u,d)}async buildEndRoundTx(t){return await this.contract.endRound.populateTransaction(t)}async buildSetClaimingEnabledTx(t,e){return await this.contract.setClaimingEnabled.populateTransaction(t,e)}async buildSetRefundEnabledTx(t,e){return await this.contract.setRefundEnabled.populateTransaction(t,e)}async buildContributeTx(t,n,o){let i=18;n!==e.ethers.ZeroAddress&&(i=await(0,r.getTokenDecimals)(n,this.getRandomProvider()));const a=e.ethers.parseUnits(o.toString(),i),s=await this.contract.contribute.populateTransaction(t,n,n===e.ethers.ZeroAddress?0:a);return n===e.ethers.ZeroAddress&&(s.value=a),s}async buildContributeTxRaw(t,n,o){const r=await this.contract.contribute.populateTransaction(t,n,n===e.ethers.ZeroAddress?0:o);return n===e.ethers.ZeroAddress&&(r.value=o),r}async buildWithdrawFundsTx(t,e){const n=await(0,r.getTokenDecimals)(t,this.getRandomProvider()),o=BigInt(Math.floor(e*Math.pow(10,n)));return await this.contract.withdrawFunds.populateTransaction(t,o)}async buildClaimTokensByRoundIdTx(t){return await this.contract.claimTokensByRoundId.populateTransaction(t)}async getWhitelistedToken(t){const e=await this.contract.whitelistedTokens(t);return{isWhitelisted:e.isWhitelisted,price:Number(e.price)/this.PRICE_PRECISION,priceRaw:e.price}}async getRound(t){const e=await this.contract.rounds(t);return this.projectToken||(this.projectToken=await this.getProjectToken()),this.projectTokenDecimals||(this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider())),{startTime:Number(e.startTime),endTime:Number(e.endTime),targetFund:Number(e.targetFund)/this.PRICE_PRECISION,totalAllocation:Number(e.totalAllocation)/10**this.projectTokenDecimals,maxFundPerAccount:Number(e.maxFundPerAccount)/this.PRICE_PRECISION,maxFundPerAccountRaw:e.maxFundPerAccount,exists:e.exists,ended:e.ended,claimingEnabled:e.claimingEnabled,refundEnabled:e.refundEnabled}}async getUserContribution(t,n){this.projectToken||(this.projectToken=await this.getProjectToken()),this.projectTokenDecimals||(this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider()));const o=await this.contract.userContributions(t,n);let i=18;return o.contributedToken!==e.ethers.ZeroAddress&&"0x0000000000000000000000000000000000000000"!==o.contributedToken&&(i=await(0,r.getTokenDecimals)(o.contributedToken,this.getRandomProvider())),{fundAmount:Number(o.fundAmount)/this.PRICE_PRECISION,tokenAllocation:Number(o.tokenAllocation)/10**this.projectTokenDecimals,claimed:o.claimed,refunded:o.refunded,contributedToken:o.contributedToken,contributedAmount:Number(o.contributedAmount)/10**i,contributedAmountRaw:o.contributedAmount}}async getRoundRaisedFunds(t){const e=await this.contract.roundRaisedFunds(t);return Number(e)/this.PRICE_PRECISION}async getRoundParticipants(t){const e=await this.contract.roundParticipants(t);return Number(e)}async getUserParticipatedRound(t){const e=await this.contract.userParticipatedRound(t);return Number(e)}async getProjectToken(){return await this.contract.projectToken()}async getTotalRounds(){const t=await this.contract.totalRounds();return Number(t)}async getTotalRaisedFunds(){const t=await this.contract.totalRaisedFunds();return Number(t)/this.PRICE_PRECISION}async isRoundActive(t){return await this.contract.isRoundActive(t)}async getLatestRoundId(){const t=await this.getTotalRounds();return 0===t?-1:t-1}async getRoundInfo(t){const e=await this.getTotalRounds();if(t<0||t>=e)throw new Error(`Invalid round ID: ${t}`);return{roundId:t,config:await this.getRound(t),raisedFunds:await this.getRoundRaisedFunds(t),participants:await this.getRoundParticipants(t),isActive:await this.isRoundActive(t)}}async getUserTotalContribution(t){const e=await this.contract.getUserTotalContribution(t);return{totalFundAmount:Number(e.totalFundAmount)/this.PRICE_PRECISION,totalTokenAllocation:Number(e.totalTokenAllocation)}}async getTransactionStatus(t,e=10){return await(0,r.getTransactionStatus)(this.getRandomProvider(),t,e)}getContractAddress(){return this.contractAddress}async getAllEvents(t,e){return await this.bootstrap(),(0,r.getAllEvents)(this.contract,(()=>this.getRandomProvider()),(()=>this.getContractWithRandomProvider()),t,e)}async streamEvents(t,e,n,o=1e3,i=5e3){return await this.bootstrap(),(0,r.streamEvents)({getProvider:()=>this.getRandomProvider(),getAllEvents:(t,e)=>this.getAllEvents(t,e),formatEvent:t=>this.formatEventArgs(t),onEvent:e,saveLatestBlock:n,fromBlock:t,batchSize:o,sleepTime:i})}async getUserRoundContribution(t,n){const[o,i]=await Promise.all([this.contract.getUserRoundContribution(t,n),this.contract.rounds(t)]),a=o.contributedToken!==e.ethers.ZeroAddress?await(0,r.getTokenDecimals)(o.contributedToken,this.getRandomProvider()):18,s={fundAmount:Number(o.fundAmount)/this.PRICE_PRECISION,tokenAllocation:Number(o.tokenAllocation),claimed:o.claimed,refunded:o.refunded,contributedToken:o.contributedToken,contributedAmount:Number(o.contributedAmount)/a,contributedAmountRaw:o.contributedAmount},d=Math.floor(Date.now()/1e3),c=i.exists&&!i.ended&&d>=Number(i.startTime)&&d<=Number(i.endTime),u={contribution:s,roundInfo:{exists:i.exists,isActive:c,claimingEnabled:i.claimingEnabled,refundEnabled:i.refundEnabled}};if(s.fundAmount>0){const t=s.contributedToken;let n="ETH",o=18;return t!==e.ethers.ZeroAddress&&([n,o]=await Promise.all([(0,r.getTokenSymbol)(t,this.getRandomProvider()),(0,r.getTokenDecimals)(t,this.getRandomProvider())])),{...u,tokenInfo:{symbol:n,decimals:o}}}return u}async buildTransferProjectTokenToContract(t){this.projectToken||(this.projectToken=await this.getProjectToken()),this.projectTokenDecimals||(this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider()));const n=new e.ethers.Interface(["function transfer(address to, uint256 amount) returns (bool)"]),o=e.ethers.parseUnits(t.toString(),this.projectTokenDecimals);return{to:this.projectToken,data:n.encodeFunctionData("transfer",[this.contractAddress,o])}}};
|
1
|
+
"use strict";var t=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SeedRoundFundraiserSDK=void 0;const e=require("ethers"),n=t(require("./abis/SeedRoundFundraiser.json")),o=t(require("./contracts.json")),r=require("./utils"),i=t(require("./whitelist-tokens.json"));exports.SeedRoundFundraiserSDK=class{constructor(t,i){this.name="SeedRoundFundraiser",this.isBootstrapped=!1,this.PRICE_PRECISION=1e18,this.whitelistedTokensArray=[],this.projectToken="",this.projectTokenDecimals=0,this.formatEventArgs=t=>{const{eventName:e,args:n}=t;switch(e){case"TokenWhitelisted":return{...t,args:{...n,token:n.token.toLowerCase(),price:Number(n.price)/this.PRICE_PRECISION}};case"TokenPriceUpdated":return{...t,args:{...n,token:n.token.toLowerCase(),oldPrice:Number(n.oldPrice)/this.PRICE_PRECISION,newPrice:Number(n.newPrice)/this.PRICE_PRECISION}};case"TokenRemovedFromWhitelist":return{...t,args:{...n,token:n.token.toLowerCase()}};case"RoundCreated":case"RoundUpdated":return{...t,args:{...n,roundId:Number(n.roundId),startTime:Number(n.startTime),endTime:Number(n.endTime),targetFund:Number(n.targetFund)/this.PRICE_PRECISION,totalAllocation:Number(n.totalAllocation),maxFundPerAccount:Number(n.maxFundPerAccount)/this.PRICE_PRECISION}};case"RoundEnded":return{...t,args:{...n,roundId:Number(n.roundId),raisedFunds:Number(n.raisedFunds)/this.PRICE_PRECISION,participants:Number(n.participants)}};case"Contribution":return{...t,args:{...n,roundId:Number(n.roundId),contributor:n.contributor.toLowerCase(),token:n.token.toLowerCase(),amount:Number(n.amount),fundAmount:Number(n.fundAmount)/this.PRICE_PRECISION,tokenAllocation:Number(n.tokenAllocation)}};case"TokensClaimed":return{...t,args:{...n,roundId:Number(n.roundId),user:n.user.toLowerCase(),amount:Number(n.amount)}};case"ProjectTokenUpdated":return{...t,args:{...n,oldToken:n.oldToken.toLowerCase(),newToken:n.newToken.toLowerCase()}};case"ClaimingEnabledUpdated":case"RefundEnabledUpdated":return{...t,args:{...n,roundId:Number(n.roundId),enabled:n.enabled}};case"Refunded":return{...t,args:{...n,roundId:Number(n.roundId),user:n.user.toLowerCase(),token:n.token.toLowerCase(),amount:Number(n.amount)}};default:return t}};const a=Array.isArray(t)?t:[t];this.providers=a.map((t=>new e.ethers.JsonRpcProvider(t)));const s=(0,r.getRandomProvider)(this.providers);this.contractAddress=(0,r.resolveContractAddress)(a[0],this.name,o.default,i),this.contract=new e.ethers.Contract(this.contractAddress,n.default.abi,s),this.networkName=(0,r.getNetworkFromRpc)(a[0]),this.importWhitelistedTokens()}importWhitelistedTokens(){try{i.default[this.networkName]?(this.whitelistedTokensArray=i.default[this.networkName].map((t=>({name:t.name,address:t.address.toLowerCase(),decimals:t.decimals,symbol:t.symbol,icon:t.icon}))),console.log(`Imported ${this.whitelistedTokensArray.length} whitelisted tokens for ${this.networkName} network`)):console.log(`No whitelisted tokens found for ${this.networkName} network`)}catch(t){console.error("Error importing whitelisted tokens:",t)}}async getWhitelistedTokenInfo(t,e,n,o,r){const i=t.toLowerCase();if(!this.whitelistedTokensArray.some((t=>t.address===i)))return null;const a=await this.getWhitelistedToken(i);if(!a.isWhitelisted)return null;let s=0,d=0n;return r&&r.roundId>=0&&(d=r.maxFundPerAccountRaw*BigInt(this.PRICE_PRECISION)/a.priceRaw,s=r.maxFundPerAccount/a.price),{address:i,isWhitelisted:a.isWhitelisted,price:a.price,symbol:e,maxContribution:s,maxContributionRaw:d,decimals:n,icon:o}}async getAllWhitelistedTokensInfo(){const t=await this.getLatestRoundId();let e;if(t>=0){const n=await this.getRound(t);n.exists&&!n.ended&&(e={roundId:t,maxFundPerAccount:n.maxFundPerAccount,maxFundPerAccountRaw:n.maxFundPerAccountRaw})}const n=this.whitelistedTokensArray.map((t=>this.getWhitelistedTokenInfo(t.address,t.symbol,t.decimals,t.icon,e)));return(await Promise.all(n)).filter((t=>null!==t))}getRandomProvider(){return(0,r.getRandomProvider)(this.providers)}getContractWithRandomProvider(){return new e.ethers.Contract(this.contractAddress,n.default.abi,this.getRandomProvider())}async bootstrap(){if(this.isBootstrapped)return;const t=await Promise.all(this.providers.map(((t,e)=>(0,r.checkRpcHealth)(t,e))));if(this.providers=this.providers.filter(((e,n)=>t[n])),0===this.providers.length)throw new Error("No active RPC providers available");this.projectToken=await this.getProjectToken(),this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider()),this.isBootstrapped=!0}async signAndSendTransaction(t,e,n={}){return(0,r.signAndSendTransaction)(t,e,(()=>this.getRandomProvider()),n,this.contract)}async buildAddWhitelistedTokenTx(t,e){const n=BigInt(Math.floor(e*this.PRICE_PRECISION));return await this.contract.addWhitelistedToken.populateTransaction(t,n)}async buildUpdateTokenPriceTx(t,e){const n=BigInt(Math.floor(e*this.PRICE_PRECISION));return await this.contract.updateTokenPrice.populateTransaction(t,n)}async buildRemoveWhitelistedTokenTx(t){return await this.contract.removeWhitelistedToken.populateTransaction(t)}async buildCreateRoundTx(t,e,n,o,i){const a=BigInt(Math.floor(n*this.PRICE_PRECISION)),s=BigInt(Math.floor(i*this.PRICE_PRECISION)),d=await(0,r.getTokenDecimals)(await this.getProjectToken(),this.getRandomProvider()),c=BigInt(Math.floor(o*Math.pow(10,d)));return await this.contract.createRound.populateTransaction(t,e,a,c,s)}async buildUpdateRoundTx(t,e,n,o,i,a){const s=BigInt(Math.floor(o*this.PRICE_PRECISION)),d=BigInt(Math.floor(a*this.PRICE_PRECISION)),c=await(0,r.getTokenDecimals)(await this.getProjectToken(),this.getRandomProvider()),u=BigInt(Math.floor(i*Math.pow(10,c)));return await this.contract.updateRound.populateTransaction(t,e,n,s,u,d)}async buildEndRoundTx(t){return await this.contract.endRound.populateTransaction(t)}async buildSetClaimingEnabledTx(t,e){return await this.contract.setClaimingEnabled.populateTransaction(t,e)}async buildSetRefundEnabledTx(t,e){return await this.contract.setRefundEnabled.populateTransaction(t,e)}async buildContributeTx(t,n,o){let i=18;n!==e.ethers.ZeroAddress&&(i=await(0,r.getTokenDecimals)(n,this.getRandomProvider()));const a=e.ethers.parseUnits(o.toString(),i),s=await this.contract.contribute.populateTransaction(t,n,n===e.ethers.ZeroAddress?0:a);return n===e.ethers.ZeroAddress&&(s.value=a),s}async buildContributeTxRaw(t,n,o){const r=await this.contract.contribute.populateTransaction(t,n,n===e.ethers.ZeroAddress?0:o);return n===e.ethers.ZeroAddress&&(r.value=o),r}async buildWithdrawFundsTx(t,e){const n=await(0,r.getTokenDecimals)(t,this.getRandomProvider()),o=BigInt(Math.floor(e*Math.pow(10,n)));return await this.contract.withdrawFunds.populateTransaction(t,o)}async buildClaimTokensByRoundIdTx(t){return await this.contract.claimTokensByRoundId.populateTransaction(t)}async getWhitelistedToken(t){const e=await this.contract.whitelistedTokens(t);return{isWhitelisted:e.isWhitelisted,price:Number(e.price)/this.PRICE_PRECISION,priceRaw:e.price}}async getRound(t){const e=await this.contract.rounds(t);return this.projectToken||(this.projectToken=await this.getProjectToken()),this.projectTokenDecimals||(this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider())),{startTime:Number(e.startTime),endTime:Number(e.endTime),targetFund:Number(e.targetFund)/this.PRICE_PRECISION,totalAllocation:Number(e.totalAllocation)/10**this.projectTokenDecimals,maxFundPerAccount:Number(e.maxFundPerAccount)/this.PRICE_PRECISION,maxFundPerAccountRaw:e.maxFundPerAccount,exists:e.exists,ended:e.ended,claimingEnabled:e.claimingEnabled,refundEnabled:e.refundEnabled}}async getUserContribution(t,n){this.projectToken||(this.projectToken=await this.getProjectToken()),this.projectTokenDecimals||(this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider()));const o=await this.contract.userContributions(t,n);let i=18;return o.contributedToken!==e.ethers.ZeroAddress&&"0x0000000000000000000000000000000000000000"!==o.contributedToken&&(i=await(0,r.getTokenDecimals)(o.contributedToken,this.getRandomProvider())),{fundAmount:Number(o.fundAmount)/this.PRICE_PRECISION,tokenAllocation:Number(o.tokenAllocation)/10**this.projectTokenDecimals,claimed:o.claimed,refunded:o.refunded,contributedToken:o.contributedToken,contributedAmount:Number(o.contributedAmount)/10**i,contributedAmountRaw:o.contributedAmount}}async getRoundRaisedFunds(t){const e=await this.contract.roundRaisedFunds(t);return Number(e)/this.PRICE_PRECISION}async getRoundParticipants(t){const e=await this.contract.roundParticipants(t);return Number(e)}async getUserParticipatedRound(t){const e=await this.contract.userParticipatedRound(t);return Number(e)}async getProjectToken(){return await this.contract.projectToken()}async getTotalRounds(){const t=await this.contract.totalRounds();return Number(t)}async getTotalRaisedFunds(){const t=await this.contract.totalRaisedFunds();return Number(t)/this.PRICE_PRECISION}async isRoundActive(t){return await this.contract.isRoundActive(t)}async getLatestRoundId(){const t=await this.getTotalRounds();return 0===t?-1:t-1}async getRoundInfo(t){const e=await this.getTotalRounds();if(t<0||t>=e)throw new Error(`Invalid round ID: ${t}`);return{roundId:t,config:await this.getRound(t),raisedFunds:await this.getRoundRaisedFunds(t),participants:await this.getRoundParticipants(t),isActive:await this.isRoundActive(t)}}async getUserTotalContribution(t){const e=await this.contract.getUserTotalContribution(t);return{totalFundAmount:Number(e.totalFundAmount)/this.PRICE_PRECISION,totalTokenAllocation:Number(e.totalTokenAllocation)}}async getTransactionStatus(t,e=10){return await(0,r.getTransactionStatus)(this.getRandomProvider(),t,e)}getContractAddress(){return this.contractAddress}async getAllEvents(t,e){return await this.bootstrap(),(0,r.getAllEvents)(this.contract,(()=>this.getRandomProvider()),(()=>this.getContractWithRandomProvider()),t,e)}async streamEvents(t,e,n,o=1e3,i=5e3){return await this.bootstrap(),(0,r.streamEvents)({getProvider:()=>this.getRandomProvider(),getAllEvents:(t,e)=>this.getAllEvents(t,e),formatEvent:t=>this.formatEventArgs(t),onEvent:e,saveLatestBlock:n,fromBlock:t,batchSize:o,sleepTime:i})}async getUserRoundContribution(t,n){const[o,i]=await Promise.all([this.contract.getUserRoundContribution(t,n),this.contract.rounds(t)]),a=o.contributedToken!==e.ethers.ZeroAddress?await(0,r.getTokenDecimals)(o.contributedToken,this.getRandomProvider()):18,s={fundAmount:Number(o.fundAmount)/this.PRICE_PRECISION,tokenAllocation:Number(o.tokenAllocation),claimed:o.claimed,refunded:o.refunded,contributedToken:o.contributedToken,contributedAmount:Number(o.contributedAmount)/a,contributedAmountRaw:o.contributedAmount},d=Math.floor(Date.now()/1e3),c=i.exists&&!i.ended&&d>=Number(i.startTime)&&d<=Number(i.endTime),u={contribution:s,roundInfo:{exists:i.exists,isActive:c,claimingEnabled:i.claimingEnabled,refundEnabled:i.refundEnabled}};if(s.fundAmount>0){const t=s.contributedToken;let n="ETH",o=18;return t!==e.ethers.ZeroAddress&&([n,o]=await Promise.all([(0,r.getTokenSymbol)(t,this.getRandomProvider()),(0,r.getTokenDecimals)(t,this.getRandomProvider())])),{...u,tokenInfo:{symbol:n,decimals:o}}}return u}async buildTransferProjectTokenToContract(t){this.projectToken||(this.projectToken=await this.getProjectToken()),this.projectTokenDecimals||(this.projectTokenDecimals=await(0,r.getTokenDecimals)(this.projectToken,this.getRandomProvider()));const n=new e.ethers.Interface(["function transfer(address to, uint256 amount) returns (bool)"]),o=e.ethers.parseUnits(t.toString(),this.projectTokenDecimals);return{to:this.projectToken,data:n.encodeFunctionData("transfer",[this.contractAddress,o])}}async hasAdminRole(t){const e=await this.contract.DEFAULT_ADMIN_ROLE();return await this.contract.hasRole(e,t)}async buildGrantAdminRoleTx(t){const e=await this.contract.DEFAULT_ADMIN_ROLE();return await this.contract.grantRole.populateTransaction(e,t)}async getAdminRoleHash(){return await this.contract.DEFAULT_ADMIN_ROLE()}};
|
@@ -27,6 +27,13 @@
|
|
27
27
|
"decimals": 18,
|
28
28
|
"symbol": "WETH",
|
29
29
|
"icon": "https://assets.coingecko.com/coins/images/2518/standard/weth.png?1696503332"
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"name": "USDC",
|
33
|
+
"address": "0xDd33fEeD5D44D9e89b69C8E9397292E0D6554a66",
|
34
|
+
"decimals": 6,
|
35
|
+
"symbol": "USDC",
|
36
|
+
"icon": "https://assets.coingecko.com/coins/images/6319/standard/usdc.png?1696506694"
|
30
37
|
}
|
31
38
|
]
|
32
39
|
}
|