Skip to content

Commit 875c15e

Browse files
committed
feat: renamed all the instances to have a create prefix
1 parent 80c052d commit 875c15e

9 files changed

Lines changed: 71 additions & 71 deletions

File tree

src/core/batch/batch.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { erc20Abi, getAddress } from 'viem';
22
import { describe, expect, it } from 'vitest';
33
import { publicClient } from '../../test/utils';
44
import { InputParamFetcherType } from '../encoding';
5-
import { ComposableBatch } from './batch';
5+
import { createComposableBatch } from './batch';
66

77
const ACCOUNT = getAddress('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
88
const USDC = getAddress('0x036CbD53842c5426634e7929541eC2318f3dCF7e');
@@ -24,7 +24,7 @@ const UNISWAP_V3_FACTORY_ABI = [
2424
// ---------------------------------------------------------------------------
2525

2626
describe('ComposableBatch — construction', () => {
27-
const batch = ComposableBatch(publicClient, ACCOUNT);
27+
const batch = createComposableBatch(publicClient, ACCOUNT);
2828

2929
it('stores publicClient', () => {
3030
expect(batch.publicClient).toBe(publicClient);
@@ -40,7 +40,7 @@ describe('ComposableBatch — construction', () => {
4040
// ---------------------------------------------------------------------------
4141

4242
describe('ComposableBatch — erc20Token', () => {
43-
const batch = ComposableBatch(publicClient, ACCOUNT);
43+
const batch = createComposableBatch(publicClient, ACCOUNT);
4444
const token = batch.erc20Token(USDC);
4545

4646
it('returns an ERC20TokenInstance with the correct address', () => {
@@ -93,7 +93,7 @@ describe('ComposableBatch — erc20Token', () => {
9393
// ---------------------------------------------------------------------------
9494

9595
describe('ComposableBatch — nativeToken', () => {
96-
const batch = ComposableBatch(publicClient, ACCOUNT);
96+
const batch = createComposableBatch(publicClient, ACCOUNT);
9797
const native = batch.nativeToken();
9898

9999
it('balance uses accountAddress when address is omitted', async () => {
@@ -126,12 +126,12 @@ describe('ComposableBatch — nativeToken', () => {
126126

127127
describe('ComposableBatch — add, length, clear, toCalldata', () => {
128128
it('length is 0 on a fresh batch', () => {
129-
const batch = ComposableBatch(publicClient, ACCOUNT);
129+
const batch = createComposableBatch(publicClient, ACCOUNT);
130130
expect(batch.length).toBe(0);
131131
});
132132

133133
it('add(single call) increments length by 1', () => {
134-
const batch = ComposableBatch(publicClient, ACCOUNT);
134+
const batch = createComposableBatch(publicClient, ACCOUNT);
135135
const call = batch
136136
.contract(USDC, erc20Abi)
137137
.write({ functionName: 'transfer', args: [WETH, 1n] });
@@ -140,7 +140,7 @@ describe('ComposableBatch — add, length, clear, toCalldata', () => {
140140
});
141141

142142
it('add(array of calls) increments length by the array size', () => {
143-
const batch = ComposableBatch(publicClient, ACCOUNT);
143+
const batch = createComposableBatch(publicClient, ACCOUNT);
144144
const token = batch.contract(USDC, erc20Abi);
145145
const calls = [
146146
token.write({ functionName: 'transfer', args: [WETH, 1n] }),
@@ -151,15 +151,15 @@ describe('ComposableBatch — add, length, clear, toCalldata', () => {
151151
});
152152

153153
it('add() can be called multiple times and accumulates calls', () => {
154-
const batch = ComposableBatch(publicClient, ACCOUNT);
154+
const batch = createComposableBatch(publicClient, ACCOUNT);
155155
const token = batch.contract(USDC, erc20Abi);
156156
batch.add(token.write({ functionName: 'transfer', args: [WETH, 1n] }));
157157
batch.add(token.write({ functionName: 'approve', args: [WETH, 1n] }));
158158
expect(batch.length).toBe(2);
159159
});
160160

161161
it('clear() resets length to 0', () => {
162-
const batch = ComposableBatch(publicClient, ACCOUNT);
162+
const batch = createComposableBatch(publicClient, ACCOUNT);
163163
const call = batch
164164
.contract(USDC, erc20Abi)
165165
.write({ functionName: 'transfer', args: [WETH, 1n] });
@@ -169,7 +169,7 @@ describe('ComposableBatch — add, length, clear, toCalldata', () => {
169169
});
170170

171171
it('toCalldata() returns a hex string', async () => {
172-
const batch = ComposableBatch(publicClient, ACCOUNT);
172+
const batch = createComposableBatch(publicClient, ACCOUNT);
173173
const call = batch
174174
.contract(USDC, erc20Abi)
175175
.write({ functionName: 'transfer', args: [WETH, 1n] });
@@ -179,7 +179,7 @@ describe('ComposableBatch — add, length, clear, toCalldata', () => {
179179
});
180180

181181
it('toCalldata() with multiple calls returns a hex string', async () => {
182-
const batch = ComposableBatch(publicClient, ACCOUNT);
182+
const batch = createComposableBatch(publicClient, ACCOUNT);
183183
const token = batch.contract(USDC, erc20Abi);
184184
batch.add(token.write({ functionName: 'transfer', args: [WETH, 1n] }));
185185
batch.add(token.write({ functionName: 'approve', args: [WETH, 1_000_000n] }));
@@ -188,8 +188,8 @@ describe('ComposableBatch — add, length, clear, toCalldata', () => {
188188
});
189189

190190
it('toCalldata() produces different output for different calls', async () => {
191-
const batchA = ComposableBatch(publicClient, ACCOUNT);
192-
const batchB = ComposableBatch(publicClient, ACCOUNT);
191+
const batchA = createComposableBatch(publicClient, ACCOUNT);
192+
const batchB = createComposableBatch(publicClient, ACCOUNT);
193193
const token = batchA.contract(USDC, erc20Abi);
194194
batchA.add(token.write({ functionName: 'transfer', args: [WETH, 1n] }));
195195
batchB.add(
@@ -206,12 +206,12 @@ describe('ComposableBatch — add, length, clear, toCalldata', () => {
206206

207207
describe('ComposableBatch — calls getter', () => {
208208
it('calls is empty on a fresh batch', () => {
209-
const batch = ComposableBatch(publicClient, ACCOUNT);
209+
const batch = createComposableBatch(publicClient, ACCOUNT);
210210
expect(batch.calls).toHaveLength(0);
211211
});
212212

213213
it('calls reflects added single call', () => {
214-
const batch = ComposableBatch(publicClient, ACCOUNT);
214+
const batch = createComposableBatch(publicClient, ACCOUNT);
215215
const call = batch
216216
.contract(USDC, erc20Abi)
217217
.write({ functionName: 'transfer', args: [WETH, 1n] });
@@ -221,7 +221,7 @@ describe('ComposableBatch — calls getter', () => {
221221
});
222222

223223
it('calls reflects added array of calls', () => {
224-
const batch = ComposableBatch(publicClient, ACCOUNT);
224+
const batch = createComposableBatch(publicClient, ACCOUNT);
225225
const token = batch.contract(USDC, erc20Abi);
226226
batch.add([
227227
token.write({ functionName: 'transfer', args: [WETH, 1n] }),
@@ -231,14 +231,14 @@ describe('ComposableBatch — calls getter', () => {
231231
});
232232

233233
it('calls is empty after clear()', () => {
234-
const batch = ComposableBatch(publicClient, ACCOUNT);
234+
const batch = createComposableBatch(publicClient, ACCOUNT);
235235
batch.add(batch.contract(USDC, erc20Abi).write({ functionName: 'transfer', args: [WETH, 1n] }));
236236
batch.clear();
237237
expect(batch.calls).toHaveLength(0);
238238
});
239239

240240
it('calls returns a copy — mutating it does not affect the batch', () => {
241-
const batch = ComposableBatch(publicClient, ACCOUNT);
241+
const batch = createComposableBatch(publicClient, ACCOUNT);
242242
batch.add(batch.contract(USDC, erc20Abi).write({ functionName: 'transfer', args: [WETH, 1n] }));
243243
const snapshot = batch.calls;
244244
snapshot.pop();
@@ -251,7 +251,7 @@ describe('ComposableBatch — calls getter', () => {
251251
// ---------------------------------------------------------------------------
252252

253253
describe('ComposableBatch — contract', () => {
254-
const batch = ComposableBatch(publicClient, ACCOUNT);
254+
const batch = createComposableBatch(publicClient, ACCOUNT);
255255
const factory = batch.contract(UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
256256

257257
it('returns a ContractInstance with the correct address', () => {

src/core/batch/batch.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Address, Chain, PublicClient, Transport } from 'viem';
2-
import { contract } from '../contract';
2+
import { createContract } from '../contract';
33
import { type ComposableCall, encodeExecuteComposable } from '../encoding';
4-
import { storage } from '../storage';
5-
import { ERC20Token, NativeToken } from '../token';
4+
import { createStorage } from '../storage';
5+
import { createERC20Token, createNativeToken } from '../token';
66
import type { ComposableBatchInstance } from './types';
77

8-
export function ComposableBatch<
8+
export function createComposableBatch<
99
TTransport extends Transport = Transport,
1010
TChain extends Chain | undefined = Chain | undefined,
1111
>(
@@ -21,16 +21,16 @@ export function ComposableBatch<
2121
return calls.length;
2222
},
2323
erc20Token(tokenAddress) {
24-
return ERC20Token(publicClient, tokenAddress, accountAddress);
24+
return createERC20Token(publicClient, tokenAddress, accountAddress);
2525
},
2626
nativeToken() {
27-
return NativeToken(publicClient, accountAddress);
27+
return createNativeToken(publicClient, accountAddress);
2828
},
2929
contract(address, abi) {
30-
return contract(publicClient, address, abi);
30+
return createContract(publicClient, address, abi);
3131
},
3232
storage() {
33-
return storage(publicClient, accountAddress);
33+
return createStorage(publicClient, accountAddress);
3434
},
3535
get calls() {
3636
return [...calls];

src/core/contract/contract.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getAddress } from 'viem';
22
import { describe, expect, it } from 'vitest';
33
import { publicClient } from '../../test/utils';
44
import { InputParamFetcherType, InputParamType } from '../encoding';
5-
import { contract } from './contract';
5+
import { createContract } from './contract';
66

77
// Uniswap V3 Factory on Base Sepolia
88
const UNISWAP_V3_FACTORY = getAddress('0x4752ba5DBc23f44D87826276BF6Fd6b1C372aD24');
@@ -94,7 +94,7 @@ const ERC20_WRITE_ABI = ERC20_ABI;
9494
// ---------------------------------------------------------------------------
9595

9696
describe('contract — Uniswap V3 Factory (Base Sepolia)', () => {
97-
const factory = contract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
97+
const factory = createContract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
9898

9999
it('stores the correct address and abi', () => {
100100
expect(factory.address).toBe(UNISWAP_V3_FACTORY);
@@ -135,7 +135,7 @@ describe('contract — Uniswap V3 Factory (Base Sepolia)', () => {
135135
// ---------------------------------------------------------------------------
136136

137137
describe('contract — write (ERC20 on Base Sepolia)', () => {
138-
const token = contract(publicClient, USDC, ERC20_WRITE_ABI);
138+
const token = createContract(publicClient, USDC, ERC20_WRITE_ABI);
139139
const SPENDER = WETH; // arbitrary recipient/spender address
140140

141141
it('write(transfer) returns a ComposableCall', () => {
@@ -220,7 +220,7 @@ describe('contract — write (ERC20 on Base Sepolia)', () => {
220220
});
221221

222222
it('write(transfer) accepts a RuntimeValue for the recipient arg', () => {
223-
const factory = contract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
223+
const factory = createContract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
224224
const runtimeRecipient = factory.runtimeValue({ functionName: 'owner', args: [] });
225225
const call = token.write({ functionName: 'transfer', args: [runtimeRecipient, 1_000_000n] });
226226
expect(call.functionSig).toBe('0xa9059cbb');
@@ -235,7 +235,7 @@ describe('contract — write (ERC20 on Base Sepolia)', () => {
235235
});
236236

237237
it('write(approve) accepts RuntimeValues for both args', () => {
238-
const factory = contract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
238+
const factory = createContract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
239239
const runtimeSpender = factory.runtimeValue({ functionName: 'owner', args: [] });
240240
const runtimeAmount = token.runtimeValue({ functionName: 'totalSupply', args: [] });
241241
const call = token.write({ functionName: 'approve', args: [runtimeSpender, runtimeAmount] });
@@ -248,7 +248,7 @@ describe('contract — write (ERC20 on Base Sepolia)', () => {
248248
// ---------------------------------------------------------------------------
249249

250250
describe('contract — check (ERC20 on Base Sepolia)', () => {
251-
const token = contract(publicClient, USDC, ERC20_ABI);
251+
const token = createContract(publicClient, USDC, ERC20_ABI);
252252

253253
it('check(balanceOf) returns a ComposableCall with a functionSig', () => {
254254
const call = token.check({
@@ -368,7 +368,7 @@ describe('contract — check (ERC20 on Base Sepolia)', () => {
368368
// ---------------------------------------------------------------------------
369369

370370
describe('contract — runtimeValue (Uniswap V3 Factory)', () => {
371-
const factory = contract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
371+
const factory = createContract(publicClient, UNISWAP_V3_FACTORY, UNISWAP_V3_FACTORY_ABI);
372372

373373
it('runtimeValue returns a RuntimeValue with isRuntime=true', () => {
374374
const rv = factory.runtimeValue({ functionName: 'owner', args: [] });

src/core/contract/contract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { getFunctionContextFromAbi } from '../encoding/runtimeAbiEncoding';
2323
import type { AnyData } from '../types';
2424
import type { ContractInstance } from './types';
2525

26-
export function contract<
26+
export function createContract<
2727
const TAbi extends Abi | readonly unknown[],
2828
TTransport extends Transport = Transport,
2929
TChain extends Chain | undefined = Chain | undefined,

src/core/storage/storage.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';
33
import { publicClient } from '../../test/utils';
44
import { InputParamFetcherType, InputParamType } from '../encoding';
55
import { NAMESPACE_STORAGE_CONTRACT_ADDRESS } from './constants';
6-
import { getStorageNamespace, getStorageSlot, storage } from './storage';
6+
import { createStorage, getStorageNamespace, getStorageSlot } from './storage';
77

88
// Arbitrary stable addresses used as account / caller throughout tests
99
const ACCOUNT = getAddress('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'); // vitalik.eth
@@ -86,7 +86,7 @@ describe('getStorageSlot', () => {
8686

8787
describe('storage — instance construction', () => {
8888
it('stores the correct accountAddress', () => {
89-
const instance = storage(publicClient, ACCOUNT);
89+
const instance = createStorage(publicClient, ACCOUNT);
9090
expect(instance.accountAddress).toBe(ACCOUNT);
9191
});
9292
});
@@ -96,7 +96,7 @@ describe('storage — instance construction', () => {
9696
// ---------------------------------------------------------------------------
9797

9898
describe('storage — getStorageKey', () => {
99-
const instance = storage(publicClient, ACCOUNT);
99+
const instance = createStorage(publicClient, ACCOUNT);
100100

101101
it('returns a bigint', async () => {
102102
const key = await instance.getStorageKey();
@@ -120,7 +120,7 @@ describe('storage — getStorageKey', () => {
120120
// ---------------------------------------------------------------------------
121121

122122
describe('storage — write', () => {
123-
const instance = storage(publicClient, ACCOUNT);
123+
const instance = createStorage(publicClient, ACCOUNT);
124124

125125
it('returns a ComposableCall with a functionSig', async () => {
126126
const call = await instance.write({ value: 12345n, storageKey: 1n });
@@ -205,7 +205,7 @@ describe('storage — write', () => {
205205
// Live read of an initialized slot is covered by the integration test.
206206

207207
describe('storage — read', () => {
208-
const instance = storage(publicClient, ACCOUNT);
208+
const instance = createStorage(publicClient, ACCOUNT);
209209

210210
it('rejects for an uninitialized slot', async () => {
211211
// The contract reverts when the slot has no data written to it yet
@@ -218,7 +218,7 @@ describe('storage — read', () => {
218218
// ---------------------------------------------------------------------------
219219

220220
describe('storage — runtimeValue', () => {
221-
const instance = storage(publicClient, ACCOUNT);
221+
const instance = createStorage(publicClient, ACCOUNT);
222222

223223
it('returns a RuntimeValue with isRuntime=true', async () => {
224224
const rv = await instance.runtimeValue({ storageKey: 1n });
@@ -293,7 +293,7 @@ describe('storage — runtimeValue', () => {
293293
// ---------------------------------------------------------------------------
294294

295295
describe('storage — check', () => {
296-
const instance = storage(publicClient, ACCOUNT);
296+
const instance = createStorage(publicClient, ACCOUNT);
297297

298298
it('returns a ComposableCall with a functionSig', async () => {
299299
const call = await instance.check({ constraints: [{ gte: 0n }], storageKey: 1n });

src/core/storage/storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type PublicClient,
88
type Transport,
99
} from 'viem';
10-
import { contract } from '../contract';
10+
import { createContract } from '../contract';
1111
import { toBytes32 } from '../encoding/utils';
1212
import { NAMESPACE_STORAGE_ABI } from './abi';
1313
import { NAMESPACE_STORAGE_CONTRACT_ADDRESS } from './constants';
@@ -88,11 +88,11 @@ export const getStorageSlot = async (
8888
// StorageInstance factory
8989
// ---------------------------------------------------------------------------
9090

91-
export function storage<
91+
export function createStorage<
9292
TTransport extends Transport = Transport,
9393
TChain extends Chain | undefined = Chain | undefined,
9494
>(publicClient: PublicClient<TTransport, TChain>, accountAddress: Address): StorageInstance {
95-
const contractInstance = contract(
95+
const contractInstance = createContract(
9696
publicClient,
9797
NAMESPACE_STORAGE_CONTRACT_ADDRESS,
9898
NAMESPACE_STORAGE_ABI,

0 commit comments

Comments
 (0)