diff --git a/README.md b/README.md index 923a1c3..34e9577 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ Payment routes are provided in the following structure: fee: Object (e.g. undefined or fee object) feeAmount: BigNumber (e.g. ) exchangeRoutes: Array (list of exchange routes offering to convert ) + currentAllowance: BigNumber (e.g. ) approvalRequired: Boolean (e.g. true) approvalTransaction: Transaction (to approve the fromToken being used from the payment router to perform the payment) directTransfer: Boolean (e.g. true) @@ -337,6 +338,8 @@ Payment routes are provided in the following structure: `approvalRequired`: indicates if a upfront token approval is required in order to perform the payment, make sure you execute `approve` before executing the payment transaction itself. +`currentAllowance`: provides the current set allowance as BigNumber. + `directTransfer`: indicates if the payment does not require any swapping/exchanging. See [@depay/web3-wallets](https://github.com/DePayFi/web3-wallets#sendtransaction) for details about the transaction format. diff --git a/dev.html b/dev.html index 0988fba..044066c 100644 --- a/dev.html +++ b/dev.html @@ -5,7 +5,7 @@ Development - + diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index bc86928..b1e17d2 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -47261,10 +47261,10 @@ const getConfiguration = () =>{ return getWindow()._Web3ClientConfiguration }; -function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } +function _optionalChain$5$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL$1 = 10; const CHUNK_SIZE$1 = 99; -const MAX_RETRY$1 = 3; +const MAX_RETRY$1 = 5; class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { @@ -47292,12 +47292,12 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$3$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$5$1([payload, 'optionalAccess', _ => _.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.result])) { + } else if(_optionalChain$5$1([payload, 'optionalAccess', _2 => _2.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); @@ -47372,6 +47372,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { } +function _optionalChain$4$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders$1 = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -47417,17 +47418,20 @@ const setProviderEndpoints$2 = async (blockchain, endpoints, detectFastest = tru let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$4$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -47482,10 +47486,10 @@ var EVM = { setProvider: setProvider$2, }; -function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } +function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL = 10; const CHUNK_SIZE = 99; -const MAX_RETRY = 3; +const MAX_RETRY = 10; class StaticJsonRpcSequentialProvider extends Connection { @@ -47501,9 +47505,7 @@ class StaticJsonRpcSequentialProvider extends Connection { } handleError(error, attempt, chunk) { - if(attempt < MAX_RETRY && error && [ - 'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400' - ].some((errorType)=>error.toString().match(errorType))) { + if(attempt < MAX_RETRY) { const index = this._endpoints.indexOf(this._endpoint)+1; this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; this._provider = new Connection(this._endpoint); @@ -47533,7 +47535,15 @@ class StaticJsonRpcSequentialProvider extends Connection { ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - resolve(parsedJson); + if(parsedJson.find((entry)=>_optionalChain$3$1([entry, 'optionalAccess', _ => _.error]))) { + if(attempt < MAX_RETRY) { + reject('Error in batch found!'); + } else { + resolve(parsedJson); + } + } else { + resolve(parsedJson); + } }).catch(reject); } else { reject(`${response.status} ${response.text}`); @@ -47551,7 +47561,7 @@ class StaticJsonRpcSequentialProvider extends Connection { .then((result) => { chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; @@ -47608,6 +47618,7 @@ class StaticJsonRpcSequentialProvider extends Connection { } } +function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -47653,17 +47664,20 @@ const setProviderEndpoints$1 = async (blockchain, endpoints, detectFastest = tru let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$2$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -50644,6 +50658,7 @@ class PaymentRoute { feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -50660,6 +50675,7 @@ class PaymentRoute { this.fee = fee; this.feeAmount = feeAmount; this.exchangeRoutes = exchangeRoutes || []; + this.currentAllowance = currentAllowance; this.approvalRequired = approvalRequired; this.approvalTransaction = approvalTransaction; this.directTransfer = directTransfer; @@ -50949,6 +50965,7 @@ let addApproval = (routes) => { ) { routes[index].approvalRequired = false; } else { + routes[index].currentAllowance = ethers.BigNumber.from(allowances[index]); routes[index].approvalRequired = ethers.BigNumber.from(route.fromAmount).gte(ethers.BigNumber.from(allowances[index])); if(routes[index].approvalRequired) { routes[index].approvalTransaction = { diff --git a/dist/esm/index.js b/dist/esm/index.js index 36441a0..ef6cff7 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -132,10 +132,10 @@ const getConfiguration = () =>{ return getWindow()._Web3ClientConfiguration }; -function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } +function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL$1 = 10; const CHUNK_SIZE$1 = 99; -const MAX_RETRY$1 = 3; +const MAX_RETRY$1 = 5; class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { @@ -163,12 +163,12 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$5([payload, 'optionalAccess', _ => _.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) { + } else if(_optionalChain$5([payload, 'optionalAccess', _2 => _2.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); @@ -243,6 +243,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { } +function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders$1 = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -288,17 +289,20 @@ const setProviderEndpoints$2 = async (blockchain, endpoints, detectFastest = tru let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$4([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -353,10 +357,10 @@ var EVM = { setProvider: setProvider$2, }; -function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } +function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL = 10; const CHUNK_SIZE = 99; -const MAX_RETRY = 3; +const MAX_RETRY = 10; class StaticJsonRpcSequentialProvider extends Connection { @@ -372,9 +376,7 @@ class StaticJsonRpcSequentialProvider extends Connection { } handleError(error, attempt, chunk) { - if(attempt < MAX_RETRY && error && [ - 'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400' - ].some((errorType)=>error.toString().match(errorType))) { + if(attempt < MAX_RETRY) { const index = this._endpoints.indexOf(this._endpoint)+1; this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; this._provider = new Connection(this._endpoint); @@ -404,7 +406,15 @@ class StaticJsonRpcSequentialProvider extends Connection { ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - resolve(parsedJson); + if(parsedJson.find((entry)=>_optionalChain$3([entry, 'optionalAccess', _ => _.error]))) { + if(attempt < MAX_RETRY) { + reject('Error in batch found!'); + } else { + resolve(parsedJson); + } + } else { + resolve(parsedJson); + } }).catch(reject); } else { reject(`${response.status} ${response.text}`); @@ -422,7 +432,7 @@ class StaticJsonRpcSequentialProvider extends Connection { .then((result) => { chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$3([payload, 'optionalAccess', _2 => _2.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; @@ -479,6 +489,7 @@ class StaticJsonRpcSequentialProvider extends Connection { } } +function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -524,17 +535,20 @@ const setProviderEndpoints$1 = async (blockchain, endpoints, detectFastest = tru let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$2([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -2212,6 +2226,7 @@ class PaymentRoute { feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -2228,6 +2243,7 @@ class PaymentRoute { this.fee = fee; this.feeAmount = feeAmount; this.exchangeRoutes = exchangeRoutes || []; + this.currentAllowance = currentAllowance; this.approvalRequired = approvalRequired; this.approvalTransaction = approvalTransaction; this.directTransfer = directTransfer; @@ -2517,6 +2533,7 @@ let addApproval = (routes) => { ) { routes[index].approvalRequired = false; } else { + routes[index].currentAllowance = ethers.BigNumber.from(allowances[index]); routes[index].approvalRequired = ethers.BigNumber.from(route.fromAmount).gte(ethers.BigNumber.from(allowances[index])); if(routes[index].approvalRequired) { routes[index].approvalTransaction = { diff --git a/dist/esm/index.solana.js b/dist/esm/index.solana.js index 2e67eeb..5b63493 100644 --- a/dist/esm/index.solana.js +++ b/dist/esm/index.solana.js @@ -132,10 +132,10 @@ const getConfiguration = () =>{ return getWindow()._Web3ClientConfiguration }; -function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } +function _optionalChain$5$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL$1 = 10; const CHUNK_SIZE$1 = 99; -const MAX_RETRY$1 = 3; +const MAX_RETRY$1 = 5; class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { @@ -163,12 +163,12 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$3$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$5$1([payload, 'optionalAccess', _ => _.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.result])) { + } else if(_optionalChain$5$1([payload, 'optionalAccess', _2 => _2.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); @@ -243,6 +243,7 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { } +function _optionalChain$4$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders$1 = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -288,17 +289,20 @@ const setProviderEndpoints$2 = async (blockchain, endpoints, detectFastest = tru let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$4$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -353,10 +357,10 @@ var EVM = { setProvider: setProvider$2, }; -function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } +function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL = 10; const CHUNK_SIZE = 99; -const MAX_RETRY = 3; +const MAX_RETRY = 10; class StaticJsonRpcSequentialProvider extends Connection { @@ -372,9 +376,7 @@ class StaticJsonRpcSequentialProvider extends Connection { } handleError(error, attempt, chunk) { - if(attempt < MAX_RETRY && error && [ - 'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400' - ].some((errorType)=>error.toString().match(errorType))) { + if(attempt < MAX_RETRY) { const index = this._endpoints.indexOf(this._endpoint)+1; this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; this._provider = new Connection(this._endpoint); @@ -404,7 +406,15 @@ class StaticJsonRpcSequentialProvider extends Connection { ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - resolve(parsedJson); + if(parsedJson.find((entry)=>_optionalChain$3$1([entry, 'optionalAccess', _ => _.error]))) { + if(attempt < MAX_RETRY) { + reject('Error in batch found!'); + } else { + resolve(parsedJson); + } + } else { + resolve(parsedJson); + } }).catch(reject); } else { reject(`${response.status} ${response.text}`); @@ -422,7 +432,7 @@ class StaticJsonRpcSequentialProvider extends Connection { .then((result) => { chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; @@ -479,6 +489,7 @@ class StaticJsonRpcSequentialProvider extends Connection { } } +function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -524,17 +535,20 @@ const setProviderEndpoints$1 = async (blockchain, endpoints, detectFastest = tru let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$2$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -3329,6 +3343,7 @@ class PaymentRoute { feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -3345,6 +3360,7 @@ class PaymentRoute { this.fee = fee; this.feeAmount = feeAmount; this.exchangeRoutes = exchangeRoutes || []; + this.currentAllowance = currentAllowance; this.approvalRequired = approvalRequired; this.approvalTransaction = approvalTransaction; this.directTransfer = directTransfer; @@ -3634,6 +3650,7 @@ let addApproval = (routes) => { ) { routes[index].approvalRequired = false; } else { + routes[index].currentAllowance = ethers.BigNumber.from(allowances[index]); routes[index].approvalRequired = ethers.BigNumber.from(route.fromAmount).gte(ethers.BigNumber.from(allowances[index])); if(routes[index].approvalRequired) { routes[index].approvalTransaction = { diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 0741558..aa10e1e 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -47267,10 +47267,10 @@ return getWindow()._Web3ClientConfiguration }; - function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } + function _optionalChain$5$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL$1 = 10; const CHUNK_SIZE$1 = 99; - const MAX_RETRY$1 = 3; + const MAX_RETRY$1 = 5; class StaticJsonRpcBatchProvider extends ethers.ethers.providers.JsonRpcProvider { @@ -47298,12 +47298,12 @@ // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$3$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$5$1([payload, 'optionalAccess', _ => _.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.result])) { + } else if(_optionalChain$5$1([payload, 'optionalAccess', _2 => _2.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); @@ -47378,6 +47378,7 @@ } + function _optionalChain$4$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders$1 = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -47423,17 +47424,20 @@ let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$4$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -47488,10 +47492,10 @@ setProvider: setProvider$2, }; - function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } + function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL = 10; const CHUNK_SIZE = 99; - const MAX_RETRY = 3; + const MAX_RETRY = 10; class StaticJsonRpcSequentialProvider extends Connection { @@ -47507,9 +47511,7 @@ } handleError(error, attempt, chunk) { - if(attempt < MAX_RETRY && error && [ - 'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400' - ].some((errorType)=>error.toString().match(errorType))) { + if(attempt < MAX_RETRY) { const index = this._endpoints.indexOf(this._endpoint)+1; this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; this._provider = new Connection(this._endpoint); @@ -47539,7 +47541,15 @@ ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - resolve(parsedJson); + if(parsedJson.find((entry)=>_optionalChain$3$1([entry, 'optionalAccess', _ => _.error]))) { + if(attempt < MAX_RETRY) { + reject('Error in batch found!'); + } else { + resolve(parsedJson); + } + } else { + resolve(parsedJson); + } }).catch(reject); } else { reject(`${response.status} ${response.text}`); @@ -47557,7 +47567,7 @@ .then((result) => { chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; @@ -47614,6 +47624,7 @@ } } + function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -47659,17 +47670,20 @@ let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$2$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -50650,6 +50664,7 @@ feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -50666,6 +50681,7 @@ this.fee = fee; this.feeAmount = feeAmount; this.exchangeRoutes = exchangeRoutes || []; + this.currentAllowance = currentAllowance; this.approvalRequired = approvalRequired; this.approvalTransaction = approvalTransaction; this.directTransfer = directTransfer; @@ -50955,6 +50971,7 @@ ) { routes[index].approvalRequired = false; } else { + routes[index].currentAllowance = ethers.ethers.BigNumber.from(allowances[index]); routes[index].approvalRequired = ethers.ethers.BigNumber.from(route.fromAmount).gte(ethers.ethers.BigNumber.from(allowances[index])); if(routes[index].approvalRequired) { routes[index].approvalTransaction = { diff --git a/dist/umd/index.js b/dist/umd/index.js index c7d0100..3eb4d29 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -137,10 +137,10 @@ return getWindow()._Web3ClientConfiguration }; - function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } + function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL$1 = 10; const CHUNK_SIZE$1 = 99; - const MAX_RETRY$1 = 3; + const MAX_RETRY$1 = 5; class StaticJsonRpcBatchProvider extends ethers.ethers.providers.JsonRpcProvider { @@ -168,12 +168,12 @@ // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$5([payload, 'optionalAccess', _ => _.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) { + } else if(_optionalChain$5([payload, 'optionalAccess', _2 => _2.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); @@ -248,6 +248,7 @@ } + function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders$1 = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -293,17 +294,20 @@ let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$4([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -358,10 +362,10 @@ setProvider: setProvider$2, }; - function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } + function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL = 10; const CHUNK_SIZE = 99; - const MAX_RETRY = 3; + const MAX_RETRY = 10; class StaticJsonRpcSequentialProvider extends solanaWeb3_js.Connection { @@ -377,9 +381,7 @@ } handleError(error, attempt, chunk) { - if(attempt < MAX_RETRY && error && [ - 'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400' - ].some((errorType)=>error.toString().match(errorType))) { + if(attempt < MAX_RETRY) { const index = this._endpoints.indexOf(this._endpoint)+1; this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; this._provider = new solanaWeb3_js.Connection(this._endpoint); @@ -409,7 +411,15 @@ ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - resolve(parsedJson); + if(parsedJson.find((entry)=>_optionalChain$3([entry, 'optionalAccess', _ => _.error]))) { + if(attempt < MAX_RETRY) { + reject('Error in batch found!'); + } else { + resolve(parsedJson); + } + } else { + resolve(parsedJson); + } }).catch(reject); } else { reject(`${response.status} ${response.text}`); @@ -427,7 +437,7 @@ .then((result) => { chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$3([payload, 'optionalAccess', _2 => _2.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; @@ -484,6 +494,7 @@ } } + function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -529,17 +540,20 @@ let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$2([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -2217,6 +2231,7 @@ feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -2233,6 +2248,7 @@ this.fee = fee; this.feeAmount = feeAmount; this.exchangeRoutes = exchangeRoutes || []; + this.currentAllowance = currentAllowance; this.approvalRequired = approvalRequired; this.approvalTransaction = approvalTransaction; this.directTransfer = directTransfer; @@ -2522,6 +2538,7 @@ ) { routes[index].approvalRequired = false; } else { + routes[index].currentAllowance = ethers.ethers.BigNumber.from(allowances[index]); routes[index].approvalRequired = ethers.ethers.BigNumber.from(route.fromAmount).gte(ethers.ethers.BigNumber.from(allowances[index])); if(routes[index].approvalRequired) { routes[index].approvalTransaction = { diff --git a/dist/umd/index.solana.js b/dist/umd/index.solana.js index ef52512..81abbb5 100644 --- a/dist/umd/index.solana.js +++ b/dist/umd/index.solana.js @@ -137,10 +137,10 @@ return getWindow()._Web3ClientConfiguration }; - function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } + function _optionalChain$5$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL$1 = 10; const CHUNK_SIZE$1 = 99; - const MAX_RETRY$1 = 3; + const MAX_RETRY$1 = 5; class StaticJsonRpcBatchProvider extends ethers.ethers.providers.JsonRpcProvider { @@ -168,12 +168,12 @@ // on whether it was a success or error chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$3$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$5$1([payload, 'optionalAccess', _ => _.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; inflightRequest.reject(error); - } else if(_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.result])) { + } else if(_optionalChain$5$1([payload, 'optionalAccess', _2 => _2.result])) { inflightRequest.resolve(payload.result); } else { inflightRequest.reject(); @@ -248,6 +248,7 @@ } + function _optionalChain$4$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders$1 = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -293,17 +294,20 @@ let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'net_version', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$4$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -358,10 +362,10 @@ setProvider: setProvider$2, }; - function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } + function _optionalChain$3$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const BATCH_INTERVAL = 10; const CHUNK_SIZE = 99; - const MAX_RETRY = 3; + const MAX_RETRY = 10; class StaticJsonRpcSequentialProvider extends solanaWeb3_js.Connection { @@ -377,9 +381,7 @@ } handleError(error, attempt, chunk) { - if(attempt < MAX_RETRY && error && [ - 'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400' - ].some((errorType)=>error.toString().match(errorType))) { + if(attempt < MAX_RETRY) { const index = this._endpoints.indexOf(this._endpoint)+1; this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; this._provider = new solanaWeb3_js.Connection(this._endpoint); @@ -409,7 +411,15 @@ ).then((response)=>{ if(response.ok) { response.json().then((parsedJson)=>{ - resolve(parsedJson); + if(parsedJson.find((entry)=>_optionalChain$3$1([entry, 'optionalAccess', _ => _.error]))) { + if(attempt < MAX_RETRY) { + reject('Error in batch found!'); + } else { + resolve(parsedJson); + } + } else { + resolve(parsedJson); + } }).catch(reject); } else { reject(`${response.status} ${response.text}`); @@ -427,7 +437,7 @@ .then((result) => { chunk.forEach((inflightRequest, index) => { const payload = result[index]; - if (_optionalChain$2$1([payload, 'optionalAccess', _ => _.error])) { + if (_optionalChain$3$1([payload, 'optionalAccess', _2 => _2.error])) { const error = new Error(payload.error.message); error.code = payload.error.code; error.data = payload.error.data; @@ -484,6 +494,7 @@ } } + function _optionalChain$2$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } const getAllProviders = ()=> { if(getWindow()._Web3ClientProviders == undefined) { getWindow()._Web3ClientProviders = {}; @@ -529,17 +540,20 @@ let timeout = 900; let before = new Date().getTime(); setTimeout(()=>resolve(timeout), timeout); - const response = await fetch(endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - referrer: "", - referrerPolicy: "no-referrer", - body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) - }); - if(!response.ok) { return resolve(999) } + let response; + try { + response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + referrer: "", + referrerPolicy: "no-referrer", + body: JSON.stringify({ method: 'getIdentity', id: 1, jsonrpc: '2.0' }) + }); + } catch (e) {} + if(!_optionalChain$2$1([response, 'optionalAccess', _ => _.ok])) { return resolve(999) } let after = new Date().getTime(); resolve(after-before); }) @@ -3334,6 +3348,7 @@ feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -3350,6 +3365,7 @@ this.fee = fee; this.feeAmount = feeAmount; this.exchangeRoutes = exchangeRoutes || []; + this.currentAllowance = currentAllowance; this.approvalRequired = approvalRequired; this.approvalTransaction = approvalTransaction; this.directTransfer = directTransfer; @@ -3639,6 +3655,7 @@ ) { routes[index].approvalRequired = false; } else { + routes[index].currentAllowance = ethers.ethers.BigNumber.from(allowances[index]); routes[index].approvalRequired = ethers.ethers.BigNumber.from(route.fromAmount).gte(ethers.ethers.BigNumber.from(allowances[index])); if(routes[index].approvalRequired) { routes[index].approvalTransaction = { diff --git a/package.evm.json b/package.evm.json index a3e1be1..aa217ba 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-payments-evm", "moduleName": "Web3Payments", - "version": "13.9.2", + "version": "13.10.0", "description": "JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", diff --git a/package.json b/package.json index 4976741..03a5a62 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-payments", "moduleName": "Web3Payments", - "version": "13.9.2", + "version": "13.10.0", "description": "JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index e0d92a9..2d8d5b1 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-payments-solana", "moduleName": "Web3Payments", - "version": "13.9.2", + "version": "13.10.0", "description": "JavaScript library to scan crypto wallets for liquefiable assets and perform cost-effective, auto-converted payments on-chain.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js", diff --git a/src/route.js b/src/route.js index 1805d40..9c67277 100644 --- a/src/route.js +++ b/src/route.js @@ -42,6 +42,7 @@ class PaymentRoute { feeAmount, exchangeRoutes, approvalRequired, + currentAllowance, approvalTransaction, directTransfer, }) { @@ -58,6 +59,7 @@ class PaymentRoute { this.fee = fee this.feeAmount = feeAmount this.exchangeRoutes = exchangeRoutes || [] + this.currentAllowance = currentAllowance this.approvalRequired = approvalRequired this.approvalTransaction = approvalTransaction this.directTransfer = directTransfer @@ -347,6 +349,7 @@ let addApproval = (routes) => { ) { routes[index].approvalRequired = false } else { + routes[index].currentAllowance = ethers.BigNumber.from(allowances[index]) routes[index].approvalRequired = ethers.BigNumber.from(route.fromAmount).gte(ethers.BigNumber.from(allowances[index])) if(routes[index].approvalRequired) { routes[index].approvalTransaction = {