Skip to content

Commit

Permalink
v13.11.0: switch to Uniswap V3 Router2
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Oct 4, 2024
1 parent 72b252b commit 4c52729
Show file tree
Hide file tree
Showing 16 changed files with 473 additions and 257 deletions.
4 changes: 2 additions & 2 deletions dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/5.7.1/ethers.umd.min.js" type="application/javascript"></script>
<script crossorigin src="https://unpkg.com/@depay/solana-web3.js@1"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-blockchains@9"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-client@10"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-client@10.19.1"></script>
<script crossorigin src="https://unpkg.com/@depay/walletconnect-v2@2"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-wallets@17"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-tokens@10"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-assets@7"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-exchanges@13"></script>
<script crossorigin src="https://unpkg.com/@depay/web3-exchanges@13.10.0"></script>
<script src="tmp/index.dev.js"></script>
<link rel="stylesheet" href="https://unpkg.com/bootstrap@4/dist/css/bootstrap.css">
<style>
Expand Down
104 changes: 71 additions & 33 deletions dist/esm/index.evm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47263,7 +47263,7 @@ const getConfiguration = () =>{

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 CHUNK_SIZE$1 = 50;
const MAX_RETRY$1 = 5;

class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
Expand All @@ -47277,51 +47277,81 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
this._pendingBatch = [];
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY$1 && error) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
}

detectNetwork() {
return Promise.resolve(Blockchains.findByName(this._network).id)
}

batchRequest(batch, attempt) {
return new Promise((resolve, reject) => {

if (batch.length === 0) resolve([]); // Do nothing if requests is empty

fetch(
this._endpoint,
{
method: 'POST',
body: JSON.stringify(batch),
headers: { 'Content-Type': 'application/json' },
}
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
if(parsedJson.find((entry)=>{
return _optionalChain$5$1([entry, 'optionalAccess', _ => _.error]) && [-32062,-32016].includes(_optionalChain$5$1([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code]))
})) {
if(attempt < MAX_RETRY$1) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
}
}).catch(reject);
})
}

requestChunk(chunk, endpoint, attempt) {

try {
const batch = chunk.map((inflight) => inflight.request);

const request = chunk.map((inflight) => inflight.request);
return ethers.utils.fetchJson(endpoint, JSON.stringify(request))
try {
return this.batchRequest(batch, attempt)
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$5$1([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$5$1([payload, 'optionalAccess', _4 => _4.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$5$1([payload, 'optionalAccess', _2 => _2.result])) {
} else if(_optionalChain$5$1([payload, 'optionalAccess', _5 => _5.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(attempt < MAX_RETRY$1 && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}).catch((error) => this.handleError(error, attempt, chunk))
} catch (error){ this.handleError(error, attempt, chunk); }
}

send(method, params) {
Expand Down Expand Up @@ -47381,6 +47411,7 @@ const getAllProviders$1 = ()=> {
};

const setProvider$2 = (blockchain, provider)=> {
if(provider == undefined) { return }
if(getAllProviders$1()[blockchain] === undefined) { getAllProviders$1()[blockchain] = []; }
const index = getAllProviders$1()[blockchain].indexOf(provider);
if(index > -1) {
Expand Down Expand Up @@ -47488,7 +47519,7 @@ var EVM = {

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 CHUNK_SIZE = 50;
const MAX_RETRY = 10;

class StaticJsonRpcSequentialProvider extends Connection {
Expand Down Expand Up @@ -47627,6 +47658,7 @@ const getAllProviders = ()=> {
};

const setProvider$1 = (blockchain, provider)=> {
if(provider == undefined) { return }
if(getAllProviders()[blockchain] === undefined) { getAllProviders()[blockchain] = []; }
const index = getAllProviders()[blockchain].indexOf(provider);
if(index > -1) {
Expand Down Expand Up @@ -47732,8 +47764,8 @@ var Solana = {
setProvider: setProvider$1,
};

let supported$2 = ['ethereum', 'bsc', 'polygon', 'solana', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base'];
supported$2.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base'];
let supported$2 = ['ethereum', 'bsc', 'polygon', 'solana', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain'];
supported$2.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain'];
supported$2.solana = ['solana'];

function _optionalChain$1$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; }
Expand Down Expand Up @@ -48096,7 +48128,7 @@ var allowanceOnEVM = ({ blockchain, address, api, owner, spender })=>{
api,
method: 'allowance',
params: [owner, spender],
cache: 5000, // 5 seconds
// no cache for allowance!
},
)
};
Expand All @@ -48108,7 +48140,6 @@ var balanceOnEVM = async ({ blockchain, address, account, api, id })=>{
blockchain: blockchain,
address: account,
method: 'balance',
cache: 10000, // 10 seconds
},
)
} else {
Expand All @@ -48119,7 +48150,6 @@ var balanceOnEVM = async ({ blockchain, address, account, api, id })=>{
method: 'balanceOf',
api,
params: id ? [account, id] : [account],
cache: 10000, // 10 seconds
},
)
}
Expand Down Expand Up @@ -49175,8 +49205,8 @@ var symbolOnSolana = async ({ blockchain, address })=>{
return _optionalChain$1([metaData, 'optionalAccess', _ => _.symbol])
};

let supported$1 = ['ethereum', 'bsc', 'polygon', 'solana', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base'];
supported$1.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base'];
let supported$1 = ['ethereum', 'bsc', 'polygon', 'solana', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain'];
supported$1.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain'];
supported$1.solana = ['solana'];

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; }
Expand Down Expand Up @@ -49371,6 +49401,14 @@ Token.base = {
WRAPPED: WETH,
};

Token.worldchain = {
DEFAULT: ERC20,
ERC20: ERC20,
20: ERC20,
1155: ERC1155,
WRAPPED: WETH,
};

Token.solana = {
MINT_LAYOUT,
METADATA_LAYOUT,
Expand Down
88 changes: 60 additions & 28 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const getConfiguration = () =>{

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 CHUNK_SIZE$1 = 50;
const MAX_RETRY$1 = 5;

class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
Expand All @@ -148,51 +148,81 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider {
this._pendingBatch = [];
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY$1 && error) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
}

detectNetwork() {
return Promise.resolve(Blockchains.findByName(this._network).id)
}

batchRequest(batch, attempt) {
return new Promise((resolve, reject) => {

if (batch.length === 0) resolve([]); // Do nothing if requests is empty

fetch(
this._endpoint,
{
method: 'POST',
body: JSON.stringify(batch),
headers: { 'Content-Type': 'application/json' },
}
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
if(parsedJson.find((entry)=>{
return _optionalChain$5([entry, 'optionalAccess', _ => _.error]) && [-32062,-32016].includes(_optionalChain$5([entry, 'optionalAccess', _2 => _2.error, 'optionalAccess', _3 => _3.code]))
})) {
if(attempt < MAX_RETRY$1) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
}
}).catch(reject);
})
}

requestChunk(chunk, endpoint, attempt) {

try {
const batch = chunk.map((inflight) => inflight.request);

const request = chunk.map((inflight) => inflight.request);
return ethers.utils.fetchJson(endpoint, JSON.stringify(request))
try {
return this.batchRequest(batch, attempt)
.then((result) => {
// For each result, feed it to the correct Promise, depending
// on whether it was a success or error
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$5([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$5([payload, 'optionalAccess', _4 => _4.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
inflightRequest.reject(error);
} else if(_optionalChain$5([payload, 'optionalAccess', _2 => _2.result])) {
} else if(_optionalChain$5([payload, 'optionalAccess', _5 => _5.result])) {
inflightRequest.resolve(payload.result);
} else {
inflightRequest.reject();
}
});
}).catch((error) => {
if(attempt < MAX_RETRY$1 && error && error.code == 'SERVER_ERROR') {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._failover();
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this.requestChunk(chunk, this._endpoint, attempt+1);
} else {
chunk.forEach((inflightRequest) => {
inflightRequest.reject(error);
});
}
})

} catch (e) {

chunk.forEach((inflightRequest) => {
inflightRequest.reject();
});
}
}).catch((error) => this.handleError(error, attempt, chunk))
} catch (error){ this.handleError(error, attempt, chunk); }
}

send(method, params) {
Expand Down Expand Up @@ -252,6 +282,7 @@ const getAllProviders$1 = ()=> {
};

const setProvider$2 = (blockchain, provider)=> {
if(provider == undefined) { return }
if(getAllProviders$1()[blockchain] === undefined) { getAllProviders$1()[blockchain] = []; }
const index = getAllProviders$1()[blockchain].indexOf(provider);
if(index > -1) {
Expand Down Expand Up @@ -359,7 +390,7 @@ var EVM = {

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 CHUNK_SIZE = 50;
const MAX_RETRY = 10;

class StaticJsonRpcSequentialProvider extends Connection {
Expand Down Expand Up @@ -498,6 +529,7 @@ const getAllProviders = ()=> {
};

const setProvider$1 = (blockchain, provider)=> {
if(provider == undefined) { return }
if(getAllProviders()[blockchain] === undefined) { getAllProviders()[blockchain] = []; }
const index = getAllProviders()[blockchain].indexOf(provider);
if(index > -1) {
Expand Down Expand Up @@ -603,8 +635,8 @@ var Solana = {
setProvider: setProvider$1,
};

let supported$1 = ['ethereum', 'bsc', 'polygon', 'solana', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base'];
supported$1.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base'];
let supported$1 = ['ethereum', 'bsc', 'polygon', 'solana', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain'];
supported$1.evm = ['ethereum', 'bsc', 'polygon', 'fantom', 'arbitrum', 'avalanche', 'gnosis', 'optimism', 'base', 'worldchain'];
supported$1.solana = ['solana'];

function _optionalChain$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; }
Expand Down
Loading

0 comments on commit 4c52729

Please sign in to comment.