diff --git a/.yarn/cache/@types-crypto-js-npm-4.2.1-e032b646fb-413a3de36f.zip b/.yarn/cache/@types-crypto-js-npm-4.2.1-e032b646fb-413a3de36f.zip new file mode 100644 index 000000000..8dcc27948 Binary files /dev/null and b/.yarn/cache/@types-crypto-js-npm-4.2.1-e032b646fb-413a3de36f.zip differ diff --git a/.yarn/cache/crypto-js-npm-4.2.0-d6f7744e63-c7bcc56a6e.zip b/.yarn/cache/crypto-js-npm-4.2.0-d6f7744e63-c7bcc56a6e.zip new file mode 100644 index 000000000..8fcc0793d Binary files /dev/null and b/.yarn/cache/crypto-js-npm-4.2.0-d6f7744e63-c7bcc56a6e.zip differ diff --git a/packages/swap-router/.ultra.cache.json b/packages/swap-router/.ultra.cache.json index fa109ce16..deee37aef 100644 --- a/packages/swap-router/.ultra.cache.json +++ b/packages/swap-router/.ultra.cache.json @@ -1 +1 @@ -{"files":{".vscode":"1700971955685.2515","build":"1701412916671.3086","node_modules":"1700891704503.8325",".eslintignore":"7de3bd702df2dee92c033c49abbedd0b0f7452e6",".eslintrc.js":"ca4815a5cf5cffa1d3fb4a014c8c602f852b002a",".gitignore":"c87c9b392c0200d9c9dafc444386ad3e15a85c64",".prettierignore":"47bb4656eb55860a075be7799cba7fa955b68141",".prettierrc":"fe5f744c7a08b128c935d1e1aed3e8a577e74507","jest.config.json":"2e496ee6bd64eb237161dcd69a6957eff2df584d","package.json":"4dda70ca76fb6022f6cb20852ecd8d2d95d638d2","src/common/array.util.ts":"9482ab121d34cc7e08a0cd33b49173b0b85823d8","src/common/bigint.util.ts":"343f4c85ca1f6c840ade68c259ed82bf5b159fb0","src/common/index.ts":"861a3167cddfc93e9eb1b6a4ae8229bb9dc2f8fd","src/common/mapper.ts":"f7d7b491dff443911a978b34e4cb378bee46c2b7","src/common/queue.ts":"ad096fefbe1c5a7339b536b0b8d39dba661b520e","src/common/test.util.ts":"3e500df6ec27ba98606acbfcaec9243e22862e43","src/constants/index.ts":"9605b149deb525c25f6e93420bbc433ff1c75cd0","src/constants/math.constant.ts":"b617851527cabcc9c3bce2c8e39208001d379ad6","src/constants/swap.constant.ts":"53e280147c68acfba490bc1f9a0b7bb1580e7280","src/index.ts":"691efb21a28bd3f0e6437edcb16192789dbbb7f6","src/swap-router/index.ts":"effaf28a826bdf1441437643e8343e7fbd8026b1","src/swap-router/swap-router-default.spec.ts":"f980bc94753df130c950eb80d8709b62ec3276fa","src/swap-router/swap-router-multi-higher-range-position-pool.spec.ts":"683ce3a82d73e915018e772723700905c3ff7c92","src/swap-router/swap-router-multi-lower-range-position-pool.spec.ts":"93bfd18d0a297f3c66743cddcf2fe10c3764e250","src/swap-router/swap-router-multi-pair-pools.spec.ts":"5fbd55be39012d46adbdc91a1111dca2aafd314d","src/swap-router/swap-router-multi-route.spec.ts":"771df497876b6bc027dc7b65d03e53209538bf2e","src/swap-router/swap-router-single-pair-pools.spec.ts":"3954e9057ef9534a3724dc960c291281d1a4ef52","src/swap-router/swap-router.ts":"606de3d518665d58f5cbafb55f45d92c30dab77d","src/swap-router/swap-router.types.ts":"2a48987217df238256a0721d227952142a37ce08","src/swap-router/utility/index.ts":"4973874904dd9d77d037d72b1ec8aed397716a38","src/swap-router/utility/route.util.ts":"d492418c9184e42d3ef29d7760eb18fa013f54c6","src/swap-simulator/index.ts":"ef493c5977bdf1123d1197b804f2344ee463870c","src/swap-simulator/swap-simulator-default.spec.ts":"867788b12ccc70abe676010aeed5d6b2b58e8036","src/swap-simulator/swap-simulator.ts":"48cc4c90a2622d806659fa2f8c4f48d600a2b2db","src/swap-simulator/swap-simulator.types.ts":"2b03d7e389ab8875852330c8fddf5a9bfe96f1c6","src/swap-simulator/utility/cache.util.ts":"c5af86d350610a80a6690846657a35635bbc752a","src/swap-simulator/utility/index.ts":"7272f5d23dfa7af2895fca9bb0b17985234ab6e1","src/swap-simulator/utility/math.util.ts":"96fbe38cbabe344f6f58220f46c20103e6df4225","src/swap-simulator/utility/swap-util.spec.ts":"b7fe082f3fef7e5a912959925924f56f8c36e020","src/swap-simulator/utility/swap.util.ts":"f49236f0d22f72b9283244e870d34401d42fe009","src/swap-simulator/utility/tick.util.ts":"4d9bf8ed782f07587c71009ad13cd249b5e3a840","tsconfig.json":"55467bd5c5eb1b501abe50b952d5f2d9fa0a0d69"},"deps":{}} \ No newline at end of file +{"files":{".vscode":"1700971955685.2515","build":"1701505721738.6106","node_modules":"1700891704503.8325",".eslintignore":"7de3bd702df2dee92c033c49abbedd0b0f7452e6",".eslintrc.js":"ca4815a5cf5cffa1d3fb4a014c8c602f852b002a",".gitignore":"c87c9b392c0200d9c9dafc444386ad3e15a85c64",".prettierignore":"47bb4656eb55860a075be7799cba7fa955b68141",".prettierrc":"fe5f744c7a08b128c935d1e1aed3e8a577e74507","jest.config.json":"2e496ee6bd64eb237161dcd69a6957eff2df584d","package.json":"4dda70ca76fb6022f6cb20852ecd8d2d95d638d2","src/common/array.util.ts":"9482ab121d34cc7e08a0cd33b49173b0b85823d8","src/common/bigint.util.ts":"343f4c85ca1f6c840ade68c259ed82bf5b159fb0","src/common/index.ts":"861a3167cddfc93e9eb1b6a4ae8229bb9dc2f8fd","src/common/mapper.ts":"f7d7b491dff443911a978b34e4cb378bee46c2b7","src/common/queue.ts":"ad096fefbe1c5a7339b536b0b8d39dba661b520e","src/common/test.util.ts":"3e500df6ec27ba98606acbfcaec9243e22862e43","src/constants/index.ts":"9605b149deb525c25f6e93420bbc433ff1c75cd0","src/constants/math.constant.ts":"b617851527cabcc9c3bce2c8e39208001d379ad6","src/constants/swap.constant.ts":"53e280147c68acfba490bc1f9a0b7bb1580e7280","src/index.ts":"691efb21a28bd3f0e6437edcb16192789dbbb7f6","src/swap-router/index.ts":"effaf28a826bdf1441437643e8343e7fbd8026b1","src/swap-router/swap-router-default.spec.ts":"f980bc94753df130c950eb80d8709b62ec3276fa","src/swap-router/swap-router-multi-higher-range-position-pool.spec.ts":"683ce3a82d73e915018e772723700905c3ff7c92","src/swap-router/swap-router-multi-lower-range-position-pool.spec.ts":"93bfd18d0a297f3c66743cddcf2fe10c3764e250","src/swap-router/swap-router-multi-pair-pools.spec.ts":"5fbd55be39012d46adbdc91a1111dca2aafd314d","src/swap-router/swap-router-multi-route.spec.ts":"771df497876b6bc027dc7b65d03e53209538bf2e","src/swap-router/swap-router-single-pair-pools.spec.ts":"3954e9057ef9534a3724dc960c291281d1a4ef52","src/swap-router/swap-router.ts":"606de3d518665d58f5cbafb55f45d92c30dab77d","src/swap-router/swap-router.types.ts":"2a48987217df238256a0721d227952142a37ce08","src/swap-router/utility/index.ts":"4973874904dd9d77d037d72b1ec8aed397716a38","src/swap-router/utility/route.util.ts":"d492418c9184e42d3ef29d7760eb18fa013f54c6","src/swap-simulator/index.ts":"ef493c5977bdf1123d1197b804f2344ee463870c","src/swap-simulator/swap-simulator-default.spec.ts":"867788b12ccc70abe676010aeed5d6b2b58e8036","src/swap-simulator/swap-simulator.ts":"48cc4c90a2622d806659fa2f8c4f48d600a2b2db","src/swap-simulator/swap-simulator.types.ts":"2b03d7e389ab8875852330c8fddf5a9bfe96f1c6","src/swap-simulator/utility/cache.util.ts":"c5af86d350610a80a6690846657a35635bbc752a","src/swap-simulator/utility/index.ts":"7272f5d23dfa7af2895fca9bb0b17985234ab6e1","src/swap-simulator/utility/math.util.ts":"96fbe38cbabe344f6f58220f46c20103e6df4225","src/swap-simulator/utility/swap-util.spec.ts":"b7fe082f3fef7e5a912959925924f56f8c36e020","src/swap-simulator/utility/swap.util.ts":"f49236f0d22f72b9283244e870d34401d42fe009","src/swap-simulator/utility/tick.util.ts":"4d9bf8ed782f07587c71009ad13cd249b5e3a840","tsconfig.json":"55467bd5c5eb1b501abe50b952d5f2d9fa0a0d69"},"deps":{}} \ No newline at end of file diff --git a/packages/web/package.json b/packages/web/package.json index caea5989b..f9af05d8f 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -24,6 +24,7 @@ "@tanstack/react-query": "4.26.1", "axios": "1.3.4", "bignumber.js": "9.1.1", + "crypto-js": "^4.2.0", "d3": "^7.8.5", "dayjs": "1.11.7", "jotai": "2.2.1", @@ -60,6 +61,7 @@ "@testing-library/jest-dom": "5.16.5", "@testing-library/react": "14.0.0", "@testing-library/user-event": "14.4.3", + "@types/crypto-js": "^4.2.1", "@types/d3": "^7.4.0", "@types/jest": "29.4.0", "@types/node": "18.14.6", diff --git a/packages/web/src/components/common/select-fee-tier/SelectFeeTier.tsx b/packages/web/src/components/common/select-fee-tier/SelectFeeTier.tsx index 413d310e7..be673e5c5 100644 --- a/packages/web/src/components/common/select-fee-tier/SelectFeeTier.tsx +++ b/packages/web/src/components/common/select-fee-tier/SelectFeeTier.tsx @@ -31,7 +31,7 @@ const SelectFeeTier: React.FC = ({ selected={feeTier === item} feeTier={item} pools={pools} - liquidityRange={feetierOfLiquidityMap[SwapFeeTierInfoMap[item].fee] || null} + liquidityRange={feetierOfLiquidityMap[SwapFeeTierInfoMap[item].fee]} onClick={() => onClickFeeTierItem(item)} /> ))} @@ -61,7 +61,7 @@ const SelectFeeTierItem: React.FC = ({ if (liquidityRange === null) { return "Not created"; } - return `${liquidityRange}% Select`; + return `${Math.round(liquidityRange)}% Select`; }, [liquidityRange]); const description = useMemo(() => { diff --git a/packages/web/src/containers/remove-liquidity-container/RemoveLiquidityContainer.tsx b/packages/web/src/containers/remove-liquidity-container/RemoveLiquidityContainer.tsx index d3e51abac..54c6094d4 100644 --- a/packages/web/src/containers/remove-liquidity-container/RemoveLiquidityContainer.tsx +++ b/packages/web/src/containers/remove-liquidity-container/RemoveLiquidityContainer.tsx @@ -22,6 +22,7 @@ const MOCK_DATA = { "id": "0x7a80x0ce176e1b11a8f88a4ba2535de80e81f88592bad", "nftId": "0x7a8", "pool": { + "path": "gno.land/r/bar:gno.land/r/foo:300", "name": "ETH-swETH", "incentivizedType": "INCENTIVIZED", "tokenA": { diff --git a/packages/web/src/hooks/pool/use-pool.tsx b/packages/web/src/hooks/pool/use-pool.tsx index 69116b3d5..ea4965792 100644 --- a/packages/web/src/hooks/pool/use-pool.tsx +++ b/packages/web/src/hooks/pool/use-pool.tsx @@ -31,7 +31,7 @@ export const usePool = ({ }, [pools, tokenA, tokenB]); async function fetchPoolInfos(pools: PoolModel[]) { - const poolInfos = await (await Promise.all(pools.map(pool => poolRepository.getPoolInfoByPoolPath(pool.id).catch(null)))).filter(info => info !== null); + const poolInfos = await (await Promise.all(pools.map(pool => poolRepository.getPoolInfoByPoolPath(pool.path).catch(null)))).filter(info => info !== null); return poolInfos; } @@ -81,8 +81,8 @@ export const usePool = ({ const feetierOfLiquidityMap: { [key in string]: number } = {}; const totalLiquidities = infos.map(info => info.liquidity).reduce((total, cur) => total + cur, 0n); for (const info of infos) { - const liquidityRate = Math.round(Number(info.liquidity / totalLiquidities) * 100); - const feeTier = currentPools.find(pool => pool.id === info.poolPath)?.fee; + const liquidityRate = Number(info.liquidity) * 100 / Number(totalLiquidities); + const feeTier = currentPools.find(pool => pool.path === info.poolPath)?.fee; if (feeTier) { feetierOfLiquidityMap[`${feeTier}`] = liquidityRate; } diff --git a/packages/web/src/models/pool/mapper/pool-mapper.ts b/packages/web/src/models/pool/mapper/pool-mapper.ts index b8c602e44..4e70d31c5 100644 --- a/packages/web/src/models/pool/mapper/pool-mapper.ts +++ b/packages/web/src/models/pool/mapper/pool-mapper.ts @@ -7,6 +7,7 @@ import { PoolCardInfo } from "../info/pool-card-info"; import { PoolSelectItemInfo } from "../info/pool-select-item-info"; import { PoolResponse } from "@repositories/pool"; import { IncentivizedOptions } from "@common/values"; +import { makeId } from "@utils/common"; export class PoolMapper { public static toListInfo(poolModel: PoolModel): PoolListInfo { @@ -129,6 +130,7 @@ export class PoolMapper { const bins = pool.bins.map(bin => ({ ...bin, })); + const id = pool.id ?? makeId(pool.poolPath); const incentivizedTypeStr = pool.incentivizedType?.toUpperCase() || ""; const incentivizedType: IncentivizedOptions = incentivizedTypeStr !== "INCENTIVIZED" @@ -138,6 +140,8 @@ export class PoolMapper { : "NON_INCENTIVIZED"; return { ...pool, + id, + path: pool.poolPath, incentivizedType, bins, }; diff --git a/packages/web/src/models/pool/pool-model.ts b/packages/web/src/models/pool/pool-model.ts index 070594241..1632ccb9e 100644 --- a/packages/web/src/models/pool/pool-model.ts +++ b/packages/web/src/models/pool/pool-model.ts @@ -5,6 +5,8 @@ import { PoolBinModel } from "./pool-bin-model"; export interface PoolModel { id: string; + path: string; + incentivizedType: IncentivizedOptions; name: string; diff --git a/packages/web/src/repositories/pool/mock/pool-detail.json b/packages/web/src/repositories/pool/mock/pool-detail.json index dcfec4a75..ebc3c14ff 100644 --- a/packages/web/src/repositories/pool/mock/pool-detail.json +++ b/packages/web/src/repositories/pool/mock/pool-detail.json @@ -1,6 +1,7 @@ { "pool": { "name": "bar_foo_500", + "path": "gno.land/r/bar:gno.land/r/bar:500", "tokenA": { "chainId": "dev", "createdAt": "2023-10-12T06:56:10+09:00", diff --git a/packages/web/src/repositories/pool/mock/pools.json b/packages/web/src/repositories/pool/mock/pools.json index e8b5dd061..c7bf8d29e 100644 --- a/packages/web/src/repositories/pool/mock/pools.json +++ b/packages/web/src/repositories/pool/mock/pools.json @@ -35,6 +35,7 @@ "volumeChange": 118279700.0, "totalVolume": 1182797.0, "id": "bar_foo_500", + "path": "gno.land/r/bar:gno.land/r/bar:500", "apr": 0.12345, "fee": "0.05%", "feeVolume": 131.937491, diff --git a/packages/web/src/repositories/pool/pool-repository-impl.ts b/packages/web/src/repositories/pool/pool-repository-impl.ts index 9c153d17f..f0cc953d5 100644 --- a/packages/web/src/repositories/pool/pool-repository-impl.ts +++ b/packages/web/src/repositories/pool/pool-repository-impl.ts @@ -92,12 +92,16 @@ export class PoolRepositoryImpl implements PoolRepository { const response = await this.rpcProvider.evaluateExpression( poolPackagePath, param, - ).then(evaluateExpressionToObject) + ).then(evaluateExpressionToObject<{ + response: { + data: PoolRPCResponse + } + }>) .then(response => { - if (!response) { + if (!response?.response?.data) { return null; } - return PoolRPCMapper.from(response); + return PoolRPCMapper.from(response?.response?.data); }) .catch(e => { console.error(e); diff --git a/packages/web/src/repositories/pool/response/pool-list-response.ts b/packages/web/src/repositories/pool/response/pool-list-response.ts index b450d123d..f3ae0265d 100644 --- a/packages/web/src/repositories/pool/response/pool-list-response.ts +++ b/packages/web/src/repositories/pool/response/pool-list-response.ts @@ -9,7 +9,9 @@ export interface PoolListResponse { pools: PoolResponse[]; } export interface PoolResponse { - id: string; + id?: string; + + poolPath: string; incentivizedType?: string; diff --git a/packages/web/src/utils/common.ts b/packages/web/src/utils/common.ts index 9cf82db44..a9cb22572 100644 --- a/packages/web/src/utils/common.ts +++ b/packages/web/src/utils/common.ts @@ -1,3 +1,5 @@ +import * as CryptoJS from "crypto-js"; + export function wait( runner: () => Promise, waitTime = 1000, @@ -27,3 +29,7 @@ export function wait( }, 500); }); } + +export function makeId(value: string) { + return CryptoJS.SHA256(value).toString(); +} diff --git a/yarn.lock b/yarn.lock index bf0806a4c..200d2a06e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2174,6 +2174,7 @@ __metadata: "@testing-library/jest-dom": "npm:5.16.5" "@testing-library/react": "npm:14.0.0" "@testing-library/user-event": "npm:14.4.3" + "@types/crypto-js": "npm:^4.2.1" "@types/d3": "npm:^7.4.0" "@types/jest": "npm:29.4.0" "@types/node": "npm:18.14.6" @@ -2185,6 +2186,7 @@ __metadata: babel-jest: "npm:29.4.3" babel-loader: "npm:9.1.2" bignumber.js: "npm:9.1.1" + crypto-js: "npm:^4.2.0" d3: "npm:^7.8.5" dayjs: "npm:1.11.7" eslint: "npm:8.35.0" @@ -4727,6 +4729,13 @@ __metadata: languageName: node linkType: hard +"@types/crypto-js@npm:^4.2.1": + version: 4.2.1 + resolution: "@types/crypto-js@npm:4.2.1" + checksum: 413a3de36ff916fd796aac6069dc4afba26c3add11c2570eff43f98eb86e34ed8fa2693636743d13685f038f9d3a21e3327b33e3a06c3cb332be5ca64b802925 + languageName: node + linkType: hard + "@types/d3-array@npm:*": version: 3.0.9 resolution: "@types/d3-array@npm:3.0.9" @@ -8500,6 +8509,13 @@ __metadata: languageName: node linkType: hard +"crypto-js@npm:^4.2.0": + version: 4.2.0 + resolution: "crypto-js@npm:4.2.0" + checksum: c7bcc56a6e01c3c397e95aa4a74e4241321f04677f9a618a8f48a63b5781617248afb9adb0629824792e7ec20ca0d4241a49b6b2938ae6f973ec4efc5c53c924 + languageName: node + linkType: hard + "css-loader@npm:^3.6.0": version: 3.6.0 resolution: "css-loader@npm:3.6.0"