@debridge-finance/intents-client 1.0.0-dev.0 → 1.0.0-dev.2

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/README.md CHANGED
@@ -67,15 +67,12 @@ The examples folder contains a sequence of files that demonstrate the complete w
67
67
  - Fall back to multi-transaction if needed
68
68
  - Send transactions to blockchain
69
69
 
70
- 4. **Authorize Tokens** (`04-give-token-approval.ts`)
71
- - Generate approval instructions for protocol transfers
72
-
73
- 5. **Execute Swap** (`05-sandwich-swap.ts`)
70
+ 4. **Execute Swap** (`04-sandwich-swap.ts`)
74
71
  - Set up token accounts
75
72
  - Create swap transaction with intent
76
73
  - Execute the swap
77
74
 
78
- 6. **Complete Intent** (`06-intent-execution.ts`)
75
+ 5. **Complete Intent** (`05-intent-execution.ts`)
79
76
  - Initialize DLN client
80
77
  - Create cross-chain order
81
78
  - Generate final execution instructions
package/dist/index.d.mts CHANGED
@@ -1800,6 +1800,14 @@ type ComputeBudget = {
1800
1800
  limit?: number;
1801
1801
  price?: number;
1802
1802
  };
1803
+ interface ApproveProtocolTransfersParams {
1804
+ owner: PublicKey;
1805
+ tokens: {
1806
+ mint: PublicKey;
1807
+ amount: bigint;
1808
+ }[];
1809
+ tokenProgram?: PublicKey;
1810
+ }
1803
1811
  interface UpdateIntent {
1804
1812
  payer?: PublicKey;
1805
1813
  id: Buffer;
@@ -1952,6 +1960,7 @@ declare class IntentsClient {
1952
1960
  private getSpace;
1953
1961
  getState(connection: Connection): Promise<State | null>;
1954
1962
  getIntentStorage(connection: Connection, intentId: Buffer): Promise<IntentStorage | null>;
1963
+ approveProtocolTransfersIxs({ owner, tokens, tokenProgram, }: ApproveProtocolTransfersParams): Promise<TransactionInstruction[]>;
1955
1964
  private closeIntentIxs;
1956
1965
  executeIntentIxs({ intentId, taker, maker, tokenMint, order, dlnSrc, tokenProgram, }: ExecuteIntentParams): Promise<TransactionInstruction[]>;
1957
1966
  initIntentIxs(maker: PublicKey, payer: PublicKey, id: Buffer, encodedIntentLength: number, inputTokensAmount: number): Promise<TransactionInstruction[]>;
@@ -1972,7 +1981,6 @@ declare class IntentsClient {
1972
1981
  createIntentTxs({ authority, payer, intent, signature, blockhash, ALTs, computeBudget, }: InitIntentParams): Promise<{
1973
1982
  init: VersionedTransaction[];
1974
1983
  write: VersionedTransaction[];
1975
- record: PublicKey;
1976
1984
  }>;
1977
1985
  createAndUpdateIntentTxs({ authority, payer, intent, signature, blockhash, ALTs, computeBudget, }: CreateAndUpdateIntentParams): Promise<VersionedTransaction[]>;
1978
1986
  updateRecordTxs({ authority, payer, record, serializedIntent, offset, blockhash, ALTs, computeBudget, }: UpdateRecordTxsParams): Promise<VersionedTransaction[]>;
package/dist/index.d.ts CHANGED
@@ -1800,6 +1800,14 @@ type ComputeBudget = {
1800
1800
  limit?: number;
1801
1801
  price?: number;
1802
1802
  };
1803
+ interface ApproveProtocolTransfersParams {
1804
+ owner: PublicKey;
1805
+ tokens: {
1806
+ mint: PublicKey;
1807
+ amount: bigint;
1808
+ }[];
1809
+ tokenProgram?: PublicKey;
1810
+ }
1803
1811
  interface UpdateIntent {
1804
1812
  payer?: PublicKey;
1805
1813
  id: Buffer;
@@ -1952,6 +1960,7 @@ declare class IntentsClient {
1952
1960
  private getSpace;
1953
1961
  getState(connection: Connection): Promise<State | null>;
1954
1962
  getIntentStorage(connection: Connection, intentId: Buffer): Promise<IntentStorage | null>;
1963
+ approveProtocolTransfersIxs({ owner, tokens, tokenProgram, }: ApproveProtocolTransfersParams): Promise<TransactionInstruction[]>;
1955
1964
  private closeIntentIxs;
1956
1965
  executeIntentIxs({ intentId, taker, maker, tokenMint, order, dlnSrc, tokenProgram, }: ExecuteIntentParams): Promise<TransactionInstruction[]>;
1957
1966
  initIntentIxs(maker: PublicKey, payer: PublicKey, id: Buffer, encodedIntentLength: number, inputTokensAmount: number): Promise<TransactionInstruction[]>;
@@ -1972,7 +1981,6 @@ declare class IntentsClient {
1972
1981
  createIntentTxs({ authority, payer, intent, signature, blockhash, ALTs, computeBudget, }: InitIntentParams): Promise<{
1973
1982
  init: VersionedTransaction[];
1974
1983
  write: VersionedTransaction[];
1975
- record: PublicKey;
1976
1984
  }>;
1977
1985
  createAndUpdateIntentTxs({ authority, payer, intent, signature, blockhash, ALTs, computeBudget, }: CreateAndUpdateIntentParams): Promise<VersionedTransaction[]>;
1978
1986
  updateRecordTxs({ authority, payer, record, serializedIntent, offset, blockhash, ALTs, computeBudget, }: UpdateRecordTxsParams): Promise<VersionedTransaction[]>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var anchor=require('@coral-xyz/anchor'),solanaUtils=require('@debridge-finance/solana-utils'),web3_js=require('@solana/web3.js'),splToken=require('@solana/spl-token'),splRecord=require('@solana/spl-record'),jsSha3=require('js-sha3');var K={address:"intueneJjzHttKp83gWH3GX1h1Uwuixuusj4T8vGDzk",metadata:{name:"intentsProgram",version:"0.0.0",spec:"0.1.0",description:"deBridge Intents Program"},instructions:[{name:"approveProtocolTransfers",discriminator:[17,3,184,144,112,130,116,98],accounts:[{name:"owner",signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"tokenProgram"}],args:[{name:"amounts",type:{vec:"u64"}}]},{name:"authorizedTransfer",discriminator:[136,178,202,213,255,92,81,119],accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"from"},{name:"to"},{name:"mint"},{name:"tokenProgram"}],args:[{name:"amount",type:"u64"}]},{name:"closeAccount",discriminator:[125,255,149,14,110,34,72,24],accounts:[{name:"programAuthority",signer:true,address:"intueneJjzHttKp83gWH3GX1h1Uwuixuusj4T8vGDzk"},{name:"target",writable:true},{name:"rentReceiver",writable:true}],args:[]},{name:"closeIntent",discriminator:[112,245,154,249,57,126,54,122],accounts:[{name:"initiator",writable:true,signer:true},{name:"rentPayer",writable:true},{name:"intentStorage",writable:true},{name:"state"},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[]},{name:"collectFee",discriminator:[60,173,247,103,4,93,130,48],accounts:[{name:"feeCollector",signer:true,relations:["state"]},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"feeLedger",writable:true,pda:{seeds:[{kind:"account",path:"state"},{kind:"account",path:"tokenProgram"},{kind:"account",path:"mint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"destination",writable:true},{name:"mint"},{name:"tokenProgram"}],args:[{name:"amount",type:"u64"}]},{name:"executeIntent",discriminator:[53,130,47,154,227,220,122,212],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"maker"},{name:"makerGiveToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"const",value:[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{kind:"account",path:"tokenMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"dlnSrc",address:"srch38nzfcgwJnfKE6xWD8vfNJtudazwisdcociAuQt"},{name:"dlnSrcState"},{name:"dlnSrcGiveOrderState",writable:true},{name:"dlnSrcGiveOrderWallet",writable:true},{name:"dlnSrcAuthorizedNativeSender"},{name:"dlnSrcFeeLedgerWallet",writable:true},{name:"tokenMint"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[{name:"dlnOrderArgs",type:"bytes"},{name:"dlnOrderNonce",type:"u64"}]},{name:"initIntent",discriminator:[231,255,81,23,112,148,49,134],accounts:[{name:"maker",signer:true},{name:"rentPayer",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"space",type:"u32"}]},{name:"initIntentUsingSig",discriminator:[163,186,238,179,190,181,19,185],accounts:[{name:"rentPayer",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"space",type:"u32"},{name:"maker",type:"pubkey"},{name:"signature",type:{array:["u8",64]}}]},{name:"initState",discriminator:[124,213,73,136,80,37,141,54],accounts:[{name:"protocolAuthority",signer:true},{name:"programAuthority",signer:true,address:"intueneJjzHttKp83gWH3GX1h1Uwuixuusj4T8vGDzk"},{name:"rentPayer",writable:true,signer:true},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[]},{name:"reallocState",discriminator:[67,181,233,214,215,148,245,126],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]},{name:"rentPayer",writable:true,signer:true},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"newSpace",type:"u32"}]},{name:"setDefaultFee",discriminator:[150,137,197,111,176,227,201,110],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"defaultFeeBps",type:"u16"}]},{name:"setDelegateApprovedBudgets",discriminator:[82,182,181,250,30,186,95,15],accounts:[{name:"maker",signer:true},{name:"rentPayer",writable:true,signer:true},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"state"},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"delegate",type:"pubkey"},{name:"nonce",type:"u64"},{name:"args",type:{defined:{name:"setApprovedTokenBudgets"}}}]},{name:"setFeeCollector",discriminator:[143,46,10,113,121,157,245,166],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"feeCollector",type:"pubkey"}]},{name:"setLastValidTimestamp",discriminator:[70,101,113,35,233,224,156,184],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"lastValidTimestamp",type:"u64"}]},{name:"setPause",discriminator:[63,32,154,2,56,103,79,45],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"pauseFlag",type:"bool"}]},{name:"setProtocolAuthority",discriminator:[96,162,46,152,72,147,175,176],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]},{name:"newProtocolAuthority",signer:true}],args:[]},{name:"swapBegin",discriminator:[87,236,193,120,215,245,9,37],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"feeLedger",writable:true,pda:{seeds:[{kind:"account",path:"state"},{kind:"account",path:"inputTokenProgram"},{kind:"account",path:"inputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"intentStorage",writable:true},{name:"inputMint"},{name:"outputMint"},{name:"makerInputToken",writable:true},{name:"takerInputToken",writable:true,pda:{seeds:[{kind:"account",path:"taker"},{kind:"account",path:"inputTokenProgram"},{kind:"account",path:"inputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"takerOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"taker"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"intentOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"instructions",address:"Sysvar1nstructions1111111111111111111111111"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"inputTokenProgram"},{name:"outputTokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[{name:"amount",type:"u64"},{name:"target",type:{defined:{name:"targetTokenAccount"}}}]},{name:"swapEnd",discriminator:[75,178,142,132,50,126,38,31],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"outputMint"},{name:"takerOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"taker"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"intentOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"instructions",address:"Sysvar1nstructions1111111111111111111111111"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"outputTokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[]},{name:"updateIntent",discriminator:[214,203,249,158,90,27,54,17],accounts:[{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"buffer",optional:true}],args:[{name:"dataOrigin",type:{defined:{name:"dataOrigin"}}}]}],accounts:[{name:"intentStorage",discriminator:[175,239,93,146,246,119,144,249]},{name:"makerInfo",discriminator:[164,184,52,218,144,52,100,40]},{name:"state",discriminator:[216,146,107,94,104,75,182,177]}],errors:[{code:6e3,name:"protocolIsOnPause",msg:"Protocol is on pause"},{code:6001,name:"unknownCaller",msg:"Unknown caller"},{code:6002,name:"sigVerifyErr",msg:"Ed25519 signature is invalid or does not match provided intent hash and public key"},{code:6003,name:"intentStorageIsInitialized",msg:"Intent storage is already initialized"},{code:6004,name:"intentStorageIsSealed",msg:"Intent encoded data already matches expected hash"},{code:6005,name:"intentHashMismatch",msg:"Intent ..."},{code:6006,name:"intentIsInvalidatedByUser"},{code:6007,name:"intentIsInvalidatedByProtocolAuthority"},{code:6008,name:"intentIsExpired"},{code:6009,name:"intentIsNotReadyYet",msg:"Intent is not ready for execution yet"},{code:6010,name:"unknownInputToken"},{code:6011,name:"insufficientInputTokenAmount"},{code:6012,name:"intentArbitraryDataOverflow"},{code:6013,name:"takerIsNotAllowed"},{code:6014,name:"delegateNonceIsAdvanced"}],types:[{name:"approvedTokenBudget",type:{kind:"struct",fields:[{name:"tokenMint",type:"pubkey"},{name:"approvedAmount",type:"u64"},{name:"expiration",type:"u64"}]}},{name:"currentTokenBudget",type:{kind:"struct",fields:[{name:"tokenMint",type:"pubkey"},{name:"approvedAmount",type:"u64"},{name:"expiration",type:"u64"},{name:"remainingAmount",type:"u64"}]}},{name:"dataOrigin",type:{kind:"enum",variants:[{name:"instruction",fields:["bytes"]},{name:"buffer",fields:[{name:"offset",type:"u32"},{name:"length",type:"u32"}]}]}},{name:"delegateBudgets",type:{kind:"enum",variants:[{name:"perToken",fields:[{vec:{defined:{name:"currentTokenBudget"}}}]},{name:"any"},{name:"revoked"}]}},{name:"delegateInfo",type:{kind:"struct",fields:[{name:"delegate",type:"pubkey"},{name:"nonce",type:"u64"},{name:"budgets",type:{defined:{name:"delegateBudgets"}}}]}},{name:"intentBudget",type:{kind:"struct",fields:[{name:"mintIndex",type:"u8"},{name:"remainingAmount",type:"u64"}]}},{name:"intentBudgets",type:{kind:"struct",fields:[{vec:{defined:{name:"intentBudget"}}}]}},{name:"intentId",type:{kind:"struct",fields:[{array:["u8",32]}]}},{name:"intentStorage",type:{kind:"struct",fields:[{name:"maker",type:"pubkey"},{name:"rentPayer",type:"pubkey"},{name:"arbitraryData",type:{array:["u8",100]}},{name:"intentId",type:{defined:{name:"intentId"}}},{name:"version",type:"u8"},{name:"storedIntent",type:{defined:{name:"storedIntent"}}},{name:"bump",type:"u8"}]}},{name:"makerInfo",type:{kind:"struct",fields:[{name:"lastValidTimestamp",type:"u64"},{name:"delegates",type:{vec:{defined:{name:"delegateInfo"}}}}]}},{name:"setApprovedTokenBudgets",type:{kind:"enum",variants:[{name:"set",fields:[{vec:{defined:{name:"approvedTokenBudget"}}}]},{name:"setAny"},{name:"revoke"}]}},{name:"state",type:{kind:"struct",fields:[{name:"protocolAuthority",type:"pubkey"},{name:"feeCollector",type:"pubkey"},{name:"defaultFeeBps",type:"u16"},{name:"isPaused",type:"bool"},{name:"lastValidTimestamp",type:"u64"},{name:"bump",type:"u8"}]}},{name:"storedIntent",type:{kind:"enum",variants:[{name:"uninitialized"},{name:"inProgress",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]},{name:"closed",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]},{name:"terminated"}]}},{name:"targetTokenAccount",type:{kind:"enum",variants:[{name:"taker"},{name:"intent"}]}}],constants:[{name:"intentStorageBaseSeed",type:"bytes",value:"[105, 110, 116, 101, 110, 116, 95, 115, 116, 111, 114, 97, 103, 101]"},{name:"makerInfoSeed",type:"bytes",value:"[109, 97, 107, 101, 114, 95, 105, 110, 102, 111]"},{name:"stateSeed",type:"bytes",value:"[115, 116, 97, 116, 101]"}]};var w=l=>{let e=[];return l?.limit&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({units:l.limit})),l?.price&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({microLamports:l.price})),e},I=({instructions:l,payer:e,blockhash:n,ALTs:t})=>new web3_js.VersionedTransaction(web3_js.MessageV0.compile({instructions:l,payerKey:e,recentBlockhash:n,addressLookupTableAccounts:t}));var T=splRecord.RECORD_META_DATA_SIZE,F=class l{programId;recordProgramId;_provider;_intentsProgram;_state;constructor(e,{programId:n,recordProgramId:t=splRecord.RECORD_PROGRAM_ID}){K.address=n.toString(),this.programId=n,this.recordProgramId=t,this._provider=new anchor.AnchorProvider(e,{},{}),anchor.setProvider(this._provider),this._intentsProgram=new anchor.Program(K,this._provider),this._state=l.getStatePda(this._intentsProgram.programId);}getSpace(e,n){return 198+(1+e+(4+9*n))}async getState(e){let n=await e.getAccountInfo(this._state);if(!n)return null;let t=this._intentsProgram.coder.accounts.decode("state",n.data);return {...t,lastValidTimestamp:Number(t.lastValidTimestamp.toString())}}async getIntentStorage(e,n){let t=l.getIntentStoragePda(this._intentsProgram.programId,n),a=await e.getAccountInfo(t);if(!a)return null;let r=this._intentsProgram.coder.accounts.decode("intentStorage",a.data);return {...r,intentId:Buffer.from(r.intentId[0])}}async closeIntentIxs(e,n,t){return [await this._intentsProgram.methods.closeIntent().accountsStrict({initiator:e,rentPayer:n,intentStorage:l.getIntentStoragePda(this._intentsProgram.programId,t),state:this._state,systemProgram:web3_js.SystemProgram.programId}).instruction()]}async executeIntentIxs({intentId:e,taker:n,maker:t,tokenMint:a,order:r,dlnSrc:i=new web3_js.PublicKey(solanaUtils.programs.dlnSrc),tokenProgram:s=splToken.TOKEN_PROGRAM_ID}){let o=solanaUtils.dlnSrcResolver(i).methods,[d]=o.getStateAccount(),[u]=o.getGiveOrderStateAccount(r.id),[m]=o.getGiveOrderWalletAddress(r.id),[c]=o.getAuthorizedNativeSenderAddress(Buffer.from(new anchor.BN(r.dstChainId.toString()).toArray("be",32))),[p]=o.getFeeLedgerWalletAddress(a),f=l.getIntentStoragePda(this._intentsProgram.programId,e),g=splToken.getAssociatedTokenAddressSync(a,f,true,s);return [await this._intentsProgram.methods.executeIntent(r.args,new anchor.BN(r.nonce.toString())).accountsStrict({taker:n,state:this._state,intentStorage:f,maker:t,makerGiveToken:g,dlnSrc:i,dlnSrcState:d,dlnSrcGiveOrderState:u,dlnSrcGiveOrderWallet:m,dlnSrcAuthorizedNativeSender:c,dlnSrcFeeLedgerWallet:p,tokenMint:a,systemProgram:web3_js.SystemProgram.programId,tokenProgram:s,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID}).instruction()]}async initIntentIxs(e,n,t,a,r){let i=this.getSpace(a,r);return [await this._intentsProgram.methods.initIntent({0:Array.from(t)},i).accountsStrict({maker:e,rentPayer:n,state:this._state,intentStorage:l.getIntentStoragePda(this._intentsProgram.programId,t),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async initIntentUsingSigIxs(e,n,t,a,r,i){let s=this.getSpace(a,r);return [await this._intentsProgram.methods.initIntentUsingSig({0:Array.from(t)},s,e,Array.from(i)).accountsStrict({rentPayer:n,state:this._state,intentStorage:l.getIntentStoragePda(this._intentsProgram.programId,t),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async setDelegateApprovedBudgetsIxs({maker:e,payer:n,delegate:t,nonce:a,tokens:r}){let i;return "set"in r?i={set:r.set.map(({tokenMint:s,approvedAmount:o,expiration:d})=>({tokenMint:s,approvedAmount:new anchor.BN(o.toString()),expiration:new anchor.BN(d.toString())}))}:"setAny"in r?i={setAny:{}}:i={revoke:{}},[await this._intentsProgram.methods.setDelegateApprovedBudgets(t,new anchor.BN(a.toString()),i).accountsStrict({maker:e,rentPayer:n,state:this._state,makerInfo:l.getMakerInfoPda(this._intentsProgram.programId,e),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async swapBeginIxs({taker:e,maker:n,intentId:t,amount:a,target:r,inputMint:i,outputMint:s,inputTokenProgram:o=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:d=splToken.TOKEN_PROGRAM_ID}){let u=l.getIntentStoragePda(this._intentsProgram.programId,t),m=splToken.getAssociatedTokenAddressSync(i,this._state,true,o),c=splToken.getAssociatedTokenAddressSync(i,n,true,o),p=splToken.getAssociatedTokenAddressSync(i,e,true,o),f=splToken.getAssociatedTokenAddressSync(s,e,true,d),g=splToken.getAssociatedTokenAddressSync(s,u,true,d);return [await this._intentsProgram.methods.swapBegin(new anchor.BN(a.toString()),r==="intent"?{intent:{}}:{taker:{}}).accountsStrict({taker:e,state:this._state,feeLedger:m,intentStorage:u,inputMint:i,outputMint:s,makerInputToken:c,takerInputToken:p,takerOutputToken:f,intentOutputToken:g,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,inputTokenProgram:o,outputTokenProgram:d,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID}).instruction()]}async swapEndIxs({taker:e,intentId:n,outputMint:t,outputTokenProgram:a=splToken.TOKEN_PROGRAM_ID}){let r=l.getIntentStoragePda(this._intentsProgram.programId,n),i=splToken.getAssociatedTokenAddressSync(t,e,true,a),s=splToken.getAssociatedTokenAddressSync(t,r,true,a);return [await this._intentsProgram.methods.swapEnd().accountsStrict({taker:e,state:this._state,intentStorage:r,outputMint:t,takerOutputToken:i,intentOutputToken:s,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,outputTokenProgram:a,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID}).instruction()]}async updateIntentIxs({payer:e,record:n,id:t,offset:a,length:r,data:i}){let s=l.getIntentStoragePda(this._intentsProgram.programId,t);return [await this._intentsProgram.methods.updateIntent(i?{instruction:[i]}:{buffer:{offset:a,length:r}}).accountsStrict({rentPayer:e,state:this._state,intentStorage:s,systemProgram:web3_js.SystemProgram.programId,buffer:n??null}).instruction()]}closeRecordIxs({record:e,authority:n,receiver:t}){return t||(t=n),[splRecord.createCloseAccountInstruction(e,n,t,this.recordProgramId)]}writeRecordIxs({authority:e,record:n,buffer:t,offset:a}){return [splRecord.createWriteInstruction(n,e,BigInt(a),t,this.recordProgramId)]}async reallocRecordIxs({authority:e,payer:n,record:t,buffer:a,offset:r}){n||(n=e);let i=await this._provider.connection.getAccountInfo(t);if(!i)throw new Error("Record account not found");let s=i.lamports,o=i.data.length,d=r+a.length,u=[];if(d>o){let c=await this._provider.connection.getMinimumBalanceForRentExemption(d+1)-s,p=web3_js.SystemProgram.transfer({fromPubkey:n,toPubkey:t,lamports:c});u.push(p);let f=splRecord.createReallocateInstruction(t,e,BigInt(d-T),this.recordProgramId);u.push(f);}return u}async initIntentTxs({authority:e,payer:n,intent:t,signature:a,blockhash:r,ALTs:i,computeBudget:s}){n||(n=e);let o,d=web3_js.Keypair.generate(),u=t.data,m=T+u.length,c=await this._provider.connection.getMinimumBalanceForRentExemption(m+1),p=w(s);a?o=await this.initIntentUsingSigIxs(e,n,t.id,u.length,t.inputTokensLength,a):o=await this.initIntentIxs(e,n,t.id,u.length,t.inputTokensLength);let f=web3_js.SystemProgram.createAccount({fromPubkey:n,newAccountPubkey:d.publicKey,lamports:c,space:m,programId:this.recordProgramId}),g=splRecord.createInitializeInstruction(d.publicKey,e,this.recordProgramId),y=I({instructions:[...p,...o,f,g],payer:n,blockhash:r,ALTs:i});return y.sign([d]),{record:d.publicKey,txs:[y]}}async writeIntentTxs({authority:e,payer:n,record:t,intent:a,blockhash:r,ALTs:i,computeBudget:s}){n||(n=e);let o=[],d=a.data,u=d.length,m=w(s),c=this.closeRecordIxs({record:t,authority:e,receiver:n}),p=I({instructions:[...m,...await this.updateIntentIxs({payer:n,id:a.id,data:d}),...c],payer:n,blockhash:r,ALTs:i}),f=solanaUtils.txs.getTransactionSize(p);if(f&&f<=solanaUtils.constants.MAX_TX_SIZE)return [p];let g=0,y=[];for(;g<u;){let b,x=[...m],B=1,G=u-g,W=[],D=0;for(;B<=G;){let U=Math.floor((B+G)/2),j=d.subarray(g,g+U);b=this.writeRecordIxs({authority:e,record:t,buffer:j,offset:g});let q=I({instructions:[...x,...b],payer:n,blockhash:r,ALTs:i}),V=solanaUtils.txs.getTransactionSize(q);V&&V<=solanaUtils.constants.MAX_TX_SIZE?(W=b,D=U,B=U+1):G=U-1;}x.push(...W),y=x;let Z=I({instructions:x,payer:n,blockhash:r,ALTs:i});o.push(Z),g+=D;}let S=[...await this.updateIntentIxs({record:t,payer:n,id:a.id,offset:T,length:u}),...c],E=[...y,...S],R=I({instructions:E,payer:n,blockhash:r,ALTs:i}),P=solanaUtils.txs.getTransactionSize(R);if(P&&P<=solanaUtils.constants.MAX_TX_SIZE)o[o.length-1]=R;else {let b=I({instructions:S,payer:n,blockhash:r,ALTs:i});o.push(b);}return o}async createIntentTxs({authority:e,payer:n,intent:t,signature:a,blockhash:r,ALTs:i,computeBudget:s}){let{record:o,txs:d}=await this.initIntentTxs({authority:e,payer:n,intent:t,signature:a,blockhash:r,ALTs:i,computeBudget:s}),u=await this.writeIntentTxs({authority:e,payer:n,record:o,intent:t,blockhash:r,ALTs:i,computeBudget:s});return {init:d,write:u,record:o}}async createAndUpdateIntentTxs({authority:e,payer:n,intent:t,signature:a,blockhash:r,ALTs:i,computeBudget:s}){n||(n=e);let o,d,u=w(s);a?o=await this.initIntentUsingSigIxs(e,n,t.id,t.data?t.data.length:t.length,t.inputTokensLength,a):o=await this.initIntentIxs(e,n,t.id,t.data?t.data.length:t.length,t.inputTokensLength),t.data?d=await this.updateIntentIxs({payer:n,id:t.id,data:t.data}):d=await this.updateIntentIxs({payer:n,record:t.record,id:t.id,offset:T+t.offset,length:t.length});let m=I({instructions:[...u,...o,...d],payer:n,blockhash:r,ALTs:i}),c=solanaUtils.txs.getTransactionSize(m);if(c&&c>solanaUtils.constants.MAX_TX_SIZE)throw new Error(`Tx size is ${c}, should be less than ${solanaUtils.constants.MAX_TX_SIZE}`);return [m]}async updateRecordTxs({authority:e,payer:n,record:t,serializedIntent:a,offset:r=T,blockhash:i,ALTs:s,computeBudget:o}){if(n||(n=e),r<T)throw new Error(`Offset can't be less than ${T}`);let d=[],u=a.length,m=await this.reallocRecordIxs({authority:e,payer:n,record:t,buffer:a,offset:r}),c=w(o),p=0;for(;p<u;){let f,g=[...c,...p===0?m:[]],y=1,v=u-p,S=[],E=0;for(;y<=v;){let P=Math.floor((y+v)/2),b=a.subarray(p,p+P);f=this.writeRecordIxs({authority:e,record:t,buffer:b,offset:p});let x=I({instructions:[...g,...f],payer:n,blockhash:i,ALTs:s}),B=solanaUtils.txs.getTransactionSize(x);B&&B<=solanaUtils.constants.MAX_TX_SIZE?(S=f,E=P,y=P+1):v=P-1;}g.push(...S);let R=I({instructions:g,payer:n,blockhash:i,ALTs:s});d.push(R),p+=E;}return d}async closeIntentTxs({authority:e,payer:n,record:t,receiver:a,id:r,blockhash:i,ALTs:s,computeBudget:o}){n||(n=e);let d=w(o),u=await this.closeIntentIxs(e,a??e,r);if(d.push(...u),t){let c=this.closeRecordIxs({record:t,authority:e,receiver:a});d.push(...c);}return [I({instructions:d,payer:n,blockhash:i,ALTs:s})]}async swapTxs({taker:e,maker:n,intentId:t,inputMint:a,outputMint:r,amount:i,target:s,inputTokenProgram:o=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:d=splToken.TOKEN_PROGRAM_ID,instructions:u=[],computeBudget:m,payer:c,blockhash:p,ALTs:f}){c||(c=e);let g=w(m),y=await this.swapBeginIxs({taker:e,maker:n,intentId:t,inputMint:a,outputMint:r,amount:i,target:s,inputTokenProgram:o,outputTokenProgram:d}),v=await this.swapEndIxs({taker:e,intentId:t,outputMint:r,outputTokenProgram:d});return [I({instructions:[...g,...y,...u,...v],payer:c,blockhash:p,ALTs:f})]}static getStatePda(e){let[n]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("state")],e);return n}static getIntentStoragePda(e,n){let[t]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("intent_storage"),n],e);return t}static getMakerInfoPda(e,n){let[t]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("maker_info"),n.toBuffer()],e);return t}static getDelegatesPda(e,n){let[t]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("user_delegates"),n.toBuffer()],e);return t}};var M=class{addresses;lookupMap=new Map;constructor(e){this.addresses=e.map(n=>Buffer.from(n));}lookupIndex(e){let n=e.toString("hex"),t=this.lookupMap.get(n);if(t===void 0)throw new Error(`Address ${n} not found in AddressesList`);return t}serialize(){let e=new Map;for(let s of this.addresses){let o=e.get(s.length);o===void 0?e.set(s.length,[s]):o.push(s);}let n=Array.from(e.keys()).sort(),t=Buffer.alloc(n.reduce((s,o)=>s+e.get(o).length*o,0)+n.length*2+1);t[0]=n.length;let a=1,r=1+n.length*2,i=0;for(let s of n){let o=e.get(s).sort((u,m)=>u.compare(m));for(let u of o)this.lookupMap.set(u.toString("hex"),i),i+=1;t[a]=s,a+=1,t[a]=o.length,a+=1;let d=Buffer.concat(o);t.set(d,r),r+=d.length;}return t}};var J=class{data;addressesList;serializedList;constructor(e){this.data=e,this.addressesList=this.buildAddressesListFromIntent(e),this.serializedList=this.addressesList.serialize();}buildAddressesListFromIntent(e){let n=new Set,t=s=>n.add(s.toString("hex")),a=s=>{if(s)for(let{address:o}of s)t(o);},r=s=>{if(s)for(let o of s)t(o.inputAddress),t(o.outputAddress);};for(let s of e.inputTokens)t(s.address);r(e.giveTokens),r(e.takeTokens),a(e.receiverDetails),a(e.dstAuthorityAddress);let i=Array.from(n).map(s=>Buffer.from(s,"hex"));return new M(i)}serializeReceiversInfo(e){if(!e||e.length===0)return Buffer.from([0]);let n=e.map(({chainIds:t,address:a})=>{let r;if(t==="any")r=Buffer.alloc(2),r.writeUInt8(this.addressesList.lookupIndex(a),0),r.writeUInt8(0,1);else {r=Buffer.alloc(3+t.length*4),r.writeUInt8(this.addressesList.lookupIndex(a),0),r.writeUInt8(1,1),r.writeUInt8(t.length,2);for(let[i,s]of t.entries())r.writeUInt32LE(s,3+i*4);}return r});return Buffer.concat([Buffer.from([n.length]),...n])}serializeInputTokens(){let e=this.data.inputTokens.map(n=>{let t=Buffer.alloc(25);return t[0]=this.addressesList.lookupIndex(n.address),t.writeBigUInt64LE(n.minPartialAmount,1),t.writeBigUInt64LE(n.maxPartialAmount,9),t.writeBigUInt64LE(n.budget,17),t});return Buffer.concat([Buffer.from([e.length]),...e])}serializeTokenInfo(e){if(!e||e.length===0)return Buffer.from([0]);let n=e.map(t=>{let a=Buffer.alloc(18);return a.writeUInt8(this.addressesList.lookupIndex(t.inputAddress),0),a.writeUInt8(this.addressesList.lookupIndex(t.outputAddress),1),a.writeBigInt64LE(t.price,2),a});return Buffer.concat([Buffer.from([e.length]),...n])}serializeTakeTokenInfo(e){if(!e||e.length===0)return Buffer.from([0]);let n=e.map(t=>{let a=Buffer.alloc(22);return a.writeUInt8(this.addressesList.lookupIndex(t.inputAddress),0),a.writeUInt8(t.outputTokenChainId,1),a.writeUInt8(this.addressesList.lookupIndex(t.outputAddress),5),a.writeBigInt64LE(t.price,6),a});return Buffer.concat([Buffer.from([e.length]),...n])}serializeOptionalBytes(e){return e?Buffer.concat([Buffer.from([1]),e]):Buffer.from([0])}serializeShortArray(e){if(!e)return Buffer.from([0]);let n=Buffer.alloc(2);return n.writeInt16LE(e.length,0),Buffer.concat([Buffer.from([1]),n,e])}serializeAddresses(e){return !e||e.length===0?Buffer.from([0]):Buffer.concat([Buffer.from([e.length]),...e])}serializeOptionalPubkey(e){return e?Buffer.concat([Buffer.from([1]),e.toBuffer()]):Buffer.from([0])}serialize(){let e=[],n=Buffer.alloc(4);n.writeUInt32LE(this.data.chainId,0),e.push(n),e.push(this.data.owner.toBuffer()),this.data.authority?e.push(this.data.authority.toBuffer()):e.push(this.data.owner.toBuffer());let t=Buffer.alloc(16);return t.writeBigUInt64LE(BigInt(this.data.timestamp),0),t.writeBigUInt64LE(BigInt(this.data.expirationTimestamp),8),e.push(t),e.push(this.serializedList),e.push(this.serializeInputTokens()),e.push(this.serializeTokenInfo(this.data.giveTokens)),e.push(this.serializeTakeTokenInfo(this.data.takeTokens)),e.push(this.serializeReceiversInfo(this.data.receiverDetails)),e.push(this.serializeAddresses(this.data.allowedSenders)),e.push(this.serializeOptionalPubkey(this.data.preInteractions)),e.push(this.serializeOptionalPubkey(this.data.postInteractions)),e.push(this.serializeShortArray(this.data.validationRules)),e.push(this.serializeOptionalBytes(this.data.executionMetadataHash)),e.push(this.serializeAddresses(this.data.srcAllowedCancelBeneficiary)),e.push(this.serializeReceiversInfo(this.data.dstAuthorityAddress)),this.data.externalCallHash==="any"?e.push(Buffer.from([1]),Buffer.from([0])):this.data.externalCallHash?e.push(Buffer.from([1]),this.serializeOptionalBytes(this.data.externalCallHash)):e.push(Buffer.from([0])),this.data.dlnMetadata==="any"?e.push(Buffer.from([1]),Buffer.from([0])):this.data.dlnMetadata?e.push(Buffer.from([1]),this.serializeShortArray(this.data.dlnMetadata)):e.push(Buffer.from([0])),Buffer.concat(e)}getId(){let e=jsSha3.keccak256(this.serialize());return {hex:`0x${e}`,buffer:Buffer.from(e,"hex")}}static getId(e){let n=jsSha3.keccak256(e);return {hex:`0x${n}`,buffer:Buffer.from(n,"hex")}}static getTextToSign(e){return e.getId().hex}};exports.DEFAULT_RECORD_OFFSET=T;exports.Intent=J;exports.IntentsClient=F;//# sourceMappingURL=index.js.map
1
+ 'use strict';var anchor=require('@coral-xyz/anchor'),solanaUtils=require('@debridge-finance/solana-utils'),web3_js=require('@solana/web3.js'),splToken=require('@solana/spl-token'),splRecord=require('@solana/spl-record'),jsSha3=require('js-sha3');var K={address:"intueneJjzHttKp83gWH3GX1h1Uwuixuusj4T8vGDzk",metadata:{name:"intentsProgram",version:"0.0.0",spec:"0.1.0",description:"deBridge Intents Program"},instructions:[{name:"approveProtocolTransfers",discriminator:[17,3,184,144,112,130,116,98],accounts:[{name:"owner",signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"tokenProgram"}],args:[{name:"amounts",type:{vec:"u64"}}]},{name:"authorizedTransfer",discriminator:[136,178,202,213,255,92,81,119],accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"from"},{name:"to"},{name:"mint"},{name:"tokenProgram"}],args:[{name:"amount",type:"u64"}]},{name:"closeAccount",discriminator:[125,255,149,14,110,34,72,24],accounts:[{name:"programAuthority",signer:true,address:"intueneJjzHttKp83gWH3GX1h1Uwuixuusj4T8vGDzk"},{name:"target",writable:true},{name:"rentReceiver",writable:true}],args:[]},{name:"closeIntent",discriminator:[112,245,154,249,57,126,54,122],accounts:[{name:"initiator",writable:true,signer:true},{name:"rentPayer",writable:true},{name:"intentStorage",writable:true},{name:"state"},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[]},{name:"collectFee",discriminator:[60,173,247,103,4,93,130,48],accounts:[{name:"feeCollector",signer:true,relations:["state"]},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"feeLedger",writable:true,pda:{seeds:[{kind:"account",path:"state"},{kind:"account",path:"tokenProgram"},{kind:"account",path:"mint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"destination",writable:true},{name:"mint"},{name:"tokenProgram"}],args:[{name:"amount",type:"u64"}]},{name:"executeIntent",discriminator:[53,130,47,154,227,220,122,212],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"maker"},{name:"makerGiveToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"const",value:[6,221,246,225,215,101,161,147,217,203,225,70,206,235,121,172,28,180,133,237,95,91,55,145,58,140,245,133,126,255,0,169]},{kind:"account",path:"tokenMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"dlnSrc",address:"srch38nzfcgwJnfKE6xWD8vfNJtudazwisdcociAuQt"},{name:"dlnSrcState"},{name:"dlnSrcGiveOrderState",writable:true},{name:"dlnSrcGiveOrderWallet",writable:true},{name:"dlnSrcAuthorizedNativeSender"},{name:"dlnSrcFeeLedgerWallet",writable:true},{name:"tokenMint"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[{name:"dlnOrderArgs",type:"bytes"},{name:"dlnOrderNonce",type:"u64"}]},{name:"initIntent",discriminator:[231,255,81,23,112,148,49,134],accounts:[{name:"maker",signer:true},{name:"rentPayer",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"space",type:"u32"}]},{name:"initIntentUsingSig",discriminator:[163,186,238,179,190,181,19,185],accounts:[{name:"rentPayer",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"space",type:"u32"},{name:"maker",type:"pubkey"},{name:"signature",type:{array:["u8",64]}}]},{name:"initState",discriminator:[124,213,73,136,80,37,141,54],accounts:[{name:"protocolAuthority",signer:true},{name:"programAuthority",signer:true,address:"intueneJjzHttKp83gWH3GX1h1Uwuixuusj4T8vGDzk"},{name:"rentPayer",writable:true,signer:true},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[]},{name:"reallocState",discriminator:[67,181,233,214,215,148,245,126],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]},{name:"rentPayer",writable:true,signer:true},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"newSpace",type:"u32"}]},{name:"setDefaultFee",discriminator:[150,137,197,111,176,227,201,110],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"defaultFeeBps",type:"u16"}]},{name:"setDelegateApprovedBudgets",discriminator:[82,182,181,250,30,186,95,15],accounts:[{name:"maker",signer:true},{name:"rentPayer",writable:true,signer:true},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"state"},{name:"systemProgram",address:"11111111111111111111111111111111"}],args:[{name:"delegate",type:"pubkey"},{name:"nonce",type:"u64"},{name:"args",type:{defined:{name:"setApprovedTokenBudgets"}}}]},{name:"setFeeCollector",discriminator:[143,46,10,113,121,157,245,166],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"feeCollector",type:"pubkey"}]},{name:"setLastValidTimestamp",discriminator:[70,101,113,35,233,224,156,184],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"lastValidTimestamp",type:"u64"}]},{name:"setPause",discriminator:[63,32,154,2,56,103,79,45],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]}],args:[{name:"pauseFlag",type:"bool"}]},{name:"setProtocolAuthority",discriminator:[96,162,46,152,72,147,175,176],accounts:[{name:"inner",accounts:[{name:"protocolAuthority",signer:true,relations:["state"]},{name:"state",writable:true,pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}}]},{name:"newProtocolAuthority",signer:true}],args:[]},{name:"swapBegin",discriminator:[87,236,193,120,215,245,9,37],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"feeLedger",writable:true,pda:{seeds:[{kind:"account",path:"state"},{kind:"account",path:"inputTokenProgram"},{kind:"account",path:"inputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"intentStorage",writable:true},{name:"inputMint"},{name:"outputMint"},{name:"makerInputToken",writable:true},{name:"takerInputToken",writable:true,pda:{seeds:[{kind:"account",path:"taker"},{kind:"account",path:"inputTokenProgram"},{kind:"account",path:"inputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"takerOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"taker"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"intentOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"instructions",address:"Sysvar1nstructions1111111111111111111111111"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"inputTokenProgram"},{name:"outputTokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[{name:"amount",type:"u64"},{name:"target",type:{defined:{name:"targetTokenAccount"}}}]},{name:"swapEnd",discriminator:[75,178,142,132,50,126,38,31],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"intentStorage",writable:true},{name:"outputMint"},{name:"takerOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"taker"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"intentOutputToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"outputTokenProgram"},{kind:"account",path:"outputMint"}],program:{kind:"const",value:[140,151,37,143,78,36,137,241,187,61,16,41,20,142,13,131,11,90,19,153,218,255,16,132,4,142,123,216,219,233,248,89]}}},{name:"instructions",address:"Sysvar1nstructions1111111111111111111111111"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"outputTokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[]},{name:"updateIntent",discriminator:[214,203,249,158,90,27,54,17],accounts:[{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"buffer",optional:true}],args:[{name:"dataOrigin",type:{defined:{name:"dataOrigin"}}}]}],accounts:[{name:"intentStorage",discriminator:[175,239,93,146,246,119,144,249]},{name:"makerInfo",discriminator:[164,184,52,218,144,52,100,40]},{name:"state",discriminator:[216,146,107,94,104,75,182,177]}],errors:[{code:6e3,name:"protocolIsOnPause",msg:"Protocol is on pause"},{code:6001,name:"unknownCaller",msg:"Unknown caller"},{code:6002,name:"sigVerifyErr",msg:"Ed25519 signature is invalid or does not match provided intent hash and public key"},{code:6003,name:"intentStorageIsInitialized",msg:"Intent storage is already initialized"},{code:6004,name:"intentStorageIsSealed",msg:"Intent encoded data already matches expected hash"},{code:6005,name:"intentHashMismatch",msg:"Intent ..."},{code:6006,name:"intentIsInvalidatedByUser"},{code:6007,name:"intentIsInvalidatedByProtocolAuthority"},{code:6008,name:"intentIsExpired"},{code:6009,name:"intentIsNotReadyYet",msg:"Intent is not ready for execution yet"},{code:6010,name:"unknownInputToken"},{code:6011,name:"insufficientInputTokenAmount"},{code:6012,name:"intentArbitraryDataOverflow"},{code:6013,name:"takerIsNotAllowed"},{code:6014,name:"delegateNonceIsAdvanced"}],types:[{name:"approvedTokenBudget",type:{kind:"struct",fields:[{name:"tokenMint",type:"pubkey"},{name:"approvedAmount",type:"u64"},{name:"expiration",type:"u64"}]}},{name:"currentTokenBudget",type:{kind:"struct",fields:[{name:"tokenMint",type:"pubkey"},{name:"approvedAmount",type:"u64"},{name:"expiration",type:"u64"},{name:"remainingAmount",type:"u64"}]}},{name:"dataOrigin",type:{kind:"enum",variants:[{name:"instruction",fields:["bytes"]},{name:"buffer",fields:[{name:"offset",type:"u32"},{name:"length",type:"u32"}]}]}},{name:"delegateBudgets",type:{kind:"enum",variants:[{name:"perToken",fields:[{vec:{defined:{name:"currentTokenBudget"}}}]},{name:"any"},{name:"revoked"}]}},{name:"delegateInfo",type:{kind:"struct",fields:[{name:"delegate",type:"pubkey"},{name:"nonce",type:"u64"},{name:"budgets",type:{defined:{name:"delegateBudgets"}}}]}},{name:"intentBudget",type:{kind:"struct",fields:[{name:"mintIndex",type:"u8"},{name:"remainingAmount",type:"u64"}]}},{name:"intentBudgets",type:{kind:"struct",fields:[{vec:{defined:{name:"intentBudget"}}}]}},{name:"intentId",type:{kind:"struct",fields:[{array:["u8",32]}]}},{name:"intentStorage",type:{kind:"struct",fields:[{name:"maker",type:"pubkey"},{name:"rentPayer",type:"pubkey"},{name:"arbitraryData",type:{array:["u8",100]}},{name:"intentId",type:{defined:{name:"intentId"}}},{name:"version",type:"u8"},{name:"storedIntent",type:{defined:{name:"storedIntent"}}},{name:"bump",type:"u8"}]}},{name:"makerInfo",type:{kind:"struct",fields:[{name:"lastValidTimestamp",type:"u64"},{name:"delegates",type:{vec:{defined:{name:"delegateInfo"}}}}]}},{name:"setApprovedTokenBudgets",type:{kind:"enum",variants:[{name:"set",fields:[{vec:{defined:{name:"approvedTokenBudget"}}}]},{name:"setAny"},{name:"revoke"}]}},{name:"state",type:{kind:"struct",fields:[{name:"protocolAuthority",type:"pubkey"},{name:"feeCollector",type:"pubkey"},{name:"defaultFeeBps",type:"u16"},{name:"isPaused",type:"bool"},{name:"lastValidTimestamp",type:"u64"},{name:"bump",type:"u8"}]}},{name:"storedIntent",type:{kind:"enum",variants:[{name:"uninitialized"},{name:"inProgress",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]},{name:"closed",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]},{name:"terminated"}]}},{name:"targetTokenAccount",type:{kind:"enum",variants:[{name:"taker"},{name:"intent"}]}}],constants:[{name:"intentStorageBaseSeed",type:"bytes",value:"[105, 110, 116, 101, 110, 116, 95, 115, 116, 111, 114, 97, 103, 101]"},{name:"makerInfoSeed",type:"bytes",value:"[109, 97, 107, 101, 114, 95, 105, 110, 102, 111]"},{name:"stateSeed",type:"bytes",value:"[115, 116, 97, 116, 101]"}]};var w=l=>{let e=[];return l?.limit&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({units:l.limit})),l?.price&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({microLamports:l.price})),e},y=({instructions:l,payer:e,blockhash:t,ALTs:n})=>new web3_js.VersionedTransaction(web3_js.MessageV0.compile({instructions:l,payerKey:e,recentBlockhash:t,addressLookupTableAccounts:n}));var S=splRecord.RECORD_META_DATA_SIZE,F=class l{programId;recordProgramId;_provider;_intentsProgram;_state;constructor(e,{programId:t,recordProgramId:n=splRecord.RECORD_PROGRAM_ID}){K.address=t.toString(),this.programId=t,this.recordProgramId=n,this._provider=new anchor.AnchorProvider(e,{},{}),anchor.setProvider(this._provider),this._intentsProgram=new anchor.Program(K,this._provider),this._state=l.getStatePda(this._intentsProgram.programId);}getSpace(e,t){return 198+(1+e+(4+9*t))}async getState(e){let t=await e.getAccountInfo(this._state);if(!t)return null;let n=this._intentsProgram.coder.accounts.decode("state",t.data);return {...n,lastValidTimestamp:Number(n.lastValidTimestamp.toString())}}async getIntentStorage(e,t){let n=l.getIntentStoragePda(this._intentsProgram.programId,t),a=await e.getAccountInfo(n);if(!a)return null;let r=this._intentsProgram.coder.accounts.decode("intentStorage",a.data);return {...r,intentId:Buffer.from(r.intentId[0])}}async approveProtocolTransfersIxs({owner:e,tokens:t,tokenProgram:n=splToken.TOKEN_PROGRAM_ID}){let{amounts:a,accounts:r}=t.reduce(({amounts:i,accounts:s},{mint:o,amount:d})=>({amounts:i.concat(new anchor.BN(d.toString())),accounts:s.concat({pubkey:splToken.getAssociatedTokenAddressSync(o,e,true,n),isSigner:false,isWritable:true})}),{amounts:[],accounts:[]});return [await this._intentsProgram.methods.approveProtocolTransfers(a).accountsStrict({owner:e,state:this._state,tokenProgram:n}).remainingAccounts(r).instruction()]}async closeIntentIxs(e,t,n){return [await this._intentsProgram.methods.closeIntent().accountsStrict({initiator:e,rentPayer:t,intentStorage:l.getIntentStoragePda(this._intentsProgram.programId,n),state:this._state,systemProgram:web3_js.SystemProgram.programId}).instruction()]}async executeIntentIxs({intentId:e,taker:t,maker:n,tokenMint:a,order:r,dlnSrc:i=new web3_js.PublicKey(solanaUtils.programs.dlnSrc),tokenProgram:s=splToken.TOKEN_PROGRAM_ID}){let o=solanaUtils.dlnSrcResolver(i).methods,[d]=o.getStateAccount(),[u]=o.getGiveOrderStateAccount(r.id),[m]=o.getGiveOrderWalletAddress(r.id),[c]=o.getAuthorizedNativeSenderAddress(Buffer.from(new anchor.BN(r.dstChainId.toString()).toArray("be",32))),[p]=o.getFeeLedgerWalletAddress(a),f=l.getIntentStoragePda(this._intentsProgram.programId,e),g=splToken.getAssociatedTokenAddressSync(a,f,true,s);return [await this._intentsProgram.methods.executeIntent(r.args,new anchor.BN(r.nonce.toString())).accountsStrict({taker:t,state:this._state,intentStorage:f,maker:n,makerGiveToken:g,dlnSrc:i,dlnSrcState:d,dlnSrcGiveOrderState:u,dlnSrcGiveOrderWallet:m,dlnSrcAuthorizedNativeSender:c,dlnSrcFeeLedgerWallet:p,tokenMint:a,systemProgram:web3_js.SystemProgram.programId,tokenProgram:s,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID}).instruction()]}async initIntentIxs(e,t,n,a,r){let i=this.getSpace(a,r);return [await this._intentsProgram.methods.initIntent({0:Array.from(n)},i).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:l.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async initIntentUsingSigIxs(e,t,n,a,r,i){let s=this.getSpace(a,r);return [await this._intentsProgram.methods.initIntentUsingSig({0:Array.from(n)},s,e,Array.from(i)).accountsStrict({rentPayer:t,state:this._state,intentStorage:l.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async setDelegateApprovedBudgetsIxs({maker:e,payer:t,delegate:n,nonce:a,tokens:r}){let i;return "set"in r?i={set:r.set.map(({tokenMint:s,approvedAmount:o,expiration:d})=>({tokenMint:s,approvedAmount:new anchor.BN(o.toString()),expiration:new anchor.BN(d.toString())}))}:"setAny"in r?i={setAny:{}}:i={revoke:{}},[await this._intentsProgram.methods.setDelegateApprovedBudgets(n,new anchor.BN(a.toString()),i).accountsStrict({maker:e,rentPayer:t,state:this._state,makerInfo:l.getMakerInfoPda(this._intentsProgram.programId,e),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async swapBeginIxs({taker:e,maker:t,intentId:n,amount:a,target:r,inputMint:i,outputMint:s,inputTokenProgram:o=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:d=splToken.TOKEN_PROGRAM_ID}){let u=l.getIntentStoragePda(this._intentsProgram.programId,n),m=splToken.getAssociatedTokenAddressSync(i,this._state,true,o),c=splToken.getAssociatedTokenAddressSync(i,t,true,o),p=splToken.getAssociatedTokenAddressSync(i,e,true,o),f=splToken.getAssociatedTokenAddressSync(s,e,true,d),g=splToken.getAssociatedTokenAddressSync(s,u,true,d);return [await this._intentsProgram.methods.swapBegin(new anchor.BN(a.toString()),r==="intent"?{intent:{}}:{taker:{}}).accountsStrict({taker:e,state:this._state,feeLedger:m,intentStorage:u,inputMint:i,outputMint:s,makerInputToken:c,takerInputToken:p,takerOutputToken:f,intentOutputToken:g,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,inputTokenProgram:o,outputTokenProgram:d,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID}).instruction()]}async swapEndIxs({taker:e,intentId:t,outputMint:n,outputTokenProgram:a=splToken.TOKEN_PROGRAM_ID}){let r=l.getIntentStoragePda(this._intentsProgram.programId,t),i=splToken.getAssociatedTokenAddressSync(n,e,true,a),s=splToken.getAssociatedTokenAddressSync(n,r,true,a);return [await this._intentsProgram.methods.swapEnd().accountsStrict({taker:e,state:this._state,intentStorage:r,outputMint:n,takerOutputToken:i,intentOutputToken:s,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,outputTokenProgram:a,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID}).instruction()]}async updateIntentIxs({payer:e,record:t,id:n,offset:a,length:r,data:i}){let s=l.getIntentStoragePda(this._intentsProgram.programId,n);return [await this._intentsProgram.methods.updateIntent(i?{instruction:[i]}:{buffer:{offset:a,length:r}}).accountsStrict({rentPayer:e,state:this._state,intentStorage:s,systemProgram:web3_js.SystemProgram.programId,buffer:t??null}).instruction()]}closeRecordIxs({record:e,authority:t,receiver:n}){return n||(n=t),[splRecord.createCloseAccountInstruction(e,t,n,this.recordProgramId)]}writeRecordIxs({authority:e,record:t,buffer:n,offset:a}){return [splRecord.createWriteInstruction(t,e,BigInt(a),n,this.recordProgramId)]}async reallocRecordIxs({authority:e,payer:t,record:n,buffer:a,offset:r}){t||(t=e);let i=await this._provider.connection.getAccountInfo(n);if(!i)throw new Error("Record account not found");let s=i.lamports,o=i.data.length,d=r+a.length,u=[];if(d>o){let c=await this._provider.connection.getMinimumBalanceForRentExemption(d+1)-s,p=web3_js.SystemProgram.transfer({fromPubkey:t,toPubkey:n,lamports:c});u.push(p);let f=splRecord.createReallocateInstruction(n,e,BigInt(d-S),this.recordProgramId);u.push(f);}return u}async initIntentTxs({authority:e,payer:t,intent:n,signature:a,blockhash:r,ALTs:i,computeBudget:s}){t||(t=e);let o,d=web3_js.Keypair.generate(),u=n.data,m=S+u.length,c=await this._provider.connection.getMinimumBalanceForRentExemption(m+1),p=w(s);a?o=await this.initIntentUsingSigIxs(e,t,n.id,u.length,n.inputTokensLength,a):o=await this.initIntentIxs(e,t,n.id,u.length,n.inputTokensLength);let f=web3_js.SystemProgram.createAccount({fromPubkey:t,newAccountPubkey:d.publicKey,lamports:c,space:m,programId:this.recordProgramId}),g=splRecord.createInitializeInstruction(d.publicKey,t,this.recordProgramId),I=y({instructions:[...p,...o,f,g],payer:t,blockhash:r,ALTs:i});return I.sign([d]),{record:d.publicKey,txs:[I]}}async writeIntentTxs({authority:e,payer:t,record:n,intent:a,blockhash:r,ALTs:i,computeBudget:s}){t||(t=e);let o=[],d=a.data,u=d.length,m=w(s),c=this.closeRecordIxs({record:n,authority:t,receiver:t}),p=y({instructions:[...m,...await this.updateIntentIxs({payer:t,id:a.id,data:d}),...c],payer:t,blockhash:r,ALTs:i}),f=solanaUtils.txs.getTransactionSize(p);if(f&&f<=solanaUtils.constants.MAX_TX_SIZE)return [p];let g=0,I=[];for(;g<u;){let b,B=[...m],z=1,G=u-g,W=[],D=0;for(;z<=G;){let U=Math.floor((z+G)/2),j=d.subarray(g,g+U);b=this.writeRecordIxs({authority:t,record:n,buffer:j,offset:g});let q=y({instructions:[...B,...b],payer:t,blockhash:r,ALTs:i}),V=solanaUtils.txs.getTransactionSize(q);V&&V<=solanaUtils.constants.MAX_TX_SIZE?(W=b,D=U,z=U+1):G=U-1;}B.push(...W),I=B;let Z=y({instructions:B,payer:t,blockhash:r,ALTs:i});o.push(Z),g+=D;}let A=[...await this.updateIntentIxs({record:n,payer:t,id:a.id,offset:S,length:u}),...c],E=[...I,...A],R=y({instructions:E,payer:t,blockhash:r,ALTs:i}),P=solanaUtils.txs.getTransactionSize(R);if(P&&P<=solanaUtils.constants.MAX_TX_SIZE)o[o.length-1]=R;else {let b=y({instructions:A,payer:t,blockhash:r,ALTs:i});o.push(b);}return o}async createIntentTxs({authority:e,payer:t,intent:n,signature:a,blockhash:r,ALTs:i,computeBudget:s}){let{record:o,txs:d}=await this.initIntentTxs({authority:e,payer:t,intent:n,signature:a,blockhash:r,ALTs:i,computeBudget:s}),u=await this.writeIntentTxs({authority:e,payer:t,record:o,intent:n,blockhash:r,ALTs:i,computeBudget:s});return {init:d,write:u}}async createAndUpdateIntentTxs({authority:e,payer:t,intent:n,signature:a,blockhash:r,ALTs:i,computeBudget:s}){t||(t=e);let o,d,u=w(s);a?o=await this.initIntentUsingSigIxs(e,t,n.id,n.data?n.data.length:n.length,n.inputTokensLength,a):o=await this.initIntentIxs(e,t,n.id,n.data?n.data.length:n.length,n.inputTokensLength),n.data?d=await this.updateIntentIxs({payer:t,id:n.id,data:n.data}):d=await this.updateIntentIxs({payer:t,record:n.record,id:n.id,offset:S+n.offset,length:n.length});let m=y({instructions:[...u,...o,...d],payer:t,blockhash:r,ALTs:i}),c=solanaUtils.txs.getTransactionSize(m);if(c&&c>solanaUtils.constants.MAX_TX_SIZE)throw new Error(`Tx size is ${c}, should be less than ${solanaUtils.constants.MAX_TX_SIZE}`);return [m]}async updateRecordTxs({authority:e,payer:t,record:n,serializedIntent:a,offset:r=S,blockhash:i,ALTs:s,computeBudget:o}){if(t||(t=e),r<S)throw new Error(`Offset can't be less than ${S}`);let d=[],u=a.length,m=await this.reallocRecordIxs({authority:e,payer:t,record:n,buffer:a,offset:r}),c=w(o),p=0;for(;p<u;){let f,g=[...c,...p===0?m:[]],I=1,x=u-p,A=[],E=0;for(;I<=x;){let P=Math.floor((I+x)/2),b=a.subarray(p,p+P);f=this.writeRecordIxs({authority:t,record:n,buffer:b,offset:p});let B=y({instructions:[...g,...f],payer:t,blockhash:i,ALTs:s}),z=solanaUtils.txs.getTransactionSize(B);z&&z<=solanaUtils.constants.MAX_TX_SIZE?(A=f,E=P,I=P+1):x=P-1;}g.push(...A);let R=y({instructions:g,payer:t,blockhash:i,ALTs:s});d.push(R),p+=E;}return d}async closeIntentTxs({authority:e,payer:t,record:n,receiver:a,id:r,blockhash:i,ALTs:s,computeBudget:o}){t||(t=e);let d=w(o),u=await this.closeIntentIxs(e,a??e,r);if(d.push(...u),n){let c=this.closeRecordIxs({record:n,authority:t,receiver:a});d.push(...c);}return [y({instructions:d,payer:t,blockhash:i,ALTs:s})]}async swapTxs({taker:e,maker:t,intentId:n,inputMint:a,outputMint:r,amount:i,target:s,inputTokenProgram:o=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:d=splToken.TOKEN_PROGRAM_ID,instructions:u=[],computeBudget:m,payer:c,blockhash:p,ALTs:f}){c||(c=e);let g=w(m),I=await this.swapBeginIxs({taker:e,maker:t,intentId:n,inputMint:a,outputMint:r,amount:i,target:s,inputTokenProgram:o,outputTokenProgram:d}),x=await this.swapEndIxs({taker:e,intentId:n,outputMint:r,outputTokenProgram:d});return [y({instructions:[...g,...I,...u,...x],payer:c,blockhash:p,ALTs:f})]}static getStatePda(e){let[t]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("state")],e);return t}static getIntentStoragePda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("intent_storage"),t],e);return n}static getMakerInfoPda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("maker_info"),t.toBuffer()],e);return n}static getDelegatesPda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("user_delegates"),t.toBuffer()],e);return n}};var M=class{addresses;lookupMap=new Map;constructor(e){this.addresses=e.map(t=>Buffer.from(t));}lookupIndex(e){let t=e.toString("hex"),n=this.lookupMap.get(t);if(n===void 0)throw new Error(`Address ${t} not found in AddressesList`);return n}serialize(){let e=new Map;for(let s of this.addresses){let o=e.get(s.length);o===void 0?e.set(s.length,[s]):o.push(s);}let t=Array.from(e.keys()).sort(),n=Buffer.alloc(t.reduce((s,o)=>s+e.get(o).length*o,0)+t.length*2+1);n[0]=t.length;let a=1,r=1+t.length*2,i=0;for(let s of t){let o=e.get(s).sort((u,m)=>u.compare(m));for(let u of o)this.lookupMap.set(u.toString("hex"),i),i+=1;n[a]=s,a+=1,n[a]=o.length,a+=1;let d=Buffer.concat(o);n.set(d,r),r+=d.length;}return n}};var J=class{data;addressesList;serializedList;constructor(e){this.data=e,this.addressesList=this.buildAddressesListFromIntent(e),this.serializedList=this.addressesList.serialize();}buildAddressesListFromIntent(e){let t=new Set,n=s=>t.add(s.toString("hex")),a=s=>{if(s)for(let{address:o}of s)n(o);},r=s=>{if(s)for(let o of s)n(o.inputAddress),n(o.outputAddress);};for(let s of e.inputTokens)n(s.address);r(e.giveTokens),r(e.takeTokens),a(e.receiverDetails),a(e.dstAuthorityAddress);let i=Array.from(t).map(s=>Buffer.from(s,"hex"));return new M(i)}serializeReceiversInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(({chainIds:n,address:a})=>{let r;if(n==="any")r=Buffer.alloc(2),r.writeUInt8(this.addressesList.lookupIndex(a),0),r.writeUInt8(0,1);else {r=Buffer.alloc(3+n.length*4),r.writeUInt8(this.addressesList.lookupIndex(a),0),r.writeUInt8(1,1),r.writeUInt8(n.length,2);for(let[i,s]of n.entries())r.writeUInt32LE(s,3+i*4);}return r});return Buffer.concat([Buffer.from([t.length]),...t])}serializeInputTokens(){let e=this.data.inputTokens.map(t=>{let n=Buffer.alloc(25);return n[0]=this.addressesList.lookupIndex(t.address),n.writeBigUInt64LE(t.minPartialAmount,1),n.writeBigUInt64LE(t.maxPartialAmount,9),n.writeBigUInt64LE(t.budget,17),n});return Buffer.concat([Buffer.from([e.length]),...e])}serializeTokenInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(n=>{let a=Buffer.alloc(18);return a.writeUInt8(this.addressesList.lookupIndex(n.inputAddress),0),a.writeUInt8(this.addressesList.lookupIndex(n.outputAddress),1),a.writeBigInt64LE(n.price,2),a});return Buffer.concat([Buffer.from([e.length]),...t])}serializeTakeTokenInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(n=>{let a=Buffer.alloc(22);return a.writeUInt8(this.addressesList.lookupIndex(n.inputAddress),0),a.writeUInt8(n.outputTokenChainId,1),a.writeUInt8(this.addressesList.lookupIndex(n.outputAddress),5),a.writeBigInt64LE(n.price,6),a});return Buffer.concat([Buffer.from([e.length]),...t])}serializeOptionalBytes(e){return e?Buffer.concat([Buffer.from([1]),e]):Buffer.from([0])}serializeShortArray(e){if(!e)return Buffer.from([0]);let t=Buffer.alloc(2);return t.writeInt16LE(e.length,0),Buffer.concat([Buffer.from([1]),t,e])}serializeAddresses(e){return !e||e.length===0?Buffer.from([0]):Buffer.concat([Buffer.from([e.length]),...e])}serializeOptionalPubkey(e){return e?Buffer.concat([Buffer.from([1]),e.toBuffer()]):Buffer.from([0])}serialize(){let e=[],t=Buffer.alloc(4);t.writeUInt32LE(this.data.chainId,0),e.push(t),e.push(this.data.owner.toBuffer()),this.data.authority?e.push(this.data.authority.toBuffer()):e.push(this.data.owner.toBuffer());let n=Buffer.alloc(16);return n.writeBigUInt64LE(BigInt(this.data.timestamp),0),n.writeBigUInt64LE(BigInt(this.data.expirationTimestamp),8),e.push(n),e.push(this.serializedList),e.push(this.serializeInputTokens()),e.push(this.serializeTokenInfo(this.data.giveTokens)),e.push(this.serializeTakeTokenInfo(this.data.takeTokens)),e.push(this.serializeReceiversInfo(this.data.receiverDetails)),e.push(this.serializeAddresses(this.data.allowedSenders)),e.push(this.serializeOptionalPubkey(this.data.preInteractions)),e.push(this.serializeOptionalPubkey(this.data.postInteractions)),e.push(this.serializeShortArray(this.data.validationRules)),e.push(this.serializeOptionalBytes(this.data.executionMetadataHash)),e.push(this.serializeAddresses(this.data.srcAllowedCancelBeneficiary)),e.push(this.serializeReceiversInfo(this.data.dstAuthorityAddress)),this.data.externalCallHash==="any"?e.push(Buffer.from([1]),Buffer.from([0])):this.data.externalCallHash?e.push(Buffer.from([1]),this.serializeOptionalBytes(this.data.externalCallHash)):e.push(Buffer.from([0])),this.data.dlnMetadata==="any"?e.push(Buffer.from([1]),Buffer.from([0])):this.data.dlnMetadata?e.push(Buffer.from([1]),this.serializeShortArray(this.data.dlnMetadata)):e.push(Buffer.from([0])),Buffer.concat(e)}getId(){let e=jsSha3.keccak256(this.serialize());return {hex:`0x${e}`,buffer:Buffer.from(e,"hex")}}static getId(e){let t=jsSha3.keccak256(e);return {hex:`0x${t}`,buffer:Buffer.from(t,"hex")}}static getTextToSign(e){return e.getId().hex}};exports.DEFAULT_RECORD_OFFSET=S;exports.Intent=J;exports.IntentsClient=F;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map