Skip to content

Commit

Permalink
fix: use tezos token list
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <ojuswimail@gmail.com>
  • Loading branch information
OjusWiZard committed Jan 9, 2024
1 parent d57b773 commit b1aba35
Show file tree
Hide file tree
Showing 11 changed files with 719 additions and 279 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@
"@injectivelabs/sdk-ts": "^1.10.58",
"@pancakeswap/sdk": "^4.0.0",
"@pancakeswap/smart-router": "^4.2.1",
"@pancakeswap/tokens": "^0.1.6",
"@pancakeswap/swap-sdk-core": "^1.0.0",
"@pancakeswap/tokens": "^0.1.6",
"@pancakeswap/v3-core": "^1.0.2",
"@pancakeswap/v3-periphery": "^1.0.2",
"@pancakeswap/v3-sdk": "^3.7.0",
"@pangolindex/sdk": "^1.1.0",
"@perp/sdk-curie": "^1.16.0",
"@quipuswap/tokens-whitelist": "^1.1.24",
"@sushiswap/sdk": "^5.0.0-canary.116",
"@taquito/rpc": "^17.0.0",
"@taquito/signer": "^17.0.0",
Expand Down Expand Up @@ -103,8 +102,8 @@
"web3": "^1.7.3",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5",
"xsswap-sdk": "^1.0.1",
"xrpl": "^2.7.0",
"xsswap-sdk": "^1.0.1",
"yarn": "^1.22.17"
},
"devDependencies": {
Expand Down
36 changes: 21 additions & 15 deletions src/connectors/quipuswap/utils/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import GhostnetWhitelistTokens from '@quipuswap/tokens-whitelist/tokens/quipuswap-ithacanet.whitelist.json';
import MainnetWhitelistTokens from '@quipuswap/tokens-whitelist/tokens/quipuswap.whitelist.json';
import GhostnetTokens from '../../../../templates/lists/tezos.ghostnet.tokens.json';
import MainnetTokens from '../../../../templates/lists/tezos.mainnet.tokens.json';
import { DexTypeEnum } from 'swap-router-sdk';
import { ConnectType, QSNetwork, QSNetworkType, NetworkType, SupportedNetwork } from '../shared/types';

export const IPFS_GATEWAY = 'https://cloudflare-ipfs.com/ipfs';
import { ConnectType, QSNetwork, QSNetworkType, NetworkType, SupportedNetwork, Token } from '../shared/types';
import { mapBackendToken } from '../shared/backend.token.map';

export const KNOWN_DEX_TYPES = [
DexTypeEnum.QuipuSwap,
Expand All @@ -14,22 +13,29 @@ export const KNOWN_DEX_TYPES = [
DexTypeEnum.YupanaWtez
];

const tokenStandardiser = (token: typeof MainnetWhitelistTokens.tokens[0]) => {
if (token.metadata.symbol === 'TEZ')
token.metadata.symbol = 'XTZ';
else
token.metadata.symbol = token.metadata.symbol.toUpperCase();
return token;
const tokenStandardiser = (token: typeof MainnetTokens.tokens[0]): Token => {
// token.symbol = token.symbol.toUpperCase();
// return token;
return mapBackendToken({
contractAddress: token.address ?? 'tez',
type: token.standard,
fa2TokenId: token.tokenId ?? undefined,
metadata: {
decimals: token.decimals,
name: token.name,
symbol: token.symbol.toUpperCase(),
}
})
};

const TOKENS_MAP = {
[NetworkType.MAINNET]: {
...MainnetWhitelistTokens,
tokens: MainnetWhitelistTokens.tokens.map(tokenStandardiser)
...MainnetTokens,
tokens: MainnetTokens.tokens.map(tokenStandardiser)
},
[NetworkType.GHOSTNET]: {
...GhostnetWhitelistTokens,
tokens: GhostnetWhitelistTokens.tokens.map(tokenStandardiser)
...GhostnetTokens,
tokens: GhostnetTokens.tokens.map(tokenStandardiser)
}
};

Expand Down
7 changes: 0 additions & 7 deletions src/connectors/quipuswap/utils/config/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import { NetworkType, Standard, SupportedNetwork, Token } from "../shared/types";
import { IPFS_GATEWAY } from "./config";

export const TEZOS_TOKEN: Token = {
type: Standard.Fa12,
contractAddress: 'tez',
isWhitelisted: true,
metadata: {
decimals: 6,
name: 'Tezos',
symbol: 'XTZ',
thumbnailUri: `${IPFS_GATEWAY}/Qmf3brydfr8c6CKGUUu73Dd7wfBw66Zbzof5E1BWGeU222`
}
};

export const MAINNET_QUIPU_TOKEN: Token = {
type: Standard.Fa2,
contractAddress: 'KT193D4vozYnhGJQVtw7CoxxqphqUEEwK6Vb',
fa2TokenId: 0,
isWhitelisted: true,
metadata: {
decimals: 6,
symbol: 'QUIPU',
name: 'Quipuswap Governance Token',
thumbnailUri: 'https://quipuswap.com/tokens/quipu.png'
}
};

Expand All @@ -40,12 +35,10 @@ export const MAINNET_WTEZ_TOKEN: Token = {
type: Standard.Fa2,
contractAddress: 'KT1UpeXdK6AJbX58GJ92pLZVCucn2DR8Nu4b',
fa2TokenId: 0,
isWhitelisted: true,
metadata: {
decimals: 6,
symbol: 'wTEZ',
name: 'Wrapped Tezos FA2 token',
thumbnailUri: 'ipfs://QmUWhCYXtC8r8aXgjrwsLrZmopiGMHdLWoQzEueAktJbHB'
}
};

Expand Down
1 change: 0 additions & 1 deletion src/connectors/quipuswap/utils/shared/backend.token.map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { RawToken, Standard, Token } from './types';
export const mapBackendToken = (raw: RawToken, newSymbol?: string): Token => ({
...raw,
fa2TokenId: raw.fa2TokenId === undefined ? undefined : Number(raw.fa2TokenId),
isWhitelisted: !!raw.isWhitelisted,
type: raw.type as Standard,
metadata: {
...raw.metadata,
Expand Down
19 changes: 4 additions & 15 deletions src/connectors/quipuswap/utils/shared/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BigNumber from "bignumber.js";
import { NetworkType, Nullable, Optional, QSNetwork, Standard, SupportedNetwork, Token, TokenAddress, TokenId, TokenWithQSNetworkType, Undefined } from "./types";
import { TEZOS_TOKEN, networksQuipuTokens } from "../config/tokens";
import { getSavedTokensApi } from "./local.storage";
import { mapBackendToken } from "./backend.token.map";
import { InvalidTokensListError } from "./errors";
import { networkTokens } from "../config/config";
Expand Down Expand Up @@ -57,38 +56,28 @@ export const toAtomic = (real: BigNumber, decimalsOrToken: Optional<number | Tok
);


export const getFallbackTokens = (network: QSNetwork, addTokensFromLocalStorage?: boolean) => {
export const getFallbackTokens = (network: QSNetwork) => {
let tokens: Array<TokenWithQSNetworkType> = [
{
...TEZOS_TOKEN,
network: network.id
},
networksQuipuTokens[network.id]
];

if (addTokensFromLocalStorage) {
tokens = tokens.concat(getSavedTokensApi(network.id));
}

return getUniqArray(tokens, getTokenSlug);
};

export const isTokenEqual = (a: TokenAddress, b: TokenAddress) =>
a.contractAddress === b.contractAddress && a.fa2TokenId === b.fa2TokenId;

export const getTokens = (network: QSNetwork, addTokensFromLocalStorage?: boolean) => {
let tokens = getFallbackTokens(network, addTokensFromLocalStorage);
export const getTokens = (network: QSNetwork) => {
let tokens = getFallbackTokens(network);

const _networkTokens = networkTokens(network.id);
const arr: Token[] = _networkTokens?.tokens?.length ? _networkTokens.tokens.map(token => mapBackendToken(token)) : [];

if (arr.length) {
const Tokens: Token[] = arr.map(token => ({
...token,
isWhitelisted: true
}));

tokens = tokens.filter(fallbackToken => !Tokens.some(token => isTokenEqual(fallbackToken, token))).concat(Tokens);
tokens = tokens.filter(fallbackToken => !arr.some(token => isTokenEqual(fallbackToken, token))).concat(arr);
} else {
throw new InvalidTokensListError(networkTokens);
}
Expand Down
25 changes: 0 additions & 25 deletions src/connectors/quipuswap/utils/shared/local.storage.ts

This file was deleted.

6 changes: 1 addition & 5 deletions src/connectors/quipuswap/utils/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export type Optional<T> = T | null | undefined;
export type Undefined<T> = T | undefined;
export type Nullable<T> = T | null;

export interface RawToken extends Omit<Token, 'type' | 'isWhitelisted'> {
export interface RawToken extends Omit<Token, 'type'> {
type: string;
isWhitelisted?: boolean;
}

export type TokenId = Pick<Token, 'contractAddress' | 'fa2TokenId' | 'type'>;
Expand All @@ -33,13 +32,10 @@ export interface TokenMetadata {
decimals: number;
symbol: string;
name: string;
thumbnailUri: string;
categories?: Array<string>;
}

export interface Token extends TokenAddress {
type: Standard;
isWhitelisted: Nullable<boolean>;
metadata: TokenMetadata;
}

Expand Down
2 changes: 1 addition & 1 deletion src/connectors/quipuswap/utils/swap.outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const findQuipuSwapV3Output = (aTokenAmount: BigNumber, pair: TradeOperat

return output;
} catch (e) {
return new Nat(-1);
return new Nat(0);
}
};

Expand Down
88 changes: 88 additions & 0 deletions src/templates/lists/tezos.ghostnet.tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,94 @@
"decimals": 6,
"standard": "FA2",
"tokenId": 2
},
{
"name": "Tezos",
"symbol": "XTZ",
"address": null,
"decimals": 6,
"standard": "TEZ",
"tokenId": null
},
{
"name": "Apple Token",
"symbol": "Apple",
"address": "KT1BRxbKjhRabGSB6saqK6QrBenaSvFJSgHu",
"decimals": 10,
"standard": "FA1.2",
"tokenId": 0
},
{
"name": "GOLD Token",
"symbol": "GOLD",
"address": "KT1PzyU2nXYW8RkoFqmqWPFCA7bgC7yGNRoC",
"decimals": 12,
"standard": "FA1.2",
"tokenId": 0
},
{
"name": "Test youves BTC",
"symbol": "uBTC",
"address": "KT1N4NfnYmJucXYkuPdvJG4Jxbz3TetCTqJc",
"decimals": 12,
"standard": "FA2",
"tokenId": 2
},
{
"name": "Test tzBTC",
"symbol": "tzBTC",
"address": "KT1Wdq6sj3ZkNqQ7CeE6kTNbJXfobMX7Eqpz",
"decimals": 8,
"standard": "FA1.2",
"tokenId": 0
},
{
"name": "Test youves USD",
"symbol": "uUSD",
"address": "KT1N4NfnYmJucXYkuPdvJG4Jxbz3TetCTqJc",
"decimals": 12,
"standard": "FA2",
"tokenId": 0
},
{
"name": "Test Kolibri USD",
"symbol": "kUSD",
"address": "KT1GG8Zd5rUp1XV8nMPRBY2tSyVn6NR5F4Q1",
"decimals": 18,
"standard": "FA1.2",
"tokenId": 0
},
{
"name": "Test USDtez",
"symbol": "USDtz",
"address": "KT1QzmrMs1xUXZJ8TPAoDEFaKC6w56RfdLWo",
"decimals": 6,
"standard": "FA1.2",
"tokenId": 0
},
{
"name": "Ethereum USDC",
"symbol": "USDC.e",
"address": "KT1A4W7CfD5sKkWXJke392jVmxSA6vaHrdWk",
"decimals": 6,
"standard": "FA2",
"tokenId": 2
},
{
"name": "Quipuswap Governance Token",
"symbol": "QUIPU",
"address": "KT19363aZDTjeRyoDkSLZhCk62pS4xfvxo6c",
"decimals": 6,
"standard": "FA2",
"tokenId": 0
},
{
"name": "Wrapped Tezos FA2 token",
"symbol": "wTEZ",
"address": "KT1L8ujeb25JWKa4yPB61ub4QG2NbaKfdJDK",
"decimals": 6,
"standard": "FA2",
"tokenId": 0
}
]
}
Loading

0 comments on commit b1aba35

Please sign in to comment.