Skip to content

Safe allowlist minting #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class HypercertClient implements HypercertClientInterface {
}

const safeTransactions = new SafeTransactions(overrides.safeAddress, this._walletClient, this._getContract());
return safeTransactions.mintHypercert(method, params, overrides);
return safeTransactions.sendTransaction(method, params, overrides);
}

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

const request = await this.simulateRequest(
account,
"mintClaimFromAllowlist",
[account.address, proof, hypercertTokenId, units],
overrides,
);
const accountAddress = overrides?.safeAddress ?? account.address;
const params = [accountAddress, proof, hypercertTokenId, units];

// If a safe address is provided, use the SafeTransactions class
if (overrides?.safeAddress) {
if (!this._walletClient) {
throw new ClientError("Safe address provided but no wallet client found");
}

const safeTransactions = new SafeTransactions(overrides.safeAddress, this._walletClient, this._getContract());
return safeTransactions.sendTransaction("mintClaimFromAllowlist", params, overrides);
}

const request = await this.simulateRequest(account, "mintClaimFromAllowlist", params, overrides);
return this.submitRequest(request);
};

Expand Down
2 changes: 1 addition & 1 deletion src/safe/SafeTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class SafeTransactions {
});
}

public mintHypercert = (
public sendTransaction = (
functionName: string,
params: unknown[],
overrides?: SupportedOverrides,
Expand Down
39 changes: 31 additions & 8 deletions test/safe/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("SafeTransactions", () => {
} as any);
});

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

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

await safeTransactions.mintHypercert(functionName, validParams, {
await safeTransactions.sendTransaction(functionName, validParams, {
safeAddress,
});

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

await safeTransactions.mintHypercert("mintClaim", validParams, {
await safeTransactions.sendTransaction("mintClaim", validParams, {
safeAddress,
});

Expand All @@ -95,7 +95,7 @@ describe("SafeTransactions", () => {
);

try {
await safeTransactions.mintHypercert("mintClaim", validParams, { safeAddress });
await safeTransactions.sendTransaction("mintClaim", validParams, { safeAddress });
expect.fail("Should throw ClientError");
} catch (e) {
expect(e).to.be.instanceOf(ClientError);
Expand All @@ -104,7 +104,7 @@ describe("SafeTransactions", () => {
});

it("follows complete transaction flow", async () => {
const hash = await safeTransactions.mintHypercert("mintClaim", validParams, {
const hash = await safeTransactions.sendTransaction("mintClaim", validParams, {
safeAddress,
});

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

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

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

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

const proposeCall = safeApiKitStub.proposeTransaction.getCall(0);
expect(proposeCall.args[0]).to.deep.include({
Expand All @@ -171,6 +171,29 @@ describe("SafeTransactions", () => {
});
});
});

describe("constructor", () => {
it("throws error when wallet client has no chain ID", () => {
chai.Assertion.expectAssertions(2);

const invalidWalletClient = { ...walletClient, chain: undefined };

try {
new SafeTransactions(
safeAddress,
invalidWalletClient as any,
{
address: contractAddress,
abi: HypercertMinterAbi,
} as any,
);
expect.fail("Should throw Error");
} catch (e) {
expect(e).to.be.instanceOf(Error);
expect((e as Error).message).to.eq("No chain ID found in wallet client");
}
});
});
});

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