Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should successfully close accrual period of given currencies', async () => {
await ethersRevenueFund1.closeAccrualPeriod(currencies, {gasLimit: 1e6});
(await ethersMockedAccrualBeneficiary99._closedAccrualPeriodsCount())
._bn.should.eq.BN(1);
(await ethersMockedAccrualBeneficiary01._closedAccrualPeriodsCount())
._bn.should.eq.BN(1);
(await provider.getBalance(ethersMockedAccrualBeneficiary99.address))
._bn.should.eq.BN(utils.parseEther('0.99')._bn);
(await provider.getBalance(ethersMockedAccrualBeneficiary01.address))
._bn.should.eq.BN(utils.parseEther('0.01')._bn);
(await ethersERC20.allowance(ethersRevenueFund1.address, ethersMockedAccrualBeneficiary99.address))
._bn.should.eq.BN(99);
(await ethersERC20.allowance(ethersRevenueFund1.address, ethersMockedAccrualBeneficiary01.address))
._bn.should.eq.BN(1);
});
});
it('should add on top of the first deposit', async () => {
await web3ClientFund.receiveEthersTo(
glob.user_a,
'',
{
from: glob.user_a,
value: web3.toWei(1, 'ether'),
gas: 1e6
}
);
(await ethersBalanceTracker.get(glob.user_a, depositedBalanceType, mocks.address0, 0))
._bn.should.eq.BN(utils.parseEther('2')._bn);
});
});
it('should successfully unstage', async () => {
await web3ClientFund.withdraw(
web3.toWei(0.2, 'ether'), mocks.address0, 0, '', {from: glob.user_a}
);
(await ethersBalanceTracker.get(glob.user_a, depositedBalanceType, mocks.address0, 0))
._bn.should.eq.BN(utils.parseEther('0.7')._bn);
(await ethersBalanceTracker.get(glob.user_a, settledBalanceType, mocks.address0, 0))
._bn.should.eq.BN(0);
(await ethersBalanceTracker.get(glob.user_a, stagedBalanceType, mocks.address0, 0))
._bn.should.eq.BN(utils.parseEther('0.1')._bn);
});
});
it('should revert', async () => {
ethersMockedClientFundAuthorizedService.updateSettledBalance(
glob.user_a, utils.parseEther('-1'), mocks.address0, 0, '', 0, {gasLimit: 1e6}
).should.be.rejected;
});
});
await web3TokenHolderRevenueFund.receiveEthersTo(
glob.user_a, '',
{
from: glob.user_a,
value: web3.toWei(1, 'ether'),
gas: 1e6
}
);
(await ethersTokenHolderRevenueFund.depositsCount())
._bn.should.eq.BN(2);
(await ethersTokenHolderRevenueFund.periodAccrualBalance(mocks.address0, 0))
._bn.should.eq.BN(utils.parseEther('2')._bn);
(await ethersTokenHolderRevenueFund.aggregateAccrualBalance(mocks.address0, 0))
._bn.should.eq.BN(utils.parseEther('2')._bn);
});
});
async function fundAddress({ recipient, signerAddress }: Args) {
console.log('Funding account from ' + signerAddress + ' to ' + recipient)
const provider = createProvider()
const signer = provider.getSigner(signerAddress)
const tx = await signer.sendTransaction({
to: recipient,
value: utils.parseEther('1000'),
})
const receipt = await tx.wait()
console.log(receipt)
}
async convertNominsToHavvens(inputAmount) {
inputAmount = this.cleanInput(inputAmount);
const fromAmount = utils.parseEther(inputAmount);
const [amountReceived, exchangeRate, havvenAmount] = await Promise.all([
this.getNominAmountReceived(fromAmount),
this.getNominToHavvenExchangeRate(),
this.getHavvensReceivedForNomins(fromAmount),
]);
const nominFeeAmount = fromAmount.sub(amountReceived);
return {
nominAmount: inputAmount,
exchangeRate,
havvenAmount,
nominFeeAmount,
};
}
export async function calculateGasEstimate(transaction: Object, network: string) {
const {
from,
amount,
symbol,
contractAddress,
decimals: defaultDecimals = 18,
tokenId,
} = transaction;
let { to, data } = transaction;
const provider = getEthereumProvider(network);
const value = symbol === ETH
? utils.parseEther(amount.toString())
: '0x';
if (tokenId) {
let contract;
const code = await provider.getCode(contractAddress);
const contractTransferMethod = getERC721ContractTransferMethod(code);
switch (contractTransferMethod) {
case 'safeTransferFrom':
contract = new Contract(contractAddress, ERC721_CONTRACT_ABI_SAFE_TRANSFER_FROM, provider);
({ data } = await contract.interface.functions.safeTransferFrom.apply(null, [from, to, tokenId]));
break;
case 'transfer':
contract = new Contract(contractAddress, ERC721_CONTRACT_ABI, provider);
({ data } = await contract.interface.functions.transfer.apply(null, [to, tokenId]));
break;
case 'transferFrom':
contract = new Contract(contractAddress, ERC721_CONTRACT_ABI_TRANSFER_FROM, provider);
async convertHavvensToEther(inputAmount) {
inputAmount = this.cleanInput(inputAmount);
const unit = utils.parseEther('1');
const fromAmount = utils.parseEther(inputAmount);
const [exchangeRate, transferFeeRate] = await Promise.all([
this.getEtherToHavvensExchangeRate(),
this.getNominTransferFeeRate(),
]);
const nominFeeAmount = fromAmount.mul(transferFeeRate).div(unit);
const amountIncludingFee = fromAmount.add(nominFeeAmount);
const reverseExchangeRate = unit.mul(unit).div(exchangeRate);
const etherAmount = amountIncludingFee.mul(reverseExchangeRate).div(unit);
return {
nominAmount: inputAmount,
exchangeRate,