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

dev(scripts): deploy default DualVM tokens #1499

Merged
merged 20 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "solidity_contracts/lib/openzeppelin-contracts"]
path = solidity_contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "starknet-addresses"]
path = starknet-addresses
url = https://github.com/starknet-io/starknet-addresses
39 changes: 34 additions & 5 deletions cairo/token/src/starknet_token.cairo
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#[starknet::contract]
mod StarknetToken {
use openzeppelin::token::erc20::ERC20Component;
use openzeppelin::token::erc20::interface::IERC20Metadata;
use starknet::ContractAddress;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>;
impl ERC20InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
struct Storage {
#[substorage(v0)]
erc20: ERC20Component::Storage
erc20: ERC20Component::Storage,
decimals: u8,
}

#[event]
Expand All @@ -25,11 +27,38 @@ mod StarknetToken {
}

#[constructor]
fn constructor(ref self: ContractState, initial_supply: u256, recipient: ContractAddress) {
let name = "MyToken";
let symbol = "MTK";
fn constructor(ref self: ContractState, name: ByteArray, symbol: ByteArray, decimals: u8, initial_supply: u256, recipient: ContractAddress) {
self._set_decimals(decimals);

// ERC20 initialization
self.erc20.initializer(name, symbol);
self.erc20._mint(recipient, initial_supply);
}

#[external(v0)]
fn mint(ref self: ContractState, to: ContractAddress, amount: u256) {
self.erc20._mint(to, amount);
}

#[abi(embed_v0)]
impl ERC20MetadataImpl of IERC20Metadata<ContractState> {
fn name(self: @ContractState) -> ByteArray {
self.erc20.name()
}

fn symbol(self: @ContractState) -> ByteArray {
self.erc20.symbol()
}

fn decimals(self: @ContractState) -> u8 {
self.decimals.read()
}
}

#[generate_trait]
impl InternalImpl of InternalTrait {
fn _set_decimals(ref self: ContractState, decimals: u8) {
self.decimals.write(decimals);
}
}
}
59 changes: 32 additions & 27 deletions cairo_zero/openzeppelin/ERC20.cairo
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.uint256 import Uint256

from openzeppelin.access.ownable.library import Ownable
from openzeppelin.token.erc20.library import ERC20

@constructor
Expand All @@ -15,7 +14,6 @@ func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
) {
ERC20.initializer(name, symbol, decimals);
ERC20._mint(recipient, initial_supply);
Ownable.initializer(owner);
return ();
}

Expand All @@ -41,6 +39,13 @@ func totalSupply{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
return (totalSupply=totalSupply);
}

@view
func total_supply{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
obatirou marked this conversation as resolved.
Show resolved Hide resolved
total_supply: Uint256
) {
return ERC20.total_supply();
}

@view
func decimals{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
decimals: felt
Expand All @@ -55,18 +60,20 @@ func balanceOf{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
return ERC20.balance_of(account);
}

@view
func balance_of{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(account: felt) -> (
balance: Uint256
) {
return ERC20.balance_of(account);
}

@view
func allowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
owner: felt, spender: felt
) -> (remaining: Uint256) {
return ERC20.allowance(owner, spender);
}

@view
func owner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (owner: felt) {
return Ownable.owner();
}

//
// Externals
//
Expand All @@ -85,6 +92,13 @@ func transferFrom{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_pt
return ERC20.transfer_from(sender, recipient, amount);
}

@external
func transfer_from{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
sender: felt, recipient: felt, amount: Uint256
) -> (success: felt) {
return ERC20.transfer_from(sender, recipient, amount);
}

@external
func approve{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, amount: Uint256
Expand All @@ -100,31 +114,22 @@ func increaseAllowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_che
}

@external
func decreaseAllowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, subtracted_value: Uint256
func increase_allowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, added_value: Uint256
) -> (success: felt) {
return ERC20.decrease_allowance(spender, subtracted_value);
}

@external
func mint{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
to: felt, amount: Uint256
) {
Ownable.assert_only_owner();
ERC20._mint(to, amount);
return ();
return ERC20.increase_allowance(spender, added_value);
}

@external
func transferOwnership{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newOwner: felt
) {
Ownable.transfer_ownership(newOwner);
return ();
func decreaseAllowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, subtracted_value: Uint256
) -> (success: felt) {
return ERC20.decrease_allowance(spender, subtracted_value);
}

@external
func renounceOwnership{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
Ownable.renounce_ownership();
return ();
func decrease_allowance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
spender: felt, subtracted_value: Uint256
) -> (success: felt) {
return ERC20.decrease_allowance(spender, subtracted_value);
}
2 changes: 1 addition & 1 deletion deployments/starknet-sepolia/kakarot_deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
"address": "0xba5ed099633d3b313e4d5f7bdc1305d3c28ba5ed",
"starknet_address": "0x2361be1b7ded312bfc16c2547eaaf2308d3c9b6aa9037d8fc9ee57329f00951"
}
}
}
41 changes: 10 additions & 31 deletions kakarot_scripts/constants.py
enitrat marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# see https://gist.github.com/rekmarks/a47bd5f2525936c4b8eee31a16345553
MAX_SAFE_CHAIN_ID = 4503599627370476

TOKEN_ADDRESSES_DIR = Path("starknet-addresses/bridged_tokens")


class NetworkType(Enum):
PROD = "prod"
Expand All @@ -34,7 +36,7 @@ class NetworkType(Enum):

NETWORKS = {
"mainnet": {
"name": "starknet-mainnet",
"name": "mainnet",
"explorer_url": "https://starkscan.co",
"rpc_url": f"https://rpc.nethermind.io/mainnet-juno/?apikey={os.getenv('NETHERMIND_API_KEY')}",
"l1_rpc_url": f"https://mainnet.infura.io/v3/{os.getenv('INFURA_KEY')}",
Expand All @@ -45,9 +47,10 @@ class NetworkType(Enum):
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
"voyager_api_url": "https://api.voyager.online/beta",
"argent_multisig_api": "https://cloud.argent-api.com/v1/multisig/starknet/mainnet",
"token_addresses_file": TOKEN_ADDRESSES_DIR / "mainnet.json",
},
"sepolia": {
"name": "starknet-sepolia",
"name": "sepolia",
"explorer_url": "https://sepolia.starkscan.co/",
"rpc_url": f"https://rpc.nethermind.io/sepolia-juno/?apikey={os.getenv('NETHERMIND_API_KEY')}",
"l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}",
Expand All @@ -58,9 +61,10 @@ class NetworkType(Enum):
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
"voyager_api_url": "https://sepolia-api.voyager.online/beta",
"argent_multisig_api": "https://cloud.argent-api.com/v1/multisig/starknet/sepolia",
"token_addresses_file": TOKEN_ADDRESSES_DIR / "sepolia.json",
},
"sepolia-staging": {
"name": "starknet-sepolia-staging",
"staging": {
"name": "staging",
"explorer_url": "https://sepolia.starkscan.co/",
"rpc_url": f"https://rpc.nethermind.io/sepolia-juno/?apikey={os.getenv('NETHERMIND_API_KEY')}",
"l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}",
Expand All @@ -71,6 +75,7 @@ class NetworkType(Enum):
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
"voyager_api_url": "https://sepolia-api.voyager.online/beta",
"argent_multisig_api": "https://cloud.argent-api.com/v1/multisig/starknet/sepolia",
"token_addresses_file": TOKEN_ADDRESSES_DIR / "sepolia.json",
},
"starknet-devnet": {
"name": "starknet-devnet",
Expand All @@ -89,6 +94,7 @@ class NetworkType(Enum):
"type": NetworkType.DEV,
"check_interval": 0.01,
"max_wait": 3,
"token_addresses_file": TOKEN_ADDRESSES_DIR / "sepolia.json",
"relayers": [
{
"address": 0xE29882A1FCBA1E7E10CAD46212257FEA5C752A4F9B1B1EC683C503A2CF5C8A,
Expand Down Expand Up @@ -137,33 +143,6 @@ class NetworkType(Enum):
"check_interval": 6,
"max_wait": 30,
},
"sharingan": {
"name": "sharingan",
"explorer_url": "",
"rpc_url": os.getenv("SHARINGAN_RPC_URL"),
"l1_rpc_url": "http://127.0.0.1:8545",
"type": NetworkType.PROD,
"check_interval": 6,
"max_wait": 30,
},
"kakarot-sepolia": {
"name": "kakarot-sepolia",
"explorer_url": "",
"rpc_url": os.getenv("KAKAROT_SEPOLIA_RPC_URL"),
"l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}",
"type": NetworkType.PROD,
"check_interval": 6,
"max_wait": 360,
},
"kakarot-staging": {
"name": "kakarot-staging",
"explorer_url": "",
"rpc_url": os.getenv("KAKAROT_STAGING_RPC_URL"),
"l1_rpc_url": f"https://sepolia.infura.io/v3/{os.getenv('INFURA_KEY')}",
"type": NetworkType.STAGING,
"check_interval": 1,
"max_wait": 30,
},
}

if os.getenv("STARKNET_NETWORK") is not None:
Expand Down
Loading
Loading