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

Feature: Remove owner from create app #168

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/wet-ways-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@openformat/sdk": patch
---

- Remove owner param from createApp
30 changes: 30 additions & 0 deletions packages/sdk/src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,40 @@ export const polygonMumbai = {
testnet: true,
} as const satisfies Chain;

export const arbitrumSepolia = {
id: 421_614,
name: 'Arbitrum Sepolia',
nativeCurrency: {
name: 'Arbitrum Sepolia Ether',
symbol: 'ETH',
decimals: 18,
},
rpcUrls: {
default: {
http: ['https://sepolia-rollup.arbitrum.io/rpc'],
},
},
blockExplorers: {
default: {
name: 'Arbiscan',
url: 'https://sepolia.arbiscan.io',
apiUrl: 'https://api-sepolia.arbiscan.io/api',
},
},
contracts: {
multicall3: {
address: '0xca11bde05977b3631167028862be2a173976ca11',
blockCreated: 81930,
},
},
testnet: true,
};

export const Chains = {
aurora,
auroraTestnet,
foundry,
polygon,
polygonMumbai,
arbitrumSepolia,
};
18 changes: 8 additions & 10 deletions packages/sdk/src/core/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from 'ethers';
import { appFactoryContracts } from '../constants';
import { AppFactory__factory } from '../contract-types';
import { validateWallets } from '../helpers';
import { getArgumentFromEvent, parseErrorData } from '../helpers/transaction';
import { Errors } from '../types';
import { BaseContract } from './base';
/**
* A class representing a Factory contract that extends the BaseContract class.
Expand Down Expand Up @@ -74,18 +74,16 @@ export class Factory extends BaseContract {
* @returns {Promise<ContractReceipt>} A Promise that resolves to the transaction receipt of the contract creation.
*/

async createApp({
name,
owner,
}: {
name: string;
owner: string;
}): Promise<{ id: string }> {
async createApp({ name }: { name: string }): Promise<{ id: string }> {
try {
const providerNetwork = await this.provider.getNetwork();
this.checkNetworksMatch();

validateWallets([owner]);
const signerAddress = await this.signer?.getAddress();

if (!signerAddress || !ethers.utils.isAddress(signerAddress)) {
throw new Error(Errors.InvalidSigner);
}

const factoryAddress = this.getAppFactoryContractAddress(
providerNetwork.chainId
Expand All @@ -98,7 +96,7 @@ export class Factory extends BaseContract {

const tx = await contract.create(
ethers.utils.formatBytes32String(name),
owner
signerAddress
);

const receipt = await this.processTransaction(tx);
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,5 @@ export enum ContractErrors {
}

export enum Errors {
LowTransactionFeeBalance = 'Signer $OFT balance too low. Please top up.',
InvalidSigner = 'The signer does not exist or is not a valid address',
}
8 changes: 2 additions & 6 deletions packages/sdk/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,18 @@ describe('AppFactory', () => {
it('should create an app', async () => {
const app = await global.sdk.factory.createApp({
name: faker.internet.domainWord(),
owner: global.walletAddress,
});

expect(app.id).toContain('0x');
});

it('should throw error if app name already exists', async () => {
const name = faker.internet.domainWord();
const params = {
owner: global.walletAddress,
};

await global.sdk.factory.createApp({ name, ...params });
await global.sdk.factory.createApp({ name });

async function handleCreate() {
await global.sdk.factory.createApp({ name, ...params });
await global.sdk.factory.createApp({ name });
}

await expect(handleCreate).rejects.toThrow(
Expand Down
Loading