diff --git a/contracts/CrowdPooling/impl/CPFunding.sol b/contracts/CrowdPooling/impl/CPFunding.sol index a09a59b..b15b4a2 100644 --- a/contracts/CrowdPooling/impl/CPFunding.sol +++ b/contracts/CrowdPooling/impl/CPFunding.sol @@ -16,6 +16,7 @@ import {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol"; import {IDVMFactory} from "../../Factory/DVMFactory.sol"; import {CPStorage} from "./CPStorage.sol"; import {PMMPricing} from "../../lib/PMMPricing.sol"; +import {IDODOCallee} from "../../intf/IDODOCallee.sol"; contract CPFunding is CPStorage { using SafeERC20 for IERC20; @@ -39,12 +40,17 @@ contract CPFunding is CPStorage { emit Bid(to, input, mtFee); } - function cancel(address assetTo, uint256 amount) external phaseBidOrCalm preventReentrant { + function cancel(address to, uint256 amount, bytes calldata data) external phaseBidOrCalm preventReentrant { require(_SHARES_[msg.sender] >= amount, "SHARES_NOT_ENOUGH"); _burnShares(msg.sender, amount); - _transferQuoteOut(assetTo, amount); + _transferQuoteOut(to, amount); _sync(); - emit Cancel(assetTo,amount); + + if(data.length > 0){ + IDODOCallee(to).CPCancelCall(msg.sender,amount,data); + } + + emit Cancel(msg.sender,amount); } function _mintShares(address to, uint256 amount) internal { diff --git a/contracts/SmartRoute/helper/DODOCalleeHelper.sol b/contracts/SmartRoute/helper/DODOCalleeHelper.sol index caac55c..f1a7522 100644 --- a/contracts/SmartRoute/helper/DODOCalleeHelper.sol +++ b/contracts/SmartRoute/helper/DODOCalleeHelper.sol @@ -1,5 +1,5 @@ /* - + Copyright 2020 DODO ZOO. SPDX-License-Identifier: Apache-2.0 @@ -43,6 +43,15 @@ contract DODOCalleeHelper is ReentrancyGuard { _withdraw(assetTo, _quoteToken, quoteAmount, _quoteToken == _WETH_); } + function CPCancelCall( + address payable assetTo, + uint256 amount, + bytes calldata + )external preventReentrant{ + address _quoteToken = IDODOV2(msg.sender)._QUOTE_TOKEN_(); + _withdraw(assetTo, _quoteToken, amount, _quoteToken == _WETH_); + } + function _withdraw( address payable to, address token, diff --git a/contracts/intf/IDODOCallee.sol b/contracts/intf/IDODOCallee.sol index d506c0c..0dd00a4 100644 --- a/contracts/intf/IDODOCallee.sol +++ b/contracts/intf/IDODOCallee.sol @@ -31,7 +31,7 @@ interface IDODOCallee { bytes calldata data ) external; - function CACancelCall( + function CPCancelCall( address sender, uint256 amount, bytes calldata data diff --git a/test/CrowdPooling/CPBid.test.ts b/test/CrowdPooling/CPBid.test.ts index 252c837..5743b47 100644 --- a/test/CrowdPooling/CPBid.test.ts +++ b/test/CrowdPooling/CPBid.test.ts @@ -41,6 +41,7 @@ describe("Funding", () => { freezeDuration: new BigNumber(86400), vestingDuration: new BigNumber(86400), cliffRate: decimalStr("1"), + quoteTokenContract:"" } ctx = new CPContext(); await ctx.init(config); @@ -57,7 +58,7 @@ describe("Funding", () => { describe("bid & cancel", () => { - it("bid", async () => { + it("bid and cancel", async () => { await ctx.QUOTE.methods.transfer(ctx.CP.options.address, decimalStr("100")).send(ctx.sendParam(bidder1)) await logGas(ctx.CP.methods.bid(bidder1), ctx.sendParam(bidder1), "bid") assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("99.9")) @@ -75,6 +76,7 @@ describe("Funding", () => { assert.equal(await ctx.CP.methods.getShares(bidder1).call(), decimalStr("79.9")) assert.equal(await ctx.CP.methods._TOTAL_SHARES_().call(), decimalStr("129.85")) assert.equal(await ctx.QUOTE.methods.balanceOf(bidder1).call(), decimalStr("920")) + }) }) diff --git a/test/utils/CrowdPoolingContext.ts b/test/utils/CrowdPoolingContext.ts index c8710a9..4be9af2 100644 --- a/test/utils/CrowdPoolingContext.ts +++ b/test/utils/CrowdPoolingContext.ts @@ -30,6 +30,7 @@ export interface CPContextInitConfig { freezeDuration: BigNumber; vestingDuration: BigNumber; cliffRate: string; + quoteTokenContract: string; } @@ -43,6 +44,7 @@ export class CPContext { Deployer: string; Maintainer: string; SpareAccounts: string[]; + DODOCallee: Contract; constructor() { } @@ -67,10 +69,18 @@ export class CPContext { contracts.MINTABLE_ERC20_CONTRACT_NAME, ["TestBase", "BASE", 18] ); - this.QUOTE = await contracts.newContract( - contracts.MINTABLE_ERC20_CONTRACT_NAME, - ["TestQuote", "QUOTE", 18] - ); + if(config.quoteTokenContract){ + this.QUOTE = await contracts.newContract( + config.quoteTokenContract, + ["TestQuote", "QUOTE", 18] + ); + }else{ + this.QUOTE = await contracts.newContract( + contracts.MINTABLE_ERC20_CONTRACT_NAME, + ["TestQuote", "QUOTE", 18] + ); + } + this.DODOCallee = await contracts.newContract(contracts.DODO_CALLEE_HELPER_NAME,[this.QUOTE.options.address]); this.DVMFactory = await contracts.newContract(contracts.DVM_FACTORY_NAME, [ diff --git a/test/utils/EVM.ts b/test/utils/EVM.ts index 75e071a..682d662 100644 --- a/test/utils/EVM.ts +++ b/test/utils/EVM.ts @@ -13,7 +13,7 @@ import Web3 from 'web3'; export function getDefaultWeb3() { return new Web3(process.env.RPC_NODE_URI) } - +process.env.RPC_NODE_URI="http://127.0.0.1:8545" export class EVM { private provider = new Web3.providers.HttpProvider(process.env.RPC_NODE_URI);