dydxprotocol / perpetual Goto Github PK
View Code? Open in Web Editor NEWEthereum Smart Contracts and TypeScript library used for the dYdX Perpetual Contracts
License: Apache License 2.0
Ethereum Smart Contracts and TypeScript library used for the dYdX Perpetual Contracts
License: Apache License 2.0
contracts/test/v1/
set up test contracts for the Funder
, Oracle
, Trader
, and Vault
.src/lib/modules/
set up a Testing.ts
file that helps us set the values for these contracts. You can use https://github.com/dydxprotocol/solo/blob/master/src/modules/testing/Testing.ts for inspirationsrc/Perpetual.ts
migrations/2_deploy.js
file if the network is a test networktest/helpers/
that helps set these as the contracts that are used by the protocol. We can use this at the start of most tests>=
to >
One very strange edge case that could happen here is the sign of the position could be different when the transaction is sent, and when it is mined, so as a liquidator you could get the opposite of the trade you want (you could sell when you thought you were going to buy)
Maybe it's worth including a flag in the data as to what side the maker intends to take
In deploy scripts
When we run tests with ENABLE_SOL_TRACE
the sol-trace
library will do its own compilation step when running truffle test
. I had to disable compiler optimization when compiling with Truffle to get the source maps used by sol-trace to match up with the Truffle-compiled contracts.
It seems like the optimizer
setting in compiler.json
is not being respected, even though the file is definitely read by @0x/sol-compiler
and the useDockerisedSolc
option is used.
See:
Add something similar to: https://github.com/dydxprotocol/solo/blob/master/src/modules/Api.ts
#25 adds contracts/Imports.sol
to get sol-trace
to compile successfully when running tests with ENABLE_SOL_TRACE=true
.
The problem seems to be that @0x/sol-compiler
doesn't detect sources in the same way as Truffle, and doesn't include these files when generating the config
object passed as input to solc
.
Ideally we can get rid of Imports.sol
and fix this maybe either through configuration of the compiler via compiler.sol
or by patching @0x/sol-compiler
.
See:
See https://circleci.com/gh/dydxprotocol/workflows/perpetual/tree/ken%2Fsolidity-function-format
6 tests failed with:
Error: Returned error: VM Exception while processing transaction: revert Accounts must be sorted
Then passed when run a second time.
Can either check this in the base protocol or have the Liquidator contract do a get call to the base protocol (the second way is probably better)
Whether that's taking a percentage of all liquidations, etc.
We settled on not doing this for now, but something to consider
Intelligently set the amount to liquidate such that the liquidating account does not become underwater after the liquidation
One solution: allow deleveraging of positions if not deleveraged within X time by the privileged actors
Antonio: "Is there a reason we need to allow the sender to specify the amount at all? Why not just always use Math.min(makerBalance.position, takerBalance.position)
?"
I think it's fine as it gives more flexibility, but I'll let you make the decision Ken
See if you can get this to run (might be easy now that sol-trace is working)
SingedInt
P1BalanceMath
Also: reassigning signedIndexDiff
https://github.com/dydxprotocol/solo/blob/master/contracts/external/traders/CanonicalOrders.sol#L712
If an account has a negativeValue that is greater than it's positive value, then it is underwater. The Deleveraging contract should allow anyone to take one of these accounts and have it be subsumed by any other account that has the opposite position. This contract will be a P1Trader
contract. The deleveraging should not be allowed to make either account "go past zero" in terms of their position size.
To release: Monday morning 4/20
Create a spec we can share publicly on the protocol
Should be within some validated range (shouldn't be below 100%)
Maybe shouldn't be able to be changed more than some percentage at a time
Probably not loading the old cache correctly
Something similar to: https://uniswap.org/bug-bounty/
Another reference: https://medium.com/dydxderivatives/announcing-bug-bounties-for-the-dydx-margin-trading-protocol-d0c817d1cda4
We will still use OWASP so you can include that diagram
solidity-coverage 0.6.x doesn't work with Solidity 0.6.0
solidity-coverage 0.7.x runs through truffle test which uses mocha which doesn't play nice with typescript, so we would have to compile the tests into a different folder and then run truffle test in there. We could move everything over to use mocha instead of jest
To occur Monday morning 4/20
Consider adding a timelock on withdrawals / trades not sent by an admin account. Also would add a way for withdrawals to be performed by signed message
Maker requires this oracle to have a whitelist of addresses that can read from it (aka be the msg.sender)
So make it ownable and able to have a mapping of approved addresses to be approved/unapproved by the owner which will be our multisig
Maker BTC-USD oracle here https://etherscan.io/address/0x064409168198A7E9108036D072eF59F923dEDC9A
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.