Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LoanV3 artifacts #19

Merged
merged 22 commits into from
Jul 18, 2022
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion scripts/build-typechain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Note: if this cannot be done in js, then perhaps as a `./bin/build-typechain.sh` instead.
const path = require('path')
const typechain = require('typechain')
const { readFileSync } = require('fs')
const { readFileSync, writeFileSync } = require('fs')

const artifactsOutputDir = path.join(__dirname, '../src/typechain')
const pathDir = path.join(__dirname, `../node_modules/@maplelabs/`)

const getParsedConfig = () => {
const configPath = path.join(__dirname, '../config.json')
Expand Down Expand Up @@ -37,9 +38,55 @@ const generateTypechainBindings = async (config) => {
}
}

function mergeEvents({ src, dst }) {
console.log(`🔀 Merging events from ${src} events into ${dst}`)
const srcJson = JSON.parse(readFileSync(path.join(pathDir, `${src}`)).toString())
const events = srcJson.filter((entry) => entry.type === 'event')
const dstJson = JSON.parse(readFileSync(path.join(pathDir, `${dst}`)).toString())
const eventIndexJson = dstJson.findIndex((el) => el.type !== 'event')
dstJson.splice(eventIndexJson, 0, ...events)
writeFileSync(path.join(pathDir, `${dst}`), JSON.stringify(dstJson, null, 2))
}

function overwriteEventParams({ files, eventName, inputs }) {
for (const src of files) {
console.log('✏️ Overwriting event params for', src)
const filePath = path.join(pathDir, `${src.toLowerCase()}/abis/${src}.json`)
const json = JSON.parse(readFileSync(filePath).toString())
const eventIndex = json.findIndex((el) => el.type === 'event' && el.name === eventName)
json[eventIndex].inputs = inputs
writeFileSync(filePath, JSON.stringify(json, null, 2))
}
}

async function buildTypechain() {
console.log('⏳ Building Typechain...')
const config = getParsedConfig()
mergeEvents({ src: 'loanV3/abis/Refinancer.json', dst: 'loanV3/abis/MapleLoan.json' })
callum-hyland marked this conversation as resolved.
Show resolved Hide resolved
overwriteEventParams({
files: ['Pool', 'StakeLocker'],
eventName: 'LossesRecognized',
inputs: [
{
indexed: true,
internalType: 'address',
name: 'by',
type: 'address'
},
{
indexed: false,
internalType: 'uint256',
name: 'lossesRecognized',
type: 'uint256'
},
{
indexed: false,
internalType: 'uint256',
name: 'totalLossesRecognized',
type: 'uint256'
}
]
})
await generateTypechainBindings(config)
}

Expand Down