diff --git a/packages/dai-plugin-migrations/package.json b/packages/dai-plugin-migrations/package.json index 690eb74f5..845554c12 100644 --- a/packages/dai-plugin-migrations/package.json +++ b/packages/dai-plugin-migrations/package.json @@ -1,7 +1,7 @@ { "name": "@makerdao/dai-plugin-migrations", "description": "Plugin to add migrations to dai.js", - "version": "1.3.4", + "version": "1.3.8", "license": "MIT", "main": "dist/index.js", "unpkg": "umd/index.js", diff --git a/packages/dai-plugin-migrations/src/MigrationService.js b/packages/dai-plugin-migrations/src/MigrationService.js index 13fdbca7b..ca4e85082 100644 --- a/packages/dai-plugin-migrations/src/MigrationService.js +++ b/packages/dai-plugin-migrations/src/MigrationService.js @@ -4,25 +4,15 @@ import SingleToMultiCdp from './migrations/SingleToMultiCdp'; import GlobalSettlementSavingsDai from './migrations/GlobalSettlementSavingsDai'; import GlobalSettlementCollateralClaims from './migrations/GlobalSettlementCollateralClaims'; import GlobalSettlementDaiRedeemer from './migrations/GlobalSettlementDaiRedeemer'; -import SaiToDai from './migrations/SaiToDai'; import MkrRedeemer from './migrations/MkrRedeemer'; -import DaiToSai from './migrations/DaiToSai'; import ChiefMigrate from './migrations/ChiefMigrate'; import RedeemSai from './migrations/RedeemSai'; import RedeemCollateral from './migrations/RedeemCollateral'; -const { - SINGLE_TO_MULTI_CDP, - SAI_TO_DAI, - DAI_TO_SAI, - MKR_REDEEMER, - CHIEF_MIGRATE -} = Migrations; +const { SINGLE_TO_MULTI_CDP, MKR_REDEEMER, CHIEF_MIGRATE } = Migrations; const migrations = { [SINGLE_TO_MULTI_CDP]: SingleToMultiCdp, - [SAI_TO_DAI]: SaiToDai, - [DAI_TO_SAI]: DaiToSai, [CHIEF_MIGRATE]: ChiefMigrate, [Migrations.GLOBAL_SETTLEMENT_SAVINGS_DAI]: GlobalSettlementSavingsDai, [Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: GlobalSettlementCollateralClaims, @@ -60,8 +50,6 @@ export default class MigrationService extends PublicService { [SINGLE_TO_MULTI_CDP]: await this.getMigration( SINGLE_TO_MULTI_CDP ).check(), - [SAI_TO_DAI]: await this.getMigration(SAI_TO_DAI).check(), - [DAI_TO_SAI]: await this.getMigration(DAI_TO_SAI).check(), [CHIEF_MIGRATE]: await this.getMigration(CHIEF_MIGRATE).check(), [MKR_REDEEMER]: await this.getMigration(MKR_REDEEMER).check(), [Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: await this.getMigration( diff --git a/packages/dai-plugin-migrations/src/constants.js b/packages/dai-plugin-migrations/src/constants.js index 9dfbd6efe..4c32dc3c1 100644 --- a/packages/dai-plugin-migrations/src/constants.js +++ b/packages/dai-plugin-migrations/src/constants.js @@ -6,8 +6,6 @@ export const ServiceRoles = { export const Migrations = { SINGLE_TO_MULTI_CDP: 'single-to-multi-cdp', - SAI_TO_DAI: 'sai-to-dai', - DAI_TO_SAI: 'dai-to-sai', GLOBAL_SETTLEMENT_SAVINGS_DAI: 'global-settlement-savings-dai', GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS: 'global-settlement-collateral-claims', GLOBAL_SETTLEMENT_DAI_REDEEMER: 'global-settlement-dai-redeemer', diff --git a/packages/dai-plugin-migrations/src/migrations/DaiToSai.js b/packages/dai-plugin-migrations/src/migrations/DaiToSai.js deleted file mode 100644 index 8caff043a..000000000 --- a/packages/dai-plugin-migrations/src/migrations/DaiToSai.js +++ /dev/null @@ -1,34 +0,0 @@ -import { tracksTransactions } from '../utils'; -import { DAI } from '..'; - -export default class DaiToSai { - constructor(manager) { - this._manager = manager; - this._dai = manager.get('token').getToken(DAI); - return this; - } - - async check() { - return this._dai.balance(); - } - - @tracksTransactions - async execute(amount, { promise }) { - const formattedAmount = DAI(amount).toFixed('wei'); - const address = this._manager.get('web3').currentAddress(); - const migrationContract = this._manager - .get('smartContract') - .getContract('MIGRATION'); - const allowance = await this._dai.allowance( - address, - migrationContract.address - ); - if (allowance.toNumber() < amount) { - await this._dai.approve(migrationContract.address, formattedAmount, { - promise - }); - } - - return migrationContract.swapDaiToSai(formattedAmount, { promise }); - } -} diff --git a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js index 05f0cf93c..7e262dd98 100644 --- a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js +++ b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementCollateralClaims.js @@ -47,56 +47,25 @@ export default class GlobalSettlementCollateralClaims { return freeCollateral; } - freeEth(cdpId) { - const cdpManagerAddress = this._container - .get('smartContract') - .getContractAddress('CDP_MANAGER_1'); - const endAddress = this._container - .get('smartContract') - .getContractAddress('MCD_END_1'); - const ethJoinAddress = this._container - .get('smartContract') - .getContractAddress('MCD_JOIN_ETH_A'); - return this._container - .get('smartContract') - .getContract('PROXY_ACTIONS_END') - .freeETH(cdpManagerAddress, ethJoinAddress, endAddress, cdpId, { - dsProxy: true - }); - } - - freeBat(cdpId) { - const cdpManagerAddress = this._container - .get('smartContract') - .getContractAddress('CDP_MANAGER_1'); - const endAddress = this._container - .get('smartContract') - .getContractAddress('MCD_END_1'); - const gemJoinAddress = this._container - .get('smartContract') - .getContractAddress('MCD_JOIN_BAT_A'); - return this._container - .get('smartContract') - .getContract('PROXY_ACTIONS_END') - .freeGem(cdpManagerAddress, gemJoinAddress, endAddress, cdpId, { - dsProxy: true - }); + _ilkToAdapter(ilk) { + return 'MCD_JOIN_' + ilk.replace(/-/g, '_'); } - freeUsdc(cdpId) { + free(cdpId, ilk) { const cdpManagerAddress = this._container .get('smartContract') .getContractAddress('CDP_MANAGER_1'); const endAddress = this._container .get('smartContract') .getContractAddress('MCD_END_1'); - const gemJoinAddress = this._container + const joinAddress = this._container .get('smartContract') - .getContractAddress('MCD_JOIN_USDC_A'); + .getContractAddress(this._ilkToAdapter(ilk)); + const methodName = ilk.substring(0, 3) === 'ETH' ? 'freeETH' : 'freeGem'; return this._container .get('smartContract') - .getContract('PROXY_ACTIONS_END') - .freeGem(cdpManagerAddress, gemJoinAddress, endAddress, cdpId, { + .getContract('PROXY_ACTIONS_END')[methodName]( + cdpManagerAddress, joinAddress, endAddress, cdpId, { dsProxy: true }); } diff --git a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js index 161af92b8..4490f2cd6 100644 --- a/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js +++ b/packages/dai-plugin-migrations/src/migrations/GlobalSettlementDaiRedeemer.js @@ -71,53 +71,24 @@ export default class GlobalSettlementDaiRedeemer { .pack(daiJoinAddress, endAddress, formattedAmount, { dsProxy: true }); } - async cashEth(daiAmount) { - const formattedAmount = DAI_1(daiAmount).toFixed('wei'); - const joinAddress = this._container - .get('smartContract') - .getContractAddress('MCD_JOIN_ETH_A'); - const endAddress = this._container - .get('smartContract') - .getContractAddress('MCD_END_1'); - const ilkBytes = stringToBytes('ETH-A'); - return this._container - .get('smartContract') - .getContract('PROXY_ACTIONS_END') - .cashETH(joinAddress, endAddress, ilkBytes, formattedAmount, { - dsProxy: true - }); + _ilkToAdapter(ilk) { + return 'MCD_JOIN_' + ilk.replace(/-/g, '_'); } - async cashBat(daiAmount) { + async cash(daiAmount, ilk) { const formattedAmount = DAI_1(daiAmount).toFixed('wei'); const joinAddress = this._container .get('smartContract') - .getContractAddress('MCD_JOIN_BAT_A'); + .getContractAddress(this._ilkToAdapter(ilk)); const endAddress = this._container .get('smartContract') .getContractAddress('MCD_END_1'); - const ilkBytes = stringToBytes('BAT-A'); + const ilkBytes = stringToBytes(ilk); + const methodName = ilk.substring(0, 3) === 'ETH' ? 'cashETH' : 'cashGem'; return this._container .get('smartContract') - .getContract('PROXY_ACTIONS_END') - .cashGem(joinAddress, endAddress, ilkBytes, formattedAmount, { - dsProxy: true - }); - } - - async cashUsdc(daiAmount) { - const formattedAmount = DAI_1(daiAmount).toFixed('wei'); - const joinAddress = this._container - .get('smartContract') - .getContractAddress('MCD_JOIN_USDC_A'); - const endAddress = this._container - .get('smartContract') - .getContractAddress('MCD_END_1'); - const ilkBytes = stringToBytes('USDC-A'); - return this._container - .get('smartContract') - .getContract('PROXY_ACTIONS_END') - .cashGem(joinAddress, endAddress, ilkBytes, formattedAmount, { + .getContract('PROXY_ACTIONS_END')[methodName]( + joinAddress, endAddress, ilkBytes, formattedAmount, { dsProxy: true }); } diff --git a/packages/dai-plugin-migrations/src/migrations/SaiToDai.js b/packages/dai-plugin-migrations/src/migrations/SaiToDai.js deleted file mode 100644 index 146dc7ed1..000000000 --- a/packages/dai-plugin-migrations/src/migrations/SaiToDai.js +++ /dev/null @@ -1,34 +0,0 @@ -import { tracksTransactions } from '../utils'; -import { SAI } from '..'; - -export default class SaiToDai { - constructor(manager) { - this._manager = manager; - this._sai = manager.get('token').getToken(SAI); - return this; - } - - async check() { - return this._sai.balance(); - } - - @tracksTransactions - async execute(amount, { promise }) { - const formattedAmount = SAI(amount).toFixed('wei'); - const address = this._manager.get('web3').currentAddress(); - const migrationContract = this._manager - .get('smartContract') - .getContract('MIGRATION'); - const allowance = await this._sai.allowance( - address, - migrationContract.address - ); - if (allowance.toNumber() < amount) { - await this._sai.approve(migrationContract.address, formattedAmount, { - promise - }); - } - - return migrationContract.swapSaiToDai(formattedAmount, { promise }); - } -} diff --git a/packages/dai-plugin-migrations/test/MigrationService.spec.js b/packages/dai-plugin-migrations/test/MigrationService.spec.js index 4759cdec2..188a22cbe 100644 --- a/packages/dai-plugin-migrations/test/MigrationService.spec.js +++ b/packages/dai-plugin-migrations/test/MigrationService.spec.js @@ -2,7 +2,6 @@ import { migrationMaker } from './helpers'; import { mockCdpIds } from './helpers/mocks'; import { ServiceRoles, Migrations } from '../src/constants'; import SingleToMultiCdp from '../src/migrations/SingleToMultiCdp'; -import SaiToDai from '../src/migrations/SaiToDai'; import GlobalSettlementSavingsDai from '../src/migrations/GlobalSettlementSavingsDai'; import GlobalSettlementCollateralClaims from '../src/migrations/GlobalSettlementCollateralClaims'; import GlobalSettlementDaiRedeemer from '../src/migrations/GlobalSettlementDaiRedeemer'; @@ -38,7 +37,6 @@ test('can fetch a list of all migrations', () => { expect(ids).toEqual( expect.arrayContaining([ Migrations.SINGLE_TO_MULTI_CDP, - Migrations.SAI_TO_DAI, Migrations.GLOBAL_SETTLEMENT_SAVINGS_DAI, Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS, Migrations.GLOBAL_SETTLEMENT_DAI_REDEEMER, @@ -48,14 +46,13 @@ test('can fetch a list of all migrations', () => { Migrations.REDEEM_COLLATERAL ]) ); - expect(ids.length).toEqual(10); + expect(ids.length).toEqual(8); }); test('getting each migration returns a valid migration', () => { expect(service.getMigration(Migrations.SINGLE_TO_MULTI_CDP)).toBeInstanceOf( SingleToMultiCdp ); - expect(service.getMigration(Migrations.SAI_TO_DAI)).toBeInstanceOf(SaiToDai); expect( service.getMigration(Migrations.GLOBAL_SETTLEMENT_SAVINGS_DAI) ).toBeInstanceOf(GlobalSettlementSavingsDai); @@ -82,12 +79,9 @@ test('runAllChecks', async () => { await mockCdpIds(maker); const result = await service.runAllChecks(); expect(result).toEqual({ - [Migrations.SAI_TO_DAI]: expect.anything(), - [Migrations.DAI_TO_SAI]: expect.anything(), [Migrations.SINGLE_TO_MULTI_CDP]: {}, [Migrations.CHIEF_MIGRATE]: expect.anything(), [Migrations.MKR_REDEEMER]: expect.anything(), [Migrations.GLOBAL_SETTLEMENT_COLLATERAL_CLAIMS]: expect.anything() }); - expect(result[Migrations.SAI_TO_DAI].eq(0)).toBeTruthy(); }); diff --git a/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js b/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js deleted file mode 100644 index 2f012cd5b..000000000 --- a/packages/dai-plugin-migrations/test/migrations/DaiToSai.spec.js +++ /dev/null @@ -1,67 +0,0 @@ -import { migrationMaker, drawSaiAndMigrateToDai } from '../helpers'; -import { ServiceRoles, Migrations } from '../../src/constants'; -import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; -import { ETH } from '@makerdao/dai-plugin-mcd/dist'; - -let maker, migration, snapshot; - -describe('DAI to SAI Migration', () => { - beforeAll(async () => { - maker = await migrationMaker(); - const service = maker.service(ServiceRoles.MIGRATION); - migration = service.getMigration(Migrations.DAI_TO_SAI); - snapshot = await takeSnapshot(maker); - }); - - afterAll(async () => { - restoreSnapshot(snapshot, maker); - }); - - test('if the account has no DAI, return 0', async () => { - const amount = await maker - .service('token') - .getToken('DAI') - .balance(); - expect(amount.toNumber()).toBe(0); - - expect((await migration.check()).eq(0)).toBeTruthy(); - }); - - test('if the account has some DAI, return the balance', async () => { - await maker.service('mcd:cdpManager').openLockAndDraw('ETH-A', ETH(5), 100); - - const amount = await maker - .service('token') - .getToken('DAI') - .balance(); - expect(amount.toNumber()).toBe(100); - - expect((await migration.check()).eq(100)).toBeTruthy(); - }); - - xtest('execute migrates DAI to SAI', async () => { - await drawSaiAndMigrateToDai(10, maker); - const address = maker.service('web3').currentAddress(); - await maker.service('mcd:cdpManager').openLockAndDraw('ETH-A', ETH(5), 100); - const daiBalanceBeforeMigration = await migration._dai.balanceOf(address); - const saiBalanceBeforeMigration = await maker - .service('token') - .getToken('SAI') - .balanceOf(address); - - await migration.execute(100); - - const daiBalanceAfterMigration = await migration._dai.balanceOf(address); - const saiBalanceAfterMigration = await maker - .service('token') - .getToken('SAI') - .balanceOf(address); - - expect(saiBalanceBeforeMigration.toNumber()).toEqual( - saiBalanceAfterMigration.toNumber() - 100 - ); - expect(daiBalanceBeforeMigration.toNumber()).toEqual( - daiBalanceAfterMigration.toNumber() + 100 - ); - }); -}); diff --git a/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js b/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js deleted file mode 100644 index e6243fb9b..000000000 --- a/packages/dai-plugin-migrations/test/migrations/SaiToDai.spec.js +++ /dev/null @@ -1,67 +0,0 @@ -import { migrationMaker } from '../helpers'; -import { ServiceRoles, Migrations } from '../../src/constants'; -import { takeSnapshot, restoreSnapshot } from '@makerdao/test-helpers'; - -let maker, migration, snapshot; - -describe('SAI to DAI Migration', () => { - beforeAll(async () => { - maker = await migrationMaker(); - const service = maker.service(ServiceRoles.MIGRATION); - migration = service.getMigration(Migrations.SAI_TO_DAI); - snapshot = await takeSnapshot(maker); - }); - - afterAll(async () => { - restoreSnapshot(snapshot, maker); - }); - - test('if the account has no SAI, return 0', async () => { - const amount = await maker - .service('token') - .getToken('SAI') - .balance(); - expect(amount.toNumber()).toBe(0); - - expect((await migration.check()).eq(0)).toBeTruthy(); - }); - - test('if the account has some SAI, return the balance', async () => { - const proxy = await maker.service('proxy').ensureProxy(); - await maker.service('cdp').openProxyCdpLockEthAndDrawSai(0.1, 1, proxy); - - const amount = await maker - .service('token') - .getToken('SAI') - .balance(); - expect(amount.toNumber()).toBe(1); - - expect((await migration.check()).eq(1)).toBeTruthy(); - }); - - xtest('execute migrates SAI to DAI', async () => { - const address = maker.service('web3').currentAddress(); - const proxy = await maker.service('proxy').ensureProxy(); - await maker.service('cdp').openProxyCdpLockEthAndDrawSai(0.1, 1, proxy); - const saiBalanceBeforeMigration = await migration._sai.balanceOf(address); - const daiBalanceBeforeMigration = await maker - .service('token') - .getToken('DAI') - .balanceOf(address); - - await migration.execute(1); - - const saiBalanceAfterMigration = await migration._sai.balanceOf(address); - const daiBalanceAfterMigration = await maker - .service('token') - .getToken('DAI') - .balanceOf(address); - - expect(saiBalanceBeforeMigration.toNumber()).toEqual( - saiBalanceAfterMigration.toNumber() + 1 - ); - expect(daiBalanceBeforeMigration.toNumber()).toEqual( - daiBalanceAfterMigration.toNumber() - 1 - ); - }); -}); diff --git a/packages/dai-plugin-scd/contracts/abiMap.js b/packages/dai-plugin-scd/contracts/abiMap.js index 6352b9e47..02f8cba8b 100644 --- a/packages/dai-plugin-scd/contracts/abiMap.js +++ b/packages/dai-plugin-scd/contracts/abiMap.js @@ -17,5 +17,6 @@ module.exports = { PROXY_REGISTRY: require('./abis/ProxyRegistry'), DS_PROXY_FACTORY: require('./abis/DSProxyFactory'), DS_PROXY: require('./abis/DSProxy'), - MULTICALL: require('./abis/Multicall') + MULTICALL: require('./abis/Multicall'), + SAI_TUB_CONSTANT: require('./abis/SaiTubConstant') }; diff --git a/packages/dai-plugin-scd/contracts/abis/SaiTubConstant.json b/packages/dai-plugin-scd/contracts/abis/SaiTubConstant.json new file mode 100644 index 000000000..520420e0e --- /dev/null +++ b/packages/dai-plugin-scd/contracts/abis/SaiTubConstant.json @@ -0,0 +1,11 @@ +[ + { + "constant":true, + "inputs":[{"name":"cup","type":"bytes32"}], + "name":"tab", + "outputs":[{"name":"","type":"uint256"}], + "payable":false, + "stateMutability":"nonpayable", + "type":"function" + } +] \ No newline at end of file diff --git a/packages/dai-plugin-scd/contracts/addresses/kovan.json b/packages/dai-plugin-scd/contracts/addresses/kovan.json index 36f40a5da..c1ff8d699 100644 --- a/packages/dai-plugin-scd/contracts/addresses/kovan.json +++ b/packages/dai-plugin-scd/contracts/addresses/kovan.json @@ -12,6 +12,7 @@ "SAI_MOM": "0x72ee9496b0867dfe5e8b280254da55e51e34d27b", "SAI_VOX": "0xbb4339c0ab5b1d9f14bd6e3426444a1e9d86a1d9", "SAI_TUB": "0xa71937147b55Deb8a530C7229C442Fd3F31b7db2", + "SAI_TUB_CONSTANT": "0xa71937147b55Deb8a530C7229C442Fd3F31b7db2", "SAI_TAP": "0xc936749d2d0139174ee0271bd28325074fdbc654", "SAI_TOP": "0x5f00393547561da3030ebf30e52f5dc0d5d3362c", "MAKER_OTC": "0xe325acB9765b02b8b418199bf9650972299235F4", diff --git a/packages/dai-plugin-scd/contracts/addresses/mainnet.json b/packages/dai-plugin-scd/contracts/addresses/mainnet.json index 4cc013331..fb32cde29 100644 --- a/packages/dai-plugin-scd/contracts/addresses/mainnet.json +++ b/packages/dai-plugin-scd/contracts/addresses/mainnet.json @@ -13,6 +13,7 @@ "SAI_MOM": "0xf2c5369cffb8ea6284452b0326e326dbfdcb867c", "SAI_VOX": "0x9b0f70df76165442ca6092939132bbaea77f2d7a", "SAI_TUB": "0x448a5065aebb8e423f0896e6c5d525c040f59af3", + "SAI_TUB_CONSTANT": "0x448a5065aebb8e423f0896e6c5d525c040f59af3", "SAI_TAP": "0xbda109309f9fafa6dd6a9cb9f1df4085b27ee8ef", "SAI_TOP": "0x9b0ccf7c8994e19f39b2b4cf708e0a7df65fa8a3", "MAKER_OTC": "0x794e6e91555438aFc3ccF1c5076A74F42133d08D", diff --git a/packages/dai-plugin-scd/contracts/addresses/testnet.json b/packages/dai-plugin-scd/contracts/addresses/testnet.json index aaa2cbe6f..25646e987 100644 --- a/packages/dai-plugin-scd/contracts/addresses/testnet.json +++ b/packages/dai-plugin-scd/contracts/addresses/testnet.json @@ -27,6 +27,7 @@ "SAI_MOM": "0x603D52D6AE2b98A49f8f32817ad4EfFe7E8A2502", "SAI_VOX": "0xE16bf7AaFeB33cC921d6D311E0ff33C4faA836dD", "SAI_TUB": "0xE82CE3D6Bf40F2F9414C8d01A35E3d9eb16a1761", + "SAI_TUB_CONSTANT": "0xE82CE3D6Bf40F2F9414C8d01A35E3d9eb16a1761", "SAI_TAP": "0x6896659267C3C9FD055d764327199A98E571e00D", "SAI_TOP": "0x2774031B3898fbe414F929b3223cE1039325e7Dc" } diff --git a/packages/dai-plugin-scd/contracts/contracts.js b/packages/dai-plugin-scd/contracts/contracts.js index 3b13cae66..6a3e24f46 100644 --- a/packages/dai-plugin-scd/contracts/contracts.js +++ b/packages/dai-plugin-scd/contracts/contracts.js @@ -12,5 +12,6 @@ export default { PROXY_REGISTRY: 'PROXY_REGISTRY', DS_PROXY_FACTORY: 'DS_PROXY_FACTORY', DS_PROXY: 'DS_PROXY', - MULTICALL: 'MULTICALL' + MULTICALL: 'MULTICALL', + SAI_TUB_CONSTANT: 'SAI_TUB_CONSTANT' }; diff --git a/packages/dai-plugin-scd/package.json b/packages/dai-plugin-scd/package.json index b4e8aacc6..f8e2af786 100644 --- a/packages/dai-plugin-scd/package.json +++ b/packages/dai-plugin-scd/package.json @@ -1,7 +1,7 @@ { "name": "@makerdao/dai-plugin-scd", "description": "Plugin to add Single-Collateral Dai support to dai.js", - "version": "1.2.8", + "version": "1.2.9", "license": "MIT", "main": "dist/src/index.js", "unpkg": "umd/index.js", diff --git a/packages/dai-plugin-scd/src/EthereumCdpService.js b/packages/dai-plugin-scd/src/EthereumCdpService.js index 94d4eb202..9c5a54350 100644 --- a/packages/dai-plugin-scd/src/EthereumCdpService.js +++ b/packages/dai-plugin-scd/src/EthereumCdpService.js @@ -267,14 +267,12 @@ export default class EthereumCdpService extends PrivateService { async getDebtValue(cdpId, unit = SAI) { const hexCdpId = numberToBytes32(cdpId); - // we need to use the Web3.js contract interface to get the return value - // from the non-constant function `tab` - const tub = this._smartContract().getWeb3ContractByName(contracts.SAI_TUB); - const tab = await new Promise((resolve, reject) => - tub.methods - .tab(hexCdpId) - .call({}, (err, val) => (err ? reject(err) : resolve(val))) + // use an altered abi that treats tub.tab() like a constant function + // so we can read from it, even though it's actually a non-constant function + const TubConstantTab = this._smartContract().getContract( + contracts.SAI_TUB_CONSTANT ); + const tab = await TubConstantTab.tab(hexCdpId); const saiDebt = SAI.wei(tab.toString()); switch (unit) { case SAI: