Skip to content

Commit

Permalink
Merge pull request #22 from BibliothecaDAO/removeliquidity
Browse files Browse the repository at this point in the history
Remove liquidity
  • Loading branch information
FelixGibson authored Nov 8, 2023
2 parents c6d6479 + aaf2da7 commit 5f36881
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 24 deletions.
56 changes: 35 additions & 21 deletions examples/interface/src/components/ButtonClick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ButtonClick = () => {
const [erc20AmountForSwap, setERC20AmountForSwap] = useState(0);
const [wGoldForSwap, setWGoldForSwap] = useState(0);
const [nftForWithdraw, setNftForWithdraw] = useState(0);
const [positionId, setPositionId] = useState(0);
const [liquidity, setLiquidity] = useState(0);

const erc1155_address = useMemo(
() => "0x03467674358c444d5868e40b4de2c8b08f0146cbdb4f77242bd7619efcf3c0a6",
Expand All @@ -41,6 +43,7 @@ const ButtonClick = () => {
() => "0x031e8a7ab6a6a556548ac85cbb8b5f56e8905696e9f13e9a858142b8ee0cc221",
[],
);

const simple_swapper = useMemo(
() => "0x064f7ed2dc5070133ae8ccdf85f01e82507facbe5cdde456e1418e3901dc51a0",
[],
Expand Down Expand Up @@ -120,12 +123,10 @@ const ButtonClick = () => {
}, [account, lowerBound, upperBound, ethAmount, erc1155Amount]);



const withdraw = useCallback(async () => {
const { transaction_hash } = await wrap.withdraw(nftForWithdraw);
console.log(transaction_hash);

}, [account,nftForWithdraw]);
}, [account, nftForWithdraw]);


const handleSwapFromERC1155ToERC20BySimpleSwap = useCallback(async () => {
Expand Down Expand Up @@ -166,24 +167,15 @@ const ButtonClick = () => {
console.log(transaction_hash);
}, [account, erc20AmountForSwap, currentPrice]);

const handleSwapFromWGoldToWSliverBySimpleSwap = useCallback(async () => {
const withdrawLiquidity = useCallback(async () => {
if (!account) return;
// debugger;
const params = {
amountIn: 0.001 * 10 ** 18,
minERC20AmountOut: 1313331313,
simpleSwapperAddress: simple_swapper,
userAddress: account.address,
fee: FeeAmount.LOWEST,
slippage: 0.99,
};

const { transaction_hash } = await wrap.swapSimple(
SwapDirection.ERC20_TO_ERC1155,
params,
const { transaction_hash } = await wrap.withdrawLiquidity(
positionId,
liquidity,
);
console.log(transaction_hash);
}, [account, wGoldForSwap, currentPrice]);
}, [account, liquidity]);

const mayInitializePool = useCallback(async () => {
const initialize_tick = {
Expand All @@ -198,10 +190,6 @@ const ButtonClick = () => {
console.log(transaction_hash);
}, [account, lowerBound, upperBound]);





const mintERC1155Token = useCallback(async () => {
if (!address) return;
const call: Call = {
Expand Down Expand Up @@ -242,6 +230,7 @@ const ButtonClick = () => {
<div>
<button onClick={mintERC1155Token}>mint ERC1155 token</button>
</div>

<div>
<h3> Add Liquidity </h3>
</div>
Expand Down Expand Up @@ -287,6 +276,31 @@ const ButtonClick = () => {
<button onClick={handleAddLiquidity}>add liquidity</button>
</div>

<div>
<h3> Withdraw Liquidity </h3>
</div>
<div>
<label htmlFor="erc20 amount">id:</label>
<input
type="number"
id="position id"
value={positionId}
onChange={(e) => setPositionId(parseFloat(e.target.value))}
/>
</div>
<div>
<label htmlFor="erc20 amount">liquidity:</label>
<input
type="number"
id="liquidity"
value={liquidity}
onChange={(e) => setLiquidity(parseFloat(e.target.value))}
/>
</div>
<div>
<button onClick={withdrawLiquidity}>withdraw</button>
</div>

{/*<div>*/}
{/* <h3> Swap From ERC1155 to ERC20 By AVNU </h3>*/}
{/*</div>*/}
Expand Down
44 changes: 41 additions & 3 deletions sdk/packages/instaswap-core/src/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,55 @@ export class Wrap {
]);
};

public withdraw = async (amount:BigNumberish): Promise<InvokeFunctionResponse> => {
public withdrawLiquidity = async (
id: number,
liquidity: BigNumberish,
): Promise<InvokeFunctionResponse> => {
const withdraw: Call = {
contractAddress: Wrap.EkuboPositionAddress,
entrypoint: "withdraw",
calldata: CallData.compile({
id: id,
pool_key: {
token0: Wrap.SortedTokens[0],
token1: Wrap.SortedTokens[1],
fee: Wrap.getFeeX128(FeeAmount.LOWEST),
tick_spacing: 200,
extension: 0,
},
bounds: {
lower: {
mag: 50000000n,
sign: 1,
},
upper: {
mag: 50000000n,
sign: 0,
},
},
liquidity: liquidity,
min_token0: 0,
min_token1: 0,
collect_fees: 1,
}),
};

return Wrap.account.execute([withdraw]);
};

public withdraw = async (
amount: BigNumberish,
): Promise<InvokeFunctionResponse> => {
return Wrap.account.execute([
{
contractAddress: Wrap.WERC20Address,
entrypoint: "withdraw",
calldata: CallData.compile({
amount: cairo.uint256(amount),
}),
}
},
]);
}
};

public quoteSingle = async (
fee: FeeAmount,
Expand Down

0 comments on commit 5f36881

Please sign in to comment.