Skip to content

Commit dccd1b7

Browse files
committed
refactor: queries contracts get
1 parent 5a1ee63 commit dccd1b7

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@sablier/deployments",
33
"description": "Deployment data for the Sablier Protocol",
4-
"version": "1.0.0-alpha.44",
4+
"version": "1.0.0-alpha.45",
55
"author": {
66
"name": "Sablier Labs Ltd",
77
"url": "https://sablier.com"

src/contracts/queries.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,31 @@ const queries = {
1111
* - {address}
1212
*/
1313
get: (opts: {
14-
chainId?: number;
14+
chainId: number;
1515
contractAddress?: string;
1616
contractName?: string;
17-
deployment?: Sablier.Deployment;
18-
release?: Sablier.Release;
17+
deployments?: Sablier.Deployment[];
18+
protocol?: Sablier.Protocol;
1919
}): Sablier.Contract | undefined => {
20-
const { contractAddress, contractName, deployment, release, chainId } = opts;
20+
const { chainId, deployments, contractAddress, contractName, protocol } = opts;
2121

2222
if (contractAddress && contractName) {
23-
throw new Error("Cannot specify both contractAddress and contractNam as query options");
23+
throw new Error("Cannot specify both contractAddress and contractName as query options");
2424
}
2525

2626
if (contractName) {
27-
if (deployment) {
28-
return _.find(deployment.contracts, { name: contractName });
29-
}
30-
31-
if (release) {
32-
if (!chainId) {
33-
throw new Error("Cannot specify release without chainId");
34-
}
35-
const dep = _.find(release.deployments, { chainId });
36-
return dep && _.find(dep.contracts, { name: contractName });
27+
if (!deployments) {
28+
throw new Error("Cannot specify contractName without deployments");
3729
}
30+
const dep = _.find(deployments, { chainId });
31+
return dep && _.find(dep.contracts, { name: contractName });
3832
}
3933

4034
if (contractAddress) {
41-
if (!release) {
42-
throw new Error("Cannot specify contractAddress without release");
43-
}
44-
if (!chainId) {
45-
throw new Error("Cannot specify contractAddress without chainId");
35+
if (!protocol) {
36+
throw new Error("Cannot specify contractAddress without protocol");
4637
}
47-
return _.get(catalog, [release.protocol, chainId, contractAddress]);
38+
return _.get(catalog, [protocol, chainId, contractAddress]);
4839
}
4940

5041
return undefined;

tests/contracts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("Contract catalog", () => {
4444
const entry = queries.contracts.get({
4545
chainId: deployment.chainId,
4646
contractAddress: lowercaseAddress,
47-
release,
47+
protocol: release.protocol,
4848
});
4949
expect(entry).toStrictEqual(contract);
5050
});

0 commit comments

Comments
 (0)