Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

90 upgradable contracts #100

Merged
merged 8 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy_badge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ permissions:
env:
COMPILED_SOURCE: ./build/CarbonableBadge.json
PROTOSTAR_TOML_FILE: ./protostar.toml
PROTOSTAR_VERSION: 0.7.0
PROTOSTAR_VERSION: 0.8.1

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_minter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ permissions:
env:
COMPILED_SOURCE: ./build/CarbonableMinter.json
PROTOSTAR_TOML_FILE: ./protostar.toml
PROTOSTAR_VERSION: 0.7.0
PROTOSTAR_VERSION: 0.8.1

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ permissions:
env:
COMPILED_SOURCE: ./build/CarbonableProject.json
PROTOSTAR_TOML_FILE: ./protostar.toml
PROTOSTAR_VERSION: 0.7.0
PROTOSTAR_VERSION: 0.8.1

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI Tests
on: [push, pull_request, pull_request_target]

env:
PROTOSTAR_VERSION: 0.7.0
PROTOSTAR_VERSION: 0.8.1

jobs:
protostar-tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/transfer_ownership.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ permissions:
env:
PROJECT_ABI: ./build/CarbonableProject_abi.json
PROTOSTAR_TOML_FILE: ./protostar.toml
PROTOSTAR_VERSION: 0.7.0
PROTOSTAR_VERSION: 0.8.1

jobs:
transfer:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Python
__pycache__
env
.env

# starknet
node.json
Expand Down
2 changes: 1 addition & 1 deletion lib/cairo_contracts
Submodule cairo_contracts updated 84 files
+3 −0 .gitignore
+43 −1 CONTRIBUTING.md
+2 −2 PULL_REQUEST_TEMPLATE.md
+33 −23 README.md
+1 −1 docs/antora.yml
+2 −2 docs/modules/ROOT/nav.adoc
+121 −165 docs/modules/ROOT/pages/access.adoc
+248 −222 docs/modules/ROOT/pages/accounts.adoc
+71 −81 docs/modules/ROOT/pages/erc20.adoc
+98 −120 docs/modules/ROOT/pages/erc721.adoc
+70 −38 docs/modules/ROOT/pages/extensibility.adoc
+21 −11 docs/modules/ROOT/pages/index.adoc
+22 −30 docs/modules/ROOT/pages/introspection.adoc
+82 −81 docs/modules/ROOT/pages/proxies.adoc
+38 −53 docs/modules/ROOT/pages/security.adoc
+2 −2 docs/modules/ROOT/pages/utilities.adoc
+14 −0 docs/modules/ROOT/pages/wizard.adoc
+1 −1 scripts/update_version.py
+1 −1 src/openzeppelin/access/accesscontrol/IAccessControl.cairo
+1 −1 src/openzeppelin/access/accesscontrol/library.cairo
+1 −1 src/openzeppelin/access/ownable/library.cairo
+4 −2 src/openzeppelin/account/IAccount.cairo
+13 −7 src/openzeppelin/account/library.cairo
+3 −3 src/openzeppelin/account/presets/Account.cairo
+1 −1 src/openzeppelin/account/presets/AddressRegistry.cairo
+1 −1 src/openzeppelin/account/presets/EthAccount.cairo
+1 −1 src/openzeppelin/introspection/erc165/IERC165.cairo
+1 −1 src/openzeppelin/introspection/erc165/library.cairo
+1 −1 src/openzeppelin/security/initializable/library.cairo
+1 −1 src/openzeppelin/security/pausable/library.cairo
+3 −3 src/openzeppelin/security/reentrancyguard/library.cairo
+6 −16 src/openzeppelin/security/safemath/library.cairo
+1 −1 src/openzeppelin/token/erc20/IERC20.cairo
+1 −1 src/openzeppelin/token/erc20/library.cairo
+1 −1 src/openzeppelin/token/erc20/presets/ERC20.cairo
+1 −1 src/openzeppelin/token/erc20/presets/ERC20Burnable.cairo
+1 −1 src/openzeppelin/token/erc20/presets/ERC20Mintable.cairo
+1 −1 src/openzeppelin/token/erc20/presets/ERC20Pausable.cairo
+1 −1 src/openzeppelin/token/erc20/presets/ERC20Upgradeable.cairo
+1 −1 src/openzeppelin/token/erc721/IERC721.cairo
+1 −1 src/openzeppelin/token/erc721/IERC721Metadata.cairo
+1 −1 src/openzeppelin/token/erc721/IERC721Receiver.cairo
+1 −1 src/openzeppelin/token/erc721/enumerable/IERC721Enumerable.cairo
+1 −1 src/openzeppelin/token/erc721/enumerable/library.cairo
+1 −1 src/openzeppelin/token/erc721/enumerable/presets/ERC721EnumerableMintableBurnable.cairo
+1 −1 src/openzeppelin/token/erc721/enumerable/presets/utils/ERC721Holder.cairo
+1 −1 src/openzeppelin/token/erc721/library.cairo
+1 −1 src/openzeppelin/token/erc721/presets/ERC721MintableBurnable.cairo
+1 −1 src/openzeppelin/token/erc721/presets/ERC721MintablePausable.cairo
+1 −1 src/openzeppelin/upgrades/library.cairo
+21 −6 src/openzeppelin/upgrades/presets/Proxy.cairo
+7 −1 src/openzeppelin/utils/constants/library.cairo
+72 −0 src/openzeppelin/utils/presets/UniversalDeployer.cairo
+65 −0 tests/access/OwnableBaseSuite.py
+2 −4 tests/access/test_AccessControl.py
+22 −82 tests/access/test_Ownable.py
+12 −7 tests/account/test_Account.py
+3 −4 tests/account/test_EthAccount.py
+1 −3 tests/introspection/test_ERC165.py
+19 −0 tests/mocks/ERC721SafeMintableMock.cairo
+8 −8 tests/mocks/ReentrancyMock.cairo
+5 −15 tests/mocks/SafeMathMock.cairo
+8 −1 tests/mocks/UpgradesMockV1.cairo
+2 −1 tests/security/test_initializable.py
+2 −2 tests/security/test_pausable.py
+2 −3 tests/security/test_reentrancy.py
+3 −3 tests/security/test_safemath.py
+1 −1 tests/signers.py
+711 −0 tests/token/erc20/ERC20BaseSuite.py
+5 −700 tests/token/erc20/test_ERC20.py
+152 −151 tests/token/erc20/test_ERC20Burnable.py
+97 −113 tests/token/erc20/test_ERC20Mintable.py
+131 −143 tests/token/erc20/test_ERC20Pausable.py
+144 −159 tests/token/erc20/test_ERC20Upgradeable.py
+924 −0 tests/token/erc721/ERC721BaseSuite.py
+386 −176 tests/token/erc721/test_ERC721EnumerableMintableBurnable.py
+154 −1,054 tests/token/erc721/test_ERC721MintableBurnable.py
+230 −126 tests/token/erc721/test_ERC721MintablePausable.py
+170 −154 tests/token/erc721/test_ERC721SafeMintableMock.py
+151 −155 tests/upgrades/test_Proxy.py
+318 −300 tests/upgrades/test_upgrades.py
+3 −82 tests/utils.py
+102 −0 tests/utils/test_UniversalDeployer.py
+4 −0 tox.ini
19 changes: 15 additions & 4 deletions protostar.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
protostar-version = "0.7.0"
protostar-version = "0.8.1"
lib-path = "lib"
cairo-path = ["./lib/cairopen_contracts/src", "./lib/cairo_contracts/src", "./lib/bal7hazar_contracts/src", "src"]

Expand All @@ -9,15 +9,26 @@ CarbonableProject = ["src/project/project.cairo"]
CarbonableMinter = ["src/mint/minter.cairo"]
CarbonableYielder = ["src/farm/yielder.cairo"]
CarbonableOffseter = ["src/farm/offseter.cairo"]
CarbonableProxy = ["src/proxy/proxy.cairo"]

[test]
target = ["tests"]

[profile.devnet.deploy]
[profile.devnet.project]
gateway-url = "http://127.0.0.1:5050/"

[profile.testnet.deploy]
[profile.testnet.project]
network = "testnet"
private-key-path = "./.env"
account-address = "0x063675fa1ecea10063722e61557ed7f49ed2503d6cdd74f4b31e9770b473650c"
block-explorer = "starkscan"

[profile.mainnet.deploy]
[profile.testnet2.project]
gateway-url="https://alpha4-2.starknet.io"
chain-id=1536727068981429685321
private-key-path = "./.env"
account-address = "0x063675fa1ecea10063722e61557ed7f49ed2503d6cdd74f4b31e9770b473650c"
block-explorer = "starkscan"

[profile.mainnet.project]
network = "mainnet"
54 changes: 0 additions & 54 deletions scripts/airdrop_badge.sh

This file was deleted.

28 changes: 14 additions & 14 deletions scripts/configs/testnet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
ACCOUNT=carbonable
WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount

# ERC-1155 settings
ERC1155_URI="ipfs://bafybeid3s2i3rjqdxeaoi2du7r3yev4n25uzbwla7nyj5v22rwdl7lfvz4"
ERC1155_NAME="Carbonable ERC-1155 Test"
# Carbonable Badge Settings
BADGE_URI="ipfs://bafybeid3s2i3rjqdxeaoi2du7r3yev4n25uzbwla7nyj5v22rwdl7lfvz4"
BADGE_NAME="Carbonable Badge Test"

# ERC-721 settings
ERC721_NAME="Carbonable ERC-721 Test"
ERC721_SYMBOL=CET
ERC721_URI="ipfs://bafybeihfuraj3mqqhn73ly2eap3ovxyu6ilasrmxpdg4hz7giul4hgr7zy"
# Carbonable Project Settings
PROJECT_NAME="Carbonable Project Test"
PROJECT_SYMBOL=CARB
PROJECT_URI="ipfs://bafybeigfdn34lppjksypyvmkeeim5536e77oj4jfsh62lbom2zu643rxbm"

# Minter settings
PAYMENT_TOKEN_ADDRESS=0x07394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10
PUBLIC_SALE_OPEN=1
MAX_BUY_PER_TX=5
UNIT_PRICE="10 0"
MAX_SUPPLY_FOR_MINT="10 0"
RESERVED_SUPPLY_FOR_MINT="3 0"
# Carbonable Minter Settings
PAYMENT_TOKEN_ADDRESS=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
MINTER_PUBLIC_SALE_OPEN=1
MINTER_MAX_BUY_PER_TX=5
MINTER_UNIT_PRICE="10 0"
MINTER_MAX_SUPPLY_FOR_MINT="10 0"
MINTER_RESERVED_SUPPLY_FOR_MINT="3 0"
20 changes: 20 additions & 0 deletions scripts/configs/testnet2.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Global settings
ACCOUNT=carbonable
WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount

# Carbonable Badge Settings
BADGE_URI="ipfs://bafybeid3s2i3rjqdxeaoi2du7r3yev4n25uzbwla7nyj5v22rwdl7lfvz4"
BADGE_NAME="Carbonable Badge Test"

# Carbonable Project Settings
PROJECT_NAME="Carbonable Project Test"
PROJECT_SYMBOL=CARB
PROJECT_URI="ipfs://bafybeigfdn34lppjksypyvmkeeim5536e77oj4jfsh62lbom2zu643rxbm"

# Carbonable Minter Settings
PAYMENT_TOKEN_ADDRESS=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
MINTER_PUBLIC_SALE_OPEN=1
MINTER_MAX_BUY_PER_TX=5
MINTER_UNIT_PRICE="10 0"
MINTER_MAX_SUPPLY_FOR_MINT="10 0"
MINTER_RESERVED_SUPPLY_FOR_MINT="3 0"
9 changes: 5 additions & 4 deletions scripts/deploy_project.sh → scripts/deploy_protocol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ deploy_all_contracts() {
[ ! -z $PROFILE ] && PROFILE_OPT="--profile $PROFILE"

# Deploy ERC-721 token contract
if [ -z $ERC721_ADDRESS ]; then
erc721_name=$(str_to_hex "$ERC721_NAME")
erc721_symbol=$(str_to_hex "$ERC721_SYMBOL")
if [ -z $PROJECT_ADDRESS ]; then
project_name=$(str_to_hex "$PROJECT_NAME")
project_symbol=$(str_to_hex "$PROJECT_SYMBOL")
log_info "Deploying ERC-721 contract..."
ERC721_ADDRESS=`send_transaction "protostar $PROFILE_OPT deploy ./build/CarbonableProject.json --inputs $erc721_name $erc721_symbol $ADMIN_ADDRESS" "$NETWORK"` || exit_error
PROJECT_CLASS_HASH=`send_transaction "protostar $PROFILE_OPT declare ./build/CarbonableProject.json --max-fee auto" "$NETWORK"` || exit_error
PROJECT_ADDRESS=`send_transaction "protostar $PROFILE_OPT deploy ./build/CarbonableProxy.json --max-fee auto --inputs $project_name $project_symbol $ADMIN_ADDRESS" "$NETWORK"` || exit_error
fi

# Deploy Minter contract
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PARENT_DIR="$(dirname "$SOURCE_FILE")"

### GENERATION
echo $TIMES
for (( i=0; i<$TIMES; i++))
for (( i=1; i<=$TIMES; i++))
do
cp $SOURCE_FILE $PARENT_DIR/$i.json
done
2 changes: 1 addition & 1 deletion scripts/starknet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ get_account_address() {
get_network() {
profile=$1
protostar_toml_file=$2
network=$(grep profile.$profile $protostar_toml_file -A3 -m1 | sed -n 's@^.*[network=|gateway_url=]"\(.*\)".*$@\1@p')
network=$(grep profile.$profile $protostar_toml_file -A3 -m1 | sed -n 's@^.*[network =|gateway_url =]"\(.*\)".*$@\1@p')
echo $(get_legacy_network "$network")
}

Expand Down
10 changes: 5 additions & 5 deletions src/farm/library.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace CarbonableFarmer {
let (contract_address) = get_contract_address();
let (carbonable_project_address) = carbonable_project_address_.read();
// [Check] Throws error if unknown token id
let (owner) = IERC721.ownerOf(
let (owner) = IERC721.ownerOf(
contract_address=carbonable_project_address, tokenId=token_id
);
with_attr error_message("CarbonableFarmer: token_id has not been registred") {
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace CarbonableFarmer {
alloc_locals;

// [Security] Start reetrancy guard
ReentrancyGuard._start();
ReentrancyGuard.start();

// [Check] Locked status
let (status) = is_locked();
Expand Down Expand Up @@ -259,7 +259,7 @@ namespace CarbonableFarmer {
registration_.write(token_id, caller);

// [Security] End reetrancy guard
ReentrancyGuard._end();
ReentrancyGuard.end();

return (success=TRUE,);
}
Expand All @@ -270,7 +270,7 @@ namespace CarbonableFarmer {
alloc_locals;

// [Security] Start reetrancy guard
ReentrancyGuard._start();
ReentrancyGuard.start();

// [Check] Locked status
let (status) = is_locked();
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace CarbonableFarmer {
}

// [Security] End reetrancy guard
ReentrancyGuard._end();
ReentrancyGuard.end();

return (success=TRUE,);
}
Expand Down
51 changes: 47 additions & 4 deletions src/farm/offseter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ from starkware.cairo.common.uint256 import Uint256

// Project dependencies
from openzeppelin.access.ownable.library import Ownable
from openzeppelin.upgrades.library import Proxy

// Local dependencies
from src.farm.library import CarbonableFarmer

//
// Constructor
// Initializer
//

@constructor
func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
carbonable_project_address: felt, owner: felt
@external
func initializer{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
carbonable_project_address: felt, owner: felt, proxy_admin: felt
) {
// Desc:
// Initialize the contract with the given parameters -
Expand All @@ -30,10 +31,52 @@ func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
// Explicit args:
// carbonable_project_address(felt): Address of the corresponding Carbonable project
// owner(felt): Owner address
// proxy_admin(felt): Admin address
// Returns:
// None
CarbonableFarmer.initializer(carbonable_project_address);
Ownable.initializer(owner);
Proxy.initializer(proxy_admin);
return ();
}

@view
func getImplementationHash{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
implementation: felt
) {
return Proxy.get_implementation_hash();
}

@view
func getAdmin{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (admin: felt) {
return Proxy.get_admin();
}

@external
func upgrade{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
new_implementation: felt
) {
// Desc:
// Renounce ownership
// Implicit args:
// syscall_ptr(felt*)
// pedersen_ptr(HashBuiltin*)
// range_check_ptr
// Returns:
// None
// Explicit args:
// new_implementation(felt): new contract implementation
// Raises:
// caller: caller is not a contract admin
Proxy.assert_only_admin();
Proxy._set_implementation_hash(new_implementation);
return ();
}

@external
func setAdmin{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(new_admin: felt) {
Proxy.assert_only_admin();
Proxy._set_admin(new_admin);
return ();
}

Expand Down
Loading