Skip to content

Commit

Permalink
Merge pull request #14 from 1inch/chore/deps_update
Browse files Browse the repository at this point in the history
chore(deps): use ethers@5 instead of old web3
  • Loading branch information
krboktv authored Jul 10, 2023
2 parents 4017831 + 4f26347 commit 69cf368
Show file tree
Hide file tree
Showing 5 changed files with 817 additions and 805 deletions.
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/multicall",
"version": "1.0.8",
"version": "1.0.9",
"description": "High-weight optimized call-processor",
"repository": {
"type": "git",
Expand All @@ -21,10 +21,10 @@
"release": "standard-version"
},
"dependencies": {
"@ethersproject/bignumber": "^5.2.0",
"web3": "1.8.1"
"ethers": "5"
},
"devDependencies": {
"web3": "1.8.1",
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
Expand All @@ -51,10 +51,7 @@
"tslib": "^2.2.0",
"typescript": "^4.2.4"
},
"peerDependencies": {
"assert": "^2.0.0",
"stream": "^0.0.2"
},
"peerDependencies": {},
"publishConfig": {
"registry": "https://npm.pkg.github.com/1inch"
},
Expand Down
2 changes: 1 addition & 1 deletion src/connector/provider.connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export interface ProviderConnector {
decodeABIParameter<T>(type: string | SolStructType, hex: string): T;

decodeABIParameterList<T>(type: string[] | SolStructType[], hex: string): T;
}
}
40 changes: 22 additions & 18 deletions src/connector/web3-provider.connector.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import {ProviderConnector, SolStructType} from './provider.connector';
import Web3 from 'web3';
import {AbiItem} from '../model/abi.model';
import {AbiItem as Web3AbiItem} from 'web3-utils';
import Contract from 'web3-eth-contract'
import {Interface, defaultAbiCoder, ParamType} from 'ethers/lib/utils';

export class Web3ProviderConnector implements ProviderConnector {
type Web3 = {
eth: {
call(callInfo: { data: string, to: string }, blockNumber: number | string): Promise<string>
}
}

export class Web3ProviderConnector implements ProviderConnector {
constructor(protected readonly web3Provider: Web3) {
// eslint-disable-next-line
// @ts-ignore
Contract.setProvider(web3Provider.currentProvider)
}

contractEncodeABI(
abi: AbiItem[],
address: string | null,
_address: string | null,
methodName: string,
methodParams: unknown[]
): string {
// eslint-disable-next-line
// @ts-ignore
const contract = new Contract(
abi as Web3AbiItem[],
address === null ? undefined : address
);
return contract.methods[methodName](...methodParams).encodeABI();

return new Interface(
abi,
).encodeFunctionData(methodName, methodParams);
}

ethCall(
Expand All @@ -42,10 +39,17 @@ export class Web3ProviderConnector implements ProviderConnector {
}

decodeABIParameter<T>(type: string | SolStructType, hex: string): T {
return this.web3Provider.eth.abi.decodeParameter(type, hex) as T;
return this.decodeABIParameterList<[T]>([type], hex)[0];
}

decodeABIParameterList<T>(type: string[] | SolStructType[], hex: string): T {
return this.web3Provider.eth.abi.decodeParameters(type, hex) as T;
decodeABIParameterList<T>(type: (string | SolStructType)[], hex: string): T {
const types = type.map((t) => {
return typeof t === 'string' ? t : ParamType.fromObject(t as {
readonly name?: string;
readonly type?: string;
})
})

return defaultAbiCoder.decode(types, hex) as unknown as T;
}
}
3 changes: 1 addition & 2 deletions test/multicall.service.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {CHAIN_1_MULTICALL_ADDRESS, Web3ProviderConnector} from '../src';
import Web3 from 'web3';
import ERC20ABI from './ERC20.abi.json';
import {BigNumber} from '@ethersproject/bignumber';
import {ProviderConnector} from '../dist';
import { GasLimitService } from '../src/gas-limit.service';
import { MultiCallService } from '../src/multicall.service';
Expand Down Expand Up @@ -100,7 +99,7 @@ describe('MultiCallService', () => {
);

const balances = res.map((x) => {
return provider.decodeABIParameter<BigNumber>('uint256', x).toString()
return provider.decodeABIParameter('uint256', x).toString()
});

expect(balances).toEqual(expectedBalances);
Expand Down
Loading

0 comments on commit 69cf368

Please sign in to comment.