Skip to content

Commit bae14b1

Browse files
committed
js: allow separate fee payer in createSub
1 parent 7e466ea commit bae14b1

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

js/src/bindings.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,14 @@ export const createReverseName = async (
407407
* @param subdomain The subdomain to create with or without .sol e.g something.bonfida.sol or something.bonfida
408408
* @param owner The owner of the parent domain creating the subdomain
409409
* @param space The space to allocate to the subdomain (defaults to 2kb)
410+
* @param feePayer Optional: Specifies a fee payer different from the parent owner
410411
*/
411412
export const createSubdomain = async (
412413
connection: Connection,
413414
subdomain: string,
414415
owner: PublicKey,
415416
space = 2_000,
417+
feePayer?: PublicKey,
416418
) => {
417419
const ixs: TransactionInstruction[] = [];
418420
const sub = subdomain.split(".")[0];
@@ -431,7 +433,7 @@ export const createSubdomain = async (
431433
connection,
432434
"\0".concat(sub),
433435
space, // Hardcode space to 2kB
434-
owner,
436+
feePayer || owner,
435437
owner,
436438
lamports,
437439
undefined,
@@ -446,7 +448,7 @@ export const createSubdomain = async (
446448
const [, ix_reverse] = await createReverseName(
447449
pubkey,
448450
"\0".concat(sub),
449-
owner,
451+
feePayer || owner,
450452
parent,
451453
owner,
452454
);

js/tests/reverse.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test("Create sub", async () => {
1818
connection,
1919
sub + "." + parent,
2020
parentOwner,
21-
1_000
21+
1_000,
2222
);
2323
const tx = new Transaction();
2424
tx.add(...ix);

js/tests/sub.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { createSubdomain, transferSubdomain } from "../src/bindings";
55
import { randomBytes } from "crypto";
66
import { VAULT_OWNER } from "../src/constants";
77
import { findSubdomains, getDomainKeySync } from "../src/utils";
8+
import { resolve } from "../src/resolve";
89

910
jest.setTimeout(20_000);
1011

@@ -68,3 +69,26 @@ test("Find sub domain", async () => {
6869
const expectedSub = ["dex", "naming", "test"];
6970
subs.sort().forEach((e, idx) => expect(e).toBe(expectedSub[idx]));
7071
});
72+
73+
test("Create sub - Fee payer ", async () => {
74+
const sub = "gvbhnjklmjnhb";
75+
const parent = "bonfida.sol";
76+
const feePayer = VAULT_OWNER;
77+
78+
const parentOwner = await resolve(connection, parent);
79+
const [, ix] = await createSubdomain(
80+
connection,
81+
sub + "." + parent,
82+
parentOwner,
83+
1_000,
84+
feePayer,
85+
);
86+
const tx = new Transaction();
87+
tx.add(...ix);
88+
const { blockhash } = await connection.getLatestBlockhash();
89+
90+
tx.recentBlockhash = blockhash;
91+
tx.feePayer = VAULT_OWNER;
92+
const res = await connection.simulateTransaction(tx);
93+
expect(res.value.err).toBe(null);
94+
});

0 commit comments

Comments
 (0)