Skip to content

Commit a9bd7ed

Browse files
authored
Merge pull request #104 from SetProtocol/will/isSetController
Add isSet getter to the SystemAPI Controller contract
2 parents e07b676 + 7b6407d commit a9bd7ed

File tree

6 files changed

+93
-8
lines changed

6 files changed

+93
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "set.js",
3-
"version": "0.4.11",
3+
"version": "0.4.12",
44
"description": "A javascript library for interacting with the Set Protocol v2",
55
"keywords": [
66
"set.js",

src/api/SystemAPI.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,14 @@ export default class SystemAPI {
7171
public async getSetsAsync(callerAddress?: Address): Promise<Address[]> {
7272
return await this.controllerWrapper.getSets(callerAddress);
7373
}
74+
75+
/**
76+
* Returns whether or not an address is a SetToken
77+
*
78+
* @param address Address to check
79+
* @return boolean
80+
*/
81+
public async isSetAsync(address, callerAddress?: Address): Promise<boolean> {
82+
return await this.controllerWrapper.isSet(address, callerAddress);
83+
}
7484
}

src/wrappers/set-protocol-v2/ContractWrapper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ export default class ContractWrapper {
7777
*/
7878
public async loadControllerContractAsync(
7979
controllerAddress: Address,
80-
signer: Signer,
80+
callerAddress?: Address,
8181
): Promise<Controller> {
82+
const signer = (this.provider as JsonRpcProvider).getSigner(callerAddress);
8283
const cacheKey = `Controller_${controllerAddress}_${await signer.getAddress()}`;
8384

8485
if (cacheKey in this.cache) {

src/wrappers/set-protocol-v2/ControllerWrapper.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
'use strict';
1818

19-
import { Provider, JsonRpcProvider } from '@ethersproject/providers';
19+
import { Provider } from '@ethersproject/providers';
2020
import { Address } from '@setprotocol/set-protocol-v2/utils/types';
2121

2222
import ContractWrapper from './ContractWrapper';
@@ -36,7 +36,7 @@ export default class ControllerWrapper {
3636

3737
public constructor(provider: Provider, controllerAddress: Address) {
3838
this.provider = provider;
39-
this.contracts = new ContractWrapper(provider);
39+
this.contracts = new ContractWrapper(this.provider);
4040
this.controllerAddress = controllerAddress;
4141
}
4242

@@ -51,7 +51,7 @@ export default class ControllerWrapper {
5151
): Promise<Address[]> {
5252
const controller = await this.contracts.loadControllerContractAsync(
5353
this.controllerAddress,
54-
(this.provider as JsonRpcProvider).getSigner(callerAddress)
54+
callerAddress,
5555
);
5656

5757
return controller.getFactories();
@@ -68,7 +68,7 @@ export default class ControllerWrapper {
6868
): Promise<Address[]> {
6969
const controller = await this.contracts.loadControllerContractAsync(
7070
this.controllerAddress,
71-
(this.provider as JsonRpcProvider).getSigner(callerAddress)
71+
callerAddress,
7272
);
7373

7474
return controller.getModules();
@@ -85,7 +85,7 @@ export default class ControllerWrapper {
8585
): Promise<Address[]> {
8686
const controller = await this.contracts.loadControllerContractAsync(
8787
this.controllerAddress,
88-
(this.provider as JsonRpcProvider).getSigner(callerAddress)
88+
callerAddress,
8989
);
9090

9191
return controller.getResources();
@@ -102,9 +102,27 @@ export default class ControllerWrapper {
102102
): Promise<Address[]> {
103103
const controller = await this.contracts.loadControllerContractAsync(
104104
this.controllerAddress,
105-
(this.provider as JsonRpcProvider).getSigner(callerAddress)
105+
callerAddress,
106106
);
107107

108108
return controller.getSets();
109109
}
110+
111+
/**
112+
* Returns whether or not an address is a SetToken
113+
*
114+
* @param address Address to check
115+
* @return boolean
116+
*/
117+
public async isSet(
118+
address: Address,
119+
callerAddress?: Address,
120+
): Promise<boolean> {
121+
const controller = await this.contracts.loadControllerContractAsync(
122+
this.controllerAddress,
123+
callerAddress,
124+
);
125+
126+
return controller.isSet(address);
127+
}
110128
}

test/api/SystemAPI.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,27 @@ describe('SystemAPI', () => {
9191
expect(controllerWrapper.getSets).to.have.beenCalled;
9292
});
9393
});
94+
95+
describe('#isSetAsync', () => {
96+
let subjectAddress: Address;
97+
let nullCallerAddress: Address;
98+
99+
beforeEach(async () => {
100+
subjectAddress = '0xEC0815AA9B462ed4fC84B5dFc43Fd2a10a54B569';
101+
nullCallerAddress = '0x0000000000000000000000000000000000000000';
102+
});
103+
104+
async function subject(): Promise<boolean> {
105+
return await systemAPI.isSetAsync(subjectAddress, nullCallerAddress);
106+
}
107+
108+
it('should call the ControllerWrapper with correct params', async () => {
109+
await subject();
110+
111+
expect(controllerWrapper.isSet).to.have.beenCalledWith(
112+
subjectAddress,
113+
nullCallerAddress,
114+
);
115+
});
116+
});
94117
});

test/wrappers/set-protocol-v2/ControllerWrapper.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,37 @@ describe('ControllerWrapper', () => {
185185
});
186186
});
187187
});
188+
189+
describe('#isSet', () => {
190+
let subjectCaller: Address;
191+
192+
beforeEach(async () => {
193+
subjectCaller = functionCaller;
194+
});
195+
196+
async function subject(): Promise<boolean> {
197+
return controllerWrapper.isSet(mockSetTokenAddress, subjectCaller);
198+
}
199+
200+
it('returns false', async () => {
201+
const isSet = await subject();
202+
203+
expect(isSet).to.eq(false);
204+
});
205+
206+
describe('when the SetToken is added to the factory', () => {
207+
beforeEach(async () => {
208+
await controller.addFactory(mockSetTokenFactory);
209+
210+
controller = controller.connect(provider.getSigner(mockSetTokenFactory));
211+
await controller.addSet(mockSetTokenAddress);
212+
});
213+
214+
it('returns true', async () => {
215+
const isSet = await subject();
216+
217+
expect(isSet).to.eq(true);
218+
});
219+
});
220+
});
188221
});

0 commit comments

Comments
 (0)