Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2 to 0.1.3

contracts/migrations/Initializable.sol

60

examples/complex/index.js

@@ -1,2 +0,2 @@

const decodeLogs = require('zos-lib/test/helpers/decodeLogs');
const decodeLogs = require('zos-lib').decodeLogs;

@@ -12,6 +12,8 @@ const OwnedUpgradeabilityProxy = artifacts.require('zos-lib/contracts/upgradeability/OwnedUpgradeabilityProxy.sol');

const owner = web3.eth.accounts[0];
const stdlib = "0xA739d10Cc20211B973dEE09DB8F0D75736E2D817";
const owner = web3.eth.accounts[1];
const contractName = "Donations";
const txParams = {
from: owner
from: owner,
gas: 2000000
};

@@ -21,7 +23,6 @@

console.log("Deploying AppManager...");
const initialVersion = '0.0.1';
// Setup a proxy factory that will create proxy contracts for the project's upgradeable contracts.
console.log(`Deploying proxy factory...`);
this.factory = await UpgradeabilityProxyFactory.new(txParams);

@@ -31,2 +32,3 @@ console.log(`Deployed proxy factory at ${this.factory.address}`);

// A package keeps track of the project's versions.
console.log(`Deploying application package...`);
this.package = await Package.new(txParams);

@@ -36,2 +38,4 @@ 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}...`);
// TODO
this.directory = await AppDirectory.new(0, txParams);

@@ -41,2 +45,3 @@ console.log(`Deployed application directory for initial version at ${this.directory.address}`);

// Initialize the package with the first version.
console.log(`Adding version to package...`);
await this.package.addVersion(initialVersion, this.directory.address, txParams);

@@ -46,2 +51,3 @@ console.log(`Added application directory to package`);

// App manager bootstraping is ready.
console.log(`Deploying application manager...`);
this.appManager = await AppManager.new(this.package.address, initialVersion, this.factory.address, txParams);

@@ -51,7 +57,5 @@ console.log(`Deployed application manager at ${this.appManager.address}`);

async function deployInitialImplementationWithProxy() {
async function deployVersion1Implementation() {
console.log(`Deploying initial implementation...`);
// Deploy contract implementation.
console.log(`Deploying first implementation...`);
const implementation = await DonationsV1.new(txParams);

@@ -61,2 +65,3 @@ console.log(`Deploying first implementation at ${implementation.address}`);

// Register the implementation in the current version.
console.log(`Registering implementation...`);
await this.directory.setImplementation(contractName, implementation.address, txParams);

@@ -68,3 +73,3 @@ console.log(`Registered implementation in current contract directory`);

const {receipt} = await this.appManager.create(contractName, txParams);
const logs = decodeLogs([receipt.logs[0]], UpgradeabilityProxyFactory, 0x0);
const logs = decodeLogs([receipt.logs[1]], UpgradeabilityProxyFactory, 0x0);
const proxyAddress = logs.find(l => l.event === 'ProxyCreated').args.proxy;

@@ -75,3 +80,3 @@ this.proxy = OwnedUpgradeabilityProxy.at(proxyAddress);

async function deployUpdatedImplementation() {
async function deployVersion2() {

@@ -81,6 +86,8 @@ const versionName = '0.0.2';

// Prepare a new version for the app.
this.directory = await AppDirectory.new(0, txParams);
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);

@@ -90,13 +97,15 @@ console.log(`Deploying new implementation 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`);
// Connect the app manager to zos' standard library.
// await this.directory.setStdlib();
// 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 new application version ${versionName}`);
await this.appManager.setVersion(versionName, txParams);
// TODO
await this.package.addVersion(versionName, this.directory.address, this.txParams);
await this.appManager.setVersion(versionName);
// Upgrade the proxy to the application's latest version.
console.log(`Upgrading proxy for ${contractName}`);
await this.appManager.upgradeTo(this.proxy.address, contractName, txParams);

@@ -106,10 +115,13 @@ console.log(`Upgraded contract proxy to latest app version ${versionName}`);

// Add an ERC721 token implementation to the project.
console.log(`Creating proxy for ERC721 token...`);
const {receipt} = await this.appManager.create('MintableERC721Token', txParams);
const logs = decodeLogs([receipt.logs[0]], UpgradeabilityProxyFactory, 0x0);
const logs = decodeLogs([receipt.logs[1]], UpgradeabilityProxyFactory, 0x0);
const proxyAddress = logs.find(l => l.event === 'ProxyCreated').args.proxy;
// const tokenProxy = MintableERC721Token.at(proxyAddress);
console.log(`Token proxy created at ${proxyAddress}`);
// Set the token in the new implementation.
const donations = DonationsV2.at(this.proxy);
await donations.setToken(proxyAddress);
console.log(`Setting application's token...`);
const donations = DonationsV2.at(this.proxy.address);
await donations.setToken(proxyAddress, txParams);
console.log(`Token set succesfully`);
}

@@ -119,4 +131,4 @@

await setupAppManager();
await deployInitialImplementationWithProxy();
await deployUpdatedImplementation();
await deployVersion1Implementation();
await deployVersion2();
};

10

examples/complex/package.json

@@ -8,3 +8,3 @@ {

"compile": "rm -rf build && npx truffle compile",
"start": "npm run compile && npx truffle exec index.js"
"start": "npm run compile && npx truffle exec index.js --network ropsten"
},

@@ -18,9 +18,5 @@ "keywords": [

"dependencies": {
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"babel-register": "^6.26.0",
"truffle": "^4.1.5",
"openzeppelin-zos": "file:../../../../zeppelin-solidity/openzeppelin-zos-1.9.0-beta.tgz",
"truffle": "^4.1.5"
}
}
{
"name": "zos-lib",
"version": "0.1.2",
"version": "0.1.3",
"description": "zeppelin_os library",

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

@@ -99,5 +99,38 @@ # zeppelin_os library

## <a name="complex"></a> Develop and operate a complex upgradeable app
Note: This shows a low-level manual method of developing a complex upgradeable smart contract application. You probably want to use [the higher-level CLI guide](https://github.com/zeppelinos/zos-cli/blob/master/README.md) instead, but feel free to continue reading if you want to understand the core contracts of `zos-lib`.
Most real-world applications require more than a single smart contract. Here's how to build a complex upgradeable app with multiple smart contracts and connect it to the zOS Kernel standard libraries.
Let's imagine we want to build a simple donation application where we give donors some sort of recognition.
An initial version of the contract can look like so:
```sol
```
We want to use `zos-lib` to deploy this contract with upgradeability capabilities. Given this will probably be a complex application and we'll want to use the zOS Kernel standard libraries, we'll use the `AppManager` programming interface.
The first step to do so is to create and configure the `AppManager` contract. This contract will live in the blockchain and manage the different versions of our smart contract code and upgradeability proxies. It's the single entry point to manage our application's contract's upgradeability and instances. Let's set it up:
```js
```
Next, we need to deploy the first version of the app contracts. To do so, we register the implementation of our `DonationsV1` in the `AppManager` and request it to create a new upgradeable proxy for it. Let's do it:
```js
```
Now let's suppose we want to give some sort of retribution to people donating money to our donation campaign. We want to mint new ERC721 cryptocollectibles for every received donation. To do so, we'll link our application to a zOS Kernel standard library release that contains an implementation of a mintable ERC721 token. Here's the new contract code:
```sol
```
What we need to do next is link our application to the zOS Kernel standard library release containing that mintable ERC721 implementation, and set it to our upgradeable contract. To do so, we create a new version of our application in the `AppManager`, register a new `AppDirectory` containing the new version of our contract implementation, and then set the standard library version of ERC721 to our upgradeable contract. Let's see how:
```js
```
That's it! We now have the same contract, retaining the original balance, and storage, but with an upgraded code. The upgradeable contract is also linked to an on-chain upgradeable standard library containing an implementation of a mintable ERC721 token. State of the art!
## Develop a zOS Kernel standard library release
See [this guide in the zeppelinos/kernel repo](https://github.com/zeppelinos/kernel#developing-kernel-standard-libraries) to learn how to develop new zOS kernel standard library releases.

Sorry, the diff of this file is not supported yet

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