xdefilab / xdefi-base Goto Github PK
View Code? Open in Web Editor NEWxDeFi Optimized Multi Asset AMM Dex on Ethereum
Home Page: https://swap.xdefi.com
License: GNU General Public License v3.0
xDeFi Optimized Multi Asset AMM Dex on Ethereum
Home Page: https://swap.xdefi.com
License: GNU General Public License v3.0
在前端约束情况下单次Swap涉及一个简化判断:wO/wI是否为1或2或1/2或其他浮点数
1: 跳过计算(重要紧急)
2: 裸乘(重要)
0.5: 引导用户反向裸乘(重要)
其他: 其他
建议:
64-73 原始
public pure returns (uint256 tokenAmountOut) {
uint256 weightRatio = tokenWeightIn.bdiv(tokenWeightOut);
uint256 adjustedIn = BONE.bsub(swapFee);
adjustedIn = tokenAmountIn.bmul(adjustedIn);
uint256 y = tokenBalanceIn.bdiv(tokenBalanceIn.badd(adjustedIn));
uint256 foo = y.bpow(weightRatio);
uint256 bar = BONE.bsub(foo);
tokenAmountOut = tokenBalanceOut.bmul(bar);
return tokenAmountOut;
}
修改
public pure returns (uint256 tokenAmountOut) {
if (tokenWeightIn==tokenWightOut){
uint256 weightRatio = 1;
}else if (tokenWeightIn>>1==tokenWightOut){
uint256 weightRatio = 2;
} else{
uint256 weightRatio = tokenWeightIn.bdiv(tokenWeightOut);
}
uint256 adjustedIn = BONE.bsub(swapFee);
adjustedIn = tokenAmountIn.bmul(adjustedIn);
uint256 y = tokenBalanceIn.bdiv(tokenBalanceIn.badd(adjustedIn));
if (tokenWeightIn==tokenWightOut){
uint256 foo = y;
}else if (tokenWeightIn>>1==tokenWightOut){
uint256 foo = y.bmul(y);
} else{
uint256 foo = y.bpow(weightRatio);
}
uint256 bar = BONE.bsub(foo);
tokenAmountOut = tokenBalanceOut.bmul(bar);
return tokenAmountOut;
}
92-101行
原始
public pure returns (uint256 tokenAmountIn) {
uint256 weightRatio = tokenWeightOut.bdiv(tokenWeightIn);
uint256 diff = tokenBalanceOut.bsub(tokenAmountOut);
uint256 y = tokenBalanceOut.bdiv(diff);
uint256 foo = y.bpow(weightRatio);
foo = foo.bsub(BONE);
tokenAmountIn = BONE.bsub(swapFee);
tokenAmountIn = tokenBalanceIn.bmul(foo).bdiv(tokenAmountIn);
return tokenAmountIn;
}
修改
public pure returns (uint256 tokenAmountIn) {
if (tokenWeightOut==tokenWeightIn){
uint256 weightRatio = 1;
}else if (tokenWeightOut>>1==tokenWeightIn){
uint256 weightRatio = 2;
} else{
uint256 weightRatio = tokenWeightOut.bdiv(tokenWeightIn);
}
uint256 diff = tokenBalanceOut.bsub(tokenAmountOut);
uint256 y = tokenBalanceOut.bdiv(diff);
if (tokenWeightOut==tokenWeightIn){
uint256 foo = y;
}else if (tokenWeightOut>>1==tokenWeightIn){
uint256 foo = y.bmul(y);
} else{
uint256 foo = y.bpow(weightRatio);
}
foo = foo.bsub(BONE);
tokenAmountIn = BONE.bsub(swapFee);
tokenAmountIn = tokenBalanceIn.bmul(foo).bdiv(tokenAmountIn);
return tokenAmountIn;
}
Hello.
I got a metamask error during the next swap in the network test. Do you need such information or is it a metamask problem? (I made screenshots and wrote down the error codes)
`Детали ошибки
Сообщение: new BigNumber() not a base 16 number: undefined
Код: BigNumber Error
Стек:
BigNumber Error: new BigNumber() not a base 16 number: undefined
at $ (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui.js:43:44267)
at w (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui.js:43:49784)
at new H (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui.js:43:41731)
at E (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui.js:152:619624)
at S (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui.js:152:620308)
at Function.mapToProps (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui.js:152:227614)
at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:93:20755)
at Function.n.mapToProps (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:93:20891)
at n (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:93:20755)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:93:19596
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:93:12990
at Object.useMemo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:63534)
at useMemo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:136:5250)
at _ (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:93:12934)
at ca (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:59367)
at Ga (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:67589)
at Va (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:67408)
at Ua (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:67127)
at jl (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:107861)
at bu (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:90053)
at pu (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:89978)
at iu (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:87326)
at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:45768
at r.unstable_runWithPriority (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:172:3472)
at Vo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:45477)
at Yo (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:45713)
at Ko (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:45648)
at le (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:114525)
at Er (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/ui-libs.js:75:29321)
at HTMLDocument.c (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/initSentry.js:1:10461)`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.