Created
June 14, 2020 13:42
-
-
Save FernandoMartinelli/c95603767092c5237c4643aef5faaf4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isWrapPair(equivalentSets, tokenA, tokenB): | |
for equivalentSet in equivalentSets: | |
if ((tokenA in equivalentSet) and (tokenB in equivalentSet)): | |
return True | |
return False | |
equivalentSets = [ | |
["WETH", "aETH", "cETH", "iETH", "iETH", "PETH"], # ETH group | |
["DAI", "aDAI", "cDAI", "dDAI", "iDAI", "yDAI", "rDAI", "CHAI"], # DAI group | |
["USDC", "aUSDC", "cUSDC", "dUSDC", "iUSDC", "yUSDC"] # USDC group | |
] | |
pools = [] | |
pools.append({ | |
"Weights": [ 0.75, 0.25 ], | |
"Tokens": ['A', 'B'] | |
}) | |
pools.append({ | |
"Weights": [ 0.75, 0.25 ], | |
"Tokens": ['cDAI', 'aDAI'] | |
}) | |
pools.append({ | |
"Weights": [ 0.49, 0.49, 0.02 ], | |
"Tokens": ['A', 'B', 'C'] | |
}) | |
pools.append({ | |
"Weights": [ 0.49, 0.49, 0.02 ], | |
"Tokens": ['cDAI', 'aDAI', 'DAI'] | |
}) | |
pools.append({ | |
"Weights": [ 0.49, 0.49, 0.02 ], | |
"Tokens": ['cDAI', 'aDAI', 'C'] | |
}) | |
pools.append({ | |
"Weights": [ 0.49, 0.49, 0.02 ], | |
"Tokens": ['cDAI', 'B', 'DAI'] | |
}) | |
for pool in pools: | |
poolWeights = pool['Weights'] | |
poolTokens = pool['Tokens'] | |
ratioFactorSum = 0 | |
wrapFactorSum = 0 | |
pairWeightSum = 0 | |
n = len(poolWeights) | |
for i in range(0, n): | |
if poolWeights[i] != 0: | |
for j in range(i+1, n): | |
pairWeight = poolWeights[i] * poolWeights[j] | |
normalizedWeight1 = poolWeights[i] / (poolWeights[i] + poolWeights[j]) | |
normalizedWeight2 = poolWeights[j] / (poolWeights[i] + poolWeights[j]) | |
ratioFactorSum += (4 * normalizedWeight1 * normalizedWeight2) * pairWeight | |
wrapFactorPair = 0.1 if isWrapPair(equivalentSets, poolTokens[i], poolTokens[j]) else 1 | |
wrapFactorSum += wrapFactorPair * pairWeight | |
pairWeightSum += pairWeight | |
ratioFactor = ratioFactorSum / pairWeightSum | |
wrapFactor = wrapFactorSum / pairWeightSum | |
print(str(pool['Weights'])+ ', ' +str(pool['Tokens'])+ ' => ' + str(round(ratioFactor * wrapFactor,4))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment