Skip to content

Commit

Permalink
Fix local deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
ljiatu committed Dec 31, 2023
1 parent 102d11e commit b90a58f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
1 change: 0 additions & 1 deletion contracts/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ contract Errors {
// first loss cover operation
error notAllProvidersPaidOut(); // 0xf878b213
error firstLossCoverLiquidityCapExceeded();
error tooManyProviders();

// receivable operation
error receivableAssetMismatch(); // 0x41dbeec1
Expand Down
6 changes: 4 additions & 2 deletions contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ interface IPool {

/**
* @notice Distributes loss recovery to senior tranche, junior tranche and first loss covers
* @param lossRecovery the amount that was deemed as losses before and has been recovered.
* @param lossRecovery the amount that was deemed as losses before and has been receovered.
* This amount shall be distributed to senior tranche, junior tranche, and first loss covers
* in this sequence to offset the losses that they have experienced before.
* in this sequenence to offset the losses that they have experienced before.
*/
function distributeLossRecovery(uint256 lossRecovery) external;

/**
* @notice Updates the assets for the two tranches with the specified values.
* @dev This function should only be called after `refreshPool` is called to bring
* the assets data up-to-date.
* @param assets The amount of assets for each tranche to update to.
*/
function updateTranchesAssets(uint96[2] memory assets) external;
Expand Down
33 changes: 7 additions & 26 deletions scripts/deploy-local-test-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
deployProtocolContracts,
PayPeriodDuration,
} from "../test/BaseTest";
import {
getMinFirstLossCoverRequirement,
overrideFirstLossCoverConfig,
toToken,
} from "../test/TestUtils";
import { overrideFirstLossCoverConfig, toToken } from "../test/TestUtils";
import {
BorrowerLevelCreditManager,
Calendar,
Expand Down Expand Up @@ -71,27 +67,12 @@ let poolConfigContract: PoolConfig,
creditDueManagerContract: CreditDueManager,
creditManagerContract: BorrowerLevelCreditManager;

async function depositFirstLossCover(
poolContract: Pool,
coverContract: FirstLossCover,
account: SignerWithAddress,
) {
const fetchPoolConfigContractAddr = await poolContract.poolConfig();
const PoolConfig = await ethers.getContractFactory("PoolConfig");
const fetchPoolConfigContract = PoolConfig.attach(fetchPoolConfigContractAddr);

await coverContract.connect(poolOwner).setCoverProvider(account.address, {
poolCapCoverageInBps: 1,
poolValueCoverageInBps: 100,
});
async function depositFirstLossCover(coverContract: FirstLossCover, account: SignerWithAddress) {
await coverContract.connect(poolOwner).addCoverProvider(account.address);
await mockTokenContract
.connect(account)
.approve(coverContract.address, ethers.constants.MaxUint256);
await coverContract
.connect(account)
.depositCover(
(await getMinFirstLossCoverRequirement(coverContract, fetchPoolConfigContract)).mul(2),
);
await coverContract.connect(account).depositCover(toToken(1_000));
}

async function deployPool(
Expand Down Expand Up @@ -167,7 +148,7 @@ async function deployPool(
);

// Deposit first loss cover
await depositFirstLossCover(poolContract, borrowerFirstLossCoverContract, borrowerActive);
await depositFirstLossCover(borrowerFirstLossCoverContract, borrowerActive);

// Set first loss cover liquidity cap
const totalAssetsBorrowerFLC = await borrowerFirstLossCoverContract.totalAssets();
Expand All @@ -179,7 +160,7 @@ async function deployPool(
poolConfigContract,
poolOwner,
{
liquidityCap: totalAssetsBorrowerFLC.sub(yieldAmount),
maxLiquidity: totalAssetsBorrowerFLC.sub(yieldAmount),
},
);
await overrideFirstLossCoverConfig(
Expand All @@ -188,7 +169,7 @@ async function deployPool(
poolConfigContract,
poolOwner,
{
liquidityCap: totalAssetsAffiliateFLC.sub(yieldAmount),
maxLiquidity: totalAssetsAffiliateFLC.sub(yieldAmount),
},
);

Expand Down

0 comments on commit b90a58f

Please sign in to comment.