Skip to content

Commit 80b6adc

Browse files
committed
update
1 parent 9045316 commit 80b6adc

File tree

4 files changed

+1404
-0
lines changed

4 files changed

+1404
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ DAPP Contract usage interaction is constantly under development, however we rece
189189
- [AmisDapp Airdrop revenue generator on Ropsten, Kovan and soon mainnet](https://amisolution.github.io/ERC20-AMIS/airdrop)
190190
- [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)
191191
- [AMIS Trade on 0x relay with smartdex -in dev - https://amis-erc20.github.io/smartdex](https://amis-erc20.github.io/smartdex)
192+
- [Loan Generator](https://ropsten.etherscan.io/address/0x85b4b45df063c35b16adbf1f04f70728f7bc6635#readContract)
193+
- [Escrow Management](https://ropsten.etherscan.io/address/0x53a00aae1d0c9717f2ecbfe94e418b355e09fc82)
192194

193195
Visit us on our blogs @Medium, Blogspot, erc20-amis.amisolution.net and / or [Wordpress](https://erc20amis.wordpress.com/) for more details.
194196
[This page on github.io is here => https://amisolution.github.io/ERC20-AMIS](https://amisolution.github.io/ERC20-AMIS/)

contracts/Conferencev02

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
pragma solidity ^0.4.24;
2+
3+
/**
4+
aaaaaaaaaa: aaaaaaaa` aaaaaaaa aaaaaaaaa+ aaaaaaaaaaaaaaaaaa+
5+
a` ,: + . . ,` aa ' ; +
6+
aa :, a : : a aa, a ' a
7+
aa :, aa + ' a aaa ' a `.
8+
aa; :, aa` # +, ,` aaaa + aa a
9+
aaa :, aaa # a' a aaaa a aa. +
10+
aaa ;. aaa; + aa a aaaaa ; aaa #aaaaaaaaaaa
11+
aaaa ;. aaaa : aa .. aaaaa; # aaa# aaaaaaaaaaa
12+
aaaa '. aaaaa .aa a aaaaaa a aaaa .aaaaaaaaaa'
13+
aaaa; '. aaaaa a a aaaaaaa `, aaaaa :
14+
aaaaa '. aaaaaa .. aaaaaaa` a aaaaa; a
15+
aaaaa '. aaaaaa, a aaaaaaaa a aaaaaa +
16+
aaaaaa '` aaaaaaa a aaaaaaaa' .. aaaaaaa '
17+
aaaaaa + +` aaaaaaa+ `,,aaaaaaaa a aaaaaaa+ a
18+
aaaaa; a +` aaaaaaaa a aaaaaaaa a,aaaaaaaaaaaaaaaaaaa ;
19+
:aaaaa +# +` aaaaaaaa a aaaaaaa. ,``aaaaaaaaaaaaaaaaaa+ #
20+
aaaaa a; +` +aaaaaa` `, aaaaaaa a `aaaaaaaaaaaaaaaaaa a
21+
aaaaa +a. +` ,aaaaaa a aaaaaa# # aaaaaaaaaaaaaaaaaa `,
22+
aaaa #` aaaaa; . ' a 'aaaaa :` aaaaaa a
23+
`aaa; # aaaaa , a `, .aaaaa a aaaaa a
24+
'aaa # aaaa# :: aa # aaaa: + 'aaaa :`
25+
aaa # #aaa a; 'a# a aaaa ; aaa. a
26+
aaa aaaa. # :aaa a+ ,aa` : aaaa a aaa #
27+
aa aaaaa a aa. #aa ; aa # #aaaaaaaaaaa' :aaaaaaaaaaaaaaaaaaaaaaa
28+
,aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa#aaaaa aaaaaaaaaa: ;aaaaaaaaaaa :aaaaaaaaaaaaaaaaaaaaaa
29+
#aaaaaaaaa aaaaaaaaaaa; #aaaaaaaaa .'#a aaaaaaaaa: `aaaaaaaaaa `aaaaaaaaaaaaaaaaaaaa`
30+
*/
31+
32+
33+
contract Conferencev02 { // can be killed, so the owner gets sent the money in the end
34+
35+
address public organizer;
36+
mapping (address => uint) public registrantsPaid;
37+
uint public numRegistrants;
38+
uint public quota;
39+
40+
event Deposit(address _from, uint _amount); // so you can log the event
41+
event Refund(address _to, uint _amount); // so you can log the event
42+
43+
function Conference() {
44+
organizer = msg.sender;
45+
quota = 100;
46+
numRegistrants = 0;
47+
}
48+
49+
function buyTicket() public payable {
50+
if (numRegistrants >= quota) {
51+
revert(); // throw ensures funds will be returned
52+
}
53+
registrantsPaid[msg.sender] = msg.value;
54+
numRegistrants++;
55+
Deposit(msg.sender, msg.value);
56+
}
57+
58+
function changeQuota(uint newquota) public {
59+
if (msg.sender != organizer) { return; }
60+
quota = newquota;
61+
}
62+
63+
function refundTicket(address recipient, uint amount) public {
64+
if (msg.sender != organizer) { return; }
65+
if (registrantsPaid[recipient] == amount) {
66+
address myAddress = this;
67+
if (myAddress.balance >= amount) {
68+
recipient.transfer(amount);
69+
Refund(recipient, amount);
70+
registrantsPaid[recipient] = 0;
71+
numRegistrants--;
72+
}
73+
}
74+
return;
75+
}
76+
77+
function destroy() {
78+
if (msg.sender == organizer) { // without this funds could be locked in the contract forever!
79+
suicide(organizer);
80+
}
81+
}
82+
}

contracts/EscrowManagement.sol

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
pragma solidity ^0.4.24;
2+
3+
// ----------------------------------------------------------------------------
4+
// ERC Token Standard #20 Interface
5+
// ----------------------------------------------------------------------------
6+
contract ERC20Interface {
7+
function totalSupply() public constant returns (uint);
8+
function balanceOf(address tokenOwner) public constant returns (uint balance);
9+
function allowance(address tokenOwner, address spender) public constant returns (uint remaining);
10+
function transfer(address to, uint tokens) public returns (bool success);
11+
function approve(address spender, uint tokens) public returns (bool success);
12+
function transferFrom(address from, address to, uint tokens) public returns (bool success);
13+
14+
event Transfer(address indexed from, address indexed to, uint tokens);
15+
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
16+
}
17+
18+
contract EscrowManagement {
19+
20+
// CONTRACT VARIABLES ###########################################################################################
21+
22+
uint public numberOfSuccessfullExecutions;
23+
24+
// Escrow Order Template
25+
struct Escrow {
26+
address creator; // address of the creator of the order
27+
uint amountTokenSell; // amount of sell units creator is selling
28+
address tokenAddressSell; // address of the sell unit
29+
uint amountTokenBuy; // amount of buy units creator is buying
30+
address tokenAddressBuy; // address of the buy unit
31+
}
32+
33+
mapping (address => mapping (address => Escrow[])) allOrders; // Stores all the escrows trading with said sell and by tokens
34+
35+
enum EscrowState{
36+
Created, // State representing that escrow order has been created by the seller
37+
Accepted, // State representing that escrow order has been accepted by the buyer
38+
Completed, // State representing that escrow order has been fulfilled and the exchange of tokens completed
39+
Died // State representing that escrow order has been removed and deleted from the order book
40+
}
41+
42+
// ##############################################################################################################
43+
44+
45+
// EVENTS #######################################################################################################
46+
47+
event EscrowManagerInitialized(); // Escrow Manager Contract has been deployed and ready for usage
48+
event EscrowCreated(EscrowState escrowState); // Escrow order has been created by the seller
49+
event EscrowAccepted(EscrowState escrowState); // Escrow order has been accepted by the buyer
50+
event EscrowCompleted(EscrowState escrowState); // Escrow order has been fulfilled and the exchange of tokens completed
51+
event EscrowDied(EscrowState escrowState); // Escrow order has been removed and deleted from the order book
52+
53+
// ##############################################################################################################
54+
55+
56+
// MODIFIERS ####################################################################################################
57+
58+
// Asserts that the escrow order chosen is valid
59+
// inputs:
60+
// address _tokenAddressSell : contract address of the sell unit
61+
// address _tokenAddressBuy : contract address of the buy unit
62+
// uint escrowId : position id of the escrow order in the order book
63+
modifier onlyValidEscrowId(address _tokenAddressSell, address _tokenAddressBuy, uint escrowId){
64+
require(
65+
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
67+
);
68+
_;
69+
}
70+
71+
// Asserts that the escrow order chosen is valid
72+
// inputs:
73+
// uint sellTokenAmount : amount of sell tokens
74+
// uint buyTokenAmount : amount of buy tokens
75+
modifier onlyNonZeroAmts(uint sellTokenAmount, uint buyTokenAmount){
76+
require(
77+
sellTokenAmount > 0 && buyTokenAmount > 0, // Ensure that the amounts entered into the creation of an escrow order are non-zero and positive
78+
"Escrow order amounts are 0!" // Message to send if the condition above has failed, revert transaction
79+
);
80+
_;
81+
}
82+
83+
// ##############################################################################################################
84+
85+
86+
// MAIN CONTRACT METHODS ########################################################################################
87+
88+
// Constructor function for EscrowManager contract deployment
89+
function EscrowManager() {
90+
numberOfSuccessfullExecutions = 0;
91+
EscrowManagerInitialized();
92+
}
93+
94+
// Creates the escrow order and stores the order in the escrow manager
95+
// inputs:
96+
// address _tokenAddressSell: contract address of the sell unit
97+
// uint _amountTokenSell: amount of sell units to sell
98+
// address _tokenAddressBuy: contract address of buy unit
99+
// uint _amountTokenBuy: amount of buy units to buy
100+
// events:
101+
// EscrowCreated(EscrowState.Created): Escrow order has been created and is added to the orderbook
102+
function createEscrow(address _tokenAddressSell, uint _amountTokenSell,
103+
address _tokenAddressBuy, uint _amountTokenBuy)
104+
payable
105+
onlyNonZeroAmts(_amountTokenSell, _amountTokenBuy)
106+
{
107+
108+
Escrow memory newEscrow = Escrow({ // Create escrow order based on the 'Escrow' template
109+
creator: msg.sender, // Assign the sender of the transaction to be the creator of the escrow order
110+
amountTokenSell: _amountTokenSell, // Creator's specified sell amount
111+
tokenAddressSell: _tokenAddressSell, // Creator's specified sell unit
112+
amountTokenBuy: _amountTokenBuy, // Creator's specified buy amount
113+
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, uint escrowId)
129+
payable
130+
onlyValidEscrowId(_tokenAddressSell, _tokenAddressBuy, escrowId)
131+
{
132+
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, address buyer)
146+
private
147+
{
148+
ERC20Interface(escrow.tokenAddressBuy).transfer(escrow.creator, escrow.amountTokenBuy); // EscrowManager transfers buy token amount to escrow creator (seller)
149+
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, uint escrowId)
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
169+
}
170+
171+
// ##############################################################################################################
172+
173+
174+
// GETTERS ######################################################################################################
175+
176+
// Retrieves all the escrow orders based on the sell unit and the buy unit
177+
// inputs:
178+
// address _tokenAddressSell: contract address of the sell unit
179+
// address _tokenAddressBuy: contract address of the buy unit
180+
// outputs:
181+
// uint[] sellAmount: list of the all the amounts in terms sell units in the list of escrow orders
182+
// uint[] buyAmount: list of the all the amounts in terms buy units in the list of escrow orders
183+
function getOrderBook(address _tokenAddressSell, address _tokenAddressBuy)
184+
constant returns (uint[] sellAmount, uint[] buyAmount)
185+
{
186+
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 = new uint[](numEscrows); // Initiate list of sell amounts
189+
uint[] memory buyAmounts = new uint[](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
195+
}
196+
197+
// ##############################################################################################################
198+
199+
}

0 commit comments

Comments
 (0)