From 51b0a2471a34f8f2fa97ccbd3d841d28bc44476c Mon Sep 17 00:00:00 2001 From: Tyler Sorensen Date: Thu, 15 Apr 2021 16:22:37 -1000 Subject: [PATCH] add getTail(), switch to ethers contracts --- .../contracts/abis/Clipper.json | 3 +- .../contracts/abis/Dog.json | 9 ++++-- .../src/LiquidationService.js | 32 +++++++------------ .../test/LiquidationService.test.js | 19 +++++++---- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/packages/dai-plugin-liquidations/contracts/abis/Clipper.json b/packages/dai-plugin-liquidations/contracts/abis/Clipper.json index 8866fb72e..fe73d53d4 100644 --- a/packages/dai-plugin-liquidations/contracts/abis/Clipper.json +++ b/packages/dai-plugin-liquidations/contracts/abis/Clipper.json @@ -426,7 +426,8 @@ "name": "tail", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", - "type": "function" + "type": "function", + "constant":true }, { "constant": false, diff --git a/packages/dai-plugin-liquidations/contracts/abis/Dog.json b/packages/dai-plugin-liquidations/contracts/abis/Dog.json index 10f796d25..898cf7680 100644 --- a/packages/dai-plugin-liquidations/contracts/abis/Dog.json +++ b/packages/dai-plugin-liquidations/contracts/abis/Dog.json @@ -194,14 +194,16 @@ "name": "Dirt", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", - "type": "function" + "type": "function", + "constant":true }, { "inputs": [], "name": "Hole", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", - "type": "function" + "type": "function", + "constant":true }, { "inputs": [ @@ -298,7 +300,8 @@ { "internalType": "uint256", "name": "dirt", "type": "uint256" } ], "stateMutability": "view", - "type": "function" + "type": "function", + "constant":true }, { "inputs": [], diff --git a/packages/dai-plugin-liquidations/src/LiquidationService.js b/packages/dai-plugin-liquidations/src/LiquidationService.js index 384481b4e..289202ec6 100644 --- a/packages/dai-plugin-liquidations/src/LiquidationService.js +++ b/packages/dai-plugin-liquidations/src/LiquidationService.js @@ -247,9 +247,8 @@ export default class LiquidationService extends PublicService { } async getHoleAndDirtForIlk(ilk) { - const data = await this._dogContractWeb3() - .methods.ilks(stringToBytes(ilk)) - .call({ from: this.get('web3').currentAddress() }); + const data = await this._dogContract() + .ilks(stringToBytes(ilk)); const hole = new BigNumber(data.hole).div(RAD); const dirt = new BigNumber(data.dirt).div(RAD); const diff = hole.minus(dirt); @@ -258,12 +257,8 @@ export default class LiquidationService extends PublicService { async getHoleAndDirt() { const [h, d] = await Promise.all([ - this._dogContractWeb3() - .methods.Hole() - .call({ from: this.get('web3').currentAddress() }), - this._dogContractWeb3() - .methods.Dirt() - .call({ from: this.get('web3').currentAddress() }) + this._dogContract().Hole(), + this._dogContract().Dirt() ]); const hole = new BigNumber(h).div(RAD); const dirt = new BigNumber(d).div(RAD); @@ -271,13 +266,16 @@ export default class LiquidationService extends PublicService { return { hole, dirt, diff }; } - async getChost() { - const chost = await this._clipperContractWeb3() - .methods.chost() - .call({ from: this.get('web3').currentAddress() }); + async getChost(ilk) { + const chost = await this._clipperContractByIlk(ilk).chost(); return new BigNumber(chost).div(RAD); } + async getTail(ilk) { + const tail = await this._clipperContractByIlk(ilk).tail(); + return tail.toNumber(); + } + @tracksTransactions async yank(id, { promise }) { return await this._clipperContract().yank(id, { promise }); @@ -322,14 +320,6 @@ export default class LiquidationService extends PublicService { return this.get('smartContract').getContractByName(`MCD_CLIP_${suffix}`); } - _clipperContractWeb3() { - return this.get('smartContract').getWeb3ContractByName('MCD_CLIP_LINK_A'); - } - - _dogContractWeb3() { - return this.get('smartContract').getWeb3ContractByName('MCD_DOG'); - } - _dogContract() { return this.get('smartContract').getContractByName('MCD_DOG'); } diff --git a/packages/dai-plugin-liquidations/test/LiquidationService.test.js b/packages/dai-plugin-liquidations/test/LiquidationService.test.js index 2d131fb5a..965889c87 100644 --- a/packages/dai-plugin-liquidations/test/LiquidationService.test.js +++ b/packages/dai-plugin-liquidations/test/LiquidationService.test.js @@ -171,17 +171,22 @@ test('get price for LINK-A', async () => { console.log('price', price); }, 10000); -test('getHoleAndDirtForIlk', async () => { - const data = await service.getHoleAndDirtForIlk('LINK-A'); - console.log('data', data); +test('getHoleAndDirtForIlk for LINK-A', async () => { + const holeAndDirt = await service.getHoleAndDirtForIlk('LINK-A'); + console.log('data', holeAndDirt); }, 10000); test('getHoleAndDirt', async () => { - const data = await service.getHoleAndDirt(); - console.log('data', data); + const holeAndDirt = await service.getHoleAndDirt(); + console.log('data', holeAndDirt); }, 10000); xtest('getChost', async () => { - const chost = await service.getChost(); - console.log('data', chost); + const chost = await service.getChost('LINK-A'); + console.log('chost', chost); +}, 10000); + +test('getTail', async () => { + const tail = await service.getTail('LINK-A'); + console.log('tail', tail); }, 10000);