Skip to content

Commit

Permalink
add erc20 contest deployment helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrowan committed Oct 10, 2024
1 parent 7f74305 commit 72c3aee
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionReceipt> {
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,
Expand Down

0 comments on commit 72c3aee

Please sign in to comment.