Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions src/smartcontracts/AidStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;

// temp eth address: 0xe712d4adCEd452954eFf9846982fd043EB0Ee02C

contract AidStorage {

struct NftUnit {
string imgUrl;
string raribleUrl;
string price;
}

struct MilestoneUnit {
string description;
bool status;
}

// 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[]) public orgNfts;
mapping (uint => MilestoneUnit[]) public orgMilestones;

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, MilestoneUnit[] calldata newMilestones) 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");

MilestoneUnit[] storage currMilestones = orgMilestones[orgId];
for(uint i=0; i<newMilestones.length;i++) {
currMilestones.push(newMilestones[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");
MilestoneUnit[] storage currMilestones = orgMilestones[orgId];
for(uint i=0;i<indices.length;i++) {
uint rmIdx = indices[i];
require(rmIdx >= 0 && rmIdx < currMilestones.length,
"The organization you are searching for does not exist");
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
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");
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]);
}
}

}
16 changes: 8 additions & 8 deletions src/smartcontracts/TokenSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down