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

add flag to indicate swimUSD & do not mark them as stable coin #438

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@solana/spl-token": "^0.3.5",
"@solana/web3.js": "^1.62.0",
"@swim-io/aptos": "^0.36.0",
"@swim-io/core": "^0.36.0",
"@swim-io/core": "workspace:^",
"@swim-io/evm": "^0.36.0",
"@swim-io/evm-contracts": "^0.36.0",
"@swim-io/pool-math": "^0.36.0",
Expand Down
3 changes: 2 additions & 1 deletion apps/ui/src/components/SwapForm/SwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ export const SwapForm = ({ maxSlippageFraction }: Props): ReactElement => {

const isLargeSwap = useIsLargeSwap(fromToken, toToken, inputAmount);
const isSmallEthSwap =
TOKEN_PROJECTS_BY_ID[fromToken.projectId].isStablecoin &&
(TOKEN_PROJECTS_BY_ID[fromToken.projectId].isStablecoin ||
TOKEN_PROJECTS_BY_ID[fromToken.projectId].isSwimUsd) &&
[fromToken.nativeEcosystemId, toToken.nativeEcosystemId].includes(
EvmEcosystemId.Ethereum,
) &&
Expand Down
3 changes: 2 additions & 1 deletion apps/ui/src/components/SwapFormV2/SwapFormV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export const SwapFormV2 = ({ maxSlippageFraction }: Props): ReactElement => {
inputAmount,
);
const isSmallEthSwap =
TOKEN_PROJECTS_BY_ID[fromTokenConfig.projectId].isStablecoin &&
(TOKEN_PROJECTS_BY_ID[fromTokenConfig.projectId].isStablecoin ||
TOKEN_PROJECTS_BY_ID[fromTokenConfig.projectId].isSwimUsd) &&
[fromTokenOption.ecosystemId, toTokenOption.ecosystemId].includes(
EvmEcosystemId.Ethereum,
) &&
Expand Down
6 changes: 4 additions & 2 deletions apps/ui/src/hooks/swim/useIsLargeSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export const useIsLargeSwap = (
const inputPoolUsdValue = pools[0].poolUsdValue;
const outputPoolUsdValue = pools[pools.length - 1].poolUsdValue;
const outputAmount = useSwapOutputAmountEstimate(inputAmount, toToken);
const fromTokenProject = TOKEN_PROJECTS_BY_ID[fromToken.projectId];
const toTokenProject = TOKEN_PROJECTS_BY_ID[toToken.projectId];
return (
(TOKEN_PROJECTS_BY_ID[fromToken.projectId].isStablecoin &&
((fromTokenProject.isStablecoin || fromTokenProject.isSwimUsd) &&
inputPoolUsdValue !== null &&
inputAmount
.toHuman(SOLANA_ECOSYSTEM_ID)
.gt(inputPoolUsdValue.mul(0.1))) ||
(TOKEN_PROJECTS_BY_ID[toToken.projectId].isStablecoin &&
((toTokenProject.isStablecoin || toTokenProject.isSwimUsd) &&
outputPoolUsdValue !== null &&
outputAmount !== null &&
outputAmount.toHuman(SOLANA_ECOSYSTEM_ID).gt(outputPoolUsdValue.mul(0.1)))
Expand Down
8 changes: 6 additions & 2 deletions apps/ui/src/hooks/swim/useIsLargeSwapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ export const useIsLargeSwapV2 = (
}
const inputBalance = sum(poolBalances[0]);
const outputBalance = sum(poolBalances[poolBalances.length - 1]);
const fromTokenProject =
TOKEN_PROJECTS_BY_ID[fromTokenOption.tokenConfig.projectId];
const toTokenProject =
TOKEN_PROJECTS_BY_ID[toTokenOption.tokenConfig.projectId];
return (
(TOKEN_PROJECTS_BY_ID[fromTokenOption.tokenConfig.projectId].isStablecoin &&
((fromTokenProject.isStablecoin || fromTokenProject.isSwimUsd) &&
inputBalance !== null &&
inputAmount.gt(inputBalance.mul(0.1))) ||
(TOKEN_PROJECTS_BY_ID[toTokenOption.tokenConfig.projectId].isStablecoin &&
((toTokenProject.isStablecoin || toTokenProject.isSwimUsd) &&
outputBalance !== null &&
outputAmount !== null &&
outputAmount.gt(outputBalance.mul(0.1)))
Expand Down
9 changes: 6 additions & 3 deletions apps/ui/src/hooks/swim/usePoolUsdValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ export const usePoolUsdValues = (poolSpecs: readonly PoolSpec[]) => {
poolTokens.some(
(tokenConfig) =>
!TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isStablecoin &&
!TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isSwimUsd &&
!prices.get(tokenConfig.id),
)
) {
return new Decimal(0);
}
return poolTokens.reduce((sum, tokenConfig, i) => {
const price = TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isStablecoin
? new Decimal(1)
: prices.get(tokenConfig.id) ?? new Decimal(1);
const price =
TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isStablecoin ||
TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isSwimUsd
? new Decimal(1)
: prices.get(tokenConfig.id) ?? new Decimal(1);
return sum.add(poolBalances[i].mul(price));
}, new Decimal(0));
}
Expand Down
3 changes: 2 additions & 1 deletion apps/ui/src/models/amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export class Amount {
i18next.resolvedLanguage,
);
const numberFormatter = new Intl.NumberFormat(language, {
...(TOKEN_PROJECTS_BY_ID[this.tokenConfig.projectId].isStablecoin
...(TOKEN_PROJECTS_BY_ID[this.tokenConfig.projectId].isStablecoin ||
TOKEN_PROJECTS_BY_ID[this.tokenConfig.projectId].isSwimUsd
? {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
Expand Down
9 changes: 6 additions & 3 deletions apps/ui/src/models/swim/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ export const getPoolUsdValue = (
tokens: readonly TokenConfig[],
poolTokenAccounts: readonly TokenAccount[],
): Decimal | null =>
tokens.every(
(tokenConfig) => TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isStablecoin,
)
tokens.every((tokenConfig) => {
return (
TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isStablecoin ||
TOKEN_PROJECTS_BY_ID[tokenConfig.projectId].isSwimUsd
);
})
? poolTokenAccounts.reduce((acc, account) => {
const tokenConfig = tokens.find(
(spec) =>
Expand Down
11 changes: 10 additions & 1 deletion packages/token-projects/src/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ describe("Token Project", () => {
expect(tokenNumbers).toEqual(Array.from(new Set(tokenNumbers)));
});

it.each(Object.values(TOKEN_PROJECTS_BY_ID))(
"should have correct isSwimUsd flag ($id)",
(tokenProject) => {
expect(tokenProject.isSwimUsd).toBe(
/swimUSD/i.test(tokenProject.displayName),
);
},
);

it.each(Object.values(TOKEN_PROJECTS_BY_ID))(
"should have unique token number within range ($id)",
(tokenProject) => {
/* eslint-disable jest/no-conditional-expect */
if (typeof tokenProject.tokenNumber !== "number") {
expect(tokenProject.tokenNumber).toBeNull();
} else if (tokenProject.isStablecoin && tokenProject.isLp) {
} else if (tokenProject.isSwimUsd) {
// case for swimUSD
expect(tokenProject.tokenNumber).toBeGreaterThanOrEqual(0x0000);
expect(tokenProject.tokenNumber).toBeLessThanOrEqual(0x00ff);
Expand Down
Loading