master
lza_menace 2 years ago
parent a3090e57a5
commit 7e5c8ae24a

@ -1,5 +1,3 @@
# sendit
# ShipIt
ERC-721 and ERc-1155 token bulk sender contract.
Using this as an opportunity to learn Foundry for smart contract development and management.
ERC-721 and ERC-1155 token bulk sender contract.

@ -2,6 +2,11 @@
source .env
ERC721=0x5FbDB2315678afecb367f032d93F642f64180aa3
ERC1155=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
SHIPIT=0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
OP=0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395
echo -e "[+] Deploying ERC-721"
forge create --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY src/sampleERC721.sol:NFT721 | grep Deployed
@ -12,14 +17,14 @@ echo -e "[+] Deploying SendIt"
forge create --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY src/SendIt.sol:SendIt | grep Deployed
echo -e "[+] Sending test Ether"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY 0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395 --value 0.5ether > /dev/null
echo -e "[+] Minting 500 ERC-721 tokens to deployer"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY 0x5FbDB2315678afecb367f032d93F642f64180aa3 "mint(uint256)" 500 > /dev/null
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY $OP --value 0.5ether > /dev/null
echo -e "[+] Minting 500 ERC-1155 tokens to deployer"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 "mint(uint256,uint256)" 1 500 > /dev/null
echo -e "[+] Minting 800 ERC-721 tokens to deployer (id 1-800)"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY $ERC721 "mint(uint256)" 800 > /dev/null
echo -e "[+] Setting approval for contract"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY 0x5FbDB2315678afecb367f032d93F642f64180aa3 "setApprovalForAll(address,bool)" 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 true > /dev/null
echo -e "[+] Minting 800 ERC-1155 tokens to deployer (id 1)"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY $ERC1155 "mint(uint256,uint256)" 1 800 > /dev/null
echo -e "[+] Setting approval for contracts"
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY $ERC721 "setApprovalForAll(address,bool)" $SHIPIT true > /dev/null
cast send --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY $ERC1155 "setApprovalForAll(address,bool)" $SHIPIT true > /dev/null

@ -2,7 +2,7 @@
src = 'src'
out = 'out'
libs = ['lib']
gas_reports = ["SendIt"]
gas_reports = ["ShipIt"]
[rpc_endpoints]
goerli = "${GOERLI_RPC_URL}"

@ -5,7 +5,7 @@ import {ERC721} from "openzeppelin-contracts/token/ERC721/ERC721.sol";
import {ERC1155} from "openzeppelin-contracts/token/ERC1155/ERC1155.sol";
import {Ownable} from "openzeppelin-contracts/access/Ownable.sol";
contract SendIt is Ownable {
contract ShipIt is Ownable {
mapping(address => address) public addressVault; // users can store their personal vaults for ease of use
uint256 public usageFee = .00015 ether; // charge a small fee for the cost savings it provides

@ -2,18 +2,18 @@
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import {SendIt} from "../src/SendIt.sol";
import {ShipIt} from "../src/ShipIt.sol";
import {NFT721} from "../src/sampleERC721.sol";
import {NFT1155} from "../src/sampleERC1155.sol";
contract SendItTest is Test {
contract ShipItTest is Test {
using stdStorage for StdStorage;
SendIt public sendit;
ShipIt public shipit;
NFT721 public nft721;
NFT1155 public nft1155;
function setUp() public {
sendit = new SendIt();
shipit = new ShipIt();
nft721 = new NFT721();
nft1155 = new NFT1155();
}
@ -22,7 +22,7 @@ contract SendItTest is Test {
function test721BulkTransferSuccess() public {
uint256 amt = 20;
uint256 fee = sendit.usageFee();
uint256 fee = shipit.usageFee();
uint256 val = fee * amt;
uint256[] memory tokenIndexes = new uint256[](amt);
address[] memory recipients = new address[](amt);
@ -33,8 +33,8 @@ contract SendItTest is Test {
vm.deal(address(5), 1 ether);
vm.startPrank(address(5));
nft721.mint(amt);
nft721.setApprovalForAll(address(sendit), true);
sendit.contractBulkTransfer{value: val}(
nft721.setApprovalForAll(address(shipit), true);
shipit.contractBulkTransfer{value: val}(
address(nft721),
tokenIndexes,
recipients,
@ -45,7 +45,7 @@ contract SendItTest is Test {
function testFail721NonTokenOwnerCanSend() public {
uint256 amt = 1;
uint256 fee = sendit.usageFee();
uint256 fee = shipit.usageFee();
uint256 val = fee * amt;
uint256[] memory tokenIndexes = new uint256[](amt);
address[] memory recipients = new address[](amt);
@ -55,10 +55,10 @@ contract SendItTest is Test {
vm.deal(address(3), 1 ether);
vm.startPrank(address(5));
nft721.mint(amt);
nft721.setApprovalForAll(address(sendit), true);
nft721.setApprovalForAll(address(shipit), true);
vm.stopPrank();
vm.prank(address(3));
sendit.contractBulkTransfer{value: val}(
shipit.contractBulkTransfer{value: val}(
address(nft721),
tokenIndexes,
recipients,
@ -68,7 +68,7 @@ contract SendItTest is Test {
function test1155BulkTransferSuccess() public {
uint256 amt = 10;
uint256 fee = sendit.usageFee();
uint256 fee = shipit.usageFee();
uint256 val = fee * amt;
uint256[] memory tokenIndexes = new uint256[](amt);
address[] memory recipients = new address[](amt);
@ -79,8 +79,8 @@ contract SendItTest is Test {
vm.deal(address(5), 1 ether);
vm.startPrank(address(5));
nft1155.mint(1, amt);
nft1155.setApprovalForAll(address(sendit), true);
sendit.contractBulkTransfer{value: val}(
nft1155.setApprovalForAll(address(shipit), true);
shipit.contractBulkTransfer{value: val}(
address(nft1155),
tokenIndexes,
recipients,
@ -91,7 +91,7 @@ contract SendItTest is Test {
function testFail1155NonTokenOwnerCanSend() public {
uint256 amt = 1;
uint256 fee = sendit.usageFee();
uint256 fee = shipit.usageFee();
uint256 val = fee * amt;
uint256[] memory tokenIndexes = new uint256[](amt);
address[] memory recipients = new address[](amt);
@ -101,10 +101,10 @@ contract SendItTest is Test {
vm.deal(address(3), 1 ether);
vm.startPrank(address(5));
nft1155.mint(1, amt);
nft1155.setApprovalForAll(address(sendit), true);
nft1155.setApprovalForAll(address(shipit), true);
vm.stopPrank();
vm.prank(address(3));
sendit.contractBulkTransfer{value: val}(
shipit.contractBulkTransfer{value: val}(
address(nft1155),
tokenIndexes,
recipients,
@ -116,35 +116,35 @@ contract SendItTest is Test {
function testUpdateVault() public {
vm.prank(address(1));
sendit.updateVault(address(3));
assertEq(sendit.addressVault(address(1)), address(3));
shipit.updateVault(address(3));
assertEq(shipit.addressVault(address(1)), address(3));
}
// admin
function testOwnerCanWithdraw() public {
address owner = sendit.owner();
vm.deal(address(sendit), 1 ether);
address owner = shipit.owner();
vm.deal(address(shipit), 1 ether);
vm.deal(owner, 1 ether);
vm.deal(address(20), 2 ether);
vm.prank(owner);
sendit.transferOwnership(address(20));
shipit.transferOwnership(address(20));
vm.prank(address(20));
sendit.withdraw();
shipit.withdraw();
vm.startPrank(address(30));
vm.expectRevert();
sendit.withdraw();
shipit.withdraw();
}
function testOwnerCanUpdateFee() public {
address owner = sendit.owner();
address owner = shipit.owner();
vm.deal(owner, 1 ether);
vm.prank(owner);
sendit.updateFee(0.1 ether);
assertEq(sendit.usageFee(), 0.1 ether);
shipit.updateFee(0.1 ether);
assertEq(shipit.usageFee(), 0.1 ether);
vm.startPrank(address(1));
vm.expectRevert();
sendit.updateFee(0.25 ether);
shipit.updateFee(0.25 ether);
}
}
Loading…
Cancel
Save