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

πŸ”§ fix(build): domain config build issues #54

Merged
merged 3 commits into from
Oct 17, 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
14 changes: 14 additions & 0 deletions configs/domain/get-token-by-token-symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {IToken, TokenSymbol, tokenByTokenSymbol} from "🀝";


export const getTokenByTokenSymbol = (): Record<TokenSymbol, Omit<IToken, 'address'>> => {
const result: Record<TokenSymbol, Omit<IToken, 'address'>> = {} as unknown as Record<TokenSymbol, Omit<IToken, 'address'>>;

for (const symbol of Object.keys(tokenByTokenSymbol) as TokenSymbol[]) {
if (Object.prototype.hasOwnProperty.call(tokenByTokenSymbol, symbol) && tokenByTokenSymbol[symbol].toObject) {
result[symbol] = { ...tokenByTokenSymbol[symbol].toObject() };
}
}

return result;
};
22 changes: 14 additions & 8 deletions configs/domain/get-tokens-by-network.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {ADDRESSES, ADDRESS_ZERO, Common, SystemKeys} from '@oasisdex/addresses'
import {IToken, Network, TokenSymbol, Tokens, tokens} from "🀝";
import {
IToken,
Network,
TokenByTokenSymbol,
TokenSymbol,
tokenByTokenSymbol
} from "🀝";

type TokenSubset = {
[key in TokenSymbol]?: IToken;
Expand All @@ -24,37 +30,37 @@ export const getTokensByNetwork = (): NetworkTokens => {

return {
[Network.MAINNET]: [
...generateEntries(tokens, mainnetCommon)
...generateEntries(tokenByTokenSymbol, mainnetCommon)
],
[Network.OPTIMISM]: [
...generateEntries(tokens, optimismCommon),
...generateEntries(tokenByTokenSymbol, optimismCommon),
],
[Network.ARBITRUM]: [
...generateEntries(tokens, arbitrumCommon),
...generateEntries(tokenByTokenSymbol, arbitrumCommon),
],
[Network.BASE]: [],
[Network.POLYGON]: [],
[Network.GOERLI]: [
...generateEntries(tokens, goerliCommon),
...generateEntries(tokenByTokenSymbol, goerliCommon),
],
[Network.OPTIMISM_GOERLI]: [],
[Network.ARBITRUM_GOERLI]: [],
[Network.POLYGON_MUMBAI]: [],
}
};

function generateEntries(tokens: Tokens, networkCommonAddresses: Record<Common, string>) {
function generateEntries(tokenByTokenSymbol: TokenByTokenSymbol, networkCommonAddresses: Record<Common, string>) {
const entries = [];

for (const tokenSymbol in tokens) {
for (const tokenSymbol in tokenByTokenSymbol) {
// We're forcing the type here because we know that the tokenSymbol is (or should be) a key of Tokens
const address = networkCommonAddresses[tokenSymbol as keyof typeof networkCommonAddresses];

// Check if the address is neither ZERO_ADDRESS nor an empty string.
// Also in case there's no overlap between tokenSymbols and networkCommonAddresses ignore the tokenSymbol
if (address && address !== "" && address !== ADDRESS_ZERO) {
const tokenObject = {
[tokenSymbol]: tokens[tokenSymbol as TokenSymbol].setAddress(address).toObject()
[tokenSymbol]: tokenByTokenSymbol[tokenSymbol as TokenSymbol].setAddress(address).toObject()
};
entries.push(tokenObject);
}
Expand Down
14 changes: 0 additions & 14 deletions configs/domain/get-tokens-by-token-symbol.ts

This file was deleted.

2 changes: 1 addition & 1 deletion configs/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getLabelByDenominationSymbol} from "./get-denomination-symbol";
import {getLabelByLendingProtocol} from "./get-lending-protocols";
import {getNetworkNameByNetwork} from "./get-networks";
import {getTokenByTokenSymbol} from "./get-tokens-by-token-symbol";
import {getTokenByTokenSymbol} from "./get-token-by-token-symbol";
import {getTokensByNetwork} from "./get-tokens-by-network";

export default function () {
Expand Down
6 changes: 3 additions & 3 deletions shared/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Represents individual tokens with their specific attributes.
* The `Token` class encapsulates details like token symbol, precision (for decimal representation),
* and an optional Ethereum address (if assigned). Additionally, the `tokensByTokenSymbol` dictionary
* and an optional Ethereum address (if assigned). Additionally, the `tokenByTokenSymbol` dictionary
* allows for easy retrieval of tokens based on their symbol.
*/

Expand Down Expand Up @@ -100,7 +100,7 @@ const YIELDETH = new Token(TokenSymbol.YIELDETH, 18)
const YFI = new Token(TokenSymbol.YFI, 18)
const ZRX = new Token(TokenSymbol.ZRX, 18)

export type TokensByTokenSymbol = {
export type TokenByTokenSymbol = {
[key in TokenSymbol]: Token;
};

Expand All @@ -109,7 +109,7 @@ export type TokensByTokenSymbol = {
* This allows for easy lookup and provides a unified way to access token-specific details
* throughout the application.
*/
export const tokensByTokenSymbol: TokensByTokenSymbol = {
export const tokenByTokenSymbol: TokenByTokenSymbol = {
ETH,
WETH,
STETH,
Expand Down
Loading