├── .circleci └── config.yml ├── .env.default ├── .eslintrc.js ├── .gitattributes ├── .github └── semantic.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.json ├── .solcover.js ├── .solhint.json ├── .solhintignore ├── .spec.template.ts ├── README.md ├── contracts ├── interfaces │ ├── IAirdropModule.sol │ ├── IAmmAdapter.sol │ ├── IBasicIssuanceModule.sol │ ├── IClaimAdapter.sol │ ├── IClaimModule.sol │ ├── IController.sol │ ├── IDebtIssuanceModule.sol │ ├── IExchangeAdapter.sol │ ├── IGovernanceAdapter.sol │ ├── IIndexExchangeAdapter.sol │ ├── IIntegrationRegistry.sol │ ├── IIssuanceModule.sol │ ├── IManagerIssuanceHook.sol │ ├── IModule.sol │ ├── IModuleIssuanceHook.sol │ ├── IModuleIssuanceHookV2.sol │ ├── INAVIssuanceHook.sol │ ├── INAVIssuanceModule.sol │ ├── IOracle.sol │ ├── IOracleAdapter.sol │ ├── IPerpV2BasisTradingModule.sol │ ├── IPerpV2LeverageModuleV2.sol │ ├── IPriceOracle.sol │ ├── ISetToken.sol │ ├── ISetTokenCreator.sol │ ├── ISetValuer.sol │ ├── IStakingAdapter.sol │ ├── IStreamingFeeModule.sol │ ├── ITradeModule.sol │ ├── IWrapAdapter.sol │ ├── IWrapModuleV2.sol │ ├── IWrapV2Adapter.sol │ ├── IWrappedFCash.sol │ ├── IWrappedFCashFactory.sol │ └── external │ │ ├── IAaveLendingPool.sol │ │ ├── IAaveLendingPoolCore.sol │ │ ├── ICErc20.sol │ │ ├── ICEth.sol │ │ ├── IComptroller.sol │ │ ├── IDMMFactory.sol │ │ ├── IDMMPool.sol │ │ ├── IGaugeController.sol │ │ ├── IKyberNetworkProxy.sol │ │ ├── INotionalProxy.sol │ │ ├── IStableSwapPool.sol │ │ ├── IStakingRewards.sol │ │ ├── ISwapRouter.sol │ │ ├── ISynth.sol │ │ ├── ISynthetixExchanger.sol │ │ ├── IUniswapV2Factory.sol │ │ ├── IUniswapV2Pair.sol │ │ ├── IUniswapV2Router.sol │ │ ├── IWETH.sol │ │ ├── IYearnVault.sol │ │ ├── aave-v2 │ │ ├── IAToken.sol │ │ ├── ILendingPool.sol │ │ ├── ILendingPoolAddressesProvider.sol │ │ ├── IProtocolDataProvider.sol │ │ ├── IStableDebtToken.sol │ │ ├── IVariableDebtToken.sol │ │ └── lib │ │ │ └── DataTypes.sol │ │ └── perp-v2 │ │ ├── IAccountBalance.sol │ │ ├── IClearingHouse.sol │ │ ├── IClearingHouseConfig.sol │ │ ├── IExchange.sol │ │ ├── IIndexPrice.sol │ │ ├── IMarketRegistry.sol │ │ ├── IQuoter.sol │ │ └── IVault.sol ├── lib │ ├── AddressArrayUtils.sol │ ├── BytesArrayUtils.sol │ ├── ExplicitERC20.sol │ ├── PreciseUnitMath.sol │ ├── StringArrayUtils.sol │ ├── Uint256ArrayUtils.sol │ └── UnitConversionUtils.sol ├── mocks │ ├── AddressArrayUtilsMock.sol │ ├── BytesArrayUtilsMock.sol │ ├── ContractCallerMock.sol │ ├── ExplicitERC20Mock.sol │ ├── ForceFunderMock.sol │ ├── GodModeMock.sol │ ├── OracleAdapterMock.sol │ ├── OracleMock.sol │ ├── PositionMock.sol │ ├── PositionV2Mock.sol │ ├── PreciseUnitMathMock.sol │ ├── StandardTokenMock.sol │ ├── StandardTokenWithFeeMock.sol │ ├── StandardTokenWithRoundingErrorMock.sol │ ├── StringArrayUtilsMock.sol │ ├── Uint256ArrayUtilsMock.sol │ ├── UnitConversionUtilsMock.sol │ ├── WrappedfCashFactoryMock.sol │ ├── WrappedfCashMock.sol │ ├── external │ │ ├── ChainlinkAggregatorMock.sol │ │ ├── CompoundPriceOracleMock.sol │ │ ├── ComptrollerMock.sol │ │ ├── CurveStableswapMock.sol │ │ ├── GaugeControllerMock.sol │ │ ├── KyberNetworkProxyMock.sol │ │ ├── LendingPoolAddressProviderMock.sol │ │ ├── OneInchExchangeMock.sol │ │ ├── ProtocolDataProvider.sol │ │ ├── SynthMock.sol │ │ ├── SynthetixExchangerMock.sol │ │ ├── TribePegExchangerMock.sol │ │ ├── YearnStrategyMock.sol │ │ ├── YearnVaultMock.sol │ │ └── ZeroExMock.sol │ ├── integrations │ │ ├── AmmAdapterMock.sol │ │ ├── ClaimAdapterMock.sol │ │ ├── GovernanceAdapterMock.sol │ │ ├── StakingAdapterMock.sol │ │ ├── TradeAdapterMock.sol │ │ ├── WrapAdapterMock.sol │ │ └── WrapV2AdapterMock.sol │ └── protocol │ │ ├── CustomSetValuerMock.sol │ │ ├── integration │ │ ├── AaveLendingPoolCoreMock.sol │ │ ├── AaveLendingPoolMock.sol │ │ └── lib │ │ │ ├── AaveV2Mock.sol │ │ │ ├── CompoundMock.sol │ │ │ ├── PerpV2LibraryV2Mock.sol │ │ │ ├── PerpV2Mock.sol │ │ │ ├── PerpV2PositionsMock.sol │ │ │ └── UniswapV3MathMock.sol │ │ ├── lib │ │ ├── InvokeMock.sol │ │ ├── IssuanceValidationUtilsMock.sol │ │ ├── ModuleBaseMock.sol │ │ ├── ModuleBaseV2Mock.sol │ │ ├── ResourceIdentifierMock.sol │ │ └── SetTokenAccessibleMock.sol │ │ └── module │ │ ├── DebtIssuanceMock.sol │ │ ├── DebtModuleMock.sol │ │ ├── ManagerIssuanceHookMock.sol │ │ ├── ModuleIssuanceHookMock.sol │ │ ├── NAVIssuanceCaller.sol │ │ └── NAVIssuanceHookMock.sol ├── product │ ├── AMMSplitter.sol │ ├── APYRescue.sol │ ├── AssetLimitHook.sol │ └── TokenEnabler.sol ├── protocol-viewers │ ├── ERC20Viewer.sol │ ├── PerpV2LeverageModuleViewer.sol │ ├── ProtocolViewer.sol │ ├── SetTokenViewer.sol │ └── StreamingFeeModuleViewer.sol └── protocol │ ├── Controller.sol │ ├── IntegrationRegistry.sol │ ├── PriceOracle.sol │ ├── SetToken.sol │ ├── SetTokenCreator.sol │ ├── SetValuer.sol │ ├── integration │ ├── UniswapV2TransferFeeExchangeAdapter.sol │ ├── amm │ │ └── UniswapV2AmmAdapter.sol │ ├── claim │ │ └── CompClaimAdapter.sol │ ├── exchange │ │ ├── CurveExchangeAdapter.sol │ │ ├── CurveStEthExchangeAdapter.sol │ │ ├── KyberExchangeAdapter.sol │ │ ├── OneInchExchangeAdapter.sol │ │ ├── SynthetixExchangeAdapter.sol │ │ ├── UniswapV2ExchangeAdapter.sol │ │ ├── UniswapV2ExchangeAdapterV2.sol │ │ ├── UniswapV3ExchangeAdapter.sol │ │ ├── UniswapV3ExchangeAdapterV2.sol │ │ └── ZeroExApiAdapter.sol │ ├── governance │ │ ├── AaveGovernanceV2Adapter.sol │ │ ├── CompoundBravoGovernanceAdapter.sol │ │ ├── CompoundLikeGovernanceAdapter.sol │ │ └── SnapshotGovernanceAdapter.sol │ ├── index-exchange │ │ ├── BalancerV1IndexExchangeAdapter.sol │ │ ├── KyberV3IndexExchangeAdapter.sol │ │ ├── UniswapV2IndexExchangeAdapter.sol │ │ └── UniswapV3IndexExchangeAdapter.sol │ ├── lib │ │ ├── AaveV2.sol │ │ ├── Compound.sol │ │ ├── PerpV2.sol │ │ ├── PerpV2LibraryV2.sol │ │ ├── PerpV2Positions.sol │ │ └── UniswapV3Math.sol │ ├── oracles │ │ ├── CTokenOracle.sol │ │ ├── UniswapPairPriceAdapter.sol │ │ └── YearnVaultOracle.sol │ ├── staking │ │ └── CurveStakingAdapter.sol │ ├── wrap-v2 │ │ ├── AaveV2WrapV2Adapter.sol │ │ ├── CompoundWrapV2Adapter.sol │ │ └── YearnWrapV2Adapter.sol │ └── wrap │ │ ├── RgtMigrationWrapAdapter.sol │ │ └── notional │ │ ├── WrappedfCash.sol │ │ ├── WrappedfCashFactory.sol │ │ ├── nBeaconProxy.sol │ │ └── nUpgradeableBeacon.sol │ ├── lib │ ├── Invoke.sol │ ├── IssuanceValidationUtils.sol │ ├── ModuleBase.sol │ ├── ModuleBaseV2.sol │ ├── Position.sol │ ├── PositionV2.sol │ ├── ResourceIdentifier.sol │ └── SetTokenAccessible.sol │ └── modules │ ├── v1 │ ├── AaveLeverageModule.sol │ ├── AirdropModule.sol │ ├── AmmModule.sol │ ├── BasicIssuanceModule.sol │ ├── ClaimModule.sol │ ├── CompoundLeverageModule.sol │ ├── CustomOracleNAVIssuanceModule.sol │ ├── DebtIssuanceModule.sol │ ├── DebtIssuanceModuleV2.sol │ ├── GeneralIndexModule.sol │ ├── GovernanceModule.sol │ ├── IssuanceModule.sol │ ├── NotionalTradeModule.sol │ ├── SingleIndexModule.sol │ ├── SlippageIssuanceModule.sol │ ├── StakingModule.sol │ ├── StreamingFeeModule.sol │ ├── TradeModule.sol │ ├── WrapModule.sol │ └── WrapModuleV2.sol │ └── v2 │ ├── PerpV2BasisTradingModule.sol │ └── PerpV2LeverageModuleV2.sol ├── deprecated ├── AGIMigrationWrapAdapter.sol ├── AaveGovernanceAdapter.sol ├── AaveMigrationWrapAdapter.sol ├── AaveWrapAdapter.sol ├── AxieInfinityMigrationWrapAdapter.sol ├── CompoundWrapAdapter.sol ├── DgMigrationWrapAdapter.sol ├── KyberMigrationAdapter.sol ├── NAVIssuanceModule.sol ├── PerpV2LeverageModule.sol └── YearnWrapAdapter.sol ├── external ├── abi │ ├── aave │ │ └── v2 │ │ │ ├── AaveGovernanceV2.json │ │ │ ├── AaveTokenV2Mintable.json │ │ │ ├── AaveV2AToken.json │ │ │ ├── AaveV2DefaultReserveInterestRateStrategy.json │ │ │ ├── AaveV2LendingPool.json │ │ │ ├── AaveV2LendingPoolAddressesProvider.json │ │ │ ├── AaveV2LendingPoolCollateralManager.json │ │ │ ├── AaveV2LendingPoolConfigurator.json │ │ │ ├── AaveV2LendingRateOracle.json │ │ │ ├── AaveV2Oracle.json │ │ │ ├── AaveV2PriceOracle.json │ │ │ ├── AaveV2ProtocolDataProvider.json │ │ │ ├── AaveV2StableDebtToken.json │ │ │ ├── AaveV2StakedTokenIncentivesController.json │ │ │ ├── AaveV2VariableDebtToken.json │ │ │ ├── Executor.json │ │ │ ├── GovernanceStrategy.json │ │ │ └── lib │ │ │ ├── GenericLogic.json │ │ │ ├── ReserveLogic.json │ │ │ └── ValidationLogic.json │ ├── balancer │ │ ├── BFactory.json │ │ ├── BPool.json │ │ ├── BRegistry.json │ │ └── ExchangeProxy.json │ ├── compound │ │ ├── CERc20.json │ │ ├── CEther.json │ │ ├── Comp.json │ │ ├── CompoundGovernorAlpha.json │ │ ├── CompoundGovernorBravoDelegate.json │ │ ├── CompoundGovernorBravoDelegator.json │ │ ├── CompoundPriceOracle.sol │ │ ├── CompoundTimelock.json │ │ ├── Comptroller.json │ │ ├── PriceOracleProxy.json │ │ ├── Unitroller.json │ │ └── WhitePaperInterestRateModel.json │ ├── curve │ │ ├── CRVToken.json │ │ ├── CurveDeposit.json │ │ ├── CurvePoolERC20.json │ │ ├── GaugeController.json │ │ ├── LiquidityGauge.json │ │ ├── LiquidityGaugeReward.json │ │ ├── Minter.json │ │ └── Stableswap.json │ ├── kyber │ │ ├── DMMFactory.json │ │ ├── DMMPool.json │ │ ├── DMMRouter02.json │ │ └── KyberNetworkTokenV2.json │ ├── notional │ │ ├── BatchAction.json │ │ ├── ERC1155Action.json │ │ └── Router.json │ ├── perp │ │ ├── PerpV2AccountBalance.json │ │ ├── PerpV2BaseToken.json │ │ ├── PerpV2ChainlinkPriceFeed.json │ │ ├── PerpV2ClearingHouse.json │ │ ├── PerpV2ClearingHouseConfig.json │ │ ├── PerpV2Exchange.json │ │ ├── PerpV2InsuranceFund.json │ │ ├── PerpV2MarketRegistry.json │ │ ├── PerpV2OrderBook.json │ │ ├── PerpV2QuoteToken.json │ │ ├── PerpV2Quoter.json │ │ ├── PerpV2TestAggregatorV3.json │ │ ├── PerpV2Vault.json │ │ └── PerpV2VirtualToken.json │ ├── snapshot │ │ └── DelegateRegistry.json │ ├── uniswap │ │ ├── v2 │ │ │ ├── StakingRewards.json │ │ │ ├── Uni.json │ │ │ ├── UniswapGovernorAlpha.json │ │ │ ├── UniswapTimelock.json │ │ │ ├── UniswapV2Factory.json │ │ │ ├── UniswapV2Pair.json │ │ │ └── UniswapV2Router02.json │ │ └── v3 │ │ │ ├── NFTDescriptor.json │ │ │ ├── NonfungiblePositionManager.json │ │ │ ├── Quoter.json │ │ │ ├── SwapRouter.json │ │ │ ├── UniswapV3Factory.json │ │ │ └── UniswapV3Pool.json │ ├── weth │ │ └── WETH9.json │ └── yearn │ │ ├── Registry.json │ │ └── Vault.json └── contracts │ ├── WETH9.sol │ ├── aave │ ├── v1 │ │ ├── AToken.sol │ │ ├── AaveGovernanceV2.sol │ │ ├── AavePropositionPower.sol │ │ ├── AaveProtoGovernance.sol │ │ ├── AaveTokenV2Mintable.sol │ │ ├── AssetVotingWeightProvider.sol │ │ ├── CoreLibrary.sol │ │ ├── DefaultReserveInterestRateStrategy.sol │ │ ├── Executor.sol │ │ ├── GovernanceParamsProvider.sol │ │ ├── GovernanceStrategy.sol │ │ ├── LendToAaveMigrator.sol │ │ ├── LendingPool.sol │ │ ├── LendingPoolAddressesProvider.sol │ │ ├── LendingPoolConfigurator.sol │ │ ├── LendingPoolCore.sol │ │ ├── LendingPoolDataProvider.sol │ │ └── LendingRateOracle.sol │ └── v2 │ │ ├── AaveV2AToken.sol │ │ ├── AaveV2DefaultReserveInterestRateStrategy.sol │ │ ├── AaveV2LendingPool.sol │ │ ├── AaveV2LendingPoolAddressesProvider.sol │ │ ├── AaveV2LendingPoolConfigurator.sol │ │ ├── AaveV2ProtocolDataProvider.sol │ │ ├── AaveV2StableDebtToken.sol │ │ ├── AaveV2StakedTokenIncentivesController.sol │ │ ├── AaveV2VariableDebtToken.sol │ │ └── lib │ │ ├── GenericLogic.sol │ │ ├── ReserveLogic.sol │ │ └── ValidationLogic.sol │ ├── axie_infinity │ └── TokenSwap.sol │ ├── balancer │ ├── BFactory.sol │ ├── BPool.sol │ ├── BRegistry.sol │ └── ExchangeProxy.sol │ ├── compound │ ├── CERc20.sol │ ├── CEther.sol │ ├── CToken.sol │ ├── Comp.sol │ ├── CompoundBravoDelegate.sol │ ├── CompoundBravoDelegator.sol │ ├── CompoundTimelock.sol │ ├── Comptroller.sol │ ├── GovernorAlpha.sol │ ├── PriceOracle.sol │ ├── PriceOracleProxy.sol │ ├── Unitroller.sol │ └── WhitePaperInterestRateModel.sol │ ├── curve │ ├── CRVToken.vy │ ├── CurveDeposit.vy │ ├── CurvePoolERC20.vy │ ├── GaugeController.vy │ ├── LiquidityGauge.vy │ ├── LiquidityGaugeReward.vy │ ├── Minter.vy │ └── Stableswap.vy │ ├── kyber │ ├── DMMFactory.sol │ ├── DMMPool.sol │ └── KyberNetworkTokenV2.sol │ ├── synthetix │ ├── Exchanger.sol │ └── Synth.sol │ ├── uniswap │ ├── v2 │ │ ├── GovernorAlpha.sol │ │ ├── StakingRewards.sol │ │ ├── Uni.sol │ │ ├── UniswapTimelock.sol │ │ ├── UniswapV2Factory.sol │ │ ├── UniswapV2Pair.sol │ │ ├── UniswapV2Router02.sol │ │ └── lib │ │ │ └── UniswapV2Library.sol │ └── v3 │ │ ├── NonfungiblePositionDescriptor.sol │ │ ├── NonfungiblePositionManager.sol │ │ ├── Quoter.sol │ │ ├── SwapRouter.sol │ │ ├── UniswapV3Factory.sol │ │ ├── UniswapV3Pool.sol │ │ └── lib │ │ └── BytesLib.sol │ └── yearn │ ├── BaseStrategy.sol │ ├── Registry.vy │ └── Vault.vy ├── hardhat.config.ts ├── package.json ├── pull_request_template.md ├── scripts ├── clean.sh ├── prepublish_only.sh ├── release_hardhat.sh └── release_latest.sh ├── subgraph └── test │ ├── deploy-state-multi-token.ts │ └── deploy-state.ts ├── tasks ├── index.ts └── subtasks.ts ├── test ├── fixtures │ ├── aaveV2.spec.ts │ ├── balancer.spec.ts │ ├── compound.spec.ts │ ├── curve.spec.ts │ ├── kyberV3DMM.spec.ts │ ├── perpV2.spec.ts │ ├── uniswap.spec.ts │ ├── uniswapV3.spec.ts │ └── yearn.spec.ts ├── integration │ ├── aaveGovernanceV2Module.spec.ts │ ├── aaveUniswapLeverageDebtIssuance.spec.ts │ ├── ammSplitterGeneralIndexModule.spec.ts │ ├── ammSplitterTradeModule.spec.ts │ ├── apyRescue.spec.ts │ ├── claim │ │ └── compClaimAdapter.spec.ts │ ├── compoundBravoGovernanceModule.spec.ts │ ├── compoundGovernanceModule.spec.ts │ ├── compoundUniswapLeverageDebtIssuance.spec.ts │ ├── curveExchangeALM.spec.ts │ ├── curveStEthALM.spec.ts │ ├── curveStakingModule.spec.ts │ ├── deFiPulseIntegration.spec.ts │ ├── deployments │ │ └── aaveLeverageModuleDeployment.spec.ts │ ├── notionalTradeModule │ │ ├── notionalTradeModule.spec.ts │ │ └── utils.ts │ ├── oracles │ │ ├── cTokenOracle.spec.ts │ │ └── yearnVaultOracle.spec.ts │ ├── perpV2BasisTradingSlippageIssuance.spec.ts │ ├── perpV2LeverageV2SlippageIssuance.spec.ts │ ├── rgtMigrationWrapModule.spec.ts │ ├── snapshotDelegationModule.spec.ts │ ├── sushiswapExchangeTradeModule.spec.ts │ ├── uniswapGovernanceModule.spec.ts │ ├── uniswapV2ExchangeGeneralIndexModule.spec.ts │ ├── uniswapV2ExchangeTradeModule.spec.ts │ └── wrap-v2 │ │ ├── aaveV2WrapModuleV2.spec.ts │ │ ├── compoundWrapModuleV2.spec.ts │ │ └── yearnWrapModuleV2.spec.ts ├── lib │ ├── addressArrayUtils.spec.ts │ ├── bytesArrayUtils.spec.ts │ ├── explicitERC20Mock.spec.ts │ ├── preciseUnitMath.spec.ts │ ├── stringArrayUtils.spec.ts │ ├── uint256ArrayUtils.spec.ts │ └── unitConversionUtils.spec.ts ├── product │ ├── ammSplitter.spec.ts │ ├── apyRescue.spec.ts │ ├── assetLimitHook.spec.ts │ └── tokenEnabler.spec.ts ├── protocol-viewers │ ├── perpV2LeverageModuleViewer.spec.ts │ └── protocolViewer.spec.ts └── protocol │ ├── controller.spec.ts │ ├── integration │ ├── amm │ │ └── UniswapV2AmmAdapter.spec.ts │ ├── exchange │ │ ├── curveExchangeAdapter.spec.ts │ │ ├── curveStEthExchangeAdapter.spec.ts │ │ ├── kyberExchangeAdapter.spec.ts │ │ ├── oneInchExchangeAdapter.spec.ts │ │ ├── synthetixExchangeAdapter.spec.ts │ │ ├── uniswapV2ExchangeAdapter.spec.ts │ │ ├── uniswapV2ExchangeAdapterV2.spec.ts │ │ ├── uniswapV3ExchangeAdapter.spec.ts │ │ ├── uniswapV3ExchangeAdapterV2.spec.ts │ │ └── zeroExApiAdapter.spec.ts │ ├── governance │ │ ├── aaveGovernanceV2Adapter.spec.ts │ │ ├── compoundBravoGovernanceAdapter.spec.ts │ │ ├── compoundLikeGovernanceAdapter.spec.ts │ │ └── snapshotGovernanceAdapter.spec.ts │ ├── index-exchange │ │ ├── balancerV1IndexExchangeAdapter.spec.ts │ │ ├── kyberV3IndexExchangeAdapter.spec.ts │ │ ├── uniswapV2IndexExchangeAdapter.spec.ts │ │ └── uniswapV3IndexExchangeAdapter.spec.ts │ ├── lib │ │ ├── aaveV2.spec.ts │ │ ├── compound.spec.ts │ │ ├── perpV2.spec.ts │ │ ├── perpV2LibraryV2.spec.ts │ │ ├── perpV2Positions.spec.ts │ │ └── uniswapV3Math.spec.ts │ ├── oracles │ │ └── uniswapPairPriceAdapter.spec.ts │ ├── staking │ │ └── curveStakingAdapter.spec.ts │ ├── uniswapV2TransferFeeExchangeAdapter.spec.ts │ ├── wrap-v2 │ │ ├── aaveV2WrapV2Adapter.spec.ts │ │ ├── compoundWrapV2Adapter.spec.ts │ │ └── yearnWrapV2Adapter.spec.ts │ └── wrap │ │ └── rgtMigrationWrapAdapter.spec.ts │ ├── integrationRegistry.spec.ts │ ├── lib │ ├── invoke.spec.ts │ ├── moduleBase.spec.ts │ ├── moduleBaseV2.spec.ts │ ├── position.spec.ts │ ├── positionV2.spec.ts │ ├── resourceIdentifier.spec.ts │ └── setTokenAccessible.spec.ts │ ├── modules │ ├── v1 │ │ ├── aaveLeverageModule.spec.ts │ │ ├── airdropModule.spec.ts │ │ ├── ammModule.spec.ts │ │ ├── basicIssuanceModule.spec.ts │ │ ├── claimModule.spec.ts │ │ ├── compoundLeverageModule.spec.ts │ │ ├── compoundLeverageModule2.spec.ts │ │ ├── customOracleNAVIssuanceModule.spec.ts │ │ ├── debtIssuanceModule.spec.ts │ │ ├── debtIssuanceModuleV2.spec.ts │ │ ├── generalIndexModule.spec.ts │ │ ├── governanceModule.spec.ts │ │ ├── issuanceModule.spec.ts │ │ ├── notionalTradeModule.spec.ts │ │ ├── singleIndexModule.spec.ts │ │ ├── slippageIssuanceModule.spec.ts │ │ ├── stakingModule.spec.ts │ │ ├── streamingFeeModule.spec.ts │ │ ├── tradeModule.spec.ts │ │ ├── wrapModule.spec.ts │ │ └── wrapModuleV2.spec.ts │ └── v2 │ │ ├── perpV2BasisTradingModule.spec.ts │ │ └── perpV2LeverageModuleV2.spec.ts │ ├── priceOracle.spec.ts │ ├── setToken.spec.ts │ ├── setTokenCreator.spec.ts │ └── setValuer.spec.ts ├── tsconfig.dist.json ├── tsconfig.hardhat.json ├── tsconfig.json ├── utils ├── common │ ├── adapterUtils.ts │ ├── addressUtils.ts │ ├── blockchainUtils.ts │ ├── feeModuleUtils.ts │ ├── index.ts │ ├── libraryUtils.ts │ ├── mathUtils.ts │ ├── navIssuanceModuleUtils.ts │ ├── perpV2Utils.ts │ ├── protocolUtils.ts │ ├── uniswapUtils.ts │ └── unitsUtils.ts ├── constants.ts ├── contracts │ ├── aaveV2.ts │ ├── balancer.ts │ ├── compound.ts │ ├── curve.ts │ ├── index.ts │ ├── kyberV3.ts │ ├── notional.ts │ ├── perpV2.ts │ ├── uniswap.ts │ ├── uniswapV3.ts │ └── yearn.ts ├── deploys │ ├── dependencies.ts │ ├── deployAdapters.ts │ ├── deployCoreContracts.ts │ ├── deployExternal.ts │ ├── deployLibraries.ts │ ├── deployMocks.ts │ ├── deployModules.ts │ ├── deployOracles.ts │ ├── deployProduct.ts │ ├── deployViewers.ts │ └── index.ts ├── fixtures │ ├── aaveV2Fixture.ts │ ├── balancerFixture.ts │ ├── compoundFixture.ts │ ├── curveFixture.ts │ ├── index.ts │ ├── kyberV3DMMFixture.ts │ ├── perpV2Fixture.ts │ ├── systemFixture.ts │ ├── uniswapFixture.ts │ ├── uniswapV3Fixture.ts │ └── yearnFixture.ts ├── index.ts ├── tasks │ ├── artifactUtils.ts │ ├── index.ts │ └── setupNativeSolc.ts ├── test │ ├── accountUtils.ts │ ├── index.ts │ ├── testingUtils.ts │ └── types.ts ├── types.ts └── wallets.ts └── yarn.lock /.env.default: -------------------------------------------------------------------------------- 1 | # These are randomly generated hex so that CircleCI will work 2 | ALCHEMY_TOKEN=fake_alchemy_token 3 | INFURA_TOKEN=799e620c4b39064f7a8cfd8452976ed1 4 | KOVAN_DEPLOY_PRIVATE_KEY=0f3456f7f1ed59aaa29f35f4674a87e754e1055249a2888bdaec3dea49d2e456 5 | STAGING_MAINNET_DEPLOY_PRIVATE_KEY=0f3456f7f1ed59aaa29f35f4674a87e754e1055249a2888bdaec3dea49d2e456 6 | PRODUCTION_MAINNET_DEPLOY_PRIVATE_KEY=0f3456f7f1ed59aaa29f35f4674a87e754e1055249a2888bdaec3dea49d2e456 7 | 8 | NODE_OPTIONS=--max_old_space_size=8192 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "browser": true, 4 | "node": true 5 | }, 6 | "parser": "@typescript-eslint/parser", 7 | "parserOptions": { 8 | "project": "tsconfig.json", 9 | "sourceType": "module" 10 | }, 11 | "plugins": [ 12 | "eslint-plugin-no-null", 13 | "eslint-plugin-jsdoc", 14 | "@typescript-eslint", 15 | "@typescript-eslint/tslint" 16 | ], 17 | "rules": { 18 | "@typescript-eslint/indent": [ 19 | "error", 20 | 2 21 | ], 22 | "@typescript-eslint/member-delimiter-style": [ 23 | "error", 24 | { 25 | "multiline": { 26 | "delimiter": "semi", 27 | "requireLast": true 28 | }, 29 | "singleline": { 30 | "delimiter": "semi", 31 | "requireLast": false 32 | } 33 | } 34 | ], 35 | "@typescript-eslint/prefer-namespace-keyword": "error", 36 | "@typescript-eslint/quotes": [ 37 | "error", 38 | "double", 39 | { 40 | "avoidEscape": true 41 | } 42 | ], 43 | "@typescript-eslint/semi": [ 44 | "error", 45 | "always" 46 | ], 47 | "@typescript-eslint/type-annotation-spacing": "error", 48 | "arrow-parens": [ 49 | "error", 50 | "as-needed" 51 | ], 52 | "brace-style": [ 53 | "error", 54 | "1tbs" 55 | ], 56 | "comma-dangle": [ 57 | "error", 58 | { 59 | "objects": "only-multiline", 60 | "arrays": "only-multiline", 61 | "imports": "only-multiline", 62 | "exports": "only-multiline", 63 | "functions": "only-multiline" 64 | } 65 | ], 66 | "jsdoc/check-alignment": "error", 67 | "jsdoc/check-indentation": "error", 68 | "jsdoc/newline-after-description": "error", 69 | "max-len": [ 70 | "error", 71 | { 72 | "code": 150 73 | } 74 | ], 75 | "no-null/no-null": "error", 76 | "no-trailing-spaces": "error", 77 | "no-unused-vars": "error", 78 | "no-var": "error", 79 | "prefer-const": "error", 80 | "quotes": "error", 81 | "semi": "error", 82 | "spaced-comment": [ 83 | "error", 84 | "always", 85 | { 86 | "markers": [ 87 | "/" 88 | ] 89 | } 90 | ], 91 | } 92 | }; 93 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /.github/semantic.yml: -------------------------------------------------------------------------------- 1 | titleOnly: true 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /artifacts 3 | /build 4 | /cache 5 | /dist 6 | /etherscan 7 | /flatten 8 | /deployments/kovan 9 | /deployments/localhost_31337 10 | /deployments/staging_mainnet_1 11 | /deployments/production_1 12 | /deployments/50-development.json 13 | /node_modules 14 | /transpiled 15 | /types/generated/* 16 | /typechain 17 | coverage.json 18 | coverage/ 19 | .env 20 | .releaserc.json 21 | 22 | /.coverage_cache 23 | /.coverage_contracts 24 | 25 | ### Node ### 26 | 27 | # Logs 28 | *.log 29 | /logs 30 | npm-debug.log* 31 | yarn-debug.log* 32 | yarn-error.log* 33 | 34 | # IDE Configs 35 | .vscode/* 36 | .idea 37 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SetProtocol/set-protocol-v2/63d6cf5d09fb5cccf5e8032be3e384c433f7ef35/.npmignore -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | contracts/ 2 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "parser": "typescript", 4 | "tabWidth": 2, 5 | "trailingComma": "all", 6 | "arrowParens": "always" 7 | } 8 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | const shell = require('shelljs'); // This module is already a solidity-coverage dep 2 | 3 | module.exports = { 4 | skipFiles: [ 5 | 'mocks', 6 | 'interfaces', 7 | 'protocol/modules/UniswapYieldStrategy.sol', 8 | 'product/AssetLimitHook.sol', 9 | 'protocol-viewers' 10 | ], 11 | providerOptions: { 12 | default_balance_ether: 100000000, 13 | gasLimit: 30000000, 14 | } 15 | } -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "rules": { 4 | "reason-string": ["warn", { "maxLength": 50 }], 5 | "compiler-version": ["error", ">=0.6.10"] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | contracts/mocks 3 | contracts/Migrations.sol 4 | contracts/external 5 | contracts/protocol/integration/wrap/notional 6 | -------------------------------------------------------------------------------- /.spec.template.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | import { BigNumber } from "ethers/utils"; 3 | import { ethers } from "hardhat"; 4 | 5 | import { Address, Account } from "@utils/types"; 6 | import {} from "@utils/constants"; 7 | import {} from "@utils/contracts"; 8 | import DeployHelper from "@utils/deploys"; 9 | import { 10 | addSnapshotBeforeRestoreAfterEach, 11 | ether, 12 | getAccounts, 13 | getSystemFixture, 14 | getWaffleExpect, 15 | } from "@utils/index"; 16 | import { SystemFixture } from "@utils/fixtures"; 17 | import { ContractTransaction } from "ethers"; 18 | 19 | const expect = getWaffleExpect(); 20 | 21 | describe("SPEC TITLE", () => { 22 | let owner: Account; 23 | let deployer: DeployHelper; 24 | let setup: SystemFixture; 25 | 26 | before(async () => { 27 | [ 28 | owner, 29 | ] = await getAccounts(); 30 | 31 | deployer = new DeployHelper(owner.wallet); 32 | setup = getSystemFixture(owner.address); 33 | await setup.initialize(); 34 | }); 35 | 36 | addSnapshotBeforeRestoreAfterEach(); 37 | 38 | describe("#FUNCTION_NAME", async () => { 39 | let subjectArgument: Address; 40 | 41 | beforeEach(async () => { 42 | }); 43 | 44 | async function subject(): Promise { 45 | } 46 | 47 | it("should do something", async () => { 48 | }); 49 | }); 50 | }); 51 | -------------------------------------------------------------------------------- /contracts/interfaces/IAmmAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IAmmAdapter 23 | * @author Set Protocol 24 | */ 25 | interface IAmmAdapter { 26 | 27 | function getProvideLiquidityCalldata( 28 | address _setToken, 29 | address _pool, 30 | address[] calldata _components, 31 | uint256[] calldata _maxTokensIn, 32 | uint256 _minLiquidity 33 | ) 34 | external 35 | view 36 | returns (address _target, uint256 _value, bytes memory _calldata); 37 | 38 | function getProvideLiquiditySingleAssetCalldata( 39 | address _setToken, 40 | address _pool, 41 | address _component, 42 | uint256 _maxTokenIn, 43 | uint256 _minLiquidity 44 | ) external view returns (address _target, uint256 _value, bytes memory _calldata); 45 | 46 | function getRemoveLiquidityCalldata( 47 | address _setToken, 48 | address _pool, 49 | address[] calldata _components, 50 | uint256[] calldata _minTokensOut, 51 | uint256 _liquidity 52 | ) external view returns (address _target, uint256 _value, bytes memory _calldata); 53 | 54 | function getRemoveLiquiditySingleAssetCalldata( 55 | address _setToken, 56 | address _pool, 57 | address _component, 58 | uint256 _minTokenOut, 59 | uint256 _liquidity 60 | ) external view returns (address _target, uint256 _value, bytes memory _calldata); 61 | 62 | function getSpenderAddress(address _pool) external view returns(address); 63 | function isValidPool(address _pool, address[] memory _components) external view returns(bool); 64 | } -------------------------------------------------------------------------------- /contracts/interfaces/IBasicIssuanceModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "./ISetToken.sol"; 21 | 22 | interface IBasicIssuanceModule { 23 | function getRequiredComponentUnitsForIssue( 24 | ISetToken _setToken, 25 | uint256 _quantity 26 | ) external returns(address[] memory, uint256[] memory); 27 | 28 | function redeem( 29 | ISetToken _setToken, 30 | uint256 _quantity, 31 | address _to 32 | ) 33 | external; 34 | } 35 | -------------------------------------------------------------------------------- /contracts/interfaces/IClaimAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 20 | 21 | import { ISetToken } from "../interfaces/ISetToken.sol"; 22 | 23 | pragma solidity 0.6.10; 24 | 25 | /** 26 | * @title IClaimAdapter 27 | * @author Set Protocol 28 | * 29 | */ 30 | interface IClaimAdapter { 31 | 32 | /** 33 | * Generates the calldata for claiming tokens from the rewars pool 34 | * 35 | * @param _setToken the set token that is owed the tokens 36 | * @param _rewardPool the rewards pool to claim from 37 | * 38 | * @return _subject the rewards pool to call 39 | * @return _value the amount of ether to send in the call 40 | * @return _calldata the calldata to use 41 | */ 42 | function getClaimCallData( 43 | ISetToken _setToken, 44 | address _rewardPool 45 | ) external view returns(address _subject, uint256 _value, bytes memory _calldata); 46 | 47 | /** 48 | * Gets the amount of unclaimed rewards 49 | * 50 | * @param _setToken the set token that is owed the tokens 51 | * @param _rewardPool the rewards pool to check 52 | * 53 | * @return uint256 the amount of unclaimed rewards 54 | */ 55 | function getRewardsAmount(ISetToken _setToken, address _rewardPool) external view returns(uint256); 56 | 57 | /** 58 | * Gets the rewards token 59 | * 60 | * @param _rewardPool the rewards pool to check 61 | * 62 | * @return IERC20 the reward token 63 | */ 64 | function getTokenAddress(address _rewardPool) external view returns(IERC20); 65 | } 66 | -------------------------------------------------------------------------------- /contracts/interfaces/IController.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | interface IController { 21 | function addSet(address _setToken) external; 22 | function feeRecipient() external view returns(address); 23 | function getModuleFee(address _module, uint256 _feeType) external view returns(uint256); 24 | function isModule(address _module) external view returns(bool); 25 | function isSet(address _setToken) external view returns(bool); 26 | function isSystemContract(address _contractAddress) external view returns (bool); 27 | function resourceId(uint256 _id) external view returns(address); 28 | } -------------------------------------------------------------------------------- /contracts/interfaces/IDebtIssuanceModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "./ISetToken.sol"; 21 | 22 | /** 23 | * @title IDebtIssuanceModule 24 | * @author Set Protocol 25 | * 26 | * Interface for interacting with Debt Issuance module interface. 27 | */ 28 | interface IDebtIssuanceModule { 29 | 30 | /** 31 | * Called by another module to register itself on debt issuance module. Any logic can be included 32 | * in case checks need to be made or state needs to be updated. 33 | */ 34 | function registerToIssuanceModule(ISetToken _setToken) external; 35 | 36 | /** 37 | * Called by another module to unregister itself on debt issuance module. Any logic can be included 38 | * in case checks need to be made or state needs to be cleared. 39 | */ 40 | function unregisterFromIssuanceModule(ISetToken _setToken) external; 41 | } -------------------------------------------------------------------------------- /contracts/interfaces/IExchangeAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | interface IExchangeAdapter { 21 | function getSpender() external view returns(address); 22 | function getTradeCalldata( 23 | address _fromToken, 24 | address _toToken, 25 | address _toAddress, 26 | uint256 _fromQuantity, 27 | uint256 _minToQuantity, 28 | bytes memory _data 29 | ) 30 | external 31 | view 32 | returns (address, uint256, bytes memory); 33 | } -------------------------------------------------------------------------------- /contracts/interfaces/IGovernanceAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IGovernanceAdapter 23 | * @author Set Protocol 24 | */ 25 | interface IGovernanceAdapter { 26 | 27 | function getVoteCalldata( 28 | uint256 _proposalId, 29 | bool _support, 30 | bytes memory _data 31 | ) 32 | external 33 | view 34 | returns (address _target, uint256 _value, bytes memory _calldata); 35 | 36 | function getDelegateCalldata(address _delegatee) external view returns (address _target, uint256 _value, bytes memory _calldata); 37 | 38 | function getRegisterCalldata(address _setToken) external view returns (address _target, uint256 _value, bytes memory _calldata); 39 | 40 | function getRevokeCalldata() external view returns (address _target, uint256 _value, bytes memory _calldata); 41 | 42 | function getProposeCalldata(bytes memory _proposalData) external view returns (address _target, uint256 _value, bytes memory _calldata); 43 | } -------------------------------------------------------------------------------- /contracts/interfaces/IIndexExchangeAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | interface IIndexExchangeAdapter { 21 | function getSpender() external view returns(address); 22 | 23 | /** 24 | * Returns calldata for executing trade on given adapter's exchange when using the GeneralIndexModule. 25 | * 26 | * @param _sourceToken Address of source token to be sold 27 | * @param _destinationToken Address of destination token to buy 28 | * @param _destinationAddress Address that assets should be transferred to 29 | * @param _isSendTokenFixed Boolean indicating if the send quantity is fixed, used to determine correct trade interface 30 | * @param _sourceQuantity Fixed/Max amount of source token to sell 31 | * @param _destinationQuantity Min/Fixed amount of destination tokens to receive 32 | * @param _data Arbitrary bytes that can be used to store exchange specific parameters or logic 33 | * 34 | * @return address Target contract address 35 | * @return uint256 Call value 36 | * @return bytes Trade calldata 37 | */ 38 | function getTradeCalldata( 39 | address _sourceToken, 40 | address _destinationToken, 41 | address _destinationAddress, 42 | bool _isSendTokenFixed, 43 | uint256 _sourceQuantity, 44 | uint256 _destinationQuantity, 45 | bytes memory _data 46 | ) 47 | external 48 | view 49 | returns (address, uint256, bytes memory); 50 | } -------------------------------------------------------------------------------- /contracts/interfaces/IIntegrationRegistry.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | interface IIntegrationRegistry { 21 | function addIntegration(address _module, string memory _id, address _wrapper) external; 22 | function getIntegrationAdapter(address _module, string memory _id) external view returns(address); 23 | function getIntegrationAdapterWithHash(address _module, bytes32 _id) external view returns(address); 24 | function isValidIntegration(address _module, string memory _id) external view returns(bool); 25 | } -------------------------------------------------------------------------------- /contracts/interfaces/IIssuanceModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "./ISetToken.sol"; 21 | 22 | /** 23 | * @title IIssuanceModule 24 | * @author Set Protocol 25 | * 26 | * Interface for interacting with Issuance module interface. 27 | */ 28 | interface IIssuanceModule { 29 | function updateIssueFee(ISetToken _setToken, uint256 _newIssueFee) external; 30 | function updateRedeemFee(ISetToken _setToken, uint256 _newRedeemFee) external; 31 | function updateFeeRecipient(ISetToken _setToken, address _newRedeemFee) external; 32 | 33 | function initialize( 34 | ISetToken _setToken, 35 | uint256 _maxManagerFee, 36 | uint256 _managerIssueFee, 37 | uint256 _managerRedeemFee, 38 | address _feeRecipient, 39 | address _managerIssuanceHook 40 | ) external; 41 | } 42 | -------------------------------------------------------------------------------- /contracts/interfaces/IManagerIssuanceHook.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "./ISetToken.sol"; 21 | 22 | interface IManagerIssuanceHook { 23 | function invokePreIssueHook(ISetToken _setToken, uint256 _issueQuantity, address _sender, address _to) external; 24 | function invokePreRedeemHook(ISetToken _setToken, uint256 _redeemQuantity, address _sender, address _to) external; 25 | } -------------------------------------------------------------------------------- /contracts/interfaces/IModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IModule 23 | * @author Set Protocol 24 | * 25 | * Interface for interacting with Modules. 26 | */ 27 | interface IModule { 28 | /** 29 | * Called by a SetToken to notify that this module was removed from the Set token. Any logic can be included 30 | * in case checks need to be made or state needs to be cleared. 31 | */ 32 | function removeModule() external; 33 | } -------------------------------------------------------------------------------- /contracts/interfaces/IModuleIssuanceHook.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 21 | 22 | import { ISetToken } from "./ISetToken.sol"; 23 | 24 | 25 | /** 26 | * CHANGELOG: 27 | * - Added a module level issue hook that can be used to set state ahead of component level 28 | * issue hooks 29 | */ 30 | interface IModuleIssuanceHook { 31 | 32 | function moduleIssueHook(ISetToken _setToken, uint256 _setTokenQuantity) external; 33 | function moduleRedeemHook(ISetToken _setToken, uint256 _setTokenQuantity) external; 34 | 35 | function componentIssueHook( 36 | ISetToken _setToken, 37 | uint256 _setTokenQuantity, 38 | IERC20 _component, 39 | bool _isEquity 40 | ) external; 41 | 42 | function componentRedeemHook( 43 | ISetToken _setToken, 44 | uint256 _setTokenQuantity, 45 | IERC20 _component, 46 | bool _isEquity 47 | ) external; 48 | } -------------------------------------------------------------------------------- /contracts/interfaces/INAVIssuanceHook.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "./ISetToken.sol"; 21 | 22 | interface INAVIssuanceHook { 23 | function invokePreIssueHook( 24 | ISetToken _setToken, 25 | address _reserveAsset, 26 | uint256 _reserveAssetQuantity, 27 | address _sender, 28 | address _to 29 | ) 30 | external; 31 | 32 | function invokePreRedeemHook( 33 | ISetToken _setToken, 34 | uint256 _redeemQuantity, 35 | address _sender, 36 | address _to 37 | ) 38 | external; 39 | } -------------------------------------------------------------------------------- /contracts/interfaces/INAVIssuanceModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "./ISetToken.sol"; 21 | 22 | interface INAVIssuanceModule { 23 | function issue( 24 | ISetToken _setToken, 25 | address _reserveAsset, 26 | uint256 _reserveAssetQuantity, 27 | uint256 _minSetTokenReceiveQuantity, 28 | address _to 29 | ) 30 | external; 31 | 32 | function redeem( 33 | ISetToken _setToken, 34 | address _reserveAsset, 35 | uint256 _setTokenQuantity, 36 | uint256 _minReserveReceiveQuantity, 37 | address _to 38 | ) 39 | external; 40 | } -------------------------------------------------------------------------------- /contracts/interfaces/IOracle.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IOracle 23 | * @author Set Protocol 24 | * 25 | * Interface for operating with any external Oracle that returns uint256 or 26 | * an adapting contract that converts oracle output to uint256 27 | */ 28 | interface IOracle { 29 | /** 30 | * @return Current price of asset represented in uint256, typically a preciseUnit where 10^18 = 1. 31 | */ 32 | function read() external view returns (uint256); 33 | } -------------------------------------------------------------------------------- /contracts/interfaces/IOracleAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IOracleAdapter 23 | * @author Set Protocol 24 | * 25 | * Interface for calling an oracle adapter. 26 | */ 27 | interface IOracleAdapter { 28 | 29 | /** 30 | * Function for retrieving a price that requires sourcing data from outside protocols to calculate. 31 | * 32 | * @param _assetOne First asset in pair 33 | * @param _assetTwo Second asset in pair 34 | * @return Boolean indicating if oracle exists 35 | * @return Current price of asset represented in uint256 36 | */ 37 | function getPrice(address _assetOne, address _assetTwo) external view returns (bool, uint256); 38 | } -------------------------------------------------------------------------------- /contracts/interfaces/IPriceOracle.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | /** 21 | * @title IPriceOracle 22 | * @author Set Protocol 23 | * 24 | * Interface for interacting with PriceOracle 25 | */ 26 | interface IPriceOracle { 27 | 28 | /* ============ Functions ============ */ 29 | 30 | function getPrice(address _assetOne, address _assetTwo) external view returns (uint256); 31 | function masterQuoteAsset() external view returns (address); 32 | } -------------------------------------------------------------------------------- /contracts/interfaces/ISetTokenCreator.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface ISetTokenCreator { 22 | function create( 23 | address[] memory _components, 24 | int256[] memory _units, 25 | address[] memory _modules, 26 | address _manager, 27 | string memory _name, 28 | string memory _symbol 29 | ) 30 | external 31 | returns (address); 32 | } 33 | -------------------------------------------------------------------------------- /contracts/interfaces/ISetValuer.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "../interfaces/ISetToken.sol"; 21 | 22 | interface ISetValuer { 23 | function calculateSetTokenValuation(ISetToken _setToken, address _quoteAsset) external view returns (uint256); 24 | } -------------------------------------------------------------------------------- /contracts/interfaces/IStakingAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | /** 22 | * @title IStakingAdapter 23 | * @author Set Protocol 24 | * 25 | */ 26 | interface IStakingAdapter { 27 | 28 | function getSpenderAddress(address _stakingContract) external view returns(address); 29 | 30 | function getStakeCallData( 31 | address _stakingContract, 32 | uint256 _notionalAmount 33 | ) 34 | external 35 | view 36 | returns(address, uint256, bytes memory); 37 | 38 | function getUnstakeCallData( 39 | address _stakingContract, 40 | uint256 _notionalAmount 41 | ) 42 | external 43 | view 44 | returns(address, uint256, bytes memory); 45 | } -------------------------------------------------------------------------------- /contracts/interfaces/IStreamingFeeModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | pragma experimental "ABIEncoderV2"; 20 | 21 | import { ISetToken } from "./ISetToken.sol"; 22 | 23 | interface IStreamingFeeModule { 24 | struct FeeState { 25 | address feeRecipient; 26 | uint256 maxStreamingFeePercentage; 27 | uint256 streamingFeePercentage; 28 | uint256 lastStreamingFeeTimestamp; 29 | } 30 | 31 | function feeStates(ISetToken _setToken) external view returns (FeeState memory); 32 | function getFee(ISetToken _setToken) external view returns (uint256); 33 | function accrueFee(ISetToken _setToken) external; 34 | function updateStreamingFee(ISetToken _setToken, uint256 _newFee) external; 35 | function updateFeeRecipient(ISetToken _setToken, address _newFeeRecipient) external; 36 | function initialize(ISetToken _setToken, FeeState memory _settings) external; 37 | } 38 | -------------------------------------------------------------------------------- /contracts/interfaces/ITradeModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | pragma experimental "ABIEncoderV2"; 20 | 21 | import { ISetToken } from "./ISetToken.sol"; 22 | 23 | interface ITradeModule { 24 | function initialize(ISetToken _setToken) external; 25 | 26 | function trade( 27 | ISetToken _setToken, 28 | string memory _exchangeName, 29 | address _sendToken, 30 | uint256 _sendQuantity, 31 | address _receiveToken, 32 | uint256 _minReceiveQuantity, 33 | bytes memory _data 34 | ) external; 35 | } 36 | -------------------------------------------------------------------------------- /contracts/interfaces/IWrapAdapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IWrapAdapter 23 | * @author Set Protocol 24 | * 25 | */ 26 | interface IWrapAdapter { 27 | 28 | function ETH_TOKEN_ADDRESS() external view returns (address); 29 | 30 | function getWrapCallData( 31 | address _underlyingToken, 32 | address _wrappedToken, 33 | uint256 _underlyingUnits 34 | ) external view returns (address _subject, uint256 _value, bytes memory _calldata); 35 | 36 | function getUnwrapCallData( 37 | address _underlyingToken, 38 | address _wrappedToken, 39 | uint256 _wrappedTokenUnits 40 | ) external view returns (address _subject, uint256 _value, bytes memory _calldata); 41 | 42 | function getSpenderAddress(address _underlyingToken, address _wrappedToken) external view returns(address); 43 | } -------------------------------------------------------------------------------- /contracts/interfaces/IWrapModuleV2.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { ISetToken } from "./ISetToken.sol"; 23 | import { IWETH } from "./external/IWETH.sol"; 24 | 25 | interface IWrapModuleV2 { 26 | function weth() external view returns(IWETH); 27 | 28 | function initialize(ISetToken _setToken) external; 29 | 30 | function wrap( 31 | ISetToken _setToken, 32 | address _underlyingToken, 33 | address _wrappedToken, 34 | uint256 _underlyingUnits, 35 | string calldata _integrationName, 36 | bytes memory _wrapData 37 | ) external; 38 | 39 | function wrapWithEther( 40 | ISetToken _setToken, 41 | address _wrappedToken, 42 | uint256 _underlyingUnits, 43 | string calldata _integrationName, 44 | bytes memory _wrapData 45 | ) external; 46 | 47 | function unwrap( 48 | ISetToken _setToken, 49 | address _underlyingToken, 50 | address _wrappedToken, 51 | uint256 _wrappedUnits, 52 | string calldata _integrationName, 53 | bytes memory _unwrapData 54 | ) external; 55 | 56 | function unwrapWithEther( 57 | ISetToken _setToken, 58 | address _wrappedToken, 59 | uint256 _wrappedUnits, 60 | string calldata _integrationName, 61 | bytes memory _unwrapData 62 | ) external; 63 | } 64 | -------------------------------------------------------------------------------- /contracts/interfaces/IWrapV2Adapter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | 21 | /** 22 | * @title IWrapV2Adapter 23 | * @author Set Protocol 24 | */ 25 | interface IWrapV2Adapter { 26 | 27 | function ETH_TOKEN_ADDRESS() external view returns (address); 28 | 29 | function getWrapCallData( 30 | address _underlyingToken, 31 | address _wrappedToken, 32 | uint256 _underlyingUnits, 33 | address _to, 34 | bytes memory _wrapData 35 | ) external view returns (address _subject, uint256 _value, bytes memory _calldata); 36 | 37 | function getUnwrapCallData( 38 | address _underlyingToken, 39 | address _wrappedToken, 40 | uint256 _wrappedTokenUnits, 41 | address _to, 42 | bytes memory _unwrapData 43 | ) external view returns (address _subject, uint256 _value, bytes memory _calldata); 44 | 45 | function getSpenderAddress(address _underlyingToken, address _wrappedToken) external view returns(address); 46 | } -------------------------------------------------------------------------------- /contracts/interfaces/IWrappedFCashFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | pragma solidity 0.6.10; 3 | 4 | interface IWrappedfCashFactory { 5 | function deployWrapper(uint16 currencyId, uint40 maturity) external returns(address); 6 | function computeAddress(uint16 currencyId, uint40 maturity) external view returns(address); 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IAaveLendingPool.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IAaveLendingPool { 22 | function core() external view returns(address); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IAaveLendingPoolCore.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IAaveLendingPoolCore { 22 | function getReserveATokenAddress(address _reserve) external view returns (address); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IComptroller.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { ICErc20 } from "./ICErc20.sol"; 22 | 23 | 24 | /** 25 | * @title IComptroller 26 | * @author Set Protocol 27 | * 28 | * Interface for interacting with Compound Comptroller 29 | */ 30 | interface IComptroller { 31 | 32 | /** 33 | * @notice Add assets to be included in account liquidity calculation 34 | * @param cTokens The list of addresses of the cToken markets to be enabled 35 | * @return Success indicator for whether each corresponding market was entered 36 | */ 37 | function enterMarkets(address[] memory cTokens) external returns (uint[] memory); 38 | 39 | /** 40 | * @notice Removes asset from sender's account liquidity calculation 41 | * @dev Sender must not have an outstanding borrow balance in the asset, 42 | * or be providing neccessary collateral for an outstanding borrow. 43 | * @param cTokenAddress The address of the asset to be removed 44 | * @return Whether or not the account successfully exited the market 45 | */ 46 | function exitMarket(address cTokenAddress) external returns (uint); 47 | 48 | function getAllMarkets() external view returns (ICErc20[] memory); 49 | 50 | function claimComp(address holder) external; 51 | 52 | function compAccrued(address holder) external view returns (uint); 53 | 54 | function getCompAddress() external view returns (address); 55 | } -------------------------------------------------------------------------------- /contracts/interfaces/external/IDMMFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BUSL-1.1 2 | pragma solidity 0.6.10; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | interface IDMMFactory { 7 | function createPool( 8 | IERC20 tokenA, 9 | IERC20 tokenB, 10 | uint32 ampBps 11 | ) external returns (address pool); 12 | 13 | function setFeeConfiguration(address feeTo, uint16 governmentFeeBps) external; 14 | 15 | function setFeeToSetter(address) external; 16 | 17 | function getFeeConfiguration() external view returns (address feeTo, uint16 governmentFeeBps); 18 | 19 | function feeToSetter() external view returns (address); 20 | 21 | function allPools(uint256) external view returns (address pool); 22 | 23 | function allPoolsLength() external view returns (uint256); 24 | 25 | function getUnamplifiedPool(IERC20 token0, IERC20 token1) external view returns (address); 26 | 27 | function getPools(IERC20 token0, IERC20 token1) 28 | external 29 | view 30 | returns (address[] memory _tokenPools); 31 | 32 | function isPool( 33 | IERC20 token0, 34 | IERC20 token1, 35 | address pool 36 | ) external view returns (bool); 37 | } 38 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IDMMPool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BUSL-1.1 2 | pragma solidity 0.6.10; 3 | 4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | import "./IDMMFactory.sol"; 7 | 8 | interface IDMMPool { 9 | function mint(address to) external returns (uint256 liquidity); 10 | 11 | function burn(address to) external returns (uint256 amount0, uint256 amount1); 12 | 13 | function swap( 14 | uint256 amount0Out, 15 | uint256 amount1Out, 16 | address to, 17 | bytes calldata data 18 | ) external; 19 | 20 | function sync() external; 21 | 22 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1); 23 | 24 | function getTradeInfo() 25 | external 26 | view 27 | returns ( 28 | uint112 _vReserve0, 29 | uint112 _vReserve1, 30 | uint112 reserve0, 31 | uint112 reserve1, 32 | uint256 feeInPrecision 33 | ); 34 | 35 | function token0() external view returns (IERC20); 36 | 37 | function token1() external view returns (IERC20); 38 | 39 | function ampBps() external view returns (uint32); 40 | 41 | function factory() external view returns (IDMMFactory); 42 | 43 | function kLast() external view returns (uint256); 44 | } -------------------------------------------------------------------------------- /contracts/interfaces/external/IGaugeController.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IGaugeController { 22 | function gauge_types(address _gauge) external view returns (int128); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IKyberNetworkProxy.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IKyberNetworkProxy { 22 | function getExpectedRate( 23 | address _src, 24 | address _dest, 25 | uint256 _srcQty 26 | ) 27 | external 28 | view 29 | returns (uint256, uint256); 30 | 31 | function trade( 32 | address _src, 33 | uint256 _srcAmount, 34 | address _dest, 35 | address _destAddress, 36 | uint256 _maxDestAmount, 37 | uint256 _minConversionRate, 38 | address _referalFeeAddress 39 | ) 40 | external 41 | payable 42 | returns (uint256); 43 | } 44 | -------------------------------------------------------------------------------- /contracts/interfaces/external/INotionalProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.11; 3 | import { NotionalProxy } from "notional-solidity-sdk/interfaces/notional/NotionalProxy.sol"; 4 | 5 | interface INotionalProxy is NotionalProxy {} 6 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IStableSwapPool.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | SPDX-License-Identifier: Apache License, Version 2.0 13 | */ 14 | 15 | pragma solidity 0.6.10; 16 | 17 | /** 18 | * Curve StableSwap ERC20 <-> ERC20 pool. 19 | */ 20 | interface IStableSwapPool { 21 | 22 | function exchange( 23 | int128 i, 24 | int128 j, 25 | uint256 dx, 26 | uint256 min_dy 27 | ) external payable returns (uint256); 28 | 29 | function coins(uint256) external view returns (address); 30 | } 31 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IStakingRewards.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IStakingRewards { 22 | function balanceOf(address account) external view returns (uint256); 23 | function earned(address account) external view returns (uint256); 24 | function stake(uint256 amount) external; 25 | function withdraw(uint256 amount) external; 26 | function getReward() external; 27 | } -------------------------------------------------------------------------------- /contracts/interfaces/external/ISynth.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | // https://docs.synthetix.io/contracts/source/interfaces/isynth 22 | interface ISynth { 23 | function currencyKey() external view returns (bytes32); 24 | } 25 | -------------------------------------------------------------------------------- /contracts/interfaces/external/ISynthetixExchanger.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | // https://docs.synthetix.io/contracts/source/interfaces/iExchanger 22 | interface ISynthetixExchanger { 23 | function getAmountsForExchange( 24 | uint sourceAmount, 25 | bytes32 sourceCurrencyKey, 26 | bytes32 destinationCurrencyKey 27 | ) 28 | external 29 | view 30 | returns ( 31 | uint amountReceived, 32 | uint fee, 33 | uint exchangeFeeRate 34 | ); 35 | 36 | function exchange( 37 | address from, 38 | bytes32 sourceCurrencyKey, 39 | uint sourceAmount, 40 | bytes32 destinationCurrencyKey, 41 | address destinationAddress 42 | ) external returns (uint amountReceived); 43 | } 44 | -------------------------------------------------------------------------------- /contracts/interfaces/external/IUniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache License, Version 2.0 2 | pragma solidity 0.6.10; 3 | 4 | interface IUniswapV2Factory { 5 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 6 | 7 | function getPair(address tokenA, address tokenB) external view returns (address pair); 8 | function allPairs(uint) external view returns (address pair); 9 | function allPairsLength() external view returns (uint); 10 | 11 | function feeTo() external view returns (address); 12 | function feeToSetter() external view returns (address); 13 | 14 | function createPair(address tokenA, address tokenB) external returns (address pair); 15 | } -------------------------------------------------------------------------------- /contracts/interfaces/external/IWETH.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 22 | 23 | /** 24 | * @title IWETH 25 | * @author Set Protocol 26 | * 27 | * Interface for Wrapped Ether. This interface allows for interaction for wrapped ether's deposit and withdrawal 28 | * functionality. 29 | */ 30 | interface IWETH is IERC20{ 31 | function deposit() 32 | external 33 | payable; 34 | 35 | function withdraw( 36 | uint256 wad 37 | ) 38 | external; 39 | } -------------------------------------------------------------------------------- /contracts/interfaces/external/IYearnVault.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IYearnVault { 22 | function token() external view returns(address); 23 | function pricePerShare() external view returns(uint256); 24 | } 25 | -------------------------------------------------------------------------------- /contracts/interfaces/external/aave-v2/IAToken.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 21 | interface IAToken is IERC20 { 22 | function UNDERLYING_ASSET_ADDRESS() external view returns (address); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/interfaces/external/aave-v2/IProtocolDataProvider.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | pragma experimental ABIEncoderV2; 20 | 21 | import { ILendingPoolAddressesProvider } from "./ILendingPoolAddressesProvider.sol"; 22 | 23 | interface IProtocolDataProvider { 24 | struct TokenData { 25 | string symbol; 26 | address tokenAddress; 27 | } 28 | 29 | function ADDRESSES_PROVIDER() external view returns (ILendingPoolAddressesProvider); 30 | function getAllReservesTokens() external view returns (TokenData[] memory); 31 | function getAllATokens() external view returns (TokenData[] memory); 32 | function getReserveConfigurationData(address asset) external view returns (uint256 decimals, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus, uint256 reserveFactor, bool usageAsCollateralEnabled, bool borrowingEnabled, bool stableBorrowRateEnabled, bool isActive, bool isFrozen); 33 | function getReserveData(address asset) external view returns (uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp); 34 | function getUserReserveData(address asset, address user) external view returns (uint256 currentATokenBalance, uint256 currentStableDebt, uint256 currentVariableDebt, uint256 principalStableDebt, uint256 scaledVariableDebt, uint256 stableBorrowRate, uint256 liquidityRate, uint40 stableRateLastUpdated, bool usageAsCollateralEnabled); 35 | function getReserveTokensAddresses(address asset) external view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress); 36 | } -------------------------------------------------------------------------------- /contracts/interfaces/external/aave-v2/IStableDebtToken.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 21 | 22 | /** 23 | * @title IStableDebtToken 24 | * @notice Defines the interface for the stable debt token 25 | * @author Aave 26 | **/ 27 | 28 | interface IStableDebtToken is IERC20 {} 29 | -------------------------------------------------------------------------------- /contracts/interfaces/external/aave-v2/IVariableDebtToken.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 21 | 22 | /** 23 | * @title IVariableDebtToken 24 | * @author Aave 25 | * @notice Defines the basic interface for a variable debt token. 26 | **/ 27 | interface IVariableDebtToken is IERC20 {} 28 | -------------------------------------------------------------------------------- /contracts/interfaces/external/aave-v2/lib/DataTypes.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | library DataTypes { 21 | // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. 22 | struct ReserveData { 23 | //stores the reserve configuration 24 | ReserveConfigurationMap configuration; 25 | //the liquidity index. Expressed in ray 26 | uint128 liquidityIndex; 27 | //variable borrow index. Expressed in ray 28 | uint128 variableBorrowIndex; 29 | //the current supply rate. Expressed in ray 30 | uint128 currentLiquidityRate; 31 | //the current variable borrow rate. Expressed in ray 32 | uint128 currentVariableBorrowRate; 33 | //the current stable borrow rate. Expressed in ray 34 | uint128 currentStableBorrowRate; 35 | uint40 lastUpdateTimestamp; 36 | //tokens addresses 37 | address aTokenAddress; 38 | address stableDebtTokenAddress; 39 | address variableDebtTokenAddress; 40 | //address of the interest rate strategy 41 | address interestRateStrategyAddress; 42 | //the id of the reserve. Represents the position in the list of the active reserves 43 | uint8 id; 44 | } 45 | 46 | struct ReserveConfigurationMap { 47 | //bit 0-15: LTV 48 | //bit 16-31: Liq. threshold 49 | //bit 32-47: Liq. bonus 50 | //bit 48-55: Decimals 51 | //bit 56: Reserve is active 52 | //bit 57: reserve is frozen 53 | //bit 58: borrowing is enabled 54 | //bit 59: stable rate borrowing enabled 55 | //bit 60-63: reserved 56 | //bit 64-79: reserve factor 57 | uint256 data; 58 | } 59 | 60 | struct UserConfigurationMap { 61 | uint256 data; 62 | } 63 | 64 | enum InterestRateMode {NONE, STABLE, VARIABLE} 65 | } 66 | -------------------------------------------------------------------------------- /contracts/interfaces/external/perp-v2/IAccountBalance.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental ABIEncoderV2; 21 | 22 | interface IAccountBalance { 23 | function getBaseTokens(address trader) external view returns (address[] memory); 24 | function hasOrder(address trader) external view returns (bool); 25 | function getMarginRequirementForLiquidation(address trader) external view returns (int256); 26 | function getTotalDebtValue(address trader) external view returns (uint256); 27 | function getPnlAndPendingFee(address trader) external view returns (int256,int256,uint256); 28 | function getBase(address trader, address baseToken) external view returns (int256); 29 | function getQuote(address trader, address baseToken) external view returns (int256); 30 | function getNetQuoteBalanceAndPendingFee(address trader) external view returns (int256, uint256); 31 | function getTotalPositionSize(address trader, address baseToken) external view returns (int256); 32 | function getTotalPositionValue(address trader, address baseToken) external view returns (int256); 33 | function getTotalAbsPositionValue(address trader) external view returns (uint256); 34 | function getClearingHouseConfig() external view returns (address); 35 | function getExchange() external view returns (address); 36 | function getOrderBook() external view returns (address); 37 | function getVault() external view returns (address); 38 | function getTakerPositionSize(address trader, address baseToken) external view returns (int256); 39 | function getTakerOpenNotional(address trader, address baseToken) external view returns (int256); 40 | } 41 | -------------------------------------------------------------------------------- /contracts/interfaces/external/perp-v2/IClearingHouseConfig.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental ABIEncoderV2; 21 | 22 | interface IClearingHouseConfig { 23 | function getImRatio() external view returns (uint24 imRatio); 24 | } 25 | -------------------------------------------------------------------------------- /contracts/interfaces/external/perp-v2/IIndexPrice.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IIndexPrice { 22 | function getIndexPrice(uint256 interval) external view returns (uint256 indexPrice); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/interfaces/external/perp-v2/IMarketRegistry.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental ABIEncoderV2; 21 | 22 | interface IMarketRegistry { 23 | // 24 | // EXTERNAL VIEW 25 | // 26 | 27 | function getPool(address baseToken) external view returns (address); 28 | 29 | function getQuoteToken() external view returns (address); 30 | 31 | function getUniswapV3Factory() external view returns (address); 32 | 33 | function hasPool(address baseToken) external view returns (bool); 34 | } 35 | -------------------------------------------------------------------------------- /contracts/interfaces/external/perp-v2/IQuoter.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental ABIEncoderV2; 21 | 22 | interface IQuoter { 23 | struct SwapParams { 24 | address baseToken; 25 | bool isBaseToQuote; 26 | bool isExactInput; 27 | uint256 amount; 28 | uint160 sqrtPriceLimitX96; // price slippage protection 29 | } 30 | 31 | struct SwapResponse { 32 | uint256 deltaAvailableBase; 33 | uint256 deltaAvailableQuote; 34 | int256 exchangedPositionSize; 35 | int256 exchangedPositionNotional; 36 | uint160 sqrtPriceX96; 37 | } 38 | 39 | function swap(SwapParams memory params) external returns (SwapResponse memory response); 40 | } 41 | -------------------------------------------------------------------------------- /contracts/interfaces/external/perp-v2/IVault.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | interface IVault { 22 | function getBalance(address account) external view returns (int256); 23 | function decimals() external view returns (uint8); 24 | function getFreeCollateral(address trader) external view returns (uint256); 25 | function getFreeCollateralByRatio(address trader, uint24 ratio) external view returns (int256); 26 | function getLiquidateMarginRequirement(address trader) external view returns (int256); 27 | function getSettlementToken() external view returns (address); 28 | function getAccountBalance() external view returns (address); 29 | function getClearingHouse() external view returns (address); 30 | function getExchange() external view returns (address); 31 | } 32 | -------------------------------------------------------------------------------- /contracts/lib/BytesArrayUtils.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | /** 22 | * @title BytesArrayUtils 23 | * @author Set Protocol 24 | * 25 | * Utility library to type cast bytes arrays. Extends BytesLib (external/contracts/uniswap/v3/lib/BytesLib.sol) 26 | * library functionality. 27 | */ 28 | library BytesArrayUtils { 29 | 30 | /** 31 | * Type cast byte to boolean. 32 | * @param _bytes Bytes array 33 | * @param _start Starting index 34 | * @return bool Boolean value 35 | */ 36 | function toBool(bytes memory _bytes, uint256 _start) internal pure returns (bool) { 37 | require(_start + 1 >= _start, "toBool_overflow"); 38 | require(_bytes.length >= _start + 1, "toBool_outOfBounds"); 39 | uint8 tempUint; 40 | 41 | assembly { 42 | tempUint := mload(add(add(_bytes, 0x1), _start)) 43 | } 44 | 45 | require(tempUint <= 1, "Invalid bool data"); // Should be either 0 or 1 46 | 47 | return (tempUint == 0) ? false : true; 48 | } 49 | } -------------------------------------------------------------------------------- /contracts/lib/StringArrayUtils.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | /** 22 | * @title StringArrayUtils 23 | * @author Set Protocol 24 | * 25 | * Utility functions to handle String Arrays 26 | */ 27 | library StringArrayUtils { 28 | 29 | /** 30 | * Finds the index of the first occurrence of the given element. 31 | * @param A The input string to search 32 | * @param a The value to find 33 | * @return Returns (index and isIn) for the first occurrence starting from index 0 34 | */ 35 | function indexOf(string[] memory A, string memory a) internal pure returns (uint256, bool) { 36 | uint256 length = A.length; 37 | for (uint256 i = 0; i < length; i++) { 38 | if (keccak256(bytes(A[i])) == keccak256(bytes(a))) { 39 | return (i, true); 40 | } 41 | } 42 | return (uint256(-1), false); 43 | } 44 | 45 | /** 46 | * @param A The input array to search 47 | * @param a The string to remove 48 | */ 49 | function removeStorage(string[] storage A, string memory a) 50 | internal 51 | { 52 | (uint256 index, bool isIn) = indexOf(A, a); 53 | if (!isIn) { 54 | revert("String not in array."); 55 | } else { 56 | uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here 57 | if (index != lastIndex) { A[index] = A[lastIndex]; } 58 | A.pop(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /contracts/lib/Uint256ArrayUtils.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | /** 22 | * @title Uint256ArrayUtils 23 | * @author Set Protocol 24 | * 25 | * Utility functions to handle Uint256 Arrays 26 | */ 27 | library Uint256ArrayUtils { 28 | 29 | /** 30 | * Returns the combination of the two arrays 31 | * @param A The first array 32 | * @param B The second array 33 | * @return Returns A extended by B 34 | */ 35 | function extend(uint256[] memory A, uint256[] memory B) internal pure returns (uint256[] memory) { 36 | uint256 aLength = A.length; 37 | uint256 bLength = B.length; 38 | uint256[] memory newUints = new uint256[](aLength + bLength); 39 | for (uint256 i = 0; i < aLength; i++) { 40 | newUints[i] = A[i]; 41 | } 42 | for (uint256 j = 0; j < bLength; j++) { 43 | newUints[aLength + j] = B[j]; 44 | } 45 | return newUints; 46 | } 47 | } -------------------------------------------------------------------------------- /contracts/mocks/BytesArrayUtilsMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { BytesArrayUtils } from "../lib/BytesArrayUtils.sol"; 23 | 24 | 25 | contract BytesArrayUtilsMock { 26 | using BytesArrayUtils for bytes; 27 | 28 | function testToBool(bytes memory _bytes, uint256 _start) external pure returns (bool) { 29 | return _bytes.toBool(_start); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts/mocks/ContractCallerMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { Address } from "@openzeppelin/contracts/utils/Address.sol"; 22 | 23 | 24 | contract ContractCallerMock { 25 | using Address for address; 26 | 27 | constructor() public {} 28 | 29 | function invoke( 30 | address _target, 31 | uint256 _value, 32 | bytes calldata _data 33 | ) 34 | external 35 | returns (bytes memory _returnValue) 36 | { 37 | _returnValue = _target.functionCallWithValue(_data, _value); 38 | 39 | return _returnValue; 40 | } 41 | } -------------------------------------------------------------------------------- /contracts/mocks/ExplicitERC20Mock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { ExplicitERC20 } from "../lib/ExplicitERC20.sol"; 23 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 24 | 25 | contract ExplicitERC20Mock { 26 | 27 | function transferFrom( 28 | IERC20 _token, 29 | address _from, 30 | address _to, 31 | uint256 _quantity 32 | ) 33 | external 34 | { 35 | ExplicitERC20.transferFrom( 36 | _token, 37 | _from, 38 | _to, 39 | _quantity 40 | ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /contracts/mocks/ForceFunderMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | 22 | contract ForceFunderMock { 23 | /** 24 | * Convenience method for depositing eth into non-payable contracts 25 | * which the forked provider tests would like to impersonate 26 | * as a message sender. 27 | * 28 | * @param destination destination of eth payment 29 | */ 30 | function fund(address destination) public payable { 31 | selfdestruct(payable(address(destination))); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /contracts/mocks/GodModeMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { IController } from "../interfaces/IController.sol"; 22 | import { ISetToken } from "../interfaces/ISetToken.sol"; 23 | import { ModuleBase } from "../protocol/lib/ModuleBase.sol"; 24 | 25 | 26 | contract GodModeMock is ModuleBase { 27 | 28 | constructor(IController _controller) public ModuleBase(_controller) {} 29 | 30 | function transferTokens( 31 | ISetToken _setToken, 32 | address _component, 33 | address _to, 34 | uint256 _amount 35 | ) 36 | external 37 | { 38 | _setToken.invokeTransfer(_component, _to, _amount); 39 | } 40 | 41 | function initialize(ISetToken _setToken) external { _setToken.initializeModule(); } 42 | 43 | function removeModule() external override {} 44 | } -------------------------------------------------------------------------------- /contracts/mocks/OracleAdapterMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; 22 | import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; 23 | 24 | import { IOracle } from "../interfaces/IOracle.sol"; 25 | 26 | contract OracleAdapterMock { 27 | 28 | uint256 public dummyPrice; 29 | address public asset; 30 | 31 | constructor(address _asset, uint256 _dummyPrice) 32 | public 33 | { dummyPrice = _dummyPrice; asset = _asset; } 34 | 35 | function getPrice(address _assetOne, address _assetTwo) 36 | external 37 | view 38 | returns (bool, uint256) 39 | { 40 | _assetTwo; // Used to silence compiler warnings 41 | 42 | if (_assetOne == asset) { 43 | return (true, dummyPrice); 44 | } else { 45 | return (false, 0); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /contracts/mocks/OracleMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | contract OracleMock { 22 | uint256 public price; 23 | 24 | constructor(uint256 _startingPrice) public { 25 | price = _startingPrice; 26 | } 27 | 28 | /* ============ External Functions ============ */ 29 | function updatePrice(uint256 _newPrice) external { 30 | price = _newPrice; 31 | } 32 | 33 | /** 34 | * Returns the queried data from an oracle returning uint256 35 | * 36 | * @return Current price of asset represented in uint256 37 | */ 38 | function read() external view returns (uint256) { 39 | return price; 40 | } 41 | } -------------------------------------------------------------------------------- /contracts/mocks/StandardTokenMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; 22 | 23 | // mock class using BasicToken 24 | contract StandardTokenMock is ERC20 { 25 | constructor( 26 | address _initialAccount, 27 | uint256 _initialBalance, 28 | string memory _name, 29 | string memory _symbol, 30 | uint8 _decimals 31 | ) 32 | public 33 | ERC20(_name, _symbol) 34 | { 35 | _mint(_initialAccount, _initialBalance); 36 | _setupDecimals(_decimals); 37 | } 38 | 39 | function mint(address to, uint amount) external { 40 | _mint(to, amount); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /contracts/mocks/StringArrayUtilsMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { StringArrayUtils } from "../lib/StringArrayUtils.sol"; 23 | 24 | 25 | contract StringArrayUtilsMock { 26 | using StringArrayUtils for string[]; 27 | 28 | string[] public storageArray; 29 | 30 | function testIndexOf(string[] memory A, string memory a) external pure returns (uint256, bool) { 31 | return A.indexOf(a); 32 | } 33 | 34 | function testRemoveStorage(string memory a) external { 35 | storageArray.removeStorage(a); 36 | } 37 | 38 | function setStorageArray(string[] memory A) external { 39 | storageArray = A; 40 | } 41 | 42 | function getStorageArray() external view returns(string[] memory) { 43 | return storageArray; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/mocks/Uint256ArrayUtilsMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { Uint256ArrayUtils } from "../lib/Uint256ArrayUtils.sol"; 23 | 24 | 25 | contract Uint256ArrayUtilsMock { 26 | using Uint256ArrayUtils for uint256[]; 27 | 28 | function testExtend(uint256[] memory A, uint256[] memory B) external pure returns (uint256[] memory) { 29 | return A.extend(B); 30 | } 31 | } -------------------------------------------------------------------------------- /contracts/mocks/UnitConversionUtilsMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { UnitConversionUtils } from "../lib/UnitConversionUtils.sol"; 22 | 23 | contract UnitConversionUtilsMock { 24 | using UnitConversionUtils for int256; 25 | using UnitConversionUtils for uint256; 26 | 27 | /* ============ External ============ */ 28 | 29 | function testFromPreciseUnitToDecimalsUint(uint256 _amount, uint8 _decimals) 30 | public 31 | pure 32 | returns (uint256) 33 | { 34 | return _amount.fromPreciseUnitToDecimals(_decimals); 35 | } 36 | 37 | function testFromPreciseUnitToDecimalsInt(int256 _amount, uint8 _decimals) 38 | public 39 | pure 40 | returns (int256) 41 | { 42 | return _amount.fromPreciseUnitToDecimals(_decimals); 43 | } 44 | 45 | function testToPreciseUnitsFromDecimalsInt(int256 _amount, uint8 _decimals) 46 | public 47 | pure 48 | returns (int256) 49 | { 50 | return _amount.toPreciseUnitsFromDecimals(_decimals); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /contracts/mocks/WrappedfCashFactoryMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { IWrappedfCashFactory } from "../interfaces/IWrappedFCashFactory.sol"; 23 | import { WrappedfCashMock } from "./WrappedfCashMock.sol"; 24 | 25 | 26 | // mock class using BasicToken 27 | contract WrappedfCashFactoryMock is IWrappedfCashFactory { 28 | 29 | mapping(uint16 => mapping(uint40 => address)) paramsToAddress; 30 | bool private revertComputeAddress; 31 | 32 | function registerWrapper(uint16 _currencyId, uint40 _maturity, address _fCashWrapper) external { 33 | paramsToAddress[_currencyId][_maturity] = _fCashWrapper; 34 | } 35 | 36 | function deployWrapper(uint16 _currencyId, uint40 _maturity) external override returns(address) { 37 | return computeAddress(_currencyId, _maturity); 38 | } 39 | 40 | function computeAddress(uint16 _currencyId, uint40 _maturity) public view override returns(address) { 41 | require(!revertComputeAddress, "Test revertion ComputeAddress"); 42 | return paramsToAddress[_currencyId][_maturity]; 43 | } 44 | 45 | function setRevertComputeAddress(bool _revertComputeAddress) external{ 46 | revertComputeAddress = _revertComputeAddress; 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /contracts/mocks/external/CompoundPriceOracleMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | contract CompoundPriceOracleMock { 22 | mapping(address => uint256) public assetToPrices; 23 | 24 | /* ============ External Functions ============ */ 25 | function setUnderlyingPrice(address _token, uint256 _newPrice) external { 26 | assetToPrices[_token] = _newPrice; 27 | } 28 | 29 | function getUnderlyingPrice(address _asset) external view returns (uint256) { 30 | return assetToPrices[_asset]; 31 | } 32 | } -------------------------------------------------------------------------------- /contracts/mocks/external/GaugeControllerMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | /** 22 | * @title GaugeControllerMock 23 | * @author Set Protocol 24 | * 25 | * Mocks similar behaviour of the Curve GaugeController contract 26 | */ 27 | contract GaugeControllerMock { 28 | 29 | mapping(address => int128) internal types; 30 | 31 | function addGaugeType(address _gauge, int128 _type) external { 32 | types[_gauge] = _type + 1; 33 | } 34 | 35 | function gauge_types(address _gauge) external view returns (int128) { 36 | int128 gaugeType = types[_gauge]; 37 | 38 | require(gaugeType != 0, "Not valid"); 39 | return gaugeType - 1; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/mocks/external/LendingPoolAddressProviderMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | /** 22 | * @title LendingPoolAddressesProviderMock 23 | * @author Set Protocol 24 | * @notice Mock contract for Aave's LendingPoolAddressesProvider 25 | */ 26 | contract LendingPoolAddressesProviderMock { 27 | 28 | mapping(bytes32 => address) private _addresses; 29 | bytes32 private constant LENDING_POOL = "LENDING_POOL"; 30 | 31 | function setAddress(bytes32 id, address newAddress) external { 32 | _addresses[id] = newAddress; 33 | } 34 | 35 | function getAddress(bytes32 id) public view returns (address) { 36 | return _addresses[id]; 37 | } 38 | 39 | function getLendingPool() external view returns (address) { 40 | return getAddress(LENDING_POOL); 41 | } 42 | } -------------------------------------------------------------------------------- /contracts/mocks/external/ProtocolDataProvider.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental ABIEncoderV2; 21 | 22 | import "../../interfaces/external/aave-v2/IProtocolDataProvider.sol"; 23 | 24 | /** 25 | * @title ProtocolDataProviderMock 26 | * @author Set Protocol 27 | * @notice Mock contract for Aave's ProtocolDataProvider 28 | */ 29 | contract ProtocolDataProviderMock { 30 | function getAllReservesTokens() external pure returns (IProtocolDataProvider.TokenData[] memory) { 31 | return new IProtocolDataProvider.TokenData[](0); 32 | } 33 | } -------------------------------------------------------------------------------- /contracts/mocks/external/SynthMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import "../StandardTokenMock.sol"; 22 | 23 | // mock class using BasicToken 24 | contract SynthMock is StandardTokenMock { 25 | bytes32 public currencyKey; 26 | 27 | constructor( 28 | address _initialAccount, 29 | uint256 _initialBalance, 30 | string memory _name, 31 | string memory _symbol, 32 | uint8 _decimals, 33 | bytes32 _currencyKey 34 | ) 35 | public 36 | StandardTokenMock( 37 | _initialAccount, 38 | _initialBalance, 39 | _name, 40 | _symbol, 41 | _decimals 42 | ) 43 | { 44 | currencyKey = _currencyKey; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/mocks/external/TribePegExchangerMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 22 | import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 23 | 24 | /** 25 | * @title Contract to exchange RGT with TRIBE post-merger 26 | */ 27 | contract TribePegExchangerMock { 28 | using SafeERC20 for IERC20; 29 | 30 | /// @notice the multiplier applied to RGT before converting to TRIBE scaled up by 1e9 31 | uint256 public constant exchangeRate = 26705673430; // 26.7 TRIBE / RGT 32 | /// @notice the granularity of the exchange rate 33 | uint256 public constant scalar = 1e9; 34 | 35 | event Exchange(address indexed from, uint256 amountIn, uint256 amountOut); 36 | 37 | address public immutable rgt; 38 | address public immutable tribe; 39 | 40 | constructor(address _rgt, address _tribe) public { 41 | rgt = _rgt; 42 | tribe = _tribe; 43 | } 44 | 45 | /// @notice call to exchange held RGT with TRIBE 46 | /// @param amount the amount to exchange 47 | /// Mirrors the real contract without the permission state checks. 48 | function exchange(uint256 amount) public { 49 | uint256 tribeOut = amount * exchangeRate / scalar; 50 | IERC20(rgt).safeTransferFrom(msg.sender, address(this), amount); 51 | IERC20(tribe).safeTransfer(msg.sender, tribeOut); 52 | emit Exchange(msg.sender, amount, tribeOut); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /contracts/mocks/external/YearnVaultMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | contract YearnVaultMock { 22 | uint256 public pricePerShare; 23 | 24 | constructor(uint256 _pricePerShare) public { 25 | pricePerShare = _pricePerShare; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /contracts/mocks/protocol/CustomSetValuerMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { ISetValuer } from "../../interfaces/ISetValuer.sol"; 23 | import { ISetToken } from "../../interfaces/ISetToken.sol"; 24 | 25 | /** 26 | * @title CustomSetValuerMock 27 | * @author Set Protocol 28 | * 29 | * Contract that returns a mocked valuation for a set. 30 | */ 31 | contract CustomSetValuerMock is ISetValuer { 32 | /* ============ State Variables ============ */ 33 | 34 | mapping (address => uint256) valuation; 35 | 36 | /* ============ External Functions ============ */ 37 | function setValuation(address _quoteAsset, uint256 _valuation) external { 38 | valuation[_quoteAsset] = _valuation; 39 | } 40 | 41 | /** 42 | * Gets the valuation of a SetToken using data from the price oracle. Reverts 43 | * if no price exists for a component in the SetToken. Note: this works for external 44 | * positions and negative (debt) positions. 45 | * 46 | * Note: There is a risk that the valuation is off if airdrops aren't retrieved or 47 | * debt builds up via interest and its not reflected in the position 48 | * 49 | * @param _quoteAsset Address of token to quote valuation in 50 | * 51 | * @return SetToken valuation in terms of quote asset in precise units 1e18 52 | */ 53 | function calculateSetTokenValuation(ISetToken /* _setToken */, address _quoteAsset) external view override returns (uint256) { 54 | return valuation[_quoteAsset]; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /contracts/mocks/protocol/integration/AaveLendingPoolCoreMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | contract AaveLendingPoolCoreMock { 22 | 23 | mapping(address => address) public reserves; 24 | 25 | function getReserveATokenAddress(address _reserve) public view returns (address) { 26 | return reserves[_reserve]; 27 | } 28 | 29 | function setReserveATokenAddress(address _reserve, address _aToken) public { 30 | reserves[_reserve] = _aToken; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /contracts/mocks/protocol/integration/AaveLendingPoolMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | contract AaveLendingPoolMock { 22 | 23 | address public core; 24 | 25 | constructor(address _core) public { 26 | core = _core; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/mocks/protocol/integration/lib/UniswapV3MathMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental ABIEncoderV2; 21 | 22 | import { UniswapV3Math } from "../../../../protocol/integration/lib/UniswapV3Math.sol"; 23 | 24 | /** 25 | * @title UniswapV3MathMock 26 | * @author Set Protocol 27 | * 28 | * Mock for UniswapV3Math Library contract. Used for testing UniswapV3Math Library contract, as the library 29 | * contract can't be tested directly using ethers.js 30 | */ 31 | contract UniswapV3MathMock { 32 | using UniswapV3Math for uint160; 33 | using UniswapV3Math for uint256; 34 | 35 | /* ============ External ============ */ 36 | 37 | function testFormatSqrtPriceX96ToPriceX96(uint160 _sqrtPriceX96) 38 | public 39 | pure 40 | returns (uint256) 41 | { 42 | return _sqrtPriceX96.formatSqrtPriceX96ToPriceX96(); 43 | } 44 | 45 | function testFormatX96ToX10_18(uint256 _valueX96) 46 | public 47 | pure 48 | returns (uint256) 49 | { 50 | return _valueX96.formatX96ToX10_18(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /contracts/mocks/protocol/lib/InvokeMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 22 | import { Invoke } from "../../../protocol/lib/Invoke.sol"; 23 | 24 | contract InvokeMock { 25 | 26 | /* ============ External Functions ============ */ 27 | 28 | function testInvokeApprove( 29 | ISetToken _setToken, 30 | address _token, 31 | address _spender, 32 | uint256 _quantity 33 | ) external { 34 | Invoke.invokeApprove(_setToken, _token, _spender, _quantity); 35 | } 36 | 37 | function testInvokeTransfer( 38 | ISetToken _setToken, 39 | address _token, 40 | address _spender, 41 | uint256 _quantity 42 | ) external { 43 | Invoke.invokeTransfer(_setToken, _token, _spender, _quantity); 44 | } 45 | 46 | function testStrictInvokeTransfer( 47 | ISetToken _setToken, 48 | address _token, 49 | address _spender, 50 | uint256 _quantity 51 | ) external { 52 | Invoke.strictInvokeTransfer(_setToken, _token, _spender, _quantity); 53 | } 54 | 55 | function testInvokeUnwrapWETH(ISetToken _setToken, address _weth, uint256 _quantity) external { 56 | Invoke.invokeUnwrapWETH(_setToken, _weth, _quantity); 57 | } 58 | 59 | function testInvokeWrapWETH(ISetToken _setToken, address _weth, uint256 _quantity) external { 60 | Invoke.invokeWrapWETH(_setToken, _weth, _quantity); 61 | } 62 | 63 | /* ============ Helper Functions ============ */ 64 | 65 | function initializeModuleOnSet(ISetToken _setToken) external { 66 | _setToken.initializeModule(); 67 | } 68 | } -------------------------------------------------------------------------------- /contracts/mocks/protocol/lib/IssuanceValidationUtilsMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 22 | import { IssuanceValidationUtils } from "../../../protocol/lib/IssuanceValidationUtils.sol"; 23 | 24 | contract IssuanceValidationUtilsMock { 25 | /* ============ External Functions ============ */ 26 | 27 | function testValidateCollateralizationPostTransferInPreHook( 28 | ISetToken _setToken, 29 | address _component, 30 | uint256 _initialSetSupply, 31 | uint256 _componentQuantity 32 | ) 33 | external 34 | view 35 | { 36 | IssuanceValidationUtils.validateCollateralizationPostTransferInPreHook( 37 | _setToken, 38 | _component, 39 | _initialSetSupply, 40 | _componentQuantity 41 | ); 42 | } 43 | 44 | function testValidateCollateralizationPostTransferOut( 45 | ISetToken _setToken, 46 | address _component, 47 | uint256 _finalSetSupply 48 | ) 49 | external 50 | view 51 | { 52 | IssuanceValidationUtils.validateCollateralizationPostTransferOut( 53 | _setToken, 54 | _component, 55 | _finalSetSupply 56 | ); 57 | } 58 | } -------------------------------------------------------------------------------- /contracts/mocks/protocol/lib/ResourceIdentifierMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { IController } from "../../../interfaces/IController.sol"; 22 | import { IIntegrationRegistry } from "../../../interfaces/IIntegrationRegistry.sol"; 23 | import { IPriceOracle } from "../../../interfaces/IPriceOracle.sol"; 24 | import { ISetValuer } from "../../../interfaces/ISetValuer.sol"; 25 | import { ResourceIdentifier } from "../../../protocol/lib/ResourceIdentifier.sol"; 26 | 27 | contract ResourceIdentifierMock { 28 | 29 | /* ============ External Functions ============ */ 30 | 31 | function testGetIntegrationRegistry(IController _controller) external view returns (IIntegrationRegistry) { 32 | 33 | return ResourceIdentifier.getIntegrationRegistry(_controller); 34 | } 35 | 36 | function testGetPriceOracle(IController _controller) external view returns (IPriceOracle) { 37 | return ResourceIdentifier.getPriceOracle(_controller); 38 | } 39 | 40 | function testGetSetValuer(IController _controller) external view returns (ISetValuer) { 41 | return ResourceIdentifier.getSetValuer(_controller); 42 | } 43 | } -------------------------------------------------------------------------------- /contracts/mocks/protocol/lib/SetTokenAccessibleMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { IController } from "../../../interfaces/IController.sol"; 22 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 23 | import { SetTokenAccessible } from "../../../protocol/lib/SetTokenAccessible.sol"; 24 | 25 | contract SetTokenAccessibleMock is SetTokenAccessible { 26 | 27 | constructor(IController _controller) public SetTokenAccessible(_controller) {} 28 | 29 | /* ============ External Functions ============ */ 30 | 31 | function testOnlyAllowedSet(ISetToken _setToken) 32 | external 33 | view 34 | onlyAllowedSet(_setToken) {} 35 | 36 | /* ============ Helper Functions ============ */ 37 | 38 | function initializeModuleOnSet(ISetToken _setToken) external { 39 | _setToken.initializeModule(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/mocks/protocol/module/DebtIssuanceMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 21 | 22 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 23 | 24 | contract DebtIssuanceMock { 25 | 26 | mapping(ISetToken => bool) public isRegistered; 27 | 28 | function initialize(ISetToken _setToken) external { 29 | _setToken.initializeModule(); 30 | } 31 | 32 | function removeModule() external {} 33 | 34 | function registerToIssuanceModule(ISetToken _setToken) external { 35 | isRegistered[_setToken] = true; 36 | } 37 | 38 | function unregisterFromIssuanceModule(ISetToken _setToken) external { 39 | isRegistered[_setToken] = false; 40 | } 41 | } -------------------------------------------------------------------------------- /contracts/mocks/protocol/module/ManagerIssuanceHookMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 21 | 22 | contract ManagerIssuanceHookMock { 23 | ISetToken public retrievedSetToken; 24 | uint256 public retrievedIssueQuantity; 25 | address public retrievedSender; 26 | address public retrievedTo; 27 | 28 | function invokePreIssueHook(ISetToken _setToken, uint256 _issueQuantity, address _sender, address _to) external { 29 | retrievedSetToken = _setToken; 30 | retrievedIssueQuantity = _issueQuantity; 31 | retrievedSender = _sender; 32 | retrievedTo = _to; 33 | } 34 | 35 | function invokePreRedeemHook(ISetToken _setToken, uint256 _redeemQuantity, address _sender, address _to) external { 36 | retrievedSetToken = _setToken; 37 | retrievedIssueQuantity = _redeemQuantity; 38 | retrievedSender = _sender; 39 | retrievedTo = _to; 40 | } 41 | } -------------------------------------------------------------------------------- /contracts/mocks/protocol/module/NAVIssuanceCaller.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 23 | 24 | import { INAVIssuanceModule } from "../../../interfaces/INAVIssuanceModule.sol"; 25 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 26 | 27 | 28 | contract NAVIssuanceCaller { 29 | INAVIssuanceModule public navIssuance; 30 | 31 | constructor(INAVIssuanceModule _navIssuance) public { navIssuance = _navIssuance; } 32 | 33 | function issue( 34 | ISetToken _setToken, 35 | address _reserveAsset, 36 | uint256 _reserveAssetQuantity, 37 | uint256 _minSetTokenReceiveQuantity, 38 | address _to 39 | ) 40 | external 41 | { 42 | IERC20(_reserveAsset).approve(address(navIssuance), _reserveAssetQuantity); 43 | navIssuance.issue( 44 | _setToken, 45 | _reserveAsset, 46 | _reserveAssetQuantity, 47 | _minSetTokenReceiveQuantity, 48 | _to 49 | ); 50 | } 51 | 52 | function redeem( 53 | ISetToken _setToken, 54 | address _reserveAsset, 55 | uint256 _setTokenQuantity, 56 | uint256 _minReserveReceiveQuantity, 57 | address _to 58 | ) 59 | external 60 | { 61 | navIssuance.redeem( 62 | _setToken, 63 | _reserveAsset, 64 | _setTokenQuantity, 65 | _minReserveReceiveQuantity, 66 | _to 67 | ); 68 | } 69 | } -------------------------------------------------------------------------------- /contracts/mocks/protocol/module/NAVIssuanceHookMock.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | 20 | import { ISetToken } from "../../../interfaces/ISetToken.sol"; 21 | 22 | contract NAVIssuanceHookMock { 23 | ISetToken public retrievedSetToken; 24 | address public retrievedReserveAsset; 25 | uint256 public retrievedReserveAssetQuantity; 26 | address public retrievedSender; 27 | uint256 public retrievedRedeemQuantity; 28 | address public retrievedTo; 29 | 30 | function invokePreIssueHook( 31 | ISetToken _setToken, 32 | address _reserveAsset, 33 | uint256 _reserveAssetQuantity, 34 | address _sender, 35 | address _to 36 | ) 37 | external 38 | { 39 | retrievedSetToken = _setToken; 40 | retrievedReserveAsset = _reserveAsset; 41 | retrievedReserveAssetQuantity = _reserveAssetQuantity; 42 | retrievedSender = _sender; 43 | retrievedTo = _to; 44 | } 45 | 46 | function invokePreRedeemHook( 47 | ISetToken _setToken, 48 | uint256 _redeemQuantity, 49 | address _sender, 50 | address _to 51 | ) 52 | external 53 | { 54 | retrievedSetToken = _setToken; 55 | retrievedRedeemQuantity = _redeemQuantity; 56 | retrievedSender = _sender; 57 | retrievedTo = _to; 58 | } 59 | } -------------------------------------------------------------------------------- /contracts/product/TokenEnabler.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | 21 | import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; 22 | 23 | import { IController } from "../interfaces/IController.sol"; 24 | 25 | contract TokenEnabler is Ownable { 26 | 27 | IController public immutable controller; 28 | address[] public tokensToEnable; 29 | 30 | /* ============ Constructor ============ */ 31 | 32 | constructor( 33 | IController _controller, 34 | address[] memory _tokensToEnable 35 | ) 36 | public 37 | Ownable() 38 | { 39 | controller = _controller; 40 | tokensToEnable = _tokensToEnable; 41 | } 42 | 43 | /* ============ External Functions ============ */ 44 | 45 | /** 46 | * ONLY OWNER: Enables tokens on the controller 47 | */ 48 | function enableTokens() external onlyOwner { 49 | for (uint256 i = 0; i < tokensToEnable.length; i++) { 50 | controller.addSet(tokensToEnable[i]); 51 | } 52 | } 53 | 54 | /* ============ View Functions ============ */ 55 | 56 | function getTokensToEnable() external view returns(address[] memory) { 57 | return tokensToEnable; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /contracts/protocol-viewers/ProtocolViewer.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | pragma experimental "ABIEncoderV2"; 20 | 21 | 22 | import { ERC20Viewer } from "./ERC20Viewer.sol"; 23 | import { SetTokenViewer } from "./SetTokenViewer.sol"; 24 | import { StreamingFeeModuleViewer } from "./StreamingFeeModuleViewer.sol"; 25 | 26 | 27 | /** 28 | * @title ProtocolViewer 29 | * @author Set Protocol 30 | * 31 | * ProtocolViewer enables batch queries of various protocol state. 32 | */ 33 | contract ProtocolViewer is 34 | ERC20Viewer, 35 | SetTokenViewer, 36 | StreamingFeeModuleViewer 37 | { 38 | constructor() public {} 39 | } 40 | -------------------------------------------------------------------------------- /contracts/protocol-viewers/StreamingFeeModuleViewer.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | pragma solidity 0.6.10; 19 | pragma experimental "ABIEncoderV2"; 20 | 21 | 22 | import { ISetToken } from "../interfaces/ISetToken.sol"; 23 | import { IStreamingFeeModule } from "../interfaces/IStreamingFeeModule.sol"; 24 | import { StreamingFeeModule } from "../protocol/modules/v1/StreamingFeeModule.sol"; 25 | 26 | 27 | /** 28 | * @title StreamingFeeModuleViewer 29 | * @author Set Protocol 30 | * 31 | * StreamingFeeModuleViewer enables batch queries of StreamingFeeModule state. 32 | */ 33 | contract StreamingFeeModuleViewer { 34 | 35 | struct StreamingFeeInfo { 36 | address feeRecipient; 37 | uint256 streamingFeePercentage; 38 | uint256 unaccruedFees; 39 | } 40 | 41 | function batchFetchStreamingFeeInfo( 42 | IStreamingFeeModule _streamingFeeModule, 43 | ISetToken[] memory _setTokens 44 | ) 45 | external 46 | view 47 | returns (StreamingFeeInfo[] memory) 48 | { 49 | StreamingFeeInfo[] memory feeInfo = new StreamingFeeInfo[](_setTokens.length); 50 | 51 | for (uint256 i = 0; i < _setTokens.length; i++) { 52 | IStreamingFeeModule.FeeState memory feeState = _streamingFeeModule.feeStates(_setTokens[i]); 53 | uint256 unaccruedFees = _streamingFeeModule.getFee(_setTokens[i]); 54 | 55 | feeInfo[i] = StreamingFeeInfo({ 56 | feeRecipient: feeState.feeRecipient, 57 | streamingFeePercentage: feeState.streamingFeePercentage, 58 | unaccruedFees: unaccruedFees 59 | }); 60 | } 61 | 62 | return feeInfo; 63 | } 64 | } -------------------------------------------------------------------------------- /contracts/protocol/integration/wrap/notional/WrappedfCash.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.11; 3 | import { wfCashERC4626 } from "wrapped-fcash/contracts/wfCashERC4626.sol"; 4 | import { INotionalV2 } from "wrapped-fcash/interfaces/notional/INotionalV2.sol"; 5 | import { IWETH9 } from "wrapped-fcash/interfaces/IWETH9.sol"; 6 | 7 | contract WrappedfCash is wfCashERC4626 { 8 | constructor(INotionalV2 _notionalProxy, IWETH9 _weth) wfCashERC4626(_notionalProxy, _weth){ 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocol/integration/wrap/notional/WrappedfCashFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.11; 3 | import { WrappedfCashFactory as WrappedfCashFactoryBase } from "wrapped-fcash/contracts/proxy/WrappedfCashFactory.sol"; 4 | 5 | contract WrappedfCashFactory is WrappedfCashFactoryBase { 6 | constructor(address _beacon) WrappedfCashFactoryBase(_beacon){ 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocol/integration/wrap/notional/nBeaconProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.11; 3 | import { nBeaconProxy as nBeaconProxyBase } from "wrapped-fcash/contracts/proxy/nBeaconProxy.sol"; 4 | 5 | contract nBeaconProxy is nBeaconProxyBase { 6 | constructor(address beacon, bytes memory data) payable nBeaconProxyBase(beacon, data) { } 7 | } 8 | -------------------------------------------------------------------------------- /contracts/protocol/integration/wrap/notional/nUpgradeableBeacon.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.11; 3 | 4 | import "openzeppelin-contracts-V4/proxy/beacon/UpgradeableBeacon.sol"; 5 | 6 | /// @dev Re-exporting to make available to brownie 7 | /// UpgradeableBeacon is Ownable, default owner is the deployer 8 | contract nUpgradeableBeacon is UpgradeableBeacon { 9 | constructor(address implementation_) UpgradeableBeacon(implementation_) {} 10 | } 11 | 12 | -------------------------------------------------------------------------------- /contracts/protocol/modules/v1/IssuanceModule.sol: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Set Labs Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | SPDX-License-Identifier: Apache License, Version 2.0 17 | */ 18 | 19 | pragma solidity 0.6.10; 20 | pragma experimental "ABIEncoderV2"; 21 | 22 | import { DebtIssuanceModuleV2 } from "./DebtIssuanceModuleV2.sol"; 23 | import { IController } from "../../../interfaces/IController.sol"; 24 | 25 | /** 26 | * @title IssuanceModule 27 | * @author Set Protocol 28 | * 29 | * The IssuanceModule is a module that enables users to issue and redeem SetTokens that contain default and all 30 | * external positions, including debt positions. The manager can define arbitrary issuance logic in the manager 31 | * hook, as well as specify issue and redeem fees. The manager can remove the module. 32 | */ 33 | contract IssuanceModule is DebtIssuanceModuleV2 { 34 | 35 | /* ============ Constructor ============ */ 36 | 37 | /** 38 | * Set state controller state variable 39 | */ 40 | constructor(IController _controller) public DebtIssuanceModuleV2(_controller) {} 41 | } 42 | -------------------------------------------------------------------------------- /external/contracts/aave/v1/AavePropositionPower.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.16; 2 | 3 | import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol"; 4 | import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol"; 5 | 6 | /// @title AavePropositionPower 7 | /// @author Aave 8 | /// @notice Asset to control the permissions on the actions in AaveProtoGovernance, like: 9 | /// - Register a new Proposal 10 | contract AavePropositionPower is ERC20Capped, ERC20Detailed { 11 | 12 | /// @notice Constructor 13 | /// @param name Asset name 14 | /// @param symbol Asset symbol 15 | /// @param decimals Asset decimals 16 | /// @param council List of addresses which will receive tokens initially 17 | /// @param cap The cap of tokens to mint, length of the council list 18 | constructor( 19 | string memory name, 20 | string memory symbol, 21 | uint8 decimals, 22 | address[] memory council, 23 | uint256 cap 24 | ) 25 | public ERC20Capped(cap * 1 ether) ERC20Detailed(name, symbol, decimals) { 26 | require(cap == council.length, "INCONSISTENT_CAP_AND_COUNCIL_SIZE"); 27 | for (uint256 i = 0; i < cap; i++) { 28 | _mint(council[i], 1 ether); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /external/contracts/aave/v1/AssetVotingWeightProvider.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.16; 2 | 3 | import "@openzeppelin/contracts/ownership/Ownable.sol"; 4 | 5 | import "../interfaces/IAssetVotingWeightProvider.sol"; 6 | 7 | /// @title AssetVotingWeightProvider 8 | /// @notice Smart contract to register whitelisted assets with its voting weight per asset 9 | /// - The ownership is on the AaveProtoGovernance, that way the whitelisting of new assets or 10 | /// the change of the weight of a current one will be done through governance. 11 | contract AssetVotingWeightProvider is Ownable, IAssetVotingWeightProvider { 12 | 13 | event AssetWeightSet(IERC20 indexed asset, address indexed setter, uint256 weight); 14 | 15 | mapping(address => uint256) private votingWeights; 16 | 17 | /// @notice Constructor 18 | /// @param _assets Dynamic array of asset addresses 19 | /// @param _weights Dynamic array of asset weights, for each one of _assets 20 | constructor(IERC20[] memory _assets, uint256[] memory _weights) public { 21 | require(_assets.length == _weights.length, "INCONSISTENT_ASSETS_WEIGHTS_LENGTHS"); 22 | for (uint256 i = 0; i < _assets.length; i++) { 23 | internalSetVotingWeight(_assets[i], _weights[i]); 24 | } 25 | } 26 | 27 | /// @notice Gets the weight of an asset 28 | /// @param _asset The asset smart contract address 29 | /// @return The uint256 weight of the asset 30 | function getVotingWeight(IERC20 _asset) public view returns(uint256) { 31 | address asset = address(_asset); 32 | return votingWeights[asset]; 33 | } 34 | 35 | /// @notice Sets the weight for an asset 36 | /// @param _asset The asset smart contract address 37 | /// @param _weight The asset smart contract address 38 | /// @return The uint256 weight of the asset 39 | function setVotingWeight(IERC20 _asset, uint256 _weight) external onlyOwner { 40 | internalSetVotingWeight(_asset, _weight); 41 | } 42 | 43 | /// @notice Internal function to set the weight for an asset 44 | /// @param _asset The asset smart contract address 45 | /// @return The uint256 weight of the asset 46 | function internalSetVotingWeight(IERC20 _asset, uint256 _weight) internal { 47 | address asset = address(_asset); 48 | votingWeights[asset] = _weight; 49 | emit AssetWeightSet(_asset, msg.sender, _weight); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /external/contracts/aave/v1/Executor.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: agpl-3.0 2 | pragma solidity 0.7.5; 3 | pragma abicoder v2; 4 | 5 | import {ExecutorWithTimelock} from './ExecutorWithTimelock.sol'; 6 | import {ProposalValidator} from './ProposalValidator.sol'; 7 | 8 | /** 9 | * @title Time Locked, Validator, Executor Contract 10 | * @dev Contract 11 | * - Validate Proposal creations/ cancellation 12 | * - Validate Vote Quorum and Vote success on proposal 13 | * - Queue, Execute, Cancel, successful proposals' transactions. 14 | * @author Aave 15 | **/ 16 | contract Executor is ExecutorWithTimelock, ProposalValidator { 17 | constructor( 18 | address admin, 19 | uint256 delay, 20 | uint256 gracePeriod, 21 | uint256 minimumDelay, 22 | uint256 maximumDelay, 23 | uint256 propositionThreshold, 24 | uint256 voteDuration, 25 | uint256 voteDifferential, 26 | uint256 minimumQuorum 27 | ) 28 | ExecutorWithTimelock(admin, delay, gracePeriod, minimumDelay, maximumDelay) 29 | ProposalValidator(propositionThreshold, voteDuration, voteDifferential, minimumQuorum) 30 | {} 31 | } -------------------------------------------------------------------------------- /external/contracts/aave/v1/LendingRateOracle.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.5.0; 2 | 3 | import "../../interfaces/ILendingRateOracle.sol"; 4 | 5 | 6 | contract LendingRateOracle is ILendingRateOracle { 7 | 8 | mapping(address => uint256) borrowRates; 9 | mapping(address => uint256) liquidityRates; 10 | 11 | 12 | function getMarketBorrowRate(address _asset) external view returns(uint256) { 13 | return borrowRates[_asset]; 14 | } 15 | 16 | function setMarketBorrowRate(address _asset, uint256 _rate) external { 17 | borrowRates[_asset] = _rate; 18 | } 19 | 20 | function getMarketLiquidityRate(address _asset) external view returns(uint256) { 21 | return liquidityRates[_asset]; 22 | } 23 | 24 | function setMarketLiquidityRate(address _asset, uint256 _rate) external { 25 | liquidityRates[_asset] = _rate; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /external/contracts/axie_infinity/TokenSwap.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.17; 2 | 3 | /** 4 | * Smart contract wallet to support swapping between old ERC-20 token to a new contract. 5 | * It also supports swap and deposit into mainchainGateway in a single transaction. 6 | * Pre-requisites: New token needs to be transferred to this contract. 7 | * Dev should check that the decimals and supply of old token and new token are identical. 8 | */ 9 | contract TokenSwap is HasAdmin { 10 | IERC20 public oldToken; 11 | IERC20 public newToken; 12 | MainchainGateway public mainchainGateway; 13 | 14 | constructor( 15 | IERC20 _oldToken, 16 | IERC20 _newToken 17 | ) 18 | public 19 | { 20 | oldToken = _oldToken; 21 | newToken = _newToken; 22 | } 23 | 24 | function setGateway(MainchainGateway _mainchainGateway) external onlyAdmin { 25 | if (address(mainchainGateway) != address(0)) { 26 | require(newToken.approve(address(mainchainGateway), 0)); 27 | } 28 | 29 | mainchainGateway = _mainchainGateway; 30 | require(newToken.approve(address(mainchainGateway), uint256(-1))); 31 | } 32 | 33 | function swapToken() external { 34 | uint256 _balance = oldToken.balanceOf(msg.sender); 35 | require(oldToken.transferFrom(msg.sender, address(this), _balance)); 36 | require(newToken.transfer(msg.sender, _balance)); 37 | } 38 | 39 | function swapAndBridge(address _recipient, uint256 _amount) external { 40 | require(_recipient != address(0), "TokenSwap: recipient is the zero address"); 41 | uint256 _balance = oldToken.balanceOf(msg.sender); 42 | require(oldToken.transferFrom(msg.sender, address(this), _balance)); 43 | 44 | require(_amount <= _balance); 45 | require(newToken.transfer(msg.sender, _balance - _amount)); 46 | mainchainGateway.depositERC20For(_recipient, address(newToken), _amount); 47 | } 48 | 49 | function swapAndBridgeAll(address _recipient) external { 50 | require(_recipient != address(0), "TokenSwap: recipient is the zero address"); 51 | uint256 _balance = oldToken.balanceOf(msg.sender); 52 | require(oldToken.transferFrom(msg.sender, address(this), _balance)); 53 | mainchainGateway.depositERC20For(_recipient, address(newToken), _balance); 54 | } 55 | 56 | // Used when some old token lost forever 57 | function withdrawToken() external onlyAdmin { 58 | newToken.transfer(msg.sender, newToken.balanceOf(address(this))); 59 | } 60 | } -------------------------------------------------------------------------------- /external/contracts/balancer/BFactory.sol: -------------------------------------------------------------------------------- 1 | // This program is free software: you can redistribute it and/or modify 2 | // it under the terms of the GNU General Public License as published by 3 | // the Free Software Foundation, either version 3 of the License, or 4 | // (at your option) any later version. 5 | 6 | // This program is disstributed in the hope that it will be useful, 7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 | // GNU General Public License for more details. 10 | 11 | // You should have received a copy of the GNU General Public License 12 | // along with this program. If not, see . 13 | 14 | pragma solidity 0.5.12; 15 | 16 | // Builds new BPools, logging their addresses and providing `isBPool(address) -> (bool)` 17 | 18 | import "./BPool.sol"; 19 | 20 | contract BFactory is BBronze { 21 | event LOG_NEW_POOL( 22 | address indexed caller, 23 | address indexed pool 24 | ); 25 | 26 | event LOG_BLABS( 27 | address indexed caller, 28 | address indexed blabs 29 | ); 30 | 31 | mapping(address=>bool) private _isBPool; 32 | 33 | function isBPool(address b) 34 | external view returns (bool) 35 | { 36 | return _isBPool[b]; 37 | } 38 | 39 | function newBPool() 40 | external 41 | returns (BPool) 42 | { 43 | BPool bpool = new BPool(); 44 | _isBPool[address(bpool)] = true; 45 | emit LOG_NEW_POOL(msg.sender, address(bpool)); 46 | bpool.setController(msg.sender); 47 | return bpool; 48 | } 49 | 50 | address private _blabs; 51 | 52 | constructor() public { 53 | _blabs = msg.sender; 54 | } 55 | 56 | function getBLabs() 57 | external view 58 | returns (address) 59 | { 60 | return _blabs; 61 | } 62 | 63 | function setBLabs(address b) 64 | external 65 | { 66 | require(msg.sender == _blabs, "ERR_NOT_BLABS"); 67 | emit LOG_BLABS(msg.sender, b); 68 | _blabs = b; 69 | } 70 | 71 | function collect(BPool pool) 72 | external 73 | { 74 | require(msg.sender == _blabs, "ERR_NOT_BLABS"); 75 | uint collected = IERC20(pool).balanceOf(address(this)); 76 | bool xfer = pool.transfer(_blabs, collected); 77 | require(xfer, "ERR_ERC20_FAILED"); 78 | } 79 | } -------------------------------------------------------------------------------- /external/contracts/uniswap/v2/UniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.16; 2 | 3 | import './interfaces/IUniswapV2Factory.sol'; 4 | import './UniswapV2Pair.sol'; 5 | 6 | contract UniswapV2Factory is IUniswapV2Factory { 7 | address public feeTo; 8 | address public feeToSetter; 9 | 10 | mapping(address => mapping(address => address)) public getPair; 11 | address[] public allPairs; 12 | 13 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 14 | 15 | constructor(address _feeToSetter) public { 16 | feeToSetter = _feeToSetter; 17 | } 18 | 19 | function allPairsLength() external view returns (uint) { 20 | return allPairs.length; 21 | } 22 | 23 | function createPair(address tokenA, address tokenB) external returns (address pair) { 24 | require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES'); 25 | (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); 26 | require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS'); 27 | require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient 28 | bytes memory bytecode = type(UniswapV2Pair).creationCode; 29 | bytes32 salt = keccak256(abi.encodePacked(token0, token1)); 30 | assembly { 31 | pair := create2(0, add(bytecode, 32), mload(bytecode), salt) 32 | } 33 | IUniswapV2Pair(pair).initialize(token0, token1); 34 | getPair[token0][token1] = pair; 35 | getPair[token1][token0] = pair; // populate mapping in the reverse direction 36 | allPairs.push(pair); 37 | emit PairCreated(token0, token1, pair, allPairs.length); 38 | } 39 | 40 | function setFeeTo(address _feeTo) external { 41 | require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN'); 42 | feeTo = _feeTo; 43 | } 44 | 45 | function setFeeToSetter(address _feeToSetter) external { 46 | require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN'); 47 | feeToSetter = _feeToSetter; 48 | } 49 | } -------------------------------------------------------------------------------- /external/contracts/uniswap/v2/lib/UniswapV2Library.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache License, Version 2.0 2 | pragma solidity 0.6.10; 3 | 4 | import "../../../../../contracts/interfaces/external/IUniswapV2Pair.sol"; 5 | 6 | import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; 7 | 8 | library UniswapV2Library { 9 | using SafeMath for uint; 10 | 11 | // returns sorted token addresses, used to handle return values from pairs sorted in this order 12 | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { 13 | require(tokenA != tokenB, "UniswapV2Library: IDENTICAL_ADDRESSES"); 14 | (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); 15 | require(token0 != address(0), "UniswapV2Library: ZERO_ADDRESS"); 16 | } 17 | 18 | // calculates the CREATE2 address for a pair without making any external calls 19 | function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) { 20 | (address token0, address token1) = sortTokens(tokenA, tokenB); 21 | pair = address(uint(keccak256(abi.encodePacked( 22 | hex"ff", 23 | factory, 24 | keccak256(abi.encodePacked(token0, token1)), 25 | hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f" // init code hash 26 | )))); 27 | } 28 | 29 | // fetches and sorts the reserves for a pair 30 | function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { 31 | (address token0,) = sortTokens(tokenA, tokenB); 32 | (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves(); 33 | (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); 34 | } 35 | } -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Code Review Processes 2 | ## New Feature Review 3 | Before submitting a pull request for new review, make sure the following is done: 4 | * Design doc is created and posted here: [Insert Link] 5 | * Code cleanliness and completeness is addressed via [guidelines](https://app.gitbook.com/@setprotocol-1/s/set/smart-contract-engineering/sc-code-review-process) 6 | 7 | README Checks 8 | - [] README has proper context for the reviewer to understand what the code includes, any important design considerations, and areas to pay more attention to 9 | 10 | Code Checks 11 | - [] Add explanatory comments. If there is complex code that requires specific context or understanding, note that in a comment 12 | - [] Remove unncessary comments. Any comments that do not add additional context, information, etc. should be removed 13 | - [] Add javadocs. 14 | - [] Scrub through the code for inconsistencies (e.g. removing extra spaces) 15 | - [] Ensure there are not any .onlys in spec files 16 | 17 | 18 | Broader Considerations 19 | - [] Ensure variable, function and event naming is clear, consistent, and reflective for the scope of the code. 20 | - [] Consider if certain pieces of logic should be placed in a different library, module 21 | -------------------------------------------------------------------------------- /scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | rm -f coverage.json 6 | rm -rf .coverage_cache 7 | rm -rf .coverage_contracts 8 | rm -rf cache 9 | rm -rf coverage 10 | rm -rf typechain 11 | rm -rf artifacts 12 | rm -rf dist 13 | -------------------------------------------------------------------------------- /scripts/prepublish_only.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Run in the `prepublishOnly npm hook`. We publish a specially built version 4 | # of the repo to the @hardhat tag which includes hardcoded gas values in the hardhat 5 | # artifact abis and deposits type definitions alongside the js files in the dist. 6 | # This build is necessary for Perp fixtures to run correctly at set-v2-strategies 7 | set -o errexit 8 | 9 | echo "Running prepublishOnly npm hook" 10 | echo "PUBLISH_HARDHAT = $PUBLISH_HARDHAT" 11 | 12 | # This hook is skipped when publishing in CI because semantic-release is discarding TS products of 13 | # npm lifecycle hooks. In CI we re-write the tsconfig on the fly to generate the correct outputs. 14 | if [[ -v CI ]]; then 15 | exit 0 16 | elif [[ -v PUBLISH_HARDHAT ]]; then 17 | yarn build:npm:hardhat 18 | else 19 | yarn build:npm:latest 20 | fi 21 | -------------------------------------------------------------------------------- /scripts/release_hardhat.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | # Auto-publishes a specially built release to the @hardhat tag using version schema `x.x.x-hardhat.1` 6 | # which can be installed with `yarn add @setprotocol/set-protocol-v2@hardhat` 7 | # See scripts/prepublish_only.sh for details about this build. 8 | # 9 | # The `release_default...` branch config here is necessary to trick the semantic-release tool into publishing 10 | # latest and hardhat builds from `master`. These are handled by separate jobs in CI (see circleci/config.yml) 11 | echo '{ 12 | "branches": [ 13 | { "name": "release_default_do_not_delete" }, 14 | { "name": "master", "channel": "hardhat", "prerelease": "hhat"} 15 | ] 16 | }' > .releaserc.json 17 | 18 | # `semantic-release` discards any dist changes generated by npm lifecycle hooks so we need to copy the custom 19 | # config into the default config to produce correct build. This change *IS NOT* committed to the repo and 20 | # this script does not update the package.json version. 21 | cp tsconfig.hardhat.json tsconfig.json 22 | 23 | npx semantic-release --debug 24 | -------------------------------------------------------------------------------- /scripts/release_latest.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -o errexit 4 | 5 | # Auto-publishes `latest` from master, updates package version on github 6 | # Version format is `x.x.x` and installs with `yarn add @setprotocol/set-protocol-v2` 7 | # `package.json` version field is updated and pushed to Github 8 | echo '{ 9 | "branches": [ 10 | { "name": "master" } 11 | ], 12 | "plugins": [ 13 | "@semantic-release/commit-analyzer", 14 | "@semantic-release/release-notes-generator", 15 | "@semantic-release/npm", 16 | "@semantic-release/git" 17 | ] 18 | }' > .releaserc.json 19 | 20 | # Regenerate artifacts to strip out hardcoded gas values in artifact ABIs 21 | yarn build:npm:latest 22 | 23 | npx semantic-release --debug 24 | -------------------------------------------------------------------------------- /tasks/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./subtasks"; 2 | -------------------------------------------------------------------------------- /tasks/subtasks.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs-extra"; 2 | 3 | import { 4 | TASK_COMPILE_SOLIDITY_GET_ARTIFACT_FROM_COMPILATION_OUTPUT, 5 | } from "hardhat/builtin-tasks/task-names"; 6 | 7 | import { TASK_TYPECHAIN_GENERATE_TYPES } from "@typechain/hardhat/dist/constants"; 8 | 9 | import { subtask } from "hardhat/config"; 10 | import { addGasToAbiMethods, removeGasFromAbiMethods } from "../utils/tasks"; 11 | 12 | // Injects network block limit (minus 1 million) in the abi so 13 | // ethers uses it instead of running gas estimation. 14 | subtask(TASK_COMPILE_SOLIDITY_GET_ARTIFACT_FROM_COMPILATION_OUTPUT) 15 | .setAction(async (_, { network }, runSuper) => { 16 | const artifact = await runSuper(); 17 | 18 | // These changes should be skipped when publishing to npm. 19 | // They override ethers' gas estimation 20 | if (!process.env.SKIP_ABI_GAS_MODS) { 21 | artifact.abi = addGasToAbiMethods(network.config, artifact.abi); 22 | } 23 | 24 | return artifact; 25 | } 26 | ); 27 | 28 | // Hooks into the typechain task to inject hardcoded gas into external ABIs (and run them fast) 29 | // ABIs picked up by this task need their location listed in the externalGasMods array 30 | // in `hardhat.config.json`. Temporarily rewrites artifact so typechain picks up the network 31 | // specific gas requirement without introducing any git changes. 32 | subtask(TASK_TYPECHAIN_GENERATE_TYPES) 33 | .setAction(async (_, env, runSuper) => { 34 | const artifacts: any[] = []; 35 | 36 | for (const project of (env.config as any).externalGasMods) { 37 | const files = fs.readdirSync(project); 38 | 39 | for (const file of files) { 40 | const artifactPath = `${process.cwd()}/${project}/${file}`; 41 | const artifact = require(artifactPath); 42 | 43 | artifact.abi = addGasToAbiMethods(env.network.config, artifact.abi); 44 | fs.outputFileSync(artifactPath, JSON.stringify(artifact, undefined, " ")); 45 | artifacts.push({artifact, artifactPath}); 46 | } 47 | } 48 | 49 | await runSuper(); 50 | 51 | for (const item of artifacts) { 52 | item.artifact.abi = removeGasFromAbiMethods(item.artifact.abi); 53 | fs.outputFileSync(item.artifactPath, JSON.stringify(item.artifact, undefined, " ")); 54 | } 55 | } 56 | ); 57 | 58 | export {}; 59 | -------------------------------------------------------------------------------- /test/fixtures/balancer.spec.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | 3 | import { Account } from "@utils/test/types"; 4 | import { 5 | ether, 6 | } from "@utils/index"; 7 | import { 8 | addSnapshotBeforeRestoreAfterEach, 9 | getAccounts, 10 | getSystemFixture, 11 | getBalancerFixture, 12 | } from "@utils/test/index"; 13 | import { SystemFixture, BalancerFixture } from "@utils/fixtures"; 14 | import { THREE } from "@utils/constants"; 15 | 16 | describe("BalancerFixture", () => { 17 | let owner: Account; 18 | 19 | let setup: SystemFixture; 20 | let balancerSetup: BalancerFixture; 21 | 22 | before(async () => { 23 | [ 24 | owner, 25 | ] = await getAccounts(); 26 | 27 | setup = getSystemFixture(owner.address); 28 | balancerSetup = getBalancerFixture(owner.address); 29 | 30 | await setup.initialize(); 31 | }); 32 | 33 | addSnapshotBeforeRestoreAfterEach(); 34 | 35 | describe("#initialize", async () => { 36 | async function subject(): Promise { 37 | await balancerSetup.initialize( 38 | owner, 39 | setup.weth, 40 | setup.wbtc, 41 | setup.dai 42 | ); 43 | } 44 | 45 | it("should deploy a WETH/DAI balancer pool", async () => { 46 | await subject(); 47 | 48 | await setup.weth.approve(balancerSetup.exchange.address, ether(5)); 49 | await balancerSetup.exchange.smartSwapExactOut( 50 | setup.weth.address, 51 | setup.dai.address, 52 | ether(1000), 53 | ether(5), 54 | THREE 55 | ); 56 | }); 57 | }); 58 | }); -------------------------------------------------------------------------------- /test/fixtures/yearn.spec.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | 3 | import { Account } from "@utils/test/types"; 4 | import DeployHelper from "@utils/deploys"; 5 | import { 6 | ether, 7 | } from "@utils/index"; 8 | import { 9 | addSnapshotBeforeRestoreAfterEach, 10 | getAccounts, 11 | getYearnFixture, 12 | getWaffleExpect 13 | } from "@utils/test/index"; 14 | import { StandardTokenMock } from "../../typechain/StandardTokenMock"; 15 | import { YearnFixture } from "@utils/fixtures"; 16 | import { Vault } from "../../typechain/Vault"; 17 | 18 | 19 | const expect = getWaffleExpect(); 20 | 21 | describe("YearnFixture", () => { 22 | let owner: Account; 23 | let yearnSetup: YearnFixture; 24 | let dai: StandardTokenMock; 25 | 26 | before(async () => { 27 | [ 28 | owner, 29 | ] = await getAccounts(); 30 | 31 | const deployer = new DeployHelper(owner.wallet); 32 | dai = await deployer.mocks.deployTokenMock(owner.address, ether(10000), 18); 33 | 34 | yearnSetup = getYearnFixture(owner.address); 35 | 36 | await yearnSetup.initialize(); 37 | }); 38 | 39 | addSnapshotBeforeRestoreAfterEach(); 40 | 41 | describe("#createAndEnableVaultWithStrategyMock", async () => { 42 | async function subject(): Promise { 43 | return await yearnSetup.createAndEnableVaultWithStrategyMock( 44 | dai.address, 45 | owner.address, 46 | owner.address, 47 | owner.address, 48 | "MockStrategy", 49 | "M", 50 | ether(100) 51 | ); 52 | } 53 | 54 | it("should create and enable a vault", async () => { 55 | const vault = await subject(); 56 | 57 | const pricePerShare = await vault.pricePerShare(); // No deposit into the vault. 1 share = 1 underlying 58 | expect(pricePerShare).to.eq(ether(1)); 59 | 60 | }); 61 | }); 62 | 63 | }); 64 | -------------------------------------------------------------------------------- /test/lib/uint256ArrayUtils.spec.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | import { BigNumber } from "ethers"; 3 | 4 | import { Account } from "@utils/test/types"; 5 | import { ONE, TWO, THREE, MAX_UINT_256 } from "@utils/constants"; 6 | import { Uint256ArrayUtilsMock } from "@utils/contracts"; 7 | import DeployHelper from "@utils/deploys"; 8 | import { 9 | addSnapshotBeforeRestoreAfterEach, 10 | getAccounts, 11 | getWaffleExpect, 12 | } from "@utils/test/index"; 13 | 14 | const expect = getWaffleExpect(); 15 | 16 | describe("Uint256ArrayUtils", () => { 17 | let accountOne: Account; 18 | let deployer: DeployHelper; 19 | 20 | let uintArrayUtils: Uint256ArrayUtilsMock; 21 | 22 | before(async () => { 23 | [ 24 | accountOne, 25 | ] = await getAccounts(); 26 | 27 | deployer = new DeployHelper(accountOne.wallet); 28 | uintArrayUtils = await deployer.mocks.deployUint256ArrayUtilsMock(); 29 | }); 30 | 31 | addSnapshotBeforeRestoreAfterEach(); 32 | 33 | describe("#extend", async () => { 34 | let subjectArrayA: BigNumber[]; 35 | let subjectArrayB: BigNumber[]; 36 | 37 | beforeEach(async () => { 38 | subjectArrayA = [ONE, TWO]; 39 | subjectArrayB = [MAX_UINT_256, THREE]; 40 | }); 41 | 42 | async function subject(): Promise { 43 | return uintArrayUtils.testExtend(subjectArrayA, subjectArrayB); 44 | } 45 | 46 | it("should return the correct index and true", async () => { 47 | const newArray = await subject(); 48 | 49 | const expectedArray = subjectArrayA.concat(subjectArrayB); 50 | expect(JSON.stringify(newArray)).to.eq(JSON.stringify(expectedArray)); 51 | }); 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /test/protocol/integration/lib/uniswapV3Math.spec.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | 3 | import { BigNumber } from "ethers"; 4 | 5 | import { Account } from "@utils/test/types"; 6 | import { UniswapV3MathMock } from "@utils/contracts"; 7 | import DeployHelper from "@utils/deploys"; 8 | import { 9 | addSnapshotBeforeRestoreAfterEach, 10 | getAccounts, 11 | getSystemFixture, 12 | getWaffleExpect, 13 | getUniswapV3Fixture, 14 | getPerpV2Fixture 15 | } from "@utils/test/index"; 16 | 17 | import { SystemFixture, UniswapV3Fixture, PerpV2Fixture } from "@utils/fixtures"; 18 | 19 | const expect = getWaffleExpect(); 20 | 21 | describe("UniswapV3MathLib", () => { 22 | let owner: Account; 23 | let deployer: DeployHelper; 24 | let setup: SystemFixture; 25 | let uniswapV3Fixture: UniswapV3Fixture; 26 | let perpV2Fixture: PerpV2Fixture; 27 | 28 | let uniswapV3MathMock: UniswapV3MathMock; 29 | 30 | before(async () => { 31 | [ 32 | owner, 33 | ] = await getAccounts(); 34 | 35 | deployer = new DeployHelper(owner.wallet); 36 | setup = getSystemFixture(owner.address); 37 | await setup.initialize(); 38 | 39 | perpV2Fixture = getPerpV2Fixture(owner.address); 40 | uniswapV3Fixture = getUniswapV3Fixture(owner.address); 41 | await uniswapV3Fixture.initialize( 42 | owner, 43 | setup.weth, 44 | 2500, 45 | setup.wbtc, 46 | 35000, 47 | setup.dai 48 | ); 49 | 50 | uniswapV3MathMock = await deployer.mocks.deployUniswapV3MathMock(); 51 | }); 52 | 53 | addSnapshotBeforeRestoreAfterEach(); 54 | 55 | describe("integration test for #formatSqrtPriceX96ToPriceX96, #formatX96ToX10_18", async () => { 56 | let subjectSqrtPriceX96: BigNumber; 57 | 58 | beforeEach(async () => { 59 | subjectSqrtPriceX96 = (await uniswapV3Fixture.wethWbtcPool.slot0()).sqrtPriceX96; 60 | }); 61 | 62 | async function subject(): Promise { 63 | const priceX86 = await uniswapV3MathMock.testFormatSqrtPriceX96ToPriceX96(subjectSqrtPriceX96); 64 | return uniswapV3MathMock.testFormatX96ToX10_18(priceX86); 65 | }; 66 | 67 | it("should format UniswapV3 pool sqrt price correctly", async () => { 68 | const expectedPrice = await perpV2Fixture.getPriceFromSqrtPriceX96(subjectSqrtPriceX96); 69 | const price = await subject(); 70 | 71 | expect(price).eq(expectedPrice); 72 | }); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /test/protocol/modules/v1/issuanceModule.spec.ts: -------------------------------------------------------------------------------- 1 | import "module-alias/register"; 2 | 3 | import { Account } from "@utils/test/types"; 4 | import { IssuanceModule } from "@utils/contracts"; 5 | import DeployHelper from "@utils/deploys"; 6 | import { 7 | addSnapshotBeforeRestoreAfterEach, 8 | getAccounts, 9 | getWaffleExpect, 10 | getSystemFixture, 11 | } from "@utils/test/index"; 12 | import { SystemFixture } from "@utils/fixtures"; 13 | 14 | const expect = getWaffleExpect(); 15 | 16 | describe("IssuanceModule", () => { 17 | let owner: Account; 18 | let deployer: DeployHelper; 19 | let setup: SystemFixture; 20 | 21 | before(async () => { 22 | [ 23 | owner, 24 | ] = await getAccounts(); 25 | 26 | deployer = new DeployHelper(owner.wallet); 27 | setup = getSystemFixture(owner.address); 28 | await setup.initialize(); 29 | }); 30 | 31 | addSnapshotBeforeRestoreAfterEach(); 32 | 33 | describe("#constructor", async () => { 34 | let subjectIssuanceModule: IssuanceModule; 35 | 36 | async function subject(): Promise { 37 | return deployer.modules.deployIssuanceModule(setup.controller.address); 38 | } 39 | 40 | it("should have the correct controller", async () => { 41 | subjectIssuanceModule = await subject(); 42 | const expectedController = await subjectIssuanceModule.controller(); 43 | expect(expectedController).to.eq(setup.controller.address); 44 | }); 45 | }); 46 | }); -------------------------------------------------------------------------------- /tsconfig.dist.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": [ 4 | "test/**/*.ts" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tsconfig.hardhat.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "strictPropertyInitialization": false, 8 | "outDir": "./dist", 9 | "resolveJsonModule": true, 10 | "declaration": true, 11 | "declarationMap": true, 12 | "sourceMap": true, 13 | "baseUrl": ".", 14 | "moduleResolution": "node", 15 | "paths": { 16 | "@utils/*": ["utils/*"], 17 | "@typechain/*": ["typechain/*"] 18 | } 19 | }, 20 | "include": [ 21 | "./utils/**/*.ts", 22 | "./deploy/**/*.ts", 23 | "./typechain/**/*.ts", 24 | "./tasks/**/*.ts" 25 | ], 26 | "files": [ 27 | "hardhat.config.ts", 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "strictPropertyInitialization": false, 8 | "outDir": "dist", 9 | "resolveJsonModule": true, 10 | "declaration": true, 11 | "declarationDir": "./dist/types", 12 | "declarationMap": true, 13 | "sourceMap": true, 14 | "baseUrl": ".", 15 | "moduleResolution": "node", 16 | "paths": { 17 | "@utils/*": ["utils/*"], 18 | "@typechain/*": ["typechain/*"] 19 | } 20 | }, 21 | "include": [ 22 | "./test/**/*.ts", 23 | "./utils/**/*.ts", 24 | "./deploy/**/*.ts", 25 | "./typechain/**/*.ts", 26 | "./tasks/**/*.ts" 27 | ], 28 | "files": [ 29 | "hardhat.config.ts", 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /utils/common/adapterUtils.ts: -------------------------------------------------------------------------------- 1 | import { keccak256 } from "ethers/lib/utils"; 2 | import { BigNumber } from "ethers"; 3 | 4 | export const addressToData = (address: String) => address.replace("0x", "000000000000000000000000"); 5 | export const bigNumberToData = (number: BigNumber) => number.toHexString().replace("0x", "").padStart(64, "0"); 6 | export const hashAdapterName = (name: string) => keccak256(new Buffer(name)); 7 | -------------------------------------------------------------------------------- /utils/common/addressUtils.ts: -------------------------------------------------------------------------------- 1 | import { Wallet } from "ethers"; 2 | import { Address } from "../types"; 3 | 4 | export const getRandomAddress = async (): Promise
=> { 5 | const wallet = Wallet.createRandom(); 6 | return await wallet.getAddress(); 7 | }; 8 | -------------------------------------------------------------------------------- /utils/common/blockchainUtils.ts: -------------------------------------------------------------------------------- 1 | import { providers } from "ethers"; 2 | 3 | export class Blockchain { 4 | public _provider: providers.Web3Provider | providers.JsonRpcProvider; 5 | private _snapshotId: number; 6 | 7 | constructor(_provider: providers.Web3Provider | providers.JsonRpcProvider) { 8 | this._provider = _provider; 9 | 10 | this._snapshotId = 0; 11 | } 12 | 13 | public async saveSnapshotAsync(): Promise { 14 | const response = await this.sendJSONRpcRequestAsync("evm_snapshot", []); 15 | 16 | this._snapshotId = response; 17 | return response; 18 | } 19 | 20 | public async revertAsync(): Promise { 21 | await this.sendJSONRpcRequestAsync("evm_revert", [this._snapshotId]); 22 | } 23 | 24 | public async revertByIdAsync(id: string): Promise { 25 | await this.sendJSONRpcRequestAsync("evm_revert", [id]); 26 | } 27 | 28 | public async resetAsync(): Promise { 29 | await this.sendJSONRpcRequestAsync("evm_revert", ["0x1"]); 30 | } 31 | 32 | public async increaseTimeAsync(duration: number): Promise { 33 | await this.sendJSONRpcRequestAsync("evm_increaseTime", [duration]); 34 | } 35 | 36 | public async getCurrentTimestamp(): Promise { 37 | return await this._provider.getBlock(await this._provider.getBlockNumber()); 38 | } 39 | 40 | public async setNextBlockTimestamp(timestamp: number): Promise { 41 | await this.sendJSONRpcRequestAsync("evm_setNextBlockTimestamp", [timestamp]); 42 | } 43 | 44 | public async waitBlocksAsync(count: number) { 45 | for (let i = 0; i < count; i++) { 46 | await this.sendJSONRpcRequestAsync("evm_mine", []); 47 | } 48 | } 49 | 50 | private async sendJSONRpcRequestAsync(method: string, params: any[]): Promise { 51 | return this._provider.send(method, params); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /utils/common/feeModuleUtils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from "ethers"; 2 | 3 | import { preciseMul, preciseMulCeilInt } from "./mathUtils"; 4 | import { ONE_YEAR_IN_SECONDS, PRECISE_UNIT } from "../constants"; 5 | import { Address } from "../types"; 6 | import { StreamingFeeModule } from "../contracts"; 7 | 8 | export const getStreamingFee = async( 9 | feeModule: StreamingFeeModule, 10 | setToken: Address, 11 | previousAccrueTimestamp: BigNumber, 12 | recentAccrueTimestamp: BigNumber, 13 | streamingFee?: BigNumber 14 | ): Promise => { 15 | const feeState = await feeModule.feeStates(setToken); 16 | const accrualRate = streamingFee ? streamingFee : feeState.streamingFeePercentage; 17 | 18 | const timeElapsed = recentAccrueTimestamp.sub(previousAccrueTimestamp); 19 | return timeElapsed.mul(accrualRate).div(ONE_YEAR_IN_SECONDS); 20 | }; 21 | 22 | export const getStreamingFeeInflationAmount = ( 23 | inflationPercent: BigNumber, 24 | totalSupply: BigNumber 25 | ): BigNumber => { 26 | const a = inflationPercent.mul(totalSupply); 27 | const b = PRECISE_UNIT.sub(inflationPercent); 28 | 29 | return a.div(b); 30 | }; 31 | 32 | export const getPostFeePositionUnits = ( 33 | preFeeUnits: BigNumber[], 34 | inflationPercent: BigNumber 35 | ): BigNumber[] => { 36 | const newUnits: BigNumber[] = []; 37 | for (let i = 0; i < preFeeUnits.length; i++) { 38 | if (preFeeUnits[i].gte(0)) { 39 | newUnits.push(preciseMul(preFeeUnits[i], PRECISE_UNIT.sub(inflationPercent))); 40 | } else { 41 | newUnits.push(preciseMulCeilInt(preFeeUnits[i], PRECISE_UNIT.sub(inflationPercent))); 42 | } 43 | } 44 | return newUnits; 45 | }; 46 | -------------------------------------------------------------------------------- /utils/common/index.ts: -------------------------------------------------------------------------------- 1 | export { Blockchain } from "./blockchainUtils"; 2 | export { ProtocolUtils } from "./protocolUtils"; 3 | export { ether, gWei, bitcoin, usdc } from "./unitsUtils"; 4 | export { 5 | getPostFeePositionUnits, 6 | getStreamingFee, 7 | getStreamingFeeInflationAmount 8 | } from "./feeModuleUtils"; 9 | export { 10 | divDown, 11 | min, 12 | preciseDiv, 13 | preciseDivCeil, 14 | preciseMul, 15 | preciseMulCeil, 16 | preciseMulCeilInt, 17 | preciseDivCeilInt 18 | } from "./mathUtils"; 19 | export { addressToData, bigNumberToData, hashAdapterName } from "./adapterUtils"; 20 | export { 21 | getExpectedIssuePositionMultiplier, 22 | getExpectedIssuePositionUnit, 23 | getExpectedPostFeeQuantity, 24 | getExpectedSetTokenIssueQuantity, 25 | getExpectedReserveRedeemQuantity, 26 | getExpectedRedeemPositionMultiplier, 27 | getExpectedRedeemPositionUnit 28 | } from "./navIssuanceModuleUtils"; 29 | export { 30 | calculateEngageQuantities, 31 | calculateLPTokensIssued, 32 | calculateRebalanceFlows, 33 | calculateRebalanceQuantity, 34 | calculateTokensInReserve, 35 | getReservesSafe 36 | } from "./uniswapUtils"; 37 | export { 38 | convertLibraryNameToLinkId 39 | } from "./libraryUtils"; 40 | export { 41 | getRandomAddress 42 | } from "./addressUtils"; 43 | export { 44 | toUSDCDecimals, 45 | calculateUSDCTransferIn, 46 | calculateUSDCTransferOut, 47 | calculateExternalPositionUnit, 48 | calculateMaxIssueQuantity, 49 | calculateUSDCTransferInPreciseUnits, 50 | calculateUSDCTransferOutPreciseUnits, 51 | calculateLeverageRatios, 52 | getUSDCDeltaDueToFundingGrowth, 53 | leverUp, 54 | getNetFundingGrowth 55 | } from "./perpV2Utils"; 56 | -------------------------------------------------------------------------------- /utils/common/libraryUtils.ts: -------------------------------------------------------------------------------- 1 | import { utils } from "ethers"; 2 | import path from "path"; 3 | 4 | // Converts a fully qualified contract name in a bytecode link id. 5 | // (A fully qualified name looks like: `contracts/mocks/LibraryMock.sol:LibraryMock`) 6 | export function convertLibraryNameToLinkId(libraryName: string): string { 7 | if (!(libraryName.includes(path.sep) && libraryName.includes(":"))) { 8 | throw new Error( 9 | "Converting library name to link id requires a fully qualified " + 10 | "contract name. Example: `contracts/mocks/LibraryMock.sol:LibraryMock`" 11 | ); 12 | } 13 | 14 | const hashedName = utils.keccak256(utils.toUtf8Bytes(libraryName)); 15 | return `__$${hashedName.slice(2).slice(0, 34)}$__`; 16 | } 17 | -------------------------------------------------------------------------------- /utils/common/mathUtils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from "ethers"; 2 | 3 | import { PRECISE_UNIT, ZERO } from "../constants"; 4 | 5 | export const preciseMul = (a: BigNumber, b: BigNumber): BigNumber => { 6 | return a.mul(b).div(PRECISE_UNIT); 7 | }; 8 | 9 | export const preciseMulCeil = (a: BigNumber, b: BigNumber): BigNumber => { 10 | if (a.eq(0) || b.eq(0)) { 11 | return ZERO; 12 | } 13 | 14 | return a.mul(b).sub(1).div(PRECISE_UNIT).add(1); 15 | }; 16 | 17 | export const preciseMulCeilInt = (a: BigNumber, b: BigNumber): BigNumber => { 18 | if (a.eq(0) || b.eq(0)) { 19 | return ZERO; 20 | } 21 | 22 | if (a.gt(0) && b.gt(0) || a.lt(0) && b.lt(0)) { 23 | return a.mul(b).sub(1).div(PRECISE_UNIT).add(1); 24 | } else { 25 | return a.mul(b).add(1).div(PRECISE_UNIT).sub(1); 26 | } 27 | }; 28 | 29 | export const preciseDiv = (a: BigNumber, b: BigNumber): BigNumber => { 30 | return a.mul(PRECISE_UNIT).div(b); 31 | }; 32 | 33 | export const preciseDivCeil = (a: BigNumber, b: BigNumber): BigNumber => { 34 | if (a.eq(0) || b.eq(0)) { 35 | return ZERO; 36 | } 37 | 38 | return a.mul(PRECISE_UNIT).sub(1).div(b).add(1); 39 | }; 40 | 41 | export const preciseDivCeilInt = (a: BigNumber, b: BigNumber): BigNumber => { 42 | const result = a.mul(PRECISE_UNIT).div(b); 43 | if (result.mul(b).eq(a.mul(PRECISE_UNIT))) { 44 | return result; 45 | } 46 | 47 | if ((a.gt(0) && b.gt(0)) || (a.lt(0) && b.lt(0))) { 48 | return result.add(1); 49 | } else { 50 | return result.sub(1); 51 | } 52 | }; 53 | 54 | export const divDown = (a: BigNumber, b: BigNumber): BigNumber => { 55 | let result = a.div(b); 56 | if (a.lt(0) && b.gt(0) && !a.mod(b).isZero()) { 57 | result = result.sub(1); 58 | } else if (a.gt(0) && b.lt(0) && !a.mod(b.mul(-1)).isZero()) { 59 | result = result.sub(1); 60 | } 61 | return result; 62 | }; 63 | 64 | export const min = ( 65 | valueOne: BigNumber, 66 | valueTwo: BigNumber 67 | ): BigNumber => { 68 | return valueOne.lt(valueTwo) ? valueOne : valueTwo; 69 | }; 70 | -------------------------------------------------------------------------------- /utils/common/protocolUtils.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber, constants, ethers, providers } from "ethers"; 2 | 3 | import { EMPTY_BYTES } from "../constants"; 4 | import { Address, Position } from "../types"; 5 | 6 | const { AddressZero } = constants; 7 | 8 | export class ProtocolUtils { 9 | public _provider: providers.Web3Provider | providers.JsonRpcProvider; 10 | 11 | constructor(_provider: providers.Web3Provider | providers.JsonRpcProvider) { 12 | this._provider = _provider; 13 | } 14 | 15 | public async getCreatedSetTokenAddress (txnHash: string | undefined): Promise { 16 | if (!txnHash) { 17 | throw new Error("Invalid transaction hash"); 18 | } 19 | 20 | const abi = ["event SetTokenCreated(address indexed _setToken, address _manager, string _name, string _symbol)"]; 21 | const iface = new ethers.utils.Interface(abi); 22 | 23 | const topic = ethers.utils.id("SetTokenCreated(address,address,string,string)"); 24 | const logs = await this._provider.getLogs({ 25 | fromBlock: "latest", 26 | toBlock: "latest", 27 | topics: [topic], 28 | }); 29 | 30 | const parsed = iface.parseLog(logs[logs.length - 1]); 31 | return parsed.args._setToken; 32 | } 33 | 34 | public getDefaultPosition(component: Address, unit: BigNumber): Position { 35 | return { 36 | component, 37 | module: AddressZero, 38 | unit, 39 | positionState: 0, 40 | data: EMPTY_BYTES, 41 | }; 42 | } 43 | 44 | public getExternalPosition(component: Address, module: Address, unit: BigNumber, data: string): Position { 45 | return { 46 | component, 47 | module, 48 | unit, 49 | positionState: 1, 50 | data, 51 | }; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /utils/common/unitsUtils.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from "ethers"; 2 | import { BigNumber } from "ethers"; 3 | 4 | export const ether = (amount: number | string): BigNumber => { 5 | const weiString = ethers.utils.parseEther(amount.toString()); 6 | return BigNumber.from(weiString); 7 | }; 8 | 9 | export const gWei = (amount: number): BigNumber => { 10 | const weiString = BigNumber.from("1000000000").mul(amount); 11 | return BigNumber.from(weiString); 12 | }; 13 | 14 | export const bitcoin = (amount: number): BigNumber => { 15 | const weiString = 100000000 * amount; // Handles decimal Bitcoins better 16 | return BigNumber.from(weiString); 17 | }; 18 | 19 | export const usdc = (amount: number): BigNumber => { 20 | const weiString = 1000000 * amount; 21 | return BigNumber.from(weiString); 22 | }; 23 | -------------------------------------------------------------------------------- /utils/constants.ts: -------------------------------------------------------------------------------- 1 | import { constants } from "ethers"; 2 | import { BigNumber } from "ethers"; 3 | 4 | const { AddressZero, MaxUint256, One, Two, Zero } = constants; 5 | 6 | export const MODULE_STATE = { 7 | "NONE": 0, 8 | "PENDING": 1, 9 | "INITIALIZED": 2, 10 | }; 11 | 12 | export const POSITION_STATE = { 13 | "DEFAULT": 0, 14 | "EXTERNAL": 1, 15 | }; 16 | 17 | export const ADDRESS_ZERO = AddressZero; 18 | export const EMPTY_BYTES = "0x"; 19 | export const ZERO_BYTES = "0x0000000000000000000000000000000000000000000000000000000000000000"; 20 | export const MAX_UINT_256 = MaxUint256; 21 | export const ONE = One; 22 | export const TWO = Two; 23 | export const THREE = BigNumber.from(3); 24 | export const ZERO = Zero; 25 | export const MAX_INT_256 = "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; 26 | export const MIN_INT_256 = "-0x8000000000000000000000000000000000000000000000000000000000000000"; 27 | export const ONE_DAY_IN_SECONDS = BigNumber.from(60 * 60 * 24); 28 | export const ONE_HOUR_IN_SECONDS = BigNumber.from(60 * 60); 29 | export const ONE_YEAR_IN_SECONDS = BigNumber.from(31557600); 30 | 31 | export const PRECISE_UNIT = constants.WeiPerEther; 32 | export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"; 33 | -------------------------------------------------------------------------------- /utils/contracts/aaveV2.ts: -------------------------------------------------------------------------------- 1 | export { AaveV2AToken } from "../../typechain/AaveV2AToken"; 2 | export { AaveV2DefaultReserveInterestRateStrategy } from "../../typechain/AaveV2DefaultReserveInterestRateStrategy"; 3 | export { AaveV2LendingPool } from "../../typechain/AaveV2LendingPool"; 4 | export { AaveV2LendingPoolAddressesProvider } from "../../typechain/AaveV2LendingPoolAddressesProvider"; 5 | export { AaveV2LendingPoolCollateralManager } from "../../typechain/AaveV2LendingPoolCollateralManager"; 6 | export { AaveV2LendingPoolConfigurator } from "../../typechain/AaveV2LendingPoolConfigurator"; 7 | export { AaveV2LendingRateOracle } from "../../typechain/AaveV2LendingRateOracle"; 8 | export { AaveV2Oracle } from "../../typechain/AaveV2Oracle"; 9 | export { AaveV2ProtocolDataProvider } from "../../typechain/AaveV2ProtocolDataProvider"; 10 | export { AaveV2PriceOracle } from "../../typechain/AaveV2PriceOracle"; 11 | export { AaveV2StableDebtToken } from "../../typechain/AaveV2StableDebtToken"; 12 | export { AaveV2StakedTokenIncentivesController } from "../../typechain/AaveV2StakedTokenIncentivesController"; 13 | export { AaveV2VariableDebtToken } from "../../typechain/AaveV2VariableDebtToken"; 14 | 15 | // Governance V2 16 | export { AaveGovernanceV2 } from "../../typechain/AaveGovernanceV2"; 17 | export { AaveTokenV2Mintable } from "../../typechain/AaveTokenV2Mintable"; 18 | export { GovernanceStrategy } from "../../typechain/GovernanceStrategy"; 19 | export { Executor } from "../../typechain/Executor"; 20 | 21 | // Libraries 22 | export { GenericLogic } from "../../typechain/GenericLogic"; 23 | export { ReserveLogic } from "../../typechain/ReserveLogic"; 24 | export { ValidationLogic } from "../../typechain/ValidationLogic"; -------------------------------------------------------------------------------- /utils/contracts/balancer.ts: -------------------------------------------------------------------------------- 1 | // External Balancer Contracts 2 | export { BFactory } from "../../typechain/BFactory"; 3 | export { BPool } from "../../typechain/BPool"; 4 | export { BRegistry } from "../../typechain/BRegistry"; 5 | export { ExchangeProxy } from "../../typechain/ExchangeProxy"; -------------------------------------------------------------------------------- /utils/contracts/compound.ts: -------------------------------------------------------------------------------- 1 | // External Compound Contracts 2 | export { Comp } from "../../typechain/Comp"; 3 | export { CompoundGovernorAlpha } from "../../typechain/CompoundGovernorAlpha"; 4 | export { CompoundGovernorBravoDelegate } from "../../typechain/CompoundGovernorBravoDelegate"; 5 | export { CompoundGovernorBravoDelegator } from "../../typechain/CompoundGovernorBravoDelegator"; 6 | export { CompoundTimelock } from "../../typechain/CompoundTimelock"; 7 | export { Comptroller } from "../../typechain/Comptroller"; 8 | export { CERc20 } from "../../typechain/CERc20"; 9 | export { CEther } from "../../typechain/CEther"; 10 | export { CompoundPriceOracleMock } from "../../typechain/CompoundPriceOracleMock"; 11 | export { PriceOracleProxy } from "../../typechain/PriceOracleProxy"; 12 | export { Unitroller } from "../../typechain/Unitroller"; 13 | export { WhitePaperInterestRateModel } from "../../typechain/WhitePaperInterestRateModel"; 14 | -------------------------------------------------------------------------------- /utils/contracts/curve.ts: -------------------------------------------------------------------------------- 1 | // External Curve Contracts 2 | export { CurveDeposit } from "../../typechain/CurveDeposit"; 3 | export { CurvePoolERC20 } from "../../typechain/CurvePoolERC20"; 4 | export { CurveStableswapMock } from "../../typechain/CurveStableswapMock"; 5 | export { CRVToken } from "../../typechain/CRVToken"; 6 | export { GaugeController } from "../../typechain/GaugeController"; 7 | export { LiquidityGauge } from "../../typechain/LiquidityGauge"; 8 | export { LiquidityGaugeReward } from "../../typechain/LiquidityGaugeReward"; 9 | export { Minter } from "../../typechain/Minter"; 10 | export { Stableswap } from "../../typechain/Stableswap"; 11 | -------------------------------------------------------------------------------- /utils/contracts/kyberV3.ts: -------------------------------------------------------------------------------- 1 | // External Kyber contracts 2 | export { KyberNetworkTokenV2 } from "../../typechain/KyberNetworkTokenV2"; 3 | export { DMMFactory } from "../../typechain/DMMFactory"; 4 | export { DMMPool } from "../../typechain/DMMPool"; 5 | export { DMMRouter02 } from "../../typechain/DMMRouter02"; -------------------------------------------------------------------------------- /utils/contracts/notional.ts: -------------------------------------------------------------------------------- 1 | // External Uniswap Contracts 2 | export { WrappedfCash } from "../../typechain/WrappedfCash"; 3 | export { WrappedfCashFactory } from "../../typechain/WrappedfCashFactory"; 4 | -------------------------------------------------------------------------------- /utils/contracts/perpV2.ts: -------------------------------------------------------------------------------- 1 | export { PerpV2AccountBalance } from "../../typechain/PerpV2AccountBalance"; 2 | export { PerpV2BaseToken } from "../../typechain/PerpV2BaseToken"; 3 | export { PerpV2ChainlinkPriceFeed } from "../../typechain/PerpV2ChainlinkPriceFeed"; 4 | export { PerpV2ClearingHouseConfig } from "../../typechain/PerpV2ClearingHouseConfig"; 5 | export { PerpV2Exchange } from "../../typechain/PerpV2Exchange"; 6 | export { PerpV2InsuranceFund } from "../../typechain/PerpV2InsuranceFund"; 7 | export { PerpV2TestAggregatorV3 } from "../../typechain/PerpV2TestAggregatorV3"; 8 | export { PerpV2VirtualToken } from "../../typechain/PerpV2VirtualToken"; 9 | export { PerpV2ClearingHouse } from "../../typechain/PerpV2ClearingHouse"; 10 | export { PerpV2MarketRegistry } from "../../typechain/PerpV2MarketRegistry"; 11 | export { PerpV2OrderBook } from "../../typechain/PerpV2OrderBook"; 12 | export { PerpV2Quoter } from "../../typechain/PerpV2Quoter"; 13 | export { PerpV2QuoteToken } from "../../typechain/PerpV2QuoteToken"; 14 | export { PerpV2Vault } from "../../typechain/PerpV2Vault"; 15 | -------------------------------------------------------------------------------- /utils/contracts/uniswap.ts: -------------------------------------------------------------------------------- 1 | // External Uniswap Contracts 2 | export { StakingRewards } from "../../typechain/StakingRewards"; 3 | export { Uni } from "../../typechain/Uni"; 4 | export { UniswapGovernorAlpha } from "../../typechain/UniswapGovernorAlpha"; 5 | export { UniswapTimelock } from "../../typechain/UniswapTimelock"; 6 | export { UniswapV2Factory } from "../../typechain/UniswapV2Factory"; 7 | export { UniswapV2Pair } from "../../typechain/UniswapV2Pair"; 8 | export { UniswapV2Router02 } from "../../typechain/UniswapV2Router02"; -------------------------------------------------------------------------------- /utils/contracts/uniswapV3.ts: -------------------------------------------------------------------------------- 1 | // External Uniswap V3 contracts 2 | export { UniswapV3Factory } from "../../typechain/UniswapV3Factory"; 3 | export { UniswapV3Pool } from "../../typechain/UniswapV3Pool"; 4 | export { SwapRouter } from "../../typechain/SwapRouter"; 5 | export { NonfungiblePositionManager } from "../../typechain/NonfungiblePositionManager"; 6 | export { Quoter } from "../../typechain/Quoter"; 7 | export { NFTDescriptor } from "../../typechain/NFTDescriptor"; 8 | -------------------------------------------------------------------------------- /utils/contracts/yearn.ts: -------------------------------------------------------------------------------- 1 | // External Yearn Contracts 2 | export { Vault } from "../../typechain/Vault"; 3 | export { Registry } from "../../typechain/Registry"; 4 | -------------------------------------------------------------------------------- /utils/deploys/deployLibraries.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "ethers"; 2 | 3 | import { 4 | AaveV2, 5 | Compound, 6 | PerpV2, 7 | PerpV2LibraryV2, 8 | PerpV2Positions, 9 | PositionV2 10 | } from "../contracts"; 11 | 12 | import { Compound__factory } from "../../typechain/factories/Compound__factory"; 13 | import { AaveV2__factory } from "../../typechain/factories/AaveV2__factory"; 14 | import { PerpV2__factory } from "../../typechain/factories/PerpV2__factory"; 15 | import { PerpV2LibraryV2__factory } from "../../typechain/factories/PerpV2LibraryV2__factory"; 16 | import { PerpV2Positions__factory } from "../../typechain/factories/PerpV2Positions__factory"; 17 | import { PositionV2__factory } from "../../typechain/factories/PositionV2__factory"; 18 | 19 | export default class DeployLibraries { 20 | private _deployerSigner: Signer; 21 | 22 | constructor(deployerSigner: Signer) { 23 | this._deployerSigner = deployerSigner; 24 | } 25 | 26 | public async deployCompound(): Promise { 27 | return await new Compound__factory(this._deployerSigner).deploy(); 28 | } 29 | 30 | public async deployAaveV2(): Promise { 31 | return await new AaveV2__factory(this._deployerSigner).deploy(); 32 | } 33 | 34 | public async deployPerpV2(): Promise { 35 | return await new PerpV2__factory(this._deployerSigner).deploy(); 36 | } 37 | 38 | public async deployPositionV2(): Promise { 39 | return await new PositionV2__factory(this._deployerSigner).deploy(); 40 | } 41 | 42 | public async deployPerpV2LibraryV2(): Promise { 43 | return await new PerpV2LibraryV2__factory(this._deployerSigner).deploy(); 44 | } 45 | 46 | public async deployPerpV2Positions(): Promise { 47 | return await new PerpV2Positions__factory(this._deployerSigner).deploy(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /utils/deploys/deployOracles.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "ethers"; 2 | import { Address } from "../types"; 3 | import { BigNumber } from "ethers"; 4 | 5 | import { CTokenOracle, YearnVaultOracle } from "../contracts"; 6 | 7 | import { CTokenOracle__factory } from "../../typechain/factories/CTokenOracle__factory"; 8 | import { YearnVaultOracle__factory } from "../../typechain/factories/YearnVaultOracle__factory"; 9 | 10 | export default class DeployOracles { 11 | private _deployerSigner: Signer; 12 | 13 | constructor(deployerSigner: Signer) { 14 | this._deployerSigner = deployerSigner; 15 | } 16 | 17 | public async deployCTokenOracle( 18 | cToken: Address, 19 | underlyingOracle: Address, 20 | cTokenFullUnit: BigNumber, 21 | underlyingFullUnit: BigNumber, 22 | dataDescription: string): Promise { 23 | return await new CTokenOracle__factory(this._deployerSigner) 24 | .deploy(cToken, underlyingOracle, cTokenFullUnit, underlyingFullUnit, dataDescription); 25 | } 26 | 27 | public async deployYearnVaultOracle( 28 | vault: Address, 29 | underlyingOracle: Address, 30 | underlyingFullUnit: BigNumber, 31 | dataDescription: string): Promise { 32 | return await new YearnVaultOracle__factory(this._deployerSigner).deploy(vault, underlyingOracle, underlyingFullUnit, dataDescription); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /utils/deploys/deployProduct.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "ethers"; 2 | import { BigNumber } from "ethers"; 3 | 4 | import { 5 | APYRescue, 6 | AssetLimitHook, 7 | AMMSplitter, 8 | TokenEnabler 9 | } from "../contracts"; 10 | 11 | import { APYRescue__factory } from "../../typechain/factories/APYRescue__factory"; 12 | import { AssetLimitHook__factory } from "../../typechain/factories/AssetLimitHook__factory"; 13 | import { AMMSplitter__factory } from "../../typechain/factories/AMMSplitter__factory"; 14 | import { TokenEnabler__factory } from "../../typechain/factories/TokenEnabler__factory"; 15 | import { Address } from "../types"; 16 | 17 | export default class DeployProduct { 18 | private _deployerSigner: Signer; 19 | 20 | constructor(deployerSigner: Signer) { 21 | this._deployerSigner = deployerSigner; 22 | } 23 | 24 | public async deployAssetLimitHook( 25 | _assets: Address[], 26 | _limits: BigNumber[] 27 | ): Promise { 28 | return await new AssetLimitHook__factory(this._deployerSigner).deploy(_assets, _limits); 29 | } 30 | 31 | public async getAssetLimitHook(assetLimitHookAddress: Address): Promise { 32 | return await new AssetLimitHook__factory(this._deployerSigner).attach(assetLimitHookAddress); 33 | } 34 | 35 | public async deployAMMSplitter( 36 | uniRouter: Address, 37 | sushiRouter: Address, 38 | uniFactory: Address, 39 | sushiFactory: Address 40 | ): Promise { 41 | return await new AMMSplitter__factory(this._deployerSigner).deploy(uniRouter, sushiRouter, uniFactory, sushiFactory); 42 | } 43 | 44 | public deployAPYRescue( 45 | apyToken: Address, 46 | recoveredTokens: Address[], 47 | basicIssuanceModule: Address 48 | ): Promise { 49 | return new APYRescue__factory(this._deployerSigner).deploy(apyToken, recoveredTokens, basicIssuanceModule); 50 | } 51 | 52 | public deployTokenEnabler( 53 | controller: Address, 54 | tokensToEnable: Address[] 55 | ): Promise { 56 | return new TokenEnabler__factory(this._deployerSigner).deploy(controller, tokensToEnable); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /utils/deploys/deployViewers.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "ethers"; 2 | 3 | import { PerpV2LeverageModuleViewer } from "../contracts"; 4 | import { ProtocolViewer } from "../contracts"; 5 | 6 | import { PerpV2LeverageModuleViewer__factory } from "../../typechain/factories/PerpV2LeverageModuleViewer__factory"; 7 | import { ProtocolViewer__factory } from "../../typechain/factories/ProtocolViewer__factory"; 8 | import { Address } from "@utils/types"; 9 | 10 | export default class DeployViewers { 11 | private _deployerSigner: Signer; 12 | 13 | constructor(deployerSigner: Signer) { 14 | this._deployerSigner = deployerSigner; 15 | } 16 | 17 | public async deployProtocolViewer(): Promise { 18 | return await new ProtocolViewer__factory(this._deployerSigner).deploy(); 19 | } 20 | 21 | public async deployPerpV2LeverageModuleViewer( 22 | perpModule: Address, 23 | perpAccountBalance: Address, 24 | perpClearingHouseConfig: Address, 25 | vQuoteToken: Address 26 | ): Promise { 27 | return await new PerpV2LeverageModuleViewer__factory(this._deployerSigner).deploy( 28 | perpModule, 29 | perpAccountBalance, 30 | perpClearingHouseConfig, 31 | vQuoteToken 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /utils/deploys/index.ts: -------------------------------------------------------------------------------- 1 | import { Signer } from "ethers"; 2 | 3 | import DeployLibraries from "./deployLibraries"; 4 | import DeployMocks from "./deployMocks"; 5 | import DeployModules from "./deployModules"; 6 | import DeployCoreContracts from "./deployCoreContracts"; 7 | import DeployExternalContracts from "./deployExternal"; 8 | import DeployAdapters from "./deployAdapters"; 9 | import DeployViewers from "./deployViewers"; 10 | import DeployProduct from "./deployProduct"; 11 | import DeployOracles from "./deployOracles"; 12 | 13 | export default class DeployHelper { 14 | public libraries: DeployLibraries; 15 | public mocks: DeployMocks; 16 | public modules: DeployModules; 17 | public core: DeployCoreContracts; 18 | public external: DeployExternalContracts; 19 | public adapters: DeployAdapters; 20 | public viewers: DeployViewers; 21 | public product: DeployProduct; 22 | public oracles: DeployOracles; 23 | 24 | constructor(deployerSigner: Signer) { 25 | this.libraries = new DeployLibraries(deployerSigner); 26 | this.mocks = new DeployMocks(deployerSigner); 27 | this.modules = new DeployModules(deployerSigner); 28 | this.core = new DeployCoreContracts(deployerSigner); 29 | this.external = new DeployExternalContracts(deployerSigner); 30 | this.adapters = new DeployAdapters(deployerSigner); 31 | this.viewers = new DeployViewers(deployerSigner); 32 | this.product = new DeployProduct(deployerSigner); 33 | this.oracles = new DeployOracles(deployerSigner); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /utils/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export { AaveV2Fixture } from "./aaveV2Fixture"; 2 | export { BalancerFixture } from "./balancerFixture"; 3 | export { CompoundFixture } from "./compoundFixture"; 4 | export { CurveFixture } from "./curveFixture"; 5 | export { KyberV3DMMFixture } from "./kyberV3DMMFixture"; 6 | export { SystemFixture } from "./systemFixture"; 7 | export { UniswapFixture } from "./uniswapFixture"; 8 | export { UniswapV3Fixture } from "./uniswapV3Fixture"; 9 | export { YearnFixture } from "./yearnFixture"; 10 | export { PerpV2Fixture } from "./perpV2Fixture"; 11 | -------------------------------------------------------------------------------- /utils/fixtures/yearnFixture.ts: -------------------------------------------------------------------------------- 1 | import { providers, BigNumber, Signer } from "ethers"; 2 | 3 | import { 4 | Vault, 5 | Registry 6 | } from "../contracts/yearn"; 7 | import DeployHelper from "../deploys"; 8 | import { Address } from "../types"; 9 | 10 | export class YearnFixture { 11 | private _deployer: DeployHelper; 12 | private _ownerAddress: Address; 13 | private _ownerSigner: Signer; 14 | 15 | public registry: Registry; 16 | 17 | constructor(provider: providers.Web3Provider | providers.JsonRpcProvider, ownerAddress: Address) { 18 | this._ownerAddress = ownerAddress; 19 | this._ownerSigner = provider.getSigner(ownerAddress); 20 | this._deployer = new DeployHelper(this._ownerSigner); 21 | } 22 | 23 | public async initialize(): Promise { 24 | this.registry = await this._deployer.external.deployRegistry(); // self.governance = msg.sender == ownerAddress 25 | } 26 | 27 | public async createAndEnableVaultWithStrategyMock( 28 | underlying: Address, 29 | governance: Address, 30 | guardian: Address, 31 | rewards: Address, 32 | name: string, 33 | symbol: string, 34 | depositLimit: BigNumber 35 | ): Promise { 36 | // https://github.com/yearn/yearn-vaults/blob/master/docs/OPERATIONS.md 37 | const emptyVault = await this._deployer.external.deployVault(); 38 | await emptyVault["initialize(address,address,address,string,string,address)"] 39 | (underlying, governance, rewards, name, symbol, guardian); 40 | 41 | await emptyVault.setGovernance(this._ownerAddress); 42 | await emptyVault.acceptGovernance(); 43 | 44 | await this.registry.newRelease(emptyVault.address); 45 | await this.registry["newVault(address,address,address,string,string)"](underlying, guardian, rewards, name, symbol); 46 | 47 | const vaultAddress = await this.registry.latestVault(underlying); 48 | 49 | const vault = await this._deployer.external.getVault(vaultAddress); 50 | await vault.setDepositLimit(depositLimit); 51 | await vault.setManagementFee(0); 52 | 53 | const strategy = await this._deployer.mocks.deployYearnStrategyMock(vault.address); 54 | 55 | await vault.addStrategy(strategy.address, 9800, 0, 1000, 0); 56 | 57 | await strategy.setKeeper(this._ownerAddress); 58 | await strategy.setRewards(rewards); 59 | 60 | 61 | return vault; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /utils/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | addressToData, 3 | bigNumberToData, 4 | bitcoin, 5 | calculateEngageQuantities, 6 | calculateLPTokensIssued, 7 | calculateRebalanceFlows, 8 | calculateRebalanceQuantity, 9 | calculateTokensInReserve, 10 | divDown, 11 | ether, 12 | getExpectedIssuePositionMultiplier, 13 | getExpectedIssuePositionUnit, 14 | getExpectedPostFeeQuantity, 15 | getPostFeePositionUnits, 16 | getExpectedSetTokenIssueQuantity, 17 | getExpectedReserveRedeemQuantity, 18 | getExpectedRedeemPositionMultiplier, 19 | getExpectedRedeemPositionUnit, 20 | getReservesSafe, 21 | getStreamingFee, 22 | getStreamingFeeInflationAmount, 23 | gWei, 24 | hashAdapterName, 25 | min, 26 | preciseDiv, 27 | preciseDivCeil, 28 | preciseMul, 29 | preciseMulCeil, 30 | preciseMulCeilInt, 31 | preciseDivCeilInt, 32 | usdc, 33 | } from "./common"; 34 | -------------------------------------------------------------------------------- /utils/tasks/artifactUtils.ts: -------------------------------------------------------------------------------- 1 | import type { ethers } from "ethers"; 2 | import { NetworkConfig } from "hardhat/types"; 3 | 4 | 5 | // Adds a `gas` field to the ABI function elements so that ethers doesn't 6 | // automatically estimate gas limits on every call. Halves execution time. 7 | // (Borrowed from hardhat-ethers/src/internal/helpers.ts) 8 | export function addGasToAbiMethods( 9 | networkConfig: NetworkConfig, 10 | abi: any[] 11 | ): any[] { 12 | const { BigNumber } = require("ethers") as typeof ethers; 13 | 14 | // Stay well under network limit b/c ethers adds a margin 15 | // Also need special setting logic for coverage b/c it compiles 16 | // before configuring the network with higher gas values. 17 | let gas: number; 18 | if (process.env.COVERAGE === "true") { 19 | const CoverageAPI: any = require("solidity-coverage/api"); 20 | gas = new CoverageAPI().gasLimit as number; 21 | } else { 22 | gas = networkConfig.gas as number; 23 | } 24 | 25 | const gasLimit = BigNumber.from(gas).sub(1000000).toHexString(); 26 | 27 | const modifiedAbi: any[] = []; 28 | 29 | for (const abiElement of abi) { 30 | if (abiElement.type !== "function") { 31 | modifiedAbi.push(abiElement); 32 | continue; 33 | } 34 | 35 | modifiedAbi.push({ 36 | ...abiElement, 37 | gas: gasLimit, 38 | }); 39 | } 40 | 41 | return modifiedAbi; 42 | } 43 | 44 | // Removes gas field from ABI. Useful when temporarily modifying external artifacts 45 | // that have variable gas requirements depending on use context (e.g coverage, different networks) 46 | export function removeGasFromAbiMethods(abi: any[]) { 47 | const modifiedAbi: any[] = []; 48 | 49 | for (const abiElement of abi) { 50 | if (abiElement.type !== "function") { 51 | modifiedAbi.push(abiElement); 52 | continue; 53 | } 54 | 55 | delete abiElement.gas; 56 | 57 | modifiedAbi.push(abiElement); 58 | } 59 | 60 | return modifiedAbi; 61 | } 62 | -------------------------------------------------------------------------------- /utils/tasks/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./artifactUtils"; 2 | export * from "./setupNativeSolc"; 3 | -------------------------------------------------------------------------------- /utils/tasks/setupNativeSolc.ts: -------------------------------------------------------------------------------- 1 | import { execSync } from "child_process"; 2 | 3 | let isFirstRun = true; 4 | 5 | // @ts-ignore 6 | export async function setupNativeSolc({ input }, { config }, runSuper) { 7 | let solcVersionOutput = ""; 8 | try { 9 | solcVersionOutput = execSync("solc --version").toString(); 10 | } catch (error) { 11 | // Probably failed because solc wasn"t installed. We do nothing here. 12 | } 13 | 14 | isFirstRun && console.log("Local native solc version: ", solcVersionOutput); 15 | 16 | if (!solcVersionOutput.includes(config.solidity.version)) { 17 | isFirstRun && console.log("Using solcjs"); 18 | isFirstRun = false; 19 | return runSuper(); 20 | } 21 | 22 | isFirstRun && console.log("Using native solc"); 23 | isFirstRun = false; 24 | 25 | const output = execSync("solc --standard-json", { 26 | input: JSON.stringify(input, undefined, 2), 27 | }); 28 | 29 | return JSON.parse(output.toString("utf8")); 30 | } 31 | -------------------------------------------------------------------------------- /utils/test/index.ts: -------------------------------------------------------------------------------- 1 | // These utils will be provider-aware of the hardhat interface 2 | import { ethers } from "hardhat"; 3 | import { Address } from "../types"; 4 | 5 | import { 6 | AaveV2Fixture, 7 | BalancerFixture, 8 | CompoundFixture, 9 | CurveFixture, 10 | KyberV3DMMFixture, 11 | SystemFixture, 12 | UniswapFixture, 13 | YearnFixture, 14 | UniswapV3Fixture, 15 | PerpV2Fixture 16 | } from "../fixtures"; 17 | import { Blockchain, ProtocolUtils } from "../common"; 18 | 19 | // Hardhat-Provider Aware Exports 20 | const provider = ethers.provider; 21 | export const getSystemFixture = (ownerAddress: Address) => new SystemFixture(provider, ownerAddress); 22 | export const getProtocolUtils = () => new ProtocolUtils(provider); 23 | export const getBlockchainUtils = () => new Blockchain(provider); 24 | export const getAaveV2Fixture = (ownerAdderss: Address) => new AaveV2Fixture(provider, ownerAdderss); 25 | export const getBalancerFixture = (ownerAddress: Address) => new BalancerFixture(provider, ownerAddress); 26 | export const getCurveFixture = (ownerAddress: Address) => new CurveFixture(provider, ownerAddress); 27 | export const getCompoundFixture = (ownerAddress: Address) => new CompoundFixture(provider, ownerAddress); 28 | export const getKyberV3DMMFixture = (ownerAddress: Address) => new KyberV3DMMFixture(provider, ownerAddress); 29 | export const getUniswapFixture = (ownerAddress: Address) => new UniswapFixture(provider, ownerAddress); 30 | export const getYearnFixture = (ownerAddress: Address) => new YearnFixture(provider, ownerAddress); 31 | export const getUniswapV3Fixture = (ownerAddress: Address) => new UniswapV3Fixture(provider, ownerAddress); 32 | export const getPerpV2Fixture = (ownerAddress: Address) => new PerpV2Fixture(provider, ownerAddress); 33 | 34 | export { ForkedTokens } from "./types"; 35 | 36 | export { 37 | getAccounts, 38 | getEthBalance, 39 | getRandomAccount, 40 | getForkedTokens, 41 | initializeForkedTokens, 42 | } from "./accountUtils"; 43 | export { 44 | addSnapshotBeforeRestoreAfterEach, 45 | getLastBlockTimestamp, 46 | getProvider, 47 | getTransactionTimestamp, 48 | getWaffleExpect, 49 | increaseTimeAsync, 50 | mineBlockAsync, 51 | cacheBeforeEach 52 | } from "./testingUtils"; 53 | export { 54 | getRandomAddress 55 | } from "../common"; 56 | -------------------------------------------------------------------------------- /utils/test/types.ts: -------------------------------------------------------------------------------- 1 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address"; 2 | import { Address } from "../types"; 3 | import { IERC20 } from "../../typechain"; 4 | 5 | export type Account = { 6 | address: Address; 7 | wallet: SignerWithAddress; 8 | }; 9 | 10 | export type ForkedTokens = { 11 | [key: string]: IERC20; 12 | }; 13 | -------------------------------------------------------------------------------- /utils/types.ts: -------------------------------------------------------------------------------- 1 | import { BigNumber } from "ethers"; 2 | import { 3 | ContractTransaction as ContractTransactionType, 4 | Wallet as WalletType 5 | } from "ethers"; 6 | 7 | export type Address = string; 8 | export type Bytes = string; 9 | 10 | export type Position = { 11 | component: Address; 12 | module: Address; 13 | unit: BigNumber; 14 | positionState: number; 15 | data: string; 16 | }; 17 | 18 | export type ContractTransaction = ContractTransactionType; 19 | export type Wallet = WalletType; 20 | 21 | export interface StreamingFeeState { 22 | feeRecipient: Address; 23 | streamingFeePercentage: BigNumber; 24 | maxStreamingFeePercentage: BigNumber; 25 | lastStreamingFeeTimestamp: BigNumber; 26 | } 27 | 28 | export interface AirdropSettings { 29 | airdrops: Address[]; 30 | feeRecipient: Address; 31 | airdropFee: BigNumber; 32 | anyoneAbsorb: boolean; 33 | } 34 | 35 | export interface CustomOracleNAVIssuanceSettings { 36 | managerIssuanceHook: Address; 37 | managerRedemptionHook: Address; 38 | setValuer: Address; 39 | reserveAssets: Address[]; 40 | feeRecipient: Address; 41 | managerFees: [BigNumber, BigNumber]; 42 | maxManagerFee: BigNumber; 43 | premiumPercentage: BigNumber; 44 | maxPremiumPercentage: BigNumber; 45 | minSetTokenSupply: BigNumber; 46 | } 47 | -------------------------------------------------------------------------------- /utils/wallets.ts: -------------------------------------------------------------------------------- 1 | import { ethers, providers } from "ethers"; 2 | 3 | export const privateKeys = [ 4 | "0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d", 5 | "0x5d862464fe9303452126c8bc94274b8c5f9874cbd219789b3eb2128075a76f72", 6 | "0xdf02719c4df8b9b8ac7f551fcb5d9ef48fa27eef7a66453879f4d8fdc6e78fb1", 7 | "0xff12e391b79415e941a94de3bf3a9aee577aed0731e297d5cfa0b8a1e02fa1d0", 8 | "0x752dd9cf65e68cfaba7d60225cbdbc1f4729dd5e5507def72815ed0d8abc6249", 9 | "0xefb595a0178eb79a8df953f87c5148402a224cdf725e88c0146727c6aceadccd", 10 | "0x83c6d2cc5ddcf9711a6d59b417dc20eb48afd58d45290099e5987e3d768f328f", 11 | "0xbb2d3f7c9583780a7d3904a2f55d792707c345f21de1bacb2d389934d82796b2", 12 | "0xb2fd4d29c1390b71b8795ae81196bfd60293adf99f9d32a0aff06288fcdac55f", 13 | ]; 14 | 15 | export function generatedWallets(provider: providers.Provider) { 16 | return privateKeys.map((key: string) => { 17 | return new ethers.Wallet(key, provider); 18 | }); 19 | } 20 | --------------------------------------------------------------------------------