generated from auditless/cairo-template
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Felix/sdk #19
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
bb5e93d
feat: add factory
FelixGibson e3b131f
feat: add factory abi
FelixGibson 30b3dc1
feat: fix abi problem
FelixGibson af00fbb
feat: add abi
FelixGibson df99e0e
feat: partly finish addLiquidity
FelixGibson a7d86da
feat: try add test
FelixGibson a1d139a
feat: add interface
FelixGibson 614d2de
feat: not finish yet
FelixGibson 915a9f3
feat: approveForAll success
FelixGibson d6691b9
feat: add erc20
FelixGibson d9c32d3
feat: finish add liquidity, but run failed
FelixGibson 1a393d5
feat: add may initiallize pool
FelixGibson 8e19beb
feat: add position
FelixGibson b2d0c23
feat: add_liquidity pass
FelixGibson a256b3e
feat: add bounds when adding liquidity
FelixGibson 84afd82
feat: add input text
FelixGibson d7db741
feat: add erc1155 balance check
FelixGibson bbe6766
feat: add erc1155 mint
FelixGibson bda0ae7
feat: add more input for erc1155 amount
FelixGibson a88e291
feat: fix order bug
FelixGibson 91a5a15
feat: not can swap yet
FelixGibson 17b7b43
feat: fix bugs
FelixGibson 4aa66e0
feat: add avnu swap
FelixGibson f0903d4
feat: can swap
FelixGibson a3c6085
chore
FelixGibson 6081938
feat: swap success
FelixGibson 6b18424
feat: swap success from erc20
FelixGibson c30f410
bug: fix sqrt_ratio_limit
FelixGibson 71071b2
sdk-refactor
huyao 5ea051d
feat: add price
FelixGibson 02e8447
more refactor
huyao 51d3c51
remove useless code
huyao 1a4a555
merge new functions and refactor
huyao 386b266
Merge branch 'felix/sdk' into sdk-refactor
huyao 1f64f89
Merge pull request #20 from BibliothecaDAO/sdk-refactor
FelixGibson 64f9e22
graphql-index
huyao f90e0e4
Merge branch 'felix/sdk' into graphql
huyao a8cdb0f
Merge pull request #21 from BibliothecaDAO/graphql
FelixGibson 396683a
linting by prettier
huyao 4825053
remove useless code
huyao d5f52d0
feat: add nft address
FelixGibson 0a963c3
add starknet.js & get-starknent for build bun on ubuntu
huyao c6d6479
Merge branch 'felix/sdk' of https://github.com/BibliothecaDAO/InstaSw…
huyao bb9c5a7
add remove liquidity method for sdk
huyao aaf2da7
remove expired functions
huyao 5f36881
Merge pull request #22 from BibliothecaDAO/removeliquidity
FelixGibson c18ca3d
add list_liquidity api for indexer & add readme for indexer/sdk
huyao efb24a5
Update README.md
huyao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
{} |
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 |
---|---|---|
@@ -1,3 +1,117 @@ | ||
## InstaSwap | ||
# InstaSwap | ||
|
||
### initialize sdk | ||
|
||
To initialize sdk,fill the config first | ||
|
||
```js | ||
|
||
import { Provider, constants } from "starknet"; | ||
import { useAccount } from "@starknet-react/core"; | ||
.... | ||
|
||
const provider = new Provider({ | ||
sequencer: { network: constants.NetworkName.SN_GOERLI }, | ||
}); | ||
|
||
const config = { | ||
erc1155Address: "0x03467674358c444d5868e40b4de2c8b08f0146cbdb4f77242bd7619efcf3c0a6", | ||
werc20Address: "0x06b09e4c92a08076222b392c77e7eab4af5d127188082713aeecbe9013003bf4", | ||
erc20Address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", | ||
ekuboPositionAddress: "0x73fa8432bf59f8ed535f29acfd89a7020758bda7be509e00dfed8a9fde12ddc", | ||
ekuboCoreAddress: "0x031e8a7ab6a6a556548ac85cbb8b5f56e8905696e9f13e9a858142b8ee0cc221", | ||
quoterAddress: "0x042aa743335663ed9c7b52b331ab7f81cc8d65280d311506653f9b5cc22be7cb", | ||
provider: provider, | ||
account: useAccount(), | ||
}; | ||
|
||
const wrap = new Wrap(config); | ||
... | ||
``` | ||
|
||
### Initialize pool | ||
|
||
```js | ||
const initialize_tick = { mag: 0n, sign: false }; | ||
|
||
const { transaction_hash } = await wrap.mayInitializePool( | ||
FeeAmount.LOWEST, | ||
initialize_tick, | ||
); | ||
``` | ||
|
||
### Add liquidity | ||
|
||
```js | ||
const params = { | ||
erc1155Amount: [erc1155 amount], | ||
erc20Amount: [erc20 amount], | ||
fee: [fee], | ||
lowerPrice: [lowerBound], | ||
upperPrice: [upperBound], | ||
}; | ||
|
||
wrap.addLiquidity(params); | ||
|
||
``` | ||
|
||
|
||
|
||
### Withdraw Liquidity | ||
|
||
```js | ||
wrap.withdrawLiquidity(positionId,liquidity); | ||
``` | ||
|
||
|
||
|
||
|
||
### Simple wrap | ||
|
||
- from erc115 to erc20 | ||
|
||
```js | ||
|
||
const params = { | ||
amountIn: [erc1155 amount for swap], | ||
minERC20AmountOut: [min amount], | ||
simpleSwapperAddress: [simple swapper address], | ||
userAddress:[user address], | ||
fee: [fee], | ||
slippage: [slippage], | ||
}; | ||
|
||
wrap.swapSimple( | ||
SwapDirection.ERC1155_TO_ERC20, | ||
params, | ||
); | ||
|
||
|
||
``` | ||
|
||
- from erc20 to erc1155 | ||
|
||
```js | ||
const params = { | ||
amountIn: [erc20 amount for swap], | ||
minERC20AmountOut: [min amount], | ||
simpleSwapperAddress: [simple swapper address], | ||
userAddress:[user address], | ||
fee: [fee], | ||
slippage: [slippage], | ||
}; | ||
|
||
wrap.swapSimple( | ||
SwapDirection.ERC20_TO_ERC1155, | ||
params, | ||
); | ||
|
||
``` | ||
|
||
### Withdraw erc1155 | ||
|
||
```js | ||
wrap.withdraw(erc1155Num); | ||
``` | ||
|
||
|
||
## |
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 |
---|---|---|
@@ -1,29 +1,34 @@ | ||
### Export ENV | ||
``` bash | ||
|
||
```bash | ||
export STARKNET_NETWORK=alpha-goerli | ||
export STARKNET_WALLET=starkware.starknet.wallets.open_zeppelin.OpenZeppelinAccount | ||
``` | ||
|
||
### Setup accounts | ||
``` bash | ||
|
||
```bash | ||
starknet new_account --account with_testnet_eth --gateway_url http://localhost:5050 --feeder_gateway_url http://localhost:5050 | ||
starknet deploy_account --gateway_url http://localhost:5050 --feeder_gateway_url http://localhost:5050 --account with_testnet_eth | ||
``` | ||
|
||
### Check txn status | ||
|
||
ps. replace with your own hash | ||
|
||
``` bash | ||
```bash | ||
starknet tx_status --hash 0x2b221bc1aab675e99189692fd530003d269eb099abba70ebd29c3fb5ab10187 --gateway_url http://localhost:5050 --feeder_gateway_url http://localhost:5050 | ||
``` | ||
|
||
### Declare contracts on dev-net | ||
``` bash | ||
|
||
```bash | ||
starknet declare --contract target/dev/instaswap_InstaSwapPair.sierra.json --account devnet_account1 --max_fee 10000000000000000 --gateway_url http://localhost:5050 --feeder_gateway_url http://localhost:5050 | ||
``` | ||
|
||
### Deploy contracts on dev-net | ||
``` bash | ||
|
||
```bash | ||
starknet deploy --class_hash 0x11e3711dbd08dd49631efa3a80faa28457cc193d1c620708331e1780e4b6b6e --account devnet_account1 --max_fee 100000000000000000 --gateway_url http://localhost:5050 --feeder_gateway_url http://localhost:5050 | ||
|
||
``` | ||
``` |
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,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.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> |
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,31 @@ | ||
{ | ||
"name": "interface", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@bibliothecadao/instaswap-core": "link:instaswap/packages/instaswap-core", | ||
"@starknet-react/core": "^1.0.1", | ||
"get-starknet": "^3.0.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"starknet": "next" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.27", | ||
"@types/react-dom": "^18.0.10", | ||
"@typescript-eslint/eslint-plugin": "^6.7.3", | ||
"@vitejs/plugin-react": "^3.1.0", | ||
"bun-types": "^1.0.8", | ||
"eslint": "^8.26.0", | ||
"eslint-plugin-react": "^7.31.4", | ||
"typescript": "^5.2.2", | ||
"vite": "^4.1.0", | ||
"vite-plugin-checker": "^0.5.1" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,30 @@ | ||
import { useBlock } from "@starknet-react/core"; | ||
import WalletBar from "./components/WalletBar"; | ||
import { BlockNumber, BlockTag } from "starknet"; | ||
|
||
function App() { | ||
const latestBlockNumber: BlockNumber = BlockTag.latest; | ||
const { data, isLoading, isError } = useBlock({ | ||
refetchInterval: 3000, | ||
blockIdentifier: latestBlockNumber, | ||
}); | ||
|
||
return ( | ||
<main> | ||
<p> | ||
Get started by editing | ||
<code>pages/index.tsx</code> | ||
</p> | ||
<div> | ||
{isLoading | ||
? "Loading..." | ||
: isError | ||
? "Error while fetching the latest block hash" | ||
: `Latest block hash: ${data?.block_hash}`} | ||
</div> | ||
<WalletBar /> | ||
</main> | ||
); | ||
} | ||
|
||
export default App; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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