Skip to content

Commit

Permalink
add list_liquidity api for indexer & add readme for indexer/sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
huyao committed Nov 20, 2023
1 parent 5f36881 commit c18ca3d
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 7 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
118 changes: 116 additions & 2 deletions README.md
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);
```


##
83 changes: 83 additions & 0 deletions graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,88 @@ copy the config example file,then replace the database information

then visit http://localhost:8088/ for GraphQL playground

## Queries

```graphql
query getPoolKeys {
pool_keys{
fee
key_hash
token0
token1
tick_spacing
extension
}
}

query getPoolKeyByHash {
pool_key(
key_hash: "[hash]"
) {
fee
key_hash
token0
token1
tick_spacing
extension
}
}

query getPositionDeposits {
position_deposits {
block_number
transaction_index
event_index
transaction_hash
token_id
lower_bound
upper_bound
pool_key_hash
liquidity
delta0
delta1
}
}


query getPositionDepositByHash {
position_deposit(transaction_hash:"[hash]") {
block_number
transaction_index
event_index
transaction_hash
token_id
lower_bound
upper_bound
pool_key_hash
liquidity
delta0
delta1
}
}


query getSwapByHash {
swap(transaction_hash:"[hash]") {
transaction_index
event_index
transaction_hash
locker
pool_key_hash
delta0
delta1
sqrt_ratio_after
tick_after
liquidity_after
}
}


query getListLiquidity {
list_liquidity(account:"0x0112C1E020708b84aaC85983734A6ffB5fCe89891e8414e4E54F94CE75c06a90"){
token_id
}
}
```


122 changes: 122 additions & 0 deletions graphql/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion graphql/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions graphql/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Query {
pool_key(key_hash: String!): PoolKey!
position_transfers:[PositionTransfer!]!
position_transfer(transaction_hash: String!):PositionTransfer
list_liquidity(account: String!):[PositionTransfer!]!
position_deposits:[PositionDeposit!]!
position_deposit(transaction_hash: String!): PositionDeposit
swap(transaction_hash: String!):Swap!
Expand Down
Loading

0 comments on commit c18ca3d

Please sign in to comment.