aiia-vault-sdk 1.1.17 → 1.1.18
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.
@@ -318,6 +318,26 @@ export declare class SeedRoundFundraiserSDK {
|
|
318
318
|
* @notice For ERC20 tokens, ensure you have approved the contract first
|
319
319
|
*/
|
320
320
|
buildContributeTx(roundId: number, token: string, amount: number): Promise<ethers.ContractTransaction>;
|
321
|
+
/**
|
322
|
+
* Builds a transaction to contribute to a round using raw token amounts
|
323
|
+
*
|
324
|
+
* @param roundId - The ID of the round to contribute to
|
325
|
+
* @param token - The token address (use ethers.ZeroAddress for ETH)
|
326
|
+
* @param amountRaw - Raw amount to contribute in smallest units (wei/atomic units)
|
327
|
+
* @returns Populated transaction
|
328
|
+
*
|
329
|
+
* @example
|
330
|
+
* ```typescript
|
331
|
+
* // Contribute 1.5 ETH in wei (1.5 * 10^18)
|
332
|
+
* const tx = await sdk.buildContributeTxRaw(0, ethers.ZeroAddress, ethers.parseEther("1.5"));
|
333
|
+
*
|
334
|
+
* // Contribute 1000 USDC in raw units (1000 * 10^6)
|
335
|
+
* const tx = await sdk.buildContributeTxRaw(0, "0x...", 1000000000n);
|
336
|
+
* ```
|
337
|
+
*
|
338
|
+
* @notice For ERC20 tokens, ensure you have approved the contract first
|
339
|
+
*/
|
340
|
+
buildContributeTxRaw(roundId: number, token: string, amountRaw: bigint): Promise<ethers.ContractTransaction>;
|
321
341
|
/**
|
322
342
|
* Builds a transaction to withdraw accumulated funds
|
323
343
|
*
|
@@ -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 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(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])}}};
|