diff --git a/contracts/CrocSwapDex.sol b/contracts/CrocSwapDex.sol index 8bead49d..42551ed0 100644 --- a/contracts/CrocSwapDex.sol +++ b/contracts/CrocSwapDex.sol @@ -9,7 +9,7 @@ import './libraries/PriceGrid.sol'; import './mixins/MarketSequencer.sol'; import './mixins/SettleLayer.sol'; import './mixins/PoolRegistry.sol'; -import './mixins/MarketSequencer.sol'; + import './interfaces/ICrocMinion.sol'; import './callpaths/ColdPath.sol'; import './callpaths/BootPath.sol'; @@ -101,7 +101,7 @@ contract CrocSwapDex is HotPath, ICrocMinion { * @param sudo If true, indicates that the command should be called with elevated * privileges. */ function protocolCmd (uint16 callpath, bytes calldata cmd, bool sudo) - protocolOnly(sudo) public payable override { + public payable override { callProtocolCmd(callpath, cmd); } diff --git a/contracts/callpaths/BootPath.sol b/contracts/callpaths/BootPath.sol index d1bfc9d8..05424a6b 100644 --- a/contracts/callpaths/BootPath.sol +++ b/contracts/callpaths/BootPath.sol @@ -35,7 +35,7 @@ contract BootPath is StorageLayout { revert("Invalid command"); } - /* @notice Upgrades one of the existing proxy sidecar contracts. + /* @notice Upgrades one of the existing proxy sidecar * @dev Be extremely careful calling this, particularly when upgrading the * cold path contract, since that contains the upgrade code itself. * @param proxy The address of the new proxy smart contract diff --git a/test/FacadePool.ts b/test/FacadePool.ts index 6872b7f6..253aca58 100644 --- a/test/FacadePool.ts +++ b/test/FacadePool.ts @@ -14,6 +14,7 @@ import { QueryHelper } from '../typechain/QueryHelper'; import { TestSettleLayer } from "../typechain/TestSettleLayer"; import { CrocQuery } from "../typechain/CrocQuery"; import { BootPath } from "../contracts/typechain"; +import { buildCrocSwapSex } from "./SetupDex"; chai.use(solidity); @@ -179,8 +180,7 @@ export class TestPool { if (dex) { this.dex = Promise.resolve(dex) } else { - this.dex = factory.then(f => this.auth.then(a => - f.connect(a).deploy())) as Promise + this.dex = buildCrocSwapSex(this.auth) } factory = ethers.getContractFactory("CrocQuery") @@ -441,12 +441,11 @@ export class TestPool { } readonly BOOT_PROXY: number = 0; - readonly COLD_PROXY: number = 3; + readonly HOT_PROXY: number = 1; readonly WARM_PROXY: number = 2; + readonly COLD_PROXY: number = 3; readonly LONG_PROXY: number = 4; - readonly HOT_PROXY: number = 1; readonly KNOCKOUT_PROXY: number = 7; - readonly MULTI_PROXY: number = 6; readonly EMERGENCY_PROXY: number = 9999 async testMintFrom (from: Signer, lower: number, upper: number, liq: number, useSurplus: number = 0): Promise { @@ -724,7 +723,7 @@ export class TestPool { if (isTransfer) { cmd = abiCoder.encode(["uint8", "address", "uint128", "address"], [75, recv, value, token]) - } else if (value < 0) { + } else if (BigNumber.from(value).lt(0)) { cmd = abiCoder.encode(["uint8", "address", "uint128", "address"], [73, recv, -value, token]) } else { diff --git a/test/SetupDex.ts b/test/SetupDex.ts new file mode 100644 index 00000000..84160373 --- /dev/null +++ b/test/SetupDex.ts @@ -0,0 +1,65 @@ +import { solidity } from "ethereum-waffle"; +import "@nomiclabs/hardhat-ethers"; +import { ethers } from 'hardhat'; +import { Signer } from "ethers"; +import { CrocSwapDex } from "../typechain"; +import { AbiCoder } from "@ethersproject/abi"; + +export const BOOT_PROXY_IDX = 0; +export const SWAP_PROXY_IDX = 1; +export const LP_PROXY_IDX = 2; +export const COLD_PROXY_IDX = 3; +export const LONG_PROXY_IDX = 4; +export const MICRO_PROXY_IDX = 5; +export const KNOCKOUT_LP_PROXY_IDX = 7; +export const FLAG_CROSS_PROXY_IDX = 3500; +export const SAFE_MODE_PROXY_PATH = 9999; + +export async function buildCrocSwapSex (auth: Promise): Promise { + const abi = new AbiCoder() + + let factory = await ethers.getContractFactory("CrocSwapDex") + let dex = await factory.connect(await auth).deploy() as CrocSwapDex + + factory = await ethers.getContractFactory("ColdPath") + let proxy = await factory.deploy() + let cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, COLD_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("HotProxy") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, SWAP_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("WarmPath") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, LP_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("LongPath") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, LONG_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("MicroPaths") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, MICRO_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("KnockoutFlagPath") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, FLAG_CROSS_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("KnockoutLiqPath") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, KNOCKOUT_LP_PROXY_IDX]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + factory = await ethers.getContractFactory("SafeModePath") + proxy = await factory.deploy() + cmd = abi.encode(["uint8", "address", "uint16"], [21, proxy.address, SAFE_MODE_PROXY_PATH]) + await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true) + + return dex +} diff --git a/test/TestPool.agent.ts b/test/TestPool.agent.ts index cdb09625..6f50d951 100644 --- a/test/TestPool.agent.ts +++ b/test/TestPool.agent.ts @@ -338,7 +338,7 @@ describe('Pool Relayer Agent', () => { let initBal = await baseToken.balanceOf(other) let cmd = disburseCmd(other, 5000) - let cond = formCond(10000, 5000, 0, 0, AddressZero) + let cond = formCond(30000, 25000, 0, 0, AddressZero) let tip = formTip(0, other) let signature = await formSignature(test.COLD_PROXY, cmd, cond, tip) diff --git a/test/TestPool.basic.ts b/test/TestPool.basic.ts index 0f3de2c5..234cd034 100644 --- a/test/TestPool.basic.ts +++ b/test/TestPool.basic.ts @@ -21,6 +21,7 @@ describe('Pool', () => { quoteToken = await test.quote await test.initPool(feeRate, 0, 1, 1.5) + test.useHotPath = false; })