Skip to content

Commit

Permalink
feat: aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
haoquang24 committed May 15, 2023
1 parent d678009 commit 77094d5
Show file tree
Hide file tree
Showing 46 changed files with 5,526 additions and 146 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ NEXT_PUBLIC_ASH_CAPTCHA_ID=
NEXT_PUBLIC_ASH_LOGIN_TWITTER_LINK=
NEXT_PUBLIC_ASH_LOGIN_DISCORD_LINK=
NEXT_PUBLIC_ASH_WALLET_CONNECT_V2_PROJECT_ID=
NEXT_PUBLIC_AG_API=

SENTRY_ENABLE=
SENTRY_AUTH_TOKEN=
Expand Down
112 changes: 112 additions & 0 deletions assets/abi/aggregator.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"buildInfo": {
"rustc": {
"version": "1.70.0-nightly",
"commitHash": "2036fdd24f77d607dcfaa24c48fbe85d3f785823",
"commitDate": "2023-03-27",
"channel": "Nightly",
"short": "rustc 1.70.0-nightly (2036fdd24 2023-03-27)"
},
"contractCrate": {
"name": "aggregator",
"version": "0.0.0"
},
"framework": {
"name": "multiversx-sc",
"version": "0.40.0"
}
},
"name": "AggregatorContract",
"constructor": {
"inputs": [],
"outputs": []
},
"endpoints": [
{
"name": "aggregate",
"mutability": "mutable",
"payableInTokens": [
"*"
],
"inputs": [
{
"name": "steps",
"type": "List<AggregatorStep>"
},
{
"name": "limits",
"type": "variadic<TokenAmount>",
"multi_arg": true
}
],
"outputs": [
{
"type": "List<EsdtTokenPayment>"
}
]
}
],
"events": [],
"hasCallback": false,
"types": {
"AggregatorStep": {
"type": "struct",
"fields": [
{
"name": "token_in",
"type": "TokenIdentifier"
},
{
"name": "token_out",
"type": "TokenIdentifier"
},
{
"name": "amount_in",
"type": "BigUint"
},
{
"name": "pool_address",
"type": "Address"
},
{
"name": "function_name",
"type": "bytes"
},
{
"name": "arguments",
"type": "List<bytes>"
}
]
},
"EsdtTokenPayment": {
"type": "struct",
"fields": [
{
"name": "token_identifier",
"type": "TokenIdentifier"
},
{
"name": "token_nonce",
"type": "u64"
},
{
"name": "amount",
"type": "BigUint"
}
]
},
"TokenAmount": {
"type": "struct",
"fields": [
{
"name": "token",
"type": "TokenIdentifier"
},
{
"name": "amount",
"type": "BigUint"
}
]
}
}
}
Binary file modified assets/images/fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/protocols/ashswap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/protocols/xexchange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions assets/svg/hierarchy-square.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 9 additions & 33 deletions atoms/tokensState.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { FARMS } from "const/farms";
import pools from "const/pool";
import { TOKENS, TOKENS_MAP } from "const/tokens";
import { IESDTInfo } from "helper/token/token";
import { TokenAmount } from "helper/token/tokenAmount";
import { IMetaESDT } from "interface/tokens";
import { atom, selectorFamily } from "recoil";
import { atom, atomFamily, selectorFamily } from "recoil";
import { KeyedMutator } from "swr";
type Token = {
identifier: string;
type Token = IESDTInfo & {
balance: string;
decimals: number;
name: string;
symbol: string;
icon?: string;
valueUsd: number;
price: number;
};
const defaultTokenMapState: Record<string, Token> = Object.fromEntries(
TOKENS.map((t) => {
const token: Token = {
identifier: t.identifier,
...t,
balance: "0",
decimals: t.decimals,
name: t.name,
symbol: t.symbol,
icon: t.logoURI,
valueUsd: 0,
price: 0,
};
Expand All @@ -34,26 +25,6 @@ export const tokenMapState = atom<Record<string, Token>>({
key: "token_map_state",
default: defaultTokenMapState,
});
const defaultLPTokenMapState = Object.fromEntries(
pools.map((p) => {
const lpToken = p.lpToken;
const token: Token = {
identifier: lpToken.identifier,
balance: "0",
decimals: lpToken.decimals,
name: lpToken.name,
symbol: lpToken.symbol,
icon: lpToken.logoURI,
valueUsd: 0,
price: 0,
};
return [lpToken.identifier, token];
})
);
export const lpTokenMapState = atom<Record<string, Token>>({
key: "lp_token_map_state",
default: defaultLPTokenMapState,
});

const defaultFarmTokenMapState = Object.fromEntries(
FARMS.map((f) => {
Expand Down Expand Up @@ -85,3 +56,8 @@ export const tokenBalanceSelector = selectorFamily<TokenAmount | undefined, stri
return new TokenAmount(TOKENS_MAP[tokenId], tokenMap[tokenId].balance);
}
});

export const tokenInfoOnNetworkAtom = atomFamily<IESDTInfo, string>({
key: "token_info_on_network_atom_family",
default: undefined,
});
48 changes: 48 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: "http://localhost:3001/graphql",
documents: [
"graphql/**/*.gql",
// "pages/**/*.gql", "components/**/*.gql", "views/**/*.gql"
],
generates: {
// "./generated/gql/": {
// preset: "client",
// },
"./generated/gql/schema.graphql": {
plugins: ["schema-ast"],
},
"./generated/gql/fragmentMetadata.json": {
plugins: ["fragment-matcher"],
},
"./generated/gql/operations.ts": {
plugins: ["typescript-document-nodes"],
},
"./generated/gql/graphql-codegen-generated.ts": {
plugins: [
{
add: {
content: "/* tslint:disable */",
},
},
"typescript",
"typescript-operations",
"typescript-graphql-request",
],
config: {
declarationKind: "interface",
enumsAsTypes: true,
nonOptionalTypename: true,
preResolveTypes: true,
scalars: {
BigInt: "string",
BigDecimal: "string",
Bytes: "string",
AmountHumanReadable: "string",
},
},
},
},
};
export default config;
15 changes: 5 additions & 10 deletions components/AddressMenu/WalletBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import ImgEgldIcon from "assets/images/egld-icon.png";
import { accBalanceState } from "atoms/dappState";
import { lpTokenMapState, tokenMapState } from "atoms/tokensState";
import { tokenMapState } from "atoms/tokensState";
import BigNumber from "bignumber.js";
import Avatar from "components/Avatar";
import TextAmt from "components/TextAmt";
import { CHAIN_ID } from "const/dappConfig";
import { ENVIRONMENT } from "const/env";
import pools from "const/pool";
import { TOKENS } from "const/tokens";
import { WRAPPED_EGLD } from "const/wrappedEGLD";
import { toEGLDD } from "helper/balance";
import { IESDTInfo } from "helper/token/token";
import Link from "next/link";
import { useMemo } from "react";
import { useRecoilValue } from "recoil";
import Link from "next/link";
import { WRAPPED_EGLD } from "const/wrappedEGLD";
type TokenWithBalance = IESDTInfo & {
balance: BigNumber;
};
Expand Down Expand Up @@ -75,7 +71,6 @@ const TokenBalance = ({ data }: { data: TokenWithBalance }) => {
};
function WalletBalance() {
const tokenMap = useRecoilValue(tokenMapState);
const lpTokenMap = useRecoilValue(lpTokenMapState);
const ashSupportedBalances = useMemo(() => {
const supportedTokens: TokenWithBalance[] = TOKENS.map((t) => {
return {
Expand All @@ -90,14 +85,14 @@ function WalletBalance() {
return {
...t,
balance: new BigNumber(
lpTokenMap[t.identifier]?.balance || 0
tokenMap[t.identifier]?.balance || 0
),
};
})
.filter((t) => t.balance.gt(0));

return [...supportedTokens, ...lpTokens];
}, [tokenMap, lpTokenMap]);
}, [tokenMap]);
return (
<div className="bg-stake-dark-500 py-4">
<div className="px-6 text-stake-gray-500 text-xs font-bold mb-4">
Expand Down
13 changes: 13 additions & 0 deletions components/Avatar/TokenAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { memo } from "react";
import useGetESDTInfo from "hooks/useGetESDTInfo";
import Avatar from ".";

type Props = Omit<Parameters<typeof Avatar>[0], "src" | "alt"> & {
identifier: string;
};
function TokenAvatar({ identifier, ...props }: Props) {
const token = useGetESDTInfo(identifier);
return <Avatar src={token?.logoURI} alt={token?.name} {...props} />;
}

export default memo(TokenAvatar);
9 changes: 5 additions & 4 deletions components/BaseModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Transition, TransitionClasses } from "@headlessui/react";
import IconClose from "assets/svg/close.svg";
import customTwMerge from "helper/customTwMerge";
import { useScreenSize } from "hooks/useScreenSize";
import moment from "moment";
import {
createContext,
Fragment,
createContext,
useContext,
useEffect,
useMemo,
Expand Down Expand Up @@ -38,11 +38,12 @@ const CONTAINER = {
modal: "",
};
Modal.setAppElement("body");
export type BaseModalType = Props & {
export type BaseModalType = Omit<Props, "className"> & {
transition?: "btt" | "center" | "none";
type?: "modal" | "drawer_btt" | "drawer_ttb" | "drawer_ltr" | "drawer_rtl";
mobileType?: "modal" | "drawer_btt" | "drawer_ttb" | "drawer_ltr" | "drawer_rtl";
destroyOnClose?: boolean;
className?: string;
};
const ModalContext = createContext<BaseModalType>({ isOpen: false });

Expand Down Expand Up @@ -153,7 +154,7 @@ const BaseModal = (props: BaseModalType) => {
afterLeave={() => setAnimating(false)}
>
<div
className={`${CONTAINER[type]} ${props.className}`}
className={customTwMerge(CONTAINER[type], props.className)}
>
{props.children}
</div>
Expand Down
Loading

0 comments on commit 77094d5

Please sign in to comment.