From c9b4fb5de5645cd7fd321847a622522f75f75dad Mon Sep 17 00:00:00 2001 From: DR497 <47689875+dr497@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:42:12 +0800 Subject: [PATCH] js: allow separate fee payer in createSub --- js/src/bindings.ts | 6 ++++-- js/tests/reverse.test.ts | 2 +- js/tests/sub.test.ts | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/js/src/bindings.ts b/js/src/bindings.ts index 4165a3df..ceb80b74 100644 --- a/js/src/bindings.ts +++ b/js/src/bindings.ts @@ -407,12 +407,14 @@ export const createReverseName = async ( * @param subdomain The subdomain to create with or without .sol e.g something.bonfida.sol or something.bonfida * @param owner The owner of the parent domain creating the subdomain * @param space The space to allocate to the subdomain (defaults to 2kb) + * @param feePayer Optional: Specifies a fee payer different from the parent owner */ export const createSubdomain = async ( connection: Connection, subdomain: string, owner: PublicKey, space = 2_000, + feePayer?: PublicKey, ) => { const ixs: TransactionInstruction[] = []; const sub = subdomain.split(".")[0]; @@ -431,7 +433,7 @@ export const createSubdomain = async ( connection, "\0".concat(sub), space, // Hardcode space to 2kB - owner, + feePayer || owner, owner, lamports, undefined, @@ -446,7 +448,7 @@ export const createSubdomain = async ( const [, ix_reverse] = await createReverseName( pubkey, "\0".concat(sub), - owner, + feePayer || owner, parent, owner, ); diff --git a/js/tests/reverse.test.ts b/js/tests/reverse.test.ts index 4a374213..202ee678 100644 --- a/js/tests/reverse.test.ts +++ b/js/tests/reverse.test.ts @@ -18,7 +18,7 @@ test("Create sub", async () => { connection, sub + "." + parent, parentOwner, - 1_000 + 1_000, ); const tx = new Transaction(); tx.add(...ix); diff --git a/js/tests/sub.test.ts b/js/tests/sub.test.ts index 25b3a7ba..69244ebb 100644 --- a/js/tests/sub.test.ts +++ b/js/tests/sub.test.ts @@ -5,6 +5,7 @@ import { createSubdomain, transferSubdomain } from "../src/bindings"; import { randomBytes } from "crypto"; import { VAULT_OWNER } from "../src/constants"; import { findSubdomains, getDomainKeySync } from "../src/utils"; +import { resolve } from "../src/resolve"; jest.setTimeout(20_000); @@ -68,3 +69,26 @@ test("Find sub domain", async () => { const expectedSub = ["dex", "naming", "test"]; subs.sort().forEach((e, idx) => expect(e).toBe(expectedSub[idx])); }); + +test("Create sub - Fee payer ", async () => { + const sub = "gvbhnjklmjnhb"; + const parent = "bonfida.sol"; + const feePayer = VAULT_OWNER; + + const parentOwner = await resolve(connection, parent); + const [, ix] = await createSubdomain( + connection, + sub + "." + parent, + parentOwner, + 1_000, + feePayer, + ); + const tx = new Transaction(); + tx.add(...ix); + const { blockhash } = await connection.getLatestBlockhash(); + + tx.recentBlockhash = blockhash; + tx.feePayer = VAULT_OWNER; + const res = await connection.simulateTransaction(tx); + expect(res.value.err).toBe(null); +});