@zcomb/programs-sdk 1.11.2 → 1.11.3

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.
@@ -501,9 +501,10 @@ export declare class FutarchyClient {
501
501
  *
502
502
  * @param creator - The user who will receive conditional tokens
503
503
  * @param proposalPda - The proposal PDA (must be initialized but not launched)
504
+ * @param options - Transaction options including priorityFeeMicroLamports
504
505
  * @returns Transaction signature
505
506
  */
506
- ensureConditionalATAs(creator: PublicKey, proposalPda: PublicKey): Promise<string>;
507
+ ensureConditionalATAs(creator: PublicKey, proposalPda: PublicKey, options?: TxOptions): Promise<string>;
507
508
  /**
508
509
  * Internal helper to create conditional ATAs given mint arrays.
509
510
  * Used by both ensureConditionalATAs and launchProposal to avoid redundant fetches.
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,s,r)}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var s=e(t),r=0;r<s.length;r++)"default"!==s[r]&&__createBinding(i,t,s[r]);return __setModuleDefault(i,t),i}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.FutarchyClient=void 0;const anchor_1=require("@coral-xyz/anchor"),web3_js_1=require("@solana/web3.js"),spl_token_1=require("@solana/spl-token"),constants_1=require("./constants"),utils_1=require("./utils"),instructions_1=require("./instructions"),vault_1=require("../vault"),amm_1=require("../amm"),idls_1=require("../generated/idls"),multisig=__importStar(require("@sqds/multisig")),DEFAULT_COMPUTE_UNITS=5e5;class FutarchyClient{constructor(e,t,i){this.programId=t??constants_1.PROGRAM_ID,this.program=new anchor_1.Program(idls_1.FutarchyIDL,e),this.vault=new vault_1.VaultClient(e),this.amm=new amm_1.AMMClient(e),this.defaultComputeUnits=i??5e5}deriveDAOPDA(e){return(0,utils_1.deriveDAOPDA)(e,this.programId)}deriveModeratorPDA(e){return(0,utils_1.deriveModeratorPDA)(e,this.programId)}deriveProposalPDA(e,t){return(0,utils_1.deriveProposalPDA)(e,t,this.programId)}async fetchDAO(e){return(0,utils_1.fetchDAOAccount)(this.program,e)}async fetchModerator(e){return(0,utils_1.fetchModeratorAccount)(this.program,e)}async fetchProposal(e){return(0,utils_1.fetchProposalAccount)(this.program,e)}isProposalExpired(e){return(0,utils_1.isProposalExpired)(e)}getTimeRemaining(e){return(0,utils_1.getTimeRemaining)(e)}getComputeUnits(e){return e?.computeUnits??this.defaultComputeUnits}maybeAddComputeBudget(e){if(!1===e?.includeCuBudget)return[];const t=[web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({units:this.getComputeUnits(e)})];return void 0!==e?.priorityFeeMicroLamports&&e.priorityFeeMicroLamports>0&&t.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:e.priorityFeeMicroLamports})),t}async initializeModerator(e,t,i,s,r){const[a]=this.deriveModeratorPDA(s);return{builder:(0,instructions_1.initializeModerator)(this.program,e,t,i,a,s).preInstructions(this.maybeAddComputeBudget(r)),moderatorPda:a,name:s}}async addHistoricalProposal(e,t,i,s,r,a,o,n){const d=(await this.fetchModerator(t)).proposalIdCounter,[l]=this.deriveProposalPDA(t,d);return{builder:(0,instructions_1.addHistoricalProposal)(this.program,e,t,l,i,s,r,a,o).preInstructions(this.maybeAddComputeBudget(n)),proposalPda:l,proposalId:d}}async initializeProposal(e,t,i,s,r){const a=await this.fetchModerator(t),o=a.proposalIdCounter,[n]=this.deriveProposalPDA(t,o),[d]=(0,vault_1.deriveVaultPDA)(n,o,this.vault.programId),[l]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Base,0,this.vault.programId),[u]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Base,1,this.vault.programId),[c]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Quote,0,this.vault.programId),[p]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Quote,1,this.vault.programId),[m]=(0,amm_1.derivePoolPDA)(n,c,l,this.amm.programId),[g]=(0,amm_1.derivePoolPDA)(n,p,u,this.amm.programId),[h]=(0,amm_1.deriveReservePDA)(m,c,this.amm.programId),[_]=(0,amm_1.deriveReservePDA)(m,l,this.amm.programId),[b]=(0,amm_1.deriveFeeVaultPDA)(m,this.amm.programId),[A]=(0,amm_1.deriveReservePDA)(g,p,this.amm.programId),[k]=(0,amm_1.deriveReservePDA)(g,u,this.amm.programId),[y]=(0,amm_1.deriveFeeVaultPDA)(g,this.amm.programId),v=(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint,d,!0),P=(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint,d,!0),f=[{pubkey:a.baseMint,isSigner:!1,isWritable:!1},{pubkey:a.quoteMint,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:v,isSigner:!1,isWritable:!0},{pubkey:P,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:h,isSigner:!1,isWritable:!0},{pubkey:_,isSigner:!1,isWritable:!0},{pubkey:amm_1.FEE_AUTHORITY,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!0},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:A,isSigner:!1,isWritable:!0},{pubkey:k,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0}];return{builder:(0,instructions_1.initializeProposal)(this.program,e,t,n,i,s??null,f).preInstructions(this.maybeAddComputeBudget(r)),proposalPda:n,proposalId:o,vaultPda:d,pools:[m,g],condBaseMints:[l,u],condQuoteMints:[c,p]}}async addOption(e,t,i){const s=await this.fetchProposal(t),r=s.numOptions,[a]=(0,vault_1.deriveConditionalMint)(s.vault,vault_1.VaultType.Base,r,this.vault.programId),[o]=(0,vault_1.deriveConditionalMint)(s.vault,vault_1.VaultType.Quote,r,this.vault.programId),[n]=(0,amm_1.derivePoolPDA)(t,o,a,this.amm.programId),[d]=(0,amm_1.deriveReservePDA)(n,o,this.amm.programId),[l]=(0,amm_1.deriveReservePDA)(n,a,this.amm.programId),[u]=(0,amm_1.deriveFeeVaultPDA)(n,this.amm.programId),c=[{pubkey:s.vault,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:amm_1.FEE_AUTHORITY,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!0}];return{builder:(0,instructions_1.addOption)(this.program,e,t,c).preInstructions(this.maybeAddComputeBudget(i)),optionIndex:r,pool:n,condBaseMint:a,condQuoteMint:o}}async launchProposal(e,t,i,s,r){const a=await this.fetchProposal(t),o=await this.vault.fetchVault(a.vault),n=a.numOptions,d=o.condBaseMints.slice(0,n),l=o.condQuoteMints.slice(0,n);(r?.ensureATAs??n>=3)&&await this._createConditionalATAs(e,d,l);const u=a.pools.slice(0,n),c=d.map(t=>(0,spl_token_1.getAssociatedTokenAddressSync)(t,e)),p=l.map(t=>(0,spl_token_1.getAssociatedTokenAddressSync)(t,e)),m=[],g=[];for(let e=0;e<n;e++){const[t]=(0,amm_1.deriveReservePDA)(u[e],l[e],this.amm.programId),[i]=(0,amm_1.deriveReservePDA)(u[e],d[e],this.amm.programId);m.push(t),g.push(i)}const h=[{pubkey:o.baseMint.address,isSigner:!1,isWritable:!1},{pubkey:o.quoteMint.address,isSigner:!1,isWritable:!1},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint.address,a.vault,!0),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint.address,a.vault,!0),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint.address,e),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint.address,e),isSigner:!1,isWritable:!0}];for(const e of d)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of l)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of c)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of p)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of u)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of m)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of g)h.push({pubkey:e,isSigner:!1,isWritable:!0});return{builder:(0,instructions_1.launchProposal)(this.program,e,t,a.vault,i,s,h).preInstructions(this.maybeAddComputeBudget(r))}}async ensureConditionalATAs(e,t){const i=await this.fetchProposal(t),s=await this.vault.fetchVault(i.vault),r=s.condBaseMints.slice(0,i.numOptions),a=s.condQuoteMints.slice(0,i.numOptions);return this._createConditionalATAs(e,r,a)}async _createConditionalATAs(e,t,i){const s=this.program.provider,r=[];for(let s=0;s<t.length;s++){const a=(0,spl_token_1.getAssociatedTokenAddressSync)(t[s],e),o=(0,spl_token_1.getAssociatedTokenAddressSync)(i[s],e);r.push((0,spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(e,a,e,t[s]),(0,spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(e,o,e,i[s]))}const a=(new web3_js_1.Transaction).add(...r);return s.sendAndConfirm(a)}async finalizeProposal(e,t,i){const s=await this.fetchProposal(t),r=await this.vault.fetchVault(s.vault),a=s.numOptions,o=[];for(let e=0;e<a;e++){const t=s.pools[e],[i]=(0,amm_1.deriveReservePDA)(t,r.condQuoteMints[e],this.amm.programId),[a]=(0,amm_1.deriveReservePDA)(t,r.condBaseMints[e],this.amm.programId);o.push({pubkey:t,isSigner:!1,isWritable:!0}),o.push({pubkey:i,isSigner:!1,isWritable:!1}),o.push({pubkey:a,isSigner:!1,isWritable:!1})}return{builder:(0,instructions_1.finalizeProposal)(this.program,e,t,s.vault,o).preInstructions(this.maybeAddComputeBudget(i))}}async redeemLiquidity(e,t,i){const s=await this.fetchProposal(t),r=await this.vault.fetchVault(s.vault),a=s.numOptions,{winningIdx:o}=(0,utils_1.parseProposalState)(s.state);if(null===o)throw new Error("Proposal not finalized");const n=s.pools[o],[d]=(0,amm_1.deriveReservePDA)(n,r.condQuoteMints[o],this.amm.programId),[l]=(0,amm_1.deriveReservePDA)(n,r.condBaseMints[o],this.amm.programId),u=[{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condQuoteMints[o],e),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condBaseMints[o],e),isSigner:!1,isWritable:!0},{pubkey:r.baseMint.address,isSigner:!1,isWritable:!1},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.baseMint.address,s.vault,!0),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.baseMint.address,e),isSigner:!1,isWritable:!0}];for(let t=0;t<a;t++)u.push({pubkey:r.condBaseMints[t],isSigner:!1,isWritable:!0}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condBaseMints[t],e),isSigner:!1,isWritable:!0});u.push({pubkey:r.quoteMint.address,isSigner:!1,isWritable:!1}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.quoteMint.address,s.vault,!0),isSigner:!1,isWritable:!0}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.quoteMint.address,e),isSigner:!1,isWritable:!0});for(let t=0;t<a;t++)u.push({pubkey:r.condQuoteMints[t],isSigner:!1,isWritable:!0}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condQuoteMints[t],e),isSigner:!1,isWritable:!0});return{builder:(0,instructions_1.redeemLiquidity)(this.program,e,t,s.vault,n,u).preInstructions(this.maybeAddComputeBudget(i)),numOptions:a}}async createRedemptionALT(e,t,i=0){const s=this.program.provider,r=await this.fetchProposal(t),a=await this.vault.fetchVault(r.vault),o=r.numOptions,{winningIdx:n}=(0,utils_1.parseProposalState)(r.state);if(null===n)throw new Error("Proposal not finalized");const d=[this.programId,this.vault.programId,this.amm.programId,web3_js_1.SystemProgram.programId,spl_token_1.TOKEN_PROGRAM_ID,spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,t,r.vault,r.moderator,a.baseMint.address,a.quoteMint.address,r.pools[n],(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint.address,r.vault,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint.address,r.vault,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint.address,e),(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint.address,e)],[l]=(0,amm_1.deriveReservePDA)(r.pools[n],a.condQuoteMints[n],this.amm.programId),[u]=(0,amm_1.deriveReservePDA)(r.pools[n],a.condBaseMints[n],this.amm.programId);d.push(l,u);for(let t=0;t<o;t++)d.push(a.condBaseMints[t],a.condQuoteMints[t],(0,spl_token_1.getAssociatedTokenAddressSync)(a.condBaseMints[t],e),(0,spl_token_1.getAssociatedTokenAddressSync)(a.condQuoteMints[t],e));const c=await s.connection.getSlot("finalized"),[p,m]=web3_js_1.AddressLookupTableProgram.createLookupTable({authority:e,payer:e,recentSlot:c}),g=new web3_js_1.Transaction;i>0&&g.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:i})),g.add(p);const{blockhash:h,lastValidBlockHeight:_}=await s.connection.getLatestBlockhash("confirmed");g.recentBlockhash=h,g.feePayer=e;const b=await s.wallet.signTransaction(g),A=await s.connection.sendRawTransaction(b.serialize(),{skipPreflight:!0});await s.connection.confirmTransaction({signature:A,blockhash:h,lastValidBlockHeight:_},"confirmed");for(let t=0;t<d.length;t+=20){const r=d.slice(t,t+20),a=web3_js_1.AddressLookupTableProgram.extendLookupTable({payer:e,authority:e,lookupTable:m,addresses:r}),o=new web3_js_1.Transaction;i>0&&o.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:i})),o.add(a);const{blockhash:n,lastValidBlockHeight:l}=await s.connection.getLatestBlockhash("confirmed");o.recentBlockhash=n,o.feePayer=e;const u=await s.wallet.signTransaction(o),c=await s.connection.sendRawTransaction(u.serialize(),{skipPreflight:!0});await s.connection.confirmTransaction({signature:c,blockhash:n,lastValidBlockHeight:l},"confirmed")}return{altAddress:m}}async redeemLiquidityVersioned(e,t,i,s){const r=this.program.provider,{builder:a,numOptions:o}=await this.redeemLiquidity(e,t);let n=i,d=null;if(!n&&o>=3){console.log(` Creating redemption ALT for ${o} options...`);n=(await this.createRedemptionALT(e,t)).altAddress,console.log(` ✓ Redemption ALT created: ${n.toBase58()}`),console.log(" Waiting for ALT propagation...");const i=18+4*o;let s=0;for(await new Promise(e=>setTimeout(e,2e3));s<30;){const e=await r.connection.getAddressLookupTable(n,{commitment:"confirmed"});if(e.value){const t=e.value.state.addresses.length;if(console.log(` Attempt ${s+1}: ALT has ${t}/${i} addresses`),t>=i){d=e.value,console.log(` ✓ ALT verified with ${t} addresses`);break}}await new Promise(e=>setTimeout(e,1e3)),s++}if(!d)throw new Error(`ALT failed to populate with expected ${i} addresses after ${s} attempts`)}if(!n)throw new Error("ALT address required for multi-option redemption");d||(d=await this.fetchALT(n));const l=await a.instruction(),u=[web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({units:5e5})];void 0!==s?.priorityFeeMicroLamports&&s.priorityFeeMicroLamports>0&&u.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s.priorityFeeMicroLamports}));const{blockhash:c,lastValidBlockHeight:p}=await r.connection.getLatestBlockhash("confirmed");return{versionedTx:this.buildVersionedTxWithALT(e,[...u,l],d,c),altAddress:n,numOptions:o,blockhash:c,lastValidBlockHeight:p}}async sendVersionedTransaction(e,t){const i=this.program.provider;let s,r;if(t)s=t.blockhash,r=t.lastValidBlockHeight;else{const e=await i.connection.getLatestBlockhash("confirmed");s=e.blockhash,r=e.lastValidBlockHeight}const a=await i.connection.sendTransaction(e,{skipPreflight:!1,preflightCommitment:"confirmed"});return await i.connection.confirmTransaction({signature:a,blockhash:s,lastValidBlockHeight:r},"confirmed"),a}async createProposalALT(e,t,i=2,s=0){const r=this.program.provider,a=await this.fetchModerator(t),o=a.proposalIdCounter,[n]=this.deriveProposalPDA(t,o),[d]=(0,vault_1.deriveVaultPDA)(n,o,this.vault.programId),l=[this.programId,this.vault.programId,this.amm.programId,web3_js_1.SystemProgram.programId,spl_token_1.TOKEN_PROGRAM_ID,spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,t,n,d,a.baseMint,a.quoteMint,amm_1.FEE_AUTHORITY,(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint,d,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint,d,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint,e),(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint,e)];for(let t=0;t<i;t++){const[i]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Base,t,this.vault.programId),[s]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Quote,t,this.vault.programId),[r]=(0,amm_1.derivePoolPDA)(n,s,i,this.amm.programId),[a]=(0,amm_1.deriveReservePDA)(r,s,this.amm.programId),[o]=(0,amm_1.deriveReservePDA)(r,i,this.amm.programId),[u]=(0,amm_1.deriveFeeVaultPDA)(r,this.amm.programId);l.push(i,s,r,a,o,u,(0,spl_token_1.getAssociatedTokenAddressSync)(i,e),(0,spl_token_1.getAssociatedTokenAddressSync)(s,e))}const u=await r.connection.getSlot("finalized"),[c,p]=web3_js_1.AddressLookupTableProgram.createLookupTable({authority:e,payer:e,recentSlot:u}),m=new web3_js_1.Transaction;s>0&&m.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s})),m.add(c);const{blockhash:g,lastValidBlockHeight:h}=await r.connection.getLatestBlockhash("confirmed");m.recentBlockhash=g,m.feePayer=e;const _=await r.wallet.signTransaction(m),b=await r.connection.sendRawTransaction(_.serialize(),{skipPreflight:!0});await r.connection.confirmTransaction({signature:b,blockhash:g,lastValidBlockHeight:h},"confirmed");for(let t=0;t<l.length;t+=20){const i=l.slice(t,t+20),a=web3_js_1.AddressLookupTableProgram.extendLookupTable({payer:e,authority:e,lookupTable:p,addresses:i}),o=new web3_js_1.Transaction;s>0&&o.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s})),o.add(a);const{blockhash:n,lastValidBlockHeight:d}=await r.connection.getLatestBlockhash("confirmed");o.recentBlockhash=n,o.feePayer=e;const u=await r.wallet.signTransaction(o),c=await r.connection.sendRawTransaction(u.serialize(),{skipPreflight:!0});await r.connection.confirmTransaction({signature:c,blockhash:n,lastValidBlockHeight:d},"confirmed")}return{altAddress:p}}async fetchALT(e){const t=await this.program.provider.connection.getAddressLookupTable(e);if(!t.value)throw new Error("ALT not found");return t.value}async buildVersionedTx(e,t,i){const s=this.program.provider,r=await this.fetchALT(i),{blockhash:a,lastValidBlockHeight:o}=await s.connection.getLatestBlockhash("confirmed");return{versionedTx:this.buildVersionedTxWithALT(e,t,r,a),blockhash:a,lastValidBlockHeight:o}}buildVersionedTxWithALT(e,t,i,s){const r=new web3_js_1.TransactionMessage({payerKey:e,recentBlockhash:s,instructions:t}).compileToV0Message([i]);return new web3_js_1.VersionedTransaction(r)}deriveMintCreateKeyPDA(e,t){return(0,utils_1.deriveMintCreateKeyPDA)(e,t,this.programId)}async fetchSquadsProgramConfig(){const[e]=multisig.getProgramConfigPda({programId:constants_1.SQUADS_PROGRAM_ID});return{programConfig:e,programConfigTreasury:(await multisig.accounts.ProgramConfig.fromAccountAddress(this.program.provider.connection,e)).treasury}}deriveMultisigPda(e){const[t]=multisig.getMultisigPda({createKey:e,programId:constants_1.SQUADS_PROGRAM_ID});return t}async initializeParentDAO(e,t,i,s,r,a,o,n,d){const[l]=this.deriveDAOPDA(i),[u]=this.deriveModeratorPDA(i),[c]=this.deriveMintCreateKeyPDA(l,i),p=await this.fetchSquadsProgramConfig(),m=this.deriveMultisigPda(l),g=this.deriveMultisigPda(c);return{builder:(0,instructions_1.initializeParentDAO)(this.program,e,t,l,u,s,r,p.programConfig,p.programConfigTreasury,m,g,c,constants_1.SQUADS_PROGRAM_ID,i,a,o,n).preInstructions(this.maybeAddComputeBudget(d)),daoPda:l,moderatorPda:u,treasuryMultisig:m,mintMultisig:g}}async initializeChildDAO(e,t,i,s,r,a,o){const[n]=this.deriveDAOPDA(s),[d]=this.deriveDAOPDA(i),[l]=this.deriveMintCreateKeyPDA(n,s),u=await this.fetchSquadsProgramConfig(),c=this.deriveMultisigPda(n),p=this.deriveMultisigPda(l);return{builder:(0,instructions_1.initializeChildDAO)(this.program,e,t,n,d,r,u.programConfig,u.programConfigTreasury,c,p,l,constants_1.SQUADS_PROGRAM_ID,s,a).preInstructions(this.maybeAddComputeBudget(o)),daoPda:n,parentDaoPda:d,treasuryMultisig:c,mintMultisig:p}}async upgradeDAO(e,t,i,s,r,a,o,n,d){const[l]=this.deriveDAOPDA(i),[u]=this.deriveDAOPDA(s),[c]=this.deriveModeratorPDA(i);return{builder:(0,instructions_1.upgradeDAO)(this.program,e,t,l,u,c,r,a,o,n).preInstructions(this.maybeAddComputeBudget(d)),daoPda:l,moderatorPda:c}}async addHistoricalParentDAO(e,t,i,s,r,a,o,n,d,l,u,c){const[p]=this.deriveDAOPDA(t),[m]=this.deriveModeratorPDA(t);return{builder:(0,instructions_1.addHistoricalParentDAO)(this.program,e,p,m,r,a,i,s,t,o,n,d,l,u).preInstructions(this.maybeAddComputeBudget(c)),daoPda:p,moderatorPda:m}}async transferAdmin(e,t,i,s){const[r]=this.deriveDAOPDA(t),[a]=this.deriveModeratorPDA(t);return{builder:(0,instructions_1.transferAdmin)(this.program,e,r,a,i).preInstructions(this.maybeAddComputeBudget(s)),daoPda:r,moderatorPda:a}}}exports.FutarchyClient=FutarchyClient;
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,s){void 0===s&&(s=i);var r=Object.getOwnPropertyDescriptor(t,i);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,s,r)}:function(e,t,i,s){void 0===s&&(s=i),e[s]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[t.length]=i);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var i={};if(null!=t)for(var s=e(t),r=0;r<s.length;r++)"default"!==s[r]&&__createBinding(i,t,s[r]);return __setModuleDefault(i,t),i}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.FutarchyClient=void 0;const anchor_1=require("@coral-xyz/anchor"),web3_js_1=require("@solana/web3.js"),spl_token_1=require("@solana/spl-token"),constants_1=require("./constants"),utils_1=require("./utils"),instructions_1=require("./instructions"),vault_1=require("../vault"),amm_1=require("../amm"),idls_1=require("../generated/idls"),multisig=__importStar(require("@sqds/multisig")),DEFAULT_COMPUTE_UNITS=5e5;class FutarchyClient{constructor(e,t,i){this.programId=t??constants_1.PROGRAM_ID,this.program=new anchor_1.Program(idls_1.FutarchyIDL,e),this.vault=new vault_1.VaultClient(e),this.amm=new amm_1.AMMClient(e),this.defaultComputeUnits=i??5e5}deriveDAOPDA(e){return(0,utils_1.deriveDAOPDA)(e,this.programId)}deriveModeratorPDA(e){return(0,utils_1.deriveModeratorPDA)(e,this.programId)}deriveProposalPDA(e,t){return(0,utils_1.deriveProposalPDA)(e,t,this.programId)}async fetchDAO(e){return(0,utils_1.fetchDAOAccount)(this.program,e)}async fetchModerator(e){return(0,utils_1.fetchModeratorAccount)(this.program,e)}async fetchProposal(e){return(0,utils_1.fetchProposalAccount)(this.program,e)}isProposalExpired(e){return(0,utils_1.isProposalExpired)(e)}getTimeRemaining(e){return(0,utils_1.getTimeRemaining)(e)}getComputeUnits(e){return e?.computeUnits??this.defaultComputeUnits}maybeAddComputeBudget(e){if(!1===e?.includeCuBudget)return[];const t=[web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({units:this.getComputeUnits(e)})];return void 0!==e?.priorityFeeMicroLamports&&e.priorityFeeMicroLamports>0&&t.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:e.priorityFeeMicroLamports})),t}async initializeModerator(e,t,i,s,r){const[o]=this.deriveModeratorPDA(s);return{builder:(0,instructions_1.initializeModerator)(this.program,e,t,i,o,s).preInstructions(this.maybeAddComputeBudget(r)),moderatorPda:o,name:s}}async addHistoricalProposal(e,t,i,s,r,o,a,n){const d=(await this.fetchModerator(t)).proposalIdCounter,[l]=this.deriveProposalPDA(t,d);return{builder:(0,instructions_1.addHistoricalProposal)(this.program,e,t,l,i,s,r,o,a).preInstructions(this.maybeAddComputeBudget(n)),proposalPda:l,proposalId:d}}async initializeProposal(e,t,i,s,r){const o=await this.fetchModerator(t),a=o.proposalIdCounter,[n]=this.deriveProposalPDA(t,a),[d]=(0,vault_1.deriveVaultPDA)(n,a,this.vault.programId),[l]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Base,0,this.vault.programId),[u]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Base,1,this.vault.programId),[c]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Quote,0,this.vault.programId),[p]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Quote,1,this.vault.programId),[m]=(0,amm_1.derivePoolPDA)(n,c,l,this.amm.programId),[g]=(0,amm_1.derivePoolPDA)(n,p,u,this.amm.programId),[h]=(0,amm_1.deriveReservePDA)(m,c,this.amm.programId),[_]=(0,amm_1.deriveReservePDA)(m,l,this.amm.programId),[b]=(0,amm_1.deriveFeeVaultPDA)(m,this.amm.programId),[A]=(0,amm_1.deriveReservePDA)(g,p,this.amm.programId),[k]=(0,amm_1.deriveReservePDA)(g,u,this.amm.programId),[y]=(0,amm_1.deriveFeeVaultPDA)(g,this.amm.programId),v=(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint,d,!0),P=(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint,d,!0),f=[{pubkey:o.baseMint,isSigner:!1,isWritable:!1},{pubkey:o.quoteMint,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:v,isSigner:!1,isWritable:!0},{pubkey:P,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!0},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:p,isSigner:!1,isWritable:!0},{pubkey:m,isSigner:!1,isWritable:!0},{pubkey:h,isSigner:!1,isWritable:!0},{pubkey:_,isSigner:!1,isWritable:!0},{pubkey:amm_1.FEE_AUTHORITY,isSigner:!1,isWritable:!1},{pubkey:b,isSigner:!1,isWritable:!0},{pubkey:g,isSigner:!1,isWritable:!0},{pubkey:A,isSigner:!1,isWritable:!0},{pubkey:k,isSigner:!1,isWritable:!0},{pubkey:y,isSigner:!1,isWritable:!0}];return{builder:(0,instructions_1.initializeProposal)(this.program,e,t,n,i,s??null,f).preInstructions(this.maybeAddComputeBudget(r)),proposalPda:n,proposalId:a,vaultPda:d,pools:[m,g],condBaseMints:[l,u],condQuoteMints:[c,p]}}async addOption(e,t,i){const s=await this.fetchProposal(t),r=s.numOptions,[o]=(0,vault_1.deriveConditionalMint)(s.vault,vault_1.VaultType.Base,r,this.vault.programId),[a]=(0,vault_1.deriveConditionalMint)(s.vault,vault_1.VaultType.Quote,r,this.vault.programId),[n]=(0,amm_1.derivePoolPDA)(t,a,o,this.amm.programId),[d]=(0,amm_1.deriveReservePDA)(n,a,this.amm.programId),[l]=(0,amm_1.deriveReservePDA)(n,o,this.amm.programId),[u]=(0,amm_1.deriveFeeVaultPDA)(n,this.amm.programId),c=[{pubkey:s.vault,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:amm_1.FEE_AUTHORITY,isSigner:!1,isWritable:!1},{pubkey:u,isSigner:!1,isWritable:!0}];return{builder:(0,instructions_1.addOption)(this.program,e,t,c).preInstructions(this.maybeAddComputeBudget(i)),optionIndex:r,pool:n,condBaseMint:o,condQuoteMint:a}}async launchProposal(e,t,i,s,r){const o=await this.fetchProposal(t),a=await this.vault.fetchVault(o.vault),n=o.numOptions,d=a.condBaseMints.slice(0,n),l=a.condQuoteMints.slice(0,n);(r?.ensureATAs??n>=3)&&await this._createConditionalATAs(e,d,l,r?.priorityFeeMicroLamports);const u=o.pools.slice(0,n),c=d.map(t=>(0,spl_token_1.getAssociatedTokenAddressSync)(t,e)),p=l.map(t=>(0,spl_token_1.getAssociatedTokenAddressSync)(t,e)),m=[],g=[];for(let e=0;e<n;e++){const[t]=(0,amm_1.deriveReservePDA)(u[e],l[e],this.amm.programId),[i]=(0,amm_1.deriveReservePDA)(u[e],d[e],this.amm.programId);m.push(t),g.push(i)}const h=[{pubkey:a.baseMint.address,isSigner:!1,isWritable:!1},{pubkey:a.quoteMint.address,isSigner:!1,isWritable:!1},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint.address,o.vault,!0),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint.address,o.vault,!0),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(a.baseMint.address,e),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(a.quoteMint.address,e),isSigner:!1,isWritable:!0}];for(const e of d)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of l)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of c)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of p)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of u)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of m)h.push({pubkey:e,isSigner:!1,isWritable:!0});for(const e of g)h.push({pubkey:e,isSigner:!1,isWritable:!0});return{builder:(0,instructions_1.launchProposal)(this.program,e,t,o.vault,i,s,h).preInstructions(this.maybeAddComputeBudget(r))}}async ensureConditionalATAs(e,t,i){const s=await this.fetchProposal(t),r=await this.vault.fetchVault(s.vault),o=r.condBaseMints.slice(0,s.numOptions),a=r.condQuoteMints.slice(0,s.numOptions);return this._createConditionalATAs(e,o,a,i?.priorityFeeMicroLamports)}async _createConditionalATAs(e,t,i,s){const r=this.program.provider,o=[];s&&s>0&&o.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s}));for(let s=0;s<t.length;s++){const r=(0,spl_token_1.getAssociatedTokenAddressSync)(t[s],e),a=(0,spl_token_1.getAssociatedTokenAddressSync)(i[s],e);o.push((0,spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(e,r,e,t[s]),(0,spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(e,a,e,i[s]))}const a=(new web3_js_1.Transaction).add(...o);return r.sendAndConfirm(a)}async finalizeProposal(e,t,i){const s=await this.fetchProposal(t),r=await this.vault.fetchVault(s.vault),o=s.numOptions,a=[];for(let e=0;e<o;e++){const t=s.pools[e],[i]=(0,amm_1.deriveReservePDA)(t,r.condQuoteMints[e],this.amm.programId),[o]=(0,amm_1.deriveReservePDA)(t,r.condBaseMints[e],this.amm.programId);a.push({pubkey:t,isSigner:!1,isWritable:!0}),a.push({pubkey:i,isSigner:!1,isWritable:!1}),a.push({pubkey:o,isSigner:!1,isWritable:!1})}return{builder:(0,instructions_1.finalizeProposal)(this.program,e,t,s.vault,a).preInstructions(this.maybeAddComputeBudget(i))}}async redeemLiquidity(e,t,i){const s=await this.fetchProposal(t),r=await this.vault.fetchVault(s.vault),o=s.numOptions,{winningIdx:a}=(0,utils_1.parseProposalState)(s.state);if(null===a)throw new Error("Proposal not finalized");const n=s.pools[a],[d]=(0,amm_1.deriveReservePDA)(n,r.condQuoteMints[a],this.amm.programId),[l]=(0,amm_1.deriveReservePDA)(n,r.condBaseMints[a],this.amm.programId),u=[{pubkey:d,isSigner:!1,isWritable:!0},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condQuoteMints[a],e),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condBaseMints[a],e),isSigner:!1,isWritable:!0},{pubkey:r.baseMint.address,isSigner:!1,isWritable:!1},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.baseMint.address,s.vault,!0),isSigner:!1,isWritable:!0},{pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.baseMint.address,e),isSigner:!1,isWritable:!0}];for(let t=0;t<o;t++)u.push({pubkey:r.condBaseMints[t],isSigner:!1,isWritable:!0}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condBaseMints[t],e),isSigner:!1,isWritable:!0});u.push({pubkey:r.quoteMint.address,isSigner:!1,isWritable:!1}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.quoteMint.address,s.vault,!0),isSigner:!1,isWritable:!0}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.quoteMint.address,e),isSigner:!1,isWritable:!0});for(let t=0;t<o;t++)u.push({pubkey:r.condQuoteMints[t],isSigner:!1,isWritable:!0}),u.push({pubkey:(0,spl_token_1.getAssociatedTokenAddressSync)(r.condQuoteMints[t],e),isSigner:!1,isWritable:!0});return{builder:(0,instructions_1.redeemLiquidity)(this.program,e,t,s.vault,n,u).preInstructions(this.maybeAddComputeBudget(i)),numOptions:o}}async createRedemptionALT(e,t,i=0){const s=this.program.provider,r=await this.fetchProposal(t),o=await this.vault.fetchVault(r.vault),a=r.numOptions,{winningIdx:n}=(0,utils_1.parseProposalState)(r.state);if(null===n)throw new Error("Proposal not finalized");const d=[this.programId,this.vault.programId,this.amm.programId,web3_js_1.SystemProgram.programId,spl_token_1.TOKEN_PROGRAM_ID,spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,t,r.vault,r.moderator,o.baseMint.address,o.quoteMint.address,r.pools[n],(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint.address,r.vault,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint.address,r.vault,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint.address,e),(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint.address,e)],[l]=(0,amm_1.deriveReservePDA)(r.pools[n],o.condQuoteMints[n],this.amm.programId),[u]=(0,amm_1.deriveReservePDA)(r.pools[n],o.condBaseMints[n],this.amm.programId);d.push(l,u);for(let t=0;t<a;t++)d.push(o.condBaseMints[t],o.condQuoteMints[t],(0,spl_token_1.getAssociatedTokenAddressSync)(o.condBaseMints[t],e),(0,spl_token_1.getAssociatedTokenAddressSync)(o.condQuoteMints[t],e));const c=await s.connection.getSlot("finalized"),[p,m]=web3_js_1.AddressLookupTableProgram.createLookupTable({authority:e,payer:e,recentSlot:c}),g=new web3_js_1.Transaction;i>0&&g.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:i})),g.add(p);const{blockhash:h,lastValidBlockHeight:_}=await s.connection.getLatestBlockhash("confirmed");g.recentBlockhash=h,g.feePayer=e;const b=await s.wallet.signTransaction(g),A=await s.connection.sendRawTransaction(b.serialize(),{skipPreflight:!0});await s.connection.confirmTransaction({signature:A,blockhash:h,lastValidBlockHeight:_},"confirmed");for(let t=0;t<d.length;t+=20){const r=d.slice(t,t+20),o=web3_js_1.AddressLookupTableProgram.extendLookupTable({payer:e,authority:e,lookupTable:m,addresses:r}),a=new web3_js_1.Transaction;i>0&&a.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:i})),a.add(o);const{blockhash:n,lastValidBlockHeight:l}=await s.connection.getLatestBlockhash("confirmed");a.recentBlockhash=n,a.feePayer=e;const u=await s.wallet.signTransaction(a),c=await s.connection.sendRawTransaction(u.serialize(),{skipPreflight:!0});await s.connection.confirmTransaction({signature:c,blockhash:n,lastValidBlockHeight:l},"confirmed")}return{altAddress:m}}async redeemLiquidityVersioned(e,t,i,s){const r=this.program.provider,{builder:o,numOptions:a}=await this.redeemLiquidity(e,t);let n=i,d=null;if(!n&&a>=3){console.log(` Creating redemption ALT for ${a} options...`);n=(await this.createRedemptionALT(e,t)).altAddress,console.log(` ✓ Redemption ALT created: ${n.toBase58()}`),console.log(" Waiting for ALT propagation...");const i=18+4*a;let s=0;for(await new Promise(e=>setTimeout(e,2e3));s<30;){const e=await r.connection.getAddressLookupTable(n,{commitment:"confirmed"});if(e.value){const t=e.value.state.addresses.length;if(console.log(` Attempt ${s+1}: ALT has ${t}/${i} addresses`),t>=i){d=e.value,console.log(` ✓ ALT verified with ${t} addresses`);break}}await new Promise(e=>setTimeout(e,1e3)),s++}if(!d)throw new Error(`ALT failed to populate with expected ${i} addresses after ${s} attempts`)}if(!n)throw new Error("ALT address required for multi-option redemption");d||(d=await this.fetchALT(n));const l=await o.instruction(),u=[web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({units:5e5})];void 0!==s?.priorityFeeMicroLamports&&s.priorityFeeMicroLamports>0&&u.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s.priorityFeeMicroLamports}));const{blockhash:c,lastValidBlockHeight:p}=await r.connection.getLatestBlockhash("confirmed");return{versionedTx:this.buildVersionedTxWithALT(e,[...u,l],d,c),altAddress:n,numOptions:a,blockhash:c,lastValidBlockHeight:p}}async sendVersionedTransaction(e,t){const i=this.program.provider;let s,r;if(t)s=t.blockhash,r=t.lastValidBlockHeight;else{const e=await i.connection.getLatestBlockhash("confirmed");s=e.blockhash,r=e.lastValidBlockHeight}const o=await i.connection.sendTransaction(e,{skipPreflight:!1,preflightCommitment:"confirmed"});return await i.connection.confirmTransaction({signature:o,blockhash:s,lastValidBlockHeight:r},"confirmed"),o}async createProposalALT(e,t,i=2,s=0){const r=this.program.provider,o=await this.fetchModerator(t),a=o.proposalIdCounter,[n]=this.deriveProposalPDA(t,a),[d]=(0,vault_1.deriveVaultPDA)(n,a,this.vault.programId),l=[this.programId,this.vault.programId,this.amm.programId,web3_js_1.SystemProgram.programId,spl_token_1.TOKEN_PROGRAM_ID,spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,t,n,d,o.baseMint,o.quoteMint,amm_1.FEE_AUTHORITY,(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint,d,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint,d,!0),(0,spl_token_1.getAssociatedTokenAddressSync)(o.baseMint,e),(0,spl_token_1.getAssociatedTokenAddressSync)(o.quoteMint,e)];for(let t=0;t<i;t++){const[i]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Base,t,this.vault.programId),[s]=(0,vault_1.deriveConditionalMint)(d,vault_1.VaultType.Quote,t,this.vault.programId),[r]=(0,amm_1.derivePoolPDA)(n,s,i,this.amm.programId),[o]=(0,amm_1.deriveReservePDA)(r,s,this.amm.programId),[a]=(0,amm_1.deriveReservePDA)(r,i,this.amm.programId),[u]=(0,amm_1.deriveFeeVaultPDA)(r,this.amm.programId);l.push(i,s,r,o,a,u,(0,spl_token_1.getAssociatedTokenAddressSync)(i,e),(0,spl_token_1.getAssociatedTokenAddressSync)(s,e))}const u=await r.connection.getSlot("finalized"),[c,p]=web3_js_1.AddressLookupTableProgram.createLookupTable({authority:e,payer:e,recentSlot:u}),m=new web3_js_1.Transaction;s>0&&m.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s})),m.add(c);const{blockhash:g,lastValidBlockHeight:h}=await r.connection.getLatestBlockhash("confirmed");m.recentBlockhash=g,m.feePayer=e;const _=await r.wallet.signTransaction(m),b=await r.connection.sendRawTransaction(_.serialize(),{skipPreflight:!0});await r.connection.confirmTransaction({signature:b,blockhash:g,lastValidBlockHeight:h},"confirmed");for(let t=0;t<l.length;t+=20){const i=l.slice(t,t+20),o=web3_js_1.AddressLookupTableProgram.extendLookupTable({payer:e,authority:e,lookupTable:p,addresses:i}),a=new web3_js_1.Transaction;s>0&&a.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({microLamports:s})),a.add(o);const{blockhash:n,lastValidBlockHeight:d}=await r.connection.getLatestBlockhash("confirmed");a.recentBlockhash=n,a.feePayer=e;const u=await r.wallet.signTransaction(a),c=await r.connection.sendRawTransaction(u.serialize(),{skipPreflight:!0});await r.connection.confirmTransaction({signature:c,blockhash:n,lastValidBlockHeight:d},"confirmed")}return{altAddress:p}}async fetchALT(e){const t=await this.program.provider.connection.getAddressLookupTable(e);if(!t.value)throw new Error("ALT not found");return t.value}async buildVersionedTx(e,t,i){const s=this.program.provider,r=await this.fetchALT(i),{blockhash:o,lastValidBlockHeight:a}=await s.connection.getLatestBlockhash("confirmed");return{versionedTx:this.buildVersionedTxWithALT(e,t,r,o),blockhash:o,lastValidBlockHeight:a}}buildVersionedTxWithALT(e,t,i,s){const r=new web3_js_1.TransactionMessage({payerKey:e,recentBlockhash:s,instructions:t}).compileToV0Message([i]);return new web3_js_1.VersionedTransaction(r)}deriveMintCreateKeyPDA(e,t){return(0,utils_1.deriveMintCreateKeyPDA)(e,t,this.programId)}async fetchSquadsProgramConfig(){const[e]=multisig.getProgramConfigPda({programId:constants_1.SQUADS_PROGRAM_ID});return{programConfig:e,programConfigTreasury:(await multisig.accounts.ProgramConfig.fromAccountAddress(this.program.provider.connection,e)).treasury}}deriveMultisigPda(e){const[t]=multisig.getMultisigPda({createKey:e,programId:constants_1.SQUADS_PROGRAM_ID});return t}async initializeParentDAO(e,t,i,s,r,o,a,n,d){const[l]=this.deriveDAOPDA(i),[u]=this.deriveModeratorPDA(i),[c]=this.deriveMintCreateKeyPDA(l,i),p=await this.fetchSquadsProgramConfig(),m=this.deriveMultisigPda(l),g=this.deriveMultisigPda(c);return{builder:(0,instructions_1.initializeParentDAO)(this.program,e,t,l,u,s,r,p.programConfig,p.programConfigTreasury,m,g,c,constants_1.SQUADS_PROGRAM_ID,i,o,a,n).preInstructions(this.maybeAddComputeBudget(d)),daoPda:l,moderatorPda:u,treasuryMultisig:m,mintMultisig:g}}async initializeChildDAO(e,t,i,s,r,o,a){const[n]=this.deriveDAOPDA(s),[d]=this.deriveDAOPDA(i),[l]=this.deriveMintCreateKeyPDA(n,s),u=await this.fetchSquadsProgramConfig(),c=this.deriveMultisigPda(n),p=this.deriveMultisigPda(l);return{builder:(0,instructions_1.initializeChildDAO)(this.program,e,t,n,d,r,u.programConfig,u.programConfigTreasury,c,p,l,constants_1.SQUADS_PROGRAM_ID,s,o).preInstructions(this.maybeAddComputeBudget(a)),daoPda:n,parentDaoPda:d,treasuryMultisig:c,mintMultisig:p}}async upgradeDAO(e,t,i,s,r,o,a,n,d){const[l]=this.deriveDAOPDA(i),[u]=this.deriveDAOPDA(s),[c]=this.deriveModeratorPDA(i);return{builder:(0,instructions_1.upgradeDAO)(this.program,e,t,l,u,c,r,o,a,n).preInstructions(this.maybeAddComputeBudget(d)),daoPda:l,moderatorPda:c}}async addHistoricalParentDAO(e,t,i,s,r,o,a,n,d,l,u,c){const[p]=this.deriveDAOPDA(t),[m]=this.deriveModeratorPDA(t);return{builder:(0,instructions_1.addHistoricalParentDAO)(this.program,e,p,m,r,o,i,s,t,a,n,d,l,u).preInstructions(this.maybeAddComputeBudget(c)),daoPda:p,moderatorPda:m}}async transferAdmin(e,t,i,s){const[r]=this.deriveDAOPDA(t),[o]=this.deriveModeratorPDA(t);return{builder:(0,instructions_1.transferAdmin)(this.program,e,r,o,i).preInstructions(this.maybeAddComputeBudget(s)),daoPda:r,moderatorPda:o}}}exports.FutarchyClient=FutarchyClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomb/programs-sdk",
3
- "version": "1.11.2",
3
+ "version": "1.11.3",
4
4
  "description": "SDK for ZCombinator Programs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",