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

Enroll token #1

Merged
merged 17 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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 .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
.DS_Store
.snfoundry_cache/
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scarb 2.6.5
starknet-foundry 0.26.0
29 changes: 29 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "cairo_appchain_bridge"
version = "0.1.0"
dependencies = [
"openzeppelin",
"piltover",
"snforge_std",
]

[[package]]
name = "openzeppelin"
version = "0.14.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.14.0#f091c4f51ddeb10297db984acae965328c5a4e5b"

[[package]]
name = "piltover"
version = "0.1.0"
source = "git+https://github.com/byteZorvin/piltover?branch=main#34be166da6ec295f950c65ad231890127da68b5e"
dependencies = [
"openzeppelin",
]

[[package]]
name = "snforge_std"
version = "0.26.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.26.0#50eb589db65e113efe4f09241feb59b574228c7e"
26 changes: 26 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "cairo_appchain_bridge"
version = "0.1.0"
edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.14.0" }
starknet = "2.6.4"
piltover = { git = "https://github.com/byteZorvin/piltover", branch="main"}

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.26.0" }

[[target.starknet-contract]]
casm = true
build-external-contracts = ["piltover::appchain::appchain"]

[[tool.snforge.fork]]
name = "mainnet"
url = "https://starknet-mainnet.public.blastapi.io"
block_id.tag = "Latest"
byteZorvin marked this conversation as resolved.
Show resolved Hide resolved

[scripts]
test = "snforge test"
14 changes: 14 additions & 0 deletions scripts/my_script/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "my_script"
version = "0.1.0"
dependencies = [
"sncast_std",
]

[[package]]
name = "sncast_std"
version = "0.26.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.26.0#50eb589db65e113efe4f09241feb59b574228c7e"
10 changes: 10 additions & 0 deletions scripts/my_script/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "my_script"
version = "0.1.0"
edition = "2023_11"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
sncast_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.26.0" }
starknet = ">=2.6.4"
1 change: 1 addition & 0 deletions scripts/my_script/src/lib.cairo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to delete this dummy script for now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted ✅

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod my_script;
12 changes: 12 additions & 0 deletions scripts/my_script/src/my_script.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use sncast_std::{call, CallResult};

// The example below uses a contract deployed to the Sepolia testnet
fn main() {
let contract_address = 0x07e867f1fa6da2108dd2b3d534f1fbec411c5ec9504eb3baa1e49c7a0bef5ab5;
let call_result = call(
contract_address.try_into().unwrap(), selector!("get_greeting"), array![]
)
.expect('call failed');
assert(*call_result.data[1] == 'Hello, Starknet!', *call_result.data[1]);
println!("{:?}", call_result);
}
94 changes: 94 additions & 0 deletions src/bridge/interface.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use starknet::ContractAddress;

#[derive(Serde, Drop, starknet::Store, PartialEq)]
pub enum TokenStatus {
#[default]
Unknown,
Pending,
Active,
Blocked
}

#[derive(Serde, Drop, starknet::Store)]
pub struct TokenSettings {
pub token_status: TokenStatus,
pub deployment_message_hash: felt252,
pub pending_deployment_expiration: u64,
pub max_total_balance: u256,
pub withdrawal_limit_applied: bool
}
byteZorvin marked this conversation as resolved.
Show resolved Hide resolved

#[starknet::interface]
pub trait ITokenBridgeAdmin<TContractState> {
fn set_appchain_token_bridge(ref self: TContractState, appchain_bridge: ContractAddress);
fn block_token(ref self: TContractState, token: ContractAddress);
fn deactivate_and_block_token(ref self: TContractState, token: ContractAddress);
fn enable_withdrawal_limit(ref self: TContractState, token: ContractAddress);
fn disable_withdrawal_limit(ref self: TContractState, token: ContractAddress);
fn set_max_total_balance(
ref self: TContractState, token: ContractAddress, max_total_balance: u256
);
}

#[starknet::interface]
pub trait ITokenBridge<TContractState> {
fn appchain_bridge(self: @TContractState) -> ContractAddress;
fn identity(self: @TContractState) -> ByteArray;
fn getStatus(self: @TContractState, token: ContractAddress) -> TokenStatus;
fn isServicingToken(self: @TContractState, token: ContractAddress) -> bool;
fn is_withdrawal_limit_applied(self: @TContractState, token: ContractAddress) -> bool;

fn enroll_token(ref self: TContractState, token: ContractAddress);
fn check_deployment_status(ref self: TContractState, token: ContractAddress);

fn deposit(
ref self: TContractState,
token: ContractAddress,
amount: u256,
appchain_recipient: ContractAddress
);
fn deposit_with_message(
ref self: TContractState,
token: ContractAddress,
amount: u256,
appchain_recipient: ContractAddress,
message: Span<felt252>
);

fn withdraw(
ref self: TContractState, token: ContractAddress, amount: u256, recipient: ContractAddress
);

fn deposit_cancel_request(
ref self: TContractState,
token: ContractAddress,
amount: u256,
appchain_recipient: ContractAddress,
nonce: felt252
);
fn deposit_with_message_cancel_request(
ref self: TContractState,
token: ContractAddress,
amount: u256,
appchain_recipient: ContractAddress,
message: Span<felt252>,
nonce: felt252
);

fn deposit_with_message_reclaim(
ref self: TContractState,
token: ContractAddress,
amount: u256,
appchain_recipient: ContractAddress,
message: Span<felt252>,
nonce: felt252
);
fn deposit_reclaim(
ref self: TContractState,
token: ContractAddress,
amount: u256,
appchain_recipient: ContractAddress,
nonce: felt252
);
fn get_remaining_intraday_allowance(self: @TContractState, token: ContractAddress) -> u256;
}
Loading