@debridge-finance/intents-client 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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'),buffer=require('buffer'),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:"maker"},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"intentStorage",writable:true},{name:"intentGiveToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"tokenProgram"},{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"},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"dlnOrderArgs",type:{defined:{name:"createOrderArgs"}}},{name:"dlnOrderNonce",type:"u64"},{name:"tradeId",type:{array:["u8",32]}}]},{name:"executeIntent2",discriminator:[57,145,38,151,5,101,106,72],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"maker"},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"intentStorage",writable:true},{name:"intentTakeToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"tokenProgram"},{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:"feeLedger",writable:true,pda:{seeds:[{kind:"account",path:"state"},{kind:"account",path:"tokenProgram"},{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:"receiver"},{name:"receiverTakeToken",writable:true,pda:{seeds:[{kind:"account",path:"receiver"},{kind:"account",path:"tokenProgram"},{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:"tokenMint"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"amount",type:"u64"},{name:"tradeId",type:{array:["u8",32]}}]},{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]}]}}]},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"defaultFeeBps",type:"u32"}]},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],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:"maker"},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"amount",type:"u64"},{name:"expectedCreditedAccount",type:{defined:{name:"targetTokenAccount"}}},{name:"tradeId",type:{array:["u8",32]}}]},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"expectedOutcomeAmount",type:"u64"},{name:"takerSurplusShareBps",type:"u32"}]},{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]}],events:[{name:"fulfilled",discriminator:[210,174,131,213,40,182,83,110]},{name:"fulfilledDln",discriminator:[42,231,52,35,155,251,144,108]},{name:"intentBudgetSpent",discriminator:[106,148,20,168,115,89,145,56]},{name:"swapped",discriminator:[217,52,52,83,147,135,96,109]}],errors:[{code:6e3,name:"protocolIsOnPause",msg:"Protocol is on pause"},{code:6001,name:"timeParadox",msg:"Time Paradox"},{code:6002,name:"unknownCaller",msg:"Unknown caller"},{code:6003,name:"sigVerifyErr",msg:"Ed25519 signature is invalid or does not match provided intent hash and public key"},{code:6004,name:"intentStorageIsInitialized",msg:"Intent storage is already initialized"},{code:6005,name:"intentStorageIsSealed",msg:"Intent encoded data already matches expected hash"},{code:6006,name:"intentHashMismatch"},{code:6007,name:"intentOwnerMismatchActualMaker"},{code:6008,name:"intentIsInvalidatedByUser"},{code:6009,name:"intentIsInvalidatedByProtocolAuthority"},{code:6010,name:"intentIsExpired"},{code:6011,name:"intentIsNotReadyYet",msg:"Intent is not ready for execution yet"},{code:6012,name:"unknownInputToken"},{code:6013,name:"insufficientInputTokenAmount"},{code:6014,name:"intentArbitraryDataOverflow"},{code:6015,name:"takerIsNotAllowed"},{code:6016,name:"takerMustBeFixedWhenAnyExtcallIsAllowed"},{code:6017,name:"ambiguousReceivers"},{code:6018,name:"interactionAccountNotFound"},{code:6019,name:"interactionProgramNotFound"},{code:6020,name:"interactionFixedAccountNotFound"},{code:6021,name:"delegateNonceIsAdvanced"},{code:6022,name:"crossProgramInvokeIsRestricted"},{code:6023,name:"invalidDlnOrderTargetTokenOrPrice"}],types:[{name:"address",type:{kind:"type",alias:{vec:"u8"}}},{name:"approvedTokenBudget",type:{kind:"struct",fields:[{name:"tokenMint",type:"pubkey"},{name:"approvedAmount",type:"u64"},{name:"expiration",type:"u64"}]}},{name:"createOrderArgs",docs:["Structure for forming a new order"],type:{kind:"struct",fields:[{name:"giveOriginalAmount",docs:["Input amount for `create order` call, that will be transferred from the user's wallet.","The dln commissions will be deducted from it and the resulting value will be used as [`Order::give.amount`]"],type:"u64"},{name:"take",docs:["Offer to take in destination chain"],type:{defined:{name:"offer"}}},{name:"receiverDst",docs:["Address in dst chain","Address of receiver_dst of tokens in target chain","or","address of external call executor if `external_call` presented"],type:{defined:{name:"address"}}},{name:"extcall",docs:["External call for automatically execution in target chain after execution of order"],type:{option:"bytes"}},{name:"givePatchAuthoritySrc",docs:["Address in source chain","Can call `patch_order_give` method of src program"],type:"pubkey"},{name:"allowedCancelBeneficiarySrc",docs:["Address in source chain","If the field is `Some`, then only this address can receive cancel"],type:{option:"pubkey"}},{name:"orderAuthorityAddressDst",docs:["Address in destination chain","Can `send_order_cancel`, `process_fallback` and `patch_order_take`"],type:{defined:{name:"address"}}},{name:"allowedTakerDst",docs:["Address in destination chain","If the field is `Some`, then only this address can call `fulfill_order` with this","order"],type:{option:{defined:{name:"address"}}}}]}},{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:"fulfilled",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"takeToken",type:"pubkey"},{name:"takeTokenAmount",type:"u64"},{name:"takeTokenFeeAmount",type:"u64"}]}},{name:"fulfilledDln",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"orderId",type:{defined:{name:"u256"}}},{name:"giveToken",type:"pubkey"},{name:"giveTokenAmount",type:"pubkey"},{name:"giveTokenFeeAmount",type:"pubkey"},{name:"takeToken",type:{defined:{name:"address"}}},{name:"takeTokenAmount",type:{defined:{name:"u256"}}},{name:"takeTokenRecipient",type:{defined:{name:"address"}}}]}},{name:"intentBudget",type:{kind:"struct",fields:[{name:"mintIndex",type:"u8"},{name:"remainingAmount",type:"u64"}]}},{name:"intentBudgetSpent",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"inputToken",type:"pubkey"},{name:"inputTokenSpentAmount",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:"offer",type:{kind:"struct",fields:[{name:"chainId",type:{defined:{name:"u256"}}},{name:"tokenAddress",type:{defined:{name:"address"}}},{name:"amount",type:{defined:{name:"u256"}}}]}},{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:"u32"},{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:"swapped",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"inputToken",type:"pubkey"},{name:"inputTokenAmount",type:"u64"},{name:"outputToken",type:"pubkey"},{name:"outputTokenAmount",type:"u64"},{name:"takerOutputTokenShareAmount",type:"u64"}]}},{name:"targetTokenAccount",type:{kind:"enum",variants:[{name:"taker"},{name:"intent"}]}},{name:"u256",type:{kind:"type",alias:{array:["u8",32]}}}],constants:[{name:"intentStorageBaseSeed",type:"bytes",value:"[105, 110, 116, 101, 110, 116, 95, 115, 116, 111, 114, 97, 103, 101]"},{name:"interactionCallAuthority",type:"bytes",value:"[105, 110, 116, 101, 114, 97, 99, 116, 105, 111, 110, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121]"},{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]"}]};function W(m,e){let t;switch(e){case "u256":t=32;break;case "u64":t=8;break}return new anchor.BN(m.toString()).toArray("be",t)}var S=m=>{let e=[];return m?.limit&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({units:m.limit})),m?.price&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({microLamports:m.price})),e},k=({instructions:m,payer:e,blockhash:t,ALTs:n})=>new web3_js.VersionedTransaction(web3_js.MessageV0.compile({instructions:m,payerKey:e,recentBlockhash:t,addressLookupTableAccounts:n}));var B=splRecord.RECORD_META_DATA_SIZE,Z=class m{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=m.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=m.getIntentStoragePda(this._intentsProgram.programId,t),r=await e.getAccountInfo(n);if(!r)return null;let s=this._intentsProgram.coder.accounts.decode("intentStorage",r.data);return {...s,intentId:buffer.Buffer.from(s.intentId[0])}}async approveProtocolTransfersIxs({owner:e,tokens:t,tokenProgram:n=splToken.TOKEN_PROGRAM_ID}){let{amounts:r,accounts:s}=t.reduce(({amounts:a,accounts:i},{mint:o,amount:d})=>({amounts:a.concat(new anchor.BN(d.toString())),accounts:i.concat({pubkey:splToken.getAssociatedTokenAddressSync(o,e,true,n),isSigner:false,isWritable:true})}),{amounts:[],accounts:[]});return [await this._intentsProgram.methods.approveProtocolTransfers(r).accountsStrict({owner:e,state:this._state,tokenProgram:n}).remainingAccounts(s).instruction()]}async closeIntentIxs(e,t,n){return [await this._intentsProgram.methods.closeIntent().accountsStrict({initiator:e,rentPayer:t,intentStorage:m.getIntentStoragePda(this._intentsProgram.programId,n),state:this._state,systemProgram:web3_js.SystemProgram.programId}).instruction()]}async executeIntentIxs({tradeId:e,intentId:t,taker:n,maker:r,tokenMint:s,dlnOrder:a,dlnSrc:i=new web3_js.PublicKey(solanaUtils.programs.dlnSrc),tokenProgram:o=splToken.TOKEN_PROGRAM_ID}){let d=solanaUtils.dlnSrcResolver(i).methods,[u]=d.getStateAccount(),[c]=d.getGiveOrderStateAccount(a.id),[p]=d.getGiveOrderWalletAddress(a.id),[g]=d.getAuthorizedNativeSenderAddress(buffer.Buffer.from(new anchor.BN(a.dstChainId.toString()).toArray("be",32))),[f]=d.getFeeLedgerWalletAddress(s),l=m.getIntentStoragePda(this._intentsProgram.programId,t),y=splToken.getAssociatedTokenAddressSync(s,l,true,o),b={giveOriginalAmount:new anchor.BN(a.args.giveOriginalAmount.toString()),take:{amount:W(a.args.take.amount,"u256"),chainId:W(a.args.take.chainId,"u256"),tokenAddress:Array.from(a.args.take.tokenAddress)},receiverDst:Array.from(a.args.receiver),extcall:a.args.externalCall?.externalCallData?buffer.Buffer.from(a.args.externalCall.externalCallData):null,givePatchAuthoritySrc:a.args.givePatchAuthority,orderAuthorityAddressDst:Array.from(a.args.orderAuthorityDstAddress),allowedCancelBeneficiarySrc:a.args.allowedCancelBeneficiary,allowedTakerDst:a.args.allowedTaker?Array.from(a.args.allowedTaker):null};return [await this._intentsProgram.methods.executeIntent(b,new anchor.BN(a.nonce.toString()),Array.from(e)).accountsStrict({taker:n,state:this._state,intentStorage:l,maker:r,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,r),intentGiveToken:y,dlnSrc:i,dlnSrcState:u,dlnSrcGiveOrderState:c,dlnSrcGiveOrderWallet:p,dlnSrcAuthorizedNativeSender:g,dlnSrcFeeLedgerWallet:f,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:o,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async executeSameChainIntentIxs({tradeId:e,intentId:t,taker:n,maker:r,tokenMint:s,receiver:a,amount:i,tokenProgram:o=splToken.TOKEN_PROGRAM_ID}){let d=m.getIntentStoragePda(this._intentsProgram.programId,t),u=splToken.getAssociatedTokenAddressSync(s,d,true,o),c=splToken.getAssociatedTokenAddressSync(s,a,true,o),p=splToken.getAssociatedTokenAddressSync(s,this._state,true,o);return [await this._intentsProgram.methods.executeIntent2(new anchor.BN(i.toString()),Array.from(e)).accountsStrict({taker:n,state:this._state,maker:r,receiver:a,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,r),intentStorage:d,intentTakeToken:u,feeLedger:p,receiverTakeToken:c,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:o,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async initIntentIxs(e,t,n,r,s){let a=this.getSpace(r,s);return [await this._intentsProgram.methods.initIntent({0:Array.from(n)},a).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:m.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async initIntentUsingSigIxs(e,t,n,r,s,a){let i=this.getSpace(r,s);return [await this._intentsProgram.methods.initIntentUsingSig({0:Array.from(n)},i,e,Array.from(a)).accountsStrict({rentPayer:t,state:this._state,intentStorage:m.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async setDelegateApprovedBudgetsIxs({maker:e,payer:t,delegate:n,nonce:r,tokens:s}){let a;return "set"in s?a={set:s.set.map(({tokenMint:i,approvedAmount:o,expiration:d})=>({tokenMint:i,approvedAmount:new anchor.BN(o.toString()),expiration:new anchor.BN(d.toString())}))}:"setAny"in s?a={setAny:{}}:a={revoke:{}},[await this._intentsProgram.methods.setDelegateApprovedBudgets(n,new anchor.BN(r.toString()),a).accountsStrict({maker:e,rentPayer:t,state:this._state,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,e),systemProgram:web3_js.SystemProgram.programId,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:r,beginAmount:s,target:a,inputMint:i,outputMint:o,inputTokenProgram:d=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:u=splToken.TOKEN_PROGRAM_ID}){let c=m.getIntentStoragePda(this._intentsProgram.programId,n),p=splToken.getAssociatedTokenAddressSync(i,t,true,d),g=splToken.getAssociatedTokenAddressSync(i,e,true,d),f=splToken.getAssociatedTokenAddressSync(o,e,true,u),l=splToken.getAssociatedTokenAddressSync(o,c,true,u);return [await this._intentsProgram.methods.swapBegin(new anchor.BN(s.toString()),a==="intent"?{intent:{}}:{taker:{}},Array.from(r)).accountsStrict({taker:e,maker:t,state:this._state,intentStorage:c,inputMint:i,outputMint:o,makerInputToken:p,takerInputToken:g,takerOutputToken:f,intentOutputToken:l,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,inputTokenProgram:d,outputTokenProgram:u,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,t),eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async swapEndIxs({taker:e,intentId:t,endAmount:n,bps:r,outputMint:s,outputTokenProgram:a=splToken.TOKEN_PROGRAM_ID}){let i=m.getIntentStoragePda(this._intentsProgram.programId,t),o=splToken.getAssociatedTokenAddressSync(s,e,true,a),d=splToken.getAssociatedTokenAddressSync(s,i,true,a);return [await this._intentsProgram.methods.swapEnd(new anchor.BN(n.toString()),r).accountsStrict({taker:e,state:this._state,intentStorage:i,outputMint:s,takerOutputToken:o,intentOutputToken:d,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,outputTokenProgram:a,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async updateIntentIxs({payer:e,record:t,id:n,offset:r,length:s,data:a}){let i=m.getIntentStoragePda(this._intentsProgram.programId,n);return [await this._intentsProgram.methods.updateIntent(a?{instruction:[a]}:{buffer:{offset:r,length:s}}).accountsStrict({rentPayer:e,state:this._state,intentStorage:i,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:r}){return [splRecord.createWriteInstruction(t,e,BigInt(r),n,this.recordProgramId)]}async reallocRecordIxs({authority:e,payer:t,record:n,buffer:r,offset:s}){t||(t=e);let a=await this._provider.connection.getAccountInfo(n);if(!a)throw new Error("Record account not found");let i=a.lamports,o=a.data.length,d=s+r.length,u=[];if(d>o){let p=await this._provider.connection.getMinimumBalanceForRentExemption(d+1)-i,g=web3_js.SystemProgram.transfer({fromPubkey:t,toPubkey:n,lamports:p});u.push(g);let f=splRecord.createReallocateInstruction(n,e,BigInt(d-B),this.recordProgramId);u.push(f);}return u}async initIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:i}){t||(t=e);let o,d=web3_js.Keypair.generate(),u=n.data,c=B+u.length,p=await this._provider.connection.getMinimumBalanceForRentExemption(c+1),g=S(i);r?o=await this.initIntentUsingSigIxs(e,t,n.id,u.length,n.inputTokensLength,r):o=await this.initIntentIxs(e,t,n.id,u.length,n.inputTokensLength);let f=web3_js.SystemProgram.createAccount({fromPubkey:t,newAccountPubkey:d.publicKey,lamports:p,space:c,programId:this.recordProgramId}),l=splRecord.createInitializeInstruction(d.publicKey,t,this.recordProgramId),y=k({instructions:[...g,...o,f,l],payer:t,blockhash:s,ALTs:a});return {record:d,txs:[y]}}async writeIntentTxs({authority:e,payer:t,record:n,intent:r,blockhash:s,ALTs:a,computeBudget:i}){t||(t=e);let o=[],d=r.data,u=d.length,c=S(i),p=this.closeRecordIxs({record:n,authority:t,receiver:t}),g=k({instructions:[...c,...await this.updateIntentIxs({payer:t,id:r.id,data:d}),...p],payer:t,blockhash:s,ALTs:a}),f=solanaUtils.txs.getTransactionSize(g);if(f&&f<=solanaUtils.constants.MAX_TX_SIZE)return [g];let l=0,y=[];for(;l<u;){let x,L=[...c],M=1,D=u-l,F=[],V=0;for(;M<=D;){let G=Math.floor((M+D)/2),$=d.subarray(l,l+G);x=this.writeRecordIxs({authority:t,record:n,buffer:$,offset:l});let Y=k({instructions:[...L,...x],payer:t,blockhash:s,ALTs:a}),N=solanaUtils.txs.getTransactionSize(Y);N&&N<=solanaUtils.constants.MAX_TX_SIZE?(F=x,V=G,M=G+1):D=G-1;}L.push(...F),y=L;let q=k({instructions:L,payer:t,blockhash:s,ALTs:a});o.push(q),l+=V;}let A=[...await this.updateIntentIxs({record:n,payer:t,id:r.id,offset:B,length:u}),...p],_=[...y,...A],z=k({instructions:_,payer:t,blockhash:s,ALTs:a}),v=solanaUtils.txs.getTransactionSize(z);if(v&&v<=solanaUtils.constants.MAX_TX_SIZE)o[o.length-1]=z;else {let x=k({instructions:A,payer:t,blockhash:s,ALTs:a});o.push(x);}return o}async createIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:i}){let{record:o,txs:d}=await this.initIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:i}),u=await this.writeIntentTxs({authority:e,payer:t,record:o.publicKey,intent:n,blockhash:s,ALTs:a,computeBudget:i});return {init:d,write:u,record:o}}async createAndUpdateIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:i}){t||(t=e);let o,d,u=S(i);r?o=await this.initIntentUsingSigIxs(e,t,n.id,n.data?n.data.length:n.length,n.inputTokensLength,r):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:B+n.offset,length:n.length});let c=k({instructions:[...u,...o,...d],payer:t,blockhash:s,ALTs:a}),p=solanaUtils.txs.getTransactionSize(c);if(p&&p>solanaUtils.constants.MAX_TX_SIZE)throw new Error(`Tx size is ${p}, should be less than ${solanaUtils.constants.MAX_TX_SIZE}`);return [c]}async updateRecordTxs({authority:e,payer:t,record:n,serializedIntent:r,offset:s=B,blockhash:a,ALTs:i,computeBudget:o}){if(t||(t=e),s<B)throw new Error(`Offset can't be less than ${B}`);let d=[],u=r.length,c=await this.reallocRecordIxs({authority:e,payer:t,record:n,buffer:r,offset:s}),p=S(o),g=0;for(;g<u;){let f,l=[...p,...g===0?c:[]],y=1,b=u-g,A=[],_=0;for(;y<=b;){let v=Math.floor((y+b)/2),x=r.subarray(g,g+v);f=this.writeRecordIxs({authority:t,record:n,buffer:x,offset:g});let L=k({instructions:[...l,...f],payer:t,blockhash:a,ALTs:i}),M=solanaUtils.txs.getTransactionSize(L);M&&M<=solanaUtils.constants.MAX_TX_SIZE?(A=f,_=v,y=v+1):b=v-1;}l.push(...A);let z=k({instructions:l,payer:t,blockhash:a,ALTs:i});d.push(z),g+=_;}return d}async closeIntentTxs({authority:e,payer:t,record:n,receiver:r,id:s,blockhash:a,ALTs:i,computeBudget:o}){t||(t=e);let d=S(o),u=await this.closeIntentIxs(e,r??e,s);if(d.push(...u),n){let p=this.closeRecordIxs({record:n,authority:t,receiver:r});d.push(...p);}return [k({instructions:d,payer:t,blockhash:a,ALTs:i})]}async swapTxs({taker:e,maker:t,intentId:n,tradeId:r,inputMint:s,outputMint:a,beginAmount:i,endAmount:o,bps:d,target:u,inputTokenProgram:c=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:p=splToken.TOKEN_PROGRAM_ID,instructions:g=[],computeBudget:f,payer:l,blockhash:y,ALTs:b}){l||(l=e);let A=S(f),_=await this.swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:r,inputMint:s,outputMint:a,beginAmount:i,target:u,inputTokenProgram:c,outputTokenProgram:p}),z=await this.swapEndIxs({taker:e,intentId:n,endAmount:o,bps:d,outputMint:a,outputTokenProgram:p});return [k({instructions:[...A,..._,...g,...z],payer:l,blockhash:y,ALTs:b})]}static getStatePda(e){let[t]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("state")],e);return t}static getIntentStoragePda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("intent_storage"),t],e);return n}static getMakerInfoPda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("maker_info"),t.toBuffer()],e);return n}static getDelegatesPda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("user_delegates"),t.toBuffer()],e);return n}static getEventAuthorityPda(e){let[t]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("__event_authority")],e);return t}};var C=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 i of this.addresses){let o=e.get(i.length);o===void 0?e.set(i.length,[i]):o.push(i);}let t=Array.from(e.keys()).sort(),n=Buffer.alloc(t.reduce((i,o)=>i+e.get(o).length*o,0)+t.length*2+1);n[0]=t.length;let r=1,s=1+t.length*2,a=0;for(let i of t){let o=e.get(i).sort((u,c)=>u.compare(c));for(let u of o)this.lookupMap.set(u.toString("hex"),a),a+=1;n[r]=i,r+=1,n[r]=o.length,r+=1;let d=Buffer.concat(o);n.set(d,s),s+=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=o=>t.add(o.toString("hex")),r=o=>{if(o)for(let{address:d}of o)n(d);},s=o=>{if(o)for(let d of o)d.input!=="any"&&n(d.input),n(d.output);},a=o=>{if(o){for(let d of o)if(n(d.input),d.output!=="any")for(let u of d.output)u.token&&u.token!=="any"&&n(u.token);}};for(let o of e.inputTokens)n(o.token);s(e.giveTokens),a(e.takeTokens),r(e.receiverDetails),r(e.dstAuthorityAddress);let i=Array.from(t).map(o=>Buffer.from(o,"hex"));return new C(i)}serializeReceiversInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(({chainIds:n,address:r})=>{let s;if(n==="any")s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(r),0),s.writeUInt8(0,1);else {s=Buffer.alloc(3+n.length*4),s.writeUInt8(this.addressesList.lookupIndex(r),0),s.writeUInt8(1,1),s.writeUInt8(n.length,2);for(let[a,i]of n.entries())s.writeUInt32LE(i,3+a*4);}return s});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.token),n.writeBigUInt64LE(t.minPartialAmount,1),n.writeBigUInt64LE(t.maxPartialAmount,9),n.writeBigUInt64LE(t.constraintBudget,17),n});return Buffer.concat([Buffer.from([e.length]),...e])}serializeGiveTokens(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(n=>{let r;return n.input==="any"?(r=Buffer.alloc(2),r.writeUInt8(this.addressesList.lookupIndex(n.output),0),r.writeUInt8(0,1)):(r=Buffer.alloc(19),r.writeUInt8(this.addressesList.lookupIndex(n.output),0),r.writeUInt8(1,1),r.writeUInt8(this.addressesList.lookupIndex(n.input),2),r.writeBigInt64LE(n.price,3)),r});return Buffer.concat([Buffer.from([e.length]),...t])}serializeTakeTokens(e){let t=0,n=e.map(r=>{let s;return r.output==="any"?(t=1,s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(r.input),0),s.writeUInt8(0,1)):(t+=r.output.length,s=Buffer.concat(r.output.map(a=>{if(a.chainId==="any"){let i=Buffer.alloc(2);return i.writeUInt8(this.addressesList.lookupIndex(r.input),0),i.writeUInt8(0,1),i}if(a.token==="any"){let i=Buffer.alloc(6);return i.writeUInt8(1,0),i.writeUInt8(a.chainId,1),i.writeUInt8(0,5),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(r.input)]),i])}else {let i=Buffer.alloc(24);return i.writeUInt8(1,0),i.writeUInt32LE(a.chainId,1),i.writeUInt8(1,5),i.writeUInt8(this.addressesList.lookupIndex(a.token),6),i.writeUInt8(1,7),i.writeBigInt64LE(a.price,8),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(r.input)]),i])}}))),s});return Buffer.concat([Buffer.from([t]),...n])}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(Buffer.from([0]));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.serializeGiveTokens(this.data.giveTokens)),e.push(this.serializeTakeTokens(this.data.takeTokens)),e.push(this.serializeReceiversInfo(this.data.receiverDetails)),this.data.allowedSenders==="any"?e.push(Buffer.from([1]),Buffer.from([0])):e.push(Buffer.from([1]),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=B;exports.Intent=j;exports.IntentsClient=Z;//# 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'),buffer=require('buffer'),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:"maker"},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"intentStorage",writable:true},{name:"intentGiveToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"tokenProgram"},{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"},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"dlnOrderArgs",type:{defined:{name:"createOrderArgs"}}},{name:"dlnOrderNonce",type:"u64"},{name:"tradeId",type:{array:["u8",32]}}]},{name:"executeIntent2",discriminator:[57,145,38,151,5,101,106,72],accounts:[{name:"taker",writable:true,signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"maker"},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"intentStorage",writable:true},{name:"intentTakeToken",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{kind:"account",path:"tokenProgram"},{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:"feeLedger",writable:true,pda:{seeds:[{kind:"account",path:"state"},{kind:"account",path:"tokenProgram"},{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:"receiver"},{name:"receiverTakeToken",writable:true,pda:{seeds:[{kind:"account",path:"receiver"},{kind:"account",path:"tokenProgram"},{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:"tokenMint"},{name:"systemProgram",address:"11111111111111111111111111111111"},{name:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"amount",type:"u64"},{name:"tradeId",type:{array:["u8",32]}}]},{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]}]}}]},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"defaultFeeBps",type:"u32"}]},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],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:"maker"},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"amount",type:"u64"},{name:"expectedCreditedAccount",type:{defined:{name:"targetTokenAccount"}}},{name:"tradeId",type:{array:["u8",32]}}]},{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"},{name:"eventAuthority",pda:{seeds:[{kind:"const",value:[95,95,101,118,101,110,116,95,97,117,116,104,111,114,105,116,121]}]}},{name:"program"}],args:[{name:"expectedOutcomeAmount",type:"u64"},{name:"takerSurplusShareBps",type:"u32"}]},{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]}],events:[{name:"fulfilled",discriminator:[210,174,131,213,40,182,83,110]},{name:"fulfilledDln",discriminator:[42,231,52,35,155,251,144,108]},{name:"intentBudgetSpent",discriminator:[106,148,20,168,115,89,145,56]},{name:"swapped",discriminator:[217,52,52,83,147,135,96,109]}],errors:[{code:6e3,name:"protocolIsOnPause",msg:"Protocol is on pause"},{code:6001,name:"timeParadox",msg:"Time Paradox"},{code:6002,name:"unknownCaller",msg:"Unknown caller"},{code:6003,name:"sigVerifyErr",msg:"Ed25519 signature is invalid or does not match provided intent hash and public key"},{code:6004,name:"intentStorageIsInitialized",msg:"Intent storage is already initialized"},{code:6005,name:"intentStorageIsSealed",msg:"Intent encoded data already matches expected hash"},{code:6006,name:"intentHashMismatch"},{code:6007,name:"intentOwnerMismatchActualMaker"},{code:6008,name:"intentIsInvalidatedByUser"},{code:6009,name:"intentIsInvalidatedByProtocolAuthority"},{code:6010,name:"intentIsExpired"},{code:6011,name:"intentIsNotReadyYet",msg:"Intent is not ready for execution yet"},{code:6012,name:"unknownInputToken"},{code:6013,name:"insufficientInputTokenAmount"},{code:6014,name:"intentArbitraryDataOverflow"},{code:6015,name:"takerIsNotAllowed"},{code:6016,name:"takerMustBeFixedWhenAnyExtcallIsAllowed"},{code:6017,name:"ambiguousReceivers"},{code:6018,name:"interactionAccountNotFound"},{code:6019,name:"interactionProgramNotFound"},{code:6020,name:"interactionFixedAccountNotFound"},{code:6021,name:"delegateNonceIsAdvanced"},{code:6022,name:"crossProgramInvokeIsRestricted"},{code:6023,name:"invalidDlnOrderTargetTokenOrPrice"}],types:[{name:"address",type:{kind:"type",alias:{vec:"u8"}}},{name:"approvedTokenBudget",type:{kind:"struct",fields:[{name:"tokenMint",type:"pubkey"},{name:"approvedAmount",type:"u64"},{name:"expiration",type:"u64"}]}},{name:"createOrderArgs",docs:["Structure for forming a new order"],type:{kind:"struct",fields:[{name:"giveOriginalAmount",docs:["Input amount for `create order` call, that will be transferred from the user's wallet.","The dln commissions will be deducted from it and the resulting value will be used as [`Order::give.amount`]"],type:"u64"},{name:"take",docs:["Offer to take in destination chain"],type:{defined:{name:"offer"}}},{name:"receiverDst",docs:["Address in dst chain","Address of receiver_dst of tokens in target chain","or","address of external call executor if `external_call` presented"],type:{defined:{name:"address"}}},{name:"extcall",docs:["External call for automatically execution in target chain after execution of order"],type:{option:"bytes"}},{name:"givePatchAuthoritySrc",docs:["Address in source chain","Can call `patch_order_give` method of src program"],type:"pubkey"},{name:"allowedCancelBeneficiarySrc",docs:["Address in source chain","If the field is `Some`, then only this address can receive cancel"],type:{option:"pubkey"}},{name:"orderAuthorityAddressDst",docs:["Address in destination chain","Can `send_order_cancel`, `process_fallback` and `patch_order_take`"],type:{defined:{name:"address"}}},{name:"allowedTakerDst",docs:["Address in destination chain","If the field is `Some`, then only this address can call `fulfill_order` with this","order"],type:{option:{defined:{name:"address"}}}}]}},{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:"fulfilled",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"takeToken",type:"pubkey"},{name:"takeTokenAmount",type:"u64"},{name:"takeTokenFeeAmount",type:"u64"}]}},{name:"fulfilledDln",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"orderId",type:{defined:{name:"u256"}}},{name:"giveToken",type:"pubkey"},{name:"giveTokenAmount",type:"pubkey"},{name:"giveTokenFeeAmount",type:"pubkey"},{name:"takeToken",type:{defined:{name:"address"}}},{name:"takeTokenAmount",type:{defined:{name:"u256"}}},{name:"takeTokenRecipient",type:{defined:{name:"address"}}}]}},{name:"intentBudget",type:{kind:"struct",fields:[{name:"mintIndex",type:"u8"},{name:"remainingAmount",type:"u64"}]}},{name:"intentBudgetSpent",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"inputToken",type:"pubkey"},{name:"inputTokenSpentAmount",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:"offer",type:{kind:"struct",fields:[{name:"chainId",type:{defined:{name:"u256"}}},{name:"tokenAddress",type:{defined:{name:"address"}}},{name:"amount",type:{defined:{name:"u256"}}}]}},{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:"u32"},{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:"swapped",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"tradeId",type:{array:["u8",32]}},{name:"executionMetadata",type:{option:"bytes"}},{name:"inputToken",type:"pubkey"},{name:"inputTokenAmount",type:"u64"},{name:"outputToken",type:"pubkey"},{name:"outputTokenAmount",type:"u64"},{name:"takerOutputTokenShareAmount",type:"u64"}]}},{name:"targetTokenAccount",type:{kind:"enum",variants:[{name:"taker"},{name:"intent"}]}},{name:"u256",type:{kind:"type",alias:{array:["u8",32]}}}],constants:[{name:"intentStorageBaseSeed",type:"bytes",value:"[105, 110, 116, 101, 110, 116, 95, 115, 116, 111, 114, 97, 103, 101]"},{name:"interactionCallAuthority",type:"bytes",value:"[105, 110, 116, 101, 114, 97, 99, 116, 105, 111, 110, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121]"},{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]"}]};function W(m,e){let t;switch(e){case "u256":t=32;break;case "u64":t=8;break}return new anchor.BN(m.toString()).toArray("be",t)}var S=m=>{let e=[];return m?.limit&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({units:m.limit})),m?.price&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({microLamports:m.price})),e},k=({instructions:m,payer:e,blockhash:t,ALTs:n})=>new web3_js.VersionedTransaction(web3_js.MessageV0.compile({instructions:m,payerKey:e,recentBlockhash:t,addressLookupTableAccounts:n}));var B=splRecord.RECORD_META_DATA_SIZE,Z=class m{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=m.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=m.getIntentStoragePda(this._intentsProgram.programId,t),r=await e.getAccountInfo(n);if(!r)return null;let s=this._intentsProgram.coder.accounts.decode("intentStorage",r.data);return {...s,intentId:buffer.Buffer.from(s.intentId[0])}}async approveProtocolTransfersIxs({owner:e,tokens:t,tokenProgram:n=splToken.TOKEN_PROGRAM_ID}){let{amounts:r,accounts:s}=t.reduce(({amounts:a,accounts:o},{mint:i,amount:d})=>({amounts:a.concat(new anchor.BN(d.toString())),accounts:o.concat({pubkey:splToken.getAssociatedTokenAddressSync(i,e,true,n),isSigner:false,isWritable:true})}),{amounts:[],accounts:[]});return [await this._intentsProgram.methods.approveProtocolTransfers(r).accountsStrict({owner:e,state:this._state,tokenProgram:n}).remainingAccounts(s).instruction()]}async closeIntentIxs(e,t,n){return [await this._intentsProgram.methods.closeIntent().accountsStrict({initiator:e,rentPayer:t,intentStorage:m.getIntentStoragePda(this._intentsProgram.programId,n),state:this._state,systemProgram:web3_js.SystemProgram.programId}).instruction()]}async executeIntentIxs({tradeId:e,intentId:t,taker:n,maker:r,tokenMint:s,dlnOrder:a,dlnSrc:o=new web3_js.PublicKey(solanaUtils.programs.dlnSrc),tokenProgram:i=splToken.TOKEN_PROGRAM_ID}){let d=solanaUtils.dlnSrcResolver(o).methods,[u]=d.getStateAccount(),[c]=d.getGiveOrderStateAccount(a.id),[p]=d.getGiveOrderWalletAddress(a.id),[g]=d.getAuthorizedNativeSenderAddress(buffer.Buffer.from(new anchor.BN(a.dstChainId.toString()).toArray("be",32))),[f]=d.getFeeLedgerWalletAddress(s),l=m.getIntentStoragePda(this._intentsProgram.programId,t),y=splToken.getAssociatedTokenAddressSync(s,l,true,i),b={giveOriginalAmount:new anchor.BN(a.args.giveOriginalAmount.toString()),take:{amount:W(a.args.take.amount,"u256"),chainId:W(a.args.take.chainId,"u256"),tokenAddress:Array.from(a.args.take.tokenAddress)},receiverDst:Array.from(a.args.receiver),extcall:a.args.externalCall?.externalCallData?buffer.Buffer.from(a.args.externalCall.externalCallData):null,givePatchAuthoritySrc:a.args.givePatchAuthority,orderAuthorityAddressDst:Array.from(a.args.orderAuthorityDstAddress),allowedCancelBeneficiarySrc:a.args.allowedCancelBeneficiary,allowedTakerDst:a.args.allowedTaker?Array.from(a.args.allowedTaker):null};return [await this._intentsProgram.methods.executeIntent(b,new anchor.BN(a.nonce.toString()),Array.from(e)).accountsStrict({taker:n,state:this._state,intentStorage:l,maker:r,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,r),intentGiveToken:y,dlnSrc:o,dlnSrcState:u,dlnSrcGiveOrderState:c,dlnSrcGiveOrderWallet:p,dlnSrcAuthorizedNativeSender:g,dlnSrcFeeLedgerWallet:f,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:i,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async executeSameChainIntentIxs({tradeId:e,intentId:t,taker:n,maker:r,tokenMint:s,receiver:a,amount:o,tokenProgram:i=splToken.TOKEN_PROGRAM_ID}){let d=m.getIntentStoragePda(this._intentsProgram.programId,t),u=splToken.getAssociatedTokenAddressSync(s,d,true,i),c=splToken.getAssociatedTokenAddressSync(s,a,true,i),p=splToken.getAssociatedTokenAddressSync(s,this._state,true,i);return [await this._intentsProgram.methods.executeIntent2(new anchor.BN(o.toString()),Array.from(e)).accountsStrict({taker:n,state:this._state,maker:r,receiver:a,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,r),intentStorage:d,intentTakeToken:u,feeLedger:p,receiverTakeToken:c,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:i,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async initIntentIxs(e,t,n,r,s){let a=this.getSpace(r,s);return [await this._intentsProgram.methods.initIntent({0:Array.from(n)},a).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:m.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async initIntentUsingSigIxs(e,t,n,r,s,a){let o=this.getSpace(r,s);return [await this._intentsProgram.methods.initIntentUsingSig({0:Array.from(n)},o,e,Array.from(a)).accountsStrict({rentPayer:t,state:this._state,intentStorage:m.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async setDelegateApprovedBudgetsIxs({maker:e,payer:t,delegate:n,nonce:r,tokens:s}){let a;return "set"in s?a={set:s.set.map(({tokenMint:o,approvedAmount:i,expiration:d})=>({tokenMint:o,approvedAmount:new anchor.BN(i.toString()),expiration:new anchor.BN(d.toString())}))}:"setAny"in s?a={setAny:{}}:a={revoke:{}},[await this._intentsProgram.methods.setDelegateApprovedBudgets(n,new anchor.BN(r.toString()),a).accountsStrict({maker:e,rentPayer:t,state:this._state,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,e),systemProgram:web3_js.SystemProgram.programId,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:r,beginAmount:s,target:a,inputMint:o,outputMint:i,inputTokenProgram:d=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:u=splToken.TOKEN_PROGRAM_ID}){let c=m.getIntentStoragePda(this._intentsProgram.programId,n),p=splToken.getAssociatedTokenAddressSync(o,t,true,d),g=splToken.getAssociatedTokenAddressSync(o,e,true,d),f=splToken.getAssociatedTokenAddressSync(i,e,true,u),l=splToken.getAssociatedTokenAddressSync(i,c,true,u);return [await this._intentsProgram.methods.swapBegin(new anchor.BN(s.toString()),a==="intent"?{intent:{}}:{taker:{}},Array.from(r)).accountsStrict({taker:e,maker:t,state:this._state,intentStorage:c,inputMint:o,outputMint:i,makerInputToken:p,takerInputToken:g,takerOutputToken:f,intentOutputToken:l,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,inputTokenProgram:d,outputTokenProgram:u,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,makerInfo:m.getMakerInfoPda(this._intentsProgram.programId,t),eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async swapEndIxs({taker:e,intentId:t,endAmount:n,bps:r,outputMint:s,outputTokenProgram:a=splToken.TOKEN_PROGRAM_ID}){let o=m.getIntentStoragePda(this._intentsProgram.programId,t),i=splToken.getAssociatedTokenAddressSync(s,e,true,a),d=splToken.getAssociatedTokenAddressSync(s,o,true,a);return [await this._intentsProgram.methods.swapEnd(new anchor.BN(n.toString()),r).accountsStrict({taker:e,state:this._state,intentStorage:o,outputMint:s,takerOutputToken:i,intentOutputToken:d,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,outputTokenProgram:a,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:m.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async updateIntentIxs({payer:e,record:t,id:n,offset:r,length:s,data:a}){let o=m.getIntentStoragePda(this._intentsProgram.programId,n);return [await this._intentsProgram.methods.updateIntent(a?{instruction:[a]}:{buffer:{offset:r,length:s}}).accountsStrict({rentPayer:e,state:this._state,intentStorage:o,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:r}){return [splRecord.createWriteInstruction(t,e,BigInt(r),n,this.recordProgramId)]}async reallocRecordIxs({authority:e,payer:t,record:n,buffer:r,offset:s}){t||(t=e);let a=await this._provider.connection.getAccountInfo(n);if(!a)throw new Error("Record account not found");let o=a.lamports,i=a.data.length,d=s+r.length,u=[];if(d>i){let p=await this._provider.connection.getMinimumBalanceForRentExemption(d+1)-o,g=web3_js.SystemProgram.transfer({fromPubkey:t,toPubkey:n,lamports:p});u.push(g);let f=splRecord.createReallocateInstruction(n,e,BigInt(d-B),this.recordProgramId);u.push(f);}return u}async initIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:o}){t||(t=e);let i,d=web3_js.Keypair.generate(),u=n.data,c=B+u.length,p=await this._provider.connection.getMinimumBalanceForRentExemption(c+1),g=S(o);r?i=await this.initIntentUsingSigIxs(e,t,n.id,u.length,n.inputTokensLength,r):i=await this.initIntentIxs(e,t,n.id,u.length,n.inputTokensLength);let f=web3_js.SystemProgram.createAccount({fromPubkey:t,newAccountPubkey:d.publicKey,lamports:p,space:c,programId:this.recordProgramId}),l=splRecord.createInitializeInstruction(d.publicKey,t,this.recordProgramId),y=k({instructions:[...g,...i,f,l],payer:t,blockhash:s,ALTs:a});return {record:d,txs:[y]}}async writeIntentTxs({authority:e,payer:t,record:n,intent:r,blockhash:s,ALTs:a,computeBudget:o}){t||(t=e);let i=[],d=r.data,u=d.length,c=S(o),p=this.closeRecordIxs({record:n,authority:t,receiver:t}),g=k({instructions:[...c,...await this.updateIntentIxs({payer:t,id:r.id,data:d}),...p],payer:t,blockhash:s,ALTs:a}),f=solanaUtils.txs.getTransactionSize(g);if(f&&f<=solanaUtils.constants.MAX_TX_SIZE)return [g];let l=0,y=[];for(;l<u;){let x,L=[...c],M=1,D=u-l,F=[],V=0;for(;M<=D;){let G=Math.floor((M+D)/2),$=d.subarray(l,l+G);x=this.writeRecordIxs({authority:t,record:n,buffer:$,offset:l});let Y=k({instructions:[...L,...x],payer:t,blockhash:s,ALTs:a}),N=solanaUtils.txs.getTransactionSize(Y);N&&N<=solanaUtils.constants.MAX_TX_SIZE?(F=x,V=G,M=G+1):D=G-1;}L.push(...F),y=L;let q=k({instructions:L,payer:t,blockhash:s,ALTs:a});i.push(q),l+=V;}let A=[...await this.updateIntentIxs({record:n,payer:t,id:r.id,offset:B,length:u}),...p],_=[...y,...A],z=k({instructions:_,payer:t,blockhash:s,ALTs:a}),v=solanaUtils.txs.getTransactionSize(z);if(v&&v<=solanaUtils.constants.MAX_TX_SIZE)i[i.length-1]=z;else {let x=k({instructions:A,payer:t,blockhash:s,ALTs:a});i.push(x);}return i}async createIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:o}){let{record:i,txs:d}=await this.initIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:o}),u=await this.writeIntentTxs({authority:e,payer:t,record:i.publicKey,intent:n,blockhash:s,ALTs:a,computeBudget:o});return {init:d,write:u,record:i}}async createAndUpdateIntentTxs({authority:e,payer:t,intent:n,signature:r,blockhash:s,ALTs:a,computeBudget:o}){t||(t=e);let i,d,u=S(o);r?i=await this.initIntentUsingSigIxs(e,t,n.id,n.data?n.data.length:n.length,n.inputTokensLength,r):i=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:B+n.offset,length:n.length});let c=k({instructions:[...u,...i,...d],payer:t,blockhash:s,ALTs:a}),p=solanaUtils.txs.getTransactionSize(c);if(p&&p>solanaUtils.constants.MAX_TX_SIZE)throw new Error(`Tx size is ${p}, should be less than ${solanaUtils.constants.MAX_TX_SIZE}`);return [c]}async updateRecordTxs({authority:e,payer:t,record:n,serializedIntent:r,offset:s=B,blockhash:a,ALTs:o,computeBudget:i}){if(t||(t=e),s<B)throw new Error(`Offset can't be less than ${B}`);let d=[],u=r.length,c=await this.reallocRecordIxs({authority:e,payer:t,record:n,buffer:r,offset:s}),p=S(i),g=0;for(;g<u;){let f,l=[...p,...g===0?c:[]],y=1,b=u-g,A=[],_=0;for(;y<=b;){let v=Math.floor((y+b)/2),x=r.subarray(g,g+v);f=this.writeRecordIxs({authority:t,record:n,buffer:x,offset:g});let L=k({instructions:[...l,...f],payer:t,blockhash:a,ALTs:o}),M=solanaUtils.txs.getTransactionSize(L);M&&M<=solanaUtils.constants.MAX_TX_SIZE?(A=f,_=v,y=v+1):b=v-1;}l.push(...A);let z=k({instructions:l,payer:t,blockhash:a,ALTs:o});d.push(z),g+=_;}return d}async closeIntentTxs({authority:e,payer:t,record:n,receiver:r,id:s,blockhash:a,ALTs:o,computeBudget:i}){t||(t=e);let d=S(i),u=await this.closeIntentIxs(e,r??e,s);if(d.push(...u),n){let p=this.closeRecordIxs({record:n,authority:t,receiver:r});d.push(...p);}return [k({instructions:d,payer:t,blockhash:a,ALTs:o})]}async swapTxs({taker:e,maker:t,intentId:n,tradeId:r,inputMint:s,outputMint:a,beginAmount:o,endAmount:i,bps:d,target:u,inputTokenProgram:c=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:p=splToken.TOKEN_PROGRAM_ID,instructions:g=[],computeBudget:f,payer:l,blockhash:y,ALTs:b}){l||(l=e);let A=S(f),_=await this.swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:r,inputMint:s,outputMint:a,beginAmount:o,target:u,inputTokenProgram:c,outputTokenProgram:p}),z=await this.swapEndIxs({taker:e,intentId:n,endAmount:i,bps:d,outputMint:a,outputTokenProgram:p});return [k({instructions:[...A,..._,...g,...z],payer:l,blockhash:y,ALTs:b})]}static getStatePda(e){let[t]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("state")],e);return t}static getIntentStoragePda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("intent_storage"),t],e);return n}static getMakerInfoPda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("maker_info"),t.toBuffer()],e);return n}static getDelegatesPda(e,t){let[n]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("user_delegates"),t.toBuffer()],e);return n}static getEventAuthorityPda(e){let[t]=web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from("__event_authority")],e);return t}};var C=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 o of this.addresses){let i=e.get(o.length);i===void 0?e.set(o.length,[o]):i.push(o);}let t=Array.from(e.keys()).sort(),n=Buffer.alloc(t.reduce((o,i)=>o+e.get(i).length*i,0)+t.length*2+1);n[0]=t.length;let r=1,s=1+t.length*2,a=0;for(let o of t){let i=e.get(o).sort((u,c)=>u.compare(c));for(let u of i)this.lookupMap.set(u.toString("hex"),a),a+=1;n[r]=o,r+=1,n[r]=i.length,r+=1;let d=Buffer.concat(i);n.set(d,s),s+=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=i=>t.add(i.toString("hex")),r=i=>{if(i)for(let{address:d}of i)n(d);},s=i=>{if(i)for(let d of i)d.input!=="any"&&n(d.input),n(d.output);},a=i=>{if(i){for(let d of i)if(n(d.input),d.output!=="any")for(let u of d.output)u.token&&u.token!=="any"&&n(u.token);}};for(let i of e.inputTokens)n(i.token);s(e.giveTokens),a(e.takeTokens),r(e.receiverDetails),r(e.dstAuthorityAddress);let o=Array.from(t).map(i=>Buffer.from(i,"hex"));return new C(o)}serializeReceiversInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(({chainIds:n,address:r})=>{let s;if(n==="any")s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(r),0),s.writeUInt8(0,1);else {s=Buffer.alloc(3+n.length*4),s.writeUInt8(this.addressesList.lookupIndex(r),0),s.writeUInt8(1,1),s.writeUInt8(n.length,2);for(let[a,o]of n.entries())s.writeUInt32LE(o,3+a*4);}return s});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.token),n.writeBigUInt64LE(t.minPartialAmount,1),n.writeBigUInt64LE(t.maxPartialAmount,9),n.writeBigUInt64LE(t.constraintBudget,17),n});return Buffer.concat([Buffer.from([e.length]),...e])}serializeGiveTokens(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(n=>{let r;if(n.input==="any")r=Buffer.alloc(2),r.writeUInt8(this.addressesList.lookupIndex(n.output),0),r.writeUInt8(0,1);else {r=Buffer.alloc(35),r.writeUInt8(this.addressesList.lookupIndex(n.output),0),r.writeUInt8(1,1),r.writeUInt8(this.addressesList.lookupIndex(n.input),2),r.writeBigInt64LE(n.price,3);let s=n.price.toString(16).padStart(64,"0");Buffer.from(s,"hex").copy(r,3);}return r});return Buffer.concat([Buffer.from([e.length]),...t])}serializeTakeTokens(e){let t=0,n=e.map(r=>{let s;return r.output==="any"?(t=1,s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(r.input),0),s.writeUInt8(0,1)):(t+=r.output.length,s=Buffer.concat(r.output.map(a=>{if(a.chainId==="any"){let o=Buffer.alloc(2);return o.writeUInt8(this.addressesList.lookupIndex(r.input),0),o.writeUInt8(0,1),o}if(a.token==="any"){let o=Buffer.alloc(6);return o.writeUInt8(1,0),o.writeUInt8(a.chainId,1),o.writeUInt8(0,5),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(r.input)]),o])}else {let o=Buffer.alloc(40);o.writeUInt8(1,0),o.writeUInt32LE(a.chainId,1),o.writeUInt8(1,5),o.writeUInt8(this.addressesList.lookupIndex(a.token),6),o.writeUInt8(1,7);let i=a.price.toString(16).padStart(64,"0");return Buffer.from(i,"hex").copy(o,8),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(r.input)]),o])}}))),s});return Buffer.concat([Buffer.from([t]),...n])}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(Buffer.from([0]));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.serializeGiveTokens(this.data.giveTokens)),e.push(this.serializeTakeTokens(this.data.takeTokens)),e.push(this.serializeReceiversInfo(this.data.receiverDetails)),this.data.allowedSenders==="any"?e.push(Buffer.from([1]),Buffer.from([0])):e.push(Buffer.from([1]),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=B;exports.Intent=j;exports.IntentsClient=Z;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|