mirror of
https://github.com/grassrootseconomics/erc20-pool.git
synced 2024-11-07 06:26:47 +01:00
Enable choice in net fee, settable evm version
Signed-off-by: lash <dev@holbrook.no> Signed-off-by: Mohammed Sohail <sohailsameja@gmail.com>
This commit is contained in:
parent
c688989c40
commit
066f7914a6
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
{"compiler":{"version":"0.8.25+commit.b61c2a91"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"address","name":"_inToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"valueFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"DecimalQuote.sol":"DecimalQuote"},"evmVersion":"istanbul","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"DecimalQuote.sol":{"keccak256":"0x4053ab914f5f3b89b17af0e091de359c808058461d12502cf53d495b5abc31b4","license":"AGPL-3.0-or-later","urls":["bzz-raw://496e4f4a2039dc9447d04db14ce8624b4caf2038cf017c56f632157a50f69cae","dweb:/ipfs/QmWDRaBfANxZrKb73AziafrbB5tZkgYjvd1ym1vGje47Ui"]}},"version":1}
|
{"compiler":{"version":"0.8.21-develop.2024.4.15+commit.d9974bed"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_outToken","type":"address"},{"internalType":"address","name":"_inToken","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"valueFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"DecimalQuote.sol":"DecimalQuote"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"DecimalQuote.sol":{"keccak256":"0x4053ab914f5f3b89b17af0e091de359c808058461d12502cf53d495b5abc31b4","license":"AGPL-3.0-or-later","urls":["bzz-raw://496e4f4a2039dc9447d04db14ce8624b4caf2038cf017c56f632157a50f69cae","dweb:/ipfs/QmWDRaBfANxZrKb73AziafrbB5tZkgYjvd1ym1vGje47Ui"]}},"version":1}
|
||||||
|
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
@ -56,9 +56,16 @@ class TestPoolFee(TestERC20Pool):
|
|||||||
r = self.rpc.do(o)
|
r = self.rpc.do(o)
|
||||||
self.assertEqual(int(r, 16), 990)
|
self.assertEqual(int(r, 16), 990)
|
||||||
|
|
||||||
nonce_oracle = RPCNonceOracle(self.accounts[2], conn=self.conn)
|
|
||||||
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
(tx_hash, o) = c.withdraw(self.pool_address, self.accounts[2], self.foo_address)
|
(tx_hash, o) = c.withdraw(self.pool_address, self.accounts[1], self.foo_address)
|
||||||
|
self.rpc.do(o)
|
||||||
|
o = receipt(tx_hash)
|
||||||
|
r = self.conn.do(o)
|
||||||
|
self.assertEqual(r['status'], 0)
|
||||||
|
|
||||||
|
nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn)
|
||||||
|
c = Pool(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
|
||||||
|
(tx_hash, o) = c.withdraw(self.pool_address, self.accounts[0], self.foo_address)
|
||||||
self.rpc.do(o)
|
self.rpc.do(o)
|
||||||
o = receipt(tx_hash)
|
o = receipt(tx_hash)
|
||||||
r = self.conn.do(o)
|
r = self.conn.do(o)
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
SOLC = /usr/local/bin/solc
|
SOLC = /usr/local/bin/solc
|
||||||
|
EVM_VERSION = byzantium
|
||||||
|
|
||||||
all:
|
all:
|
||||||
$(SOLC) --bin SwapPool.sol --evm-version istanbul | awk 'NR>3' > SwapPool.bin
|
$(SOLC) --bin SwapPool.sol --evm-version $(EVM_VERSION)| awk 'NR>3' > SwapPool.bin
|
||||||
$(SOLC) --abi SwapPool.sol --evm-version istanbul | awk 'NR>3' > SwapPool.json
|
$(SOLC) --abi SwapPool.sol --evm-version $(EVM_VERSION) | awk 'NR>3' > SwapPool.json
|
||||||
$(SOLC) --metadata SwapPool.sol --evm-version istanbul | awk 'NR>3' > SwapPool.metadata.json
|
$(SOLC) --metadata SwapPool.sol --evm-version $(EVM_VERSION) | awk 'NR>3' > SwapPool.metadata.json
|
||||||
truncate -s -1 SwapPool.bin
|
truncate -s -1 SwapPool.bin
|
||||||
$(SOLC) --bin DecimalQuote.sol --evm-version istanbul | awk 'NR>3' > DecimalQuote.bin
|
$(SOLC) --bin DecimalQuote.sol --evm-version $(EVM_VERSION) | awk 'NR>3' > DecimalQuote.bin
|
||||||
$(SOLC) --abi DecimalQuote.sol --evm-version istanbul | awk 'NR>3' > DecimalQuote.json
|
$(SOLC) --abi DecimalQuote.sol --evm-version $(EVM_VERSION) | awk 'NR>3' > DecimalQuote.json
|
||||||
$(SOLC) --metadata DecimalQuote.sol --evm-version istanbul | awk 'NR>3' > DecimalQuote.metadata.json
|
$(SOLC) --metadata DecimalQuote.sol --evm-version $(EVM_VERSION) | awk 'NR>3' > DecimalQuote.metadata.json
|
||||||
truncate -s -1 DecimalQuote.bin
|
truncate -s -1 DecimalQuote.bin
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
|
@ -163,7 +163,7 @@ contract SwapPool {
|
|||||||
return quote;
|
return quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
function withdraw(address _outToken, address _inToken, uint256 _value) public {
|
function withdraw_less_fee(address _outToken, address _inToken, uint256 _value) public {
|
||||||
bool r;
|
bool r;
|
||||||
bytes memory v;
|
bytes memory v;
|
||||||
uint256 balance;
|
uint256 balance;
|
||||||
@ -197,6 +197,46 @@ contract SwapPool {
|
|||||||
emit Swap(msg.sender, _inToken, _outToken, _value, outValue, fee);
|
emit Swap(msg.sender, _inToken, _outToken, _value, outValue, fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function withdraw(address _outToken, address _inToken, uint256 _value) public {
|
||||||
|
bool r;
|
||||||
|
bytes memory v;
|
||||||
|
uint256 netValue;
|
||||||
|
uint256 outValue;
|
||||||
|
uint256 balance;
|
||||||
|
uint256 fee;
|
||||||
|
|
||||||
|
fee = getFee(_value);
|
||||||
|
netValue = _value - fee;
|
||||||
|
netValue = getQuote(_outToken, _inToken, netValue);
|
||||||
|
|
||||||
|
(r, v) = _outToken.call(abi.encodeWithSignature("balanceOf(address)", this));
|
||||||
|
require(r, "ERR_TOKEN");
|
||||||
|
balance = abi.decode(v, (uint256));
|
||||||
|
outValue = netValue + fee;
|
||||||
|
require(balance >= outValue, "ERR_BALANCE");
|
||||||
|
|
||||||
|
deposit(_inToken, _value);
|
||||||
|
|
||||||
|
(r, v) = _outToken.call(abi.encodeWithSignature('transfer(address,uint256)', msg.sender, netValue));
|
||||||
|
require(r, "ERR_TOKEN");
|
||||||
|
r = abi.decode(v, (bool));
|
||||||
|
require(r, "ERR_TRANSFER");
|
||||||
|
|
||||||
|
if (feeAddress != address(0)) {
|
||||||
|
fees[_outToken] += fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit Swap(msg.sender, _inToken, _outToken, _value, outValue, fee);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdraw(address _outToken, address _inToken, uint256 _value, bool _deduct_fee) public {
|
||||||
|
if (_deduct_fee) {
|
||||||
|
withdraw_less_fee(_outToken, _inToken, _value);
|
||||||
|
} else {
|
||||||
|
withdraw(_outToken, _inToken, _value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Withdraw token to fee address
|
// Withdraw token to fee address
|
||||||
function withdraw(address _outToken) public returns (uint256) {
|
function withdraw(address _outToken) public returns (uint256) {
|
||||||
uint256 balance;
|
uint256 balance;
|
||||||
|
Loading…
Reference in New Issue
Block a user