Skip to content

Commit

Permalink
[GSW-416] feat: Integrate Pools API
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Oct 13, 2023
1 parent 090da87 commit 67da391
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 157 deletions.
30 changes: 30 additions & 0 deletions packages/web/src/hooks/pool/use-pool-data.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { PoolPosition } from "@containers/earn-my-position-container/EarnMyPositionContainer";
import { useGnoswapContext } from "@hooks/common/use-gnoswap-context";
import { CardListPoolInfo } from "@models/common/card-list-item-info";
import { PoolCardInfo } from "@models/pool/info/pool-card-info";
import { PoolMapper } from "@models/pool/mapper/pool-mapper";
import { PoolState } from "@states/index";
import { useAtom } from "jotai";
import { useMemo } from "react";

export const usePoolData = () => {
const { poolRepository } = useGnoswapContext();
const [pools, setPools] = useAtom(PoolState.pools);
const [isFetchedPools, setIsFetchedPools] = useAtom(PoolState.isFetchedPools);
const [isFetchedPositions, setIsFetchedPositions] = useAtom(PoolState.isFetchedPositions);

const poolListInfos = useMemo(() => {
return pools.map(PoolMapper.toListInfo);
}, [pools]);

const higestAPRs: CardListPoolInfo[] = useMemo(() => {
const sortedTokens = pools.sort((p1, p2) => {
Expand All @@ -19,13 +28,34 @@ export const usePoolData = () => {
}));
}, [pools]);

const myPositions: PoolPosition[] = useMemo(() => {
return [];
}, []);
async function updatePositions() {
setIsFetchedPositions(true);
}

const incentivizedPools: PoolCardInfo[] = useMemo(() => {
return pools
.map(PoolMapper.toCardInfo)
.filter(info => info.incentiveType === "Incentivized");
}, [pools]);

async function updatePools() {
const response = await poolRepository.getPools();
setPools(response.pools);
setIsFetchedPools(true);
}

return {
isFetchedPools,
higestAPRs,
isFetchedPositions,
myPositions,
pools,
poolListInfos,
incentivizedPools,
updatePools,
updatePositions,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const useEarnAddLiquidityConfirmModal = ({
setModalContent(null);
}, [setModalContent, setOpenedModal]);

const moveMain = useCallback(() => {
const moveEarn = useCallback(() => {
close();
navigator.push("/");
navigator.push("/earn");
}, [close, navigator]);

const confirm = useCallback(() => {
Expand All @@ -113,8 +113,8 @@ export const useEarnAddLiquidityConfirmModal = ({
slippage,
startPrice: currentPrice,
swapFeeTier,
}).then(result => result && moveMain());
}, [createPool, currentPrice, moveMain, priceRange, slippage, swapFeeTier, tokenA, tokenAAmountInput.amount, tokenB, tokenBAmountInput.amount]);
}).then(result => result && moveEarn());
}, [createPool, currentPrice, moveEarn, priceRange, slippage, swapFeeTier, tokenA, tokenAAmountInput.amount, tokenB, tokenBAmountInput.amount]);

const openModal = useCallback(() => {
if (!amountInfo || !priceRangeInfo) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/models/pool/pool-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface PoolModel {

totalVolume: AmountModel;

fee: number;
fee: string;

feeVolume: number;

Expand Down
129 changes: 43 additions & 86 deletions packages/web/src/repositories/pool/mock/pool-detail.json
Original file line number Diff line number Diff line change
@@ -1,106 +1,63 @@
{
"pool": {
"name": "1inch_weth_500",
"name": "bar_foo_500",
"tokenA": {
"chainId": "test3",
"address": "0x111111111117dC0aa78b770fA6A738034120C302",
"path": "gno.land/r/demo/1inch",
"name": "1inch",
"symbol": "1INCH",
"decimals": 6,
"logoURI": "https://assets.coingecko.com/coins/images/13469/thumb/1inch-token.png?1608803028",
"priceId": "1inch",
"createdAt": "2023-09-26T05:36:37+09:00"
"chainId": "dev",
"createdAt": "2023-10-12T06:56:10+09:00",
"name": "Bar",
"address": "g1w8wqgrp08cqhtupzx98n4jtm8kqy7vadfmmyd0",
"path": "gno.land/r/bar",
"decimals": 4,
"symbol": "BAR",
"logoURI": "https://s2.coinmarketcap.com/static/img/coins/64x64/5994.png",
"priceId": "gno.land/r/bar"
},
"tokenB": {
"name": "Wrapped Ether",
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"path": "gno.land/r/demo/weth",
"symbol": "WETH",
"decimals": 6,
"chainId": "test3",
"priceId": "weth",
"createdAt": "2023-09-26T05:36:37+09:00",
"isWrappedGasToken": true,
"logoURI": "https://s2.coinmarketcap.com/static/img/coins/64x64/2396.png"
"chainId": "dev",
"createdAt": "2023-10-12T06:56:08+09:00",
"name": "Foo",
"address": "g1evezrh92xaucffmtgsaa3rvmz5s8kedffsg469",
"path": "gno.land/r/foo",
"decimals": 4,
"symbol": "FOO",
"logoURI": "https://s2.coinmarketcap.com/static/img/coins/64x64/5994.png",
"priceId": "gno.land/r/foo"
},
"tvl": {
"amount": 10621.170589130697,
"amount": 1182782.0,
"currency": "USD"
},
"tvlChange": 0,
"tvlChange": 118278200.0,
"volume": {
"amount": 0,
"amount": 1182797.0,
"currency": "USD"
},
"volumeChange": -1,
"volumeChange": 118279700.0,
"totalVolume": {
"amount": 133703.0054829442,
"amount": 1182797.0,
"currency": "USD"
},
"id": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"fee": 0.05,
"feeVolume": 0,
"feeChange": -1,
"currentTick": 15,
"price": 1.0619905601291797,
"tokenABalance": 49.981458116220594,
"tokenBBalance": 24049.763462426952,
"tickSpacing": 40,
"resolvedBins": [
{
"binId": "1",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 15,
"reserveA": 49.981458116220594,
"reserveB": 1223.4471028043677,
"lpTokenId": "1",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
},
{
"binId": "2",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 16,
"reserveA": 0,
"reserveB": 1264.593283181672,
"lpTokenId": "2",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
}
],
"bins": [
{
"binId": "1",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 15,
"reserveA": 49.981458116220594,
"reserveB": 1223.4471028043677,
"lpTokenId": "1",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
},
{
"binId": "2",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 16,
"reserveA": 0,
"reserveB": 1264.593283181672,
"lpTokenId": "2",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
}
],
"id": "bar_foo_500",
"apr": 0.12345,
"fee": "500",
"feeVolume": 131.937491,
"feeChange": 13193.749143,
"currentTick": 8090,
"price": 1.49859,
"tokenABalance": 591391,
"tokenBBalance": 2777571,
"tickSpacing": 10,
"bins": [],
"resolvedBins": [],
"topBin": {
"binId": "1",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 15,
"reserveA": 49.981458116220594,
"reserveB": 1223.4471028058367,
"lpTokenId": "3",
"binId": "",
"poolId": "",
"currentTick": 0,
"reserveA": 0,
"reserveB": 0,
"lpTokenId": "",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
},
"apr": 148.07
}
}
}
110 changes: 44 additions & 66 deletions packages/web/src/repositories/pool/mock/pools.json
Original file line number Diff line number Diff line change
@@ -1,90 +1,68 @@
{
"meta": {
"height": 18177740,
"timestamp": "2023-09-26T05:36:37+09:00"
"height": 0,
"timestamp": "2023-10-12T10:33:10+09:00"
},
"pools": [
{
"name": "1inch_weth_500",
"name": "bar_foo_500",
"tokenA": {
"chainId": "test3",
"address": "0x111111111117dC0aa78b770fA6A738034120C302",
"path": "gno.land/r/demo/1inch",
"name": "1inch",
"symbol": "1INCH",
"decimals": 6,
"logoURI": "https://assets.coingecko.com/coins/images/13469/thumb/1inch-token.png?1608803028",
"priceId": "1inch",
"createdAt": "2023-09-26T05:36:37+09:00"
"chainId": "dev",
"createdAt": "2023-10-12T06:56:10+09:00",
"name": "Bar",
"address": "g1w8wqgrp08cqhtupzx98n4jtm8kqy7vadfmmyd0",
"path": "gno.land/r/bar",
"decimals": 4,
"symbol": "BAR",
"logoURI": "https://s2.coinmarketcap.com/static/img/coins/64x64/5994.png",
"priceId": "gno.land/r/bar"
},
"tokenB": {
"name": "Wrapped Ether",
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"path": "gno.land/r/demo/weth",
"symbol": "WETH",
"decimals": 6,
"chainId": "test3",
"priceId": "weth",
"createdAt": "2023-09-26T05:36:37+09:00",
"isWrappedGasToken": true,
"logoURI": "https://s2.coinmarketcap.com/static/img/coins/64x64/2396.png"
"chainId": "dev",
"createdAt": "2023-10-12T06:56:08+09:00",
"name": "Foo",
"address": "g1evezrh92xaucffmtgsaa3rvmz5s8kedffsg469",
"path": "gno.land/r/foo",
"decimals": 4,
"symbol": "FOO",
"logoURI": "https://s2.coinmarketcap.com/static/img/coins/64x64/5994.png",
"priceId": "gno.land/r/foo"
},
"tvl": {
"amount": 10621.170589130697,
"amount": 1182782.0,
"currency": "USD"
},
"tvlChange": 0,
"tvlChange": 118278200.0,
"volume": {
"amount": 0,
"amount": 1182797.0,
"currency": "USD"
},
"volumeChange": -1,
"volumeChange": 118279700.0,
"totalVolume": {
"amount": 133703.0054829442,
"amount": 1182797.0,
"currency": "USD"
},
"id": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"fee": 0.05,
"feeVolume": 0,
"feeChange": -1,
"currentTick": 15,
"price": 1.0619905601291797,
"tokenABalance": 49.981458116220594,
"tokenBBalance": 24049.763462426952,
"tickSpacing": 40,
"bins": [
{
"binId": "1",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 15,
"reserveA": 49.981458116220594,
"reserveB": 1223.4471028043677,
"lpTokenId": "1",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
},
{
"binId": "2",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 16,
"reserveA": 0,
"reserveB": 1264.593283181672,
"lpTokenId": "2",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
}
],
"id": "bar_foo_500",
"apr": 0.12345,
"fee": "500",
"feeVolume": 131.937491,
"feeChange": 13193.749143,
"currentTick": 8090,
"price": 1.49859,
"tokenABalance": 591391,
"tokenBBalance": 2777571,
"tickSpacing": 10,
"bins": [],
"topBin": {
"binId": "1",
"poolId": "0x001903de96a72d11d27cd8c2bee003a730e032a8",
"currentTick": 15,
"reserveA": 49.981458116220594,
"reserveB": 1223.4471028058367,
"lpTokenId": "3",
"binId": "",
"poolId": "",
"currentTick": 0,
"reserveA": 0,
"reserveB": 0,
"lpTokenId": "",
"timestamp": "0001-01-01T00:00:00Z",
"annualizedFeeGrowth": 0
},
"apr": 148.07
}
}
]
}
7 changes: 7 additions & 0 deletions packages/web/src/states/pool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { PoolModel } from "@models/pool/pool-model";
import { PositionModel } from "@models/position/position-model";
import { atom } from "jotai";

export const isFetchedPools = atom<boolean>(false);

export const pools = atom<PoolModel[]>([]);

export const isFetchedPositions = atom<boolean>(false);

export const positions = atom<PositionModel[]>([]);

0 comments on commit 67da391

Please sign in to comment.