mirror of
https://github.com/grassrootseconomics/erc20-pool.git
synced 2024-11-23 12:36:46 +01:00
fixes: fee application to swap quote
commit4931ef1d70
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Tue Mar 26 16:56:44 2024 +0800 fix: include fees in public liquidity commit78844169c5
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Thu Mar 21 17:00:33 2024 +0800 update: fix-pool builds commitab897bf901
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Thu Mar 21 16:57:06 2024 +0800 fix: apply fee after quote. Exclude fees from public liquidity commitc38fb552e9
Author: Mohammed Sohail <sohailsameja@gmail.com> Date: Thu Mar 21 13:09:29 2024 +0800 feat: make getQuote a public function * useful for 3rd part integration. No need to make a 2nd call to the quoter.
This commit is contained in:
parent
f812790610
commit
561c4b3a71
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ build/
|
|||||||
dist/
|
dist/
|
||||||
solidity/*.json
|
solidity/*.json
|
||||||
solidity/*.bin
|
solidity/*.bin
|
||||||
|
.venv
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -119,7 +119,7 @@ contract SwapPool {
|
|||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuote(address _outToken, address _inToken, uint256 _value) private returns (uint256) {
|
function getQuote(address _outToken, address _inToken, uint256 _value) public returns (uint256) {
|
||||||
bool r;
|
bool r;
|
||||||
bytes memory v;
|
bytes memory v;
|
||||||
uint256 quote;
|
uint256 quote;
|
||||||
@ -137,22 +137,26 @@ contract SwapPool {
|
|||||||
function withdraw(address _outToken, address _inToken, uint256 _value) public {
|
function withdraw(address _outToken, address _inToken, uint256 _value) public {
|
||||||
bool r;
|
bool r;
|
||||||
bytes memory v;
|
bytes memory v;
|
||||||
uint256 netValue;
|
|
||||||
uint256 balance;
|
uint256 balance;
|
||||||
uint256 fee;
|
uint256 fee;
|
||||||
|
uint256 outValue;
|
||||||
|
|
||||||
fee = getFee(_value);
|
outValue = getQuote(_outToken, _inToken, _value);
|
||||||
netValue = _value - fee;
|
|
||||||
netValue = getQuote(_outToken, _inToken, netValue);
|
|
||||||
|
|
||||||
(r, v) = _outToken.call(abi.encodeWithSignature("balanceOf(address)", this));
|
(r, v) = _outToken.call(abi.encodeWithSignature("balanceOf(address)", this));
|
||||||
require(r, "ERR_TOKEN");
|
require(r, "ERR_TOKEN");
|
||||||
balance = abi.decode(v, (uint256));
|
balance = abi.decode(v, (uint256));
|
||||||
require(balance >= netValue + fee, "ERR_BALANCE");
|
|
||||||
|
// deduct the fees from the quoted outValue
|
||||||
|
fee = getFee(outValue);
|
||||||
|
outValue -= fee;
|
||||||
|
|
||||||
|
// pool should have enough balance to cover the final outValue (fees already deducted)
|
||||||
|
require(balance >= outValue, "ERR_BALANCE");
|
||||||
|
|
||||||
deposit(_inToken, _value);
|
deposit(_inToken, _value);
|
||||||
|
|
||||||
(r, v) = _outToken.call(abi.encodeWithSignature('transfer(address,uint256)', msg.sender, netValue));
|
(r, v) = _outToken.call(abi.encodeWithSignature('transfer(address,uint256)', msg.sender, outValue));
|
||||||
require(r, "ERR_TOKEN");
|
require(r, "ERR_TOKEN");
|
||||||
r = abi.decode(v, (bool));
|
r = abi.decode(v, (bool));
|
||||||
require(r, "ERR_TRANSFER");
|
require(r, "ERR_TRANSFER");
|
||||||
@ -235,3 +239,4 @@ contract SwapPool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user