New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zos-lib

Package Overview
Dependencies
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zos-lib - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

examples/single/build/contracts/AddressUtils.json

49

examples/complex/index.js
const decodeLogs = require('zos-lib').decodeLogs;
const encodeCall = require('zos-lib').encodeCall;

@@ -17,3 +18,4 @@ const OwnedUpgradeabilityProxy = artifacts.require('zos-lib/contracts/upgradeability/OwnedUpgradeabilityProxy.sol');

from: owner,
gas: 2000000
gas: 2000000,
gasPrice: 120000000000
};

@@ -25,3 +27,6 @@

// Setup a proxy factory that will create proxy contracts for the project's upgradeable contracts.
console.log("<< Setting up AppManager >>");
// Setup a proxy factory that will be in charge of creating proxy contracts
// for all of the project's upgradeable contracts.
console.log(`Deploying proxy factory...`);

@@ -31,3 +36,4 @@ this.factory = await UpgradeabilityProxyFactory.new(txParams);

// A package keeps track of the project's versions.
// A package keeps track of the project's versions, each of which is a
// contract directory, i.e. a list of contracts.
console.log(`Deploying application package...`);

@@ -39,7 +45,6 @@ this.package = await Package.new(txParams);

console.log(`Deploying application directory for version ${initialVersion}...`);
// TODO
this.directory = await AppDirectory.new(0, txParams);
console.log(`Deployed application directory for initial version at ${this.directory.address}`);
// Initialize the package with the first version.
// Initialize the package with the first contract directory.
console.log(`Adding version to package...`);

@@ -49,3 +54,3 @@ await this.package.addVersion(initialVersion, this.directory.address, txParams);

// App manager bootstraping is ready.
// With a proxy factory and a package, the project's app manager is bootstrapped and ready for use.
console.log(`Deploying application manager...`);

@@ -58,7 +63,10 @@ this.appManager = await AppManager.new(this.package.address, initialVersion, this.factory.address, txParams);

console.log(`Deploying first implementation...`);
console.log("\n<< Deploying version 1 >>");
// Deploy an implementation that defines the behavior of the main contract.
console.log(`Deploying first implementation of ${contractName}...`);
const implementation = await DonationsV1.new(txParams);
console.log(`Deploying first implementation at ${implementation.address}`);
console.log(`Deployed first implementation at ${implementation.address}`);
// Register the implementation in the current version.
// Register the implementation in the current version of the app.
console.log(`Registering implementation...`);

@@ -68,9 +76,12 @@ await this.directory.setImplementation(contractName, implementation.address, txParams);

// Create a proxy to interact with the implementation.
console.log(`Creating proxy...`);
const {receipt} = await this.appManager.create(contractName, txParams);
// Create a proxy that wraps the implementation, making it upgradeable.
// At this point, the proxy's address is usable by any dapp, but can also be upgraded
// without having to use a new address or losing the contract's storage.
console.log(`Creating proxy for ${contractName}...`);
const callData = encodeCall('initialize', ['address'], [owner]);
const {receipt} = await this.appManager.createAndCall(contractName, callData, txParams);
const logs = decodeLogs([receipt.logs[1]], UpgradeabilityProxyFactory, 0x0);
const proxyAddress = logs.find(l => l.event === 'ProxyCreated').args.proxy;
this.proxy = OwnedUpgradeabilityProxy.at(proxyAddress);
console.log(`Proxy created at ${proxyAddress}`);
console.log(`Proxy for ${contractName} created at ${proxyAddress}`);
}

@@ -80,5 +91,7 @@

console.log("\n<< Deploying version 2 >>");
const versionName = '0.0.2';
// Prepare a new version for the app.
// Prepare a new version for the app that will hold the new implementation for the main contract.
console.log(`Deploying new application directory...`);

@@ -91,3 +104,3 @@ this.directory = await AppDirectory.new(stdlib, txParams);

const implementation = await DonationsV2.new(txParams);
console.log(`Deploying new implementation at ${implementation.address}`);
console.log(`Deploying new implementation of ${contractName} at ${implementation.address}`);

@@ -103,3 +116,3 @@ // Register the new implementation in the current version.

await this.package.addVersion(versionName, this.directory.address, txParams);
console.log(`Setting new application version ${versionName}`);
console.log(`Setting the app's version to ${versionName}`);
await this.appManager.setVersion(versionName, txParams);

@@ -110,6 +123,6 @@

await this.appManager.upgradeTo(this.proxy.address, contractName, txParams);
console.log(`Upgraded contract proxy to latest app version ${versionName}`);
console.log(`Upgraded contract proxy for ${contractName} to latest app version ${versionName}`);
// Add an ERC721 token implementation to the project.
console.log(`Creating proxy for ERC721 token...`);
console.log(`Creating proxy for ERC721 token, for use in ${contractName}...`);
const {receipt} = await this.appManager.create('MintableERC721Token', txParams);

@@ -116,0 +129,0 @@ const logs = decodeLogs([receipt.logs[1]], UpgradeabilityProxyFactory, 0x0);

{
"name": "zos-lib",
"version": "0.1.3",
"version": "0.1.4",
"description": "zeppelin_os library",

@@ -5,0 +5,0 @@ "scripts": {

@@ -108,2 +108,30 @@ # zeppelin_os library

```sol
pragma solidity ^0.4.21;
import "openzeppelin-zos/contracts/ownership/Ownable.sol";
import "openzeppelin-zos/contracts/math/SafeMath.sol";
contract DonationsV1 is Ownable {
using SafeMath for uint256;
// Keeps a mapping of total donor balances.
mapping(address => uint256) public donorBalances;
function donate() payable public {
require(msg.value > 0);
// Update user donation balance.
donorBalances[msg.sender] = donorBalances[msg.sender].add(msg.value);
}
function getDonationBalance(address _donor) public view returns (uint256) {
return donorBalances[_donor];
}
function withdraw(address _wallet) onlyOwner {
// Withdraw all donated funds.
_wallet.transfer(this.balance);
}
}
```

@@ -116,2 +144,33 @@

```js
const initialVersion = '0.0.1';
console.log("<< Setting up AppManager >>");
// Setup a proxy factory that will be in charge of creating proxy contracts
// for all of the project's upgradeable contracts.
console.log(`Deploying proxy factory...`);
this.factory = await UpgradeabilityProxyFactory.new(txParams);
console.log(`Deployed proxy factory at ${this.factory.address}`);
// A package keeps track of the project's versions, each of which is a
// contract directory, i.e. a list of contracts.
console.log(`Deploying application package...`);
this.package = await Package.new(txParams);
console.log(`Deployed application package at ${this.package.address}`);
// For each version, a directory keeps track of the project's contract implementations.
console.log(`Deploying application directory for version ${initialVersion}...`);
this.directory = await AppDirectory.new(0, txParams);
console.log(`Deployed application directory for initial version at ${this.directory.address}`);
// Initialize the package with the first contract directory.
console.log(`Adding version to package...`);
await this.package.addVersion(initialVersion, this.directory.address, txParams);
console.log(`Added application directory to package`);
// With a proxy factory and a package, the project's app manager is bootstrapped and ready for use.
console.log(`Deploying application manager...`);
this.appManager = await AppManager.new(this.package.address, initialVersion, this.factory.address, txParams);
console.log(`Deployed application manager at ${this.appManager.address}`);
```

@@ -121,2 +180,24 @@

```js
console.log("\n<< Deploying version 1 >>");
// Deploy an implementation that defines the behavior of the main contract.
console.log(`Deploying first implementation of ${contractName}...`);
const implementation = await DonationsV1.new(txParams);
console.log(`Deployed first implementation at ${implementation.address}`);
// Register the implementation in the current version of the app.
console.log(`Registering implementation...`);
await this.directory.setImplementation(contractName, implementation.address, txParams);
console.log(`Registered implementation in current contract directory`);
// Create a proxy that wraps the implementation, making it upgradeable.
// At this point, the proxy's address is usable by any dapp, but can also be upgraded
// without having to use a new address or losing the contract's storage.
console.log(`Creating proxy for ${contractName}...`);
const callData = encodeCall('initialize', ['address'], [owner]);
const {receipt} = await this.appManager.createAndCall(contractName, callData, txParams);
const logs = decodeLogs([receipt.logs[1]], UpgradeabilityProxyFactory, 0x0);
const proxyAddress = logs.find(l => l.event === 'ProxyCreated').args.proxy;
this.proxy = OwnedUpgradeabilityProxy.at(proxyAddress);
console.log(`Proxy for ${contractName} created at ${proxyAddress}`);
```

@@ -127,2 +208,36 @@

```sol
pragma solidity ^0.4.21;
import "./DonationsV1.sol";
import "openzeppelin-zos/contracts/token/ERC721/MintableERC721Token.sol";
contract DonationsV2 is DonationsV1 {
// Keeps track of the highest donation.
uint256 public highestDonation;
// ERC721 non-fungible tokens to be emitted on donations.
MintableERC721Token public token;
uint256 public numEmittedTokens;
function setToken(MintableERC721Token _token) external onlyOwner {
require(_token != address(0));
require(token == address(0));
token = _token;
}
function donate() payable public {
super.donate();
// Is this the highest donation?
if(msg.value > highestDonation) {
// Emit a token.
token.mint(msg.sender, numEmittedTokens);
numEmittedTokens++;
highestDonation = msg.value;
}
}
}
```

@@ -133,2 +248,45 @@

```js
console.log("\n<< Deploying version 2 >>");
const versionName = '0.0.2';
// Prepare a new version for the app that will hold the new implementation for the main contract.
console.log(`Deploying new application directory...`);
this.directory = await AppDirectory.new(stdlib, txParams);
console.log(`Deployed application directory for new version ${versionName} at ${this.directory.address}`);
// Deploy contract implementation.
console.log(`Deploying new contract implementation...`);
const implementation = await DonationsV2.new(txParams);
console.log(`Deploying new implementation of ${contractName} at ${implementation.address}`);
// Register the new implementation in the current version.
console.log(`Registering new contract implementation...`);
await this.directory.setImplementation(contractName, implementation.address, txParams);
console.log(`Registered implementation in current contract directory`);
// Create a new application version with the new directory and
// update the app's version to it.
console.log(`Adding new application version ${versionName}`);
await this.package.addVersion(versionName, this.directory.address, txParams);
console.log(`Setting the app's version to ${versionName}`);
await this.appManager.setVersion(versionName, txParams);
// Upgrade the proxy to the application's latest version.
console.log(`Upgrading proxy for ${contractName}`);
await this.appManager.upgradeTo(this.proxy.address, contractName, txParams);
console.log(`Upgraded contract proxy for ${contractName} to latest app version ${versionName}`);
// Add an ERC721 token implementation to the project.
console.log(`Creating proxy for ERC721 token, for use in ${contractName}...`);
const {receipt} = await this.appManager.create('MintableERC721Token', txParams);
const logs = decodeLogs([receipt.logs[1]], UpgradeabilityProxyFactory, 0x0);
const proxyAddress = logs.find(l => l.event === 'ProxyCreated').args.proxy;
console.log(`Token proxy created at ${proxyAddress}`);
// Set the token in the new implementation.
console.log(`Setting application's token...`);
const donations = DonationsV2.at(this.proxy.address);
await donations.setToken(proxyAddress, txParams);
console.log(`Token set succesfully`);
```

@@ -135,0 +293,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc