snapper-sdk
Version:
An SDK for building applications on top of Snapper.
2 lines • 6.21 kB
JavaScript
import{PublicKey as E}from"@solana/web3.js";import{get as l,set as B}from"lodash";var x=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let t=e.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(t)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},_={},C={};function T(s){let e=l(_,s);if(!e){let t=l(C,s);e=new x({name:s,logLevel:t}),B(_,s,e)}return e}import{PublicKey as r}from"@solana/web3.js";var Q=new r("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),W=new r("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),z=new r("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Y=new r("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),J=new r("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),f=new r("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),X=new r("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Z=new r("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),$=new r("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),ee=new r("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),te=new r("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),re=new r("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),ne=new r("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),oe=new r("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),se=new r("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),ue=new r("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),ae=new r("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),ie=new r("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),ce=new r("SNaPnpKUY656VPwbKmKT8FG4T85g4VWhRH1B4TQUfKs"),pe=new r("9pR79Lqe6wDNjag3v8MeVYUostoXjY2ognTydor6AtEZ"),ye=new r("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),O=new r("4AscABy58S62owbByjUUkQfZsP7fxYH1rDYb69V58HPM"),D=new r("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),V=new r("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),Pe=new r("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),v=new r("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),de=new r("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),k=new r("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var xe={SERUM_MARKET:r.default,OPENBOOK_MARKET:new r("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:r.default,FarmV3:new r("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new r("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new r("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new r("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new r("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new r("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new r("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new r("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new r("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:O,CREATE_CPMM_POOL_AUTH:D,CREATE_CPMM_POOL_FEE_ACC:V,FEE_DESTINATION_ID:new r("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:v,LCOK_CPMM_AUTH:k};var h={[f.toBase58()]:3},w={3:f};import{PublicKey as N}from"@solana/web3.js";import S,{isBN as lt}from"bn.js";import{bits as me,BitStructure as le,blob as K,Blob as _e,cstr as Te,f32 as he,f32be as we,f64 as Me,f64be as Se,greedy as Ae,Layout as I,ns64 as Re,ns64be as Ee,nu64 as Ue,nu64be as Be,offset as Ce,s16 as Oe,s16be as De,s24 as Ve,s24be as ve,s32 as ke,s32be as Ke,s40 as Ie,s40be as Ge,s48 as Ne,s48be as qe,s8 as Fe,seq as He,struct as je,Structure as G,u16 as Qe,u16be as We,u24 as ze,u24be as Ye,u32 as Je,u32be as Xe,u40 as Ze,u40be as $e,u48 as et,u48be as tt,u8 as rt,UInt as nt,union as ot,Union as st,unionLayoutDiscriminator as ut,utf8 as at}from"@solana/buffer-layout";var g=I,M=G;var i=K;var b=class extends g{constructor(t,n,o){super(t,o);this.blob=i(t),this.signed=n}decode(t,n=0){let o=new S(this.blob.decode(t,n),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(t,n,o=0){return typeof t=="number"&&(t=new S(t)),this.signed&&(t=t.toTwos(this.span*8)),this.blob.encode(t.toArrayLike(Buffer,"le",this.span),n,o)}};function u(s){return new b(8,!1,s)}var L=class extends g{constructor(t,n,o,y){super(t.span,y);this.layout=t,this.decoder=n,this.encoder=o}decode(t,n){return this.decoder(this.layout.decode(t,n))}encode(t,n,o){return this.layout.encode(this.encoder(t),n,o)}getSpan(t,n){return this.layout.getSpan(t,n)}};function a(s){return new L(i(32),e=>new N(e),e=>e.toBuffer(),s)}var m=class extends M{decode(e,t){return super.decode(e,t)}};function A(s,e,t){return new m(s,e,t)}var q=A([i(5),i(8),a("ownAddress"),u("vaultSignerNonce"),a("baseMint"),a("quoteMint"),a("baseVault"),u("baseDepositsTotal"),u("baseFeesAccrued"),a("quoteVault"),u("quoteDepositsTotal"),u("quoteFeesAccrued"),u("quoteDustThreshold"),a("requestQueue"),a("eventQueue"),a("bids"),a("asks"),u("baseLotSize"),u("quoteLotSize"),u("feeRateBps"),u("referrerRebatesAccrued"),i(7)]),R={3:q};var d=T("Serum"),U=class{static getProgramId(e){let t=w[e];return t||d.logWithError("invalid version","version",e),t}static getVersion(e){let t=e.toBase58(),n=h[t];return n||d.logWithError("invalid program id","programId",t),n}static getStateLayout(e){let t=R[e];return t||d.logWithError(!!t,"invalid version","version",e),t}static getLayouts(e){return{state:this.getStateLayout(e)}}static getAssociatedAuthority({programId:e,marketId:t}){let n=[t.toBuffer()],o=0,y;for(;o<100;){try{let P=n.concat(Buffer.from([o]),Buffer.alloc(7));y=E.createProgramAddressSync(P,e)}catch(P){if(P instanceof TypeError)throw P;o++;continue}return{publicKey:y,nonce:o}}return d.logWithError("unable to find a viable program address nonce","params",{programId:e,marketId:t}),{publicKey:E.default,nonce:o}}};export{U as Market};
//# sourceMappingURL=serum.mjs.map