Skip to content

Commit

Permalink
chore: sync
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Jul 3, 2024
1 parent f724b99 commit 2d42c2d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
21 changes: 18 additions & 3 deletions packages/sdk/src/Actions/ContractAction.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Config } from '@wagmi/core';
import { zeroAddress } from 'viem';
import { beforeEach, describe, test } from 'vitest';
import { isAddress, zeroAddress } from 'viem';
import { beforeEach, describe, expect, test } from 'vitest';
import { setupConfig, testAccount } from '../../test/viem';
import { ContractAction } from './ContractAction';

Expand All @@ -22,6 +22,21 @@ describe('ContractAction', () => {
},
);
const address = await action.deploy();
console.log(address);
expect(isAddress(address)).toBe(true);
});

test('can successfully be initialized after deployment', async () => {
const action = new ContractAction(
{ config, account: testAccount },
{
chainId: BigInt(31_337),
target: zeroAddress,
selector: '0xdeadbeef',
value: 2n,
},
);
await action.deploy();
await action.initialize();
console.log(await action.chainId());
});
});
46 changes: 34 additions & 12 deletions packages/sdk/src/Deployable/DeployableTarget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { deployContract } from '@wagmi/core';
import {
deployContract,
waitForTransactionReceipt,
writeContract,
} from '@wagmi/core';
import type { Address, Hash, WaitForTransactionReceiptParameters } from 'viem';
import { DeployableAlreadyDeployedError } from '../errors';
import { getDeployedContractAddress } from '../utils';
import {
Deployable,
type DeployableOptions,
Expand All @@ -19,19 +22,36 @@ export class DeployableTarget<Payload = unknown> extends Deployable<Payload> {
this.isBase = isBase;
}

public override async deploy(
public async initialize(
_payload?: Payload,
_options?: DeployableOptions,
waitParams: Omit<WaitForTransactionReceiptParameters, 'hash'> = {},
): Promise<Address> {
) {
const payload = _payload || this._payload;
const config = _options?.config || this._config;
const address = await getDeployedContractAddress(
config,
this.deployRaw(_payload, _options),
waitParams,
);
this._address = address;
return address;
console.log(payload);
const { abi, args } = this.buildParameters(payload);
console.log(args);
const hash = await writeContract(config, {
...this.optionallyAttachAccount(_options?.account),
abi,
args,
functionName: 'initialize',
address: this.assertValidAddress(),
});
await waitForTransactionReceipt(config, {
...waitParams,
hash,
});
}

public override async deploy(
payload?: Payload,
options?: DeployableOptions,
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
): Promise<Address> {
await super.deploy(payload, options, waitParams);
return this.assertValidAddress();
}

public override async deployRaw(
Expand All @@ -41,9 +61,11 @@ export class DeployableTarget<Payload = unknown> extends Deployable<Payload> {
if (this.address) throw new DeployableAlreadyDeployedError(this.address);
const payload = _payload || this._payload;
const config = _options?.config || this._config;
const { args, ...deployment } = this.buildParameters(payload);
return await deployContract(config, {
...this.buildParameters(payload),
...deployment,
...this.optionallyAttachAccount(_options?.account),
args: [],
});
}
}

0 comments on commit 2d42c2d

Please sign in to comment.