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

🌟 feat(domain-config): Domain config for Tokens/LendingProtocols etc #51

Merged
merged 19 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 13 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 modified bun.lockb
Binary file not shown.
Empty file added configs/domain/README.md
Empty file.
6 changes: 6 additions & 0 deletions configs/domain/get-denomination-symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {DenominationSymbols} from "🀝";
import {EnumToObject, enumToObject} from "πŸ› οΈ";

export const getDenominationSymbols = (): EnumToObject<typeof DenominationSymbols> => {
return enumToObject(DenominationSymbols)
};
11 changes: 11 additions & 0 deletions configs/domain/get-lending-protocols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { LendingProtocol, LendingProtocolLabel} from "🀝";

export const getLendingProtocols = (): Record<LendingProtocol, LendingProtocolLabel> => {
return {
[LendingProtocol.AaveV2]: LendingProtocolLabel.aavev2,
[LendingProtocol.AaveV3]: LendingProtocolLabel.aavev3,
[LendingProtocol.Ajna]: LendingProtocolLabel.ajna,
[LendingProtocol.Maker]: LendingProtocolLabel.maker,
[LendingProtocol.SparkV3]: LendingProtocolLabel.sparkv3,
}
};
6 changes: 6 additions & 0 deletions configs/domain/get-networks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {EnumToObject, enumToObject} from "πŸ› οΈ";
import {Networks} from "🀝";

export const getNetworks = (): EnumToObject<typeof Networks> => {
return enumToObject(Networks)
};
64 changes: 64 additions & 0 deletions configs/domain/get-tokens-by-network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {ADDRESSES, ADDRESS_ZERO, Common, SystemKeys} from '@oasisdex/addresses'
import {IToken, Networks, TokenSymbols, Tokens, tokens} from "🀝";

type TokenSubset = {
[key in TokenSymbols]?: IToken;
};

type NetworkTokens = {
[network in Networks]: TokenSubset[];
};

/**
* Returns tokens for each network
* Can be enhanced to return address enriched tokens for each network
*/
export const getTokensByNetwork = (): NetworkTokens => {
const mainnetCommon = ADDRESSES[Networks.MAINNET][SystemKeys.COMMON]
const optimismCommon = ADDRESSES[Networks.OPTIMISM][SystemKeys.COMMON]
const arbitrumCommon = ADDRESSES[Networks.ARBITRUM][SystemKeys.COMMON]
// const baseCommon = ADDRESSES[Networks.BASE][SystemKeys.COMMON]
// const polygonCommon = ADDRESSES[Networks.POLYGON][SystemKeys.COMMON]
const goerliCommon = ADDRESSES[Networks.GOERLI][SystemKeys.COMMON]
// const optimismGoerliCommon = ADDRESSES[Networks.OPTIMISM_GOERLI][SystemKeys.COMMON]

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

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

for (const tokenSymbol in tokens) {
// 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 TokenSymbols].setAddress(address).toObject()
};
entries.push(tokenObject);
}
}

return entries
}
14 changes: 14 additions & 0 deletions configs/domain/get-tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {IToken, TokenSymbols, tokens} from "🀝";


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

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

return result;
};
21 changes: 21 additions & 0 deletions configs/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {getDenominationSymbols} from "./get-denomination-symbols";
import {getLendingProtocols} from "./get-lending-protocols";
import {getNetworks} from "./get-networks";
import {getTokens} from "./get-tokens";
import {getTokensByNetwork} from "./get-tokens-by-network";

export default function () {
/**
* Goal is to capture domain specific configurations that is common
* across all Summer.fi systems and apps.
*
* Possible extensions could include Products / Product categories / Strategies etc
*/
return {
tokens: getTokens(),
tokensByNetwork: getTokensByNetwork(),
lendingProtocols: getLendingProtocols(),
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
networks: getNetworks(),
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
denominationSymbols: getDenominationSymbols()
piotrwitek marked this conversation as resolved.
Show resolved Hide resolved
};
}
6 changes: 4 additions & 2 deletions configs/oasis-borrow/getNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {TokenSymbols} from "🀝";

export const getNavigation= () => ({
protocols: {
ajna: {
Expand Down Expand Up @@ -70,7 +72,7 @@ export const getNavigation= () => ({
},
},
tokens: {
popular: ['ETH', 'STETH', 'RETH', 'CBETH', 'DAI', 'WBTC', 'USDC'],
new: ['SDAI'],
popular: [TokenSymbols.ETH, TokenSymbols.STETH, TokenSymbols.RETH, TokenSymbols.CBETH, TokenSymbols.DAI, TokenSymbols.WBTC, TokenSymbols.USDC],
new: [TokenSymbols.SDAI],
},
})
3 changes: 2 additions & 1 deletion configs/oasis-borrow/getParameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigHelperType } from "⌨️";
import {TokenSymbols} from "🀝";

export const getParameters = ({
notProduction,
Expand All @@ -13,7 +14,7 @@ export const getParameters = ({
showFlashloanInformation: notProduction,
},
closeDisabledFor: {
collateral: ["DAI", "USDC"],
collateral: [TokenSymbols.DAI, TokenSymbols.USDC],
strategyTypes: ["short"],
},
adjustDisabledFor: {
Expand Down
2 changes: 2 additions & 0 deletions helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export const constants = {
configFolder: path.join(__dirname, "../configs"),
distFolder: path.join(__dirname, "../dist"),
};


12 changes: 12 additions & 0 deletions helpers/enum-to-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type EnumToObject<E extends Record<string, string>> = {
[K in keyof E]: E[K];
};

export function enumToObject<E extends Record<string, string>>(e: E): { [K in keyof E]: E[K] } {
return Object.keys(e)
.filter(key => isNaN(Number(key)))
.reduce((obj, key) => {
obj[key as keyof E] = e[key as keyof E];
return obj;
}, {} as { [K in keyof E]: E[K] });
}
13 changes: 7 additions & 6 deletions helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { constants } from "./constants";
export { generateConfigs } from "./generate-configs";
export { getConfigMainModules } from "./get-config-main-modules";
export { getEnvironments } from "./get-environments";
export { parseConfig } from "./parse-config";
export { createConfigFiles } from "./create-config-files";
export {constants} from "./constants";
export {generateConfigs} from "./generate-configs";
export {getConfigMainModules} from "./get-config-main-modules";
export {getEnvironments} from "./get-environments";
export {parseConfig} from "./parse-config";
export {createConfigFiles} from "./create-config-files";
export * from './enum-to-object'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"homepage": "https://github.com/OasisDEX/oazo-configuration#readme",
"dependencies": {
"@oasisdex/addresses": "0.1.7",
"@types/node": "^20.5.9",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
Expand Down
22 changes: 22 additions & 0 deletions shared/denomination-symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export enum DenominationSymbols {
USD = 'USD',
ETH = 'ETH',
BTC = 'BTC',
GBP = 'GBP',
EUR = 'EUR',
JPY = 'JPY',
KRW = 'KRW',
CNY = 'CNY',
AUD = 'AUD',
CAD = 'CAD',
CHF = 'CHF',
ARS = 'ARS',
PHP = 'PHP',
NZD = 'NZD',
SGD = 'SGD',
NGN = 'NGN',
ZAR = 'ZAR',
RUB = 'RUB',
INR = 'INR',
BRL = 'BRL'
}
5 changes: 5 additions & 0 deletions shared/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './networks';
export * from './token-symbols'
export * from './denomination-symbols'
export * from './tokens';
export * from './lending-protocols'
15 changes: 15 additions & 0 deletions shared/lending-protocols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum LendingProtocol {
AaveV2 = 'aavev2',
AaveV3 = 'aavev3',
Ajna = 'ajna',
Maker = 'maker',
SparkV3 = 'sparkv3',
}

export enum LendingProtocolLabel {
aavev2 = 'Aave V2',
aavev3 = 'Aave V3',
ajna = 'Ajna',
maker = 'Maker',
sparkv3 = 'Spark',
zerotucks marked this conversation as resolved.
Show resolved Hide resolved
}
14 changes: 14 additions & 0 deletions shared/networks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum Networks {
// Mainnets
MAINNET = 'mainnet',
OPTIMISM = 'optimism',
ARBITRUM = 'arbitrum',
BASE = 'base',
POLYGON = 'polygon',

// Testnets
GOERLI = 'goerli',
OPTIMISM_GOERLI = 'optimism_goerli',
ARBITRUM_GOERLI = 'arbitrum_goerli',
POLYGON_MUMBAI = 'polygon_mumbai',
}
62 changes: 62 additions & 0 deletions shared/token-symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export enum TokenSymbols {
ETH = 'ETH',
WETH = 'WETH',
STETH = 'STETH',
WSTETH = 'WSTETH',
WBTC = 'WBTC',
USDC = 'USDC',
DAI = 'DAI',
CBETH = 'CBETH',
RETH = 'RETH',
AAVE = 'AAVE',
LINK = 'LINK',
UNI = 'UNI',
SUSHI = 'SUSHI',
CRV = 'CRV',
SNX = 'SNX',
ADAI = 'ADAI',
BAL = 'BAL',
BAT = 'BAT',
COMP = 'COMP',
CRVV1ETHSTETH = 'CRVV1ETHSTETH',
FRAX = 'FRAX',
GHO = 'GHO',
GNO = 'GNO',
GUNIV3DAIUSDC1 = 'GUNIV3DAIUSDC1',
GUNIV3DAIUSDC2 = 'GUNIV3DAIUSDC2',
GUSD = 'GUSD',
KNC = 'KNC',
LDO = 'LDO',
LRC = 'LRC',
LUSD = 'LUSD',
MANA = 'MANA',
MATIC = 'MATIC',
PAX = 'PAX',
PAXUSD = 'PAXUSD',
RENBTC = 'RENBTC',
RWA001 = 'RWA001',
RWA002 = 'RWA002',
RWA003 = 'RWA003',
RWA004 = 'RWA004',
RWA005 = 'RWA005',
RWA006 = 'RWA006',
SDAI = 'SDAI',
TBTC = 'TBTC',
TUSD = 'TUSD',
UNIV2AAVEETH = 'UNIV2AAVEETH',
UNIV2DAIETH = 'UNIV2DAIETH',
UNIV2DAIUSDC = 'UNIV2DAIUSDC',
UNIV2DAIUSDT = 'UNIV2DAIUSDT',
UNIV2ETHUSDT = 'UNIV2ETHUSDT',
UNIV2LINKETH = 'UNIV2LINKETH',
UNIV2UNIETH = 'UNIV2UNIETH',
UNIV2USDCETH = 'UNIV2USDCETH',
UNIV2WBTCDAI = 'UNIV2WBTCDAI',
UNIV2WBTCETH = 'UNIV2WBTCETH',
USDT = 'USDT',
WLD = 'WLD',
YIELDBTC = 'YIELDBTC',
YIELDETH = 'YIELDETH',
YFI = 'YFI',
ZRX = 'ZRX',
}
Loading
Loading