@kodiak-finance/orderly-default-solana-adapter 2.8.18 → 2.8.19

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.mjs CHANGED
@@ -1,2 +1,3630 @@
1
- var Ba=Object.defineProperty,Ka=Object.defineProperties;var Oa=Object.getOwnPropertyDescriptors;var He=Object.getOwnPropertySymbols;var Ca=Object.prototype.hasOwnProperty,La=Object.prototype.propertyIsEnumerable;var ue=(a,n,e)=>n in a?Ba(a,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[n]=e,p=(a,n)=>{for(var e in n||(n={}))Ca.call(n,e)&&ue(a,e,n[e]);if(He)for(var e of He(n))La.call(n,e)&&ue(a,e,n[e]);return a},g=(a,n)=>Ka(a,Oa(n));var C=(a,n,e)=>(ue(a,typeof n!="symbol"?n+"":n,e),e);var c=(a,n,e)=>new Promise((s,r)=>{var t=u=>{try{m(e.next(u))}catch(i){r(i)}},o=u=>{try{m(e.throw(u))}catch(i){r(i)}},m=u=>u.done?s(u.value):Promise.resolve(u.value).then(t,o);m((e=e.apply(a,n)).next())});typeof window!="undefined"&&(window.__ORDERLY_VERSION__=window.__ORDERLY_VERSION__||{},window.__ORDERLY_VERSION__["@kodiak-finance/orderly-default-solana-adapter"]="2.7.4");var Ha="2.7.4";import*as Ia from"@noble/ed25519";import{getAccount as an}from"@solana/spl-token";import{WalletAdapterNetwork as nn}from"@solana/wallet-adapter-base";import{clusterApiUrl as tn,Connection as _e,PublicKey as D,Transaction as sn,TransactionInstruction as Be}from"@solana/web3.js";import{encode as rn}from"bs58";import{bytesToHex as on}from"ethereum-cryptography/utils";import{BaseWalletAdapter as un,SimpleDI as mn}from"@kodiak-finance/orderly-core";import{MaxUint256 as dn,ChainNamespace as ln}from"@kodiak-finance/orderly-types";import{BN as ve,Program as ca}from"@coral-xyz/anchor";import{ComputeBudgetProgram as Za,PublicKey as L,SystemProgram as Xa,TransactionMessage as pa,VersionedTransaction as fa}from"@solana/web3.js";import{decode as ya}from"bs58";import{keccak256 as I}from"ethereum-cryptography/keccak";import{bytesToHex as H,hexToBytes as R}from"ethereum-cryptography/utils";import{AbiCoder as N,solidityPackedKeccak256 as x}from"ethers";import{utils as Ja}from"@kodiak-finance/orderly-core";import{DEFAUL_ORDERLY_KEY_SCOPE as $a,LedgerWalletKey as en}from"@kodiak-finance/orderly-types";import{addressToBytes32 as Q}from"@layerzerolabs/lz-v2-utilities";import{PublicKey as S}from"@solana/web3.js";var k=new S("76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6"),b=new S("7a4WjyR8VZ7yZz5XJAKm39BUGn5iT9CKcv2pmG9tdXVH"),U=new S("6doghB248px58JSSwG4qejQ46kFMW4AMj7vzJnWZHNZn"),v=new S("8ahPGPjEbpgGaZx2NV1iG5Shj7TDwvsjkEDcGWjt94TP"),Ne=b,We=b,V=new S("HtEYV4xB4wvsj5fgTkcfuChYpvGYzgzwvNhgDZQNh7wW"),Ue="VaultAuthority",Ve="Broker",Ge="Token",Fe="SolVault",me=Q("0x9Dc724b24146BeDD2dA28b8C4B74126169B8f312"),ze=Q("0x45b6C6266A7A2170617d8A27A50C642fd68b91c4"),Ye=Q("0x5Bf771A65d057e778C5f0Ed52A0003316f94322D"),qe=Q("0xCecAe061aa078e13b5e70D5F9eCee90a3F2B6AeA"),Qe=40200,je=30213,j=new S("BWp8HaYYhiNHekt3zgQhqoCrRftneGxxfgKmCZ6svHN"),Ze=new S("BswrQQoPKAFojTuJutZcBMtigAgTghEH4M8ofn3EG2X2"),Xe=new S("BbGKfxuPwDmu58BjPpd7PMG69TqnZjSpKaLDMgf9E9Dr"),Je=new S("8iq7xCQt3bLdRRn4A46d5GuaXYinBoiAhbe2sUmZVzwg"),de=new S("EYJq9eU4GMRUriUJBgGoZ8YLQBXcWaciXuSsEXE7ieQS"),le=new S("5zBjLor7vEraAt4zp2H82sy9MSqFoDnNa1Lx6EYKTYRZ"),ce=new S("9shwxWDUNhtwkHocsUAmrNAQfBH2DHh4njdAEdHZZkF2"),Z=new S("ErBmAD61mGFKvrFNaTJuxoPwqrS8GgtwtqJTJVjFWx9Q");var pe={version:"0.1.0",name:"solana_vault",instructions:[{name:"setVault",accounts:[{name:"admin",isMut:!0,isSigner:!0},{name:"vaultAuthority",isMut:!0,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetVaultParams"}}]},{name:"deposit",accounts:[{name:"user",isMut:!0,isSigner:!0},{name:"userTokenAccount",isMut:!0,isSigner:!1},{name:"vaultAuthority",isMut:!0,isSigner:!1},{name:"vaultTokenAccount",isMut:!0,isSigner:!1},{name:"depositToken",isMut:!1,isSigner:!1},{name:"peer",isMut:!1,isSigner:!1},{name:"enforcedOptions",isMut:!1,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"allowedBroker",isMut:!1,isSigner:!1},{name:"allowedToken",isMut:!1,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1},{name:"associatedTokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"depositParams",type:{defined:"DepositParams"}},{name:"oappParams",type:{defined:"OAppSendParams"}}],returns:{defined:"MessagingReceipt"}},{name:"depositSol",accounts:[{name:"user",isMut:!0,isSigner:!0},{name:"vaultAuthority",isMut:!0,isSigner:!1},{name:"solVault",isMut:!0,isSigner:!1,docs:["CHECKED: sol_vault is used for SOL deposit"]},{name:"peer",isMut:!1,isSigner:!1},{name:"enforcedOptions",isMut:!1,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"allowedBroker",isMut:!1,isSigner:!1},{name:"allowedToken",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"depositParams",type:{defined:"DepositParams"}},{name:"oappParams",type:{defined:"OAppSendParams"}}],returns:{defined:"MessagingReceipt"}},{name:"initOapp",accounts:[{name:"payer",isMut:!0,isSigner:!0},{name:"oappConfig",isMut:!0,isSigner:!1},{name:"lzReceiveTypes",isMut:!0,isSigner:!1},{name:"accountList",isMut:!0,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"InitOAppParams"}}]},{name:"setAccountList",accounts:[{name:"admin",isMut:!0,isSigner:!0},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"lzReceiveTypes",isMut:!0,isSigner:!1},{name:"accountsList",isMut:!0,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetAccountListParams"}}]},{name:"setManagerRole",accounts:[{name:"owner",isMut:!0,isSigner:!0},{name:"vaultAuthority",isMut:!0,isSigner:!1},{name:"managerRole",isMut:!0,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetManagerRoleParams"}}]},{name:"setBroker",accounts:[{name:"brokerManager",isMut:!0,isSigner:!0},{name:"allowedBroker",isMut:!0,isSigner:!1},{name:"managerRole",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetBrokerParams"}}]},{name:"setWithdrawBroker",accounts:[{name:"brokerManager",isMut:!0,isSigner:!0},{name:"withdrawBroker",isMut:!0,isSigner:!1},{name:"managerRole",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetWithdrawBrokerParams"}}]},{name:"setToken",accounts:[{name:"tokenManager",isMut:!0,isSigner:!0},{name:"allowedToken",isMut:!0,isSigner:!1},{name:"managerRole",isMut:!1,isSigner:!1},{name:"mintAccount",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetTokenParams"}}]},{name:"setWithdrawToken",accounts:[{name:"tokenManager",isMut:!0,isSigner:!0},{name:"withdrawToken",isMut:!0,isSigner:!1},{name:"managerRole",isMut:!1,isSigner:!1},{name:"mintAccount",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetWithdrawTokenParams"}}]},{name:"setOrderDelivery",accounts:[{name:"owner",isMut:!0,isSigner:!0},{name:"vaultAuthority",isMut:!0,isSigner:!1}],args:[{name:"params",type:{defined:"SetOrderDeliveryParams"}}]},{name:"oappQuote",accounts:[{name:"oappConfig",isMut:!1,isSigner:!1},{name:"peer",isMut:!1,isSigner:!1},{name:"enforcedOptions",isMut:!1,isSigner:!1},{name:"vaultAuthority",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"DepositParams"}}],returns:{defined:"MessagingFee"}},{name:"lzReceive",accounts:[{name:"payer",isMut:!0,isSigner:!0},{name:"peer",isMut:!1,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"withdrawBrokerPda",isMut:!1,isSigner:!1},{name:"withdrawTokenPda",isMut:!1,isSigner:!1,docs:["CHECK"]},{name:"tokenMint",isMut:!1,isSigner:!1,docs:["CHECK"]},{name:"receiver",isMut:!0,isSigner:!1,docs:["CHECK"]},{name:"receiverTokenAccount",isMut:!0,isSigner:!1,docs:["UNCHECKED"]},{name:"vaultAuthority",isMut:!0,isSigner:!1},{name:"vaultTokenAccount",isMut:!0,isSigner:!1},{name:"tokenProgram",isMut:!1,isSigner:!1,docs:["CHECKED: sol_vault is used for SOL withdrawal"]},{name:"associatedTokenProgram",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1},{name:"eventAuthority",isMut:!1,isSigner:!1},{name:"program",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"OAppLzReceiveParams"}}]},{name:"lzReceiveTypes",accounts:[{name:"oappConfig",isMut:!1,isSigner:!1},{name:"accountList",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"OAppLzReceiveParams"}}],returns:{vec:{defined:"oapp::endpoint_cpi::LzAccount"}}},{name:"setRateLimit",accounts:[{name:"admin",isMut:!1,isSigner:!0},{name:"peer",isMut:!0,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetRateLimitParams"}}]},{name:"setDelegate",accounts:[{name:"admin",isMut:!1,isSigner:!0},{name:"oappConfig",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetDelegateParams"}}]},{name:"transferAdmin",accounts:[{name:"admin",isMut:!1,isSigner:!0},{name:"oappConfig",isMut:!0,isSigner:!1}],args:[{name:"params",type:{defined:"TransferAdminParams"}}]},{name:"setPeer",accounts:[{name:"admin",isMut:!0,isSigner:!0},{name:"peer",isMut:!0,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetPeerParams"}}]},{name:"setEnforcedOptions",accounts:[{name:"admin",isMut:!0,isSigner:!0},{name:"enforcedOptions",isMut:!0,isSigner:!1},{name:"oappConfig",isMut:!1,isSigner:!1},{name:"systemProgram",isMut:!1,isSigner:!1}],args:[{name:"params",type:{defined:"SetEnforcedOptionsParams"}}]}],accounts:[{name:"enforcedOptions",type:{kind:"struct",fields:[{name:"send",type:"bytes"},{name:"sendAndCall",type:"bytes"},{name:"bump",type:"u8"}]}},{name:"oAppConfig",type:{kind:"struct",fields:[{name:"endpointProgram",type:"publicKey"},{name:"bump",type:"u8"},{name:"admin",type:"publicKey"}]}},{name:"oAppLzReceiveTypesAccounts",type:{kind:"struct",fields:[{name:"oappConfig",type:"publicKey"},{name:"accountList",type:"publicKey"}]}},{name:"accountList",type:{kind:"struct",fields:[{name:"bump",type:"u8"},{name:"woofiProPda",type:"publicKey"},{name:"withdrawUsdcPda",type:"publicKey"},{name:"usdcMint",type:"publicKey"},{name:"withdrawUsdtPda",type:"publicKey"},{name:"usdtMint",type:"publicKey"},{name:"withdrawWsolPda",type:"publicKey"},{name:"wsolMint",type:"publicKey"}]}},{name:"peer",type:{kind:"struct",fields:[{name:"address",type:{array:["u8",32]}},{name:"rateLimiter",type:{option:{defined:"RateLimiter"}}},{name:"bump",type:"u8"}]}},{name:"allowedBroker",type:{kind:"struct",fields:[{name:"brokerHash",type:{array:["u8",32]}},{name:"allowed",type:"bool"},{name:"bump",type:"u8"}]}},{name:"allowedToken",type:{kind:"struct",fields:[{name:"mintAccount",type:"publicKey"},{name:"tokenHash",type:{array:["u8",32]}},{name:"tokenDecimals",type:"u8"},{name:"allowed",type:"bool"},{name:"bump",type:"u8"}]}},{name:"managerRole",type:{kind:"struct",fields:[{name:"roleHash",type:{array:["u8",32]}},{name:"allowed",type:"bool"},{name:"bump",type:"u8"}]}},{name:"vaultAuthority",type:{kind:"struct",fields:[{name:"bump",docs:["Bump seed for the vault authority PDA"],type:"u8"},{name:"owner",type:"publicKey"},{name:"depositNonce",type:"u64"},{name:"orderDelivery",type:"bool"},{name:"inboundNonce",type:"u64"},{name:"dstEid",type:"u32"},{name:"solChainId",type:"u128"}]}},{name:"withdrawBroker",type:{kind:"struct",fields:[{name:"brokerHash",type:{array:["u8",32]}},{name:"brokerIndex",type:"u16"},{name:"allowed",type:"bool"},{name:"bump",type:"u8"}]}},{name:"withdrawToken",type:{kind:"struct",fields:[{name:"mintAccount",type:"publicKey"},{name:"tokenHash",type:{array:["u8",32]}},{name:"tokenDecimals",type:"u8"},{name:"tokenIndex",type:"u8"},{name:"allowed",type:"bool"},{name:"bump",type:"u8"}]}}],types:[{name:"VaultDepositParams",type:{kind:"struct",fields:[{name:"accountId",type:{array:["u8",32]}},{name:"brokerHash",type:{array:["u8",32]}},{name:"userAddress",type:{array:["u8",32]}},{name:"tokenHash",type:{array:["u8",32]}},{name:"srcChainId",type:"u128"},{name:"tokenAmount",type:"u128"},{name:"srcChainDepositNonce",type:"u64"}]}},{name:"LzMessage",type:{kind:"struct",fields:[{name:"msgType",type:"u8"},{name:"payload",type:"bytes"}]}},{name:"AccountWithdrawSol",type:{kind:"struct",fields:[{name:"sender",type:{array:["u8",32]}},{name:"receiver",type:{array:["u8",32]}},{name:"brokerIndex",type:"u16"},{name:"tokenIndex",type:"u8"},{name:"tokenAmount",type:"u64"},{name:"fee",type:"u64"},{name:"chainId",type:"u64"},{name:"withdrawNonce",type:"u64"}]}},{name:"VaultWithdrawParams",type:{kind:"struct",fields:[{name:"accountId",type:{array:["u8",32]}},{name:"sender",type:{array:["u8",32]}},{name:"receiver",type:{array:["u8",32]}},{name:"brokerHash",type:{array:["u8",32]}},{name:"tokenHash",type:{array:["u8",32]}},{name:"tokenAmount",type:"u64"},{name:"fee",type:"u128"},{name:"chainId",type:"u128"},{name:"withdrawNonce",type:"u64"}]}},{name:"InitOAppParams",type:{kind:"struct",fields:[{name:"admin",type:"publicKey"},{name:"accountList",type:"publicKey"},{name:"endpointProgram",type:{option:"publicKey"}}]}},{name:"OAppLzReceiveParams",type:{kind:"struct",fields:[{name:"srcEid",type:"u32"},{name:"sender",type:{array:["u8",32]}},{name:"nonce",type:"u64"},{name:"guid",type:{array:["u8",32]}},{name:"message",type:"bytes"},{name:"extraData",type:"bytes"}]}},{name:"MessagingFee",type:{kind:"struct",fields:[{name:"nativeFee",type:"u64"},{name:"lzTokenFee",type:"u64"}]}},{name:"SetAccountListParams",type:{kind:"struct",fields:[{name:"woofiProPda",type:"publicKey"},{name:"withdrawUsdcPda",type:"publicKey"},{name:"usdcMint",type:"publicKey"},{name:"withdrawUsdtPda",type:"publicKey"},{name:"usdtMint",type:"publicKey"},{name:"withdrawWsolPda",type:"publicKey"},{name:"wsolMint",type:"publicKey"}]}},{name:"SetDelegateParams",type:{kind:"struct",fields:[{name:"delegate",type:"publicKey"}]}},{name:"SetEnforcedOptionsParams",type:{kind:"struct",fields:[{name:"dstEid",type:"u32"},{name:"send",type:"bytes"},{name:"sendAndCall",type:"bytes"}]}},{name:"SetPeerParams",type:{kind:"struct",fields:[{name:"dstEid",type:"u32"},{name:"peer",type:{array:["u8",32]}}]}},{name:"SetRateLimitParams",type:{kind:"struct",fields:[{name:"dstEid",type:"u32"},{name:"refillPerSecond",type:{option:"u64"}},{name:"capacity",type:{option:"u64"}},{name:"enabled",type:"bool"}]}},{name:"TransferAdminParams",type:{kind:"struct",fields:[{name:"admin",type:"publicKey"}]}},{name:"DepositParams",type:{kind:"struct",fields:[{name:"accountId",type:{array:["u8",32]}},{name:"brokerHash",type:{array:["u8",32]}},{name:"tokenHash",type:{array:["u8",32]}},{name:"userAddress",type:{array:["u8",32]}},{name:"tokenAmount",type:"u64"}]}},{name:"OAppSendParams",type:{kind:"struct",fields:[{name:"nativeFee",type:"u64"},{name:"lzTokenFee",type:"u64"}]}},{name:"SetBrokerParams",type:{kind:"struct",fields:[{name:"brokerManagerRole",type:{array:["u8",32]}},{name:"brokerHash",type:{array:["u8",32]}},{name:"allowed",type:"bool"}]}},{name:"SetManagerRoleParams",type:{kind:"struct",fields:[{name:"roleHash",type:{array:["u8",32]}},{name:"managerAddress",type:"publicKey"},{name:"allowed",type:"bool"}]}},{name:"SetOrderDeliveryParams",type:{kind:"struct",fields:[{name:"orderDelivery",type:"bool"},{name:"nonce",type:"u64"}]}},{name:"SetTokenParams",type:{kind:"struct",fields:[{name:"tokenManagerRole",type:{array:["u8",32]}},{name:"mintAccount",type:"publicKey"},{name:"tokenHash",type:{array:["u8",32]}},{name:"allowed",type:"bool"}]}},{name:"SetVaultParams",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"depositNonce",type:"u64"},{name:"orderDelivery",type:"bool"},{name:"inboundNonce",type:"u64"},{name:"dstEid",type:"u32"},{name:"solChainId",type:"u128"}]}},{name:"SetWithdrawBrokerParams",type:{kind:"struct",fields:[{name:"brokerManagerRole",type:{array:["u8",32]}},{name:"brokerHash",type:{array:["u8",32]}},{name:"brokerIndex",type:"u16"},{name:"allowed",type:"bool"}]}},{name:"SetWithdrawTokenParams",type:{kind:"struct",fields:[{name:"tokenManagerRole",type:{array:["u8",32]}},{name:"tokenHash",type:{array:["u8",32]}},{name:"tokenIndex",type:"u8"},{name:"allowed",type:"bool"}]}},{name:"RateLimiter",type:{kind:"struct",fields:[{name:"capacity",type:"u64"},{name:"tokens",type:"u64"},{name:"refillPerSecond",type:"u64"},{name:"lastRefillTime",type:"u64"}]}},{name:"OAppError",type:{kind:"enum",variants:[{name:"Unauthorized"},{name:"InvalidSender"},{name:"InvalidReceiver"},{name:"InvalidOptions"},{name:"InvalidEndpointProgram"},{name:"RateLimitExceeded"},{name:"WithdrawFailed"},{name:"InvalidInboundNonce"},{name:"InvalidReceiverTokenAccount"},{name:"InvalidAdminTokenAccount"},{name:"InvalidMessageType"},{name:"InvalidTokenIndex"}]}},{name:"MsgType",type:{kind:"enum",variants:[{name:"Deposit"},{name:"Withdraw"},{name:"RebalanceBurn"},{name:"RebalanceMint"}]}}],events:[{name:"SetAllowedBroker",fields:[{name:"brokerHash",type:{array:["u8",32]},index:!1}]},{name:"ResetAllowedBroker",fields:[{name:"brokerHash",type:{array:["u8",32]},index:!1}]},{name:"SetAllowedToken",fields:[{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"mintAccount",type:"publicKey",index:!1}]},{name:"ResetAllowedToken",fields:[{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"mintAccount",type:"publicKey",index:!1}]},{name:"SetWithdrawTokenIndex",fields:[{name:"tokenIndex",type:"u8",index:!1},{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"mintAccount",type:"publicKey",index:!1}]},{name:"ResetWithdrawTokenIndex",fields:[{name:"tokenIndex",type:"u8",index:!1},{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"mintAccount",type:"publicKey",index:!1}]},{name:"SetWithdrawBrokerEvent",fields:[{name:"brokerHash",type:{array:["u8",32]},index:!1},{name:"brokerIndex",type:"u16",index:!1}]},{name:"ResetWithdrawBrokerEvent",fields:[{name:"brokerHash",type:{array:["u8",32]},index:!1},{name:"brokerIndex",type:"u16",index:!1}]},{name:"SetManager",fields:[{name:"roleHash",type:{array:["u8",32]},index:!1},{name:"managerAddress",type:"publicKey",index:!1},{name:"allowed",type:"bool",index:!1}]},{name:"Deposited",fields:[{name:"user",type:"publicKey",index:!1},{name:"amount",type:"u64",index:!1}]},{name:"Withdrawn",fields:[{name:"user",type:"publicKey",index:!1},{name:"amount",type:"u64",index:!1}]},{name:"CreatedATA",fields:[{name:"accountId",type:{array:["u8",32]},index:!1},{name:"receiver",type:{array:["u8",32]},index:!1},{name:"receiverTokenAccount",type:{array:["u8",32]},index:!1},{name:"withdrawNonce",type:"u64",index:!1}]},{name:"VaultDeposited",fields:[{name:"accountId",type:{array:["u8",32]},index:!1},{name:"brokerHash",type:{array:["u8",32]},index:!1},{name:"userAddress",type:{array:["u8",32]},index:!1},{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"srcChainId",type:"u128",index:!1},{name:"tokenAmount",type:"u64",index:!1},{name:"srcChainDepositNonce",type:"u64",index:!1}]},{name:"VaultWithdrawn",fields:[{name:"accountId",type:{array:["u8",32]},index:!1},{name:"sender",type:{array:["u8",32]},index:!1},{name:"receiver",type:{array:["u8",32]},index:!1},{name:"brokerHash",type:{array:["u8",32]},index:!1},{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"tokenAmount",type:"u64",index:!1},{name:"fee",type:"u128",index:!1},{name:"chainId",type:"u128",index:!1},{name:"withdrawNonce",type:"u64",index:!1}]},{name:"FrozenWithdrawn",fields:[{name:"accountId",type:{array:["u8",32]},index:!1},{name:"sender",type:{array:["u8",32]},index:!1},{name:"receiver",type:{array:["u8",32]},index:!1},{name:"brokerHash",type:{array:["u8",32]},index:!1},{name:"tokenHash",type:{array:["u8",32]},index:!1},{name:"tokenAmount",type:"u64",index:!1},{name:"fee",type:"u128",index:!1},{name:"chainId",type:"u128",index:!1},{name:"withdrawNonce",type:"u64",index:!1}]},{name:"OAppSent",fields:[{name:"guid",type:{array:["u8",32]},index:!1},{name:"dstEid",type:"u32",index:!1}]},{name:"OAppReceived",fields:[{name:"guid",type:{array:["u8",32]},index:!1},{name:"srcEid",type:"u32",index:!1}]}],errors:[{code:6e3,name:"InsufficientFunds",msg:"Deposited funds are insufficient for withdrawal"},{code:6001,name:"UserInfoBelongsToAnotherUser",msg:"User info pda belongs to another user"},{code:6002,name:"BrokerNotAllowed",msg:"Broker is not allowed"},{code:6003,name:"TokenNotAllowed",msg:"Token is not allowed"},{code:6004,name:"InvalidAccountId",msg:"AccountId is invalid"},{code:6005,name:"InvalidVaultOwner",msg:"Vault owner is not the same as the payer"},{code:6006,name:"ManagerRoleNotAllowed",msg:"Manager role is not allowed"}]};import{DVN_CONFIG_SEED as Na,ENDPOINT_SEED as Wa,ENFORCED_OPTIONS_SEED as Ua,EVENT_SEED as $e,EXECUTOR_CONFIG_SEED as Va,LZ_RECEIVE_TYPES_SEED as kn,MESSAGE_LIB_SEED as X,NONCE_SEED as Ga,OAPP_SEED as Fa,PEER_SEED as za,PRICE_FEED_SEED as Ya,SEND_CONFIG_SEED as ea,SEND_LIBRARY_CONFIG_SEED as aa,ULN_SEED as qa}from"@layerzerolabs/lz-solana-sdk-v2";import{getAssociatedTokenAddressSync as Qa}from"@solana/spl-token";import{PublicKey as l}from"@solana/web3.js";var G=(a,n)=>Qa(a,n,!0);function fe(a){return l.findProgramAddressSync([Buffer.from(Ue,"utf8")],a)[0]}function na(a){return l.findProgramAddressSync([Buffer.from(Fe,"utf8")],a)[0]}function ta(a,n){let e=Array.from(Buffer.from(n.slice(2),"hex"));return l.findProgramAddressSync([Buffer.from(Ve,"utf8"),Buffer.from(e)],a)[0]}function sa(a,n){let e=Array.from(Buffer.from(n.slice(2),"hex"));return l.findProgramAddressSync([Buffer.from(Ge,"utf8"),Buffer.from(e)],a)[0]}function ye(a){return l.findProgramAddressSync([Buffer.from(Fa,"utf8")],a)[0]}function ge(a,n,e){let s=Buffer.alloc(4);return s.writeUInt32BE(e),l.findProgramAddressSync([Buffer.from(za,"utf8"),n.toBuffer(),s],a)[0]}function Se(a,n,e){let s=Buffer.alloc(4);return s.writeUInt32BE(e),l.findProgramAddressSync([Buffer.from(Ua,"utf8"),n.toBuffer(),s],a)[0]}function ra(){return l.findProgramAddressSync([Buffer.from(X,"utf8")],b)[0]}function be(a,n){let e=Buffer.alloc(4);return e.writeUInt32BE(n),l.findProgramAddressSync([Buffer.from(aa,"utf8"),a.toBuffer(),e],k)[0]}function ke(a){let n=Buffer.alloc(4);return n.writeUInt32BE(a),l.findProgramAddressSync([Buffer.from(aa,"utf8"),n],k)[0]}function ia(a){return l.findProgramAddressSync([Buffer.from(X,"utf8"),a.toBuffer()],k)[0]}function Ae(){return l.findProgramAddressSync([Buffer.from(Wa,"utf8")],k)[0]}function ja(a){let n=me;return a.toBase58()===de.toBase58()&&(n=me),a.toBase58()===le.toBase58()&&(n=ze),a.toBase58()===ce.toBase58()&&(n=Ye),a.toBase58()===Z.toBase58()&&(n=qe),n}function Pe(a,n,e){let s=Buffer.alloc(4),r=ja(a);return s.writeUInt32BE(e),l.findProgramAddressSync([Buffer.from(Ga,"utf8"),n.toBuffer(),s,r],k)[0]}function oa(){return l.findProgramAddressSync([Buffer.from($e,"utf8")],k)[0]}function ua(){return l.findProgramAddressSync([Buffer.from(qa,"utf8")],b)[0]}function he(a,n){let e=Buffer.alloc(4);return e.writeUInt32BE(n),l.findProgramAddressSync([Buffer.from(ea,"utf8"),e,a.toBuffer()],b)[0]}function Me(a){let n=Buffer.alloc(4);return n.writeUInt32BE(a),l.findProgramAddressSync([Buffer.from(ea,"utf8"),n],Ne)[0]}function ma(){return l.findProgramAddressSync([Buffer.from($e,"utf8")],b)[0]}function we(){return l.findProgramAddressSync([Buffer.from(Va,"utf8")],U)[0]}function Ie(){return l.findProgramAddressSync([Buffer.from(Ya,"utf8")],v)[0]}function Ee(){return l.findProgramAddressSync([Buffer.from(Na,"utf8")],V)[0]}function xe(a){return a.toBase58()===Z.toBase58()?je:Qe}function De(a){return a.toBase58()===de.toBase58()?(console.log("DEV_LOOKUP_TABLE_ADDRESS: ",j.toBase58()),j):a.toBase58()===le.toBase58()?Ze:a.toBase58()===ce.toBase58()?Xe:a.toBase58()===Z.toBase58()?Je:j}function da(a){return l.findProgramAddressSync([Buffer.from(X,"utf8")],a||b)[0]}function la(a,n){return l.findProgramAddressSync([Buffer.from(X,"utf8"),a.toBytes()],n||k)[0]}function Te(a,n){return c(this,null,function*(){return(yield a.getAddressLookupTable(n)).value})}function ga(a){let{publicKey:n,brokerId:e,expiration:s=365,timestamp:r=Date.now(),scope:t,tag:o,chainId:m,subAccountId:u}=a,i=p(p({brokerId:e,chainType:"SOL",orderlyKey:n,scope:t||$a,chainId:m,timestamp:r,expiration:r+1e3*60*60*24*s},typeof o!="undefined"?{tag:o}:{}),typeof u!="undefined"?{subAccountId:u}:{}),d=x(["string"],[i.brokerId]),A=x(["string"],[i.orderlyKey]),h=x(["string"],[i.scope]),y=N.defaultAbiCoder(),M=I(R(y.encode(["bytes32","bytes32","bytes32","uint256","uint256","uint256"],[d,A,h,i.chainId,i.timestamp,i.expiration]))),P=H(M),T=new TextEncoder().encode(P);return[i,T]}function Sa(a){let{chainId:n,registrationNonce:e,brokerId:s,timestamp:r}=a,t={brokerId:s,chainId:n,timestamp:r,registrationNonce:e},o=x(["string"],[t.brokerId]),m=N.defaultAbiCoder(),u=I(R(m.encode(["bytes32","uint256","uint256","uint256"],[o,t.chainId,t.timestamp,t.registrationNonce]))),i=H(u),d=new TextEncoder().encode(i);return[t,d]}function ba(a){let{chainId:n,receiver:e,token:s,amount:r,nonce:t}=a,o={chainId:n,receiver:e,token:s,amount:r,transferNonce:t,chainType:"SOL"},m=x(["string"],[o.token]),u=N.defaultAbiCoder(),i=I(R(u.encode(["bytes32","bytes32","uint256","uint64","uint256"],[o.receiver,m,o.amount,o.transferNonce,n]))),d=H(i),A=new TextEncoder().encode(d);return[o,A]}function ka(a){return c(this,null,function*(){let{payloadType:n,nonce:e,receiver:s,amount:r,vaultId:t,token:o,dexBrokerId:m,chainId:u}=a,i={payloadType:n,nonce:e,receiver:s,amount:r,vaultId:t,token:o,dexBrokerId:m,chainId:u},d;d=ya(s),new Uint8Array(32).set(d);let y=R(t),M=I(new TextEncoder().encode(o)),P=I(new TextEncoder().encode(m)),T=N.defaultAbiCoder(),_=I(R(T.encode(["uint8","uint256","bytes32","uint256","bytes32","bytes32","bytes32","uint256"],[n,e,d,r,y,M,P,u]))),B=H(_),f=new TextEncoder().encode(B);return[i,f]})}function Aa(a){let{chainId:n,receiver:e,token:s,amount:r,nonce:t,brokerId:o}=a,m=Date.now(),u={brokerId:o,chainId:n,receiver:e,token:s,amount:r,withdrawNonce:t,timestamp:m,chainType:"SOL"},i=x(["string"],[u.brokerId]),d=x(["string"],[u.token]),A=I(Buffer.from("Orderly Network")),h=N.defaultAbiCoder(),y=I(R(h.encode(["bytes32","bytes32","uint256","bytes32","uint256","uint64","uint64","bytes32"],[i,d,n,ya(u.receiver),u.amount,u.withdrawNonce,m,A]))),M=H(y),P=new TextEncoder().encode(M);return[u,P]}function Pa(a){let{settlePnlNonce:n,brokerId:e,chainId:s,timestamp:r}=a,t={brokerId:e,chainId:s,timestamp:r,chainType:"SOL",settleNonce:n},o=x(["string"],[e]),m=N.defaultAbiCoder(),u=I(R(m.encode(["bytes32","uint256","uint64","uint64"],[o,t.chainId,t.settleNonce,t.timestamp]))),i=H(u),d=new TextEncoder().encode(i);return[t,d]}function Re(r){return c(this,arguments,function*({vaultAddress:a,userAddress:n,connection:e,depositData:s}){console.log("-- vaultAddress",a);let t=new L(a),o=xe(t),m=new ca(pe,t,{connection:e}),u=new L(n),i=ye(t),d=ge(t,i,o),A=Se(t,i,o),h=be(i,o),y=ke(o),M=Ae(),P=Pe(t,i,o),T=he(i,o),_=Me(o),B=we(),f=Ie(),w=Ee(),W=da(b),F=la(W),J=fe(t),$=ha(n,s),ee=yield m.methods.oappQuote($).accounts({oappConfig:i,peer:d,enforcedOptions:A,vaultAuthority:J}).remainingAccounts([{pubkey:k,isWritable:!1,isSigner:!1},{pubkey:b,isWritable:!1,isSigner:!1},{pubkey:h,isWritable:!1,isSigner:!1},{pubkey:y,isWritable:!1,isSigner:!1},{pubkey:F,isWritable:!1,isSigner:!1},{pubkey:M,isWritable:!1,isSigner:!1},{pubkey:P,isWritable:!1,isSigner:!1},{pubkey:W,isWritable:!1,isSigner:!1},{pubkey:T,isWritable:!1,isSigner:!1},{pubkey:_,isWritable:!1,isSigner:!1},{pubkey:U,isWritable:!1,isSigner:!1},{pubkey:B,isWritable:!1,isSigner:!1},{pubkey:v,isWritable:!1,isSigner:!1},{pubkey:f,isWritable:!1,isSigner:!1},{pubkey:V,isWritable:!1,isSigner:!1},{pubkey:w,isWritable:!1,isSigner:!1},{pubkey:v,isWritable:!1,isSigner:!1},{pubkey:f,isWritable:!1,isSigner:!1}]).instruction(),ae=yield e.getLatestBlockhash(),ne=De(t),z=yield Te(e,ne);if(!z)throw console.log("-- lookup table account error"),new Error("-- lookup table account error");let te=new pa({payerKey:u,recentBlockhash:ae.blockhash,instructions:[ee]}).compileToV0Message([z]),se=new fa(te),E=yield e.simulateTransaction(se);if(console.log("-- feeRes",E),E.value.err){let O=typeof E.value.err=="object"?JSON.stringify(E.value.err):E.value.err;throw O.toString().includes("AccountNotFound")?new Error("Error: Account gas is insufficient."):new Error(`Error: ${O}`)}let Y=`Program return: ${m.programId} `,q=E.value.logs.find(O=>O.startsWith(Y));if(!q)throw new Error("Error: get deposit fee error");let re=q.slice(Y.length),K=Buffer.from(re,"base64");return console.log(K.readBigUInt64LE(0),K.readBigUInt64LE(1)),K.readBigUInt64LE(0)})}var ha=(a,n)=>{let e=n.brokerHash,s=Array.from(Buffer.from(e.slice(2),"hex")),r=n.tokenHash,t=Array.from(Buffer.from(r.slice(2),"hex")),o=n.accountId,m=Array.from(Buffer.from(o.slice(2),"hex")),u=new L(a);return{accountId:m,brokerHash:s,tokenHash:t,userAddress:Array.from(u.toBuffer()),tokenAmount:new ve(n.tokenAmount)}};function Ma(t){return c(this,arguments,function*({vaultAddress:a,userAddress:n,connection:e,sendTransaction:s,depositData:r}){let o=r.brokerHash,m=r.tokenHash,u=Ja.parseTokenHash("SOL"),i=m.toLowerCase()===u.toLowerCase();console.log("-- vault address",a);let d=new L(a),A=new ca(pe,d,{connection:e}),h=new L(r.tokenAddress),y=new L(n),M=G(h,y),P=fe(d),T=G(h,P),_=ta(d,o),B=sa(d,m),f=ye(d);console.log("-- oappconfig pda",f.toBase58());let w=xe(d),W=ge(d,f,w),F=Se(d,f,w),J=ra(),$=be(f,w),ee=ke(w),ae=ia(J),ne=Ae(),z=Pe(d,f,w),te=oa(),se=ua(),E=he(f,w),Y=Me(w),q=ma(),re=we(),K=Ie(),O=Ee(),ie=ha(n,r),Oe=()=>[{isSigner:!1,isWritable:!1,pubkey:k},{isSigner:!1,isWritable:!1,pubkey:f},{isSigner:!1,isWritable:!1,pubkey:b},{isSigner:!1,isWritable:!1,pubkey:$},{isSigner:!1,isWritable:!1,pubkey:ee},{isSigner:!1,isWritable:!1,pubkey:ae},{isSigner:!1,isWritable:!1,pubkey:ne},{isSigner:!1,isWritable:!0,pubkey:z},{isSigner:!1,isWritable:!1,pubkey:te},{isSigner:!1,isWritable:!1,pubkey:k},{isSigner:!1,isWritable:!1,pubkey:se},{isSigner:!1,isWritable:!1,pubkey:E},{isSigner:!1,isWritable:!1,pubkey:Y},{isSigner:!0,isWritable:!1,pubkey:y},{isSigner:!1,isWritable:!1,pubkey:We},{isSigner:!1,isWritable:!1,pubkey:Xa.programId},{isSigner:!1,isWritable:!1,pubkey:q},{isSigner:!1,isWritable:!1,pubkey:b},{isSigner:!1,isWritable:!1,pubkey:U},{isSigner:!1,isWritable:!0,pubkey:re},{isSigner:!1,isWritable:!1,pubkey:v},{isSigner:!1,isWritable:!1,pubkey:K},{isSigner:!1,isWritable:!1,pubkey:V},{isSigner:!1,isWritable:!0,pubkey:O},{isSigner:!1,isWritable:!1,pubkey:v},{isSigner:!1,isWritable:!1,pubkey:K}],Ea=yield Re({vaultAddress:a,userAddress:n,connection:e,depositData:r}),oe={nativeFee:new ve(Ea.toString()),lzTokenFee:new ve(0)};console.log("--- value params",{vaultDepositParams:ie,sendParam:oe});let xa=i?yield A.methods.depositSol(ie,oe).accounts({solVault:na(d),vaultAuthority:P,user:y,peer:W,enforcedOptions:F,oappConfig:f,allowedBroker:_,allowedToken:B}).remainingAccounts(Oe()).instruction():yield A.methods.deposit(ie,oe).accounts({userTokenAccount:M,vaultAuthority:P,vaultTokenAccount:T,depositToken:h,user:y,peer:W,enforcedOptions:F,oappConfig:f,allowedBroker:_,allowedToken:B}).remainingAccounts(Oe()).instruction(),Da=De(d),Ce=yield Te(e,Da);if(!Ce){console.log("-- lookup table account error");return}let Ta=Za.setComputeUnitLimit({units:4e5}),va=yield e.getLatestBlockhash(),Ra=new pa({payerKey:y,recentBlockhash:va.blockhash,instructions:[xa,Ta]}).compileToV0Message([Ce]),_a=new fa(Ra),Le=yield s(_a,e);return console.log("res",Le),Le})}function wa(a){let n=window.localStorage.getItem(en);if(!n)return!1;let e=JSON.parse(n!=null?n:"[]");return console.log("-- addressArr",e),!!e.includes(a)}var Ke=class extends un{constructor(){super();C(this,"chainNamespace",ln.solana);C(this,"_address");C(this,"_chainId");C(this,"_provider");C(this,"_connection")}get address(){return this._address}get chainId(){return this._chainId}set chainId(e){this._chainId=e}get connection(){if(this._connection)return this._connection;if(this._provider.rpcUrl)return this._connection=new _e(this._provider.rpcUrl,{commitment:"confirmed"}),this._connection;if(this._provider.network===nn.Devnet)return this._connection=new _e(tn(this._provider.network),{commitment:"confirmed"}),this._connection;let e=mn.get("account"),s="/v1/solana-rpc-proxy";return this._connection=new _e(`${e.apiBaseUrl}${s}`,{commitment:"confirmed",fetchMiddleware:(r,t,o)=>c(this,null,function*(){let m={url:s,method:t==null?void 0:t.method,data:JSON.parse(t==null?void 0:t.body)},u=yield this.signMessageByOrderlyKey(m);for(let i of Object.keys(u))(t==null?void 0:t.headers)[i]=u[i];return o(r,t)})}),this._connection}setConfig(e){this._address=e.address,this._chainId=e.chain.id,e.provider&&(this._provider=e.provider)}lifecycleName(e,s){console.log("lifecycle",e,s)}active(e){this.setConfig(e),this.lifecycleName("active",e)}deactivate(){this.lifecycleName("deactivate",{})}update(e){this.lifecycleName("update",e),this.setConfig(e)}generateSecretKey(){let e,s;do e=Ia.utils.randomPrivateKey(),s=rn(e);while(s.length!==44);return s}uint8ArrayToHexString(e){return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("")}signMessage(e){return c(this,null,function*(){if(wa(this._address)){let t=new sn;t.add(new Be({keys:[],programId:new D("ComputeBudget111111111111111111111111111111"),data:new Uint8Array([3,0,0,0,0,0,0,0,0])})),t.add(new Be({keys:[],programId:new D("ComputeBudget111111111111111111111111111111"),data:new Uint8Array([2,0,0,0,0])})),t.add(new Be({keys:[],programId:new D("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),data:e}));let o=new D(this.address);t.feePayer=o;let m=new Uint8Array(32).fill(0);t.recentBlockhash=new D(m).toString();let i=(yield this._provider.signTransaction(t)).signatures[0].signature;if(i)return this.uint8ArrayToHexString(i);throw console.log("-- sign message error",i),new Error("Unsupported signature")}let r=yield this._provider.signMessage(e);return"0x"+on(r)})}generateRegisterAccountMessage(e){return c(this,null,function*(){let[s,r]=Sa(g(p({},e),{chainId:this.chainId})),t=yield this.signMessage(r);return{message:g(p({},s),{chainType:"SOL"}),signatured:t}})}generateWithdrawMessage(e){return c(this,null,function*(){let[s,r]=Aa(g(p({},e),{chainId:this.chainId})),t=yield this.signMessage(r);return{message:g(p({},s),{chainType:"SOL"}),domain:{name:"",version:"",chainId:this.chainId,verifyingContract:e.verifyContract},signatured:t}})}generateInternalTransferMessage(e){return c(this,null,function*(){let[s,r]=ba(g(p({},e),{chainId:this.chainId})),t=yield this.signMessage(r);return{message:g(p({},s),{chainType:"SOL"}),domain:{name:"",version:"",chainId:this.chainId,verifyingContract:e.verifyContract},signatured:t}})}generateAddOrderlyKeyMessage(e){return c(this,null,function*(){let[s,r]=ga(g(p({},e),{chainId:this.chainId})),t=yield this.signMessage(r);return{message:g(p({},s),{chainType:"SOL"}),signatured:t}})}generateSettleMessage(e){return c(this,null,function*(){let[s,r]=Pa(g(p({},e),{chainId:this.chainId})),t=yield this.signMessage(r);return{message:g(p({},s),{chainType:"SOL"}),domain:{name:"",version:"",chainId:this.chainId,verifyingContract:e.verifyContract},signatured:t}})}generateDexRequestMessage(e){return c(this,null,function*(){let[s,r]=yield ka(g(p({},e),{chainId:this.chainId})),t=yield this.signMessage(r);return{message:g(p({},e),{chainType:"SOL"}),signatured:t,domain:e.domain}})}getBalance(){return c(this,null,function*(){let e=new D(this.address),s=yield this.connection.getBalance(e);return BigInt(s)})}call(e,s,r,t){return c(this,null,function*(){if(s==="balanceOf"){let o=new D(e),m=new D(this._address),u=G(o,m),i=this.connection;return(yield an(i,u,"confirmed")).amount}return s==="allowance"?dn:BigInt(0)})}sendTransaction(e,s,r,t){return c(this,null,function*(){if(console.log("-- solanan sendTransaction",{contractAddress:e,method:s,payload:r,options:t}),s==="deposit")return Ma({vaultAddress:e,userAddress:this._address,connection:this.connection,depositData:r.data[0],sendTransaction:this._provider.sendTransaction})})}callOnChain(e,s,r,t,o){return c(this,null,function*(){return console.log("-- params ",{chain:e,address:s,method:r,params:t}),r==="getDepositFee"?Re({vaultAddress:s,userAddress:this._address,connection:this.connection,depositData:t[1]}):0})}pollTransactionReceiptWithBackoff(e,s,r,t){return c(this,null,function*(){return Promise.resolve({status:1})})}};export{Ke as DefaultSolanaWalletAdapter,Ha as version};
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+ var __async = (__this, __arguments, generator) => {
25
+ return new Promise((resolve, reject) => {
26
+ var fulfilled = (value) => {
27
+ try {
28
+ step(generator.next(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var rejected = (value) => {
34
+ try {
35
+ step(generator.throw(value));
36
+ } catch (e) {
37
+ reject(e);
38
+ }
39
+ };
40
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
41
+ step((generator = generator.apply(__this, __arguments)).next());
42
+ });
43
+ };
44
+
45
+ // src/version.ts
46
+ if (typeof window !== "undefined") {
47
+ window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
48
+ window.__ORDERLY_VERSION__["@kodiak-finance/orderly-default-solana-adapter"] = "2.7.4";
49
+ }
50
+ var version_default = "2.7.4";
51
+
52
+ // src/walletAdapter.ts
53
+ import * as ed from "@noble/ed25519";
54
+ import { getAccount } from "@solana/spl-token";
55
+ import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
56
+ import {
57
+ clusterApiUrl,
58
+ Connection as Connection3,
59
+ PublicKey as PublicKey4,
60
+ Transaction,
61
+ TransactionInstruction
62
+ } from "@solana/web3.js";
63
+ import { encode as bs58encode } from "bs58";
64
+ import { bytesToHex as bytesToHex2 } from "ethereum-cryptography/utils";
65
+ import {
66
+ BaseWalletAdapter,
67
+ SimpleDI
68
+ } from "@kodiak-finance/orderly-core";
69
+ import { MaxUint256, ChainNamespace } from "@kodiak-finance/orderly-types";
70
+
71
+ // src/helper.ts
72
+ import { BN, Program } from "@coral-xyz/anchor";
73
+ import {
74
+ ComputeBudgetProgram,
75
+ PublicKey as PublicKey3,
76
+ SystemProgram,
77
+ TransactionMessage,
78
+ VersionedTransaction
79
+ } from "@solana/web3.js";
80
+ import { decode as bs58Decode } from "bs58";
81
+ import { keccak256 } from "ethereum-cryptography/keccak";
82
+ import { bytesToHex, hexToBytes } from "ethereum-cryptography/utils";
83
+ import { AbiCoder, solidityPackedKeccak256 } from "ethers";
84
+ import {
85
+ utils as CoreUtils
86
+ } from "@kodiak-finance/orderly-core";
87
+ import {
88
+ DEFAUL_ORDERLY_KEY_SCOPE,
89
+ LedgerWalletKey
90
+ } from "@kodiak-finance/orderly-types";
91
+
92
+ // src/constant.ts
93
+ import { addressToBytes32 } from "@layerzerolabs/lz-v2-utilities";
94
+ import { PublicKey } from "@solana/web3.js";
95
+ var ENDPOINT_PROGRAM_ID = new PublicKey(
96
+ "76y77prsiCMvXMjuoZ5VRrhG5qYBrUMYTE5WgHqgjEn6"
97
+ );
98
+ var SEND_LIB_PROGRAM_ID = new PublicKey(
99
+ "7a4WjyR8VZ7yZz5XJAKm39BUGn5iT9CKcv2pmG9tdXVH"
100
+ );
101
+ var EXECUTOR_PROGRAM_ID = new PublicKey(
102
+ "6doghB248px58JSSwG4qejQ46kFMW4AMj7vzJnWZHNZn"
103
+ );
104
+ var PRICE_FEED_PROGRAM_ID = new PublicKey(
105
+ "8ahPGPjEbpgGaZx2NV1iG5Shj7TDwvsjkEDcGWjt94TP"
106
+ );
107
+ var RECEIVE_LIB_PROGRAM_ID = SEND_LIB_PROGRAM_ID;
108
+ var TREASURY_PROGRAM_ID = SEND_LIB_PROGRAM_ID;
109
+ var DVN_PROGRAM_ID = new PublicKey(
110
+ "HtEYV4xB4wvsj5fgTkcfuChYpvGYzgzwvNhgDZQNh7wW"
111
+ );
112
+ var VAULT_AUTHORITY_SEED = "VaultAuthority";
113
+ var BROKER_SEED = "Broker";
114
+ var TOKEN_SEED = "Token";
115
+ var SOL_VAULT_SEED = "SolVault";
116
+ var DEV_PEER_ADDRESS = addressToBytes32(
117
+ "0x9Dc724b24146BeDD2dA28b8C4B74126169B8f312"
118
+ );
119
+ var QA_PEER_ADDRESS = addressToBytes32(
120
+ "0x45b6C6266A7A2170617d8A27A50C642fd68b91c4"
121
+ );
122
+ var STAGING_PEER_ADDRESS = addressToBytes32(
123
+ "0x5Bf771A65d057e778C5f0Ed52A0003316f94322D"
124
+ );
125
+ var MAINNET_PEER_ADDRESS = addressToBytes32(
126
+ "0xCecAe061aa078e13b5e70D5F9eCee90a3F2B6AeA"
127
+ );
128
+ var DEV_DST_EID = 40200;
129
+ var MAIN_DST_EID = 30213;
130
+ var DEV_LOOKUP_TABLE_ADDRESS = new PublicKey(
131
+ "BWp8HaYYhiNHekt3zgQhqoCrRftneGxxfgKmCZ6svHN"
132
+ );
133
+ var QA_LOOKUP_TABLE_ADDRESS = new PublicKey(
134
+ "BswrQQoPKAFojTuJutZcBMtigAgTghEH4M8ofn3EG2X2"
135
+ );
136
+ var STAGING_LOOKUP_TABLE_ADDRESS = new PublicKey(
137
+ "BbGKfxuPwDmu58BjPpd7PMG69TqnZjSpKaLDMgf9E9Dr"
138
+ );
139
+ var MAINNET_LOOKUP_TABLE_ADDRESS = new PublicKey(
140
+ "8iq7xCQt3bLdRRn4A46d5GuaXYinBoiAhbe2sUmZVzwg"
141
+ );
142
+ var DEV_OAPP_PROGRAM_ID = new PublicKey(
143
+ "EYJq9eU4GMRUriUJBgGoZ8YLQBXcWaciXuSsEXE7ieQS"
144
+ );
145
+ var QA_OAPP_PROGRAM_ID = new PublicKey(
146
+ "5zBjLor7vEraAt4zp2H82sy9MSqFoDnNa1Lx6EYKTYRZ"
147
+ );
148
+ var STAGING_OAPP_PROGRAM_ID = new PublicKey(
149
+ "9shwxWDUNhtwkHocsUAmrNAQfBH2DHh4njdAEdHZZkF2"
150
+ );
151
+ var MAINNET_OAPP_PROGRAM_ID = new PublicKey(
152
+ "ErBmAD61mGFKvrFNaTJuxoPwqrS8GgtwtqJTJVjFWx9Q"
153
+ );
154
+
155
+ // src/idl/solana_vault.ts
156
+ var IDL = {
157
+ version: "0.1.0",
158
+ name: "solana_vault",
159
+ instructions: [
160
+ {
161
+ name: "setVault",
162
+ accounts: [
163
+ {
164
+ name: "admin",
165
+ isMut: true,
166
+ isSigner: true
167
+ },
168
+ {
169
+ name: "vaultAuthority",
170
+ isMut: true,
171
+ isSigner: false
172
+ },
173
+ {
174
+ name: "oappConfig",
175
+ isMut: false,
176
+ isSigner: false
177
+ },
178
+ {
179
+ name: "systemProgram",
180
+ isMut: false,
181
+ isSigner: false
182
+ }
183
+ ],
184
+ args: [
185
+ {
186
+ name: "params",
187
+ type: {
188
+ defined: "SetVaultParams"
189
+ }
190
+ }
191
+ ]
192
+ },
193
+ {
194
+ name: "deposit",
195
+ accounts: [
196
+ {
197
+ name: "user",
198
+ isMut: true,
199
+ isSigner: true
200
+ },
201
+ {
202
+ name: "userTokenAccount",
203
+ isMut: true,
204
+ isSigner: false
205
+ },
206
+ {
207
+ name: "vaultAuthority",
208
+ isMut: true,
209
+ isSigner: false
210
+ },
211
+ {
212
+ name: "vaultTokenAccount",
213
+ isMut: true,
214
+ isSigner: false
215
+ },
216
+ {
217
+ name: "depositToken",
218
+ isMut: false,
219
+ isSigner: false
220
+ },
221
+ {
222
+ name: "peer",
223
+ isMut: false,
224
+ isSigner: false
225
+ },
226
+ {
227
+ name: "enforcedOptions",
228
+ isMut: false,
229
+ isSigner: false
230
+ },
231
+ {
232
+ name: "oappConfig",
233
+ isMut: false,
234
+ isSigner: false
235
+ },
236
+ {
237
+ name: "allowedBroker",
238
+ isMut: false,
239
+ isSigner: false
240
+ },
241
+ {
242
+ name: "allowedToken",
243
+ isMut: false,
244
+ isSigner: false
245
+ },
246
+ {
247
+ name: "tokenProgram",
248
+ isMut: false,
249
+ isSigner: false
250
+ },
251
+ {
252
+ name: "associatedTokenProgram",
253
+ isMut: false,
254
+ isSigner: false
255
+ },
256
+ {
257
+ name: "systemProgram",
258
+ isMut: false,
259
+ isSigner: false
260
+ }
261
+ ],
262
+ args: [
263
+ {
264
+ name: "depositParams",
265
+ type: {
266
+ defined: "DepositParams"
267
+ }
268
+ },
269
+ {
270
+ name: "oappParams",
271
+ type: {
272
+ defined: "OAppSendParams"
273
+ }
274
+ }
275
+ ],
276
+ returns: {
277
+ defined: "MessagingReceipt"
278
+ }
279
+ },
280
+ {
281
+ name: "depositSol",
282
+ accounts: [
283
+ {
284
+ name: "user",
285
+ isMut: true,
286
+ isSigner: true
287
+ },
288
+ {
289
+ name: "vaultAuthority",
290
+ isMut: true,
291
+ isSigner: false
292
+ },
293
+ {
294
+ name: "solVault",
295
+ isMut: true,
296
+ isSigner: false,
297
+ docs: ["CHECKED: sol_vault is used for SOL deposit"]
298
+ },
299
+ {
300
+ name: "peer",
301
+ isMut: false,
302
+ isSigner: false
303
+ },
304
+ {
305
+ name: "enforcedOptions",
306
+ isMut: false,
307
+ isSigner: false
308
+ },
309
+ {
310
+ name: "oappConfig",
311
+ isMut: false,
312
+ isSigner: false
313
+ },
314
+ {
315
+ name: "allowedBroker",
316
+ isMut: false,
317
+ isSigner: false
318
+ },
319
+ {
320
+ name: "allowedToken",
321
+ isMut: false,
322
+ isSigner: false
323
+ },
324
+ {
325
+ name: "systemProgram",
326
+ isMut: false,
327
+ isSigner: false
328
+ }
329
+ ],
330
+ args: [
331
+ {
332
+ name: "depositParams",
333
+ type: {
334
+ defined: "DepositParams"
335
+ }
336
+ },
337
+ {
338
+ name: "oappParams",
339
+ type: {
340
+ defined: "OAppSendParams"
341
+ }
342
+ }
343
+ ],
344
+ returns: {
345
+ defined: "MessagingReceipt"
346
+ }
347
+ },
348
+ {
349
+ name: "initOapp",
350
+ accounts: [
351
+ {
352
+ name: "payer",
353
+ isMut: true,
354
+ isSigner: true
355
+ },
356
+ {
357
+ name: "oappConfig",
358
+ isMut: true,
359
+ isSigner: false
360
+ },
361
+ {
362
+ name: "lzReceiveTypes",
363
+ isMut: true,
364
+ isSigner: false
365
+ },
366
+ {
367
+ name: "accountList",
368
+ isMut: true,
369
+ isSigner: false
370
+ },
371
+ {
372
+ name: "systemProgram",
373
+ isMut: false,
374
+ isSigner: false
375
+ }
376
+ ],
377
+ args: [
378
+ {
379
+ name: "params",
380
+ type: {
381
+ defined: "InitOAppParams"
382
+ }
383
+ }
384
+ ]
385
+ },
386
+ {
387
+ name: "setAccountList",
388
+ accounts: [
389
+ {
390
+ name: "admin",
391
+ isMut: true,
392
+ isSigner: true
393
+ },
394
+ {
395
+ name: "oappConfig",
396
+ isMut: false,
397
+ isSigner: false
398
+ },
399
+ {
400
+ name: "lzReceiveTypes",
401
+ isMut: true,
402
+ isSigner: false
403
+ },
404
+ {
405
+ name: "accountsList",
406
+ isMut: true,
407
+ isSigner: false
408
+ },
409
+ {
410
+ name: "systemProgram",
411
+ isMut: false,
412
+ isSigner: false
413
+ }
414
+ ],
415
+ args: [
416
+ {
417
+ name: "params",
418
+ type: {
419
+ defined: "SetAccountListParams"
420
+ }
421
+ }
422
+ ]
423
+ },
424
+ {
425
+ name: "setManagerRole",
426
+ accounts: [
427
+ {
428
+ name: "owner",
429
+ isMut: true,
430
+ isSigner: true
431
+ },
432
+ {
433
+ name: "vaultAuthority",
434
+ isMut: true,
435
+ isSigner: false
436
+ },
437
+ {
438
+ name: "managerRole",
439
+ isMut: true,
440
+ isSigner: false
441
+ },
442
+ {
443
+ name: "systemProgram",
444
+ isMut: false,
445
+ isSigner: false
446
+ }
447
+ ],
448
+ args: [
449
+ {
450
+ name: "params",
451
+ type: {
452
+ defined: "SetManagerRoleParams"
453
+ }
454
+ }
455
+ ]
456
+ },
457
+ {
458
+ name: "setBroker",
459
+ accounts: [
460
+ {
461
+ name: "brokerManager",
462
+ isMut: true,
463
+ isSigner: true
464
+ },
465
+ {
466
+ name: "allowedBroker",
467
+ isMut: true,
468
+ isSigner: false
469
+ },
470
+ {
471
+ name: "managerRole",
472
+ isMut: false,
473
+ isSigner: false
474
+ },
475
+ {
476
+ name: "systemProgram",
477
+ isMut: false,
478
+ isSigner: false
479
+ }
480
+ ],
481
+ args: [
482
+ {
483
+ name: "params",
484
+ type: {
485
+ defined: "SetBrokerParams"
486
+ }
487
+ }
488
+ ]
489
+ },
490
+ {
491
+ name: "setWithdrawBroker",
492
+ accounts: [
493
+ {
494
+ name: "brokerManager",
495
+ isMut: true,
496
+ isSigner: true
497
+ },
498
+ {
499
+ name: "withdrawBroker",
500
+ isMut: true,
501
+ isSigner: false
502
+ },
503
+ {
504
+ name: "managerRole",
505
+ isMut: false,
506
+ isSigner: false
507
+ },
508
+ {
509
+ name: "systemProgram",
510
+ isMut: false,
511
+ isSigner: false
512
+ }
513
+ ],
514
+ args: [
515
+ {
516
+ name: "params",
517
+ type: {
518
+ defined: "SetWithdrawBrokerParams"
519
+ }
520
+ }
521
+ ]
522
+ },
523
+ {
524
+ name: "setToken",
525
+ accounts: [
526
+ {
527
+ name: "tokenManager",
528
+ isMut: true,
529
+ isSigner: true
530
+ },
531
+ {
532
+ name: "allowedToken",
533
+ isMut: true,
534
+ isSigner: false
535
+ },
536
+ {
537
+ name: "managerRole",
538
+ isMut: false,
539
+ isSigner: false
540
+ },
541
+ {
542
+ name: "mintAccount",
543
+ isMut: false,
544
+ isSigner: false
545
+ },
546
+ {
547
+ name: "systemProgram",
548
+ isMut: false,
549
+ isSigner: false
550
+ }
551
+ ],
552
+ args: [
553
+ {
554
+ name: "params",
555
+ type: {
556
+ defined: "SetTokenParams"
557
+ }
558
+ }
559
+ ]
560
+ },
561
+ {
562
+ name: "setWithdrawToken",
563
+ accounts: [
564
+ {
565
+ name: "tokenManager",
566
+ isMut: true,
567
+ isSigner: true
568
+ },
569
+ {
570
+ name: "withdrawToken",
571
+ isMut: true,
572
+ isSigner: false
573
+ },
574
+ {
575
+ name: "managerRole",
576
+ isMut: false,
577
+ isSigner: false
578
+ },
579
+ {
580
+ name: "mintAccount",
581
+ isMut: false,
582
+ isSigner: false
583
+ },
584
+ {
585
+ name: "systemProgram",
586
+ isMut: false,
587
+ isSigner: false
588
+ }
589
+ ],
590
+ args: [
591
+ {
592
+ name: "params",
593
+ type: {
594
+ defined: "SetWithdrawTokenParams"
595
+ }
596
+ }
597
+ ]
598
+ },
599
+ {
600
+ name: "setOrderDelivery",
601
+ accounts: [
602
+ {
603
+ name: "owner",
604
+ isMut: true,
605
+ isSigner: true
606
+ },
607
+ {
608
+ name: "vaultAuthority",
609
+ isMut: true,
610
+ isSigner: false
611
+ }
612
+ ],
613
+ args: [
614
+ {
615
+ name: "params",
616
+ type: {
617
+ defined: "SetOrderDeliveryParams"
618
+ }
619
+ }
620
+ ]
621
+ },
622
+ {
623
+ name: "oappQuote",
624
+ accounts: [
625
+ {
626
+ name: "oappConfig",
627
+ isMut: false,
628
+ isSigner: false
629
+ },
630
+ {
631
+ name: "peer",
632
+ isMut: false,
633
+ isSigner: false
634
+ },
635
+ {
636
+ name: "enforcedOptions",
637
+ isMut: false,
638
+ isSigner: false
639
+ },
640
+ {
641
+ name: "vaultAuthority",
642
+ isMut: false,
643
+ isSigner: false
644
+ }
645
+ ],
646
+ args: [
647
+ {
648
+ name: "params",
649
+ type: {
650
+ defined: "DepositParams"
651
+ }
652
+ }
653
+ ],
654
+ returns: {
655
+ defined: "MessagingFee"
656
+ }
657
+ },
658
+ {
659
+ name: "lzReceive",
660
+ accounts: [
661
+ {
662
+ name: "payer",
663
+ isMut: true,
664
+ isSigner: true
665
+ },
666
+ {
667
+ name: "peer",
668
+ isMut: false,
669
+ isSigner: false
670
+ },
671
+ {
672
+ name: "oappConfig",
673
+ isMut: false,
674
+ isSigner: false
675
+ },
676
+ {
677
+ name: "withdrawBrokerPda",
678
+ isMut: false,
679
+ isSigner: false
680
+ },
681
+ {
682
+ name: "withdrawTokenPda",
683
+ isMut: false,
684
+ isSigner: false,
685
+ docs: ["CHECK"]
686
+ },
687
+ {
688
+ name: "tokenMint",
689
+ isMut: false,
690
+ isSigner: false,
691
+ docs: ["CHECK"]
692
+ },
693
+ {
694
+ name: "receiver",
695
+ isMut: true,
696
+ isSigner: false,
697
+ docs: ["CHECK"]
698
+ },
699
+ {
700
+ name: "receiverTokenAccount",
701
+ isMut: true,
702
+ isSigner: false,
703
+ docs: ["UNCHECKED"]
704
+ },
705
+ {
706
+ name: "vaultAuthority",
707
+ isMut: true,
708
+ isSigner: false
709
+ },
710
+ {
711
+ name: "vaultTokenAccount",
712
+ isMut: true,
713
+ isSigner: false
714
+ },
715
+ {
716
+ name: "tokenProgram",
717
+ isMut: false,
718
+ isSigner: false,
719
+ docs: ["CHECKED: sol_vault is used for SOL withdrawal"]
720
+ },
721
+ {
722
+ name: "associatedTokenProgram",
723
+ isMut: false,
724
+ isSigner: false
725
+ },
726
+ {
727
+ name: "systemProgram",
728
+ isMut: false,
729
+ isSigner: false
730
+ },
731
+ {
732
+ name: "eventAuthority",
733
+ isMut: false,
734
+ isSigner: false
735
+ },
736
+ {
737
+ name: "program",
738
+ isMut: false,
739
+ isSigner: false
740
+ }
741
+ ],
742
+ args: [
743
+ {
744
+ name: "params",
745
+ type: {
746
+ defined: "OAppLzReceiveParams"
747
+ }
748
+ }
749
+ ]
750
+ },
751
+ {
752
+ name: "lzReceiveTypes",
753
+ accounts: [
754
+ {
755
+ name: "oappConfig",
756
+ isMut: false,
757
+ isSigner: false
758
+ },
759
+ {
760
+ name: "accountList",
761
+ isMut: false,
762
+ isSigner: false
763
+ }
764
+ ],
765
+ args: [
766
+ {
767
+ name: "params",
768
+ type: {
769
+ defined: "OAppLzReceiveParams"
770
+ }
771
+ }
772
+ ],
773
+ returns: {
774
+ vec: {
775
+ defined: "oapp::endpoint_cpi::LzAccount"
776
+ }
777
+ }
778
+ },
779
+ {
780
+ name: "setRateLimit",
781
+ accounts: [
782
+ {
783
+ name: "admin",
784
+ isMut: false,
785
+ isSigner: true
786
+ },
787
+ {
788
+ name: "peer",
789
+ isMut: true,
790
+ isSigner: false
791
+ },
792
+ {
793
+ name: "oappConfig",
794
+ isMut: false,
795
+ isSigner: false
796
+ }
797
+ ],
798
+ args: [
799
+ {
800
+ name: "params",
801
+ type: {
802
+ defined: "SetRateLimitParams"
803
+ }
804
+ }
805
+ ]
806
+ },
807
+ {
808
+ name: "setDelegate",
809
+ accounts: [
810
+ {
811
+ name: "admin",
812
+ isMut: false,
813
+ isSigner: true
814
+ },
815
+ {
816
+ name: "oappConfig",
817
+ isMut: false,
818
+ isSigner: false
819
+ }
820
+ ],
821
+ args: [
822
+ {
823
+ name: "params",
824
+ type: {
825
+ defined: "SetDelegateParams"
826
+ }
827
+ }
828
+ ]
829
+ },
830
+ {
831
+ name: "transferAdmin",
832
+ accounts: [
833
+ {
834
+ name: "admin",
835
+ isMut: false,
836
+ isSigner: true
837
+ },
838
+ {
839
+ name: "oappConfig",
840
+ isMut: true,
841
+ isSigner: false
842
+ }
843
+ ],
844
+ args: [
845
+ {
846
+ name: "params",
847
+ type: {
848
+ defined: "TransferAdminParams"
849
+ }
850
+ }
851
+ ]
852
+ },
853
+ {
854
+ name: "setPeer",
855
+ accounts: [
856
+ {
857
+ name: "admin",
858
+ isMut: true,
859
+ isSigner: true
860
+ },
861
+ {
862
+ name: "peer",
863
+ isMut: true,
864
+ isSigner: false
865
+ },
866
+ {
867
+ name: "oappConfig",
868
+ isMut: false,
869
+ isSigner: false
870
+ },
871
+ {
872
+ name: "systemProgram",
873
+ isMut: false,
874
+ isSigner: false
875
+ }
876
+ ],
877
+ args: [
878
+ {
879
+ name: "params",
880
+ type: {
881
+ defined: "SetPeerParams"
882
+ }
883
+ }
884
+ ]
885
+ },
886
+ {
887
+ name: "setEnforcedOptions",
888
+ accounts: [
889
+ {
890
+ name: "admin",
891
+ isMut: true,
892
+ isSigner: true
893
+ },
894
+ {
895
+ name: "enforcedOptions",
896
+ isMut: true,
897
+ isSigner: false
898
+ },
899
+ {
900
+ name: "oappConfig",
901
+ isMut: false,
902
+ isSigner: false
903
+ },
904
+ {
905
+ name: "systemProgram",
906
+ isMut: false,
907
+ isSigner: false
908
+ }
909
+ ],
910
+ args: [
911
+ {
912
+ name: "params",
913
+ type: {
914
+ defined: "SetEnforcedOptionsParams"
915
+ }
916
+ }
917
+ ]
918
+ }
919
+ ],
920
+ accounts: [
921
+ {
922
+ name: "enforcedOptions",
923
+ type: {
924
+ kind: "struct",
925
+ fields: [
926
+ {
927
+ name: "send",
928
+ type: "bytes"
929
+ },
930
+ {
931
+ name: "sendAndCall",
932
+ type: "bytes"
933
+ },
934
+ {
935
+ name: "bump",
936
+ type: "u8"
937
+ }
938
+ ]
939
+ }
940
+ },
941
+ {
942
+ name: "oAppConfig",
943
+ type: {
944
+ kind: "struct",
945
+ fields: [
946
+ {
947
+ name: "endpointProgram",
948
+ type: "publicKey"
949
+ },
950
+ {
951
+ name: "bump",
952
+ type: "u8"
953
+ },
954
+ {
955
+ name: "admin",
956
+ type: "publicKey"
957
+ }
958
+ ]
959
+ }
960
+ },
961
+ {
962
+ name: "oAppLzReceiveTypesAccounts",
963
+ type: {
964
+ kind: "struct",
965
+ fields: [
966
+ {
967
+ name: "oappConfig",
968
+ type: "publicKey"
969
+ },
970
+ {
971
+ name: "accountList",
972
+ type: "publicKey"
973
+ }
974
+ ]
975
+ }
976
+ },
977
+ {
978
+ name: "accountList",
979
+ type: {
980
+ kind: "struct",
981
+ fields: [
982
+ {
983
+ name: "bump",
984
+ type: "u8"
985
+ },
986
+ {
987
+ name: "woofiProPda",
988
+ type: "publicKey"
989
+ },
990
+ {
991
+ name: "withdrawUsdcPda",
992
+ type: "publicKey"
993
+ },
994
+ {
995
+ name: "usdcMint",
996
+ type: "publicKey"
997
+ },
998
+ {
999
+ name: "withdrawUsdtPda",
1000
+ type: "publicKey"
1001
+ },
1002
+ {
1003
+ name: "usdtMint",
1004
+ type: "publicKey"
1005
+ },
1006
+ {
1007
+ name: "withdrawWsolPda",
1008
+ type: "publicKey"
1009
+ },
1010
+ {
1011
+ name: "wsolMint",
1012
+ type: "publicKey"
1013
+ }
1014
+ ]
1015
+ }
1016
+ },
1017
+ {
1018
+ name: "peer",
1019
+ type: {
1020
+ kind: "struct",
1021
+ fields: [
1022
+ {
1023
+ name: "address",
1024
+ type: {
1025
+ array: ["u8", 32]
1026
+ }
1027
+ },
1028
+ {
1029
+ name: "rateLimiter",
1030
+ type: {
1031
+ option: {
1032
+ defined: "RateLimiter"
1033
+ }
1034
+ }
1035
+ },
1036
+ {
1037
+ name: "bump",
1038
+ type: "u8"
1039
+ }
1040
+ ]
1041
+ }
1042
+ },
1043
+ {
1044
+ name: "allowedBroker",
1045
+ type: {
1046
+ kind: "struct",
1047
+ fields: [
1048
+ {
1049
+ name: "brokerHash",
1050
+ type: {
1051
+ array: ["u8", 32]
1052
+ }
1053
+ },
1054
+ {
1055
+ name: "allowed",
1056
+ type: "bool"
1057
+ },
1058
+ {
1059
+ name: "bump",
1060
+ type: "u8"
1061
+ }
1062
+ ]
1063
+ }
1064
+ },
1065
+ {
1066
+ name: "allowedToken",
1067
+ type: {
1068
+ kind: "struct",
1069
+ fields: [
1070
+ {
1071
+ name: "mintAccount",
1072
+ type: "publicKey"
1073
+ },
1074
+ {
1075
+ name: "tokenHash",
1076
+ type: {
1077
+ array: ["u8", 32]
1078
+ }
1079
+ },
1080
+ {
1081
+ name: "tokenDecimals",
1082
+ type: "u8"
1083
+ },
1084
+ {
1085
+ name: "allowed",
1086
+ type: "bool"
1087
+ },
1088
+ {
1089
+ name: "bump",
1090
+ type: "u8"
1091
+ }
1092
+ ]
1093
+ }
1094
+ },
1095
+ {
1096
+ name: "managerRole",
1097
+ type: {
1098
+ kind: "struct",
1099
+ fields: [
1100
+ {
1101
+ name: "roleHash",
1102
+ type: {
1103
+ array: ["u8", 32]
1104
+ }
1105
+ },
1106
+ {
1107
+ name: "allowed",
1108
+ type: "bool"
1109
+ },
1110
+ {
1111
+ name: "bump",
1112
+ type: "u8"
1113
+ }
1114
+ ]
1115
+ }
1116
+ },
1117
+ {
1118
+ name: "vaultAuthority",
1119
+ type: {
1120
+ kind: "struct",
1121
+ fields: [
1122
+ {
1123
+ name: "bump",
1124
+ docs: ["Bump seed for the vault authority PDA"],
1125
+ type: "u8"
1126
+ },
1127
+ {
1128
+ name: "owner",
1129
+ type: "publicKey"
1130
+ },
1131
+ {
1132
+ name: "depositNonce",
1133
+ type: "u64"
1134
+ },
1135
+ {
1136
+ name: "orderDelivery",
1137
+ type: "bool"
1138
+ },
1139
+ {
1140
+ name: "inboundNonce",
1141
+ type: "u64"
1142
+ },
1143
+ {
1144
+ name: "dstEid",
1145
+ type: "u32"
1146
+ },
1147
+ {
1148
+ name: "solChainId",
1149
+ type: "u128"
1150
+ }
1151
+ ]
1152
+ }
1153
+ },
1154
+ {
1155
+ name: "withdrawBroker",
1156
+ type: {
1157
+ kind: "struct",
1158
+ fields: [
1159
+ {
1160
+ name: "brokerHash",
1161
+ type: {
1162
+ array: ["u8", 32]
1163
+ }
1164
+ },
1165
+ {
1166
+ name: "brokerIndex",
1167
+ type: "u16"
1168
+ },
1169
+ {
1170
+ name: "allowed",
1171
+ type: "bool"
1172
+ },
1173
+ {
1174
+ name: "bump",
1175
+ type: "u8"
1176
+ }
1177
+ ]
1178
+ }
1179
+ },
1180
+ {
1181
+ name: "withdrawToken",
1182
+ type: {
1183
+ kind: "struct",
1184
+ fields: [
1185
+ {
1186
+ name: "mintAccount",
1187
+ type: "publicKey"
1188
+ },
1189
+ {
1190
+ name: "tokenHash",
1191
+ type: {
1192
+ array: ["u8", 32]
1193
+ }
1194
+ },
1195
+ {
1196
+ name: "tokenDecimals",
1197
+ type: "u8"
1198
+ },
1199
+ {
1200
+ name: "tokenIndex",
1201
+ type: "u8"
1202
+ },
1203
+ {
1204
+ name: "allowed",
1205
+ type: "bool"
1206
+ },
1207
+ {
1208
+ name: "bump",
1209
+ type: "u8"
1210
+ }
1211
+ ]
1212
+ }
1213
+ }
1214
+ ],
1215
+ types: [
1216
+ {
1217
+ name: "VaultDepositParams",
1218
+ type: {
1219
+ kind: "struct",
1220
+ fields: [
1221
+ {
1222
+ name: "accountId",
1223
+ type: {
1224
+ array: ["u8", 32]
1225
+ }
1226
+ },
1227
+ {
1228
+ name: "brokerHash",
1229
+ type: {
1230
+ array: ["u8", 32]
1231
+ }
1232
+ },
1233
+ {
1234
+ name: "userAddress",
1235
+ type: {
1236
+ array: ["u8", 32]
1237
+ }
1238
+ },
1239
+ {
1240
+ name: "tokenHash",
1241
+ type: {
1242
+ array: ["u8", 32]
1243
+ }
1244
+ },
1245
+ {
1246
+ name: "srcChainId",
1247
+ type: "u128"
1248
+ },
1249
+ {
1250
+ name: "tokenAmount",
1251
+ type: "u128"
1252
+ },
1253
+ {
1254
+ name: "srcChainDepositNonce",
1255
+ type: "u64"
1256
+ }
1257
+ ]
1258
+ }
1259
+ },
1260
+ {
1261
+ name: "LzMessage",
1262
+ type: {
1263
+ kind: "struct",
1264
+ fields: [
1265
+ {
1266
+ name: "msgType",
1267
+ type: "u8"
1268
+ },
1269
+ {
1270
+ name: "payload",
1271
+ type: "bytes"
1272
+ }
1273
+ ]
1274
+ }
1275
+ },
1276
+ {
1277
+ name: "AccountWithdrawSol",
1278
+ type: {
1279
+ kind: "struct",
1280
+ fields: [
1281
+ {
1282
+ name: "sender",
1283
+ type: {
1284
+ array: ["u8", 32]
1285
+ }
1286
+ },
1287
+ {
1288
+ name: "receiver",
1289
+ type: {
1290
+ array: ["u8", 32]
1291
+ }
1292
+ },
1293
+ {
1294
+ name: "brokerIndex",
1295
+ type: "u16"
1296
+ },
1297
+ {
1298
+ name: "tokenIndex",
1299
+ type: "u8"
1300
+ },
1301
+ {
1302
+ name: "tokenAmount",
1303
+ type: "u64"
1304
+ },
1305
+ {
1306
+ name: "fee",
1307
+ type: "u64"
1308
+ },
1309
+ {
1310
+ name: "chainId",
1311
+ type: "u64"
1312
+ },
1313
+ {
1314
+ name: "withdrawNonce",
1315
+ type: "u64"
1316
+ }
1317
+ ]
1318
+ }
1319
+ },
1320
+ {
1321
+ name: "VaultWithdrawParams",
1322
+ type: {
1323
+ kind: "struct",
1324
+ fields: [
1325
+ {
1326
+ name: "accountId",
1327
+ type: {
1328
+ array: ["u8", 32]
1329
+ }
1330
+ },
1331
+ {
1332
+ name: "sender",
1333
+ type: {
1334
+ array: ["u8", 32]
1335
+ }
1336
+ },
1337
+ {
1338
+ name: "receiver",
1339
+ type: {
1340
+ array: ["u8", 32]
1341
+ }
1342
+ },
1343
+ {
1344
+ name: "brokerHash",
1345
+ type: {
1346
+ array: ["u8", 32]
1347
+ }
1348
+ },
1349
+ {
1350
+ name: "tokenHash",
1351
+ type: {
1352
+ array: ["u8", 32]
1353
+ }
1354
+ },
1355
+ {
1356
+ name: "tokenAmount",
1357
+ type: "u64"
1358
+ },
1359
+ {
1360
+ name: "fee",
1361
+ type: "u128"
1362
+ },
1363
+ {
1364
+ name: "chainId",
1365
+ type: "u128"
1366
+ },
1367
+ {
1368
+ name: "withdrawNonce",
1369
+ type: "u64"
1370
+ }
1371
+ ]
1372
+ }
1373
+ },
1374
+ {
1375
+ name: "InitOAppParams",
1376
+ type: {
1377
+ kind: "struct",
1378
+ fields: [
1379
+ {
1380
+ name: "admin",
1381
+ type: "publicKey"
1382
+ },
1383
+ {
1384
+ name: "accountList",
1385
+ type: "publicKey"
1386
+ },
1387
+ {
1388
+ name: "endpointProgram",
1389
+ type: {
1390
+ option: "publicKey"
1391
+ }
1392
+ }
1393
+ ]
1394
+ }
1395
+ },
1396
+ {
1397
+ name: "OAppLzReceiveParams",
1398
+ type: {
1399
+ kind: "struct",
1400
+ fields: [
1401
+ {
1402
+ name: "srcEid",
1403
+ type: "u32"
1404
+ },
1405
+ {
1406
+ name: "sender",
1407
+ type: {
1408
+ array: ["u8", 32]
1409
+ }
1410
+ },
1411
+ {
1412
+ name: "nonce",
1413
+ type: "u64"
1414
+ },
1415
+ {
1416
+ name: "guid",
1417
+ type: {
1418
+ array: ["u8", 32]
1419
+ }
1420
+ },
1421
+ {
1422
+ name: "message",
1423
+ type: "bytes"
1424
+ },
1425
+ {
1426
+ name: "extraData",
1427
+ type: "bytes"
1428
+ }
1429
+ ]
1430
+ }
1431
+ },
1432
+ {
1433
+ name: "MessagingFee",
1434
+ type: {
1435
+ kind: "struct",
1436
+ fields: [
1437
+ {
1438
+ name: "nativeFee",
1439
+ type: "u64"
1440
+ },
1441
+ {
1442
+ name: "lzTokenFee",
1443
+ type: "u64"
1444
+ }
1445
+ ]
1446
+ }
1447
+ },
1448
+ {
1449
+ name: "SetAccountListParams",
1450
+ type: {
1451
+ kind: "struct",
1452
+ fields: [
1453
+ {
1454
+ name: "woofiProPda",
1455
+ type: "publicKey"
1456
+ },
1457
+ {
1458
+ name: "withdrawUsdcPda",
1459
+ type: "publicKey"
1460
+ },
1461
+ {
1462
+ name: "usdcMint",
1463
+ type: "publicKey"
1464
+ },
1465
+ {
1466
+ name: "withdrawUsdtPda",
1467
+ type: "publicKey"
1468
+ },
1469
+ {
1470
+ name: "usdtMint",
1471
+ type: "publicKey"
1472
+ },
1473
+ {
1474
+ name: "withdrawWsolPda",
1475
+ type: "publicKey"
1476
+ },
1477
+ {
1478
+ name: "wsolMint",
1479
+ type: "publicKey"
1480
+ }
1481
+ ]
1482
+ }
1483
+ },
1484
+ {
1485
+ name: "SetDelegateParams",
1486
+ type: {
1487
+ kind: "struct",
1488
+ fields: [
1489
+ {
1490
+ name: "delegate",
1491
+ type: "publicKey"
1492
+ }
1493
+ ]
1494
+ }
1495
+ },
1496
+ {
1497
+ name: "SetEnforcedOptionsParams",
1498
+ type: {
1499
+ kind: "struct",
1500
+ fields: [
1501
+ {
1502
+ name: "dstEid",
1503
+ type: "u32"
1504
+ },
1505
+ {
1506
+ name: "send",
1507
+ type: "bytes"
1508
+ },
1509
+ {
1510
+ name: "sendAndCall",
1511
+ type: "bytes"
1512
+ }
1513
+ ]
1514
+ }
1515
+ },
1516
+ {
1517
+ name: "SetPeerParams",
1518
+ type: {
1519
+ kind: "struct",
1520
+ fields: [
1521
+ {
1522
+ name: "dstEid",
1523
+ type: "u32"
1524
+ },
1525
+ {
1526
+ name: "peer",
1527
+ type: {
1528
+ array: ["u8", 32]
1529
+ }
1530
+ }
1531
+ ]
1532
+ }
1533
+ },
1534
+ {
1535
+ name: "SetRateLimitParams",
1536
+ type: {
1537
+ kind: "struct",
1538
+ fields: [
1539
+ {
1540
+ name: "dstEid",
1541
+ type: "u32"
1542
+ },
1543
+ {
1544
+ name: "refillPerSecond",
1545
+ type: {
1546
+ option: "u64"
1547
+ }
1548
+ },
1549
+ {
1550
+ name: "capacity",
1551
+ type: {
1552
+ option: "u64"
1553
+ }
1554
+ },
1555
+ {
1556
+ name: "enabled",
1557
+ type: "bool"
1558
+ }
1559
+ ]
1560
+ }
1561
+ },
1562
+ {
1563
+ name: "TransferAdminParams",
1564
+ type: {
1565
+ kind: "struct",
1566
+ fields: [
1567
+ {
1568
+ name: "admin",
1569
+ type: "publicKey"
1570
+ }
1571
+ ]
1572
+ }
1573
+ },
1574
+ {
1575
+ name: "DepositParams",
1576
+ type: {
1577
+ kind: "struct",
1578
+ fields: [
1579
+ {
1580
+ name: "accountId",
1581
+ type: {
1582
+ array: ["u8", 32]
1583
+ }
1584
+ },
1585
+ {
1586
+ name: "brokerHash",
1587
+ type: {
1588
+ array: ["u8", 32]
1589
+ }
1590
+ },
1591
+ {
1592
+ name: "tokenHash",
1593
+ type: {
1594
+ array: ["u8", 32]
1595
+ }
1596
+ },
1597
+ {
1598
+ name: "userAddress",
1599
+ type: {
1600
+ array: ["u8", 32]
1601
+ }
1602
+ },
1603
+ {
1604
+ name: "tokenAmount",
1605
+ type: "u64"
1606
+ }
1607
+ ]
1608
+ }
1609
+ },
1610
+ {
1611
+ name: "OAppSendParams",
1612
+ type: {
1613
+ kind: "struct",
1614
+ fields: [
1615
+ {
1616
+ name: "nativeFee",
1617
+ type: "u64"
1618
+ },
1619
+ {
1620
+ name: "lzTokenFee",
1621
+ type: "u64"
1622
+ }
1623
+ ]
1624
+ }
1625
+ },
1626
+ {
1627
+ name: "SetBrokerParams",
1628
+ type: {
1629
+ kind: "struct",
1630
+ fields: [
1631
+ {
1632
+ name: "brokerManagerRole",
1633
+ type: {
1634
+ array: ["u8", 32]
1635
+ }
1636
+ },
1637
+ {
1638
+ name: "brokerHash",
1639
+ type: {
1640
+ array: ["u8", 32]
1641
+ }
1642
+ },
1643
+ {
1644
+ name: "allowed",
1645
+ type: "bool"
1646
+ }
1647
+ ]
1648
+ }
1649
+ },
1650
+ {
1651
+ name: "SetManagerRoleParams",
1652
+ type: {
1653
+ kind: "struct",
1654
+ fields: [
1655
+ {
1656
+ name: "roleHash",
1657
+ type: {
1658
+ array: ["u8", 32]
1659
+ }
1660
+ },
1661
+ {
1662
+ name: "managerAddress",
1663
+ type: "publicKey"
1664
+ },
1665
+ {
1666
+ name: "allowed",
1667
+ type: "bool"
1668
+ }
1669
+ ]
1670
+ }
1671
+ },
1672
+ {
1673
+ name: "SetOrderDeliveryParams",
1674
+ type: {
1675
+ kind: "struct",
1676
+ fields: [
1677
+ {
1678
+ name: "orderDelivery",
1679
+ type: "bool"
1680
+ },
1681
+ {
1682
+ name: "nonce",
1683
+ type: "u64"
1684
+ }
1685
+ ]
1686
+ }
1687
+ },
1688
+ {
1689
+ name: "SetTokenParams",
1690
+ type: {
1691
+ kind: "struct",
1692
+ fields: [
1693
+ {
1694
+ name: "tokenManagerRole",
1695
+ type: {
1696
+ array: ["u8", 32]
1697
+ }
1698
+ },
1699
+ {
1700
+ name: "mintAccount",
1701
+ type: "publicKey"
1702
+ },
1703
+ {
1704
+ name: "tokenHash",
1705
+ type: {
1706
+ array: ["u8", 32]
1707
+ }
1708
+ },
1709
+ {
1710
+ name: "allowed",
1711
+ type: "bool"
1712
+ }
1713
+ ]
1714
+ }
1715
+ },
1716
+ {
1717
+ name: "SetVaultParams",
1718
+ type: {
1719
+ kind: "struct",
1720
+ fields: [
1721
+ {
1722
+ name: "owner",
1723
+ type: "publicKey"
1724
+ },
1725
+ {
1726
+ name: "depositNonce",
1727
+ type: "u64"
1728
+ },
1729
+ {
1730
+ name: "orderDelivery",
1731
+ type: "bool"
1732
+ },
1733
+ {
1734
+ name: "inboundNonce",
1735
+ type: "u64"
1736
+ },
1737
+ {
1738
+ name: "dstEid",
1739
+ type: "u32"
1740
+ },
1741
+ {
1742
+ name: "solChainId",
1743
+ type: "u128"
1744
+ }
1745
+ ]
1746
+ }
1747
+ },
1748
+ {
1749
+ name: "SetWithdrawBrokerParams",
1750
+ type: {
1751
+ kind: "struct",
1752
+ fields: [
1753
+ {
1754
+ name: "brokerManagerRole",
1755
+ type: {
1756
+ array: ["u8", 32]
1757
+ }
1758
+ },
1759
+ {
1760
+ name: "brokerHash",
1761
+ type: {
1762
+ array: ["u8", 32]
1763
+ }
1764
+ },
1765
+ {
1766
+ name: "brokerIndex",
1767
+ type: "u16"
1768
+ },
1769
+ {
1770
+ name: "allowed",
1771
+ type: "bool"
1772
+ }
1773
+ ]
1774
+ }
1775
+ },
1776
+ {
1777
+ name: "SetWithdrawTokenParams",
1778
+ type: {
1779
+ kind: "struct",
1780
+ fields: [
1781
+ {
1782
+ name: "tokenManagerRole",
1783
+ type: {
1784
+ array: ["u8", 32]
1785
+ }
1786
+ },
1787
+ {
1788
+ name: "tokenHash",
1789
+ type: {
1790
+ array: ["u8", 32]
1791
+ }
1792
+ },
1793
+ {
1794
+ name: "tokenIndex",
1795
+ type: "u8"
1796
+ },
1797
+ {
1798
+ name: "allowed",
1799
+ type: "bool"
1800
+ }
1801
+ ]
1802
+ }
1803
+ },
1804
+ {
1805
+ name: "RateLimiter",
1806
+ type: {
1807
+ kind: "struct",
1808
+ fields: [
1809
+ {
1810
+ name: "capacity",
1811
+ type: "u64"
1812
+ },
1813
+ {
1814
+ name: "tokens",
1815
+ type: "u64"
1816
+ },
1817
+ {
1818
+ name: "refillPerSecond",
1819
+ type: "u64"
1820
+ },
1821
+ {
1822
+ name: "lastRefillTime",
1823
+ type: "u64"
1824
+ }
1825
+ ]
1826
+ }
1827
+ },
1828
+ {
1829
+ name: "OAppError",
1830
+ type: {
1831
+ kind: "enum",
1832
+ variants: [
1833
+ {
1834
+ name: "Unauthorized"
1835
+ },
1836
+ {
1837
+ name: "InvalidSender"
1838
+ },
1839
+ {
1840
+ name: "InvalidReceiver"
1841
+ },
1842
+ {
1843
+ name: "InvalidOptions"
1844
+ },
1845
+ {
1846
+ name: "InvalidEndpointProgram"
1847
+ },
1848
+ {
1849
+ name: "RateLimitExceeded"
1850
+ },
1851
+ {
1852
+ name: "WithdrawFailed"
1853
+ },
1854
+ {
1855
+ name: "InvalidInboundNonce"
1856
+ },
1857
+ {
1858
+ name: "InvalidReceiverTokenAccount"
1859
+ },
1860
+ {
1861
+ name: "InvalidAdminTokenAccount"
1862
+ },
1863
+ {
1864
+ name: "InvalidMessageType"
1865
+ },
1866
+ {
1867
+ name: "InvalidTokenIndex"
1868
+ }
1869
+ ]
1870
+ }
1871
+ },
1872
+ {
1873
+ name: "MsgType",
1874
+ type: {
1875
+ kind: "enum",
1876
+ variants: [
1877
+ {
1878
+ name: "Deposit"
1879
+ },
1880
+ {
1881
+ name: "Withdraw"
1882
+ },
1883
+ {
1884
+ name: "RebalanceBurn"
1885
+ },
1886
+ {
1887
+ name: "RebalanceMint"
1888
+ }
1889
+ ]
1890
+ }
1891
+ }
1892
+ ],
1893
+ events: [
1894
+ {
1895
+ name: "SetAllowedBroker",
1896
+ fields: [
1897
+ {
1898
+ name: "brokerHash",
1899
+ type: {
1900
+ array: ["u8", 32]
1901
+ },
1902
+ index: false
1903
+ }
1904
+ ]
1905
+ },
1906
+ {
1907
+ name: "ResetAllowedBroker",
1908
+ fields: [
1909
+ {
1910
+ name: "brokerHash",
1911
+ type: {
1912
+ array: ["u8", 32]
1913
+ },
1914
+ index: false
1915
+ }
1916
+ ]
1917
+ },
1918
+ {
1919
+ name: "SetAllowedToken",
1920
+ fields: [
1921
+ {
1922
+ name: "tokenHash",
1923
+ type: {
1924
+ array: ["u8", 32]
1925
+ },
1926
+ index: false
1927
+ },
1928
+ {
1929
+ name: "mintAccount",
1930
+ type: "publicKey",
1931
+ index: false
1932
+ }
1933
+ ]
1934
+ },
1935
+ {
1936
+ name: "ResetAllowedToken",
1937
+ fields: [
1938
+ {
1939
+ name: "tokenHash",
1940
+ type: {
1941
+ array: ["u8", 32]
1942
+ },
1943
+ index: false
1944
+ },
1945
+ {
1946
+ name: "mintAccount",
1947
+ type: "publicKey",
1948
+ index: false
1949
+ }
1950
+ ]
1951
+ },
1952
+ {
1953
+ name: "SetWithdrawTokenIndex",
1954
+ fields: [
1955
+ {
1956
+ name: "tokenIndex",
1957
+ type: "u8",
1958
+ index: false
1959
+ },
1960
+ {
1961
+ name: "tokenHash",
1962
+ type: {
1963
+ array: ["u8", 32]
1964
+ },
1965
+ index: false
1966
+ },
1967
+ {
1968
+ name: "mintAccount",
1969
+ type: "publicKey",
1970
+ index: false
1971
+ }
1972
+ ]
1973
+ },
1974
+ {
1975
+ name: "ResetWithdrawTokenIndex",
1976
+ fields: [
1977
+ {
1978
+ name: "tokenIndex",
1979
+ type: "u8",
1980
+ index: false
1981
+ },
1982
+ {
1983
+ name: "tokenHash",
1984
+ type: {
1985
+ array: ["u8", 32]
1986
+ },
1987
+ index: false
1988
+ },
1989
+ {
1990
+ name: "mintAccount",
1991
+ type: "publicKey",
1992
+ index: false
1993
+ }
1994
+ ]
1995
+ },
1996
+ {
1997
+ name: "SetWithdrawBrokerEvent",
1998
+ fields: [
1999
+ {
2000
+ name: "brokerHash",
2001
+ type: {
2002
+ array: ["u8", 32]
2003
+ },
2004
+ index: false
2005
+ },
2006
+ {
2007
+ name: "brokerIndex",
2008
+ type: "u16",
2009
+ index: false
2010
+ }
2011
+ ]
2012
+ },
2013
+ {
2014
+ name: "ResetWithdrawBrokerEvent",
2015
+ fields: [
2016
+ {
2017
+ name: "brokerHash",
2018
+ type: {
2019
+ array: ["u8", 32]
2020
+ },
2021
+ index: false
2022
+ },
2023
+ {
2024
+ name: "brokerIndex",
2025
+ type: "u16",
2026
+ index: false
2027
+ }
2028
+ ]
2029
+ },
2030
+ {
2031
+ name: "SetManager",
2032
+ fields: [
2033
+ {
2034
+ name: "roleHash",
2035
+ type: {
2036
+ array: ["u8", 32]
2037
+ },
2038
+ index: false
2039
+ },
2040
+ {
2041
+ name: "managerAddress",
2042
+ type: "publicKey",
2043
+ index: false
2044
+ },
2045
+ {
2046
+ name: "allowed",
2047
+ type: "bool",
2048
+ index: false
2049
+ }
2050
+ ]
2051
+ },
2052
+ {
2053
+ name: "Deposited",
2054
+ fields: [
2055
+ {
2056
+ name: "user",
2057
+ type: "publicKey",
2058
+ index: false
2059
+ },
2060
+ {
2061
+ name: "amount",
2062
+ type: "u64",
2063
+ index: false
2064
+ }
2065
+ ]
2066
+ },
2067
+ {
2068
+ name: "Withdrawn",
2069
+ fields: [
2070
+ {
2071
+ name: "user",
2072
+ type: "publicKey",
2073
+ index: false
2074
+ },
2075
+ {
2076
+ name: "amount",
2077
+ type: "u64",
2078
+ index: false
2079
+ }
2080
+ ]
2081
+ },
2082
+ {
2083
+ name: "CreatedATA",
2084
+ fields: [
2085
+ {
2086
+ name: "accountId",
2087
+ type: {
2088
+ array: ["u8", 32]
2089
+ },
2090
+ index: false
2091
+ },
2092
+ {
2093
+ name: "receiver",
2094
+ type: {
2095
+ array: ["u8", 32]
2096
+ },
2097
+ index: false
2098
+ },
2099
+ {
2100
+ name: "receiverTokenAccount",
2101
+ type: {
2102
+ array: ["u8", 32]
2103
+ },
2104
+ index: false
2105
+ },
2106
+ {
2107
+ name: "withdrawNonce",
2108
+ type: "u64",
2109
+ index: false
2110
+ }
2111
+ ]
2112
+ },
2113
+ {
2114
+ name: "VaultDeposited",
2115
+ fields: [
2116
+ {
2117
+ name: "accountId",
2118
+ type: {
2119
+ array: ["u8", 32]
2120
+ },
2121
+ index: false
2122
+ },
2123
+ {
2124
+ name: "brokerHash",
2125
+ type: {
2126
+ array: ["u8", 32]
2127
+ },
2128
+ index: false
2129
+ },
2130
+ {
2131
+ name: "userAddress",
2132
+ type: {
2133
+ array: ["u8", 32]
2134
+ },
2135
+ index: false
2136
+ },
2137
+ {
2138
+ name: "tokenHash",
2139
+ type: {
2140
+ array: ["u8", 32]
2141
+ },
2142
+ index: false
2143
+ },
2144
+ {
2145
+ name: "srcChainId",
2146
+ type: "u128",
2147
+ index: false
2148
+ },
2149
+ {
2150
+ name: "tokenAmount",
2151
+ type: "u64",
2152
+ index: false
2153
+ },
2154
+ {
2155
+ name: "srcChainDepositNonce",
2156
+ type: "u64",
2157
+ index: false
2158
+ }
2159
+ ]
2160
+ },
2161
+ {
2162
+ name: "VaultWithdrawn",
2163
+ fields: [
2164
+ {
2165
+ name: "accountId",
2166
+ type: {
2167
+ array: ["u8", 32]
2168
+ },
2169
+ index: false
2170
+ },
2171
+ {
2172
+ name: "sender",
2173
+ type: {
2174
+ array: ["u8", 32]
2175
+ },
2176
+ index: false
2177
+ },
2178
+ {
2179
+ name: "receiver",
2180
+ type: {
2181
+ array: ["u8", 32]
2182
+ },
2183
+ index: false
2184
+ },
2185
+ {
2186
+ name: "brokerHash",
2187
+ type: {
2188
+ array: ["u8", 32]
2189
+ },
2190
+ index: false
2191
+ },
2192
+ {
2193
+ name: "tokenHash",
2194
+ type: {
2195
+ array: ["u8", 32]
2196
+ },
2197
+ index: false
2198
+ },
2199
+ {
2200
+ name: "tokenAmount",
2201
+ type: "u64",
2202
+ index: false
2203
+ },
2204
+ {
2205
+ name: "fee",
2206
+ type: "u128",
2207
+ index: false
2208
+ },
2209
+ {
2210
+ name: "chainId",
2211
+ type: "u128",
2212
+ index: false
2213
+ },
2214
+ {
2215
+ name: "withdrawNonce",
2216
+ type: "u64",
2217
+ index: false
2218
+ }
2219
+ ]
2220
+ },
2221
+ {
2222
+ name: "FrozenWithdrawn",
2223
+ fields: [
2224
+ {
2225
+ name: "accountId",
2226
+ type: {
2227
+ array: ["u8", 32]
2228
+ },
2229
+ index: false
2230
+ },
2231
+ {
2232
+ name: "sender",
2233
+ type: {
2234
+ array: ["u8", 32]
2235
+ },
2236
+ index: false
2237
+ },
2238
+ {
2239
+ name: "receiver",
2240
+ type: {
2241
+ array: ["u8", 32]
2242
+ },
2243
+ index: false
2244
+ },
2245
+ {
2246
+ name: "brokerHash",
2247
+ type: {
2248
+ array: ["u8", 32]
2249
+ },
2250
+ index: false
2251
+ },
2252
+ {
2253
+ name: "tokenHash",
2254
+ type: {
2255
+ array: ["u8", 32]
2256
+ },
2257
+ index: false
2258
+ },
2259
+ {
2260
+ name: "tokenAmount",
2261
+ type: "u64",
2262
+ index: false
2263
+ },
2264
+ {
2265
+ name: "fee",
2266
+ type: "u128",
2267
+ index: false
2268
+ },
2269
+ {
2270
+ name: "chainId",
2271
+ type: "u128",
2272
+ index: false
2273
+ },
2274
+ {
2275
+ name: "withdrawNonce",
2276
+ type: "u64",
2277
+ index: false
2278
+ }
2279
+ ]
2280
+ },
2281
+ {
2282
+ name: "OAppSent",
2283
+ fields: [
2284
+ {
2285
+ name: "guid",
2286
+ type: {
2287
+ array: ["u8", 32]
2288
+ },
2289
+ index: false
2290
+ },
2291
+ {
2292
+ name: "dstEid",
2293
+ type: "u32",
2294
+ index: false
2295
+ }
2296
+ ]
2297
+ },
2298
+ {
2299
+ name: "OAppReceived",
2300
+ fields: [
2301
+ {
2302
+ name: "guid",
2303
+ type: {
2304
+ array: ["u8", 32]
2305
+ },
2306
+ index: false
2307
+ },
2308
+ {
2309
+ name: "srcEid",
2310
+ type: "u32",
2311
+ index: false
2312
+ }
2313
+ ]
2314
+ }
2315
+ ],
2316
+ errors: [
2317
+ {
2318
+ code: 6e3,
2319
+ name: "InsufficientFunds",
2320
+ msg: "Deposited funds are insufficient for withdrawal"
2321
+ },
2322
+ {
2323
+ code: 6001,
2324
+ name: "UserInfoBelongsToAnotherUser",
2325
+ msg: "User info pda belongs to another user"
2326
+ },
2327
+ {
2328
+ code: 6002,
2329
+ name: "BrokerNotAllowed",
2330
+ msg: "Broker is not allowed"
2331
+ },
2332
+ {
2333
+ code: 6003,
2334
+ name: "TokenNotAllowed",
2335
+ msg: "Token is not allowed"
2336
+ },
2337
+ {
2338
+ code: 6004,
2339
+ name: "InvalidAccountId",
2340
+ msg: "AccountId is invalid"
2341
+ },
2342
+ {
2343
+ code: 6005,
2344
+ name: "InvalidVaultOwner",
2345
+ msg: "Vault owner is not the same as the payer"
2346
+ },
2347
+ {
2348
+ code: 6006,
2349
+ name: "ManagerRoleNotAllowed",
2350
+ msg: "Manager role is not allowed"
2351
+ }
2352
+ ]
2353
+ };
2354
+
2355
+ // src/solana.util.ts
2356
+ import {
2357
+ DVN_CONFIG_SEED,
2358
+ ENDPOINT_SEED,
2359
+ ENFORCED_OPTIONS_SEED,
2360
+ EVENT_SEED,
2361
+ EXECUTOR_CONFIG_SEED,
2362
+ LZ_RECEIVE_TYPES_SEED,
2363
+ MESSAGE_LIB_SEED,
2364
+ NONCE_SEED,
2365
+ OAPP_SEED,
2366
+ PEER_SEED,
2367
+ PRICE_FEED_SEED,
2368
+ SEND_CONFIG_SEED,
2369
+ SEND_LIBRARY_CONFIG_SEED,
2370
+ ULN_SEED
2371
+ } from "@layerzerolabs/lz-solana-sdk-v2";
2372
+ import { getAssociatedTokenAddressSync } from "@solana/spl-token";
2373
+ import { PublicKey as PublicKey2 } from "@solana/web3.js";
2374
+ var getTokenAccounts = (token, owner) => {
2375
+ const tokenAccount = getAssociatedTokenAddressSync(token, owner, true);
2376
+ return tokenAccount;
2377
+ };
2378
+ function getVaultAuthorityPda(VAULT_PROGRAM_ID) {
2379
+ return PublicKey2.findProgramAddressSync(
2380
+ [Buffer.from(VAULT_AUTHORITY_SEED, "utf8")],
2381
+ VAULT_PROGRAM_ID
2382
+ )[0];
2383
+ }
2384
+ function getSolVaultPda(VAULT_PROGRAM_ID) {
2385
+ return PublicKey2.findProgramAddressSync(
2386
+ [Buffer.from(SOL_VAULT_SEED, "utf8")],
2387
+ VAULT_PROGRAM_ID
2388
+ )[0];
2389
+ }
2390
+ function getBrokerPDA(programId, brokerHash) {
2391
+ const hash = Array.from(Buffer.from(brokerHash.slice(2), "hex"));
2392
+ return PublicKey2.findProgramAddressSync(
2393
+ [Buffer.from(BROKER_SEED, "utf8"), Buffer.from(hash)],
2394
+ programId
2395
+ )[0];
2396
+ }
2397
+ function getTokenPDA(programId, tokenHash) {
2398
+ const hash = Array.from(Buffer.from(tokenHash.slice(2), "hex"));
2399
+ return PublicKey2.findProgramAddressSync(
2400
+ [Buffer.from(TOKEN_SEED, "utf8"), Buffer.from(hash)],
2401
+ programId
2402
+ )[0];
2403
+ }
2404
+ function getOAppConfigPda(programId) {
2405
+ return PublicKey2.findProgramAddressSync(
2406
+ [Buffer.from(OAPP_SEED, "utf8")],
2407
+ programId
2408
+ )[0];
2409
+ }
2410
+ function getPeerPda(OAPP_PROGRAM_ID, oappConfigPda, dstEid) {
2411
+ const bufferDstEid = Buffer.alloc(4);
2412
+ bufferDstEid.writeUInt32BE(dstEid);
2413
+ return PublicKey2.findProgramAddressSync(
2414
+ [Buffer.from(PEER_SEED, "utf8"), oappConfigPda.toBuffer(), bufferDstEid],
2415
+ OAPP_PROGRAM_ID
2416
+ )[0];
2417
+ }
2418
+ function getEndorcedOptionsPda(OAPP_PROGRAM_ID, oappConfigPda, dstEid) {
2419
+ const bufferDstEid = Buffer.alloc(4);
2420
+ bufferDstEid.writeUInt32BE(dstEid);
2421
+ return PublicKey2.findProgramAddressSync(
2422
+ [
2423
+ Buffer.from(ENFORCED_OPTIONS_SEED, "utf8"),
2424
+ oappConfigPda.toBuffer(),
2425
+ bufferDstEid
2426
+ ],
2427
+ OAPP_PROGRAM_ID
2428
+ )[0];
2429
+ }
2430
+ function getSendLibPda() {
2431
+ return PublicKey2.findProgramAddressSync(
2432
+ [Buffer.from(MESSAGE_LIB_SEED, "utf8")],
2433
+ SEND_LIB_PROGRAM_ID
2434
+ )[0];
2435
+ }
2436
+ function getSendLibConfigPda(oappConfigPda, dstEid) {
2437
+ const bufferDstEid = Buffer.alloc(4);
2438
+ bufferDstEid.writeUInt32BE(dstEid);
2439
+ return PublicKey2.findProgramAddressSync(
2440
+ [
2441
+ Buffer.from(SEND_LIBRARY_CONFIG_SEED, "utf8"),
2442
+ oappConfigPda.toBuffer(),
2443
+ bufferDstEid
2444
+ ],
2445
+ ENDPOINT_PROGRAM_ID
2446
+ )[0];
2447
+ }
2448
+ function getDefaultSendLibConfigPda(dstEid) {
2449
+ const bufferDstEid = Buffer.alloc(4);
2450
+ bufferDstEid.writeUInt32BE(dstEid);
2451
+ return PublicKey2.findProgramAddressSync(
2452
+ [Buffer.from(SEND_LIBRARY_CONFIG_SEED, "utf8"), bufferDstEid],
2453
+ ENDPOINT_PROGRAM_ID
2454
+ )[0];
2455
+ }
2456
+ function getSendLibInfoPda(sendLibPda) {
2457
+ return PublicKey2.findProgramAddressSync(
2458
+ [Buffer.from(MESSAGE_LIB_SEED, "utf8"), sendLibPda.toBuffer()],
2459
+ ENDPOINT_PROGRAM_ID
2460
+ )[0];
2461
+ }
2462
+ function getEndpointSettingPda() {
2463
+ return PublicKey2.findProgramAddressSync(
2464
+ [Buffer.from(ENDPOINT_SEED, "utf8")],
2465
+ ENDPOINT_PROGRAM_ID
2466
+ )[0];
2467
+ }
2468
+ function getPeerAddress(OAPP_PROGRAM_ID) {
2469
+ let peer_address = DEV_PEER_ADDRESS;
2470
+ if (OAPP_PROGRAM_ID.toBase58() === DEV_OAPP_PROGRAM_ID.toBase58()) {
2471
+ peer_address = DEV_PEER_ADDRESS;
2472
+ }
2473
+ if (OAPP_PROGRAM_ID.toBase58() === QA_OAPP_PROGRAM_ID.toBase58()) {
2474
+ peer_address = QA_PEER_ADDRESS;
2475
+ }
2476
+ if (OAPP_PROGRAM_ID.toBase58() === STAGING_OAPP_PROGRAM_ID.toBase58()) {
2477
+ peer_address = STAGING_PEER_ADDRESS;
2478
+ }
2479
+ if (OAPP_PROGRAM_ID.toBase58() === MAINNET_OAPP_PROGRAM_ID.toBase58()) {
2480
+ peer_address = MAINNET_PEER_ADDRESS;
2481
+ }
2482
+ return peer_address;
2483
+ }
2484
+ function getNoncePda(OAPP_PROGRAM_ID, oappConfigPda, dstEid) {
2485
+ const bufferDstEid = Buffer.alloc(4);
2486
+ const peer_address = getPeerAddress(OAPP_PROGRAM_ID);
2487
+ bufferDstEid.writeUInt32BE(dstEid);
2488
+ return PublicKey2.findProgramAddressSync(
2489
+ [
2490
+ Buffer.from(NONCE_SEED, "utf8"),
2491
+ oappConfigPda.toBuffer(),
2492
+ bufferDstEid,
2493
+ peer_address
2494
+ ],
2495
+ ENDPOINT_PROGRAM_ID
2496
+ )[0];
2497
+ }
2498
+ function getEventAuthorityPda() {
2499
+ return PublicKey2.findProgramAddressSync(
2500
+ [Buffer.from(EVENT_SEED, "utf8")],
2501
+ ENDPOINT_PROGRAM_ID
2502
+ )[0];
2503
+ }
2504
+ function getUlnSettingPda() {
2505
+ return PublicKey2.findProgramAddressSync(
2506
+ [Buffer.from(ULN_SEED, "utf8")],
2507
+ SEND_LIB_PROGRAM_ID
2508
+ )[0];
2509
+ }
2510
+ function getSendConfigPda(oappConfigPda, dstEid) {
2511
+ const bufferDstEid = Buffer.alloc(4);
2512
+ bufferDstEid.writeUInt32BE(dstEid);
2513
+ return PublicKey2.findProgramAddressSync(
2514
+ [
2515
+ Buffer.from(SEND_CONFIG_SEED, "utf8"),
2516
+ bufferDstEid,
2517
+ oappConfigPda.toBuffer()
2518
+ ],
2519
+ SEND_LIB_PROGRAM_ID
2520
+ )[0];
2521
+ }
2522
+ function getDefaultSendConfigPda(dstEid) {
2523
+ const bufferDstEid = Buffer.alloc(4);
2524
+ bufferDstEid.writeUInt32BE(dstEid);
2525
+ return PublicKey2.findProgramAddressSync(
2526
+ [Buffer.from(SEND_CONFIG_SEED, "utf8"), bufferDstEid],
2527
+ RECEIVE_LIB_PROGRAM_ID
2528
+ )[0];
2529
+ }
2530
+ function getUlnEventAuthorityPda() {
2531
+ return PublicKey2.findProgramAddressSync(
2532
+ [Buffer.from(EVENT_SEED, "utf8")],
2533
+ SEND_LIB_PROGRAM_ID
2534
+ )[0];
2535
+ }
2536
+ function getExecutorConfigPda() {
2537
+ return PublicKey2.findProgramAddressSync(
2538
+ [Buffer.from(EXECUTOR_CONFIG_SEED, "utf8")],
2539
+ EXECUTOR_PROGRAM_ID
2540
+ )[0];
2541
+ }
2542
+ function getPriceFeedPda() {
2543
+ return PublicKey2.findProgramAddressSync(
2544
+ [Buffer.from(PRICE_FEED_SEED, "utf8")],
2545
+ PRICE_FEED_PROGRAM_ID
2546
+ )[0];
2547
+ }
2548
+ function getDvnConfigPda() {
2549
+ return PublicKey2.findProgramAddressSync(
2550
+ [Buffer.from(DVN_CONFIG_SEED, "utf8")],
2551
+ DVN_PROGRAM_ID
2552
+ )[0];
2553
+ }
2554
+ function getDstEID(OAPP_PROGRAM_ID) {
2555
+ if (OAPP_PROGRAM_ID.toBase58() === MAINNET_OAPP_PROGRAM_ID.toBase58()) {
2556
+ return MAIN_DST_EID;
2557
+ }
2558
+ return DEV_DST_EID;
2559
+ }
2560
+ function getLookupTableAddress(OAPP_PROGRAM_ID) {
2561
+ if (OAPP_PROGRAM_ID.toBase58() === DEV_OAPP_PROGRAM_ID.toBase58()) {
2562
+ console.log(
2563
+ "DEV_LOOKUP_TABLE_ADDRESS: ",
2564
+ DEV_LOOKUP_TABLE_ADDRESS.toBase58()
2565
+ );
2566
+ return DEV_LOOKUP_TABLE_ADDRESS;
2567
+ }
2568
+ if (OAPP_PROGRAM_ID.toBase58() === QA_OAPP_PROGRAM_ID.toBase58()) {
2569
+ return QA_LOOKUP_TABLE_ADDRESS;
2570
+ }
2571
+ if (OAPP_PROGRAM_ID.toBase58() === STAGING_OAPP_PROGRAM_ID.toBase58()) {
2572
+ return STAGING_LOOKUP_TABLE_ADDRESS;
2573
+ }
2574
+ if (OAPP_PROGRAM_ID.toBase58() === MAINNET_OAPP_PROGRAM_ID.toBase58()) {
2575
+ return MAINNET_LOOKUP_TABLE_ADDRESS;
2576
+ }
2577
+ return DEV_LOOKUP_TABLE_ADDRESS;
2578
+ }
2579
+ function getMessageLibPda(programId) {
2580
+ return PublicKey2.findProgramAddressSync(
2581
+ [Buffer.from(MESSAGE_LIB_SEED, "utf8")],
2582
+ programId ? programId : SEND_LIB_PROGRAM_ID
2583
+ )[0];
2584
+ }
2585
+ function getMessageLibInfoPda(msgLibPda, programId) {
2586
+ return PublicKey2.findProgramAddressSync(
2587
+ [Buffer.from(MESSAGE_LIB_SEED, "utf8"), msgLibPda.toBytes()],
2588
+ programId ? programId : ENDPOINT_PROGRAM_ID
2589
+ )[0];
2590
+ }
2591
+ function getLookupTableAccount(connection, lookupTableAddress) {
2592
+ return __async(this, null, function* () {
2593
+ const lookupTableAccount = (yield connection.getAddressLookupTable(lookupTableAddress)).value;
2594
+ return lookupTableAccount;
2595
+ });
2596
+ }
2597
+
2598
+ // src/helper.ts
2599
+ function addOrderlyKeyMessage(inputs) {
2600
+ const {
2601
+ publicKey,
2602
+ brokerId,
2603
+ expiration = 365,
2604
+ timestamp = Date.now(),
2605
+ scope,
2606
+ tag,
2607
+ chainId,
2608
+ subAccountId
2609
+ } = inputs;
2610
+ const message = __spreadValues(__spreadValues({
2611
+ brokerId,
2612
+ chainType: "SOL",
2613
+ orderlyKey: publicKey,
2614
+ scope: scope || DEFAUL_ORDERLY_KEY_SCOPE,
2615
+ chainId,
2616
+ timestamp,
2617
+ expiration: timestamp + 1e3 * 60 * 60 * 24 * expiration
2618
+ }, typeof tag !== "undefined" ? { tag } : {}), typeof subAccountId !== "undefined" ? { subAccountId } : {});
2619
+ const brokerIdHash = solidityPackedKeccak256(["string"], [message.brokerId]);
2620
+ const orderlyKeyHash = solidityPackedKeccak256(
2621
+ ["string"],
2622
+ [message.orderlyKey]
2623
+ );
2624
+ const scopeHash = solidityPackedKeccak256(["string"], [message.scope]);
2625
+ const abicoder = AbiCoder.defaultAbiCoder();
2626
+ const msgToSign = keccak256(
2627
+ hexToBytes(
2628
+ abicoder.encode(
2629
+ ["bytes32", "bytes32", "bytes32", "uint256", "uint256", "uint256"],
2630
+ [
2631
+ brokerIdHash,
2632
+ orderlyKeyHash,
2633
+ scopeHash,
2634
+ message.chainId,
2635
+ message.timestamp,
2636
+ message.expiration
2637
+ ]
2638
+ )
2639
+ )
2640
+ );
2641
+ const msgToSignHex = bytesToHex(msgToSign);
2642
+ const msgToSignTextEncoded = new TextEncoder().encode(
2643
+ msgToSignHex
2644
+ );
2645
+ return [message, msgToSignTextEncoded];
2646
+ }
2647
+ function registerAccountMessage(inputs) {
2648
+ const { chainId, registrationNonce, brokerId, timestamp } = inputs;
2649
+ const message = {
2650
+ brokerId,
2651
+ chainId,
2652
+ timestamp,
2653
+ registrationNonce
2654
+ };
2655
+ const brokerIdHash = solidityPackedKeccak256(["string"], [message.brokerId]);
2656
+ const abicoder = AbiCoder.defaultAbiCoder();
2657
+ const msgToSign = keccak256(
2658
+ hexToBytes(
2659
+ abicoder.encode(
2660
+ ["bytes32", "uint256", "uint256", "uint256"],
2661
+ [
2662
+ brokerIdHash,
2663
+ message.chainId,
2664
+ message.timestamp,
2665
+ message.registrationNonce
2666
+ ]
2667
+ )
2668
+ )
2669
+ );
2670
+ const msgToSignHex = bytesToHex(msgToSign);
2671
+ const msgToSignTextEncoded = new TextEncoder().encode(
2672
+ msgToSignHex
2673
+ );
2674
+ return [message, msgToSignTextEncoded];
2675
+ }
2676
+ function internalTransferMessage(inputs) {
2677
+ const { chainId, receiver, token, amount, nonce } = inputs;
2678
+ const message = {
2679
+ chainId,
2680
+ receiver,
2681
+ token,
2682
+ amount,
2683
+ transferNonce: nonce,
2684
+ chainType: "SOL"
2685
+ };
2686
+ const tokenSymbolHash = solidityPackedKeccak256(["string"], [message.token]);
2687
+ const abicoder = AbiCoder.defaultAbiCoder();
2688
+ const msgToSign = keccak256(
2689
+ hexToBytes(
2690
+ abicoder.encode(
2691
+ ["bytes32", "bytes32", "uint256", "uint64", "uint256"],
2692
+ [
2693
+ message.receiver,
2694
+ tokenSymbolHash,
2695
+ message.amount,
2696
+ message.transferNonce,
2697
+ chainId
2698
+ ]
2699
+ )
2700
+ )
2701
+ );
2702
+ const msgToSignHex = bytesToHex(msgToSign);
2703
+ const msgToSignTextEncoded = new TextEncoder().encode(
2704
+ msgToSignHex
2705
+ );
2706
+ return [message, msgToSignTextEncoded];
2707
+ }
2708
+ function dexRequestMessage(inputs) {
2709
+ return __async(this, null, function* () {
2710
+ const {
2711
+ payloadType,
2712
+ nonce,
2713
+ receiver,
2714
+ amount,
2715
+ vaultId,
2716
+ token,
2717
+ dexBrokerId,
2718
+ chainId
2719
+ } = inputs;
2720
+ const message = {
2721
+ payloadType,
2722
+ nonce,
2723
+ receiver,
2724
+ amount,
2725
+ vaultId,
2726
+ token,
2727
+ dexBrokerId,
2728
+ chainId
2729
+ };
2730
+ let receiverBytes;
2731
+ receiverBytes = bs58Decode(receiver);
2732
+ const receiverBytes32 = new Uint8Array(32);
2733
+ receiverBytes32.set(receiverBytes);
2734
+ const vaultIdHex = vaultId;
2735
+ const vaultIdBytes = hexToBytes(vaultIdHex);
2736
+ const tokenHash = keccak256(new TextEncoder().encode(token));
2737
+ const dexBrokerIdHash = keccak256(new TextEncoder().encode(dexBrokerId));
2738
+ const abicoder = AbiCoder.defaultAbiCoder();
2739
+ const msgToSign = keccak256(
2740
+ hexToBytes(
2741
+ abicoder.encode(
2742
+ [
2743
+ "uint8",
2744
+ // payloadType
2745
+ "uint256",
2746
+ // nonce
2747
+ "bytes32",
2748
+ // receiver (Base58 decoded)
2749
+ "uint256",
2750
+ // amount
2751
+ "bytes32",
2752
+ // vaultId
2753
+ "bytes32",
2754
+ // token hash
2755
+ "bytes32",
2756
+ // dexBrokerId hash
2757
+ "uint256"
2758
+ // chainId
2759
+ ],
2760
+ [
2761
+ payloadType,
2762
+ nonce,
2763
+ receiverBytes,
2764
+ amount,
2765
+ vaultIdBytes,
2766
+ tokenHash,
2767
+ dexBrokerIdHash,
2768
+ chainId
2769
+ ]
2770
+ )
2771
+ )
2772
+ );
2773
+ const msgToSignHex = bytesToHex(msgToSign);
2774
+ const msgToSignTextEncoded = new TextEncoder().encode(
2775
+ msgToSignHex
2776
+ );
2777
+ return [message, msgToSignTextEncoded];
2778
+ });
2779
+ }
2780
+ function withdrawMessage(inputs) {
2781
+ const { chainId, receiver, token, amount, nonce, brokerId } = inputs;
2782
+ const timestamp = Date.now();
2783
+ const message = {
2784
+ brokerId,
2785
+ chainId,
2786
+ receiver,
2787
+ token,
2788
+ amount,
2789
+ withdrawNonce: nonce,
2790
+ timestamp,
2791
+ chainType: "SOL"
2792
+ };
2793
+ const brokerIdHash = solidityPackedKeccak256(["string"], [message.brokerId]);
2794
+ const tokenSymbolHash = solidityPackedKeccak256(["string"], [message.token]);
2795
+ const salt = keccak256(Buffer.from("Orderly Network"));
2796
+ const abicoder = AbiCoder.defaultAbiCoder();
2797
+ const msgToSign = keccak256(
2798
+ hexToBytes(
2799
+ abicoder.encode(
2800
+ [
2801
+ "bytes32",
2802
+ "bytes32",
2803
+ "uint256",
2804
+ "bytes32",
2805
+ "uint256",
2806
+ "uint64",
2807
+ "uint64",
2808
+ "bytes32"
2809
+ ],
2810
+ [
2811
+ brokerIdHash,
2812
+ tokenSymbolHash,
2813
+ chainId,
2814
+ bs58Decode(message.receiver),
2815
+ message.amount,
2816
+ message.withdrawNonce,
2817
+ timestamp,
2818
+ salt
2819
+ ]
2820
+ )
2821
+ )
2822
+ );
2823
+ const msgToSignHex = bytesToHex(msgToSign);
2824
+ const msgToSignTextEncoded = new TextEncoder().encode(
2825
+ msgToSignHex
2826
+ );
2827
+ return [message, msgToSignTextEncoded];
2828
+ }
2829
+ function settleMessage(inputs) {
2830
+ const { settlePnlNonce, brokerId, chainId, timestamp } = inputs;
2831
+ const message = {
2832
+ brokerId,
2833
+ chainId,
2834
+ timestamp,
2835
+ chainType: "SOL",
2836
+ settleNonce: settlePnlNonce
2837
+ };
2838
+ const brokerIdHash = solidityPackedKeccak256(["string"], [brokerId]);
2839
+ const abicoder = AbiCoder.defaultAbiCoder();
2840
+ const msgToSign = keccak256(
2841
+ hexToBytes(
2842
+ abicoder.encode(
2843
+ ["bytes32", "uint256", "uint64", "uint64"],
2844
+ [brokerIdHash, message.chainId, message.settleNonce, message.timestamp]
2845
+ )
2846
+ )
2847
+ );
2848
+ const msgToSignHex = bytesToHex(msgToSign);
2849
+ const msgToSignTextEncoded = new TextEncoder().encode(
2850
+ msgToSignHex
2851
+ );
2852
+ return [message, msgToSignTextEncoded];
2853
+ }
2854
+ function getDepositQuoteFee(_0) {
2855
+ return __async(this, arguments, function* ({
2856
+ vaultAddress,
2857
+ userAddress,
2858
+ connection,
2859
+ depositData
2860
+ }) {
2861
+ console.log("-- vaultAddress", vaultAddress);
2862
+ const appProgramId = new PublicKey3(vaultAddress);
2863
+ const DST_EID = getDstEID(appProgramId);
2864
+ const program = new Program(IDL, appProgramId, {
2865
+ connection
2866
+ });
2867
+ const userPublicKey = new PublicKey3(userAddress);
2868
+ const oappConfigPDA = getOAppConfigPda(appProgramId);
2869
+ const peerPDA = getPeerPda(appProgramId, oappConfigPDA, DST_EID);
2870
+ const endorcedPDA = getEndorcedOptionsPda(
2871
+ appProgramId,
2872
+ oappConfigPDA,
2873
+ DST_EID
2874
+ );
2875
+ const sendLibConfigPDA = getSendLibConfigPda(oappConfigPDA, DST_EID);
2876
+ const defaultSendLibPDA = getDefaultSendLibConfigPda(DST_EID);
2877
+ const endpointSettingPDA = getEndpointSettingPda();
2878
+ const noncePDA = getNoncePda(appProgramId, oappConfigPDA, DST_EID);
2879
+ const sendConfigPDA = getSendConfigPda(oappConfigPDA, DST_EID);
2880
+ const defaultSendConfigPDA = getDefaultSendConfigPda(DST_EID);
2881
+ const executorConfigPDA = getExecutorConfigPda();
2882
+ const priceFeedPDA = getPriceFeedPda();
2883
+ const dvnConfigPDA = getDvnConfigPda();
2884
+ const messageLibPDA = getMessageLibPda(SEND_LIB_PROGRAM_ID);
2885
+ const messageLibInfoPDA = getMessageLibInfoPda(messageLibPDA);
2886
+ const vaultAuthorityPDA = getVaultAuthorityPda(appProgramId);
2887
+ const depositParams = getDepositParams(userAddress, depositData);
2888
+ const quoteFee = yield program.methods.oappQuote(depositParams).accounts({
2889
+ oappConfig: oappConfigPDA,
2890
+ peer: peerPDA,
2891
+ enforcedOptions: endorcedPDA,
2892
+ vaultAuthority: vaultAuthorityPDA
2893
+ }).remainingAccounts([
2894
+ // ENDPOINT solana/programs/programs/uln/src/instructions/endpoint/send.rs
2895
+ {
2896
+ pubkey: ENDPOINT_PROGRAM_ID,
2897
+ isWritable: false,
2898
+ isSigner: false
2899
+ },
2900
+ {
2901
+ pubkey: SEND_LIB_PROGRAM_ID,
2902
+ isWritable: false,
2903
+ isSigner: false
2904
+ },
2905
+ {
2906
+ pubkey: sendLibConfigPDA,
2907
+ // send_library_config
2908
+ isWritable: false,
2909
+ isSigner: false
2910
+ },
2911
+ {
2912
+ pubkey: defaultSendLibPDA,
2913
+ // default_send_library_config
2914
+ isWritable: false,
2915
+ isSigner: false
2916
+ },
2917
+ {
2918
+ pubkey: messageLibInfoPDA,
2919
+ // send_library_info
2920
+ isWritable: false,
2921
+ isSigner: false
2922
+ },
2923
+ {
2924
+ pubkey: endpointSettingPDA,
2925
+ // endpoint settings
2926
+ isWritable: false,
2927
+ isSigner: false
2928
+ },
2929
+ {
2930
+ pubkey: noncePDA,
2931
+ // nonce
2932
+ isWritable: false,
2933
+ isSigner: false
2934
+ },
2935
+ {
2936
+ pubkey: messageLibPDA,
2937
+ isWritable: false,
2938
+ isSigner: false
2939
+ },
2940
+ {
2941
+ pubkey: sendConfigPDA,
2942
+ isWritable: false,
2943
+ isSigner: false
2944
+ },
2945
+ {
2946
+ pubkey: defaultSendConfigPDA,
2947
+ isWritable: false,
2948
+ isSigner: false
2949
+ },
2950
+ {
2951
+ pubkey: EXECUTOR_PROGRAM_ID,
2952
+ isWritable: false,
2953
+ isSigner: false
2954
+ },
2955
+ {
2956
+ pubkey: executorConfigPDA,
2957
+ isWritable: false,
2958
+ isSigner: false
2959
+ },
2960
+ {
2961
+ pubkey: PRICE_FEED_PROGRAM_ID,
2962
+ isWritable: false,
2963
+ isSigner: false
2964
+ },
2965
+ {
2966
+ pubkey: priceFeedPDA,
2967
+ isWritable: false,
2968
+ isSigner: false
2969
+ },
2970
+ {
2971
+ pubkey: DVN_PROGRAM_ID,
2972
+ isWritable: false,
2973
+ isSigner: false
2974
+ },
2975
+ {
2976
+ pubkey: dvnConfigPDA,
2977
+ isWritable: false,
2978
+ isSigner: false
2979
+ },
2980
+ {
2981
+ pubkey: PRICE_FEED_PROGRAM_ID,
2982
+ isWritable: false,
2983
+ isSigner: false
2984
+ },
2985
+ {
2986
+ pubkey: priceFeedPDA,
2987
+ isWritable: false,
2988
+ isSigner: false
2989
+ }
2990
+ ]).instruction();
2991
+ const lastBlockHash = yield connection.getLatestBlockhash();
2992
+ const lookupTableAddress = getLookupTableAddress(appProgramId);
2993
+ const lookupTableAccount = yield getLookupTableAccount(
2994
+ connection,
2995
+ lookupTableAddress
2996
+ );
2997
+ if (!lookupTableAccount) {
2998
+ console.log("-- lookup table account error");
2999
+ throw new Error("-- lookup table account error");
3000
+ }
3001
+ const feeMsg = new TransactionMessage({
3002
+ payerKey: userPublicKey,
3003
+ recentBlockhash: lastBlockHash.blockhash,
3004
+ instructions: [quoteFee]
3005
+ }).compileToV0Message([lookupTableAccount]);
3006
+ const feeTx = new VersionedTransaction(feeMsg);
3007
+ const feeRes = yield connection.simulateTransaction(feeTx);
3008
+ console.log("-- feeRes", feeRes);
3009
+ if (feeRes.value.err) {
3010
+ const errorInfo = typeof feeRes.value.err === "object" ? JSON.stringify(feeRes.value.err) : feeRes.value.err;
3011
+ if (errorInfo.toString().includes("AccountNotFound")) {
3012
+ throw new Error("Error: Account gas is insufficient.");
3013
+ }
3014
+ throw new Error(`Error: ${errorInfo}`);
3015
+ }
3016
+ const returnPrefix = `Program return: ${program.programId} `;
3017
+ const returnLogEntry = feeRes.value.logs.find(
3018
+ (log) => log.startsWith(returnPrefix)
3019
+ );
3020
+ if (!returnLogEntry) {
3021
+ throw new Error("Error: get deposit fee error");
3022
+ }
3023
+ const encodedReturnData = returnLogEntry.slice(returnPrefix.length);
3024
+ const decodedBuffer = Buffer.from(encodedReturnData, "base64");
3025
+ console.log(
3026
+ decodedBuffer.readBigUInt64LE(0),
3027
+ decodedBuffer.readBigUInt64LE(1)
3028
+ );
3029
+ return decodedBuffer.readBigUInt64LE(0);
3030
+ });
3031
+ }
3032
+ var getDepositParams = (userAddress, depositData) => {
3033
+ const brokerHash = depositData.brokerHash;
3034
+ const codedBrokerHash = Array.from(Buffer.from(brokerHash.slice(2), "hex"));
3035
+ const tokenHash = depositData.tokenHash;
3036
+ const codedTokenHash = Array.from(Buffer.from(tokenHash.slice(2), "hex"));
3037
+ const solAccountId = depositData.accountId;
3038
+ const codedAccountId = Array.from(Buffer.from(solAccountId.slice(2), "hex"));
3039
+ const userPublicKey = new PublicKey3(userAddress);
3040
+ return {
3041
+ accountId: codedAccountId,
3042
+ brokerHash: codedBrokerHash,
3043
+ tokenHash: codedTokenHash,
3044
+ userAddress: Array.from(userPublicKey.toBuffer()),
3045
+ tokenAmount: new BN(depositData.tokenAmount)
3046
+ };
3047
+ };
3048
+ function deposit(_0) {
3049
+ return __async(this, arguments, function* ({
3050
+ vaultAddress,
3051
+ userAddress,
3052
+ connection,
3053
+ sendTransaction,
3054
+ depositData
3055
+ }) {
3056
+ const brokerHash = depositData.brokerHash;
3057
+ const tokenHash = depositData.tokenHash;
3058
+ const SOL_HASH = CoreUtils.parseTokenHash("SOL");
3059
+ const isSolDeposit = tokenHash.toLowerCase() === SOL_HASH.toLowerCase();
3060
+ console.log("-- vault address", vaultAddress);
3061
+ const appProgramId = new PublicKey3(vaultAddress);
3062
+ const program = new Program(IDL, appProgramId, {
3063
+ connection
3064
+ });
3065
+ const token = new PublicKey3(depositData.tokenAddress);
3066
+ const userPublicKey = new PublicKey3(userAddress);
3067
+ const userTokenAccount = getTokenAccounts(token, userPublicKey);
3068
+ const vaultAuthorityPda = getVaultAuthorityPda(appProgramId);
3069
+ const vaultTokenAccount = getTokenAccounts(token, vaultAuthorityPda);
3070
+ const allowedBrokerPDA = getBrokerPDA(appProgramId, brokerHash);
3071
+ const allowedTokenPDA = getTokenPDA(appProgramId, tokenHash);
3072
+ const oappConfigPDA = getOAppConfigPda(appProgramId);
3073
+ console.log("-- oappconfig pda", oappConfigPDA.toBase58());
3074
+ const DST_EID = getDstEID(appProgramId);
3075
+ const peerPDA = getPeerPda(appProgramId, oappConfigPDA, DST_EID);
3076
+ const endorcedPDA = getEndorcedOptionsPda(
3077
+ appProgramId,
3078
+ oappConfigPDA,
3079
+ DST_EID
3080
+ );
3081
+ const sendLibPDA = getSendLibPda();
3082
+ const sendLibConfigPDA = getSendLibConfigPda(oappConfigPDA, DST_EID);
3083
+ const defaultSendLibPDA = getDefaultSendLibConfigPda(DST_EID);
3084
+ const sendLibInfoPDA = getSendLibInfoPda(sendLibPDA);
3085
+ const endpointSettingPDA = getEndpointSettingPda();
3086
+ const noncePDA = getNoncePda(appProgramId, oappConfigPDA, DST_EID);
3087
+ const eventAuthorityPDA = getEventAuthorityPda();
3088
+ const ulnSettingPDA = getUlnSettingPda();
3089
+ const sendConfigPDA = getSendConfigPda(oappConfigPDA, DST_EID);
3090
+ const defaultSendConfigPDA = getDefaultSendConfigPda(DST_EID);
3091
+ const ulnEventAuthorityPDA = getUlnEventAuthorityPda();
3092
+ const executorConfigPDA = getExecutorConfigPda();
3093
+ const priceFeedPDA = getPriceFeedPda();
3094
+ const dvnConfigPDA = getDvnConfigPda();
3095
+ const vaultDepositParams = getDepositParams(userAddress, depositData);
3096
+ const buildSendRemainingAccounts = () => [
3097
+ // ENDPOINT solana/programs/programs/uln/src/instructions/endpoint/send.rs
3098
+ {
3099
+ isSigner: false,
3100
+ isWritable: false,
3101
+ pubkey: ENDPOINT_PROGRAM_ID
3102
+ },
3103
+ {
3104
+ isSigner: false,
3105
+ isWritable: false,
3106
+ // 0
3107
+ pubkey: oappConfigPDA
3108
+ },
3109
+ {
3110
+ isSigner: false,
3111
+ isWritable: false,
3112
+ pubkey: SEND_LIB_PROGRAM_ID
3113
+ },
3114
+ {
3115
+ isSigner: false,
3116
+ isWritable: false,
3117
+ // 7
3118
+ pubkey: sendLibConfigPDA
3119
+ },
3120
+ {
3121
+ isSigner: false,
3122
+ isWritable: false,
3123
+ // 9
3124
+ pubkey: defaultSendLibPDA
3125
+ },
3126
+ {
3127
+ isSigner: false,
3128
+ isWritable: false,
3129
+ // 8
3130
+ pubkey: sendLibInfoPDA
3131
+ },
3132
+ {
3133
+ isSigner: false,
3134
+ isWritable: false,
3135
+ // 14
3136
+ pubkey: endpointSettingPDA
3137
+ },
3138
+ {
3139
+ isSigner: false,
3140
+ isWritable: true,
3141
+ // 15
3142
+ pubkey: noncePDA
3143
+ },
3144
+ {
3145
+ isSigner: false,
3146
+ isWritable: false,
3147
+ // 3
3148
+ pubkey: eventAuthorityPDA
3149
+ },
3150
+ // ULN solana/programs/programs/uln/src/instructions/endpoint/send.rs
3151
+ {
3152
+ isSigner: false,
3153
+ isWritable: false,
3154
+ pubkey: ENDPOINT_PROGRAM_ID
3155
+ },
3156
+ {
3157
+ isSigner: false,
3158
+ isWritable: false,
3159
+ // 13
3160
+ pubkey: ulnSettingPDA
3161
+ },
3162
+ {
3163
+ isSigner: false,
3164
+ isWritable: false,
3165
+ // 10
3166
+ pubkey: sendConfigPDA
3167
+ },
3168
+ {
3169
+ isSigner: false,
3170
+ isWritable: false,
3171
+ // 11
3172
+ pubkey: defaultSendConfigPDA
3173
+ },
3174
+ {
3175
+ isSigner: true,
3176
+ isWritable: false,
3177
+ pubkey: userPublicKey
3178
+ },
3179
+ {
3180
+ isSigner: false,
3181
+ isWritable: false,
3182
+ pubkey: TREASURY_PROGRAM_ID
3183
+ },
3184
+ {
3185
+ isSigner: false,
3186
+ isWritable: false,
3187
+ pubkey: SystemProgram.programId
3188
+ },
3189
+ {
3190
+ isSigner: false,
3191
+ isWritable: false,
3192
+ // 12
3193
+ pubkey: ulnEventAuthorityPDA
3194
+ },
3195
+ {
3196
+ isSigner: false,
3197
+ isWritable: false,
3198
+ pubkey: SEND_LIB_PROGRAM_ID
3199
+ },
3200
+ {
3201
+ isSigner: false,
3202
+ isWritable: false,
3203
+ pubkey: EXECUTOR_PROGRAM_ID
3204
+ },
3205
+ {
3206
+ isSigner: false,
3207
+ isWritable: true,
3208
+ // 16
3209
+ pubkey: executorConfigPDA
3210
+ },
3211
+ {
3212
+ isSigner: false,
3213
+ isWritable: false,
3214
+ pubkey: PRICE_FEED_PROGRAM_ID
3215
+ },
3216
+ {
3217
+ isSigner: false,
3218
+ isWritable: false,
3219
+ // 17
3220
+ pubkey: priceFeedPDA
3221
+ },
3222
+ {
3223
+ isSigner: false,
3224
+ isWritable: false,
3225
+ pubkey: DVN_PROGRAM_ID
3226
+ },
3227
+ {
3228
+ isSigner: false,
3229
+ isWritable: true,
3230
+ // 18
3231
+ pubkey: dvnConfigPDA
3232
+ },
3233
+ {
3234
+ isSigner: false,
3235
+ isWritable: false,
3236
+ pubkey: PRICE_FEED_PROGRAM_ID
3237
+ },
3238
+ {
3239
+ isSigner: false,
3240
+ isWritable: false,
3241
+ // 17
3242
+ pubkey: priceFeedPDA
3243
+ }
3244
+ ];
3245
+ const fee = yield getDepositQuoteFee({
3246
+ vaultAddress,
3247
+ userAddress,
3248
+ connection,
3249
+ depositData
3250
+ });
3251
+ const sendParam = {
3252
+ nativeFee: new BN(fee.toString()),
3253
+ lzTokenFee: new BN(0)
3254
+ };
3255
+ console.log("--- value params", {
3256
+ vaultDepositParams,
3257
+ sendParam
3258
+ });
3259
+ const ixDepositEntry = isSolDeposit ? yield program.methods.depositSol(vaultDepositParams, sendParam).accounts({
3260
+ solVault: getSolVaultPda(appProgramId),
3261
+ vaultAuthority: vaultAuthorityPda,
3262
+ user: userPublicKey,
3263
+ peer: peerPDA,
3264
+ enforcedOptions: endorcedPDA,
3265
+ oappConfig: oappConfigPDA,
3266
+ allowedBroker: allowedBrokerPDA,
3267
+ allowedToken: allowedTokenPDA
3268
+ }).remainingAccounts(buildSendRemainingAccounts()).instruction() : yield program.methods.deposit(vaultDepositParams, sendParam).accounts({
3269
+ userTokenAccount,
3270
+ vaultAuthority: vaultAuthorityPda,
3271
+ vaultTokenAccount,
3272
+ depositToken: token,
3273
+ user: userPublicKey,
3274
+ peer: peerPDA,
3275
+ enforcedOptions: endorcedPDA,
3276
+ oappConfig: oappConfigPDA,
3277
+ allowedBroker: allowedBrokerPDA,
3278
+ allowedToken: allowedTokenPDA
3279
+ }).remainingAccounts(buildSendRemainingAccounts()).instruction();
3280
+ const lookupTableAddress = getLookupTableAddress(appProgramId);
3281
+ const lookupTableAccount = yield getLookupTableAccount(
3282
+ connection,
3283
+ lookupTableAddress
3284
+ );
3285
+ if (!lookupTableAccount) {
3286
+ console.log("-- lookup table account error");
3287
+ return;
3288
+ }
3289
+ const ixAddComputeBudget = ComputeBudgetProgram.setComputeUnitLimit({
3290
+ units: 4e5
3291
+ });
3292
+ const lastBlockHash = yield connection.getLatestBlockhash();
3293
+ const msg = new TransactionMessage({
3294
+ payerKey: userPublicKey,
3295
+ recentBlockhash: lastBlockHash.blockhash,
3296
+ instructions: [ixDepositEntry, ixAddComputeBudget]
3297
+ }).compileToV0Message([lookupTableAccount]);
3298
+ const tx = new VersionedTransaction(msg);
3299
+ const res = yield sendTransaction(tx, connection);
3300
+ console.log("res", res);
3301
+ return res;
3302
+ });
3303
+ }
3304
+ function checkIsLedgerWallet(userAddress) {
3305
+ const info = window.localStorage.getItem(LedgerWalletKey);
3306
+ if (!info) {
3307
+ return false;
3308
+ }
3309
+ const addressArr = JSON.parse(info != null ? info : "[]");
3310
+ console.log("-- addressArr", addressArr);
3311
+ if (addressArr.includes(userAddress)) {
3312
+ return true;
3313
+ }
3314
+ return false;
3315
+ }
3316
+
3317
+ // src/walletAdapter.ts
3318
+ var DefaultSolanaWalletAdapter = class extends BaseWalletAdapter {
3319
+ constructor() {
3320
+ super();
3321
+ __publicField(this, "chainNamespace", ChainNamespace.solana);
3322
+ __publicField(this, "_address");
3323
+ __publicField(this, "_chainId");
3324
+ __publicField(this, "_provider");
3325
+ __publicField(this, "_connection");
3326
+ }
3327
+ get address() {
3328
+ return this._address;
3329
+ }
3330
+ get chainId() {
3331
+ return this._chainId;
3332
+ }
3333
+ set chainId(chainId) {
3334
+ this._chainId = chainId;
3335
+ }
3336
+ get connection() {
3337
+ if (this._connection) {
3338
+ return this._connection;
3339
+ }
3340
+ if (this._provider.rpcUrl) {
3341
+ this._connection = new Connection3(this._provider.rpcUrl, {
3342
+ commitment: "confirmed"
3343
+ });
3344
+ return this._connection;
3345
+ }
3346
+ if (this._provider.network === WalletAdapterNetwork.Devnet) {
3347
+ this._connection = new Connection3(clusterApiUrl(this._provider.network), {
3348
+ commitment: "confirmed"
3349
+ });
3350
+ return this._connection;
3351
+ }
3352
+ const account = SimpleDI.get("account");
3353
+ const url = "/v1/solana-rpc-proxy";
3354
+ this._connection = new Connection3(`${account.apiBaseUrl}${url}`, {
3355
+ commitment: "confirmed",
3356
+ fetchMiddleware: (info, init, fetch) => __async(this, null, function* () {
3357
+ const payload = {
3358
+ url,
3359
+ method: init == null ? void 0 : init.method,
3360
+ data: JSON.parse(init == null ? void 0 : init.body)
3361
+ };
3362
+ const signature = yield this.signMessageByOrderlyKey(payload);
3363
+ for (const key of Object.keys(signature)) {
3364
+ (init == null ? void 0 : init.headers)[key] = signature[key];
3365
+ }
3366
+ return fetch(info, init);
3367
+ })
3368
+ });
3369
+ return this._connection;
3370
+ }
3371
+ setConfig(config) {
3372
+ this._address = config.address;
3373
+ this._chainId = config.chain.id;
3374
+ if (config.provider) {
3375
+ this._provider = config.provider;
3376
+ }
3377
+ }
3378
+ lifecycleName(name, data) {
3379
+ console.log("lifecycle", name, data);
3380
+ }
3381
+ active(config) {
3382
+ this.setConfig(config);
3383
+ this.lifecycleName("active", config);
3384
+ }
3385
+ deactivate() {
3386
+ this.lifecycleName("deactivate", {});
3387
+ }
3388
+ update(config) {
3389
+ this.lifecycleName("update", config);
3390
+ this.setConfig(config);
3391
+ }
3392
+ generateSecretKey() {
3393
+ let privKey, secretKey;
3394
+ do {
3395
+ privKey = ed.utils.randomPrivateKey();
3396
+ secretKey = bs58encode(privKey);
3397
+ } while (secretKey.length !== 44);
3398
+ return secretKey;
3399
+ }
3400
+ uint8ArrayToHexString(uint8Array) {
3401
+ return Array.from(uint8Array).map((byte) => byte.toString(16).padStart(2, "0")).join("");
3402
+ }
3403
+ signMessage(message) {
3404
+ return __async(this, null, function* () {
3405
+ const isLedger = checkIsLedgerWallet(this._address);
3406
+ if (isLedger) {
3407
+ const transaction = new Transaction();
3408
+ transaction.add(
3409
+ new TransactionInstruction({
3410
+ keys: [],
3411
+ programId: new PublicKey4(
3412
+ "ComputeBudget111111111111111111111111111111"
3413
+ ),
3414
+ data: new Uint8Array([3, 0, 0, 0, 0, 0, 0, 0, 0])
3415
+ })
3416
+ );
3417
+ transaction.add(
3418
+ new TransactionInstruction({
3419
+ keys: [],
3420
+ programId: new PublicKey4(
3421
+ "ComputeBudget111111111111111111111111111111"
3422
+ ),
3423
+ data: new Uint8Array([2, 0, 0, 0, 0])
3424
+ })
3425
+ );
3426
+ transaction.add(
3427
+ new TransactionInstruction({
3428
+ keys: [],
3429
+ programId: new PublicKey4(
3430
+ "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
3431
+ ),
3432
+ data: message
3433
+ })
3434
+ );
3435
+ const userPublicKey = new PublicKey4(this.address);
3436
+ transaction.feePayer = userPublicKey;
3437
+ const zeroHash = new Uint8Array(32).fill(0);
3438
+ transaction.recentBlockhash = new PublicKey4(zeroHash).toString();
3439
+ const signedTransaction = yield this._provider.signTransaction(transaction);
3440
+ const signature = signedTransaction.signatures[0].signature;
3441
+ if (signature) {
3442
+ return this.uint8ArrayToHexString(signature);
3443
+ } else {
3444
+ console.log("-- sign message error", signature);
3445
+ throw new Error("Unsupported signature");
3446
+ }
3447
+ }
3448
+ const signRes = yield this._provider.signMessage(message);
3449
+ return "0x" + bytesToHex2(signRes);
3450
+ });
3451
+ }
3452
+ generateRegisterAccountMessage(inputs) {
3453
+ return __async(this, null, function* () {
3454
+ const [message, toSignatureMessage] = registerAccountMessage(__spreadProps(__spreadValues({}, inputs), {
3455
+ chainId: this.chainId
3456
+ }));
3457
+ const signature = yield this.signMessage(toSignatureMessage);
3458
+ return {
3459
+ message: __spreadProps(__spreadValues({}, message), {
3460
+ chainType: "SOL"
3461
+ }),
3462
+ signatured: signature
3463
+ };
3464
+ });
3465
+ }
3466
+ generateWithdrawMessage(inputs) {
3467
+ return __async(this, null, function* () {
3468
+ const [message, toSignatureMessage] = withdrawMessage(__spreadProps(__spreadValues({}, inputs), {
3469
+ chainId: this.chainId
3470
+ }));
3471
+ const signature = yield this.signMessage(toSignatureMessage);
3472
+ return {
3473
+ message: __spreadProps(__spreadValues({}, message), {
3474
+ chainType: "SOL"
3475
+ }),
3476
+ domain: {
3477
+ name: "",
3478
+ version: "",
3479
+ chainId: this.chainId,
3480
+ verifyingContract: inputs.verifyContract
3481
+ },
3482
+ signatured: signature
3483
+ };
3484
+ });
3485
+ }
3486
+ generateInternalTransferMessage(inputs) {
3487
+ return __async(this, null, function* () {
3488
+ const [message, toSignatureMessage] = internalTransferMessage(__spreadProps(__spreadValues({}, inputs), {
3489
+ chainId: this.chainId
3490
+ }));
3491
+ const signature = yield this.signMessage(toSignatureMessage);
3492
+ return {
3493
+ message: __spreadProps(__spreadValues({}, message), {
3494
+ chainType: "SOL"
3495
+ }),
3496
+ domain: {
3497
+ name: "",
3498
+ version: "",
3499
+ chainId: this.chainId,
3500
+ verifyingContract: inputs.verifyContract
3501
+ },
3502
+ signatured: signature
3503
+ };
3504
+ });
3505
+ }
3506
+ generateAddOrderlyKeyMessage(inputs) {
3507
+ return __async(this, null, function* () {
3508
+ const [message, toSignatureMessage] = addOrderlyKeyMessage(__spreadProps(__spreadValues({}, inputs), {
3509
+ chainId: this.chainId
3510
+ }));
3511
+ const signature = yield this.signMessage(toSignatureMessage);
3512
+ return {
3513
+ message: __spreadProps(__spreadValues({}, message), {
3514
+ chainType: "SOL"
3515
+ }),
3516
+ signatured: signature
3517
+ };
3518
+ });
3519
+ }
3520
+ generateSettleMessage(inputs) {
3521
+ return __async(this, null, function* () {
3522
+ const [message, toSignatureMessage] = settleMessage(__spreadProps(__spreadValues({}, inputs), {
3523
+ chainId: this.chainId
3524
+ }));
3525
+ const signature = yield this.signMessage(toSignatureMessage);
3526
+ return {
3527
+ message: __spreadProps(__spreadValues({}, message), {
3528
+ chainType: "SOL"
3529
+ }),
3530
+ domain: {
3531
+ name: "",
3532
+ version: "",
3533
+ chainId: this.chainId,
3534
+ verifyingContract: inputs.verifyContract
3535
+ },
3536
+ signatured: signature
3537
+ };
3538
+ });
3539
+ }
3540
+ generateDexRequestMessage(inputs) {
3541
+ return __async(this, null, function* () {
3542
+ const [message, toSignatureMessage] = yield dexRequestMessage(__spreadProps(__spreadValues({}, inputs), {
3543
+ chainId: this.chainId
3544
+ }));
3545
+ const signature = yield this.signMessage(toSignatureMessage);
3546
+ return {
3547
+ message: __spreadProps(__spreadValues({}, inputs), {
3548
+ chainType: "SOL"
3549
+ }),
3550
+ signatured: signature,
3551
+ domain: inputs.domain
3552
+ };
3553
+ });
3554
+ }
3555
+ getBalance() {
3556
+ return __async(this, null, function* () {
3557
+ const publicKey = new PublicKey4(this.address);
3558
+ const lamports = yield this.connection.getBalance(publicKey);
3559
+ return BigInt(lamports);
3560
+ });
3561
+ }
3562
+ call(address, method, params, options) {
3563
+ return __async(this, null, function* () {
3564
+ if (method === "balanceOf") {
3565
+ const tokenPublicKey = new PublicKey4(address);
3566
+ const userPublicKey = new PublicKey4(this._address);
3567
+ const userTokenAccount = getTokenAccounts(tokenPublicKey, userPublicKey);
3568
+ const connection = this.connection;
3569
+ const tokenAmount = yield getAccount(
3570
+ connection,
3571
+ userTokenAccount,
3572
+ "confirmed"
3573
+ );
3574
+ return tokenAmount.amount;
3575
+ }
3576
+ if (method === "allowance") {
3577
+ return MaxUint256;
3578
+ }
3579
+ return BigInt(0);
3580
+ });
3581
+ }
3582
+ sendTransaction(contractAddress, method, payload, options) {
3583
+ return __async(this, null, function* () {
3584
+ console.log("-- solanan sendTransaction", {
3585
+ contractAddress,
3586
+ method,
3587
+ payload,
3588
+ options
3589
+ });
3590
+ if (method === "deposit") {
3591
+ return deposit({
3592
+ vaultAddress: contractAddress,
3593
+ userAddress: this._address,
3594
+ connection: this.connection,
3595
+ depositData: payload.data[0],
3596
+ sendTransaction: this._provider.sendTransaction
3597
+ });
3598
+ }
3599
+ });
3600
+ }
3601
+ callOnChain(chain, address, method, params, options) {
3602
+ return __async(this, null, function* () {
3603
+ console.log("-- params ", {
3604
+ chain,
3605
+ address,
3606
+ method,
3607
+ params
3608
+ });
3609
+ if (method === "getDepositFee") {
3610
+ return getDepositQuoteFee({
3611
+ vaultAddress: address,
3612
+ userAddress: this._address,
3613
+ connection: this.connection,
3614
+ depositData: params[1]
3615
+ });
3616
+ }
3617
+ return 0;
3618
+ });
3619
+ }
3620
+ pollTransactionReceiptWithBackoff(txHash, baseInterval, maxInterval, maxRetries) {
3621
+ return __async(this, null, function* () {
3622
+ return Promise.resolve({ status: 1 });
3623
+ });
3624
+ }
3625
+ };
3626
+ export {
3627
+ DefaultSolanaWalletAdapter,
3628
+ version_default as version
3629
+ };
2
3630
  //# sourceMappingURL=index.mjs.map