Skip to content

Commit

Permalink
Merge pull request #33 from FinBook/live&dev
Browse files Browse the repository at this point in the history
update
  • Loading branch information
yizhoucao committed Mar 6, 2019
2 parents 34e4915 + 479d18e commit 4c1dde1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 71 deletions.
117 changes: 49 additions & 68 deletions src/services/ContractService.ts
Expand Up @@ -30,28 +30,32 @@ export default class ContractService {
public createDuoWrappers(): {
[type: string]: { [tenor: string]: DualClassWrapper | VivaldiWrapper };
} {
return {
Beethoven: {
Perpetual: new DualClassWrapper(
this.web3Wrapper,
this.web3Wrapper.contractAddresses.Custodians.Beethoven.Perpetual.custodian.address
)
},
Mozart: {
Perpetual: new DualClassWrapper(
this.web3Wrapper,
this.web3Wrapper.contractAddresses.Custodians.Mozart.Perpetual.custodian.address
)
}
// ,Vivaldi: {
// '100C-3H': new VivaldiWrapper(
// this.web3Wrapper,
// this.web3Wrapper.contractAddresses.Custodians.Vivaldi[
// '100C-3H'
// ].custodian.address
// )
// }
};
const duoWrappers: {
[type: string]: { [tenor: string]: DualClassWrapper | VivaldiWrapper };
} = {};
const custodianAddrs = this.web3Wrapper.contractAddresses.Custodians;
for (const contractType in custodianAddrs)
if (!util.isEmptyObject(custodianAddrs[contractType]))
for (const tenor in custodianAddrs[contractType])
Object.assign(duoWrappers, {
[contractType]: {
[tenor]:
contractType === WrapperConstants.VIVALDI
? new VivaldiWrapper(
this.web3Wrapper,
this.web3Wrapper.contractAddresses.Custodians[
contractType
][tenor].custodian.address
)
: new DualClassWrapper(
this.web3Wrapper,
this.web3Wrapper.contractAddresses.Custodians[
contractType
][tenor].custodian.address
)
}
});
return duoWrappers;
}

public createMagiWrapper() {
Expand Down Expand Up @@ -80,21 +84,11 @@ export default class ContractService {
public async trigger() {
await this.fetchKey();
const duoWrappers = this.createDuoWrappers();
const VivaldiWrappers: VivaldiWrapper[] = [];
for (const tenor in duoWrappers.Vivaldi)
VivaldiWrappers.push(duoWrappers.Vivaldi[tenor] as VivaldiWrapper);
const DualWrappers = [];
for (const type in duoWrappers)
for (const tenor in duoWrappers[type]) DualWrappers.push(duoWrappers[type][tenor]);

eventUtil.trigger(
this.address,
[
duoWrappers.Beethoven.Perpetual as DualClassWrapper,
// duoWrappers.Beethoven.M19 as DualClassWrapper,
duoWrappers.Mozart.Perpetual as DualClassWrapper,
// duoWrappers.Mozart.M19 as DualClassWrapper,
...VivaldiWrappers
],
this.option.event
);
eventUtil.trigger(this.address, DualWrappers, this.option.event);
}

public async commitPrice() {
Expand All @@ -106,18 +100,15 @@ export default class ContractService {

public async fetchPrice() {
await this.fetchKey();
const dualClassCustodianWrappers = this.createDuoWrappers();
const duoWrappers = this.createDuoWrappers();
const magiWrapper = this.createMagiWrapper();
priceUtil.fetchPrice(
this.address,
[
dualClassCustodianWrappers.Beethoven.Perpetual as DualClassWrapper,
// dualClassCustodianWrappers.Beethoven.M19 as DualClassWrapper,
dualClassCustodianWrappers.Mozart.Perpetual as DualClassWrapper
// dualClassCustodianWrappers.Mozart.M19 as DualClassWrapper
],
magiWrapper
);
const DualWrappers: DualClassWrapper[] = [];
for (const type in duoWrappers)
if (type !== WrapperConstants.VIVALDI)
for (const tenor in duoWrappers[type])
DualWrappers.push(duoWrappers[type][tenor] as DualClassWrapper);

priceUtil.fetchPrice(this.address, DualWrappers, magiWrapper);
global.setInterval(() => dbUtil.insertHeartbeat(), 30000);
}

Expand Down Expand Up @@ -195,7 +186,9 @@ export default class ContractService {
}
};
try {
kovanManagerAccount = require('../static/kovanManagerAccount.json');
kovanManagerAccount = require(`../static/${
option.live ? 'live' : 'kovan'
}ManagerAccount.json`);
} catch (error) {
console.log(error);
}
Expand All @@ -208,17 +201,15 @@ export default class ContractService {
const account = kovanManagerAccount.Beethoven.operator.address;
const type = this.option.contractType;
const tenor = this.option.tenor;

if (
![
WrapperConstants.BEETHOVEN,
WrapperConstants.MOZART,
WrapperConstants.VIVALDI
].includes(type) ||
![WrapperConstants.TENOR_PPT].includes(tenor)
!this.web3Wrapper.contractAddresses.Custodians[type] ||
!this.web3Wrapper.contractAddresses.Custodians[type][tenor]
) {
util.logDebug('no contract type or tenor specified');
return;
}

const custodianContract = this.createDuoWrappers();
const contractWrapper: DualClassWrapper | VivaldiWrapper = custodianContract[type][tenor];
if (option.contractType === WrapperConstants.VIVALDI) {
Expand Down Expand Up @@ -249,20 +240,10 @@ export default class ContractService {
const duoWrappers = this.createDuoWrappers();
const magiWrapper = this.createMagiWrapper();
const esplanadeWrapper = this.createEsplanadeWrapper();
const VivaldiWrappers = [];
for (const tenor in duoWrappers.Vivaldi) VivaldiWrappers.push(duoWrappers.Vivaldi[tenor]);

eventUtil.fetch(
[
duoWrappers.Beethoven.Perpetual,
// duoWrappers.Beethoven.M19,
duoWrappers.Mozart.Perpetual,
// duoWrappers.Mozart.M19,
magiWrapper,
esplanadeWrapper,
...VivaldiWrappers
],
this.option.force
);
const DualWrappers = [];
for (const type in duoWrappers)
for (const tenor in duoWrappers[type]) DualWrappers.push(duoWrappers[type][tenor]);
eventUtil.fetch([magiWrapper, esplanadeWrapper, ...DualWrappers], this.option.force);
}
}
26 changes: 23 additions & 3 deletions src/services/__snapshots__/ContractService.test.ts.snap
Expand Up @@ -71,6 +71,11 @@ Object {
"contract": "dualClassWrapper",
},
},
"Vivaldi": Object {
"100C-3H": Object {
"contract": "VivaldiWrapper",
},
},
}
`;

Expand Down Expand Up @@ -409,14 +414,14 @@ exports[`fetchEvent 1`] = `
Array [
Array [
Array [
"BTV-PPT",
"MZT-PPT",
Object {
"contract": "MagiWrapper",
},
Object {
"contract": "EsplanadeWrapper",
},
"BTV-PPT",
"MZT-PPT",
"VVD-tenor",
],
false,
Expand Down Expand Up @@ -518,7 +523,19 @@ Array [
]
`;

exports[`startCustodian, vivaldi 1`] = `Array []`;
exports[`startCustodian, vivaldi 1`] = `
Array [
Array [
"account",
"0x2C4bD22588af822a95Fb9D7e972A1F1C4aE28F13",
"0x9f49bb024EB176d227d4b85A58730a5dDeEF529D",
"0x0d729B3C11b3E6Bf5792d36f640f3Be6f187Dd67",
1,
true,
true,
],
]
`;

exports[`trigger 1`] = `
Array [
Expand All @@ -531,6 +548,9 @@ Array [
Object {
"contract": "dualClassWrapper",
},
Object {
"contract": "VivaldiWrapper",
},
],
"event",
],
Expand Down

0 comments on commit 4c1dde1

Please sign in to comment.