From 5cfd8be1ae5b34d67d60d8500def5d394f4ec40b Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Mon, 6 Jul 2020 16:03:22 -0500 Subject: [PATCH] Add _ethpm_packages dir to each example --- README.md | 5 ++ .../_ethpm_packages/escrow/_src/Escrow.sol | 32 +++++++ .../escrow/_src/SafeSendLib.sol | 20 +++++ .../_ethpm_packages/escrow/manifest.json | 1 + examples/escrow/_ethpm_packages/ethpm.lock | 11 +++ examples/owned/_ethpm_packages/ethpm.lock | 11 +++ .../_ethpm_packages/owned/_src/Owned.sol | 12 +++ .../owned/_ethpm_packages/owned/manifest.json | 1 + .../piper-coin/_ethpm_packages/ethpm.lock | 11 +++ .../piper-coin/_ethpm_packages/ethpm.lock | 11 +++ .../standard-token/_src/AbstractToken.sol | 20 +++++ .../standard-token/_src/StandardToken.sol | 84 +++++++++++++++++++ .../standard-token/manifest.json | 1 + .../_ethpm_packages/piper-coin/manifest.json | 1 + .../safe-math-lib/_ethpm_packages/ethpm.lock | 11 +++ .../safe-math-lib/_src/SafeMathLib.sol | 24 ++++++ .../safe-math-lib/manifest.json | 1 + .../standard-token/_ethpm_packages/ethpm.lock | 11 +++ .../standard-token/_src/AbstractToken.sol | 20 +++++ .../standard-token/_src/StandardToken.sol | 84 +++++++++++++++++++ .../standard-token/manifest.json | 1 + .../transferable/_ethpm_packages/ethpm.lock | 11 +++ .../transferable/_ethpm_packages/ethpm.lock | 11 +++ .../_ethpm_packages/owned/_src/Owned.sol | 12 +++ .../_ethpm_packages/owned/manifest.json | 1 + .../transferable/_src/Transferable.sol | 14 ++++ .../transferable/manifest.json | 1 + .../_ethpm_packages/ethpm.lock | 11 +++ .../_ethpm_packages/ethpm.lock | 11 +++ .../wallet/_ethpm_packages/ethpm.lock | 20 +++++ .../_ethpm_packages/owned/_src/Owned.sol | 12 +++ .../_ethpm_packages/owned/manifest.json | 1 + .../safe-math-lib/_src/SafeMathLib.sol | 24 ++++++ .../safe-math-lib/manifest.json | 1 + .../_ethpm_packages/wallet/_src/Wallet.sol | 41 +++++++++ .../_ethpm_packages/wallet/manifest.json | 1 + .../wallet-with-send/_src/WalletWithSend.sol | 18 ++++ .../wallet-with-send/manifest.json | 1 + examples/wallet/_ethpm_packages/ethpm.lock | 11 +++ .../wallet/_ethpm_packages/ethpm.lock | 20 +++++ .../_ethpm_packages/owned/_src/Owned.sol | 12 +++ .../_ethpm_packages/owned/manifest.json | 1 + .../safe-math-lib/_src/SafeMathLib.sol | 24 ++++++ .../safe-math-lib/manifest.json | 1 + .../_ethpm_packages/wallet/_src/Wallet.sol | 41 +++++++++ .../_ethpm_packages/wallet/manifest.json | 1 + 46 files changed, 675 insertions(+) create mode 100644 examples/escrow/_ethpm_packages/escrow/_src/Escrow.sol create mode 100644 examples/escrow/_ethpm_packages/escrow/_src/SafeSendLib.sol create mode 100644 examples/escrow/_ethpm_packages/escrow/manifest.json create mode 100644 examples/escrow/_ethpm_packages/ethpm.lock create mode 100644 examples/owned/_ethpm_packages/ethpm.lock create mode 100644 examples/owned/_ethpm_packages/owned/_src/Owned.sol create mode 100644 examples/owned/_ethpm_packages/owned/manifest.json create mode 100644 examples/piper-coin/_ethpm_packages/ethpm.lock create mode 100644 examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/ethpm.lock create mode 100644 examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/AbstractToken.sol create mode 100644 examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/StandardToken.sol create mode 100644 examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/manifest.json create mode 100644 examples/piper-coin/_ethpm_packages/piper-coin/manifest.json create mode 100644 examples/safe-math-lib/_ethpm_packages/ethpm.lock create mode 100644 examples/safe-math-lib/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol create mode 100644 examples/safe-math-lib/_ethpm_packages/safe-math-lib/manifest.json create mode 100644 examples/standard-token/_ethpm_packages/ethpm.lock create mode 100644 examples/standard-token/_ethpm_packages/standard-token/_src/AbstractToken.sol create mode 100644 examples/standard-token/_ethpm_packages/standard-token/_src/StandardToken.sol create mode 100644 examples/standard-token/_ethpm_packages/standard-token/manifest.json create mode 100644 examples/transferable/_ethpm_packages/ethpm.lock create mode 100644 examples/transferable/_ethpm_packages/transferable/_ethpm_packages/ethpm.lock create mode 100644 examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/_src/Owned.sol create mode 100644 examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/manifest.json create mode 100644 examples/transferable/_ethpm_packages/transferable/_src/Transferable.sol create mode 100644 examples/transferable/_ethpm_packages/transferable/manifest.json create mode 100644 examples/wallet-with-send/_ethpm_packages/ethpm.lock create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/ethpm.lock create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_src/Wallet.sol create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/manifest.json create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/_src/WalletWithSend.sol create mode 100644 examples/wallet-with-send/_ethpm_packages/wallet-with-send/manifest.json create mode 100644 examples/wallet/_ethpm_packages/ethpm.lock create mode 100644 examples/wallet/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock create mode 100644 examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol create mode 100644 examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json create mode 100644 examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol create mode 100644 examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json create mode 100644 examples/wallet/_ethpm_packages/wallet/_src/Wallet.sol create mode 100644 examples/wallet/_ethpm_packages/wallet/manifest.json diff --git a/README.md b/README.md index ea92189..07ff763 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,8 @@ Each invalid test fixture contains an ``errorInfo`` field. ``N0007`` - Invalid ``"compilers"`` field. ``N0008`` - Invalid ``"buildDependencies"`` field. ``N0009`` - Invalid ``"meta"`` field. + + +### Package installation fixtures + +Within each ``examples`` directory is an ``_ethpm_packages`` directory. This directory follows the EthPM [write-to-disk](https://ethpm-cli.readthedocs.io/en/latest/disk.html#ethpm-packages) formatting rules for how it's respective V3 manifest (``v3.json``) should be installed by a framework. diff --git a/examples/escrow/_ethpm_packages/escrow/_src/Escrow.sol b/examples/escrow/_ethpm_packages/escrow/_src/Escrow.sol new file mode 100644 index 0000000..a5a0c25 --- /dev/null +++ b/examples/escrow/_ethpm_packages/escrow/_src/Escrow.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +import {SafeSendLib} from "./SafeSendLib.sol"; + + +/// @title Contract for holding funds in escrow between two semi trusted parties. +/// @author Piper Merriam +contract Escrow { + using SafeSendLib for address; + + address public sender; + address public recipient; + + constructor(address _recipient) public { + sender = msg.sender; + recipient = _recipient; + } + + /// @dev Releases the escrowed funds to the other party. + /// @notice This will release the escrowed funds to the other party. + function releaseFunds() public { + if (msg.sender == sender) { + recipient.sendOrThrow(address(this).balance); + } else if (msg.sender == recipient) { + sender.sendOrThrow(address(this).balance); + } else { + revert(); + } + } +} diff --git a/examples/escrow/_ethpm_packages/escrow/_src/SafeSendLib.sol b/examples/escrow/_ethpm_packages/escrow/_src/SafeSendLib.sol new file mode 100644 index 0000000..0e5a23d --- /dev/null +++ b/examples/escrow/_ethpm_packages/escrow/_src/SafeSendLib.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +/// @title Library for safe sending of ether. +/// @author Piper Merriam +library SafeSendLib { + /// @dev Attempts to send the specified amount to the recipient throwing an error if it fails + /// @param recipient The address that the funds should be to. + /// @param value The amount in wei that should be sent. + function sendOrThrow(address recipient, uint value) public returns (bool) { + if (value > address(this).balance) + revert(); + + if (!payable(recipient).send(value)) + revert(); + + return true; + } +} diff --git a/examples/escrow/_ethpm_packages/escrow/manifest.json b/examples/escrow/_ethpm_packages/escrow/manifest.json new file mode 100644 index 0000000..458ef2c --- /dev/null +++ b/examples/escrow/_ethpm_packages/escrow/manifest.json @@ -0,0 +1 @@ +{"compilers":[{"contractTypes":["Escrow","SafeSendLib"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"Escrow":{"abi":[{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"recipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"releaseFunds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}],"deploymentBytecode":{"bytecode":"0x608060405234801561001057600080fd5b506040516104e83803806104e88339818101604052602081101561003357600080fd5b8101908080519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610413806100d56000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806366d003ac1461004657806367e404ce1461009057806369d89575146100da575b600080fd5b61004e6100e4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61009861010a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e261012f565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561028257600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561024157600080fd5b505af4158015610255573d6000803e3d6000fd5b505050506040513d602081101561026b57600080fd5b8101908080519060200190929190505050506103db565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156103d5576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561039457600080fd5b505af41580156103a8573d6000803e3d6000fd5b505050506040513d60208110156103be57600080fd5b8101908080519060200190929190505050506103da565b600080fd5b5b56fea2646970667358221220c0256c8fdbb9d70e72b54b5dcae800eb0d0723c366103209d2e40e60b6f352e564736f6c63430006080033","linkReferences":[{"length":20,"name":"SafeSendLib","offsets":[660,999]}]},"devdoc":{"author":"Piper Merriam ","methods":{"releaseFunds()":{"details":"Releases the escrowed funds to the other party."}},"title":"Contract for holding funds in escrow between two semi trusted parties."},"runtimeBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50600436106100415760003560e01c806366d003ac1461004657806367e404ce1461009057806369d89575146100da575b600080fd5b61004e6100e4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61009861010a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100e261012f565b005b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561028257600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561024157600080fd5b505af4158015610255573d6000803e3d6000fd5b505050506040513d602081101561026b57600080fd5b8101908080519060200190929190505050506103db565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156103d5576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16730000000000000000000000000000000000000000639341231c9091476040518363ffffffff1660e01b8152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060206040518083038186803b15801561039457600080fd5b505af41580156103a8573d6000803e3d6000fd5b505050506040513d60208110156103be57600080fd5b8101908080519060200190929190505050506103da565b600080fd5b5b56fea2646970667358221220c0256c8fdbb9d70e72b54b5dcae800eb0d0723c366103209d2e40e60b6f352e564736f6c63430006080033","linkReferences":[{"length":20,"name":"SafeSendLib","offsets":[447,786]}]},"sourceId":"Escrow.sol"},"SafeSendLib":{"abi":[],"deploymentBytecode":{"bytecode":"0x610132610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361060335760003560e01c80639341231c146038575b600080fd5b818015604357600080fd5b50608d60048036036040811015605857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505060a7565b604051808215151515815260200191505060405180910390f35b60004782111560b557600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505060f257600080fd5b600190509291505056fea26469706673582212203471502f8b953b5622ae380d01fe3a6c574e1b7ae3ba80ebae95d88771f6714564736f6c63430006080033"},"devdoc":{"author":"Piper Merriam ","methods":{"sendOrThrow(address,uint256)":{"details":"Attempts to send the specified amount to the recipient throwing an error if it fails","params":{"recipient":"The address that the funds should be to.","value":"The amount in wei that should be sent."}}},"title":"Library for safe sending of ether."},"runtimeBytecode":{"bytecode":"0x730000000000000000000000000000000000000000301460806040526004361060335760003560e01c80639341231c146038575b600080fd5b818015604357600080fd5b50608d60048036036040811015605857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505060a7565b604051808215151515815260200191505060405180910390f35b60004782111560b557600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505060f257600080fd5b600190509291505056fea26469706673582212203471502f8b953b5622ae380d01fe3a6c574e1b7ae3ba80ebae95d88771f6714564736f6c63430006080033"},"sourceId":"SafeSendLib.sol"}},"deployments":{"blockchain://d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3/block/752820c0ad7abc1200f9ad42c4adc6fbb4bd44b5bed4667990e64565102c1ba6":{"Escrow":{"address":"0x41B8E7F94F92aE75266054f7029b2f5C30D19171","block":"0xe29b6d17dc4da99bbd985dd62c69cf70f3437c2c104eee24fa7a41d73e4a6524","contractType":"Escrow","runtimeBytecode":{"linkDependencies":[{"offsets":[447,786],"type":"reference","value":"SafeSendLib"}]},"transaction":"0x6f1bdf9e303c866dc74452cb418e05737c9b8c3a5ddfcd1c09509d5ec1fc23e9"},"SafeSendLib":{"address":"0x379EdD01a8c6E56649C092D2699eA877CC89414B","block":"0xb05e03a8ba4b744d5754f93fcb9c48e836fa624d9c2942c7081661a0e9e3134b","contractType":"SafeSendLib","transaction":"0x32a498696bd9924f34ac01f755c126d5628947f9935188098dc8eb6f7a30c418"}}},"manifest":"ethpm/3","name":"escrow","sources":{"./Escrow.sol":{"installPath":"./Escrow.sol","type":"solidity","urls":["ipfs://QmNLpdCi4UakwJ9rBoL7rDnEzNeA6f8uvKbiMhZVqTucu1"]},"./SafeSendLib.sol":{"installPath":"./SafeSendLib.sol","type":"solidity","urls":["ipfs://QmbEnqvCSAAYwQ474S1vCSBdMgdiRZ4gZWEmSmdXepXQJq"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/escrow/_ethpm_packages/ethpm.lock b/examples/escrow/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..bcc1b78 --- /dev/null +++ b/examples/escrow/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "escrow": { + "alias": "escrow", + "install_uri": "ipfs://QmNpLojZo471M357NTUZ1qKDwjUZrfYctWhzPtNFEXcSaL", + "registry_address": null, + "resolved_content_hash": "QmNpLojZo471M357NTUZ1qKDwjUZrfYctWhzPtNFEXcSaL", + "resolved_package_name": "escrow", + "resolved_uri": "ipfs://QmNpLojZo471M357NTUZ1qKDwjUZrfYctWhzPtNFEXcSaL", + "resolved_version": "1.0.0" + } +} diff --git a/examples/owned/_ethpm_packages/ethpm.lock b/examples/owned/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..417d608 --- /dev/null +++ b/examples/owned/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "owned": { + "alias": "owned", + "install_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "registry_address": null, + "resolved_content_hash": "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_package_name": "owned", + "resolved_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_version": "1.0.0" + } +} diff --git a/examples/owned/_ethpm_packages/owned/_src/Owned.sol b/examples/owned/_ethpm_packages/owned/_src/Owned.sol new file mode 100644 index 0000000..b85703b --- /dev/null +++ b/examples/owned/_ethpm_packages/owned/_src/Owned.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + +contract Owned { + address owner; + + modifier onlyOwner { require(msg.sender == owner); _; } + + constructor() public { + owner = msg.sender; + } +} \ No newline at end of file diff --git a/examples/owned/_ethpm_packages/owned/manifest.json b/examples/owned/_ethpm_packages/owned/manifest.json new file mode 100644 index 0000000..ef18e8b --- /dev/null +++ b/examples/owned/_ethpm_packages/owned/manifest.json @@ -0,0 +1 @@ +{"manifest":"ethpm/3","meta":{"authors":["Piper Merriam "],"description":"Reusable contracts which implement a privileged 'owner' model for authorization.","keywords":["authorization"],"license":"MIT","links":{"documentation":"ipfs://QmUYcVzTfSwJoigggMxeo2g5STWAgJdisQsqcXHws7b1FW"}},"name":"owned","sources":{"Owned.sol":{"installPath":"./Owned.sol","type":"solidity","urls":["ipfs://QmU8QUSt56ZoBDJgjjXvAZEPro9LmK1m2gjVG5Q4s9x29W"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/piper-coin/_ethpm_packages/ethpm.lock b/examples/piper-coin/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..40b6975 --- /dev/null +++ b/examples/piper-coin/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "piper-coin": { + "alias": "piper-coin", + "install_uri": "ipfs://QmNbvXM5ig6Qtz6abRuG52KgjFqfXDyBCdRTz7QDENgxzv", + "registry_address": null, + "resolved_content_hash": "QmNbvXM5ig6Qtz6abRuG52KgjFqfXDyBCdRTz7QDENgxzv", + "resolved_package_name": "piper-coin", + "resolved_uri": "ipfs://QmNbvXM5ig6Qtz6abRuG52KgjFqfXDyBCdRTz7QDENgxzv", + "resolved_version": "1.0.0" + } +} diff --git a/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/ethpm.lock b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..4a77ee6 --- /dev/null +++ b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "standard-token": { + "alias": "standard-token", + "install_uri": "ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", + "registry_address": null, + "resolved_content_hash": "QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", + "resolved_package_name": "standard-token", + "resolved_uri": "ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", + "resolved_version": "1.0.0" + } +} diff --git a/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/AbstractToken.sol b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/AbstractToken.sol new file mode 100644 index 0000000..5ec5afe --- /dev/null +++ b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/AbstractToken.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +/// Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 + +/// @title Abstract token contract - Functions to be implemented by token contracts. +/// @author Stefan George - +abstract contract Token { + // This is not an abstract function, because solc won't recognize generated getter functions for public variables as functions + function totalSupply() external view virtual returns (uint256 supply) {} + function balanceOf(address owner) public view virtual returns (uint256 balance); + function transfer(address to, uint256 value) public virtual returns (bool success); + function transferFrom(address from, address to, uint256 value) public virtual returns (bool success); + function approve(address spender, uint256 value) public virtual returns (bool success); + function allowance(address owner, address spender) public view virtual returns (uint256 remaining); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); +} \ No newline at end of file diff --git a/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/StandardToken.sol b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/StandardToken.sol new file mode 100644 index 0000000..79acc8e --- /dev/null +++ b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/_src/StandardToken.sol @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +import "./AbstractToken.sol"; + + +/// @title Standard token contract +/// @author Stefan George - +contract StandardToken is Token { + /* + * Data structures + */ + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; + uint256 override public totalSupply; + + constructor (uint _totalSupply) public { + totalSupply = _totalSupply; + balances[msg.sender] = _totalSupply; + emit Transfer(address(0), msg.sender, _totalSupply); + } + + /* + * Read and write storage functions + */ + /// @dev Transfers sender's tokens to a given address. Returns success. + /// @param _to Address of token receiver. + /// @param _value Number of tokens to transfer. + function transfer(address _to, uint256 _value) public override returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0) { + balances[msg.sender] -= _value; + balances[_to] += _value; + emit Transfer(msg.sender, _to, _value); + return true; + } + else { + return false; + } + } + + /// @dev Allows allowed third party to transfer tokens from one address to another. Returns success. + /// @param _from Address from where tokens are withdrawn. + /// @param _to Address to where tokens are sent. + /// @param _value Number of tokens to transfer. + function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] += _value; + balances[_from] -= _value; + allowed[_from][msg.sender] -= _value; + emit Transfer(_from, _to, _value); + return true; + } + else { + return false; + } + } + + /// @dev Returns number of tokens owned by given address. + /// @param _owner Address of token owner. + function balanceOf(address _owner) public override view returns (uint256 balance) { + return balances[_owner]; + } + + /// @dev Sets approved amount of tokens for spender. Returns success. + /// @param _spender Address of allowed account. + /// @param _value Number of approved tokens. + function approve(address _spender, uint256 _value) public override returns (bool success) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + /* + * Read storage functions + */ + /// @dev Returns number of allowed tokens for given address. + /// @param _owner Address of token owner. + /// @param _spender Address of token spender. + function allowance(address _owner, address _spender) public override view returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} \ No newline at end of file diff --git a/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/manifest.json b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/manifest.json new file mode 100644 index 0000000..4a75962 --- /dev/null +++ b/examples/piper-coin/_ethpm_packages/piper-coin/_ethpm_packages/standard-token/manifest.json @@ -0,0 +1 @@ +{"contractTypes":{"StandardToken":{"abi":[{"inputs":[{"internalType":"uint256","name":"_totalSupply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"author":"Stefan George - ","methods":{"allowance(address,address)":{"details":"Returns number of allowed tokens for given address.","params":{"_owner":"Address of token owner.","_spender":"Address of token spender."}},"approve(address,uint256)":{"details":"Sets approved amount of tokens for spender. Returns success.","params":{"_spender":"Address of allowed account.","_value":"Number of approved tokens."}},"balanceOf(address)":{"details":"Returns number of tokens owned by given address.","params":{"_owner":"Address of token owner."}},"transfer(address,uint256)":{"details":"Transfers sender's tokens to a given address. Returns success.","params":{"_to":"Address of token receiver.","_value":"Number of tokens to transfer."}},"transferFrom(address,address,uint256)":{"details":"Allows allowed third party to transfer tokens from one address to another. Returns success.","params":{"_from":"Address from where tokens are withdrawn.","_to":"Address to where tokens are sent.","_value":"Number of tokens to transfer."}}},"title":"Standard token contract"},"sourceId":"StandardToken.sol"},"Token":{"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"supply","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"author":"Stefan George - ","methods":{},"title":"Abstract token contract - Functions to be implemented by token contracts."},"sourceId":"AbstractToken.sol","userdoc":{"methods":{},"notice":"Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20"}}},"manifest":"ethpm/3","name":"standard-token","sources":{"./AbstractToken.sol":{"installPath":"./AbstractToken.sol","type":"solidity","urls":["ipfs://QmSBYuGKSH2veDepMbFQu3XVStYRCvuqFjUV7YCPufeHJz"]},"./StandardToken.sol":{"installPath":"./StandardToken.sol","type":"solidity","urls":["ipfs://QmUofKBtNJVaqoSAtnHfrarJyyLm1oMUTAK4yCtnmYMJVy"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/piper-coin/_ethpm_packages/piper-coin/manifest.json b/examples/piper-coin/_ethpm_packages/piper-coin/manifest.json new file mode 100644 index 0000000..2a91f72 --- /dev/null +++ b/examples/piper-coin/_ethpm_packages/piper-coin/manifest.json @@ -0,0 +1 @@ +{"buildDependencies":{"standard-token":"ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA"},"deployments":{"blockchain://41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d/block/8edfc8c04a400d0269bb4f89b6620c28321bf3ef205452cc0a3dd9a3d4d90640":{"PiperCoin":{"address":"0x77C7C1e9F6cC426179F9bb95f3f9F6d8D37315a5","block":"0x8a78fa5f540ad205c2259dbf134c09a18e83fb50721b1c6a74be6421663c239e","contractType":"standard-token:StandardToken","runtimeBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50600436106100625760003560e01c8063095ea7b31461006757806318160ddd146100cd57806323b872dd146100eb57806370a0823114610171578063a9059cbb146101c9578063dd62ed3e1461022f575b600080fd5b6100b36004803603604081101561007d57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506102a7565b604051808215151515815260200191505060405180910390f35b6100d5610399565b6040518082815260200191505060405180910390f35b6101576004803603606081101561010157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061039f565b604051808215151515815260200191505060405180910390f35b6101b36004803603602081101561018757600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610618565b6040518082815260200191505060405180910390f35b610215600480360360408110156101df57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610660565b604051808215151515815260200191505060405180910390f35b6102916004803603604081101561024557600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506107c6565b6040518082815260200191505060405180910390f35b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60025481565b6000816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015801561046b575081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205410155b80156104775750600082115b1561060c57816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540192505081905550816000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825403925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a360019050610611565b600090505b9392505050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054101580156106b05750600082115b156107bb57816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190506107c0565b600090505b92915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490509291505056fea26469706673582212205b1030a46711be4af481d287498c2f627fc76b95f9dac96fd56a41db27633a3d64736f6c634300060a0033"},"transaction":"0x76221eca6879628d1d4549f44b6fc0aa923743ce4f0ddcc7721dbf9151e554d7"}}},"manifest":"ethpm/3","name":"piper-coin","version":"1.0.0"} \ No newline at end of file diff --git a/examples/safe-math-lib/_ethpm_packages/ethpm.lock b/examples/safe-math-lib/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..3d6f4b5 --- /dev/null +++ b/examples/safe-math-lib/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "safe-math-lib": { + "alias": "safe-math-lib", + "install_uri": "ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "registry_address": null, + "resolved_content_hash": "QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "resolved_package_name": "safe-math-lib", + "resolved_uri": "ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "resolved_version": "1.0.0" + } +} diff --git a/examples/safe-math-lib/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol b/examples/safe-math-lib/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol new file mode 100644 index 0000000..f0c7c75 --- /dev/null +++ b/examples/safe-math-lib/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +/// @title Safe Math Library +/// @author Piper Merriam +library SafeMathLib { + /// @dev Adds a and b, throwing an error if the operation would cause an overflow. + /// @param a The first number to add + /// @param b The second number to add + function safeAdd(uint256 a, uint256 b) public pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } + + /// @dev Subtracts b from a, throwing an error if the operation would cause an underflow. + /// @param a The number to be subtracted from + /// @param b The amount that should be subtracted + function safeSub(uint256 a, uint256 b) public pure returns (uint256) { + assert(b <= a); + return a - b; + } +} \ No newline at end of file diff --git a/examples/safe-math-lib/_ethpm_packages/safe-math-lib/manifest.json b/examples/safe-math-lib/_ethpm_packages/safe-math-lib/manifest.json new file mode 100644 index 0000000..3e7640e --- /dev/null +++ b/examples/safe-math-lib/_ethpm_packages/safe-math-lib/manifest.json @@ -0,0 +1 @@ +{"compilers":[{"contractTypes":["SafeMathLib"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"SafeMathLib":{"abi":[{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"safeAdd","outputs":[{"internalType":"uint256","name":"c","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"safeSub","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}],"deploymentBytecode":{"bytecode":"0x610144610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063a293d1e814610045578063e6cb901314610091575b600080fd5b61007b6004803603604081101561005b57600080fd5b8101908080359060200190929190803590602001909291905050506100dd565b6040518082815260200191505060405180910390f35b6100c7600480360360408110156100a757600080fd5b8101908080359060200190929190803590602001909291905050506100f4565b6040518082815260200191505060405180910390f35b6000828211156100e957fe5b818303905092915050565b600081830190508281101561010557fe5b8090509291505056fea26469706673582212201732500f2fac649ab2ce116d2145af69b3e8c6ef2d172ec377db7ed0b7a4801964736f6c63430006080033"},"devdoc":{"author":"Piper Merriam ","methods":{"safeAdd(uint256,uint256)":{"details":"Adds a and b, throwing an error if the operation would cause an overflow.","params":{"a":"The first number to add","b":"The second number to add"}},"safeSub(uint256,uint256)":{"details":"Subtracts b from a, throwing an error if the operation would cause an underflow.","params":{"a":"The number to be subtracted from","b":"The amount that should be subtracted"}}},"title":"Safe Math Library"},"runtimeBytecode":{"bytecode":"0x73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063a293d1e814610045578063e6cb901314610091575b600080fd5b61007b6004803603604081101561005b57600080fd5b8101908080359060200190929190803590602001909291905050506100dd565b6040518082815260200191505060405180910390f35b6100c7600480360360408110156100a757600080fd5b8101908080359060200190929190803590602001909291905050506100f4565b6040518082815260200191505060405180910390f35b6000828211156100e957fe5b818303905092915050565b600081830190508281101561010557fe5b8090509291505056fea26469706673582212201732500f2fac649ab2ce116d2145af69b3e8c6ef2d172ec377db7ed0b7a4801964736f6c63430006080033"},"sourceId":"SafeMathLib.sol"}},"deployments":{"blockchain://d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3/block/c4b7297b918ce3a93186eccff5195e77ef0c47b4e8cb8b66439aa25271f5170c":{"SafeMathLib":{"address":"0x6B2534269C5Ee98C37729d07Dc92C4b97EBB6235","block":"0x64fa9306a5c7aa3b8a71c29cd09fb897c3fb7325a3dbc75c4627dd8f08b759a6","contractType":"SafeMathLib","transaction":"0xb0ac2dbb86a29d70c8f3996834672e3af8cae7fc37718e49ac3adfd99eb23d31"}}},"manifest":"ethpm/3","name":"safe-math-lib","sources":{"./SafeMathLib.sol":{"installPath":"./SafeMathLib.sol","type":"solidity","urls":["ipfs://QmeyYahfHxPSoytQ2rPH2JUURin24sPvaMo6o6tKghwkAg"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/standard-token/_ethpm_packages/ethpm.lock b/examples/standard-token/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..4a77ee6 --- /dev/null +++ b/examples/standard-token/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "standard-token": { + "alias": "standard-token", + "install_uri": "ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", + "registry_address": null, + "resolved_content_hash": "QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", + "resolved_package_name": "standard-token", + "resolved_uri": "ipfs://QmQNffBrmbB3TuBCtYfYsJWJVLssatWXa3H6CkGeyNUySA", + "resolved_version": "1.0.0" + } +} diff --git a/examples/standard-token/_ethpm_packages/standard-token/_src/AbstractToken.sol b/examples/standard-token/_ethpm_packages/standard-token/_src/AbstractToken.sol new file mode 100644 index 0000000..5ec5afe --- /dev/null +++ b/examples/standard-token/_ethpm_packages/standard-token/_src/AbstractToken.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +/// Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20 + +/// @title Abstract token contract - Functions to be implemented by token contracts. +/// @author Stefan George - +abstract contract Token { + // This is not an abstract function, because solc won't recognize generated getter functions for public variables as functions + function totalSupply() external view virtual returns (uint256 supply) {} + function balanceOf(address owner) public view virtual returns (uint256 balance); + function transfer(address to, uint256 value) public virtual returns (bool success); + function transferFrom(address from, address to, uint256 value) public virtual returns (bool success); + function approve(address spender, uint256 value) public virtual returns (bool success); + function allowance(address owner, address spender) public view virtual returns (uint256 remaining); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval(address indexed owner, address indexed spender, uint256 value); +} \ No newline at end of file diff --git a/examples/standard-token/_ethpm_packages/standard-token/_src/StandardToken.sol b/examples/standard-token/_ethpm_packages/standard-token/_src/StandardToken.sol new file mode 100644 index 0000000..79acc8e --- /dev/null +++ b/examples/standard-token/_ethpm_packages/standard-token/_src/StandardToken.sol @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +import "./AbstractToken.sol"; + + +/// @title Standard token contract +/// @author Stefan George - +contract StandardToken is Token { + /* + * Data structures + */ + mapping (address => uint256) balances; + mapping (address => mapping (address => uint256)) allowed; + uint256 override public totalSupply; + + constructor (uint _totalSupply) public { + totalSupply = _totalSupply; + balances[msg.sender] = _totalSupply; + emit Transfer(address(0), msg.sender, _totalSupply); + } + + /* + * Read and write storage functions + */ + /// @dev Transfers sender's tokens to a given address. Returns success. + /// @param _to Address of token receiver. + /// @param _value Number of tokens to transfer. + function transfer(address _to, uint256 _value) public override returns (bool success) { + if (balances[msg.sender] >= _value && _value > 0) { + balances[msg.sender] -= _value; + balances[_to] += _value; + emit Transfer(msg.sender, _to, _value); + return true; + } + else { + return false; + } + } + + /// @dev Allows allowed third party to transfer tokens from one address to another. Returns success. + /// @param _from Address from where tokens are withdrawn. + /// @param _to Address to where tokens are sent. + /// @param _value Number of tokens to transfer. + function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) { + if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) { + balances[_to] += _value; + balances[_from] -= _value; + allowed[_from][msg.sender] -= _value; + emit Transfer(_from, _to, _value); + return true; + } + else { + return false; + } + } + + /// @dev Returns number of tokens owned by given address. + /// @param _owner Address of token owner. + function balanceOf(address _owner) public override view returns (uint256 balance) { + return balances[_owner]; + } + + /// @dev Sets approved amount of tokens for spender. Returns success. + /// @param _spender Address of allowed account. + /// @param _value Number of approved tokens. + function approve(address _spender, uint256 _value) public override returns (bool success) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } + + /* + * Read storage functions + */ + /// @dev Returns number of allowed tokens for given address. + /// @param _owner Address of token owner. + /// @param _spender Address of token spender. + function allowance(address _owner, address _spender) public override view returns (uint256 remaining) { + return allowed[_owner][_spender]; + } + +} \ No newline at end of file diff --git a/examples/standard-token/_ethpm_packages/standard-token/manifest.json b/examples/standard-token/_ethpm_packages/standard-token/manifest.json new file mode 100644 index 0000000..4a75962 --- /dev/null +++ b/examples/standard-token/_ethpm_packages/standard-token/manifest.json @@ -0,0 +1 @@ +{"contractTypes":{"StandardToken":{"abi":[{"inputs":[{"internalType":"uint256","name":"_totalSupply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"author":"Stefan George - ","methods":{"allowance(address,address)":{"details":"Returns number of allowed tokens for given address.","params":{"_owner":"Address of token owner.","_spender":"Address of token spender."}},"approve(address,uint256)":{"details":"Sets approved amount of tokens for spender. Returns success.","params":{"_spender":"Address of allowed account.","_value":"Number of approved tokens."}},"balanceOf(address)":{"details":"Returns number of tokens owned by given address.","params":{"_owner":"Address of token owner."}},"transfer(address,uint256)":{"details":"Transfers sender's tokens to a given address. Returns success.","params":{"_to":"Address of token receiver.","_value":"Number of tokens to transfer."}},"transferFrom(address,address,uint256)":{"details":"Allows allowed third party to transfer tokens from one address to another. Returns success.","params":{"_from":"Address from where tokens are withdrawn.","_to":"Address to where tokens are sent.","_value":"Number of tokens to transfer."}}},"title":"Standard token contract"},"sourceId":"StandardToken.sol"},"Token":{"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"supply","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"author":"Stefan George - ","methods":{},"title":"Abstract token contract - Functions to be implemented by token contracts."},"sourceId":"AbstractToken.sol","userdoc":{"methods":{},"notice":"Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20"}}},"manifest":"ethpm/3","name":"standard-token","sources":{"./AbstractToken.sol":{"installPath":"./AbstractToken.sol","type":"solidity","urls":["ipfs://QmSBYuGKSH2veDepMbFQu3XVStYRCvuqFjUV7YCPufeHJz"]},"./StandardToken.sol":{"installPath":"./StandardToken.sol","type":"solidity","urls":["ipfs://QmUofKBtNJVaqoSAtnHfrarJyyLm1oMUTAK4yCtnmYMJVy"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/transferable/_ethpm_packages/ethpm.lock b/examples/transferable/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..24b8767 --- /dev/null +++ b/examples/transferable/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "transferable": { + "alias": "transferable", + "install_uri": "ipfs://QmQAB7K4trduGoQ899LPtcqhPqnUcE56NKWYk2vx82UBJ6", + "registry_address": null, + "resolved_content_hash": "QmQAB7K4trduGoQ899LPtcqhPqnUcE56NKWYk2vx82UBJ6", + "resolved_package_name": "transferable", + "resolved_uri": "ipfs://QmQAB7K4trduGoQ899LPtcqhPqnUcE56NKWYk2vx82UBJ6", + "resolved_version": "1.0.0" + } +} diff --git a/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/ethpm.lock b/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..417d608 --- /dev/null +++ b/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "owned": { + "alias": "owned", + "install_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "registry_address": null, + "resolved_content_hash": "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_package_name": "owned", + "resolved_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_version": "1.0.0" + } +} diff --git a/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/_src/Owned.sol b/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/_src/Owned.sol new file mode 100644 index 0000000..b85703b --- /dev/null +++ b/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/_src/Owned.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + +contract Owned { + address owner; + + modifier onlyOwner { require(msg.sender == owner); _; } + + constructor() public { + owner = msg.sender; + } +} \ No newline at end of file diff --git a/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/manifest.json b/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/manifest.json new file mode 100644 index 0000000..ef18e8b --- /dev/null +++ b/examples/transferable/_ethpm_packages/transferable/_ethpm_packages/owned/manifest.json @@ -0,0 +1 @@ +{"manifest":"ethpm/3","meta":{"authors":["Piper Merriam "],"description":"Reusable contracts which implement a privileged 'owner' model for authorization.","keywords":["authorization"],"license":"MIT","links":{"documentation":"ipfs://QmUYcVzTfSwJoigggMxeo2g5STWAgJdisQsqcXHws7b1FW"}},"name":"owned","sources":{"Owned.sol":{"installPath":"./Owned.sol","type":"solidity","urls":["ipfs://QmU8QUSt56ZoBDJgjjXvAZEPro9LmK1m2gjVG5Q4s9x29W"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/transferable/_ethpm_packages/transferable/_src/Transferable.sol b/examples/transferable/_ethpm_packages/transferable/_src/Transferable.sol new file mode 100644 index 0000000..87d2195 --- /dev/null +++ b/examples/transferable/_ethpm_packages/transferable/_src/Transferable.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + +import {Owned} from "owned/contracts/Owned.sol"; + +contract Transferable is Owned { + event OwnerChanged(address indexed prevOwner, address indexed newOwner); + + function transferOwner(address newOwner) public onlyOwner returns (bool) { + emit OwnerChanged(owner, newOwner); + owner = newOwner; + return true; + } +} \ No newline at end of file diff --git a/examples/transferable/_ethpm_packages/transferable/manifest.json b/examples/transferable/_ethpm_packages/transferable/manifest.json new file mode 100644 index 0000000..5f2c417 --- /dev/null +++ b/examples/transferable/_ethpm_packages/transferable/manifest.json @@ -0,0 +1 @@ +{"buildDependencies":{"owned":"ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR"},"manifest":"ethpm/3","meta":{"authors":["Piper Merriam "],"description":"Reusable contracts which implement a privileged 'owner' model for authorization with functionality for transfering ownership.","keywords":["authorization"],"license":"MIT"},"name":"transferable","sources":{"Transferable.sol":{"installPath":"./Transferable.sol","type":"solidity","urls":["ipfs://QmdWB74Ca8tyXtS3UxzJqcvETv3LLkacX2ywfJfNNWVnYt"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/ethpm.lock b/examples/wallet-with-send/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..58af32b --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "wallet-with-send": { + "alias": "wallet-with-send", + "install_uri": "ipfs://QmSL3do3oYQfJmCCK8AQ8w278GQS5WJJmega5L22X3PGdG", + "registry_address": null, + "resolved_content_hash": "QmSL3do3oYQfJmCCK8AQ8w278GQS5WJJmega5L22X3PGdG", + "resolved_package_name": "wallet-with-send", + "resolved_uri": "ipfs://QmSL3do3oYQfJmCCK8AQ8w278GQS5WJJmega5L22X3PGdG", + "resolved_version": "1.0.0" + } +} diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/ethpm.lock b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..97113d9 --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "wallet": { + "alias": "wallet", + "install_uri": "ipfs://QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm", + "registry_address": null, + "resolved_content_hash": "QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm", + "resolved_package_name": "wallet", + "resolved_uri": "ipfs://QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm", + "resolved_version": "1.0.0" + } +} diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..88feb2c --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock @@ -0,0 +1,20 @@ +{ + "owned": { + "alias": "owned", + "install_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "registry_address": null, + "resolved_content_hash": "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_package_name": "owned", + "resolved_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_version": "1.0.0" + }, + "safe-math-lib": { + "alias": "safe-math-lib", + "install_uri": "ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "registry_address": null, + "resolved_content_hash": "QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "resolved_package_name": "safe-math-lib", + "resolved_uri": "ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "resolved_version": "1.0.0" + } +} diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol new file mode 100644 index 0000000..b85703b --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + +contract Owned { + address owner; + + modifier onlyOwner { require(msg.sender == owner); _; } + + constructor() public { + owner = msg.sender; + } +} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json new file mode 100644 index 0000000..ef18e8b --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json @@ -0,0 +1 @@ +{"manifest":"ethpm/3","meta":{"authors":["Piper Merriam "],"description":"Reusable contracts which implement a privileged 'owner' model for authorization.","keywords":["authorization"],"license":"MIT","links":{"documentation":"ipfs://QmUYcVzTfSwJoigggMxeo2g5STWAgJdisQsqcXHws7b1FW"}},"name":"owned","sources":{"Owned.sol":{"installPath":"./Owned.sol","type":"solidity","urls":["ipfs://QmU8QUSt56ZoBDJgjjXvAZEPro9LmK1m2gjVG5Q4s9x29W"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol new file mode 100644 index 0000000..f0c7c75 --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +/// @title Safe Math Library +/// @author Piper Merriam +library SafeMathLib { + /// @dev Adds a and b, throwing an error if the operation would cause an overflow. + /// @param a The first number to add + /// @param b The second number to add + function safeAdd(uint256 a, uint256 b) public pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } + + /// @dev Subtracts b from a, throwing an error if the operation would cause an underflow. + /// @param a The number to be subtracted from + /// @param b The amount that should be subtracted + function safeSub(uint256 a, uint256 b) public pure returns (uint256) { + assert(b <= a); + return a - b; + } +} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json new file mode 100644 index 0000000..3e7640e --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json @@ -0,0 +1 @@ +{"compilers":[{"contractTypes":["SafeMathLib"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"SafeMathLib":{"abi":[{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"safeAdd","outputs":[{"internalType":"uint256","name":"c","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"safeSub","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}],"deploymentBytecode":{"bytecode":"0x610144610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063a293d1e814610045578063e6cb901314610091575b600080fd5b61007b6004803603604081101561005b57600080fd5b8101908080359060200190929190803590602001909291905050506100dd565b6040518082815260200191505060405180910390f35b6100c7600480360360408110156100a757600080fd5b8101908080359060200190929190803590602001909291905050506100f4565b6040518082815260200191505060405180910390f35b6000828211156100e957fe5b818303905092915050565b600081830190508281101561010557fe5b8090509291505056fea26469706673582212201732500f2fac649ab2ce116d2145af69b3e8c6ef2d172ec377db7ed0b7a4801964736f6c63430006080033"},"devdoc":{"author":"Piper Merriam ","methods":{"safeAdd(uint256,uint256)":{"details":"Adds a and b, throwing an error if the operation would cause an overflow.","params":{"a":"The first number to add","b":"The second number to add"}},"safeSub(uint256,uint256)":{"details":"Subtracts b from a, throwing an error if the operation would cause an underflow.","params":{"a":"The number to be subtracted from","b":"The amount that should be subtracted"}}},"title":"Safe Math Library"},"runtimeBytecode":{"bytecode":"0x73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063a293d1e814610045578063e6cb901314610091575b600080fd5b61007b6004803603604081101561005b57600080fd5b8101908080359060200190929190803590602001909291905050506100dd565b6040518082815260200191505060405180910390f35b6100c7600480360360408110156100a757600080fd5b8101908080359060200190929190803590602001909291905050506100f4565b6040518082815260200191505060405180910390f35b6000828211156100e957fe5b818303905092915050565b600081830190508281101561010557fe5b8090509291505056fea26469706673582212201732500f2fac649ab2ce116d2145af69b3e8c6ef2d172ec377db7ed0b7a4801964736f6c63430006080033"},"sourceId":"SafeMathLib.sol"}},"deployments":{"blockchain://d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3/block/c4b7297b918ce3a93186eccff5195e77ef0c47b4e8cb8b66439aa25271f5170c":{"SafeMathLib":{"address":"0x6B2534269C5Ee98C37729d07Dc92C4b97EBB6235","block":"0x64fa9306a5c7aa3b8a71c29cd09fb897c3fb7325a3dbc75c4627dd8f08b759a6","contractType":"SafeMathLib","transaction":"0xb0ac2dbb86a29d70c8f3996834672e3af8cae7fc37718e49ac3adfd99eb23d31"}}},"manifest":"ethpm/3","name":"safe-math-lib","sources":{"./SafeMathLib.sol":{"installPath":"./SafeMathLib.sol","type":"solidity","urls":["ipfs://QmeyYahfHxPSoytQ2rPH2JUURin24sPvaMo6o6tKghwkAg"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_src/Wallet.sol b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_src/Wallet.sol new file mode 100644 index 0000000..4ea2c32 --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/_src/Wallet.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +import {SafeMathLib} from "./safe-math-lib/contracts/SafeMathLib.sol"; +import {Owned} from "./owned/contracts/Owned.sol"; + + +/// @title Contract for holding funds in escrow between two semi trusted parties. +/// @author Piper Merriam +contract Wallet is Owned { + using SafeMathLib for uint; + + mapping (address => uint) allowances; + + /// @dev Fallback function for depositing funds + fallback() external { + } + + /// @dev Sends the recipient the specified amount + /// @notice This will send the reciepient the specified amount. + function send(address payable recipient, uint value) public onlyOwner returns (bool) { + return recipient.send(value); + } + + /// @dev Sets recipient to be approved to withdraw the specified amount + /// @notice This will set the recipient to be approved to withdraw the specified amount. + function approve(address recipient, uint value) public onlyOwner returns (bool) { + allowances[recipient] = value; + return true; + } + + /// @dev Lets caller withdraw up to their approved amount + /// @notice This will withdraw provided value, deducting it from your total allowance. + function withdraw(uint value) public returns (bool) { + allowances[msg.sender] = allowances[msg.sender].safeSub(value); + if (!msg.sender.send(value)) + revert(); + return true; + } +} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/manifest.json b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/manifest.json new file mode 100644 index 0000000..25d0e37 --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_ethpm_packages/wallet/manifest.json @@ -0,0 +1 @@ +{"buildDependencies":{"owned":"ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR","safe-math-lib":"ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk"},"compilers":[{"contractTypes":["Wallet"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"Wallet":{"abi":[{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"send","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"deploymentBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610430806100606000396000f3fe608060405234801561001057600080fd5b50600436106100455760003560e01c8063095ea7b3146100485780632e1a7d4d146100ae578063d0679d34146100f457610046565b5b005b6100946004803603604081101561005e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061015a565b604051808215151515815260200191505060405180910390f35b6100da600480360360208110156100c457600080fd5b8101908080359060200190929190505050610203565b604051808215151515815260200191505060405180910390f35b6101406004803603604081101561010a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610362565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101b557600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561029d57600080fd5b505af41580156102b1573d6000803e3d6000fd5b505050506040513d60208110156102c757600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505061035957600080fd5b60019050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103bd57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505090509291505056fea2646970667358221220fa09119fa13c8df37a523851a236b913e5d00bf3274d5619daad516f510c8a9264736f6c63430006080033","linkReferences":[{"length":20,"name":"safe-math-lib:SafeMathLib","offsets":[679]}]},"devdoc":{"author":"Piper Merriam ","methods":{"approve(address,uint256)":{"details":"Sets recipient to be approved to withdraw the specified amount"},"send(address,uint256)":{"details":"Sends the recipient the specified amount"},"withdraw(uint256)":{"details":"Lets caller withdraw up to their approved amount"}},"title":"Contract for holding funds in escrow between two semi trusted parties."},"runtimeBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50600436106100455760003560e01c8063095ea7b3146100485780632e1a7d4d146100ae578063d0679d34146100f457610046565b5b005b6100946004803603604081101561005e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061015a565b604051808215151515815260200191505060405180910390f35b6100da600480360360208110156100c457600080fd5b8101908080359060200190929190505050610203565b604051808215151515815260200191505060405180910390f35b6101406004803603604081101561010a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610362565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101b557600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561029d57600080fd5b505af41580156102b1573d6000803e3d6000fd5b505050506040513d60208110156102c757600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505061035957600080fd5b60019050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103bd57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505090509291505056fea2646970667358221220fa09119fa13c8df37a523851a236b913e5d00bf3274d5619daad516f510c8a9264736f6c63430006080033","linkReferences":[{"length":20,"name":"safe-math-lib:SafeMathLib","offsets":[583]}]},"sourceId":"Wallet.sol","userdoc":{"methods":{"approve(address,uint256)":{"notice":"This will set the recipient to be approved to withdraw the specified amount."},"send(address,uint256)":{"notice":"This will send the reciepient the specified amount."},"withdraw(uint256)":{"notice":"This will withdraw provided value, deducting it from your total allowance."}}}}},"deployments":{"blockchain://41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d/block/e30e4ef1dd1e73e788c3d094859f14ddd139a19e8a3667e2ee4831d9bd1113ac":{"Wallet":{"address":"0x491CB3AC79d0f5D7078C3cF6EF3daEcE9623CD21","block":"0x77adadc004c1a830682f3237b42ce81a379d11dfd88292c97ad80658f470717a","contractType":"Wallet","runtimeBytecode":{"linkDependencies":[{"offsets":[583],"type":"reference","value":"safe-math-lib:SafeMathLib"}]},"transaction":"0x8648f43125776ec2b727eda84d10c67db1693fce8bc1e7b3f84f9e40086e4773"}}},"manifest":"ethpm/3","name":"wallet","sources":{"Wallet.sol":{"installPath":"./Wallet.sol","type":"solidity","urls":["ipfs://QmfTZzHLSShTS1woD7JNszAyhjtS7ErFDT4QmtwEQQ1qpa"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_src/WalletWithSend.sol b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_src/WalletWithSend.sol new file mode 100644 index 0000000..399f953 --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/_src/WalletWithSend.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +import {Wallet} from "./wallet/contracts/Wallet.sol"; + + +/// @title Wallet contract with simple send and approval spending functionality +/// @author Piper Merriam +contract WalletWithSend is Wallet { + /// @dev Sends funds that have been approved to the specified address + /// @notice This will send the reciepient the specified amount. + function approvedSend(uint value, address payable to) public { + allowances[msg.sender] = allowances[msg.sender].safeSub(value); + if (!to.send(value)) + revert(); + } +} \ No newline at end of file diff --git a/examples/wallet-with-send/_ethpm_packages/wallet-with-send/manifest.json b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/manifest.json new file mode 100644 index 0000000..7448633 --- /dev/null +++ b/examples/wallet-with-send/_ethpm_packages/wallet-with-send/manifest.json @@ -0,0 +1 @@ +{"buildDependencies":{"wallet":"ipfs://QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm"},"compilers":[{"contractTypes":["WalletWithSend"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"WalletWithSend":{"abi":[{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"address payable","name":"to","type":"address"}],"name":"approvedSend","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"send","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"deploymentBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506105e1806100606000396000f3fe608060405234801561001057600080fd5b50600436106100505760003560e01c8063095ea7b3146100535780632e1a7d4d146100b9578063c577ff8b146100ff578063d0679d341461014d57610051565b5b005b61009f6004803603604081101561006957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506101b3565b604051808215151515815260200191505060405180910390f35b6100e5600480360360208110156100cf57600080fd5b810190808035906020019092919050505061025c565b604051808215151515815260200191505060405180910390f35b61014b6004803603604081101561011557600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103bb565b005b6101996004803603604081101561016357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610513565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461020e57600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156102f657600080fd5b505af415801561030a573d6000803e3d6000fd5b505050506040513d602081101561032057600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f193505050506103b257600080fd5b60019050919050565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561045357600080fd5b505af4158015610467573d6000803e3d6000fd5b505050506040513d602081101561047d57600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505061050f57600080fd5b5050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461056e57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505090509291505056fea2646970667358221220b3e9d35017f06ad00bdc4a7887a8d810719509dbab16e308d48e0a800d95d90e64736f6c63430006080033","linkReferences":[{"length":20,"name":"wallet:safe-math-lib:SafeMathLib","offsets":[768,1117]}]},"devdoc":{"author":"Piper Merriam ","methods":{"approve(address,uint256)":{"details":"Sets recipient to be approved to withdraw the specified amount"},"approvedSend(uint256,address)":{"details":"Sends funds that have been approved to the specified address"},"send(address,uint256)":{"details":"Sends the recipient the specified amount"},"withdraw(uint256)":{"details":"Lets caller withdraw up to their approved amount"}},"title":"Wallet contract with simple send and approval spending functionality"},"runtimeBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50600436106100505760003560e01c8063095ea7b3146100535780632e1a7d4d146100b9578063c577ff8b146100ff578063d0679d341461014d57610051565b5b005b61009f6004803603604081101561006957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506101b3565b604051808215151515815260200191505060405180910390f35b6100e5600480360360208110156100cf57600080fd5b810190808035906020019092919050505061025c565b604051808215151515815260200191505060405180910390f35b61014b6004803603604081101561011557600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506103bb565b005b6101996004803603604081101561016357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610513565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461020e57600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b1580156102f657600080fd5b505af415801561030a573d6000803e3d6000fd5b505050506040513d602081101561032057600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f193505050506103b257600080fd5b60019050919050565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561045357600080fd5b505af4158015610467573d6000803e3d6000fd5b505050506040513d602081101561047d57600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508073ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505061050f57600080fd5b5050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461056e57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505090509291505056fea2646970667358221220b3e9d35017f06ad00bdc4a7887a8d810719509dbab16e308d48e0a800d95d90e64736f6c63430006080033","linkReferences":[{"length":20,"name":"wallet:safe-math-lib:SafeMathLib","offsets":[672,1021]}]},"sourceId":"WalletWithSend.sol","userdoc":{"methods":{"approve(address,uint256)":{"notice":"This will set the recipient to be approved to withdraw the specified amount."},"approvedSend(uint256,address)":{"notice":"This will send the reciepient the specified amount."},"send(address,uint256)":{"notice":"This will send the reciepient the specified amount."},"withdraw(uint256)":{"notice":"This will withdraw provided value, deducting it from your total allowance."}}}}},"deployments":{"blockchain://41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d/block/b6d0d43f61e5e36d20eb3d5caca12220b024ed2861a814795d1fd6596fe041bf":{"Wallet":{"address":"0x4308223cdec48F8a396Ba206025b39caD11cacE6","block":"0x48ed49ff47ecf433d7c8f1847ddae8c1250ad948fda22342f78f732823534780","contractType":"WalletWithSend","runtimeBytecode":{"linkDependencies":[{"offsets":[672,1021],"type":"reference","value":"wallet:safe-math-lib:SafeMathLib"}]},"transaction":"0xc1bdfc5eeb517aabb3b65cb24f8d0cd3fd4b8d71f94f90f3e76250cbb96b5369"}}},"manifest":"ethpm/3","name":"wallet-with-send","sources":{"WalletWithSend.sol":{"installPath":"./WalletWithSend.sol","type":"solidity","urls":["ipfs://QmQmKim8MpVGgkaJzHCAWkAJnr3hPLrUXmaz5Ao1gWjxNY"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet/_ethpm_packages/ethpm.lock b/examples/wallet/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..97113d9 --- /dev/null +++ b/examples/wallet/_ethpm_packages/ethpm.lock @@ -0,0 +1,11 @@ +{ + "wallet": { + "alias": "wallet", + "install_uri": "ipfs://QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm", + "registry_address": null, + "resolved_content_hash": "QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm", + "resolved_package_name": "wallet", + "resolved_uri": "ipfs://QmRALeFkttSr6DLmPiNtAqLcMJYXu4BK3SjZGVgW8VASnm", + "resolved_version": "1.0.0" + } +} diff --git a/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock new file mode 100644 index 0000000..88feb2c --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/ethpm.lock @@ -0,0 +1,20 @@ +{ + "owned": { + "alias": "owned", + "install_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "registry_address": null, + "resolved_content_hash": "QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_package_name": "owned", + "resolved_uri": "ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR", + "resolved_version": "1.0.0" + }, + "safe-math-lib": { + "alias": "safe-math-lib", + "install_uri": "ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "registry_address": null, + "resolved_content_hash": "QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "resolved_package_name": "safe-math-lib", + "resolved_uri": "ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk", + "resolved_version": "1.0.0" + } +} diff --git a/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol new file mode 100644 index 0000000..b85703b --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/_src/Owned.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + +contract Owned { + address owner; + + modifier onlyOwner { require(msg.sender == owner); _; } + + constructor() public { + owner = msg.sender; + } +} \ No newline at end of file diff --git a/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json new file mode 100644 index 0000000..ef18e8b --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/owned/manifest.json @@ -0,0 +1 @@ +{"manifest":"ethpm/3","meta":{"authors":["Piper Merriam "],"description":"Reusable contracts which implement a privileged 'owner' model for authorization.","keywords":["authorization"],"license":"MIT","links":{"documentation":"ipfs://QmUYcVzTfSwJoigggMxeo2g5STWAgJdisQsqcXHws7b1FW"}},"name":"owned","sources":{"Owned.sol":{"installPath":"./Owned.sol","type":"solidity","urls":["ipfs://QmU8QUSt56ZoBDJgjjXvAZEPro9LmK1m2gjVG5Q4s9x29W"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol new file mode 100644 index 0000000..f0c7c75 --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/_src/SafeMathLib.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +/// @title Safe Math Library +/// @author Piper Merriam +library SafeMathLib { + /// @dev Adds a and b, throwing an error if the operation would cause an overflow. + /// @param a The first number to add + /// @param b The second number to add + function safeAdd(uint256 a, uint256 b) public pure returns (uint256 c) { + c = a + b; + assert(c >= a); + return c; + } + + /// @dev Subtracts b from a, throwing an error if the operation would cause an underflow. + /// @param a The number to be subtracted from + /// @param b The amount that should be subtracted + function safeSub(uint256 a, uint256 b) public pure returns (uint256) { + assert(b <= a); + return a - b; + } +} \ No newline at end of file diff --git a/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json new file mode 100644 index 0000000..3e7640e --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/_ethpm_packages/safe-math-lib/manifest.json @@ -0,0 +1 @@ +{"compilers":[{"contractTypes":["SafeMathLib"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"SafeMathLib":{"abi":[{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"safeAdd","outputs":[{"internalType":"uint256","name":"c","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"safeSub","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}],"deploymentBytecode":{"bytecode":"0x610144610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063a293d1e814610045578063e6cb901314610091575b600080fd5b61007b6004803603604081101561005b57600080fd5b8101908080359060200190929190803590602001909291905050506100dd565b6040518082815260200191505060405180910390f35b6100c7600480360360408110156100a757600080fd5b8101908080359060200190929190803590602001909291905050506100f4565b6040518082815260200191505060405180910390f35b6000828211156100e957fe5b818303905092915050565b600081830190508281101561010557fe5b8090509291505056fea26469706673582212201732500f2fac649ab2ce116d2145af69b3e8c6ef2d172ec377db7ed0b7a4801964736f6c63430006080033"},"devdoc":{"author":"Piper Merriam ","methods":{"safeAdd(uint256,uint256)":{"details":"Adds a and b, throwing an error if the operation would cause an overflow.","params":{"a":"The first number to add","b":"The second number to add"}},"safeSub(uint256,uint256)":{"details":"Subtracts b from a, throwing an error if the operation would cause an underflow.","params":{"a":"The number to be subtracted from","b":"The amount that should be subtracted"}}},"title":"Safe Math Library"},"runtimeBytecode":{"bytecode":"0x73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c8063a293d1e814610045578063e6cb901314610091575b600080fd5b61007b6004803603604081101561005b57600080fd5b8101908080359060200190929190803590602001909291905050506100dd565b6040518082815260200191505060405180910390f35b6100c7600480360360408110156100a757600080fd5b8101908080359060200190929190803590602001909291905050506100f4565b6040518082815260200191505060405180910390f35b6000828211156100e957fe5b818303905092915050565b600081830190508281101561010557fe5b8090509291505056fea26469706673582212201732500f2fac649ab2ce116d2145af69b3e8c6ef2d172ec377db7ed0b7a4801964736f6c63430006080033"},"sourceId":"SafeMathLib.sol"}},"deployments":{"blockchain://d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3/block/c4b7297b918ce3a93186eccff5195e77ef0c47b4e8cb8b66439aa25271f5170c":{"SafeMathLib":{"address":"0x6B2534269C5Ee98C37729d07Dc92C4b97EBB6235","block":"0x64fa9306a5c7aa3b8a71c29cd09fb897c3fb7325a3dbc75c4627dd8f08b759a6","contractType":"SafeMathLib","transaction":"0xb0ac2dbb86a29d70c8f3996834672e3af8cae7fc37718e49ac3adfd99eb23d31"}}},"manifest":"ethpm/3","name":"safe-math-lib","sources":{"./SafeMathLib.sol":{"installPath":"./SafeMathLib.sol","type":"solidity","urls":["ipfs://QmeyYahfHxPSoytQ2rPH2JUURin24sPvaMo6o6tKghwkAg"]}},"version":"1.0.0"} \ No newline at end of file diff --git a/examples/wallet/_ethpm_packages/wallet/_src/Wallet.sol b/examples/wallet/_ethpm_packages/wallet/_src/Wallet.sol new file mode 100644 index 0000000..4ea2c32 --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/_src/Wallet.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.8; + + +import {SafeMathLib} from "./safe-math-lib/contracts/SafeMathLib.sol"; +import {Owned} from "./owned/contracts/Owned.sol"; + + +/// @title Contract for holding funds in escrow between two semi trusted parties. +/// @author Piper Merriam +contract Wallet is Owned { + using SafeMathLib for uint; + + mapping (address => uint) allowances; + + /// @dev Fallback function for depositing funds + fallback() external { + } + + /// @dev Sends the recipient the specified amount + /// @notice This will send the reciepient the specified amount. + function send(address payable recipient, uint value) public onlyOwner returns (bool) { + return recipient.send(value); + } + + /// @dev Sets recipient to be approved to withdraw the specified amount + /// @notice This will set the recipient to be approved to withdraw the specified amount. + function approve(address recipient, uint value) public onlyOwner returns (bool) { + allowances[recipient] = value; + return true; + } + + /// @dev Lets caller withdraw up to their approved amount + /// @notice This will withdraw provided value, deducting it from your total allowance. + function withdraw(uint value) public returns (bool) { + allowances[msg.sender] = allowances[msg.sender].safeSub(value); + if (!msg.sender.send(value)) + revert(); + return true; + } +} \ No newline at end of file diff --git a/examples/wallet/_ethpm_packages/wallet/manifest.json b/examples/wallet/_ethpm_packages/wallet/manifest.json new file mode 100644 index 0000000..25d0e37 --- /dev/null +++ b/examples/wallet/_ethpm_packages/wallet/manifest.json @@ -0,0 +1 @@ +{"buildDependencies":{"owned":"ipfs://QmcxvhkJJVpbxEAa6cgW3B6XwPJb79w9GpNUv2P2THUzZR","safe-math-lib":"ipfs://QmWnPsiS3Xb8GvCDEBFnnKs8Yk4HaAX6rCqJAaQXGbCoPk"},"compilers":[{"contractTypes":["Wallet"],"name":"solc","settings":{"optimize":false},"version":"0.6.8+commit.0bbfe453"}],"contractTypes":{"Wallet":{"abi":[{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"send","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"deploymentBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610430806100606000396000f3fe608060405234801561001057600080fd5b50600436106100455760003560e01c8063095ea7b3146100485780632e1a7d4d146100ae578063d0679d34146100f457610046565b5b005b6100946004803603604081101561005e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061015a565b604051808215151515815260200191505060405180910390f35b6100da600480360360208110156100c457600080fd5b8101908080359060200190929190505050610203565b604051808215151515815260200191505060405180910390f35b6101406004803603604081101561010a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610362565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101b557600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561029d57600080fd5b505af41580156102b1573d6000803e3d6000fd5b505050506040513d60208110156102c757600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505061035957600080fd5b60019050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103bd57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505090509291505056fea2646970667358221220fa09119fa13c8df37a523851a236b913e5d00bf3274d5619daad516f510c8a9264736f6c63430006080033","linkReferences":[{"length":20,"name":"safe-math-lib:SafeMathLib","offsets":[679]}]},"devdoc":{"author":"Piper Merriam ","methods":{"approve(address,uint256)":{"details":"Sets recipient to be approved to withdraw the specified amount"},"send(address,uint256)":{"details":"Sends the recipient the specified amount"},"withdraw(uint256)":{"details":"Lets caller withdraw up to their approved amount"}},"title":"Contract for holding funds in escrow between two semi trusted parties."},"runtimeBytecode":{"bytecode":"0x608060405234801561001057600080fd5b50600436106100455760003560e01c8063095ea7b3146100485780632e1a7d4d146100ae578063d0679d34146100f457610046565b5b005b6100946004803603604081101561005e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061015a565b604051808215151515815260200191505060405180910390f35b6100da600480360360208110156100c457600080fd5b8101908080359060200190929190505050610203565b604051808215151515815260200191505060405180910390f35b6101406004803603604081101561010a57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610362565b604051808215151515815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101b557600080fd5b81600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506001905092915050565b6000600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205473000000000000000000000000000000000000000063a293d1e89091846040518363ffffffff1660e01b8152600401808381526020018281526020019250505060206040518083038186803b15801561029d57600080fd5b505af41580156102b1573d6000803e3d6000fd5b505050506040513d60208110156102c757600080fd5b8101908080519060200190929190505050600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505061035957600080fd5b60019050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103bd57600080fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505090509291505056fea2646970667358221220fa09119fa13c8df37a523851a236b913e5d00bf3274d5619daad516f510c8a9264736f6c63430006080033","linkReferences":[{"length":20,"name":"safe-math-lib:SafeMathLib","offsets":[583]}]},"sourceId":"Wallet.sol","userdoc":{"methods":{"approve(address,uint256)":{"notice":"This will set the recipient to be approved to withdraw the specified amount."},"send(address,uint256)":{"notice":"This will send the reciepient the specified amount."},"withdraw(uint256)":{"notice":"This will withdraw provided value, deducting it from your total allowance."}}}}},"deployments":{"blockchain://41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d/block/e30e4ef1dd1e73e788c3d094859f14ddd139a19e8a3667e2ee4831d9bd1113ac":{"Wallet":{"address":"0x491CB3AC79d0f5D7078C3cF6EF3daEcE9623CD21","block":"0x77adadc004c1a830682f3237b42ce81a379d11dfd88292c97ad80658f470717a","contractType":"Wallet","runtimeBytecode":{"linkDependencies":[{"offsets":[583],"type":"reference","value":"safe-math-lib:SafeMathLib"}]},"transaction":"0x8648f43125776ec2b727eda84d10c67db1693fce8bc1e7b3f84f9e40086e4773"}}},"manifest":"ethpm/3","name":"wallet","sources":{"Wallet.sol":{"installPath":"./Wallet.sol","type":"solidity","urls":["ipfs://QmfTZzHLSShTS1woD7JNszAyhjtS7ErFDT4QmtwEQQ1qpa"]}},"version":"1.0.0"} \ No newline at end of file