Skip to content

Commit

Permalink
Extracted correlatedAssets to a dictionary to be able to reuse in SDK v2
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwitek committed Apr 15, 2024
1 parent cc676ee commit ab9caaa
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 61 deletions.
1 change: 1 addition & 0 deletions packages/dma-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export { getMarketRate } from './strategies/morphoblue/validation'
export { views } from './views'

// UTILS
export { correlatedAssetDictionary } from './utils/swap/correlated-assets'
export { isCorrelatedPosition } from './utils/swap/fee-resolver'
export { normalizeValue } from '@dma-common/utils/common'
export { negativeToZero } from '@dma-common/utils/common'
Expand Down
66 changes: 66 additions & 0 deletions packages/dma-library/src/utils/swap/correlated-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export const correlatedAssetDictionary = {
CorrelatedAssetFee: {
ETH: [
'WETH',
'ETH',
'WSTETH',
'CBETH',
'RETH',
'STETH',
'OSETH',
'WEETH',
'EZETH',
'AWSTETH',
'ASETH',
'CWETHV3',
], // ETH correlated assets
BTC: ['WBTC', 'TBTC'], // BTC correlated assets
Stable: ['USDC', 'DAI', 'GHO', 'SDAI', 'USDT', 'CDAI', 'AUSDC', 'PYUSD'], // USDC correlated assets
},
LowCorrelatedAssetFee: {
ETH: [
'WSTETH',
'RETH',
'CBETH',
'STETH',
'AETHWSTETH',
'AETHWETH',
'AETHRETH',
'AETHCBETH',
'ASETH',
'AWETH',
'CETH',
'CWETHV3',
'WEETH',
'WETH',
],
BTC: ['WBTC', 'TBTC', 'AWBTC', 'AETHWBTC'],
Stable: [
'DAI',
'USDT',
'USDC',
'PYUSD',
'FRAX',
'LUSD',
'GUSD',
'CRVUSD',
'SDAI',
'SUSDE',
'USDE',
'AETHSDAI',
'AETHUSDC',
'AETHUSDT',
'AETHDAI',
'AETHPYUSD',
'AETHLUSD',
'AUSDC',
'ADAI',
'AUSDT',
'CUSDCV3',
'CDAI',
'CUSDC',
'SUSD',
'USDC.E',
],
},
}
75 changes: 14 additions & 61 deletions packages/dma-library/src/utils/swap/fee-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DEFAULT_FEE, LOW_CORRELATED_ASSET_FEE, NO_FEE } from '@dma-common/constants'
import BigNumber from 'bignumber.js'

import { correlatedAssetDictionary } from './correlated-assets'

export const feeResolver = <T extends string = string>(
fromToken: T,
toToken: T,
Expand Down Expand Up @@ -50,24 +52,17 @@ export const feeResolver = <T extends string = string>(
return feeToCharge
}

/**
* Checks if two symbols are in a correlated position.
* @param symbolA - The first symbol.
* @param symbolB - The second symbol.
* @returns True if the symbols are in a correlated position, false otherwise.
*/
export function isCorrelatedPosition(symbolA: string, symbolB: string) {
const correlatedAssetMatrix = [
[
'WETH',
'ETH',
'WSTETH',
'CBETH',
'RETH',
'STETH',
'OSETH',
'WEETH',
'EZETH',
'AWSTETH',
'ASETH',
'CWETHV3',
], // ETH correlated assets
['WBTC', 'TBTC'], // BTC correlated assets
['USDC', 'DAI', 'GHO', 'SDAI', 'USDT', 'CDAI', 'AUSDC', 'PYUSD'], // USDC correlated assets
correlatedAssetDictionary.CorrelatedAssetFee.ETH,
correlatedAssetDictionary.CorrelatedAssetFee.BTC,
correlatedAssetDictionary.CorrelatedAssetFee.Stable,
// Add more arrays here to expand the matrix in the future
]

Expand All @@ -94,53 +89,11 @@ export function isCorrelatedPosition(symbolA: string, symbolB: string) {
*/
export function isCorrelatedLowFeePosition(symbolA: string, symbolB: string) {
const correlatedAssetMatrix = [
[
'DAI',
'USDT',
'USDC',
'PYUSD',
'FRAX',
'LUSD',
'GUSD',
'CRVUSD',
'SDAI',
'SUSDE',
'USDE',
'AETHSDAI',
'AETHUSDC',
'AETHUSDT',
'AETHDAI',
'AETHPYUSD',
'AETHLUSD',
'AUSDC',
'ADAI',
'AUSDT',
'CUSDCV3',
'CDAI',
'CUSDC',
'SUSD',
'USDC.E',
],
[
'WSTETH',
'RETH',
'CBETH',
'STETH',
'AETHWSTETH',
'AETHWETH',
'AETHRETH',
'AETHCBETH',
'ASETH',
'AWETH',
'CETH',
'CWETHV3',
'WEETH',
'WETH',
],
['WBTC', 'TBTC', 'AWBTC', 'AETHWBTC'],
correlatedAssetDictionary.LowCorrelatedAssetFee.Stable,
correlatedAssetDictionary.LowCorrelatedAssetFee.ETH,
correlatedAssetDictionary.LowCorrelatedAssetFee.BTC,
// Add more arrays here to expand the matrix in the future
]

// Iterate over each row in the matrix
for (let i = 0; i < correlatedAssetMatrix.length; i++) {
// Check if both symbols are in the same row
Expand Down

0 comments on commit ab9caaa

Please sign in to comment.