Skip to content
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

[GSW-606] feat: Change the parameters of pool contarct #239

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/swap-router/.ultra.cache.json
Original file line number Diff line number Diff line change
@@ -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":{}}
{"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":{}}
2 changes: 2 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const SelectFeeTier: React.FC<SelectFeeTierProps> = ({
selected={feeTier === item}
feeTier={item}
pools={pools}
liquidityRange={feetierOfLiquidityMap[SwapFeeTierInfoMap[item].fee] || null}
liquidityRange={feetierOfLiquidityMap[SwapFeeTierInfoMap[item].fee]}
onClick={() => onClickFeeTierItem(item)}
/>
))}
Expand Down Expand Up @@ -61,7 +61,7 @@ const SelectFeeTierItem: React.FC<SelectFeeTierItemProps> = ({
if (liquidityRange === null) {
return "Not created";
}
return `${liquidityRange}% Select`;
return `${Math.round(liquidityRange)}% Select`;
}, [liquidityRange]);

const description = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/hooks/pool/use-pool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/web/src/models/pool/mapper/pool-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand All @@ -138,6 +140,8 @@ export class PoolMapper {
: "NON_INCENTIVIZED";
return {
...pool,
id,
path: pool.poolPath,
incentivizedType,
bins,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/models/pool/pool-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { PoolBinModel } from "./pool-bin-model";
export interface PoolModel {
id: string;

path: string;

incentivizedType: IncentivizedOptions;

name: string;
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/repositories/pool/mock/pool-detail.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/repositories/pool/mock/pools.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions packages/web/src/repositories/pool/pool-repository-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ export class PoolRepositoryImpl implements PoolRepository {
const response = await this.rpcProvider.evaluateExpression(
poolPackagePath,
param,
).then(evaluateExpressionToObject<PoolRPCResponse>)
).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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export interface PoolListResponse {
pools: PoolResponse[];
}
export interface PoolResponse {
id: string;
id?: string;

poolPath: string;

incentivizedType?: string;

Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as CryptoJS from "crypto-js";

export function wait<T>(
runner: () => Promise<T>,
waitTime = 1000,
Expand Down Expand Up @@ -27,3 +29,7 @@ export function wait<T>(
}, 500);
});
}

export function makeId(value: string) {
return CryptoJS.SHA256(value).toString();
}
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down