Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@delvtech/hyperdrive-js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@delvtech/hyperdrive-js - npm Package Compare versions

Comparing version
0.0.2
to
1.0.0
+6
dist/chunk-GYQBJEPF.js
var ht=Object.create;var Y=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var bt=Object.getPrototypeOf,vt=Object.prototype.hasOwnProperty;var $=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports);var Pt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ft(t))!vt.call(s,i)&&i!==e&&Y(s,i,{get:()=>t[i],enumerable:!(r=gt(t,i))||r.enumerable});return s};var wt=(s,t,e)=>(e=s!=null?ht(bt(s)):{},Pt(t||!s||!s.__esModule?Y(e,"default",{value:s,enumerable:!0}):e,s));var j=$((te,Z)=>{"use strict";function b(s,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(s)),this._timeouts=s,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}Z.exports=b;b.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};b.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};b.prototype.retry=function(s){if(this._timeout&&clearTimeout(this._timeout),!s)return!1;var t=new Date().getTime();if(s&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(s),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(s);var e=this._timeouts.shift();if(e===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),e=this._cachedTimeouts.slice(-1);else return!1;var r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},e),this._options.unref&&this._timer.unref(),!0};b.prototype.attempt=function(s,t){this._fn=s,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var e=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){e._operationTimeoutCb()},e._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};b.prototype.try=function(s){console.log("Using RetryOperation.try() is deprecated"),this.attempt(s)};b.prototype.start=function(s){console.log("Using RetryOperation.start() is deprecated"),this.attempt(s)};b.prototype.start=b.prototype.try;b.prototype.errors=function(){return this._errors};b.prototype.attempts=function(){return this._attempts};b.prototype.mainError=function(){if(this._errors.length===0)return null;for(var s={},t=null,e=0,r=0;r<this._errors.length;r++){var i=this._errors[r],n=i.message,o=(s[n]||0)+1;s[n]=o,o>=e&&(t=i,e=o)}return t}});var Q=$(E=>{"use strict";var Ct=j();E.operation=function(s){var t=E.timeouts(s);return new Ct(t,{forever:s&&(s.forever||s.retries===1/0),unref:s&&s.unref,maxRetryTime:s&&s.maxRetryTime})};E.timeouts=function(s){if(s instanceof Array)return[].concat(s);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var e in s)t[e]=s[e];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return s&&s.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(n,o){return n-o}),r};E.createTimeout=function(s,t){var e=t.randomize?Math.random()+1:1,r=Math.round(e*Math.max(t.minTimeout,1)*Math.pow(t.factor,s));return r=Math.min(r,t.maxTimeout),r};E.wrap=function(s,t,e){if(t instanceof Array&&(e=t,t=null),!e){e=[];for(var r in s)typeof s[r]=="function"&&e.push(r)}for(var i=0;i<e.length;i++){var n=e[i],o=s[n];s[n]=function(c){var m=E.operation(t),u=Array.prototype.slice.call(arguments,1),d=u.pop();u.push(function(p){m.retry(p)||(p&&(arguments[0]=m.mainError()),d.apply(this,arguments))}),m.attempt(function(){c.apply(s,u)})}.bind(s,o),s[n].options=t}}});var et=$((ie,tt)=>{"use strict";tt.exports=Q()});import{DriftError as yt}from"@delvtech/drift";var f=class extends yt{constructor(t,e){super(t,{...e,prefix:"\u16CB ",name:"Hyperdrive SDK Error"})}};import{IHyperdrive as At}from"@delvtech/hyperdrive-artifacts/IHyperdrive";var U=At.abi;import{fixed as St}from"@delvtech/fixed-point-wasm";import{calcAprGivenFixedPrice as Et}from"@delvtech/hyperdrive-wasm";function N({positionDuration:s,baseAmount:t,bondAmount:e}){return Et({positionDuration:s,price:St(t).div(e).bigint})}var k=class extends f{constructor(t,e){let{event:r,address:i}=e[0],n=`Failed to fetch "${r}" events from ${i} on chain ${t}.`;n+=`
Requested block ranges:`;for(let o of e)n+=`
- ${o.fromBlock} to ${o.toBlock}`;super(n)}};async function K({params:s,drift:t,epochBlock:e=0n,retries:r=3,backoff:i=n=>2**n*100}){let n=typeof i=="number"?()=>i:i,o=await t.getChainId(),a=new Map,c=[s];for(let m=0;m<=r;m++){let u=[],d=!1,p=await Promise.all(c.map(async(w,_)=>{let W=[w.fromBlock,w.toBlock].join("-"),x=a.get(W);if(x)return u[_]=[w],x;if(x=await t.cache.getEvents(w),x)return a.set(W,x),u[_]=[w],x;try{let O=await t.adapter.getEvents(w);return a.set(W,O),t.cache.preloadEvents({...w,value:O}),u[_]=[w],O}catch{d=!0;let O=await xt(t,w,e);if(!O)throw new k(o,c);return u[_]=O,[]}}));if(!d)return p.flat();let h=new k(o,c);if(m===r)throw h;c=u.flat();let P=h.message;P+=`
Number of attempts left: ${r-m}`,P+=`
Retrying with ${c.length} requests...`,console.warn(P);let C=n(m),pt=Math.floor(C*(.5+Math.random()));await Ot(pt)}throw new k(o,[s])}async function J(s,t,e=0n){if(typeof t=="bigint")return t;if(t==="earliest")return e;let{number:r}=await s.getBlock(t);return r}async function xt(s,{fromBlock:t,toBlock:e,...r},i=0n){if(t===e||(t=await J(s,t,i),t===void 0)||(e=await J(s,e,i),e===void 0||t>=e))return null;let n=e-t,o=t+n/2n;return[{fromBlock:t,toBlock:o,...r},{fromBlock:o+1n,toBlock:e,...r}]}function Ot(s){return new Promise(t=>setTimeout(t,s))}var y=class{drift;debugName;constructor({debugName:t,drift:e,epochBlock:r,eventQueryRetries:i=3,eventQueryRetryBackoff:n=o=>2**o*100}){this.debugName=t??this.constructor.name,this.drift=e,e.hooks.on("before:getEvents",async({args:o,resolve:a})=>{let[{fromBlock:c,toBlock:m,...u}]=o,d=await K({params:{fromBlock:c,toBlock:m,...u},drift:e,epochBlock:r,retries:i,backoff:n});a(d)})}};import{IERC20 as Rt}from"@delvtech/hyperdrive-artifacts/IERC20";var X=Rt.abi;var A=class extends y{contract;constructor({debugName:t="ERC-20 Token",address:e,epochBlock:r,...i}){super({debugName:t,epochBlock:r,...i}),this.contract=this.drift.contract({abi:X,address:e,epochBlock:r})}get address(){return this.contract.address}getName(){return this.contract.read("name")}getSymbol(){return this.contract.read("symbol")}getDecimals(){return this.contract.read("decimals")}getAllowance({owner:t,spender:e,options:r}){return this.contract.read("allowance",{owner:t,spender:e},r)}getBalanceOf({account:t,options:e}){return this.contract.read("balanceOf",{account:t},e)}getTotalSupply(t){return this.contract.read("totalSupply",{},t)}};var S=class s extends y{static address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";address=s.address;constructor({debugName:t="ETH",...e}){super({debugName:t,...e})}async getName(){return"Ethereum"}async getSymbol(){return"ETH"}async getDecimals(){return 18}async getAllowance(){return 2n**256n-1n}async getBalanceOf({account:t,options:e}){return this.drift.getBalance({address:t,...e})}};import{fixed as g}from"@delvtech/fixed-point-wasm";var rt=wt(et(),1);var kt=Object.prototype.toString,Tt=s=>kt.call(s)==="[object Error]",Lt=new Set(["network error","Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Load failed","Network request failed","fetch failed","terminated"]);function M(s){return s&&Tt(s)&&s.name==="TypeError"&&typeof s.message=="string"?s.message==="Load failed"?s.stack===void 0:Lt.has(s.message):!1}var H=class extends Error{constructor(t){super(),t instanceof Error?(this.originalError=t,{message:t}=t):(this.originalError=new Error(t),this.originalError.stack=this.stack),this.name="AbortError",this.message=t}},it=(s,t,e)=>{let r=e.retries-(t-1);return s.attemptNumber=t,s.retriesLeft=r,s};async function F(s,t){return new Promise((e,r)=>{t={...t},t.onFailedAttempt??=()=>{},t.shouldRetry??=()=>!0,t.retries??=10;let i=rt.default.operation(t),n=()=>{i.stop(),r(t.signal?.reason)};t.signal&&!t.signal.aborted&&t.signal.addEventListener("abort",n,{once:!0});let o=()=>{t.signal?.removeEventListener("abort",n),i.stop()};i.attempt(async a=>{try{let c=await s(a);o(),e(c)}catch(c){try{if(!(c instanceof Error))throw new TypeError(`Non-error was thrown: "${c}". You should only throw errors.`);if(c instanceof H)throw c.originalError;if(c instanceof TypeError&&!M(c))throw c;if(it(c,a,t),await t.shouldRetry(c)||(i.stop(),r(c)),await t.onFailedAttempt(c),!i.retry(c))throw i.mainError()}catch(m){it(m,a,t),o(),r(m)}}})})}function I(s,t){if(t)return s;throw new f(`Unhandled discriminated union member: ${JSON.stringify(s)}`)}var V=31536000n,nt=115792089237316195423570985008687907853269984665640564039457584007913129639935n,v="0x";function ot(s){if(s===0)return"LP";if(s===1)return"LONG";if(s===2)return"SHORT";if(s===3)return"WITHDRAWAL_SHARE";throw new f(`parseAssetType(${s}) did not match a valid asset type.`)}function G(s){let t=s.slice(2),e=Number(t.slice(0,2)),r=ot(e),i=t.slice(2,64),n=BigInt(parseInt(i,16));return{assetType:r,timestamp:n}}function B(s,t){return s-s%t}var q=0n;import{fixed as _t}from"@delvtech/fixed-point-wasm";function at({openVaultSharePrice:s,endingVaultSharePrice:t,bondAmount:e,decimals:r}){return _t(t-s).mul(e,r).bigint}var st=0x0300000000000000000000000000000000000000000000000000000000000000n;import*as l from"@delvtech/hyperdrive-wasm";var R=class extends y{address;contract;zapContractAddress;constructor({debugName:t="Hyperdrive",address:e,epochBlock:r,zapContractAddress:i,...n}){super({debugName:t,epochBlock:r,...n}),this.address=e,this.zapContractAddress=i,this.contract=this.drift.contract({abi:U,address:e,epochBlock:r})}async getKind(){return this.contract.read("kind")}async getVersion(){let t=await this.contract.read("version"),[e,r,i]=t.replace(/^\D*/,"").split(".").map(n=>parseInt(n));return{major:e,minor:r,patch:i,string:t}}async getBaseToken(){let t=await this.contract.read("baseToken");return t===S.address?new S({drift:this.drift}):new A({address:t,drift:this.drift})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new A({address:t,drift:this.drift})}getDecimals(){return this.contract.read("decimals")}async convertToBase({sharesAmount:t,options:e}){return this.contract.read("convertToBase",{_shareAmount:t},e)}async convertToShares({baseAmount:t,options:e}){return this.contract.read("convertToShares",{_baseAmount:t},e)}async getInitializationBlock(t){let r=(await F(async()=>{let i=await this.contract.getEvents("Initialize",t);if(!i.length||i[0].blockNumber===void 0)throw this.contract.cache.clear(),new f(`Pool has not been initialized, no block found. ${this.address}`);return i},{retries:10,onFailedAttempt:async i=>{console.log(`getInitializationBlock failed on Hyperdrive ${this.address}, chainId: ${await this.drift.getChainId()}. There are ${i.retriesLeft} retries left.`)}}))[0].blockNumber;return this.drift.getBlock(r,{throws:!0})}async getYieldSourceRate({blockRange:t,options:e}){let r=await this.drift.getBlock(e?.block,{throws:!0}),i=r.number-t,{number:n}=await this.getInitializationBlock();n&&n>i&&(i=n);let o=await this.drift.getBlock(i,{throws:!0}),{vaultSharePrice:a}=await this.getPoolInfo({block:i}),{vaultSharePrice:c}=await this.getPoolInfo(e),m=r.timestamp-o.timestamp;return ct({startPrice:a,endPrice:c,timeFrame:m})}getCheckpointTime(t={}){return this._getCheckpointTime(t)}async _getCheckpointTime({timestamp:t,blockNumber:e,options:r}={}){let{checkpointDuration:i}=await this.getPoolConfig(r);return t===void 0&&(t=(await this.drift.getBlock(e??r?.block,{throws:!0})).timestamp),B(t,i)}async getCheckpoint({checkpointTime:t,timestamp:e,blockNumber:r,options:i}={}){t===void 0&&(t=await this._getCheckpointTime({timestamp:e,blockNumber:r,options:i}));let{lastWeightedSpotPriceUpdateTime:n,vaultSharePrice:o,weightedSpotPrice:a}=await this.contract.read("getCheckpoint",{_checkpointTime:t},i);return{checkpointTime:t,lastWeightedSpotPriceUpdateTime:n,vaultSharePrice:o,weightedSpotPrice:a}}async getCheckpointExposure({checkpointTime:t,blockNumber:e,timestamp:r,options:i}={}){return t===void 0&&(t=await this._getCheckpointTime({blockNumber:e,timestamp:r,options:i})),this.contract.read("getCheckpointExposure",{_checkpointTime:t},i)}getMarketState(t){return this.contract.read("getMarketState",void 0,t)}getPoolConfig(t){return this.contract.read("getPoolConfig",void 0,t)}getPoolInfo(t){return this.contract.read("getPoolInfo",void 0,t)}async getFixedApr(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return l.spotRate({poolConfig:e,poolInfo:r})}async getImpliedRate({bondAmount:t,timestamp:e,variableApy:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),{vaultSharePrice:a}=await this.getCheckpoint({timestamp:e});return a||(a=(await this.getPoolInfo()).vaultSharePrice),l.calcImpliedRate({poolInfo:o,poolConfig:n,bondAmount:t,openVaultSharePrice:a,variableApy:r})}async getIdleLiquidity(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return l.idleShareReservesInBase({poolInfo:r,poolConfig:e})}async getPresentValue(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t),i=l.presentValue({poolInfo:r,poolConfig:e,currentTime:BigInt(Date.now())/1000n});return this.convertToBase({sharesAmount:i,options:t})}async getShortAccruedYield({checkpointTime:t,bondAmount:e,options:r}){let{vaultSharePrice:i}=await this.getCheckpoint({checkpointTime:t,options:r}),{positionDuration:n}=await this.getPoolConfig(r),o=t+n,c=await this.getCheckpointTime({options:r})>=o,m;if(c)m=(await this.getCheckpoint({checkpointTime:o,options:r})).vaultSharePrice;else{let u=await this.getPoolInfo(r);m=u.vaultSharePrice,i!=0n||(i=u.vaultSharePrice)}return at({openVaultSharePrice:i,endingVaultSharePrice:m,bondAmount:e,decimals:await this.getDecimals()})}async getTradingVolume(t){let{fromBlock:e,toBlock:r}=t||{},i=await this.getLongEvents({fromBlock:e,toBlock:r}),n=await this.getShortEvents({fromBlock:e,toBlock:r}),o=i.reduce((c,{bondAmount:m})=>c+m,0n),a=n.reduce((c,{bondAmount:m})=>c+m,0n);return{longVolume:o,shortVolume:a,totalVolume:o+a}}async getLongPrice(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return l.spotPrice({poolConfig:e,poolInfo:r})}async getLongEvents(t){let e=await this.contract.getEvents("OpenLong",t),r=await this.contract.getEvents("CloseLong",t);return[...e,...r].map(({args:i,eventName:n,blockNumber:o,transactionHash:a})=>{let c=i.asBase?i.amount:g(i.amount).mul(i.vaultSharePrice).bigint;return{trader:i.trader,assetId:i.assetId,bondAmount:i.bondAmount,baseAmount:c,eventName:n,blockNumber:o,transactionHash:a}}).sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber))}async getShortEvents(t){let e=await this.contract.getEvents("OpenShort",t),r=await this.contract.getEvents("CloseShort",t);return[...e,...r].map(({args:i,eventName:n,blockNumber:o,transactionHash:a})=>{let c=i.asBase?i.amount:g(i.amount).mul(i.vaultSharePrice).bigint;return{trader:i.trader,assetId:i.assetId,bondAmount:i.bondAmount,baseAmount:c,eventName:n,blockNumber:o,transactionHash:a}}).sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber))}async getLpEvents(t){let e=await this.contract.getEvents("AddLiquidity",t),r=await this.contract.getEvents("RemoveLiquidity",t),i=await this.contract.getEvents("RedeemWithdrawalShares",t);return{addLiquidity:e,removeLiquidity:r,redeemWithdrawalShares:i}}async getLpApy({fromBlock:t,options:e}){let{number:r}=await this.getInitializationBlock();r&&r>t&&(t=r);let i=await this.drift.getBlock(e?.block,{throws:!0}),n=await this.drift.getBlock(t,{throws:!0}),{lpSharePrice:o}=await this.getPoolInfo({block:t}),{lpSharePrice:a}=await this.getPoolInfo(),c=i.timestamp-n.timestamp;return{lpApy:ct({startPrice:o,endPrice:a,timeFrame:c})}}async getCheckpointEvents(t){return await this.contract.getEvents("CreateCheckpoint",t)}_calcOpenLongs({openLongEvents:t,closeLongEvents:e}){let r=[...t,...e].sort((n,o)=>Number(n.blockNumber)-Number(o.blockNumber)),i={};return r.forEach(n=>{let o=n.args.assetId.toString(),a=i[o]||{assetId:n.args.assetId,maturity:n.args.maturityTime,baseAmountPaid:0n,bondAmount:0n},c=n.args.asBase?n.args.amount:g(n.args.amount).mul(n.args.vaultSharePrice).bigint;switch(n.eventName){case"OpenLong":i[o]={...a,baseAmountPaid:a.baseAmountPaid+c,bondAmount:a.bondAmount+n.args.bondAmount};return;case"CloseLong":n.args.bondAmount===a.bondAmount?delete i[o]:i[o]={...a,baseAmountPaid:a.baseAmountPaid-c,bondAmount:a.bondAmount-n.args.bondAmount};return;default:I(n,!0)}}),Object.values(i).filter(n=>n.bondAmount)}async getOpenLongPositions({account:t,options:e}){let r=await this.contract.getEvents("TransferSingle",{filter:{to:t},...e}),i=await this.contract.getEvents("TransferSingle",{filter:{from:t},...e}),n=r.filter(mt),o=i.filter(mt),a=[...n,...o].sort((m,u)=>Number(m.blockNumber)-Number(u.blockNumber)),c={};for(let m of a){let u=c[m.args.id.toString()]??{assetId:m.args.id,maturity:G(m.data).timestamp,value:0n};if(m.args.to===t)u.value+=m.args.value;else if(m.args.from===t&&(u.value-=m.args.value,u.value===0n)){delete c[m.args.id.toString()];continue}c[m.args.id.toString()]=u}return Object.values(c).filter(m=>m.value)}async getOpenLongDetails({assetId:t,account:e,options:r}){if(!(await this.getOpenLongPositions({account:e,options:r})).find(m=>m.assetId===t))throw new f(`No position with asset id: ${t} found for account ${e}`);let o=await this.contract.getEvents("OpenLong",{filter:{trader:e,assetId:t},...r}),a=await this.contract.getEvents("CloseLong",{filter:{trader:e,assetId:t},...r});if(this.zapContractAddress){let m=await this.contract.getEvents("TransferSingle",{filter:{from:e,to:this.zapContractAddress},...r});if(m.length){let u=m.map(({transactionHash:h})=>h),p=(await this.contract.getEvents("CloseLong",{filter:{trader:this.zapContractAddress,assetId:t},fromBlock:m[0].blockNumber,toBlock:m.at(-1)?.blockNumber})).filter(({transactionHash:h})=>u.includes(h));for(let h of p)a.push(h)}}return this._calcOpenLongs({openLongEvents:o,closeLongEvents:a})[0]}async getOpenLongs({account:t,options:e}){let r=await this.contract.getEvents("OpenLong",{filter:{trader:t},...e}),i=await this.contract.getEvents("CloseLong",{filter:{trader:t},...e});return this._calcOpenLongs({openLongEvents:r,closeLongEvents:i})}async getOpenShorts({account:t,options:e}){let{checkpointDuration:r,positionDuration:i}=await this.getPoolConfig({block:e?.toBlock}),n=await this.contract.getEvents("OpenShort",{filter:{trader:t},...e}),o=await this.contract.getEvents("CloseShort",{filter:{trader:t},...e});return this._calcOpenShorts({hyperdriveAddress:this.address,checkpointDuration:r,positionDuration:i,openShortEvents:n,closeShortEvents:o})}async _calcOpenShorts({hyperdriveAddress:t,checkpointDuration:e,positionDuration:r,closeShortEvents:i,openShortEvents:n}){let o=[...n,...i].sort((c,m)=>Number(c.blockNumber)-Number(m.blockNumber)),a={};for(let c of o){let m=c.args.assetId.toString(),{timestamp:u}=await this.drift.getBlock(c.blockNumber,{throws:!0});a[m]=a[m]||{hyperdriveAddress:t,assetId:c.args.assetId,maturity:c.args.maturityTime,checkpointTime:B(u,e),openedTimestamp:u,baseAmountPaid:0n,bondAmount:0n,baseProceeds:0n,fixedRatePaid:0n};let d=c.args.asBase?c.args.amount:g(c.args.amount).mul(c.args.vaultSharePrice).bigint,{eventName:p}=c;switch(p){case"OpenShort":a[m].baseAmountPaid+=d,a[m].bondAmount+=c.args.bondAmount,a[m].baseProceeds+=c.args.baseProceeds,a[m].fixedRatePaid=N({positionDuration:r,baseAmount:a[m].baseProceeds,bondAmount:a[m].bondAmount});continue;case"CloseShort":{if(c.args.bondAmount===a[m].bondAmount){delete a[m];continue}a[m].baseAmountPaid-=d,a[m].bondAmount-=c.args.bondAmount,a[m].baseProceeds-=c.args.basePayment,a[m].fixedRatePaid=N({positionDuration:r,baseAmount:a[m].baseProceeds,bondAmount:a[m].bondAmount});continue}default:I(p,!0)}}return Object.values(a).filter(c=>c.bondAmount)}async getClosedLongs({account:t,options:e}){let r=await this.contract.getEvents("CloseLong",{filter:{trader:t},...e});return(await Promise.all(r.map(async n=>{let o=n.args.assetId,a=n.args.asBase?n.args.amount:g(n.args.amount).mul(n.args.vaultSharePrice).bigint;return{assetId:o,bondAmount:n.args.bondAmount,baseAmount:a,maturity:n.args.maturityTime,closedTimestamp:(await this.drift.getBlock(n.blockNumber,{throws:!0})).timestamp}}))).filter(n=>n.bondAmount)}async getClosedShorts({account:t,options:e}){let r=await this.contract.getEvents("CloseShort",{filter:{trader:t},...e}),{checkpointDuration:i}=await this.getPoolConfig({block:e?.toBlock});return(await Promise.all(r.map(async o=>{let{assetId:a,maturityTime:c}=o.args,{timestamp:m}=await this.drift.getBlock(o.blockNumber,{throws:!0}),u=o.args.asBase?o.args.amount:g(o.args.amount).mul(o.args.vaultSharePrice).bigint;return{hyperdriveAddress:this.address,assetId:a,bondAmount:o.args.bondAmount,baseAmountReceived:u,maturity:c,closedTimestamp:m,checkpointTime:B(m,i)}}))).filter(o=>o.bondAmount)}async getMaxShort({budget:t,options:e}){let r=await this.getPoolInfo(e),i=await this.getPoolConfig(e),n=await this.getCheckpointExposure({options:e}),{vaultSharePrice:o}=await this.getCheckpoint({options:e}),a=l.maxShort({budget:t,poolInfo:r,poolConfig:i,maxIterations:14,openVaultSharePrice:o,checkpointExposure:n}),c=l.calcOpenShort({poolInfo:r,poolConfig:i,bondAmount:a,openVaultSharePrice:o}),m=await this.convertToShares({baseAmount:c,options:e});return{maxBaseIn:c,maxSharesIn:m,maxBondsOut:a}}async getMaxLong(t){let e=await this.getPoolInfo(t),r=await this.getPoolConfig(t),i=await this.getCheckpointExposure({options:t}),n=l.maxLong({poolInfo:e,poolConfig:r,budget:nt,checkpointExposure:i}),o=await this.convertToShares({baseAmount:n,options:t}),a=l.calcOpenLong({poolInfo:e,poolConfig:r,baseAmount:n});return{maxBaseIn:n,maxSharesIn:o,maxBondsOut:a}}getLpSharesTotalSupply(t){return this.contract.read("totalSupply",{tokenId:q},t?.options)}getLpShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:q,owner:t},e)}async getOpenLpPosition({account:t,asBase:e,options:r}){let i=await this.contract.getEvents("AddLiquidity",{filter:{provider:t},...r}),n=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},...r}),o=await this.getDecimals(),{lpShareBalance:a,baseAmountPaid:c}=this._calcOpenLpPosition({addLiquidityEvents:i,removeLiquidityEvents:n});if(!a)return{lpShareBalance:a,baseAmountPaid:c,baseValue:0n,sharesValue:0n};let{proceeds:m,withdrawalShares:u}=await this.previewRemoveLiquidity({lpSharesIn:a,minOutputPerShare:1n,asBase:e,destination:t}),d=e?m:await this.convertToBase({sharesAmount:m}),{lpSharePrice:p}=await this.getPoolInfo(),h=g(p,o).mul(u,o).bigint,P=await this.convertToShares({baseAmount:h});return{lpShareBalance:a,baseAmountPaid:c,baseValue:d+h,sharesValue:m+P}}_calcOpenLpPosition({addLiquidityEvents:t,removeLiquidityEvents:e}){let r=[...t,...e].sort((o,a)=>Number(o.blockNumber)-Number(a.blockNumber)),i=0n,n=0n;return r.forEach(o=>{let a=o.args.asBase?o.args.amount:g(o.args.amount).mul(o.args.vaultSharePrice).bigint;switch(o.eventName){case"AddLiquidity":n+=o.args.lpAmount,i+=a;return;case"RemoveLiquidity":{if(n-=o.args.lpAmount,n<=0n)i=0n;else{let c=g(o.args.withdrawalShareAmount).mul(o.args.lpSharePrice).bigint;i=i-a-c}return}default:I(o,!0)}}),{lpShareBalance:n,baseAmountPaid:i}}async getClosedLpShares({account:t,options:e}){let r=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},...e});return Promise.all(r.map(async({blockNumber:i,args:n})=>{let{lpAmount:o,withdrawalShareAmount:a,asBase:c,amount:m,lpSharePrice:u}=n,d=c?m:g(n.amount).mul(n.vaultSharePrice).bigint;return{lpAmount:o,baseAmount:d,withdrawalShareAmount:a,lpSharePrice:u,closedTimestamp:(await this.drift.getBlock(i,{throws:!0})).timestamp}}))}getWithdrawalShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:st,owner:t},e)}async getRedeemedWithdrawalShares({account:t,options:e}){let r=await this.contract.getEvents("RedeemWithdrawalShares",{filter:{provider:t},...e});return Promise.all(r.map(async({blockNumber:i,args:n})=>{let{withdrawalShareAmount:o,amount:a,asBase:c,vaultSharePrice:m}=n,u=c?n.amount:g(a).mul(m).bigint;return{hyperdriveAddress:this.address,withdrawalShareAmount:o,baseAmount:u,redeemedTimestamp:(await this.drift.getBlock(i,{throws:!0})).timestamp}}))}async previewOpenLong({amountIn:t,asBase:e,options:r}){let i=await this.getPoolConfig(r),n=await this.getPoolInfo(r),o=await this.getCheckpointTime({options:r}),a=t;e||(a=await this.convertToBase({sharesAmount:t,options:r}));let c=l.spotPriceAfterLong({poolInfo:n,poolConfig:i,baseAmount:a}),m=l.calcAprGivenFixedPrice({price:c,positionDuration:i.positionDuration}),u=l.calcOpenLong({poolInfo:n,poolConfig:i,baseAmount:a}),d=l.openLongCurveFee({poolInfo:n,poolConfig:i,baseAmount:a});return{maturityTime:o+i.positionDuration,bondProceeds:u,spotPriceAfterOpen:c,spotRateAfterOpen:m,curveFee:d}}async previewOpenShort({amountOfBondsToShort:t,asBase:e,options:r}){let i=await this.getPoolConfig(r),n=await this.getPoolInfo(r),o=await this.getCheckpoint({options:r}),a=await this.getShortAccruedYield({checkpointTime:o.checkpointTime,bondAmount:t,options:r}),c=l.calcOpenShort({poolInfo:n,poolConfig:i,bondAmount:t,openVaultSharePrice:o.vaultSharePrice}),m=g(i.positionDuration).div(V),u=g(c).sub(a),d=g(t).sub(u),p=u.div(d).div(m).bigint,h=l.spotPriceAfterShort({poolInfo:n,poolConfig:i,bondAmount:t}),P=l.calcAprGivenFixedPrice({price:h,positionDuration:i.positionDuration}),C=l.openShortCurveFee({poolInfo:n,poolConfig:i,bondAmount:t});return e?{maturityTime:o.checkpointTime+i.positionDuration,traderDeposit:c,spotPriceAfterOpen:h,spotRateAfterOpen:P,curveFee:C,fixedRatePaid:p}:{maturityTime:o.checkpointTime+i.positionDuration,traderDeposit:await this.convertToShares({baseAmount:c,options:r}),spotPriceAfterOpen:h,spotRateAfterOpen:P,curveFee:await this.convertToShares({baseAmount:C,options:r}),fixedRatePaid:p}}async getShortBondsGivenDeposit({amountIn:t,asBase:e,tolerance:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=await this.getCheckpoint({options:i}),c=await this.getCheckpointExposure({options:i}),m=t;e||(m=await this.convertToBase({sharesAmount:t,options:i}));let u=l.absoluteMaxShort({poolInfo:o,poolConfig:n,checkpointExposure:c});return l.shortBondsGivenDeposit({poolInfo:o,poolConfig:n,targetBaseAmount:m,absoluteMaxBondAmount:u,openVaultSharePrice:a.vaultSharePrice,maybeTolerance:r})}async previewCloseLong({maturityTime:t,bondAmountIn:e,asBase:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=BigInt(Math.floor(Date.now()/1e3)),c=l.closeLongFlatFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:a}),m=l.closeLongCurveFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:a}),u=c+m,d=l.calcCloseLong({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:a});return r?{amountOut:await this.convertToBase({sharesAmount:d,options:i}),flatPlusCurveFee:await this.convertToBase({sharesAmount:u,options:i})}:{amountOut:d,flatPlusCurveFee:u}}async estimateShortMarketValue({maturityTime:t,asBase:e,shortAmountIn:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=t-n.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:i}),m=BigInt(Math.floor(Date.now()/1e3)),u=o.vaultSharePrice;t<=m&&(u=(await this.getCheckpoint({timestamp:t,options:i})).vaultSharePrice);let d=l.calcShortMarketValue({poolInfo:o,poolConfig:n,bondAmount:r,openVaultSharePrice:c,closeVaultSharePrice:u,maturityTime:t,currentTime:m});return e?this.convertToBase({sharesAmount:d,options:i}):d}async previewCloseShort({maturityTime:t,shortAmountIn:e,asBase:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=t-n.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:i}),m=BigInt(Math.floor(Date.now()/1e3)),u=o.vaultSharePrice;t<=m&&(u=(await this.getCheckpoint({timestamp:t,options:i})).vaultSharePrice);let d=l.closeShortFlatFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:m}),p=l.closeShortCurveFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:m}),h=d+p,P=l.calcCloseShort({poolInfo:o,poolConfig:n,bondAmount:e,openVaultSharePrice:c,closeVaultSharePrice:u,maturityTime:t,currentTime:m});return r?{amountOut:await this.convertToBase({sharesAmount:P,options:i}),flatPlusCurveFee:await this.convertToBase({sharesAmount:h,options:i})}:{amountOut:P,flatPlusCurveFee:h}}async previewAddLiquidity({contribution:t,minApr:e,minLpSharePrice:r,maxApr:i,asBase:n,options:o}){let a=await this.getPoolConfig(o),c=await this.getPoolInfo(o),m=BigInt(Math.floor(Date.now()/1e3)),u=l.calcAddLiquidity({poolInfo:c,poolConfig:a,currentTime:m,contribution:t,asBase:n,minLpSharePrice:r,minApr:e,maxApr:i}),d=await this.getDecimals(),p=g(u,d).mul(c.lpSharePrice,d).bigint,h=n?p:await this.convertToShares({baseAmount:p,options:o});return{lpSharesOut:u,slippagePaid:t-h}}async previewRemoveLiquidity({lpSharesIn:t,minOutputPerShare:e,destination:r,asBase:i,extraData:n=v,options:o}){let{proceeds:a,withdrawalShares:c}=await this.contract.simulateWrite("removeLiquidity",{_lpShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},{...o,from:r});return{proceeds:a,withdrawalShares:c}}async previewRedeemWithdrawalShares({withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:i,extraData:n=v,options:o}){let{proceeds:a,withdrawalSharesRedeemed:c}=await this.contract.simulateWrite("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},o);return{asBase:i,baseProceeds:i?a:await this.convertToBase({sharesAmount:a}),sharesProceeds:i?await this.convertToShares({baseAmount:a}):a,withdrawalSharesRedeemed:c}}};function ct({startPrice:s,endPrice:t,timeFrame:e}){let r=g(t).div(s),i=g(e).div(V);return r.pow(g(1e18).div(i)).sub(1e18).bigint}function mt(s){let{assetType:t}=G(s.data);return t==="LONG"}var T=class extends A{constructor(t){super(t)}async approve({spender:t,amount:e,options:r}){return await this.contract.write("approve",{spender:t,amount:e},{...r,onMined:n=>{this.contract.cache.invalidateReadsMatching("allowance"),r?.onMined?.(n)}})}};var L=class extends S{constructor(t){super(t)}async approve(){throw new f("This method is not available for the native ETH token.")}};var D=class extends R{constructor(t){super(t)}async getBaseToken(t){let e=await this.contract.read("baseToken",{},t);return e===L.address?new L({drift:this.drift}):new T({address:e,drift:this.drift})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new T({address:t,drift:this.drift})}async checkpoint({args:{time:t},options:e}){return this.contract.write("checkpoint",{_checkpointTime:BigInt(t),_maxIterations:4n},{...e,onMined:r=>{this.contract.cache.clear(),e?.onMined?.(r)}})}async pause({args:{paused:t},options:e}){return this.contract.write("pause",{_status:t},{...e,onMined:r=>{this.contract.cache.invalidateReadsMatching("getMarketState"),e?.onMined?.(r)}})}async initialize({args:{contribution:t,apr:e,destination:r,asBase:i=!0,extraData:n=v},options:o}){return this.contract.write("initialize",{_apr:e,_contribution:t,_options:{destination:r,asBase:i,extraData:n}},{...o,onMined:a=>{this.contract.cache.clear(),o?.onMined?.(a)}})}async openLong({args:{destination:t,amount:e,minBondsOut:r,minVaultSharePrice:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("openLong",{_amount:e,_minOutput:r,_minVaultSharePrice:i,_options:{destination:t,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async openShort({args:{destination:t,bondAmount:e,minVaultSharePrice:r,maxDeposit:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("openShort",{_bondAmount:e,_maxDeposit:i,_minVaultSharePrice:r,_options:{destination:t,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeLong({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("closeLong",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:i,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeShort({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("closeShort",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:i,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async addLiquidity({args:{destination:t,contribution:e,minApr:r,minLpSharePrice:i,maxApr:n,asBase:o=!0,extraData:a=v},options:c}){return this.contract.write("addLiquidity",{_contribution:e,_minLpSharePrice:i,_minApr:r,_maxApr:n,_options:{destination:t,asBase:o,extraData:a}},{...c,onMined:m=>{this.contract.cache.clear(),c?.onMined?.(m)}})}async removeLiquidity({args:{destination:t,lpSharesIn:e,minOutputPerShare:r,asBase:i=!0,extraData:n=v},options:o}){return this.contract.write("removeLiquidity",{_lpShares:e,_minOutputPerShare:r,_options:{destination:t,asBase:i,extraData:n}},{...o,onMined:a=>{this.contract.cache.clear(),o?.onMined?.(a)}})}async redeemWithdrawalShares({args:{withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:i=!0,extraData:n=v},options:o}){return this.contract.write("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},{...o,onMined:a=>{this.contract.cache.clear(),o?.onMined?.(a)}})}};import{fixed as ut}from"@delvtech/fixed-point-wasm";var dt=class extends z(R){};function z(s){return class extends s{constructor(...[t]){let{debugName:e="Hyperdrive v1.0.14",...r}=t;super({debugName:e,...r})}async convertToBase({sharesAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),i=await this.getDecimals();return ut(t,i).mul(r,i).bigint}async convertToShares({baseAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),i=await this.getDecimals();return ut(t,i).div(r).bigint}}}var lt=class extends z(D){};export{f as a,U as b,N as c,y as d,l as e,X as f,A as g,S as h,R as i,T as j,L as k,D as l,dt as m,lt as n};
//# sourceMappingURL=chunk-GYQBJEPF.js.map

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

+5
-1

@@ -1,2 +0,6 @@

"use strict";var ye=Object.create;var Z=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Ee=(s,t)=>{for(var e in t)Z(s,e,{get:t[e],enumerable:!0})},_t=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Re(t))!Ce.call(s,o)&&o!==e&&Z(s,o,{get:()=>t[o],enumerable:!(r=be(t,o))||r.enumerable});return s};var Dt=(s,t,e)=>(e=s!=null?ye(xe(s)):{},_t(t||!s||!s.__esModule?Z(e,"default",{value:s,enumerable:!0}):e,s)),ve=s=>_t(Z({},"__esModule",{value:!0}),s);var He={};Ee(He,{HyperdriveSdkError:()=>E,ReadClient:()=>C,ReadErc20:()=>g,ReadErc4626:()=>S,ReadErc4626Hyperdrive:()=>_,ReadEth:()=>R,ReadEzEthHyperdrive:()=>st,ReadFactory:()=>O,ReadHyperdrive:()=>u,ReadLsEth:()=>V,ReadLsEthHyperdrive:()=>pt,ReadMockErc4626:()=>D,ReadMockErc4626Hyperdrive:()=>it,ReadREth:()=>q,ReadREthHyperdrive:()=>ut,ReadRegistry:()=>Y,ReadStEth:()=>W,ReadStEthHyperdrive:()=>I,ReadWriteClient:()=>bt,ReadWriteErc20:()=>x,ReadWriteErc4626:()=>w,ReadWriteErc4626Hyperdrive:()=>F,ReadWriteEth:()=>v,ReadWriteEzEthHyperdrive:()=>ct,ReadWriteFactory:()=>k,ReadWriteHyperdrive:()=>l,ReadWriteLsEth:()=>z,ReadWriteLsEthHyperdrive:()=>mt,ReadWriteMockErc4626:()=>$,ReadWriteMockErc4626Hyperdrive:()=>nt,ReadWriteREth:()=>G,ReadWriteREthHyperdrive:()=>lt,ReadWriteRegistry:()=>yt,ReadWriteStEth:()=>M,ReadWriteStEthHyperdrive:()=>L,adjustAmountByPercentage:()=>le,calculateAprFromPrice:()=>U,calculateMatureLongYieldAfterFees:()=>se,erc20Abi:()=>J,erc4626Abi:()=>rt,ezEthHyperdriveAbi:()=>at,factoryAbi:()=>ft,getHprFromApr:()=>ge,getHprFromApy:()=>fe,getHyperdrive:()=>te,hyperdriveAbi:()=>H,hyperdriveRewardsAbi:()=>he,lsEthAbi:()=>dt,mockErc4626Abi:()=>ot,rEthAbi:()=>ht,registryAbi:()=>gt,stEthAbi:()=>Q,zapAbi:()=>me});module.exports=ve(He);var Ft=require("@delvtech/drift"),E=class extends Ft.DriftError{constructor(t,e){super(t,{...e,prefix:"\u16CB ",name:"Hyperdrive SDK Error"})}};var Qt=Dt(require("semver"),1);var $t=require("@delvtech/hyperdrive-artifacts/IHyperdrive"),H=$t.IHyperdrive.abi;var f=require("@delvtech/fixed-point-wasm");function K(s,t){if(t)return s;throw new E(`Unhandled discriminated union member: ${JSON.stringify(s)}`)}var Vt=require("@delvtech/fixed-point-wasm"),zt=require("@delvtech/hyperdrive-wasm");function U({positionDuration:s,baseAmount:t,bondAmount:e}){return(0,zt.calcAprGivenFixedPrice)({positionDuration:s,price:(0,Vt.fixed)(t).div(e).bigint})}var xt=31536000n,qt=115792089237316195423570985008687907853269984665640564039457584007913129639935n;var A="0x";var C=class{drift;debugName;constructor({debugName:t,drift:e,earliestBlock:r}){if(this.debugName=t??this.constructor.name,this.drift=e,r){let o=this.drift.contract;this.drift.contract=i=>{let n=o(i),a=n.getEvents;return n.getEvents=async function(c,d){let p={...d},h=p?.fromBlock,y=typeof h=="bigint"&&h<r;return(!h||h==="earliest"||y)&&(p.fromBlock=r),a(c,p)},n}}}};async function P(s,t){let e=await s.getBlock(t);if(!e){let r=t?.blockHash??t?.blockNumber??t?.blockTag;throw new E(`Block${r!==void 0?` ${r}`:""} not found`)}return e}function Gt(s){if(s===0)return"LP";if(s===1)return"LONG";if(s===2)return"SHORT";if(s===3)return"WITHDRAWAL_SHARE";throw new E(`parseAssetType(${s}) did not match a valid asset type.`)}function Ct(s){let t=s.slice(2),e=Number(t.slice(0,2)),r=Gt(e),o=t.slice(2,64),i=BigInt(parseInt(o,16));return{assetType:r,timestamp:i}}function X(s,t){return s-s%t}var Et=0n;var Yt=require("@delvtech/fixed-point-wasm");function Ut({openVaultSharePrice:s,endingVaultSharePrice:t,bondAmount:e,decimals:r}){return(0,Yt.fixed)(t-s).mul(e,r).bigint}var jt=0x0300000000000000000000000000000000000000000000000000000000000000n;var m=Dt(require("@delvtech/hyperdrive-wasm"),1);var Zt=require("@delvtech/hyperdrive-artifacts/IERC20"),J=Zt.IERC20.abi;var g=class extends C{contract;constructor({debugName:t="ERC-20 Token",address:e,cache:r,cacheNamespace:o,...i}){super({debugName:t,...i}),this.contract=this.drift.contract({abi:J,address:e,cache:r,cacheNamespace:o})}get address(){return this.contract.address}get namespace(){return this.contract.cacheNamespace}getName(){return this.contract.read("name")}getSymbol(){return this.contract.read("symbol")}getDecimals(){return this.contract.read("decimals")}getAllowance({owner:t,spender:e,options:r}){return this.contract.read("allowance",{owner:t,spender:e},r)}getBalanceOf({account:t,options:e}){return this.contract.read("balanceOf",{account:t},e)}getTotalSupply(t){return this.contract.read("totalSupply",{},t)}};var R=class s extends C{static address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";address=s.address;constructor({debugName:t="ETH",...e}){super({debugName:t,...e})}async getName(){return"Ethereum"}async getSymbol(){return"ETH"}async getDecimals(){return 18}async getAllowance(){return 2n**256n-1n}async getBalanceOf({account:t,options:e}){return this.drift.getBalance({address:t,...e})}};var u=class extends C{address;contract;zapContractAddress;constructor({debugName:t="Hyperdrive",address:e,cache:r,cacheNamespace:o,drift:i,zapContractAddress:n,...a}){super({debugName:t,drift:i,...a}),this.address=e,this.zapContractAddress=n,this.contract=this.drift.contract({abi:H,address:e,cache:r,cacheNamespace:o})}async getKind(){return this.contract.read("kind")}async getVersion(){let t=await this.contract.read("version"),[e,r,o]=t.replace(/^\D*/,"").split(".").map(i=>parseInt(i));return{major:e,minor:r,patch:o,string:t}}async getBaseToken(){let t=await this.contract.read("baseToken");return t===R.address?new R({drift:this.drift}):new g({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new g({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}getDecimals(){return this.contract.read("decimals")}async convertToBase({sharesAmount:t,options:e}){return this.contract.read("convertToBase",{_shareAmount:t},e)}async convertToShares({baseAmount:t,options:e}){return this.contract.read("convertToShares",{_baseAmount:t},e)}async getInitializationBlock(t){let e=await this.contract.getEvents("Initialize",t);if(!e.length||e[0].blockNumber===void 0)throw new E("Pool has not been initialized, no block found.");let r=e[0].blockNumber;return P(this.drift,{blockNumber:r})}async getYieldSourceRate({blockRange:t,options:e}){let r=await P(this.drift,e),o=r.blockNumber-t,{blockNumber:i}=await this.getInitializationBlock();i&&i>o&&(o=i);let n=await P(this.drift,{blockNumber:o}),{vaultSharePrice:a}=await this.getPoolInfo({block:o}),{vaultSharePrice:c}=await this.getPoolInfo(e),d=r.timestamp-n.timestamp;return Kt({startPrice:a,endPrice:c,timeFrame:d})}getCheckpointTime(t={}){return this._getCheckpointTime(t)}async _getCheckpointTime({timestamp:t,blockNumber:e,options:r}={}){let{checkpointDuration:o}=await this.getPoolConfig(r);if(t===void 0){let i=e?{blockNumber:e}:r;t=(await P(this.drift,i)).timestamp}return X(t,o)}async getCheckpoint({checkpointTime:t,timestamp:e,blockNumber:r,options:o}={}){t===void 0&&(t=await this._getCheckpointTime({timestamp:e,blockNumber:r,options:o}));let{lastWeightedSpotPriceUpdateTime:i,vaultSharePrice:n,weightedSpotPrice:a}=await this.contract.read("getCheckpoint",{_checkpointTime:t},o);return{checkpointTime:t,lastWeightedSpotPriceUpdateTime:i,vaultSharePrice:n,weightedSpotPrice:a}}async getCheckpointExposure({checkpointTime:t,blockNumber:e,timestamp:r,options:o}={}){return t===void 0&&(t=await this._getCheckpointTime({blockNumber:e,timestamp:r,options:o})),this.contract.read("getCheckpointExposure",{_checkpointTime:t},o)}getMarketState(t){return this.contract.read("getMarketState",void 0,t)}getPoolConfig(t){return this.contract.read("getPoolConfig",void 0,t)}getPoolInfo(t){return this.contract.read("getPoolInfo",void 0,t)}async getFixedApr(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return m.spotRate({poolConfig:e,poolInfo:r})}async getImpliedRate({bondAmount:t,timestamp:e,variableApy:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),{vaultSharePrice:a}=await this.getCheckpoint({timestamp:e});return a||(a=(await this.getPoolInfo()).vaultSharePrice),m.calcImpliedRate({poolInfo:n,poolConfig:i,bondAmount:t,openVaultSharePrice:a,variableApy:r})}async getIdleLiquidity(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return m.idleShareReservesInBase({poolInfo:r,poolConfig:e})}async getPresentValue(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t),o=m.presentValue({poolInfo:r,poolConfig:e,currentTime:BigInt(Date.now())/1000n});return this.convertToBase({sharesAmount:o,options:t})}async getShortAccruedYield({checkpointTime:t,bondAmount:e,options:r}){let{vaultSharePrice:o}=await this.getCheckpoint({checkpointTime:t,options:r}),{positionDuration:i}=await this.getPoolConfig(r),n=t+i,c=await this.getCheckpointTime({options:r})>=n,d;if(c)d=(await this.getCheckpoint({checkpointTime:n,options:r})).vaultSharePrice;else{let p=await this.getPoolInfo(r);d=p.vaultSharePrice,o!=0n||(o=p.vaultSharePrice)}return Ut({openVaultSharePrice:o,endingVaultSharePrice:d,bondAmount:e,decimals:await this.getDecimals()})}async getTradingVolume(t){let{fromBlock:e,toBlock:r}=t||{},o=await this.getLongEvents({fromBlock:e,toBlock:r}),i=await this.getShortEvents({fromBlock:e,toBlock:r}),n=o.reduce((c,{bondAmount:d})=>c+d,0n),a=i.reduce((c,{bondAmount:d})=>c+d,0n);return{longVolume:n,shortVolume:a,totalVolume:n+a}}async getLongPrice(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return m.spotPrice({poolConfig:e,poolInfo:r})}async getLongEvents(t){let e=await this.contract.getEvents("OpenLong",t),r=await this.contract.getEvents("CloseLong",t);return[...e,...r].map(({args:o,eventName:i,blockNumber:n,transactionHash:a})=>{let c=o.asBase?o.amount:(0,f.fixed)(o.amount).mul(o.vaultSharePrice).bigint;return{trader:o.trader,assetId:o.assetId,bondAmount:o.bondAmount,baseAmount:c,eventName:i,blockNumber:n,transactionHash:a}}).sort((o,i)=>Number(o.blockNumber)-Number(i.blockNumber))}async getShortEvents(t){let e=await this.contract.getEvents("OpenShort",t),r=await this.contract.getEvents("CloseShort",t);return[...e,...r].map(({args:o,eventName:i,blockNumber:n,transactionHash:a})=>{let c=o.asBase?o.amount:(0,f.fixed)(o.amount).mul(o.vaultSharePrice).bigint;return{trader:o.trader,assetId:o.assetId,bondAmount:o.bondAmount,baseAmount:c,eventName:i,blockNumber:n,transactionHash:a}}).sort((o,i)=>Number(o.blockNumber)-Number(i.blockNumber))}async getLpEvents(t){let e=await this.contract.getEvents("AddLiquidity",t),r=await this.contract.getEvents("RemoveLiquidity",t),o=await this.contract.getEvents("RedeemWithdrawalShares",t);return{addLiquidity:e,removeLiquidity:r,redeemWithdrawalShares:o}}async getLpApy({fromBlock:t,options:e}){let{blockNumber:r}=await this.getInitializationBlock();r&&r>t&&(t=r);let o=await P(this.drift,e),i=await P(this.drift,{blockNumber:t}),{lpSharePrice:n}=await this.getPoolInfo({block:t}),{lpSharePrice:a}=await this.getPoolInfo(),c=o.timestamp-i.timestamp;return{lpApy:Kt({startPrice:n,endPrice:a,timeFrame:c})}}async getCheckpointEvents(t){return await this.contract.getEvents("CreateCheckpoint",t)}_calcOpenLongs({openLongEvents:t,closeLongEvents:e}){let r=[...t,...e].sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber)),o={};return r.forEach(i=>{let n=i.args.assetId.toString(),a=o[n]||{assetId:i.args.assetId,maturity:i.args.maturityTime,baseAmountPaid:0n,bondAmount:0n},c=i.args.asBase?i.args.amount:(0,f.fixed)(i.args.amount).mul(i.args.vaultSharePrice).bigint;switch(i.eventName){case"OpenLong":o[n]={...a,baseAmountPaid:a.baseAmountPaid+c,bondAmount:a.bondAmount+i.args.bondAmount};return;case"CloseLong":i.args.bondAmount===a.bondAmount?delete o[n]:o[n]={...a,baseAmountPaid:a.baseAmountPaid-c,bondAmount:a.bondAmount-i.args.bondAmount};return;default:K(i,!0)}}),Object.values(o).filter(i=>i.bondAmount)}async getOpenLongPositions({account:t,options:e}){let r=await this.contract.getEvents("TransferSingle",{filter:{to:t},toBlock:e?.block}),o=await this.contract.getEvents("TransferSingle",{filter:{from:t},toBlock:e?.block}),i=r.filter(Xt),n=o.filter(Xt),a=[...i,...n].sort((d,p)=>Number(d.blockNumber)-Number(p.blockNumber)),c={};for(let d of a){let p=c[d.args.id.toString()]??{assetId:d.args.id,maturity:Ct(d.data).timestamp,value:0n};if(d.args.to===t)p.value+=d.args.value;else if(d.args.from===t&&(p.value-=d.args.value,p.value===0n)){delete c[d.args.id.toString()];continue}c[d.args.id.toString()]=p}return Object.values(c).filter(d=>d.value)}async getOpenLongDetails({assetId:t,account:e,options:r}){if(!(await this.getOpenLongPositions({account:e,options:r})).find(d=>d.assetId===t))throw new E(`No position with asset id: ${t} found for account ${e}`);let n=await this.contract.getEvents("OpenLong",{filter:{trader:e,assetId:t}}),a=await this.contract.getEvents("CloseLong",{filter:{trader:e,assetId:t}});if(this.zapContractAddress){let d=await this.contract.getEvents("TransferSingle",{filter:{from:e,to:this.zapContractAddress},toBlock:r?.block});if(d.length){let p=d.map(({transactionHash:b})=>b),y=(await this.contract.getEvents("CloseLong",{filter:{trader:this.zapContractAddress,assetId:t},fromBlock:d[0].blockNumber,toBlock:d.at(-1)?.blockNumber})).filter(({transactionHash:b})=>p.includes(b));for(let b of y)a.push(b)}}return this._calcOpenLongs({openLongEvents:n,closeLongEvents:a})[0]}async getOpenLongs({account:t,options:e}){let r=await this.contract.getEvents("OpenLong",{filter:{trader:t},toBlock:e?.block}),o=await this.contract.getEvents("CloseLong",{filter:{trader:t},toBlock:e?.block});return this._calcOpenLongs({openLongEvents:r,closeLongEvents:o})}async getOpenShorts({account:t,options:e}){let{checkpointDuration:r,positionDuration:o}=await this.getPoolConfig(e),i=await this.contract.getEvents("OpenShort",{filter:{trader:t},toBlock:e?.block}),n=await this.contract.getEvents("CloseShort",{filter:{trader:t},toBlock:e?.block});return this._calcOpenShorts({hyperdriveAddress:this.address,checkpointDuration:r,positionDuration:o,openShortEvents:i,closeShortEvents:n})}async _calcOpenShorts({hyperdriveAddress:t,checkpointDuration:e,positionDuration:r,closeShortEvents:o,openShortEvents:i}){let n=[...i,...o].sort((c,d)=>Number(c.blockNumber)-Number(d.blockNumber)),a={};for(let c of n){let d=c.args.assetId.toString(),{timestamp:p}=await P(this.drift,{blockNumber:c.blockNumber});a[d]=a[d]||{hyperdriveAddress:t,assetId:c.args.assetId,maturity:c.args.maturityTime,checkpointTime:X(p,e),openedTimestamp:p,baseAmountPaid:0n,bondAmount:0n,baseProceeds:0n,fixedRatePaid:0n};let h=c.args.asBase?c.args.amount:(0,f.fixed)(c.args.amount).mul(c.args.vaultSharePrice).bigint,{eventName:y}=c;switch(y){case"OpenShort":a[d].baseAmountPaid+=h,a[d].bondAmount+=c.args.bondAmount,a[d].baseProceeds+=c.args.baseProceeds,a[d].fixedRatePaid=U({positionDuration:r,baseAmount:a[d].baseProceeds,bondAmount:a[d].bondAmount});continue;case"CloseShort":{if(c.args.bondAmount===a[d].bondAmount){delete a[d];continue}a[d].baseAmountPaid-=h,a[d].bondAmount-=c.args.bondAmount,a[d].baseProceeds-=c.args.basePayment,a[d].fixedRatePaid=U({positionDuration:r,baseAmount:a[d].baseProceeds,bondAmount:a[d].bondAmount});continue}default:K(y,!0)}}return Object.values(a).filter(c=>c.bondAmount)}async getClosedLongs({account:t,options:e}){let r=await this.contract.getEvents("CloseLong",{filter:{trader:t},toBlock:e?.block});return(await Promise.all(r.map(async i=>{let n=i.args.assetId,a=i.args.asBase?i.args.amount:(0,f.fixed)(i.args.amount).mul(i.args.vaultSharePrice).bigint;return{assetId:n,bondAmount:i.args.bondAmount,baseAmount:a,baseAmountPaid:0n,maturity:i.args.maturityTime,closedTimestamp:(await P(this.drift,{blockNumber:i.blockNumber})).timestamp}}))).filter(i=>i.bondAmount)}async getClosedShorts({account:t,options:e}){let r=await this.contract.getEvents("CloseShort",{filter:{trader:t},toBlock:e?.block}),{checkpointDuration:o}=await this.getPoolConfig(e);return(await Promise.all(r.map(async n=>{let{assetId:a,maturityTime:c}=n.args,{timestamp:d}=await P(this.drift,{blockNumber:n.blockNumber}),p=n.args.asBase?n.args.amount:(0,f.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;return{hyperdriveAddress:this.address,assetId:a,bondAmount:n.args.bondAmount,baseAmountReceived:p,maturity:c,closedTimestamp:d,checkpointTime:X(d,o)}}))).filter(n=>n.bondAmount)}async getMaxShort({budget:t,options:e}){let r=await this.getPoolInfo(e),o=await this.getPoolConfig(e),i=await this.getCheckpointExposure({options:e}),{vaultSharePrice:n}=await this.getCheckpoint({options:e}),a=m.maxShort({budget:t,poolInfo:r,poolConfig:o,maxIterations:14,openVaultSharePrice:n,checkpointExposure:i}),c=m.calcOpenShort({poolInfo:r,poolConfig:o,bondAmount:a,openVaultSharePrice:n}),d=await this.convertToShares({baseAmount:c,options:e});return{maxBaseIn:c,maxSharesIn:d,maxBondsOut:a}}async getMaxLong(t){let e=await this.getPoolInfo(t),r=await this.getPoolConfig(t),o=await this.getCheckpointExposure({options:t}),i=m.maxLong({poolInfo:e,poolConfig:r,budget:qt,checkpointExposure:o}),n=await this.convertToShares({baseAmount:i,options:t}),a=m.calcOpenLong({poolInfo:e,poolConfig:r,baseAmount:i});return{maxBaseIn:i,maxSharesIn:n,maxBondsOut:a}}getLpSharesTotalSupply(t){return this.contract.read("totalSupply",{tokenId:Et},t?.options)}getLpShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:Et,owner:t},e)}async getOpenLpPosition({account:t,asBase:e,options:r}){let o=await this.contract.getEvents("AddLiquidity",{filter:{provider:t},toBlock:r?.block}),i=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},toBlock:r?.block}),n=await this.getDecimals(),{lpShareBalance:a,baseAmountPaid:c}=this._calcOpenLpPosition({addLiquidityEvents:o,removeLiquidityEvents:i});if(!a)return{lpShareBalance:a,baseAmountPaid:c,baseValue:0n,sharesValue:0n};let{proceeds:d,withdrawalShares:p}=await this.previewRemoveLiquidity({lpSharesIn:a,minOutputPerShare:1n,asBase:e,destination:t}),h=e?d:await this.convertToBase({sharesAmount:d}),{lpSharePrice:y}=await this.getPoolInfo(),b=(0,f.fixed)(y,n).mul(p,n).bigint,T=await this.convertToShares({baseAmount:b});return{lpShareBalance:a,baseAmountPaid:c,baseValue:h+b,sharesValue:d+T}}_calcOpenLpPosition({addLiquidityEvents:t,removeLiquidityEvents:e}){let r=[...t,...e].sort((n,a)=>Number(n.blockNumber)-Number(a.blockNumber)),o=0n,i=0n;return r.forEach(n=>{let a=n.args.asBase?n.args.amount:(0,f.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;switch(n.eventName){case"AddLiquidity":i+=n.args.lpAmount,o+=a;return;case"RemoveLiquidity":{if(i-=n.args.lpAmount,i<=0n)o=0n;else{let c=(0,f.fixed)(n.args.withdrawalShareAmount).mul(n.args.lpSharePrice).bigint;o=o-a-c}return}default:K(n,!0)}}),{lpShareBalance:i,baseAmountPaid:o}}async getClosedLpShares({account:t,options:e}){let r=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},toBlock:e?.block});return Promise.all(r.map(async({blockNumber:o,args:i})=>{let{lpAmount:n,withdrawalShareAmount:a,asBase:c,amount:d,lpSharePrice:p}=i,h=c?d:(0,f.fixed)(i.amount).mul(i.vaultSharePrice).bigint;return{lpAmount:n,baseAmount:h,withdrawalShareAmount:a,lpSharePrice:p,closedTimestamp:(await P(this.drift,{blockNumber:o})).timestamp}}))}getWithdrawalShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:jt,owner:t},e)}async getRedeemedWithdrawalShares({account:t,options:e}){let r=await this.contract.getEvents("RedeemWithdrawalShares",{filter:{provider:t},toBlock:e?.block});return Promise.all(r.map(async({blockNumber:o,args:i})=>{let{withdrawalShareAmount:n,amount:a,asBase:c,vaultSharePrice:d}=i,p=c?i.amount:(0,f.fixed)(a).mul(d).bigint;return{hyperdriveAddress:this.address,withdrawalShareAmount:n,baseAmount:p,redeemedTimestamp:(await P(this.drift,{blockNumber:o})).timestamp}}))}async previewOpenLong({amountIn:t,asBase:e,options:r}){let o=await this.getPoolConfig(r),i=await this.getPoolInfo(r),n=await this.getCheckpointTime({options:r}),a=t;e||(a=await this.convertToBase({sharesAmount:t,options:r}));let c=m.spotPriceAfterLong({poolInfo:i,poolConfig:o,baseAmount:a}),d=m.calcAprGivenFixedPrice({price:c,positionDuration:o.positionDuration}),p=m.calcOpenLong({poolInfo:i,poolConfig:o,baseAmount:a}),h=m.openLongCurveFee({poolInfo:i,poolConfig:o,baseAmount:a});return{maturityTime:n+o.positionDuration,bondProceeds:p,spotPriceAfterOpen:c,spotRateAfterOpen:d,curveFee:h}}async previewOpenShort({amountOfBondsToShort:t,asBase:e,options:r}){let o=await this.getPoolConfig(r),i=await this.getPoolInfo(r),n=await this.getCheckpoint({options:r}),a=await this.getShortAccruedYield({checkpointTime:n.checkpointTime,bondAmount:t,options:r}),c=m.calcOpenShort({poolInfo:i,poolConfig:o,bondAmount:t,openVaultSharePrice:n.vaultSharePrice}),d=(0,f.fixed)(o.positionDuration).div(xt),p=(0,f.fixed)(c).sub(a),h=(0,f.fixed)(t).sub(p),y=p.div(h).div(d).bigint,b=m.spotPriceAfterShort({poolInfo:i,poolConfig:o,bondAmount:t}),T=m.calcAprGivenFixedPrice({price:b,positionDuration:o.positionDuration}),Rt=m.openShortCurveFee({poolInfo:i,poolConfig:o,bondAmount:t});return e?{maturityTime:n.checkpointTime+o.positionDuration,traderDeposit:c,spotPriceAfterOpen:b,spotRateAfterOpen:T,curveFee:Rt,fixedRatePaid:y}:{maturityTime:n.checkpointTime+o.positionDuration,traderDeposit:await this.convertToShares({baseAmount:c,options:r}),spotPriceAfterOpen:b,spotRateAfterOpen:T,curveFee:await this.convertToShares({baseAmount:Rt,options:r}),fixedRatePaid:y}}async getShortBondsGivenDeposit({amountIn:t,asBase:e,tolerance:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=await this.getCheckpoint({options:o}),c=await this.getCheckpointExposure({options:o}),d=t;e||(d=await this.convertToBase({sharesAmount:t,options:o}));let p=m.absoluteMaxShort({poolInfo:n,poolConfig:i,checkpointExposure:c});return m.shortBondsGivenDeposit({poolInfo:n,poolConfig:i,targetBaseAmount:d,absoluteMaxBondAmount:p,openVaultSharePrice:a.vaultSharePrice,maybeTolerance:r})}async previewCloseLong({maturityTime:t,bondAmountIn:e,asBase:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=BigInt(Math.floor(Date.now()/1e3)),c=m.closeLongFlatFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a}),d=m.closeLongCurveFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a}),p=c+d,h=m.calcCloseLong({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a});return r?{amountOut:await this.convertToBase({sharesAmount:h,options:o}),flatPlusCurveFee:await this.convertToBase({sharesAmount:p,options:o})}:{amountOut:h,flatPlusCurveFee:p}}async estimateShortMarketValue({maturityTime:t,asBase:e,shortAmountIn:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=t-i.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:o}),d=BigInt(Math.floor(Date.now()/1e3)),p=n.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:o})).vaultSharePrice);let h=m.calcShortMarketValue({poolInfo:n,poolConfig:i,bondAmount:r,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return e?this.convertToBase({sharesAmount:h,options:o}):h}async previewCloseShort({maturityTime:t,shortAmountIn:e,asBase:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=t-i.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:o}),d=BigInt(Math.floor(Date.now()/1e3)),p=n.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:o})).vaultSharePrice);let h=m.closeShortFlatFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:d}),y=m.closeShortCurveFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:d}),b=h+y,T=m.calcCloseShort({poolInfo:n,poolConfig:i,bondAmount:e,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return r?{amountOut:await this.convertToBase({sharesAmount:T,options:o}),flatPlusCurveFee:await this.convertToBase({sharesAmount:b,options:o})}:{amountOut:T,flatPlusCurveFee:b}}async previewAddLiquidity({contribution:t,minApr:e,minLpSharePrice:r,maxApr:o,asBase:i,options:n}){let a=await this.getPoolConfig(n),c=await this.getPoolInfo(n),d=BigInt(Math.floor(Date.now()/1e3)),p=m.calcAddLiquidity({poolInfo:c,poolConfig:a,currentTime:d,contribution:t,asBase:i,minLpSharePrice:r,minApr:e,maxApr:o}),h=await this.getDecimals(),y=(0,f.fixed)(p,h).mul(c.lpSharePrice,h).bigint,b=i?y:await this.convertToShares({baseAmount:y,options:n});return{lpSharesOut:p,slippagePaid:t-b}}async previewRemoveLiquidity({lpSharesIn:t,minOutputPerShare:e,destination:r,asBase:o,extraData:i=A,options:n}){let{proceeds:a,withdrawalShares:c}=await this.contract.simulateWrite("removeLiquidity",{_lpShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},{...n,from:r});return{proceeds:a,withdrawalShares:c}}async previewRedeemWithdrawalShares({withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:o,extraData:i=A,options:n}){let{proceeds:a,withdrawalSharesRedeemed:c}=await this.contract.simulateWrite("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},n);return{asBase:o,baseProceeds:o?a:await this.convertToBase({sharesAmount:a}),sharesProceeds:o?await this.convertToShares({baseAmount:a}):a,withdrawalSharesRedeemed:c}}};function Kt({startPrice:s,endPrice:t,timeFrame:e}){let r=(0,f.fixed)(t).div(s),o=(0,f.fixed)(e).div(xt);return r.pow((0,f.fixed)(1e18).div(o)).sub(1e18).bigint}function Xt(s){let{assetType:t}=Ct(s.data);return t==="LONG"}var x=class extends g{constructor(t){super(t)}async approve({spender:t,amount:e,options:r}){return await this.contract.write("approve",{spender:t,amount:e},{...r,onMined:i=>{this.contract.invalidateReadsMatching("allowance"),r?.onMined?.(i)}})}};var v=class extends R{constructor(t){super(t)}async approve(){throw new E("This method is not available for the native ETH token.")}};var l=class extends u{constructor(t){super(t)}async getBaseToken(t){let e=await this.contract.read("baseToken",{},t);return e===v.address?new v({drift:this.drift}):new x({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new x({address:t,drift:this.drift,cacheNamespace:this.contract.cacheNamespace})}async checkpoint({args:{time:t},options:e}){return this.contract.write("checkpoint",{_checkpointTime:BigInt(t),_maxIterations:4n},{...e,onMined:r=>{this.contract.cache.clear(),e?.onMined?.(r)}})}async pause({args:{paused:t},options:e}){return this.contract.write("pause",{_status:t},{...e,onMined:r=>{this.contract.invalidateReadsMatching("getMarketState"),e?.onMined?.(r)}})}async initialize({args:{contribution:t,apr:e,destination:r,asBase:o=!0,extraData:i=A},options:n}){return this.contract.write("initialize",{_apr:e,_contribution:t,_options:{destination:r,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}async openLong({args:{destination:t,amount:e,minBondsOut:r,minVaultSharePrice:o,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("openLong",{_amount:e,_minOutput:r,_minVaultSharePrice:o,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async openShort({args:{destination:t,bondAmount:e,minVaultSharePrice:r,maxDeposit:o,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("openShort",{_bondAmount:e,_maxDeposit:o,_minVaultSharePrice:r,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeLong({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:o,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("closeLong",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:o,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeShort({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:o,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("closeShort",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:o,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async addLiquidity({args:{destination:t,contribution:e,minApr:r,minLpSharePrice:o,maxApr:i,asBase:n=!0,extraData:a=A},options:c}){return this.contract.write("addLiquidity",{_contribution:e,_minLpSharePrice:o,_minApr:r,_maxApr:i,_options:{destination:t,asBase:n,extraData:a}},{...c,onMined:d=>{this.contract.cache.clear(),c?.onMined?.(d)}})}async removeLiquidity({args:{destination:t,lpSharesIn:e,minOutputPerShare:r,asBase:o=!0,extraData:i=A},options:n}){return this.contract.write("removeLiquidity",{_lpShares:e,_minOutputPerShare:r,_options:{destination:t,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}async redeemWithdrawalShares({args:{withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:o=!0,extraData:i=A},options:n}){return this.contract.write("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}};var At=require("@delvtech/fixed-point-wasm");var Jt=require("@delvtech/hyperdrive-artifacts/ILido"),Q=Jt.ILido.abi;var W=class extends vt(g){};function vt(s){return class extends s{stEthContract;constructor(...[t]){let{debugName:e="stETH Token",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.stEthContract=this.drift.contract({abi:Q,address:r,cache:o,cacheNamespace:i})}getSharesOf({account:t,options:e}){return this.stEthContract.read("sharesOf",{_account:t},e)}getPooledEthByShares({sharesAmount:t,options:e}){return this.stEthContract.read("getPooledEthByShares",{_sharesAmount:t},e)}getSharesByPooledEth({ethAmount:t,options:e}){return this.stEthContract.read("getSharesByPooledEth",{_ethAmount:t},e)}}}var I=class extends j(u){constructor(t){super(t)}};function j(s){return class extends s{constructor(...[t]){let{debugName:e="stETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(){let{vaultSharesToken:t}=await this.getPoolConfig();return new W({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getMaxShort({budget:t,options:e}){let r=await super.getMaxShort({budget:t,options:e}),o=await this.getDecimals();return{...r,maxSharesIn:(0,At.fixed)(r.maxSharesIn,o).mul(1e18-1e12,18).bigint}}async getMaxLong(t){let e=await super.getMaxLong(t),r=await this.getDecimals();return{...e,maxSharesIn:(0,At.fixed)(e.maxSharesIn,r).mul(1e18-1e12,18).bigint}}}}var M=class extends vt(x){};var L=class extends Pt(l){};function Pt(s){return class extends j(s){async getBaseToken(){return new v({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new M({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var Ot=require("@delvtech/fixed-point-wasm");var B=class extends St(u){};function St(s){return class extends s{constructor(...[t]){let{debugName:e="Hyperdrive v1.0.14",...r}=t;super({debugName:e,...r})}async convertToBase({sharesAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),o=await this.getDecimals();return(0,Ot.fixed)(t,o).mul(r,o).bigint}async convertToShares({baseAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),o=await this.getDecimals();return(0,Ot.fixed)(t,o).div(r).bigint}}}var tt=class extends j(B){};var N=class extends St(l){};var et=class extends Pt(N){};async function te({address:s,drift:t,cache:e=t.cache,cacheNamespace:r,earliestBlock:o,debugName:i,zapContractAddress:n}){r??=await t.getChainId();let a={address:s,drift:t,cache:e,cacheNamespace:r,earliestBlock:o,debugName:i,zapContractAddress:n},c=Pe(a),d=await t.read({abi:H,address:s,fn:"version",cacheNamespace:r}),p=Qt.default.lte(d,"1.0.14");switch(p?void 0:await t.read({abi:H,address:s,fn:"kind",cacheNamespace:r})){case"StETHHyperdrive":return c&&p?new et(a):c?new L(a):p?new tt(a):new I(a);default:return c&&p?new N(a):c?new l(a):p?new B(a):new u(a)}}function Pe(s){return typeof s.drift.write=="function"}var ee=require("@delvtech/hyperdrive-artifacts/IERC4626"),re=require("@delvtech/hyperdrive-artifacts/MockERC4626"),rt=ee.IERC4626.abi,ot=re.MockERC4626.abi;var S=class extends wt(g){};function wt(s){return class extends s{erc4626Contract;constructor(...[t]){let{debugName:e="ERC-4626 Tokenized Vault",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.erc4626Contract=this.drift.contract({abi:rt,address:r,cache:o,cacheNamespace:i})}getTotalAssets(t){return this.erc4626Contract.read("totalAssets",{},t)}convertToAssets({sharesAmount:t,options:e}){return this.erc4626Contract.read("convertToAssets",{shares:t},e)}convertToShares({assetsAmount:t,options:e}){return this.erc4626Contract.read("convertToShares",{assets:t},e)}}}var _=class extends kt(u){};function kt(s){return class extends s{constructor(...[t]){let{debugName:e="ERC-4626 Hyperdrive",...r}=t;super({debugName:e,...r})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new S({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var D=class extends Tt(S){};function Tt(s){return class extends s{mockErc4626Contract;constructor(...[t]){let{debugName:e="Mock ERC-4626 Tokenized Vault",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.mockErc4626Contract=this.drift.contract({abi:ot,address:r,cache:o,cacheNamespace:i})}getRate(t){return this.mockErc4626Contract.read("getRate",{},t)}}}var it=class extends Ht(_){};function Ht(s){return class extends s{constructor(...[t]){let{debugName:e}=t;super({debugName:e??"Mock ERC-4626 Hyperdrive",...t})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new D({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var w=class extends wt(x){};var F=class extends Oe(l){};function Oe(s){return class extends kt(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new w({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var $=class extends Tt(w){mint({receiver:t,sharesAmount:e,options:r}){return this.mockErc4626Contract.write("mint",{_receiver:t,_shares:e},r)}setRate({rate:t,options:e}){return this.mockErc4626Contract.write("setRate",{_rate_:t},e)}};var nt=class extends Se(F){};function Se(s){return class extends Ht(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new $({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var oe=require("@delvtech/hyperdrive-artifacts/IEzETHHyperdrive"),at=oe.IEzETHHyperdrive.abi;var st=class extends Wt(u){};function Wt(s){return class extends s{ezEthHyperdriveContract;constructor(...[t]){let{debugName:e="EzETH Hyperdrive",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.ezEthHyperdriveContract=this.drift.contract({abi:at,address:r,cache:o,cacheNamespace:i})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(){let{vaultSharesToken:t}=await this.getPoolConfig();return new g({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var ct=class extends we(l){};function we(s){return class extends Wt(s){async getBaseToken(){return new v({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new x({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var ie=require("@delvtech/hyperdrive-artifacts/IRiverV1"),dt=ie.IRiverV1.abi;var V=class extends It(g){};function It(s){return class extends s{lsEthContract;constructor(...[t]){let{drift:e,address:r,cache:o,cacheNamespace:i}=t;super({address:r,drift:e,cache:o,cacheNamespace:i}),this.lsEthContract=e.contract({abi:dt,address:r,cache:o,cacheNamespace:i})}async getTotalEthSupply(t){return this.lsEthContract.read("totalUnderlyingSupply",{},t)}async getEthBalanceOf({account:t,options:e}){return this.lsEthContract.read("balanceOfUnderlying",{_owner:t},e)}async getEthBalanceFromShares({sharesAmount:t,options:e}){return this.lsEthContract.read("underlyingBalanceFromShares",{_shares:t},e)}async getSharesFromEthBalance({ethBalance:t,options:e}){return this.lsEthContract.read("sharesFromUnderlyingBalance",{_underlyingAssetAmount:t},e)}}}var pt=class extends Mt(u){};function Mt(s){return class extends s{constructor(...[t]){let{debugName:e="lsETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new V({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var z=class extends It(x){};var mt=class extends ke(l){};function ke(s){return class extends Mt(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new z({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getBaseToken(){return new v({drift:this.drift})}}}var Bt=require("@delvtech/fixed-point-wasm");var ne=require("@delvtech/hyperdrive-artifacts/IRocketTokenRETH"),ht=ne.IRocketTokenRETH.abi;var q=class extends Lt(g){};function Lt(s){return class extends s{rEthContract;constructor(...[t]){let{drift:e,address:r,cache:o,cacheNamespace:i}=t;super({address:r,drift:e,cache:o,cacheNamespace:i}),this.rEthContract=e.contract({abi:ht,address:r,cache:o,cacheNamespace:i})}async getTotalEthSupply(t){return this.rEthContract.read("getTotalCollateral",{},t)}async getEthBalanceOf({account:t,options:e}){let r=await this.getBalanceOf({account:t,options:e});return this.rEthContract.read("getEthValue",{_rethAmount:r},e)}async getEthValue({rEthAmount:t,options:e}){return this.rEthContract.read("getEthValue",{_rethAmount:t},e)}async getREthValue({ethAmount:t,options:e}){return this.rEthContract.read("getRethValue",{_ethAmount:t},e)}}}var ut=class extends Nt(u){};function Nt(s){return class extends s{constructor(...[t]){let{debugName:e="rETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new q({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getMaxShort({budget:t,options:e}){let r=await super.getMaxShort({budget:t,options:e}),o=await this.getDecimals();return{...r,maxSharesIn:(0,Bt.fixed)(r.maxSharesIn,o).mul(1e18-1e12,18).bigint}}async getMaxLong(t){let e=await super.getMaxLong(t),r=await this.getDecimals();return{...e,maxSharesIn:(0,Bt.fixed)(e.maxSharesIn,r).mul(1e18-1e12,18).bigint}}}}var G=class extends Lt(x){};var lt=class extends Te(l){};function Te(s){return class extends Nt(s){async getBaseToken(){return new v({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new G({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var ae=require("@delvtech/fixed-point-wasm");function se({flatFee:s,bondAmount:t,baseAmountPaid:e,decimals:r}){let o=(0,ae.fixed)(t,r).mul(s).bigint;return t-e-o}var ce=require("@delvtech/hyperdrive-artifacts/IHyperdriveRegistry"),gt=ce.IHyperdriveRegistry.abi;var de=require("@delvtech/hyperdrive-artifacts/IHyperdriveFactory"),ft=de.IHyperdriveFactory.abi;var O=class extends C{address;contract;constructor({debugName:t="Hyperdrive Factory",address:e,cache:r,cacheNamespace:o,...i}){super({debugName:t,...i}),this.address=e,this.contract=this.drift.contract({abi:ft,address:e,cache:r,cacheNamespace:o})}async getIsInstance(t){return this.contract.read("isInstance",{_instance:t})}async getIsDeployerCoordinator(t){return this.contract.read("isDeployerCoordinator",{_deployerCoordinator:t})}async getDeployerCoordinatorAddresses({instances:t,options:e}={}){if(t)return(await this.contract.read("getDeployerCoordinatorByInstances",{__instances:t})).slice();let r=await this.contract.read("getNumberOfDeployerCoordinators",{},e);return r===0n?[]:(await this.contract.read("getDeployerCoordinatorsInRange",{_startIndex:0n,_endIndex:r},e)).slice()}async getInstances(t){return(await this.getInstanceAddresses(t)).map(r=>new u({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstanceAddresses(t){let e=await this.contract.read("getNumberOfInstances",{},t);return e===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:e},t)).slice()}};var Y=class extends C{address;contract;constructor({debugName:t="Hyperdrive Registry",address:e,cache:r,cacheNamespace:o,...i}){super({debugName:t,...i}),this.address=e,this.contract=this.drift.contract({abi:gt,address:e,cache:r,cacheNamespace:o})}async getFactories(t){return(await this.getFactoryAddresses(t)).map(r=>new O({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getFactoryAddresses(t){let e=await this.contract.read("getNumberOfFactories",{},t);return e===0n?[]:(await this.contract.read("getFactoriesInRange",{_startIndex:0n,_endIndex:e},t)).slice()}async getFactoryInfo(t,e){return this.contract.read("getFactoryInfoWithMetadata",{_factory:t},e)}async getFactoryInfos(t,e){return(await this.contract.read("getFactoryInfosWithMetadata",{__factories:t},e)).slice()}async getInstances(t){return(await this.getInstanceAddresses(t)).map(r=>new u({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstanceAddresses(t){let e=await this.contract.read("getNumberOfInstances",{},t);return e===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:e},t)).slice()}async getInstanceInfo(t,e){let{factory:r,...o}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:t},e);return{factory:new O({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...o}}async getInstanceInfos(t,e){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:t},e)).map(({factory:o,...i})=>({factory:new O({address:o,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...i}))}};var k=class extends O{constructor(t){super(t)}async getInstances(t){return(await this.getInstanceAddresses(t)).map(r=>new l({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}};var yt=class extends Y{constructor(t){super(t)}async getFactories(t){return(await this.getFactoryAddresses(t)).map(r=>new k({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstances(t){let e=await this.contract.read("getNumberOfInstances",{},t);return e===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:e},t)).map(o=>new l({address:o,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstanceInfo(t,e){let{factory:r,...o}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:t},e);return{factory:new k({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...o}}async getInstanceInfos(t,e){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:t},e)).map(({factory:o,...i})=>({factory:new k({address:o,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...i}))}};var pe=require("@delvtech/hyperdrive-artifacts/UniV3Zap"),me=pe.UniV3Zap.abi;var he=[{type:"constructor",inputs:[{name:"initialOwner",type:"address",internalType:"address"},{name:"initialTimelock",type:"uint256",internalType:"uint256"},{name:"initialRoot",type:"bytes32",internalType:"bytes32"},{name:"initialIpfsHash",type:"bytes32",internalType:"bytes32"}],stateMutability:"nonpayable"},{type:"function",name:"acceptRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"batchClaim",inputs:[{name:"_accounts",type:"address[]",internalType:"address[]"},{name:"_rewards",type:"address[]",internalType:"address[]"},{name:"_claimable",type:"uint256[]",internalType:"uint256[]"},{name:"_proofs",type:"bytes32[][]",internalType:"bytes32[][]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"},{name:"claimable",type:"uint256",internalType:"uint256"},{name:"proof",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"claimed",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"ipfsHash",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"isUpdater",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"pendingRoot",inputs:[],outputs:[{name:"root",type:"bytes32",internalType:"bytes32"},{name:"ipfsHash",type:"bytes32",internalType:"bytes32"},{name:"validAt",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"revokePendingRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"root",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"setOwner",inputs:[{name:"newOwner",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRootUpdater",inputs:[{name:"updater",type:"address",internalType:"address"},{name:"active",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setTimelock",inputs:[{name:"newTimelock",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"submitRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"timelock",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"error",name:"ArrayEndIndexLessThanStartIndex",inputs:[]},{type:"error",name:"ArrayIndexOutOfBounds",inputs:[]},{type:"error",name:"IncorrectLength",inputs:[]}];var bt=class extends C{constructor(t){super(t)}};var ue=require("@delvtech/fixed-point-wasm");function le({amount:s,percentage:t,decimals:e,direction:r}){let o=(0,ue.fixed)(s,e).mul(t,e).div(100,0);return r==="down"?s-o.bigint:s+o.bigint}function ge(s,t){return m.calcHprGivenApr({apr:s,positionDuration:t})}function fe(s,t){return m.calcHprGivenApy({apy:s,positionDuration:t})}0&&(module.exports={HyperdriveSdkError,ReadClient,ReadErc20,ReadErc4626,ReadErc4626Hyperdrive,ReadEth,ReadEzEthHyperdrive,ReadFactory,ReadHyperdrive,ReadLsEth,ReadLsEthHyperdrive,ReadMockErc4626,ReadMockErc4626Hyperdrive,ReadREth,ReadREthHyperdrive,ReadRegistry,ReadStEth,ReadStEthHyperdrive,ReadWriteClient,ReadWriteErc20,ReadWriteErc4626,ReadWriteErc4626Hyperdrive,ReadWriteEth,ReadWriteEzEthHyperdrive,ReadWriteFactory,ReadWriteHyperdrive,ReadWriteLsEth,ReadWriteLsEthHyperdrive,ReadWriteMockErc4626,ReadWriteMockErc4626Hyperdrive,ReadWriteREth,ReadWriteREthHyperdrive,ReadWriteRegistry,ReadWriteStEth,ReadWriteStEthHyperdrive,adjustAmountByPercentage,calculateAprFromPrice,calculateMatureLongYieldAfterFees,erc20Abi,erc4626Abi,ezEthHyperdriveAbi,factoryAbi,getHprFromApr,getHprFromApy,getHyperdrive,hyperdriveAbi,hyperdriveRewardsAbi,lsEthAbi,mockErc4626Abi,rEthAbi,registryAbi,stEthAbi,zapAbi});
"use strict";var Vt=Object.create;var F=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var zt=Object.getPrototypeOf,Yt=Object.prototype.hasOwnProperty;var K=(o,t)=>()=>(t||o((t={exports:{}}).exports,t),t.exports),Ut=(o,t)=>{for(var e in t)F(o,e,{get:t[e],enumerable:!0})},at=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of qt(t))!Yt.call(o,i)&&i!==e&&F(o,i,{get:()=>t[i],enumerable:!(r=Gt(t,i))||r.enumerable});return o};var J=(o,t,e)=>(e=o!=null?Vt(zt(o)):{},at(t||!o||!o.__esModule?F(e,"default",{value:o,enumerable:!0}):e,o)),Zt=o=>at(F({},"__esModule",{value:!0}),o);var pt=K((ae,dt)=>{"use strict";function v(o,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(o)),this._timeouts=o,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}dt.exports=v;v.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};v.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};v.prototype.retry=function(o){if(this._timeout&&clearTimeout(this._timeout),!o)return!1;var t=new Date().getTime();if(o&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(o),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(o);var e=this._timeouts.shift();if(e===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),e=this._cachedTimeouts.slice(-1);else return!1;var r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},e),this._options.unref&&this._timer.unref(),!0};v.prototype.attempt=function(o,t){this._fn=o,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var e=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){e._operationTimeoutCb()},e._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};v.prototype.try=function(o){console.log("Using RetryOperation.try() is deprecated"),this.attempt(o)};v.prototype.start=function(o){console.log("Using RetryOperation.start() is deprecated"),this.attempt(o)};v.prototype.start=v.prototype.try;v.prototype.errors=function(){return this._errors};v.prototype.attempts=function(){return this._attempts};v.prototype.mainError=function(){if(this._errors.length===0)return null;for(var o={},t=null,e=0,r=0;r<this._errors.length;r++){var i=this._errors[r],n=i.message,a=(o[n]||0)+1;o[n]=a,a>=e&&(t=i,e=a)}return t}});var mt=K(C=>{"use strict";var jt=pt();C.operation=function(o){var t=C.timeouts(o);return new jt(t,{forever:o&&(o.forever||o.retries===1/0),unref:o&&o.unref,maxRetryTime:o&&o.maxRetryTime})};C.timeouts=function(o){if(o instanceof Array)return[].concat(o);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var e in o)t[e]=o[e];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return o&&o.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(n,a){return n-a}),r};C.createTimeout=function(o,t){var e=t.randomize?Math.random()+1:1,r=Math.round(e*Math.max(t.minTimeout,1)*Math.pow(t.factor,o));return r=Math.min(r,t.maxTimeout),r};C.wrap=function(o,t,e){if(t instanceof Array&&(e=t,t=null),!e){e=[];for(var r in o)typeof o[r]=="function"&&e.push(r)}for(var i=0;i<e.length;i++){var n=e[i],a=o[n];o[n]=function(c){var d=C.operation(t),p=Array.prototype.slice.call(arguments,1),u=p.pop();p.push(function(l){d.retry(l)||(l&&(arguments[0]=d.mainError()),u.apply(this,arguments))}),d.attempt(function(){c.apply(o,p)})}.bind(o,a),o[n].options=t}}});var lt=K((ce,ut)=>{"use strict";ut.exports=mt()});var re={};Ut(re,{HyperdriveSdkError:()=>y,ReadClient:()=>f,ReadErc20:()=>O,ReadEth:()=>S,ReadFactory:()=>P,ReadHyperdrive:()=>b,ReadRegistry:()=>W,ReadWriteClient:()=>Z,ReadWriteErc20:()=>T,ReadWriteEth:()=>I,ReadWriteFactory:()=>E,ReadWriteHyperdrive:()=>w,ReadWriteRegistry:()=>U,adjustAmountByPercentage:()=>Mt,calculateAprFromPrice:()=>D,calculateMatureLongYieldAfterFees:()=>kt,erc20Abi:()=>V,factoryAbi:()=>Y,getHprFromApr:()=>Ft,getHprFromApy:()=>$t,getHyperdrive:()=>Tt,hyperdriveAbi:()=>L,hyperdriveRewardsAbi:()=>Dt,registryAbi:()=>z,zapAbi:()=>Bt});module.exports=Zt(re);var st=require("@delvtech/drift"),y=class extends st.DriftError{constructor(t,e){super(t,{...e,prefix:"\u16CB ",name:"Hyperdrive SDK Error"})}};var Ct=J(require("semver"),1);var ct=require("@delvtech/hyperdrive-artifacts/IHyperdrive"),L=ct.IHyperdrive.abi;var g=require("@delvtech/fixed-point-wasm");var gt=J(lt(),1);var Kt=Object.prototype.toString,Jt=o=>Kt.call(o)==="[object Error]",Xt=new Set(["network error","Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Load failed","Network request failed","fetch failed","terminated"]);function X(o){return o&&Jt(o)&&o.name==="TypeError"&&typeof o.message=="string"?o.message==="Load failed"?o.stack===void 0:Xt.has(o.message):!1}var Q=class extends Error{constructor(t){super(),t instanceof Error?(this.originalError=t,{message:t}=t):(this.originalError=new Error(t),this.originalError.stack=this.stack),this.name="AbortError",this.message=t}},ht=(o,t,e)=>{let r=e.retries-(t-1);return o.attemptNumber=t,o.retriesLeft=r,o};async function tt(o,t){return new Promise((e,r)=>{t={...t},t.onFailedAttempt??=()=>{},t.shouldRetry??=()=>!0,t.retries??=10;let i=gt.default.operation(t),n=()=>{i.stop(),r(t.signal?.reason)};t.signal&&!t.signal.aborted&&t.signal.addEventListener("abort",n,{once:!0});let a=()=>{t.signal?.removeEventListener("abort",n),i.stop()};i.attempt(async s=>{try{let c=await o(s);a(),e(c)}catch(c){try{if(!(c instanceof Error))throw new TypeError(`Non-error was thrown: "${c}". You should only throw errors.`);if(c instanceof Q)throw c.originalError;if(c instanceof TypeError&&!X(c))throw c;if(ht(c,s,t),await t.shouldRetry(c)||(i.stop(),r(c)),await t.onFailedAttempt(c),!i.retry(c))throw i.mainError()}catch(d){ht(d,s,t),a(),r(d)}}})})}function $(o,t){if(t)return o;throw new y(`Unhandled discriminated union member: ${JSON.stringify(o)}`)}var ft=require("@delvtech/fixed-point-wasm"),yt=require("@delvtech/hyperdrive-wasm");function D({positionDuration:o,baseAmount:t,bondAmount:e}){return(0,yt.calcAprGivenFixedPrice)({positionDuration:o,price:(0,ft.fixed)(t).div(e).bigint})}var et=31536000n,bt=115792089237316195423570985008687907853269984665640564039457584007913129639935n,A="0x";var H=class extends y{constructor(t,e){let{event:r,address:i}=e[0],n=`Failed to fetch "${r}" events from ${i} on chain ${t}.`;n+=`
Requested block ranges:`;for(let a of e)n+=`
- ${a.fromBlock} to ${a.toBlock}`;super(n)}};async function At({params:o,drift:t,epochBlock:e=0n,retries:r=3,backoff:i=n=>2**n*100}){let n=typeof i=="number"?()=>i:i,a=await t.getChainId(),s=new Map,c=[o];for(let d=0;d<=r;d++){let p=[],u=!1,l=await Promise.all(c.map(async(x,M)=>{let j=[x.fromBlock,x.toBlock].join("-"),k=s.get(j);if(k)return p[M]=[x],k;if(k=await t.cache.getEvents(x),k)return s.set(j,k),p[M]=[x],k;try{let _=await t.adapter.getEvents(x);return s.set(j,_),t.cache.preloadEvents({...x,value:_}),p[M]=[x],_}catch{u=!0;let _=await Qt(t,x,e);if(!_)throw new H(a,c);return p[M]=_,[]}}));if(!u)return l.flat();let h=new H(a,c);if(d===r)throw h;c=p.flat();let R=h.message;R+=`
Number of attempts left: ${r-d}`,R+=`
Retrying with ${c.length} requests...`,console.warn(R);let B=n(d),Nt=Math.floor(B*(.5+Math.random()));await te(Nt)}throw new H(a,[o])}async function vt(o,t,e=0n){if(typeof t=="bigint")return t;if(t==="earliest")return e;let{number:r}=await o.getBlock(t);return r}async function Qt(o,{fromBlock:t,toBlock:e,...r},i=0n){if(t===e||(t=await vt(o,t,i),t===void 0)||(e=await vt(o,e,i),e===void 0||t>=e))return null;let n=e-t,a=t+n/2n;return[{fromBlock:t,toBlock:a,...r},{fromBlock:a+1n,toBlock:e,...r}]}function te(o){return new Promise(t=>setTimeout(t,o))}var f=class{drift;debugName;constructor({debugName:t,drift:e,epochBlock:r,eventQueryRetries:i=3,eventQueryRetryBackoff:n=a=>2**a*100}){this.debugName=t??this.constructor.name,this.drift=e,e.hooks.on("before:getEvents",async({args:a,resolve:s})=>{let[{fromBlock:c,toBlock:d,...p}]=a,u=await At({params:{fromBlock:c,toBlock:d,...p},drift:e,epochBlock:r,retries:i,backoff:n});s(u)})}};function wt(o){if(o===0)return"LP";if(o===1)return"LONG";if(o===2)return"SHORT";if(o===3)return"WITHDRAWAL_SHARE";throw new y(`parseAssetType(${o}) did not match a valid asset type.`)}function rt(o){let t=o.slice(2),e=Number(t.slice(0,2)),r=wt(e),i=t.slice(2,64),n=BigInt(parseInt(i,16));return{assetType:r,timestamp:n}}function N(o,t){return o-o%t}var it=0n;var Rt=require("@delvtech/fixed-point-wasm");function Pt({openVaultSharePrice:o,endingVaultSharePrice:t,bondAmount:e,decimals:r}){return(0,Rt.fixed)(t-o).mul(e,r).bigint}var xt=0x0300000000000000000000000000000000000000000000000000000000000000n;var m=J(require("@delvtech/hyperdrive-wasm"),1);var Ot=require("@delvtech/hyperdrive-artifacts/IERC20"),V=Ot.IERC20.abi;var O=class extends f{contract;constructor({debugName:t="ERC-20 Token",address:e,epochBlock:r,...i}){super({debugName:t,epochBlock:r,...i}),this.contract=this.drift.contract({abi:V,address:e,epochBlock:r})}get address(){return this.contract.address}getName(){return this.contract.read("name")}getSymbol(){return this.contract.read("symbol")}getDecimals(){return this.contract.read("decimals")}getAllowance({owner:t,spender:e,options:r}){return this.contract.read("allowance",{owner:t,spender:e},r)}getBalanceOf({account:t,options:e}){return this.contract.read("balanceOf",{account:t},e)}getTotalSupply(t){return this.contract.read("totalSupply",{},t)}};var S=class o extends f{static address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";address=o.address;constructor({debugName:t="ETH",...e}){super({debugName:t,...e})}async getName(){return"Ethereum"}async getSymbol(){return"ETH"}async getDecimals(){return 18}async getAllowance(){return 2n**256n-1n}async getBalanceOf({account:t,options:e}){return this.drift.getBalance({address:t,...e})}};var b=class extends f{address;contract;zapContractAddress;constructor({debugName:t="Hyperdrive",address:e,epochBlock:r,zapContractAddress:i,...n}){super({debugName:t,epochBlock:r,...n}),this.address=e,this.zapContractAddress=i,this.contract=this.drift.contract({abi:L,address:e,epochBlock:r})}async getKind(){return this.contract.read("kind")}async getVersion(){let t=await this.contract.read("version"),[e,r,i]=t.replace(/^\D*/,"").split(".").map(n=>parseInt(n));return{major:e,minor:r,patch:i,string:t}}async getBaseToken(){let t=await this.contract.read("baseToken");return t===S.address?new S({drift:this.drift}):new O({address:t,drift:this.drift})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new O({address:t,drift:this.drift})}getDecimals(){return this.contract.read("decimals")}async convertToBase({sharesAmount:t,options:e}){return this.contract.read("convertToBase",{_shareAmount:t},e)}async convertToShares({baseAmount:t,options:e}){return this.contract.read("convertToShares",{_baseAmount:t},e)}async getInitializationBlock(t){let r=(await tt(async()=>{let i=await this.contract.getEvents("Initialize",t);if(!i.length||i[0].blockNumber===void 0)throw this.contract.cache.clear(),new y(`Pool has not been initialized, no block found. ${this.address}`);return i},{retries:10,onFailedAttempt:async i=>{console.log(`getInitializationBlock failed on Hyperdrive ${this.address}, chainId: ${await this.drift.getChainId()}. There are ${i.retriesLeft} retries left.`)}}))[0].blockNumber;return this.drift.getBlock(r,{throws:!0})}async getYieldSourceRate({blockRange:t,options:e}){let r=await this.drift.getBlock(e?.block,{throws:!0}),i=r.number-t,{number:n}=await this.getInitializationBlock();n&&n>i&&(i=n);let a=await this.drift.getBlock(i,{throws:!0}),{vaultSharePrice:s}=await this.getPoolInfo({block:i}),{vaultSharePrice:c}=await this.getPoolInfo(e),d=r.timestamp-a.timestamp;return St({startPrice:s,endPrice:c,timeFrame:d})}getCheckpointTime(t={}){return this._getCheckpointTime(t)}async _getCheckpointTime({timestamp:t,blockNumber:e,options:r}={}){let{checkpointDuration:i}=await this.getPoolConfig(r);return t===void 0&&(t=(await this.drift.getBlock(e??r?.block,{throws:!0})).timestamp),N(t,i)}async getCheckpoint({checkpointTime:t,timestamp:e,blockNumber:r,options:i}={}){t===void 0&&(t=await this._getCheckpointTime({timestamp:e,blockNumber:r,options:i}));let{lastWeightedSpotPriceUpdateTime:n,vaultSharePrice:a,weightedSpotPrice:s}=await this.contract.read("getCheckpoint",{_checkpointTime:t},i);return{checkpointTime:t,lastWeightedSpotPriceUpdateTime:n,vaultSharePrice:a,weightedSpotPrice:s}}async getCheckpointExposure({checkpointTime:t,blockNumber:e,timestamp:r,options:i}={}){return t===void 0&&(t=await this._getCheckpointTime({blockNumber:e,timestamp:r,options:i})),this.contract.read("getCheckpointExposure",{_checkpointTime:t},i)}getMarketState(t){return this.contract.read("getMarketState",void 0,t)}getPoolConfig(t){return this.contract.read("getPoolConfig",void 0,t)}getPoolInfo(t){return this.contract.read("getPoolInfo",void 0,t)}async getFixedApr(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return m.spotRate({poolConfig:e,poolInfo:r})}async getImpliedRate({bondAmount:t,timestamp:e,variableApy:r,options:i}){let n=await this.getPoolConfig(i),a=await this.getPoolInfo(i),{vaultSharePrice:s}=await this.getCheckpoint({timestamp:e});return s||(s=(await this.getPoolInfo()).vaultSharePrice),m.calcImpliedRate({poolInfo:a,poolConfig:n,bondAmount:t,openVaultSharePrice:s,variableApy:r})}async getIdleLiquidity(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return m.idleShareReservesInBase({poolInfo:r,poolConfig:e})}async getPresentValue(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t),i=m.presentValue({poolInfo:r,poolConfig:e,currentTime:BigInt(Date.now())/1000n});return this.convertToBase({sharesAmount:i,options:t})}async getShortAccruedYield({checkpointTime:t,bondAmount:e,options:r}){let{vaultSharePrice:i}=await this.getCheckpoint({checkpointTime:t,options:r}),{positionDuration:n}=await this.getPoolConfig(r),a=t+n,c=await this.getCheckpointTime({options:r})>=a,d;if(c)d=(await this.getCheckpoint({checkpointTime:a,options:r})).vaultSharePrice;else{let p=await this.getPoolInfo(r);d=p.vaultSharePrice,i!=0n||(i=p.vaultSharePrice)}return Pt({openVaultSharePrice:i,endingVaultSharePrice:d,bondAmount:e,decimals:await this.getDecimals()})}async getTradingVolume(t){let{fromBlock:e,toBlock:r}=t||{},i=await this.getLongEvents({fromBlock:e,toBlock:r}),n=await this.getShortEvents({fromBlock:e,toBlock:r}),a=i.reduce((c,{bondAmount:d})=>c+d,0n),s=n.reduce((c,{bondAmount:d})=>c+d,0n);return{longVolume:a,shortVolume:s,totalVolume:a+s}}async getLongPrice(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return m.spotPrice({poolConfig:e,poolInfo:r})}async getLongEvents(t){let e=await this.contract.getEvents("OpenLong",t),r=await this.contract.getEvents("CloseLong",t);return[...e,...r].map(({args:i,eventName:n,blockNumber:a,transactionHash:s})=>{let c=i.asBase?i.amount:(0,g.fixed)(i.amount).mul(i.vaultSharePrice).bigint;return{trader:i.trader,assetId:i.assetId,bondAmount:i.bondAmount,baseAmount:c,eventName:n,blockNumber:a,transactionHash:s}}).sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber))}async getShortEvents(t){let e=await this.contract.getEvents("OpenShort",t),r=await this.contract.getEvents("CloseShort",t);return[...e,...r].map(({args:i,eventName:n,blockNumber:a,transactionHash:s})=>{let c=i.asBase?i.amount:(0,g.fixed)(i.amount).mul(i.vaultSharePrice).bigint;return{trader:i.trader,assetId:i.assetId,bondAmount:i.bondAmount,baseAmount:c,eventName:n,blockNumber:a,transactionHash:s}}).sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber))}async getLpEvents(t){let e=await this.contract.getEvents("AddLiquidity",t),r=await this.contract.getEvents("RemoveLiquidity",t),i=await this.contract.getEvents("RedeemWithdrawalShares",t);return{addLiquidity:e,removeLiquidity:r,redeemWithdrawalShares:i}}async getLpApy({fromBlock:t,options:e}){let{number:r}=await this.getInitializationBlock();r&&r>t&&(t=r);let i=await this.drift.getBlock(e?.block,{throws:!0}),n=await this.drift.getBlock(t,{throws:!0}),{lpSharePrice:a}=await this.getPoolInfo({block:t}),{lpSharePrice:s}=await this.getPoolInfo(),c=i.timestamp-n.timestamp;return{lpApy:St({startPrice:a,endPrice:s,timeFrame:c})}}async getCheckpointEvents(t){return await this.contract.getEvents("CreateCheckpoint",t)}_calcOpenLongs({openLongEvents:t,closeLongEvents:e}){let r=[...t,...e].sort((n,a)=>Number(n.blockNumber)-Number(a.blockNumber)),i={};return r.forEach(n=>{let a=n.args.assetId.toString(),s=i[a]||{assetId:n.args.assetId,maturity:n.args.maturityTime,baseAmountPaid:0n,bondAmount:0n},c=n.args.asBase?n.args.amount:(0,g.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;switch(n.eventName){case"OpenLong":i[a]={...s,baseAmountPaid:s.baseAmountPaid+c,bondAmount:s.bondAmount+n.args.bondAmount};return;case"CloseLong":n.args.bondAmount===s.bondAmount?delete i[a]:i[a]={...s,baseAmountPaid:s.baseAmountPaid-c,bondAmount:s.bondAmount-n.args.bondAmount};return;default:$(n,!0)}}),Object.values(i).filter(n=>n.bondAmount)}async getOpenLongPositions({account:t,options:e}){let r=await this.contract.getEvents("TransferSingle",{filter:{to:t},...e}),i=await this.contract.getEvents("TransferSingle",{filter:{from:t},...e}),n=r.filter(Et),a=i.filter(Et),s=[...n,...a].sort((d,p)=>Number(d.blockNumber)-Number(p.blockNumber)),c={};for(let d of s){let p=c[d.args.id.toString()]??{assetId:d.args.id,maturity:rt(d.data).timestamp,value:0n};if(d.args.to===t)p.value+=d.args.value;else if(d.args.from===t&&(p.value-=d.args.value,p.value===0n)){delete c[d.args.id.toString()];continue}c[d.args.id.toString()]=p}return Object.values(c).filter(d=>d.value)}async getOpenLongDetails({assetId:t,account:e,options:r}){if(!(await this.getOpenLongPositions({account:e,options:r})).find(d=>d.assetId===t))throw new y(`No position with asset id: ${t} found for account ${e}`);let a=await this.contract.getEvents("OpenLong",{filter:{trader:e,assetId:t},...r}),s=await this.contract.getEvents("CloseLong",{filter:{trader:e,assetId:t},...r});if(this.zapContractAddress){let d=await this.contract.getEvents("TransferSingle",{filter:{from:e,to:this.zapContractAddress},...r});if(d.length){let p=d.map(({transactionHash:h})=>h),l=(await this.contract.getEvents("CloseLong",{filter:{trader:this.zapContractAddress,assetId:t},fromBlock:d[0].blockNumber,toBlock:d.at(-1)?.blockNumber})).filter(({transactionHash:h})=>p.includes(h));for(let h of l)s.push(h)}}return this._calcOpenLongs({openLongEvents:a,closeLongEvents:s})[0]}async getOpenLongs({account:t,options:e}){let r=await this.contract.getEvents("OpenLong",{filter:{trader:t},...e}),i=await this.contract.getEvents("CloseLong",{filter:{trader:t},...e});return this._calcOpenLongs({openLongEvents:r,closeLongEvents:i})}async getOpenShorts({account:t,options:e}){let{checkpointDuration:r,positionDuration:i}=await this.getPoolConfig({block:e?.toBlock}),n=await this.contract.getEvents("OpenShort",{filter:{trader:t},...e}),a=await this.contract.getEvents("CloseShort",{filter:{trader:t},...e});return this._calcOpenShorts({hyperdriveAddress:this.address,checkpointDuration:r,positionDuration:i,openShortEvents:n,closeShortEvents:a})}async _calcOpenShorts({hyperdriveAddress:t,checkpointDuration:e,positionDuration:r,closeShortEvents:i,openShortEvents:n}){let a=[...n,...i].sort((c,d)=>Number(c.blockNumber)-Number(d.blockNumber)),s={};for(let c of a){let d=c.args.assetId.toString(),{timestamp:p}=await this.drift.getBlock(c.blockNumber,{throws:!0});s[d]=s[d]||{hyperdriveAddress:t,assetId:c.args.assetId,maturity:c.args.maturityTime,checkpointTime:N(p,e),openedTimestamp:p,baseAmountPaid:0n,bondAmount:0n,baseProceeds:0n,fixedRatePaid:0n};let u=c.args.asBase?c.args.amount:(0,g.fixed)(c.args.amount).mul(c.args.vaultSharePrice).bigint,{eventName:l}=c;switch(l){case"OpenShort":s[d].baseAmountPaid+=u,s[d].bondAmount+=c.args.bondAmount,s[d].baseProceeds+=c.args.baseProceeds,s[d].fixedRatePaid=D({positionDuration:r,baseAmount:s[d].baseProceeds,bondAmount:s[d].bondAmount});continue;case"CloseShort":{if(c.args.bondAmount===s[d].bondAmount){delete s[d];continue}s[d].baseAmountPaid-=u,s[d].bondAmount-=c.args.bondAmount,s[d].baseProceeds-=c.args.basePayment,s[d].fixedRatePaid=D({positionDuration:r,baseAmount:s[d].baseProceeds,bondAmount:s[d].bondAmount});continue}default:$(l,!0)}}return Object.values(s).filter(c=>c.bondAmount)}async getClosedLongs({account:t,options:e}){let r=await this.contract.getEvents("CloseLong",{filter:{trader:t},...e});return(await Promise.all(r.map(async n=>{let a=n.args.assetId,s=n.args.asBase?n.args.amount:(0,g.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;return{assetId:a,bondAmount:n.args.bondAmount,baseAmount:s,maturity:n.args.maturityTime,closedTimestamp:(await this.drift.getBlock(n.blockNumber,{throws:!0})).timestamp}}))).filter(n=>n.bondAmount)}async getClosedShorts({account:t,options:e}){let r=await this.contract.getEvents("CloseShort",{filter:{trader:t},...e}),{checkpointDuration:i}=await this.getPoolConfig({block:e?.toBlock});return(await Promise.all(r.map(async a=>{let{assetId:s,maturityTime:c}=a.args,{timestamp:d}=await this.drift.getBlock(a.blockNumber,{throws:!0}),p=a.args.asBase?a.args.amount:(0,g.fixed)(a.args.amount).mul(a.args.vaultSharePrice).bigint;return{hyperdriveAddress:this.address,assetId:s,bondAmount:a.args.bondAmount,baseAmountReceived:p,maturity:c,closedTimestamp:d,checkpointTime:N(d,i)}}))).filter(a=>a.bondAmount)}async getMaxShort({budget:t,options:e}){let r=await this.getPoolInfo(e),i=await this.getPoolConfig(e),n=await this.getCheckpointExposure({options:e}),{vaultSharePrice:a}=await this.getCheckpoint({options:e}),s=m.maxShort({budget:t,poolInfo:r,poolConfig:i,maxIterations:14,openVaultSharePrice:a,checkpointExposure:n}),c=m.calcOpenShort({poolInfo:r,poolConfig:i,bondAmount:s,openVaultSharePrice:a}),d=await this.convertToShares({baseAmount:c,options:e});return{maxBaseIn:c,maxSharesIn:d,maxBondsOut:s}}async getMaxLong(t){let e=await this.getPoolInfo(t),r=await this.getPoolConfig(t),i=await this.getCheckpointExposure({options:t}),n=m.maxLong({poolInfo:e,poolConfig:r,budget:bt,checkpointExposure:i}),a=await this.convertToShares({baseAmount:n,options:t}),s=m.calcOpenLong({poolInfo:e,poolConfig:r,baseAmount:n});return{maxBaseIn:n,maxSharesIn:a,maxBondsOut:s}}getLpSharesTotalSupply(t){return this.contract.read("totalSupply",{tokenId:it},t?.options)}getLpShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:it,owner:t},e)}async getOpenLpPosition({account:t,asBase:e,options:r}){let i=await this.contract.getEvents("AddLiquidity",{filter:{provider:t},...r}),n=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},...r}),a=await this.getDecimals(),{lpShareBalance:s,baseAmountPaid:c}=this._calcOpenLpPosition({addLiquidityEvents:i,removeLiquidityEvents:n});if(!s)return{lpShareBalance:s,baseAmountPaid:c,baseValue:0n,sharesValue:0n};let{proceeds:d,withdrawalShares:p}=await this.previewRemoveLiquidity({lpSharesIn:s,minOutputPerShare:1n,asBase:e,destination:t}),u=e?d:await this.convertToBase({sharesAmount:d}),{lpSharePrice:l}=await this.getPoolInfo(),h=(0,g.fixed)(l,a).mul(p,a).bigint,R=await this.convertToShares({baseAmount:h});return{lpShareBalance:s,baseAmountPaid:c,baseValue:u+h,sharesValue:d+R}}_calcOpenLpPosition({addLiquidityEvents:t,removeLiquidityEvents:e}){let r=[...t,...e].sort((a,s)=>Number(a.blockNumber)-Number(s.blockNumber)),i=0n,n=0n;return r.forEach(a=>{let s=a.args.asBase?a.args.amount:(0,g.fixed)(a.args.amount).mul(a.args.vaultSharePrice).bigint;switch(a.eventName){case"AddLiquidity":n+=a.args.lpAmount,i+=s;return;case"RemoveLiquidity":{if(n-=a.args.lpAmount,n<=0n)i=0n;else{let c=(0,g.fixed)(a.args.withdrawalShareAmount).mul(a.args.lpSharePrice).bigint;i=i-s-c}return}default:$(a,!0)}}),{lpShareBalance:n,baseAmountPaid:i}}async getClosedLpShares({account:t,options:e}){let r=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},...e});return Promise.all(r.map(async({blockNumber:i,args:n})=>{let{lpAmount:a,withdrawalShareAmount:s,asBase:c,amount:d,lpSharePrice:p}=n,u=c?d:(0,g.fixed)(n.amount).mul(n.vaultSharePrice).bigint;return{lpAmount:a,baseAmount:u,withdrawalShareAmount:s,lpSharePrice:p,closedTimestamp:(await this.drift.getBlock(i,{throws:!0})).timestamp}}))}getWithdrawalShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:xt,owner:t},e)}async getRedeemedWithdrawalShares({account:t,options:e}){let r=await this.contract.getEvents("RedeemWithdrawalShares",{filter:{provider:t},...e});return Promise.all(r.map(async({blockNumber:i,args:n})=>{let{withdrawalShareAmount:a,amount:s,asBase:c,vaultSharePrice:d}=n,p=c?n.amount:(0,g.fixed)(s).mul(d).bigint;return{hyperdriveAddress:this.address,withdrawalShareAmount:a,baseAmount:p,redeemedTimestamp:(await this.drift.getBlock(i,{throws:!0})).timestamp}}))}async previewOpenLong({amountIn:t,asBase:e,options:r}){let i=await this.getPoolConfig(r),n=await this.getPoolInfo(r),a=await this.getCheckpointTime({options:r}),s=t;e||(s=await this.convertToBase({sharesAmount:t,options:r}));let c=m.spotPriceAfterLong({poolInfo:n,poolConfig:i,baseAmount:s}),d=m.calcAprGivenFixedPrice({price:c,positionDuration:i.positionDuration}),p=m.calcOpenLong({poolInfo:n,poolConfig:i,baseAmount:s}),u=m.openLongCurveFee({poolInfo:n,poolConfig:i,baseAmount:s});return{maturityTime:a+i.positionDuration,bondProceeds:p,spotPriceAfterOpen:c,spotRateAfterOpen:d,curveFee:u}}async previewOpenShort({amountOfBondsToShort:t,asBase:e,options:r}){let i=await this.getPoolConfig(r),n=await this.getPoolInfo(r),a=await this.getCheckpoint({options:r}),s=await this.getShortAccruedYield({checkpointTime:a.checkpointTime,bondAmount:t,options:r}),c=m.calcOpenShort({poolInfo:n,poolConfig:i,bondAmount:t,openVaultSharePrice:a.vaultSharePrice}),d=(0,g.fixed)(i.positionDuration).div(et),p=(0,g.fixed)(c).sub(s),u=(0,g.fixed)(t).sub(p),l=p.div(u).div(d).bigint,h=m.spotPriceAfterShort({poolInfo:n,poolConfig:i,bondAmount:t}),R=m.calcAprGivenFixedPrice({price:h,positionDuration:i.positionDuration}),B=m.openShortCurveFee({poolInfo:n,poolConfig:i,bondAmount:t});return e?{maturityTime:a.checkpointTime+i.positionDuration,traderDeposit:c,spotPriceAfterOpen:h,spotRateAfterOpen:R,curveFee:B,fixedRatePaid:l}:{maturityTime:a.checkpointTime+i.positionDuration,traderDeposit:await this.convertToShares({baseAmount:c,options:r}),spotPriceAfterOpen:h,spotRateAfterOpen:R,curveFee:await this.convertToShares({baseAmount:B,options:r}),fixedRatePaid:l}}async getShortBondsGivenDeposit({amountIn:t,asBase:e,tolerance:r,options:i}){let n=await this.getPoolConfig(i),a=await this.getPoolInfo(i),s=await this.getCheckpoint({options:i}),c=await this.getCheckpointExposure({options:i}),d=t;e||(d=await this.convertToBase({sharesAmount:t,options:i}));let p=m.absoluteMaxShort({poolInfo:a,poolConfig:n,checkpointExposure:c});return m.shortBondsGivenDeposit({poolInfo:a,poolConfig:n,targetBaseAmount:d,absoluteMaxBondAmount:p,openVaultSharePrice:s.vaultSharePrice,maybeTolerance:r})}async previewCloseLong({maturityTime:t,bondAmountIn:e,asBase:r,options:i}){let n=await this.getPoolConfig(i),a=await this.getPoolInfo(i),s=BigInt(Math.floor(Date.now()/1e3)),c=m.closeLongFlatFee({poolInfo:a,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:s}),d=m.closeLongCurveFee({poolInfo:a,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:s}),p=c+d,u=m.calcCloseLong({poolInfo:a,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:s});return r?{amountOut:await this.convertToBase({sharesAmount:u,options:i}),flatPlusCurveFee:await this.convertToBase({sharesAmount:p,options:i})}:{amountOut:u,flatPlusCurveFee:p}}async estimateShortMarketValue({maturityTime:t,asBase:e,shortAmountIn:r,options:i}){let n=await this.getPoolConfig(i),a=await this.getPoolInfo(i),s=t-n.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:s,options:i}),d=BigInt(Math.floor(Date.now()/1e3)),p=a.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:i})).vaultSharePrice);let u=m.calcShortMarketValue({poolInfo:a,poolConfig:n,bondAmount:r,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return e?this.convertToBase({sharesAmount:u,options:i}):u}async previewCloseShort({maturityTime:t,shortAmountIn:e,asBase:r,options:i}){let n=await this.getPoolConfig(i),a=await this.getPoolInfo(i),s=t-n.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:s,options:i}),d=BigInt(Math.floor(Date.now()/1e3)),p=a.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:i})).vaultSharePrice);let u=m.closeShortFlatFee({poolInfo:a,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:d}),l=m.closeShortCurveFee({poolInfo:a,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:d}),h=u+l,R=m.calcCloseShort({poolInfo:a,poolConfig:n,bondAmount:e,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return r?{amountOut:await this.convertToBase({sharesAmount:R,options:i}),flatPlusCurveFee:await this.convertToBase({sharesAmount:h,options:i})}:{amountOut:R,flatPlusCurveFee:h}}async previewAddLiquidity({contribution:t,minApr:e,minLpSharePrice:r,maxApr:i,asBase:n,options:a}){let s=await this.getPoolConfig(a),c=await this.getPoolInfo(a),d=BigInt(Math.floor(Date.now()/1e3)),p=m.calcAddLiquidity({poolInfo:c,poolConfig:s,currentTime:d,contribution:t,asBase:n,minLpSharePrice:r,minApr:e,maxApr:i}),u=await this.getDecimals(),l=(0,g.fixed)(p,u).mul(c.lpSharePrice,u).bigint,h=n?l:await this.convertToShares({baseAmount:l,options:a});return{lpSharesOut:p,slippagePaid:t-h}}async previewRemoveLiquidity({lpSharesIn:t,minOutputPerShare:e,destination:r,asBase:i,extraData:n=A,options:a}){let{proceeds:s,withdrawalShares:c}=await this.contract.simulateWrite("removeLiquidity",{_lpShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},{...a,from:r});return{proceeds:s,withdrawalShares:c}}async previewRedeemWithdrawalShares({withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:i,extraData:n=A,options:a}){let{proceeds:s,withdrawalSharesRedeemed:c}=await this.contract.simulateWrite("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},a);return{asBase:i,baseProceeds:i?s:await this.convertToBase({sharesAmount:s}),sharesProceeds:i?await this.convertToShares({baseAmount:s}):s,withdrawalSharesRedeemed:c}}};function St({startPrice:o,endPrice:t,timeFrame:e}){let r=(0,g.fixed)(t).div(o),i=(0,g.fixed)(e).div(et);return r.pow((0,g.fixed)(1e18).div(i)).sub(1e18).bigint}function Et(o){let{assetType:t}=rt(o.data);return t==="LONG"}var T=class extends O{constructor(t){super(t)}async approve({spender:t,amount:e,options:r}){return await this.contract.write("approve",{spender:t,amount:e},{...r,onMined:n=>{this.contract.cache.invalidateReadsMatching("allowance"),r?.onMined?.(n)}})}};var I=class extends S{constructor(t){super(t)}async approve(){throw new y("This method is not available for the native ETH token.")}};var w=class extends b{constructor(t){super(t)}async getBaseToken(t){let e=await this.contract.read("baseToken",{},t);return e===I.address?new I({drift:this.drift}):new T({address:e,drift:this.drift})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new T({address:t,drift:this.drift})}async checkpoint({args:{time:t},options:e}){return this.contract.write("checkpoint",{_checkpointTime:BigInt(t),_maxIterations:4n},{...e,onMined:r=>{this.contract.cache.clear(),e?.onMined?.(r)}})}async pause({args:{paused:t},options:e}){return this.contract.write("pause",{_status:t},{...e,onMined:r=>{this.contract.cache.invalidateReadsMatching("getMarketState"),e?.onMined?.(r)}})}async initialize({args:{contribution:t,apr:e,destination:r,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("initialize",{_apr:e,_contribution:t,_options:{destination:r,asBase:i,extraData:n}},{...a,onMined:s=>{this.contract.cache.clear(),a?.onMined?.(s)}})}async openLong({args:{destination:t,amount:e,minBondsOut:r,minVaultSharePrice:i,asBase:n=!0,extraData:a=A},options:s}){return this.contract.write("openLong",{_amount:e,_minOutput:r,_minVaultSharePrice:i,_options:{destination:t,asBase:n,extraData:a}},{...s,onMined:c=>{this.contract.cache.clear(),s?.onMined?.(c)}})}async openShort({args:{destination:t,bondAmount:e,minVaultSharePrice:r,maxDeposit:i,asBase:n=!0,extraData:a=A},options:s}){return this.contract.write("openShort",{_bondAmount:e,_maxDeposit:i,_minVaultSharePrice:r,_options:{destination:t,asBase:n,extraData:a}},{...s,onMined:c=>{this.contract.cache.clear(),s?.onMined?.(c)}})}async closeLong({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:i,asBase:n=!0,extraData:a=A},options:s}){return this.contract.write("closeLong",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:i,asBase:n,extraData:a}},{...s,onMined:c=>{this.contract.cache.clear(),s?.onMined?.(c)}})}async closeShort({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:i,asBase:n=!0,extraData:a=A},options:s}){return this.contract.write("closeShort",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:i,asBase:n,extraData:a}},{...s,onMined:c=>{this.contract.cache.clear(),s?.onMined?.(c)}})}async addLiquidity({args:{destination:t,contribution:e,minApr:r,minLpSharePrice:i,maxApr:n,asBase:a=!0,extraData:s=A},options:c}){return this.contract.write("addLiquidity",{_contribution:e,_minLpSharePrice:i,_minApr:r,_maxApr:n,_options:{destination:t,asBase:a,extraData:s}},{...c,onMined:d=>{this.contract.cache.clear(),c?.onMined?.(d)}})}async removeLiquidity({args:{destination:t,lpSharesIn:e,minOutputPerShare:r,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("removeLiquidity",{_lpShares:e,_minOutputPerShare:r,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:s=>{this.contract.cache.clear(),a?.onMined?.(s)}})}async redeemWithdrawalShares({args:{withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:i=!0,extraData:n=A},options:a}){return this.contract.write("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},{...a,onMined:s=>{this.contract.cache.clear(),a?.onMined?.(s)}})}};var nt=require("@delvtech/fixed-point-wasm");var G=class extends ot(b){};function ot(o){return class extends o{constructor(...[t]){let{debugName:e="Hyperdrive v1.0.14",...r}=t;super({debugName:e,...r})}async convertToBase({sharesAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),i=await this.getDecimals();return(0,nt.fixed)(t,i).mul(r,i).bigint}async convertToShares({baseAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),i=await this.getDecimals();return(0,nt.fixed)(t,i).div(r).bigint}}}var q=class extends ot(w){};async function Tt(o){let{address:t,drift:e}=o,r=ee(o),i=await e.read({abi:L,address:t,fn:"version"});return Ct.default.lte(i,"1.0.14")?r?new q(o):new G(o):r?new w(o):new b(o)}function ee(o){return o.drift.isReadWrite()}var It=require("@delvtech/fixed-point-wasm");function kt({flatFee:o,bondAmount:t,baseAmountPaid:e,decimals:r}){let i=(0,It.fixed)(t,r).mul(o,18).bigint;return t-e-i}var _t=require("@delvtech/hyperdrive-artifacts/IHyperdriveRegistry"),z=_t.IHyperdriveRegistry.abi;var Lt=require("@delvtech/hyperdrive-artifacts/IHyperdriveFactory"),Y=Lt.IHyperdriveFactory.abi;var P=class extends f{address;contract;constructor({debugName:t="Hyperdrive Factory",address:e,epochBlock:r,...i}){super({debugName:t,epochBlock:r,...i}),this.address=e,this.contract=this.drift.contract({abi:Y,address:e,epochBlock:r})}async getIsInstance(t){return this.contract.read("isInstance",{_instance:t})}async getIsDeployerCoordinator(t){return this.contract.read("isDeployerCoordinator",{_deployerCoordinator:t})}async getDeployerCoordinatorAddresses({instances:t,options:e}={}){if(t)return(await this.contract.read("getDeployerCoordinatorByInstances",{__instances:t})).slice();let r=await this.contract.read("getNumberOfDeployerCoordinators",{},e);return r===0n?[]:(await this.contract.read("getDeployerCoordinatorsInRange",{_startIndex:0n,_endIndex:r},e)).slice()}async getInstances(t){return(await this.getInstanceAddresses(t)).map(r=>new b({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstanceAddresses(t){let e=await this.contract.read("getNumberOfInstances",{},t);return e===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:e},t)).slice()}};var W=class extends f{address;contract;constructor({debugName:t="Hyperdrive Registry",address:e,epochBlock:r,...i}){super({debugName:t,...i}),this.address=e,this.contract=this.drift.contract({abi:z,address:e,epochBlock:r})}async getFactories(t){return(await this.getFactoryAddresses(t)).map(r=>new P({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getFactoryAddresses(t){let e=await this.contract.read("getNumberOfFactories",{},t);return e===0n?[]:(await this.contract.read("getFactoriesInRange",{_startIndex:0n,_endIndex:e},t)).slice()}async getFactoryInfo(t,e){return this.contract.read("getFactoryInfoWithMetadata",{_factory:t},e)}async getFactoryInfos(t,e){return(await this.contract.read("getFactoryInfosWithMetadata",{__factories:t},e)).slice()}async getInstances(t){return(await this.getInstanceAddresses(t)).map(r=>new b({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstanceAddresses(t){let e=await this.contract.read("getNumberOfInstances",{},t);return e===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:e},t)).slice()}async getInstanceInfo(t,e){let{factory:r,...i}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:t},e);return{factory:new P({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}),...i}}async getInstanceInfos(t,e){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:t},e)).map(({factory:i,...n})=>({factory:new P({address:i,drift:this.drift,epochBlock:this.contract.epochBlock}),...n}))}};var E=class extends P{constructor(t){super(t)}async getInstances(t){return(await this.getInstanceAddresses(t)).map(r=>new w({address:r,drift:this.drift}))}};var U=class extends W{constructor(t){super(t)}async getFactories(t){return(await this.getFactoryAddresses(t)).map(r=>new E({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstances(t){let e=await this.contract.read("getNumberOfInstances",{},t);return e===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:e},t)).map(i=>new w({address:i,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstanceInfo(t,e){let{factory:r,...i}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:t},e);return{factory:new E({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}),...i}}async getInstanceInfos(t,e){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:t},e)).map(({factory:i,...n})=>({factory:new E({address:i,drift:this.drift,epochBlock:this.contract.epochBlock}),...n}))}};var Wt=require("@delvtech/hyperdrive-artifacts/UniV3Zap"),Bt=Wt.UniV3Zap.abi;var Dt=[{type:"constructor",inputs:[{name:"initialOwner",type:"address",internalType:"address"},{name:"initialTimelock",type:"uint256",internalType:"uint256"},{name:"initialRoot",type:"bytes32",internalType:"bytes32"},{name:"initialIpfsHash",type:"bytes32",internalType:"bytes32"}],stateMutability:"nonpayable"},{type:"function",name:"acceptRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"batchClaim",inputs:[{name:"_accounts",type:"address[]",internalType:"address[]"},{name:"_rewards",type:"address[]",internalType:"address[]"},{name:"_claimable",type:"uint256[]",internalType:"uint256[]"},{name:"_proofs",type:"bytes32[][]",internalType:"bytes32[][]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"},{name:"claimable",type:"uint256",internalType:"uint256"},{name:"proof",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"claimed",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"ipfsHash",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"isUpdater",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"pendingRoot",inputs:[],outputs:[{name:"root",type:"bytes32",internalType:"bytes32"},{name:"ipfsHash",type:"bytes32",internalType:"bytes32"},{name:"validAt",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"revokePendingRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"root",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"setOwner",inputs:[{name:"newOwner",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRootUpdater",inputs:[{name:"updater",type:"address",internalType:"address"},{name:"active",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setTimelock",inputs:[{name:"newTimelock",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"submitRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"timelock",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"error",name:"ArrayEndIndexLessThanStartIndex",inputs:[]},{type:"error",name:"ArrayIndexOutOfBounds",inputs:[]},{type:"error",name:"IncorrectLength",inputs:[]}];var Z=class extends f{constructor(t){super(t)}};var Ht=require("@delvtech/fixed-point-wasm");function Mt({amount:o,percentage:t,decimals:e,direction:r}){let i=(0,Ht.fixed)(o,e).mul(t,e).div(100,0);return r==="down"?o-i.bigint:o+i.bigint}function Ft(o,t){return m.calcHprGivenApr({apr:o,positionDuration:t})}function $t(o,t){return m.calcHprGivenApy({apy:o,positionDuration:t})}0&&(module.exports={HyperdriveSdkError,ReadClient,ReadErc20,ReadEth,ReadFactory,ReadHyperdrive,ReadRegistry,ReadWriteClient,ReadWriteErc20,ReadWriteEth,ReadWriteFactory,ReadWriteHyperdrive,ReadWriteRegistry,adjustAmountByPercentage,calculateAprFromPrice,calculateMatureLongYieldAfterFees,erc20Abi,factoryAbi,getHprFromApr,getHprFromApy,getHyperdrive,hyperdriveAbi,hyperdriveRewardsAbi,registryAbi,zapAbi});
//# sourceMappingURL=index.cjs.map
+1
-1

@@ -1,2 +0,2 @@

import{A as U,B as Z,D as V,E as G,G as Y,H as q,J,K,M as Q,O as X,P as $,Q as ee,S as te,T as re,V as ae,W as ne,X as ie,Z as oe,_ as se,a as E,b as R,c as T,d as p,e as h,f as F,g as _,h as M,i as d,j as P,k as S,l as c,m as k,n as N,o as l,p as D,q as b,r as O,s as I,t as W,u as w,v as L,w as z,x as B,y as j}from"./chunk-HKUPLPJB.js";import pe from"semver";async function de({address:n,drift:e,cache:t=e.cache,cacheNamespace:r,earliestBlock:a,debugName:i,zapContractAddress:C}){r??=await e.getChainId();let o={address:n,drift:e,cache:t,cacheNamespace:r,earliestBlock:a,debugName:i,zapContractAddress:C},u=ce(o),H=await e.read({abi:R,address:n,fn:"version",cacheNamespace:r}),m=pe.lte(H,"1.0.14");switch(m?void 0:await e.read({abi:R,address:n,fn:"kind",cacheNamespace:r})){case"StETHHyperdrive":return u&&m?new w(o):u?new b(o):m?new I(o):new l(o);default:return u&&m?new W(o):u?new c(o):m?new O(o):new d(o)}}function ce(n){return typeof n.drift.write=="function"}import{fixed as ye}from"@delvtech/fixed-point-wasm";function me({flatFee:n,bondAmount:e,baseAmountPaid:t,decimals:r}){let a=ye(e,r).mul(n).bigint;return e-t-a}import{IHyperdriveRegistry as fe}from"@delvtech/hyperdrive-artifacts/IHyperdriveRegistry";var A=fe.abi;import{IHyperdriveFactory as ue}from"@delvtech/hyperdrive-artifacts/IHyperdriveFactory";var x=ue.abi;var s=class extends p{address;contract;constructor({debugName:e="Hyperdrive Factory",address:t,cache:r,cacheNamespace:a,...i}){super({debugName:e,...i}),this.address=t,this.contract=this.drift.contract({abi:x,address:t,cache:r,cacheNamespace:a})}async getIsInstance(e){return this.contract.read("isInstance",{_instance:e})}async getIsDeployerCoordinator(e){return this.contract.read("isDeployerCoordinator",{_deployerCoordinator:e})}async getDeployerCoordinatorAddresses({instances:e,options:t}={}){if(e)return(await this.contract.read("getDeployerCoordinatorByInstances",{__instances:e})).slice();let r=await this.contract.read("getNumberOfDeployerCoordinators",{},t);return r===0n?[]:(await this.contract.read("getDeployerCoordinatorsInRange",{_startIndex:0n,_endIndex:r},t)).slice()}async getInstances(e){return(await this.getInstanceAddresses(e)).map(r=>new d({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstanceAddresses(e){let t=await this.contract.read("getNumberOfInstances",{},e);return t===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:t},e)).slice()}};var f=class extends p{address;contract;constructor({debugName:e="Hyperdrive Registry",address:t,cache:r,cacheNamespace:a,...i}){super({debugName:e,...i}),this.address=t,this.contract=this.drift.contract({abi:A,address:t,cache:r,cacheNamespace:a})}async getFactories(e){return(await this.getFactoryAddresses(e)).map(r=>new s({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getFactoryAddresses(e){let t=await this.contract.read("getNumberOfFactories",{},e);return t===0n?[]:(await this.contract.read("getFactoriesInRange",{_startIndex:0n,_endIndex:t},e)).slice()}async getFactoryInfo(e,t){return this.contract.read("getFactoryInfoWithMetadata",{_factory:e},t)}async getFactoryInfos(e,t){return(await this.contract.read("getFactoryInfosWithMetadata",{__factories:e},t)).slice()}async getInstances(e){return(await this.getInstanceAddresses(e)).map(r=>new d({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstanceAddresses(e){let t=await this.contract.read("getNumberOfInstances",{},e);return t===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:t},e)).slice()}async getInstanceInfo(e,t){let{factory:r,...a}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:e},t);return{factory:new s({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...a}}async getInstanceInfos(e,t){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:e},t)).map(({factory:a,...i})=>({factory:new s({address:a,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...i}))}};var y=class extends s{constructor(e){super(e)}async getInstances(e){return(await this.getInstanceAddresses(e)).map(r=>new c({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}};var g=class extends f{constructor(e){super(e)}async getFactories(e){return(await this.getFactoryAddresses(e)).map(r=>new y({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstances(e){let t=await this.contract.read("getNumberOfInstances",{},e);return t===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:t},e)).map(a=>new c({address:a,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}))}async getInstanceInfo(e,t){let{factory:r,...a}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:e},t);return{factory:new y({address:r,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...a}}async getInstanceInfos(e,t){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:e},t)).map(({factory:a,...i})=>({factory:new y({address:a,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace}),...i}))}};import{UniV3Zap as Re}from"@delvtech/hyperdrive-artifacts/UniV3Zap";var he=Re.abi;var le=[{type:"constructor",inputs:[{name:"initialOwner",type:"address",internalType:"address"},{name:"initialTimelock",type:"uint256",internalType:"uint256"},{name:"initialRoot",type:"bytes32",internalType:"bytes32"},{name:"initialIpfsHash",type:"bytes32",internalType:"bytes32"}],stateMutability:"nonpayable"},{type:"function",name:"acceptRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"batchClaim",inputs:[{name:"_accounts",type:"address[]",internalType:"address[]"},{name:"_rewards",type:"address[]",internalType:"address[]"},{name:"_claimable",type:"uint256[]",internalType:"uint256[]"},{name:"_proofs",type:"bytes32[][]",internalType:"bytes32[][]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"},{name:"claimable",type:"uint256",internalType:"uint256"},{name:"proof",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"claimed",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"ipfsHash",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"isUpdater",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"pendingRoot",inputs:[],outputs:[{name:"root",type:"bytes32",internalType:"bytes32"},{name:"ipfsHash",type:"bytes32",internalType:"bytes32"},{name:"validAt",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"revokePendingRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"root",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"setOwner",inputs:[{name:"newOwner",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRootUpdater",inputs:[{name:"updater",type:"address",internalType:"address"},{name:"active",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setTimelock",inputs:[{name:"newTimelock",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"submitRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"timelock",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"error",name:"ArrayEndIndexLessThanStartIndex",inputs:[]},{type:"error",name:"ArrayIndexOutOfBounds",inputs:[]},{type:"error",name:"IncorrectLength",inputs:[]}];var v=class extends p{constructor(e){super(e)}};import{fixed as be}from"@delvtech/fixed-point-wasm";function Ae({amount:n,percentage:e,decimals:t,direction:r}){let a=be(n,t).mul(e,t).div(100,0);return r==="down"?n-a.bigint:n+a.bigint}function xe(n,e){return h.calcHprGivenApr({apr:n,positionDuration:e})}function ge(n,e){return h.calcHprGivenApy({apy:n,positionDuration:e})}export{E as HyperdriveSdkError,p as ReadClient,_ as ReadErc20,B as ReadErc4626,j as ReadErc4626Hyperdrive,M as ReadEth,K as ReadEzEthHyperdrive,s as ReadFactory,d as ReadHyperdrive,$ as ReadLsEth,ee as ReadLsEthHyperdrive,U as ReadMockErc4626,Z as ReadMockErc4626Hyperdrive,ne as ReadREth,ie as ReadREthHyperdrive,f as ReadRegistry,N as ReadStEth,l as ReadStEthHyperdrive,v as ReadWriteClient,P as ReadWriteErc20,V as ReadWriteErc4626,G as ReadWriteErc4626Hyperdrive,S as ReadWriteEth,Q as ReadWriteEzEthHyperdrive,y as ReadWriteFactory,c as ReadWriteHyperdrive,te as ReadWriteLsEth,re as ReadWriteLsEthHyperdrive,Y as ReadWriteMockErc4626,q as ReadWriteMockErc4626Hyperdrive,oe as ReadWriteREth,se as ReadWriteREthHyperdrive,g as ReadWriteRegistry,D as ReadWriteStEth,b as ReadWriteStEthHyperdrive,Ae as adjustAmountByPercentage,T as calculateAprFromPrice,me as calculateMatureLongYieldAfterFees,F as erc20Abi,L as erc4626Abi,J as ezEthHyperdriveAbi,x as factoryAbi,xe as getHprFromApr,ge as getHprFromApy,de as getHyperdrive,R as hyperdriveAbi,le as hyperdriveRewardsAbi,X as lsEthAbi,z as mockErc4626Abi,ae as rEthAbi,A as registryAbi,k as stEthAbi,he as zapAbi};
import{a as g,b as f,c as O,d as s,e as m,f as x,g as I,h as v,i as o,j as W,k as w,l as d,m as h,n as A}from"./chunk-GYQBJEPF.js";import C from"semver";async function H(n){let{address:e,drift:t}=n,r=T(n),a=await t.read({abi:f,address:e,fn:"version"});return C.lte(a,"1.0.14")?r?new A(n):new h(n):r?new d(n):new o(n)}function T(n){return n.drift.isReadWrite()}import{fixed as F}from"@delvtech/fixed-point-wasm";function _({flatFee:n,bondAmount:e,baseAmountPaid:t,decimals:r}){let a=F(e,r).mul(n,18).bigint;return e-t-a}import{IHyperdriveRegistry as M}from"@delvtech/hyperdrive-artifacts/IHyperdriveRegistry";var u=M.abi;import{IHyperdriveFactory as k}from"@delvtech/hyperdrive-artifacts/IHyperdriveFactory";var l=k.abi;var i=class extends s{address;contract;constructor({debugName:e="Hyperdrive Factory",address:t,epochBlock:r,...a}){super({debugName:e,epochBlock:r,...a}),this.address=t,this.contract=this.drift.contract({abi:l,address:t,epochBlock:r})}async getIsInstance(e){return this.contract.read("isInstance",{_instance:e})}async getIsDeployerCoordinator(e){return this.contract.read("isDeployerCoordinator",{_deployerCoordinator:e})}async getDeployerCoordinatorAddresses({instances:e,options:t}={}){if(e)return(await this.contract.read("getDeployerCoordinatorByInstances",{__instances:e})).slice();let r=await this.contract.read("getNumberOfDeployerCoordinators",{},t);return r===0n?[]:(await this.contract.read("getDeployerCoordinatorsInRange",{_startIndex:0n,_endIndex:r},t)).slice()}async getInstances(e){return(await this.getInstanceAddresses(e)).map(r=>new o({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstanceAddresses(e){let t=await this.contract.read("getNumberOfInstances",{},e);return t===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:t},e)).slice()}};var y=class extends s{address;contract;constructor({debugName:e="Hyperdrive Registry",address:t,epochBlock:r,...a}){super({debugName:e,...a}),this.address=t,this.contract=this.drift.contract({abi:u,address:t,epochBlock:r})}async getFactories(e){return(await this.getFactoryAddresses(e)).map(r=>new i({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getFactoryAddresses(e){let t=await this.contract.read("getNumberOfFactories",{},e);return t===0n?[]:(await this.contract.read("getFactoriesInRange",{_startIndex:0n,_endIndex:t},e)).slice()}async getFactoryInfo(e,t){return this.contract.read("getFactoryInfoWithMetadata",{_factory:e},t)}async getFactoryInfos(e,t){return(await this.contract.read("getFactoryInfosWithMetadata",{__factories:e},t)).slice()}async getInstances(e){return(await this.getInstanceAddresses(e)).map(r=>new o({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstanceAddresses(e){let t=await this.contract.read("getNumberOfInstances",{},e);return t===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:t},e)).slice()}async getInstanceInfo(e,t){let{factory:r,...a}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:e},t);return{factory:new i({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}),...a}}async getInstanceInfos(e,t){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:e},t)).map(({factory:a,...c})=>({factory:new i({address:a,drift:this.drift,epochBlock:this.contract.epochBlock}),...c}))}};var p=class extends i{constructor(e){super(e)}async getInstances(e){return(await this.getInstanceAddresses(e)).map(r=>new d({address:r,drift:this.drift}))}};var R=class extends y{constructor(e){super(e)}async getFactories(e){return(await this.getFactoryAddresses(e)).map(r=>new p({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstances(e){let t=await this.contract.read("getNumberOfInstances",{},e);return t===0n?[]:(await this.contract.read("getInstancesInRange",{_startIndex:0n,_endIndex:t},e)).map(a=>new d({address:a,drift:this.drift,epochBlock:this.contract.epochBlock}))}async getInstanceInfo(e,t){let{factory:r,...a}=await this.contract.read("getInstanceInfoWithMetadata",{_instance:e},t);return{factory:new p({address:r,drift:this.drift,epochBlock:this.contract.epochBlock}),...a}}async getInstanceInfos(e,t){return(await this.contract.read("getInstanceInfosWithMetadata",{__instances:e},t)).map(({factory:a,...c})=>({factory:new p({address:a,drift:this.drift,epochBlock:this.contract.epochBlock}),...c}))}};import{UniV3Zap as P}from"@delvtech/hyperdrive-artifacts/UniV3Zap";var B=P.abi;var D=[{type:"constructor",inputs:[{name:"initialOwner",type:"address",internalType:"address"},{name:"initialTimelock",type:"uint256",internalType:"uint256"},{name:"initialRoot",type:"bytes32",internalType:"bytes32"},{name:"initialIpfsHash",type:"bytes32",internalType:"bytes32"}],stateMutability:"nonpayable"},{type:"function",name:"acceptRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"batchClaim",inputs:[{name:"_accounts",type:"address[]",internalType:"address[]"},{name:"_rewards",type:"address[]",internalType:"address[]"},{name:"_claimable",type:"uint256[]",internalType:"uint256[]"},{name:"_proofs",type:"bytes32[][]",internalType:"bytes32[][]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"nonpayable"},{type:"function",name:"claim",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"},{name:"claimable",type:"uint256",internalType:"uint256"},{name:"proof",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"claimed",inputs:[{name:"account",type:"address",internalType:"address"},{name:"reward",type:"address",internalType:"address"}],outputs:[{name:"amount",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"ipfsHash",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"isUpdater",inputs:[{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"pendingRoot",inputs:[],outputs:[{name:"root",type:"bytes32",internalType:"bytes32"},{name:"ipfsHash",type:"bytes32",internalType:"bytes32"},{name:"validAt",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"revokePendingRoot",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"root",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"setOwner",inputs:[{name:"newOwner",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRootUpdater",inputs:[{name:"updater",type:"address",internalType:"address"},{name:"active",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setTimelock",inputs:[{name:"newTimelock",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"submitRoot",inputs:[{name:"newRoot",type:"bytes32",internalType:"bytes32"},{name:"newIpfsHash",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"timelock",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"error",name:"ArrayEndIndexLessThanStartIndex",inputs:[]},{type:"error",name:"ArrayIndexOutOfBounds",inputs:[]},{type:"error",name:"IncorrectLength",inputs:[]}];var b=class extends s{constructor(e){super(e)}};import{fixed as E}from"@delvtech/fixed-point-wasm";function S({amount:n,percentage:e,decimals:t,direction:r}){let a=E(n,t).mul(e,t).div(100,0);return r==="down"?n-a.bigint:n+a.bigint}function L(n,e){return m.calcHprGivenApr({apr:n,positionDuration:e})}function N(n,e){return m.calcHprGivenApy({apy:n,positionDuration:e})}export{g as HyperdriveSdkError,s as ReadClient,I as ReadErc20,v as ReadEth,i as ReadFactory,o as ReadHyperdrive,y as ReadRegistry,b as ReadWriteClient,W as ReadWriteErc20,w as ReadWriteEth,p as ReadWriteFactory,d as ReadWriteHyperdrive,R as ReadWriteRegistry,S as adjustAmountByPercentage,O as calculateAprFromPrice,_ as calculateMatureLongYieldAfterFees,x as erc20Abi,l as factoryAbi,L as getHprFromApr,N as getHprFromApy,H as getHyperdrive,f as hyperdriveAbi,D as hyperdriveRewardsAbi,u as registryAbi,B as zapAbi};
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/hyperdrive/getHyperdrive.ts","../src/hyperdrive/longs/calculateMatureLongYieldAfterFees.ts","../src/registry/abi.ts","../src/factory/abi.ts","../src/factory/ReadFactory.ts","../src/registry/ReadRegistry.ts","../src/factory/ReadWriteFactory.ts","../src/registry/ReadWriteRegistry.ts","../src/hyperdrive/zaps/abi.ts","../src/rewards/abi.ts","../src/drift/ReadWriteClient.ts","../src/base/adjustAmountByPercentage.ts","../src/base/getHprFromApr.ts","../src/base/getHprFromApy.ts"],"sourcesContent":["import { Drift, ReadWriteAdapter } from \"@delvtech/drift\";\nimport semver from \"semver\";\nimport { hyperdriveAbi } from \"src/hyperdrive/abi\";\nimport {\n ReadHyperdrive,\n ReadHyperdriveOptions,\n} from \"src/hyperdrive/ReadHyperdrive\";\nimport {\n ReadWriteHyperdrive,\n ReadWriteHyperdriveOptions,\n} from \"src/hyperdrive/ReadWriteHyperdrive\";\nimport { ReadStEthHyperdrive } from \"src/hyperdrive/steth/ReadStEthHyperdrive\";\nimport { ReadWriteStEthHyperdrive } from \"src/hyperdrive/steth/ReadWriteStEthHyperdrive\";\nimport { ReadStEthHyperdrive_v1_0_14 } from \"src/hyperdrive/steth/v1.0.14/ReadStEthHyperdrive_v1_0_14\";\nimport { ReadWriteStEthHyperdrive_v1_0_14 } from \"src/hyperdrive/steth/v1.0.14/ReadWriteStEthHyperdrive_v1_0_14\";\nimport { ReadHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadHyperdrive_v1_0_14\";\nimport { ReadWriteHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadWriteHyperdrive_v1_0_14\";\n\nexport interface HyperdriveOptions<T extends Drift = Drift>\n extends ReadHyperdriveOptions {\n drift: T;\n}\n\nexport type Hyperdrive<T extends Drift = Drift> =\n T extends Drift<ReadWriteAdapter> ? ReadWriteHyperdrive : ReadHyperdrive;\n\nexport async function getHyperdrive<T extends Drift = Drift>({\n address,\n drift,\n cache = drift.cache,\n cacheNamespace,\n earliestBlock,\n debugName,\n zapContractAddress,\n}: HyperdriveOptions<T>): Promise<Hyperdrive<T>> {\n cacheNamespace ??= await drift.getChainId();\n\n const options: HyperdriveOptions<T> = {\n address,\n drift,\n cache,\n cacheNamespace,\n earliestBlock,\n debugName,\n zapContractAddress,\n };\n const isReadWrite = isReadWriteOptions(options);\n\n const version = await drift.read({\n abi: hyperdriveAbi,\n address,\n fn: \"version\",\n cacheNamespace,\n });\n const isV1_0_14 = semver.lte(version, \"1.0.14\");\n\n const kind = isV1_0_14\n ? undefined\n : await drift.read({\n abi: hyperdriveAbi,\n address,\n fn: \"kind\",\n cacheNamespace,\n });\n\n switch (kind) {\n case \"StETHHyperdrive\":\n if (isReadWrite && isV1_0_14) {\n return new ReadWriteStEthHyperdrive_v1_0_14(options);\n }\n\n if (isReadWrite) {\n return new ReadWriteStEthHyperdrive(options);\n }\n\n if (isV1_0_14) {\n return new ReadStEthHyperdrive_v1_0_14(options) as any;\n }\n\n return new ReadStEthHyperdrive(options) as any;\n\n default:\n if (isReadWrite && isV1_0_14) {\n return new ReadWriteHyperdrive_v1_0_14(options);\n }\n\n if (isReadWrite) {\n return new ReadWriteHyperdrive(options);\n }\n\n if (isV1_0_14) {\n return new ReadHyperdrive_v1_0_14(options) as any;\n }\n\n return new ReadHyperdrive(options) as any;\n }\n}\n\nfunction isReadWriteOptions(\n options: HyperdriveOptions,\n): options is ReadWriteHyperdriveOptions {\n return typeof options.drift.write === \"function\";\n}\n","import { fixed } from \"@delvtech/fixed-point-wasm\";\n\nexport function calculateMatureLongYieldAfterFees({\n flatFee,\n bondAmount,\n baseAmountPaid,\n decimals,\n}: {\n flatFee: bigint;\n bondAmount: bigint;\n baseAmountPaid: bigint;\n decimals: number;\n}): bigint {\n // Flat fee is always 18 decimals\n const poolFee = fixed(bondAmount, decimals).mul(flatFee).bigint;\n return bondAmount - baseAmountPaid - poolFee;\n}\n","import { IHyperdriveRegistry } from \"@delvtech/hyperdrive-artifacts/IHyperdriveRegistry\";\n\nexport const registryAbi = IHyperdriveRegistry.abi;\nexport type RegistryAbi = typeof registryAbi;\n","import { IHyperdriveFactory } from \"@delvtech/hyperdrive-artifacts/IHyperdriveFactory\";\n\nexport const factoryAbi = IHyperdriveFactory.abi;\nexport type FactoryAbi = typeof factoryAbi;\n","import { Contract, ContractReadOptions } from \"@delvtech/drift\";\nimport { Address } from \"abitype\";\nimport { ReadContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadClient } from \"src/drift/ReadClient\";\nimport { FactoryAbi, factoryAbi } from \"src/factory/abi\";\nimport { ReadHyperdrive } from \"src/hyperdrive/ReadHyperdrive\";\n\nexport interface ReadFactoryOptions extends ReadContractClientOptions {}\n\nexport class ReadFactory extends ReadClient {\n address: Address;\n contract: Contract<FactoryAbi>;\n\n constructor({\n debugName = \"Hyperdrive Factory\",\n address,\n cache,\n cacheNamespace,\n ...rest\n }: ReadFactoryOptions) {\n super({ debugName, ...rest });\n this.address = address;\n this.contract = this.drift.contract({\n abi: factoryAbi,\n address,\n cache,\n cacheNamespace,\n });\n }\n\n /**\n * Find out if the given address is an instance deployed by the factory.\n */\n async getIsInstance(address: Address): Promise<boolean> {\n return this.contract.read(\"isInstance\", { _instance: address });\n }\n\n /**\n * Find out if the given address is a deployer coordinator registered with the\n * factory.\n */\n async getIsDeployerCoordinator(address: Address): Promise<boolean> {\n return this.contract.read(\"isDeployerCoordinator\", {\n _deployerCoordinator: address,\n });\n }\n\n /**\n * Get the address of all registered deployer coordinators.\n */\n async getDeployerCoordinatorAddresses({\n instances,\n options,\n }: {\n /**\n * Only return deployer coordinators that deployed the given instances.\n */\n instances?: Address[];\n options?: ContractReadOptions;\n } = {}): Promise<Address[]> {\n if (instances) {\n const readOnlyAddresses = await this.contract.read(\n \"getDeployerCoordinatorByInstances\",\n {\n __instances: instances,\n },\n );\n return readOnlyAddresses.slice();\n }\n\n const count = await this.contract.read(\n \"getNumberOfDeployerCoordinators\",\n {},\n options,\n );\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getDeployerCoordinatorsInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n\n /**\n * Get a {@linkcode ReadHyperdrive} instance for each Hyperdrive instance\n * deployed by the deployer factory.\n */\n async getInstances(options?: ContractReadOptions): Promise<ReadHyperdrive[]> {\n const hyperdriveAddresses = await this.getInstanceAddresses(options);\n return hyperdriveAddresses.map(\n (address) =>\n new ReadHyperdrive({\n address,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n );\n }\n\n /**\n * Get the address of all Hyperdrive instances deployed by the factory.\n */\n async getInstanceAddresses(\n options?: ContractReadOptions,\n ): Promise<Address[]> {\n const count = await this.contract.read(\"getNumberOfInstances\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getInstancesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n}\n","import { Contract, ContractReadOptions } from \"@delvtech/drift\";\nimport { Address } from \"abitype\";\nimport { ReadContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadClient } from \"src/drift/ReadClient\";\nimport { ReadFactory } from \"src/factory/ReadFactory\";\nimport { ReadHyperdrive } from \"src/hyperdrive/ReadHyperdrive\";\nimport { RegistryAbi, registryAbi } from \"src/registry/abi\";\nimport {\n FactoryInfoWithMetadata,\n ReadInstanceInfoWithMetadata,\n} from \"src/registry/types\";\n\nexport interface ReadRegistryOptions extends ReadContractClientOptions {}\n\nexport class ReadRegistry extends ReadClient {\n address: Address;\n contract: Contract<RegistryAbi>;\n\n constructor({\n debugName = \"Hyperdrive Registry\",\n address,\n cache,\n cacheNamespace,\n ...rest\n }: ReadRegistryOptions) {\n super({ debugName, ...rest });\n this.address = address;\n this.contract = this.drift.contract({\n abi: registryAbi,\n address,\n cache,\n cacheNamespace,\n });\n }\n\n /**\n * Get a {@linkcode ReadFactory} instance for each registered factory.\n */\n async getFactories(options?: ContractReadOptions): Promise<ReadFactory[]> {\n const factoryAddresses = await this.getFactoryAddresses(options);\n return factoryAddresses.map(\n (address) =>\n new ReadFactory({\n address,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n );\n }\n\n /**\n * Get the address of all registered factories.\n */\n async getFactoryAddresses(options?: ContractReadOptions): Promise<Address[]> {\n const count = await this.contract.read(\"getNumberOfFactories\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getFactoriesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n\n /**\n * Gets the Hyperdrive factory info with associated metadata for a factory.\n */\n async getFactoryInfo(\n factoryAddress: Address,\n options?: ContractReadOptions,\n ): Promise<FactoryInfoWithMetadata> {\n return this.contract.read(\n \"getFactoryInfoWithMetadata\",\n { _factory: factoryAddress },\n options,\n );\n }\n\n /**\n * Gets the Hyperdrive factory info with associated metadata for a list of\n * factories\n */\n async getFactoryInfos(\n factoryAddresses: Address[],\n options?: ContractReadOptions,\n ): Promise<FactoryInfoWithMetadata[]> {\n const readonlyInfos = await this.contract.read(\n \"getFactoryInfosWithMetadata\",\n { __factories: factoryAddresses },\n options,\n );\n return readonlyInfos.slice();\n }\n\n /**\n * Get a {@linkcode ReadHyperdrive} instance for each Hyperdrive instance\n * registered in the registry.\n */\n async getInstances(options?: ContractReadOptions): Promise<ReadHyperdrive[]> {\n const hyperdriveAddresses = await this.getInstanceAddresses(options);\n return hyperdriveAddresses.map(\n (address) =>\n new ReadHyperdrive({\n address,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n );\n }\n\n /**\n * Get the address of all Hyperdrive instances registered in the registry.\n */\n async getInstanceAddresses(\n options?: ContractReadOptions,\n ): Promise<Address[]> {\n const count = await this.contract.read(\"getNumberOfInstances\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getInstancesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n\n /**\n * Gets the instance info with associated metadata for an instance.\n */\n async getInstanceInfo(\n instanceAddress: Address,\n options?: ContractReadOptions,\n ): Promise<ReadInstanceInfoWithMetadata> {\n const { factory, ...rest } = await this.contract.read(\n \"getInstanceInfoWithMetadata\",\n { _instance: instanceAddress },\n options,\n );\n return {\n factory: new ReadFactory({\n address: factory,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n ...rest,\n };\n }\n\n /**\n * Gets the instance info with associated metadata for a list of instances.\n */\n async getInstanceInfos(\n instanceAddresses: Address[],\n options?: ContractReadOptions,\n ): Promise<ReadInstanceInfoWithMetadata[]> {\n const infos = await this.contract.read(\n \"getInstanceInfosWithMetadata\",\n { __instances: instanceAddresses },\n options,\n );\n return infos.map(({ factory, ...rest }) => ({\n factory: new ReadFactory({\n address: factory,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n ...rest,\n }));\n }\n}\n","import {\n ContractReadOptions,\n Drift,\n ReadWriteAdapter,\n ReadWriteContract,\n ReplaceProps,\n} from \"@delvtech/drift\";\nimport { ReadWriteContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadFactory, ReadFactoryOptions } from \"src/factory/ReadFactory\";\nimport { FactoryAbi } from \"src/factory/abi\";\nimport { ReadWriteHyperdrive } from \"src/hyperdrive/ReadWriteHyperdrive\";\n\nexport interface ReadWriteFactoryOptions\n extends ReplaceProps<ReadFactoryOptions, ReadWriteContractClientOptions> {}\n\nexport class ReadWriteFactory extends ReadFactory {\n declare contract: ReadWriteContract<FactoryAbi>;\n declare drift: Drift<ReadWriteAdapter>;\n\n constructor(options: ReadWriteFactoryOptions) {\n super(options);\n }\n\n /**\n * Get a {@linkcode ReadWriteHyperdrive} instance for each Hyperdrive instance\n * deployed by the deployer factory.\n */\n async getInstances(\n options?: ContractReadOptions,\n ): Promise<ReadWriteHyperdrive[]> {\n const hyperdriveAddresses = await this.getInstanceAddresses(options);\n return hyperdriveAddresses.map(\n (address) =>\n new ReadWriteHyperdrive({\n address,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n );\n }\n}\n","import {\n ContractReadOptions,\n Drift,\n ReadWriteAdapter,\n ReadWriteContract,\n ReplaceProps,\n} from \"@delvtech/drift\";\nimport { Address } from \"abitype\";\nimport { ReadWriteContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadWriteFactory } from \"src/factory/ReadWriteFactory\";\nimport { ReadWriteHyperdrive } from \"src/hyperdrive/ReadWriteHyperdrive\";\nimport { ReadRegistry, ReadRegistryOptions } from \"src/registry/ReadRegistry\";\nimport { RegistryAbi } from \"src/registry/abi\";\nimport { ReadWriteInstanceInfoWithMetadata } from \"src/registry/types\";\n\nexport interface ReadWriteRegistryOptions\n extends ReplaceProps<ReadRegistryOptions, ReadWriteContractClientOptions> {}\n\nexport class ReadWriteRegistry extends ReadRegistry {\n declare drift: Drift<ReadWriteAdapter>;\n declare contract: ReadWriteContract<RegistryAbi>;\n\n constructor(options: ReadWriteRegistryOptions) {\n super(options);\n }\n\n /**\n * Get a {@linkcode ReadWriteFactory} instance for each registered factory.\n */\n async getFactories(\n options?: ContractReadOptions,\n ): Promise<ReadWriteFactory[]> {\n const factoryAddresses = await this.getFactoryAddresses(options);\n return factoryAddresses.map(\n (address) =>\n new ReadWriteFactory({\n address,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n );\n }\n\n /**\n * Get a {@linkcode ReadWriteHyperdrive} instance for each Hyperdrive instance\n * registered in the registry.\n */\n async getInstances(\n options?: ContractReadOptions,\n ): Promise<ReadWriteHyperdrive[]> {\n const count = await this.contract.read(\"getNumberOfInstances\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const hyperdriveAddresses = await this.contract.read(\n \"getInstancesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return hyperdriveAddresses.map(\n (address) =>\n new ReadWriteHyperdrive({\n address,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n );\n }\n\n async getInstanceInfo(\n instanceAddress: Address,\n options?: ContractReadOptions,\n ): Promise<ReadWriteInstanceInfoWithMetadata> {\n const { factory, ...rest } = await this.contract.read(\n \"getInstanceInfoWithMetadata\",\n { _instance: instanceAddress },\n options,\n );\n return {\n factory: new ReadWriteFactory({\n address: factory,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n ...rest,\n };\n }\n\n /**\n * Gets the instance info with associated metadata for a list of instances.\n */\n async getInstanceInfos(\n instanceAddresses: Address[],\n options?: ContractReadOptions,\n ): Promise<ReadWriteInstanceInfoWithMetadata[]> {\n const infos = await this.contract.read(\n \"getInstanceInfosWithMetadata\",\n { __instances: instanceAddresses },\n options,\n );\n return infos.map(({ factory, ...rest }) => ({\n factory: new ReadWriteFactory({\n address: factory,\n drift: this.drift,\n cache: this.contract.cache,\n cacheNamespace: this.contract.cacheNamespace,\n }),\n ...rest,\n }));\n }\n}\n","import { UniV3Zap } from \"@delvtech/hyperdrive-artifacts/UniV3Zap\";\n\nexport const zapAbi = UniV3Zap.abi;\nexport type ZapAbi = typeof UniV3Zap.abi;\n","export const hyperdriveRewardsAbi = [\n {\n type: \"constructor\",\n inputs: [\n {\n name: \"initialOwner\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"initialTimelock\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"initialRoot\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"initialIpfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"acceptRoot\",\n inputs: [],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"batchClaim\",\n inputs: [\n {\n name: \"_accounts\",\n type: \"address[]\",\n internalType: \"address[]\",\n },\n {\n name: \"_rewards\",\n type: \"address[]\",\n internalType: \"address[]\",\n },\n {\n name: \"_claimable\",\n type: \"uint256[]\",\n internalType: \"uint256[]\",\n },\n {\n name: \"_proofs\",\n type: \"bytes32[][]\",\n internalType: \"bytes32[][]\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"uint256[]\",\n internalType: \"uint256[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"claim\",\n inputs: [\n {\n name: \"account\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"reward\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"claimable\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"proof\",\n type: \"bytes32[]\",\n internalType: \"bytes32[]\",\n },\n ],\n outputs: [\n {\n name: \"amount\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"claimed\",\n inputs: [\n {\n name: \"account\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"reward\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"amount\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"ipfsHash\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"isUpdater\",\n inputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"bool\",\n internalType: \"bool\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"owner\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"pendingRoot\",\n inputs: [],\n outputs: [\n {\n name: \"root\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"ipfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"validAt\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"revokePendingRoot\",\n inputs: [],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"root\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"setOwner\",\n inputs: [\n {\n name: \"newOwner\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"setRoot\",\n inputs: [\n {\n name: \"newRoot\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"newIpfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"setRootUpdater\",\n inputs: [\n {\n name: \"updater\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"active\",\n type: \"bool\",\n internalType: \"bool\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"setTimelock\",\n inputs: [\n {\n name: \"newTimelock\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"submitRoot\",\n inputs: [\n {\n name: \"newRoot\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"newIpfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"timelock\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"error\",\n name: \"ArrayEndIndexLessThanStartIndex\",\n inputs: [],\n },\n {\n type: \"error\",\n name: \"ArrayIndexOutOfBounds\",\n inputs: [],\n },\n {\n type: \"error\",\n name: \"IncorrectLength\",\n inputs: [],\n },\n] as const;\nexport type HyperdriveRewardsAbi = typeof hyperdriveRewardsAbi;\n","import { Drift, ReadWriteAdapter } from \"@delvtech/drift\";\nimport { ReadClient, ReadClientOptions } from \"src/drift/ReadClient\";\n\n/**\n * The base options required for all read-write clients.\n */\nexport interface ReadWriteClientOptions extends ReadClientOptions {\n drift: Drift<ReadWriteAdapter>;\n}\n\n/**\n * A base class for read-write clients.\n */\nexport class ReadWriteClient extends ReadClient {\n declare drift: Drift<ReadWriteAdapter>;\n\n constructor(options: ReadWriteClientOptions) {\n super(options);\n }\n}\n","import { fixed } from \"@delvtech/fixed-point-wasm\";\n\ninterface AdjustAmountByPercentageOptions {\n /**\n * The amount to adjust\n */\n amount: bigint;\n /**\n * The percentage to adjust it by, eg: 1e18 for 1%\n */\n percentage: bigint;\n\n /**\n * The decimals of precision for the `amount`\n */\n decimals: number;\n direction: \"up\" | \"down\";\n}\n\n/**\n * Adjusts a given amount by some percentage. Useful for slippage calculations.\n *\n * Example:\n *\n * ```ts\n * adjustAmountByPercentage({\n * amount: parseUnits(\"100\", 18),\n * decimals: 18,\n * percentage: BigInt(1e18),\n * direction: \"down\",\n * }) === parseUnits(\"99\")\n * ```\n *\n * ```ts\n * adjustAmountByPercentage({\n * amount: parseUnits(\"100\", 18),\n * decimals: 18,\n * percentage: BigInt(1e18),\n * direction: \"up\",\n * }) === parseUnits(\"101\")\n * ```\n */\nexport function adjustAmountByPercentage({\n amount,\n percentage,\n decimals,\n direction,\n}: AdjustAmountByPercentageOptions): bigint {\n const slippageAmount = fixed(amount, decimals)\n .mul(percentage, decimals)\n .div(100, 0);\n return direction === \"down\"\n ? amount - slippageAmount.bigint\n : amount + slippageAmount.bigint;\n}\n","import { hyperwasm } from \"src/hyperwasm\";\n// TODO: This is now simply a renamed, re-exported hyperwasm function. We should\n// consider re-exporting all hyperwasm functions directly or not at all.\nexport function getHprFromApr(apr: bigint, positionDuration: bigint): bigint {\n return hyperwasm.calcHprGivenApr({ apr, positionDuration });\n}\n","import { hyperwasm } from \"src/hyperwasm\";\n// TODO: This is now simply a renamed, re-exported hyperwasm function. We should\n// consider re-exporting all hyperwasm functions directly or not at all.\nexport function getHprFromApy(apy: bigint, positionDuration: bigint): bigint {\n return hyperwasm.calcHprGivenApy({ apy, positionDuration });\n}\n"],"mappings":"mVACA,OAAOA,OAAY,SAyBnB,eAAsBC,GAAuC,CAC3D,QAAAC,EACA,MAAAC,EACA,MAAAC,EAAQD,EAAM,MACd,eAAAE,EACA,cAAAC,EACA,UAAAC,EACA,mBAAAC,CACF,EAAiD,CAC/CH,IAAmB,MAAMF,EAAM,WAAW,EAE1C,IAAMM,EAAgC,CACpC,QAAAP,EACA,MAAAC,EACA,MAAAC,EACA,eAAAC,EACA,cAAAC,EACA,UAAAC,EACA,mBAAAC,CACF,EACME,EAAcC,GAAmBF,CAAO,EAExCG,EAAU,MAAMT,EAAM,KAAK,CAC/B,IAAKU,EACL,QAAAX,EACA,GAAI,UACJ,eAAAG,CACF,CAAC,EACKS,EAAYC,GAAO,IAAIH,EAAS,QAAQ,EAW9C,OATaE,EACT,OACA,MAAMX,EAAM,KAAK,CACf,IAAKU,EACL,QAAAX,EACA,GAAI,OACJ,eAAAG,CACF,CAAC,EAES,CACZ,IAAK,kBACH,OAAIK,GAAeI,EACV,IAAIE,EAAiCP,CAAO,EAGjDC,EACK,IAAIO,EAAyBR,CAAO,EAGzCK,EACK,IAAII,EAA4BT,CAAO,EAGzC,IAAIU,EAAoBV,CAAO,EAExC,QACE,OAAIC,GAAeI,EACV,IAAIM,EAA4BX,CAAO,EAG5CC,EACK,IAAIW,EAAoBZ,CAAO,EAGpCK,EACK,IAAIQ,EAAuBb,CAAO,EAGpC,IAAIc,EAAed,CAAO,CACrC,CACF,CAEA,SAASE,GACPF,EACuC,CACvC,OAAO,OAAOA,EAAQ,MAAM,OAAU,UACxC,CCtGA,OAAS,SAAAe,OAAa,6BAEf,SAASC,GAAkC,CAChD,QAAAC,EACA,WAAAC,EACA,eAAAC,EACA,SAAAC,CACF,EAKW,CAET,IAAMC,EAAUN,GAAMG,EAAYE,CAAQ,EAAE,IAAIH,CAAO,EAAE,OACzD,OAAOC,EAAaC,EAAiBE,CACvC,CChBA,OAAS,uBAAAC,OAA2B,qDAE7B,IAAMC,EAAcD,GAAoB,ICF/C,OAAS,sBAAAE,OAA0B,oDAE5B,IAAMC,EAAaD,GAAmB,ICOtC,IAAME,EAAN,cAA0BC,CAAW,CAC1C,QACA,SAEA,YAAY,CACV,UAAAC,EAAY,qBACZ,QAAAC,EACA,MAAAC,EACA,eAAAC,EACA,GAAGC,CACL,EAAuB,CACrB,MAAM,CAAE,UAAAJ,EAAW,GAAGI,CAAK,CAAC,EAC5B,KAAK,QAAUH,EACf,KAAK,SAAW,KAAK,MAAM,SAAS,CAClC,IAAKI,EACL,QAAAJ,EACA,MAAAC,EACA,eAAAC,CACF,CAAC,CACH,CAKA,MAAM,cAAcF,EAAoC,CACtD,OAAO,KAAK,SAAS,KAAK,aAAc,CAAE,UAAWA,CAAQ,CAAC,CAChE,CAMA,MAAM,yBAAyBA,EAAoC,CACjE,OAAO,KAAK,SAAS,KAAK,wBAAyB,CACjD,qBAAsBA,CACxB,CAAC,CACH,CAKA,MAAM,gCAAgC,CACpC,UAAAK,EACA,QAAAC,CACF,EAMI,CAAC,EAAuB,CAC1B,GAAID,EAOF,OAN0B,MAAM,KAAK,SAAS,KAC5C,oCACA,CACE,YAAaA,CACf,CACF,GACyB,MAAM,EAGjC,IAAME,EAAQ,MAAM,KAAK,SAAS,KAChC,kCACA,CAAC,EACDD,CACF,EAEA,OAAIC,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,iCACA,CACE,YAAa,GACb,UAAWA,CACb,EACAD,CACF,GACyB,MAAM,CACjC,CAMA,MAAM,aAAaA,EAA0D,CAE3E,OAD4B,MAAM,KAAK,qBAAqBA,CAAO,GACxC,IACxBN,GACC,IAAIQ,EAAe,CACjB,QAAAR,EACA,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,CACL,CACF,CAKA,MAAM,qBACJM,EACoB,CACpB,IAAMC,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGD,CAAO,EAE1E,OAAIC,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAD,CACF,GACyB,MAAM,CACjC,CACF,ECpHO,IAAMG,EAAN,cAA2BC,CAAW,CAC3C,QACA,SAEA,YAAY,CACV,UAAAC,EAAY,sBACZ,QAAAC,EACA,MAAAC,EACA,eAAAC,EACA,GAAGC,CACL,EAAwB,CACtB,MAAM,CAAE,UAAAJ,EAAW,GAAGI,CAAK,CAAC,EAC5B,KAAK,QAAUH,EACf,KAAK,SAAW,KAAK,MAAM,SAAS,CAClC,IAAKI,EACL,QAAAJ,EACA,MAAAC,EACA,eAAAC,CACF,CAAC,CACH,CAKA,MAAM,aAAaG,EAAuD,CAExE,OADyB,MAAM,KAAK,oBAAoBA,CAAO,GACvC,IACrBL,GACC,IAAIM,EAAY,CACd,QAAAN,EACA,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,CACL,CACF,CAKA,MAAM,oBAAoBK,EAAmD,CAC3E,IAAME,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGF,CAAO,EAE1E,OAAIE,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAF,CACF,GACyB,MAAM,CACjC,CAKA,MAAM,eACJG,EACAH,EACkC,CAClC,OAAO,KAAK,SAAS,KACnB,6BACA,CAAE,SAAUG,CAAe,EAC3BH,CACF,CACF,CAMA,MAAM,gBACJI,EACAJ,EACoC,CAMpC,OALsB,MAAM,KAAK,SAAS,KACxC,8BACA,CAAE,YAAaI,CAAiB,EAChCJ,CACF,GACqB,MAAM,CAC7B,CAMA,MAAM,aAAaA,EAA0D,CAE3E,OAD4B,MAAM,KAAK,qBAAqBA,CAAO,GACxC,IACxBL,GACC,IAAIU,EAAe,CACjB,QAAAV,EACA,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,CACL,CACF,CAKA,MAAM,qBACJK,EACoB,CACpB,IAAME,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGF,CAAO,EAE1E,OAAIE,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAF,CACF,GACyB,MAAM,CACjC,CAKA,MAAM,gBACJM,EACAN,EACuC,CACvC,GAAM,CAAE,QAAAO,EAAS,GAAGT,CAAK,EAAI,MAAM,KAAK,SAAS,KAC/C,8BACA,CAAE,UAAWQ,CAAgB,EAC7BN,CACF,EACA,MAAO,CACL,QAAS,IAAIC,EAAY,CACvB,QAASM,EACT,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,EACD,GAAGT,CACL,CACF,CAKA,MAAM,iBACJU,EACAR,EACyC,CAMzC,OALc,MAAM,KAAK,SAAS,KAChC,+BACA,CAAE,YAAaQ,CAAkB,EACjCR,CACF,GACa,IAAI,CAAC,CAAE,QAAAO,EAAS,GAAGT,CAAK,KAAO,CAC1C,QAAS,IAAIG,EAAY,CACvB,QAASM,EACT,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,EACD,GAAGT,CACL,EAAE,CACJ,CACF,EC5KO,IAAMW,EAAN,cAA+BC,CAAY,CAIhD,YAAYC,EAAkC,CAC5C,MAAMA,CAAO,CACf,CAMA,MAAM,aACJA,EACgC,CAEhC,OAD4B,MAAM,KAAK,qBAAqBA,CAAO,GACxC,IACxBC,GACC,IAAIC,EAAoB,CACtB,QAAAD,EACA,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,CACL,CACF,CACF,ECvBO,IAAME,EAAN,cAAgCC,CAAa,CAIlD,YAAYC,EAAmC,CAC7C,MAAMA,CAAO,CACf,CAKA,MAAM,aACJA,EAC6B,CAE7B,OADyB,MAAM,KAAK,oBAAoBA,CAAO,GACvC,IACrBC,GACC,IAAIC,EAAiB,CACnB,QAAAD,EACA,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,CACL,CACF,CAMA,MAAM,aACJD,EACgC,CAChC,IAAMG,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGH,CAAO,EAE1E,OAAIG,IAAU,GACL,CAAC,GAGkB,MAAM,KAAK,SAAS,KAC9C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAH,CACF,GAC2B,IACxBC,GACC,IAAIG,EAAoB,CACtB,QAAAH,EACA,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,CACL,CACF,CAEA,MAAM,gBACJI,EACAL,EAC4C,CAC5C,GAAM,CAAE,QAAAM,EAAS,GAAGC,CAAK,EAAI,MAAM,KAAK,SAAS,KAC/C,8BACA,CAAE,UAAWF,CAAgB,EAC7BL,CACF,EACA,MAAO,CACL,QAAS,IAAIE,EAAiB,CAC5B,QAASI,EACT,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,EACD,GAAGC,CACL,CACF,CAKA,MAAM,iBACJC,EACAR,EAC8C,CAM9C,OALc,MAAM,KAAK,SAAS,KAChC,+BACA,CAAE,YAAaQ,CAAkB,EACjCR,CACF,GACa,IAAI,CAAC,CAAE,QAAAM,EAAS,GAAGC,CAAK,KAAO,CAC1C,QAAS,IAAIL,EAAiB,CAC5B,QAASI,EACT,MAAO,KAAK,MACZ,MAAO,KAAK,SAAS,MACrB,eAAgB,KAAK,SAAS,cAChC,CAAC,EACD,GAAGC,CACL,EAAE,CACJ,CACF,ECtHA,OAAS,YAAAE,OAAgB,0CAElB,IAAMC,GAASD,GAAS,ICFxB,IAAME,GAAuB,CAClC,CACE,KAAM,cACN,OAAQ,CACN,CACE,KAAM,eACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,kBACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,kBACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,aACN,OAAQ,CAAC,EACT,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,aACN,OAAQ,CACN,CACE,KAAM,YACN,KAAM,YACN,aAAc,WAChB,EACA,CACE,KAAM,WACN,KAAM,YACN,aAAc,WAChB,EACA,CACE,KAAM,aACN,KAAM,YACN,aAAc,WAChB,EACA,CACE,KAAM,UACN,KAAM,cACN,aAAc,aAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,GACN,KAAM,YACN,aAAc,WAChB,CACF,EACA,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,QACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,YACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,QACN,KAAM,YACN,aAAc,WAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,UACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,WACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,YACN,OAAQ,CACN,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,GACN,KAAM,OACN,aAAc,MAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,QACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,cACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,OACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,WACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,oBACN,OAAQ,CAAC,EACT,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,OACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,WACN,OAAQ,CACN,CACE,KAAM,WACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,UACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,iBACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,SACN,KAAM,OACN,aAAc,MAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,cACN,OAAQ,CACN,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,aACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,WACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,QACN,KAAM,kCACN,OAAQ,CAAC,CACX,EACA,CACE,KAAM,QACN,KAAM,wBACN,OAAQ,CAAC,CACX,EACA,CACE,KAAM,QACN,KAAM,kBACN,OAAQ,CAAC,CACX,CACF,ECrTO,IAAMC,EAAN,cAA8BC,CAAW,CAG9C,YAAYC,EAAiC,CAC3C,MAAMA,CAAO,CACf,CACF,ECnBA,OAAS,SAAAC,OAAa,6BA0Cf,SAASC,GAAyB,CACvC,OAAAC,EACA,WAAAC,EACA,SAAAC,EACA,UAAAC,CACF,EAA4C,CAC1C,IAAMC,EAAiBN,GAAME,EAAQE,CAAQ,EAC1C,IAAID,EAAYC,CAAQ,EACxB,IAAI,IAAK,CAAC,EACb,OAAOC,IAAc,OACjBH,EAASI,EAAe,OACxBJ,EAASI,EAAe,MAC9B,CCnDO,SAASC,GAAcC,EAAaC,EAAkC,CAC3E,OAAOC,EAAU,gBAAgB,CAAE,IAAAF,EAAK,iBAAAC,CAAiB,CAAC,CAC5D,CCFO,SAASE,GAAcC,EAAaC,EAAkC,CAC3E,OAAOC,EAAU,gBAAgB,CAAE,IAAAF,EAAK,iBAAAC,CAAiB,CAAC,CAC5D","names":["semver","getHyperdrive","address","drift","cache","cacheNamespace","earliestBlock","debugName","zapContractAddress","options","isReadWrite","isReadWriteOptions","version","hyperdriveAbi","isV1_0_14","semver","ReadWriteStEthHyperdrive_v1_0_14","ReadWriteStEthHyperdrive","ReadStEthHyperdrive_v1_0_14","ReadStEthHyperdrive","ReadWriteHyperdrive_v1_0_14","ReadWriteHyperdrive","ReadHyperdrive_v1_0_14","ReadHyperdrive","fixed","calculateMatureLongYieldAfterFees","flatFee","bondAmount","baseAmountPaid","decimals","poolFee","IHyperdriveRegistry","registryAbi","IHyperdriveFactory","factoryAbi","ReadFactory","ReadClient","debugName","address","cache","cacheNamespace","rest","factoryAbi","instances","options","count","ReadHyperdrive","ReadRegistry","ReadClient","debugName","address","cache","cacheNamespace","rest","registryAbi","options","ReadFactory","count","factoryAddress","factoryAddresses","ReadHyperdrive","instanceAddress","factory","instanceAddresses","ReadWriteFactory","ReadFactory","options","address","ReadWriteHyperdrive","ReadWriteRegistry","ReadRegistry","options","address","ReadWriteFactory","count","ReadWriteHyperdrive","instanceAddress","factory","rest","instanceAddresses","UniV3Zap","zapAbi","hyperdriveRewardsAbi","ReadWriteClient","ReadClient","options","fixed","adjustAmountByPercentage","amount","percentage","decimals","direction","slippageAmount","getHprFromApr","apr","positionDuration","hyperwasm","getHprFromApy","apy","positionDuration","hyperwasm"]}
{"version":3,"sources":["../src/hyperdrive/getHyperdrive.ts","../src/hyperdrive/longs/calculateMatureLongYieldAfterFees.ts","../src/registry/abi.ts","../src/factory/abi.ts","../src/factory/ReadFactory.ts","../src/registry/ReadRegistry.ts","../src/factory/ReadWriteFactory.ts","../src/registry/ReadWriteRegistry.ts","../src/hyperdrive/zaps/abi.ts","../src/rewards/abi.ts","../src/drift/ReadWriteClient.ts","../src/base/adjustAmountByPercentage.ts","../src/base/getHprFromApr.ts","../src/base/getHprFromApy.ts"],"sourcesContent":["import {\n Drift,\n ReadWriteAdapter,\n type ReadAdapter,\n type WriteAdapter,\n} from \"@delvtech/drift\";\nimport semver from \"semver\";\nimport { hyperdriveAbi } from \"src/hyperdrive/abi\";\nimport {\n ReadHyperdrive,\n ReadHyperdriveOptions,\n} from \"src/hyperdrive/ReadHyperdrive\";\nimport {\n ReadWriteHyperdrive,\n ReadWriteHyperdriveOptions,\n} from \"src/hyperdrive/ReadWriteHyperdrive\";\nimport { ReadHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadHyperdrive_v1_0_14\";\nimport { ReadWriteHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadWriteHyperdrive_v1_0_14\";\n\nexport interface HyperdriveOptions<T extends Drift = Drift>\n extends ReadHyperdriveOptions {\n drift: T;\n}\n\nexport type Hyperdrive<T extends Drift = Drift> =\n T[\"adapter\"] extends ReadWriteAdapter\n ? ReadWriteHyperdrive\n : T[\"adapter\"] extends ReadAdapter & {\n [K in keyof WriteAdapter]?: never;\n }\n ? ReadHyperdrive\n : ReadHyperdrive & Partial<ReadWriteHyperdrive>;\n\nexport async function getHyperdrive<T extends Drift = Drift>(\n options: HyperdriveOptions<T>,\n): Promise<Hyperdrive<T>> {\n const { address, drift } = options;\n const isReadWrite = isReadWriteOptions(options);\n\n const version = await drift.read({\n abi: hyperdriveAbi,\n address,\n fn: \"version\",\n });\n const isV1_0_14 = semver.lte(version, \"1.0.14\");\n\n if (isV1_0_14) {\n return isReadWrite\n ? new ReadWriteHyperdrive_v1_0_14(options)\n : (new ReadHyperdrive_v1_0_14(options) as Hyperdrive<T>);\n }\n\n return isReadWrite\n ? new ReadWriteHyperdrive(options)\n : (new ReadHyperdrive(options) as Hyperdrive<T>);\n}\n\nfunction isReadWriteOptions(\n options: HyperdriveOptions,\n): options is ReadWriteHyperdriveOptions {\n return options.drift.isReadWrite();\n}\n","import { fixed } from \"@delvtech/fixed-point-wasm\";\n\nexport function calculateMatureLongYieldAfterFees({\n flatFee,\n bondAmount,\n baseAmountPaid,\n decimals,\n}: {\n flatFee: bigint;\n bondAmount: bigint;\n baseAmountPaid: bigint;\n decimals: number;\n}): bigint {\n // Flat fee is always 18 decimals\n const poolFee = fixed(bondAmount, decimals).mul(flatFee, 18).bigint;\n return bondAmount - baseAmountPaid - poolFee;\n}\n","import { IHyperdriveRegistry } from \"@delvtech/hyperdrive-artifacts/IHyperdriveRegistry\";\n\nexport const registryAbi = IHyperdriveRegistry.abi;\nexport type RegistryAbi = typeof registryAbi;\n","import { IHyperdriveFactory } from \"@delvtech/hyperdrive-artifacts/IHyperdriveFactory\";\n\nexport const factoryAbi = IHyperdriveFactory.abi;\nexport type FactoryAbi = typeof factoryAbi;\n","import { Contract, type ReadOptions } from \"@delvtech/drift\";\nimport { Address } from \"abitype\";\nimport { ReadContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadClient } from \"src/drift/ReadClient\";\nimport { FactoryAbi, factoryAbi } from \"src/factory/abi\";\nimport { ReadHyperdrive } from \"src/hyperdrive/ReadHyperdrive\";\n\nexport interface ReadFactoryOptions extends ReadContractClientOptions {}\n\nexport class ReadFactory extends ReadClient {\n address: Address;\n contract: Contract<FactoryAbi>;\n\n constructor({\n debugName = \"Hyperdrive Factory\",\n address,\n epochBlock,\n ...rest\n }: ReadFactoryOptions) {\n super({ debugName, epochBlock, ...rest });\n this.address = address;\n this.contract = this.drift.contract({\n abi: factoryAbi,\n address,\n epochBlock,\n });\n }\n\n /**\n * Find out if the given address is an instance deployed by the factory.\n */\n async getIsInstance(address: Address): Promise<boolean> {\n return this.contract.read(\"isInstance\", { _instance: address });\n }\n\n /**\n * Find out if the given address is a deployer coordinator registered with the\n * factory.\n */\n async getIsDeployerCoordinator(address: Address): Promise<boolean> {\n return this.contract.read(\"isDeployerCoordinator\", {\n _deployerCoordinator: address,\n });\n }\n\n /**\n * Get the address of all registered deployer coordinators.\n */\n async getDeployerCoordinatorAddresses({\n instances,\n options,\n }: {\n /**\n * Only return deployer coordinators that deployed the given instances.\n */\n instances?: Address[];\n options?: ReadOptions;\n } = {}): Promise<Address[]> {\n if (instances) {\n const readOnlyAddresses = await this.contract.read(\n \"getDeployerCoordinatorByInstances\",\n {\n __instances: instances,\n },\n );\n return readOnlyAddresses.slice();\n }\n\n const count = await this.contract.read(\n \"getNumberOfDeployerCoordinators\",\n {},\n options,\n );\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getDeployerCoordinatorsInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n\n /**\n * Get a {@linkcode ReadHyperdrive} instance for each Hyperdrive instance\n * deployed by the deployer factory.\n */\n async getInstances(options?: ReadOptions): Promise<ReadHyperdrive[]> {\n const hyperdriveAddresses = await this.getInstanceAddresses(options);\n return hyperdriveAddresses.map(\n (address) =>\n new ReadHyperdrive({\n address,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n );\n }\n\n /**\n * Get the address of all Hyperdrive instances deployed by the factory.\n */\n async getInstanceAddresses(options?: ReadOptions): Promise<Address[]> {\n const count = await this.contract.read(\"getNumberOfInstances\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getInstancesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n}\n","import { Contract, ReadOptions } from \"@delvtech/drift\";\nimport { Address } from \"abitype\";\nimport { ReadContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadClient } from \"src/drift/ReadClient\";\nimport { ReadFactory } from \"src/factory/ReadFactory\";\nimport { ReadHyperdrive } from \"src/hyperdrive/ReadHyperdrive\";\nimport { RegistryAbi, registryAbi } from \"src/registry/abi\";\nimport {\n FactoryInfoWithMetadata,\n ReadInstanceInfoWithMetadata,\n} from \"src/registry/types\";\n\nexport interface ReadRegistryOptions extends ReadContractClientOptions {}\n\nexport class ReadRegistry extends ReadClient {\n address: Address;\n contract: Contract<RegistryAbi>;\n\n constructor({\n debugName = \"Hyperdrive Registry\",\n address,\n epochBlock,\n ...rest\n }: ReadRegistryOptions) {\n super({ debugName, ...rest });\n this.address = address;\n this.contract = this.drift.contract({\n abi: registryAbi,\n address,\n epochBlock,\n });\n }\n\n /**\n * Get a {@linkcode ReadFactory} instance for each registered factory.\n */\n async getFactories(options?: ReadOptions): Promise<ReadFactory[]> {\n const factoryAddresses = await this.getFactoryAddresses(options);\n return factoryAddresses.map(\n (address) =>\n new ReadFactory({\n address,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n );\n }\n\n /**\n * Get the address of all registered factories.\n */\n async getFactoryAddresses(options?: ReadOptions): Promise<Address[]> {\n const count = await this.contract.read(\"getNumberOfFactories\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getFactoriesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n\n /**\n * Gets the Hyperdrive factory info with associated metadata for a factory.\n */\n async getFactoryInfo(\n factoryAddress: Address,\n options?: ReadOptions,\n ): Promise<FactoryInfoWithMetadata> {\n return this.contract.read(\n \"getFactoryInfoWithMetadata\",\n { _factory: factoryAddress },\n options,\n );\n }\n\n /**\n * Gets the Hyperdrive factory info with associated metadata for a list of\n * factories\n */\n async getFactoryInfos(\n factoryAddresses: Address[],\n options?: ReadOptions,\n ): Promise<FactoryInfoWithMetadata[]> {\n const readonlyInfos = await this.contract.read(\n \"getFactoryInfosWithMetadata\",\n { __factories: factoryAddresses },\n options,\n );\n return readonlyInfos.slice();\n }\n\n /**\n * Get a {@linkcode ReadHyperdrive} instance for each Hyperdrive instance\n * registered in the registry.\n */\n async getInstances(options?: ReadOptions): Promise<ReadHyperdrive[]> {\n const hyperdriveAddresses = await this.getInstanceAddresses(options);\n return hyperdriveAddresses.map(\n (address) =>\n new ReadHyperdrive({\n address,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n );\n }\n\n /**\n * Get the address of all Hyperdrive instances registered in the registry.\n */\n async getInstanceAddresses(options?: ReadOptions): Promise<Address[]> {\n const count = await this.contract.read(\"getNumberOfInstances\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const readOnlyAddresses = await this.contract.read(\n \"getInstancesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return readOnlyAddresses.slice();\n }\n\n /**\n * Gets the instance info with associated metadata for an instance.\n */\n async getInstanceInfo(\n instanceAddress: Address,\n options?: ReadOptions,\n ): Promise<ReadInstanceInfoWithMetadata> {\n const { factory, ...rest } = await this.contract.read(\n \"getInstanceInfoWithMetadata\",\n { _instance: instanceAddress },\n options,\n );\n return {\n factory: new ReadFactory({\n address: factory,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n ...rest,\n };\n }\n\n /**\n * Gets the instance info with associated metadata for a list of instances.\n */\n async getInstanceInfos(\n instanceAddresses: Address[],\n options?: ReadOptions,\n ): Promise<ReadInstanceInfoWithMetadata[]> {\n const infos = await this.contract.read(\n \"getInstanceInfosWithMetadata\",\n { __instances: instanceAddresses },\n options,\n );\n return infos.map(({ factory, ...rest }) => ({\n factory: new ReadFactory({\n address: factory,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n ...rest,\n }));\n }\n}\n","import {\n Drift,\n ReadOptions,\n ReadWriteAdapter,\n ReadWriteContract,\n type Replace,\n} from \"@delvtech/drift\";\nimport { ReadWriteContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadFactory, ReadFactoryOptions } from \"src/factory/ReadFactory\";\nimport { FactoryAbi } from \"src/factory/abi\";\nimport { ReadWriteHyperdrive } from \"src/hyperdrive/ReadWriteHyperdrive\";\n\nexport interface ReadWriteFactoryOptions\n extends Replace<ReadFactoryOptions, ReadWriteContractClientOptions> {}\n\nexport class ReadWriteFactory extends ReadFactory {\n declare contract: ReadWriteContract<FactoryAbi>;\n declare drift: Drift<ReadWriteAdapter>;\n\n constructor(options: ReadWriteFactoryOptions) {\n super(options);\n }\n\n /**\n * Get a {@linkcode ReadWriteHyperdrive} instance for each Hyperdrive instance\n * deployed by the deployer factory.\n */\n async getInstances(options?: ReadOptions): Promise<ReadWriteHyperdrive[]> {\n const hyperdriveAddresses = await this.getInstanceAddresses(options);\n return hyperdriveAddresses.map(\n (address) =>\n new ReadWriteHyperdrive({\n address,\n drift: this.drift,\n }),\n );\n }\n}\n","import {\n Drift,\n ReadOptions,\n ReadWriteAdapter,\n ReadWriteContract,\n Replace,\n} from \"@delvtech/drift\";\nimport { Address } from \"abitype\";\nimport { ReadWriteContractClientOptions } from \"src/drift/ContractClient\";\nimport { ReadWriteFactory } from \"src/factory/ReadWriteFactory\";\nimport { ReadWriteHyperdrive } from \"src/hyperdrive/ReadWriteHyperdrive\";\nimport { ReadRegistry, ReadRegistryOptions } from \"src/registry/ReadRegistry\";\nimport { RegistryAbi } from \"src/registry/abi\";\nimport { ReadWriteInstanceInfoWithMetadata } from \"src/registry/types\";\n\nexport interface ReadWriteRegistryOptions\n extends Replace<ReadRegistryOptions, ReadWriteContractClientOptions> {}\n\nexport class ReadWriteRegistry extends ReadRegistry {\n declare drift: Drift<ReadWriteAdapter>;\n declare contract: ReadWriteContract<RegistryAbi>;\n\n constructor(options: ReadWriteRegistryOptions) {\n super(options);\n }\n\n /**\n * Get a {@linkcode ReadWriteFactory} instance for each registered factory.\n */\n async getFactories(options?: ReadOptions): Promise<ReadWriteFactory[]> {\n const factoryAddresses = await this.getFactoryAddresses(options);\n return factoryAddresses.map(\n (address) =>\n new ReadWriteFactory({\n address,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n );\n }\n\n /**\n * Get a {@linkcode ReadWriteHyperdrive} instance for each Hyperdrive instance\n * registered in the registry.\n */\n async getInstances(options?: ReadOptions): Promise<ReadWriteHyperdrive[]> {\n const count = await this.contract.read(\"getNumberOfInstances\", {}, options);\n\n if (count === 0n) {\n return [];\n }\n\n const hyperdriveAddresses = await this.contract.read(\n \"getInstancesInRange\",\n {\n _startIndex: 0n,\n _endIndex: count,\n },\n options,\n );\n return hyperdriveAddresses.map(\n (address) =>\n new ReadWriteHyperdrive({\n address,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n );\n }\n\n async getInstanceInfo(\n instanceAddress: Address,\n options?: ReadOptions,\n ): Promise<ReadWriteInstanceInfoWithMetadata> {\n const { factory, ...rest } = await this.contract.read(\n \"getInstanceInfoWithMetadata\",\n { _instance: instanceAddress },\n options,\n );\n return {\n factory: new ReadWriteFactory({\n address: factory,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n ...rest,\n };\n }\n\n /**\n * Gets the instance info with associated metadata for a list of instances.\n */\n async getInstanceInfos(\n instanceAddresses: Address[],\n options?: ReadOptions,\n ): Promise<ReadWriteInstanceInfoWithMetadata[]> {\n const infos = await this.contract.read(\n \"getInstanceInfosWithMetadata\",\n { __instances: instanceAddresses },\n options,\n );\n return infos.map(({ factory, ...rest }) => ({\n factory: new ReadWriteFactory({\n address: factory,\n drift: this.drift,\n epochBlock: this.contract.epochBlock,\n }),\n ...rest,\n }));\n }\n}\n","import { UniV3Zap } from \"@delvtech/hyperdrive-artifacts/UniV3Zap\";\n\nexport const zapAbi = UniV3Zap.abi;\nexport type ZapAbi = typeof UniV3Zap.abi;\n","export const hyperdriveRewardsAbi = [\n {\n type: \"constructor\",\n inputs: [\n {\n name: \"initialOwner\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"initialTimelock\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"initialRoot\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"initialIpfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"acceptRoot\",\n inputs: [],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"batchClaim\",\n inputs: [\n {\n name: \"_accounts\",\n type: \"address[]\",\n internalType: \"address[]\",\n },\n {\n name: \"_rewards\",\n type: \"address[]\",\n internalType: \"address[]\",\n },\n {\n name: \"_claimable\",\n type: \"uint256[]\",\n internalType: \"uint256[]\",\n },\n {\n name: \"_proofs\",\n type: \"bytes32[][]\",\n internalType: \"bytes32[][]\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"uint256[]\",\n internalType: \"uint256[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"claim\",\n inputs: [\n {\n name: \"account\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"reward\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"claimable\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n {\n name: \"proof\",\n type: \"bytes32[]\",\n internalType: \"bytes32[]\",\n },\n ],\n outputs: [\n {\n name: \"amount\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"claimed\",\n inputs: [\n {\n name: \"account\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"reward\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"amount\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"ipfsHash\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"isUpdater\",\n inputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [\n {\n name: \"\",\n type: \"bool\",\n internalType: \"bool\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"owner\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"pendingRoot\",\n inputs: [],\n outputs: [\n {\n name: \"root\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"ipfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"validAt\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"revokePendingRoot\",\n inputs: [],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"root\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"setOwner\",\n inputs: [\n {\n name: \"newOwner\",\n type: \"address\",\n internalType: \"address\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"setRoot\",\n inputs: [\n {\n name: \"newRoot\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"newIpfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"setRootUpdater\",\n inputs: [\n {\n name: \"updater\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"active\",\n type: \"bool\",\n internalType: \"bool\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"setTimelock\",\n inputs: [\n {\n name: \"newTimelock\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"submitRoot\",\n inputs: [\n {\n name: \"newRoot\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n {\n name: \"newIpfsHash\",\n type: \"bytes32\",\n internalType: \"bytes32\",\n },\n ],\n outputs: [],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"timelock\",\n inputs: [],\n outputs: [\n {\n name: \"\",\n type: \"uint256\",\n internalType: \"uint256\",\n },\n ],\n stateMutability: \"view\",\n },\n {\n type: \"error\",\n name: \"ArrayEndIndexLessThanStartIndex\",\n inputs: [],\n },\n {\n type: \"error\",\n name: \"ArrayIndexOutOfBounds\",\n inputs: [],\n },\n {\n type: \"error\",\n name: \"IncorrectLength\",\n inputs: [],\n },\n] as const;\nexport type HyperdriveRewardsAbi = typeof hyperdriveRewardsAbi;\n","import { Drift, ReadWriteAdapter } from \"@delvtech/drift\";\nimport { ReadClient, ReadClientOptions } from \"src/drift/ReadClient\";\n\n/**\n * The base options required for all read-write clients.\n */\nexport interface ReadWriteClientOptions extends ReadClientOptions {\n drift: Drift<ReadWriteAdapter>;\n}\n\n/**\n * A base class for read-write clients.\n */\nexport class ReadWriteClient extends ReadClient {\n declare drift: Drift<ReadWriteAdapter>;\n\n constructor(options: ReadWriteClientOptions) {\n super(options);\n }\n}\n","import { fixed } from \"@delvtech/fixed-point-wasm\";\n\ninterface AdjustAmountByPercentageOptions {\n /**\n * The amount to adjust\n */\n amount: bigint;\n /**\n * The percentage to adjust it by, eg: 1e18 for 1%\n */\n percentage: bigint;\n\n /**\n * The decimals of precision for the `amount`\n */\n decimals: number;\n direction: \"up\" | \"down\";\n}\n\n/**\n * Adjusts a given amount by some percentage. Useful for slippage calculations.\n *\n * Example:\n *\n * ```ts\n * adjustAmountByPercentage({\n * amount: parseUnits(\"100\", 18),\n * decimals: 18,\n * percentage: BigInt(1e18),\n * direction: \"down\",\n * }) === parseUnits(\"99\")\n * ```\n *\n * ```ts\n * adjustAmountByPercentage({\n * amount: parseUnits(\"100\", 18),\n * decimals: 18,\n * percentage: BigInt(1e18),\n * direction: \"up\",\n * }) === parseUnits(\"101\")\n * ```\n */\nexport function adjustAmountByPercentage({\n amount,\n percentage,\n decimals,\n direction,\n}: AdjustAmountByPercentageOptions): bigint {\n const slippageAmount = fixed(amount, decimals)\n .mul(percentage, decimals)\n .div(100, 0);\n return direction === \"down\"\n ? amount - slippageAmount.bigint\n : amount + slippageAmount.bigint;\n}\n","import { hyperwasm } from \"src/hyperwasm\";\n// TODO: This is now simply a renamed, re-exported hyperwasm function. We should\n// consider re-exporting all hyperwasm functions directly or not at all.\nexport function getHprFromApr(apr: bigint, positionDuration: bigint): bigint {\n return hyperwasm.calcHprGivenApr({ apr, positionDuration });\n}\n","import { hyperwasm } from \"src/hyperwasm\";\n// TODO: This is now simply a renamed, re-exported hyperwasm function. We should\n// consider re-exporting all hyperwasm functions directly or not at all.\nexport function getHprFromApy(apy: bigint, positionDuration: bigint): bigint {\n return hyperwasm.calcHprGivenApy({ apy, positionDuration });\n}\n"],"mappings":"mIAMA,OAAOA,MAAY,SA2BnB,eAAsBC,EACpBC,EACwB,CACxB,GAAM,CAAE,QAAAC,EAAS,MAAAC,CAAM,EAAIF,EACrBG,EAAcC,EAAmBJ,CAAO,EAExCK,EAAU,MAAMH,EAAM,KAAK,CAC/B,IAAKI,EACL,QAAAL,EACA,GAAI,SACN,CAAC,EAGD,OAFkBM,EAAO,IAAIF,EAAS,QAAQ,EAGrCF,EACH,IAAIK,EAA4BR,CAAO,EACtC,IAAIS,EAAuBT,CAAO,EAGlCG,EACH,IAAIO,EAAoBV,CAAO,EAC9B,IAAIW,EAAeX,CAAO,CACjC,CAEA,SAASI,EACPJ,EACuC,CACvC,OAAOA,EAAQ,MAAM,YAAY,CACnC,CC7DA,OAAS,SAAAY,MAAa,6BAEf,SAASC,EAAkC,CAChD,QAAAC,EACA,WAAAC,EACA,eAAAC,EACA,SAAAC,CACF,EAKW,CAET,IAAMC,EAAUN,EAAMG,EAAYE,CAAQ,EAAE,IAAIH,EAAS,EAAE,EAAE,OAC7D,OAAOC,EAAaC,EAAiBE,CACvC,CChBA,OAAS,uBAAAC,MAA2B,qDAE7B,IAAMC,EAAcD,EAAoB,ICF/C,OAAS,sBAAAE,MAA0B,oDAE5B,IAAMC,EAAaD,EAAmB,ICOtC,IAAME,EAAN,cAA0BC,CAAW,CAC1C,QACA,SAEA,YAAY,CACV,UAAAC,EAAY,qBACZ,QAAAC,EACA,WAAAC,EACA,GAAGC,CACL,EAAuB,CACrB,MAAM,CAAE,UAAAH,EAAW,WAAAE,EAAY,GAAGC,CAAK,CAAC,EACxC,KAAK,QAAUF,EACf,KAAK,SAAW,KAAK,MAAM,SAAS,CAClC,IAAKG,EACL,QAAAH,EACA,WAAAC,CACF,CAAC,CACH,CAKA,MAAM,cAAcD,EAAoC,CACtD,OAAO,KAAK,SAAS,KAAK,aAAc,CAAE,UAAWA,CAAQ,CAAC,CAChE,CAMA,MAAM,yBAAyBA,EAAoC,CACjE,OAAO,KAAK,SAAS,KAAK,wBAAyB,CACjD,qBAAsBA,CACxB,CAAC,CACH,CAKA,MAAM,gCAAgC,CACpC,UAAAI,EACA,QAAAC,CACF,EAMI,CAAC,EAAuB,CAC1B,GAAID,EAOF,OAN0B,MAAM,KAAK,SAAS,KAC5C,oCACA,CACE,YAAaA,CACf,CACF,GACyB,MAAM,EAGjC,IAAME,EAAQ,MAAM,KAAK,SAAS,KAChC,kCACA,CAAC,EACDD,CACF,EAEA,OAAIC,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,iCACA,CACE,YAAa,GACb,UAAWA,CACb,EACAD,CACF,GACyB,MAAM,CACjC,CAMA,MAAM,aAAaA,EAAkD,CAEnE,OAD4B,MAAM,KAAK,qBAAqBA,CAAO,GACxC,IACxBL,GACC,IAAIO,EAAe,CACjB,QAAAP,EACA,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,CACL,CACF,CAKA,MAAM,qBAAqBK,EAA2C,CACpE,IAAMC,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGD,CAAO,EAE1E,OAAIC,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAD,CACF,GACyB,MAAM,CACjC,CACF,EC/GO,IAAMG,EAAN,cAA2BC,CAAW,CAC3C,QACA,SAEA,YAAY,CACV,UAAAC,EAAY,sBACZ,QAAAC,EACA,WAAAC,EACA,GAAGC,CACL,EAAwB,CACtB,MAAM,CAAE,UAAAH,EAAW,GAAGG,CAAK,CAAC,EAC5B,KAAK,QAAUF,EACf,KAAK,SAAW,KAAK,MAAM,SAAS,CAClC,IAAKG,EACL,QAAAH,EACA,WAAAC,CACF,CAAC,CACH,CAKA,MAAM,aAAaG,EAA+C,CAEhE,OADyB,MAAM,KAAK,oBAAoBA,CAAO,GACvC,IACrBJ,GACC,IAAIK,EAAY,CACd,QAAAL,EACA,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,CACL,CACF,CAKA,MAAM,oBAAoBI,EAA2C,CACnE,IAAME,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGF,CAAO,EAE1E,OAAIE,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAF,CACF,GACyB,MAAM,CACjC,CAKA,MAAM,eACJG,EACAH,EACkC,CAClC,OAAO,KAAK,SAAS,KACnB,6BACA,CAAE,SAAUG,CAAe,EAC3BH,CACF,CACF,CAMA,MAAM,gBACJI,EACAJ,EACoC,CAMpC,OALsB,MAAM,KAAK,SAAS,KACxC,8BACA,CAAE,YAAaI,CAAiB,EAChCJ,CACF,GACqB,MAAM,CAC7B,CAMA,MAAM,aAAaA,EAAkD,CAEnE,OAD4B,MAAM,KAAK,qBAAqBA,CAAO,GACxC,IACxBJ,GACC,IAAIS,EAAe,CACjB,QAAAT,EACA,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,CACL,CACF,CAKA,MAAM,qBAAqBI,EAA2C,CACpE,IAAME,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGF,CAAO,EAE1E,OAAIE,IAAU,GACL,CAAC,GAGgB,MAAM,KAAK,SAAS,KAC5C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAF,CACF,GACyB,MAAM,CACjC,CAKA,MAAM,gBACJM,EACAN,EACuC,CACvC,GAAM,CAAE,QAAAO,EAAS,GAAGT,CAAK,EAAI,MAAM,KAAK,SAAS,KAC/C,8BACA,CAAE,UAAWQ,CAAgB,EAC7BN,CACF,EACA,MAAO,CACL,QAAS,IAAIC,EAAY,CACvB,QAASM,EACT,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,EACD,GAAGT,CACL,CACF,CAKA,MAAM,iBACJU,EACAR,EACyC,CAMzC,OALc,MAAM,KAAK,SAAS,KAChC,+BACA,CAAE,YAAaQ,CAAkB,EACjCR,CACF,GACa,IAAI,CAAC,CAAE,QAAAO,EAAS,GAAGT,CAAK,KAAO,CAC1C,QAAS,IAAIG,EAAY,CACvB,QAASM,EACT,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,EACD,GAAGT,CACL,EAAE,CACJ,CACF,ECpKO,IAAMW,EAAN,cAA+BC,CAAY,CAIhD,YAAYC,EAAkC,CAC5C,MAAMA,CAAO,CACf,CAMA,MAAM,aAAaA,EAAuD,CAExE,OAD4B,MAAM,KAAK,qBAAqBA,CAAO,GACxC,IACxBC,GACC,IAAIC,EAAoB,CACtB,QAAAD,EACA,MAAO,KAAK,KACd,CAAC,CACL,CACF,CACF,ECnBO,IAAME,EAAN,cAAgCC,CAAa,CAIlD,YAAYC,EAAmC,CAC7C,MAAMA,CAAO,CACf,CAKA,MAAM,aAAaA,EAAoD,CAErE,OADyB,MAAM,KAAK,oBAAoBA,CAAO,GACvC,IACrBC,GACC,IAAIC,EAAiB,CACnB,QAAAD,EACA,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,CACL,CACF,CAMA,MAAM,aAAaD,EAAuD,CACxE,IAAMG,EAAQ,MAAM,KAAK,SAAS,KAAK,uBAAwB,CAAC,EAAGH,CAAO,EAE1E,OAAIG,IAAU,GACL,CAAC,GAGkB,MAAM,KAAK,SAAS,KAC9C,sBACA,CACE,YAAa,GACb,UAAWA,CACb,EACAH,CACF,GAC2B,IACxBC,GACC,IAAIG,EAAoB,CACtB,QAAAH,EACA,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,CACL,CACF,CAEA,MAAM,gBACJI,EACAL,EAC4C,CAC5C,GAAM,CAAE,QAAAM,EAAS,GAAGC,CAAK,EAAI,MAAM,KAAK,SAAS,KAC/C,8BACA,CAAE,UAAWF,CAAgB,EAC7BL,CACF,EACA,MAAO,CACL,QAAS,IAAIE,EAAiB,CAC5B,QAASI,EACT,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,EACD,GAAGC,CACL,CACF,CAKA,MAAM,iBACJC,EACAR,EAC8C,CAM9C,OALc,MAAM,KAAK,SAAS,KAChC,+BACA,CAAE,YAAaQ,CAAkB,EACjCR,CACF,GACa,IAAI,CAAC,CAAE,QAAAM,EAAS,GAAGC,CAAK,KAAO,CAC1C,QAAS,IAAIL,EAAiB,CAC5B,QAASI,EACT,MAAO,KAAK,MACZ,WAAY,KAAK,SAAS,UAC5B,CAAC,EACD,GAAGC,CACL,EAAE,CACJ,CACF,EC9GA,OAAS,YAAAE,MAAgB,0CAElB,IAAMC,EAASD,EAAS,ICFxB,IAAME,EAAuB,CAClC,CACE,KAAM,cACN,OAAQ,CACN,CACE,KAAM,eACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,kBACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,kBACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,aACN,OAAQ,CAAC,EACT,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,aACN,OAAQ,CACN,CACE,KAAM,YACN,KAAM,YACN,aAAc,WAChB,EACA,CACE,KAAM,WACN,KAAM,YACN,aAAc,WAChB,EACA,CACE,KAAM,aACN,KAAM,YACN,aAAc,WAChB,EACA,CACE,KAAM,UACN,KAAM,cACN,aAAc,aAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,GACN,KAAM,YACN,aAAc,WAChB,CACF,EACA,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,QACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,YACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,QACN,KAAM,YACN,aAAc,WAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,UACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,SACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,WACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,YACN,OAAQ,CACN,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CACP,CACE,KAAM,GACN,KAAM,OACN,aAAc,MAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,QACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,cACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,OACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,WACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,oBACN,OAAQ,CAAC,EACT,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,OACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,WACN,KAAM,WACN,OAAQ,CACN,CACE,KAAM,WACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,UACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,iBACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,SACN,KAAM,OACN,aAAc,MAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,cACN,OAAQ,CACN,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,aACN,OAAQ,CACN,CACE,KAAM,UACN,KAAM,UACN,aAAc,SAChB,EACA,CACE,KAAM,cACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,QAAS,CAAC,EACV,gBAAiB,YACnB,EACA,CACE,KAAM,WACN,KAAM,WACN,OAAQ,CAAC,EACT,QAAS,CACP,CACE,KAAM,GACN,KAAM,UACN,aAAc,SAChB,CACF,EACA,gBAAiB,MACnB,EACA,CACE,KAAM,QACN,KAAM,kCACN,OAAQ,CAAC,CACX,EACA,CACE,KAAM,QACN,KAAM,wBACN,OAAQ,CAAC,CACX,EACA,CACE,KAAM,QACN,KAAM,kBACN,OAAQ,CAAC,CACX,CACF,ECrTO,IAAMC,EAAN,cAA8BC,CAAW,CAG9C,YAAYC,EAAiC,CAC3C,MAAMA,CAAO,CACf,CACF,ECnBA,OAAS,SAAAC,MAAa,6BA0Cf,SAASC,EAAyB,CACvC,OAAAC,EACA,WAAAC,EACA,SAAAC,EACA,UAAAC,CACF,EAA4C,CAC1C,IAAMC,EAAiBN,EAAME,EAAQE,CAAQ,EAC1C,IAAID,EAAYC,CAAQ,EACxB,IAAI,IAAK,CAAC,EACb,OAAOC,IAAc,OACjBH,EAASI,EAAe,OACxBJ,EAASI,EAAe,MAC9B,CCnDO,SAASC,EAAcC,EAAaC,EAAkC,CAC3E,OAAOC,EAAU,gBAAgB,CAAE,IAAAF,EAAK,iBAAAC,CAAiB,CAAC,CAC5D,CCFO,SAASE,EAAcC,EAAaC,EAAkC,CAC3E,OAAOC,EAAU,gBAAgB,CAAE,IAAAF,EAAK,iBAAAC,CAAiB,CAAC,CAC5D","names":["semver","getHyperdrive","options","address","drift","isReadWrite","isReadWriteOptions","version","hyperdriveAbi","semver","ReadWriteHyperdrive_v1_0_14","ReadHyperdrive_v1_0_14","ReadWriteHyperdrive","ReadHyperdrive","fixed","calculateMatureLongYieldAfterFees","flatFee","bondAmount","baseAmountPaid","decimals","poolFee","IHyperdriveRegistry","registryAbi","IHyperdriveFactory","factoryAbi","ReadFactory","ReadClient","debugName","address","epochBlock","rest","factoryAbi","instances","options","count","ReadHyperdrive","ReadRegistry","ReadClient","debugName","address","epochBlock","rest","registryAbi","options","ReadFactory","count","factoryAddress","factoryAddresses","ReadHyperdrive","instanceAddress","factory","instanceAddresses","ReadWriteFactory","ReadFactory","options","address","ReadWriteHyperdrive","ReadWriteRegistry","ReadRegistry","options","address","ReadWriteFactory","count","ReadWriteHyperdrive","instanceAddress","factory","rest","instanceAddresses","UniV3Zap","zapAbi","hyperdriveRewardsAbi","ReadWriteClient","ReadClient","options","fixed","adjustAmountByPercentage","amount","percentage","decimals","direction","slippageAmount","getHprFromApr","apr","positionDuration","hyperwasm","getHprFromApy","apy","positionDuration","hyperwasm"]}

@@ -1,2 +0,6 @@

"use strict";var me=Object.create;var D=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var fe=(s,t)=>{for(var e in t)D(s,e,{get:t[e],enumerable:!0})},kt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ue(t))!ge.call(s,o)&&o!==e&&D(s,o,{get:()=>t[o],enumerable:!(r=he(t,o))||r.enumerable});return s};var be=(s,t,e)=>(e=s!=null?me(le(s)):{},kt(t||!s||!s.__esModule?D(e,"default",{value:s,enumerable:!0}):e,s)),Re=s=>kt(D({},"__esModule",{value:!0}),s);var Ee={};fe(Ee,{ReadErc4626Hyperdrive_v1_0_14:()=>T,ReadEzEthHyperdrive_v1_0_14:()=>j,ReadHyperdrive_v1_0_14:()=>E,ReadLsEthHyperdrive_v1_0_14:()=>Z,ReadMockErc4626Hyperdrive_v1_0_14:()=>q,ReadREthHyperdrive_v1_0_14:()=>et,ReadStEthHyperdrive_v1_0_14:()=>nt,ReadWriteErc4626Hyperdrive_v1_0_14:()=>M,ReadWriteEzEthHyperdrive_v1_0_14:()=>K,ReadWriteHyperdrive_v1_0_14:()=>v,ReadWriteLsEthHyperdrive_v1_0_14:()=>Q,ReadWriteMockErc4626Hyperdrive_v1_0_14:()=>U,ReadWriteREthHyperdrive_v1_0_14:()=>ot,ReadWriteStEthHyperdrive_v1_0_14:()=>st});module.exports=Re(Ee);var ut=require("@delvtech/fixed-point-wasm");var u=require("@delvtech/fixed-point-wasm");var wt=require("@delvtech/drift"),y=class extends wt.DriftError{constructor(t,e){super(t,{...e,prefix:"\u16CB ",name:"Hyperdrive SDK Error"})}};function $(s,t){if(t)return s;throw new y(`Unhandled discriminated union member: ${JSON.stringify(s)}`)}var Tt=require("@delvtech/fixed-point-wasm"),Ht=require("@delvtech/hyperdrive-wasm");function dt({positionDuration:s,baseAmount:t,bondAmount:e}){return(0,Ht.calcAprGivenFixedPrice)({positionDuration:s,price:(0,Tt.fixed)(t).div(e).bigint})}var pt=31536000n,Mt=115792089237316195423570985008687907853269984665640564039457584007913129639935n;var S="0x";var O=class{drift;debugName;constructor({debugName:t,drift:e,earliestBlock:r}){if(this.debugName=t??this.constructor.name,this.drift=e,r){let o=this.drift.contract;this.drift.contract=i=>{let n=o(i),a=n.getEvents;return n.getEvents=async function(c,d){let p={...d},m=p?.fromBlock,l=typeof m=="bigint"&&m<r;return(!m||m==="earliest"||l)&&(p.fromBlock=r),a(c,p)},n}}}};async function A(s,t){let e=await s.getBlock(t);if(!e){let r=t?.blockHash??t?.blockNumber??t?.blockTag;throw new y(`Block${r!==void 0?` ${r}`:""} not found`)}return e}var Lt=require("@delvtech/hyperdrive-artifacts/IHyperdrive"),Wt=Lt.IHyperdrive.abi;function Bt(s){if(s===0)return"LP";if(s===1)return"LONG";if(s===2)return"SHORT";if(s===3)return"WITHDRAWAL_SHARE";throw new y(`parseAssetType(${s}) did not match a valid asset type.`)}function mt(s){let t=s.slice(2),e=Number(t.slice(0,2)),r=Bt(e),o=t.slice(2,64),i=BigInt(parseInt(o,16));return{assetType:r,timestamp:i}}function V(s,t){return s-s%t}var ht=0n;var It=require("@delvtech/fixed-point-wasm");function _t({openVaultSharePrice:s,endingVaultSharePrice:t,bondAmount:e,decimals:r}){return(0,It.fixed)(t-s).mul(e,r).bigint}var Nt=0x0300000000000000000000000000000000000000000000000000000000000000n;var h=be(require("@delvtech/hyperdrive-wasm"),1);var Dt=require("@delvtech/hyperdrive-artifacts/IERC20"),$t=Dt.IERC20.abi;var f=class extends O{contract;constructor({debugName:t="ERC-20 Token",address:e,cache:r,cacheNamespace:o,...i}){super({debugName:t,...i}),this.contract=this.drift.contract({abi:$t,address:e,cache:r,cacheNamespace:o})}get address(){return this.contract.address}get namespace(){return this.contract.cacheNamespace}getName(){return this.contract.read("name")}getSymbol(){return this.contract.read("symbol")}getDecimals(){return this.contract.read("decimals")}getAllowance({owner:t,spender:e,options:r}){return this.contract.read("allowance",{owner:t,spender:e},r)}getBalanceOf({account:t,options:e}){return this.contract.read("balanceOf",{account:t},e)}getTotalSupply(t){return this.contract.read("totalSupply",{},t)}};var R=class s extends O{static address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";address=s.address;constructor({debugName:t="ETH",...e}){super({debugName:t,...e})}async getName(){return"Ethereum"}async getSymbol(){return"ETH"}async getDecimals(){return 18}async getAllowance(){return 2n**256n-1n}async getBalanceOf({account:t,options:e}){return this.drift.getBalance({address:t,...e})}};var b=class extends O{address;contract;zapContractAddress;constructor({debugName:t="Hyperdrive",address:e,cache:r,cacheNamespace:o,drift:i,zapContractAddress:n,...a}){super({debugName:t,drift:i,...a}),this.address=e,this.zapContractAddress=n,this.contract=this.drift.contract({abi:Wt,address:e,cache:r,cacheNamespace:o})}async getKind(){return this.contract.read("kind")}async getVersion(){let t=await this.contract.read("version"),[e,r,o]=t.replace(/^\D*/,"").split(".").map(i=>parseInt(i));return{major:e,minor:r,patch:o,string:t}}async getBaseToken(){let t=await this.contract.read("baseToken");return t===R.address?new R({drift:this.drift}):new f({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new f({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}getDecimals(){return this.contract.read("decimals")}async convertToBase({sharesAmount:t,options:e}){return this.contract.read("convertToBase",{_shareAmount:t},e)}async convertToShares({baseAmount:t,options:e}){return this.contract.read("convertToShares",{_baseAmount:t},e)}async getInitializationBlock(t){let e=await this.contract.getEvents("Initialize",t);if(!e.length||e[0].blockNumber===void 0)throw new y("Pool has not been initialized, no block found.");let r=e[0].blockNumber;return A(this.drift,{blockNumber:r})}async getYieldSourceRate({blockRange:t,options:e}){let r=await A(this.drift,e),o=r.blockNumber-t,{blockNumber:i}=await this.getInitializationBlock();i&&i>o&&(o=i);let n=await A(this.drift,{blockNumber:o}),{vaultSharePrice:a}=await this.getPoolInfo({block:o}),{vaultSharePrice:c}=await this.getPoolInfo(e),d=r.timestamp-n.timestamp;return Vt({startPrice:a,endPrice:c,timeFrame:d})}getCheckpointTime(t={}){return this._getCheckpointTime(t)}async _getCheckpointTime({timestamp:t,blockNumber:e,options:r}={}){let{checkpointDuration:o}=await this.getPoolConfig(r);if(t===void 0){let i=e?{blockNumber:e}:r;t=(await A(this.drift,i)).timestamp}return V(t,o)}async getCheckpoint({checkpointTime:t,timestamp:e,blockNumber:r,options:o}={}){t===void 0&&(t=await this._getCheckpointTime({timestamp:e,blockNumber:r,options:o}));let{lastWeightedSpotPriceUpdateTime:i,vaultSharePrice:n,weightedSpotPrice:a}=await this.contract.read("getCheckpoint",{_checkpointTime:t},o);return{checkpointTime:t,lastWeightedSpotPriceUpdateTime:i,vaultSharePrice:n,weightedSpotPrice:a}}async getCheckpointExposure({checkpointTime:t,blockNumber:e,timestamp:r,options:o}={}){return t===void 0&&(t=await this._getCheckpointTime({blockNumber:e,timestamp:r,options:o})),this.contract.read("getCheckpointExposure",{_checkpointTime:t},o)}getMarketState(t){return this.contract.read("getMarketState",void 0,t)}getPoolConfig(t){return this.contract.read("getPoolConfig",void 0,t)}getPoolInfo(t){return this.contract.read("getPoolInfo",void 0,t)}async getFixedApr(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return h.spotRate({poolConfig:e,poolInfo:r})}async getImpliedRate({bondAmount:t,timestamp:e,variableApy:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),{vaultSharePrice:a}=await this.getCheckpoint({timestamp:e});return a||(a=(await this.getPoolInfo()).vaultSharePrice),h.calcImpliedRate({poolInfo:n,poolConfig:i,bondAmount:t,openVaultSharePrice:a,variableApy:r})}async getIdleLiquidity(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return h.idleShareReservesInBase({poolInfo:r,poolConfig:e})}async getPresentValue(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t),o=h.presentValue({poolInfo:r,poolConfig:e,currentTime:BigInt(Date.now())/1000n});return this.convertToBase({sharesAmount:o,options:t})}async getShortAccruedYield({checkpointTime:t,bondAmount:e,options:r}){let{vaultSharePrice:o}=await this.getCheckpoint({checkpointTime:t,options:r}),{positionDuration:i}=await this.getPoolConfig(r),n=t+i,c=await this.getCheckpointTime({options:r})>=n,d;if(c)d=(await this.getCheckpoint({checkpointTime:n,options:r})).vaultSharePrice;else{let p=await this.getPoolInfo(r);d=p.vaultSharePrice,o!=0n||(o=p.vaultSharePrice)}return _t({openVaultSharePrice:o,endingVaultSharePrice:d,bondAmount:e,decimals:await this.getDecimals()})}async getTradingVolume(t){let{fromBlock:e,toBlock:r}=t||{},o=await this.getLongEvents({fromBlock:e,toBlock:r}),i=await this.getShortEvents({fromBlock:e,toBlock:r}),n=o.reduce((c,{bondAmount:d})=>c+d,0n),a=i.reduce((c,{bondAmount:d})=>c+d,0n);return{longVolume:n,shortVolume:a,totalVolume:n+a}}async getLongPrice(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return h.spotPrice({poolConfig:e,poolInfo:r})}async getLongEvents(t){let e=await this.contract.getEvents("OpenLong",t),r=await this.contract.getEvents("CloseLong",t);return[...e,...r].map(({args:o,eventName:i,blockNumber:n,transactionHash:a})=>{let c=o.asBase?o.amount:(0,u.fixed)(o.amount).mul(o.vaultSharePrice).bigint;return{trader:o.trader,assetId:o.assetId,bondAmount:o.bondAmount,baseAmount:c,eventName:i,blockNumber:n,transactionHash:a}}).sort((o,i)=>Number(o.blockNumber)-Number(i.blockNumber))}async getShortEvents(t){let e=await this.contract.getEvents("OpenShort",t),r=await this.contract.getEvents("CloseShort",t);return[...e,...r].map(({args:o,eventName:i,blockNumber:n,transactionHash:a})=>{let c=o.asBase?o.amount:(0,u.fixed)(o.amount).mul(o.vaultSharePrice).bigint;return{trader:o.trader,assetId:o.assetId,bondAmount:o.bondAmount,baseAmount:c,eventName:i,blockNumber:n,transactionHash:a}}).sort((o,i)=>Number(o.blockNumber)-Number(i.blockNumber))}async getLpEvents(t){let e=await this.contract.getEvents("AddLiquidity",t),r=await this.contract.getEvents("RemoveLiquidity",t),o=await this.contract.getEvents("RedeemWithdrawalShares",t);return{addLiquidity:e,removeLiquidity:r,redeemWithdrawalShares:o}}async getLpApy({fromBlock:t,options:e}){let{blockNumber:r}=await this.getInitializationBlock();r&&r>t&&(t=r);let o=await A(this.drift,e),i=await A(this.drift,{blockNumber:t}),{lpSharePrice:n}=await this.getPoolInfo({block:t}),{lpSharePrice:a}=await this.getPoolInfo(),c=o.timestamp-i.timestamp;return{lpApy:Vt({startPrice:n,endPrice:a,timeFrame:c})}}async getCheckpointEvents(t){return await this.contract.getEvents("CreateCheckpoint",t)}_calcOpenLongs({openLongEvents:t,closeLongEvents:e}){let r=[...t,...e].sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber)),o={};return r.forEach(i=>{let n=i.args.assetId.toString(),a=o[n]||{assetId:i.args.assetId,maturity:i.args.maturityTime,baseAmountPaid:0n,bondAmount:0n},c=i.args.asBase?i.args.amount:(0,u.fixed)(i.args.amount).mul(i.args.vaultSharePrice).bigint;switch(i.eventName){case"OpenLong":o[n]={...a,baseAmountPaid:a.baseAmountPaid+c,bondAmount:a.bondAmount+i.args.bondAmount};return;case"CloseLong":i.args.bondAmount===a.bondAmount?delete o[n]:o[n]={...a,baseAmountPaid:a.baseAmountPaid-c,bondAmount:a.bondAmount-i.args.bondAmount};return;default:$(i,!0)}}),Object.values(o).filter(i=>i.bondAmount)}async getOpenLongPositions({account:t,options:e}){let r=await this.contract.getEvents("TransferSingle",{filter:{to:t},toBlock:e?.block}),o=await this.contract.getEvents("TransferSingle",{filter:{from:t},toBlock:e?.block}),i=r.filter(Ft),n=o.filter(Ft),a=[...i,...n].sort((d,p)=>Number(d.blockNumber)-Number(p.blockNumber)),c={};for(let d of a){let p=c[d.args.id.toString()]??{assetId:d.args.id,maturity:mt(d.data).timestamp,value:0n};if(d.args.to===t)p.value+=d.args.value;else if(d.args.from===t&&(p.value-=d.args.value,p.value===0n)){delete c[d.args.id.toString()];continue}c[d.args.id.toString()]=p}return Object.values(c).filter(d=>d.value)}async getOpenLongDetails({assetId:t,account:e,options:r}){if(!(await this.getOpenLongPositions({account:e,options:r})).find(d=>d.assetId===t))throw new y(`No position with asset id: ${t} found for account ${e}`);let n=await this.contract.getEvents("OpenLong",{filter:{trader:e,assetId:t}}),a=await this.contract.getEvents("CloseLong",{filter:{trader:e,assetId:t}});if(this.zapContractAddress){let d=await this.contract.getEvents("TransferSingle",{filter:{from:e,to:this.zapContractAddress},toBlock:r?.block});if(d.length){let p=d.map(({transactionHash:g})=>g),l=(await this.contract.getEvents("CloseLong",{filter:{trader:this.zapContractAddress,assetId:t},fromBlock:d[0].blockNumber,toBlock:d.at(-1)?.blockNumber})).filter(({transactionHash:g})=>p.includes(g));for(let g of l)a.push(g)}}return this._calcOpenLongs({openLongEvents:n,closeLongEvents:a})[0]}async getOpenLongs({account:t,options:e}){let r=await this.contract.getEvents("OpenLong",{filter:{trader:t},toBlock:e?.block}),o=await this.contract.getEvents("CloseLong",{filter:{trader:t},toBlock:e?.block});return this._calcOpenLongs({openLongEvents:r,closeLongEvents:o})}async getOpenShorts({account:t,options:e}){let{checkpointDuration:r,positionDuration:o}=await this.getPoolConfig(e),i=await this.contract.getEvents("OpenShort",{filter:{trader:t},toBlock:e?.block}),n=await this.contract.getEvents("CloseShort",{filter:{trader:t},toBlock:e?.block});return this._calcOpenShorts({hyperdriveAddress:this.address,checkpointDuration:r,positionDuration:o,openShortEvents:i,closeShortEvents:n})}async _calcOpenShorts({hyperdriveAddress:t,checkpointDuration:e,positionDuration:r,closeShortEvents:o,openShortEvents:i}){let n=[...i,...o].sort((c,d)=>Number(c.blockNumber)-Number(d.blockNumber)),a={};for(let c of n){let d=c.args.assetId.toString(),{timestamp:p}=await A(this.drift,{blockNumber:c.blockNumber});a[d]=a[d]||{hyperdriveAddress:t,assetId:c.args.assetId,maturity:c.args.maturityTime,checkpointTime:V(p,e),openedTimestamp:p,baseAmountPaid:0n,bondAmount:0n,baseProceeds:0n,fixedRatePaid:0n};let m=c.args.asBase?c.args.amount:(0,u.fixed)(c.args.amount).mul(c.args.vaultSharePrice).bigint,{eventName:l}=c;switch(l){case"OpenShort":a[d].baseAmountPaid+=m,a[d].bondAmount+=c.args.bondAmount,a[d].baseProceeds+=c.args.baseProceeds,a[d].fixedRatePaid=dt({positionDuration:r,baseAmount:a[d].baseProceeds,bondAmount:a[d].bondAmount});continue;case"CloseShort":{if(c.args.bondAmount===a[d].bondAmount){delete a[d];continue}a[d].baseAmountPaid-=m,a[d].bondAmount-=c.args.bondAmount,a[d].baseProceeds-=c.args.basePayment,a[d].fixedRatePaid=dt({positionDuration:r,baseAmount:a[d].baseProceeds,bondAmount:a[d].bondAmount});continue}default:$(l,!0)}}return Object.values(a).filter(c=>c.bondAmount)}async getClosedLongs({account:t,options:e}){let r=await this.contract.getEvents("CloseLong",{filter:{trader:t},toBlock:e?.block});return(await Promise.all(r.map(async i=>{let n=i.args.assetId,a=i.args.asBase?i.args.amount:(0,u.fixed)(i.args.amount).mul(i.args.vaultSharePrice).bigint;return{assetId:n,bondAmount:i.args.bondAmount,baseAmount:a,baseAmountPaid:0n,maturity:i.args.maturityTime,closedTimestamp:(await A(this.drift,{blockNumber:i.blockNumber})).timestamp}}))).filter(i=>i.bondAmount)}async getClosedShorts({account:t,options:e}){let r=await this.contract.getEvents("CloseShort",{filter:{trader:t},toBlock:e?.block}),{checkpointDuration:o}=await this.getPoolConfig(e);return(await Promise.all(r.map(async n=>{let{assetId:a,maturityTime:c}=n.args,{timestamp:d}=await A(this.drift,{blockNumber:n.blockNumber}),p=n.args.asBase?n.args.amount:(0,u.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;return{hyperdriveAddress:this.address,assetId:a,bondAmount:n.args.bondAmount,baseAmountReceived:p,maturity:c,closedTimestamp:d,checkpointTime:V(d,o)}}))).filter(n=>n.bondAmount)}async getMaxShort({budget:t,options:e}){let r=await this.getPoolInfo(e),o=await this.getPoolConfig(e),i=await this.getCheckpointExposure({options:e}),{vaultSharePrice:n}=await this.getCheckpoint({options:e}),a=h.maxShort({budget:t,poolInfo:r,poolConfig:o,maxIterations:14,openVaultSharePrice:n,checkpointExposure:i}),c=h.calcOpenShort({poolInfo:r,poolConfig:o,bondAmount:a,openVaultSharePrice:n}),d=await this.convertToShares({baseAmount:c,options:e});return{maxBaseIn:c,maxSharesIn:d,maxBondsOut:a}}async getMaxLong(t){let e=await this.getPoolInfo(t),r=await this.getPoolConfig(t),o=await this.getCheckpointExposure({options:t}),i=h.maxLong({poolInfo:e,poolConfig:r,budget:Mt,checkpointExposure:o}),n=await this.convertToShares({baseAmount:i,options:t}),a=h.calcOpenLong({poolInfo:e,poolConfig:r,baseAmount:i});return{maxBaseIn:i,maxSharesIn:n,maxBondsOut:a}}getLpSharesTotalSupply(t){return this.contract.read("totalSupply",{tokenId:ht},t?.options)}getLpShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:ht,owner:t},e)}async getOpenLpPosition({account:t,asBase:e,options:r}){let o=await this.contract.getEvents("AddLiquidity",{filter:{provider:t},toBlock:r?.block}),i=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},toBlock:r?.block}),n=await this.getDecimals(),{lpShareBalance:a,baseAmountPaid:c}=this._calcOpenLpPosition({addLiquidityEvents:o,removeLiquidityEvents:i});if(!a)return{lpShareBalance:a,baseAmountPaid:c,baseValue:0n,sharesValue:0n};let{proceeds:d,withdrawalShares:p}=await this.previewRemoveLiquidity({lpSharesIn:a,minOutputPerShare:1n,asBase:e,destination:t}),m=e?d:await this.convertToBase({sharesAmount:d}),{lpSharePrice:l}=await this.getPoolInfo(),g=(0,u.fixed)(l,n).mul(p,n).bigint,k=await this.convertToShares({baseAmount:g});return{lpShareBalance:a,baseAmountPaid:c,baseValue:m+g,sharesValue:d+k}}_calcOpenLpPosition({addLiquidityEvents:t,removeLiquidityEvents:e}){let r=[...t,...e].sort((n,a)=>Number(n.blockNumber)-Number(a.blockNumber)),o=0n,i=0n;return r.forEach(n=>{let a=n.args.asBase?n.args.amount:(0,u.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;switch(n.eventName){case"AddLiquidity":i+=n.args.lpAmount,o+=a;return;case"RemoveLiquidity":{if(i-=n.args.lpAmount,i<=0n)o=0n;else{let c=(0,u.fixed)(n.args.withdrawalShareAmount).mul(n.args.lpSharePrice).bigint;o=o-a-c}return}default:$(n,!0)}}),{lpShareBalance:i,baseAmountPaid:o}}async getClosedLpShares({account:t,options:e}){let r=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},toBlock:e?.block});return Promise.all(r.map(async({blockNumber:o,args:i})=>{let{lpAmount:n,withdrawalShareAmount:a,asBase:c,amount:d,lpSharePrice:p}=i,m=c?d:(0,u.fixed)(i.amount).mul(i.vaultSharePrice).bigint;return{lpAmount:n,baseAmount:m,withdrawalShareAmount:a,lpSharePrice:p,closedTimestamp:(await A(this.drift,{blockNumber:o})).timestamp}}))}getWithdrawalShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:Nt,owner:t},e)}async getRedeemedWithdrawalShares({account:t,options:e}){let r=await this.contract.getEvents("RedeemWithdrawalShares",{filter:{provider:t},toBlock:e?.block});return Promise.all(r.map(async({blockNumber:o,args:i})=>{let{withdrawalShareAmount:n,amount:a,asBase:c,vaultSharePrice:d}=i,p=c?i.amount:(0,u.fixed)(a).mul(d).bigint;return{hyperdriveAddress:this.address,withdrawalShareAmount:n,baseAmount:p,redeemedTimestamp:(await A(this.drift,{blockNumber:o})).timestamp}}))}async previewOpenLong({amountIn:t,asBase:e,options:r}){let o=await this.getPoolConfig(r),i=await this.getPoolInfo(r),n=await this.getCheckpointTime({options:r}),a=t;e||(a=await this.convertToBase({sharesAmount:t,options:r}));let c=h.spotPriceAfterLong({poolInfo:i,poolConfig:o,baseAmount:a}),d=h.calcAprGivenFixedPrice({price:c,positionDuration:o.positionDuration}),p=h.calcOpenLong({poolInfo:i,poolConfig:o,baseAmount:a}),m=h.openLongCurveFee({poolInfo:i,poolConfig:o,baseAmount:a});return{maturityTime:n+o.positionDuration,bondProceeds:p,spotPriceAfterOpen:c,spotRateAfterOpen:d,curveFee:m}}async previewOpenShort({amountOfBondsToShort:t,asBase:e,options:r}){let o=await this.getPoolConfig(r),i=await this.getPoolInfo(r),n=await this.getCheckpoint({options:r}),a=await this.getShortAccruedYield({checkpointTime:n.checkpointTime,bondAmount:t,options:r}),c=h.calcOpenShort({poolInfo:i,poolConfig:o,bondAmount:t,openVaultSharePrice:n.vaultSharePrice}),d=(0,u.fixed)(o.positionDuration).div(pt),p=(0,u.fixed)(c).sub(a),m=(0,u.fixed)(t).sub(p),l=p.div(m).div(d).bigint,g=h.spotPriceAfterShort({poolInfo:i,poolConfig:o,bondAmount:t}),k=h.calcAprGivenFixedPrice({price:g,positionDuration:o.positionDuration}),ct=h.openShortCurveFee({poolInfo:i,poolConfig:o,bondAmount:t});return e?{maturityTime:n.checkpointTime+o.positionDuration,traderDeposit:c,spotPriceAfterOpen:g,spotRateAfterOpen:k,curveFee:ct,fixedRatePaid:l}:{maturityTime:n.checkpointTime+o.positionDuration,traderDeposit:await this.convertToShares({baseAmount:c,options:r}),spotPriceAfterOpen:g,spotRateAfterOpen:k,curveFee:await this.convertToShares({baseAmount:ct,options:r}),fixedRatePaid:l}}async getShortBondsGivenDeposit({amountIn:t,asBase:e,tolerance:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=await this.getCheckpoint({options:o}),c=await this.getCheckpointExposure({options:o}),d=t;e||(d=await this.convertToBase({sharesAmount:t,options:o}));let p=h.absoluteMaxShort({poolInfo:n,poolConfig:i,checkpointExposure:c});return h.shortBondsGivenDeposit({poolInfo:n,poolConfig:i,targetBaseAmount:d,absoluteMaxBondAmount:p,openVaultSharePrice:a.vaultSharePrice,maybeTolerance:r})}async previewCloseLong({maturityTime:t,bondAmountIn:e,asBase:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=BigInt(Math.floor(Date.now()/1e3)),c=h.closeLongFlatFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a}),d=h.closeLongCurveFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a}),p=c+d,m=h.calcCloseLong({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a});return r?{amountOut:await this.convertToBase({sharesAmount:m,options:o}),flatPlusCurveFee:await this.convertToBase({sharesAmount:p,options:o})}:{amountOut:m,flatPlusCurveFee:p}}async estimateShortMarketValue({maturityTime:t,asBase:e,shortAmountIn:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=t-i.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:o}),d=BigInt(Math.floor(Date.now()/1e3)),p=n.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:o})).vaultSharePrice);let m=h.calcShortMarketValue({poolInfo:n,poolConfig:i,bondAmount:r,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return e?this.convertToBase({sharesAmount:m,options:o}):m}async previewCloseShort({maturityTime:t,shortAmountIn:e,asBase:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=t-i.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:o}),d=BigInt(Math.floor(Date.now()/1e3)),p=n.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:o})).vaultSharePrice);let m=h.closeShortFlatFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:d}),l=h.closeShortCurveFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:d}),g=m+l,k=h.calcCloseShort({poolInfo:n,poolConfig:i,bondAmount:e,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return r?{amountOut:await this.convertToBase({sharesAmount:k,options:o}),flatPlusCurveFee:await this.convertToBase({sharesAmount:g,options:o})}:{amountOut:k,flatPlusCurveFee:g}}async previewAddLiquidity({contribution:t,minApr:e,minLpSharePrice:r,maxApr:o,asBase:i,options:n}){let a=await this.getPoolConfig(n),c=await this.getPoolInfo(n),d=BigInt(Math.floor(Date.now()/1e3)),p=h.calcAddLiquidity({poolInfo:c,poolConfig:a,currentTime:d,contribution:t,asBase:i,minLpSharePrice:r,minApr:e,maxApr:o}),m=await this.getDecimals(),l=(0,u.fixed)(p,m).mul(c.lpSharePrice,m).bigint,g=i?l:await this.convertToShares({baseAmount:l,options:n});return{lpSharesOut:p,slippagePaid:t-g}}async previewRemoveLiquidity({lpSharesIn:t,minOutputPerShare:e,destination:r,asBase:o,extraData:i=S,options:n}){let{proceeds:a,withdrawalShares:c}=await this.contract.simulateWrite("removeLiquidity",{_lpShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},{...n,from:r});return{proceeds:a,withdrawalShares:c}}async previewRedeemWithdrawalShares({withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:o,extraData:i=S,options:n}){let{proceeds:a,withdrawalSharesRedeemed:c}=await this.contract.simulateWrite("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},n);return{asBase:o,baseProceeds:o?a:await this.convertToBase({sharesAmount:a}),sharesProceeds:o?await this.convertToShares({baseAmount:a}):a,withdrawalSharesRedeemed:c}}};function Vt({startPrice:s,endPrice:t,timeFrame:e}){let r=(0,u.fixed)(t).div(s),o=(0,u.fixed)(e).div(pt);return r.pow((0,u.fixed)(1e18).div(o)).sub(1e18).bigint}function Ft(s){let{assetType:t}=mt(s.data);return t==="LONG"}var E=class extends lt(b){};function lt(s){return class extends s{constructor(...[t]){let{debugName:e="Hyperdrive v1.0.14",...r}=t;super({debugName:e,...r})}async convertToBase({sharesAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),o=await this.getDecimals();return(0,ut.fixed)(t,o).mul(r,o).bigint}async convertToShares({baseAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),o=await this.getDecimals();return(0,ut.fixed)(t,o).div(r).bigint}}}var x=class extends f{constructor(t){super(t)}async approve({spender:t,amount:e,options:r}){return await this.contract.write("approve",{spender:t,amount:e},{...r,onMined:i=>{this.contract.invalidateReadsMatching("allowance"),r?.onMined?.(i)}})}};var P=class extends R{constructor(t){super(t)}async approve(){throw new y("This method is not available for the native ETH token.")}};var C=class extends b{constructor(t){super(t)}async getBaseToken(t){let e=await this.contract.read("baseToken",{},t);return e===P.address?new P({drift:this.drift}):new x({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new x({address:t,drift:this.drift,cacheNamespace:this.contract.cacheNamespace})}async checkpoint({args:{time:t},options:e}){return this.contract.write("checkpoint",{_checkpointTime:BigInt(t),_maxIterations:4n},{...e,onMined:r=>{this.contract.cache.clear(),e?.onMined?.(r)}})}async pause({args:{paused:t},options:e}){return this.contract.write("pause",{_status:t},{...e,onMined:r=>{this.contract.invalidateReadsMatching("getMarketState"),e?.onMined?.(r)}})}async initialize({args:{contribution:t,apr:e,destination:r,asBase:o=!0,extraData:i=S},options:n}){return this.contract.write("initialize",{_apr:e,_contribution:t,_options:{destination:r,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}async openLong({args:{destination:t,amount:e,minBondsOut:r,minVaultSharePrice:o,asBase:i=!0,extraData:n=S},options:a}){return this.contract.write("openLong",{_amount:e,_minOutput:r,_minVaultSharePrice:o,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async openShort({args:{destination:t,bondAmount:e,minVaultSharePrice:r,maxDeposit:o,asBase:i=!0,extraData:n=S},options:a}){return this.contract.write("openShort",{_bondAmount:e,_maxDeposit:o,_minVaultSharePrice:r,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeLong({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:o,asBase:i=!0,extraData:n=S},options:a}){return this.contract.write("closeLong",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:o,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeShort({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:o,asBase:i=!0,extraData:n=S},options:a}){return this.contract.write("closeShort",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:o,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async addLiquidity({args:{destination:t,contribution:e,minApr:r,minLpSharePrice:o,maxApr:i,asBase:n=!0,extraData:a=S},options:c}){return this.contract.write("addLiquidity",{_contribution:e,_minLpSharePrice:o,_minApr:r,_maxApr:i,_options:{destination:t,asBase:n,extraData:a}},{...c,onMined:d=>{this.contract.cache.clear(),c?.onMined?.(d)}})}async removeLiquidity({args:{destination:t,lpSharesIn:e,minOutputPerShare:r,asBase:o=!0,extraData:i=S},options:n}){return this.contract.write("removeLiquidity",{_lpShares:e,_minOutputPerShare:r,_options:{destination:t,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}async redeemWithdrawalShares({args:{withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:o=!0,extraData:i=S},options:n}){return this.contract.write("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}};var v=class extends lt(C){};var zt=require("@delvtech/hyperdrive-artifacts/IERC4626"),qt=require("@delvtech/hyperdrive-artifacts/MockERC4626"),Gt=zt.IERC4626.abi,Yt=qt.MockERC4626.abi;var w=class extends gt(f){};function gt(s){return class extends s{erc4626Contract;constructor(...[t]){let{debugName:e="ERC-4626 Tokenized Vault",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.erc4626Contract=this.drift.contract({abi:Gt,address:r,cache:o,cacheNamespace:i})}getTotalAssets(t){return this.erc4626Contract.read("totalAssets",{},t)}convertToAssets({sharesAmount:t,options:e}){return this.erc4626Contract.read("convertToAssets",{shares:t},e)}convertToShares({assetsAmount:t,options:e}){return this.erc4626Contract.read("convertToShares",{assets:t},e)}}}var F=class extends L(b){};function L(s){return class extends s{constructor(...[t]){let{debugName:e="ERC-4626 Hyperdrive",...r}=t;super({debugName:e,...r})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new w({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var T=class extends L(E){};var z=class extends ft(w){};function ft(s){return class extends s{mockErc4626Contract;constructor(...[t]){let{debugName:e="Mock ERC-4626 Tokenized Vault",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.mockErc4626Contract=this.drift.contract({abi:Yt,address:r,cache:o,cacheNamespace:i})}getRate(t){return this.mockErc4626Contract.read("getRate",{},t)}}}var Ut=class extends W(F){};function W(s){return class extends s{constructor(...[t]){let{debugName:e}=t;super({debugName:e??"Mock ERC-4626 Hyperdrive",...t})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new z({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var q=class extends W(T){};var H=class extends gt(x){};var G=class extends bt(C){};function bt(s){return class extends L(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new H({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var M=class extends bt(v){};var Y=class extends ft(H){mint({receiver:t,sharesAmount:e,options:r}){return this.mockErc4626Contract.write("mint",{_receiver:t,_shares:e},r)}setRate({rate:t,options:e}){return this.mockErc4626Contract.write("setRate",{_rate_:t},e)}};var jt=class extends Rt(G){};function Rt(s){return class extends W(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new Y({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var U=class extends Rt(M){};var Kt=require("@delvtech/hyperdrive-artifacts/IEzETHHyperdrive"),Xt=Kt.IEzETHHyperdrive.abi;var Zt=class extends B(b){};function B(s){return class extends s{ezEthHyperdriveContract;constructor(...[t]){let{debugName:e="EzETH Hyperdrive",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.ezEthHyperdriveContract=this.drift.contract({abi:Xt,address:r,cache:o,cacheNamespace:i})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(){let{vaultSharesToken:t}=await this.getPoolConfig();return new f({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var j=class extends B(E){};var Jt=class extends xt(C){};function xt(s){return class extends B(s){async getBaseToken(){return new P({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new x({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var K=class extends xt(v){};var Qt=require("@delvtech/hyperdrive-artifacts/IRiverV1"),te=Qt.IRiverV1.abi;var X=class extends Et(f){};function Et(s){return class extends s{lsEthContract;constructor(...[t]){let{drift:e,address:r,cache:o,cacheNamespace:i}=t;super({address:r,drift:e,cache:o,cacheNamespace:i}),this.lsEthContract=e.contract({abi:te,address:r,cache:o,cacheNamespace:i})}async getTotalEthSupply(t){return this.lsEthContract.read("totalUnderlyingSupply",{},t)}async getEthBalanceOf({account:t,options:e}){return this.lsEthContract.read("balanceOfUnderlying",{_owner:t},e)}async getEthBalanceFromShares({sharesAmount:t,options:e}){return this.lsEthContract.read("underlyingBalanceFromShares",{_shares:t},e)}async getSharesFromEthBalance({ethBalance:t,options:e}){return this.lsEthContract.read("sharesFromUnderlyingBalance",{_underlyingAssetAmount:t},e)}}}var ee=class extends I(b){};function I(s){return class extends s{constructor(...[t]){let{debugName:e="lsETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new X({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var Z=class extends I(E){};var J=class extends Et(x){};var re=class extends Ct(C){};function Ct(s){return class extends I(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new J({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getBaseToken(){return new P({drift:this.drift})}}}var Q=class extends Ct(v){};var yt=require("@delvtech/fixed-point-wasm");var oe=require("@delvtech/hyperdrive-artifacts/IRocketTokenRETH"),ie=oe.IRocketTokenRETH.abi;var tt=class extends vt(f){};function vt(s){return class extends s{rEthContract;constructor(...[t]){let{drift:e,address:r,cache:o,cacheNamespace:i}=t;super({address:r,drift:e,cache:o,cacheNamespace:i}),this.rEthContract=e.contract({abi:ie,address:r,cache:o,cacheNamespace:i})}async getTotalEthSupply(t){return this.rEthContract.read("getTotalCollateral",{},t)}async getEthBalanceOf({account:t,options:e}){let r=await this.getBalanceOf({account:t,options:e});return this.rEthContract.read("getEthValue",{_rethAmount:r},e)}async getEthValue({rEthAmount:t,options:e}){return this.rEthContract.read("getEthValue",{_rethAmount:t},e)}async getREthValue({ethAmount:t,options:e}){return this.rEthContract.read("getRethValue",{_ethAmount:t},e)}}}var ne=class extends _(b){};function _(s){return class extends s{constructor(...[t]){let{debugName:e="rETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new tt({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getMaxShort({budget:t,options:e}){let r=await super.getMaxShort({budget:t,options:e}),o=await this.getDecimals();return{...r,maxSharesIn:(0,yt.fixed)(r.maxSharesIn,o).mul(1e18-1e12,18).bigint}}async getMaxLong(t){let e=await super.getMaxLong(t),r=await this.getDecimals();return{...e,maxSharesIn:(0,yt.fixed)(e.maxSharesIn,r).mul(1e18-1e12,18).bigint}}}}var et=class extends _(E){};var rt=class extends vt(x){};var ae=class extends Pt(C){};function Pt(s){return class extends _(s){async getBaseToken(){return new P({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new rt({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var ot=class extends Pt(v){};var At=require("@delvtech/fixed-point-wasm");var se=require("@delvtech/hyperdrive-artifacts/ILido"),ce=se.ILido.abi;var it=class extends St(f){};function St(s){return class extends s{stEthContract;constructor(...[t]){let{debugName:e="stETH Token",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.stEthContract=this.drift.contract({abi:ce,address:r,cache:o,cacheNamespace:i})}getSharesOf({account:t,options:e}){return this.stEthContract.read("sharesOf",{_account:t},e)}getPooledEthByShares({sharesAmount:t,options:e}){return this.stEthContract.read("getPooledEthByShares",{_sharesAmount:t},e)}getSharesByPooledEth({ethAmount:t,options:e}){return this.stEthContract.read("getSharesByPooledEth",{_ethAmount:t},e)}}}var de=class extends N(b){constructor(t){super(t)}};function N(s){return class extends s{constructor(...[t]){let{debugName:e="stETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(){let{vaultSharesToken:t}=await this.getPoolConfig();return new it({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getMaxShort({budget:t,options:e}){let r=await super.getMaxShort({budget:t,options:e}),o=await this.getDecimals();return{...r,maxSharesIn:(0,At.fixed)(r.maxSharesIn,o).mul(1e18-1e12,18).bigint}}async getMaxLong(t){let e=await super.getMaxLong(t),r=await this.getDecimals();return{...e,maxSharesIn:(0,At.fixed)(e.maxSharesIn,r).mul(1e18-1e12,18).bigint}}}}var nt=class extends N(E){};var at=class extends St(x){};var pe=class extends Ot(C){};function Ot(s){return class extends N(s){async getBaseToken(){return new P({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new at({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var st=class extends Ot(v){};0&&(module.exports={ReadErc4626Hyperdrive_v1_0_14,ReadEzEthHyperdrive_v1_0_14,ReadHyperdrive_v1_0_14,ReadLsEthHyperdrive_v1_0_14,ReadMockErc4626Hyperdrive_v1_0_14,ReadREthHyperdrive_v1_0_14,ReadStEthHyperdrive_v1_0_14,ReadWriteErc4626Hyperdrive_v1_0_14,ReadWriteEzEthHyperdrive_v1_0_14,ReadWriteHyperdrive_v1_0_14,ReadWriteLsEthHyperdrive_v1_0_14,ReadWriteMockErc4626Hyperdrive_v1_0_14,ReadWriteREthHyperdrive_v1_0_14,ReadWriteStEthHyperdrive_v1_0_14});
"use strict";var At=Object.create;var I=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var Et=Object.getOwnPropertyNames;var xt=Object.getPrototypeOf,Ot=Object.prototype.hasOwnProperty;var H=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),Rt=(s,t)=>{for(var e in t)I(s,e,{get:t[e],enumerable:!0})},X=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Et(t))!Ot.call(s,i)&&i!==e&&I(s,i,{get:()=>t[i],enumerable:!(r=St(t,i))||r.enumerable});return s};var Z=(s,t,e)=>(e=s!=null?At(xt(s)):{},X(t||!s||!s.__esModule?I(e,"default",{value:s,enumerable:!0}):e,s)),Ct=s=>X(I({},"__esModule",{value:!0}),s);var Q=H(($t,j)=>{"use strict";function b(s,t){typeof t=="boolean"&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(s)),this._timeouts=s,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}j.exports=b;b.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)};b.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null};b.prototype.retry=function(s){if(this._timeout&&clearTimeout(this._timeout),!s)return!1;var t=new Date().getTime();if(s&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(s),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(s);var e=this._timeouts.shift();if(e===void 0)if(this._cachedTimeouts)this._errors.splice(0,this._errors.length-1),e=this._cachedTimeouts.slice(-1);else return!1;var r=this;return this._timer=setTimeout(function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout(function(){r._operationTimeoutCb(r._attempts)},r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)},e),this._options.unref&&this._timer.unref(),!0};b.prototype.attempt=function(s,t){this._fn=s,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var e=this;this._operationTimeoutCb&&(this._timeout=setTimeout(function(){e._operationTimeoutCb()},e._operationTimeout)),this._operationStart=new Date().getTime(),this._fn(this._attempts)};b.prototype.try=function(s){console.log("Using RetryOperation.try() is deprecated"),this.attempt(s)};b.prototype.start=function(s){console.log("Using RetryOperation.start() is deprecated"),this.attempt(s)};b.prototype.start=b.prototype.try;b.prototype.errors=function(){return this._errors};b.prototype.attempts=function(){return this._attempts};b.prototype.mainError=function(){if(this._errors.length===0)return null;for(var s={},t=null,e=0,r=0;r<this._errors.length;r++){var i=this._errors[r],n=i.message,o=(s[n]||0)+1;s[n]=o,o>=e&&(t=i,e=o)}return t}});var tt=H(A=>{"use strict";var kt=Q();A.operation=function(s){var t=A.timeouts(s);return new kt(t,{forever:s&&(s.forever||s.retries===1/0),unref:s&&s.unref,maxRetryTime:s&&s.maxRetryTime})};A.timeouts=function(s){if(s instanceof Array)return[].concat(s);var t={retries:10,factor:2,minTimeout:1*1e3,maxTimeout:1/0,randomize:!1};for(var e in s)t[e]=s[e];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],i=0;i<t.retries;i++)r.push(this.createTimeout(i,t));return s&&s.forever&&!r.length&&r.push(this.createTimeout(i,t)),r.sort(function(n,o){return n-o}),r};A.createTimeout=function(s,t){var e=t.randomize?Math.random()+1:1,r=Math.round(e*Math.max(t.minTimeout,1)*Math.pow(t.factor,s));return r=Math.min(r,t.maxTimeout),r};A.wrap=function(s,t,e){if(t instanceof Array&&(e=t,t=null),!e){e=[];for(var r in s)typeof s[r]=="function"&&e.push(r)}for(var i=0;i<e.length;i++){var n=e[i],o=s[n];s[n]=function(c){var m=A.operation(t),u=Array.prototype.slice.call(arguments,1),d=u.pop();u.push(function(p){m.retry(p)||(p&&(arguments[0]=m.mainError()),d.apply(this,arguments))}),m.attempt(function(){c.apply(s,u)})}.bind(s,o),s[n].options=t}}});var it=H((Mt,et)=>{"use strict";et.exports=tt()});var Dt={};Rt(Dt,{ReadHyperdrive_v1_0_14:()=>W,ReadWriteHyperdrive_v1_0_14:()=>N});module.exports=Ct(Dt);var J=require("@delvtech/fixed-point-wasm");var g=require("@delvtech/fixed-point-wasm");var nt=Z(it(),1);var Tt=Object.prototype.toString,Lt=s=>Tt.call(s)==="[object Error]",_t=new Set(["network error","Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Load failed","Network request failed","fetch failed","terminated"]);function F(s){return s&&Lt(s)&&s.name==="TypeError"&&typeof s.message=="string"?s.message==="Load failed"?s.stack===void 0:_t.has(s.message):!1}var V=class extends Error{constructor(t){super(),t instanceof Error?(this.originalError=t,{message:t}=t):(this.originalError=new Error(t),this.originalError.stack=this.stack),this.name="AbortError",this.message=t}},rt=(s,t,e)=>{let r=e.retries-(t-1);return s.attemptNumber=t,s.retriesLeft=r,s};async function G(s,t){return new Promise((e,r)=>{t={...t},t.onFailedAttempt??=()=>{},t.shouldRetry??=()=>!0,t.retries??=10;let i=nt.default.operation(t),n=()=>{i.stop(),r(t.signal?.reason)};t.signal&&!t.signal.aborted&&t.signal.addEventListener("abort",n,{once:!0});let o=()=>{t.signal?.removeEventListener("abort",n),i.stop()};i.attempt(async a=>{try{let c=await s(a);o(),e(c)}catch(c){try{if(!(c instanceof Error))throw new TypeError(`Non-error was thrown: "${c}". You should only throw errors.`);if(c instanceof V)throw c.originalError;if(c instanceof TypeError&&!F(c))throw c;if(rt(c,a,t),await t.shouldRetry(c)||(i.stop(),r(c)),await t.onFailedAttempt(c),!i.retry(c))throw i.mainError()}catch(m){rt(m,a,t),o(),r(m)}}})})}var ot=require("@delvtech/drift"),f=class extends ot.DriftError{constructor(t,e){super(t,{...e,prefix:"\u16CB ",name:"Hyperdrive SDK Error"})}};function B(s,t){if(t)return s;throw new f(`Unhandled discriminated union member: ${JSON.stringify(s)}`)}var at=require("@delvtech/fixed-point-wasm"),st=require("@delvtech/hyperdrive-wasm");function q({positionDuration:s,baseAmount:t,bondAmount:e}){return(0,st.calcAprGivenFixedPrice)({positionDuration:s,price:(0,at.fixed)(t).div(e).bigint})}var z=31536000n,ct=115792089237316195423570985008687907853269984665640564039457584007913129639935n,v="0x";var k=class extends f{constructor(t,e){let{event:r,address:i}=e[0],n=`Failed to fetch "${r}" events from ${i} on chain ${t}.`;n+=`
Requested block ranges:`;for(let o of e)n+=`
- ${o.fromBlock} to ${o.toBlock}`;super(n)}};async function ut({params:s,drift:t,epochBlock:e=0n,retries:r=3,backoff:i=n=>2**n*100}){let n=typeof i=="number"?()=>i:i,o=await t.getChainId(),a=new Map,c=[s];for(let m=0;m<=r;m++){let u=[],d=!1,p=await Promise.all(c.map(async(w,_)=>{let M=[w.fromBlock,w.toBlock].join("-"),x=a.get(M);if(x)return u[_]=[w],x;if(x=await t.cache.getEvents(w),x)return a.set(M,x),u[_]=[w],x;try{let O=await t.adapter.getEvents(w);return a.set(M,O),t.cache.preloadEvents({...w,value:O}),u[_]=[w],O}catch{d=!0;let O=await It(t,w,e);if(!O)throw new k(o,c);return u[_]=O,[]}}));if(!d)return p.flat();let h=new k(o,c);if(m===r)throw h;c=u.flat();let P=h.message;P+=`
Number of attempts left: ${r-m}`,P+=`
Retrying with ${c.length} requests...`,console.warn(P);let C=n(m),yt=Math.floor(C*(.5+Math.random()));await Bt(yt)}throw new k(o,[s])}async function mt(s,t,e=0n){if(typeof t=="bigint")return t;if(t==="earliest")return e;let{number:r}=await s.getBlock(t);return r}async function It(s,{fromBlock:t,toBlock:e,...r},i=0n){if(t===e||(t=await mt(s,t,i),t===void 0)||(e=await mt(s,e,i),e===void 0||t>=e))return null;let n=e-t,o=t+n/2n;return[{fromBlock:t,toBlock:o,...r},{fromBlock:o+1n,toBlock:e,...r}]}function Bt(s){return new Promise(t=>setTimeout(t,s))}var y=class{drift;debugName;constructor({debugName:t,drift:e,epochBlock:r,eventQueryRetries:i=3,eventQueryRetryBackoff:n=o=>2**o*100}){this.debugName=t??this.constructor.name,this.drift=e,e.hooks.on("before:getEvents",async({args:o,resolve:a})=>{let[{fromBlock:c,toBlock:m,...u}]=o,d=await ut({params:{fromBlock:c,toBlock:m,...u},drift:e,epochBlock:r,retries:i,backoff:n});a(d)})}};var dt=require("@delvtech/hyperdrive-artifacts/IHyperdrive"),lt=dt.IHyperdrive.abi;function pt(s){if(s===0)return"LP";if(s===1)return"LONG";if(s===2)return"SHORT";if(s===3)return"WITHDRAWAL_SHARE";throw new f(`parseAssetType(${s}) did not match a valid asset type.`)}function Y(s){let t=s.slice(2),e=Number(t.slice(0,2)),r=pt(e),i=t.slice(2,64),n=BigInt(parseInt(i,16));return{assetType:r,timestamp:n}}function D(s,t){return s-s%t}var U=0n;var ht=require("@delvtech/fixed-point-wasm");function gt({openVaultSharePrice:s,endingVaultSharePrice:t,bondAmount:e,decimals:r}){return(0,ht.fixed)(t-s).mul(e,r).bigint}var ft=0x0300000000000000000000000000000000000000000000000000000000000000n;var l=Z(require("@delvtech/hyperdrive-wasm"),1);var bt=require("@delvtech/hyperdrive-artifacts/IERC20"),vt=bt.IERC20.abi;var S=class extends y{contract;constructor({debugName:t="ERC-20 Token",address:e,epochBlock:r,...i}){super({debugName:t,epochBlock:r,...i}),this.contract=this.drift.contract({abi:vt,address:e,epochBlock:r})}get address(){return this.contract.address}getName(){return this.contract.read("name")}getSymbol(){return this.contract.read("symbol")}getDecimals(){return this.contract.read("decimals")}getAllowance({owner:t,spender:e,options:r}){return this.contract.read("allowance",{owner:t,spender:e},r)}getBalanceOf({account:t,options:e}){return this.contract.read("balanceOf",{account:t},e)}getTotalSupply(t){return this.contract.read("totalSupply",{},t)}};var E=class s extends y{static address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";address=s.address;constructor({debugName:t="ETH",...e}){super({debugName:t,...e})}async getName(){return"Ethereum"}async getSymbol(){return"ETH"}async getDecimals(){return 18}async getAllowance(){return 2n**256n-1n}async getBalanceOf({account:t,options:e}){return this.drift.getBalance({address:t,...e})}};var R=class extends y{address;contract;zapContractAddress;constructor({debugName:t="Hyperdrive",address:e,epochBlock:r,zapContractAddress:i,...n}){super({debugName:t,epochBlock:r,...n}),this.address=e,this.zapContractAddress=i,this.contract=this.drift.contract({abi:lt,address:e,epochBlock:r})}async getKind(){return this.contract.read("kind")}async getVersion(){let t=await this.contract.read("version"),[e,r,i]=t.replace(/^\D*/,"").split(".").map(n=>parseInt(n));return{major:e,minor:r,patch:i,string:t}}async getBaseToken(){let t=await this.contract.read("baseToken");return t===E.address?new E({drift:this.drift}):new S({address:t,drift:this.drift})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new S({address:t,drift:this.drift})}getDecimals(){return this.contract.read("decimals")}async convertToBase({sharesAmount:t,options:e}){return this.contract.read("convertToBase",{_shareAmount:t},e)}async convertToShares({baseAmount:t,options:e}){return this.contract.read("convertToShares",{_baseAmount:t},e)}async getInitializationBlock(t){let r=(await G(async()=>{let i=await this.contract.getEvents("Initialize",t);if(!i.length||i[0].blockNumber===void 0)throw this.contract.cache.clear(),new f(`Pool has not been initialized, no block found. ${this.address}`);return i},{retries:10,onFailedAttempt:async i=>{console.log(`getInitializationBlock failed on Hyperdrive ${this.address}, chainId: ${await this.drift.getChainId()}. There are ${i.retriesLeft} retries left.`)}}))[0].blockNumber;return this.drift.getBlock(r,{throws:!0})}async getYieldSourceRate({blockRange:t,options:e}){let r=await this.drift.getBlock(e?.block,{throws:!0}),i=r.number-t,{number:n}=await this.getInitializationBlock();n&&n>i&&(i=n);let o=await this.drift.getBlock(i,{throws:!0}),{vaultSharePrice:a}=await this.getPoolInfo({block:i}),{vaultSharePrice:c}=await this.getPoolInfo(e),m=r.timestamp-o.timestamp;return Pt({startPrice:a,endPrice:c,timeFrame:m})}getCheckpointTime(t={}){return this._getCheckpointTime(t)}async _getCheckpointTime({timestamp:t,blockNumber:e,options:r}={}){let{checkpointDuration:i}=await this.getPoolConfig(r);return t===void 0&&(t=(await this.drift.getBlock(e??r?.block,{throws:!0})).timestamp),D(t,i)}async getCheckpoint({checkpointTime:t,timestamp:e,blockNumber:r,options:i}={}){t===void 0&&(t=await this._getCheckpointTime({timestamp:e,blockNumber:r,options:i}));let{lastWeightedSpotPriceUpdateTime:n,vaultSharePrice:o,weightedSpotPrice:a}=await this.contract.read("getCheckpoint",{_checkpointTime:t},i);return{checkpointTime:t,lastWeightedSpotPriceUpdateTime:n,vaultSharePrice:o,weightedSpotPrice:a}}async getCheckpointExposure({checkpointTime:t,blockNumber:e,timestamp:r,options:i}={}){return t===void 0&&(t=await this._getCheckpointTime({blockNumber:e,timestamp:r,options:i})),this.contract.read("getCheckpointExposure",{_checkpointTime:t},i)}getMarketState(t){return this.contract.read("getMarketState",void 0,t)}getPoolConfig(t){return this.contract.read("getPoolConfig",void 0,t)}getPoolInfo(t){return this.contract.read("getPoolInfo",void 0,t)}async getFixedApr(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return l.spotRate({poolConfig:e,poolInfo:r})}async getImpliedRate({bondAmount:t,timestamp:e,variableApy:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),{vaultSharePrice:a}=await this.getCheckpoint({timestamp:e});return a||(a=(await this.getPoolInfo()).vaultSharePrice),l.calcImpliedRate({poolInfo:o,poolConfig:n,bondAmount:t,openVaultSharePrice:a,variableApy:r})}async getIdleLiquidity(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return l.idleShareReservesInBase({poolInfo:r,poolConfig:e})}async getPresentValue(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t),i=l.presentValue({poolInfo:r,poolConfig:e,currentTime:BigInt(Date.now())/1000n});return this.convertToBase({sharesAmount:i,options:t})}async getShortAccruedYield({checkpointTime:t,bondAmount:e,options:r}){let{vaultSharePrice:i}=await this.getCheckpoint({checkpointTime:t,options:r}),{positionDuration:n}=await this.getPoolConfig(r),o=t+n,c=await this.getCheckpointTime({options:r})>=o,m;if(c)m=(await this.getCheckpoint({checkpointTime:o,options:r})).vaultSharePrice;else{let u=await this.getPoolInfo(r);m=u.vaultSharePrice,i!=0n||(i=u.vaultSharePrice)}return gt({openVaultSharePrice:i,endingVaultSharePrice:m,bondAmount:e,decimals:await this.getDecimals()})}async getTradingVolume(t){let{fromBlock:e,toBlock:r}=t||{},i=await this.getLongEvents({fromBlock:e,toBlock:r}),n=await this.getShortEvents({fromBlock:e,toBlock:r}),o=i.reduce((c,{bondAmount:m})=>c+m,0n),a=n.reduce((c,{bondAmount:m})=>c+m,0n);return{longVolume:o,shortVolume:a,totalVolume:o+a}}async getLongPrice(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return l.spotPrice({poolConfig:e,poolInfo:r})}async getLongEvents(t){let e=await this.contract.getEvents("OpenLong",t),r=await this.contract.getEvents("CloseLong",t);return[...e,...r].map(({args:i,eventName:n,blockNumber:o,transactionHash:a})=>{let c=i.asBase?i.amount:(0,g.fixed)(i.amount).mul(i.vaultSharePrice).bigint;return{trader:i.trader,assetId:i.assetId,bondAmount:i.bondAmount,baseAmount:c,eventName:n,blockNumber:o,transactionHash:a}}).sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber))}async getShortEvents(t){let e=await this.contract.getEvents("OpenShort",t),r=await this.contract.getEvents("CloseShort",t);return[...e,...r].map(({args:i,eventName:n,blockNumber:o,transactionHash:a})=>{let c=i.asBase?i.amount:(0,g.fixed)(i.amount).mul(i.vaultSharePrice).bigint;return{trader:i.trader,assetId:i.assetId,bondAmount:i.bondAmount,baseAmount:c,eventName:n,blockNumber:o,transactionHash:a}}).sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber))}async getLpEvents(t){let e=await this.contract.getEvents("AddLiquidity",t),r=await this.contract.getEvents("RemoveLiquidity",t),i=await this.contract.getEvents("RedeemWithdrawalShares",t);return{addLiquidity:e,removeLiquidity:r,redeemWithdrawalShares:i}}async getLpApy({fromBlock:t,options:e}){let{number:r}=await this.getInitializationBlock();r&&r>t&&(t=r);let i=await this.drift.getBlock(e?.block,{throws:!0}),n=await this.drift.getBlock(t,{throws:!0}),{lpSharePrice:o}=await this.getPoolInfo({block:t}),{lpSharePrice:a}=await this.getPoolInfo(),c=i.timestamp-n.timestamp;return{lpApy:Pt({startPrice:o,endPrice:a,timeFrame:c})}}async getCheckpointEvents(t){return await this.contract.getEvents("CreateCheckpoint",t)}_calcOpenLongs({openLongEvents:t,closeLongEvents:e}){let r=[...t,...e].sort((n,o)=>Number(n.blockNumber)-Number(o.blockNumber)),i={};return r.forEach(n=>{let o=n.args.assetId.toString(),a=i[o]||{assetId:n.args.assetId,maturity:n.args.maturityTime,baseAmountPaid:0n,bondAmount:0n},c=n.args.asBase?n.args.amount:(0,g.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;switch(n.eventName){case"OpenLong":i[o]={...a,baseAmountPaid:a.baseAmountPaid+c,bondAmount:a.bondAmount+n.args.bondAmount};return;case"CloseLong":n.args.bondAmount===a.bondAmount?delete i[o]:i[o]={...a,baseAmountPaid:a.baseAmountPaid-c,bondAmount:a.bondAmount-n.args.bondAmount};return;default:B(n,!0)}}),Object.values(i).filter(n=>n.bondAmount)}async getOpenLongPositions({account:t,options:e}){let r=await this.contract.getEvents("TransferSingle",{filter:{to:t},...e}),i=await this.contract.getEvents("TransferSingle",{filter:{from:t},...e}),n=r.filter(wt),o=i.filter(wt),a=[...n,...o].sort((m,u)=>Number(m.blockNumber)-Number(u.blockNumber)),c={};for(let m of a){let u=c[m.args.id.toString()]??{assetId:m.args.id,maturity:Y(m.data).timestamp,value:0n};if(m.args.to===t)u.value+=m.args.value;else if(m.args.from===t&&(u.value-=m.args.value,u.value===0n)){delete c[m.args.id.toString()];continue}c[m.args.id.toString()]=u}return Object.values(c).filter(m=>m.value)}async getOpenLongDetails({assetId:t,account:e,options:r}){if(!(await this.getOpenLongPositions({account:e,options:r})).find(m=>m.assetId===t))throw new f(`No position with asset id: ${t} found for account ${e}`);let o=await this.contract.getEvents("OpenLong",{filter:{trader:e,assetId:t},...r}),a=await this.contract.getEvents("CloseLong",{filter:{trader:e,assetId:t},...r});if(this.zapContractAddress){let m=await this.contract.getEvents("TransferSingle",{filter:{from:e,to:this.zapContractAddress},...r});if(m.length){let u=m.map(({transactionHash:h})=>h),p=(await this.contract.getEvents("CloseLong",{filter:{trader:this.zapContractAddress,assetId:t},fromBlock:m[0].blockNumber,toBlock:m.at(-1)?.blockNumber})).filter(({transactionHash:h})=>u.includes(h));for(let h of p)a.push(h)}}return this._calcOpenLongs({openLongEvents:o,closeLongEvents:a})[0]}async getOpenLongs({account:t,options:e}){let r=await this.contract.getEvents("OpenLong",{filter:{trader:t},...e}),i=await this.contract.getEvents("CloseLong",{filter:{trader:t},...e});return this._calcOpenLongs({openLongEvents:r,closeLongEvents:i})}async getOpenShorts({account:t,options:e}){let{checkpointDuration:r,positionDuration:i}=await this.getPoolConfig({block:e?.toBlock}),n=await this.contract.getEvents("OpenShort",{filter:{trader:t},...e}),o=await this.contract.getEvents("CloseShort",{filter:{trader:t},...e});return this._calcOpenShorts({hyperdriveAddress:this.address,checkpointDuration:r,positionDuration:i,openShortEvents:n,closeShortEvents:o})}async _calcOpenShorts({hyperdriveAddress:t,checkpointDuration:e,positionDuration:r,closeShortEvents:i,openShortEvents:n}){let o=[...n,...i].sort((c,m)=>Number(c.blockNumber)-Number(m.blockNumber)),a={};for(let c of o){let m=c.args.assetId.toString(),{timestamp:u}=await this.drift.getBlock(c.blockNumber,{throws:!0});a[m]=a[m]||{hyperdriveAddress:t,assetId:c.args.assetId,maturity:c.args.maturityTime,checkpointTime:D(u,e),openedTimestamp:u,baseAmountPaid:0n,bondAmount:0n,baseProceeds:0n,fixedRatePaid:0n};let d=c.args.asBase?c.args.amount:(0,g.fixed)(c.args.amount).mul(c.args.vaultSharePrice).bigint,{eventName:p}=c;switch(p){case"OpenShort":a[m].baseAmountPaid+=d,a[m].bondAmount+=c.args.bondAmount,a[m].baseProceeds+=c.args.baseProceeds,a[m].fixedRatePaid=q({positionDuration:r,baseAmount:a[m].baseProceeds,bondAmount:a[m].bondAmount});continue;case"CloseShort":{if(c.args.bondAmount===a[m].bondAmount){delete a[m];continue}a[m].baseAmountPaid-=d,a[m].bondAmount-=c.args.bondAmount,a[m].baseProceeds-=c.args.basePayment,a[m].fixedRatePaid=q({positionDuration:r,baseAmount:a[m].baseProceeds,bondAmount:a[m].bondAmount});continue}default:B(p,!0)}}return Object.values(a).filter(c=>c.bondAmount)}async getClosedLongs({account:t,options:e}){let r=await this.contract.getEvents("CloseLong",{filter:{trader:t},...e});return(await Promise.all(r.map(async n=>{let o=n.args.assetId,a=n.args.asBase?n.args.amount:(0,g.fixed)(n.args.amount).mul(n.args.vaultSharePrice).bigint;return{assetId:o,bondAmount:n.args.bondAmount,baseAmount:a,maturity:n.args.maturityTime,closedTimestamp:(await this.drift.getBlock(n.blockNumber,{throws:!0})).timestamp}}))).filter(n=>n.bondAmount)}async getClosedShorts({account:t,options:e}){let r=await this.contract.getEvents("CloseShort",{filter:{trader:t},...e}),{checkpointDuration:i}=await this.getPoolConfig({block:e?.toBlock});return(await Promise.all(r.map(async o=>{let{assetId:a,maturityTime:c}=o.args,{timestamp:m}=await this.drift.getBlock(o.blockNumber,{throws:!0}),u=o.args.asBase?o.args.amount:(0,g.fixed)(o.args.amount).mul(o.args.vaultSharePrice).bigint;return{hyperdriveAddress:this.address,assetId:a,bondAmount:o.args.bondAmount,baseAmountReceived:u,maturity:c,closedTimestamp:m,checkpointTime:D(m,i)}}))).filter(o=>o.bondAmount)}async getMaxShort({budget:t,options:e}){let r=await this.getPoolInfo(e),i=await this.getPoolConfig(e),n=await this.getCheckpointExposure({options:e}),{vaultSharePrice:o}=await this.getCheckpoint({options:e}),a=l.maxShort({budget:t,poolInfo:r,poolConfig:i,maxIterations:14,openVaultSharePrice:o,checkpointExposure:n}),c=l.calcOpenShort({poolInfo:r,poolConfig:i,bondAmount:a,openVaultSharePrice:o}),m=await this.convertToShares({baseAmount:c,options:e});return{maxBaseIn:c,maxSharesIn:m,maxBondsOut:a}}async getMaxLong(t){let e=await this.getPoolInfo(t),r=await this.getPoolConfig(t),i=await this.getCheckpointExposure({options:t}),n=l.maxLong({poolInfo:e,poolConfig:r,budget:ct,checkpointExposure:i}),o=await this.convertToShares({baseAmount:n,options:t}),a=l.calcOpenLong({poolInfo:e,poolConfig:r,baseAmount:n});return{maxBaseIn:n,maxSharesIn:o,maxBondsOut:a}}getLpSharesTotalSupply(t){return this.contract.read("totalSupply",{tokenId:U},t?.options)}getLpShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:U,owner:t},e)}async getOpenLpPosition({account:t,asBase:e,options:r}){let i=await this.contract.getEvents("AddLiquidity",{filter:{provider:t},...r}),n=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},...r}),o=await this.getDecimals(),{lpShareBalance:a,baseAmountPaid:c}=this._calcOpenLpPosition({addLiquidityEvents:i,removeLiquidityEvents:n});if(!a)return{lpShareBalance:a,baseAmountPaid:c,baseValue:0n,sharesValue:0n};let{proceeds:m,withdrawalShares:u}=await this.previewRemoveLiquidity({lpSharesIn:a,minOutputPerShare:1n,asBase:e,destination:t}),d=e?m:await this.convertToBase({sharesAmount:m}),{lpSharePrice:p}=await this.getPoolInfo(),h=(0,g.fixed)(p,o).mul(u,o).bigint,P=await this.convertToShares({baseAmount:h});return{lpShareBalance:a,baseAmountPaid:c,baseValue:d+h,sharesValue:m+P}}_calcOpenLpPosition({addLiquidityEvents:t,removeLiquidityEvents:e}){let r=[...t,...e].sort((o,a)=>Number(o.blockNumber)-Number(a.blockNumber)),i=0n,n=0n;return r.forEach(o=>{let a=o.args.asBase?o.args.amount:(0,g.fixed)(o.args.amount).mul(o.args.vaultSharePrice).bigint;switch(o.eventName){case"AddLiquidity":n+=o.args.lpAmount,i+=a;return;case"RemoveLiquidity":{if(n-=o.args.lpAmount,n<=0n)i=0n;else{let c=(0,g.fixed)(o.args.withdrawalShareAmount).mul(o.args.lpSharePrice).bigint;i=i-a-c}return}default:B(o,!0)}}),{lpShareBalance:n,baseAmountPaid:i}}async getClosedLpShares({account:t,options:e}){let r=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},...e});return Promise.all(r.map(async({blockNumber:i,args:n})=>{let{lpAmount:o,withdrawalShareAmount:a,asBase:c,amount:m,lpSharePrice:u}=n,d=c?m:(0,g.fixed)(n.amount).mul(n.vaultSharePrice).bigint;return{lpAmount:o,baseAmount:d,withdrawalShareAmount:a,lpSharePrice:u,closedTimestamp:(await this.drift.getBlock(i,{throws:!0})).timestamp}}))}getWithdrawalShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:ft,owner:t},e)}async getRedeemedWithdrawalShares({account:t,options:e}){let r=await this.contract.getEvents("RedeemWithdrawalShares",{filter:{provider:t},...e});return Promise.all(r.map(async({blockNumber:i,args:n})=>{let{withdrawalShareAmount:o,amount:a,asBase:c,vaultSharePrice:m}=n,u=c?n.amount:(0,g.fixed)(a).mul(m).bigint;return{hyperdriveAddress:this.address,withdrawalShareAmount:o,baseAmount:u,redeemedTimestamp:(await this.drift.getBlock(i,{throws:!0})).timestamp}}))}async previewOpenLong({amountIn:t,asBase:e,options:r}){let i=await this.getPoolConfig(r),n=await this.getPoolInfo(r),o=await this.getCheckpointTime({options:r}),a=t;e||(a=await this.convertToBase({sharesAmount:t,options:r}));let c=l.spotPriceAfterLong({poolInfo:n,poolConfig:i,baseAmount:a}),m=l.calcAprGivenFixedPrice({price:c,positionDuration:i.positionDuration}),u=l.calcOpenLong({poolInfo:n,poolConfig:i,baseAmount:a}),d=l.openLongCurveFee({poolInfo:n,poolConfig:i,baseAmount:a});return{maturityTime:o+i.positionDuration,bondProceeds:u,spotPriceAfterOpen:c,spotRateAfterOpen:m,curveFee:d}}async previewOpenShort({amountOfBondsToShort:t,asBase:e,options:r}){let i=await this.getPoolConfig(r),n=await this.getPoolInfo(r),o=await this.getCheckpoint({options:r}),a=await this.getShortAccruedYield({checkpointTime:o.checkpointTime,bondAmount:t,options:r}),c=l.calcOpenShort({poolInfo:n,poolConfig:i,bondAmount:t,openVaultSharePrice:o.vaultSharePrice}),m=(0,g.fixed)(i.positionDuration).div(z),u=(0,g.fixed)(c).sub(a),d=(0,g.fixed)(t).sub(u),p=u.div(d).div(m).bigint,h=l.spotPriceAfterShort({poolInfo:n,poolConfig:i,bondAmount:t}),P=l.calcAprGivenFixedPrice({price:h,positionDuration:i.positionDuration}),C=l.openShortCurveFee({poolInfo:n,poolConfig:i,bondAmount:t});return e?{maturityTime:o.checkpointTime+i.positionDuration,traderDeposit:c,spotPriceAfterOpen:h,spotRateAfterOpen:P,curveFee:C,fixedRatePaid:p}:{maturityTime:o.checkpointTime+i.positionDuration,traderDeposit:await this.convertToShares({baseAmount:c,options:r}),spotPriceAfterOpen:h,spotRateAfterOpen:P,curveFee:await this.convertToShares({baseAmount:C,options:r}),fixedRatePaid:p}}async getShortBondsGivenDeposit({amountIn:t,asBase:e,tolerance:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=await this.getCheckpoint({options:i}),c=await this.getCheckpointExposure({options:i}),m=t;e||(m=await this.convertToBase({sharesAmount:t,options:i}));let u=l.absoluteMaxShort({poolInfo:o,poolConfig:n,checkpointExposure:c});return l.shortBondsGivenDeposit({poolInfo:o,poolConfig:n,targetBaseAmount:m,absoluteMaxBondAmount:u,openVaultSharePrice:a.vaultSharePrice,maybeTolerance:r})}async previewCloseLong({maturityTime:t,bondAmountIn:e,asBase:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=BigInt(Math.floor(Date.now()/1e3)),c=l.closeLongFlatFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:a}),m=l.closeLongCurveFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:a}),u=c+m,d=l.calcCloseLong({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:a});return r?{amountOut:await this.convertToBase({sharesAmount:d,options:i}),flatPlusCurveFee:await this.convertToBase({sharesAmount:u,options:i})}:{amountOut:d,flatPlusCurveFee:u}}async estimateShortMarketValue({maturityTime:t,asBase:e,shortAmountIn:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=t-n.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:i}),m=BigInt(Math.floor(Date.now()/1e3)),u=o.vaultSharePrice;t<=m&&(u=(await this.getCheckpoint({timestamp:t,options:i})).vaultSharePrice);let d=l.calcShortMarketValue({poolInfo:o,poolConfig:n,bondAmount:r,openVaultSharePrice:c,closeVaultSharePrice:u,maturityTime:t,currentTime:m});return e?this.convertToBase({sharesAmount:d,options:i}):d}async previewCloseShort({maturityTime:t,shortAmountIn:e,asBase:r,options:i}){let n=await this.getPoolConfig(i),o=await this.getPoolInfo(i),a=t-n.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:i}),m=BigInt(Math.floor(Date.now()/1e3)),u=o.vaultSharePrice;t<=m&&(u=(await this.getCheckpoint({timestamp:t,options:i})).vaultSharePrice);let d=l.closeShortFlatFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:m}),p=l.closeShortCurveFee({poolInfo:o,poolConfig:n,bondAmount:e,maturityTime:t,currentTime:m}),h=d+p,P=l.calcCloseShort({poolInfo:o,poolConfig:n,bondAmount:e,openVaultSharePrice:c,closeVaultSharePrice:u,maturityTime:t,currentTime:m});return r?{amountOut:await this.convertToBase({sharesAmount:P,options:i}),flatPlusCurveFee:await this.convertToBase({sharesAmount:h,options:i})}:{amountOut:P,flatPlusCurveFee:h}}async previewAddLiquidity({contribution:t,minApr:e,minLpSharePrice:r,maxApr:i,asBase:n,options:o}){let a=await this.getPoolConfig(o),c=await this.getPoolInfo(o),m=BigInt(Math.floor(Date.now()/1e3)),u=l.calcAddLiquidity({poolInfo:c,poolConfig:a,currentTime:m,contribution:t,asBase:n,minLpSharePrice:r,minApr:e,maxApr:i}),d=await this.getDecimals(),p=(0,g.fixed)(u,d).mul(c.lpSharePrice,d).bigint,h=n?p:await this.convertToShares({baseAmount:p,options:o});return{lpSharesOut:u,slippagePaid:t-h}}async previewRemoveLiquidity({lpSharesIn:t,minOutputPerShare:e,destination:r,asBase:i,extraData:n=v,options:o}){let{proceeds:a,withdrawalShares:c}=await this.contract.simulateWrite("removeLiquidity",{_lpShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},{...o,from:r});return{proceeds:a,withdrawalShares:c}}async previewRedeemWithdrawalShares({withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:i,extraData:n=v,options:o}){let{proceeds:a,withdrawalSharesRedeemed:c}=await this.contract.simulateWrite("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},o);return{asBase:i,baseProceeds:i?a:await this.convertToBase({sharesAmount:a}),sharesProceeds:i?await this.convertToShares({baseAmount:a}):a,withdrawalSharesRedeemed:c}}};function Pt({startPrice:s,endPrice:t,timeFrame:e}){let r=(0,g.fixed)(t).div(s),i=(0,g.fixed)(e).div(z);return r.pow((0,g.fixed)(1e18).div(i)).sub(1e18).bigint}function wt(s){let{assetType:t}=Y(s.data);return t==="LONG"}var W=class extends K(R){};function K(s){return class extends s{constructor(...[t]){let{debugName:e="Hyperdrive v1.0.14",...r}=t;super({debugName:e,...r})}async convertToBase({sharesAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),i=await this.getDecimals();return(0,J.fixed)(t,i).mul(r,i).bigint}async convertToShares({baseAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),i=await this.getDecimals();return(0,J.fixed)(t,i).div(r).bigint}}}var T=class extends S{constructor(t){super(t)}async approve({spender:t,amount:e,options:r}){return await this.contract.write("approve",{spender:t,amount:e},{...r,onMined:n=>{this.contract.cache.invalidateReadsMatching("allowance"),r?.onMined?.(n)}})}};var L=class extends E{constructor(t){super(t)}async approve(){throw new f("This method is not available for the native ETH token.")}};var $=class extends R{constructor(t){super(t)}async getBaseToken(t){let e=await this.contract.read("baseToken",{},t);return e===L.address?new L({drift:this.drift}):new T({address:e,drift:this.drift})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new T({address:t,drift:this.drift})}async checkpoint({args:{time:t},options:e}){return this.contract.write("checkpoint",{_checkpointTime:BigInt(t),_maxIterations:4n},{...e,onMined:r=>{this.contract.cache.clear(),e?.onMined?.(r)}})}async pause({args:{paused:t},options:e}){return this.contract.write("pause",{_status:t},{...e,onMined:r=>{this.contract.cache.invalidateReadsMatching("getMarketState"),e?.onMined?.(r)}})}async initialize({args:{contribution:t,apr:e,destination:r,asBase:i=!0,extraData:n=v},options:o}){return this.contract.write("initialize",{_apr:e,_contribution:t,_options:{destination:r,asBase:i,extraData:n}},{...o,onMined:a=>{this.contract.cache.clear(),o?.onMined?.(a)}})}async openLong({args:{destination:t,amount:e,minBondsOut:r,minVaultSharePrice:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("openLong",{_amount:e,_minOutput:r,_minVaultSharePrice:i,_options:{destination:t,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async openShort({args:{destination:t,bondAmount:e,minVaultSharePrice:r,maxDeposit:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("openShort",{_bondAmount:e,_maxDeposit:i,_minVaultSharePrice:r,_options:{destination:t,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeLong({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("closeLong",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:i,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeShort({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:i,asBase:n=!0,extraData:o=v},options:a}){return this.contract.write("closeShort",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:i,asBase:n,extraData:o}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async addLiquidity({args:{destination:t,contribution:e,minApr:r,minLpSharePrice:i,maxApr:n,asBase:o=!0,extraData:a=v},options:c}){return this.contract.write("addLiquidity",{_contribution:e,_minLpSharePrice:i,_minApr:r,_maxApr:n,_options:{destination:t,asBase:o,extraData:a}},{...c,onMined:m=>{this.contract.cache.clear(),c?.onMined?.(m)}})}async removeLiquidity({args:{destination:t,lpSharesIn:e,minOutputPerShare:r,asBase:i=!0,extraData:n=v},options:o}){return this.contract.write("removeLiquidity",{_lpShares:e,_minOutputPerShare:r,_options:{destination:t,asBase:i,extraData:n}},{...o,onMined:a=>{this.contract.cache.clear(),o?.onMined?.(a)}})}async redeemWithdrawalShares({args:{withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:i=!0,extraData:n=v},options:o}){return this.contract.write("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:i,extraData:n}},{...o,onMined:a=>{this.contract.cache.clear(),o?.onMined?.(a)}})}};var N=class extends K($){};0&&(module.exports={ReadHyperdrive_v1_0_14,ReadWriteHyperdrive_v1_0_14});
//# sourceMappingURL=v1.0.14.cjs.map

@@ -1,5 +0,5 @@

import { b as ReadHyperdrive, a as ReadWriteHyperdrive, ai as Constructor, aj as ReadErc4626HyperdriveMixin, ak as ReadMockErc4626HyperdriveMixin, al as ReadWriteErc4626HyperdriveMixin, am as ReadWriteMockErc4626HyperdriveMixin, an as ReadEzEthHyperdriveMixin, ao as ReadWriteEzEthHyperdriveMixin, ap as ReadLsEthHyperdriveMixin, aq as ReadWriteLsEthHyperdriveMixin, ar as ReadREthHyperdriveMixin, as as ReadWriteREthHyperdriveMixin, at as ReadStEthHyperdriveMixin, au as ReadWriteStEthHyperdriveMixin } from './ReadWriteStEthHyperdrive-d4HcnlS3.cjs';
import { b as ReadHyperdrive, a as ReadWriteHyperdrive } from './ReadWriteHyperdrive-_j2fcJmj.cjs';
import '@delvtech/drift';
import '@delvtech/hyperdrive-artifacts/IHyperdrive';
import 'abitype';
import '@delvtech/hyperdrive-artifacts/IHyperdrive';

@@ -17,50 +17,2 @@ declare const ReadHyperdrive_v1_0_14_base: typeof ReadHyperdrive;

declare const ReadErc4626Hyperdrive_v1_0_14_base: Constructor<ReadErc4626HyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadErc4626Hyperdrive_v1_0_14 extends ReadErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadMockErc4626Hyperdrive_v1_0_14_base: Constructor<ReadMockErc4626HyperdriveMixin> & typeof ReadErc4626Hyperdrive_v1_0_14;
declare class ReadMockErc4626Hyperdrive_v1_0_14 extends ReadMockErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadWriteErc4626Hyperdrive_v1_0_14_base: Constructor<ReadWriteErc4626HyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteErc4626Hyperdrive_v1_0_14 extends ReadWriteErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadWriteMockErc4626Hyperdrive_v1_0_14_base: Constructor<ReadWriteMockErc4626HyperdriveMixin> & typeof ReadWriteErc4626Hyperdrive_v1_0_14;
declare class ReadWriteMockErc4626Hyperdrive_v1_0_14 extends ReadWriteMockErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadEzEthHyperdrive_v1_0_14_base: Constructor<ReadEzEthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadEzEthHyperdrive_v1_0_14 extends ReadEzEthHyperdrive_v1_0_14_base {
}
declare const ReadWriteEzEthHyperdrive_v1_0_14_base: Constructor<ReadWriteEzEthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteEzEthHyperdrive_v1_0_14 extends ReadWriteEzEthHyperdrive_v1_0_14_base {
}
declare const ReadLsEthHyperdrive_v1_0_14_base: Constructor<ReadLsEthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadLsEthHyperdrive_v1_0_14 extends ReadLsEthHyperdrive_v1_0_14_base {
}
declare const ReadWriteLsEthHyperdrive_v1_0_14_base: Constructor<ReadWriteLsEthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteLsEthHyperdrive_v1_0_14 extends ReadWriteLsEthHyperdrive_v1_0_14_base {
}
declare const ReadREthHyperdrive_v1_0_14_base: Constructor<ReadREthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadREthHyperdrive_v1_0_14 extends ReadREthHyperdrive_v1_0_14_base {
}
declare const ReadWriteREthHyperdrive_v1_0_14_base: Constructor<ReadWriteREthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteREthHyperdrive_v1_0_14 extends ReadWriteREthHyperdrive_v1_0_14_base {
}
declare const ReadStEthHyperdrive_v1_0_14_base: Constructor<ReadStEthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadStEthHyperdrive_v1_0_14 extends ReadStEthHyperdrive_v1_0_14_base {
}
declare const ReadWriteStEthHyperdrive_v1_0_14_base: Constructor<ReadWriteStEthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteStEthHyperdrive_v1_0_14 extends ReadWriteStEthHyperdrive_v1_0_14_base {
}
export { ReadErc4626Hyperdrive_v1_0_14, ReadEzEthHyperdrive_v1_0_14, ReadHyperdrive_v1_0_14, ReadLsEthHyperdrive_v1_0_14, ReadMockErc4626Hyperdrive_v1_0_14, ReadREthHyperdrive_v1_0_14, ReadStEthHyperdrive_v1_0_14, ReadWriteErc4626Hyperdrive_v1_0_14, ReadWriteEzEthHyperdrive_v1_0_14, ReadWriteHyperdrive_v1_0_14, ReadWriteLsEthHyperdrive_v1_0_14, ReadWriteMockErc4626Hyperdrive_v1_0_14, ReadWriteREthHyperdrive_v1_0_14, ReadWriteStEthHyperdrive_v1_0_14 };
export { ReadHyperdrive_v1_0_14, ReadWriteHyperdrive_v1_0_14 };

@@ -1,5 +0,5 @@

import { b as ReadHyperdrive, a as ReadWriteHyperdrive, ai as Constructor, aj as ReadErc4626HyperdriveMixin, ak as ReadMockErc4626HyperdriveMixin, al as ReadWriteErc4626HyperdriveMixin, am as ReadWriteMockErc4626HyperdriveMixin, an as ReadEzEthHyperdriveMixin, ao as ReadWriteEzEthHyperdriveMixin, ap as ReadLsEthHyperdriveMixin, aq as ReadWriteLsEthHyperdriveMixin, ar as ReadREthHyperdriveMixin, as as ReadWriteREthHyperdriveMixin, at as ReadStEthHyperdriveMixin, au as ReadWriteStEthHyperdriveMixin } from './ReadWriteStEthHyperdrive-d4HcnlS3.js';
import { b as ReadHyperdrive, a as ReadWriteHyperdrive } from './ReadWriteHyperdrive-_j2fcJmj.js';
import '@delvtech/drift';
import '@delvtech/hyperdrive-artifacts/IHyperdrive';
import 'abitype';
import '@delvtech/hyperdrive-artifacts/IHyperdrive';

@@ -17,50 +17,2 @@ declare const ReadHyperdrive_v1_0_14_base: typeof ReadHyperdrive;

declare const ReadErc4626Hyperdrive_v1_0_14_base: Constructor<ReadErc4626HyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadErc4626Hyperdrive_v1_0_14 extends ReadErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadMockErc4626Hyperdrive_v1_0_14_base: Constructor<ReadMockErc4626HyperdriveMixin> & typeof ReadErc4626Hyperdrive_v1_0_14;
declare class ReadMockErc4626Hyperdrive_v1_0_14 extends ReadMockErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadWriteErc4626Hyperdrive_v1_0_14_base: Constructor<ReadWriteErc4626HyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteErc4626Hyperdrive_v1_0_14 extends ReadWriteErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadWriteMockErc4626Hyperdrive_v1_0_14_base: Constructor<ReadWriteMockErc4626HyperdriveMixin> & typeof ReadWriteErc4626Hyperdrive_v1_0_14;
declare class ReadWriteMockErc4626Hyperdrive_v1_0_14 extends ReadWriteMockErc4626Hyperdrive_v1_0_14_base {
}
declare const ReadEzEthHyperdrive_v1_0_14_base: Constructor<ReadEzEthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadEzEthHyperdrive_v1_0_14 extends ReadEzEthHyperdrive_v1_0_14_base {
}
declare const ReadWriteEzEthHyperdrive_v1_0_14_base: Constructor<ReadWriteEzEthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteEzEthHyperdrive_v1_0_14 extends ReadWriteEzEthHyperdrive_v1_0_14_base {
}
declare const ReadLsEthHyperdrive_v1_0_14_base: Constructor<ReadLsEthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadLsEthHyperdrive_v1_0_14 extends ReadLsEthHyperdrive_v1_0_14_base {
}
declare const ReadWriteLsEthHyperdrive_v1_0_14_base: Constructor<ReadWriteLsEthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteLsEthHyperdrive_v1_0_14 extends ReadWriteLsEthHyperdrive_v1_0_14_base {
}
declare const ReadREthHyperdrive_v1_0_14_base: Constructor<ReadREthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadREthHyperdrive_v1_0_14 extends ReadREthHyperdrive_v1_0_14_base {
}
declare const ReadWriteREthHyperdrive_v1_0_14_base: Constructor<ReadWriteREthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteREthHyperdrive_v1_0_14 extends ReadWriteREthHyperdrive_v1_0_14_base {
}
declare const ReadStEthHyperdrive_v1_0_14_base: Constructor<ReadStEthHyperdriveMixin> & typeof ReadHyperdrive_v1_0_14;
declare class ReadStEthHyperdrive_v1_0_14 extends ReadStEthHyperdrive_v1_0_14_base {
}
declare const ReadWriteStEthHyperdrive_v1_0_14_base: Constructor<ReadWriteStEthHyperdriveMixin> & typeof ReadWriteHyperdrive_v1_0_14;
declare class ReadWriteStEthHyperdrive_v1_0_14 extends ReadWriteStEthHyperdrive_v1_0_14_base {
}
export { ReadErc4626Hyperdrive_v1_0_14, ReadEzEthHyperdrive_v1_0_14, ReadHyperdrive_v1_0_14, ReadLsEthHyperdrive_v1_0_14, ReadMockErc4626Hyperdrive_v1_0_14, ReadREthHyperdrive_v1_0_14, ReadStEthHyperdrive_v1_0_14, ReadWriteErc4626Hyperdrive_v1_0_14, ReadWriteEzEthHyperdrive_v1_0_14, ReadWriteHyperdrive_v1_0_14, ReadWriteLsEthHyperdrive_v1_0_14, ReadWriteMockErc4626Hyperdrive_v1_0_14, ReadWriteREthHyperdrive_v1_0_14, ReadWriteStEthHyperdrive_v1_0_14 };
export { ReadHyperdrive_v1_0_14, ReadWriteHyperdrive_v1_0_14 };

@@ -1,2 +0,2 @@

import{$ as l,C as y,F as H,I as n,L as c,N as E,R,U as M,Y as W,r as e,s as h,t as o,u as k,z as s}from"./chunk-HKUPLPJB.js";var i=class extends s(e){};var p=class extends y(i){};var t=class extends H(o){};var d=class extends n(t){};var m=class extends c(e){};var x=class extends E(o){};var _=class extends R(e){};var v=class extends M(o){};var a=class extends W(e){};var f=class extends l(o){};export{i as ReadErc4626Hyperdrive_v1_0_14,m as ReadEzEthHyperdrive_v1_0_14,e as ReadHyperdrive_v1_0_14,_ as ReadLsEthHyperdrive_v1_0_14,p as ReadMockErc4626Hyperdrive_v1_0_14,a as ReadREthHyperdrive_v1_0_14,h as ReadStEthHyperdrive_v1_0_14,t as ReadWriteErc4626Hyperdrive_v1_0_14,x as ReadWriteEzEthHyperdrive_v1_0_14,o as ReadWriteHyperdrive_v1_0_14,v as ReadWriteLsEthHyperdrive_v1_0_14,d as ReadWriteMockErc4626Hyperdrive_v1_0_14,f as ReadWriteREthHyperdrive_v1_0_14,k as ReadWriteStEthHyperdrive_v1_0_14};
import{m as e,n as r}from"./chunk-GYQBJEPF.js";export{e as ReadHyperdrive_v1_0_14,r as ReadWriteHyperdrive_v1_0_14};
//# sourceMappingURL=v1.0.14.js.map

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/hyperdrive/erc4626/v1.0.14/ReadErc4626Hyperdrive_v1_0_14.ts","../src/hyperdrive/erc4626/v1.0.14/ReadMockErc4626Hyperdrive_v1_0_14.ts","../src/hyperdrive/erc4626/v1.0.14/ReadWriteErc4626Hyperdrive_v1_0_14.ts","../src/hyperdrive/erc4626/v1.0.14/ReadWriteMockErc4626Hyperdrive_v1_0_14.ts","../src/hyperdrive/ezeth/v1.0.14/ReadEzEthHyperdrive_v1_0_14.ts","../src/hyperdrive/ezeth/v1.0.14/ReadWriteEzEthHyperdrive_v1_0_14.ts","../src/hyperdrive/lseth/v1.0.14/ReadLsEthHyperdrive_v1_0_14.ts","../src/hyperdrive/lseth/v1.0.14/ReadWriteLsEthHyperdrive_v1_0_14.ts","../src/hyperdrive/reth/v1.0.14/ReadREthHyperdrive_v1_0_14.ts","../src/hyperdrive/reth/v1.0.14/ReadWriteREthHyperdrive_v1_0_14.ts"],"sourcesContent":["import { readErc4626HyperdriveMixin } from \"src/hyperdrive/erc4626/ReadErc4626Hyperdrive\";\nimport { ReadHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadHyperdrive_v1_0_14\";\n\nexport class ReadErc4626Hyperdrive_v1_0_14 extends readErc4626HyperdriveMixin(\n ReadHyperdrive_v1_0_14,\n) {}\n","import { readMockErc4626HyperdriveMixin } from \"src/hyperdrive/erc4626/ReadMockErc4626Hyperdrive\";\nimport { ReadErc4626Hyperdrive_v1_0_14 } from \"src/hyperdrive/erc4626/v1.0.14/ReadErc4626Hyperdrive_v1_0_14\";\n\nexport class ReadMockErc4626Hyperdrive_v1_0_14 extends readMockErc4626HyperdriveMixin(\n ReadErc4626Hyperdrive_v1_0_14,\n) {}\n","import { readWriteErc4626HyperdriveMixin } from \"src/hyperdrive/erc4626/ReadWriteErc4626Hyperdrive\";\nimport { ReadWriteHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadWriteHyperdrive_v1_0_14\";\n\nexport class ReadWriteErc4626Hyperdrive_v1_0_14 extends readWriteErc4626HyperdriveMixin(\n ReadWriteHyperdrive_v1_0_14,\n) {}\n","import { readWriteMockErc4626HyperdriveMixin } from \"src/hyperdrive/erc4626/ReadWriteMockErc4626Hyperdrive\";\nimport { ReadWriteErc4626Hyperdrive_v1_0_14 } from \"src/hyperdrive/erc4626/v1.0.14/ReadWriteErc4626Hyperdrive_v1_0_14\";\n\nexport class ReadWriteMockErc4626Hyperdrive_v1_0_14 extends readWriteMockErc4626HyperdriveMixin(\n ReadWriteErc4626Hyperdrive_v1_0_14,\n) {}\n","import { readEzEthHyperdriveMixin } from \"src/hyperdrive/ezeth/ReadEzEthHyperdrive\";\nimport { ReadHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadHyperdrive_v1_0_14\";\n\nexport class ReadEzEthHyperdrive_v1_0_14 extends readEzEthHyperdriveMixin(\n ReadHyperdrive_v1_0_14,\n) {}\n","import { readWriteEzEthHyperdriveMixin } from \"src/hyperdrive/ezeth/ReadWriteEzEthHyperdrive\";\nimport { ReadWriteHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadWriteHyperdrive_v1_0_14\";\n\nexport class ReadWriteEzEthHyperdrive_v1_0_14 extends readWriteEzEthHyperdriveMixin(\n ReadWriteHyperdrive_v1_0_14,\n) {}\n","import { readLsEthHyperdriveMixin } from \"src/hyperdrive/lseth/ReadLsEthHyperdrive\";\nimport { ReadHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadHyperdrive_v1_0_14\";\n\nexport class ReadLsEthHyperdrive_v1_0_14 extends readLsEthHyperdriveMixin(\n ReadHyperdrive_v1_0_14,\n) {}\n","import { readWriteLsEthHyperdriveMixin } from \"src/hyperdrive/lseth/ReadWriteLsEthHyperdrive\";\nimport { ReadWriteHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadWriteHyperdrive_v1_0_14\";\n\nexport class ReadWriteLsEthHyperdrive_v1_0_14 extends readWriteLsEthHyperdriveMixin(\n ReadWriteHyperdrive_v1_0_14,\n) {}\n","import { readREthHyperdriveMixin } from \"src/hyperdrive/reth/ReadREthHyperdrive\";\nimport { ReadHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadHyperdrive_v1_0_14\";\n\nexport class ReadREthHyperdrive_v1_0_14 extends readREthHyperdriveMixin(\n ReadHyperdrive_v1_0_14,\n) {}\n","import { readWriteREthHyperdriveMixin } from \"src/hyperdrive/reth/ReadWriteREthHyperdrive\";\nimport { ReadWriteHyperdrive_v1_0_14 } from \"src/hyperdrive/v1.0.14/ReadWriteHyperdrive_v1_0_14\";\n\nexport class ReadWriteREthHyperdrive_v1_0_14 extends readWriteREthHyperdriveMixin(\n ReadWriteHyperdrive_v1_0_14,\n) {}\n"],"mappings":"8HAGO,IAAMA,EAAN,cAA4CC,EACjDC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAAgDC,EACrDC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAAiDC,EACtDC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAAqDC,EAC1DC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAA0CC,EAC/CC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAA+CC,EACpDC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAA0CC,EAC/CC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAA+CC,EACpDC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAAyCC,EAC9CC,CACF,CAAE,CAAC,ECFI,IAAMC,EAAN,cAA8CC,EACnDC,CACF,CAAE,CAAC","names":["ReadErc4626Hyperdrive_v1_0_14","readErc4626HyperdriveMixin","ReadHyperdrive_v1_0_14","ReadMockErc4626Hyperdrive_v1_0_14","readMockErc4626HyperdriveMixin","ReadErc4626Hyperdrive_v1_0_14","ReadWriteErc4626Hyperdrive_v1_0_14","readWriteErc4626HyperdriveMixin","ReadWriteHyperdrive_v1_0_14","ReadWriteMockErc4626Hyperdrive_v1_0_14","readWriteMockErc4626HyperdriveMixin","ReadWriteErc4626Hyperdrive_v1_0_14","ReadEzEthHyperdrive_v1_0_14","readEzEthHyperdriveMixin","ReadHyperdrive_v1_0_14","ReadWriteEzEthHyperdrive_v1_0_14","readWriteEzEthHyperdriveMixin","ReadWriteHyperdrive_v1_0_14","ReadLsEthHyperdrive_v1_0_14","readLsEthHyperdriveMixin","ReadHyperdrive_v1_0_14","ReadWriteLsEthHyperdrive_v1_0_14","readWriteLsEthHyperdriveMixin","ReadWriteHyperdrive_v1_0_14","ReadREthHyperdrive_v1_0_14","readREthHyperdriveMixin","ReadHyperdrive_v1_0_14","ReadWriteREthHyperdrive_v1_0_14","readWriteREthHyperdriveMixin","ReadWriteHyperdrive_v1_0_14"]}
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
{
"name": "@delvtech/hyperdrive-js",
"version": "0.0.2",
"license": "AGPL-3.0",
"version": "1.0.0",
"description": "TypeScript SDK for the Hyperdrive AMM.",
"license": "Apache-2.0",
"author": "DELV (https://github.com/delvtech)",
"repository": {
"type": "git",
"url": "git+https://github.com/delvtech/hyperdrive-frontend.git",
"directory": "packages/hyperdrive-js"
},
"type": "module",
"sideEffects": false,
"exports": {
".": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./v1.0.14": {
"require": {
"types": "./dist/v1.0.14.d.cts",
"default": "./dist/v1.0.14.cjs"
},
"import": {
"types": "./dist/v1.0.14.d.ts",
"default": "./dist/v1.0.14.js"
}
},
"./package.json": "./package.json"
},
"scripts": {

@@ -14,7 +45,7 @@ "build": "tsup",

"peerDependencies": {
"@delvtech/drift": "^0.0.1-beta.11"
"@delvtech/drift": "^1.0.0"
},
"dependencies": {
"@delvtech/fixed-point-wasm": "^0.0.8",
"@delvtech/hyperdrive-artifacts": "^1.0.20",
"@delvtech/hyperdrive-artifacts": "^1.0.21",
"@delvtech/hyperdrive-wasm": "^0.16.1",

@@ -26,3 +57,3 @@ "lodash.groupby": "^4.6.0",

"devDependencies": {
"@delvtech/drift": "^0.0.1-beta.11",
"@delvtech/drift": "^1.0.0",
"@hyperdrive/eslint-config": "*",

@@ -37,2 +68,3 @@ "@hyperdrive/prettier-config": "*",

"prettier": "3.3.3",
"p-retry": "^6.2.1",
"prettier-plugin-organize-imports": "4.0.0",

@@ -42,24 +74,22 @@ "sinon": "^18.0.0",

"tsup": "^8.2.3",
"typescript": "^5.5.4",
"typescript": "^5.9.2",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.0.4"
},
"main": "dist/index.js",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {
".": [
"./dist/index.d.ts"
],
"v1.0.14": [
"./dist/v1.0.14.js"
]
}
},
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./v1.0.14": {
"types": "./dist/v1.0.14.d.ts",
"default": "./dist/v1.0.14.js",
"require": "./dist/v1.0.14.cjs"
},
"./package.json": "./package.json"
},
"publishConfig": {

@@ -66,0 +96,0 @@ "access": "public"

import{DriftError as It}from"@delvtech/drift";var x=class extends It{constructor(t,e){super(t,{...e,prefix:"\u16CB ",name:"Hyperdrive SDK Error"})}};import{IHyperdrive as Nt}from"@delvtech/hyperdrive-artifacts/IHyperdrive";var st=Nt.abi;import{fixed as _t}from"@delvtech/fixed-point-wasm";import{calcAprGivenFixedPrice as Dt}from"@delvtech/hyperdrive-wasm";function G({positionDuration:s,baseAmount:t,bondAmount:e}){return Dt({positionDuration:s,price:_t(t).div(e).bigint})}var S=class{drift;debugName;constructor({debugName:t,drift:e,earliestBlock:r}){if(this.debugName=t??this.constructor.name,this.drift=e,r){let o=this.drift.contract;this.drift.contract=i=>{let n=o(i),a=n.getEvents;return n.getEvents=async function(c,d){let p={...d},m=p?.fromBlock,l=typeof m=="bigint"&&m<r;return(!m||m==="earliest"||l)&&(p.fromBlock=r),a(c,p)},n}}}};import{IERC20 as $t}from"@delvtech/hyperdrive-artifacts/IERC20";var ct=$t.abi;var b=class extends S{contract;constructor({debugName:t="ERC-20 Token",address:e,cache:r,cacheNamespace:o,...i}){super({debugName:t,...i}),this.contract=this.drift.contract({abi:ct,address:e,cache:r,cacheNamespace:o})}get address(){return this.contract.address}get namespace(){return this.contract.cacheNamespace}getName(){return this.contract.read("name")}getSymbol(){return this.contract.read("symbol")}getDecimals(){return this.contract.read("decimals")}getAllowance({owner:t,spender:e,options:r}){return this.contract.read("allowance",{owner:t,spender:e},r)}getBalanceOf({account:t,options:e}){return this.contract.read("balanceOf",{account:t},e)}getTotalSupply(t){return this.contract.read("totalSupply",{},t)}};var R=class s extends S{static address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";address=s.address;constructor({debugName:t="ETH",...e}){super({debugName:t,...e})}async getName(){return"Ethereum"}async getSymbol(){return"ETH"}async getDecimals(){return 18}async getAllowance(){return 2n**256n-1n}async getBalanceOf({account:t,options:e}){return this.drift.getBalance({address:t,...e})}};import{fixed as u}from"@delvtech/fixed-point-wasm";function T(s,t){if(t)return s;throw new x(`Unhandled discriminated union member: ${JSON.stringify(s)}`)}var Y=31536000n,dt=115792089237316195423570985008687907853269984665640564039457584007913129639935n;var v="0x";async function P(s,t){let e=await s.getBlock(t);if(!e){let r=t?.blockHash??t?.blockNumber??t?.blockTag;throw new x(`Block${r!==void 0?` ${r}`:""} not found`)}return e}function pt(s){if(s===0)return"LP";if(s===1)return"LONG";if(s===2)return"SHORT";if(s===3)return"WITHDRAWAL_SHARE";throw new x(`parseAssetType(${s}) did not match a valid asset type.`)}function U(s){let t=s.slice(2),e=Number(t.slice(0,2)),r=pt(e),o=t.slice(2,64),i=BigInt(parseInt(o,16));return{assetType:r,timestamp:i}}function H(s,t){return s-s%t}var j=0n;import{fixed as Vt}from"@delvtech/fixed-point-wasm";function mt({openVaultSharePrice:s,endingVaultSharePrice:t,bondAmount:e,decimals:r}){return Vt(t-s).mul(e,r).bigint}var ht=0x0300000000000000000000000000000000000000000000000000000000000000n;import*as h from"@delvtech/hyperdrive-wasm";var f=class extends S{address;contract;zapContractAddress;constructor({debugName:t="Hyperdrive",address:e,cache:r,cacheNamespace:o,drift:i,zapContractAddress:n,...a}){super({debugName:t,drift:i,...a}),this.address=e,this.zapContractAddress=n,this.contract=this.drift.contract({abi:st,address:e,cache:r,cacheNamespace:o})}async getKind(){return this.contract.read("kind")}async getVersion(){let t=await this.contract.read("version"),[e,r,o]=t.replace(/^\D*/,"").split(".").map(i=>parseInt(i));return{major:e,minor:r,patch:o,string:t}}async getBaseToken(){let t=await this.contract.read("baseToken");return t===R.address?new R({drift:this.drift}):new b({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new b({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}getDecimals(){return this.contract.read("decimals")}async convertToBase({sharesAmount:t,options:e}){return this.contract.read("convertToBase",{_shareAmount:t},e)}async convertToShares({baseAmount:t,options:e}){return this.contract.read("convertToShares",{_baseAmount:t},e)}async getInitializationBlock(t){let e=await this.contract.getEvents("Initialize",t);if(!e.length||e[0].blockNumber===void 0)throw new x("Pool has not been initialized, no block found.");let r=e[0].blockNumber;return P(this.drift,{blockNumber:r})}async getYieldSourceRate({blockRange:t,options:e}){let r=await P(this.drift,e),o=r.blockNumber-t,{blockNumber:i}=await this.getInitializationBlock();i&&i>o&&(o=i);let n=await P(this.drift,{blockNumber:o}),{vaultSharePrice:a}=await this.getPoolInfo({block:o}),{vaultSharePrice:c}=await this.getPoolInfo(e),d=r.timestamp-n.timestamp;return ut({startPrice:a,endPrice:c,timeFrame:d})}getCheckpointTime(t={}){return this._getCheckpointTime(t)}async _getCheckpointTime({timestamp:t,blockNumber:e,options:r}={}){let{checkpointDuration:o}=await this.getPoolConfig(r);if(t===void 0){let i=e?{blockNumber:e}:r;t=(await P(this.drift,i)).timestamp}return H(t,o)}async getCheckpoint({checkpointTime:t,timestamp:e,blockNumber:r,options:o}={}){t===void 0&&(t=await this._getCheckpointTime({timestamp:e,blockNumber:r,options:o}));let{lastWeightedSpotPriceUpdateTime:i,vaultSharePrice:n,weightedSpotPrice:a}=await this.contract.read("getCheckpoint",{_checkpointTime:t},o);return{checkpointTime:t,lastWeightedSpotPriceUpdateTime:i,vaultSharePrice:n,weightedSpotPrice:a}}async getCheckpointExposure({checkpointTime:t,blockNumber:e,timestamp:r,options:o}={}){return t===void 0&&(t=await this._getCheckpointTime({blockNumber:e,timestamp:r,options:o})),this.contract.read("getCheckpointExposure",{_checkpointTime:t},o)}getMarketState(t){return this.contract.read("getMarketState",void 0,t)}getPoolConfig(t){return this.contract.read("getPoolConfig",void 0,t)}getPoolInfo(t){return this.contract.read("getPoolInfo",void 0,t)}async getFixedApr(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return h.spotRate({poolConfig:e,poolInfo:r})}async getImpliedRate({bondAmount:t,timestamp:e,variableApy:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),{vaultSharePrice:a}=await this.getCheckpoint({timestamp:e});return a||(a=(await this.getPoolInfo()).vaultSharePrice),h.calcImpliedRate({poolInfo:n,poolConfig:i,bondAmount:t,openVaultSharePrice:a,variableApy:r})}async getIdleLiquidity(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return h.idleShareReservesInBase({poolInfo:r,poolConfig:e})}async getPresentValue(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t),o=h.presentValue({poolInfo:r,poolConfig:e,currentTime:BigInt(Date.now())/1000n});return this.convertToBase({sharesAmount:o,options:t})}async getShortAccruedYield({checkpointTime:t,bondAmount:e,options:r}){let{vaultSharePrice:o}=await this.getCheckpoint({checkpointTime:t,options:r}),{positionDuration:i}=await this.getPoolConfig(r),n=t+i,c=await this.getCheckpointTime({options:r})>=n,d;if(c)d=(await this.getCheckpoint({checkpointTime:n,options:r})).vaultSharePrice;else{let p=await this.getPoolInfo(r);d=p.vaultSharePrice,o!=0n||(o=p.vaultSharePrice)}return mt({openVaultSharePrice:o,endingVaultSharePrice:d,bondAmount:e,decimals:await this.getDecimals()})}async getTradingVolume(t){let{fromBlock:e,toBlock:r}=t||{},o=await this.getLongEvents({fromBlock:e,toBlock:r}),i=await this.getShortEvents({fromBlock:e,toBlock:r}),n=o.reduce((c,{bondAmount:d})=>c+d,0n),a=i.reduce((c,{bondAmount:d})=>c+d,0n);return{longVolume:n,shortVolume:a,totalVolume:n+a}}async getLongPrice(t){let e=await this.getPoolConfig(t),r=await this.getPoolInfo(t);return h.spotPrice({poolConfig:e,poolInfo:r})}async getLongEvents(t){let e=await this.contract.getEvents("OpenLong",t),r=await this.contract.getEvents("CloseLong",t);return[...e,...r].map(({args:o,eventName:i,blockNumber:n,transactionHash:a})=>{let c=o.asBase?o.amount:u(o.amount).mul(o.vaultSharePrice).bigint;return{trader:o.trader,assetId:o.assetId,bondAmount:o.bondAmount,baseAmount:c,eventName:i,blockNumber:n,transactionHash:a}}).sort((o,i)=>Number(o.blockNumber)-Number(i.blockNumber))}async getShortEvents(t){let e=await this.contract.getEvents("OpenShort",t),r=await this.contract.getEvents("CloseShort",t);return[...e,...r].map(({args:o,eventName:i,blockNumber:n,transactionHash:a})=>{let c=o.asBase?o.amount:u(o.amount).mul(o.vaultSharePrice).bigint;return{trader:o.trader,assetId:o.assetId,bondAmount:o.bondAmount,baseAmount:c,eventName:i,blockNumber:n,transactionHash:a}}).sort((o,i)=>Number(o.blockNumber)-Number(i.blockNumber))}async getLpEvents(t){let e=await this.contract.getEvents("AddLiquidity",t),r=await this.contract.getEvents("RemoveLiquidity",t),o=await this.contract.getEvents("RedeemWithdrawalShares",t);return{addLiquidity:e,removeLiquidity:r,redeemWithdrawalShares:o}}async getLpApy({fromBlock:t,options:e}){let{blockNumber:r}=await this.getInitializationBlock();r&&r>t&&(t=r);let o=await P(this.drift,e),i=await P(this.drift,{blockNumber:t}),{lpSharePrice:n}=await this.getPoolInfo({block:t}),{lpSharePrice:a}=await this.getPoolInfo(),c=o.timestamp-i.timestamp;return{lpApy:ut({startPrice:n,endPrice:a,timeFrame:c})}}async getCheckpointEvents(t){return await this.contract.getEvents("CreateCheckpoint",t)}_calcOpenLongs({openLongEvents:t,closeLongEvents:e}){let r=[...t,...e].sort((i,n)=>Number(i.blockNumber)-Number(n.blockNumber)),o={};return r.forEach(i=>{let n=i.args.assetId.toString(),a=o[n]||{assetId:i.args.assetId,maturity:i.args.maturityTime,baseAmountPaid:0n,bondAmount:0n},c=i.args.asBase?i.args.amount:u(i.args.amount).mul(i.args.vaultSharePrice).bigint;switch(i.eventName){case"OpenLong":o[n]={...a,baseAmountPaid:a.baseAmountPaid+c,bondAmount:a.bondAmount+i.args.bondAmount};return;case"CloseLong":i.args.bondAmount===a.bondAmount?delete o[n]:o[n]={...a,baseAmountPaid:a.baseAmountPaid-c,bondAmount:a.bondAmount-i.args.bondAmount};return;default:T(i,!0)}}),Object.values(o).filter(i=>i.bondAmount)}async getOpenLongPositions({account:t,options:e}){let r=await this.contract.getEvents("TransferSingle",{filter:{to:t},toBlock:e?.block}),o=await this.contract.getEvents("TransferSingle",{filter:{from:t},toBlock:e?.block}),i=r.filter(lt),n=o.filter(lt),a=[...i,...n].sort((d,p)=>Number(d.blockNumber)-Number(p.blockNumber)),c={};for(let d of a){let p=c[d.args.id.toString()]??{assetId:d.args.id,maturity:U(d.data).timestamp,value:0n};if(d.args.to===t)p.value+=d.args.value;else if(d.args.from===t&&(p.value-=d.args.value,p.value===0n)){delete c[d.args.id.toString()];continue}c[d.args.id.toString()]=p}return Object.values(c).filter(d=>d.value)}async getOpenLongDetails({assetId:t,account:e,options:r}){if(!(await this.getOpenLongPositions({account:e,options:r})).find(d=>d.assetId===t))throw new x(`No position with asset id: ${t} found for account ${e}`);let n=await this.contract.getEvents("OpenLong",{filter:{trader:e,assetId:t}}),a=await this.contract.getEvents("CloseLong",{filter:{trader:e,assetId:t}});if(this.zapContractAddress){let d=await this.contract.getEvents("TransferSingle",{filter:{from:e,to:this.zapContractAddress},toBlock:r?.block});if(d.length){let p=d.map(({transactionHash:g})=>g),l=(await this.contract.getEvents("CloseLong",{filter:{trader:this.zapContractAddress,assetId:t},fromBlock:d[0].blockNumber,toBlock:d.at(-1)?.blockNumber})).filter(({transactionHash:g})=>p.includes(g));for(let g of l)a.push(g)}}return this._calcOpenLongs({openLongEvents:n,closeLongEvents:a})[0]}async getOpenLongs({account:t,options:e}){let r=await this.contract.getEvents("OpenLong",{filter:{trader:t},toBlock:e?.block}),o=await this.contract.getEvents("CloseLong",{filter:{trader:t},toBlock:e?.block});return this._calcOpenLongs({openLongEvents:r,closeLongEvents:o})}async getOpenShorts({account:t,options:e}){let{checkpointDuration:r,positionDuration:o}=await this.getPoolConfig(e),i=await this.contract.getEvents("OpenShort",{filter:{trader:t},toBlock:e?.block}),n=await this.contract.getEvents("CloseShort",{filter:{trader:t},toBlock:e?.block});return this._calcOpenShorts({hyperdriveAddress:this.address,checkpointDuration:r,positionDuration:o,openShortEvents:i,closeShortEvents:n})}async _calcOpenShorts({hyperdriveAddress:t,checkpointDuration:e,positionDuration:r,closeShortEvents:o,openShortEvents:i}){let n=[...i,...o].sort((c,d)=>Number(c.blockNumber)-Number(d.blockNumber)),a={};for(let c of n){let d=c.args.assetId.toString(),{timestamp:p}=await P(this.drift,{blockNumber:c.blockNumber});a[d]=a[d]||{hyperdriveAddress:t,assetId:c.args.assetId,maturity:c.args.maturityTime,checkpointTime:H(p,e),openedTimestamp:p,baseAmountPaid:0n,bondAmount:0n,baseProceeds:0n,fixedRatePaid:0n};let m=c.args.asBase?c.args.amount:u(c.args.amount).mul(c.args.vaultSharePrice).bigint,{eventName:l}=c;switch(l){case"OpenShort":a[d].baseAmountPaid+=m,a[d].bondAmount+=c.args.bondAmount,a[d].baseProceeds+=c.args.baseProceeds,a[d].fixedRatePaid=G({positionDuration:r,baseAmount:a[d].baseProceeds,bondAmount:a[d].bondAmount});continue;case"CloseShort":{if(c.args.bondAmount===a[d].bondAmount){delete a[d];continue}a[d].baseAmountPaid-=m,a[d].bondAmount-=c.args.bondAmount,a[d].baseProceeds-=c.args.basePayment,a[d].fixedRatePaid=G({positionDuration:r,baseAmount:a[d].baseProceeds,bondAmount:a[d].bondAmount});continue}default:T(l,!0)}}return Object.values(a).filter(c=>c.bondAmount)}async getClosedLongs({account:t,options:e}){let r=await this.contract.getEvents("CloseLong",{filter:{trader:t},toBlock:e?.block});return(await Promise.all(r.map(async i=>{let n=i.args.assetId,a=i.args.asBase?i.args.amount:u(i.args.amount).mul(i.args.vaultSharePrice).bigint;return{assetId:n,bondAmount:i.args.bondAmount,baseAmount:a,baseAmountPaid:0n,maturity:i.args.maturityTime,closedTimestamp:(await P(this.drift,{blockNumber:i.blockNumber})).timestamp}}))).filter(i=>i.bondAmount)}async getClosedShorts({account:t,options:e}){let r=await this.contract.getEvents("CloseShort",{filter:{trader:t},toBlock:e?.block}),{checkpointDuration:o}=await this.getPoolConfig(e);return(await Promise.all(r.map(async n=>{let{assetId:a,maturityTime:c}=n.args,{timestamp:d}=await P(this.drift,{blockNumber:n.blockNumber}),p=n.args.asBase?n.args.amount:u(n.args.amount).mul(n.args.vaultSharePrice).bigint;return{hyperdriveAddress:this.address,assetId:a,bondAmount:n.args.bondAmount,baseAmountReceived:p,maturity:c,closedTimestamp:d,checkpointTime:H(d,o)}}))).filter(n=>n.bondAmount)}async getMaxShort({budget:t,options:e}){let r=await this.getPoolInfo(e),o=await this.getPoolConfig(e),i=await this.getCheckpointExposure({options:e}),{vaultSharePrice:n}=await this.getCheckpoint({options:e}),a=h.maxShort({budget:t,poolInfo:r,poolConfig:o,maxIterations:14,openVaultSharePrice:n,checkpointExposure:i}),c=h.calcOpenShort({poolInfo:r,poolConfig:o,bondAmount:a,openVaultSharePrice:n}),d=await this.convertToShares({baseAmount:c,options:e});return{maxBaseIn:c,maxSharesIn:d,maxBondsOut:a}}async getMaxLong(t){let e=await this.getPoolInfo(t),r=await this.getPoolConfig(t),o=await this.getCheckpointExposure({options:t}),i=h.maxLong({poolInfo:e,poolConfig:r,budget:dt,checkpointExposure:o}),n=await this.convertToShares({baseAmount:i,options:t}),a=h.calcOpenLong({poolInfo:e,poolConfig:r,baseAmount:i});return{maxBaseIn:i,maxSharesIn:n,maxBondsOut:a}}getLpSharesTotalSupply(t){return this.contract.read("totalSupply",{tokenId:j},t?.options)}getLpShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:j,owner:t},e)}async getOpenLpPosition({account:t,asBase:e,options:r}){let o=await this.contract.getEvents("AddLiquidity",{filter:{provider:t},toBlock:r?.block}),i=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},toBlock:r?.block}),n=await this.getDecimals(),{lpShareBalance:a,baseAmountPaid:c}=this._calcOpenLpPosition({addLiquidityEvents:o,removeLiquidityEvents:i});if(!a)return{lpShareBalance:a,baseAmountPaid:c,baseValue:0n,sharesValue:0n};let{proceeds:d,withdrawalShares:p}=await this.previewRemoveLiquidity({lpSharesIn:a,minOutputPerShare:1n,asBase:e,destination:t}),m=e?d:await this.convertToBase({sharesAmount:d}),{lpSharePrice:l}=await this.getPoolInfo(),g=u(l,n).mul(p,n).bigint,A=await this.convertToShares({baseAmount:g});return{lpShareBalance:a,baseAmountPaid:c,baseValue:m+g,sharesValue:d+A}}_calcOpenLpPosition({addLiquidityEvents:t,removeLiquidityEvents:e}){let r=[...t,...e].sort((n,a)=>Number(n.blockNumber)-Number(a.blockNumber)),o=0n,i=0n;return r.forEach(n=>{let a=n.args.asBase?n.args.amount:u(n.args.amount).mul(n.args.vaultSharePrice).bigint;switch(n.eventName){case"AddLiquidity":i+=n.args.lpAmount,o+=a;return;case"RemoveLiquidity":{if(i-=n.args.lpAmount,i<=0n)o=0n;else{let c=u(n.args.withdrawalShareAmount).mul(n.args.lpSharePrice).bigint;o=o-a-c}return}default:T(n,!0)}}),{lpShareBalance:i,baseAmountPaid:o}}async getClosedLpShares({account:t,options:e}){let r=await this.contract.getEvents("RemoveLiquidity",{filter:{provider:t},toBlock:e?.block});return Promise.all(r.map(async({blockNumber:o,args:i})=>{let{lpAmount:n,withdrawalShareAmount:a,asBase:c,amount:d,lpSharePrice:p}=i,m=c?d:u(i.amount).mul(i.vaultSharePrice).bigint;return{lpAmount:n,baseAmount:m,withdrawalShareAmount:a,lpSharePrice:p,closedTimestamp:(await P(this.drift,{blockNumber:o})).timestamp}}))}getWithdrawalShares({account:t,options:e}){return this.contract.read("balanceOf",{tokenId:ht,owner:t},e)}async getRedeemedWithdrawalShares({account:t,options:e}){let r=await this.contract.getEvents("RedeemWithdrawalShares",{filter:{provider:t},toBlock:e?.block});return Promise.all(r.map(async({blockNumber:o,args:i})=>{let{withdrawalShareAmount:n,amount:a,asBase:c,vaultSharePrice:d}=i,p=c?i.amount:u(a).mul(d).bigint;return{hyperdriveAddress:this.address,withdrawalShareAmount:n,baseAmount:p,redeemedTimestamp:(await P(this.drift,{blockNumber:o})).timestamp}}))}async previewOpenLong({amountIn:t,asBase:e,options:r}){let o=await this.getPoolConfig(r),i=await this.getPoolInfo(r),n=await this.getCheckpointTime({options:r}),a=t;e||(a=await this.convertToBase({sharesAmount:t,options:r}));let c=h.spotPriceAfterLong({poolInfo:i,poolConfig:o,baseAmount:a}),d=h.calcAprGivenFixedPrice({price:c,positionDuration:o.positionDuration}),p=h.calcOpenLong({poolInfo:i,poolConfig:o,baseAmount:a}),m=h.openLongCurveFee({poolInfo:i,poolConfig:o,baseAmount:a});return{maturityTime:n+o.positionDuration,bondProceeds:p,spotPriceAfterOpen:c,spotRateAfterOpen:d,curveFee:m}}async previewOpenShort({amountOfBondsToShort:t,asBase:e,options:r}){let o=await this.getPoolConfig(r),i=await this.getPoolInfo(r),n=await this.getCheckpoint({options:r}),a=await this.getShortAccruedYield({checkpointTime:n.checkpointTime,bondAmount:t,options:r}),c=h.calcOpenShort({poolInfo:i,poolConfig:o,bondAmount:t,openVaultSharePrice:n.vaultSharePrice}),d=u(o.positionDuration).div(Y),p=u(c).sub(a),m=u(t).sub(p),l=p.div(m).div(d).bigint,g=h.spotPriceAfterShort({poolInfo:i,poolConfig:o,bondAmount:t}),A=h.calcAprGivenFixedPrice({price:g,positionDuration:o.positionDuration}),q=h.openShortCurveFee({poolInfo:i,poolConfig:o,bondAmount:t});return e?{maturityTime:n.checkpointTime+o.positionDuration,traderDeposit:c,spotPriceAfterOpen:g,spotRateAfterOpen:A,curveFee:q,fixedRatePaid:l}:{maturityTime:n.checkpointTime+o.positionDuration,traderDeposit:await this.convertToShares({baseAmount:c,options:r}),spotPriceAfterOpen:g,spotRateAfterOpen:A,curveFee:await this.convertToShares({baseAmount:q,options:r}),fixedRatePaid:l}}async getShortBondsGivenDeposit({amountIn:t,asBase:e,tolerance:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=await this.getCheckpoint({options:o}),c=await this.getCheckpointExposure({options:o}),d=t;e||(d=await this.convertToBase({sharesAmount:t,options:o}));let p=h.absoluteMaxShort({poolInfo:n,poolConfig:i,checkpointExposure:c});return h.shortBondsGivenDeposit({poolInfo:n,poolConfig:i,targetBaseAmount:d,absoluteMaxBondAmount:p,openVaultSharePrice:a.vaultSharePrice,maybeTolerance:r})}async previewCloseLong({maturityTime:t,bondAmountIn:e,asBase:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=BigInt(Math.floor(Date.now()/1e3)),c=h.closeLongFlatFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a}),d=h.closeLongCurveFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a}),p=c+d,m=h.calcCloseLong({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:a});return r?{amountOut:await this.convertToBase({sharesAmount:m,options:o}),flatPlusCurveFee:await this.convertToBase({sharesAmount:p,options:o})}:{amountOut:m,flatPlusCurveFee:p}}async estimateShortMarketValue({maturityTime:t,asBase:e,shortAmountIn:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=t-i.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:o}),d=BigInt(Math.floor(Date.now()/1e3)),p=n.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:o})).vaultSharePrice);let m=h.calcShortMarketValue({poolInfo:n,poolConfig:i,bondAmount:r,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return e?this.convertToBase({sharesAmount:m,options:o}):m}async previewCloseShort({maturityTime:t,shortAmountIn:e,asBase:r,options:o}){let i=await this.getPoolConfig(o),n=await this.getPoolInfo(o),a=t-i.positionDuration,{vaultSharePrice:c}=await this.getCheckpoint({timestamp:a,options:o}),d=BigInt(Math.floor(Date.now()/1e3)),p=n.vaultSharePrice;t<=d&&(p=(await this.getCheckpoint({timestamp:t,options:o})).vaultSharePrice);let m=h.closeShortFlatFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:d}),l=h.closeShortCurveFee({poolInfo:n,poolConfig:i,bondAmount:e,maturityTime:t,currentTime:d}),g=m+l,A=h.calcCloseShort({poolInfo:n,poolConfig:i,bondAmount:e,openVaultSharePrice:c,closeVaultSharePrice:p,maturityTime:t,currentTime:d});return r?{amountOut:await this.convertToBase({sharesAmount:A,options:o}),flatPlusCurveFee:await this.convertToBase({sharesAmount:g,options:o})}:{amountOut:A,flatPlusCurveFee:g}}async previewAddLiquidity({contribution:t,minApr:e,minLpSharePrice:r,maxApr:o,asBase:i,options:n}){let a=await this.getPoolConfig(n),c=await this.getPoolInfo(n),d=BigInt(Math.floor(Date.now()/1e3)),p=h.calcAddLiquidity({poolInfo:c,poolConfig:a,currentTime:d,contribution:t,asBase:i,minLpSharePrice:r,minApr:e,maxApr:o}),m=await this.getDecimals(),l=u(p,m).mul(c.lpSharePrice,m).bigint,g=i?l:await this.convertToShares({baseAmount:l,options:n});return{lpSharesOut:p,slippagePaid:t-g}}async previewRemoveLiquidity({lpSharesIn:t,minOutputPerShare:e,destination:r,asBase:o,extraData:i=v,options:n}){let{proceeds:a,withdrawalShares:c}=await this.contract.simulateWrite("removeLiquidity",{_lpShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},{...n,from:r});return{proceeds:a,withdrawalShares:c}}async previewRedeemWithdrawalShares({withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:o,extraData:i=v,options:n}){let{proceeds:a,withdrawalSharesRedeemed:c}=await this.contract.simulateWrite("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},n);return{asBase:o,baseProceeds:o?a:await this.convertToBase({sharesAmount:a}),sharesProceeds:o?await this.convertToShares({baseAmount:a}):a,withdrawalSharesRedeemed:c}}};function ut({startPrice:s,endPrice:t,timeFrame:e}){let r=u(t).div(s),o=u(e).div(Y);return r.pow(u(1e18).div(o)).sub(1e18).bigint}function lt(s){let{assetType:t}=U(s.data);return t==="LONG"}var C=class extends b{constructor(t){super(t)}async approve({spender:t,amount:e,options:r}){return await this.contract.write("approve",{spender:t,amount:e},{...r,onMined:i=>{this.contract.invalidateReadsMatching("allowance"),r?.onMined?.(i)}})}};var y=class extends R{constructor(t){super(t)}async approve(){throw new x("This method is not available for the native ETH token.")}};var E=class extends f{constructor(t){super(t)}async getBaseToken(t){let e=await this.contract.read("baseToken",{},t);return e===y.address?new y({drift:this.drift}):new C({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getSharesToken(){let t=await this.contract.read("vaultSharesToken");return new C({address:t,drift:this.drift,cacheNamespace:this.contract.cacheNamespace})}async checkpoint({args:{time:t},options:e}){return this.contract.write("checkpoint",{_checkpointTime:BigInt(t),_maxIterations:4n},{...e,onMined:r=>{this.contract.cache.clear(),e?.onMined?.(r)}})}async pause({args:{paused:t},options:e}){return this.contract.write("pause",{_status:t},{...e,onMined:r=>{this.contract.invalidateReadsMatching("getMarketState"),e?.onMined?.(r)}})}async initialize({args:{contribution:t,apr:e,destination:r,asBase:o=!0,extraData:i=v},options:n}){return this.contract.write("initialize",{_apr:e,_contribution:t,_options:{destination:r,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}async openLong({args:{destination:t,amount:e,minBondsOut:r,minVaultSharePrice:o,asBase:i=!0,extraData:n=v},options:a}){return this.contract.write("openLong",{_amount:e,_minOutput:r,_minVaultSharePrice:o,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async openShort({args:{destination:t,bondAmount:e,minVaultSharePrice:r,maxDeposit:o,asBase:i=!0,extraData:n=v},options:a}){return this.contract.write("openShort",{_bondAmount:e,_maxDeposit:o,_minVaultSharePrice:r,_options:{destination:t,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeLong({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:o,asBase:i=!0,extraData:n=v},options:a}){return this.contract.write("closeLong",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:o,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async closeShort({args:{maturityTime:t,bondAmountIn:e,minAmountOut:r,destination:o,asBase:i=!0,extraData:n=v},options:a}){return this.contract.write("closeShort",{_maturityTime:t,_bondAmount:e,_minOutput:r,_options:{destination:o,asBase:i,extraData:n}},{...a,onMined:c=>{this.contract.cache.clear(),a?.onMined?.(c)}})}async addLiquidity({args:{destination:t,contribution:e,minApr:r,minLpSharePrice:o,maxApr:i,asBase:n=!0,extraData:a=v},options:c}){return this.contract.write("addLiquidity",{_contribution:e,_minLpSharePrice:o,_minApr:r,_maxApr:i,_options:{destination:t,asBase:n,extraData:a}},{...c,onMined:d=>{this.contract.cache.clear(),c?.onMined?.(d)}})}async removeLiquidity({args:{destination:t,lpSharesIn:e,minOutputPerShare:r,asBase:o=!0,extraData:i=v},options:n}){return this.contract.write("removeLiquidity",{_lpShares:e,_minOutputPerShare:r,_options:{destination:t,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}async redeemWithdrawalShares({args:{withdrawalSharesIn:t,minOutputPerShare:e,destination:r,asBase:o=!0,extraData:i=v},options:n}){return this.contract.write("redeemWithdrawalShares",{_withdrawalShares:t,_minOutputPerShare:e,_options:{destination:r,asBase:o,extraData:i}},{...n,onMined:a=>{this.contract.cache.clear(),n?.onMined?.(a)}})}};import{ILido as zt}from"@delvtech/hyperdrive-artifacts/ILido";var gt=zt.abi;var M=class extends K(b){};function K(s){return class extends s{stEthContract;constructor(...[t]){let{debugName:e="stETH Token",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.stEthContract=this.drift.contract({abi:gt,address:r,cache:o,cacheNamespace:i})}getSharesOf({account:t,options:e}){return this.stEthContract.read("sharesOf",{_account:t},e)}getPooledEthByShares({sharesAmount:t,options:e}){return this.stEthContract.read("getPooledEthByShares",{_sharesAmount:t},e)}getSharesByPooledEth({ethAmount:t,options:e}){return this.stEthContract.read("getSharesByPooledEth",{_ethAmount:t},e)}}}import{fixed as bt}from"@delvtech/fixed-point-wasm";var ft=class extends w(f){constructor(t){super(t)}};function w(s){return class extends s{constructor(...[t]){let{debugName:e="stETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(){let{vaultSharesToken:t}=await this.getPoolConfig();return new M({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getMaxShort({budget:t,options:e}){let r=await super.getMaxShort({budget:t,options:e}),o=await this.getDecimals();return{...r,maxSharesIn:bt(r.maxSharesIn,o).mul(1e18-1e12,18).bigint}}async getMaxLong(t){let e=await super.getMaxLong(t),r=await this.getDecimals();return{...e,maxSharesIn:bt(e.maxSharesIn,r).mul(1e18-1e12,18).bigint}}}}var L=class extends K(C){};var Rt=class extends X(E){};function X(s){return class extends w(s){async getBaseToken(){return new y({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new L({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}import{fixed as Ct}from"@delvtech/fixed-point-wasm";var B=class extends Z(f){};function Z(s){return class extends s{constructor(...[t]){let{debugName:e="Hyperdrive v1.0.14",...r}=t;super({debugName:e,...r})}async convertToBase({sharesAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),o=await this.getDecimals();return Ct(t,o).mul(r,o).bigint}async convertToShares({baseAmount:t,options:e}){let{vaultSharePrice:r}=await this.getPoolInfo(e),o=await this.getDecimals();return Ct(t,o).div(r).bigint}}}var Et=class extends w(B){};var W=class extends Z(E){};var xt=class extends X(W){};import{IERC4626 as qt}from"@delvtech/hyperdrive-artifacts/IERC4626";import{MockERC4626 as Gt}from"@delvtech/hyperdrive-artifacts/MockERC4626";var yt=qt.abi,vt=Gt.abi;var O=class extends J(b){};function J(s){return class extends s{erc4626Contract;constructor(...[t]){let{debugName:e="ERC-4626 Tokenized Vault",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.erc4626Contract=this.drift.contract({abi:yt,address:r,cache:o,cacheNamespace:i})}getTotalAssets(t){return this.erc4626Contract.read("totalAssets",{},t)}convertToAssets({sharesAmount:t,options:e}){return this.erc4626Contract.read("convertToAssets",{shares:t},e)}convertToShares({assetsAmount:t,options:e}){return this.erc4626Contract.read("convertToShares",{assets:t},e)}}}var I=class extends Q(f){};function Q(s){return class extends s{constructor(...[t]){let{debugName:e="ERC-4626 Hyperdrive",...r}=t;super({debugName:e,...r})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new O({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var N=class extends tt(O){};function tt(s){return class extends s{mockErc4626Contract;constructor(...[t]){let{debugName:e="Mock ERC-4626 Tokenized Vault",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.mockErc4626Contract=this.drift.contract({abi:vt,address:r,cache:o,cacheNamespace:i})}getRate(t){return this.mockErc4626Contract.read("getRate",{},t)}}}var Pt=class extends et(I){};function et(s){return class extends s{constructor(...[t]){let{debugName:e}=t;super({debugName:e??"Mock ERC-4626 Hyperdrive",...t})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new N({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var k=class extends J(C){};var _=class extends Yt(E){};function Yt(s){return class extends Q(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new k({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var D=class extends tt(k){mint({receiver:t,sharesAmount:e,options:r}){return this.mockErc4626Contract.write("mint",{_receiver:t,_shares:e},r)}setRate({rate:t,options:e}){return this.mockErc4626Contract.write("setRate",{_rate_:t},e)}};var St=class extends Ut(_){};function Ut(s){return class extends et(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new D({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}import{IEzETHHyperdrive as jt}from"@delvtech/hyperdrive-artifacts/IEzETHHyperdrive";var At=jt.abi;var Ot=class extends rt(f){};function rt(s){return class extends s{ezEthHyperdriveContract;constructor(...[t]){let{debugName:e="EzETH Hyperdrive",address:r,cache:o,cacheNamespace:i,...n}=t;super({debugName:e,address:r,cache:o,cacheNamespace:i,...n}),this.ezEthHyperdriveContract=this.drift.contract({abi:At,address:r,cache:o,cacheNamespace:i})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(){let{vaultSharesToken:t}=await this.getPoolConfig();return new b({address:t,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var kt=class extends Kt(E){};function Kt(s){return class extends rt(s){async getBaseToken(){return new y({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new C({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}import{IRiverV1 as Xt}from"@delvtech/hyperdrive-artifacts/IRiverV1";var wt=Xt.abi;var $=class extends ot(b){};function ot(s){return class extends s{lsEthContract;constructor(...[t]){let{drift:e,address:r,cache:o,cacheNamespace:i}=t;super({address:r,drift:e,cache:o,cacheNamespace:i}),this.lsEthContract=e.contract({abi:wt,address:r,cache:o,cacheNamespace:i})}async getTotalEthSupply(t){return this.lsEthContract.read("totalUnderlyingSupply",{},t)}async getEthBalanceOf({account:t,options:e}){return this.lsEthContract.read("balanceOfUnderlying",{_owner:t},e)}async getEthBalanceFromShares({sharesAmount:t,options:e}){return this.lsEthContract.read("underlyingBalanceFromShares",{_shares:t},e)}async getSharesFromEthBalance({ethBalance:t,options:e}){return this.lsEthContract.read("sharesFromUnderlyingBalance",{_underlyingAssetAmount:t},e)}}}var Tt=class extends it(f){};function it(s){return class extends s{constructor(...[t]){let{debugName:e="lsETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new $({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}var V=class extends ot(C){};var Ht=class extends Zt(E){};function Zt(s){return class extends it(s){async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new V({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getBaseToken(){return new y({drift:this.drift})}}}import{IRocketTokenRETH as Jt}from"@delvtech/hyperdrive-artifacts/IRocketTokenRETH";var Mt=Jt.abi;var F=class extends nt(b){};function nt(s){return class extends s{rEthContract;constructor(...[t]){let{drift:e,address:r,cache:o,cacheNamespace:i}=t;super({address:r,drift:e,cache:o,cacheNamespace:i}),this.rEthContract=e.contract({abi:Mt,address:r,cache:o,cacheNamespace:i})}async getTotalEthSupply(t){return this.rEthContract.read("getTotalCollateral",{},t)}async getEthBalanceOf({account:t,options:e}){let r=await this.getBalanceOf({account:t,options:e});return this.rEthContract.read("getEthValue",{_rethAmount:r},e)}async getEthValue({rEthAmount:t,options:e}){return this.rEthContract.read("getEthValue",{_rethAmount:t},e)}async getREthValue({ethAmount:t,options:e}){return this.rEthContract.read("getRethValue",{_ethAmount:t},e)}}}import{fixed as Lt}from"@delvtech/fixed-point-wasm";var Bt=class extends at(f){};function at(s){return class extends s{constructor(...[t]){let{debugName:e="rETH Hyperdrive",...r}=t;super({debugName:e,...r})}async getBaseToken(){return new R({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new F({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}async getMaxShort({budget:t,options:e}){let r=await super.getMaxShort({budget:t,options:e}),o=await this.getDecimals();return{...r,maxSharesIn:Lt(r.maxSharesIn,o).mul(1e18-1e12,18).bigint}}async getMaxLong(t){let e=await super.getMaxLong(t),r=await this.getDecimals();return{...e,maxSharesIn:Lt(e.maxSharesIn,r).mul(1e18-1e12,18).bigint}}}}var z=class extends nt(C){};var Wt=class extends Qt(E){};function Qt(s){return class extends at(s){async getBaseToken(){return new y({drift:this.drift})}async getSharesToken(t){let{vaultSharesToken:e}=await this.getPoolConfig(t);return new z({address:e,drift:this.drift,cache:this.contract.cache,cacheNamespace:this.contract.cacheNamespace})}}}export{x as a,st as b,G as c,S as d,h as e,ct as f,b as g,R as h,f as i,C as j,y as k,E as l,gt as m,M as n,ft as o,L as p,Rt as q,B as r,Et as s,W as t,xt as u,yt as v,vt as w,O as x,I as y,Q as z,N as A,Pt as B,et as C,k as D,_ as E,Yt as F,D as G,St as H,Ut as I,At as J,Ot as K,rt as L,kt as M,Kt as N,wt as O,$ as P,Tt as Q,it as R,V as S,Ht as T,Zt as U,Mt as V,F as W,Bt as X,at as Y,z as Z,Wt as _,Qt as $};
//# sourceMappingURL=chunk-HKUPLPJB.js.map

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display