generated from auditless/cairo-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'felix/sdk' into graphql
- Loading branch information
Showing
31 changed files
with
8,456 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
#[starknet::contract] | ||
mod WrapFactory { | ||
use openzeppelin::token::erc20::erc20::ERC20; | ||
use starknet::ContractAddress; | ||
use starknet::{ get_caller_address, get_contract_address}; | ||
use zeroable::Zeroable; | ||
use instaswap::erc1155::{IERC1155, IERC1155Dispatcher, IERC1155DispatcherTrait}; | ||
use starknet::class_hash::ClassHash; | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
CreateWrapAddress: CreateWrapAddress, | ||
} | ||
|
||
#[derive(Drop, starknet::Event)] | ||
struct CreateWrapAddress { | ||
erc1155_address: ContractAddress, | ||
token_id: u256, | ||
wrap_address: ContractAddress, | ||
} | ||
|
||
#[storage] | ||
struct Storage { | ||
map: LegacyMap::<(ContractAddress, u256), ContractAddress>, // map of (erc1155_address, token_id) to wrap_address | ||
wrap_hash: felt252, // hash of Wrap class | ||
} | ||
|
||
#[constructor] | ||
fn constructor( | ||
ref self: ContractState, | ||
wrap_hash_: felt252, | ||
) { | ||
self.wrap_hash.write(wrap_hash_); | ||
} | ||
|
||
#[external(v0)] | ||
#[generate_trait] | ||
impl WrapFactoryInterfaceImpl of WrapFactoryInterface { | ||
fn create_wrap_address(ref self: ContractState, erc1155_address: ContractAddress, token_id: u256, name: felt252, symbol: felt252) { | ||
let wrap_address = self.map.read((erc1155_address, token_id)); | ||
let wrap_hash = self.wrap_hash.read(); | ||
assert(wrap_address.is_zero(), 'Already wrapped'); | ||
let mut calldata = Default::default(); | ||
erc1155_address.serialize(ref calldata); | ||
token_id.serialize(ref calldata); | ||
name.serialize(ref calldata); | ||
symbol.serialize(ref calldata); | ||
let (address, _) = starknet::deploy_syscall(wrap_hash.try_into().unwrap(), 0, calldata.span(), false) | ||
.unwrap(); | ||
// emit event | ||
self | ||
.emit( | ||
Event::CreateWrapAddress( | ||
CreateWrapAddress { | ||
erc1155_address: erc1155_address, | ||
token_id: token_id, | ||
wrap_address: address, | ||
} | ||
) | ||
); | ||
self.map.write((erc1155_address, token_id), address); | ||
|
||
} | ||
|
||
fn get_wrap_address(self: @ContractState, erc1155_address: ContractAddress, token_id: u256) -> ContractAddress { | ||
let wrap_address = self.map.read((erc1155_address, token_id)); | ||
assert(!wrap_address.is_zero(), 'Not wrapped'); | ||
wrap_address | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], | ||
"overrides": [], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"project": "./tsconfig.json", | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["react", "@typescript-eslint"], | ||
"root": true, | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["off"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
.vite | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Create Starknet</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.