Skip to content

Commit

Permalink
Build for package.
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrantuk committed Aug 2, 2021
1 parent 0a6de4f commit 710615e
Show file tree
Hide file tree
Showing 10 changed files with 1,666 additions and 25 deletions.
6 changes: 4 additions & 2 deletions dist/helpersClass.js
Expand Up @@ -390,7 +390,8 @@ function EVMgetOutputAmountSwap(pool, poolPairData, swapType, amount) {
// TODO we will be able to remove pooltype check once Element EVM maths is available
if (
pool.poolType === types_1.PoolTypes.Weighted ||
pool.poolType === types_1.PoolTypes.Stable
pool.poolType === types_1.PoolTypes.Stable ||
pool.poolType === types_1.PoolTypes.MetaStable
) {
// Will accept/return normalised values
if (pairType === types_1.PairTypes.TokenToToken) {
Expand Down Expand Up @@ -419,7 +420,8 @@ function EVMgetOutputAmountSwap(pool, poolPairData, swapType, amount) {
// TODO we will be able to remove pooltype check once Element EVM maths is available
if (
pool.poolType === types_1.PoolTypes.Weighted ||
pool.poolType === types_1.PoolTypes.Stable
pool.poolType === types_1.PoolTypes.Stable ||
pool.poolType === types_1.PoolTypes.MetaStable
) {
if (pairType === types_1.PairTypes.TokenToToken) {
returnAmount = pool._evminGivenOut(poolPairData, amount);
Expand Down
53 changes: 32 additions & 21 deletions dist/multicall.js
Expand Up @@ -98,7 +98,11 @@ function getOnChainBalances(
pool.address,
'getSwapFeePercentage'
);
} else if (pool.poolType === 'Stable') {
} else if (
pool.poolType === 'Stable' ||
pool.poolType === 'MetaStable'
) {
// MetaStable is the same as Stable for multicall purposes
multiPool.call(
`${pool.id}.amp`,
pool.address,
Expand All @@ -120,28 +124,35 @@ function getOnChainBalances(
pools = yield multiPool.execute(pools);
subgraphPools.pools.forEach(subgraphPool => {
const onChainResult = pools[subgraphPool.id];
subgraphPool.swapFee = bmath_1
.scale(bmath_1.bnum(onChainResult.swapFee), -18)
.toString();
onChainResult.poolTokens.tokens.forEach((token, i) => {
const tokenAddress = onChainResult.poolTokens.tokens[i]
.toString()
.toLowerCase();
const T = subgraphPool.tokens.find(
t => t.address === tokenAddress
);
const balance = bmath_1
.scale(
bmath_1.bnum(onChainResult.poolTokens.balances[i]),
-Number(T.decimals)
)
try {
subgraphPool.swapFee = bmath_1
.scale(bmath_1.bnum(onChainResult.swapFee), -18)
.toString();
T.balance = balance;
if (subgraphPool.poolType === 'Weighted')
T.weight = bmath_1
.scale(bmath_1.bnum(onChainResult.weights[i]), -18)
onChainResult.poolTokens.tokens.forEach((token, i) => {
const tokenAddress = onChainResult.poolTokens.tokens[i]
.toString()
.toLowerCase();
const T = subgraphPool.tokens.find(
t => t.address === tokenAddress
);
const balance = bmath_1
.scale(
bmath_1.bnum(onChainResult.poolTokens.balances[i]),
-Number(T.decimals)
)
.toString();
});
T.balance = balance;
if (subgraphPool.poolType === 'Weighted')
T.weight = bmath_1
.scale(bmath_1.bnum(onChainResult.weights[i]), -18)
.toString();
});
} catch (err) {
// Likely an unsupported pool type
// console.log(`Issue with pool onchain call`)
// console.log(subgraphPool.id);
// console.log(onChainResult);
}
});
return subgraphPools;
});
Expand Down
19 changes: 17 additions & 2 deletions dist/pools.js
Expand Up @@ -10,6 +10,7 @@ const types_1 = require('./types');
const weightedPool_1 = require('./pools/weightedPool/weightedPool');
const stablePool_1 = require('./pools/stablePool/stablePool');
const elementPool_1 = require('./pools/elementPool/elementPool');
const metaStablePool_1 = require('./pools/metaStablePool/metaStablePool');
const bmath_1 = require('./bmath');
const disabled_tokens_json_1 = __importDefault(
require('./disabled-tokens.json')
Expand Down Expand Up @@ -85,8 +86,22 @@ function filterPoolsOfInterest(
pool.baseToken
);
newPool.setCurrentBlockTimestamp(currentBlockTimestamp);
} else
throw `Unknown pool type or type field missing: ${pool.poolType}`;
} else if (pool.poolType === 'MetaStable') {
newPool = new metaStablePool_1.MetaStablePool(
pool.id,
pool.address,
pool.amp,
pool.swapFee,
pool.totalShares,
pool.tokens,
pool.tokensList
);
} else {
console.error(
`Unknown pool type or type field missing: ${pool.poolType} ${pool.id}`
);
return;
}
let tokenListSet = new Set(pool.tokensList);
// Depending on env file, we add the BPT as well as
// we can join/exit as part of the multihop
Expand Down
131 changes: 131 additions & 0 deletions dist/pools/metaStablePool/metaStableMath.d.ts
@@ -0,0 +1,131 @@
import { BigNumber } from '../../utils/bignumber';
/**********************************************************************************************
// invariant //
// D = invariant to compute //
// A = amplifier n * D^2 + A * n^n * S * (n^n * P / D^(n−1)) //
// S = sum of balances ____________________________________________ //
// P = product of balances (n+1) * D + ( A * n^n − 1)* (n^n * P / D^(n−1)) //
// n = number of tokens //
**********************************************************************************************/
export declare function _invariant(
amp: BigNumber, // amp
balances: BigNumber[]
): BigNumber;
/**********************************************************************************************
// outGivenIn token x for y - polynomial equation to solve //
// ay = amount out to calculate //
// by = balance token out //
// y = by - ay //
// D = invariant D D^(n+1) //
// A = amplifier y^2 + ( S - ---------- - 1) * y - ------------- = 0 //
// n = number of tokens (A * n^n) A * n^2n * P //
// S = sum of final balances but y //
// P = product of final balances but y //
**********************************************************************************************/
export declare function _exactTokenInForTokenOut(
amount: any,
poolPairData: any
): BigNumber;
/**********************************************************************************************
// inGivenOut token x for y - polynomial equation to solve //
// ax = amount in to calculate //
// bx = balance token in //
// x = bx + ax //
// D = invariant D D^(n+1) //
// A = amplifier x^2 + ( S - ---------- - 1) * x - ------------- = 0 //
// n = number of tokens (A * n^n) A * n^2n * P //
// S = sum of final balances but x //
// P = product of final balances but x //
**********************************************************************************************/
export declare function _tokenInForExactTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _solveAnalyticalBalance(
sum: BigNumber,
inv: BigNumber,
amp: BigNumber,
n_pow_n: BigNumber,
p: BigNumber
): BigNumber;
export declare function _exactTokenInForBPTOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _tokenInForExactBPTOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _BPTInForExactTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _exactBPTInForTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _poolDerivatives(
amp: any,
balances: any,
tokenIndexIn: any,
tokenIndexOut: any,
is_first_derivative: any,
wrt_out: any
): BigNumber;
export declare function _poolDerivativesBPT(
amp: any,
balances: any,
bptSupply: any,
tokenIndexIn: any,
is_first_derivative: any,
is_BPT_out: any,
wrt_out: any
): BigNumber;
export declare function _spotPriceAfterSwapExactTokenInForTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _spotPriceAfterSwapTokenInForExactTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _spotPriceAfterSwapExactTokenInForBPTOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _spotPriceAfterSwapTokenInForExactBPTOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _spotPriceAfterSwapExactBPTInForTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _spotPriceAfterSwapBPTInForExactTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _derivativeSpotPriceAfterSwapExactTokenInForTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _derivativeSpotPriceAfterSwapTokenInForExactTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _derivativeSpotPriceAfterSwapExactTokenInForBPTOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _derivativeSpotPriceAfterSwapTokenInForExactBPTOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _derivativeSpotPriceAfterSwapExactBPTInForTokenOut(
amount: any,
poolPairData: any
): BigNumber;
export declare function _derivativeSpotPriceAfterSwapBPTInForExactTokenOut(
amount: any,
poolPairData: any
): BigNumber;

0 comments on commit 710615e

Please sign in to comment.