-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
257 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { Buffer } from "buffer"; | ||
|
||
export const NAME_TOKENIZER_ID = new PublicKey( | ||
"nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk", | ||
); | ||
|
||
export const MINT_PREFIX = Buffer.from("tokenized_name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { MINT_PREFIX, NAME_TOKENIZER_ID } from "./const"; | ||
|
||
export const getDomainMint = (domain: PublicKey) => { | ||
const [mint] = PublicKey.findProgramAddressSync( | ||
[MINT_PREFIX, domain.toBuffer()], | ||
NAME_TOKENIZER_ID, | ||
); | ||
return mint; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Connection, | ||
PublicKey, | ||
GetProgramAccountsFilter, | ||
} from "@solana/web3.js"; | ||
import { NAME_TOKENIZER_ID } from "./const"; | ||
import { NftRecord } from "./state"; | ||
|
||
/** | ||
* This function can be used to retrieve a NFT Record given a mint | ||
* | ||
* @param connection A solana RPC connection | ||
* @param mint The mint of the NFT Record | ||
* @returns | ||
*/ | ||
export const getRecordFromMint = async ( | ||
connection: Connection, | ||
mint: PublicKey, | ||
) => { | ||
const filters: GetProgramAccountsFilter[] = [ | ||
{ dataSize: NftRecord.LEN }, | ||
{ | ||
memcmp: { | ||
offset: 0, | ||
bytes: "3", | ||
}, | ||
}, | ||
{ | ||
memcmp: { | ||
offset: 1 + 1 + 32 + 32, | ||
bytes: mint.toBase58(), | ||
}, | ||
}, | ||
]; | ||
|
||
const result = await connection.getProgramAccounts(NAME_TOKENIZER_ID, { | ||
filters, | ||
}); | ||
|
||
return result; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
Connection, | ||
GetProgramAccountsFilter, | ||
PublicKey, | ||
} from "@solana/web3.js"; | ||
import { getDomainMint } from "./getDomainMint"; | ||
import { TOKEN_PROGRAM_ID, getMint } from "@solana/spl-token"; | ||
|
||
/** | ||
* This function can be used to retrieve the owner of a tokenized domain name | ||
* | ||
* @param connection The solana connection object to the RPC node | ||
* @param nameAccount The key of the domain name | ||
* @returns | ||
*/ | ||
export const retrieveNftOwner = async ( | ||
connection: Connection, | ||
nameAccount: PublicKey, | ||
) => { | ||
try { | ||
const mint = getDomainMint(nameAccount); | ||
|
||
const mintInfo = await getMint(connection, mint); | ||
if (mintInfo.supply.toString() === "0") { | ||
return undefined; | ||
} | ||
|
||
const filters: GetProgramAccountsFilter[] = [ | ||
{ | ||
memcmp: { | ||
offset: 0, | ||
bytes: mint.toBase58(), | ||
}, | ||
}, | ||
{ | ||
memcmp: { | ||
offset: 64, | ||
bytes: "2", | ||
}, | ||
}, | ||
{ dataSize: 165 }, | ||
]; | ||
|
||
const result = await connection.getProgramAccounts(TOKEN_PROGRAM_ID, { | ||
filters, | ||
}); | ||
|
||
if (result.length != 1) { | ||
return undefined; | ||
} | ||
|
||
return new PublicKey(result[0].account.data.slice(32, 64)); | ||
} catch { | ||
return undefined; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PublicKey, Connection, SolanaJSONRPCError } from "@solana/web3.js"; | ||
import { getDomainMint } from "./getDomainMint"; | ||
import { AccountLayout } from "@solana/spl-token"; | ||
|
||
export const retrieveNftOwnerV2 = async ( | ||
connection: Connection, | ||
nameAccount: PublicKey, | ||
) => { | ||
try { | ||
const mint = getDomainMint(nameAccount); | ||
|
||
const largestAccounts = await connection.getTokenLargestAccounts(mint); | ||
if (largestAccounts.value.length === 0) { | ||
return null; | ||
} | ||
|
||
const largestAccountInfo = await connection.getAccountInfo( | ||
largestAccounts.value[0].address, | ||
); | ||
|
||
if (!largestAccountInfo) { | ||
return null; | ||
} | ||
|
||
const decoded = AccountLayout.decode(largestAccountInfo.data); | ||
if (decoded.amount.toString() === "1") { | ||
return decoded.owner; | ||
} | ||
return null; | ||
} catch (err) { | ||
if (err instanceof SolanaJSONRPCError && err.code === -32602) { | ||
// Mint does not exist | ||
return null; | ||
} | ||
throw err; | ||
} | ||
}; |
Oops, something went wrong.