Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/spool-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
amikec authored Nov 30, 2023
2 parents f64ff9c + 5075240 commit 764794d
Show file tree
Hide file tree
Showing 4,949 changed files with 793,251 additions and 1,692,425 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Checklist

- [ ] I have followed the [Contributing Guidelines](../CONTRIBUTING.md)
- [ ] I have followed the [Contributing Guidelines](https://github.com/Zapper-fi/studio/blob/main/CONTRIBUTING.md)
- [ ] (optional) As a contributor, my Ethereum address/ENS is:
- [ ] (optional) As a contributor, my Twitter handle is:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Studio Background Check 🚓
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: '--max_old_space_size=8192'
run: pnpm build

unit:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:

- name: Build package
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NODE_OPTIONS: '--max_old_space_size=8192'
run: pnpm build
if: ${{ steps.release.outputs.release_created }}

Expand Down
594 changes: 594 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/commands/create-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { generateAppModule } from '../generators/generate-app-module';
import { promptAppId, promptAppName, promptAppNetworks } from '../prompts';
import { strings } from '../strings';

import { generateContractFactory } from './generate-contract-factory';
import { generateViemContractFactory } from './generate-contract-factory/generate-viem-contract-factory';

export default class CreateApp extends Command {
static description = 'Creates the starting point for an app integration';
Expand All @@ -27,7 +27,7 @@ export default class CreateApp extends Command {
}

await generateAppModule(appId);
await generateContractFactory(`./src/apps/${appId}`);
await generateViemContractFactory(`./src/apps/${appId}`);

this.log(`Done! Your app ${appName} has been generated`);
}
Expand Down
192 changes: 0 additions & 192 deletions cli/commands/generate-contract-factory.ts

This file was deleted.

20 changes: 20 additions & 0 deletions cli/commands/generate-contract-factory/generate-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint no-console: 0 */
import fs, { writeFileSync } from 'fs';
import path from 'path';
import util from 'util';

const exists = util.promisify(fs.exists);

export const generateIndex = async (location: string) => {
let content = `
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
`;

if (await exists(path.join(location, `/contracts/viem.contract-factory.ts`))) {
content += `export * from './viem.contract-factory';\n`;
}

writeFileSync(path.join(location, `/contracts/index.ts`), content);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* eslint no-console: 0 */
import { writeFileSync } from 'fs';
import path from 'path';

import { readFile } from 'fs-extra';
import { camelCase, sortBy, upperFirst } from 'lodash';

import { getAbis } from './get-abis';

export const generateViemContractFactory = async (location: string) => {
const abis = await getAbis(location);
const maybeAppId = path.basename(location);

const sortedAbis = sortBy(abis);
const globalAppId = 'contract';
const globalClassName = 'ContractViemContractFactory';
const appClassName = `${upperFirst(camelCase(maybeAppId))}ViemContractFactory`;
const className = maybeAppId === globalAppId ? globalClassName : appClassName;

const moduleFile = await readFile(path.resolve(location, `${maybeAppId}.module.ts`), 'utf-8').catch(() => '');
const hasAppToolkitDep = moduleFile.includes(`extends AbstractApp()`);

const renderer = {
viem: async () => {
writeFileSync(
path.join(location, `/contracts/viem.contract-factory.ts`),
`
import { Injectable, Inject } from '@nestjs/common';
import { PublicClient } from 'viem';
import { Network } from '~types/network.interface';
${hasAppToolkitDep ? `import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface';` : ''}
${!hasAppToolkitDep ? `import { Web3Service } from '~web3/web3.service';` : ''}
${
sortedAbis.length
? `import { ${sortedAbis.map(abi => `${upperFirst(camelCase(abi))}__factory`).join(', ')} } from './viem';`
: ''
}
${sortedAbis.length ? `type ContractOpts = {address: string, network: Network};` : ''}
${!hasAppToolkitDep ? `type ViemNetworkProviderResolver = (network: Network) => PublicClient;` : ''}
@Injectable()
export class ${className} {
${
hasAppToolkitDep
? `constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) {}`
: `constructor(protected readonly networkProviderResolver: ViemNetworkProviderResolver) {}`
}
${sortedAbis
.map(
abiName =>
`${camelCase(abiName)}({address, network}: ContractOpts) { return ${upperFirst(
camelCase(abiName),
)}__factory.connect(address, ${
hasAppToolkitDep
? `this.appToolkit.getViemNetworkProvider(network)`
: `this.networkProviderResolver(network)`
}); }`,
)
.join('\n')}
}
`,
);
},
};

await renderer.viem();
};
Loading

0 comments on commit 764794d

Please sign in to comment.