You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2
Original file line number
Diff line number
Diff line change
@@ -189,6 +189,8 @@ DAPP Contract usage interaction is constantly under development, however we rece
189
189
-[AmisDapp Airdrop revenue generator on Ropsten, Kovan and soon mainnet](https://amisolution.github.io/ERC20-AMIS/airdrop)
190
190
-[AMIS Trade on-chain with Amisdex an On-chain Orderbook contract with builtin https://amis-erc20.github.io/amisdex](https://amis-erc20.github.io/amisdex)
191
191
-[AMIS Trade on 0x relay with smartdex -in dev - https://amis-erc20.github.io/smartdex](https://amis-erc20.github.io/smartdex)
allOrders[_tokenAddressSell][_tokenAddressBuy].length> escrowId, // Ensure that escrowId is less than the length of the escrow order list being referred to
66
+
"Invalid Escrow Order!"// Message to send if the condition above has failed, revert transaction
tokenAddressBuy: _tokenAddressBuy // Creator's specified buy unit
114
+
});
115
+
116
+
ERC20Interface(_tokenAddressSell).transferFrom(msg.sender, this, _amountTokenSell); // EscrowManager transfers the amount of sell units from Creator to itself
117
+
allOrders[_tokenAddressSell][_tokenAddressBuy].push(newEscrow); // Adds the new escrow order to the end of the order list in allOrders
118
+
EscrowCreated(EscrowState.Created); // Event thrown to indicate that escrow order has been created
119
+
}
120
+
121
+
// Escrow order is chosen and fulfilled
122
+
// inputs:
123
+
// address _tokenAddressSell: contract address of the sell unit
124
+
// address _tokenAddressBuy: contract address of buy unit
125
+
// uint escrowId: position of the escrow order in allOrders based on the sell and buy contract address
126
+
// events:
127
+
// EscrowAccepted(EscrowState.Accepted): Escrow order has been accepted by the sender of the transaction
128
+
function acceptEscrow(address_tokenAddressSell, address_tokenAddressBuy, uintescrowId)
Escrow memory chosenEscrow = allOrders[_tokenAddressSell][_tokenAddressBuy][escrowId]; // Extract the chosen escrow order from allOrders based on escrowId
133
+
ERC20Interface(chosenEscrow.tokenAddressBuy).transferFrom(msg.sender, this, chosenEscrow.amountTokenBuy); // EscrowManager transfers the amount of buy units from transaction sender to itself
134
+
EscrowAccepted(EscrowState.Accepted); // Escrow order amounts have been transfered to EscrowManager and thus order is accepted by transaction sender
135
+
executeEscrow(chosenEscrow, msg.sender); // EscrowManager to respective token amounts to seller and buyer
136
+
escrowDeletion(_tokenAddressSell, _tokenAddressBuy, escrowId); // EscrowManager to remove the fulfilled escrow order from allOrders
137
+
}
138
+
139
+
// EscrowManager transfers the respective tokens amounts to the seller and the buyer
140
+
// inputs:
141
+
// Escrow escrow: Chosen escrow order to execute the exchange of tokens
142
+
// address buyer: Address of the buyer that accepted the escrow order
143
+
// events:
144
+
// EscrowCompleted(EscrowState.Completed): Escrow order has been executed and exchange of tokens is completed
145
+
function executeEscrow(Escrow escrow, addressbuyer)
ERC20Interface(escrow.tokenAddressSell).transfer(buyer, escrow.amountTokenSell); // EscrowManager transfers sell token amount to buyer
150
+
numberOfSuccessfullExecutions++; // Increment the number of successful executions of the escrow orders
151
+
EscrowCompleted(EscrowState.Completed); // Escrow order execution of the exchange of tokens is completed
152
+
}
153
+
154
+
// EscrowManager removes the fulfilled escrow from allOrders
155
+
// inputs:
156
+
// address _tokenAddressSell: contract address of the sell unit
157
+
// address _tokenAddressBuy: contract address of buy unit
158
+
// uint escrowId: position of the escrow order in allOrders based on the sell and buy contract address
159
+
// events:
160
+
// EscrowDied(EscrowState.Died): Escrow order is removed from allOrders
161
+
function escrowDeletion(address_tokenAddressSell, address_tokenAddressBuy, uintescrowId)
162
+
private
163
+
{
164
+
for(uint i=escrowId; i<allOrders[_tokenAddressSell][_tokenAddressBuy].length-1; i++){ // Iterate through list of orders in allOrders starting from the current escrow order's position
165
+
allOrders[_tokenAddressSell][_tokenAddressBuy][i] = allOrders[_tokenAddressSell][_tokenAddressBuy][i+1]; // Shift the all the orders in the list 1 position to the left
166
+
}
167
+
allOrders[_tokenAddressSell][_tokenAddressBuy].length--; // Decrement the total length of the list of orders to account for the removal of 1 escrow order
168
+
EscrowDied(EscrowState.Died); // Escrow order has been removed from allOrders
Escrow[] memory escrows = allOrders[_tokenAddressSell][_tokenAddressBuy]; // Extract the list of escrow orders from allOrders
187
+
uint numEscrows = escrows.length; // Length of the list of escrow orders
188
+
uint[] memory sellAmounts =newuint[](numEscrows); // Initiate list of sell amounts
189
+
uint[] memory buyAmounts =newuint[](numEscrows); // Initiate list of buy amounts
190
+
for(uint i =0; i < numEscrows; i++){ // Iterate through list of escrow orders from position 0 to the end of the list of escrow orders
191
+
sellAmounts[i] = escrows[i].amountTokenSell; // Assign the position of the sell amount in the escrow order list to the same position in the sell amounts list
192
+
buyAmounts[i] = escrows[i].amountTokenBuy; // Assign the position of the buy amount in the escrow order list to the same position in the buy amounts list
193
+
}
194
+
return (sellAmounts, buyAmounts); // Returns the sell and buy amounts lists
0 commit comments