Skip to content

Commit

Permalink
Merge d9f4516 into 2128a93
Browse files Browse the repository at this point in the history
  • Loading branch information
alsco77 committed Feb 26, 2021
2 parents 2128a93 + d9f4516 commit 3822c0f
Show file tree
Hide file tree
Showing 49 changed files with 130,005 additions and 67 deletions.
9 changes: 9 additions & 0 deletions contracts/feeders/FeederLogic.sol
Expand Up @@ -669,6 +669,15 @@ library FeederLogic {
totalmAssets = (_config.supply * (k0 - k1)) / k0;
}

function computePrice(
BassetData[] memory _bAssets,
FeederConfig memory _config
) public view returns (uint256 price, uint256 k) {
(uint256[] memory x, uint256 sum) = _getReserves(_bAssets);
k = _invariant(x, sum, _config.a);
price = 1e18 * k / _config.supply;
}

/***************************************
INTERNAL
****************************************/
Expand Down
8 changes: 6 additions & 2 deletions contracts/feeders/FeederPool.sol
Expand Up @@ -120,8 +120,8 @@ contract FeederPool is
data.ampData = AmpData(startA, startA, 0, 0);
data.weightLimits = _config.limits;

data.swapFee = 20e14;
data.redemptionFee = 10e14;
data.swapFee = 8e14;
data.redemptionFee = 4e14;
data.cacheSize = 1e17;
}

Expand Down Expand Up @@ -551,6 +551,10 @@ contract FeederPool is
GETTERS
****************************************/

function getPrice() public view returns (uint256 price, uint256 k) {
return FeederLogic.computePrice(data.bAssetData, _getConfig());
}

/**
* @dev Get data for a all bAssets in basket
* @return personal Struct[] with full bAsset data
Expand Down
55 changes: 55 additions & 0 deletions contracts/z_mocks/feeder/ExposedFeederLogic.sol
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.0;

import "../../masset/MassetStructs.sol";
import { FeederLogic } from "../../feeders/FeederLogic.sol";

contract ExposedFeederLogic {

function computeMint(
BassetData[] memory _bAssets,
uint8 _i,
uint256 _rawInput,
FeederConfig memory _config
) public view returns (uint256 mintAmount) {
return FeederLogic.computeMint(_bAssets, _i, _rawInput, _config);
}

function computeMintMulti(
BassetData[] memory _bAssets,
uint8[] memory _indices,
uint256[] memory _rawInputs,
FeederConfig memory _config
) public view returns (uint256 mintAmount) {
return FeederLogic.computeMintMulti(_bAssets, _indices, _rawInputs, _config);
}

function computeSwap(
BassetData[] memory _bAssets,
uint8 _i,
uint8 _o,
uint256 _rawInput,
uint256 _feeRate,
FeederConfig memory _config
) public view returns (uint256 bAssetOutputQuantity, uint256 scaledSwapFee) {
return FeederLogic.computeSwap(_bAssets, _i, _o, _rawInput, _feeRate, _config);
}

function computeRedeem(
BassetData[] memory _bAssets,
uint8 _o,
uint256 _netMassetQuantity,
FeederConfig memory _config
) public view returns (uint256 rawOutputUnits) {
return FeederLogic.computeRedeem(_bAssets, _o, _netMassetQuantity, _config);
}

function computeRedeemExact(
BassetData[] memory _bAssets,
uint8[] memory _indices,
uint256[] memory _rawOutputs,
FeederConfig memory _config
) public view returns (uint256 totalmAssets) {
return FeederLogic.computeRedeemExact(_bAssets, _indices, _rawOutputs, _config);
}
}
11 changes: 11 additions & 0 deletions contracts/z_mocks/feeder/ExposedFeederPool.sol
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity 0.8.0;

import "../../masset/MassetStructs.sol";
import { FeederPool } from "../../feeders/FeederPool.sol";

contract ExposedFeederPool is FeederPool {

constructor(address _nexus, address _mAsset) FeederPool(_nexus, _mAsset) {}

}
6 changes: 6 additions & 0 deletions hardhat.config.ts
Expand Up @@ -40,6 +40,12 @@ export const hardhatConfig = {
enabled: true,
runs: 200,
},
outputSelection: {
"*": {
Masset: ["storageLayout"],
FeederPool: ["storageLayout"],
},
},
},
},
paths: { artifacts: "./build" },
Expand Down
2 changes: 1 addition & 1 deletion tasks/deployFeeder.ts
Expand Up @@ -190,7 +190,7 @@ const deployVault = async (sender: Signer, addresses: CommonAddresses, feederPoo
addresses.nexus,
feederPool.address,
addresses.staking,
simpleToExactAmount(1, 18),
simpleToExactAmount(30000, 18),
addresses.mta,
)
const receiptVaultImpl = await vImpl.deployTransaction.wait()
Expand Down
60 changes: 57 additions & 3 deletions test-utils/machines/mAssetMachine.ts
Expand Up @@ -57,6 +57,58 @@ export class MassetMachine {
return this
}

// 3 bAssets, custom reserve
public async deployLite(): Promise<MassetDetails> {
const bAssets = await Promise.all([0, 1, 2].map((i) => this.loadBassetProxy(`${i}BASSET`, `${i}BASSET`, 18)))

const forgeVal = await new InvariantValidator__factory(this.sa.default.signer).deploy(
simpleToExactAmount(1, 26),
simpleToExactAmount(1, 24),
)

const ManagerFactory = await ethers.getContractFactory("Manager")
const managerLib = (await ManagerFactory.deploy()) as Manager

const nexus = await new MockNexus__factory(this.sa.default.signer).deploy(
this.sa.governor.address,
this.sa.mockSavingsManager.address,
)
const MassetFactory = (await (
await ethers.getContractFactory("ExposedMasset", {
libraries: {
Manager: managerLib.address,
},
})
).connect(this.sa.default.signer)) as ExposedMasset__factory
const impl = (await MassetFactory.deploy(nexus.address)) as ExposedMasset

const data = impl.interface.encodeFunctionData("initialize", [
"mAsset Lite",
"mLite",
forgeVal.address,
bAssets.map((b) => ({
addr: b.address,
integrator: ZERO_ADDRESS,
hasTxFee: false,
status: 0,
})),
{
a: BN.from(135),
limits: {
min: simpleToExactAmount(5, 16),
max: simpleToExactAmount(75, 16),
},
},
])
const mAsset = await new AssetProxy__factory(this.sa.default.signer).deploy(impl.address, DEAD_ADDRESS, data)

return {
mAsset: (await MassetFactory.attach(mAsset.address)) as ExposedMasset,
bAssets,
forgeValidator: forgeVal as InvariantValidator,
}
}

public async deployMasset(useMockValidator = false, useLendingMarkets = false, useTransferFees = false): Promise<MassetDetails> {
// 1. Bassets
const bAssets = await this.loadBassetsLocal(useLendingMarkets, useTransferFees)
Expand All @@ -65,7 +117,7 @@ export class MassetMachine {
// If mocks enabled, uses mock which returns 1:1 on all actions
const forgeVal = await (useMockValidator
? new MockInvariantValidator__factory(this.sa.default.signer).deploy()
: new InvariantValidator__factory(this.sa.default.signer).deploy(simpleToExactAmount(1, 24), simpleToExactAmount(1, 24)))
: new InvariantValidator__factory(this.sa.default.signer).deploy(simpleToExactAmount(1, 26), simpleToExactAmount(1, 24)))

// 3. Masset
// 3.1. Dependencies
Expand Down Expand Up @@ -139,9 +191,11 @@ export class MassetMachine {
* @param md Masset details object containing all deployed contracts
* @param weights Whole numbers of mAsset to mint for each given bAsset
*/
public async seedWithWeightings(md: MassetDetails, weights: Array<BN | number>): Promise<void> {
public async seedWithWeightings(md: MassetDetails, weights: Array<BN | number>, inputIsInBaseUnits = false): Promise<void> {
const { mAsset, bAssets } = md
const approvals = await Promise.all(bAssets.map((b, i) => this.approveMasset(b, mAsset, weights[i], this.sa.default.signer)))
const approvals = await Promise.all(
bAssets.map((b, i) => this.approveMasset(b, mAsset, weights[i], this.sa.default.signer, inputIsInBaseUnits)),
)
await mAsset.mintMulti(
bAssets.map((b) => b.address),
approvals,
Expand Down
43 changes: 43 additions & 0 deletions test-utils/validator-data/cross/index.ts
@@ -0,0 +1,43 @@
// import fullIntegrationData from "./full/crossIntegrationData.json"
// import fullMintData from "./full/crossMintData.json"
// import fullSwapToFassetData from "./full/swapToFassetData.json"
// import fullSwapToMPassetData from "./full/swapToMPassetData.json"
// import fullRedeemData from "./full/crossRedeemData.json"

import sampleIntegrationData from "./sample/crossIntegrationData.json"
import sampleMintData from "./sample/crossMintData.json"
import sampleSwapToFassetData from "./sample/swapToFassetData.json"
import sampleSwapToMPassetData from "./sample/swapToMPassetData.json"
import sampleRedeemData from "./sample/crossRedeemData.json"

interface Data {
full
sample
}

const integrationData: Data = {
full: null,
sample: sampleIntegrationData,
}

const mintData: Data = {
full: null,
sample: sampleMintData,
}

const swapToFassetData: Data = {
full: null,
sample: sampleSwapToFassetData,
}

const swapToMPassetData: Data = {
full: null,
sample: sampleSwapToMPassetData,
}

const redeemData: Data = {
full: null,
sample: sampleRedeemData,
}

export default { integrationData, mintData, swapToFassetData, swapToMPassetData, redeemData }

0 comments on commit 3822c0f

Please sign in to comment.