Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
add getTail(), switch to ethers contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler17 committed Apr 16, 2021
1 parent 68d2239 commit 51b0a24
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
3 changes: 2 additions & 1 deletion packages/dai-plugin-liquidations/contracts/abis/Clipper.json
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@
"name": "tail",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
"type": "function",
"constant":true
},
{
"constant": false,
Expand Down
9 changes: 6 additions & 3 deletions packages/dai-plugin-liquidations/contracts/abis/Dog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -298,7 +300,8 @@
{ "internalType": "uint256", "name": "dirt", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
"type": "function",
"constant":true
},
{
"inputs": [],
Expand Down
32 changes: 11 additions & 21 deletions packages/dai-plugin-liquidations/src/LiquidationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -258,26 +257,25 @@ 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);
const diff = hole.minus(dirt);
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 });
Expand Down Expand Up @@ -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');
}
Expand Down
19 changes: 12 additions & 7 deletions packages/dai-plugin-liquidations/test/LiquidationService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 51b0a24

Please sign in to comment.