feat: update Escrow to use the proxyFor property

This commit is contained in:
Jonathan Rainville 2020-03-02 09:41:37 -05:00
parent c0ea6e83e3
commit e8fefc5922
No known key found for this signature in database
GPG Key ID: 5F4630B759727D9C
18 changed files with 109 additions and 137 deletions

View File

@ -83,14 +83,15 @@ module.exports = {
file: 'tabookey-gasless/contracts/RelayHub.sol'
},
EscrowRelay: {
args: ["$OfferStoreProxy", "$EscrowProxy", "$SNT"],
args: ["$OfferStoreProxy", "$EscrowInstance", "$SNT"],
deps: ['RelayHub']
},
Escrow: {
args: ["$accounts[0]", FALLBACK_ARBITRATOR_MAINNET, "$ArbitrationLicense", "$OfferStore", "$UserStore", "$KyberFeeBurner", FEE_MILLI_PERCENT]
},
EscrowProxy: {
EscrowInstance: {
instanceOf: "Proxy",
proxyFor: "Escrow",
args: ["0x", "$Escrow"]
},
"MiniMeToken": {"deploy": false},
@ -257,8 +258,9 @@ module.exports = {
Escrow: {
address: "0x727bF4BAed69265bBaFD39f0ab6e508F6fA118a7"
},
EscrowProxy: {
EscrowInstance: {
instanceOf: "Proxy",
proxyFor: 'Escrow',
address: "0xD5baC31a10b8938dd47326f01802fa23f1032AeE"
},
KyberFeeBurner: {

View File

@ -20,7 +20,7 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
{
console.log("Verifying if data script has been run already...");
const cVerif = new deps.web3.eth.Contract(deps.contracts.Escrow.options.jsonInterface, deps.contracts.EscrowProxy.options.address);
const cVerif = new deps.web3.eth.Contract(deps.contracts.EscrowInstance.options.jsonInterface, deps.contracts.EscrowInstance.options.address);
const isInitialized = await cVerif.methods.isInitialized().call();
if (isInitialized) {
console.log('- Data script already ran once.');
@ -46,7 +46,7 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
if(mainnetOwner){
console.log("Setting ownership of 7 contracts");
let receipt;
receipt = await sendTrxAccount0(deps.contracts.Escrow.methods.transferOwnership(mainnetOwner));
receipt = await sendTrxAccount0(deps.contracts.EscrowInstance.methods.transferOwnership(mainnetOwner));
console.log('- 1/7: ' + ((receipt.status === true || receipt.status === 1) ? 'Success' : 'FAILURE!!!'));
receipt = await sendTrxAccount0(deps.contracts.SellerLicense.methods.transferOwnership(mainnetOwner));
console.log('- 2/7: ' + ((receipt.status === true || receipt.status === 1) ? 'Success' : 'FAILURE!!!'));
@ -111,8 +111,7 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
{
console.log("Setting the initial Escrow template calling the init() function");
deps.contracts.Escrow.options.address = deps.contracts.EscrowProxy.options.address;
const receipt = await sendTrxAccount0(deps.contracts.Escrow.methods.init(
const receipt = await sendTrxAccount0(deps.contracts.EscrowInstance.methods.init(
fallbackArbitrator || main,
deps.contracts.EscrowRelay.options.address,
deps.contracts.ArbitrationLicenseProxy.options.address,
@ -132,13 +131,13 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
{
console.log("Setting the escrow proxy address in UserStore");
const receipt = await sendTrxAccount0(deps.contracts.UserStore.methods.setAllowedContract(deps.contracts.EscrowProxy.options.address, true));
const receipt = await sendTrxAccount0(deps.contracts.UserStore.methods.setAllowedContract(deps.contracts.EscrowInstance.options.address, true));
console.log((receipt.status === true || receipt.status === 1) ? '- Success' : '- FAILURE!!!');
}
{
console.log("Setting the escrow proxy address in OfferStore");
const receipt = await sendTrxAccount0(deps.contracts.OfferStore.methods.setAllowedContract(deps.contracts.EscrowProxy.options.address, true));
const receipt = await sendTrxAccount0(deps.contracts.OfferStore.methods.setAllowedContract(deps.contracts.EscrowInstance.options.address, true));
console.log((receipt.status === true || receipt.status === 1) ? '- Success' : '- FAILURE!!!');
}
@ -158,7 +157,7 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
if(mainnetOwner){
console.log("Setting ownership of 5 proxy");
let receipt;
receipt = await sendTrxAccount0(deps.contracts.Escrow.methods.transferOwnership(mainnetOwner));
receipt = await sendTrxAccount0(deps.contracts.EscrowInstance.methods.transferOwnership(mainnetOwner));
console.log('- 1/5: ' + ((receipt.status === true || receipt.status === 1) ? 'Success' : 'FAILURE!!!'));
receipt = await sendTrxAccount0(deps.contracts.SellerLicense.methods.transferOwnership(mainnetOwner));
console.log('- 2/5: ' + ((receipt.status === true || receipt.status === 1) ? 'Success' : 'FAILURE!!!'));
@ -294,20 +293,20 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
const sendTrxAccount = estimateAndSend(creatorAddress, gasPrice);
receipt = await sendTrxAccount(deps.contracts.Escrow.methods.createEscrow(ethOfferId, val, 140, creatorAddress, CONTACT_DATA, locations[offerStartIndex], usernames[offerStartIndex], nonce, signature));
receipt = await sendTrxAccount(deps.contracts.EscrowInstance.methods.createEscrow(ethOfferId, val, 140, creatorAddress, CONTACT_DATA, locations[offerStartIndex], usernames[offerStartIndex], nonce, signature));
created = receipt.events.Created;
escrowId = created.returnValues.escrowId;
// Fund
receipt = await sendTrxAccount(deps.contracts.Escrow.methods.fund(escrowId), val + feeAmount);
receipt = await sendTrxAccount(deps.contracts.EscrowInstance.methods.fund(escrowId), val + feeAmount);
// Release
receipt = await sendTrxAccount(deps.contracts.Escrow.methods.release(escrowId));
receipt = await sendTrxAccount(deps.contracts.EscrowInstance.methods.release(escrowId));
// Rate
const rating = Math.floor(Math.random() * 5) + 1;
await sendTrxAccount(deps.contracts.Escrow.methods.rateTransaction(escrowId, rating));
await sendTrxAccount(deps.contracts.EscrowInstance.methods.rateTransaction(escrowId, rating));
});
const sendTrxAccountBuyer = estimateAndSend(buyerAddress, gasPrice);
@ -321,19 +320,19 @@ module.exports = async (gasPrice, licensePrice, arbitrationLicensePrice, feeMill
signature = await deps.web3.eth.sign(hash, buyerAddress);
nonce = await deps.contracts.UserStore.methods.user_nonce(buyerAddress).call();
receipt = await sendTrxAccount(deps.contracts.Escrow.methods.createEscrow(ethOfferId, val, 140, creatorAddress, CONTACT_DATA, locations[offerStartIndex], usernames[offerStartIndex], nonce, signature));
receipt = await sendTrxAccount(deps.contracts.EscrowInstance.methods.createEscrow(ethOfferId, val, 140, creatorAddress, CONTACT_DATA, locations[offerStartIndex], usernames[offerStartIndex], nonce, signature));
created = receipt.events.Created;
escrowId = created.returnValues.escrowId;
// Fund
await sendTrxAccount(deps.contracts.Escrow.methods.fund(escrowId), val + feeAmount);
await sendTrxAccount(deps.contracts.EscrowInstance.methods.fund(escrowId), val + feeAmount);
// Buyer pays
await sendTrxAccountBuyer(deps.contracts.Escrow.methods.pay(escrowId));
await sendTrxAccountBuyer(deps.contracts.EscrowInstance.methods.pay(escrowId));
// Open case
await sendTrxAccountBuyer(deps.contracts.Escrow.methods.openCase(escrowId, '1'));
await sendTrxAccountBuyer(deps.contracts.EscrowInstance.methods.openCase(escrowId, '1'));
});
const accounts = await async.mapLimit(addresses, 1, async (address) => {

View File

@ -50,7 +50,7 @@
"address": "0xcc0Ab31133B71852278fE08D3c8F2a25633b6B92"
},
"0xc58eec9e4031117ce12618062f516c0e7fd9df2d54d3d0700b4e6e39f6f51769": {
"name": "EscrowProxy",
"name": "EscrowInstance",
"address": "0x23a6F0bdBd6b5e6DBe5768F3aA68DDC3acF610d8"
},
"0x4248a86e72c9087cc5f5f9ea64e0da7c4275820f70b245cee78977c6c2fa643c": {

View File

@ -74,7 +74,7 @@
"address": "0x727bF4BAed69265bBaFD39f0ab6e508F6fA118a7"
},
"0x3d0b9c682dbbc1027a2e3fd54fc7bd2c6c5a4d95e3da64b40df69ee34dfe4014": {
"name": "EscrowProxy",
"name": "EscrowInstance",
"address": "0xD5baC31a10b8938dd47326f01802fa23f1032AeE"
},
"0xce31be644883d3160b8a3e9adc1caeffd425b268203b19e50c2dc3c950baeddd": {

View File

@ -54,7 +54,7 @@
"address": "0x0ECB5b538EE3edE7b3410956415645d1775eBA24"
},
"0x6f4d89f2b73e5707892da5337423aa937eaf299201a1ca1386de651a911108c1": {
"name": "EscrowProxy",
"name": "EscrowInstance",
"address": "0x42fc1C3Ef2C2bb2d35f4D51c68b17bf6ae35dbC4"
},
"0x576dbedd4c5e11a388fdece1933e740ce695ea212cc82225df9a19693cba3f42": {

View File

@ -22,7 +22,7 @@
"address": "0xb009e41d5c7daC38e02fCDb6ebb97f53ed6A950c"
},
"0x084dcee6b38fbfeacf8371e068678793efc36cf8a9a1d83427e70ef8613852d3": {
"name": "EscrowProxy",
"name": "EscrowInstance",
"address": "0x06Ea1813Aa7CFf6D3eF109Be941C469F0c3e6cc6"
},
"0x33ce98f7b733f04dce6121e52d066acaedb6ca1e83be5ccc73d20391c02537f5": {

View File

@ -1,14 +1,12 @@
import { APPROVE_TOKEN, GET_SNT_ALLOWANCE, GET_TOKEN_ALLOWANCE, CANCEL_APPROVE_TOKEN } from './constants';
import ERC20Token from '../../../embarkArtifacts/contracts/ERC20Token';
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
Escrow.options.address = EscrowProxy.options.address;
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
export const approve = (tokenAddress, amount, tokenDecimals) => {
ERC20Token.options.address = tokenAddress;
return {
type: APPROVE_TOKEN,
toSend: ERC20Token.methods.approve(Escrow.options.address, amount),
toSend: ERC20Token.methods.approve(EscrowInstance.options.address, amount),
amount,
tokenDecimals
};

View File

@ -5,21 +5,19 @@ import {doTransaction} from '../../utils/saga';
import {zeroAddress} from '../../utils/address';
import {toTokenDecimals} from '../../utils/numbers';
import SNT from '../../../embarkArtifacts/contracts/SNT';
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import ERC20Token from '../../../embarkArtifacts/contracts/ERC20Token';
import { APPROVE_TOKEN, APPROVE_PRE_SUCCEEDED, APPROVE_SUCCEEDED, APPROVE_FAILED, GET_SNT_ALLOWANCE, GET_SNT_ALLOWANCE_SUCCEEDED, GET_SNT_ALLOWANCE_FAILED, GET_TOKEN_ALLOWANCE, GET_TOKEN_ALLOWANCE_FAILED, GET_TOKEN_ALLOWANCE_SUCCEEDED } from './constants';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
Escrow.options.address = EscrowProxy.options.address;
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
const {toBN} = web3.utils;
export function *approveToken({amount, tokenDecimals}) {
const feeMilliPercent = yield Escrow.methods.feeMilliPercent().call();
const feeMilliPercent = yield EscrowInstance.methods.feeMilliPercent().call();
const amountWei = toBN(toTokenDecimals(amount, tokenDecimals || 18));
const divider = 100 * (feeMilliPercent / 1000);
const feeAmount = amountWei.div(toBN(divider));
const toSend = ERC20Token.methods.approve(Escrow.options.address, (amountWei.add(feeAmount)).toString());
const toSend = ERC20Token.methods.approve(EscrowInstance.options.address, (amountWei.add(feeAmount)).toString());
yield doTransaction(APPROVE_PRE_SUCCEEDED, APPROVE_SUCCEEDED, APPROVE_FAILED, {toSend});
}
@ -29,9 +27,9 @@ export function *onApproveToken() {
export function *doGetSNTAllowance() {
if(!web3.eth.defaultAccount) return;
try {
const allowance = yield SNT.methods.allowance(web3.eth.defaultAccount, Escrow.options.address).call();
const allowance = yield SNT.methods.allowance(web3.eth.defaultAccount, EscrowInstance.options.address).call();
yield put({type: GET_SNT_ALLOWANCE_SUCCEEDED, allowance});
} catch (error) {
console.error(error);
@ -44,7 +42,7 @@ export function *doGetTokenAllowance({token}) {
try {
ERC20Token.options.address = token;
const allowance = yield ERC20Token.methods.allowance(web3.eth.defaultAccount, Escrow.options.address).call();
const allowance = yield ERC20Token.methods.allowance(web3.eth.defaultAccount, EscrowInstance.options.address).call();
yield put({type: GET_TOKEN_ALLOWANCE_SUCCEEDED, allowance});
} catch (error) {
console.error(error);

View File

@ -24,13 +24,11 @@ import {
GET_FALLBACK_ARBITRATOR,
IS_FALLBACK_ARBITRATOR
} from './constants';
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import ArbitrationLicense from '../../../embarkArtifacts/contracts/ArbitrationLicense';
import ArbitrationLicenseProxy from '../../../embarkArtifacts/contracts/ArbitrationLicenseProxy';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
ArbitrationLicense.options.address = ArbitrationLicenseProxy.options.address;
Escrow.options.address = EscrowProxy.options.address;
export const getDisputedEscrows = (includeFallbackDisputes = null, isArbitrator = false) => ({type: GET_DISPUTED_ESCROWS, includeFallbackDisputes, isArbitrator});
@ -45,13 +43,13 @@ export const resolveDispute = (escrowId, result) => {
type: RESOLVE_DISPUTE,
escrowId,
result,
toSend: Escrow.methods.setArbitrationResult(escrowId, result)
toSend: EscrowInstance.methods.setArbitrationResult(escrowId, result)
};
};
export const openDispute = (escrowId, motive) => ({type: OPEN_DISPUTE, escrowId, toSend: Escrow.methods.openCase(escrowId, motive || '')});
export const openDispute = (escrowId, motive) => ({type: OPEN_DISPUTE, escrowId, toSend: EscrowInstance.methods.openCase(escrowId, motive || '')});
export const cancelDispute = (escrowId) => ({type: CANCEL_DISPUTE, escrowId, toSend: Escrow.methods.cancelArbitration(escrowId)});
export const cancelDispute = (escrowId) => ({type: CANCEL_DISPUTE, escrowId, toSend: EscrowInstance.methods.cancelArbitration(escrowId)});
export const loadArbitration = (escrowId) => {
return {type: LOAD_ARBITRATION, escrowId};

View File

@ -1,6 +1,8 @@
/* global web3, subspace */
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import ArbitrationLicense from '../../../embarkArtifacts/contracts/ArbitrationLicense';
import ArbitrationLicenseProxy from '../../../embarkArtifacts/contracts/ArbitrationLicenseProxy';
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
import OfferStoreProxy from '../../../embarkArtifacts/contracts/OfferStoreProxy';
import SNT from '../../../embarkArtifacts/contracts/SNT';
import GnosisSafe from '../../../embarkArtifacts/contracts/GnosisSafe';
import OfferStore from '../../../embarkArtifacts/contracts/OfferStore';
@ -30,13 +32,9 @@ import {
GET_BLACKLISTED_SELLERS, GET_BLACKLISTED_SELLERS_FAILED, GET_BLACKLISTED_SELLERS_SUCCEEDED, LOAD_ARBITRATOR_SCORES, RESET_ARBITRATOR_SCORES, ADD_ARBITRATOR_SCORE,
IS_FALLBACK_ARBITRATOR, IS_FALLBACK_ARBITRATOR_SUCCEEDED, IS_FALLBACK_ARBITRATOR_FAILED
} from './constants';
import ArbitrationLicenseProxy from '../../../embarkArtifacts/contracts/ArbitrationLicenseProxy';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
import OfferStoreProxy from '../../../embarkArtifacts/contracts/OfferStoreProxy';
OfferStore.options.address = OfferStoreProxy.options.address;
ArbitrationLicense.options.address = ArbitrationLicenseProxy.options.address;
Escrow.options.address = EscrowProxy.options.address;
export function *onResolveDispute() {
yield takeEvery(RESOLVE_DISPUTE, doTransaction.bind(null, RESOLVE_DISPUTE_PRE_SUCCESS, RESOLVE_DISPUTE_SUCCEEDED, RESOLVE_DISPUTE_FAILED));
@ -53,9 +51,9 @@ export function *onCancelDispute() {
export function *doLoadArbitratorScores() {
yield put({type: RESET_ARBITRATOR_SCORES});
const TrackableEscrow = subspace.contract(Escrow);
const TrackableEscrow = subspace.contract(EscrowInstance);
const myArbitration$ = yield TrackableEscrow.events.ArbitrationResolved.track();
const arbChannel = channel();
myArbitration$.subscribe(x => arbChannel.put(x.arbitrator));
@ -95,23 +93,23 @@ export function *doGetEscrows({includeFallbackDisputes, isArbitrator}) {
filter.arbitrator = web3.eth.defaultAccount;
}
const events = yield Escrow.getPastEvents('ArbitrationRequired', {filter, fromBlock: 1});
const events = yield EscrowInstance.getPastEvents('ArbitrationRequired', {filter, fromBlock: 1});
let escrows = [];
for (let i = 0; i < events.length; i++) {
const escrowId = events[i].returnValues.escrowId;
const block = yield web3.eth.getBlock(events[0].blockNumber);
const escrow = yield call(Escrow.methods.transactions(escrowId).call);
const escrow = yield call(EscrowInstance.methods.transactions(escrowId).call);
const offer = yield OfferStore.methods.offers(escrow.offerId).call();
escrow.escrowId = escrowId;
escrow.seller = offer.owner;
escrow.arbitration = yield call(Escrow.methods.arbitrationCases(escrowId).call);
escrow.arbitration = yield call(EscrowInstance.methods.arbitrationCases(escrowId).call);
escrow.arbitration.createDate = moment(block.timestamp * 1000).format("DD.MM.YY");
if(escrow.arbitration.open || escrow.arbitration.result !== 0) {
if(
(includeFallbackDisputes && escrow.arbitration.arbitratorTimeout < (Date.now()/1000)) ||
(includeFallbackDisputes && escrow.arbitration.arbitratorTimeout < (Date.now()/1000)) ||
addressCompare(escrow.arbitrator, web3.eth.defaultAccount) ||
(addressCompare(escrow.buyer, web3.eth.defaultAccount) || addressCompare(escrow.seller, web3.eth.defaultAccount))
){
@ -143,16 +141,16 @@ export function *onGetEscrows() {
export function *doLoadArbitration({escrowId}) {
try {
const escrow = yield call(Escrow.methods.transactions(escrowId).call);
const escrow = yield call(EscrowInstance.methods.transactions(escrowId).call);
const offer = yield OfferStore.methods.offers(escrow.offerId).call();
const events = yield Escrow.getPastEvents('Created', {fromBlock: 1, filter: {escrowId: escrowId} });
const events = yield EscrowInstance.getPastEvents('Created', {fromBlock: 1, filter: {escrowId: escrowId} });
const block = yield web3.eth.getBlock(events[0].blockNumber);
escrow.createDate = moment(block.timestamp * 1000).format("DD.MM.YY");
escrow.escrowId = escrowId;
escrow.seller = offer.owner;
escrow.offer = offer;
escrow.arbitration = yield call(Escrow.methods.arbitrationCases(escrowId).call);
escrow.arbitration = yield call(EscrowInstance.methods.arbitrationCases(escrowId).call);
yield put({type: LOAD_ARBITRATION_SUCCEEDED, escrow});
} catch (error) {
@ -242,7 +240,7 @@ export function *onGetFallbackArbitrator() {
export function *doGetFallbackArbitrator() {
try {
const fallbackArbitrator = yield call(Escrow.methods.fallbackArbitrator().call);
const fallbackArbitrator = yield call(EscrowInstance.methods.fallbackArbitrator().call);
yield put({type: GET_FALLBACK_ARBITRATOR_SUCCEEDED, fallbackArbitrator});
} catch (error) {

View File

@ -1,16 +1,13 @@
/*global web3*/
import {
CREATE_ESCROW, RELEASE_ESCROW, CANCEL_ESCROW,
RATE_TRANSACTION, PAY_ESCROW, OPEN_CASE, OPEN_CASE_SIGNATURE, PAY_ESCROW_SIGNATURE, CLOSE_DIALOG,
ADD_USER_RATING, USER_RATING, GET_ESCROW, FUND_ESCROW, RESET_STATUS,
RATE_TRANSACTION, PAY_ESCROW, OPEN_CASE, GET_ESCROW, FUND_ESCROW, RESET_STATUS,
WATCH_ESCROW, WATCH_ESCROW_CREATIONS, CLEAR_NEW_ESCROW, GET_LAST_ACTIVITY, RESET_CREATE_STATUS,
GET_FEE_MILLI_PERCENT
} from './constants';
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import { toTokenDecimals } from '../../utils/numbers';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
Escrow.options.address = EscrowProxy.options.address;
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
export const createEscrow = (username, tokenAmount, currencyQuantity, contactData, offer) => {
tokenAmount = toTokenDecimals(tokenAmount, offer.token.decimals);
@ -50,19 +47,19 @@ export const fundEscrow = (escrow) => {
}*/
};
export const releaseEscrow = (escrowId) => ({ type: RELEASE_ESCROW, escrowId, toSend: Escrow.methods.release(escrowId) });
export const releaseEscrow = (escrowId) => ({ type: RELEASE_ESCROW, escrowId, toSend: EscrowInstance.methods.release(escrowId) });
export const payEscrow = (escrowId) => ({ type: PAY_ESCROW, escrowId, toSend: Escrow.methods.pay(escrowId) });
export const payEscrow = (escrowId) => ({ type: PAY_ESCROW, escrowId, toSend: EscrowInstance.methods.pay(escrowId) });
export const getEscrow = (escrowId) => ({ type: GET_ESCROW, escrowId });
export const getLastActivity = (address) => ({ type: GET_LAST_ACTIVITY, address});
export const cancelEscrow = (escrowId) => {
return { type: CANCEL_ESCROW, escrowId, toSend: Escrow.methods.cancel(escrowId) };
return { type: CANCEL_ESCROW, escrowId, toSend: EscrowInstance.methods.cancel(escrowId) };
};
export const rateTransaction = (escrowId, rating, ratingSeller) => ({ type: RATE_TRANSACTION, escrowId, rating, ratingSeller, toSend: Escrow.methods.rateTransaction(escrowId, rating) });
export const rateTransaction = (escrowId, rating, ratingSeller) => ({ type: RATE_TRANSACTION, escrowId, rating, ratingSeller, toSend: EscrowInstance.methods.rateTransaction(escrowId, rating) });
export const resetCreateStatus = () => ({type: RESET_CREATE_STATUS});
export const resetStatus = (escrowId) => ({type: RESET_STATUS, escrowId});
@ -75,16 +72,6 @@ export const clearChangedEscrow = () => ({type: CLEAR_NEW_ESCROW});
// TODO: Update with new UI
export const payEscrowSignature = (escrowId) => ({ type: PAY_ESCROW_SIGNATURE, escrowId });
export const openCase = (escrowId) => ({ type: OPEN_CASE, escrowId, toSend: Escrow.methods.openCase(escrowId)});
export const openCaseSignature = (escrowId) => ({ type: OPEN_CASE_SIGNATURE, escrowId });
export const closeDialog = () => ({ type: CLOSE_DIALOG });
export const checkUserRating = (address) => ({ type: USER_RATING, address });
export const addUserRating = () => ({ type: ADD_USER_RATING });
export const openCase = (escrowId) => ({ type: OPEN_CASE, escrowId, toSend: EscrowInstance.methods.openCase(escrowId)});
export const getFeeMilliPercent = () => ({ type: GET_FEE_MILLI_PERCENT });

View File

@ -1,8 +1,10 @@
/*global web3*/
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import OfferStore from '../../../embarkArtifacts/contracts/OfferStore';
import UserStore from '../../../embarkArtifacts/contracts/UserStore';
import EscrowRelay from '../../../embarkArtifacts/contracts/EscrowRelay';
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
import OfferStoreProxy from '../../../embarkArtifacts/contracts/OfferStoreProxy';
import UserStoreProxy from '../../../embarkArtifacts/contracts/UserStoreProxy';
import {fork, takeEvery, call, put, select, all} from 'redux-saga/effects';
import {doTransaction, contractEvent} from '../../utils/saga';
@ -27,19 +29,14 @@ import {
} from './constants';
import {eventTypes} from './helpers';
import {ADD_OFFER_SUCCEEDED, LOAD_USER} from "../metadata/constants";
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
import OfferStoreProxy from '../../../embarkArtifacts/contracts/OfferStoreProxy';
import UserStoreProxy from '../../../embarkArtifacts/contracts/UserStoreProxy';
OfferStore.options.address = OfferStoreProxy.options.address;
UserStore.options.address = UserStoreProxy.options.address;
Escrow.options.address = EscrowProxy.options.address;
const { toBN } = web3.utils;
export function *createEscrow({user, escrow}) {
const toSend = Escrow.methods.createEscrow(
const toSend = EscrowInstance.methods.createEscrow(
escrow.offerId,
escrow.tokenAmount,
escrow.currencyQuantity,
@ -65,12 +62,12 @@ export function *onPayEscrow() {
}
export function *fundEscrow({value, escrowId, token}) {
const feeMilliPercent = yield Escrow.methods.feeMilliPercent().call();
const feeMilliPercent = yield EscrowInstance.methods.feeMilliPercent().call();
const divider = 100 * (feeMilliPercent / 1000);
const feeAmount = toBN(value).div(toBN(divider));
const totalAmount = toBN(value).add(feeAmount);
const toSend = Escrow.methods.fund(escrowId);
const toSend = EscrowInstance.methods.fund(escrowId);
yield doTransaction(FUND_ESCROW_PRE_SUCCESS, FUND_ESCROW_SUCCEEDED, FUND_ESCROW_FAILED, {
value: (token !== zeroAddress) ? '0' : totalAmount.toString(),
@ -85,7 +82,7 @@ export function *onFundEscrow() {
export function *payEscrowSignature({escrowId}) {
try {
const messageHash = yield call(Escrow.methods.paySignHash(escrowId).call, {from: web3.eth.defaultAccount});
const messageHash = yield call(EscrowInstance.methods.paySignHash(escrowId).call, {from: web3.eth.defaultAccount});
const signedMessage = yield call(web3.eth.personal.sign, messageHash, web3.eth.defaultAccount);
yield put({type: PAY_ESCROW_SIGNATURE_SUCCEEDED, escrowId, signedMessage, signatureType: SIGNATURE_PAYMENT});
} catch (error) {
@ -100,7 +97,7 @@ export function *onPayEscrowSignature() {
export function *openCaseSignature({escrowId}) {
try {
const messageHash = yield call(Escrow.methods.openCaseSignHash(escrowId).call, {from: web3.eth.defaultAccount});
const messageHash = yield call(EscrowInstance.methods.openCaseSignHash(escrowId).call, {from: web3.eth.defaultAccount});
const signedMessage = yield call(web3.eth.personal.sign, messageHash, web3.eth.defaultAccount);
yield put({type: OPEN_CASE_SIGNATURE_SUCCEEDED, escrowId, signedMessage, signatureType: SIGNATURE_OPEN_CASE});
} catch (error) {
@ -155,10 +152,10 @@ export function *onRateTx() {
function *formatEscrows(escrowIds) {
const escrows = [];
for (let i = 0; i < escrowIds.length; i++) {
const escrow = yield call(Escrow.methods.transactions(escrowIds[i]).call);
const escrow = yield call(EscrowInstance.methods.transactions(escrowIds[i]).call);
escrow.escrowId = escrowIds[i];
if (escrow.paid) {
const arbitration = yield call(Escrow.methods.arbitrationCases(escrowIds[i]).call);
const arbitration = yield call(EscrowInstance.methods.arbitrationCases(escrowIds[i]).call);
if (arbitration.open) {
escrow.arbitration = arbitration;
}
@ -176,8 +173,8 @@ export function *doLoadEscrows({address}) {
throw new Error('No address yet. Wallet is not accessible yet');
}
const eventsAsBuyer = yield Escrow.getPastEvents('Created', {filter: {buyer: address}, fromBlock: 1});
const eventsAsSeller = yield Escrow.getPastEvents('Created', {filter: {seller: address}, fromBlock: 1});
const eventsAsBuyer = yield EscrowInstance.getPastEvents('Created', {filter: {buyer: address}, fromBlock: 1});
const eventsAsSeller = yield EscrowInstance.getPastEvents('Created', {filter: {seller: address}, fromBlock: 1});
const events = eventsAsBuyer.map(x => {
x.isBuyer = true;
@ -188,7 +185,7 @@ export function *doLoadEscrows({address}) {
}));
const escrows = yield all(events.map(function *(ev) {
const escrow = yield Escrow.methods.transactions(ev.returnValues.escrowId).call({from: defaultAccount});
const escrow = yield EscrowInstance.methods.transactions(ev.returnValues.escrowId).call({from: defaultAccount});
escrow.escrowId = ev.returnValues.escrowId;
escrow.offer = yield OfferStore.methods.offer(escrow.offerId).call({from: defaultAccount});
escrow.currency = escrow.offer.currency;
@ -230,7 +227,7 @@ export function *onLoadEscrows() {
export function *doGetEscrow({escrowId}) {
try {
const defaultAccount = web3.eth.defaultAccount || zeroAddress;
const escrow = yield Escrow.methods.transactions(escrowId).call({from: defaultAccount});
const escrow = yield EscrowInstance.methods.transactions(escrowId).call({from: defaultAccount});
escrow.escrowId = escrowId;
escrow.offer = yield OfferStore.methods.offer(escrow.offerId).call({from: defaultAccount});
escrow.seller = yield UserStore.methods.users(escrow.offer.owner).call({from: defaultAccount});
@ -249,7 +246,7 @@ export function *onGetEscrow() {
export function *doGetFeeMilliPercent() {
try {
const defaultAccount = web3.eth.defaultAccount || zeroAddress;
const feeMilliPercent = yield Escrow.methods.feeMilliPercent().call({from: defaultAccount});
const feeMilliPercent = yield EscrowInstance.methods.feeMilliPercent().call({from: defaultAccount});
yield put({type: GET_FEE_MILLI_PERCENT_SUCCEEDED, feeMilliPercent});
} catch (error) {
console.error(error);
@ -284,7 +281,7 @@ export function *checkUserRating({address}) {
}
const allEvents = yield all(offers.map(async (offer) => {
return Escrow.getPastEvents('Rating', {fromBlock: 1, filter: {offerId: offer.id}});
return EscrowInstance.getPastEvents('Rating', {fromBlock: 1, filter: {offerId: offer.id}});
}));
const ratings = [];
@ -355,10 +352,10 @@ export function *onGetLastActivity() {
export function *watchEscrow({escrowId}) {
try {
yield all([
contractEvent(Escrow, eventTypes.funded, {escrowId}, ESCROW_EVENT_RECEIVED),
contractEvent(Escrow, eventTypes.paid, {escrowId}, ESCROW_EVENT_RECEIVED),
contractEvent(Escrow, eventTypes.released, {escrowId}, ESCROW_EVENT_RECEIVED),
contractEvent(Escrow, eventTypes.canceled, {escrowId}, ESCROW_EVENT_RECEIVED)
contractEvent(EscrowInstance, eventTypes.funded, {escrowId}, ESCROW_EVENT_RECEIVED),
contractEvent(EscrowInstance, eventTypes.paid, {escrowId}, ESCROW_EVENT_RECEIVED),
contractEvent(EscrowInstance, eventTypes.released, {escrowId}, ESCROW_EVENT_RECEIVED),
contractEvent(EscrowInstance, eventTypes.canceled, {escrowId}, ESCROW_EVENT_RECEIVED)
]);
} catch (error) {
console.error(error);
@ -371,7 +368,7 @@ export function *onWatchEscrow() {
export function *watchEscrowCreations({offers}) {
try {
yield all(offers.map(offer => contractEvent(Escrow, eventTypes.created, {offerId: offer.id}, ESCROW_CREATED_EVENT_RECEIVED, true)));
yield all(offers.map(offer => contractEvent(EscrowInstance, eventTypes.created, {offerId: offer.id}, ESCROW_CREATED_EVENT_RECEIVED, true)));
} catch (error) {
console.error(error);
}

View File

@ -3,7 +3,7 @@ import OfferStore from '../../../embarkArtifacts/contracts/OfferStore';
import UserStore from '../../../embarkArtifacts/contracts/UserStore';
import ArbitrationLicense from '../../../embarkArtifacts/contracts/ArbitrationLicense';
import SellerLicense from '../../../embarkArtifacts/contracts/SellerLicense';
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
import {eventChannel} from 'redux-saga';
import {fork, takeEvery, put, all, call, select, take} from 'redux-saga/effects';
import {
@ -44,7 +44,6 @@ import {
import {USER_RATING, LOAD_ESCROWS} from '../escrow/constants';
import {doTransaction} from '../../utils/saga';
import {getLocation} from '../../services/googleMap';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
import { zeroAddress, addressCompare } from '../../utils/address';
import {getContactData} from '../../utils/strings';
import SellerLicenseProxy from '../../../embarkArtifacts/contracts/SellerLicenseProxy';
@ -58,7 +57,6 @@ OfferStore.options.address = OfferStoreProxy.options.address;
UserStore.options.address = UserStoreProxy.options.address;
ArbitrationLicense.options.address = ArbitrationLicenseProxy.options.address;
SellerLicense.options.address = SellerLicenseProxy.options.address;
Escrow.options.address = EscrowProxy.options.address;
export function *loadUser({address}) {
if(!address) return;
@ -181,7 +179,7 @@ export function *loadOffers({address}) {
let allReleased;
let releasedEscrows;
if (!address) {
allReleased = yield Escrow.getPastEvents('Released', {fromBlock: 1});
allReleased = yield EscrowInstance.getPastEvents('Released', {fromBlock: 1});
releasedEscrows = allReleased.map(e => e.returnValues.escrowId);
}
@ -206,7 +204,7 @@ export function *loadOffers({address}) {
}
// Get all escrows of that offer
const createdTrades = yield Escrow.getPastEvents('Created', {filter: {offerId: id}, fromBlock: 1});
const createdTrades = yield EscrowInstance.getPastEvents('Created', {filter: {offerId: id}, fromBlock: 1});
let nbReleasedTrades = 0;
createdTrades.forEach(tradeEvent => {
if (releasedEscrows.includes(tradeEvent.returnValues.escrowId)) {

View File

@ -1,7 +1,5 @@
import Escrow from '../../../embarkArtifacts/contracts/Escrow';
import {INCLUDE_SIGNATURE, SIGNATURE_OPEN_CASE, SIGNATURE_PAYMENT} from './constants';
import EscrowProxy from '../../../embarkArtifacts/contracts/EscrowProxy';
Escrow.options.address = EscrowProxy.options.address;
import EscrowInstance from '../../../embarkArtifacts/contracts/EscrowInstance';
export const includeSignature = ({type, escrowId, message}) => {
let method;
@ -15,5 +13,5 @@ export const includeSignature = ({type, escrowId, message}) => {
default:
throw new Error("Invalid signature type");
}
return { type: INCLUDE_SIGNATURE, toSend: Escrow.methods[method](escrowId, message) };
return { type: INCLUDE_SIGNATURE, toSend: EscrowInstance.methods[method](escrowId, message) };
};

View File

@ -5,13 +5,12 @@ import {Link} from "react-router-dom";
import Reputation from '../../../components/Reputation';
import Identicon from "../../../components/UserInformation/Identicon";
import classnames from 'classnames';
import EscrowProxy from '../../../../embarkArtifacts/contracts/EscrowProxy';
import Escrow from '../../../../embarkArtifacts/contracts/Escrow';
import EscrowInstance from '../../../../embarkArtifacts/contracts/EscrowInstance';
import {ARBITRATION_SOLVED_BUYER, ARBITRATION_SOLVED_SELLER} from "../../../features/arbitration/constants";
import {copyToClipboard } from '../../../utils/strings';
const TradeParticipant = ({profile, escrowId, address, isBuyer, winner, multisigInfo = false}) => {
const data = escrowId ? Escrow.methods.setArbitrationResult(escrowId, isBuyer ? ARBITRATION_SOLVED_BUYER : ARBITRATION_SOLVED_SELLER).encodeABI() : '';
const data = escrowId ? EscrowInstance.methods.setArbitrationResult(escrowId, isBuyer ? ARBITRATION_SOLVED_BUYER : ARBITRATION_SOLVED_SELLER).encodeABI() : '';
return <Row className="border bg-white rounded p-2 mr-0 ml-0 mb-2" >
<Col className="p-0" >
<Row tag={Link} to={`/profile/` + address}>
@ -34,7 +33,7 @@ const TradeParticipant = ({profile, escrowId, address, isBuyer, winner, multisig
<Col>
To select the {isBuyer ? 'buyer' : 'seller'} as the winner of the dispute, create a custom transaction in the multisig wallet with the following parameters (click to copy):
<ul className="p-3 text-small overflow-auto">
<li>Recipient: <span className="font-weight-bold clickable" onClick={() => copyToClipboard(EscrowProxy.options.address)}>{EscrowProxy.options.address}</span></li>
<li>Recipient: <span className="font-weight-bold clickable" onClick={() => copyToClipboard(EscrowInstance.options.address)}>{EscrowInstance.options.address}</span></li>
<li>Value: <span className="font-weight-bold clickable" onClick={() => copyToClipboard('0')}>0</span></li>
<li>Data (hex encoded): <span className="font-weight-bold clickable" onClick={() => copyToClipboard(data)}>{data}</span></li>
</ul>

View File

@ -9,7 +9,7 @@ import {PAYMENT_METHODS} from '../../../features/metadata/constants';
import PriceWarning from '../../../components/PriceWarning';
import Address from '../../../components/UserInformation/Address';
import {withTranslation} from "react-i18next";
import EscrowProxy from '../../../../embarkArtifacts/contracts/EscrowProxy';
import EscrowInstance from '../../../../embarkArtifacts/contracts/EscrowInstance';
import {tradeStates} from "../../../features/escrow/helpers";
import classnames from 'classnames';
import RoundedIcon from "../../../ui/RoundedIcon";
@ -49,10 +49,10 @@ const EscrowDetail = ({t, escrow, currentPrice, isBuyer, arbitrationDetails, onC
<h3 className="font-weight-normal mt-4">{t('escrow.detail.contract')}</h3>
<p className="font-weight-medium mb-0 text-break">
{EscrowProxy.options.address}
{EscrowInstance.options.address}
</p>
<span className="mb-1">
<a href={"https://etherscan.io/address/" + EscrowProxy.options.address} target="_blank"
<a href={"https://etherscan.io/address/" + EscrowInstance.options.address} target="_blank"
rel="noopener noreferrer">{t('escrow.detail.viewEtherscan')} </a>
</span>

View File

@ -1,7 +1,6 @@
/* global web3 */
import Escrow from '../embarkArtifacts/contracts/Escrow';
import EscrowRelay from '../embarkArtifacts/contracts/EscrowRelay';
import EscrowProxy from '../embarkArtifacts/contracts/EscrowProxy';
import EscrowInstance from '../embarkArtifacts/contracts/EscrowInstance';
import OfferStore from '../embarkArtifacts/contracts/OfferStore';
import OfferStoreProxy from '../embarkArtifacts/contracts/OfferStoreProxy';
import SNT from '../embarkArtifacts/contracts/SNT';
@ -10,7 +9,6 @@ import {addressCompare, zeroAddress} from './utils/address';
import {canRelay} from './features/escrow/helpers';
import stripHexPrefix from 'strip-hex-prefix';
Escrow.options.address = EscrowProxy.options.address;
OfferStore.options.address = OfferStoreProxy.options.address;
const CREATE_ESCROW = "createEscrow(uint256,uint256,uint256,address,string,string,string)";
@ -33,7 +31,7 @@ class Provider {
if(!data || data.length < 74) return false;
const offerId = web3.utils.hexToNumber('0x' + data.substr(10, 64));
const offer = await OfferStore.methods.offers(offerId).call();
return addressCompare(offer.asset, SNT.options.address) || addressCompare(offer.asset, zeroAddress);
return addressCompare(offer.asset, SNT.options.address) || addressCompare(offer.asset, zeroAddress);
}
startProvider(web3) {
@ -46,7 +44,7 @@ class Provider {
const params = payload.params[0];
const operation = params && params.data ? params.data.substring(2, 10) : "0x";
if (!(params && params.to && addressCompare(params.to, Escrow.options.address) &&
if (!(params && params.to && addressCompare(params.to, EscrowInstance.options.address) &&
payload.method === "eth_sendTransaction" &&
Object.values(VALID_OPERATIONS).includes(operation))) {
this.origProviderSend(payload, callback);
@ -76,7 +74,7 @@ class Provider {
payload.params[0].to = EscrowRelay.options.address;
payload.params[0].gas = web3.utils.fromDecimal(web3.utils.toDecimal(payload.params[0].gas) + 100000);
this.relayProviderSend(payload, (error, result) => {
callback(error, result);
});
@ -85,7 +83,7 @@ class Provider {
}
})();
};
this.origProvider.send = fSend;
this.origProvider.sendAsync = fSend;
}

View File

@ -1,8 +1,7 @@
/*global contract, config, it, assert, web3, before, describe, beforeEach*/
const TestUtils = require("../utils/testUtils");
const Escrow = require('Embark/contracts/Escrow');
const EscrowInstance = require('Embark/contracts/EscrowInstance');
const EscrowRelay = require('Embark/contracts/EscrowRelay');
const Proxy = require('Embark/contracts/Proxy');
const ArbitrationLicense = require('Embark/contracts/ArbitrationLicense');
const SNT = require('Embark/contracts/SNT');
const UserStore = require('Embark/contracts/UserStore');
@ -63,7 +62,15 @@ config({
},
*/
Escrow: {
args: ["$accounts[0]", "0x0000000000000000000000000000000000000002", "$ArbitrationLicense", "$OfferStore", "$UserStore", BURN_ADDRESS, 1000]
},
Proxy: {
deploy: false
},
EscrowInstance: {
instanceOf: "Proxy",
proxyFor: "Escrow",
args: ["0x", "$Escrow"]
},
@ -71,9 +78,6 @@ config({
args: ["$OfferStore", "$Proxy", "$SNT"]
},
Escrow: {
args: ["$accounts[0]", "0x0000000000000000000000000000000000000002", "$ArbitrationLicense", "$OfferStore", "$UserStore", BURN_ADDRESS, 1000]
},
TestEscrowUpgrade: {
args: ["$accounts[0]", "0x0000000000000000000000000000000000000002", "$ArbitrationLicense", "$OfferStore", "$UserStore", BURN_ADDRESS, 1000]
},
@ -91,12 +95,10 @@ contract("Escrow", function() {
describe("Upgradeable Escrows", async () => {
before(async () => {
Escrow.options.address = Proxy.options.address;
await UserStore.methods.setAllowedContract(Escrow.options.address, true).send();
await UserStore.methods.setAllowedContract(EscrowInstance.options.address, true).send();
await UserStore.methods.setAllowedContract(EscrowRelay.options.address, true).send();
await OfferStore.methods.setAllowedContract(Escrow.options.address, true).send();
await OfferStore.methods.setAllowedContract(EscrowInstance.options.address, true).send();
await OfferStore.methods.setAllowedContract(EscrowRelay.options.address, true).send();
@ -114,7 +116,7 @@ contract("Escrow", function() {
it("Can create initial escrow version", async () => {
// Here we are setting the initial "template" by calling the init() function
Escrow.methods.init(
EscrowInstance.methods.init(
accounts[0],
EscrowRelay.options.address,
ArbitrationLicense.options.address,
@ -127,7 +129,7 @@ contract("Escrow", function() {
});
it("Can create an escrow", async () => {
receipt = await Escrow.methods.createEscrow(ethOfferId, 123, 140, accounts[1], CONTACT_DATA, "L", "U").send({from: accounts[1]});
receipt = await EscrowInstance.methods.createEscrow(ethOfferId, 123, 140, accounts[1], CONTACT_DATA, "L", "U").send({from: accounts[1]});
const created = receipt.events.Created;
assert(!!created, "Created() not triggered");
assert.strictEqual(created.returnValues.offerId, ethOfferId, "Invalid offerId");
@ -139,7 +141,7 @@ contract("Escrow", function() {
const signature = await web3.eth.sign(hash, accounts[1]);
const nonce = await UserStore.methods.user_nonce(accounts[1]).call();
receipt = await Escrow.methods.createEscrow(ethOfferId, 123, 140, accounts[1], CONTACT_DATA, "L", "U", nonce, signature).send({from: accounts[1]});
receipt = await EscrowInstance.methods.createEscrow(ethOfferId, 123, 140, accounts[1], CONTACT_DATA, "L", "U", nonce, signature).send({from: accounts[1]});
const created = receipt.events.Created;
assert(!!created, "Created() not triggered");
assert.strictEqual(created.returnValues.offerId, ethOfferId, "Invalid offerId");
@ -147,8 +149,8 @@ contract("Escrow", function() {
});
it("Can upgrade contract", async () => {
receipt = await Escrow.methods.updateCode(TestEscrowUpgrade.options.address).send();
TestEscrowUpgrade.options.address = Escrow.options.address;
receipt = await EscrowInstance.methods.updateCode(TestEscrowUpgrade.options.address).send();
TestEscrowUpgrade.options.address = EscrowInstance.options.address;
});
it("Can call new contract functions", async () => {