-
Notifications
You must be signed in to change notification settings - Fork 59
Brian+alex/integrate taker wallet #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,13 +84,13 @@ contract CoreAccounting is | |
external | ||
isValidBatchTransaction(_tokenAddresses, _quantities) | ||
{ | ||
// For each token and quantity pair, run deposit function | ||
for (uint i = 0; i < _tokenAddresses.length; i++) { | ||
deposit( | ||
_tokenAddresses[i], | ||
_quantities[i] | ||
); | ||
} | ||
// Call internal batch deposit function | ||
batchDepositInternal( | ||
msg.sender, | ||
msg.sender, | ||
_tokenAddresses, | ||
_quantities | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -130,15 +130,8 @@ contract CoreAccounting is | |
isPositiveQuantity(_quantity) | ||
{ | ||
// Call TransferProxy contract to transfer user tokens to Vault | ||
ITransferProxy(state.transferProxyAddress).transfer( | ||
_tokenAddress, | ||
_quantity, | ||
depositInternal( | ||
msg.sender, | ||
state.vaultAddress | ||
); | ||
|
||
// Call Vault contract to attribute deposited tokens to user | ||
IVault(state.vaultAddress).incrementTokenOwner( | ||
msg.sender, | ||
_tokenAddress, | ||
_quantity | ||
|
@@ -171,4 +164,63 @@ contract CoreAccounting is | |
_quantity | ||
); | ||
} | ||
|
||
/* ============ Internal Functions ============ */ | ||
|
||
/** | ||
* Deposit any quantity of tokens into the vault. | ||
* | ||
* @param _tokenAddress The address of the ERC20 token | ||
* @param _quantity The number of tokens to deposit | ||
*/ | ||
function depositInternal( | ||
address _from, | ||
address _to, | ||
address _tokenAddress, | ||
uint _quantity | ||
) | ||
public | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes...important catch. Imma push a fix immediately. |
||
{ | ||
// Call TransferProxy contract to transfer user tokens to Vault | ||
ITransferProxy(state.transferProxyAddress).transfer( | ||
_tokenAddress, | ||
_quantity, | ||
_from, | ||
state.vaultAddress | ||
); | ||
|
||
// Call Vault contract to attribute deposited tokens to user | ||
IVault(state.vaultAddress).incrementTokenOwner( | ||
_to, | ||
_tokenAddress, | ||
_quantity | ||
); | ||
} | ||
|
||
/** | ||
* Deposit multiple tokens to the vault. Quantities should be in the | ||
* order of the addresses of the tokens being deposited. | ||
* | ||
* @param _tokenAddresses Array of the addresses of the ERC20 tokens | ||
* @param _quantities Array of the number of tokens to deposit | ||
*/ | ||
function batchDepositInternal( | ||
address _from, | ||
address _to, | ||
address[] _tokenAddresses, | ||
uint[] _quantities | ||
) | ||
internal | ||
isValidBatchTransaction(_tokenAddresses, _quantities) | ||
{ | ||
// For each token and quantity pair, run deposit function | ||
for (uint i = 0; i < _tokenAddresses.length; i++) { | ||
depositInternal( | ||
_from, | ||
_to, | ||
_tokenAddresses[i], | ||
_quantities[i] | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol"; | |
import { CoreModifiers } from "../lib/CoreSharedModifiers.sol"; | ||
import { CoreState } from "../lib/CoreState.sol"; | ||
import { ExchangeHandler } from "../lib/ExchangeHandler.sol"; | ||
import { ICoreAccounting } from "../interfaces/ICoreAccounting.sol"; | ||
import { ICoreIssuance } from "../interfaces/ICoreIssuance.sol"; | ||
import { IExchange } from "../interfaces/IExchange.sol"; | ||
import { ITransferProxy } from "../interfaces/ITransferProxy.sol"; | ||
|
@@ -42,6 +43,7 @@ import { OrderLibrary } from "../lib/OrderLibrary.sol"; | |
*/ | ||
contract CoreIssuanceOrder is | ||
ICoreIssuance, | ||
ICoreAccounting, | ||
CoreState, | ||
CoreModifiers | ||
{ | ||
|
@@ -50,7 +52,7 @@ contract CoreIssuanceOrder is | |
|
||
/* ============ Constants ============ */ | ||
|
||
uint256 constant EXCHANGE_HEADER_LENGTH = 128; | ||
uint256 constant EXCHANGE_HEADER_LENGTH = 160; | ||
|
||
string constant INVALID_CANCEL_ORDER = "Only maker can cancel order."; | ||
string constant INVALID_EXCHANGE = "Exchange does not exist."; | ||
|
@@ -151,11 +153,11 @@ contract CoreIssuanceOrder is | |
settleOrder(order, _fillQuantity, _orderData); | ||
|
||
//Issue Set | ||
// issueInternal( | ||
// order.makerAddress, | ||
// order.setAddress, | ||
// _fillQuantity | ||
// ); | ||
issueInternal( | ||
order.makerAddress, | ||
order.setAddress, | ||
_fillQuantity | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -264,7 +266,7 @@ contract CoreIssuanceOrder is | |
|
||
// Read the order body based on header order length info | ||
uint256 exchangeDataLength = header.totalOrdersLength.add(EXCHANGE_HEADER_LENGTH); | ||
bytes memory orderBody = LibBytes.slice( | ||
bytes memory bodyData = LibBytes.slice( | ||
_orderData, | ||
scannedBytes.add(EXCHANGE_HEADER_LENGTH), | ||
scannedBytes.add(exchangeDataLength) | ||
|
@@ -278,13 +280,28 @@ contract CoreIssuanceOrder is | |
exchange | ||
); | ||
|
||
//Call Exchange | ||
//IExchange(header.exchange).exchange(orderBody); | ||
// Call Exchange | ||
address[] memory componentFillTokens = new address[](header.orderCount); | ||
uint[] memory componentFillAmounts = new uint[](header.orderCount); | ||
(componentFillTokens, componentFillAmounts) = IExchange(exchange).exchange( | ||
msg.sender, | ||
header.orderCount, | ||
bodyData | ||
); | ||
|
||
// Transfer component tokens from wrapper to vault | ||
batchDepositInternal( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow that's really nice! |
||
exchange, | ||
_makerAddress, | ||
componentFillTokens, | ||
componentFillAmounts | ||
); | ||
|
||
// Update scanned bytes with header and body lengths | ||
scannedBytes = scannedBytes.add(exchangeDataLength); | ||
makerTokenUsed += header.makerTokenAmount; | ||
} | ||
|
||
return makerTokenUsed; | ||
} | ||
|
||
|
@@ -415,18 +432,22 @@ contract CoreIssuanceOrder is | |
|
||
// Execute exchange orders | ||
uint makerTokenAmountUsed = executeExchangeOrders(_orderData, _order.makerAddress); | ||
require(makerTokenAmountUsed <= requiredMakerTokenAmount); | ||
|
||
// Check that maker's component tokens in Vault have been incremented correctly | ||
for (i = 0; i < _order.requiredComponents.length; i++) { | ||
uint currentBal = IVault(state.vaultAddress).getOwnerBalance( | ||
_order.makerAddress, | ||
_order.requiredComponents[i] | ||
); | ||
//require(currentBal >= requiredBalances[i]); | ||
require(currentBal >= requiredBalances[i]); | ||
} | ||
|
||
settleAccounts(_order, _fillQuantity, requiredMakerTokenAmount, makerTokenAmountUsed); | ||
settleAccounts( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have the logic to send remaining makerTokens to the taker/arb yet? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's in the settle accounts function itself |
||
_order, | ||
_fillQuantity, | ||
requiredMakerTokenAmount, | ||
makerTokenAmountUsed | ||
); | ||
|
||
// Tally fill in orderFills mapping | ||
state.orderFills[_order.orderHash] = state.orderFills[_order.orderHash].add(_fillQuantity); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2018 Set Labs Inc. | ||
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.4.24; | ||
|
||
|
||
/** | ||
* @title ICoreIssuance | ||
* @author Set Protocol | ||
* | ||
* The ICoreIssuance Contract defines all the functions exposed in the CoreIssuance | ||
* extension. | ||
*/ | ||
contract ICoreAccounting { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a little weird to be using an abstract class here instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we can't use internal functions in libraries so we have to define it as a contract. Which unfortunately makes us have to be more careful with inheritance when the Core inherits the IssuanceOrder extension lest we overwrite the actual logic of the batchDepositInternal function. If we want to name it something else we can do that since it isn't technically an interface thought it is intended to act as such. |
||
|
||
/** | ||
* Deposit multiple tokens to the vault. Quantities should be in the | ||
* order of the addresses of the tokens being deposited. | ||
* | ||
* @param _tokenAddresses Array of the addresses of the ERC20 tokens | ||
* @param _quantities Array of the number of tokens to deposit | ||
*/ | ||
function batchDepositInternal( | ||
address _from, | ||
address _to, | ||
address[] _tokenAddresses, | ||
uint[] _quantities | ||
) | ||
internal; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? Does it increment one at a time?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this is particular to our workflow because we scan 64 bytes at at time, so you can think of it as counting from 0 starting on the 7th bit.