marginswap / marginswap-interface Goto Github PK
View Code? Open in Web Editor NEWThe marginswap trading UI
License: GNU General Public License v3.0
The marginswap trading UI
License: GNU General Public License v3.0
In the account balances component, we have been using fake data to populate our component prototypes. Replace that fake data with the real data coming from getAccountBalances()
.
The risk gauge on the Margin Account page is not working correctly. Probably because the algorithm is not correct.
Look at this for how it should work:
https://www.binance.com/en-IN/support/faq/360030493931
DrO says:
When margin level≤1.15, our system will trigger the liquidation engine and we will send you a notification by mail, text message and internal message to inform you that all assets will be liquidated to pay back the interest and loan.
1.15 is when we trigger
but when we get on faster chains, we will probably reduce to 1.1
Ethereum is too slow and clogged for us to do 1.1
Go to https://master--nifty-poitras-d43873.netlify.app/ to quickly see the current state of UI mockup.
This is the most important change we need to do today: The margin account is only supposed to display account information, without the current swap side bar:
This swap part currently displayed in the margin account view is supposed to replace the main trading UI:
So, please find those two components and replace them. For now this replacement can be relatively quick & dirty!
If I'm not mistaken the borrow interest rate displayed currently is just the lending interest rate times 2, which is correct in the general case, but not always. We should create an SDK endpoint that gets the borrowing interest rate from the Lending smart contract directly instead.
Check discord for more info
We need a couple of explainer for the table on margin account and bond lending page
Bond lending
APY: Cap at 2 decimal and add % sign
Total supplied: Also cap the UI element at 2 decimal (just the ui)
This is a how to video link. Can we have it on the ui? https://www.youtube.com/watch?v=rGGPAOCpDRs
In this file the code that we forked tries to find the best route for a specific trade on uniswap.
What we want is to generalize from just uniswap to using sushiswap as well, for looking for trading routes.
Please look for the best place in the code where we could generalize over getting data from uniswap to getting data from both uniswap and sushiswap and choosing the best route on the best system.
rename what's currently called liquidity in the margin account table to "borrowable"
and create a new column that lists the entire liquidity in that token, not just how much an individual trader can currently borrow.
Make it so that users can switch between spot and margin trading -- it's the same interface, just the ability to switch.
We can query the ethereum blockchain via infura directly, as well as through wallets such as metamask. Both infura and metamask act as providers to frameworks such as ethers
or web3
.
Next to async requests, the infura provider also offers websocket connections with listeners which we can use in conjunction with events in our contracts to update account state without polling.
The wallet is used to send signed transactions to the blockchain.
In both lending and borrowing the set of possible tokens is fixed, hence there is a very common case where we will just iterate over the list of tokens and get information like interest rate, price or the bond lending balance for each token in the list.
The cross margin trading account has a view function that returns just the tokens that an account holds and borrows (and their balances).
Some of the logic for getting and updating prices, tracking transactions etc. already exists in uniswap
and hopefully we can reuse it.
otherwise users will think it didn't go through
Make a branch where unfinshed stuff is hidden
NEW SPEC:
Modify Balances component to match this wireframe, i.e. it will include borrowing / dept, so we don't need a separate component:
We're currently making too many requests to the SDK/contract.
Create and execute a plan to reduce polling for data.
the max button on withdraw doesn't leave enough dust and then transactions can fail.
MAX
should pick an amount with some additional buffer.
Also when a user has debt that hasn't be paid, it makes sense that the user can't withdraw max.
Our code executes trades using ERC20 tokens on on-chain markets such as uniswap or sushiswap. We forked the uniswap code, but we want to expand it to not only do trades on uniswap, but also on sushiswap (which is compatible), if the price on sushiswap is better.
In this file the code that we forked tries to find the best route for a specific trade on uniswap: useTradeExactIn
and useTradeExactOut
both call to the Pair
class in the SDK. Currently this Pair
class imports a constant called FACTORY_ADDRESS
.
factoryAddress
an attribute of the class Pair
.useAllCommonPairs
should retrieve pairs for both uniswap and sushiswap.You may run into problems testing this. Let me know
Right now users can edit the token list and add tokens to the margin account interface -- which just got one user confuse.
They probably clicked on the manage button and imported their favorite token and were disappointed they couldn't trade it.
For now we should make sure that in margin we only show our approved token list
On swap page, the borrowable amount should not exceed the available liquidity in any given token.
This goes for both the displayed borrowable amount and the input validation. They should both be capped so they don't exceed the liquidity available for the selected token.
The margin account table should have a column for total amount available for borrowing in that token, using this endpoint. Furthermore, the borrowableInPeg2token
function in src/state/wallet/hooks/
should cap any borrowable amount in that token by that total amount.
We need a form to
A lot of the necessary building blocks should be in the code (i.e. the dropdown with tokens should be in the trading window code).
If while going through this you gain a good understanding you can look at the contract contracts/MarginRouter.sol
in the core repo, find the parallels to the uniswap router in the functions like crossSwapExactTokensForTokens
and work towards wiring them up similarly to the classic uniswap router contract.
Please look into this.
Some of these will require SDK functions and maybe view functions in the contracts.
APY = (100 + APR/n)**n - 100
, where APR
is a percentage and n = 24 * 365
,i.e. hours per year.HourlyBondSubscriptionLending
contract. Either by reading the struct directly from this public variable, which would be called as HourlyBondSubscriptionLendingContract.hourlyBondAccounts(token, lenderAddress)
, which I believe returns a tuple which I'm not sure how `ethersjs parses that out. Alternatively we could write a new view function or add it to an existing view function.Lending
, similarly to how crossDeposit
works in the margin-account
part of the SDK.PriceAware
contract class is deployed at the same address as the CrossMarginTrading
contract -- you may need to use the address of CrossMarginTrading
, but the .abi
of PriceAware
when initializing the Contract
object in the typescript code.APR / 365
Please delete the BOND RATE table.
As discussed, I deleted token list logic and probably broke something in loading the token list for the margin account and bond supply page. perhaps dig through the git history and restore the appropriate functions
On localhost, I first went to deposit 10 DAI in bond. clicked approve, and approved in metamask, then I see an "approve error" red toaster, followed by a notification from metamask that my transaction was completed successfully.
I then go and deposit 10 DAI into my margin account and click "borrow" to borrow 10 dai. again I get an "aprrove error" toast, on the borrow button, even though borrow should have nothing to do with approve
Add feature flags for "Stake" tab and ETH buttons in Margin Account table.
Stake tab should not be visible by default. Use ?stake=1 to view it.
on the Margin Account page, the "Deposit ETH" and "Withdraw ETH" buttons should not be visible by default. use ?eth=1 to view them
the maturity column should display how many minutes until an hourly bond can be withdrawn.
does the current logic work, because I see nothing. maybe it's nothing coming back from the smart contract? please debug
An extension of account balances component
We want a box component that contains a listing of:
There should be code for getting token icons and names from the token address somewhere in the repo.
If that's easy to find, make the component take that data structure as input, otherwise just make something up and we'll figure it out later.
For the swap page we need to calculate how much of a token a user can trade, which is a combination of how much they hold and how much they can borrow.
For this we need to get:
getHoldingAmounts
in the SDKgetAccountHoldingTotal
and getAccountBorrowTotal
borrowTargetInPeg = 3 * (holdingTotal - borrowTotal)
borrowTargetInPeg
back into the original token. (there should be code repo already for querying the price along the best route?) -- let me know if you wanna talk about this.The available amount is borrowTargetInToken + holdingAmounts
when I borrow tokens, the number displayed in margin accounts can go up and down more than it should. it even dips below the original amount. may well be on the contract side, but worth checking whether it's a UI thing
Can you make our staking panel ux be like this?
they should be in the decimals of the peg currency.
On kovan right now, DAI
is the peg currency. It has 18 decimals. On local it's currently USDT
which has 6. For now just make the number of peg decimals configurable somewhere in a constant.
We may switch everything over to DAI
, need to discuss.
On the bond supply page and probably also on the margin account page the input fields don't allow for fractions (i.e. numbers with a decimal point), they should and the fractions should be then interpreted according to the decimals of the token that is being entered.
If the swap page is in margin mode, we should show the (previously hidden) borrowable field and show the value that gets computed in the borrowable
function, (aplied to the input token) in the SDK newly added
Some stuff can't be renamed immediately, so we'll just change things as we go.
Currently some check in the swap logic sensibly keeps you from trading if you don't have enough balance in a token.
Ideally we would calculate holdings + borrowable for this. For now we can just torn off the check?
Basically:
RATE_UPDATE_WINDOW = 0 seconds; withdrawalWindow = 60 minutes
npx hardhat node
parseFloat() only has ~10-12 digits of precision
but we need 18 in eth. Refer to other implementations of the BigNumber in the code base to replace all parseFloat()'s
Please replace the menu bar with the following items:
And link to the views that you have developed
all the following amounts are denominated in the token itself (not USD)
Is interest rate being loaded in margin account and lending?
To repoduce:
note that WETH balance is correct on Swap page, just not on Margin Account page
The spot interface should have the exact same behavior that the existing uniswap swapping interface has
The price / routing parts of the interface should have the same behavior, only that balances come from the margin account contract. Swap transactions should be sent to the margin router.
Also the margin interface only allows using the marginswap token list (you have access to the repo).
the swap button is replaced by a "connect wallet" button if it's not connected.
TokenAmount
as the value for setHoldingAmounts
and setBorrowingAmounts
in src/pages/MarginAccount/index.tsx
L87-88 and then change the calls in L246-251 to create TokenAmounts from the address of the token and the value. -- and then we probably want to use the formattedCurrencyAmount
function to format those stringswhen I click to connect my wallet i see broken image stuff instead of wallet logos. do we need api keys to laod the logos or is it something else?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.