-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish all code. real deposit/2-step withdrawal/redeem for UMA; edit …
…Balancer weights.
- Loading branch information
1 parent
5b9320c
commit cf148e7
Showing
24 changed files
with
567 additions
and
121 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
function deposit_collateral(pie, uma_address) { | ||
var amount = $('#amount').val(); | ||
|
||
if (amount > 0) { | ||
try { | ||
uma_deposit(uma_address, amount.toString()); | ||
|
||
jQuery.ajax({url: '/pies/'+ pie + '/deposit_collateral.js', | ||
data: {'amount': amount}, | ||
type: "PUT", | ||
success: function(data) { update_graphics(JSON.parse(data)); }, | ||
error: function() { alert('Oh noes!'); }, | ||
async: false}); | ||
} | ||
catch(err) { | ||
alert(JSON.stringify(err)); | ||
} | ||
} | ||
else { | ||
alert("Please enter a valid amount"); | ||
} | ||
} | ||
|
||
async function uma_deposit(uma_address, amount) { | ||
web3 = new Web3(web3.currentProvider); | ||
provider = new ethers.providers.Web3Provider(web3.currentProvider); | ||
|
||
var emp = new ethers.Contract(uma_address, | ||
JSON.parse('<%=EMP_ABI.html_safe%>'), | ||
provider.getSigner(0)); | ||
|
||
await emp.deposit({ rawValue: web3.utils.toWei(amount) }); | ||
} | ||
|
||
async function request_withdrawal(pool, uma_address) { | ||
var amount = $('#amount').val(); | ||
|
||
if (amount > 0) { | ||
web3 = new Web3(web3.currentProvider); | ||
provider = new ethers.providers.Web3Provider(web3.currentProvider); | ||
|
||
var emp = new ethers.Contract(uma_address, | ||
JSON.parse('<%=EMP_ABI.html_safe%>'), | ||
provider.getSigner(0)); | ||
|
||
try { | ||
await emp.requestWithdrawal({ rawValue: web3.utils.toWei(amount) }); | ||
|
||
jQuery.ajax({url: '/balancer_pools/'+ pool + '/request_withdrawal.js', | ||
data: {'amount': amount}, | ||
type: "PUT", | ||
success: function(data) { alert("If undisputed, your withdrawal will be available in 2 hours"); window.location.reload(); }, | ||
error: function() { alert('You cannot withdraw so much that your collateralization falls below the minimum!'); }, | ||
async: false}); | ||
} | ||
catch(err) { | ||
alert(JSON.stringify(err)); | ||
} | ||
} | ||
else { | ||
alert("Please enter a valid amount"); | ||
} | ||
} | ||
|
||
function withdraw_collateral(pie, uma_address) { | ||
try { | ||
uma_withdrawal(uma_address); | ||
|
||
jQuery.ajax({url: '/pies/'+ pie + '/withdraw_collateral.js', | ||
type: "PUT", | ||
success: function(data) { update_graphics(JSON.parse(data)); }, | ||
error: function() { alert('You cannot withdraw so much that your collateralization falls below the minimum!'); }, | ||
async: false}); | ||
} | ||
catch(err) { | ||
alert(JSON.stringify(err)); | ||
} | ||
} | ||
|
||
async function uma_withdrawal(uma_address) { | ||
web3 = new Web3(web3.currentProvider); | ||
provider = new ethers.providers.Web3Provider(web3.currentProvider); | ||
|
||
var emp = new ethers.Contract(uma_address, | ||
JSON.parse('<%=EMP_ABI.html_safe%>'), | ||
provider.getSigner(0)); | ||
|
||
await emp.withdrawPassedRequest(); | ||
} | ||
|
||
function redeem_tokens(pie, uma_address) { | ||
var amount = $('#amount').val(); | ||
|
||
if (amount > 0) { | ||
try { | ||
uma_redeem(uma_address, amount); | ||
|
||
jQuery.ajax({url: '/pies/'+ pie + '/redeem_tokens.js', | ||
data: {'amount': amount}, | ||
type: "PUT", | ||
success: function(data) { update_graphics(JSON.parse(data)); }, | ||
error: function() { alert('Oh noes!'); }, | ||
async: false}); | ||
} | ||
catch(err) { | ||
alert(JSON.stringify(err)); | ||
} | ||
} | ||
else { | ||
alert("Please enter a valid amount"); | ||
} | ||
} | ||
|
||
async function uma_redeem(uma_address, amount) { | ||
web3 = new Web3(web3.currentProvider); | ||
provider = new ethers.providers.Web3Provider(web3.currentProvider); | ||
|
||
var emp = new ethers.Contract(uma_address, | ||
JSON.parse('<%=EMP_ABI.html_safe%>'), | ||
provider.getSigner(0)); | ||
|
||
// Get the address of the synthetic token we deployed | ||
const tokenAddress = await emp.tokenCurrency(); | ||
|
||
var syntheticToken = new ethers.Contract(tokenAddress, | ||
JSON.parse('<%=SYNTHETIC_TOKEN_ABI.html_safe%>'), | ||
provider.getSigner(0)); | ||
|
||
await syntheticToken.approve(uma_address, web3.utils.toWei(amount.toString())); | ||
|
||
await emp.redeem({ rawValue: web3.utils.toWei(amount.toString()) }); | ||
} | ||
|
||
function update_graphics(data) { | ||
$('#collateralization').text(data.collateralization); | ||
$('#collateral_progress').attr('class', data.progress_class + " progress-bar progress-bar-striped"); | ||
$('#adjustments').text(data.adjustments); | ||
$('#total_value').text(data.total_value); | ||
} |
Oops, something went wrong.