@oceanprotocol/lib 2.6.3 → 2.7.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/CodeExamples.md +12 -4
- package/ComputeExamples.md +2 -2
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/lib.modern.js +1 -1
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.js +1 -1
- package/dist/lib.module.js.map +1 -1
- package/dist/lib.umd.js +1 -1
- package/dist/lib.umd.js.map +1 -1
- package/dist/src/services/Provider.d.ts +2 -1
- package/package.json +1 -1
package/dist/lib.modern.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"@oceanprotocol/contracts/addresses/address.json";import e from"bignumber.js";import a from"crypto-js/sha256";import i from"web3";import n from"cross-fetch";import o from"decimal.js";import s from"@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json";import r from"@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json";import c from"@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json";import l from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json";import h from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json";import d from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json";import u from"@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json";import w from"@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json";import m from"@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json";import p from"@oceanprotocol/contracts/artifacts/contracts/ve/veFeeEstimate.vy/veFeeEstimate.json";import g from"@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json";import v from"@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json";import f from"@oceanprotocol/contracts/artifacts/contracts/df/DFStrategyV1.sol/DFStrategyV1.json";class y{constructor(){this.nodeUri=void 0,this.providerAddress=void 0,this.metadataCacheUri=void 0,this.providerUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.datatokensABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.opfCommunityFeeCollector=void 0,this.sideStakingAddress=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.chainId=void 0,this.network=void 0,this.subgraphUri=void 0,this.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0,this.veAllocate=void 0,this.veOCEAN=void 0,this.veDelegation=void 0,this.veFeeDistributor=void 0,this.veDelegationProxy=void 0,this.DFRewards=void 0,this.DFStrategyV1=void 0,this.veFeeEstimate=void 0}}function b(){return b=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(t[i]=a[i])}return t},b.apply(this,arguments)}const T="0x0000000000000000000000000000000000000000",F=1e6,C="115792089237316195423570985008687907853269984665640564039457584007913129639934",E="Returned error: Method eth_feeHistory not supported.";function k(t,e){return e&&(e.transactionBlockTimeout&&(t.transactionBlockTimeout=e.transactionBlockTimeout),e.transactionConfirmationBlocks&&(t.transactionConfirmationBlocks=e.transactionConfirmationBlocks),e.transactionPollingTimeout&&(t.transactionPollingTimeout=e.transactionPollingTimeout)),t}async function M(t,a){const i=new e(await t.eth.getGasPrice());return a?i.multipliedBy(a).integerValue(e.ROUND_DOWN).toString(10):i.toString(10)}async function x(t,a,i,n){const o=new t.eth.Contract(q,a);let s=n||await o.methods.decimals().call();"0"===s&&(s=18);const r=new e(i).div(new e(10).exponentiatedBy(s));return e.config({EXPONENTIAL_AT:50}),r.toString()}async function D(t,a,i,n){const o=new t.eth.Contract(q,a);let s=n||await o.methods.decimals().call();return"0"===s&&(s=18),e.config({EXPONENTIAL_AT:50}),new e(i).times(new e(10).exponentiatedBy(s)).toFixed(0)}async function A(t,e,...a){return await e.apply(null,a).estimateGas({from:t},(t,e)=>t?1e6:e)}async function R(t,a,i,n,o,...s){const r={from:t,gas:a+1},c=await i.eth.getChainId();try{var l,h,d;const t=await i.eth.getFeeHistory(1,"latest",[75]);if(t&&null!=t&&null!=(l=t.baseFeePerGas)&&l[0]&&null!=t&&null!=(h=t.reward)&&null!=(d=h[0])&&d[0]){var u,w,m;let a=new e(null==t||null==(u=t.reward)||null==(w=u[0])?void 0:w[0]);n>1&&(a=a.multipliedBy(n)),r.maxPriorityFeePerGas=a.integerValue(e.ROUND_DOWN).toString(10),r.maxFeePerGas=a.plus(new e(null==t||null==(m=t.baseFeePerGas)?void 0:m[0]).multipliedBy(2)).integerValue(e.ROUND_DOWN).toString(10),r.maxPriorityFeePerGas=80001!==c&&137!==c||!new e(r.maxPriorityFeePerGas).lte(new e(3e10))?r.maxPriorityFeePerGas:new e(3e10).integerValue(e.ROUND_DOWN).toString(10),r.maxFeePerGas=80001!==c&&137!==c||!new e(r.maxFeePerGas).lte(new e(3e10))?r.maxFeePerGas:new e(3e10).integerValue(e.ROUND_DOWN).toString(10)}else r.gasPrice=await M(i,n)}catch(t){"Returned error: Method eth_feeHistory not supported."===(null==t?void 0:t.message)&&B.log("Not able to use EIP 1559, getFeeHistory method not suported by network."),r.gasPrice=await M(i,n)}return await o.apply(null,s).send(r)}var P,O={nouns:["Crab","Fish","Seal","Octopus","Shark","Seahorse","Walrus","Starfish","Whale","Orca","Penguin","Jellyfish","Squid","Lobster","Pelican","Shrimp","Oyster","Clam","Seagull","Dolphin","Shell","Cormorant","Otter","Anemone","Turtle","Coral","Ray","Barracuda","Krill","Anchovy","Angelfish","Barnacle","Clownfish","Cod","Cuttlefish","Eel","Fugu","Herring","Haddock","Ling","Mackerel","Manatee","Narwhal","Nautilus","Plankton","Porpoise","Prawn","Pufferfish","Swordfish","Tuna"],adjectives:["adamant","adroit","amatory","ambitious","amused","animistic","antic","arcadian","artistic","astonishing","astounding","baleful","bellicose","bilious","blissful","boorish","brave","breathtaking","brilliant","calamitous","caustic","cerulean","clever","charming","comely","competent","concomitant","confident","contumacious","corpulent","crapulous","creative","dazzling","dedicated","defamatory","delighted","delightful","determined","didactic","dilatory","dowdy","efficacious","effulgent","egregious","empowered","endemic","enthusiastic","equanimous","exceptional","execrable","fabulous","fantastic","fastidious","feckless","fecund","friable","fulsome","garrulous","generous","gentle","guileless","gustatory","heuristic","histrionic","hubristic","incendiary","incredible","insidious","insolent","inspired","intransigent","inveterate","invidious","invigorated","irksome","jejune","juicy","jocular","joyful","judicious","kind","lachrymose","limpid","loquacious","lovely","luminous","mannered","marvelous","mendacious","meretricious","minatory","mordant","motivated","munificent","nefarious","noxious","obtuse","optimistic","parsimonious","pendulous","pernicious","pervasive","petulant","passionate","phenomenal","platitudinous","pleasant","powerful","precipitate","propitious","puckish","querulous","quiescent","rebarbative","recalcitant","redolent","rhadamanthine","risible","ruminative","sagacious","salubrious","sartorial","sclerotic","serpentine","smart","spasmodic","strident","stunning","stupendous","taciturn","tactful","tasty","tenacious","tremendous","tremulous","trenchant","turbulent","turgid","ubiquitous","uxorious","verdant","vibrant","voluble","voracious","wheedling","withering","wonderful","zealous"]};function U(t){const e=t||O,a=Math.floor(Math.random()*e.adjectives.length),i=Math.floor(Math.random()*e.nouns.length),n=Math.floor(100*Math.random()),o=e.adjectives[a].replace(/^\w/,t=>t.toUpperCase()),s=e.nouns[i].replace(/^\w/,t=>t.toUpperCase());return{name:`${o} ${s} Token`,symbol:`${(o.substring(0,3)+s.substring(0,3)).toUpperCase()}-${n}`}}function S(t,e){return t=i.utils.toChecksumAddress(t),`did:op:${a(t+e.toString(10)).toString()}`}function N(t){return a(t).toString()}async function I(t){const e=(await n(t,{method:"HEAD"})).headers.get("content-disposition"),a=null!=e&&e.split("=")[1]?null==e?void 0:e.split("=")[1]:"file",i=new XMLHttpRequest;i.responseType="blob",i.open("GET",t),i.onload=()=>{const t=window.URL.createObjectURL(i.response),e=document.createElement("a");e.href=t,e.setAttribute("download",a),document.body.appendChild(e),e.click(),e.remove(),window.URL.revokeObjectURL(t)},i.send(null)}async function j(t,e){const a=await n(t);if(!a.ok)throw new Error("Response error.");let i;try{i=a.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(a){try{i=t.split("/").pop()}catch(t){i=`file${e}`}}return{data:await a.arrayBuffer(),filename:i}}async function W(t){return new Promise(e=>{setTimeout(e,t)})}!function(t){t[t.None=-1]="None",t[t.Error=0]="Error",t[t.Warn=1]="Warn",t[t.Log=2]="Log",t[t.Verbose=3]="Verbose"}(P||(P={}));class L{constructor(t=P.Error){this.logLevel=void 0,this.logLevel=t}setLevel(t){this.logLevel=t}bypass(...t){this.dispatch("log",-Infinity,...t)}debug(...t){this.dispatch("debug",P.Verbose,...t)}log(...t){this.dispatch("log",P.Log,...t)}warn(...t){this.dispatch("warn",P.Warn,...t)}error(...t){this.dispatch("error",P.Error,...t)}dispatch(t,e,...a){this.logLevel>=e&&console[t](...a)}}const B=new L,q=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}];async function _(t,e,a){let i=await t.eth.sign(e,a);i=i.substr(2);const n="0x"+i.slice(0,64),o="0x"+i.slice(64,128);let s="0x"+i.slice(128,130);return"0x00"===s&&(s="0x1b"),"0x01"===s&&(s="0x1c"),{v:s,r:n,s:o}}async function $(t,e,a,i,n,s,r=!1,c,l){const h=new t.eth.Contract(q,i);if(!r){const e=await V(t,i,a,n);if(new o(e).greaterThanOrEqualTo(new o(s)))return new o(e).toNumber()}const d=await D(t,i,s,c),u=await A(a,h.methods.approve,n,d);return l?u:await R(a,u+1,t,null==e?void 0:e.gasFeeMultiplier,h.methods.approve,n,d)}async function G(t,a,i,n,s,r,c=!1,l){const h=new t.eth.Contract(q,n);if(!c){const a=await z(t,n,i,s);if(new e(a).gt(new e(r)))return new o(a).toNumber()}let d=null;const u=await A(i,h.methods.approve,s,r);if(l)return u;try{d=await R(i,u+1,t,null==a?void 0:a.gasFeeMultiplier,h.methods.approve,s,r)}catch(t){B.error(`ERROR: Failed to approve spender to spend tokens : ${t.message}`)}return d}async function H(t,e,a,i,n,o,s){const r=new t.eth.Contract(q,i),c=await D(t,i,o),l=await A(a,r.methods.transfer,n,c);return s?l:await R(a,l+1,t,null==e?void 0:e.gasFeeMultiplier,r.methods.transfer,n,c)}async function V(t,e,a,i,n){const o=new t.eth.Contract(q,e),s=await o.methods.allowance(a,i).call();return await x(t,e,s,n)}async function Z(t,e,a,i){const n=new t.eth.Contract(q,e),o=await n.methods.balanceOf(a).call();return await x(t,e,o,i)}async function z(t,e,a,i){const n=new t.eth.Contract(q,e);return await n.methods.allowance(a,i).call()}async function J(t,e){const a=new t.eth.Contract(q,e);return await a.methods.decimals().call()}const X={chainId:null,network:"unknown",metadataCacheUri:"https://v4.aquarius.oceanprotocol.com",nodeUri:"http://127.0.0.1:8545",providerUri:"http://127.0.0.1:8030",subgraphUri:null,explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},Q=[b({},X),b({},X,{chainId:8996,network:"development",metadataCacheUri:"http://172.15.0.5:5000",providerUri:"http://172.15.0.4:8030",subgraphUri:"https://172.15.0.15:8000"}),b({},X,{chainId:5,network:"goerli",nodeUri:"https://goerli.infura.io/v3",providerUri:"https://v4.provider.goerli.oceanprotocol.com",subgraphUri:"https://v4.subgraph.goerli.oceanprotocol.com",explorerUri:"https://goerli.etherscan.io",gasFeeMultiplier:1.1}),b({},X,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",providerUri:"https://v4.provider.mainnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.mainnet.oceanprotocol.com",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05}),b({},X,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",providerUri:"https://v4.provider.polygon.oceanprotocol.com",subgraphUri:"https://v4.subgraph.polygon.oceanprotocol.com",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",gasFeeMultiplier:1.6}),b({},X,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",providerUri:"https://v4.provider.gaiaxtestnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com"}),b({},X,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",providerUri:"https://v4.provider.mumbai.oceanprotocol.com",subgraphUri:"https://v4.subgraph.mumbai.oceanprotocol.com",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1}),b({},X,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",providerUri:"https://v4.provider.bsc.oceanprotocol.com",subgraphUri:"https://v4.subgraph.bsc.oceanprotocol.com",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05}),b({},X,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",providerUri:"https://v4.provider.energyweb.oceanprotocol.com",subgraphUri:"https://v4.subgraph.energyweb.oceanprotocol.com",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05}),b({},X,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",providerUri:"https://v4.provider.moonriver.oceanprotocol.com",subgraphUri:"https://v4.subgraph.moonriver.oceanprotocol.com",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05})];class K{getAddressesFromEnv(e,a){let i;if(a){const{FixedPrice:t,Dispenser:n,ERC721Factory:o,OPFCommunityFeeCollector:s,Ocean:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:v}=a[e];i=b({nftFactoryAddress:o,opfCommunityFeeCollector:s,fixedRateExchangeAddress:t,dispenserAddress:n,oceanTokenAddress:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:v},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}else if(t[e]){const{FixedPrice:a,Dispenser:n,OPFCommunityFeeCollector:o,ERC721Factory:s,Ocean:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:v}=t[e];i=b({nftFactoryAddress:s,opfCommunityFeeCollector:o,fixedRateExchangeAddress:a,dispenserAddress:n,oceanTokenAddress:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:v},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}return i}getConfig(t,e){const a="string"==typeof t?"network":"chainId";let i=Q.find(e=>e[a]===t);return i?(i=b({},i,this.getAddressesFromEnv(i.network)),b({},i,{nodeUri:e?`${i.nodeUri}/${e}`:i.nodeUri})):(B.error(`No config found for given network '${t}'`),null)}}class Y{constructor(t,e,a,i){this.web3=void 0,this.config=void 0,this.abi=void 0,this.web3=t,this.config=a||(new K).getConfig(e||"unknown"),this.abi=i||this.getDefaultAbi()}async amountToUnits(t,e,a){return D(this.web3,t,e,a)}async unitsToAmount(t,e,a){return x(this.web3,t,e,a)}async getFairGasPrice(){var t;return M(this.web3,null==(t=this.config)?void 0:t.gasFeeMultiplier)}getContract(t,e,a){return k(new this.web3.eth.Contract(a||this.abi,t,{from:e}),this.config)}}class tt extends Y{constructor(t,e,a,i,n){super(e,a,i,n),this.address=void 0,this.contract=void 0,this.address=t,this.contract=this.getContract(this.address)}}class et extends tt{getDefaultAbi(){return s.abi}async status(t){const e=await this.contract.methods.status(t).call();if(!e)throw new Error("Np dispenser found for the given datatoken address");return e.maxTokens=this.web3.utils.fromWei(e.maxTokens),e.maxBalance=this.web3.utils.fromWei(e.maxBalance),e.balance=this.web3.utils.fromWei(e.balance),e}async create(t,e,a,i,n,o){var s;const r=await A(e,this.contract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(i),e,n);return o?r:await R(e,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(i),e,n)}async activate(t,e,a,i,n){var o;const s=await A(i,this.contract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a));return n?s:await R(i,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a))}async deactivate(t,e,a){var i;const n=await A(e,this.contract.methods.deactivate,t);return a?n:await R(e,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.deactivate,t)}async setAllowedSwapper(t,e,a,i){var n;const o=await A(e,this.contract.methods.setAllowedSwapper,t,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setAllowedSwapper,t,a)}async dispense(t,e,a="1",i,n){var o;const s=await A(e,this.contract.methods.dispense,t,this.web3.utils.toWei(a),i);return n?s:await R(e,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.dispense,t,this.web3.utils.toWei(a),i)}async ownerWithdraw(t,e,a){var i;const n=await A(e,this.contract.methods.ownerWithdraw,t);return a?n:await R(e,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.ownerWithdraw,t)}async isDispensable(t,e,a,i="1"){const n=await this.status(t);return!(!n||!1===n.active||new o(await e.balance(t,a)).greaterThanOrEqualTo(n.maxBalance)||new o(String(i)).greaterThan(n.maxTokens)||!new o(n.balance).greaterThanOrEqualTo(i)&&!0!==n.isMinter)}}class at extends tt{getDefaultAbi(){return r.abi}async generateExchangeId(t,e){return await this.contract.methods.generateExchangeId(t,e).call()}async buyDatatokens(t,e,a,i,n=T,o="0",s){var r;const c=await this.getExchange(e),l=this.web3.utils.toWei(o),h=await this.amountToUnits(c.datatoken,a,+c.dtDecimals),d=await this.amountToUnits(c.baseToken,i,+c.btDecimals),u=await A(t,this.contract.methods.buyDT,e,h,d,n,l);return s?u:await R(t,u+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.buyDT,e,h,d,n,l)}async sellDatatokens(t,e,a,i,n=T,o="0",s){var r;const c=await this.getExchange(e),l=this.web3.utils.toWei(o),h=await this.amountToUnits(c.datatoken,a,+c.dtDecimals),d=await this.amountToUnits(c.baseToken,i,+c.btDecimals),u=await A(t,this.contract.methods.sellDT,e,h,d,n,l);return s?u:await R(t,u+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.sellDT,e,h,d,n,l)}async getNumberOfExchanges(){return await this.contract.methods.getNumberOfExchanges().call()}async setRate(t,e,a,i){var n;const o=await A(t,this.contract.methods.setRate,e,this.web3.utils.toWei(a));return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setRate,e,this.web3.utils.toWei(a))}async setAllowedSwapper(t,e,a,i){var n;const o=await A(t,this.contract.methods.setAllowedSwapper,e,a);return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setAllowedSwapper,e,a)}async activate(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!0===n.active)return null;const o=await A(t,this.contract.methods.toggleExchangeState,e);return a?o:await R(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleExchangeState,e)}async deactivate(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!1===n.active)return null;const o=await A(t,this.contract.methods.toggleExchangeState,e);return a?o:await R(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleExchangeState,e)}async getRate(t){const e=await this.contract.methods.getRate(t).call();return await this.web3.utils.fromWei(e)}async getDatatokenSupply(t){const e=await this.contract.methods.getDTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.datatoken,e,+a.dtDecimals)}async getBasetokenSupply(t){const e=await this.contract.methods.getBTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.baseToken,e,+a.btDecimals)}async getAllowedSwapper(t){return await this.contract.methods.getAllowedSwapper(t).call()}async calcBaseInGivenDatatokensOut(t,e,a="0"){const i=await this.getExchange(t),n=await this.contract.methods.calcBaseInGivenOutDT(t,await this.amountToUnits(i.datatoken,e,+i.dtDecimals),this.web3.utils.toWei(a)).call();return{baseTokenAmount:await this.unitsToAmount(i.baseToken,n.baseTokenAmount,+i.btDecimals),marketFeeAmount:await this.unitsToAmount(i.baseToken,n.marketFeeAmount,+i.btDecimals),oceanFeeAmount:await this.unitsToAmount(i.baseToken,n.oceanFeeAmount,+i.btDecimals),consumeMarketFeeAmount:await this.unitsToAmount(i.baseToken,n.consumeMarketFeeAmount,+i.btDecimals)}}async getAmountBasetokensOut(t,e,a="0"){const i=await this.getExchange(t),n=await this.contract.methods.calcBaseOutGivenInDT(t,await this.amountToUnits(i.datatoken,e,+i.dtDecimals),this.web3.utils.toWei(a)).call();return await this.unitsToAmount(i.baseToken,n[0],+i.btDecimals)}async getExchange(t){const e=await this.contract.methods.getExchange(t).call();return e.dtDecimals=e.dtDecimals.toString(),e.btDecimals=e.btDecimals.toString(),e.dtBalance=await this.unitsToAmount(e.datatoken,e.dtBalance,+e.dtDecimals),e.btBalance=await this.unitsToAmount(e.baseToken,e.btBalance,+e.btDecimals),e.dtSupply=await this.unitsToAmount(e.datatoken,e.dtSupply,+e.dtDecimals),e.btSupply=await this.unitsToAmount(e.baseToken,e.btSupply,+e.btDecimals),e.fixedRate=this.web3.utils.fromWei(e.fixedRate),e.exchangeId=t,e}async getFeesInfo(t){const e=await this.contract.methods.getFeesInfo(t).call();e.opcFee=this.web3.utils.fromWei(e.opcFee.toString()),e.marketFee=this.web3.utils.fromWei(e.marketFee.toString());const a=await this.getExchange(t);return e.marketFeeAvailable=await this.unitsToAmount(a.baseToken,e.marketFeeAvailable,+a.btDecimals),e.oceanFeeAvailable=await this.unitsToAmount(a.baseToken,e.oceanFeeAvailable,+a.btDecimals),e.exchangeId=t,e}async getExchanges(){return await this.contract.methods.getExchanges().call()}async isActive(t){return await this.contract.methods.isActive(t).call()}async activateMint(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!0===n.withMint)return null;const o=await A(t,this.contract.methods.toggleMintState,e,!0);return a?o:await R(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleMintState,e,!0)}async deactivateMint(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!1===n.withMint)return null;const o=await A(t,this.contract.methods.toggleMintState,e,!1);return a?o:await R(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleMintState,e,!1)}async collectBasetokens(t,e,a,i){var n;if(!await this.getExchange(e))return null;const o=await this.contract.methods.getExchange(e).call(),s=await this.amountToUnits(o.baseToken,a,+o.btDecimals),r=await A(t,this.contract.methods.collectBT,e,s);return i?r:await R(t,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.collectBT,e,s)}async collectDatatokens(t,e,a,i){var n;if(!await this.getExchange(e))return null;const o=await this.contract.methods.getExchange(e).call(),s=await this.amountToUnits(o.datatoken,a,+o.dtDecimals),r=await A(t,this.contract.methods.collectDT,e,s);return i?r:await R(t,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.collectDT,e,s)}async collectMarketFee(t,e,a){var i;if(!await this.getExchange(e))return null;const n=await A(t,this.contract.methods.collectMarketFee,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.collectMarketFee,e)}async collectOceanFee(t,e,a){var i;if(!await this.getExchange(e))return null;const n=await A(t,this.contract.methods.collectOceanFee,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.collectOceanFee,e)}async getOPCCollector(){return await this.contract.methods.opcCollector().call()}async getRouter(){return await this.contract.methods.router().call()}async getExchangeOwner(t){return await(await this.getExchange(t)).exchangeOwner}async updateMarketFee(t,e,a,i){var n;const o=await A(t,this.contract.methods.updateMarketFee,e,this.web3.utils.toWei(a));return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.updateMarketFee,e,this.web3.utils.toWei(a))}async updateMarketFeeCollector(t,e,a,i){var n;const o=await A(t,this.contract.methods.updateMarketFeeCollector,e,a);return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.updateMarketFeeCollector,e,a)}}class it extends tt{getDefaultAbi(){return c.abi}async buyDatatokenBatch(t,e,a){var i;const n=await A(t,this.contract.methods.buyDTBatch,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.buyDTBatch,e)}async isApprovedToken(t){return await this.contract.methods.isApprovedToken(t).call()}async isFixedPrice(t){return await this.contract.methods.isFixedRateContract(t).call()}async getOwner(){return await this.contract.methods.routerOwner().call()}async getNFTFactory(){return await this.contract.methods.factory().call()}async addApprovedToken(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.addApprovedToken,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addApprovedToken,e)}async removeApprovedToken(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.removeApprovedToken,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeApprovedToken,e)}async addFixedRateContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.addFixedRateContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addFixedRateContract,e)}async removeFixedRateContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.removeFixedRateContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeFixedRateContract,e)}async addDispenserContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.addDispenserContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addDispenserContract,e)}async removeDispenserContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.removeDispenserContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeDispenserContract,e)}async getOPCFee(t){return await this.contract.methods.getOPCFee(t).call()}async getCurrentOPCFee(){return await this.contract.methods.swapOceanFee().call()}async updateOPCFee(t,e,a,i,n,o){var s;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const r=await A(t,this.contract.methods.updateOPCFee,e,a,i,n);return o?r:await R(t,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.updateOPCFee,e,a,i,n)}}class nt extends Y{getDefaultAbi(){return d.abi}async createDatatoken(t,e,a,i,n,o,s,r,c,l,h,d){var u,w,m,p;if(!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not DatatokenDeployer");h||(h=1),c&&l||({name:c,symbol:l}=U());const g=this.getContract(t),v=await A(e,g.methods.createERC20,h,[c,l],[a,i,n,o],[this.web3.utils.toWei(r),this.web3.utils.toWei(s)],[]);if(d)return v;const f=await R(e,v+1,this.web3,null==(u=this.config)?void 0:u.gasFeeMultiplier,g.methods.createERC20,h,[c,l],[a,i,n,o],[this.web3.utils.toWei(r),this.web3.utils.toWei(s)],[]);return null==f||null==(w=f.events)||null==(m=w.TokenCreated)||null==(p=m.returnValues)?void 0:p[0]}async addManager(t,e,a,i){var n;const o=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const s=await A(e,o.methods.addManager,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addManager,a)}async removeManager(t,e,a,i){var n;const o=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const s=await A(e,o.methods.removeManager,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeManager,a)}async addDatatokenDeployer(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const s=await A(e,o.methods.addToCreateERC20List,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addToCreateERC20List,a)}async removeDatatokenDeployer(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e===a&&!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");const s=await A(e,o.methods.removeFromCreateERC20List,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeFromCreateERC20List,a)}async addMetadataUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const s=await A(e,o.methods.addToMetadataList,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addToMetadataList,a)}async removeMetadataUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");const s=await A(e,o.methods.removeFromMetadataList,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeFromMetadataList,a)}async addStoreUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const s=await A(e,o.methods.addTo725StoreList,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addTo725StoreList,a)}async removeStoreUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).store)throw new Error("Caller is not Manager nor storeUpdater");const s=await A(e,o.methods.removeFrom725StoreList,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeFrom725StoreList,a)}async cleanPermissions(t,e,a){var i;const n=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const o=await A(e,n.methods.cleanPermissions);return a?o:await R(e,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,n.methods.cleanPermissions)}async transferNft(t,e,a,i,n){var o;const s=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const r=i||1,c=await A(e,s.methods.transferFrom,e,a,r);return n?c:await R(e,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.transferFrom,e,a,r)}async safeTransferNft(t,e,a,i,n){var o;const s=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const r=i||1,c=await A(e,s.methods.safeTransferFrom,e,a,r);return n?c:await R(e,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.safeTransferFrom,e,a,r)}async setMetadata(t,e,a,i,n,o,s,r,c,l){var h;const d=this.getContract(t);if(c||(c=[]),!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const u=await A(e,d.methods.setMetaData,a,i,n,o,s,r,c);return l?u:await R(e,u+1,this.web3,null==(h=this.config)?void 0:h.gasFeeMultiplier,d.methods.setMetaData,a,i,n,o,s,r,c)}async setMetadataAndTokenURI(t,e,a,i){var n;const o=this.getContract(t);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const s=b({},a,{metadataProofs:a.metadataProofs||[]}),r=await A(e,o.methods.setMetaDataAndTokenURI,s);return i?r:await R(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setMetaDataAndTokenURI,s)}async setMetadataState(t,e,a,i){var n;const o=this.getContract(t);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const s=await A(e,o.methods.setMetaDataState,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setMetaDataState,a)}async setTokenURI(t,e,a,i){var n;const o=this.getContract(t),s=await A(e,o.methods.setTokenURI,"1",a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setTokenURI,"1",a)}async getNftOwner(t){const e=this.getContract(t);return await e.methods.ownerOf(1).call()}async getNftPermissions(t,e){const a=this.getContract(t);return await a.methods.getPermissions(e).call()}async getMetadata(t){const e=this.getContract(t);return await e.methods.getMetaData().call()}async isDatatokenDeployer(t,e){const a=this.getContract(t);return await a.methods.isERC20Deployer(e).call()}async setData(t,e,a,i){var n;if(!0!==(await this.getNftPermissions(t,e)).store)throw new Error("User is not ERC20 store updater");const o=this.getContract(t),s=this.web3.utils.keccak256(a),r=this.web3.utils.asciiToHex(i),c=await A(e,o.methods.setNewData,s,r);return await R(e,c+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setNewData,s,r)}async getData(t,e){const a=this.getContract(t),i=this.web3.utils.keccak256(e),n=await a.methods.getData(i).call();return n?this.web3.utils.hexToAscii(n):null}async getTokenURI(t,e){const a=this.getContract(t);return await a.methods.tokenURI(e).call()}}class ot extends Y{getDefaultAbi(){return l.abi}constructor(t,e,a,i,n){super(t,e,a,i),this.abiEnterprise=void 0,this.nft=void 0,this.abiEnterprise=n||h.abi,this.nft=new nt(this.web3)}async approve(t,e,a,i,n){var o;const s=this.getContract(t),r=await A(i,s.methods.approve,e,this.web3.utils.toWei(a));return n?r:await R(i,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.approve,e,this.web3.utils.toWei(a))}async createFixedRate(t,e,a,i){var n;const o=this.getContract(t);if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");a.allowedConsumer||(a.allowedConsumer=T);const s=!1===a.withMint?0:1,r=await A(e,o.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,s]);return i?r:await R(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,s])}async createDispenser(t,e,a,i,n){var o;if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");const s=this.getContract(t);i.allowedSwapper||(i.allowedSwapper=T),i.withMint=!1!==i.withMint;const r=await A(e,s.methods.createDispenser,a,i.maxTokens,i.maxBalance,i.withMint,i.allowedSwapper);return n?r:await R(e,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.createDispenser,a,i.maxTokens,i.maxBalance,i.withMint,i.allowedSwapper)}async mint(t,e,a,i,n){const s=this.getContract(t);if(!0!==(await this.getPermissions(t,e)).minter)throw new Error("Caller is not Minter");const r=await this.getCap(t);if(new o(r).gte(a)){var c;const t=await A(e,s.methods.mint,i||e,this.web3.utils.toWei(a));return n?t:await R(e,t+1,this.web3,null==(c=this.config)?void 0:c.gasFeeMultiplier,s.methods.mint,i||e,this.web3.utils.toWei(a))}throw new Error("Mint amount exceeds cap available")}async addMinter(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const s=await A(e,o.methods.addMinter,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addMinter,a)}async removeMinter(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const s=await A(e,o.methods.removeMinter,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeMinter,a)}async addPaymentManager(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const s=await A(e,o.methods.addPaymentManager,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addPaymentManager,a)}async removePaymentManager(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const s=await A(e,o.methods.removePaymentManager,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removePaymentManager,a)}async setPaymentCollector(t,e,a,i){var n;const o=this.getContract(t),s=(await this.getPermissions(t,e)).paymentManager,r=!s&&await this.getNFTAddress(t),c=r&&await this.nft.getNftOwner(r)===e,l=r&&!c&&await this.nft.getNftPermissions(r,e);if(!s&&!c&&!(null==l?void 0:l.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");const h=await A(e,o.methods.setPaymentCollector,a);return i?h:await R(e,h+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setPaymentCollector,a)}async getPaymentCollector(t){const e=this.getContract(t);return await e.methods.getPaymentCollector().call()}async transfer(t,e,a,i){const n=this.web3.utils.toWei(a);return this.transferWei(t,e,n,i)}async transferWei(t,e,a,i,n){var o;const s=this.getContract(t),r=await A(i,s.methods.transfer,e,a);return n?r:await R(i,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.transfer,e,a)}async startOrder(t,e,a,i,n,o,s){var r;const c=this.getContract(t);o||(o={consumeMarketFeeAddress:T,consumeMarketFeeToken:T,consumeMarketFeeAmount:"0"});const l=await A(e,c.methods.startOrder,a,i,n,o);return s?l:await R(e,l+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,c.methods.startOrder,a,i,n,o)}async reuseOrder(t,e,a,i,n){var o;const s=this.getContract(t),r=await A(e,s.methods.reuseOrder,a,i);return n?r:await R(e,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.reuseOrder,a,i)}async buyFromFreAndOrder(t,e,a,i,n){var o;const s=this.getContract(t,null,this.abiEnterprise),r=await this.getFreOrderParams(i),c=await A(e,s.methods.buyFromFreAndOrder,a,r);return n?c:await R(e,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.buyFromFreAndOrder,a,r)}async buyFromDispenserAndOrder(t,e,a,i,n){var o;const s=this.getContract(t,null,this.abiEnterprise),r=await A(e,s.methods.buyFromDispenserAndOrder,a,i);return n?r:await R(e,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,s.methods.buyFromDispenserAndOrder,a,i)}async setData(t,e,a,i){var n;if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");const o=this.getContract(t),s=this.web3.utils.asciiToHex(a),r=await A(e,o.methods.setData,s);return i?r:await R(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setData,s)}async cleanPermissions(t,e,a){var i;if(await this.nft.getNftOwner(await this.getNFTAddress(t))!==e)throw new Error("Caller is NOT Nft Owner");const n=this.getContract(t),o=await A(e,n.methods.cleanPermissions);return a?o:await R(e,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,n.methods.cleanPermissions)}async getPermissions(t,e){const a=this.getContract(t);return await a.methods.permissions(e).call()}async getCap(t){const e=this.getContract(t),a=await e.methods.cap().call();return this.web3.utils.fromWei(a)}async getDecimals(t){const e=this.getContract(t);return await e.methods.decimals().call()}async getSymbol(t){const e=this.getContract(t);return await e.methods.symbol().call()}async getName(t){const e=this.getContract(t);return await e.methods.name().call()}async getNFTAddress(t){const e=this.getContract(t);return await e.methods.getERC721Address().call()}async isDatatokenDeployer(t,e){const a=this.getContract(t);return await a.methods.isERC20Deployer(e).call()}async balance(t,e){const a=this.getContract(t,e),i=await a.methods.balanceOf(e).call();return this.web3.utils.fromWei(i)}async setPublishingMarketFee(t,e,a,i,n,o){var s;const r=this.getContract(t,n);if((await r.methods.getPublishingMarketFee().call())[0]!==n)throw new Error("Caller is not the Publishing Market Fee Address");const c=await A(n,r.methods.setPublishingMarketFee,e,a,i);return o?c:await R(n,c+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,r.methods.setPublishingMarketFee,e,a,i)}async getPublishingMarketFee(t,e){const a=this.getContract(t,e),i=await a.methods.getPublishingMarketFee().call();return{publishMarketFeeAddress:i[0],publishMarketFeeToken:i[1],publishMarketFeeAmount:i[2]}}async getFreOrderParams(t){return{exchangeContract:t.exchangeContract,exchangeId:t.exchangeId,maxBaseTokenAmount:await D(this.web3,t.baseTokenAddress,t.maxBaseTokenAmount,t.baseTokenDecimals),swapMarketFee:await D(this.web3,t.baseTokenAddress,t.swapMarketFee,t.baseTokenDecimals),marketFeeAddress:t.marketFeeAddress}}}class st extends tt{getDefaultAbi(){return u.abi}async createNFT(t,e,a){var i,n,o,s;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){const{name:t,symbol:a}=U();e.name=t,e.symbol=a}if(e.templateIndex>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");if(!1===(await this.getNFTTemplate(e.templateIndex)).isActive)throw new Error("Template is not active");const r=await A(t,this.contract.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,T,T,e.tokenURI,e.transferable,e.owner);if(a)return r;const c=await R(t,r+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,T,T,e.tokenURI,e.transferable,e.owner);return null==c||null==(n=c.events)||null==(o=n.NFTCreated)||null==(s=o.returnValues)?void 0:s[0]}async getCurrentNFTCount(){return await this.contract.methods.getCurrentNFTCount().call()}async getCurrentTokenCount(){return await this.contract.methods.getCurrentTokenCount().call()}async getOwner(){return await this.contract.methods.owner().call()}async getCurrentNFTTemplateCount(){return await this.contract.methods.getCurrentNFTTemplateCount().call()}async getCurrentTokenTemplateCount(){return await this.contract.methods.getCurrentTemplateCount().call()}async getNFTTemplate(t){if(t>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return await this.contract.methods.getNFTTemplate(t).call()}async getTokenTemplate(t){return await this.contract.methods.getTokenTemplate(t).call()}async checkDatatoken(t){return await this.contract.methods.erc20List(t).call()}async checkNFT(t){return await this.contract.methods.erc721List(t).call()}async addNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===T)throw new Error("Template cannot be ZERO address");const n=await A(t,this.contract.methods.add721TokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.add721TokenTemplate,e)}async disableNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const n=await A(t,this.contract.methods.disable721TokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.disable721TokenTemplate,e)}async reactivateNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const n=await A(t,this.contract.methods.reactivate721TokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.reactivate721TokenTemplate,e)}async addTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===T)throw new Error("Template cannot be address ZERO");const n=await A(t,this.contract.methods.addTokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addTokenTemplate,e)}async disableTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!1===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already disabled");const n=await A(t,this.contract.methods.disableTokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.disableTokenTemplate,e)}async reactivateTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!0===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already active");const n=await A(t,this.contract.methods.reactivateTokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.reactivateTokenTemplate,e)}async startMultipleTokenOrder(t,e,a){var i;if(e.length>50)throw new Error("Too many orders");const n=await A(t,this.contract.methods.startMultipleTokenOrder,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.startMultipleTokenOrder,e)}async createNftWithDatatoken(t,e,a,i){var n;const o=this.getErcCreationParams(a),s=await A(t,this.contract.methods.createNftWithErc20,e,o);return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.createNftWithErc20,e,o)}async createNftWithDatatokenWithFixedRate(t,e,a,i,n){var o;const s=this.getErcCreationParams(a),r=this.getFreCreationParams(i),c=await A(t,this.contract.methods.createNftWithErc20WithFixedRate,e,s,r);return n?c:await R(t,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.createNftWithErc20WithFixedRate,e,s,r)}async createNftWithDatatokenWithDispenser(t,e,a,n,o){var s;const r=this.getErcCreationParams(a);n.maxBalance=i.utils.toWei(n.maxBalance),n.maxTokens=i.utils.toWei(n.maxTokens);const c=await A(t,this.contract.methods.createNftWithErc20WithDispenser,e,r,n);return o?c:await R(t,c+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.createNftWithErc20WithDispenser,e,r,n)}getErcCreationParams(t){let e,a;return t.name&&t.symbol||({name:e,symbol:a}=U()),{templateIndex:t.templateIndex,strings:[t.name||e,t.symbol||a],addresses:[t.minter,t.paymentCollector,t.mpFeeAddress,t.feeToken],uints:[i.utils.toWei(t.cap),i.utils.toWei(t.feeAmount)],bytess:[]}}getFreCreationParams(t){t.allowedConsumer||(t.allowedConsumer=T);const e=!1===t.withMint?0:1;return{fixedPriceAddress:t.fixedRateAddress,addresses:[t.baseTokenAddress,t.owner,t.marketFeeCollector,t.allowedConsumer],uints:[t.baseTokenDecimals,t.datatokenDecimals,i.utils.toWei(t.fixedRate),i.utils.toWei(t.marketFee),e]}}}class rt extends tt{getDefaultAbi(){return w.abi}async lockTokens(t,e,a,i){var n;const o=await this.amountToUnits(await this.getToken(),e),s=await A(t,this.contract.methods.create_lock,o,a);return i?s:await R(t,s+2e4,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.create_lock,o,a)}async depositFor(t,e,a,i){var n;const o=await this.amountToUnits(await this.getToken(),a),s=await A(t,this.contract.methods.deposit_for,e,o);return i?s:await R(t,s+2e4,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.deposit_for,e,o)}async increaseAmount(t,e,a){var i;const n=await this.amountToUnits(await this.getToken(),e),o=await A(t,this.contract.methods.increase_amount,n);return a?o:await R(t,o+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.increase_amount,n)}async increaseUnlockTime(t,e,a){var i;const n=await A(t,this.contract.methods.increase_unlock_time,e);return a?n:await R(t,n+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.increase_unlock_time,e)}async withdraw(t,e){var a;const i=await A(t,this.contract.methods.withdraw);return e?i:await R(t,i+1,this.web3,null==(a=this.config)?void 0:a.gasFeeMultiplier,this.contract.methods.withdraw)}async getVotingPower(t){return await this.contract.methods.balanceOf(t).call()}async getLockedAmount(t){const e=await this.contract.methods.locked(t).call();return await this.unitsToAmount(await this.getToken(),e.amount)}async lockEnd(t){return await this.contract.methods.locked__end(t).call()}async totalSupply(){return await this.unitsToAmount(await this.getToken(),await this.contract.methods.totalSupply().call())}async getToken(){return await this.contract.methods.token().call()}}class ct extends tt{getDefaultAbi(){return m.abi}async claim(t,e){var a;const i=await A(t,this.contract.methods.claim);return e?i:await R(t,i+2e4,this.web3,null==(a=this.config)?void 0:a.gasFeeMultiplier,this.contract.methods.claim)}async claimMany(t,e,a){var i;const n=await A(t,this.contract.methods.claim_many,e);return a?n:await R(t,n+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.claim_many,e)}}class lt extends tt{getDefaultAbi(){return p.abi}async estimateClaim(t){const e=await this.contract.methods.estimateClaim(t).call(),a=new rt(await this.contract.methods.voting_escrow().call(),this.web3);return await this.unitsToAmount(await a.getToken(),e)}}class ht extends tt{getDefaultAbi(){return g.abi}async setAllocation(t,e,a,i,n){var o;const s=await A(t,this.contract.methods.setAllocation,e,a,i);return n?s:await R(t,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.setAllocation,e,a,i)}async setBatchAllocation(t,e,a,i,n){var o;const s=await A(t,this.contract.methods.setBatchAllocation,e,a,i);return n?s:await R(t,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.setBatchAllocation,e,a,i)}async getTotalAllocation(t){return await this.contract.methods.getTotalAllocation(t).call()}async getVeAllocation(t,e,a){return await this.contract.methods.getveAllocation(t,e,a).call()}}class dt extends tt{getDefaultAbi(){return v.abi}async getAvailableRewards(t,e){const a=await this.contract.methods.claimable(t,e).call();return await this.unitsToAmount(e,a)}async claimRewards(t,e,a,i){var n;const o=await A(t,this.contract.methods.claimFor,e,a);return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.claimFor,e,a)}async allocateRewards(t,e,a,i,n){var o;for(let t=0;t<a.length;t++)a[t]=await this.amountToUnits(i,a[t]);const s=await A(t,this.contract.methods.allocate,e,a,i);return n?s:await R(t,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.allocate,e,a,i)}}class ut extends tt{getDefaultAbi(){return f.abi}async getMultipleAvailableRewards(t,e){const a=await this.contract.methods.claimables(t,e).call(),i=[];for(let t=0;t<a.length;t++)i.push(await this.unitsToAmount(e[t],a[t]));return i}async claimMultipleRewards(t,e,a,i){var n;const o=await A(t,this.contract.methods.claimMultiple,e,a);return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.claimMultiple,e,a)}}class wt{constructor(t){this.aquariusURL=void 0,this.aquariusURL=t}async resolve(t,e){const a=this.aquariusURL+"/api/aquarius/assets/ddo/"+t;try{const t=await n(a,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return await t.json();throw new Error("HTTP request failed with status "+t.status)}catch(t){throw B.error(t),new Error("HTTP request failed")}}async waitForAqua(t,e,a){let i=0;do{try{const i=this.aquariusURL+"/api/aquarius/assets/ddo/"+t,o=await n(i,{method:"GET",headers:{"Content-Type":"application/json"},signal:a});if(o.ok){const t=await o.json();if(!e)return t;if(t.event&&t.event.txid===e)return t}}catch(t){}await W(1500),i++}while(i<100);return null}async validate(t,e){const a={valid:!1};let i;try{const o=this.aquariusURL+"/api/aquarius/assets/ddo/validate",s=await n(o,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:e});i=await s.json(),200===s.status?(a.valid=!0,a.hash=i.hash,a.proof={validatorAddress:i.publicKey,r:i.r[0],s:i.s[0],v:i.v}):(a.errors=i,B.error("validate Metadata failed:",s.status,a.errors))}catch(t){B.error("Error validating metadata: ",t)}return a}async getAssetMetadata(t,e){const a=this.aquariusURL+"/api/aquarius/assets/metadata/"+t;try{const t=await n(a,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return t.json();throw new Error("getAssetMetadata failed: "+t.status+t.statusText)}catch(t){throw B.error("Error getting metadata: ",t),new Error("Error getting metadata: "+t)}}async querySearch(t,e){const a=this.aquariusURL+"/api/aquarius/assets/query";try{const i=await n(a,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:e});if(i.ok)return i.json();throw new Error("querySearch failed: "+i.status+i.statusText)}catch(t){throw B.error("Error querying metadata: ",t),new Error("Error querying metadata: "+t)}}}class mt{async getEndpoints(t){try{const e=await this.getData(t);return await e.json()}catch(t){throw B.error("Finding the service endpoints failed:",t),new Error("HTTP request failed calling Provider")}}getEndpointURL(t,e){return t?t.find(t=>t.serviceName===e):null}async getServiceEndpoints(t,e){const a=[];for(const i in e.serviceEndpoints)a.push({serviceName:i,method:e.serviceEndpoints[i][0],urlPath:t+e.serviceEndpoints[i][1]});return a}async getNonce(t,e,a,i,o){i||(i=await this.getEndpoints(t)),o||(o=await this.getServiceEndpoints(t,i));const s=this.getEndpointURL(o,"nonce")?this.getEndpointURL(o,"nonce").urlPath:null;if(!s)return null;try{const t=await n(s+`?userAddress=${e}`,{method:"GET",headers:{"Content-Type":"application/json"},signal:a});return(await t.json()).nonce.toString()}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async signProviderRequest(t,e,a,i){const n=t.utils.soliditySha3({t:"bytes",v:t.utils.utf8ToHex(a)});return t&&t.currentProvider&&t.currentProvider.isMetaMask?await t.eth.personal.sign(n,e,i):await t.eth.sign(n,e)}async encrypt(t,e,a){const i=await this.getEndpoints(e),o=await this.getServiceEndpoints(e,i),s=this.getEndpointURL(o,"encrypt")?this.getEndpointURL(o,"encrypt").urlPath:null;if(!s)return null;try{const e=await n(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:a});return await e.text()}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async checkDidFiles(t,e,a,i=!1,o){const s=await this.getEndpoints(a),r=await this.getServiceEndpoints(a,s),c={did:t,serviceId:e,checksum:i},l=[],h=this.getEndpointURL(r,"fileinfo")?this.getEndpointURL(r,"fileinfo").urlPath:null;if(!h)return null;try{const t=await n(h,{method:"POST",body:JSON.stringify(c),headers:{"Content-Type":"application/json"},signal:o}),e=await t.json();for(const t of e)l.push(t);return l}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async getFileInfo(t,e,a=!1,i){const o=await this.getEndpoints(e),s=await this.getServiceEndpoints(e,o),r=b({},t,{checksum:a}),c=[],l=this.getEndpointURL(s,"fileinfo")?this.getEndpointURL(s,"fileinfo").urlPath:null;if(!l)return null;try{const t=await n(l,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"},signal:i}),e=await t.json();for(const t of e)c.push(t);return c}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async getComputeEnvironments(t,e){var a;const i=await this.getEndpoints(t),o=await this.getServiceEndpoints(t,i),s=null==(a=this.getEndpointURL(o,"computeEnvironments"))?void 0:a.urlPath;if(!s)return null;try{const t=await n(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});return await t.json()}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async initialize(t,e,a,i,o,s,r,c,l){const h=await this.getEndpoints(o),d=await this.getServiceEndpoints(o,h);let u=this.getEndpointURL(d,"initialize")?this.getEndpointURL(d,"initialize").urlPath:null;if(!u)return null;u+=`?documentId=${t}`,u+=`&serviceId=${e}`,u+=`&fileIndex=${a}`,u+=`&consumerAddress=${i}`,r&&(u+="&userdata="+encodeURI(JSON.stringify(r))),c&&(u+="&environment="+encodeURI(c)),l&&(u+="&validUntil="+l);try{const t=await n(u,{method:"GET",headers:{"Content-Type":"application/json"},signal:s});return await t.json()}catch(t){throw B.error(t),new Error("Asset URL not found or not available.")}}async initializeCompute(t,e,a,i,o,s,r){const c=await this.getEndpoints(o),l=await this.getServiceEndpoints(o,c),h={datasets:t,algorithm:e,compute:{env:a,validUntil:i},consumerAddress:s},d=this.getEndpointURL(l,"initializeCompute")?this.getEndpointURL(l,"initializeCompute").urlPath:null;if(!d)return null;try{const t=await n(d,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json"},signal:r});return await t.json()}catch(t){throw B.error(t),new Error("ComputeJob cannot be initialized")}}async getDownloadUrl(t,e,a,i,n,o,s,r){const c=await this.getEndpoints(o),l=await this.getServiceEndpoints(o,c),h=this.getEndpointURL(l,"download")?this.getEndpointURL(l,"download").urlPath:null;if(!h)return null;const d=Date.now();let u=h;return u+=`?fileIndex=${i}`,u+=`&documentId=${t}`,u+=`&transferTxId=${n}`,u+=`&serviceId=${a}`,u+=`&consumerAddress=${e}`,u+=`&nonce=${d}`,u+=`&signature=${await this.signProviderRequest(s,e,t+d)}`,r&&(u+="&userdata="+encodeURI(JSON.stringify(r))),u}async computeStart(t,e,a,i,o,s,r,c,l){const h=await this.getEndpoints(t),d=await this.getServiceEndpoints(t,h),u=this.getEndpointURL(d,"computeStart")?this.getEndpointURL(d,"computeStart").urlPath:null,w=Date.now();let m=a;m+=o.documentId,m+=w;const p=await this.signProviderRequest(e,a,m),g=Object();if(g.consumerAddress=a,g.signature=p,g.nonce=w,g.environment=i,g.dataset=o,g.algorithm=s,g.additionalDatasets&&(g.additionalDatasets=c),l&&(g.output=l),!u)return null;try{const t=await n(u,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json"},signal:r});return null!=t&&t.ok?await t.json():(B.error("Compute start failed: ",t.status,t.statusText,await t.json()),B.error("Payload was:",g),null)}catch(t){throw B.error("Compute start failed:"),B.error(t),B.error("Payload was:",g),new Error("HTTP request failed calling Provider")}}async computeStop(t,e,a,i,o,s){const r=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,r),l=this.getEndpointURL(c,"computeStop")?this.getEndpointURL(c,"computeStop").urlPath:null,h=await this.getNonce(i,e,s,r,c);let d=e;d+=a||"",d+=t&&`${this.noZeroX(t)}`||"",d+=h;const u=await this.signProviderRequest(o,e,d),w=Object();if(w.signature=u,w.documentId=this.noZeroX(t),w.consumerAddress=e,a&&(w.jobId=a),!l)return null;try{const t=await n(l,{method:"PUT",body:JSON.stringify(w),headers:{"Content-Type":"application/json"},signal:s});return null!=t&&t.ok?await t.json():(B.error("Compute stop failed:",t.status,t.statusText),B.error("Payload was:",w),null)}catch(t){throw B.error("Compute stop failed:"),B.error(t),B.error("Payload was:",w),new Error("HTTP request failed calling Provider")}}async computeStatus(t,e,a,i,o){const s=await this.getEndpoints(t),r=await this.getServiceEndpoints(t,s),c=this.getEndpointURL(r,"computeStatus")?this.getEndpointURL(r,"computeStatus").urlPath:null;let l=`?consumerAddress=${e}`;if(l+=i&&`&documentId=${this.noZeroX(i)}`||"",l+=a&&`&jobId=${a}`||"",!c)return null;try{const t=await n(c+l,{method:"GET",headers:{"Content-Type":"application/json"},signal:o});return null!=t&&t.ok?await t.json():(B.error("Get compute status failed:",t.status,t.statusText),null)}catch(t){throw B.error("Get compute status failed"),B.error(t),new Error("HTTP request failed calling Provider")}}async getComputeResultUrl(t,e,a,i,n){const o=await this.getEndpoints(t),s=await this.getServiceEndpoints(t,o),r=this.getEndpointURL(s,"computeResult")?this.getEndpointURL(s,"computeResult").urlPath:null,c=Date.now();let l=a;l+=i,l+=n.toString(),l+=c;const h=await this.signProviderRequest(e,a,l);if(!r)return null;let d=r;return d+=`?consumerAddress=${a}`,d+=`&jobId=${i}`,d+=`&index=${n.toString()}`,d+=`&nonce=${c}`,d+=h&&`&signature=${h}`||"",d}async computeDelete(t,e,a,i,o,s){const r=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,r),l=this.getEndpointURL(c,"computeDelete")?this.getEndpointURL(c,"computeDelete").urlPath:null,h=await this.getNonce(i,e,s,r,c);let d=e;d+=a||"",d+=t&&`${this.noZeroX(t)}`||"",d+=h;const u=await this.signProviderRequest(o,e,d),w=Object();if(w.documentId=this.noZeroX(t),w.consumerAddress=e,w.jobId=a,u&&(w.signature=u),!l)return null;try{const t=await n(l,{method:"DELETE",body:JSON.stringify(w),headers:{"Content-Type":"application/json"},signal:s});return null!=t&&t.ok?await t.json():(B.error("Delete compute job failed:",t.status,t.statusText),B.error("Payload was:",w),null)}catch(t){throw B.error("Delete compute job failed:"),B.error(t),B.error("Payload was:",w),new Error("HTTP request failed calling Provider")}}async isValidProvider(t,e){try{const a=await n(t,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(null!=a&&a.ok){const t=await a.json();if(t&&t.providerAddress)return!0}return!1}catch(t){return B.error(`Error validating provider: ${t.message}`),!1}}noZeroX(t){return this.zeroXTransformer(t,!1)}zeroXTransformer(t="",e){const{valid:a,output:i}=this.inputMatch(t,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(e&&a?"0x":"")+i}inputMatch(t,e,a){if("string"!=typeof t)throw B.debug("Not input string:"),B.debug(t),new Error(`[${a}] Expected string, input type: ${typeof t}`);const i=t.match(e);return i?{valid:!0,output:i[1]}:(B.warn(`[${a}] Input transformation failed.`),{valid:!1,output:t})}async getData(t){return n(t,{method:"GET",headers:{"Content-type":"application/json"}})}}const pt=new mt;export{wt as Aquarius,y as Config,K as ConfigHelper,ot as Datatoken,dt as DfRewards,ut as DfStrategyV1,et as Dispenser,E as FEE_HISTORY_NOT_SUPPORTED,at as FixedRateExchange,F as GASLIMIT_DEFAULT,P as LogLevel,L as Logger,B as LoggerInstance,C as MAX_UINT_256,nt as Nft,st as NftFactory,mt as Provider,pt as ProviderInstance,it as Router,Y as SmartContract,tt as SmartContractWithAddress,ht as VeAllocate,ct as VeFeeDistributor,lt as VeFeeEstimate,rt as VeOcean,T as ZERO_ADDRESS,V as allowance,z as allowanceWei,D as amountToUnits,$ as approve,G as approveWei,Z as balance,A as calculateEstimatedGas,Q as configHelperNetworks,J as decimals,j as downloadFile,I as downloadFileBrowser,S as generateDid,U as generateDtName,M as getFairGasPrice,N as getHash,q as minAbi,R as sendTx,k as setContractDefaults,_ as signHash,W as sleep,H as transfer,x as unitsToAmount};
|
|
1
|
+
import t from"@oceanprotocol/contracts/addresses/address.json";import e from"bignumber.js";import a from"crypto-js/sha256";import i from"web3";import n from"cross-fetch";import s from"decimal.js";import o from"@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json";import r from"@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json";import c from"@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json";import l from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json";import h from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json";import d from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json";import u from"@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json";import w from"@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json";import m from"@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json";import p from"@oceanprotocol/contracts/artifacts/contracts/ve/veFeeEstimate.vy/veFeeEstimate.json";import g from"@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json";import f from"@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json";import v from"@oceanprotocol/contracts/artifacts/contracts/df/DFStrategyV1.sol/DFStrategyV1.json";class y{constructor(){this.nodeUri=void 0,this.providerAddress=void 0,this.metadataCacheUri=void 0,this.providerUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.datatokensABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.opfCommunityFeeCollector=void 0,this.sideStakingAddress=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.chainId=void 0,this.network=void 0,this.subgraphUri=void 0,this.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0,this.veAllocate=void 0,this.veOCEAN=void 0,this.veDelegation=void 0,this.veFeeDistributor=void 0,this.veDelegationProxy=void 0,this.DFRewards=void 0,this.DFStrategyV1=void 0,this.veFeeEstimate=void 0}}function b(){return b=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(t[i]=a[i])}return t},b.apply(this,arguments)}const T="0x0000000000000000000000000000000000000000",F=1e6,C="115792089237316195423570985008687907853269984665640564039457584007913129639934",E="Returned error: Method eth_feeHistory not supported.";function k(t,e){return e&&(e.transactionBlockTimeout&&(t.transactionBlockTimeout=e.transactionBlockTimeout),e.transactionConfirmationBlocks&&(t.transactionConfirmationBlocks=e.transactionConfirmationBlocks),e.transactionPollingTimeout&&(t.transactionPollingTimeout=e.transactionPollingTimeout)),t}async function M(t,a){const i=new e(await t.eth.getGasPrice());return a?i.multipliedBy(a).integerValue(e.ROUND_DOWN).toString(10):i.toString(10)}async function x(t,a,i,n){const s=new t.eth.Contract(q,a);let o=n||await s.methods.decimals().call();"0"===o&&(o=18);const r=new e(i).div(new e(10).exponentiatedBy(o));return e.config({EXPONENTIAL_AT:50}),r.toString()}async function D(t,a,i,n){const s=new t.eth.Contract(q,a);let o=n||await s.methods.decimals().call();return"0"===o&&(o=18),e.config({EXPONENTIAL_AT:50}),new e(i).times(new e(10).exponentiatedBy(o)).toFixed(0)}async function A(t,e,...a){return await e.apply(null,a).estimateGas({from:t},(t,e)=>t?1e6:e)}async function R(t,a,i,n,s,...o){const r={from:t,gas:a+1},c=await i.eth.getChainId();try{var l,h,d;const t=await i.eth.getFeeHistory(1,"latest",[75]);if(t&&null!=t&&null!=(l=t.baseFeePerGas)&&l[0]&&null!=t&&null!=(h=t.reward)&&null!=(d=h[0])&&d[0]){var u,w,m;let a=new e(null==t||null==(u=t.reward)||null==(w=u[0])?void 0:w[0]);n>1&&(a=a.multipliedBy(n)),r.maxPriorityFeePerGas=a.integerValue(e.ROUND_DOWN).toString(10),r.maxFeePerGas=a.plus(new e(null==t||null==(m=t.baseFeePerGas)?void 0:m[0]).multipliedBy(2)).integerValue(e.ROUND_DOWN).toString(10),r.maxPriorityFeePerGas=80001!==c&&137!==c||!new e(r.maxPriorityFeePerGas).lte(new e(3e10))?r.maxPriorityFeePerGas:new e(3e10).integerValue(e.ROUND_DOWN).toString(10),r.maxFeePerGas=80001!==c&&137!==c||!new e(r.maxFeePerGas).lte(new e(3e10))?r.maxFeePerGas:new e(3e10).integerValue(e.ROUND_DOWN).toString(10)}else r.gasPrice=await M(i,n)}catch(t){"Returned error: Method eth_feeHistory not supported."===(null==t?void 0:t.message)&&B.log("Not able to use EIP 1559, getFeeHistory method not suported by network."),r.gasPrice=await M(i,n)}return await s.apply(null,o).send(r)}var P,O={nouns:["Crab","Fish","Seal","Octopus","Shark","Seahorse","Walrus","Starfish","Whale","Orca","Penguin","Jellyfish","Squid","Lobster","Pelican","Shrimp","Oyster","Clam","Seagull","Dolphin","Shell","Cormorant","Otter","Anemone","Turtle","Coral","Ray","Barracuda","Krill","Anchovy","Angelfish","Barnacle","Clownfish","Cod","Cuttlefish","Eel","Fugu","Herring","Haddock","Ling","Mackerel","Manatee","Narwhal","Nautilus","Plankton","Porpoise","Prawn","Pufferfish","Swordfish","Tuna"],adjectives:["adamant","adroit","amatory","ambitious","amused","animistic","antic","arcadian","artistic","astonishing","astounding","baleful","bellicose","bilious","blissful","boorish","brave","breathtaking","brilliant","calamitous","caustic","cerulean","clever","charming","comely","competent","concomitant","confident","contumacious","corpulent","crapulous","creative","dazzling","dedicated","defamatory","delighted","delightful","determined","didactic","dilatory","dowdy","efficacious","effulgent","egregious","empowered","endemic","enthusiastic","equanimous","exceptional","execrable","fabulous","fantastic","fastidious","feckless","fecund","friable","fulsome","garrulous","generous","gentle","guileless","gustatory","heuristic","histrionic","hubristic","incendiary","incredible","insidious","insolent","inspired","intransigent","inveterate","invidious","invigorated","irksome","jejune","juicy","jocular","joyful","judicious","kind","lachrymose","limpid","loquacious","lovely","luminous","mannered","marvelous","mendacious","meretricious","minatory","mordant","motivated","munificent","nefarious","noxious","obtuse","optimistic","parsimonious","pendulous","pernicious","pervasive","petulant","passionate","phenomenal","platitudinous","pleasant","powerful","precipitate","propitious","puckish","querulous","quiescent","rebarbative","recalcitant","redolent","rhadamanthine","risible","ruminative","sagacious","salubrious","sartorial","sclerotic","serpentine","smart","spasmodic","strident","stunning","stupendous","taciturn","tactful","tasty","tenacious","tremendous","tremulous","trenchant","turbulent","turgid","ubiquitous","uxorious","verdant","vibrant","voluble","voracious","wheedling","withering","wonderful","zealous"]};function U(t){const e=t||O,a=Math.floor(Math.random()*e.adjectives.length),i=Math.floor(Math.random()*e.nouns.length),n=Math.floor(100*Math.random()),s=e.adjectives[a].replace(/^\w/,t=>t.toUpperCase()),o=e.nouns[i].replace(/^\w/,t=>t.toUpperCase());return{name:`${s} ${o} Token`,symbol:`${(s.substring(0,3)+o.substring(0,3)).toUpperCase()}-${n}`}}function S(t,e){return t=i.utils.toChecksumAddress(t),`did:op:${a(t+e.toString(10)).toString()}`}function N(t){return a(t).toString()}async function I(t){const e=(await n(t,{method:"HEAD"})).headers.get("content-disposition"),a=null!=e&&e.split("=")[1]?null==e?void 0:e.split("=")[1]:"file",i=new XMLHttpRequest;i.responseType="blob",i.open("GET",t),i.onload=()=>{const t=window.URL.createObjectURL(i.response),e=document.createElement("a");e.href=t,e.setAttribute("download",a),document.body.appendChild(e),e.click(),e.remove(),window.URL.revokeObjectURL(t)},i.send(null)}async function j(t,e){const a=await n(t);if(!a.ok)throw new Error("Response error.");let i;try{i=a.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(a){try{i=t.split("/").pop()}catch(t){i=`file${e}`}}return{data:await a.arrayBuffer(),filename:i}}async function W(t){return new Promise(e=>{setTimeout(e,t)})}!function(t){t[t.None=-1]="None",t[t.Error=0]="Error",t[t.Warn=1]="Warn",t[t.Log=2]="Log",t[t.Verbose=3]="Verbose"}(P||(P={}));class L{constructor(t=P.Error){this.logLevel=void 0,this.logLevel=t}setLevel(t){this.logLevel=t}bypass(...t){this.dispatch("log",-Infinity,...t)}debug(...t){this.dispatch("debug",P.Verbose,...t)}log(...t){this.dispatch("log",P.Log,...t)}warn(...t){this.dispatch("warn",P.Warn,...t)}error(...t){this.dispatch("error",P.Error,...t)}dispatch(t,e,...a){this.logLevel>=e&&console[t](...a)}}const B=new L,q=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}];async function $(t,e,a){let i=await t.eth.sign(e,a);i=i.substr(2);const n="0x"+i.slice(0,64),s="0x"+i.slice(64,128);let o="0x"+i.slice(128,130);return"0x00"===o&&(o="0x1b"),"0x01"===o&&(o="0x1c"),{v:o,r:n,s}}async function _(t,e,a,i,n,o,r=!1,c,l){const h=new t.eth.Contract(q,i);if(!r){const e=await V(t,i,a,n);if(new s(e).greaterThanOrEqualTo(new s(o)))return new s(e).toNumber()}const d=await D(t,i,o,c),u=await A(a,h.methods.approve,n,d);return l?u:await R(a,u+1,t,null==e?void 0:e.gasFeeMultiplier,h.methods.approve,n,d)}async function G(t,a,i,n,o,r,c=!1,l){const h=new t.eth.Contract(q,n);if(!c){const a=await z(t,n,i,o);if(new e(a).gt(new e(r)))return new s(a).toNumber()}let d=null;const u=await A(i,h.methods.approve,o,r);if(l)return u;try{d=await R(i,u+1,t,null==a?void 0:a.gasFeeMultiplier,h.methods.approve,o,r)}catch(t){B.error(`ERROR: Failed to approve spender to spend tokens : ${t.message}`)}return d}async function H(t,e,a,i,n,s,o){const r=new t.eth.Contract(q,i),c=await D(t,i,s),l=await A(a,r.methods.transfer,n,c);return o?l:await R(a,l+1,t,null==e?void 0:e.gasFeeMultiplier,r.methods.transfer,n,c)}async function V(t,e,a,i,n){const s=new t.eth.Contract(q,e),o=await s.methods.allowance(a,i).call();return await x(t,e,o,n)}async function Z(t,e,a,i){const n=new t.eth.Contract(q,e),s=await n.methods.balanceOf(a).call();return await x(t,e,s,i)}async function z(t,e,a,i){const n=new t.eth.Contract(q,e);return await n.methods.allowance(a,i).call()}async function J(t,e){const a=new t.eth.Contract(q,e);return await a.methods.decimals().call()}const X={chainId:null,network:"unknown",metadataCacheUri:"https://v4.aquarius.oceanprotocol.com",nodeUri:"http://127.0.0.1:8545",providerUri:"https://v4.provider.oceanprotocol.com",subgraphUri:null,explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},Q=[b({},X),b({},X,{chainId:8996,network:"development",metadataCacheUri:"http://172.15.0.5:5000",providerUri:"http://172.15.0.4:8030",subgraphUri:"https://172.15.0.15:8000"}),b({},X,{chainId:5,network:"goerli",nodeUri:"https://goerli.infura.io/v3",subgraphUri:"https://v4.subgraph.goerli.oceanprotocol.com",explorerUri:"https://goerli.etherscan.io",gasFeeMultiplier:1.1}),b({},X,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",subgraphUri:"https://v4.subgraph.mainnet.oceanprotocol.com",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05}),b({},X,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",subgraphUri:"https://v4.subgraph.polygon.oceanprotocol.com",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",gasFeeMultiplier:1.6}),b({},X,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",providerUri:"https://v4.provider.gaiaxtestnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com"}),b({},X,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",subgraphUri:"https://v4.subgraph.mumbai.oceanprotocol.com",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1}),b({},X,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",subgraphUri:"https://v4.subgraph.bsc.oceanprotocol.com",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05}),b({},X,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",subgraphUri:"https://v4.subgraph.energyweb.oceanprotocol.com",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05}),b({},X,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",subgraphUri:"https://v4.subgraph.moonriver.oceanprotocol.com",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05})];class K{getAddressesFromEnv(e,a){let i;if(a){const{FixedPrice:t,Dispenser:n,ERC721Factory:s,OPFCommunityFeeCollector:o,Ocean:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:f}=a[e];i=b({nftFactoryAddress:s,opfCommunityFeeCollector:o,fixedRateExchangeAddress:t,dispenserAddress:n,oceanTokenAddress:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:f},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}else if(t[e]){const{FixedPrice:a,Dispenser:n,OPFCommunityFeeCollector:s,ERC721Factory:o,Ocean:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:f}=t[e];i=b({nftFactoryAddress:o,opfCommunityFeeCollector:s,fixedRateExchangeAddress:a,dispenserAddress:n,oceanTokenAddress:r,chainId:c,startBlock:l,veAllocate:h,veOCEAN:d,veDelegation:u,veFeeDistributor:w,veDelegationProxy:m,DFRewards:p,DFStrategyV1:g,veFeeEstimate:f},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}return i}getConfig(t,e){const a="string"==typeof t?"network":"chainId";let i=Q.find(e=>e[a]===t);return i?(i=b({},i,this.getAddressesFromEnv(i.network)),b({},i,{nodeUri:e?`${i.nodeUri}/${e}`:i.nodeUri})):(B.error(`No config found for given network '${t}'`),null)}}class Y{constructor(t,e,a,i){this.web3=void 0,this.config=void 0,this.abi=void 0,this.web3=t,this.config=a||(new K).getConfig(e||"unknown"),this.abi=i||this.getDefaultAbi()}async amountToUnits(t,e,a){return D(this.web3,t,e,a)}async unitsToAmount(t,e,a){return x(this.web3,t,e,a)}async getFairGasPrice(){var t;return M(this.web3,null==(t=this.config)?void 0:t.gasFeeMultiplier)}getContract(t,e,a){return k(new this.web3.eth.Contract(a||this.abi,t,{from:e}),this.config)}}class tt extends Y{constructor(t,e,a,i,n){super(e,a,i,n),this.address=void 0,this.contract=void 0,this.address=t,this.contract=this.getContract(this.address)}}class et extends tt{getDefaultAbi(){return o.abi}async status(t){const e=await this.contract.methods.status(t).call();if(!e)throw new Error("Np dispenser found for the given datatoken address");return e.maxTokens=this.web3.utils.fromWei(e.maxTokens),e.maxBalance=this.web3.utils.fromWei(e.maxBalance),e.balance=this.web3.utils.fromWei(e.balance),e}async create(t,e,a,i,n,s){var o;const r=await A(e,this.contract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(i),e,n);return s?r:await R(e,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(i),e,n)}async activate(t,e,a,i,n){var s;const o=await A(i,this.contract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a));return n?o:await R(i,o+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a))}async deactivate(t,e,a){var i;const n=await A(e,this.contract.methods.deactivate,t);return a?n:await R(e,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.deactivate,t)}async setAllowedSwapper(t,e,a,i){var n;const s=await A(e,this.contract.methods.setAllowedSwapper,t,a);return i?s:await R(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setAllowedSwapper,t,a)}async dispense(t,e,a="1",i,n){var s;const o=await A(e,this.contract.methods.dispense,t,this.web3.utils.toWei(a),i);return n?o:await R(e,o+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.dispense,t,this.web3.utils.toWei(a),i)}async ownerWithdraw(t,e,a){var i;const n=await A(e,this.contract.methods.ownerWithdraw,t);return a?n:await R(e,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.ownerWithdraw,t)}async isDispensable(t,e,a,i="1"){const n=await this.status(t);return!(!n||!1===n.active||new s(await e.balance(t,a)).greaterThanOrEqualTo(n.maxBalance)||new s(String(i)).greaterThan(n.maxTokens)||!new s(n.balance).greaterThanOrEqualTo(i)&&!0!==n.isMinter)}}class at extends tt{getDefaultAbi(){return r.abi}async generateExchangeId(t,e){return await this.contract.methods.generateExchangeId(t,e).call()}async buyDatatokens(t,e,a,i,n=T,s="0",o){var r;const c=await this.getExchange(e),l=this.web3.utils.toWei(s),h=await this.amountToUnits(c.datatoken,a,+c.dtDecimals),d=await this.amountToUnits(c.baseToken,i,+c.btDecimals),u=await A(t,this.contract.methods.buyDT,e,h,d,n,l);return o?u:await R(t,u+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.buyDT,e,h,d,n,l)}async sellDatatokens(t,e,a,i,n=T,s="0",o){var r;const c=await this.getExchange(e),l=this.web3.utils.toWei(s),h=await this.amountToUnits(c.datatoken,a,+c.dtDecimals),d=await this.amountToUnits(c.baseToken,i,+c.btDecimals),u=await A(t,this.contract.methods.sellDT,e,h,d,n,l);return o?u:await R(t,u+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.sellDT,e,h,d,n,l)}async getNumberOfExchanges(){return await this.contract.methods.getNumberOfExchanges().call()}async setRate(t,e,a,i){var n;const s=await A(t,this.contract.methods.setRate,e,this.web3.utils.toWei(a));return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setRate,e,this.web3.utils.toWei(a))}async setAllowedSwapper(t,e,a,i){var n;const s=await A(t,this.contract.methods.setAllowedSwapper,e,a);return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setAllowedSwapper,e,a)}async activate(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!0===n.active)return null;const s=await A(t,this.contract.methods.toggleExchangeState,e);return a?s:await R(t,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleExchangeState,e)}async deactivate(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!1===n.active)return null;const s=await A(t,this.contract.methods.toggleExchangeState,e);return a?s:await R(t,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleExchangeState,e)}async getRate(t){const e=await this.contract.methods.getRate(t).call();return await this.web3.utils.fromWei(e)}async getDatatokenSupply(t){const e=await this.contract.methods.getDTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.datatoken,e,+a.dtDecimals)}async getBasetokenSupply(t){const e=await this.contract.methods.getBTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.baseToken,e,+a.btDecimals)}async getAllowedSwapper(t){return await this.contract.methods.getAllowedSwapper(t).call()}async calcBaseInGivenDatatokensOut(t,e,a="0"){const i=await this.getExchange(t),n=await this.contract.methods.calcBaseInGivenOutDT(t,await this.amountToUnits(i.datatoken,e,+i.dtDecimals),this.web3.utils.toWei(a)).call();return{baseTokenAmount:await this.unitsToAmount(i.baseToken,n.baseTokenAmount,+i.btDecimals),marketFeeAmount:await this.unitsToAmount(i.baseToken,n.marketFeeAmount,+i.btDecimals),oceanFeeAmount:await this.unitsToAmount(i.baseToken,n.oceanFeeAmount,+i.btDecimals),consumeMarketFeeAmount:await this.unitsToAmount(i.baseToken,n.consumeMarketFeeAmount,+i.btDecimals)}}async getAmountBasetokensOut(t,e,a="0"){const i=await this.getExchange(t),n=await this.contract.methods.calcBaseOutGivenInDT(t,await this.amountToUnits(i.datatoken,e,+i.dtDecimals),this.web3.utils.toWei(a)).call();return await this.unitsToAmount(i.baseToken,n[0],+i.btDecimals)}async getExchange(t){const e=await this.contract.methods.getExchange(t).call();return e.dtDecimals=e.dtDecimals.toString(),e.btDecimals=e.btDecimals.toString(),e.dtBalance=await this.unitsToAmount(e.datatoken,e.dtBalance,+e.dtDecimals),e.btBalance=await this.unitsToAmount(e.baseToken,e.btBalance,+e.btDecimals),e.dtSupply=await this.unitsToAmount(e.datatoken,e.dtSupply,+e.dtDecimals),e.btSupply=await this.unitsToAmount(e.baseToken,e.btSupply,+e.btDecimals),e.fixedRate=this.web3.utils.fromWei(e.fixedRate),e.exchangeId=t,e}async getFeesInfo(t){const e=await this.contract.methods.getFeesInfo(t).call();e.opcFee=this.web3.utils.fromWei(e.opcFee.toString()),e.marketFee=this.web3.utils.fromWei(e.marketFee.toString());const a=await this.getExchange(t);return e.marketFeeAvailable=await this.unitsToAmount(a.baseToken,e.marketFeeAvailable,+a.btDecimals),e.oceanFeeAvailable=await this.unitsToAmount(a.baseToken,e.oceanFeeAvailable,+a.btDecimals),e.exchangeId=t,e}async getExchanges(){return await this.contract.methods.getExchanges().call()}async isActive(t){return await this.contract.methods.isActive(t).call()}async activateMint(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!0===n.withMint)return null;const s=await A(t,this.contract.methods.toggleMintState,e,!0);return a?s:await R(t,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleMintState,e,!0)}async deactivateMint(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!1===n.withMint)return null;const s=await A(t,this.contract.methods.toggleMintState,e,!1);return a?s:await R(t,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleMintState,e,!1)}async collectBasetokens(t,e,a,i){var n;if(!await this.getExchange(e))return null;const s=await this.contract.methods.getExchange(e).call(),o=await this.amountToUnits(s.baseToken,a,+s.btDecimals),r=await A(t,this.contract.methods.collectBT,e,o);return i?r:await R(t,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.collectBT,e,o)}async collectDatatokens(t,e,a,i){var n;if(!await this.getExchange(e))return null;const s=await this.contract.methods.getExchange(e).call(),o=await this.amountToUnits(s.datatoken,a,+s.dtDecimals),r=await A(t,this.contract.methods.collectDT,e,o);return i?r:await R(t,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.collectDT,e,o)}async collectMarketFee(t,e,a){var i;if(!await this.getExchange(e))return null;const n=await A(t,this.contract.methods.collectMarketFee,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.collectMarketFee,e)}async collectOceanFee(t,e,a){var i;if(!await this.getExchange(e))return null;const n=await A(t,this.contract.methods.collectOceanFee,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.collectOceanFee,e)}async getOPCCollector(){return await this.contract.methods.opcCollector().call()}async getRouter(){return await this.contract.methods.router().call()}async getExchangeOwner(t){return await(await this.getExchange(t)).exchangeOwner}async updateMarketFee(t,e,a,i){var n;const s=await A(t,this.contract.methods.updateMarketFee,e,this.web3.utils.toWei(a));return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.updateMarketFee,e,this.web3.utils.toWei(a))}async updateMarketFeeCollector(t,e,a,i){var n;const s=await A(t,this.contract.methods.updateMarketFeeCollector,e,a);return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.updateMarketFeeCollector,e,a)}}class it extends tt{getDefaultAbi(){return c.abi}async buyDatatokenBatch(t,e,a){var i;const n=await A(t,this.contract.methods.buyDTBatch,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.buyDTBatch,e)}async isApprovedToken(t){return await this.contract.methods.isApprovedToken(t).call()}async isFixedPrice(t){return await this.contract.methods.isFixedRateContract(t).call()}async getOwner(){return await this.contract.methods.routerOwner().call()}async getNFTFactory(){return await this.contract.methods.factory().call()}async addApprovedToken(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.addApprovedToken,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addApprovedToken,e)}async removeApprovedToken(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.removeApprovedToken,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeApprovedToken,e)}async addFixedRateContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.addFixedRateContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addFixedRateContract,e)}async removeFixedRateContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.removeFixedRateContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeFixedRateContract,e)}async addDispenserContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.addDispenserContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addDispenserContract,e)}async removeDispenserContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await A(t,this.contract.methods.removeDispenserContract,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeDispenserContract,e)}async getOPCFee(t){return await this.contract.methods.getOPCFee(t).call()}async getCurrentOPCFee(){return await this.contract.methods.swapOceanFee().call()}async updateOPCFee(t,e,a,i,n,s){var o;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const r=await A(t,this.contract.methods.updateOPCFee,e,a,i,n);return s?r:await R(t,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.updateOPCFee,e,a,i,n)}}class nt extends Y{getDefaultAbi(){return d.abi}async createDatatoken(t,e,a,i,n,s,o,r,c,l,h,d){var u,w,m,p;if(!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not DatatokenDeployer");h||(h=1),c&&l||({name:c,symbol:l}=U());const g=this.getContract(t),f=await A(e,g.methods.createERC20,h,[c,l],[a,i,n,s],[this.web3.utils.toWei(r),this.web3.utils.toWei(o)],[]);if(d)return f;const v=await R(e,f+1,this.web3,null==(u=this.config)?void 0:u.gasFeeMultiplier,g.methods.createERC20,h,[c,l],[a,i,n,s],[this.web3.utils.toWei(r),this.web3.utils.toWei(o)],[]);return null==v||null==(w=v.events)||null==(m=w.TokenCreated)||null==(p=m.returnValues)?void 0:p[0]}async addManager(t,e,a,i){var n;const s=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const o=await A(e,s.methods.addManager,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.addManager,a)}async removeManager(t,e,a,i){var n;const s=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const o=await A(e,s.methods.removeManager,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.removeManager,a)}async addDatatokenDeployer(t,e,a,i){var n;const s=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const o=await A(e,s.methods.addToCreateERC20List,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.addToCreateERC20List,a)}async removeDatatokenDeployer(t,e,a,i){var n;const s=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e===a&&!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");const o=await A(e,s.methods.removeFromCreateERC20List,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.removeFromCreateERC20List,a)}async addMetadataUpdater(t,e,a,i){var n;const s=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const o=await A(e,s.methods.addToMetadataList,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.addToMetadataList,a)}async removeMetadataUpdater(t,e,a,i){var n;const s=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");const o=await A(e,s.methods.removeFromMetadataList,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.removeFromMetadataList,a)}async addStoreUpdater(t,e,a,i){var n;const s=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const o=await A(e,s.methods.addTo725StoreList,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.addTo725StoreList,a)}async removeStoreUpdater(t,e,a,i){var n;const s=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).store)throw new Error("Caller is not Manager nor storeUpdater");const o=await A(e,s.methods.removeFrom725StoreList,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.removeFrom725StoreList,a)}async cleanPermissions(t,e,a){var i;const n=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const s=await A(e,n.methods.cleanPermissions);return a?s:await R(e,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,n.methods.cleanPermissions)}async transferNft(t,e,a,i,n){var s;const o=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const r=i||1,c=await A(e,o.methods.transferFrom,e,a,r);return n?c:await R(e,c+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.transferFrom,e,a,r)}async safeTransferNft(t,e,a,i,n){var s;const o=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const r=i||1,c=await A(e,o.methods.safeTransferFrom,e,a,r);return n?c:await R(e,c+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.safeTransferFrom,e,a,r)}async setMetadata(t,e,a,i,n,s,o,r,c,l){var h;const d=this.getContract(t);if(c||(c=[]),!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const u=await A(e,d.methods.setMetaData,a,i,n,s,o,r,c);return l?u:await R(e,u+1,this.web3,null==(h=this.config)?void 0:h.gasFeeMultiplier,d.methods.setMetaData,a,i,n,s,o,r,c)}async setMetadataAndTokenURI(t,e,a,i){var n;const s=this.getContract(t);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const o=b({},a,{metadataProofs:a.metadataProofs||[]}),r=await A(e,s.methods.setMetaDataAndTokenURI,o);return i?r:await R(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.setMetaDataAndTokenURI,o)}async setMetadataState(t,e,a,i){var n;const s=this.getContract(t);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const o=await A(e,s.methods.setMetaDataState,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.setMetaDataState,a)}async setTokenURI(t,e,a,i){var n;const s=this.getContract(t),o=await A(e,s.methods.setTokenURI,"1",a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.setTokenURI,"1",a)}async getNftOwner(t){const e=this.getContract(t);return await e.methods.ownerOf(1).call()}async getNftPermissions(t,e){const a=this.getContract(t);return await a.methods.getPermissions(e).call()}async getMetadata(t){const e=this.getContract(t);return await e.methods.getMetaData().call()}async isDatatokenDeployer(t,e){const a=this.getContract(t);return await a.methods.isERC20Deployer(e).call()}async setData(t,e,a,i){var n;if(!0!==(await this.getNftPermissions(t,e)).store)throw new Error("User is not ERC20 store updater");const s=this.getContract(t),o=this.web3.utils.keccak256(a),r=this.web3.utils.asciiToHex(i),c=await A(e,s.methods.setNewData,o,r);return await R(e,c+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.setNewData,o,r)}async getData(t,e){const a=this.getContract(t),i=this.web3.utils.keccak256(e),n=await a.methods.getData(i).call();return n?this.web3.utils.hexToAscii(n):null}async getTokenURI(t,e){const a=this.getContract(t);return await a.methods.tokenURI(e).call()}}class st extends Y{getDefaultAbi(){return l.abi}constructor(t,e,a,i,n){super(t,e,a,i),this.abiEnterprise=void 0,this.nft=void 0,this.abiEnterprise=n||h.abi,this.nft=new nt(this.web3)}async approve(t,e,a,i,n){var s;const o=this.getContract(t),r=await A(i,o.methods.approve,e,this.web3.utils.toWei(a));return n?r:await R(i,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.approve,e,this.web3.utils.toWei(a))}async createFixedRate(t,e,a,i){var n;const s=this.getContract(t);if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");a.allowedConsumer||(a.allowedConsumer=T);const o=!1===a.withMint?0:1,r=await A(e,s.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,o]);return i?r:await R(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,o])}async createDispenser(t,e,a,i,n){var s;if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");const o=this.getContract(t);i.allowedSwapper||(i.allowedSwapper=T),i.withMint=!1!==i.withMint;const r=await A(e,o.methods.createDispenser,a,i.maxTokens,i.maxBalance,i.withMint,i.allowedSwapper);return n?r:await R(e,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.createDispenser,a,i.maxTokens,i.maxBalance,i.withMint,i.allowedSwapper)}async mint(t,e,a,i,n){const o=this.getContract(t);if(!0!==(await this.getPermissions(t,e)).minter)throw new Error("Caller is not Minter");const r=await this.getCap(t);if(new s(r).gte(a)){var c;const t=await A(e,o.methods.mint,i||e,this.web3.utils.toWei(a));return n?t:await R(e,t+1,this.web3,null==(c=this.config)?void 0:c.gasFeeMultiplier,o.methods.mint,i||e,this.web3.utils.toWei(a))}throw new Error("Mint amount exceeds cap available")}async addMinter(t,e,a,i){var n;const s=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const o=await A(e,s.methods.addMinter,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.addMinter,a)}async removeMinter(t,e,a,i){var n;const s=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const o=await A(e,s.methods.removeMinter,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.removeMinter,a)}async addPaymentManager(t,e,a,i){var n;const s=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const o=await A(e,s.methods.addPaymentManager,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.addPaymentManager,a)}async removePaymentManager(t,e,a,i){var n;const s=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const o=await A(e,s.methods.removePaymentManager,a);return i?o:await R(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.removePaymentManager,a)}async setPaymentCollector(t,e,a,i){var n;const s=this.getContract(t),o=(await this.getPermissions(t,e)).paymentManager,r=!o&&await this.getNFTAddress(t),c=r&&await this.nft.getNftOwner(r)===e,l=r&&!c&&await this.nft.getNftPermissions(r,e);if(!o&&!c&&!(null==l?void 0:l.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");const h=await A(e,s.methods.setPaymentCollector,a);return i?h:await R(e,h+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.setPaymentCollector,a)}async getPaymentCollector(t){const e=this.getContract(t);return await e.methods.getPaymentCollector().call()}async transfer(t,e,a,i){const n=this.web3.utils.toWei(a);return this.transferWei(t,e,n,i)}async transferWei(t,e,a,i,n){var s;const o=this.getContract(t),r=await A(i,o.methods.transfer,e,a);return n?r:await R(i,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.transfer,e,a)}async startOrder(t,e,a,i,n,s,o){var r;const c=this.getContract(t);s||(s={consumeMarketFeeAddress:T,consumeMarketFeeToken:T,consumeMarketFeeAmount:"0"});const l=await A(e,c.methods.startOrder,a,i,n,s);return o?l:await R(e,l+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,c.methods.startOrder,a,i,n,s)}async reuseOrder(t,e,a,i,n){var s;const o=this.getContract(t),r=await A(e,o.methods.reuseOrder,a,i);return n?r:await R(e,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.reuseOrder,a,i)}async buyFromFreAndOrder(t,e,a,i,n){var s;const o=this.getContract(t,null,this.abiEnterprise),r=await this.getFreOrderParams(i),c=await A(e,o.methods.buyFromFreAndOrder,a,r);return n?c:await R(e,c+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.buyFromFreAndOrder,a,r)}async buyFromDispenserAndOrder(t,e,a,i,n){var s;const o=this.getContract(t,null,this.abiEnterprise),r=await A(e,o.methods.buyFromDispenserAndOrder,a,i);return n?r:await R(e,r+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,o.methods.buyFromDispenserAndOrder,a,i)}async setData(t,e,a,i){var n;if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");const s=this.getContract(t),o=this.web3.utils.asciiToHex(a),r=await A(e,s.methods.setData,o);return i?r:await R(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,s.methods.setData,o)}async cleanPermissions(t,e,a){var i;if(await this.nft.getNftOwner(await this.getNFTAddress(t))!==e)throw new Error("Caller is NOT Nft Owner");const n=this.getContract(t),s=await A(e,n.methods.cleanPermissions);return a?s:await R(e,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,n.methods.cleanPermissions)}async getPermissions(t,e){const a=this.getContract(t);return await a.methods.permissions(e).call()}async getCap(t){const e=this.getContract(t),a=await e.methods.cap().call();return this.web3.utils.fromWei(a)}async getDecimals(t){const e=this.getContract(t);return await e.methods.decimals().call()}async getSymbol(t){const e=this.getContract(t);return await e.methods.symbol().call()}async getName(t){const e=this.getContract(t);return await e.methods.name().call()}async getNFTAddress(t){const e=this.getContract(t);return await e.methods.getERC721Address().call()}async isDatatokenDeployer(t,e){const a=this.getContract(t);return await a.methods.isERC20Deployer(e).call()}async balance(t,e){const a=this.getContract(t,e),i=await a.methods.balanceOf(e).call();return this.web3.utils.fromWei(i)}async setPublishingMarketFee(t,e,a,i,n,s){var o;const r=this.getContract(t,n);if((await r.methods.getPublishingMarketFee().call())[0]!==n)throw new Error("Caller is not the Publishing Market Fee Address");const c=await A(n,r.methods.setPublishingMarketFee,e,a,i);return s?c:await R(n,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.setPublishingMarketFee,e,a,i)}async getPublishingMarketFee(t,e){const a=this.getContract(t,e),i=await a.methods.getPublishingMarketFee().call();return{publishMarketFeeAddress:i[0],publishMarketFeeToken:i[1],publishMarketFeeAmount:i[2]}}async getFreOrderParams(t){return{exchangeContract:t.exchangeContract,exchangeId:t.exchangeId,maxBaseTokenAmount:await D(this.web3,t.baseTokenAddress,t.maxBaseTokenAmount,t.baseTokenDecimals),swapMarketFee:await D(this.web3,t.baseTokenAddress,t.swapMarketFee,t.baseTokenDecimals),marketFeeAddress:t.marketFeeAddress}}}class ot extends tt{getDefaultAbi(){return u.abi}async createNFT(t,e,a){var i,n,s,o;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){const{name:t,symbol:a}=U();e.name=t,e.symbol=a}if(e.templateIndex>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");if(!1===(await this.getNFTTemplate(e.templateIndex)).isActive)throw new Error("Template is not active");const r=await A(t,this.contract.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,T,T,e.tokenURI,e.transferable,e.owner);if(a)return r;const c=await R(t,r+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,T,T,e.tokenURI,e.transferable,e.owner);return null==c||null==(n=c.events)||null==(s=n.NFTCreated)||null==(o=s.returnValues)?void 0:o[0]}async getCurrentNFTCount(){return await this.contract.methods.getCurrentNFTCount().call()}async getCurrentTokenCount(){return await this.contract.methods.getCurrentTokenCount().call()}async getOwner(){return await this.contract.methods.owner().call()}async getCurrentNFTTemplateCount(){return await this.contract.methods.getCurrentNFTTemplateCount().call()}async getCurrentTokenTemplateCount(){return await this.contract.methods.getCurrentTemplateCount().call()}async getNFTTemplate(t){if(t>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return await this.contract.methods.getNFTTemplate(t).call()}async getTokenTemplate(t){return await this.contract.methods.getTokenTemplate(t).call()}async checkDatatoken(t){return await this.contract.methods.erc20List(t).call()}async checkNFT(t){return await this.contract.methods.erc721List(t).call()}async addNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===T)throw new Error("Template cannot be ZERO address");const n=await A(t,this.contract.methods.add721TokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.add721TokenTemplate,e)}async disableNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const n=await A(t,this.contract.methods.disable721TokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.disable721TokenTemplate,e)}async reactivateNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const n=await A(t,this.contract.methods.reactivate721TokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.reactivate721TokenTemplate,e)}async addTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===T)throw new Error("Template cannot be address ZERO");const n=await A(t,this.contract.methods.addTokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addTokenTemplate,e)}async disableTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!1===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already disabled");const n=await A(t,this.contract.methods.disableTokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.disableTokenTemplate,e)}async reactivateTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!0===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already active");const n=await A(t,this.contract.methods.reactivateTokenTemplate,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.reactivateTokenTemplate,e)}async startMultipleTokenOrder(t,e,a){var i;if(e.length>50)throw new Error("Too many orders");const n=await A(t,this.contract.methods.startMultipleTokenOrder,e);return a?n:await R(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.startMultipleTokenOrder,e)}async createNftWithDatatoken(t,e,a,i){var n;const s=this.getErcCreationParams(a),o=await A(t,this.contract.methods.createNftWithErc20,e,s);return i?o:await R(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.createNftWithErc20,e,s)}async createNftWithDatatokenWithFixedRate(t,e,a,i,n){var s;const o=this.getErcCreationParams(a),r=this.getFreCreationParams(i),c=await A(t,this.contract.methods.createNftWithErc20WithFixedRate,e,o,r);return n?c:await R(t,c+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.createNftWithErc20WithFixedRate,e,o,r)}async createNftWithDatatokenWithDispenser(t,e,a,n,s){var o;const r=this.getErcCreationParams(a);n.maxBalance=i.utils.toWei(n.maxBalance),n.maxTokens=i.utils.toWei(n.maxTokens);const c=await A(t,this.contract.methods.createNftWithErc20WithDispenser,e,r,n);return s?c:await R(t,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.createNftWithErc20WithDispenser,e,r,n)}getErcCreationParams(t){let e,a;return t.name&&t.symbol||({name:e,symbol:a}=U()),{templateIndex:t.templateIndex,strings:[t.name||e,t.symbol||a],addresses:[t.minter,t.paymentCollector,t.mpFeeAddress,t.feeToken],uints:[i.utils.toWei(t.cap),i.utils.toWei(t.feeAmount)],bytess:[]}}getFreCreationParams(t){t.allowedConsumer||(t.allowedConsumer=T);const e=!1===t.withMint?0:1;return{fixedPriceAddress:t.fixedRateAddress,addresses:[t.baseTokenAddress,t.owner,t.marketFeeCollector,t.allowedConsumer],uints:[t.baseTokenDecimals,t.datatokenDecimals,i.utils.toWei(t.fixedRate),i.utils.toWei(t.marketFee),e]}}}class rt extends tt{getDefaultAbi(){return w.abi}async lockTokens(t,e,a,i){var n;const s=await this.amountToUnits(await this.getToken(),e),o=await A(t,this.contract.methods.create_lock,s,a);return i?o:await R(t,o+2e4,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.create_lock,s,a)}async depositFor(t,e,a,i){var n;const s=await this.amountToUnits(await this.getToken(),a),o=await A(t,this.contract.methods.deposit_for,e,s);return i?o:await R(t,o+2e4,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.deposit_for,e,s)}async increaseAmount(t,e,a){var i;const n=await this.amountToUnits(await this.getToken(),e),s=await A(t,this.contract.methods.increase_amount,n);return a?s:await R(t,s+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.increase_amount,n)}async increaseUnlockTime(t,e,a){var i;const n=await A(t,this.contract.methods.increase_unlock_time,e);return a?n:await R(t,n+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.increase_unlock_time,e)}async withdraw(t,e){var a;const i=await A(t,this.contract.methods.withdraw);return e?i:await R(t,i+1,this.web3,null==(a=this.config)?void 0:a.gasFeeMultiplier,this.contract.methods.withdraw)}async getVotingPower(t){return await this.contract.methods.balanceOf(t).call()}async getLockedAmount(t){const e=await this.contract.methods.locked(t).call();return await this.unitsToAmount(await this.getToken(),e.amount)}async lockEnd(t){return await this.contract.methods.locked__end(t).call()}async totalSupply(){return await this.unitsToAmount(await this.getToken(),await this.contract.methods.totalSupply().call())}async getToken(){return await this.contract.methods.token().call()}}class ct extends tt{getDefaultAbi(){return m.abi}async claim(t,e){var a;const i=await A(t,this.contract.methods.claim);return e?i:await R(t,i+2e4,this.web3,null==(a=this.config)?void 0:a.gasFeeMultiplier,this.contract.methods.claim)}async claimMany(t,e,a){var i;const n=await A(t,this.contract.methods.claim_many,e);return a?n:await R(t,n+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.claim_many,e)}}class lt extends tt{getDefaultAbi(){return p.abi}async estimateClaim(t){const e=await this.contract.methods.estimateClaim(t).call(),a=new rt(await this.contract.methods.voting_escrow().call(),this.web3);return await this.unitsToAmount(await a.getToken(),e)}}class ht extends tt{getDefaultAbi(){return g.abi}async setAllocation(t,e,a,i,n){var s;const o=await A(t,this.contract.methods.setAllocation,e,a,i);return n?o:await R(t,o+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.setAllocation,e,a,i)}async setBatchAllocation(t,e,a,i,n){var s;const o=await A(t,this.contract.methods.setBatchAllocation,e,a,i);return n?o:await R(t,o+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.setBatchAllocation,e,a,i)}async getTotalAllocation(t){return await this.contract.methods.getTotalAllocation(t).call()}async getVeAllocation(t,e,a){return await this.contract.methods.getveAllocation(t,e,a).call()}}class dt extends tt{getDefaultAbi(){return f.abi}async getAvailableRewards(t,e){const a=await this.contract.methods.claimable(t,e).call();return await this.unitsToAmount(e,a)}async claimRewards(t,e,a,i){var n;const s=await A(t,this.contract.methods.claimFor,e,a);return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.claimFor,e,a)}async allocateRewards(t,e,a,i,n){var s;for(let t=0;t<a.length;t++)a[t]=await this.amountToUnits(i,a[t]);const o=await A(t,this.contract.methods.allocate,e,a,i);return n?o:await R(t,o+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.allocate,e,a,i)}}class ut extends tt{getDefaultAbi(){return v.abi}async getMultipleAvailableRewards(t,e){const a=await this.contract.methods.claimables(t,e).call(),i=[];for(let t=0;t<a.length;t++)i.push(await this.unitsToAmount(e[t],a[t]));return i}async claimMultipleRewards(t,e,a,i){var n;const s=await A(t,this.contract.methods.claimMultiple,e,a);return i?s:await R(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.claimMultiple,e,a)}}class wt{constructor(t){this.aquariusURL=void 0,this.aquariusURL=t}async resolve(t,e){const a=this.aquariusURL+"/api/aquarius/assets/ddo/"+t;try{const t=await n(a,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return await t.json();throw new Error("HTTP request failed with status "+t.status)}catch(t){throw B.error(t),new Error("HTTP request failed")}}async waitForAqua(t,e,a){let i=0;do{try{const i=this.aquariusURL+"/api/aquarius/assets/ddo/"+t,s=await n(i,{method:"GET",headers:{"Content-Type":"application/json"},signal:a});if(s.ok){const t=await s.json();if(!e)return t;if(t.event&&t.event.txid===e)return t}}catch(t){}await W(1500),i++}while(i<100);return null}async validate(t,e){const a={valid:!1};let i;try{const s=this.aquariusURL+"/api/aquarius/assets/ddo/validate",o=await n(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:e});i=await o.json(),200===o.status?(a.valid=!0,a.hash=i.hash,a.proof={validatorAddress:i.publicKey,r:i.r[0],s:i.s[0],v:i.v}):(a.errors=i,B.error("validate Metadata failed:",o.status,a.errors))}catch(t){B.error("Error validating metadata: ",t)}return a}async getAssetMetadata(t,e){const a=this.aquariusURL+"/api/aquarius/assets/metadata/"+t;try{const t=await n(a,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return t.json();throw new Error("getAssetMetadata failed: "+t.status+t.statusText)}catch(t){throw B.error("Error getting metadata: ",t),new Error("Error getting metadata: "+t)}}async querySearch(t,e){const a=this.aquariusURL+"/api/aquarius/assets/query";try{const i=await n(a,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:e});if(i.ok)return i.json();throw new Error("querySearch failed: "+i.status+i.statusText)}catch(t){throw B.error("Error querying metadata: ",t),new Error("Error querying metadata: "+t)}}}class mt{async getEndpoints(t){try{const e=await this.getData(t);return await e.json()}catch(t){throw B.error("Finding the service endpoints failed:",t),new Error("HTTP request failed calling Provider")}}getEndpointURL(t,e){return t?t.find(t=>t.serviceName===e):null}async getServiceEndpoints(t,e){const a=[];for(const i in e.serviceEndpoints)a.push({serviceName:i,method:e.serviceEndpoints[i][0],urlPath:t+e.serviceEndpoints[i][1]});return a}async getNonce(t,e,a,i,s){i||(i=await this.getEndpoints(t)),s||(s=await this.getServiceEndpoints(t,i));const o=this.getEndpointURL(s,"nonce")?this.getEndpointURL(s,"nonce").urlPath:null;if(!o)return null;try{const t=await n(o+`?userAddress=${e}`,{method:"GET",headers:{"Content-Type":"application/json"},signal:a});return(await t.json()).nonce.toString()}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async signProviderRequest(t,e,a,i){const n=t.utils.soliditySha3({t:"bytes",v:t.utils.utf8ToHex(a)});return t&&t.currentProvider&&t.currentProvider.isMetaMask?await t.eth.personal.sign(n,e,i):await t.eth.sign(n,e)}async encrypt(t,e,a,i){const s=await this.getEndpoints(a),o=await this.getServiceEndpoints(a,s),r=(this.getEndpointURL(o,"encrypt")?this.getEndpointURL(o,"encrypt").urlPath:null)+`?chainId=${e}`;if(!r)return null;try{const e=await n(r,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:i});return await e.text()}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async checkDidFiles(t,e,a,i=!1,s){const o=await this.getEndpoints(a),r=await this.getServiceEndpoints(a,o),c={did:t,serviceId:e,checksum:i},l=[],h=this.getEndpointURL(r,"fileinfo")?this.getEndpointURL(r,"fileinfo").urlPath:null;if(!h)return null;try{const t=await n(h,{method:"POST",body:JSON.stringify(c),headers:{"Content-Type":"application/json"},signal:s}),e=await t.json();for(const t of e)l.push(t);return l}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async getFileInfo(t,e,a=!1,i){const s=await this.getEndpoints(e),o=await this.getServiceEndpoints(e,s),r=b({},t,{checksum:a}),c=[],l=this.getEndpointURL(o,"fileinfo")?this.getEndpointURL(o,"fileinfo").urlPath:null;if(!l)return null;try{const t=await n(l,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"},signal:i}),e=await t.json();for(const t of e)c.push(t);return c}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async getComputeEnvironments(t,e){var a;const i=await this.getEndpoints(t),s=await this.getServiceEndpoints(t,i),o=null==(a=this.getEndpointURL(s,"computeEnvironments"))?void 0:a.urlPath;if(!o)return null;try{const t=await n(o,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});return await t.json()}catch(t){throw B.error(t),new Error("HTTP request failed calling Provider")}}async initialize(t,e,a,i,s,o,r,c,l){const h=await this.getEndpoints(s),d=await this.getServiceEndpoints(s,h);let u=this.getEndpointURL(d,"initialize")?this.getEndpointURL(d,"initialize").urlPath:null;if(!u)return null;u+=`?documentId=${t}`,u+=`&serviceId=${e}`,u+=`&fileIndex=${a}`,u+=`&consumerAddress=${i}`,r&&(u+="&userdata="+encodeURI(JSON.stringify(r))),c&&(u+="&environment="+encodeURI(c)),l&&(u+="&validUntil="+l);try{const t=await n(u,{method:"GET",headers:{"Content-Type":"application/json"},signal:o});return await t.json()}catch(t){throw B.error(t),new Error("Asset URL not found or not available.")}}async initializeCompute(t,e,a,i,s,o,r){const c=await this.getEndpoints(s),l=await this.getServiceEndpoints(s,c),h={datasets:t,algorithm:e,compute:{env:a,validUntil:i},consumerAddress:o},d=this.getEndpointURL(l,"initializeCompute")?this.getEndpointURL(l,"initializeCompute").urlPath:null;if(!d)return null;try{const t=await n(d,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json"},signal:r});return await t.json()}catch(t){throw B.error(t),new Error("ComputeJob cannot be initialized")}}async getDownloadUrl(t,e,a,i,n,s,o,r){const c=await this.getEndpoints(s),l=await this.getServiceEndpoints(s,c),h=this.getEndpointURL(l,"download")?this.getEndpointURL(l,"download").urlPath:null;if(!h)return null;const d=Date.now();let u=h;return u+=`?fileIndex=${i}`,u+=`&documentId=${t}`,u+=`&transferTxId=${n}`,u+=`&serviceId=${a}`,u+=`&consumerAddress=${e}`,u+=`&nonce=${d}`,u+=`&signature=${await this.signProviderRequest(o,e,t+d)}`,r&&(u+="&userdata="+encodeURI(JSON.stringify(r))),u}async computeStart(t,e,a,i,s,o,r,c,l){const h=await this.getEndpoints(t),d=await this.getServiceEndpoints(t,h),u=this.getEndpointURL(d,"computeStart")?this.getEndpointURL(d,"computeStart").urlPath:null,w=Date.now();let m=a;m+=s.documentId,m+=w;const p=await this.signProviderRequest(e,a,m),g=Object();if(g.consumerAddress=a,g.signature=p,g.nonce=w,g.environment=i,g.dataset=s,g.algorithm=o,g.additionalDatasets&&(g.additionalDatasets=c),l&&(g.output=l),!u)return null;try{const t=await n(u,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json"},signal:r});return null!=t&&t.ok?await t.json():(B.error("Compute start failed: ",t.status,t.statusText,await t.json()),B.error("Payload was:",g),null)}catch(t){throw B.error("Compute start failed:"),B.error(t),B.error("Payload was:",g),new Error("HTTP request failed calling Provider")}}async computeStop(t,e,a,i,s,o){const r=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,r),l=this.getEndpointURL(c,"computeStop")?this.getEndpointURL(c,"computeStop").urlPath:null,h=await this.getNonce(i,e,o,r,c);let d=e;d+=a||"",d+=t&&`${this.noZeroX(t)}`||"",d+=h;const u=await this.signProviderRequest(s,e,d),w=Object();if(w.signature=u,w.documentId=this.noZeroX(t),w.consumerAddress=e,a&&(w.jobId=a),!l)return null;try{const t=await n(l,{method:"PUT",body:JSON.stringify(w),headers:{"Content-Type":"application/json"},signal:o});return null!=t&&t.ok?await t.json():(B.error("Compute stop failed:",t.status,t.statusText),B.error("Payload was:",w),null)}catch(t){throw B.error("Compute stop failed:"),B.error(t),B.error("Payload was:",w),new Error("HTTP request failed calling Provider")}}async computeStatus(t,e,a,i,s){const o=await this.getEndpoints(t),r=await this.getServiceEndpoints(t,o),c=this.getEndpointURL(r,"computeStatus")?this.getEndpointURL(r,"computeStatus").urlPath:null;let l=`?consumerAddress=${e}`;if(l+=i&&`&documentId=${this.noZeroX(i)}`||"",l+=a&&`&jobId=${a}`||"",!c)return null;try{const t=await n(c+l,{method:"GET",headers:{"Content-Type":"application/json"},signal:s});return null!=t&&t.ok?await t.json():(B.error("Get compute status failed:",t.status,t.statusText),null)}catch(t){throw B.error("Get compute status failed"),B.error(t),new Error("HTTP request failed calling Provider")}}async getComputeResultUrl(t,e,a,i,n){const s=await this.getEndpoints(t),o=await this.getServiceEndpoints(t,s),r=this.getEndpointURL(o,"computeResult")?this.getEndpointURL(o,"computeResult").urlPath:null,c=Date.now();let l=a;l+=i,l+=n.toString(),l+=c;const h=await this.signProviderRequest(e,a,l);if(!r)return null;let d=r;return d+=`?consumerAddress=${a}`,d+=`&jobId=${i}`,d+=`&index=${n.toString()}`,d+=`&nonce=${c}`,d+=h&&`&signature=${h}`||"",d}async computeDelete(t,e,a,i,s,o){const r=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,r),l=this.getEndpointURL(c,"computeDelete")?this.getEndpointURL(c,"computeDelete").urlPath:null,h=await this.getNonce(i,e,o,r,c);let d=e;d+=a||"",d+=t&&`${this.noZeroX(t)}`||"",d+=h;const u=await this.signProviderRequest(s,e,d),w=Object();if(w.documentId=this.noZeroX(t),w.consumerAddress=e,w.jobId=a,u&&(w.signature=u),!l)return null;try{const t=await n(l,{method:"DELETE",body:JSON.stringify(w),headers:{"Content-Type":"application/json"},signal:o});return null!=t&&t.ok?await t.json():(B.error("Delete compute job failed:",t.status,t.statusText),B.error("Payload was:",w),null)}catch(t){throw B.error("Delete compute job failed:"),B.error(t),B.error("Payload was:",w),new Error("HTTP request failed calling Provider")}}async isValidProvider(t,e){try{const a=await n(t,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(null!=a&&a.ok){const t=await a.json();if(t&&t.providerAddress)return!0}return!1}catch(t){return B.error(`Error validating provider: ${t.message}`),!1}}noZeroX(t){return this.zeroXTransformer(t,!1)}zeroXTransformer(t="",e){const{valid:a,output:i}=this.inputMatch(t,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(e&&a?"0x":"")+i}inputMatch(t,e,a){if("string"!=typeof t)throw B.debug("Not input string:"),B.debug(t),new Error(`[${a}] Expected string, input type: ${typeof t}`);const i=t.match(e);return i?{valid:!0,output:i[1]}:(B.warn(`[${a}] Input transformation failed.`),{valid:!1,output:t})}async getData(t){return n(t,{method:"GET",headers:{"Content-type":"application/json"}})}}const pt=new mt;export{wt as Aquarius,y as Config,K as ConfigHelper,st as Datatoken,dt as DfRewards,ut as DfStrategyV1,et as Dispenser,E as FEE_HISTORY_NOT_SUPPORTED,at as FixedRateExchange,F as GASLIMIT_DEFAULT,P as LogLevel,L as Logger,B as LoggerInstance,C as MAX_UINT_256,nt as Nft,ot as NftFactory,mt as Provider,pt as ProviderInstance,it as Router,Y as SmartContract,tt as SmartContractWithAddress,ht as VeAllocate,ct as VeFeeDistributor,lt as VeFeeEstimate,rt as VeOcean,T as ZERO_ADDRESS,V as allowance,z as allowanceWei,D as amountToUnits,_ as approve,G as approveWei,Z as balance,A as calculateEstimatedGas,Q as configHelperNetworks,J as decimals,j as downloadFile,I as downloadFileBrowser,S as generateDid,U as generateDtName,M as getFairGasPrice,N as getHash,q as minAbi,R as sendTx,k as setContractDefaults,$ as signHash,W as sleep,H as transfer,x as unitsToAmount};
|
|
2
2
|
//# sourceMappingURL=lib.modern.js.map
|