Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into indexfund-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey authored and Andrey committed Jul 24, 2023
2 parents 82bf6f3 + eaa0356 commit 8f9a543
Show file tree
Hide file tree
Showing 57 changed files with 3,120 additions and 415 deletions.
82 changes: 41 additions & 41 deletions contract-address.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"31337": {
"accounts": {
"diamond": "0x1D99a347B5EcdbAa3C5365470d461Cf66B77ECd2",
"diamond": "0x84227190685c25c4aF662EE1bD0E4cd82e57360D",
"facets": {
"accountsDeployContract": "0xbe241D1B7b54bF06742cefd45A3440C6562f7603",
"accountsDepositWithdrawEndowments": "0x3c705dB336C81c7FEFC5746e283aB2c0781A4B7b",
"accountsDonationMatch": "0xA82ED5224ba72f2f776e09B11DC99E30Ee65Da8d",
"accountsAllowance": "0x1dBDba33dfA381bCC89FCe74DFF69Aa96B53b503",
"accountsCreateEndowment": "0x7798A400cBe0Ca14a7D614ECa1CD15adE5055413",
"accountsDaoEndowments": "0x17C8b71E5eE01A726766c99d397D619219C8CAF3",
"accountsQueryEndowments": "0xE4F89Fb0dBb45378633c05ACAb071eB998F0A736",
"accountsStrategy": "0x9Fe28b717aDE38BA99E32c45BE3Ee4291f2E338B",
"accountsSwapRouter": "0x7B3Be2dDDdDf9A0a3fE1DC57B98980F662C3a422",
"accountsUpdate": "0x8990C5DAAA40673eF8826990A6Fd8284a0a17d61",
"accountsUpdateEndowments": "0x90352F820342f8BE0012848bCB8aBd37877d7ec2",
"accountsUpdateEndowmentSettingsController": "0x82B642D9deDb3Ad19b8E99FF3792A49d4d9d85Bf",
"accountsUpdateStatusEndowments": "0xf69E1dFAc3D43F438Bae80090b8E186B0231CFeb",
"diamondCutFacet": "0x49FcbCC4E425add3a45AFC82F4dD0E5c227A0Ff8",
"diamondInitFacet": "0x84227190685c25c4aF662EE1bD0E4cd82e57360D",
"diamondLoupeFacet": "0xDDEec1224034F4A68A2697eF13379a014fa60261",
"ownershipFacet": "0x199c27B10a195ee79e02d50846e59A4aFB82CAD1"
"accountsDeployContract": "0xA82ED5224ba72f2f776e09B11DC99E30Ee65Da8d",
"accountsDepositWithdrawEndowments": "0x1dBDba33dfA381bCC89FCe74DFF69Aa96B53b503",
"accountsDonationMatch": "0x17C8b71E5eE01A726766c99d397D619219C8CAF3",
"accountsAllowance": "0x7798A400cBe0Ca14a7D614ECa1CD15adE5055413",
"accountsCreateEndowment": "0x7B3Be2dDDdDf9A0a3fE1DC57B98980F662C3a422",
"accountsDaoEndowments": "0x8990C5DAAA40673eF8826990A6Fd8284a0a17d61",
"accountsQueryEndowments": "0xf69E1dFAc3D43F438Bae80090b8E186B0231CFeb",
"accountsStrategy": "0x650aEF4b63095e4EDe581BC79CdeA927e3ba553A",
"accountsSwapRouter": "0x90352F820342f8BE0012848bCB8aBd37877d7ec2",
"accountsUpdate": "0xE4F89Fb0dBb45378633c05ACAb071eB998F0A736",
"accountsUpdateEndowments": "0x82B642D9deDb3Ad19b8E99FF3792A49d4d9d85Bf",
"accountsUpdateEndowmentSettingsController": "0x9Fe28b717aDE38BA99E32c45BE3Ee4291f2E338B",
"accountsUpdateStatusEndowments": "0xDDEec1224034F4A68A2697eF13379a014fa60261",
"diamondCutFacet": "0x1D99a347B5EcdbAa3C5365470d461Cf66B77ECd2",
"diamondInitFacet": "0xbe241D1B7b54bF06742cefd45A3440C6562f7603",
"diamondLoupeFacet": "0x199c27B10a195ee79e02d50846e59A4aFB82CAD1",
"ownershipFacet": "0x3c705dB336C81c7FEFC5746e283aB2c0781A4B7b"
}
},
"axelar": {
"gasService": "0x55cb3b67D9E65F0Cf4eABCAC84564a1bE6E3b06A",
"gateway": "0x7290f72B5C67052DDE8e6E179F7803c493e90d3f"
"gasService": "0x7290f72B5C67052DDE8e6E179F7803c493e90d3f",
"gateway": "0x0AFdAcD509e73115EA1654B1a770f1a807e7c9C0"
},
"donationMatch": {
"emitter": "",
Expand All @@ -39,8 +39,8 @@
"proxy": ""
},
"gasFwd": {
"factory": "0x87F850cbC2cFfac086F20d0d7307E12d06fA2127",
"implementation": "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"
"factory": "0xB0748F8B73C53aB94b3DD1109f3427B7Bb2907F5",
"implementation": "0xDeBD0Bc00932E8b5bEfF65053989B0687c894b5F"
},
"giftcards": {
"implementation": "",
Expand Down Expand Up @@ -101,38 +101,38 @@
"implementation": ""
},
"indexFund": {
"implementation": "0x549bc7EE4B85A2Df5F74799f213483CE599F1999",
"proxy": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
"implementation": "0x34E59e53Bd4f1A60ca8b6c21572509027571341d",
"proxy": "0x0165878A594ca255338adfa4d48449f69242Eb8F"
},
"libraries": {
"angelCoreStruct": "",
"stringArray": ""
},
"multiSig": {
"charityApplications": {
"implementation": "0xDeBD0Bc00932E8b5bEfF65053989B0687c894b5F",
"proxy": "0xB0748F8B73C53aB94b3DD1109f3427B7Bb2907F5"
"implementation": "0x549bc7EE4B85A2Df5F74799f213483CE599F1999",
"proxy": "0xEe54514745B056F07040CaCF801f59031D801431"
},
"apTeam": {
"implementation": "0xa85b028984bC54A2a3D844B070544F59dDDf89DE",
"proxy": "0xD499f5F7d3C918D0e553BA03954c4E02af16B6e4"
"implementation": "0xD499f5F7d3C918D0e553BA03954c4E02af16B6e4",
"proxy": "0xDadd1125B8Df98A66Abd5EB302C0d9Ca5A061dC2"
},
"endowment": {
"emitter": {
"implementation": "0x20F43316cf784C821a65aE874c8060f30c30c7C4",
"proxy": "0x9B4aC8FAfC44575C6963fA22D50963379e899a49"
"implementation": "0xa115891Cae16388b84cb7a521A2032f6b354FE25",
"proxy": "0x6ad448bF2AdbF3A7Aa9BfE411eD908315566aE24"
},
"factory": "0x34E59e53Bd4f1A60ca8b6c21572509027571341d",
"implementation": "0xEe54514745B056F07040CaCF801f59031D801431"
"factory": "0x9B4aC8FAfC44575C6963fA22D50963379e899a49",
"implementation": "0x20F43316cf784C821a65aE874c8060f30c30c7C4"
}
},
"registrar": {
"implementation": "0xDadd1125B8Df98A66Abd5EB302C0d9Ca5A061dC2",
"proxy": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
"implementation": "0x2572e04Caf46ba8692Bd6B4CBDc46DAA3cA9647E",
"proxy": "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0"
},
"router": {
"implementation": "0x23d351BA89eaAc4E328133Cb48e050064C219A1E",
"proxy": "0x35D2F51DBC8b401B11fA3FE04423E0f5cd9fEDb4"
"implementation": "0x72F375F23BCDA00078Ac12e7e9E7f6a8CA523e7D",
"proxy": "0xf23B8c9debCdCEa2a40E81c3f6d786987069D40d"
},
"subDao": {
"emitter": {
Expand All @@ -147,9 +147,9 @@
"dai": "",
"halo": "",
"reserveToken": "",
"seedAsset": "0x0AFdAcD509e73115EA1654B1a770f1a807e7c9C0",
"usdc": "0x1a6a3e7Bb246158dF31d8f924B84D961669Ba4e5",
"wmatic": "0xBa3e08b4753E68952031102518379ED2fDADcA30"
"seedAsset": "0xc63d2a04762529edB649d7a4cC3E57A0085e8544",
"usdc": "0x093e8F4d8f267d2CeEc9eB889E2054710d187beD",
"wmatic": "0x34ee84036C47d852901b7069aBD80171D9A489a6"
},
"uniswap": {
"factory": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
Expand Down Expand Up @@ -267,8 +267,8 @@
},
"multiSig": {
"charityApplications": {
"implementation": "0xe657852734f2c5215a5e8A69EF564eAfAFfb81bC",
"proxy": "0x3769916a8c97FFf1C48DE49b03181578576aFdF1"
"implementation": "0xE2Af564F27EE4a6721f1650f9FAa975a11Fdc50F",
"proxy": "0x4cb1E5cc57a5cEb38C0087300cFdDDE3a08B3694"
},
"apTeam": {
"implementation": "0xC944590c3fe90e97129ac5AF077DCFB229f3A909",
Expand Down
4 changes: 3 additions & 1 deletion contracts/core/accounts/facets/AccountsDeployContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ contract AccountsDeployContract is IAccountsDeployContract, ReentrancyGuardFacet
registrar_config.subdaoEmitter
);

// TODO: create a ProxyFactory contract that instantiates proxy contracts
// Reason: will make the contract more easily testable (factory could be mocked)
daoAddress = address(new ProxyContract(implementation, admin, subDaoData));
// >> SHOULD IT BE CALLED INSIDE SubDao.initializeSubDao?

ISubDaoEmitter(registrar_config.subdaoEmitter).initializeSubDao(daoAddress);

ISubDao(daoAddress).buildDaoTokenMesage(createDaoMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {AccountStorage} from "../storage.sol";
import {Validator} from "../../validator.sol";
import {IRegistrar} from "../../registrar/interfaces/IRegistrar.sol";
import {RegistrarStorage} from "../../registrar/storage.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IDonationMatching} from "../../../normalized_endowment/donation-match/IDonationMatching.sol";
import {ReentrancyGuardFacet} from "./ReentrancyGuardFacet.sol";
import {IAccountsEvents} from "../interfaces/IAccountsEvents.sol";
Expand All @@ -29,6 +30,7 @@ contract AccountsDepositWithdrawEndowments is
IAccountsDepositWithdrawEndowments
{
using SafeMath for uint256;
using SafeERC20 for IERC20;

/**
* @notice Deposit MATIC into the endowment. Wraps first to ERC20 before processing.
Expand Down Expand Up @@ -74,10 +76,8 @@ contract AccountsDepositWithdrawEndowments is
state.AcceptedTokens[details.id][tokenAddress],
"Not in an Accepted Tokens List"
);
require(
IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount),
"Transfer failed"
);

IERC20(tokenAddress).safeTransferFrom(msg.sender, address(this), amount);

processTokenDeposit(details, tokenAddress, amount);
}
Expand All @@ -97,7 +97,6 @@ contract AccountsDepositWithdrawEndowments is
AccountStorage.State storage state = LibAccounts.diamondStorage();
AccountStorage.Endowment storage tempEndowment = state.ENDOWMENTS[details.id];

require(tokenAddress != address(0), "Invalid ERC20 token");
require(details.lockedPercentage + details.liquidPercentage == 100, "InvalidSplit");

RegistrarStorage.Config memory registrar_config = IRegistrar(state.config.registrarContract)
Expand All @@ -109,24 +108,19 @@ contract AccountsDepositWithdrawEndowments is
);
amount = amount.sub(depositFeeAmount);

require(
IERC20(tokenAddress).transfer(tempEndowment.depositFee.payoutAddress, depositFeeAmount),
"Transfer Failed"
);
IERC20(tokenAddress).safeTransfer(tempEndowment.depositFee.payoutAddress, depositFeeAmount);
}

uint256 lockedSplitPercent = details.lockedPercentage;
uint256 liquidSplitPercent = details.liquidPercentage;

LibAccounts.SplitDetails memory registrar_split_configs = registrar_config.splitToLiquid;

require(registrar_config.indexFundContract != address(0), "No Index Fund");

if (msg.sender != registrar_config.indexFundContract) {
if (tempEndowment.endowType == LibAccounts.EndowmentType.Charity) {
// use the Registrar default split for Charities
(lockedSplitPercent, liquidSplitPercent) = Validator.checkSplits(
registrar_split_configs,
registrar_config.splitToLiquid,
lockedSplitPercent,
liquidSplitPercent,
tempEndowment.ignoreUserSplits
Expand Down Expand Up @@ -174,7 +168,6 @@ contract AccountsDepositWithdrawEndowments is
state.STATES[details.id].balances.locked[tokenAddress] += lockedAmount;
state.STATES[details.id].balances.liquid[tokenAddress] += liquidAmount;

state.ENDOWMENTS[details.id] = tempEndowment;
emit EndowmentDeposit(details.id, tokenAddress, lockedAmount, liquidAmount);
}

Expand Down Expand Up @@ -233,7 +226,7 @@ contract AccountsDepositWithdrawEndowments is
senderAllowed = true;
}
}
require(senderAllowed, "Sender address is not listed in maturityAllowlist.");
require(senderAllowed, "Sender address is not listed in maturityAllowlist");
}
} else {
if (tempEndowment.allowlistedBeneficiaries.length > 0) {
Expand All @@ -245,7 +238,7 @@ contract AccountsDepositWithdrawEndowments is
}
require(
senderAllowed || msg.sender == tempEndowment.owner,
"Sender address is not listed in allowlistedBeneficiaries nor is it the Endowment Owner."
"Sender address is not listed in allowlistedBeneficiaries nor is it the Endowment Owner"
);
}

Expand Down Expand Up @@ -291,19 +284,16 @@ contract AccountsDepositWithdrawEndowments is
}

// ensure balance of tokens can cover the requested withdraw amount
require(current_bal > tokens[t].amnt, "InsufficientFunds");
require(current_bal >= tokens[t].amnt, "Insufficient Funds");

// calculate AP Protocol fee owed on withdrawn token amount
uint256 withdrawFeeAp = (tokens[t].amnt.mul(withdrawFeeRateAp)).div(LibAccounts.FEE_BASIS);

// Transfer AP Protocol fee to treasury
// (ie. standard Withdraw Fee + any early Locked Withdraw Penalty)
require(
IERC20(tokens[t].addr).transfer(
registrar_config.treasury,
withdrawFeeAp + earlyLockedWithdrawPenalty
),
"Transfer failed"
IERC20(tokens[t].addr).safeTransfer(
registrar_config.treasury,
withdrawFeeAp + earlyLockedWithdrawPenalty
);

// ** Endowment specific withdraw fee **
Expand All @@ -317,20 +307,17 @@ contract AccountsDepositWithdrawEndowments is
);

// transfer endowment withdraw fee to payout address
require(
IERC20(tokens[t].addr).transfer(
tempEndowment.withdrawFee.payoutAddress,
withdrawFeeEndow
),
"Insufficient Funds"
IERC20(tokens[t].addr).safeTransfer(
tempEndowment.withdrawFee.payoutAddress,
withdrawFeeEndow
);
}

// send all tokens (less fees) to the ultimate beneficiary address/endowment
if (beneficiaryAddress != address(0)) {
require(
IERC20(tokens[t].addr).transfer(beneficiaryAddress, (amountLeftover - withdrawFeeEndow)),
"Transfer failed"
IERC20(tokens[t].addr).safeTransfer(
beneficiaryAddress,
(amountLeftover - withdrawFeeEndow)
);
} else {
// check endowment specified is not closed
Expand All @@ -340,7 +327,11 @@ contract AccountsDepositWithdrawEndowments is
);
// Send deposit message to 100% Liquid account of an endowment
processTokenDeposit(
AccountMessages.DepositRequest({id: id, lockedPercentage: 0, liquidPercentage: 100}),
AccountMessages.DepositRequest({
id: beneficiaryEndowId,
lockedPercentage: 0,
liquidPercentage: 100
}),
tokens[t].addr,
(amountLeftover - withdrawFeeEndow)
);
Expand Down
Loading

0 comments on commit 8f9a543

Please sign in to comment.