diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/NamespaceFactoryAbi.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/NamespaceFactoryAbi.ts index 4314661c8d0..1504b0e381f 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/NamespaceFactoryAbi.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/NamespaceFactoryAbi.ts @@ -1,4 +1,18 @@ export const namespaceFactoryAbi = [ + { + type: 'function', + name: 'newSingleERC20Contest', + inputs: [ + { name: 'name', type: 'string', internalType: 'string' }, + { name: 'length', type: 'uint256', internalType: 'uint256' }, + { name: 'winnerShares', type: 'uint256[]', internalType: 'uint256[]' }, + { name: 'token', type: 'address', internalType: 'address' }, + { name: 'voterShare', type: 'uint256', internalType: 'uint256' }, + { name: 'exhangeToken', type: 'address', internalType: 'address' }, + ], + outputs: [{ name: '', type: 'address', internalType: 'address' }], + stateMutability: 'nonpayable', + }, { inputs: [], stateMutability: 'view', diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Contest.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Contest.ts index e8dbde5dd8f..b147405b80e 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Contest.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Contest.ts @@ -130,6 +130,43 @@ class Contest extends ContractBase { } } + async newSingleERC20Contest( + namespaceName: string, + contestInterval: number, + winnerShares: number[], + voteToken: string, + voterShare: number, + walletAddress: string, + exchangeToken: string, + ): Promise { + if (!this.initialized || !this.walletEnabled) { + await this.initialize(true); + } + + try { + const txReceipt = await this.namespaceFactory.newERC20Contest( + namespaceName, + contestInterval, + winnerShares, + voteToken, + voterShare, + walletAddress, + exchangeToken, + ); + // @ts-expect-error StrictNullChecks + const eventLog = txReceipt.logs.find((log) => log.topics[0] == TOPIC_LOG); + const newContestAddress = this.web3.eth.abi.decodeParameters( + ['address', 'address', 'uint256', 'bool'], + // @ts-expect-error StrictNullChecks + eventLog.data.toString(), + )['0'] as string; + this.contractAddress = newContestAddress; + return newContestAddress; + } catch (error) { + throw new Error('Failed to initialize contest ' + error); + } + } + /** * Allows for deposit of contest token(ETH or ERC20) to contest * @param amount amount in ether to send to contest diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/NamespaceFactory.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/NamespaceFactory.ts index b42006c9949..8b1ae39aa8f 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/NamespaceFactory.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/NamespaceFactory.ts @@ -218,6 +218,42 @@ class NamespaceFactory extends ContractBase { return txReceipt; } + async newERC20Contest( + namespaceName: string, + contestInterval: number, + winnerShares: number[], + voteToken: string, + voterShare: number, + walletAddress: string, + exchangeToken: string, + ): Promise { + if (!this.initialized || !this.walletEnabled) { + await this.initialize(true); + } + const maxFeePerGasEst = await this.estimateGas(); + let txReceipt; + try { + txReceipt = await this.contract.methods + .newSingleERC20Contest( + namespaceName, + contestInterval, + winnerShares, + voteToken, + voterShare, + exchangeToken, + ) + .send({ + from: walletAddress, + type: '0x2', + maxFeePerGas: maxFeePerGasEst?.toString(), + maxPriorityFeePerGas: this.web3.utils.toWei('0.001', 'gwei'), + }); + } catch { + throw new Error('Transaction failed'); + } + return txReceipt; + } + async getFeeManagerBalance( namespace: string, token?: string,