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

Felix/sdk #19

Merged
merged 48 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
bb5e93d
feat: add factory
FelixGibson Sep 18, 2023
e3b131f
feat: add factory abi
FelixGibson Sep 19, 2023
30b3dc1
feat: fix abi problem
FelixGibson Sep 23, 2023
af00fbb
feat: add abi
FelixGibson Sep 29, 2023
df99e0e
feat: partly finish addLiquidity
FelixGibson Sep 29, 2023
a7d86da
feat: try add test
FelixGibson Sep 29, 2023
a1d139a
feat: add interface
FelixGibson Sep 29, 2023
614d2de
feat: not finish yet
FelixGibson Sep 29, 2023
915a9f3
feat: approveForAll success
FelixGibson Sep 29, 2023
d6691b9
feat: add erc20
FelixGibson Sep 29, 2023
d9c32d3
feat: finish add liquidity, but run failed
FelixGibson Sep 30, 2023
1a393d5
feat: add may initiallize pool
FelixGibson Sep 30, 2023
8e19beb
feat: add position
FelixGibson Sep 30, 2023
b2d0c23
feat: add_liquidity pass
FelixGibson Sep 30, 2023
a256b3e
feat: add bounds when adding liquidity
FelixGibson Oct 1, 2023
84afd82
feat: add input text
FelixGibson Oct 2, 2023
d7db741
feat: add erc1155 balance check
FelixGibson Oct 2, 2023
bbe6766
feat: add erc1155 mint
FelixGibson Oct 2, 2023
bda0ae7
feat: add more input for erc1155 amount
FelixGibson Oct 2, 2023
a88e291
feat: fix order bug
FelixGibson Oct 3, 2023
91a5a15
feat: not can swap yet
FelixGibson Oct 3, 2023
17b7b43
feat: fix bugs
FelixGibson Oct 3, 2023
4aa66e0
feat: add avnu swap
FelixGibson Oct 4, 2023
f0903d4
feat: can swap
FelixGibson Oct 4, 2023
a3c6085
chore
FelixGibson Oct 5, 2023
6081938
feat: swap success
FelixGibson Oct 6, 2023
6b18424
feat: swap success from erc20
FelixGibson Oct 6, 2023
c30f410
bug: fix sqrt_ratio_limit
FelixGibson Oct 6, 2023
71071b2
sdk-refactor
huyao Oct 10, 2023
5ea051d
feat: add price
FelixGibson Oct 10, 2023
02e8447
more refactor
huyao Oct 11, 2023
51d3c51
remove useless code
huyao Oct 11, 2023
1a4a555
merge new functions and refactor
huyao Oct 12, 2023
386b266
Merge branch 'felix/sdk' into sdk-refactor
huyao Oct 12, 2023
1f64f89
Merge pull request #20 from BibliothecaDAO/sdk-refactor
FelixGibson Oct 12, 2023
64f9e22
graphql-index
huyao Oct 31, 2023
f90e0e4
Merge branch 'felix/sdk' into graphql
huyao Oct 31, 2023
a8cdb0f
Merge pull request #21 from BibliothecaDAO/graphql
FelixGibson Nov 2, 2023
396683a
linting by prettier
huyao Nov 3, 2023
4825053
remove useless code
huyao Nov 3, 2023
d5f52d0
feat: add nft address
FelixGibson Nov 4, 2023
0a963c3
add starknet.js & get-starknent for build bun on ubuntu
huyao Nov 7, 2023
c6d6479
Merge branch 'felix/sdk' of https://github.com/BibliothecaDAO/InstaSw…
huyao Nov 7, 2023
bb9c5a7
add remove liquidity method for sdk
huyao Nov 8, 2023
aaf2da7
remove expired functions
huyao Nov 8, 2023
5f36881
Merge pull request #22 from BibliothecaDAO/removeliquidity
FelixGibson Nov 8, 2023
c18ca3d
add list_liquidity api for indexer & add readme for indexer/sdk
huyao Nov 20, 2023
efb24a5
Update README.md
huyao Nov 20, 2023
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/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.7.0"
- run: cd contracts && scarb test
- run: cd contracts
75 changes: 75 additions & 0 deletions contracts/src/wrap_factory.cairo
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));
Copy link
Contributor

Choose a reason for hiding this comment

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

should move this to helper fn

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
}

}

}
20 changes: 20 additions & 0 deletions examples/interface/.eslintrc.json
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"]
}
}
25 changes: 25 additions & 0 deletions examples/interface/.gitignore
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 added examples/interface/bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions examples/interface/index.html
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>
Loading