diff --git a/.solcover.js b/.solcover.js index 93f4590c4..5b02ac4af 100644 --- a/.solcover.js +++ b/.solcover.js @@ -9,6 +9,6 @@ module.exports = { 'mocks', 'external', // https://github.com/sc-forks/solidity-coverage/blob/master/docs/faq.md#why-are-send-and-transfer-throwing - 'supplementary/PayableExchangeIssuance.sol' // Transfer functions cannot be properly tested. See link above. + 'supplementary/RebalancingSetExchangeIssuanceModule.sol' // Transfer functions cannot be properly tested. See link above. ], }; diff --git a/artifacts/index.ts b/artifacts/index.ts index 1ea6cf5d9..e576b763f 100644 --- a/artifacts/index.ts +++ b/artifacts/index.ts @@ -15,7 +15,7 @@ import { LinearAuctionPriceCurve } from "./ts/LinearAuctionPriceCurve"; import { Median } from "./ts/Median"; import { NoDecimalTokenMock } from "./ts/NoDecimalTokenMock"; import { NoXferReturnTokenMock } from "./ts/NoXferReturnTokenMock"; -import { PayableExchangeIssuance } from "./ts/PayableExchangeIssuance"; +import { RebalancingSetExchangeIssuanceModule } from "./ts/RebalancingSetExchangeIssuanceModule"; import { RebalanceAuctionModule } from "./ts/RebalanceAuctionModule"; import { RebalancingHelperLibrary } from "./ts/RebalancingHelperLibrary"; import { RebalancingSetToken } from "./ts/RebalancingSetToken"; @@ -62,7 +62,7 @@ export { MedianContract, NoDecimalTokenMockContract, NoXferReturnTokenMockContract, - PayableExchangeIssuanceContract, + RebalancingSetExchangeIssuanceModuleContract, RebalanceAuctionModuleContract, RebalancingSetTokenContract, RebalancingSetTokenFactoryContract, @@ -100,7 +100,7 @@ export { Median, NoDecimalTokenMock, NoXferReturnTokenMock, - PayableExchangeIssuance, + RebalancingSetExchangeIssuanceModule, RebalanceAuctionModule, RebalancingHelperLibrary, RebalancingSetToken, diff --git a/contracts/supplementary/PayableExchangeIssuance.sol b/contracts/supplementary/RebalancingSetExchangeIssuanceModule.sol similarity index 93% rename from contracts/supplementary/PayableExchangeIssuance.sol rename to contracts/supplementary/RebalancingSetExchangeIssuanceModule.sol index f9402c60a..b8824012e 100644 --- a/contracts/supplementary/PayableExchangeIssuance.sol +++ b/contracts/supplementary/RebalancingSetExchangeIssuanceModule.sol @@ -32,13 +32,13 @@ import { IWETH } from "../lib/IWETH.sol"; /** - * @title PayableExchangeIssuance + * @title RebalancingSetExchangeIssuanceModule * @author Set Protocol * - * The PayableExchangeIssuance supplementary smart contract allows a user to send Eth and atomically + * The RebalancingSetExchangeIssuanceModule supplementary smart contract allows a user to send Eth and atomically * issue a rebalancing Set */ -contract PayableExchangeIssuance is +contract RebalancingSetExchangeIssuanceModule is ReentrancyGuard { using SafeMath for uint256; @@ -77,7 +77,7 @@ contract PayableExchangeIssuance is /* ============ Constructor ============ */ /** - * Constructor function for PayableExchangeIssuance + * Constructor function for RebalancingSetExchangeIssuanceModule * * @param _core The address of Core * @param _transferProxy The address of the TransferProxy @@ -125,7 +125,7 @@ contract PayableExchangeIssuance is { require( // coverage-disable-line msg.sender == weth, - "PayableExchangeIssuance.fallback: Cannot receive ETH directly unless unwrapping WETH" + "RebalancingSetExchangeIssuanceModule.fallback: Cannot receive ETH directly unless unwrapping WETH" ); } @@ -239,6 +239,9 @@ contract PayableExchangeIssuance is _orderData ); + // Loops through base set components and withdrawTo user if postive quantity + + // Withdraw eth from WETH uint256 wethBalance = ERC20Wrapper.balanceOf( weth, @@ -338,13 +341,13 @@ contract PayableExchangeIssuance is // Require only 1 receive token require( _exchangeIssuanceParams.receiveTokens.length == 1, - "PayableExchangeIssuance.validateRedeemInputs: Only 1 Receive Token Allowed" + "RebalancingSetExchangeIssuanceModule.validateRedeemInputs: Only 1 Receive Token Allowed" ); // Require receive token is weth require( weth == _exchangeIssuanceParams.receiveTokens[0], - "PayableExchangeIssuance.validateRedeemInputs: Receive token must be Weth" + "RebalancingSetExchangeIssuanceModule.validateRedeemInputs: Receive token must be Weth" ); ISetToken rebalancingSet = ISetToken(_rebalancingSetAddress); @@ -353,7 +356,7 @@ contract PayableExchangeIssuance is address baseSet = rebalancingSet.getComponents()[0]; require( baseSet == _exchangeIssuanceParams.setAddress, - "PayableExchangeIssuance.validateRedeemInputs: Base Set addresses must match" + "RebalancingSetExchangeIssuanceModule.validateRedeemInputs: Base Set addresses must match" ); // Quantity of base Set must be the same as in exchange issuance params @@ -364,7 +367,7 @@ contract PayableExchangeIssuance is .div(rebalancingSetNaturalUnit); require( impliedBaseSetQuantity == _exchangeIssuanceParams.quantity, - "PayableExchangeIssuance.validateRedeemInputs: Base Set quantities must match" + "RebalancingSetExchangeIssuanceModule.validateRedeemInputs: Base Set quantities must match" ); } } diff --git a/deployments/stages/3_modules.ts b/deployments/stages/3_modules.ts index 0c8c238ce..623cb001d 100755 --- a/deployments/stages/3_modules.ts +++ b/deployments/stages/3_modules.ts @@ -7,7 +7,7 @@ import { ExchangeIssuanceModuleContract, KyberNetworkWrapperContract, LinearAuctionPriceCurveContract, - PayableExchangeIssuanceContract, + RebalancingSetExchangeIssuanceModuleContract, RebalanceAuctionModuleContract, RebalancingTokenIssuanceModuleContract, ZeroExExchangeWrapperContract, @@ -19,7 +19,7 @@ import { ERC20Wrapper } from '../../artifacts/ts/ERC20Wrapper'; import { ExchangeIssuanceModule } from '../../artifacts/ts/ExchangeIssuanceModule'; import { KyberNetworkWrapper } from '../../artifacts/ts/KyberNetworkWrapper'; import { LinearAuctionPriceCurve } from '../../artifacts/ts/LinearAuctionPriceCurve'; -import { PayableExchangeIssuance } from '../../artifacts/ts/PayableExchangeIssuance'; +import { RebalancingSetExchangeIssuanceModule } from '../../artifacts/ts/RebalancingSetExchangeIssuanceModule'; import { RebalanceAuctionModule } from '../../artifacts/ts/RebalanceAuctionModule'; import { RebalancingTokenIssuanceModule } from '../../artifacts/ts/RebalancingTokenIssuanceModule'; import { SetTokenLibrary } from '../../artifacts/ts/SetTokenLibrary'; @@ -53,7 +53,7 @@ export class ModulesStage implements DeploymentStageInterface { await this.deployLinearAuctionPriceCurve(); - await this.deployPayableExchangeIssuance(); + await this.deployRebalancingSetExchangeIssuanceModule(); } private async deployExchangeIssuanceModule(): Promise { @@ -131,12 +131,13 @@ export class ModulesStage implements DeploymentStageInterface { return await RebalancingTokenIssuanceModuleContract.at(address, this._web3, TX_DEFAULTS); } - private async deployPayableExchangeIssuance(): Promise { - const name = PayableExchangeIssuance.contractName; + private async deployRebalancingSetExchangeIssuanceModule(): + Promise { + const name = RebalancingSetExchangeIssuanceModule.contractName; let address = await getContractAddress(name); if (address) { - return await PayableExchangeIssuanceContract.at(address, this._web3, TX_DEFAULTS); + return await RebalancingSetExchangeIssuanceModuleContract.at(address, this._web3, TX_DEFAULTS); } const coreAddress = await getContractAddress(Core.contractName); @@ -145,12 +146,12 @@ export class ModulesStage implements DeploymentStageInterface { const erc20WrapperAddress = await getContractAddress(ERC20Wrapper.contractName); const wethAddress = await findDependency(DEPENDENCY.WETH); - const originalByteCode = PayableExchangeIssuance.bytecode; + const originalByteCode = RebalancingSetExchangeIssuanceModule.bytecode; const linkedByteCode = linkLibraries([ { name: ERC20Wrapper.contractName, address: erc20WrapperAddress }, ], originalByteCode); - const data = new this._web3.eth.Contract(PayableExchangeIssuance.abi).deploy({ + const data = new this._web3.eth.Contract(RebalancingSetExchangeIssuanceModule.abi).deploy({ data: linkedByteCode, arguments: [ coreAddress, @@ -161,7 +162,7 @@ export class ModulesStage implements DeploymentStageInterface { }).encodeABI(); address = await deployContract(data, this._web3, name); - return await PayableExchangeIssuanceContract.at(address, this._web3, TX_DEFAULTS); + return await RebalancingSetExchangeIssuanceModuleContract.at(address, this._web3, TX_DEFAULTS); } private async deployKyberWrapper(): Promise { diff --git a/deployments/test/3_modules.spec.ts b/deployments/test/3_modules.spec.ts index dd2da0fe7..b2b9621c4 100755 --- a/deployments/test/3_modules.spec.ts +++ b/deployments/test/3_modules.spec.ts @@ -15,7 +15,7 @@ import { Core } from '../../artifacts/ts/Core'; import { ExchangeIssuanceModule } from '../../artifacts/ts/ExchangeIssuanceModule'; import { KyberNetworkWrapper } from '../../artifacts/ts/KyberNetworkWrapper'; import { LinearAuctionPriceCurve } from '../../artifacts/ts/LinearAuctionPriceCurve'; -import { PayableExchangeIssuance } from '../../artifacts/ts/PayableExchangeIssuance'; +import { RebalancingSetExchangeIssuanceModule } from '../../artifacts/ts/RebalancingSetExchangeIssuanceModule'; import { RebalanceAuctionModule } from '../../artifacts/ts/RebalanceAuctionModule'; import { RebalancingTokenIssuanceModule } from '../../artifacts/ts/RebalancingTokenIssuanceModule'; import { ZeroExExchangeWrapper } from '../../artifacts/ts/ZeroExExchangeWrapper'; @@ -118,7 +118,10 @@ describe('Deployment: Modules', () => { before(async () => { const rebalanceAuctionAddress = await getContractAddress(RebalancingTokenIssuanceModule.contractName); - rebalanceTokenIssuanceModule = new web3.eth.Contract(RebalancingTokenIssuanceModule.abi, rebalanceAuctionAddress); + rebalanceTokenIssuanceModule = new web3.eth.Contract( + RebalancingTokenIssuanceModule.abi, + rebalanceAuctionAddress, + ); }); it('finds a valid contract at the address', async () => { @@ -230,7 +233,7 @@ describe('Deployment: Modules', () => { describe('Payable Exchange', () => { /** - * Check if the PayableExchangeIssuance has been deployed with: + * Check if the RebalancingSetExchangeIssuanceModule has been deployed with: * - Core * - TransferProxy * - ExchangeIssuanceModule @@ -240,12 +243,15 @@ describe('Deployment: Modules', () => { let payableExchangeWrapper; before(async () => { - const payableExchangeAddress = await getContractAddress(PayableExchangeIssuance.contractName); - payableExchangeWrapper = new web3.eth.Contract(PayableExchangeIssuance.abi, payableExchangeAddress); + const payableExchangeAddress = await getContractAddress(RebalancingSetExchangeIssuanceModule.contractName); + payableExchangeWrapper = new web3.eth.Contract( + RebalancingSetExchangeIssuanceModule.abi, + payableExchangeAddress, + ); }); it('finds a valid contract at the address', async () => { - const code = await getContractCode(PayableExchangeIssuance.contractName, web3); + const code = await getContractCode(RebalancingSetExchangeIssuanceModule.contractName, web3); expect(code.length).toBeGreaterThan(3); }); diff --git a/test/contracts/supplementary/payableExchangeIssuance.spec.ts b/test/contracts/supplementary/rebalancingSetExchangeIssuanceModule.spec.ts similarity index 96% rename from test/contracts/supplementary/payableExchangeIssuance.spec.ts rename to test/contracts/supplementary/rebalancingSetExchangeIssuanceModule.spec.ts index 2bfde381f..48ca54110 100644 --- a/test/contracts/supplementary/payableExchangeIssuance.spec.ts +++ b/test/contracts/supplementary/rebalancingSetExchangeIssuanceModule.spec.ts @@ -11,7 +11,7 @@ import { BigNumberSetup } from '@utils/bigNumberSetup'; import { CoreContract, ExchangeIssuanceModuleContract, - PayableExchangeIssuanceContract, + RebalancingSetExchangeIssuanceModuleContract, RebalancingSetTokenContract, RebalancingSetTokenFactoryContract, SetTokenContract, @@ -26,7 +26,7 @@ import { ether } from '@utils/units'; import { LogPayableExchangeIssue, LogPayableExchangeRedeem, -} from '@utils/contract_logs/payableExchangeIssuance'; +} from '@utils/contract_logs/rebalancingSetExchangeIssuanceModule'; import { expectRevertError } from '@utils/tokenAssertions'; import { getWeb3, getGasUsageInEth } from '@utils/web3Helper'; import { @@ -46,14 +46,14 @@ const web3 = getWeb3(); const { expect } = chai; const blockchain = new Blockchain(web3); const Core = artifacts.require('Core'); -const PayableExchangeIssuance = artifacts.require('PayableExchangeIssuance'); +const RebalancingSetExchangeIssuanceModule = artifacts.require('RebalancingSetExchangeIssuanceModule'); const { SetProtocolTestUtils: SetTestUtils, SetProtocolUtils: SetUtils } = setProtocolUtils; const setTestUtils = new SetTestUtils(web3); const setUtils = new SetUtils(web3); const { NULL_ADDRESS, ZERO } = SetUtils.CONSTANTS; -contract('PayableExchangeIssuance', accounts => { +contract('RebalancingSetExchangeIssuanceModule', accounts => { const [ ownerAccount, tokenPurchaser, @@ -67,7 +67,7 @@ contract('PayableExchangeIssuance', accounts => { let vault: VaultContract; let rebalancingSetTokenFactory: RebalancingSetTokenFactoryContract; let setTokenFactory: SetTokenFactoryContract; - let payableExchangeIssuance: PayableExchangeIssuanceContract; + let payableExchangeIssuance: RebalancingSetExchangeIssuanceModuleContract; let weth: WethMockContract; const coreWrapper = new CoreWrapper(ownerAccount, ownerAccount); @@ -82,7 +82,7 @@ contract('PayableExchangeIssuance', accounts => { before(async () => { ABIDecoder.addABI(Core.abi); - ABIDecoder.addABI(PayableExchangeIssuance.abi); + ABIDecoder.addABI(RebalancingSetExchangeIssuanceModule.abi); transferProxy = await coreWrapper.deployTransferProxyAsync(); vault = await coreWrapper.deployVaultAsync(); @@ -100,7 +100,7 @@ contract('PayableExchangeIssuance', accounts => { weth = await erc20Wrapper.deployWrappedEtherAsync(ownerAccount); - payableExchangeIssuance = await coreWrapper.deployPayableExchangeIssuanceAsync( + payableExchangeIssuance = await coreWrapper.deployRebalancingSetExchangeIssuanceModuleAsync( core.address, transferProxy.address, exchangeIssuanceModule.address, @@ -118,7 +118,7 @@ contract('PayableExchangeIssuance', accounts => { after(async () => { ABIDecoder.removeABI(Core.abi); - ABIDecoder.removeABI(PayableExchangeIssuance.abi); + ABIDecoder.removeABI(RebalancingSetExchangeIssuanceModule.abi); }); beforeEach(async () => { @@ -132,8 +132,8 @@ contract('PayableExchangeIssuance', accounts => { describe('#constructor', async () => { const subjectCaller: Address = ownerAccount; - async function subject(): Promise { - return await coreWrapper.deployPayableExchangeIssuanceAsync( + async function subject(): Promise { + return await coreWrapper.deployRebalancingSetExchangeIssuanceModuleAsync( core.address, transferProxy.address, exchangeIssuanceModule.address, @@ -506,7 +506,7 @@ contract('PayableExchangeIssuance', accounts => { { from: subjectCaller } ); - // Approve base component to PayableExchangeIssuance contract + // Approve base component to RebalancingSetExchangeIssuanceModule contract await erc20Wrapper.approveTransfersAsync( [rebalancingSetToken], payableExchangeIssuance.address, diff --git a/test/scenarios/payable-exchange-issuance/payableExchangeIssuanceScenarios.spec.ts b/test/scenarios/payable-exchange-issuance/payableExchangeIssuanceScenarios.spec.ts index c04c8d976..6e7f91de3 100644 --- a/test/scenarios/payable-exchange-issuance/payableExchangeIssuanceScenarios.spec.ts +++ b/test/scenarios/payable-exchange-issuance/payableExchangeIssuanceScenarios.spec.ts @@ -10,7 +10,7 @@ import ChaiSetup from '@utils/chaiSetup'; import { BigNumberSetup } from '@utils/bigNumberSetup'; import { CoreContract, - PayableExchangeIssuanceContract, + RebalancingSetExchangeIssuanceModuleContract, RebalancingSetTokenContract, RebalancingSetTokenFactoryContract, SetTokenContract, @@ -51,7 +51,7 @@ contract('PayableExchangeIssuance::Scenarios', accounts => { let core: CoreContract; let rebalancingSetTokenFactory: RebalancingSetTokenFactoryContract; let setTokenFactory: SetTokenFactoryContract; - let payableExchangeIssuance: PayableExchangeIssuanceContract; + let payableExchangeIssuance: RebalancingSetExchangeIssuanceModuleContract; let weth: WethMockContract; const coreWrapper = new CoreWrapper(ownerAccount, ownerAccount); @@ -72,7 +72,7 @@ contract('PayableExchangeIssuance::Scenarios', accounts => { rebalancingSetTokenFactory = await coreWrapper.getDeployedRebalancingSetTokenFactoryAsync(); weth = await erc20Wrapper.getDeployedWETHAsync(); - payableExchangeIssuance = await coreWrapper.getDeployedPayableExchangeIssuanceModuleAsync(); + payableExchangeIssuance = await coreWrapper.getDeployedRebalancingSetExchangeIssuanceModuleAsync(); }); after(async () => { diff --git a/utils/contract_logs/payableExchangeIssuance.ts b/utils/contract_logs/rebalancingSetExchangeIssuanceModule.ts similarity index 100% rename from utils/contract_logs/payableExchangeIssuance.ts rename to utils/contract_logs/rebalancingSetExchangeIssuanceModule.ts diff --git a/utils/contracts.ts b/utils/contracts.ts index a90bc7c90..a0a5dc68f 100644 --- a/utils/contracts.ts +++ b/utils/contracts.ts @@ -27,7 +27,9 @@ import { LinearAuctionPriceCurveContract } from '../types/generated/linear_aucti import { MedianContract } from '../types/generated/median'; import { NoDecimalTokenMockContract } from '../types/generated/no_decimal_token_mock'; import { NoXferReturnTokenMockContract } from '../types/generated/no_xfer_return_token_mock'; -import { PayableExchangeIssuanceContract } from '../types/generated/payable_exchange_issuance'; +import { + RebalancingSetExchangeIssuanceModuleContract +} from '../types/generated/rebalancing_set_exchange_issuance_module'; import { PriceFeedContract } from '../types/generated/price_feed'; import { RebalanceAuctionModuleContract } from '../types/generated/rebalance_auction_module'; import { RebalanceAuctionModuleMockContract } from '../types/generated/rebalance_auction_module_mock'; @@ -86,7 +88,7 @@ export { MedianContract, NoDecimalTokenMockContract, NoXferReturnTokenMockContract, - PayableExchangeIssuanceContract, + RebalancingSetExchangeIssuanceModuleContract, PriceFeedContract, RebalanceAuctionModuleContract, RebalanceAuctionModuleMockContract, diff --git a/utils/wrappers/coreWrapper.ts b/utils/wrappers/coreWrapper.ts index 6df0d91ef..e33f65ca1 100644 --- a/utils/wrappers/coreWrapper.ts +++ b/utils/wrappers/coreWrapper.ts @@ -7,7 +7,7 @@ import { CoreContract, CoreMockContract, ExchangeIssuanceModuleContract, - PayableExchangeIssuanceContract, + RebalancingSetExchangeIssuanceModuleContract, RebalanceAuctionModuleContract, RebalanceAuctionModuleMockContract, RebalancingSetTokenContract, @@ -41,7 +41,7 @@ const CoreIssuanceLibrary = artifacts.require('CoreIssuanceLibrary'); const CoreMock = artifacts.require('CoreMock'); const ERC20Wrapper = artifacts.require('ERC20Wrapper'); const ExchangeIssuanceModule = artifacts.require('ExchangeIssuanceModule'); -const PayableExchangeIssuance = artifacts.require('PayableExchangeIssuance'); +const RebalancingSetExchangeIssuanceModule = artifacts.require('RebalancingSetExchangeIssuanceModule'); const RebalanceAuctionModule = artifacts.require('RebalanceAuctionModule'); const RebalanceAuctionModuleMock = artifacts.require('RebalanceAuctionModuleMock'); const RebalancingHelperLibrary = artifacts.require('RebalancingHelperLibrary'); @@ -130,10 +130,11 @@ export class CoreWrapper { return await RebalanceAuctionModuleContract.at(address, web3, TX_DEFAULTS); } - public async getDeployedPayableExchangeIssuanceModuleAsync(): Promise { - const address = await getContractAddress(PayableExchangeIssuance.contractName); + public async getDeployedRebalancingSetExchangeIssuanceModuleAsync(): + Promise { + const address = await getContractAddress(RebalancingSetExchangeIssuanceModule.contractName); - return await PayableExchangeIssuanceContract.at(address, web3, TX_DEFAULTS); + return await RebalancingSetExchangeIssuanceModuleContract.at(address, web3, TX_DEFAULTS); } /* ============ Deployment ============ */ @@ -499,20 +500,20 @@ export class CoreWrapper { ); } - public async deployPayableExchangeIssuanceAsync( + public async deployRebalancingSetExchangeIssuanceModuleAsync( core: Address, transferProxy: Address, exchangeIssuanceModule: Address, wrappedEther: Address, from: Address = this._contractOwnerAddress - ): Promise { + ): Promise { const erc20WrapperLibrary = await ERC20Wrapper.new( { from: this._contractOwnerAddress }, ); - await PayableExchangeIssuance.link('ERC20Wrapper', erc20WrapperLibrary.address); + await RebalancingSetExchangeIssuanceModule.link('ERC20Wrapper', erc20WrapperLibrary.address); - const payableExchangeIssuanceContract = await PayableExchangeIssuance.new( + const payableExchangeIssuanceContract = await RebalancingSetExchangeIssuanceModule.new( core, transferProxy, exchangeIssuanceModule, @@ -520,7 +521,7 @@ export class CoreWrapper { { from }, ); - return new PayableExchangeIssuanceContract( + return new RebalancingSetExchangeIssuanceModuleContract( new web3.eth.Contract(payableExchangeIssuanceContract.abi, payableExchangeIssuanceContract.address), { from }, );