@bonfida/spl-name-service 0.1.67 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bindings.d.ts +4 -1
- package/dist/constants.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/instructions.d.ts +19 -0
- package/package.json +3 -2
- package/src/bindings.ts +62 -17
- package/src/constants.ts +23 -0
- package/src/instructions.ts +149 -0
package/dist/bindings.d.ts
CHANGED
|
@@ -51,13 +51,16 @@ export declare function transferNameOwnership(connection: Connection, name: stri
|
|
|
51
51
|
export declare function deleteNameRegistry(connection: Connection, name: string, refundTargetKey: PublicKey, nameClass?: PublicKey, nameParent?: PublicKey): Promise<TransactionInstruction>;
|
|
52
52
|
/**
|
|
53
53
|
* This function can be used to register a .sol domain
|
|
54
|
+
* @param connection The Solana RPC connection object
|
|
54
55
|
* @param name The domain name to register e.g bonfida if you want to register bonfida.sol
|
|
55
56
|
* @param space The domain name account size (max 10kB)
|
|
56
57
|
* @param buyer The public key of the buyer
|
|
57
58
|
* @param buyerTokenAccount The buyer token account (USDC)
|
|
59
|
+
* @param mint Optional mint used to purchase the domain, defaults to USDC
|
|
60
|
+
* @param referrerKey Optional referrer key
|
|
58
61
|
* @returns
|
|
59
62
|
*/
|
|
60
|
-
export declare const registerDomainName: (name: string, space: number, buyer: PublicKey, buyerTokenAccount: PublicKey) => Promise<TransactionInstruction[][]>;
|
|
63
|
+
export declare const registerDomainName: (connection: Connection, name: string, space: number, buyer: PublicKey, buyerTokenAccount: PublicKey, mint?: PublicKey, referrerKey?: PublicKey) => Promise<TransactionInstruction[][]>;
|
|
61
64
|
/**
|
|
62
65
|
*
|
|
63
66
|
* @param nameAccount The name account to create the reverse account for
|
package/dist/constants.d.ts
CHANGED
|
@@ -40,3 +40,8 @@ export declare const TWITTER_ROOT_PARENT_REGISTRY_KEY: PublicKey;
|
|
|
40
40
|
*/
|
|
41
41
|
export declare const SOL_RECORD_SIG_LEN = 96;
|
|
42
42
|
export declare const BONFIDA_USDC_BNB: PublicKey;
|
|
43
|
+
export declare const USDC_MINT: PublicKey;
|
|
44
|
+
export declare const REFERRERS: PublicKey[];
|
|
45
|
+
export declare const TOKENS_SYM_MINT: Map<string, string>;
|
|
46
|
+
export declare const PYTH_MAPPING_ACC: PublicKey;
|
|
47
|
+
export declare const VAULT_OWNER: PublicKey;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@solana/web3.js"),t=require("@solana/spl-token"),r=require("bn.js"),i=require("borsh"),a=require("@ethersproject/sha2"),s=require("@bonfida/name-offers"),n=require("tweetnacl");class o extends r{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(4===t.length)return t;if(t.length>4)throw new Error("Numberu32 too large");const r=Buffer.alloc(4);return t.copy(r),r}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new r([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class c extends r{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(8===t.length)return t;if(t.length>8)throw new Error("Numberu64 too large");const r=Buffer.alloc(8);return t.copy(r),r}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new r([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function u(t,r,i,a,s,n,c,u,l,p,f){const d=[Buffer.from(Int8Array.from([0])),new o(n.length).toBuffer(),n,c.toBuffer(),u.toBuffer()],w=Buffer.concat(d),y=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1}];return l?y.push({pubkey:l,isSigner:!0,isWritable:!1}):y.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),p?y.push({pubkey:p,isSigner:!1,isWritable:!1}):y.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),f&&y.push({pubkey:f,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:y,programId:t,data:w})}function l(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new o(a.length).toBuffer(),a],c=Buffer.concat(n),u=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:t,data:c})}function p(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),l=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&l.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||l.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),l.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:l,programId:t,data:u})}function f(t,r,i,a){const s=[Buffer.from(Int8Array.from([3]))],n=Buffer.concat(s),o=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:o,programId:t,data:n})}class d{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(d.schema,this)}getInstruction(r,i,a,s,n,o,c,u,l,p,f){const d=Buffer.from(this.serialize()),w=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:t.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:w,programId:r,data:d})}}d.schema=new Map([[d,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class w{constructor(e){this.tag=5,this.name=e.name}serialize(){return i.serialize(w.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u){const l=Buffer.from(this.serialize());let p=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0}];if(c){if(!u)throw new Error("Missing parent name owner");p.push({pubkey:c,isSigner:!1,isWritable:!0}),p.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:p,programId:t,data:l})}}w.schema=new Map([[w,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);const y=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),g=Buffer.from("tokenized_name"),m=async(r,i)=>{try{const[a]=await e.PublicKey.findProgramAddress([g,i.toBuffer()],y);if("0"===(await t.getMint(r,a)).supply.toString())return;const s=[{memcmp:{offset:0,bytes:a.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],n=await r.getProgramAccounts(t.TOKEN_PROGRAM_ID,{filters:s});if(1!=n.length)return;return new e.PublicKey(n[0].account.data.slice(32,64))}catch{return}};class b{constructor(t){this.parentName=new e.PublicKey(t.parentName),this.owner=new e.PublicKey(t.owner),this.class=new e.PublicKey(t.class)}static async retrieve(e,t){var r;const a=await e.getAccountInfo(t);if(!a)throw new Error("Invalid name account provided");let s=i.deserializeUnchecked(this.schema,b,a.data);s.data=null===(r=a.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await m(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),a=e=>{if(!e)return;const t=i.deserializeUnchecked(this.schema,b,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>a(null==e?void 0:e.data)))}static async retrieveBatch(e,t){let r=[];const i=[...t];for(;i.length>0;)r.push(...await this._retrieveBatch(e,i.splice(0,100)));return r}}b.HEADER_LEN=96,b.schema=new Map([[b,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class h{constructor(e){this.name=e.name,this.ticker=e.ticker,this.mint=e.mint,this.decimals=e.decimals,this.website=null==e?void 0:e.website,this.logoUri=null==e?void 0:e.logoUri}serialize(){return i.serialize(h.schema,this)}static deserialize(e){return i.deserializeUnchecked(h.schema,h,e)}}h.schema=new Map([[h,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class R{constructor(e){this.mint=e.mint}serialize(){return i.serialize(R.schema,this)}static deserialize(e){return i.deserializeUnchecked(R.schema,R,e)}}R.schema=new Map([[R,{kind:"struct",fields:[["mint",[32]]]}]]);const x=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),S="SPL Name Service",v=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),B=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),k=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),E=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),P=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),I=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),A=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),T=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7");async function N(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return b.retrieve(e,t)}async function K(e){const t=S+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")}async function W(t,r,i){const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=await e.PublicKey.findProgramAddress(a,x);return s}const D=async(e,t=v)=>{let r=await K(e);return{pubkey:await W(r,void 0,t),hashed:r}},_=async(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=await D(r[1]);return{...await D(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await D(r[2]),{pubkey:t}=await D("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await D(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await D(e,v),isSub:!1,parent:void 0}};async function H(e,t,r,i,a){const s=await K(t),n=await W(s,i,a);let o;o=i||(await b.retrieve(e,n)).registry.owner;return f(x,n,r,o)}class O{constructor(e){this.twitterRegistryKey=e.twitterRegistryKey,this.twitterHandle=e.twitterHandle}static async retrieve(e,t){let r=await e.getAccountInfo(t,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return i.deserializeUnchecked(this.schema,O,r.data.slice(b.HEADER_LEN))}}async function L(t,r,a,s,n){const p=await K(s.toString()),f=await W(p,I,A);let d=i.serialize(O.schema,new O({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[u(x,e.SystemProgram.programId,f,s,n,p,new c(await t.getMinimumBalanceForRentExemption(d.length+b.HEADER_LEN)),new o(d.length),I,A,I),l(x,f,new o(0),Buffer.from(d),I)]}O.schema=new Map([[O,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const z=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),F=async(e,t)=>{const r=await W(await K(t.toBase58()),void 0,z),{registry:i}=await b.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return h.deserialize(i.data)},M=e=>{const t=S+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")},U=(t,r,i)=>{const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=e.PublicKey.findProgramAddressSync(a,x);return s};async function C(e,t){const i=M(t.toBase58()),a=U(i,P),{registry:s}=await b.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new r(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}const V=(e,t=v)=>{let r=M(e);return{pubkey:U(r,void 0,t),hashed:r}},j=(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=V(r[1]);return{...V(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=V(r[2]),{pubkey:t}=V("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...V(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...V(e,v),isSub:!1,parent:void 0}};var G;exports.Record=void 0,(G=exports.Record||(exports.Record={})).IPFS="IPFS",G.ARWV="ARWV",G.SOL="SOL",G.ETH="ETH",G.BTC="BTC",G.LTC="LTC",G.DOGE="DOGE",G.Email="email",G.Url="url",G.Discord="discord",G.Github="github",G.Reddit="reddit",G.Twitter="twitter",G.Telegram="telegram",G.Pic="pic",G.SHDW="SHDW",G.POINT="POINT",G.BSC="BSC",G.Injective="INJECT";const q=(e,t)=>{const{pubkey:r}=j(t+"."+e,!0);return r},Y=async(e,t,r)=>{var i,a;const s=q(t,r);let{registry:n}=await b.retrieve(e,s);const o=r===exports.Record.SOL?96:null===(i=n.data)||void 0===i?void 0:i.indexOf(0);return n.data=null===(a=n.data)||void 0===a?void 0:a.slice(0,o),n},X=async(e,t)=>await Y(e,t,exports.Record.SOL),Z=(e,t,r)=>n.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=E,exports.BONFIDA_USDC_BNB=T,exports.HASH_PREFIX=S,exports.MINT_PREFIX=g,exports.Mint=R,exports.NAME_PROGRAM_ID=x,exports.NAME_TOKENIZER_ID=y,exports.NameRegistryState=b,exports.Numberu32=o,exports.Numberu64=c,exports.PYTH_FIDA_PRICE_ACC=k,exports.REGISTER_PROGRAM_ID=B,exports.REVERSE_LOOKUP_CLASS=P,exports.ROOT_DOMAIN_ACCOUNT=v,exports.ReverseTwitterRegistryState=O,exports.SOL_RECORD_SIG_LEN=96,exports.TOKEN_TLD=z,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=A,exports.TWITTER_VERIFICATION_AUTHORITY=I,exports.TokenData=h,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await K(e),s=await W(a,void 0,A);return[l(x,s,new o(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await K(t),n=await W(s,void 0,A);let o=[p(x,n,i,r,void 0)];const c=await K(r.toString());return await W(c,I,void 0),o.push(await H(e,r.toString(),a,I,A)),o=o.concat(await L(e,t,n,i,a)),o},exports.checkSolRecord=Z,exports.createInstruction=u,exports.createNameRegistry=async function(t,r,i,a,s,n,l,p){const f=await K(r),d=await W(f,l,p),w=n||await t.getMinimumBalanceForRentExemption(i);let y;if(p){const{registry:e}=await N(t,p);y=e.owner}return u(x,e.SystemProgram.programId,d,s,a,f,new c(w),new o(i),l,p,y)},exports.createReverseInstruction=w,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([B.toBuffer()],B),o=await K(t.toBase58()),c=await W(o,n,a);return[[],[new w({name:r}).getInstruction(B,e.SYSVAR_RENT_PUBKEY,x,v,c,n,i,a,s)]]},exports.createReverseTwitterRegistry=L,exports.createV2Instruction=d,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await K(r),l=await W(n,void 0,A),p=await t.getMinimumBalanceForRentExemption(a+b.HEADER_LEN);let f=[u(x,e.SystemProgram.programId,l,i,s,n,new c(p),new o(a),void 0,A,I)];return f=f.concat(await L(t,r,l,i,s)),f},exports.deleteInstruction=f,exports.deleteNameRegistry=H,exports.deleteTwitterRegistry=async function(e,t){const r=await K(e),i=await W(r,void 0,A),a=await K(t.toString()),s=await W(a,I,A);return[f(x,i,t,t),f(x,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:P.toBase58()}}],i=await e.getProgramAccounts(x,{filters:r}),a=await C(e,t),s=i.map((e=>{var t;return null===(t=e.account.data.slice(97).toString("utf-8"))||void 0===t?void 0:t.split("\0").join("")})),n=s.map((e=>j(e+"."+a).pubkey)),o=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!o[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:v.toBase58()}}];return(await e.getProgramAccounts(x,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:v.toBase58()}}];return await e.getProgramAccounts(x,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await Y(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await Y(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await Y(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await Y(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await Y(e,t,exports.Record.DOGE),exports.getDomainKey=_,exports.getDomainKeySync=j,exports.getEmailRecord=async(e,t)=>await Y(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await Y(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await s.FavouriteDomain.getKey(s.NAME_OFFERS_ID,new e.PublicKey(r)),a=await s.FavouriteDomain.retrieve(t,i),n=await C(t,a.nameAccount);return{domain:a.nameAccount,reverse:n}},exports.getGithubRecord=async(e,t)=>await Y(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await K(r.toString()),a=await W(i,I,A);let s=await O.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=K,exports.getHashedNameSync=M,exports.getInjectiveRecord=async(e,t)=>await Y(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await Y(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await Y(e,t,exports.Record.LTC),exports.getNameAccountKey=W,exports.getNameAccountKeySync=U,exports.getNameOwner=N,exports.getPicRecord=async(e,t)=>await Y(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await Y(e,t,exports.Record.POINT),exports.getRecord=Y,exports.getRecordKeySync=q,exports.getRedditRecord=async(e,t)=>await Y(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await _(e),a=await K(r.toBase58());return await W(a,P,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=j(e),a=M(r.toBase58());return U(a,P,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await Y(e,t,exports.Record.SHDW),exports.getSolRecord=X,exports.getTelegramRecord=async(e,t)=>await Y(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=F,exports.getTokenInfoFromName=async(t,r)=>{const i=await W(await K(r),void 0,z),{registry:a}=await b.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(R.deserialize(a.data).mint);return await F(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:A.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:I.toBase58()}}],s=await t.getProgramAccounts(x,{filters:a});for(const t of s)if(t.account.data.length>b.HEADER_LEN+32){let r=t.account.data.slice(b.HEADER_LEN),a=i.deserializeUnchecked(O.schema,O,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await Y(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await K(t),i=await W(r,void 0,A),{registry:a}=await b.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:A.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(x,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(b.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await K(e);return await W(t,void 0,A)},exports.getUrlRecord=async(e,t)=>await Y(e,t,exports.Record.Url),exports.performReverseLookup=async function(e,t){const i=await K(t.toBase58()),a=await W(i,P),{registry:s}=await b.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new r(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()},exports.performReverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=await K(e.toBase58()),r=await W(t,P);i.push(r)}return(await b.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new r(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.registerDomainName=async(t,r,i,a)=>{const[s]=await e.PublicKey.findProgramAddress([B.toBuffer()],B),n=await K(t),o=await W(n,void 0,v),c=await K(o.toBase58()),u=await W(c,s),[l]=await e.PublicKey.findProgramAddress([o.toBuffer()],B);return[[],[new d({name:t,space:r}).getInstruction(B,e.SYSVAR_RENT_PUBKEY,x,v,o,u,s,i,a,T,l)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=j(r),{registry:a,nftOwner:s}=await b.retrieve(t,i);if(s)return s;try{const i=j(exports.Record.SOL+"."+r,!0),s=await X(t,r);if(!s.data)throw new Error("Invalid SOL record data");const n=new TextEncoder,o=Buffer.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),c=n.encode(o.toString("hex"));if(!Z(c,s.data.slice(32),a.owner))throw new Error("Signature invalid");return new e.PublicKey(s.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return a.owner},exports.retrieveNftOwner=m,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(y,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=C,exports.reverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=M(e.toBase58()),r=U(t,P);i.push(r)}return(await b.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new r(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.transferInstruction=p,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await K(t),o=await W(n,i,a);let c;return c=i||(await b.retrieve(e,o)).registry.owner,p(x,o,r,c,i,a,s)},exports.updateInstruction=l,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await K(t),c=await W(n,a,s);let u;return u=a||(await b.retrieve(e,c)).registry.owner,l(x,c,new o(r),i,u)};
|
|
1
|
+
"use strict";var e=require("@solana/web3.js"),t=require("@solana/spl-token"),r=require("bn.js"),i=require("borsh"),a=require("@ethersproject/sha2"),s=require("@pythnetwork/client"),n=require("@bonfida/name-offers"),o=require("tweetnacl");class c extends r{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(4===t.length)return t;if(t.length>4)throw new Error("Numberu32 too large");const r=Buffer.alloc(4);return t.copy(r),r}static fromBuffer(e){if(4!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new r([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}class u extends r{toBuffer(){const e=super.toArray().reverse(),t=Buffer.from(e);if(8===t.length)return t;if(t.length>8)throw new Error("Numberu64 too large");const r=Buffer.alloc(8);return t.copy(r),r}static fromBuffer(e){if(8!==e.length)throw new Error(`Invalid buffer length: ${e.length}`);return new r([...e].reverse().map((e=>`00${e.toString(16)}`.slice(-2))).join(""),16)}}function p(t,r,i,a,s,n,o,u,p,l,f){const d=[Buffer.from(Int8Array.from([0])),new c(n.length).toBuffer(),n,o.toBuffer(),u.toBuffer()],y=Buffer.concat(d),w=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!0,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1}];return p?w.push({pubkey:p,isSigner:!0,isWritable:!1}):w.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),l?w.push({pubkey:l,isSigner:!1,isWritable:!1}):w.push({pubkey:new e.PublicKey(Buffer.alloc(32)),isSigner:!1,isWritable:!1}),f&&w.push({pubkey:f,isSigner:!0,isWritable:!1}),new e.TransactionInstruction({keys:w,programId:t,data:y})}function l(t,r,i,a,s){const n=[Buffer.from(Int8Array.from([1])),i.toBuffer(),new c(a.length).toBuffer(),a],o=Buffer.concat(n),u=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!0,isWritable:!1}];return new e.TransactionInstruction({keys:u,programId:t,data:o})}function f(t,r,i,a,s,n,o){const c=[Buffer.from(Int8Array.from([2])),i.toBuffer()],u=Buffer.concat(c),p=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:o||a,isSigner:!0,isWritable:!1}];return s&&p.push({pubkey:s,isSigner:!0,isWritable:!1}),o&&n&&(s||p.push({pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1}),p.push({pubkey:n,isSigner:!1,isWritable:!1})),new e.TransactionInstruction({keys:p,programId:t,data:u})}function d(t,r,i,a){const s=[Buffer.from(Int8Array.from([3]))],n=Buffer.concat(s),o=[{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!0}];return new e.TransactionInstruction({keys:o,programId:t,data:n})}class y{constructor(e){this.tag=9,this.name=e.name,this.space=e.space}serialize(){return i.serialize(y.schema,this)}getInstruction(r,i,a,s,n,o,c,u,p,l,f){const d=Buffer.from(this.serialize()),y=[{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:e.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!0,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:t.TOKEN_PROGRAM_ID,isSigner:!1,isWritable:!1},{pubkey:f,isSigner:!1,isWritable:!1}];return new e.TransactionInstruction({keys:y,programId:r,data:d})}}y.schema=new Map([[y,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"]]}]]);class w{constructor(e){this.tag=5,this.name=e.name}serialize(){return i.serialize(w.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u){const p=Buffer.from(this.serialize());let l=[{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:e.PublicKey.default,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0}];if(c){if(!u)throw new Error("Missing parent name owner");l.push({pubkey:c,isSigner:!1,isWritable:!0}),l.push({pubkey:u,isSigner:!0,isWritable:!1})}return new e.TransactionInstruction({keys:l,programId:t,data:p})}}w.schema=new Map([[w,{kind:"struct",fields:[["tag","u8"],["name","string"]]}]]);class g{constructor(e){this.tag=13,this.name=e.name,this.space=e.space,this.referrerIdxOpt=e.referrerIdxOpt}serialize(){return i.serialize(g.schema,this)}getInstruction(t,r,i,a,s,n,o,c,u,p,l,f,d,y,w,g,m){const b=Buffer.from(this.serialize());let h=[];return h.push({pubkey:r,isSigner:!1,isWritable:!1}),h.push({pubkey:i,isSigner:!1,isWritable:!1}),h.push({pubkey:a,isSigner:!1,isWritable:!0}),h.push({pubkey:s,isSigner:!1,isWritable:!0}),h.push({pubkey:n,isSigner:!1,isWritable:!1}),h.push({pubkey:o,isSigner:!1,isWritable:!1}),h.push({pubkey:c,isSigner:!0,isWritable:!0}),h.push({pubkey:u,isSigner:!1,isWritable:!0}),h.push({pubkey:p,isSigner:!1,isWritable:!1}),h.push({pubkey:l,isSigner:!1,isWritable:!1}),h.push({pubkey:f,isSigner:!1,isWritable:!1}),h.push({pubkey:d,isSigner:!1,isWritable:!0}),h.push({pubkey:y,isSigner:!1,isWritable:!1}),h.push({pubkey:w,isSigner:!1,isWritable:!1}),h.push({pubkey:g,isSigner:!1,isWritable:!1}),m&&h.push({pubkey:m,isSigner:!1,isWritable:!0}),new e.TransactionInstruction({keys:h,programId:t,data:b})}}g.schema=new Map([[g,{kind:"struct",fields:[["tag","u8"],["name","string"],["space","u32"],["referrerIdxOpt",{kind:"option",type:"u16"}]]}]]);const m=new e.PublicKey("nftD3vbNkNqfj2Sd3HZwbpw4BxxKWr4AjGb9X38JeZk"),b=Buffer.from("tokenized_name"),h=async(r,i)=>{try{const[a]=await e.PublicKey.findProgramAddress([b,i.toBuffer()],m);if("0"===(await t.getMint(r,a)).supply.toString())return;const s=[{memcmp:{offset:0,bytes:a.toBase58()}},{memcmp:{offset:64,bytes:"2"}},{dataSize:165}],n=await r.getProgramAccounts(t.TOKEN_PROGRAM_ID,{filters:s});if(1!=n.length)return;return new e.PublicKey(n[0].account.data.slice(32,64))}catch{return}};class S{constructor(t){this.parentName=new e.PublicKey(t.parentName),this.owner=new e.PublicKey(t.owner),this.class=new e.PublicKey(t.class)}static async retrieve(e,t){var r;const a=await e.getAccountInfo(t);if(!a)throw new Error("Invalid name account provided");let s=i.deserializeUnchecked(this.schema,S,a.data);s.data=null===(r=a.data)||void 0===r?void 0:r.slice(this.HEADER_LEN);return{registry:s,nftOwner:await h(e,t)}}static async _retrieveBatch(e,t){const r=await e.getMultipleAccountsInfo(t),a=e=>{if(!e)return;const t=i.deserializeUnchecked(this.schema,S,e);return t.data=null==e?void 0:e.slice(this.HEADER_LEN),t};return r.map((e=>a(null==e?void 0:e.data)))}static async retrieveBatch(e,t){let r=[];const i=[...t];for(;i.length>0;)r.push(...await this._retrieveBatch(e,i.splice(0,100)));return r}}S.HEADER_LEN=96,S.schema=new Map([[S,{kind:"struct",fields:[["parentName",[32]],["owner",[32]],["class",[32]]]}]]);class R{constructor(e){this.name=e.name,this.ticker=e.ticker,this.mint=e.mint,this.decimals=e.decimals,this.website=null==e?void 0:e.website,this.logoUri=null==e?void 0:e.logoUri}serialize(){return i.serialize(R.schema,this)}static deserialize(e){return i.deserializeUnchecked(R.schema,R,e)}}R.schema=new Map([[R,{kind:"struct",fields:[["name","string"],["ticker","string"],["mint",[32]],["decimals","u8"],["website",{kind:"option",type:"string"}],["logoUri",{kind:"option",type:"string"}]]}]]);class x{constructor(e){this.mint=e.mint}serialize(){return i.serialize(x.schema,this)}static deserialize(e){return i.deserializeUnchecked(x.schema,x,e)}}x.schema=new Map([[x,{kind:"struct",fields:[["mint",[32]]]}]]);const k=new e.PublicKey("namesLPneVptA9Z5rqUDD9tMTWEJwofgaYwp8cawRkX"),v="SPL Name Service",E=new e.PublicKey("58PwtjSDuFHuUkYjH9BYnnQKHfwo9reZhC2zMJv9JPkx"),B=new e.PublicKey("jCebN34bUfdeUYJT13J1yG16XWQpt5PDx6Mse9GUqhR"),P=new e.PublicKey("ETp9eKXVv1dWwHSpsXRUuXHmw24PwRkttCGVgpZEY9zF"),I=new e.PublicKey("AUoZ3YAhV3b2rZeEH93UMZHXUZcTramBvb4d9YEVySkc"),A=new e.PublicKey("33m47vH6Eav6jr5Ry86XjhRft2jRBLDnDgPSHoquXi2Z"),T=new e.PublicKey("FvPH7PrVrLGKPfqaf3xJodFTjZriqrAXXLTVWEorTFBi"),W=new e.PublicKey("4YcexoW3r78zz16J2aqmukBLRwGq6rAvWzJpkYAXqebv"),K=new e.PublicKey("DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"),N=new e.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),D=[],_=new Map([["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v","USDC"],["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","USDT"],["So11111111111111111111111111111111111111112","SOL"],["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp","FIDA"],["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf","ETH"],["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So","MSOL"]]),O=new e.PublicKey("AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"),H=new e.PublicKey("GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi");async function L(e,t){if(!await e.getAccountInfo(t))throw new Error("Unable to find the given account.");return S.retrieve(e,t)}async function F(e){const t=v+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")}async function M(t,r,i){const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=await e.PublicKey.findProgramAddress(a,k);return s}const C=async(e,t=E)=>{let r=await F(e);return{pubkey:await M(r,void 0,t),hashed:r}},z=async(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=await C(r[1]);return{...await C(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=await C(r[2]),{pubkey:t}=await C("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...await C(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...await C(e,E),isSub:!1,parent:void 0}},U=e=>{const t=v+e,r=a.sha256(Buffer.from(t,"utf8")).slice(2);return Buffer.from(r,"hex")},G=(t,r,i)=>{const a=[t];r?a.push(r.toBuffer()):a.push(Buffer.alloc(32)),i?a.push(i.toBuffer()):a.push(Buffer.alloc(32));const[s]=e.PublicKey.findProgramAddressSync(a,k);return s};async function Y(e,t){const i=U(t.toBase58()),a=G(i,A),{registry:s}=await S.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new r(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()}const q=(e,t=E)=>{let r=U(e);return{pubkey:G(r,void 0,t),hashed:r}},V=(e,t=!1)=>{e.endsWith(".sol")&&(e=e.slice(0,-4));const r=e.split(".");if(2===r.length){const e=Buffer.from([t?1:0]).toString().concat(r[0]),{pubkey:i}=q(r[1]);return{...q(e,i),isSub:!0,parent:i}}if(3===r.length&&t){const{pubkey:e}=q(r[2]),{pubkey:t}=q("\0".concat(r[1]),e),i=Buffer.from([1]).toString();return{...q(i.concat(r[0]),t),isSub:!0,parent:e,isSubRecord:!0}}if(r.length>=3)throw new Error("Invalid derivation input");return{...q(e,E),isSub:!1,parent:void 0}};async function j(e,t,r,i,a){const s=await F(t),n=await M(s,i,a);let o;o=i||(await S.retrieve(e,n)).registry.owner;return d(k,n,r,o)}class Z{constructor(e){this.twitterRegistryKey=e.twitterRegistryKey,this.twitterHandle=e.twitterHandle}static async retrieve(e,t){let r=await e.getAccountInfo(t,"processed");if(!r)throw new Error("Invalid reverse Twitter account provided");return i.deserializeUnchecked(this.schema,Z,r.data.slice(S.HEADER_LEN))}}async function X(t,r,a,s,n){const o=await F(s.toString()),f=await M(o,T,W);let d=i.serialize(Z.schema,new Z({twitterRegistryKey:a.toBytes(),twitterHandle:r}));return[p(k,e.SystemProgram.programId,f,s,n,o,new u(await t.getMinimumBalanceForRentExemption(d.length+S.HEADER_LEN)),new c(d.length),T,W,T),l(k,f,new c(0),Buffer.from(d),T)]}Z.schema=new Map([[Z,{kind:"struct",fields:[["twitterRegistryKey",[32]],["twitterHandle","string"]]}]]);const J=new e.PublicKey("6NSu2tci4apRKQtt257bAVcvqYjB3zV2H1dWo56vgpa6"),Q=async(e,t)=>{const r=await M(await F(t.toBase58()),void 0,J),{registry:i}=await S.retrieve(e,r);if(!i.data)throw new Error("Invalid account data");return R.deserialize(i.data)};var $;exports.Record=void 0,($=exports.Record||(exports.Record={})).IPFS="IPFS",$.ARWV="ARWV",$.SOL="SOL",$.ETH="ETH",$.BTC="BTC",$.LTC="LTC",$.DOGE="DOGE",$.Email="email",$.Url="url",$.Discord="discord",$.Github="github",$.Reddit="reddit",$.Twitter="twitter",$.Telegram="telegram",$.Pic="pic",$.SHDW="SHDW",$.POINT="POINT",$.BSC="BSC",$.Injective="INJECT";const ee=(e,t)=>{const{pubkey:r}=V(t+"."+e,!0);return r},te=async(e,t,r)=>{var i,a;const s=ee(t,r);let{registry:n}=await S.retrieve(e,s);const o=r===exports.Record.SOL?96:null===(i=n.data)||void 0===i?void 0:i.indexOf(0);return n.data=null===(a=n.data)||void 0===a?void 0:a.slice(0,o),n},re=async(e,t)=>await te(e,t,exports.Record.SOL),ie=(e,t,r)=>o.sign.detached.verify(e,t,r.toBytes());exports.BONFIDA_FIDA_BNB=I,exports.BONFIDA_USDC_BNB=K,exports.HASH_PREFIX=v,exports.MINT_PREFIX=b,exports.Mint=x,exports.NAME_PROGRAM_ID=k,exports.NAME_TOKENIZER_ID=m,exports.NameRegistryState=S,exports.Numberu32=c,exports.Numberu64=u,exports.PYTH_FIDA_PRICE_ACC=P,exports.PYTH_MAPPING_ACC=O,exports.REFERRERS=D,exports.REGISTER_PROGRAM_ID=B,exports.REVERSE_LOOKUP_CLASS=A,exports.ROOT_DOMAIN_ACCOUNT=E,exports.ReverseTwitterRegistryState=Z,exports.SOL_RECORD_SIG_LEN=96,exports.TOKENS_SYM_MINT=_,exports.TOKEN_TLD=J,exports.TWITTER_ROOT_PARENT_REGISTRY_KEY=W,exports.TWITTER_VERIFICATION_AUTHORITY=T,exports.TokenData=R,exports.USDC_MINT=N,exports.VAULT_OWNER=H,exports.changeTwitterRegistryData=async function(e,t,r,i){const a=await F(e),s=await M(a,void 0,W);return[l(k,s,new c(r),i,t)]},exports.changeVerifiedPubkey=async function(e,t,r,i,a){const s=await F(t),n=await M(s,void 0,W);let o=[f(k,n,i,r,void 0)];const c=await F(r.toString());return await M(c,T,void 0),o.push(await j(e,r.toString(),a,T,W)),o=o.concat(await X(e,t,n,i,a)),o},exports.checkSolRecord=ie,exports.createInstruction=p,exports.createInstructionV3=g,exports.createNameRegistry=async function(t,r,i,a,s,n,o,l){const f=await F(r),d=await M(f,o,l),y=n||await t.getMinimumBalanceForRentExemption(i);let w;if(l){const{registry:e}=await L(t,l);w=e.owner}return p(k,e.SystemProgram.programId,d,s,a,f,new u(y),new c(i),o,l,w)},exports.createReverseInstruction=w,exports.createReverseName=async(t,r,i,a,s)=>{let[n]=await e.PublicKey.findProgramAddress([B.toBuffer()],B),o=await F(t.toBase58()),c=await M(o,n,a);return[[],[new w({name:r}).getInstruction(B,e.SYSVAR_RENT_PUBKEY,k,E,c,n,i,a,s)]]},exports.createReverseTwitterRegistry=X,exports.createV2Instruction=y,exports.createVerifiedTwitterRegistry=async function(t,r,i,a,s){const n=await F(r),o=await M(n,void 0,W),l=await t.getMinimumBalanceForRentExemption(a+S.HEADER_LEN);let f=[p(k,e.SystemProgram.programId,o,i,s,n,new u(l),new c(a),void 0,W,T)];return f=f.concat(await X(t,r,o,i,s)),f},exports.deleteInstruction=d,exports.deleteNameRegistry=j,exports.deleteTwitterRegistry=async function(e,t){const r=await F(e),i=await M(r,void 0,W),a=await F(t.toString()),s=await M(a,T,W);return[d(k,i,t,t),d(k,s,t,t)]},exports.findSubdomains=async(e,t)=>{const r=[{memcmp:{offset:0,bytes:t.toBase58()}},{memcmp:{offset:64,bytes:A.toBase58()}}],i=await e.getProgramAccounts(k,{filters:r}),a=await Y(e,t),s=i.map((e=>{var t;return null===(t=e.account.data.slice(97).toString("utf-8"))||void 0===t?void 0:t.split("\0").join("")})),n=s.map((e=>V(e+"."+a).pubkey)),o=await e.getMultipleAccountsInfo(n);return s.filter(((e,t)=>!!o[t]))},exports.getAllDomains=async function(e,t){const r=[{memcmp:{offset:32,bytes:t.toBase58()}},{memcmp:{offset:0,bytes:E.toBase58()}}];return(await e.getProgramAccounts(k,{filters:r})).map((e=>e.pubkey))},exports.getAllRegisteredDomains=async e=>{const t=[{memcmp:{offset:0,bytes:E.toBase58()}}];return await e.getProgramAccounts(k,{dataSlice:{offset:32,length:32},filters:t})},exports.getArweaveRecord=async(e,t)=>await te(e,t,exports.Record.ARWV),exports.getBscRecord=async(e,t)=>await te(e,t,exports.Record.BSC),exports.getBtcRecord=async(e,t)=>await te(e,t,exports.Record.BTC),exports.getDiscordRecord=async(e,t)=>await te(e,t,exports.Record.Discord),exports.getDogeRecord=async(e,t)=>await te(e,t,exports.Record.DOGE),exports.getDomainKey=z,exports.getDomainKeySync=V,exports.getEmailRecord=async(e,t)=>await te(e,t,exports.Record.Email),exports.getEthRecord=async(e,t)=>await te(e,t,exports.Record.ETH),exports.getFavoriteDomain=async(t,r)=>{const[i]=await n.FavouriteDomain.getKey(n.NAME_OFFERS_ID,new e.PublicKey(r)),a=await n.FavouriteDomain.retrieve(t,i),s=await Y(t,a.nameAccount);return{domain:a.nameAccount,reverse:s}},exports.getGithubRecord=async(e,t)=>await te(e,t,exports.Record.Github),exports.getHandleAndRegistryKey=async function(t,r){const i=await F(r.toString()),a=await M(i,T,W);let s=await Z.retrieve(t,a);return[s.twitterHandle,new e.PublicKey(s.twitterRegistryKey)]},exports.getHashedName=F,exports.getHashedNameSync=U,exports.getInjectiveRecord=async(e,t)=>await te(e,t,exports.Record.Injective),exports.getIpfsRecord=async(e,t)=>await te(e,t,exports.Record.IPFS),exports.getLtcRecord=async(e,t)=>await te(e,t,exports.Record.LTC),exports.getNameAccountKey=M,exports.getNameAccountKeySync=G,exports.getNameOwner=L,exports.getPicRecord=async(e,t)=>await te(e,t,exports.Record.Pic),exports.getPointRecord=async(e,t)=>await te(e,t,exports.Record.POINT),exports.getRecord=te,exports.getRecordKeySync=ee,exports.getRedditRecord=async(e,t)=>await te(e,t,exports.Record.Reddit),exports.getReverseKey=async(e,t)=>{const{pubkey:r,parent:i}=await z(e),a=await F(r.toBase58());return await M(a,A,t?i:void 0)},exports.getReverseKeySync=(e,t)=>{const{pubkey:r,parent:i}=V(e),a=U(r.toBase58());return G(a,A,t?i:void 0)},exports.getShdwRecord=async(e,t)=>await te(e,t,exports.Record.SHDW),exports.getSolRecord=re,exports.getTelegramRecord=async(e,t)=>await te(e,t,exports.Record.Telegram),exports.getTokenInfoFromMint=Q,exports.getTokenInfoFromName=async(t,r)=>{const i=await M(await F(r),void 0,J),{registry:a}=await S.retrieve(t,i);if(!a.data)throw new Error("Invalid account data");const s=new e.PublicKey(x.deserialize(a.data).mint);return await Q(t,s)},exports.getTwitterHandleandRegistryKeyViaFilters=async function(t,r){const a=[{memcmp:{offset:0,bytes:W.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:T.toBase58()}}],s=await t.getProgramAccounts(k,{filters:a});for(const t of s)if(t.account.data.length>S.HEADER_LEN+32){let r=t.account.data.slice(S.HEADER_LEN),a=i.deserializeUnchecked(Z.schema,Z,r);return[a.twitterHandle,new e.PublicKey(a.twitterRegistryKey)]}throw new Error("Registry not found.")},exports.getTwitterRecord=async(e,t)=>await te(e,t,exports.Record.Twitter),exports.getTwitterRegistry=async function(e,t){const r=await F(t),i=await M(r,void 0,W),{registry:a}=await S.retrieve(e,i);return a},exports.getTwitterRegistryData=async function(t,r){const i=[{memcmp:{offset:0,bytes:W.toBase58()}},{memcmp:{offset:32,bytes:r.toBase58()}},{memcmp:{offset:64,bytes:new e.PublicKey(Buffer.alloc(32,0)).toBase58()}}],a=await t.getProgramAccounts(k,{filters:i});if(a.length>1)throw new Error("Found more than one registry.");return a[0].account.data.slice(S.HEADER_LEN)},exports.getTwitterRegistryKey=async function(e){const t=await F(e);return await M(t,void 0,W)},exports.getUrlRecord=async(e,t)=>await te(e,t,exports.Record.Url),exports.performReverseLookup=async function(e,t){const i=await F(t.toBase58()),a=await M(i,A),{registry:s}=await S.retrieve(e,a);if(!s.data)throw new Error("Could not retrieve name data");const n=new r(s.data.slice(0,4),"le").toNumber();return s.data.slice(4,4+n).toString()},exports.performReverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=await F(e.toBase58()),r=await M(t,A);i.push(r)}return(await S.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new r(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.registerDomainName=async(r,i,a,n,o,c=N,u)=>{const[p]=e.PublicKey.findProgramAddressSync([B.toBuffer()],B),l=U(i),f=G(l,void 0,E),d=U(f.toBase58()),y=G(d,p),[w]=e.PublicKey.findProgramAddressSync([f.toBuffer()],B),m=D.findIndex((e=>null==u?void 0:u.equals(e))),b=new s.PythHttpClient(r,s.getPythProgramKeyForCluster("mainnet-beta")),h=await b.getData(),S=_.get(c.toBase58());if(!S)throw new Error("Symbol not found");const R=h.productPrice.get("Crypto."+S+"/USD"),x=h.productFromSymbol.get("Crypto."+S+"/USD"),v=t.getAssociatedTokenAddressSync(c,H);return[[],[new g({name:i,space:a,referrerIdxOpt:-1!=m?m:null}).getInstruction(B,k,E,f,y,e.SystemProgram.programId,p,n,o,O,R.productAccountKey,new e.PublicKey(x.price_account),v,t.TOKEN_PROGRAM_ID,e.SYSVAR_RENT_PUBKEY,w,u)]]},exports.resolve=async(t,r)=>{const{pubkey:i}=V(r),{registry:a,nftOwner:s}=await S.retrieve(t,i);if(s)return s;try{const i=V(exports.Record.SOL+"."+r,!0),s=await re(t,r);if(!s.data)throw new Error("Invalid SOL record data");const n=new TextEncoder,o=Buffer.concat([s.data.slice(0,32),i.pubkey.toBuffer()]),c=n.encode(o.toString("hex"));if(!ie(c,s.data.slice(32),a.owner))throw new Error("Signature invalid");return new e.PublicKey(s.data.slice(0,32))}catch(e){if(e instanceof Error&&"FetchError"===e.name)throw e;console.log(e)}return a.owner},exports.retrieveNftOwner=h,exports.retrieveNfts=async t=>{const r=await t.getProgramAccounts(m,{filters:[{memcmp:{offset:0,bytes:"3"}}]});return r.map((t=>new e.PublicKey(t.account.data.slice(66,98))))},exports.reverseLookup=Y,exports.reverseLookupBatch=async function(e,t){let i=[];for(let e of t){const t=U(e.toBase58()),r=G(t,A);i.push(r)}return(await S.retrieveBatch(e,i)).map((e=>{if(void 0===e||void 0===e.data)return;let t=new r(e.data.slice(0,4),"le").toNumber();return e.data.slice(4,4+t).toString()}))},exports.transferInstruction=f,exports.transferNameOwnership=async function(e,t,r,i,a,s){const n=await F(t),o=await M(n,i,a);let c;return c=i||(await S.retrieve(e,o)).registry.owner,f(k,o,r,c,i,a,s)},exports.updateInstruction=l,exports.updateNameRegistryData=async function(e,t,r,i,a,s){const n=await F(t),o=await M(n,a,s);let u;return u=a||(await S.retrieve(e,o)).registry.owner,l(k,o,new c(r),i,u)};
|
package/dist/instructions.d.ts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
3
|
import { Numberu32, Numberu64 } from "./int";
|
|
4
4
|
import { Schema } from "borsh";
|
|
5
|
+
export interface AccountKey {
|
|
6
|
+
pubkey: PublicKey;
|
|
7
|
+
isSigner: boolean;
|
|
8
|
+
isWritable: boolean;
|
|
9
|
+
}
|
|
5
10
|
export declare function createInstruction(nameProgramId: PublicKey, systemProgramId: PublicKey, nameKey: PublicKey, nameOwnerKey: PublicKey, payerKey: PublicKey, hashed_name: Buffer, lamports: Numberu64, space: Numberu32, nameClassKey?: PublicKey, nameParent?: PublicKey, nameParentOwner?: PublicKey): TransactionInstruction;
|
|
6
11
|
export declare function updateInstruction(nameProgramId: PublicKey, nameAccountKey: PublicKey, offset: Numberu32, input_data: Buffer, nameUpdateSigner: PublicKey): TransactionInstruction;
|
|
7
12
|
export declare function transferInstruction(nameProgramId: PublicKey, nameAccountKey: PublicKey, newOwnerKey: PublicKey, currentNameOwnerKey: PublicKey, nameClassKey?: PublicKey, nameParent?: PublicKey, parentOwner?: PublicKey): TransactionInstruction;
|
|
@@ -28,3 +33,17 @@ export declare class createReverseInstruction {
|
|
|
28
33
|
serialize(): Uint8Array;
|
|
29
34
|
getInstruction(programId: PublicKey, rentSysvarAccount: PublicKey, namingServiceProgram: PublicKey, rootDomain: PublicKey, reverseLookupAccount: PublicKey, centralStateAccount: PublicKey, feePayer: PublicKey, parentName?: PublicKey, parentNameOwner?: PublicKey): TransactionInstruction;
|
|
30
35
|
}
|
|
36
|
+
export declare class createInstructionV3 {
|
|
37
|
+
tag: number;
|
|
38
|
+
name: string;
|
|
39
|
+
space: number;
|
|
40
|
+
referrerIdxOpt: number | null;
|
|
41
|
+
static schema: Schema;
|
|
42
|
+
constructor(obj: {
|
|
43
|
+
name: string;
|
|
44
|
+
space: number;
|
|
45
|
+
referrerIdxOpt: number | null;
|
|
46
|
+
});
|
|
47
|
+
serialize(): Uint8Array;
|
|
48
|
+
getInstruction(programId: PublicKey, namingServiceProgram: PublicKey, rootDomain: PublicKey, name: PublicKey, reverseLookup: PublicKey, systemProgram: PublicKey, centralState: PublicKey, buyer: PublicKey, buyerTokenSource: PublicKey, pythMappingAcc: PublicKey, pythProductAcc: PublicKey, pythPriceAcc: PublicKey, vault: PublicKey, splTokenProgram: PublicKey, rentSysvar: PublicKey, state: PublicKey, referrerAccountOpt?: PublicKey): TransactionInstruction;
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonfida/spl-name-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@bonfida/name-offers": "^0.0.4",
|
|
57
|
-
"@ethersproject/sha2": "^5.5.0"
|
|
57
|
+
"@ethersproject/sha2": "^5.5.0",
|
|
58
|
+
"@pythnetwork/client": "^2.17.0"
|
|
58
59
|
},
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"@solana/buffer-layout": "^4.0.0",
|
package/src/bindings.ts
CHANGED
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
deleteInstruction,
|
|
11
11
|
transferInstruction,
|
|
12
12
|
updateInstruction,
|
|
13
|
-
createV2Instruction,
|
|
14
13
|
createReverseInstruction,
|
|
14
|
+
createInstructionV3,
|
|
15
15
|
} from "./instructions";
|
|
16
16
|
import { NameRegistryState } from "./state";
|
|
17
17
|
import { Numberu64, Numberu32 } from "./int";
|
|
@@ -24,8 +24,21 @@ import {
|
|
|
24
24
|
NAME_PROGRAM_ID,
|
|
25
25
|
ROOT_DOMAIN_ACCOUNT,
|
|
26
26
|
REGISTER_PROGRAM_ID,
|
|
27
|
-
|
|
27
|
+
REFERRERS,
|
|
28
|
+
USDC_MINT,
|
|
29
|
+
TOKENS_SYM_MINT,
|
|
30
|
+
PYTH_MAPPING_ACC,
|
|
31
|
+
VAULT_OWNER,
|
|
28
32
|
} from "./constants";
|
|
33
|
+
import {
|
|
34
|
+
getPythProgramKeyForCluster,
|
|
35
|
+
PythHttpClient,
|
|
36
|
+
} from "@pythnetwork/client";
|
|
37
|
+
import { getHashedNameSync, getNameAccountKeySync } from "./utils";
|
|
38
|
+
import {
|
|
39
|
+
TOKEN_PROGRAM_ID,
|
|
40
|
+
getAssociatedTokenAddressSync,
|
|
41
|
+
} from "@solana/spl-token";
|
|
29
42
|
|
|
30
43
|
/**
|
|
31
44
|
* Creates a name account with the given rent budget, allocated space, owner and class.
|
|
@@ -227,53 +240,85 @@ export async function deleteNameRegistry(
|
|
|
227
240
|
|
|
228
241
|
/**
|
|
229
242
|
* This function can be used to register a .sol domain
|
|
243
|
+
* @param connection The Solana RPC connection object
|
|
230
244
|
* @param name The domain name to register e.g bonfida if you want to register bonfida.sol
|
|
231
245
|
* @param space The domain name account size (max 10kB)
|
|
232
246
|
* @param buyer The public key of the buyer
|
|
233
247
|
* @param buyerTokenAccount The buyer token account (USDC)
|
|
248
|
+
* @param mint Optional mint used to purchase the domain, defaults to USDC
|
|
249
|
+
* @param referrerKey Optional referrer key
|
|
234
250
|
* @returns
|
|
235
251
|
*/
|
|
236
252
|
export const registerDomainName = async (
|
|
253
|
+
connection: Connection,
|
|
237
254
|
name: string,
|
|
238
255
|
space: number,
|
|
239
256
|
buyer: PublicKey,
|
|
240
|
-
buyerTokenAccount: PublicKey
|
|
257
|
+
buyerTokenAccount: PublicKey,
|
|
258
|
+
mint = USDC_MINT,
|
|
259
|
+
referrerKey?: PublicKey
|
|
241
260
|
) => {
|
|
242
|
-
const [
|
|
261
|
+
const [cs] = PublicKey.findProgramAddressSync(
|
|
243
262
|
[REGISTER_PROGRAM_ID.toBuffer()],
|
|
244
263
|
REGISTER_PROGRAM_ID
|
|
245
264
|
);
|
|
246
265
|
|
|
247
|
-
const hashed =
|
|
248
|
-
const nameAccount =
|
|
266
|
+
const hashed = getHashedNameSync(name);
|
|
267
|
+
const nameAccount = getNameAccountKeySync(
|
|
249
268
|
hashed,
|
|
250
269
|
undefined,
|
|
251
270
|
ROOT_DOMAIN_ACCOUNT
|
|
252
271
|
);
|
|
253
272
|
|
|
254
|
-
const hashedReverseLookup =
|
|
255
|
-
const reverseLookupAccount =
|
|
256
|
-
hashedReverseLookup,
|
|
257
|
-
centralState
|
|
258
|
-
);
|
|
273
|
+
const hashedReverseLookup = getHashedNameSync(nameAccount.toBase58());
|
|
274
|
+
const reverseLookupAccount = getNameAccountKeySync(hashedReverseLookup, cs);
|
|
259
275
|
|
|
260
|
-
const [derived_state] =
|
|
276
|
+
const [derived_state] = PublicKey.findProgramAddressSync(
|
|
261
277
|
[nameAccount.toBuffer()],
|
|
262
278
|
REGISTER_PROGRAM_ID
|
|
263
279
|
);
|
|
264
280
|
|
|
265
|
-
const
|
|
281
|
+
const referrerIdx = REFERRERS.findIndex((e) => referrerKey?.equals(e));
|
|
282
|
+
|
|
283
|
+
const pythConnection = new PythHttpClient(
|
|
284
|
+
connection,
|
|
285
|
+
getPythProgramKeyForCluster("mainnet-beta")
|
|
286
|
+
);
|
|
287
|
+
const data = await pythConnection.getData();
|
|
288
|
+
|
|
289
|
+
const symbol = TOKENS_SYM_MINT.get(mint.toBase58());
|
|
290
|
+
|
|
291
|
+
if (!symbol) {
|
|
292
|
+
throw new Error("Symbol not found");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const priceData = data.productPrice.get("Crypto." + symbol + "/USD")!;
|
|
296
|
+
const productData = data.productFromSymbol.get("Crypto." + symbol + "/USD")!;
|
|
297
|
+
|
|
298
|
+
const vault = getAssociatedTokenAddressSync(mint, VAULT_OWNER);
|
|
299
|
+
|
|
300
|
+
const ix = new createInstructionV3({
|
|
301
|
+
name,
|
|
302
|
+
space,
|
|
303
|
+
referrerIdxOpt: referrerIdx != -1 ? referrerIdx : null,
|
|
304
|
+
}).getInstruction(
|
|
266
305
|
REGISTER_PROGRAM_ID,
|
|
267
|
-
SYSVAR_RENT_PUBKEY,
|
|
268
306
|
NAME_PROGRAM_ID,
|
|
269
307
|
ROOT_DOMAIN_ACCOUNT,
|
|
270
308
|
nameAccount,
|
|
271
309
|
reverseLookupAccount,
|
|
272
|
-
|
|
310
|
+
SystemProgram.programId,
|
|
311
|
+
cs,
|
|
273
312
|
buyer,
|
|
274
313
|
buyerTokenAccount,
|
|
275
|
-
|
|
276
|
-
|
|
314
|
+
PYTH_MAPPING_ACC,
|
|
315
|
+
priceData.productAccountKey,
|
|
316
|
+
new PublicKey(productData.price_account),
|
|
317
|
+
vault,
|
|
318
|
+
TOKEN_PROGRAM_ID,
|
|
319
|
+
SYSVAR_RENT_PUBKEY,
|
|
320
|
+
derived_state,
|
|
321
|
+
referrerKey
|
|
277
322
|
);
|
|
278
323
|
|
|
279
324
|
return [[], [ix]];
|
package/src/constants.ts
CHANGED
|
@@ -69,3 +69,26 @@ export const SOL_RECORD_SIG_LEN = 96;
|
|
|
69
69
|
export const BONFIDA_USDC_BNB = new PublicKey(
|
|
70
70
|
"DmSyHDSM9eSLyvoLsPvDr5fRRFZ7Bfr3h3ULvWpgQaq7"
|
|
71
71
|
);
|
|
72
|
+
|
|
73
|
+
export const USDC_MINT = new PublicKey(
|
|
74
|
+
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export const REFERRERS: PublicKey[] = [];
|
|
78
|
+
|
|
79
|
+
export const TOKENS_SYM_MINT = new Map<string, string>([
|
|
80
|
+
["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "USDC"],
|
|
81
|
+
["Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB", "USDT"],
|
|
82
|
+
["So11111111111111111111111111111111111111112", "SOL"],
|
|
83
|
+
["EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp", "FIDA"],
|
|
84
|
+
["FeGn77dhg1KXRRFeSwwMiykZnZPw5JXW6naf2aQgZDQf", "ETH"],
|
|
85
|
+
["mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So", "MSOL"],
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
export const PYTH_MAPPING_ACC = new PublicKey(
|
|
89
|
+
"AHtgzX45WTKfkPG53L6WYhGEXwQkN1BVknET3sVsLL8J"
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export const VAULT_OWNER = new PublicKey(
|
|
93
|
+
"GcWEQ9K78FV7LEHteFVciYApERk5YvQuFDQPk1yYJVXi"
|
|
94
|
+
);
|
package/src/instructions.ts
CHANGED
|
@@ -7,6 +7,12 @@ import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
|
7
7
|
import { Numberu32, Numberu64 } from "./int";
|
|
8
8
|
import { Schema, serialize } from "borsh";
|
|
9
9
|
|
|
10
|
+
export interface AccountKey {
|
|
11
|
+
pubkey: PublicKey;
|
|
12
|
+
isSigner: boolean;
|
|
13
|
+
isWritable: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export function createInstruction(
|
|
11
17
|
nameProgramId: PublicKey,
|
|
12
18
|
systemProgramId: PublicKey,
|
|
@@ -434,3 +440,146 @@ export class createReverseInstruction {
|
|
|
434
440
|
});
|
|
435
441
|
}
|
|
436
442
|
}
|
|
443
|
+
|
|
444
|
+
export class createInstructionV3 {
|
|
445
|
+
tag: number;
|
|
446
|
+
name: string;
|
|
447
|
+
space: number;
|
|
448
|
+
referrerIdxOpt: number | null;
|
|
449
|
+
static schema: Schema = new Map([
|
|
450
|
+
[
|
|
451
|
+
createInstructionV3,
|
|
452
|
+
{
|
|
453
|
+
kind: "struct",
|
|
454
|
+
fields: [
|
|
455
|
+
["tag", "u8"],
|
|
456
|
+
["name", "string"],
|
|
457
|
+
["space", "u32"],
|
|
458
|
+
["referrerIdxOpt", { kind: "option", type: "u16" }],
|
|
459
|
+
],
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
]);
|
|
463
|
+
constructor(obj: {
|
|
464
|
+
name: string;
|
|
465
|
+
space: number;
|
|
466
|
+
referrerIdxOpt: number | null;
|
|
467
|
+
}) {
|
|
468
|
+
this.tag = 13;
|
|
469
|
+
this.name = obj.name;
|
|
470
|
+
this.space = obj.space;
|
|
471
|
+
this.referrerIdxOpt = obj.referrerIdxOpt;
|
|
472
|
+
}
|
|
473
|
+
serialize(): Uint8Array {
|
|
474
|
+
return serialize(createInstructionV3.schema, this);
|
|
475
|
+
}
|
|
476
|
+
getInstruction(
|
|
477
|
+
programId: PublicKey,
|
|
478
|
+
namingServiceProgram: PublicKey,
|
|
479
|
+
rootDomain: PublicKey,
|
|
480
|
+
name: PublicKey,
|
|
481
|
+
reverseLookup: PublicKey,
|
|
482
|
+
systemProgram: PublicKey,
|
|
483
|
+
centralState: PublicKey,
|
|
484
|
+
buyer: PublicKey,
|
|
485
|
+
buyerTokenSource: PublicKey,
|
|
486
|
+
pythMappingAcc: PublicKey,
|
|
487
|
+
pythProductAcc: PublicKey,
|
|
488
|
+
pythPriceAcc: PublicKey,
|
|
489
|
+
vault: PublicKey,
|
|
490
|
+
splTokenProgram: PublicKey,
|
|
491
|
+
rentSysvar: PublicKey,
|
|
492
|
+
state: PublicKey,
|
|
493
|
+
referrerAccountOpt?: PublicKey
|
|
494
|
+
): TransactionInstruction {
|
|
495
|
+
const data = Buffer.from(this.serialize());
|
|
496
|
+
let keys: AccountKey[] = [];
|
|
497
|
+
keys.push({
|
|
498
|
+
pubkey: namingServiceProgram,
|
|
499
|
+
isSigner: false,
|
|
500
|
+
isWritable: false,
|
|
501
|
+
});
|
|
502
|
+
keys.push({
|
|
503
|
+
pubkey: rootDomain,
|
|
504
|
+
isSigner: false,
|
|
505
|
+
isWritable: false,
|
|
506
|
+
});
|
|
507
|
+
keys.push({
|
|
508
|
+
pubkey: name,
|
|
509
|
+
isSigner: false,
|
|
510
|
+
isWritable: true,
|
|
511
|
+
});
|
|
512
|
+
keys.push({
|
|
513
|
+
pubkey: reverseLookup,
|
|
514
|
+
isSigner: false,
|
|
515
|
+
isWritable: true,
|
|
516
|
+
});
|
|
517
|
+
keys.push({
|
|
518
|
+
pubkey: systemProgram,
|
|
519
|
+
isSigner: false,
|
|
520
|
+
isWritable: false,
|
|
521
|
+
});
|
|
522
|
+
keys.push({
|
|
523
|
+
pubkey: centralState,
|
|
524
|
+
isSigner: false,
|
|
525
|
+
isWritable: false,
|
|
526
|
+
});
|
|
527
|
+
keys.push({
|
|
528
|
+
pubkey: buyer,
|
|
529
|
+
isSigner: true,
|
|
530
|
+
isWritable: true,
|
|
531
|
+
});
|
|
532
|
+
keys.push({
|
|
533
|
+
pubkey: buyerTokenSource,
|
|
534
|
+
isSigner: false,
|
|
535
|
+
isWritable: true,
|
|
536
|
+
});
|
|
537
|
+
keys.push({
|
|
538
|
+
pubkey: pythMappingAcc,
|
|
539
|
+
isSigner: false,
|
|
540
|
+
isWritable: false,
|
|
541
|
+
});
|
|
542
|
+
keys.push({
|
|
543
|
+
pubkey: pythProductAcc,
|
|
544
|
+
isSigner: false,
|
|
545
|
+
isWritable: false,
|
|
546
|
+
});
|
|
547
|
+
keys.push({
|
|
548
|
+
pubkey: pythPriceAcc,
|
|
549
|
+
isSigner: false,
|
|
550
|
+
isWritable: false,
|
|
551
|
+
});
|
|
552
|
+
keys.push({
|
|
553
|
+
pubkey: vault,
|
|
554
|
+
isSigner: false,
|
|
555
|
+
isWritable: true,
|
|
556
|
+
});
|
|
557
|
+
keys.push({
|
|
558
|
+
pubkey: splTokenProgram,
|
|
559
|
+
isSigner: false,
|
|
560
|
+
isWritable: false,
|
|
561
|
+
});
|
|
562
|
+
keys.push({
|
|
563
|
+
pubkey: rentSysvar,
|
|
564
|
+
isSigner: false,
|
|
565
|
+
isWritable: false,
|
|
566
|
+
});
|
|
567
|
+
keys.push({
|
|
568
|
+
pubkey: state,
|
|
569
|
+
isSigner: false,
|
|
570
|
+
isWritable: false,
|
|
571
|
+
});
|
|
572
|
+
if (!!referrerAccountOpt) {
|
|
573
|
+
keys.push({
|
|
574
|
+
pubkey: referrerAccountOpt,
|
|
575
|
+
isSigner: false,
|
|
576
|
+
isWritable: true,
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return new TransactionInstruction({
|
|
580
|
+
keys,
|
|
581
|
+
programId,
|
|
582
|
+
data,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
}
|