Skip to content

Commit

Permalink
fix: merge feeder machines into single more generic class
Browse files Browse the repository at this point in the history
  • Loading branch information
stobiewan authored and superduck35 committed Oct 14, 2021
1 parent 5f670a9 commit 90056a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 363 deletions.
7 changes: 4 additions & 3 deletions contracts/feeders/NonPeggedFeederPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import { FeederLogic } from "./FeederLogic.sol";
/**
* @title NonPeggedFeederPool
* @author mStable, @stobiewan
* @notice Base contract for Feeder Pools (fPools) handling non-pegged stable assets with a redemption price. Feeder Pools are combined of
* 50/50 fAsset and mAsset. This supports efficient swaps into and out of mAssets and the bAssets in the mAsset basket (a.k.a mpAssets).
* There is 0 fee to trade from fAsset into mAsset, providing low cost on-ramps into mAssets.
* @notice Base contract for Feeder Pools (fPools) handling non-pegged stable assets with a redemption price. Feeder
* Pools are combined of 50/50 fAsset and mAsset. This supports efficient swaps into and out of mAssets and the
* bAssets in the mAsset basket (a.k.a mpAssets). There is 0 fee to trade from fAsset into mAsset, providing
* low cost on-ramps into mAssets.
* @dev VERSION: 1.0
* DATE: 2021-10-01
*/
Expand Down
34 changes: 29 additions & 5 deletions test-utils/machines/feederMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
MockAaveV2__factory,
Masset,
MockERC20__factory,
NonPeggedFeederPool__factory,
RedemptionPriceSnapMock,
RedemptionPriceSnapMock__factory,
} from "types/generated"
import { BN, minimum, simpleToExactAmount } from "@utils/math"
import { ratioScale, ZERO_ADDRESS, DEAD_ADDRESS, fullScale } from "@utils/constants"
Expand All @@ -36,6 +39,7 @@ export interface FeederDetails {
bAssets?: MockERC20[]
pTokens?: Array<string>
mAssetDetails?: MassetDetails
redemptionPriceSnap?: RedemptionPriceSnapMock
}

export class FeederMachine {
Expand All @@ -59,6 +63,7 @@ export class FeederMachine {
useLendingMarkets = false,
useInterestValidator = false,
use2dp = false,
useRedemptionPrice = false,
): Promise<FeederDetails> {
const mAssetDetails = await this.mAssetMachine.deployMasset(useLendingMarkets, false)
// Mints 10k mAsset to begin with
Expand All @@ -72,6 +77,9 @@ export class FeederMachine {
"contracts/feeders/FeederLogic.sol:FeederLogic": feederLogic.address,
"contracts/feeders/FeederManager.sol:FeederManager": feederManager.address,
}
let redemptionPriceSnap: RedemptionPriceSnapMock
let feederPoolFactory;
let impl;

// - Deploy InterestValidator contract
let interestValidator: InterestValidator
Expand Down Expand Up @@ -104,10 +112,25 @@ export class FeederMachine {
}

// Deploy feeder pool
const impl = await new FeederPool__factory(linkedAddress, this.sa.default.signer).deploy(
mAssetDetails.nexus.address,
mAssetDetails.mAsset.address,
)
if (useRedemptionPrice) {
// - Deploy RedemptionPriceSnapMock contract
redemptionPriceSnap = await new RedemptionPriceSnapMock__factory(this.sa.default.signer).deploy()
let redemptionPriceSnapAddress = redemptionPriceSnap.address

feederPoolFactory = NonPeggedFeederPool__factory;
impl = await new feederPoolFactory(linkedAddress, this.sa.default.signer).deploy(
mAssetDetails.nexus.address,
mAssetDetails.mAsset.address,
redemptionPriceSnapAddress,
)
}
else {
feederPoolFactory = FeederPool__factory;
impl = await new feederPoolFactory(linkedAddress, this.sa.default.signer).deploy(
mAssetDetails.nexus.address,
mAssetDetails.mAsset.address,
)
}
const data = impl.interface.encodeFunctionData("initialize", [
"mStable mBTC/bBTC Feeder",
"bBTC fPool",
Expand Down Expand Up @@ -135,7 +158,7 @@ export class FeederMachine {
// Deploy feeder pool proxy and call initialize on the feeder pool implementation
const poolProxy = await new AssetProxy__factory(this.sa.default.signer).deploy(impl.address, DEAD_ADDRESS, data)
// Link the feeder pool ABI to its proxy
const pool = await new FeederPool__factory(linkedAddress, this.sa.default.signer).attach(poolProxy.address)
const pool = await new feederPoolFactory(linkedAddress, this.sa.default.signer).attach(poolProxy.address)

// - Add feeder pool to the platform integration whitelist
if (useLendingMarkets) {
Expand Down Expand Up @@ -163,6 +186,7 @@ export class FeederMachine {
bAssets,
pTokens,
mAssetDetails,
redemptionPriceSnap,
}
}

Expand Down
Loading

0 comments on commit 90056a5

Please sign in to comment.