@debridge-finance/intents-client 1.3.0-dev.0 → 1.3.0-dev.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.d.mts CHANGED
@@ -3727,6 +3727,7 @@ declare class Intent implements Serializable {
3727
3727
  static getId(serializedIntent: Buffer, maker: PublicKey, programId: PublicKey): {
3728
3728
  hex: string;
3729
3729
  buffer: Buffer;
3730
+ rawHash: Buffer;
3730
3731
  };
3731
3732
  }
3732
3733
 
package/dist/index.d.ts CHANGED
@@ -3727,6 +3727,7 @@ declare class Intent implements Serializable {
3727
3727
  static getId(serializedIntent: Buffer, maker: PublicKey, programId: PublicKey): {
3728
3728
  hex: string;
3729
3729
  buffer: Buffer;
3730
+ rawHash: Buffer;
3730
3731
  };
3731
3732
  }
3732
3733
 
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 O={address:"intV2u5xDE8T2ZMFP3W3X6sVqGHBT7zvYtTW3rRLmvE",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:"maker",signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"tokenProgram"}],args:[{name:"amounts",type:{vec:"u64"}}]},{name:"cancelIntent",discriminator:[67,73,238,244,208,89,225,59],accounts:[{name:"initiator",signer:true},{name:"intentStorage",writable:true},{name:"state"}],args:[]},{name:"closeAccount",discriminator:[125,255,149,14,110,34,72,24],accounts:[{name:"programAuthority",signer:true,address:"intV2u5xDE8T2ZMFP3W3X6sVqGHBT7zvYtTW3rRLmvE"},{name:"target",writable:true},{name:"rentReceiver",writable:true}],args:[]},{name:"closeIntent",discriminator:[112,245,154,249,57,126,54,122],accounts:[{name:"initiator",signer:true},{name:"maker",docs:["CHECK"]},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{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"},{name:"maker",relations:["intentStorage"]},{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",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"},{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:"dlnMetadata",type:"bytes"},{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",relations:["intentStorage"]},{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",docs:["TODO: may be optional if receiver_take_token is already initialized"]},{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"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}}]},{name:"initIntentByDelegate",discriminator:[85,140,35,112,240,67,16,40],accounts:[{name:"delegate",signer:true},{name:"maker",docs:["CHECK"]},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}}]},{name:"initIntentByDelegateUsingSig",discriminator:[113,25,150,248,204,41,36,34],accounts:[{name:"delegate",docs:["CHECK"]},{name:"maker",docs:["CHECK"]},{name:"makerInfo",pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}},{name:"signature",type:{array:["u8",64]}}]},{name:"initIntentUsingSig",discriminator:[163,186,238,179,190,181,19,185],accounts:[{name:"maker",docs:["CHECK"]},{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}},{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:"intV2u5xDE8T2ZMFP3W3X6sVqGHBT7zvYtTW3rRLmvE"},{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:"setCancelUntilTimestamp",discriminator:[206,248,194,176,4,206,30,228],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:"cancelUntilTimestamp",type:"u64"}]},{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:"delegate"},{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:"nonce",type:"u64"},{name:"approvedTokenBudgets",type:{defined:{name:"setApprovedTokenBudgets"}}}]},{name:"setDelegateApprovedBudgetsUsingSig",discriminator:[26,11,76,149,162,38,128,0],accounts:[{name:"maker"},{name:"delegate"},{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:"nonce",type:"u64"},{name:"encodedApprovedTokenBudgets",type:"bytes"},{name:"signature",type:{array:["u8",64]}}]},{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:"setMakerCancelUntilTimestamp",discriminator:[144,42,186,107,205,215,55,229],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:"cancelUntilTimestamp",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",relations:["intentStorage"]},{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,pda:{seeds:[{kind:"account",path:"maker"},{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:"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},{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:"target",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:"inputMint"},{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:"expectedOutputTokenAmount",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},{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:"dataOrigin",type:{defined:{name:"dataOrigin"}}}]},{name:"withdrawCancelledIntentTokenAccount",discriminator:[174,169,179,36,13,33,88,124],accounts:[{name:"state"},{name:"maker",docs:["CHECK"],relations:["intentStorage"]},{name:"intentStorage",writable:true},{name:"intentTokenAccount",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:"makerTokenAccount",writable:true,pda:{seeds:[{kind:"account",path:"maker"},{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:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[]},{name:"withdrawClosedIntentTokenAccount",discriminator:[123,141,239,126,107,232,214,120],accounts:[{name:"state"},{name:"intentStorage",docs:["TODO: custom Account<'info, Terminated>"],pda:{seeds:[{kind:"const",value:[105,110,116,101,110,116,95,115,116,111,114,97,103,101]},{kind:"arg",path:"intentId"}]}},{name:"intentTokenAccount",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{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:"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:"mint"},{name:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[{name:"intentId",type:{defined:{name:"intentId"}}}]}],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:"closedIntent",discriminator:[197,62,20,42,191,176,242,94]},{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:"newIntent",discriminator:[101,118,73,187,15,74,57,97]},{name:"sealedIntent",discriminator:[28,191,234,161,83,32,138,137]},{name:"swapped",discriminator:[217,52,52,83,147,135,96,109]}],errors:[{code:6160,name:"invalidArgument"},{code:6170,name:"invalidAmount"},{code:6172,name:"malformedRemainingAccounts"},{code:16782961,name:"protocolPaused"},{code:16782979,name:"timeParadox"},{code:6234,name:"unknownCaller"},{code:6236,name:"unknownCancelAuthority"},{code:6079,name:"signatureVerificationFailed"},{code:6085,name:"intentIdMiscalculated"},{code:6086,name:"intentFromAnotherChain"},{code:6087,name:"intentSameChainOnly"},{code:6088,name:"intentInconsistentInputTokens"},{code:6089,name:"intentInconsistentGiveTokens"},{code:6096,name:"intentInconsistentTakeTokens"},{code:6097,name:"intentInconsitentReceivers"},{code:6098,name:"intentInconsitentDstAuthorities"},{code:6275,name:"intentStorageAlreadyInitialized"},{code:6276,name:"intentHashMismatch"},{code:6277,name:"intentStorageSealed"},{code:6278,name:"missedBufferAccount"},{code:6288,name:"intentNotReady"},{code:6289,name:"intentCancelled"},{code:6290,name:"intentExpired"},{code:6291,name:"intentInvalidatedByUser"},{code:6292,name:"intentInvalidatedByProtocolAuthority"},{code:6293,name:"expectedClosedIntent"},{code:9664,name:"tokenAccountMissingProtocolDelegate"},{code:9665,name:"unknownInputToken"},{code:9666,name:"inputTokenAmountOutOfRange"},{code:9667,name:"inputTokenAmountExceedsBudget"},{code:9680,name:"takerNotAllowed"},{code:9681,name:"unknownRoute"},{code:9682,name:"priceViolation"},{code:9683,name:"invalidReceiver"},{code:9793,name:"invalidDlnOrderTakeAmount"},{code:9794,name:"invalidDlnDstReceiver"},{code:9802,name:"invalidDlnDstOrderAuthority"},{code:9803,name:"invalidDlnDstAllowedTaker"},{code:9804,name:"invalidDlnSrcAllowedCancelBeneficiary"},{code:9805,name:"invalidDlnMetadata"},{code:9806,name:"invalidDlnExtcallHash"},{code:9788,name:"cantBeClosed"},{code:9839,name:"intentArbitraryDataOverflow"},{code:8832,name:"takerMustBeFixedWhenExtcallAllowed"},{code:8833,name:"ambiguousReceivers"},{code:9600,name:"interactionAccountNotFound"},{code:9601,name:"interactionProgramNotFound"},{code:6239,name:"interactionFixedAccountNotFound"},{code:9536,name:"unknownDelegate"},{code:9537,name:"delegateNonceMismatchNext"},{code:9546,name:"delegateHasNoApproval"},{code:9547,name:"delegateExceedsApprovedBudget"},{code:9550,name:"delegateApprovalExpired"},{code:9551,name:"delegateRevoked"},{code:16767137,name:"crossProgramInvokeRestricted"}],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:"closedIntent",type:{kind:"struct",fields:[{name:"status",type:{defined:{name:"closedIntentStatus"}}}]}},{name:"closedIntentStatus",repr:{kind:"rust"},type:{kind:"enum",variants:[{name:"wiped"},{name:"terminated"}]}},{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:"any"},{name:"perToken",fields:[{vec:{defined:{name:"currentTokenBudget"}}}]},{name:"revoked"}]}},{name:"delegateInfo",type:{kind:"struct",fields:[{name:"delegate",type:"pubkey"},{name:"nonce",type:"u64"},{name:"budgets",type:{defined:{name:"delegateBudgets"}}}]}},{name:"encodedIntentHash",type:{kind:"struct",fields:[{array:["u8",32]}]}},{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:"executionMetadata",type:{option:"bytes"}},{name:"tradeId",type:{array:["u8",32]}},{name:"orderId",type:{defined:{name:"u256"}}},{name:"giveTokenFeeAmount",type:"u64"}]}},{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:"delegate",type:{option:"pubkey"}},{name:"rentPayer",type:"pubkey"},{name:"arbitraryData",type:{array:["u8",100]}},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}},{name:"version",type:"u8"},{name:"storedIntent",type:{defined:{name:"storedIntent"}}},{name:"bump",type:"u8"}]}},{name:"makerInfo",type:{kind:"struct",fields:[{name:"cancelUntilTimestamp",type:"u64"},{name:"delegates",type:{vec:{defined:{name:"delegateInfo"}}}}]}},{name:"newIntent",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}}]}},{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:"sealedIntent",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"encodedIntent",type:"bytes"}]}},{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:"cancelUntilTimestamp",type:"u64"},{name:"bump",type:"u8"}]}},{name:"storedIntent",type:{kind:"enum",variants:[{name:"uninitialized"},{name:"ready",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]},{name:"cancelled",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]}]}},{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:"clockDriftToleranceSecs",type:"u64",value:"300"},{name:"defaultFeeBps",type:"u32",value:"8"},{name:"intentIdHashPrefix",docs:["Used **only** as sub-seed for [IntentId][`crate::types::IntentId`]"],type:"bytes",value:"[105, 110, 116, 101, 110, 116, 95, 105, 100]"},{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(c,e){let t;switch(e){case "u256":t=32;break;case "u64":t=8;break}return new anchor.BN(c.toString()).toArray("be",t)}var S=c=>{let e=[];return c?.limit&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({units:c.limit})),c?.price&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({microLamports:c.price})),e},y=({instructions:c,payer:e,blockhash:t,ALTs:n})=>new web3_js.VersionedTransaction(web3_js.MessageV0.compile({instructions:c,payerKey:e,recentBlockhash:t,addressLookupTableAccounts:n}));var B=splRecord.RECORD_META_DATA_SIZE,q=class c{programId;idl;recordProgramId;_provider;_intentsProgram;_state;constructor(e,{programId:t,recordProgramId:n=splRecord.RECORD_PROGRAM_ID}){O.address=t.toString(),this.idl=O,this.programId=t,this.recordProgramId=n,this._provider=new anchor.AnchorProvider(e,{},{}),anchor.setProvider(this._provider),this._intentsProgram=new anchor.Program(O,this._provider),this._state=c.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=c.getIntentStoragePda(this._intentsProgram.programId,t),a=await e.getAccountInfo(n);if(!a)return null;let s=this._intentsProgram.coder.accounts.decode("intentStorage",a.data);return {...s,intentId:buffer.Buffer.from(s.intentId[0])}}async approveProtocolTransfersIxs({maker:e,tokens:t,tokenProgram:n=splToken.TOKEN_PROGRAM_ID}){let{amounts:a,accounts:s}=t.reduce(({amounts:r,accounts:o},{mint:i,amount:d})=>({amounts:r.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(a).accountsStrict({maker: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:c.getIntentStoragePda(this._intentsProgram.programId,n),state:this._state,systemProgram:web3_js.SystemProgram.programId,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,e),maker:e}).instruction()]}async executeIntentIxs({tradeId:e,intentId:t,taker:n,maker:a,tokenMint:s,dlnOrder:r,dlnMetadata:o,dlnSrc:i=new web3_js.PublicKey(solanaUtils.programs.dlnSrc),tokenProgram:d=splToken.TOKEN_PROGRAM_ID}){let m=solanaUtils.dlnSrcResolver(i).methods,[u]=m.getStateAccount(),[l]=m.getGiveOrderStateAccount(r.id),[p]=m.getGiveOrderWalletAddress(r.id),[f]=m.getAuthorizedNativeSenderAddress(buffer.Buffer.from(new anchor.BN(r.dstChainId.toString()).toArray("be",32))),[g]=m.getFeeLedgerWalletAddress(s),k=c.getIntentStoragePda(this._intentsProgram.programId,t),v=splToken.getAssociatedTokenAddressSync(s,k,true,d),b={giveOriginalAmount:new anchor.BN(r.args.giveOriginalAmount.toString()),take:{amount:W(r.args.take.amount,"u256"),chainId:W(r.args.take.chainId,"u256"),tokenAddress:Array.from(r.args.take.tokenAddress)},receiverDst:Array.from(r.args.receiver),extcall:r.args.externalCall?.externalCallData?buffer.Buffer.from(r.args.externalCall.externalCallData):null,givePatchAuthoritySrc:r.args.givePatchAuthority,orderAuthorityAddressDst:Array.from(r.args.orderAuthorityDstAddress),allowedCancelBeneficiarySrc:r.args.allowedCancelBeneficiary,allowedTakerDst:r.args.allowedTaker?Array.from(r.args.allowedTaker):null};return [await this._intentsProgram.methods.executeIntent(b,new anchor.BN(r.nonce.toString()),o??buffer.Buffer.from([]),Array.from(e)).accountsStrict({taker:n,state:this._state,intentStorage:k,maker:a,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,a),intentGiveToken:v,dlnSrc:i,dlnSrcState:u,dlnSrcGiveOrderState:l,dlnSrcGiveOrderWallet:p,dlnSrcAuthorizedNativeSender:f,dlnSrcFeeLedgerWallet:g,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:d,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async executeSameChainIntentIxs({tradeId:e,intentId:t,taker:n,maker:a,tokenMint:s,receiver:r,amount:o,tokenProgram:i=splToken.TOKEN_PROGRAM_ID}){let d=c.getIntentStoragePda(this._intentsProgram.programId,t),m=splToken.getAssociatedTokenAddressSync(s,d,true,i),u=splToken.getAssociatedTokenAddressSync(s,r,true,i),l=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:a,receiver:r,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,a),intentStorage:d,intentTakeToken:m,feeLedger:l,receiverTakeToken:u,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:i,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async initIntentIxs(e,t,n,a,s,r){let o=this.getSpace(s,r);return [await this._intentsProgram.methods.initIntent(o,{0:Array.from(a)}).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:c.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async initIntentUsingSigIxs(e,t,n=null,a,s,r,o,i){let d=this.getSpace(r,o);return [await this._intentsProgram.methods.initIntentUsingSig(d,{0:Array.from(s)},Array.from(i)).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:c.getIntentStoragePda(this._intentsProgram.programId,a),systemProgram:web3_js.SystemProgram.programId,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async setDelegateApprovedBudgetsIxs({maker:e,payer:t,delegate:n,nonce:a,tokens:s}){let r;return "set"in s?r={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?r={setAny:{}}:r={revoke:{}},[await this._intentsProgram.methods.setDelegateApprovedBudgets(new anchor.BN(a.toString()),r).accountsStrict({maker:e,delegate:n,rentPayer:t,state:this._state,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,e),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:a,beginAmount:s,target:r,inputMint:o,outputMint:i,inputTokenProgram:d=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:m=splToken.TOKEN_PROGRAM_ID}){let u=c.getIntentStoragePda(this._intentsProgram.programId,n),l=splToken.getAssociatedTokenAddressSync(o,t,true,d),p=splToken.getAssociatedTokenAddressSync(o,e,true,d),f=splToken.getAssociatedTokenAddressSync(i,e,true,m),g=splToken.getAssociatedTokenAddressSync(i,u,true,m);return [await this._intentsProgram.methods.swapBegin(new anchor.BN(s.toString()),r==="intent"?{intent:{}}:{taker:{}},Array.from(a)).accountsStrict({taker:e,maker:t,state:this._state,intentStorage:u,inputMint:o,outputMint:i,makerInputToken:l,takerInputToken:p,takerOutputToken:f,intentOutputToken:g,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,inputTokenProgram:d,outputTokenProgram:m,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,t),eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async swapEndIxs({taker:e,intentId:t,endAmount:n,bps:a,inputMint:s,outputMint:r,outputTokenProgram:o=splToken.TOKEN_PROGRAM_ID}){let i=c.getIntentStoragePda(this._intentsProgram.programId,t),d=splToken.getAssociatedTokenAddressSync(r,e,true,o),m=splToken.getAssociatedTokenAddressSync(r,i,true,o);return [await this._intentsProgram.methods.swapEnd(new anchor.BN(n.toString()),a).accountsStrict({taker:e,state:this._state,intentStorage:i,inputMint:s,outputMint:r,takerOutputToken:d,intentOutputToken:m,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,outputTokenProgram:o,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async updateIntentIxs({payer:e,record:t,id:n,offset:a,length:s,data:r}){let o=c.getIntentStoragePda(this._intentsProgram.programId,n);return [await this._intentsProgram.methods.updateIntent(r?{instruction:[r]}:{buffer:{offset:a,length:s}}).accountsStrict({rentPayer:e,state:this._state,intentStorage:o,systemProgram:web3_js.SystemProgram.programId,buffer:t??null,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).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:s}){t||(t=e);let r=await this._provider.connection.getAccountInfo(n);if(!r)throw new Error("Record account not found");let o=r.lamports,i=r.data.length,d=s+a.length,m=[];if(d>i){let l=await this._provider.connection.getMinimumBalanceForRentExemption(d+1)-o,p=web3_js.SystemProgram.transfer({fromPubkey:t,toPubkey:n,lamports:l});m.push(p);let f=splRecord.createReallocateInstruction(n,e,BigInt(d-B),this.recordProgramId);m.push(f);}return m}async initIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}){t||(t=e);let d,m=web3_js.Keypair.generate(),u=a.data,l=B+u.length,p=await this._provider.connection.getMinimumBalanceForRentExemption(l+1),f=S(i);s?d=await this.initIntentUsingSigIxs(e,t,n??null,a.id,a.hash,u.length,a.inputTokensLength,s):d=await this.initIntentIxs(e,t,a.id,a.hash,u.length,a.inputTokensLength);let g=web3_js.SystemProgram.createAccount({fromPubkey:t,newAccountPubkey:m.publicKey,lamports:p,space:l,programId:this.recordProgramId}),k=splRecord.createInitializeInstruction(m.publicKey,t,this.recordProgramId),v=y({instructions:[...f,...d,g,k],payer:t,blockhash:r,ALTs:o});return {record:m,txs:[v]}}async writeIntentTxs({authority:e,payer:t,record:n,intent:a,blockhash:s,ALTs:r,computeBudget:o}){t||(t=e);let i=[],d=a.data,m=d.length,u=S(o),l=this.closeRecordIxs({record:n,authority:t,receiver:t}),p=y({instructions:[...u,...await this.updateIntentIxs({payer:t,id:a.id,data:d}),...l],payer:t,blockhash:s,ALTs:r}),f=solanaUtils.txs.getTransactionSize(p);if(f&&f<=solanaUtils.constants.MAX_TX_SIZE)return [p];let g=0,k=[];for(;g<m;){let w,_=[...u],M=1,G=m-g,K=[],F=0;for(;M<=G;){let z=Math.floor((M+G)/2),Y=d.subarray(g,g+z);w=this.writeRecordIxs({authority:t,record:n,buffer:Y,offset:g});let $=y({instructions:[..._,...w],payer:t,blockhash:s,ALTs:r}),V=solanaUtils.txs.getTransactionSize($);V&&V<=solanaUtils.constants.MAX_TX_SIZE?(K=w,F=z,M=z+1):G=z-1;}_.push(...K),k=_;let J=y({instructions:_,payer:t,blockhash:s,ALTs:r});i.push(J),g+=F;}let b=[...await this.updateIntentIxs({record:n,payer:t,id:a.id,offset:B,length:m}),...l],E=[...k,...b],C=y({instructions:E,payer:t,blockhash:s,ALTs:r}),A=solanaUtils.txs.getTransactionSize(C);if(A&&A<=solanaUtils.constants.MAX_TX_SIZE)i[i.length-1]=C;else {let w=y({instructions:b,payer:t,blockhash:s,ALTs:r});i.push(w);}return i}async createIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}){let{record:d,txs:m}=await this.initIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}),u=await this.writeIntentTxs({authority:e,payer:t,record:d.publicKey,intent:a,blockhash:r,ALTs:o,computeBudget:i});return {init:m,write:u,record:d}}async createAndUpdateIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}){t||(t=e);let d,m,u=S(i);s?d=await this.initIntentUsingSigIxs(e,t,n,a.id,a.hash,a.data?a.data.length:a.length,a.inputTokensLength,s):d=await this.initIntentIxs(e,t,a.id,a.hash,a.data?a.data.length:a.length,a.inputTokensLength),a.data?m=await this.updateIntentIxs({payer:t,id:a.id,data:a.data}):m=await this.updateIntentIxs({payer:t,record:a.record,id:a.id,offset:B+a.offset,length:a.length});let l=y({instructions:[...u,...d,...m],payer:t,blockhash:r,ALTs:o}),p=solanaUtils.txs.getTransactionSize(l);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 [l]}async updateRecordTxs({authority:e,payer:t,record:n,serializedIntent:a,offset:s=B,blockhash:r,ALTs:o,computeBudget:i}){if(t||(t=e),s<B)throw new Error(`Offset can't be less than ${B}`);let d=[],m=a.length,u=await this.reallocRecordIxs({authority:e,payer:t,record:n,buffer:a,offset:s}),l=S(i),p=0;for(;p<m;){let f,g=[...l,...p===0?u:[]],k=1,v=m-p,b=[],E=0;for(;k<=v;){let A=Math.floor((k+v)/2),w=a.subarray(p,p+A);f=this.writeRecordIxs({authority:t,record:n,buffer:w,offset:p});let _=y({instructions:[...g,...f],payer:t,blockhash:r,ALTs:o}),M=solanaUtils.txs.getTransactionSize(_);M&&M<=solanaUtils.constants.MAX_TX_SIZE?(b=f,E=A,k=A+1):v=A-1;}g.push(...b);let C=y({instructions:g,payer:t,blockhash:r,ALTs:o});d.push(C),p+=E;}return d}async closeIntentTxs({authority:e,payer:t,record:n,receiver:a,id:s,blockhash:r,ALTs:o,computeBudget:i}){t||(t=e);let d=S(i),m=await this.closeIntentIxs(e,a??e,s);if(d.push(...m),n){let l=this.closeRecordIxs({record:n,authority:t,receiver:a});d.push(...l);}return [y({instructions:d,payer:t,blockhash:r,ALTs:o})]}async swapTxs({taker:e,maker:t,intentId:n,tradeId:a,inputMint:s,outputMint:r,beginAmount:o,endAmount:i,bps:d,target:m,inputTokenProgram:u=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:l=splToken.TOKEN_PROGRAM_ID,instructions:p=[],lastInstructions:f=[],computeBudget:g,payer:k,blockhash:v,ALTs:b}){k||(k=e);let E=S(g),C=await this.swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:a,inputMint:s,outputMint:r,beginAmount:o,target:m,inputTokenProgram:u,outputTokenProgram:l}),A=await this.swapEndIxs({taker:e,intentId:n,endAmount:i,bps:d,inputMint:s,outputMint:r,outputTokenProgram:l});return [y({instructions:[...E,...C,...p,...A,...f],payer:k,blockhash:v,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 H=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 a=1,s=1+t.length*2,r=0;for(let o of t){let i=e.get(o).sort((m,u)=>m.compare(u));for(let m of i)this.lookupMap.set(m.toString("hex"),r),r+=1;n[a]=o,a+=1,n[a]=i.length,a+=1;let d=Buffer.concat(i);n.set(d,s),s+=d.length;}return n}};var X=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")),a=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);},r=i=>{if(i){for(let d of i)if(n(d.input),d.output!=="any")for(let m of d.output)m.token&&m.token!=="any"&&n(m.token);}};for(let i of e.inputTokens)n(i.token);s(e.giveTokens),r(e.takeTokens),a(e.receiverDetails),a(e.dstAuthorityAddress);let o=Array.from(t).map(i=>Buffer.from(i,"hex"));return new H(o)}serializeReceiversInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(({chainIds:n,address:a})=>{let s;if(n==="any")s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(a),0),s.writeUInt8(1,1);else {s=Buffer.alloc(3+n.length*4),s.writeUInt8(this.addressesList.lookupIndex(a),0),s.writeUInt8(0,1),s.writeUInt8(n.length,2);for(let[r,o]of n.entries())s.writeUInt32LE(o,3+r*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 a;if(n.input==="any")a=Buffer.alloc(2),a.writeUInt8(this.addressesList.lookupIndex(n.output),0),a.writeUInt8(1,1);else {a=Buffer.alloc(35),a.writeUInt8(this.addressesList.lookupIndex(n.output),0),a.writeUInt8(0,1),a.writeUInt8(this.addressesList.lookupIndex(n.input),2),a.writeBigInt64LE(n.price,3);let s=n.price.toString(16).padStart(64,"0");Buffer.from(s,"hex").copy(a,3);}return a});return Buffer.concat([Buffer.from([e.length]),...t])}serializeTakeTokens(e){let t=0,n=e.map(a=>{let s;return a.output==="any"?(t=1,s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(a.input),0),s.writeUInt8(1,1)):(t+=a.output.length,s=Buffer.concat(a.output.map(r=>{if(r.token==="any"){let o=Buffer.alloc(6);return o.writeUInt8(0,0),o.writeUInt8(r.chainId,1),o.writeUInt8(1,5),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(a.input)]),o])}else {let o=Buffer.alloc(40);o.writeUInt8(0,0),o.writeUInt32LE(r.chainId,1),o.writeUInt8(0,5),o.writeUInt8(this.addressesList.lookupIndex(r.token),6),o.writeUInt8(0,7);let i=r.price.toString(16).padStart(64,"0");return Buffer.from(i,"hex").copy(o,8),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(a.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),this.data.authority?e.push(Buffer.from([1]),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])):e.push(Buffer.from([0]),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([1])):this.data.externalCallHash?e.push(Buffer.from([1]),Buffer.from([0]),this.serializeOptionalBytes(this.data.externalCallHash)):e.push(Buffer.from([0])),this.data.dlnMetadata==="any"?e.push(Buffer.from([1]),Buffer.from([1])):this.data.dlnMetadata?e.push(Buffer.from([1]),Buffer.from([0]),this.serializeShortArray(this.data.dlnMetadata)):e.push(Buffer.from([0])),Buffer.concat(e)}static getId(e,t,n){let a=jsSha3.keccak256(e),s=Buffer.from(a,"hex"),[r]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("intent_id"),t.toBuffer(),s],n);return {hex:`0x${r.toBuffer().toString("hex")}`,buffer:r.toBuffer()}}};exports.DEFAULT_RECORD_OFFSET=B;exports.IDL=O;exports.Intent=X;exports.IntentsClient=q;//# 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 O={address:"intV2u5xDE8T2ZMFP3W3X6sVqGHBT7zvYtTW3rRLmvE",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:"maker",signer:true},{name:"state",pda:{seeds:[{kind:"const",value:[115,116,97,116,101]}]}},{name:"tokenProgram"}],args:[{name:"amounts",type:{vec:"u64"}}]},{name:"cancelIntent",discriminator:[67,73,238,244,208,89,225,59],accounts:[{name:"initiator",signer:true},{name:"intentStorage",writable:true},{name:"state"}],args:[]},{name:"closeAccount",discriminator:[125,255,149,14,110,34,72,24],accounts:[{name:"programAuthority",signer:true,address:"intV2u5xDE8T2ZMFP3W3X6sVqGHBT7zvYtTW3rRLmvE"},{name:"target",writable:true},{name:"rentReceiver",writable:true}],args:[]},{name:"closeIntent",discriminator:[112,245,154,249,57,126,54,122],accounts:[{name:"initiator",signer:true},{name:"maker",docs:["CHECK"]},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{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"},{name:"maker",relations:["intentStorage"]},{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",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"},{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:"dlnMetadata",type:"bytes"},{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",relations:["intentStorage"]},{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",docs:["TODO: may be optional if receiver_take_token is already initialized"]},{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"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}}]},{name:"initIntentByDelegate",discriminator:[85,140,35,112,240,67,16,40],accounts:[{name:"delegate",signer:true},{name:"maker",docs:["CHECK"]},{name:"makerInfo",writable:true,pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}}]},{name:"initIntentByDelegateUsingSig",discriminator:[113,25,150,248,204,41,36,34],accounts:[{name:"delegate",docs:["CHECK"]},{name:"maker",docs:["CHECK"]},{name:"makerInfo",pda:{seeds:[{kind:"const",value:[109,97,107,101,114,95,105,110,102,111]},{kind:"account",path:"maker"}]}},{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}},{name:"signature",type:{array:["u8",64]}}]},{name:"initIntentUsingSig",discriminator:[163,186,238,179,190,181,19,185],accounts:[{name:"maker",docs:["CHECK"]},{name:"rentPayer",writable:true,signer:true},{name:"state"},{name:"intentStorage",writable:true},{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:"space",type:"u32"},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}},{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:"intV2u5xDE8T2ZMFP3W3X6sVqGHBT7zvYtTW3rRLmvE"},{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:"setCancelUntilTimestamp",discriminator:[206,248,194,176,4,206,30,228],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:"cancelUntilTimestamp",type:"u64"}]},{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:"delegate"},{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:"nonce",type:"u64"},{name:"approvedTokenBudgets",type:{defined:{name:"setApprovedTokenBudgets"}}}]},{name:"setDelegateApprovedBudgetsUsingSig",discriminator:[26,11,76,149,162,38,128,0],accounts:[{name:"maker"},{name:"delegate"},{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:"nonce",type:"u64"},{name:"encodedApprovedTokenBudgets",type:"bytes"},{name:"signature",type:{array:["u8",64]}}]},{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:"setMakerCancelUntilTimestamp",discriminator:[144,42,186,107,205,215,55,229],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:"cancelUntilTimestamp",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",relations:["intentStorage"]},{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,pda:{seeds:[{kind:"account",path:"maker"},{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:"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},{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:"target",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:"inputMint"},{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:"expectedOutputTokenAmount",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},{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:"dataOrigin",type:{defined:{name:"dataOrigin"}}}]},{name:"withdrawCancelledIntentTokenAccount",discriminator:[174,169,179,36,13,33,88,124],accounts:[{name:"state"},{name:"maker",docs:["CHECK"],relations:["intentStorage"]},{name:"intentStorage",writable:true},{name:"intentTokenAccount",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:"makerTokenAccount",writable:true,pda:{seeds:[{kind:"account",path:"maker"},{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:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[]},{name:"withdrawClosedIntentTokenAccount",discriminator:[123,141,239,126,107,232,214,120],accounts:[{name:"state"},{name:"intentStorage",docs:["TODO: custom Account<'info, Terminated>"],pda:{seeds:[{kind:"const",value:[105,110,116,101,110,116,95,115,116,111,114,97,103,101]},{kind:"arg",path:"intentId"}]}},{name:"intentTokenAccount",writable:true,pda:{seeds:[{kind:"account",path:"intentStorage"},{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:"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:"mint"},{name:"tokenProgram"},{name:"associatedTokenProgram",address:"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"}],args:[{name:"intentId",type:{defined:{name:"intentId"}}}]}],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:"closedIntent",discriminator:[197,62,20,42,191,176,242,94]},{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:"newIntent",discriminator:[101,118,73,187,15,74,57,97]},{name:"sealedIntent",discriminator:[28,191,234,161,83,32,138,137]},{name:"swapped",discriminator:[217,52,52,83,147,135,96,109]}],errors:[{code:6160,name:"invalidArgument"},{code:6170,name:"invalidAmount"},{code:6172,name:"malformedRemainingAccounts"},{code:16782961,name:"protocolPaused"},{code:16782979,name:"timeParadox"},{code:6234,name:"unknownCaller"},{code:6236,name:"unknownCancelAuthority"},{code:6079,name:"signatureVerificationFailed"},{code:6085,name:"intentIdMiscalculated"},{code:6086,name:"intentFromAnotherChain"},{code:6087,name:"intentSameChainOnly"},{code:6088,name:"intentInconsistentInputTokens"},{code:6089,name:"intentInconsistentGiveTokens"},{code:6096,name:"intentInconsistentTakeTokens"},{code:6097,name:"intentInconsitentReceivers"},{code:6098,name:"intentInconsitentDstAuthorities"},{code:6275,name:"intentStorageAlreadyInitialized"},{code:6276,name:"intentHashMismatch"},{code:6277,name:"intentStorageSealed"},{code:6278,name:"missedBufferAccount"},{code:6288,name:"intentNotReady"},{code:6289,name:"intentCancelled"},{code:6290,name:"intentExpired"},{code:6291,name:"intentInvalidatedByUser"},{code:6292,name:"intentInvalidatedByProtocolAuthority"},{code:6293,name:"expectedClosedIntent"},{code:9664,name:"tokenAccountMissingProtocolDelegate"},{code:9665,name:"unknownInputToken"},{code:9666,name:"inputTokenAmountOutOfRange"},{code:9667,name:"inputTokenAmountExceedsBudget"},{code:9680,name:"takerNotAllowed"},{code:9681,name:"unknownRoute"},{code:9682,name:"priceViolation"},{code:9683,name:"invalidReceiver"},{code:9793,name:"invalidDlnOrderTakeAmount"},{code:9794,name:"invalidDlnDstReceiver"},{code:9802,name:"invalidDlnDstOrderAuthority"},{code:9803,name:"invalidDlnDstAllowedTaker"},{code:9804,name:"invalidDlnSrcAllowedCancelBeneficiary"},{code:9805,name:"invalidDlnMetadata"},{code:9806,name:"invalidDlnExtcallHash"},{code:9788,name:"cantBeClosed"},{code:9839,name:"intentArbitraryDataOverflow"},{code:8832,name:"takerMustBeFixedWhenExtcallAllowed"},{code:8833,name:"ambiguousReceivers"},{code:9600,name:"interactionAccountNotFound"},{code:9601,name:"interactionProgramNotFound"},{code:6239,name:"interactionFixedAccountNotFound"},{code:9536,name:"unknownDelegate"},{code:9537,name:"delegateNonceMismatchNext"},{code:9546,name:"delegateHasNoApproval"},{code:9547,name:"delegateExceedsApprovedBudget"},{code:9550,name:"delegateApprovalExpired"},{code:9551,name:"delegateRevoked"},{code:16767137,name:"crossProgramInvokeRestricted"}],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:"closedIntent",type:{kind:"struct",fields:[{name:"status",type:{defined:{name:"closedIntentStatus"}}}]}},{name:"closedIntentStatus",repr:{kind:"rust"},type:{kind:"enum",variants:[{name:"wiped"},{name:"terminated"}]}},{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:"any"},{name:"perToken",fields:[{vec:{defined:{name:"currentTokenBudget"}}}]},{name:"revoked"}]}},{name:"delegateInfo",type:{kind:"struct",fields:[{name:"delegate",type:"pubkey"},{name:"nonce",type:"u64"},{name:"budgets",type:{defined:{name:"delegateBudgets"}}}]}},{name:"encodedIntentHash",type:{kind:"struct",fields:[{array:["u8",32]}]}},{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:"executionMetadata",type:{option:"bytes"}},{name:"tradeId",type:{array:["u8",32]}},{name:"orderId",type:{defined:{name:"u256"}}},{name:"giveTokenFeeAmount",type:"u64"}]}},{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:"delegate",type:{option:"pubkey"}},{name:"rentPayer",type:"pubkey"},{name:"arbitraryData",type:{array:["u8",100]}},{name:"encodedIntentHash",type:{defined:{name:"encodedIntentHash"}}},{name:"version",type:"u8"},{name:"storedIntent",type:{defined:{name:"storedIntent"}}},{name:"bump",type:"u8"}]}},{name:"makerInfo",type:{kind:"struct",fields:[{name:"cancelUntilTimestamp",type:"u64"},{name:"delegates",type:{vec:{defined:{name:"delegateInfo"}}}}]}},{name:"newIntent",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}}]}},{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:"sealedIntent",type:{kind:"struct",fields:[{name:"intentId",type:{defined:{name:"intentId"}}},{name:"encodedIntent",type:"bytes"}]}},{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:"cancelUntilTimestamp",type:"u64"},{name:"bump",type:"u8"}]}},{name:"storedIntent",type:{kind:"enum",variants:[{name:"uninitialized"},{name:"ready",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]},{name:"cancelled",fields:[{name:"encodedIntent",type:"bytes"},{name:"budgets",type:{defined:{name:"intentBudgets"}}}]}]}},{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:"clockDriftToleranceSecs",type:"u64",value:"300"},{name:"defaultFeeBps",type:"u32",value:"8"},{name:"intentIdHashPrefix",docs:["Used **only** as sub-seed for [IntentId][`crate::types::IntentId`]"],type:"bytes",value:"[105, 110, 116, 101, 110, 116, 95, 105, 100]"},{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(c,e){let t;switch(e){case "u256":t=32;break;case "u64":t=8;break}return new anchor.BN(c.toString()).toArray("be",t)}var S=c=>{let e=[];return c?.limit&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitLimit({units:c.limit})),c?.price&&e.push(web3_js.ComputeBudgetProgram.setComputeUnitPrice({microLamports:c.price})),e},y=({instructions:c,payer:e,blockhash:t,ALTs:n})=>new web3_js.VersionedTransaction(web3_js.MessageV0.compile({instructions:c,payerKey:e,recentBlockhash:t,addressLookupTableAccounts:n}));var B=splRecord.RECORD_META_DATA_SIZE,q=class c{programId;idl;recordProgramId;_provider;_intentsProgram;_state;constructor(e,{programId:t,recordProgramId:n=splRecord.RECORD_PROGRAM_ID}){O.address=t.toString(),this.idl=O,this.programId=t,this.recordProgramId=n,this._provider=new anchor.AnchorProvider(e,{},{}),anchor.setProvider(this._provider),this._intentsProgram=new anchor.Program(O,this._provider),this._state=c.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=c.getIntentStoragePda(this._intentsProgram.programId,t),a=await e.getAccountInfo(n);if(!a)return null;let s=this._intentsProgram.coder.accounts.decode("intentStorage",a.data);return {...s,intentId:buffer.Buffer.from(s.intentId[0])}}async approveProtocolTransfersIxs({maker:e,tokens:t,tokenProgram:n=splToken.TOKEN_PROGRAM_ID}){let{amounts:a,accounts:s}=t.reduce(({amounts:r,accounts:o},{mint:i,amount:d})=>({amounts:r.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(a).accountsStrict({maker: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:c.getIntentStoragePda(this._intentsProgram.programId,n),state:this._state,systemProgram:web3_js.SystemProgram.programId,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,e),maker:e}).instruction()]}async executeIntentIxs({tradeId:e,intentId:t,taker:n,maker:a,tokenMint:s,dlnOrder:r,dlnMetadata:o,dlnSrc:i=new web3_js.PublicKey(solanaUtils.programs.dlnSrc),tokenProgram:d=splToken.TOKEN_PROGRAM_ID}){let m=solanaUtils.dlnSrcResolver(i).methods,[u]=m.getStateAccount(),[l]=m.getGiveOrderStateAccount(r.id),[p]=m.getGiveOrderWalletAddress(r.id),[f]=m.getAuthorizedNativeSenderAddress(buffer.Buffer.from(new anchor.BN(r.dstChainId.toString()).toArray("be",32))),[g]=m.getFeeLedgerWalletAddress(s),k=c.getIntentStoragePda(this._intentsProgram.programId,t),v=splToken.getAssociatedTokenAddressSync(s,k,true,d),b={giveOriginalAmount:new anchor.BN(r.args.giveOriginalAmount.toString()),take:{amount:W(r.args.take.amount,"u256"),chainId:W(r.args.take.chainId,"u256"),tokenAddress:Array.from(r.args.take.tokenAddress)},receiverDst:Array.from(r.args.receiver),extcall:r.args.externalCall?.externalCallData?buffer.Buffer.from(r.args.externalCall.externalCallData):null,givePatchAuthoritySrc:r.args.givePatchAuthority,orderAuthorityAddressDst:Array.from(r.args.orderAuthorityDstAddress),allowedCancelBeneficiarySrc:r.args.allowedCancelBeneficiary,allowedTakerDst:r.args.allowedTaker?Array.from(r.args.allowedTaker):null};return [await this._intentsProgram.methods.executeIntent(b,new anchor.BN(r.nonce.toString()),o??buffer.Buffer.from([]),Array.from(e)).accountsStrict({taker:n,state:this._state,intentStorage:k,maker:a,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,a),intentGiveToken:v,dlnSrc:i,dlnSrcState:u,dlnSrcGiveOrderState:l,dlnSrcGiveOrderWallet:p,dlnSrcAuthorizedNativeSender:f,dlnSrcFeeLedgerWallet:g,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:d,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async executeSameChainIntentIxs({tradeId:e,intentId:t,taker:n,maker:a,tokenMint:s,receiver:r,amount:o,tokenProgram:i=splToken.TOKEN_PROGRAM_ID}){let d=c.getIntentStoragePda(this._intentsProgram.programId,t),m=splToken.getAssociatedTokenAddressSync(s,d,true,i),u=splToken.getAssociatedTokenAddressSync(s,r,true,i),l=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:a,receiver:r,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,a),intentStorage:d,intentTakeToken:m,feeLedger:l,receiverTakeToken:u,tokenMint:s,systemProgram:web3_js.SystemProgram.programId,tokenProgram:i,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async initIntentIxs(e,t,n,a,s,r){let o=this.getSpace(s,r);return [await this._intentsProgram.methods.initIntent(o,{0:Array.from(a)}).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:c.getIntentStoragePda(this._intentsProgram.programId,n),systemProgram:web3_js.SystemProgram.programId,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async initIntentUsingSigIxs(e,t,n=null,a,s,r,o,i){let d=this.getSpace(r,o);return [await this._intentsProgram.methods.initIntentUsingSig(d,{0:Array.from(s)},Array.from(i)).accountsStrict({maker:e,rentPayer:t,state:this._state,intentStorage:c.getIntentStoragePda(this._intentsProgram.programId,a),systemProgram:web3_js.SystemProgram.programId,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async setDelegateApprovedBudgetsIxs({maker:e,payer:t,delegate:n,nonce:a,tokens:s}){let r;return "set"in s?r={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?r={setAny:{}}:r={revoke:{}},[await this._intentsProgram.methods.setDelegateApprovedBudgets(new anchor.BN(a.toString()),r).accountsStrict({maker:e,delegate:n,rentPayer:t,state:this._state,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,e),systemProgram:web3_js.SystemProgram.programId}).instruction()]}async swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:a,beginAmount:s,target:r,inputMint:o,outputMint:i,inputTokenProgram:d=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:m=splToken.TOKEN_PROGRAM_ID}){let u=c.getIntentStoragePda(this._intentsProgram.programId,n),l=splToken.getAssociatedTokenAddressSync(o,t,true,d),p=splToken.getAssociatedTokenAddressSync(o,e,true,d),f=splToken.getAssociatedTokenAddressSync(i,e,true,m),g=splToken.getAssociatedTokenAddressSync(i,u,true,m);return [await this._intentsProgram.methods.swapBegin(new anchor.BN(s.toString()),r==="intent"?{intent:{}}:{taker:{}},Array.from(a)).accountsStrict({taker:e,maker:t,state:this._state,intentStorage:u,inputMint:o,outputMint:i,makerInputToken:l,takerInputToken:p,takerOutputToken:f,intentOutputToken:g,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,inputTokenProgram:d,outputTokenProgram:m,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,makerInfo:c.getMakerInfoPda(this._intentsProgram.programId,t),eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async swapEndIxs({taker:e,intentId:t,endAmount:n,bps:a,inputMint:s,outputMint:r,outputTokenProgram:o=splToken.TOKEN_PROGRAM_ID}){let i=c.getIntentStoragePda(this._intentsProgram.programId,t),d=splToken.getAssociatedTokenAddressSync(r,e,true,o),m=splToken.getAssociatedTokenAddressSync(r,i,true,o);return [await this._intentsProgram.methods.swapEnd(new anchor.BN(n.toString()),a).accountsStrict({taker:e,state:this._state,intentStorage:i,inputMint:s,outputMint:r,takerOutputToken:d,intentOutputToken:m,instructions:web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,systemProgram:web3_js.SystemProgram.programId,outputTokenProgram:o,associatedTokenProgram:splToken.ASSOCIATED_TOKEN_PROGRAM_ID,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).instruction()]}async updateIntentIxs({payer:e,record:t,id:n,offset:a,length:s,data:r}){let o=c.getIntentStoragePda(this._intentsProgram.programId,n);return [await this._intentsProgram.methods.updateIntent(r?{instruction:[r]}:{buffer:{offset:a,length:s}}).accountsStrict({rentPayer:e,state:this._state,intentStorage:o,systemProgram:web3_js.SystemProgram.programId,buffer:t??null,eventAuthority:c.getEventAuthorityPda(this._intentsProgram.programId),program:this._intentsProgram.programId}).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:s}){t||(t=e);let r=await this._provider.connection.getAccountInfo(n);if(!r)throw new Error("Record account not found");let o=r.lamports,i=r.data.length,d=s+a.length,m=[];if(d>i){let l=await this._provider.connection.getMinimumBalanceForRentExemption(d+1)-o,p=web3_js.SystemProgram.transfer({fromPubkey:t,toPubkey:n,lamports:l});m.push(p);let f=splRecord.createReallocateInstruction(n,e,BigInt(d-B),this.recordProgramId);m.push(f);}return m}async initIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}){t||(t=e);let d,m=web3_js.Keypair.generate(),u=a.data,l=B+u.length,p=await this._provider.connection.getMinimumBalanceForRentExemption(l+1),f=S(i);s?d=await this.initIntentUsingSigIxs(e,t,n??null,a.id,a.hash,u.length,a.inputTokensLength,s):d=await this.initIntentIxs(e,t,a.id,a.hash,u.length,a.inputTokensLength);let g=web3_js.SystemProgram.createAccount({fromPubkey:t,newAccountPubkey:m.publicKey,lamports:p,space:l,programId:this.recordProgramId}),k=splRecord.createInitializeInstruction(m.publicKey,t,this.recordProgramId),v=y({instructions:[...f,...d,g,k],payer:t,blockhash:r,ALTs:o});return {record:m,txs:[v]}}async writeIntentTxs({authority:e,payer:t,record:n,intent:a,blockhash:s,ALTs:r,computeBudget:o}){t||(t=e);let i=[],d=a.data,m=d.length,u=S(o),l=this.closeRecordIxs({record:n,authority:t,receiver:t}),p=y({instructions:[...u,...await this.updateIntentIxs({payer:t,id:a.id,data:d}),...l],payer:t,blockhash:s,ALTs:r}),f=solanaUtils.txs.getTransactionSize(p);if(f&&f<=solanaUtils.constants.MAX_TX_SIZE)return [p];let g=0,k=[];for(;g<m;){let w,_=[...u],M=1,G=m-g,K=[],F=0;for(;M<=G;){let z=Math.floor((M+G)/2),Y=d.subarray(g,g+z);w=this.writeRecordIxs({authority:t,record:n,buffer:Y,offset:g});let $=y({instructions:[..._,...w],payer:t,blockhash:s,ALTs:r}),V=solanaUtils.txs.getTransactionSize($);V&&V<=solanaUtils.constants.MAX_TX_SIZE?(K=w,F=z,M=z+1):G=z-1;}_.push(...K),k=_;let J=y({instructions:_,payer:t,blockhash:s,ALTs:r});i.push(J),g+=F;}let b=[...await this.updateIntentIxs({record:n,payer:t,id:a.id,offset:B,length:m}),...l],E=[...k,...b],C=y({instructions:E,payer:t,blockhash:s,ALTs:r}),A=solanaUtils.txs.getTransactionSize(C);if(A&&A<=solanaUtils.constants.MAX_TX_SIZE)i[i.length-1]=C;else {let w=y({instructions:b,payer:t,blockhash:s,ALTs:r});i.push(w);}return i}async createIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}){let{record:d,txs:m}=await this.initIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}),u=await this.writeIntentTxs({authority:e,payer:t,record:d.publicKey,intent:a,blockhash:r,ALTs:o,computeBudget:i});return {init:m,write:u,record:d}}async createAndUpdateIntentTxs({authority:e,payer:t,delegate:n,intent:a,signature:s,blockhash:r,ALTs:o,computeBudget:i}){t||(t=e);let d,m,u=S(i);s?d=await this.initIntentUsingSigIxs(e,t,n,a.id,a.hash,a.data?a.data.length:a.length,a.inputTokensLength,s):d=await this.initIntentIxs(e,t,a.id,a.hash,a.data?a.data.length:a.length,a.inputTokensLength),a.data?m=await this.updateIntentIxs({payer:t,id:a.id,data:a.data}):m=await this.updateIntentIxs({payer:t,record:a.record,id:a.id,offset:B+a.offset,length:a.length});let l=y({instructions:[...u,...d,...m],payer:t,blockhash:r,ALTs:o}),p=solanaUtils.txs.getTransactionSize(l);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 [l]}async updateRecordTxs({authority:e,payer:t,record:n,serializedIntent:a,offset:s=B,blockhash:r,ALTs:o,computeBudget:i}){if(t||(t=e),s<B)throw new Error(`Offset can't be less than ${B}`);let d=[],m=a.length,u=await this.reallocRecordIxs({authority:e,payer:t,record:n,buffer:a,offset:s}),l=S(i),p=0;for(;p<m;){let f,g=[...l,...p===0?u:[]],k=1,v=m-p,b=[],E=0;for(;k<=v;){let A=Math.floor((k+v)/2),w=a.subarray(p,p+A);f=this.writeRecordIxs({authority:t,record:n,buffer:w,offset:p});let _=y({instructions:[...g,...f],payer:t,blockhash:r,ALTs:o}),M=solanaUtils.txs.getTransactionSize(_);M&&M<=solanaUtils.constants.MAX_TX_SIZE?(b=f,E=A,k=A+1):v=A-1;}g.push(...b);let C=y({instructions:g,payer:t,blockhash:r,ALTs:o});d.push(C),p+=E;}return d}async closeIntentTxs({authority:e,payer:t,record:n,receiver:a,id:s,blockhash:r,ALTs:o,computeBudget:i}){t||(t=e);let d=S(i),m=await this.closeIntentIxs(e,a??e,s);if(d.push(...m),n){let l=this.closeRecordIxs({record:n,authority:t,receiver:a});d.push(...l);}return [y({instructions:d,payer:t,blockhash:r,ALTs:o})]}async swapTxs({taker:e,maker:t,intentId:n,tradeId:a,inputMint:s,outputMint:r,beginAmount:o,endAmount:i,bps:d,target:m,inputTokenProgram:u=splToken.TOKEN_PROGRAM_ID,outputTokenProgram:l=splToken.TOKEN_PROGRAM_ID,instructions:p=[],lastInstructions:f=[],computeBudget:g,payer:k,blockhash:v,ALTs:b}){k||(k=e);let E=S(g),C=await this.swapBeginIxs({taker:e,maker:t,intentId:n,tradeId:a,inputMint:s,outputMint:r,beginAmount:o,target:m,inputTokenProgram:u,outputTokenProgram:l}),A=await this.swapEndIxs({taker:e,intentId:n,endAmount:i,bps:d,inputMint:s,outputMint:r,outputTokenProgram:l});return [y({instructions:[...E,...C,...p,...A,...f],payer:k,blockhash:v,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 H=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 a=1,s=1+t.length*2,r=0;for(let o of t){let i=e.get(o).sort((m,u)=>m.compare(u));for(let m of i)this.lookupMap.set(m.toString("hex"),r),r+=1;n[a]=o,a+=1,n[a]=i.length,a+=1;let d=Buffer.concat(i);n.set(d,s),s+=d.length;}return n}};var X=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")),a=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);},r=i=>{if(i){for(let d of i)if(n(d.input),d.output!=="any")for(let m of d.output)m.token&&m.token!=="any"&&n(m.token);}};for(let i of e.inputTokens)n(i.token);s(e.giveTokens),r(e.takeTokens),a(e.receiverDetails),a(e.dstAuthorityAddress);let o=Array.from(t).map(i=>Buffer.from(i,"hex"));return new H(o)}serializeReceiversInfo(e){if(!e||e.length===0)return Buffer.from([0]);let t=e.map(({chainIds:n,address:a})=>{let s;if(n==="any")s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(a),0),s.writeUInt8(1,1);else {s=Buffer.alloc(3+n.length*4),s.writeUInt8(this.addressesList.lookupIndex(a),0),s.writeUInt8(0,1),s.writeUInt8(n.length,2);for(let[r,o]of n.entries())s.writeUInt32LE(o,3+r*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 a;if(n.input==="any")a=Buffer.alloc(2),a.writeUInt8(this.addressesList.lookupIndex(n.output),0),a.writeUInt8(1,1);else {a=Buffer.alloc(35),a.writeUInt8(this.addressesList.lookupIndex(n.output),0),a.writeUInt8(0,1),a.writeUInt8(this.addressesList.lookupIndex(n.input),2),a.writeBigInt64LE(n.price,3);let s=n.price.toString(16).padStart(64,"0");Buffer.from(s,"hex").copy(a,3);}return a});return Buffer.concat([Buffer.from([e.length]),...t])}serializeTakeTokens(e){let t=0,n=e.map(a=>{let s;return a.output==="any"?(t=1,s=Buffer.alloc(2),s.writeUInt8(this.addressesList.lookupIndex(a.input),0),s.writeUInt8(1,1)):(t+=a.output.length,s=Buffer.concat(a.output.map(r=>{if(r.token==="any"){let o=Buffer.alloc(6);return o.writeUInt8(0,0),o.writeUInt8(r.chainId,1),o.writeUInt8(1,5),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(a.input)]),o])}else {let o=Buffer.alloc(40);o.writeUInt8(0,0),o.writeUInt32LE(r.chainId,1),o.writeUInt8(0,5),o.writeUInt8(this.addressesList.lookupIndex(r.token),6),o.writeUInt8(0,7);let i=r.price.toString(16).padStart(64,"0");return Buffer.from(i,"hex").copy(o,8),Buffer.concat([Buffer.from([this.addressesList.lookupIndex(a.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),this.data.authority?e.push(Buffer.from([1]),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])):e.push(Buffer.from([0]),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([1])):this.data.externalCallHash?e.push(Buffer.from([1]),Buffer.from([0]),this.serializeOptionalBytes(this.data.externalCallHash)):e.push(Buffer.from([0])),this.data.dlnMetadata==="any"?e.push(Buffer.from([1]),Buffer.from([1])):this.data.dlnMetadata?e.push(Buffer.from([1]),Buffer.from([0]),this.serializeShortArray(this.data.dlnMetadata)):e.push(Buffer.from([0])),Buffer.concat(e)}static getId(e,t,n){let a=jsSha3.keccak256(e),s=Buffer.from(a,"hex"),[r]=web3_js.PublicKey.findProgramAddressSync([Buffer.from("intent_id"),t.toBuffer(),s],n);return {hex:`0x${r.toBuffer().toString("hex")}`,buffer:r.toBuffer(),rawHash:s}}};exports.DEFAULT_RECORD_OFFSET=B;exports.IDL=O;exports.Intent=X;exports.IntentsClient=q;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map