Skip to content

Commit 4f93e2d

Browse files
committed
Remove unused withdraw
1 parent 8833e38 commit 4f93e2d

File tree

2 files changed

+0
-97
lines changed

2 files changed

+0
-97
lines changed

contracts/ito.sol

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -460,36 +460,4 @@ contract HappyTokenPool is Initializable {
460460
pool.ratios[i*2+1] = 0;
461461
}
462462
}
463-
464-
/**
465-
* withdraw() transfers out a single token after a pool is expired or empty
466-
* id swap pool id
467-
* addr_i withdraw token index
468-
* this function can only be called by the pool creator. after validation, it transfers the addr_i th token
469-
* out to the pool creator address.
470-
**/
471-
472-
function withdraw (bytes32 id, uint256 addr_i) public {
473-
Pool storage pool = pool_by_id[id];
474-
require(msg.sender == pool.creator, "Only the pool creator can withdraw.");
475-
476-
uint256 withdraw_balance = pool.exchanged_tokens[addr_i];
477-
require(withdraw_balance > 0, "None of this token left");
478-
uint256 expiration = pool.packed3.end_time + base_time;
479-
uint256 remaining_tokens = pool.packed2.total_tokens;
480-
// only after expiration or the pool is empty
481-
require(expiration <= block.timestamp || remaining_tokens == 0, "Not expired yet");
482-
address token_address = pool.exchange_addrs[addr_i];
483-
484-
// clear the record
485-
pool.exchanged_tokens[addr_i] = 0;
486-
487-
// ERC20
488-
if (token_address != DEFAULT_ADDRESS)
489-
IERC20(token_address).safeTransfer(msg.sender, withdraw_balance);
490-
// ETH
491-
else
492-
payable(msg.sender).transfer(withdraw_balance);
493-
emit WithdrawSuccess(id, token_address, withdraw_balance);
494-
}
495463
}

test/TestTP.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,71 +1284,6 @@ describe('HappyTokenPool', () => {
12841284
});
12851285
});
12861286

1287-
describe('withdraw()', async () => {
1288-
beforeEach(async () => {
1289-
await testTokenADeployed.approve(happyTokenPoolDeployed.address, new BigNumber('1e27').toFixed());
1290-
});
1291-
1292-
it('Should emit WithdrawSuccess event and withdraw the specified token', async () => {
1293-
const fakeTime = (new Date().getTime() + 1000 * 1000) / 1000;
1294-
fpp.end_time = Math.ceil(fakeTime) - base_timestamp;
1295-
fpp.exchange_ratios = [1, 75000, 1, 100, 1, 100];
1296-
fpp.limit = BigNumber('50000e18').toFixed();
1297-
fpp.total_tokens = BigNumber('50000e18').toFixed();
1298-
const { id: pool_id } = await getResultFromPoolFill(happyTokenPoolDeployed, fpp);
1299-
1300-
const exchange_ETH_amount = BigNumber('3e14').toFixed();
1301-
1302-
const { verification, validation } = getVerification(PASSWORD, signers[2].address);
1303-
await happyTokenPoolDeployed
1304-
.connect(signers[2])
1305-
.swap(pool_id, verification, ETH_address_index, exchange_ETH_amount, [pool_id], {
1306-
value: exchange_ETH_amount,
1307-
});
1308-
1309-
const exchange_tokenB_amount = BigNumber('200e18').toFixed();
1310-
await approveThenSwapToken(
1311-
testTokenBDeployed,
1312-
signers[3],
1313-
tokenB_address_index,
1314-
pool_id,
1315-
exchange_tokenB_amount,
1316-
);
1317-
1318-
// "none-pool owner" can not withdraw
1319-
const account_not_creator = signers[4];
1320-
await expect(
1321-
happyTokenPoolDeployed.connect(account_not_creator).withdraw(pool_id, ETH_address_index),
1322-
).to.be.rejectedWith(Error);
1323-
1324-
await helper.advanceTimeAndBlock(2000 * 1000);
1325-
await happyTokenPoolDeployed.connect(creator).withdraw(pool_id, tokenB_address_index);
1326-
await happyTokenPoolDeployed.connect(creator).withdraw(pool_id, ETH_address_index);
1327-
1328-
// can not withdraw again
1329-
expect(happyTokenPoolDeployed.connect(creator).withdraw(pool_id, ETH_address_index)).to.be.rejectedWith(
1330-
Error,
1331-
);
1332-
expect(happyTokenPoolDeployed.connect(creator).withdraw(pool_id, tokenB_address_index)).to.be.rejectedWith(
1333-
Error,
1334-
);
1335-
1336-
const latestBlock = await ethers.provider.getBlockNumber();
1337-
const filter = happyTokenPoolDeployed.filters.WithdrawSuccess();
1338-
filter.fromBlock = latestBlock - 2;
1339-
filter.toBlock = latestBlock;
1340-
const logs = await ethers.provider.getLogs(filter);
1341-
1342-
let parsedLog = itoInterface.parseLog(logs[0]);
1343-
const logWithdrawTokenB = parsedLog.args;
1344-
parsedLog = itoInterface.parseLog(logs[1]);
1345-
const logWithdrawETH = parsedLog.args;
1346-
1347-
expect(logWithdrawTokenB.withdraw_balance.toString()).that.to.be.eq(BigNumber('200e18').toFixed());
1348-
expect(logWithdrawETH.withdraw_balance.toString()).that.to.be.eq(BigNumber('3e14').toFixed());
1349-
});
1350-
});
1351-
13521287
describe('smart contract upgrade', async () => {
13531288
let pool_user;
13541289
let verification;

0 commit comments

Comments
 (0)