Skip to content

Instantly share code, notes, and snippets.

@e00dan
Created March 31, 2022 17:24
Show Gist options
  • Save e00dan/ceef086f56438e9c48d9ebcffec7d0c9 to your computer and use it in GitHub Desktop.
Save e00dan/ceef086f56438e9c48d9ebcffec7d0c9 to your computer and use it in GitHub Desktop.
import BigNumber from 'bignumber.js/bignumber';
import abiLibrary from 'lib/abi';
const daoAddress = process.env.DAO_ADDRESS || '';
const tributeToken = process.env.TRIBUTE_TOKEN_ADDRESS;
const paymentToken = process.env.TRIBUTE_TOKEN_ADDRESS;
const getDao = async (address: string) => {
const dao = await new web3.eth.Contract(abiLibrary.moloch2, address);
return dao;
};
const getReceipt = async (proposal: any, user: string, estimatedGas: number) => {
let receipt;
try {
receipt = await proposal.send({ from: user, gas: estimatedGas }).on('receipt', (receipt: any) => {
return receipt;
});
} catch (err) {
receipt = err;
}
return receipt;
};
const useCreateProposal = async (
user: string,
applicantAddress: string,
sharesRequested: number,
lootRequested: number,
tributeOffered: BigNumber.Value,
paymentRequested: BigNumber.Value,
details: { title: any; description: any; link: any },
) => {
const exponentialValue = new BigNumber(10 ** 8);
const tributeOfferedToExponential = new BigNumber(tributeOffered).multipliedBy(exponentialValue);
const paymentRequestedToExponential = new BigNumber(paymentRequested).multipliedBy(exponentialValue);
const dao = await getDao(daoAddress);
const token = new web3.eth.Contract(abiLibrary.erc20, '0x884541623C1B26A926a5320615F117113765fF81');
console.log('token whitelist', {
a: await dao.methods.tokenWhitelist('0x884541623C1B26A926a5320615F117113765fF81').call(),
daoAddress,
existingApproval: await token.methods.allowance(user, daoAddress).call()
});
const approveTx = await token.methods.approve(daoAddress, tributeOfferedToExponential).send({
gasLimit: 6000000,
gasPrice: 0,
from: user
});
console.log({
approveTx
});
console.log('submitProposal', {
applicantAddress,
sharesRequested,
lootRequested,
tributeOfferedToExponential,
tributeToken,
paymentRequestedToExponential,
paymentToken,
});
const proposal = await dao.methods.submitProposal(
applicantAddress,
sharesRequested,
lootRequested,
tributeOfferedToExponential,
tributeToken,
paymentRequestedToExponential,
paymentToken,
`{"title": "${details.title}", "description": "${details.description}", "link": "${details.link}"}`,
);
const estimatedGas = 6000000;
const receipt = await getReceipt(proposal, user, estimatedGas);
console.log(receipt);
return receipt;
};
export default useCreateProposal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment