alpaca-finance / bsc-alpaca-contract Goto Github PK
View Code? Open in Web Editor NEWSmart Contracts for Alpaca Finance on Fantom & BNB Chain
Home Page: https://alpacafinance.org
License: MIT License
Smart Contracts for Alpaca Finance on Fantom & BNB Chain
Home Page: https://alpacafinance.org
License: MIT License
As a user who has been using the alpaca finance for one year, I want to make my own contribution to the protocol by becoming a liquidation robot. Now that you have entered a new chain, can you accept the application for a new liquidation robot?
In the Alpaca Finance Protocol, a number of situations require the real-time swap of one token to another. For example, the StrategyAddBaseTokenOnly strategy takes only the base token and converts some portion of it to quote token so that their ratio matches the current swap price in the PancakeSwapV2 pool. Note that in PancakeSwapV2, if you make a token swap or trade on the exchange, you will need to pay a 0.25% trading fee, which is broken down into three parts. The first part of 0.17% is returned to liquidity pools in the form of a fee reward for liquidity providers while the second part of 0.03% is sent to the PancakeSwap Treasury, third part of 0.05% is used to CAKE buyback and burn.
To elaborate, i show below the getAmountOut() routine inside the the PancakeLibraryV2. For comparison, i also show the getMktSellAmount() routine in PancakeswapV2Worker. It is interesting to note that PancakeswapV2Worker has implicitly assumed the trading fee is 0.2%, instead of 0.25%. The difference in the built-in trading fee may skew the optimal allocation of assets in the developed strategies, including StrategyAddBaseTokenOnly and StrategyAddTwoSidesOptimal. It also affects the helper contract, i,e., ibTokenRouter.
PancakeLibraryV2.sol:
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, "PancakeLibrary: INSUFFICIENT_INPUT_AMOUNT");
require(reserveIn > 0 && reserveOut > 0, "PancakeLibrary: INSUFFICIENT_LIQUIDITY");
uint amountInWithFee = amountIn.mul(9975);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(10000).add(amountInWithFee);
amountOut = numerator / denominator;
}
PancakeswapV2Worker.sol:
/// @dev Return maximum output given the input amount and the status of Uniswap reserves.
/// @param aIn The amount of asset to market sell.
/// @param rIn the amount of asset in reserve for input.
/// @param rOut The amount of asset in reserve for output.
function getMktSellAmount(uint256 aIn, uint256 rIn, uint256 rOut) public view returns (uint256) {
if (aIn == 0) return 0;
require(rIn > 0 && rOut > 0, "PancakeswapWorker::getMktSellAmount:: bad reserve values");
/// if fee is not set,
/// revert to V1 fee first as this can implied that migrationLp hasn't bee executed
uint256 _fee = fee;
uint256 _feeDenom = feeDenom;
if (_fee == 0) _fee = 998;
if (_feeDenom == 0) _feeDenom = 1000;
uint256 aInWithFee = aIn.mul(_fee);
uint256 numerator = aInWithFee.mul(rOut);
uint256 denominator = rIn.mul(_feeDenom).add(aInWithFee);
return numerator / denominator;
}
Recommendation: Make the built-in trading fee in Alpaca consistent with the actual trading fee in PancakeSwapV2.
Most pages are incomplete, i.e. last part of page is cutted on seemingly random moment. A lot of sentences are cutted in the middle.
I am pretty sure that it is result of improper pdf compilation, probably recompiling source would fix this issue.
I have difficulties running the tests.
This resulted in the errors below:
test/CakeMaxiWorker.test.ts:9:3 - error TS2724: '"../typechain"' has no exported member named 'PancakeFactory'. Did you mean 'IPancakeFactory'?
test/CakeMaxiWorker.test.ts:10:3 - error TS2724: '"../typechain"' has no exported member named 'PancakeFactoryfactory'. Did you mean 'IPancakeFactoryfactory'?
Are there classes missing or did I do somenthing wrong?
Can anyone publish how to setup this project in order to run the tests?
my dev version:
node: v14.0.0
yarn: v1.22.18
npm: v6.14.4
But when I run yarn in the project pathοΌan error occurred :
yarn install v1.22.18
[1/5] π Validating package.json...
[2/5] π Resolving packages...
success Already up-to-date.
$ yarn build
yarn run v1.22.18
$ yarn run build:cjs
$ tsc -p tsconfig.cjs.json
error TS18003: No inputs were found in config file '/Users/nateyang/Documents/GitHub/bsc-alpaca-contract/tsconfig.cjs.json'. Specified 'include' paths were '["./typechain/**/*.ts"]' and 'exclude' paths were '["node_modules","build","cache","artifacts"]'.
Knowing the wallet address, which contract do I call to get a list of my vault position numbers?
I've ask the same question in another issue, but it seem a bit inappropriate there.
Is your Frontend Webpage open-sourced?
If so, where does its code locate?
If not, can you open it please?
I am a leveraged farmer on your platform trying to write a programme to tract the safety buffers of my vaults. Then I guessed your frontend would be the perfect place to start.
I want to run the test fileγ
In deploy/exec/dex/deploy/token-liq-pool.ts there is a typo.
In line 152 it should be liquidity, but there is a typo.
I saw you changed your directory structure for your contracts, and checking the Contracts Documentation I noticed your links aren't updated.
Probably not your biggest priority right now, just to let you know.
How do I generate the json files in results in order to deploy the contracts? Or am I doing sth out of the order?
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.