@oceanprotocol/lib 5.1.1 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.cjs CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("@oceanprotocol/contracts/addresses/address.json"),t=require("fs"),r=require("ethers"),n=require("@oasisprotocol/sapphire-paratime"),o=require("bignumber.js"),i=require("decimal.js"),s=require("@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json"),a=require("@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json"),u=require("@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json"),c=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json"),l=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json"),d=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json"),h=require("@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json"),m=require("@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json"),f=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json"),v=require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json"),g=require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json"),p=require("@oceanprotocol/contracts/artifacts/contracts/escrow/Escrow.sol/Escrow.json"),P=require("@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json"),y=require("cross-fetch"),w=require("@oceanprotocol/ddo-js"),b=require("jsonwebtoken"),k=require("crypto-js/sha256.js"),T=require("crypto");function S(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function A(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var E,F,C,x=/*#__PURE__*/S(e),j=/*#__PURE__*/S(t),D=/*#__PURE__*/A(n),M=/*#__PURE__*/S(o),O=/*#__PURE__*/S(i),N=/*#__PURE__*/S(s),R=/*#__PURE__*/S(a),U=/*#__PURE__*/S(u),I=/*#__PURE__*/S(c),L=/*#__PURE__*/S(l),G=/*#__PURE__*/S(d),_=/*#__PURE__*/S(h),q=/*#__PURE__*/S(m),B=/*#__PURE__*/S(f),z=/*#__PURE__*/S(v),J=/*#__PURE__*/S(g),W=/*#__PURE__*/S(p),H=/*#__PURE__*/S(P),V=/*#__PURE__*/S(y),Z=/*#__PURE__*/S(b),X=/*#__PURE__*/S(k);function K(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function $(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return K(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?K(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Y.apply(null,arguments)}function Q(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,ee(e,t)}function ee(e,t){return ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ee(e,t)}exports.FileObjectType=void 0,(E=exports.FileObjectType||(exports.FileObjectType={})).URL="url",E.IPFS="ipfs",E.ARWEAVE="arweave",exports.EncryptMethod=void 0,(F=exports.EncryptMethod||(exports.EncryptMethod={})).AES="AES",F.ECIES="ECIES",exports.LogLevel=void 0,(C=exports.LogLevel||(exports.LogLevel={}))[C.None=-1]="None",C[C.Error=0]="Error",C[C.Warn=1]="Warn",C[C.Log=2]="Log",C[C.Verbose=3]="Verbose";var te=/*#__PURE__*/function(){function e(e){this.logLevel=void 0,this.logLevel=e,this.logLevel=e||exports.LogLevel.Error}var t=e.prototype;return t.setLevel=function(e){this.logLevel=e},t.bypass=function(){this.dispatch.apply(this,["log",-Infinity].concat([].slice.call(arguments)))},t.debug=function(){this.dispatch.apply(this,["debug",exports.LogLevel.Verbose].concat([].slice.call(arguments)))},t.log=function(){this.dispatch.apply(this,["log",exports.LogLevel.Log].concat([].slice.call(arguments)))},t.warn=function(){this.dispatch.apply(this,["warn",exports.LogLevel.Warn].concat([].slice.call(arguments)))},t.error=function(){this.dispatch.apply(this,["error",exports.LogLevel.Error].concat([].slice.call(arguments)))},t.dispatch=function(e,t){var r;this.logLevel>=t&&(r=console)[e].apply(r,[].slice.call(arguments,2))},e}(),re=new te,ne={chainId:null,network:"unknown",nodeUri:"http://127.0.0.1:8545",oceanNodeUri:"http://127.0.0.1:8001",explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},oe=[Y({},ne),Y({},ne,{chainId:8996,network:"development",oceanNodeUri:"http://127.0.0.1:8001",sdk:"evm"}),Y({},ne,{chainId:11155111,network:"sepolia",nodeUri:"https://sepolia.infura.io/v3",explorerUri:"https://sepolia.etherscan.io",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:8453,network:"base",nodeUri:"https://mainnet.base.org",explorerUri:"https://etherscan.io",startBlock:30562198,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",gasFeeMultiplier:1.6,sdk:"evm"}),Y({},ne,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com",sdk:"evm"}),Y({},ne,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:100,network:"gen-x-testnet",nodeUri:"https://rpc.genx.minimal-gaia-x.eu",explorerUri:"https://explorer.genx.minimal-gaia-x.eu/",gasFeeMultiplier:1,sdk:"evm"}),Y({},ne,{chainId:10,network:"optimism",nodeUri:"https://mainnet.optimism.io",explorerUri:"https://optimistic.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:11155420,network:"optimism_sepolia",nodeUri:"https://sepolia.optimism.io",explorerUri:"https://sepolia-optimism.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:23294,network:"oasis_sapphire",nodeUri:"https://sapphire.oasis.io",explorerUri:"https://explorer.oasis.io/mainnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),Y({},ne,{chainId:23295,network:"oasis_sapphire_testnet",nodeUri:"https://testnet.sapphire.oasis.dev",explorerUri:"https://explorer.oasis.io/testnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),Y({},ne,{chainId:32456,network:"pontus-x-devnet",nodeUri:"https://rpc.dev.pontus-x.eu",explorerUri:"https://explorer.dev.pontus-x.eu/testnet/pontusx",sdk:"evm"})],ie=[23294,23295],se=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getAddressesFromEnv=function(e,t){var r,n=function(){return process.env.NODE_URL?{oceanNodeUri:process.env.NODE_URL}:{}};if(t&&t[e]){var o=t[e];r=Y({nftFactoryAddress:o.ERC721Factory,opfCommunityFeeCollector:o.OPFCommunityFeeCollector,fixedRateExchangeAddress:o.FixedPrice,dispenserAddress:o.Dispenser,oceanTokenAddress:o.Ocean,routerFactoryAddress:o.Router,chainId:o.chainId,startBlock:o.startBlock,accessListFactory:o.AccessListFactory,escrow:o.Escrow,EnterpriseFeeCollector:o.EnterpriseFeeCollector},n())}else if(x.default[e]){var i=x.default[e];r=Y({nftFactoryAddress:i.ERC721Factory,opfCommunityFeeCollector:i.OPFCommunityFeeCollector,fixedRateExchangeAddress:i.FixedPrice,dispenserAddress:i.Dispenser,oceanTokenAddress:i.Ocean,routerFactoryAddress:i.Router,chainId:i.chainId,startBlock:i.startBlock,accessListFactory:i.AccessListFactory,escrow:i.Escrow,EnterpriseFeeCollector:i.EnterpriseFeeCollector},n())}return r},t.getConfig=function(e,t){var r,n="string"==typeof e?"network":"chainId",o=oe.find(function(t){return t[n]===e});if(!o)return re.error("No config found for given network '"+e+"'"),null;try{r=process.env.ADDRESS_FILE?JSON.parse(j.default.readFileSync(process.env.ADDRESS_FILE,"utf8")):null}catch(e){console.log(e),r=null}var i=this.getAddressesFromEnv(o.network,r);return!i&&ie.includes(o.chainId)&&(i=this.getAddressesFromEnv(o.network.replace("sapph","saph"),r)),"sdk"in o&&null!==o.sdk||(o.sdk=ie.includes(o.chainId)?"oasis":"evm"),i&&"accessListFactory"in i&&(o.accessListFactory=i.accessListFactory),o=Y({},o,i),Y({},o,{nodeUri:t?o.nodeUri+"/"+t:o.nodeUri})},e}(),ae=[{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"}],ue=function(e,t,r,n){try{var o=arguments;return Promise.resolve(t.provider.getNetwork()).then(function(i){var s=i.chainId;return Promise.resolve(t.provider.getFeeData()).then(function(t){var i={};if(t.maxPriorityFeePerGas){var a=t.maxPriorityFeePerGas.toString(),u=t.maxFeePerGas.toString();r>1&&(a=Math.round(Number(t.maxPriorityFeePerGas)*r).toString(),u=Math.round(Number(t.maxFeePerGas)*r).toString()),i={maxPriorityFeePerGas:(Number(s)===pe||Number(s)===ge)&&Number(a)<me?me:Number(s)===Pe&&Number(a)<fe?fe:ie.includes(Number(s))&&Number(a)<ve?ve:Number(a),maxFeePerGas:(Number(s)===pe||Number(s)===ge)&&Number(u)<me?me:Number(s)===Pe&&Number(u)<fe?fe:ie.includes(Number(s))&&Number(u)<ve?ve:Number(u)}}else i={gasPrice:t.gasPrice};return i.gasLimit=BigInt(new M.default(e).plus(20000n).toString()),function(e,t){try{var r=Promise.resolve(n.apply(void 0,[].slice.call(o,4).concat([i]))).then(function(e){return Promise.resolve(e.wait()).then(function(){return e})})}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(e){return re.error("Send tx error: ",e),null})})})}catch(e){return Promise.reject(e)}},ce=function(e,t,n,o){try{var i=function(e){return"0"===e&&(e=18),r.parseUnits(n,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(de(e,t)).then(i))}catch(e){return Promise.reject(e)}},le=function(e,t,n,o){try{var i=function(e){return"0"===e&&(e=18),r.formatUnits(n,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(de(e,t)).then(i))}catch(e){return Promise.reject(e)}},de=function(e,t){try{var n=new r.ethers.Contract(t,ae,e);return Promise.resolve(n.decimals())}catch(e){return Promise.reject(e)}},he=function(e,t){try{return Promise.resolve(e.provider.getFeeData()).then(function(e){var r=BigInt(e.gasPrice.toString());return t?(r*BigInt(t)).toString(10):r.toString()})}catch(e){return Promise.reject(e)}},me=3e10,fe=4e9,ve=1e10,ge=137,pe=80001,Pe=11155111;function ye(e,t){return e}function we(e,t){if(e&&e.logs)return e.logs.filter(function(e){return e instanceof r.EventLog&&e.eventName===t})[0]}var be=/*#__PURE__*/function(){function e(e,t,r,n){this.signer=void 0,this.config=void 0,this.abi=void 0,this.signer=e,this.config=r||(new se).getConfig(t),this.abi=n||this.getDefaultAbi()}var t=e.prototype;return t.getSignerAccordingSdk=function(){return this.config&&"sdk"in this.config&&"oasis"===this.config.sdk?D.wrap(this.signer):this.signer},t.amountToUnits=function(e,t,r){try{return Promise.resolve(ce(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.unitsToAmount=function(e,t,r){try{return Promise.resolve(le(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.getFairGasPrice=function(){try{var e;return Promise.resolve(he(this.signer,null==(e=this.config)?void 0:e.gasFeeMultiplier))}catch(e){return Promise.reject(e)}},t.getContract=function(e,t){if(!e)throw new Error("Contract address is required but not provided");return ye(new r.ethers.Contract(e,new r.ethers.Interface(JSON.stringify(t||this.abi)),this.signer))},e}(),ke=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,r,n,o,i)||this).address=void 0,s.contract=void 0,s.address=t,s.contract=s.getContract(s.address),s}return Q(t,e),t}(be),Te=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return N.default.abi},r.status=function(e){try{var t=this;return Promise.resolve(t.contract.status(e)).then(function(e){if(!e)throw new Error("Np dispenser found for the given datatoken address");var r=e.isMinter,n=e.owner,o=e.active;return Promise.resolve(t.unitsToAmount(null,e.maxTokens,18)).then(function(i){return Promise.resolve(t.unitsToAmount(null,e.maxBalance,18)).then(function(s){return Promise.resolve(t.unitsToAmount(null,e.balance,18)).then(function(t){return{active:o,owner:n,isMinter:r,maxTokens:i,maxBalance:s,balance:t,allowedSwapper:e.allowedSwapper}})})})})}catch(e){return Promise.reject(e)}},r.create=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.contract.create.estimateGas(e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o)).then(function(a){var u;return i?a:Promise.resolve(ue(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.create,e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.contract.activate.estimateGas(e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18))).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.activate,e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18)))})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.contract.deactivate.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.deactivate,e))})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.dispense=function(e,t,r,n){void 0===t&&(t="1");try{var o=this;return Promise.resolve(o.contract.dispense.estimateGas(e,o.amountToUnits(null,t,18),r)).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.dispense,e,o.amountToUnits(null,t,18),r))})}catch(e){return Promise.reject(e)}},r.ownerWithdraw=function(e,t){try{var r=this;return Promise.resolve(r.contract.ownerWithdraw.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.ownerWithdraw,e))})}catch(e){return Promise.reject(e)}},r.isDispensable=function(e,t,r,n){void 0===n&&(n="1");try{return Promise.resolve(this.status(e)).then(function(o){return!!o&&!1!==o.active&&Promise.resolve(t.balance(e,r)).then(function(e){return!(new O.default(e).greaterThanOrEqualTo(o.maxBalance)||new O.default(String(n)).greaterThan(o.maxTokens)||!new O.default(o.balance).greaterThanOrEqualTo(n)&&!0!==o.isMinter)})})}catch(e){return Promise.reject(e)}},t}(ke),Se="0x0000000000000000000000000000000000000000",Ae=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return R.default.abi},r.generateExchangeId=function(e,t){try{return Promise.resolve(this.contract.generateExchangeId(e,t))}catch(e){return Promise.reject(e)}},r.buyDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=Se),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.buyDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(ue(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.buyDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.sellDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=Se),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.sellDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(ue(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.sellDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.getNumberOfExchanges=function(){try{return Promise.resolve(this.contract.getNumberOfExchanges()).then(Number)}catch(e){return Promise.reject(e)}},r.setRate=function(e,t,r){try{var n=this,o=n.contract.setRate,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.setRate,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(ue(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.getRate=function(e){try{var t=this;return Promise.resolve(t.contract.getRate(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.getDatatokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getDTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.datatoken,r,Number(e.dtDecimals)))})})}catch(e){return Promise.reject(e)}},r.getBasetokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getBTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.baseToken,r,Number(e.btDecimals)))})})}catch(e){return Promise.reject(e)}},r.getAllowedSwapper=function(e){try{return Promise.resolve(this.contract.getAllowedSwapper(e))}catch(e){return Promise.reject(e)}},r.calcBaseInGivenDatatokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseInGivenOutDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e.baseTokenAmount,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.unitsToAmount(o.baseToken,e.publishMarketFeeAmount,Number(o.btDecimals))).then(function(r){return Promise.resolve(n.unitsToAmount(o.baseToken,e.oceanFeeAmount,Number(o.btDecimals))).then(function(i){return Promise.resolve(n.unitsToAmount(o.baseToken,e.consumeMarketFeeAmount,Number(o.btDecimals))).then(function(e){return{baseTokenAmount:t,marketFeeAmount:r,oceanFeeAmount:i,consumeMarketFeeAmount:e}})})})})})})})})}catch(e){return Promise.reject(e)}},r.getAmountBasetokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseOutGivenInDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e[0],Number(o.btDecimals)))})})})})}catch(e){return Promise.reject(e)}},r.getExchange=function(e){try{var t=this;return Promise.resolve(t.contract.getExchange(e)).then(function(r){var n=r.btDecimals.toString(),o=r.dtDecimals.toString(),i=r.allowedSwapper,s=r.exchangeOwner,a=r.withMint,u=r.baseToken,c=r.datatoken,l=r.active;return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtBalance,Number(r.dtDecimals))).then(function(d){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btBalance,Number(r.btDecimals))).then(function(h){return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtSupply,Number(r.dtDecimals))).then(function(m){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btSupply,Number(r.btDecimals))).then(function(f){return Promise.resolve(t.unitsToAmount(null,r.fixedRate,18)).then(function(t){return{active:l,datatoken:c,baseToken:u,withMint:a,exchangeOwner:s,allowedSwapper:i,dtDecimals:o,btDecimals:n,dtBalance:d,btBalance:h,dtSupply:m,btSupply:f,fixedRate:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getFeesInfo=function(e){try{var t=this;return Promise.resolve(t.contract.getFeesInfo(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(n){return Promise.resolve(t.unitsToAmount(null,r.opcFee.toString(),18)).then(function(o){return Promise.resolve(t.unitsToAmount(null,r.marketFee.toString(),18)).then(function(i){var s=r.marketFeeCollector;return Promise.resolve(t.unitsToAmount(n.baseToken,r.marketFeeAvailable,Number(n.btDecimals))).then(function(a){return Promise.resolve(t.unitsToAmount(n.baseToken,r.oceanFeeAvailable,Number(n.btDecimals))).then(function(t){return{opcFee:o,marketFee:i,marketFeeCollector:s,marketFeeAvailable:a,oceanFeeAvailable:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getExchanges=function(){try{return Promise.resolve(this.contract.getExchanges())}catch(e){return Promise.reject(e)}},r.isActive=function(e){try{return Promise.resolve(this.contract.isActive(e))}catch(e){return Promise.reject(e)}},r.activateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!0)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!0))}):null})}catch(e){return Promise.reject(e)}},r.deactivateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!1)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!1))}):null})}catch(e){return Promise.reject(e)}},r.collectBasetokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.baseToken,t,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.contract.collectBT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectBT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectDatatokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.contract.collectDT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectDT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectMarketFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectMarketFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectMarketFee,e))}):null})}catch(e){return Promise.reject(e)}},r.collectOceanFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectOceanFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectOceanFee,e))}):null})}catch(e){return Promise.reject(e)}},r.getOPCCollector=function(){try{return Promise.resolve(this.contract.opcCollector())}catch(e){return Promise.reject(e)}},r.getRouter=function(){try{return Promise.resolve(this.contract.router())}catch(e){return Promise.reject(e)}},r.getExchangeOwner=function(e){try{return Promise.resolve(this.getExchange(e)).then(function(e){return e.exchangeOwner})}catch(e){return Promise.reject(e)}},r.updateMarketFee=function(e,t,r){try{var n=this,o=n.contract.updateMarketFee,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.updateMarketFee,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(ue(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.updateMarketFeeCollector=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.updateMarketFeeCollector.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.updateMarketFeeCollector,e,t))})}catch(e){return Promise.reject(e)}},t}(ke),Ee=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return U.default.abi},r.buyDatatokenBatch=function(e,t){try{var r=this;return Promise.resolve(r.contract.buyDTBatch.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.buyDTBatch,e))})}catch(e){return Promise.reject(e)}},r.isApprovedToken=function(e){try{return Promise.resolve(this.contract.isApprovedToken(e))}catch(e){return Promise.reject(e)}},r.isFixedPrice=function(e){try{return Promise.resolve(this.contract.isFixedRateContract(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.routerOwner())}catch(e){return Promise.reject(e)}},r.getNFTFactory=function(){try{return Promise.resolve(this.contract.factory())}catch(e){return Promise.reject(e)}},r.addApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.removeApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.addFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.removeFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.addDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.removeDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.getOPCFee=function(e){try{return Promise.resolve(this.contract.getOPCFee(e)).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentOPCFee=function(){try{return Promise.resolve(this.contract.swapOceanFee()).then(Number)}catch(e){return Promise.reject(e)}},r.updateOPCFee=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getOwner()).then(function(a){if(a!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(s.contract.updateOPCFee.estimateGas(t,r,n,o)).then(function(e){var a;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(a=s.config)?void 0:a.gasFeeMultiplier,s.contract.updateOPCFee,t,r,n,o))})})}catch(e){return Promise.reject(e)}},t}(ke),Fe={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 Ce(e){var t=e||Fe,r=Math.floor(Math.random()*t.adjectives.length),n=Math.floor(Math.random()*t.nouns.length),o=Math.floor(100*Math.random()),i=t.adjectives[r].replace(/^\w/,function(e){return e.toUpperCase()}),s=t.nouns[n].replace(/^\w/,function(e){return e.toUpperCase()});return{name:i+" "+s+" Token",symbol:(i.substring(0,3)+s.substring(0,3)).toUpperCase()+"-"+o}}function xe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var je=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return _.default.abi},n.createNFT=function(e,t){try{var r=this;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){var n=Ce(),o=n.symbol;e.name=n.name,e.symbol=o}var i=e.templateIndex;return Promise.resolve(r.getCurrentNFTTemplateCount()).then(function(n){if(i>n)throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");return Promise.resolve(r.getNFTTemplate(e.templateIndex)).then(function(n){if(!1===n.isActive)throw new Error("Template is not active");return Promise.resolve(r.contract.deployERC721Contract.estimateGas(e.name,e.symbol,e.templateIndex,Se,Se,e.tokenURI,e.transferable,e.owner)).then(function(n){return t?n:xe(function(){var t;return Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(t=r.config)?void 0:t.gasFeeMultiplier,r.contract.deployERC721Contract,e.name,e.symbol,e.templateIndex,Se,Se,e.tokenURI,e.transferable,e.owner)).then(function(e){if(!e){var t="Tx for deploying new NFT contract does not exist or status is not successful.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return we(e,"NFTCreated").args[0]})})},function(e){console.error("Creation of NFT failed: "+e)})})})})}catch(e){return Promise.reject(e)}},n.getCurrentNFTCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getCurrentTokenCount=function(){try{return Promise.resolve(this.contract.getCurrentTokenCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},n.getCurrentNFTTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getCurrentTokenTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getNFTTemplate=function(e){try{var t=this;return Promise.resolve(t.getCurrentNFTTemplateCount()).then(function(r){if(e>r)throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");return Promise.resolve(t.contract.getNFTTemplate(e))})}catch(e){return Promise.reject(e)}},n.getTokenTemplate=function(e){try{return Promise.resolve(this.contract.getTokenTemplate(e))}catch(e){return Promise.reject(e)}},n.checkDatatoken=function(e){try{return Promise.resolve(this.contract.erc20List(e))}catch(e){return Promise.reject(e)}},n.checkNFT=function(e){try{return Promise.resolve(this.contract.erc721List(e))}catch(e){return Promise.reject(e)}},n.addNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Se)throw new Error("Template cannot be ZERO address");return Promise.resolve(n.contract.add721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.add721TokenTemplate,t))})})}catch(e){return Promise.reject(e)}},n.disableNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.disable721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disable721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},n.reactivateNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.reactivate721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivate721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},n.addTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Se)throw new Error("Template cannot be address ZERO");return Promise.resolve(n.contract.addTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addTokenTemplate,t))})})}catch(e){return Promise.reject(e)}},n.disableTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!1===e.isActive)throw new Error("Template is already disabled");return Promise.resolve(n.contract.disableTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disableTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},n.reactivateTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!0===e.isActive)throw new Error("Template is already active");return Promise.resolve(n.contract.reactivateTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivateTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},n.startMultipleTokenOrder=function(e,t){try{var r=this;if(e.length>50)throw new Error("Too many orders");return Promise.resolve(r.contract.startMultipleTokenOrder.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.startMultipleTokenOrder,e))})}catch(e){return Promise.reject(e)}},n.createNftWithDatatoken=function(e,t,r){try{var n=this;return Promise.resolve(n.getErcCreationParams(t)).then(function(t){return Promise.resolve(n.contract.createNftWithErc20.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.createNftWithErc20,e,t))})})}catch(e){return Promise.reject(e)}},n.createNftWithDatatokenWithFixedRate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.getFreCreationParams(r)).then(function(r){return Promise.resolve(o.contract.createNftWithErc20WithFixedRate.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithFixedRate,e,t,r))})})})}catch(e){return Promise.reject(e)}},n.createNftWithDatatokenWithDispenser=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.amountToUnits(null,r.maxBalance,18)).then(function(i){return r.maxBalance=i,Promise.resolve(o.amountToUnits(null,r.maxTokens,18)).then(function(i){return r.maxTokens=i,Promise.resolve(o.contract.createNftWithErc20WithDispenser.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithDispenser,e,t,r))})})})})}catch(e){return Promise.reject(e)}},n.getErcCreationParams=function(e){try{var t,n,o=function(){var o=[e.minter,e.paymentCollector,e.mpFeeAddress,e.feeToken];e.filesObject&&(e.accessListFactory&&o.push(e.accessListFactory),e.allowAccessList&&o.push(e.allowAccessList),e.denyAccessList&&o.push(e.denyAccessList));var s=[e.name||t,e.symbol||n],u=e.templateIndex;return Promise.resolve(i.amountToUnits(null,e.cap,18)).then(function(t){return Promise.resolve(i.amountToUnits(null,e.feeAmount,a)).then(function(n){return{templateIndex:u,strings:s,addresses:o,uints:[t,n],bytess:e.filesObject?[r.toUtf8Bytes(JSON.stringify(e.filesObject))]:[]}})})},i=this;if(!e.name||!e.symbol){var s=Ce();t=s.name,n=s.symbol}var a=18,u=function(){if(e.feeToken!==Se){var t=xe(function(){return Promise.resolve(de(i.signer,e.feeToken)).then(function(e){a=e})},function(e){re.error("getTokenDecimals error",e)});if(t&&t.then)return t.then(function(){})}}();return Promise.resolve(u&&u.then?u.then(o):o())}catch(e){return Promise.reject(e)}},n.getFreCreationParams=function(e){try{var t=this;e.allowedConsumer||(e.allowedConsumer=Se);var r=!1===e.withMint?0:1,n=[e.baseTokenAddress,e.owner,e.marketFeeCollector,e.allowedConsumer],o=e.fixedRateAddress,i=e.datatokenDecimals,s=e.baseTokenDecimals;return Promise.resolve(t.amountToUnits(null,e.fixedRate,e.datatokenDecimals)).then(function(a){return Promise.resolve(t.amountToUnits(null,e.marketFee,e.datatokenDecimals)).then(function(e){return{fixedPriceAddress:o,addresses:n,uints:[s,i,a,e,r]}})})}catch(e){return Promise.reject(e)}},t}(ke);function De(e,t,r){if(!e.s){if(r instanceof Me){if(!r.s)return void(r.o=De.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(De.bind(null,e,t),De.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var Me=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{De(n,1,i(this.v))}catch(e){De(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?De(n,1,t?t(o):o):r?De(n,1,r(o)):De(n,2,o)}catch(e){De(n,2,e)}},n},e}();function Oe(e){return e instanceof Me&&1&e.s}var Ne=function(e,t,n,o){try{var i="number"==typeof n,s=new je(t,e,o);return Promise.resolve(s.getCurrentTokenTemplateCount()).then(function(t){var o;function a(e){return o?e:-1}var u=1,c=function(e,t,r){for(var n;;){var o=e();if(Oe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Oe(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Oe(s)){n=2;break}}}var a=new Me,u=De.bind(null,a,2);return(0===n?o.then(l):1===n?i.then(c):s.then(d)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!Oe(s))return void s.then(d).then(void 0,u);if(!(o=e())||Oe(o)&&!o.v)return void De(a,1,i);if(o.then)return void o.then(l).then(void 0,u);Oe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function l(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):De(a,1,i)}function d(){(o=e())?o.then?o.then(l).then(void 0,u):l(o):De(a,1,i)}}(function(){return!o&&u<=t},function(){return u++},function(){return Promise.resolve(s.getTokenTemplate(u)).then(function(t){var s=new r.ethers.Contract(t.templateAddress,q.default.abi,e);return i?Promise.resolve(s.getId()).then(function(e){if(t.isActive&&e.toString()===n.toString())return o=1,u}):t.isActive&&t.templateAddress===n.toString()?(o=1,u):void 0})});return c&&c.then?c.then(a):a(c)})}catch(e){return Promise.reject(e)}};function Re(){try{if(process.env.ADDRESS_FILE){var e=j.default.readFileSync(process.env.ADDRESS_FILE,"utf8");return JSON.parse(e)}return x.default}catch(e){return x.default}}function Ue(e){try{var t=Re();if(t)for(var r=Object.keys(t),n=0,o=r;n<o.length;n++){var i=o[n];if(t[i].chainId===e)return t[i]}}catch(e){console.error(e)}return null}var Ie=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return G.default.abi},n.createDatatoken=function(e,t,n,o,i,s,a,u,c,l,d,h,m,f,v,g){try{var p=this;return Promise.resolve(p.getNftPermissions(e,t)).then(function(t){if(!0!==t.deployERC20)throw new Error("Caller is not DatatokenDeployer");if(d||(d=1),!c||!l){var P=Ce();c=P.name,l=P.symbol}var y=p.getContract(e);if(!p.signer.provider)throw new Error("Provider is required but not available");return Promise.resolve(p.signer.provider.getNetwork()).then(function(e){var t=e.chainId;function P(){var e=y.createERC20,t=e.estimateGas,P=[c,l],w=d;return Promise.resolve(p.amountToUnits(null,u,18)).then(function(b){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(k){return Promise.resolve(t.call(e,w,P,[n,o,i,s],[b,k],[])).then(function(e){var t;if(g)return e;var P=[n,o,i,s];m&&(P.push(m.toLowerCase()),P.push(f?f.toLowerCase():Se),P.push(v||Se));var w=[c,l],b=d,k=y.createERC20,T=null==(t=p.config)?void 0:t.gasFeeMultiplier,S=p.getSignerAccordingSdk();return Promise.resolve(p.amountToUnits(null,u,18)).then(function(t){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(n){return Promise.resolve(ue(e,S,T,k,b,w,P,[t,n],h?[r.toUtf8Bytes(h)]:[])).then(function(e){return Promise.resolve(e.wait()).then(function(e){var t=we(e,"TokenCreated");return null==t?void 0:t.args[0]})})})})})})})}var w=Ue(Number(t)),b=function(){if(h)return Promise.resolve(Ne(p.signer,w.ERC721Factory,4,Number(t))).then(function(e){d=e})}();return b&&b.then?b.then(P):P()})})}catch(e){return Promise.reject(e)}},n.addManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.addManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addManager,r))})})}catch(e){return Promise.reject(e)}},n.removeManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.removeManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeManager,r))})})}catch(e){return Promise.reject(e)}},n.addDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToCreateERC20List,r))})})}catch(e){return Promise.reject(e)}},n.removeDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t===r&&!0!==e.deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");return Promise.resolve(i.removeFromCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromCreateERC20List,r))})}var u=!0!==s.manager;return u||t!==r?a(u||t===r&&o.getNftPermissions(e,t)):Promise.resolve(u||t===r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},n.addMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToMetadataList,r))})})}catch(e){return Promise.reject(e)}},n.removeMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");return Promise.resolve(i.removeFromMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromMetadataList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},n.addStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addTo725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addTo725StoreList,r))})})}catch(e){return Promise.reject(e)}},n.removeStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.store)throw new Error("Caller is not Manager nor storeUpdater");return Promise.resolve(i.removeFrom725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFrom725StoreList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},n.cleanPermissions=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(n.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(o.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.cleanPermissions))})})}catch(e){return Promise.reject(e)}},n.transferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.transferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.transferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},n.safeTransferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.safeTransferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.safeTransferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},n.setMetadata=function(e,t,r,n,o,i,s,a,u,c){try{var l=this,d=l.getContract(e);return u||(u=[]),Promise.resolve(l.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");return Promise.resolve(d.setMetaData.estimateGas(r,n,o,i,s,a,u)).then(function(e){var t;return c?e:Promise.resolve(ue(e,l.signer,null==(t=l.config)?void 0:t.gasFeeMultiplier,d.setMetaData,r,n,o,i,s,a,u))})})}catch(e){return Promise.reject(e)}},n.setMetadataAndTokenURI=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");var t=Y({},r,{metadataProofs:r.metadataProofs||[]});return Promise.resolve(i.setMetaDataAndTokenURI.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.signer,null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setMetaDataAndTokenURI,t))})})}catch(e){return Promise.reject(e)}},n.setMetadataState=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");return Promise.resolve(i.setMetaDataState.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setMetaDataState,r))})})}catch(e){return Promise.reject(e)}},n.setTokenURI=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(o.setTokenURI.estimateGas("1",t)).then(function(e){var i;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,o.setTokenURI,"1",t))})}catch(e){return Promise.reject(e)}},n.getNftOwner=function(e){try{var t=this.getContract(e);return Promise.resolve(t.ownerOf(1))}catch(e){return Promise.reject(e)}},n.getNftPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.getPermissions(t))}catch(e){return Promise.reject(e)}},n.getMetadata=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getMetaData())}catch(e){return Promise.reject(e)}},n.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},n.setData=function(e,t,n,o,i){try{var s=this;return Promise.resolve(s.getNftPermissions(e,t)).then(function(t){if(!0!==t.store)throw new Error("User is not ERC20 store updater");var a=s.getContract(e),u=r.keccak256(n),c=r.hexlify(r.toUtf8Bytes(o));return Promise.resolve(a.setNewData.estimateGas(u,c)).then(function(e){var t;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(t=s.config)?void 0:t.gasFeeMultiplier,a.setNewData,u,c))})})}catch(e){return Promise.reject(e)}},n.getData=function(e,t){try{var n=this.getContract(e),o=r.keccak256(t);return Promise.resolve(n.getData(o)).then(function(e){return e?r.toUtf8String(e):null})}catch(e){return Promise.reject(e)}},n.getTokenURI=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.tokenURI(t))}catch(e){return Promise.reject(e)}},n.isDatatokenDeployed=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isDeployed(t))}catch(e){return Promise.reject(e)}},t}(be),Le=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o)||this).abiEnterprise=void 0,s.nft=void 0,s.abiEnterprise=i||L.default.abi,s.nft=new Ie(s.signer,r),s}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return I.default.abi},n.approve=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.approve.estimateGas(t,ce(null,null,r,18))).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.approve,t,ce(null,null,r,18)))})}catch(e){return Promise.reject(e)}},n.createFixedRate=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!e)throw new Error("User is not Datatoken Deployer");r.allowedConsumer||(r.allowedConsumer=Se);var t=!1===r.withMint?0:1;return Promise.resolve(i.createFixedRate.estimateGas(r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t])).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.createFixedRate,r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t]))})})}catch(e){return Promise.reject(e)}},n.createDispenser=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e);return n.allowedSwapper||(n.allowedSwapper=Se),n.withMint=!1!==n.withMint,Promise.resolve(s.createDispenser.estimateGas(r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper)).then(function(e){var t;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.createDispenser,r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper))})})}catch(e){return Promise.reject(e)}},n.mint=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getPermissions(e,t)).then(function(a){if(!0!==a.minter)throw new Error("Caller is not Minter");return Promise.resolve(i.getCap(e)).then(function(e){if(new O.default(e).gte(r))return Promise.resolve(s.mint.estimateGas(n||t,ce(null,null,r,18))).then(function(e){var a;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,s.mint,n||t,ce(null,null,r,18)))});throw new Error("Mint amount exceeds cap available")})})}catch(e){return Promise.reject(e)}},n.addMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addMinter,r))})})}catch(e){return Promise.reject(e)}},n.removeMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removeMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeMinter,r))})})}catch(e){return Promise.reject(e)}},n.addPaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addPaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addPaymentManager,r))})})}catch(e){return Promise.reject(e)}},n.removePaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removePaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removePaymentManager,r))})})}catch(e){return Promise.reject(e)}},n.setPaymentCollector=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getPermissions(e,t)).then(function(s){function a(e){function s(s){function a(e){if(!u&&!c&&!(null==e?void 0:e.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");return Promise.resolve(i.setPaymentCollector.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setPaymentCollector,r))})}var c=e&&s===t;return e&&!c?Promise.resolve(e&&!c&&o.nft.getNftPermissions(e,t)).then(a):a(e&&!c&&o.nft.getNftPermissions(e,t))}return e?Promise.resolve(o.nft.getNftOwner(e)).then(s):s(e)}var u=s.paymentManager;return u?a(!u&&o.getNFTAddress(e)):Promise.resolve(!u&&o.getNFTAddress(e)).then(a)})}catch(e){return Promise.reject(e)}},n.getPaymentCollector=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPaymentCollector())}catch(e){return Promise.reject(e)}},n.transfer=function(e,t,r,n){try{var o=this,i=o.transferWei;return Promise.resolve(ce(null,null,r,18)).then(function(r){return i.call(o,e,t,r,n)})}catch(e){return Promise.reject(e)}},n.transferWei=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.transfer.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.transfer,t,r))})}catch(e){return Promise.reject(e)}},n.startOrder=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e,s.abi);return o||(o={consumeMarketFeeAddress:Se,consumeMarketFeeToken:Se,consumeMarketFeeAmount:"0"}),Promise.resolve(a.startOrder.estimateGas(t,r,n,o)).then(function(e){var u;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,a.startOrder,t,r,n,o))})}catch(e){return Promise.reject(e)}},n.reuseOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.reuseOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.reuseOrder,t,r))})}catch(e){return Promise.reject(e)}},n.buyFromFreAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(o.getFreOrderParams(r)).then(function(e){return Promise.resolve(i.buyFromFreAndOrder.estimateGas(t,e)).then(function(r){var s;return n?r:Promise.resolve(ue(r,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromFreAndOrder,t,e))})})}catch(e){return Promise.reject(e)}},n.buyFromDispenserAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(i.buyFromDispenserAndOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromDispenserAndOrder,t,r))})}catch(e){return Promise.reject(e)}},n.setData=function(e,t,n,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e),a=r.hexlify(r.toUtf8Bytes(n));return Promise.resolve(s.setData.estimateGas(a)).then(function(e){var t;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.setData,a))})})}catch(e){return Promise.reject(e)}},n.cleanPermissions=function(e,t,r){try{var n=this,o=n.nft,i=o.getNftOwner;return Promise.resolve(n.getNFTAddress(e)).then(function(s){return Promise.resolve(i.call(o,s)).then(function(o){if(o!==t)throw new Error("Caller is NOT Nft Owner");var i=n.getContract(e);return Promise.resolve(i.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,i.cleanPermissions))})})})}catch(e){return Promise.reject(e)}},n.getPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.permissions(t))}catch(e){return Promise.reject(e)}},n.getCap=function(e){try{var t=this,r=t.getContract(e);return Promise.resolve(r.cap()).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},n.getDecimals=function(e){try{var t=this.getContract(e);return Promise.resolve(t.decimals()).then(Number)}catch(e){return Promise.reject(e)}},n.getId=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getId()).then(Number)}catch(e){return Promise.reject(e)}},n.getSymbol=function(e){try{var t=this.getContract(e);return Promise.resolve(t.symbol())}catch(e){return Promise.reject(e)}},n.getName=function(e){try{var t=this.getContract(e);return Promise.resolve(t.name())}catch(e){return Promise.reject(e)}},n.getNFTAddress=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getERC721Address())}catch(e){return Promise.reject(e)}},n.getFixedRates=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getFixedRates())}catch(e){return Promise.reject(e)}},n.getDispensers=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getDispensers())}catch(e){return Promise.reject(e)}},n.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},n.balance=function(e,t){try{var r=this,n=r.getContract(e);return Promise.resolve(n.balanceOf(t)).then(function(e){return Promise.resolve(r.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},n.allowance=function(e,t,r,n){void 0===n&&(n=18);try{var o=this,i=o.getContract(e);return Promise.resolve(i.allowance(t,r)).then(function(e){return Promise.resolve(o.unitsToAmount(null,e,n))})}catch(e){return Promise.reject(e)}},n.setPublishingMarketFee=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e);return Promise.resolve(a.getPublishingMarketFee()).then(function(e){if(e[0]!==o)throw new Error("Caller is not the Publishing Market Fee Address");return Promise.resolve(a.setPublishingMarketFee.estimateGas(t,r,n)).then(function(e){var o;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(o=s.config)?void 0:o.gasFeeMultiplier,a.setPublishingMarketFee,t,r,n))})})}catch(e){return Promise.reject(e)}},n.getPublishingMarketFee=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPublishingMarketFee()).then(function(e){return{publishMarketFeeAddress:e[0],publishMarketFeeToken:e[1],publishMarketFeeAmount:e[2].toString()}})}catch(e){return Promise.reject(e)}},n.getFreOrderParams=function(e){try{var t=this,r=e.exchangeId,n=e.exchangeContract;return Promise.resolve(ce(t.signer,e.baseTokenAddress,e.maxBaseTokenAmount,e.baseTokenDecimals)).then(function(o){return Promise.resolve(ce(t.signer,e.baseTokenAddress,e.swapMarketFee,e.baseTokenDecimals)).then(function(t){return{exchangeContract:n,exchangeId:r,maxBaseTokenAmount:o,swapMarketFee:t,marketFeeAddress:e.marketFeeAddress}})})}catch(e){return Promise.reject(e)}},t}(be),Ge=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,n,o,i)||this).accessList=void 0,s.fileObject=void 0,s.abi=s.getDefaultAbi(),s.fileObject=r,s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return B.default.abi},r.setFileObj=function(e){this.fileObject=e},r.getAllowlistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getAllowListContract())}catch(e){return Promise.reject(e)}},r.getDenylistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getDenyListContract())}catch(e){return Promise.reject(e)}},r.setAllowListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setAllowListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setAllowListContract,t))})})}catch(e){return Promise.reject(e)}},r.setDenyListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setDenyListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setDenyListContract,t))})})}catch(e){return Promise.reject(e)}},r.setFileObject=function(e,t,r){try{var n=this;return Promise.resolve(n.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var o=n.getContract(e);return Promise.resolve(o.setFilesObject.estimateGas(n.fileObject)).then(function(e){var t;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.setFilesObject,n.fileObject))})})}catch(e){return Promise.reject(e)}},r.getFileObject=function(e,t,r,n,o,i,s){try{var a=this.getContract(e,this.getDefaultAbi());return Promise.resolve(a.getFileObject(t,r,n,o,i,s))}catch(e){return Promise.reject(e)}},t}(Le),_e=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return z.default.abi},r.getTokenUri=function(e){try{return Promise.resolve(this.contract.tokenURI(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.getId=function(){try{return Promise.resolve(this.contract.getId()).then(Number)}catch(e){return Promise.reject(e)}},r.getName=function(){try{return Promise.resolve(this.contract.name())}catch(e){return Promise.reject(e)}},r.getSymbol=function(){try{return Promise.resolve(this.contract.symbol())}catch(e){return Promise.reject(e)}},r.balance=function(e){try{var t=this;return Promise.resolve(t.contract.balanceOf(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.mint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.mint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.mint,e,t))})}catch(e){return Promise.reject(e)}},r.batchMint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.batchMint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.batchMint,e,t))})}catch(e){return Promise.reject(e)}},r.burn=function(e,t){try{var r=this;return Promise.resolve(r.contract.burn.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.burn,e))})}catch(e){return Promise.reject(e)}},r.transferOwnership=function(e,t){try{var r=this;return Promise.resolve(r.contract.transferOwnership.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.transferOwnership,e))})}catch(e){return Promise.reject(e)}},r.renounceOwnership=function(e){try{var t=this;return Promise.resolve(t.contract.renounceOwnership.estimateGas()).then(function(r){var n;return e?r:Promise.resolve(ue(r,t.getSignerAccordingSdk(),null==(n=t.config)?void 0:n.gasFeeMultiplier,t.contract.renounceOwnership))})}catch(e){return Promise.reject(e)}},t}(ke),qe=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return J.default.abi},r.deployAccessListContract=function(e,t,r,n,o,i,s){void 0===n&&(n=!1);try{var a=this;if(!e||!t){var u=Ce();e=u.name,t=u.symbol}return Promise.resolve(a.contract.deployAccessListContract.estimateGas(e,t,n,o,i,r)).then(function(u){return s?u:function(s,c){try{var l=Promise.resolve(ue(u,a.getSignerAccordingSdk(),null==(d=a.config)?void 0:d.gasFeeMultiplier,a.contract.deployAccessListContract,e,t,n,o,i,r)).then(function(e){if(!e){var t="Tx for deploying new access list was not processed on chain.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return we(e,"NewAccessList").args[0]})})}catch(e){return c(e)}var d;return l&&l.then?l.then(void 0,c):l}(0,function(e){console.error("Creation of AccessList failed: "+e)})})}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.isSoulbound=function(e){try{return Promise.resolve(this.contract.isSoulBound(e))}catch(e){return Promise.reject(e)}},r.isDeployed=function(e){try{return Promise.resolve(this.contract.isDeployed(e))}catch(e){return Promise.reject(e)}},r.changeTemplateAddress=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Se)throw new Error("Template address cannot be ZERO address");return Promise.resolve(n.contract.changeTemplateAddress.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.changeTemplateAddress,t))})})}catch(e){return Promise.reject(e)}},t}(ke);function Be(e,t,r){if(!e.s){if(r instanceof ze){if(!r.s)return void(r.o=Be.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Be.bind(null,e,t),Be.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var ze=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Be(n,1,i(this.v))}catch(e){Be(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Be(n,1,t?t(o):o):r?Be(n,1,r(o)):Be(n,2,o)}catch(e){Be(n,2,e)}},n},e}(),Je=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return W.default.abi},n.getFunds=function(e){try{return Promise.resolve(this.contract.getFunds(e))}catch(e){return Promise.reject(e)}},n.getUserFunds=function(e,t){try{return Promise.resolve(this.contract.getUserFunds(e,t))}catch(e){return Promise.reject(e)}},n.getUserTokens=function(e){try{return Promise.resolve(this.contract.getUserTokens(e))}catch(e){return Promise.reject(e)}},n.getLocks=function(e,t,r){try{return Promise.resolve(this.contract.getLocks(e,t,r))}catch(e){return Promise.reject(e)}},n.getAuthorizations=function(e,t,r){try{return Promise.resolve(this.contract.getAuthorizations(e,t,r))}catch(e){return Promise.reject(e)}},n.verifyFundsForEscrowPayment=function(e,t,n,o,i,s,a){try{var u,c=this;return Promise.resolve(null==(u=c.signer.provider)?void 0:u.getBalance(r.getAddress(t))).then(function(u){if(new M.default(u).isZero())return{isValid:!1,message:"Native token balance is 0. Please add funds"};var l=new Le(c.signer),d=l.allowance;return Promise.resolve(c.signer.getAddress()).then(function(u){return Promise.resolve(d.call(l,e,u,c.contract.target.toString(),a)).then(function(u){return Promise.resolve(c.amountToUnits(e,u,18)).then(function(u){function d(){var u=l.balance;return Promise.resolve(c.signer.getAddress()).then(function(d){return Promise.resolve(u.call(l,e,d)).then(function(u){if(new M.default(u).isZero())return{isValid:!1,message:"Payment token balance is 0. Please add funds"};var l=c.getAuthorizations;return Promise.resolve(c.signer.getAddress()).then(function(d){return Promise.resolve(l.call(c,e,d,t)).then(function(l){var d=c.getUserFunds;return Promise.resolve(c.signer.getAddress()).then(function(h){return Promise.resolve(d.call(c,h,e)).then(function(d){function h(){var n=function(){if(0===l.length)return Promise.resolve(c.authorize(r.getAddress(e),r.getAddress(t),(Number(o)/2).toString(),i,s)).then(function(){})}();return n&&n.then?n.then(function(){return{isValid:!0,message:""}}):{isValid:!0,message:""}}var m=function(){if(new M.default(d[0]).isZero()){var t=function(){if(n&&new M.default(r.parseEther(u)).isLessThanOrEqualTo(new M.default(r.parseEther(n)))&&new M.default(r.parseEther(n)).isGreaterThan(new M.default(o)))return Promise.resolve(c.deposit(e,n,a)).then(function(){});var t=function(){if(new M.default(r.parseEther(u)).isLessThanOrEqualTo(new M.default(r.parseEther(o)))){var t=c.deposit;return Promise.resolve(c.unitsToAmount(e,o,a)).then(function(r){return Promise.resolve(t.call(c,e,r,a)).then(function(){})})}return Promise.resolve(c.deposit(e,u,a)).then(function(){})}();return t&&t.then?t.then(function(){}):void 0}();if(t&&t.then)return t.then(function(){})}}();return m&&m.then?m.then(h):h()})})})})})})}var h=function(){if(new M.default(u).isLessThan(new M.default(o)))return Promise.resolve(l.approve(r.getAddress(e),r.getAddress(c.contract.target.toString()),o)).then(function(){})}();return h&&h.then?h.then(d):d()})})})})}catch(e){return Promise.reject(e)}},n.deposit=function(e,t,r,n){try{var o=this;return Promise.resolve(o.amountToUnits(e,t,r)).then(function(t){return Promise.resolve(o.contract.deposit.estimateGas(e,t)).then(function(r){var i;return n?r:Promise.resolve(ue(r,o.getSignerAccordingSdk(),null==(i=o.config)?void 0:i.gasFeeMultiplier,o.contract.deposit,e,t))})})}catch(e){return Promise.reject(e)}},n.withdraw=function(e,t,r,n){try{var o=this,i=[],s=[];if(e.length!==t.length)throw new Error("Tokens and amounts arrays must have the same length");return Promise.resolve(o.signer.getAddress()).then(function(a){function u(){return Promise.resolve(Promise.all(s.map(function(e,t){return o.amountToUnits(i[t],e,r)}))).then(function(t){return Promise.resolve(o.contract.withdraw.estimateGas(e,t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,o.contract.withdraw,i,t))})})}var c,l,d,h,m,f=(c=e,l=function(r){var n=e[r],u=new M.default(t[r]);return Promise.resolve(o.getUserFunds(a,n)).then(function(e){var o=new M.default(e[0]);u.isGreaterThan(0)&&u.isLessThanOrEqualTo(o)?(i.push(n),s.push(t[r])):console.log("Insufficient funds for token "+n)})},m=-1,function e(t){try{for(;++m<c.length;)if((t=l(m))&&t.then){if(!((r=t)instanceof ze&&1&r.s))return void t.then(e,h||(h=Be.bind(null,d=new ze,2)));t=t.v}d?Be(d,1,t):d=t}catch(e){Be(d||(d=new ze),2,e)}var r}(),d);return f&&f.then?f.then(u):u()})}catch(e){return Promise.reject(e)}},n.authorize=function(e,t,r,n,o,i,s){try{var a=this,u=a.getAuthorizations;return Promise.resolve(a.signer.getAddress()).then(function(c){return Promise.resolve(u.call(a,e,c,t)).then(function(u){return 0!==u.length?(console.log("Payee "+t+" already authorized"),null):Promise.resolve(a.amountToUnits(e,r,i)).then(function(r){return Promise.resolve(a.amountToUnits(e,n,i)).then(function(n){return Promise.resolve(a.amountToUnits(e,o,i)).then(function(o){return Promise.resolve(a.contract.authorize.estimateGas(e,t,r,n,o)).then(function(i){var u;return s?i:Promise.resolve(ue(i,a.getSignerAccordingSdk(),null==(u=a.config)?void 0:u.gasFeeMultiplier,a.contract.authorize,e,t,r,n,o))})})})})})})}catch(e){return Promise.reject(e)}},n.cancelExpiredLocks=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.contract.cancelExpiredLocks.estimateGas(e,t,r,n)).then(function(s){var a;return o?s:Promise.resolve(ue(s,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,i.contract.cancelExpiredLocks,e,t,r,n))})}catch(e){return Promise.reject(e)}},t}(ke),We=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return H.default.abi},r.isTokenAllowed=function(e){try{return Promise.resolve(this.contract.isTokenAllowed(e))}catch(e){return Promise.reject(e)}},r.getToken=function(e){try{return Promise.resolve(this.contract.getToken(e))}catch(e){return Promise.reject(e)}},r.calculateFee=function(e,t,r){try{var n=this,o=n.amountToUnits(e,t.toString(),r);return Promise.resolve(n.contract.calculateFee(e,o)).then(function(t){return n.unitsToAmount(e,t,r)})}catch(e){return Promise.reject(e)}},t}(ke),He=function(e){try{return Promise.resolve(new Promise(function(t){setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},Ve=function(e,t){try{var n=r.keccak256(r.toUtf8Bytes(t)),o=r.getBytes(n);if(!e.provider)throw new Error("Provider is required but not available");return Promise.resolve(e.provider.getNetwork()).then(function(t){var r=t.chainId;return function(t,r){try{var n=Promise.resolve(e.signMessage(o))}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(t){return re.error("Sign message error: ",t),function(){if(8996===Number(r))return console.log("Signing message with _legacySignMessage"),Promise.resolve(e._legacySignMessage(o))}()})})}catch(e){return Promise.reject(e)}};function Ze(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function Xe(e,t,r){if(!e.s){if(r instanceof Ke){if(!r.s)return void(r.o=Xe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Xe.bind(null,e,t),Xe.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Ke=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Xe(n,1,i(this.v))}catch(e){Xe(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Xe(n,1,t?t(o):o):r?Xe(n,1,r(o)):Xe(n,2,o)}catch(e){Xe(n,2,e)}},n},e}();function $e(e){return e instanceof Ke&&1&e.s}var Ye=/*#__PURE__*/function(){function e(e){this.aquariusURL=void 0,this.aquariusURL=e}var t=e.prototype;return t.resolve=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/ddo/"+e;return Promise.resolve(Ze(function(){return Promise.resolve(V.default(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return Promise.resolve(e.json());throw new Error("HTTP request failed with status "+e.status)})},function(e){throw re.error(e),new Error("HTTP request failed")}))}catch(e){return Promise.reject(e)}},t.waitForIndexer=function(e,t,r,n,o,i){void 0===n&&(n=3e4),void 0===o&&(o=100);try{var s,a=this,u=0;o>500&&(re.warn("Max Limit exceeded, defaulting to 500 retries."),o=500);var c=function(e,t){var r;do{var n=e();if(n&&n.then){if(!$e(n)){r=!0;break}n=n.v}var o=t();if($e(o)&&(o=o.v),!o)return n}while(!o.then);var i=new Ke,s=Xe.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;$e(o=t())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=e())&&n.then){if(!$e(n))return void n.then(a).then(void 0,s);n=n.v}}Xe(i,1,n)}function u(r){if(r){do{if((n=e())&&n.then){if(!$e(n))return void n.then(a).then(void 0,s);n=n.v}if($e(r=t())&&(r=r.v),!r)return void Xe(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else Xe(i,1,n)}}(function(){function o(e){return s?e:Promise.resolve(He(n)).then(function(){u++})}var c=Ze(function(){return Promise.resolve(V.default(a.aquariusURL+"/api/aquarius/assets/ddo/"+e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:i},signal:r})).then(function(e){return function(){if(e.ok)return Promise.resolve(e.json()).then(function(e){var r=w.DDOManager.getDDOClass(e).getAssetFields().indexedMetadata;return t?r.event&&r.event.txid===t?(s=1,e):void 0:(s=1,e)})}()})},function(){});return c&&c.then?c.then(o):o(c)},function(){return!s&&u<o});return Promise.resolve(c&&c.then?c.then(function(e){return s?e:null}):s?c:null)}catch(e){return Promise.reject(e)}},t.validate=function(e,t,r,n,o){try{var i=r+"/api/aquarius/assets/ddo/validate",s=r+"/api/services/nonce";return Promise.resolve(Ze(function(){return Promise.resolve(t.getAddress()).then(function(r){return Promise.resolve(V.default(s+"?userAddress="+r,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o},signal:n})).then(function(s){return Promise.resolve(s.json()).then(function(s){var a=s.nonce;console.log("[getNonce] Consumer: "+r+" nonce: "+a),a&&null!==a||(a="0");var u=(Number(a)+1).toString();return Promise.resolve(Ve(t,r+u)).then(function(t){return Promise.resolve(V.default(i,{method:"POST",body:JSON.stringify({ddo:e,publisherAddress:r,nonce:u,signature:t}),headers:{"Content-Type":"application/octet-stream",Authorization:o},signal:n})).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw new Error("Metadata validation failed");return console.log("Ddo successfully validated"),{valid:!0,hash:t.hash,proof:{validatorAddress:t.publicKey,r:t.r[0],s:t.s[0],v:t.v}}})})})})})})},function(e){re.error("Metadata validation failed",e.message)}))}catch(e){return Promise.reject(e)}},t.getAssetMetadata=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/metadata/"+e;return Promise.resolve(Ze(function(){return Promise.resolve(V.default(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("getAssetMetadata failed: "+e.status+e.statusText)})},function(e){throw re.error("Error getting metadata: ",e),new Error("Error getting metadata: "+e)}))}catch(e){return Promise.reject(e)}},t.querySearch=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/query";return Promise.resolve(Ze(function(){return Promise.resolve(V.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("querySearch failed: "+e.status+e.statusText)})},function(e){throw re.error("Error querying metadata: ",e),new Error("Error querying metadata: "+e)}))}catch(e){return Promise.reject(e)}},e}();function Qe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var et=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getConsumerAddress=function(e){try{return Promise.resolve("string"==typeof e?function(e){try{return Z.default.decode(e,{json:!0})}catch(e){throw new Error("Error decoding JWT")}}(e).address:e.getAddress())}catch(e){return Promise.reject(e)}},t.getSignature=function(e,t){try{return Promise.resolve("string"==typeof e?null:this.signProviderRequest(e,t))}catch(e){return Promise.reject(e)}},t.getAuthorization=function(e){return"string"==typeof e?e:void 0},t.getEndpoints=function(e,t){try{var r=this;return Promise.resolve(Qe(function(){return Promise.resolve(r.getData(e,t)).then(function(e){return Promise.resolve(e.json())})},function(e){throw re.error("Finding the service endpoints failed:",e),new Error("HTTP request failed calling Provider")}))}catch(e){return Promise.reject(e)}},t.getEndpointURL=function(e,t){return e?e.find(function(e){return e.serviceName.toLowerCase()===t.toLowerCase()}):null},t.getServiceEndpoints=function(e,t){try{var r=[];for(var n in t.serviceEndpoints){var o={serviceName:n,method:t.serviceEndpoints[n][0],urlPath:e.replace(/\/+$/,"")+"/"+t.serviceEndpoints[n][1].replace(/^\/+/,"")};r.push(o)}return Promise.resolve(r)}catch(e){return Promise.reject(e)}},t.getNonce=function(e,t,r,n,o){try{var i=function(){function i(){var e=s.getEndpointURL(o,"nonce")?s.getEndpointURL(o,"nonce").urlPath:null;return e?Qe(function(){return Promise.resolve(V.default(e+"?userAddress="+t,{method:"GET",headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return Promise.resolve(e.json()).then(function(e){var r=e.nonce;return console.log("[getNonce] Consumer: "+t+" nonce: "+r),r&&null!==r?Number(r):0})})},function(e){throw re.error(e),new Error(e.message)}):null}var a=function(){if(!o)return Promise.resolve(s.getServiceEndpoints(e,n)).then(function(e){o=e})}();return a&&a.then?a.then(i):i()},s=this,a=function(){if(!n)return Promise.resolve(s.getEndpoints(e)).then(function(e){n=e})}();return Promise.resolve(a&&a.then?a.then(i):i())}catch(e){return Promise.reject(e)}},t.signProviderRequest=function(e,t){try{var n=r.ethers.solidityPackedKeccak256(["bytes"],[r.ethers.hexlify(r.ethers.toUtf8Bytes(t))]),o=r.ethers.toBeArray(n);return Promise.resolve(Qe(function(){return Promise.resolve(e.signMessage(o))},function(){return Promise.resolve(e.provider.getNetwork()).then(function(t){var r=Number(t.chainId);return function(){if(8996===r)return Promise.resolve(e._legacySignMessage(o))}()})}))}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getEndpoints(r)).then(function(o){return Promise.resolve(s.getServiceEndpoints(r,o)).then(function(a){return Promise.resolve(s.getConsumerAddress(n)).then(function(u){return Promise.resolve(s.getNonce(r,u,i,o,a)).then(function(r){var o=(r+1).toString(),c=String(o);return Promise.resolve(s.getSignature(n,c)).then(function(r){var n=(s.getEndpointURL(a,"encrypt")?s.getEndpointURL(a,"encrypt").urlPath:null)+"?chainId="+t;return n?(n+="?nonce="+o,n+="&consumerAddress="+u,n+="&signature="+r,Qe(function(){return Promise.resolve(V.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/octet-stream"},signal:i})).then(function(e){return Promise.resolve(e.text())})},function(e){throw re.error(e),new Error("HTTP request failed calling Provider")})):null})})})})})}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{var i=this;return Promise.resolve(i.getEndpoints(r)).then(function(s){return Promise.resolve(i.getServiceEndpoints(r,s)).then(function(r){function s(e){var t;function r(e){return t?e:Promise.resolve(a.json()).then(function(e){throw re.error("File info call failed: ",a.status,a.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=a)&&e.ok)return Promise.resolve(a.json()).then(function(e){for(var r,n=$(e);!(r=n()).done;)c.push(r.value);return t=1,c})}();return n&&n.then?n.then(r):r(n)}var a,u={did:e,serviceId:t,checksum:n},c=[],l=i.getEndpointURL(r,"fileinfo")?i.getEndpointURL(r,"fileinfo").urlPath:null;if(!l)return null;var d=Qe(function(){return Promise.resolve(V.default(l,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:o})).then(function(e){a=e})},function(e){throw re.error("File info call failed: "),re.error(e),new Error(e)});return d&&d.then?d.then(s):s()})})}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{var o=this;return Promise.resolve(o.getEndpoints(t)).then(function(i){return Promise.resolve(o.getServiceEndpoints(t,i)).then(function(t){function i(e){var t;function r(e){return t?e:Promise.resolve(s.json()).then(function(e){throw re.error("File info call failed: ",s.status,s.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=s)&&e.ok)return Promise.resolve(s.json()).then(function(e){for(var r,n=$(e);!(r=n()).done;)u.push(r.value);return t=1,u})}();return n&&n.then?n.then(r):r(n)}var s,a=Y({},e,{checksum:r}),u=[],c=o.getEndpointURL(t,"fileinfo")?o.getEndpointURL(t,"fileinfo").urlPath:null;if(!c)return null;var l=Qe(function(){return Promise.resolve(V.default(c,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){s=e})},function(e){throw re.error("File info call failed: "),re.error(e),new Error(e)});return l&&l.then?l.then(i):i()})})}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{var r=this;return Promise.resolve(r.getEndpoints(e)).then(function(n){return Promise.resolve(r.getServiceEndpoints(e,n)).then(function(e){var n;function o(e){var t;return null!=(t=i)&&t.ok?i.json():Promise.resolve(i.json()).then(function(e){throw re.error("Fetch compute env failed: ",i.status,i.statusText,e),new Error(JSON.stringify(e))})}var i,s=null==(n=r.getEndpointURL(e,"computeEnvironments"))?void 0:n.urlPath;if(!s)return null;var a=Qe(function(){return Promise.resolve(V.default(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){i=e})},function(e){throw re.error("Fetch compute env failed: "),re.error(e),new Error(e)});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(o)).then(function(l){return Promise.resolve(c.getServiceEndpoints(o,l)).then(function(o){function l(e){var t;function r(e){return t?e:Promise.resolve(d.json()).then(function(e){throw re.error("Provider initialized failed: ",d.status,d.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(200===(null==(e=d)?void 0:e.status))return Promise.resolve(d.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d,h=c.getEndpointURL(o,"initialize")?c.getEndpointURL(o,"initialize").urlPath:null;if(!h)return null;h+="?documentId="+e,h+="&serviceId="+t,h+="&fileIndex="+r,h+="&consumerAddress="+n,s&&(h+="&userdata="+encodeURI(JSON.stringify(s))),a&&(h+="&environment="+encodeURI(a)),u&&(h+="&validUntil="+u);var m=Qe(function(){return Promise.resolve(V.default(h,{method:"GET",headers:{"Content-Type":"application/json"},signal:i})).then(function(e){d=e})},function(e){throw re.error("Provider initialized failed: "),re.error(e),new Error("Provider initialize failed url: "+h+" ")});return m&&m.then?m.then(l):l()})})}catch(e){return Promise.reject(e)}},t.initializeComputeV1=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(n)).then(function(l){return Promise.resolve(c.getServiceEndpoints(n,l)).then(function(n){function l(e){var t;function r(e){return t?e:Promise.resolve(d.json()).then(function(e){throw re.error("Initialize compute failed: ",d.status,d.statusText,e),re.error("Payload was:",JSON.stringify(h)),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=d)&&e.ok)return Promise.resolve(d.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d,h={datasets:e,algorithm:t,payment:{chainId:i,token:s,maxJobDuration:a},consumerAddress:o,environment:r},m=c.getEndpointURL(n,"initializeCompute")?c.getEndpointURL(n,"initializeCompute").urlPath:null;if(!m)return null;var f=Qe(function(){return Promise.resolve(V.default(m,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json"},signal:u})).then(function(e){d=e})},function(e){throw re.error("Initialize compute failed: "),re.error(e),new Error("ComputeJob cannot be initialized")});return f&&f.then?f.then(l):l()})})}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l){try{var d=this;return Promise.resolve(d.getEndpoints(i)).then(function(h){return Promise.resolve(d.getServiceEndpoints(i,h)).then(function(m){var f=d.getEndpointURL(m,"initializeCompute")?d.getEndpointURL(m,"initializeCompute").urlPath:null;return f?Promise.resolve(d.getConsumerAddress(s)).then(function(v){return Promise.resolve(d.getNonce(i,v,l,h,m)).then(function(i){var h,m=(i+1).toString(),g=v;return g+=null==(h=e[0])?void 0:h.documentId,g+=m,Promise.resolve(d.getSignature(s,g)).then(function(i){function h(e){var t;function r(e){return t?e:Promise.resolve(m.json()).then(function(e){throw re.error("Initialize compute failed: ",m.status,m.statusText,e),re.error("Payload was:",JSON.stringify(g)),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=m)&&e.ok)return Promise.resolve(m.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var m,g={datasets:e,algorithm:t,environment:r,payment:{chainId:u,token:n,resources:a},maxJobDuration:o,consumerAddress:v,signature:i};c&&(g.policyServer=c);var p=Qe(function(){return console.log("Initialize compute url:",f),Promise.resolve(V.default(f,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json",Authorization:d.getAuthorization(s)},signal:l})).then(function(e){return m=e,console.log("Raw response:",m),function(){if(!m.ok)return Promise.resolve(m.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw re.error("Initialize compute failed: "),re.error(e),new Error("ComputeJob cannot be initialized: "+e.message+".")});return p&&p.then?p.then(h):h()})})}):null})})}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getEndpoints(o)).then(function(c){return Promise.resolve(u.getServiceEndpoints(o,c)).then(function(l){var d=u.getEndpointURL(l,"download")?u.getEndpointURL(l,"download").urlPath:null;return d?Promise.resolve(u.getConsumerAddress(i)).then(function(h){return Promise.resolve(u.getNonce(o,h,null,c,l)).then(function(o){var c=(o+1).toString();return Promise.resolve(u.getSignature(i,e+c)).then(function(o){var i=d;return i+="?fileIndex="+r,i+="&documentId="+e,i+="&transferTxId="+n,i+="&serviceId="+t,i+="&consumerAddress="+h,i+="&nonce="+c,s&&(i+="&policyServer="+encodeURI(JSON.stringify(s))),i+="&signature="+o,a&&(i+="&userdata="+encodeURI(JSON.stringify(a))),i})})}):null})})}catch(e){return Promise.reject(e)}},t.computeStartV1=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getEndpoints(e)).then(function(c){return Promise.resolve(u.getServiceEndpoints(e,c)).then(function(l){var d=u.getEndpointURL(l,"computeStart")?u.getEndpointURL(l,"computeStart").urlPath:null;return Promise.resolve(t.getAddress()).then(function(h){return Promise.resolve(u.getNonce(e,h,i,c,l)).then(function(e){var c=(e+1).toString(),l=h;return l+=n.documentId,l+=c,Promise.resolve(u.signProviderRequest(t,l)).then(function(e){function t(e){var t;function r(e){if(t)return e;var r=re.error,n=u.statusText,o=u.status;return Promise.resolve(u.json()).then(function(e){return r.call(re,"Compute start failed: ",o,n,e),re.error("Payload was:",l),null})}var n=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var u,l=Object();if(l.consumerAddress=h,l.signature=e,l.nonce=c,l.environment=r,l.dataset=n,l.algorithm=o,s&&(l.additionalDatasets=s),a&&(l.output=a),!d)return null;var m=Qe(function(){return Promise.resolve(V.default(d,{method:"POST",body:JSON.stringify(l),headers:{"Content-Type":"application/json"},signal:i})).then(function(e){u=e})},function(e){throw re.error("Compute start failed:"),re.error(e),re.error("Payload was:",l),new Error("HTTP request failed calling Provider")});return m&&m.then?m.then(t):t()})})})})})}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,d,h,m,f){try{var v=this;return console.log("called new compute start method..."),console.log("datasets: ",n),console.log("algorithm: ",o),Promise.resolve(v.getEndpoints(e)).then(function(g){return Promise.resolve(v.getServiceEndpoints(e,g)).then(function(p){var P=v.getEndpointURL(p,"computeStart")?v.getEndpointURL(p,"computeStart").urlPath:null;return P?Promise.resolve(v.getConsumerAddress(t)).then(function(y){return Promise.resolve(v.getNonce(e,y,m,g,p)).then(function(e){var g,p=(e+1).toString(),w=String(y+(null==(g=n[0])?void 0:g.documentId)+p);return Promise.resolve(v.getSignature(t,w)).then(function(e){function g(e){var t;function r(e){return t?e:Promise.resolve(w.json()).then(function(e){throw re.error("Compute start failed: ",w.status,w.statusText,e),re.error("Payload was:",b),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=w)&&e.ok)return Promise.resolve(w.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var w,b=Object();b.consumerAddress=y,b.signature=e,b.nonce=p,b.environment=r,b.maxJobDuration=i,b.resources=a,b.dataset=n[0],b.datasets=n,b.algorithm=o,b.chainId=u,b.payment={chainId:u,token:s,maxJobDuration:i},a&&(b.resources=a),c&&(b.metadata=c),l&&(b.additionalViewers=l),d&&(b.output=d),h&&(b.policyServer=h),f&&(b.queueMaxWaitTime=f);var k=Qe(function(){return Promise.resolve(V.default(P,{method:"POST",body:JSON.stringify(b),headers:{"Content-Type":"application/json",Authorization:v.getAuthorization(t)},signal:m})).then(function(e){w=e})},function(e){throw re.error("Compute start failed:"),re.error(e),re.error("Payload was:",b),new Error("HTTP request failed calling Provider")});return k&&k.then?k.then(g):g()})})}):(re.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,d){try{var h=this;return console.log("called new free compute start method..."),console.log("datasets: ",n),console.log("algorithm: ",o),Promise.resolve(h.getEndpoints(e)).then(function(m){return Promise.resolve(h.getServiceEndpoints(e,m)).then(function(f){var v=h.getEndpointURL(f,"freeCompute")?h.getEndpointURL(f,"freeCompute").urlPath:null;return v?Promise.resolve(h.getConsumerAddress(t)).then(function(g){return Promise.resolve(h.getNonce(e,g,l,m,f)).then(function(e){var m=(e+1).toString(),f=m;return console.log("signatureMessage: ",f),Promise.resolve(h.getSignature(t,f)).then(function(e){function f(e){var t;function r(e){return t?e:Promise.resolve(p.json()).then(function(e){throw re.error("Compute start failed: ",p.status,p.statusText,e),re.error("Payload was:",P),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=p)&&e.ok)return Promise.resolve(p.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var p,P=Object();P.consumerAddress=g,P.signature=e,P.nonce=m,P.environment=r,P.resources=i,P.dataset=n[0],P.datasets=n,P.algorithm=o,s&&(P.metadata=s),a&&(P.additionalViewers=a),P.output=u,c&&(P.policyServer=c),d&&(P.queueMaxWaitTime=d);var y=Qe(function(){return Promise.resolve(V.default(v,{method:"POST",body:JSON.stringify(P),headers:{"Content-Type":"application/json",Authorization:h.getAuthorization(t)},signal:l})).then(function(e){p=e})},function(e){throw re.error("Compute start failed:"),re.error(e),re.error("Payload was:",P),new Error("HTTP request failed calling Provider")});return y&&y.then?y.then(f):f()})})}):(re.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeStreamableLogs")?o.getEndpointURL(a,"computeStreamableLogs").urlPath:null;return u?Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,n,s,a)).then(function(e){function s(){var e;function r(t){var r,n;if(null!=(r=e)&&r.ok||200===(null==(n=e)?void 0:n.status))return console.log("Response body:",e.body),e.body;var o=re.error,i=e.statusText,s=e.status;return Promise.resolve(e.json()).then(function(e){return o.call(re,"computeStreamableLogs failed: ",s,i,e),null})}var i=Qe(function(){return Promise.resolve(V.default(u+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o.getAuthorization(t)},signal:n})).then(function(t){e=t,console.log("Raw response:",e)})},function(e){throw re.error("computeStreamableLogs failed:"),re.error(e),new Error("HTTP request failed calling Provider")});return i&&i.then?i.then(r):r()}var a=(e+1).toString(),l="?consumerAddress="+c+"&jobId="+r,d=function(){if(!i)return Promise.resolve(o.getSignature(t,""+c+r+a)).then(function(e){l+="&signature="+e,l+="&nonce="+a})}();return d&&d.then?d.then(s):s()})}):(re.error("Compute start failed: Cannot get proper computeStreamableLogs route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.getComputeStartRoutes=function(e,t){void 0===t&&(t=!1);try{var r=this;return Promise.resolve(r.getEndpoints(e)).then(function(n){return Promise.resolve(r.getServiceEndpoints(e,n)).then(function(e){return t?r.getEndpointURL(e,"freeCompute")?r.getEndpointURL(e,"freeCompute").urlPath:null:r.getEndpointURL(e,"computeStart")?r.getEndpointURL(e,"computeStart").urlPath:null})})}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{var i=this,s="string"==typeof r;return Promise.resolve(i.getEndpoints(t)).then(function(a){return Promise.resolve(i.getServiceEndpoints(t,a)).then(function(u){var c=i.getEndpointURL(u,"computeStop")?i.getEndpointURL(u,"computeStop").urlPath:null;return Promise.resolve(i.getConsumerAddress(r)).then(function(l){return Promise.resolve(i.getNonce(t,l,o,a,u)).then(function(t){var a=(t+1).toString();return Promise.resolve(i.getSignature(r,l+(e||""))).then(function(t){function u(e){var t;function r(e){return t?e:Promise.resolve(h.json()).then(function(e){throw re.error("Compute stop failed: ",h.status,h.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=h)&&e.ok)return Promise.resolve(h.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d=new URLSearchParams;d.set("consumerAddress",l),d.set("nonce",a),d.set("jobId",e),s||d.set("signature",t),n&&d.set("agreementId",n);var h,m=d.toString();if(!m)return null;var f=Qe(function(){return Promise.resolve(V.default(c+"?"+m,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:i.getAuthorization(r)},signal:o})).then(function(e){h=e})},function(e){throw re.error("Compute stop failed:"),re.error(e),new Error("HTTP request failed calling Provider")});return f&&f.then?f.then(u):u()})})})})})}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getEndpoints(e)).then(function(a){return Promise.resolve(s.getServiceEndpoints(e,a)).then(function(e){function a(e){var t;function r(e){var r;if(t)return e;function n(e){return r?e:Promise.resolve(u.json()).then(function(e){throw re.error("Get compute status failed:",u.status,u.statusText,e),new Error(JSON.stringify(e))})}re.error("Get compute status failed:",u.status,u.statusText);var o=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var n=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var u,c=s.getEndpointURL(e,"computeStatus")?s.getEndpointURL(e,"computeStatus").urlPath:null,l="?consumerAddress="+t;if(l+=n&&"&agreementId="+n||"",l+=r&&"&jobId="+r||"",!c)return null;var d=Qe(function(){return console.log("computeStatusUrl: ",c+l),Promise.resolve(V.default(c+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:i},signal:o})).then(function(e){u=e})},function(e){throw re.error("Get compute status failed"),re.error(e),new Error(e)});return d&&d.then?d.then(a):a()})})}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeResult")?o.getEndpointURL(a,"computeResult").urlPath:null;return Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,null,s,a)).then(function(e){var s=(e+1).toString(),a=c;return a+=r,a+=n.toString(),a+=s,Promise.resolve(o.getSignature(t,a)).then(function(e){if(!u)return null;var t=u;return t+="?consumerAddress="+c,t+="&jobId="+r,t+="&index="+n.toString(),i||(t+="&nonce="+s,t+="&signature="+e),t})})})})})}catch(e){return Promise.reject(e)}},t.computeDelete=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.getEndpoints(n)).then(function(s){return Promise.resolve(i.getServiceEndpoints(n,s)).then(function(a){var u=i.getEndpointURL(a,"computeDelete")?i.getEndpointURL(a,"computeDelete").urlPath:null;return Promise.resolve(i.getConsumerAddress(t)).then(function(c){return Promise.resolve(i.getNonce(n,c,o,s,a)).then(function(n){var s=(n+1).toString(),a=c;return a+=r||"",a+=e&&""+i.noZeroX(e)||"",a+=s,Promise.resolve(i.getSignature(t,a)).then(function(n){function s(e){var t;function r(e){return t?e:Promise.resolve(a.json()).then(function(e){throw re.error("Delete compute job failed:",a.status,a.statusText,e),re.error("Payload was:",l),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=a)&&e.ok)return Promise.resolve(a.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var a,l=Object();if(l.documentId=e,l.consumerAddress=c,l.jobId=r,n&&(l.signature=n),!u)return null;var d=Qe(function(){return Promise.resolve(V.default(u,{method:"DELETE",body:JSON.stringify(l),headers:{"Content-Type":"application/json",Authorization:i.getAuthorization(t)},signal:o})).then(function(e){a=e})},function(e){throw re.error("Delete compute job failed:"),re.error(e),re.error("Payload was:",l),new Error("HTTP request failed calling Provider")});return d&&d.then?d.then(s):s()})})})})})}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{var n=this;return Promise.resolve(e.getAddress()).then(function(o){return Promise.resolve(n.getEndpoints(t)).then(function(i){return Promise.resolve(n.getServiceEndpoints(t,i)).then(function(s){var a=n.getEndpointURL(s,"generateAuthToken").urlPath||null;return Promise.resolve(n.getNonce(t,o,r,i,s)).then(function(t){var i=(t+1).toString();return Promise.resolve(n.signProviderRequest(e,o+i)).then(function(e){return Qe(function(){return Promise.resolve(V.default(a,{method:"POST",body:JSON.stringify({address:o,signature:e,nonce:i}),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to generate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){return null==e?void 0:e.token})})},function(e){throw re.error("Generate auth token failed:"),re.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{var o=this;return Promise.resolve(e.getAddress()).then(function(i){return Promise.resolve(o.getEndpoints(r)).then(function(s){return Promise.resolve(o.getServiceEndpoints(r,s)).then(function(a){var u=o.getEndpointURL(a,"invalidateAuthToken").urlPath||null;return Promise.resolve(o.getNonce(r,i,n,s,a)).then(function(r){var s=(r+1).toString();return Promise.resolve(o.signProviderRequest(e,i+s)).then(function(e){return Qe(function(){return Promise.resolve(V.default(u,{method:"POST",body:JSON.stringify({address:i,signature:e,token:t,nonce:s}),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to invalidate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json())})},function(e){throw re.error("Generate auth token failed:"),re.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){try{return Promise.resolve(Qe(function(){return Promise.resolve(V.default(e,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){var t,r=function(){if(null!=e&&e.ok)return Promise.resolve(e.json()).then(function(e){if(e&&(e.providerAddress||e.providerAddresses))return t=!0})}();return r&&r.then?r.then(function(e){return!!t&&e}):!!t&&r})},function(e){return re.error("Error validating provider: "+e.message),!1}))}catch(e){return Promise.reject(e)}},t.PolicyServerPassthrough=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw re.error("PolicyServerPassthrough failed: ",i.status,i.statusText,e),re.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"PolicyServerPassthrough")?n.getEndpointURL(e,"PolicyServerPassthrough").urlPath:null;if(!s)return null;var a=Qe(function(){return Promise.resolve(V.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw re.error("PolicyServerPassthrough failed: "),re.error(e),new Error("PolicyServerPassthrough failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw re.error("initializePSVerification failed: ",i.status,i.statusText,e),re.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"initializePSVerification")?n.getEndpointURL(e,"initializePSVerification").urlPath:null;if(!s)return null;var a=Qe(function(){return Promise.resolve(V.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw re.error("initializePSVerification failed: "),re.error(e),new Error("initializePSVerification failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.noZeroX=function(e){return this.zeroXTransformer(e,!1)},t.zeroXTransformer=function(e,t){void 0===e&&(e="");var r=this.inputMatch(e,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(t&&r.valid?"0x":"")+r.output},t.inputMatch=function(e,t,r){if("string"!=typeof e)throw re.debug("Not input string:"),re.debug(e),new Error("["+r+"] Expected string, input type: "+typeof e);var n=e.match(t);return n?{valid:!0,output:n[1]}:(re.warn("["+r+"] Input transformation failed."),{valid:!1,output:e})},t.getData=function(e,t){try{return Promise.resolve(V.default(e,{method:"GET",headers:{"Content-type":"application/json",Authorization:t}}))}catch(e){return Promise.reject(e)}},e}(),tt=new et,rt=function(e,t,n,o){try{var i=new r.ethers.Contract(t,ae,e);return Promise.resolve(i.allowance(n,o))}catch(e){return Promise.reject(e)}},nt=function(e,t,n,o,i){try{var s=new r.ethers.Contract(t,ae,e);return Promise.resolve(s.allowance(n,o)).then(function(r){return Promise.resolve(le(e,t,r,i))})}catch(e){return Promise.reject(e)}},ot=function(e,t,n,o,i,s,a,u){void 0===a&&(a=!1);try{var c,l=function(r){if(c)return r;var n=null;return Promise.resolve(d.approve.estimateGas(i,s)).then(function(r){if(u)return r;var o=function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){return Promise.resolve(ue(r,e,null==t?void 0:t.gasFeeMultiplier,d.approve,i,s)).then(function(e){n=e})},function(e){re.error("ERROR: Failed to approve spender to spend tokens : "+e.message)});return o&&o.then?o.then(function(){return n}):n})},d=new r.ethers.Contract(o,ae,e),h=function(){if(!a)return Promise.resolve(rt(e,o,n,i)).then(function(e){if(new M.default(e).isGreaterThan(new M.default(s))){var t=BigInt(e);return c=1,t}})}();return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}},it=function(e,t,n,o,i,s,a,u,c){void 0===a&&(a=!1);try{var l,d=function(r){return l?r:Promise.resolve(ce(e,o,s,u)).then(function(r){return Promise.resolve(h.approve.estimateGas(i,r)).then(function(n){return c?new O.default(n.toString()):Promise.resolve(ue(n,e,null==t?void 0:t.gasFeeMultiplier,h.approve,i,r))})})},h=new r.ethers.Contract(o,ae,e),m=function(){if(!a)return Promise.resolve(nt(e,o,n,i)).then(function(e){if(new O.default(e).greaterThanOrEqualTo(new O.default(s))){var t=new O.default(e).toNumber();return l=1,t}})}();return Promise.resolve(m&&m.then?m.then(d):d(m))}catch(e){return Promise.reject(e)}},st={datasets:{invalid:"Datasets is not a list, as expected"},algorithm:{serviceId:{missing:"The serviceId key is missing from the algorithm s DDO.",not_found:"The provided serviceId does not exist.",service_not_access_compute:"Service type is neither access, nor compute.",main_service_compute:"If the main service is not compute for this asset when calling initialize endpoint.",compute_services_not_in_same_provider:"Files attached to the compute service are not decrypted by the correct provider. This occurs when both asset and algorithm are requested by their compute service which cannot be decrypted by a single provider as how it is supposed to be."},container:{checksum_prefix:"Container checksum does not start with the prefix sha256:.",mising_entrypoint_image_checksum:"Either entrypoint, either image, or either checksum are missing from the container dictionary from the algorithm s DDO."},documentId:{did_not_found:"The algorithm s DID could not be retrieved from the metadata store, because the algorithm asset does not exist.",missing:"The documentId key is missing from the algorithm s DDO."},transferTxId:{missing:"The transferTxId key is missing from the algorithm s DDO."},missing_meta_documentId:"Either algorithm metadata, or algorithm DID are missing.",did_not_found:"Either algorithm metadata, or algorithm DID are missing.",not_algo:"Either algorithm metadata, or algorithm DID are missing.",in_use_or_not_on_chain:"Either algorithm metadata, or algorithm DID are missing.",meta_oneof_url_rawcode_remote:"Either algorithm metadata, or algorithm DID are missing.",file_unavailable:"One possibility is that the asset could not be retrieved from Aquariuss database. Otherwise, there are issues related to services"},error:{not_trusted_algo_publisher:"The owner of the algorithm's DDO is not a trusted algorithms publishers list.",not_trusted_algo:"The algorithm's DID is not in the asset's trusted algorithms dictionary. ",no_publisherTrustedAlgorithms:"The algorithm's key publisherTrustedAlgorithms does not exist in the algorithm's DDO.",algorithm_file_checksum_mismatch:"filesChecksum from the algorithm's DDO is invalid.",algorithm_container_checksum_mismatch:"The containerChecksum from the algorithm's DDO is invalid.",no_raw_algo_allowed:"The asset does not allow raw algorithms to be run on it.","Asset malformed":"The asset published on chain is malformed, missing some required keys or not compliant with our schemas.","Asset is not consumable.":"Assets metadata status is not in the range of valid status codes for assets. The recognized states for the metadata are defined on our docs.","DID is not a valid algorithm.":"Either the algorithm assets DID is incorrectly typed, either the algorithm timeout expired.","Compute environment does not exist.":"The compute environment provided by the user does not exist, it is not served by our compute-to-data feature. The user can use get_c2d_environments to check the list of available compute environments.","The validUntil value is not correct.":"validUntil value is most probably expired.","Cannot resolve DID":"The dataset DID does not exist in the Metadata store.","Invalid serviceId":"The serviceId of that dataset is not correct.","Unable to get dataset files":"The files of that dataset could not be decrypted or retrieved","cannot decrypt files for this service.":"The files of that dataset could not be decrypted due to the fact that file object, which contains the structure and the type of specific file, is missing from the validation part.","Unsupported type ":"The file object type is not supported by Provider.","malformed file object":"The file object structure is invalid and does not contain the wanted information for the specific file."},order:{fees_not_paid:" Provider fees are not paid."},output:{invalid:"The algorithms validation after the build stage has not been decoded properly as a dictionary."}};function at(e,t,r){if(!e.s){if(r instanceof ut){if(!r.s)return void(r.o=at.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(at.bind(null,e,t),at.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ut=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{at(n,1,i(this.v))}catch(e){at(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?at(n,1,t?t(o):o):r?at(n,1,r(o)):at(n,2,o)}catch(e){at(n,2,e)}},n},e}();function ct(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}exports.AccessListContract=_e,exports.AccesslistFactory=qe,exports.Aquarius=Ye,exports.Config=function(){this.nodeUri=void 0,this.providerAddress=void 0,this.oceanNodeUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.routerFactoryAddress=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.EnterpriseFeeCollector=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.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0,this.sdk=void 0,this.accessListFactory=void 0,this.escrow=void 0},exports.ConfigHelper=se,exports.DEVELOPMENT_CHAIN_ID=8996,exports.Datatoken=Le,exports.Datatoken4=Ge,exports.Dispenser=Te,exports.EnterpriseFeeCollectorContract=We,exports.EscrowContract=Je,exports.FEE_HISTORY_NOT_SUPPORTED="Returned error: Method eth_feeHistory not supported.",exports.FixedRateExchange=Ae,exports.GASLIMIT_DEFAULT=1e6,exports.KNOWN_CONFIDENTIAL_EVMS=ie,exports.Logger=te,exports.LoggerInstance=re,exports.MAX_UINT_256="115792089237316195423570985008687907853269984665640564039457584007913129639934",exports.Nft=Ie,exports.NftFactory=je,exports.Provider=et,exports.ProviderInstance=tt,exports.Router=Ee,exports.SmartContract=be,exports.SmartContractWithAddress=ke,exports.ZERO_ADDRESS=Se,exports.allowance=nt,exports.allowanceWei=rt,exports.amountToUnits=ce,exports.approve=it,exports.approveWei=ot,exports.balance=function(e,t,n,o){try{var i=new r.ethers.Contract(t,ae,e);return Promise.resolve(i.balanceOf(n)).then(function(r){return Promise.resolve(le(e,t,r,o))})}catch(e){return Promise.reject(e)}},exports.calculateActiveTemplateIndex=Ne,exports.configHelperNetworks=oe,exports.createAccessListFactory=function(e,t,n){try{var o=new r.ethers.Contract(e,J.default.abi,t);return Promise.resolve(t.getAddress()).then(function(e){var t,r=ct(function(){return Promise.resolve(o.deployAccessListContract("AllowList","ALLOW",!0,e,n||[e],["https://oceanprotocol.com/nft/"])).then(function(e){return function(){if(e&&e.wait)return Promise.resolve(e.wait()).then(function(e){var r=we(e,"NewAccessList");return t=1,r.args[0]})}()})},function(e){console.log("ERROR createAccessListFactory(): ",e)});return r&&r.then?r.then(function(e){return t?e:null}):t?r:null})}catch(e){return Promise.reject(e)}},exports.createAsset=function(e,t,n,o,i,s,a,u,c,l,d,h,m,f,v){void 0===a&&(a=!0);try{var g,p,P=this,y=w.DDOManager.getDDOClass(s),b=y.getAssetFields().indexedMetadata,k=(null==(g=y.getDDOData())||null==(g=g.stats)||null==(g=g.price)?void 0:g.value)||(null==b||null==(p=b.stats[0])||null==(p=p.prices[0])?void 0:p.price),S=y.getDDOFields(),A=S.chainId,E=S.nftAddress,F=y.getDDOFields().services;if("string"!=typeof i&&"number"!=typeof i)throw new Error('Invalid template! Must be a "number" or a "string"');return Promise.resolve(n.provider.getNetwork()).then(function(g){var p=g.chainId;if(A&&A!==Number(p))throw new Error("Chain ID from DDO is different than the configured network.");var w=(new se).getConfig(parseInt(String(p)));return Promise.resolve(Ne(n,w.nftFactoryAddress,i,Number(p))).then(function(i){if(i<1){if(8996!==Number(p))throw new Error("Invalid template index: "+i);i=1}var g=new Ie(n,Number(p)),b=new je(w.nftFactoryAddress,n,Number(p));return Promise.resolve(n.getAddress()).then(function(S){var C,x;function j(e){return x?e:Promise.resolve(D.wait()).then(function(e){var t;function i(e){if(t)return e;function i(){function e(){var e=g.setMetadata,a=E;return Promise.resolve(n.getAddress()).then(function(n){return Promise.resolve(e.call(g,a,n,0,u,"",r.toBeHex(i),t,o)).then(function(){return s.id})})}F[0].datatokenAddress=m,F[0].serviceEndpoint=u;var t,o,i,c=y.makeDid(E=h,A.toString());s=y.updateFields({id:c,nftAddress:E});var d=function(){if(a)return Promise.resolve(tt.encrypt(s,Number(p),u,n,null)).then(function(e){return t=e,Promise.resolve(l.validate(s,n,u)).then(function(e){o=e.hash,i=2})});var e=JSON.stringify(s),c=Buffer.from(e);t=r.hexlify(c),o="0x"+T.createHash("sha256").update(t).digest("hex"),i=0}();return d&&d.then?d.then(e):e()}var c=function(){if("oasis"!==w.sdk)return Promise.resolve(tt.encrypt(o,Number(p),u,n,null)).then(function(e){F[0].files=e});F[0].files=""}();return c&&c.then?c.then(i):i()}var c=we(e,"NFTCreated"),d=we(e,"TokenCreated"),h=c.args.newTokenAddress,m=d.args.newTokenAddress;o.datatokenAddress=m,o.nftAddress=h;var f=function(){if("oasis"===w.sdk){var e=new r.ethers.Contract(m,B.default.abi,n);return ct(function(){return Promise.resolve(e.setFilesObject(r.toUtf8Bytes(JSON.stringify(o)))).then(function(e){var t=function(){if(e.wait)return Promise.resolve(e.wait()).then(function(){})}();if(t&&t.then)return t.then(function(){})})},function(e){return console.log("Error updating files object with data token and nft addresses: ",e),t=1,null})}}();return f&&f.then?f.then(i):i(f)})}var D,M={name:e,symbol:t,templateIndex:1,tokenURI:"aaa",transferable:!0,owner:S},O={templateIndex:i,cap:"100000",feeAmount:"0",paymentCollector:S,feeToken:c||w.oceanTokenAddress,minter:S,mpFeeAddress:Se};null!=o&&o.files[0].type&&[exports.FileObjectType.ARWEAVE,exports.FileObjectType.IPFS,exports.FileObjectType.URL].includes(null==o||null==(C=o.files[0])||null==(C=C.type)?void 0:C.toLowerCase())||(console.log('Missing or invalid files object type, defaulting to "url"'),o.type=exports.FileObjectType.URL),"oasis"===w.sdk&&(O.filesObject=o,O.accessListFactory=d||w.accessListFactory,O.allowAccessList=h,O.denyAccessList=m);var N=ct(function(){var e=function(){if(!k)return Promise.resolve(b.createNftWithDatatoken(M,O)).then(function(e){D=e});var e=function(){if("0"===k.toString())return Promise.resolve(b.createNftWithDatatokenWithDispenser(M,O,{dispenserAddress:w.dispenserAddress,maxTokens:"1",maxBalance:"100000000",withMint:!0,allowedSwapper:Se})).then(function(e){D=e});var e=f||w.oceanTokenAddress;return Promise.resolve(de(P.signer,e)).then(function(t){v||(v=t);var r={fixedRateAddress:w.fixedRateExchangeAddress,baseTokenAddress:e,owner:S,marketFeeCollector:S,baseTokenDecimals:v,datatokenDecimals:18,fixedRate:k.toString(),marketFee:"0",allowedConsumer:S,withMint:!0};return Promise.resolve(b.createNftWithDatatokenWithFixedRate(M,O,r)).then(function(e){D=e})})}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})},function(e){return console.log("ERROR creating NFT bundle",e),x=1,null});return N&&N.then?N.then(j):j(N)})})})}catch(e){return Promise.reject(e)}},exports.decimals=function(e,t){try{var n=new r.ethers.Contract(t,ae,e);return Promise.resolve(n.decimals()).then(Number)}catch(e){return Promise.reject(e)}},exports.downloadFile=function(e,t){try{return Promise.resolve(fetch(e)).then(function(r){if(!r.ok)throw new Error("Response error.");var n;try{n=r.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(r){try{n=e.split("/").pop()}catch(e){n="file"+t}}return Promise.resolve(r.arrayBuffer()).then(function(e){return{data:e,filename:n}})})}catch(e){return Promise.reject(e)}},exports.downloadFileBrowser=function(e){var t=new XMLHttpRequest;t.responseType="blob",t.open("GET",e),t.onload=function(){var e=t.getResponseHeader("content-disposition"),r=null==e?void 0:e.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/),n=r&&r[1]?r[1]:"file",o=window.URL.createObjectURL(t.response),i=document.createElement("a");i.href=o,i.setAttribute("download",n),document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(o)},t.send()},exports.generateDid=function(e,t){return e=r.getAddress(e),"did:op:"+X.default(e+t.toString(10)).toString()},exports.generateDtName=Ce,exports.getErrorMessage=function(e){try{var t=JSON.parse(e),r=Object.keys(t)[0];if("error"===r){var n,o=t[r];return(null==(n=st[r])?void 0:n[o])||"Provider request failed: "+o}var i=t[r];return t[Object.keys(t)[1]]+" : "+i}catch(t){return re.error("[getErrorMessage] error: ",t),e}},exports.getEventFromTx=we,exports.getFairGasPrice=he,exports.getHash=function(e){return X.default(e).toString()},exports.getOceanArtifactsAddresses=Re,exports.getOceanArtifactsAddressesByChainId=Ue,exports.getTokenDecimals=de,exports.isDefined=function(e){return null!=e},exports.minAbi=ae,exports.orderAsset=function(e,t,r,n,o,i,s,a,u,c,l,d){void 0===u&&(u="0"),void 0===c&&(c=0),void 0===l&&(l=0),void 0===d&&(d=0);try{var h=w.DDOManager.getDDOClass(e),m=h.getAssetFields().datatokens,f=h.getDDOFields(),v=f.chainId,g=f.services;return s||(s={consumeMarketFeeAddress:"0x0000000000000000000000000000000000000000",consumeMarketFeeAmount:"0",consumeMarketFeeToken:"0x0000000000000000000000000000000000000000"}),Promise.resolve(t.provider.getNetwork()).then(function(h){if(v!==Number(h.chainId))throw new Error("Chain ID from DDO is different than the configured network.");if(!m[c].address)throw new Error("The datatoken with index: "+c+" does not exist for the asset with did: "+e.id);if(!g[l].id)throw new Error("There is no service with index: "+l+" defined for the asset with did: "+e.id);return Promise.resolve(n.getId(m[c].address)).then(function(h){return Promise.resolve(n.getFixedRates(m[c].address)).then(function(f){return Promise.resolve(n.getDispensers(m[c].address)).then(function(v){return Promise.resolve(n.getPublishingMarketFee(m[c].address)).then(function(p){function P(e){return a?e:Promise.resolve(b.call(tt,T,k,0,e,o||r.oceanNodeUri)).then(y)}function y(o){function v(o){function a(o){var i,a={consumer:o,serviceIndex:l,_providerFee:P,_consumeMarketFee:s};return function(e,t){var r,n=-1;e:{for(var o=0;o<t.length;o++){var i=t[o][0];if(i){var s=i();if(s&&s.then)break e;if(s===e){n=o;break}}else n=o}if(-1!==n){do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then){r=!0;break e}var c=t[n][2];n++}while(c&&!c());return u}}var l=new ut,d=at.bind(null,l,2);return(r?u.then(h):s.then(function r(s){for(;;){if(s===e){n=o;break}if(++o===t.length){if(-1!==n)break;return void at(l,1,u)}if(i=t[o][0]){if((s=i())&&s.then)return void s.then(r).then(void 0,d)}else n=o}do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then)return void u.then(h).then(void 0,d);var c=t[n][2];n++}while(c&&!c());at(l,1,u)})).then(void 0,d),l;function h(e){for(;;){var r=t[n][2];if(!r||r())break;n++;for(var o=t[n][1];!o;)n++,o=t[n][1];if((e=o())&&e.then)return void e.then(h).then(void 0,d)}at(l,1,e)}}(w,[[function(){return"free"},function(){var e=function(e){var t;if(i)return e;function o(e){if(t)return e}var s=function(){if(2===h||4===h)return Promise.resolve(n.buyFromDispenserAndOrder(g[l].datatokenAddress,a,r.dispenserAddress)).then(function(e){return t=1,e})}();return s&&s.then?s.then(o):o(s)},o=function(){if(1===h){var e=new Te(r.dispenserAddress,t),o=e.dispense,s=m[c].address;return Promise.resolve(t.getAddress()).then(function(t){return Promise.resolve(o.call(e,s,"1",t)).then(function(e){if(!e)throw new Error("Failed to dispense !");return Promise.resolve(e.wait()).then(function(){return Promise.resolve(n.startOrder(m[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return i=1,e})})})})}}();return o&&o.then?o.then(e):e(o)}],[function(){return"fixed"},function(){var o=new Ae(r.fixedRateExchangeAddress,t);if(!f[d].id)throw new Error("There is no fixed rate exchange with index: "+l+" for the asset with did: "+e.id);return Promise.resolve(o.getFeesInfo(f[d].id)).then(function(e){return Promise.resolve(o.getExchange(f[d].id)).then(function(i){return Promise.resolve(o.calcBaseInGivenDatatokensOut(e.exchangeId,"1",s.consumeMarketFeeAmount)).then(function(l){var d;function f(e){var o;if(d)return e;function s(e){if(o)return e}var u=function(){if(2===h||4===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(it(t,r,e,i.baseToken,m[c].address,v,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to confirm/mine approval transaction!");return Promise.resolve(n.buyFromFreAndOrder(m[c].address,a,g)).then(function(e){return o=1,e})}if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return u&&u.then?u.then(s):s(u)}var v=new O.default(+l.baseTokenAmount||0).add(new O.default(s.consumeMarketFeeAmount||0)).add(new O.default(+p.publishMarketFeeAmount||0)).toString(),g={exchangeContract:r.fixedRateExchangeAddress,exchangeId:e.exchangeId,maxBaseTokenAmount:v,baseTokenAddress:i.baseToken,baseTokenDecimals:parseInt(i.btDecimals)||18,swapMarketFee:u,marketFeeAddress:p.publishMarketFeeAddress},P=function(){if(1===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(it(t,r,e,i.baseToken,r.fixedRateExchangeAddress,v,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return Promise.resolve(o.buyDatatokens(i.exchangeId,"1",v,p.publishMarketFeeAddress,u)).then(function(e){return Promise.resolve(e.wait()).then(function(e){if(!e)throw new Error("Failed to buy datatoken from fixed rate!");return Promise.resolve(n.startOrder(m[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return d=1,e})})})}return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return P&&P.then?P.then(f):f(P)})})})}],[void 0,function(){throw new Error("Pricing schema not supported !")}]])}return i?a(i):Promise.resolve(t.getAddress()).then(a)}var P=a||o.providerFee,y=function(){if(P&&P.providerFeeAddress!==Se&&P.providerFeeAmount&&parseInt(P.providerFeeAmount)>0)return function(e,n){try{var o=Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(ot(t,r,e,P.providerFeeToken,g[0].datatokenAddress,P.providerFeeAmount)).then(function(){})})}catch(e){return n()}return o&&o.then?o.then(void 0,n):o}(0,function(){throw new Error("Failed to approve provider fee token "+P.providerFeeToken)})}();return y&&y.then?y.then(v):v()}var w=f.length>0?"fixed":v.length>0?"free":"NOT_ALLOWED",b=a||tt.initialize,k=a||g[l].id,T=a||e.id;return a?P(y(a)):Promise.resolve(t.getAddress()).then(P)})})})})})}catch(e){return Promise.reject(e)}},exports.sendTx=ue,exports.setContractDefaults=ye,exports.signHash=function(e,t){try{var n=r.getBytes(t);return Promise.resolve(e._legacySignMessage(n)).then(function(e){var t="0x"+(e=e.substr(2)).slice(0,64),r="0x"+e.slice(64,128),n="0x"+e.slice(128,130);return"0x00"===n&&(n="0x1b"),"0x01"===n&&(n="0x1c"),{v:n,r:t,s:r}})}catch(e){return Promise.reject(e)}},exports.signRequest=Ve,exports.sleep=He,exports.transfer=function(e,t,n,o,i,s,a){try{var u=new r.ethers.Contract(n,ae,e);return Promise.resolve(ce(e,n,i,s)).then(function(r){return Promise.resolve(u.transfer.estimateGas(o,r)).then(function(n){return a?n:Promise.resolve(ue(n,e,null==t?void 0:t.gasFeeMultiplier,u.transfer,o,r))})})}catch(e){return Promise.reject(e)}},exports.unitsToAmount=le,exports.useOasisSDK=function(e){var t=(new se).getConfig(e);return t&&"oasis"===t.sdk};
1
+ var e=require("@oceanprotocol/contracts/addresses/address.json"),t=require("fs"),r=require("ethers"),n=require("@oasisprotocol/sapphire-paratime"),o=require("bignumber.js"),i=require("decimal.js"),s=require("@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json"),a=require("@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json"),u=require("@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json"),c=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json"),l=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json"),d=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json"),h=require("@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json"),m=require("@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json"),f=require("@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json"),v=require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json"),g=require("@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json"),p=require("@oceanprotocol/contracts/artifacts/contracts/escrow/Escrow.sol/Escrow.json"),P=require("@oceanprotocol/contracts/artifacts/contracts/communityFee/EnterpriseFeeCollector.sol/EnterpriseFeeCollector.json"),y=require("cross-fetch"),w=require("@oceanprotocol/ddo-js"),b=require("jsonwebtoken"),k=require("crypto-js/sha256.js"),T=require("crypto");function S(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function A(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var E,F,C,x=/*#__PURE__*/S(e),j=/*#__PURE__*/S(t),D=/*#__PURE__*/A(n),M=/*#__PURE__*/S(o),O=/*#__PURE__*/S(i),N=/*#__PURE__*/S(s),R=/*#__PURE__*/S(a),U=/*#__PURE__*/S(u),I=/*#__PURE__*/S(c),L=/*#__PURE__*/S(l),G=/*#__PURE__*/S(d),_=/*#__PURE__*/S(h),q=/*#__PURE__*/S(m),B=/*#__PURE__*/S(f),z=/*#__PURE__*/S(v),J=/*#__PURE__*/S(g),W=/*#__PURE__*/S(p),H=/*#__PURE__*/S(P),V=/*#__PURE__*/S(y),Z=/*#__PURE__*/S(b),X=/*#__PURE__*/S(k);function K(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function $(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return K(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?K(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Y.apply(null,arguments)}function Q(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,ee(e,t)}function ee(e,t){return ee=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ee(e,t)}exports.FileObjectType=void 0,(E=exports.FileObjectType||(exports.FileObjectType={})).URL="url",E.IPFS="ipfs",E.ARWEAVE="arweave",exports.EncryptMethod=void 0,(F=exports.EncryptMethod||(exports.EncryptMethod={})).AES="AES",F.ECIES="ECIES",exports.LogLevel=void 0,(C=exports.LogLevel||(exports.LogLevel={}))[C.None=-1]="None",C[C.Error=0]="Error",C[C.Warn=1]="Warn",C[C.Log=2]="Log",C[C.Verbose=3]="Verbose";var te=/*#__PURE__*/function(){function e(e){this.logLevel=void 0,this.logLevel=e,this.logLevel=e||exports.LogLevel.Error}var t=e.prototype;return t.setLevel=function(e){this.logLevel=e},t.bypass=function(){this.dispatch.apply(this,["log",-Infinity].concat([].slice.call(arguments)))},t.debug=function(){this.dispatch.apply(this,["debug",exports.LogLevel.Verbose].concat([].slice.call(arguments)))},t.log=function(){this.dispatch.apply(this,["log",exports.LogLevel.Log].concat([].slice.call(arguments)))},t.warn=function(){this.dispatch.apply(this,["warn",exports.LogLevel.Warn].concat([].slice.call(arguments)))},t.error=function(){this.dispatch.apply(this,["error",exports.LogLevel.Error].concat([].slice.call(arguments)))},t.dispatch=function(e,t){var r;this.logLevel>=t&&(r=console)[e].apply(r,[].slice.call(arguments,2))},e}(),re=new te,ne={chainId:null,network:"unknown",nodeUri:"http://127.0.0.1:8545",oceanNodeUri:"http://127.0.0.1:8001",explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},oe=[Y({},ne),Y({},ne,{chainId:8996,network:"development",oceanNodeUri:"http://127.0.0.1:8001",sdk:"evm"}),Y({},ne,{chainId:11155111,network:"sepolia",nodeUri:"https://sepolia.infura.io/v3",explorerUri:"https://sepolia.etherscan.io",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:8453,network:"base",nodeUri:"https://mainnet.base.org",explorerUri:"https://etherscan.io",startBlock:30562198,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",gasFeeMultiplier:1.6,sdk:"evm"}),Y({},ne,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com",sdk:"evm"}),Y({},ne,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05,sdk:"evm"}),Y({},ne,{chainId:100,network:"gen-x-testnet",nodeUri:"https://rpc.genx.minimal-gaia-x.eu",explorerUri:"https://explorer.genx.minimal-gaia-x.eu/",gasFeeMultiplier:1,sdk:"evm"}),Y({},ne,{chainId:10,network:"optimism",nodeUri:"https://mainnet.optimism.io",explorerUri:"https://optimistic.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:11155420,network:"optimism_sepolia",nodeUri:"https://sepolia.optimism.io",explorerUri:"https://sepolia-optimism.etherscan.io/",gasFeeMultiplier:1.1,sdk:"evm"}),Y({},ne,{chainId:23294,network:"oasis_sapphire",nodeUri:"https://sapphire.oasis.io",explorerUri:"https://explorer.oasis.io/mainnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),Y({},ne,{chainId:23295,network:"oasis_sapphire_testnet",nodeUri:"https://testnet.sapphire.oasis.dev",explorerUri:"https://explorer.oasis.io/testnet/sapphire/",gasFeeMultiplier:1,sdk:"oasis"}),Y({},ne,{chainId:32456,network:"pontus-x-devnet",nodeUri:"https://rpc.dev.pontus-x.eu",explorerUri:"https://explorer.dev.pontus-x.eu/testnet/pontusx",sdk:"evm"})],ie=[23294,23295],se=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getAddressesFromEnv=function(e,t){var r,n=function(){return process.env.NODE_URL?{oceanNodeUri:process.env.NODE_URL}:{}};if(t&&t[e]){var o=t[e];r=Y({nftFactoryAddress:o.ERC721Factory,opfCommunityFeeCollector:o.OPFCommunityFeeCollector,fixedRateExchangeAddress:o.FixedPrice,dispenserAddress:o.Dispenser,oceanTokenAddress:o.Ocean,routerFactoryAddress:o.Router,chainId:o.chainId,startBlock:o.startBlock,accessListFactory:o.AccessListFactory,escrow:o.Escrow,EnterpriseFeeCollector:o.EnterpriseFeeCollector},n())}else if(x.default[e]){var i=x.default[e];r=Y({nftFactoryAddress:i.ERC721Factory,opfCommunityFeeCollector:i.OPFCommunityFeeCollector,fixedRateExchangeAddress:i.FixedPrice,dispenserAddress:i.Dispenser,oceanTokenAddress:i.Ocean,routerFactoryAddress:i.Router,chainId:i.chainId,startBlock:i.startBlock,accessListFactory:i.AccessListFactory,escrow:i.Escrow,EnterpriseFeeCollector:i.EnterpriseFeeCollector},n())}return r},t.getConfig=function(e,t){var r,n="string"==typeof e?"network":"chainId",o=oe.find(function(t){return t[n]===e});if(!o)return re.error("No config found for given network '"+e+"'"),null;try{r=process.env.ADDRESS_FILE?JSON.parse(j.default.readFileSync(process.env.ADDRESS_FILE,"utf8")):null}catch(e){console.log(e),r=null}var i=this.getAddressesFromEnv(o.network,r);return!i&&ie.includes(o.chainId)&&(i=this.getAddressesFromEnv(o.network.replace("sapph","saph"),r)),"sdk"in o&&null!==o.sdk||(o.sdk=ie.includes(o.chainId)?"oasis":"evm"),i&&"accessListFactory"in i&&(o.accessListFactory=i.accessListFactory),o=Y({},o,i),Y({},o,{nodeUri:t?o.nodeUri+"/"+t:o.nodeUri})},e}(),ae=[{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"}],ue=function(e,t,r,n){try{var o=arguments;return Promise.resolve(t.provider.getNetwork()).then(function(i){var s=i.chainId;return Promise.resolve(t.provider.getFeeData()).then(function(t){var i={};if(t.maxPriorityFeePerGas){var a=t.maxPriorityFeePerGas.toString(),u=t.maxFeePerGas.toString();r>1&&(a=Math.round(Number(t.maxPriorityFeePerGas)*r).toString(),u=Math.round(Number(t.maxFeePerGas)*r).toString()),i={maxPriorityFeePerGas:(Number(s)===pe||Number(s)===ge)&&Number(a)<me?me:Number(s)===Pe&&Number(a)<fe?fe:ie.includes(Number(s))&&Number(a)<ve?ve:Number(a),maxFeePerGas:(Number(s)===pe||Number(s)===ge)&&Number(u)<me?me:Number(s)===Pe&&Number(u)<fe?fe:ie.includes(Number(s))&&Number(u)<ve?ve:Number(u)}}else i={gasPrice:t.gasPrice};return i.gasLimit=BigInt(new M.default(e).plus(20000n).toString()),function(e,t){try{var r=Promise.resolve(n.apply(void 0,[].slice.call(o,4).concat([i]))).then(function(e){return Promise.resolve(e.wait()).then(function(){return e})})}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(0,function(e){return re.error("Send tx error: ",e),null})})})}catch(e){return Promise.reject(e)}},ce=function(e,t,n,o){try{var i=function(e){return"0"===e&&(e=18),r.parseUnits(n,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(de(e,t)).then(i))}catch(e){return Promise.reject(e)}},le=function(e,t,n,o){try{var i=function(e){return"0"===e&&(e=18),r.formatUnits(n,e).toString()};return Promise.resolve(o?i(o):Promise.resolve(de(e,t)).then(i))}catch(e){return Promise.reject(e)}},de=function(e,t){try{var n=new r.ethers.Contract(t,ae,e);return Promise.resolve(n.decimals())}catch(e){return Promise.reject(e)}},he=function(e,t){try{return Promise.resolve(e.provider.getFeeData()).then(function(e){var r=BigInt(e.gasPrice.toString());return t?(r*BigInt(t)).toString(10):r.toString()})}catch(e){return Promise.reject(e)}},me=3e10,fe=4e9,ve=1e10,ge=137,pe=80001,Pe=11155111;function ye(e,t){return e}function we(e,t){if(e&&e.logs)return e.logs.filter(function(e){return e instanceof r.EventLog&&e.eventName===t})[0]}var be=/*#__PURE__*/function(){function e(e,t,r,n){this.signer=void 0,this.config=void 0,this.abi=void 0,this.signer=e,this.config=r||(new se).getConfig(t),this.abi=n||this.getDefaultAbi()}var t=e.prototype;return t.getSignerAccordingSdk=function(){return this.config&&"sdk"in this.config&&"oasis"===this.config.sdk?D.wrap(this.signer):this.signer},t.amountToUnits=function(e,t,r){try{return Promise.resolve(ce(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.unitsToAmount=function(e,t,r){try{return Promise.resolve(le(this.signer,e,t,r))}catch(e){return Promise.reject(e)}},t.getFairGasPrice=function(){try{var e;return Promise.resolve(he(this.signer,null==(e=this.config)?void 0:e.gasFeeMultiplier))}catch(e){return Promise.reject(e)}},t.getContract=function(e,t){if(!e)throw new Error("Contract address is required but not provided");return ye(new r.ethers.Contract(e,new r.ethers.Interface(JSON.stringify(t||this.abi)),this.signer))},e}(),ke=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,r,n,o,i)||this).address=void 0,s.contract=void 0,s.address=t,s.contract=s.getContract(s.address),s}return Q(t,e),t}(be),Te=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return N.default.abi},r.status=function(e){try{var t=this;return Promise.resolve(t.contract.status(e)).then(function(e){if(!e)throw new Error("Np dispenser found for the given datatoken address");var r=e.isMinter,n=e.owner,o=e.active;return Promise.resolve(t.unitsToAmount(null,e.maxTokens,18)).then(function(i){return Promise.resolve(t.unitsToAmount(null,e.maxBalance,18)).then(function(s){return Promise.resolve(t.unitsToAmount(null,e.balance,18)).then(function(t){return{active:o,owner:n,isMinter:r,maxTokens:i,maxBalance:s,balance:t,allowedSwapper:e.allowedSwapper}})})})})}catch(e){return Promise.reject(e)}},r.create=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.contract.create.estimateGas(e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o)).then(function(a){var u;return i?a:Promise.resolve(ue(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.create,e,s.amountToUnits(null,r,18),s.amountToUnits(null,n,18),t,o))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.contract.activate.estimateGas(e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18))).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.activate,e,o.amountToUnits(null,t,18),o.amountToUnits(null,r,18)))})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.contract.deactivate.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.deactivate,e))})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.dispense=function(e,t,r,n){void 0===t&&(t="1");try{var o=this;return Promise.resolve(o.contract.dispense.estimateGas(e,o.amountToUnits(null,t,18),r)).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.dispense,e,o.amountToUnits(null,t,18),r))})}catch(e){return Promise.reject(e)}},r.ownerWithdraw=function(e,t){try{var r=this;return Promise.resolve(r.contract.ownerWithdraw.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.ownerWithdraw,e))})}catch(e){return Promise.reject(e)}},r.isDispensable=function(e,t,r,n){void 0===n&&(n="1");try{return Promise.resolve(this.status(e)).then(function(o){return!!o&&!1!==o.active&&Promise.resolve(t.balance(e,r)).then(function(e){return!(new O.default(e).greaterThanOrEqualTo(o.maxBalance)||new O.default(String(n)).greaterThan(o.maxTokens)||!new O.default(o.balance).greaterThanOrEqualTo(n)&&!0!==o.isMinter)})})}catch(e){return Promise.reject(e)}},t}(ke),Se="0x0000000000000000000000000000000000000000",Ae=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return R.default.abi},r.generateExchangeId=function(e,t){try{return Promise.resolve(this.contract.generateExchangeId(e,t))}catch(e){return Promise.reject(e)}},r.buyDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=Se),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.buyDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(ue(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.buyDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.sellDatatokens=function(e,t,r,n,o,i){void 0===n&&(n=Se),void 0===o&&(o="0");try{var s=this;return Promise.resolve(s.getExchange(e)).then(function(a){return Promise.resolve(s.amountToUnits(null,o,18)).then(function(o){return Promise.resolve(s.amountToUnits(a.datatoken,t,Number(a.dtDecimals))).then(function(t){return Promise.resolve(s.amountToUnits(a.baseToken,r,Number(a.btDecimals))).then(function(r){return Promise.resolve(s.contract.sellDT.estimateGas(e,t,r,n,o)).then(function(a){var u;return i?a:Promise.resolve(ue(a,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,s.contract.sellDT,e,t,r,n,o))})})})})})}catch(e){return Promise.reject(e)}},r.getNumberOfExchanges=function(){try{return Promise.resolve(this.contract.getNumberOfExchanges()).then(Number)}catch(e){return Promise.reject(e)}},r.setRate=function(e,t,r){try{var n=this,o=n.contract.setRate,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.setRate,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(ue(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.setAllowedSwapper=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.setAllowedSwapper.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.setAllowedSwapper,e,t))})}catch(e){return Promise.reject(e)}},r.activate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.deactivate=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.active?null:Promise.resolve(r.contract.toggleExchangeState.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleExchangeState,e))}):null})}catch(e){return Promise.reject(e)}},r.getRate=function(e){try{var t=this;return Promise.resolve(t.contract.getRate(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.getDatatokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getDTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.datatoken,r,Number(e.dtDecimals)))})})}catch(e){return Promise.reject(e)}},r.getBasetokenSupply=function(e){try{var t=this;return Promise.resolve(t.contract.getBTSupply(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(e){return Promise.resolve(t.unitsToAmount(e.baseToken,r,Number(e.btDecimals)))})})}catch(e){return Promise.reject(e)}},r.getAllowedSwapper=function(e){try{return Promise.resolve(this.contract.getAllowedSwapper(e))}catch(e){return Promise.reject(e)}},r.calcBaseInGivenDatatokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseInGivenOutDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e.baseTokenAmount,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.unitsToAmount(o.baseToken,e.publishMarketFeeAmount,Number(o.btDecimals))).then(function(r){return Promise.resolve(n.unitsToAmount(o.baseToken,e.oceanFeeAmount,Number(o.btDecimals))).then(function(i){return Promise.resolve(n.unitsToAmount(o.baseToken,e.consumeMarketFeeAmount,Number(o.btDecimals))).then(function(e){return{baseTokenAmount:t,marketFeeAmount:r,oceanFeeAmount:i,consumeMarketFeeAmount:e}})})})})})})})})}catch(e){return Promise.reject(e)}},r.getAmountBasetokensOut=function(e,t,r){void 0===r&&(r="0");try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){var i=n.contract,s=i.calcBaseOutGivenInDT;return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.amountToUnits(null,r,18)).then(function(r){return Promise.resolve(s.call(i,e,t,r)).then(function(e){return Promise.resolve(n.unitsToAmount(o.baseToken,e[0],Number(o.btDecimals)))})})})})}catch(e){return Promise.reject(e)}},r.getExchange=function(e){try{var t=this;return Promise.resolve(t.contract.getExchange(e)).then(function(r){var n=r.btDecimals.toString(),o=r.dtDecimals.toString(),i=r.allowedSwapper,s=r.exchangeOwner,a=r.withMint,u=r.baseToken,c=r.datatoken,l=r.active;return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtBalance,Number(r.dtDecimals))).then(function(d){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btBalance,Number(r.btDecimals))).then(function(h){return Promise.resolve(t.unitsToAmount(r.datatoken,r.dtSupply,Number(r.dtDecimals))).then(function(m){return Promise.resolve(t.unitsToAmount(r.baseToken,r.btSupply,Number(r.btDecimals))).then(function(f){return Promise.resolve(t.unitsToAmount(null,r.fixedRate,18)).then(function(t){return{active:l,datatoken:c,baseToken:u,withMint:a,exchangeOwner:s,allowedSwapper:i,dtDecimals:o,btDecimals:n,dtBalance:d,btBalance:h,dtSupply:m,btSupply:f,fixedRate:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getFeesInfo=function(e){try{var t=this;return Promise.resolve(t.contract.getFeesInfo(e)).then(function(r){return Promise.resolve(t.getExchange(e)).then(function(n){return Promise.resolve(t.unitsToAmount(null,r.opcFee.toString(),18)).then(function(o){return Promise.resolve(t.unitsToAmount(null,r.marketFee.toString(),18)).then(function(i){var s=r.marketFeeCollector;return Promise.resolve(t.unitsToAmount(n.baseToken,r.marketFeeAvailable,Number(n.btDecimals))).then(function(a){return Promise.resolve(t.unitsToAmount(n.baseToken,r.oceanFeeAvailable,Number(n.btDecimals))).then(function(t){return{opcFee:o,marketFee:i,marketFeeCollector:s,marketFeeAvailable:a,oceanFeeAvailable:t,exchangeId:e}})})})})})})}catch(e){return Promise.reject(e)}},r.getExchanges=function(){try{return Promise.resolve(this.contract.getExchanges())}catch(e){return Promise.reject(e)}},r.isActive=function(e){try{return Promise.resolve(this.contract.isActive(e))}catch(e){return Promise.reject(e)}},r.activateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!0===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!0)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!0))}):null})}catch(e){return Promise.reject(e)}},r.deactivateMint=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?!1===n.withMint?null:Promise.resolve(r.contract.toggleMintState.estimateGas(e,!1)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.toggleMintState,e,!1))}):null})}catch(e){return Promise.reject(e)}},r.collectBasetokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.baseToken,t,Number(o.btDecimals))).then(function(t){return Promise.resolve(n.contract.collectBT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectBT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectDatatokens=function(e,t,r){try{var n=this;return Promise.resolve(n.getExchange(e)).then(function(o){return o?Promise.resolve(n.contract.getExchange(e)).then(function(o){return Promise.resolve(n.amountToUnits(o.datatoken,t,Number(o.dtDecimals))).then(function(t){return Promise.resolve(n.contract.collectDT.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.collectDT,e,t))})})}):null})}catch(e){return Promise.reject(e)}},r.collectMarketFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectMarketFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectMarketFee,e))}):null})}catch(e){return Promise.reject(e)}},r.collectOceanFee=function(e,t){try{var r=this;return Promise.resolve(r.getExchange(e)).then(function(n){return n?Promise.resolve(r.contract.collectOceanFee.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.collectOceanFee,e))}):null})}catch(e){return Promise.reject(e)}},r.getOPCCollector=function(){try{return Promise.resolve(this.contract.opcCollector())}catch(e){return Promise.reject(e)}},r.getRouter=function(){try{return Promise.resolve(this.contract.router())}catch(e){return Promise.reject(e)}},r.getExchangeOwner=function(e){try{return Promise.resolve(this.getExchange(e)).then(function(e){return e.exchangeOwner})}catch(e){return Promise.reject(e)}},r.updateMarketFee=function(e,t,r){try{var n=this,o=n.contract.updateMarketFee,i=o.estimateGas;return Promise.resolve(n.amountToUnits(null,t,18)).then(function(s){return Promise.resolve(i.call(o,e,s)).then(function(o){var i;if(r)return o;var s=n.contract.updateMarketFee,a=null==(i=n.config)?void 0:i.gasFeeMultiplier,u=n.getSignerAccordingSdk();return Promise.resolve(n.amountToUnits(null,t,18)).then(function(t){return Promise.resolve(ue(o,u,a,s,e,t))})})})}catch(e){return Promise.reject(e)}},r.updateMarketFeeCollector=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.updateMarketFeeCollector.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.updateMarketFeeCollector,e,t))})}catch(e){return Promise.reject(e)}},t}(ke),Ee=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return U.default.abi},r.buyDatatokenBatch=function(e,t){try{var r=this;return Promise.resolve(r.contract.buyDTBatch.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.buyDTBatch,e))})}catch(e){return Promise.reject(e)}},r.isApprovedToken=function(e){try{return Promise.resolve(this.contract.isApprovedToken(e))}catch(e){return Promise.reject(e)}},r.isFixedPrice=function(e){try{return Promise.resolve(this.contract.isFixedRateContract(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.routerOwner())}catch(e){return Promise.reject(e)}},r.getNFTFactory=function(){try{return Promise.resolve(this.contract.factory())}catch(e){return Promise.reject(e)}},r.addApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.removeApprovedToken=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeApprovedToken.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeApprovedToken,t))})})}catch(e){return Promise.reject(e)}},r.addFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.removeFixedRateContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeFixedRateContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeFixedRateContract,t))})})}catch(e){return Promise.reject(e)}},r.addDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.addDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.removeDispenserContract=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(n.contract.removeDispenserContract.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.removeDispenserContract,t))})})}catch(e){return Promise.reject(e)}},r.getOPCFee=function(e){try{return Promise.resolve(this.contract.getOPCFee(e)).then(Number)}catch(e){return Promise.reject(e)}},r.getCurrentOPCFee=function(){try{return Promise.resolve(this.contract.swapOceanFee()).then(Number)}catch(e){return Promise.reject(e)}},r.updateOPCFee=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getOwner()).then(function(a){if(a!==e)throw new Error("Caller is not Router Owner");return Promise.resolve(s.contract.updateOPCFee.estimateGas(t,r,n,o)).then(function(e){var a;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(a=s.config)?void 0:a.gasFeeMultiplier,s.contract.updateOPCFee,t,r,n,o))})})}catch(e){return Promise.reject(e)}},t}(ke),Fe={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 Ce(e){var t=e||Fe,r=Math.floor(Math.random()*t.adjectives.length),n=Math.floor(Math.random()*t.nouns.length),o=Math.floor(100*Math.random()),i=t.adjectives[r].replace(/^\w/,function(e){return e.toUpperCase()}),s=t.nouns[n].replace(/^\w/,function(e){return e.toUpperCase()});return{name:i+" "+s+" Token",symbol:(i.substring(0,3)+s.substring(0,3)).toUpperCase()+"-"+o}}function xe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var je=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return _.default.abi},n.createNFT=function(e,t){try{var r=this;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){var n=Ce(),o=n.symbol;e.name=n.name,e.symbol=o}var i=e.templateIndex;return Promise.resolve(r.getCurrentNFTTemplateCount()).then(function(n){if(i>n)throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");return Promise.resolve(r.getNFTTemplate(e.templateIndex)).then(function(n){if(!1===n.isActive)throw new Error("Template is not active");return Promise.resolve(r.contract.deployERC721Contract.estimateGas(e.name,e.symbol,e.templateIndex,Se,Se,e.tokenURI,e.transferable,e.owner)).then(function(n){return t?n:xe(function(){var t;return Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(t=r.config)?void 0:t.gasFeeMultiplier,r.contract.deployERC721Contract,e.name,e.symbol,e.templateIndex,Se,Se,e.tokenURI,e.transferable,e.owner)).then(function(e){if(!e){var t="Tx for deploying new NFT contract does not exist or status is not successful.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return we(e,"NFTCreated").args[0]})})},function(e){console.error("Creation of NFT failed: "+e)})})})})}catch(e){return Promise.reject(e)}},n.getCurrentNFTCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getCurrentTokenCount=function(){try{return Promise.resolve(this.contract.getCurrentTokenCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},n.getCurrentNFTTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentNFTTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getCurrentTokenTemplateCount=function(){try{return Promise.resolve(this.contract.getCurrentTemplateCount()).then(Number)}catch(e){return Promise.reject(e)}},n.getNFTTemplate=function(e){try{var t=this;return Promise.resolve(t.getCurrentNFTTemplateCount()).then(function(r){if(e>r)throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");return Promise.resolve(t.contract.getNFTTemplate(e))})}catch(e){return Promise.reject(e)}},n.getTokenTemplate=function(e){try{return Promise.resolve(this.contract.getTokenTemplate(e))}catch(e){return Promise.reject(e)}},n.checkDatatoken=function(e){try{return Promise.resolve(this.contract.erc20List(e))}catch(e){return Promise.reject(e)}},n.checkNFT=function(e){try{return Promise.resolve(this.contract.erc721List(e))}catch(e){return Promise.reject(e)}},n.addNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Se)throw new Error("Template cannot be ZERO address");return Promise.resolve(n.contract.add721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.add721TokenTemplate,t))})})}catch(e){return Promise.reject(e)}},n.disableNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.disable721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disable721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},n.reactivateNFTTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentNFTTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.contract.reactivate721TokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivate721TokenTemplate,t))})})})}catch(e){return Promise.reject(e)}},n.addTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Se)throw new Error("Template cannot be address ZERO");return Promise.resolve(n.contract.addTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.addTokenTemplate,t))})})}catch(e){return Promise.reject(e)}},n.disableTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!1===e.isActive)throw new Error("Template is already disabled");return Promise.resolve(n.contract.disableTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.disableTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},n.reactivateTokenTemplate=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");return Promise.resolve(n.getCurrentTokenTemplateCount()).then(function(e){if(t>e)throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return Promise.resolve(n.getTokenTemplate(t)).then(function(e){if(!0===e.isActive)throw new Error("Template is already active");return Promise.resolve(n.contract.reactivateTokenTemplate.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.reactivateTokenTemplate,t))})})})})}catch(e){return Promise.reject(e)}},n.startMultipleTokenOrder=function(e,t){try{var r=this;if(e.length>50)throw new Error("Too many orders");return Promise.resolve(r.contract.startMultipleTokenOrder.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.startMultipleTokenOrder,e))})}catch(e){return Promise.reject(e)}},n.createNftWithDatatoken=function(e,t,r){try{var n=this;return Promise.resolve(n.getErcCreationParams(t)).then(function(t){return Promise.resolve(n.contract.createNftWithErc20.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.createNftWithErc20,e,t))})})}catch(e){return Promise.reject(e)}},n.createNftWithDatatokenWithFixedRate=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.getFreCreationParams(r)).then(function(r){return Promise.resolve(o.contract.createNftWithErc20WithFixedRate.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithFixedRate,e,t,r))})})})}catch(e){return Promise.reject(e)}},n.createNftWithDatatokenWithDispenser=function(e,t,r,n){try{var o=this;return Promise.resolve(o.getErcCreationParams(t)).then(function(t){return Promise.resolve(o.amountToUnits(null,r.maxBalance,18)).then(function(i){return r.maxBalance=i,Promise.resolve(o.amountToUnits(null,r.maxTokens,18)).then(function(i){return r.maxTokens=i,Promise.resolve(o.contract.createNftWithErc20WithDispenser.estimateGas(e,t,r)).then(function(i){var s;return n?i:Promise.resolve(ue(i,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,o.contract.createNftWithErc20WithDispenser,e,t,r))})})})})}catch(e){return Promise.reject(e)}},n.getErcCreationParams=function(e){try{var t,n,o=function(){var o=[e.minter,e.paymentCollector,e.mpFeeAddress,e.feeToken];e.filesObject&&(e.accessListFactory&&o.push(e.accessListFactory),e.allowAccessList&&o.push(e.allowAccessList),e.denyAccessList&&o.push(e.denyAccessList));var s=[e.name||t,e.symbol||n],u=e.templateIndex;return Promise.resolve(i.amountToUnits(null,e.cap,18)).then(function(t){return Promise.resolve(i.amountToUnits(null,e.feeAmount,a)).then(function(n){return{templateIndex:u,strings:s,addresses:o,uints:[t,n],bytess:e.filesObject?[r.toUtf8Bytes(JSON.stringify(e.filesObject))]:[]}})})},i=this;if(!e.name||!e.symbol){var s=Ce();t=s.name,n=s.symbol}var a=18,u=function(){if(e.feeToken!==Se){var t=xe(function(){return Promise.resolve(de(i.signer,e.feeToken)).then(function(e){a=e})},function(e){re.error("getTokenDecimals error",e)});if(t&&t.then)return t.then(function(){})}}();return Promise.resolve(u&&u.then?u.then(o):o())}catch(e){return Promise.reject(e)}},n.getFreCreationParams=function(e){try{var t=this;e.allowedConsumer||(e.allowedConsumer=Se);var r=!1===e.withMint?0:1,n=[e.baseTokenAddress,e.owner,e.marketFeeCollector,e.allowedConsumer],o=e.fixedRateAddress,i=e.datatokenDecimals,s=e.baseTokenDecimals;return Promise.resolve(t.amountToUnits(null,e.fixedRate,e.datatokenDecimals)).then(function(a){return Promise.resolve(t.amountToUnits(null,e.marketFee,e.datatokenDecimals)).then(function(e){return{fixedPriceAddress:o,addresses:n,uints:[s,i,a,e,r]}})})}catch(e){return Promise.reject(e)}},t}(ke);function De(e,t,r){if(!e.s){if(r instanceof Me){if(!r.s)return void(r.o=De.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(De.bind(null,e,t),De.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var Me=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{De(n,1,i(this.v))}catch(e){De(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?De(n,1,t?t(o):o):r?De(n,1,r(o)):De(n,2,o)}catch(e){De(n,2,e)}},n},e}();function Oe(e){return e instanceof Me&&1&e.s}var Ne=function(e,t,n,o){try{var i="number"==typeof n,s=new je(t,e,o);return Promise.resolve(s.getCurrentTokenTemplateCount()).then(function(t){var o;function a(e){return o?e:-1}var u=1,c=function(e,t,r){for(var n;;){var o=e();if(Oe(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Oe(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Oe(s)){n=2;break}}}var a=new Me,u=De.bind(null,a,2);return(0===n?o.then(l):1===n?i.then(c):s.then(d)).then(void 0,u),a;function c(n){i=n;do{if(t&&(s=t())&&s.then&&!Oe(s))return void s.then(d).then(void 0,u);if(!(o=e())||Oe(o)&&!o.v)return void De(a,1,i);if(o.then)return void o.then(l).then(void 0,u);Oe(i=r())&&(i=i.v)}while(!i||!i.then);i.then(c).then(void 0,u)}function l(e){e?(i=r())&&i.then?i.then(c).then(void 0,u):c(i):De(a,1,i)}function d(){(o=e())?o.then?o.then(l).then(void 0,u):l(o):De(a,1,i)}}(function(){return!o&&u<=t},function(){return u++},function(){return Promise.resolve(s.getTokenTemplate(u)).then(function(t){var s=new r.ethers.Contract(t.templateAddress,q.default.abi,e);return i?Promise.resolve(s.getId()).then(function(e){if(t.isActive&&e.toString()===n.toString())return o=1,u}):t.isActive&&t.templateAddress===n.toString()?(o=1,u):void 0})});return c&&c.then?c.then(a):a(c)})}catch(e){return Promise.reject(e)}};function Re(){try{if(process.env.ADDRESS_FILE){var e=j.default.readFileSync(process.env.ADDRESS_FILE,"utf8");return JSON.parse(e)}return x.default}catch(e){return x.default}}function Ue(e){try{var t=Re();if(t)for(var r=Object.keys(t),n=0,o=r;n<o.length;n++){var i=o[n];if(t[i].chainId===e)return t[i]}}catch(e){console.error(e)}return null}var Ie=/*#__PURE__*/function(e){function t(){return e.apply(this,arguments)||this}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return G.default.abi},n.createDatatoken=function(e,t,n,o,i,s,a,u,c,l,d,h,m,f,v,g){try{var p=this;return Promise.resolve(p.getNftPermissions(e,t)).then(function(t){if(!0!==t.deployERC20)throw new Error("Caller is not DatatokenDeployer");if(d||(d=1),!c||!l){var P=Ce();c=P.name,l=P.symbol}var y=p.getContract(e);if(!p.signer.provider)throw new Error("Provider is required but not available");return Promise.resolve(p.signer.provider.getNetwork()).then(function(e){var t=e.chainId;function P(){var e=y.createERC20,t=e.estimateGas,P=[c,l],w=d;return Promise.resolve(p.amountToUnits(null,u,18)).then(function(b){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(k){return Promise.resolve(t.call(e,w,P,[n,o,i,s],[b,k],[])).then(function(e){var t;if(g)return e;var P=[n,o,i,s];m&&(P.push(m.toLowerCase()),P.push(f?f.toLowerCase():Se),P.push(v||Se));var w=[c,l],b=d,k=y.createERC20,T=null==(t=p.config)?void 0:t.gasFeeMultiplier,S=p.getSignerAccordingSdk();return Promise.resolve(p.amountToUnits(null,u,18)).then(function(t){return Promise.resolve(p.amountToUnits(null,a,18)).then(function(n){return Promise.resolve(ue(e,S,T,k,b,w,P,[t,n],h?[r.toUtf8Bytes(h)]:[])).then(function(e){return Promise.resolve(e.wait()).then(function(e){var t=we(e,"TokenCreated");return null==t?void 0:t.args[0]})})})})})})})}var w=Ue(Number(t)),b=function(){if(h)return Promise.resolve(Ne(p.signer,w.ERC721Factory,4,Number(t))).then(function(e){d=e})}();return b&&b.then?b.then(P):P()})})}catch(e){return Promise.reject(e)}},n.addManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.addManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addManager,r))})})}catch(e){return Promise.reject(e)}},n.removeManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(i.removeManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeManager,r))})})}catch(e){return Promise.reject(e)}},n.addDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToCreateERC20List,r))})})}catch(e){return Promise.reject(e)}},n.removeDatatokenDeployer=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t===r&&!0!==e.deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");return Promise.resolve(i.removeFromCreateERC20List.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromCreateERC20List,r))})}var u=!0!==s.manager;return u||t!==r?a(u||t===r&&o.getNftPermissions(e,t)):Promise.resolve(u||t===r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},n.addMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addToMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addToMetadataList,r))})})}catch(e){return Promise.reject(e)}},n.removeMetadataUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");return Promise.resolve(i.removeFromMetadataList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFromMetadataList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},n.addStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!0!==e.manager)throw new Error("Caller is not Manager");return Promise.resolve(i.addTo725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addTo725StoreList,r))})})}catch(e){return Promise.reject(e)}},n.removeStoreUpdater=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(s){function a(e){if(u||t!==r&&!0!==e.store)throw new Error("Caller is not Manager nor storeUpdater");return Promise.resolve(i.removeFrom725StoreList.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeFrom725StoreList,r))})}var u=!0!==s.manager;return u||t===r?a(u||t!==r&&o.getNftPermissions(e,t)):Promise.resolve(u||t!==r&&o.getNftPermissions(e,t)).then(a)})}catch(e){return Promise.reject(e)}},n.cleanPermissions=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(n.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");return Promise.resolve(o.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.cleanPermissions))})})}catch(e){return Promise.reject(e)}},n.transferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.transferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.transferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},n.safeTransferNft=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getNftOwner(e)).then(function(e){if(e!==t)throw new Error("Caller is not NFT Owner");var a=n||1;return Promise.resolve(s.safeTransferFrom.estimateGas(t,r,a)).then(function(e){var n;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(n=i.config)?void 0:n.gasFeeMultiplier,s.safeTransferFrom,t,r,a))})})}catch(e){return Promise.reject(e)}},n.setMetadata=function(e,t,r,n,o,i,s,a,u,c){try{var l=this,d=l.getContract(e);return u||(u=[]),Promise.resolve(l.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");return Promise.resolve(d.setMetaData.estimateGas(r,n,o,i,s,a,u)).then(function(e){var t;return c?e:Promise.resolve(ue(e,l.signer,null==(t=l.config)?void 0:t.gasFeeMultiplier,d.setMetaData,r,n,o,i,s,a,u))})})}catch(e){return Promise.reject(e)}},n.setMetadataAndTokenURI=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");var t=Y({},r,{metadataProofs:r.metadataProofs||[]});return Promise.resolve(i.setMetaDataAndTokenURI.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.signer,null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setMetaDataAndTokenURI,t))})})}catch(e){return Promise.reject(e)}},n.setMetadataState=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getNftPermissions(e,t)).then(function(e){if(!e.updateMetadata)throw new Error("Caller is not Metadata updater");return Promise.resolve(i.setMetaDataState.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setMetaDataState,r))})})}catch(e){return Promise.reject(e)}},n.setTokenURI=function(e,t,r){try{var n=this,o=n.getContract(e);return Promise.resolve(o.setTokenURI.estimateGas("1",t)).then(function(e){var i;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,o.setTokenURI,"1",t))})}catch(e){return Promise.reject(e)}},n.getNftOwner=function(e){try{var t=this.getContract(e);return Promise.resolve(t.ownerOf(1))}catch(e){return Promise.reject(e)}},n.getNftPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.getPermissions(t))}catch(e){return Promise.reject(e)}},n.getMetadata=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getMetaData())}catch(e){return Promise.reject(e)}},n.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},n.setData=function(e,t,n,o,i){try{var s=this;return Promise.resolve(s.getNftPermissions(e,t)).then(function(t){if(!0!==t.store)throw new Error("User is not ERC20 store updater");var a=s.getContract(e),u=r.keccak256(n),c=r.hexlify(r.toUtf8Bytes(o));return Promise.resolve(a.setNewData.estimateGas(u,c)).then(function(e){var t;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(t=s.config)?void 0:t.gasFeeMultiplier,a.setNewData,u,c))})})}catch(e){return Promise.reject(e)}},n.getData=function(e,t){try{var n=this.getContract(e),o=r.keccak256(t);return Promise.resolve(n.getData(o)).then(function(e){return e?r.toUtf8String(e):null})}catch(e){return Promise.reject(e)}},n.getTokenURI=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.tokenURI(t))}catch(e){return Promise.reject(e)}},n.isDatatokenDeployed=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isDeployed(t))}catch(e){return Promise.reject(e)}},t}(be),Le=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o)||this).abiEnterprise=void 0,s.nft=void 0,s.abiEnterprise=i||L.default.abi,s.nft=new Ie(s.signer,r),s}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return I.default.abi},n.approve=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.approve.estimateGas(t,ce(null,null,r,18))).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.approve,t,ce(null,null,r,18)))})}catch(e){return Promise.reject(e)}},n.createFixedRate=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!e)throw new Error("User is not Datatoken Deployer");r.allowedConsumer||(r.allowedConsumer=Se);var t=!1===r.withMint?0:1;return Promise.resolve(i.createFixedRate.estimateGas(r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t])).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.createFixedRate,r.fixedRateAddress,[r.baseTokenAddress,r.owner,r.marketFeeCollector,r.allowedConsumer],[r.baseTokenDecimals,r.datatokenDecimals,r.fixedRate,r.marketFee,t]))})})}catch(e){return Promise.reject(e)}},n.createDispenser=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e);return n.allowedSwapper||(n.allowedSwapper=Se),n.withMint=!1!==n.withMint,Promise.resolve(s.createDispenser.estimateGas(r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper)).then(function(e){var t;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.createDispenser,r,n.maxTokens,n.maxBalance,n.withMint,n.allowedSwapper))})})}catch(e){return Promise.reject(e)}},n.mint=function(e,t,r,n,o){try{var i=this,s=i.getContract(e);return Promise.resolve(i.getPermissions(e,t)).then(function(a){if(!0!==a.minter)throw new Error("Caller is not Minter");return Promise.resolve(i.getCap(e)).then(function(e){if(new O.default(e).gte(r))return Promise.resolve(s.mint.estimateGas(n||t,ce(null,null,r,18))).then(function(e){var a;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,s.mint,n||t,ce(null,null,r,18)))});throw new Error("Mint amount exceeds cap available")})})}catch(e){return Promise.reject(e)}},n.addMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addMinter,r))})})}catch(e){return Promise.reject(e)}},n.removeMinter=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removeMinter.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removeMinter,r))})})}catch(e){return Promise.reject(e)}},n.addPaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.addPaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.addPaymentManager,r))})})}catch(e){return Promise.reject(e)}},n.removePaymentManager=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.isDatatokenDeployer(e,t)).then(function(e){if(!0!==e)throw new Error("Caller is not DatatokenDeployer");return Promise.resolve(i.removePaymentManager.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.removePaymentManager,r))})})}catch(e){return Promise.reject(e)}},n.setPaymentCollector=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(o.getPermissions(e,t)).then(function(s){function a(e){function s(s){function a(e){if(!u&&!c&&!(null==e?void 0:e.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");return Promise.resolve(i.setPaymentCollector.estimateGas(r)).then(function(e){var t;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(t=o.config)?void 0:t.gasFeeMultiplier,i.setPaymentCollector,r))})}var c=e&&s===t;return e&&!c?Promise.resolve(e&&!c&&o.nft.getNftPermissions(e,t)).then(a):a(e&&!c&&o.nft.getNftPermissions(e,t))}return e?Promise.resolve(o.nft.getNftOwner(e)).then(s):s(e)}var u=s.paymentManager;return u?a(!u&&o.getNFTAddress(e)):Promise.resolve(!u&&o.getNFTAddress(e)).then(a)})}catch(e){return Promise.reject(e)}},n.getPaymentCollector=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPaymentCollector())}catch(e){return Promise.reject(e)}},n.transfer=function(e,t,r,n){try{var o=this,i=o.transferWei;return Promise.resolve(ce(null,null,r,18)).then(function(r){return i.call(o,e,t,r,n)})}catch(e){return Promise.reject(e)}},n.transferWei=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.transfer.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.transfer,t,r))})}catch(e){return Promise.reject(e)}},n.startOrder=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e,s.abi);return o||(o={consumeMarketFeeAddress:Se,consumeMarketFeeToken:Se,consumeMarketFeeAmount:"0"}),Promise.resolve(a.startOrder.estimateGas(t,r,n,o)).then(function(e){var u;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(u=s.config)?void 0:u.gasFeeMultiplier,a.startOrder,t,r,n,o))})}catch(e){return Promise.reject(e)}},n.reuseOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e);return Promise.resolve(i.reuseOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.reuseOrder,t,r))})}catch(e){return Promise.reject(e)}},n.buyFromFreAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(o.getFreOrderParams(r)).then(function(e){return Promise.resolve(i.buyFromFreAndOrder.estimateGas(t,e)).then(function(r){var s;return n?r:Promise.resolve(ue(r,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromFreAndOrder,t,e))})})}catch(e){return Promise.reject(e)}},n.buyFromDispenserAndOrder=function(e,t,r,n){try{var o=this,i=o.getContract(e,o.abiEnterprise);return Promise.resolve(i.buyFromDispenserAndOrder.estimateGas(t,r)).then(function(e){var s;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(s=o.config)?void 0:s.gasFeeMultiplier,i.buyFromDispenserAndOrder,t,r))})}catch(e){return Promise.reject(e)}},n.setData=function(e,t,n,o){try{var i=this;return Promise.resolve(i.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var s=i.getContract(e),a=r.hexlify(r.toUtf8Bytes(n));return Promise.resolve(s.setData.estimateGas(a)).then(function(e){var t;return o?e:Promise.resolve(ue(e,i.getSignerAccordingSdk(),null==(t=i.config)?void 0:t.gasFeeMultiplier,s.setData,a))})})}catch(e){return Promise.reject(e)}},n.cleanPermissions=function(e,t,r){try{var n=this,o=n.nft,i=o.getNftOwner;return Promise.resolve(n.getNFTAddress(e)).then(function(s){return Promise.resolve(i.call(o,s)).then(function(o){if(o!==t)throw new Error("Caller is NOT Nft Owner");var i=n.getContract(e);return Promise.resolve(i.cleanPermissions.estimateGas()).then(function(e){var t;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,i.cleanPermissions))})})})}catch(e){return Promise.reject(e)}},n.getPermissions=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.permissions(t))}catch(e){return Promise.reject(e)}},n.getCap=function(e){try{var t=this,r=t.getContract(e);return Promise.resolve(r.cap()).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},n.getDecimals=function(e){try{var t=this.getContract(e);return Promise.resolve(t.decimals()).then(Number)}catch(e){return Promise.reject(e)}},n.getId=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getId()).then(Number)}catch(e){return Promise.reject(e)}},n.getSymbol=function(e){try{var t=this.getContract(e);return Promise.resolve(t.symbol())}catch(e){return Promise.reject(e)}},n.getName=function(e){try{var t=this.getContract(e);return Promise.resolve(t.name())}catch(e){return Promise.reject(e)}},n.getNFTAddress=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getERC721Address())}catch(e){return Promise.reject(e)}},n.getFixedRates=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getFixedRates())}catch(e){return Promise.reject(e)}},n.getDispensers=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getDispensers())}catch(e){return Promise.reject(e)}},n.isDatatokenDeployer=function(e,t){try{var r=this.getContract(e);return Promise.resolve(r.isERC20Deployer(t))}catch(e){return Promise.reject(e)}},n.balance=function(e,t){try{var r=this,n=r.getContract(e);return Promise.resolve(n.balanceOf(t)).then(function(e){return Promise.resolve(r.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},n.allowance=function(e,t,r,n){void 0===n&&(n=18);try{var o=this,i=o.getContract(e);return Promise.resolve(i.allowance(t,r)).then(function(e){return Promise.resolve(o.unitsToAmount(null,e,n))})}catch(e){return Promise.reject(e)}},n.setPublishingMarketFee=function(e,t,r,n,o,i){try{var s=this,a=s.getContract(e);return Promise.resolve(a.getPublishingMarketFee()).then(function(e){if(e[0]!==o)throw new Error("Caller is not the Publishing Market Fee Address");return Promise.resolve(a.setPublishingMarketFee.estimateGas(t,r,n)).then(function(e){var o;return i?e:Promise.resolve(ue(e,s.getSignerAccordingSdk(),null==(o=s.config)?void 0:o.gasFeeMultiplier,a.setPublishingMarketFee,t,r,n))})})}catch(e){return Promise.reject(e)}},n.getPublishingMarketFee=function(e){try{var t=this.getContract(e);return Promise.resolve(t.getPublishingMarketFee()).then(function(e){return{publishMarketFeeAddress:e[0],publishMarketFeeToken:e[1],publishMarketFeeAmount:e[2].toString()}})}catch(e){return Promise.reject(e)}},n.getFreOrderParams=function(e){try{var t=this,r=e.exchangeId,n=e.exchangeContract;return Promise.resolve(ce(t.signer,e.baseTokenAddress,e.maxBaseTokenAmount,e.baseTokenDecimals)).then(function(o){return Promise.resolve(ce(t.signer,e.baseTokenAddress,e.swapMarketFee,e.baseTokenDecimals)).then(function(t){return{exchangeContract:n,exchangeId:r,maxBaseTokenAmount:o,swapMarketFee:t,marketFeeAddress:e.marketFeeAddress}})})}catch(e){return Promise.reject(e)}},t}(be),Ge=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,n,o,i)||this).accessList=void 0,s.fileObject=void 0,s.abi=s.getDefaultAbi(),s.fileObject=r,s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return B.default.abi},r.setFileObj=function(e){this.fileObject=e},r.getAllowlistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getAllowListContract())}catch(e){return Promise.reject(e)}},r.getDenylistContract=function(e){try{var t=this.getContract(e,this.getDefaultAbi());return Promise.resolve(t.getDenyListContract())}catch(e){return Promise.reject(e)}},r.setAllowListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setAllowListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setAllowListContract,t))})})}catch(e){return Promise.reject(e)}},r.setDenyListContract=function(e,t,r,n){try{var o=this;return Promise.resolve(o.isDatatokenDeployer(e,r)).then(function(r){if(!r)throw new Error("User is not Datatoken Deployer");var i=o.getContract(e);return Promise.resolve(i.setDenyListContract.estimateGas(t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,i.setDenyListContract,t))})})}catch(e){return Promise.reject(e)}},r.setFileObject=function(e,t,r){try{var n=this;return Promise.resolve(n.isDatatokenDeployer(e,t)).then(function(t){if(!t)throw new Error("User is not Datatoken Deployer");var o=n.getContract(e);return Promise.resolve(o.setFilesObject.estimateGas(n.fileObject)).then(function(e){var t;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(t=n.config)?void 0:t.gasFeeMultiplier,o.setFilesObject,n.fileObject))})})}catch(e){return Promise.reject(e)}},r.getFileObject=function(e,t,r,n,o,i,s){try{var a=this.getContract(e,this.getDefaultAbi());return Promise.resolve(a.getFileObject(t,r,n,o,i,s))}catch(e){return Promise.reject(e)}},t}(Le),_e=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return z.default.abi},r.getTokenUri=function(e){try{return Promise.resolve(this.contract.tokenURI(e))}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.getId=function(){try{return Promise.resolve(this.contract.getId()).then(Number)}catch(e){return Promise.reject(e)}},r.getName=function(){try{return Promise.resolve(this.contract.name())}catch(e){return Promise.reject(e)}},r.getSymbol=function(){try{return Promise.resolve(this.contract.symbol())}catch(e){return Promise.reject(e)}},r.balance=function(e){try{var t=this;return Promise.resolve(t.contract.balanceOf(e)).then(function(e){return Promise.resolve(t.unitsToAmount(null,e,18))})}catch(e){return Promise.reject(e)}},r.mint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.mint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.mint,e,t))})}catch(e){return Promise.reject(e)}},r.batchMint=function(e,t,r){try{var n=this;return Promise.resolve(n.contract.batchMint.estimateGas(e,t)).then(function(o){var i;return r?o:Promise.resolve(ue(o,n.getSignerAccordingSdk(),null==(i=n.config)?void 0:i.gasFeeMultiplier,n.contract.batchMint,e,t))})}catch(e){return Promise.reject(e)}},r.burn=function(e,t){try{var r=this;return Promise.resolve(r.contract.burn.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.burn,e))})}catch(e){return Promise.reject(e)}},r.transferOwnership=function(e,t){try{var r=this;return Promise.resolve(r.contract.transferOwnership.estimateGas(e)).then(function(n){var o;return t?n:Promise.resolve(ue(n,r.getSignerAccordingSdk(),null==(o=r.config)?void 0:o.gasFeeMultiplier,r.contract.transferOwnership,e))})}catch(e){return Promise.reject(e)}},r.renounceOwnership=function(e){try{var t=this;return Promise.resolve(t.contract.renounceOwnership.estimateGas()).then(function(r){var n;return e?r:Promise.resolve(ue(r,t.getSignerAccordingSdk(),null==(n=t.config)?void 0:n.gasFeeMultiplier,t.contract.renounceOwnership))})}catch(e){return Promise.reject(e)}},t}(ke),qe=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return J.default.abi},r.deployAccessListContract=function(e,t,r,n,o,i,s){void 0===n&&(n=!1);try{var a=this;if(!e||!t){var u=Ce();e=u.name,t=u.symbol}return Promise.resolve(a.contract.deployAccessListContract.estimateGas(e,t,n,o,i,r)).then(function(u){return s?u:function(s,c){try{var l=Promise.resolve(ue(u,a.getSignerAccordingSdk(),null==(d=a.config)?void 0:d.gasFeeMultiplier,a.contract.deployAccessListContract,e,t,n,o,i,r)).then(function(e){if(!e){var t="Tx for deploying new access list was not processed on chain.";throw console.error(t),t}return Promise.resolve(e.wait()).then(function(e){return we(e,"NewAccessList").args[0]})})}catch(e){return c(e)}var d;return l&&l.then?l.then(void 0,c):l}(0,function(e){console.error("Creation of AccessList failed: "+e)})})}catch(e){return Promise.reject(e)}},r.getOwner=function(){try{return Promise.resolve(this.contract.owner())}catch(e){return Promise.reject(e)}},r.isSoulbound=function(e){try{return Promise.resolve(this.contract.isSoulBound(e))}catch(e){return Promise.reject(e)}},r.isDeployed=function(e){try{return Promise.resolve(this.contract.isDeployed(e))}catch(e){return Promise.reject(e)}},r.changeTemplateAddress=function(e,t,r){try{var n=this;return Promise.resolve(n.getOwner()).then(function(o){if(o!==e)throw new Error("Caller is not Factory Owner");if(t===Se)throw new Error("Template address cannot be ZERO address");return Promise.resolve(n.contract.changeTemplateAddress.estimateGas(t)).then(function(e){var o;return r?e:Promise.resolve(ue(e,n.getSignerAccordingSdk(),null==(o=n.config)?void 0:o.gasFeeMultiplier,n.contract.changeTemplateAddress,t))})})}catch(e){return Promise.reject(e)}},t}(ke);function Be(e,t,r){if(!e.s){if(r instanceof ze){if(!r.s)return void(r.o=Be.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Be.bind(null,e,t),Be.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}var ze=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Be(n,1,i(this.v))}catch(e){Be(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Be(n,1,t?t(o):o):r?Be(n,1,r(o)):Be(n,2,o)}catch(e){Be(n,2,e)}},n},e}(),Je=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abiEnterprise=void 0,s.abi=i||s.getDefaultAbi(),s}Q(t,e);var n=t.prototype;return n.getDefaultAbi=function(){return W.default.abi},n.getFunds=function(e){try{return Promise.resolve(this.contract.getFunds(e))}catch(e){return Promise.reject(e)}},n.getUserFunds=function(e,t){try{return Promise.resolve(this.contract.getUserFunds(e,t))}catch(e){return Promise.reject(e)}},n.getUserTokens=function(e){try{return Promise.resolve(this.contract.getUserTokens(e))}catch(e){return Promise.reject(e)}},n.getLocks=function(e,t,r){try{return Promise.resolve(this.contract.getLocks(e,t,r))}catch(e){return Promise.reject(e)}},n.getAuthorizations=function(e,t,r){try{return Promise.resolve(this.contract.getAuthorizations(e,t,r))}catch(e){return Promise.reject(e)}},n.verifyFundsForEscrowPayment=function(e,t,n,o,i,s,a){try{var u,c=this;return Promise.resolve(null==(u=c.signer.provider)?void 0:u.getBalance(r.getAddress(t))).then(function(u){if(new M.default(u).isZero())return{isValid:!1,message:"Native token balance is 0. Please add funds"};var l=new Le(c.signer),d=l.allowance;return Promise.resolve(c.signer.getAddress()).then(function(u){return Promise.resolve(d.call(l,e,u,c.contract.target.toString(),a)).then(function(u){return Promise.resolve(c.amountToUnits(e,u,18)).then(function(u){function d(){var u=l.balance;return Promise.resolve(c.signer.getAddress()).then(function(d){return Promise.resolve(u.call(l,e,d)).then(function(u){if(new M.default(u).isZero())return{isValid:!1,message:"Payment token balance is 0. Please add funds"};var l=c.getAuthorizations;return Promise.resolve(c.signer.getAddress()).then(function(d){return Promise.resolve(l.call(c,e,d,t)).then(function(l){var d=c.getUserFunds;return Promise.resolve(c.signer.getAddress()).then(function(h){return Promise.resolve(d.call(c,h,e)).then(function(d){function h(){var n=function(){if(0===l.length)return Promise.resolve(c.authorize(r.getAddress(e),r.getAddress(t),(Number(o)/2).toString(),i,s)).then(function(){})}();return n&&n.then?n.then(function(){return{isValid:!0,message:""}}):{isValid:!0,message:""}}var m=function(){if(new M.default(d[0]).isZero()){var t=function(){if(n&&new M.default(r.parseEther(u)).isLessThanOrEqualTo(new M.default(r.parseEther(n)))&&new M.default(r.parseEther(n)).isGreaterThan(new M.default(o)))return Promise.resolve(c.deposit(e,n,a)).then(function(){});var t=function(){if(new M.default(r.parseEther(u)).isLessThanOrEqualTo(new M.default(r.parseEther(o)))){var t=c.deposit;return Promise.resolve(c.unitsToAmount(e,o,a)).then(function(r){return Promise.resolve(t.call(c,e,r,a)).then(function(){})})}return Promise.resolve(c.deposit(e,u,a)).then(function(){})}();return t&&t.then?t.then(function(){}):void 0}();if(t&&t.then)return t.then(function(){})}}();return m&&m.then?m.then(h):h()})})})})})})}var h=function(){if(new M.default(u).isLessThan(new M.default(o)))return Promise.resolve(l.approve(r.getAddress(e),r.getAddress(c.contract.target.toString()),o)).then(function(){})}();return h&&h.then?h.then(d):d()})})})})}catch(e){return Promise.reject(e)}},n.deposit=function(e,t,r,n){try{var o=this;return Promise.resolve(o.amountToUnits(e,t,r)).then(function(t){return Promise.resolve(o.contract.deposit.estimateGas(e,t)).then(function(r){var i;return n?r:Promise.resolve(ue(r,o.getSignerAccordingSdk(),null==(i=o.config)?void 0:i.gasFeeMultiplier,o.contract.deposit,e,t))})})}catch(e){return Promise.reject(e)}},n.withdraw=function(e,t,r,n){try{var o=this,i=[],s=[];if(e.length!==t.length)throw new Error("Tokens and amounts arrays must have the same length");return Promise.resolve(o.signer.getAddress()).then(function(a){function u(){return Promise.resolve(Promise.all(s.map(function(e,t){return o.amountToUnits(i[t],e,r)}))).then(function(t){return Promise.resolve(o.contract.withdraw.estimateGas(e,t)).then(function(e){var r;return n?e:Promise.resolve(ue(e,o.getSignerAccordingSdk(),null==(r=o.config)?void 0:r.gasFeeMultiplier,o.contract.withdraw,i,t))})})}var c,l,d,h,m,f=(c=e,l=function(r){var n=e[r],u=new M.default(t[r]);return Promise.resolve(o.getUserFunds(a,n)).then(function(e){var o=new M.default(e[0]);u.isGreaterThan(0)&&u.isLessThanOrEqualTo(o)?(i.push(n),s.push(t[r])):console.log("Insufficient funds for token "+n)})},m=-1,function e(t){try{for(;++m<c.length;)if((t=l(m))&&t.then){if(!((r=t)instanceof ze&&1&r.s))return void t.then(e,h||(h=Be.bind(null,d=new ze,2)));t=t.v}d?Be(d,1,t):d=t}catch(e){Be(d||(d=new ze),2,e)}var r}(),d);return f&&f.then?f.then(u):u()})}catch(e){return Promise.reject(e)}},n.authorize=function(e,t,r,n,o,i,s){try{var a=this,u=a.getAuthorizations;return Promise.resolve(a.signer.getAddress()).then(function(c){return Promise.resolve(u.call(a,e,c,t)).then(function(u){return 0!==u.length?(console.log("Payee "+t+" already authorized"),null):Promise.resolve(a.amountToUnits(e,r,i)).then(function(r){return Promise.resolve(a.amountToUnits(e,n,i)).then(function(n){return Promise.resolve(a.amountToUnits(e,o,i)).then(function(o){return Promise.resolve(a.contract.authorize.estimateGas(e,t,r,n,o)).then(function(i){var u;return s?i:Promise.resolve(ue(i,a.getSignerAccordingSdk(),null==(u=a.config)?void 0:u.gasFeeMultiplier,a.contract.authorize,e,t,r,n,o))})})})})})})}catch(e){return Promise.reject(e)}},n.cancelExpiredLocks=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.contract.cancelExpiredLocks.estimateGas(e,t,r,n)).then(function(s){var a;return o?s:Promise.resolve(ue(s,i.getSignerAccordingSdk(),null==(a=i.config)?void 0:a.gasFeeMultiplier,i.contract.cancelExpiredLocks,e,t,r,n))})}catch(e){return Promise.reject(e)}},t}(ke),We=/*#__PURE__*/function(e){function t(t,r,n,o,i){var s;return(s=e.call(this,t,r,n,o,i)||this).abi=i||s.getDefaultAbi(),s}Q(t,e);var r=t.prototype;return r.getDefaultAbi=function(){return H.default.abi},r.isTokenAllowed=function(e){try{return Promise.resolve(this.contract.isTokenAllowed(e))}catch(e){return Promise.reject(e)}},r.getToken=function(e){try{return Promise.resolve(this.contract.getToken(e))}catch(e){return Promise.reject(e)}},r.calculateFee=function(e,t,r){try{var n=this,o=n.amountToUnits(e,t.toString(),r);return Promise.resolve(n.contract.calculateFee(e,o)).then(function(t){return n.unitsToAmount(e,t,r)})}catch(e){return Promise.reject(e)}},t}(ke),He=function(e){try{return Promise.resolve(new Promise(function(t){setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},Ve=function(e,t){try{var n=r.keccak256(r.toUtf8Bytes(t)),o=r.getBytes(n);if(!e.provider)throw new Error("Provider is required but not available");return Promise.resolve(e.provider.getNetwork()).then(function(t){var r=t.chainId;return function(t,r){try{var n=Promise.resolve(e.signMessage(o))}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(t){return re.error("Sign message error: ",t),function(){if(8996===Number(r))return console.log("Signing message with _legacySignMessage"),Promise.resolve(e._legacySignMessage(o))}()})})}catch(e){return Promise.reject(e)}};function Ze(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}function Xe(e,t,r){if(!e.s){if(r instanceof Ke){if(!r.s)return void(r.o=Xe.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Xe.bind(null,e,t),Xe.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var Ke=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{Xe(n,1,i(this.v))}catch(e){Xe(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?Xe(n,1,t?t(o):o):r?Xe(n,1,r(o)):Xe(n,2,o)}catch(e){Xe(n,2,e)}},n},e}();function $e(e){return e instanceof Ke&&1&e.s}var Ye=/*#__PURE__*/function(){function e(e){this.aquariusURL=void 0,this.aquariusURL=e}var t=e.prototype;return t.resolve=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/ddo/"+e;return Promise.resolve(Ze(function(){return Promise.resolve(V.default(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return Promise.resolve(e.json());throw new Error("HTTP request failed with status "+e.status)})},function(e){throw re.error(e),new Error("HTTP request failed")}))}catch(e){return Promise.reject(e)}},t.waitForIndexer=function(e,t,r,n,o,i){void 0===n&&(n=3e4),void 0===o&&(o=100);try{var s,a=this,u=0;o>500&&(re.warn("Max Limit exceeded, defaulting to 500 retries."),o=500);var c=function(e,t){var r;do{var n=e();if(n&&n.then){if(!$e(n)){r=!0;break}n=n.v}var o=t();if($e(o)&&(o=o.v),!o)return n}while(!o.then);var i=new Ke,s=Xe.bind(null,i,2);return(r?n.then(a):o.then(u)).then(void 0,s),i;function a(r){for(n=r;$e(o=t())&&(o=o.v),o;){if(o.then)return void o.then(u).then(void 0,s);if((n=e())&&n.then){if(!$e(n))return void n.then(a).then(void 0,s);n=n.v}}Xe(i,1,n)}function u(r){if(r){do{if((n=e())&&n.then){if(!$e(n))return void n.then(a).then(void 0,s);n=n.v}if($e(r=t())&&(r=r.v),!r)return void Xe(i,1,n)}while(!r.then);r.then(u).then(void 0,s)}else Xe(i,1,n)}}(function(){function o(e){return s?e:Promise.resolve(He(n)).then(function(){u++})}var c=Ze(function(){return Promise.resolve(V.default(a.aquariusURL+"/api/aquarius/assets/ddo/"+e,{method:"GET",headers:{"Content-Type":"application/json",Authorization:i},signal:r})).then(function(e){return function(){if(e.ok)return Promise.resolve(e.json()).then(function(e){var r=w.DDOManager.getDDOClass(e).getAssetFields().indexedMetadata;return t?r.event&&r.event.txid===t?(s=1,e):void 0:(s=1,e)})}()})},function(){});return c&&c.then?c.then(o):o(c)},function(){return!s&&u<o});return Promise.resolve(c&&c.then?c.then(function(e){return s?e:null}):s?c:null)}catch(e){return Promise.reject(e)}},t.validate=function(e,t,r,n,o){try{var i=r+"/api/aquarius/assets/ddo/validate",s=r+"/api/services/nonce";return Promise.resolve(Ze(function(){return Promise.resolve(t.getAddress()).then(function(r){return Promise.resolve(V.default(s+"?userAddress="+r,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o},signal:n})).then(function(s){return Promise.resolve(s.json()).then(function(s){var a=s.nonce;console.log("[getNonce] Consumer: "+r+" nonce: "+a),a&&null!==a||(a="0");var u=(Number(a)+1).toString();return Promise.resolve(Ve(t,r+u)).then(function(t){return Promise.resolve(V.default(i,{method:"POST",body:JSON.stringify({ddo:e,publisherAddress:r,nonce:u,signature:t}),headers:{"Content-Type":"application/octet-stream",Authorization:o},signal:n})).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw new Error("Metadata validation failed");return console.log("Ddo successfully validated"),{valid:!0,hash:t.hash,proof:{validatorAddress:t.publicKey,r:t.r[0],s:t.s[0],v:t.v}}})})})})})})},function(e){re.error("Metadata validation failed",e.message)}))}catch(e){return Promise.reject(e)}},t.getAssetMetadata=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/metadata/"+e;return Promise.resolve(Ze(function(){return Promise.resolve(V.default(n,{method:"GET",headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("getAssetMetadata failed: "+e.status+e.statusText)})},function(e){throw re.error("Error getting metadata: ",e),new Error("Error getting metadata: "+e)}))}catch(e){return Promise.reject(e)}},t.querySearch=function(e,t,r){try{var n=this.aquariusURL+"/api/aquarius/assets/query";return Promise.resolve(Ze(function(){return Promise.resolve(V.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json",Authorization:r},signal:t})).then(function(e){if(e.ok)return e.json();throw new Error("querySearch failed: "+e.status+e.statusText)})},function(e){throw re.error("Error querying metadata: ",e),new Error("Error querying metadata: "+e)}))}catch(e){return Promise.reject(e)}},e}();function Qe(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}var et=/*#__PURE__*/function(){function e(){}var t=e.prototype;return t.getConsumerAddress=function(e){try{return Promise.resolve("string"==typeof e?function(e){try{return Z.default.decode(e,{json:!0})}catch(e){throw new Error("Error decoding JWT")}}(e).address:e.getAddress())}catch(e){return Promise.reject(e)}},t.getSignature=function(e,t){try{return Promise.resolve("string"==typeof e?null:this.signProviderRequest(e,t))}catch(e){return Promise.reject(e)}},t.getAuthorization=function(e){return"string"==typeof e?e:void 0},t.getEndpoints=function(e,t){try{var r=this;return Promise.resolve(Qe(function(){return Promise.resolve(r.getData(e,t)).then(function(e){return Promise.resolve(e.json())})},function(e){throw re.error("Finding the service endpoints failed:",e),new Error("HTTP request failed calling Provider")}))}catch(e){return Promise.reject(e)}},t.getEndpointURL=function(e,t){return e?e.find(function(e){return e.serviceName.toLowerCase()===t.toLowerCase()}):null},t.getServiceEndpoints=function(e,t){try{var r=[];for(var n in t.serviceEndpoints){var o={serviceName:n,method:t.serviceEndpoints[n][0],urlPath:e.replace(/\/+$/,"")+"/"+t.serviceEndpoints[n][1].replace(/^\/+/,"")};r.push(o)}return Promise.resolve(r)}catch(e){return Promise.reject(e)}},t.getNonce=function(e,t,r,n,o){try{var i=function(){function i(){var e=s.getEndpointURL(o,"nonce")?s.getEndpointURL(o,"nonce").urlPath:null;return e?Qe(function(){return Promise.resolve(V.default(e+"?userAddress="+t,{method:"GET",headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return Promise.resolve(e.json()).then(function(e){var r=e.nonce;return console.log("[getNonce] Consumer: "+t+" nonce: "+r),r&&null!==r?Number(r):0})})},function(e){throw re.error(e),new Error(e.message)}):null}var a=function(){if(!o)return Promise.resolve(s.getServiceEndpoints(e,n)).then(function(e){o=e})}();return a&&a.then?a.then(i):i()},s=this,a=function(){if(!n)return Promise.resolve(s.getEndpoints(e)).then(function(e){n=e})}();return Promise.resolve(a&&a.then?a.then(i):i())}catch(e){return Promise.reject(e)}},t.signProviderRequest=function(e,t){try{var n=r.ethers.solidityPackedKeccak256(["bytes"],[r.ethers.hexlify(r.ethers.toUtf8Bytes(t))]),o=r.ethers.toBeArray(n);return Promise.resolve(Qe(function(){return Promise.resolve(e.signMessage(o))},function(){return Promise.resolve(e.provider.getNetwork()).then(function(t){var r=Number(t.chainId);return function(){if(8996===r)return Promise.resolve(e._legacySignMessage(o))}()})}))}catch(e){return Promise.reject(e)}},t.encrypt=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getEndpoints(r)).then(function(o){return Promise.resolve(s.getServiceEndpoints(r,o)).then(function(a){return Promise.resolve(s.getConsumerAddress(n)).then(function(u){return Promise.resolve(s.getNonce(r,u,i,o,a)).then(function(r){var o=(r+1).toString(),c=String(o);return Promise.resolve(s.getSignature(n,c)).then(function(r){var n=(s.getEndpointURL(a,"encrypt")?s.getEndpointURL(a,"encrypt").urlPath:null)+"?chainId="+t;return n?(n+="&nonce="+o,n+="&consumerAddress="+u,n+="&signature="+r,Qe(function(){return Promise.resolve(V.default(n,{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/octet-stream"},signal:i})).then(function(e){return Promise.resolve(e.text())})},function(e){throw re.error(e),new Error("HTTP request failed calling Provider")})):null})})})})})}catch(e){return Promise.reject(e)}},t.checkDidFiles=function(e,t,r,n,o){void 0===n&&(n=!1);try{var i=this;return Promise.resolve(i.getEndpoints(r)).then(function(s){return Promise.resolve(i.getServiceEndpoints(r,s)).then(function(r){function s(e){var t;function r(e){return t?e:Promise.resolve(a.json()).then(function(e){throw re.error("File info call failed: ",a.status,a.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=a)&&e.ok)return Promise.resolve(a.json()).then(function(e){for(var r,n=$(e);!(r=n()).done;)c.push(r.value);return t=1,c})}();return n&&n.then?n.then(r):r(n)}var a,u={did:e,serviceId:t,checksum:n},c=[],l=i.getEndpointURL(r,"fileinfo")?i.getEndpointURL(r,"fileinfo").urlPath:null;if(!l)return null;var d=Qe(function(){return Promise.resolve(V.default(l,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:o})).then(function(e){a=e})},function(e){throw re.error("File info call failed: "),re.error(e),new Error(e)});return d&&d.then?d.then(s):s()})})}catch(e){return Promise.reject(e)}},t.getFileInfo=function(e,t,r,n){void 0===r&&(r=!1);try{var o=this;return Promise.resolve(o.getEndpoints(t)).then(function(i){return Promise.resolve(o.getServiceEndpoints(t,i)).then(function(t){function i(e){var t;function r(e){return t?e:Promise.resolve(s.json()).then(function(e){throw re.error("File info call failed: ",s.status,s.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=s)&&e.ok)return Promise.resolve(s.json()).then(function(e){for(var r,n=$(e);!(r=n()).done;)u.push(r.value);return t=1,u})}();return n&&n.then?n.then(r):r(n)}var s,a=Y({},e,{checksum:r}),u=[],c=o.getEndpointURL(t,"fileinfo")?o.getEndpointURL(t,"fileinfo").urlPath:null;if(!c)return null;var l=Qe(function(){return Promise.resolve(V.default(c,{method:"POST",body:JSON.stringify(a),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){s=e})},function(e){throw re.error("File info call failed: "),re.error(e),new Error(e)});return l&&l.then?l.then(i):i()})})}catch(e){return Promise.reject(e)}},t.getComputeEnvironments=function(e,t){try{var r=this;return Promise.resolve(r.getEndpoints(e)).then(function(n){return Promise.resolve(r.getServiceEndpoints(e,n)).then(function(e){var n;function o(e){var t;return null!=(t=i)&&t.ok?i.json():Promise.resolve(i.json()).then(function(e){throw re.error("Fetch compute env failed: ",i.status,i.statusText,e),new Error(JSON.stringify(e))})}var i,s=null==(n=r.getEndpointURL(e,"computeEnvironments"))?void 0:n.urlPath;if(!s)return null;var a=Qe(function(){return Promise.resolve(V.default(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){i=e})},function(e){throw re.error("Fetch compute env failed: "),re.error(e),new Error(e)});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initialize=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(o)).then(function(l){return Promise.resolve(c.getServiceEndpoints(o,l)).then(function(o){function l(e){var t;function r(e){return t?e:Promise.resolve(d.json()).then(function(e){throw re.error("Provider initialized failed: ",d.status,d.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(200===(null==(e=d)?void 0:e.status))return Promise.resolve(d.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d,h=c.getEndpointURL(o,"initialize")?c.getEndpointURL(o,"initialize").urlPath:null;if(!h)return null;h+="?documentId="+e,h+="&serviceId="+t,h+="&fileIndex="+r,h+="&consumerAddress="+n,s&&(h+="&userdata="+encodeURI(JSON.stringify(s))),a&&(h+="&environment="+encodeURI(a)),u&&(h+="&validUntil="+u);var m=Qe(function(){return Promise.resolve(V.default(h,{method:"GET",headers:{"Content-Type":"application/json"},signal:i})).then(function(e){d=e})},function(e){throw re.error("Provider initialized failed: "),re.error(e),new Error("Provider initialize failed url: "+h+" ")});return m&&m.then?m.then(l):l()})})}catch(e){return Promise.reject(e)}},t.initializeComputeV1=function(e,t,r,n,o,i,s,a,u){try{var c=this;return Promise.resolve(c.getEndpoints(n)).then(function(l){return Promise.resolve(c.getServiceEndpoints(n,l)).then(function(n){function l(e){var t;function r(e){return t?e:Promise.resolve(d.json()).then(function(e){throw re.error("Initialize compute failed: ",d.status,d.statusText,e),re.error("Payload was:",JSON.stringify(h)),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=d)&&e.ok)return Promise.resolve(d.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d,h={datasets:e,algorithm:t,payment:{chainId:i,token:s,maxJobDuration:a},consumerAddress:o,environment:r},m=c.getEndpointURL(n,"initializeCompute")?c.getEndpointURL(n,"initializeCompute").urlPath:null;if(!m)return null;var f=Qe(function(){return Promise.resolve(V.default(m,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json"},signal:u})).then(function(e){d=e})},function(e){throw re.error("Initialize compute failed: "),re.error(e),new Error("ComputeJob cannot be initialized")});return f&&f.then?f.then(l):l()})})}catch(e){return Promise.reject(e)}},t.initializeCompute=function(e,t,r,n,o,i,s,a,u,c,l){try{var d=this;return Promise.resolve(d.getEndpoints(i)).then(function(h){return Promise.resolve(d.getServiceEndpoints(i,h)).then(function(m){var f=d.getEndpointURL(m,"initializeCompute")?d.getEndpointURL(m,"initializeCompute").urlPath:null;return f?Promise.resolve(d.getConsumerAddress(s)).then(function(v){return Promise.resolve(d.getNonce(i,v,l,h,m)).then(function(i){var h,m=(i+1).toString(),g=v;return g+=null==(h=e[0])?void 0:h.documentId,g+=m,Promise.resolve(d.getSignature(s,g)).then(function(i){function h(e){var t;function r(e){return t?e:Promise.resolve(m.json()).then(function(e){throw re.error("Initialize compute failed: ",m.status,m.statusText,e),re.error("Payload was:",JSON.stringify(g)),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=m)&&e.ok)return Promise.resolve(m.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var m,g={datasets:e,algorithm:t,environment:r,payment:{chainId:u,token:n,resources:a},maxJobDuration:o,consumerAddress:v,signature:i};c&&(g.policyServer=c);var p=Qe(function(){return console.log("Initialize compute url:",f),Promise.resolve(V.default(f,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json",Authorization:d.getAuthorization(s)},signal:l})).then(function(e){return m=e,console.log("Raw response:",m),function(){if(!m.ok)return Promise.resolve(m.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw re.error("Initialize compute failed: "),re.error(e),new Error("ComputeJob cannot be initialized: "+e.message+".")});return p&&p.then?p.then(h):h()})})}):null})})}catch(e){return Promise.reject(e)}},t.getDownloadUrl=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getEndpoints(o)).then(function(c){return Promise.resolve(u.getServiceEndpoints(o,c)).then(function(l){var d=u.getEndpointURL(l,"download")?u.getEndpointURL(l,"download").urlPath:null;return d?Promise.resolve(u.getConsumerAddress(i)).then(function(h){return Promise.resolve(u.getNonce(o,h,null,c,l)).then(function(o){var c=(o+1).toString();return Promise.resolve(u.getSignature(i,e+c)).then(function(o){var i=d;return i+="?fileIndex="+r,i+="&documentId="+e,i+="&transferTxId="+n,i+="&serviceId="+t,i+="&consumerAddress="+h,i+="&nonce="+c,s&&(i+="&policyServer="+encodeURI(JSON.stringify(s))),i+="&signature="+o,a&&(i+="&userdata="+encodeURI(JSON.stringify(a))),i})})}):null})})}catch(e){return Promise.reject(e)}},t.computeStartV1=function(e,t,r,n,o,i,s,a){try{var u=this;return Promise.resolve(u.getEndpoints(e)).then(function(c){return Promise.resolve(u.getServiceEndpoints(e,c)).then(function(l){var d=u.getEndpointURL(l,"computeStart")?u.getEndpointURL(l,"computeStart").urlPath:null;return Promise.resolve(t.getAddress()).then(function(h){return Promise.resolve(u.getNonce(e,h,i,c,l)).then(function(e){var c=(e+1).toString(),l=h;return l+=n.documentId,l+=c,Promise.resolve(u.signProviderRequest(t,l)).then(function(e){function t(e){var t;function r(e){if(t)return e;var r=re.error,n=u.statusText,o=u.status;return Promise.resolve(u.json()).then(function(e){return r.call(re,"Compute start failed: ",o,n,e),re.error("Payload was:",l),null})}var n=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var u,l=Object();if(l.consumerAddress=h,l.signature=e,l.nonce=c,l.environment=r,l.dataset=n,l.algorithm=o,s&&(l.additionalDatasets=s),a&&(l.output=a),!d)return null;var m=Qe(function(){return Promise.resolve(V.default(d,{method:"POST",body:JSON.stringify(l),headers:{"Content-Type":"application/json"},signal:i})).then(function(e){u=e})},function(e){throw re.error("Compute start failed:"),re.error(e),re.error("Payload was:",l),new Error("HTTP request failed calling Provider")});return m&&m.then?m.then(t):t()})})})})})}catch(e){return Promise.reject(e)}},t.computeStart=function(e,t,r,n,o,i,s,a,u,c,l,d,h,m,f){try{var v=this;return console.log("called new compute start method..."),console.log("datasets: ",n),console.log("algorithm: ",o),Promise.resolve(v.getEndpoints(e)).then(function(g){return Promise.resolve(v.getServiceEndpoints(e,g)).then(function(p){var P=v.getEndpointURL(p,"computeStart")?v.getEndpointURL(p,"computeStart").urlPath:null;return P?Promise.resolve(v.getConsumerAddress(t)).then(function(y){return Promise.resolve(v.getNonce(e,y,m,g,p)).then(function(e){var g,p=(e+1).toString(),w=String(y+(null==(g=n[0])?void 0:g.documentId)+p);return Promise.resolve(v.getSignature(t,w)).then(function(e){function g(e){var t;function r(e){return t?e:Promise.resolve(w.json()).then(function(e){throw re.error("Compute start failed: ",w.status,w.statusText,e),re.error("Payload was:",b),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=w)&&e.ok)return Promise.resolve(w.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var w,b=Object();b.consumerAddress=y,b.signature=e,b.nonce=p,b.environment=r,b.maxJobDuration=i,b.resources=a,b.dataset=n[0],b.datasets=n,b.algorithm=o,b.chainId=u,b.payment={chainId:u,token:s,maxJobDuration:i},a&&(b.resources=a),c&&(b.metadata=c),l&&(b.additionalViewers=l),d&&(b.output=d),h&&(b.policyServer=h),f&&(b.queueMaxWaitTime=f);var k=Qe(function(){return Promise.resolve(V.default(P,{method:"POST",body:JSON.stringify(b),headers:{"Content-Type":"application/json",Authorization:v.getAuthorization(t)},signal:m})).then(function(e){w=e})},function(e){throw re.error("Compute start failed:"),re.error(e),re.error("Payload was:",b),new Error("HTTP request failed calling Provider")});return k&&k.then?k.then(g):g()})})}):(re.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.freeComputeStart=function(e,t,r,n,o,i,s,a,u,c,l,d){try{var h=this;return console.log("called new free compute start method..."),console.log("datasets: ",n),console.log("algorithm: ",o),Promise.resolve(h.getEndpoints(e)).then(function(m){return Promise.resolve(h.getServiceEndpoints(e,m)).then(function(f){var v=h.getEndpointURL(f,"freeCompute")?h.getEndpointURL(f,"freeCompute").urlPath:null;return v?Promise.resolve(h.getConsumerAddress(t)).then(function(g){return Promise.resolve(h.getNonce(e,g,l,m,f)).then(function(e){var m=(e+1).toString(),f=m;return console.log("signatureMessage: ",f),Promise.resolve(h.getSignature(t,f)).then(function(e){function f(e){var t;function r(e){return t?e:Promise.resolve(p.json()).then(function(e){throw re.error("Compute start failed: ",p.status,p.statusText,e),re.error("Payload was:",P),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=p)&&e.ok)return Promise.resolve(p.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var p,P=Object();P.consumerAddress=g,P.signature=e,P.nonce=m,P.environment=r,P.resources=i,P.dataset=n[0],P.datasets=n,P.algorithm=o,s&&(P.metadata=s),a&&(P.additionalViewers=a),P.output=u,c&&(P.policyServer=c),d&&(P.queueMaxWaitTime=d);var y=Qe(function(){return Promise.resolve(V.default(v,{method:"POST",body:JSON.stringify(P),headers:{"Content-Type":"application/json",Authorization:h.getAuthorization(t)},signal:l})).then(function(e){p=e})},function(e){throw re.error("Compute start failed:"),re.error(e),re.error("Payload was:",P),new Error("HTTP request failed calling Provider")});return y&&y.then?y.then(f):f()})})}):(re.error("Compute start failed: Cannot get proper computeStart route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.computeStreamableLogs=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeStreamableLogs")?o.getEndpointURL(a,"computeStreamableLogs").urlPath:null;return u?Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,n,s,a)).then(function(e){function s(){var e;function r(t){var r,n;if(null!=(r=e)&&r.ok||200===(null==(n=e)?void 0:n.status))return console.log("Response body:",e.body),e.body;var o=re.error,i=e.statusText,s=e.status;return Promise.resolve(e.json()).then(function(e){return o.call(re,"computeStreamableLogs failed: ",s,i,e),null})}var i=Qe(function(){return Promise.resolve(V.default(u+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:o.getAuthorization(t)},signal:n})).then(function(t){e=t,console.log("Raw response:",e)})},function(e){throw re.error("computeStreamableLogs failed:"),re.error(e),new Error("HTTP request failed calling Provider")});return i&&i.then?i.then(r):r()}var a=(e+1).toString(),l="?consumerAddress="+c+"&jobId="+r,d=function(){if(!i)return Promise.resolve(o.getSignature(t,""+c+r+a)).then(function(e){l+="&signature="+e,l+="&nonce="+a})}();return d&&d.then?d.then(s):s()})}):(re.error("Compute start failed: Cannot get proper computeStreamableLogs route (perhaps not implemented on provider?)"),null)})})}catch(e){return Promise.reject(e)}},t.getComputeStartRoutes=function(e,t){void 0===t&&(t=!1);try{var r=this;return Promise.resolve(r.getEndpoints(e)).then(function(n){return Promise.resolve(r.getServiceEndpoints(e,n)).then(function(e){return t?r.getEndpointURL(e,"freeCompute")?r.getEndpointURL(e,"freeCompute").urlPath:null:r.getEndpointURL(e,"computeStart")?r.getEndpointURL(e,"computeStart").urlPath:null})})}catch(e){return Promise.reject(e)}},t.computeStop=function(e,t,r,n,o){try{var i=this,s="string"==typeof r;return Promise.resolve(i.getEndpoints(t)).then(function(a){return Promise.resolve(i.getServiceEndpoints(t,a)).then(function(u){var c=i.getEndpointURL(u,"computeStop")?i.getEndpointURL(u,"computeStop").urlPath:null;return Promise.resolve(i.getConsumerAddress(r)).then(function(l){return Promise.resolve(i.getNonce(t,l,o,a,u)).then(function(t){var a=(t+1).toString();return Promise.resolve(i.getSignature(r,l+(e||""))).then(function(t){function u(e){var t;function r(e){return t?e:Promise.resolve(h.json()).then(function(e){throw re.error("Compute stop failed: ",h.status,h.statusText,e),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=h)&&e.ok)return Promise.resolve(h.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var d=new URLSearchParams;d.set("consumerAddress",l),d.set("nonce",a),d.set("jobId",e),s||d.set("signature",t),n&&d.set("agreementId",n);var h,m=d.toString();if(!m)return null;var f=Qe(function(){return Promise.resolve(V.default(c+"?"+m,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:i.getAuthorization(r)},signal:o})).then(function(e){h=e})},function(e){throw re.error("Compute stop failed:"),re.error(e),new Error("HTTP request failed calling Provider")});return f&&f.then?f.then(u):u()})})})})})}catch(e){return Promise.reject(e)}},t.computeStatus=function(e,t,r,n,o,i){try{var s=this;return Promise.resolve(s.getEndpoints(e)).then(function(a){return Promise.resolve(s.getServiceEndpoints(e,a)).then(function(e){function a(e){var t;function r(e){var r;if(t)return e;function n(e){return r?e:Promise.resolve(u.json()).then(function(e){throw re.error("Get compute status failed:",u.status,u.statusText,e),new Error(JSON.stringify(e))})}re.error("Get compute status failed:",u.status,u.statusText);var o=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var n=function(e){if(null!=(e=u)&&e.ok)return Promise.resolve(u.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var u,c=s.getEndpointURL(e,"computeStatus")?s.getEndpointURL(e,"computeStatus").urlPath:null,l="?consumerAddress="+t;if(l+=n&&"&agreementId="+n||"",l+=r&&"&jobId="+r||"",!c)return null;var d=Qe(function(){return console.log("computeStatusUrl: ",c+l),Promise.resolve(V.default(c+l,{method:"GET",headers:{"Content-Type":"application/json",Authorization:i},signal:o})).then(function(e){u=e})},function(e){throw re.error("Get compute status failed"),re.error(e),new Error(e)});return d&&d.then?d.then(a):a()})})}catch(e){return Promise.reject(e)}},t.getComputeResultUrl=function(e,t,r,n){try{var o=this,i="string"==typeof t;return Promise.resolve(o.getEndpoints(e)).then(function(s){return Promise.resolve(o.getServiceEndpoints(e,s)).then(function(a){var u=o.getEndpointURL(a,"computeResult")?o.getEndpointURL(a,"computeResult").urlPath:null;return Promise.resolve(o.getConsumerAddress(t)).then(function(c){return Promise.resolve(o.getNonce(e,c,null,s,a)).then(function(e){var s=(e+1).toString(),a=c;return a+=r,a+=n.toString(),a+=s,Promise.resolve(o.getSignature(t,a)).then(function(e){if(!u)return null;var t=u;return t+="?consumerAddress="+c,t+="&jobId="+r,t+="&index="+n.toString(),i||(t+="&nonce="+s,t+="&signature="+e),t})})})})})}catch(e){return Promise.reject(e)}},t.computeDelete=function(e,t,r,n,o){try{var i=this;return Promise.resolve(i.getEndpoints(n)).then(function(s){return Promise.resolve(i.getServiceEndpoints(n,s)).then(function(a){var u=i.getEndpointURL(a,"computeDelete")?i.getEndpointURL(a,"computeDelete").urlPath:null;return Promise.resolve(i.getConsumerAddress(t)).then(function(c){return Promise.resolve(i.getNonce(n,c,o,s,a)).then(function(n){var s=(n+1).toString(),a=c;return a+=r||"",a+=e&&""+i.noZeroX(e)||"",a+=s,Promise.resolve(i.getSignature(t,a)).then(function(n){function s(e){var t;function r(e){return t?e:Promise.resolve(a.json()).then(function(e){throw re.error("Delete compute job failed:",a.status,a.statusText,e),re.error("Payload was:",l),new Error(JSON.stringify(e))})}var n=function(e){if(null!=(e=a)&&e.ok)return Promise.resolve(a.json()).then(function(e){return t=1,e})}();return n&&n.then?n.then(r):r(n)}var a,l=Object();if(l.documentId=e,l.consumerAddress=c,l.jobId=r,n&&(l.signature=n),!u)return null;var d=Qe(function(){return Promise.resolve(V.default(u,{method:"DELETE",body:JSON.stringify(l),headers:{"Content-Type":"application/json",Authorization:i.getAuthorization(t)},signal:o})).then(function(e){a=e})},function(e){throw re.error("Delete compute job failed:"),re.error(e),re.error("Payload was:",l),new Error("HTTP request failed calling Provider")});return d&&d.then?d.then(s):s()})})})})})}catch(e){return Promise.reject(e)}},t.generateAuthToken=function(e,t,r){try{var n=this;return Promise.resolve(e.getAddress()).then(function(o){return Promise.resolve(n.getEndpoints(t)).then(function(i){return Promise.resolve(n.getServiceEndpoints(t,i)).then(function(s){var a=n.getEndpointURL(s,"generateAuthToken").urlPath||null;return Promise.resolve(n.getNonce(t,o,r,i,s)).then(function(t){var i=(t+1).toString();return Promise.resolve(n.signProviderRequest(e,o+i)).then(function(e){return Qe(function(){return Promise.resolve(V.default(a,{method:"POST",body:JSON.stringify({address:o,signature:e,nonce:i}),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to generate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){return null==e?void 0:e.token})})},function(e){throw re.error("Generate auth token failed:"),re.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.invalidateAuthToken=function(e,t,r,n){try{var o=this;return Promise.resolve(e.getAddress()).then(function(i){return Promise.resolve(o.getEndpoints(r)).then(function(s){return Promise.resolve(o.getServiceEndpoints(r,s)).then(function(a){var u=o.getEndpointURL(a,"invalidateAuthToken").urlPath||null;return Promise.resolve(o.getNonce(r,i,n,s,a)).then(function(r){var s=(r+1).toString();return Promise.resolve(o.signProviderRequest(e,i+s)).then(function(e){return Qe(function(){return Promise.resolve(V.default(u,{method:"POST",body:JSON.stringify({address:i,signature:e,token:t,nonce:s}),headers:{"Content-Type":"application/json"},signal:n})).then(function(e){if(null==e||!e.ok)throw new Error("Failed to invalidate auth token: "+e.status+" "+e.statusText);return Promise.resolve(e.json())})},function(e){throw re.error("Generate auth token failed:"),re.error(e),new Error("HTTP request failed calling Provider")})})})})})})}catch(e){return Promise.reject(e)}},t.isValidProvider=function(e,t){try{return Promise.resolve(Qe(function(){return Promise.resolve(V.default(e,{method:"GET",headers:{"Content-Type":"application/json"},signal:t})).then(function(e){var t,r=function(){if(null!=e&&e.ok)return Promise.resolve(e.json()).then(function(e){if(e&&(e.providerAddress||e.providerAddresses))return t=!0})}();return r&&r.then?r.then(function(e){return!!t&&e}):!!t&&r})},function(e){return re.error("Error validating provider: "+e.message),!1}))}catch(e){return Promise.reject(e)}},t.PolicyServerPassthrough=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw re.error("PolicyServerPassthrough failed: ",i.status,i.statusText,e),re.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"PolicyServerPassthrough")?n.getEndpointURL(e,"PolicyServerPassthrough").urlPath:null;if(!s)return null;var a=Qe(function(){return Promise.resolve(V.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw re.error("PolicyServerPassthrough failed: "),re.error(e),new Error("PolicyServerPassthrough failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.initializePSVerification=function(e,t,r){try{var n=this;return Promise.resolve(n.getEndpoints(e)).then(function(o){return Promise.resolve(n.getServiceEndpoints(e,o)).then(function(e){function o(e){var r;function n(e){return r?e:Promise.resolve(i.json()).then(function(e){throw re.error("initializePSVerification failed: ",i.status,i.statusText,e),re.error("Payload was:",JSON.stringify(t)),new Error(JSON.stringify(e))})}var o=function(e){if(null!=(e=i)&&e.ok)return Promise.resolve(i.json()).then(function(e){return r=1,e})}();return o&&o.then?o.then(n):n(o)}var i,s=n.getEndpointURL(e,"initializePSVerification")?n.getEndpointURL(e,"initializePSVerification").urlPath:null;if(!s)return null;var a=Qe(function(){return Promise.resolve(V.default(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:r})).then(function(e){return i=e,function(){if(!i.ok)return Promise.resolve(i.text()).then(function(e){throw new Error(""+e)})}()})},function(e){throw re.error("initializePSVerification failed: "),re.error(e),new Error("initializePSVerification failed: "+e.message+".")});return a&&a.then?a.then(o):o()})})}catch(e){return Promise.reject(e)}},t.noZeroX=function(e){return this.zeroXTransformer(e,!1)},t.zeroXTransformer=function(e,t){void 0===e&&(e="");var r=this.inputMatch(e,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(t&&r.valid?"0x":"")+r.output},t.inputMatch=function(e,t,r){if("string"!=typeof e)throw re.debug("Not input string:"),re.debug(e),new Error("["+r+"] Expected string, input type: "+typeof e);var n=e.match(t);return n?{valid:!0,output:n[1]}:(re.warn("["+r+"] Input transformation failed."),{valid:!1,output:e})},t.getData=function(e,t){try{return Promise.resolve(V.default(e,{method:"GET",headers:{"Content-type":"application/json",Authorization:t}}))}catch(e){return Promise.reject(e)}},e}(),tt=new et,rt=function(e,t,n,o){try{var i=new r.ethers.Contract(t,ae,e);return Promise.resolve(i.allowance(n,o))}catch(e){return Promise.reject(e)}},nt=function(e,t,n,o,i){try{var s=new r.ethers.Contract(t,ae,e);return Promise.resolve(s.allowance(n,o)).then(function(r){return Promise.resolve(le(e,t,r,i))})}catch(e){return Promise.reject(e)}},ot=function(e,t,n,o,i,s,a,u){void 0===a&&(a=!1);try{var c,l=function(r){if(c)return r;var n=null;return Promise.resolve(d.approve.estimateGas(i,s)).then(function(r){if(u)return r;var o=function(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}(function(){return Promise.resolve(ue(r,e,null==t?void 0:t.gasFeeMultiplier,d.approve,i,s)).then(function(e){n=e})},function(e){re.error("ERROR: Failed to approve spender to spend tokens : "+e.message)});return o&&o.then?o.then(function(){return n}):n})},d=new r.ethers.Contract(o,ae,e),h=function(){if(!a)return Promise.resolve(rt(e,o,n,i)).then(function(e){if(new M.default(e).isGreaterThan(new M.default(s))){var t=BigInt(e);return c=1,t}})}();return Promise.resolve(h&&h.then?h.then(l):l(h))}catch(e){return Promise.reject(e)}},it=function(e,t,n,o,i,s,a,u,c){void 0===a&&(a=!1);try{var l,d=function(r){return l?r:Promise.resolve(ce(e,o,s,u)).then(function(r){return Promise.resolve(h.approve.estimateGas(i,r)).then(function(n){return c?new O.default(n.toString()):Promise.resolve(ue(n,e,null==t?void 0:t.gasFeeMultiplier,h.approve,i,r))})})},h=new r.ethers.Contract(o,ae,e),m=function(){if(!a)return Promise.resolve(nt(e,o,n,i)).then(function(e){if(new O.default(e).greaterThanOrEqualTo(new O.default(s))){var t=new O.default(e).toNumber();return l=1,t}})}();return Promise.resolve(m&&m.then?m.then(d):d(m))}catch(e){return Promise.reject(e)}},st={datasets:{invalid:"Datasets is not a list, as expected"},algorithm:{serviceId:{missing:"The serviceId key is missing from the algorithm s DDO.",not_found:"The provided serviceId does not exist.",service_not_access_compute:"Service type is neither access, nor compute.",main_service_compute:"If the main service is not compute for this asset when calling initialize endpoint.",compute_services_not_in_same_provider:"Files attached to the compute service are not decrypted by the correct provider. This occurs when both asset and algorithm are requested by their compute service which cannot be decrypted by a single provider as how it is supposed to be."},container:{checksum_prefix:"Container checksum does not start with the prefix sha256:.",mising_entrypoint_image_checksum:"Either entrypoint, either image, or either checksum are missing from the container dictionary from the algorithm s DDO."},documentId:{did_not_found:"The algorithm s DID could not be retrieved from the metadata store, because the algorithm asset does not exist.",missing:"The documentId key is missing from the algorithm s DDO."},transferTxId:{missing:"The transferTxId key is missing from the algorithm s DDO."},missing_meta_documentId:"Either algorithm metadata, or algorithm DID are missing.",did_not_found:"Either algorithm metadata, or algorithm DID are missing.",not_algo:"Either algorithm metadata, or algorithm DID are missing.",in_use_or_not_on_chain:"Either algorithm metadata, or algorithm DID are missing.",meta_oneof_url_rawcode_remote:"Either algorithm metadata, or algorithm DID are missing.",file_unavailable:"One possibility is that the asset could not be retrieved from Aquariuss database. Otherwise, there are issues related to services"},error:{not_trusted_algo_publisher:"The owner of the algorithm's DDO is not a trusted algorithms publishers list.",not_trusted_algo:"The algorithm's DID is not in the asset's trusted algorithms dictionary. ",no_publisherTrustedAlgorithms:"The algorithm's key publisherTrustedAlgorithms does not exist in the algorithm's DDO.",algorithm_file_checksum_mismatch:"filesChecksum from the algorithm's DDO is invalid.",algorithm_container_checksum_mismatch:"The containerChecksum from the algorithm's DDO is invalid.",no_raw_algo_allowed:"The asset does not allow raw algorithms to be run on it.","Asset malformed":"The asset published on chain is malformed, missing some required keys or not compliant with our schemas.","Asset is not consumable.":"Assets metadata status is not in the range of valid status codes for assets. The recognized states for the metadata are defined on our docs.","DID is not a valid algorithm.":"Either the algorithm assets DID is incorrectly typed, either the algorithm timeout expired.","Compute environment does not exist.":"The compute environment provided by the user does not exist, it is not served by our compute-to-data feature. The user can use get_c2d_environments to check the list of available compute environments.","The validUntil value is not correct.":"validUntil value is most probably expired.","Cannot resolve DID":"The dataset DID does not exist in the Metadata store.","Invalid serviceId":"The serviceId of that dataset is not correct.","Unable to get dataset files":"The files of that dataset could not be decrypted or retrieved","cannot decrypt files for this service.":"The files of that dataset could not be decrypted due to the fact that file object, which contains the structure and the type of specific file, is missing from the validation part.","Unsupported type ":"The file object type is not supported by Provider.","malformed file object":"The file object structure is invalid and does not contain the wanted information for the specific file."},order:{fees_not_paid:" Provider fees are not paid."},output:{invalid:"The algorithms validation after the build stage has not been decoded properly as a dictionary."}};function at(e,t,r){if(!e.s){if(r instanceof ut){if(!r.s)return void(r.o=at.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(at.bind(null,e,t),at.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var ut=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,o=this.s;if(o){var i=1&o?t:r;if(i){try{at(n,1,i(this.v))}catch(e){at(n,2,e)}return n}return this}return this.o=function(e){try{var o=e.v;1&e.s?at(n,1,t?t(o):o):r?at(n,1,r(o)):at(n,2,o)}catch(e){at(n,2,e)}},n},e}();function ct(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}exports.AccessListContract=_e,exports.AccesslistFactory=qe,exports.Aquarius=Ye,exports.Config=function(){this.nodeUri=void 0,this.providerAddress=void 0,this.oceanNodeUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.routerFactoryAddress=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.EnterpriseFeeCollector=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.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0,this.sdk=void 0,this.accessListFactory=void 0,this.escrow=void 0},exports.ConfigHelper=se,exports.DEVELOPMENT_CHAIN_ID=8996,exports.Datatoken=Le,exports.Datatoken4=Ge,exports.Dispenser=Te,exports.EnterpriseFeeCollectorContract=We,exports.EscrowContract=Je,exports.FEE_HISTORY_NOT_SUPPORTED="Returned error: Method eth_feeHistory not supported.",exports.FixedRateExchange=Ae,exports.GASLIMIT_DEFAULT=1e6,exports.KNOWN_CONFIDENTIAL_EVMS=ie,exports.Logger=te,exports.LoggerInstance=re,exports.MAX_UINT_256="115792089237316195423570985008687907853269984665640564039457584007913129639934",exports.Nft=Ie,exports.NftFactory=je,exports.Provider=et,exports.ProviderInstance=tt,exports.Router=Ee,exports.SmartContract=be,exports.SmartContractWithAddress=ke,exports.ZERO_ADDRESS=Se,exports.allowance=nt,exports.allowanceWei=rt,exports.amountToUnits=ce,exports.approve=it,exports.approveWei=ot,exports.balance=function(e,t,n,o){try{var i=new r.ethers.Contract(t,ae,e);return Promise.resolve(i.balanceOf(n)).then(function(r){return Promise.resolve(le(e,t,r,o))})}catch(e){return Promise.reject(e)}},exports.calculateActiveTemplateIndex=Ne,exports.configHelperNetworks=oe,exports.createAccessListFactory=function(e,t,n){try{var o=new r.ethers.Contract(e,J.default.abi,t);return Promise.resolve(t.getAddress()).then(function(e){var t,r=ct(function(){return Promise.resolve(o.deployAccessListContract("AllowList","ALLOW",!0,e,n||[e],["https://oceanprotocol.com/nft/"])).then(function(e){return function(){if(e&&e.wait)return Promise.resolve(e.wait()).then(function(e){var r=we(e,"NewAccessList");return t=1,r.args[0]})}()})},function(e){console.log("ERROR createAccessListFactory(): ",e)});return r&&r.then?r.then(function(e){return t?e:null}):t?r:null})}catch(e){return Promise.reject(e)}},exports.createAsset=function(e,t,n,o,i,s,a,u,c,l,d,h,m,f,v){void 0===a&&(a=!0);try{var g,p,P=this,y=w.DDOManager.getDDOClass(s),b=y.getAssetFields().indexedMetadata,k=(null==(g=y.getDDOData())||null==(g=g.stats)||null==(g=g.price)?void 0:g.value)||(null==b||null==(p=b.stats[0])||null==(p=p.prices[0])?void 0:p.price),S=y.getDDOFields(),A=S.chainId,E=S.nftAddress,F=y.getDDOFields().services;if("string"!=typeof i&&"number"!=typeof i)throw new Error('Invalid template! Must be a "number" or a "string"');return Promise.resolve(n.provider.getNetwork()).then(function(g){var p=g.chainId;if(A&&A!==Number(p))throw new Error("Chain ID from DDO is different than the configured network.");var w=(new se).getConfig(parseInt(String(p)));return Promise.resolve(Ne(n,w.nftFactoryAddress,i,Number(p))).then(function(i){if(i<1){if(8996!==Number(p))throw new Error("Invalid template index: "+i);i=1}var g=new Ie(n,Number(p)),b=new je(w.nftFactoryAddress,n,Number(p));return Promise.resolve(n.getAddress()).then(function(S){var C,x;function j(e){return x?e:Promise.resolve(D.wait()).then(function(e){var t;function i(e){if(t)return e;function i(){function e(){var e=g.setMetadata,a=E;return Promise.resolve(n.getAddress()).then(function(n){return Promise.resolve(e.call(g,a,n,0,u,"",r.toBeHex(i),t,o)).then(function(){return s.id})})}F[0].datatokenAddress=m,F[0].serviceEndpoint=u;var t,o,i,c=y.makeDid(E=h,A.toString());s=y.updateFields({id:c,nftAddress:E});var d=function(){if(a)return Promise.resolve(tt.encrypt(s,Number(p),u,n,null)).then(function(e){return t=e,Promise.resolve(l.validate(s,n,u)).then(function(e){o=e.hash,i=2})});var e=JSON.stringify(s),c=Buffer.from(e);t=r.hexlify(c),o="0x"+T.createHash("sha256").update(t).digest("hex"),i=0}();return d&&d.then?d.then(e):e()}var c=function(){if("oasis"!==w.sdk)return Promise.resolve(tt.encrypt(o,Number(p),u,n,null)).then(function(e){F[0].files=e});F[0].files=""}();return c&&c.then?c.then(i):i()}var c=we(e,"NFTCreated"),d=we(e,"TokenCreated"),h=c.args.newTokenAddress,m=d.args.newTokenAddress;o.datatokenAddress=m,o.nftAddress=h;var f=function(){if("oasis"===w.sdk){var e=new r.ethers.Contract(m,B.default.abi,n);return ct(function(){return Promise.resolve(e.setFilesObject(r.toUtf8Bytes(JSON.stringify(o)))).then(function(e){var t=function(){if(e.wait)return Promise.resolve(e.wait()).then(function(){})}();if(t&&t.then)return t.then(function(){})})},function(e){return console.log("Error updating files object with data token and nft addresses: ",e),t=1,null})}}();return f&&f.then?f.then(i):i(f)})}var D,M={name:e,symbol:t,templateIndex:1,tokenURI:"aaa",transferable:!0,owner:S},O={templateIndex:i,cap:"100000",feeAmount:"0",paymentCollector:S,feeToken:c||w.oceanTokenAddress,minter:S,mpFeeAddress:Se};null!=o&&o.files[0].type&&[exports.FileObjectType.ARWEAVE,exports.FileObjectType.IPFS,exports.FileObjectType.URL].includes(null==o||null==(C=o.files[0])||null==(C=C.type)?void 0:C.toLowerCase())||(console.log('Missing or invalid files object type, defaulting to "url"'),o.type=exports.FileObjectType.URL),"oasis"===w.sdk&&(O.filesObject=o,O.accessListFactory=d||w.accessListFactory,O.allowAccessList=h,O.denyAccessList=m);var N=ct(function(){var e=function(){if(!k)return Promise.resolve(b.createNftWithDatatoken(M,O)).then(function(e){D=e});var e=function(){if("0"===k.toString())return Promise.resolve(b.createNftWithDatatokenWithDispenser(M,O,{dispenserAddress:w.dispenserAddress,maxTokens:"1",maxBalance:"100000000",withMint:!0,allowedSwapper:Se})).then(function(e){D=e});var e=f||w.oceanTokenAddress;return Promise.resolve(de(P.signer,e)).then(function(t){v||(v=t);var r={fixedRateAddress:w.fixedRateExchangeAddress,baseTokenAddress:e,owner:S,marketFeeCollector:S,baseTokenDecimals:v,datatokenDecimals:18,fixedRate:k.toString(),marketFee:"0",allowedConsumer:S,withMint:!0};return Promise.resolve(b.createNftWithDatatokenWithFixedRate(M,O,r)).then(function(e){D=e})})}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})},function(e){return console.log("ERROR creating NFT bundle",e),x=1,null});return N&&N.then?N.then(j):j(N)})})})}catch(e){return Promise.reject(e)}},exports.decimals=function(e,t){try{var n=new r.ethers.Contract(t,ae,e);return Promise.resolve(n.decimals()).then(Number)}catch(e){return Promise.reject(e)}},exports.downloadFile=function(e,t){try{return Promise.resolve(fetch(e)).then(function(r){if(!r.ok)throw new Error("Response error.");var n;try{n=r.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(r){try{n=e.split("/").pop()}catch(e){n="file"+t}}return Promise.resolve(r.arrayBuffer()).then(function(e){return{data:e,filename:n}})})}catch(e){return Promise.reject(e)}},exports.downloadFileBrowser=function(e){var t=new XMLHttpRequest;t.responseType="blob",t.open("GET",e),t.onload=function(){var e=t.getResponseHeader("content-disposition"),r=null==e?void 0:e.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/),n=r&&r[1]?r[1]:"file",o=window.URL.createObjectURL(t.response),i=document.createElement("a");i.href=o,i.setAttribute("download",n),document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(o)},t.send()},exports.generateDid=function(e,t){return e=r.getAddress(e),"did:op:"+X.default(e+t.toString(10)).toString()},exports.generateDtName=Ce,exports.getErrorMessage=function(e){try{var t=JSON.parse(e),r=Object.keys(t)[0];if("error"===r){var n,o=t[r];return(null==(n=st[r])?void 0:n[o])||"Provider request failed: "+o}var i=t[r];return t[Object.keys(t)[1]]+" : "+i}catch(t){return re.error("[getErrorMessage] error: ",t),e}},exports.getEventFromTx=we,exports.getFairGasPrice=he,exports.getHash=function(e){return X.default(e).toString()},exports.getOceanArtifactsAddresses=Re,exports.getOceanArtifactsAddressesByChainId=Ue,exports.getTokenDecimals=de,exports.isDefined=function(e){return null!=e},exports.minAbi=ae,exports.orderAsset=function(e,t,r,n,o,i,s,a,u,c,l,d){void 0===u&&(u="0"),void 0===c&&(c=0),void 0===l&&(l=0),void 0===d&&(d=0);try{var h=w.DDOManager.getDDOClass(e),m=h.getAssetFields().datatokens,f=h.getDDOFields(),v=f.chainId,g=f.services;return s||(s={consumeMarketFeeAddress:"0x0000000000000000000000000000000000000000",consumeMarketFeeAmount:"0",consumeMarketFeeToken:"0x0000000000000000000000000000000000000000"}),Promise.resolve(t.provider.getNetwork()).then(function(h){if(v!==Number(h.chainId))throw new Error("Chain ID from DDO is different than the configured network.");if(!m[c].address)throw new Error("The datatoken with index: "+c+" does not exist for the asset with did: "+e.id);if(!g[l].id)throw new Error("There is no service with index: "+l+" defined for the asset with did: "+e.id);return Promise.resolve(n.getId(m[c].address)).then(function(h){return Promise.resolve(n.getFixedRates(m[c].address)).then(function(f){return Promise.resolve(n.getDispensers(m[c].address)).then(function(v){return Promise.resolve(n.getPublishingMarketFee(m[c].address)).then(function(p){function P(e){return a?e:Promise.resolve(b.call(tt,T,k,0,e,o||r.oceanNodeUri)).then(y)}function y(o){function v(o){function a(o){var i,a={consumer:o,serviceIndex:l,_providerFee:P,_consumeMarketFee:s};return function(e,t){var r,n=-1;e:{for(var o=0;o<t.length;o++){var i=t[o][0];if(i){var s=i();if(s&&s.then)break e;if(s===e){n=o;break}}else n=o}if(-1!==n){do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then){r=!0;break e}var c=t[n][2];n++}while(c&&!c());return u}}var l=new ut,d=at.bind(null,l,2);return(r?u.then(h):s.then(function r(s){for(;;){if(s===e){n=o;break}if(++o===t.length){if(-1!==n)break;return void at(l,1,u)}if(i=t[o][0]){if((s=i())&&s.then)return void s.then(r).then(void 0,d)}else n=o}do{for(var a=t[n][1];!a;)n++,a=t[n][1];var u=a();if(u&&u.then)return void u.then(h).then(void 0,d);var c=t[n][2];n++}while(c&&!c());at(l,1,u)})).then(void 0,d),l;function h(e){for(;;){var r=t[n][2];if(!r||r())break;n++;for(var o=t[n][1];!o;)n++,o=t[n][1];if((e=o())&&e.then)return void e.then(h).then(void 0,d)}at(l,1,e)}}(w,[[function(){return"free"},function(){var e=function(e){var t;if(i)return e;function o(e){if(t)return e}var s=function(){if(2===h||4===h)return Promise.resolve(n.buyFromDispenserAndOrder(g[l].datatokenAddress,a,r.dispenserAddress)).then(function(e){return t=1,e})}();return s&&s.then?s.then(o):o(s)},o=function(){if(1===h){var e=new Te(r.dispenserAddress,t),o=e.dispense,s=m[c].address;return Promise.resolve(t.getAddress()).then(function(t){return Promise.resolve(o.call(e,s,"1",t)).then(function(e){if(!e)throw new Error("Failed to dispense !");return Promise.resolve(e.wait()).then(function(){return Promise.resolve(n.startOrder(m[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return i=1,e})})})})}}();return o&&o.then?o.then(e):e(o)}],[function(){return"fixed"},function(){var o=new Ae(r.fixedRateExchangeAddress,t);if(!f[d].id)throw new Error("There is no fixed rate exchange with index: "+l+" for the asset with did: "+e.id);return Promise.resolve(o.getFeesInfo(f[d].id)).then(function(e){return Promise.resolve(o.getExchange(f[d].id)).then(function(i){return Promise.resolve(o.calcBaseInGivenDatatokensOut(e.exchangeId,"1",s.consumeMarketFeeAmount)).then(function(l){var d;function f(e){var o;if(d)return e;function s(e){if(o)return e}var u=function(){if(2===h||4===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(it(t,r,e,i.baseToken,m[c].address,v,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to confirm/mine approval transaction!");return Promise.resolve(n.buyFromFreAndOrder(m[c].address,a,g)).then(function(e){return o=1,e})}if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return u&&u.then?u.then(s):s(u)}var v=new O.default(+l.baseTokenAmount||0).add(new O.default(s.consumeMarketFeeAmount||0)).add(new O.default(+p.publishMarketFeeAmount||0)).toString(),g={exchangeContract:r.fixedRateExchangeAddress,exchangeId:e.exchangeId,maxBaseTokenAmount:v,baseTokenAddress:i.baseToken,baseTokenDecimals:parseInt(i.btDecimals)||18,swapMarketFee:u,marketFeeAddress:p.publishMarketFeeAddress},P=function(){if(1===h)return Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(it(t,r,e,i.baseToken,r.fixedRateExchangeAddress,v,!1)).then(function(e){function t(e){if(!e)throw new Error("Failed to approve "+i.baseToken+" !");return Promise.resolve(o.buyDatatokens(i.exchangeId,"1",v,p.publishMarketFeeAddress,u)).then(function(e){return Promise.resolve(e.wait()).then(function(e){if(!e)throw new Error("Failed to buy datatoken from fixed rate!");return Promise.resolve(n.startOrder(m[c].address,a.consumer,a.serviceIndex,a._providerFee,a._consumeMarketFee)).then(function(e){return d=1,e})})})}return"number"!=typeof e?Promise.resolve("number"!=typeof e?e.wait():e).then(t):t("number"!=typeof e?e.wait():e)})})}();return P&&P.then?P.then(f):f(P)})})})}],[void 0,function(){throw new Error("Pricing schema not supported !")}]])}return i?a(i):Promise.resolve(t.getAddress()).then(a)}var P=a||o.providerFee,y=function(){if(P&&P.providerFeeAddress!==Se&&P.providerFeeAmount&&parseInt(P.providerFeeAmount)>0)return function(e,n){try{var o=Promise.resolve(t.getAddress()).then(function(e){return Promise.resolve(ot(t,r,e,P.providerFeeToken,g[0].datatokenAddress,P.providerFeeAmount)).then(function(){})})}catch(e){return n()}return o&&o.then?o.then(void 0,n):o}(0,function(){throw new Error("Failed to approve provider fee token "+P.providerFeeToken)})}();return y&&y.then?y.then(v):v()}var w=f.length>0?"fixed":v.length>0?"free":"NOT_ALLOWED",b=a||tt.initialize,k=a||g[l].id,T=a||e.id;return a?P(y(a)):Promise.resolve(t.getAddress()).then(P)})})})})})}catch(e){return Promise.reject(e)}},exports.sendTx=ue,exports.setContractDefaults=ye,exports.signHash=function(e,t){try{var n=r.getBytes(t);return Promise.resolve(e._legacySignMessage(n)).then(function(e){var t="0x"+(e=e.substr(2)).slice(0,64),r="0x"+e.slice(64,128),n="0x"+e.slice(128,130);return"0x00"===n&&(n="0x1b"),"0x01"===n&&(n="0x1c"),{v:n,r:t,s:r}})}catch(e){return Promise.reject(e)}},exports.signRequest=Ve,exports.sleep=He,exports.transfer=function(e,t,n,o,i,s,a){try{var u=new r.ethers.Contract(n,ae,e);return Promise.resolve(ce(e,n,i,s)).then(function(r){return Promise.resolve(u.transfer.estimateGas(o,r)).then(function(n){return a?n:Promise.resolve(ue(n,e,null==t?void 0:t.gasFeeMultiplier,u.transfer,o,r))})})}catch(e){return Promise.reject(e)}},exports.unitsToAmount=le,exports.useOasisSDK=function(e){var t=(new se).getConfig(e);return t&&"oasis"===t.sdk};
2
2
  //# sourceMappingURL=lib.cjs.map