diff --git a/packages/dma-library/package.json b/packages/dma-library/package.json index 1f4e769c9..ea3820feb 100644 --- a/packages/dma-library/package.json +++ b/packages/dma-library/package.json @@ -1,6 +1,6 @@ { "name": "@oasisdex/dma-library", - "version": "0.6.57", + "version": "0.6.58", "typings": "lib/index.d.ts", "types": "lib/index.d.ts", "main": "lib/index.js", diff --git a/packages/dma-library/src/strategies/morphoblue/multiply/open.ts b/packages/dma-library/src/strategies/morphoblue/multiply/open.ts index 185b6c702..3f702c9bc 100644 --- a/packages/dma-library/src/strategies/morphoblue/multiply/open.ts +++ b/packages/dma-library/src/strategies/morphoblue/multiply/open.ts @@ -460,34 +460,47 @@ export async function getSwapData( return { swapData, collectFeeFrom, preSwapFee } } +const getTokenSymbolAbi = (type: 'string' | 'bytes32') => { + return [ + { + constant: true, + inputs: [], + name: 'symbol', + outputs: [ + { + name: '', + type, + }, + ], + payable: false, + stateMutability: 'view', + type: 'function', + }, + ] +} + export async function getTokenSymbol( token: Address, provider: providers.Provider, ): Promise { - const erc20 = new ethers.Contract( - token, - [ - { - constant: true, - inputs: [], - name: 'symbol', - outputs: [ - { - name: '', - type: 'string', - }, - ], - payable: false, - stateMutability: 'view', - type: 'function', - }, - ], - provider, - ) - - const symbol = await erc20.symbol() - - return symbol + try { + const erc20 = new ethers.Contract(token, getTokenSymbolAbi('string'), provider) + + return await erc20.symbol() + } catch (e) { + // It's required because for example MKR token symbol() returns bytes32 instead of string + console.warn('Issue with getting token symbol as string, trying to fetch as bytes32...') + + try { + const erc20 = new ethers.Contract(token, getTokenSymbolAbi('bytes32'), provider) + const symbol = await erc20.symbol() + + return ethers.utils.parseBytes32String(symbol) + } catch (e) { + console.error('Failed to get token symbol') + return 'UNKNOWN_SYMBOL' + } + } } export function prepareMorphoMultiplyDMAPayload(