polkamarkets-js 3.4.1 → 3.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/script/AddAdminToLand.s.sol +1 -1
- package/script/ClaimMerkleRoot.s.sol +29 -29
- package/script/CreateLand.s.sol +1 -1
- package/script/DeployMerkleRewardsDistributor.s.sol +21 -21
- package/script/MintTokens.s.sol +1 -1
- package/script/PublishMerkleRoot.s.sol +50 -50
- package/script/UpdateMarket.s.sol +55 -0
- package/script/copy-abis.js +57 -0
- package/src/Application.js +12 -1
- package/src/models/IContract.js +87 -1
- package/src/models/PolkamarketsSmartAccount.js +23 -0
- package/src/models/PredictionMarketV3Contract.js +49 -16
- package/abis/AccessControlUpgradeable.json +0 -1
- package/abis/AddAdminToLand.json +0 -1
- package/abis/AddressUpgradeable.json +0 -1
- package/abis/ClaimMerkleRoot.json +0 -1
- package/abis/CreateLand.json +0 -1
- package/abis/CreateMarkets.json +0 -1
- package/abis/DeployContracts.json +0 -1
- package/abis/DeployMerkleRewardsDistributor.json +0 -1
- package/abis/DeployToken.json +0 -1
- package/abis/DeployUSDT.json +0 -1
- package/abis/ECDSA.json +0 -1
- package/abis/ERC165Upgradeable.json +0 -1
- package/abis/ERC1967UpgradeUpgradeable.json +0 -1
- package/abis/Hashes.json +0 -1
- package/abis/IBeaconUpgradeable.json +0 -1
- package/abis/IERC1822ProxiableUpgradeable.json +0 -1
- package/abis/IERC20PermitUpgradeable.json +0 -1
- package/abis/IERC20Upgradeable.json +0 -1
- package/abis/Manager.json +0 -1
- package/abis/MerkleProof.json +0 -1
- package/abis/MerkleRewardsDistributor.json +0 -1
- package/abis/MerkleRewardsDistributorTest.json +0 -1
- package/abis/MessageHashUtils.json +0 -1
- package/abis/MintTokens.json +0 -1
- package/abis/Nonces.json +0 -1
- package/abis/Panic.json +0 -1
- package/abis/PublishMerkleRoot.json +0 -1
- package/abis/ResolveMarket.json +0 -1
- package/abis/RewardsDistributor.json +0 -1
- package/abis/RewardsDistributorTest.json +0 -1
- package/abis/SafeCast.json +0 -1
- package/abis/SafeERC20Upgradeable.json +0 -1
- package/abis/SignedMath.json +0 -1
- package/abis/StorageSlotUpgradeable.json +0 -1
- package/abis/TradeMarket.json +0 -1
- package/abis/USDT.json +0 -1
- package/abis/UpdateMarket.json +0 -1
- package/abis/UpdateTest.json +0 -1
- package/abis/WhaleTest.json +0 -1
- package/lib/openzeppelin-contracts/contracts/mocks/docs/ERC20WithAutoMinerReward.sol +0 -22
- package/lib/openzeppelin-contracts/contracts/mocks/docs/ERC4626Fees.sol +0 -109
- package/lib/openzeppelin-contracts/contracts/mocks/docs/MyNFT.sol +0 -9
- package/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlERC20MintBase.sol +0 -25
- package/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlERC20MintMissing.sol +0 -24
- package/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlERC20MintOnlyRole.sol +0 -23
- package/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlModified.sol +0 -14
- package/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessManagedERC20MintBase.sol +0 -16
- package/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/MyContractOwnable.sol +0 -17
- package/lib/openzeppelin-contracts/contracts/mocks/docs/account/MyAccountERC7702.sol +0 -20
- package/lib/openzeppelin-contracts/contracts/mocks/docs/account/MyFactoryAccount.sol +0 -37
- package/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyGovernor.sol +0 -80
- package/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyToken.sol +0 -21
- package/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyTokenTimestampBased.sol +0 -32
- package/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyTokenWrapped.sol +0 -28
- package/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC1155/GameItems.sol +0 -21
- package/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC1155/MyERC115HolderContract.sol +0 -7
- package/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC20/GLDToken.sol +0 -11
- package/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC6909/ERC6909GameItems.sol +0 -26
- package/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC721/GameItem.sol +0 -19
- package/lib/openzeppelin-contracts/contracts/mocks/docs/utilities/Base64NFT.sol +0 -27
- package/lib/openzeppelin-contracts/contracts/mocks/docs/utilities/Multicall.sol +0 -15
- package/lib/openzeppelin-contracts/docs/README.md +0 -16
- package/lib/openzeppelin-contracts/docs/antora.yml +0 -7
- package/lib/openzeppelin-contracts/docs/config.js +0 -21
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/access-control-multiple.svg +0 -97
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/access-manager-functions.svg +0 -47
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/access-manager.svg +0 -99
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack-3a.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack-3b.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack-6.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-deposit.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-mint.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-rate-linear.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-rate-loglog.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-rate-loglogext.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/tally-exec.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/images/tally-vote.png +0 -0
- package/lib/openzeppelin-contracts/docs/modules/ROOT/nav.adoc +0 -29
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/access-control.adoc +0 -288
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/account-abstraction.adoc +0 -100
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/accounts.adoc +0 -354
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/backwards-compatibility.adoc +0 -50
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/eoa-delegation.adoc +0 -143
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc1155.adoc +0 -118
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc20-supply.adoc +0 -71
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc20.adoc +0 -67
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc4626.adoc +0 -214
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc6909.adoc +0 -47
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc721.adoc +0 -58
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/extending-contracts.adoc +0 -51
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/faq.adoc +0 -13
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/governance.adoc +0 -239
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/index.adoc +0 -70
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/multisig.adoc +0 -306
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/tokens.adoc +0 -31
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/upgradeable.adoc +0 -77
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/utilities.adoc +0 -591
- package/lib/openzeppelin-contracts/docs/modules/ROOT/pages/wizard.adoc +0 -15
- package/lib/openzeppelin-contracts/docs/templates/contract.hbs +0 -141
- package/lib/openzeppelin-contracts/docs/templates/helpers.js +0 -46
- package/lib/openzeppelin-contracts/docs/templates/page.hbs +0 -4
- package/lib/openzeppelin-contracts/docs/templates/properties.js +0 -88
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/ERC20WithAutoMinerRewardUpgradeable.sol +0 -28
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/ERC4626FeesUpgradeable.sol +0 -115
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/MyNFTUpgradeable.sol +0 -14
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/access-control/AccessControlERC20MintBaseUpgradeable.sol +0 -31
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/access-control/AccessControlERC20MintMissingUpgradeable.sol +0 -30
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/access-control/AccessControlERC20MintOnlyRoleUpgradeable.sol +0 -29
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/access-control/AccessControlModifiedUpgradeable.sol +0 -20
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/access-control/AccessManagedERC20MintBaseUpgradeable.sol +0 -22
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/access-control/MyContractOwnableUpgradeable.sol +0 -22
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/account/MyAccountERC7702Upgradeable.sol +0 -26
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/account/MyFactoryAccountUpgradeable.sol +0 -42
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/governance/MyGovernorUpgradeable.sol +0 -92
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/governance/MyTokenTimestampBasedUpgradeable.sol +0 -39
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/governance/MyTokenUpgradeable.sol +0 -28
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/governance/MyTokenWrappedUpgradeable.sol +0 -39
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/token/ERC1155/GameItemsUpgradeable.sol +0 -27
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/token/ERC1155/MyERC115HolderContractUpgradeable.sol +0 -13
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/token/ERC20/GLDTokenUpgradeable.sol +0 -17
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/token/ERC6909/ERC6909GameItemsUpgradeable.sol +0 -31
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/token/ERC721/GameItemUpgradeable.sol +0 -24
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/utilities/Base64NFTUpgradeable.sol +0 -32
- package/lib/openzeppelin-contracts-upgradeable/contracts/mocks/docs/utilities/MulticallUpgradeable.sol +0 -21
- package/lib/openzeppelin-contracts-upgradeable/docs/README.md +0 -16
- package/lib/openzeppelin-contracts-upgradeable/docs/antora.yml +0 -7
- package/lib/openzeppelin-contracts-upgradeable/docs/config.js +0 -21
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/access-control-multiple.svg +0 -97
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/access-manager-functions.svg +0 -47
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/access-manager.svg +0 -99
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-attack-3a.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-attack-3b.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-attack-6.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-attack.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-deposit.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-mint.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-rate-linear.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-rate-loglog.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/erc4626-rate-loglogext.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/tally-exec.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/images/tally-vote.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/nav.adoc +0 -29
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/access-control.adoc +0 -288
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/account-abstraction.adoc +0 -100
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/accounts.adoc +0 -354
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/backwards-compatibility.adoc +0 -50
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/eoa-delegation.adoc +0 -143
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/erc1155.adoc +0 -118
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/erc20-supply.adoc +0 -71
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/erc20.adoc +0 -67
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/erc4626.adoc +0 -214
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/erc6909.adoc +0 -47
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/erc721.adoc +0 -58
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/extending-contracts.adoc +0 -51
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/faq.adoc +0 -13
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/governance.adoc +0 -239
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/index.adoc +0 -70
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/multisig.adoc +0 -306
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/tokens.adoc +0 -31
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/upgradeable.adoc +0 -77
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/utilities.adoc +0 -591
- package/lib/openzeppelin-contracts-upgradeable/docs/modules/ROOT/pages/wizard.adoc +0 -15
- package/lib/openzeppelin-contracts-upgradeable/docs/templates/contract.hbs +0 -141
- package/lib/openzeppelin-contracts-upgradeable/docs/templates/helpers.js +0 -46
- package/lib/openzeppelin-contracts-upgradeable/docs/templates/page.hbs +0 -4
- package/lib/openzeppelin-contracts-upgradeable/docs/templates/properties.js +0 -88
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/ERC20WithAutoMinerReward.sol +0 -22
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/ERC4626Fees.sol +0 -109
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/MyNFT.sol +0 -9
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlERC20MintBase.sol +0 -25
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlERC20MintMissing.sol +0 -24
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlERC20MintOnlyRole.sol +0 -23
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessControlModified.sol +0 -14
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/AccessManagedERC20MintBase.sol +0 -16
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/access-control/MyContractOwnable.sol +0 -17
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/account/MyAccountERC7702.sol +0 -20
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/account/MyFactoryAccount.sol +0 -37
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyGovernor.sol +0 -80
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyToken.sol +0 -21
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyTokenTimestampBased.sol +0 -32
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/governance/MyTokenWrapped.sol +0 -28
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC1155/GameItems.sol +0 -21
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC1155/MyERC115HolderContract.sol +0 -7
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC20/GLDToken.sol +0 -11
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC6909/ERC6909GameItems.sol +0 -26
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/token/ERC721/GameItem.sol +0 -19
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/utilities/Base64NFT.sol +0 -27
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/mocks/docs/utilities/Multicall.sol +0 -15
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/README.md +0 -16
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/antora.yml +0 -7
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/config.js +0 -21
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/access-control-multiple.svg +0 -97
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/access-manager-functions.svg +0 -47
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/access-manager.svg +0 -99
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack-3a.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack-3b.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack-6.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-attack.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-deposit.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-mint.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-rate-linear.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-rate-loglog.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/erc4626-rate-loglogext.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/tally-exec.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/images/tally-vote.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/nav.adoc +0 -29
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/access-control.adoc +0 -288
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/account-abstraction.adoc +0 -100
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/accounts.adoc +0 -354
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/backwards-compatibility.adoc +0 -50
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/eoa-delegation.adoc +0 -143
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc1155.adoc +0 -118
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc20-supply.adoc +0 -71
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc20.adoc +0 -67
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc4626.adoc +0 -214
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc6909.adoc +0 -47
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/erc721.adoc +0 -58
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/extending-contracts.adoc +0 -51
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/faq.adoc +0 -13
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/governance.adoc +0 -239
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/index.adoc +0 -70
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/multisig.adoc +0 -306
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/tokens.adoc +0 -31
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/upgradeable.adoc +0 -77
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/utilities.adoc +0 -591
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/modules/ROOT/pages/wizard.adoc +0 -15
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/templates/contract.hbs +0 -141
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/templates/helpers.js +0 -46
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/templates/page.hbs +0 -4
- package/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/docs/templates/properties.js +0 -88
- package/lib/openzeppelin-contracts-upgradeable.git/docs/antora.yml +0 -6
- package/lib/openzeppelin-contracts-upgradeable.git/docs/config.js +0 -21
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/images/tally-exec.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/images/tally-vote.png +0 -0
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/nav.adoc +0 -23
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/access-control.adoc +0 -217
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/crosschain.adoc +0 -210
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/crowdsales.adoc +0 -11
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/drafts.adoc +0 -19
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/erc1155.adoc +0 -153
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/erc20-supply.adoc +0 -113
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/erc20.adoc +0 -85
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/erc721.adoc +0 -90
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/erc777.adoc +0 -73
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/extending-contracts.adoc +0 -129
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/governance.adoc +0 -321
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/index.adoc +0 -63
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/releases-stability.adoc +0 -85
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/tokens.adoc +0 -32
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/upgradeable.adoc +0 -73
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/utilities.adoc +0 -190
- package/lib/openzeppelin-contracts-upgradeable.git/docs/modules/ROOT/pages/wizard.adoc +0 -15
- package/lib/openzeppelin-contracts-upgradeable.git/docs/templates/contract.hbs +0 -85
- package/lib/openzeppelin-contracts-upgradeable.git/docs/templates/helpers.js +0 -46
- package/lib/openzeppelin-contracts-upgradeable.git/docs/templates/page.hbs +0 -4
- package/lib/openzeppelin-contracts-upgradeable.git/docs/templates/properties.js +0 -49
- package/lib/openzeppelin-contracts.git/docs/antora.yml +0 -6
- package/lib/openzeppelin-contracts.git/docs/config.js +0 -21
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/images/tally-exec.png +0 -0
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/images/tally-vote.png +0 -0
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/nav.adoc +0 -23
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/access-control.adoc +0 -217
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/crosschain.adoc +0 -210
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/crowdsales.adoc +0 -11
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/drafts.adoc +0 -19
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/erc1155.adoc +0 -153
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/erc20-supply.adoc +0 -113
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/erc20.adoc +0 -85
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/erc721.adoc +0 -90
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/erc777.adoc +0 -73
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/extending-contracts.adoc +0 -129
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/governance.adoc +0 -321
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/index.adoc +0 -63
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/releases-stability.adoc +0 -85
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/tokens.adoc +0 -32
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/upgradeable.adoc +0 -73
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/utilities.adoc +0 -190
- package/lib/openzeppelin-contracts.git/docs/modules/ROOT/pages/wizard.adoc +0 -15
- package/lib/openzeppelin-contracts.git/docs/templates/contract.hbs +0 -85
- package/lib/openzeppelin-contracts.git/docs/templates/helpers.js +0 -46
- package/lib/openzeppelin-contracts.git/docs/templates/page.hbs +0 -4
- package/lib/openzeppelin-contracts.git/docs/templates/properties.js +0 -49
- package/lib/reality-eth-monorepo/packages/docs/Audit_Reality_v3_202108.pdf +0 -0
- package/lib/reality-eth-monorepo/packages/docs/Makefile +0 -20
- package/lib/reality-eth-monorepo/packages/docs/arbitrators.rst +0 -85
- package/lib/reality-eth-monorepo/packages/docs/audit.rst +0 -12
- package/lib/reality-eth-monorepo/packages/docs/audit_v2.rst +0 -249
- package/lib/reality-eth-monorepo/packages/docs/audit_v2_ERC20.rst +0 -1075
- package/lib/reality-eth-monorepo/packages/docs/audit_v3.rst +0 -70
- package/lib/reality-eth-monorepo/packages/docs/conf.py +0 -155
- package/lib/reality-eth-monorepo/packages/docs/contract_explanation.rst +0 -82
- package/lib/reality-eth-monorepo/packages/docs/contracts.rst +0 -277
- package/lib/reality-eth-monorepo/packages/docs/dapp.rst +0 -126
- package/lib/reality-eth-monorepo/packages/docs/dapp_links.rst +0 -67
- package/lib/reality-eth-monorepo/packages/docs/fees.rst +0 -89
- package/lib/reality-eth-monorepo/packages/docs/index.rst +0 -26
- package/lib/reality-eth-monorepo/packages/docs/javascript.rst +0 -142
- package/lib/reality-eth-monorepo/packages/docs/make.bat +0 -36
- package/lib/reality-eth-monorepo/packages/docs/question_box.png +0 -0
- package/lib/reality-eth-monorepo/packages/docs/requirements.txt +0 -24
- package/lib/reality-eth-monorepo/packages/docs/whitepaper.rst +0 -165
- package/test/UpdateTest.t.sol +0 -55
- package/test/WhaleTest.t.sol +0 -188
- package/tooling/docs/jsdoc.json +0 -6
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
= How to set up on-chain governance
|
|
2
|
-
|
|
3
|
-
In this guide we will learn how OpenZeppelin’s Governor contract works, how to set it up, and how to use it to create proposals, vote for them, and execute them, using tools provided by Ethers.js and Tally.
|
|
4
|
-
|
|
5
|
-
NOTE: Find detailed contract documentation at xref:api:governance.adoc[Governance API].
|
|
6
|
-
|
|
7
|
-
== Introduction
|
|
8
|
-
|
|
9
|
-
Decentralized protocols are in constant evolution from the moment they are publicly released. Often, the initial team retains control of this evolution in the first stages, but eventually delegates it to a community of stakeholders. The process by which this community makes decisions is called on-chain governance, and it has become a central component of decentralized protocols, fueling varied decisions such as parameter tweaking, smart contract upgrades, integrations with other protocols, treasury management, grants, etc.
|
|
10
|
-
|
|
11
|
-
This governance protocol is generally implemented in a special-purpose contract called “Governor”. The GovernorAlpha and GovernorBravo contracts designed by Compound have been very successful and popular so far, with the downside that projects with different requirements have had to fork the code to customize it for their needs, which can pose a high risk of introducing security issues. For OpenZeppelin Contracts, we set out to build a modular system of Governor contracts so that forking is not needed, and different requirements can be accommodated by writing small modules using Solidity inheritance. You will find the most common requirements out of the box in OpenZeppelin Contracts, but writing additional ones is simple, and we will be adding new features as requested by the community in future releases. Additionally, the design of OpenZeppelin Governor requires minimal use of storage and results in more gas efficient operation.
|
|
12
|
-
|
|
13
|
-
== Compatibility
|
|
14
|
-
|
|
15
|
-
OpenZeppelin’s Governor system was designed with a concern for compatibility with existing systems that were based on Compound’s GovernorAlpha and GovernorBravo. Because of this, you will find that many modules are presented in two variants, one of which is built for compatibility with those systems.
|
|
16
|
-
|
|
17
|
-
=== ERC20Votes & ERC20VotesComp
|
|
18
|
-
|
|
19
|
-
The ERC20 extension to keep track of votes and vote delegation is one such case. The shorter one is the more generic version because it can support token supplies greater than 2^96, while the “Comp” variant is limited in that regard, but exactly fits the interface of the COMP token that is used by GovernorAlpha and Bravo. Both contract variants share the same events, so they are fully compatible when looking at events only.
|
|
20
|
-
|
|
21
|
-
=== Governor & GovernorCompatibilityBravo
|
|
22
|
-
|
|
23
|
-
An OpenZeppelin Governor contract is by default not interface-compatible with GovernorAlpha or Bravo, since some of the functions are different or missing, although it shares all of the same events. However, it’s possible to opt in to full compatibility by inheriting from the GovernorCompatibilityBravo module. The contract will be cheaper to deploy and use without this module.
|
|
24
|
-
|
|
25
|
-
=== GovernorTimelockControl & GovernorTimelockCompound
|
|
26
|
-
|
|
27
|
-
When using a timelock with your Governor contract, you can use either OpenZeppelin’s TimelockController or Compound’s Timelock. Based on the choice of timelock, you should choose the corresponding Governor module: GovernorTimelockControl or GovernorTimelockCompound respectively. This allows you to migrate an existing GovernorAlpha instance to an OpenZeppelin-based Governor without changing the timelock in use.
|
|
28
|
-
|
|
29
|
-
=== Tally
|
|
30
|
-
|
|
31
|
-
https://www.tally.xyz[Tally] is a full-fledged application for user owned on-chain governance. It comprises a voting dashboard, proposal creation wizard, real time research and analysis, and educational content.
|
|
32
|
-
|
|
33
|
-
For all of these options, the Governor will be compatible with Tally: users will be able to create proposals, visualize voting power and advocates, navigate proposals, and cast votes. For proposal creation in particular, projects can also use Defender Admin as an alternative interface.
|
|
34
|
-
|
|
35
|
-
In the rest of this guide, we will focus on a fresh deploy of the vanilla OpenZeppelin Governor features without concern for compatibility with GovernorAlpha or Bravo.
|
|
36
|
-
|
|
37
|
-
== Setup
|
|
38
|
-
|
|
39
|
-
=== Token
|
|
40
|
-
|
|
41
|
-
The voting power of each account in our governance setup will be determined by an ERC20 token. The token has to implement the ERC20Votes extension. This extension will keep track of historical balances so that voting power is retrieved from past snapshots rather than current balance, which is an important protection that prevents double voting.
|
|
42
|
-
|
|
43
|
-
```solidity
|
|
44
|
-
// SPDX-License-Identifier: MIT
|
|
45
|
-
pragma solidity ^0.8.2;
|
|
46
|
-
|
|
47
|
-
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
48
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
|
|
49
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
|
|
50
|
-
|
|
51
|
-
contract MyToken is ERC20, ERC20Permit, ERC20Votes {
|
|
52
|
-
constructor() ERC20("MyToken", "MTK") ERC20Permit("MyToken") {}
|
|
53
|
-
|
|
54
|
-
// The functions below are overrides required by Solidity.
|
|
55
|
-
|
|
56
|
-
function _afterTokenTransfer(address from, address to, uint256 amount)
|
|
57
|
-
internal
|
|
58
|
-
override(ERC20, ERC20Votes)
|
|
59
|
-
{
|
|
60
|
-
super._afterTokenTransfer(from, to, amount);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function _mint(address to, uint256 amount)
|
|
64
|
-
internal
|
|
65
|
-
override(ERC20, ERC20Votes)
|
|
66
|
-
{
|
|
67
|
-
super._mint(to, amount);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function _burn(address account, uint256 amount)
|
|
71
|
-
internal
|
|
72
|
-
override(ERC20, ERC20Votes)
|
|
73
|
-
{
|
|
74
|
-
super._burn(account, amount);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
If your project already has a live token that does not include ERC20Votes and is not upgradeable, you can wrap it in a governance token by using ERC20Wrapper. This will allow token holders to participate in governance by wrapping their tokens 1-to-1.
|
|
80
|
-
|
|
81
|
-
```solidity
|
|
82
|
-
// SPDX-License-Identifier: MIT
|
|
83
|
-
pragma solidity ^0.8.2;
|
|
84
|
-
|
|
85
|
-
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
86
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
|
|
87
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
|
|
88
|
-
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
|
|
89
|
-
|
|
90
|
-
contract MyToken is ERC20, ERC20Permit, ERC20Votes, ERC20Wrapper {
|
|
91
|
-
constructor(IERC20 wrappedToken)
|
|
92
|
-
ERC20("MyToken", "MTK")
|
|
93
|
-
ERC20Permit("MyToken")
|
|
94
|
-
ERC20Wrapper(wrappedToken)
|
|
95
|
-
{}
|
|
96
|
-
|
|
97
|
-
// The functions below are overrides required by Solidity.
|
|
98
|
-
|
|
99
|
-
function _afterTokenTransfer(address from, address to, uint256 amount)
|
|
100
|
-
internal
|
|
101
|
-
override(ERC20, ERC20Votes)
|
|
102
|
-
{
|
|
103
|
-
super._afterTokenTransfer(from, to, amount);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function _mint(address to, uint256 amount)
|
|
107
|
-
internal
|
|
108
|
-
override(ERC20, ERC20Votes)
|
|
109
|
-
{
|
|
110
|
-
super._mint(to, amount);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function _burn(address account, uint256 amount)
|
|
114
|
-
internal
|
|
115
|
-
override(ERC20, ERC20Votes)
|
|
116
|
-
{
|
|
117
|
-
super._burn(account, amount);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
NOTE: Voting power could be determined in different ways: multiple ERC20 tokens, ERC721 tokens, sybil resistant identities, etc. All of these options are potentially supported by writing a custom Votes module for your Governor. The only other source of voting power available in OpenZeppelin Contracts currently is xref:api:token/ERC721.adoc#ERC721Votes[`ERC721Votes`].
|
|
123
|
-
|
|
124
|
-
=== Governor
|
|
125
|
-
|
|
126
|
-
Initially, we will build a Governor without a timelock. The core logic is given by the Governor contract, but we still need to choose: 1) how voting power is determined, 2) how many votes are needed for quorum, 3) what options people have when casting a vote and how those votes are counted, and 4) what type of token should be used to vote. Each of these aspects is customizable by writing your own module, or more easily choosing one from OpenZeppelin Contracts.
|
|
127
|
-
|
|
128
|
-
For 1) we will use the GovernorVotes module, which hooks to an IVotes instance to determine the voting power of an account based on the token balance they hold when a proposal becomes active. This module requires as a constructor parameter the address of the token.
|
|
129
|
-
|
|
130
|
-
For 2) we will use GovernorVotesQuorumFraction which works together with ERC20Votes to define quorum as a percentage of the total supply at the block a proposal’s voting power is retrieved. This requires a constructor parameter to set the percentage. Most Governors nowadays use 4%, so we will initialize the module with parameter 4 (this indicates the percentage, resulting in 4%).
|
|
131
|
-
|
|
132
|
-
For 3) we will use GovernorCountingSimple, a module that offers 3 options to voters: For, Against, and Abstain, and where only For and Abstain votes are counted towards quorum.
|
|
133
|
-
|
|
134
|
-
Besides these modules, Governor itself has some parameters we must set.
|
|
135
|
-
|
|
136
|
-
votingDelay: How long after a proposal is created should voting power be fixed. A large voting delay gives users time to unstake tokens if necessary.
|
|
137
|
-
|
|
138
|
-
votingPeriod: How long does a proposal remain open to votes.
|
|
139
|
-
|
|
140
|
-
These parameters are specified in number of blocks. Assuming block time of around 13.14 seconds, we will set votingDelay = 1 day = 6570 blocks, and votingPeriod = 1 week = 45992 blocks.
|
|
141
|
-
|
|
142
|
-
We can optionally set a proposal threshold as well. This restricts proposal creation to accounts who have enough voting power.
|
|
143
|
-
|
|
144
|
-
```solidity
|
|
145
|
-
// SPDX-License-Identifier: MIT
|
|
146
|
-
pragma solidity ^0.8.2;
|
|
147
|
-
|
|
148
|
-
import "@openzeppelin/contracts/governance/Governor.sol";
|
|
149
|
-
import "@openzeppelin/contracts/governance/compatibility/GovernorCompatibilityBravo.sol";
|
|
150
|
-
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
|
|
151
|
-
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
|
|
152
|
-
import "@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";
|
|
153
|
-
|
|
154
|
-
contract MyGovernor is Governor, GovernorCompatibilityBravo, GovernorVotes, GovernorVotesQuorumFraction, GovernorTimelockControl {
|
|
155
|
-
constructor(IVotes _token, TimelockController _timelock)
|
|
156
|
-
Governor("MyGovernor")
|
|
157
|
-
GovernorVotes(_token)
|
|
158
|
-
GovernorVotesQuorumFraction(4)
|
|
159
|
-
GovernorTimelockControl(_timelock)
|
|
160
|
-
{}
|
|
161
|
-
|
|
162
|
-
function votingDelay() public pure override returns (uint256) {
|
|
163
|
-
return 6575; // 1 day
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function votingPeriod() public pure override returns (uint256) {
|
|
167
|
-
return 46027; // 1 week
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function proposalThreshold() public pure override returns (uint256) {
|
|
171
|
-
return 0;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// The functions below are overrides required by Solidity.
|
|
175
|
-
|
|
176
|
-
function state(uint256 proposalId)
|
|
177
|
-
public
|
|
178
|
-
view
|
|
179
|
-
override(Governor, IGovernor, GovernorTimelockControl)
|
|
180
|
-
returns (ProposalState)
|
|
181
|
-
{
|
|
182
|
-
return super.state(proposalId);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
|
|
186
|
-
public
|
|
187
|
-
override(Governor, GovernorCompatibilityBravo, IGovernor)
|
|
188
|
-
returns (uint256)
|
|
189
|
-
{
|
|
190
|
-
return super.propose(targets, values, calldatas, description);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function _execute(uint256 proposalId, address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
|
|
194
|
-
internal
|
|
195
|
-
override(Governor, GovernorTimelockControl)
|
|
196
|
-
{
|
|
197
|
-
super._execute(proposalId, targets, values, calldatas, descriptionHash);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function _cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
|
|
201
|
-
internal
|
|
202
|
-
override(Governor, GovernorTimelockControl)
|
|
203
|
-
returns (uint256)
|
|
204
|
-
{
|
|
205
|
-
return super._cancel(targets, values, calldatas, descriptionHash);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function _executor()
|
|
209
|
-
internal
|
|
210
|
-
view
|
|
211
|
-
override(Governor, GovernorTimelockControl)
|
|
212
|
-
returns (address)
|
|
213
|
-
{
|
|
214
|
-
return super._executor();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function supportsInterface(bytes4 interfaceId)
|
|
218
|
-
public
|
|
219
|
-
view
|
|
220
|
-
override(Governor, IERC165, GovernorTimelockControl)
|
|
221
|
-
returns (bool)
|
|
222
|
-
{
|
|
223
|
-
return super.supportsInterface(interfaceId);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
=== Timelock
|
|
230
|
-
|
|
231
|
-
It is good practice to add a timelock to governance decisions. This allows users to exit the system if they disagree with a decision before it is executed. We will use OpenZeppelin’s TimelockController in combination with the GovernorTimelockControl module.
|
|
232
|
-
|
|
233
|
-
IMPORTANT: When using a timelock, it is the timelock that will execute proposals and thus the timelock that should hold any funds, ownership, and access control roles. Before version 4.5 there was no way to recover funds in the Governor contract when using a timelock! Before version 4.3, when using the Compound Timelock, ETH in the timelock was not easily accessible.
|
|
234
|
-
|
|
235
|
-
TimelockController uses an AccessControl setup that we need to understand in order to set up roles.
|
|
236
|
-
|
|
237
|
-
- The Proposer role is in charge of queueing operations: this is the role the Governor instance should be granted, and it should likely be the only proposer in the system.
|
|
238
|
-
- The Executor role is in charge of executing already available operations: we can assign this role to the special zero address to allow anyone to execute (if operations can be particularly time sensitive, the Governor should be made Executor instead).
|
|
239
|
-
- Lastly, there is the Admin role, which can grant and revoke the two previous roles: this is a very sensitive role that will be granted automatically to the timelock itself, and optionally to a second account, which can be used for ease of setup but should promptly renounce the role.
|
|
240
|
-
|
|
241
|
-
== Proposal Lifecycle
|
|
242
|
-
|
|
243
|
-
Let’s walk through how to create and execute a proposal on our newly deployed Governor.
|
|
244
|
-
|
|
245
|
-
A proposal is a sequence of actions that the Governor contract will perform if it passes. Each action consists of a target address, calldata encoding a function call, and an amount of ETH to include. Additionally, a proposal includes a human-readable description.
|
|
246
|
-
|
|
247
|
-
=== Create a Proposal
|
|
248
|
-
|
|
249
|
-
Let’s say we want to create a proposal to give a team a grant, in the form of ERC20 tokens from the governance treasury. This proposal will consist of a single action where the target is the ERC20 token, calldata is the encoded function call `transfer(<team wallet>, <grant amount>)`, and with 0 ETH attached.
|
|
250
|
-
|
|
251
|
-
Generally a proposal will be created with the help of an interface such as Tally or Defender. Here we will show how to create the proposal using Ethers.js.
|
|
252
|
-
|
|
253
|
-
First we get all the parameters necessary for the proposal action.
|
|
254
|
-
|
|
255
|
-
```javascript
|
|
256
|
-
const tokenAddress = ...;
|
|
257
|
-
const token = await ethers.getContractAt(‘ERC20’, tokenAddress);
|
|
258
|
-
|
|
259
|
-
const teamAddress = ...;
|
|
260
|
-
const grantAmount = ...;
|
|
261
|
-
const transferCalldata = token.interface.encodeFunctionData(‘transfer’, [teamAddress, grantAmount]);
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Now we are ready to call the propose function of the governor. Note that we don’t pass in one array of actions, but instead three arrays corresponding to the list of targets, the list of values, and the list of calldatas. In this case it’s a single action, so it’s simple:
|
|
265
|
-
|
|
266
|
-
```javascript
|
|
267
|
-
await governor.propose(
|
|
268
|
-
[tokenAddress],
|
|
269
|
-
[0],
|
|
270
|
-
[transferCalldata],
|
|
271
|
-
“Proposal #1: Give grant to team”,
|
|
272
|
-
);
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
This will create a new proposal, with a proposal id that is obtained by hashing together the proposal data, and which will also be found in an event in the logs of the transaction.
|
|
276
|
-
|
|
277
|
-
=== Cast a Vote
|
|
278
|
-
|
|
279
|
-
Once a proposal is active, delegates can cast their vote. Note that it is delegates who carry voting power: if a token holder wants to participate, they can set a trusted representative as their delegate, or they can become a delegate themselves by self-delegating their voting power.
|
|
280
|
-
|
|
281
|
-
Votes are cast by interacting with the Governor contract through the `castVote` family of functions. Voters would generally invoke this from a governance UI such as Tally.
|
|
282
|
-
|
|
283
|
-
image::tally-vote.png[Voting in Tally]
|
|
284
|
-
|
|
285
|
-
=== Execute the Proposal
|
|
286
|
-
|
|
287
|
-
Once the voting period is over, if quorum was reached (enough voting power participated) and the majority voted in favor, the proposal is considered successful and can proceed to be executed. Once a proposal passes, it can be queued and executed from the same place you voted.
|
|
288
|
-
|
|
289
|
-
image::tally-exec.png[Administration Panel in Tally]
|
|
290
|
-
|
|
291
|
-
We will see now how to do this manually using Ethers.js.
|
|
292
|
-
|
|
293
|
-
If a timelock was set up, the first step to execution is queueing. You will notice that both the queue and execute functions require passing in the entire proposal parameters, as opposed to just the proposal id. This is necessary because this data is not stored on chain, as a measure to save gas. Note that these parameters can always be found in the events emitted by the contract. The only parameter that is not sent in its entirety is the description, since this is only needed in its hashed form to compute the proposal id.
|
|
294
|
-
|
|
295
|
-
To queue, we call the queue function:
|
|
296
|
-
|
|
297
|
-
```javascript
|
|
298
|
-
const descriptionHash = ethers.utils.id(“Proposal #1: Give grant to team”);
|
|
299
|
-
|
|
300
|
-
await governor.queue(
|
|
301
|
-
[tokenAddress],
|
|
302
|
-
[0],
|
|
303
|
-
[transferCalldata],
|
|
304
|
-
descriptionHash,
|
|
305
|
-
);
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
This will cause the governor to interact with the timelock contract and queue the actions for execution after the required delay.
|
|
309
|
-
|
|
310
|
-
After enough time has passed (according to the timelock parameters), the proposal can be executed. If there was no timelock to begin with, this step can be ran immediately after the proposal succeeds.
|
|
311
|
-
|
|
312
|
-
```javascript
|
|
313
|
-
await governor.execute(
|
|
314
|
-
[tokenAddress],
|
|
315
|
-
[0],
|
|
316
|
-
[transferCalldata],
|
|
317
|
-
descriptionHash,
|
|
318
|
-
);
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
Executing the proposal will transfer the ERC20 tokens to the chosen recipient. To wrap up: we set up a system where a treasury is controlled by the collective decision of the token holders of a project, and all actions are executed via proposals enforced by on-chain votes.
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
= Contracts
|
|
2
|
-
|
|
3
|
-
*A library for secure smart contract development.* Build on a solid foundation of community-vetted code.
|
|
4
|
-
|
|
5
|
-
* Implementations of standards like xref:erc20.adoc[ERC20] and xref:erc721.adoc[ERC721].
|
|
6
|
-
* Flexible xref:access-control.adoc[role-based permissioning] scheme.
|
|
7
|
-
* Reusable xref:utilities.adoc[Solidity components] to build custom contracts and complex decentralized systems.
|
|
8
|
-
|
|
9
|
-
== Overview
|
|
10
|
-
|
|
11
|
-
[[install]]
|
|
12
|
-
=== Installation
|
|
13
|
-
|
|
14
|
-
```console
|
|
15
|
-
$ npm install @openzeppelin/contracts
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
OpenZeppelin Contracts features a xref:releases-stability.adoc#api-stability[stable API], which means your contracts won't break unexpectedly when upgrading to a newer minor version.
|
|
19
|
-
|
|
20
|
-
[[usage]]
|
|
21
|
-
=== Usage
|
|
22
|
-
|
|
23
|
-
Once installed, you can use the contracts in the library by importing them:
|
|
24
|
-
|
|
25
|
-
[source,solidity]
|
|
26
|
-
----
|
|
27
|
-
// contracts/MyNFT.sol
|
|
28
|
-
// SPDX-License-Identifier: MIT
|
|
29
|
-
pragma solidity ^0.8.0;
|
|
30
|
-
|
|
31
|
-
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
|
32
|
-
|
|
33
|
-
contract MyNFT is ERC721 {
|
|
34
|
-
constructor() ERC721("MyNFT", "MNFT") {
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
----
|
|
38
|
-
|
|
39
|
-
TIP: If you're new to smart contract development, head to xref:learn::developing-smart-contracts.adoc[Developing Smart Contracts] to learn about creating a new project and compiling your contracts.
|
|
40
|
-
|
|
41
|
-
To keep your system secure, you should **always** use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.
|
|
42
|
-
|
|
43
|
-
[[security]]
|
|
44
|
-
== Security
|
|
45
|
-
|
|
46
|
-
Please report any security issues you find via our https://www.immunefi.com/bounty/openzeppelin[bug bounty program on Immunefi] or directly to security@openzeppelin.org.
|
|
47
|
-
|
|
48
|
-
[[next-steps]]
|
|
49
|
-
== Learn More
|
|
50
|
-
|
|
51
|
-
The guides in the sidebar will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:
|
|
52
|
-
|
|
53
|
-
* xref:access-control.adoc[Access Control]: decide who can perform each of the actions on your system.
|
|
54
|
-
* xref:tokens.adoc[Tokens]: create tradable assets or collectibles, like the well known xref:erc20.adoc[ERC20] and xref:erc721.adoc[ERC721] standards.
|
|
55
|
-
* xref:utilities.adoc[Utilities]: generic useful tools, including non-overflowing math, signature verification, and trustless paying systems.
|
|
56
|
-
|
|
57
|
-
The xref:api:token/ERC20.adoc[full API] is also thoroughly documented, and serves as a great reference when developing your smart contract application. You can also ask for help or follow Contracts' development in the https://forum.openzeppelin.com[community forum].
|
|
58
|
-
|
|
59
|
-
Finally, you may want to take a look at the https://blog.openzeppelin.com/guides/[guides on our blog], which cover several common use cases and good practices. The following articles provide great background reading, though please note, some of the referenced tools have changed as the tooling in the ecosystem continues to rapidly evolve.
|
|
60
|
-
|
|
61
|
-
* https://blog.openzeppelin.com/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05[The Hitchhiker’s Guide to Smart Contracts in Ethereum] will help you get an overview of the various tools available for smart contract development, and help you set up your environment.
|
|
62
|
-
* https://blog.openzeppelin.com/a-gentle-introduction-to-ethereum-programming-part-1-783cc7796094[A Gentle Introduction to Ethereum Programming, Part 1] provides very useful information on an introductory level, including many basic concepts from the Ethereum platform.
|
|
63
|
-
* For a more in-depth dive, you may read the guide https://blog.openzeppelin.com/designing-the-architecture-for-your-ethereum-application-9cec086f8317[Designing the architecture for your Ethereum application], which discusses how to better structure your application and its relationship to the real world.
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
= New Releases and API Stability
|
|
2
|
-
|
|
3
|
-
Developing smart contracts is hard, and a conservative approach towards dependencies is sometimes favored. However, it is also very important to stay on top of new releases: these may include bug fixes, or deprecate old patterns in favor of newer and better practices.
|
|
4
|
-
|
|
5
|
-
Here we describe when you should expect new releases to come out, and how this affects you as a user of OpenZeppelin Contracts.
|
|
6
|
-
|
|
7
|
-
[[release-schedule]]
|
|
8
|
-
== Release Schedule
|
|
9
|
-
|
|
10
|
-
OpenZeppelin Contracts follows a <<versioning-scheme, semantic versioning scheme>>.
|
|
11
|
-
|
|
12
|
-
We aim for a new minor release every 1 or 2 months.
|
|
13
|
-
|
|
14
|
-
[[minor-releases]]
|
|
15
|
-
=== Release Candidates
|
|
16
|
-
|
|
17
|
-
Before every release, we publish a feature-frozen release candidate. The purpose of the release candidate is to have a period where the community can review the new code before the actual release. If important problems are discovered, several more release candidates may be required. After a week of no more changes to the release candidate, the new version is published.
|
|
18
|
-
|
|
19
|
-
[[major-releases]]
|
|
20
|
-
=== Major Releases
|
|
21
|
-
|
|
22
|
-
After several months or a year a new major release may come out. These are not scheduled, but will be based on the need to release breaking changes such as a redesign of a core feature of the library (e.g. https://github.com/OpenZeppelin/openzeppelin-contracts/pulls/2112[access control] in 3.0). Since we value stability, we aim for these to happen infrequently (expect no less than six months between majors). However, we may be forced to release one when there are big changes to the Solidity language.
|
|
23
|
-
|
|
24
|
-
[[api-stability]]
|
|
25
|
-
== API Stability
|
|
26
|
-
|
|
27
|
-
On the https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v2.0.0[OpenZeppelin Contracts 2.0 release], we committed ourselves to keeping a stable API. We aim to more precisely define what we understand by _stable_ and _API_ here, so users of the library can understand these guarantees and be confident their project won't break unexpectedly.
|
|
28
|
-
|
|
29
|
-
In a nutshell, the API being stable means _if your project is working today, it will continue to do so after a minor upgrade_. New contracts and features will be added in minor releases, but only in a backwards compatible way.
|
|
30
|
-
|
|
31
|
-
[[versioning-scheme]]
|
|
32
|
-
=== Versioning Scheme
|
|
33
|
-
|
|
34
|
-
We follow https://semver.org/[SemVer], which means API breakage may occur between major releases (which <<release-schedule, don't happen very often>>).
|
|
35
|
-
|
|
36
|
-
[[solidity-functions]]
|
|
37
|
-
=== Solidity Functions
|
|
38
|
-
|
|
39
|
-
While the internal implementation of functions may change, their semantics and signature will remain the same. The domain of their arguments will not be less restrictive (e.g. if transferring a value of 0 is disallowed, it will remain disallowed), nor will general state restrictions be lifted (e.g. `whenPaused` modifiers).
|
|
40
|
-
|
|
41
|
-
If new functions are added to a contract, it will be in a backwards-compatible way: their usage won't be mandatory, and they won't extend functionality in ways that may foreseeable break an application (e.g. https://github.com/OpenZeppelin/openzeppelin-contracts/issues/1512[an `internal` method may be added to make it easier to retrieve information that was already available]).
|
|
42
|
-
|
|
43
|
-
[[internal]]
|
|
44
|
-
==== `internal`
|
|
45
|
-
|
|
46
|
-
This extends not only to `external` and `public` functions, but also `internal` ones: many contracts are meant to be used by inheriting them (e.g. `Pausable`, `PullPayment`, `AccessControl`), and are therefore used by calling these functions. Similarly, since all OpenZeppelin Contracts state variables are `private`, they can only be accessed this way (e.g. to create new `ERC20` tokens, instead of manually modifying `totalSupply` and `balances`, `_mint` should be called).
|
|
47
|
-
|
|
48
|
-
`private` functions have no guarantees on their behavior, usage, or existence.
|
|
49
|
-
|
|
50
|
-
Finally, sometimes language limitations will force us to e.g. make `internal` a function that should be `private` in order to implement features the way we want to. These cases will be well documented, and the normal stability guarantees won't apply.
|
|
51
|
-
|
|
52
|
-
[[libraries]]
|
|
53
|
-
=== Libraries
|
|
54
|
-
|
|
55
|
-
Some of our Solidity libraries use ``struct``s to handle internal data that should not be accessed directly (e.g. `Counter`). There's an https://github.com/ethereum/solidity/issues/4637[open issue] in the Solidity repository requesting a language feature to prevent said access, but it looks like it won't be implemented any time soon. Because of this, we will use leading underscores and mark said `struct` s to make it clear to the user that its contents and layout are _not_ part of the API.
|
|
56
|
-
|
|
57
|
-
[[events]]
|
|
58
|
-
=== Events
|
|
59
|
-
|
|
60
|
-
No events will be removed, and their arguments won't be changed in any way. New events may be added in later versions, and existing events may be emitted under new, reasonable circumstances (e.g. https://github.com/OpenZeppelin/openzeppelin-contracts/issues/707[from 2.1 on, `ERC20` also emits `Approval` on `transferFrom` calls]).
|
|
61
|
-
|
|
62
|
-
[[drafts]]
|
|
63
|
-
=== Drafts
|
|
64
|
-
|
|
65
|
-
Some contracts implement EIPs that are still in Draft status, recognizable by a file name beginning with `draft-`, such as `utils/cryptography/draft-EIP712.sol`. Due to their nature as drafts, the details of these contracts may change and we cannot guarantee their stability. Minor releases of OpenZeppelin Contracts may contain breaking changes for the contracts labelled as Drafts, which will be duly announced in the https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CHANGELOG.md[changelog]. The EIPs included are used by projects in production and this may make them less likely to change significantly.
|
|
66
|
-
|
|
67
|
-
[[gas-costs]]
|
|
68
|
-
=== Gas Costs
|
|
69
|
-
|
|
70
|
-
While attempts will generally be made to lower the gas costs of working with OpenZeppelin Contracts, there are no guarantees regarding this. In particular, users should not assume gas costs will not increase when upgrading library versions.
|
|
71
|
-
|
|
72
|
-
[[bugfixes]]
|
|
73
|
-
=== Bug Fixes
|
|
74
|
-
|
|
75
|
-
The API stability guarantees may need to be broken in order to fix a bug, and we will do so. This decision won't be made lightly however, and all options will be explored to make the change as non-disruptive as possible. When sufficient, contracts or functions which may result in unsafe behavior will be deprecated instead of removed (e.g. https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1543[#1543] and https://github.com/OpenZeppelin/openzeppelin-contracts/pull/1550[#1550]).
|
|
76
|
-
|
|
77
|
-
[[solidity-compiler-version]]
|
|
78
|
-
=== Solidity Compiler Version
|
|
79
|
-
|
|
80
|
-
Starting on version 0.5.0, the Solidity team switched to a faster release cycle, with minor releases every few weeks (v0.5.0 was released on November 2018, and v0.5.5 on March 2019), and major, breaking-change releases every couple of months (with v0.6.0 released on December 2019 and v0.7.0 on July 2020). Including the compiler version in OpenZeppelin Contract's stability guarantees would therefore force the library to either stick to old compilers, or release frequent major updates simply to keep up with newer Solidity releases.
|
|
81
|
-
|
|
82
|
-
Because of this, *the minimum required Solidity compiler version is not part of the stability guarantees*, and users may be required to upgrade their compiler when using newer versions of Contracts. Bug fixes will still be backported to past major releases so that all versions currently in use receive these updates.
|
|
83
|
-
|
|
84
|
-
You can read more about the rationale behind this, the other options we considered and why we went down this path https://github.com/OpenZeppelin/openzeppelin-contracts/issues/1498#issuecomment-449191611[here].
|
|
85
|
-
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
= Tokens
|
|
2
|
-
|
|
3
|
-
Ah, the "token": blockchain's most powerful and most misunderstood tool.
|
|
4
|
-
|
|
5
|
-
A token is a _representation of something in the blockchain_. This something can be money, time, services, shares in a company, a virtual pet, anything. By representing things as tokens, we can allow smart contracts to interact with them, exchange them, create or destroy them.
|
|
6
|
-
|
|
7
|
-
[[but_first_coffee_a_primer_on_token_contracts]]
|
|
8
|
-
== But First, [strikethrough]#Coffee# a Primer on Token Contracts
|
|
9
|
-
|
|
10
|
-
Much of the confusion surrounding tokens comes from two concepts getting mixed up: _token contracts_ and the actual _tokens_.
|
|
11
|
-
|
|
12
|
-
A _token contract_ is simply an Ethereum smart contract. "Sending tokens" actually means "calling a method on a smart contract that someone wrote and deployed". At the end of the day, a token contract is not much more than a mapping of addresses to balances, plus some methods to add and subtract from those balances.
|
|
13
|
-
|
|
14
|
-
It is these balances that represent the _tokens_ themselves. Someone "has tokens" when their balance in the token contract is non-zero. That's it! These balances could be considered money, experience points in a game, deeds of ownership, or voting rights, and each of these tokens would be stored in different token contracts.
|
|
15
|
-
|
|
16
|
-
[[different-kinds-of-tokens]]
|
|
17
|
-
== Different Kinds of Tokens
|
|
18
|
-
|
|
19
|
-
Note that there's a big difference between having two voting rights and two deeds of ownership: each vote is equal to all others, but houses usually are not! This is called https://en.wikipedia.org/wiki/Fungibility[fungibility]. _Fungible goods_ are equivalent and interchangeable, like Ether, fiat currencies, and voting rights. _Non-fungible_ goods are unique and distinct, like deeds of ownership, or collectibles.
|
|
20
|
-
|
|
21
|
-
In a nutshell, when dealing with non-fungibles (like your house) you care about _which ones_ you have, while in fungible assets (like your bank account statement) what matters is _how much_ you have.
|
|
22
|
-
|
|
23
|
-
== Standards
|
|
24
|
-
|
|
25
|
-
Even though the concept of a token is simple, they have a variety of complexities in the implementation. Because everything in Ethereum is just a smart contract, and there are no rules about what smart contracts have to do, the community has developed a variety of *standards* (called EIPs or ERCs) for documenting how a contract can interoperate with other contracts.
|
|
26
|
-
|
|
27
|
-
You've probably heard of the ERC20 or ERC721 token standards, and that's why you're here. Head to our specialized guides to learn more about these:
|
|
28
|
-
|
|
29
|
-
* xref:erc20.adoc[ERC20]: the most widespread token standard for fungible assets, albeit somewhat limited by its simplicity.
|
|
30
|
-
* xref:erc721.adoc[ERC721]: the de-facto solution for non-fungible tokens, often used for collectibles and games.
|
|
31
|
-
* xref:erc777.adoc[ERC777]: a richer standard for fungible tokens, enabling new use cases and building on past learnings. Backwards compatible with ERC20.
|
|
32
|
-
* xref:erc1155.adoc[ERC1155]: a novel standard for multi-tokens, allowing for a single contract to represent multiple fungible and non-fungible tokens, along with batched operations for increased gas efficiency.
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
= Using with Upgrades
|
|
2
|
-
|
|
3
|
-
If your contract is going to be deployed with upgradeability, such as using the xref:upgrades-plugins::index.adoc[OpenZeppelin Upgrades Plugins], you will need to use the Upgradeable variant of OpenZeppelin Contracts.
|
|
4
|
-
|
|
5
|
-
This variant is available as a separate package called `@openzeppelin/contracts-upgradeable`, which is hosted in the repository https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable[OpenZeppelin/openzeppelin-contracts-upgradeable].
|
|
6
|
-
|
|
7
|
-
It follows all of the rules for xref:upgrades-plugins::writing-upgradeable.adoc[Writing Upgradeable Contracts]: constructors are replaced by initializer functions, state variables are initialized in initializer functions, and we additionally check for storage incompatibilities across minor versions.
|
|
8
|
-
|
|
9
|
-
TIP: OpenZeppelin provides a full suite of tools for deploying and securing upgradeable smart contracts. xref:openzeppelin::upgrades.adoc[Check out the full list of resources].
|
|
10
|
-
|
|
11
|
-
== Overview
|
|
12
|
-
|
|
13
|
-
=== Installation
|
|
14
|
-
|
|
15
|
-
```console
|
|
16
|
-
$ npm install @openzeppelin/contracts-upgradeable
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
=== Usage
|
|
20
|
-
|
|
21
|
-
The package replicates the structure of the main OpenZeppelin Contracts package, but every file and contract has the suffix `Upgradeable`.
|
|
22
|
-
|
|
23
|
-
```diff
|
|
24
|
-
-import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
|
|
25
|
-
+import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
|
|
26
|
-
|
|
27
|
-
-contract MyCollectible is ERC721 {
|
|
28
|
-
+contract MyCollectible is ERC721Upgradeable {
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Constructors are replaced by internal initializer functions following the naming convention `+__{ContractName}_init+`. Since these are internal, you must always define your own public initializer function and call the parent initializer of the contract you extend.
|
|
32
|
-
|
|
33
|
-
```diff
|
|
34
|
-
- constructor() ERC721("MyCollectible", "MCO") public {
|
|
35
|
-
+ function initialize() initializer public {
|
|
36
|
-
+ __ERC721_init("MyCollectible", "MCO");
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
CAUTION: Use with multiple inheritance requires special attention. See the section below titled <<multiple-inheritance>>.
|
|
41
|
-
|
|
42
|
-
Once this contract is set up and compiled, you can deploy it using the xref:upgrades-plugins::index.adoc[Upgrades Plugins]. The following snippet shows an example deployment script using Hardhat.
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
// scripts/deploy-my-collectible.js
|
|
46
|
-
const { ethers, upgrades } = require("hardhat");
|
|
47
|
-
|
|
48
|
-
async function main() {
|
|
49
|
-
const MyCollectible = await ethers.getContractFactory("MyCollectible");
|
|
50
|
-
|
|
51
|
-
const mc = await upgrades.deployProxy(MyCollectible);
|
|
52
|
-
|
|
53
|
-
await mc.deployed();
|
|
54
|
-
console.log("MyCollectible deployed to:", mc.address);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
main();
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
== Further Notes
|
|
61
|
-
|
|
62
|
-
[[multiple-inheritance]]
|
|
63
|
-
=== Multiple Inheritance
|
|
64
|
-
|
|
65
|
-
Initializer functions are not linearized by the compiler like constructors. Because of this, each `+__{ContractName}_init+` function embeds the linearized calls to all parent initializers. As a consequence, calling two of these `init` functions can potentially initialize the same contract twice.
|
|
66
|
-
|
|
67
|
-
The function `+__{ContractName}_init_unchained+` found in every contract is the initializer function minus the calls to parent initializers, and can be used to avoid the double initialization problem, but doing this manually is not recommended. We hope to be able to implement safety checks for this in future versions of the Upgrades Plugins.
|
|
68
|
-
|
|
69
|
-
=== Storage Gaps
|
|
70
|
-
|
|
71
|
-
You may notice that every contract includes a state variable named `+__gap+`. This is empty reserved space in storage that is put in place in Upgradeable contracts. It allows us to freely add new state variables in the future without compromising the storage compatibility with existing deployments.
|
|
72
|
-
|
|
73
|
-
It isn't safe to simply add a state variable because it "shifts down" all of the state variables below in the inheritance chain. This makes the storage layouts incompatible, as explained in xref:upgrades-plugins::writing-upgradeable.adoc#modifying-your-contracts[Writing Upgradeable Contracts]. The size of the `+__gap+` array is calculated so that the amount of storage used by a contract always adds up to the same number (in this case 50 storage slots).
|