Skip to content

Commit 6d8641c

Browse files
authored
Merge pull request #38 from hypercerts-org/safe-allowlist-minting
Safe allowlist minting
2 parents 3930923 + 17b89bf commit 6d8641c

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

src/client.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export class HypercertClient implements HypercertClientInterface {
253253
}
254254

255255
const safeTransactions = new SafeTransactions(overrides.safeAddress, this._walletClient, this._getContract());
256-
return safeTransactions.mintHypercert(method, params, overrides);
256+
return safeTransactions.sendTransaction(method, params, overrides);
257257
}
258258

259259
const request = await this.simulateRequest(account, method, params, overrides);
@@ -469,6 +469,8 @@ export class HypercertClient implements HypercertClientInterface {
469469
* This function handles the claiming of a fraction from an allowlist for the connected account.
470470
* It verifies the Merkle proof if a root is provided and then submits the minting request.
471471
*
472+
* If you provide `overrides.safeAddress`, the transaction will be sent as a Safe transaction instead.
473+
*
472474
* @param params - The parameters for the claim operation.
473475
* @param params.hypercertTokenId - The ID of the hypercert token to claim.
474476
* @param params.units - The number of units to claim.
@@ -497,12 +499,20 @@ export class HypercertClient implements HypercertClientInterface {
497499
);
498500
}
499501

500-
const request = await this.simulateRequest(
501-
account,
502-
"mintClaimFromAllowlist",
503-
[account.address, proof, hypercertTokenId, units],
504-
overrides,
505-
);
502+
const accountAddress = overrides?.safeAddress ?? account.address;
503+
const params = [accountAddress, proof, hypercertTokenId, units];
504+
505+
// If a safe address is provided, use the SafeTransactions class
506+
if (overrides?.safeAddress) {
507+
if (!this._walletClient) {
508+
throw new ClientError("Safe address provided but no wallet client found");
509+
}
510+
511+
const safeTransactions = new SafeTransactions(overrides.safeAddress, this._walletClient, this._getContract());
512+
return safeTransactions.sendTransaction("mintClaimFromAllowlist", params, overrides);
513+
}
514+
515+
const request = await this.simulateRequest(account, "mintClaimFromAllowlist", params, overrides);
506516
return this.submitRequest(request);
507517
};
508518

src/safe/SafeTransactions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class SafeTransactions {
3030
});
3131
}
3232

33-
public mintHypercert = (
33+
public sendTransaction = (
3434
functionName: string,
3535
params: unknown[],
3636
overrides?: SupportedOverrides,

test/safe/transactions.test.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe("SafeTransactions", () => {
4040
} as any);
4141
});
4242

43-
describe("mintHypercert", () => {
43+
describe("sendTransaction", () => {
4444
const validParams = [senderAddress, 1000n, "0xcid", 0];
4545

4646
it("correctly encodes function data for transaction", async () => {
@@ -52,7 +52,7 @@ describe("SafeTransactions", () => {
5252
args: validParams,
5353
});
5454

55-
await safeTransactions.mintHypercert(functionName, validParams, {
55+
await safeTransactions.sendTransaction(functionName, validParams, {
5656
safeAddress,
5757
});
5858

@@ -70,7 +70,7 @@ describe("SafeTransactions", () => {
7070
it("uses correct nonce from API", async () => {
7171
safeApiKitStub.getNextNonce.resolves("42");
7272

73-
await safeTransactions.mintHypercert("mintClaim", validParams, {
73+
await safeTransactions.sendTransaction("mintClaim", validParams, {
7474
safeAddress,
7575
});
7676

@@ -95,7 +95,7 @@ describe("SafeTransactions", () => {
9595
);
9696

9797
try {
98-
await safeTransactions.mintHypercert("mintClaim", validParams, { safeAddress });
98+
await safeTransactions.sendTransaction("mintClaim", validParams, { safeAddress });
9999
expect.fail("Should throw ClientError");
100100
} catch (e) {
101101
expect(e).to.be.instanceOf(ClientError);
@@ -104,7 +104,7 @@ describe("SafeTransactions", () => {
104104
});
105105

106106
it("follows complete transaction flow", async () => {
107-
const hash = await safeTransactions.mintHypercert("mintClaim", validParams, {
107+
const hash = await safeTransactions.sendTransaction("mintClaim", validParams, {
108108
safeAddress,
109109
});
110110

@@ -123,7 +123,7 @@ describe("SafeTransactions", () => {
123123
safeApiKitStub.proposeTransaction.rejects(new Error(errorMessage));
124124

125125
try {
126-
await safeTransactions.mintHypercert("mintClaim", validParams, { safeAddress });
126+
await safeTransactions.sendTransaction("mintClaim", validParams, { safeAddress });
127127
expect.fail("Should throw SafeTransactionError");
128128
} catch (e) {
129129
expect(e).to.be.instanceOf(SafeTransactionError);
@@ -142,7 +142,7 @@ describe("SafeTransactions", () => {
142142
connectedSafeStub.createTransaction.rejects(new Error(errorMessage));
143143

144144
try {
145-
await safeTransactions.mintHypercert("mintClaim", [senderAddress, 1000n, "0xcid", 0], { safeAddress });
145+
await safeTransactions.sendTransaction("mintClaim", [senderAddress, 1000n, "0xcid", 0], { safeAddress });
146146
expect.fail("Should throw SafeTransactionError");
147147
} catch (e) {
148148
expect(e).to.be.instanceOf(SafeTransactionError);
@@ -155,7 +155,7 @@ describe("SafeTransactions", () => {
155155
});
156156

157157
it("properly proposes transaction with correct parameters", async () => {
158-
await safeTransactions.mintHypercert("mintClaim", [senderAddress, 1000n, "0xcid", 0], { safeAddress });
158+
await safeTransactions.sendTransaction("mintClaim", [senderAddress, 1000n, "0xcid", 0], { safeAddress });
159159

160160
const proposeCall = safeApiKitStub.proposeTransaction.getCall(0);
161161
expect(proposeCall.args[0]).to.deep.include({
@@ -171,6 +171,29 @@ describe("SafeTransactions", () => {
171171
});
172172
});
173173
});
174+
175+
describe("constructor", () => {
176+
it("throws error when wallet client has no chain ID", () => {
177+
chai.Assertion.expectAssertions(2);
178+
179+
const invalidWalletClient = { ...walletClient, chain: undefined };
180+
181+
try {
182+
new SafeTransactions(
183+
safeAddress,
184+
invalidWalletClient as any,
185+
{
186+
address: contractAddress,
187+
abi: HypercertMinterAbi,
188+
} as any,
189+
);
190+
expect.fail("Should throw Error");
191+
} catch (e) {
192+
expect(e).to.be.instanceOf(Error);
193+
expect((e as Error).message).to.eq("No chain ID found in wallet client");
194+
}
195+
});
196+
});
174197
});
175198

176199
function createConnectedSafeStub(contractAddress: string, mockTxHash: `0x${string}`, mockSignature: `0x${string}`) {

0 commit comments

Comments
 (0)