Skip to content

Commit

Permalink
Get token symbol adjustment (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
piekczyk authored Jun 28, 2024
1 parent 1034e16 commit dd8787c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/dma-library/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
61 changes: 37 additions & 24 deletions packages/dma-library/src/strategies/morphoblue/multiply/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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(
Expand Down

0 comments on commit dd8787c

Please sign in to comment.