Compare commits
97 Commits
@0x/contra
...
@0x/contra
Author | SHA1 | Date | |
---|---|---|---|
|
15f75a08d5 | ||
|
29f9c5473d | ||
|
ea1528aea6 | ||
|
cded58c30d | ||
|
da17b49b81 | ||
|
4728cdfa7c | ||
|
97fb843f01 | ||
|
8afb044877 | ||
|
7f869868c9 | ||
|
31275228ac | ||
|
3b446e887a | ||
|
431196c391 | ||
|
d574ca1628 | ||
|
f97e6892b6 | ||
|
7742901e5c | ||
|
de68cb25d0 | ||
|
68fb6c2c27 | ||
|
a47c031ad1 | ||
|
817049456c | ||
|
e1a061789f | ||
|
28573ba772 | ||
|
880b9413f6 | ||
|
9a7c4b21a9 | ||
|
ac56038eca | ||
|
4dd2fb6903 | ||
|
0baec61f06 | ||
|
d4751788d1 | ||
|
ae68c061d1 | ||
|
b0387245f0 | ||
|
c2d06a4a23 | ||
|
270108abb7 | ||
|
e76c33232d | ||
|
58ff2dc492 | ||
|
13c45a0e96 | ||
|
be7b1a1bd4 | ||
|
132a3c6705 | ||
|
5e73257557 | ||
|
e83346fbbb | ||
|
2dd47a2103 | ||
|
f31e530b6e | ||
|
eb50f3fa9c | ||
|
8417fe4fdb | ||
|
0f1c15a6ca | ||
|
9345c4fb7f | ||
|
5e0758917b | ||
|
f56839ec6b | ||
|
cbb23a42e2 | ||
|
5a59c286d0 | ||
|
2e8c600d7a | ||
|
e851cb1cbc | ||
|
3da03da32a | ||
|
3ec8924e7f | ||
|
a04722b612 | ||
|
f9a7857a90 | ||
|
58f772c74e | ||
|
a425c7e260 | ||
|
809885afd0 | ||
|
bf9b4b993f | ||
|
d94a26f0f4 | ||
|
bd9c9cedca | ||
|
651e94bd94 | ||
|
162b6f1a74 | ||
|
865a253eb5 | ||
|
9b3781abf1 | ||
|
d89243a0d3 | ||
|
b4cefc64b4 | ||
|
2fd26587e5 | ||
|
282a351859 | ||
|
a84b848ea9 | ||
|
d329320fc2 | ||
|
bc096554b5 | ||
|
5902d878d8 | ||
|
3b0c8f6d92 | ||
|
21058c2227 | ||
|
f3b8ae0781 | ||
|
d590b004c1 | ||
|
02e21141c6 | ||
|
f839a3087d | ||
|
f458815541 | ||
|
7ba754d2a4 | ||
|
09706e4ae2 | ||
|
d18de4c541 | ||
|
001c7bfdbc | ||
|
d4e04dc712 | ||
|
8650cb5217 | ||
|
0eaaddeb95 | ||
|
1cf8663f20 | ||
|
5130259552 | ||
|
ba5e19a015 | ||
|
c0400fa986 | ||
|
51179d10ce | ||
|
78752f9178 | ||
|
762db417d7 | ||
|
85bdccbc06 | ||
|
9f8cb99340 | ||
|
87b90bb04b | ||
|
e961d88277 |
@@ -91,3 +91,4 @@ packages/abi-gen/test-cli/fixtures/artifacts/AbiGenDummy.json
|
||||
packages/abi-gen/test-cli/fixtures/artifacts/LibDummy.json
|
||||
packages/abi-gen/test-cli/fixtures/artifacts/TestLibDummy.json
|
||||
packages/*/docs
|
||||
*.sol
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "3.2.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "3.2.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "3.2.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "3.2.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "3.2.1",
|
||||
@@ -11,6 +47,14 @@
|
||||
{
|
||||
"version": "3.2.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add more types and functions to `IDydx`",
|
||||
"pr": 2466
|
||||
},
|
||||
{
|
||||
"note": "Rename `DydxBrigeAction.accountId` to `DydxBridgeAction.accountIdx`",
|
||||
"pr": 2466
|
||||
},
|
||||
{
|
||||
"note": "Fix broken tests.",
|
||||
"pr": 2462
|
||||
@@ -22,6 +66,10 @@
|
||||
{
|
||||
"note": "Add asset data decoding functions",
|
||||
"pr": 2462
|
||||
},
|
||||
{
|
||||
"note": "Add `setOperators()` to `IDydx`",
|
||||
"pr": "TODO"
|
||||
}
|
||||
],
|
||||
"timestamp": 1581204851
|
||||
|
@@ -5,15 +5,34 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.2.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.0 - _February 8, 2020_
|
||||
|
||||
* Add more types and functions to `IDydx` (#2466)
|
||||
* Rename `DydxBrigeAction.accountId` to `DydxBridgeAction.accountIdx` (#2466)
|
||||
* Fix broken tests. (#2462)
|
||||
* Remove dependency on `@0x/contracts-dev-utils` (#2462)
|
||||
* Add asset data decoding functions (#2462)
|
||||
* Add `setOperators()` to `IDydx` (#TODO)
|
||||
|
||||
## v3.1.3 - _February 6, 2020_
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -35,7 +35,7 @@ contract ChaiBridge is
|
||||
/// @param from Address to transfer asset from.
|
||||
/// @param to Address to transfer asset to.
|
||||
/// @param amount Amount of asset to transfer.
|
||||
/// @return success The magic bytes `0x37708e9b` if successful.
|
||||
/// @return success The magic bytes `0xdc1600f3` if successful.
|
||||
function bridgeTransferFrom(
|
||||
address /* tokenAddress */,
|
||||
address from,
|
||||
|
@@ -191,12 +191,12 @@ contract DydxBridge is
|
||||
depositAction = IDydx.ActionArgs({
|
||||
actionType: IDydx.ActionType.Deposit, // deposit tokens.
|
||||
amount: dydxAmount, // amount to deposit.
|
||||
accountId: bridgeAction.accountId, // index in the `accounts` when calling `operate`.
|
||||
accountIdx: bridgeAction.accountIdx, // index in the `accounts` when calling `operate`.
|
||||
primaryMarketId: bridgeAction.marketId, // indicates which token to deposit.
|
||||
otherAddress: depositFrom, // deposit from the account owner.
|
||||
// unused parameters
|
||||
secondaryMarketId: 0,
|
||||
otherAccountId: 0,
|
||||
otherAccountIdx: 0,
|
||||
data: hex''
|
||||
});
|
||||
}
|
||||
@@ -229,12 +229,12 @@ contract DydxBridge is
|
||||
withdrawAction = IDydx.ActionArgs({
|
||||
actionType: IDydx.ActionType.Withdraw, // withdraw tokens.
|
||||
amount: amountToWithdraw, // amount to withdraw.
|
||||
accountId: bridgeAction.accountId, // index in the `accounts` when calling `operate`.
|
||||
accountIdx: bridgeAction.accountIdx, // index in the `accounts` when calling `operate`.
|
||||
primaryMarketId: bridgeAction.marketId, // indicates which token to withdraw.
|
||||
otherAddress: withdrawTo, // withdraw tokens to this address.
|
||||
// unused parameters
|
||||
secondaryMarketId: 0,
|
||||
otherAccountId: 0,
|
||||
otherAccountIdx: 0,
|
||||
data: hex''
|
||||
});
|
||||
}
|
||||
|
@@ -45,12 +45,12 @@ interface IDydx {
|
||||
/// parsed into before being processed.
|
||||
struct ActionArgs {
|
||||
ActionType actionType;
|
||||
uint256 accountId;
|
||||
uint256 accountIdx;
|
||||
AssetAmount amount;
|
||||
uint256 primaryMarketId;
|
||||
uint256 secondaryMarketId;
|
||||
address otherAddress;
|
||||
uint256 otherAccountId;
|
||||
uint256 otherAccountIdx;
|
||||
bytes data;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,36 @@ interface IDydx {
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
struct D256 {
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
struct Value {
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
struct Price {
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
struct OperatorArg {
|
||||
address operator;
|
||||
bool trusted;
|
||||
}
|
||||
|
||||
/// @dev The global risk parameters that govern the health and security of the system
|
||||
struct RiskParams {
|
||||
// Required ratio of over-collateralization
|
||||
D256 marginRatio;
|
||||
// Percentage penalty incurred by liquidated accounts
|
||||
D256 liquidationSpread;
|
||||
// Percentage of the borrower's interest fee that gets passed to the suppliers
|
||||
D256 earningsRate;
|
||||
// The minimum absolute borrow value of an account
|
||||
// There must be sufficient incentivize to liquidate undercollateralized accounts
|
||||
Value minBorrowedValue;
|
||||
}
|
||||
|
||||
/// @dev The main entry-point to Solo that allows users and contracts to manage accounts.
|
||||
/// Take one or more actions on one or more accounts. The msg.sender must be the owner or
|
||||
/// operator of all accounts except for those being liquidated, vaporized, or traded with.
|
||||
@@ -86,4 +116,77 @@ interface IDydx {
|
||||
ActionArgs[] calldata actions
|
||||
)
|
||||
external;
|
||||
|
||||
// @dev Approves/disapproves any number of operators. An operator is an external address that has the
|
||||
// same permissions to manipulate an account as the owner of the account. Operators are simply
|
||||
// addresses and therefore may either be externally-owned Ethereum accounts OR smart contracts.
|
||||
// Operators are also able to act as AutoTrader contracts on behalf of the account owner if the
|
||||
// operator is a smart contract and implements the IAutoTrader interface.
|
||||
// @param args A list of OperatorArgs which have an address and a boolean. The boolean value
|
||||
// denotes whether to approve (true) or revoke approval (false) for that address.
|
||||
function setOperators(OperatorArg[] calldata args) external;
|
||||
|
||||
/// @dev Return true if a particular address is approved as an operator for an owner's accounts.
|
||||
/// Approved operators can act on the accounts of the owner as if it were the operator's own.
|
||||
/// @param owner The owner of the accounts
|
||||
/// @param operator The possible operator
|
||||
/// @return isLocalOperator True if operator is approved for owner's accounts
|
||||
function getIsLocalOperator(
|
||||
address owner,
|
||||
address operator
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (bool isLocalOperator);
|
||||
|
||||
/// @dev Get the ERC20 token address for a market.
|
||||
/// @param marketId The market to query
|
||||
/// @return tokenAddress The token address
|
||||
function getMarketTokenAddress(
|
||||
uint256 marketId
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (address tokenAddress);
|
||||
|
||||
/// @dev Get all risk parameters in a single struct.
|
||||
/// @return riskParams All global risk parameters
|
||||
function getRiskParams()
|
||||
external
|
||||
view
|
||||
returns (RiskParams memory riskParams);
|
||||
|
||||
/// @dev Get the price of the token for a market.
|
||||
/// @param marketId The market to query
|
||||
/// @return price The price of each atomic unit of the token
|
||||
function getMarketPrice(
|
||||
uint256 marketId
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (Price memory price);
|
||||
|
||||
/// @dev Get the margin premium for a market. A margin premium makes it so that any positions that
|
||||
/// include the market require a higher collateralization to avoid being liquidated.
|
||||
/// @param marketId The market to query
|
||||
/// @return premium The market's margin premium
|
||||
function getMarketMarginPremium(uint256 marketId)
|
||||
external
|
||||
view
|
||||
returns (D256 memory premium);
|
||||
|
||||
/// @dev Get the total supplied and total borrowed values of an account adjusted by the marginPremium
|
||||
/// of each market. Supplied values are divided by (1 + marginPremium) for each market and
|
||||
/// borrowed values are multiplied by (1 + marginPremium) for each market. Comparing these
|
||||
/// adjusted values gives the margin-ratio of the account which will be compared to the global
|
||||
/// margin-ratio when determining if the account can be liquidated.
|
||||
/// @param account The account to query
|
||||
/// @return supplyValue The supplied value of the account (adjusted for marginPremium)
|
||||
/// @return borrowValue The borrowed value of the account (adjusted for marginPremium)
|
||||
function getAdjustedAccountValues(
|
||||
AccountInfo calldata account
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (Value memory supplyValue, Value memory borrowValue);
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ interface IDydxBridge {
|
||||
|
||||
struct BridgeAction {
|
||||
BridgeActionType actionType; // Action to run on dydx account.
|
||||
uint256 accountId; // Index in `BridgeData.accountNumbers` for this action.
|
||||
uint256 accountIdx; // Index in `BridgeData.accountNumbers` for this action.
|
||||
uint256 marketId; // Market to operate on.
|
||||
uint256 conversionRateNumerator; // Optional. If set, transfer amount is scaled by (conversionRateNumerator/conversionRateDenominator).
|
||||
uint256 conversionRateDenominator; // Optional. If set, transfer amount is scaled by (conversionRateNumerator/conversionRateDenominator).
|
||||
@@ -39,4 +39,4 @@ interface IDydxBridge {
|
||||
uint256[] accountNumbers; // Account number used to identify the owner's specific account.
|
||||
BridgeAction[] actions; // Actions to carry out on the owner's accounts.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ contract IERC20Bridge {
|
||||
/// @param to Address to transfer asset to.
|
||||
/// @param amount Amount of asset to transfer.
|
||||
/// @param bridgeData Arbitrary asset data needed by the bridge contract.
|
||||
/// @return success The magic bytes `0x37708e9b` if successful.
|
||||
/// @return success The magic bytes `0xdc1600f3` if successful.
|
||||
function bridgeTransferFrom(
|
||||
address tokenAddress,
|
||||
address from,
|
||||
|
@@ -23,6 +23,7 @@ import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
||||
import "../src/bridges/DydxBridge.sol";
|
||||
|
||||
|
||||
// solhint-disable no-empty-blocks
|
||||
contract TestDydxBridgeToken {
|
||||
|
||||
uint256 private constant INIT_HOLDER_BALANCE = 10 * 10**18; // 10 tokens
|
||||
@@ -79,7 +80,7 @@ contract TestDydxBridge is
|
||||
|
||||
event OperateAction(
|
||||
ActionType actionType,
|
||||
uint256 accountId,
|
||||
uint256 accountIdx,
|
||||
bool amountSign,
|
||||
AssetDenomination amountDenomination,
|
||||
AssetReference amountRef,
|
||||
@@ -120,7 +121,7 @@ contract TestDydxBridge is
|
||||
for (uint i = 0; i < actions.length; ++i) {
|
||||
emit OperateAction(
|
||||
actions[i].actionType,
|
||||
actions[i].accountId,
|
||||
actions[i].accountIdx,
|
||||
actions[i].amount.sign,
|
||||
actions[i].amount.denomination,
|
||||
actions[i].amount.ref,
|
||||
@@ -128,7 +129,7 @@ contract TestDydxBridge is
|
||||
actions[i].primaryMarketId,
|
||||
actions[i].secondaryMarketId,
|
||||
actions[i].otherAddress,
|
||||
actions[i].otherAccountId,
|
||||
actions[i].otherAccountIdx,
|
||||
actions[i].data
|
||||
);
|
||||
|
||||
@@ -171,6 +172,60 @@ contract TestDydxBridge is
|
||||
return _testTokenAddress;
|
||||
}
|
||||
|
||||
/// @dev Unused.
|
||||
function setOperators(OperatorArg[] calldata args) external {}
|
||||
|
||||
/// @dev Unused.
|
||||
function getIsLocalOperator(
|
||||
address owner,
|
||||
address operator
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (bool isLocalOperator)
|
||||
{}
|
||||
|
||||
/// @dev Unused.
|
||||
function getMarketTokenAddress(
|
||||
uint256 marketId
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (address tokenAddress)
|
||||
{}
|
||||
|
||||
/// @dev Unused.
|
||||
function getRiskParams()
|
||||
external
|
||||
view
|
||||
returns (RiskParams memory riskParams)
|
||||
{}
|
||||
|
||||
/// @dev Unsused.
|
||||
function getMarketPrice(
|
||||
uint256 marketId
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (Price memory price)
|
||||
{}
|
||||
|
||||
/// @dev Unsused
|
||||
function getMarketMarginPremium(uint256 marketId)
|
||||
external
|
||||
view
|
||||
returns (IDydx.D256 memory premium)
|
||||
{}
|
||||
|
||||
/// @dev Unused.
|
||||
function getAdjustedAccountValues(
|
||||
AccountInfo calldata account
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (Value memory supplyValue, Value memory borrowValue)
|
||||
{}
|
||||
|
||||
/// @dev overrides `_getDydxAddress()` from `DeploymentConstants` to return this address.
|
||||
function _getDydxAddress()
|
||||
internal
|
||||
@@ -188,4 +243,4 @@ contract TestDydxBridge is
|
||||
{
|
||||
return msg.sender == ALWAYS_REVERT_ADDRESS ? address(0) : msg.sender;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-asset-proxy",
|
||||
"version": "3.2.1",
|
||||
"version": "3.2.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -51,12 +51,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/protocol/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@types/lodash": "4.14.104",
|
||||
@@ -78,16 +78,16 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/contracts-erc1155": "^2.1.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-erc721": "^3.1.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/contracts-erc1155": "^2.1.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-erc721": "^3.1.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"ethereum-types": "^3.1.0",
|
||||
"lodash": "^4.17.11"
|
||||
},
|
||||
|
@@ -7,7 +7,7 @@ export enum DydxBridgeActionType {
|
||||
|
||||
export interface DydxBridgeAction {
|
||||
actionType: DydxBridgeActionType;
|
||||
accountId: BigNumber;
|
||||
accountIdx: BigNumber;
|
||||
marketId: BigNumber;
|
||||
conversionRateNumerator: BigNumber;
|
||||
conversionRateDenominator: BigNumber;
|
||||
@@ -29,7 +29,7 @@ export const dydxBridgeDataEncoder = AbiEncoder.create([
|
||||
type: 'tuple[]',
|
||||
components: [
|
||||
{ name: 'actionType', type: 'uint8' },
|
||||
{ name: 'accountId', type: 'uint256' },
|
||||
{ name: 'accountIdx', type: 'uint256' },
|
||||
{ name: 'marketId', type: 'uint256' },
|
||||
{ name: 'conversionRateNumerator', type: 'uint256' },
|
||||
{ name: 'conversionRateDenominator', type: 'uint256' },
|
||||
|
@@ -1,21 +1,22 @@
|
||||
export { artifacts } from './artifacts';
|
||||
export {
|
||||
ChaiBridgeContract,
|
||||
ERC1155ProxyContract,
|
||||
ERC20BridgeProxyContract,
|
||||
ERC20ProxyContract,
|
||||
ERC721ProxyContract,
|
||||
Eth2DaiBridgeContract,
|
||||
DydxBridgeContract,
|
||||
TestDydxBridgeContract,
|
||||
IAssetDataContract,
|
||||
IAssetProxyContract,
|
||||
IChaiContract,
|
||||
IDydxContract,
|
||||
KyberBridgeContract,
|
||||
MultiAssetProxyContract,
|
||||
StaticCallProxyContract,
|
||||
TestDydxBridgeContract,
|
||||
TestStaticCallTargetContract,
|
||||
UniswapBridgeContract,
|
||||
KyberBridgeContract,
|
||||
ChaiBridgeContract,
|
||||
IChaiContract,
|
||||
} from './wrappers';
|
||||
|
||||
export { ERC20Wrapper } from './erc20_wrapper';
|
||||
|
@@ -17,14 +17,14 @@ blockchainTests.resets('DydxBridge unit tests', env => {
|
||||
const notAuthorized = '0x0000000000000000000000000000000000000001';
|
||||
const defaultDepositAction = {
|
||||
actionType: DydxBridgeActionType.Deposit,
|
||||
accountId: constants.ZERO_AMOUNT,
|
||||
accountIdx: constants.ZERO_AMOUNT,
|
||||
marketId,
|
||||
conversionRateNumerator: constants.ZERO_AMOUNT,
|
||||
conversionRateDenominator: constants.ZERO_AMOUNT,
|
||||
};
|
||||
const defaultWithdrawAction = {
|
||||
actionType: DydxBridgeActionType.Withdraw,
|
||||
accountId: constants.ZERO_AMOUNT,
|
||||
accountIdx: constants.ZERO_AMOUNT,
|
||||
marketId,
|
||||
conversionRateNumerator: constants.ZERO_AMOUNT,
|
||||
conversionRateDenominator: constants.ZERO_AMOUNT,
|
||||
@@ -118,7 +118,7 @@ blockchainTests.resets('DydxBridge unit tests', env => {
|
||||
for (const action of bridgeData.actions) {
|
||||
expectedOperateActionEvents.push({
|
||||
actionType: action.actionType as number,
|
||||
accountId: action.accountId,
|
||||
accountIdx: action.accountIdx,
|
||||
amountSign: action.actionType === DydxBridgeActionType.Deposit ? true : false,
|
||||
amountDenomination: weiDenomination,
|
||||
amountRef: deltaAmountRef,
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "1.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "1.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "1.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "1.1.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.1.0",
|
||||
"changes": [
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.1.4 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.3 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.2 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.1 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.1.0 - _February 15, 2020_
|
||||
|
||||
* Added decoders for broker data (#2484)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-broker",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.4",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -51,20 +51,20 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-erc721": "^3.1.1",
|
||||
"@0x/contracts-exchange": "^3.2.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-erc721": "^3.1.5",
|
||||
"@0x/contracts-exchange": "^3.2.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -84,10 +84,10 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"ethereum-types": "^3.1.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "3.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "3.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "3.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "3.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "3.1.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -2,6 +2,7 @@
|
||||
"artifactsDir": "./test/generated-artifacts",
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-coordinator",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -52,19 +52,19 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-dev-utils": "^1.1.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-exchange": "^3.2.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-dev-utils": "^1.3.3",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-exchange": "^3.2.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -84,14 +84,14 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/assert": "^3.0.6",
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/contract-addresses": "^4.6.0",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/json-schemas": "^5.0.6",
|
||||
"@0x/assert": "^3.0.7",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/contract-addresses": "^4.9.0",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/json-schemas": "^5.0.7",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"ethereum-types": "^3.1.0",
|
||||
"http-status-codes": "^1.3.2"
|
||||
},
|
||||
|
@@ -1,4 +1,50 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "1.3.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "1.3.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "1.3.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.3.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Update `DevUtils` addresses in `DeploymentConstants`",
|
||||
"pr": 2493
|
||||
}
|
||||
],
|
||||
"timestamp": 1582623685
|
||||
},
|
||||
{
|
||||
"version": "1.2.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add `DydxBridge` order validation",
|
||||
"pr": 2466
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "1.1.1",
|
||||
|
@@ -5,6 +5,26 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.3.3 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.2 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.1 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.3.0 - _February 25, 2020_
|
||||
|
||||
* Update `DevUtils` addresses in `DeploymentConstants` (#2493)
|
||||
|
||||
## v1.2.0 - _Invalid date_
|
||||
|
||||
* Add `DydxBridge` order validation (#2466)
|
||||
|
||||
## v1.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -34,15 +34,18 @@ contract Addresses is
|
||||
address public erc1155ProxyAddress;
|
||||
address public staticCallProxyAddress;
|
||||
address public chaiBridgeAddress;
|
||||
address public dydxBridgeAddress;
|
||||
|
||||
constructor (
|
||||
address exchange_,
|
||||
address chaiBridge_
|
||||
address chaiBridge_,
|
||||
address dydxBridge_
|
||||
)
|
||||
public
|
||||
{
|
||||
exchangeAddress = exchange_;
|
||||
chaiBridgeAddress = chaiBridge_;
|
||||
dydxBridgeAddress = dydxBridge_;
|
||||
erc20ProxyAddress = IExchange(exchange_).getAssetProxy(IAssetData(address(0)).ERC20Token.selector);
|
||||
erc721ProxyAddress = IExchange(exchange_).getAssetProxy(IAssetData(address(0)).ERC721Token.selector);
|
||||
erc1155ProxyAddress = IExchange(exchange_).getAssetProxy(IAssetData(address(0)).ERC1155Assets.selector);
|
||||
|
@@ -28,7 +28,7 @@ import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol";
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IChai.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
|
||||
import "./Addresses.sol";
|
||||
import "./LibAssetData.sol";
|
||||
import "./LibDydxBalance.sol";
|
||||
|
||||
|
||||
contract AssetBalance is
|
||||
@@ -269,11 +269,14 @@ contract AssetBalance is
|
||||
|
||||
} else if (assetProxyId == IAssetData(address(0)).ERC20Bridge.selector) {
|
||||
// Get address of ERC20 token and bridge contract
|
||||
(, address tokenAddress, address bridgeAddress,) = LibAssetData.decodeERC20BridgeAssetData(assetData);
|
||||
(, address tokenAddress, address bridgeAddress,) =
|
||||
LibAssetData.decodeERC20BridgeAssetData(assetData);
|
||||
if (tokenAddress == _getDaiAddress() && bridgeAddress == chaiBridgeAddress) {
|
||||
uint256 chaiAllowance = LibERC20Token.allowance(_getChaiAddress(), ownerAddress, chaiBridgeAddress);
|
||||
// Dai allowance is unlimited if Chai allowance is unlimited
|
||||
allowance = chaiAllowance == _MAX_UINT256 ? _MAX_UINT256 : _convertChaiToDaiAmount(chaiAllowance);
|
||||
} else if (bridgeAddress == dydxBridgeAddress) {
|
||||
allowance = LibDydxBalance.getDydxMakerAllowance(ownerAddress, bridgeAddress, _getDydxAddress());
|
||||
}
|
||||
// Allowance will be 0 if bridge is not supported
|
||||
}
|
||||
@@ -366,6 +369,17 @@ contract AssetBalance is
|
||||
if (order.makerAssetData.length < 4) {
|
||||
return (0, 0);
|
||||
}
|
||||
bytes4 assetProxyId = order.makerAssetData.readBytes4(0);
|
||||
// Handle dydx bridge assets.
|
||||
if (assetProxyId == IAssetData(address(0)).ERC20Bridge.selector) {
|
||||
(, , address bridgeAddress, ) = LibAssetData.decodeERC20BridgeAssetData(order.makerAssetData);
|
||||
if (bridgeAddress == dydxBridgeAddress) {
|
||||
return (
|
||||
LibDydxBalance.getDydxMakerBalance(order, _getDydxAddress()),
|
||||
getAssetProxyAllowance(order.makerAddress, order.makerAssetData)
|
||||
);
|
||||
}
|
||||
}
|
||||
return (
|
||||
getBalance(order.makerAddress, order.makerAssetData),
|
||||
getAssetProxyAllowance(order.makerAddress, order.makerAssetData)
|
||||
|
@@ -40,12 +40,14 @@ contract DevUtils is
|
||||
{
|
||||
constructor (
|
||||
address exchange_,
|
||||
address chaiBridge_
|
||||
address chaiBridge_,
|
||||
address dydxBridge_
|
||||
)
|
||||
public
|
||||
Addresses(
|
||||
exchange_,
|
||||
chaiBridge_
|
||||
chaiBridge_,
|
||||
dydxBridge_
|
||||
)
|
||||
LibEIP712ExchangeDomain(uint256(0), address(0)) // null args because because we only use constants
|
||||
{}
|
||||
|
436
contracts/dev-utils/contracts/src/LibDydxBalance.sol
Normal file
436
contracts/dev-utils/contracts/src/LibDydxBalance.sol
Normal file
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.16;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetData.sol";
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IDydxBridge.sol";
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IDydx.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
||||
import "@0x/contracts-utils/contracts/src/D18.sol";
|
||||
import "./LibAssetData.sol";
|
||||
|
||||
|
||||
library LibDydxBalance {
|
||||
|
||||
using LibBytes for bytes;
|
||||
using LibSafeMath for uint256;
|
||||
|
||||
/// @dev Padding % added to the minimum collateralization ratio to
|
||||
/// prevent withdrawing exactly the amount that would make an account
|
||||
/// insolvent. 1 bps.
|
||||
int256 private constant MARGIN_RATIO_PADDING = 0.0001e18;
|
||||
|
||||
/// @dev Structure that holds all pertinent info needed to perform a balance
|
||||
/// check.
|
||||
struct BalanceCheckInfo {
|
||||
IDydx dydx;
|
||||
address bridgeAddress;
|
||||
address makerAddress;
|
||||
address makerTokenAddress;
|
||||
address takerTokenAddress;
|
||||
int256 orderMakerToTakerRate;
|
||||
uint256[] accounts;
|
||||
IDydxBridge.BridgeAction[] actions;
|
||||
}
|
||||
|
||||
/// @dev Gets the maker asset allowance for a Dydx bridge order.
|
||||
/// @param makerAddress The maker of the order.
|
||||
/// @param bridgeAddress The address of the Dydx bridge.
|
||||
/// @param dydx The Dydx contract address.
|
||||
/// @return allowance The maker asset allowance.
|
||||
function getDydxMakerAllowance(address makerAddress, address bridgeAddress, address dydx)
|
||||
public
|
||||
view
|
||||
returns (uint256 allowance)
|
||||
{
|
||||
// Allowance is infinite if the dydx bridge is an operator for the maker.
|
||||
return IDydx(dydx).getIsLocalOperator(makerAddress, bridgeAddress)
|
||||
? uint256(-1) : 0;
|
||||
}
|
||||
|
||||
/// @dev Gets the maker allowance for a
|
||||
/// @dev Get the maker asset balance of an order with a `DydxBridge` maker asset.
|
||||
/// @param order An order with a dydx maker asset.
|
||||
/// @param dydx The address of the dydx contract.
|
||||
/// @return balance The maker asset balance.
|
||||
function getDydxMakerBalance(LibOrder.Order memory order, address dydx)
|
||||
public
|
||||
view
|
||||
returns (uint256 balance)
|
||||
{
|
||||
BalanceCheckInfo memory info = _getBalanceCheckInfo(order, dydx);
|
||||
// Actions must be well-formed.
|
||||
if (!_areActionsWellFormed(info)) {
|
||||
return 0;
|
||||
}
|
||||
// If the rate we withdraw maker tokens is less than one, the asset
|
||||
// proxy will throw because we will always transfer less maker tokens
|
||||
// than asked.
|
||||
if (_getMakerTokenWithdrawRate(info) < D18.one()) {
|
||||
return 0;
|
||||
}
|
||||
// The maker balance is the smaller of:
|
||||
return LibSafeMath.min256(
|
||||
// How many times we can execute all the deposit actions.
|
||||
_getDepositableMakerAmount(info),
|
||||
// How many times we can execute all the actions before the an
|
||||
// account becomes undercollateralized.
|
||||
_getSolventMakerAmount(info)
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Checks that:
|
||||
/// 1. Actions are arranged as [...deposits, withdraw].
|
||||
/// 2. There is only one deposit for each market ID.
|
||||
/// 3. Every action has a valid account index.
|
||||
/// 4. There is exactly one withdraw at the end and it is for the
|
||||
/// maker token.
|
||||
/// @param info State from `_getBalanceCheckInfo()`.
|
||||
/// @return areWellFormed Whether the actions are well-formed.
|
||||
function _areActionsWellFormed(BalanceCheckInfo memory info)
|
||||
internal
|
||||
view
|
||||
returns (bool areWellFormed)
|
||||
{
|
||||
if (info.actions.length == 0) {
|
||||
return false;
|
||||
}
|
||||
uint256 depositCount = 0;
|
||||
// Count the number of deposits.
|
||||
for (; depositCount < info.actions.length; ++depositCount) {
|
||||
IDydxBridge.BridgeAction memory action = info.actions[depositCount];
|
||||
if (action.actionType != IDydxBridge.BridgeActionType.Deposit) {
|
||||
break;
|
||||
}
|
||||
// Search all prior actions for the same market ID.
|
||||
uint256 marketId = action.marketId;
|
||||
for (uint256 j = 0; j < depositCount; ++j) {
|
||||
if (info.actions[j].marketId == marketId) {
|
||||
// Market ID is not unique.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check that the account index is within the valid range.
|
||||
if (action.accountIdx >= info.accounts.length) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// There must be exactly one withdraw action at the end.
|
||||
if (depositCount + 1 != info.actions.length) {
|
||||
return false;
|
||||
}
|
||||
IDydxBridge.BridgeAction memory withdraw = info.actions[depositCount];
|
||||
if (withdraw.actionType != IDydxBridge.BridgeActionType.Withdraw) {
|
||||
return false;
|
||||
}
|
||||
// And it must be for the maker token.
|
||||
if (info.dydx.getMarketTokenAddress(withdraw.marketId) != info.makerTokenAddress) {
|
||||
return false;
|
||||
}
|
||||
// Check the account index.
|
||||
return withdraw.accountIdx < info.accounts.length;
|
||||
}
|
||||
|
||||
/// @dev Returns the rate at which we withdraw maker tokens.
|
||||
/// @param info State from `_getBalanceCheckInfo()`.
|
||||
/// @return makerTokenWithdrawRate Maker token withdraw rate.
|
||||
function _getMakerTokenWithdrawRate(BalanceCheckInfo memory info)
|
||||
internal
|
||||
pure
|
||||
returns (int256 makerTokenWithdrawRate)
|
||||
{
|
||||
// The last action is always a withdraw for the maker token.
|
||||
IDydxBridge.BridgeAction memory withdraw = info.actions[info.actions.length - 1];
|
||||
return _getActionRate(withdraw);
|
||||
}
|
||||
|
||||
/// @dev Get how much maker asset we can transfer before a deposit fails.
|
||||
/// @param info State from `_getBalanceCheckInfo()`.
|
||||
function _getDepositableMakerAmount(BalanceCheckInfo memory info)
|
||||
internal
|
||||
view
|
||||
returns (uint256 depositableMakerAmount)
|
||||
{
|
||||
depositableMakerAmount = uint256(-1);
|
||||
// Take the minimum maker amount from all deposits.
|
||||
for (uint256 i = 0; i < info.actions.length; ++i) {
|
||||
IDydxBridge.BridgeAction memory action = info.actions[i];
|
||||
// Only looking at deposit actions.
|
||||
if (action.actionType != IDydxBridge.BridgeActionType.Deposit) {
|
||||
continue;
|
||||
}
|
||||
// `depositRate` is the rate at which we convert a maker token into
|
||||
// a taker token for deposit.
|
||||
int256 depositRate = _getActionRate(action);
|
||||
// Taker tokens will be transferred to the maker for every fill, so
|
||||
// we reduce the effective deposit rate if we're depositing the taker
|
||||
// token.
|
||||
address depositToken = info.dydx.getMarketTokenAddress(action.marketId);
|
||||
if (info.takerTokenAddress != address(0) && depositToken == info.takerTokenAddress) {
|
||||
depositRate = D18.sub(depositRate, info.orderMakerToTakerRate);
|
||||
}
|
||||
// If the deposit rate is > 0, we are limited by the transferrable
|
||||
// token balance of the maker.
|
||||
if (depositRate > 0) {
|
||||
uint256 supply = _getTransferabeTokenAmount(
|
||||
depositToken,
|
||||
info.makerAddress,
|
||||
address(info.dydx)
|
||||
);
|
||||
depositableMakerAmount = LibSafeMath.min256(
|
||||
depositableMakerAmount,
|
||||
uint256(D18.div(supply, depositRate))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Get how much maker asset we can transfer before an account
|
||||
/// becomes insolvent.
|
||||
/// @param info State from `_getBalanceCheckInfo()`.
|
||||
function _getSolventMakerAmount(BalanceCheckInfo memory info)
|
||||
internal
|
||||
view
|
||||
returns (uint256 solventMakerAmount)
|
||||
{
|
||||
solventMakerAmount = uint256(-1);
|
||||
assert(info.actions.length >= 1);
|
||||
IDydxBridge.BridgeAction memory withdraw = info.actions[info.actions.length - 1];
|
||||
assert(withdraw.actionType == IDydxBridge.BridgeActionType.Withdraw);
|
||||
int256 minCr = D18.add(_getMinimumCollateralizationRatio(info.dydx), MARGIN_RATIO_PADDING);
|
||||
// Loop through the accounts.
|
||||
for (uint256 accountIdx = 0; accountIdx < info.accounts.length; ++accountIdx) {
|
||||
(uint256 supplyValue, uint256 borrowValue) =
|
||||
_getAccountMarketValues(info, info.accounts[accountIdx]);
|
||||
// All accounts must currently be solvent.
|
||||
if (borrowValue != 0 && D18.div(supplyValue, borrowValue) < minCr) {
|
||||
return 0;
|
||||
}
|
||||
// If this is the same account used to in the withdraw/borrow action,
|
||||
// compute the maker amount at which it will become insolvent.
|
||||
if (accountIdx != withdraw.accountIdx) {
|
||||
continue;
|
||||
}
|
||||
// Compute the deposit/collateralization rate, which is the rate at
|
||||
// which (USD) value is added to the account across all markets.
|
||||
int256 dd = 0;
|
||||
for (uint256 i = 0; i < info.actions.length - 1; ++i) {
|
||||
IDydxBridge.BridgeAction memory deposit = info.actions[i];
|
||||
assert(deposit.actionType == IDydxBridge.BridgeActionType.Deposit);
|
||||
if (deposit.accountIdx == accountIdx) {
|
||||
dd = D18.add(
|
||||
dd,
|
||||
_getActionRateValue(
|
||||
info,
|
||||
deposit
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
// Compute the borrow/withdraw rate, which is the rate at which
|
||||
// (USD) value is deducted from the account.
|
||||
int256 db = _getActionRateValue(
|
||||
info,
|
||||
withdraw
|
||||
);
|
||||
// If the deposit to withdraw ratio is >= the minimum collateralization
|
||||
// ratio, then we will never become insolvent at these prices.
|
||||
if (D18.div(dd, db) >= minCr) {
|
||||
continue;
|
||||
}
|
||||
// If the adjusted deposit rates are equal, the account will remain
|
||||
// at the same level of collateralization.
|
||||
if (D18.mul(minCr, db) == dd) {
|
||||
continue;
|
||||
}
|
||||
// The collateralization ratio for this account, parameterized by
|
||||
// `t` (maker amount), is given by:
|
||||
// `cr = (supplyValue + t * dd) / (borrowValue + t * db)`
|
||||
// Solving for `t` gives us:
|
||||
// `t = (supplyValue - cr * borrowValue) / (cr * db - dd)`
|
||||
int256 t = D18.div(
|
||||
D18.sub(supplyValue, D18.mul(minCr, borrowValue)),
|
||||
D18.sub(D18.mul(minCr, db), dd)
|
||||
);
|
||||
solventMakerAmount = LibSafeMath.min256(
|
||||
solventMakerAmount,
|
||||
// `t` is in maker token units, so convert it to maker wei.
|
||||
_toWei(info.makerTokenAddress, uint256(D18.clip(t)))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Create a `BalanceCheckInfo` struct.
|
||||
/// @param order An order with a `DydxBridge` maker asset.
|
||||
/// @param dydx The address of the Dydx contract.
|
||||
/// @return info The `BalanceCheckInfo` struct.
|
||||
function _getBalanceCheckInfo(LibOrder.Order memory order, address dydx)
|
||||
private
|
||||
pure
|
||||
returns (BalanceCheckInfo memory info)
|
||||
{
|
||||
bytes memory rawBridgeData;
|
||||
(, info.makerTokenAddress, info.bridgeAddress, rawBridgeData) =
|
||||
LibAssetData.decodeERC20BridgeAssetData(order.makerAssetData);
|
||||
info.dydx = IDydx(dydx);
|
||||
info.makerAddress = order.makerAddress;
|
||||
if (order.takerAssetData.length == 36) {
|
||||
if (order.takerAssetData.readBytes4(0) == IAssetData(0).ERC20Token.selector) {
|
||||
(, info.takerTokenAddress) =
|
||||
LibAssetData.decodeERC20AssetData(order.takerAssetData);
|
||||
}
|
||||
}
|
||||
info.orderMakerToTakerRate = D18.div(order.takerAssetAmount, order.makerAssetAmount);
|
||||
(IDydxBridge.BridgeData memory bridgeData) =
|
||||
abi.decode(rawBridgeData, (IDydxBridge.BridgeData));
|
||||
info.accounts = bridgeData.accountNumbers;
|
||||
info.actions = bridgeData.actions;
|
||||
}
|
||||
|
||||
/// @dev Returns the conversion rate for an action.
|
||||
/// @param action A `BridgeAction`.
|
||||
function _getActionRate(IDydxBridge.BridgeAction memory action)
|
||||
private
|
||||
pure
|
||||
returns (int256 rate)
|
||||
{
|
||||
rate = action.conversionRateDenominator == 0
|
||||
? D18.one()
|
||||
: D18.div(
|
||||
action.conversionRateNumerator,
|
||||
action.conversionRateDenominator
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Returns the USD value of an action based on its conversion rate
|
||||
/// and market prices.
|
||||
/// @param info State from `_getBalanceCheckInfo()`.
|
||||
/// @param action A `BridgeAction`.
|
||||
function _getActionRateValue(
|
||||
BalanceCheckInfo memory info,
|
||||
IDydxBridge.BridgeAction memory action
|
||||
)
|
||||
private
|
||||
view
|
||||
returns (int256 value)
|
||||
{
|
||||
address toToken = info.dydx.getMarketTokenAddress(action.marketId);
|
||||
uint256 fromTokenDecimals = LibERC20Token.decimals(info.makerTokenAddress);
|
||||
uint256 toTokenDecimals = LibERC20Token.decimals(toToken);
|
||||
// First express the rate as 18-decimal units.
|
||||
value = toTokenDecimals > fromTokenDecimals
|
||||
? int256(
|
||||
uint256(_getActionRate(action))
|
||||
.safeDiv(10 ** (toTokenDecimals - fromTokenDecimals))
|
||||
)
|
||||
: int256(
|
||||
uint256(_getActionRate(action))
|
||||
.safeMul(10 ** (fromTokenDecimals - toTokenDecimals))
|
||||
);
|
||||
// Prices have 18 + (18 - TOKEN_DECIMALS) decimal places because
|
||||
// consistency is stupid.
|
||||
uint256 price = info.dydx.getMarketPrice(action.marketId).value;
|
||||
// Make prices have 18 decimals.
|
||||
if (toTokenDecimals > 18) {
|
||||
price = price.safeMul(10 ** (toTokenDecimals - 18));
|
||||
} else {
|
||||
price = price.safeDiv(10 ** (18 - toTokenDecimals));
|
||||
}
|
||||
// The action value is the action rate times the price.
|
||||
value = D18.mul(price, value);
|
||||
// Scale by the market premium.
|
||||
int256 marketPremium = D18.add(
|
||||
D18.one(),
|
||||
info.dydx.getMarketMarginPremium(action.marketId).value
|
||||
);
|
||||
if (action.actionType == IDydxBridge.BridgeActionType.Deposit) {
|
||||
value = D18.div(value, marketPremium);
|
||||
} else {
|
||||
value = D18.mul(value, marketPremium);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Convert a `D18` fraction of 1 token to the equivalent integer wei.
|
||||
/// @param token Address the of the token.
|
||||
/// @param units Token units expressed with 18 digit precision.
|
||||
function _toWei(address token, uint256 units)
|
||||
private
|
||||
view
|
||||
returns (uint256 rate)
|
||||
{
|
||||
uint256 decimals = LibERC20Token.decimals(token);
|
||||
rate = decimals > 18
|
||||
? units.safeMul(10 ** (decimals - 18))
|
||||
: units.safeDiv(10 ** (18 - decimals));
|
||||
}
|
||||
|
||||
/// @dev Get the global minimum collateralization ratio required for
|
||||
/// an account to be considered solvent.
|
||||
/// @param dydx The Dydx interface.
|
||||
function _getMinimumCollateralizationRatio(IDydx dydx)
|
||||
private
|
||||
view
|
||||
returns (int256 ratio)
|
||||
{
|
||||
IDydx.RiskParams memory riskParams = dydx.getRiskParams();
|
||||
return D18.add(D18.one(), D18.toSigned(riskParams.marginRatio.value));
|
||||
}
|
||||
|
||||
/// @dev Get the total supply and borrow values for an account across all markets.
|
||||
/// @param info State from `_getBalanceCheckInfo()`.
|
||||
/// @param account The Dydx account identifier.
|
||||
function _getAccountMarketValues(BalanceCheckInfo memory info, uint256 account)
|
||||
private
|
||||
view
|
||||
returns (uint256 supplyValue, uint256 borrowValue)
|
||||
{
|
||||
(IDydx.Value memory supplyValue_, IDydx.Value memory borrowValue_) =
|
||||
info.dydx.getAdjustedAccountValues(IDydx.AccountInfo(
|
||||
info.makerAddress,
|
||||
account
|
||||
));
|
||||
// Account values have 36 decimal places because dydx likes to make sure
|
||||
// you're paying attention.
|
||||
return (supplyValue_.value / 1e18, borrowValue_.value / 1e18);
|
||||
}
|
||||
|
||||
/// @dev Get the amount of an ERC20 token held by `owner` that can be transferred
|
||||
/// by `spender`.
|
||||
/// @param tokenAddress The address of the ERC20 token.
|
||||
/// @param owner The address of the token holder.
|
||||
/// @param spender The address of the token spender.
|
||||
function _getTransferabeTokenAmount(
|
||||
address tokenAddress,
|
||||
address owner,
|
||||
address spender
|
||||
)
|
||||
private
|
||||
view
|
||||
returns (uint256 transferableAmount)
|
||||
{
|
||||
return LibSafeMath.min256(
|
||||
LibERC20Token.allowance(tokenAddress, owner, spender),
|
||||
LibERC20Token.balanceOf(tokenAddress, owner)
|
||||
);
|
||||
}
|
||||
}
|
@@ -199,7 +199,7 @@ contract OrderValidationUtils is
|
||||
{
|
||||
(uint256 balance, uint256 allowance) = _getConvertibleMakerBalanceAndAssetProxyAllowance(order);
|
||||
transferableAssetAmount = LibSafeMath.min256(balance, allowance);
|
||||
return transferableAssetAmount;
|
||||
return LibSafeMath.min256(transferableAssetAmount, order.makerAssetAmount);
|
||||
}
|
||||
|
||||
/// @dev Checks that the asset data contained in a ZeroEx is valid and returns
|
||||
|
181
contracts/dev-utils/contracts/test/TestDydx.sol
Normal file
181
contracts/dev-utils/contracts/test/TestDydx.sol
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.16;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IDydx.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
|
||||
|
||||
|
||||
// solhint-disable separate-by-one-line-in-contract
|
||||
contract TestDydx {
|
||||
|
||||
struct OperatorConfig {
|
||||
address owner;
|
||||
address operator;
|
||||
}
|
||||
|
||||
struct AccountConfig {
|
||||
address owner;
|
||||
uint256 accountId;
|
||||
int256[] balances;
|
||||
}
|
||||
|
||||
struct MarketInfo {
|
||||
address token;
|
||||
uint256 price;
|
||||
}
|
||||
|
||||
struct TestConfig {
|
||||
uint256 marginRatio;
|
||||
OperatorConfig[] operators;
|
||||
AccountConfig[] accounts;
|
||||
MarketInfo[] markets;
|
||||
}
|
||||
|
||||
mapping (bytes32 => bool) private _operators;
|
||||
mapping (bytes32 => int256) private _balance;
|
||||
MarketInfo[] private _markets;
|
||||
uint256 private _marginRatio;
|
||||
|
||||
constructor(TestConfig memory config) public {
|
||||
_marginRatio = config.marginRatio;
|
||||
for (uint256 marketId = 0; marketId < config.markets.length; ++marketId) {
|
||||
_markets.push(config.markets[marketId]);
|
||||
}
|
||||
for (uint256 i = 0; i < config.operators.length; ++i) {
|
||||
OperatorConfig memory op = config.operators[i];
|
||||
_operators[_getOperatorHash(op.owner, op.operator)] = true;
|
||||
}
|
||||
for (uint256 i = 0; i < config.accounts.length; ++i) {
|
||||
AccountConfig memory acct = config.accounts[i];
|
||||
for (uint256 marketId = 0; marketId < acct.balances.length; ++marketId) {
|
||||
_balance[_getBalanceHash(acct.owner, acct.accountId, marketId)] =
|
||||
acct.balances[marketId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getIsLocalOperator(
|
||||
address owner,
|
||||
address operator
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (bool isLocalOperator)
|
||||
{
|
||||
return _operators[_getOperatorHash(owner, operator)];
|
||||
}
|
||||
|
||||
function getMarketTokenAddress(
|
||||
uint256 marketId
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (address tokenAddress)
|
||||
{
|
||||
return _markets[marketId].token;
|
||||
}
|
||||
|
||||
function getRiskParams()
|
||||
external
|
||||
view
|
||||
returns (IDydx.RiskParams memory riskParams)
|
||||
{
|
||||
return IDydx.RiskParams({
|
||||
marginRatio: IDydx.D256(_marginRatio),
|
||||
liquidationSpread: IDydx.D256(0),
|
||||
earningsRate: IDydx.D256(0),
|
||||
minBorrowedValue: IDydx.Value(0)
|
||||
});
|
||||
}
|
||||
|
||||
function getAdjustedAccountValues(
|
||||
IDydx.AccountInfo calldata account
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (IDydx.Value memory supplyValue, IDydx.Value memory borrowValue)
|
||||
{
|
||||
for (uint256 marketId = 0; marketId < _markets.length; ++marketId) {
|
||||
int256 balance =
|
||||
_balance[_getBalanceHash(account.owner, account.number, marketId)];
|
||||
// Account values have 36 decimal places.
|
||||
// `getMarketPrice()` returns a unit with
|
||||
// 18 + (18 - TOKEN_DECIMALS) decimal places so multiplying the price
|
||||
// with the wei balance will result in a 36 decimal value.
|
||||
balance = balance * int256(getMarketPrice(marketId).value);
|
||||
if (balance >= 0) {
|
||||
supplyValue.value += uint256(balance);
|
||||
} else {
|
||||
borrowValue.value += uint256(-balance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getMarketMarginPremium(uint256)
|
||||
external
|
||||
view
|
||||
returns (IDydx.D256 memory premium)
|
||||
{
|
||||
// Return 0.
|
||||
return premium;
|
||||
}
|
||||
|
||||
function getMarketPrice(
|
||||
uint256 marketId
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (IDydx.Price memory price)
|
||||
{
|
||||
MarketInfo memory market = _markets[marketId];
|
||||
uint256 decimals = LibERC20Token.decimals(market.token);
|
||||
price.value = _markets[marketId].price;
|
||||
// Market prices have 18 + (18 - TOKEN_DECIMALS)
|
||||
if (decimals > 18) {
|
||||
price.value /= 10 ** (decimals - 18);
|
||||
} else {
|
||||
price.value *= 10 ** (18 - decimals);
|
||||
}
|
||||
}
|
||||
|
||||
function _getOperatorHash(address owner, address operator)
|
||||
private
|
||||
pure
|
||||
returns (bytes32 operatorHash)
|
||||
{
|
||||
return keccak256(abi.encode(
|
||||
owner,
|
||||
operator
|
||||
));
|
||||
}
|
||||
|
||||
function _getBalanceHash(address owner, uint256 accountId, uint256 marketId)
|
||||
private
|
||||
pure
|
||||
returns (bytes32 balanceHash)
|
||||
{
|
||||
return keccak256(abi.encode(
|
||||
owner,
|
||||
accountId,
|
||||
marketId
|
||||
));
|
||||
}
|
||||
}
|
116
contracts/dev-utils/contracts/test/TestLibDydxBalance.sol
Normal file
116
contracts/dev-utils/contracts/test/TestLibDydxBalance.sol
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.16;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "../src/LibDydxBalance.sol";
|
||||
|
||||
|
||||
contract TestLibDydxBalanceToken {
|
||||
|
||||
uint8 public decimals;
|
||||
mapping (address => uint256) public balanceOf;
|
||||
mapping (address => mapping (address => uint256)) public allowance;
|
||||
|
||||
constructor(uint8 decimals_) public {
|
||||
decimals = decimals_;
|
||||
}
|
||||
|
||||
function setBalance(address owner, uint256 balance) external {
|
||||
balanceOf[owner] = balance;
|
||||
}
|
||||
|
||||
function setApproval(
|
||||
address owner,
|
||||
address spender,
|
||||
uint256 allowance_
|
||||
)
|
||||
external
|
||||
{
|
||||
allowance[owner][spender] = allowance_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract TestLibDydxBalance {
|
||||
|
||||
mapping (address => TestLibDydxBalanceToken) private tokens;
|
||||
|
||||
function createToken(uint8 decimals) external returns (address) {
|
||||
TestLibDydxBalanceToken token = new TestLibDydxBalanceToken(decimals);
|
||||
return address(tokens[address(token)] = token);
|
||||
}
|
||||
|
||||
function setTokenBalance(
|
||||
address tokenAddress,
|
||||
address owner,
|
||||
uint256 balance
|
||||
)
|
||||
external
|
||||
{
|
||||
tokens[tokenAddress].setBalance(owner, balance);
|
||||
}
|
||||
|
||||
function setTokenApproval(
|
||||
address tokenAddress,
|
||||
address owner,
|
||||
address spender,
|
||||
uint256 allowance
|
||||
)
|
||||
external
|
||||
{
|
||||
tokens[tokenAddress].setApproval(owner, spender, allowance);
|
||||
}
|
||||
|
||||
function getDydxMakerBalance(LibOrder.Order memory order, address dydx)
|
||||
public
|
||||
view
|
||||
returns (uint256 balance)
|
||||
{
|
||||
return LibDydxBalance.getDydxMakerBalance(order, dydx);
|
||||
}
|
||||
|
||||
function getSolventMakerAmount(
|
||||
LibDydxBalance.BalanceCheckInfo memory info
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (uint256 solventMakerAmount)
|
||||
{
|
||||
return LibDydxBalance._getSolventMakerAmount(info);
|
||||
}
|
||||
|
||||
function getDepositableMakerAmount(
|
||||
LibDydxBalance.BalanceCheckInfo memory info
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (uint256 depositableMakerAmount)
|
||||
{
|
||||
return LibDydxBalance._getDepositableMakerAmount(info);
|
||||
}
|
||||
|
||||
function areActionsWellFormed(LibDydxBalance.BalanceCheckInfo memory info)
|
||||
public
|
||||
view
|
||||
returns (bool areWellFormed)
|
||||
{
|
||||
return LibDydxBalance._areActionsWellFormed(info);
|
||||
}
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-dev-utils",
|
||||
"version": "1.1.1",
|
||||
"version": "1.3.3",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -8,7 +8,7 @@
|
||||
"main": "lib/src/index.js",
|
||||
"scripts": {
|
||||
"build": "yarn pre_build && tsc -b",
|
||||
"test": "yarn assert_deployable",
|
||||
"test": "yarn assert_deployable && yarn mocha -t 10000 -b ./lib/test/**_test.js",
|
||||
"assert_deployable": "node -e \"const bytecodeLen = (require('./generated-artifacts/DevUtils.json').compilerOutput.evm.bytecode.object.length-2)/2; assert(bytecodeLen<=0x6000,'DevUtils contract is too big to deploy, per EIP-170. '+bytecodeLen+'>'+0x6000)\"",
|
||||
"build:ci": "yarn build",
|
||||
"pre_build": "run-s compile quantify_bytecode contracts:gen generate_contract_wrappers contracts:copy",
|
||||
@@ -27,8 +27,8 @@
|
||||
"docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
|
||||
},
|
||||
"config": {
|
||||
"publicInterfaceContracts": "DevUtils,LibAssetData,LibOrderTransferSimulation,LibTransactionDecoder",
|
||||
"abis": "./test/generated-artifacts/@(Addresses|AssetBalance|DevUtils|EthBalanceChecker|ExternalFunctions|LibAssetData|LibOrderTransferSimulation|LibTransactionDecoder|OrderTransferSimulationUtils|OrderValidationUtils).json",
|
||||
"publicInterfaceContracts": "DevUtils,LibAssetData,LibDydxBalance,LibOrderTransferSimulation,LibTransactionDecoder",
|
||||
"abis": "./test/generated-artifacts/@(Addresses|AssetBalance|DevUtils|EthBalanceChecker|ExternalFunctions|LibAssetData|LibDydxBalance|LibOrderTransferSimulation|LibTransactionDecoder|OrderTransferSimulationUtils|OrderValidationUtils|TestDydx|TestLibDydxBalance).json",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
|
||||
},
|
||||
"repository": {
|
||||
@@ -41,17 +41,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/dev-utils/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/assert": "^3.0.6",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/assert": "^3.0.7",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@types/node": "*",
|
||||
"ethereum-types": "^3.1.0",
|
||||
"ethers": "~4.0.4",
|
||||
@@ -64,7 +64,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0"
|
||||
"@0x/base-contract": "^6.2.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@@ -7,11 +7,13 @@ import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as DevUtils from '../generated-artifacts/DevUtils.json';
|
||||
import * as LibAssetData from '../generated-artifacts/LibAssetData.json';
|
||||
import * as LibDydxBalance from '../generated-artifacts/LibDydxBalance.json';
|
||||
import * as LibOrderTransferSimulation from '../generated-artifacts/LibOrderTransferSimulation.json';
|
||||
import * as LibTransactionDecoder from '../generated-artifacts/LibTransactionDecoder.json';
|
||||
export const artifacts = {
|
||||
DevUtils: DevUtils as ContractArtifact,
|
||||
LibAssetData: LibAssetData as ContractArtifact,
|
||||
LibDydxBalance: LibDydxBalance as ContractArtifact,
|
||||
LibOrderTransferSimulation: LibOrderTransferSimulation as ContractArtifact,
|
||||
LibTransactionDecoder: LibTransactionDecoder as ContractArtifact,
|
||||
};
|
||||
|
@@ -5,5 +5,6 @@
|
||||
*/
|
||||
export * from '../generated-wrappers/dev_utils';
|
||||
export * from '../generated-wrappers/lib_asset_data';
|
||||
export * from '../generated-wrappers/lib_dydx_balance';
|
||||
export * from '../generated-wrappers/lib_order_transfer_simulation';
|
||||
export * from '../generated-wrappers/lib_transaction_decoder';
|
||||
|
@@ -11,10 +11,13 @@ import * as DevUtils from '../test/generated-artifacts/DevUtils.json';
|
||||
import * as EthBalanceChecker from '../test/generated-artifacts/EthBalanceChecker.json';
|
||||
import * as ExternalFunctions from '../test/generated-artifacts/ExternalFunctions.json';
|
||||
import * as LibAssetData from '../test/generated-artifacts/LibAssetData.json';
|
||||
import * as LibDydxBalance from '../test/generated-artifacts/LibDydxBalance.json';
|
||||
import * as LibOrderTransferSimulation from '../test/generated-artifacts/LibOrderTransferSimulation.json';
|
||||
import * as LibTransactionDecoder from '../test/generated-artifacts/LibTransactionDecoder.json';
|
||||
import * as OrderTransferSimulationUtils from '../test/generated-artifacts/OrderTransferSimulationUtils.json';
|
||||
import * as OrderValidationUtils from '../test/generated-artifacts/OrderValidationUtils.json';
|
||||
import * as TestDydx from '../test/generated-artifacts/TestDydx.json';
|
||||
import * as TestLibDydxBalance from '../test/generated-artifacts/TestLibDydxBalance.json';
|
||||
export const artifacts = {
|
||||
Addresses: Addresses as ContractArtifact,
|
||||
AssetBalance: AssetBalance as ContractArtifact,
|
||||
@@ -22,8 +25,11 @@ export const artifacts = {
|
||||
EthBalanceChecker: EthBalanceChecker as ContractArtifact,
|
||||
ExternalFunctions: ExternalFunctions as ContractArtifact,
|
||||
LibAssetData: LibAssetData as ContractArtifact,
|
||||
LibDydxBalance: LibDydxBalance as ContractArtifact,
|
||||
LibOrderTransferSimulation: LibOrderTransferSimulation as ContractArtifact,
|
||||
LibTransactionDecoder: LibTransactionDecoder as ContractArtifact,
|
||||
OrderTransferSimulationUtils: OrderTransferSimulationUtils as ContractArtifact,
|
||||
OrderValidationUtils: OrderValidationUtils as ContractArtifact,
|
||||
TestDydx: TestDydx as ContractArtifact,
|
||||
TestLibDydxBalance: TestLibDydxBalance as ContractArtifact,
|
||||
};
|
||||
|
1170
contracts/dev-utils/test/lib_dydx_balance_test.ts
Normal file
1170
contracts/dev-utils/test/lib_dydx_balance_test.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,10 @@ export * from '../test/generated-wrappers/dev_utils';
|
||||
export * from '../test/generated-wrappers/eth_balance_checker';
|
||||
export * from '../test/generated-wrappers/external_functions';
|
||||
export * from '../test/generated-wrappers/lib_asset_data';
|
||||
export * from '../test/generated-wrappers/lib_dydx_balance';
|
||||
export * from '../test/generated-wrappers/lib_order_transfer_simulation';
|
||||
export * from '../test/generated-wrappers/lib_transaction_decoder';
|
||||
export * from '../test/generated-wrappers/order_transfer_simulation_utils';
|
||||
export * from '../test/generated-wrappers/order_validation_utils';
|
||||
export * from '../test/generated-wrappers/test_dydx';
|
||||
export * from '../test/generated-wrappers/test_lib_dydx_balance';
|
||||
|
@@ -5,6 +5,7 @@
|
||||
"files": [
|
||||
"generated-artifacts/DevUtils.json",
|
||||
"generated-artifacts/LibAssetData.json",
|
||||
"generated-artifacts/LibDydxBalance.json",
|
||||
"generated-artifacts/LibOrderTransferSimulation.json",
|
||||
"generated-artifacts/LibTransactionDecoder.json",
|
||||
"test/generated-artifacts/Addresses.json",
|
||||
@@ -13,10 +14,13 @@
|
||||
"test/generated-artifacts/EthBalanceChecker.json",
|
||||
"test/generated-artifacts/ExternalFunctions.json",
|
||||
"test/generated-artifacts/LibAssetData.json",
|
||||
"test/generated-artifacts/LibDydxBalance.json",
|
||||
"test/generated-artifacts/LibOrderTransferSimulation.json",
|
||||
"test/generated-artifacts/LibTransactionDecoder.json",
|
||||
"test/generated-artifacts/OrderTransferSimulationUtils.json",
|
||||
"test/generated-artifacts/OrderValidationUtils.json"
|
||||
"test/generated-artifacts/OrderValidationUtils.json",
|
||||
"test/generated-artifacts/TestDydx.json",
|
||||
"test/generated-artifacts/TestLibDydxBalance.json"
|
||||
],
|
||||
"exclude": ["./deploy/solc/solc_bin"]
|
||||
}
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "2.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "2.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "2.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "2.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "2.1.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v2.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-erc1155",
|
||||
"version": "2.1.1",
|
||||
"version": "2.1.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -52,11 +52,11 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/tokens/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
@@ -80,10 +80,10 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"lodash": "^4.17.11"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -1,4 +1,45 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "1.5.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.5.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add generic liquidity provider sampling",
|
||||
"pr": 2487
|
||||
},
|
||||
{
|
||||
"note": "Use liquidity provider registry in sampler",
|
||||
"pr": 2499
|
||||
}
|
||||
],
|
||||
"timestamp": 1582837861
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "1.4.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "1.4.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "1.4.0",
|
||||
"changes": [
|
||||
|
@@ -5,6 +5,23 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v1.5.1 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.5.0 - _February 27, 2020_
|
||||
|
||||
* Add generic liquidity provider sampling (#2487)
|
||||
* Use liquidity provider registry in sampler (#2499)
|
||||
|
||||
## v1.4.2 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.1 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v1.4.0 - _February 15, 2020_
|
||||
|
||||
* Added Curve contract sampling (#2483)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -24,12 +24,15 @@ import "@0x/contracts-erc20/contracts/src/LibERC20Token.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
|
||||
import "@0x/contracts-utils/contracts/src/DeploymentConstants.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "./IDevUtils.sol";
|
||||
import "./IERC20BridgeSampler.sol";
|
||||
import "./IEth2Dai.sol";
|
||||
import "./IKyberNetwork.sol";
|
||||
import "./IUniswapExchangeQuotes.sol";
|
||||
import "./ICurve.sol";
|
||||
import "./ILiquidityProvider.sol";
|
||||
import "./ILiquidityProviderRegistry.sol";
|
||||
|
||||
|
||||
contract ERC20BridgeSampler is
|
||||
@@ -47,6 +50,8 @@ contract ERC20BridgeSampler is
|
||||
/// @dev Base gas limit for Curve calls. Some Curves have multiple tokens
|
||||
/// So a reasonable ceil is 150k per token. Biggest Curve has 4 tokens.
|
||||
uint256 constant internal CURVE_CALL_GAS = 600e3; // 600k
|
||||
/// @dev Default gas limit for liquidity provider calls.
|
||||
uint256 constant internal DEFAULT_CALL_GAS = 200e3; // 200k
|
||||
|
||||
/// @dev Call multiple public functions on this contract in a single transaction.
|
||||
/// @param callDatas ABI-encoded call data for each function call.
|
||||
@@ -431,6 +436,137 @@ contract ERC20BridgeSampler is
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Sample sell quotes from an arbitrary on-chain liquidity provider.
|
||||
/// @param registryAddress Address of the liquidity provider registry contract.
|
||||
/// @param takerToken Address of the taker token (what to sell).
|
||||
/// @param makerToken Address of the maker token (what to buy).
|
||||
/// @param takerTokenAmounts Taker token sell amount for each sample.
|
||||
/// @return makerTokenAmounts Maker amounts bought at each taker token
|
||||
/// amount.
|
||||
function sampleSellsFromLiquidityProviderRegistry(
|
||||
address registryAddress,
|
||||
address takerToken,
|
||||
address makerToken,
|
||||
uint256[] memory takerTokenAmounts
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (uint256[] memory makerTokenAmounts)
|
||||
{
|
||||
// Initialize array of maker token amounts.
|
||||
uint256 numSamples = takerTokenAmounts.length;
|
||||
makerTokenAmounts = new uint256[](numSamples);
|
||||
|
||||
// Query registry for provider address.
|
||||
address providerAddress = getLiquidityProviderFromRegistry(
|
||||
registryAddress,
|
||||
takerToken,
|
||||
makerToken
|
||||
);
|
||||
// If provider doesn't exist, return all zeros.
|
||||
if (providerAddress == address(0)) {
|
||||
return makerTokenAmounts;
|
||||
}
|
||||
|
||||
for (uint256 i = 0; i < numSamples; i++) {
|
||||
(bool didSucceed, bytes memory resultData) =
|
||||
providerAddress.staticcall.gas(DEFAULT_CALL_GAS)(
|
||||
abi.encodeWithSelector(
|
||||
ILiquidityProvider(0).getSellQuote.selector,
|
||||
takerToken,
|
||||
makerToken,
|
||||
takerTokenAmounts[i]
|
||||
));
|
||||
uint256 buyAmount = 0;
|
||||
if (didSucceed) {
|
||||
buyAmount = abi.decode(resultData, (uint256));
|
||||
} else {
|
||||
// Exit early if the amount is too high for the liquidity provider to serve
|
||||
break;
|
||||
}
|
||||
makerTokenAmounts[i] = buyAmount;
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Sample buy quotes from an arbitrary on-chain liquidity provider.
|
||||
/// @param registryAddress Address of the liquidity provider registry contract.
|
||||
/// @param takerToken Address of the taker token (what to sell).
|
||||
/// @param makerToken Address of the maker token (what to buy).
|
||||
/// @param makerTokenAmounts Maker token buy amount for each sample.
|
||||
/// @return takerTokenAmounts Taker amounts sold at each maker token
|
||||
/// amount.
|
||||
function sampleBuysFromLiquidityProviderRegistry(
|
||||
address registryAddress,
|
||||
address takerToken,
|
||||
address makerToken,
|
||||
uint256[] memory makerTokenAmounts
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (uint256[] memory takerTokenAmounts)
|
||||
{
|
||||
// Initialize array of taker token amounts.
|
||||
uint256 numSamples = makerTokenAmounts.length;
|
||||
takerTokenAmounts = new uint256[](numSamples);
|
||||
|
||||
// Query registry for provider address.
|
||||
address providerAddress = getLiquidityProviderFromRegistry(
|
||||
registryAddress,
|
||||
takerToken,
|
||||
makerToken
|
||||
);
|
||||
// If provider doesn't exist, return all zeros.
|
||||
if (providerAddress == address(0)) {
|
||||
return takerTokenAmounts;
|
||||
}
|
||||
|
||||
// Otherwise, query liquidity provider for quotes.
|
||||
for (uint256 i = 0; i < numSamples; i++) {
|
||||
(bool didSucceed, bytes memory resultData) =
|
||||
providerAddress.staticcall.gas(DEFAULT_CALL_GAS)(
|
||||
abi.encodeWithSelector(
|
||||
ILiquidityProvider(0).getBuyQuote.selector,
|
||||
takerToken,
|
||||
makerToken,
|
||||
makerTokenAmounts[i]
|
||||
));
|
||||
uint256 sellAmount = 0;
|
||||
if (didSucceed) {
|
||||
sellAmount = abi.decode(resultData, (uint256));
|
||||
} else {
|
||||
// Exit early if the amount is too high for the liquidity provider to serve
|
||||
break;
|
||||
}
|
||||
takerTokenAmounts[i] = sellAmount;
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Returns the address of a liquidity provider for the given market
|
||||
/// (takerToken, makerToken), from a registry of liquidity providers.
|
||||
/// Returns address(0) if no such provider exists in the registry.
|
||||
/// @param takerToken Taker asset managed by liquidity provider.
|
||||
/// @param makerToken Maker asset managed by liquidity provider.
|
||||
/// @return providerAddress Address of the liquidity provider.
|
||||
function getLiquidityProviderFromRegistry(
|
||||
address registryAddress,
|
||||
address takerToken,
|
||||
address makerToken
|
||||
)
|
||||
public
|
||||
view
|
||||
returns (address providerAddress)
|
||||
{
|
||||
bytes memory callData = abi.encodeWithSelector(
|
||||
ILiquidityProviderRegistry(0).getLiquidityProviderForMarket.selector,
|
||||
takerToken,
|
||||
makerToken
|
||||
);
|
||||
(bool didSucceed, bytes memory returnData) = registryAddress.staticcall(callData);
|
||||
if (didSucceed && returnData.length == 32) {
|
||||
return LibBytes.readAddress(returnData, 12);
|
||||
}
|
||||
}
|
||||
|
||||
/// @dev Overridable way to get token decimals.
|
||||
/// @param tokenAddress Address of the token.
|
||||
/// @return decimals The decimal places for the token.
|
||||
|
@@ -149,4 +149,53 @@ interface IERC20BridgeSampler {
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory makerTokenAmounts);
|
||||
|
||||
/// @dev Sample sell quotes from an arbitrary on-chain liquidity provider.
|
||||
/// @param registryAddress Address of the liquidity provider registry contract.
|
||||
/// @param takerToken Address of the taker token (what to sell).
|
||||
/// @param makerToken Address of the maker token (what to buy).
|
||||
/// @param takerTokenAmounts Taker token sell amount for each sample.
|
||||
/// @return makerTokenAmounts Maker amounts bought at each taker token
|
||||
/// amount.
|
||||
function sampleSellsFromLiquidityProviderRegistry(
|
||||
address registryAddress,
|
||||
address takerToken,
|
||||
address makerToken,
|
||||
uint256[] calldata takerTokenAmounts
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory makerTokenAmounts);
|
||||
|
||||
/// @dev Sample buy quotes from an arbitrary on-chain liquidity provider.
|
||||
/// @param registryAddress Address of the liquidity provider registry contract.
|
||||
/// @param takerToken Address of the taker token (what to sell).
|
||||
/// @param makerToken Address of the maker token (what to buy).
|
||||
/// @param makerTokenAmounts Maker token buy amount for each sample.
|
||||
/// @return takerTokenAmounts Taker amounts sold at each maker token
|
||||
/// amount.
|
||||
function sampleBuysFromLiquidityProviderRegistry(
|
||||
address registryAddress,
|
||||
address takerToken,
|
||||
address makerToken,
|
||||
uint256[] calldata makerTokenAmounts
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory takerTokenAmounts);
|
||||
|
||||
/// @dev Returns the address of a liquidity provider for the given market
|
||||
/// (takerToken, makerToken), from a registry of liquidity providers.
|
||||
/// Returns address(0) if no such provider exists in the registry.
|
||||
/// @param takerToken Taker asset managed by liquidity provider.
|
||||
/// @param makerToken Maker asset managed by liquidity provider.
|
||||
/// @return providerAddress Address of the liquidity provider.
|
||||
function getLiquidityProviderFromRegistry(
|
||||
address registryAddress,
|
||||
address takerToken,
|
||||
address makerToken
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (address providerAddress);
|
||||
}
|
||||
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
|
||||
interface ILiquidityProvider {
|
||||
|
||||
/// @dev Transfers `amount` of the ERC20 `tokenAddress` from `from` to `to`.
|
||||
/// @param tokenAddress The address of the ERC20 token to transfer.
|
||||
/// @param from Address to transfer asset from.
|
||||
/// @param to Address to transfer asset to.
|
||||
/// @param amount Amount of asset to transfer.
|
||||
/// @param bridgeData Arbitrary asset data needed by the bridge contract.
|
||||
/// @return success The magic bytes `0xdc1600f3` if successful.
|
||||
function bridgeTransferFrom(
|
||||
address tokenAddress,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount,
|
||||
bytes calldata bridgeData
|
||||
)
|
||||
external
|
||||
returns (bytes4 success);
|
||||
|
||||
/// @dev Quotes the amount of `makerToken` that would be obtained by
|
||||
/// selling `sellAmount` of `takerToken`.
|
||||
/// @param takerToken Address of the taker token (what to sell).
|
||||
/// @param makerToken Address of the maker token (what to buy).
|
||||
/// @param sellAmount Amount of `takerToken` to sell.
|
||||
/// @return makerTokenAmount Amount of `makerToken` that would be obtained.
|
||||
function getSellQuote(
|
||||
address takerToken,
|
||||
address makerToken,
|
||||
uint256 sellAmount
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256 makerTokenAmount);
|
||||
|
||||
/// @dev Quotes the amount of `takerToken` that would need to be sold in
|
||||
/// order to obtain `buyAmount` of `makerToken`.
|
||||
/// @param takerToken Address of the taker token (what to sell).
|
||||
/// @param makerToken Address of the maker token (what to buy).
|
||||
/// @param buyAmount Amount of `makerToken` to buy.
|
||||
/// @return takerTokenAmount Amount of `takerToken` that would need to be sold.
|
||||
function getBuyQuote(
|
||||
address takerToken,
|
||||
address makerToken,
|
||||
uint256 buyAmount
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (uint256 takerTokenAmount);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
|
||||
Copyright 2019 ZeroEx Intl.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.5.9;
|
||||
|
||||
|
||||
interface ILiquidityProviderRegistry {
|
||||
|
||||
/// @dev Returns the address of a liquidity provider for the given market
|
||||
/// (takerToken, makerToken), reverting if the pool does not exist.
|
||||
/// @param takerToken Taker asset managed by liquidity provider.
|
||||
/// @param makerToken Maker asset managed by liquidity provider.
|
||||
/// @return Address of the liquidity provider.
|
||||
function getLiquidityProviderForMarket(
|
||||
address takerToken,
|
||||
address makerToken
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (address providerAddress);
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-erc20-bridge-sampler",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.1",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -36,9 +36,9 @@
|
||||
"compile:truffle": "truffle compile"
|
||||
},
|
||||
"config": {
|
||||
"publicInterfaceContracts": "ERC20BridgeSampler,IERC20BridgeSampler",
|
||||
"publicInterfaceContracts": "ERC20BridgeSampler,IERC20BridgeSampler,ILiquidityProvider,ILiquidityProviderRegistry",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||
"abis": "./test/generated-artifacts/@(ERC20BridgeSampler|ICurve|IDevUtils|IERC20BridgeSampler|IEth2Dai|IKyberNetwork|IUniswapExchangeQuotes|TestERC20BridgeSampler).json"
|
||||
"abis": "./test/generated-artifacts/@(ERC20BridgeSampler|ICurve|IDevUtils|IERC20BridgeSampler|IEth2Dai|IKyberNetwork|ILiquidityProvider|ILiquidityProviderRegistry|IUniswapExchangeQuotes|TestERC20BridgeSampler).json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -50,18 +50,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/protocol/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-exchange": "^3.2.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-exchange": "^3.2.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -79,10 +79,10 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"ethereum-types": "^3.1.0",
|
||||
"lodash": "^4.17.11"
|
||||
},
|
||||
|
@@ -7,7 +7,11 @@ import { ContractArtifact } from 'ethereum-types';
|
||||
|
||||
import * as ERC20BridgeSampler from '../generated-artifacts/ERC20BridgeSampler.json';
|
||||
import * as IERC20BridgeSampler from '../generated-artifacts/IERC20BridgeSampler.json';
|
||||
import * as ILiquidityProvider from '../generated-artifacts/ILiquidityProvider.json';
|
||||
import * as ILiquidityProviderRegistry from '../generated-artifacts/ILiquidityProviderRegistry.json';
|
||||
export const artifacts = {
|
||||
ERC20BridgeSampler: ERC20BridgeSampler as ContractArtifact,
|
||||
IERC20BridgeSampler: IERC20BridgeSampler as ContractArtifact,
|
||||
ILiquidityProvider: ILiquidityProvider as ContractArtifact,
|
||||
ILiquidityProviderRegistry: ILiquidityProviderRegistry as ContractArtifact,
|
||||
};
|
||||
|
@@ -5,3 +5,5 @@
|
||||
*/
|
||||
export * from '../generated-wrappers/erc20_bridge_sampler';
|
||||
export * from '../generated-wrappers/i_erc20_bridge_sampler';
|
||||
export * from '../generated-wrappers/i_liquidity_provider';
|
||||
export * from '../generated-wrappers/i_liquidity_provider_registry';
|
||||
|
@@ -11,6 +11,8 @@ import * as IDevUtils from '../test/generated-artifacts/IDevUtils.json';
|
||||
import * as IERC20BridgeSampler from '../test/generated-artifacts/IERC20BridgeSampler.json';
|
||||
import * as IEth2Dai from '../test/generated-artifacts/IEth2Dai.json';
|
||||
import * as IKyberNetwork from '../test/generated-artifacts/IKyberNetwork.json';
|
||||
import * as ILiquidityProvider from '../test/generated-artifacts/ILiquidityProvider.json';
|
||||
import * as ILiquidityProviderRegistry from '../test/generated-artifacts/ILiquidityProviderRegistry.json';
|
||||
import * as IUniswapExchangeQuotes from '../test/generated-artifacts/IUniswapExchangeQuotes.json';
|
||||
import * as TestERC20BridgeSampler from '../test/generated-artifacts/TestERC20BridgeSampler.json';
|
||||
export const artifacts = {
|
||||
@@ -20,6 +22,8 @@ export const artifacts = {
|
||||
IERC20BridgeSampler: IERC20BridgeSampler as ContractArtifact,
|
||||
IEth2Dai: IEth2Dai as ContractArtifact,
|
||||
IKyberNetwork: IKyberNetwork as ContractArtifact,
|
||||
ILiquidityProvider: ILiquidityProvider as ContractArtifact,
|
||||
ILiquidityProviderRegistry: ILiquidityProviderRegistry as ContractArtifact,
|
||||
IUniswapExchangeQuotes: IUniswapExchangeQuotes as ContractArtifact,
|
||||
TestERC20BridgeSampler: TestERC20BridgeSampler as ContractArtifact,
|
||||
};
|
||||
|
@@ -9,5 +9,7 @@ export * from '../test/generated-wrappers/i_dev_utils';
|
||||
export * from '../test/generated-wrappers/i_erc20_bridge_sampler';
|
||||
export * from '../test/generated-wrappers/i_eth2_dai';
|
||||
export * from '../test/generated-wrappers/i_kyber_network';
|
||||
export * from '../test/generated-wrappers/i_liquidity_provider';
|
||||
export * from '../test/generated-wrappers/i_liquidity_provider_registry';
|
||||
export * from '../test/generated-wrappers/i_uniswap_exchange_quotes';
|
||||
export * from '../test/generated-wrappers/test_erc20_bridge_sampler';
|
||||
|
@@ -5,12 +5,16 @@
|
||||
"files": [
|
||||
"generated-artifacts/ERC20BridgeSampler.json",
|
||||
"generated-artifacts/IERC20BridgeSampler.json",
|
||||
"generated-artifacts/ILiquidityProvider.json",
|
||||
"generated-artifacts/ILiquidityProviderRegistry.json",
|
||||
"test/generated-artifacts/ERC20BridgeSampler.json",
|
||||
"test/generated-artifacts/ICurve.json",
|
||||
"test/generated-artifacts/IDevUtils.json",
|
||||
"test/generated-artifacts/IERC20BridgeSampler.json",
|
||||
"test/generated-artifacts/IEth2Dai.json",
|
||||
"test/generated-artifacts/IKyberNetwork.json",
|
||||
"test/generated-artifacts/ILiquidityProvider.json",
|
||||
"test/generated-artifacts/ILiquidityProviderRegistry.json",
|
||||
"test/generated-artifacts/IUniswapExchangeQuotes.json",
|
||||
"test/generated-artifacts/TestERC20BridgeSampler.json"
|
||||
],
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "3.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "3.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "3.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "3.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "3.1.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-erc20",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -51,18 +51,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/tokens/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -82,7 +82,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0"
|
||||
"@0x/base-contract": "^6.2.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "3.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "3.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "3.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "3.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "3.1.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-erc721",
|
||||
"version": "3.1.1",
|
||||
"version": "3.1.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -52,18 +52,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/tokens/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -84,7 +84,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0"
|
||||
"@0x/base-contract": "^6.2.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "4.2.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "4.2.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "4.2.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "4.2.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "4.2.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v4.2.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.2.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.2.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.2.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.2.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-exchange-forwarder",
|
||||
"version": "4.2.1",
|
||||
"version": "4.2.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -52,25 +52,25 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-dev-utils": "^1.1.1",
|
||||
"@0x/contracts-erc1155": "^2.1.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-erc721": "^3.1.1",
|
||||
"@0x/contracts-exchange": "^3.2.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-dev-utils": "^1.3.3",
|
||||
"@0x/contracts-erc1155": "^2.1.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-erc721": "^3.1.5",
|
||||
"@0x/contracts-exchange": "^3.2.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -90,7 +90,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"ethereum-types": "^3.1.0"
|
||||
},
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "4.3.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "4.3.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "4.3.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "4.3.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "4.3.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v4.3.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.3.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.3.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.3.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.3.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-exchange-libs",
|
||||
"version": "4.3.1",
|
||||
"version": "4.3.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -52,14 +52,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/libs/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/subproviders": "^6.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/subproviders": "^6.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -80,13 +80,13 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"ethereum-types": "^3.1.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "3.2.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "3.2.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "3.2.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "3.2.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "3.2.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v3.2.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v3.2.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -1,6 +1,6 @@
|
||||
## Exchange
|
||||
|
||||
This package contains the implementation of the [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange). This contract is responsible for settling trades and is typically the entry point for all transactions that interact with the 0x protocol. Lightweight examples of how external contracts can interct with the `Exchange` contract can be found in the [examples](./contracts/examples) directory. Addresses of the deployed contracts can be found in this 0x [guide](https://0x.org/docs/guides/0x-cheat-sheet) or the [DEPLOYS](./DEPLOYS.json) file within this package.
|
||||
This package contains the implementation of the [`Exchange`](https://github.com/0xProject/0x-protocol-specification/blob/master/v2/v2-specification.md#exchange). This contract is responsible for settling trades and is typically the entry point for all transactions that interact with the 0x protocol. Lightweight examples of how external contracts can interact with the `Exchange` contract can be found in the [examples](./contracts/examples) directory. Addresses of the deployed contracts can be found in this 0x [guide](https://0x.org/docs/guides/0x-cheat-sheet) or the [DEPLOYS](./DEPLOYS.json) file within this package.
|
||||
|
||||
## Installation
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-exchange",
|
||||
"version": "3.2.1",
|
||||
"version": "3.2.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -52,21 +52,21 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/protocol/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-multisig": "^4.1.1",
|
||||
"@0x/contracts-staking": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-multisig": "^4.1.5",
|
||||
"@0x/contracts-staking": "^2.0.12",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -88,13 +88,13 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/contracts-dev-utils": "^1.1.1",
|
||||
"@0x/contracts-erc1155": "^2.1.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-erc721": "^3.1.1",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/contracts-dev-utils": "^1.3.3",
|
||||
"@0x/contracts-erc1155": "^2.1.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-erc721": "^3.1.5",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"lodash": "^4.17.11"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "6.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "6.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "6.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "6.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "6.1.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v6.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v6.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v6.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v6.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v6.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-extensions",
|
||||
"version": "6.1.1",
|
||||
"version": "6.1.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -51,24 +51,24 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-dev-utils": "^1.1.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-erc721": "^3.1.1",
|
||||
"@0x/contracts-exchange": "^3.2.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-dev-utils": "^1.3.3",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-erc721": "^3.1.5",
|
||||
"@0x/contracts-exchange": "^3.2.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -90,7 +90,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"ethereum-types": "^3.1.0"
|
||||
},
|
||||
|
@@ -1,4 +1,41 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "2.5.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.5.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Add `ChaiBridge` and `DydxBridge` gas benchmark tests.",
|
||||
"pr": 2478
|
||||
}
|
||||
],
|
||||
"timestamp": 1582837861
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "2.4.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "2.4.1",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"version": "2.4.0",
|
||||
"changes": [
|
||||
@@ -31,6 +68,14 @@
|
||||
{
|
||||
"note": "Update tests for refactored `DevUtils`",
|
||||
"pr": 2464
|
||||
},
|
||||
{
|
||||
"note": "Add DydxBridge validation",
|
||||
"pr": 2466
|
||||
},
|
||||
{
|
||||
"note": "Add DevUtils DydxBridge validation mainnet tests",
|
||||
"pr": 2466
|
||||
}
|
||||
],
|
||||
"timestamp": 1581204851
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v2.5.1 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.5.0 - _February 27, 2020_
|
||||
|
||||
* Add `ChaiBridge` and `DydxBridge` gas benchmark tests. (#2478)
|
||||
|
||||
## v2.4.2 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.4.1 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v2.4.0 - _February 15, 2020_
|
||||
|
||||
* Added ChainlinkStopLimit contract and tests (#2473)
|
||||
@@ -16,6 +32,8 @@ CHANGELOG
|
||||
|
||||
* Remove dependency on `DevUtils` for asset data encoding/decoding (#2462)
|
||||
* Update tests for refactored `DevUtils` (#2464)
|
||||
* Add DydxBridge validation (#2466)
|
||||
* Add DevUtils DydxBridge validation mainnet tests (#2466)
|
||||
|
||||
## v2.2.3 - _February 6, 2020_
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-integrations",
|
||||
"version": "2.4.0",
|
||||
"version": "2.5.1",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -51,25 +51,25 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/extensions/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contract-addresses": "^4.6.0",
|
||||
"@0x/contract-wrappers": "^13.6.0",
|
||||
"@0x/contracts-broker": "^1.1.0",
|
||||
"@0x/contracts-coordinator": "^3.1.1",
|
||||
"@0x/contracts-dev-utils": "^1.1.1",
|
||||
"@0x/contracts-erc20-bridge-sampler": "^1.4.0",
|
||||
"@0x/contracts-exchange-forwarder": "^4.2.1",
|
||||
"@0x/contracts-exchange-libs": "^4.3.1",
|
||||
"@0x/contracts-extensions": "^6.1.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contract-addresses": "^4.9.0",
|
||||
"@0x/contract-wrappers": "^13.6.3",
|
||||
"@0x/contracts-broker": "^1.1.4",
|
||||
"@0x/contracts-coordinator": "^3.1.5",
|
||||
"@0x/contracts-dev-utils": "^1.3.3",
|
||||
"@0x/contracts-erc20-bridge-sampler": "^1.5.1",
|
||||
"@0x/contracts-exchange-forwarder": "^4.2.5",
|
||||
"@0x/contracts-exchange-libs": "^4.3.5",
|
||||
"@0x/contracts-extensions": "^6.1.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/coordinator-server": "^1.0.5",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/migrations": "^6.2.0",
|
||||
"@0x/order-utils": "^10.2.1",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/migrations": "^6.2.4",
|
||||
"@0x/order-utils": "^10.2.4",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@azure/core-asynciterator-polyfill": "^1.0.0",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
@@ -92,19 +92,19 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/asset-swapper": "^4.2.0",
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-erc1155": "^2.1.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-erc721": "^3.1.1",
|
||||
"@0x/contracts-exchange": "^3.2.1",
|
||||
"@0x/contracts-multisig": "^4.1.1",
|
||||
"@0x/contracts-staking": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/asset-swapper": "^4.4.0",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-erc1155": "^2.1.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-erc721": "^3.1.5",
|
||||
"@0x/contracts-exchange": "^3.2.5",
|
||||
"@0x/contracts-multisig": "^4.1.5",
|
||||
"@0x/contracts-staking": "^2.0.12",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"ethereum-types": "^3.1.0",
|
||||
"ethereumjs-util": "^6.2.0",
|
||||
"lodash": "^4.17.11"
|
||||
|
199
contracts/integrations/test/benchmarks/chai_bridge_test.ts
Normal file
199
contracts/integrations/test/benchmarks/chai_bridge_test.ts
Normal file
@@ -0,0 +1,199 @@
|
||||
import { encodeERC20AssetData, encodeERC20BridgeAssetData } from '@0x/contracts-asset-proxy';
|
||||
import { ERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import { ExchangeContract } from '@0x/contracts-exchange';
|
||||
import { blockchainTests, constants, expect, FillEventArgs, getRandomInteger } from '@0x/contracts-test-utils';
|
||||
import { orderHashUtils } from '@0x/order-utils';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber, logUtils } from '@0x/utils';
|
||||
import { DecodedLogEntry } from 'ethereum-types';
|
||||
|
||||
import { contractAddresses } from '../mainnet_fork_utils';
|
||||
|
||||
const CHONKY_DAI_WALLET = '0xe235AAa27428E32cA14089b03F532c571C7ab3c8';
|
||||
const CHONKY_CHAI_WALLET = '0xfc64382c9ce89ba1c21692a68000366a35ff0336';
|
||||
const CHONKY_WETH_WALLET = '0x4abB24590606f5bf4645185e20C4E7B97596cA3B';
|
||||
blockchainTests.configure({
|
||||
fork: {
|
||||
unlockedAccounts: [CHONKY_CHAI_WALLET, CHONKY_WETH_WALLET, CHONKY_DAI_WALLET],
|
||||
},
|
||||
});
|
||||
|
||||
blockchainTests.fork.skip('ChaiBridge fill benchmarks', env => {
|
||||
let exchange: ExchangeContract;
|
||||
|
||||
before(async () => {
|
||||
exchange = new ExchangeContract(contractAddresses.exchange, env.provider, env.txDefaults);
|
||||
});
|
||||
|
||||
const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
|
||||
const CHAI_ADDRESS = '0x06AF07097C9Eeb7fD685c692751D5C66dB49c215';
|
||||
const CHAI_BRIDGE_ASSET_DATA = encodeERC20BridgeAssetData(
|
||||
DAI_ADDRESS,
|
||||
contractAddresses.chaiBridge,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const DAI_ASSET_DATA = encodeERC20AssetData(DAI_ADDRESS);
|
||||
const WETH_ASSET_DATA = encodeERC20AssetData(contractAddresses.etherToken);
|
||||
const SIGNATURE_PRESIGN = '0x06';
|
||||
const PROTOCOL_FEE = 150e3;
|
||||
const ONE_DAY = 60 * 60 * 24;
|
||||
const ORDER_DEFAULTS: Order = {
|
||||
chainId: 1,
|
||||
exchangeAddress: contractAddresses.exchange,
|
||||
expirationTimeSeconds: new BigNumber(Math.floor(Date.now() / 1e3) + ONE_DAY),
|
||||
salt: getRandomInteger(0, constants.MAX_UINT256),
|
||||
makerAddress: CHONKY_CHAI_WALLET,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
makerAssetAmount: new BigNumber(1e18),
|
||||
takerAssetAmount: new BigNumber(1e18),
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
makerAssetData: CHAI_BRIDGE_ASSET_DATA,
|
||||
takerAssetData: WETH_ASSET_DATA,
|
||||
makerFeeAssetData: constants.NULL_BYTES,
|
||||
takerFeeAssetData: constants.NULL_BYTES,
|
||||
};
|
||||
|
||||
async function approveSpenderAsync(
|
||||
ownerAddress: string,
|
||||
spenderAddress: string,
|
||||
tokenAddress: string,
|
||||
): Promise<void> {
|
||||
const token = new ERC20TokenContract(tokenAddress, env.provider, env.txDefaults);
|
||||
await token.approve(spenderAddress, constants.MAX_UINT256).awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: ownerAddress,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
}
|
||||
|
||||
describe('chai gas usage', () => {
|
||||
before(async () => {
|
||||
await approveSpenderAsync(CHONKY_CHAI_WALLET, contractAddresses.chaiBridge, CHAI_ADDRESS);
|
||||
await approveSpenderAsync(CHONKY_WETH_WALLET, contractAddresses.erc20Proxy, contractAddresses.etherToken);
|
||||
});
|
||||
|
||||
async function prepareOrderAsync(fields: Partial<Order> = {}): Promise<Order> {
|
||||
const order = {
|
||||
...ORDER_DEFAULTS,
|
||||
...fields,
|
||||
};
|
||||
const orderHash = orderHashUtils.getOrderHash(order);
|
||||
await exchange.preSign(orderHash).awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: order.makerAddress,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
return order;
|
||||
}
|
||||
|
||||
// Last run: 282194
|
||||
it('filling one chai maker asset', async () => {
|
||||
const order = await prepareOrderAsync();
|
||||
const receipt = await exchange
|
||||
.fillOrder(order, order.takerAssetAmount, SIGNATURE_PRESIGN)
|
||||
.awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: CHONKY_WETH_WALLET,
|
||||
value: PROTOCOL_FEE,
|
||||
gasPrice: 1,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
const fillEvent = (receipt.logs as Array<DecodedLogEntry<FillEventArgs>>).find(log => log.event === 'Fill');
|
||||
expect(fillEvent).to.exist('');
|
||||
logUtils.log(`gas used: ${receipt.gasUsed}`);
|
||||
});
|
||||
|
||||
// Last run: 292707
|
||||
it('filling one chai taker asset', async () => {
|
||||
const order = await prepareOrderAsync({
|
||||
makerAddress: CHONKY_WETH_WALLET,
|
||||
takerAssetData: CHAI_BRIDGE_ASSET_DATA,
|
||||
makerAssetData: WETH_ASSET_DATA,
|
||||
});
|
||||
const receipt = await exchange
|
||||
.fillOrder(order, order.takerAssetAmount, SIGNATURE_PRESIGN)
|
||||
.awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: CHONKY_CHAI_WALLET,
|
||||
value: PROTOCOL_FEE,
|
||||
gasPrice: 1,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
const fillEvent = (receipt.logs as Array<DecodedLogEntry<FillEventArgs>>).find(log => log.event === 'Fill');
|
||||
expect(fillEvent).to.exist('');
|
||||
logUtils.log(`gas used: ${receipt.gasUsed}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dai gas usage', () => {
|
||||
before(async () => {
|
||||
await approveSpenderAsync(CHONKY_DAI_WALLET, contractAddresses.erc20Proxy, DAI_ADDRESS);
|
||||
await approveSpenderAsync(CHONKY_WETH_WALLET, contractAddresses.erc20Proxy, contractAddresses.etherToken);
|
||||
});
|
||||
|
||||
async function prepareOrderAsync(fields: Partial<Order> = {}): Promise<Order> {
|
||||
const order = {
|
||||
...ORDER_DEFAULTS,
|
||||
...fields,
|
||||
};
|
||||
const orderHash = orderHashUtils.getOrderHash(order);
|
||||
await exchange.preSign(orderHash).awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: order.makerAddress,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
return order;
|
||||
}
|
||||
|
||||
// Last run: 124665
|
||||
it('filling one dai maker asset', async () => {
|
||||
const order = await prepareOrderAsync({
|
||||
makerAddress: CHONKY_DAI_WALLET,
|
||||
makerAssetData: DAI_ASSET_DATA,
|
||||
});
|
||||
const receipt = await exchange
|
||||
.fillOrder(order, order.takerAssetAmount, SIGNATURE_PRESIGN)
|
||||
.awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: CHONKY_WETH_WALLET,
|
||||
value: PROTOCOL_FEE,
|
||||
gasPrice: 1,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
const fillEvent = (receipt.logs as Array<DecodedLogEntry<FillEventArgs>>).find(log => log.event === 'Fill');
|
||||
expect(fillEvent).to.exist('');
|
||||
logUtils.log(`gas used: ${receipt.gasUsed}`);
|
||||
});
|
||||
|
||||
// Last run: 124665
|
||||
it('filling one dai taker asset', async () => {
|
||||
const order = await prepareOrderAsync({
|
||||
makerAddress: CHONKY_WETH_WALLET,
|
||||
takerAssetData: DAI_ASSET_DATA,
|
||||
makerAssetData: WETH_ASSET_DATA,
|
||||
});
|
||||
const receipt = await exchange
|
||||
.fillOrder(order, order.takerAssetAmount, SIGNATURE_PRESIGN)
|
||||
.awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: CHONKY_DAI_WALLET,
|
||||
value: PROTOCOL_FEE,
|
||||
gasPrice: 1,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
const fillEvent = (receipt.logs as Array<DecodedLogEntry<FillEventArgs>>).find(log => log.event === 'Fill');
|
||||
expect(fillEvent).to.exist('');
|
||||
logUtils.log(`gas used: ${receipt.gasUsed}`);
|
||||
});
|
||||
});
|
||||
});
|
267
contracts/integrations/test/benchmarks/dydx_bridge_test.ts
Normal file
267
contracts/integrations/test/benchmarks/dydx_bridge_test.ts
Normal file
@@ -0,0 +1,267 @@
|
||||
import {
|
||||
DydxBridgeActionType,
|
||||
DydxBridgeData,
|
||||
dydxBridgeDataEncoder,
|
||||
encodeERC20AssetData,
|
||||
encodeERC20BridgeAssetData,
|
||||
IDydxContract,
|
||||
} from '@0x/contracts-asset-proxy';
|
||||
import { ERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import { ExchangeContract } from '@0x/contracts-exchange';
|
||||
import {
|
||||
blockchainTests,
|
||||
constants,
|
||||
expect,
|
||||
FillEventArgs,
|
||||
getRandomInteger,
|
||||
Numberish,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { orderHashUtils } from '@0x/order-utils';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber, fromTokenUnitAmount, logUtils } from '@0x/utils';
|
||||
import { DecodedLogEntry } from 'ethereum-types';
|
||||
|
||||
import { contractAddresses } from '../mainnet_fork_utils';
|
||||
|
||||
// A chonky dai wallet.
|
||||
const MAKER_ADDRESS = '0xe235AAa27428E32cA14089b03F532c571C7ab3c8';
|
||||
// Also a chonky dai wallet.
|
||||
const TAKER_ADDRESS = '0x66c57bf505a85a74609d2c83e94aabb26d691e1f';
|
||||
blockchainTests.configure({
|
||||
fork: {
|
||||
unlockedAccounts: [TAKER_ADDRESS, MAKER_ADDRESS],
|
||||
},
|
||||
});
|
||||
|
||||
blockchainTests.fork.skip('DydxBridge fill benchmarks', env => {
|
||||
let exchange: ExchangeContract;
|
||||
let dydx: IDydxContract;
|
||||
|
||||
before(async () => {
|
||||
exchange = new ExchangeContract(contractAddresses.exchange, env.provider, env.txDefaults);
|
||||
dydx = new IDydxContract(DYDX_ADDRESS, env.provider, env.txDefaults);
|
||||
// Initialize a dydx account with some Dai collateral and USDC borrowed.
|
||||
await approveSpenderAsync(MAKER_ADDRESS, BRIDGE_ADDRESS, DAI_ADDRESS);
|
||||
await approveSpenderAsync(MAKER_ADDRESS, DYDX_ADDRESS, DAI_ADDRESS);
|
||||
await dydx
|
||||
.setOperators([{ operator: BRIDGE_ADDRESS, trusted: true }])
|
||||
.awaitTransactionSuccessAsync({ from: MAKER_ADDRESS }, { shouldValidate: false });
|
||||
await depositAndWithdrawAsync(100, 1);
|
||||
});
|
||||
|
||||
async function approveSpenderAsync(
|
||||
ownerAddress: string,
|
||||
spenderAddress: string,
|
||||
tokenAddress: string,
|
||||
): Promise<void> {
|
||||
const token = new ERC20TokenContract(tokenAddress, env.provider, env.txDefaults);
|
||||
await token.approve(spenderAddress, constants.MAX_UINT256).awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: ownerAddress,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
}
|
||||
|
||||
const ZERO = constants.ZERO_AMOUNT;
|
||||
const BRIDGE_ADDRESS = contractAddresses.dydxBridge;
|
||||
const DYDX_ACCOUNT_ID = getRandomInteger(0, constants.MAX_UINT256);
|
||||
const DYDX_ADDRESS = '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e';
|
||||
const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
|
||||
const USDC_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
|
||||
const TOKEN_INFO: { [addr: string]: { decimals: number; marketId: number } } = {
|
||||
[DAI_ADDRESS]: {
|
||||
decimals: 18,
|
||||
marketId: 3,
|
||||
},
|
||||
[USDC_ADDRESS]: {
|
||||
decimals: 6,
|
||||
marketId: 2,
|
||||
},
|
||||
};
|
||||
|
||||
function encodeDydxBridgeAssetData(fromToken: string, toToken: string, depositRate: number = 1): string {
|
||||
const fromTokenMarketId = new BigNumber(TOKEN_INFO[fromToken].marketId);
|
||||
const toTokenMarketId = new BigNumber(TOKEN_INFO[toToken].marketId);
|
||||
const bridgeData: DydxBridgeData = {
|
||||
accountNumbers: [DYDX_ACCOUNT_ID],
|
||||
actions: [
|
||||
...(depositRate > 0
|
||||
? [
|
||||
{
|
||||
actionType: DydxBridgeActionType.Deposit,
|
||||
accountIdx: ZERO,
|
||||
marketId: fromTokenMarketId,
|
||||
...createConversionFraction(toToken, fromToken, depositRate),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
actionType: DydxBridgeActionType.Withdraw,
|
||||
accountIdx: ZERO,
|
||||
marketId: toTokenMarketId,
|
||||
...createConversionFraction(toToken, toToken, 1),
|
||||
},
|
||||
],
|
||||
};
|
||||
return encodeERC20BridgeAssetData(
|
||||
toToken,
|
||||
contractAddresses.dydxBridge,
|
||||
dydxBridgeDataEncoder.encode({ bridgeData }),
|
||||
);
|
||||
}
|
||||
|
||||
// Create fraction with default 18 decimal precision.
|
||||
function createConversionFraction(
|
||||
fromToken: string,
|
||||
toToken: string,
|
||||
rate: number,
|
||||
): {
|
||||
conversionRateNumerator: BigNumber;
|
||||
conversionRateDenominator: BigNumber;
|
||||
} {
|
||||
const fromDecimals = TOKEN_INFO[fromToken].decimals;
|
||||
const toDecimals = TOKEN_INFO[toToken].decimals;
|
||||
return {
|
||||
conversionRateNumerator: fromTokenUnitAmount(rate, toDecimals),
|
||||
conversionRateDenominator: fromTokenUnitAmount(1, fromDecimals),
|
||||
};
|
||||
}
|
||||
|
||||
enum DydxActionType {
|
||||
Deposit = 0,
|
||||
Withdraw = 1,
|
||||
}
|
||||
|
||||
enum DydxAssetDenomination {
|
||||
Wei = 0,
|
||||
Par = 1,
|
||||
}
|
||||
|
||||
enum DydxAssetReference {
|
||||
Delta = 0,
|
||||
Target = 1,
|
||||
}
|
||||
|
||||
async function depositAndWithdrawAsync(depositSize: Numberish, withdrawSize: Numberish): Promise<void> {
|
||||
const dai = TOKEN_INFO[DAI_ADDRESS];
|
||||
const usdc = TOKEN_INFO[USDC_ADDRESS];
|
||||
await dydx
|
||||
.operate(
|
||||
[{ owner: MAKER_ADDRESS, number: DYDX_ACCOUNT_ID }],
|
||||
[
|
||||
{
|
||||
actionType: DydxActionType.Deposit,
|
||||
accountIdx: ZERO,
|
||||
amount: {
|
||||
sign: true,
|
||||
denomination: DydxAssetDenomination.Wei,
|
||||
ref: DydxAssetReference.Delta,
|
||||
value: fromTokenUnitAmount(depositSize, dai.decimals),
|
||||
},
|
||||
primaryMarketId: new BigNumber(dai.marketId),
|
||||
secondaryMarketId: new BigNumber(constants.NULL_ADDRESS),
|
||||
otherAddress: MAKER_ADDRESS,
|
||||
otherAccountIdx: ZERO,
|
||||
data: constants.NULL_BYTES,
|
||||
},
|
||||
{
|
||||
actionType: DydxActionType.Withdraw,
|
||||
accountIdx: ZERO,
|
||||
amount: {
|
||||
sign: false,
|
||||
denomination: DydxAssetDenomination.Wei,
|
||||
ref: DydxAssetReference.Delta,
|
||||
value: fromTokenUnitAmount(withdrawSize, usdc.decimals),
|
||||
},
|
||||
primaryMarketId: new BigNumber(usdc.marketId),
|
||||
secondaryMarketId: new BigNumber(constants.NULL_ADDRESS),
|
||||
otherAddress: MAKER_ADDRESS,
|
||||
otherAccountIdx: ZERO,
|
||||
data: constants.NULL_BYTES,
|
||||
},
|
||||
],
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from: MAKER_ADDRESS }, { shouldValidate: false });
|
||||
}
|
||||
|
||||
const DYDX_ASSET_DATA = encodeDydxBridgeAssetData(DAI_ADDRESS, USDC_ADDRESS);
|
||||
const DAI_ASSET_DATA = encodeERC20AssetData(DAI_ADDRESS);
|
||||
const SIGNATURE_PRESIGN = '0x06';
|
||||
const PROTOCOL_FEE = 150e3;
|
||||
const ONE_DAY = 60 * 60 * 24;
|
||||
const ORDER_DEFAULTS: Order = {
|
||||
chainId: 1,
|
||||
exchangeAddress: contractAddresses.exchange,
|
||||
expirationTimeSeconds: new BigNumber(Math.floor(Date.now() / 1e3) + ONE_DAY),
|
||||
salt: getRandomInteger(0, constants.MAX_UINT256),
|
||||
makerAddress: MAKER_ADDRESS,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
makerAssetAmount: fromTokenUnitAmount(50, TOKEN_INFO[USDC_ADDRESS].decimals),
|
||||
takerAssetAmount: fromTokenUnitAmount(100, TOKEN_INFO[USDC_ADDRESS].decimals),
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
makerAssetData: DYDX_ASSET_DATA,
|
||||
takerAssetData: DAI_ASSET_DATA,
|
||||
makerFeeAssetData: constants.NULL_BYTES,
|
||||
takerFeeAssetData: constants.NULL_BYTES,
|
||||
};
|
||||
|
||||
describe('gas usage', () => {
|
||||
async function prepareOrderAsync(fields: Partial<Order> = {}): Promise<Order> {
|
||||
const order = {
|
||||
...ORDER_DEFAULTS,
|
||||
...fields,
|
||||
};
|
||||
const orderHash = orderHashUtils.getOrderHash(order);
|
||||
await exchange.preSign(orderHash).awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: order.makerAddress,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
await approveSpenderAsync(TAKER_ADDRESS, contractAddresses.erc20Proxy, DAI_ADDRESS);
|
||||
return order;
|
||||
}
|
||||
|
||||
// Last run: 375066
|
||||
it('filling a DAI->USDC dydx order with a deposit action', async () => {
|
||||
const order = await prepareOrderAsync();
|
||||
const receipt = await exchange
|
||||
.fillOrder(order, order.takerAssetAmount, SIGNATURE_PRESIGN)
|
||||
.awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: TAKER_ADDRESS,
|
||||
value: PROTOCOL_FEE,
|
||||
gasPrice: 1,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
const fillEvent = (receipt.logs as Array<DecodedLogEntry<FillEventArgs>>).find(log => log.event === 'Fill');
|
||||
expect(fillEvent).to.exist('');
|
||||
logUtils.log(`gas used: ${receipt.gasUsed}`);
|
||||
});
|
||||
|
||||
// Last run: 315896
|
||||
it('filling a DAI->USDC dydx order with no deposit action', async () => {
|
||||
const order = await prepareOrderAsync({
|
||||
makerAssetData: encodeDydxBridgeAssetData(DAI_ADDRESS, USDC_ADDRESS, 0),
|
||||
});
|
||||
const receipt = await exchange
|
||||
.fillOrder(order, order.takerAssetAmount, SIGNATURE_PRESIGN)
|
||||
.awaitTransactionSuccessAsync(
|
||||
{
|
||||
from: TAKER_ADDRESS,
|
||||
value: PROTOCOL_FEE,
|
||||
gasPrice: 1,
|
||||
},
|
||||
{ shouldValidate: false },
|
||||
);
|
||||
const fillEvent = (receipt.logs as Array<DecodedLogEntry<FillEventArgs>>).find(log => log.event === 'Fill');
|
||||
expect(fillEvent).to.exist('');
|
||||
logUtils.log(`gas used: ${receipt.gasUsed}`);
|
||||
});
|
||||
});
|
||||
});
|
@@ -23,14 +23,14 @@ blockchainTests.fork.resets('Mainnet dydx bridge tests', env => {
|
||||
const defaultAmount = toBaseUnitAmount(0.01);
|
||||
const defaultDepositAction = {
|
||||
actionType: DydxBridgeActionType.Deposit as number,
|
||||
accountId: constants.ZERO_AMOUNT,
|
||||
accountIdx: constants.ZERO_AMOUNT,
|
||||
marketId: daiMarketId,
|
||||
conversionRateNumerator: constants.ZERO_AMOUNT,
|
||||
conversionRateDenominator: constants.ZERO_AMOUNT,
|
||||
};
|
||||
const defaultWithdrawAction = {
|
||||
actionType: DydxBridgeActionType.Withdraw as number,
|
||||
accountId: constants.ZERO_AMOUNT,
|
||||
accountIdx: constants.ZERO_AMOUNT,
|
||||
marketId: daiMarketId,
|
||||
// This ratio must be less than the `1` to account
|
||||
// for interest in dydx balances because the test
|
||||
@@ -71,7 +71,7 @@ blockchainTests.fork.resets('Mainnet dydx bridge tests', env => {
|
||||
case DydxBridgeActionType.Deposit:
|
||||
expectedDepositEvents.push({
|
||||
accountOwner: dydxAccountOwner,
|
||||
accountNumber: bridgeData.accountNumbers[action.accountId.toNumber()],
|
||||
accountNumber: bridgeData.accountNumbers[action.accountIdx.toNumber()],
|
||||
market: action.marketId,
|
||||
update: { deltaWei: { sign: true, value: scaledAmount } },
|
||||
from: dydxAccountOwner,
|
||||
@@ -81,7 +81,7 @@ blockchainTests.fork.resets('Mainnet dydx bridge tests', env => {
|
||||
case DydxBridgeActionType.Withdraw:
|
||||
expectedWithdrawEvents.push({
|
||||
accountOwner: dydxAccountOwner,
|
||||
accountNumber: bridgeData.accountNumbers[action.accountId.toNumber()],
|
||||
accountNumber: bridgeData.accountNumbers[action.accountIdx.toNumber()],
|
||||
market: action.marketId,
|
||||
update: { deltaWei: { sign: false, value: scaledAmount } },
|
||||
to: receiver,
|
||||
|
@@ -34,6 +34,7 @@ blockchainTests.fork.resets('DevUtils mainnet tests', env => {
|
||||
devUtilsArtifacts,
|
||||
contractAddresses.exchange,
|
||||
contractAddresses.chaiBridge,
|
||||
contractAddresses.dydxBridge,
|
||||
);
|
||||
await dai.approve(chai.address, constants.MAX_UINT256).awaitTransactionSuccessAsync({ from: daiHolder });
|
||||
await chai.join(daiHolder, daiDepositAmount).awaitTransactionSuccessAsync({ from: daiHolder });
|
||||
|
@@ -0,0 +1,454 @@
|
||||
import {
|
||||
artifacts as assetProxyArtifacts,
|
||||
DydxBridgeActionType,
|
||||
DydxBridgeContract,
|
||||
DydxBridgeData,
|
||||
dydxBridgeDataEncoder,
|
||||
encodeERC20AssetData,
|
||||
encodeERC20BridgeAssetData,
|
||||
IDydxContract,
|
||||
} from '@0x/contracts-asset-proxy';
|
||||
import { artifacts as devUtilsArtifacts, DevUtilsContract } from '@0x/contracts-dev-utils';
|
||||
import { ERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import { blockchainTests, constants, expect, Numberish } from '@0x/contracts-test-utils';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber, fromTokenUnitAmount, hexUtils, toTokenUnitAmount } from '@0x/utils';
|
||||
|
||||
import { contractAddresses } from '../mainnet_fork_utils';
|
||||
|
||||
enum DydxActionType {
|
||||
Deposit = 0,
|
||||
Withdraw = 1,
|
||||
}
|
||||
|
||||
enum DydxAssetDenomination {
|
||||
Wei = 0,
|
||||
Par = 1,
|
||||
}
|
||||
|
||||
enum DydxAssetReference {
|
||||
Delta = 0,
|
||||
Target = 1,
|
||||
}
|
||||
|
||||
const CHONKY_DAI_WALLET = '0x3a9F7C8cA36C42d7035E87C3304eE5cBd353a532';
|
||||
const CHONKY_USDC_WALLET = '0x1EDA7056fF11C9817038E0020C3a6F1d6A8Ec32e';
|
||||
|
||||
blockchainTests.configure({
|
||||
fork: {
|
||||
unlockedAccounts: [CHONKY_DAI_WALLET, CHONKY_USDC_WALLET],
|
||||
},
|
||||
});
|
||||
|
||||
blockchainTests.fork('DevUtils dydx order validation tests', env => {
|
||||
const { ZERO_AMOUNT: ZERO } = constants;
|
||||
const SIGNATURE = '0x01'; // Invalid signature. Doesn't matter.
|
||||
const DAI_ADDRESS = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
|
||||
const USDC_ADDRESS = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
|
||||
const DYDX_ADDRESS = '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e';
|
||||
const TOKEN_INFO: { [addr: string]: { decimals: number; marketId: number } } = {
|
||||
[DAI_ADDRESS]: {
|
||||
decimals: 18,
|
||||
marketId: 3,
|
||||
},
|
||||
[USDC_ADDRESS]: {
|
||||
decimals: 6,
|
||||
marketId: 2,
|
||||
},
|
||||
};
|
||||
const DAI_DECIMALS = TOKEN_INFO[DAI_ADDRESS].decimals;
|
||||
const USDC_DECIMALS = TOKEN_INFO[USDC_ADDRESS].decimals;
|
||||
let bridge: DydxBridgeContract;
|
||||
let dydx: IDydxContract;
|
||||
let dai: ERC20TokenContract;
|
||||
let usdc: ERC20TokenContract;
|
||||
let devUtils: DevUtilsContract;
|
||||
let accountOwner: string;
|
||||
let minMarginRatio: number;
|
||||
|
||||
before(async () => {
|
||||
[accountOwner] = await env.getAccountAddressesAsync();
|
||||
dydx = new IDydxContract(DYDX_ADDRESS, env.provider, env.txDefaults);
|
||||
dai = new ERC20TokenContract(DAI_ADDRESS, env.provider, env.txDefaults);
|
||||
usdc = new ERC20TokenContract(USDC_ADDRESS, env.provider, env.txDefaults);
|
||||
bridge = await DydxBridgeContract.deployFrom0xArtifactAsync(
|
||||
assetProxyArtifacts.DydxBridge,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
{},
|
||||
);
|
||||
devUtils = await DevUtilsContract.deployWithLibrariesFrom0xArtifactAsync(
|
||||
devUtilsArtifacts.DevUtils,
|
||||
devUtilsArtifacts,
|
||||
env.provider,
|
||||
env.txDefaults,
|
||||
devUtilsArtifacts,
|
||||
contractAddresses.exchange,
|
||||
contractAddresses.chaiBridge,
|
||||
bridge.address,
|
||||
);
|
||||
minMarginRatio = toTokenUnitAmount((await dydx.getRiskParams().callAsync()).marginRatio.value)
|
||||
.plus(1)
|
||||
.toNumber();
|
||||
// Set approvals and operators.
|
||||
await dai
|
||||
.approve(DYDX_ADDRESS, constants.MAX_UINT256)
|
||||
.awaitTransactionSuccessAsync({ from: CHONKY_DAI_WALLET });
|
||||
await usdc
|
||||
.approve(DYDX_ADDRESS, constants.MAX_UINT256)
|
||||
.awaitTransactionSuccessAsync({ from: CHONKY_USDC_WALLET });
|
||||
await dydx
|
||||
.setOperators([{ operator: bridge.address, trusted: true }])
|
||||
.awaitTransactionSuccessAsync({ from: CHONKY_DAI_WALLET });
|
||||
await dydx
|
||||
.setOperators([{ operator: bridge.address, trusted: true }])
|
||||
.awaitTransactionSuccessAsync({ from: CHONKY_USDC_WALLET });
|
||||
});
|
||||
|
||||
async function depositAndWithdrawAsync(
|
||||
makerAddress: string,
|
||||
accountId: BigNumber,
|
||||
depositSize: Numberish = 0,
|
||||
withdrawSize: Numberish = 0,
|
||||
): Promise<void> {
|
||||
const fromToken = makerAddress === CHONKY_DAI_WALLET ? DAI_ADDRESS : USDC_ADDRESS;
|
||||
const toToken = fromToken === DAI_ADDRESS ? USDC_ADDRESS : DAI_ADDRESS;
|
||||
const fromDecimals = TOKEN_INFO[fromToken].decimals;
|
||||
const fromMarketId = TOKEN_INFO[fromToken].marketId;
|
||||
const toDecimals = TOKEN_INFO[toToken].decimals;
|
||||
const toMarketId = TOKEN_INFO[toToken].marketId;
|
||||
await dydx
|
||||
.operate(
|
||||
[{ owner: makerAddress, number: accountId }],
|
||||
[
|
||||
...(depositSize > 0
|
||||
? [
|
||||
{
|
||||
actionType: DydxActionType.Deposit,
|
||||
accountIdx: ZERO,
|
||||
amount: {
|
||||
sign: true,
|
||||
denomination: DydxAssetDenomination.Wei,
|
||||
ref: DydxAssetReference.Delta,
|
||||
value: fromTokenUnitAmount(depositSize, fromDecimals),
|
||||
},
|
||||
primaryMarketId: new BigNumber(fromMarketId),
|
||||
secondaryMarketId: new BigNumber(constants.NULL_ADDRESS),
|
||||
otherAddress: makerAddress,
|
||||
otherAccountIdx: ZERO,
|
||||
data: constants.NULL_BYTES,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(withdrawSize > 0
|
||||
? [
|
||||
{
|
||||
actionType: DydxActionType.Withdraw,
|
||||
accountIdx: ZERO,
|
||||
amount: {
|
||||
sign: false,
|
||||
denomination: DydxAssetDenomination.Wei,
|
||||
ref: DydxAssetReference.Delta,
|
||||
value: fromTokenUnitAmount(withdrawSize, toDecimals),
|
||||
},
|
||||
primaryMarketId: new BigNumber(toMarketId),
|
||||
secondaryMarketId: new BigNumber(constants.NULL_ADDRESS),
|
||||
otherAddress: makerAddress,
|
||||
otherAccountIdx: ZERO,
|
||||
data: constants.NULL_BYTES,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from: makerAddress });
|
||||
}
|
||||
|
||||
const SECONDS_IN_ONE_YEAR = 365 * 24 * 60 * 60;
|
||||
|
||||
function createOrder(fields: Partial<Order> = {}): Order {
|
||||
return {
|
||||
chainId: 1,
|
||||
exchangeAddress: contractAddresses.exchange,
|
||||
expirationTimeSeconds: new BigNumber(Math.floor(Date.now() / 1000 + SECONDS_IN_ONE_YEAR)),
|
||||
makerAddress: CHONKY_DAI_WALLET,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
salt: new BigNumber(hexUtils.random()),
|
||||
makerAssetAmount: fromTokenUnitAmount(100, USDC_DECIMALS),
|
||||
takerAssetAmount: fromTokenUnitAmount(200, DAI_DECIMALS),
|
||||
makerFee: ZERO,
|
||||
takerFee: ZERO,
|
||||
makerAssetData: encodeDydxBridgeAssetData(),
|
||||
takerAssetData: encodeERC20AssetData(DAI_ADDRESS),
|
||||
makerFeeAssetData: constants.NULL_BYTES,
|
||||
takerFeeAssetData: constants.NULL_BYTES,
|
||||
...fields,
|
||||
};
|
||||
}
|
||||
|
||||
function encodeDydxBridgeAssetData(
|
||||
fields: Partial<{
|
||||
fromToken: string;
|
||||
toToken: string;
|
||||
depositRate: number;
|
||||
withdrawRate: number;
|
||||
accountId: BigNumber;
|
||||
}> = {},
|
||||
): string {
|
||||
const { fromToken, toToken, depositRate, withdrawRate, accountId } = {
|
||||
fromToken: DAI_ADDRESS,
|
||||
toToken: USDC_ADDRESS,
|
||||
depositRate: 1,
|
||||
withdrawRate: 1,
|
||||
accountId: ZERO,
|
||||
...fields,
|
||||
};
|
||||
const fromTokenMarketId = new BigNumber(TOKEN_INFO[fromToken].marketId);
|
||||
const toTokenMarketId = new BigNumber(TOKEN_INFO[toToken].marketId);
|
||||
const bridgeData: DydxBridgeData = {
|
||||
accountNumbers: [accountId],
|
||||
actions: [
|
||||
...(depositRate > 0
|
||||
? [
|
||||
{
|
||||
actionType: DydxBridgeActionType.Deposit,
|
||||
accountIdx: ZERO,
|
||||
marketId: fromTokenMarketId,
|
||||
...createConversionFraction(toToken, fromToken, depositRate),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(withdrawRate > 0
|
||||
? [
|
||||
{
|
||||
actionType: DydxBridgeActionType.Withdraw,
|
||||
accountIdx: ZERO,
|
||||
marketId: toTokenMarketId,
|
||||
...createConversionFraction(toToken, toToken, withdrawRate),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
};
|
||||
return encodeERC20BridgeAssetData(toToken, bridge.address, dydxBridgeDataEncoder.encode({ bridgeData }));
|
||||
}
|
||||
|
||||
// Create fraction with default 18 decimal precision.
|
||||
function createConversionFraction(
|
||||
fromToken: string,
|
||||
toToken: string,
|
||||
rate: number,
|
||||
): {
|
||||
conversionRateNumerator: BigNumber;
|
||||
conversionRateDenominator: BigNumber;
|
||||
} {
|
||||
const fromDecimals = TOKEN_INFO[fromToken].decimals;
|
||||
const toDecimals = TOKEN_INFO[toToken].decimals;
|
||||
return {
|
||||
conversionRateNumerator: fromTokenUnitAmount(rate, toDecimals),
|
||||
conversionRateDenominator: fromTokenUnitAmount(1, fromDecimals),
|
||||
};
|
||||
}
|
||||
|
||||
function randomAccountId(): BigNumber {
|
||||
return new BigNumber(hexUtils.random());
|
||||
}
|
||||
|
||||
describe('DAI -> USDC', () => {
|
||||
const makerAddress = CHONKY_DAI_WALLET;
|
||||
function _createOrder(fields: Partial<Order> = {}): Order {
|
||||
return createOrder(fields);
|
||||
}
|
||||
|
||||
it('validates a fully solvent order', async () => {
|
||||
// This account is collateralized enough to fill the order with just
|
||||
// withdraws.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 200, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: 0,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.eq(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
it('validates a perpetually solvent order', async () => {
|
||||
// This account is not very well collateralized, but the deposit rate
|
||||
// will keep the collateralization ratio the same or better.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: minMarginRatio,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.eq(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
it('validates a partially solvent order with an inadequate deposit', async () => {
|
||||
// This account is not very well collateralized and the deposit rate is
|
||||
// also too low to sustain the collateralization ratio for the full order.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: minMarginRatio * 0.95,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.gt(0);
|
||||
expect(fillableTakerAssetAmount).to.bignumber.lt(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
it('validates a partially solvent order with no deposit', async () => {
|
||||
// This account is not very well collateralized and there is no deposit
|
||||
// to keep the collateralization ratio up.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: 0,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.gt(0);
|
||||
expect(fillableTakerAssetAmount).to.bignumber.lt(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
// TODO(dorothy-zbornak): We can't actually create an account that's below
|
||||
// the margin ratio without replacing the price oracles.
|
||||
it('invalidates a virtually insolvent order', async () => {
|
||||
// This account has a collateralization ratio JUST above the
|
||||
// minimum margin ratio, so it can only withdraw nearly zero maker tokens.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 1 / (minMarginRatio + 3e-4));
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: 0,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
// Price fluctuations will cause this to be a little above zero, so we
|
||||
// don't compare to zero.
|
||||
expect(fillableTakerAssetAmount).to.bignumber.lt(fromTokenUnitAmount(1e-3, DAI_DECIMALS));
|
||||
});
|
||||
});
|
||||
|
||||
describe('USDC -> DAI', () => {
|
||||
const makerAddress = CHONKY_USDC_WALLET;
|
||||
function _createOrder(fields: Partial<Order> = {}): Order {
|
||||
return createOrder({
|
||||
makerAddress,
|
||||
takerAssetData: encodeERC20AssetData(USDC_ADDRESS),
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
fromToken: USDC_ADDRESS,
|
||||
toToken: DAI_ADDRESS,
|
||||
}),
|
||||
makerAssetAmount: fromTokenUnitAmount(100, DAI_DECIMALS),
|
||||
takerAssetAmount: fromTokenUnitAmount(100, USDC_DECIMALS),
|
||||
...fields,
|
||||
});
|
||||
}
|
||||
|
||||
it('validates a fully solvent order', async () => {
|
||||
// This account is collateralized enough to fill the order with just
|
||||
// withdraws.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 200, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: 0,
|
||||
fromToken: USDC_ADDRESS,
|
||||
toToken: DAI_ADDRESS,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.eq(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
it('validates a perpetually solvent order', async () => {
|
||||
// This account is not very well collateralized, but the deposit rate
|
||||
// will keep the collateralization ratio the same or better.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: minMarginRatio,
|
||||
fromToken: USDC_ADDRESS,
|
||||
toToken: DAI_ADDRESS,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.eq(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
it('validates a partially solvent order with an inadequate deposit', async () => {
|
||||
// This account is not very well collateralized and the deposit rate is
|
||||
// also too low to sustain the collateralization ratio for the full order.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: minMarginRatio * 0.95,
|
||||
fromToken: USDC_ADDRESS,
|
||||
toToken: DAI_ADDRESS,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.gt(0);
|
||||
expect(fillableTakerAssetAmount).to.bignumber.lt(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
it('validates a partially solvent order with no deposit', async () => {
|
||||
// This account is not very well collateralized and there is no deposit
|
||||
// to keep the collateralization ratio up.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 0);
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: 0,
|
||||
fromToken: USDC_ADDRESS,
|
||||
toToken: DAI_ADDRESS,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
expect(fillableTakerAssetAmount).to.bignumber.gt(0);
|
||||
expect(fillableTakerAssetAmount).to.bignumber.lt(order.takerAssetAmount);
|
||||
});
|
||||
|
||||
// TODO(dorothy-zbornak): We can't actually create an account that's below
|
||||
// the margin ratio without replacing the price oracles.
|
||||
it('invalidates a virtually insolvent order', async () => {
|
||||
// This account has a collateralization ratio JUST above the
|
||||
// minimum margin ratio, so it can only withdraw nearly zero maker tokens.
|
||||
const accountId = randomAccountId();
|
||||
await depositAndWithdrawAsync(makerAddress, accountId, 1, 1 / (minMarginRatio + 3e-4));
|
||||
const order = _createOrder({
|
||||
makerAssetData: encodeDydxBridgeAssetData({
|
||||
accountId,
|
||||
depositRate: 0,
|
||||
fromToken: USDC_ADDRESS,
|
||||
toToken: DAI_ADDRESS,
|
||||
}),
|
||||
});
|
||||
const [, fillableTakerAssetAmount] = await devUtils.getOrderRelevantState(order, SIGNATURE).callAsync();
|
||||
// Price fluctuations will cause this to be a little above zero, so we
|
||||
// don't compare to zero.
|
||||
expect(fillableTakerAssetAmount).to.bignumber.lt(fromTokenUnitAmount(1e-3, USDC_DECIMALS));
|
||||
});
|
||||
});
|
||||
});
|
@@ -27,6 +27,7 @@ blockchainTests('DevUtils.getOrderHash', env => {
|
||||
artifacts,
|
||||
exchange.address,
|
||||
constants.NULL_ADDRESS,
|
||||
constants.NULL_ADDRESS,
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -81,6 +81,7 @@ blockchainTests.resets('LibAssetData', env => {
|
||||
artifacts,
|
||||
deployment.exchange.address,
|
||||
constants.NULL_ADDRESS,
|
||||
constants.NULL_ADDRESS,
|
||||
);
|
||||
|
||||
staticCallTarget = await TestStaticCallTargetContract.deployFrom0xArtifactAsync(
|
||||
|
@@ -43,6 +43,7 @@ blockchainTests('LibTransactionDecoder', env => {
|
||||
artifacts,
|
||||
exchange.address,
|
||||
constants.NULL_ADDRESS,
|
||||
constants.NULL_ADDRESS,
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -34,14 +34,14 @@ blockchainTests.resets('Exchange fills dydx orders', env => {
|
||||
let testTokenAddress: string;
|
||||
const defaultDepositAction = {
|
||||
actionType: DydxBridgeActionType.Deposit as number,
|
||||
accountId: constants.ZERO_AMOUNT,
|
||||
accountIdx: constants.ZERO_AMOUNT,
|
||||
marketId,
|
||||
conversionRateNumerator: dydxConversionRateNumerator,
|
||||
conversionRateDenominator: dydxConversionRateDenominator,
|
||||
};
|
||||
const defaultWithdrawAction = {
|
||||
actionType: DydxBridgeActionType.Withdraw as number,
|
||||
accountId: constants.ZERO_AMOUNT,
|
||||
accountIdx: constants.ZERO_AMOUNT,
|
||||
marketId,
|
||||
conversionRateNumerator: constants.ZERO_AMOUNT,
|
||||
conversionRateDenominator: constants.ZERO_AMOUNT,
|
||||
|
@@ -203,6 +203,7 @@ export class DeploymentManager {
|
||||
devUtilsArtifacts,
|
||||
exchange.address,
|
||||
constants.NULL_ADDRESS,
|
||||
constants.NULL_ADDRESS,
|
||||
);
|
||||
|
||||
// Construct the new instance and return it.
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "4.1.5",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "4.1.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "4.1.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "4.1.2",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "4.1.1",
|
||||
|
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
|
||||
|
||||
CHANGELOG
|
||||
|
||||
## v4.1.5 - _March 3, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.1.4 - _February 27, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.1.3 - _February 26, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.1.2 - _February 25, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
||||
## v4.1.1 - _February 15, 2020_
|
||||
|
||||
* Dependencies updated
|
||||
|
@@ -3,6 +3,7 @@
|
||||
"contractsDir": "./contracts",
|
||||
"useDockerisedSolc": false,
|
||||
"isOfflineMode": false,
|
||||
"shouldSaveStandardInput": true,
|
||||
"compilerSettings": {
|
||||
"evmVersion": "istanbul",
|
||||
"optimizer": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@0x/contracts-multisig",
|
||||
"version": "4.1.1",
|
||||
"version": "4.1.5",
|
||||
"engines": {
|
||||
"node": ">=6.12"
|
||||
},
|
||||
@@ -49,18 +49,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/contracts/multisig/README.md",
|
||||
"devDependencies": {
|
||||
"@0x/abi-gen": "^5.2.0",
|
||||
"@0x/contracts-asset-proxy": "^3.2.1",
|
||||
"@0x/contracts-erc20": "^3.1.1",
|
||||
"@0x/contracts-gen": "^2.0.7",
|
||||
"@0x/contracts-test-utils": "^5.1.5",
|
||||
"@0x/contracts-utils": "^4.3.1",
|
||||
"@0x/dev-utils": "^3.2.0",
|
||||
"@0x/sol-compiler": "^4.0.7",
|
||||
"@0x/abi-gen": "^5.2.2",
|
||||
"@0x/contracts-asset-proxy": "^3.2.5",
|
||||
"@0x/contracts-erc20": "^3.1.5",
|
||||
"@0x/contracts-gen": "^2.0.8",
|
||||
"@0x/contracts-test-utils": "^5.3.2",
|
||||
"@0x/contracts-utils": "^4.4.3",
|
||||
"@0x/dev-utils": "^3.2.1",
|
||||
"@0x/sol-compiler": "^4.0.8",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@0x/types": "^3.1.2",
|
||||
"@0x/utils": "^5.4.0",
|
||||
"@0x/web3-wrapper": "^7.0.6",
|
||||
"@0x/utils": "^5.4.1",
|
||||
"@0x/web3-wrapper": "^7.0.7",
|
||||
"@types/lodash": "4.14.104",
|
||||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "*",
|
||||
@@ -78,7 +78,7 @@
|
||||
"typescript": "3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.0",
|
||||
"@0x/base-contract": "^6.2.1",
|
||||
"@0x/typescript-typings": "^5.0.2",
|
||||
"ethereum-types": "^3.1.0"
|
||||
},
|
||||
|
@@ -1,4 +1,40 @@
|
||||
[
|
||||
{
|
||||
"timestamp": 1583220306,
|
||||
"version": "2.0.12",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582837861,
|
||||
"version": "2.0.11",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582677073,
|
||||
"version": "2.0.10",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1582623685,
|
||||
"version": "2.0.9",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Dependencies updated"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1581748629,
|
||||
"version": "2.0.8",
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user