From 56868510c78545f2990657e153c0a8b7c6efd455 Mon Sep 17 00:00:00 2001 From: calee14 Date: Wed, 1 Jun 2022 15:33:11 -0700 Subject: [PATCH 1/5] updating last minute changes --- src/smartcontracts/TokenSwap.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/smartcontracts/TokenSwap.sol b/src/smartcontracts/TokenSwap.sol index 2b3c3bc..f2aa23c 100644 --- a/src/smartcontracts/TokenSwap.sol +++ b/src/smartcontracts/TokenSwap.sol @@ -8,29 +8,29 @@ import "https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/in contract Swapper { address internal constant UNISWAP_ROUTER_ADDRESS = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D ; - IUniswapV2Router02 public uniswapRouter; + IUniswapV2Router02 public UniswapRouter; address private daiRinkeby = 0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa; constructor() { - uniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS); + UniswapRouter = IUniswapV2Router02(UNISWAP_ROUTER_ADDRESS); } function convertEthToToken(uint daiAmount, address _token) public payable { uint deadline = block.timestamp + 15; // give some padding for the transaction to complete - uniswapRouter.swapETHForExactTokens{ value: msg.value }(daiAmount, getPathForETHtoToken(_token), msg.sender, deadline); + UniswapRouter.swapETHForExactTokens{ value: msg.value }(daiAmount, getPathForETHtoToken(_token), msg.sender, deadline); // refund leftover ETH to user - (bool success,) = msg.sender.call{ value: address(this).balance }(""); - require(success, "refund failed"); + (bool status,) = msg.sender.call{ value: address(this).balance }(""); + require(status, "could not refund"); } - function getEstimatedETHforToken(uint daiAmount, address _token) public view returns (uint[] memory) { - return uniswapRouter.getAmountsIn(daiAmount, getPathForETHtoToken(_token)); + function getEstimatedETHforToken(uint tokenAmount, address _token) public view returns (uint[] memory) { + return UniswapRouter.getAmountsIn(tokenAmount, getPathForETHtoToken(_token)); } function getPathForETHtoToken(address _token) private view returns (address[] memory) { address[] memory path = new address[](2); - path[0] = uniswapRouter.WETH(); + path[0] = UniswapRouter.WETH(); path[1] = _token; return path; From 87b2427550cc75889a16e230e24ea151028317b0 Mon Sep 17 00:00:00 2001 From: calee14 Date: Tue, 7 Jun 2022 23:09:52 -0700 Subject: [PATCH 2/5] store orgs on blockchain --- src/smartcontracts/AidStorage.sol | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/smartcontracts/AidStorage.sol diff --git a/src/smartcontracts/AidStorage.sol b/src/smartcontracts/AidStorage.sol new file mode 100644 index 0000000..1cce749 --- /dev/null +++ b/src/smartcontracts/AidStorage.sol @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.7.0 <0.9.0; + +contract AidStorage { + + struct NftUnit { + string imgUrl; + string raribleUrl; + string price; + } + + // struct object of an organization + struct Organization { + string title; // org. title + string user; // org. owner's username + string location; // org.'s location + string imgUrl; // org.'s thumbnail image url + string goal; // org.'s goal (in eth) + string donated; // org.'s amount donations received (in eth) + string description; // the org.'s description + address ownerEthAddress; // org.'s owner eth address + string[] milestones; // org.'s milestones + bool[] progress; // the progress of each milestone + } + + uint public numOrganizations; + // public dynamic array of all organizations + Organization[] public orgs; + mapping (uint => NftUnit[]) orgNfts; + + constructor() { + + } + + function createOrganiation(string memory _title, string memory _user, string memory _location, + string memory _imgUrl, string memory _goal, string memory _donated, + string memory _description, address _ownerEthAddress) public { + Organization memory newOrg; + newOrg.title = _title; + newOrg.user = _user; + newOrg.location = _location; + newOrg.imgUrl = _imgUrl; + newOrg.goal = _goal; + newOrg.donated = _donated; + newOrg.description = _description; + newOrg.ownerEthAddress = _ownerEthAddress; + orgs.push(newOrg); + numOrganizations++; + } + + function addMilestonesFor(uint orgId, string[] calldata _milestones, + bool[] calldata _progress) public { + require(_milestones.length == _progress.length, + "The lengths of milestones and progress are not the same."); + require(msg.sender == orgs[orgId].ownerEthAddress, + "You do not have access to this organization"); + + Organization storage newOrg = orgs[orgId]; + for(uint i; i<_milestones.length;i++) { + newOrg.milestones.push(_milestones[i]); + newOrg.progress.push(_progress[i]); + } + } + + function addNftUnitsFor(uint orgId, NftUnit[] calldata _nfts) public { + require(msg.sender == orgs[orgId].ownerEthAddress); + require(_nfts.length > 0, "Not enough data in Nft array"); + NftUnit[] storage _orgNfts = orgNfts[orgId]; + for(uint i=0;i<_nfts.length;i++) { + _orgNfts.push(_nfts[i]); + } + } + +} From 7760b941147e3132243dde33b5ca4665464b57eb Mon Sep 17 00:00:00 2001 From: calee14 Date: Mon, 13 Jun 2022 01:15:50 -0700 Subject: [PATCH 3/5] remove milestone and figure out struct/tuple param --- src/smartcontracts/AidStorage.sol | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/smartcontracts/AidStorage.sol b/src/smartcontracts/AidStorage.sol index 1cce749..0ef25d2 100644 --- a/src/smartcontracts/AidStorage.sol +++ b/src/smartcontracts/AidStorage.sol @@ -2,6 +2,8 @@ pragma solidity >=0.7.0 <0.9.0; +// temp eth address: 0xe712d4adCEd452954eFf9846982fd043EB0Ee02C + contract AidStorage { struct NftUnit { @@ -27,7 +29,7 @@ contract AidStorage { uint public numOrganizations; // public dynamic array of all organizations Organization[] public orgs; - mapping (uint => NftUnit[]) orgNfts; + mapping (uint => NftUnit[]) public orgNfts; constructor() { @@ -51,19 +53,37 @@ contract AidStorage { function addMilestonesFor(uint orgId, string[] calldata _milestones, bool[] calldata _progress) public { + require(orgId >= 0 && orgId < numOrganizations, + "The organization you are searching for does not exist"); require(_milestones.length == _progress.length, "The lengths of milestones and progress are not the same."); require(msg.sender == orgs[orgId].ownerEthAddress, "You do not have access to this organization"); Organization storage newOrg = orgs[orgId]; - for(uint i; i<_milestones.length;i++) { + for(uint i=0; i<_milestones.length;i++) { newOrg.milestones.push(_milestones[i]); newOrg.progress.push(_progress[i]); } } + function removeMilestonesFor(uint orgId, uint[] calldata indices) public { + require(orgId >= 0 && orgId < numOrganizations, + "The organization you are searching for does not exist"); + require(msg.sender == orgs[orgId].ownerEthAddress, + "You do not have access to this organization"); + Organization storage currOrg = orgs[orgId]; + for(uint i=0;i= 0 && rmIdx < currOrg.milestones.length, + "The organization you are searching for does not exist"); + delete currOrg.milestones[rmIdx]; + } + } + function addNftUnitsFor(uint orgId, NftUnit[] calldata _nfts) public { + require(orgId >= 0 && orgId < numOrganizations, + "The organization you are searching for does not exist"); require(msg.sender == orgs[orgId].ownerEthAddress); require(_nfts.length > 0, "Not enough data in Nft array"); NftUnit[] storage _orgNfts = orgNfts[orgId]; From 50cf0b21beef6ca5f4dfef8b08bf4221159aeef2 Mon Sep 17 00:00:00 2001 From: calee14 Date: Mon, 13 Jun 2022 01:18:27 -0700 Subject: [PATCH 4/5] comment usage of addNft --- src/smartcontracts/AidStorage.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/smartcontracts/AidStorage.sol b/src/smartcontracts/AidStorage.sol index 0ef25d2..4359e54 100644 --- a/src/smartcontracts/AidStorage.sol +++ b/src/smartcontracts/AidStorage.sol @@ -81,6 +81,14 @@ contract AidStorage { } } + /* + @params: + uint orgId - id of the organization we want to access + NftUnit[] _nfts - array of Nfts that have been minted (pass to param through struct formatting + which looks like [string, string string]) + @returns: + void - updates the nft array for the mapping of org. Nfts + */ function addNftUnitsFor(uint orgId, NftUnit[] calldata _nfts) public { require(orgId >= 0 && orgId < numOrganizations, "The organization you are searching for does not exist"); From 115a999e833f0c422db7bcf855ca6aa7325760af Mon Sep 17 00:00:00 2001 From: calee14 Date: Mon, 13 Jun 2022 01:31:44 -0700 Subject: [PATCH 5/5] map to store milestones --- src/smartcontracts/AidStorage.sol | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/smartcontracts/AidStorage.sol b/src/smartcontracts/AidStorage.sol index 4359e54..43556b8 100644 --- a/src/smartcontracts/AidStorage.sol +++ b/src/smartcontracts/AidStorage.sol @@ -12,6 +12,11 @@ contract AidStorage { string price; } + struct MilestoneUnit { + string description; + bool status; + } + // struct object of an organization struct Organization { string title; // org. title @@ -30,6 +35,7 @@ contract AidStorage { // public dynamic array of all organizations Organization[] public orgs; mapping (uint => NftUnit[]) public orgNfts; + mapping (uint => MilestoneUnit[]) public orgMilestones; constructor() { @@ -51,19 +57,15 @@ contract AidStorage { numOrganizations++; } - function addMilestonesFor(uint orgId, string[] calldata _milestones, - bool[] calldata _progress) public { + function addMilestonesFor(uint orgId, MilestoneUnit[] calldata newMilestones) public { require(orgId >= 0 && orgId < numOrganizations, "The organization you are searching for does not exist"); - require(_milestones.length == _progress.length, - "The lengths of milestones and progress are not the same."); require(msg.sender == orgs[orgId].ownerEthAddress, "You do not have access to this organization"); - Organization storage newOrg = orgs[orgId]; - for(uint i=0; i<_milestones.length;i++) { - newOrg.milestones.push(_milestones[i]); - newOrg.progress.push(_progress[i]); + MilestoneUnit[] storage currMilestones = orgMilestones[orgId]; + for(uint i=0; i= 0 && rmIdx < currOrg.milestones.length, + require(rmIdx >= 0 && rmIdx < currMilestones.length, "The organization you are searching for does not exist"); - delete currOrg.milestones[rmIdx]; + delete currMilestones[rmIdx]; } } - /* + /* addNftUnitsFor @params: uint orgId - id of the organization we want to access NftUnit[] _nfts - array of Nfts that have been minted (pass to param through struct formatting