Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add erc20 contest deployment helper #9517

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading