@oceanprotocol/lib 1.1.8 → 2.0.0-next.3

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +47 -16
  2. package/CodeExamples.md +28 -315
  3. package/README.md +4 -7
  4. package/dist/lib.js +1 -1
  5. package/dist/lib.js.map +1 -1
  6. package/dist/lib.modern.js +1 -1
  7. package/dist/lib.modern.js.map +1 -1
  8. package/dist/lib.module.js +1 -1
  9. package/dist/lib.module.js.map +1 -1
  10. package/dist/lib.umd.js +1 -1
  11. package/dist/lib.umd.js.map +1 -1
  12. package/dist/src/@types/Asset.d.ts +4 -4
  13. package/dist/src/@types/Compute.d.ts +1 -1
  14. package/dist/src/@types/DDO/DDO.d.ts +2 -5
  15. package/dist/src/@types/{Erc20.d.ts → Datatoken.d.ts} +18 -1
  16. package/dist/src/@types/Dispenser.d.ts +9 -0
  17. package/dist/src/@types/FixedPrice.d.ts +24 -0
  18. package/dist/src/@types/{Erc721.d.ts → NFT.d.ts} +6 -0
  19. package/dist/src/@types/NFTFactory.d.ts +20 -0
  20. package/dist/src/@types/Provider.d.ts +8 -0
  21. package/dist/src/@types/ReturnTypes.d.ts +2 -0
  22. package/dist/src/@types/Router.d.ts +1 -1
  23. package/dist/src/@types/index.d.ts +11 -8
  24. package/dist/src/{models → config}/Config.d.ts +2 -23
  25. package/dist/src/{utils → config}/ConfigHelper.d.ts +1 -1
  26. package/dist/src/config/index.d.ts +2 -0
  27. package/dist/src/contracts/Datatoken.d.ts +232 -0
  28. package/dist/src/contracts/Dispenser.d.ts +73 -0
  29. package/dist/src/contracts/FixedRateExchange.d.ts +212 -0
  30. package/dist/src/contracts/NFT.d.ts +197 -0
  31. package/dist/src/contracts/NFTFactory.d.ts +144 -0
  32. package/dist/src/contracts/Router.d.ts +92 -0
  33. package/dist/src/contracts/SmartContract.d.ts +22 -0
  34. package/dist/src/contracts/SmartContractWithAddress.d.ts +18 -0
  35. package/dist/src/contracts/df/DfRewards.d.ts +32 -0
  36. package/dist/src/contracts/df/DfStrategyV1.d.ts +23 -0
  37. package/dist/src/contracts/index.d.ts +13 -0
  38. package/dist/src/contracts/ve/VeAllocate.d.ts +41 -0
  39. package/dist/src/contracts/ve/VeFeeDistributor.d.ts +30 -0
  40. package/dist/src/contracts/ve/VeOcean.d.ts +69 -0
  41. package/dist/src/index.d.ts +4 -7
  42. package/dist/src/{aquarius → services}/Aquarius.d.ts +2 -3
  43. package/dist/src/{provider → services}/Provider.d.ts +5 -13
  44. package/dist/src/services/index.d.ts +2 -0
  45. package/dist/src/utils/Constants.d.ts +2 -0
  46. package/dist/src/utils/ContractUtils.d.ts +14 -8
  47. package/dist/src/utils/DdoHelpers.d.ts +1 -1
  48. package/dist/src/utils/FetchHelper.d.ts +1 -4
  49. package/dist/src/utils/Logger.d.ts +0 -1
  50. package/dist/src/utils/TokenUtils.d.ts +17 -39
  51. package/dist/src/utils/index.d.ts +6 -7
  52. package/dist/test/TestContractHandler.d.ts +4 -4
  53. package/dist/test/config.d.ts +1 -1
  54. package/dist/test/unit/{factories/NftFactory.test.d.ts → DFRewards.test.d.ts} +0 -0
  55. package/dist/test/unit/{tokens/Datatoken.test.d.ts → Datatoken.test.d.ts} +0 -0
  56. package/dist/test/unit/{pools/dispenser/Dispenser.test.d.ts → Dispenser.test.d.ts} +0 -0
  57. package/dist/test/unit/{pools/fixedRate/FixedRateExchange.test.d.ts → FixedRateExchange.test.d.ts} +0 -0
  58. package/dist/test/unit/{tokens/Nft.test.d.ts → Nft.test.d.ts} +0 -0
  59. package/dist/test/unit/{pools/Router.test.d.ts → NftFactory.test.d.ts} +0 -0
  60. package/dist/test/unit/{pools/balancer/Pool.test.d.ts → Router.test.d.ts} +0 -0
  61. package/dist/test/unit/{pools/ssContracts/SideStaking.test.d.ts → veOcean.test.d.ts} +0 -0
  62. package/package.json +6 -19
  63. package/dist/src/@types/Pool.d.ts +0 -45
  64. package/dist/src/aquarius/index.d.ts +0 -1
  65. package/dist/src/factories/NFTFactory.d.ts +0 -275
  66. package/dist/src/factories/index.d.ts +0 -1
  67. package/dist/src/models/index.d.ts +0 -1
  68. package/dist/src/pools/Router.d.ts +0 -228
  69. package/dist/src/pools/balancer/Pool.d.ts +0 -395
  70. package/dist/src/pools/balancer/index.d.ts +0 -1
  71. package/dist/src/pools/dispenser/Dispenser.d.ts +0 -145
  72. package/dist/src/pools/dispenser/index.d.ts +0 -1
  73. package/dist/src/pools/fixedRate/FixedRateExchange.d.ts +0 -388
  74. package/dist/src/pools/fixedRate/index.d.ts +0 -1
  75. package/dist/src/pools/index.d.ts +0 -5
  76. package/dist/src/pools/ssContracts/SideStaking.d.ts +0 -133
  77. package/dist/src/pools/ssContracts/index.d.ts +0 -1
  78. package/dist/src/provider/index.d.ts +0 -1
  79. package/dist/src/tokens/Datatoken.d.ts +0 -413
  80. package/dist/src/tokens/NFT.d.ts +0 -364
  81. package/dist/src/tokens/index.d.ts +0 -2
  82. package/dist/src/utils/ConversionTypeHelper.d.ts +0 -3
  83. package/dist/src/utils/PoolHelpers.d.ts +0 -8
@@ -1,2 +1,2 @@
1
- import t from"web3";import e from"bignumber.js";import a from"cross-fetch";import s from"@oceanprotocol/contracts/addresses/address.json";import i from"crypto-js/sha256";import n from"decimal.js";import o from"@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json";import r from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json";import c from"@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json";import h from"@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json";import l from"@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json";import d from"@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json";import w from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json";import u from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json";import m from"@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json";var g;!function(t){t[t.None=-1]="None",t[t.Error=0]="Error",t[t.Warn=1]="Warn",t[t.Log=2]="Log",t[t.Verbose=3]="Verbose"}(g||(g={}));class p{constructor(t=g.Error){this.logLevel=void 0,this.logLevel=t}setLevel(t){this.logLevel=t}bypass(...t){this.dispatch("log",-Infinity,...t)}debug(...t){this.dispatch("debug",g.Verbose,...t)}log(...t){this.dispatch("log",g.Log,...t)}warn(...t){this.dispatch("warn",g.Warn,...t)}error(...t){this.dispatch("error",g.Error,...t)}dispatch(t,e,...a){this.logLevel>=e&&console[t](...a)}}const f=new p;var b={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 y(t){const e=t||b,a=Math.floor(Math.random()*e.adjectives.length),s=Math.floor(Math.random()*e.nouns.length),i=Math.floor(100*Math.random()),n=e.adjectives[a].replace(/^\w/,t=>t.toUpperCase()),o=e.nouns[s].replace(/^\w/,t=>t.toUpperCase());return{name:`${n} ${o} Token`,symbol:`${(n.substring(0,3)+o.substring(0,3)).toUpperCase()}-${i}`}}const C=[{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"}],R="0x0000000000000000000000000000000000000000",A=1e6;function k(t,e){return e&&(e.transactionBlockTimeout&&(t.transactionBlockTimeout=e.transactionBlockTimeout),e.transactionConfirmationBlocks&&(t.transactionConfirmationBlocks=e.transactionConfirmationBlocks),e.transactionPollingTimeout&&(t.transactionPollingTimeout=e.transactionPollingTimeout)),t}async function T(t,a){const s=new e(await t.eth.getGasPrice());return a&&a.gasFeeMultiplier?s.multipliedBy(a.gasFeeMultiplier).integerValue(e.ROUND_DOWN).toString(10):s.toString(10)}function E(e){let a,s;return e.name&&e.symbol||({name:a,symbol:s}=y()),{templateIndex:e.templateIndex,strings:[e.name||a,e.symbol||s],addresses:[e.minter,e.paymentCollector,e.mpFeeAddress,e.feeToken],uints:[t.utils.toWei(e.cap),t.utils.toWei(e.feeAmount)],bytess:[]}}async function v(t,e){return{exchangeContract:e.exchangeContract,exchangeId:e.exchangeId,maxBaseTokenAmount:await P(t,e.baseTokenAddress,e.maxBaseTokenAmount,e.baseTokenDecimals),swapMarketFee:await P(t,e.baseTokenAddress,e.swapMarketFee,e.baseTokenDecimals),marketFeeAddress:e.marketFeeAddress}}function F(e){e.allowedConsumer||(e.allowedConsumer=R);const a=e.withMint?1:0;return{fixedPriceAddress:e.fixedRateAddress,addresses:[e.baseTokenAddress,e.owner,e.marketFeeCollector,e.allowedConsumer],uints:[e.baseTokenDecimals,e.datatokenDecimals,t.utils.toWei(e.fixedRate),t.utils.toWei(e.marketFee),a]}}async function x(e,a){return{addresses:[a.ssContract,a.baseTokenAddress,a.baseTokenSender,a.publisherAddress,a.marketFeeCollector,a.poolTemplateAddress],ssParams:[t.utils.toWei(a.rate),a.baseTokenDecimals,t.utils.toWei(a.vestingAmount),a.vestedBlocks,await P(e,a.baseTokenAddress,a.initialBaseTokenLiquidity)],swapFees:[t.utils.toWei(a.swapFeeLiquidityProvider),t.utils.toWei(a.swapFeeMarketRunner)]}}async function O(t,a,s,i){try{const n=new t.eth.Contract(C,a);let o=i||await n.methods.decimals().call();"0"===o&&(o=18);const r=new e(s).div(new e(10).exponentiatedBy(o));return e.config({EXPONENTIAL_AT:50}),r.toString()}catch(t){f.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18' : ${t.message}`)}}async function P(t,a,s,i){try{const n=new t.eth.Contract(C,a);let o=i||await n.methods.decimals().call();return"0"===o&&(o=18),e.config({EXPONENTIAL_AT:50}),new e(s).times(new e(10).exponentiatedBy(o)).toFixed(0)}catch(t){f.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18', ${t.message}`)}}async function S(t,e,...a){let s=1e6;try{s=await e.apply(null,a).estimateGas({from:t},(t,e)=>t?1e6:e)}catch(t){f.error("ERROR: Estimate gas failed!",t)}return s}async function M(t,e){const s=await a(t,e);if(!s.ok)throw f.error(`Error requesting [${e.method}] ${t}`),f.error(`Response message: \n${await s.text()}`),s;return s}async function D(t){const e=(await a(t,{method:"HEAD"})).headers.get("content-disposition").split("=")[1],s=new XMLHttpRequest;s.responseType="blob",s.open("GET",t),s.onload=()=>{const t=window.URL.createObjectURL(s.response),a=document.createElement("a");a.href=t,a.setAttribute("download",e),document.body.appendChild(a),a.click(),a.remove(),window.URL.revokeObjectURL(t)},s.send(null)}async function U(t,e){const s=await a(t);if(!s.ok)throw new Error("Response error.");let i;try{i=s.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(a){try{i=t.split("/").pop()}catch(t){i=`file${e}`}}return{data:await s.arrayBuffer(),filename:i}}async function I(t){return a(t,{method:"GET",headers:{"Content-type":"application/json"}})}async function W(t,e){return async function(t,e,s){return a(t,null!=e?{method:"POST",body:e,headers:{"Content-type":"application/json"}}:{method:"POST"})}(t,e)}function N(){return N=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&(t[s]=a[s])}return t},N.apply(this,arguments)}const $={chainId:null,network:"unknown",metadataCacheUri:"https://v4.aquarius.oceanprotocol.com",nodeUri:"http://127.0.0.1:8545",providerUri:"http://127.0.0.1:8030",subgraphUri:null,explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",poolTemplateAddress:null,fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},G=[N({},$),N({},$,{chainId:8996,network:"development",metadataCacheUri:"http://127.0.0.1:5000",providerUri:"http://172.15.0.4:8030"}),N({},$,{chainId:3,network:"ropsten",nodeUri:"https://ropsten.infura.io/v3",providerUri:"https://v4.provider.ropsten.oceanprotocol.com",subgraphUri:"https://v4.subgraph.ropsten.oceanprotocol.com",explorerUri:"https://ropsten.etherscan.io",gasFeeMultiplier:1.1}),N({},$,{chainId:4,network:"rinkeby",nodeUri:"https://rinkeby.infura.io/v3",providerUri:"https://v4.provider.rinkeby.oceanprotocol.com",subgraphUri:"https://v4.subgraph.rinkeby.oceanprotocol.com",explorerUri:"https://rinkeby.etherscan.io",gasFeeMultiplier:1.1}),N({},$,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",providerUri:"https://v4.provider.mainnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.mainnet.oceanprotocol.com",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05}),N({},$,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",providerUri:"https://v4.provider.polygon.oceanprotocol.com",subgraphUri:"https://v4.subgraph.polygon.oceanprotocol.com",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN"}),N({},$,{chainId:1287,network:"moonbase",nodeUri:"https://rpc.api.moonbase.moonbeam.network",providerUri:"https://v4.provider.moonbase.oceanprotocol.com",subgraphUri:"https://v4.subgraph.moonbase.oceanprotocol.com",explorerUri:"https://moonbase.moonscan.io/",gasFeeMultiplier:1.1}),N({},$,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",providerUri:"https://v4.provider.gaiaxtestnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com"}),N({},$,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",providerUri:"https://v4.provider.mumbai.oceanprotocol.com",subgraphUri:"https://v4.subgraph.mumbai.oceanprotocol.com",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1}),N({},$,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",providerUri:"https://v4.provider.bsc.oceanprotocol.com",subgraphUri:"https://v4.subgraph.bsc.oceanprotocol.com",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05}),N({},$,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",providerUri:"https://v4.provider.energyweb.oceanprotocol.com",subgraphUri:"https://v4.subgraph.energyweb.oceanprotocol.com",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05}),N({},$,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",providerUri:"https://v4.provider.moonriver.oceanprotocol.com",subgraphUri:"https://v4.subgraph.moonriver.oceanprotocol.com",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05})];class B{getAddressesFromEnv(t,e){let a;if(e)try{const{FixedPrice:s,Dispenser:i,Staking:n,poolTemplate:o,ERC721Factory:r,OPFCommunityFeeCollector:c,Ocean:h,chainId:l,startBlock:d}=e[t];a=N({erc721FactoryAddress:r,sideStakingAddress:n,opfCommunityFeeCollector:c,poolTemplateAddress:o,fixedRateExchangeAddress:s,dispenserAddress:i,oceanTokenAddress:h,chainId:l,startBlock:d},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}catch(t){}else if(s[t]){const{FixedPrice:e,Dispenser:i,Staking:n,poolTemplate:o,OPFCommunityFeeCollector:r,ERC721Factory:c,Ocean:h,chainId:l,startBlock:d}=s[t];a=N({erc721FactoryAddress:c,sideStakingAddress:n,opfCommunityFeeCollector:r,poolTemplateAddress:o,fixedRateExchangeAddress:e,dispenserAddress:i,oceanTokenAddress:h,chainId:l,startBlock:d},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}return a}getConfig(t,e){const a="string"==typeof t?"network":"chainId";let s=G.find(e=>e[a]===t);return s?(s=N({},s,this.getAddressesFromEnv(s.network)),N({},s,{nodeUri:e?`${s.nodeUri}/${e}`:s.nodeUri})):(f.error(`No config found for given network '${t}'`),null)}}function L(e,a){return e=t.utils.toChecksumAddress(e),`did:op:${i(e+a.toString(10)).toString()}`}function j(t){try{return i(t).toString()}catch(t){f.error("getHash error: ",t.message)}}async function q(t,e,a){let s=await t.eth.sign(e,a);s=s.substr(2);const i="0x"+s.slice(0,64),n="0x"+s.slice(64,128);let o="0x"+s.slice(128,130);return"0x00"===o&&(o="0x1b"),"0x01"===o&&(o="0x1c"),{v:o,r:i,s:n}}async function z(t,e,a,s,i,n){return S(e,(n||new t.eth.Contract(C,a)).methods.approve,s,i)}async function _(t,e,a,s,i,o=!1,r){const c=new t.eth.Contract(C,a);if(!o){const o=await Z(t,a,e,s);if(new n(o).greaterThanOrEqualTo(new n(i)))return o}let h=null;const l=await P(t,a,i,r),d=await S(e,c.methods.approve,s,l);try{h=await c.methods.approve(s,l).send({from:e,gas:d+1,gasPrice:await T(t,null)})}catch(t){f.error(`ERROR: Failed to approve spender to spend tokens : ${t.message}`)}return h}async function J(t,a,s,i,n,o=!1){const r=new t.eth.Contract(C,s);if(!o){const o=await X(t,s,a,i);if(new e(o).gt(new e(n)))return o}let c=null;const h=await S(a,r.methods.approve,i,n);try{c=await r.methods.approve(i,n).send({from:a,gas:h+1,gasPrice:await T(t,null)})}catch(t){f.error(`ERROR: Failed to approve spender to spend tokens : ${t.message}`)}return c}async function H(t,e,a,s,i,n){return S(e,(n||new t.eth.Contract(C,a)).methods.transfer,s,i)}async function V(t,e,a,s,i){const n=new t.eth.Contract(C,a);let o=null;const r=await P(t,a,i),c=await S(e,n.methods.transfer,s,r);try{o=await n.methods.transfer(s,r).send({from:e,gas:c+1,gasPrice:await T(t,null)})}catch(t){f.error(`ERROR: Failed to transfer tokens : ${t.message}`)}return o}async function Z(t,e,a,s,i){const n=new t.eth.Contract(C,e),o=await n.methods.allowance(a,s).call();return await O(t,e,o,i)}async function X(t,e,a,s,i){const n=new t.eth.Contract(C,e);return await n.methods.allowance(a,s).call()}async function Q(t,e,a,s){const i=new t.eth.Contract(C,e),n=await i.methods.balanceOf(a).call();return await O(t,e,n,s)}async function K(t,e){const a=new t.eth.Contract(C,e);return await a.methods.decimals().call()}async function Y(t){return new Promise(e=>{setTimeout(e,t)})}function tt(t){return new n(t).div(2)}function et(t){return new n(t).div(2)}async function at(t,e,a){return tt(await t.getReserve(e,a))}async function st(t,e,a){return et(await t.getReserve(e,a))}async function it(t,e,a){return et(await t.getReserve(e,a))}async function nt(t,e,a){return et(await t.getReserve(e,a))}class ot{constructor(t){this.aquariusURL=void 0,this.aquariusURL=t}async resolve(t,e){const s=this.aquariusURL+"/api/aquarius/assets/ddo/"+t;try{const t=await a(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return await t.json();throw new Error("HTTP request failed with status "+t.status)}catch(t){throw f.error(t),new Error("HTTP request failed")}}async waitForAqua(t,e,s){let i=0;do{try{const i=this.aquariusURL+"/api/aquarius/assets/ddo/"+t,n=await a(i,{method:"GET",headers:{"Content-Type":"application/json"},signal:s});if(n.ok){const t=await n.json();if(!e)return t;if(t.event&&t.event.txid===e)return t}}catch(t){}await Y(1500),i++}while(i<100);return null}async validate(t,e){const s={valid:!1};let i;try{const n=this.aquariusURL+"/api/aquarius/assets/ddo/validate",o=await a(n,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:e});i=await o.json(),200===o.status?(s.valid=!0,s.hash=i.hash,s.proof={validatorAddress:i.publicKey,r:i.r[0],s:i.s[0],v:i.v}):(s.errors=i,f.error("validate Metadata failed:",o.status,s.errors))}catch(t){f.error("Error validating metadata: ",t)}return s}async getAssetMetadata(t,e){const s=this.aquariusURL+"/api/aquarius/assets/metadata/"+t;try{const t=await a(s,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return t.json();throw new Error("getAssetMetadata failed: "+t.status+t.statusText)}catch(t){throw f.error("Error getting metadata: ",t),new Error("Error getting metadata: "+t)}}async querySearch(t,e){const s=this.aquariusURL+"/api/aquarius/assets/query";try{const i=await a(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:e});if(i.ok)return i.json();throw new Error("querySearch failed: "+i.status+i.statusText)}catch(t){throw f.error("Error querying metadata: ",t),new Error("Error querying metadata: "+t)}}}const rt="115792089237316195423570985008687907853269984665640564039457584007913129639934";class ct{constructor(t,e,a=null,s){this.poolAbi=void 0,this.web3=void 0,this.config=void 0,this.poolAbi=a||o.abi,this.web3=t,this.config=s||(new B).getConfig(e||"unknown")}async amountToUnits(t,e,a){return P(this.web3,t,e,a)}async unitsToAmount(t,e,a){return O(this.web3,t,e,a)}async sharesBalance(t,e){let a=null;try{const s=k(new this.web3.eth.Contract(this.poolAbi,e),this.config),i=await s.methods.balanceOf(t).call();a=this.web3.utils.fromWei(i)}catch(t){f.error(`ERROR: Failed to get shares of pool : ${t.message}`)}return a}async estSetSwapFee(t,e,a,s){return S(t,(s||k(new this.web3.eth.Contract(r.abi,e),this.config)).methods.setSwapFee,a)}async setSwapFee(t,e,a){const s=k(new this.web3.eth.Contract(this.poolAbi,e,{from:t}),this.config);let i=null;const n=await S(t,s.methods.setSwapFee,a);try{i=await s.methods.setSwapFee(this.web3.utils.toWei(a)).send({from:t,gas:n,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to set pool swap fee: ${t.message}`)}return i}async getNumTokens(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getNumTokens().call()}catch(t){f.error(`ERROR: Failed to get number of tokens: ${t.message}`)}return a}async getPoolSharesTotalSupply(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{const t=await e.methods.totalSupply().call();a=this.web3.utils.fromWei(t)}catch(t){f.error(`ERROR: Failed to get total supply of pool shares: ${t.message}`)}return a}async getCurrentTokens(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getCurrentTokens().call()}catch(t){f.error(`ERROR: Failed to get tokens composing this pool: ${t.message}`)}return a}async getFinalTokens(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getFinalTokens().call()}catch(t){f.error(`ERROR: Failed to get the final tokens composing this pool ${t.message}`)}return a}async getController(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getController().call()}catch(t){f.error(`ERROR: Failed to get pool controller address: ${t.message}`)}return a}async getBaseToken(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getBaseTokenAddress().call()}catch(t){f.error(`ERROR: Failed to get baseToken address: ${t.message}`)}return a}async getDatatoken(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getDatatokenAddress().call()}catch(t){f.error(`ERROR: Failed to get datatoken address: ${t.message}`)}return a}async getMarketFee(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.getMarketFee().call()}catch(t){f.error(`ERROR: Failed to get getMarketFee: ${t.message}`)}return this.web3.utils.fromWei(a).toString()}async getMarketFeeCollector(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods._publishMarketCollector().call()}catch(t){f.error(`ERROR: Failed to get marketFeeCollector address: ${t.message}`)}return a}async isBound(t,e){const a=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let s=null;try{s=await a.methods.isBound(e).call()}catch(t){f.error(`ERROR: Failed to check whether a token bounded to a pool. ${t.message}`)}return s}async getReserve(t,e,a){let s=null;try{const i=k(new this.web3.eth.Contract(this.poolAbi,t),this.config),n=await i.methods.getBalance(e).call();s=await this.unitsToAmount(e,n,a)}catch(t){f.error(`ERROR: Failed to get how many tokens are in the pool: ${t.message}`)}return s.toString()}async isFinalized(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{a=await e.methods.isFinalized().call()}catch(t){f.error(`ERROR: Failed to check whether pool is finalized: ${t.message}`)}return a}async getSwapFee(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{const t=await e.methods.getSwapFee().call();a=this.web3.utils.fromWei(t)}catch(t){f.error(`ERROR: Failed to get pool fee: ${t.message}`)}return a}async getNormalizedWeight(t,e){const a=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let s=null;try{const t=await a.methods.getNormalizedWeight(e).call();s=this.web3.utils.fromWei(t)}catch(t){f.error(`ERROR: Failed to get normalized weight of a token: ${t.message}`)}return s}async getDenormalizedWeight(t,e){const a=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let s=null;try{const t=await a.methods.getDenormalizedWeight(e).call();s=this.web3.utils.fromWei(t)}catch(t){f.error(`ERROR: Failed to get denormalized weight of a token in pool ${t.message}`)}return s}async getTotalDenormalizedWeight(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let a=null;try{const t=await e.methods.getTotalDenormalizedWeight().call();a=this.web3.utils.fromWei(t)}catch(t){f.error(`ERROR: Failed to get total denormalized weight in pool ${t.message}`)}return a}async getMarketFees(t,e,a){const s=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let i=null;try{const t=await s.methods.publishMarketFees(e).call();i=await this.unitsToAmount(e,t,a)}catch(t){f.error(`ERROR: Failed to get market fees for a token: ${t.message}`)}return i}async getCurrentMarketFees(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);try{return await e.methods.getCurrentOPCFees().call()}catch(t){f.error(`ERROR: Failed to get community fees for a token: ${t.message}`)}}async getCurrentOPCFees(t){const e=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);try{return await e.methods.getCurrentOPCFees().call()}catch(t){f.error(`ERROR: Failed to get community fees for a token: ${t.message}`)}}async getCommunityFees(t,e,a){const s=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let i=null;try{const t=await s.methods.communityFees(e).call();i=await this.unitsToAmount(e,t,a)}catch(t){f.error(`ERROR: Failed to get community fees for a token: ${t.message}`)}return i}async estCollectOPC(t,e,a){return S(t,(a||k(new this.web3.eth.Contract(this.poolAbi,e),this.config)).methods.collectOPC)}async collectOPC(t,e){const a=k(new this.web3.eth.Contract(this.poolAbi,e),this.config);let s=null;const i=await S(t,a.methods.collectOPC);try{s=await a.methods.collectOPC().send({from:t,gas:i+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to swap exact amount in : ${t.message}`)}return s}async estCollectMarketFee(t,e,a){return S(t,(a||k(new this.web3.eth.Contract(this.poolAbi,e),this.config)).methods.collectMarketFee)}async collectMarketFee(t,e){if(await this.getMarketFeeCollector(e)!==t)throw new Error("Caller is not MarketFeeCollector");const a=k(new this.web3.eth.Contract(this.poolAbi,e),this.config);let s=null;const i=await S(t,a.methods.collectMarketFee);try{s=await a.methods.collectMarketFee().send({from:t,gas:i+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to swap exact amount in : ${t.message}`)}return s}async estUpdatePublishMarketFee(t,e,a,s,i){return S(t,(i||k(new this.web3.eth.Contract(this.poolAbi,e),this.config)).methods.updatePublishMarketFee,a,this.web3.utils.toWei(s))}async updatePublishMarketFee(t,e,a,s){if(await this.getMarketFeeCollector(e)!==t)throw new Error("Caller is not MarketFeeCollector");const i=k(new this.web3.eth.Contract(this.poolAbi,e),this.config);let n=null;const o=await S(t,i.methods.updatePublishMarketFee,a,this.web3.utils.toWei(s));try{n=await i.methods.updatePublishMarketFee(a,this.web3.utils.toWei(s)).send({from:t,gas:o+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to updatePublishMarketFee : ${t.message}`)}return n}async estSwapExactAmountIn(t,e,a,s,i){const n=i||k(new this.web3.eth.Contract(this.poolAbi,e),this.config),o=await this.amountToUnits(a.tokenIn,s.tokenAmountIn,a.tokenInDecimals),r=await this.amountToUnits(a.tokenOut,s.minAmountOut,a.tokenOutDecimals),c=s.maxPrice?this.amountToUnits(await this.getBaseToken(e),s.maxPrice):rt;return S(t,n.methods.swapExactAmountIn,[a.tokenIn,a.tokenOut,a.marketFeeAddress],[o,r,c,this.web3.utils.toWei(s.swapMarketFee)])}async swapExactAmountIn(t,e,a,s){const i=k(new this.web3.eth.Contract(this.poolAbi,e),this.config),o=await st(this,e,a.tokenIn);if(new n(s.tokenAmountIn).greaterThan(o))throw new Error(`tokenAmountIn is greater than ${o.toString()}`);const r=await this.amountToUnits(a.tokenIn,s.tokenAmountIn,a.tokenInDecimals),c=await this.amountToUnits(a.tokenOut,s.minAmountOut,a.tokenOutDecimals),h=s.maxPrice?await this.amountToUnits(await this.getBaseToken(e),s.maxPrice):rt,l=await S(t,i.methods.swapExactAmountIn,[a.tokenIn,a.tokenOut,a.marketFeeAddress],[r,c,h,this.web3.utils.toWei(s.swapMarketFee)]);let d=null;try{d=await i.methods.swapExactAmountIn([a.tokenIn,a.tokenOut,a.marketFeeAddress],[r,c,h,this.web3.utils.toWei(s.swapMarketFee)]).send({from:t,gas:l+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to swap exact amount in : ${t.message}`)}return d}async estSwapExactAmountOut(t,e,a,s,i){const n=i||k(new this.web3.eth.Contract(this.poolAbi,e),this.config),o=await this.amountToUnits(a.tokenIn,s.maxAmountIn,a.tokenInDecimals),r=await this.amountToUnits(a.tokenOut,s.tokenAmountOut,a.tokenOutDecimals),c=s.maxPrice?await this.amountToUnits(await this.getBaseToken(e),s.maxPrice):rt;return S(t,n.methods.swapExactAmountOut,[a.tokenIn,a.tokenOut,a.marketFeeAddress],[o,r,c,this.web3.utils.toWei(s.swapMarketFee)])}async swapExactAmountOut(t,e,a,s){const i=k(new this.web3.eth.Contract(this.poolAbi,e),this.config);let o=null;const r=await at(this,e,a.tokenOut);if(new n(s.tokenAmountOut).greaterThan(r))throw new Error(`tokenAmountOut is greater than ${r.toString()}`);const c=await this.amountToUnits(a.tokenIn,s.maxAmountIn,a.tokenInDecimals),h=await this.amountToUnits(a.tokenOut,s.tokenAmountOut,a.tokenOutDecimals),l=s.maxPrice?this.amountToUnits(await this.getBaseToken(e),s.maxPrice):rt,d=await S(t,i.methods.swapExactAmountOut,[a.tokenIn,a.tokenOut,a.marketFeeAddress],[c,h,l,this.web3.utils.toWei(s.swapMarketFee)]);try{o=await i.methods.swapExactAmountOut([a.tokenIn,a.tokenOut,a.marketFeeAddress],[c,h,l,this.web3.utils.toWei(s.swapMarketFee)]).send({from:t,gas:d+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to swap exact amount out: ${t.message}`)}return o}async estJoinswapExternAmountIn(t,e,a,s,i){return S(t,(i||k(new this.web3.eth.Contract(this.poolAbi,e),this.config)).methods.joinswapExternAmountIn,a,s)}async joinswapExternAmountIn(t,e,a,s,i){const o=k(new this.web3.eth.Contract(this.poolAbi,e),this.config);let r=null;const c=await this.getBaseToken(e),h=await it(this,e,c);if(new n(a).greaterThan(h))throw new Error(`tokenAmountOut is greater than ${h.toString()}`);const l=await this.amountToUnits(c,a,i),d=await S(t,o.methods.joinswapExternAmountIn,l,this.web3.utils.toWei(s));try{r=await o.methods.joinswapExternAmountIn(l,this.web3.utils.toWei(s)).send({from:t,gas:d+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to pay tokens in order to join the pool: ${t.message}`)}return r}async estExitswapPoolAmountIn(t,e,a,s,i){return S(t,(i||k(new this.web3.eth.Contract(this.poolAbi,e),this.config)).methods.exitswapPoolAmountIn,a,s)}async exitswapPoolAmountIn(t,e,a,s,i){const o=k(new this.web3.eth.Contract(this.poolAbi,e),this.config);let r=null;const c=await this.getBaseToken(e),h=await this.calcSingleOutGivenPoolIn(e,c,a),l=await nt(this,e,c);if(new n(h).greaterThan(l))throw new Error(`tokenAmountOut is greater than ${l.toString()}`);const d=await this.amountToUnits(await this.getBaseToken(e),s,i),w=await S(t,o.methods.exitswapPoolAmountIn,this.web3.utils.toWei(a),d);try{r=await o.methods.exitswapPoolAmountIn(this.web3.utils.toWei(a),d).send({from:t,gas:w+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to pay pool shares into the pool: ${t.message}`)}return r}async getSpotPrice(t,a,s,i){const n=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let o=18,c=18;const h=k(new this.web3.eth.Contract(r.abi,a),this.config),l=k(new this.web3.eth.Contract(r.abi,s),this.config);try{o=await h.methods.decimals().call()}catch(t){f.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${t.message}`)}try{c=await l.methods.decimals().call()}catch(t){f.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18 ${t.message}`)}let d,w=null;try{w=await n.methods.getSpotPrice(a,s,this.web3.utils.toWei(i)).call(),w=new e(w.toString())}catch(t){f.error("ERROR: Failed to get spot price of swapping tokenIn to tokenOut")}return o>c?(d=o-c,w=new e(w/10**d),w/=10**c):(d=c-o,w=new e(w*10**(2*d)),w/=10**c),w.toString()}async getAmountInExactOut(t,e,a,s,i,o,r){const c=k(new this.web3.eth.Contract(this.poolAbi,t),this.config),h=await at(this,t,a);if(new n(s).greaterThan(h))throw new Error(`tokenAmountOut is greater than ${h.toString()}`);const l=await this.amountToUnits(a,s,r);let d=null;try{const t=await c.methods.getAmountInExactOut(e,a,l,this.web3.utils.toWei(i)).call();d={tokenAmount:await this.unitsToAmount(a,t.tokenAmountIn,o),liquidityProviderSwapFeeAmount:await this.unitsToAmount(e,t.lpFeeAmount,o),oceanFeeAmount:await this.unitsToAmount(e,t.oceanFeeAmount,o),publishMarketSwapFeeAmount:await this.unitsToAmount(e,t.publishMarketSwapFeeAmount,o),consumeMarketSwapFeeAmount:await this.unitsToAmount(e,t.consumeMarketSwapFeeAmount,o)}}catch(t){f.error(`ERROR: Failed to calcInGivenOut ${t.message}`)}return d}async getAmountOutExactIn(t,e,a,s,i,o,r){const c=k(new this.web3.eth.Contract(this.poolAbi,t),this.config),h=await st(this,t,e);if(new n(s).greaterThan(h))throw new Error(`tokenAmountIn is greater than ${h.toString()}`);const l=await this.amountToUnits(e,s,o);let d=null;try{const t=await c.methods.getAmountOutExactIn(e,a,l,this.web3.utils.toWei(i)).call();d={tokenAmount:await this.unitsToAmount(a,t.tokenAmountOut,r),liquidityProviderSwapFeeAmount:await this.unitsToAmount(e,t.lpFeeAmount,o),oceanFeeAmount:await this.unitsToAmount(e,t.oceanFeeAmount,o),publishMarketSwapFeeAmount:await this.unitsToAmount(e,t.publishMarketSwapFeeAmount,o),consumeMarketSwapFeeAmount:await this.unitsToAmount(e,t.consumeMarketSwapFeeAmount,o)}}catch(t){f.error(`ERROR: Failed to calcOutGivenIn ${t.message}`)}return d}async calcPoolOutGivenSingleIn(t,e,a,s,i){const n=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let o=null;try{const r=await n.methods.calcPoolOutSingleIn(e,await this.amountToUnits(e,a,i)).call();o=await this.unitsToAmount(t,r,s)}catch(t){f.error(`ERROR: Failed to calculate PoolOutGivenSingleIn : ${t.message}`)}return o}async calcSingleInGivenPoolOut(t,e,a,s,i){const n=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let o=null;const r=await this.amountToUnits(t,a,s);try{const t=await n.methods.calcSingleInPoolOut(e,r).call();o=await this.unitsToAmount(e,t,i)}catch(t){f.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${t.message}`)}return o}async calcSingleOutGivenPoolIn(t,e,a,s,i){const n=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let o=null;try{const r=await n.methods.calcSingleOutPoolIn(e,await this.amountToUnits(t,a,s)).call();o=await this.unitsToAmount(e,r,i)}catch(t){f.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${t}`)}return o}async calcPoolInGivenSingleOut(t,e,a,s,i){const n=k(new this.web3.eth.Contract(this.poolAbi,t),this.config);let o=null;try{const r=await n.methods.calcPoolInSingleOut(e,await this.amountToUnits(e,a,i)).call();o=await this.unitsToAmount(t,r,s)}catch(t){f.error(`ERROR: Failed to calculate PoolInGivenSingleOut : ${t.message}`)}return o}getSwapEventSignature(){const t=this.poolAbi.find(({name:t,type:e})=>"event"===e&&"LOG_SWAP"===t);return this.web3.eth.abi.encodeEventSignature(t)}getJoinEventSignature(){const t=this.poolAbi.find(({name:t,type:e})=>"event"===e&&"LOG_JOIN"===t);return this.web3.eth.abi.encodeEventSignature(t)}getExitEventSignature(){const t=this.poolAbi.find(({name:t,type:e})=>"event"===e&&"LOG_EXIT"===t);return this.web3.eth.abi.encodeEventSignature(t)}}class ht{constructor(t,e,a=null,s=null,i){this.web3=null,this.dispenserAddress=void 0,this.config=void 0,this.dispenserAbi=void 0,this.dispenserContract=void 0,this.web3=t,this.dispenserAddress=a,this.dispenserAbi=s||c.abi,this.config=i||(new B).getConfig(e||"unknown"),t&&(this.dispenserContract=k(new this.web3.eth.Contract(this.dispenserAbi,this.dispenserAddress),this.config))}async status(t){try{const e=await this.dispenserContract.methods.status(t).call();return e.maxTokens=this.web3.utils.fromWei(e.maxTokens),e.maxBalance=this.web3.utils.fromWei(e.maxBalance),e.balance=this.web3.utils.fromWei(e.balance),e}catch(e){f.warn(`No dispenser available for datatoken: ${t}`)}return null}async estGasCreate(t,e,a,s,i){return S(e,this.dispenserContract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(s),e,i)}async create(t,e,a,s,i){const n=await S(e,this.dispenserContract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(s),e,i);return await this.dispenserContract.methods.create(t,this.web3.utils.toWei(a),this.web3.utils.toWei(s),e,i).send({from:e,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estGasActivate(t,e,a,s){return S(s,this.dispenserContract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a))}async activate(t,e,a,s){try{const i=await S(s,this.dispenserContract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a));return await this.dispenserContract.methods.activate(t,this.web3.utils.toWei(e),this.web3.utils.toWei(a)).send({from:s,gas:i+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to activate dispenser: ${t.message}`)}return null}async estGasDeactivate(t,e){return S(e,this.dispenserContract.methods.deactivate,t)}async deactivate(t,e){try{const a=await S(e,this.dispenserContract.methods.deactivate,t);return await this.dispenserContract.methods.deactivate(t).send({from:e,gas:a+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to activate dispenser: ${t.message}`)}return null}async estGasSetAllowedSwapper(t,e,a){return S(e,this.dispenserContract.methods.setAllowedSwapper,t,a)}async setAllowedSwapper(t,e,a){try{const s=await S(e,this.dispenserContract.methods.setAllowedSwapper,t,a);return await this.dispenserContract.methods.setAllowedSwapper(t,a).send({from:e,gas:s+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to activate dispenser: ${t.message}`)}return null}async estGasDispense(t,e,a="1",s){return S(e,this.dispenserContract.methods.dispense,t,this.web3.utils.toWei(a),s)}async dispense(t,e,a="1",s){const i=await S(e,this.dispenserContract.methods.dispense,t,this.web3.utils.toWei(a),s);try{return await this.dispenserContract.methods.dispense(t,this.web3.utils.toWei(a),s).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to dispense tokens: ${t.message}`)}return null}async estGasOwnerWithdraw(t,e){return S(e,this.dispenserContract.methods.ownerWithdraw,t)}async ownerWithdraw(t,e){const a=await S(e,this.dispenserContract.methods.ownerWithdraw,t);try{return await this.dispenserContract.methods.ownerWithdraw(t).send({from:e,gas:a+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error(`ERROR: Failed to withdraw tokens: ${t.message}`)}return null}async isDispensable(t,e,a,s="1"){const i=await this.status(t);return!(!i||!1===i.active||new n(await e.balance(t,a)).greaterThanOrEqualTo(i.maxBalance)||new n(String(s)).greaterThan(i.maxTokens)||!new n(i.balance).greaterThanOrEqualTo(s)&&!0!==i.isMinter)}}var lt;!function(t){t[t.CreatingExchange=0]="CreatingExchange",t[t.ApprovingDatatoken=1]="ApprovingDatatoken"}(lt||(lt={}));class dt{constructor(t,e,a,s=null,i=null,n){this.oceanAddress=null,this.fixedRateAddress=void 0,this.fixedRateExchangeAbi=void 0,this.web3=void 0,this.fixedRateContract=null,this.config=void 0,this.ssAbi=void 0,this.web3=t,this.config=n||(new B).getConfig(a||"unknown"),this.fixedRateExchangeAbi=s||h.abi,this.oceanAddress=i,this.fixedRateAddress=e,this.fixedRateContract=k(new this.web3.eth.Contract(this.fixedRateExchangeAbi,this.fixedRateAddress),this.config)}async amountToUnits(t,e,a){return P(this.web3,t,e,a)}async unitsToAmount(t,e,a){return O(this.web3,t,e,a)}async generateExchangeId(t,e){return await this.fixedRateContract.methods.generateExchangeId(t,e).call()}async estBuyDT(t,e,a,s,i,n,o){return S(t,(o||this.fixedRateContract).methods.buyDT,e,a,s,i,n)}async buyDT(t,e,a,s,i=R,n="0"){const o=await this.getExchange(e),r=this.web3.utils.toWei(n),c=await this.amountToUnits(o.datatoken,a,+o.dtDecimals),h=await this.amountToUnits(o.baseToken,s,+o.btDecimals),l=await S(t,this.fixedRateContract.methods.buyDT,e,c,h,i,r);try{return await this.fixedRateContract.methods.buyDT(e,c,h,i,r).send({from:t,gas:l+1,gasPrice:await T(this.web3,this.config)})}catch(t){return f.error(`ERROR: Failed to buy datatokens: ${t.message}`),null}}async estSellDT(t,e,a,s,i,n,o){return S(t,(o||this.fixedRateContract).methods.sellDT,e,a,s,i,n)}async sellDT(t,e,a,s,i=R,n="0"){const o=await this.getExchange(e),r=this.web3.utils.toWei(n),c=await this.amountToUnits(o.datatoken,a,+o.dtDecimals),h=await this.amountToUnits(o.baseToken,s,+o.btDecimals),l=await S(t,this.fixedRateContract.methods.sellDT,e,c,h,i,r);try{return await this.fixedRateContract.methods.sellDT(e,c,h,i,r).send({from:t,gas:l+1,gasPrice:await T(this.web3,this.config)})}catch(t){return f.error(`ERROR: Failed to sell datatokens: ${t.message}`),null}}async getNumberOfExchanges(){return await this.fixedRateContract.methods.getNumberOfExchanges().call()}async estSetRate(t,e,a,s){return S(t,(s||this.fixedRateContract).methods.setRate,e,await this.web3.utils.toWei(a))}async setRate(t,e,a){const s=await S(t,this.fixedRateContract.methods.setRate,e,this.web3.utils.toWei(a));return await this.fixedRateContract.methods.setRate(e,this.web3.utils.toWei(a)).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estSetAllowedSwapper(t,e,a,s){return S(t,(s||this.fixedRateContract).methods.setAllowedSwapper,e,a)}async setAllowedSwapper(t,e,a){const s=await S(t,this.fixedRateContract.methods.setAllowedSwapper,e,a);return await this.fixedRateContract.methods.setAllowedSwapper(e,a).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estActivate(t,e,a){return S(t,(a||this.fixedRateContract).methods.toggleExchangeState,e)}async activate(t,e){const a=await this.getExchange(e);if(!a)return null;if(!0===a.active)return null;const s=await S(t,this.fixedRateContract.methods.toggleExchangeState,e);return await this.fixedRateContract.methods.toggleExchangeState(e).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estDeactivate(t,e,a){return S(t,(a||this.fixedRateContract).methods.toggleExchangeState,e)}async deactivate(t,e){const a=await this.getExchange(e);if(!a)return null;if(!1===a.active)return null;const s=await S(t,this.fixedRateContract.methods.toggleExchangeState,e);return await this.fixedRateContract.methods.toggleExchangeState(e).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async getRate(t){const e=await this.fixedRateContract.methods.getRate(t).call();return await this.web3.utils.fromWei(e)}async getDTSupply(t){const e=await this.fixedRateContract.methods.getDTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.datatoken,e,+a.dtDecimals)}async getBTSupply(t){const e=await this.fixedRateContract.methods.getBTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.baseToken,e,+a.btDecimals)}async getAllowedSwapper(t){return await this.fixedRateContract.methods.getAllowedSwapper(t).call()}async calcBaseInGivenOutDT(t,e,a="0"){const s=await this.getExchange(t),i=await this.fixedRateContract.methods.calcBaseInGivenOutDT(t,await this.amountToUnits(s.datatoken,e,+s.dtDecimals),this.web3.utils.toWei(a)).call();return{baseTokenAmount:await this.unitsToAmount(s.baseToken,i.baseTokenAmount,+s.btDecimals),marketFeeAmount:await this.unitsToAmount(s.baseToken,i.marketFeeAmount,+s.btDecimals),oceanFeeAmount:await this.unitsToAmount(s.baseToken,i.oceanFeeAmount,+s.btDecimals),consumeMarketFeeAmount:await this.unitsToAmount(s.baseToken,i.consumeMarketFeeAmount,+s.btDecimals)}}async getAmountBTOut(t,e,a="0"){const s=await this.getExchange(t),i=await this.fixedRateContract.methods.calcBaseOutGivenInDT(t,await this.amountToUnits(s.datatoken,e,+s.dtDecimals),this.web3.utils.toWei(a)).call();return await this.unitsToAmount(s.baseToken,i[0],+s.btDecimals)}async getExchange(t){const e=await this.fixedRateContract.methods.getExchange(t).call();return e.dtDecimals=e.dtDecimals.toString(),e.btDecimals=e.btDecimals.toString(),e.dtBalance=await this.unitsToAmount(e.datatoken,e.dtBalance,+e.dtDecimals),e.btBalance=await this.unitsToAmount(e.baseToken,e.btBalance,+e.btDecimals),e.dtSupply=await this.unitsToAmount(e.datatoken,e.dtSupply,+e.dtDecimals),e.btSupply=await this.unitsToAmount(e.baseToken,e.btSupply,+e.btDecimals),e.fixedRate=this.web3.utils.fromWei(e.fixedRate),e.exchangeId=t,e}async getFeesInfo(t){const e=await this.fixedRateContract.methods.getFeesInfo(t).call();e.opcFee=this.web3.utils.fromWei(e.opcFee.toString()),e.marketFee=this.web3.utils.fromWei(e.marketFee.toString());const a=await this.getExchange(t);return e.marketFeeAvailable=await this.unitsToAmount(a.baseToken,e.marketFeeAvailable,+a.btDecimals),e.oceanFeeAvailable=await this.unitsToAmount(a.baseToken,e.oceanFeeAvailable,+a.btDecimals),e.exchangeId=t,e}async getExchanges(){return await this.fixedRateContract.methods.getExchanges().call()}async isActive(t){return await this.fixedRateContract.methods.isActive(t).call()}async estActivateMint(t,e,a){return S(t,(a||this.fixedRateContract).methods.toggleMintState,e,!0)}async activateMint(t,e){const a=await this.getExchange(e);if(!a)return null;if(!0===a.withMint)return null;const s=await S(t,this.fixedRateContract.methods.toggleMintState,e,!0);return await this.fixedRateContract.methods.toggleMintState(e,!0).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estDeactivateMint(t,e,a){return S(t,(a||this.fixedRateContract).methods.toggleMintState(e,!1),e,!1)}async deactivateMint(t,e){const a=await this.getExchange(e);if(!a)return null;if(!1===a.withMint)return null;const s=await S(t,this.fixedRateContract.methods.toggleMintState,e,!1);return await this.fixedRateContract.methods.toggleMintState(e,!1).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estCollectBT(t,e,a,s){const i=s||this.fixedRateContract,n=await this.fixedRateContract.methods.getExchange(e).call(),o=await this.amountToUnits(n.baseToken,a,+n.btDecimals);return S(t,i.methods.collectBT,e,o)}async collectBT(t,e,a){if(!await this.getExchange(e))return null;const s=await this.fixedRateContract.methods.getExchange(e).call(),i=await this.amountToUnits(s.baseToken,a,+s.btDecimals),n=await S(t,this.fixedRateContract.methods.collectBT,e,i);return await this.fixedRateContract.methods.collectBT(e,i).send({from:t,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estCollectDT(t,e,a,s){const i=s||this.fixedRateContract,n=await this.fixedRateContract.methods.getExchange(e).call(),o=await this.amountToUnits(n.datatoken,a,+n.dtDecimals);return S(t,i.methods.collectDT,e,o)}async collectDT(t,e,a){if(!await this.getExchange(e))return null;const s=await this.fixedRateContract.methods.getExchange(e).call(),i=await this.amountToUnits(s.datatoken,a,+s.dtDecimals),n=await S(t,this.fixedRateContract.methods.collectDT,e,i);return await this.fixedRateContract.methods.collectDT(e,i).send({from:t,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estCollectMarketFee(t,e,a){return S(t,(a||this.fixedRateContract).methods.collectMarketFee,e)}async collectMarketFee(t,e){if(!await this.getExchange(e))return null;const a=await S(t,this.fixedRateContract.methods.collectMarketFee,e);return await this.fixedRateContract.methods.collectMarketFee(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estCollectOceanFee(t,e,a){return S(t,(a||this.fixedRateContract).methods.collectMarketFee,e)}async collectOceanFee(t,e){if(!await this.getExchange(e))return null;const a=await S(t,this.fixedRateContract.methods.collectOceanFee,e);return await this.fixedRateContract.methods.collectOceanFee(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async getOPCCollector(){let t=null;try{t=await this.fixedRateContract.methods.opcCollector().call()}catch(t){f.error(`ERROR: Failed to get OPC Collector address: ${t.message}`)}return t}async getRouter(){let t=null;try{t=await this.fixedRateContract.methods.router().call()}catch(t){f.error(`ERROR: Failed to get Router address: ${t.message}`)}return t}async getExchangeOwner(t){let e=null;try{e=await(await this.getExchange(t)).exchangeOwner}catch(t){f.error(`ERROR: Failed to get OPF Collector address: ${t.message}`)}return e}async estUpdateMarketFee(t,e,a,s){return S(t,(s||this.fixedRateContract).methods.updateMarketFee,e,a)}async updateMarketFee(t,e,a){const s=await S(t,this.fixedRateContract.methods.updateMarketFee,e,this.web3.utils.toWei(a));return await this.fixedRateContract.methods.updateMarketFee(e,this.web3.utils.toWei(a)).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estUpdateMarketFeeCollector(t,e,a,s){return S(t,(s||this.fixedRateContract).methods.updateMarketFeeCollector,e,a)}async updateMarketFeeCollector(t,e,a){const s=await S(t,this.fixedRateContract.methods.updateMarketFeeCollector,e,a);return await this.fixedRateContract.methods.updateMarketFeeCollector(e,a).send({from:t,gas:s+1,gasPrice:await T(this.web3,this.config)})}}class wt{constructor(t,e,a=null,s){this.ssAbi=void 0,this.web3=void 0,this.config=void 0,this.ssAbi=a||l.abi,this.web3=t,this.config=s||(new B).getConfig(e||"unknown")}async unitsToAmount(t,e,a){return O(this.web3,t,e,a)}async getDatatokenCirculatingSupply(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getDatatokenCirculatingSupply(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s.toString()}async getDatatokenCurrentCirculatingSupply(t,e){try{const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;return s=await a.methods.getDatatokenCurrentCirculatingSupply(e).call(),s.toString()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}}async getPublisherAddress(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getPublisherAddress(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s}async getBaseToken(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getBaseTokenAddress(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s}async getPoolAddress(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getPoolAddress(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s}async getBaseTokenBalance(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getBaseTokenBalance(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s}async getDatatokenBalance(t,e,a){const s=new this.web3.eth.Contract(this.ssAbi,t);let i=null;try{i=await s.methods.getDatatokenBalance(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return i=await this.unitsToAmount(e,i,a),i}async getvestingEndBlock(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getvestingEndBlock(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s}async getvestingAmount(t,e,a){const s=new this.web3.eth.Contract(this.ssAbi,t);let i=null;try{i=await s.methods.getvestingAmount(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return i=await this.unitsToAmount(e,i,a),i}async getvestingLastBlock(t,e){const a=new this.web3.eth.Contract(this.ssAbi,t);let s=null;try{s=await a.methods.getvestingLastBlock(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return s}async getvestingAmountSoFar(t,e,a){const s=new this.web3.eth.Contract(this.ssAbi,t);let i=null;try{i=await s.methods.getvestingAmountSoFar(e).call()}catch(t){f.error(`ERROR: Failed to get: ${t.message}`)}return i=await this.unitsToAmount(e,i,a),i}async estGetVesting(t,e,a,s){return S(t,(s||new this.web3.eth.Contract(this.ssAbi,e)).methods.getVesting,a)}async getVesting(t,e,a){const s=new this.web3.eth.Contract(this.ssAbi,e);let i=null;const n=await S(t,s.methods.getVesting,a);try{i=await s.methods.getVesting(a).send({from:t,gas:n+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error("ERROR: Failed to join swap pool amount out")}return i}async estSetPoolSwapFee(t,e,a,s,i,n){return S(t,(n||new this.web3.eth.Contract(this.ssAbi,e)).methods.setPoolSwapFee,a,s,i)}async setPoolSwapFee(t,e,a,s,i){const n=new this.web3.eth.Contract(this.ssAbi,e);let o=null;const r=await S(t,n.methods.setPoolSwapFee,a,s,i);try{o=await n.methods.setPoolSwapFee(a,s,i).send({from:t,gas:r+1,gasPrice:await T(this.web3,this.config)})}catch(t){f.error("ERROR: Failed to join swap pool amount out")}return o}async getRouter(t){const e=new this.web3.eth.Contract(this.ssAbi,t);let a=null;try{a=await e.methods.router().call()}catch(t){f.error(`ERROR: Failed to get Router address: ${t.message}`)}return a}}class ut{constructor(t,e,a,s,i){this.routerAddress=void 0,this.RouterAbi=void 0,this.web3=void 0,this.config=void 0,this.router=void 0,this.routerAddress=t,this.RouterAbi=s||d.abi,this.web3=e,this.config=i||(new B).getConfig(a||"unknown"),this.router=k(new this.web3.eth.Contract(this.RouterAbi,this.routerAddress),this.config)}async estGasBuyDTBatch(t,e){return S(t,this.router.methods.buyDTBatch,e)}async buyDTBatch(t,e){const a=await S(t,this.router.methods.buyDTBatch,e);return await this.router.methods.buyDTBatch(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async isApprovedToken(t){return await this.router.methods.isApprovedToken(t).call()}async isSideStaking(t){return await this.router.methods.isSSContract(t).call()}async isFixedPrice(t){return await this.router.methods.isFixedRateContract(t).call()}async getOwner(){return await this.router.methods.routerOwner().call()}async getNFTFactory(){return await this.router.methods.factory().call()}async isPoolTemplate(t){return await this.router.methods.isPoolTemplate(t).call()}async estGasAddApprovedToken(t,e,a){return S(t,this.router.methods.addApprovedToken,e)}async addApprovedToken(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.addApprovedToken,e);return await this.router.methods.addApprovedToken(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveApprovedToken(t,e,a){return S(t,this.router.methods.removeApprovedToken,e)}async removeApprovedToken(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.removeApprovedToken,e);return await this.router.methods.removeApprovedToken(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasAddSSContract(t,e){return S(t,this.router.methods.addSSContract,e)}async addSSContract(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.addSSContract,e);return await this.router.methods.addSSContract(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveSSContract(t,e){return S(t,this.router.methods.removeSSContract,e)}async removeSSContract(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.removeSSContract,e);return await this.router.methods.removeSSContract(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasAddFixedRateContract(t,e){return S(t,this.router.methods.addFixedRateContract,e)}async addFixedRateContract(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.addFixedRateContract,e);return await this.router.methods.addFixedRateContract(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveFixedRateContract(t,e){return S(t,this.router.methods.removeFixedRateContract,e)}async removeFixedRateContract(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.removeFixedRateContract,e);return await this.router.methods.removeFixedRateContract(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasAddDispenserContract(t,e){return S(t,this.router.methods.addDispenserContract,e)}async addDispenserContract(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.addDispenserContract,e);return await this.router.methods.addDispenserContract(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveDispenserContract(t,e){return S(t,this.router.methods.removeDispenserContract,e)}async removeDispenserContract(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.removeDispenserContract,e);return await this.router.methods.removeDispenserContract(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async getOPCFee(t){return await this.router.methods.getOPCFee(t).call()}async getCurrentOPCFee(){return await this.router.methods.swapOceanFee().call()}async estGasUpdateOPCFee(t,e,a,s,i){return S(t,this.router.methods.updateOPCFee,e,a,s,i)}async updateOPCFee(t,e,a,s,i){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await S(t,this.router.methods.updateOPCFee,e,a,s,i);return await this.router.methods.updateOPCFee(e,a,s,i).send({from:t,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estGasAddPoolTemplate(t,e){return S(t,this.router.methods.addPoolTemplate,e)}async addPoolTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.addPoolTemplate,e);return await this.router.methods.addPoolTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasRemovePoolTemplate(t,e){return S(t,this.router.methods.removePoolTemplate,e)}async removePoolTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const a=await S(t,this.router.methods.removePoolTemplate,e);return await this.router.methods.removePoolTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}}class mt{constructor(t,e,a,s){this.factory721Address=void 0,this.factory721Abi=void 0,this.nftAbi=void 0,this.web3=void 0,this.startBlock=void 0,this.config=void 0,this.nftAbi=a||u.abi,this.web3=t,this.config=s||(new B).getConfig(e||"unknown")}async estGasCreateErc20(t,e,a,s,i,n,o,r,c,h,l,d){return S(e,(d||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.createERC20,l,[c,h],[a,s,i,n],[this.web3.utils.toWei(r),this.web3.utils.toWei(o)],[])}async createErc20(t,e,a,s,i,n,o,r,c,h,l){if(!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not ERC20Deployer");l||(l=1),c&&h||({name:c,symbol:h}=y());const d=k(new this.web3.eth.Contract(this.nftAbi,t),this.config),w=await S(e,d.methods.createERC20,l,[c,h],[a,s,i,n],[this.web3.utils.toWei(r),this.web3.utils.toWei(o)],[]),u=await d.methods.createERC20(l,[c,h],[a,s,i,n],[this.web3.utils.toWei(r),this.web3.utils.toWei(o)],[]).send({from:e,gas:w+1,gasPrice:await T(this.web3,this.config)});let m=null;try{m=u.events.TokenCreated.returnValues[0]}catch(t){f.error(`ERROR: Failed to create datatoken : ${t.message}`)}return m}async estGasAddManager(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.addManager,a)}async addManager(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const i=await S(e,s.methods.addManager,a);return await s.methods.addManager(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveManager(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.removeManager,a)}async removeManager(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const i=await S(e,s.methods.removeManager,a);return await s.methods.removeManager(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasAddErc20Deployer(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.addToCreateERC20List,a)}async addErc20Deployer(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const i=await S(e,s.methods.addToCreateERC20List,a);return await s.methods.addToCreateERC20List(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveErc20Deployer(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.removeFromCreateERC20List,a)}async removeErc20Deployer(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!0!==(await this.getNftPermissions(t,e)).manager||e===a&&!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not Manager nor ERC20Deployer");const i=await S(e,s.methods.removeFromCreateERC20List,a);return await s.methods.removeFromCreateERC20List(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasAddMetadataUpdater(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.addToMetadataList,a)}async addMetadataUpdater(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const i=await S(e,s.methods.addToMetadataList,a);return await s.methods.addToMetadataList(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async esGasRemoveMetadataUpdater(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.removeFromMetadataList,a)}async removeMetadataUpdater(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");const i=await this.esGasRemoveMetadataUpdater(t,e,a,s);return await s.methods.removeFromMetadataList(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasAddStoreUpdater(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.addTo725StoreList,a)}async addStoreUpdater(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const i=await S(e,s.methods.addTo725StoreList,a);return await s.methods.addTo725StoreList(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveStoreUpdater(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.removeFrom725StoreList,a)}async removeStoreUpdater(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).store)throw new Error("Caller is not Manager nor storeUpdater");const i=await S(e,s.methods.removeFrom725StoreList,a);return await s.methods.removeFrom725StoreList(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasCleanPermissions(t,e,a){return S(e,(a||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.cleanPermissions)}async cleanPermissions(t,e){const a=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const s=await S(e,a.methods.cleanPermissions);return await a.methods.cleanPermissions().send({from:e,gas:s+1,gasPrice:await T(this.web3,this.config)})}async estGasTransferNft(t,e,a,s,i){return S(e,(i||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.transferFrom,e,a,s)}async transferNft(t,e,a,s){const i=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const n=s||1,o=await S(e,i.methods.transferFrom,e,a,n);return await i.methods.transferFrom(e,a,n).send({from:e,gas:o+1,gasPrice:await T(this.web3,this.config)})}async estGasSafeTransferNft(t,e,a,s,i){return S(e,(i||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.safeTransferFrom,e,a,s)}async safeTransferNft(t,e,a,s){const i=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const n=s||1,o=await S(e,i.methods.safeTransferFrom,e,a,n);return await i.methods.safeTransferFrom(e,a,n).send({from:e,gas:o+1,gasPrice:await T(this.web3,this.config)})}async estGasSetMetadata(t,e,a,s,i,n,o,r,c,h){return c||(c=[]),S(e,(h||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.setMetaData,a,s,i,n,o,r,c)}async setMetadata(t,e,a,s,i,n,o,r,c){const h=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(c||(c=[]),!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const l=await S(e,h.methods.setMetaData,a,s,i,n,o,r,c);return await h.methods.setMetaData(a,s,i,n,o,r,c).send({from:e,gas:l+1,gasPrice:await T(this.web3,this.config)})}async estGasSetMetadataAndTokenURI(t,e,a,s){const i=s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config),n=N({},a,{metadataProofs:a.metadataProofs||[]});return S(e,i.methods.setMetaDataAndTokenURI,n)}async setMetadataAndTokenURI(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const i=N({},a,{metadataProofs:a.metadataProofs||[]}),n=await S(e,s.methods.setMetaDataAndTokenURI,i);return await s.methods.setMetaDataAndTokenURI(i).send({from:e,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estGasSetMetadataState(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.nftAbi,t),this.config)).methods.setMetaDataState,a)}async setMetadataState(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const i=await S(e,s.methods.setMetaDataState,a);return await s.methods.setMetaDataState(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estSetTokenURI(t,e,a){return S(e,k(new this.web3.eth.Contract(this.nftAbi,t),this.config).methods.setTokenURI,"1",a)}async setTokenURI(t,e,a){const s=k(new this.web3.eth.Contract(this.nftAbi,t),this.config),i=await S(e,s.methods.setTokenURI,"1",a);return await s.methods.setTokenURI("1",a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async setData(t,e,a,s){if(!0!==(await this.getNftPermissions(t,e)).store)throw new Error("User is not ERC20 store updater");const i=k(new this.web3.eth.Contract(this.nftAbi,t),this.config),n=this.web3.utils.keccak256(a),o=this.web3.utils.asciiToHex(s),r=await S(e,i.methods.setNewData,n,o);return await i.methods.setNewData(n,o).send({from:e,gas:r+1,gasPrice:await T(this.web3,this.config)})}async getNftOwner(t){const e=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);return await e.methods.ownerOf(1).call()}async getNftPermissions(t,e){const a=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);return await a.methods.getPermissions(e).call()}async getMetadata(t){const e=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);return await e.methods.getMetaData().call()}async isErc20Deployer(t,e){const a=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);return await a.methods.isERC20Deployer(e).call()}async getData(t,e){const a=k(new this.web3.eth.Contract(this.nftAbi,t),this.config),s=this.web3.utils.keccak256(e),i=await a.methods.getData(s).call();return i?this.web3.utils.hexToAscii(i):null}async getTokenURI(t,e){const a=k(new this.web3.eth.Contract(this.nftAbi,t),this.config);return await a.methods.tokenURI(e).call()}}class gt{constructor(t,e,a,s,i){this.factoryAddress=void 0,this.factoryABI=void 0,this.datatokensAbi=void 0,this.datatokensEnterpriseAbi=void 0,this.web3=void 0,this.config=void 0,this.nft=void 0,this.web3=t,this.datatokensAbi=a||r.abi,this.datatokensEnterpriseAbi=s||w.abi,this.config=i||(new B).getConfig(e||"unknown"),this.nft=new mt(this.web3)}async estGasApprove(t,e,a,s,i){return S(s,(i||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.approve,e,this.web3.utils.toWei(a))}async approve(t,e,a,s){const i=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config),n=await S(s,i.methods.approve,e,this.web3.utils.toWei(a));return await i.methods.approve(e,this.web3.utils.toWei(a)).send({from:s,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estGasMint(t,e,a,s,i){return S(e,(i||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.mint,s||e,this.web3.utils.toWei(a))}async estGasCreateFixedRate(t,e,a,s){const i=s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return a.allowedConsumer||(a.allowedConsumer=R),S(e,i.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,e,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,a.withMint?1:0])}async createFixedRate(t,e,a){const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);if(!await this.isERC20Deployer(t,e))throw new Error("User is not ERC20 Deployer");a.allowedConsumer||(a.allowedConsumer=R);const i=a.withMint?1:0,n=await S(e,s.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,i]);return await s.methods.createFixedRate(a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,i]).send({from:e,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estGasCreateDispenser(t,e,a,s,i){const n=i||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return s.allowedSwapper||(s.allowedSwapper=R),s.withMint||(s.withMint=!1),S(e,n.methods.createDispenser,a,s.maxTokens,s.maxBalance,s.withMint,s.allowedSwapper)}async createDispenser(t,e,a,s){if(!await this.isERC20Deployer(t,e))throw new Error("User is not ERC20 Deployer");const i=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);s.allowedSwapper||(s.allowedSwapper=R),s.withMint||(s.withMint=!1);const n=await S(e,i.methods.createDispenser,a,s.maxTokens,s.maxBalance,s.withMint,s.allowedSwapper);return await i.methods.createDispenser(a,s.maxTokens,s.maxBalance,s.withMint,s.allowedSwapper).send({from:e,gas:n+1,gasPrice:await T(this.web3,this.config)})}async mint(t,e,a,s){const i=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);if(!0!==(await this.getDTPermissions(t,e)).minter)throw new Error("Caller is not Minter");const o=await this.getCap(t);if(new n(o).gte(a)){const t=await S(e,i.methods.mint,s||e,this.web3.utils.toWei(a));return await i.methods.mint(s||e,this.web3.utils.toWei(a)).send({from:e,gas:t+1,gasPrice:await T(this.web3,this.config)})}throw new Error("Mint amount exceeds cap available")}async estGasAddMinter(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.addMinter,a)}async addMinter(t,e,a){const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);if(!0!==await this.isERC20Deployer(t,e))throw new Error("Caller is not ERC20Deployer");const i=await S(e,s.methods.addMinter,a);return await s.methods.addMinter(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasRemoveMinter(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.removeMinter,a)}async removeMinter(t,e,a){const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);if(!0!==await this.isERC20Deployer(t,e))throw new Error("Caller is not ERC20Deployer");const i=await S(e,s.methods.removeMinter,a);return await s.methods.removeMinter(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasAddPaymentManager(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.addPaymentManager,a)}async addPaymentManager(t,e,a){const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);if(!0!==await this.isERC20Deployer(t,e))throw new Error("Caller is not ERC20Deployer");const i=await S(e,s.methods.addPaymentManager,a);return await s.methods.addPaymentManager(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasRemovePaymentManager(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.removePaymentManager,a)}async removePaymentManager(t,e,a){const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);if(!0!==await this.isERC20Deployer(t,e))throw new Error("Caller is not ERC20Deployer");const i=await S(e,s.methods.removePaymentManager,a);return await s.methods.removePaymentManager(a).send({from:e,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasSetPaymentCollector(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.setPaymentCollector,a)}async setPaymentCollector(t,e,a){const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config),i=(await this.getDTPermissions(t,e)).paymentManager,n=!i&&await this.getNFTAddress(t),o=n&&await this.nft.getNftOwner(n)===e,r=n&&!o&&await this.nft.getNftPermissions(n,e);if(!i&&!o&&!(null==r?void 0:r.deployERC20))throw new Error("Caller is not Fee Manager, owner or erc20 Deployer");const c=await S(e,s.methods.setPaymentCollector,a);return await s.methods.setPaymentCollector(a).send({from:e,gas:c+1,gasPrice:await T(this.web3,this.config)})}async getPaymentCollector(t){const e=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return await e.methods.getPaymentCollector().call()}async transfer(t,e,a,s){const i=this.web3.utils.toWei(a);return this.transferWei(t,e,i,s)}async estGasTransfer(t,e,a,s,i){return S(s,(i||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.transfer,e,a)}async transferWei(t,e,a,s){const i=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);try{const t=await S(s,i.methods.transfer,e,a);return await i.methods.transfer(e,a).send({from:s,gas:t+1,gasPrice:await T(this.web3,this.config)})}catch(t){throw f.error(`ERROR: Failed to transfer tokens: ${t.message}`),new Error(`Failed Failed to transfer tokens: ${t.message}`)}}async estGasStartOrder(t,e,a,s,i,n,o){return S(e,(o||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.startOrder,a,s,i,n)}async startOrder(t,e,a,s,i,n){const o=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);n||(n={consumeMarketFeeAddress:R,consumeMarketFeeToken:R,consumeMarketFeeAmount:"0"});try{const t=await S(e,o.methods.startOrder,a,s,i,n);return await o.methods.startOrder(a,s,i,n).send({from:e,gas:t+1,gasPrice:await T(this.web3,this.config)})}catch(t){throw f.error(`ERROR: Failed to start order : ${t.message}`),new Error(`Failed to start order: ${t.message}`)}}async estGasReuseOrder(t,e,a,s,i){return S(e,(i||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.reuseOrder,a,s)}async reuseOrder(t,e,a,s){const i=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);try{const t=await S(e,i.methods.reuseOrder,a,s);return await i.methods.reuseOrder(a,s).send({from:e,gas:t+1,gasPrice:await T(this.web3,this.config)})}catch(t){throw f.error(`ERROR: Failed to call reuse order order : ${t.message}`),new Error(`Failed to start order: ${t.message}`)}}async estGasBuyFromFreAndOrder(t,e,a,s,i){return S(e,(i||new this.web3.eth.Contract(this.datatokensEnterpriseAbi,t)).methods.buyFromFreAndOrder,a,s)}async buyFromFreAndOrder(t,e,a,s){const i=new this.web3.eth.Contract(this.datatokensEnterpriseAbi,t);try{const t=await v(this.web3,s),n=await S(e,i.methods.buyFromFreAndOrder,a,t);return await i.methods.buyFromFreAndOrder(a,t).send({from:e,gas:n+1,gasPrice:await T(this.web3,this.config)})}catch(t){throw f.error(`ERROR: Failed to buy DT From Fre And Order : ${t.message}`),new Error(`Failed to buy DT From Fre And Order: ${t.message}`)}}async estGasBuyFromDispenserAndOrder(t,e,a,s,i){return S(e,(i||new this.web3.eth.Contract(this.datatokensEnterpriseAbi,t)).methods.buyFromDispenserAndOrder,a,s)}async buyFromDispenserAndOrder(t,e,a,s){const i=new this.web3.eth.Contract(this.datatokensEnterpriseAbi,t);try{const t=await S(e,i.methods.buyFromDispenserAndOrder,a,s);return await i.methods.buyFromDispenserAndOrder(a,s).send({from:e,gas:t+1,gasPrice:await T(this.web3,this.config)})}catch(t){throw f.error(`ERROR: Failed to buy DT From Fre And Order : ${t.message}`),new Error(`Failed to buy DT From Fre And Order: ${t.message}`)}}async estGasSetData(t,e,a,s){return S(e,(s||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.setData,a)}async setData(t,e,a){if(!await this.isERC20Deployer(t,e))throw new Error("User is not ERC20 Deployer");const s=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config),i=this.web3.utils.asciiToHex(a),n=await S(e,s.methods.setData,i);return await s.methods.setData(i).send({from:e,gas:n+1,gasPrice:await T(this.web3,this.config)})}async estGasCleanPermissions(t,e,a){return S(e,(a||k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config)).methods.cleanPermissions)}async cleanPermissions(t,e){if(await this.nft.getNftOwner(await this.getNFTAddress(t))!==e)throw new Error("Caller is NOT Nft Owner");const a=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config),s=await S(e,a.methods.cleanPermissions);return await a.methods.cleanPermissions().send({from:e,gas:s+1,gasPrice:await T(this.web3,this.config)})}async getDTPermissions(t,e){const a=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return await a.methods.permissions(e).call()}async getCap(t){const e=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config),a=await e.methods.cap().call();return this.web3.utils.fromWei(a)}async getDecimals(t){const e=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return await e.methods.decimals().call()}async getNFTAddress(t){const e=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return await e.methods.getERC721Address().call()}async isERC20Deployer(t,e){const a=k(new this.web3.eth.Contract(this.datatokensAbi,t),this.config);return await a.methods.isERC20Deployer(e).call()}async balance(t,e){const a=new this.web3.eth.Contract(this.datatokensAbi,t,{from:e}),s=await a.methods.balanceOf(e).call();return this.web3.utils.fromWei(s)}async estGasSetPublishingMarketFee(t,e,a,s,i){return S(i,new this.web3.eth.Contract(this.datatokensAbi,t,{from:i}).methods.setPublishingMarketFee,e,a,s)}async setPublishingMarketFee(t,e,a,s,i){const n=new this.web3.eth.Contract(this.datatokensAbi,t,{from:i});if((await n.methods.getPublishingMarketFee().call())[0]!==i)throw new Error("Caller is not the Publishing Market Fee Address");const o=await this.estGasSetPublishingMarketFee(t,e,a,s,i);await n.methods.setPublishingMarketFee(e,a,s).send({from:i,gas:o+1,gasPrice:await T(this.web3,this.config)})}async getPublishingMarketFee(t,e){const a=new this.web3.eth.Contract(this.datatokensAbi,t,{from:e}),s=await a.methods.getPublishingMarketFee().call();return{publishMarketFeeAddress:s[0],publishMarketFeeToken:s[1],publishMarketFeeAmount:s[2]}}}class pt{constructor(t,e,a,s,i){this.factory721Address=void 0,this.factory721Abi=void 0,this.web3=void 0,this.config=void 0,this.factory721=void 0,this.factory721Address=t,this.factory721Abi=s||m.abi,this.web3=e,this.config=i||(new B).getConfig(a||"unknown"),this.factory721=k(new this.web3.eth.Contract(this.factory721Abi,this.factory721Address),this.config)}async estGasCreateNFT(t,e){return S(t,this.factory721.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,R,R,e.tokenURI,e.transferable,e.owner)}async createNFT(t,e){if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){const{name:t,symbol:a}=y();e.name=t,e.symbol=a}if(e.templateIndex>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");if(!1===(await this.getNFTTemplate(e.templateIndex)).isActive)throw new Error("Template is not active");const a=await S(t,this.factory721.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,R,R,e.tokenURI,e.transferable,e.owner),s=await this.factory721.methods.deployERC721Contract(e.name,e.symbol,e.templateIndex,R,R,e.tokenURI,e.transferable,e.owner).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)});let i=null;try{i=s.events.NFTCreated.returnValues[0]}catch(t){f.error(`ERROR: Failed to create datatoken : ${t.message}`)}return i}async getCurrentNFTCount(){return await this.factory721.methods.getCurrentNFTCount().call()}async getCurrentTokenCount(){return await this.factory721.methods.getCurrentTokenCount().call()}async getOwner(){return await this.factory721.methods.owner().call()}async getCurrentNFTTemplateCount(){return await this.factory721.methods.getCurrentNFTTemplateCount().call()}async getCurrentTokenTemplateCount(){return await this.factory721.methods.getCurrentTemplateCount().call()}async getNFTTemplate(t){if(t>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return await this.factory721.methods.getNFTTemplate(t).call()}async getTokenTemplate(t){return await this.factory721.methods.getTokenTemplate(t).call()}async checkDatatoken(t){return await this.factory721.methods.erc20List(t).call()}async checkNFT(t){return await this.factory721.methods.erc721List(t).call()}async estGasAddNFTTemplate(t,e){return S(t,this.factory721.methods.add721TokenTemplate,e)}async addNFTTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===R)throw new Error("Template cannot be ZERO address");const a=await S(t,this.factory721.methods.add721TokenTemplate,e);return await this.factory721.methods.add721TokenTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasDisableNFTTemplate(t,e){return S(t,this.factory721.methods.disable721TokenTemplate,e)}async disableNFTTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const a=await S(t,this.factory721.methods.disable721TokenTemplate,e);return await this.factory721.methods.disable721TokenTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasReactivateNFTTemplate(t,e){return S(t,this.factory721.methods.reactivate721TokenTemplate,e)}async reactivateNFTTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const a=await S(t,this.factory721.methods.reactivate721TokenTemplate,e);return await this.factory721.methods.reactivate721TokenTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasAddTokenTemplate(t,e){return S(t,this.factory721.methods.addTokenTemplate,e)}async addTokenTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===R)throw new Error("Template cannot be address ZERO");const a=await S(t,this.factory721.methods.addTokenTemplate,e);return await this.factory721.methods.addTokenTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasDisableTokenTemplate(t,e){return S(t,this.factory721.methods.disableTokenTemplate,e)}async disableTokenTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!1===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already disabled");const a=await S(t,this.factory721.methods.disableTokenTemplate,e);return await this.factory721.methods.disableTokenTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasReactivateTokenTemplate(t,e){return S(t,this.factory721.methods.reactivateTokenTemplate,e)}async reactivateTokenTemplate(t,e){if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!0===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already active");const a=await S(t,this.factory721.methods.reactivateTokenTemplate,e);return await this.factory721.methods.reactivateTokenTemplate(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasStartMultipleTokenOrder(t,e){return S(t,this.factory721.methods.startMultipleTokenOrder,e)}async startMultipleTokenOrder(t,e){if(e.length>50)throw new Error("Too many orders");const a=await S(t,this.factory721.methods.startMultipleTokenOrder,e);return await this.factory721.methods.startMultipleTokenOrder(e).send({from:t,gas:a+1,gasPrice:await T(this.web3,this.config)})}async estGasCreateNftWithErc20(t,e,a){const s=E(a);return S(t,this.factory721.methods.createNftWithErc20,e,s)}async createNftWithErc20(t,e,a){const s=E(a),i=await S(t,this.factory721.methods.createNftWithErc20,e,s);return await this.factory721.methods.createNftWithErc20(e,s).send({from:t,gas:i+1,gasPrice:await T(this.web3,this.config)})}async estGasCreateNftErc20WithPool(t,e,a,s){const i=E(a),n=await x(this.web3,s);return S(t,this.factory721.methods.createNftWithErc20WithPool,e,i,n)}async createNftErc20WithPool(t,e,a,s){const i=E(a),n=await x(this.web3,s),o=await S(t,this.factory721.methods.createNftWithErc20WithPool,e,i,n);return await this.factory721.methods.createNftWithErc20WithPool(e,i,n).send({from:t,gas:o+1,gasPrice:await T(this.web3,this.config)})}async estGasCreateNftErc20WithFixedRate(t,e,a,s){const i=E(a),n=await F(s);return S(t,this.factory721.methods.createNftWithErc20WithFixedRate,e,i,n)}async createNftErc20WithFixedRate(t,e,a,s){const i=E(a),n=F(s),o=await S(t,this.factory721.methods.createNftWithErc20WithFixedRate,e,i,n);return await this.factory721.methods.createNftWithErc20WithFixedRate(e,i,n).send({from:t,gas:o+1,gasPrice:await T(this.web3,this.config)})}async estGasCreateNftErc20WithDispenser(t,e,a,s){const i=E(a);return S(t,this.factory721.methods.createNftWithErc20WithDispenser,e,i,s)}async createNftErc20WithDispenser(e,a,s,i){const n=E(s);i.maxBalance=t.utils.toWei(i.maxBalance),i.maxTokens=t.utils.toWei(i.maxTokens);const o=await S(e,this.factory721.methods.createNftWithErc20WithDispenser,a,n,i);return await this.factory721.methods.createNftWithErc20WithDispenser(a,n,i).send({from:e,gas:o+1,gasPrice:await T(this.web3,this.config)})}}class ft{constructor(){this.nodeUri=void 0,this.providerAddress=void 0,this.metadataCacheUri=void 0,this.providerUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.erc721FactoryAddress=void 0,this.erc721FFactoryABI=void 0,this.datatokensABI=void 0,this.poolTemplateAddress=void 0,this.poolFactoryABI=void 0,this.poolABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.opfCommunityFeeCollector=void 0,this.sideStakingAddress=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.chainId=void 0,this.network=void 0,this.subgraphUri=void 0,this.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0}}const bt=t=>function(t="",e){const{valid:a,output:s}=function(t,e,a){if("string"!=typeof t)throw f.debug("Not input string:"),f.debug(t),new Error("[zeroXTransformer] Expected string, input type: "+typeof t);const s=t.match(/^(?:0x)*([a-f0-9]+)$/i);return s?{valid:!0,output:s[1]}:(f.warn("[zeroXTransformer] Input transformation failed."),{valid:!1,output:t})}(t);return(e&&a?"0x":"")+s}(t,!1);class yt{async getEndpoints(t){try{const e=await I(t);return await e.json()}catch(t){return f.error("Finding the service endpoints failed:",t),null}}getEndpointURL(t,e){return t?t.find(t=>t.serviceName===e):null}async getServiceEndpoints(t,e){const a=[];for(const s in e.serviceEndpoints)a.push({serviceName:s,method:e.serviceEndpoints[s][0],urlPath:t+e.serviceEndpoints[s][1]});return a}async getNonce(t,e,s,i,n){i||(i=await this.getEndpoints(t)),n||(n=await this.getServiceEndpoints(t,i));const o=this.getEndpointURL(n,"nonce")?this.getEndpointURL(n,"nonce").urlPath:null;if(!o)return null;try{const t=await a(o+`?userAddress=${e}`,{method:"GET",headers:{"Content-Type":"application/json"},signal:s});return(await t.json()).nonce.toString()}catch(t){throw f.error(t),new Error("HTTP request failed")}}async signProviderRequest(t,e,a,s){const i=t.utils.soliditySha3({t:"bytes",v:t.utils.utf8ToHex(a)});return t&&t.currentProvider&&t.currentProvider.isMetaMask?await t.eth.personal.sign(i,e,s):await t.eth.sign(i,e)}async encrypt(t,e,s){const i=await this.getEndpoints(e),n=await this.getServiceEndpoints(e,i),o=this.getEndpointURL(n,"encrypt")?this.getEndpointURL(n,"encrypt").urlPath:null;if(!o)return null;try{const e=await a(o,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:s});return await e.text()}catch(t){throw f.error(t),new Error("HTTP request failed")}}async checkDidFiles(t,e,s,i=!1,n){const o=await this.getEndpoints(s),r=await this.getServiceEndpoints(s,o),c={did:t,serviceId:e,checksum:i},h=[],l=this.getEndpointURL(r,"fileinfo")?this.getEndpointURL(r,"fileinfo").urlPath:null;if(!l)return null;try{const t=await a(l,{method:"POST",body:JSON.stringify(c),headers:{"Content-Type":"application/json"},signal:n}),e=await t.json();for(const t of e)h.push(t);return h}catch(t){return null}}async checkFileUrl(t,e,s){const i=await this.getEndpoints(e),n=await this.getServiceEndpoints(e,i),o={url:t,type:"url"},r=[],c=this.getEndpointURL(n,"fileinfo")?this.getEndpointURL(n,"fileinfo").urlPath:null;if(!c)return null;try{const t=await a(c,{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json"},signal:s}),e=await t.json();for(const t of e)r.push(t);return r}catch(t){return null}}async getComputeEnvironments(t,e){var s;const i=await this.getEndpoints(t),n=await this.getServiceEndpoints(t,i),o=null==(s=this.getEndpointURL(n,"computeEnvironments"))?void 0:s.urlPath;if(!o)return null;try{const t=await a(o,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});return await t.json()}catch(t){return f.error(t.message),null}}async initialize(t,e,s,i,n,o,r,c,h){const l=await this.getEndpoints(n),d=await this.getServiceEndpoints(n,l);let w=this.getEndpointURL(d,"initialize")?this.getEndpointURL(d,"initialize").urlPath:null;if(!w)return null;w+=`?documentId=${t}`,w+=`&serviceId=${e}`,w+=`&fileIndex=${s}`,w+=`&consumerAddress=${i}`,r&&(w+="&userdata="+encodeURI(JSON.stringify(r))),c&&(w+="&environment="+encodeURI(c)),h&&(w+="&validUntil="+h);try{const t=await a(w,{method:"GET",headers:{"Content-Type":"application/json"},signal:o});return await t.json()}catch(t){throw f.error(t),new Error("Asset URL not found or not available.")}}async initializeCompute(t,e,s,i,n,o,r){const c=await this.getEndpoints(n),h=await this.getServiceEndpoints(n,c),l={datasets:t,algorithm:e,compute:{env:s,validUntil:i},consumerAddress:o},d=this.getEndpointURL(h,"initializeCompute")?this.getEndpointURL(h,"initializeCompute").urlPath:null;if(!d)return null;try{const t=await a(d,{method:"POST",body:JSON.stringify(l),headers:{"Content-Type":"application/json"},signal:r});return await t.json()}catch(t){throw f.error(t),new Error("ComputeJob cannot be initialized")}}async getDownloadUrl(t,e,a,s,i,n,o,r){const c=await this.getEndpoints(n),h=await this.getServiceEndpoints(n,c),l=this.getEndpointURL(h,"download")?this.getEndpointURL(h,"download").urlPath:null;if(!l)return null;const d=Date.now();let w=l;return w+=`?fileIndex=${s}`,w+=`&documentId=${t}`,w+=`&transferTxId=${i}`,w+=`&serviceId=${a}`,w+=`&consumerAddress=${e}`,w+=`&nonce=${d}`,w+=`&signature=${await this.signProviderRequest(o,e,t+d)}`,r&&(w+="&userdata="+encodeURI(JSON.stringify(r))),w}async computeStart(t,e,s,i,n,o,r,c,h){const l=await this.getEndpoints(t),d=await this.getServiceEndpoints(t,l),w=this.getEndpointURL(d,"computeStart")?this.getEndpointURL(d,"computeStart").urlPath:null,u=Date.now();let m=s;m+=n.documentId,m+=u;const g=await this.signProviderRequest(e,s,m),p=Object();if(p.consumerAddress=s,p.signature=g,p.nonce=u,p.environment=i,p.dataset=n,p.algorithm=o,p.additionalDatasets&&(p.additionalDatasets=c),h&&(p.output=h),!w)return null;try{const t=await a(w,{method:"POST",body:JSON.stringify(p),headers:{"Content-Type":"application/json"},signal:r});return null!=t&&t.ok?await t.json():(f.error("Compute start failed: ",t.status,t.statusText),f.error("Payload was:",p),null)}catch(t){return f.error("Compute start failed:"),f.error(t),f.error("Payload was:",p),null}}async computeStop(t,e,s,i,n,o){const r=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,r),h=this.getEndpointURL(c,"computeStop")?this.getEndpointURL(c,"computeStop").urlPath:null,l=await this.getNonce(i,e,o,r,c);let d=e;d+=s||"",d+=t&&`${bt(t)}`||"",d+=l;const w=await this.signProviderRequest(n,e,d),u=Object();if(u.signature=w,u.documentId=bt(t),u.consumerAddress=e,s&&(u.jobId=s),!h)return null;try{const t=await a(h,{method:"PUT",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:o});return null!=t&&t.ok?await t.json():(f.error("Compute stop failed:",t.status,t.statusText),f.error("Payload was:",u),null)}catch(t){return f.error("Compute stop failed:"),f.error(t),f.error("Payload was:",u),null}}async computeStatus(t,e,s,i,n){const o=await this.getEndpoints(t),r=await this.getServiceEndpoints(t,o),c=this.getEndpointURL(r,"computeStatus")?this.getEndpointURL(r,"computeStatus").urlPath:null;let h=`?consumerAddress=${e}`;if(h+=i&&`&documentId=${bt(i)}`||"",h+=s&&`&jobId=${s}`||"",!c)return null;try{const t=await a(c+h,{method:"GET",headers:{"Content-Type":"application/json"},signal:n});return null!=t&&t.ok?await t.json():(f.error("Get compute status failed:",t.status,t.statusText),null)}catch(t){return f.error("Get compute status failed"),f.error(t),null}}async getComputeResultUrl(t,e,a,s,i){const n=await this.getEndpoints(t),o=await this.getServiceEndpoints(t,n),r=this.getEndpointURL(o,"computeResult")?this.getEndpointURL(o,"computeResult").urlPath:null,c=Date.now();let h=a;h+=s,h+=i.toString(),h+=c;const l=await this.signProviderRequest(e,a,h);if(!r)return null;let d=r;return d+=`?consumerAddress=${a}`,d+=`&jobId=${s}`,d+=`&index=${i.toString()}`,d+=`&nonce=${c}`,d+=l&&`&signature=${l}`||"",d}async computeDelete(t,e,s,i,n,o){const r=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,r),h=this.getEndpointURL(c,"computeDelete")?this.getEndpointURL(c,"computeDelete").urlPath:null,l=await this.getNonce(i,e,o,r,c);let d=e;d+=s||"",d+=t&&`${bt(t)}`||"",d+=l;const w=await this.signProviderRequest(n,e,d),u=Object();if(u.documentId=bt(t),u.consumerAddress=e,u.jobId=s,w&&(u.signature=w),!h)return null;try{const t=await a(h,{method:"DELETE",body:JSON.stringify(u),headers:{"Content-Type":"application/json"},signal:o});return null!=t&&t.ok?await t.json():(f.error("Delete compute job failed:",t.status,t.statusText),f.error("Payload was:",u),null)}catch(t){return f.error("Delete compute job failed:"),f.error(t),f.error("Payload was:",u),null}}async isValidProvider(t,e){try{const s=await a(t,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(null!=s&&s.ok){const t=await s.json();if(t&&t.providerAddress)return!0}return!1}catch(t){return f.error(`Error validating provider: ${t.message}`),!1}}}const Ct=new yt;export{ot as Aquarius,ft as Config,B as ConfigHelper,gt as Datatoken,ht as Dispenser,lt as FixedRateCreateProgressStep,dt as FixedRateExchange,A as GASLIMIT_DEFAULT,g as LogLevel,p as Logger,f as LoggerInstance,mt as Nft,pt as NftFactory,ct as Pool,yt as Provider,Ct as ProviderInstance,ut as Router,wt as SideStaking,R as ZERO_ADDRESS,Z as allowance,X as allowanceWei,P as amountToUnits,_ as approve,J as approveWei,Q as balance,et as calcMaxExactIn,tt as calcMaxExactOut,G as configHelperNetworks,K as decimals,U as downloadFile,D as downloadFileBrowser,z as estApprove,H as estTransfer,S as estimateGas,M as fetchData,L as generateDid,y as generateDtName,I as getData,E as getErcCreationParams,T as getFairGasPrice,F as getFreCreationParams,v as getFreOrderParams,j as getHash,it as getMaxAddLiquidity,nt as getMaxRemoveLiquidity,st as getMaxSwapExactIn,at as getMaxSwapExactOut,x as getPoolCreationParams,W as postData,k as setContractDefaults,q as signHash,Y as sleep,V as transfer,O as unitsToAmount};
1
+ import t from"@oceanprotocol/contracts/addresses/address.json";import e from"bignumber.js";import a from"crypto-js/sha256";import i from"web3";import n from"cross-fetch";import o from"decimal.js";import r from"@oceanprotocol/contracts/artifacts/contracts/pools/dispenser/Dispenser.sol/Dispenser.json";import s from"@oceanprotocol/contracts/artifacts/contracts/pools/fixedRate/FixedRateExchange.sol/FixedRateExchange.json";import c from"@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json";import l from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json";import h from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json";import d from"@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json";import u from"@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json";import w from"@oceanprotocol/contracts/artifacts/contracts/ve/veOCEAN.vy/veOCEAN.json";import m from"@oceanprotocol/contracts/artifacts/contracts/ve/veFeeDistributor.vy/veFeeDistributor.json";import p from"@oceanprotocol/contracts/artifacts/contracts/ve/veAllocate.sol/veAllocate.json";import g from"@oceanprotocol/contracts/artifacts/contracts/df/DFRewards.sol/DFRewards.json";import f from"@oceanprotocol/contracts/artifacts/contracts/df/DFStrategyV1.sol/DFStrategyV1.json";class v{constructor(){this.nodeUri=void 0,this.providerAddress=void 0,this.metadataCacheUri=void 0,this.providerUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.nftFactoryAddress=void 0,this.datatokensABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.opfCommunityFeeCollector=void 0,this.sideStakingAddress=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.chainId=void 0,this.network=void 0,this.subgraphUri=void 0,this.explorerUri=void 0,this.oceanTokenSymbol=void 0,this.transactionBlockTimeout=void 0,this.transactionConfirmationBlocks=void 0,this.transactionPollingTimeout=void 0,this.gasFeeMultiplier=void 0}}function y(){return y=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var i in a)Object.prototype.hasOwnProperty.call(a,i)&&(t[i]=a[i])}return t},y.apply(this,arguments)}const b="0x0000000000000000000000000000000000000000",T=1e6,k="115792089237316195423570985008687907853269984665640564039457584007913129639934",C="Returned error: Method eth_feeHistory not supported.";function F(t,e){return e&&(e.transactionBlockTimeout&&(t.transactionBlockTimeout=e.transactionBlockTimeout),e.transactionConfirmationBlocks&&(t.transactionConfirmationBlocks=e.transactionConfirmationBlocks),e.transactionPollingTimeout&&(t.transactionPollingTimeout=e.transactionPollingTimeout)),t}async function E(t,a){const i=new e(await t.eth.getGasPrice());return a?i.multipliedBy(a).integerValue(e.ROUND_DOWN).toString(10):i.toString(10)}async function M(t,a,i,n){const o=new t.eth.Contract(B,a);let r=n||await o.methods.decimals().call();"0"===r&&(r=18);const s=new e(i).div(new e(10).exponentiatedBy(r));return e.config({EXPONENTIAL_AT:50}),s.toString()}async function x(t,a,i,n){const o=new t.eth.Contract(B,a);let r=n||await o.methods.decimals().call();return"0"===r&&(r=18),e.config({EXPONENTIAL_AT:50}),new e(i).times(new e(10).exponentiatedBy(r)).toFixed(0)}async function D(t,e,...a){return await e.apply(null,a).estimateGas({from:t},(t,e)=>t?1e6:e)}async function A(t,a,i,n,o,...r){const s={from:t,gas:a+1};try{var c,l,h;const t=await i.eth.getFeeHistory(1,"latest",[75]);if(t&&null!=t&&null!=(c=t.baseFeePerGas)&&c[0]&&null!=t&&null!=(l=t.reward)&&null!=(h=l[0])&&h[0]){var d,u,w;let a=new e(null==t||null==(d=t.reward)||null==(u=d[0])?void 0:u[0]);n>1&&(a=a.multipliedBy(n)),s.maxPriorityFeePerGas=a.integerValue(e.ROUND_DOWN).toString(10),s.maxFeePerGas=a.plus(new e(null==t||null==(w=t.baseFeePerGas)?void 0:w[0]).multipliedBy(2)).integerValue(e.ROUND_DOWN).toString(10)}else s.gasPrice=await E(i,n)}catch(t){"Returned error: Method eth_feeHistory not supported."===(null==t?void 0:t.message)&&L.log("Not able to use EIP 1559, getFeeHistory method not suported by network."),s.gasPrice=await E(i,n)}return await o.apply(null,r).send(s)}var R,U={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 P(t){const e=t||U,a=Math.floor(Math.random()*e.adjectives.length),i=Math.floor(Math.random()*e.nouns.length),n=Math.floor(100*Math.random()),o=e.adjectives[a].replace(/^\w/,t=>t.toUpperCase()),r=e.nouns[i].replace(/^\w/,t=>t.toUpperCase());return{name:`${o} ${r} Token`,symbol:`${(o.substring(0,3)+r.substring(0,3)).toUpperCase()}-${n}`}}function O(t,e){return t=i.utils.toChecksumAddress(t),`did:op:${a(t+e.toString(10)).toString()}`}function S(t){return a(t).toString()}async function N(t){const e=(await n(t,{method:"HEAD"})).headers.get("content-disposition").split("=")[1],a=new XMLHttpRequest;a.responseType="blob",a.open("GET",t),a.onload=()=>{const t=window.URL.createObjectURL(a.response),i=document.createElement("a");i.href=t,i.setAttribute("download",e),document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(t)},a.send(null)}async function I(t,e){const a=await n(t);if(!a.ok)throw new Error("Response error.");let i;try{i=a.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(a){try{i=t.split("/").pop()}catch(t){i=`file${e}`}}return{data:await a.arrayBuffer(),filename:i}}async function j(t){return new Promise(e=>{setTimeout(e,t)})}!function(t){t[t.None=-1]="None",t[t.Error=0]="Error",t[t.Warn=1]="Warn",t[t.Log=2]="Log",t[t.Verbose=3]="Verbose"}(R||(R={}));class W{constructor(t=R.Error){this.logLevel=void 0,this.logLevel=t}setLevel(t){this.logLevel=t}bypass(...t){this.dispatch("log",-Infinity,...t)}debug(...t){this.dispatch("debug",R.Verbose,...t)}log(...t){this.dispatch("log",R.Log,...t)}warn(...t){this.dispatch("warn",R.Warn,...t)}error(...t){this.dispatch("error",R.Error,...t)}dispatch(t,e,...a){this.logLevel>=e&&console[t](...a)}}const L=new W,B=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}];async function q(t,e,a){let i=await t.eth.sign(e,a);i=i.substr(2);const n="0x"+i.slice(0,64),o="0x"+i.slice(64,128);let r="0x"+i.slice(128,130);return"0x00"===r&&(r="0x1b"),"0x01"===r&&(r="0x1c"),{v:r,r:n,s:o}}async function $(t,e,a,i,n,r,s=!1,c,l){const h=new t.eth.Contract(B,i);if(!s){const e=await G(t,i,a,n);if(new o(e).greaterThanOrEqualTo(new o(r)))return null}const d=await x(t,i,r,c),u=await D(a,h.methods.approve,n,d);return l?u:await A(a,u+1,t,null==e?void 0:e.gasFeeMultiplier,h.methods.approve,n,d)}async function _(t,a,i,n,o,r,s=!1,c){const l=new t.eth.Contract(B,n);if(!s){const a=await z(t,n,i,o);if(new e(a).gt(new e(r)))return null}let h=null;const d=await D(i,l.methods.approve,o,r);if(c)return d;try{h=await A(i,d+1,t,null==a?void 0:a.gasFeeMultiplier,l.methods.approve,o,r)}catch(t){L.error(`ERROR: Failed to approve spender to spend tokens : ${t.message}`)}return h}async function H(t,e,a,i,n,o,r){const s=new t.eth.Contract(B,i),c=await x(t,i,o),l=await D(a,s.methods.transfer,n,c);return r?l:await A(a,l+1,t,null==e?void 0:e.gasFeeMultiplier,s.methods.transfer,n,c)}async function G(t,e,a,i,n){const o=new t.eth.Contract(B,e),r=await o.methods.allowance(a,i).call();return await M(t,e,r,n)}async function Z(t,e,a,i){const n=new t.eth.Contract(B,e),o=await n.methods.balanceOf(a).call();return await M(t,e,o,i)}async function z(t,e,a,i,n){const o=new t.eth.Contract(B,e);return await o.methods.allowance(a,i).call()}async function J(t,e){const a=new t.eth.Contract(B,e);return await a.methods.decimals().call()}const V={chainId:null,network:"unknown",metadataCacheUri:"https://v4.aquarius.oceanprotocol.com",nodeUri:"http://127.0.0.1:8545",providerUri:"http://127.0.0.1:8030",subgraphUri:null,explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",fixedRateExchangeAddress:null,dispenserAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},X=[y({},V),y({},V,{chainId:8996,network:"development",metadataCacheUri:"http://127.0.0.1:5000",providerUri:"http://172.15.0.4:8030"}),y({},V,{chainId:3,network:"ropsten",nodeUri:"https://ropsten.infura.io/v3",providerUri:"https://v4.provider.ropsten.oceanprotocol.com",subgraphUri:"https://v4.subgraph.ropsten.oceanprotocol.com",explorerUri:"https://ropsten.etherscan.io",gasFeeMultiplier:1.1}),y({},V,{chainId:4,network:"rinkeby",nodeUri:"https://rinkeby.infura.io/v3",providerUri:"https://v4.provider.rinkeby.oceanprotocol.com",subgraphUri:"https://v4.subgraph.rinkeby.oceanprotocol.com",explorerUri:"https://rinkeby.etherscan.io",gasFeeMultiplier:1.1}),y({},V,{chainId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",providerUri:"https://v4.provider.mainnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.mainnet.oceanprotocol.com",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05}),y({},V,{chainId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",providerUri:"https://v4.provider.polygon.oceanprotocol.com",subgraphUri:"https://v4.subgraph.polygon.oceanprotocol.com",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN"}),y({},V,{chainId:1287,network:"moonbase",nodeUri:"https://rpc.api.moonbase.moonbeam.network",providerUri:"https://v4.provider.moonbase.oceanprotocol.com",subgraphUri:"https://v4.subgraph.moonbase.oceanprotocol.com",explorerUri:"https://moonbase.moonscan.io/",gasFeeMultiplier:1.1}),y({},V,{chainId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",providerUri:"https://v4.provider.gaiaxtestnet.oceanprotocol.com",subgraphUri:"https://v4.subgraph.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com"}),y({},V,{chainId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",providerUri:"https://v4.provider.mumbai.oceanprotocol.com",subgraphUri:"https://v4.subgraph.mumbai.oceanprotocol.com",explorerUri:"https://mumbai.polygonscan.com",gasFeeMultiplier:1.1}),y({},V,{chainId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",providerUri:"https://v4.provider.bsc.oceanprotocol.com",subgraphUri:"https://v4.subgraph.bsc.oceanprotocol.com",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05}),y({},V,{chainId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",providerUri:"https://v4.provider.energyweb.oceanprotocol.com",subgraphUri:"https://v4.subgraph.energyweb.oceanprotocol.com",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05}),y({},V,{chainId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",providerUri:"https://v4.provider.moonriver.oceanprotocol.com",subgraphUri:"https://v4.subgraph.moonriver.oceanprotocol.com",explorerUri:"https://moonriver.moonscan.io/",gasFeeMultiplier:1.05})];class Q{getAddressesFromEnv(e,a){let i;if(a){const{FixedPrice:t,Dispenser:n,ERC721Factory:o,OPFCommunityFeeCollector:r,Ocean:s,chainId:c,startBlock:l}=a[e];i=y({nftFactoryAddress:o,opfCommunityFeeCollector:r,fixedRateExchangeAddress:t,dispenserAddress:n,oceanTokenAddress:s,chainId:c,startBlock:l},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}else if(t[e]){const{FixedPrice:a,Dispenser:n,OPFCommunityFeeCollector:o,ERC721Factory:r,Ocean:s,chainId:c,startBlock:l}=t[e];i=y({nftFactoryAddress:r,opfCommunityFeeCollector:o,fixedRateExchangeAddress:a,dispenserAddress:n,oceanTokenAddress:s,chainId:c,startBlock:l},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}return i}getConfig(t,e){const a="string"==typeof t?"network":"chainId";let i=X.find(e=>e[a]===t);return i?(i=y({},i,this.getAddressesFromEnv(i.network)),y({},i,{nodeUri:e?`${i.nodeUri}/${e}`:i.nodeUri})):(L.error(`No config found for given network '${t}'`),null)}}class K{constructor(t,e,a,i){this.web3=void 0,this.config=void 0,this.abi=void 0,this.web3=t,this.config=a||(new Q).getConfig(e||"unknown"),this.abi=i||this.getDefaultAbi()}async amountToUnits(t,e,a){return x(this.web3,t,e,a)}async unitsToAmount(t,e,a){return M(this.web3,t,e,a)}async getFairGasPrice(){var t;return E(this.web3,null==(t=this.config)?void 0:t.gasFeeMultiplier)}getContract(t,e,a){return F(new this.web3.eth.Contract(a||this.abi,t,{from:e}),this.config)}}class Y extends K{constructor(t,e,a,i,n){super(e,a,i,n),this.address=void 0,this.contract=void 0,this.address=t,this.contract=this.getContract(this.address)}}class tt extends Y{getDefaultAbi(){return r.abi}async status(t){const e=await this.contract.methods.status(t).call();if(!e)throw new Error("Np dispenser found for the given datatoken address");return e.maxTokens=this.web3.utils.fromWei(e.maxTokens),e.maxBalance=this.web3.utils.fromWei(e.maxBalance),e.balance=this.web3.utils.fromWei(e.balance),e}async create(t,e,a,i,n,o){var r;const s=await D(e,this.contract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(i),e,n);return o?s:await A(e,s+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.create,t,this.web3.utils.toWei(a),this.web3.utils.toWei(i),e,n)}async activate(t,e,a,i,n){var o;const r=await D(i,this.contract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a));return n?r:await A(i,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.activate,t,this.web3.utils.toWei(e),this.web3.utils.toWei(a))}async deactivate(t,e,a){var i;const n=await D(e,this.contract.methods.deactivate,t);return a?n:await A(e,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.deactivate,t)}async setAllowedSwapper(t,e,a,i){var n;const o=await D(e,this.contract.methods.setAllowedSwapper,t,a);return i?o:await A(e,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setAllowedSwapper,t,a)}async dispense(t,e,a="1",i,n){var o;const r=await D(e,this.contract.methods.dispense,t,this.web3.utils.toWei(a),i);return n?r:await A(e,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.dispense,t,this.web3.utils.toWei(a),i)}async ownerWithdraw(t,e,a){var i;const n=await D(e,this.contract.methods.ownerWithdraw,t);return a?n:await A(e,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.ownerWithdraw,t)}async isDispensable(t,e,a,i="1"){const n=await this.status(t);return!(!n||!1===n.active||new o(await e.balance(t,a)).greaterThanOrEqualTo(n.maxBalance)||new o(String(i)).greaterThan(n.maxTokens)||!new o(n.balance).greaterThanOrEqualTo(i)&&!0!==n.isMinter)}}class et extends Y{getDefaultAbi(){return s.abi}async generateExchangeId(t,e){return await this.contract.methods.generateExchangeId(t,e).call()}async buyDatatokens(t,e,a,i,n=b,o="0",r){var s;const c=await this.getExchange(e),l=this.web3.utils.toWei(o),h=await this.amountToUnits(c.datatoken,a,+c.dtDecimals),d=await this.amountToUnits(c.baseToken,i,+c.btDecimals),u=await D(t,this.contract.methods.buyDT,e,h,d,n,l);return r?u:await A(t,u+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.buyDT,e,h,d,n,l)}async sellDatatokens(t,e,a,i,n=b,o="0",r){var s;const c=await this.getExchange(e),l=this.web3.utils.toWei(o),h=await this.amountToUnits(c.datatoken,a,+c.dtDecimals),d=await this.amountToUnits(c.baseToken,i,+c.btDecimals),u=await D(t,this.contract.methods.sellDT,e,h,d,n,l);return r?u:await A(t,u+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,this.contract.methods.sellDT,e,h,d,n,l)}async getNumberOfExchanges(){return await this.contract.methods.getNumberOfExchanges().call()}async setRate(t,e,a,i){var n;const o=await D(t,this.contract.methods.setRate,e,this.web3.utils.toWei(a));return i?o:await A(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setRate,e,this.web3.utils.toWei(a))}async setAllowedSwapper(t,e,a,i){var n;const o=await D(t,this.contract.methods.setAllowedSwapper,e,a);return i?o:await A(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.setAllowedSwapper,e,a)}async activate(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!0===n.active)return null;const o=await D(t,this.contract.methods.toggleExchangeState,e);return a?o:await A(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleExchangeState,e)}async deactivate(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!1===n.active)return null;const o=await D(t,this.contract.methods.toggleExchangeState,e);return a?o:await A(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleExchangeState,e)}async getRate(t){const e=await this.contract.methods.getRate(t).call();return await this.web3.utils.fromWei(e)}async getDatatokenSupply(t){const e=await this.contract.methods.getDTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.datatoken,e,+a.dtDecimals)}async getBasetokenSupply(t){const e=await this.contract.methods.getBTSupply(t).call(),a=await this.getExchange(t);return await this.unitsToAmount(a.baseToken,e,+a.btDecimals)}async getAllowedSwapper(t){return await this.contract.methods.getAllowedSwapper(t).call()}async calcBaseInGivenDatatokensOut(t,e,a="0"){const i=await this.getExchange(t),n=await this.contract.methods.calcBaseInGivenOutDT(t,await this.amountToUnits(i.datatoken,e,+i.dtDecimals),this.web3.utils.toWei(a)).call();return{baseTokenAmount:await this.unitsToAmount(i.baseToken,n.baseTokenAmount,+i.btDecimals),marketFeeAmount:await this.unitsToAmount(i.baseToken,n.marketFeeAmount,+i.btDecimals),oceanFeeAmount:await this.unitsToAmount(i.baseToken,n.oceanFeeAmount,+i.btDecimals),consumeMarketFeeAmount:await this.unitsToAmount(i.baseToken,n.consumeMarketFeeAmount,+i.btDecimals)}}async getAmountBasetokensOut(t,e,a="0"){const i=await this.getExchange(t),n=await this.contract.methods.calcBaseOutGivenInDT(t,await this.amountToUnits(i.datatoken,e,+i.dtDecimals),this.web3.utils.toWei(a)).call();return await this.unitsToAmount(i.baseToken,n[0],+i.btDecimals)}async getExchange(t){const e=await this.contract.methods.getExchange(t).call();return e.dtDecimals=e.dtDecimals.toString(),e.btDecimals=e.btDecimals.toString(),e.dtBalance=await this.unitsToAmount(e.datatoken,e.dtBalance,+e.dtDecimals),e.btBalance=await this.unitsToAmount(e.baseToken,e.btBalance,+e.btDecimals),e.dtSupply=await this.unitsToAmount(e.datatoken,e.dtSupply,+e.dtDecimals),e.btSupply=await this.unitsToAmount(e.baseToken,e.btSupply,+e.btDecimals),e.fixedRate=this.web3.utils.fromWei(e.fixedRate),e.exchangeId=t,e}async getFeesInfo(t){const e=await this.contract.methods.getFeesInfo(t).call();e.opcFee=this.web3.utils.fromWei(e.opcFee.toString()),e.marketFee=this.web3.utils.fromWei(e.marketFee.toString());const a=await this.getExchange(t);return e.marketFeeAvailable=await this.unitsToAmount(a.baseToken,e.marketFeeAvailable,+a.btDecimals),e.oceanFeeAvailable=await this.unitsToAmount(a.baseToken,e.oceanFeeAvailable,+a.btDecimals),e.exchangeId=t,e}async getExchanges(){return await this.contract.methods.getExchanges().call()}async isActive(t){return await this.contract.methods.isActive(t).call()}async activateMint(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!0===n.withMint)return null;const o=await D(t,this.contract.methods.toggleMintState,e,!0);return a?o:await A(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleMintState,e,!0)}async deactivateMint(t,e,a){var i;const n=await this.getExchange(e);if(!n)return null;if(!1===n.withMint)return null;const o=await D(t,this.contract.methods.toggleMintState,e,!1);return a?o:await A(t,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.toggleMintState,e,!1)}async collectBasetokens(t,e,a,i){var n;if(!await this.getExchange(e))return null;const o=await this.contract.methods.getExchange(e).call(),r=await this.amountToUnits(o.baseToken,a,+o.btDecimals),s=await D(t,this.contract.methods.collectBT,e,r);return i?s:await A(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.collectBT,e,r)}async collectDatatokens(t,e,a,i){var n;if(!await this.getExchange(e))return null;const o=await this.contract.methods.getExchange(e).call(),r=await this.amountToUnits(o.datatoken,a,+o.dtDecimals),s=await D(t,this.contract.methods.collectDT,e,r);return i?s:await A(t,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.collectDT,e,r)}async collectMarketFee(t,e,a){var i;if(!await this.getExchange(e))return null;const n=await D(t,this.contract.methods.collectMarketFee,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.collectMarketFee,e)}async collectOceanFee(t,e,a){var i;if(!await this.getExchange(e))return null;const n=await D(t,this.contract.methods.collectOceanFee,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.collectOceanFee,e)}async getOPCCollector(){return await this.contract.methods.opcCollector().call()}async getRouter(){return await this.contract.methods.router().call()}async getExchangeOwner(t){return await(await this.getExchange(t)).exchangeOwner}async updateMarketFee(t,e,a,i){var n;const o=await D(t,this.contract.methods.updateMarketFee,e,this.web3.utils.toWei(a));return i?o:await A(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.updateMarketFee,e,this.web3.utils.toWei(a))}async updateMarketFeeCollector(t,e,a,i){var n;const o=await D(t,this.contract.methods.updateMarketFeeCollector,e,a);return i?o:await A(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.updateMarketFeeCollector,e,a)}}class at extends Y{getDefaultAbi(){return c.abi}async buyDatatokenBatch(t,e,a){var i;const n=await D(t,this.contract.methods.buyDTBatch,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.buyDTBatch,e)}async isApprovedToken(t){return await this.contract.methods.isApprovedToken(t).call()}async isFixedPrice(t){return await this.contract.methods.isFixedRateContract(t).call()}async getOwner(){return await this.contract.methods.routerOwner().call()}async getNFTFactory(){return await this.contract.methods.factory().call()}async addApprovedToken(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await D(t,this.contract.methods.addApprovedToken,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addApprovedToken,e)}async removeApprovedToken(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await D(t,this.contract.methods.removeApprovedToken,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeApprovedToken,e)}async addFixedRateContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await D(t,this.contract.methods.addFixedRateContract,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addFixedRateContract,e)}async removeFixedRateContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await D(t,this.contract.methods.removeFixedRateContract,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeFixedRateContract,e)}async addDispenserContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await D(t,this.contract.methods.addDispenserContract,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addDispenserContract,e)}async removeDispenserContract(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const n=await D(t,this.contract.methods.removeDispenserContract,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.removeDispenserContract,e)}async getOPCFee(t){return await this.contract.methods.getOPCFee(t).call()}async getCurrentOPCFee(){return await this.contract.methods.swapOceanFee().call()}async updateOPCFee(t,e,a,i,n,o){var r;if(await this.getOwner()!==t)throw new Error("Caller is not Router Owner");const s=await D(t,this.contract.methods.updateOPCFee,e,a,i,n);return o?s:await A(t,s+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.updateOPCFee,e,a,i,n)}}class it extends K{getDefaultAbi(){return d.abi}async createDatatoken(t,e,a,i,n,o,r,s,c,l,h,d){var u,w,m,p;if(!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not DatatokenDeployer");h||(h=1),c&&l||({name:c,symbol:l}=P());const g=this.getContract(t),f=await D(e,g.methods.createERC20,h,[c,l],[a,i,n,o],[this.web3.utils.toWei(s),this.web3.utils.toWei(r)],[]);if(d)return f;const v=await A(e,f+1,this.web3,null==(u=this.config)?void 0:u.gasFeeMultiplier,g.methods.createERC20,h,[c,l],[a,i,n,o],[this.web3.utils.toWei(s),this.web3.utils.toWei(r)],[]);return null==v||null==(w=v.events)||null==(m=w.TokenCreated)||null==(p=m.returnValues)?void 0:p[0]}async addManager(t,e,a,i){var n;const o=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const r=await D(e,o.methods.addManager,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addManager,a)}async removeManager(t,e,a,i){var n;const o=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const r=await D(e,o.methods.removeManager,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeManager,a)}async addDatatokenDeployer(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const r=await D(e,o.methods.addToCreateERC20List,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addToCreateERC20List,a)}async removeDatatokenDeployer(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e===a&&!0!==(await this.getNftPermissions(t,e)).deployERC20)throw new Error("Caller is not Manager nor DatatokenDeployer");const r=await D(e,o.methods.removeFromCreateERC20List,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeFromCreateERC20List,a)}async addMetadataUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const r=await D(e,o.methods.addToMetadataList,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addToMetadataList,a)}async removeMetadataUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Manager nor Metadata Updater");const r=await D(e,o.methods.removeFromMetadataList,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeFromMetadataList,a)}async addStoreUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager)throw new Error("Caller is not Manager");const r=await D(e,o.methods.addTo725StoreList,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addTo725StoreList,a)}async removeStoreUpdater(t,e,a,i){var n;const o=this.getContract(t);if(!0!==(await this.getNftPermissions(t,e)).manager||e!==a&&!0!==(await this.getNftPermissions(t,e)).store)throw new Error("Caller is not Manager nor storeUpdater");const r=await D(e,o.methods.removeFrom725StoreList,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeFrom725StoreList,a)}async cleanPermissions(t,e,a){var i;const n=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const o=await D(e,n.methods.cleanPermissions);return a?o:await A(e,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,n.methods.cleanPermissions)}async transferNft(t,e,a,i,n){var o;const r=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const s=i||1,c=await D(e,r.methods.transferFrom,e,a,s);return n?c:await A(e,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.transferFrom,e,a,s)}async safeTransferNft(t,e,a,i,n){var o;const r=this.getContract(t);if(await this.getNftOwner(t)!==e)throw new Error("Caller is not NFT Owner");const s=i||1,c=await D(e,r.methods.safeTransferFrom,e,a,s);return n?c:await A(e,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.safeTransferFrom,e,a,s)}async setMetadata(t,e,a,i,n,o,r,s,c,l){var h;const d=this.getContract(t);if(c||(c=[]),!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const u=await D(e,d.methods.setMetaData,a,i,n,o,r,s,c);return l?u:await A(e,u+1,this.web3,null==(h=this.config)?void 0:h.gasFeeMultiplier,d.methods.setMetaData,a,i,n,o,r,s,c)}async setMetadataAndTokenURI(t,e,a,i){var n;const o=this.getContract(t);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const r=y({},a,{metadataProofs:a.metadataProofs||[]}),s=await D(e,o.methods.setMetaDataAndTokenURI,r);return i?s:await A(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setMetaDataAndTokenURI,r)}async setMetadataState(t,e,a,i){var n;const o=this.getContract(t);if(!(await this.getNftPermissions(t,e)).updateMetadata)throw new Error("Caller is not Metadata updater");const r=await D(e,o.methods.setMetaDataState,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setMetaDataState,a)}async setTokenURI(t,e,a,i){var n;const o=this.getContract(t),r=await D(e,o.methods.setTokenURI,"1",a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setTokenURI,"1",a)}async getNftOwner(t){const e=this.getContract(t);return await e.methods.ownerOf(1).call()}async getNftPermissions(t,e){const a=this.getContract(t);return await a.methods.getPermissions(e).call()}async getMetadata(t){const e=this.getContract(t);return await e.methods.getMetaData().call()}async isDatatokenDeployer(t,e){const a=this.getContract(t);return await a.methods.isERC20Deployer(e).call()}async setData(t,e,a,i){var n;if(!0!==(await this.getNftPermissions(t,e)).store)throw new Error("User is not ERC20 store updater");const o=this.getContract(t),r=this.web3.utils.keccak256(a),s=this.web3.utils.asciiToHex(i),c=await D(e,o.methods.setNewData,r,s);return await A(e,c+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setNewData,r,s)}async getData(t,e){const a=this.getContract(t),i=this.web3.utils.keccak256(e),n=await a.methods.getData(i).call();return n?this.web3.utils.hexToAscii(n):null}async getTokenURI(t,e){const a=this.getContract(t);return await a.methods.tokenURI(e).call()}}class nt extends K{getDefaultAbi(){return l.abi}constructor(t,e,a,i,n){super(t,e,a,i),this.abiEnterprise=void 0,this.nft=void 0,this.abiEnterprise=n||h.abi,this.nft=new it(this.web3)}async approve(t,e,a,i,n){var o;const r=this.getContract(t),s=await D(i,r.methods.approve,e,this.web3.utils.toWei(a));return n?s:await A(i,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.approve,e,this.web3.utils.toWei(a))}async createFixedRate(t,e,a,i){var n;const o=this.getContract(t);if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");a.allowedConsumer||(a.allowedConsumer=b);const r=a.withMint?1:0,s=await D(e,o.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,r]);return i?s:await A(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.createFixedRate,a.fixedRateAddress,[a.baseTokenAddress,a.owner,a.marketFeeCollector,a.allowedConsumer],[a.baseTokenDecimals,a.datatokenDecimals,a.fixedRate,a.marketFee,r])}async createDispenser(t,e,a,i,n){var o;if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");const r=this.getContract(t);i.allowedSwapper||(i.allowedSwapper=b),i.withMint||(i.withMint=!1);const s=await D(e,r.methods.createDispenser,a,i.maxTokens,i.maxBalance,i.withMint,i.allowedSwapper);return n?s:await A(e,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.createDispenser,a,i.maxTokens,i.maxBalance,i.withMint,i.allowedSwapper)}async mint(t,e,a,i,n){const r=this.getContract(t);if(!0!==(await this.getPermissions(t,e)).minter)throw new Error("Caller is not Minter");const s=await this.getCap(t);if(new o(s).gte(a)){var c;const t=await D(e,r.methods.mint,i||e,this.web3.utils.toWei(a));return n?t:await A(e,t+1,this.web3,null==(c=this.config)?void 0:c.gasFeeMultiplier,r.methods.mint,i||e,this.web3.utils.toWei(a))}throw new Error("Mint amount exceeds cap available")}async addMinter(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const r=await D(e,o.methods.addMinter,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addMinter,a)}async removeMinter(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const r=await D(e,o.methods.removeMinter,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removeMinter,a)}async addPaymentManager(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const r=await D(e,o.methods.addPaymentManager,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.addPaymentManager,a)}async removePaymentManager(t,e,a,i){var n;const o=this.getContract(t);if(!0!==await this.isDatatokenDeployer(t,e))throw new Error("Caller is not DatatokenDeployer");const r=await D(e,o.methods.removePaymentManager,a);return i?r:await A(e,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.removePaymentManager,a)}async setPaymentCollector(t,e,a,i){var n;const o=this.getContract(t),r=(await this.getPermissions(t,e)).paymentManager,s=!r&&await this.getNFTAddress(t),c=s&&await this.nft.getNftOwner(s)===e,l=s&&!c&&await this.nft.getNftPermissions(s,e);if(!r&&!c&&!(null==l?void 0:l.deployERC20))throw new Error("Caller is not Fee Manager, owner or Datatoken Deployer");const h=await D(e,o.methods.setPaymentCollector,a);return i?h:await A(e,h+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setPaymentCollector,a)}async getPaymentCollector(t){const e=this.getContract(t);return await e.methods.getPaymentCollector().call()}async transfer(t,e,a,i){const n=this.web3.utils.toWei(a);return this.transferWei(t,e,n,i)}async transferWei(t,e,a,i,n){var o;const r=this.getContract(t),s=await D(i,r.methods.transfer,e,a);return n?s:await A(i,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.transfer,e,a)}async startOrder(t,e,a,i,n,o,r){var s;const c=this.getContract(t);o||(o={consumeMarketFeeAddress:b,consumeMarketFeeToken:b,consumeMarketFeeAmount:"0"});const l=await D(e,c.methods.startOrder,a,i,n,o);return r?l:await A(e,l+1,this.web3,null==(s=this.config)?void 0:s.gasFeeMultiplier,c.methods.startOrder,a,i,n,o)}async reuseOrder(t,e,a,i,n){var o;const r=this.getContract(t),s=await D(e,r.methods.reuseOrder,a,i);return n?s:await A(e,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.reuseOrder,a,i)}async buyFromFreAndOrder(t,e,a,i,n){var o;const r=this.getContract(t,null,this.abiEnterprise),s=await this.getFreOrderParams(i),c=await D(e,r.methods.buyFromFreAndOrder,a,s);return n?c:await A(e,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.buyFromFreAndOrder,a,s)}async buyFromDispenserAndOrder(t,e,a,i,n){var o;const r=this.getContract(t,null,this.abiEnterprise),s=await D(e,r.methods.buyFromDispenserAndOrder,a,i);return n?s:await A(e,s+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,r.methods.buyFromDispenserAndOrder,a,i)}async setData(t,e,a,i){var n;if(!await this.isDatatokenDeployer(t,e))throw new Error("User is not Datatoken Deployer");const o=this.getContract(t),r=this.web3.utils.asciiToHex(a),s=await D(e,o.methods.setData,r);return i?s:await A(e,s+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,o.methods.setData,r)}async cleanPermissions(t,e,a){var i;if(await this.nft.getNftOwner(await this.getNFTAddress(t))!==e)throw new Error("Caller is NOT Nft Owner");const n=this.getContract(t),o=await D(e,n.methods.cleanPermissions);return a?o:await A(e,o+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,n.methods.cleanPermissions)}async getPermissions(t,e){const a=this.getContract(t);return await a.methods.permissions(e).call()}async getCap(t){const e=this.getContract(t),a=await e.methods.cap().call();return this.web3.utils.fromWei(a)}async getDecimals(t){const e=this.getContract(t);return await e.methods.decimals().call()}async getNFTAddress(t){const e=this.getContract(t);return await e.methods.getERC721Address().call()}async isDatatokenDeployer(t,e){const a=this.getContract(t);return await a.methods.isERC20Deployer(e).call()}async balance(t,e){const a=this.getContract(t,e),i=await a.methods.balanceOf(e).call();return this.web3.utils.fromWei(i)}async setPublishingMarketFee(t,e,a,i,n,o){var r;const s=this.getContract(t,n);if((await s.methods.getPublishingMarketFee().call())[0]!==n)throw new Error("Caller is not the Publishing Market Fee Address");const c=await D(n,s.methods.setPublishingMarketFee,e,a,i);return o?c:await A(n,c+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,s.methods.setPublishingMarketFee,e,a,i)}async getPublishingMarketFee(t,e){const a=this.getContract(t,e),i=await a.methods.getPublishingMarketFee().call();return{publishMarketFeeAddress:i[0],publishMarketFeeToken:i[1],publishMarketFeeAmount:i[2]}}async getFreOrderParams(t){return{exchangeContract:t.exchangeContract,exchangeId:t.exchangeId,maxBaseTokenAmount:await x(this.web3,t.baseTokenAddress,t.maxBaseTokenAmount,t.baseTokenDecimals),swapMarketFee:await x(this.web3,t.baseTokenAddress,t.swapMarketFee,t.baseTokenDecimals),marketFeeAddress:t.marketFeeAddress}}}class ot extends Y{getDefaultAbi(){return u.abi}async createNFT(t,e,a){var i,n,o,r;if(e.templateIndex||(e.templateIndex=1),!e.name||!e.symbol){const{name:t,symbol:a}=P();e.name=t,e.symbol=a}if(e.templateIndex>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e.templateIndex)throw new Error("Template index cannot be ZERO");if(!1===(await this.getNFTTemplate(e.templateIndex)).isActive)throw new Error("Template is not active");const s=await D(t,this.contract.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,b,b,e.tokenURI,e.transferable,e.owner);if(a)return s;const c=await A(t,s+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.deployERC721Contract,e.name,e.symbol,e.templateIndex,b,b,e.tokenURI,e.transferable,e.owner);return null==c||null==(n=c.events)||null==(o=n.NFTCreated)||null==(r=o.returnValues)?void 0:r[0]}async getCurrentNFTCount(){return await this.contract.methods.getCurrentNFTCount().call()}async getCurrentTokenCount(){return await this.contract.methods.getCurrentTokenCount().call()}async getOwner(){return await this.contract.methods.owner().call()}async getCurrentNFTTemplateCount(){return await this.contract.methods.getCurrentNFTTemplateCount().call()}async getCurrentTokenTemplateCount(){return await this.contract.methods.getCurrentTemplateCount().call()}async getNFTTemplate(t){if(t>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===t)throw new Error("Template index cannot be ZERO");return await this.contract.methods.getNFTTemplate(t).call()}async getTokenTemplate(t){return await this.contract.methods.getTokenTemplate(t).call()}async checkDatatoken(t){return await this.contract.methods.erc20List(t).call()}async checkNFT(t){return await this.contract.methods.erc721List(t).call()}async addNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===b)throw new Error("Template cannot be ZERO address");const n=await D(t,this.contract.methods.add721TokenTemplate,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.add721TokenTemplate,e)}async disableNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const n=await D(t,this.contract.methods.disable721TokenTemplate,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.disable721TokenTemplate,e)}async reactivateNFTTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentNFTTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");const n=await D(t,this.contract.methods.reactivate721TokenTemplate,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.reactivate721TokenTemplate,e)}async addTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e===b)throw new Error("Template cannot be address ZERO");const n=await D(t,this.contract.methods.addTokenTemplate,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.addTokenTemplate,e)}async disableTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!1===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already disabled");const n=await D(t,this.contract.methods.disableTokenTemplate,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.disableTokenTemplate,e)}async reactivateTokenTemplate(t,e,a){var i;if(await this.getOwner()!==t)throw new Error("Caller is not Factory Owner");if(e>await this.getCurrentTokenTemplateCount())throw new Error("Template index doesnt exist");if(0===e)throw new Error("Template index cannot be ZERO");if(!0===(await this.getTokenTemplate(e)).isActive)throw new Error("Template is already active");const n=await D(t,this.contract.methods.reactivateTokenTemplate,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.reactivateTokenTemplate,e)}async startMultipleTokenOrder(t,e,a){var i;if(e.length>50)throw new Error("Too many orders");const n=await D(t,this.contract.methods.startMultipleTokenOrder,e);return a?n:await A(t,n+1,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.startMultipleTokenOrder,e)}async createNftWithDatatoken(t,e,a,i){var n;const o=this.getErcCreationParams(a),r=await D(t,this.contract.methods.createNftWithErc20,e,o);return i?r:await A(t,r+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.createNftWithErc20,e,o)}async createNftWithDatatokenWithFixedRate(t,e,a,i,n){var o;const r=this.getErcCreationParams(a),s=this.getFreCreationParams(i),c=await D(t,this.contract.methods.createNftWithErc20WithFixedRate,e,r,s);return n?c:await A(t,c+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.createNftWithErc20WithFixedRate,e,r,s)}async createNftWithDatatokenWithDispenser(t,e,a,n,o){var r;const s=this.getErcCreationParams(a);n.maxBalance=i.utils.toWei(n.maxBalance),n.maxTokens=i.utils.toWei(n.maxTokens);const c=await D(t,this.contract.methods.createNftWithErc20WithDispenser,e,s,n);return o?c:await A(t,c+1,this.web3,null==(r=this.config)?void 0:r.gasFeeMultiplier,this.contract.methods.createNftWithErc20WithDispenser,e,s,n)}getErcCreationParams(t){let e,a;return t.name&&t.symbol||({name:e,symbol:a}=P()),{templateIndex:t.templateIndex,strings:[t.name||e,t.symbol||a],addresses:[t.minter,t.paymentCollector,t.mpFeeAddress,t.feeToken],uints:[i.utils.toWei(t.cap),i.utils.toWei(t.feeAmount)],bytess:[]}}getFreCreationParams(t){t.allowedConsumer||(t.allowedConsumer=b);const e=t.withMint?1:0;return{fixedPriceAddress:t.fixedRateAddress,addresses:[t.baseTokenAddress,t.owner,t.marketFeeCollector,t.allowedConsumer],uints:[t.baseTokenDecimals,t.datatokenDecimals,i.utils.toWei(t.fixedRate),i.utils.toWei(t.marketFee),e]}}}class rt extends Y{getDefaultAbi(){return w.abi}async lockTokens(t,e,a,i){var n;const o=await this.amountToUnits(await this.getToken(),e),r=await D(t,this.contract.methods.create_lock,o,a);return i?r:await A(t,r+2e4,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.create_lock,o,a)}async depositFor(t,e,a,i){var n;const o=await this.amountToUnits(await this.getToken(),a),r=await D(t,this.contract.methods.deposit_for,e,o);return i?r:await A(t,r+2e4,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.deposit_for,e,o)}async increaseAmount(t,e,a){var i;const n=await this.amountToUnits(await this.getToken(),e),o=await D(t,this.contract.methods.increase_amount,n);return a?o:await A(t,o+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.increase_amount,n)}async increaseUnlockTime(t,e,a){var i;const n=await D(t,this.contract.methods.increase_unlock_time,e);return a?n:await A(t,n+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.increase_unlock_time,e)}async withdraw(t,e){var a;const i=await D(t,this.contract.methods.withdraw);return e?i:await A(t,i+1,this.web3,null==(a=this.config)?void 0:a.gasFeeMultiplier,this.contract.methods.withdraw)}async getVotingPower(t){return await this.contract.methods.balanceOf(t).call()}async getLockedAmount(t){const e=await this.contract.methods.locked(t).call();return await this.unitsToAmount(await this.getToken(),e.amount)}async lockEnd(t){return await this.contract.methods.locked__end(t).call()}async totalSupply(){return await this.unitsToAmount(await this.getToken(),await this.contract.methods.totalSupply().call())}async getToken(){return await this.contract.methods.token().call()}}class st extends Y{getDefaultAbi(){return m.abi}async claim(t,e){var a;const i=await D(t,this.contract.methods.claim);return e?i:await A(t,i+2e4,this.web3,null==(a=this.config)?void 0:a.gasFeeMultiplier,this.contract.methods.claim)}async claimMany(t,e,a){var i;const n=await D(t,this.contract.methods.claim_many,e);return a?n:await A(t,n+2e4,this.web3,null==(i=this.config)?void 0:i.gasFeeMultiplier,this.contract.methods.claim_many,e)}}class ct extends Y{getDefaultAbi(){return p.abi}async setAllocation(t,e,a,i,n){var o;const r=await D(t,this.contract.methods.setAllocation,e,a,i);return n?r:await A(t,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.setAllocation,e,a,i)}async setBatchAllocation(t,e,a,i,n){var o;const r=await D(t,this.contract.methods.setBatchAllocation,e,a,i);return n?r:await A(t,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.setBatchAllocation,e,a,i)}async getTotalAllocation(t){return await this.contract.methods.getTotalAllocation(t).call()}async getVeAllocation(t,e,a){return await this.contract.methods.getveAllocation(t,e,a).call()}}class lt extends Y{getDefaultAbi(){return g.abi}async getAvailableRewards(t,e){const a=await this.contract.methods.claimable(t,e).call();return await this.unitsToAmount(e,a)}async claimRewards(t,e,a,i){var n;const o=await D(t,this.contract.methods.claimFor,e,a);return i?o:await A(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.claimFor,e,a)}async allocateRewards(t,e,a,i,n){var o;for(let t=0;t<a.length;t++)a[t]=await this.amountToUnits(i,a[t]);const r=await D(t,this.contract.methods.allocate,e,a,i);return n?r:await A(t,r+1,this.web3,null==(o=this.config)?void 0:o.gasFeeMultiplier,this.contract.methods.allocate,e,a,i)}}class ht extends Y{getDefaultAbi(){return f.abi}async getMultipleAvailableRewards(t,e){const a=await this.contract.methods.claimables(t,e).call(),i=[];for(let t=0;t<a.length;t++)i.push(await this.unitsToAmount(e[t],a[t]));return i}async claimMultipleRewards(t,e,a,i){var n;const o=await D(t,this.contract.methods.claimMultiple,e,a);return i?o:await A(t,o+1,this.web3,null==(n=this.config)?void 0:n.gasFeeMultiplier,this.contract.methods.claimMultiple,e,a)}}class dt{constructor(t){this.aquariusURL=void 0,this.aquariusURL=t}async resolve(t,e){const a=this.aquariusURL+"/api/aquarius/assets/ddo/"+t;try{const t=await n(a,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return await t.json();throw new Error("HTTP request failed with status "+t.status)}catch(t){throw L.error(t),new Error("HTTP request failed")}}async waitForAqua(t,e,a){let i=0;do{try{const i=this.aquariusURL+"/api/aquarius/assets/ddo/"+t,o=await n(i,{method:"GET",headers:{"Content-Type":"application/json"},signal:a});if(o.ok){const t=await o.json();if(!e)return t;if(t.event&&t.event.txid===e)return t}}catch(t){}await j(1500),i++}while(i<100);return null}async validate(t,e){const a={valid:!1};let i;try{const o=this.aquariusURL+"/api/aquarius/assets/ddo/validate",r=await n(o,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:e});i=await r.json(),200===r.status?(a.valid=!0,a.hash=i.hash,a.proof={validatorAddress:i.publicKey,r:i.r[0],s:i.s[0],v:i.v}):(a.errors=i,L.error("validate Metadata failed:",r.status,a.errors))}catch(t){L.error("Error validating metadata: ",t)}return a}async getAssetMetadata(t,e){const a=this.aquariusURL+"/api/aquarius/assets/metadata/"+t;try{const t=await n(a,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(t.ok)return t.json();throw new Error("getAssetMetadata failed: "+t.status+t.statusText)}catch(t){throw L.error("Error getting metadata: ",t),new Error("Error getting metadata: "+t)}}async querySearch(t,e){const a=this.aquariusURL+"/api/aquarius/assets/query";try{const i=await n(a,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json"},signal:e});if(i.ok)return i.json();throw new Error("querySearch failed: "+i.status+i.statusText)}catch(t){throw L.error("Error querying metadata: ",t),new Error("Error querying metadata: "+t)}}}class ut{async getEndpoints(t){try{const e=await this.getData(t);return await e.json()}catch(t){throw L.error("Finding the service endpoints failed:",t),new Error("HTTP request failed calling Provider")}}getEndpointURL(t,e){return t?t.find(t=>t.serviceName===e):null}async getServiceEndpoints(t,e){const a=[];for(const i in e.serviceEndpoints)a.push({serviceName:i,method:e.serviceEndpoints[i][0],urlPath:t+e.serviceEndpoints[i][1]});return a}async getNonce(t,e,a,i,o){i||(i=await this.getEndpoints(t)),o||(o=await this.getServiceEndpoints(t,i));const r=this.getEndpointURL(o,"nonce")?this.getEndpointURL(o,"nonce").urlPath:null;if(!r)return null;try{const t=await n(r+`?userAddress=${e}`,{method:"GET",headers:{"Content-Type":"application/json"},signal:a});return(await t.json()).nonce.toString()}catch(t){throw L.error(t),new Error("HTTP request failed calling Provider")}}async signProviderRequest(t,e,a,i){const n=t.utils.soliditySha3({t:"bytes",v:t.utils.utf8ToHex(a)});return t&&t.currentProvider&&t.currentProvider.isMetaMask?await t.eth.personal.sign(n,e,i):await t.eth.sign(n,e)}async encrypt(t,e,a){const i=await this.getEndpoints(e),o=await this.getServiceEndpoints(e,i),r=this.getEndpointURL(o,"encrypt")?this.getEndpointURL(o,"encrypt").urlPath:null;if(!r)return null;try{const e=await n(r,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/octet-stream"},signal:a});return await e.text()}catch(t){throw L.error(t),new Error("HTTP request failed calling Provider")}}async checkDidFiles(t,e,a,i=!1,o){const r=await this.getEndpoints(a),s=await this.getServiceEndpoints(a,r),c={did:t,serviceId:e,checksum:i},l=[],h=this.getEndpointURL(s,"fileinfo")?this.getEndpointURL(s,"fileinfo").urlPath:null;if(!h)return null;try{const t=await n(h,{method:"POST",body:JSON.stringify(c),headers:{"Content-Type":"application/json"},signal:o}),e=await t.json();for(const t of e)l.push(t);return l}catch(t){throw L.error(t),new Error("HTTP request failed calling Provider")}}async checkFileUrl(t,e,a){const i=await this.getEndpoints(e),o=await this.getServiceEndpoints(e,i),r={url:t,type:"url"},s=[],c=this.getEndpointURL(o,"fileinfo")?this.getEndpointURL(o,"fileinfo").urlPath:null;if(!c)return null;try{const t=await n(c,{method:"POST",body:JSON.stringify(r),headers:{"Content-Type":"application/json"},signal:a}),e=await t.json();for(const t of e)s.push(t);return s}catch(t){throw L.error(t),new Error("HTTP request failed calling Provider")}}async getComputeEnvironments(t,e){var a;const i=await this.getEndpoints(t),o=await this.getServiceEndpoints(t,i),r=null==(a=this.getEndpointURL(o,"computeEnvironments"))?void 0:a.urlPath;if(!r)return null;try{const t=await n(r,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});return await t.json()}catch(t){throw L.error(t),new Error("HTTP request failed calling Provider")}}async initialize(t,e,a,i,o,r,s,c,l){const h=await this.getEndpoints(o),d=await this.getServiceEndpoints(o,h);let u=this.getEndpointURL(d,"initialize")?this.getEndpointURL(d,"initialize").urlPath:null;if(!u)return null;u+=`?documentId=${t}`,u+=`&serviceId=${e}`,u+=`&fileIndex=${a}`,u+=`&consumerAddress=${i}`,s&&(u+="&userdata="+encodeURI(JSON.stringify(s))),c&&(u+="&environment="+encodeURI(c)),l&&(u+="&validUntil="+l);try{const t=await n(u,{method:"GET",headers:{"Content-Type":"application/json"},signal:r});return await t.json()}catch(t){throw L.error(t),new Error("Asset URL not found or not available.")}}async initializeCompute(t,e,a,i,o,r,s){const c=await this.getEndpoints(o),l=await this.getServiceEndpoints(o,c),h={datasets:t,algorithm:e,compute:{env:a,validUntil:i},consumerAddress:r},d=this.getEndpointURL(l,"initializeCompute")?this.getEndpointURL(l,"initializeCompute").urlPath:null;if(!d)return null;try{const t=await n(d,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json"},signal:s});return await t.json()}catch(t){throw L.error(t),new Error("ComputeJob cannot be initialized")}}async getDownloadUrl(t,e,a,i,n,o,r,s){const c=await this.getEndpoints(o),l=await this.getServiceEndpoints(o,c),h=this.getEndpointURL(l,"download")?this.getEndpointURL(l,"download").urlPath:null;if(!h)return null;const d=Date.now();let u=h;return u+=`?fileIndex=${i}`,u+=`&documentId=${t}`,u+=`&transferTxId=${n}`,u+=`&serviceId=${a}`,u+=`&consumerAddress=${e}`,u+=`&nonce=${d}`,u+=`&signature=${await this.signProviderRequest(r,e,t+d)}`,s&&(u+="&userdata="+encodeURI(JSON.stringify(s))),u}async computeStart(t,e,a,i,o,r,s,c,l){const h=await this.getEndpoints(t),d=await this.getServiceEndpoints(t,h),u=this.getEndpointURL(d,"computeStart")?this.getEndpointURL(d,"computeStart").urlPath:null,w=Date.now();let m=a;m+=o.documentId,m+=w;const p=await this.signProviderRequest(e,a,m),g=Object();if(g.consumerAddress=a,g.signature=p,g.nonce=w,g.environment=i,g.dataset=o,g.algorithm=r,g.additionalDatasets&&(g.additionalDatasets=c),l&&(g.output=l),!u)return null;try{const t=await n(u,{method:"POST",body:JSON.stringify(g),headers:{"Content-Type":"application/json"},signal:s});return null!=t&&t.ok?await t.json():(L.error("Compute start failed: ",t.status,t.statusText,await t.json()),L.error("Payload was:",g),null)}catch(t){throw L.error("Compute start failed:"),L.error(t),L.error("Payload was:",g),new Error("HTTP request failed calling Provider")}}async computeStop(t,e,a,i,o,r){const s=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,s),l=this.getEndpointURL(c,"computeStop")?this.getEndpointURL(c,"computeStop").urlPath:null,h=await this.getNonce(i,e,r,s,c);let d=e;d+=a||"",d+=t&&`${this.noZeroX(t)}`||"",d+=h;const u=await this.signProviderRequest(o,e,d),w=Object();if(w.signature=u,w.documentId=this.noZeroX(t),w.consumerAddress=e,a&&(w.jobId=a),!l)return null;try{const t=await n(l,{method:"PUT",body:JSON.stringify(w),headers:{"Content-Type":"application/json"},signal:r});return null!=t&&t.ok?await t.json():(L.error("Compute stop failed:",t.status,t.statusText),L.error("Payload was:",w),null)}catch(t){throw L.error("Compute stop failed:"),L.error(t),L.error("Payload was:",w),new Error("HTTP request failed calling Provider")}}async computeStatus(t,e,a,i,o){const r=await this.getEndpoints(t),s=await this.getServiceEndpoints(t,r),c=this.getEndpointURL(s,"computeStatus")?this.getEndpointURL(s,"computeStatus").urlPath:null;let l=`?consumerAddress=${e}`;if(l+=i&&`&documentId=${this.noZeroX(i)}`||"",l+=a&&`&jobId=${a}`||"",!c)return null;try{const t=await n(c+l,{method:"GET",headers:{"Content-Type":"application/json"},signal:o});return null!=t&&t.ok?await t.json():(L.error("Get compute status failed:",t.status,t.statusText),null)}catch(t){throw L.error("Get compute status failed"),L.error(t),new Error("HTTP request failed calling Provider")}}async getComputeResultUrl(t,e,a,i,n){const o=await this.getEndpoints(t),r=await this.getServiceEndpoints(t,o),s=this.getEndpointURL(r,"computeResult")?this.getEndpointURL(r,"computeResult").urlPath:null,c=Date.now();let l=a;l+=i,l+=n.toString(),l+=c;const h=await this.signProviderRequest(e,a,l);if(!s)return null;let d=s;return d+=`?consumerAddress=${a}`,d+=`&jobId=${i}`,d+=`&index=${n.toString()}`,d+=`&nonce=${c}`,d+=h&&`&signature=${h}`||"",d}async computeDelete(t,e,a,i,o,r){const s=await this.getEndpoints(i),c=await this.getServiceEndpoints(i,s),l=this.getEndpointURL(c,"computeDelete")?this.getEndpointURL(c,"computeDelete").urlPath:null,h=await this.getNonce(i,e,r,s,c);let d=e;d+=a||"",d+=t&&`${this.noZeroX(t)}`||"",d+=h;const u=await this.signProviderRequest(o,e,d),w=Object();if(w.documentId=this.noZeroX(t),w.consumerAddress=e,w.jobId=a,u&&(w.signature=u),!l)return null;try{const t=await n(l,{method:"DELETE",body:JSON.stringify(w),headers:{"Content-Type":"application/json"},signal:r});return null!=t&&t.ok?await t.json():(L.error("Delete compute job failed:",t.status,t.statusText),L.error("Payload was:",w),null)}catch(t){throw L.error("Delete compute job failed:"),L.error(t),L.error("Payload was:",w),new Error("HTTP request failed calling Provider")}}async isValidProvider(t,e){try{const a=await n(t,{method:"GET",headers:{"Content-Type":"application/json"},signal:e});if(null!=a&&a.ok){const t=await a.json();if(t&&t.providerAddress)return!0}return!1}catch(t){return L.error(`Error validating provider: ${t.message}`),!1}}noZeroX(t){return this.zeroXTransformer(t,!1)}zeroXTransformer(t="",e){const{valid:a,output:i}=this.inputMatch(t,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(e&&a?"0x":"")+i}inputMatch(t,e,a){if("string"!=typeof t)throw L.debug("Not input string:"),L.debug(t),new Error(`[${a}] Expected string, input type: ${typeof t}`);const i=t.match(e);return i?{valid:!0,output:i[1]}:(L.warn(`[${a}] Input transformation failed.`),{valid:!1,output:t})}async getData(t){return n(t,{method:"GET",headers:{"Content-type":"application/json"}})}}const wt=new ut;export{dt as Aquarius,v as Config,Q as ConfigHelper,nt as Datatoken,lt as DfRewards,ht as DfStrategyV1,tt as Dispenser,C as FEE_HISTORY_NOT_SUPPORTED,et as FixedRateExchange,T as GASLIMIT_DEFAULT,R as LogLevel,W as Logger,L as LoggerInstance,k as MAX_UINT_256,it as Nft,ot as NftFactory,ut as Provider,wt as ProviderInstance,at as Router,K as SmartContract,Y as SmartContractWithAddress,ct as VeAllocate,st as VeFeeDistributor,rt as VeOcean,b as ZERO_ADDRESS,G as allowance,z as allowanceWei,x as amountToUnits,$ as approve,_ as approveWei,Z as balance,D as calculateEstimatedGas,X as configHelperNetworks,J as decimals,I as downloadFile,N as downloadFileBrowser,O as generateDid,P as generateDtName,E as getFairGasPrice,S as getHash,B as minAbi,A as sendTx,F as setContractDefaults,q as signHash,j as sleep,H as transfer,M as unitsToAmount};
2
2
  //# sourceMappingURL=lib.modern.js.map