Skip to content

Commit

Permalink
add core contract tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Bhardwaj authored and Pranav Bhardwaj committed Aug 25, 2023
1 parent f052eb1 commit 50ac613
Show file tree
Hide file tree
Showing 15 changed files with 2,869 additions and 3 deletions.
871 changes: 871 additions & 0 deletions test/factories/delegatedManagerFactory.spec.ts

Large diffs are not rendered by default.

1,155 changes: 1,155 additions & 0 deletions test/manager/delegatedManager.spec.ts

Large diffs are not rendered by default.

602 changes: 602 additions & 0 deletions test/managerCore.spec.ts

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { BigNumber } from "@ethersproject/bignumber";

const { AddressZero, MaxUint256, One, Two, Zero } = constants;

export const MODULE_STATE = {
"NONE": 0,
"PENDING": 1,
"INITIALIZED": 2,
};

export const EXTENSION_STATE = {
"NONE": 0,
"PENDING": 1,
"INITIALIZED": 2,
};

export const ADDRESS_ZERO = AddressZero;
export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
export const EMPTY_BYTES = "0x";
Expand Down
13 changes: 13 additions & 0 deletions utils/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ export { WrapExtension } from "../../typechain/WrapExtension";
export { WrappedfCashMock } from "../../typechain/WrappedfCashMock";
export { WrappedfCashFactoryMock } from "../../typechain/WrappedfCashFactoryMock";
export { ZeroExExchangeProxyMock } from "../../typechain/ZeroExExchangeProxyMock";
export { BaseGlobalExtensionMock } from "../../typechain/BaseGlobalExtensionMock";
export { DelegatedManager } from "../../typechain/DelegatedManager";
export { DelegatedManagerFactory } from "../../typechain/DelegatedManagerFactory";
export { ManagerCore } from "../../typechain/ManagerCore";
export { ManagerMock } from "../../typechain/ManagerMock";
export { ModuleMock } from "../../typechain/ModuleMock";
export { MutualUpgradeV2Mock } from "../../typechain/MutualUpgradeV2Mock";
export { GlobalTradeExtension } from "../../typechain/GlobalTradeExtension";
export { GlobalIssuanceExtension } from "../../typechain/GlobalIssuanceExtension";
export { GlobalStreamingFeeSplitExtension } from "../../typechain/GlobalStreamingFeeSplitExtension";
export { GlobalBatchTradeExtension } from "../../typechain/GlobalBatchTradeExtension";
export { GlobalWrapExtension } from "../../typechain/GlobalWrapExtension";
export { GlobalClaimExtension } from "../../typechain/GlobalClaimExtension";
27 changes: 27 additions & 0 deletions utils/deploys/deployFactories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Signer } from "ethers";
import {
Address
} from "../types";

import { DelegatedManagerFactory } from "../contracts/index";
import { DelegatedManagerFactory__factory } from "../../typechain/factories/DelegatedManagerFactory__factory";

export default class DeployFactories {
private _deployerSigner: Signer;

constructor(deployerSigner: Signer) {
this._deployerSigner = deployerSigner;
}

public async deployDelegatedManagerFactory(
managerCore: Address,
controller: Address,
setTokenFactory: Address
): Promise<DelegatedManagerFactory> {
return await new DelegatedManagerFactory__factory(this._deployerSigner).deploy(
managerCore,
controller,
setTokenFactory
);
}
}
91 changes: 91 additions & 0 deletions utils/deploys/deployGlobalExtensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Signer } from "ethers";
import { Address } from "../types";
import {
GlobalBatchTradeExtension,
GlobalClaimExtension,
GlobalIssuanceExtension,
GlobalStreamingFeeSplitExtension,
GlobalTradeExtension,
GlobalWrapExtension
} from "../contracts/index";

import { GlobalBatchTradeExtension__factory } from "../../typechain/factories/GlobalBatchTradeExtension__factory";
import { GlobalClaimExtension__factory } from "../../typechain/factories/GlobalClaimExtension__factory";
import { GlobalIssuanceExtension__factory } from "../../typechain/factories/GlobalIssuanceExtension__factory";
import { GlobalStreamingFeeSplitExtension__factory } from "../../typechain/factories/GlobalStreamingFeeSplitExtension__factory";
import { GlobalTradeExtension__factory } from "../../typechain/factories/GlobalTradeExtension__factory";
import { GlobalWrapExtension__factory } from "../../typechain/factories/GlobalWrapExtension__factory";

export default class DeployGlobalExtensions {
private _deployerSigner: Signer;

constructor(deployerSigner: Signer) {
this._deployerSigner = deployerSigner;
}

public async deployGlobalBatchTradeExtension(
managerCore: Address,
tradeModule: Address,
integrations: string[]
): Promise<GlobalBatchTradeExtension> {
return await new GlobalBatchTradeExtension__factory(this._deployerSigner).deploy(
managerCore,
tradeModule,
integrations
);
}

public async deployGlobalClaimExtension(
managerCore: Address,
airdropModule: Address,
claimModule: Address,
integrationRegistry: Address
): Promise<GlobalClaimExtension> {
return await new GlobalClaimExtension__factory(this._deployerSigner).deploy(
managerCore,
airdropModule,
claimModule,
integrationRegistry
);
}

public async deployGlobalIssuanceExtension(
managerCore: Address,
basicIssuanceModule: Address
): Promise<GlobalIssuanceExtension> {
return await new GlobalIssuanceExtension__factory(this._deployerSigner).deploy(
managerCore,
basicIssuanceModule,
);
}

public async deployGlobalStreamingFeeSplitExtension(
managerCore: Address,
streamingFeeModule: Address
): Promise<GlobalStreamingFeeSplitExtension> {
return await new GlobalStreamingFeeSplitExtension__factory(this._deployerSigner).deploy(
managerCore,
streamingFeeModule,
);
}

public async deployGlobalTradeExtension(
managerCore: Address,
tradeModule: Address
): Promise<GlobalTradeExtension> {
return await new GlobalTradeExtension__factory(this._deployerSigner).deploy(
managerCore,
tradeModule,
);
}

public async deployGlobalWrapExtension(
managerCore: Address,
wrapModule: Address
): Promise<GlobalWrapExtension> {
return await new GlobalWrapExtension__factory(this._deployerSigner).deploy(
managerCore,
wrapModule,
);
}
}
31 changes: 29 additions & 2 deletions utils/deploys/deployManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Signer } from "ethers";
import { BigNumber } from "@ethersproject/bignumber";
import { Address } from "../types";
import { ICManager, BaseManager, BaseManagerV2 } from "../contracts/index";
import { ICManager, BaseManager, BaseManagerV2, DelegatedManager } from "../contracts/index";

import { ICManager__factory } from "../../typechain/factories/ICManager__factory";
import { BaseManager__factory } from "../../typechain/factories/BaseManager__factory";
import { BaseManagerV2__factory } from "../../typechain/factories/BaseManagerV2__factory";
import { DelegatedManager__factory } from "../../typechain/factories/DelegatedManager__factory";

export default class DeployToken {
private _deployerSigner: Signer;
Expand Down Expand Up @@ -55,4 +56,30 @@ export default class DeployToken {
methodologist
);
}
}

public async deployDelegatedManager(
setToken: Address,
factory: Address,
methodologist: Address,
extensions: Address[],
operators: Address[],
allowedAssets: Address[],
useAssetAllowlist: boolean
): Promise<DelegatedManager> {
return await new DelegatedManager__factory(this._deployerSigner).deploy(
setToken,
factory,
methodologist,
extensions,
operators,
allowedAssets,
useAssetAllowlist
);
}

/* GETTERS */

public async getDelegatedManager(managerAddress: Address): Promise<DelegatedManager> {
return await new DelegatedManager__factory(this._deployerSigner).attach(managerAddress);
}
}
16 changes: 16 additions & 0 deletions utils/deploys/deployManagerCore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Signer } from "ethers";

import { ManagerCore } from "../contracts/index";
import { ManagerCore__factory } from "../../typechain/factories/ManagerCore__factory";

export default class DeployFactories {
private _deployerSigner: Signer;

constructor(deployerSigner: Signer) {
this._deployerSigner = deployerSigner;
}

public async deployManagerCore(): Promise<ManagerCore> {
return await new ManagerCore__factory(this._deployerSigner).deploy();
}
}
12 changes: 12 additions & 0 deletions utils/deploys/deployMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import {
WrappedfCashFactoryMock,
ZeroExExchangeProxyMock,
DEXAdapter,
ModuleMock,
BaseGlobalExtensionMock,
} from "../contracts/index";

import { BaseExtensionMock__factory } from "../../typechain/factories/BaseExtensionMock__factory";
import { DEXAdapter__factory } from "../../typechain/factories/DEXAdapter__factory";
import { ModuleMock__factory } from "../../typechain/factories/ModuleMock__factory";
import { BaseGlobalExtensionMock__factory } from "../../typechain/factories/BaseGlobalExtensionMock__factory";
import { convertLibraryNameToLinkId } from "../common";
import { ChainlinkAggregatorV3Mock__factory } from "../../typechain/factories/ChainlinkAggregatorV3Mock__factory";
import { FLIStrategyExtensionMock__factory } from "../../typechain/factories/FLIStrategyExtensionMock__factory";
Expand Down Expand Up @@ -50,6 +54,10 @@ export default class DeployMocks {
return await new BaseExtensionMock__factory(this._deployerSigner).deploy(manager);
}

public async deployBaseGlobalExtensionMock(managerCore: Address, module: Address): Promise<BaseGlobalExtensionMock> {
return await new BaseGlobalExtensionMock__factory(this._deployerSigner).deploy(managerCore, module);
}

public async deployTradeAdapterMock(): Promise<TradeAdapterMock> {
return await new TradeAdapterMock__factory(this._deployerSigner).deploy();
}
Expand Down Expand Up @@ -149,6 +157,10 @@ export default class DeployMocks {
return await new DEXAdapter__factory(this._deployerSigner).deploy();
}

public async deployModuleMock(controller: Address): Promise<ModuleMock> {
return await new ModuleMock__factory(this._deployerSigner).deploy(controller);
}

public async deployFlashMintLeveragedCompMock(
wethAddress: Address,
quickRouterAddress: Address,
Expand Down
4 changes: 4 additions & 0 deletions utils/deploys/deploySetV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default class DeploySetV2 {
return await new Compound__factory(this._deployerSigner).deploy();
}

public async getSetToken(setTokenAddress: Address): Promise<SetToken> {
return await new SetToken__factory(this._deployerSigner).attach(setTokenAddress);
}

public async deploySetToken(
_components: Address[],
_units: BigNumberish[],
Expand Down
9 changes: 9 additions & 0 deletions utils/deploys/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Signer } from "ethers";

import DeployManager from "./deployManager";
import DeployManagerCore from "./deployManagerCore";
import DeployGlobalExtensions from "./deployGlobalExtensions";
import DeployFactories from "./deployFactories";
import DeployMocks from "./deployMocks";
import DeployToken from "./deployToken";
import DeploySetV2 from "./deploySetV2";
Expand All @@ -15,6 +18,9 @@ export default class DeployHelper {
public token: DeployToken;
public setV2: DeploySetV2;
public manager: DeployManager;
public managerCore: DeployManagerCore;
public globalExtensions: DeployGlobalExtensions;
public factories: DeployFactories;
public mocks: DeployMocks;
public extensions: DeployExtensions;
public external: DeployExternalContracts;
Expand All @@ -34,5 +40,8 @@ export default class DeployHelper {
this.staking = new DeployStaking(deployerSigner);
this.viewers = new DeployViewers(deployerSigner);
this.keepers = new DeployKeepers(deployerSigner);
this.managerCore = new DeployManagerCore(deployerSigner);
this.globalExtensions = new DeployGlobalExtensions(deployerSigner);
this.factories = new DeployFactories(deployerSigner);
}
}
3 changes: 2 additions & 1 deletion utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from "hardhat";
import { Blockchain } from "./common";
import { Blockchain, ProtocolUtils } from "./common";
import { Address } from "./types";

const provider = ethers.provider;
Expand All @@ -13,6 +13,7 @@ import {
UniswapV3Fixture
} from "./fixtures";

export const getProtocolUtils = () => new ProtocolUtils(provider);
export const getSetFixture = (ownerAddress: Address) => new SetFixture(provider, ownerAddress);
export const getAaveV2Fixture = (ownerAddress: Address) => new AaveV2Fixture(provider, ownerAddress);
export const getCompoundFixture = (ownerAddress: Address) => new CompoundFixture(provider, ownerAddress);
Expand Down
4 changes: 4 additions & 0 deletions utils/test/testingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,7 @@ export function setBlockNumber(blockNumber: number) {
});
});
}

export async function getLastBlockTransaction(): Promise<any> {
return (await provider.getBlockWithTransactions("latest")).transactions[0];
}
22 changes: 22 additions & 0 deletions utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,25 @@ export interface AirdropSettings {
airdropFee: BigNumber;
anyoneAbsorb: boolean;
}

export interface StreamingFeeState {
feeRecipient: Address;
streamingFeePercentage: BigNumber;
maxStreamingFeePercentage: BigNumber;
lastStreamingFeeTimestamp: BigNumber;
}

export interface TradeInfo {
exchangeName: string;
sendToken: Address;
sendQuantity: BigNumber;
receiveToken: Address;
receiveQuantity: BigNumber;
data: Bytes;
}

export interface BatchTradeResult {
success: boolean;
tradeInfo: TradeInfo;
revertReason?: string | undefined;
}

0 comments on commit 50ac613

Please sign in to comment.