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
7d49acec
Commit
7d49acec
authored
Jan 20, 2018
by
Hayden Adams
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web3 calls return errors and receipts, add factory
parent
c22503bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
21 deletions
+146
-21
App.js
src/App.js
+53
-21
factoryABI.js
src/helpers/factoryABI.js
+93
-0
No files found.
src/App.js
View file @
7d49acec
...
...
@@ -9,6 +9,7 @@ import './App.css';
import
{
exchangeABI
}
from
'
./helpers/exchangeABI.js
'
import
{
tokenABI
}
from
'
./helpers/tokenABI.js
'
import
{
factoryABI
}
from
'
./helpers/factoryABI.js
'
var
localweb3
;
...
...
@@ -30,18 +31,24 @@ class App extends Component {
const
uniTokenAddress
=
'
0x350E5DD084ecF271e8d3531D4324443952F47756
'
;
const
uniTokenContract
=
new
localweb3
.
eth
.
Contract
(
tokenABI
,
uniTokenAddress
);
const
swapTokenAddress
=
'
0x
350E5DD084ecF271e8d3531D4324443952F47756
'
;
const
swapTokenAddress
=
'
0x
8B2A87F8243f23C33fb97E23a21Ae8EDB3b71AcA
'
;
const
swapTokenContract
=
new
localweb3
.
eth
.
Contract
(
tokenABI
,
swapTokenAddress
);
const
factoryAddress
=
'
0xD6D22d102A4237F3D35361BC022a78789E6174Aa
'
;
const
factoryContract
=
new
localweb3
.
eth
.
Contract
(
factoryABI
,
factoryAddress
);
this
.
state
=
{
uniExchangeAddress
:
'
0xcDc30C3b02c5776495298198377D2Fc0fd6B1F1C
'
,
swapExchangeAddress
:
'
0x4632a7Cd732c625dcc48d75E289c209422e1D2B7
'
,
uniTokenAddress
:
'
0x350E5DD084ecF271e8d3531D4324443952F47756
'
,
swapTokenAddress
:
'
0x8B2A87F8243f23C33fb97E23a21Ae8EDB3b71AcA
'
,
currentMaskAddress
:
'
0x0000000000000000000000000000000000000000
'
,
factoryAddress
:
'
0xD6D22d102A4237F3D35361BC022a78789E6174Aa
'
,
uniExchange
:
uniExchangeContract
,
uniToken
:
uniTokenContract
,
swapExchange
:
swapExchangeContract
,
swapToken
:
swapTokenContract
,
factory
:
factoryContract
,
ethBalance
:
0
,
tokenBalance
:
0
,
tokenAllowance
:
null
,
...
...
@@ -80,14 +87,17 @@ class App extends Component {
componentDidMount
(){
this
.
getAccountInfo
();
this
.
getMarketInfo
(
'
output
'
,
'
UNI
'
);
// setInterval(this.helloWorld, 2000);
}
// helloWorld = () => {
// console.log('Hello World')
// }
getAccountInfo
=
()
=>
{
setTimeout
(()
=>
{
this
.
getEthBalance
();
this
.
getTokenBalance
();
this
.
getAllowance
();
},
1000
);
this
.
getEthBalance
();
this
.
getTokenBalance
();
this
.
getAllowance
();
}
getMarketInfo
=
(
type
,
symbol
)
=>
{
...
...
@@ -125,6 +135,12 @@ class App extends Component {
// })
}
tokenToExchangeFactoryLookup
=
(
tokenAddress
)
=>
{
this
.
state
.
factory
.
methods
.
tokenToExchangeLookup
(
tokenAddress
).
call
((
error
,
exchangeAddress
)
=>
{
console
.
log
(
exchangeAddress
)
});
}
checkNetwork
()
{
localweb3
.
eth
.
net
.
getNetworkType
((
err
,
networkId
)
=>
{
console
.
log
(
"
Connected to
"
+
networkId
)
...
...
@@ -216,11 +232,13 @@ class App extends Component {
onSelectToken
=
(
selected
,
type
)
=>
{
// console.log(selected)
// console.log(type)
this
.
setState
({
input
:
0
,
output
:
0
,
rate
:
0
,
fee
:
0
,
interaction
:
'
connected
'
})
var
marketType
=
''
;
if
(
type
===
'
input
'
)
{
this
.
setState
({
inputToken
:
selected
});
if
(
selected
.
value
===
this
.
state
.
outputToken
.
value
)
{
marketType
=
'
Invalid
'
;
this
.
setState
({
interaction
:
'
error1
'
});
}
else
if
(
selected
.
value
===
'
ETH
'
){
marketType
=
'
ETH to Token
'
;
this
.
getMarketInfo
(
'
output
'
,
this
.
state
.
outputToken
.
value
);
...
...
@@ -236,6 +254,7 @@ class App extends Component {
this
.
setState
({
outputToken
:
selected
});
if
(
selected
.
value
===
this
.
state
.
inputToken
.
value
)
{
marketType
=
'
Invalid
'
;
this
.
setState
({
interaction
:
'
error1
'
});
}
else
if
(
selected
.
value
===
'
ETH
'
){
marketType
=
'
Token to ETH
'
;
this
.
getMarketInfo
(
'
input
'
,
this
.
state
.
outputToken
.
value
);
...
...
@@ -248,32 +267,39 @@ class App extends Component {
this
.
getMarketInfo
(
'
output
'
,
selected
.
value
);
}
}
console
.
log
(
"
Exchange Type:
"
+
marketType
)
console
.
log
(
type
+
'
:
'
+
selected
.
value
);
console
.
log
(
'
Exchange Type:
'
+
marketType
);
this
.
setState
({
exchangeType
:
marketType
});
}
onInputChange
=
(
event
)
=>
{
var
inputValue
=
event
.
target
.
value
;
if
(
inputValue
&&
inputValue
!==
0
){
this
.
setState
({
input
:
inputValue
,
interaction
:
'
input
'
});
this
.
getExchangeRate
(
inputValue
);
var
marketType
=
this
.
state
.
exchangeType
;
if
(
marketType
===
'
Invalid
'
){
this
.
setState
({
input
:
inputValue
,
output
:
0
,
interaction
:
'
error1
'
});
}
else
if
(
inputValue
&&
inputValue
!==
0
&&
inputValue
!==
'
0
'
){
this
.
setState
({
input
:
inputValue
,
interaction
:
'
input
'
});
this
.
getExchangeRate
(
inputValue
);
}
else
{
this
.
setState
({
input
:
inputValue
,
output
:
0
,
interaction
:
'
connected
'
});
this
.
setState
({
input
:
inputValue
,
output
:
0
,
interaction
:
'
connected
'
});
}
}
getExchangeRate
=
(
input
)
=>
{
if
(
this
.
state
.
exchangeType
===
'
ETH to Token
'
)
{
console
.
log
(
'
Getting Rate: ETH to
'
+
this
.
state
.
outputToken
.
value
);
this
.
ethToTokenRate
(
input
);
}
else
if
(
this
.
state
.
exchangeType
===
'
Token to ETH
'
)
{
console
.
log
(
'
Getting Rate: ETH to
'
+
this
.
state
.
outputToken
.
value
);
this
.
tokenToEthRate
(
input
);
}
else
if
(
this
.
state
.
exchangeType
===
'
Token to Token
'
)
{
console
.
log
(
'
Getting Rate:
'
+
this
.
state
.
inputToken
.
value
+
'
to
'
+
this
.
state
.
outputToken
.
value
);
this
.
tokenToTokenRate
(
input
);
}
}
purchaseTokens
=
()
=>
{
console
.
log
(
this
.
state
.
exchangeType
);
if
(
this
.
state
.
exchangeType
===
'
ETH to Token
'
)
{
this
.
ethToTokenPurchase
();
}
else
if
(
this
.
state
.
exchangeType
===
'
Token to ETH
'
)
{
...
...
@@ -293,7 +319,7 @@ class App extends Component {
var
newEthInMarket
=
ethInMarket
+
ethSold
;
var
newTokensInMarket
=
invar
/
newEthInMarket
;
var
tokensOut
=
tokensInMarket
-
newTokensInMarket
;
var
adjustedTokensOut
=
tokensOut
*
0.9
9
;
var
adjustedTokensOut
=
tokensOut
*
0.9
8
;
var
buyRate
=
adjustedTokensOut
/
ethIn
;
this
.
setState
({
rate
:
buyRate
,
fee
:
exchangeFee
,
...
...
@@ -311,7 +337,7 @@ class App extends Component {
var
newTokensInMarket
=
tokensInMarket
+
tokensSold
;
var
newEthInMarket
=
invar
/
newTokensInMarket
;
var
ethOut
=
ethInMarket
-
newEthInMarket
;
var
adjustedEthOut
=
ethOut
*
0.9
9
;
var
adjustedEthOut
=
ethOut
*
0.9
8
;
var
buyRate
=
adjustedEthOut
/
tokensIn
;
this
.
setState
({
rate
:
buyRate
,
fee
:
exchangeFee
,
...
...
@@ -339,7 +365,7 @@ class App extends Component {
var
newEthInMarket2
=
ethInMarket2
+
ethSold
;
var
newTokensInMarket2
=
invar2
/
newEthInMarket2
;
var
tokensOut
=
tokensInMarket2
-
newTokensInMarket2
;
var
adjustedTokensOut
=
tokensOut
*
0.9
9
;
var
adjustedTokensOut
=
tokensOut
*
0.9
8
;
var
buyRate
=
adjustedTokensOut
/
tokensIn
;
this
.
setState
({
rate
:
buyRate
,
fee
:
exchangeFee1
,
...
...
@@ -367,8 +393,10 @@ class App extends Component {
var
timeout
=
time
+
300
;
//current block time + 5mins
exchange
.
methods
.
ethToTokenSwap
(
minTokensInt
,
timeout
).
send
(
{
from
:
this
.
state
.
currentMaskAddress
,
value
:
weiSold
},
function
(
err
,
txHash
)
{})
{
from
:
this
.
state
.
currentMaskAddress
,
value
:
weiSold
})
.
on
(
'
transactionHash
'
,
console
.
log
(
'
Transaction Hash created
'
))
.
on
(
'
receipt
'
,
(
receipt
)
=>
{
console
.
log
(
receipt
)})
//Success
.
on
(
'
error
'
,
console
.
error
);
});
}
...
...
@@ -392,8 +420,10 @@ class App extends Component {
var
timeout
=
time
+
300
;
//current block time + 5mins
exchange
.
methods
.
tokenToEthSwap
(
tokensSoldInt
,
minEthInt
,
timeout
).
send
(
{
from
:
this
.
state
.
currentMaskAddress
},
function
(
err
,
txHash
)
{})
{
from
:
this
.
state
.
currentMaskAddress
})
.
on
(
'
transactionHash
'
,
console
.
log
(
'
Transaction Hash created
'
))
.
on
(
'
receipt
'
,
(
receipt
)
=>
{
console
.
log
(
receipt
)})
//Success
.
on
(
'
error
'
,
console
.
error
);
});
}
...
...
@@ -420,8 +450,10 @@ class App extends Component {
var
timeout
=
time
+
300
;
//current block time + 5mins
exchange
.
methods
.
tokenToTokenSwap
(
tokenOutAddress
,
tokensSoldInt
,
minTokensInt
,
timeout
).
send
(
{
from
:
this
.
state
.
currentMaskAddress
},
function
(
err
,
txHash
)
{})
{
from
:
this
.
state
.
currentMaskAddress
})
.
on
(
'
transactionHash
'
,
console
.
log
(
'
Transaction Hash created
'
))
.
on
(
'
receipt
'
,
(
receipt
)
=>
{
console
.
log
(
receipt
)})
//Success
.
on
(
'
error
'
,
console
.
error
);
});
}
...
...
src/helpers/factoryABI.js
View file @
7d49acec
module
.
exports
.
factoryABI
=
[
{
"
constant
"
:
false
,
"
inputs
"
:
[
{
"
name
"
:
"
token
"
,
"
type
"
:
"
address
"
}
],
"
name
"
:
"
createExchange
"
,
"
outputs
"
:
[
{
"
name
"
:
"
exchange
"
,
"
type
"
:
"
address
"
}
],
"
payable
"
:
false
,
"
stateMutability
"
:
"
nonpayable
"
,
"
type
"
:
"
function
"
},
{
"
constant
"
:
true
,
"
inputs
"
:
[],
"
name
"
:
"
getExchangeCount
"
,
"
outputs
"
:
[
{
"
name
"
:
"
exchangeCount
"
,
"
type
"
:
"
uint256
"
}
],
"
payable
"
:
false
,
"
stateMutability
"
:
"
view
"
,
"
type
"
:
"
function
"
},
{
"
constant
"
:
true
,
"
inputs
"
:
[
{
"
name
"
:
""
,
"
type
"
:
"
uint256
"
}
],
"
name
"
:
"
tokenList
"
,
"
outputs
"
:
[
{
"
name
"
:
""
,
"
type
"
:
"
address
"
}
],
"
payable
"
:
false
,
"
stateMutability
"
:
"
view
"
,
"
type
"
:
"
function
"
},
{
"
constant
"
:
true
,
"
inputs
"
:
[
{
"
name
"
:
"
token
"
,
"
type
"
:
"
address
"
}
],
"
name
"
:
"
tokenToExchangeLookup
"
,
"
outputs
"
:
[
{
"
name
"
:
"
exchange
"
,
"
type
"
:
"
address
"
}
],
"
payable
"
:
false
,
"
stateMutability
"
:
"
view
"
,
"
type
"
:
"
function
"
},
{
"
constant
"
:
true
,
"
inputs
"
:
[
{
"
name
"
:
"
exchange
"
,
"
type
"
:
"
address
"
}
],
"
name
"
:
"
exchangeToTokenLookup
"
,
"
outputs
"
:
[
{
"
name
"
:
"
token
"
,
"
type
"
:
"
address
"
}
],
"
payable
"
:
false
,
"
stateMutability
"
:
"
view
"
,
"
type
"
:
"
function
"
}
]
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