Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
309bd109
Commit
309bd109
authored
May 18, 2018
by
Hayden Adams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove invariants
parent
5e7ae40c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
97 additions
and
192 deletions
+97
-192
App.js
src/App.js
+20
-49
exchange-actions.js
src/actions/exchange-actions.js
+16
-34
Exchange.js
src/components/Exchange.js
+25
-28
Invest.js
src/components/Invest.js
+0
-7
constants.js
src/constants.js
+11
-25
exchange-reducer.js
src/reducers/exchange-reducer.js
+16
-25
exchangeContract-reducer.js
src/reducers/exchangeContract-reducer.js
+2
-8
tokenContract-reducer.js
src/reducers/tokenContract-reducer.js
+3
-9
initial-state.js
src/store/initial-state.js
+4
-7
No files found.
src/App.js
View file @
309bd109
...
@@ -33,15 +33,12 @@ import { initializeGlobalWeb3,
...
@@ -33,15 +33,12 @@ import { initializeGlobalWeb3,
toggleInvest
}
from
'
./actions/web3-actions
'
;
toggleInvest
}
from
'
./actions/web3-actions
'
;
import
{
setInputBalance
,
import
{
setInputBalance
,
setOutputBalance
,
setOutputBalance
,
setInvariant1
,
setEthPool1
,
setInvariant2
,
setEthPool2
,
setMarketEth1
,
setTokenPool1
,
setMarketEth2
,
setTokenPool2
,
setMarketTokens1
,
setMarketTokens2
,
setAllowanceApprovalState
,
setAllowanceApprovalState
,
setInvestToken
,
setInvestToken
,
setInvestInvariant
,
setInvestEthPool
,
setInvestEthPool
,
setInvestTokenPool
,
setInvestTokenPool
,
setInvestTokenAllowance
,
setInvestTokenAllowance
,
...
@@ -75,13 +72,6 @@ class App extends Component {
...
@@ -75,13 +72,6 @@ class App extends Component {
if
(
web3
===
'
undefined
'
)
{
if
(
web3
===
'
undefined
'
)
{
this
.
props
.
setWeb3ConnectionStatus
(
false
);
this
.
props
.
setWeb3ConnectionStatus
(
false
);
}
else
{
}
else
{
this
.
setState
({
firstRun
:
cookie
.
load
(
'
firstRun
'
)
||
true
,
swapAdded
:
cookie
.
load
(
'
swapAdded
'
)
||
false
,
uniAdded
:
cookie
.
load
(
'
uniAdded
'
)
||
false
,
transactions
:
cookie
.
load
(
'
transactions
'
)
||
[],
})
// we're working with asynchronous redux
this
.
props
.
initializeGlobalWeb3
(
web3
)
this
.
props
.
initializeGlobalWeb3
(
web3
)
this
.
getInfoFirstTime
();
this
.
getInfoFirstTime
();
}
}
...
@@ -92,9 +82,8 @@ class App extends Component {
...
@@ -92,9 +82,8 @@ class App extends Component {
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-unused-vars
const
web3Subscriber
=
subscribe
(
'
web3Store.connected
'
,
state
=>
{
const
web3Subscriber
=
subscribe
(
'
web3Store.connected
'
,
state
=>
{
if
(
state
.
web3Store
.
connected
===
true
&&
!
state
.
web3Store
.
metamaskLocked
)
{
if
(
state
.
web3Store
.
connected
===
true
&&
!
state
.
web3Store
.
metamaskLocked
)
{
//console.log('successfully connected to metamask', state.web3Store.currentMaskAddress);
this
.
marketInterval
=
setInterval
(
this
.
getMarketInfo
,
10000
);
this
.
marketInterval
=
setInterval
(
this
.
getMarketInfo
,
15000
);
this
.
accountInterval
=
setInterval
(
this
.
getAccountInfo
,
10000
);
this
.
accountInterval
=
setInterval
(
this
.
getAccountInfo
,
15000
);
this
.
userInterval
=
setInterval
(
this
.
getUserAddress
,
500
);
this
.
userInterval
=
setInterval
(
this
.
getUserAddress
,
500
);
}
else
{
}
else
{
console
.
log
(
'
web3 not connected, getting user address
'
)
console
.
log
(
'
web3 not connected, getting user address
'
)
...
@@ -107,8 +96,7 @@ class App extends Component {
...
@@ -107,8 +96,7 @@ class App extends Component {
componentWillReceiveProps
(
nextProps
)
{
componentWillReceiveProps
(
nextProps
)
{
//console.log('nextProps', nextProps)
//console.log('nextProps', nextProps)
}
}
// TODO: getInfoFirstTime and getUserAddress are WET af
// TODO: improve getInfoFirstTime and getUserAddress
// lets do something about it
getInfoFirstTime
=
()
=>
{
getInfoFirstTime
=
()
=>
{
web3
.
eth
.
getAccounts
(
async
(
error
,
result
)
=>
{
web3
.
eth
.
getAccounts
(
async
(
error
,
result
)
=>
{
if
(
result
.
length
>
0
){
if
(
result
.
length
>
0
){
...
@@ -164,9 +152,6 @@ class App extends Component {
...
@@ -164,9 +152,6 @@ class App extends Component {
// send the token contract to redux store
// send the token contract to redux store
await
this
.
props
.
tokenContractReady
(
tokenAddress
[
0
],
tokenContract
);
await
this
.
props
.
tokenContractReady
(
tokenAddress
[
0
],
tokenContract
);
})
})
// this.getAccountInfo();
// this.getMarketInfo();
}
}
symbolToTokenAddress
=
(
symbol
)
=>
{
symbolToTokenAddress
=
(
symbol
)
=>
{
...
@@ -211,7 +196,7 @@ class App extends Component {
...
@@ -211,7 +196,7 @@ class App extends Component {
}
}
}
}
// this quadruplet of functions will end up being shared amongst multiple components
// this quadruplet of functions will end up being shared amongst multiple components
// will need to bring this out into a higher order component
(we'll put that to the side for now)
// will need to bring this out into a higher order component
// TODO: multiple components currently need this function, we will pass it to them via props
// TODO: multiple components currently need this function, we will pass it to them via props
getAccountInfo
=
()
=>
{
getAccountInfo
=
()
=>
{
switch
(
this
.
props
.
web3Store
.
exchangeType
)
{
switch
(
this
.
props
.
web3Store
.
exchangeType
)
{
...
@@ -243,13 +228,10 @@ class App extends Component {
...
@@ -243,13 +228,10 @@ class App extends Component {
}
}
getInvestInfo
=
()
=>
{
getInvestInfo
=
()
=>
{
var
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
investToken
.
value
);
var
symbol
=
this
.
props
.
exchange
.
investToken
.
value
;
var
token
=
this
.
symbolToTokenContract
(
this
.
props
.
exchange
.
investToken
.
value
);
var
exchange
=
this
.
symbolToExchangeContract
(
symbol
);
var
exchangeAddress
=
this
.
symbolToExchangeAddress
(
this
.
props
.
exchange
.
investToken
.
value
)
var
token
=
this
.
symbolToTokenContract
(
symbol
);
var
exchangeAddress
=
this
.
symbolToExchangeAddress
(
symbol
);
exchange
.
methods
.
invariant
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
setInvestInvariant
(
result
);
});
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
setInvestEthPool
(
result
);
this
.
props
.
setInvestEthPool
(
result
);
...
@@ -284,35 +266,27 @@ class App extends Component {
...
@@ -284,35 +266,27 @@ class App extends Component {
var
exchange
;
var
exchange
;
if
(
type
===
'
input
'
)
{
if
(
type
===
'
input
'
)
{
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
inputToken
.
value
);
exchange
.
methods
.
invariant
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
setInvariant1
(
result
);
// console.log('Input Invariant: ' + result);
});
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
set
MarketEth
1
(
result
);
this
.
props
.
set
EthPool
1
(
result
);
// console.log('Input Market ETH: ' + result);
// console.log('Input Market ETH: ' + result);
});
});
exchange
.
methods
.
tokenPool
().
call
().
then
((
result
,
error
)
=>
{
exchange
.
methods
.
tokenPool
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
set
MarketTokens
1
(
result
);
this
.
props
.
set
TokenPool
1
(
result
);
// console.log('Input Market Tokens: ' + result);
// console.log('Input Market Tokens: ' + result);
});
});
}
else
if
(
type
===
'
output
'
)
{
}
else
if
(
type
===
'
output
'
)
{
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
exchange
=
this
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
outputToken
.
value
);
exchange
.
methods
.
invariant
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
setInvariant2
(
result
);
// console.log('Output Invariant: ' + result);
});
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
set
MarketEth
2
(
result
);
this
.
props
.
set
EthPool
2
(
result
);
// console.log('Output Market ETH: ' + result);
// console.log('Output Market ETH: ' + result);
});
});
exchange
.
methods
.
tokenPool
().
call
().
then
((
result
,
error
)
=>
{
exchange
.
methods
.
tokenPool
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
set
MarketTokens
2
(
result
);
this
.
props
.
set
TokenPool
2
(
result
);
// console.log('Output Market Tokens: ' + result);
// console.log('Output Market Tokens: ' + result);
});
});
}
}
...
@@ -486,12 +460,10 @@ const mapDispatchToProps = (dispatch) => {
...
@@ -486,12 +460,10 @@ const mapDispatchToProps = (dispatch) => {
factoryContractReady
,
factoryContractReady
,
setInputBalance
,
setInputBalance
,
setOutputBalance
,
setOutputBalance
,
setInvariant1
,
setEthPool1
,
setInvariant2
,
setEthPool2
,
setMarketEth1
,
setTokenPool1
,
setMarketEth2
,
setTokenPool2
,
setMarketTokens1
,
setMarketTokens2
,
setAllowanceApprovalState
,
setAllowanceApprovalState
,
initializeGlobalWeb3
,
initializeGlobalWeb3
,
toggleAbout
,
toggleAbout
,
...
@@ -502,7 +474,6 @@ const mapDispatchToProps = (dispatch) => {
...
@@ -502,7 +474,6 @@ const mapDispatchToProps = (dispatch) => {
setInvestEthPool
,
setInvestEthPool
,
setInvestTokenPool
,
setInvestTokenPool
,
setInvestTokenAllowance
,
setInvestTokenAllowance
,
setInvestInvariant
,
setInvestShares
,
setInvestShares
,
setUserShares
,
setUserShares
,
setInvestTokenBalance
,
setInvestTokenBalance
,
...
...
src/actions/exchange-actions.js
View file @
309bd109
...
@@ -3,19 +3,16 @@ import {
...
@@ -3,19 +3,16 @@ import {
SET_OUTPUT_BALANCE
,
SET_OUTPUT_BALANCE
,
SET_INPUT_TOKEN
,
SET_INPUT_TOKEN
,
SET_OUTPUT_TOKEN
,
SET_OUTPUT_TOKEN
,
SET_INVARIANT_1
,
SET_ETH_POOL_1
,
SET_INVARIANT_2
,
SET_ETH_POOL_2
,
SET_MARKET_ETH_1
,
SET_TOKEN_POOL_1
,
SET_MARKET_ETH_2
,
SET_TOKEN_POOL_2
,
SET_MARKET_TOKENS_1
,
SET_MARKET_TOKENS_2
,
SET_ALLOWANCE_APPROVAL_STATE
,
SET_ALLOWANCE_APPROVAL_STATE
,
SET_EXCHANGE_INPUT_VALUE
,
SET_EXCHANGE_INPUT_VALUE
,
SET_EXCHANGE_OUTPUT_VALUE
,
SET_EXCHANGE_OUTPUT_VALUE
,
SET_EXCHANGE_RATE
,
SET_EXCHANGE_RATE
,
SET_EXCHANGE_FEE
,
SET_EXCHANGE_FEE
,
SET_INVEST_TOKEN
,
SET_INVEST_TOKEN
,
SET_INVEST_INVARIANT
,
SET_INVEST_ETH_POOL
,
SET_INVEST_ETH_POOL
,
SET_INVEST_TOKEN_POOL
,
SET_INVEST_TOKEN_POOL
,
SET_INVEST_SHARES
,
SET_INVEST_SHARES
,
...
@@ -49,34 +46,24 @@ export const setOutputToken = (outputToken) => ({
...
@@ -49,34 +46,24 @@ export const setOutputToken = (outputToken) => ({
outputToken
outputToken
});
});
export
const
set
Invariant1
=
(
invariant
1
)
=>
({
export
const
set
EthPool1
=
(
ethPool
1
)
=>
({
type
:
SET_
INVARIANT
_1
,
type
:
SET_
ETH_POOL
_1
,
invariant
1
ethPool
1
});
});
export
const
set
Invariant2
=
(
invariant
2
)
=>
({
export
const
set
EthPool2
=
(
ethPool
2
)
=>
({
type
:
SET_
INVARIANT
_2
,
type
:
SET_
ETH_POOL
_2
,
invariant
2
ethPool
2
});
});
export
const
set
MarketEth1
=
(
marketEth
1
)
=>
({
export
const
set
TokenPool1
=
(
tokenPool
1
)
=>
({
type
:
SET_
MARKET_ETH_1
,
type
:
SET_
TOKEN_POOL_2
,
marketEth
1
tokenPool
1
});
});
export
const
setMarketEth2
=
(
marketEth2
)
=>
({
export
const
setTokenPool2
=
(
tokenPool2
)
=>
({
type
:
SET_MARKET_ETH_2
,
type
:
SET_TOKEN_POOL_2
,
marketEth2
tokenPool2
});
export
const
setMarketTokens1
=
(
marketTokens1
)
=>
({
type
:
SET_MARKET_TOKENS_1
,
marketTokens1
});
export
const
setMarketTokens2
=
(
marketTokens2
)
=>
({
type
:
SET_MARKET_TOKENS_2
,
marketTokens2
});
});
export
const
setAllowanceApprovalState
=
(
allowanceApproved
)
=>
({
export
const
setAllowanceApprovalState
=
(
allowanceApproved
)
=>
({
...
@@ -109,11 +96,6 @@ export const setInvestToken = (investToken) => ({
...
@@ -109,11 +96,6 @@ export const setInvestToken = (investToken) => ({
investToken
investToken
});
});
export
const
setInvestInvariant
=
(
investInvariant
)
=>
({
type
:
SET_INVEST_INVARIANT
,
investInvariant
});
export
const
setInvestEthPool
=
(
investEthPool
)
=>
({
export
const
setInvestEthPool
=
(
investEthPool
)
=>
({
type
:
SET_INVEST_ETH_POOL
,
type
:
SET_INVEST_ETH_POOL
,
investEthPool
investEthPool
...
...
src/components/Exchange.js
View file @
309bd109
...
@@ -49,22 +49,22 @@ class Exchange extends Component {
...
@@ -49,22 +49,22 @@ class Exchange extends Component {
// TODO: change this to use the redux-subscribe pattern
// TODO: change this to use the redux-subscribe pattern
getMarketType
=
()
=>
{
getMarketType
=
()
=>
{
var
marketType
=
''
;
var
marketType
=
''
;
if
(
this
.
props
.
exchange
.
inputToken
.
value
===
'
ETH
'
&&
this
.
props
.
exchange
.
outputToken
.
value
===
'
ETH
'
)
{
var
inputSymbol
=
this
.
props
.
exchange
.
inputToken
.
value
;
var
outputSymbol
=
this
.
props
.
exchange
.
outputToken
.
value
;
if
(
inputSymbol
===
'
ETH
'
&&
outputSymbol
===
'
ETH
'
)
{
marketType
=
'
ETH to ETH
'
;
marketType
=
'
ETH to ETH
'
;
this
.
props
.
setInteractionState
(
'
error1
'
);
this
.
props
.
setInteractionState
(
'
error1
'
);
}
else
if
(
this
.
props
.
exchange
.
inputToken
.
value
===
this
.
props
.
exchange
.
outputToken
.
value
){
}
else
if
(
inputSymbol
===
outputSymbol
){
marketType
=
'
Token to itself
'
;
marketType
=
'
Token to itself
'
;
}
else
if
(
this
.
props
.
exchange
.
inputToken
.
value
===
'
ETH
'
){
}
else
if
(
inputSymbol
===
'
ETH
'
){
marketType
=
'
ETH to Token
'
;
marketType
=
'
ETH to Token
'
;
}
else
if
(
this
.
props
.
exchange
.
outputToken
.
value
===
'
ETH
'
){
}
else
if
(
outputSymbol
===
'
ETH
'
){
marketType
=
'
Token to ETH
'
;
marketType
=
'
Token to ETH
'
;
}
else
{
}
else
{
marketType
=
'
Token to Token
'
;
marketType
=
'
Token to Token
'
;
}
}
this
.
props
.
setExchangeType
(
marketType
);
this
.
props
.
setExchangeType
(
marketType
);
console
.
log
(
'
type:
'
,
marketType
);
console
.
log
(
'
type:
'
,
marketType
,
'
input:
'
,
inputSymbol
,
'
output:
'
,
outputSymbol
);
console
.
log
(
'
input:
'
,
this
.
props
.
exchange
.
inputToken
.
value
);
console
.
log
(
'
output:
'
,
this
.
props
.
exchange
.
outputToken
.
value
);
}
}
getExchangeRate
=
(
input
)
=>
{
getExchangeRate
=
(
input
)
=>
{
...
@@ -81,44 +81,42 @@ class Exchange extends Component {
...
@@ -81,44 +81,42 @@ class Exchange extends Component {
}
}
ethToTokenRate
=
(
ethInput
)
=>
{
ethToTokenRate
=
(
ethInput
)
=>
{
var
ethInMarket
=
+
this
.
props
.
exchange
.
marketEth
2
;
var
ethInMarket
=
+
this
.
props
.
exchange
.
ethPool
2
;
var
tokensInMarket
=
+
this
.
props
.
exchange
.
marketTokens
2
;
var
tokensInMarket
=
+
this
.
props
.
exchange
.
tokenPool
2
;
var
invar
=
+
this
.
props
.
exchange
.
invariant2
;
var
invar
=
ethInMarket
*
tokensInMarket
var
ethIn
=
ethInput
*
10
**
18
;
var
ethIn
=
ethInput
*
10
**
18
;
var
exchangeFee
=
ethIn
/
500
;
var
exchangeFee
=
ethIn
/
500
;
var
ethSold
=
ethIn
-
exchangeFee
;
var
ethSold
=
ethIn
-
exchangeFee
;
var
newEthInMarket
=
ethInMarket
+
ethSold
;
var
newEthInMarket
=
ethInMarket
+
ethSold
;
var
newTokensInMarket
=
invar
/
newEthInMarket
;
var
newTokensInMarket
=
invar
/
newEthInMarket
;
var
tokensOut
=
tokensInMarket
-
newTokensInMarket
;
var
tokensOut
=
tokensInMarket
-
newTokensInMarket
;
var
adjustedTokensOut
=
tokensOut
*
0.98
;
var
buyRate
=
tokensOut
/
ethIn
;
var
buyRate
=
adjustedTokensOut
/
ethIn
;
this
.
props
.
setExchangeRate
(
buyRate
);
this
.
props
.
setExchangeRate
(
buyRate
);
this
.
props
.
setExchangeFee
(
exchangeFee
);
this
.
props
.
setExchangeFee
(
exchangeFee
);
this
.
props
.
setExchangeOutputValue
(
adjustedT
okensOut
);
this
.
props
.
setExchangeOutputValue
(
t
okensOut
);
}
}
tokenToEthRate
=
(
tokenInput
)
=>
{
tokenToEthRate
=
(
tokenInput
)
=>
{
var
ethInMarket
=
+
this
.
props
.
exchange
.
marketEth
1
;
var
ethInMarket
=
+
this
.
props
.
exchange
.
ethPool
1
;
var
tokensInMarket
=
+
this
.
props
.
exchange
.
marketTokens
1
;
var
tokensInMarket
=
+
this
.
props
.
exchange
.
tokenPool
1
;
var
invar
=
+
this
.
props
.
exchange
.
invariant1
;
var
invar
=
ethInMarket
*
tokensInMarket
;
var
tokensIn
=
tokenInput
*
10
**
18
;
var
tokensIn
=
tokenInput
*
10
**
18
;
var
exchangeFee
=
tokensIn
/
500
;
var
exchangeFee
=
tokensIn
/
500
;
var
tokensSold
=
tokensIn
-
exchangeFee
;
var
tokensSold
=
tokensIn
-
exchangeFee
;
var
newTokensInMarket
=
tokensInMarket
+
tokensSold
;
var
newTokensInMarket
=
tokensInMarket
+
tokensSold
;
var
newEthInMarket
=
invar
/
newTokensInMarket
;
var
newEthInMarket
=
invar
/
newTokensInMarket
;
var
ethOut
=
ethInMarket
-
newEthInMarket
;
var
ethOut
=
ethInMarket
-
newEthInMarket
;
var
adjustedEthOut
=
ethOut
*
0.98
;
var
buyRate
=
ethOut
/
tokensIn
;
var
buyRate
=
adjustedEthOut
/
tokensIn
;
this
.
props
.
setExchangeRate
(
buyRate
);
this
.
props
.
setExchangeRate
(
buyRate
);
this
.
props
.
setExchangeFee
(
exchangeFee
);
this
.
props
.
setExchangeFee
(
exchangeFee
);
this
.
props
.
setExchangeOutputValue
(
adjustedE
thOut
);
this
.
props
.
setExchangeOutputValue
(
e
thOut
);
}
}
tokenToTokenRate
=
(
tokenInput
)
=>
{
tokenToTokenRate
=
(
tokenInput
)
=>
{
// Token to ETH on Exchange 1
// Token to ETH on Exchange 1
var
ethInMarket1
=
+
this
.
props
.
exchange
.
marketEth
1
;
var
ethInMarket1
=
+
this
.
props
.
exchange
.
ethPool
1
;
var
tokensInMarket1
=
+
this
.
props
.
exchange
.
marketTokens
1
;
var
tokensInMarket1
=
+
this
.
props
.
exchange
.
tokenPool
1
;
var
invar1
=
+
this
.
props
.
exchange
.
invarian
t1
;
var
invar1
=
ethInMarket1
*
tokensInMarke
t1
;
var
tokensIn
=
tokenInput
*
10
**
18
;
var
tokensIn
=
tokenInput
*
10
**
18
;
var
exchangeFee1
=
tokensIn
/
500
;
var
exchangeFee1
=
tokensIn
/
500
;
var
tokensSold
=
tokensIn
-
exchangeFee1
;
var
tokensSold
=
tokensIn
-
exchangeFee1
;
...
@@ -126,19 +124,18 @@ class Exchange extends Component {
...
@@ -126,19 +124,18 @@ class Exchange extends Component {
var
newEthInMarket1
=
invar1
/
newTokensInMarket1
;
var
newEthInMarket1
=
invar1
/
newTokensInMarket1
;
var
ethToExchange2
=
ethInMarket1
-
newEthInMarket1
;
var
ethToExchange2
=
ethInMarket1
-
newEthInMarket1
;
// ETH to Token on Exchange 2
// ETH to Token on Exchange 2
var
ethInMarket2
=
+
this
.
props
.
exchange
.
marketEth
2
;
var
ethInMarket2
=
+
this
.
props
.
exchange
.
ethPool
2
;
var
tokensInMarket2
=
+
this
.
props
.
exchange
.
marketTokens
2
;
var
tokensInMarket2
=
+
this
.
props
.
exchange
.
tokenPool
2
;
var
invar2
=
+
this
.
props
.
exchange
.
invarian
t2
;
var
invar2
=
ethInMarket2
*
tokensInMarke
t2
;
var
exchangeFee2
=
ethToExchange2
/
500
;
var
exchangeFee2
=
ethToExchange2
/
500
;
var
ethSold
=
ethToExchange2
-
exchangeFee2
;
var
ethSold
=
ethToExchange2
-
exchangeFee2
;
var
newEthInMarket2
=
ethInMarket2
+
ethSold
;
var
newEthInMarket2
=
ethInMarket2
+
ethSold
;
var
newTokensInMarket2
=
invar2
/
newEthInMarket2
;
var
newTokensInMarket2
=
invar2
/
newEthInMarket2
;
var
tokensOut
=
tokensInMarket2
-
newTokensInMarket2
;
var
tokensOut
=
tokensInMarket2
-
newTokensInMarket2
;
var
adjustedTokensOut
=
tokensOut
*
0.98
;
var
buyRate
=
tokensOut
/
tokensIn
;
var
buyRate
=
adjustedTokensOut
/
tokensIn
;
this
.
props
.
setExchangeRate
(
buyRate
);
this
.
props
.
setExchangeRate
(
buyRate
);
this
.
props
.
setExchangeFee
(
exchangeFee1
);
this
.
props
.
setExchangeFee
(
exchangeFee1
);
this
.
props
.
setExchangeOutputValue
(
adjustedT
okensOut
);
this
.
props
.
setExchangeOutputValue
(
t
okensOut
);
}
}
render
()
{
render
()
{
...
...
src/components/Invest.js
View file @
309bd109
...
@@ -4,7 +4,6 @@ import { connect } from 'react-redux';
...
@@ -4,7 +4,6 @@ import { connect } from 'react-redux';
import
{
bindActionCreators
}
from
'
redux
'
;
import
{
bindActionCreators
}
from
'
redux
'
;
import
{
setInvestToken
,
import
{
setInvestToken
,
setInvestInvariant
,
setInvestEthPool
,
setInvestEthPool
,
setInvestTokenPool
,
setInvestTokenPool
,
setInvestShares
,
setInvestShares
,
...
@@ -25,7 +24,6 @@ class Invest extends Component {
...
@@ -25,7 +24,6 @@ class Invest extends Component {
this
.
getInvestExchangeState
();
this
.
getInvestExchangeState
();
this
.
getInvestBalance
();
this
.
getInvestBalance
();
}
else
{
}
else
{
this
.
props
.
setInvestInvariant
(
0
);
this
.
props
.
setInvestTokenPool
(
0
);
this
.
props
.
setInvestTokenPool
(
0
);
this
.
props
.
setInvestEthPool
(
0
);
this
.
props
.
setInvestEthPool
(
0
);
this
.
props
.
setInvestTokenBalance
(
0
);
this
.
props
.
setInvestTokenBalance
(
0
);
...
@@ -49,10 +47,6 @@ class Invest extends Component {
...
@@ -49,10 +47,6 @@ class Invest extends Component {
getInvestExchangeState
=
()
=>
{
getInvestExchangeState
=
()
=>
{
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
investToken
.
value
);
var
exchange
=
this
.
props
.
symbolToExchangeContract
(
this
.
props
.
exchange
.
investToken
.
value
);
exchange
.
methods
.
invariant
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
setInvestInvariant
(
result
);
});
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
exchange
.
methods
.
ethPool
().
call
().
then
((
result
,
error
)
=>
{
this
.
props
.
setInvestEthPool
(
result
);
this
.
props
.
setInvestEthPool
(
result
);
});
});
...
@@ -181,7 +175,6 @@ const mapStateToProps = state => ({
...
@@ -181,7 +175,6 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
(
dispatch
)
=>
{
const
mapDispatchToProps
=
(
dispatch
)
=>
{
return
bindActionCreators
({
return
bindActionCreators
({
setInvestToken
,
setInvestToken
,
setInvestInvariant
,
setInvestEthPool
,
setInvestEthPool
,
setInvestTokenPool
,
setInvestTokenPool
,
setInvestShares
,
setInvestShares
,
...
...
src/constants.js
View file @
309bd109
// here is where we put the string literals for the actions
// string literals for actions
// set global web3 object
export
const
INITIALIZE_GLOBAL_WEB3
=
'
INITIALIZE_GLOBAL_WEB3
'
;
// web3 actions, all set from action creator to reducer to app
// web3 actions, all set from action creator to reducer to app
export
const
SET_WEB3_CONNECTION_STATUS
=
'
WEB3_CONNECTION_STATUS
'
;
export
const
SET_WEB3_CONNECTION_STATUS
=
'
WEB3_CONNECTION_STATUS
'
;
...
@@ -13,43 +16,30 @@ export const SET_NETWORK_MESSAGE = 'SET_NETWORK_MESSAGE';
...
@@ -13,43 +16,30 @@ export const SET_NETWORK_MESSAGE = 'SET_NETWORK_MESSAGE';
export
const
SET_BLOCK_TIMESTAMP
=
'
SET_BLOCK_TIMESTAMP
'
;
export
const
SET_BLOCK_TIMESTAMP
=
'
SET_BLOCK_TIMESTAMP
'
;
export
const
SET_EXCHANGE_TYPE
=
'
SET_EXCHANGE_TYPE
'
;
export
const
SET_EXCHANGE_TYPE
=
'
SET_EXCHANGE_TYPE
'
;
// action
to toggle the 'about' div
// action
s to toggle divs
export
const
TOGGLE_ABOUT
=
'
TOGGLE_ABOUT
'
;
export
const
TOGGLE_ABOUT
=
'
TOGGLE_ABOUT
'
;
// action to toggle the 'invest' div
export
const
TOGGLE_INVEST
=
'
TOGGLE_INVEST
'
;
export
const
TOGGLE_INVEST
=
'
TOGGLE_INVEST
'
;
//
factory contract action, also set
//
CONTRACT actions in actions, action creator, reducer
export
const
FACTORY_CONTRACT_READY
=
'
FACTORY_CONTRACT_READY
'
;
export
const
FACTORY_CONTRACT_READY
=
'
FACTORY_CONTRACT_READY
'
;
// token EXCHANGE contract actions, in action creator, reducer, and app
export
const
UNI_EXCHANGE_CONTRACT_READY
=
'
UNI_EXCHANGE_CONTRACT_READY
'
;
export
const
SWT_EXCHANGE_CONTRACT_READY
=
'
SWT_EXCHANGE_CONTRACT_READY
'
;
export
const
EXCHANGE_CONTRACT_READY
=
'
EXCHANGE_CONTRACT_READY
'
;
export
const
EXCHANGE_CONTRACT_READY
=
'
EXCHANGE_CONTRACT_READY
'
;
// token CONTRACT actions in actions, action creator, reducer
export
const
UNI_TOKEN_CONTRACT_READY
=
'
UNI_TOKEN_CONTRACT_READY
'
;
export
const
SWT_TOKEN_CONTRACT_READY
=
'
SWT_TOKEN_CONTRACT_READY
'
;
export
const
TOKEN_CONTRACT_READY
=
'
TOKEN_CONTRACT_READY
'
;
export
const
TOKEN_CONTRACT_READY
=
'
TOKEN_CONTRACT_READY
'
;
// actions for the exchange
, all in one place
// actions for the exchange
export
const
SET_INPUT_BALANCE
=
'
SET_INPUT_BALANCE
'
;
export
const
SET_INPUT_BALANCE
=
'
SET_INPUT_BALANCE
'
;
export
const
SET_OUTPUT_BALANCE
=
'
SET_OUTPUT_BALANCE
'
;
export
const
SET_OUTPUT_BALANCE
=
'
SET_OUTPUT_BALANCE
'
;
export
const
SET_INPUT_TOKEN
=
'
SET_INPUT_TOKEN
'
;
export
const
SET_INPUT_TOKEN
=
'
SET_INPUT_TOKEN
'
;
export
const
SET_OUTPUT_TOKEN
=
'
SET_OUTPUT_TOKEN
'
;
export
const
SET_OUTPUT_TOKEN
=
'
SET_OUTPUT_TOKEN
'
;
export
const
SET_INVARIANT_1
=
'
SET_INVARIANT_1
'
;
export
const
SET_ETH_POOL_1
=
'
SET_ETH_POOL_1
'
;
export
const
SET_INVARIANT_2
=
'
SET_INVARIANT_2
'
;
export
const
SET_ETH_POOL_2
=
'
SET_ETH_POOL_2
'
;
export
const
SET_MARKET_ETH_1
=
'
SET_MARKET_ETH_1
'
;
export
const
SET_TOKEN_POOL_1
=
'
SET_TOKEN_POOL_1
'
;
export
const
SET_MARKET_ETH_2
=
'
SET_MARKET_ETH_2
'
;
export
const
SET_TOKEN_POOL_2
=
'
SET_TOKEN_POOL_2
'
;
export
const
SET_MARKET_TOKENS_1
=
'
SET_MARKET_TOKENS_1
'
;
export
const
SET_MARKET_TOKENS_2
=
'
SET_MARKET_TOKENS_2
'
;
export
const
SET_ALLOWANCE_APPROVAL_STATE
=
'
SET_ALLOWANCE_APPROVAL_STATE
'
;
export
const
SET_ALLOWANCE_APPROVAL_STATE
=
'
SET_ALLOWANCE_APPROVAL_STATE
'
;
export
const
SET_EXCHANGE_INPUT_VALUE
=
'
SET_EXCHANGE_INPUT_VALUE
'
;
export
const
SET_EXCHANGE_INPUT_VALUE
=
'
SET_EXCHANGE_INPUT_VALUE
'
;
export
const
SET_EXCHANGE_OUTPUT_VALUE
=
'
SET_EXCHANGE_OUTPUT_VALUE
'
;
export
const
SET_EXCHANGE_OUTPUT_VALUE
=
'
SET_EXCHANGE_OUTPUT_VALUE
'
;
export
const
SET_EXCHANGE_RATE
=
'
SET_EXCHANGE_RATE
'
;
export
const
SET_EXCHANGE_RATE
=
'
SET_EXCHANGE_RATE
'
;
export
const
SET_EXCHANGE_FEE
=
'
SET_EXCHANGE_FEE
'
;
export
const
SET_EXCHANGE_FEE
=
'
SET_EXCHANGE_FEE
'
;
export
const
SET_INVEST_TOKEN
=
'
SET_INVEST_TOKEN
'
;
export
const
SET_INVEST_TOKEN
=
'
SET_INVEST_TOKEN
'
;
export
const
SET_INVEST_INVARIANT
=
'
SET_INVEST_INVARIANT
'
;
export
const
SET_INVEST_ETH_POOL
=
'
SET_INVEST_ETH
'
;
export
const
SET_INVEST_ETH_POOL
=
'
SET_INVEST_ETH
'
;
export
const
SET_INVEST_TOKEN_POOL
=
'
SET_INVEST_TOKENS
'
;
export
const
SET_INVEST_TOKEN_POOL
=
'
SET_INVEST_TOKENS
'
;
export
const
SET_INVEST_TOKEN_ALLOWANCE
=
'
SET_INVEST_TOKEN_ALLOWANCE
'
;
export
const
SET_INVEST_TOKEN_ALLOWANCE
=
'
SET_INVEST_TOKEN_ALLOWANCE
'
;
...
@@ -61,7 +51,3 @@ export const SET_INVEST_SHARES_INPUT = 'SET_INVEST_SHARES_INPUT';
...
@@ -61,7 +51,3 @@ export const SET_INVEST_SHARES_INPUT = 'SET_INVEST_SHARES_INPUT';
export
const
SET_INVEST_ETH_REQUIRED
=
'
SET_INVEST_ETH_REQUIRED
'
;
export
const
SET_INVEST_ETH_REQUIRED
=
'
SET_INVEST_ETH_REQUIRED
'
;
export
const
SET_INVEST_TOKENS_REQUIRED
=
'
SET_INVEST_TOKENS_REQUIRED
'
;
export
const
SET_INVEST_TOKENS_REQUIRED
=
'
SET_INVEST_TOKENS_REQUIRED
'
;
export
const
SET_INVEST_CHECKED
=
'
SET_INVEST_CHECKED
'
;
export
const
SET_INVEST_CHECKED
=
'
SET_INVEST_CHECKED
'
;
// test setInteractionState
export
const
INITIALIZE_GLOBAL_WEB3
=
'
INITIALIZE_GLOBAL_WEB3
'
;
src/reducers/exchange-reducer.js
View file @
309bd109
...
@@ -3,19 +3,16 @@ import {
...
@@ -3,19 +3,16 @@ import {
SET_OUTPUT_BALANCE
,
SET_OUTPUT_BALANCE
,
SET_INPUT_TOKEN
,
SET_INPUT_TOKEN
,
SET_OUTPUT_TOKEN
,
SET_OUTPUT_TOKEN
,
SET_INVARIANT_1
,
SET_ETH_POOL_1
,
SET_INVARIANT_2
,
SET_ETH_POOL_2
,
SET_MARKET_ETH_1
,
SET_TOKEN_POOL_1
,
SET_MARKET_ETH_2
,
SET_TOKEN_POOL_2
,
SET_MARKET_TOKENS_1
,
SET_MARKET_TOKENS_2
,
SET_ALLOWANCE_APPROVAL_STATE
,
SET_ALLOWANCE_APPROVAL_STATE
,
SET_EXCHANGE_INPUT_VALUE
,
SET_EXCHANGE_INPUT_VALUE
,
SET_EXCHANGE_OUTPUT_VALUE
,
SET_EXCHANGE_OUTPUT_VALUE
,
SET_EXCHANGE_RATE
,
SET_EXCHANGE_RATE
,
SET_EXCHANGE_FEE
,
SET_EXCHANGE_FEE
,
SET_INVEST_TOKEN
,
SET_INVEST_TOKEN
,
SET_INVEST_INVARIANT
,
SET_INVEST_ETH_POOL
,
SET_INVEST_ETH_POOL
,
SET_INVEST_TOKEN_POOL
,
SET_INVEST_TOKEN_POOL
,
SET_INVEST_TOKEN_ALLOWANCE
,
SET_INVEST_TOKEN_ALLOWANCE
,
...
@@ -37,10 +34,10 @@ export default (state = {}, action) => {
...
@@ -37,10 +34,10 @@ export default (state = {}, action) => {
outputToken
,
outputToken
,
invariant1
,
invariant1
,
invariant2
,
invariant2
,
marketEth
1
,
ethPool
1
,
marketEth
2
,
ethPool
2
,
marketTokens
1
,
tokenPool
1
,
marketTokens
2
,
tokenPool
2
,
allowanceApproved
,
allowanceApproved
,
inputValue
,
inputValue
,
outputValue
,
outputValue
,
...
@@ -70,18 +67,14 @@ export default (state = {}, action) => {
...
@@ -70,18 +67,14 @@ export default (state = {}, action) => {
return
Object
.
assign
({},
state
,
{
inputToken
:
inputToken
});
return
Object
.
assign
({},
state
,
{
inputToken
:
inputToken
});
case
SET_OUTPUT_TOKEN
:
case
SET_OUTPUT_TOKEN
:
return
Object
.
assign
({},
state
,
{
outputToken
:
outputToken
});
return
Object
.
assign
({},
state
,
{
outputToken
:
outputToken
});
case
SET_INVARIANT_1
:
case
SET_ETH_POOL_1
:
return
Object
.
assign
({},
state
,
{
invariant1
:
invariant1
});
return
Object
.
assign
({},
state
,
{
ethPool1
:
ethPool1
});
case
SET_INVARIANT_2
:
case
SET_ETH_POOL_2
:
return
Object
.
assign
({},
state
,
{
invariant2
:
invariant2
});
return
Object
.
assign
({},
state
,
{
ethPool2
:
ethPool2
});
case
SET_MARKET_ETH_1
:
case
SET_TOKEN_POOL_1
:
return
Object
.
assign
({},
state
,
{
marketEth1
:
marketEth1
});
return
Object
.
assign
({},
state
,
{
tokenPool1
:
tokenPool1
});
case
SET_MARKET_ETH_2
:
case
SET_TOKEN_POOL_2
:
return
Object
.
assign
({},
state
,
{
marketEth2
:
marketEth2
});
return
Object
.
assign
({},
state
,
{
tokenPool2
:
tokenPool2
});
case
SET_MARKET_TOKENS_1
:
return
Object
.
assign
({},
state
,
{
marketTokens1
:
marketTokens1
});
case
SET_MARKET_TOKENS_2
:
return
Object
.
assign
({},
state
,
{
marketTokens2
:
marketTokens2
});
case
SET_ALLOWANCE_APPROVAL_STATE
:
case
SET_ALLOWANCE_APPROVAL_STATE
:
return
Object
.
assign
({},
state
,
{
allowanceApproved
:
allowanceApproved
});
return
Object
.
assign
({},
state
,
{
allowanceApproved
:
allowanceApproved
});
case
SET_EXCHANGE_INPUT_VALUE
:
case
SET_EXCHANGE_INPUT_VALUE
:
...
@@ -94,8 +87,6 @@ export default (state = {}, action) => {
...
@@ -94,8 +87,6 @@ export default (state = {}, action) => {
return
Object
.
assign
({},
state
,
{
fee
:
fee
});
return
Object
.
assign
({},
state
,
{
fee
:
fee
});
case
SET_INVEST_TOKEN
:
case
SET_INVEST_TOKEN
:
return
Object
.
assign
({},
state
,
{
investToken
:
investToken
});
return
Object
.
assign
({},
state
,
{
investToken
:
investToken
});
case
SET_INVEST_INVARIANT
:
return
Object
.
assign
({},
state
,
{
investInvariant
:
investInvariant
});
case
SET_INVEST_ETH_POOL
:
case
SET_INVEST_ETH_POOL
:
return
Object
.
assign
({},
state
,
{
investEthPool
:
investEthPool
});
return
Object
.
assign
({},
state
,
{
investEthPool
:
investEthPool
});
case
SET_INVEST_TOKEN_POOL
:
case
SET_INVEST_TOKEN_POOL
:
...
...
src/reducers/exchangeContract-reducer.js
View file @
309bd109
import
{
import
{
UNI_EXCHANGE_CONTRACT_READY
,
SWT_EXCHANGE_CONTRACT_READY
,
EXCHANGE_CONTRACT_READY
EXCHANGE_CONTRACT_READY
}
from
'
../constants
'
}
from
'
../constants
'
export
default
(
state
=
{},
action
)
=>
{
export
default
(
state
=
{},
action
)
=>
{
const
{
contract
,
payload
}
=
action
;
const
{
contract
,
payload
}
=
action
;
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
case
UNI_EXCHANGE_CONTRACT_READY
:
case
EXCHANGE_CONTRACT_READY
:
return
Object
.
assign
({},
state
,
{
UNI
:
contract
});
case
SWT_EXCHANGE_CONTRACT_READY
:
return
Object
.
assign
({},
state
,
{
SWT
:
contract
});
case
EXCHANGE_CONTRACT_READY
:
return
Object
.
assign
({},
state
,
payload
)
return
Object
.
assign
({},
state
,
payload
)
default
:
return
state
;
default
:
return
state
;
}
}
}
}
\ No newline at end of file
src/reducers/tokenContract-reducer.js
View file @
309bd109
import
{
import
{
UNI_TOKEN_CONTRACT_READY
,
SWT_TOKEN_CONTRACT_READY
,
TOKEN_CONTRACT_READY
TOKEN_CONTRACT_READY
}
from
'
../constants
'
;
}
from
'
../constants
'
;
export
default
(
state
=
{},
action
)
=>
{
export
default
(
state
=
{},
action
)
=>
{
const
{
contract
,
payload
}
=
action
;
const
{
contract
,
payload
}
=
action
;
switch
(
action
.
type
)
{
switch
(
action
.
type
)
{
case
UNI_TOKEN_CONTRACT_READY
:
case
TOKEN_CONTRACT_READY
:
return
Object
.
assign
({},
state
,
{
UNI
:
contract
});
case
SWT_TOKEN_CONTRACT_READY
:
return
Object
.
assign
({},
state
,
{
SWT
:
contract
});
case
TOKEN_CONTRACT_READY
:
return
Object
.
assign
({},
state
,
payload
)
return
Object
.
assign
({},
state
,
payload
)
default
:
return
state
;
default
:
return
state
;
}
}
}
}
\ No newline at end of file
src/store/initial-state.js
View file @
309bd109
...
@@ -39,18 +39,15 @@ export default {
...
@@ -39,18 +39,15 @@ export default {
inputToken
:
{
value
:
'
ETH
'
,
label
:
'
ETH
'
,
clearableValue
:
false
},
inputToken
:
{
value
:
'
ETH
'
,
label
:
'
ETH
'
,
clearableValue
:
false
},
outputToken
:
{
value
:
'
BAT
'
,
label
:
'
BAT
'
,
clearableValue
:
false
},
outputToken
:
{
value
:
'
BAT
'
,
label
:
'
BAT
'
,
clearableValue
:
false
},
investToken
:
{
value
:
'
BAT
'
,
label
:
'
BAT
'
,
clearableValue
:
false
},
investToken
:
{
value
:
'
BAT
'
,
label
:
'
BAT
'
,
clearableValue
:
false
},
invariant1
:
0
,
ethPool1
:
0
,
invariant2
:
0
,
ethPool2
:
0
,
marketEth1
:
0
,
tokenPool1
:
0
,
marketEth2
:
0
,
tokenPool2
:
0
,
marketTokens1
:
0
,
marketTokens2
:
0
,
allowanceApproved
:
true
,
allowanceApproved
:
true
,
inputValue
:
0
,
inputValue
:
0
,
outputValue
:
0
,
outputValue
:
0
,
rate
:
0
,
rate
:
0
,
fee
:
0
,
fee
:
0
,
investInvariant
:
0
,
investEthPool
:
0
,
investEthPool
:
0
,
investTokenPool
:
0
,
investTokenPool
:
0
,
investShares
:
0
,
investShares
:
0
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment